Fork me on GitHub

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

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

first commit

File size: 3.9 KB
Line 
1#include <iostream>
2#include <fstream>
3
4#include "TLorentzVector.h"
5
6#include "Utilities/ExRootAnalysis/interface/ExRootTreeWriter.h"
7#include "Utilities/ExRootAnalysis/interface/ExRootTreeBranch.h"
8#include "Utilities/ExRootAnalysis/interface/BlockClasses.h"
9
10#include "interface/LHEFConverter.h"
11#include "Utilities/ExRootAnalysis/interface/LHEF.h"
12
13using namespace std;
14
15
16//------------------------------------------------------------------------------
17
18void LHEFConverter::AnalyseEvent(LHEF::Reader *reader, ExRootTreeBranch *branch, const Long64_t eventNumber)
19{
20 const LHEF::HEPEUP &hepeup = reader->hepeup;
21
22 TRootLHEFEvent *element;
23
24 element = (TRootLHEFEvent*) branch->NewEntry();
25
26 element->Number = eventNumber;
27 element->Nparticles = hepeup.NUP;
28 element->ProcessID = hepeup.IDPRUP;
29 element->Weight = hepeup.XWGTUP;
30 element->ScalePDF = hepeup.SCALUP;
31 element->CouplingQED = hepeup.AQEDUP;
32 element->CouplingQCD = hepeup.AQCDUP;
33}
34
35//---------------------------------------------------------------------------
36
37void LHEFConverter::AnalyseParticles(LHEF::Reader *reader, ExRootTreeBranch *branch)
38{
39 const LHEF::HEPEUP &hepeup = reader->hepeup;
40 Double_t signPz;
41 TLorentzVector momentum;
42 TRootLHEFParticle *element;
43
44 for(Int_t particle = 0; particle < hepeup.NUP; ++particle)
45 {
46 element = (TRootLHEFParticle*) branch->NewEntry();
47
48 element->PID = hepeup.IDUP[particle];
49 element->Status = hepeup.ISTUP[particle];
50 element->Mother1 = hepeup.MOTHUP[particle].first;
51 element->Mother2 = hepeup.MOTHUP[particle].second;
52 element->ColorLine1 = hepeup.ICOLUP[particle].first;
53 element->ColorLine2 = hepeup.ICOLUP[particle].second;
54 element->Px = hepeup.PUP[particle][0];
55 element->Py = hepeup.PUP[particle][1];
56 element->Pz = hepeup.PUP[particle][2];
57 element->E = hepeup.PUP[particle][3];
58 element->M = hepeup.PUP[particle][4];
59
60 momentum.SetPxPyPzE(element->Px, element->Py, element->Pz, element->E);
61 element->PT = momentum.Perp();
62 signPz = (element->Pz >= 0.0) ? 1.0 : -1.0;
63 element->Eta = element->PT == 0.0 ? signPz*999.9 : momentum.Eta();
64 element->Phi = momentum.Phi();
65 element->Rapidity = element->PT == 0.0 ? signPz*999.9 : momentum.Rapidity();
66 element->LifeTime = hepeup.VTIMUP[particle];
67 element->Spin = hepeup.SPINUP[particle];
68 }
69}
70
71LHEFConverter::~LHEFConverter()
72{
73}
74
75//------------------------------------------------------------------------------
76
77LHEFConverter::LHEFConverter(const string& inputFileList, const string& outputFileName) {
78
79 ExRootTreeWriter *treeWriter = new ExRootTreeWriter(outputFileName, "GEN");
80
81 // generated event from LHEF
82 ExRootTreeBranch *branchEvent = treeWriter->NewBranch("Event", TRootLHEFEvent::Class());
83
84 // generated partons from LHEF
85 ExRootTreeBranch *branchParticle = treeWriter->NewBranch("Particle", TRootLHEFParticle::Class());
86
87 // Open a stream connected to an event file:
88 ifstream infile(inputFileList.c_str());
89 string filename;
90 if(!infile.is_open()) {
91 cerr << "** ERROR: Can't open '" << inputFileList << "' for input" << endl;
92 exit(1);
93 }
94
95 while(1) { // parsing the list of files
96
97 infile >> filename;
98 if(!infile.good()) break;
99
100 // Create the Reader object:
101 LHEF::Reader *inputReader = new LHEF::Reader(filename);
102
103 cout << "** Calculating number of events to process. Please wait..." << endl;
104 Long64_t allEntries = inputReader->getNumberOfEvents();
105 cout << "** Input file contains " << allEntries << " events" << endl;
106
107 if(allEntries > 0) {
108 // Loop over all events
109 Long64_t entry = 0;
110 while(inputReader->readEvent()) {
111 treeWriter->Clear();
112 AnalyseEvent(inputReader, branchEvent, entry + 1);
113 AnalyseParticles(inputReader, branchParticle);
114 treeWriter->Fill();
115 ++entry;
116 }
117 }
118 }
119 treeWriter->Write();
120
121 cout << "** Exiting..." << endl;
122
123 delete treeWriter;
124 //delete inputReader;
125}
126
Note: See TracBrowser for help on using the repository browser.