Fork me on GitHub

source: svn/trunk/converters/root2pileup.cpp@ 1113

Last change on this file since 1113 was 1056, checked in by Pavel Demin, 12 years ago

add DelphesPileUpWriter

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