1 |
|
---|
2 | #include <iostream>
|
---|
3 | #include <map>
|
---|
4 |
|
---|
5 | #include "TROOT.h"
|
---|
6 | #include "TApplication.h"
|
---|
7 |
|
---|
8 | #include "TFile.h"
|
---|
9 | #include "TChain.h"
|
---|
10 | #include "TString.h"
|
---|
11 |
|
---|
12 | #include "TH2.h"
|
---|
13 | #include "THStack.h"
|
---|
14 | #include "TLegend.h"
|
---|
15 | #include "TPaveText.h"
|
---|
16 | #include "TLorentzVector.h"
|
---|
17 |
|
---|
18 | #include "LHEF.h"
|
---|
19 |
|
---|
20 | #include "ExRootAnalysis/ExRootClasses.h"
|
---|
21 |
|
---|
22 | #include "ExRootAnalysis/ExRootTreeWriter.h"
|
---|
23 | #include "ExRootAnalysis/ExRootTreeBranch.h"
|
---|
24 |
|
---|
25 | #include "ExRootAnalysis/ExRootUtilities.h"
|
---|
26 | #include "ExRootAnalysis/ExRootProgressBar.h"
|
---|
27 |
|
---|
28 | using namespace std;
|
---|
29 |
|
---|
30 | //---------------------------------------------------------------------------
|
---|
31 |
|
---|
32 | void AnalyseEvent(LHEF::Reader *reader, ExRootTreeBranch *branch, Long64_t eventNumber)
|
---|
33 | {
|
---|
34 | const LHEF::HEPEUP &hepeup = reader->hepeup;
|
---|
35 |
|
---|
36 | ExRootLHEFEvent *element;
|
---|
37 |
|
---|
38 | element = (ExRootLHEFEvent*) branch->NewEntry();
|
---|
39 |
|
---|
40 |
|
---|
41 | element->Number = eventNumber;
|
---|
42 | element->Nparticles = hepeup.NUP;
|
---|
43 | element->ProcessID = hepeup.IDPRUP;
|
---|
44 | element->Weight = hepeup.XWGTUP;
|
---|
45 | element->ScalePDF = hepeup.SCALUP;
|
---|
46 | element->CouplingQED = hepeup.AQEDUP;
|
---|
47 | element->CouplingQCD = hepeup.AQCDUP;
|
---|
48 | }
|
---|
49 |
|
---|
50 | //---------------------------------------------------------------------------
|
---|
51 |
|
---|
52 | void AnalyseParticles(LHEF::Reader *reader, ExRootTreeBranch *branch)
|
---|
53 | {
|
---|
54 | const LHEF::HEPEUP &hepeup = reader->hepeup;
|
---|
55 |
|
---|
56 | Int_t particle;
|
---|
57 | Double_t signPz;
|
---|
58 |
|
---|
59 | TLorentzVector momentum;
|
---|
60 |
|
---|
61 | ExRootLHEFParticle *element;
|
---|
62 |
|
---|
63 | for(particle = 0; particle < hepeup.NUP; ++particle)
|
---|
64 | {
|
---|
65 | element = (ExRootLHEFParticle*) branch->NewEntry();
|
---|
66 |
|
---|
67 | element->PID = hepeup.IDUP[particle];
|
---|
68 | element->Status = hepeup.ISTUP[particle];
|
---|
69 | element->Mother1 = hepeup.MOTHUP[particle].first;
|
---|
70 | element->Mother2 = hepeup.MOTHUP[particle].second;
|
---|
71 | element->ColorLine1 = hepeup.ICOLUP[particle].first;
|
---|
72 | element->ColorLine2 = hepeup.ICOLUP[particle].second;
|
---|
73 | element->Px = hepeup.PUP[particle][0];
|
---|
74 | element->Py = hepeup.PUP[particle][1];
|
---|
75 | element->Pz = hepeup.PUP[particle][2];
|
---|
76 | element->E = hepeup.PUP[particle][3];
|
---|
77 | element->M = hepeup.PUP[particle][4];
|
---|
78 |
|
---|
79 | momentum.SetPxPyPzE(element->Px, element->Py, element->Pz, element->E);
|
---|
80 | element->PT = momentum.Perp();
|
---|
81 | signPz = (element->Pz >= 0.0) ? 1.0 : -1.0;
|
---|
82 | element->Eta = element->PT == 0.0 ? signPz*999.9 : momentum.Eta();
|
---|
83 | element->Phi = momentum.Phi();
|
---|
84 |
|
---|
85 | element->Rapidity = element->PT == 0.0 ? signPz*999.9 : momentum.Rapidity();
|
---|
86 |
|
---|
87 | element->LifeTime = hepeup.VTIMUP[particle];
|
---|
88 | element->Spin = hepeup.SPINUP[particle];
|
---|
89 | }
|
---|
90 | }
|
---|
91 |
|
---|
92 | //------------------------------------------------------------------------------
|
---|
93 |
|
---|
94 | int main(int argc, char *argv[])
|
---|
95 | {
|
---|
96 | char *appName = "ExRootLHEFConverter";
|
---|
97 |
|
---|
98 | if(argc != 3)
|
---|
99 | {
|
---|
100 | cout << " Usage: " << appName << " input_file" << " output_file" << endl;
|
---|
101 | cout << " input_file - input file in LHEF format," << endl;
|
---|
102 | cout << " output_file - output file in ROOT format." << endl;
|
---|
103 | return 1;
|
---|
104 | }
|
---|
105 |
|
---|
106 | gROOT->SetBatch();
|
---|
107 |
|
---|
108 | int appargc = 1;
|
---|
109 | char *appargv[] = {appName};
|
---|
110 | TApplication app(appName, &appargc, appargv);
|
---|
111 |
|
---|
112 | // Open a stream connected to an event file:
|
---|
113 | ifstream inputFileStream(argv[1]);
|
---|
114 |
|
---|
115 | // Create the Reader object:
|
---|
116 | LHEF::Reader *inputReader = new LHEF::Reader(inputFileStream);
|
---|
117 |
|
---|
118 | TFile *outputFile = TFile::Open(argv[2], "RECREATE");
|
---|
119 | ExRootTreeWriter *treeWriter = new ExRootTreeWriter(outputFile, "LHEF");
|
---|
120 |
|
---|
121 | // generated event from LHEF
|
---|
122 | ExRootTreeBranch *branchEvent = treeWriter->NewBranch("Event", ExRootLHEFEvent::Class());
|
---|
123 |
|
---|
124 | // generated partons from LHEF
|
---|
125 | ExRootTreeBranch *branchParticle = treeWriter->NewBranch("Particle", ExRootLHEFParticle::Class());
|
---|
126 |
|
---|
127 | cout << "** Calculating number of events to process. Please wait..." << endl;
|
---|
128 | Long64_t allEntries = inputReader->getNumberOfEvents();
|
---|
129 | cout << "** Input file contains " << allEntries << " events" << endl;
|
---|
130 |
|
---|
131 | if(allEntries > 0)
|
---|
132 | {
|
---|
133 | ExRootProgressBar progressBar(allEntries);
|
---|
134 |
|
---|
135 | // Loop over all events
|
---|
136 | Long64_t entry = 0;
|
---|
137 | while(inputReader->readEvent())
|
---|
138 | {
|
---|
139 | treeWriter->Clear();
|
---|
140 |
|
---|
141 | AnalyseEvent(inputReader, branchEvent, entry + 1);
|
---|
142 | AnalyseParticles(inputReader, branchParticle);
|
---|
143 |
|
---|
144 | treeWriter->Fill();
|
---|
145 |
|
---|
146 | progressBar.Update(entry);
|
---|
147 |
|
---|
148 | ++entry;
|
---|
149 | }
|
---|
150 |
|
---|
151 | progressBar.Finish();
|
---|
152 | }
|
---|
153 |
|
---|
154 | treeWriter->Write();
|
---|
155 |
|
---|
156 | cout << "** Exiting..." << endl;
|
---|
157 |
|
---|
158 | delete treeWriter;
|
---|
159 | delete outputFile;
|
---|
160 | delete inputReader;
|
---|
161 | }
|
---|
162 |
|
---|
163 |
|
---|
164 |
|
---|