ATLAS Offline Software
Loading...
Searching...
No Matches
LArG4::CalibSDTool Class Reference

A base class for tools that manage LArG4CalibSDs. More...

#include <CalibSDTool.h>

Inheritance diagram for LArG4::CalibSDTool:
Collaboration diagram for LArG4::CalibSDTool:

Public Member Functions

 CalibSDTool (const std::string &type, const std::string &name, const IInterface *parent)
 Constructor.
StatusCode initialize () override final
 Initialize the tool.
StatusCode initializeSD () override final
 Create and register all SDs for the current thread.
StatusCode SetupEvent (HitCollectionMap &) override final
 Create event-owned hit collections.
StatusCode Gather (HitCollectionMap &) override final
 Finalize and record event-owned hit collections.

Protected Member Functions

virtual StatusCode initializeCalculators ()
 Initialize Calculator Services.
LArG4CalibSDmakeOneSD (const std::string &name, ILArCalibCalculatorSvc *calc, const std::vector< std::string > &volumes) const
 Helper method to create one SD.
virtual std::string hitCollectionName () const
virtual std::string deadHitCollectionName () const
virtual std::string srHitCollectionName () const
StatusCode assignSD (std::unique_ptr< G4VSensitiveDetector > sd, const std::vector< std::string > &volumes) const
 Assign SD to a list of volumes.
void SetSensitiveDetector (G4LogicalVolume *, G4VSensitiveDetector *) const
 Method stolen from G4VUserDetectorConstruction in G4 10.2.

Protected Attributes

Gaudi::Property< std::vector< std::string > > m_volumeNames {this, "LogicalVolumeNames", {}}
 All the volumes to which this SD is assigned.
Gaudi::Property< std::vector< std::string > > m_outputCollectionNames {this, "OutputCollectionNames", {}}
 Names of all output collections written out by this SD.
Gaudi::Property< bool > m_noVolumes {this, "NoVolumes", false}
 This SensitiveDetector has no volumes associated with it.
configuration properties
Gaudi::Property< G4bool > m_doPID {this, "ParticleID", false}
 Are we set up to run with PID hits?
Calo identifier helpers
const LArEM_IDm_larEmID {nullptr}
const LArFCAL_IDm_larFcalID {nullptr}
const LArHEC_IDm_larHecID {nullptr}
const CaloDM_IDm_caloDmID {nullptr}
const AtlasDetectorIDm_id_helper {nullptr}

Static Private Member Functions

static bool matchStrings (const char *first, const char *second)
 Match two strings with wildcard support.

Detailed Description

A base class for tools that manage LArG4CalibSDs.

The tool owns only the Athena-event lifecycle of the output collections. Geant4 SD instances write through calibration builder containers, which carry per-event merge state and preserve per-SD hit partitions.

Author
Steve Farrell Steve.nosp@m.n.Fa.nosp@m.rrell.nosp@m.@cer.nosp@m.n.ch

Definition at line 47 of file CalibSDTool.h.

Constructor & Destructor Documentation

◆ CalibSDTool()

LArG4::CalibSDTool::CalibSDTool ( const std::string & type,
const std::string & name,
const IInterface * parent )

Constructor.

Member Function Documentation

◆ assignSD()

StatusCode SensitiveDetectorBase::assignSD ( std::unique_ptr< G4VSensitiveDetector > sd,
const std::vector< std::string > & volumes ) const
protectedinherited

Assign SD to a list of volumes.

This method supports wild card matching

Definition at line 55 of file SensitiveDetectorBase.cxx.

