1 |
kiesel |
1.1 |
#include "TFile.h"
|
2 |
|
|
#include "TTree.h"
|
3 |
|
|
#include "TString.h"
|
4 |
|
|
#include "TLorentzVector.h"
|
5 |
|
|
|
6 |
|
|
#include "SusyEvent.h"
|
7 |
|
|
|
8 |
|
|
|
9 |
|
|
namespace tree {
|
10 |
|
|
// In this namespace classes for the trees are defined.
|
11 |
|
|
|
12 |
|
|
class Particle {
|
13 |
|
|
public:
|
14 |
|
|
float pt, eta, phi;
|
15 |
|
|
};
|
16 |
|
|
|
17 |
|
|
class Photon : public Particle {
|
18 |
|
|
public:
|
19 |
|
|
float r9, sigmaIetaIeta, hadTowOverEm, pixelseed;
|
20 |
|
|
float chargedIso, neutralIso, photonIso;
|
21 |
|
|
};
|
22 |
|
|
|
23 |
|
|
class Jet : public Particle{
|
24 |
|
|
public:
|
25 |
|
|
float pt, eta;
|
26 |
|
|
};
|
27 |
|
|
|
28 |
|
|
bool EtGreater(const tree::Particle p1, const tree::Particle p2) {
|
29 |
|
|
return p1.pt > p2.pt;
|
30 |
|
|
}
|
31 |
|
|
|
32 |
|
|
} // end namespace definition
|
33 |
|
|
|
34 |
|
|
class TreeWriter {
|
35 |
|
|
public :
|
36 |
|
|
TreeWriter(TString inputName, TString outputName );
|
37 |
|
|
virtual ~TreeWriter();
|
38 |
|
|
virtual void Loop();
|
39 |
|
|
|
40 |
|
|
void SetProcessNEvents(int nEvents) { processNEvents = nEvents; }
|
41 |
|
|
void SetReportEvents(int nEvents) { reportEvery = nEvents; }
|
42 |
|
|
|
43 |
|
|
TFile *inputFile;
|
44 |
|
|
TTree *inputTree;
|
45 |
|
|
susy::Event *event;
|
46 |
|
|
|
47 |
|
|
TFile *outFile;
|
48 |
|
|
TTree *tree;
|
49 |
|
|
|
50 |
|
|
private:
|
51 |
|
|
int processNEvents; // number of events to be processed
|
52 |
|
|
int reportEvery;
|
53 |
|
|
int loggingVerbosity;
|
54 |
|
|
|
55 |
|
|
// variables which will be stored in the tree
|
56 |
|
|
std::vector<tree::Photon> photon;
|
57 |
|
|
std::vector<tree::Jet> jet;
|
58 |
|
|
float met;
|
59 |
|
|
int nVertex;
|
60 |
|
|
float weight;
|
61 |
|
|
};
|
62 |
|
|
|
63 |
|
|
|
64 |
|
|
TreeWriter::TreeWriter(TString inputName, TString outputName) {
|
65 |
|
|
// 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);
|
70 |
|
|
|
71 |
|
|
// open the output file
|
72 |
|
|
outFile = new TFile( outputName, "recreate" );
|
73 |
|
|
tree = new TTree("susyTree","Tree for single photon analysis");
|
74 |
|
|
|
75 |
|
|
// set default parameter
|
76 |
|
|
processNEvents = -1;
|
77 |
|
|
reportEvery = 1000;
|
78 |
|
|
loggingVerbosity = 0;
|
79 |
|
|
|
80 |
|
|
}
|
81 |
|
|
|
82 |
|
|
TreeWriter::~TreeWriter() {
|
83 |
|
|
if (!inputTree) return;
|
84 |
|
|
delete inputTree->GetCurrentFile();
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
void TreeWriter::Loop() {
|
88 |
|
|
// here the event loop is implemented and the tree is filled
|
89 |
|
|
if (inputTree == 0) return;
|
90 |
|
|
|
91 |
|
|
// get number of events to be proceeded
|
92 |
|
|
Long64_t nentries = inputTree->GetEntries();
|
93 |
|
|
if(processNEvents <= 0 || processNEvents > nentries) processNEvents = nentries;
|
94 |
|
|
|
95 |
|
|
if( loggingVerbosity > 0 )
|
96 |
|
|
std::cout << "Processing " << processNEvents << " ouf of "
|
97 |
|
|
<< nentries << " events. " << std::endl;
|
98 |
|
|
|
99 |
|
|
tree::Photon *thisphoton = new tree::Photon();
|
100 |
|
|
tree::Jet *thisjet = new tree::Jet();
|
101 |
|
|
|
102 |
|
|
tree->Branch("photon", &photon);
|
103 |
|
|
tree->Branch("jet", &jet);
|
104 |
|
|
tree->Branch("met", &met, "met/F");
|
105 |
|
|
tree->Branch("nVertex", &nVertex, "nVertex/I");
|
106 |
|
|
tree->Branch("weigth", &weight, "weight/F");
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
for (long jentry=0; jentry < processNEvents; jentry++) {
|
110 |
|
|
if (jentry%reportEvery==0)
|
111 |
|
|
std::cout << jentry << " / " << processNEvents << std :: endl;
|
112 |
|
|
inputTree->GetEntry(jentry);
|
113 |
|
|
|
114 |
|
|
photon.clear();
|
115 |
|
|
jet.clear();
|
116 |
|
|
|
117 |
|
|
// photons
|
118 |
|
|
std::map<TString, std::vector<susy::Photon> >::iterator phoMap = event->photons.find("photons");
|
119 |
|
|
for(std::vector<susy::Photon>::iterator it = phoMap->second.begin();
|
120 |
|
|
it != phoMap->second.end() && phoMap != event->photons.end(); it++ ) {
|
121 |
|
|
if( ! it->isEB() )
|
122 |
|
|
continue;
|
123 |
|
|
thisphoton->pt = it->momentum.Et();
|
124 |
|
|
if( thisphoton->pt < 80 )
|
125 |
|
|
continue;
|
126 |
|
|
thisphoton->eta = it->momentum.Eta();
|
127 |
|
|
thisphoton->chargedIso = it->chargedHadronIso;
|
128 |
|
|
thisphoton->neutralIso = it->neutralHadronIso;
|
129 |
|
|
thisphoton->photonIso = it->photonIso;
|
130 |
|
|
if ( it->r9 > 1 ) // if == 1 ?
|
131 |
|
|
continue;
|
132 |
|
|
thisphoton->r9 = it->r9;
|
133 |
|
|
thisphoton->sigmaIetaIeta = it->sigmaIetaIeta;
|
134 |
|
|
thisphoton->hadTowOverEm = it->hadTowOverEm;
|
135 |
|
|
thisphoton->pixelseed = it->nPixelSeeds;
|
136 |
|
|
photon.push_back( *thisphoton );
|
137 |
|
|
}
|
138 |
|
|
if( photon.size() == 0 )
|
139 |
|
|
continue;
|
140 |
|
|
std::sort( photon.begin(), photon.end(), tree::EtGreater);
|
141 |
|
|
|
142 |
|
|
|
143 |
|
|
// 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 {
|
148 |
|
|
|
149 |
|
|
susy::PFJetCollection& jetColl = pfJets_it->second;
|
150 |
|
|
|
151 |
|
|
for(std::vector<susy::PFJet>::iterator it = jetColl.begin();
|
152 |
|
|
it != jetColl.end(); it++) {
|
153 |
|
|
std::map<TString,Float_t>::iterator s_it = it->jecScaleFactors.find("L2L3");
|
154 |
|
|
if (s_it == it->jecScaleFactors.end()) {
|
155 |
|
|
std::cout << "JEC is not available for this jet!!!" << std::endl;
|
156 |
|
|
continue;
|
157 |
|
|
}
|
158 |
|
|
float scale = s_it->second;
|
159 |
|
|
TLorentzVector corrP4 = scale * it->momentum;
|
160 |
|
|
|
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);
|
171 |
|
|
|
172 |
|
|
// met
|
173 |
|
|
std::map<TString, susy::MET>::iterator met_it = event->metMap.find("pfMet");
|
174 |
|
|
susy::MET* metobj = &(met_it->second);
|
175 |
|
|
met = metobj->met();
|
176 |
|
|
|
177 |
|
|
// vertices
|
178 |
|
|
|
179 |
|
|
nVertex = event->vertices.size();
|
180 |
|
|
weight = 1;
|
181 |
|
|
|
182 |
|
|
tree->Fill();
|
183 |
|
|
} // for jentry
|
184 |
|
|
|
185 |
|
|
|
186 |
|
|
|
187 |
|
|
tree->Write();
|
188 |
|
|
outFile->cd();
|
189 |
|
|
outFile->Write();
|
190 |
|
|
outFile->Close();
|
191 |
|
|
}
|
192 |
|
|
/*
|
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 |
|
|
*/
|