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