Fork me on GitHub

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

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

include statements have been cleaned

File size: 4.6 KB
RevLine 
[220]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
[2]11#include <iostream>
12#include <fstream>
13#include "TLorentzVector.h"
[220]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"
[2]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];
[56]60 element->M = myhepevt.phep[number][4];
[2]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 << "** ERROR: Can't open '" << inputFileList << "' for input" << endl;
104 exit(1);
105 }
106 while(1)
107 {
108 infile >> filename;
109 if(!infile.good()) break;
[18]110 ifstream checking_the_file(filename.c_str());
111 if(!checking_the_file.good()) { cout << filename << ": file not found\n"; continue;}
112 else checking_the_file.close();
[2]113
114 ierr = StdHepXdrReadInit(const_cast<char*>(filename.c_str()), &nevt, istr);
115
116 if(ierr != 0)
117 {
118 cerr << "** ERROR: Can't open file for input" << endl;
119 break;
120 }
121
122 Long64_t allEntries = nevt;
123 cout << "** Input file contains " << allEntries << " entries" << endl;
124
125 if(allEntries > 0)
126 {
127 // Loop over all objects
128 Long64_t entry = 0;
129 Long64_t recordNumber = 1;
130 for(entry = 0; entry < allEntries; ++entry)
131 {
132 ierr = StdHepXdrRead(&entryType, istr);
133
134 if(ierr != 0)
135 {
136 cerr << "** ERROR: Unexpected end of file after " << entry << " entries" << endl;
137 break;
138 }
139
140 // analyse only entries with standard HEPEVT common block
141 if(entryType == 1)
142 {
143 // add empty events for missing event numbers
144 while(recordNumber < myhepevt.nevhep)
145 {
146 treeWriter->Clear();
147 AnalyseEvent(branchGenEvent, recordNumber);
148 treeWriter->Fill();
149 ++recordNumber;
150 }
151
152 treeWriter->Clear();
153
154 AnalyseEvent(branchGenEvent, myhepevt.nevhep);
155 AnalyseParticles(branchGenParticle);
156
157 treeWriter->Fill();
158
159 ++recordNumber;
160
161 }
162 }
163 }
164 }
165 treeWriter->Write();
166 cout << "** Exiting..." << endl;
167
168 delete treeWriter;
169 StdHepXdrEnd(istr);
170
171}
172
173
174
175
Note: See TracBrowser for help on using the repository browser.