Fork me on GitHub

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

Last change on this file since 371 was 369, checked in by Xavier Rouby, 16 years ago

avoid the ROOT warning when PT is very small

File size: 7.3 KB
Line 
1/***********************************************************************
2** **
3** /----------------------------------------------\ **
4** | Delphes, a framework for the fast simulation | **
5** | of a generic collider experiment | **
6** \----------------------------------------------/ **
7** **
8** **
9** This package uses: **
10** ------------------ **
11** FastJet algorithm: Phys. Lett. B641 (2006) [hep-ph/0512210] **
12** Hector: JINST 2:P09005 (2007) [physics.acc-ph:0707.1198v2] **
13** FROG: [hep-ex/0901.2718v1] **
14** **
15** ------------------------------------------------------------------ **
16** **
17** Main authors: **
18** ------------- **
19** **
20** Severine Ovyn Xavier Rouby **
21** severine.ovyn@uclouvain.be xavier.rouby@cern **
22** **
23** Center for Particle Physics and Phenomenology (CP3) **
24** Universite catholique de Louvain (UCL) **
25** Louvain-la-Neuve, Belgium **
26** **
27** Copyright (C) 2008-2009, **
28** All rights reserved. **
29** **
30***********************************************************************/
31
32
33#include <iostream>
34#include <fstream>
35#include "TLorentzVector.h"
36#include "BlockClasses.h"
37#include "ExRootTreeWriter.h"
38#include "ExRootTreeBranch.h"
39#include "stdhep_mcfio.h"
40#include "stdhep_declarations.h"
41#include "STDHEPConverter.h"
42
43using namespace std;
44
45//---------------------------------------------------------------------------
46
47void STDHEPConverter::AnalyseEvent(ExRootTreeBranch *branch, const Long64_t eventNumber)
48{
49 TRootGenEvent *element;
50
51 element = static_cast<TRootGenEvent*>(branch->NewEntry());
52
53 element->Number = eventNumber;
54}
55
56//---------------------------------------------------------------------------
57
58void STDHEPConverter::AnalyseParticles(ExRootTreeBranch *branch)
59{
60 int Nmax = -1; // useless for the moment -- should be changed in order
61 if(Nmax>0) Nmax = min(Nmax,myhepevt.nhep); // to use Nevt in DataConverter
62 else Nmax = myhepevt.nhep;
63
64 TRootC::GenParticle *element;
65
66 Double_t signPz;
67 TLorentzVector momentum;
68 Int_t number;
69
70 for(number = 0; number < Nmax; ++number)
71 {
72 element = static_cast<TRootC::GenParticle*>(branch->NewEntry());
73
74 element->PID = myhepevt.idhep[number];
75 element->Status = myhepevt.isthep[number];
76 element->M1 = myhepevt.jmohep[number][0] - 1;
77 element->M2 = myhepevt.jmohep[number][1] - 1;
78 element->D1 = myhepevt.jdahep[number][0] - 1;
79 element->D2 = myhepevt.jdahep[number][1] - 1;
80// element->Charge = myhepevt.hepchg(element->PID);
81
82 element->E = myhepevt.phep[number][3];
83 element->Px = myhepevt.phep[number][0];
84 element->Py = myhepevt.phep[number][1];
85 element->Pz = myhepevt.phep[number][2];
86 element->M = myhepevt.phep[number][4];
87
88 momentum.SetPxPyPzE(element->Px, element->Py, element->Pz, element->E);
89 element->PT = momentum.Perp();
90 signPz = (element->Pz >= 0.0) ? 1.0 : -1.0;
91 //element->Eta = element->PT == 0.0 ? signPz*999.9 : momentum.Eta(); to avoid a warning from ROOT, replace the "==0" by "< 1e-6"
92 element->Eta = element->PT <1e-6 ? signPz*999.9 : momentum.Eta();
93 element->Phi = momentum.Phi();
94
95 element->T = myhepevt.vhep[number][3];
96 element->X = myhepevt.vhep[number][0];
97 element->Y = myhepevt.vhep[number][1];
98 element->Z = myhepevt.vhep[number][2];
99 }
100}
101
102
103//------------------------------------------------------------------------------
104
105STDHEPConverter::~STDHEPConverter()
106{
107}
108
109//------------------------------------------------------------------------------
110
111STDHEPConverter::STDHEPConverter(const string& inputFileList, const string& outputFileName, const int& Nevents) : DataConverter(Nevents)
112{
113 int ierr, entryType;
114 int istr = 0;
115 int nevt = 0;
116
117 ExRootTreeWriter *treeWriter = new ExRootTreeWriter(outputFileName, "GEN");
118
119 // information about generated event
120 ExRootTreeBranch *branchGenEvent = treeWriter->NewBranch("Event", TRootGenEvent::Class());
121 // generated particles from HEPEVT
122 ExRootTreeBranch *branchGenParticle = treeWriter->NewBranch("Particle", TRootC::GenParticle::Class());
123
124 // Open a stream connected to an event file:
125 ifstream infile(inputFileList.c_str());
126 string filename;
127 if(!infile.is_open())
128 {
129 cerr << left << setw(30) <<"** ERROR: Can't open "<<""
130 << left << setw(20) << inputFileList <<""
131 << right << setw(19) <<"for input **"<<""<<endl;
132
133 exit(1);
134 }
135 while(1)
136 {
137 infile >> filename;
138 if(!infile.good()) break;
139 ifstream checking_the_file(filename.c_str());
140 if(!checking_the_file.good())
141 {
142 cerr << left << setw(30) <<"** ERROR: Can't find file "<<""
143 << left << setw(20) << filename <<""
144 << right << setw(19) <<"for input **"<<""<<endl;
145 continue;
146 }
147 else checking_the_file.close();
148
149 ierr = StdHepXdrReadInit(const_cast<char*>(filename.c_str()), &nevt, istr);
150
151 if(ierr != 0)
152 {
153 cerr <<"** ERROR: Can't open file for input **"<<endl;
154 break;
155 }
156
157 Long64_t allEntries = nevt;
158
159 if(allEntries > 0)
160 {
161 // Loop over all objects
162 Long64_t entry = 0;
163 Long64_t recordNumber = 1;
164 for(entry = 0; entry < allEntries; ++entry)
165 {
166 ierr = StdHepXdrRead(&entryType, istr);
167
168 if(ierr != 0)
169 {
170 cerr << left << setw(49) <<"** ERROR: Unexpected end of file after"<<""
171 << left << setw(10) << entry <<""
172 << right << setw(10) <<"entries **"<<""<<endl;
173 break;
174 }
175
176 // analyse only entries with standard HEPEVT common block
177 if(entryType == 1)
178 {
179 // add empty events for missing event numbers
180 while(recordNumber < myhepevt.nevhep)
181 {
182 treeWriter->Clear();
183 AnalyseEvent(branchGenEvent, recordNumber);
184 treeWriter->Fill();
185 ++recordNumber;
186 }
187
188 treeWriter->Clear();
189
190 AnalyseEvent(branchGenEvent, myhepevt.nevhep);
191 AnalyseParticles(branchGenParticle);
192
193 treeWriter->Fill();
194
195 ++recordNumber;
196
197 }
198 }
199 }
200 StdHepXdrEnd(istr);
201 }
202 treeWriter->Write();
203
204 delete treeWriter;
205
206}
207
208
209
210
Note: See TracBrowser for help on using the repository browser.