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 "PFMet.h" |
37 |
> |
#include "PFCandidate.h" |
38 |
> |
#include "PFCandidateCol.h" |
39 |
> |
#include "PileupInfoCol.h" |
40 |
> |
#include "PileupEnergyDensity.h" |
41 |
> |
#include "MCParticle.h" |
42 |
> |
#include "TriggerMask.h" |
43 |
> |
#include "TriggerTable.h" |
44 |
> |
#include "TriggerObject.h" |
45 |
> |
#include "TriggerObjectRel.h" |
46 |
> |
#include "Names.h" |
47 |
> |
#include "BaseMod.h" |
48 |
> |
#include "TriggerObjectsTable.h" |
49 |
|
|
50 |
|
// |
51 |
< |
// utility headers |
51 |
> |
// our headers |
52 |
|
// |
53 |
|
#include "ParseArgs.h" |
54 |
+ |
#include "MuonSelection.h" |
55 |
+ |
#include "ElectronSelection.h" |
56 |
+ |
#include "IsolationSelection.h" |
57 |
+ |
#include "ReferenceSelection.h" |
58 |
+ |
|
59 |
+ |
#include "TriggerUtils.h" |
60 |
+ |
#include "PassHLT.h" |
61 |
+ |
#include "Angles.h" |
62 |
+ |
#include "KinematicsStruct.h" |
63 |
+ |
#include "InfoStruct.h" |
64 |
+ |
#include "GenInfoStruct.h" |
65 |
+ |
#include "WeightStruct.h" |
66 |
+ |
#include "AngleTuple.h" |
67 |
+ |
#include "FOTuple.h" |
68 |
+ |
|
69 |
+ |
#include "RunLumiRangeMap.h" |
70 |
|
#include "SampleWeight.h" |
71 |
< |
#include "Selection.h" |
72 |
< |
#include "HZZCiCElectronSelection.h" |
73 |
< |
#include "SampleWeight.h" |
71 |
> |
#include "EfficiencyWeightsInterface.h" |
72 |
> |
#include "SelectionFuncs.h" |
73 |
> |
|
74 |
> |
#include "SimpleLepton.h" |
75 |
> |
|
76 |
> |
#ifndef CMSSW_BASE |
77 |
> |
#define CMSSW_BASE "../" |
78 |
> |
#endif |
79 |
> |
|
80 |
> |
using namespace mithep; |
81 |
> |
|
82 |
> |
// |
83 |
> |
// globals |
84 |
> |
//---------------------------------------------------------------------------- |
85 |
> |
TH1D *hpu_2011, *hpu_2012; |
86 |
> |
RunLumiRangeMap rlrm; |
87 |
> |
vector<SimpleLepton> failingLeptons ; // for fake estimation |
88 |
> |
vector<SimpleLepton> passingLeptons; // for fake estimation |
89 |
> |
vector<unsigned> cutvec; |
90 |
> |
vector<vector<unsigned> > zcutvec; |
91 |
> |
vector<vector<unsigned> > zzcutvec; |
92 |
> |
map<unsigned,float> evtrhoMap; |
93 |
> |
vector<string> cutstrs; |
94 |
> |
bool passes_HLT_MC; |
95 |
> |
vector<bool> PFnoPUflag;; |
96 |
> |
|
97 |
> |
// |
98 |
> |
// prototypes |
99 |
> |
//---------------------------------------------------------------------------- |
100 |
> |
void initRunLumiRangeMap(ControlFlags &ctrl); |
101 |
> |
//---------------------------------------------------------------------------- |
102 |
|
|
51 |
– |
//#define THEIR_EVENTS |
103 |
|
|
104 |
< |
//=== MAIN ================================================================================================= |
104 |
> |
// |
105 |
> |
// MAIN |
106 |
> |
//---------------------------------------------------------------------------- |
107 |
|
int main(int argc, char** argv) |
108 |
+ |
//---------------------------------------------------------------------------- |
109 |
|
{ |
110 |
< |
|
110 |
> |
cutstrs.push_back(string("skim0")); //0 |
111 |
> |
cutstrs.push_back(string("skim1")); //1 |
112 |
> |
cutstrs.push_back(string("skim2")); //1 |
113 |
> |
cutstrs.push_back(string("trigger")); //2 |
114 |
> |
// ------------------------------------------------- |
115 |
> |
cutstrs.push_back(string("Z candidate")); //3 |
116 |
> |
cutstrs.push_back(string("good Z1")); //4 |
117 |
> |
// ------------------------------------------------- |
118 |
> |
cutstrs.push_back(string("4l")); //5 |
119 |
> |
cutstrs.push_back(string("ZZ candidate")); //6 |
120 |
> |
cutstrs.push_back(string("good Z2")); //7 |
121 |
> |
cutstrs.push_back(string("ZZ 20/10")); //8 |
122 |
> |
cutstrs.push_back(string("resonance")); //9 |
123 |
> |
cutstrs.push_back(string("m4l>70")); //10 |
124 |
> |
cutstrs.push_back(string("m4l>100, mZ2 > 12")); //11 |
125 |
> |
|
126 |
> |
|
127 |
> |
|
128 |
> |
|
129 |
> |
string cmsswpath(CMSSW_BASE); |
130 |
> |
cmsswpath.append("/src"); |
131 |
> |
std::bitset<1024> triggerBits; |
132 |
|
vector<vector<string> > inputFiles; |
133 |
|
inputFiles.push_back(vector<string>()); |
134 |
+ |
map<string,unsigned> entrymap; // number of unskimmed entries in each file |
135 |
+ |
for( int i=0; i<cutstrs.size(); i++ ) cutvec.push_back(0); |
136 |
+ |
for( int i=0; i<2; i++ ) { |
137 |
+ |
zcutvec.push_back(vector<unsigned>()); |
138 |
+ |
for( int j=0; j<cutstrs.size(); j++ ) zcutvec[i].push_back(0); |
139 |
+ |
} |
140 |
+ |
for( int i=0; i<3; i++ ) { |
141 |
+ |
zzcutvec.push_back(vector<unsigned>()); |
142 |
+ |
for( int j=0; j<cutstrs.size(); j++ ) zzcutvec[i].push_back(0); |
143 |
+ |
} |
144 |
+ |
|
145 |
|
|
146 |
|
// |
147 |
|
// args |
148 |
|
//-------------------------------------------------------------------------------------------------------------- |
149 |
|
ControlFlags ctrl; |
150 |
|
parse_args( argc, argv, ctrl ); |
151 |
< |
if( ctrl.inputfile.empty() || |
152 |
< |
ctrl.inputfile.empty() ) { |
153 |
< |
cerr << "usage: applySelection.exe <flags> " << endl; |
154 |
< |
cerr << "\tmandoatory flags : " << endl; |
155 |
< |
cerr << "\t--inputfile | file containing a list of ntuples to run over" << endl; |
156 |
< |
cerr << "\t--outputfile | file to store selected evet" << endl; |
157 |
< |
return 1; |
158 |
< |
} |
151 |
> |
if( ctrl.inputfiles.empty() &&ctrl.inputfile.empty() ) |
152 |
> |
{ |
153 |
> |
cerr << "usage: applySelection.exe <flags> " << endl; |
154 |
> |
cerr << "\tmandoatory flags : " << endl; |
155 |
> |
cerr << "\t--inputfiles | file containing a list of ntuples to run over" << endl; |
156 |
> |
cerr << "\t--inputfile | a file to run over" << endl; |
157 |
> |
cerr << "\t--outputfile | file to store selected evet" << endl; |
158 |
> |
return 1; |
159 |
> |
} |
160 |
|
ctrl.dump(); |
161 |
|
|
162 |
+ |
|
163 |
+ |
|
164 |
|
// |
165 |
|
// File I/O |
166 |
|
//-------------------------------------------------------------------------------------------------------------- |
167 |
|
TChain * chain = new TChain("Events"); |
168 |
< |
ifstream f(ctrl.inputfile.c_str()); |
168 |
> |
TChain * hltchain = new TChain("HLT"); |
169 |
> |
|
170 |
|
string fname; |
171 |
< |
while (f >> fname) { |
172 |
< |
if( !(strncmp( fname.c_str(), "#", 1 ) ) ) continue; // skip commented lines |
173 |
< |
cout << "adding inputfile : " << fname.c_str() << endl; |
174 |
< |
chain->AddFile(fname.c_str()); |
171 |
> |
unsigned total_unskimmed=0; |
172 |
> |
if( !ctrl.inputfiles.empty() ) { |
173 |
> |
ifstream f(ctrl.inputfiles.c_str()); |
174 |
> |
while (f >> fname) { |
175 |
> |
if( !(strncmp( fname.c_str(), "#", 1 ) ) ) continue; // skip commented lines |
176 |
> |
cout << "adding inputfile : " << fname.c_str() << endl; |
177 |
> |
entrymap[string(fname.c_str())] = unskimmedEntries(fname.c_str()); |
178 |
> |
cout << "unskimmed entries: " << entrymap[string(fname.c_str())] << endl; |
179 |
> |
total_unskimmed += entrymap[string(fname.c_str())]; |
180 |
> |
chain->AddFile(fname.c_str()); |
181 |
> |
hltchain->AddFile(fname.c_str()); |
182 |
> |
} |
183 |
> |
} else { |
184 |
> |
cout << "adding inputfile : " << ctrl.inputfile.c_str() << endl; |
185 |
> |
unsigned unsk_ents = unskimmedEntries(ctrl.inputfile.c_str()); |
186 |
> |
entrymap[string(ctrl.inputfile.c_str())] = unsk_ents; |
187 |
> |
cout << "unskimmed entries: " << unsk_ents << endl; |
188 |
> |
total_unskimmed += unsk_ents; |
189 |
> |
chain->AddFile(ctrl.inputfile.c_str()); |
190 |
> |
hltchain->AddFile(ctrl.inputfile.c_str()); |
191 |
|
} |
192 |
+ |
// // write the total number of unskimmed events that went into making this output file to a text file |
193 |
+ |
// writeEntries(ctrl,total_unskimmed); |
194 |
|
|
195 |
+ |
const char * ofname; |
196 |
+ |
if( strcmp( ctrl.outputfile.c_str(), "") ) { |
197 |
+ |
ofname = ctrl.outputfile.c_str(); |
198 |
+ |
} else { |
199 |
+ |
ofname = "tmp.root"; |
200 |
+ |
} |
201 |
|
// table of cross section values |
202 |
< |
SimpleTable xstab("./data/xs.dat"); |
202 |
> |
string xspath = (cmsswpath+string("/MitPhysics/data/xs.dat")); |
203 |
> |
cout << "xspath: " << xspath.c_str() << endl; |
204 |
> |
SimpleTable xstab(xspath.c_str()); |
205 |
> |
|
206 |
> |
|
207 |
|
|
208 |
|
// |
209 |
|
// Setup |
210 |
|
//-------------------------------------------------------------------------------------------------------------- |
211 |
< |
TH1F * h_evt = new TH1F("hevt", "hevt", 2, 0, 2 ); |
212 |
< |
TH1F * h_evtfail = new TH1F("hevtfail", "hevtfail", 100, 0, 100 ); |
213 |
< |
TNtuple * passtuple = new TNtuple( "passtuple", "passtuple", "run:evt:lumi:channel:mZ1:mZ2:m4l:pt4l:w" ); |
214 |
< |
initCiCSelection(); |
215 |
< |
initRunLumiRangeMap(); |
211 |
> |
Angles angles; |
212 |
> |
KinematicsStruct kinematics; |
213 |
> |
InfoStruct evtinfo; |
214 |
> |
WeightStruct weights; |
215 |
> |
GenInfoStruct geninfo; |
216 |
> |
|
217 |
> |
AngleTuple nt( (const char*)ofname, (const char*)"zznt"); |
218 |
> |
nt.makeAngleBranch(angles); |
219 |
> |
nt.makeKinematicsBranch(kinematics); |
220 |
> |
nt.makeInfoBranch(evtinfo); |
221 |
|
|
222 |
+ |
|
223 |
+ |
FOTuple foTree( nt.getFile(), (const char*)"FOtree"); |
224 |
+ |
foTree.makeInfoBranch(evtinfo); |
225 |
+ |
foTree.makeFailedLeptonBranch(failingLeptons); |
226 |
+ |
foTree.makePassedLeptonBranch(passingLeptons); |
227 |
+ |
|
228 |
+ |
TH1F * h_wf11_hpt; |
229 |
+ |
if(ctrl.mc) { |
230 |
+ |
nt.makeWeightBranch(weights); |
231 |
+ |
if(ctrl.fillGen ) nt.makeGenInfoBranch(geninfo); |
232 |
+ |
initEfficiencyWeights(); |
233 |
+ |
initPUWeights(); |
234 |
+ |
|
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_wf11_hpt = (TH1F*)(f_hpt->FindObjectAny(wptname)); |
243 |
+ |
} |
244 |
+ |
|
245 |
+ |
} else { |
246 |
+ |
initRunLumiRangeMap(ctrl); |
247 |
+ |
} |
248 |
+ |
|
249 |
+ |
// initMuonIDMVA(); |
250 |
+ |
initElectronIDMVAV1(); |
251 |
+ |
initTrigger(); |
252 |
|
|
253 |
|
// |
254 |
< |
// Loop |
254 |
> |
// Setup tree I/O |
255 |
|
//-------------------------------------------------------------------------------------------------------------- |
103 |
– |
|
104 |
– |
// |
105 |
– |
// Access samples and fill histograms |
256 |
|
TFile *inputFile=0; |
257 |
|
TTree *eventTree=0; |
258 |
< |
|
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); |
127 |
< |
|
258 |
> |
string currentFile(""); |
259 |
|
|
260 |
+ |
UInt_t fNMaxTriggers = 1024; |
261 |
+ |
mithep::EventHeader *info = new mithep::EventHeader(); |
262 |
+ |
mithep::Array<mithep::PFMet> *metArr = new mithep::Array<mithep::PFMet>(); |
263 |
+ |
mithep::Array<mithep::Electron> *electronArr = new mithep::Array<mithep::Electron>(); |
264 |
+ |
mithep::Array<mithep::Muon> *muonArr = new mithep::Array<mithep::Muon>(); |
265 |
+ |
mithep::Array<mithep::Vertex> *vtxArr = new mithep::Array<mithep::Vertex>(); |
266 |
+ |
mithep::Array<mithep::PFCandidate> *pfArr = new mithep::Array<mithep::PFCandidate>(); |
267 |
+ |
mithep::Array<mithep::PileupInfo> *puArr = new mithep::Array<mithep::PileupInfo>(); |
268 |
+ |
mithep::Array<mithep::PileupEnergyDensity> *puDArr = new mithep::Array<mithep::PileupEnergyDensity>(); |
269 |
+ |
mithep::Array<mithep::Track> *trkArr = new mithep::Array<mithep::Track>(); |
270 |
+ |
mithep::Array<mithep::MCParticle> *mcArr = new mithep::Array<mithep::MCParticle>(); |
271 |
+ |
mithep::MCEventInfo *mcEvtInfo = new mithep::MCEventInfo(); |
272 |
+ |
mithep::TriggerMask *trigMask = new mithep::TriggerMask(); |
273 |
+ |
mithep::TriggerTable *hltTable = new mithep::TriggerTable(fNMaxTriggers); |
274 |
+ |
vector<string> *hltTableStrings = new vector<string>(); |
275 |
+ |
vector<string> *hltLabelStrings = new vector<string>(); |
276 |
+ |
mithep::Array<mithep::TriggerObject> *hltObjArr = new mithep::Array<mithep::TriggerObject>(); |
277 |
+ |
mithep::Array<mithep::TriggerObjectRel> *hltRelsArr = new mithep::Array<mithep::TriggerObjectRel>(); |
278 |
+ |
std::vector<std::string> *hltTab = new vector<string>(); |
279 |
+ |
std::vector<std::string> *hltLab = new vector<string>(); |
280 |
+ |
TriggerObjectsTable *fTrigObjs = new TriggerObjectsTable(hltTable,fNMaxTriggers); |
281 |
+ |
|
282 |
+ |
|
283 |
+ |
TString fElectronName(Names::gkElectronBrn); |
284 |
+ |
TString fMuonName(Names::gkMuonBrn); |
285 |
+ |
TString fInfoName(Names::gkEvtHeaderBrn); |
286 |
+ |
TString fPFMetName("PFMet"); |
287 |
+ |
TString fPrimVtxName(Names::gkPVBrn); |
288 |
+ |
TString fPFCandidateName(Names::gkPFCandidatesBrn); |
289 |
+ |
TString fPileupInfoName(Names::gkPileupInfoBrn); |
290 |
+ |
TString fPileupEnergyDensityName(Names::gkPileupEnergyDensityBrn); |
291 |
+ |
TString fTrackName(Names::gkTrackBrn); |
292 |
+ |
TString fMCParticleName(Names::gkMCPartBrn); |
293 |
+ |
TString fMCEvtInfoName(Names::gkMCEvtInfoBrn); |
294 |
+ |
TString fTriggerMaskName(Names::gkHltBitBrn); |
295 |
+ |
TString fTriggerTableName(Names::gkHltTableBrn); |
296 |
+ |
TString fTriggerLabelName(Names::gkHltLabelBrn); |
297 |
+ |
TString fTriggerObjectName(Names::gkHltObjBrn); |
298 |
+ |
TString fTriggerObjectRelsName(Form("HLTObjectsRelation")); |
299 |
+ |
|
300 |
+ |
// TString fHLTLabName(Names::gkHltLabelBrn); |
301 |
+ |
// TString fHLTTabName(Names::gkHltTableBrn); |
302 |
+ |
// TString fHLTTabNamePub(Form("%sFwk",fHLTTabName.Data())); |
303 |
+ |
// TString fHLTLabNamePub(Form("%sFwk",fHLTLabName.Data())); |
304 |
+ |
// TString fObjsNamePub(Form("%sFwk",fTriggerObjectName.Data())); |
305 |
|
|
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 |
306 |
|
|
307 |
< |
unsigned evtfail = fails_HZZ4L_selection(ctrl, info, electronArr, muonArr, eventweight, passtuple ); |
308 |
< |
h_evtfail->Fill( evtfail, eventweight ); |
309 |
< |
cout << endl << endl; |
310 |
< |
|
311 |
< |
} //end loop over data |
307 |
> |
|
308 |
> |
chain->SetBranchAddress(fInfoName, &info); |
309 |
> |
chain->SetBranchAddress(fPFMetName, &metArr); |
310 |
> |
chain->SetBranchAddress(fElectronName, &electronArr); |
311 |
> |
chain->SetBranchAddress(fMuonName, &muonArr); |
312 |
> |
chain->SetBranchAddress(fPrimVtxName, &vtxArr); |
313 |
> |
chain->SetBranchAddress(fPFCandidateName, &pfArr); |
314 |
> |
if( ctrl.mc ) { |
315 |
> |
chain->SetBranchAddress(fPileupInfoName, &puArr); |
316 |
> |
chain->SetBranchAddress(fMCParticleName, &mcArr); |
317 |
> |
chain->SetBranchAddress(fMCEvtInfoName, &mcEvtInfo); |
318 |
> |
} |
319 |
> |
chain->SetBranchAddress(fPileupEnergyDensityName, &puDArr); |
320 |
> |
chain->SetBranchAddress(fTrackName, &trkArr); |
321 |
> |
chain->SetBranchAddress(fTriggerMaskName, &trigMask); |
322 |
> |
chain->SetBranchAddress(fTriggerObjectName, &hltObjArr); |
323 |
> |
chain->SetBranchAddress(fTriggerObjectRelsName, &hltRelsArr); |
324 |
> |
// chain->SetBranchAddress(fHLTTabNamePub, &hltTab); |
325 |
> |
// chain->SetBranchAddress(fHLTLabNamePub, &hltLab); |
326 |
> |
|
327 |
> |
cout << "hlttable: " << fTriggerTableName << endl; |
328 |
> |
hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings); |
329 |
> |
hltchain->SetBranchAddress(fTriggerLabelName, &hltLabelStrings); |
330 |
> |
|
331 |
> |
mithep::Vertex vtx; // best primary vertex in the event |
332 |
> |
|
333 |
> |
// ginfo = NULL; |
334 |
> |
// if( ctrl.mc ) { chain->SetBranchAddress("Gen", &ginfo);} |
335 |
> |
|
336 |
> |
int count=0, pass=0; |
337 |
> |
float passcorr=0., passcorr_errup=0., passcorr_errdown=0.; |
338 |
> |
float denom[3]={0.,0.,0.}; |
339 |
> |
float numer[3]={0.,0.,0.}; |
340 |
> |
float numercorr[3]={0.,0.,0.}; |
341 |
|
|
342 |
+ |
// only 1 HLT table / file ??? |
343 |
+ |
hltchain->GetEntry(0); |
344 |
|
|
345 |
+ |
int imax = chain->GetEntries(); |
346 |
+ |
cout << "nEntries: " << imax << endl; |
347 |
|
|
348 |
< |
delete info; |
349 |
< |
delete electronArr; |
350 |
< |
delete muonArr; |
348 |
> |
// |
349 |
> |
// Loop !!!!!!!!! |
350 |
> |
//-------------------------------------------------------------------------------------------------------------- |
351 |
> |
for(UInt_t ientry=0; ientry<imax; ientry++) |
352 |
> |
{ |
353 |
> |
chain->GetEntry(ientry); |
354 |
> |
if(!(ientry%1000)) cerr << "entry: " << ientry << endl; |
355 |
> |
|
356 |
> |
if( ctrl.debug ) { |
357 |
> |
cout << "-----------------------------------------------------------------" << endl; |
358 |
> |
cout << "-----------------------------------------------------------------" << endl; |
359 |
> |
cout << "Run: " << info->RunNum() |
360 |
> |
<< "\tEvt: " << info->EvtNum() |
361 |
> |
<< "\tLumi: " << info->LumiSec() |
362 |
> |
<< endl; |
363 |
> |
cout << "-----------------------------------------------------------------" << endl; |
364 |
> |
} |
365 |
> |
|
366 |
> |
|
367 |
> |
string fname = string(chain->GetFile()->GetEndpointUrl()->GetFile()); |
368 |
> |
if(ctrl.debug) cout << "era is " << ctrl.era << endl; |
369 |
> |
if( ctrl.era == 0 ) { |
370 |
> |
setEra( fname, ctrl ); |
371 |
> |
if(ctrl.debug) cout << "era is now " << ctrl.era << endl; |
372 |
> |
} |
373 |
> |
|
374 |
> |
// |
375 |
> |
// pfNoPU |
376 |
> |
// |
377 |
> |
//mithep::Array<PFCandidate> pfNoPileUp; |
378 |
> |
PFnoPUflag.clear(); |
379 |
> |
int pfnopu_size = makePFnoPUArray( pfArr, PFnoPUflag, vtxArr ); |
380 |
> |
assert(pfnopu_size == pfArr->GetEntries()); |
381 |
> |
|
382 |
> |
// |
383 |
> |
// data/MC |
384 |
> |
// |
385 |
> |
if(ctrl.mc) { |
386 |
> |
// |
387 |
> |
// gen info |
388 |
> |
// |
389 |
> |
if( ctrl.fillGen ) |
390 |
> |
fillGenInfo( mcArr, mcEvtInfo, geninfo, ESampleType::kHZZ, ctrl); |
391 |
> |
|
392 |
> |
// |
393 |
> |
// xsec & PU weights |
394 |
> |
// |
395 |
> |
weights.w = getWeight(xstab,entrymap,chain)/ctrl.totalMC; |
396 |
> |
cout << "xsec weight: " << weights.w << endl; |
397 |
> |
|
398 |
> |
unsigned npu = getNPU(puArr, 0); |
399 |
> |
weights.npu = npu; |
400 |
> |
weights.npuw = getPUWeight(ctrl.era,npu); |
401 |
> |
cerr << "weights.npuw: " << weights.npuw << endl; |
402 |
> |
|
403 |
> |
// |
404 |
> |
// pt reweighting for Higgs < 140, F11 |
405 |
> |
// |
406 |
> |
if( ctrl.fillGen ) { |
407 |
> |
if( (fname.find("f11-h115zz4l") != string::npos) || |
408 |
> |
(fname.find("f11-h120zz4l") != string::npos) || |
409 |
> |
(fname.find("f11-h130zz4l") != string::npos) ) { |
410 |
> |
weights.w *= h_wf11_hpt->GetBinContent(h_wf11_hpt->FindBin(geninfo.pt_zz)); |
411 |
> |
} |
412 |
> |
} |
413 |
> |
|
414 |
> |
// |
415 |
> |
// trigger |
416 |
> |
// |
417 |
> |
if( string(chain->GetFile()->GetEndpointUrl()->GetFile()) != currentFile ) { |
418 |
> |
currentFile = string(chain->GetFile()->GetEndpointUrl()->GetFile()); |
419 |
> |
hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings); |
420 |
> |
hltchain->SetBranchAddress(fTriggerLabelName, &hltLabelStrings); |
421 |
> |
hltchain->GetEntry(0); |
422 |
> |
hltTable->Clear(); |
423 |
> |
fillTriggerNames(hltTable, hltTableStrings ); |
424 |
> |
hltTable->Print(); |
425 |
> |
} |
426 |
> |
if( ctrl.debug ) cout << "file is : " << currentFile << endl; |
427 |
> |
fillTriggerBits( hltTable, trigMask, triggerBits ); |
428 |
> |
passes_HLT_MC = true; // passed to apply as extern global, just for sync |
429 |
> |
if( !passHLTMC(triggerBits, info->RunNum(), info->EvtNum(), k2012_MC ) ) { |
430 |
> |
passes_HLT_MC = false; |
431 |
> |
} |
432 |
> |
|
433 |
> |
setHLTObjectRelations( hltObjArr, hltRelsArr, hltTableStrings, hltLabelStrings, fTrigObjs ); |
434 |
> |
|
435 |
> |
} else { |
436 |
> |
// |
437 |
> |
// JSON |
438 |
> |
// |
439 |
> |
if(!(ctrl.noJSON) ) { |
440 |
> |
RunLumiRangeMap::RunLumiPairType rl(info->RunNum(), info->LumiSec()); |
441 |
> |
if( !(rlrm.HasRunLumi(rl)) ) { |
442 |
> |
if( ctrl.debug ) cout << "fails JSON" << endl; |
443 |
> |
continue; |
444 |
> |
} |
445 |
> |
} |
446 |
> |
|
447 |
> |
// |
448 |
> |
// trigger |
449 |
> |
// |
450 |
> |
if( string(chain->GetFile()->GetEndpointUrl()->GetFile()) != currentFile ) { |
451 |
> |
currentFile = string(chain->GetFile()->GetEndpointUrl()->GetFile()); |
452 |
> |
hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings); |
453 |
> |
hltchain->SetBranchAddress(fTriggerLabelName, &hltLabelStrings); |
454 |
> |
hltchain->GetEntry(0); |
455 |
> |
hltTable->Clear(); |
456 |
> |
fillTriggerNames(hltTable, hltTableStrings ); |
457 |
> |
} |
458 |
> |
|
459 |
> |
setHLTObjectRelations( hltObjArr, hltRelsArr, hltTableStrings, hltLabelStrings, fTrigObjs ); |
460 |
> |
|
461 |
> |
if( ctrl.debug ) cout << "file is : " << currentFile << endl; |
462 |
> |
/* |
463 |
> |
fillTriggerBits( hltTable, trigMask, triggerBits ); |
464 |
> |
if( !passHLT(triggerBits, info->RunNum(), info->EvtNum() ) ) { |
465 |
> |
if( ctrl.debug ) cout << "\tfails trigger ... " << endl; |
466 |
> |
continue; |
467 |
> |
} |
468 |
> |
*/ |
469 |
> |
} |
470 |
> |
|
471 |
> |
// |
472 |
> |
// lepton/kinematic selection ... |
473 |
> |
// |
474 |
> |
failingLeptons.clear(); |
475 |
> |
passingLeptons.clear(); |
476 |
> |
EventData ret4l = |
477 |
> |
|
478 |
> |
|
479 |
> |
// reference |
480 |
> |
apply_HZZ4L_reference_selection(ctrl, info, |
481 |
> |
vtxArr, |
482 |
> |
pfArr, |
483 |
> |
puDArr, |
484 |
> |
electronArr, |
485 |
> |
&electronReferencePreSelection, |
486 |
> |
&electronReferenceIDMVASelectionV1, |
487 |
> |
&electronReferenceIsoSelection, |
488 |
> |
muonArr, |
489 |
> |
&muonReferencePreSelection, |
490 |
> |
&muonIDPFSelection, |
491 |
> |
&muonReferenceIsoSelection); |
492 |
> |
|
493 |
> |
if( ctrl.debug ) cout << endl; |
494 |
> |
|
495 |
> |
|
496 |
> |
int Z1type=0, Z2type=0; |
497 |
> |
if( ret4l.status.selectionBits.to_ulong() >= PASS_ZCANDIDATE ) { |
498 |
> |
if( abs(ret4l.Z1leptons[0].type) == 11 ) Z1type = 11; |
499 |
> |
if( abs(ret4l.Z1leptons[0].type) == 13 ) Z1type = 13; |
500 |
> |
} |
501 |
> |
if( ret4l.status.selectionBits.to_ulong() >= PASS_ZZCANDIDATE ) { |
502 |
> |
if( abs(ret4l.Z2leptons[0].type) == 11 ) Z2type = 11; |
503 |
> |
if( abs(ret4l.Z2leptons[0].type) == 13 ) Z2type = 13; |
504 |
> |
} |
505 |
> |
|
506 |
> |
if( ret4l.status.pass() ) { |
507 |
> |
fillAngles(ret4l,angles); |
508 |
> |
fillKinematics(ret4l,kinematics); |
509 |
> |
fillMassErrors(ret4l,muonArr,electronArr,kinematics); |
510 |
> |
TLorentzVector pfmet; pfmet.SetPxPyPzE(metArr->At(0)->Mex(),metArr->At(0)->Mey(),0,0); |
511 |
> |
fillEventInfo( info, pfmet, evtinfo, ctrl.mc ? getNPU(puArr) : 0); |
512 |
> |
if( ctrl.mc) { |
513 |
> |
setEffiencyWeights(ctrl.era, ret4l, triggerBits, hltTable, hltObjArr, fTrigObjs, weights); |
514 |
> |
if(ctrl.debug) |
515 |
> |
cout << "w: " << weights.w << "\t" |
516 |
> |
<< "npuw: " << weights.npuw << "\t" |
517 |
> |
<< "won: " << weights.won << "\t" |
518 |
> |
<< "woff: " << weights.woff << endl; |
519 |
> |
} |
520 |
> |
|
521 |
> |
|
522 |
> |
nt.Fill(); |
523 |
> |
|
524 |
> |
cerr << "PASS:: " |
525 |
> |
<< "\trun: " << evtinfo.run |
526 |
> |
<< "\tevt: " << evtinfo.evt |
527 |
> |
<< "\tlumi: " << evtinfo.lumi |
528 |
> |
<< "\tchannel: " << kinematics.channel |
529 |
> |
<< "\tm4l: " << kinematics.m4l |
530 |
> |
<< "\tmZ1: " << kinematics.mZ1 |
531 |
> |
<< "\tmZ2: " << kinematics.mZ2 |
532 |
> |
<< endl; |
533 |
> |
pass++; |
534 |
> |
// if( pass > 3 ) break; |
535 |
> |
|
536 |
> |
} else if( ret4l.status.selectionBits.test(PASS_GOODZ1) && |
537 |
> |
ret4l.status.selectionBits.to_ulong() < (1UL<<PASS_4L)) { // save for fakes ... |
538 |
> |
if(ctrl.debug) { |
539 |
> |
cout << "failingLeptons : " << failingLeptons.size() << endl; |
540 |
> |
for( int f=0; f<failingLeptons.size(); f++ ) { |
541 |
> |
SimpleLepton l = failingLeptons[f]; |
542 |
> |
cout << "f: " << f << "\t" |
543 |
> |
<< "type: " << l.type << "\t" |
544 |
> |
<< "pT: " << l.vec.Pt() << "\t" |
545 |
> |
<< "eta: " << l.vec.Eta() |
546 |
> |
<< endl; |
547 |
> |
} |
548 |
> |
} |
549 |
> |
TLorentzVector pfmet; pfmet.SetPxPyPzE(metArr->At(0)->Mex(),metArr->At(0)->Mey(),0,0); |
550 |
> |
fillEventInfo( info, pfmet, evtinfo, ctrl.mc ? getNPU(puArr) : 0); |
551 |
> |
foTree.Fill(); |
552 |
> |
} else { |
553 |
> |
if(ctrl.debug) |
554 |
> |
cout << "failing with some other code : " << ret4l.status.selectionBits << endl; |
555 |
> |
} |
556 |
> |
} |
557 |
|
|
558 |
+ |
|
559 |
+ |
foTree.getFile()->cd(); |
560 |
+ |
foTree.getTree()->Write(); |
561 |
+ |
nt.WriteClose(); |
562 |
+ |
|
563 |
+ |
if(ctrl.debug) |
564 |
+ |
cout << endl << endl; |
565 |
+ |
for( int i=0; i<cutvec.size(); i++ ) { |
566 |
+ |
cout << "cut: " << i << "\t" |
567 |
+ |
<< "pass: " << cutvec[i]; |
568 |
+ |
|
569 |
+ |
if( i>PASS_TRIGGER&&i<=PASS_GOODZ1 ) |
570 |
+ |
cout << "\t2e: " << zcutvec[0][i] |
571 |
+ |
<< "\t2m: " << zcutvec[1][i]; |
572 |
+ |
|
573 |
+ |
if( i>PASS_ZCANDIDATE ) |
574 |
+ |
cout << "\t4e: " << zzcutvec[0][i] |
575 |
+ |
<< "\t4m: " << zzcutvec[1][i] |
576 |
+ |
<< "\t2e2m: " << zzcutvec[2][i]; |
577 |
|
|
578 |
+ |
cout << "\t" << cutstrs[i] << endl; |
579 |
|
|
580 |
< |
//-------------------------------------------------------------------------------------------------------------- |
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"; |
580 |
> |
cout << endl; |
581 |
|
} |
582 |
|
|
188 |
– |
TFile *file = new TFile(ofname, "RECREATE"); |
189 |
– |
h_evt->Write(); |
190 |
– |
h_evtfail->Write(); |
191 |
– |
passtuple->Write(); |
192 |
– |
file->Close(); |
193 |
– |
delete file; |
194 |
– |
|
195 |
– |
cerr << "done!" << endl; |
583 |
|
} |
584 |
|
|
585 |
|
|
586 |
< |
|
586 |
> |
//---------------------------------------------------------------------------- |
587 |
> |
void initRunLumiRangeMap(ControlFlags &ctrl) |
588 |
> |
//---------------------------------------------------------------------------- |
589 |
> |
{ |
590 |
> |
/* |
591 |
> |
rlrm.AddJSONFile(std::string("./data/Cert_136033-149442_7TeV_Apr21ReReco_Collisions10_JSON.txt")); |
592 |
> |
// rlrm.AddJSONFile(std::string("./data/Cert_160404-173244_7TeV_PromptReco_Collisions11_JSON_v2.txt")); |
593 |
> |
rlrm.AddJSONFile(std::string("./data/Cert_160404-178078_7TeV_PromptReco_Collisions11_JSON.txt")); |
594 |
> |
rlrm.AddJSONFile(std::string("./data/Cert_160404-163869_7TeV_May10ReReco_Collisions11_JSON_v3.txt")); |
595 |
> |
rlrm.AddJSONFile(std::string("./data/Cert_170249-172619_7TeV_ReReco5Aug_Collisions11_JSON.txt")); |
596 |
> |
// r11b |
597 |
> |
rlrm.AddJSONFile(std::string("./data/Cert_160404-180252_7TeV_PromptReco_Collisions11_JSON.txt")); |
598 |
> |
*/ |
599 |
> |
|
600 |
> |
// 2012 only for now ... |
601 |
> |
std::string jsonFile; |
602 |
> |
if(ctrl.jsonFile=="") |
603 |
> |
jsonFile = "./data/Cert_190456-194479_8TeV_PromptReco_Collisions12_JSON.txt"; |
604 |
> |
else |
605 |
> |
jsonFile = ctrl.jsonFile; |
606 |
> |
rlrm.AddJSONFile(jsonFile); |
607 |
> |
}; |