source: trunk/MadWeight/Analysis.C@ 20

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

first commit of working code

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