ATLAS Offline Software
EnergyLossRecorder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // EnergyLossRecorder.cxx, (c) ATLAS Detector software
8 
10 #include "G4Step.hh"
11 #include "G4StepPoint.hh"
12 #include "G4ThreeVector.hh"
13 #include "G4Material.hh"
14 #include "G4Element.hh"
15 #include "G4TouchableHistory.hh"
16 #include "G4LogicalVolume.hh"
17 // TrkValInterfaces
20 
21 namespace G4UA
22 {
23 
25  : m_config(config)
26  , m_entries(0)
27  {
28 
29  }
30 
31  // FIXME: Why implement run action if empty?
33  {
34  }
35 
37  {
38  }
39 
41  {
42  }
43 
45  {
46  if (m_config.pmWriter) {
47  // FIXME: thread-unsafe usage of a component in a thread-local action?
48  // See ATLASSIM-3562.
50  }
51  m_entries = 0;
52  }
53 
54  void EnergyLossRecorder::UserSteppingAction(const G4Step* aStep)
55  {
56  // kill secondary particles
57  if (aStep->GetTrack()->GetParentID()) {
58  aStep->GetTrack()->SetTrackStatus(fStopAndKill);
59  return;
60  }
61  if(!m_config.pmWriter) return;
62  // we require a minimum amount of material for recording the step
63 
64  // the material information
65  const G4TouchableHistory* touchHist = static_cast<const G4TouchableHistory*>(aStep->GetPreStepPoint()->GetTouchable());
66  // G4LogicalVolume
67  const G4LogicalVolume *lv= touchHist ? touchHist->GetVolume()->GetLogicalVolume() : nullptr;
68  const G4Material *mat = lv ? lv->GetMaterial() : nullptr;
69 
70  // log the information // cut off air
71  if (mat && mat->GetRadlen() < 200000.) {
72  // keep primary particles - calculate the kinematics for them
73  G4ThreeVector pos = aStep->GetPreStepPoint()->GetPosition();
74  double px = aStep->GetPreStepPoint()->GetMomentum().x();
75  double py = aStep->GetPreStepPoint()->GetMomentum().y();
76  double pz = aStep->GetPreStepPoint()->GetMomentum().z();
77  Amg::Vector3D position(pos.x(),pos.y(),pos.z());
79 
80  // record the starting parameters at the first step
81  if (m_entries==0) {
82  // increase the counter
83  ++m_entries;
84  double m = aStep->GetTrack()->GetDynamicParticle()->GetMass();
85  int pdgCode = aStep->GetTrack()->GetDynamicParticle()->GetPDGcode();
86  m_config.pmWriter->initializeTrack(position,momentum,m,pdgCode);
87  }
88  else {
90  }
91  }
92  }
93 
94 } // namespace G4UA
G4UA::EnergyLossRecorder::BeginOfEventAction
virtual void BeginOfEventAction(const G4Event *) override
Definition: EnergyLossRecorder.cxx:40
test_pyathena.px
px
Definition: test_pyathena.py:18
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
G4UA
for nSW
Definition: CalibrationDefaultProcessing.h:19
mat
GeoMaterial * mat
Definition: LArDetectorConstructionTBEC.cxx:55
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
GeoPrimitives.h
EnergyLossRecorder.h
ParticleGun_EoverP_Config.momentum
momentum
Definition: ParticleGun_EoverP_Config.py:63
G4UA::EnergyLossRecorder::m_entries
unsigned int m_entries
Definition: EnergyLossRecorder.h:57
G4UA::EnergyLossRecorder::m_config
Config m_config
Definition: EnergyLossRecorder.h:56
Amg::pz
@ pz
Definition: GeoPrimitives.h:40
G4UA::EnergyLossRecorder::EndOfEventAction
virtual void EndOfEventAction(const G4Event *) override
Definition: EnergyLossRecorder.cxx:44
G4UA::EnergyLossRecorder::Config
Definition: EnergyLossRecorder.h:45
Amg::py
@ py
Definition: GeoPrimitives.h:39
G4UA::EnergyLossRecorder::EndOfRunAction
virtual void EndOfRunAction(const G4Run *) override
Definition: EnergyLossRecorder.cxx:36
G4UA::EnergyLossRecorder::EnergyLossRecorder
EnergyLossRecorder(const Config &config)
Definition: EnergyLossRecorder.cxx:24
G4UA::EnergyLossRecorder::Config::pmWriter
Trk::IPositionMomentumWriter * pmWriter
Definition: EnergyLossRecorder.h:46
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
G4UA::EnergyLossRecorder::UserSteppingAction
virtual void UserSteppingAction(const G4Step *) override
Definition: EnergyLossRecorder.cxx:54
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
IPositionMomentumWriter.h
Trk::IPositionMomentumWriter::initializeTrack
virtual void initializeTrack(const Amg::Vector3D &pos, const Amg::Vector3D &mom, double m, int pdg)=0
Initialize State.
Trk::IPositionMomentumWriter::finalizeTrack
virtual void finalizeTrack()=0
Finalization State.
Trk::IPositionMomentumWriter::recordTrackState
virtual void recordTrackState(const Amg::Vector3D &pos, const Amg::Vector3D &mom)=0
Record a single TrackState.
G4UA::EnergyLossRecorder::BeginOfRunAction
virtual void BeginOfRunAction(const G4Run *) override
Definition: EnergyLossRecorder.cxx:32