Fork me on GitHub

source: git/converters/root2pileup.cpp@ 952bbbc

Last change on this file since 952bbbc was 341014c, checked in by Pavel Demin <pavel-demin@…>, 6 years ago

apply .clang-format to all .h, .cc and .cpp files

  • Property mode set to 100644
File size: 3.8 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
[d7d2da3]19#include <iostream>
20#include <sstream>
[341014c]21#include <stdexcept>
[d7d2da3]22#include <string>
23
24#include <signal.h>
25
26#include "TApplication.h"
[341014c]27#include "TROOT.h"
[d7d2da3]28
29#include "TClonesArray.h"
[341014c]30#include "TFile.h"
[d7d2da3]31
32#include "classes/DelphesClasses.h"
33#include "classes/DelphesPileUpWriter.h"
34
35#include "ExRootAnalysis/ExRootProgressBar.h"
[341014c]36#include "ExRootAnalysis/ExRootTreeReader.h"
[d7d2da3]37
38using namespace std;
39
40//---------------------------------------------------------------------------
41
42static bool interrupted = false;
43
44void SignalHandler(int sig)
45{
46 interrupted = true;
47}
48
49//---------------------------------------------------------------------------
50
51int main(int argc, char *argv[])
52{
53 char appName[] = "root2pileup";
54 stringstream message;
55 TChain *inputChain = 0;
56 ExRootTreeReader *treeReader = 0;
57 TClonesArray *branchParticle = 0;
58 TIterator *itParticle = 0;
59 GenParticle *particle = 0;
60 DelphesPileUpWriter *writer = 0;
61 Long64_t entry, allEntries;
62 Int_t i;
63
64 if(argc < 3)
65 {
[341014c]66 cout << " Usage: " << appName << " output_file"
67 << " input_file(s)" << endl;
[d7d2da3]68 cout << " output_file - output binary pile-up file," << endl;
69 cout << " input_file(s) - input file(s) in ROOT format." << endl;
70 return 1;
71 }
72
73 signal(SIGINT, SignalHandler);
74
75 gROOT->SetBatch();
76
77 int appargc = 1;
78 char *appargv[] = {appName};
79 TApplication app(appName, &appargc, appargv);
80
81 try
82 {
83 inputChain = new TChain("Delphes");
84 for(i = 2; i < argc && !interrupted; ++i)
85 {
86 inputChain->Add(argv[i]);
87 }
88
89 treeReader = new ExRootTreeReader(inputChain);
90 branchParticle = treeReader->UseBranch("Particle");
91 itParticle = branchParticle->MakeIterator();
92
93 writer = new DelphesPileUpWriter(argv[1]);
94
95 allEntries = treeReader->GetEntries();
96 cout << "** Input file(s) contain(s) " << allEntries << " events" << endl;
97
98 if(allEntries > 0)
99 {
100 ExRootProgressBar progressBar(allEntries - 1);
101 // Loop over all events in the input file
102 for(entry = 0; entry < allEntries && !interrupted; ++entry)
103 {
104 if(!treeReader->ReadEntry(entry))
105 {
106 cerr << "** ERROR: cannot read event " << entry << endl;
107 break;
108 }
109
110 itParticle->Reset();
[341014c]111 while((particle = static_cast<GenParticle *>(itParticle->Next())))
[d7d2da3]112 {
113 writer->WriteParticle(particle->PID,
114 particle->X, particle->Y, particle->Z, particle->T,
115 particle->Px, particle->Py, particle->Pz, particle->E);
116 }
[341014c]117
[d7d2da3]118 writer->WriteEntry();
119
120 progressBar.Update(entry);
121 }
122 progressBar.Finish();
123
124 writer->WriteIndex();
125 }
126
127 cout << "** Exiting..." << endl;
128
129 delete writer;
130 delete itParticle;
131 delete treeReader;
132 delete inputChain;
133 return 0;
134 }
135 catch(runtime_error &e)
136 {
137 if(writer) delete writer;
138 if(itParticle) delete itParticle;
139 if(treeReader) delete treeReader;
140 if(inputChain) delete inputChain;
141 cerr << "** ERROR: " << e.what() << endl;
142 return 1;
143 }
144}
Note: See TracBrowser for help on using the repository browser.