ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MMSteppingAction.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MMSteppingAction.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-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 
10 
11 #include <stdexcept>
12 
13 #include "Acts/Utilities/Units.hpp"
14 #include "G4Material.hh"
15 #include "G4Step.hh"
16 
18  nullptr;
19 
21  // Static acces function via G4RunManager
22  return fgInstance;
23 }
24 
27  m_steps(),
28  m_tracksteps()
29 // m_volMgr(MaterialRunAction::Instance()->getGeant4VolumeManager())
30 {
31  if (fgInstance) {
32  throw std::logic_error("Attempted to duplicate a singleton");
33  } else {
34  fgInstance = this;
35  }
36 }
37 
39  fgInstance = nullptr;
40 }
41 
43  // get the material
45 
46  if (material && material->GetName() != "Vacuum" &&
47  material->GetName() != "Air") {
48  // go through the elements of the material & weigh it with its fraction
49  const G4ElementVector* elements = material->GetElementVector();
50  const G4double* fraction = material->GetFractionVector();
51  size_t nElements = material->GetNumberOfElements();
52  double A = 0.;
53  double Z = 0.;
54  double X0 = material->GetRadlen();
55  double L0 = material->GetNuclearInterLength();
56  double rho = material->GetDensity() * CLHEP::mm3 / CLHEP::gram;
57  double steplength = step->GetStepLength() / CLHEP::mm;
58  if (nElements == 1) {
59  A = material->GetA() * CLHEP::mole / CLHEP::gram;
60  Z = material->GetZ();
61  } else {
62  for (size_t i = 0; i < nElements; i++) {
63  A += elements->at(i)->GetA() * fraction[i] * CLHEP::mole / CLHEP::gram;
64  Z += elements->at(i)->GetZ() * fraction[i];
65  }
66  }
67 
68  /* G4cout << *material << G4endl;
69  G4cout << "----G4StepMaterial----" << G4endl;
71  G4cout << "Material: " << material->GetName() << G4endl;
72  G4cout << "X0: " << X0 << G4endl;
73  G4cout << "L0: " << L0 << G4endl;
74  G4cout << "A: " << A << G4endl;
75  G4cout << "Z: " << Z << G4endl;
76  G4cout << "rho: " << rho << G4endl;
77  G4cout << "steplength: " << steplength << G4endl;*/
78 
79  // create the RecordedMaterialProperties
80  const auto& rawPos = step->GetPreStepPoint()->GetPosition();
81  Acts::MaterialInteraction mInteraction;
82  mInteraction.position = Acts::Vector3D(rawPos.x(), rawPos.y(), rawPos.z());
83  mInteraction.materialProperties =
84  Acts::MaterialProperties(X0, L0, A, Z, rho, steplength);
85  m_steps.push_back(mInteraction);
86 
87  // // Get the track associated to the step
88  // G4Track* track = step->GetTrack();
89  // const auto& trkPos = track->GetPosition();
90  // const auto& trkTime = track->GetGlobalTime();
91  // // Get the particle from the track
92  // const auto& par = track->GetDynamicParticle();
93  // std::string parName = track->GetDefinition()->GetParticleName();
94  // const auto& par4Mom = par->Get4Momentum();
95  //
96  // if (track->GetTrackID() == 1) { // only consider primary tracks
97  // /*G4cout <<
98  // "px: " << par4Mom.px() << "\t" <<
99  // "py: " << par4Mom.py() << "\t" <<
100  // "pz: " << par4Mom.pz() << "\t" <<
101  // "e: " << par4Mom.e() << G4endl;
102  //
103  // G4cout <<
104  // "x: " << trkPos.x() << "\t" <<
105  // "y: " << trkPos.y() << "\t" <<
106  // "z: " << trkPos.z() << "\t" <<
107  // "t: " << trkTime << G4endl;
108  // */
109  //
110  // m_tracksteps.emplace_back(
111  // 0,
112  // 0, // set Acts::GeometryID = 0 and Barcode = 0
113  // Acts::ActsVectorD<4>(trkPos.x() * Acts::UnitConstants::mm,
114  // trkPos.y() * Acts::UnitConstants::mm,
115  // trkPos.z() * Acts::UnitConstants::mm,
116  // trkTime * Acts::UnitConstants::ns), // pos4
117  // Acts::ActsVectorD<4>(
118  // par4Mom.px() * Acts::UnitConstants::MeV,
119  // par4Mom.py() * Acts::UnitConstants::MeV,
120  // par4Mom.pz() * Acts::UnitConstants::MeV,
121  // par4Mom.e() * Acts::UnitConstants::MeV), // before4
122  // Acts::ActsVectorD<4>(0, 0, 0, 0)); // after4
123  // }
124  }
125 }
126 
128  m_steps.clear();
129  m_tracksteps.clear();
130 }