Fork me on GitHub

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

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

checks that the input file is present

File size: 4.1 KB
RevLine 
[2]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;
[18]99 ifstream checking_the_file(filename.c_str());
100 if(!checking_the_file.good()) { cout << filename << ": file not found\n"; continue;}
101 else checking_the_file.close();
[2]102
103 // Create the Reader object:
104 LHEF::Reader *inputReader = new LHEF::Reader(filename);
105
106 cout << "** Calculating number of events to process. Please wait..." << endl;
107 Long64_t allEntries = inputReader->getNumberOfEvents();
108 cout << "** Input file contains " << allEntries << " events" << endl;
109
110 if(allEntries > 0) {
111 // Loop over all events
112 Long64_t entry = 0;
113 while(inputReader->readEvent()) {
114 treeWriter->Clear();
115 AnalyseEvent(inputReader, branchEvent, entry + 1);
116 AnalyseParticles(inputReader, branchParticle);
117 treeWriter->Fill();
118 ++entry;
119 }
120 }
121 }
122 treeWriter->Write();
123
124 cout << "** Exiting..." << endl;
125
126 delete treeWriter;
127 //delete inputReader;
128}
129
Note: See TracBrowser for help on using the repository browser.