Skip to content

Commit d0435c1

Browse files
committed
Simple template utility macro to read HepMC data
1 parent 9c3f3a9 commit d0435c1

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

MC/utils/hepmc_reader.C

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
void hepmc_reader(const char* fname, int version = 2);
2+
void user_code(const std::vector<TParticle>& particles);
3+
4+
void
5+
hepmc_reader(const char* fname, int version)
6+
{
7+
8+
/** instance and initialise genarator HepMC **/
9+
auto reader = new o2::eventgen::GeneratorHepMC;
10+
reader->setFileName(fname);
11+
reader->setVersion(version);
12+
if (!reader->Init())
13+
return;
14+
15+
/** loop over events **/
16+
while (reader->generateEvent() && reader->importParticles()) {
17+
18+
/** get particles **/
19+
auto& particles = reader->getParticles();
20+
21+
/** execute user code **/
22+
user_code(particles);
23+
24+
}
25+
26+
}
27+
28+
void
29+
user_code(const std::vector<TParticle>& particles)
30+
{
31+
for (auto& particle : particles)
32+
particle.Print();
33+
}
34+

0 commit comments

Comments
 (0)