LDMX Software
TrackerSD.cxx
1#include "SimCore/SDs/TrackerSD.h"
2// STL
3#include <iostream>
4
5// Geant4
6#include "G4Step.hh"
7#include "G4StepPoint.hh"
8
9namespace simcore {
10
13 : SensitiveDetector(name, ci, p) {
14 subsystem_ = p.getParameter<std::string>("subsystem");
15 collection_name_ = p.getParameter<std::string>("collection_name");
16
17 subDetID_ = ldmx::SubdetectorIDType(p.getParameter<int>("subdet_id"));
18}
19
20G4bool TrackerSD::ProcessHits(G4Step* aStep, G4TouchableHistory*) {
21 // Get the edep from the step.
22 G4double edep = aStep->GetTotalEnergyDeposit();
23
24 // Skip steps with no energy dep which come from non-Geantino particles.
25 if (edep == 0.0 and not isGeantino(aStep)) {
26 if (verboseLevel > 2) {
27 std::cout << "TrackerSD skipping step with zero edep" << std::endl
28 << std::endl;
29 }
30 return false;
31 }
32
33 // Create a new hit object.
34 ldmx::SimTrackerHit& hit{hits_.emplace_back()};
35
36 // Assign track ID for finding the SimParticle in post event processing.
37 hit.setTrackID(aStep->GetTrack()->GetTrackID());
38
39 // Set the edep.
40 hit.setEdep(edep);
41
42 // Set the start position.
43 G4StepPoint* prePoint = aStep->GetPreStepPoint();
44 // hit->setStartPosition(prePoint->GetPosition());
45
46 // Set the end position.
47 G4StepPoint* postPoint = aStep->GetPostStepPoint();
48 // hit->setEndPosition(postPoint->GetPosition());
49
50 G4ThreeVector start = prePoint->GetPosition();
51 G4ThreeVector end = postPoint->GetPosition();
52
53 // Set the mid position.
54 G4ThreeVector mid = 0.5 * (start + end);
55 hit.setPosition(mid.x(), mid.y(), mid.z());
56
57 // Compute path length.
58 G4double pathLength =
59 sqrt(pow(start.x() - end.x(), 2) + pow(start.y() - end.y(), 2) +
60 pow(start.z() - end.z(), 2));
61 hit.setPathLength(pathLength);
62
63 // Set the global time.
64 hit.setTime(aStep->GetTrack()->GetGlobalTime());
65
66 /*
67 * Compute and set the momentum.
68 */
69 G4ThreeVector p = postPoint->GetMomentum();
70 hit.setMomentum(p.x(), p.y(), p.z());
71
72 /*
73 * Set the 32-bit ID on the hit.
74 */
75 int copyNum =
76 prePoint->GetTouchableHandle()->GetHistory()->GetVolume(2)->GetCopyNo();
77 int layer = copyNum / 10;
78 int module = copyNum % 10;
79 ldmx::TrackerID id(subDetID_, layer, module);
80 hit.setID(id.raw());
81 hit.setLayerID(layer);
82 hit.setModuleID(module);
83
84 // Set energy and pdg code of SimParticle (common things requested)
85 hit.setEnergy(postPoint->GetTotalEnergy());
86 hit.setPdgID(aStep->GetTrack()->GetDynamicParticle()->GetPDGcode());
87
88 return true;
89}
90
91} // namespace simcore
92
93DECLARE_SENSITIVEDETECTOR(simcore::TrackerSD)
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
Represents a simulated tracker hit in the simulation.
void setTrackID(const int simTrackID)
Set the Sim particle track ID of the hit.
Extension of DetectorID providing access to layer and module number for tracker IDs.
Definition TrackerID.h:20
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.
Basic sensitive detector for trackers.
Definition TrackerSD.h:14
G4bool ProcessHits(G4Step *step, G4TouchableHistory *history) override
Process a step by creating a hit.
Definition TrackerSD.cxx:20
std::string subsystem_
The name of the subsystem we are apart of.
Definition TrackerSD.h:58
std::string collection_name_
The name of the output collection.
Definition TrackerSD.h:61
ldmx::SubdetectorIDType subDetID_
The detector ID.
Definition TrackerSD.h:67
TrackerSD(const std::string &name, simcore::ConditionsInterface &ci, const framework::config::Parameters &p)
Class constructor.
Definition TrackerSD.cxx:11
std::vector< ldmx::SimTrackerHit > hits_
The collection of hits.
Definition TrackerSD.h:64