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

SD tool which manages EM barrel sensitive detectors. More...

#include <EMBSDTool.h>

Inheritance diagram for LArG4::EMBSDTool:
Collaboration diagram for LArG4::EMBSDTool:

Public Member Functions

 EMBSDTool (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.
virtual StatusCode SetupEvent () override
 Beginning of an athena event.
StatusCode Gather (HitCollectionMap &) override final
 Finalize and record event-owned hit collections.
virtual StatusCode Gather () override
 End of an athena event.

Protected Member Functions

LArG4SimpleSDmakeOneSD (const std::string &name, ILArCalculatorSvc *calc, const std::vector< std::string > &volumes) const
 Helper method to create one SD.
bool useFrozenShowers () const
 Are we handling frozen shower fast sim?
virtual std::string hitCollectionName () const
 Collection receiving the hits for this tool.
StatusCode assignSD (std::unique_ptr< G4VSensitiveDetector > sd, const std::vector< std::string > &volumes) const
 Assign SD to a list of volumes.
G4VSensitiveDetector * getSD ()
 Retrieve the current SD.
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< std::string > m_timeBinType {this, "TimeBinType", "Default"}
 What time binning type for regular hits?
Gaudi::Property< float > m_timeBinWidth {this, "TimeBinWidth", 2.5*CLHEP::ns}
 What time bin width for regular hits?
Gaudi::Property< G4bool > m_useFrozenShowers {this, "UseFrozenShowers", false}
 Is there going to be a fast simulation coming into this SD?
Calo identifier helpers
const LArEM_IDm_larEmID {nullptr}
const LArFCAL_IDm_larFcalID {nullptr}
const LArHEC_IDm_larHecID {nullptr}

Private Member Functions

StatusCode initializeCalculators () override final
 Initialize Calculator Services.
G4VSensitiveDetector * makeSD () const override final
 Create the SD wrapper for current worker thread.
void setSD (G4VSensitiveDetector *)
 Set the current SD.

Static Private Member Functions

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

Private Attributes

ServiceHandle< ILArCalculatorSvcm_embcalc {this, "EMBCalculator", "EMBCalculator"}
ServiceHandle< ILArCalculatorSvcm_pscalc {this, "EMBPSCalculator", "EMBPresamplerCalculator"}
G4VSensitiveDetector * m_SD {}
 The sensitive detector to which this thing corresponds.
Configuration
Gaudi::Property< std::vector< std::string > > m_stacVolumes {this, "StacVolumes"}
 List of volumes for the stac SD.
Gaudi::Property< std::vector< std::string > > m_presVolumes {this, "PresamplerVolumes"}
 List of volumes for the presampler SD.

Detailed Description

SD tool which manages EM barrel sensitive detectors.

NOTE: this design is in flux, migrating to be more multi-threading-friendly

Definition at line 24 of file EMBSDTool.h.

Constructor & Destructor Documentation

◆ EMBSDTool()

LArG4::EMBSDTool::EMBSDTool ( 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 64 of file SensitiveDetectorBase.cxx.

66{
67 // Propagate verbosity setting to the SD
68 if(msgLvl(MSG::VERBOSE)) sd->SetVerboseLevel(10);
69 else if(msgLvl(MSG::DEBUG)) sd->SetVerboseLevel(5);
70
71 // Add the sensitive detector to the SD manager in G4 for SDs,
72 // even if it has no volumes associated to it.
73 auto sdMgr = G4SDManager::GetSDMpointer();
74 auto sdPtr = sd.get();
75 // SDManager is now the SD owner
76 //for later use
77 auto sdName = sd->GetName();
78 sdMgr->AddNewDetector(sd.release());
79
80 if(!volumes.empty()) {
81 bool gotOne = false;
82 auto logicalVolumeStore = G4LogicalVolumeStore::GetInstance();
83 for(const auto& volumeName : volumes) {
84 // Keep track of how many volumes we find with this name string.
85 // We allow for multiple matches.
86 int numFound = 0;
87
88 // Find volumes with this name
89 for(auto* logVol : *logicalVolumeStore) {
90
91 ATH_MSG_VERBOSE("Check whether "<<logVol->GetName()<<" belongs to the set of sensitive detectors "<<volumeName);
92 if( matchStrings( volumeName.data(), logVol->GetName() ) ){
93 ++numFound;
94 SetSensitiveDetector(logVol, sdPtr);
95 }
96
97 }
98 // Warn if no volumes were found
99 if(numFound == 0) {
100 ATH_MSG_WARNING("Volume " << volumeName <<
101 " not found in G4LogicalVolumeStore.");
102 }
103 else {
104 ATH_MSG_VERBOSE("Found " << numFound << " copies of LV " << volumeName <<
105 "; SD " << sdName << " assigned.");
106 gotOne = true;
107 }
108
109 }
110
111 // Abort if we have failed to assign any volume
112 if(!gotOne) {
113 ATH_MSG_ERROR( "Failed to assign *any* volume to SD " << name() <<
114 " and expected at least one. Size of the volume store "<<G4LogicalVolumeStore::GetInstance()->size() );
115 return StatusCode::FAILURE;
116 }
117 }
118
119 return StatusCode::SUCCESS;
120}
#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.

◆ Gather() [1/2]

StatusCode LArG4::SimpleSDTool::Gather ( HitCollectionMap & )
finaloverridevirtualinherited

Finalize and record event-owned hit collections.

Reimplemented from SensitiveDetectorBase.

◆ Gather() [2/2]

virtual StatusCode SensitiveDetectorBase::Gather ( )
inlineoverridevirtualinherited

End of an athena event.

Store the output collection in SG at this point. If we are using a WriteHandle, then this can be empty!

Reimplemented in FCS_Param::FCS_StepInfoSDTool.

Definition at line 78 of file SensitiveDetectorBase.h.

78{ return StatusCode::SUCCESS; }

◆ getSD()

G4VSensitiveDetector * SensitiveDetectorBase::getSD ( )
protectedinherited

Retrieve the current SD.

In AthenaMT, this means the thread-local SD. Otherwise, it is simply the single SD.

Definition at line 122 of file SensitiveDetectorBase.cxx.

123{
124#ifdef G4MULTITHREADED
125 // Get current thread-ID
126 const auto tid = std::this_thread::get_id();
127 // Retrieve it from the SD map
128 auto sdPair = m_sdThreadMap.find(tid);
129 if(sdPair == m_sdThreadMap.end()) return nullptr;
130 return sdPair->second;
131#else
132 return m_SD;
133#endif
134}
G4VSensitiveDetector * m_SD
The sensitive detector to which this thing corresponds.

◆ hitCollectionName()

virtual std::string LArG4::SimpleSDTool::hitCollectionName ( ) const
protectedvirtualinherited

Collection receiving the hits for this tool.

◆ initialize()

StatusCode LArG4::SimpleSDTool::initialize ( )
finaloverrideinherited

Initialize the tool.

◆ initializeCalculators()

StatusCode LArG4::EMBSDTool::initializeCalculators ( )
finaloverrideprivatevirtual

Initialize Calculator Services.

Reimplemented from LArG4::SimpleSDTool.

◆ initializeSD()

StatusCode LArG4::SimpleSDTool::initializeSD ( )
finaloverrideinherited

Create and register all SDs for the current thread.

◆ makeOneSD()

LArG4SimpleSD * LArG4::SimpleSDTool::makeOneSD ( const std::string & name,
ILArCalculatorSvc * calc,
const std::vector< std::string > & volumes ) const
protectedinherited

Helper method to create one SD.

◆ makeSD()

G4VSensitiveDetector * LArG4::EMBSDTool::makeSD ( ) const
finaloverrideprivate

Create the SD wrapper for current worker thread.

◆ 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 149 of file SensitiveDetectorBase.cxx.

150{
151 // If we reach at the end of both strings, we are done
152 if (*first == '\0' && *second == '\0')
153 return true;
154
155 // If there are consecutive '*' present in the first string
156 // advance to the next character
157 if(*first == '*' && *(first + 1) == '*')
158 return matchStrings(first + 1, second);
159
160 // Make sure that the characters after '*' are present in second string.
161 if (*first == '*' && *(first + 1) != '\0' && *second == '\0')
162 return false;
163
164 // If the current characters of both strings match
165 if (*first == *second)
166 return matchStrings(first + 1, second + 1);
167
168 // If there is *, then there are two possibilities
169 // a) We consider current character of second string
170 // b) We ignore current character of second string.
171 if (*first == '*')
172 return matchStrings(first + 1, second) || matchStrings(first, second + 1);
173 return false;
174}

◆ setSD()

void SensitiveDetectorBase::setSD ( G4VSensitiveDetector * sd)
privateinherited

Set the current SD.

In hive, this gets assigned as the thread-local SD.

Definition at line 136 of file SensitiveDetectorBase.cxx.

137{
138#ifdef G4MULTITHREADED
139 const auto tid = std::this_thread::get_id();
140 ATH_MSG_DEBUG("Creating and registering SD " << sd << " in thread " << tid);
141 m_sdThreadMap.insert( std::make_pair(tid, sd) );
142#else
143 m_SD = sd;
144#endif
145}
#define ATH_MSG_DEBUG(x)

◆ SetSensitiveDetector()

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

Method stolen from G4VUserDetectorConstruction in G4 10.2.

Definition at line 176 of file SensitiveDetectorBase.cxx.

178{
179 // New Logic: allow for "multiple" SDs being attached to a single LV.
180 // To do that we use a special proxy SD called G4MultiSensitiveDetector
181
182 // Get existing SD if already set and check if it is of the special type
183 G4VSensitiveDetector* originalSD = logVol->GetSensitiveDetector();
184 if ( originalSD == nullptr )
185 {
186 logVol->SetSensitiveDetector(aSD);
187 }
188 else
189 {
190 G4MultiSensitiveDetector* msd = dynamic_cast<G4MultiSensitiveDetector*>(originalSD);
191 if ( msd != nullptr )
192 {
193 msd->AddSD(aSD);
194 }
195 else
196 {
197 // Construct a unique name using the volume address
198 std::stringstream ss;
200 const G4String msdname = "/MultiSD_" + logVol->GetName() + ss.str();
201 msd = new G4MultiSensitiveDetector(std::move(msdname));
202 // We need to register the proxy to have correct handling of IDs
203 G4SDManager::GetSDMpointer()->AddNewDetector(msd);
204 msd->AddSD(originalSD);
205 msd->AddSD(aSD);
206 logVol->SetSensitiveDetector(msd);
207 }
208 }
209}
static Double_t ss

◆ SetupEvent() [1/2]

StatusCode LArG4::SimpleSDTool::SetupEvent ( HitCollectionMap & )
finaloverridevirtualinherited

Create event-owned hit collections.

Reimplemented from SensitiveDetectorBase.

◆ SetupEvent() [2/2]

virtual StatusCode SensitiveDetectorBase::SetupEvent ( )
inlineoverridevirtualinherited

Beginning of an athena event.

This is where collection initialization should happen. If we are using a WriteHandle, then this could be empty.

Definition at line 70 of file SensitiveDetectorBase.h.

70{ return StatusCode::SUCCESS; }

◆ useFrozenShowers()

bool LArG4::SimpleSDTool::useFrozenShowers ( ) const
inlineprotectedinherited

Are we handling frozen shower fast sim?

Definition at line 81 of file SimpleSDTool.h.

81{ return m_useFrozenShowers; }
Gaudi::Property< G4bool > m_useFrozenShowers
Is there going to be a fast simulation coming into this SD?

Member Data Documentation

◆ m_embcalc

ServiceHandle<ILArCalculatorSvc> LArG4::EMBSDTool::m_embcalc {this, "EMBCalculator", "EMBCalculator"}
private

Definition at line 47 of file EMBSDTool.h.

47{this, "EMBCalculator", "EMBCalculator"}; //LArBarrelCalculator::GetCalculator()

◆ m_larEmID

const LArEM_ID* LArG4::SimpleSDTool::m_larEmID {nullptr}
protectedinherited

Definition at line 102 of file SimpleSDTool.h.

102{nullptr};

◆ m_larFcalID

const LArFCAL_ID* LArG4::SimpleSDTool::m_larFcalID {nullptr}
protectedinherited

Definition at line 103 of file SimpleSDTool.h.

103{nullptr};

◆ m_larHecID

const LArHEC_ID* LArG4::SimpleSDTool::m_larHecID {nullptr}
protectedinherited

Definition at line 104 of file SimpleSDTool.h.

104{nullptr};

◆ m_noVolumes

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

This SensitiveDetector has no volumes associated with it.

Definition at line 101 of file SensitiveDetectorBase.h.

101{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 98 of file SensitiveDetectorBase.h.

98{this, "OutputCollectionNames", {}};

◆ m_presVolumes

Gaudi::Property<std::vector<std::string> > LArG4::EMBSDTool::m_presVolumes {this, "PresamplerVolumes"}
private

List of volumes for the presampler SD.

Definition at line 44 of file EMBSDTool.h.

44{this, "PresamplerVolumes"};

◆ m_pscalc

ServiceHandle<ILArCalculatorSvc> LArG4::EMBSDTool::m_pscalc {this, "EMBPSCalculator", "EMBPresamplerCalculator"}
private

Definition at line 48 of file EMBSDTool.h.

48{this, "EMBPSCalculator", "EMBPresamplerCalculator"}; //LArBarrelPresamplerCalculator::GetCalculator()

◆ m_SD

G4VSensitiveDetector* SensitiveDetectorBase::m_SD {}
privateinherited

The sensitive detector to which this thing corresponds.

Definition at line 125 of file SensitiveDetectorBase.h.

125{};

◆ m_stacVolumes

Gaudi::Property<std::vector<std::string> > LArG4::EMBSDTool::m_stacVolumes {this, "StacVolumes"}
private

List of volumes for the stac SD.

Definition at line 42 of file EMBSDTool.h.

42{this, "StacVolumes"};

◆ m_timeBinType

Gaudi::Property<std::string> LArG4::SimpleSDTool::m_timeBinType {this, "TimeBinType", "Default"}
protectedinherited

What time binning type for regular hits?

Definition at line 92 of file SimpleSDTool.h.

92{this, "TimeBinType", "Default"};

◆ m_timeBinWidth

Gaudi::Property<float> LArG4::SimpleSDTool::m_timeBinWidth {this, "TimeBinWidth", 2.5*CLHEP::ns}
protectedinherited

What time bin width for regular hits?

Definition at line 94 of file SimpleSDTool.h.

94{this, "TimeBinWidth", 2.5*CLHEP::ns};

◆ m_useFrozenShowers

Gaudi::Property<G4bool> LArG4::SimpleSDTool::m_useFrozenShowers {this, "UseFrozenShowers", false}
protectedinherited

Is there going to be a fast simulation coming into this SD?

Definition at line 96 of file SimpleSDTool.h.

96{this, "UseFrozenShowers", false};

◆ 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 96 of file SensitiveDetectorBase.h.

96{this, "LogicalVolumeNames", {}};

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