9#include <G4LogicalVolume.hh>
11#include <G4StepPoint.hh>
13#include <G4UserSteppingAction.hh>
14#include <G4UserTrackingAction.hh>
15#include <G4VProcess.hh>
16#include <G4VSensitiveDetector.hh>
17#include <SHiP/QuantityView.hpp>
18#include <SHiP/SimHit.hpp>
19#include <SHiP/SimParticle.hpp>
20#include <unordered_map>
29inline thread_local std::vector<SimHit>
tl_hits;
31inline thread_local std::unordered_map<int, std::size_t>
tl_track_map;
37 auto* pre = step->GetPreStepPoint();
38 auto pos = pre->GetPosition();
39 auto mom = pre->GetMomentum();
40 auto* lv = pre->GetTouchable()->GetVolume()->GetLogicalVolume();
43 auto it = detector_ids.find(lv);
44 hit.detectorId = it != detector_ids.end() ? it->second : -1;
45 hit.trackId = step->GetTrack()->GetTrackID();
46 hit.pdgCode = step->GetTrack()->GetDefinition()->GetPDGEncoding();
56 : G4VSensitiveDetector(name), detector_ids_{std::move(detector_ids)} {}
58 G4bool
ProcessHits(G4Step* step, G4TouchableHistory*)
override {
59 double edep = step->GetTotalEnergyDeposit();
60 if (edep <= 0)
return false;
79 ship::Energy ke_threshold = ship::Energy::zero())
80 : G4VSensitiveDetector(name),
81 detector_ids_{std::move(detector_ids)},
82 ke_threshold_{
aegir::clhep::g4(ke_threshold)} {}
84 G4bool
ProcessHits(G4Step* step, G4TouchableHistory*)
override {
85 if (!step->IsFirstStepInVolume())
return false;
87 auto* track = step->GetTrack();
88 if (track->GetKineticEnergy() < ke_threshold_)
return false;
91 hit.energyDeposit = 0;
92 ship::view::setPathLength(hit,
100 double ke_threshold_;
108 : ke_threshold_{
aegir::clhep::g4(ke_threshold)} {}
111 auto* track = step->GetTrack();
112 if (track->GetKineticEnergy() < ke_threshold_) {
113 track->SetTrackStatus(fStopAndKill);
118 double ke_threshold_;
124 : particle_ke_cut_{
aegir::clhep::g4(particle_ke_cut)} {}
127 if (particle_ke_cut_ > 0 && track->GetParentID() != 0 &&
128 track->GetKineticEnergy() < particle_ke_cut_)
132 p.trackId = track->GetTrackID();
133 p.parentId = track->GetParentID();
134 p.pdgCode = track->GetDefinition()->GetPDGEncoding();
141 auto* creator = track->GetCreatorProcess();
142 p.creatorProcess = creator ? creator->GetProcessSubType() : 0;
157 double particle_ke_cut_;
Definition geant4_sim_core.hpp:76
G4bool ProcessHits(G4Step *step, G4TouchableHistory *) override
Definition geant4_sim_core.hpp:84
CrossingSD(G4String const &name, DetectorIdMap detector_ids, ship::Energy ke_threshold=ship::Energy::zero())
Definition geant4_sim_core.hpp:78
Definition geant4_sim_core.hpp:105
EnergyCutAction(ship::Energy ke_threshold)
Definition geant4_sim_core.hpp:107
void UserSteppingAction(const G4Step *step) override
Definition geant4_sim_core.hpp:110
Definition geant4_sim_core.hpp:53
ScoringSD(G4String const &name, DetectorIdMap detector_ids)
Definition geant4_sim_core.hpp:55
G4bool ProcessHits(G4Step *step, G4TouchableHistory *) override
Definition geant4_sim_core.hpp:58
Definition geant4_sim_core.hpp:121
void PostUserTrackingAction(const G4Track *track) override
Definition geant4_sim_core.hpp:148
void PreUserTrackingAction(const G4Track *track) override
Definition geant4_sim_core.hpp:126
TrackingAction(ship::Energy particle_ke_cut=ship::Energy::zero())
Definition geant4_sim_core.hpp:123
Definition detector_construction.hpp:30
thread_local std::vector< SimParticle > tl_particles
Definition geant4_sim_core.hpp:30
thread_local std::unordered_map< int, std::size_t > tl_track_map
Definition geant4_sim_core.hpp:31
thread_local std::vector< SimHit > tl_hits
Definition geant4_sim_core.hpp:29
SimHit make_base_hit(G4Step const *step, DetectorIdMap const &detector_ids)
Definition geant4_sim_core.hpp:35
std::unordered_map< G4LogicalVolume *, int > DetectorIdMap
Definition geant4_sim_core.hpp:33
ship::Energy energy(G4double v)
Definition clhep_bridge.hpp:34
ship::Length length(G4double v)
Definition clhep_bridge.hpp:28
ship::Vec3< ship::Length > position(G4ThreeVector const &v)
Definition clhep_bridge.hpp:41
ship::Momentum momentum(G4double v)
Definition clhep_bridge.hpp:38
ship::Time time(G4double v)
Definition clhep_bridge.hpp:31
Definition math_utils.hpp:12