Fork me on GitHub

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

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

first test 2.0

File size: 6.2 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***********************************************************************/
31
32
[2]33#include <iostream>
34#include <fstream>
35
36#include "TLorentzVector.h"
37
[219]38#include "ExRootTreeWriter.h"
39#include "BlockClasses.h"
40#include "LHEFConverter.h"
[2]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
106LHEFConverter::LHEFConverter(const string& inputFileList, const string& outputFileName) {
107
108 ExRootTreeWriter *treeWriter = new ExRootTreeWriter(outputFileName, "GEN");
109
110 // generated event from LHEF
111 ExRootTreeBranch *branchEvent = treeWriter->NewBranch("Event", TRootLHEFEvent::Class());
112
113 // generated partons from LHEF
114 ExRootTreeBranch *branchParticle = treeWriter->NewBranch("Particle", TRootLHEFParticle::Class());
115
116 // Open a stream connected to an event file:
117 ifstream infile(inputFileList.c_str());
118 string filename;
119 if(!infile.is_open()) {
[245]120 cerr << left << setw(30) <<"** ERROR: Can't open "<<""
121 << left << setw(20) << inputFileList <<""
122 << right << setw(19) <<"for input **"<<""<<endl;
[2]123 exit(1);
124 }
125
126 while(1) { // parsing the list of files
127
128 infile >> filename;
129 if(!infile.good()) break;
[18]130 ifstream checking_the_file(filename.c_str());
[245]131 if(!checking_the_file.good())
132 {
133 cerr << left << setw(30) <<"** ERROR: Can't find file "<<""
134 << left << setw(20) << filename <<""
135 << right << setw(19) <<"for input **"<<""<<endl;
136 continue;
[246]137 }
[18]138 else checking_the_file.close();
[2]139
140 // Create the Reader object:
141 LHEF::Reader *inputReader = new LHEF::Reader(filename);
142
143 Long64_t allEntries = inputReader->getNumberOfEvents();
144
145 if(allEntries > 0) {
146 // Loop over all events
147 Long64_t entry = 0;
148 while(inputReader->readEvent()) {
149 treeWriter->Clear();
150 AnalyseEvent(inputReader, branchEvent, entry + 1);
151 AnalyseParticles(inputReader, branchParticle);
152 treeWriter->Fill();
153 ++entry;
154 }
155 }
156 }
157 treeWriter->Write();
158
159
160 delete treeWriter;
161 //delete inputReader;
162}
163
Note: See TracBrowser for help on using the repository browser.