Fork me on GitHub

source: git/classes/DelphesLHEFReader.cc@ ae5b7b7

3.4.3pre06
Last change on this file since ae5b7b7 was 77e9ae1, checked in by Pavel Demin <pavel-demin@…>, 6 years ago

set Standard to Cpp03 in .clang-format

  • Property mode set to 100644
File size: 7.5 KB
RevLine 
[b443089]1/*
2 * Delphes: a framework for fast simulation of a generic collider experiment
3 * Copyright (C) 2012-2014 Universite catholique de Louvain (UCL), Belgium
[1fa50c2]4 *
[b443089]5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
[1fa50c2]9 *
[b443089]10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
[1fa50c2]14 *
[b443089]15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
[d7d2da3]19/** \class DelphesLHEFReader
20 *
21 * Reads LHEF file
22 *
23 * \author P. Demin - UCL, Louvain-la-Neuve
24 *
25 */
26
27#include "classes/DelphesLHEFReader.h"
28
29#include <iostream>
30#include <sstream>
[341014c]31#include <stdexcept>
[d7d2da3]32
33#include <stdio.h>
34
35#include "TDatabasePDG.h"
36#include "TLorentzVector.h"
[341014c]37#include "TObjArray.h"
38#include "TParticlePDG.h"
39#include "TStopwatch.h"
[d7d2da3]40
41#include "classes/DelphesClasses.h"
42#include "classes/DelphesFactory.h"
43#include "classes/DelphesStream.h"
44
45#include "ExRootAnalysis/ExRootTreeBranch.h"
46
47using namespace std;
48
[c6667c0]49static const int kBufferSize = 16384;
[d7d2da3]50
51//---------------------------------------------------------------------------
52
53DelphesLHEFReader::DelphesLHEFReader() :
54 fInputFile(0), fBuffer(0), fPDG(0),
[341014c]55 fEventReady(kFALSE), fEventCounter(-1), fParticleCounter(-1), fCrossSection(1)
[01f9722]56
[d7d2da3]57{
58 fBuffer = new char[kBufferSize];
59
60 fPDG = TDatabasePDG::Instance();
61}
62
63//---------------------------------------------------------------------------
64
65DelphesLHEFReader::~DelphesLHEFReader()
66{
67 if(fBuffer) delete[] fBuffer;
68}
69
70//---------------------------------------------------------------------------
71
72void DelphesLHEFReader::SetInputFile(FILE *inputFile)
73{
74 fInputFile = inputFile;
75}
76
77//---------------------------------------------------------------------------
78
79void DelphesLHEFReader::Clear()
80{
[0dc0eeb]81 fEventReady = kFALSE;
[d7d2da3]82 fEventCounter = -1;
83 fParticleCounter = -1;
[986d9d5]84 fWeightList.clear();
[d7d2da3]85}
86
87//---------------------------------------------------------------------------
88
89bool DelphesLHEFReader::EventReady()
90{
[0dc0eeb]91 return fEventReady;
[d7d2da3]92}
93
94//---------------------------------------------------------------------------
95
96bool DelphesLHEFReader::ReadBlock(DelphesFactory *factory,
97 TObjArray *allParticleOutputArray,
98 TObjArray *stableParticleOutputArray,
99 TObjArray *partonOutputArray)
100{
[986d9d5]101 int rc, id;
[0dc0eeb]102 char *pch;
[1d9c62a]103 double weight, xsec;
[d7d2da3]104
105 if(!fgets(fBuffer, kBufferSize, fInputFile)) return kFALSE;
106
[be42bf4]107 if(strstr(fBuffer, "<event>"))
[d7d2da3]108 {
109 Clear();
110 fEventCounter = 1;
111 }
112 else if(fEventCounter > 0)
113 {
[0dc0eeb]114 DelphesStream bufferStream(fBuffer);
115
[d7d2da3]116 rc = bufferStream.ReadInt(fParticleCounter)
117 && bufferStream.ReadInt(fProcessID)
118 && bufferStream.ReadDbl(fWeight)
119 && bufferStream.ReadDbl(fScalePDF)
120 && bufferStream.ReadDbl(fAlphaQED)
121 && bufferStream.ReadDbl(fAlphaQCD);
122
123 if(!rc)
124 {
[341014c]125 cerr << "** ERROR: "
126 << "invalid event format" << endl;
[d7d2da3]127 return kFALSE;
128 }
129
130 --fEventCounter;
131 }
132 else if(fParticleCounter > 0)
133 {
[0dc0eeb]134 DelphesStream bufferStream(fBuffer);
135
[d7d2da3]136 rc = bufferStream.ReadInt(fPID)
137 && bufferStream.ReadInt(fStatus)
138 && bufferStream.ReadInt(fM1)
139 && bufferStream.ReadInt(fM2)
140 && bufferStream.ReadInt(fC1)
141 && bufferStream.ReadInt(fC2)
142 && bufferStream.ReadDbl(fPx)
143 && bufferStream.ReadDbl(fPy)
144 && bufferStream.ReadDbl(fPz)
145 && bufferStream.ReadDbl(fE)
146 && bufferStream.ReadDbl(fMass);
147
148 if(!rc)
149 {
[341014c]150 cerr << "** ERROR: "
151 << "invalid particle format" << endl;
[d7d2da3]152 return kFALSE;
153 }
154
155 AnalyzeParticle(factory, allParticleOutputArray,
156 stableParticleOutputArray, partonOutputArray);
157
158 --fParticleCounter;
159 }
[0dc0eeb]160 else if(strstr(fBuffer, "<wgt"))
161 {
[986d9d5]162 pch = strpbrk(fBuffer, "\"'");
[0dc0eeb]163 if(!pch)
164 {
[341014c]165 cerr << "** ERROR: "
166 << "invalid weight format" << endl;
[0dc0eeb]167 return kFALSE;
168 }
169
[986d9d5]170 DelphesStream idStream(pch + 1);
171 rc = idStream.ReadInt(id);
172
173 pch = strchr(fBuffer, '>');
174 if(!pch)
175 {
[341014c]176 cerr << "** ERROR: "
177 << "invalid weight format" << endl;
[986d9d5]178 return kFALSE;
179 }
180
181 DelphesStream weightStream(pch + 1);
182 rc = weightStream.ReadDbl(weight);
[0dc0eeb]183
184 if(!rc)
185 {
[341014c]186 cerr << "** ERROR: "
187 << "invalid weight format" << endl;
[0dc0eeb]188 return kFALSE;
189 }
190
[986d9d5]191 fWeightList.push_back(make_pair(id, weight));
[0dc0eeb]192 }
[1d9c62a]193 else if(strstr(fBuffer, "<xsecinfo"))
194 {
195 pch = strstr(fBuffer, "totxsec");
196 if(!pch)
197 {
[341014c]198 cerr << "** ERROR: "
199 << "invalid cross section format" << endl;
[1d9c62a]200 return kFALSE;
201 }
202
203 pch = strpbrk(pch + 1, "\"'");
204 if(!pch)
205 {
[341014c]206 cerr << "** ERROR: "
207 << "invalid cross section format" << endl;
[1d9c62a]208 return kFALSE;
209 }
210
211 DelphesStream xsecStream(pch + 1);
212 rc = xsecStream.ReadDbl(xsec);
213
214 if(!rc)
215 {
[341014c]216 cerr << "** ERROR: "
217 << "invalid cross section format" << endl;
[1d9c62a]218 return kFALSE;
219 }
220
221 fCrossSection = xsec;
222 }
[0dc0eeb]223 else if(strstr(fBuffer, "</event>"))
224 {
225 fEventReady = kTRUE;
226 }
[d7d2da3]227
228 return kTRUE;
229}
230
231//---------------------------------------------------------------------------
232
233void DelphesLHEFReader::AnalyzeEvent(ExRootTreeBranch *branch, long long eventNumber,
234 TStopwatch *readStopWatch, TStopwatch *procStopWatch)
235{
236 LHEFEvent *element;
237
238 element = static_cast<LHEFEvent *>(branch->NewEntry());
239 element->Number = eventNumber;
240
241 element->ProcessID = fProcessID;
242 element->Weight = fWeight;
[01f9722]243 element->CrossSection = fCrossSection;
244
[d7d2da3]245 element->ScalePDF = fScalePDF;
246 element->AlphaQED = fAlphaQED;
247 element->AlphaQCD = fAlphaQCD;
248
249 element->ReadTime = readStopWatch->RealTime();
250 element->ProcTime = procStopWatch->RealTime();
251}
252
253//---------------------------------------------------------------------------
254
[1e8afcc]255void DelphesLHEFReader::AnalyzeWeight(ExRootTreeBranch *branch)
[0dc0eeb]256{
[986d9d5]257 LHEFWeight *element;
[77e9ae1]258 vector<pair<int, double> >::const_iterator itWeightList;
[0dc0eeb]259
[986d9d5]260 for(itWeightList = fWeightList.begin(); itWeightList != fWeightList.end(); ++itWeightList)
[0dc0eeb]261 {
[986d9d5]262 element = static_cast<LHEFWeight *>(branch->NewEntry());
[0dc0eeb]263
[986d9d5]264 element->ID = itWeightList->first;
265 element->Weight = itWeightList->second;
[0dc0eeb]266 }
267}
268
269//---------------------------------------------------------------------------
270
[d7d2da3]271void DelphesLHEFReader::AnalyzeParticle(DelphesFactory *factory,
272 TObjArray *allParticleOutputArray,
273 TObjArray *stableParticleOutputArray,
274 TObjArray *partonOutputArray)
275{
276 Candidate *candidate;
277 TParticlePDG *pdgParticle;
278 int pdgCode;
279
280 candidate = factory->NewCandidate();
281
282 candidate->PID = fPID;
283 pdgCode = TMath::Abs(candidate->PID);
284
285 candidate->Status = fStatus;
286
287 pdgParticle = fPDG->GetParticle(fPID);
[341014c]288 candidate->Charge = pdgParticle ? int(pdgParticle->Charge() / 3.0) : -999;
[80d4a34]289 candidate->Mass = fMass;
[d7d2da3]290
291 candidate->Momentum.SetPxPyPzE(fPx, fPy, fPz, fE);
292 candidate->Position.SetXYZT(0.0, 0.0, 0.0, 0.0);
293
294 candidate->M1 = fM1 - 1;
295 candidate->M2 = fM2 - 1;
296
297 candidate->D1 = -1;
298 candidate->D2 = -1;
299
300 allParticleOutputArray->Add(candidate);
301
302 if(!pdgParticle) return;
303
[b23e468]304 if(fStatus == 1)
[d7d2da3]305 {
306 stableParticleOutputArray->Add(candidate);
307 }
308 else if(pdgCode <= 5 || pdgCode == 21 || pdgCode == 15)
309 {
310 partonOutputArray->Add(candidate);
311 }
312}
313
314//---------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.