Fork me on GitHub

source: git/readers/DelphesROOT.cpp@ 3873449

ImprovedOutputFile Timing dual_readout llp
Last change on this file since 3873449 was 3873449, checked in by Michele Selvaggi <michele.selvaggi@…>, 8 years ago

added DelphesROOT reader

  • Property mode set to 100644
File size: 7.4 KB
Line 
1/*
2 * Delphes: a framework for fast simulation of a generic collider experiment
3 * Copyright (C) 2012-2014 Universite catholique de Louvain (UCL), Belgium
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <algorithm>
20#include <stdexcept>
21#include <iostream>
22#include <sstream>
23#include <memory>
24
25#include <map>
26#include <vector>
27
28#include <stdlib.h>
29#include <signal.h>
30#include <stdio.h>
31
32#include "TROOT.h"
33#include "TApplication.h"
34
35#include "TFile.h"
36#include "TClonesArray.h"
37#include "TObjArray.h"
38#include "TStopwatch.h"
39#include "TDatabasePDG.h"
40#include "TParticlePDG.h"
41#include "TLorentzVector.h"
42
43#include "modules/Delphes.h"
44#include "classes/DelphesStream.h"
45#include "classes/DelphesClasses.h"
46#include "classes/DelphesFactory.h"
47
48#include "ExRootAnalysis/ExRootTreeWriter.h"
49#include "ExRootAnalysis/ExRootTreeReader.h"
50#include "ExRootAnalysis/ExRootTreeBranch.h"
51#include "ExRootAnalysis/ExRootProgressBar.h"
52
53
54
55using namespace std;
56
57//---------------------------------------------------------------------------
58
59
60//---------------------------------------------------------------------------
61
62static bool interrupted = false;
63
64void SignalHandler(int sig)
65{
66 interrupted = true;
67}
68
69//---------------------------------------------------------------------------
70
71int main(int argc, char *argv[])
72{
73 char appName[] = "DelphesROOT";
74 stringstream message;
75 TFile *inputFile = 0;
76 TFile *outputFile = 0;
77 TStopwatch eventStopWatch;
78 ExRootTreeWriter *treeWriter = 0;
79 ExRootTreeBranch *branchEvent = 0;
80 ExRootConfReader *confReader = 0;
81 Delphes *modularDelphes = 0;
82 DelphesFactory *factory = 0;
83 GenParticle *gen;
84 HepMCEvent *element, *eve;
85 Candidate *candidate;
86 Int_t pdgCode;
87
88 const Double_t c_light = 2.99792458E8;
89
90 TObjArray *allParticleOutputArray = 0, *stableParticleOutputArray = 0, *partonOutputArray = 0;
91 Int_t i;
92 Long64_t eventCounter, numberOfEvents;
93
94 if(argc < 4)
95 {
96 cout << " Usage: " << appName << " config_file" << " output_file" << " input_file(s)" << endl;
97 cout << " config_file - configuration file in Tcl format," << endl;
98 cout << " output_file - output file in ROOT format," << endl;
99 cout << " input_file(s) - input file(s) in ROOT format." << endl;
100 return 1;
101 }
102
103 signal(SIGINT, SignalHandler);
104
105 gROOT->SetBatch();
106
107 int appargc = 1;
108 char *appargv[] = {appName};
109 TApplication app(appName, &appargc, appargv);
110
111 try
112 {
113 outputFile = TFile::Open(argv[2], "CREATE");
114
115 if(outputFile == NULL)
116 {
117 message << "can't open " << argv[2] << endl;
118 throw runtime_error(message.str());
119 }
120
121 treeWriter = new ExRootTreeWriter(outputFile, "Delphes");
122
123 branchEvent = treeWriter->NewBranch("Event", HepMCEvent::Class());
124
125 confReader = new ExRootConfReader;
126 confReader->ReadFile(argv[1]);
127
128 modularDelphes = new Delphes("Delphes");
129 modularDelphes->SetConfReader(confReader);
130 modularDelphes->SetTreeWriter(treeWriter);
131
132 TChain *chain = new TChain("Delphes");
133
134 factory = modularDelphes->GetFactory();
135 allParticleOutputArray = modularDelphes->ExportArray("allParticles");
136 stableParticleOutputArray = modularDelphes->ExportArray("stableParticles");
137 partonOutputArray = modularDelphes->ExportArray("partons");
138
139 modularDelphes->InitTask();
140
141 for(i = 3; i < argc && !interrupted; ++i)
142 {
143 cout << "** Reading " << argv[i] << endl;
144
145 chain->Add(argv[i]);
146 ExRootTreeReader *treeReader = new ExRootTreeReader(chain);
147
148 inputFile = TFile::Open(argv[i]);
149
150 if(inputFile == NULL)
151 {
152 message << "can't open " << argv[i] << endl;
153 throw runtime_error(message.str());
154 }
155
156 numberOfEvents = treeReader->GetEntries();
157 TClonesArray *branchParticle = treeReader->UseBranch("Particle");
158 TClonesArray *branchHepMCEvent = treeReader->UseBranch("Event");
159
160 if(numberOfEvents <= 0) continue;
161
162 // ExRootProgressBar progressBar(numberOfEvents - 1);
163 ExRootProgressBar progressBar(-1);
164
165 // Loop over all objects
166 eventCounter = 0;
167 modularDelphes->Clear();
168 treeWriter->Clear();
169 for(Int_t entry = 0; entry < numberOfEvents; ++entry)
170 {
171
172 eventCounter++;
173 treeReader->ReadEntry(entry);
174
175 // -- TBC need also to include event weights --
176
177 eve = (HepMCEvent*) branchHepMCEvent->At(0);
178 element = static_cast<HepMCEvent *>(branchEvent->NewEntry());
179
180 element->Number = eventCounter;
181
182 element->ProcessID = eve->ProcessID;
183 element->MPI = eve->MPI;
184 element->Weight = eve->Weight;
185 element->Scale = eve->Scale;
186 element->AlphaQED = eve->AlphaQED;
187 element->AlphaQCD = eve->AlphaQCD;
188
189 element->ID1 = eve->ID1;
190 element->ID2 = eve->ID2;
191 element->X1 = eve->X1;
192 element->X2 = eve->X2;
193 element->ScalePDF = eve->ScalePDF;
194 element->PDF1 = eve->PDF1;
195 element->PDF2 = eve->PDF2;
196
197 element->ReadTime = eve->ReadTime;
198 element->ProcTime = eve->ProcTime;
199
200 for(Int_t j=0; j < branchParticle->GetEntriesFast(); j++)
201 {
202
203 gen = (GenParticle*) branchParticle->At(j);
204 candidate = factory->NewCandidate();
205
206 candidate->Momentum = gen->P4();
207 candidate->Position.SetXYZT(gen->X, gen->Y, gen->Z, gen->T*1.0E3*c_light);
208
209 candidate->PID = gen->PID;
210 candidate->Status = gen->Status;
211
212 candidate->M1 = gen->M1;
213 candidate->M2 = gen->M2;
214
215 candidate->D1 = gen->D1;
216 candidate->D2 = gen->D2;
217
218 candidate->Charge = gen->Charge;
219 candidate->Mass = gen->Mass;
220
221 allParticleOutputArray->Add(candidate);
222
223 pdgCode = TMath::Abs(gen->PID);
224
225 if(gen->Status == 1)
226 {
227 stableParticleOutputArray->Add(candidate);
228 }
229 else if(pdgCode <= 5 || pdgCode == 21 || pdgCode == 15)
230 {
231 partonOutputArray->Add(candidate);
232 }
233 }
234
235 modularDelphes->ProcessTask();
236
237 treeWriter->Fill();
238
239 modularDelphes->Clear();
240 treeWriter->Clear();
241
242 progressBar.Update(eventCounter, eventCounter);
243 ++eventCounter;
244 }
245
246 progressBar.Update(eventCounter, eventCounter, kTRUE);
247 progressBar.Finish();
248
249 inputFile->Close();
250
251 delete treeReader;
252
253 }
254
255 modularDelphes->FinishTask();
256 treeWriter->Write();
257
258 cout << "** Exiting..." << endl;
259
260 delete modularDelphes;
261 delete confReader;
262 delete treeWriter;
263 delete outputFile;
264 delete chain;
265
266 return 0;
267 }
268 catch(runtime_error &e)
269 {
270 if(treeWriter) delete treeWriter;
271 if(outputFile) delete outputFile;
272 cerr << "** ERROR: " << e.what() << endl;
273 return 1;
274 }
275}
Note: See TracBrowser for help on using the repository browser.