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 |
|
using namespace std; |
9 |
|
|
10 |
|
// |
11 |
< |
// ROOT headers |
11 |
> |
// root headers |
12 |
|
// |
13 |
< |
#include <TROOT.h> // access to gROOT, entry point to ROOT system |
14 |
< |
#include <TSystem.h> // interface to OS |
15 |
< |
#include <TFile.h> // file handle class |
16 |
< |
#include <TNtuple.h> |
17 |
< |
#include <TTree.h> // class to access ntuples |
18 |
< |
#include <TChain.h> // |
19 |
< |
#include <TBranch.h> // class to access branches in TTree |
20 |
< |
#include <TClonesArray.h> // ROOT array class |
21 |
< |
#include <TCanvas.h> // class for drawing |
22 |
< |
#include <TH1F.h> // 1D histograms |
23 |
< |
#include <TBenchmark.h> // class to track macro running statistics |
24 |
< |
#include <TLorentzVector.h> // 4-vector class |
25 |
< |
#include <TVector3.h> // 3D vector class |
13 |
> |
#include <TFile.h> |
14 |
> |
#include <TTree.h> |
15 |
> |
#include <TChain.h> |
16 |
> |
#include <TBranch.h> |
17 |
> |
#include <TClonesArray.h> |
18 |
> |
|
19 |
> |
|
20 |
> |
// |
21 |
> |
// TMVA |
22 |
> |
// |
23 |
> |
#include "TMVA/Reader.h" |
24 |
> |
#include "TMVA/Tools.h" |
25 |
> |
#include "TMVA/Config.h" |
26 |
> |
#include "TMVA/MethodBDT.h" |
27 |
|
|
28 |
|
// |
29 |
|
// ntuple format headers |
30 |
|
// |
31 |
< |
#include "HiggsAnaDefs.hh" |
32 |
< |
#include "TEventInfo.hh" |
33 |
< |
#include "TElectron.hh" |
34 |
< |
#include "TMuon.hh" |
35 |
< |
#include "TJet.hh" |
36 |
< |
#include "RunLumiRangeMap.h" |
31 |
> |
#include "EventHeader.h" |
32 |
> |
#include "Electron.h" |
33 |
> |
#include "Muon.h" |
34 |
> |
#include "Vertex.h" |
35 |
> |
#include "PFCandidate.h" |
36 |
> |
#include "PFCandidateCol.h" |
37 |
> |
#include "PileupInfoCol.h" |
38 |
> |
#include "PileupEnergyDensity.h" |
39 |
> |
#include "TriggerMask.h" |
40 |
> |
#include "TriggerTable.h" |
41 |
> |
#include "Names.h" |
42 |
> |
#include "BaseMod.h" |
43 |
|
|
44 |
|
// |
45 |
< |
// utility headers |
45 |
> |
// our headers |
46 |
|
// |
47 |
|
#include "ParseArgs.h" |
48 |
+ |
#include "MuonSelection.h" |
49 |
+ |
#include "ElectronSelection.h" |
50 |
+ |
#include "IsolationSelection.h" |
51 |
+ |
|
52 |
+ |
//#include "Selection.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 "GlobalDataAndFuncs.h" |
63 |
+ |
#include "RunLumiRangeMap.h" |
64 |
+ |
|
65 |
+ |
#include "AngleTuple.h" |
66 |
+ |
#include "FOTuple.h" |
67 |
+ |
|
68 |
|
#include "SampleWeight.h" |
69 |
< |
#include "Selection.h" |
70 |
< |
#include "HZZCiCElectronSelection.h" |
71 |
< |
#include "HZZLikelihoodElectronSelection.h" |
72 |
< |
#include "HZZBDTElectronSelection.h" |
73 |
< |
#include "SampleWeight.h" |
69 |
> |
#include "EfficiencyWeightsInterface.h" |
70 |
> |
|
71 |
> |
#include "SimpleLepton.h" |
72 |
> |
|
73 |
> |
#ifndef CMSSW_BASE |
74 |
> |
#define CMSSW_BASE "../" |
75 |
> |
#endif |
76 |
> |
|
77 |
> |
using namespace mithep; |
78 |
> |
|
79 |
> |
// |
80 |
> |
// globals |
81 |
> |
//---------------------------------------------------------------------------- |
82 |
> |
TH1D * hpu; |
83 |
> |
RunLumiRangeMap rlrm; |
84 |
> |
vector<SimpleLepton> failingLeptons ; // for fake estimation |
85 |
> |
vector<SimpleLepton> passingLeptons; // for fake estimation |
86 |
> |
|
87 |
> |
// |
88 |
> |
// prototypes |
89 |
> |
//---------------------------------------------------------------------------- |
90 |
> |
bool setPV(ControlFlags,const mithep::Array<mithep::Vertex>*, mithep::Vertex& ); |
91 |
> |
void initPUWeights(); |
92 |
> |
double getPUWeight(unsigned npu); |
93 |
> |
void setEffiencyWeights(EventData&, WeightStruct& ); |
94 |
> |
void initRunLumiRangeMap(); |
95 |
> |
//---------------------------------------------------------------------------- |
96 |
|
|
53 |
– |
//#define THEIR_EVENTS |
97 |
|
|
98 |
< |
//=== MAIN ================================================================================================= |
98 |
> |
// |
99 |
> |
// MAIN |
100 |
> |
//---------------------------------------------------------------------------- |
101 |
|
int main(int argc, char** argv) |
102 |
+ |
//---------------------------------------------------------------------------- |
103 |
|
{ |
104 |
< |
|
104 |
> |
string cmsswpath(CMSSW_BASE); |
105 |
> |
cmsswpath.append("/src"); |
106 |
> |
std::bitset<1024> triggerBits; |
107 |
|
vector<vector<string> > inputFiles; |
108 |
|
inputFiles.push_back(vector<string>()); |
109 |
+ |
map<string,unsigned> entrymap; // number of unskimmed entries in each file |
110 |
|
|
111 |
|
// |
112 |
|
// args |
113 |
|
//-------------------------------------------------------------------------------------------------------------- |
114 |
|
ControlFlags ctrl; |
115 |
|
parse_args( argc, argv, ctrl ); |
116 |
< |
if( ctrl.inputfile.empty() || |
117 |
< |
ctrl.inputfile.empty() ) { |
118 |
< |
cerr << "usage: applySelection.exe <flags> " << endl; |
119 |
< |
cerr << "\tmandoatory flags : " << endl; |
120 |
< |
cerr << "\t--inputfile | file containing a list of ntuples to run over" << endl; |
121 |
< |
cerr << "\t--outputfile | file to store selected evet" << endl; |
122 |
< |
return 1; |
123 |
< |
} |
116 |
> |
if( ctrl.inputfiles.empty() &&ctrl.inputfile.empty() ) |
117 |
> |
{ |
118 |
> |
cerr << "usage: applySelection.exe <flags> " << endl; |
119 |
> |
cerr << "\tmandoatory flags : " << endl; |
120 |
> |
cerr << "\t--inputfiles | file containing a list of ntuples to run over" << endl; |
121 |
> |
cerr << "\t--inputfile | a file to run over" << endl; |
122 |
> |
cerr << "\t--outputfile | file to store selected evet" << endl; |
123 |
> |
return 1; |
124 |
> |
} |
125 |
|
ctrl.dump(); |
126 |
|
|
127 |
< |
map<string,double> entrymap; // number of unskimmed entries in each file |
127 |
> |
|
128 |
|
|
129 |
|
// |
130 |
|
// File I/O |
131 |
|
//-------------------------------------------------------------------------------------------------------------- |
132 |
|
TChain * chain = new TChain("Events"); |
133 |
< |
ifstream f(ctrl.inputfile.c_str()); |
133 |
> |
TChain * hltchain = new TChain("HLT"); |
134 |
> |
|
135 |
|
string fname; |
136 |
< |
while (f >> fname) { |
137 |
< |
if( !(strncmp( fname.c_str(), "#", 1 ) ) ) continue; // skip commented lines |
138 |
< |
cout << "adding inputfile : " << fname.c_str() << endl; |
139 |
< |
entrymap[string(fname.c_str())] = unskimmedEntries(fname.c_str()); |
140 |
< |
chain->AddFile(fname.c_str()); |
136 |
> |
if( !ctrl.inputfiles.empty() ) { |
137 |
> |
ifstream f(ctrl.inputfiles.c_str()); |
138 |
> |
while (f >> fname) { |
139 |
> |
if( !(strncmp( fname.c_str(), "#", 1 ) ) ) continue; // skip commented lines |
140 |
> |
cout << "adding inputfile : " << fname.c_str() << endl; |
141 |
> |
entrymap[string(fname.c_str())] = unskimmedEntries(fname.c_str()); |
142 |
> |
cout << "unskimmed entries: " << entrymap[string(fname.c_str())] << endl; |
143 |
> |
chain->AddFile(fname.c_str()); |
144 |
> |
hltchain->AddFile(fname.c_str()); |
145 |
> |
} |
146 |
> |
} else { |
147 |
> |
cout << "adding inputfile : " << ctrl.inputfile.c_str() << endl; |
148 |
> |
unsigned tmpent = unskimmedEntries(ctrl.inputfile.c_str()); |
149 |
> |
cout << "tmpent: " << tmpent << endl; |
150 |
> |
entrymap[string(ctrl.inputfile.c_str())] = unskimmedEntries(ctrl.inputfile.c_str()); |
151 |
> |
cout << "unskimmed entries: " << entrymap[string(ctrl.inputfile.c_str())] << endl; |
152 |
> |
chain->AddFile(ctrl.inputfile.c_str()); |
153 |
> |
hltchain->AddFile(ctrl.inputfile.c_str()); |
154 |
|
} |
155 |
|
|
156 |
+ |
const char * ofname; |
157 |
+ |
if( strcmp( ctrl.outputfile.c_str(), "") ) { |
158 |
+ |
ofname = ctrl.outputfile.c_str(); |
159 |
+ |
} else { |
160 |
+ |
ofname = "tmp.root"; |
161 |
+ |
} |
162 |
|
// table of cross section values |
163 |
< |
SimpleTable xstab("./data/xs.dat"); |
163 |
> |
string xspath = (cmsswpath+string("/MitPhysics/data/xs.dat")); |
164 |
> |
cout << "xspath: " << xspath.c_str() << endl; |
165 |
> |
SimpleTable xstab(xspath.c_str()); |
166 |
> |
|
167 |
|
|
168 |
|
// |
169 |
|
// Setup |
170 |
|
//-------------------------------------------------------------------------------------------------------------- |
171 |
< |
TH1F * h_evt = new TH1F("hevt", "hevt", 2, 0, 2 ); |
172 |
< |
TH1F * h_evtfail = new TH1F("hevtfail", "hevtfail", 1024, 0, 1024 ); |
173 |
< |
TNtuple * passtuple = new TNtuple( "passtuple", "passtuple", "run:evt:lumi:channel:mZ1:mZ2:m4l:pt4l:w" ); |
174 |
< |
initCiCSelection(); |
175 |
< |
if(ctrl.eleSele=="lik") initLikSelection(); |
176 |
< |
if(ctrl.eleSele=="bdt") initBDTSelection(); |
177 |
< |
initRunLumiRangeMap(); |
171 |
> |
Angles angles; |
172 |
> |
KinematicsStruct kinematics; |
173 |
> |
InfoStruct evtinfo; |
174 |
> |
WeightStruct weights; |
175 |
> |
// GenInfoStruct geninfo; |
176 |
> |
|
177 |
> |
AngleTuple nt( (const char*)ofname, (const char*)"zznt"); |
178 |
> |
nt.makeAngleBranch(angles); |
179 |
> |
nt.makeKinematicsBranch(kinematics); |
180 |
> |
nt.makeInfoBranch(evtinfo); |
181 |
> |
FOTuple foTree( nt.getFile(), (const char*)"fo"); |
182 |
> |
foTree.makeFailedLeptonBranch(failingLeptons); |
183 |
> |
foTree.makeZLeptonBranch(passingLeptons); |
184 |
> |
|
185 |
> |
TH1F * h_w_hpt; |
186 |
> |
if(ctrl.mc) { |
187 |
> |
nt.makeWeightBranch(weights); |
188 |
> |
// nt.makeGenInfoBranch(geninfo); |
189 |
> |
initEfficiencyWeights(); |
190 |
> |
initPUWeights(); |
191 |
> |
/* |
192 |
> |
// Higgs only, pt reweighting |
193 |
> |
if( ctrl.mH <= 140 ) { |
194 |
> |
char wptname[256]; |
195 |
> |
sprintf( wptname, "/data/blue/pharris/Flat/ntupler/root/weight_ptH_%i.root", ctrl.mH ); |
196 |
> |
TFile * f_hpt = new TFile(wptname); |
197 |
> |
f_hpt->Print(); |
198 |
> |
sprintf(wptname, "weight_hqt_fehipro_fit_%i", ctrl.mH); |
199 |
> |
h_w_hpt = (TH1F*)(f_hpt->FindObjectAny(wptname)); |
200 |
> |
h_w_hpt->Print(); |
201 |
> |
} |
202 |
> |
*/ |
203 |
> |
} else { |
204 |
> |
initRunLumiRangeMap(); |
205 |
> |
} |
206 |
> |
|
207 |
> |
// initMuonIDMVA(); |
208 |
> |
initMuonIsoMVA(); |
209 |
> |
initElectronIDMVA(); |
210 |
> |
initElectronIsoMVA(); |
211 |
> |
initTrigger(); |
212 |
> |
|
213 |
|
|
106 |
– |
// |
107 |
– |
// Loop |
108 |
– |
//-------------------------------------------------------------------------------------------------------------- |
214 |
|
|
215 |
|
// |
216 |
< |
// Access samples and fill histograms |
216 |
> |
// Setup tree I/O |
217 |
> |
//-------------------------------------------------------------------------------------------------------------- |
218 |
|
TFile *inputFile=0; |
219 |
|
TTree *eventTree=0; |
220 |
< |
|
115 |
< |
// Data structures to store info from TTrees |
116 |
< |
mithep::TEventInfo *info = new mithep::TEventInfo(); |
117 |
< |
TClonesArray *electronArr = new TClonesArray("mithep::TElectron"); |
118 |
< |
TClonesArray *muonArr = new TClonesArray("mithep::TMuon"); |
119 |
< |
|
120 |
< |
|
121 |
< |
TBranch *infoBr; |
122 |
< |
TBranch *electronBr; |
123 |
< |
TBranch *muonBr; |
124 |
< |
|
125 |
< |
// chain->SetBranchStatus("*",0); //disable all branches |
126 |
< |
// chain->SetBranchStatus("Info", 1); |
127 |
< |
// chain->SetBranchStatus("Muon", 1); |
128 |
< |
// chain->SetBranchStatus("Electron", 1); |
129 |
< |
|
130 |
< |
chain->SetBranchAddress("Info", &info); |
131 |
< |
chain->SetBranchAddress("Electron", &electronArr); |
132 |
< |
chain->SetBranchAddress("Muon", &muonArr); |
220 |
> |
string currentFile(""); |
221 |
|
|
222 |
+ |
mithep::EventHeader *info = new mithep::EventHeader(); |
223 |
+ |
// mithep::TGenInfo *ginfo = new mithep::TGenInfo(); |
224 |
+ |
mithep::Array<mithep::Electron> *electronArr = new mithep::Array<mithep::Electron>(); |
225 |
+ |
mithep::Array<mithep::Muon> *muonArr = new mithep::Array<mithep::Muon>(); |
226 |
+ |
mithep::Array<mithep::Vertex> *vtxArr = new mithep::Array<mithep::Vertex>(); |
227 |
+ |
mithep::Array<mithep::PFCandidate> *pfArr = new mithep::Array<mithep::PFCandidate>(); |
228 |
+ |
mithep::Array<mithep::PileupInfo> *puArr = new mithep::Array<mithep::PileupInfo>(); |
229 |
+ |
mithep::Array<mithep::PileupEnergyDensity> *puDArr = new mithep::Array<mithep::PileupEnergyDensity>(); |
230 |
+ |
mithep::Array<mithep::Track> *trkArr = new mithep::Array<mithep::Track>(); |
231 |
+ |
mithep::TriggerMask *trigMask = new mithep::TriggerMask(); |
232 |
+ |
mithep::TriggerTable *hltTable = new mithep::TriggerTable(); |
233 |
+ |
vector<string> *hltTableStrings = new vector<string>(); |
234 |
+ |
|
235 |
+ |
TString fElectronName(Names::gkElectronBrn); |
236 |
+ |
TString fMuonName(Names::gkMuonBrn); |
237 |
+ |
TString fInfoName(Names::gkEvtHeaderBrn); |
238 |
+ |
TString fPrimVtxName(Names::gkPVBrn); |
239 |
+ |
TString fPFCandidateName(Names::gkPFCandidatesBrn); |
240 |
+ |
TString fPileupInfoName(Names::gkPileupInfoBrn); |
241 |
+ |
TString fPileupEnergyDensityName(Names::gkPileupEnergyDensityBrn); |
242 |
+ |
TString fTrackName(Names::gkTrackBrn); |
243 |
+ |
TString fTriggerMaskName(Names::gkHltBitBrn); |
244 |
+ |
TString fTriggerTableName(Names::gkHltTableBrn); |
245 |
+ |
|
246 |
+ |
chain->SetBranchAddress(fInfoName, &info); |
247 |
+ |
chain->SetBranchAddress(fElectronName, &electronArr); |
248 |
+ |
chain->SetBranchAddress(fMuonName, &muonArr); |
249 |
+ |
chain->SetBranchAddress(fPrimVtxName, &vtxArr); |
250 |
+ |
chain->SetBranchAddress(fPFCandidateName, &pfArr); |
251 |
+ |
chain->SetBranchAddress(fPileupInfoName, &puArr); |
252 |
+ |
chain->SetBranchAddress(fPileupEnergyDensityName, &puDArr); |
253 |
+ |
chain->SetBranchAddress(fTrackName, &trkArr); |
254 |
+ |
chain->SetBranchAddress(fTriggerMaskName, &trigMask); |
255 |
+ |
cout << "hlttable: " << fTriggerTableName << endl; |
256 |
+ |
hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings); |
257 |
+ |
|
258 |
+ |
mithep::Vertex vtx; // best primary vertex in the event |
259 |
+ |
|
260 |
+ |
// ginfo = NULL; |
261 |
+ |
// if( ctrl.mc ) { chain->SetBranchAddress("Gen", &ginfo);} |
262 |
+ |
|
263 |
+ |
int count=0, pass=0; |
264 |
+ |
float passcorr=0., passcorr_errup=0., passcorr_errdown=0.; |
265 |
+ |
float denom[3]={0.,0.,0.}; |
266 |
+ |
float numer[3]={0.,0.,0.}; |
267 |
+ |
float numercorr[3]={0.,0.,0.}; |
268 |
+ |
|
269 |
+ |
// only 1 HLT table / file ??? |
270 |
+ |
hltchain->GetEntry(0); |
271 |
+ |
cerr << "here... " << endl; |
272 |
|
|
273 |
+ |
int imax = chain->GetEntries(); |
274 |
+ |
cout << "nEntries: " << imax << endl; |
275 |
|
|
136 |
– |
cout << "nEntries: " << chain->GetEntries() << endl; |
137 |
– |
for(UInt_t ientry=0; ientry<chain->GetEntries(); ientry++) { |
138 |
– |
|
139 |
– |
chain->GetEntry(ientry); |
140 |
– |
if(!(ientry%100000)) cout << "entry: " << ientry << endl; |
141 |
– |
|
142 |
– |
// get event weight for this file |
143 |
– |
double eventweight=1; |
144 |
– |
if(ctrl.mc) eventweight = getWeight(xstab,entrymap,chain); |
145 |
– |
|
146 |
– |
#ifdef THEIR_EVENTS |
147 |
– |
if( !( info->evtNum == 504867308 || |
148 |
– |
info->evtNum == 368148849 || |
149 |
– |
info->evtNum == 129514273 || |
150 |
– |
info->evtNum == 286336207 || |
151 |
– |
info->evtNum == 344708580 || |
152 |
– |
info->evtNum == 30998576 || |
153 |
– |
info->evtNum == 155679852 || |
154 |
– |
info->evtNum == 394010457 || |
155 |
– |
info->evtNum == 917379387 || |
156 |
– |
info->evtNum == 78213037 || |
157 |
– |
info->evtNum == 337493970 || |
158 |
– |
info->evtNum == 1491724484 || |
159 |
– |
info->evtNum == 480301165 || |
160 |
– |
info->evtNum == 1038911933 || |
161 |
– |
info->evtNum == 876658967 || |
162 |
– |
info->evtNum == 966824024 || |
163 |
– |
info->evtNum == 141954801 || |
164 |
– |
info->evtNum == 160966858 || |
165 |
– |
info->evtNum == 191231387 || |
166 |
– |
info->evtNum == 66033190 || |
167 |
– |
info->evtNum == 10347106 || |
168 |
– |
info->evtNum == 107360878 ) ) continue; |
169 |
– |
#endif |
276 |
|
|
277 |
< |
unsigned evtfail = fails_HZZ4L_selection(ctrl, info, electronArr, muonArr, eventweight, passtuple); |
278 |
< |
h_evtfail->Fill( evtfail, eventweight ); |
279 |
< |
if( ctrl.debug ) cout << endl << endl; |
280 |
< |
|
281 |
< |
} //end loop over data |
277 |
> |
// |
278 |
> |
// Loop !!!!!!!!! |
279 |
> |
//-------------------------------------------------------------------------------------------------------------- |
280 |
> |
for(UInt_t ientry=0; ientry<imax; ientry++) |
281 |
> |
{ |
282 |
> |
chain->GetEntry(ientry); |
283 |
> |
if(!(ientry%1000)) cerr << "entry: " << ientry << endl; |
284 |
> |
if( ientry>100 )break; |
285 |
> |
setPV( ctrl, vtxArr, vtx); |
286 |
> |
|
287 |
> |
|
288 |
> |
// |
289 |
> |
// data/MC |
290 |
> |
// |
291 |
> |
if(ctrl.mc) { |
292 |
> |
// |
293 |
> |
// xsec & PU weights |
294 |
> |
// |
295 |
> |
weights.w = getWeight(xstab,entrymap,chain)/ctrl.totalMC; |
296 |
> |
int npu = -1; |
297 |
> |
for(int i=0;i<puArr->GetEntries();i++) { |
298 |
> |
if(puArr->At(i)->GetBunchCrossing() == 0) |
299 |
> |
npu = puArr->At(i)->GetPU_NumInteractions(); |
300 |
> |
} |
301 |
> |
assert(npu>=0); |
302 |
> |
evtinfo.npu; |
303 |
> |
weights.npuw = getPUWeight(evtinfo.npu); |
304 |
> |
// cout << "weight: " << weights.w << endl; |
305 |
> |
} else { |
306 |
> |
// |
307 |
> |
// JSON |
308 |
> |
// |
309 |
> |
RunLumiRangeMap::RunLumiPairType rl(info->RunNum(), info->LumiSec()); |
310 |
> |
if( !(rlrm.HasRunLumi(rl)) ) { |
311 |
> |
if( ctrl.debug ) cout << "\tfails JSON" << endl; |
312 |
> |
continue; |
313 |
> |
} |
314 |
> |
// |
315 |
> |
// trigger |
316 |
> |
// |
317 |
> |
if( string(chain->GetFile()->GetEndpointUrl()->GetFile()) != currentFile ) { |
318 |
> |
currentFile = string(chain->GetFile()->GetEndpointUrl()->GetFile()); |
319 |
> |
hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings); |
320 |
> |
hltchain->GetEntry(0); |
321 |
> |
hltTable->Clear(); |
322 |
> |
fillTriggerBits(hltTable, hltTableStrings ); |
323 |
> |
} |
324 |
> |
if( ctrl.debug ) cout << "file is : " << currentFile << endl; |
325 |
> |
fillTriggerBits( hltTable, trigMask, triggerBits ); |
326 |
> |
if( !passHLT(triggerBits, info->RunNum(), info->EvtNum() ) ) { |
327 |
> |
if( ctrl.debug ) cout << "\tfails trigger ... " << endl; |
328 |
> |
continue; |
329 |
> |
} |
330 |
> |
} |
331 |
> |
|
332 |
> |
// |
333 |
> |
// lepton/kinematic selection ... |
334 |
> |
// |
335 |
> |
failingLeptons.clear(); |
336 |
> |
passingLeptons.clear(); |
337 |
> |
EventData ret4l = |
338 |
> |
apply_HZZ4L_reference_selection(ctrl, info, |
339 |
> |
vtx, |
340 |
> |
pfArr, |
341 |
> |
puDArr, |
342 |
> |
electronArr, |
343 |
> |
&electronReferencePreSelection, |
344 |
> |
&electronReferenceIDMVASelection, |
345 |
> |
&electronReferenceIsoSelection, |
346 |
> |
muonArr, |
347 |
> |
&muonReferencePreSelection, |
348 |
> |
&muonIDPFSelection, |
349 |
> |
&muonReferenceIsoSelection); |
350 |
> |
/* |
351 |
> |
apply_HZZ4L_reference_selection(ctrl, info, |
352 |
> |
vtx, |
353 |
> |
pfArr, |
354 |
> |
puArr, |
355 |
> |
electronArr, |
356 |
> |
&electronPreSelection, |
357 |
> |
&electronIDMVASelection, |
358 |
> |
&electronIsoMVASelection, |
359 |
> |
muonArr, |
360 |
> |
&muonPreSelection, |
361 |
> |
&muonIDPFSelection, |
362 |
> |
&muonIsoMVASelection); |
363 |
> |
*/ |
364 |
> |
|
365 |
> |
if( ctrl.debug ) cout << endl; |
366 |
> |
|
367 |
> |
// cout << "bits: " << ret4l.status.selectionBits << endl; |
368 |
> |
|
369 |
> |
if( ret4l.status.pass() ) { |
370 |
> |
|
371 |
> |
fillAngles(ret4l,angles); |
372 |
> |
fillKinematics(ret4l,kinematics); |
373 |
> |
fillEventInfo(info,evtinfo); |
374 |
> |
if( ctrl.mc) { |
375 |
> |
// fillGenInfo(ginfo,geninfo); |
376 |
> |
setEffiencyWeights(ret4l, weights); |
377 |
> |
if(ctrl.debug) |
378 |
> |
cout << "w: " << weights.w << "\t" |
379 |
> |
<< "won: " << weights.won << "\t" |
380 |
> |
<< "woff: " << weights.woff << endl; |
381 |
> |
} |
382 |
> |
|
383 |
> |
/* |
384 |
> |
// only for Higgs < 140 |
385 |
> |
geninfo.weight *= h_w_hpt->GetBinContent(h_w_hpt->FindBin(geninfo.pt_zz)); |
386 |
> |
angles.bdt = reader->EvaluateMVA("BDTG"); |
387 |
> |
*/ |
388 |
> |
nt.Fill(); |
389 |
> |
|
390 |
> |
cerr << "PASS:: " |
391 |
> |
<< "\trun: " << evtinfo.run |
392 |
> |
<< "\tevt: " << evtinfo.evt |
393 |
> |
<< "\tlumi: " << evtinfo.lumi |
394 |
> |
<< "\tcostheta1: " << angles.costheta1 |
395 |
> |
<< "\tcostheta2: " << angles.costheta2 |
396 |
> |
<< "\tcostheta*: " << angles.costhetastar |
397 |
> |
<< "\tbdt: " << angles.bdt |
398 |
> |
<< endl; |
399 |
> |
pass++; |
400 |
> |
// if( pass > 3 ) break; |
401 |
> |
|
402 |
> |
} else if( ret4l.status.selectionBits.test(PASS_ZCANDIDATE) ) { // save for fakes ... |
403 |
> |
cout << "failingLeptons : " << failingLeptons.size() << endl; |
404 |
> |
for( int f=0; f<failingLeptons.size(); f++ ) { |
405 |
> |
SimpleLepton l = failingLeptons[f]; |
406 |
> |
cout << "f: " << f << "\t" |
407 |
> |
<< "type: " << l.type << "\t" |
408 |
> |
<< "pT: " << l.vec->Pt() |
409 |
> |
<< endl; |
410 |
> |
} |
411 |
> |
/* |
412 |
> |
cout << "passingLeptons : " << passingLeptons.GetSize() << endl; |
413 |
> |
for( int f=0; f<passingLeptons.GetSize(); f++ ) { |
414 |
> |
cout << "f: " << f << "\t" |
415 |
> |
<< "type: " << passingLeptons.At(f).type << "\t" |
416 |
> |
<< "pT: " << passingLeptons.At(f).vec->Pt() |
417 |
> |
<< endl; |
418 |
> |
} |
419 |
> |
*/ |
420 |
> |
cout << endl; |
421 |
> |
foTree.Fill(); |
422 |
> |
} |
423 |
> |
} |
424 |
|
|
425 |
+ |
|
426 |
+ |
foTree.getFile()->cd(); |
427 |
+ |
foTree.getTree()->Write(); |
428 |
+ |
nt.WriteClose(); |
429 |
+ |
} |
430 |
|
|
431 |
+ |
//---------------------------------------------------------------------------- |
432 |
+ |
// |
433 |
+ |
// Get primary vertices |
434 |
+ |
// Assumes primary vertices are ordered by sum-pT^2 (as should be in CMSSW) |
435 |
+ |
// NOTE: if no PV is found from fitting tracks, the beamspot is used |
436 |
+ |
// |
437 |
+ |
//---------------------------------------------------------------------------- |
438 |
+ |
bool setPV(ControlFlags ctrl, |
439 |
+ |
const mithep::Array<mithep::Vertex> * vtxArr, |
440 |
+ |
mithep::Vertex & vtx) |
441 |
+ |
//---------------------------------------------------------------------------- |
442 |
+ |
{ |
443 |
+ |
const Vertex *bestPV = 0; |
444 |
+ |
float best_sumpt=-1; |
445 |
+ |
|
446 |
+ |
// good PV requirements |
447 |
+ |
const UInt_t fMinNTracksFit = 0; |
448 |
+ |
const Double_t fMinNdof = 4; |
449 |
+ |
const Double_t fMaxAbsZ = 24; |
450 |
+ |
const Double_t fMaxRho = 2; |
451 |
+ |
|
452 |
+ |
for(int i=0; i<vtxArr->GetEntries(); ++i) { |
453 |
+ |
const Vertex *pv = (Vertex*)(vtxArr->At(i)); |
454 |
+ |
if( ctrl.debug ) cout << "vertex :: " << i << "\tntrks: " << pv->NTracks() << endl; |
455 |
+ |
|
456 |
+ |
// Select best PV for corrected d0; if no PV passing cuts, the first PV in the collection will be used |
457 |
+ |
// if(!pv->IsValid()) continue; |
458 |
+ |
if(pv->NTracksFit() < fMinNTracksFit) continue; |
459 |
+ |
if(pv->Ndof() < fMinNdof) continue; |
460 |
+ |
if(fabs(pv->Z()) > fMaxAbsZ) continue; |
461 |
+ |
if(pv->Position().Rho() > fMaxRho) continue; |
462 |
+ |
|
463 |
+ |
// take the first ... |
464 |
+ |
bestPV = pv; |
465 |
+ |
break; |
466 |
+ |
|
467 |
+ |
// this never reached ... |
468 |
+ |
float tmp_sumpt=0; |
469 |
+ |
for( int t=0; t<pv->NTracks(); t++ ) |
470 |
+ |
tmp_sumpt += pv->Trk(t)->Pt(); |
471 |
+ |
|
472 |
+ |
if( tmp_sumpt > best_sumpt ) { |
473 |
+ |
bestPV = pv; |
474 |
+ |
best_sumpt = tmp_sumpt; |
475 |
+ |
if( ctrl.debug) cout << "new PV set, pt : " << best_sumpt << endl; |
476 |
+ |
} |
477 |
+ |
} |
478 |
+ |
|
479 |
+ |
if(!bestPV) bestPV = vtxArr->At(0); |
480 |
+ |
vtx.SetPosition(bestPV->X(),bestPV->Y(),bestPV->Z()); |
481 |
+ |
vtx.SetErrors(bestPV->XErr(),bestPV->YErr(),bestPV->ZErr()); |
482 |
+ |
return true; |
483 |
+ |
}; |
484 |
|
|
179 |
– |
delete info; |
180 |
– |
delete electronArr; |
181 |
– |
delete muonArr; |
485 |
|
|
486 |
|
|
487 |
+ |
//---------------------------------------------------------------------------- |
488 |
+ |
void setEffiencyWeights(EventData & evtdat, WeightStruct & weights ) |
489 |
+ |
//---------------------------------------------------------------------------- |
490 |
+ |
{ |
491 |
+ |
vector<SimpleLepton> lepvec = evtdat.Z1leptons; |
492 |
+ |
lepvec.insert(lepvec.end(), evtdat.Z2leptons.begin(), evtdat.Z2leptons.end()); |
493 |
+ |
double w_offline=-1, werr_offline=0; |
494 |
+ |
double w_online=-1, werr_online=0; |
495 |
+ |
|
496 |
+ |
vector< pair <double,double> > wlegs; // pair here is eff & err |
497 |
+ |
vector< pair <float,float> > mvec; // pair here is eta & pt |
498 |
|
|
499 |
< |
//-------------------------------------------------------------------------------------------------------------- |
500 |
< |
// Save Histograms; |
501 |
< |
//============================================================================================================== |
502 |
< |
const char * ofname; |
503 |
< |
if( strcmp( ctrl.outputfile.c_str(), "") ) { |
504 |
< |
ofname = ctrl.outputfile.c_str(); |
505 |
< |
} else { |
506 |
< |
ofname = "tmp.root"; |
499 |
> |
// vector< pair <float,float> > evec; // pair here is eta & pt |
500 |
> |
// now deal with medium vs loose |
501 |
> |
vector< pair< bool, pair <float,float> > > evec; // pair here is eta & pt |
502 |
> |
|
503 |
> |
for( int k=0; k<lepvec.size(); k++ ) { |
504 |
> |
if( abs(lepvec[k].type) == 13 ) { |
505 |
> |
mvec.push_back( std::pair<float,float> (fabs(lepvec[k].vec->Eta()), lepvec[k].vec->Pt()) ); |
506 |
> |
wlegs.push_back( muonPerLegOfflineEfficiencyWeight( fabs(lepvec[k].vec->Eta()), |
507 |
> |
lepvec[k].vec->Pt() ) ); |
508 |
> |
} else { |
509 |
> |
|
510 |
> |
// now deal with medium vs loose |
511 |
> |
// evec.push_back( std::pair<float,float> (fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt()) ); |
512 |
> |
|
513 |
> |
std::pair<float,float> tmppair(fabs(lepvec[k].vec->Eta()), lepvec[k].vec->Pt()); |
514 |
> |
evec.push_back( std::pair<bool, std::pair<float,float> > (lepvec[k].isTight, tmppair) ); |
515 |
> |
|
516 |
> |
// wlegs.push_back( elePerLegOfflineEfficiencyWeight( fabs(lepvec[k].vec->Eta()), |
517 |
> |
// lepvec[k].vec->Pt() ) ); |
518 |
> |
|
519 |
> |
wlegs.push_back( elePerLegOfflineEfficiencyWeight( fabs(lepvec[k].vec->Eta()), |
520 |
> |
lepvec[k].vec->Pt(), |
521 |
> |
lepvec[k].isTight ) ); |
522 |
> |
|
523 |
> |
} |
524 |
|
} |
525 |
< |
|
526 |
< |
TFile *file = new TFile(ofname, "RECREATE"); |
527 |
< |
h_evt->Write(); |
528 |
< |
h_evtfail->Write(); |
529 |
< |
passtuple->Write(); |
530 |
< |
file->Close(); |
531 |
< |
delete file; |
532 |
< |
|
202 |
< |
// map<TString,TMVA::Reader*>::iterator it; |
203 |
< |
// for(it=readers.begin(); it!=readers.end(); it++) delete (*it).second; |
204 |
< |
|
205 |
< |
cerr << "done!" << endl; |
525 |
> |
|
526 |
> |
pair<double,double> offpair = getOfflineEfficiencyWeight( wlegs ); |
527 |
> |
weights.woff = offpair.first; |
528 |
> |
weights.werroff = offpair.second; |
529 |
> |
|
530 |
> |
pair<double,double> onpair = getOnlineEfficiencyWeight( mvec, evec ); |
531 |
> |
weights.won = onpair.first; |
532 |
> |
weights.werron = onpair.second; |
533 |
|
} |
534 |
|
|
535 |
|
|
536 |
+ |
//---------------------------------------------------------------------------- |
537 |
+ |
void initRunLumiRangeMap() |
538 |
+ |
//---------------------------------------------------------------------------- |
539 |
+ |
{ |
540 |
+ |
/* |
541 |
+ |
rlrm.AddJSONFile(std::string("./data/Cert_136033-149442_7TeV_Apr21ReReco_Collisions10_JSON.txt")); |
542 |
+ |
// rlrm.AddJSONFile(std::string("./data/Cert_160404-173244_7TeV_PromptReco_Collisions11_JSON_v2.txt")); |
543 |
+ |
rlrm.AddJSONFile(std::string("./data/Cert_160404-178078_7TeV_PromptReco_Collisions11_JSON.txt")); |
544 |
+ |
rlrm.AddJSONFile(std::string("./data/Cert_160404-163869_7TeV_May10ReReco_Collisions11_JSON_v3.txt")); |
545 |
+ |
rlrm.AddJSONFile(std::string("./data/Cert_170249-172619_7TeV_ReReco5Aug_Collisions11_JSON.txt")); |
546 |
+ |
// r11b |
547 |
+ |
rlrm.AddJSONFile(std::string("./data/Cert_160404-180252_7TeV_PromptReco_Collisions11_JSON.txt")); |
548 |
+ |
*/ |
549 |
+ |
}; |
550 |
+ |
|
551 |
|
|
552 |
+ |
//---------------------------------------------------------------------------- |
553 |
+ |
void initPUWeights() |
554 |
+ |
//---------------------------------------------------------------------------- |
555 |
+ |
{ |
556 |
+ |
TFile * puf = new TFile("data/PileupReweighting.Summer11DYmm_To_Full2011.root"); |
557 |
+ |
hpu = (TH1D*)(puf->Get("puWeights")); |
558 |
+ |
} |
559 |
+ |
|
560 |
+ |
//---------------------------------------------------------------------------- |
561 |
+ |
double getPUWeight(unsigned npu) |
562 |
+ |
//---------------------------------------------------------------------------- |
563 |
+ |
{ |
564 |
+ |
return hpu->GetBinContent(hpu->FindBin(npu)); |
565 |
+ |
} |