14 |
|
if (loggingVerbosity_ > 0) |
15 |
|
std::cout << "Add files to chain" << std::endl; |
16 |
|
inputTree->Add( inputName ); |
17 |
+ |
Init( outputName, loggingVerbosity_ ); |
18 |
+ |
} |
19 |
+ |
|
20 |
+ |
TreeWriter::TreeWriter( TChain* inputTree_, TString outputName, int loggingVerbosity_ ) { |
21 |
+ |
inputTree = inputTree_; |
22 |
+ |
Init( outputName, loggingVerbosity_ ); |
23 |
+ |
} |
24 |
+ |
|
25 |
+ |
|
26 |
+ |
void TreeWriter::Init( TString outputName, int loggingVerbosity_ ) { |
27 |
|
|
28 |
|
if (loggingVerbosity_ > 0) |
29 |
|
std::cout << "Set Branch Address of susy::Event" << std::endl; |
30 |
|
event = new susy::Event; |
31 |
|
inputTree->SetBranchAddress("susyEvent", &event); |
32 |
|
|
33 |
+ |
// Here the number of proceeded events will be stored. For plotting, simply use L*sigma/eventNumber |
34 |
+ |
eventNumbers = new TH1F("eventNumbers", "Histogram containing number of generated Events", 1, 0, 1); |
35 |
+ |
eventNumbers->GetXaxis()->SetBinLabel(1,"Number of generated Events"); |
36 |
+ |
|
37 |
|
// open the output file |
38 |
|
if (loggingVerbosity_>0) |
39 |
|
std::cout << "Open file " << outputName << " for writing." << std::endl; |
53 |
|
pileupHisto = (TH1F*) puFile->Get("pileup"); |
54 |
|
} |
55 |
|
|
42 |
– |
|
43 |
– |
|
56 |
|
TreeWriter::~TreeWriter() { |
57 |
|
if (pileupHisto != 0 ) |
58 |
|
delete pileupHisto; |
64 |
|
return sqrt(pow(v1.Eta() - v2.Eta(), 2) + pow(v1.Phi() - v2.Phi(), 2) ); |
65 |
|
} |
66 |
|
|
67 |
+ |
float effectiveAreaElectron( float eta ) { |
68 |
+ |
// see https://twiki.cern.ch/twiki/bin/view/CMS/EgammaEARhoCorrection |
69 |
+ |
// only for Delta R = 0.3 on 2012 Data |
70 |
+ |
eta = fabs( eta ); |
71 |
+ |
float ea; |
72 |
+ |
if( eta < 1.0 ) ea = 0.13; |
73 |
+ |
else if( eta < 1.479 ) ea = 0.14; |
74 |
+ |
else if( eta < 2.0 ) ea = 0.07; |
75 |
+ |
else if( eta < 2.2 ) ea = 0.09; |
76 |
+ |
else if( eta < 2.3 ) ea = 0.11; |
77 |
+ |
else if( eta < 2.4 ) ea = 0.11; |
78 |
+ |
else ea = 0.14; |
79 |
+ |
return ea; |
80 |
+ |
} |
81 |
+ |
|
82 |
|
// correct iso, see https://twiki.cern.ch/twiki/bin/view/CMS/CutBasedPhotonID2012 |
83 |
|
float chargedHadronIso_corrected(susy::Photon gamma, float rho) { |
84 |
< |
float eta = fabs(gamma.caloPosition.Eta()); |
85 |
< |
float ea; |
84 |
> |
float eta = fabs(gamma.caloPosition.Eta()); |
85 |
> |
float ea; |
86 |
|
|
87 |
< |
if(eta < 1.0) ea = 0.012; |
88 |
< |
else if(eta < 1.479) ea = 0.010; |
89 |
< |
else if(eta < 2.0) ea = 0.014; |
90 |
< |
else if(eta < 2.2) ea = 0.012; |
91 |
< |
else if(eta < 2.3) ea = 0.016; |
92 |
< |
else if(eta < 2.4) ea = 0.020; |
93 |
< |
else ea = 0.012; |
87 |
> |
if(eta < 1.0) ea = 0.012; |
88 |
> |
else if(eta < 1.479) ea = 0.010; |
89 |
> |
else if(eta < 2.0) ea = 0.014; |
90 |
> |
else if(eta < 2.2) ea = 0.012; |
91 |
> |
else if(eta < 2.3) ea = 0.016; |
92 |
> |
else if(eta < 2.4) ea = 0.020; |
93 |
> |
else ea = 0.012; |
94 |
|
|
95 |
< |
float iso = gamma.chargedHadronIso; |
96 |
< |
iso = max(iso - rho*ea, (float)0.); |
95 |
> |
float iso = gamma.chargedHadronIso; |
96 |
> |
iso = max(iso - rho*ea, (float)0.); |
97 |
|
|
98 |
< |
return iso; |
98 |
> |
return iso; |
99 |
|
} |
100 |
|
|
101 |
|
float neutralHadronIso_corrected(susy::Photon gamma, float rho) { |
102 |
< |
float eta = fabs(gamma.caloPosition.Eta()); |
103 |
< |
float ea; |
102 |
> |
float eta = fabs(gamma.caloPosition.Eta()); |
103 |
> |
float ea; |
104 |
|
|
105 |
< |
if(eta < 1.0) ea = 0.030; |
106 |
< |
else if(eta < 1.479) ea = 0.057; |
107 |
< |
else if(eta < 2.0) ea = 0.039; |
108 |
< |
else if(eta < 2.2) ea = 0.015; |
109 |
< |
else if(eta < 2.3) ea = 0.024; |
110 |
< |
else if(eta < 2.4) ea = 0.039; |
111 |
< |
else ea = 0.072; |
105 |
> |
if(eta < 1.0) ea = 0.030; |
106 |
> |
else if(eta < 1.479) ea = 0.057; |
107 |
> |
else if(eta < 2.0) ea = 0.039; |
108 |
> |
else if(eta < 2.2) ea = 0.015; |
109 |
> |
else if(eta < 2.3) ea = 0.024; |
110 |
> |
else if(eta < 2.4) ea = 0.039; |
111 |
> |
else ea = 0.072; |
112 |
|
|
113 |
< |
float iso = gamma.neutralHadronIso; |
114 |
< |
iso = max(iso - rho*ea, (float)0.); |
113 |
> |
float iso = gamma.neutralHadronIso; |
114 |
> |
iso = max(iso - rho*ea, (float)0.); |
115 |
|
|
116 |
< |
return iso; |
116 |
> |
return iso; |
117 |
|
} |
118 |
|
|
119 |
|
float photonIso_corrected(susy::Photon gamma, float rho) { |
120 |
< |
float eta = fabs(gamma.caloPosition.Eta()); |
121 |
< |
float ea; |
120 |
> |
float eta = fabs(gamma.caloPosition.Eta()); |
121 |
> |
float ea; |
122 |
|
|
123 |
< |
if(eta < 1.0) ea = 0.148; |
124 |
< |
else if(eta < 1.479) ea = 0.130; |
125 |
< |
else if(eta < 2.0) ea = 0.112; |
126 |
< |
else if(eta < 2.2) ea = 0.216; |
127 |
< |
else if(eta < 2.3) ea = 0.262; |
128 |
< |
else if(eta < 2.4) ea = 0.260; |
129 |
< |
else ea = 0.266; |
123 |
> |
if(eta < 1.0) ea = 0.148; |
124 |
> |
else if(eta < 1.479) ea = 0.130; |
125 |
> |
else if(eta < 2.0) ea = 0.112; |
126 |
> |
else if(eta < 2.2) ea = 0.216; |
127 |
> |
else if(eta < 2.3) ea = 0.262; |
128 |
> |
else if(eta < 2.4) ea = 0.260; |
129 |
> |
else ea = 0.266; |
130 |
|
|
131 |
< |
float iso = gamma.photonIso; |
132 |
< |
iso = max(iso - rho*ea, (float)0.); |
131 |
> |
float iso = gamma.photonIso; |
132 |
> |
iso = max(iso - rho*ea, (float)0.); |
133 |
> |
|
134 |
> |
return iso; |
135 |
> |
} |
136 |
|
|
137 |
< |
return iso; |
137 |
> |
float d0correction( susy::Electron electron, susy::Event event ) { |
138 |
> |
TVector3 beamspot = event.vertices[0].position; |
139 |
> |
susy::Track track = event.tracks[electron.gsfTrackIndex]; |
140 |
> |
float d0 = track.d0() - beamspot.X()*sin(track.phi()) + beamspot.Y()*cos(track.phi()); |
141 |
> |
cout << "return " << d0 << endl; |
142 |
> |
return d0; |
143 |
> |
} |
144 |
> |
|
145 |
> |
float dZcorrection( susy::Electron electron, susy::Event event ) { |
146 |
> |
TVector3 beamspot = event.vertices[0].position; |
147 |
> |
susy::Track track = event.tracks[electron.gsfTrackIndex]; |
148 |
> |
|
149 |
> |
if(track.momentum.Pt() == 0.) return 1.e6; |
150 |
> |
float dz = (track.vertex.Z() - beamspot.Z()) - ((track.vertex.X() - beamspot.X())*track.momentum.Px() + (track.vertex.Y() - beamspot.Y())*track.momentum.Py()) / track.momentum.Pt() * (track.momentum.Pz() / track.momentum.Pt()); |
151 |
> |
return dz; |
152 |
|
} |
153 |
|
|
154 |
|
float TreeWriter::getPtFromMatchedJet( susy::Photon myPhoton, susy::Event myEvent ) { |
186 |
|
}// if, else |
187 |
|
|
188 |
|
if ( nearJets.size() == 0 ) { |
189 |
< |
//std::cout << "No jet with deltaR < .3 found, do not change photon_pt" << std::endl; |
189 |
> |
if( loggingVerbosity > 1 ) |
190 |
> |
std::cout << "No jet with deltaR < .3 found, do not change photon_pt" << std::endl; |
191 |
|
return myPhoton.momentum.Et(); |
192 |
|
} |
193 |
|
|
217 |
|
|
218 |
|
// get number of events to be proceeded |
219 |
|
Long64_t nentries = inputTree->GetEntries(); |
220 |
+ |
// store them in histo |
221 |
+ |
eventNumbers->Fill( "Number of generated Events", nentries ); |
222 |
|
if(processNEvents <= 0 || processNEvents > nentries) processNEvents = nentries; |
223 |
|
|
224 |
|
if( loggingVerbosity > 0 ) |
233 |
|
tree->Branch("electron", &electron); |
234 |
|
tree->Branch("muon", &muon); |
235 |
|
tree->Branch("met", &met, "met/F"); |
236 |
+ |
tree->Branch("metPhi", &met_phi, "metPhi/F"); |
237 |
+ |
tree->Branch("type1met", &type1met, "type1met/F"); |
238 |
+ |
tree->Branch("type1metPhi", &type1met_phi, "type1metPhi/F"); |
239 |
|
tree->Branch("ht", &ht, "ht/F"); |
240 |
|
tree->Branch("nVertex", &nVertex, "nVertex/I"); |
241 |
|
tree->Branch("pu_weight", &pu_weight, "pu_weight/F"); |
272 |
|
std::map<TString, std::vector<susy::Photon> >::iterator phoMap = event->photons.find("photons"); |
273 |
|
for(std::vector<susy::Photon>::iterator it = phoMap->second.begin(); |
274 |
|
it != phoMap->second.end() && phoMap != event->photons.end(); ++it ) { |
275 |
< |
if( ! it->isEB() && skim ) |
275 |
> |
if( !(it->isEB() || it->isEE()) && skim ) |
276 |
|
continue; |
277 |
|
thisphoton->pt = getPtFromMatchedJet( *it, *event ); |
278 |
< |
if( thisphoton->pt < 80 && skim ) |
229 |
< |
continue; |
230 |
< |
thisphoton->eta = it->momentum.Eta(); |
231 |
< |
thisphoton->phi = it->momentum.Phi(); |
278 |
> |
|
279 |
|
thisphoton->chargedIso = chargedHadronIso_corrected(*it, event->rho25); |
280 |
|
thisphoton->neutralIso = neutralHadronIso_corrected(*it, event->rho25); |
281 |
|
thisphoton->photonIso = photonIso_corrected(*it, event->rho25); |
282 |
< |
if ( it->r9 >= 1 && skim ) |
282 |
> |
|
283 |
> |
bool loose_photon_barrel = thisphoton->pt>20 |
284 |
> |
&& it->isEB() |
285 |
> |
&& it->passelectronveto |
286 |
> |
&& it->hadTowOverEm<0.05 |
287 |
> |
&& it->sigmaIetaIeta<0.012 |
288 |
> |
&& thisphoton->chargedIso<2.6 |
289 |
> |
&& thisphoton->neutralIso<3.5+0.04*thisphoton->pt |
290 |
> |
&& thisphoton->photonIso<1.3+0.005*thisphoton->pt; |
291 |
> |
bool loose_photon_endcap = thisphoton->pt > 20 |
292 |
> |
&& it->isEE() |
293 |
> |
&& it->passelectronveto |
294 |
> |
&& it->hadTowOverEm<0.05 |
295 |
> |
&& it->sigmaIetaIeta<0.034 |
296 |
> |
&& thisphoton->chargedIso<2.3 |
297 |
> |
&& thisphoton->neutralIso<2.9+0.04*thisphoton->pt; |
298 |
> |
if(!(loose_photon_endcap || loose_photon_barrel || thisphoton->pt > 75 ) && skim ) |
299 |
|
continue; |
300 |
+ |
thisphoton->eta = it->momentum.Eta(); |
301 |
+ |
thisphoton->phi = it->momentum.Phi(); |
302 |
|
thisphoton->r9 = it->r9; |
303 |
|
thisphoton->sigmaIetaIeta = it->sigmaIetaIeta; |
304 |
|
thisphoton->hadTowOverEm = it->hadTowOverEm; |
305 |
|
thisphoton->pixelseed = it->nPixelSeeds; |
306 |
+ |
thisphoton->conversionSafeVeto = it->passelectronveto; |
307 |
|
photon.push_back( *thisphoton ); |
308 |
|
if( loggingVerbosity > 2 ) |
309 |
|
std::cout << " p_T, gamma = " << thisphoton->pt << std::endl; |
333 |
|
float scale = s_it->second; |
334 |
|
TLorentzVector corrP4 = scale * it->momentum; |
335 |
|
|
336 |
< |
if(std::abs(corrP4.Eta()) > 3.0 && skim ) continue; |
336 |
> |
if(std::fabs(corrP4.Eta()) > 3.0 && skim ) continue; |
337 |
|
if(corrP4.Et() < 30 && skim ) continue; |
338 |
|
thisjet->pt = corrP4.Et(); |
339 |
|
thisjet->eta = corrP4.Eta(); |
340 |
|
thisjet->phi = corrP4.Phi(); |
341 |
|
thisjet->bCSV = it->bTagDiscriminators[susy::kCSV]; |
342 |
+ |
// jet composition |
343 |
+ |
thisjet->chargedHadronEnergy = it->chargedHadronEnergy; |
344 |
+ |
thisjet->neutralHadronEnergy = it->neutralHadronEnergy; |
345 |
+ |
thisjet->photonEnergy = it->photonEnergy; |
346 |
+ |
thisjet->electronEnergy = it->electronEnergy; |
347 |
+ |
thisjet->muonEnergy = it->muonEnergy; |
348 |
+ |
thisjet->HFHadronEnergy = it->HFHadronEnergy; |
349 |
+ |
thisjet->HFEMEnergy = it->HFEMEnergy; |
350 |
+ |
thisjet->chargedEmEnergy = it->chargedEmEnergy; |
351 |
+ |
thisjet->chargedMuEnergy = it->chargedMuEnergy; |
352 |
+ |
thisjet->neutralEmEnergy = it->neutralEmEnergy; |
353 |
+ |
|
354 |
|
if( loggingVerbosity > 2 ) |
355 |
|
std::cout << " p_T, jet = " << thisjet->pt << std::endl; |
356 |
|
|
382 |
|
|
383 |
|
// electrons |
384 |
|
tree::Particle* thiselectron = new tree::Particle(); |
307 |
– |
|
385 |
|
map<TString, vector<susy::Electron> >::iterator eleMap = event->electrons.find("gsfElectrons"); |
386 |
|
if(eleMap == event->electrons.end() && loggingVerbosity > 0) { |
387 |
|
cout << "gsfElectrons not found!" << endl; |
388 |
|
} else { |
389 |
+ |
cout << "now begin electrons " << endl; |
390 |
|
for(vector<susy::Electron>::iterator it = eleMap->second.begin(); it < eleMap->second.end(); ++it) { |
391 |
< |
thiselectron->pt = it->momentum.Et(); |
391 |
> |
// for cuts see https://twiki.cern.ch/twiki/bin/viewauth/CMS/EgammaCutBasedIdentification for veto electrons |
392 |
> |
if( it->momentum.Pt() < 1 || it->momentum.Pt() > 1e6 ) |
393 |
> |
continue; // spike rejection |
394 |
> |
float iso = ( it->chargedHadronIso + max(it->neutralHadronIso+it->photonIso |
395 |
> |
- effectiveAreaElectron(it->momentum.Eta())*event->rho25, (Float_t)0. ) |
396 |
> |
) / it->momentum.Pt(); |
397 |
> |
cout << iso << endl; |
398 |
> |
cout << d0correction( *it, *event ) << endl; |
399 |
> |
float test = d0correction( *it, *event ); |
400 |
> |
cout << test << endl; |
401 |
> |
float dZ = std::fabs( dZcorrection( *it, *event ) ); |
402 |
> |
cout <<" find e" << endl; |
403 |
> |
float d0 = 0.; |
404 |
> |
if ( it->isEB() ){ |
405 |
> |
if ( fabs(it->deltaEtaSuperClusterTrackAtVtx) > 0.007 |
406 |
> |
|| fabs(it->deltaPhiSuperClusterTrackAtVtx) > 0.8 |
407 |
> |
|| it->sigmaIetaIeta > 0.01 |
408 |
> |
|| it->hcalOverEcalBc > 0.15 |
409 |
> |
|| d0 > 0.04 |
410 |
> |
|| dZ > 0.2 |
411 |
> |
|| iso > 0.15 ) |
412 |
> |
continue; |
413 |
> |
} |
414 |
> |
else if( it->isEE() ) { |
415 |
> |
if ( fabs(it->deltaEtaSuperClusterTrackAtVtx) > 0.01 |
416 |
> |
|| fabs(it->deltaPhiSuperClusterTrackAtVtx) > 0.7 |
417 |
> |
|| it->sigmaIetaIeta > 0.03 |
418 |
> |
|| d0 > 0.04 |
419 |
> |
|| dZ > 0.2 |
420 |
> |
|| iso > 0.15 ) |
421 |
> |
continue; |
422 |
> |
} |
423 |
> |
else // not in barrel nor in endcap |
424 |
> |
continue; |
425 |
> |
// TODO: conversion rejection information not implemented yet, see twiki for more details |
426 |
> |
|
427 |
> |
thiselectron->pt = it->momentum.Pt(); |
428 |
|
if( thiselectron->pt < 20 ) |
429 |
|
continue; |
430 |
|
if( loggingVerbosity > 2 ) |
437 |
|
if( loggingVerbosity > 1 ) |
438 |
|
std::cout << "Found " << electron.size() << " electrons" << std::endl; |
439 |
|
|
326 |
– |
// this seems not to work yet, where is the bug? |
327 |
– |
/* |
328 |
– |
std::vector<susy::Electron> eVector = event->electrons["gsfElectronsx"]; |
329 |
– |
for( std::vector<susy::Electron>::iterator it = eVector.begin(); it != eVector.end(); ++it) { |
330 |
– |
thiselectron->pt = it->momentum.Et(); |
331 |
– |
if( thiselectron->pt < 20 ) |
332 |
– |
continue; |
333 |
– |
if( loggingVerbosity > 2 ) |
334 |
– |
std::cout << " p_T, electron = " << it->momentum.Et() << std::endl; |
335 |
– |
thiselectron->eta = it->momentum.Eta(); |
336 |
– |
thiselectron->phi = it->momentum.Phi(); |
337 |
– |
electron.push_back( *thiselectron ); |
338 |
– |
} |
339 |
– |
*/ |
340 |
– |
|
440 |
|
// muons |
441 |
|
std::vector<susy::Muon> mVector = event->muons["muons"]; |
442 |
|
tree::Particle* thismuon = new tree::Particle(); |
443 |
|
for( std::vector<susy::Muon>::iterator it = mVector.begin(); it != mVector.end(); ++it) { |
444 |
+ |
if( !( it->isPFMuon() && ( it->isGlobalMuon() || it->isTrackerMuon() ) ) ) |
445 |
+ |
continue; // see https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideMuonId#Loose_Muon |
446 |
|
thismuon->pt = it->momentum.Et(); |
447 |
|
if( thismuon->pt < 20 ) |
448 |
|
continue; |
465 |
|
|
466 |
|
|
467 |
|
outFile->cd(); |
468 |
+ |
eventNumbers->Write(); |
469 |
|
tree->Write(); |
470 |
|
outFile->Write(); |
471 |
|
outFile->Close(); |