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