ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/Selection/src/applySelection.cc
Revision: 1.29
Committed: Thu May 24 17:56:51 2012 UTC (12 years, 11 months ago) by khahn
Content type: text/plain
Branch: MAIN
CVS Tags: synched2
Changes since 1.28: +2 -5 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 //
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 //
22 // TMVA
23 //
24 #include "TMVA/Reader.h"
25 #include "TMVA/Tools.h"
26 #include "TMVA/Config.h"
27 #include "TMVA/MethodBDT.h"
28
29 //
30 // ntuple format headers
31 //
32 #include "EventHeader.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 "TriggerMask.h"
42 #include "TriggerTable.h"
43 #include "Names.h"
44 #include "BaseMod.h"
45
46 //
47 // our headers
48 //
49 #include "ParseArgs.h"
50 #include "MuonSelection.h"
51 #include "ElectronSelection.h"
52 #include "IsolationSelection.h"
53 #include "ReferenceSelection.h"
54
55 #include "TriggerUtils.h"
56 #include "PassHLT.h"
57 #include "Angles.h"
58 #include "KinematicsStruct.h"
59 #include "InfoStruct.h"
60 #include "GenInfoStruct.h"
61 #include "WeightStruct.h"
62 //#include "GlobalDataAndFuncs.h"
63 #include "RunLumiRangeMap.h"
64
65 #include "AngleTuple.h"
66 #include "FOTuple.h"
67
68 #include "SampleWeight.h"
69 #include "EfficiencyWeightsInterface.h"
70
71 #include "SimpleLepton.h"
72
73 #ifndef CMSSW_BASE
74 #define CMSSW_BASE "../"
75 #endif
76
77 using namespace mithep;
78
79 //
80 // globals
81 //----------------------------------------------------------------------------
82 TH1D * hpu;
83 RunLumiRangeMap rlrm;
84 vector<SimpleLepton> failingLeptons ; // for fake estimation
85 vector<SimpleLepton> passingLeptons; // for fake estimation
86 vector<unsigned> cutvec;
87 vector<vector<unsigned> > zcutvec;
88 vector<vector<unsigned> > zzcutvec;
89 map<unsigned,float> evtrhoMap;
90 vector<string> cutstrs;
91 bool passes_HLT_MC;
92 vector<bool> PFnoPUflag;;
93
94 //
95 // prototypes
96 //----------------------------------------------------------------------------
97 void initPUWeights();
98 double getPUWeight(unsigned npu);
99 void setEra(string, ControlFlags&);
100 void setEffiencyWeights(EventData&, WeightStruct& );
101 void initRunLumiRangeMap();
102 void initEvtRhoMap(map<unsigned,float> &);
103 unsigned makePFnoPUArray(mithep::Array<PFCandidate> * fPFCandidates,
104 vector<bool> &pfNoPileUpFlag,
105 const mithep::Array<mithep::Vertex> * vtxArr );
106 //----------------------------------------------------------------------------
107
108
109 //
110 // MAIN
111 //----------------------------------------------------------------------------
112 int main(int argc, char** argv)
113 //----------------------------------------------------------------------------
114 {
115 cutstrs.push_back(string("skim0")); //0
116 cutstrs.push_back(string("skim1")); //1
117 cutstrs.push_back(string("skim2")); //1
118 cutstrs.push_back(string("trigger")); //2
119 // -------------------------------------------------
120 cutstrs.push_back(string("Z candidate")); //3
121 cutstrs.push_back(string("good Z1")); //4
122 // -------------------------------------------------
123 cutstrs.push_back(string("4l")); //5
124 cutstrs.push_back(string("ZZ candidate")); //6
125 cutstrs.push_back(string("good Z2")); //7
126 cutstrs.push_back(string("ZZ 20/10")); //8
127 cutstrs.push_back(string("resonance")); //9
128 cutstrs.push_back(string("m4l>70")); //10
129 cutstrs.push_back(string("m4l>100, mZ2 > 12")); //11
130
131
132
133
134 string cmsswpath(CMSSW_BASE);
135 cmsswpath.append("/src");
136 std::bitset<1024> triggerBits;
137 vector<vector<string> > inputFiles;
138 inputFiles.push_back(vector<string>());
139 map<string,unsigned> entrymap; // number of unskimmed entries in each file
140 for( int i=0; i<cutstrs.size(); i++ ) cutvec.push_back(0);
141 for( int i=0; i<2; i++ ) {
142 zcutvec.push_back(vector<unsigned>());
143 for( int j=0; j<cutstrs.size(); j++ ) zcutvec[i].push_back(0);
144 }
145 for( int i=0; i<3; i++ ) {
146 zzcutvec.push_back(vector<unsigned>());
147 for( int j=0; j<cutstrs.size(); j++ ) zzcutvec[i].push_back(0);
148 }
149
150
151 //
152 // args
153 //--------------------------------------------------------------------------------------------------------------
154 ControlFlags ctrl;
155 parse_args( argc, argv, ctrl );
156 if( ctrl.inputfiles.empty() &&ctrl.inputfile.empty() )
157 {
158 cerr << "usage: applySelection.exe <flags> " << endl;
159 cerr << "\tmandoatory flags : " << endl;
160 cerr << "\t--inputfiles | file containing a list of ntuples to run over" << endl;
161 cerr << "\t--inputfile | a file to run over" << endl;
162 cerr << "\t--outputfile | file to store selected evet" << endl;
163 return 1;
164 }
165 ctrl.dump();
166
167
168
169 //
170 // File I/O
171 //--------------------------------------------------------------------------------------------------------------
172 TChain * chain = new TChain("Events");
173 TChain * hltchain = new TChain("HLT");
174
175 string fname;
176 if( !ctrl.inputfiles.empty() ) {
177 ifstream f(ctrl.inputfiles.c_str());
178 while (f >> fname) {
179 if( !(strncmp( fname.c_str(), "#", 1 ) ) ) continue; // skip commented lines
180 cout << "adding inputfile : " << fname.c_str() << endl;
181 entrymap[string(fname.c_str())] = unskimmedEntries(fname.c_str());
182 cout << "unskimmed entries: " << entrymap[string(fname.c_str())] << endl;
183 chain->AddFile(fname.c_str());
184 hltchain->AddFile(fname.c_str());
185 }
186 } else {
187 cout << "adding inputfile : " << ctrl.inputfile.c_str() << endl;
188 unsigned tmpent = unskimmedEntries(ctrl.inputfile.c_str());
189 cout << "tmpent: " << tmpent << endl;
190 entrymap[string(ctrl.inputfile.c_str())] = unskimmedEntries(ctrl.inputfile.c_str());
191 cout << "unskimmed entries: " << entrymap[string(ctrl.inputfile.c_str())] << endl;
192 chain->AddFile(ctrl.inputfile.c_str());
193 hltchain->AddFile(ctrl.inputfile.c_str());
194 }
195
196 const char * ofname;
197 if( strcmp( ctrl.outputfile.c_str(), "") ) {
198 ofname = ctrl.outputfile.c_str();
199 } else {
200 ofname = "tmp.root";
201 }
202 // table of cross section values
203 string xspath = (cmsswpath+string("/MitPhysics/data/xs.dat"));
204 cout << "xspath: " << xspath.c_str() << endl;
205 SimpleTable xstab(xspath.c_str());
206
207
208 //
209 // Setup
210 //--------------------------------------------------------------------------------------------------------------
211 Angles angles;
212 KinematicsStruct kinematics;
213 InfoStruct evtinfo;
214 WeightStruct weights;
215 GenInfoStruct geninfo;
216
217 AngleTuple nt( (const char*)ofname, (const char*)"zznt");
218 nt.makeAngleBranch(angles);
219 nt.makeKinematicsBranch(kinematics);
220 nt.makeInfoBranch(evtinfo);
221
222 FOTuple foTree( nt.getFile(), (const char*)"FOtree");
223 foTree.makeFailedLeptonBranch(failingLeptons);
224 foTree.makeZLeptonBranch(passingLeptons);
225
226 TH1F * h_wf11_hpt;
227 if(ctrl.mc) {
228 nt.makeWeightBranch(weights);
229 nt.makeGenInfoBranch(geninfo);
230 initEfficiencyWeights();
231 initPUWeights();
232
233 // Higgs only, pt reweighting
234 if( ctrl.mH <= 140 ) {
235 char wptname[256];
236 sprintf( wptname, "/data/blue/pharris/Flat/ntupler/root/weight_ptH_%i.root", ctrl.mH );
237 TFile * f_hpt = new TFile(wptname);
238 f_hpt->Print();
239 sprintf(wptname, "weight_hqt_fehipro_fit_%i", ctrl.mH);
240 h_wf11_hpt = (TH1F*)(f_hpt->FindObjectAny(wptname));
241 }
242
243 } else {
244 initRunLumiRangeMap();
245 }
246
247 // initMuonIDMVA();
248 initMuonIsoMVA();
249 initElectronIDMVA();
250 initElectronIsoMVA();
251 initTrigger();
252
253 // hack
254 initEvtRhoMap(evtrhoMap);
255
256
257 //
258 // Setup tree I/O
259 //--------------------------------------------------------------------------------------------------------------
260 TFile *inputFile=0;
261 TTree *eventTree=0;
262 string currentFile("");
263
264 mithep::EventHeader *info = new mithep::EventHeader();
265 mithep::Array<mithep::Electron> *electronArr = new mithep::Array<mithep::Electron>();
266 mithep::Array<mithep::Muon> *muonArr = new mithep::Array<mithep::Muon>();
267 mithep::Array<mithep::Vertex> *vtxArr = new mithep::Array<mithep::Vertex>();
268 mithep::Array<mithep::PFCandidate> *pfArr = new mithep::Array<mithep::PFCandidate>();
269 mithep::Array<mithep::PileupInfo> *puArr = new mithep::Array<mithep::PileupInfo>();
270 mithep::Array<mithep::PileupEnergyDensity> *puDArr = new mithep::Array<mithep::PileupEnergyDensity>();
271 mithep::Array<mithep::Track> *trkArr = new mithep::Array<mithep::Track>();
272 mithep::Array<mithep::MCParticle> *mcArr = new mithep::Array<mithep::MCParticle>();
273 mithep::MCEventInfo *mcEvtInfo = new mithep::MCEventInfo();
274 mithep::TriggerMask *trigMask = new mithep::TriggerMask();
275 mithep::TriggerTable *hltTable = new mithep::TriggerTable();
276 vector<string> *hltTableStrings = new vector<string>();
277
278 TString fElectronName(Names::gkElectronBrn);
279 TString fMuonName(Names::gkMuonBrn);
280 TString fInfoName(Names::gkEvtHeaderBrn);
281 TString fPrimVtxName(Names::gkPVBrn);
282 TString fPFCandidateName(Names::gkPFCandidatesBrn);
283 TString fPileupInfoName(Names::gkPileupInfoBrn);
284 TString fPileupEnergyDensityName(Names::gkPileupEnergyDensityBrn);
285 TString fTrackName(Names::gkTrackBrn);
286 TString fMCParticleName(Names::gkMCPartBrn);
287 TString fMCEvtInfoName(Names::gkMCEvtInfoBrn);
288 TString fTriggerMaskName(Names::gkHltBitBrn);
289 TString fTriggerTableName(Names::gkHltTableBrn);
290
291 chain->SetBranchAddress(fInfoName, &info);
292 chain->SetBranchAddress(fElectronName, &electronArr);
293 chain->SetBranchAddress(fMuonName, &muonArr);
294 chain->SetBranchAddress(fPrimVtxName, &vtxArr);
295 chain->SetBranchAddress(fPFCandidateName, &pfArr);
296 if( ctrl.mc ) {
297 chain->SetBranchAddress(fPileupInfoName, &puArr);
298 chain->SetBranchAddress(fMCParticleName, &mcArr);
299 chain->SetBranchAddress(fMCEvtInfoName, &mcEvtInfo);
300 }
301 chain->SetBranchAddress(fPileupEnergyDensityName, &puDArr);
302 chain->SetBranchAddress(fTrackName, &trkArr);
303 chain->SetBranchAddress(fTriggerMaskName, &trigMask);
304 cout << "hlttable: " << fTriggerTableName << endl;
305 hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings);
306
307 mithep::Vertex vtx; // best primary vertex in the event
308
309 // ginfo = NULL;
310 // if( ctrl.mc ) { chain->SetBranchAddress("Gen", &ginfo);}
311
312 int count=0, pass=0;
313 float passcorr=0., passcorr_errup=0., passcorr_errdown=0.;
314 float denom[3]={0.,0.,0.};
315 float numer[3]={0.,0.,0.};
316 float numercorr[3]={0.,0.,0.};
317
318 // only 1 HLT table / file ???
319 hltchain->GetEntry(0);
320 cerr << "here... " << endl;
321
322 int imax = chain->GetEntries();
323 cout << "nEntries: " << imax << endl;
324
325
326 //
327 // Loop !!!!!!!!!
328 //--------------------------------------------------------------------------------------------------------------
329 for(UInt_t ientry=0; ientry<imax; ientry++)
330 {
331 chain->GetEntry(ientry);
332 if(!(ientry%1000)) cerr << "entry: " << ientry << endl;
333
334 #ifdef HACKED_RHOS
335 float rho = evtrhoMap[info->EvtNum()];
336 #endif
337 string fname = string(chain->GetFile()->GetEndpointUrl()->GetFile());
338 setEra( fname, ctrl );
339
340
341 //
342 // pfNoPU
343 //
344 //mithep::Array<PFCandidate> pfNoPileUp;
345 PFnoPUflag.clear();
346 int pfnopu_size = makePFnoPUArray( pfArr, PFnoPUflag, vtxArr );
347 assert(pfnopu_size == pfArr->GetEntries());
348
349 //
350 // data/MC
351 //
352 if(ctrl.mc) {
353 //
354 // gen info
355 //
356 if(ctrl.fillGen)
357 fillGenInfo( mcArr, mcEvtInfo, geninfo, ESampleType::kHZZ, ctrl);
358
359 //
360 // xsec & PU weights
361 //
362 weights.w = getWeight(xstab,entrymap,chain)/ctrl.totalMC;
363 cout << "xsec weight: " << weights.w << endl;
364 int npu = -1;
365 for(int i=0;i<puArr->GetEntries();i++) {
366 if(puArr->At(i)->GetBunchCrossing() == 0)
367 npu = puArr->At(i)->GetPU_NumInteractions();
368 }
369 assert(npu>=0);
370 evtinfo.npu;
371 weights.npuw = getPUWeight(evtinfo.npu);
372
373 //
374 // pt reweighting for Higgs < 140, F11
375 //
376 if( ctrl.fillGen ) {
377 if( (fname.find("f11-h115zz4l") != string::npos) ||
378 (fname.find("f11-h120zz4l") != string::npos) ||
379 (fname.find("f11-h130zz4l") != string::npos) ) {
380 weights.w *= h_wf11_hpt->GetBinContent(h_wf11_hpt->FindBin(geninfo.pt_zz));
381 }
382 }
383
384 //
385 // trigger
386 //
387 if( string(chain->GetFile()->GetEndpointUrl()->GetFile()) != currentFile ) {
388 currentFile = string(chain->GetFile()->GetEndpointUrl()->GetFile());
389 hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings);
390 hltchain->GetEntry(0);
391 hltTable->Clear();
392 fillTriggerBits(hltTable, hltTableStrings );
393 }
394 if( ctrl.debug ) cout << "file is : " << currentFile << endl;
395 fillTriggerBits( hltTable, trigMask, triggerBits );
396 passes_HLT_MC = true; // passed to apply as extern global, just for sync
397 if( !passHLTMC(triggerBits, info->RunNum(), info->EvtNum(), k2012_MC ) ) {
398 passes_HLT_MC = false;
399 }
400 } else {
401 //
402 // JSON
403 //
404 /*
405 RunLumiRangeMap::RunLumiPairType rl(info->RunNum(), info->LumiSec());
406 if( !(rlrm.HasRunLumi(rl)) ) {
407 if( ctrl.debug ) cout << "\tfails JSON" << endl;
408 continue;
409 }
410 */
411 //
412 // trigger
413 //
414 if( string(chain->GetFile()->GetEndpointUrl()->GetFile()) != currentFile ) {
415 currentFile = string(chain->GetFile()->GetEndpointUrl()->GetFile());
416 hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings);
417 hltchain->GetEntry(0);
418 hltTable->Clear();
419 fillTriggerBits(hltTable, hltTableStrings );
420 }
421 if( ctrl.debug ) cout << "file is : " << currentFile << endl;
422 /*
423 fillTriggerBits( hltTable, trigMask, triggerBits );
424 if( !passHLT(triggerBits, info->RunNum(), info->EvtNum() ) ) {
425 if( ctrl.debug ) cout << "\tfails trigger ... " << endl;
426 continue;
427 }
428 */
429 }
430
431 //
432 // lepton/kinematic selection ...
433 //
434 failingLeptons.clear();
435 passingLeptons.clear();
436 EventData ret4l =
437
438
439 // reference
440 apply_HZZ4L_reference_selection(ctrl, info,
441 vtxArr,
442 pfArr,
443 #ifdef HACKED_RHOS
444 rho,
445 #else
446 puDArr,
447 #endif
448 electronArr,
449 &electronReferencePreSelection,
450 &electronReferenceIDMVASelectionV1,
451 &electronReferenceIsoSelection,
452 muonArr,
453 &muonReferencePreSelection,
454 &muonIDPFSelection,
455 &muonReferenceIsoSelection);
456
457 /*
458 // evolved
459 apply_HZZ4L_reference2_selection(ctrl, info,
460 vtx,
461 pfArr,
462 //rho,
463 puDArr,
464 electronArr,
465 &electronReferencePreSelection,
466 //&electronPreSelection,
467 &electronReferenceIDMVASelection,
468 &electronIsoMVASelection,
469 muonArr,
470 &muonReferencePreSelection,
471 //&muonPreSelection,
472 &muonIDPFSelection,
473 &muonIsoMVASelection);
474 */
475
476 if( ctrl.debug ) cout << endl;
477
478
479 int Z1type=0, Z2type=0;
480 if( ret4l.status.selectionBits.to_ulong() >= PASS_ZCANDIDATE ) {
481 if( abs(ret4l.Z1leptons[0].type) == 11 ) Z1type = 11;
482 if( abs(ret4l.Z1leptons[0].type) == 13 ) Z1type = 13;
483 }
484 if( ret4l.status.selectionBits.to_ulong() >= PASS_ZZCANDIDATE ) {
485 if( abs(ret4l.Z2leptons[0].type) == 11 ) Z2type = 11;
486 if( abs(ret4l.Z2leptons[0].type) == 13 ) Z2type = 13;
487 }
488
489 #ifdef SYNC
490 cout << "bits: " << ret4l.status.selectionBits << "\t"
491 << "Z1: " << Z1type << "\t"
492 << "Z2: " << Z2type << endl;
493 cout << endl;
494 #endif
495
496 if( ret4l.status.pass() ) {
497 fillAngles(ret4l,angles);
498 fillKinematics(ret4l,kinematics);
499 fillEventInfo(info,evtinfo);
500 if( ctrl.mc) {
501 // fillGenInfo(ginfo,geninfo);
502 setEffiencyWeights(ret4l, weights);
503 if(ctrl.debug)
504 cout << "w: " << weights.w << "\t"
505 << "won: " << weights.won << "\t"
506 << "woff: " << weights.woff << endl;
507 }
508
509
510 nt.Fill();
511
512 cerr << "PASS:: "
513 << "\trun: " << evtinfo.run
514 << "\tevt: " << evtinfo.evt
515 << "\tlumi: " << evtinfo.lumi
516 << "\tcostheta1: " << angles.costheta1
517 << "\tcostheta2: " << angles.costheta2
518 << "\tcostheta*: " << angles.costhetastar
519 << "\tbdt: " << angles.bdt
520 << endl;
521 pass++;
522 // if( pass > 3 ) break;
523
524 } else if( ret4l.status.selectionBits.test(PASS_GOODZ1) ) { // save for fakes ...
525 // if(ctrl.debug) {
526 cout << "failingLeptons : " << failingLeptons.size() << endl;
527 for( int f=0; f<failingLeptons.size(); f++ ) {
528 SimpleLepton l = failingLeptons[f];
529 cout << "f: " << f << "\t"
530 << "type: " << l.type << "\t"
531 << "pT: " << l.vec.Pt() << "\t"
532 << "eta: " << l.vec.Eta()
533 << endl;
534 // }
535 }
536 foTree.Fill();
537 }
538 }
539
540
541 foTree.getFile()->cd();
542 foTree.getTree()->Write();
543 nt.WriteClose();
544
545 cout << endl;
546 cout << endl;
547 for( int i=0; i<cutvec.size(); i++ ) {
548 cout << "cut: " << i << "\t"
549 << "pass: " << cutvec[i];
550
551 if( i>PASS_TRIGGER&&i<=PASS_GOODZ1 )
552 cout << "\t2e: " << zcutvec[0][i]
553 << "\t2m: " << zcutvec[1][i];
554
555 if( i>PASS_ZCANDIDATE )
556 cout << "\t4e: " << zzcutvec[0][i]
557 << "\t4m: " << zzcutvec[1][i]
558 << "\t2e2m: " << zzcutvec[2][i];
559
560 cout << "\t" << cutstrs[i] << endl;
561
562 cout << endl;
563 }
564
565 }
566
567
568
569 //----------------------------------------------------------------------------
570 void setEffiencyWeights(EventData & evtdat, WeightStruct & weights )
571 //----------------------------------------------------------------------------
572 {
573 vector<SimpleLepton> lepvec = evtdat.Z1leptons;
574 lepvec.insert(lepvec.end(), evtdat.Z2leptons.begin(), evtdat.Z2leptons.end());
575 double w_offline=-1, werr_offline=0;
576 double w_online=-1, werr_online=0;
577
578 vector< pair <double,double> > wlegs; // pair here is eff & err
579 vector< pair <float,float> > mvec; // pair here is eta & pt
580
581 // vector< pair <float,float> > evec; // pair here is eta & pt
582 // now deal with medium vs loose
583 vector< pair< bool, pair <float,float> > > evec; // pair here is eta & pt
584
585 for( int k=0; k<lepvec.size(); k++ ) {
586 if( abs(lepvec[k].type) == 13 ) {
587 mvec.push_back( std::pair<float,float> (fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt()) );
588 wlegs.push_back( muonPerLegOfflineEfficiencyWeight( fabs(lepvec[k].vec.Eta()),
589 lepvec[k].vec.Pt() ) );
590 } else {
591
592 // now deal with medium vs loose
593 // evec.push_back( std::pair<float,float> (fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt()) );
594
595 std::pair<float,float> tmppair(fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt());
596 evec.push_back( std::pair<bool, std::pair<float,float> > (lepvec[k].isTight, tmppair) );
597
598 // wlegs.push_back( elePerLegOfflineEfficiencyWeight( fabs(lepvec[k].vec.Eta()),
599 // lepvec[k].vec.Pt() ) );
600
601 wlegs.push_back( elePerLegOfflineEfficiencyWeight( fabs(lepvec[k].vec.Eta()),
602 lepvec[k].vec.Pt(),
603 lepvec[k].isTight ) );
604
605 }
606 }
607
608 pair<double,double> offpair = getOfflineEfficiencyWeight( wlegs );
609 weights.woff = offpair.first;
610 weights.werroff = offpair.second;
611
612 pair<double,double> onpair = getOnlineEfficiencyWeight( mvec, evec );
613 weights.won = onpair.first;
614 weights.werron = onpair.second;
615 }
616
617
618 //----------------------------------------------------------------------------
619 void initRunLumiRangeMap()
620 //----------------------------------------------------------------------------
621 {
622 /*
623 rlrm.AddJSONFile(std::string("./data/Cert_136033-149442_7TeV_Apr21ReReco_Collisions10_JSON.txt"));
624 // rlrm.AddJSONFile(std::string("./data/Cert_160404-173244_7TeV_PromptReco_Collisions11_JSON_v2.txt"));
625 rlrm.AddJSONFile(std::string("./data/Cert_160404-178078_7TeV_PromptReco_Collisions11_JSON.txt"));
626 rlrm.AddJSONFile(std::string("./data/Cert_160404-163869_7TeV_May10ReReco_Collisions11_JSON_v3.txt"));
627 rlrm.AddJSONFile(std::string("./data/Cert_170249-172619_7TeV_ReReco5Aug_Collisions11_JSON.txt"));
628 // r11b
629 rlrm.AddJSONFile(std::string("./data/Cert_160404-180252_7TeV_PromptReco_Collisions11_JSON.txt"));
630 */
631 };
632
633
634 //----------------------------------------------------------------------------
635 void initPUWeights()
636 //----------------------------------------------------------------------------
637 {
638 TFile * puf = new TFile("data/PileupReweighting.Summer11DYmm_To_Full2011.root");
639 hpu = (TH1D*)(puf->Get("puWeights"));
640 }
641
642 //----------------------------------------------------------------------------
643 double getPUWeight(unsigned npu)
644 //----------------------------------------------------------------------------
645 {
646 return hpu->GetBinContent(hpu->FindBin(npu));
647 }
648
649 //----------------------------------------------------------------------------
650 void initEvtRhoMap( map<unsigned, float> & evtrhoMap )
651 //----------------------------------------------------------------------------
652 {
653 unsigned evt;
654 float rho;
655
656 cout << "initialzing EvtRhoMap ";
657 //FILE * f = fopen("evtrho.dat", "r");
658 // FILE * f = fopen("allrho.cali.uniq.dat", "r");
659 FILE * f = fopen("/data/blue/khahn/CMSSW_4_4_2/src/MitHzz4l/allrhoAA.cali.uniq.dat", "r");
660 int lcount=0;
661 while( fscanf( f, "%u:%f", &evt, &rho ) ) {
662 if( feof(f) ) break;
663 evtrhoMap[evt] = rho;
664 lcount++;
665 if( !(lcount%1000) ) cout << "."; flush(cout);
666 }
667 cout << " done" << endl;
668 }
669
670 //----------------------------------------------------------------------------
671 unsigned makePFnoPUArray(mithep::Array<PFCandidate> * fPFCandidates,
672 vector<bool> &pfNoPileUpflag,
673 const mithep::Array<mithep::Vertex> * vtxArr )
674 //----------------------------------------------------------------------------
675 {
676 for(UInt_t i = 0; i < fPFCandidates->GetEntries(); i++) {
677 const PFCandidate *pf = fPFCandidates->At(i);
678 assert(pf);
679
680 if(pf->PFType() == PFCandidate::eHadron) {
681 if(pf->HasTrackerTrk() &&
682 vtxArr->At(0)->HasTrack(pf->TrackerTrk()) &&
683 vtxArr->At(0)->TrackWeight(pf->TrackerTrk()) > 0) {
684
685 pfNoPileUpflag.push_back(1);
686
687 } else {
688
689 Bool_t vertexFound = kFALSE;
690 const Vertex *closestVtx = 0;
691 Double_t dzmin = 10000;
692
693 // loop over vertices
694 for(UInt_t j = 0; j < vtxArr->GetEntries(); j++) {
695 const Vertex *vtx = vtxArr->At(j);
696 assert(vtx);
697
698 if(pf->HasTrackerTrk() &&
699 vtx->HasTrack(pf->TrackerTrk()) &&
700 vtx->TrackWeight(pf->TrackerTrk()) > 0) {
701 vertexFound = kTRUE;
702 closestVtx = vtx;
703 break;
704 }
705 Double_t dz = fabs(pf->SourceVertex().Z() - vtx->Z());
706 if(dz < dzmin) {
707 closestVtx = vtx;
708 dzmin = dz;
709 }
710 }
711
712 // if(fCheckClosestZVertex) {
713 if(1) {
714 // Fallback: if track is not associated with any vertex,
715 // associate it with the vertex closest in z
716 if(vertexFound || closestVtx != vtxArr->At(0)) {
717 // pfPileUp->Add(pf);
718 pfNoPileUpflag.push_back(0);
719 } else {
720 pfNoPileUpflag.push_back(1);
721 }
722 } else {
723 if(vertexFound && closestVtx != vtxArr->At(0)) {
724 // pfPileUp->Add(pf);
725 pfNoPileUpflag.push_back(0);
726 } else {
727 // PFCandidate * pfNoPileUp->AddNew(); // Ridiculous but that's how it is
728 pfNoPileUpflag.push_back(1);
729 }
730 }
731 } //hadron & trk stuff
732 } else { // hadron
733 // PFCandidate * ptr = pfNoPileUp->AddNew();
734 pfNoPileUpflag.push_back(1);
735 }
736 } // Loop over PF candidates
737
738 return pfNoPileUpflag.size();
739 }
740
741 void setEra(string fname, ControlFlags &ctrl)
742 {
743 if( ctrl.mc && (fname.find("f11-") != string::npos) ) ctrl.era=2011 ;
744 if( ctrl.mc && (fname.find("s12-") != string::npos) ) ctrl.era=2012 ;
745 if( !ctrl.mc && (fname.find("r11-") != string::npos) ) ctrl.era=2011 ;
746 if( !ctrl.mc && (fname.find("r12-") != string::npos) ) ctrl.era=2012 ;
747 }