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::SimCalorimeterHithits_
 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 TrackMapgetTrackMap () 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 37 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 7 of file EcalSD.cxx.

9 : SensitiveDetector(name, ci, p) {
10 enable_hit_contribs_ = p.get<bool>("enableHitContribs");
11 compress_hit_contribs_ = p.get<bool>("compressHitContribs");
12 max_origin_track_id_ = p.get<int>("max_origin_track_id");
13}
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:78
int max_origin_track_id_
maximum track ID to be considered an "origin"
Definition EcalSD.h:94
bool enable_hit_contribs_
enable hit contribs
Definition EcalSD.h:90
bool compress_hit_contribs_
compress hit contribs
Definition EcalSD.h:92
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 61 of file EcalSD.h.

61 {
62 auto region = vol->GetRegion();
63 if (region and region->GetName().contains("CalorimeterRegion")) {
64 return vol->GetName().contains("Si");
65 }
66 return false;
67 }

◆ onFinishedEvent()

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

Clear the map of hits we have accumulated.

Implements simcore::SensitiveDetector.

Definition at line 84 of file EcalSD.h.

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

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 15 of file EcalSD.cxx.

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

126 {
127 // squash hits into list
128 std::vector<ldmx::SimCalorimeterHit> hits;
129 hits.reserve(hits_.size());
130 for (const auto& [id, hit] : hits_) hits.push_back(hit);
131 event.add(COLLECTION_NAME, hits);
132}
static const std::string COLLECTION_NAME
Name of output collection of hits_.
Definition EcalSD.h:40

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 40 of file EcalSD.h.

Referenced by saveHits().

◆ compress_hit_contribs_

bool simcore::EcalSD::compress_hit_contribs_
private

compress hit contribs

Definition at line 92 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 90 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 88 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 94 of file EcalSD.h.

Referenced by EcalSD(), and ProcessHits().


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