Fork me on GitHub

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

Last change on this file since 446 was 443, checked in by Xavier Rouby, 15 years ago

new header in all files

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