ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/mstein/triggerStudy/triggerStudy.C
Revision: 1.5
Committed: Thu Dec 6 12:27:27 2012 UTC (12 years, 5 months ago) by mstein
Content type: text/plain
Branch: MAIN
Changes since 1.4: +269 -110 lines
Log Message:
simple trigger efficiency estimation

File Contents

# Content
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 //--------------------------------------------------- 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_passed, TH1D* &h_failed);
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 //================================================================================= triggerStudy
94 //main function which will be called
95 //here, it is possible to run over multiple files and to estimate trigger efficiencies for different samples
96 void triggerStudy(){
97
98 //--------------------------------------------------- define the muon TriggerFilters to be checked
99 triggerFilterToCheckMu.push_back("hltL1sMu16Eta2p1");
100 triggerFilterToCheckMu.push_back("hltL2fL1sMu16Eta2p1L1f0L2Filtered16Q");
101 triggerFilterToCheckMu.push_back("hltL3crIsoL1sMu16Eta2p1L1f0L2f16QL3f20L3crIsoFiltered10");
102 triggerFilterToCheckMu.push_back("hltIsoMu202p1TriCentralPFJet30MuCleaned");
103 triggerFilterToCheckMu.push_back("hltIsoMu202p1TriCentralPFJet303020MuCleaned");
104 triggerFilterToCheckMu.push_back("hltDiMuonGlb22Trk8DzFiltered0p2");
105 triggerFilterToCheckMu.push_back("hltL3crIsoL1sMu14Eta2p1L1f0L2f16QL3f20L3crIsoRhoFiltered0p15");
106 //--------------------------------------------------- define the electron TriggerFilters to be checked
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 //--------------------------------------------------- define the sample(s) to loop over and the output file
114 //these are small test files of ONE single file af a sample
115 // Loop("/scratch/hh/current/cms/user/mstein/output/TTJets_mu_tree.root", "out_TTJets_mu_tree.root");
116 // Loop("/scratch/hh/current/cms/user/mstein/output/TTJets_el_tree.root", "out_TTJets_el_tree.root");
117 // Loop("/scratch/hh/current/cms/user/mstein/output/DYJets_mu_tree.root", "out_DYJets_mu_tree.root");
118 // Loop("/scratch/hh/current/cms/user/mstein/output/DYJets_el_tree.root", "out_DYJets_el_tree.root");
119 // Loop("/scratch/hh/current/cms/user/mstein/output/SingleMu_mu_tree.root", "out_SingleMu_mu_tree.root");
120 // Loop("/scratch/hh/current/cms/user/mstein/output/SingleElectron_el_tree.root", "out_SingleElectron_el_tree.root");
121 //these are the whole samples
122 // 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");
123 // 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");
124 Loop("/scratch/hh/current/cms/user/mstein/output/DYJets/M-50/DYJets_M-50_TrigStudy-mu_noTail_Tree.root", "out_DYJets_M-50_TrigStudy-mu_noTail_Tree.root");
125 // Loop("/scratch/hh/current/cms/user/mstein/output/DYJets/M-50/DYJets_M-50_TrigStudy-el_noTail_Tree.root", "out_DYJets_M-50_TrigStudy-el_noTail_Tree.root");
126 // Loop("/scratch/hh/current/cms/user/mstein/output/SingleElectron/Run2012B-13Jul2012-v1/SingleElectron_Run2012B-13Jul2012-v1_TrigStudy-el_noTail_Tree.root", "out_SingleElectron_Run2012B-13Jul2012-v1_TrigStudy-el_noTail_Tree.root");
127 // Loop("/scratch/hh/current/cms/user/mstein/output/SingleMu/Run2012B-13Jul2012-v1/SingleMu_Run2012B-13Jul2012-v1_TrigStudy-mu_noTail_Tree.root", "out_SingleMu_Run2012B-13Jul2012-v1_TrigStudy-mu_noTail_Tree.root");
128
129
130 }
131
132
133 //================================================================================= plotHistograms
134 void plotHistograms(eventInfo& evt, map<TString, plotMaker> &plot){
135 plot["event"].addh1d("muMultiplicity", "muMultiplicity", "muon multiplicity", "events", 5, -0.5, 4.5, evt.muonP4->size(), evt.Weight);
136 plot["event"].addh1d("elMultiplicity", "elMultiplicity", "electron multiplicity", "events", 5, -0.5, 4.5, evt.electronP4->size(), evt.Weight);
137 plot["event"].addh1d("jetMultiplicity", "jetMultiplicity", "jet multiplicity", "events", 10, -0.5, 9.5, evt.jetP4->size(), evt.Weight);
138
139 for(Int_t i=0,N=triggerFilterToCheckMu.size(); i<N; ++i){
140 investigateTriggerFilterMu(evt, plot, triggerFilterToCheckMu.at(i));
141 }
142 // for(Int_t i=0,N=triggerFilterToCheckEl.size(); i<N; ++i){
143 // investigateTriggerFilterEl(evt, plot, triggerFilterToCheckEl.at(i));
144 // }
145 }
146
147
148 //================================================================================= investigateTriggerFilterMu
149 //check, if the positive lepton can be matched to the trigger filter
150 //if yes, take this lepton as Tag
151 //then probe the other lepton
152 void investigateTriggerFilterMu(eventInfo& evt, map<TString, plotMaker> &plot, TString filterName, TString label){
153 //--------------------------------------------------- do some consistency check - just to be sure
154 if(evt.muonP4->size() != 2){
155 cout<<"WARNING: The size of the muon vector is NOT two!"<<endl;
156 cout<<"evt.muonP4->size() = " << evt.muonP4->size() << endl;
157 return;
158 }
159 if(evt.muonP4->size() != evt.triggerFilterMu.size()){
160 cout<<"WARNING: The size of the muon vector and Matching-info vector is different!"<<endl;
161 cout<<"evt.muonP4->size() = " << evt.muonP4->size() << endl;
162 cout<<"evt.triggerFilterMu.size() = " << evt.triggerFilterMu.size() << endl;
163 return;
164 }
165 if(evt.muonP4->size() != evt.muonCharge->size()){
166 cout<<"WARNING: The size of the muon vector and muon-charge vector is different!"<<endl;
167 cout<<"evt.muonP4->size() = " << evt.muonP4->size() << endl;
168 cout<<"evt.muonCharge->size() = " << evt.muonCharge->size() << endl;
169 return;
170 }
171 // if(evt.electronP4->size() != evt.triggerFilterEl.size()){
172 // cout<<"WARNING: The size of the electron vector and Matching-info vector is different!"
173 // cout<<"evt.electronP4->size() = " << evt.electronP4->size() << endl;
174 // cout<<"evt.triggerFilterEl->size() = " << evt.triggerFilterEl->size() << endl;
175 // return;
176 // }
177 // if(evt.electronP4->size() != evt.electronP4.size()){
178 // cout<<"WARNING: The size of the electron vector and muon-charge vector is different!"
179 // cout<<"evt.electronP4->size() = " << evt.electronP4->size() << endl;
180 // cout<<"evt.electronP4->size() = " << evt.electronP4->size() << endl;
181 // return;
182 // }
183 //--------------------------------------------------- check which lepton has positive and which negative charge
184 Int_t index_pos = 0;
185 Int_t index_neg = 1;
186 if(evt.muonCharge->at(0)==-1){
187 index_pos = 0;
188 index_pos = 1;
189 }
190 //--------------------------------------------------- check which lepton has been matched to the trigger filter
191 vector<bool> matched;
192 for(Int_t i=0,N=evt.muonP4->size(); i<N; ++i){
193 matched.push_back(false);
194 for(Int_t j=0,M=evt.triggerFilterMu.at(i).size(); j<M; ++j){
195 if(filterName == evt.triggerFilterMu.at(i).at(j)){
196 matched.back() = true;
197 break;
198 }
199 }
200 }
201 //--------------------------------------------------- do the plotting according to the outcome, which lepton could be matched
202
203 //if the positive lepton IS NOT matched => no Tag found => return
204 if(!matched.at(index_pos)) return;
205
206 //if the positive lepton IS matched => plot Tag and Probe, and passed and failed
207 //plot the Tag
208 plot[filterName].addh1d(filterName+"_pt_tag", filterName+"_pt_tag", "p_{T}(tag) [GeV/c]", "events", binPt, lowPt, upPt, evt.muonP4->at(index_pos).Pt(), evt.Weight);
209 plot[filterName].addh1d(filterName+"_eta_tag", filterName+"_eta_tag", "#eta(tag)", "events", binEta, lowEta, upEta, evt.muonP4->at(index_pos).eta(), evt.Weight);
210 //plot the Probe
211 plot[filterName].addh1d(filterName+"_pt_probe", filterName+"_pt_probe", "p_{T}(probe) [GeV/c]", "events", binPt, lowPt, upPt, evt.muonP4->at(index_neg).pt(), evt.Weight);
212 plot[filterName].addh1d(filterName+"_eta_probe", filterName+"_eta_probe", "#eta(probe)", "events", binEta, lowEta, upEta, evt.muonP4->at(index_neg).eta(), evt.Weight);
213 //plot the passed
214 if(matched.at(index_neg)){
215 plot[filterName].addh1d(filterName+"_pt_passed", filterName+"_pt_passed", "p_{T}(passed) [GeV/c]", "events", binPt, lowPt, upPt, evt.muonP4->at(index_neg).pt(), evt.Weight);
216 plot[filterName].addh1d(filterName+"_eta_passed", filterName+"_eta_passed", "#eta(passed)", "events", binEta, lowEta, upEta, evt.muonP4->at(index_neg).eta(), evt.Weight);
217 plot[filterName].addh1d(filterName+"_PUVertices_passed", filterName+"_PUVertices_passed", "number of primary vertices (passed)", "events", binPU, lowPU, upPU, evt.PUInter, evt.Weight);
218 }
219 else{//plot the failed
220 plot[filterName].addh1d(filterName+"_pt_failed", filterName+"_pt_failed", "p_{T}(failed) [GeV/c]", "events", binPt, lowPt, upPt, evt.muonP4->at(index_neg).pt(), evt.Weight);
221 plot[filterName].addh1d(filterName+"_eta_failed", filterName+"_eta_failed", "#eta(failed)", "events", binEta, lowEta, upEta, evt.muonP4->at(index_neg).eta(), evt.Weight);
222 plot[filterName].addh1d(filterName+"_PUVertices_failed", filterName+"_PUVertices_failed", "number of primary vertices (failed)", "events", binPU, lowPU, upPU, evt.PUInter, evt.Weight);
223 }
224 }
225
226
227 //================================================================================= makeEfficiencyPlots
228 //eff = passed/(passed+failed)
229 void makeEfficiencyPlots(map<TString, plotMaker> &plot){
230 cout<<"----------> Create efficiency histograms"<<endl;
231
232 vector<string> allTriggerFiltersToCheck = triggerFilterToCheckMu;
233 for(Int_t i=0,N=triggerFilterToCheckEl.size(); i<N; ++i){
234 allTriggerFiltersToCheck.push_back(triggerFilterToCheckEl.at(i));
235 }
236 vector<string> histNames;
237 histNames.push_back("_pt_passed");
238 histNames.push_back("_eta_passed");
239 histNames.push_back("_PUVertices_passed");
240
241 for(Int_t i=0,N=allTriggerFiltersToCheck.size(); i<N; ++i){
242 TString triggerFilter = allTriggerFiltersToCheck.at(i);
243 for(Int_t j=0,M=histNames.size(); j<M; ++j){
244 TString passedName = triggerFilter;
245 TString failedName = triggerFilter;
246 TString effName = triggerFilter;
247 passedName += histNames.at(j);
248 failedName += histNames.at(j);
249 effName += histNames.at(j);
250 failedName.ReplaceAll("passed", "failed");
251 effName.ReplaceAll("passed", "eff");
252
253 if(plot[triggerFilter].isNewh1d(passedName)) continue;
254 if(plot[triggerFilter].isNewh1d(failedName)) continue;
255
256 TH1D *h_passed = (TH1D*)(plot[triggerFilter].h1d[passedName])->Clone();
257 TH1D *h_failed = (TH1D*)(plot[triggerFilter].h1d[failedName])->Clone();
258 TH1D *den = (TH1D*)(h_passed)->Clone();
259 den->Add((TH1D*)(h_failed)->Clone());
260
261 TH1D *eff = (TH1D*)(h_passed)->Clone();
262 eff->Divide(den);
263 setEfficiencyErrors(eff, h_passed, h_failed);
264
265 eff->SetName(effName);
266 eff->SetTitle(effName);
267
268 TString xTitle_eff = eff->GetXaxis()->GetTitle();
269 xTitle_eff.ReplaceAll("(passed)","");
270 eff->GetXaxis()->SetTitle(xTitle_eff);
271 eff->GetYaxis()->SetTitle("efficiency");
272 //eff->SetAxisRange(0.,1.,"Y");
273 plot[triggerFilter].addh1d(eff);
274 }
275 }
276 }
277
278
279 //================================================================================= setEfficiencyErrors
280 //p = passed; f = failed
281 // f(eff) = p/(p+f)
282 // df/dt = 1/(p+f) - p/(p+f)^2
283 // df/dp = - p/(p+f)^2
284 // eff_sig = sqrt(p_sig^2*(df/dp)^2 + f_sig^2*(df/df)^2)
285 void setEfficiencyErrors(TH1D* &eff, TH1D* &h_passed, TH1D* &h_failed){
286 if(h_passed->GetNbinsX() != h_failed->GetNbinsX()){
287 cout<<"WARNING: the number of bins of the passed and failed histograms differ! The efficiency calculation might be depricated!"<<endl;
288 cout<<"Number of bins (passed | failed): " << h_passed->GetNbinsX() << " | " << h_failed->GetNbinsX() << endl;
289 }
290 if(h_passed->GetXaxis()->GetXmax() != h_failed->GetXaxis()->GetXmax()){
291 cout<<"WARNING: the upper x-range of the passed and failed histograms differ! The efficiency calculation might be depricated!"<<endl;
292 cout<<"Number of bins (passed | failed): " << h_passed->GetXaxis()->GetXmax() << " | " << h_failed->GetXaxis()->GetXmax() << endl;
293 }
294 if(h_passed->GetXaxis()->GetXmin() != h_failed->GetXaxis()->GetXmin()){
295 cout<<"WARNING: the lower x-range of the passed and failed histograms differ! The efficiency calculation might be depricated!"<<endl;
296 cout<<"Number of bins (passed | failed): " << h_passed->GetXaxis()->GetXmin() << " | " << h_failed->GetXaxis()->GetXmin() << endl;
297 }
298 //loop over single bins of histograms an set the efficiency error
299 for(Int_t i=1,N=h_passed->GetNbinsX(); i<=N; ++i){
300 Double_t p = h_passed ->GetBinContent(i);
301 Double_t f = h_failed->GetBinContent(i);
302 Double_t p_sig = h_passed ->GetBinError(i);
303 Double_t f_sig = h_failed->GetBinError(i);
304
305 if(eff->GetBinContent(i)==0.) continue;
306
307 Double_t dedt = 1/(p+f)-p/((p+f)*(p+f));
308 Double_t dedp = -p/((p+f)*(p+f));
309
310 Double_t eff_sig = sqrt(p_sig*p_sig*dedt*dedt + f_sig*f_sig*dedp*dedp);
311 eff->SetBinError(i, eff_sig);
312 }
313 }
314
315
316 //================================================================================= Loop
317 void Loop(TString inputFileName, TString outputFileName){
318 //timer.Start("Loop");
319 TString treeName = "trigStudyTree";
320 map<TString, plotMaker> myPlots;
321
322 //--------------------------------------------------- open file and read in leafs
323 TFile* inputFile = new TFile(inputFileName,"READ");
324 if (!inputFile->IsOpen()) std::cout<<"Could not open file "<<inputFileName<<std::endl;
325 TTree* inputTree= (TTree*)inputFile->Get(treeName);
326
327 eventInfo event;
328 initBranches(inputTree, event);
329 //--------------------------------------------------- Event Loop
330 int nEvents=inputTree->GetEntries();
331 cout<<endl;
332 cout<<"///////////////////////////////////////////////////////////////////////////////"<<endl;
333 cout<<"////////////////////////////// Starting Event Loop ////////////////////////////"<<endl;
334 cout<<"///////////////////////////////////////////////////////////////////////////////"<<endl;
335 cout<<"Investigate File: " << inputFileName << endl;
336 cout<<"Read out TTree: " << treeName << endl;
337 cout<<"Number of events: " << nEvents << endl;
338 cout<<"-------------------------------------------------------------------------------"<<endl;
339 cout<<endl;
340 cout<<"Looping over events..."<<endl;
341 nEvents=50000;
342 for (int iEvent=0; iEvent<nEvents; ++iEvent){
343 tools::progress(iEvent);
344 inputTree->GetEntry(iEvent);
345 handleTriggerMatchingInfo(event);
346 // printEventInfo(event);
347 // printMuonInfo(event);
348 //printElectronInfo(event);
349 plotHistograms(event, myPlots);
350 //tools::progressReset();
351 }
352
353 makeEfficiencyPlots(myPlots);
354 //--------------------------------------------------- Save all histograms in the appropriate folders
355 TString option="RECREATE";
356 for(typename map<TString, plotMaker>::iterator it = myPlots.begin(); it != myPlots.end(); ++it){
357 it->second.savePlots(outputFileName, option, it->first);
358 option="UPDATE";
359 }
360 //timer.Stop("Loop");
361 }
362
363
364 //================================================================================= handleTriggerMatchingInfo
365 // converting the trigger Info to a more practical format: vector<string> --> vector<vector<string> >
366 void handleTriggerMatchingInfo(eventInfo& evt){
367 evt.triggerFilterEl.clear();
368 evt.triggerFilterMu.clear();
369 //make simple check
370
371 if(evt.electronP4->size() != evt.DESYtriggerElMatchedTriggerFilter->size()){
372 cout<<"WARNING: Size of electron vector does not correspond to size of matching info vector!"<<endl;
373 cout<<"evt.electronP4->size() = " << evt.electronP4->size() << endl;
374 cout<<"evt.DESYtriggerElMatchedTriggerFilter->size() = " << evt.DESYtriggerElMatchedTriggerFilter->size() << endl;
375
376 tools::printVector("evt.electronP4", *(evt.electronP4));
377 tools::printVector("evt.DESYtriggerElMatchedTriggerFilter", *(evt.DESYtriggerElMatchedTriggerFilter));
378
379 return;
380 }
381 if(evt.muonP4->size() != evt.DESYtriggerMuMatchedTriggerFilter->size()){
382 cout<<"WARNING: Size of muon vector does not correspond to size of matching info vector!"<<endl;
383 cout<<"evt.muonP4->size() = " << evt.muonP4->size() << endl;
384 cout<<"evt.DESYtriggerMuMatchedTriggerFilter->size() = " << evt.DESYtriggerMuMatchedTriggerFilter->size() << endl;
385 return;
386 }
387
388 for(Int_t i=0,N=evt.electronP4->size(); i<N; ++i){
389 evt.triggerFilterEl.push_back(tools::splitToWords(evt.DESYtriggerElMatchedTriggerFilter->at(i), ";"));
390 //cout<<"evt.DESYtriggerElMatchedTriggerFilter->at("<<i<<") = " << evt.DESYtriggerElMatchedTriggerFilter->at(i) << endl;
391 //tools::printVector<TString>("triggerFilterEl", evt.triggerFilterEl.at(i));
392 }
393 // printMuonInfo(evt);
394 // printElectronInfo(evt);
395
396 //tools::printVector("evt.triggerFilterMu", evt.triggerFilterMu);
397 // tools::printVector("evt.DESYtriggerMuMatchedTriggerFilter", *(evt.DESYtriggerMuMatchedTriggerFilter));
398 // tools::printVector("evt.muonP4", *(evt.muonP4));
399
400 for(Int_t i=0,N=evt.muonP4->size(); i<N; ++i){
401 evt.triggerFilterMu.push_back(tools::splitToWords(evt.DESYtriggerMuMatchedTriggerFilter->at(i), ";"));
402 //cout<<"evt.DESYtriggerMuMatchedTriggerFilter->at("<<i<<") = " << evt.DESYtriggerMuMatchedTriggerFilter->at(i) << endl;
403 //tools::printVector<TString>("triggerFilterMu", evt.triggerFilterMu.at(i));
404 }
405 //cout<<"size: muonP4 | filterinfo = "
406 //<<evt.muonP4->size() << " | "
407 //<<evt.DESYtriggerMuMatchedTriggerFilter->size()
408 //<<endl;
409 }
410
411
412 //================================================================================= initBranches
413 void initBranches(TTree *tree, eventInfo& evt){
414 //--------------------------------------------------- initialize event info
415 evt.DESYtriggerElMatchedTriggerFilter = 0;
416 evt.DESYtriggerMuMatchedTriggerFilter = 0;
417 evt.DESYtriggerNameMap = 0;
418 evt.electronCharge = 0;
419 evt.electronP4 = 0;
420 evt.Event = 0;
421 evt.HT = 0.;
422 evt.jetP4 = 0;
423 evt.MET = 0.;
424 evt.muonCharge = 0;
425 evt.muonP4 = 0;
426 evt.prescaled = 0;
427 evt.Run = 0;
428 evt.PUInter = 0.;
429 evt.PUWeight = 0.;
430 evt.triggered = 0;
431 evt.Weight = 0.;
432 //--------------------------------------------------- assign branches to event structure
433 tree->SetBranchAddress("DESYtriggerElMatchedTriggerFilter", &(evt.DESYtriggerElMatchedTriggerFilter));
434 tree->SetBranchAddress("DESYtriggerMuMatchedTriggerFilter",&(evt.DESYtriggerMuMatchedTriggerFilter));
435 tree->SetBranchAddress("DESYtriggerNameMap",&(evt.DESYtriggerNameMap));
436 tree->SetBranchAddress("electronCharge",&(evt.electronCharge));
437 tree->SetBranchAddress("electronP4",&(evt.electronP4));
438 tree->SetBranchAddress("Event",&(evt.Event));
439 tree->SetBranchAddress("HT",&(evt.HT));
440 tree->SetBranchAddress("jetP4",&(evt.jetP4));
441 tree->SetBranchAddress("MET",&(evt.MET));
442 tree->SetBranchAddress("muonCharge",&(evt.muonCharge));
443 tree->SetBranchAddress("muonP4",&(evt.muonP4));
444 tree->SetBranchAddress("prescaled",&(evt.prescaled));
445 tree->SetBranchAddress("Run",&(evt.Run));
446 tree->SetBranchAddress("PUInter",&(evt.PUInter));
447 tree->SetBranchAddress("PUWeight",&(evt.PUWeight));
448 tree->SetBranchAddress("triggered",&(evt.triggered));
449 tree->SetBranchAddress("Weight",&(evt.Weight));
450 }
451
452
453 //================================================================================= printEventInfo
454 void printEventInfo(eventInfo& evt, ostream& os){
455 os<<endl;
456 os<<"///////////////////////////////////////////////////////"<<endl;
457 os<<"///////////////////// Event Info //////////////////////"<<endl;
458 os<<"///////////////////////////////////////////////////////"<<endl;
459 os<<endl;
460 os<<"-----------------------------------------"<<endl;
461 os<<"Run = "<<evt.Run<<endl;
462 os<<"Event = "<<evt.Event<<endl;
463 os<<"Weight = "<<evt.Weight<<endl;
464 os<<"PUWeight = "<<evt.PUWeight<<endl;
465 os<<"PUInter = "<<evt.PUInter<<endl;
466 os<<"-----------------------------------------"<<endl;
467 os<<"HT = "<<evt.HT<<endl;
468 os<<"MET = "<<evt.MET<<endl;
469 os<<"-----------------------------------------"<<endl;
470 os<<"No. of Muons = "<<evt.muonP4->size()<<endl;
471 os<<"No. of Electrons = "<<evt.electronP4->size()<<endl;
472 os<<"No. of Jets = "<<evt.jetP4->size()<<endl;
473 os<<"-----------------------------------------"<<endl;
474 os<<"muonCharge.size() = "<<evt.muonCharge->size()<<endl;
475 os<<"electronCharge.size() = "<<evt.electronCharge->size()<<endl;
476 os<<"-----------------------------------------"<<endl;
477 os<<"MuMatchedTriggerFilter.size() = "<<evt.DESYtriggerMuMatchedTriggerFilter->size()<<endl;
478 os<<"ElMatchedTriggerFilter.size() = "<<evt.DESYtriggerElMatchedTriggerFilter->size()<<endl;
479 os<<"-----------------------------------------"<<endl;
480 os<<"triggered.size() = "<<evt.triggered->size()<<endl;
481 os<<"prescaled.size() = "<<evt.prescaled->size()<<endl;
482 os<<"DESYTriggerMap.size() = "<<evt.DESYtriggerNameMap->size()<<endl;
483 os<<"-----------------------------------------"<<endl;
484 os<<endl;
485
486 //tools::printVector<string>("jetP4", *(evt.jetP4));
487 //tools::printVector<string>("DESYtriggerMuMatchedTriggerFilter", *(evt.DESYtriggerMuMatchedTriggerFilter));
488 //tools::printVector<string>("DESYtriggerElMatchedTriggerFilter", *(evt.DESYtriggerElMatchedTriggerFilter));
489 //tools::printVector<string>("DESYtriggerNameMap", *(evt.DESYtriggerNameMap));
490 //tools::printVector<string>("prescaled", *(evt.prescaled));
491 //tools::printVector<string>("triggered", *(evt.triggered));
492 }
493
494
495 //================================================================================= printMuonInfo
496 void printMuonInfo(eventInfo& evt, ostream& os){
497 os<<endl;
498 os<<"///////////////////////////////////////////////////////"<<endl;
499 os<<"////////////////////// Muon Info //////////////////////"<<endl;
500 os<<"///////////////////////////////////////////////////////"<<endl;
501 os<<endl;
502 tools::printVector<LorentzM>("muonP4", *(evt.muonP4), os);
503 tools::printVector<int>("muonCharge", *(evt.muonCharge), os);
504 //------------------------ print invariant mass from all possible muon pairs
505 if(evt.muonP4->size()>=2){
506 os<<"-------------> Invariant masses of all possible muon pairs:"<<endl;
507 for(Int_t i=0,N=evt.muonP4->size(); i<N-1; ++i){
508 for(Int_t j=i+1; j<N; ++j){
509 Double_t minv = (evt.muonP4->at(i) + evt.muonP4->at(j)).mass();
510 os<<"Minv("<<i<<" + " <<j<<") = "<<minv<<endl;
511 }
512 }
513 os<<endl;
514 }
515 //------------------------ print matching info
516 for(Int_t i=0,N=evt.muonP4->size(); i<N; ++i){
517 os<<"----------------------------------------------------------------------------> Matches for muon "<<i<<":"<<
518 endl;
519 tools::printVector<TString>("matched TriggerFilter", evt.triggerFilterMu.at(i), os);
520 }
521 os<<endl;
522 }
523
524
525 //================================================================================= printElectronInfo
526 void printElectronInfo(eventInfo& evt, ostream& os){
527 os<<endl;
528 os<<"///////////////////////////////////////////////////////"<<endl;
529 os<<"///////////////////// Electron Info ///////////////////"<<endl;
530 os<<"///////////////////////////////////////////////////////"<<endl;
531 os<<endl;
532 tools::printVector<LorentzM>("electronP4", *(evt.electronP4), os);
533 tools::printVector<int>("electronCharge", *(evt.electronCharge), os);
534 //------------------------ print invariant mass from all possible electron pairs
535 if(evt.electronP4->size()>=2){
536 os<<"-------------> Invariant masses of all possible electron pairs:"<<endl;
537 for(Int_t i=0,N=evt.electronP4->size(); i<N-1; ++i){
538 for(Int_t j=i+1; j<N; ++j){
539 Double_t minv = (evt.electronP4->at(i) + evt.electronP4->at(j)).mass();
540 os<<"Minv("<<i<<" + " <<j<<") = "<<minv<<endl;
541 }
542 }
543 os<<endl;
544 }
545 //------------------------ print matching info
546 for(Int_t i=0,N=evt.electronP4->size(); i<N; ++i){
547 os<<"----------------------------------------------------------------------------> Matches for electron "<<i<<":"<<
548 endl;
549 tools::printVector<TString>("matched TriggerFilter", evt.triggerFilterEl.at(i), os);
550 }
551 os<<endl;
552 }
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568 //Thats another version of implementing the T&P method
569 //This version uses ALL Objects within an event to extract the trigger efficiency.
570 //However, this method leads to a more complex treatment of the counting and the error propagation.
571 //The advantage is higher statistict. But the statistis is anayhow large enough...
572 // //================================================================================= investigateTriggerFilterMu
573 // // eff = 2*NTT / (2*NTT + NTP)
574 // void investigateTriggerFilterMu(eventInfo& evt, map<TString, plotMaker> &plot, TString filterName){
575 // //create vector which stores, if a muon is matched to the trigger filter with the name "filterName"
576 // vector<bool> matched;
577 // vector<int> probeIndex;
578 // for(Int_t i=0,N=evt.muonP4->size(); i<N; ++i){
579 // matched.push_back(false);
580 // for(Int_t j=0,M=evt.triggerFilterMu.at(i).size(); j<M; ++j){
581 // if(filterName == evt.triggerFilterMu.at(i).at(j)){
582 // matched.back() = true;
583 // break;
584 // }
585 // }
586 // if(!matched.at(i)) probeIndex.push_back(i);
587 // }
588 //
589 // if(probeIndex.size()>2){
590 // cout<<"WARNING: Something is awkward with the number of Probe leptons: " << probeIndex.size() << endl;
591 // cout<<"The number of probe leptons is expected to be 1 or 2, because here a T&P method is applied!" << endl;
592 // }
593 // else if(probeIndex.size()==2) return; //make only plots if at least one Tag exists in an event
594 //
595 // //Fill the Tag histograms
596 // //here, we have TWO Tag leptons -> use BOTH for the efficiency
597 // if(probeIndex.size()==0){
598 // for(Int_t i=0,N=evt.muonP4->size(); i<N; ++i){
599 // plot[filterName].addh1d("pt_tag", "pt_tag", "p_{T}(tag) [GeV/c]", "events", binPt, lowPt, upPt, evt.muonP4->at(i).Pt(), evt.Weight);
600 // plot[filterName].addh1d("eta_tag", "eta_tag", "#eta(tag)", "events", binEta, lowEta, upEta, evt.muonP4->at(i).eta(), evt.Weight);
601 // }
602 // //the factor of '2' is due to the fact, that there are two matched tag leptons
603 // plot[filterName].addh1d("PUVertices_tag", "PUVertices_tag", "number of primary vertices (tag)", "events", binPU, lowPU, upPU, evt.PUInter, 2*evt.Weight);
604 // }
605 //
606 // //Fill the Probe histograms
607 // //here, we have ONE Tag lepton -> the probe is NOT matched to the trigger filter
608 // if(probeIndex.size()==1){
609 // plot[filterName].addh1d("pt_probe", "pt_probe", "p_{T}(probe) [GeV/c]", "events", binPt, lowPt, upPt, evt.muonP4->at(probeIndex.back()).pt(), evt.Weight);
610 // plot[filterName].addh1d("eta_probe", "eta_probe", "#eta(probe)", "events", binEta, lowEta, upEta, evt.muonP4->at(probeIndex.back()).eta(), evt.Weight);
611 // plot[filterName].addh1d("PUVertices_probe", "PUVertices_probe", "number of primary vertices (probe)", "events", binPU, lowPU, upPU, evt.PUInter, evt.Weight);
612 // }
613 // }
614 //
615 //
616 // //================================================================================= makeEfficiencyPlots
617 // //eff = tag/(tag+probe)
618 // void makeEfficiencyPlots(map<TString, plotMaker> &plot){
619 // cout<<"----------> Create efficiency histograms"<<endl;
620 //
621 // vector<string> allTriggerFiltersToCheck = triggerFilterToCheckMu;
622 // for(Int_t i=0,N=triggerFilterToCheckEl.size(); i<N; ++i){
623 // allTriggerFiltersToCheck.push_back(triggerFilterToCheckEl.at(i));
624 // }
625 // vector<string> histNames;
626 // histNames.push_back("pt_tag");
627 // histNames.push_back("eta_tag");
628 // histNames.push_back("PUVertices_tag");
629 //
630 // for(Int_t i=0,N=allTriggerFiltersToCheck.size(); i<N; ++i){
631 // TString triggerFilter = allTriggerFiltersToCheck.at(i);
632 // for(Int_t j=0,M=histNames.size(); j<M; ++j){
633 // TString tagName = histNames.at(j);
634 // TString probeName = histNames.at(j);
635 // TString effName = histNames.at(j);
636 // probeName.ReplaceAll("tag", "probe");
637 // effName.ReplaceAll("tag", "eff");
638 // if(plot[triggerFilter].isNewh1d(tagName)) continue;
639 // if(plot[triggerFilter].isNewh1d(probeName)) continue;
640 //
641 // TH1D *h_tag = (TH1D*)(plot[triggerFilter].h1d[tagName])->Clone();
642 // TH1D *h_probe = (TH1D*)(plot[triggerFilter].h1d[probeName])->Clone();
643 // TH1D *den = (TH1D*)(h_tag)->Clone();
644 // den->Add((TH1D*)(h_probe)->Clone());
645 //
646 // TH1D *eff = (TH1D*)(h_tag)->Clone();
647 // eff->Divide(den);
648 // setEfficiencyErrors(eff, h_tag, h_probe);
649 //
650 // eff->SetName(effName);
651 // eff->SetTitle(effName);
652 //
653 // TString xTitle_eff = eff->GetXaxis()->GetTitle();
654 // xTitle_eff.ReplaceAll("(tag)","");
655 // eff->GetXaxis()->SetTitle(xTitle_eff);
656 // eff->GetYaxis()->SetTitle("efficiency");
657 // //eff->SetAxisRange(0.,1.,"Y");
658 // plot[triggerFilter].addh1d(eff);
659 // }
660 // }
661 // }
662 //
663 //
664 // //================================================================================= setEfficiencyErrors
665 // // f(eff) = t/(t+p)
666 // // df/dt = 1/(t+p) - t/(t+p)^2
667 // // df/dp = - t/(t+p)^2
668 // // eff_sig = sqrt(t_sig^2*(df/dt)^2 + p_sig^2*(df/dp)^2)
669 // void setEfficiencyErrors(TH1D* &eff, TH1D* &h_tag, TH1D* &h_probe){
670 // if(h_tag->GetNbinsX() != h_probe->GetNbinsX()){
671 // cout<<"WARNING: the number of bins of the tag and probe histograms differ! The efficiency calculation might be depricated!"<<endl;
672 // cout<<"Number of bins (Tag | Probe): " << h_tag->GetNbinsX() << " | " << h_probe->GetNbinsX() << endl;
673 // }
674 // if(h_tag->GetXaxis()->GetXmax() != h_probe->GetXaxis()->GetXmax()){
675 // cout<<"WARNING: the upper x-range of the tag and probe histograms differ! The efficiency calculation might be depricated!"<<endl;
676 // cout<<"Number of bins (Tag | Probe): " << h_tag->GetXaxis()->GetXmax() << " | " << h_probe->GetXaxis()->GetXmax() << endl;
677 // }
678 // if(h_tag->GetXaxis()->GetXmin() != h_probe->GetXaxis()->GetXmin()){
679 // cout<<"WARNING: the lower x-range of the tag and probe histograms differ! The efficiency calculation might be depricated!"<<endl;
680 // cout<<"Number of bins (Tag | Probe): " << h_tag->GetXaxis()->GetXmin() << " | " << h_probe->GetXaxis()->GetXmin() << endl;
681 // }
682 // //loop over single bins of histograms an set the efficiency error
683 // for(Int_t i=1,N=h_tag->GetNbinsX(); i<=N; ++i){
684 // Double_t t = h_tag ->GetBinContent(i);
685 // Double_t p = h_probe->GetBinContent(i);
686 // Double_t t_sig = h_tag ->GetBinError(i);
687 // Double_t p_sig = h_probe->GetBinError(i);
688 //
689 // if(eff->GetBinContent(i)==0.) continue;
690 //
691 // Double_t dedt = 1/(t+p)-t/((t+p)*(t+p));
692 // Double_t dedp = -t/((t+p)*(t+p));
693 //
694 // Double_t eff_sig = sqrt(t_sig*t_sig*dedt*dedt + p_sig*p_sig*dedp*dedp);
695 // eff->SetBinError(i, eff_sig);
696 // }
697 // }
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723