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