Fork me on GitHub

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

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

Nevent implemented in DetectorCard

File size: 7.5 KB
RevLine 
[264]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***********************************************************************/
[220]31
32
[2]33#include <iostream>
34#include <fstream>
[419]35#include <cmath>
[2]36#include "TLorentzVector.h"
[220]37#include "BlockClasses.h"
[376]38#include "SmearUtil.h"
[220]39#include "ExRootTreeWriter.h"
40#include "ExRootTreeBranch.h"
41#include "stdhep_mcfio.h"
42#include "stdhep_declarations.h"
43#include "STDHEPConverter.h"
[380]44#include "PdgParticle.h"
[2]45
46using namespace std;
47
48//---------------------------------------------------------------------------
49
50void STDHEPConverter::AnalyseEvent(ExRootTreeBranch *branch, const Long64_t eventNumber)
51{
52 TRootGenEvent *element;
53
54 element = static_cast<TRootGenEvent*>(branch->NewEntry());
55
56 element->Number = eventNumber;
57}
58
59//---------------------------------------------------------------------------
60
61void STDHEPConverter::AnalyseParticles(ExRootTreeBranch *branch)
62{
[295]63 int Nmax = -1; // useless for the moment -- should be changed in order
64 if(Nmax>0) Nmax = min(Nmax,myhepevt.nhep); // to use Nevt in DataConverter
65 else Nmax = myhepevt.nhep;
66
[350]67 TRootC::GenParticle *element;
[2]68
69 Double_t signPz;
70 TLorentzVector momentum;
71 Int_t number;
72
[295]73 for(number = 0; number < Nmax; ++number)
[2]74 {
[350]75 element = static_cast<TRootC::GenParticle*>(branch->NewEntry());
[2]76
77 element->PID = myhepevt.idhep[number];
78 element->Status = myhepevt.isthep[number];
79 element->M1 = myhepevt.jmohep[number][0] - 1;
80 element->M2 = myhepevt.jmohep[number][1] - 1;
81 element->D1 = myhepevt.jdahep[number][0] - 1;
82 element->D2 = myhepevt.jdahep[number][1] - 1;
[380]83 PdgParticle pdg_part = pdg_table[element->PID];
84 element->Charge = pdg_part.charge();
85 element->M = pdg_part.mass();
[2]86
87 element->E = myhepevt.phep[number][3];
88 element->Px = myhepevt.phep[number][0];
89 element->Py = myhepevt.phep[number][1];
90 element->Pz = myhepevt.phep[number][2];
[380]91 //element->M = myhepevt.phep[number][4];
[2]92
93 momentum.SetPxPyPzE(element->Px, element->Py, element->Pz, element->E);
94 element->PT = momentum.Perp();
95 signPz = (element->Pz >= 0.0) ? 1.0 : -1.0;
[369]96 //element->Eta = element->PT == 0.0 ? signPz*999.9 : momentum.Eta(); to avoid a warning from ROOT, replace the "==0" by "< 1e-6"
97 element->Eta = element->PT <1e-6 ? signPz*999.9 : momentum.Eta();
[2]98 element->Phi = momentum.Phi();
99
100 element->T = myhepevt.vhep[number][3];
101 element->X = myhepevt.vhep[number][0];
102 element->Y = myhepevt.vhep[number][1];
103 element->Z = myhepevt.vhep[number][2];
104 }
105}
106
107
108//------------------------------------------------------------------------------
109
110STDHEPConverter::~STDHEPConverter()
111{
112}
113
114//------------------------------------------------------------------------------
115
[380]116STDHEPConverter::STDHEPConverter(const string& inputFileList, const string& outputFileName, const PdgTable& pdg, const int& Nevents) : DataConverter(pdg, Nevents)
[2]117{
118 int ierr, entryType;
119 int istr = 0;
120 int nevt = 0;
121
122 ExRootTreeWriter *treeWriter = new ExRootTreeWriter(outputFileName, "GEN");
123
124 // information about generated event
125 ExRootTreeBranch *branchGenEvent = treeWriter->NewBranch("Event", TRootGenEvent::Class());
126 // generated particles from HEPEVT
[350]127 ExRootTreeBranch *branchGenParticle = treeWriter->NewBranch("Particle", TRootC::GenParticle::Class());
[2]128
129 // Open a stream connected to an event file:
130 ifstream infile(inputFileList.c_str());
131 string filename;
132 if(!infile.is_open())
133 {
[245]134 cerr << left << setw(30) <<"** ERROR: Can't open "<<""
135 << left << setw(20) << inputFileList <<""
136 << right << setw(19) <<"for input **"<<""<<endl;
137
[2]138 exit(1);
139 }
140 while(1)
141 {
142 infile >> filename;
143 if(!infile.good()) break;
[18]144 ifstream checking_the_file(filename.c_str());
[245]145 if(!checking_the_file.good())
146 {
147 cerr << left << setw(30) <<"** ERROR: Can't find file "<<""
148 << left << setw(20) << filename <<""
149 << right << setw(19) <<"for input **"<<""<<endl;
150 continue;
151 }
[18]152 else checking_the_file.close();
[2]153
154 ierr = StdHepXdrReadInit(const_cast<char*>(filename.c_str()), &nevt, istr);
155
156 if(ierr != 0)
157 {
[245]158 cerr <<"** ERROR: Can't open file for input **"<<endl;
[2]159 break;
160 }
[419]161
162 Long64_t allEntries = (Nevt<0)?nevt:min(nevt,Nevt+1); // do not miss the "+1"
[2]163 if(allEntries > 0)
164 {
165 // Loop over all objects
166 Long64_t entry = 0;
167 Long64_t recordNumber = 1;
168 for(entry = 0; entry < allEntries; ++entry)
169 {
170 ierr = StdHepXdrRead(&entryType, istr);
171
172 if(ierr != 0)
173 {
[245]174 cerr << left << setw(49) <<"** ERROR: Unexpected end of file after"<<""
175 << left << setw(10) << entry <<""
176 << right << setw(10) <<"entries **"<<""<<endl;
[2]177 break;
178 }
179
180 // analyse only entries with standard HEPEVT common block
181 if(entryType == 1)
182 {
183 // add empty events for missing event numbers
184 while(recordNumber < myhepevt.nevhep)
185 {
186 treeWriter->Clear();
187 AnalyseEvent(branchGenEvent, recordNumber);
188 treeWriter->Fill();
189 ++recordNumber;
190 }
191
192 treeWriter->Clear();
193
194 AnalyseEvent(branchGenEvent, myhepevt.nevhep);
195 AnalyseParticles(branchGenParticle);
196
197 treeWriter->Fill();
198
199 ++recordNumber;
200
201 }
202 }
203 }
[245]204 StdHepXdrEnd(istr);
[2]205 }
206 treeWriter->Write();
207
208 delete treeWriter;
209
210}
211
212
213
214
Note: See TracBrowser for help on using the repository browser.