LDMX Software
ScoringPlaneSD.cxx
1
2#include "SimCore/SDs/ScoringPlaneSD.h"
3
4#include "DetDescr/SimSpecialID.h"
5
6/*----------------*/
7/* C++ StdLib */
8/*----------------*/
9#include <iostream>
10
11/*~~~~~~~~~~~~*/
12/* Geant4 */
13/*~~~~~~~~~~~~*/
14#include "G4ChargedGeantino.hh"
15#include "G4Geantino.hh"
16#include "G4SDManager.hh"
17#include "G4Step.hh"
18#include "G4StepPoint.hh"
19
20namespace simcore {
21
22ScoringPlaneSD::ScoringPlaneSD(const std::string& name,
25 : SensitiveDetector(name, ci, params) {
26 collection_name_ = params.getParameter<std::string>("collection_name");
27 match_substr_ = params.getParameter<std::string>("match_substr");
28}
29
30G4bool ScoringPlaneSD::ProcessHits(G4Step* step, G4TouchableHistory* history) {
31 // Get the edep from the step.
32 G4double edep = step->GetTotalEnergyDeposit();
33
34 // Create a new hit object.
35 ldmx::SimTrackerHit& hit{hits_.emplace_back()};
36
37 // Assign track ID for finding the SimParticle in post event processing.
38 hit.setTrackID(step->GetTrack()->GetTrackID());
39 hit.setPdgID(step->GetTrack()->GetDynamicParticle()->GetPDGcode());
40
41 // Set the edep.
42 hit.setEdep(edep);
43
44 // Set the start position.
45 G4StepPoint* prePoint = step->GetPreStepPoint();
46
47 // Set the end position.
48 G4StepPoint* postPoint = step->GetPostStepPoint();
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(step->GetTrack()->GetGlobalTime());
65
66 // Set the momentum
67 G4ThreeVector p = postPoint->GetMomentum();
68 hit.setMomentum(p.x(), p.y(), p.z());
69 hit.setEnergy(postPoint->GetTotalEnergy());
70
71 /*
72 * Set the 32-bit ID on the hit.
73 */
74 int cpNumber = prePoint->GetTouchableHandle()->GetCopyNumber();
76 hit.setID(id.raw());
77
78 return true;
79}
80
84
85} // namespace simcore
86
87DECLARE_SENSITIVEDETECTOR(simcore::ScoringPlaneSD)
Implements an event buffer system for storing event data.
Definition Event.h:41
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
Implements detector ids for special simulation-derived hits like scoring planes.
static SimSpecialID ScoringPlaneID(int plane)
Create a scoring id from pieces.
Represents a simulated tracker hit in the simulation.
void setTrackID(const int simTrackID)
Set the Sim particle track ID of the hit.
Handle to the conditions system, provided at construction to classes which require it.
Class defining a basic sensitive detector for scoring planes.
std::string collection_name_
Name of output collection to add.
ScoringPlaneSD(const std::string &name, simcore::ConditionsInterface &ci, const framework::config::Parameters &params)
Constructor.
std::vector< ldmx::SimTrackerHit > hits_
The actual output collection.
virtual G4bool ProcessHits(G4Step *step, G4TouchableHistory *hist) override
This is Geant4's handle to tell us that a particle has stepped through our sensitive detector and we ...
virtual void saveHits(framework::Event &event) override
We are given the event bus here and we must decide now what to persist into the event.
std::string match_substr_
Substring to match to logical volumes.
Dynamically loaded Geant4 SensitiveDetector for saving hits in specific volumes within the simulation...