]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TEvtGen/THepMCParser.cxx
Compilation on MacOS with clang
[u/mrichter/AliRoot.git] / TEvtGen / THepMCParser.cxx
CommitLineData
cb3eff76 1// module identifier line...
2// Author: Brian Thorsbro, 24/6-2014
3
4#include <iostream>
5#include <sstream>
6#include <string>
7#include <list>
8#include <set>
9#include <time.h>
10
11#include "THepMCParser.h"
12#include "HepMC/IO_GenEvent.h"
13#include "TObject.h"
14#include "TTree.h"
15#include "TClonesArray.h"
16#include "TFile.h"
17#include "TParticle.h"
18#include "TDatabasePDG.h"
71c3b2be 19#include "HepMC/IO_GenEvent.h"
cb3eff76 20
21using namespace std;
22
23
24THepMCParser::THepMCParser(const char * infile) : fTree(0)
25{
26 HepMC::IO_BaseClass * events = new HepMC::IO_GenEvent(infile, std::ios::in);
27 init(events);
28 delete events;
29 events = 0; // nullptr
30}
31THepMCParser::THepMCParser(HepMC::IO_BaseClass * events) : fTree(0)
32{
33 init(events);
34}
35void THepMCParser::init(HepMC::IO_BaseClass * events)
36{
37 int particlecount = 0;
38 fTree = new TTree("treeEPOS","Tree EPOS");
39 TClonesArray * array = new TClonesArray("TParticle");
40 // array->BypassStreamer();
41 fTree->Branch("Particles",&array); // more flags?
42 THepMCParser::HeavyIonHeader_t heavyIonHeader;
43 fTree->Branch("HeavyIonInfo", &heavyIonHeader, THepMCParser::fgHeavyIonHeaderBranchString);
44 THepMCParser::PdfHeader_t pdfHeader;
45 fTree->Branch("PdfInfo", &pdfHeader, THepMCParser::fgPdfHeaderBranchString);
46 HepMC::GenEvent* evt = 0; // nullptr
47 while ((evt = events->read_next_event())) {
48 string errMsg1 = ParseGenEvent2TCloneArray(evt,array);
49 string errMsg2 = ParseGenEvent2HeaderStructs(evt,heavyIonHeader,pdfHeader);
50 if (errMsg1.length() == 0 && errMsg2.length() == 0) {
51 fTree->Fill();
52 } else {
53 if (errMsg1.length() != 0) cerr << errMsg1 << endl;
54 if (errMsg2.length() != 0) cerr << errMsg2 << endl;
55 }
56 particlecount += array->Capacity();
57 }
58// array->Clear();
59// delete array;
60// array = 0; // nullptr
61 cout << " parsed " << particlecount << " particles" << endl;
62}
63
64
65TTree * THepMCParser::GetTTree()
66{
67 return fTree;
68}
69void THepMCParser::WriteTTreeToFile(const char *outfile)
70{
71 TFile * f = new TFile(outfile, "recreate");
72 fTree->Write();
73 delete f;
74 f = 0; // nullptr
75}
76
77
78
79// Based on a validator written by Peter Hristov, CERN
80bool THepMCParser::IsValidMotherDaughtersConsitency(bool useStdErr, bool requireSecondMotherBeforeDaughters)
81{
82 bool valid = true;
83 TClonesArray * array = new TClonesArray("TParticle");
84 TBranch* branch = fTree->GetBranch("Particles");
85 branch->SetAddress(&array);
86 Int_t count = branch->GetEntries();
87 for (Int_t idx=0; idx<count; ++idx) {
88 array->Clear();
89 branch->GetEntry(idx); // "fill" the array
90 Int_t nkeep = array->GetEntriesFast();
91 for (Int_t i=0; i<nkeep; i++) {
92 TParticle * part = (TParticle*)array->AddrAt(i);
93 Int_t mum1 = part->GetFirstMother();
94 Int_t mum2 = part->GetSecondMother();
95 Int_t fd = part->GetFirstDaughter();
96 Int_t ld = part->GetLastDaughter();
97 if (mum1>-1 && i<mum1) {
98 valid = false;
99 if (useStdErr) cerr << "Problem: first_mother(" << mum1 << ") after daughter(" << i << ")" << endl;
100 }
101 if (mum2>-1 && i<mum2 && requireSecondMotherBeforeDaughters) {
102 valid = false;
103 if (useStdErr) cerr << "Problem: second_mother(" << mum2 << ") after daughter(" << i << ")" << endl;
104 }
105 if (fd > ld ) {
106 valid = false;
107 if (useStdErr) cerr << "Problem: first_daughter(" << fd << ") > last_daughter(" << ld << ")" << endl;
108 }
109 for (Int_t id=TMath::Max(fd,0); id<=ld; id++) {
110 TParticle * daughter = (TParticle*)array->AddrAt(id);
111 if (daughter->GetFirstMother() != i && daughter->GetSecondMother() != i) {
112 valid = false;
113 if (useStdErr) cerr << "Problem: mother("<< i << ") not registered as mother for either first_daughter("
114 << daughter->GetFirstMother() << ") or second_daughter("
115 << daughter->GetSecondMother() << ")" << endl;
116 }
117 }
118 }
119 }
120 delete array;
121 array = 0;
122 return valid;
123}
124
125bool THepMCParser::IsValidParticleInvariantMass(bool useStdErr, bool includeStatusCode2Particles)
126{
127 bool valid = true;
128 TClonesArray *array = new TClonesArray("TParticle");
129 TBranch* branch = fTree->GetBranch("Particles");
130 branch->SetAddress(&array);
131 Int_t count = branch->GetEntries();
132 for (Int_t idx=0; idx<count; ++idx) {
133 array->Clear();
134 branch->GetEntry(idx);
135 Int_t nkeep = array->GetEntries();
136 for (Int_t i=0; i<nkeep; i++) {
137 TParticle * parton = (TParticle*)array->AddrAt(i);
138 if (parton->GetStatusCode()==2 && !includeStatusCode2Particles) {
139 continue;
140 }
141 TLorentzVector v;
142 parton->Momentum(v);
143 Double_t m1 = v.M(); // invariant mass from the particle in the HepMC event
144 TParticlePDG *dbParton = parton->GetPDG();
145 if (!dbParton) {
146 if (useStdErr) cerr << "Warning: could not look up particle with PDG Code: " << parton->GetPdgCode() << endl << endl;
147 continue;
148 }
149 Double_t m2 = dbParton->Mass();
150 bool checkok;
151 if (m2 == 0) {
152 checkok = abs(m1) < 0.0001; // no such thing as negative mass...
153 } else {
154 checkok = abs(1 - m1/m2) < 0.01;
155 }
156 if (!checkok && useStdErr) {
157 cerr << "Problem: " << GetParticleName(parton) << " HepMC:" << m1 << endl;
158 cerr << ListReactionChain(array,i);
159 cerr << endl;
160 }
161 if (!checkok)
162 valid = false;
163 }
164 }
165 delete array;
166 array = 0;
167 return valid;
168}
169
170bool THepMCParser::IsValidVertexInvariantMass(bool useStdErr, bool includeStatusCode2Particles)
171{
172 bool valid = true;
173 TClonesArray * array = new TClonesArray("TParticle");
174 TBranch* branch = fTree->GetBranch("Particles");
175 branch->SetAddress(&array);
176 Int_t count = branch->GetEntries();
177 for (Int_t idx=0; idx<count; ++idx) {
178 array->Clear();
179 branch->GetEntry(idx); // "fill" the array
180 TLorentzVector v_st1;
181 TLorentzVector v_st4;
182 Int_t nkeep = array->GetEntriesFast();
183 for (Int_t i=0; i<nkeep; i++) {
184 TParticle * parton = (TParticle*)array->AddrAt(i);
185 TLorentzVector v_in;
186 parton->Momentum(v_in);
187 if (parton->GetStatusCode()==4) {
188 v_st4 += v_in;
189 } else if (parton->GetStatusCode()==1) {
190 v_st1 += v_in;
191 }
192 if (!includeStatusCode2Particles) { // only check beam particles vs final particles
193 continue;
194 }
195 Int_t fd = parton->GetFirstDaughter();
196 Int_t ld = parton->GetLastDaughter();
197 if (fd == -1) continue; // no daughters, continue loop
198 Int_t mother2 = -1;
199 TLorentzVector v_out;
200 bool oneok = false; bool allok = true; bool agreemother2 = true;
201 ostringstream daughterpdg;
202 ostringstream motherpdg;
203 for (Int_t id=TMath::Max(fd,0); id<=ld; id++) {
204 TParticle * daughter = (TParticle*)array->AddrAt(id);
205 if (fd==id) {
206 daughter->Momentum(v_out);
207 mother2 = daughter->GetSecondMother();
208 } else {
209 TLorentzVector d;
210 daughter->Momentum(d);
211 v_out += d;
212 if (daughter->GetSecondMother() != mother2) agreemother2 = false;
213 }
214 if (daughter->GetFirstMother() == i) {
215 oneok = true;
216 } else {
217 allok = false;
218 }
219 daughterpdg << " " << daughter->GetPdgCode();
220 }
221 motherpdg << " " << parton->GetPdgCode();
222 if (mother2 > -1 && agreemother2) {
223 TParticle * m2 = (TParticle*)array->AddrAt(mother2);
224 TLorentzVector m2v;
225 m2->Momentum(m2v);
226 v_in += m2v;
227 motherpdg << " " << m2->GetPdgCode();
228 }
229 if (oneok && allok && agreemother2) {
230 bool checkok = abs(1 - v_in.M()/v_out.M()) < 0.1;
231 if (!checkok) valid=false;
232 if (!checkok && useStdErr) {
233 // cerr << "Problem: " << i << "[" << fd << "," << ld << "] PDG:" << motherpdg.str() << " ->" << daughterpdg.str() << " Inv.mass: " << v_in.M() << " -> " << v_out.M() << endl;
234 cerr << ListReactionChain(array,i);
235 cerr << endl;
236 // cerr << v_in.Px() << " " << v_in.Py() << " " << v_in.Pz() << " " << v_in.E() << endl;
237 } else if (useStdErr) {
238 // cerr << "OK: " << i << "[" << fd << "," << ld << "] PDG:" << motherpdg.str() << " ->" << daughterpdg.str() << " Inv.mass: " << v_in.M() << " -> " << v_out.M() << endl;
239 }
240 }
241 }
242 bool checkok = abs(1 - v_st4.M()/v_st1.M()) < 0.001;
243 if (!checkok) valid=false;
244 if (!checkok && useStdErr) {
245 cerr << " BEAM PARTICLES -> FINAL PARTICLES " << endl;
246 cerr << " status 4 (" << v_st4.M() << ") -> status 1 (" << v_st1.M() << ")" << endl << endl;
247 }
248 }
249 delete array;
250 array = 0;
251 return valid;
252}
253
254string THepMCParser::GetParticleName(TParticle * thisPart)
255{
256 TParticlePDG *dbPart = thisPart->GetPDG();
257 ostringstream name;
258 if (dbPart) {
259 name << dbPart->GetName() << "(" << dbPart->PdgCode() << "," << dbPart->Mass() << ")";
260 } else {
261 name << thisPart->GetPdgCode() << "(NoDBinfo)";
262 }
263 return name.str();
264}
265
266string THepMCParser::ListReactionChain(TClonesArray * particles, Int_t particleId)
267{
268 ostringstream output;
269
270 TParticle * part = (TParticle*)particles->AddrAt(particleId);
271 Int_t m1id = part->GetFirstMother();
272 Int_t m2id = part->GetSecondMother();
273 if (m1id > 1) { // ignore the initial collision with beam particles
274 ostringstream inStr;
275 ostringstream outStr;
276 TParticle * m1 = (TParticle*)particles->AddrAt(m1id);
277 TLorentzVector v_in;
278 m1->Momentum(v_in);
279 inStr << GetParticleName(m1) << "[" << v_in.M() << "]";
280 if (m2id > 1) {
281 TParticle * m2 = (TParticle*)particles->AddrAt(m2id);
282 TLorentzVector v_m2;
283 m2->Momentum(v_m2);
284 v_in += v_m2;
285 inStr << " " << GetParticleName(m2) << "[" << v_m2.M() << "]";
286 }
287 Int_t fd = m1->GetFirstDaughter();
288 Int_t ld = m1->GetLastDaughter();
289 TLorentzVector v_out;
290 part->Momentum(v_out);
291 outStr << GetParticleName(part) << "[" << v_out.M() << "]";
292 for (Int_t i=fd; i<=ld; ++i) {
293 if (i!=particleId) {
294 TParticle * d = (TParticle*)particles->AddrAt(i);
295 TLorentzVector v_d;
296 d->Momentum(v_d);
297 v_out += v_d;
298 outStr << " " << GetParticleName(d) << "[" << v_d.M() << "]";
299 }
300 }
301 output << "Parent reaction, inv mass: " << v_in.M() << " -> " << v_out.M() << endl;
302 output << " - partons: " << inStr.str() << " -> " << outStr.str() << endl;
303 }
304 Int_t fd = part->GetFirstDaughter();
305 Int_t ld = part->GetLastDaughter();
306 if (fd > -1) {
307 ostringstream inStr;
308 ostringstream outStr;
309 TLorentzVector v_in;
310 part->Momentum(v_in);
311 inStr << GetParticleName(part) << "[" << v_in.M() << "]";
312
313 TParticle * f = (TParticle*)particles->AddrAt(fd);
314 m2id = f->GetSecondMother();
315 if (m2id == particleId) {
316 m2id = f->GetFirstMother();
317 }
318 if (m2id > -1) {
319 TParticle * m2 = (TParticle*)particles->AddrAt(m2id);
320 TLorentzVector v_m2;
321 m2->Momentum(v_m2);
322 v_in += v_m2;
323 inStr << " " << GetParticleName(m2) << "[" << v_m2.M() << "]";
324 }
325 TLorentzVector v_out;
326 f->Momentum(v_out);
327 outStr << GetParticleName(f) << "[" << v_out.M() << "]";
328 for (Int_t i=fd+1; i<=ld; ++i) {
329 TParticle * d = (TParticle*)particles->AddrAt(i);
330 TLorentzVector v_d;
331 d->Momentum(v_d);
332 v_out += v_d;
333 outStr << " " << GetParticleName(d) << "[" << v_d.M() << "]";
334 }
335 output << "Child reaction, inv mass: " << v_in.M() << " -> " << v_out.M() << endl;
336 output << " - partons: " << inStr.str() << " -> " << outStr.str() << endl;
337 } else {
338 output << "Child reaction" << endl << " - none" << endl;
339 }
340
341 return output.str();
342}
343
344
345string THepMCParser::ParseGenEvent2TCloneArray(HepMC::GenEvent * genEvent, TClonesArray * array, bool requireSecondMotherBeforeDaughters)
346{
347 if (requireSecondMotherBeforeDaughters) {
348 return "requireSecondMotherBeforeDaughters not implemented yet!";
349 }
350 array->Clear();
351 ostringstream errMsgStream;
352 map<int,Int_t> partonMemory; // unordered_map in c++11 - but probably not much performance gain from that: log(n) vs log(1) where constant can be high
353
354 // Check event with HepMC's internal validation algorithm
355 if (!genEvent->is_valid()) {
356 errMsgStream << "Error with event id: " << genEvent->event_number() << ", event is not valid!";
357 return errMsgStream.str();
358 }
359
360 // Pull out the beam particles from the event
361 const pair<HepMC::GenParticle *,HepMC::GenParticle *> beamparts = genEvent->beam_particles();
362
363 // Four sanity checks:
364 // - Beam particles exists and are not the same
365 // - Both beam particles should have no production vertices, they come from the beams
366 // - Both beam particles should have defined end vertices, as they both should contribute
367 // - Both beam particles should have the exact same end vertex
368 if (!beamparts.first || !beamparts.second || beamparts.first->barcode()==beamparts.second->barcode()) {
369 errMsgStream << "Error with event id: " << genEvent->event_number() << ", beam particles doesn't exists or are the same";
370 return errMsgStream.str();
371 }
372 if (beamparts.first->production_vertex() || beamparts.second->production_vertex()) {
373 errMsgStream << "Error with event id: " << genEvent->event_number() << ", beam particles have production vertex/vertices...";
374 return errMsgStream.str();
375 }
376 if (!beamparts.first->end_vertex() || !beamparts.second->end_vertex()) {
377 errMsgStream << "Error with event id: " << genEvent->event_number() << ", beam particles have undefined end vertex/vertices...";
378 return errMsgStream.str();
379 }
380 if (beamparts.first->end_vertex() != beamparts.second->end_vertex()) {
381 errMsgStream << "Error with event id: " << genEvent->event_number() << ", beam particles do not collide in the same end vertex.";
382 return errMsgStream.str();
383 }
384
385 // Set the array to hold the number of particles in the event
386 array->Expand(genEvent->particles_size());
387
388 // Create a TParticle for each beam particle
389 new((*array)[0]) TParticle(
390 beamparts.first->pdg_id(),
391 beamparts.first->status(), // check if status has the same meaning
392 -1, // no mother1
393 -1, // no mother2
394 -1, // first daughter not known yet
395 -1, // last daughter not known yet
396 beamparts.first->momentum().px(),
397 beamparts.first->momentum().py(),
398 beamparts.first->momentum().pz(),
399 beamparts.first->momentum().e(),
400 0, // no production vertex, so zero?
401 0,
402 0,
403 0
404 );
405 partonMemory[beamparts.first->barcode()] = 0;
406 new((*array)[1]) TParticle(
407 beamparts.second->pdg_id(),
408 beamparts.second->status(),
409 -1, // no mother1
410 -1, // no mother2
411 -1, // first daughter not known yet
412 -1, // last daughter not known yet
413 beamparts.second->momentum().px(),
414 beamparts.second->momentum().py(),
415 beamparts.second->momentum().pz(),
416 beamparts.second->momentum().e(),
417 0, // no production vertex, so zero?
418 0,
419 0,
420 0
421 );
422 partonMemory[beamparts.second->barcode()] = 1;
423 Int_t arrayID = 2; // start counting IDs after the beam particles
424
425 // Do first vertex as a special case for performance, since its often has the most daughters and both mothers are known
426 Int_t firstDaughter = arrayID;
427 for (HepMC::GenVertex::particles_out_const_iterator iter = beamparts.first->end_vertex()->particles_out_const_begin();
428 iter != beamparts.first->end_vertex()->particles_out_const_end();
429 ++iter) {
430 new((*array)[arrayID]) TParticle(
431 (*iter)->pdg_id(),
432 (*iter)->status(),
433 0, // beam particle 1
434 1, // beam particle 2
435 -1, // first daughter not known yet
436 -1, // last daughter not known yet
437 (*iter)->momentum().px(),
438 (*iter)->momentum().py(),
439 (*iter)->momentum().pz(),
440 (*iter)->momentum().e(),
441 beamparts.first->end_vertex()->position().x(),
442 beamparts.first->end_vertex()->position().y(),
443 beamparts.first->end_vertex()->position().z(),
444 beamparts.first->end_vertex()->position().t()
445 );
446 partonMemory[(*iter)->barcode()] = arrayID;
447 ++arrayID;
448 }
449 Int_t lastDaughter = arrayID-1;
450 ((TParticle*)array->AddrAt(0))->SetFirstDaughter(firstDaughter); // beam particle 1
451 ((TParticle*)array->AddrAt(0))->SetLastDaughter(lastDaughter);
452 ((TParticle*)array->AddrAt(1))->SetFirstDaughter(firstDaughter); // beam particle 2
453 ((TParticle*)array->AddrAt(1))->SetLastDaughter(lastDaughter);
454
455 // Build vertex list by exploring tree and sorting such that daughters comes after mothers
456 list<HepMC::GenVertex*> vertexList;
457 set<int> vertexSearchSet;
458 ExploreVertex(beamparts.first->end_vertex(),vertexList,vertexSearchSet,requireSecondMotherBeforeDaughters);
459
460 // Analyze each vertex
461 for (list<HepMC::GenVertex*>::iterator i = vertexList.begin(); i != vertexList.end(); ++i) {
462 HepMC::GenVertex * vertex = (*i);
463
464 // first establish mother relations
465 HepMC::GenVertex::particles_in_const_iterator iter = vertex->particles_in_const_begin();
466 if (iter == vertex->particles_in_const_end()) {
467 return "Particle without a mother, and its not a beam particle!";
468 }
469 int motherA = partonMemory[(*iter)->barcode()];
470 if (((TParticle*)array->AddrAt(motherA))->GetFirstDaughter() > -1) {
471 return "Trying to assign new daughters to a particle that already has daughters defined!";
472 }
473 ++iter;
474 int motherB = -1;
475 if (iter != vertex->particles_in_const_end()) {
476 motherB = partonMemory[(*iter)->barcode()];
477 if (((TParticle*)array->AddrAt(motherB))->GetFirstDaughter() > -1) {
478 return "Trying to assign new daughters to a particle that already has daughters defined!";
479 }
480 ++iter;
481 if (iter != vertex->particles_in_const_end()) {
482 return "Particle with more than two mothers!";
483 }
484 }
485 if (motherB > -1 && motherB < motherA) {
486 int swap = motherA; motherA = motherB; motherB = swap;
487 }
488
489 // add the particles to the array, important that they are add in succession with respect to arrayID
490 firstDaughter = arrayID;
491 for (iter = vertex->particles_out_const_begin();
492 iter != vertex->particles_out_const_end();
493 ++iter) {
494 new((*array)[arrayID]) TParticle(
495 (*iter)->pdg_id(),
496 (*iter)->status(),
497 motherA, // mother 1
498 motherB, // mother 2
499 -1, // first daughter, if applicable, not known yet
500 -1, // last daughter, if applicable, not known yet
501 (*iter)->momentum().px(),
502 (*iter)->momentum().py(),
503 (*iter)->momentum().pz(),
504 (*iter)->momentum().e(),
505 vertex->position().x(),
506 vertex->position().y(),
507 vertex->position().z(),
508 vertex->position().t()
509 );
510 partonMemory[(*iter)->barcode()] = arrayID;
511 ++arrayID;
512 }
513 lastDaughter = arrayID-1;
514 if (lastDaughter < firstDaughter) {
515 return "Vertex with no out particles, should not be possible!";
516 }
517 // update mother with daughter interval
518 ((TParticle*)array->AddrAt(motherA))->SetFirstDaughter(firstDaughter);
519 ((TParticle*)array->AddrAt(motherA))->SetLastDaughter(lastDaughter);
520 if (motherB > -1) {
521 ((TParticle*)array->AddrAt(motherB))->SetFirstDaughter(firstDaughter);
522 ((TParticle*)array->AddrAt(motherB))->SetLastDaughter(lastDaughter);
523 }
524 }
525
526 return "";
527}
528
529
530void THepMCParser::ExploreVertex(HepMC::GenVertex * vertex, list<HepMC::GenVertex*> & vertexList, set<int> & vertexSearchSet, bool requireSecondMotherBeforeDaughters)
531{
532 for (HepMC::GenVertex::particles_out_const_iterator iter = vertex->particles_out_const_begin();
533 iter != vertex->particles_out_const_end();
534 ++iter) {
535 HepMC::GenVertex * testVertex = (*iter)->end_vertex();
536 if (testVertex) {
537 bool foundVertex = vertexSearchSet.find((*iter)->end_vertex()->barcode()) != vertexSearchSet.end();
538 if (requireSecondMotherBeforeDaughters) {
539 // redo this algorithem to move subtree instead of node....
540 // its not completely error proof in its current implementation even though the error is extremely rare
541
542 if (foundVertex) for (list<HepMC::GenVertex*>::iterator i = vertexList.begin(); i != vertexList.end(); ++i) {
543 if ((*i)->barcode() == testVertex->barcode()) {
544 vertexList.erase(i);
545 cout << " it happened, the vertex parsing order had to be changed " << endl;
546 break;
547 }
548 } else {
549 vertexSearchSet.insert((*iter)->end_vertex()->barcode());
550 }
551 vertexList.push_back(testVertex);
552 if (!foundVertex) ExploreVertex(testVertex,vertexList,vertexSearchSet,requireSecondMotherBeforeDaughters);
553
554 } else {
555 if (!foundVertex) {
556 vertexSearchSet.insert((*iter)->end_vertex()->barcode());
557 vertexList.push_back(testVertex);
558 ExploreVertex(testVertex,vertexList,vertexSearchSet,requireSecondMotherBeforeDaughters);
559 }
560 }
561 }
562 }
563}
564
565
566
567const char * THepMCParser::fgHeavyIonHeaderBranchString = "Ncoll_hard/I:Npart_proj:Npart_targ:Ncoll:spectator_neutrons:spectator_protons:N_Nwounded_collisions:Nwounded_N_collisions:Nwounded_Nwounded_collisions:impact_parameter/F:event_plane_angle:eccentricity:sigma_inel_NN";
568const char * THepMCParser::fgPdfHeaderBranchString = "id1/I:id2:pdf_id1:pdf_id2:x1/D:x2:scalePDF:pdf1:pdf2";
569
570string THepMCParser::ParseGenEvent2HeaderStructs(HepMC::GenEvent * genEvent, HeavyIonHeader_t & heavyIonHeader, PdfHeader_t & pdfHeader, bool fillZeroOnMissingHeavyIon, bool fillZeroOnMissingPdf)
571{
572 HepMC::HeavyIon * heavyIon = genEvent->heavy_ion();
573 HepMC::PdfInfo * pdfInfo = genEvent->pdf_info();
574 if ((!heavyIon && !fillZeroOnMissingHeavyIon) || (!pdfInfo && !fillZeroOnMissingPdf)) {
575 return "HeavyIonInfo and/or PdfInfo not defined for this event, did you read it with IO_GenEvent?";
576 }
577 if (heavyIon) {
578 heavyIonHeader.Ncoll_hard = heavyIon->Ncoll_hard();
579 heavyIonHeader.Npart_proj = heavyIon->Npart_proj();
580 heavyIonHeader.Npart_targ = heavyIon->Npart_targ();
581 heavyIonHeader.Ncoll = heavyIon->Ncoll();
582 heavyIonHeader.spectator_neutrons = heavyIon->spectator_neutrons();
583 heavyIonHeader.spectator_protons = heavyIon->spectator_protons();
584 heavyIonHeader.N_Nwounded_collisions = heavyIon->N_Nwounded_collisions();
585 heavyIonHeader.Nwounded_N_collisions = heavyIon->Nwounded_N_collisions();
586 heavyIonHeader.Nwounded_Nwounded_collisions = heavyIon->Nwounded_Nwounded_collisions();
587 heavyIonHeader.impact_parameter = heavyIon->impact_parameter();
588 heavyIonHeader.event_plane_angle = heavyIon->event_plane_angle();
589 heavyIonHeader.eccentricity = heavyIon->eccentricity();
590 heavyIonHeader.sigma_inel_NN = heavyIon->sigma_inel_NN();
591 } else {
592 heavyIonHeader.Ncoll_hard = 0;
593 heavyIonHeader.Npart_proj = 0;
594 heavyIonHeader.Npart_targ = 0;
595 heavyIonHeader.Ncoll = 0;
596 heavyIonHeader.spectator_neutrons = 0;
597 heavyIonHeader.spectator_protons = 0;
598 heavyIonHeader.N_Nwounded_collisions = 0;
599 heavyIonHeader.Nwounded_N_collisions = 0;
600 heavyIonHeader.Nwounded_Nwounded_collisions = 0;
601 heavyIonHeader.impact_parameter = 0.0;
602 heavyIonHeader.event_plane_angle = 0.0;
603 heavyIonHeader.eccentricity = 0.0;
604 heavyIonHeader.sigma_inel_NN = 0.0;
605 }
606 if (pdfInfo) {
607 pdfHeader.id1 = pdfInfo->id1();
608 pdfHeader.id2 = pdfInfo->id2();
609 pdfHeader.pdf_id1 = pdfInfo->pdf_id1();
610 pdfHeader.pdf_id2 = pdfInfo->pdf_id2();
611 pdfHeader.x1 = pdfInfo->x1();
612 pdfHeader.x2 = pdfInfo->x2();
613 pdfHeader.scalePDF = pdfInfo->scalePDF();
614 pdfHeader.pdf1 = pdfInfo->pdf1();
615 pdfHeader.pdf2 = pdfInfo->pdf2();
616 } else {
617 pdfHeader.id1 = 0;
618 pdfHeader.id2 = 0;
619 pdfHeader.pdf_id1 = 0;
620 pdfHeader.pdf_id2 = 0;
621 pdfHeader.x1 = 0.0;
622 pdfHeader.x2 = 0.0;
623 pdfHeader.scalePDF = 0.0;
624 pdfHeader.pdf1 = 0.0;
625 pdfHeader.pdf2 = 0.0;
626 }
627 return "";
628}
629
630
631
632
633
634
635