LDMX Software
simcore::EcalSD Class Reference

ECal sensitive detector that uses an EcalHexReadout to create the hits_. More...

#include <EcalSD.h>

Public Member Functions

 EcalSD (const std::string &name, simcore::ConditionsInterface &ci, const framework::config::Parameters &p)
 Class constructor.
 
virtual ~EcalSD ()=default
 Class destructor.
 
virtual bool isSensDet (G4LogicalVolume *vol) const override
 Should the input volume be consider apart of this sensitive detector?
 
G4bool ProcessHits (G4Step *aStep, G4TouchableHistory *ROhist) override
 Process steps to create hits_.
 
virtual void saveHits (framework::Event &event) override
 Add our hits to the event bus.
 
virtual void onFinishedEvent () override
 Clear the map of hits we have accumulated.
 
- Public Member Functions inherited from simcore::SensitiveDetector
 SensitiveDetector (const std::string &name, simcore::ConditionsInterface &ci, const framework::config::Parameters &parameters)
 Constructor.
 
 DECLARE_FACTORY_WITH_WAREHOUSE (SensitiveDetector, SensitiveDetector *, const std::string &, simcore::ConditionsInterface &, const framework::config::Parameters &)
 The SD Factory.
 
virtual ~SensitiveDetector ()=default
 Destructor.
 
virtual void EndOfEvent (G4HCofThisEvent *) override
 This is Geant4's handle to tell us the event is ending.
 

Static Public Attributes

static const std::string COLLECTION_NAME = "EcalSimHits"
 Name of output collection of hits_.
 

Private Attributes

std::map< ldmx::EcalID, ldmx::SimCalorimeterHit > hits_
 map of hits to add to the event (will be squashed)
 
bool enable_hit_contribs_
 enable hit contribs
 
bool compress_hit_contribs_
 compress hit contribs
 
int max_origin_track_id_
 maximum track ID to be considered an "origin"
 

Additional Inherited Members

- Protected Member Functions inherited from simcore::SensitiveDetector
template<class T >
const T & getCondition (const std::string &condition_name)
 Record the configuration of this detector into the run header.
 
bool isGeantino (const G4Step *step) const
 Check if the passed step is a step of a geantino.
 
const TrackMap & getTrackMap () const
 Get a handle to the current track map.
 
 enableLogging ("SensitiveDetector")
 Enable logging for this class.
 

Detailed Description

ECal sensitive detector that uses an EcalHexReadout to create the hits_.

Definition at line 29 of file EcalSD.h.

Constructor & Destructor Documentation

◆ EcalSD()

simcore::EcalSD::EcalSD ( const std::string & name,
simcore::ConditionsInterface & ci,
const framework::config::Parameters & p )

Class constructor.

Parameters
nameThe name of the sensitive detector.
theCollectionNameThe name of the hits collection.
subDetIDThe subdetector ID.

Definition at line 12 of file EcalSD.cxx.

14 : SensitiveDetector(name, ci, p) {
15 enable_hit_contribs_ = p.get<bool>("enable_hit_contribs");
16 compress_hit_contribs_ = p.get<bool>("compress_hit_contribs");
17 max_origin_track_id_ = p.get<int>("max_origin_track_id");
18}
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:75
int max_origin_track_id_
maximum track ID to be considered an "origin"
Definition EcalSD.h:86
bool enable_hit_contribs_
enable hit contribs
Definition EcalSD.h:82
bool compress_hit_contribs_
compress hit contribs
Definition EcalSD.h:84
SensitiveDetector(const std::string &name, simcore::ConditionsInterface &ci, const framework::config::Parameters &parameters)
Constructor.

References compress_hit_contribs_, enable_hit_contribs_, framework::config::Parameters::get(), and max_origin_track_id_.

Member Function Documentation

◆ isSensDet()

virtual bool simcore::EcalSD::isSensDet ( G4LogicalVolume * vol) const
inlineoverridevirtual

