10#include "G4LogicalVolumeStore.hh"
11#include "G4MultiSensitiveDetector.hh"
12#include "G4SDManager.hh"
18 const std::string& name,
19 const IInterface* parent)
20 : base_class(
type,name,parent)
32 ATH_MSG_ERROR(
"Initializing SD from " << name() <<
", NoVolumes = "
33 << (
m_noVolumes?
"true" :
"false") <<
", but LogicalVolumeNames = "
35 return StatusCode::FAILURE;
39 auto sd = std::unique_ptr<G4VSensitiveDetector>(makeSD());
43 return StatusCode::FAILURE;
49 return StatusCode::SUCCESS;
56assignSD(std::unique_ptr<G4VSensitiveDetector> sd,
const std::vector<std::string>& volumes)
const
59 if(msgLvl(MSG::VERBOSE)) sd->SetVerboseLevel(10);
60 else if(msgLvl(MSG::DEBUG)) sd->SetVerboseLevel(5);
64 auto sdMgr = G4SDManager::GetSDMpointer();
65 auto sdPtr = sd.get();
68 auto sdName = sd->GetName();
69 sdMgr->AddNewDetector(sd.release());
71 if(!volumes.empty()) {
73 auto logicalVolumeStore = G4LogicalVolumeStore::GetInstance();
74 for(
const auto& volumeName : volumes) {
80 for(
auto* logVol : *logicalVolumeStore) {
82 ATH_MSG_VERBOSE(
"Check whether "<<logVol->GetName()<<
" belongs to the set of sensitive detectors "<<volumeName);
83 if(
matchStrings( volumeName.data(), logVol->GetName() ) ){
92 " not found in G4LogicalVolumeStore.");
95 ATH_MSG_VERBOSE(
"Found " << numFound <<
" copies of LV " << volumeName <<
96 "; SD " << sdName <<
" assigned.");
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;
110 return StatusCode::SUCCESS;
118 if (*first ==
'\0' && *second ==
'\0')
123 if(*first ==
'*' && *(first + 1) ==
'*')
127 if (*first ==
'*' && *(first + 1) !=
'\0' && *second ==
'\0')
131 if (*first == *second)
149 G4VSensitiveDetector* originalSD = logVol->GetSensitiveDetector();
150 if ( originalSD ==
nullptr )
152 logVol->SetSensitiveDetector(aSD);
156 G4MultiSensitiveDetector* msd =
dynamic_cast<G4MultiSensitiveDetector*
>(originalSD);
157 if ( msd !=
nullptr )
164 std::stringstream
ss;
166 const G4String msdname =
"/MultiSD_" + logVol->GetName() +
ss.str();
167 msd =
new G4MultiSensitiveDetector(std::move(msdname));
169 G4SDManager::GetSDMpointer()->AddNewDetector(msd);
170 msd->AddSD(originalSD);
172 logVol->SetSensitiveDetector(msd);
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
size_t size() const
Number of registered mappings.
StatusCode assignSD(std::unique_ptr< G4VSensitiveDetector > sd, const std::vector< std::string > &volumes) const
Assign SD to a list of volumes.
Gaudi::Property< std::vector< std::string > > m_volumeNames
All the volumes to which this SD is assigned.
StatusCode initializeSD() override
Setup an SD in the current thread.
Gaudi::Property< bool > m_noVolumes
This SensitiveDetector has no volumes associated with it.
SensitiveDetectorBase(const std::string &type, const std::string &name, const IInterface *parent)
Standard constructor.
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.