57{
58 // Propagate verbosity setting to the SD
59 if(msgLvl(MSG::VERBOSE)) sd->SetVerboseLevel(10);
60 else if(msgLvl(MSG::DEBUG)) sd->SetVerboseLevel(5);
61
62 // Add the sensitive detector to the SD manager in G4 for SDs,
63 // even if it has no volumes associated to it.
64 auto sdMgr = G4SDManager::GetSDMpointer();
65 auto sdPtr = sd.get();
66 // SDManager is now the SD owner
67 //for later use
68 auto sdName = sd->GetName();
69 sdMgr->AddNewDetector(sd.release());
70
71 if(!volumes.empty()) {
72 bool gotOne = false;
73 auto logicalVolumeStore = G4LogicalVolumeStore::GetInstance();
74 for(const auto& volumeName : volumes) {
75 // Keep track of how many volumes we find with this name string.
76 // We allow for multiple matches.
77 int numFound = 0;
78
79 // Find volumes with this name
80 for(auto* logVol : *logicalVolumeStore) {
81
82 ATH_MSG_VERBOSE("Check whether "<<logVol->GetName()<<" belongs to the set of sensitive detectors "<<volumeName);
83 if( matchStrings( volumeName.data(), logVol->GetName() ) ){
84 ++numFound;
85 SetSensitiveDetector(logVol, sdPtr);
86 }
87
88 }
89 // Warn if no volumes were found
90 if(numFound == 0) {
91 ATH_MSG_WARNING("Volume " << volumeName <<
92 " not found in G4LogicalVolumeStore.");
93 }
94 else {
95 ATH_MSG_VERBOSE("Found " << numFound << " copies of LV " << volumeName <<
96 "; SD " << sdName << " assigned.");
97 gotOne = true;
98 }
99
100 }
101
102 // Abort if we have failed to assign any volume
103 if(!gotOne) {
104 ATH_MSG_ERROR( "Failed to assign *any* volume to SD " << name() <<
105 " and expected at least one. Size of the volume store "<<G4LogicalVolumeStore::GetInstance()->size() );
106 return StatusCode::FAILURE;
107 }
108 }
109
110 return StatusCode::SUCCESS;
111}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
size_t size() const
Number of registered mappings.
static bool matchStrings(const char *first, const char *second)
Match two strings with wildcard support.
void SetSensitiveDetector(G4LogicalVolume *, G4VSensitiveDetector *) const
Method stolen from G4VUserDetectorConstruction in G4 10.2.

◆ deadHitCollectionName()

virtual std::string LArG4::CalibSDTool::deadHitCollectionName ( ) const
protectedvirtual

◆ Gather()

StatusCode LArG4::CalibSDTool::Gather ( HitCollectionMap & )
finaloverridevirtual

Finalize and record event-owned hit collections.

Reimplemented from SensitiveDetectorBase.

◆ hitCollectionName()

virtual std::string LArG4::CalibSDTool::hitCollectionName ( ) const
protectedvirtual

◆ initialize()

StatusCode LArG4::CalibSDTool::initialize ( )
finaloverride

Initialize the tool.

◆ initializeCalculators()

virtual StatusCode LArG4::CalibSDTool::initializeCalculators ( )
inlineprotectedvirtual

Initialize Calculator Services.

Reimplemented in LArG4::ActiveSDTool, LArG4::DeadSDTool, and LArG4::InactiveSDTool.

Definition at line 71 of file CalibSDTool.h.

71{ return StatusCode::SUCCESS; }

◆ initializeSD()

StatusCode LArG4::CalibSDTool::initializeSD ( )
finaloverride

Create and register all SDs for the current thread.

◆ makeOneSD()

LArG4CalibSD * LArG4::CalibSDTool::makeOneSD ( const std::string & name,
ILArCalibCalculatorSvc * calc,
const std::vector< std::string > & volumes ) const
protected

Helper method to create one SD.

◆ matchStrings()

bool SensitiveDetectorBase::matchStrings ( const char * first,
const char * second )
staticprivateinherited

Match two strings with wildcard support.

Compares two strings character by character with optional * wildcard in the first argument

Definition at line 115 of file SensitiveDetectorBase.cxx.

116{
117 // If we reach at the end of both strings, we are done
118 if (*first == '\0' && *second == '\0')
119 return true;
120
121 // If there are consecutive '*' present in the first string
122 // advance to the next character
123 if(*first == '*' && *(first + 1) == '*')
124 return matchStrings(first + 1, second);
125
126 // Make sure that the characters after '*' are present in second string.
127 if (*first == '*' && *(first + 1) != '\0' && *second == '\0')
128 return false;
129
130 // If the current characters of both strings match
131 if (*first == *second)
132 return matchStrings(first + 1, second + 1);
133
134 // If there is *, then there are two possibilities
135 // a) We consider current character of second string
136 // b) We ignore current character of second string.
137 if (*first == '*')
138 return matchStrings(first + 1, second) || matchStrings(first, second + 1);
139 return false;
140}

