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