ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HepMC3Example.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file HepMC3Example.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2018 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #include <fstream>
10 
15 #include "HepMC3/ReaderAscii.h"
16 #include "HepPID/ParticleName.hh"
17 
21 int main(int argc, char* argv[]) {
22  FW::HepMC3ReaderAscii simReader;
23 
24  std::cout << "Preparing reader " << std::flush;
25  HepMC3::ReaderAscii reader("test.hepmc3");
26  if (simReader.status(reader)) {
27  std::cout << "succesful" << std::endl;
28  } else {
29  std::cout << "failed" << std::endl;
30  }
31 
32  std::shared_ptr<HepMC3::GenEvent> genevt(new HepMC3::GenEvent());
33 
34  std::cout << "Reading event " << std::flush;
35  if (simReader.readEvent(reader, genevt)) {
36  std::cout << "succesful" << std::endl;
37  } else {
38  std::cout << "failed" << std::endl;
39  }
40  std::cout << std::endl;
41 
42  FW::HepMC3Event simEvent;
43 
44  std::cout << "Event data:" << std::endl;
45  std::cout << "Units: ";
46  if (simEvent.momentumUnit(genevt) == Acts::units::_GeV)
47  std::cout << "[GEV], ";
48  else if (simEvent.momentumUnit(genevt) == Acts::units::_MeV)
49  std::cout << "[MeV], ";
50  if (simEvent.lengthUnit(genevt) == Acts::units::_mm)
51  std::cout << "[mm]" << std::endl;
52  else if (simEvent.lengthUnit(genevt) == Acts::units::_cm)
53  std::cout << "[cm]" << std::endl;
54  Acts::Vector3D evtPos = simEvent.eventPos(genevt);
55  std::cout << "Event position: " << evtPos(0) << ", " << evtPos(1) << ", "
56  << evtPos(2) << std::endl;
57  std::cout << "Event time: " << simEvent.eventTime(genevt) << std::endl;
58 
59  std::cout << "Beam particles: ";
60  std::vector<std::unique_ptr<FW::SimParticle>> beam = simEvent.beams(genevt);
61  if (beam.empty())
62  std::cout << "none" << std::endl;
63  else {
64  for (auto& pbeam : beam)
65  std::cout << HepPID::particleName(pbeam->pdg()) << " ";
66  std::cout << std::endl;
67  }
68 
69  std::cout << std::endl << "Vertices: ";
70  std::vector<std::unique_ptr<FW::SimVertex>> vertices =
71  simEvent.vertices(genevt);
72  if (vertices.empty())
73  std::cout << "none" << std::endl;
74  else {
75  std::cout << std::endl;
76  for (auto& vertex : vertices) {
77  for (auto& particle : vertex->incoming)
78  std::cout << HepPID::particleName(particle.pdg()) << " ";
79  std::cout << "-> ";
80  for (auto& particle : vertex->outgoing)
81  std::cout << HepPID::particleName(particle.pdg()) << " ";
82  std::cout << "\t@(" << vertex->time() << ", " << vertex->position()(0)
83  << ", " << vertex->position()(1) << ", "
84  << vertex->position()(2) << ")" << std::endl;
85  }
86  std::cout << std::endl;
87  }
88 
89  std::cout << "Total particle record:" << std::endl;
90  std::vector<std::unique_ptr<FW::SimParticle>> particles =
91  simEvent.particles(genevt);
92  for (auto& particle : particles)
93  std::cout << HepPID::particleName(particle->pdg())
94  << "\tID:" << particle->particleId() << ", momentum: ("
95  << particle->momentum4()(0) << ", " << particle->momentum4()(1)
96  << ", " << particle->momentum4()(2)
97  << "), mass: " << particle->mass() << std::endl;
98 
99  std::cout << std::endl << "Initial to final state: ";
100  std::vector<std::unique_ptr<FW::SimParticle>> fState =
101  simEvent.finalState(genevt);
102  for (auto& pbeam : beam)
103  std::cout << HepPID::particleName(pbeam->pdg()) << " ";
104  std::cout << "-> ";
105  for (auto& fs : fState)
106  std::cout << HepPID::particleName(fs->pdg()) << " ";
107  std::cout << std::endl;
108 }