Fork me on GitHub

source: git/readers/DelphesProMC.cpp@ b315535

ImprovedOutputFile Timing dual_readout llp
Last change on this file since b315535 was 1fa50c2, checked in by Pavel Demin <pavel.demin@…>, 10 years ago

fix GPLv3 header

  • Property mode set to 100644
File size: 8.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 <stdexcept>
20#include <iostream>
21#include <sstream>
22#include <memory>
23
24#include <map>
25
26#include <stdlib.h>
27#include <signal.h>
28#include <stdio.h>
29
30#include "TROOT.h"
31#include "TApplication.h"
32
33#include "TFile.h"
34#include "TObjArray.h"
35#include "TStopwatch.h"
36#include "TDatabasePDG.h"
37#include "TParticlePDG.h"
38#include "TLorentzVector.h"
39
40#include "modules/Delphes.h"
41#include "classes/DelphesStream.h"
42#include "classes/DelphesClasses.h"
43#include "classes/DelphesFactory.h"
44
45#include "ExRootAnalysis/ExRootTreeWriter.h"
46#include "ExRootAnalysis/ExRootTreeBranch.h"
47#include "ExRootAnalysis/ExRootProgressBar.h"
48
49#include "ProMC.pb.h"
50#include "ProMCBook.h"
51#include "ProMCHeader.pb.h"
52
53using namespace std;
54
55//---------------------------------------------------------------------------
56
57void ConvertInput(ProMCEvent &event, double momentumUnit, double positionUnit,
58 ExRootTreeBranch *branch, DelphesFactory *factory,
59 TObjArray *allParticleOutputArray, TObjArray *stableParticleOutputArray,
60 TObjArray *partonOutputArray, TStopwatch *readStopWatch, TStopwatch *procStopWatch)
61{
62 Int_t i;
63
64 ProMCEvent_Event *mutableEvent;
65 ProMCEvent_Particles *mutableParticles;
66
67 HepMCEvent *element;
68 Candidate *candidate;
69 TDatabasePDG *pdg;
70 TParticlePDG *pdgParticle;
71 Int_t pdgCode;
72
73 Int_t pid, status;
74 Double_t px, py, pz, mass;
75 Double_t x, y, z, t;
76
77 pdg = TDatabasePDG::Instance();
78
79 // event information
80 mutableEvent = event.mutable_event();
81
82 element = static_cast<HepMCEvent *>(branch->NewEntry());
83
84 element->Number = mutableEvent->number();
85
86 element->ProcessID = mutableEvent->process_id();
87 element->MPI = mutableEvent->mpi();
88 element->Weight = mutableEvent->weight();
89 element->Scale = mutableEvent->scale();
90 element->AlphaQED = mutableEvent->alpha_qed();
91 element->AlphaQCD = mutableEvent->alpha_qcd();
92
93 element->ID1 = mutableEvent->id1();
94 element->ID2 = mutableEvent->id2();
95 element->X1 = mutableEvent->x1();
96 element->X2 = mutableEvent->x2();
97 element->ScalePDF = mutableEvent->scale_pdf();
98 element->PDF1 = mutableEvent->pdf1();
99 element->PDF2 = mutableEvent->pdf2();
100
101 element->ReadTime = readStopWatch->RealTime();
102 element->ProcTime = procStopWatch->RealTime();
103
104 mutableParticles = event.mutable_particles();
105
106 for(i = 0; i < mutableParticles->pdg_id_size(); ++i)
107 {
108 pid = mutableParticles->pdg_id(i);
109 status = mutableParticles->status(i);
110
111 px = mutableParticles->px(i)/momentumUnit;
112 py = mutableParticles->py(i)/momentumUnit;
113 pz = mutableParticles->pz(i)/momentumUnit;
114 mass = mutableParticles->mass(i)/momentumUnit;
115 x = mutableParticles->x(i)/positionUnit;
116 y = mutableParticles->y(i)/positionUnit;
117 z = mutableParticles->z(i)/positionUnit;
118 t = mutableParticles->t(i)/positionUnit;
119
120 candidate = factory->NewCandidate();
121
122 candidate->PID = pid;
123 pdgCode = TMath::Abs(candidate->PID);
124
125 candidate->Status = status;
126
127 candidate->M1 = mutableParticles->mother1(i);
128 candidate->M2 = mutableParticles->mother2(i);
129
130 candidate->D1 = mutableParticles->daughter1(i);
131 candidate->D2 = mutableParticles->daughter2(i);
132
133 pdgParticle = pdg->GetParticle(pid);
134 candidate->Charge = pdgParticle ? Int_t(pdgParticle->Charge()/3.0) : -999;
135 candidate->Mass = mass;
136
137 candidate->Momentum.SetXYZM(px, py, pz, mass);
138
139 candidate->Position.SetXYZT(x, y, z, t);
140
141 allParticleOutputArray->Add(candidate);
142
143 if(!pdgParticle) continue;
144
145 if(status == 1)
146 {
147 stableParticleOutputArray->Add(candidate);
148 }
149 else if(pdgCode <= 5 || pdgCode == 21 || pdgCode == 15)
150 {
151 partonOutputArray->Add(candidate);
152 }
153 }
154}
155
156//---------------------------------------------------------------------------
157
158static bool interrupted = false;
159
160void SignalHandler(int sig)
161{
162 interrupted = true;
163}
164
165//---------------------------------------------------------------------------
166
167int main(int argc, char *argv[])
168{
169 char appName[] = "DelphesProMC";
170 stringstream message;
171 ProMCBook *inputFile = 0;
172 TFile *outputFile = 0;
173 TStopwatch readStopWatch, procStopWatch;
174 ExRootTreeWriter *treeWriter = 0;
175 ExRootTreeBranch *branchEvent = 0;
176 ExRootConfReader *confReader = 0;
177 Delphes *modularDelphes = 0;
178 DelphesFactory *factory = 0;
179 TObjArray *allParticleOutputArray = 0, *stableParticleOutputArray = 0, *partonOutputArray = 0;
180 Int_t i;
181 Long64_t eventCounter, numberOfEvents;
182 double momentumUnit = 1.0, positionUnit = 1.0;
183
184 if(argc < 4)
185 {
186 cout << " Usage: " << appName << " config_file" << " output_file" << " input_file(s)" << endl;
187 cout << " config_file - configuration file in Tcl format," << endl;
188 cout << " output_file - output file in ROOT format," << endl;
189 cout << " input_file(s) - input file(s) in ProMC format." << endl;
190 return 1;
191 }
192
193 signal(SIGINT, SignalHandler);
194
195 gROOT->SetBatch();
196
197 int appargc = 1;
198 char *appargv[] = {appName};
199 TApplication app(appName, &appargc, appargv);
200
201 try
202 {
203 outputFile = TFile::Open(argv[2], "CREATE");
204
205 if(outputFile == NULL)
206 {
207 message << "can't open " << argv[2] << endl;
208 throw runtime_error(message.str());
209 }
210
211 treeWriter = new ExRootTreeWriter(outputFile, "Delphes");
212
213 branchEvent = treeWriter->NewBranch("Event", HepMCEvent::Class());
214
215 confReader = new ExRootConfReader;
216 confReader->ReadFile(argv[1]);
217
218 modularDelphes = new Delphes("Delphes");
219 modularDelphes->SetConfReader(confReader);
220 modularDelphes->SetTreeWriter(treeWriter);
221
222 factory = modularDelphes->GetFactory();
223 allParticleOutputArray = modularDelphes->ExportArray("allParticles");
224 stableParticleOutputArray = modularDelphes->ExportArray("stableParticles");
225 partonOutputArray = modularDelphes->ExportArray("partons");
226
227 modularDelphes->InitTask();
228
229 for(i = 3; i < argc && !interrupted; ++i)
230 {
231 cout << "** Reading " << argv[i] << endl;
232
233 inputFile = new ProMCBook(argv[i], "r");
234
235 ProMCHeader header = inputFile->getHeader();
236
237 momentumUnit = static_cast<double>(header.momentumunit());
238 positionUnit = static_cast<double>(header.lengthunit());
239
240
241
242 if(inputFile == NULL)
243 {
244 message << "can't open " << argv[i] << endl;
245 throw runtime_error(message.str());
246 }
247
248 numberOfEvents = inputFile->getEvents();
249
250 if(numberOfEvents <= 0) continue;
251
252 ExRootProgressBar progressBar(numberOfEvents - 1);
253
254 // Loop over all objects
255 modularDelphes->Clear();
256 treeWriter->Clear();
257 readStopWatch.Start();
258 for(eventCounter = 0; eventCounter < numberOfEvents && !interrupted; ++eventCounter)
259 {
260 if(inputFile->next() != 0) continue;
261 ProMCEvent event = inputFile->get();
262
263 readStopWatch.Stop();
264
265 procStopWatch.Start();
266 ConvertInput(event, momentumUnit, positionUnit,
267 branchEvent, factory,
268 allParticleOutputArray, stableParticleOutputArray,
269 partonOutputArray, &readStopWatch, &procStopWatch);
270 modularDelphes->ProcessTask();
271 procStopWatch.Stop();
272
273 treeWriter->Fill();
274
275 modularDelphes->Clear();
276 treeWriter->Clear();
277
278 readStopWatch.Start();
279 progressBar.Update(eventCounter);
280 }
281
282 progressBar.Update(eventCounter, eventCounter, kTRUE);
283 progressBar.Finish();
284
285 inputFile->close();
286 delete inputFile;
287 }
288
289 modularDelphes->FinishTask();
290 treeWriter->Write();
291
292 cout << "** Exiting..." << endl;
293
294 delete modularDelphes;
295 delete confReader;
296 delete treeWriter;
297 delete outputFile;
298
299 return 0;
300 }
301 catch(runtime_error &e)
302 {
303 if(treeWriter) delete treeWriter;
304 if(outputFile) delete outputFile;
305 cerr << "** ERROR: " << e.what() << endl;
306 return 1;
307 }
308}
Note: See TracBrowser for help on using the repository browser.