14 #include "G4LogicalVolumeStore.hh"
15 #include "G4SDManager.hh"
18 #include "G4AtlasTools/G4MultiSensitiveDetector.hh"
23 const std::string&
name,
38 << (
m_noVolumes?
"true" :
"false") <<
", but LogicalVolumeNames = "
40 return StatusCode::FAILURE;
47 return StatusCode::FAILURE;
55 return StatusCode::FAILURE;
63 return StatusCode::SUCCESS;
70 assignSD(G4VSensitiveDetector*
sd,
const std::vector<std::string>& volumes)
const
78 auto sdMgr = G4SDManager::GetSDMpointer();
79 sdMgr->AddNewDetector(
sd);
81 if(!volumes.empty()) {
83 auto logicalVolumeStore = G4LogicalVolumeStore::GetInstance();
84 for(
const auto& volumeName : volumes) {
90 for(
auto* logVol : *logicalVolumeStore) {
92 ATH_MSG_VERBOSE(
"Check whether "<<logVol->GetName()<<
" belongs to the set of sensitive detectors "<<volumeName);
93 if(
matchStrings( volumeName.data(), logVol->GetName() ) ){
102 " not found in G4LogicalVolumeStore.");
105 ATH_MSG_VERBOSE(
"Found " << numFound <<
" copies of LV " << volumeName <<
106 "; SD " <<
sd->GetName() <<
" assigned.");
115 " and expected at least one. Size of the volume store "<<G4LogicalVolumeStore::GetInstance()->
size() );
116 return StatusCode::FAILURE;
120 return StatusCode::SUCCESS;
125 #ifdef G4MULTITHREADED
127 const auto tid = std::this_thread::get_id();
129 auto sdPair = m_sdThreadMap.find(tid);
130 if(sdPair == m_sdThreadMap.end())
return nullptr;
131 return sdPair->second;
139 #ifdef G4MULTITHREADED
140 const auto tid = std::this_thread::get_id();
141 ATH_MSG_DEBUG(
"Creating and registering SD " <<
sd <<
" in thread " << tid);
142 m_sdThreadMap.insert( std::make_pair(tid,
sd) );
184 G4VSensitiveDetector* originalSD = logVol->GetSensitiveDetector();
185 if ( originalSD ==
nullptr )
187 logVol->SetSensitiveDetector(aSD);
191 G4MultiSensitiveDetector* msd =
dynamic_cast<G4MultiSensitiveDetector*
>(originalSD);
192 if ( msd !=
nullptr )
199 std::stringstream
ss;
200 ss << static_cast<const void*>(logVol);
201 const G4String msdname =
"/MultiSD_" + logVol->GetName() +
ss.str();
203 msd =
new G4MultiSensitiveDetector(msdname);
205 G4SDManager::GetSDMpointer()->AddNewDetector(msd);
206 msd->AddSD(originalSD);
208 logVol->SetSensitiveDetector(msd);