Fork me on GitHub

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

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

vers un Nevnt implemente correctement. Pas fini

File size: 6.3 KB
Line 
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***********************************************************************/
31
32
33#include <iostream>
34#include <fstream>
35
36#include "TLorentzVector.h"
37
38#include "ExRootTreeWriter.h"
39#include "BlockClasses.h"
40#include "LHEFConverter.h"
41
42using namespace std;
43
44
45//------------------------------------------------------------------------------
46
47void LHEFConverter::AnalyseEvent(LHEF::Reader *reader, ExRootTreeBranch *branch, const Long64_t eventNumber)
48{
49 const LHEF::HEPEUP &hepeup = reader->hepeup;
50
51 TRootLHEFEvent *element;
52
53 element = (TRootLHEFEvent*) branch->NewEntry();
54
55 element->Number = eventNumber;
56 element->Nparticles = hepeup.NUP;
57 element->ProcessID = hepeup.IDPRUP;
58 element->Weight = hepeup.XWGTUP;
59 element->ScalePDF = hepeup.SCALUP;
60 element->CouplingQED = hepeup.AQEDUP;
61 element->CouplingQCD = hepeup.AQCDUP;
62}
63
64//---------------------------------------------------------------------------
65
66void LHEFConverter::AnalyseParticles(LHEF::Reader *reader, ExRootTreeBranch *branch)
67{
68 const LHEF::HEPEUP &hepeup = reader->hepeup;
69 Double_t signPz;
70 TLorentzVector momentum;
71 TRootLHEFParticle *element;
72
73 for(Int_t particle = 0; particle < hepeup.NUP; ++particle)
74 {
75 element = (TRootLHEFParticle*) branch->NewEntry();
76
77 element->PID = hepeup.IDUP[particle];
78 element->Status = hepeup.ISTUP[particle];
79 element->Mother1 = hepeup.MOTHUP[particle].first;
80 element->Mother2 = hepeup.MOTHUP[particle].second;
81 element->ColorLine1 = hepeup.ICOLUP[particle].first;
82 element->ColorLine2 = hepeup.ICOLUP[particle].second;
83 element->Px = hepeup.PUP[particle][0];
84 element->Py = hepeup.PUP[particle][1];
85 element->Pz = hepeup.PUP[particle][2];
86 element->E = hepeup.PUP[particle][3];
87 element->M = hepeup.PUP[particle][4];
88
89 momentum.SetPxPyPzE(element->Px, element->Py, element->Pz, element->E);
90 element->PT = momentum.Perp();
91 signPz = (element->Pz >= 0.0) ? 1.0 : -1.0;
92 element->Eta = element->PT == 0.0 ? signPz*999.9 : momentum.Eta();
93 element->Phi = momentum.Phi();
94 element->Rapidity = element->PT == 0.0 ? signPz*999.9 : momentum.Rapidity();
95 element->LifeTime = hepeup.VTIMUP[particle];
96 element->Spin = hepeup.SPINUP[particle];
97 }
98}
99
100LHEFConverter::~LHEFConverter()
101{
102}
103
104//------------------------------------------------------------------------------
105//Nevents not yet implemented! 08.03.2009
106LHEFConverter::LHEFConverter(const string& inputFileList, const string& outputFileName, const int& Nevents) :
107 DataConverter(Nevents) {
108
109 ExRootTreeWriter *treeWriter = new ExRootTreeWriter(outputFileName, "GEN");
110
111 // generated event from LHEF
112 ExRootTreeBranch *branchEvent = treeWriter->NewBranch("Event", TRootLHEFEvent::Class());
113
114 // generated partons from LHEF
115 ExRootTreeBranch *branchParticle = treeWriter->NewBranch("Particle", TRootLHEFParticle::Class());
116
117 // Open a stream connected to an event file:
118 ifstream infile(inputFileList.c_str());
119 string filename;
120 if(!infile.is_open()) {
121 cerr << left << setw(30) <<"** ERROR: Can't open "<<""
122 << left << setw(20) << inputFileList <<""
123 << right << setw(19) <<"for input **"<<""<<endl;
124 exit(1);
125 }
126
127 while(1) { // parsing the list of files
128
129 infile >> filename;
130 if(!infile.good()) break;
131 ifstream checking_the_file(filename.c_str());
132 if(!checking_the_file.good())
133 {
134 cerr << left << setw(30) <<"** ERROR: Can't find file "<<""
135 << left << setw(20) << filename <<""
136 << right << setw(19) <<"for input **"<<""<<endl;
137 continue;
138 }
139 else checking_the_file.close();
140
141 // Create the Reader object:
142 LHEF::Reader *inputReader = new LHEF::Reader(filename);
143
144 Long64_t allEntries = inputReader->getNumberOfEvents();
145
146 if(allEntries > 0) {
147 // Loop over all events
148 Long64_t entry = 0;
149 while(inputReader->readEvent()) {
150 treeWriter->Clear();
151 AnalyseEvent(inputReader, branchEvent, entry + 1);
152 AnalyseParticles(inputReader, branchParticle);
153 treeWriter->Fill();
154 ++entry;
155 }
156 }
157 }
158 treeWriter->Write();
159
160
161 delete treeWriter;
162 //delete inputReader;
163}
164
Note: See TracBrowser for help on using the repository browser.