ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/NonMCBackground/src/select_fakes.cc
Revision: 1.5
Committed: Tue Jun 19 17:11:28 2012 UTC (12 years, 11 months ago) by dkralph
Content type: text/plain
Branch: MAIN
Changes since 1.4: +1 -0 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 dkralph 1.2 //
2     // System headers
3     //
4     #include <vector> // STL vector class
5     #include <iostream> // standard I/O
6     #include <iomanip> // functions to format standard I/O
7     #include <bitset>
8     #include <map>
9     using namespace std;
10    
11     //
12     // root headers
13     //
14     #include <TFile.h>
15     #include <TTree.h>
16     #include <TChain.h>
17     #include <TBranch.h>
18     #include <TClonesArray.h>
19    
20     //
21     // TMVA
22     //
23     #include "TMVA/Reader.h"
24     #include "TMVA/Tools.h"
25     #include "TMVA/Config.h"
26     #include "TMVA/MethodBDT.h"
27    
28     //
29     // ntuple format headers
30     //
31     #include "EventHeader.h"
32     #include "PFMet.h"
33     #include "Electron.h"
34     #include "Muon.h"
35     #include "Vertex.h"
36     #include "PFCandidate.h"
37     #include "PFCandidateCol.h"
38     #include "PileupInfoCol.h"
39     #include "PileupEnergyDensity.h"
40     #include "MCParticle.h"
41     #include "MCEventInfo.h"
42     #include "TriggerMask.h"
43     #include "TriggerTable.h"
44     #include "Names.h"
45     #include "BaseMod.h"
46    
47     //
48     // our headers
49     //
50     #include "ParseArgs.h"
51     #include "MuonSelection.h"
52     #include "ElectronSelection.h"
53     #include "IsolationSelection.h"
54 dkralph 1.3 #include "SelectionFuncs.h"
55 dkralph 1.2
56     #include "TriggerUtils.h"
57     #include "PassHLT.h"
58     #include "RunLumiRangeMap.h"
59 dkralph 1.3 #include "fake_defs.h"
60 dkralph 1.5 #include "Various.h"
61 dkralph 1.2 #include "CommonDefs.h"
62    
63     #ifndef CMSSW_BASE
64     #define CMSSW_BASE "../"
65     #endif
66    
67     using namespace mithep;
68     //
69     // globals
70     //----------------------------------------------------------------------------
71     TH1D * hpu;
72     mithep::RunLumiRangeMap rlrm;
73     vector<SimpleLepton> failingLeptons ; // for fake estimation
74     vector<SimpleLepton> passingLeptons; // for fake estimation
75     vector<unsigned> cutvec;
76     vector<vector<unsigned> > zcutvec;
77     vector<vector<unsigned> > zzcutvec;
78     map<unsigned,float> evtrhoMap;
79     vector<string> cutstrs;
80     bool passes_HLT_MC;
81     vector<bool> PFnoPUflag;;
82    
83     //
84     // prototypes
85     //----------------------------------------------------------------------------
86     void initRunLumiRangeMap();
87    
88     mithep::MuonTools::EMuonEffectiveAreaTarget eraMu;
89     mithep::ElectronTools::EElectronEffectiveAreaTarget eraEle;
90     vector<const mithep::PFCandidate*> photonsToVeto;
91     //
92     // globals
93     //----------------------------------------------------------------------------
94    
95     void fill_muon_fakes(ControlFlags &ctrl,
96     mithep::Array<mithep::Muon> *muonArr,
97 dkralph 1.4 mithep::Array<mithep::Electron> *electronArr,
98 dkralph 1.2 mithep::Array<mithep::PFJet> *jetArr,
99     mithep::Array<mithep::PFCandidate> *pfArr,
100     mithep::Array<mithep::PileupEnergyDensity> *puDArr,
101     const mithep::Vertex *vtx,
102     foinfo &foi,
103     const mithep::Muon *zmu1,
104     const mithep::Muon *zmu2,
105     const mithep::Electron *zele1,
106     const mithep::Electron *zele2);
107     void fill_electron_fakes(ControlFlags &ctrl,
108 dkralph 1.4 mithep::Array<mithep::Muon> *muonArr,
109 dkralph 1.2 mithep::Array<mithep::Electron> *electronArr,
110     mithep::Array<mithep::PFJet> *jetArr,
111     mithep::Array<mithep::PFCandidate> *pfArr,
112     mithep::Array<mithep::PileupEnergyDensity> *puDArr,
113     const mithep::Vertex *vtx,
114     foinfo &foi,
115     const mithep::Muon *zmu1,
116     const mithep::Muon *zmu2,
117     const mithep::Electron *zele1,
118     const mithep::Electron *zele2);
119 dkralph 1.1
120     //=== MAIN =================================================================================================
121     int main(int argc, char** argv)
122     {
123 dkralph 1.2
124     string cmsswpath(CMSSW_BASE);
125     cmsswpath.append("/src");
126     std::bitset<1024> triggerBits;
127 dkralph 1.1 vector<vector<string> > inputFiles;
128     inputFiles.push_back(vector<string>());
129 dkralph 1.2 map<string,unsigned> entrymap; // number of unskimmed entries in each file
130 dkralph 1.1
131     //
132     // args
133     //--------------------------------------------------------------------------------------------------------------
134     ControlFlags ctrl;
135     parse_args( argc, argv, ctrl );
136     ctrl.dump();
137    
138     //
139     // File I/O
140     //--------------------------------------------------------------------------------------------------------------
141     TChain * chain = new TChain("Events");
142 dkralph 1.2 TChain * hltchain = new TChain("HLT");
143    
144 dkralph 1.1 string fname;
145 dkralph 1.2 unsigned total_unskimmed=0;
146     if( !ctrl.inputfiles.empty() ) {
147     ifstream f(ctrl.inputfiles.c_str());
148     while (f >> fname) {
149     if( !(strncmp( fname.c_str(), "#", 1 ) ) ) continue; // skip commented lines
150     cout << "adding inputfile : " << fname.c_str() << endl;
151     entrymap[string(fname.c_str())] = unskimmedEntries(fname.c_str());
152     total_unskimmed += entrymap[string(fname.c_str())];
153     chain->AddFile(fname.c_str());
154     hltchain->AddFile(fname.c_str());
155     }
156     } else {
157     cout << "adding inputfile : " << ctrl.inputfile.c_str() << endl;
158     unsigned unsk_ents = unskimmedEntries(ctrl.inputfile.c_str());
159     entrymap[string(ctrl.inputfile.c_str())] = unsk_ents;
160     total_unskimmed += unsk_ents;
161     chain->AddFile(ctrl.inputfile.c_str());
162     hltchain->AddFile(ctrl.inputfile.c_str());
163 dkralph 1.1 }
164 dkralph 1.2 // write the total number of unskimmed events that went into making this output file to a text file
165     writeEntries(ctrl,total_unskimmed);
166 dkralph 1.1
167 dkralph 1.2 foinfo foi;
168     foi.nEvents=0;
169     foi.nDenom=0;
170     foi.nNumer=0;
171 dkralph 1.1
172 dkralph 1.2 double metMax = 25;
173 dkralph 1.1
174     //
175     // Setup
176     //--------------------------------------------------------------------------------------------------------------
177     const char * ofname;
178     if( strcmp( ctrl.outputfile.c_str(), "") ) {
179     ofname = ctrl.outputfile.c_str();
180     } else {
181     ofname = "fo.root";
182     }
183    
184     TFile *outFile = new TFile(ofname, "RECREATE");
185     TTree *outTree = new TTree("FO","FO");
186 dkralph 1.2 foi.outTree = outTree;
187     outTree->Branch("pt", &foi.fopt, "pt/F");
188     outTree->Branch("eta", &foi.foeta, "eta/F");
189     outTree->Branch("phi", &foi.fophi, "phi/F");
190     outTree->Branch("pass", &foi.fopass,"pass/F");
191     outTree->Branch("jpt", &foi.jpt,"jpt/F");
192    
193     // initMuonIDMVA();
194     getEATargets(ctrl,eraMu,eraEle);
195     initElectronIDMVAV1();
196     initMuonIsoMVA();
197     initElectronIDMVA();
198     initElectronIsoMVA();
199     initTrigger();
200     if(!ctrl.mc)
201     initRunLumiRangeMap();
202 dkralph 1.1
203     //
204     // Access samples and fill histograms
205     TFile *inputFile=0;
206     TTree *eventTree=0;
207 dkralph 1.2 string currentFile("");
208 dkralph 1.1
209 dkralph 1.2 mithep::EventHeader *info = new mithep::EventHeader();
210     mithep::Array<mithep::PFMet> *metArr = new mithep::Array<mithep::PFMet>();
211     mithep::Array<mithep::Electron> *electronArr = new mithep::Array<mithep::Electron>();
212     mithep::Array<mithep::Muon> *muonArr = new mithep::Array<mithep::Muon>();
213     mithep::Array<mithep::Vertex> *vtxArr = new mithep::Array<mithep::Vertex>();
214     mithep::Array<mithep::PFCandidate> *pfArr = new mithep::Array<mithep::PFCandidate>();
215     mithep::Array<mithep::PFJet> *jetArr = new mithep::Array<mithep::PFJet>();
216     mithep::Array<mithep::PileupInfo> *puArr = new mithep::Array<mithep::PileupInfo>();
217     mithep::Array<mithep::PileupEnergyDensity> *puDArr = new mithep::Array<mithep::PileupEnergyDensity>();
218     mithep::Array<mithep::Track> *trkArr = new mithep::Array<mithep::Track>();
219     mithep::Array<mithep::MCParticle> *mcArr = new mithep::Array<mithep::MCParticle>();
220     mithep::MCEventInfo *mcEvtInfo = new mithep::MCEventInfo();
221     mithep::TriggerMask *trigMask = new mithep::TriggerMask();
222     mithep::TriggerTable *hltTable = new mithep::TriggerTable();
223     vector<string> *hltTableStrings = new vector<string>();
224    
225     TString fElectronName(Names::gkElectronBrn);
226     TString fMuonName(Names::gkMuonBrn);
227     TString fInfoName(Names::gkEvtHeaderBrn);
228     TString fPFMetName("PFMet");
229     TString fPrimVtxName(Names::gkPVBrn);
230     TString fPFCandidateName(Names::gkPFCandidatesBrn);
231     TString fPFJetName(Names::gkPFJetBrn);
232     TString fPileupInfoName(Names::gkPileupInfoBrn);
233     TString fPileupEnergyDensityName(Names::gkPileupEnergyDensityBrn);
234     TString fTrackName(Names::gkTrackBrn);
235     TString fMCParticleName(Names::gkMCPartBrn);
236     TString fMCEvtInfoName(Names::gkMCEvtInfoBrn);
237     TString fTriggerMaskName(Names::gkHltBitBrn);
238     TString fTriggerTableName(Names::gkHltTableBrn);
239    
240     chain->SetBranchAddress(fInfoName, &info);
241     chain->SetBranchAddress(fPFMetName, &metArr);
242     chain->SetBranchAddress(fElectronName, &electronArr);
243     chain->SetBranchAddress(fMuonName, &muonArr);
244     chain->SetBranchAddress(fPrimVtxName, &vtxArr);
245     chain->SetBranchAddress(fPFCandidateName, &pfArr);
246     chain->SetBranchAddress(fPFJetName, &jetArr);
247     if( ctrl.mc ) {
248     chain->SetBranchAddress(fPileupInfoName, &puArr);
249     chain->SetBranchAddress(fMCParticleName, &mcArr);
250     chain->SetBranchAddress(fMCEvtInfoName, &mcEvtInfo);
251     }
252     chain->SetBranchAddress(fPileupEnergyDensityName, &puDArr);
253     chain->SetBranchAddress(fTrackName, &trkArr);
254     chain->SetBranchAddress(fTriggerMaskName, &trigMask);
255     cout << "hlttable: " << fTriggerTableName << endl;
256     hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings);
257    
258     const mithep::Vertex *vtx; // best primary vertex in the event
259 dkralph 1.1
260 dkralph 1.2 // ginfo = NULL;
261     // if( ctrl.mc ) { chain->SetBranchAddress("Gen", &ginfo);}
262    
263     // only 1 HLT table / file ???
264     hltchain->GetEntry(0);
265    
266     int imax = chain->GetEntries();
267     cout << "nEntries: " << imax << endl;
268 dkralph 1.1 for(UInt_t ientry=0; ientry<imax; ientry++) {
269     chain->GetEntry(ientry);
270 dkralph 1.2 if(!(ientry%10000)) cout << "entry: " << ientry << "\tfrac: " << setw(15) << float(ientry)/chain->GetEntries() << endl;
271    
272     // pfNoPU
273     PFnoPUflag.clear();
274     int pfnopu_size = makePFnoPUArray( pfArr, PFnoPUflag, vtxArr );
275     assert(pfnopu_size == pfArr->GetEntries());
276    
277     // // check for certified runs
278     // mithep::RunLumiRangeMap::RunLumiPairType rl(info->runNum, info->lumiSec);
279     // if(!rlrm.HasRunLumi(rl)) { if(ctrl.debug) cout << "\tfailing rlrm..." << endl; continue; }
280    
281     foi.nEvents++;
282 dkralph 1.1
283 dkralph 1.2 setPV( ctrl, vtxArr, vtx);
284 dkralph 1.1
285 dkralph 1.2 TLorentzVector pfmet; pfmet.SetPxPyPzE(metArr->At(0)->Mex(),metArr->At(0)->Mey(),0,0);
286     if(pfmet.Pt() > metMax) continue;
287 dkralph 1.1
288 dkralph 1.2 // good lepton selection
289     vector<const mithep::Muon*> goodMuons;
290     vector<const mithep::Electron*> goodElectrons;
291     for(int imu=0; imu<muonArr->GetEntries(); imu++) {
292     const mithep::Muon *mu = (*muonArr)[imu];
293     SelectionStatus status = muonReferencePreSelection(ctrl,mu,vtx,pfArr);
294     if( !status.passPre() ) continue;
295     goodMuons.push_back(mu);
296     }
297     int NElectrons=0;
298 dkralph 1.1 for(Int_t i=0; i<electronArr->GetEntries(); i++) {
299 dkralph 1.2 const mithep::Electron *ele = (*electronArr)[i];
300     if(ele->Pt() > 5) NElectrons++;
301     SelectionStatus status = electronReferencePreSelection(ctrl,ele,vtx);
302     if( !status.passPre() ) continue;
303 dkralph 1.4 bool muonMatch=false;
304     for(unsigned imu=0; imu<muonArr->GetEntries(); imu++) {
305     const mithep::Muon *mu = (*muonArr)[imu];
306     if(dr(mu,ele) < 0.05) muonMatch = true;
307     }
308     if(muonMatch) { cout << "matched to muon in lepton counter!" << endl; continue; }
309 dkralph 1.2 //????????????????????????????????????????????????????????????????????????????????????????
310     // add in iso here?
311     //????????????????????????????????????????????????????????????????????????????????????????
312     goodElectrons.push_back(ele);
313 dkralph 1.1 }
314    
315 dkralph 1.2 // look for z pairs
316     int NZCandidates=0;
317     const mithep::Muon *zmu1=0,*zmu2=0;
318     const mithep::Electron *zele1=0,*zele2=0;
319     for(unsigned imu=0; imu<goodMuons.size(); imu++) {
320     TLorentzVector mu1;
321     mu1.SetPtEtaPhiM(goodMuons[imu]->Pt(),goodMuons[imu]->Eta(),goodMuons[imu]->Phi(),MUON_MASS);
322     for(unsigned jmu=imu+1; jmu<goodMuons.size(); jmu++) {
323     TLorentzVector mu2;
324     mu2.SetPtEtaPhiM(goodMuons[jmu]->Pt(),goodMuons[jmu]->Eta(),goodMuons[jmu]->Phi(),MUON_MASS);
325     TLorentzVector dimu(mu1+mu2);
326     if(dimu.M() < 75 || dimu.M() > 105) continue;
327     if(goodMuons[imu]->Charge() == goodMuons[jmu]->Charge()) continue;
328    
329     zmu1 = goodMuons[imu];
330     zmu2 = goodMuons[jmu];
331     NZCandidates++;
332     }
333     }
334     for(unsigned iele=0; iele<goodElectrons.size(); iele++) {
335     TLorentzVector ele1;
336     ele1.SetPtEtaPhiM(goodElectrons[iele]->Pt(),goodElectrons[iele]->Eta(),goodElectrons[iele]->Phi(),ELECTRON_MASS);
337     for(unsigned jele=iele+1; jele<goodElectrons.size(); jele++) {
338     TLorentzVector ele2;
339     ele2.SetPtEtaPhiM(goodElectrons[jele]->Pt(),goodElectrons[jele]->Eta(),goodElectrons[jele]->Phi(),ELECTRON_MASS);
340     TLorentzVector diele(ele1+ele2);
341     if(diele.M() < 75 || diele.M() > 105) continue;
342     if(goodElectrons[iele]->Charge() == goodElectrons[jele]->Charge()) continue;
343    
344     zele1 = goodElectrons[iele];
345     zele2 = goodElectrons[jele];
346     NZCandidates++;
347 dkralph 1.1 }
348 dkralph 1.2 }
349    
350     if(NZCandidates!=1) continue;
351     int ZDecayType = (zmu1 && zmu2) ? 13 : 11;
352    
353     // we want only one jet...
354     if(ZDecayType==11 && NElectrons > 3) continue;
355     if(ZDecayType==13 && NElectrons > 1) continue;
356    
357     // pointless...
358     if(zele1) assert(zele2 && !zmu1 && !zmu2);
359     if(zele2) assert(zele1 && !zmu1 && !zmu2);
360     if(zmu1) assert(zmu2 && !zele1 && !zele2);
361     if(zmu2) assert(zmu1 && !zele1 && !zele2);
362    
363     if(ctrl.fakeScheme.Contains("mu_")) {
364 dkralph 1.4 fill_muon_fakes(ctrl,muonArr,electronArr,jetArr,pfArr,puDArr,vtx,foi,zmu1,zmu2,zele1,zele2);
365 dkralph 1.2 } else if(ctrl.fakeScheme.Contains("ele_")) {
366 dkralph 1.4 fill_electron_fakes(ctrl,muonArr,electronArr,jetArr,pfArr,puDArr,vtx,foi,zmu1,zmu2,zele1,zele2);
367 dkralph 1.2 } else assert(0);
368 dkralph 1.1
369    
370 dkralph 1.2 }
371    
372 dkralph 1.1 outFile->Write();
373     outFile->Close();
374 dkralph 1.2
375 dkralph 1.1 //--------------------------------------------------------------------------------------------------------------
376     // Summary print out
377     //==============================================================================================================
378     cout << endl;
379     cout << "*" << endl;
380     cout << "* SUMMARY" << endl;
381     cout << "*--------------------------------------------------" << endl;
382     cout << endl;
383    
384 dkralph 1.2 cout << " >>> No. of events processed: " << foi.nEvents << endl;
385     cout << " >>> No. of denominator objects: " << foi.nDenom << endl;
386     cout << " >>> No. of numerator objects: " << foi.nNumer << endl;
387     cout << " >>> ratio: " << float(foi.nNumer)/foi.nDenom << endl;
388 dkralph 1.1 cout << endl;
389    
390 dkralph 1.2 TString outputDir(ofname);
391     outputDir = outputDir(0,outputDir.Last('/'));
392 dkralph 1.1 ofstream txtfile;
393     char txtfname[100];
394 dkralph 1.2 TString txtname(ctrl.outputfile);
395     txtname.ReplaceAll(".root",".txt");
396     cout << "writing text to: " << txtname << endl;
397     txtfile.open(txtname);
398 dkralph 1.1 txtfile << "*" << endl;
399     txtfile << "* SUMMARY" << endl;
400     txtfile << "*--------------------------------------------------" << endl;
401     txtfile << endl;
402    
403 dkralph 1.2 txtfile << " >>> No. of events processed: " << foi.nEvents << endl;
404     txtfile << " >>> No. of denominator objects: " << foi.nDenom << endl;
405     txtfile << " >>> No. of numerator objects: " << foi.nNumer << endl;
406     txtfile << " >>> ratio: " << float(foi.nNumer)/foi.nDenom << endl;
407 dkralph 1.1 txtfile << endl;
408     txtfile.close();
409    
410     cout << " <> Output saved in " << outputDir << "/" << endl;
411     cout << endl;
412    
413     cout << "done!" << endl;
414 dkralph 1.2 }
415     //----------------------------------------------------------------------------------------
416     void fill_muon_fakes(ControlFlags &ctrl,
417     mithep::Array<mithep::Muon> *muonArr,
418 dkralph 1.4 mithep::Array<mithep::Electron> *electronArr,
419 dkralph 1.2 mithep::Array<mithep::PFJet> *jetArr,
420     mithep::Array<mithep::PFCandidate> *pfArr,
421     mithep::Array<mithep::PileupEnergyDensity> *puDArr,
422     const mithep::Vertex *vtx,
423     foinfo &foi,
424     const mithep::Muon *zmu1,
425     const mithep::Muon *zmu2,
426     const mithep::Electron *zele1,
427     const mithep::Electron *zele2)
428     {
429    
430     // count denominator and numerator objects
431     for(Int_t imu=0; imu<muonArr->GetEntries(); imu++) {
432     const mithep::Muon* mu = (*muonArr)[imu];
433     if(ctrl.debug) cout << "\t\timu: " << imu << endl;
434    
435     if(mu==zmu1 || mu==zmu2) { if(ctrl.debug) cout << "\t\tdecayed from the z..." << endl; continue; }
436     if(zele1 && dr(mu,zele1) < 0.3) { if(ctrl.debug) cout << "\t\tdr-matched to zele1" << endl; continue; }
437     if(zele2 && dr(mu,zele2) < 0.3) { if(ctrl.debug) cout << "\t\tdr-matched to zele2" << endl; continue; }
438     if(zmu1 && dr(mu,zmu1) < 0.3) { if(ctrl.debug) cout << "\t\tdr-matched to zmu1" << endl; continue; }
439     if(zmu2 && dr(mu,zmu2) < 0.3) { if(ctrl.debug) cout << "\t\tdr-matched to zmu2" << endl; continue; }
440    
441     //find leading jet in the event
442     Double_t leadingJetPt = -1;
443     for(Int_t j=0; j<jetArr->GetEntries(); j++) {
444     const mithep::PFJet *jet = (*jetArr)[j];
445     if (jet->Pt() > leadingJetPt && dr(jet,mu) > 1) {
446     leadingJetPt = jet->Pt();
447     }
448     }
449 dkralph 1.1
450 dkralph 1.2 // denominator definition
451     if(mu->Pt() < 5 || mu->Pt() > 35) { if(ctrl.debug) cout << "\t\tfails pt: " << mu->Pt() << endl; continue; }
452     SelectionStatus musel;
453     musel |= muonReferencePreSelection(ctrl,mu,vtx,pfArr);;
454     if( !musel.passPre() ) { if(ctrl.debug) cout << "\t\tfails mu presection..." << endl; continue; }
455    
456     foi.nDenom++;
457     if(ctrl.debug) cout << "\t\tdenominator: " << foi.nDenom << endl;
458    
459     // numerator definition
460     musel |= muonIDPFSelection(ctrl,mu,vtx,pfArr);
461     musel |= muonReferenceIsoSelection(ctrl,mu,vtx,pfArr,puDArr,eraMu,photonsToVeto);
462    
463     // bool pass = passSelection(ctrl,musel);
464     bool pass = musel.loose();
465    
466     if(pass) {
467     foi.nNumer++;
468     if(ctrl.debug) cout << "\t\tnumerator: " << foi.nNumer << endl;
469     }
470     // fill output TTree
471     foi.fopt = mu->Pt();
472     foi.foeta = mu->Eta();
473     foi.fophi = mu->Phi();
474     foi.fopass = pass ? 1 : 0;
475     foi.jpt = leadingJetPt;
476     foi.outTree->Fill();
477     }
478     }
479     //----------------------------------------------------------------------------------------
480     void fill_electron_fakes(ControlFlags &ctrl,
481 dkralph 1.4 mithep::Array<mithep::Muon> *muonArr,
482 dkralph 1.2 mithep::Array<mithep::Electron> *electronArr,
483     mithep::Array<mithep::PFJet> *jetArr,
484     mithep::Array<mithep::PFCandidate> *pfArr,
485     mithep::Array<mithep::PileupEnergyDensity> *puDArr,
486     const mithep::Vertex *vtx,
487     foinfo &foi,
488     const mithep::Muon *zmu1,
489     const mithep::Muon *zmu2,
490     const mithep::Electron *zele1,
491     const mithep::Electron *zele2)
492     {
493    
494     // count denominator and numerator objects
495     for(Int_t iele=0; iele<electronArr->GetEntries(); iele++) {
496     const mithep::Electron* ele = (*electronArr)[iele];
497    
498 dkralph 1.4 bool muonMatch=false;
499     for(unsigned imu=0; imu<muonArr->GetEntries(); imu++) {
500     const mithep::Muon *mu = (*muonArr)[imu];
501     if(dr(mu,ele) < 0.05) muonMatch = true;
502     }
503     if(muonMatch) { cout << "matched to muon in filler!" << endl; continue; }
504    
505 dkralph 1.2 if(ele==zele1 || ele==zele2) { if(ctrl.debug) cout << "\t\tdecayed from the z..." << endl; continue; }
506     if(zele1 && dr(ele,zele1) < 0.3) { if(ctrl.debug) cout << "\t\tdr-matched to zele1" << endl; continue; }
507     if(zele2 && dr(ele,zele2) < 0.3) { if(ctrl.debug) cout << "\t\tdr-matched to zele2" << endl; continue; }
508     if(zmu1 && dr(zmu1,ele) < 0.3) { if(ctrl.debug) cout << "\t\tdr-matched to zmu1" << endl; continue; }
509     if(zmu2 && dr(zmu2,ele) < 0.3) { if(ctrl.debug) cout << "\t\tdr-matched to zmu2" << endl; continue; }
510    
511     //find leading jet in the event
512     Double_t leadingJetPt = -1;
513     for(Int_t j=0; j<jetArr->GetEntries(); j++) {
514     const mithep::PFJet *jet = (*jetArr)[j];
515     if (jet->Pt() > leadingJetPt && dr(jet,ele) > 1) {
516     leadingJetPt = jet->Pt();
517     }
518     }
519    
520     // denominator definition
521     if(ele->Pt() < 5 || ele->Pt() > 35) { if(ctrl.debug) cout << "\t\tfails pt: " << ele->Pt() << endl; continue; }
522     SelectionStatus elsel;
523     elsel |= electronReferencePreSelection(ctrl,ele,vtx);
524     if( !elsel.passPre() ) { if(ctrl.debug) cout << "\t\tfails ele presection..." << endl; continue; }
525    
526     foi.nDenom++;
527     if(ctrl.debug) cout << "\t\tdenominator: " << foi.nDenom << endl;
528    
529     // numerator definition
530     elsel |= electronReferenceIDMVASelectionV1(ctrl,ele,vtx);
531     elsel |= electronReferenceIsoSelection(ctrl,ele,vtx,pfArr,puDArr,eraEle,photonsToVeto);
532    
533     // status |= eleSele(ctrl,ele,iele,brs);
534     // bool pass = passSelection(ctrl,status);
535     bool pass = elsel.loose();
536    
537     if(pass) {
538     foi.nNumer++;
539     if(ctrl.debug) cout << "\t\tnumerator: " << foi.nNumer << endl;
540     }
541     // fill output TTree
542     foi.fopt = ele->Pt();
543     foi.foeta = ele->Eta();
544     foi.fophi = ele->Phi();
545     foi.fopass = pass ? 1 : 0;
546     foi.jpt = leadingJetPt;
547     foi.outTree->Fill();
548     }
549 dkralph 1.1 }
550 dkralph 1.2 //----------------------------------------------------------------------------
551     void initRunLumiRangeMap()
552     //----------------------------------------------------------------------------
553     {
554     /*
555     rlrm.AddJSONFile(std::string("./data/Cert_136033-149442_7TeV_Apr21ReReco_Collisions10_JSON.txt"));
556     // rlrm.AddJSONFile(std::string("./data/Cert_160404-173244_7TeV_PromptReco_Collisions11_JSON_v2.txt"));
557     rlrm.AddJSONFile(std::string("./data/Cert_160404-178078_7TeV_PromptReco_Collisions11_JSON.txt"));
558     rlrm.AddJSONFile(std::string("./data/Cert_160404-163869_7TeV_May10ReReco_Collisions11_JSON_v3.txt"));
559     rlrm.AddJSONFile(std::string("./data/Cert_170249-172619_7TeV_ReReco5Aug_Collisions11_JSON.txt"));
560     // r11b
561     rlrm.AddJSONFile(std::string("./data/Cert_160404-180252_7TeV_PromptReco_Collisions11_JSON.txt"));
562     */
563    
564     // 2012 only for now ...
565     rlrm.AddJSONFile(std::string("./data/Cert_190456-194479_8TeV_PromptReco_Collisions12_JSON.txt"));
566    
567     };