Fork me on GitHub

source: git/converters/pileup2root.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: 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#include <iostream>
20#include <sstream>
[341014c]21#include <stdexcept>
[d7d2da3]22
23#include <signal.h>
24#include <stdio.h>
[341014c]25#include <stdlib.h>
[d7d2da3]26
27#include "TApplication.h"
[341014c]28#include "TROOT.h"
[d7d2da3]29
[341014c]30#include "TDatabasePDG.h"
[d7d2da3]31#include "TFile.h"
[341014c]32#include "TLorentzVector.h"
[d7d2da3]33#include "TObjArray.h"
34#include "TParticlePDG.h"
[341014c]35#include "TStopwatch.h"
[d7d2da3]36
37#include "classes/DelphesClasses.h"
38#include "classes/DelphesFactory.h"
39#include "classes/DelphesPileUpReader.h"
[341014c]40#include "classes/DelphesStream.h"
[d7d2da3]41
42#include "ExRootAnalysis/ExRootProgressBar.h"
[341014c]43#include "ExRootAnalysis/ExRootTreeBranch.h"
44#include "ExRootAnalysis/ExRootTreeWriter.h"
[d7d2da3]45
46using namespace std;
47
48//------------------------------------------------------------------------------
49
50void ProcessEvent(DelphesPileUpReader *reader, ExRootTreeBranch *branch)
51{
52 GenParticle *particle;
53 Int_t pid;
54 Float_t x, y, z, t;
55 Float_t px, py, pz, e;
56 TDatabasePDG *pdg = TDatabasePDG::Instance();
57 TParticlePDG *pdgParticle;
58 TLorentzVector momentum;
59 Double_t pt, signPz, cosTheta, eta, rapidity;
60
61 while(reader->ReadParticle(pid, x, y, z, t, px, py, pz, e))
62 {
[341014c]63 particle = static_cast<GenParticle *>(branch->NewEntry());
[d7d2da3]64
65 particle->PID = pid;
66 particle->X = x;
67 particle->Y = y;
68 particle->Z = z;
69 particle->T = t;
70 particle->Px = px;
71 particle->Py = py;
72 particle->Pz = pz;
73 particle->E = e;
74
75 particle->Status = 1;
76 particle->IsPU = 1;
77
78 particle->M1 = -1;
79 particle->M2 = -1;
80
81 particle->D1 = -1;
82 particle->D2 = -1;
83
84 pdgParticle = pdg->GetParticle(pid);
[341014c]85 particle->Charge = pdgParticle ? Int_t(pdgParticle->Charge() / 3.0) : -999;
[d7d2da3]86
87 particle->Mass = pdgParticle ? pdgParticle->Mass() : -999.9;
88
89 momentum.SetPxPyPzE(px, py, pz, e);
90 pt = momentum.Pt();
91 cosTheta = TMath::Abs(momentum.CosTheta());
92 signPz = (momentum.Pz() >= 0.0) ? 1.0 : -1.0;
[341014c]93 eta = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Eta());
94 rapidity = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Rapidity());
[d7d2da3]95
96 particle->Eta = eta;
97 particle->Phi = momentum.Phi();
98 particle->PT = pt;
99
100 particle->Rapidity = rapidity;
101 }
102}
103
104//---------------------------------------------------------------------------
105
106static bool interrupted = false;
107
108void SignalHandler(int sig)
109{
110 interrupted = true;
111}
112
113//---------------------------------------------------------------------------
114
115int main(int argc, char *argv[])
116{
117 char appName[] = "pileup2root";
118 stringstream message;
119 TFile *outputFile = 0;
120 ExRootTreeWriter *treeWriter = 0;
121 ExRootTreeBranch *branchParticle = 0;
122 DelphesPileUpReader *reader = 0;
123 Long64_t entry, allEntries;
124
125 if(argc != 3)
126 {
[341014c]127 cout << " Usage: " << appName << " output_file"
128 << " input_file" << endl;
[d7d2da3]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}
Note: See TracBrowser for help on using the repository browser.