Fork me on GitHub

source: git/converters/pileup2root.cpp@ e57c062

ImprovedOutputFile Timing dual_readout llp
Last change on this file since e57c062 was 7d0eb75, checked in by Pavel Demin <pavel-demin@…>, 6 years ago

remove rpc includes from pileup2root.cpp

  • Property mode set to 100644
File size: 5.1 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
20#include <stdexcept>
21#include <iostream>
22#include <sstream>
23
24#include <stdlib.h>
25#include <signal.h>
26#include <stdio.h>
27
28#include "TROOT.h"
29#include "TApplication.h"
30
31#include "TFile.h"
32#include "TObjArray.h"
33#include "TStopwatch.h"
34#include "TDatabasePDG.h"
35#include "TParticlePDG.h"
36#include "TLorentzVector.h"
37
38#include "classes/DelphesStream.h"
39#include "classes/DelphesClasses.h"
40#include "classes/DelphesFactory.h"
41#include "classes/DelphesPileUpReader.h"
42
43#include "ExRootAnalysis/ExRootTreeWriter.h"
44#include "ExRootAnalysis/ExRootTreeBranch.h"
45#include "ExRootAnalysis/ExRootProgressBar.h"
46
47using namespace std;
48
49//------------------------------------------------------------------------------
50
51void ProcessEvent(DelphesPileUpReader *reader, ExRootTreeBranch *branch)
52{
53 GenParticle *particle;
54 Int_t pid;
55 Float_t x, y, z, t;
56 Float_t px, py, pz, e;
57 TDatabasePDG *pdg = TDatabasePDG::Instance();
58 TParticlePDG *pdgParticle;
59 TLorentzVector momentum;
60 Double_t pt, signPz, cosTheta, eta, rapidity;
61
62 while(reader->ReadParticle(pid, x, y, z, t, px, py, pz, e))
63 {
64 particle = static_cast<GenParticle*>(branch->NewEntry());
65
66 particle->PID = pid;
67 particle->X = x;
68 particle->Y = y;
69 particle->Z = z;
70 particle->T = t;
71 particle->Px = px;
72 particle->Py = py;
73 particle->Pz = pz;
74 particle->E = e;
75
76 particle->Status = 1;
77 particle->IsPU = 1;
78
79 particle->M1 = -1;
80 particle->M2 = -1;
81
82 particle->D1 = -1;
83 particle->D2 = -1;
84
85 pdgParticle = pdg->GetParticle(pid);
86 particle->Charge = pdgParticle ? Int_t(pdgParticle->Charge()/3.0) : -999;
87
88 particle->Mass = pdgParticle ? pdgParticle->Mass() : -999.9;
89
90 momentum.SetPxPyPzE(px, py, pz, e);
91 pt = momentum.Pt();
92 cosTheta = TMath::Abs(momentum.CosTheta());
93 signPz = (momentum.Pz() >= 0.0) ? 1.0 : -1.0;
94 eta = (cosTheta == 1.0 ? signPz*999.9 : momentum.Eta());
95 rapidity = (cosTheta == 1.0 ? signPz*999.9 : momentum.Rapidity());
96
97 particle->Eta = eta;
98 particle->Phi = momentum.Phi();
99 particle->PT = pt;
100
101 particle->Rapidity = rapidity;
102 }
103}
104
105//---------------------------------------------------------------------------
106
107static bool interrupted = false;
108
109void SignalHandler(int sig)
110{
111 interrupted = true;
112}
113
114//---------------------------------------------------------------------------
115
116int main(int argc, char *argv[])
117{
118 char appName[] = "pileup2root";
119 stringstream message;
120 TFile *outputFile = 0;
121 ExRootTreeWriter *treeWriter = 0;
122 ExRootTreeBranch *branchParticle = 0;
123 DelphesPileUpReader *reader = 0;
124 Long64_t entry, allEntries;
125
126 if(argc != 3)
127 {
128 cout << " Usage: " << appName << " output_file" << " input_file" << endl;
129 cout << " output_file - output file in ROOT format," << endl;
130 cout << " input_file - input binary pile-up file." << endl;
131 return 1;
132 }
133
134 signal(SIGINT, SignalHandler);
135
136 gROOT->SetBatch();
137
138 int appargc = 1;
139 char *appargv[] = {appName};
140 TApplication app(appName, &appargc, appargv);
141
142 try
143 {
144 outputFile = TFile::Open(argv[1], "CREATE");
145
146 if(outputFile == NULL)
147 {
148 message << "can't open " << argv[1];
149 throw runtime_error(message.str());
150 }
151
152 cout << "** Reading " << argv[2] << endl;
153
154 reader = new DelphesPileUpReader(argv[2]);
155 allEntries = reader->GetEntries();
156
157 cout << "** Input file contains " << allEntries << " events" << endl;
158
159 if(allEntries > 0)
160 {
161 treeWriter = new ExRootTreeWriter(outputFile, "Delphes");
162 branchParticle = treeWriter->NewBranch("Particle", GenParticle::Class());
163
164 ExRootProgressBar progressBar(allEntries - 1);
165 // Loop over all events
166 for(entry = 0; entry < allEntries && !interrupted; ++entry)
167 {
168 if(!reader->ReadEntry(entry))
169 {
170 cerr << "** ERROR: cannot read event " << entry << endl;
171 break;
172 }
173
174 treeWriter->Clear();
175 ProcessEvent(reader, branchParticle);
176 treeWriter->Fill();
177
178 progressBar.Update(entry);
179 }
180 treeWriter->Write();
181
182 progressBar.Finish();
183
184 delete treeWriter;
185 }
186 delete reader;
187
188 cout << "** Exiting..." << endl;
189
190 return 0;
191 }
192 catch(runtime_error &e)
193 {
194 if(treeWriter) delete treeWriter;
195 if(reader) delete reader;
196 if(outputFile) delete outputFile;
197 cerr << "** ERROR: " << e.what() << endl;
198 return 1;
199 }
200}
201
202
Note: See TracBrowser for help on using the repository browser.