Fork me on GitHub

source: git/readers/DelphesProMC.cpp@ e5fa629

ImprovedOutputFile Timing llp
Last change on this file since e5fa629 was e5fa629, checked in by chekanov <chekanov@…>, 6 years ago

Propogate pileup information from HepSim

  • Property mode set to 100644
File size: 8.6 KB
RevLine 
[b443089]1/*
2 * Delphes: a framework for fast simulation of a generic collider experiment
3 * Copyright (C) 2012-2014 Universite catholique de Louvain (UCL), Belgium
[1fa50c2]4 *
[b443089]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.
[1fa50c2]9 *
[b443089]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.
[1fa50c2]14 *
[b443089]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
[4b17b1e]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
[a85a257]49#include "ProMC.pb.h"
50#include "ProMCBook.h"
51#include "ProMCHeader.pb.h"
[4b17b1e]52
53using namespace std;
54
55//---------------------------------------------------------------------------
56
[a85a257]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)
[4b17b1e]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;
[80d4a34]74 Double_t px, py, pz, mass;
[e26d4d6]75 Double_t x, y, z, t;
[4b17b1e]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();
[e3ab175]87 element->MPI = mutableEvent->mpi();
88 element->Weight = mutableEvent->weight();
[4b17b1e]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
[6e0bbe3]101 element->ReadTime = readStopWatch->RealTime();
102 element->ProcTime = procStopWatch->RealTime();
[4b17b1e]103
104 mutableParticles = event.mutable_particles();
105
[1c30542]106 for(i = 0; i < mutableParticles->pdg_id_size(); ++i)
[4b17b1e]107 {
108 pid = mutableParticles->pdg_id(i);
109 status = mutableParticles->status(i);
[a85a257]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;
[4b17b1e]119
120 candidate = factory->NewCandidate();
121
122 candidate->PID = pid;
123 pdgCode = TMath::Abs(candidate->PID);
124
125 candidate->Status = status;
126
[e5fa629]127 candidate->IsPU=0;
128 if (mutableParticles->barcode(i)>0) candidate->IsPU=1; // pileup particle
129
[4b17b1e]130 candidate->M1 = mutableParticles->mother1(i);
131 candidate->M2 = mutableParticles->mother2(i);
132
133 candidate->D1 = mutableParticles->daughter1(i);
134 candidate->D2 = mutableParticles->daughter2(i);
135
136 pdgParticle = pdg->GetParticle(pid);
137 candidate->Charge = pdgParticle ? Int_t(pdgParticle->Charge()/3.0) : -999;
[80d4a34]138 candidate->Mass = mass;
[4b17b1e]139
[80d4a34]140 candidate->Momentum.SetXYZM(px, py, pz, mass);
[4b17b1e]141
[e26d4d6]142 candidate->Position.SetXYZT(x, y, z, t);
[4b17b1e]143
144 allParticleOutputArray->Add(candidate);
145
[2f82259]146 if(!pdgParticle) continue;
[4b17b1e]147
148 if(status == 1)
149 {
150 stableParticleOutputArray->Add(candidate);
151 }
152 else if(pdgCode <= 5 || pdgCode == 21 || pdgCode == 15)
153 {
154 partonOutputArray->Add(candidate);
155 }
156 }
157}
158
159//---------------------------------------------------------------------------
160
161static bool interrupted = false;
162
163void SignalHandler(int sig)
164{
165 interrupted = true;
166}
167
168//---------------------------------------------------------------------------
169
170int main(int argc, char *argv[])
171{
[298a8fb]172 char appName[] = "DelphesProMC";
[4b17b1e]173 stringstream message;
174 ProMCBook *inputFile = 0;
175 TFile *outputFile = 0;
[6e0bbe3]176 TStopwatch readStopWatch, procStopWatch;
[4b17b1e]177 ExRootTreeWriter *treeWriter = 0;
178 ExRootTreeBranch *branchEvent = 0;
179 ExRootConfReader *confReader = 0;
180 Delphes *modularDelphes = 0;
181 DelphesFactory *factory = 0;
182 TObjArray *allParticleOutputArray = 0, *stableParticleOutputArray = 0, *partonOutputArray = 0;
183 Int_t i;
[a0538b9]184 Long64_t eventCounter, numberOfEvents;
[a85a257]185 double momentumUnit = 1.0, positionUnit = 1.0;
[4b17b1e]186
187 if(argc < 4)
188 {
189 cout << " Usage: " << appName << " config_file" << " output_file" << " input_file(s)" << endl;
190 cout << " config_file - configuration file in Tcl format," << endl;
191 cout << " output_file - output file in ROOT format," << endl;
192 cout << " input_file(s) - input file(s) in ProMC format." << endl;
193 return 1;
194 }
195
196 signal(SIGINT, SignalHandler);
197
198 gROOT->SetBatch();
199
200 int appargc = 1;
201 char *appargv[] = {appName};
202 TApplication app(appName, &appargc, appargv);
203
204 try
205 {
206 outputFile = TFile::Open(argv[2], "CREATE");
207
208 if(outputFile == NULL)
209 {
210 message << "can't open " << argv[2] << endl;
211 throw runtime_error(message.str());
212 }
213
214 treeWriter = new ExRootTreeWriter(outputFile, "Delphes");
215
[e3ab175]216 branchEvent = treeWriter->NewBranch("Event", HepMCEvent::Class());
[4b17b1e]217
218 confReader = new ExRootConfReader;
219 confReader->ReadFile(argv[1]);
220
221 modularDelphes = new Delphes("Delphes");
222 modularDelphes->SetConfReader(confReader);
223 modularDelphes->SetTreeWriter(treeWriter);
224
225 factory = modularDelphes->GetFactory();
226 allParticleOutputArray = modularDelphes->ExportArray("allParticles");
227 stableParticleOutputArray = modularDelphes->ExportArray("stableParticles");
228 partonOutputArray = modularDelphes->ExportArray("partons");
229
230 modularDelphes->InitTask();
231
232 for(i = 3; i < argc && !interrupted; ++i)
233 {
234 cout << "** Reading " << argv[i] << endl;
235
[e5fa629]236 // use 64 bit
237 //inputFile = new ProMCBook(argv[i], "r", true);
238
239 //use 32 bit zip (faster but limitted to 64k events)
[4b17b1e]240 inputFile = new ProMCBook(argv[i], "r");
241
[a85a257]242 ProMCHeader header = inputFile->getHeader();
243
244 momentumUnit = static_cast<double>(header.momentumunit());
245 positionUnit = static_cast<double>(header.lengthunit());
246
247
248
[4b17b1e]249 if(inputFile == NULL)
250 {
251 message << "can't open " << argv[i] << endl;
252 throw runtime_error(message.str());
253 }
254
[298a8fb]255 numberOfEvents = inputFile->getEvents();
[4b17b1e]256
[a0538b9]257 if(numberOfEvents <= 0) continue;
[4b17b1e]258
[a0538b9]259 ExRootProgressBar progressBar(numberOfEvents - 1);
[4b17b1e]260
261 // Loop over all objects
262 modularDelphes->Clear();
263 treeWriter->Clear();
[6e0bbe3]264 readStopWatch.Start();
[a0538b9]265 for(eventCounter = 0; eventCounter < numberOfEvents && !interrupted; ++eventCounter)
[4b17b1e]266 {
267 if(inputFile->next() != 0) continue;
268 ProMCEvent event = inputFile->get();
269
[6e0bbe3]270 readStopWatch.Stop();
271
272 procStopWatch.Start();
[a85a257]273 ConvertInput(event, momentumUnit, positionUnit,
274 branchEvent, factory,
275 allParticleOutputArray, stableParticleOutputArray,
276 partonOutputArray, &readStopWatch, &procStopWatch);
[4b17b1e]277 modularDelphes->ProcessTask();
[6e0bbe3]278 procStopWatch.Stop();
[4b17b1e]279
280 treeWriter->Fill();
281
282 modularDelphes->Clear();
283 treeWriter->Clear();
284
[6e0bbe3]285 readStopWatch.Start();
[a0538b9]286 progressBar.Update(eventCounter);
[4b17b1e]287 }
[a0538b9]288
289 progressBar.Update(eventCounter, eventCounter, kTRUE);
[4b17b1e]290 progressBar.Finish();
291
292 inputFile->close();
[e3ab175]293 delete inputFile;
[4b17b1e]294 }
295
296 modularDelphes->FinishTask();
297 treeWriter->Write();
298
299 cout << "** Exiting..." << endl;
300
301 delete modularDelphes;
302 delete confReader;
303 delete treeWriter;
304 delete outputFile;
305
306 return 0;
307 }
308 catch(runtime_error &e)
309 {
310 if(treeWriter) delete treeWriter;
311 if(outputFile) delete outputFile;
312 cerr << "** ERROR: " << e.what() << endl;
313 return 1;
314 }
315}
Note: See TracBrowser for help on using the repository browser.