1 |
< |
#include "TFile.h" |
2 |
< |
#include "TTree.h" |
3 |
< |
#include "TString.h" |
4 |
< |
#include "TLorentzVector.h" |
1 |
> |
#include "treeWriter.h" |
2 |
|
|
3 |
< |
#include "SusyEvent.h" |
3 |
> |
using namespace std; |
4 |
|
|
5 |
+ |
TreeWriter::TreeWriter( std::string inputName, std::string outputName, int loggingVerbosity_ ) { |
6 |
+ |
// read the input file |
7 |
+ |
inputTree = new TChain("susyTree"); |
8 |
+ |
if (loggingVerbosity_ > 0) |
9 |
+ |
std::cout << "Add files to chain" << std::endl; |
10 |
+ |
inputTree->Add( inputName.c_str() ); |
11 |
+ |
Init( outputName, loggingVerbosity_ ); |
12 |
+ |
} |
13 |
|
|
14 |
< |
namespace tree { |
15 |
< |
// In this namespace classes for the trees are defined. |
14 |
> |
TreeWriter::TreeWriter( TChain* inputTree_, std::string outputName, int loggingVerbosity_ ) { |
15 |
> |
inputTree = inputTree_; |
16 |
> |
Init( outputName, loggingVerbosity_ ); |
17 |
> |
} |
18 |
|
|
19 |
< |
class Particle { |
20 |
< |
public: |
21 |
< |
float pt, eta, phi; |
22 |
< |
}; |
19 |
> |
void TreeWriter::Init( std::string outputName, int loggingVerbosity_ ) { |
20 |
> |
|
21 |
> |
if (loggingVerbosity_ > 0) |
22 |
> |
std::cout << "Set Branch Address of susy::Event" << std::endl; |
23 |
> |
event = new susy::Event; |
24 |
> |
inputTree->SetBranchAddress("susyEvent", &event); |
25 |
|
|
26 |
< |
class Photon : public Particle { |
27 |
< |
public: |
28 |
< |
float r9, sigmaIetaIeta, hadTowOverEm, pixelseed; |
20 |
< |
float chargedIso, neutralIso, photonIso; |
21 |
< |
}; |
26 |
> |
// Here the number of proceeded events will be stored. For plotting, simply use L*sigma/eventNumber |
27 |
> |
eventNumbers = new TH1F("eventNumbers", "Histogram containing number of generated events", 1, 0, 1); |
28 |
> |
eventNumbers->GetXaxis()->SetBinLabel(1,"Number of generated events"); |
29 |
|
|
30 |
< |
class Jet : public Particle{ |
31 |
< |
public: |
32 |
< |
float pt, eta; |
33 |
< |
}; |
30 |
> |
// open the output file |
31 |
> |
if (loggingVerbosity_>0) |
32 |
> |
std::cout << "Open file " << outputName << " for writing." << std::endl; |
33 |
> |
outFile = new TFile( outputName.c_str(), "recreate" ); |
34 |
> |
tree = new TTree("susyTree","Tree for single photon analysis"); |
35 |
|
|
36 |
< |
bool EtGreater(const tree::Particle p1, const tree::Particle p2) { |
37 |
< |
return p1.pt > p2.pt; |
36 |
> |
// set default parameter |
37 |
> |
processNEvents = -1; |
38 |
> |
reportEvery = 1000; |
39 |
> |
loggingVerbosity = loggingVerbosity_; |
40 |
> |
skim = true; |
41 |
> |
pileupHisto = 0; |
42 |
|
} |
43 |
|
|
44 |
< |
} // end namespace definition |
44 |
> |
void TreeWriter::PileUpWeightFile( string pileupFileName ) { |
45 |
> |
TFile *puFile = new TFile( pileupFileName.c_str() ); |
46 |
> |
pileupHisto = (TH1F*) puFile->Get("pileup"); |
47 |
> |
} |
48 |
|
|
49 |
< |
class TreeWriter { |
50 |
< |
public : |
51 |
< |
TreeWriter(TString inputName, TString outputName ); |
52 |
< |
virtual ~TreeWriter(); |
53 |
< |
virtual void Loop(); |
49 |
> |
TreeWriter::~TreeWriter() { |
50 |
> |
if (pileupHisto != 0 ) |
51 |
> |
delete pileupHisto; |
52 |
> |
inputTree->GetCurrentFile()->Close(); |
53 |
> |
delete inputTree; |
54 |
> |
delete event; |
55 |
> |
delete outFile; |
56 |
> |
delete tree; |
57 |
> |
} |
58 |
|
|
59 |
< |
void SetProcessNEvents(int nEvents) { processNEvents = nEvents; } |
60 |
< |
void SetReportEvents(int nEvents) { reportEvery = nEvents; } |
59 |
> |
template<class Type> |
60 |
> |
std::vector<Type>* getVectorFromMap( map<TString, vector<Type> > myMap, TString search ){ |
61 |
> |
// if nothing is found, return a empty vector (which has to be deleted never the less) |
62 |
> |
std::vector<Type>* vec; |
63 |
> |
typename map<TString, vector<Type> >::iterator mapIt = myMap.find( search ); |
64 |
> |
if( mapIt == myMap.end() ) { |
65 |
> |
cout << "ERROR: Collection \"" << search << "\" not found!" << endl; |
66 |
> |
vec = new std::vector<Type>; |
67 |
> |
} else |
68 |
> |
vec = &mapIt->second; |
69 |
> |
cout << vec->size() << endl; |
70 |
> |
return vec; |
71 |
> |
} |
72 |
|
|
73 |
< |
TFile *inputFile; |
74 |
< |
TTree *inputTree; |
75 |
< |
susy::Event *event; |
73 |
> |
float deltaPhi( float phi1, float phi2) { |
74 |
> |
float result = phi1 - phi2; |
75 |
> |
while (result > M_PI) result -= 2*M_PI; |
76 |
> |
while (result <= -M_PI) result += 2*M_PI; |
77 |
> |
return result; |
78 |
> |
} |
79 |
|
|
80 |
< |
TFile *outFile; |
81 |
< |
TTree *tree; |
80 |
> |
// useful functions |
81 |
> |
float deltaR( const TLorentzVector& v1, const TLorentzVector& v2 ) { |
82 |
> |
// deltaR = sqrt ( deltaEta^2 + deltaPhi^2 ) |
83 |
> |
return sqrt(pow(v1.Eta() - v2.Eta(), 2) + pow(deltaPhi(v1.Phi(),v2.Phi()), 2) ); |
84 |
> |
} |
85 |
|
|
86 |
< |
private: |
87 |
< |
int processNEvents; // number of events to be processed |
88 |
< |
int reportEvery; |
89 |
< |
int loggingVerbosity; |
86 |
> |
float effectiveAreaElectron( float eta ) { |
87 |
> |
// needed by calculating the isolation for electrons |
88 |
> |
// see https://twiki.cern.ch/twiki/bin/view/CMS/EgammaEARhoCorrection |
89 |
> |
// only for Delta R = 0.3 on 2012 Data |
90 |
> |
eta = fabs( eta ); |
91 |
> |
float ea; |
92 |
> |
if( eta < 1.0 ) ea = 0.13; |
93 |
> |
else if( eta < 1.479 ) ea = 0.14; |
94 |
> |
else if( eta < 2.0 ) ea = 0.07; |
95 |
> |
else if( eta < 2.2 ) ea = 0.09; |
96 |
> |
else if( eta < 2.3 ) ea = 0.11; |
97 |
> |
else if( eta < 2.4 ) ea = 0.11; |
98 |
> |
else ea = 0.14; |
99 |
> |
return ea; |
100 |
> |
} |
101 |
|
|
102 |
< |
// variables which will be stored in the tree |
103 |
< |
std::vector<tree::Photon> photon; |
104 |
< |
std::vector<tree::Jet> jet; |
105 |
< |
float met; |
106 |
< |
int nVertex; |
107 |
< |
float weight; |
108 |
< |
}; |
102 |
> |
// correct iso, see https://twiki.cern.ch/twiki/bin/view/CMS/CutBasedPhotonID2012 |
103 |
> |
float chargedHadronIso_corrected(const susy::Photon& gamma, float rho) { |
104 |
> |
float eta = fabs(gamma.caloPosition.Eta()); |
105 |
> |
float ea; |
106 |
> |
|
107 |
> |
if(eta < 1.0) ea = 0.012; |
108 |
> |
else if(eta < 1.479) ea = 0.010; |
109 |
> |
else if(eta < 2.0) ea = 0.014; |
110 |
> |
else if(eta < 2.2) ea = 0.012; |
111 |
> |
else if(eta < 2.3) ea = 0.016; |
112 |
> |
else if(eta < 2.4) ea = 0.020; |
113 |
> |
else ea = 0.012; |
114 |
|
|
115 |
+ |
float iso = gamma.chargedHadronIso; |
116 |
+ |
iso = max(iso - rho*ea, (float)0.); |
117 |
|
|
118 |
< |
TreeWriter::TreeWriter(TString inputName, TString outputName) { |
119 |
< |
// read the input file |
66 |
< |
inputFile = new TFile( inputName, "read" ); |
67 |
< |
inputTree = (TTree*) inputFile->Get("susyTree"); |
68 |
< |
event = new susy::Event; |
69 |
< |
inputTree->SetBranchAddress("susyEvent", &event); |
118 |
> |
return iso; |
119 |
> |
} |
120 |
|
|
121 |
< |
// open the output file |
122 |
< |
outFile = new TFile( outputName, "recreate" ); |
123 |
< |
tree = new TTree("susyTree","Tree for single photon analysis"); |
121 |
> |
float neutralHadronIso_corrected(const susy::Photon& gamma, float rho) { |
122 |
> |
float eta = fabs(gamma.caloPosition.Eta()); |
123 |
> |
float ea; |
124 |
> |
|
125 |
> |
if(eta < 1.0) ea = 0.030; |
126 |
> |
else if(eta < 1.479) ea = 0.057; |
127 |
> |
else if(eta < 2.0) ea = 0.039; |
128 |
> |
else if(eta < 2.2) ea = 0.015; |
129 |
> |
else if(eta < 2.3) ea = 0.024; |
130 |
> |
else if(eta < 2.4) ea = 0.039; |
131 |
> |
else ea = 0.072; |
132 |
|
|
133 |
< |
// set default parameter |
134 |
< |
processNEvents = -1; |
77 |
< |
reportEvery = 1000; |
78 |
< |
loggingVerbosity = 0; |
133 |
> |
float iso = gamma.neutralHadronIso; |
134 |
> |
iso = max(iso - rho*ea, (float)0.); |
135 |
|
|
136 |
+ |
return iso; |
137 |
|
} |
138 |
|
|
139 |
< |
TreeWriter::~TreeWriter() { |
140 |
< |
if (!inputTree) return; |
141 |
< |
delete inputTree->GetCurrentFile(); |
139 |
> |
float photonIso_corrected(const susy::Photon& gamma, float rho) { |
140 |
> |
float eta = fabs(gamma.caloPosition.Eta()); |
141 |
> |
float ea; |
142 |
> |
|
143 |
> |
if(eta < 1.0) ea = 0.148; |
144 |
> |
else if(eta < 1.479) ea = 0.130; |
145 |
> |
else if(eta < 2.0) ea = 0.112; |
146 |
> |
else if(eta < 2.2) ea = 0.216; |
147 |
> |
else if(eta < 2.3) ea = 0.262; |
148 |
> |
else if(eta < 2.4) ea = 0.260; |
149 |
> |
else ea = 0.266; |
150 |
> |
|
151 |
> |
float iso = gamma.photonIso; |
152 |
> |
iso = max(iso - rho*ea, (float)0.); |
153 |
> |
|
154 |
> |
return iso; |
155 |
|
} |
156 |
|
|
157 |
+ |
float d0correction( const susy::Electron& electron, const susy::Event& event ) { |
158 |
+ |
// copied from Brian Francis |
159 |
+ |
TVector3 beamspot = event.vertices[0].position; |
160 |
+ |
susy::Track track = event.tracks[electron.gsfTrackIndex]; |
161 |
+ |
float d0 = track.d0() - beamspot.X()*sin(track.phi()) + beamspot.Y()*cos(track.phi()); |
162 |
+ |
return d0; |
163 |
+ |
} |
164 |
+ |
|
165 |
+ |
float dZcorrection( const susy::Electron& electron, const susy::Event& event ) { |
166 |
+ |
// copied from Brian Francis |
167 |
+ |
TVector3 beamspot = event.vertices[0].position; |
168 |
+ |
susy::Track track = event.tracks[electron.gsfTrackIndex]; |
169 |
+ |
|
170 |
+ |
if(track.momentum.Pt() == 0.) return 1.e6; |
171 |
+ |
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()); |
172 |
+ |
return dz; |
173 |
+ |
} |
174 |
+ |
|
175 |
+ |
float getPtFromMatchedJet( const susy::Photon& myPhoton, const susy::PFJetCollection& jetColl, int loggingVerbosity = 0 ) { |
176 |
+ |
/** |
177 |
+ |
* \brief Takes jet p_T as photon p_T |
178 |
+ |
* |
179 |
+ |
* At first all jets with DeltaR < 0.3 (isolation cone) are searched. |
180 |
+ |
* If several jets are found, take the one with the minimal pt difference |
181 |
+ |
* compared to the photon. If no such jets are found, keep the photon_pt |
182 |
+ |
* TODO: remove photon matched jet from jet-selection? |
183 |
+ |
*/ |
184 |
+ |
std::vector<susy::PFJet> nearJets; |
185 |
+ |
nearJets.clear(); |
186 |
+ |
|
187 |
+ |
for(std::vector<susy::PFJet>::const_iterator it = jetColl.begin(); |
188 |
+ |
it != jetColl.end(); ++it) { |
189 |
+ |
float scale = 1.; |
190 |
+ |
std::map<TString,Float_t>::const_iterator s_it = it->jecScaleFactors.find("L2L3"); |
191 |
+ |
if (s_it == it->jecScaleFactors.end()) { |
192 |
+ |
std::cout << "JEC is not available for this jet!!!" << std::endl; |
193 |
+ |
continue; |
194 |
+ |
} else { |
195 |
+ |
scale = s_it->second; |
196 |
+ |
} |
197 |
+ |
TLorentzVector corrP4 = scale * it->momentum; |
198 |
+ |
float deltaR_ = deltaR(myPhoton.momentum, corrP4 ); |
199 |
+ |
if (deltaR_ > 0.3) continue; |
200 |
+ |
if( loggingVerbosity > 2 ) |
201 |
+ |
std::cout << " pT_jet / pT_gamma = " << it->momentum.Et() / myPhoton.momentum.Et() << std::endl; |
202 |
+ |
nearJets.push_back( *it ); |
203 |
+ |
}// for jet |
204 |
+ |
|
205 |
+ |
if ( nearJets.size() == 0 ) { |
206 |
+ |
if( loggingVerbosity > 1 ) |
207 |
+ |
std::cout << "No jet with deltaR < .3 found, do not change photon_pt" << std::endl; |
208 |
+ |
return myPhoton.momentum.Et(); |
209 |
+ |
} |
210 |
+ |
|
211 |
+ |
float pt = 0; |
212 |
+ |
float minPtDifferenz = 1E20; // should be very high |
213 |
+ |
for( std::vector<susy::PFJet>::iterator it = nearJets.begin(), jetEnd = nearJets.end(); |
214 |
+ |
it != jetEnd; ++it ) { |
215 |
+ |
float ptDiff = fabs(myPhoton.momentum.Et() - it->momentum.Et()); |
216 |
+ |
if ( ptDiff < minPtDifferenz ) { |
217 |
+ |
minPtDifferenz = ptDiff; |
218 |
+ |
pt = it->momentum.Et(); |
219 |
+ |
} |
220 |
+ |
} |
221 |
+ |
|
222 |
+ |
// testing |
223 |
+ |
if( nearJets.size() > 1 && loggingVerbosity > 0 ) |
224 |
+ |
std::cout << "There are several jets matching to this photon. " |
225 |
+ |
<< "Please check if jet-matching is correct." << std::endl; |
226 |
+ |
return pt; |
227 |
+ |
} |
228 |
+ |
|
229 |
+ |
|
230 |
|
void TreeWriter::Loop() { |
231 |
+ |
/** |
232 |
+ |
* \brief Loops over input chain and fills tree |
233 |
+ |
* |
234 |
+ |
* This is the major function of treeWriter, which initialize the output, loops |
235 |
+ |
* over all events and fill the tree. In the end, the tree is saved to the |
236 |
+ |
* output File |
237 |
+ |
*/ |
238 |
+ |
|
239 |
|
// here the event loop is implemented and the tree is filled |
240 |
|
if (inputTree == 0) return; |
241 |
|
|
242 |
|
// get number of events to be proceeded |
243 |
|
Long64_t nentries = inputTree->GetEntries(); |
244 |
+ |
// store them in histo |
245 |
+ |
eventNumbers->Fill( "Number of generated events", nentries ); |
246 |
|
if(processNEvents <= 0 || processNEvents > nentries) processNEvents = nentries; |
247 |
|
|
248 |
|
if( loggingVerbosity > 0 ) |
249 |
|
std::cout << "Processing " << processNEvents << " ouf of " |
250 |
|
<< nentries << " events. " << std::endl; |
251 |
|
|
99 |
– |
tree::Photon *thisphoton = new tree::Photon(); |
100 |
– |
tree::Jet *thisjet = new tree::Jet(); |
101 |
– |
|
252 |
|
tree->Branch("photon", &photon); |
253 |
|
tree->Branch("jet", &jet); |
254 |
+ |
tree->Branch("electron", &electron); |
255 |
+ |
tree->Branch("muon", &muon); |
256 |
|
tree->Branch("met", &met, "met/F"); |
257 |
+ |
tree->Branch("metPhi", &met_phi, "metPhi/F"); |
258 |
+ |
tree->Branch("type1met", &type1met, "type1met/F"); |
259 |
+ |
tree->Branch("type1metPhi", &type1met_phi, "type1metPhi/F"); |
260 |
+ |
tree->Branch("ht", &ht, "ht/F"); |
261 |
|
tree->Branch("nVertex", &nVertex, "nVertex/I"); |
262 |
< |
tree->Branch("weigth", &weight, "weight/F"); |
263 |
< |
|
262 |
> |
tree->Branch("weight", &weight, "weight/D"); |
263 |
> |
tree->Branch("genElectron", &genElectron); |
264 |
> |
tree->Branch("genPhoton", &genPhoton); |
265 |
|
|
266 |
< |
for (long jentry=0; jentry < processNEvents; jentry++) { |
267 |
< |
if (jentry%reportEvery==0) |
266 |
> |
for (unsigned long jentry=0; jentry < processNEvents; ++jentry) { |
267 |
> |
if ( loggingVerbosity>1 || jentry%reportEvery==0 ) |
268 |
|
std::cout << jentry << " / " << processNEvents << std :: endl; |
269 |
< |
inputTree->GetEntry(jentry); |
269 |
> |
inputTree->LoadTree( jentry ); |
270 |
> |
inputTree->GetEntry( jentry ); |
271 |
|
|
272 |
|
photon.clear(); |
273 |
|
jet.clear(); |
274 |
+ |
electron.clear(); |
275 |
+ |
muon.clear(); |
276 |
+ |
genElectron.clear(); |
277 |
+ |
genPhoton.clear(); |
278 |
+ |
ht = 0; |
279 |
+ |
|
280 |
+ |
// weights |
281 |
+ |
if (pileupHisto == 0) { |
282 |
+ |
weight = 1.; |
283 |
+ |
} else { |
284 |
+ |
float trueNumInteractions = -1; |
285 |
+ |
for( susy::PUSummaryInfoCollection::const_iterator iBX = event->pu.begin(); |
286 |
+ |
iBX != event->pu.end() && trueNumInteractions < 0; ++iBX) { |
287 |
+ |
if (iBX->BX == 0) |
288 |
+ |
trueNumInteractions = iBX->trueNumInteractions; |
289 |
+ |
} |
290 |
+ |
weight = pileupHisto->GetBinContent( pileupHisto->FindBin( trueNumInteractions ) ); |
291 |
+ |
} |
292 |
+ |
|
293 |
+ |
// get ak5 jets |
294 |
+ |
std::vector<susy::PFJet> jetVector = event->pfJets["ak5"]; |
295 |
|
|
296 |
|
// photons |
297 |
< |
std::map<TString, std::vector<susy::Photon> >::iterator phoMap = event->photons.find("photons"); |
298 |
< |
for(std::vector<susy::Photon>::iterator it = phoMap->second.begin(); |
299 |
< |
it != phoMap->second.end() && phoMap != event->photons.end(); it++ ) { |
300 |
< |
if( ! it->isEB() ) |
301 |
< |
continue; |
123 |
< |
thisphoton->pt = it->momentum.Et(); |
124 |
< |
if( thisphoton->pt < 80 ) |
297 |
> |
std::vector<susy::Photon> photonVector = event->photons["photons"]; |
298 |
> |
|
299 |
> |
for(std::vector<susy::Photon>::iterator it = photonVector.begin(); |
300 |
> |
it != photonVector.end(); ++it ) { |
301 |
> |
if( !(it->isEE() || it->isEB()) && it->momentum.Pt()<20 && it->isEBEtaGap() && it->isEBPhiGap() && it->isEERingGap() && it->isEEDeeGap() && it->isEBEEGap() && skim ) |
302 |
|
continue; |
303 |
< |
thisphoton->eta = it->momentum.Eta(); |
304 |
< |
thisphoton->chargedIso = it->chargedHadronIso; |
305 |
< |
thisphoton->neutralIso = it->neutralHadronIso; |
306 |
< |
thisphoton->photonIso = it->photonIso; |
307 |
< |
if ( it->r9 > 1 ) // if == 1 ? |
303 |
> |
tree::Photon thisphoton; |
304 |
> |
|
305 |
> |
thisphoton.chargedIso = chargedHadronIso_corrected(*it, event->rho25); |
306 |
> |
thisphoton.neutralIso = neutralHadronIso_corrected(*it, event->rho25); |
307 |
> |
thisphoton.photonIso = photonIso_corrected(*it, event->rho25); |
308 |
> |
|
309 |
> |
bool loose_photon_barrel = it->isEB() |
310 |
> |
&& it->hadTowOverEm<0.05 |
311 |
> |
&& it->sigmaIetaIeta<0.012 |
312 |
> |
&& thisphoton.chargedIso<2.6 |
313 |
> |
&& thisphoton.neutralIso<3.5+0.04*thisphoton.pt |
314 |
> |
&& thisphoton.photonIso<1.3+0.005*thisphoton.pt; |
315 |
> |
|
316 |
> |
bool loose_photon_endcap = it->isEE() |
317 |
> |
&& it->hadTowOverEm<0.05 |
318 |
> |
&& it->sigmaIetaIeta<0.034 |
319 |
> |
&& thisphoton.chargedIso<2.3 |
320 |
> |
&& thisphoton.neutralIso<2.9+0.04*thisphoton.pt; |
321 |
> |
|
322 |
> |
thisphoton.ptJet = getPtFromMatchedJet( *it, jetVector, loggingVerbosity ); |
323 |
> |
if(!(loose_photon_endcap || loose_photon_barrel || thisphoton.ptJet > 75 ) && skim ) |
324 |
|
continue; |
325 |
< |
thisphoton->r9 = it->r9; |
326 |
< |
thisphoton->sigmaIetaIeta = it->sigmaIetaIeta; |
327 |
< |
thisphoton->hadTowOverEm = it->hadTowOverEm; |
328 |
< |
thisphoton->pixelseed = it->nPixelSeeds; |
329 |
< |
photon.push_back( *thisphoton ); |
325 |
> |
thisphoton.pt = it->momentum.Pt(); |
326 |
> |
thisphoton.eta = it->momentum.Eta(); |
327 |
> |
thisphoton.phi = it->momentum.Phi(); |
328 |
> |
thisphoton.r9 = it->r9; |
329 |
> |
thisphoton.sigmaIetaIeta = it->sigmaIetaIeta; |
330 |
> |
thisphoton.hadTowOverEm = it->hadTowOverEm; |
331 |
> |
thisphoton.pixelseed = it->nPixelSeeds; |
332 |
> |
thisphoton.conversionSafeVeto = it->passelectronveto; |
333 |
> |
photon.push_back( thisphoton ); |
334 |
> |
if( loggingVerbosity > 2 ) |
335 |
> |
std::cout << " p_T, gamma = " << thisphoton.pt << std::endl; |
336 |
|
} |
337 |
< |
if( photon.size() == 0 ) |
337 |
> |
|
338 |
> |
if( photon.size() == 0 && skim ) |
339 |
|
continue; |
340 |
|
std::sort( photon.begin(), photon.end(), tree::EtGreater); |
341 |
< |
|
341 |
> |
if( loggingVerbosity > 1 ) |
342 |
> |
std::cout << "Found " << photon.size() << " photons" << std::endl; |
343 |
|
|
344 |
|
// jets |
144 |
– |
std::map<TString,susy::PFJetCollection>::iterator pfJets_it = event->pfJets.find("ak5"); |
145 |
– |
if(pfJets_it == event->pfJets.end()){ |
146 |
– |
if(event->pfJets.size() > 0) std::cout << "JetCollection is not available!!!" << std::endl; |
147 |
– |
} else { |
345 |
|
|
149 |
– |
susy::PFJetCollection& jetColl = pfJets_it->second; |
346 |
|
|
347 |
< |
for(std::vector<susy::PFJet>::iterator it = jetColl.begin(); |
348 |
< |
it != jetColl.end(); it++) { |
349 |
< |
std::map<TString,Float_t>::iterator s_it = it->jecScaleFactors.find("L2L3"); |
350 |
< |
if (s_it == it->jecScaleFactors.end()) { |
351 |
< |
std::cout << "JEC is not available for this jet!!!" << std::endl; |
352 |
< |
continue; |
353 |
< |
} |
354 |
< |
float scale = s_it->second; |
355 |
< |
TLorentzVector corrP4 = scale * it->momentum; |
347 |
> |
for(std::vector<susy::PFJet>::iterator it = jetVector.begin(); |
348 |
> |
it != jetVector.end(); ++it) { |
349 |
> |
tree::Jet thisjet; |
350 |
> |
|
351 |
> |
// scale with JEC |
352 |
> |
float scale = 1.; |
353 |
> |
if(it->jecScaleFactors.count("L2L3") == 0) |
354 |
> |
std::cout << "ERROR: JEC is not available for this jet" << std::endl; |
355 |
> |
else |
356 |
> |
scale = it->jecScaleFactors.find("L2L3")->second; |
357 |
> |
TLorentzVector corrP4 = scale * it->momentum; |
358 |
> |
|
359 |
> |
// Calculate HT. |
360 |
> |
// The definiton differs from the saved jet, since trigger is described better |
361 |
> |
if( std::abs( corrP4.Eta() ) < 3 && corrP4.Pt() > 40 ) |
362 |
> |
ht += thisjet.pt; |
363 |
> |
|
364 |
> |
if(std::abs(corrP4.Eta()) > 2.6 && skim ) continue; |
365 |
> |
if(corrP4.Pt() < 30 && skim ) continue; |
366 |
> |
thisjet.pt = corrP4.Pt(); |
367 |
> |
thisjet.eta = corrP4.Eta(); |
368 |
> |
thisjet.phi = corrP4.Phi(); |
369 |
> |
thisjet.bCSV = it->bTagDiscriminators[susy::kCSV]; |
370 |
> |
// jet composition |
371 |
> |
thisjet.chargedHadronEnergy = it->chargedHadronEnergy; |
372 |
> |
thisjet.neutralHadronEnergy = it->neutralHadronEnergy; |
373 |
> |
thisjet.photonEnergy = it->photonEnergy; |
374 |
> |
thisjet.electronEnergy = it->electronEnergy; |
375 |
> |
thisjet.muonEnergy = it->muonEnergy; |
376 |
> |
thisjet.HFHadronEnergy = it->HFHadronEnergy; |
377 |
> |
thisjet.HFEMEnergy = it->HFEMEnergy; |
378 |
> |
thisjet.chargedEmEnergy = it->chargedEmEnergy; |
379 |
> |
thisjet.chargedMuEnergy = it->chargedMuEnergy; |
380 |
> |
thisjet.neutralEmEnergy = it->neutralEmEnergy; |
381 |
> |
|
382 |
> |
if( loggingVerbosity > 2 ) |
383 |
> |
std::cout << " p_T, jet = " << thisjet.pt << std::endl; |
384 |
> |
|
385 |
> |
jet.push_back( thisjet ); |
386 |
> |
}// for jet |
387 |
> |
if( jet.size() < 2 && skim ) |
388 |
> |
continue; |
389 |
> |
std::sort( jet.begin(), jet.end(), tree::EtGreater); |
390 |
> |
if( loggingVerbosity > 1 ) |
391 |
> |
std::cout << "Found " << jet.size() << " jets" << std::endl; |
392 |
> |
|
393 |
> |
if( ht < 450 && skim) |
394 |
> |
continue; |
395 |
> |
|
396 |
|
|
161 |
– |
if(std::abs(corrP4.Eta()) > 3.0) continue; |
162 |
– |
thisjet->pt = corrP4.Et(); |
163 |
– |
thisjet->eta = corrP4.Eta(); |
164 |
– |
jet.push_back( *thisjet ); |
165 |
– |
}// for jet |
166 |
– |
}// if, else |
167 |
– |
if( jet.size() == 0 ) |
168 |
– |
std::cout << "error, no jets found " << std::endl; |
169 |
– |
else |
170 |
– |
std::sort( jet.begin(), jet.end(), tree::EtGreater); |
397 |
|
|
398 |
|
// met |
399 |
|
std::map<TString, susy::MET>::iterator met_it = event->metMap.find("pfMet"); |
400 |
|
susy::MET* metobj = &(met_it->second); |
401 |
|
met = metobj->met(); |
402 |
+ |
met_phi = metobj->mEt.Phi(); |
403 |
+ |
if( loggingVerbosity > 2 ) |
404 |
+ |
std::cout << " met = " << met << std::endl; |
405 |
+ |
|
406 |
+ |
std::map<TString, susy::MET>::iterator type1met_it = event->metMap.find("pfType1CorrectedMet"); |
407 |
+ |
susy::MET* type1metobj = &(type1met_it->second); |
408 |
+ |
type1met = type1metobj->met(); |
409 |
+ |
type1met_phi = type1metobj->mEt.Phi(); |
410 |
+ |
if( loggingVerbosity > 2 ) |
411 |
+ |
std::cout << " type1met = " << type1met << std::endl; |
412 |
+ |
|
413 |
+ |
// electrons |
414 |
+ |
std::vector<susy::Electron> eVector = event->electrons["gsfElectrons"]; |
415 |
+ |
for(std::vector<susy::Electron>::iterator it = eVector.begin(); it < eVector.end(); ++it) { |
416 |
+ |
tree::Particle thiselectron; |
417 |
+ |
if( loggingVerbosity > 2 ) |
418 |
+ |
cout << " electron pt = " << it->momentum.Pt() << endl; |
419 |
+ |
// for cuts see https://twiki.cern.ch/twiki/bin/viewauth/CMS/EgammaCutBasedIdentification |
420 |
+ |
// use veto electrons |
421 |
+ |
if( it->momentum.Pt() < 20 || it->momentum.Pt() > 1e6 ) |
422 |
+ |
continue; // spike rejection |
423 |
+ |
float iso = ( it->chargedHadronIso + max(it->neutralHadronIso+it->photonIso - effectiveAreaElectron(it->momentum.Eta())*event->rho25, (float)0. ) |
424 |
+ |
) / it->momentum.Pt(); |
425 |
+ |
float d0 = d0correction( *it, *event ); |
426 |
+ |
float dZ = std::abs( dZcorrection( *it, *event ) ); |
427 |
+ |
if ( it->isEB() ){ |
428 |
+ |
if ( fabs(it->deltaEtaSuperClusterTrackAtVtx) > 0.007 |
429 |
+ |
|| fabs(it->deltaPhiSuperClusterTrackAtVtx) > 0.8 |
430 |
+ |
|| it->sigmaIetaIeta > 0.01 |
431 |
+ |
|| it->hcalOverEcalBc > 0.15 |
432 |
+ |
|| d0 > 0.04 |
433 |
+ |
|| dZ > 0.2 |
434 |
+ |
|| iso > 0.15 ) |
435 |
+ |
continue; |
436 |
+ |
} |
437 |
+ |
else if( it->isEE() ) { |
438 |
+ |
if ( fabs(it->deltaEtaSuperClusterTrackAtVtx) > 0.01 |
439 |
+ |
|| fabs(it->deltaPhiSuperClusterTrackAtVtx) > 0.7 |
440 |
+ |
|| it->sigmaIetaIeta > 0.03 |
441 |
+ |
|| d0 > 0.04 |
442 |
+ |
|| dZ > 0.2 |
443 |
+ |
|| iso > 0.15 ) |
444 |
+ |
continue; |
445 |
+ |
} |
446 |
+ |
else // not in barrel nor in endcap |
447 |
+ |
continue; |
448 |
|
|
449 |
< |
// vertices |
449 |
> |
thiselectron.pt = it->momentum.Pt(); |
450 |
> |
if( loggingVerbosity > 2 ) |
451 |
> |
std::cout << " p_T, electron = " << it->momentum.Et() << std::endl; |
452 |
> |
thiselectron.eta = it->momentum.Eta(); |
453 |
> |
thiselectron.phi = it->momentum.Phi(); |
454 |
> |
electron.push_back( thiselectron ); |
455 |
> |
} |
456 |
> |
if( loggingVerbosity > 1 ) |
457 |
> |
std::cout << "Found " << electron.size() << " electrons" << std::endl; |
458 |
|
|
459 |
+ |
// muons |
460 |
+ |
tree::Particle thismuon; |
461 |
+ |
std::vector<susy::Muon> mVector = event->muons["muons"]; |
462 |
+ |
for( std::vector<susy::Muon>::iterator it = mVector.begin(); it != mVector.end(); ++it) { |
463 |
+ |
if( !( it->isPFMuon() && ( it->isGlobalMuon() || it->isTrackerMuon() ) ) ) |
464 |
+ |
continue; // see https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideMuonId#Loose_Muon |
465 |
+ |
thismuon.pt = it->momentum.Et(); |
466 |
+ |
if( thismuon.pt < 20 ) |
467 |
+ |
continue; |
468 |
+ |
thismuon.eta = it->momentum.Eta(); |
469 |
+ |
thismuon.phi = it->momentum.Phi(); |
470 |
+ |
muon.push_back( thismuon ); |
471 |
+ |
} |
472 |
+ |
if( loggingVerbosity > 1 ) |
473 |
+ |
std::cout << "Found " << muon.size() << " muons" << std::endl; |
474 |
+ |
|
475 |
+ |
// vertices |
476 |
|
nVertex = event->vertices.size(); |
477 |
< |
weight = 1; |
477 |
> |
|
478 |
> |
tree::Particle thisGenParticle; |
479 |
> |
for( std::vector<susy::Particle>::iterator it = event->genParticles.begin(); it != event->genParticles.end(); ++it ) { |
480 |
> |
if( it->momentum.Pt() < 20 ) continue; |
481 |
> |
thisGenParticle.pt = it->momentum.Pt(); |
482 |
> |
thisGenParticle.eta = it->momentum.Eta(); |
483 |
> |
thisGenParticle.phi = it->momentum.Phi(); |
484 |
> |
switch( std::abs(it->pdgId) ) { |
485 |
> |
case 22: // photon |
486 |
> |
genPhoton.push_back( thisGenParticle ); |
487 |
> |
break; |
488 |
> |
case 11: // electron |
489 |
> |
// Demand a W boson as mother particle of electron |
490 |
> |
if( abs(event->genParticles[it->motherIndex].pdgId) == 24 ) |
491 |
> |
genElectron.push_back( thisGenParticle ); |
492 |
> |
break; |
493 |
> |
} |
494 |
> |
} |
495 |
|
|
496 |
|
tree->Fill(); |
497 |
|
} // for jentry |
498 |
|
|
499 |
|
|
186 |
– |
|
187 |
– |
tree->Write(); |
500 |
|
outFile->cd(); |
501 |
+ |
eventNumbers->Write(); |
502 |
+ |
tree->Write(); |
503 |
|
outFile->Write(); |
504 |
|
outFile->Close(); |
505 |
|
} |
506 |
< |
/* |
193 |
< |
int main(int argc, char** argv) { |
194 |
< |
TreeWriter *tw = new TreeWriter("qcd-1000-nTuple-test.root", "myQCDTree.root"); |
195 |
< |
tw->SetProcessNEvents(10); |
196 |
< |
tw->Loop(); |
197 |
< |
} |
198 |
< |
*/ |
506 |
> |
|