Fork me on GitHub

source: git/converters/pileup2root.cpp@ fcc959c

ImprovedOutputFile Timing dual_readout llp
Last change on this file since fcc959c was d7d2da3, checked in by pavel <pavel@…>, 11 years ago

move branches/ModularDelphes to trunk

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