Fork me on GitHub

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

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

new header in all files

File size: 7.6 KB
RevLine 
[264]1/***********************************************************************
2** **
3** /----------------------------------------------\ **
4** | Delphes, a framework for the fast simulation | **
5** | of a generic collider experiment | **
[443]6** \------------- arXiv:0903.2225v1 ------------/ **
[264]7** **
8** **
9** This package uses: **
10** ------------------ **
[443]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] **
[264]14** FROG: [hep-ex/0901.2718v1] **
[443]15** HepMC: Comput. Phys. Commun.134 (2001) 41 **
[264]16** **
17** ------------------------------------------------------------------ **
18** **
19** Main authors: **
20** ------------- **
21** **
[443]22** Severine Ovyn Xavier Rouby **
23** severine.ovyn@uclouvain.be xavier.rouby@cern **
[264]24** **
[443]25** Center for Particle Physics and Phenomenology (CP3) **
26** Universite catholique de Louvain (UCL) **
27** Louvain-la-Neuve, Belgium **
28** **
[264]29** Copyright (C) 2008-2009, **
[443]30** All rights reserved. **
[264]31** **
32***********************************************************************/
[220]33
[2]34#include <iostream>
35#include <fstream>
[419]36#include <cmath>
[2]37#include "TLorentzVector.h"
[220]38#include "BlockClasses.h"
[376]39#include "SmearUtil.h"
[220]40#include "ExRootTreeWriter.h"
41#include "ExRootTreeBranch.h"
42#include "stdhep_mcfio.h"
43#include "stdhep_declarations.h"
44#include "STDHEPConverter.h"
[380]45#include "PdgParticle.h"
[2]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{
[295]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
[350]68 TRootC::GenParticle *element;
[2]69
70 Double_t signPz;
71 TLorentzVector momentum;
72 Int_t number;
73
[295]74 for(number = 0; number < Nmax; ++number)
[2]75 {
[350]76 element = static_cast<TRootC::GenParticle*>(branch->NewEntry());
[2]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;
[380]84 PdgParticle pdg_part = pdg_table[element->PID];
85 element->Charge = pdg_part.charge();
86 element->M = pdg_part.mass();
[2]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];
[380]92 //element->M = myhepevt.phep[number][4];
[2]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;
[369]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();
[2]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
[380]117STDHEPConverter::STDHEPConverter(const string& inputFileList, const string& outputFileName, const PdgTable& pdg, const int& Nevents) : DataConverter(pdg, Nevents)
[2]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
[350]128 ExRootTreeBranch *branchGenParticle = treeWriter->NewBranch("Particle", TRootC::GenParticle::Class());
[2]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 {
[245]135 cerr << left << setw(30) <<"** ERROR: Can't open "<<""
136 << left << setw(20) << inputFileList <<""
137 << right << setw(19) <<"for input **"<<""<<endl;
138
[2]139 exit(1);
140 }
141 while(1)
142 {
143 infile >> filename;
144 if(!infile.good()) break;
[18]145 ifstream checking_the_file(filename.c_str());
[245]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 }
[18]153 else checking_the_file.close();
[2]154
155 ierr = StdHepXdrReadInit(const_cast<char*>(filename.c_str()), &nevt, istr);
156
157 if(ierr != 0)
158 {
[245]159 cerr <<"** ERROR: Can't open file for input **"<<endl;
[2]160 break;
161 }
[419]162
163 Long64_t allEntries = (Nevt<0)?nevt:min(nevt,Nevt+1); // do not miss the "+1"
[2]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 {
[245]175 cerr << left << setw(49) <<"** ERROR: Unexpected end of file after"<<""
176 << left << setw(10) << entry <<""
177 << right << setw(10) <<"entries **"<<""<<endl;
[2]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 }
[245]205 StdHepXdrEnd(istr);
[2]206 }
207 treeWriter->Write();
208
209 delete treeWriter;
210
211}
212
213
214
215
Note: See TracBrowser for help on using the repository browser.