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 "TriggerMask.h"
|
41 |
#include "TriggerTable.h"
|
42 |
#include "Names.h"
|
43 |
#include "BaseMod.h"
|
44 |
|
45 |
//
|
46 |
// our headers
|
47 |
//
|
48 |
#include "ParseArgs.h"
|
49 |
#include "MuonSelection.h"
|
50 |
#include "ElectronSelection.h"
|
51 |
#include "IsolationSelection.h"
|
52 |
|
53 |
//#include "Selection.h"
|
54 |
//#include "ReferenceSelection.h"
|
55 |
#include "ReferenceSelection2.h"
|
56 |
|
57 |
#include "TriggerUtils.h"
|
58 |
#include "PassHLT.h"
|
59 |
#include "Angles.h"
|
60 |
#include "KinematicsStruct.h"
|
61 |
#include "InfoStruct.h"
|
62 |
//#include "GenInfoStruct.h"
|
63 |
#include "WeightStruct.h"
|
64 |
//#include "GlobalDataAndFuncs.h"
|
65 |
#include "RunLumiRangeMap.h"
|
66 |
|
67 |
#include "AngleTuple.h"
|
68 |
#include "FOTuple.h"
|
69 |
|
70 |
#include "SampleWeight.h"
|
71 |
#include "EfficiencyWeightsInterface.h"
|
72 |
|
73 |
#include "SimpleLepton.h"
|
74 |
|
75 |
#ifndef CMSSW_BASE
|
76 |
#define CMSSW_BASE "../"
|
77 |
#endif
|
78 |
|
79 |
using namespace mithep;
|
80 |
|
81 |
//
|
82 |
// globals
|
83 |
//----------------------------------------------------------------------------
|
84 |
TH1D * hpu;
|
85 |
RunLumiRangeMap rlrm;
|
86 |
vector<SimpleLepton> failingLeptons ; // for fake estimation
|
87 |
vector<SimpleLepton> passingLeptons; // for fake estimation
|
88 |
vector<unsigned> cutvec;
|
89 |
vector<vector<unsigned> > zcutvec;
|
90 |
vector<vector<unsigned> > zzcutvec;
|
91 |
map<unsigned,float> evtrhoMap;
|
92 |
vector<string> cutstrs;
|
93 |
|
94 |
//
|
95 |
// prototypes
|
96 |
//----------------------------------------------------------------------------
|
97 |
bool setPV(ControlFlags,const mithep::Array<mithep::Vertex>*, mithep::Vertex& );
|
98 |
void initPUWeights();
|
99 |
double getPUWeight(unsigned npu);
|
100 |
void setEffiencyWeights(EventData&, WeightStruct& );
|
101 |
void initRunLumiRangeMap();
|
102 |
void initEvtRhoMap(map<unsigned,float> &);
|
103 |
//----------------------------------------------------------------------------
|
104 |
|
105 |
|
106 |
//
|
107 |
// MAIN
|
108 |
//----------------------------------------------------------------------------
|
109 |
int main(int argc, char** argv)
|
110 |
//----------------------------------------------------------------------------
|
111 |
{
|
112 |
cutstrs.push_back(string("skim0")); //0
|
113 |
cutstrs.push_back(string("skim1")); //1
|
114 |
// -------------------------------------------------
|
115 |
cutstrs.push_back(string("Z candidate")); //2
|
116 |
cutstrs.push_back(string("good Z1")); //3
|
117 |
// -------------------------------------------------
|
118 |
cutstrs.push_back(string("4l")); //4
|
119 |
cutstrs.push_back(string("ZZ candidate")); //5
|
120 |
cutstrs.push_back(string("good Z2")); //6
|
121 |
cutstrs.push_back(string("ZZ 20/10")); //7
|
122 |
cutstrs.push_back(string("resonance")); //8
|
123 |
cutstrs.push_back(string("m4l>70")); //9
|
124 |
cutstrs.push_back(string("m4l>100")); //10
|
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,unsigned> entrymap; // number of unskimmed entries in each file
|
135 |
for( int i=0; i<11; 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<11; 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<11; j++ ) zzcutvec[i].push_back(0);
|
143 |
}
|
144 |
|
145 |
|
146 |
//
|
147 |
// args
|
148 |
//--------------------------------------------------------------------------------------------------------------
|
149 |
ControlFlags ctrl;
|
150 |
parse_args( argc, argv, ctrl );
|
151 |
if( ctrl.inputfiles.empty() &&ctrl.inputfile.empty() )
|
152 |
{
|
153 |
cerr << "usage: applySelection.exe <flags> " << endl;
|
154 |
cerr << "\tmandoatory flags : " << endl;
|
155 |
cerr << "\t--inputfiles | file containing a list of ntuples to run over" << endl;
|
156 |
cerr << "\t--inputfile | a file to run over" << endl;
|
157 |
cerr << "\t--outputfile | file to store selected evet" << endl;
|
158 |
return 1;
|
159 |
}
|
160 |
ctrl.dump();
|
161 |
|
162 |
|
163 |
|
164 |
//
|
165 |
// File I/O
|
166 |
//--------------------------------------------------------------------------------------------------------------
|
167 |
TChain * chain = new TChain("Events");
|
168 |
TChain * hltchain = new TChain("HLT");
|
169 |
|
170 |
string fname;
|
171 |
if( !ctrl.inputfiles.empty() ) {
|
172 |
ifstream f(ctrl.inputfiles.c_str());
|
173 |
while (f >> fname) {
|
174 |
if( !(strncmp( fname.c_str(), "#", 1 ) ) ) continue; // skip commented lines
|
175 |
cout << "adding inputfile : " << fname.c_str() << endl;
|
176 |
entrymap[string(fname.c_str())] = unskimmedEntries(fname.c_str());
|
177 |
cout << "unskimmed entries: " << entrymap[string(fname.c_str())] << endl;
|
178 |
chain->AddFile(fname.c_str());
|
179 |
hltchain->AddFile(fname.c_str());
|
180 |
}
|
181 |
} else {
|
182 |
cout << "adding inputfile : " << ctrl.inputfile.c_str() << endl;
|
183 |
unsigned tmpent = unskimmedEntries(ctrl.inputfile.c_str());
|
184 |
cout << "tmpent: " << tmpent << endl;
|
185 |
entrymap[string(ctrl.inputfile.c_str())] = unskimmedEntries(ctrl.inputfile.c_str());
|
186 |
cout << "unskimmed entries: " << entrymap[string(ctrl.inputfile.c_str())] << endl;
|
187 |
chain->AddFile(ctrl.inputfile.c_str());
|
188 |
hltchain->AddFile(ctrl.inputfile.c_str());
|
189 |
}
|
190 |
|
191 |
const char * ofname;
|
192 |
if( strcmp( ctrl.outputfile.c_str(), "") ) {
|
193 |
ofname = ctrl.outputfile.c_str();
|
194 |
} else {
|
195 |
ofname = "tmp.root";
|
196 |
}
|
197 |
// table of cross section values
|
198 |
string xspath = (cmsswpath+string("/MitPhysics/data/xs.dat"));
|
199 |
cout << "xspath: " << xspath.c_str() << endl;
|
200 |
SimpleTable xstab(xspath.c_str());
|
201 |
|
202 |
|
203 |
//
|
204 |
// Setup
|
205 |
//--------------------------------------------------------------------------------------------------------------
|
206 |
Angles angles;
|
207 |
KinematicsStruct kinematics;
|
208 |
InfoStruct evtinfo;
|
209 |
WeightStruct weights;
|
210 |
// GenInfoStruct geninfo;
|
211 |
|
212 |
AngleTuple nt( (const char*)ofname, (const char*)"zznt");
|
213 |
nt.makeAngleBranch(angles);
|
214 |
nt.makeKinematicsBranch(kinematics);
|
215 |
nt.makeInfoBranch(evtinfo);
|
216 |
|
217 |
FOTuple foTree( nt.getFile(), (const char*)"FOtree");
|
218 |
foTree.makeFailedLeptonBranch(failingLeptons);
|
219 |
foTree.makeZLeptonBranch(passingLeptons);
|
220 |
|
221 |
TH1F * h_w_hpt;
|
222 |
if(ctrl.mc) {
|
223 |
nt.makeWeightBranch(weights);
|
224 |
// nt.makeGenInfoBranch(geninfo);
|
225 |
initEfficiencyWeights();
|
226 |
initPUWeights();
|
227 |
/*
|
228 |
// Higgs only, pt reweighting
|
229 |
if( ctrl.mH <= 140 ) {
|
230 |
char wptname[256];
|
231 |
sprintf( wptname, "/data/blue/pharris/Flat/ntupler/root/weight_ptH_%i.root", ctrl.mH );
|
232 |
TFile * f_hpt = new TFile(wptname);
|
233 |
f_hpt->Print();
|
234 |
sprintf(wptname, "weight_hqt_fehipro_fit_%i", ctrl.mH);
|
235 |
h_w_hpt = (TH1F*)(f_hpt->FindObjectAny(wptname));
|
236 |
h_w_hpt->Print();
|
237 |
}
|
238 |
*/
|
239 |
} else {
|
240 |
initRunLumiRangeMap();
|
241 |
}
|
242 |
|
243 |
// initMuonIDMVA();
|
244 |
initMuonIsoMVA();
|
245 |
initElectronIDMVA();
|
246 |
initElectronIsoMVA();
|
247 |
initTrigger();
|
248 |
|
249 |
// hack
|
250 |
initEvtRhoMap(evtrhoMap);
|
251 |
|
252 |
|
253 |
//
|
254 |
// Setup tree I/O
|
255 |
//--------------------------------------------------------------------------------------------------------------
|
256 |
TFile *inputFile=0;
|
257 |
TTree *eventTree=0;
|
258 |
string currentFile("");
|
259 |
|
260 |
mithep::EventHeader *info = new mithep::EventHeader();
|
261 |
// mithep::TGenInfo *ginfo = new mithep::TGenInfo();
|
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>();
|
265 |
mithep::Array<mithep::PFCandidate> *pfArr = new mithep::Array<mithep::PFCandidate>();
|
266 |
mithep::Array<mithep::PileupInfo> *puArr = new mithep::Array<mithep::PileupInfo>();
|
267 |
mithep::Array<mithep::PileupEnergyDensity> *puDArr = new mithep::Array<mithep::PileupEnergyDensity>();
|
268 |
mithep::Array<mithep::Track> *trkArr = new mithep::Array<mithep::Track>();
|
269 |
mithep::TriggerMask *trigMask = new mithep::TriggerMask();
|
270 |
mithep::TriggerTable *hltTable = new mithep::TriggerTable();
|
271 |
vector<string> *hltTableStrings = new vector<string>();
|
272 |
|
273 |
TString fElectronName(Names::gkElectronBrn);
|
274 |
TString fMuonName(Names::gkMuonBrn);
|
275 |
TString fInfoName(Names::gkEvtHeaderBrn);
|
276 |
TString fPrimVtxName(Names::gkPVBrn);
|
277 |
TString fPFCandidateName(Names::gkPFCandidatesBrn);
|
278 |
TString fPileupInfoName(Names::gkPileupInfoBrn);
|
279 |
TString fPileupEnergyDensityName(Names::gkPileupEnergyDensityBrn);
|
280 |
TString fTrackName(Names::gkTrackBrn);
|
281 |
TString fTriggerMaskName(Names::gkHltBitBrn);
|
282 |
TString fTriggerTableName(Names::gkHltTableBrn);
|
283 |
|
284 |
chain->SetBranchAddress(fInfoName, &info);
|
285 |
chain->SetBranchAddress(fElectronName, &electronArr);
|
286 |
chain->SetBranchAddress(fMuonName, &muonArr);
|
287 |
chain->SetBranchAddress(fPrimVtxName, &vtxArr);
|
288 |
chain->SetBranchAddress(fPFCandidateName, &pfArr);
|
289 |
if( ctrl.mc ) chain->SetBranchAddress(fPileupInfoName, &puArr);
|
290 |
chain->SetBranchAddress(fPileupEnergyDensityName, &puDArr);
|
291 |
chain->SetBranchAddress(fTrackName, &trkArr);
|
292 |
chain->SetBranchAddress(fTriggerMaskName, &trigMask);
|
293 |
cout << "hlttable: " << fTriggerTableName << endl;
|
294 |
hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings);
|
295 |
|
296 |
mithep::Vertex vtx; // best primary vertex in the event
|
297 |
|
298 |
// ginfo = NULL;
|
299 |
// if( ctrl.mc ) { chain->SetBranchAddress("Gen", &ginfo);}
|
300 |
|
301 |
int count=0, pass=0;
|
302 |
float passcorr=0., passcorr_errup=0., passcorr_errdown=0.;
|
303 |
float denom[3]={0.,0.,0.};
|
304 |
float numer[3]={0.,0.,0.};
|
305 |
float numercorr[3]={0.,0.,0.};
|
306 |
|
307 |
// only 1 HLT table / file ???
|
308 |
hltchain->GetEntry(0);
|
309 |
cerr << "here... " << endl;
|
310 |
|
311 |
int imax = chain->GetEntries();
|
312 |
cout << "nEntries: " << imax << endl;
|
313 |
|
314 |
|
315 |
//
|
316 |
// Loop !!!!!!!!!
|
317 |
//--------------------------------------------------------------------------------------------------------------
|
318 |
for(UInt_t ientry=0; ientry<imax; ientry++)
|
319 |
{
|
320 |
chain->GetEntry(ientry);
|
321 |
if(!(ientry%1000)) cerr << "entry: " << ientry << endl;
|
322 |
setPV( ctrl, vtxArr, vtx);
|
323 |
|
324 |
cout << "origrho: " << puDArr->At(0)->Rho()
|
325 |
<< "\torigrholoweta: " << puDArr->At(0)->RhoLowEta()
|
326 |
<< endl;
|
327 |
|
328 |
|
329 |
//
|
330 |
// data/MC
|
331 |
//
|
332 |
if(ctrl.mc) {
|
333 |
//
|
334 |
// xsec & PU weights
|
335 |
//
|
336 |
// weights.w = getWeight(xstab,entrymap,chain)/ctrl.totalMC;
|
337 |
int npu = -1;
|
338 |
for(int i=0;i<puArr->GetEntries();i++) {
|
339 |
if(puArr->At(i)->GetBunchCrossing() == 0)
|
340 |
npu = puArr->At(i)->GetPU_NumInteractions();
|
341 |
}
|
342 |
assert(npu>=0);
|
343 |
evtinfo.npu;
|
344 |
weights.npuw = getPUWeight(evtinfo.npu);
|
345 |
// cout << "weight: " << weights.w << endl;
|
346 |
//
|
347 |
// trigger
|
348 |
//
|
349 |
if( string(chain->GetFile()->GetEndpointUrl()->GetFile()) != currentFile ) {
|
350 |
currentFile = string(chain->GetFile()->GetEndpointUrl()->GetFile());
|
351 |
hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings);
|
352 |
hltchain->GetEntry(0);
|
353 |
hltTable->Clear();
|
354 |
fillTriggerBits(hltTable, hltTableStrings );
|
355 |
}
|
356 |
if( ctrl.debug ) cout << "file is : " << currentFile << endl;
|
357 |
fillTriggerBits( hltTable, trigMask, triggerBits );
|
358 |
if( !passHLT(triggerBits, info->RunNum(), info->EvtNum() ) ) {
|
359 |
if( ctrl.debug ) cout << "\tfails trigger ... " << endl;
|
360 |
continue;
|
361 |
}
|
362 |
} else {
|
363 |
//
|
364 |
// JSON
|
365 |
//
|
366 |
/*
|
367 |
RunLumiRangeMap::RunLumiPairType rl(info->RunNum(), info->LumiSec());
|
368 |
if( !(rlrm.HasRunLumi(rl)) ) {
|
369 |
if( ctrl.debug ) cout << "\tfails JSON" << endl;
|
370 |
continue;
|
371 |
}
|
372 |
*/
|
373 |
//
|
374 |
// trigger
|
375 |
//
|
376 |
if( string(chain->GetFile()->GetEndpointUrl()->GetFile()) != currentFile ) {
|
377 |
currentFile = string(chain->GetFile()->GetEndpointUrl()->GetFile());
|
378 |
hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings);
|
379 |
hltchain->GetEntry(0);
|
380 |
hltTable->Clear();
|
381 |
fillTriggerBits(hltTable, hltTableStrings );
|
382 |
}
|
383 |
if( ctrl.debug ) cout << "file is : " << currentFile << endl;
|
384 |
fillTriggerBits( hltTable, trigMask, triggerBits );
|
385 |
if( !passHLT(triggerBits, info->RunNum(), info->EvtNum() ) ) {
|
386 |
if( ctrl.debug ) cout << "\tfails trigger ... " << endl;
|
387 |
continue;
|
388 |
}
|
389 |
}
|
390 |
|
391 |
//
|
392 |
// lepton/kinematic selection ...
|
393 |
//
|
394 |
failingLeptons.clear();
|
395 |
passingLeptons.clear();
|
396 |
EventData ret4l =
|
397 |
apply_HZZ4L_reference2_selection(ctrl, info,
|
398 |
vtx,
|
399 |
pfArr,
|
400 |
// evtrhoMap[info->EvtNum()],
|
401 |
puDArr,
|
402 |
electronArr,
|
403 |
&electronReferencePreSelection,
|
404 |
&electronReferenceIDMVASelection,
|
405 |
&electronReferenceIsoSelection,
|
406 |
muonArr,
|
407 |
&muonReferencePreSelection,
|
408 |
&muonIDPFSelection,
|
409 |
&muonReferenceIsoSelection);
|
410 |
/*
|
411 |
apply_HZZ4L_reference_selection(ctrl, info,
|
412 |
vtx,
|
413 |
pfArr,
|
414 |
puArr,
|
415 |
electronArr,
|
416 |
&electronPreSelection,
|
417 |
&electronIDMVASelection,
|
418 |
&electronIsoMVASelection,
|
419 |
muonArr,
|
420 |
&muonPreSelection,
|
421 |
&muonIDPFSelection,
|
422 |
&muonIsoMVASelection);
|
423 |
*/
|
424 |
|
425 |
if( ctrl.debug ) cout << endl;
|
426 |
|
427 |
|
428 |
int Z1type=0, Z2type=0;
|
429 |
if( ret4l.status.selectionBits.to_ulong() >= PASS_ZCANDIDATE ) {
|
430 |
if( abs(ret4l.Z1leptons[0].type) == 11 ) Z1type = 11;
|
431 |
if( abs(ret4l.Z1leptons[0].type) == 13 ) Z1type = 13;
|
432 |
}
|
433 |
if( ret4l.status.selectionBits.to_ulong() >= PASS_ZZCANDIDATE ) {
|
434 |
if( abs(ret4l.Z2leptons[0].type) == 11 ) Z2type = 11;
|
435 |
if( abs(ret4l.Z2leptons[0].type) == 13 ) Z2type = 13;
|
436 |
}
|
437 |
|
438 |
cout << "bits: " << ret4l.status.selectionBits << "\t"
|
439 |
<< "Z1: " << Z1type << "\t"
|
440 |
<< "Z2: " << Z2type << endl;
|
441 |
cout << endl;
|
442 |
|
443 |
|
444 |
if( ret4l.status.pass() ) {
|
445 |
fillAngles(ret4l,angles);
|
446 |
fillKinematics(ret4l,kinematics);
|
447 |
fillEventInfo(info,evtinfo);
|
448 |
if( ctrl.mc) {
|
449 |
// fillGenInfo(ginfo,geninfo);
|
450 |
setEffiencyWeights(ret4l, weights);
|
451 |
if(ctrl.debug)
|
452 |
cout << "w: " << weights.w << "\t"
|
453 |
<< "won: " << weights.won << "\t"
|
454 |
<< "woff: " << weights.woff << endl;
|
455 |
}
|
456 |
|
457 |
/*
|
458 |
// only for Higgs < 140
|
459 |
geninfo.weight *= h_w_hpt->GetBinContent(h_w_hpt->FindBin(geninfo.pt_zz));
|
460 |
angles.bdt = reader->EvaluateMVA("BDTG");
|
461 |
*/
|
462 |
nt.Fill();
|
463 |
|
464 |
cerr << "PASS:: "
|
465 |
<< "\trun: " << evtinfo.run
|
466 |
<< "\tevt: " << evtinfo.evt
|
467 |
<< "\tlumi: " << evtinfo.lumi
|
468 |
<< "\tcostheta1: " << angles.costheta1
|
469 |
<< "\tcostheta2: " << angles.costheta2
|
470 |
<< "\tcostheta*: " << angles.costhetastar
|
471 |
<< "\tbdt: " << angles.bdt
|
472 |
<< endl;
|
473 |
pass++;
|
474 |
// if( pass > 3 ) break;
|
475 |
|
476 |
} else if( ret4l.status.selectionBits.test(PASS_ZCANDIDATE) ) { // save for fakes ...
|
477 |
if(ctrl.debug) {
|
478 |
cout << "failingLeptons : " << failingLeptons.size() << endl;
|
479 |
for( int f=0; f<failingLeptons.size(); f++ ) {
|
480 |
SimpleLepton l = failingLeptons[f];
|
481 |
cout << "f: " << f << "\t"
|
482 |
<< "type: " << l.type << "\t"
|
483 |
<< "pT: " << l.vec.Pt() << "\t"
|
484 |
<< "eta: " << l.vec.Eta()
|
485 |
<< endl;
|
486 |
}
|
487 |
}
|
488 |
foTree.Fill();
|
489 |
}
|
490 |
}
|
491 |
|
492 |
|
493 |
foTree.getFile()->cd();
|
494 |
foTree.getTree()->Write();
|
495 |
nt.WriteClose();
|
496 |
|
497 |
cout << endl;
|
498 |
cout << endl;
|
499 |
for( int i=0; i<cutvec.size(); i++ ) {
|
500 |
cout << "cut: " << i << "\t"
|
501 |
<< "pass: " << cutvec[i];
|
502 |
|
503 |
if( i>1&&i<=3 )
|
504 |
cout << "\t2e: " << zcutvec[0][i]
|
505 |
<< "\t2m: " << zcutvec[1][i];
|
506 |
|
507 |
if( i>3 )
|
508 |
cout << "\t4e: " << zzcutvec[0][i]
|
509 |
<< "\t4m: " << zzcutvec[1][i]
|
510 |
<< "\t2e2m: " << zzcutvec[2][i];
|
511 |
|
512 |
cout << "\t" << cutstrs[i] << endl;
|
513 |
|
514 |
cout << endl;
|
515 |
}
|
516 |
|
517 |
}
|
518 |
|
519 |
//----------------------------------------------------------------------------
|
520 |
//
|
521 |
// Get primary vertices
|
522 |
// Assumes primary vertices are ordered by sum-pT^2 (as should be in CMSSW)
|
523 |
// NOTE: if no PV is found from fitting tracks, the beamspot is used
|
524 |
//
|
525 |
//----------------------------------------------------------------------------
|
526 |
bool setPV(ControlFlags ctrl,
|
527 |
const mithep::Array<mithep::Vertex> * vtxArr,
|
528 |
mithep::Vertex & vtx)
|
529 |
//----------------------------------------------------------------------------
|
530 |
{
|
531 |
const Vertex *bestPV = 0;
|
532 |
float best_sumpt=-1;
|
533 |
|
534 |
// good PV requirements
|
535 |
const UInt_t fMinNTracksFit = 0;
|
536 |
const Double_t fMinNdof = 4;
|
537 |
const Double_t fMaxAbsZ = 24;
|
538 |
const Double_t fMaxRho = 2;
|
539 |
|
540 |
for(int i=0; i<vtxArr->GetEntries(); ++i) {
|
541 |
const Vertex *pv = (Vertex*)(vtxArr->At(i));
|
542 |
if( ctrl.debug ) cout << "vertex :: " << i << "\tntrks: " << pv->NTracks() << endl;
|
543 |
|
544 |
// Select best PV for corrected d0; if no PV passing cuts, the first PV in the collection will be used
|
545 |
// if(!pv->IsValid()) continue;
|
546 |
if(pv->NTracksFit() < fMinNTracksFit) continue;
|
547 |
if(pv->Ndof() < fMinNdof) continue;
|
548 |
if(fabs(pv->Z()) > fMaxAbsZ) continue;
|
549 |
if(pv->Position().Rho() > fMaxRho) continue;
|
550 |
|
551 |
// take the first ...
|
552 |
bestPV = pv;
|
553 |
break;
|
554 |
|
555 |
// this never reached ...
|
556 |
float tmp_sumpt=0;
|
557 |
for( int t=0; t<pv->NTracks(); t++ )
|
558 |
tmp_sumpt += pv->Trk(t)->Pt();
|
559 |
|
560 |
if( tmp_sumpt > best_sumpt ) {
|
561 |
bestPV = pv;
|
562 |
best_sumpt = tmp_sumpt;
|
563 |
if( ctrl.debug) cout << "new PV set, pt : " << best_sumpt << endl;
|
564 |
}
|
565 |
}
|
566 |
|
567 |
if(!bestPV) bestPV = vtxArr->At(0);
|
568 |
vtx.SetPosition(bestPV->X(),bestPV->Y(),bestPV->Z());
|
569 |
vtx.SetErrors(bestPV->XErr(),bestPV->YErr(),bestPV->ZErr());
|
570 |
return true;
|
571 |
};
|
572 |
|
573 |
|
574 |
|
575 |
//----------------------------------------------------------------------------
|
576 |
void setEffiencyWeights(EventData & evtdat, WeightStruct & weights )
|
577 |
//----------------------------------------------------------------------------
|
578 |
{
|
579 |
vector<SimpleLepton> lepvec = evtdat.Z1leptons;
|
580 |
lepvec.insert(lepvec.end(), evtdat.Z2leptons.begin(), evtdat.Z2leptons.end());
|
581 |
double w_offline=-1, werr_offline=0;
|
582 |
double w_online=-1, werr_online=0;
|
583 |
|
584 |
vector< pair <double,double> > wlegs; // pair here is eff & err
|
585 |
vector< pair <float,float> > mvec; // pair here is eta & pt
|
586 |
|
587 |
// vector< pair <float,float> > evec; // pair here is eta & pt
|
588 |
// now deal with medium vs loose
|
589 |
vector< pair< bool, pair <float,float> > > evec; // pair here is eta & pt
|
590 |
|
591 |
for( int k=0; k<lepvec.size(); k++ ) {
|
592 |
if( abs(lepvec[k].type) == 13 ) {
|
593 |
mvec.push_back( std::pair<float,float> (fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt()) );
|
594 |
wlegs.push_back( muonPerLegOfflineEfficiencyWeight( fabs(lepvec[k].vec.Eta()),
|
595 |
lepvec[k].vec.Pt() ) );
|
596 |
} else {
|
597 |
|
598 |
// now deal with medium vs loose
|
599 |
// evec.push_back( std::pair<float,float> (fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt()) );
|
600 |
|
601 |
std::pair<float,float> tmppair(fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt());
|
602 |
evec.push_back( std::pair<bool, std::pair<float,float> > (lepvec[k].isTight, tmppair) );
|
603 |
|
604 |
// wlegs.push_back( elePerLegOfflineEfficiencyWeight( fabs(lepvec[k].vec.Eta()),
|
605 |
// lepvec[k].vec.Pt() ) );
|
606 |
|
607 |
wlegs.push_back( elePerLegOfflineEfficiencyWeight( fabs(lepvec[k].vec.Eta()),
|
608 |
lepvec[k].vec.Pt(),
|
609 |
lepvec[k].isTight ) );
|
610 |
|
611 |
}
|
612 |
}
|
613 |
|
614 |
pair<double,double> offpair = getOfflineEfficiencyWeight( wlegs );
|
615 |
weights.woff = offpair.first;
|
616 |
weights.werroff = offpair.second;
|
617 |
|
618 |
pair<double,double> onpair = getOnlineEfficiencyWeight( mvec, evec );
|
619 |
weights.won = onpair.first;
|
620 |
weights.werron = onpair.second;
|
621 |
}
|
622 |
|
623 |
|
624 |
//----------------------------------------------------------------------------
|
625 |
void initRunLumiRangeMap()
|
626 |
//----------------------------------------------------------------------------
|
627 |
{
|
628 |
/*
|
629 |
rlrm.AddJSONFile(std::string("./data/Cert_136033-149442_7TeV_Apr21ReReco_Collisions10_JSON.txt"));
|
630 |
// rlrm.AddJSONFile(std::string("./data/Cert_160404-173244_7TeV_PromptReco_Collisions11_JSON_v2.txt"));
|
631 |
rlrm.AddJSONFile(std::string("./data/Cert_160404-178078_7TeV_PromptReco_Collisions11_JSON.txt"));
|
632 |
rlrm.AddJSONFile(std::string("./data/Cert_160404-163869_7TeV_May10ReReco_Collisions11_JSON_v3.txt"));
|
633 |
rlrm.AddJSONFile(std::string("./data/Cert_170249-172619_7TeV_ReReco5Aug_Collisions11_JSON.txt"));
|
634 |
// r11b
|
635 |
rlrm.AddJSONFile(std::string("./data/Cert_160404-180252_7TeV_PromptReco_Collisions11_JSON.txt"));
|
636 |
*/
|
637 |
};
|
638 |
|
639 |
|
640 |
//----------------------------------------------------------------------------
|
641 |
void initPUWeights()
|
642 |
//----------------------------------------------------------------------------
|
643 |
{
|
644 |
TFile * puf = new TFile("data/PileupReweighting.Summer11DYmm_To_Full2011.root");
|
645 |
hpu = (TH1D*)(puf->Get("puWeights"));
|
646 |
}
|
647 |
|
648 |
//----------------------------------------------------------------------------
|
649 |
double getPUWeight(unsigned npu)
|
650 |
//----------------------------------------------------------------------------
|
651 |
{
|
652 |
return hpu->GetBinContent(hpu->FindBin(npu));
|
653 |
}
|
654 |
|
655 |
//----------------------------------------------------------------------------
|
656 |
void initEvtRhoMap( map<unsigned, float> & evtrhoMap )
|
657 |
//----------------------------------------------------------------------------
|
658 |
{
|
659 |
unsigned evt;
|
660 |
float rho;
|
661 |
|
662 |
FILE * f = fopen("evtrho.dat", "r");
|
663 |
while( fscanf( f, "%u:%f", &evt, &rho ) ) {
|
664 |
evtrhoMap[evt] = rho;
|
665 |
}
|
666 |
|
667 |
}
|