Fork me on GitHub

source: git/converters/pileup2root.cpp@ 255a666

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

fix GPLv3 header

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