Should the input volume be consider apart of this sensitive detector?

Note
Dependent on names defined in GDML!

Implements simcore::SensitiveDetector.

Definition at line 53 of file EcalSD.h.

53 {
54 auto region = vol->GetRegion();
55 if (region and region->GetName().contains("CalorimeterRegion")) {
56 return vol->GetName().contains("Si");
57 }
58 return false;
59 }

◆ onFinishedEvent()

virtual void simcore::EcalSD::onFinishedEvent ( )
inlineoverridevirtual

Clear the map of hits we have accumulated.

Implements simcore::SensitiveDetector.

Definition at line 76 of file EcalSD.h.

76{ hits_.clear(); }
std::map< ldmx::EcalID, ldmx::SimCalorimeterHit > hits_
map of hits to add to the event (will be squashed)
Definition EcalSD.h:80

References hits_.

◆ ProcessHits()

G4bool simcore::EcalSD::ProcessHits ( G4Step * aStep,
G4TouchableHistory * ROhist )
overridevirtual

Process steps to create hits_.

Parameters
aStepThe step information.
ROhistThe readout history.

DEBUG this printout is helpful when developing the GDML and/or EcalGeometry since Geant4 will probe where exactly the GDML sensitive volumes are std::cout << "(" << position[0] << ", " << position[1] << ", " << position[2] << ") " << cpynum << " -> layer " << layerNumber << " module " << module_position << std::endl;

Implements simcore::SensitiveDetector.

Definition at line 20 of file EcalSD.cxx.

20 {
21 static const int layer_depth = 2; // index depends on GDML implementation
22 const auto& geometry = getCondition<ldmx::EcalGeometry>(
23 ldmx::EcalGeometry::CONDITIONS_OBJECT_NAME);
24
25 // Get the edep from the step.
26 G4double edep = aStep->GetTotalEnergyDeposit();
27
28 // Skip steps with no energy dep which come from non-Geantino particles.
29 if (edep == 0.0 and not isGeantino(aStep)) {
30 ldmx_log(trace) << "CalorimeterSD skipping step with zero edep.";
31 return false;
32 }
33
34 // Compute the hit position
35 G4StepPoint* pre_point = aStep->GetPreStepPoint();
36 G4StepPoint* post_point = aStep->GetPostStepPoint();
37 G4ThreeVector position =
38 0.5 * (pre_point->GetPosition() + post_point->GetPosition());
39
40 // Create the ID for the hit.
41 int cpynum{0}; // Initialize cpynum to 0
42
43 auto pre_step_point = aStep->GetPreStepPoint();
44 if (pre_step_point) {
45 const auto& touchable_handle = pre_step_point->GetTouchableHandle();
46 if (touchable_handle) {
47 auto history = touchable_handle->GetHistory();
48 if (history) {
49 auto volume = history->GetVolume(layer_depth);
50 if (volume) {
51 cpynum = volume->GetCopyNo();
52 }
53 }
54 }
55 }
56 int layer_number;
57 layer_number = cpynum / 7;
58 int module_position = cpynum % 7;
70 // fastest, but need to trust module number between GDML and EcalGeometry
71 // match
72 ldmx::EcalID id =
73 geometry.getID(position.x(), position.y(), layer_number, module_position);
74
75 // medium, only need to trust z-layer positions in GDML and EcalGeometry match
76 // helpful for debugging any issues where transverse position is not
77 // matching between the GDML and EcalGeometry
78 // ldmx::EcalID id = geometry.getID(position[0], position[1], layerNumber);
79
80 // slowest, completely rely on EcalGeometry
81 // this is helpful for validating the EcalGeometry implementation and
82 // configuration since this will be called with any hit position that
83 // is inside of the configured SD volumes from Geant4's point of view
84 // ldmx::EcalID id = geometry.getID(position[0], position[1], position[2]);
85
86 if (hits_.find(id) == hits_.end()) {
87 // hit in empty cell
88 auto& hit = hits_[id];
89 hit.setID(id.raw());
90 hit.setPosition(position.x(), position.y(), position.z());
91 }
92
93 auto& hit = hits_[id];
94
95 // hit variables
96 auto track = aStep->GetTrack();
97 auto time = track->GetGlobalTime();
98 auto track_id = track->GetTrackID();
99 auto pdg = track->GetParticleDefinition()->GetPDGEncoding();
100
102 int contrib_i = hit.findContribIndex(track_id, pdg);
103 if (compress_hit_contribs_ and contrib_i != -1) {
104 hit.updateContrib(contrib_i, edep, time);
105 } else {
106 auto map{getTrackMap()};
107 auto incident{map.findIncident(track_id)};
108 // default "origin" is just the same as incident
109 // "origin" checks if a hit "originates" from one of the earliest
110 // track IDs (i.e. probably one of the primaries)
111 int origin{incident};
112 for (int i{1}; i < max_origin_track_id_; ++i) {
113 if (map.isDescendant(track_id, i, 100)) {
114 origin = i;
115 break;
116 }
117 }
118 hit.addContrib(incident, track_id, pdg, edep, time, origin);
119 }
120 } else {
121 // no hit contribs and hit already exists
122 hit.setEdep(hit.getEdep() + edep);
123 if (time < hit.getTime() or hit.getTime() == 0) {
124 hit.setTime(time);
125 }
126 }
127
128 return true;
129}
Extension of DetectorID providing access to ECal layers and cell numbers in a hex grid.
Definition EcalID.h:20
bool isGeantino(const G4Step *step) const
Check if the passed step is a step of a geantino.
const TrackMap & getTrackMap() const
Get a handle to the current track map.
const T & getCondition(const std::string &condition_name)
Record the configuration of this detector into the run header.

