LDMX Software
TrigScintSD.cxx
1#include "SimCore/SDs/TrigScintSD.h"
2
3/*~~~~~~~~~~~~~~*/
4/* DetDescr */
5/*~~~~~~~~~~~~~~*/
6#include "DetDescr/TrigScintID.h"
7
8/*~~~~~~~~~~~~*/
9/* Geant4 */
10/*~~~~~~~~~~~~*/
11#include "G4Step.hh"
12#include "G4StepPoint.hh"
13
14namespace simcore {
15
16TrigScintSD::TrigScintSD(const std::string& name,
19 : SensitiveDetector(name, ci, p) {
20 module_id_ = p.getParameter<int>("module_id");
21 collection_name_ = p.getParameter<std::string>("collection_name");
22 vol_name_ = p.getParameter<std::string>("volume_name");
23}
24
25G4bool TrigScintSD::ProcessHits(G4Step* step, G4TouchableHistory* history) {
26 // Get the energy deposited by the particle during the step
27 auto energy{step->GetTotalEnergyDeposit()};
28
29 // If a non-Geantino particle doesn't deposit energy during the step,
30 // skip processing it.
31 if (energy == 0 and not isGeantino(step)) return false;
32
33 // Create a new instance of a calorimeter hit
34 // emplace_back returns a *reference* to the hit that was constructed
35 // and we should keep that reference so that we are editing the correct hit
36 ldmx::SimCalorimeterHit& hit = hits_.emplace_back();
37
38 G4StepPoint* prePoint = step->GetPreStepPoint();
39 G4StepPoint* postPoint = step->GetPostStepPoint();
40 if (prePoint == nullptr || postPoint == nullptr) {
41 return false;
42 }
43
44 // A Geant4 "touchable" is a way to uniquely identify a particular volume,
45 // short for touchable detector element. See the detector definition and
46 // response section of the Geant4 application developers manual for details.
47 //
48 // The TouchableHandle is just a reference counted pointer to a
49 // G4TouchableHistory object, which is a concrete implementation of a
50 // G4Touchable interface.
51 if (!prePoint->GetTouchableHandle()) {
52 return false;
53 }
54 auto touchableHistory{prePoint->GetTouchableHandle()->GetHistory()};
55 // Affine transform for converting between local and global coordinates
56 auto topTransform{touchableHistory->GetTopTransform()};
57 // Set the hit position
58 auto position{0.5 * (prePoint->GetPosition() + postPoint->GetPosition())};
59
60 // Convert the center of the bar to its corresponding global position
61 auto volumePosition{topTransform.Inverse().TransformPoint(G4ThreeVector())};
62 hit.setPosition(position[0], position[1], volumePosition.z());
63
64 // Get the track associated with this step
65 auto track{step->GetTrack()};
66
67 // Set the ID on the hit.
68 auto bar{track->GetVolume()->GetCopyNo()};
70 hit.setID(id.raw());
71
72 // add single contrib to this calorimeter hit
73 // IncidentID - this track's ID
74 // Track ID
75 // PDG ID
76 // energy deposited
77 // global time of this hit
78 hit.addContrib(track->GetTrackID(), track->GetTrackID(),
79 track->GetParticleDefinition()->GetPDGEncoding(), energy,
80 track->GetGlobalTime());
81
82 // Step details
83 hit.setPathLength(step->GetStepLength());
84 hit.setVelocity(track->GetVelocity());
85 // Convert pre/post step position from global coordinates to coordinates
86 // within the scintillator bar
87 const auto localPreStepPoint{
88 topTransform.TransformPoint(prePoint->GetPosition())};
89 const auto localPostStepPoint{
90 topTransform.TransformPoint(postPoint->GetPosition())};
91 hit.setPreStepPosition(localPreStepPoint[0], localPreStepPoint[1],
92 localPreStepPoint[2]);
93
94 hit.setPostStepPosition(localPostStepPoint[0], localPostStepPoint[1],
95 localPostStepPoint[2]);
96
97 hit.setPreStepTime(prePoint->GetGlobalTime());
98 hit.setPostStepTime(postPoint->GetGlobalTime());
99
100 return true;
101}
102
103} // namespace simcore
104
105DECLARE_SENSITIVEDETECTOR(simcore::TrigScintSD)
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:27
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:89
Stores simulated calorimeter hit information.
void setPreStepTime(const float time)
Set global pre-step time of the hit [ns].
void setPathLength(const float length)
Set the physical path length for the interaction [mm].
void setPosition(const float x, const float y, const float z)
Set the XYZ position of the hit [mm].
void addContrib(int incidentID, int trackID, int pdgCode, float edep, float time)
Add a hit contribution from a SimParticle.
void setPostStepPosition(const float x, const float y, const float z)
Set the XYZ post-step position of the hit in the coordinate frame of the sensitive volume [mm].
void setID(const int id)
Set the detector ID.
void setPostStepTime(const float time)
Set global post-step time of the hit [ns].
void setPreStepPosition(const float x, const float y, const float z)
Set the XYZ pre-step position of the hit in the coordinate frame of the sensitive volume [mm].
void setVelocity(float velocity)
Set the velocity of the track [mm/ns].
Class that defines the detector ID of the trigger scintillator.
Definition TrigScintID.h:14
Handle to the conditions system, provided at construction to classes which require it.
Dynamically loaded Geant4 SensitiveDetector for saving hits in specific volumes within the simulation...
bool isGeantino(const G4Step *step) const
Check if the passed step is a step of a geantino.
Class defining a sensitive detector of type trigger scintillator.
Definition TrigScintSD.h:12
std::string vol_name_
name of trigger pad volume this SD is capturing
Definition TrigScintSD.h:65
G4bool ProcessHits(G4Step *step, G4TouchableHistory *history) override
Process steps to create hits.
std::string collection_name_
name of the hit collection for this SD
Definition TrigScintSD.h:63
std::vector< ldmx::SimCalorimeterHit > hits_
our collection of hits in this SD
Definition TrigScintSD.h:61
TrigScintSD(const std::string &name, simcore::ConditionsInterface &ci, const framework::config::Parameters &p)
Class constructor.
int module_id_
the ID number for the module we are gathering hits from
Definition TrigScintSD.h:67