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 
13 
14 #include <fstream>
15 
16 #include "HepMC3/ReaderAscii.h"
17 #include "HepPID/ParticleName.hh"
18 
22 int main(int /*argc*/, char** /*argv*/) {
24 
25  std::cout << "Preparing reader " << std::flush;
26  HepMC3::ReaderAscii reader("test.hepmc3");
27  if (simReader.status(reader)) {
28  std::cout << "succesful" << std::endl;
29  } else {
30  std::cout << "failed" << std::endl;
31  }
32 
33  std::shared_ptr<HepMC3::GenEvent> genevt(new HepMC3::GenEvent());
34 
35  std::cout << "Reading event " << std::flush;
36  if (simReader.readEvent(reader, genevt)) {
37  std::cout << "succesful" << std::endl;
38  } else {
39  std::cout << "failed" << std::endl;
40  }
41  std::cout << std::endl;
42 
44 
45  std::cout << "Event data:" << std::endl;
46  std::cout << "Units: ";
47  if (simEvent.momentumUnit(genevt) == Acts::UnitConstants::GeV)
48  std::cout << "[GEV], ";
49  else if (simEvent.momentumUnit(genevt) == Acts::UnitConstants::MeV)
50  std::cout << "[MeV], ";
51  if (simEvent.lengthUnit(genevt) == Acts::UnitConstants::mm)
52  std::cout << "[mm]" << std::endl;
53  else if (simEvent.lengthUnit(genevt) == Acts::UnitConstants::cm)
54  std::cout << "[cm]" << std::endl;
55  Acts::Vector3D evtPos = simEvent.eventPos(genevt);
56  std::cout << "Event position: " << evtPos(0) << ", " << evtPos(1) << ", "
57  << evtPos(2) << std::endl;
58  std::cout << "Event time: " << simEvent.eventTime(genevt) << std::endl;
59 
60  std::cout << "Beam particles: ";
61  std::vector<std::unique_ptr<ActsExamples::SimParticle>> beam =
62  simEvent.beams(genevt);
63  if (beam.empty())
64  std::cout << "none" << std::endl;
65  else {
66  for (auto& pbeam : beam)
67  std::cout << HepPID::particleName(pbeam->pdg()) << " ";
68  std::cout << std::endl;
69  }
70 
71  std::cout << std::endl << "Vertices: ";
72  std::vector<std::unique_ptr<ActsExamples::SimVertex>> vertices =
73  simEvent.vertices(genevt);
74  if (vertices.empty())
75  std::cout << "none" << std::endl;
76  else {
77  std::cout << std::endl;
78  for (auto& vertex : vertices) {
79  for (auto& particle : vertex->incoming)
80  std::cout << HepPID::particleName(particle.pdg()) << " ";
81  std::cout << "-> ";
82  for (auto& particle : vertex->outgoing)
83  std::cout << HepPID::particleName(particle.pdg()) << " ";
84  std::cout << "\t@(" << vertex->time() << ", " << vertex->position()(0)
85  << ", " << vertex->position()(1) << ", "
86  << vertex->position()(2) << ")" << std::endl;
87  }
88  std::cout << std::endl;
89  }
90 
91  std::cout << "Total particle record:" << std::endl;
92  std::vector<std::unique_ptr<ActsExamples::SimParticle>> particles =
93  simEvent.particles(genevt);
94  for (auto& particle : particles)
95  std::cout << HepPID::particleName(particle->pdg())
96  << "\tID:" << particle->particleId() << ", momentum: ("
97  << particle->momentum4()(0) << ", " << particle->momentum4()(1)
98  << ", " << particle->momentum4()(2)
99  << "), mass: " << particle->mass() << std::endl;
100 
101  std::cout << std::endl << "Initial to final state: ";
102  std::vector<std::unique_ptr<ActsExamples::SimParticle>> fState =
103  simEvent.finalState(genevt);
104  for (auto& pbeam : beam)
105  std::cout << HepPID::particleName(pbeam->pdg()) << " ";
106  std::cout << "-> ";
107  for (auto& fs : fState)
108  std::cout << HepPID::particleName(fs->pdg()) << " ";
109  std::cout << std::endl;
110 }