References compress_hit_contribs_, enable_hit_contribs_, simcore::SensitiveDetector::getCondition(), simcore::SensitiveDetector::getTrackMap(), hits_, simcore::SensitiveDetector::isGeantino(), and max_origin_track_id_.

◆ saveHits()

void simcore::EcalSD::saveHits ( framework::Event & event)
overridevirtual

Add our hits to the event bus.

Implements simcore::SensitiveDetector.

Definition at line 131 of file EcalSD.cxx.

131 {
132 // squash hits into list
133 std::vector<ldmx::SimCalorimeterHit> hits;
134 hits.reserve(hits_.size());
135 for (const auto& [id, hit] : hits_) hits.push_back(hit);
136 event.add(COLLECTION_NAME, hits);
137}
static const std::string COLLECTION_NAME
Name of output collection of hits_.
Definition EcalSD.h:32

References COLLECTION_NAME, and hits_.

Member Data Documentation

◆ COLLECTION_NAME

const std::string simcore::EcalSD::COLLECTION_NAME = "EcalSimHits"
static

Name of output collection of hits_.

Definition at line 32 of file EcalSD.h.

Referenced by saveHits().

◆ compress_hit_contribs_

bool simcore::EcalSD::compress_hit_contribs_
private

compress hit contribs

Definition at line 84 of file EcalSD.h.

Referenced by EcalSD(), and ProcessHits().

◆ enable_hit_contribs_

bool simcore::EcalSD::enable_hit_contribs_
private

enable hit contribs

Definition at line 82 of file EcalSD.h.

Referenced by EcalSD(), and ProcessHits().

◆ hits_

std::map<ldmx::EcalID, ldmx::SimCalorimeterHit> simcore::EcalSD::hits_
private

map of hits to add to the event (will be squashed)

Definition at line 80 of file EcalSD.h.

Referenced by onFinishedEvent(), ProcessHits(), and saveHits().

◆ max_origin_track_id_

int simcore::EcalSD::max_origin_track_id_
private

maximum track ID to be considered an "origin"

Definition at line 86 of file EcalSD.h.

Referenced by EcalSD(), and ProcessHits().


The documentation for this class was generated from the following files: