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