-
Notifications
You must be signed in to change notification settings - Fork 13
/
AliGenReaderHepMC_dev.cxx
141 lines (122 loc) · 4.49 KB
/
AliGenReaderHepMC_dev.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include <TDatabasePDG.h>
#include <TParticle.h>
#include <TVirtualMC.h>
#include <AliGenPythiaEventHeader.h>
#include <AliLog.h>
#include <AliRun.h>
#include <AliStack.h>
#include "HepMC/GenEvent.h"
#include "HepMC/IO_BaseClass.h"
#include "HepMC/IO_GenEvent.h"
#include "THepMCParser_dev.h"
#include "AliGenReaderHepMC_dev.h"
ClassImp(AliGenReaderHepMC_dev)
AliGenReaderHepMC_dev::AliGenReaderHepMC_dev()
: fEventsHandle(0)
, fGenEvent(0)
, fParticleArray(0)
, fParticleIterator(0)
, fGenEventHeader(0)
{
;
}
AliGenReaderHepMC_dev::AliGenReaderHepMC_dev(const AliGenReaderHepMC_dev& reader)
: AliGenReader(reader)
, fEventsHandle(0)
, fGenEvent(0)
, fParticleArray(0)
, fParticleIterator(0)
, fGenEventHeader(0)
{
reader.Copy(*this);
}
AliGenReaderHepMC_dev& AliGenReaderHepMC_dev::operator=(const AliGenReaderHepMC_dev& rhs)
{
// Assignment operator
rhs.Copy(*this);
return *this;
}
AliGenReaderHepMC_dev::~AliGenReaderHepMC_dev()
{
delete fEventsHandle;
delete fGenEvent;
delete fParticleArray;
delete fParticleIterator;
} // not deleting fGenEventHeader as it is returned out
void AliGenReaderHepMC_dev::Copy(TObject&) const
{
//
// Copy
//
Fatal("Copy", "Not implemented!\n");
}
void AliGenReaderHepMC_dev::Init()
{
// check if file exists
if (access(fFileName, R_OK) != 0)
AliError(Form("Couldn't open input file: %s", fFileName));
// Initialisation
fEventsHandle = new HepMC::IO_GenEvent(fFileName, std::ios::in);
fParticleArray = new TClonesArray("TParticle");
fParticleIterator = new TIter(fParticleArray);
}
Int_t AliGenReaderHepMC_dev::NextEvent()
{
// Clean memory
if (fGenEvent) delete fGenEvent;
// Read the next event
if ((fGenEvent = fEventsHandle->read_next_event())) {
std::string err_mess = THepMCParser_dev::ParseGenEvent2TCloneArray(fGenEvent, fParticleArray, "GEV", "MM", false);
if (!err_mess.empty()) {
AliErrorStream() << "Unable to parse event: " << err_mess << std::endl <<
"Skipping to the next event." << std::endl;
return NextEvent();
}
fParticleIterator->Reset();
THepMCParser_dev::HeavyIonHeader_t heavyIonHeader;
THepMCParser_dev::PdfHeader_t pdfHeader;
THepMCParser_dev::ParseGenEvent2HeaderStructs(fGenEvent, heavyIonHeader, pdfHeader, true, true);
// Here I am going to do a hack. I need an event header that can hold information such as cross section and pt hard
AliGenPythiaEventHeader* pythia_header = new AliGenPythiaEventHeader("HepMC");
fGenEventHeader = pythia_header;
// propagate the event weight from HepMC to the event header
HepMC::WeightContainer weights = fGenEvent->weights();
if (!weights.empty()) pythia_header->SetEventWeight(weights.front());
HepMC::GenCrossSection* cross_section = fGenEvent->cross_section();
if (cross_section) {
pythia_header->SetXsection(cross_section->cross_section() / 1.0e9); // pb -> mb
AliDebugStream(2) << "Cross section is " << cross_section->cross_section() << " pb" << std::endl;
}
else {
AliDebugStream(2) << "Cross section object not valid." << std::endl;
}
pythia_header->SetPtHard(fGenEvent->event_scale()); // careful here: using the "event scale" instead of the pt hard
pythia_header->SetTrials(1);
AliDebugStream(1) << "Parsed event " << fGenEvent->event_number() << " with " << fGenEvent->particles_size() << " particles, weight = " << fGenEventHeader->EventWeight() << std::endl;
// convert time from [mm/c] to [s]
const Double_t conv = 0.0001 / 2.99792458e8;
fParticleIterator->Reset();
Int_t npart = fParticleArray->GetEntries();
for (Int_t i = 0; i < npart; i++) {
TParticle* particle = (TParticle*)fParticleIterator->Next();
particle->SetProductionVertex(particle->Vx(), particle->Vy(), particle->Vz(), particle->T() * conv);
}
fParticleIterator->Reset();
return npart;
}
AliWarningStream() << "No more events in the file." << std::endl;
return 0;
}
TParticle* AliGenReaderHepMC_dev::NextParticle()
{
// Read next particle
TParticle* particle = (TParticle*)fParticleIterator->Next();
if (particle && particle->GetStatusCode() == 1) {
particle->SetBit(kTransportBit);
}
return particle;
}
void AliGenReaderHepMC_dev::RewindEvent()
{
fParticleIterator->Reset();
}