LDMX Software
Public Member Functions | Private Attributes | List of all members
simcore::TrackerSD Class Reference

Basic sensitive detector for trackers. More...

#include <TrackerSD.h>

Public Member Functions

 TrackerSD (const std::string &name, simcore::ConditionsInterface &ci, const framework::config::Parameters &p)
 Class constructor.
 
virtual ~TrackerSD ()=default
 Destructor.
 
virtual bool isSensDet (G4LogicalVolume *volume) const override
 Should the input logical volume be attached to this sensitive detector?
 
G4bool ProcessHits (G4Step *step, G4TouchableHistory *history) override
 Process a step by creating a hit.
 
virtual void saveHits (framework::Event &event) override
 Add the hits to the event and then reset the container.
 
virtual void OnFinishedEvent () override
 Cleanup SD and prepare a new-event state.
 
- Public Member Functions inherited from simcore::SensitiveDetector
 SensitiveDetector (const std::string &name, simcore::ConditionsInterface &ci, const framework::config::Parameters &parameters)
 Constructor.
 
virtual ~SensitiveDetector ()=default
 Destructor.
 
virtual void EndOfEvent (G4HCofThisEvent *) override
 This is Geant4's handle to tell us the event is ending.
 

Private Attributes

std::string subsystem_
 The name of the subsystem we are apart of.
 
std::string collection_name_
 The name of the output collection.
 
std::vector< ldmx::SimTrackerHithits_
 The collection of hits.
 
ldmx::SubdetectorIDType subDetID_
 The detector ID.
 

Additional Inherited Members

- Public Types inherited from simcore::SensitiveDetector
using Factory = ::simcore::Factory< SensitiveDetector, SensitiveDetector *, const std::string &, simcore::ConditionsInterface &, const framework::config::Parameters & >
 The SD Factory.
 
- 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.
 

Detailed Description

Basic sensitive detector for trackers.

Definition at line 14 of file TrackerSD.h.

Constructor & Destructor Documentation

◆ TrackerSD()

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

Class constructor.

Parameters
[in]nameThe name of the sensitive detector.
[in]ciconditions interface handle
[in]pparameters to configure sensitive detector

Definition at line 11 of file TrackerSD.cxx.

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}
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:89
SensitiveDetector(const std::string &name, simcore::ConditionsInterface &ci, const framework::config::Parameters &parameters)
Constructor.
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

References collection_name_, framework::config::Parameters::getParameter(), subDetID_, and subsystem_.

Member Function Documentation

◆ isSensDet()

virtual bool simcore::TrackerSD::isSensDet ( G4LogicalVolume *  volume) const
inlineoverridevirtual

Should the input logical volume be attached to this sensitive detector?

Note
This is dependent on the naming convention in the GDML!

Implements simcore::SensitiveDetector.

Definition at line 34 of file TrackerSD.h.

34 {
35 return (volume->GetName().contains("Sensor") and
36 volume->GetName().contains(subsystem_));
37 }

References subsystem_.

◆ OnFinishedEvent()

virtual void simcore::TrackerSD::OnFinishedEvent ( )
inlineoverridevirtual

Cleanup SD and prepare a new-event state.

Implements simcore::SensitiveDetector.

Definition at line 54 of file TrackerSD.h.

54{ hits_.clear(); }
std::vector< ldmx::SimTrackerHit > hits_
The collection of hits.
Definition TrackerSD.h:64

References hits_.

◆ ProcessHits()

G4bool simcore::TrackerSD::ProcessHits ( G4Step *  step,
G4TouchableHistory *  history 
)
overridevirtual

Process a step by creating a hit.

Parameters
stepThe step information
historyThe readout history.

Implements simcore::SensitiveDetector.

Definition at line 20 of file TrackerSD.cxx.

20 {
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}
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
bool isGeantino(const G4Step *step) const
Check if the passed step is a step of a geantino.

References hits_, simcore::SensitiveDetector::isGeantino(), ldmx::SimTrackerHit::setTrackID(), and subDetID_.

◆ saveHits()

virtual void simcore::TrackerSD::saveHits ( framework::Event event)
inlineoverridevirtual

Add the hits to the event and then reset the container.

Implements simcore::SensitiveDetector.

Definition at line 50 of file TrackerSD.h.

50 {
51 event.add(collection_name_, hits_);
52 }

References collection_name_, and hits_.

Member Data Documentation

◆ collection_name_

std::string simcore::TrackerSD::collection_name_
private

The name of the output collection.

Definition at line 61 of file TrackerSD.h.

Referenced by saveHits(), and TrackerSD().

◆ hits_

std::vector<ldmx::SimTrackerHit> simcore::TrackerSD::hits_
private

The collection of hits.

Definition at line 64 of file TrackerSD.h.

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

◆ subDetID_

ldmx::SubdetectorIDType simcore::TrackerSD::subDetID_
private

The detector ID.

Definition at line 67 of file TrackerSD.h.

Referenced by ProcessHits(), and TrackerSD().

◆ subsystem_

std::string simcore::TrackerSD::subsystem_
private

The name of the subsystem we are apart of.

Definition at line 58 of file TrackerSD.h.

Referenced by isSensDet(), and TrackerSD().


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