67 |
|
|
68 |
|
#include "TriggerUtils.h" |
69 |
|
#include "PassHLT.h" |
70 |
– |
#include "Angles.h" |
70 |
|
#include "KinematicsStruct.h" |
71 |
|
#include "InfoStruct.h" |
72 |
|
#include "GenInfoStruct.h" |
73 |
|
#include "WeightStruct.h" |
74 |
|
#include "AngleTuple.h" |
76 |
– |
#include "JetInfoStruct.h" |
75 |
|
#include "FOTuple.h" |
76 |
|
|
77 |
|
#include "RunLumiRangeMap.h" |
81 |
|
|
82 |
|
#include "SimpleLepton.h" |
83 |
|
|
84 |
+ |
#include "Cintex/Cintex.h" |
85 |
+ |
|
86 |
|
#ifndef CMSSW_BASE |
87 |
|
#define CMSSW_BASE "../" |
88 |
|
#endif |
109 |
|
MuCorr *muCorr; |
110 |
|
void addDummyZ2Lepotons(EventData &ret4l); |
111 |
|
void setNtupleVals(ControlFlags &ctrl, EventData &ret4l, InfoStruct &evtinfo, Angles &angles, KinematicsStruct &kine, |
112 |
< |
JetInfoStruct &ji, WeightStruct &weights, EventHeader *info, Array<PFJet> *jetArr, Array<PFMet> *metArr, |
112 |
> |
JetInfoStruct &ji, WeightStruct &weights, EventHeader *info, Array<Muon> *muonArr, Array<Electron> *electronArr, Array<PFJet> *jetArr, Array<PFMet> *metArr, |
113 |
|
vector<SimpleLepton> &simpleLeptonJets, FactorizedJetCorrector *fJetCorrector, Array<PileupInfo> *puArr, |
114 |
|
Array<PileupEnergyDensity> *puDArr, JetIDMVA *fJetIDMVA, Array<Vertex> *vtxArr, bitset<1024> &triggerBits, |
115 |
|
TriggerTable *hltTable, Array<TriggerObject> *hltObjArr, TriggerObjectsTable *fTrigObjs, AngleTuple *nt); |
134 |
|
int main(int argc, char** argv) |
135 |
|
//---------------------------------------------------------------------------- |
136 |
|
{ |
137 |
+ |
|
138 |
|
vector<TString> cuts; |
139 |
|
cuts.push_back("start"); // NOTE: is incremented in ReferenceSelection, so if you turn on JSONS be careful |
140 |
|
cuts.push_back("trigger"); |
145 |
|
cuts.push_back("m4l>70"); |
146 |
|
cuts.push_back("mZ2>12"); |
147 |
|
cuts.push_back("m4l>100"); |
148 |
+ |
cuts.push_back("m4l > 100 && >= 1 jets"); |
149 |
+ |
cuts.push_back("m4l > 100 && 2 jets"); |
150 |
+ |
cuts.push_back("m4l > 100 && fisher > 0.4"); |
151 |
|
|
152 |
|
for(unsigned icut=0; icut<cuts.size(); icut++) |
153 |
|
counts[cuts[icut]] = new map<TString,int>; |
190 |
|
ifstream f(ctrl.inputfiles.c_str()); |
191 |
|
while (f >> fname) { |
192 |
|
if( !(strncmp( fname.c_str(), "#", 1 ) ) ) continue; // skip commented lines |
193 |
< |
if(fname.find("/store/") != string::npos) fname = "root://eoscms//"+fname; |
193 |
> |
//if(fname.find("/store/") != string::npos) fname = "root://eoscms//"+fname; |
194 |
|
cout << "adding inputfile : " << fname.c_str() << endl; |
195 |
|
entrymap[string(fname.c_str())] = unskimmedEntries(fname.c_str()); |
196 |
|
cerr << "unskimmed entries: " << entrymap[string(fname.c_str())] << endl; |
200 |
|
runchain->AddFile(fname.c_str()); |
201 |
|
} |
202 |
|
} else { |
203 |
< |
if(ctrl.inputfile.find("/store/") != string::npos) ctrl.inputfile = "root://eoscms//"+ctrl.inputfile; |
203 |
> |
//if(ctrl.inputfile.find("/store/") != string::npos) ctrl.inputfile = "root://eoscms//"+ctrl.inputfile; |
204 |
|
cout << "adding inputfile : " << ctrl.inputfile.c_str() << endl; |
205 |
|
unsigned unsk_ents = unskimmedEntries(ctrl.inputfile.c_str()); |
206 |
|
entrymap[string(ctrl.inputfile.c_str())] = unsk_ents; |
225 |
|
cout << "xspath: " << xspath.c_str() << endl; |
226 |
|
SimpleTable xstab(xspath.c_str()); |
227 |
|
if(ctrl.mc) { |
228 |
< |
getWeight(xstab,entrymap,chain); // test *now* whether we've got the xs in here, so it fails before it creates the output |
228 |
> |
if(ctrl.use_xs_weights) getWeight(xstab,entrymap,chain); // test *now* whether we've got the xs in here, so it fails before it creates the output |
229 |
|
} |
230 |
|
|
231 |
+ |
//root will write to this temporary file instead of to memory and the selection will run faster |
232 |
+ |
|
233 |
|
// |
234 |
|
// Setup |
235 |
|
//-------------------------------------------------------------------------------------------------------------- |
245 |
|
nt.makeAngleBranch(angles); |
246 |
|
nt.makeKinematicsBranch(kine); |
247 |
|
nt.makeInfoBranch(evtinfo); |
248 |
< |
// nt.makeJetInfoBranch(ji); |
249 |
< |
// nt.makeJetAngleBranches("DataStruct/data/jetAngleVars.txt"); |
248 |
> |
nt.makeJetInfoBranch(ji); |
249 |
> |
//nt.makeJetAngleBranches("DataStruct/data/jetAngleVars.txt"); |
250 |
|
|
251 |
|
FOTuple *foTree=0; |
252 |
|
if(ctrl.fakeScheme != "none") { |
267 |
|
} else |
268 |
|
nt.makeGenInfoBranch(geninfo); |
269 |
|
} |
270 |
< |
initEfficiencyWeights(); |
265 |
< |
// initPUWeights(); |
270 |
> |
if(ctrl.use_eff_weights) initEfficiencyWeights(); |
271 |
|
} else { |
272 |
|
if(!(ctrl.noJSON) ) |
273 |
|
initRunLumiRangeMap(ctrl); |
276 |
|
initElectronIDMVAV1(); |
277 |
|
initTrigger(); |
278 |
|
initAnalysisTriggers(ti); |
279 |
+ |
initMela(ctrl); |
280 |
+ |
initMassErrors(); |
281 |
|
ti.dump(); |
282 |
|
|
283 |
< |
if(ctrl.do_escale) { |
283 |
> |
{ |
284 |
> |
TFile tmp_file("tmp_file.root","RECREATE"); |
285 |
> |
} |
286 |
> |
|
287 |
> |
if(ctrl.do_eregression) { |
288 |
|
string regPath("EGamma/EGammaAnalysisTools/data/eleEnergyRegWeights_V1.root"); |
289 |
|
// if(TString(getenv("HOSTNAME")).Contains(TRegexp("t3[bd][te][cs][hk]"))) |
290 |
< |
regPath = cmsswpath + "/" + regPath; |
290 |
> |
regPath = cmsswpath + "/" + regPath; |
291 |
|
electron_momentum_correction.initialize_regression(regPath); |
281 |
– |
if(ctrl.mc) { |
282 |
– |
if(ctrl.era == 2011) ctrl.smearing_scaling_dataset = "Fall11"; |
283 |
– |
else ctrl.smearing_scaling_dataset = "Summer12_DR53X_HCP2012"; |
284 |
– |
} else { |
285 |
– |
if(ctrl.era == 2011) ctrl.smearing_scaling_dataset = "Jan16ReReco"; |
286 |
– |
else ctrl.smearing_scaling_dataset = "2012Jul13ReReco"; |
287 |
– |
} |
292 |
|
} |
293 |
+ |
|
294 |
|
if(ctrl.correct_muon_momentum) { |
295 |
|
muCorr = new MuCorr; |
296 |
|
muCorr->corr2011 = new rochcor; |
301 |
|
vector<JetCorrectorParameters> correctionParameters; |
302 |
|
FactorizedJetCorrector *fJetCorrector; |
303 |
|
JetIDMVA *fJetIDMVA; |
304 |
< |
// initJets(ctrl, cmsswpath, fJetCorrParsv, correctionParameters, fJetCorrector, fJetIDMVA); |
304 |
> |
initJets(ctrl, cmsswpath, fJetCorrParsv, correctionParameters, fJetCorrector, fJetIDMVA); |
305 |
|
|
306 |
|
// |
307 |
|
// Setup tree I/O |
369 |
|
chain->GetEntry(ientry); |
370 |
|
if(!(ientry%1000)) cerr << "entry: " << ientry << " ( / " << imax << " )" << endl; |
371 |
|
|
372 |
+ |
//if(info->EvtNum() != 217502611) continue; |
373 |
+ |
|
374 |
|
increment(counts,"start"); |
375 |
|
if( ctrl.debug ) { |
376 |
|
cout << "-----------------------------------------------------------------" << endl; |
414 |
|
} |
415 |
|
if( ctrl.debug ) cout << "file is : " << currentFile << endl; |
416 |
|
passes_HLT = passHLT(ctrl, triggerBits, ti, info->RunNum(), hltTable, fTrigObjs); // NOTE: run value is not used if it's MC |
417 |
< |
|
418 |
< |
// data/MC |
419 |
< |
if(ctrl.mc) { |
420 |
< |
if(ctrl.fillGen) fillGenInfo( mcArr, mcEvtInfo, geninfo, genSampleType, ctrl); |
421 |
< |
// NOTE: xs weight and npuw are reset in merge.cc |
422 |
< |
if(ctrl.use_weights) weights.w = getWeight(xstab,entrymap,chain)/ctrl.totalMC; |
423 |
< |
else |
424 |
< |
weights.w = 1; |
425 |
< |
weights.npu = getNPU(puArr, 0); |
426 |
< |
weights.npuw = getPUWeight(ctrl.era, fname, weights.npu); |
427 |
< |
} else { |
428 |
< |
// JSON |
429 |
< |
if(!(ctrl.noJSON) ) { |
430 |
< |
RunLumiRangeMap::RunLumiPairType rl(info->RunNum(), info->LumiSec()); |
431 |
< |
if( !(rlrm.HasRunLumi(rl)) ) { |
432 |
< |
if( ctrl.debug ) cout << "fails JSON" << endl; |
433 |
< |
continue; |
434 |
< |
} |
417 |
> |
|
418 |
> |
// data/MC |
419 |
> |
if(ctrl.mc) { |
420 |
> |
if(ctrl.fillGen) fillGenInfo( mcArr, mcEvtInfo, geninfo, genSampleType, ctrl); |
421 |
> |
// NOTE: xs weight and npuw are reset in merge.cc |
422 |
> |
if(ctrl.use_xs_weights) |
423 |
> |
weights.w = getWeight(xstab,entrymap,chain)/ctrl.totalMC; |
424 |
> |
else |
425 |
> |
weights.w = 1; |
426 |
> |
weights.npu = getNPU(puArr, 0); |
427 |
> |
weights.npuw = getPUWeight(ctrl.era, fname, weights.npu); |
428 |
> |
} else { |
429 |
> |
// JSON |
430 |
> |
if(!(ctrl.noJSON) ) { |
431 |
> |
RunLumiRangeMap::RunLumiPairType rl(info->RunNum(), info->LumiSec()); |
432 |
> |
if( !(rlrm.HasRunLumi(rl)) ) { |
433 |
> |
if( ctrl.debug ) cout << "fails JSON" << endl; |
434 |
> |
continue; |
435 |
|
} |
436 |
|
} |
437 |
|
} |
458 |
|
|
459 |
|
if(ctrl.fakeScheme == "none") { // fill angletuple if event passes full selection |
460 |
|
if( ret4l.status.pass() ) { |
461 |
< |
setNtupleVals(ctrl, ret4l, evtinfo, angles, kine, ji, weights, info, jetArr, metArr, simpleLeptonJets, fJetCorrector, puArr, puDArr, fJetIDMVA, vtxArr, triggerBits, hltTable, hltObjArr, fTrigObjs, &nt); |
461 |
> |
setNtupleVals(ctrl, ret4l, evtinfo, angles, kine, ji, weights, info, muonArr, electronArr, jetArr, metArr, simpleLeptonJets, fJetCorrector, puArr, puDArr, fJetIDMVA, vtxArr, triggerBits, hltTable, hltObjArr, fTrigObjs, &nt); |
462 |
|
nt.Fill(); |
463 |
+ |
|
464 |
+ |
int theZ1type = kine.l1type; |
465 |
+ |
int theZ2type = kine.l3type; |
466 |
+ |
|
467 |
+ |
if(ctrl.debug) cout << "simpleLeptonJets.size() = " << simpleLeptonJets.size() << endl; |
468 |
+ |
|
469 |
+ |
if(kine.m4l > 100){ |
470 |
+ |
if(simpleLeptonJets.size() >= 1) { |
471 |
+ |
increment(counts,"m4l > 100 && >= 1 jets",theZ1type,theZ2type); |
472 |
+ |
if(simpleLeptonJets.size() == 2) { |
473 |
+ |
increment(counts,"m4l > 100 && 2 jets",theZ1type,theZ2type); |
474 |
+ |
SimpleLepton j1 = simpleLeptonJets[0]; |
475 |
+ |
SimpleLepton j2 = simpleLeptonJets[1]; |
476 |
+ |
double deta = abs(j1.vec.Eta()-j2.vec.Eta()); |
477 |
+ |
double mjj = (j1.vec + j2.vec).M(); |
478 |
+ |
double fisher = 0.09407 * deta +0.00041581*mjj; |
479 |
+ |
if(fisher > 0.4) increment(counts, "m4l > 100 && fisher > 0.4",theZ1type,theZ2type); |
480 |
+ |
} |
481 |
+ |
} |
482 |
+ |
} |
483 |
+ |
|
484 |
+ |
|
485 |
|
} else { |
486 |
|
if(ctrl.debug) cout << "failing with code : " << ret4l.status.selectionBits << endl; |
487 |
|
} |
491 |
|
unsigned nleps = passingLeptons.size() + failingLeptons.size(); |
492 |
|
if( (nleps>=3 && ctrl.fakeScheme=="ZPlusF" ) || (nleps>=4 && ctrl.fakeScheme=="ZPlusFF" ) ) { |
493 |
|
addDummyZ2Lepotons(ret4l); |
494 |
< |
setNtupleVals(ctrl, ret4l, evtinfo, angles, kine, ji, weights, info, jetArr, metArr, simpleLeptonJets, fJetCorrector, puArr, puDArr, fJetIDMVA, vtxArr, triggerBits, hltTable, hltObjArr, fTrigObjs, &nt); |
494 |
> |
setNtupleVals(ctrl, ret4l, evtinfo, angles, kine, ji, weights, info, muonArr, electronArr, jetArr, metArr, simpleLeptonJets, fJetCorrector, puArr, puDArr, fJetIDMVA, vtxArr, triggerBits, hltTable, hltObjArr, fTrigObjs, &nt); |
495 |
|
nt.Fill(); |
496 |
|
foTree->Fill(); |
497 |
|
} |
499 |
|
if(ctrl.debug) cout << "failing PASS_GOODZ1" << endl; |
500 |
|
} |
501 |
|
} |
502 |
+ |
|
503 |
+ |
hltTable->Delete(); |
504 |
+ |
|
505 |
|
} |
506 |
|
|
507 |
|
if(ctrl.fakeScheme != "none") { |
512 |
|
|
513 |
|
for(unsigned icut=0; icut<cuts.size(); icut++) { |
514 |
|
map<TString,int> thisCount(*(counts[cuts[icut]])); |
515 |
< |
cerr << setw(20) << cuts[icut] << "\t" << setw(9) << thisCount["all"] << " (" |
515 |
> |
cerr << setw(25) << cuts[icut] << "\t" << setw(9) << thisCount["all"] << " (" |
516 |
|
<< setw(9) << thisCount["4e"] << setw(9) << thisCount["4m"] << setw(9) << thisCount["2e2m"] << ")" << endl; |
517 |
|
} |
518 |
+ |
|
519 |
|
} |
520 |
|
//---------------------------------------------------------------------------------------- |
521 |
|
void addDummyZ2Lepotons(EventData &ret4l) |
529 |
|
} |
530 |
|
//---------------------------------------------------------------------------------------- |
531 |
|
void setNtupleVals(ControlFlags &ctrl, EventData &ret4l, InfoStruct &evtinfo, Angles &angles, KinematicsStruct &kine, |
532 |
< |
JetInfoStruct &ji, WeightStruct &weights, EventHeader *info, Array<PFJet> *jetArr, Array<PFMet> *metArr, |
532 |
> |
JetInfoStruct &ji, WeightStruct &weights, EventHeader *info, Array<Muon> *muonArr, Array<Electron> *electronArr, Array<PFJet> *jetArr, Array<PFMet> *metArr, |
533 |
|
vector<SimpleLepton> &simpleLeptonJets, FactorizedJetCorrector *fJetCorrector, Array<PileupInfo> *puArr, |
534 |
|
Array<PileupEnergyDensity> *puDArr, JetIDMVA *fJetIDMVA, Array<Vertex> *vtxArr, bitset<1024> &triggerBits, |
535 |
|
TriggerTable *hltTable, Array<TriggerObject> *hltObjArr, TriggerObjectsTable *fTrigObjs, AngleTuple *nt) |
536 |
|
{ |
537 |
|
fillKinematics(ret4l,kine); |
538 |
< |
// fillMassErrors(ret4l,muonArr,electronArr,kine); |
538 |
> |
|
539 |
> |
//the last two arguments are usePt and useY respectively |
540 |
> |
fillMela(kine,0,0); |
541 |
> |
|
542 |
> |
fillMassErrors(ctrl,ret4l,muonArr,electronArr,kine); |
543 |
> |
|
544 |
|
TLorentzVector pfmet; pfmet.SetPxPyPzE(metArr->At(0)->Mex(),metArr->At(0)->Mey(),0,0); |
545 |
|
fillEventInfo( info, pfmet, evtinfo, ctrl.mc ? getNPU(puArr) : 0, vtxArr->GetEntries()); |
546 |
< |
// fillJets(ctrl, jetArr, simpleLeptonJets, fJetCorrector, puDArr, fJetIDMVA, vtxArr, ret4l); |
547 |
< |
// fillJetInfo(simpleLeptonJets, ji, ctrl); |
548 |
< |
// fillJetAngleBranches(ji, ret4l, nt, ctrl); |
546 |
> |
fillJets(ctrl, jetArr, simpleLeptonJets, fJetCorrector, puDArr, fJetIDMVA, vtxArr, ret4l); |
547 |
> |
fillJetInfo(simpleLeptonJets, ji, ctrl); |
548 |
> |
//fillJetAngleBranches(ji, ret4l, nt, ctrl); |
549 |
|
evtinfo.status = 0; |
550 |
|
evtinfo.status = setHltBits(ti, triggerBits); |
551 |
|
|
553 |
|
fillAngles(ret4l,angles); |
554 |
|
|
555 |
|
if( ctrl.mc) { |
556 |
< |
setEfficiencyWeights(ctrl, ctrl.era, ret4l, triggerBits, hltTable, hltObjArr, fTrigObjs, weights); |
556 |
> |
if(ctrl.use_eff_weights) setEfficiencyWeights(ctrl, ctrl.era, ret4l, triggerBits, hltTable, hltObjArr, fTrigObjs, weights); |
557 |
|
if(ctrl.debug) |
558 |
|
cout << "w: " << weights.w << "\t" << "npuw: " << weights.npuw << "\t" << "won: " << weights.won << "\t" << "woff: " << weights.woff << endl; |
559 |
|
} |