1 |
kiesel |
1.2 |
#include<iostream>
|
2 |
kiesel |
1.4 |
#include<math.h>
|
3 |
kiesel |
1.2 |
|
4 |
kiesel |
1.5 |
#include "TSystem.h"
|
5 |
|
|
|
6 |
|
|
#include "treeWriter.h"
|
7 |
|
|
|
8 |
|
|
using namespace std;
|
9 |
kiesel |
1.1 |
|
10 |
kiesel |
1.6 |
TreeWriter::TreeWriter(TString inputName, TString outputName, int loggingVerbosity_ ) {
|
11 |
kiesel |
1.1 |
// read the input file
|
12 |
kiesel |
1.5 |
inputTree = new TChain("susyTree");
|
13 |
kiesel |
1.6 |
if (loggingVerbosity_ > 0)
|
14 |
|
|
std::cout << "Add files to chain" << std::endl;
|
15 |
kiesel |
1.5 |
inputTree->Add( inputName );
|
16 |
|
|
|
17 |
kiesel |
1.6 |
if (loggingVerbosity_ > 0)
|
18 |
|
|
std::cout << "Set Branch Address of susy::Event" << std::endl;
|
19 |
kiesel |
1.1 |
event = new susy::Event;
|
20 |
|
|
inputTree->SetBranchAddress("susyEvent", &event);
|
21 |
|
|
|
22 |
|
|
// open the output file
|
23 |
|
|
outFile = new TFile( outputName, "recreate" );
|
24 |
|
|
tree = new TTree("susyTree","Tree for single photon analysis");
|
25 |
|
|
|
26 |
|
|
// set default parameter
|
27 |
|
|
processNEvents = -1;
|
28 |
|
|
reportEvery = 1000;
|
29 |
kiesel |
1.6 |
loggingVerbosity = loggingVerbosity_;
|
30 |
kiesel |
1.5 |
skim = true;
|
31 |
kiesel |
1.1 |
|
32 |
|
|
}
|
33 |
|
|
|
34 |
|
|
TreeWriter::~TreeWriter() {
|
35 |
|
|
if (!inputTree) return;
|
36 |
|
|
delete inputTree->GetCurrentFile();
|
37 |
|
|
}
|
38 |
|
|
|
39 |
kiesel |
1.4 |
float TreeWriter::deltaR( TLorentzVector v1, TLorentzVector v2 ) {
|
40 |
|
|
return sqrt(pow(v1.Eta() - v2.Eta(), 2) + pow(v1.Phi() - v2.Phi(), 2) );
|
41 |
|
|
}
|
42 |
|
|
|
43 |
kiesel |
1.5 |
float TreeWriter::getPtFromMatchedJet( susy::Photon myPhoton, susy::Event myEvent ) {
|
44 |
kiesel |
1.4 |
/**
|
45 |
|
|
* \brief Takes jet p_T as photon p_T
|
46 |
|
|
*
|
47 |
|
|
* At first all jets with DeltaR < 0.3 (isolation cone) are searched.
|
48 |
|
|
* If several jets are found, take the one with the minimal pt difference
|
49 |
kiesel |
1.5 |
* compared to the photon. If no such jets are found, keep the photon_pt
|
50 |
kiesel |
1.4 |
* TODO: remove photon matched jet from jet-selection?
|
51 |
|
|
*/
|
52 |
|
|
std::vector<susy::PFJet> nearJets;
|
53 |
|
|
nearJets.clear();
|
54 |
|
|
|
55 |
kiesel |
1.5 |
std::map<TString,susy::PFJetCollection>::iterator pfJets_it = myEvent.pfJets.find("ak5");
|
56 |
|
|
if(pfJets_it == myEvent.pfJets.end()){
|
57 |
|
|
if(myEvent.pfJets.size() > 0) std::cout << "JetCollection is not available!!!" << std::endl;
|
58 |
kiesel |
1.4 |
} else {
|
59 |
|
|
susy::PFJetCollection& jetColl = pfJets_it->second;
|
60 |
|
|
for(std::vector<susy::PFJet>::iterator it = jetColl.begin();
|
61 |
|
|
it != jetColl.end(); it++) {
|
62 |
|
|
std::map<TString,Float_t>::iterator s_it = it->jecScaleFactors.find("L2L3");
|
63 |
|
|
if (s_it == it->jecScaleFactors.end()) {
|
64 |
|
|
std::cout << "JEC is not available for this jet!!!" << std::endl;
|
65 |
|
|
continue;
|
66 |
|
|
}
|
67 |
|
|
float scale = s_it->second;
|
68 |
|
|
TLorentzVector corrP4 = scale * it->momentum;
|
69 |
kiesel |
1.5 |
float deltaR_ = deltaR(myPhoton.momentum, corrP4 );
|
70 |
kiesel |
1.4 |
if (deltaR_ > 0.3) continue;
|
71 |
kiesel |
1.5 |
if( loggingVerbosity > 0 )
|
72 |
|
|
std::cout << "gamma pt jet matching factor = " << it->momentum.Et() / myPhoton.momentum.Et() << std::endl;
|
73 |
kiesel |
1.4 |
nearJets.push_back( *it );
|
74 |
|
|
}// for jet
|
75 |
|
|
}// if, else
|
76 |
|
|
|
77 |
|
|
if ( nearJets.size() == 0 ) {
|
78 |
kiesel |
1.5 |
//std::cout << "No jet with deltaR < .3 found, do not change photon_pt" << std::endl;
|
79 |
|
|
return myPhoton.momentum.Et();
|
80 |
kiesel |
1.4 |
}
|
81 |
|
|
|
82 |
|
|
float pt = 0;
|
83 |
|
|
float minPtDifferenz = 1E20; // should be very high
|
84 |
|
|
for( std::vector<susy::PFJet>::iterator it = nearJets.begin(), jetEnd = nearJets.end();
|
85 |
|
|
it != jetEnd; it++ ) {
|
86 |
kiesel |
1.5 |
float ptDiff = fabs(myPhoton.momentum.Et() - it->momentum.Et());
|
87 |
kiesel |
1.4 |
if ( ptDiff < minPtDifferenz ) {
|
88 |
|
|
minPtDifferenz = ptDiff;
|
89 |
|
|
pt = it->momentum.Et();
|
90 |
|
|
}
|
91 |
|
|
}
|
92 |
|
|
|
93 |
|
|
// testing
|
94 |
kiesel |
1.6 |
if( nearJets.size() > 1 && loggingVerbosity > 0 )
|
95 |
kiesel |
1.4 |
std::cout << "There are several jets matching to this photon. "
|
96 |
kiesel |
1.6 |
<< "Please check if jet-matching is correct." << std::endl;
|
97 |
kiesel |
1.4 |
return pt;
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
|
101 |
kiesel |
1.1 |
void TreeWriter::Loop() {
|
102 |
kiesel |
1.4 |
|
103 |
kiesel |
1.1 |
// here the event loop is implemented and the tree is filled
|
104 |
|
|
if (inputTree == 0) return;
|
105 |
|
|
|
106 |
|
|
// get number of events to be proceeded
|
107 |
|
|
Long64_t nentries = inputTree->GetEntries();
|
108 |
|
|
if(processNEvents <= 0 || processNEvents > nentries) processNEvents = nentries;
|
109 |
|
|
|
110 |
|
|
if( loggingVerbosity > 0 )
|
111 |
|
|
std::cout << "Processing " << processNEvents << " ouf of "
|
112 |
|
|
<< nentries << " events. " << std::endl;
|
113 |
|
|
|
114 |
|
|
tree::Photon *thisphoton = new tree::Photon();
|
115 |
|
|
tree::Jet *thisjet = new tree::Jet();
|
116 |
|
|
|
117 |
|
|
tree->Branch("photon", &photon);
|
118 |
|
|
tree->Branch("jet", &jet);
|
119 |
|
|
tree->Branch("met", &met, "met/F");
|
120 |
kiesel |
1.5 |
tree->Branch("ht", &ht, "ht/F");
|
121 |
kiesel |
1.1 |
tree->Branch("nVertex", &nVertex, "nVertex/I");
|
122 |
kiesel |
1.4 |
tree->Branch("nElectron", &nElectron, "nElectron/I");
|
123 |
kiesel |
1.1 |
|
124 |
|
|
|
125 |
|
|
for (long jentry=0; jentry < processNEvents; jentry++) {
|
126 |
kiesel |
1.4 |
if ( loggingVerbosity>0 && jentry%reportEvery==0 )
|
127 |
kiesel |
1.1 |
std::cout << jentry << " / " << processNEvents << std :: endl;
|
128 |
|
|
inputTree->GetEntry(jentry);
|
129 |
|
|
|
130 |
|
|
photon.clear();
|
131 |
|
|
jet.clear();
|
132 |
kiesel |
1.5 |
ht = 0;
|
133 |
kiesel |
1.1 |
|
134 |
|
|
// photons
|
135 |
kiesel |
1.5 |
if( loggingVerbosity > 1 )
|
136 |
kiesel |
1.6 |
std::cout << "Process photons" << std::endl;
|
137 |
kiesel |
1.1 |
std::map<TString, std::vector<susy::Photon> >::iterator phoMap = event->photons.find("photons");
|
138 |
|
|
for(std::vector<susy::Photon>::iterator it = phoMap->second.begin();
|
139 |
|
|
it != phoMap->second.end() && phoMap != event->photons.end(); it++ ) {
|
140 |
kiesel |
1.4 |
if( ! it->isEB() && skim )
|
141 |
kiesel |
1.1 |
continue;
|
142 |
kiesel |
1.4 |
thisphoton->pt = getPtFromMatchedJet( *it, *event );
|
143 |
|
|
if( thisphoton->pt < 80 && skim )
|
144 |
kiesel |
1.1 |
continue;
|
145 |
|
|
thisphoton->eta = it->momentum.Eta();
|
146 |
kiesel |
1.4 |
thisphoton->phi = it->momentum.Phi();
|
147 |
kiesel |
1.1 |
thisphoton->chargedIso = it->chargedHadronIso;
|
148 |
|
|
thisphoton->neutralIso = it->neutralHadronIso;
|
149 |
|
|
thisphoton->photonIso = it->photonIso;
|
150 |
kiesel |
1.4 |
if ( it->r9 > 1 && skim ) // if == 1 ?
|
151 |
kiesel |
1.1 |
continue;
|
152 |
|
|
thisphoton->r9 = it->r9;
|
153 |
|
|
thisphoton->sigmaIetaIeta = it->sigmaIetaIeta;
|
154 |
|
|
thisphoton->hadTowOverEm = it->hadTowOverEm;
|
155 |
|
|
thisphoton->pixelseed = it->nPixelSeeds;
|
156 |
|
|
photon.push_back( *thisphoton );
|
157 |
kiesel |
1.5 |
ht += thisphoton->pt;
|
158 |
|
|
if( loggingVerbosity > 2 )
|
159 |
kiesel |
1.6 |
std::cout << " p_T, gamma = " << thisphoton->pt << std::endl;
|
160 |
kiesel |
1.1 |
}
|
161 |
kiesel |
1.5 |
|
162 |
kiesel |
1.4 |
if( photon.size() == 0 && skim )
|
163 |
kiesel |
1.1 |
continue;
|
164 |
|
|
std::sort( photon.begin(), photon.end(), tree::EtGreater);
|
165 |
kiesel |
1.5 |
if( loggingVerbosity > 1 )
|
166 |
|
|
std::cout << "Found " << photon.size() << " photons" << std::endl;
|
167 |
kiesel |
1.1 |
|
168 |
|
|
// jets
|
169 |
|
|
std::map<TString,susy::PFJetCollection>::iterator pfJets_it = event->pfJets.find("ak5");
|
170 |
|
|
if(pfJets_it == event->pfJets.end()){
|
171 |
|
|
if(event->pfJets.size() > 0) std::cout << "JetCollection is not available!!!" << std::endl;
|
172 |
|
|
} else {
|
173 |
|
|
|
174 |
|
|
susy::PFJetCollection& jetColl = pfJets_it->second;
|
175 |
|
|
|
176 |
|
|
for(std::vector<susy::PFJet>::iterator it = jetColl.begin();
|
177 |
|
|
it != jetColl.end(); it++) {
|
178 |
|
|
std::map<TString,Float_t>::iterator s_it = it->jecScaleFactors.find("L2L3");
|
179 |
|
|
if (s_it == it->jecScaleFactors.end()) {
|
180 |
|
|
std::cout << "JEC is not available for this jet!!!" << std::endl;
|
181 |
|
|
continue;
|
182 |
|
|
}
|
183 |
|
|
float scale = s_it->second;
|
184 |
|
|
TLorentzVector corrP4 = scale * it->momentum;
|
185 |
|
|
|
186 |
kiesel |
1.4 |
if(std::abs(corrP4.Eta()) > 3.0 && skim ) continue;
|
187 |
kiesel |
1.1 |
thisjet->pt = corrP4.Et();
|
188 |
|
|
thisjet->eta = corrP4.Eta();
|
189 |
kiesel |
1.4 |
thisjet->phi = corrP4.Phi();
|
190 |
kiesel |
1.1 |
jet.push_back( *thisjet );
|
191 |
kiesel |
1.5 |
ht += thisjet->pt;
|
192 |
kiesel |
1.1 |
}// for jet
|
193 |
|
|
}// if, else
|
194 |
kiesel |
1.4 |
if( jet.size() < 2 && skim )
|
195 |
|
|
continue;
|
196 |
|
|
std::sort( jet.begin(), jet.end(), tree::EtGreater);
|
197 |
kiesel |
1.1 |
|
198 |
|
|
// met
|
199 |
|
|
std::map<TString, susy::MET>::iterator met_it = event->metMap.find("pfMet");
|
200 |
|
|
susy::MET* metobj = &(met_it->second);
|
201 |
|
|
met = metobj->met();
|
202 |
|
|
|
203 |
kiesel |
1.4 |
// electrons
|
204 |
kiesel |
1.5 |
//std::vector<susy::Electron> eVector = event->electrons["gsfElectrons"];
|
205 |
|
|
//nElectron = eVector.size();
|
206 |
kiesel |
1.4 |
|
207 |
kiesel |
1.1 |
// vertices
|
208 |
|
|
|
209 |
|
|
nVertex = event->vertices.size();
|
210 |
|
|
|
211 |
kiesel |
1.5 |
if( ht < 450 && skim)
|
212 |
|
|
continue;
|
213 |
kiesel |
1.4 |
|
214 |
kiesel |
1.1 |
tree->Fill();
|
215 |
|
|
} // for jentry
|
216 |
|
|
|
217 |
|
|
|
218 |
|
|
|
219 |
|
|
tree->Write();
|
220 |
|
|
outFile->cd();
|
221 |
|
|
outFile->Write();
|
222 |
|
|
outFile->Close();
|
223 |
|
|
}
|
224 |
kiesel |
1.3 |
|