Fork me on GitHub

source: svn/trunk/src/STDHEPConverter.cc@ 258

Last change on this file since 258 was 245, checked in by severine ovyn, 16 years ago

OK for error message

File size: 5.0 KB
Line 
1/*
2 ---- Delphes ----
3 A Fast Simulator for general purpose LHC detector
4 S. Ovyn ~~~~ severine.ovyn@uclouvain.be
5
6 Center for Particle Physics and Phenomenology (CP3)
7 Universite Catholique de Louvain (UCL)
8 Louvain-la-Neuve, Belgium
9*/
10
11#include <iostream>
12#include <fstream>
13#include "TLorentzVector.h"
14#include "BlockClasses.h"
15#include "ExRootTreeWriter.h"
16#include "ExRootTreeBranch.h"
17#include "stdhep_mcfio.h"
18#include "stdhep_declarations.h"
19#include "STDHEPConverter.h"
20
21using namespace std;
22
23//---------------------------------------------------------------------------
24
25void STDHEPConverter::AnalyseEvent(ExRootTreeBranch *branch, const Long64_t eventNumber)
26{
27 TRootGenEvent *element;
28
29 element = static_cast<TRootGenEvent*>(branch->NewEntry());
30
31 element->Number = eventNumber;
32}
33
34//---------------------------------------------------------------------------
35
36void STDHEPConverter::AnalyseParticles(ExRootTreeBranch *branch)
37{
38 TRootGenParticle *element;
39
40 Double_t signPz;
41 TLorentzVector momentum;
42 Int_t number;
43
44 for(number = 0; number < myhepevt.nhep; ++number)
45 {
46 element = static_cast<TRootGenParticle*>(branch->NewEntry());
47
48 element->PID = myhepevt.idhep[number];
49 element->Status = myhepevt.isthep[number];
50 element->M1 = myhepevt.jmohep[number][0] - 1;
51 element->M2 = myhepevt.jmohep[number][1] - 1;
52 element->D1 = myhepevt.jdahep[number][0] - 1;
53 element->D2 = myhepevt.jdahep[number][1] - 1;
54// element->Charge = myhepevt.hepchg(element->PID);
55
56 element->E = myhepevt.phep[number][3];
57 element->Px = myhepevt.phep[number][0];
58 element->Py = myhepevt.phep[number][1];
59 element->Pz = myhepevt.phep[number][2];
60 element->M = myhepevt.phep[number][4];
61
62 momentum.SetPxPyPzE(element->Px, element->Py, element->Pz, element->E);
63 element->PT = momentum.Perp();
64 signPz = (element->Pz >= 0.0) ? 1.0 : -1.0;
65 element->Eta = element->PT == 0.0 ? signPz*999.9 : momentum.Eta();
66 element->Phi = momentum.Phi();
67
68 element->T = myhepevt.vhep[number][3];
69 element->X = myhepevt.vhep[number][0];
70 element->Y = myhepevt.vhep[number][1];
71 element->Z = myhepevt.vhep[number][2];
72 }
73}
74
75
76//------------------------------------------------------------------------------
77
78STDHEPConverter::~STDHEPConverter()
79{
80}
81
82//------------------------------------------------------------------------------
83
84STDHEPConverter::STDHEPConverter(const string& inputFileList, const string& outputFileName)
85{
86
87 int ierr, entryType;
88 int istr = 0;
89 int nevt = 0;
90
91 ExRootTreeWriter *treeWriter = new ExRootTreeWriter(outputFileName, "GEN");
92
93 // information about generated event
94 ExRootTreeBranch *branchGenEvent = treeWriter->NewBranch("Event", TRootGenEvent::Class());
95 // generated particles from HEPEVT
96 ExRootTreeBranch *branchGenParticle = treeWriter->NewBranch("Particle", TRootGenParticle::Class());
97
98 // Open a stream connected to an event file:
99 ifstream infile(inputFileList.c_str());
100 string filename;
101 if(!infile.is_open())
102 {
103 cerr << left << setw(30) <<"** ERROR: Can't open "<<""
104 << left << setw(20) << inputFileList <<""
105 << right << setw(19) <<"for input **"<<""<<endl;
106
107 exit(1);
108 }
109 while(1)
110 {
111 infile >> filename;
112 if(!infile.good()) break;
113 ifstream checking_the_file(filename.c_str());
114 if(!checking_the_file.good())
115 {
116 cerr << left << setw(30) <<"** ERROR: Can't find file "<<""
117 << left << setw(20) << filename <<""
118 << right << setw(19) <<"for input **"<<""<<endl;
119 continue;
120 }
121 else checking_the_file.close();
122
123 ierr = StdHepXdrReadInit(const_cast<char*>(filename.c_str()), &nevt, istr);
124
125 if(ierr != 0)
126 {
127 cerr <<"** ERROR: Can't open file for input **"<<endl;
128 break;
129 }
130
131 Long64_t allEntries = nevt;
132
133 if(allEntries > 0)
134 {
135 // Loop over all objects
136 Long64_t entry = 0;
137 Long64_t recordNumber = 1;
138 for(entry = 0; entry < allEntries; ++entry)
139 {
140 ierr = StdHepXdrRead(&entryType, istr);
141
142 if(ierr != 0)
143 {
144 cerr << left << setw(49) <<"** ERROR: Unexpected end of file after"<<""
145 << left << setw(10) << entry <<""
146 << right << setw(10) <<"entries **"<<""<<endl;
147 break;
148 }
149
150 // analyse only entries with standard HEPEVT common block
151 if(entryType == 1)
152 {
153 // add empty events for missing event numbers
154 while(recordNumber < myhepevt.nevhep)
155 {
156 treeWriter->Clear();
157 AnalyseEvent(branchGenEvent, recordNumber);
158 treeWriter->Fill();
159 ++recordNumber;
160 }
161
162 treeWriter->Clear();
163
164 AnalyseEvent(branchGenEvent, myhepevt.nevhep);
165 AnalyseParticles(branchGenParticle);
166
167 treeWriter->Fill();
168
169 ++recordNumber;
170
171 }
172 }
173 }
174 StdHepXdrEnd(istr);
175 }
176 treeWriter->Write();
177
178 delete treeWriter;
179
180}
181
182
183
184
Note: See TracBrowser for help on using the repository browser.