33 |
|
#include "Electron.h" |
34 |
|
#include "Muon.h" |
35 |
|
#include "Vertex.h" |
36 |
+ |
#include "PFMet.h" |
37 |
|
#include "PFCandidate.h" |
38 |
|
#include "PFCandidateCol.h" |
39 |
|
#include "PileupInfoCol.h" |
45 |
|
#include "TriggerObjectRel.h" |
46 |
|
#include "Names.h" |
47 |
|
#include "BaseMod.h" |
48 |
< |
#include "MitAna/TreeMod/interface/HLTFwkMod.h" |
48 |
> |
#include "TriggerObjectsTable.h" |
49 |
> |
|
50 |
|
// |
51 |
|
// our headers |
52 |
|
// |
82 |
|
// |
83 |
|
// globals |
84 |
|
//---------------------------------------------------------------------------- |
85 |
< |
TH1D * hpu; |
85 |
> |
TH1D *hpu_2011, *hpu_2012; |
86 |
|
RunLumiRangeMap rlrm; |
87 |
|
vector<SimpleLepton> failingLeptons ; // for fake estimation |
88 |
|
vector<SimpleLepton> passingLeptons; // for fake estimation |
97 |
|
// |
98 |
|
// prototypes |
99 |
|
//---------------------------------------------------------------------------- |
100 |
< |
void initPUWeights(); |
99 |
< |
double getPUWeight(unsigned npu); |
100 |
< |
void initRunLumiRangeMap(); |
101 |
< |
void setHLTObjectRelations( mithep::Array<mithep::TriggerObject> *hltObjArr, |
102 |
< |
mithep::Array<mithep::TriggerObjectRel> *hltRelsArr, |
103 |
< |
vector<string> * fHLTTab, |
104 |
< |
vector<string> * fHLTLab ) |
105 |
< |
{ |
106 |
< |
|
107 |
< |
const int n = hltRelsArr->GetEntries(); |
108 |
< |
for (int i=0; i<n; ++i) { |
109 |
< |
const TriggerObjectRel *rel = hltRelsArr->At(i); |
110 |
< |
if (!rel) continue; |
111 |
< |
|
112 |
< |
const TriggerObjectBase *ob = hltObjArr->At(rel->ObjInd()); |
113 |
< |
if (!ob) continue; |
114 |
< |
|
115 |
< |
hltObjArr->At(rel->ObjInd())->SetTrigName(fHLTTab->at(rel->TrgId()).c_str()); |
116 |
< |
hltObjArr->At(rel->ObjInd())->SetModuleName(fHLTLab->at(rel->ModInd()).c_str()); |
117 |
< |
hltObjArr->At(rel->ObjInd())->SetFilterName(fHLTLab->at(rel->FilterInd()).c_str()); |
118 |
< |
if (hltObjArr->At(rel->ObjInd())->TagInd()>=0) |
119 |
< |
hltObjArr->At(rel->ObjInd())->SetTagName(fHLTLab->at(hltObjArr->At(rel->ObjInd())->TagInd()).c_str()); |
120 |
< |
else |
121 |
< |
hltObjArr->At(rel->ObjInd())->SetTagName("Unknown"); |
122 |
< |
} |
123 |
< |
}; |
124 |
< |
|
100 |
> |
void initRunLumiRangeMap(ControlFlags &ctrl); |
101 |
|
//---------------------------------------------------------------------------- |
102 |
|
|
103 |
|
|
168 |
|
TChain * hltchain = new TChain("HLT"); |
169 |
|
|
170 |
|
string fname; |
171 |
+ |
unsigned total_unskimmed=0; |
172 |
|
if( !ctrl.inputfiles.empty() ) { |
173 |
|
ifstream f(ctrl.inputfiles.c_str()); |
174 |
|
while (f >> fname) { |
176 |
|
cout << "adding inputfile : " << fname.c_str() << endl; |
177 |
|
entrymap[string(fname.c_str())] = unskimmedEntries(fname.c_str()); |
178 |
|
cout << "unskimmed entries: " << entrymap[string(fname.c_str())] << endl; |
179 |
+ |
total_unskimmed += entrymap[string(fname.c_str())]; |
180 |
|
chain->AddFile(fname.c_str()); |
181 |
|
hltchain->AddFile(fname.c_str()); |
182 |
|
} |
183 |
|
} else { |
184 |
|
cout << "adding inputfile : " << ctrl.inputfile.c_str() << endl; |
185 |
< |
unsigned tmpent = unskimmedEntries(ctrl.inputfile.c_str()); |
186 |
< |
cout << "tmpent: " << tmpent << endl; |
187 |
< |
entrymap[string(ctrl.inputfile.c_str())] = unskimmedEntries(ctrl.inputfile.c_str()); |
188 |
< |
cout << "unskimmed entries: " << entrymap[string(ctrl.inputfile.c_str())] << endl; |
185 |
> |
unsigned unsk_ents = unskimmedEntries(ctrl.inputfile.c_str()); |
186 |
> |
entrymap[string(ctrl.inputfile.c_str())] = unsk_ents; |
187 |
> |
cout << "unskimmed entries: " << unsk_ents << endl; |
188 |
> |
total_unskimmed += unsk_ents; |
189 |
|
chain->AddFile(ctrl.inputfile.c_str()); |
190 |
|
hltchain->AddFile(ctrl.inputfile.c_str()); |
191 |
|
} |
192 |
+ |
// // write the total number of unskimmed events that went into making this output file to a text file |
193 |
+ |
// writeEntries(ctrl,total_unskimmed); |
194 |
|
|
195 |
|
const char * ofname; |
196 |
|
if( strcmp( ctrl.outputfile.c_str(), "") ) { |
204 |
|
SimpleTable xstab(xspath.c_str()); |
205 |
|
|
206 |
|
|
207 |
+ |
|
208 |
|
// |
209 |
|
// Setup |
210 |
|
//-------------------------------------------------------------------------------------------------------------- |
228 |
|
if(ctrl.mc) { |
229 |
|
nt.makeWeightBranch(weights); |
230 |
|
if(ctrl.fillGen ) nt.makeGenInfoBranch(geninfo); |
231 |
< |
if(ctrl.efftype != string("WTF?")) initEfficiencyWeights(); |
231 |
> |
initEfficiencyWeights(); |
232 |
|
initPUWeights(); |
233 |
|
|
234 |
|
// Higgs only, pt reweighting |
249 |
|
initElectronIDMVAV1(); |
250 |
|
initTrigger(); |
251 |
|
|
271 |
– |
|
252 |
|
// |
253 |
|
// Setup tree I/O |
254 |
|
//-------------------------------------------------------------------------------------------------------------- |
256 |
|
TTree *eventTree=0; |
257 |
|
string currentFile(""); |
258 |
|
|
259 |
+ |
UInt_t fNMaxTriggers = 1024; |
260 |
|
mithep::EventHeader *info = new mithep::EventHeader(); |
261 |
+ |
mithep::Array<mithep::PFMet> *metArr = new mithep::Array<mithep::PFMet>(); |
262 |
|
mithep::Array<mithep::Electron> *electronArr = new mithep::Array<mithep::Electron>(); |
263 |
|
mithep::Array<mithep::Muon> *muonArr = new mithep::Array<mithep::Muon>(); |
264 |
|
mithep::Array<mithep::Vertex> *vtxArr = new mithep::Array<mithep::Vertex>(); |
269 |
|
mithep::Array<mithep::MCParticle> *mcArr = new mithep::Array<mithep::MCParticle>(); |
270 |
|
mithep::MCEventInfo *mcEvtInfo = new mithep::MCEventInfo(); |
271 |
|
mithep::TriggerMask *trigMask = new mithep::TriggerMask(); |
272 |
< |
mithep::TriggerTable *hltTable = new mithep::TriggerTable(); |
272 |
> |
mithep::TriggerTable *hltTable = new mithep::TriggerTable(fNMaxTriggers); |
273 |
|
vector<string> *hltTableStrings = new vector<string>(); |
274 |
|
vector<string> *hltLabelStrings = new vector<string>(); |
275 |
|
mithep::Array<mithep::TriggerObject> *hltObjArr = new mithep::Array<mithep::TriggerObject>(); |
276 |
|
mithep::Array<mithep::TriggerObjectRel> *hltRelsArr = new mithep::Array<mithep::TriggerObjectRel>(); |
277 |
|
std::vector<std::string> *hltTab = new vector<string>(); |
278 |
< |
std::vector<std::string> *hltLab = new vector<string>(); |
278 |
> |
std::vector<std::string> *hltLab = new vector<string>(); |
279 |
> |
TriggerObjectsTable *fTrigObjs = new TriggerObjectsTable(hltTable,fNMaxTriggers); |
280 |
|
|
281 |
|
|
282 |
|
TString fElectronName(Names::gkElectronBrn); |
283 |
|
TString fMuonName(Names::gkMuonBrn); |
284 |
|
TString fInfoName(Names::gkEvtHeaderBrn); |
285 |
+ |
TString fPFMetName("PFMet"); |
286 |
|
TString fPrimVtxName(Names::gkPVBrn); |
287 |
|
TString fPFCandidateName(Names::gkPFCandidatesBrn); |
288 |
|
TString fPileupInfoName(Names::gkPileupInfoBrn); |
296 |
|
TString fTriggerObjectName(Names::gkHltObjBrn); |
297 |
|
TString fTriggerObjectRelsName(Form("HLTObjectsRelation")); |
298 |
|
|
299 |
< |
TString fHLTLabName(Names::gkHltLabelBrn); |
300 |
< |
TString fHLTTabName(Names::gkHltTableBrn); |
301 |
< |
TString fHLTTabNamePub(Form("%sFwk",fHLTTabName.Data())); |
302 |
< |
TString fHLTLabNamePub(Form("%sFwk",fHLTLabName.Data())); |
303 |
< |
TString fObjsNamePub(Form("%sFwk",fTriggerObjectName.Data())); |
320 |
< |
|
299 |
> |
// TString fHLTLabName(Names::gkHltLabelBrn); |
300 |
> |
// TString fHLTTabName(Names::gkHltTableBrn); |
301 |
> |
// TString fHLTTabNamePub(Form("%sFwk",fHLTTabName.Data())); |
302 |
> |
// TString fHLTLabNamePub(Form("%sFwk",fHLTLabName.Data())); |
303 |
> |
// TString fObjsNamePub(Form("%sFwk",fTriggerObjectName.Data())); |
304 |
|
|
305 |
|
|
306 |
+ |
|
307 |
|
chain->SetBranchAddress(fInfoName, &info); |
308 |
+ |
chain->SetBranchAddress(fPFMetName, &metArr); |
309 |
|
chain->SetBranchAddress(fElectronName, &electronArr); |
310 |
|
chain->SetBranchAddress(fMuonName, &muonArr); |
311 |
|
chain->SetBranchAddress(fPrimVtxName, &vtxArr); |
320 |
|
chain->SetBranchAddress(fTriggerMaskName, &trigMask); |
321 |
|
chain->SetBranchAddress(fTriggerObjectName, &hltObjArr); |
322 |
|
chain->SetBranchAddress(fTriggerObjectRelsName, &hltRelsArr); |
323 |
< |
chain->SetBranchAddress(fHLTTabNamePub, &hltTab); |
324 |
< |
chain->SetBranchAddress(fHLTLabNamePub, &hltLab); |
323 |
> |
// chain->SetBranchAddress(fHLTTabNamePub, &hltTab); |
324 |
> |
// chain->SetBranchAddress(fHLTLabNamePub, &hltLab); |
325 |
|
|
326 |
|
cout << "hlttable: " << fTriggerTableName << endl; |
327 |
|
hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings); |
340 |
|
|
341 |
|
// only 1 HLT table / file ??? |
342 |
|
hltchain->GetEntry(0); |
358 |
– |
cerr << "here... " << endl; |
343 |
|
|
344 |
|
int imax = chain->GetEntries(); |
345 |
|
cout << "nEntries: " << imax << endl; |
346 |
|
|
363 |
– |
HLTFwkMod stupid; |
364 |
– |
|
347 |
|
// |
348 |
|
// Loop !!!!!!!!! |
349 |
|
//-------------------------------------------------------------------------------------------------------------- |
351 |
|
{ |
352 |
|
chain->GetEntry(ientry); |
353 |
|
if(!(ientry%1000)) cerr << "entry: " << ientry << endl; |
354 |
< |
|
354 |
> |
|
355 |
|
if( ctrl.debug ) { |
356 |
|
cout << "-----------------------------------------------------------------" << endl; |
357 |
|
cout << "-----------------------------------------------------------------" << endl; |
364 |
|
|
365 |
|
|
366 |
|
string fname = string(chain->GetFile()->GetEndpointUrl()->GetFile()); |
367 |
< |
setEra( fname, ctrl ); |
368 |
< |
|
369 |
< |
|
367 |
> |
if(ctrl.debug) cout << "era is " << ctrl.era << endl; |
368 |
> |
if( ctrl.era == 0 ) { |
369 |
> |
setEra( fname, ctrl ); |
370 |
> |
if(ctrl.debug) cout << "era is now " << ctrl.era << endl; |
371 |
> |
} |
372 |
|
|
373 |
|
// |
374 |
|
// pfNoPU |
393 |
|
// |
394 |
|
weights.w = getWeight(xstab,entrymap,chain)/ctrl.totalMC; |
395 |
|
cout << "xsec weight: " << weights.w << endl; |
396 |
< |
int npu = -1; |
397 |
< |
for(int i=0;i<puArr->GetEntries();i++) { |
398 |
< |
if(puArr->At(i)->GetBunchCrossing() == 0) |
399 |
< |
npu = puArr->At(i)->GetPU_NumInteractions(); |
400 |
< |
} |
401 |
< |
assert(npu>=0); |
418 |
< |
evtinfo.npu; |
419 |
< |
weights.npuw = getPUWeight(evtinfo.npu); |
420 |
< |
|
396 |
> |
|
397 |
> |
unsigned npu = getNPU(puArr, 0); |
398 |
> |
weights.npu = npu; |
399 |
> |
weights.npuw = getPUWeight(ctrl.era,npu); |
400 |
> |
cerr << "weights.npuw: " << weights.npuw << endl; |
401 |
> |
|
402 |
|
// |
403 |
|
// pt reweighting for Higgs < 140, F11 |
404 |
|
// |
428 |
|
passes_HLT_MC = false; |
429 |
|
} |
430 |
|
|
431 |
< |
setHLTObjectRelations( hltObjArr, hltRelsArr, hltTableStrings, hltLabelStrings ); |
451 |
< |
for( int i=0; i<hltObjArr->GetEntries(); i++ ) { |
452 |
< |
const mithep::TriggerObject *to = (*hltObjArr)[i]; |
453 |
< |
to->Print(); |
454 |
< |
} |
455 |
< |
|
431 |
> |
setHLTObjectRelations( hltObjArr, hltRelsArr, hltTableStrings, hltLabelStrings, fTrigObjs ); |
432 |
|
|
433 |
|
} else { |
434 |
|
// |
441 |
|
continue; |
442 |
|
} |
443 |
|
} |
444 |
< |
|
444 |
> |
|
445 |
|
// |
446 |
|
// trigger |
447 |
|
// |
454 |
|
fillTriggerNames(hltTable, hltTableStrings ); |
455 |
|
} |
456 |
|
|
457 |
< |
setHLTObjectRelations( hltObjArr, hltRelsArr, hltTableStrings, hltLabelStrings ); |
482 |
< |
for( int i=0; i<hltObjArr->GetEntries(); i++ ) { |
483 |
< |
const mithep::TriggerObject *to = (*hltObjArr)[i]; |
484 |
< |
to->Print(); |
485 |
< |
} |
457 |
> |
setHLTObjectRelations( hltObjArr, hltRelsArr, hltTableStrings, hltLabelStrings, fTrigObjs ); |
458 |
|
|
459 |
|
if( ctrl.debug ) cout << "file is : " << currentFile << endl; |
460 |
|
/* |
502 |
|
} |
503 |
|
|
504 |
|
#ifdef SYNC |
505 |
< |
cout << "bits: " << ret4l.status.selectionBits << "\t" |
506 |
< |
<< "Z1: " << Z1type << "\t" |
507 |
< |
<< "Z2: " << Z2type << endl; |
508 |
< |
cout << endl; |
505 |
> |
if(ctrl.debug) |
506 |
> |
cout << "bits: " << ret4l.status.selectionBits << "\t" |
507 |
> |
<< "Z1: " << Z1type << "\t" |
508 |
> |
<< "Z2: " << Z2type << endl << endl; |
509 |
|
#endif |
510 |
|
|
511 |
|
if( ret4l.status.pass() ) { |
512 |
|
fillAngles(ret4l,angles); |
513 |
|
fillKinematics(ret4l,kinematics); |
514 |
|
fillMassErrors(ret4l,muonArr,electronArr,kinematics); |
515 |
< |
fillEventInfo(info,evtinfo); |
515 |
> |
TLorentzVector pfmet; pfmet.SetPxPyPzE(metArr->At(0)->Mex(),metArr->At(0)->Mey(),0,0); |
516 |
> |
fillEventInfo( info, pfmet, evtinfo, ctrl.mc ? getNPU(puArr) : 0); |
517 |
|
if( ctrl.mc) { |
518 |
< |
if( std::string(ctrl.efftype) != std::string("WTF?")) { |
519 |
< |
setEffiencyWeights(ret4l, weights); |
520 |
< |
} else { |
521 |
< |
weights.won = weights.woff = 1.; |
522 |
< |
} |
523 |
< |
if(ctrl.debug) |
524 |
< |
cout << "w: " << weights.w << "\t" |
525 |
< |
<< "won: " << weights.won << "\t" |
526 |
< |
<< "woff: " << weights.woff << endl; |
518 |
> |
// if( std::string(ctrl.efftype) != std::string("WTF?")) { |
519 |
> |
setEffiencyWeights(ctrl.era, ret4l, weights); |
520 |
> |
// } else { |
521 |
> |
// weights.won = weights.woff = 1.; |
522 |
> |
// } |
523 |
> |
if(ctrl.debug) |
524 |
> |
cout << "w: " << weights.w << "\t" |
525 |
> |
<< "npuw: " << weights.npuw << "\t" |
526 |
> |
<< "won: " << weights.won << "\t" |
527 |
> |
<< "woff: " << weights.woff << endl; |
528 |
|
} |
529 |
|
|
530 |
|
|
534 |
|
<< "\trun: " << evtinfo.run |
535 |
|
<< "\tevt: " << evtinfo.evt |
536 |
|
<< "\tlumi: " << evtinfo.lumi |
537 |
< |
<< "\tcostheta1: " << angles.costheta1 |
538 |
< |
<< "\tcostheta2: " << angles.costheta2 |
539 |
< |
<< "\tcostheta*: " << angles.costhetastar |
540 |
< |
<< "\tbdt: " << angles.bdt |
537 |
> |
<< "\tchannel: " << kinematics.channel |
538 |
> |
<< "\tm4l: " << kinematics.m4l |
539 |
> |
<< "\tmZ1: " << kinematics.mZ1 |
540 |
> |
<< "\tmZ2: " << kinematics.mZ2 |
541 |
|
<< endl; |
542 |
|
pass++; |
543 |
|
// if( pass > 3 ) break; |
557 |
|
} |
558 |
|
foTree.Fill(); |
559 |
|
} else { |
560 |
< |
cout << "failing with some other code : " << ret4l.status.selectionBits << endl; |
560 |
> |
if(ctrl.debug) |
561 |
> |
cout << "failing with some other code : " << ret4l.status.selectionBits << endl; |
562 |
|
} |
563 |
|
} |
564 |
|
|
567 |
|
foTree.getTree()->Write(); |
568 |
|
nt.WriteClose(); |
569 |
|
|
570 |
< |
cout << endl; |
571 |
< |
cout << endl; |
570 |
> |
if(ctrl.debug) |
571 |
> |
cout << endl << endl; |
572 |
|
for( int i=0; i<cutvec.size(); i++ ) { |
573 |
|
cout << "cut: " << i << "\t" |
574 |
|
<< "pass: " << cutvec[i]; |
591 |
|
|
592 |
|
|
593 |
|
//---------------------------------------------------------------------------- |
594 |
< |
void initRunLumiRangeMap() |
594 |
> |
void initRunLumiRangeMap(ControlFlags &ctrl) |
595 |
|
//---------------------------------------------------------------------------- |
596 |
|
{ |
597 |
|
/* |
605 |
|
*/ |
606 |
|
|
607 |
|
// 2012 only for now ... |
608 |
< |
rlrm.AddJSONFile(std::string("./data/Cert_190456-194479_8TeV_PromptReco_Collisions12_JSON.txt")); |
609 |
< |
|
608 |
> |
std::string jsonFile; |
609 |
> |
if(ctrl.jsonFile=="") |
610 |
> |
jsonFile = "./data/Cert_190456-194479_8TeV_PromptReco_Collisions12_JSON.txt"; |
611 |
> |
else |
612 |
> |
jsonFile = ctrl.jsonFile; |
613 |
> |
rlrm.AddJSONFile(jsonFile); |
614 |
|
}; |
636 |
– |
|
637 |
– |
|
638 |
– |
//---------------------------------------------------------------------------- |
639 |
– |
void initPUWeights() |
640 |
– |
//---------------------------------------------------------------------------- |
641 |
– |
{ |
642 |
– |
TFile * puf = new TFile("data/PileupReweighting.Summer11DYmm_To_Full2011.root"); |
643 |
– |
hpu = (TH1D*)(puf->Get("puWeights")); |
644 |
– |
} |
645 |
– |
|
646 |
– |
//---------------------------------------------------------------------------- |
647 |
– |
double getPUWeight(unsigned npu) |
648 |
– |
//---------------------------------------------------------------------------- |
649 |
– |
{ |
650 |
– |
return hpu->GetBinContent(hpu->FindBin(npu)); |
651 |
– |
} |