◆ SetSensitiveDetector()

void SensitiveDetectorBase::SetSensitiveDetector ( G4LogicalVolume * logVol,
G4VSensitiveDetector * aSD ) const
protectedinherited

Method stolen from G4VUserDetectorConstruction in G4 10.2.

Definition at line 142 of file SensitiveDetectorBase.cxx.

144{
145 // New Logic: allow for "multiple" SDs being attached to a single LV.
146 // To do that we use a special proxy SD called G4MultiSensitiveDetector
147
148 // Get existing SD if already set and check if it is of the special type
149 G4VSensitiveDetector* originalSD = logVol->GetSensitiveDetector();
150 if ( originalSD == nullptr )
151 {
152 logVol->SetSensitiveDetector(aSD);
153 }
154 else
155 {
156 G4MultiSensitiveDetector* msd = dynamic_cast<G4MultiSensitiveDetector*>(originalSD);
157 if ( msd != nullptr )
158 {
159 msd->AddSD(aSD);
160 }
161 else
162 {
163 // Construct a unique name using the volume address
164 std::stringstream ss;
166 const G4String msdname = "/MultiSD_" + logVol->GetName() + ss.str();
167 msd = new G4MultiSensitiveDetector(std::move(msdname));
168 // We need to register the proxy to have correct handling of IDs
169 G4SDManager::GetSDMpointer()->AddNewDetector(msd);
170 msd->AddSD(originalSD);
171 msd->AddSD(aSD);
172 logVol->SetSensitiveDetector(msd);
173 }
174 }
175}
static Double_t ss

◆ SetupEvent()

StatusCode LArG4::CalibSDTool::SetupEvent ( HitCollectionMap & )
finaloverridevirtual

Create event-owned hit collections.

Reimplemented from SensitiveDetectorBase.

◆ srHitCollectionName()

virtual std::string LArG4::CalibSDTool::srHitCollectionName ( ) const
protectedvirtual

Reimplemented in LArG4::ActiveSDTool.

Member Data Documentation

◆ m_caloDmID

const CaloDM_ID* LArG4::CalibSDTool::m_caloDmID {nullptr}
protected

Definition at line 97 of file CalibSDTool.h.

97{nullptr};

◆ m_doPID

Gaudi::Property<G4bool> LArG4::CalibSDTool::m_doPID {this, "ParticleID", false}
protected

Are we set up to run with PID hits?

Definition at line 88 of file CalibSDTool.h.

88{this, "ParticleID", false};

◆ m_id_helper

const AtlasDetectorID* LArG4::CalibSDTool::m_id_helper {nullptr}
protected

Definition at line 98 of file CalibSDTool.h.

98{nullptr};

◆ m_larEmID

const LArEM_ID* LArG4::CalibSDTool::m_larEmID {nullptr}
protected

Definition at line 94 of file CalibSDTool.h.

94{nullptr};

◆ m_larFcalID

const LArFCAL_ID* LArG4::CalibSDTool::m_larFcalID {nullptr}
protected

Definition at line 95 of file CalibSDTool.h.

95{nullptr};

◆ m_larHecID

const LArHEC_ID* LArG4::CalibSDTool::m_larHecID {nullptr}
protected

Definition at line 96 of file CalibSDTool.h.

96{nullptr};

◆ m_noVolumes

Gaudi::Property<bool> SensitiveDetectorBase::m_noVolumes {this, "NoVolumes", false}
protectedinherited

This SensitiveDetector has no volumes associated with it.

Definition at line 83 of file SensitiveDetectorBase.h.

83{this, "NoVolumes", false};

◆ m_outputCollectionNames

Gaudi::Property<std::vector<std::string> > SensitiveDetectorBase::m_outputCollectionNames {this, "OutputCollectionNames", {}}
protectedinherited

Names of all output collections written out by this SD.

Definition at line 80 of file SensitiveDetectorBase.h.

80{this, "OutputCollectionNames", {}};

◆ m_volumeNames

Gaudi::Property<std::vector<std::string> > SensitiveDetectorBase::m_volumeNames {this, "LogicalVolumeNames", {}}
protectedinherited

All the volumes to which this SD is assigned.

Definition at line 78 of file SensitiveDetectorBase.h.

78{this, "LogicalVolumeNames", {}};

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