source: trunk/MadWeight/Analysis.C@ 21

Last change on this file since 21 was 21, checked in by Pavel Demin, 16 years ago

fix AnalyseMissingET

  • Property svn:executable set to *
File size: 8.4 KB
Line 
1
2#include <iostream>
3#include <fstream>
4#include <sstream>
5#include <map>
6
7#include "TROOT.h"
8#include "TApplication.h"
9
10#include "TFile.h"
11#include "TChain.h"
12#include "TString.h"
13#include "TClonesArray.h"
14
15#include "TH2.h"
16#include "THStack.h"
17#include "TLegend.h"
18#include "TPaveText.h"
19#include "TLorentzVector.h"
20
21#include "ExRootAnalysis/ExRootClasses.h"
22
23#include "ExRootAnalysis/ExRootTreeReader.h"
24#include "ExRootAnalysis/ExRootTreeWriter.h"
25#include "ExRootAnalysis/ExRootTreeBranch.h"
26
27#include "ExRootAnalysis/ExRootUtilities.h"
28#include "ExRootAnalysis/ExRootProgressBar.h"
29
30using namespace std;
31
32//------------------------------------------------------------------------------
33
34class MadWeightAnalysis
35{
36public:
37 MadWeightAnalysis(ExRootTreeReader *treeReader,
38 ExRootTreeWriter *treeWriter);
39 ~MadWeightAnalysis();
40
41 void ProcessEvent();
42
43private:
44
45 void AnalyseEvent();
46
47 void AnalysePhotons();
48 void AnalyseElectrons();
49 void AnalyseMuons();
50 void AnalyseTaus();
51 void AnalyseJets();
52
53 void AnalyseMissingET();
54
55 Long64_t fTriggerWord, fEventNumber;
56
57 ExRootTreeReader *fTreeReader;
58 ExRootTreeWriter *fTreeWriter;
59
60 TClonesArray *fInputEvent;
61 TClonesArray *fInputPhoton;
62 TClonesArray *fInputElectron;
63 TClonesArray *fInputMuon;
64 TClonesArray *fInputTau;
65 TClonesArray *fInputJet;
66 TClonesArray *fInputMissingET;
67
68 TIterator *fItPhoton;
69 TIterator *fItElectron;
70 TIterator *fItMuon;
71 TIterator *fItTau;
72 TIterator *fItJet;
73
74 ExRootTreeBranch *fOutputEvent;
75 ExRootTreeBranch *fOutputPhoton;
76 ExRootTreeBranch *fOutputElectron;
77 ExRootTreeBranch *fOutputMuon;
78 ExRootTreeBranch *fOutputTau;
79 ExRootTreeBranch *fOutputJet;
80 ExRootTreeBranch *fOutputMissingET;
81};
82
83//------------------------------------------------------------------------------
84
85MadWeightAnalysis::MadWeightAnalysis(ExRootTreeReader *treeReader,
86 ExRootTreeWriter *treeWriter) :
87 fTriggerWord(0), fEventNumber(1), fTreeReader(0), fTreeWriter(0)
88{
89 fTreeReader = treeReader;
90 fTreeWriter = treeWriter;
91
92 // information about reconstructed event
93 fInputEvent = fTreeReader->UseBranch("Event");
94 // reconstructed photons
95 fInputPhoton = fTreeReader->UseBranch("Photon");
96 fItPhoton = fInputPhoton->MakeIterator();
97 // reconstructed electrons
98 fInputElectron = fTreeReader->UseBranch("Electron");
99 fItElectron = fInputElectron->MakeIterator();
100 // reconstructed muons
101 fInputMuon = fTreeReader->UseBranch("Muon");
102 fItMuon = fInputMuon->MakeIterator();
103 // reconstructed hadronically-decaying tau leptons
104 fInputTau = fTreeReader->UseBranch("Tau");
105 fItTau = fInputTau->MakeIterator();
106 // reconstructed jets
107 fInputJet = fTreeReader->UseBranch("Jet");
108 fItJet = fInputJet->MakeIterator();
109 // missing transverse energy
110 fInputMissingET = fTreeReader->UseBranch("MissingET");
111
112
113 // information about reconstructed event
114 fOutputEvent = fTreeWriter->NewBranch("Event", ExRootEvent::Class());
115 // reconstructed photons
116 fOutputPhoton = fTreeWriter->NewBranch("Photon", ExRootPhoton::Class());
117 // reconstructed electrons
118 fOutputElectron = fTreeWriter->NewBranch("Electron", ExRootElectron::Class());
119 // reconstructed muons
120 fOutputMuon = fTreeWriter->NewBranch("Muon", ExRootMuon::Class());
121 // reconstructed hadronically-decaying tau leptons
122 fOutputTau = fTreeWriter->NewBranch("Tau", ExRootTau::Class());
123 // reconstructed jets
124 fOutputJet = fTreeWriter->NewBranch("Jet", ExRootJet::Class());
125 // missing transverse energy
126 fOutputMissingET = fTreeWriter->NewBranch("MissingET", ExRootMissingET::Class());
127
128}
129
130//------------------------------------------------------------------------------
131
132MadWeightAnalysis::~MadWeightAnalysis()
133{
134}
135
136//---------------------------------------------------------------------------
137
138void MadWeightAnalysis::ProcessEvent()
139{
140 AnalyseEvent();
141
142 AnalysePhotons();
143 AnalyseElectrons();
144 AnalyseMuons();
145 AnalyseTaus();
146 AnalyseJets();
147
148 AnalyseMissingET();
149}
150
151//---------------------------------------------------------------------------
152
153void MadWeightAnalysis::AnalyseEvent()
154{
155 ExRootEvent *input, *output;
156
157 input = static_cast<ExRootEvent*>(fInputEvent->At(0));
158
159 output = static_cast<ExRootEvent*>(fOutputEvent->NewEntry());
160
161 *output = *input;
162
163}
164
165//---------------------------------------------------------------------------
166
167void MadWeightAnalysis::AnalysePhotons()
168{
169 ExRootPhoton *input, *output;
170
171 fItPhoton->Reset();
172 while((input = static_cast<ExRootPhoton*>(fItPhoton->Next())))
173 {
174 // Example: select central photons
175 if(TMath::Abs(input->Eta) < 1.0)
176 {
177 output = static_cast<ExRootPhoton*>(fOutputPhoton->NewEntry());
178
179 *output = *input;
180 }
181 }
182}
183
184//---------------------------------------------------------------------------
185
186void MadWeightAnalysis::AnalyseElectrons()
187{
188 ExRootElectron *input, *output;
189
190 fItElectron->Reset();
191 while((input = static_cast<ExRootElectron*>(fItElectron->Next())))
192 {
193 // Example: select central electrons
194 if(TMath::Abs(input->Eta) < 1.0)
195 {
196 output = static_cast<ExRootElectron*>(fOutputElectron->NewEntry());
197
198 *output = *input;
199 }
200 }
201}
202
203//---------------------------------------------------------------------------
204
205void MadWeightAnalysis::AnalyseMuons()
206{
207 ExRootMuon *input, *output;
208
209 fItMuon->Reset();
210 while((input = static_cast<ExRootMuon*>(fItMuon->Next())))
211 {
212 // Example: select central muons
213 if(TMath::Abs(input->Eta) < 1.0)
214 {
215 output = static_cast<ExRootMuon*>(fOutputMuon->NewEntry());
216
217 *output = *input;
218 }
219 }
220}
221
222//---------------------------------------------------------------------------
223
224void MadWeightAnalysis::AnalyseTaus()
225{
226 ExRootTau *input, *output;
227
228 fItTau->Reset();
229 while((input = static_cast<ExRootTau*>(fItTau->Next())))
230 {
231 // Example: select central taus
232 if(TMath::Abs(input->Eta) < 1.0)
233 {
234 output = static_cast<ExRootTau*>(fOutputTau->NewEntry());
235
236 *output = *input;
237 }
238 }
239}
240
241//---------------------------------------------------------------------------
242
243void MadWeightAnalysis::AnalyseJets()
244{
245 ExRootJet *input, *output;
246
247 fItJet->Reset();
248 while((input = static_cast<ExRootJet*>(fItJet->Next())))
249 {
250 // Example: select central jets
251 if(TMath::Abs(input->Eta) < 1.0)
252 {
253 output = static_cast<ExRootJet*>(fOutputJet->NewEntry());
254
255 *output = *input;
256 }
257 }
258}
259
260//---------------------------------------------------------------------------
261
262void MadWeightAnalysis::AnalyseMissingET()
263{
264 ExRootMissingET *input, *output;
265
266 if(fInputMissingET->GetEntriesFast() > 0)
267 {
268 input = static_cast<ExRootMissingET*>(fInputMissingET->At(0));
269
270
271 output = static_cast<ExRootMissingET*>(fOutputMissingET->NewEntry());
272
273 *output = *input;
274 }
275}
276
277//---------------------------------------------------------------------------
278
279void Analysis(const char *inputFileName, const char *outputFileName)
280{
281 TChain *chain = new TChain("LHCO");
282 chain->Add(inputFileName);
283
284 ExRootTreeReader *treeReader = new ExRootTreeReader(chain);
285
286 cout << "** Calculating number of events to process. Please wait..." << endl;
287 Long64_t allEntries = treeReader->GetEntries();
288 cout << "** Input file contains " << allEntries << " events" << endl;
289
290 Long64_t entry;
291
292 if(allEntries > 0)
293 {
294 // Create ROOT tree writer:
295 TFile *outputFile = TFile::Open(outputFileName, "RECREATE");
296 ExRootTreeWriter *treeWriter = new ExRootTreeWriter(outputFile, "LHCO");
297
298 // Create analysis object:
299 MadWeightAnalysis *analysis = new MadWeightAnalysis(treeReader, treeWriter);
300
301 ExRootProgressBar progressBar(allEntries);
302 // Loop over all events
303 for(entry = 0; entry < allEntries; ++entry)
304 {
305 if(!treeReader->ReadEntry(entry))
306 {
307 cout << "** ERROR: cannot read event " << entry << endl;
308 break;
309 }
310
311 treeWriter->Clear();
312
313 analysis->ProcessEvent();
314
315 treeWriter->Fill();
316
317 progressBar.Update(entry);
318 }
319 progressBar.Finish();
320
321 treeWriter->Write();
322
323 delete analysis;
324 delete treeWriter;
325 }
326
327 cout << "** Exiting..." << endl;
328
329 delete treeReader;
330 delete chain;
331}
332
333
Note: See TracBrowser for help on using the repository browser.