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 "EWKAnaDefs.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 "TriggerMask.h" |
38 |
> |
#include "TriggerTable.h" |
39 |
> |
#include "Names.h" |
40 |
> |
#include "BaseMod.h" |
41 |
|
|
42 |
|
// |
43 |
< |
// utility headers |
43 |
> |
// our headers |
44 |
|
// |
45 |
|
#include "ParseArgs.h" |
46 |
< |
#include "Selection.h" |
47 |
< |
#include "HZZCiCElectronSelection.h" |
46 |
> |
#include "MuonSelection.h" |
47 |
> |
#include "ElectronSelection.h" |
48 |
> |
#include "IsolationSelection.h" |
49 |
> |
|
50 |
> |
//#include "Selection.h" |
51 |
> |
#include "ReferenceSelection.h" |
52 |
> |
|
53 |
> |
#include "TriggerUtils.h" |
54 |
> |
#include "PassHLT.h" |
55 |
> |
#include "Angles.h" |
56 |
> |
#include "KinematicsStruct.h" |
57 |
> |
#include "InfoStruct.h" |
58 |
> |
//#include "GenInfoStruct.h" |
59 |
> |
#include "WeightStruct.h" |
60 |
> |
#include "GlobalDataAndFuncs.h" |
61 |
> |
#include "AngleTuple.h" |
62 |
> |
|
63 |
> |
#include "SampleWeight.h" |
64 |
> |
#include "EfficiencyWeightsInterface.h" |
65 |
> |
|
66 |
> |
#ifndef CMSSW_BASE |
67 |
> |
#define CMSSW_BASE "../" |
68 |
> |
#endif |
69 |
> |
|
70 |
> |
using namespace mithep; |
71 |
|
|
72 |
< |
//#define THEIR_EVENTS |
72 |
> |
|
73 |
> |
//---------------------------------------------------------------------------- |
74 |
> |
bool setPV(ControlFlags,const mithep::Array<mithep::Vertex>*, mithep::Vertex& ); |
75 |
> |
//---------------------------------------------------------------------------- |
76 |
|
|
77 |
|
//=== MAIN ================================================================================================= |
78 |
|
int main(int argc, char** argv) |
79 |
|
{ |
80 |
< |
|
80 |
> |
string cmsswpath(CMSSW_BASE); |
81 |
> |
cmsswpath.append("/src"); |
82 |
> |
std::bitset<1024> triggerBits; |
83 |
|
vector<vector<string> > inputFiles; |
84 |
|
inputFiles.push_back(vector<string>()); |
85 |
+ |
map<string,double> entrymap; // number of unskimmed entries in each file |
86 |
|
|
87 |
|
// |
88 |
|
// args |
89 |
|
//-------------------------------------------------------------------------------------------------------------- |
90 |
|
ControlFlags ctrl; |
91 |
|
parse_args( argc, argv, ctrl ); |
92 |
< |
if( ctrl.inputfile.empty() || |
93 |
< |
ctrl.inputfile.empty() ) { |
94 |
< |
cerr << "usage: applySelection.exe <flags> " << endl; |
95 |
< |
cerr << "\tmandoatory flags : " << endl; |
96 |
< |
cerr << "\t--inputfile | file containing a list of ntuples to run over" << endl; |
97 |
< |
cerr << "\t--outputfile | file to store selected evet" << endl; |
98 |
< |
return 1; |
99 |
< |
} |
92 |
> |
if( ctrl.inputfiles.empty() &&ctrl.inputfile.empty() ) |
93 |
> |
{ |
94 |
> |
cerr << "usage: applySelection.exe <flags> " << endl; |
95 |
> |
cerr << "\tmandoatory flags : " << endl; |
96 |
> |
cerr << "\t--inputfiles | file containing a list of ntuples to run over" << endl; |
97 |
> |
cerr << "\t--inputfile | a file to run over" << endl; |
98 |
> |
cerr << "\t--outputfile | file to store selected evet" << endl; |
99 |
> |
return 1; |
100 |
> |
} |
101 |
|
ctrl.dump(); |
102 |
+ |
assert( ctrl.mH != 0 ); |
103 |
+ |
|
104 |
+ |
|
105 |
|
|
106 |
|
// |
107 |
|
// File I/O |
108 |
|
//-------------------------------------------------------------------------------------------------------------- |
109 |
|
TChain * chain = new TChain("Events"); |
110 |
< |
ifstream f(ctrl.inputfile.c_str()); |
110 |
> |
TChain * hltchain = new TChain("HLT"); |
111 |
> |
|
112 |
|
string fname; |
113 |
< |
while (f >> fname) { |
114 |
< |
if( !(strncmp( fname.c_str(), "#", 1 ) ) ) continue; // skip commented lines |
115 |
< |
cout << "adding inputfile : " << fname.c_str() << endl; |
116 |
< |
chain->AddFile(fname.c_str()); |
113 |
> |
if( !ctrl.inputfiles.empty() ) { |
114 |
> |
ifstream f(ctrl.inputfiles.c_str()); |
115 |
> |
while (f >> fname) { |
116 |
> |
if( !(strncmp( fname.c_str(), "#", 1 ) ) ) continue; // skip commented lines |
117 |
> |
cout << "adding inputfile : " << fname.c_str() << endl; |
118 |
> |
entrymap[string(fname.c_str())] = unskimmedEntries(fname.c_str()); |
119 |
> |
chain->AddFile(fname.c_str()); |
120 |
> |
hltchain->AddFile(fname.c_str()); |
121 |
> |
} |
122 |
> |
} else { |
123 |
> |
cout << "adding inputfile : " << ctrl.inputfile.c_str() << endl; |
124 |
> |
entrymap[string(ctrl.inputfile.c_str())] = unskimmedEntries(ctrl.inputfile.c_str()); |
125 |
> |
chain->AddFile(ctrl.inputfile.c_str()); |
126 |
> |
hltchain->AddFile(ctrl.inputfile.c_str()); |
127 |
|
} |
128 |
|
|
129 |
< |
// |
130 |
< |
// Setup |
131 |
< |
//-------------------------------------------------------------------------------------------------------------- |
132 |
< |
TH1F * h_evt = new TH1F("hevt", "hevt", 2, 0, 2 ); |
133 |
< |
TH1F * h_evtfail = new TH1F("hevtfail", "hevtfail", 100, 0, 100 ); |
134 |
< |
TNtuple * passtuple = new TNtuple( "passtuple", "passtuple", "run:evt:lumi:channel:mZ1:mZ2:m4l:pt4l:w" ); |
135 |
< |
initCiCSelection(); |
136 |
< |
initRunLumiRangeMap(); |
129 |
> |
const char * ofname; |
130 |
> |
if( strcmp( ctrl.outputfile.c_str(), "") ) { |
131 |
> |
ofname = ctrl.outputfile.c_str(); |
132 |
> |
} else { |
133 |
> |
ofname = "tmp.root"; |
134 |
> |
} |
135 |
> |
// table of cross section values |
136 |
> |
string xspath = (cmsswpath+string("/MitPhysics/data/xs.dat")); |
137 |
> |
cout << "xspath: " << xspath.c_str() << endl; |
138 |
> |
SimpleTable xstab(xspath.c_str()); |
139 |
|
|
140 |
|
|
141 |
|
// |
142 |
< |
// Loop |
142 |
> |
// Setup |
143 |
|
//-------------------------------------------------------------------------------------------------------------- |
144 |
+ |
Angles angles; |
145 |
+ |
KinematicsStruct kinematics; |
146 |
+ |
InfoStruct evtinfo; |
147 |
+ |
WeightStruct weights; |
148 |
+ |
// GenInfoStruct geninfo; |
149 |
+ |
|
150 |
+ |
AngleTuple nt( (const char*)ofname, (const char*)"zznt"); |
151 |
+ |
nt.makeAngleBranch(angles); |
152 |
+ |
nt.makeKinematicsBranch(kinematics); |
153 |
+ |
nt.makeInfoBranch(evtinfo); |
154 |
+ |
|
155 |
+ |
TH1F * h_w_hpt; |
156 |
+ |
if(ctrl.mc) { |
157 |
+ |
nt.makeWeightBranch(weights); |
158 |
+ |
// nt.makeGenInfoBranch(geninfo); |
159 |
+ |
initEfficiencyWeights(); |
160 |
+ |
/* |
161 |
+ |
// Higgs only, pt reweighting |
162 |
+ |
if( ctrl.mH <= 140 ) { |
163 |
+ |
char wptname[256]; |
164 |
+ |
sprintf( wptname, "/data/blue/pharris/Flat/ntupler/root/weight_ptH_%i.root", ctrl.mH ); |
165 |
+ |
TFile * f_hpt = new TFile(wptname); |
166 |
+ |
f_hpt->Print(); |
167 |
+ |
sprintf(wptname, "weight_hqt_fehipro_fit_%i", ctrl.mH); |
168 |
+ |
h_w_hpt = (TH1F*)(f_hpt->FindObjectAny(wptname)); |
169 |
+ |
h_w_hpt->Print(); |
170 |
+ |
} |
171 |
+ |
*/ |
172 |
+ |
} else { |
173 |
+ |
initRunLumiRangeMap(); |
174 |
+ |
} |
175 |
+ |
|
176 |
+ |
// initMuonIDMVA(); |
177 |
+ |
initMuonIsoMVA(); |
178 |
+ |
initElectronIDMVA(); |
179 |
+ |
initElectronIsoMVA(); |
180 |
+ |
initTrigger(); |
181 |
+ |
|
182 |
+ |
|
183 |
+ |
//########################################################################## |
184 |
+ |
// Setup tree I/O |
185 |
+ |
//########################################################################## |
186 |
|
|
187 |
|
// |
188 |
|
// Access samples and fill histograms |
189 |
|
TFile *inputFile=0; |
190 |
|
TTree *eventTree=0; |
191 |
< |
|
191 |
> |
string currentFile(""); |
192 |
> |
|
193 |
|
// Data structures to store info from TTrees |
194 |
< |
mithep::TEventInfo *info = new mithep::TEventInfo(); |
195 |
< |
TClonesArray *electronArr = new TClonesArray("mithep::TElectron"); |
196 |
< |
TClonesArray *muonArr = new TClonesArray("mithep::TMuon"); |
194 |
> |
mithep::EventHeader *info = new mithep::EventHeader(); |
195 |
> |
// mithep::TGenInfo *ginfo = new mithep::TGenInfo(); |
196 |
> |
mithep::Array<mithep::Electron> *electronArr = new mithep::Array<mithep::Electron>(); |
197 |
> |
mithep::Array<mithep::Muon> *muonArr = new mithep::Array<mithep::Muon>(); |
198 |
> |
mithep::Array<mithep::Vertex> *vtxArr = new mithep::Array<mithep::Vertex>(); |
199 |
> |
mithep::Array<mithep::PFCandidate> *pfArr = new mithep::Array<mithep::PFCandidate>(); |
200 |
> |
mithep::Array<mithep::PileupEnergyDensity> *puArr = new mithep::Array<mithep::PileupEnergyDensity>(); |
201 |
> |
mithep::Array<mithep::Track> *trkArr = new mithep::Array<mithep::Track>(); |
202 |
> |
mithep::TriggerMask *trigMask = new mithep::TriggerMask(); |
203 |
> |
mithep::TriggerTable *hltTable = new mithep::TriggerTable(); |
204 |
> |
vector<string> *hltTableStrings = new vector<string>(); |
205 |
> |
|
206 |
> |
TString fElectronName(Names::gkElectronBrn); |
207 |
> |
TString fMuonName(Names::gkMuonBrn); |
208 |
> |
TString fInfoName(Names::gkEvtHeaderBrn); |
209 |
> |
TString fPrimVtxName(Names::gkPVBrn); |
210 |
> |
TString fPFCandidateName(Names::gkPFCandidatesBrn); |
211 |
> |
TString fPileupEnergyDensityName(Names::gkPileupEnergyDensityBrn); |
212 |
> |
TString fTrackName(Names::gkTrackBrn); |
213 |
> |
TString fTriggerMaskName(Names::gkHltBitBrn); |
214 |
> |
TString fTriggerTableName(Names::gkHltTableBrn); |
215 |
|
|
216 |
+ |
chain->SetBranchAddress(fInfoName, &info); |
217 |
+ |
chain->SetBranchAddress(fElectronName, &electronArr); |
218 |
+ |
chain->SetBranchAddress(fMuonName, &muonArr); |
219 |
+ |
chain->SetBranchAddress(fPrimVtxName, &vtxArr); |
220 |
+ |
chain->SetBranchAddress(fPFCandidateName, &pfArr); |
221 |
+ |
chain->SetBranchAddress(fPileupEnergyDensityName, &puArr); |
222 |
+ |
chain->SetBranchAddress(fTrackName, &trkArr); |
223 |
+ |
chain->SetBranchAddress(fTriggerMaskName, &trigMask); |
224 |
+ |
cout << "hlttable: " << fTriggerTableName << endl; |
225 |
+ |
hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings); |
226 |
+ |
|
227 |
+ |
mithep::Vertex vtx; // best primary vertex in the event |
228 |
+ |
|
229 |
+ |
// ginfo = NULL; |
230 |
+ |
// if( ctrl.mc ) { chain->SetBranchAddress("Gen", &ginfo);} |
231 |
+ |
|
232 |
+ |
int count=0, pass=0; |
233 |
+ |
float passcorr=0., passcorr_errup=0., passcorr_errdown=0.; |
234 |
+ |
float denom[3]={0.,0.,0.}; |
235 |
+ |
float numer[3]={0.,0.,0.}; |
236 |
+ |
float numercorr[3]={0.,0.,0.}; |
237 |
+ |
|
238 |
+ |
// only 1 HLT table / file ??? |
239 |
+ |
hltchain->GetEntry(0); |
240 |
+ |
cerr << "here... " << endl; |
241 |
+ |
|
242 |
+ |
int imax = chain->GetEntries(); |
243 |
+ |
cout << "nEntries: " << imax << endl; |
244 |
+ |
|
245 |
+ |
|
246 |
+ |
//########################################################################## |
247 |
+ |
// Loop !!!!!!!!! should alternate events here and +1 in the training ... |
248 |
+ |
//########################################################################## |
249 |
+ |
for(UInt_t ientry=0; ientry<imax; ientry++) |
250 |
+ |
{ |
251 |
+ |
chain->GetEntry(ientry); |
252 |
+ |
if(!(ientry%1000)) cerr << "entry: " << ientry << endl; |
253 |
+ |
|
254 |
+ |
setPV( ctrl, vtxArr, vtx); |
255 |
+ |
|
256 |
+ |
if(ctrl.mc) { |
257 |
+ |
weights.w = getWeight(xstab,entrymap,chain); |
258 |
+ |
} else { |
259 |
+ |
if( string(chain->GetFile()->GetEndpointUrl()->GetFile()) != currentFile ) { |
260 |
+ |
currentFile = string(chain->GetFile()->GetEndpointUrl()->GetFile()); |
261 |
+ |
hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings); |
262 |
+ |
hltchain->GetEntry(0); |
263 |
+ |
hltTable->Clear(); |
264 |
+ |
fillTriggerBits(hltTable, hltTableStrings ); |
265 |
+ |
} |
266 |
+ |
if( ctrl.debug ) cout << "file is : " << currentFile << endl; |
267 |
+ |
fillTriggerBits( hltTable, trigMask, triggerBits ); |
268 |
+ |
} |
269 |
+ |
|
270 |
+ |
|
271 |
+ |
// |
272 |
+ |
// trigger |
273 |
+ |
// |
274 |
+ |
if( !ctrl.mc ) { |
275 |
+ |
if( !passHLT(triggerBits, info->RunNum(), info->EvtNum() ) ) { |
276 |
+ |
if( ctrl.debug ) cout << "\tfails trigger ... " << endl; |
277 |
+ |
continue; |
278 |
+ |
} |
279 |
+ |
} |
280 |
+ |
|
281 |
+ |
// |
282 |
+ |
// lepton/kinematic selection ... |
283 |
+ |
// |
284 |
+ |
EventData ret4l = |
285 |
+ |
apply_HZZ4L_reference_selection(ctrl, info, |
286 |
+ |
vtx, |
287 |
+ |
pfArr, |
288 |
+ |
puArr, |
289 |
+ |
electronArr, |
290 |
+ |
&electronReferencePreSelection, |
291 |
+ |
&electronReferenceIDMVASelection, |
292 |
+ |
&electronReferenceIsoSelection, |
293 |
+ |
muonArr, |
294 |
+ |
&muonReferencePreSelection, |
295 |
+ |
&muonIDPFSelection, |
296 |
+ |
&muonReferenceIsoSelection); |
297 |
+ |
if( ctrl.debug ) cout << endl; |
298 |
+ |
|
299 |
+ |
cout << "bits: " << ret4l.status.selectionBits << endl; |
300 |
+ |
|
301 |
+ |
if( ret4l.status.pass() ) { |
302 |
+ |
|
303 |
+ |
fillAngles(ret4l,angles); |
304 |
+ |
fillKinematics(ret4l,kinematics); |
305 |
+ |
fillEventInfo(info,evtinfo); |
306 |
+ |
//if(ctrl.mc) fillGenInfo(ginfo,geninfo); |
307 |
+ |
|
308 |
+ |
/* |
309 |
+ |
// only for Higgs < 140 |
310 |
+ |
geninfo.weight *= h_w_hpt->GetBinContent(h_w_hpt->FindBin(geninfo.pt_zz)); |
311 |
+ |
angles.bdt = reader->EvaluateMVA("BDTG"); |
312 |
+ |
*/ |
313 |
+ |
nt.Fill(); |
314 |
+ |
|
315 |
+ |
cerr << "PASS:: " |
316 |
+ |
<< "\trun: " << evtinfo.run |
317 |
+ |
<< "\tevt: " << evtinfo.evt |
318 |
+ |
<< "\tlumi: " << evtinfo.lumi |
319 |
+ |
<< "\tcostheta1: " << angles.costheta1 |
320 |
+ |
<< "\tcostheta2: " << angles.costheta2 |
321 |
+ |
<< "\tcostheta*: " << angles.costhetastar |
322 |
+ |
<< "\tbdt: " << angles.bdt |
323 |
+ |
<< endl; |
324 |
+ |
pass++; |
325 |
+ |
// if( pass > 3 ) break; |
326 |
|
|
327 |
< |
TBranch *infoBr; |
328 |
< |
TBranch *electronBr; |
112 |
< |
TBranch *muonBr; |
113 |
< |
|
114 |
< |
// chain->SetBranchStatus("*",0); //disable all branches |
115 |
< |
// chain->SetBranchStatus("Info", 1); |
116 |
< |
// chain->SetBranchStatus("Muon", 1); |
117 |
< |
// chain->SetBranchStatus("Electron", 1); |
118 |
< |
|
119 |
< |
chain->SetBranchAddress("Info", &info); |
120 |
< |
chain->SetBranchAddress("Electron", &electronArr); |
121 |
< |
chain->SetBranchAddress("Muon", &muonArr); |
122 |
< |
|
327 |
> |
} |
328 |
> |
} |
329 |
|
|
330 |
+ |
nt.WriteClose(); |
331 |
+ |
} |
332 |
|
|
333 |
< |
cout << "nEntries: " << chain->GetEntries() << endl; |
334 |
< |
for(UInt_t ientry=0; ientry<chain->GetEntries(); ientry++) { |
333 |
> |
//---------------------------------------------------------------------------- |
334 |
> |
// |
335 |
> |
// Get primary vertices |
336 |
> |
// Assumes primary vertices are ordered by sum-pT^2 (as should be in CMSSW) |
337 |
> |
// NOTE: if no PV is found from fitting tracks, the beamspot is used |
338 |
> |
// |
339 |
> |
//---------------------------------------------------------------------------- |
340 |
> |
bool setPV(ControlFlags ctrl, |
341 |
> |
const mithep::Array<mithep::Vertex> * vtxArr, |
342 |
> |
mithep::Vertex & vtx) |
343 |
> |
//---------------------------------------------------------------------------- |
344 |
> |
{ |
345 |
> |
const Vertex *bestPV = 0; |
346 |
> |
float best_sumpt=-1; |
347 |
> |
|
348 |
> |
// good PV requirements |
349 |
> |
const UInt_t fMinNTracksFit = 0; |
350 |
> |
const Double_t fMinNdof = 4; |
351 |
> |
const Double_t fMaxAbsZ = 24; |
352 |
> |
const Double_t fMaxRho = 2; |
353 |
> |
|
354 |
> |
for(int i=0; i<vtxArr->GetEntries(); ++i) { |
355 |
> |
const Vertex *pv = (Vertex*)(vtxArr->At(i)); |
356 |
> |
if( ctrl.debug ) cout << "vertex :: " << i << "\tntrks: " << pv->NTracks() << endl; |
357 |
|
|
358 |
< |
chain->GetEntry(ientry); |
359 |
< |
|
360 |
< |
#ifdef THEIR_EVENTS |
361 |
< |
if( !( info->evtNum == 504867308 || |
362 |
< |
info->evtNum == 368148849 || |
363 |
< |
info->evtNum == 129514273 || |
364 |
< |
info->evtNum == 286336207 || |
365 |
< |
info->evtNum == 344708580 || |
366 |
< |
info->evtNum == 30998576 || |
367 |
< |
info->evtNum == 155679852 || |
368 |
< |
info->evtNum == 394010457 || |
369 |
< |
info->evtNum == 917379387 || |
370 |
< |
info->evtNum == 78213037 || |
371 |
< |
info->evtNum == 337493970 || |
372 |
< |
info->evtNum == 1491724484 || |
373 |
< |
info->evtNum == 480301165 || |
374 |
< |
info->evtNum == 1038911933 || |
375 |
< |
info->evtNum == 876658967 || |
376 |
< |
info->evtNum == 966824024 || |
377 |
< |
info->evtNum == 141954801 || |
378 |
< |
info->evtNum == 160966858 || |
149 |
< |
info->evtNum == 191231387 || |
150 |
< |
info->evtNum == 66033190 || |
151 |
< |
info->evtNum == 10347106 || |
152 |
< |
info->evtNum == 107360878 ) ) continue; |
153 |
< |
#endif |
154 |
< |
|
155 |
< |
unsigned evtfail = fails_HZZ4L_selection(ctrl, info, electronArr, muonArr, passtuple ); |
156 |
< |
double eventweight = info->eventweight; |
157 |
< |
h_evtfail->Fill( evtfail, eventweight ); |
158 |
< |
cout << endl << endl; |
159 |
< |
|
160 |
< |
} //end loop over data |
161 |
< |
|
162 |
< |
|
163 |
< |
|
164 |
< |
delete info; |
165 |
< |
delete electronArr; |
166 |
< |
delete muonArr; |
167 |
< |
|
168 |
< |
|
169 |
< |
|
170 |
< |
//-------------------------------------------------------------------------------------------------------------- |
171 |
< |
// Save Histograms; |
172 |
< |
//============================================================================================================== |
173 |
< |
const char * ofname; |
174 |
< |
if( strcmp( ctrl.outputfile.c_str(), "") ) { |
175 |
< |
ofname = ctrl.outputfile.c_str(); |
176 |
< |
} else { |
177 |
< |
ofname = "tmp.root"; |
358 |
> |
// Select best PV for corrected d0; if no PV passing cuts, the first PV in the collection will be used |
359 |
> |
// if(!pv->IsValid()) continue; |
360 |
> |
if(pv->NTracksFit() < fMinNTracksFit) continue; |
361 |
> |
if(pv->Ndof() < fMinNdof) continue; |
362 |
> |
if(fabs(pv->Z()) > fMaxAbsZ) continue; |
363 |
> |
if(pv->Position().Rho() > fMaxRho) continue; |
364 |
> |
|
365 |
> |
// take the first ... |
366 |
> |
bestPV = pv; |
367 |
> |
break; |
368 |
> |
|
369 |
> |
// this never reached ... |
370 |
> |
float tmp_sumpt=0; |
371 |
> |
for( int t=0; t<pv->NTracks(); t++ ) |
372 |
> |
tmp_sumpt += pv->Trk(t)->Pt(); |
373 |
> |
|
374 |
> |
if( tmp_sumpt > best_sumpt ) { |
375 |
> |
bestPV = pv; |
376 |
> |
best_sumpt = tmp_sumpt; |
377 |
> |
if( ctrl.debug) cout << "new PV set, pt : " << best_sumpt << endl; |
378 |
> |
} |
379 |
|
} |
380 |
< |
|
381 |
< |
TFile *file = new TFile(ofname, "RECREATE"); |
382 |
< |
h_evt->Write(); |
383 |
< |
h_evtfail->Write(); |
384 |
< |
passtuple->Write(); |
385 |
< |
file->Close(); |
185 |
< |
delete file; |
186 |
< |
|
187 |
< |
cerr << "done!" << endl; |
188 |
< |
} |
189 |
< |
|
190 |
< |
|
191 |
< |
|
380 |
> |
|
381 |
> |
if(!bestPV) bestPV = vtxArr->At(0); |
382 |
> |
vtx.SetPosition(bestPV->X(),bestPV->Y(),bestPV->Z()); |
383 |
> |
vtx.SetErrors(bestPV->XErr(),bestPV->YErr(),bestPV->ZErr()); |
384 |
> |
return true; |
385 |
> |
}; |