Fork me on GitHub

source: svn/trunk/src/LHEFConverter.cc@ 459

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

lhe bug (empty Analysis tree) solved

File size: 8.7 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***********************************************************************/
33
[2]34#include <iostream>
35#include <fstream>
36
37#include "TLorentzVector.h"
38
[219]39#include "ExRootTreeWriter.h"
40#include "BlockClasses.h"
41#include "LHEFConverter.h"
[380]42#include "SmearUtil.h"
43#include "PdgParticle.h"
[2]44
45using namespace std;
46
47
48//------------------------------------------------------------------------------
49
50void LHEFConverter::AnalyseEvent(LHEF::Reader *reader, ExRootTreeBranch *branch, const Long64_t eventNumber)
51{
52 const LHEF::HEPEUP &hepeup = reader->hepeup;
53
54 TRootLHEFEvent *element;
55
56 element = (TRootLHEFEvent*) branch->NewEntry();
57
58 element->Number = eventNumber;
59 element->Nparticles = hepeup.NUP;
60 element->ProcessID = hepeup.IDPRUP;
61 element->Weight = hepeup.XWGTUP;
62 element->ScalePDF = hepeup.SCALUP;
63 element->CouplingQED = hepeup.AQEDUP;
64 element->CouplingQCD = hepeup.AQCDUP;
65}
66
67//---------------------------------------------------------------------------
68
69void LHEFConverter::AnalyseParticles(LHEF::Reader *reader, ExRootTreeBranch *branch)
70{
71 const LHEF::HEPEUP &hepeup = reader->hepeup;
72 Double_t signPz;
73 TLorentzVector momentum;
74 TRootLHEFParticle *element;
75
76 for(Int_t particle = 0; particle < hepeup.NUP; ++particle)
77 {
78 element = (TRootLHEFParticle*) branch->NewEntry();
79
80 element->PID = hepeup.IDUP[particle];
81 element->Status = hepeup.ISTUP[particle];
[450]82 element->M1 = hepeup.MOTHUP[particle].first;
83 element->M2 = hepeup.MOTHUP[particle].second;
84 element->D1 = 0;
85 element->D2 = 0;
[2]86 element->ColorLine1 = hepeup.ICOLUP[particle].first;
87 element->ColorLine2 = hepeup.ICOLUP[particle].second;
88 element->Px = hepeup.PUP[particle][0];
89 element->Py = hepeup.PUP[particle][1];
90 element->Pz = hepeup.PUP[particle][2];
91 element->E = hepeup.PUP[particle][3];
[380]92 //element->M = hepeup.PUP[particle][4];
93 //element->Charge = ChargeVal(element->PID);
94
95 PdgParticle pdg_part = pdg_table[element->PID];
96 element->Charge = pdg_part.charge();
97 element->M = pdg_part.mass();
98
[2]99 momentum.SetPxPyPzE(element->Px, element->Py, element->Pz, element->E);
100 element->PT = momentum.Perp();
101 signPz = (element->Pz >= 0.0) ? 1.0 : -1.0;
[369]102 //element->Eta = element->PT == 0.0 ? signPz*999.9 : momentum.Eta(); to avoid a warning from ROOT, replace the "==0" by "< 1e-6"
[413]103 element->Eta = element->PT < 1E-6 ? signPz*999.9 : momentum.Eta();
[2]104 element->Phi = momentum.Phi();
[413]105 element->Rapidity = element->PT < 1E-6 ? signPz*999.9 : momentum.Rapidity();
[2]106 element->LifeTime = hepeup.VTIMUP[particle];
107 element->Spin = hepeup.SPINUP[particle];
108 }
109}
110
[450]111
112//---------------------------------------------------------------------------
113/*
114void LHEFConverter::AnalyseParticles(LHEF::Reader *reader, ExRootTreeBranch *branch)
115{
116 const LHEF::HEPEUP &hepeup = reader->hepeup;
117 Double_t signPz;
118 TLorentzVector momentum;
119 TRootC::GenParticle *element;
120
121 for(Int_t particle = 0; particle < hepeup.NUP; ++particle)
122 {
123 element = (TRootC::GenParticle*) branch->NewEntry();
124
125 element->PID = hepeup.IDUP[particle];
126 element->Status = hepeup.ISTUP[particle];
127 element->M1 = hepeup.MOTHUP[particle].first;
128 element->M2 = hepeup.MOTHUP[particle].second;
129 //element->ColorLine1 = hepeup.ICOLUP[particle].first;
130 //element->ColorLine2 = hepeup.ICOLUP[particle].second;
131 element->D1 = 0;
132 element->D2 = 0;
133
134 PdgParticle pdg_part = pdg_table[element->PID];
135 element->Charge = pdg_part.charge();
136 element->M = pdg_part.mass();
137 //element->Charge = ChargeVal(element->PID);
138 //element->M = hepeup.PUP[particle][4];
139
140 element->E = hepeup.PUP[particle][3];
141 element->Px = hepeup.PUP[particle][0];
142 element->Py = hepeup.PUP[particle][1];
143 element->Pz = hepeup.PUP[particle][2];
144
145 momentum.SetPxPyPzE(element->Px, element->Py, element->Pz, element->E);
146 element->PT = momentum.Perp();
147 signPz = (element->Pz >= 0.0) ? 1.0 : -1.0;
148 //element->Eta = element->PT == 0.0 ? signPz*999.9 : momentum.Eta(); to avoid a warning from ROOT, replace the "==0" by "< 1e-6"
149 element->Eta = element->PT < 1E-6 ? signPz*999.9 : momentum.Eta();
150 element->Phi = momentum.Phi();
151// element->Rapidity = element->PT < 1E-6 ? signPz*999.9 : momentum.Rapidity();
152// element->LifeTime = hepeup.VTIMUP[particle];
153// element->Spin = hepeup.SPINUP[particle];
154 }
155}
156*/
157
[2]158LHEFConverter::~LHEFConverter()
159{
160}
161
162//------------------------------------------------------------------------------
[450]163LHEFConverter::LHEFConverter(const string& inputFileList, const string& outputFileName, const PdgTable& pdg, const int& Nevents) : DataConverter(pdg,Nevents) {
[2]164
165 ExRootTreeWriter *treeWriter = new ExRootTreeWriter(outputFileName, "GEN");
166
167 // generated event from LHEF
168 ExRootTreeBranch *branchEvent = treeWriter->NewBranch("Event", TRootLHEFEvent::Class());
169
170 // generated partons from LHEF
171 ExRootTreeBranch *branchParticle = treeWriter->NewBranch("Particle", TRootLHEFParticle::Class());
[450]172 //ExRootTreeBranch *branchParticle = treeWriter->NewBranch("Particle", TRootC::GenParticle::Class());
[2]173
174 // Open a stream connected to an event file:
175 ifstream infile(inputFileList.c_str());
176 string filename;
177 if(!infile.is_open()) {
[245]178 cerr << left << setw(30) <<"** ERROR: Can't open "<<""
179 << left << setw(20) << inputFileList <<""
180 << right << setw(19) <<"for input **"<<""<<endl;
[2]181 exit(1);
182 }
183
184 while(1) { // parsing the list of files
185
186 infile >> filename;
187 if(!infile.good()) break;
[18]188 ifstream checking_the_file(filename.c_str());
[245]189 if(!checking_the_file.good())
190 {
191 cerr << left << setw(30) <<"** ERROR: Can't find file "<<""
192 << left << setw(20) << filename <<""
193 << right << setw(19) <<"for input **"<<""<<endl;
194 continue;
[246]195 }
[18]196 else checking_the_file.close();
[2]197
198 // Create the Reader object:
199 LHEF::Reader *inputReader = new LHEF::Reader(filename);
200
201 Long64_t allEntries = inputReader->getNumberOfEvents();
[419]202 allEntries = (Nevt<0)?allEntries:min((int)allEntries,Nevt); // do not miss the "+1"
203
[2]204 if(allEntries > 0) {
205 // Loop over all events
206 Long64_t entry = 0;
207 while(inputReader->readEvent()) {
208 treeWriter->Clear();
209 AnalyseEvent(inputReader, branchEvent, entry + 1);
210 AnalyseParticles(inputReader, branchParticle);
211 treeWriter->Fill();
212 ++entry;
[419]213 if(allEntries<entry+1) break;
[2]214 }
215 }
216 }
217 treeWriter->Write();
218 delete treeWriter;
219 //delete inputReader;
220}
221
Note: See TracBrowser for help on using the repository browser.