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 |
|
// |
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" |
40 |
+ |
#include "PileupEnergyDensity.h" |
41 |
+ |
#include "MCParticle.h" |
42 |
|
#include "TriggerMask.h" |
43 |
|
#include "TriggerTable.h" |
44 |
+ |
#include "TriggerObject.h" |
45 |
+ |
#include "TriggerObjectRel.h" |
46 |
|
#include "Names.h" |
47 |
|
#include "BaseMod.h" |
48 |
+ |
#include "TriggerObjectsTable.h" |
49 |
|
|
50 |
|
// |
51 |
|
// our headers |
53 |
|
#include "ParseArgs.h" |
54 |
|
#include "MuonSelection.h" |
55 |
|
#include "ElectronSelection.h" |
56 |
+ |
#include "ElectronMomentumCorrection.h" |
57 |
|
#include "IsolationSelection.h" |
58 |
< |
#include "Selection.h" |
58 |
> |
#include "ReferenceSelection.h" |
59 |
> |
|
60 |
|
#include "TriggerUtils.h" |
61 |
|
#include "PassHLT.h" |
62 |
|
#include "Angles.h" |
63 |
|
#include "KinematicsStruct.h" |
64 |
|
#include "InfoStruct.h" |
65 |
< |
//#include "GenInfoStruct.h" |
65 |
> |
#include "GenInfoStruct.h" |
66 |
|
#include "WeightStruct.h" |
57 |
– |
#include "GlobalDataAndFuncs.h" |
67 |
|
#include "AngleTuple.h" |
68 |
+ |
#include "FOTuple.h" |
69 |
|
|
70 |
+ |
#include "RunLumiRangeMap.h" |
71 |
|
#include "SampleWeight.h" |
72 |
|
#include "EfficiencyWeightsInterface.h" |
73 |
+ |
#include "SelectionFuncs.h" |
74 |
+ |
|
75 |
+ |
#include "SimpleLepton.h" |
76 |
|
|
77 |
|
#ifndef CMSSW_BASE |
78 |
|
#define CMSSW_BASE "../" |
80 |
|
|
81 |
|
using namespace mithep; |
82 |
|
|
83 |
+ |
// |
84 |
+ |
// globals |
85 |
+ |
//---------------------------------------------------------------------------- |
86 |
+ |
TH1D *hpu_2011, *hpu_2012; |
87 |
+ |
RunLumiRangeMap rlrm; |
88 |
+ |
vector<SimpleLepton> failingLeptons ; // for fake estimation |
89 |
+ |
vector<SimpleLepton> passingLeptons; // for fake estimation |
90 |
+ |
vector<unsigned> cutvec; |
91 |
+ |
vector<vector<unsigned> > zcutvec; |
92 |
+ |
vector<vector<unsigned> > zzcutvec; |
93 |
+ |
map<unsigned,float> evtrhoMap; |
94 |
+ |
vector<string> cutstrs; |
95 |
+ |
bool passes_HLT_MC,passes_HLT; |
96 |
+ |
vector<bool> PFnoPUflag;; |
97 |
|
|
98 |
+ |
// |
99 |
+ |
// prototypes |
100 |
|
//---------------------------------------------------------------------------- |
101 |
< |
bool setPV(ControlFlags,const mithep::Array<mithep::Vertex>*, mithep::Vertex& ); |
101 |
> |
void initRunLumiRangeMap(ControlFlags &ctrl); |
102 |
|
//---------------------------------------------------------------------------- |
103 |
|
|
104 |
< |
//=== MAIN ================================================================================================= |
104 |
> |
// |
105 |
> |
// MAIN |
106 |
> |
//---------------------------------------------------------------------------- |
107 |
|
int main(int argc, char** argv) |
108 |
+ |
//---------------------------------------------------------------------------- |
109 |
|
{ |
110 |
+ |
cutstrs.push_back(string("skim0")); //0 |
111 |
+ |
cutstrs.push_back(string("skim1")); //1 |
112 |
+ |
cutstrs.push_back(string("skim2")); //1 |
113 |
+ |
cutstrs.push_back(string("trigger")); //2 |
114 |
+ |
// ------------------------------------------------- |
115 |
+ |
cutstrs.push_back(string("Z candidate")); //3 |
116 |
+ |
cutstrs.push_back(string("good Z1")); //4 |
117 |
+ |
// ------------------------------------------------- |
118 |
+ |
cutstrs.push_back(string("4l")); //5 |
119 |
+ |
cutstrs.push_back(string("ZZ candidate")); //6 |
120 |
+ |
cutstrs.push_back(string("good Z2")); //7 |
121 |
+ |
cutstrs.push_back(string("ZZ 20/10")); //8 |
122 |
+ |
cutstrs.push_back(string("resonance")); //9 |
123 |
+ |
cutstrs.push_back(string("m4l>70")); //10 |
124 |
+ |
cutstrs.push_back(string("m4l>100, mZ2 > 12")); //11 |
125 |
+ |
|
126 |
+ |
|
127 |
+ |
|
128 |
+ |
|
129 |
|
string cmsswpath(CMSSW_BASE); |
130 |
|
cmsswpath.append("/src"); |
131 |
|
std::bitset<1024> triggerBits; |
132 |
|
vector<vector<string> > inputFiles; |
133 |
|
inputFiles.push_back(vector<string>()); |
134 |
< |
map<string,double> entrymap; // number of unskimmed entries in each file |
134 |
> |
map<string,unsigned> entrymap; // number of unskimmed entries in each file |
135 |
> |
for( int i=0; i<cutstrs.size(); i++ ) cutvec.push_back(0); |
136 |
> |
for( int i=0; i<2; i++ ) { |
137 |
> |
zcutvec.push_back(vector<unsigned>()); |
138 |
> |
for( int j=0; j<cutstrs.size(); j++ ) zcutvec[i].push_back(0); |
139 |
> |
} |
140 |
> |
for( int i=0; i<3; i++ ) { |
141 |
> |
zzcutvec.push_back(vector<unsigned>()); |
142 |
> |
for( int j=0; j<cutstrs.size(); j++ ) zzcutvec[i].push_back(0); |
143 |
> |
} |
144 |
> |
|
145 |
|
|
146 |
|
// |
147 |
|
// args |
158 |
|
return 1; |
159 |
|
} |
160 |
|
ctrl.dump(); |
99 |
– |
assert( ctrl.mH != 0 ); |
161 |
|
|
162 |
|
|
163 |
|
|
166 |
|
//-------------------------------------------------------------------------------------------------------------- |
167 |
|
TChain * chain = new TChain("Events"); |
168 |
|
TChain * hltchain = new TChain("HLT"); |
169 |
+ |
TChain * runchain = new TChain(Names::gkRunTreeName); |
170 |
|
|
171 |
|
string fname; |
172 |
+ |
unsigned total_unskimmed=0; |
173 |
|
if( !ctrl.inputfiles.empty() ) { |
174 |
|
ifstream f(ctrl.inputfiles.c_str()); |
175 |
|
while (f >> fname) { |
176 |
|
if( !(strncmp( fname.c_str(), "#", 1 ) ) ) continue; // skip commented lines |
177 |
|
cout << "adding inputfile : " << fname.c_str() << endl; |
178 |
|
entrymap[string(fname.c_str())] = unskimmedEntries(fname.c_str()); |
179 |
+ |
cout << "unskimmed entries: " << entrymap[string(fname.c_str())] << endl; |
180 |
+ |
total_unskimmed += entrymap[string(fname.c_str())]; |
181 |
|
chain->AddFile(fname.c_str()); |
182 |
|
hltchain->AddFile(fname.c_str()); |
183 |
+ |
runchain->AddFile(fname.c_str()); |
184 |
|
} |
185 |
|
} else { |
186 |
|
cout << "adding inputfile : " << ctrl.inputfile.c_str() << endl; |
187 |
< |
entrymap[string(ctrl.inputfile.c_str())] = unskimmedEntries(ctrl.inputfile.c_str()); |
187 |
> |
unsigned unsk_ents = unskimmedEntries(ctrl.inputfile.c_str()); |
188 |
> |
entrymap[string(ctrl.inputfile.c_str())] = unsk_ents; |
189 |
> |
cout << "unskimmed entries: " << unsk_ents << endl; |
190 |
> |
total_unskimmed += unsk_ents; |
191 |
|
chain->AddFile(ctrl.inputfile.c_str()); |
192 |
|
hltchain->AddFile(ctrl.inputfile.c_str()); |
193 |
+ |
runchain->AddFile(ctrl.inputfile.c_str()); |
194 |
|
} |
195 |
+ |
// // write the total number of unskimmed events that went into making this output file to a text file |
196 |
+ |
writeEntries(ctrl,total_unskimmed); |
197 |
|
|
198 |
|
const char * ofname; |
199 |
|
if( strcmp( ctrl.outputfile.c_str(), "") ) { |
207 |
|
SimpleTable xstab(xspath.c_str()); |
208 |
|
|
209 |
|
|
210 |
+ |
|
211 |
|
// |
212 |
|
// Setup |
213 |
|
//-------------------------------------------------------------------------------------------------------------- |
215 |
|
KinematicsStruct kinematics; |
216 |
|
InfoStruct evtinfo; |
217 |
|
WeightStruct weights; |
218 |
< |
// GenInfoStruct geninfo; |
218 |
> |
GenInfoStruct geninfo; |
219 |
|
|
220 |
|
AngleTuple nt( (const char*)ofname, (const char*)"zznt"); |
221 |
|
nt.makeAngleBranch(angles); |
222 |
|
nt.makeKinematicsBranch(kinematics); |
223 |
|
nt.makeInfoBranch(evtinfo); |
224 |
|
|
225 |
< |
TH1F * h_w_hpt; |
225 |
> |
|
226 |
> |
FOTuple foTree( nt.getFile(), (const char*)"FOtree"); |
227 |
> |
foTree.makeInfoBranch(evtinfo); |
228 |
> |
foTree.makeFailedLeptonBranch(failingLeptons); |
229 |
> |
foTree.makePassedLeptonBranch(passingLeptons); |
230 |
> |
|
231 |
> |
TH1F * h_wf11_hpt; |
232 |
|
if(ctrl.mc) { |
233 |
|
nt.makeWeightBranch(weights); |
234 |
< |
// nt.makeGenInfoBranch(geninfo); |
235 |
< |
initEfficiencyWeights(); |
236 |
< |
/* |
234 |
> |
if(ctrl.fillGen ) nt.makeGenInfoBranch(geninfo); |
235 |
> |
//initEfficiencyWeights(); |
236 |
> |
initPUWeights(); |
237 |
> |
|
238 |
|
// Higgs only, pt reweighting |
239 |
|
if( ctrl.mH <= 140 ) { |
240 |
|
char wptname[256]; |
242 |
|
TFile * f_hpt = new TFile(wptname); |
243 |
|
f_hpt->Print(); |
244 |
|
sprintf(wptname, "weight_hqt_fehipro_fit_%i", ctrl.mH); |
245 |
< |
h_w_hpt = (TH1F*)(f_hpt->FindObjectAny(wptname)); |
166 |
< |
h_w_hpt->Print(); |
245 |
> |
h_wf11_hpt = (TH1F*)(f_hpt->FindObjectAny(wptname)); |
246 |
|
} |
247 |
< |
*/ |
247 |
> |
|
248 |
|
} else { |
249 |
< |
initRunLumiRangeMap(); |
249 |
> |
initRunLumiRangeMap(ctrl); |
250 |
|
} |
251 |
|
|
252 |
< |
initMuonIDMVA(); |
253 |
< |
initMuonIsoMVA(); |
175 |
< |
initElectronIDMVA(); |
176 |
< |
initElectronIsoMVA(); |
252 |
> |
// initMuonIDMVA(); |
253 |
> |
initElectronIDMVAV1(); |
254 |
|
initTrigger(); |
255 |
< |
|
256 |
< |
|
257 |
< |
//########################################################################## |
258 |
< |
// Setup tree I/O |
259 |
< |
//########################################################################## |
183 |
< |
|
255 |
> |
ElectronMomentumCorrection electron_mom_corr; |
256 |
> |
electron_mom_corr.initialize_regression("../EGamma/EGammaAnalysisTools/data/eleEnergyRegWeights_V1.root"); |
257 |
> |
TrigInfo ti; |
258 |
> |
initAnalysisTriggers(ti); |
259 |
> |
|
260 |
|
// |
261 |
< |
// Access samples and fill histograms |
261 |
> |
// Setup tree I/O |
262 |
> |
//-------------------------------------------------------------------------------------------------------------- |
263 |
|
TFile *inputFile=0; |
264 |
|
TTree *eventTree=0; |
265 |
|
string currentFile(""); |
266 |
|
|
267 |
< |
// Data structures to store info from TTrees |
268 |
< |
mithep::EventHeader *info = new mithep::EventHeader(); |
269 |
< |
// mithep::TGenInfo *ginfo = new mithep::TGenInfo(); |
267 |
> |
UInt_t fNMaxTriggers = 1024; |
268 |
> |
mithep::EventHeader *info = new mithep::EventHeader(); |
269 |
> |
mithep::Array<mithep::PFMet> *metArr = new mithep::Array<mithep::PFMet>(); |
270 |
|
mithep::Array<mithep::Electron> *electronArr = new mithep::Array<mithep::Electron>(); |
271 |
|
mithep::Array<mithep::Muon> *muonArr = new mithep::Array<mithep::Muon>(); |
272 |
|
mithep::Array<mithep::Vertex> *vtxArr = new mithep::Array<mithep::Vertex>(); |
273 |
|
mithep::Array<mithep::PFCandidate> *pfArr = new mithep::Array<mithep::PFCandidate>(); |
274 |
< |
mithep::Array<mithep::PileupEnergyDensity> *puArr = new mithep::Array<mithep::PileupEnergyDensity>(); |
274 |
> |
mithep::Array<mithep::PileupInfo> *puArr = new mithep::Array<mithep::PileupInfo>(); |
275 |
> |
mithep::Array<mithep::PileupEnergyDensity> *puDArr = new mithep::Array<mithep::PileupEnergyDensity>(); |
276 |
|
mithep::Array<mithep::Track> *trkArr = new mithep::Array<mithep::Track>(); |
277 |
+ |
mithep::Array<mithep::MCParticle> *mcArr = new mithep::Array<mithep::MCParticle>(); |
278 |
+ |
mithep::MCEventInfo *mcEvtInfo = new mithep::MCEventInfo(); |
279 |
|
mithep::TriggerMask *trigMask = new mithep::TriggerMask(); |
280 |
< |
mithep::TriggerTable *hltTable = new mithep::TriggerTable(); |
280 |
> |
mithep::TriggerTable *hltTable = new mithep::TriggerTable(fNMaxTriggers); |
281 |
|
vector<string> *hltTableStrings = new vector<string>(); |
282 |
+ |
vector<string> *hltLabelStrings = new vector<string>(); |
283 |
+ |
mithep::Array<mithep::TriggerObject> *hltObjArr = new mithep::Array<mithep::TriggerObject>(); |
284 |
+ |
mithep::Array<mithep::TriggerObjectRel> *hltRelsArr = new mithep::Array<mithep::TriggerObjectRel>(); |
285 |
+ |
std::vector<std::string> *hltTab = new vector<string>(); |
286 |
+ |
std::vector<std::string> *hltLab = new vector<string>(); |
287 |
+ |
TriggerObjectsTable *fTrigObjs = new TriggerObjectsTable(hltTable,fNMaxTriggers); |
288 |
+ |
|
289 |
+ |
RunInfo *runInfo = new RunInfo(); |
290 |
|
|
291 |
|
TString fElectronName(Names::gkElectronBrn); |
292 |
|
TString fMuonName(Names::gkMuonBrn); |
293 |
|
TString fInfoName(Names::gkEvtHeaderBrn); |
294 |
+ |
TString fPFMetName("PFMet"); |
295 |
|
TString fPrimVtxName(Names::gkPVBrn); |
296 |
|
TString fPFCandidateName(Names::gkPFCandidatesBrn); |
297 |
+ |
TString fPileupInfoName(Names::gkPileupInfoBrn); |
298 |
|
TString fPileupEnergyDensityName(Names::gkPileupEnergyDensityBrn); |
299 |
|
TString fTrackName(Names::gkTrackBrn); |
300 |
+ |
TString fMCParticleName(Names::gkMCPartBrn); |
301 |
+ |
TString fMCEvtInfoName(Names::gkMCEvtInfoBrn); |
302 |
|
TString fTriggerMaskName(Names::gkHltBitBrn); |
303 |
|
TString fTriggerTableName(Names::gkHltTableBrn); |
304 |
+ |
TString fTriggerLabelName(Names::gkHltLabelBrn); |
305 |
+ |
TString fTriggerObjectName(Names::gkHltObjBrn); |
306 |
+ |
TString fTriggerObjectRelsName(Form("HLTObjectsRelation")); |
307 |
+ |
|
308 |
+ |
// TString fHLTLabName(Names::gkHltLabelBrn); |
309 |
+ |
// TString fHLTTabName(Names::gkHltTableBrn); |
310 |
+ |
// TString fHLTTabNamePub(Form("%sFwk",fHLTTabName.Data())); |
311 |
+ |
// TString fHLTLabNamePub(Form("%sFwk",fHLTLabName.Data())); |
312 |
+ |
// TString fObjsNamePub(Form("%sFwk",fTriggerObjectName.Data())); |
313 |
+ |
|
314 |
+ |
|
315 |
|
|
316 |
|
chain->SetBranchAddress(fInfoName, &info); |
317 |
+ |
chain->SetBranchAddress(fPFMetName, &metArr); |
318 |
|
chain->SetBranchAddress(fElectronName, &electronArr); |
319 |
|
chain->SetBranchAddress(fMuonName, &muonArr); |
320 |
|
chain->SetBranchAddress(fPrimVtxName, &vtxArr); |
321 |
|
chain->SetBranchAddress(fPFCandidateName, &pfArr); |
322 |
< |
chain->SetBranchAddress(fPileupEnergyDensityName, &puArr); |
322 |
> |
if( ctrl.mc ) { |
323 |
> |
chain->SetBranchAddress(fPileupInfoName, &puArr); |
324 |
> |
chain->SetBranchAddress(fMCParticleName, &mcArr); |
325 |
> |
chain->SetBranchAddress(fMCEvtInfoName, &mcEvtInfo); |
326 |
> |
} |
327 |
> |
chain->SetBranchAddress(fPileupEnergyDensityName, &puDArr); |
328 |
|
chain->SetBranchAddress(fTrackName, &trkArr); |
329 |
|
chain->SetBranchAddress(fTriggerMaskName, &trigMask); |
330 |
+ |
chain->SetBranchAddress(fTriggerObjectName, &hltObjArr); |
331 |
+ |
chain->SetBranchAddress(fTriggerObjectRelsName, &hltRelsArr); |
332 |
+ |
// chain->SetBranchAddress(fHLTTabNamePub, &hltTab); |
333 |
+ |
// chain->SetBranchAddress(fHLTLabNamePub, &hltLab); |
334 |
+ |
|
335 |
|
cout << "hlttable: " << fTriggerTableName << endl; |
336 |
|
hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings); |
337 |
+ |
hltchain->SetBranchAddress(fTriggerLabelName, &hltLabelStrings); |
338 |
+ |
|
339 |
+ |
runchain->SetBranchAddress(Names::gkRunInfoBrn, &runInfo); |
340 |
|
|
341 |
|
mithep::Vertex vtx; // best primary vertex in the event |
342 |
|
|
351 |
|
|
352 |
|
// only 1 HLT table / file ??? |
353 |
|
hltchain->GetEntry(0); |
237 |
– |
cerr << "here... " << endl; |
354 |
|
|
355 |
< |
int imax = chain->GetEntries(); |
356 |
< |
cout << "nEntries: " << imax << endl; |
355 |
> |
int imax; |
356 |
> |
//-1 means process all of the events |
357 |
> |
if(ctrl.n_events_to_process != -2 && ctrl.n_events_to_process != -1){ |
358 |
> |
if(ctrl.n_events_to_process > chain->GetEntries()){ |
359 |
> |
cerr << "error: n_events_to_process is larger than chain->GetEntries()" << endl; |
360 |
> |
return 1; |
361 |
> |
} |
362 |
> |
imax = ctrl.n_events_to_process; |
363 |
> |
} |
364 |
> |
else |
365 |
> |
imax = chain->GetEntries(); |
366 |
|
|
367 |
+ |
cout << "number of events to process: " << imax << endl; |
368 |
|
|
369 |
< |
//########################################################################## |
370 |
< |
// Loop !!!!!!!!! should alternate events here and +1 in the training ... |
371 |
< |
//########################################################################## |
369 |
> |
// |
370 |
> |
// Loop !!!!!!!!! |
371 |
> |
//-------------------------------------------------------------------------------------------------------------- |
372 |
> |
int lastHltEntry=-2; |
373 |
|
for(UInt_t ientry=0; ientry<imax; ientry++) |
374 |
|
{ |
375 |
|
chain->GetEntry(ientry); |
376 |
|
if(!(ientry%1000)) cerr << "entry: " << ientry << endl; |
377 |
|
|
378 |
< |
setPV( ctrl, vtxArr, vtx); |
379 |
< |
|
380 |
< |
if(ctrl.mc) { |
381 |
< |
weights.w = getWeight(xstab,entrymap,chain); |
382 |
< |
} else { |
383 |
< |
if( string(chain->GetFile()->GetEndpointUrl()->GetFile()) != currentFile ) { |
384 |
< |
currentFile = string(chain->GetFile()->GetEndpointUrl()->GetFile()); |
385 |
< |
hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings); |
386 |
< |
hltchain->GetEntry(0); |
387 |
< |
hltTable->Clear(); |
388 |
< |
fillTriggerBits(hltTable, hltTableStrings ); |
389 |
< |
} |
263 |
< |
if( ctrl.debug ) cout << "file is : " << currentFile << endl; |
264 |
< |
fillTriggerBits( hltTable, trigMask, triggerBits ); |
378 |
> |
if( ctrl.debug ) { |
379 |
> |
cout << "-----------------------------------------------------------------" << endl; |
380 |
> |
cout << "-----------------------------------------------------------------" << endl; |
381 |
> |
cout << "Run: " << info->RunNum() |
382 |
> |
<< "\tEvt: " << info->EvtNum() |
383 |
> |
<< "\tLumi: " << info->LumiSec() |
384 |
> |
<< endl; |
385 |
> |
cerr << "Run: " << info->RunNum() |
386 |
> |
<< "\tEvt: " << info->EvtNum() |
387 |
> |
<< "\tLumi: " << info->LumiSec() |
388 |
> |
<< endl; |
389 |
> |
cout << "-----------------------------------------------------------------" << endl; |
390 |
|
} |
391 |
+ |
|
392 |
+ |
runchain->GetEvent(info->RunEntry()); |
393 |
+ |
hltchain->GetEntry(runInfo->HltEntry()); |
394 |
+ |
hltTable->Clear(); |
395 |
+ |
fillTriggerNames(hltTable, hltTableStrings ); |
396 |
+ |
if(ctrl.debug && (lastHltEntry != runInfo->HltEntry())) hltTable->Print(); |
397 |
+ |
lastHltEntry = runInfo->HltEntry(); |
398 |
+ |
fillTriggerBits( hltTable, trigMask, triggerBits ); |
399 |
+ |
setHLTObjectRelations( hltObjArr, hltRelsArr, hltTableStrings, hltLabelStrings, fTrigObjs ); |
400 |
+ |
// printTriggerObjs( hltTable, fTrigObjs); |
401 |
|
|
402 |
< |
|
402 |
> |
string fname = string(chain->GetFile()->GetEndpointUrl()->GetFile()); |
403 |
> |
if(ctrl.debug) cout << "era is " << ctrl.era << endl; |
404 |
> |
if( ctrl.era == 0 ) { |
405 |
> |
setEra( fname, ctrl ); |
406 |
> |
if(ctrl.debug) cout << "era is now " << ctrl.era << endl; |
407 |
> |
} |
408 |
> |
|
409 |
> |
// |
410 |
> |
// pfNoPU |
411 |
> |
// |
412 |
> |
//mithep::Array<PFCandidate> pfNoPileUp; |
413 |
> |
PFnoPUflag.clear(); |
414 |
> |
int pfnopu_size = makePFnoPUArray( pfArr, PFnoPUflag, vtxArr ); |
415 |
> |
assert(pfnopu_size == pfArr->GetEntries()); |
416 |
> |
|
417 |
|
// |
418 |
|
// trigger |
419 |
|
// |
420 |
< |
if( !ctrl.mc ) { |
421 |
< |
if( !passHLT(triggerBits, info->RunNum(), info->EvtNum() ) ) { |
422 |
< |
if( ctrl.debug ) cout << "\tfails trigger ... " << endl; |
423 |
< |
continue; |
420 |
> |
if( string(chain->GetFile()->GetEndpointUrl()->GetFile()) != currentFile ) { |
421 |
> |
currentFile = string(chain->GetFile()->GetEndpointUrl()->GetFile()); |
422 |
> |
} |
423 |
> |
if( ctrl.debug ) cout << "file is : " << currentFile << endl; |
424 |
> |
|
425 |
> |
// |
426 |
> |
// data/MC |
427 |
> |
// |
428 |
> |
if(ctrl.mc) { |
429 |
> |
// |
430 |
> |
// gen info |
431 |
> |
// |
432 |
> |
if( ctrl.fillGen ) |
433 |
> |
fillGenInfo( mcArr, mcEvtInfo, geninfo, ESampleType::kHZZ, ctrl); |
434 |
> |
|
435 |
> |
// |
436 |
> |
// xsec & PU weights |
437 |
> |
// |
438 |
> |
weights.w = getWeight(xstab,entrymap,chain)/ctrl.totalMC; |
439 |
> |
cout << "xsec weight: " << weights.w << endl; |
440 |
> |
|
441 |
> |
unsigned npu = getNPU(puArr, 0); |
442 |
> |
weights.npu = npu; |
443 |
> |
weights.npuw = getPUWeight(ctrl.era,npu); |
444 |
> |
cerr << "weights.npuw: " << weights.npuw << endl; |
445 |
> |
|
446 |
> |
// |
447 |
> |
// pt reweighting for Higgs < 140, F11 |
448 |
> |
// |
449 |
> |
if( ctrl.fillGen ) { |
450 |
> |
if( (fname.find("f11-h115zz4l") != string::npos) || |
451 |
> |
(fname.find("f11-h120zz4l") != string::npos) || |
452 |
> |
(fname.find("f11-h130zz4l") != string::npos) ) { |
453 |
> |
weights.w *= h_wf11_hpt->GetBinContent(h_wf11_hpt->FindBin(geninfo.pt_zz)); |
454 |
> |
} |
455 |
|
} |
456 |
+ |
|
457 |
+ |
// trigger |
458 |
+ |
passes_HLT_MC = true; // passed to apply as extern global, just for sync |
459 |
+ |
if( !passHLTMC(triggerBits, info->RunNum(), info->EvtNum(), k2012_MC ) ) { |
460 |
+ |
passes_HLT_MC = false; |
461 |
+ |
} |
462 |
+ |
|
463 |
+ |
} else { |
464 |
+ |
// |
465 |
+ |
// JSON |
466 |
+ |
// |
467 |
+ |
if(!(ctrl.noJSON) ) { |
468 |
+ |
RunLumiRangeMap::RunLumiPairType rl(info->RunNum(), info->LumiSec()); |
469 |
+ |
if( !(rlrm.HasRunLumi(rl)) ) { |
470 |
+ |
if( ctrl.debug ) cout << "fails JSON" << endl; |
471 |
+ |
continue; |
472 |
+ |
} |
473 |
+ |
} |
474 |
+ |
|
475 |
+ |
// trigger |
476 |
+ |
passes_HLT = true; |
477 |
+ |
//if( !passHLT(ctrl, triggerBits,ti,info->RunNum()) ) { |
478 |
+ |
// passes_HLT = false; |
479 |
+ |
//} |
480 |
+ |
|
481 |
|
} |
482 |
< |
|
482 |
> |
|
483 |
|
// |
484 |
|
// lepton/kinematic selection ... |
485 |
|
// |
486 |
+ |
failingLeptons.clear(); |
487 |
+ |
passingLeptons.clear(); |
488 |
|
EventData ret4l = |
489 |
< |
apply_HZZ4L_selection(ctrl, info, |
490 |
< |
vtx, |
491 |
< |
pfArr, |
492 |
< |
puArr, |
493 |
< |
electronArr, |
494 |
< |
&electronPreSelection, |
495 |
< |
// &electronBDTSelection, |
496 |
< |
&electronIDMVASelection, |
497 |
< |
// &electronIsoSelection, |
498 |
< |
&electronIsoMVASelection, |
499 |
< |
muonArr, |
500 |
< |
&muonPreSelection, |
501 |
< |
&muonIDPFSelection, |
502 |
< |
// &muonIDMVASelection, |
503 |
< |
// &passMuonSelection, |
504 |
< |
&muonIsoMVASelection); |
489 |
> |
|
490 |
> |
|
491 |
> |
// reference |
492 |
> |
apply_HZZ4L_reference_selection(ctrl, info, |
493 |
> |
vtxArr, |
494 |
> |
pfArr, |
495 |
> |
puDArr, |
496 |
> |
electronArr, |
497 |
> |
&electronReferencePreSelection, |
498 |
> |
&electronReferenceIDMVASelectionV1, |
499 |
> |
&electronReferenceIsoSelection, |
500 |
> |
muonArr, |
501 |
> |
&muonReferencePreSelection, |
502 |
> |
&muonIDPFSelection, |
503 |
> |
&muonReferenceIsoSelection); |
504 |
> |
|
505 |
|
if( ctrl.debug ) cout << endl; |
506 |
+ |
|
507 |
+ |
|
508 |
+ |
int Z1type=0, Z2type=0; |
509 |
+ |
if( ret4l.status.selectionBits.to_ulong() >= PASS_ZCANDIDATE ) { |
510 |
+ |
if( abs(ret4l.Z1leptons[0].type) == 11 ) Z1type = 11; |
511 |
+ |
if( abs(ret4l.Z1leptons[0].type) == 13 ) Z1type = 13; |
512 |
+ |
} |
513 |
+ |
if( ret4l.status.selectionBits.to_ulong() >= PASS_ZZCANDIDATE ) { |
514 |
+ |
if( abs(ret4l.Z2leptons[0].type) == 11 ) Z2type = 11; |
515 |
+ |
if( abs(ret4l.Z2leptons[0].type) == 13 ) Z2type = 13; |
516 |
+ |
} |
517 |
|
|
518 |
|
if( ret4l.status.pass() ) { |
301 |
– |
|
519 |
|
fillAngles(ret4l,angles); |
520 |
|
fillKinematics(ret4l,kinematics); |
521 |
< |
fillEventInfo(info,evtinfo); |
522 |
< |
//if(ctrl.mc) fillGenInfo(ginfo,geninfo); |
521 |
> |
fillMassErrors(ret4l,muonArr,electronArr,kinematics); |
522 |
> |
TLorentzVector pfmet; pfmet.SetPxPyPzE(metArr->At(0)->Mex(),metArr->At(0)->Mey(),0,0); |
523 |
> |
fillEventInfo( info, pfmet, evtinfo, ctrl.mc ? getNPU(puArr) : 0); |
524 |
> |
if( ctrl.mc) { |
525 |
> |
//setEffiencyWeights(ctrl.era, ret4l, triggerBits, hltTable, hltObjArr, fTrigObjs, weights); |
526 |
> |
if(ctrl.debug) |
527 |
> |
cout << "w: " << weights.w << "\t" |
528 |
> |
<< "npuw: " << weights.npuw << "\t" |
529 |
> |
<< "won: " << weights.won << "\t" |
530 |
> |
<< "woff: " << weights.woff << endl; |
531 |
> |
} |
532 |
|
|
533 |
< |
/* |
308 |
< |
// only for Higgs < 140 |
309 |
< |
geninfo.weight *= h_w_hpt->GetBinContent(h_w_hpt->FindBin(geninfo.pt_zz)); |
310 |
< |
angles.bdt = reader->EvaluateMVA("BDTG"); |
311 |
< |
*/ |
533 |
> |
|
534 |
|
nt.Fill(); |
535 |
|
|
536 |
|
cerr << "PASS:: " |
537 |
|
<< "\trun: " << evtinfo.run |
538 |
|
<< "\tevt: " << evtinfo.evt |
539 |
|
<< "\tlumi: " << evtinfo.lumi |
540 |
< |
<< "\tcostheta1: " << angles.costheta1 |
541 |
< |
<< "\tcostheta2: " << angles.costheta2 |
542 |
< |
<< "\tcostheta*: " << angles.costhetastar |
543 |
< |
<< "\tbdt: " << angles.bdt |
540 |
> |
<< "\tchannel: " << kinematics.channel |
541 |
> |
<< "\tm4l: " << kinematics.m4l |
542 |
> |
<< "\tmZ1: " << kinematics.mZ1 |
543 |
> |
<< "\tmZ2: " << kinematics.mZ2 |
544 |
|
<< endl; |
545 |
|
pass++; |
546 |
|
// if( pass > 3 ) break; |
547 |
|
|
548 |
< |
} |
549 |
< |
} |
548 |
> |
} else if( ret4l.status.selectionBits.test(PASS_GOODZ1) && |
549 |
> |
ret4l.status.selectionBits.to_ulong() < (1UL<<PASS_4L)) { // save for fakes ... |
550 |
> |
if(ctrl.debug) { |
551 |
> |
cout << "failingLeptons : " << failingLeptons.size() << endl; |
552 |
> |
for( int f=0; f<failingLeptons.size(); f++ ) { |
553 |
> |
SimpleLepton l = failingLeptons[f]; |
554 |
> |
cout << "f: " << f << "\t" |
555 |
> |
<< "type: " << l.type << "\t" |
556 |
> |
<< "pT: " << l.vec.Pt() << "\t" |
557 |
> |
<< "eta: " << l.vec.Eta() |
558 |
> |
<< endl; |
559 |
> |
} |
560 |
> |
} |
561 |
> |
TLorentzVector pfmet; pfmet.SetPxPyPzE(metArr->At(0)->Mex(),metArr->At(0)->Mey(),0,0); |
562 |
> |
fillEventInfo( info, pfmet, evtinfo, ctrl.mc ? getNPU(puArr) : 0); |
563 |
> |
foTree.Fill(); |
564 |
> |
} else { |
565 |
> |
if(ctrl.debug) |
566 |
> |
cout << "failing with some other code : " << ret4l.status.selectionBits << endl; |
567 |
> |
} |
568 |
> |
if(ctrl.debug) |
569 |
> |
cout << "passes HLT: " << passes_HLT << endl; |
570 |
> |
} |
571 |
|
|
572 |
+ |
|
573 |
+ |
foTree.getFile()->cd(); |
574 |
+ |
foTree.getTree()->Write(); |
575 |
|
nt.WriteClose(); |
576 |
+ |
|
577 |
+ |
if(ctrl.debug) |
578 |
+ |
cout << endl << endl; |
579 |
+ |
for( int i=0; i<cutvec.size(); i++ ) { |
580 |
+ |
cout << "cut: " << i << "\t" |
581 |
+ |
<< "pass: " << cutvec[i]; |
582 |
+ |
|
583 |
+ |
if( i>PASS_TRIGGER&&i<=PASS_GOODZ1 ) |
584 |
+ |
cout << "\t2e: " << zcutvec[0][i] |
585 |
+ |
<< "\t2m: " << zcutvec[1][i]; |
586 |
+ |
|
587 |
+ |
if( i>PASS_ZCANDIDATE ) |
588 |
+ |
cout << "\t4e: " << zzcutvec[0][i] |
589 |
+ |
<< "\t4m: " << zzcutvec[1][i] |
590 |
+ |
<< "\t2e2m: " << zzcutvec[2][i]; |
591 |
+ |
|
592 |
+ |
cout << "\t" << cutstrs[i] << endl; |
593 |
+ |
|
594 |
+ |
cout << endl; |
595 |
+ |
} |
596 |
+ |
|
597 |
|
} |
598 |
|
|
599 |
+ |
|
600 |
|
//---------------------------------------------------------------------------- |
601 |
< |
// |
334 |
< |
// Get primary vertices |
335 |
< |
// Assumes primary vertices are ordered by sum-pT^2 (as should be in CMSSW) |
336 |
< |
// NOTE: if no PV is found from fitting tracks, the beamspot is used |
337 |
< |
// |
338 |
< |
//---------------------------------------------------------------------------- |
339 |
< |
bool setPV(ControlFlags ctrl, |
340 |
< |
const mithep::Array<mithep::Vertex> * vtxArr, |
341 |
< |
mithep::Vertex & vtx) |
601 |
> |
void initRunLumiRangeMap(ControlFlags &ctrl) |
602 |
|
//---------------------------------------------------------------------------- |
603 |
< |
{ |
604 |
< |
const Vertex *bestPV = 0; |
605 |
< |
float best_sumpt=-1; |
606 |
< |
|
607 |
< |
// good PV requirements |
608 |
< |
const UInt_t fMinNTracksFit = 0; |
609 |
< |
const Double_t fMinNdof = 4; |
610 |
< |
const Double_t fMaxAbsZ = 24; |
611 |
< |
const Double_t fMaxRho = 2; |
612 |
< |
|
613 |
< |
for(int i=0; i<vtxArr->GetEntries(); ++i) { |
614 |
< |
const Vertex *pv = (Vertex*)(vtxArr->At(i)); |
615 |
< |
if( ctrl.debug ) cout << "vertex :: " << i << "\tntrks: " << pv->NTracks() << endl; |
616 |
< |
|
617 |
< |
// Select best PV for corrected d0; if no PV passing cuts, the first PV in the collection will be used |
618 |
< |
// if(!pv->IsValid()) continue; |
619 |
< |
if(pv->NTracksFit() < fMinNTracksFit) continue; |
620 |
< |
if(pv->Ndof() < fMinNdof) continue; |
361 |
< |
if(fabs(pv->Z()) > fMaxAbsZ) continue; |
362 |
< |
if(pv->Position().Rho() > fMaxRho) continue; |
363 |
< |
|
364 |
< |
// take the first ... |
365 |
< |
bestPV = pv; |
366 |
< |
break; |
367 |
< |
|
368 |
< |
// this never reached ... |
369 |
< |
float tmp_sumpt=0; |
370 |
< |
for( int t=0; t<pv->NTracks(); t++ ) |
371 |
< |
tmp_sumpt += pv->Trk(t)->Pt(); |
372 |
< |
|
373 |
< |
if( tmp_sumpt > best_sumpt ) { |
374 |
< |
bestPV = pv; |
375 |
< |
best_sumpt = tmp_sumpt; |
376 |
< |
if( ctrl.debug) cout << "new PV set, pt : " << best_sumpt << endl; |
377 |
< |
} |
378 |
< |
} |
379 |
< |
|
380 |
< |
if(!bestPV) bestPV = vtxArr->At(0); |
381 |
< |
vtx.SetPosition(bestPV->X(),bestPV->Y(),bestPV->Z()); |
382 |
< |
vtx.SetErrors(bestPV->XErr(),bestPV->YErr(),bestPV->ZErr()); |
383 |
< |
return true; |
603 |
> |
{ |
604 |
> |
/* |
605 |
> |
rlrm.AddJSONFile(std::string("./data/Cert_136033-149442_7TeV_Apr21ReReco_Collisions10_JSON.txt")); |
606 |
> |
// rlrm.AddJSONFile(std::string("./data/Cert_160404-173244_7TeV_PromptReco_Collisions11_JSON_v2.txt")); |
607 |
> |
rlrm.AddJSONFile(std::string("./data/Cert_160404-178078_7TeV_PromptReco_Collisions11_JSON.txt")); |
608 |
> |
rlrm.AddJSONFile(std::string("./data/Cert_160404-163869_7TeV_May10ReReco_Collisions11_JSON_v3.txt")); |
609 |
> |
rlrm.AddJSONFile(std::string("./data/Cert_170249-172619_7TeV_ReReco5Aug_Collisions11_JSON.txt")); |
610 |
> |
// r11b |
611 |
> |
rlrm.AddJSONFile(std::string("./data/Cert_160404-180252_7TeV_PromptReco_Collisions11_JSON.txt")); |
612 |
> |
*/ |
613 |
> |
|
614 |
> |
// 2012 only for now ... |
615 |
> |
std::string jsonFile; |
616 |
> |
if(ctrl.jsonFile=="") |
617 |
> |
jsonFile = "./data/Cert_190456-194479_8TeV_PromptReco_Collisions12_JSON.txt"; |
618 |
> |
else |
619 |
> |
jsonFile = ctrl.jsonFile; |
620 |
> |
rlrm.AddJSONFile(jsonFile); |
621 |
|
}; |