ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/mstein/triggerStudy/triggerStudy.C
(Generate patch)

Comparing UserCode/mstein/triggerStudy/triggerStudy.C (file contents):
Revision 1.1 by mstein, Thu Nov 22 15:32:47 2012 UTC vs.
Revision 1.4 by mstein, Thu Dec 6 10:36:16 2012 UTC

# Line 1 | Line 1
1 < #ifndef triggerStudy_cxx
2 < #define  triggerStudy_cxx
3 < #include "triggerStudy.h"
4 < #include "triggerStudy.cfg"
5 < #include "histo.h"
6 <
7 < //using namespace tools;
1 > /////////////////////////////////////////////////////////
2 > //                  Trigger Study
3 > /////////////////////////////////////////////////////////
4 > //to run, execute: root run.C
5 > //
6 > //In this file, the implementation of the T&P method and
7 > //the evaluation of the trigger efficiency is performed.
8 > //some documentation can be found here:
9 > //https://twiki.cern.ch/twiki/bin/viewauth/CMSsandbox/MatthiasSteinTriggerStudy
10 >
11 >
12 > #include <iostream>
13 > #include <fstream>
14 > #include <map>
15 > #include <vector>
16 >
17 > #include <Math/LorentzVector.h>
18 >
19 > #include "TString.h"
20 > #include "TH1.h"
21 > #include "TH1D.h"
22 > #include "TTree.h"
23 > #include "TFile.h"
24 >
25 > #include "plotMaker.h"
26 > #include "tools.h"
27 > //--------------------------------------------------- declare some special types
28 > #ifdef __MAKECINT__
29 > #pragma link C++ class pair<string,bool>+;
30 > #pragma link C++ class pair<string,string>+;
31 > #pragma link C++ class map<string,bool>+;
32 > #pragma link C++ class map<string,string>+;
33 > #pragma link C++ class ROOT::Math::PtEtaPhiM4D<float>+;
34 > #pragma link C++ class ROOT::Math::LorentzVector<ROOT::Math::PtEtaPhiM4D<float> >+;
35 > #pragma link C++ class vector<ROOT::Math::LorentzVector<ROOT::Math::PtEtaPhiM4D<float> > >+;
36 > #endif
37  
38 + typedef ROOT::Math::LorentzVector<ROOT::Math::PtEtaPhiM4D<float> > LorentzM;
39  
40 < //================================================================================= mainProgram
41 < void triggerStudy::mainProgram(){
42 <  tools::enterFcn("mainProgram",1);
43 <  Loop();
44 <  tools::exitFcn("mainProgram",1);
40 > //--------------------------------------------------- Structure to store the whole event information in order to pass it to functions
41 > struct eventInfo{
42 >  vector<string> *DESYtriggerElMatchedTriggerFilter;
43 >  vector<string> *DESYtriggerMuMatchedTriggerFilter;  
44 >  map<string, string> *DESYtriggerNameMap;
45 >  vector<int> *electronCharge;
46 >  vector<LorentzM> *electronP4;
47 >  int Event;
48 >  double HT;
49 >  vector<LorentzM> *jetP4;
50 >  double MET;
51 >  vector<int> *muonCharge;
52 >  vector<LorentzM> *muonP4;
53 >  map<string, int> *prescaled;
54 >  int Run;
55 >  int PUInter;
56 >  double PUWeight;
57 >  map<string, bool> *triggered;
58 >  vector<vector<TString> > triggerFilterEl;
59 >  vector<vector<TString> > triggerFilterMu;
60 >  double Weight;
61 > };
62 >
63 > //--------------------------------------------------- functions
64 > // void init(TString inputFileName);
65 > void handleTriggerMatchingInfo(eventInfo& evt);
66 > void initBranches(TTree *tree, eventInfo &event);
67 > void investigateTriggerFilterMu(eventInfo& evt, map<TString, plotMaker> &plot, TString filterName);
68 > void Loop(TString inputFileName, TString outputFileName);
69 > void makeEfficiencyPlots(map<TString, plotMaker> &plot);
70 > void plotHistograms(eventInfo& evt, map<TString, plotMaker> &plot);
71 > void printElectronInfo(eventInfo& evt, ostream& os=cout);
72 > void printEventInfo(eventInfo& evt, ostream& os=cout);
73 > void printMuonInfo(eventInfo& evt, ostream& os=cout);
74 > void setEfficiencyErrors(TH1D* &eff, TH1D* &h_tag, TH1D* &h_probe);
75 >
76 > //--------------------------------------------------- global Variables
77 > vector<string> triggerFilterToCheckMu;
78 > vector<string> triggerFilterToCheckEl;
79 > //----------------------------------------
80 > const Int_t    binPt = 25;
81 > const Double_t lowPt = 0.;
82 > const Double_t upPt  = 250.;
83 > //----------------------------------------
84 > const Int_t    binEta = 50;
85 > const Double_t lowEta = -2.5;
86 > const Double_t upEta  = 2.5;
87 > //----------------------------------------
88 > const Int_t    binPU = 64;
89 > const Double_t lowPU = 0.;
90 > const Double_t upPU  = 64.;
91 >
92 >
93 >
94 > //================================================================================= triggerStudy
95 > //main function which will be called
96 > //here, it is possible to run over multiple files and to estimate trigger efficiencies for different samples
97 > void triggerStudy(TString inputFileName = "TTJets_mu_tree.root"){
98 >  triggerFilterToCheckMu.push_back("hltL1sMu16Eta2p1");
99 >  triggerFilterToCheckMu.push_back("hltL2fL1sMu16Eta2p1L1f0L2Filtered16Q");
100 >  triggerFilterToCheckMu.push_back("hltL3crIsoL1sMu16Eta2p1L1f0L2f16QL3f20L3crIsoFiltered10");
101 >  triggerFilterToCheckMu.push_back("hltIsoMu202p1TriCentralPFJet30MuCleaned");
102 >  triggerFilterToCheckMu.push_back("hltIsoMu202p1TriCentralPFJet303020MuCleaned");
103 >  triggerFilterToCheckMu.push_back("hltDiMuonGlb22Trk8DzFiltered0p2");  
104 >  triggerFilterToCheckMu.push_back("hltL3crIsoL1sMu14Eta2p1L1f0L2f16QL3f20L3crIsoRhoFiltered0p15");  
105 >
106 >  
107 > //   triggerFilterToCheckEl.push_back("hltL1sL1SingleEG20orL1SingleEG22");  
108 > //   triggerFilterToCheckEl.push_back("hltEle25CaloIdVTTrkIdTCaloIsoTTrkIsoTTrackIsoFilter");  
109 > //   triggerFilterToCheckEl.push_back("hltEle25CaloIdVTCaloIsoTTrkIdTTrkIsoTTriCentralPFJet30EleCleaned");  
110 > //   triggerFilterToCheckEl.push_back("hltEle25CaloIdVTCaloIsoTTrkIdTTrkIsoTTriCentralPFNoPUJet30EleCleaned");  
111 > //   triggerFilterToCheckEl.push_back("hltEle25CaloIdVTCaloIsoTTrkIdTTrkIsoTTriCentralPFNoPUJet303020EleCleaned");  
112 >  
113 >  TH1::SetDefaultSumw2();
114 >  
115 >  //Loop(inputFileName, outputFileName);
116 >  
117 >  inputFileName = "TTJets_mu_tree.root";
118 >  inputFileName = "TTJets_el_tree.root";
119 >  inputFileName = "DYJets_mu_tree.root";
120 >  inputFileName = "DYJets_el_tree.root";
121 >  
122 >  inputFileName = "TTJets_SUMMER12_TrigStudy-mu_noTail_Tree.root";
123 >  //inputFileName = "TTJets_SUMMER12_TrigStudy-el_noTail_Tree.root";
124 >  inputFileName = "DYJets_M-50_TrigStudy-mu_noTail_Tree.root";
125 >  //inputFileName = "DYJets_M-50_TrigStudy-el_noTail_Tree.root";  
126 >  
127 >  TString dir ="";
128 >  dir ="/scratch/hh/current/cms/user/mstein/output/";
129 >  Loop(dir + inputFileName, "out_"+inputFileName);
130 >  
131 >
132 >  Loop("/scratch/hh/current/cms/user/mstein/output/TTJets_mu_tree.root", "out_TTJets_mu_tree.root");
133 >  Loop("/scratch/hh/current/cms/user/mstein/output/TTJets_el_tree.root", "out_TTJets_el_tree.root");
134 >  Loop("/scratch/hh/current/cms/user/mstein/output/DYJets_mu_tree.root", "out_DYJets_mu_tree.root");
135 >  Loop("/scratch/hh/current/cms/user/mstein/output/DYJets_el_tree.root", "out_DYJets_el_tree.root");
136 >
137 >  Loop("/scratch/hh/current/cms/user/mstein/output/TTJets/SUMMER12/TTJets_SUMMER12_TrigStudy-mu_noTail_Tree.root", "out_TTJets_SUMMER12_TrigStudy-mu_noTail_Tree.root");
138 >  Loop("/scratch/hh/current/cms/user/mstein/output/TTJets/SUMMER12/TTJets_SUMMER12_TrigStudy-el_noTail_Tree.root", "out_TTJets_SUMMER12_TrigStudy-el_noTail_Tree.root");
139 >  Loop("/scratch/hh/current/cms/user/mstein/output/DYJets/M-10to50/TTJets_SUMMER12_TrigStudy-mu_noTail_Tree.root", "out_TTJets_SUMMER12_TrigStudy-mu_noTail_Tree.root");
140 >  Loop("/scratch/hh/current/cms/user/mstein/output/DYJets/M-50/TTJets_SUMMER12_TrigStudy-mu_noTail_Tree.root", "out_TTJets_SUMMER12_TrigStudy-mu_noTail_Tree.root");
141 >
142 >  
143 >  
144 >  
145 >  //   init(inputFileName);  
146 >  //   Loop("SusyCAF_Tree_n722_3403013856_out_tree.root", "TTJets.root");
147 >  //Loop("TTJets_SUMMER12_TrigStudy-mu_noTail_Tree.root", "TTJets.root");
148 >  //Loop(inputFileName, "Run2012C.root");
149   }
150  
151  
152 < //================================================================================= Loop
153 < void triggerStudy::Loop(){
154 <  tools::enterFcn("Loop",1,1);
155 <  timer.Start("Loop");
156 <  vector<UInt_t> loopEvents;
152 > //================================================================================= plotHistograms
153 > void plotHistograms(eventInfo& evt, map<TString, plotMaker> &plot){
154 >  plot["event"].addh1d("muMultiplicity", "muMultiplicity", "muon multiplicity", "events", 5, -0.5, 4.5, evt.muonP4->size(), evt.Weight);
155 >  plot["event"].addh1d("elMultiplicity", "elMultiplicity", "electron multiplicity", "events", 5, -0.5, 4.5, evt.electronP4->size(), evt.Weight);
156 >  plot["event"].addh1d("jetMultiplicity", "jetMultiplicity", "jet multiplicity", "events", 10, -0.5, 9.5, evt.jetP4->size(), evt.Weight);
157  
158 <  for(Long64_t jentry=startEvent; jentry<nentries + startEvent; ++jentry){
159 <    tools::progress(jentry);
26 <    inputTree->GetEntry(jentry);
27 <    //initVariables(jentry);
28 <  
29 <    //makeHistograms("_before");
30 <    //makeHistograms("_after");
158 >  for(Int_t i=0,N=triggerFilterToCheckMu.size(); i<N; ++i){
159 >    investigateTriggerFilterMu(evt, plot, triggerFilterToCheckMu.at(i));
160    }
161 <  timer.Stop("Loop");
162 <  tools::exitFcn("Loop",1,1);
161 > //   for(Int_t i=0,N=triggerFilterToCheckEl.size(); i<N; ++i){
162 > //     investigateTriggerFilterEl(evt, plot, triggerFilterToCheckEl.at(i));
163 > //   }
164   }
165  
166  
167 + //================================================================================= investigateTriggerFilterMu
168 + // eff = 2*NTT / (2*NTT + NTP)
169 + void investigateTriggerFilterMu(eventInfo& evt, map<TString, plotMaker> &plot, TString filterName){
170 +  //create vector which stores, if a muon is matched to the trigger filter with the name "filterName"
171 +  vector<bool> matched;
172 +  vector<int> probeIndex;
173 +  for(Int_t i=0,N=evt.muonP4->size(); i<N; ++i){
174 +    matched.push_back(false);
175 +    for(Int_t j=0,M=evt.triggerFilterMu.at(i).size(); j<M; ++j){
176 +      if(filterName == evt.triggerFilterMu.at(i).at(j)){
177 +        matched.back() = true;
178 +        break;
179 +      }
180 +    }
181 +    if(!matched.at(i)) probeIndex.push_back(i);
182 +  }
183 +  
184 +  if(probeIndex.size()>2){
185 +    cout<<"WARNING: Something is awkward with the number of Probe leptons: " << probeIndex.size() << endl;
186 +    cout<<"The number of probe leptons is expected to be 1 or 2, because here a T&P method is applied!" << endl;
187 +  }
188 +  else if(probeIndex.size()==2) return; //make only plots if at least one Tag exists in an event
189 +  
190 +  //Fill the Tag histograms
191 +  //here, we have TWO Tag leptons -> use BOTH for the efficiency
192 +  if(probeIndex.size()==0){
193 +    for(Int_t i=0,N=evt.muonP4->size(); i<N; ++i){
194 +      plot[filterName].addh1d("pt_tag", "pt_tag", "p_{T}(tag) [GeV/c]", "events", binPt, lowPt, upPt, evt.muonP4->at(i).Pt(), evt.Weight);
195 +      plot[filterName].addh1d("eta_tag", "eta_tag", "#eta(tag)", "events", binEta, lowEta, upEta, evt.muonP4->at(i).eta(), evt.Weight);
196 +    }
197 +    //the factor of '2' is due to the fact, that there are two matched tag leptons
198 +    plot[filterName].addh1d("PUVertices_tag", "PUVertices_tag", "number of primary vertices (tag)", "events", binPU, lowPU, upPU, evt.PUInter, 2*evt.Weight);
199 +  }
200  
201 +  //Fill the Probe histograms
202 +  //here, we have ONE Tag lepton -> the probe is NOT matched to the trigger filter  
203 +  if(probeIndex.size()==1){
204 +    plot[filterName].addh1d("pt_probe", "pt_probe", "p_{T}(probe) [GeV/c]", "events", binPt, lowPt, upPt, evt.muonP4->at(probeIndex.back()).pt(), evt.Weight);    
205 +    plot[filterName].addh1d("eta_probe", "eta_probe", "#eta(probe)", "events", binEta, lowEta, upEta, evt.muonP4->at(probeIndex.back()).eta(), evt.Weight);
206 +    plot[filterName].addh1d("PUVertices_probe", "PUVertices_probe", "number of primary vertices (probe)", "events", binPU, lowPU, upPU, evt.PUInter, evt.Weight);
207 +  }
208 + }
209  
210  
211 < //================================================================================= initVariables
212 < void triggerStudy::initVariables(){
213 <  tools::enterFcn("initVariables",2);
211 > //================================================================================= makeEfficiencyPlots
212 > //eff = tag/(tag+probe)
213 > void makeEfficiencyPlots(map<TString, plotMaker> &plot){
214 >  cout<<"----------> Create efficiency histograms"<<endl;
215 >
216 >  vector<string> allTriggerFiltersToCheck = triggerFilterToCheckMu;
217 >  for(Int_t i=0,N=triggerFilterToCheckEl.size(); i<N; ++i){
218 >    allTriggerFiltersToCheck.push_back(triggerFilterToCheckEl.at(i));
219 >  }
220 >  vector<string> histNames;
221 >  histNames.push_back("pt_tag");
222 >  histNames.push_back("eta_tag");
223 >  histNames.push_back("PUVertices_tag");
224 >  
225 >  for(Int_t i=0,N=allTriggerFiltersToCheck.size(); i<N; ++i){
226 >    TString triggerFilter = allTriggerFiltersToCheck.at(i);
227 >    for(Int_t j=0,M=histNames.size(); j<M; ++j){
228 >      TString tagName   = histNames.at(j);
229 >      TString probeName = histNames.at(j);
230 >      TString effName   = histNames.at(j);
231 >      probeName.ReplaceAll("tag", "probe");
232 >      effName.ReplaceAll("tag", "eff");
233 >      if(plot[triggerFilter].isNewh1d(tagName)) continue;
234 >      if(plot[triggerFilter].isNewh1d(probeName)) continue;
235 >
236 >      TH1D *h_tag   = (TH1D*)(plot[triggerFilter].h1d[tagName])->Clone();
237 >      TH1D *h_probe = (TH1D*)(plot[triggerFilter].h1d[probeName])->Clone();
238 >      TH1D *den = (TH1D*)(h_tag)->Clone();
239 >      den->Add((TH1D*)(h_probe)->Clone());
240 >
241 >      TH1D *eff = (TH1D*)(h_tag)->Clone();
242 >      eff->Divide(den);
243 >      setEfficiencyErrors(eff, h_tag, h_probe);
244 >      
245 >      eff->SetName(effName);
246 >      eff->SetTitle(effName);
247 >      
248 >      TString xTitle_eff = eff->GetXaxis()->GetTitle();
249 >      xTitle_eff.ReplaceAll("(tag)","");
250 >      eff->GetXaxis()->SetTitle(xTitle_eff);
251 >      eff->GetYaxis()->SetTitle("efficiency");
252 >      //eff->SetAxisRange(0.,1.,"Y");
253 >      plot[triggerFilter].addh1d(eff);
254 >    }
255 >  }
256 > }
257 >
258 >
259 > //================================================================================= setEfficiencyErrors
260 > // f(eff) = t/(t+p)
261 > // df/dt = 1/(t+p) - t/(t+p)^2
262 > // df/dp = - t/(t+p)^2
263 > // eff_sig = sqrt(t_sig^2*(df/dt)^2 + p_sig^2*(df/dp)^2)
264 > void setEfficiencyErrors(TH1D* &eff, TH1D* &h_tag, TH1D* &h_probe){
265 >  if(h_tag->GetNbinsX() !=  h_probe->GetNbinsX()){
266 >    cout<<"WARNING: the number of bins of the tag and probe histograms differ! The efficiency calculation might be depricated!"<<endl;
267 >    cout<<"Number of bins (Tag | Probe): " << h_tag->GetNbinsX() << " | " << h_probe->GetNbinsX() << endl;
268 >  }
269 >  if(h_tag->GetXaxis()->GetXmax() !=  h_probe->GetXaxis()->GetXmax()){
270 >    cout<<"WARNING: the upper x-range of the tag and probe histograms differ! The efficiency calculation might be depricated!"<<endl;
271 >    cout<<"Number of bins (Tag | Probe): " << h_tag->GetXaxis()->GetXmax() << " | " << h_probe->GetXaxis()->GetXmax() << endl;
272 >  }
273 >  if(h_tag->GetXaxis()->GetXmin() !=  h_probe->GetXaxis()->GetXmin()){
274 >    cout<<"WARNING: the lower x-range of the tag and probe histograms differ! The efficiency calculation might be depricated!"<<endl;
275 >    cout<<"Number of bins (Tag | Probe): " << h_tag->GetXaxis()->GetXmin() << " | " << h_probe->GetXaxis()->GetXmin() << endl;
276 >  }
277 >  //loop over single bins of histograms an set the efficiency error
278 >  for(Int_t i=1,N=h_tag->GetNbinsX(); i<=N; ++i){
279 >    Double_t t = h_tag  ->GetBinContent(i);
280 >    Double_t p = h_probe->GetBinContent(i);
281 >    Double_t t_sig = h_tag  ->GetBinError(i);
282 >    Double_t p_sig = h_probe->GetBinError(i);
283 >    
284 >    if(eff->GetBinContent(i)==0.) continue;
285 >    
286 >    Double_t dedt = 1/(t+p)-t/((t+p)*(t+p));
287 >    Double_t dedp = -t/((t+p)*(t+p));
288 >    
289 >    Double_t eff_sig = sqrt(t_sig*t_sig*dedt*dedt + p_sig*p_sig*dedp*dedp);
290 >    eff->SetBinError(i, eff_sig);
291 >  }
292 > }
293 >
294  
295 <  //cout<<"dataset = " << dataset << endl;
296 < //   Candidates             .clear();
297 <
298 <  tools::exitFcn("initVariables",2);
295 > //================================================================================= Loop
296 > void Loop(TString inputFileName, TString outputFileName){
297 >  //timer.Start("Loop");
298 >  TString treeName = "trigStudyTree";
299 >  map<TString, plotMaker> myPlots;      
300 >  
301 >  //--------------------------------------------------- open file and read in leafs
302 >  TFile* inputFile = new TFile(inputFileName,"READ");
303 >  if (!inputFile->IsOpen()) std::cout<<"Could not open file "<<inputFileName<<std::endl;
304 >  TTree* inputTree= (TTree*)inputFile->Get(treeName);
305 >  
306 >  eventInfo event;
307 >  initBranches(inputTree, event);
308 >  //--------------------------------------------------- Event Loop
309 >  int nEvents=inputTree->GetEntries();
310 >  cout<<endl;
311 >  cout<<"///////////////////////////////////////////////////////////////////////////////"<<endl;
312 >  cout<<"////////////////////////////// Starting Event Loop ////////////////////////////"<<endl;
313 >  cout<<"///////////////////////////////////////////////////////////////////////////////"<<endl;
314 >  cout<<"Investigate File: " << inputFileName << endl;
315 >  cout<<"Read out TTree:   " << treeName << endl;
316 >  cout<<"Number of events: " << nEvents << endl;
317 >  cout<<"-------------------------------------------------------------------------------"<<endl;
318 >  cout<<endl;
319 >  cout<<"Looping over events..."<<endl;
320 > //   nEvents=50000;
321 >  for (int iEvent=0; iEvent<nEvents; ++iEvent){
322 >    tools::progress(iEvent);
323 >    inputTree->GetEntry(iEvent);
324 >    handleTriggerMatchingInfo(event);
325 > //     printEventInfo(event);
326 > //      printMuonInfo(event);
327 >     //printElectronInfo(event);
328 >    plotHistograms(event, myPlots);
329 >    //tools::progressReset();
330 >  }
331 >  
332 >  makeEfficiencyPlots(myPlots);
333 >  //--------------------------------------------------- Save all histograms in the appropriate folders
334 >  TString option="RECREATE";
335 >  for(typename map<TString, plotMaker>::iterator it = myPlots.begin(); it != myPlots.end(); ++it){
336 >    it->second.savePlots(outputFileName, option, it->first);
337 >    option="UPDATE";
338 >  }
339 >  //timer.Stop("Loop");
340   }
341  
342  
343 + //================================================================================= handleTriggerMatchingInfo
344 + // converting the trigger Info to a more practical format:  vector<string> --> vector<vector<string> >
345 + void handleTriggerMatchingInfo(eventInfo& evt){
346 +  evt.triggerFilterEl.clear();
347 +  evt.triggerFilterMu.clear();
348 +  //make simple check
349 +  
350 +  if(evt.electronP4->size() != evt.DESYtriggerElMatchedTriggerFilter->size()){
351 +    cout<<"WARNING: Size of electron vector does not correspond to size of matching info vector!"<<endl;
352 +    cout<<"evt.electronP4->size()                        = " << evt.electronP4->size() << endl;
353 +    cout<<"evt.DESYtriggerElMatchedTriggerFilter->size() = " << evt.DESYtriggerElMatchedTriggerFilter->size() << endl;
354 +    
355 +    tools::printVector("evt.electronP4", *(evt.electronP4));
356 +    tools::printVector("evt.DESYtriggerElMatchedTriggerFilter", *(evt.DESYtriggerElMatchedTriggerFilter));
357  
358 +    return;
359 +  }
360 +  if(evt.muonP4->size() != evt.DESYtriggerMuMatchedTriggerFilter->size()){
361 +    cout<<"WARNING: Size of muon vector does not correspond to size of matching info vector!"<<endl;
362 +    cout<<"evt.muonP4->size()                            = " << evt.muonP4->size() << endl;
363 +    cout<<"evt.DESYtriggerMuMatchedTriggerFilter->size() = " << evt.DESYtriggerMuMatchedTriggerFilter->size() << endl;
364 +    return;
365 +  }
366 +  
367 +  for(Int_t i=0,N=evt.electronP4->size(); i<N; ++i){
368 +    evt.triggerFilterEl.push_back(tools::splitToWords(evt.DESYtriggerElMatchedTriggerFilter->at(i), ";"));
369 +    //cout<<"evt.DESYtriggerElMatchedTriggerFilter->at("<<i<<") = " << evt.DESYtriggerElMatchedTriggerFilter->at(i) << endl;
370 +    //tools::printVector<TString>("triggerFilterEl", evt.triggerFilterEl.at(i));
371 +  }
372 + //     printMuonInfo(evt);
373 + //     printElectronInfo(evt);
374 +    
375 +    //tools::printVector("evt.triggerFilterMu", evt.triggerFilterMu);
376 + //     tools::printVector("evt.DESYtriggerMuMatchedTriggerFilter", *(evt.DESYtriggerMuMatchedTriggerFilter));
377 + //     tools::printVector("evt.muonP4", *(evt.muonP4));
378 +    
379 +  for(Int_t i=0,N=evt.muonP4->size(); i<N; ++i){
380 +    evt.triggerFilterMu.push_back(tools::splitToWords(evt.DESYtriggerMuMatchedTriggerFilter->at(i), ";"));
381 +    //cout<<"evt.DESYtriggerMuMatchedTriggerFilter->at("<<i<<") = " << evt.DESYtriggerMuMatchedTriggerFilter->at(i) << endl;
382 +    //tools::printVector<TString>("triggerFilterMu", evt.triggerFilterMu.at(i));
383 +  }  
384 +  //cout<<"size: muonP4 | filterinfo = "
385 +  //<<evt.muonP4->size() << " | "
386 +  //<<evt.DESYtriggerMuMatchedTriggerFilter->size()
387 +  //<<endl;
388 + }
389  
390  
391 + //================================================================================= initBranches
392 + void initBranches(TTree *tree, eventInfo& evt){
393 +  //--------------------------------------------------- initialize event info
394 +  evt.DESYtriggerElMatchedTriggerFilter = 0;
395 +  evt.DESYtriggerMuMatchedTriggerFilter = 0;
396 +  evt.DESYtriggerNameMap                = 0;
397 +  evt.electronCharge                    = 0;
398 +  evt.electronP4                        = 0;
399 +  evt.Event                             = 0;
400 +  evt.HT                                = 0.;
401 +  evt.jetP4                             = 0;
402 +  evt.MET                               = 0.;
403 +  evt.muonCharge                        = 0;
404 +  evt.muonP4                            = 0;
405 +  evt.prescaled                         = 0;
406 +  evt.Run                               = 0;
407 +  evt.PUInter                           = 0.;
408 +  evt.PUWeight                          = 0.;
409 +  evt.triggered                         = 0;
410 +  evt.Weight                            = 0.;
411 +  //--------------------------------------------------- assign branches to event structure
412 +  tree->SetBranchAddress("DESYtriggerElMatchedTriggerFilter", &(evt.DESYtriggerElMatchedTriggerFilter));
413 +  tree->SetBranchAddress("DESYtriggerMuMatchedTriggerFilter",&(evt.DESYtriggerMuMatchedTriggerFilter));
414 +  tree->SetBranchAddress("DESYtriggerNameMap",&(evt.DESYtriggerNameMap));
415 +  tree->SetBranchAddress("electronCharge",&(evt.electronCharge));
416 +  tree->SetBranchAddress("electronP4",&(evt.electronP4));
417 +  tree->SetBranchAddress("Event",&(evt.Event));
418 +  tree->SetBranchAddress("HT",&(evt.HT));
419 +  tree->SetBranchAddress("jetP4",&(evt.jetP4));
420 +  tree->SetBranchAddress("MET",&(evt.MET));
421 +  tree->SetBranchAddress("muonCharge",&(evt.muonCharge));
422 +  tree->SetBranchAddress("muonP4",&(evt.muonP4));
423 +  tree->SetBranchAddress("prescaled",&(evt.prescaled));
424 +  tree->SetBranchAddress("Run",&(evt.Run));
425 +  tree->SetBranchAddress("PUInter",&(evt.PUInter));
426 +  tree->SetBranchAddress("PUWeight",&(evt.PUWeight));
427 +  tree->SetBranchAddress("triggered",&(evt.triggered));
428 +  tree->SetBranchAddress("Weight",&(evt.Weight));
429 + }
430  
431  
432 + //================================================================================= printEventInfo
433 + void printEventInfo(eventInfo& evt, ostream& os){
434 +  os<<endl;
435 +  os<<"///////////////////////////////////////////////////////"<<endl;
436 +  os<<"///////////////////// Event Info //////////////////////"<<endl;
437 +  os<<"///////////////////////////////////////////////////////"<<endl;
438 +  os<<endl;
439 +  os<<"-----------------------------------------"<<endl;
440 +  os<<"Run      = "<<evt.Run<<endl;
441 +  os<<"Event    = "<<evt.Event<<endl;
442 +  os<<"Weight   = "<<evt.Weight<<endl;
443 +  os<<"PUWeight = "<<evt.PUWeight<<endl;
444 +  os<<"PUInter  = "<<evt.PUInter<<endl;
445 +  os<<"-----------------------------------------"<<endl;
446 +  os<<"HT               = "<<evt.HT<<endl;
447 +  os<<"MET              = "<<evt.MET<<endl;
448 +  os<<"-----------------------------------------"<<endl;
449 +  os<<"No. of Muons     = "<<evt.muonP4->size()<<endl;
450 +  os<<"No. of Electrons = "<<evt.electronP4->size()<<endl;
451 +  os<<"No. of Jets      = "<<evt.jetP4->size()<<endl;
452 +  os<<"-----------------------------------------"<<endl;
453 +  os<<"muonCharge.size()     = "<<evt.muonCharge->size()<<endl;
454 +  os<<"electronCharge.size() = "<<evt.electronCharge->size()<<endl;
455 +  os<<"-----------------------------------------"<<endl;
456 +  os<<"MuMatchedTriggerFilter.size() = "<<evt.DESYtriggerMuMatchedTriggerFilter->size()<<endl;
457 +  os<<"ElMatchedTriggerFilter.size() = "<<evt.DESYtriggerElMatchedTriggerFilter->size()<<endl;
458 +  os<<"-----------------------------------------"<<endl;
459 +  os<<"triggered.size()      = "<<evt.triggered->size()<<endl;
460 +  os<<"prescaled.size()      = "<<evt.prescaled->size()<<endl;
461 +  os<<"DESYTriggerMap.size() = "<<evt.DESYtriggerNameMap->size()<<endl;
462 +  os<<"-----------------------------------------"<<endl;
463 +  os<<endl;
464 +  
465 +  //tools::printVector<string>("jetP4", *(evt.jetP4));  
466 +  //tools::printVector<string>("DESYtriggerMuMatchedTriggerFilter", *(evt.DESYtriggerMuMatchedTriggerFilter));
467 +  //tools::printVector<string>("DESYtriggerElMatchedTriggerFilter", *(evt.DESYtriggerElMatchedTriggerFilter));
468 +  //tools::printVector<string>("DESYtriggerNameMap", *(evt.DESYtriggerNameMap));
469 +  //tools::printVector<string>("prescaled", *(evt.prescaled));
470 +  //tools::printVector<string>("triggered", *(evt.triggered));
471 + }
472  
473  
474 + //================================================================================= printMuonInfo
475 + void printMuonInfo(eventInfo& evt, ostream& os){
476 +  os<<endl;
477 +  os<<"///////////////////////////////////////////////////////"<<endl;
478 +  os<<"////////////////////// Muon Info //////////////////////"<<endl;
479 +  os<<"///////////////////////////////////////////////////////"<<endl;
480 +  os<<endl;
481 +  tools::printVector<LorentzM>("muonP4", *(evt.muonP4), os);
482 +  tools::printVector<int>("muonCharge", *(evt.muonCharge), os);
483 +  //------------------------ print invariant mass from all possible muon pairs
484 +  if(evt.muonP4->size()>=2){
485 +    os<<"-------------> Invariant masses of all possible muon pairs:"<<endl;
486 +    for(Int_t i=0,N=evt.muonP4->size(); i<N-1; ++i){
487 +      for(Int_t j=i+1; j<N; ++j){
488 +        Double_t minv = (evt.muonP4->at(i) + evt.muonP4->at(j)).mass();
489 +        os<<"Minv("<<i<<" + " <<j<<") = "<<minv<<endl;
490 +      }
491 +    }
492 +    os<<endl;
493 +  }
494 +  //------------------------ print matching info
495 +  for(Int_t i=0,N=evt.muonP4->size(); i<N; ++i){
496 +    os<<"----------------------------------------------------------------------------> Matches for muon "<<i<<":"<<
497 +    endl;
498 +    tools::printVector<TString>("matched TriggerFilter", evt.triggerFilterMu.at(i), os);
499 +  }
500 +  os<<endl;
501 + }
502  
503  
504 + //================================================================================= printElectronInfo
505 + void printElectronInfo(eventInfo& evt, ostream& os){
506 +  os<<endl;
507 +  os<<"///////////////////////////////////////////////////////"<<endl;
508 +  os<<"///////////////////// Electron Info ///////////////////"<<endl;
509 +  os<<"///////////////////////////////////////////////////////"<<endl;
510 +  os<<endl;
511 +  tools::printVector<LorentzM>("electronP4", *(evt.electronP4), os);
512 +  tools::printVector<int>("electronCharge", *(evt.electronCharge), os);
513 +  //------------------------ print invariant mass from all possible electron pairs
514 +  if(evt.electronP4->size()>=2){
515 +    os<<"-------------> Invariant masses of all possible electron pairs:"<<endl;
516 +    for(Int_t i=0,N=evt.electronP4->size(); i<N-1; ++i){
517 +      for(Int_t j=i+1; j<N; ++j){
518 +        Double_t minv = (evt.electronP4->at(i) + evt.electronP4->at(j)).mass();
519 +        os<<"Minv("<<i<<" + " <<j<<") = "<<minv<<endl;
520 +      }
521 +    }
522 +    os<<endl;
523 +  }
524 +  //------------------------ print matching info
525 +  for(Int_t i=0,N=evt.electronP4->size(); i<N; ++i){
526 +    os<<"----------------------------------------------------------------------------> Matches for electron "<<i<<":"<<
527 +    endl;
528 +    tools::printVector<TString>("matched TriggerFilter", evt.triggerFilterEl.at(i), os);
529 +  }
530 +  os<<endl;
531 + }
532  
61 #endif
533  
534  
535  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines