EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EventAction.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EventAction.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-2020 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 "EventAction.hpp"
10 
11 #include <stdexcept>
12 
13 #include <G4Event.hh>
14 #include <G4RunManager.hh>
15 
17 #include "SteppingAction.hpp"
18 
19 using namespace ActsExamples;
20 
22 
24  return s_instance;
25 }
26 
27 EventAction::EventAction() : G4UserEventAction() {
28  if (s_instance) {
29  throw std::logic_error("Attempted to duplicate the EventAction singleton");
30  } else {
31  s_instance = this;
32  }
33 }
34 
36  s_instance = nullptr;
37 }
38 
39 void EventAction::BeginOfEventAction(const G4Event*) {
40  // reset the collection of material steps
42 }
43 
44 void EventAction::EndOfEventAction(const G4Event* event) {
45  const auto* rawPos = event->GetPrimaryVertex();
46  // access the initial direction of the track
47  G4ThreeVector rawDir = PrimaryGeneratorAction::instance()->direction();
48  // create the RecordedMaterialTrack
50  mtrecord.first.first =
51  Acts::Vector3D(rawPos->GetX0(), rawPos->GetY0(), rawPos->GetZ0());
52  mtrecord.first.second = Acts::Vector3D(rawDir.x(), rawDir.y(), rawDir.z());
53  mtrecord.second.materialInteractions =
55 
56  // write out the RecordedMaterialTrack of one event
57  m_materialTracks.push_back(mtrecord);
58 }
59 
62  m_materialTracks.clear();
63 }
64 
69 const std::vector<Acts::RecordedMaterialTrack>& EventAction::materialTracks()
70  const {
71  return m_materialTracks;
72 }