ATLAS Offline Software
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
SctSensorSDTool Class Reference

#include <SctSensorSDTool.h>

Inheritance diagram for SctSensorSDTool:
Collaboration diagram for SctSensorSDTool:

Public Member Functions

 SctSensorSDTool (const std::string &type, const std::string &name, const IInterface *parent)
 
virtual StatusCode SetupEvent (HitCollectionMap &) override
 
virtual StatusCode Gather (HitCollectionMap &) override
 
StatusCode initializeSD () override
 Setup an SD in the current thread. More...
 
virtual StatusCode SetupEvent () override
 Beginning of an athena event. More...
 
virtual StatusCode Gather () override
 End of an athena event. More...
 

Protected Member Functions

G4VSensitiveDetector * makeSD () const override final
 
StatusCode assignSD (G4VSensitiveDetector *sd, const std::vector< std::string > &volumes) const
 Assign SD to a list of volumes. More...
 
G4VSensitiveDetector * getSD ()
 Retrieve the current SD. More...
 
void SetSensitiveDetector (G4LogicalVolume *, G4VSensitiveDetector *) const
 Method stolen from G4VUserDetectorConstruction in G4 10.2. More...
 

Protected Attributes

bool m_isGmxSensor
 
ServiceHandle< IGeoDbTagSvcm_geoDbTagSvc {this, "GeoDbTagSvc", "GeoDbTagSvc", ""}
 
Gaudi::Property< std::vector< std::string > > m_volumeNames {this, "LogicalVolumeNames", {}}
 All the volumes to which this SD is assigned. More...
 
Gaudi::Property< std::vector< std::string > > m_outputCollectionNames {this, "OutputCollectionNames", {}}
 Names of all output collections written out by this SD. More...
 
Gaudi::Property< bool > m_noVolumes {this, "NoVolumes", false}
 This SensitiveDetector has no volumes associated with it. More...
 

Private Member Functions

void setSD (G4VSensitiveDetector *)
 Set the current SD. More...
 

Static Private Member Functions

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

Private Attributes

G4VSensitiveDetector * m_SD {}
 The sensitive detector to which this thing corresponds. More...
 

Detailed Description

Definition at line 24 of file SctSensorSDTool.h.

Constructor & Destructor Documentation

◆ SctSensorSDTool()

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

Definition at line 24 of file SctSensorSDTool.cxx.

26 {
27  declareProperty("GmxSensor",m_isGmxSensor);
28 }

Member Function Documentation

◆ assignSD()

StatusCode SensitiveDetectorBase::assignSD ( 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  sdMgr->AddNewDetector(sd);
75 
76  if(!volumes.empty()) {
77  bool gotOne = false;
78  auto logicalVolumeStore = G4LogicalVolumeStore::GetInstance();
79  for(const auto& volumeName : volumes) {
80  // Keep track of how many volumes we find with this name string.
81  // We allow for multiple matches.
82  int numFound = 0;
83 
84  // Find volumes with this name
85  for(auto* logVol : *logicalVolumeStore) {
86 
87  ATH_MSG_VERBOSE("Check whether "<<logVol->GetName()<<" belongs to the set of sensitive detectors "<<volumeName);
88  if( matchStrings( volumeName.data(), logVol->GetName() ) ){
89  ++numFound;
90  SetSensitiveDetector(logVol, sd);
91  }
92 
93  }
94  // Warn if no volumes were found
95  if(numFound == 0) {
96  ATH_MSG_WARNING("Volume " << volumeName <<
97  " not found in G4LogicalVolumeStore.");
98  }
99  else {
100  ATH_MSG_VERBOSE("Found " << numFound << " copies of LV " << volumeName <<
101  "; SD " << sd->GetName() << " assigned.");
102  gotOne = true;
103  }
104 
105  }
106 
107  // Abort if we have failed to assign any volume
108  if(!gotOne) {
109  ATH_MSG_ERROR( "Failed to assign *any* volume to SD " << name() <<
110  " and expected at least one. Size of the volume store "<<G4LogicalVolumeStore::GetInstance()->size() );
111  return StatusCode::FAILURE;
112  }
113  }
114 
115  return StatusCode::SUCCESS;
116 }

◆ Gather() [1/2]

virtual StatusCode SensitiveDetectorBase::Gather ( )
inlineoverridevirtualinherited

◆ Gather() [2/2]

StatusCode SctSensorSDTool::Gather ( HitCollectionMap hitCollections)
overridevirtual

Reimplemented from SensitiveDetectorBase.

Definition at line 36 of file SctSensorSDTool.cxx.

37 {
39  return StatusCode::SUCCESS;
40 }

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

119 {
120 #ifdef G4MULTITHREADED
121  // Get current thread-ID
122  const auto tid = std::this_thread::get_id();
123  // Retrieve it from the SD map
124  auto sdPair = m_sdThreadMap.find(tid);
125  if(sdPair == m_sdThreadMap.end()) return nullptr;
126  return sdPair->second;
127 #else
128  return m_SD;
129 #endif
130 }

◆ initializeSD()

StatusCode SensitiveDetectorBase::initializeSD ( )
overrideinherited

Setup an SD in the current thread.

Separate from the AthAlgTool initialize() method because it needs to be called once per worker thread in AthenaMT. Don't confuse this with the G4 SD method Initialize which is called at the beginning of every G4 event.

Definition at line 25 of file SensitiveDetectorBase.cxx.

26 {
27  ATH_MSG_VERBOSE( name() << "::initializeSD()" );
28 
29  // Sanity check for volume configuration problems.
30  // It would be better to have a more robust solution for this.
31  if(m_volumeNames.empty() != m_noVolumes) {
32  ATH_MSG_ERROR("Initializing SD from " << name() << ", NoVolumes = "
33  << (m_noVolumes? "true" : "false") << ", but LogicalVolumeNames = "
34  << m_volumeNames.value());
35  return StatusCode::FAILURE;
36  }
37 
38  // Make sure SD isn't already registered
39  if(getSD())
40  {
41  ATH_MSG_ERROR("Trying to create a SD which already exists!");
42  return StatusCode::FAILURE;
43  }
44 
45  // Make the SD stored by this tool
46  auto* sd = makeSD();
47  if(!sd)
48  {
49  ATH_MSG_ERROR("Failed to create SD!");
50  return StatusCode::FAILURE;
51  }
52  setSD(sd);
53 
54  // Assign the SD to our list of volumes
55  ATH_CHECK( assignSD( getSD(), m_volumeNames.value() ) );
56 
57  ATH_MSG_DEBUG( "Initialized and added SD " << name() );
58  return StatusCode::SUCCESS;
59 }

◆ makeSD()

G4VSensitiveDetector * SctSensorSDTool::makeSD ( ) const
finaloverrideprotected

Definition at line 44 of file SctSensorSDTool.cxx.

45 {
46  ATH_MSG_DEBUG( "Initializing SD" );
47  GeoModelIO::ReadGeoModel* sqlreader = nullptr;
48  StatusCode sc = m_geoDbTagSvc.retrieve();
49  if (sc.isFailure()) {
50  msg(MSG::ERROR) << "Could not locate GeoDbTagSvc" << endmsg;
51  }
52  else {
53  sqlreader = m_geoDbTagSvc->getSqliteReader();
54  }
55 
56  if(m_isGmxSensor)
57  {
58  return new SctSensorGmxSD(name(), m_outputCollectionNames[0],sqlreader);
59  }
60  else
61  {
62  return new SctSensorSD(name(), m_outputCollectionNames[0]);
63  }
64 }

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

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

◆ setSD()

void SensitiveDetectorBase::setSD ( G4VSensitiveDetector *  sd)
privateinherited

Set the current SD.

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

Definition at line 132 of file SensitiveDetectorBase.cxx.

133 {
134 #ifdef G4MULTITHREADED
135  const auto tid = std::this_thread::get_id();
136  ATH_MSG_DEBUG("Creating and registering SD " << sd << " in thread " << tid);
137  m_sdThreadMap.insert( std::make_pair(tid, sd) );
138 #else
139  m_SD = sd;
140 #endif
141 }

◆ SetSensitiveDetector()

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

Method stolen from G4VUserDetectorConstruction in G4 10.2.

Definition at line 172 of file SensitiveDetectorBase.cxx.

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

◆ SetupEvent() [1/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.

Reimplemented in MuonWallSDTool, AFP_SensitiveDetectorTool, AFP_SiDSensitiveDetectorTool, AFP_TDSensitiveDetectorTool, CaloCellContainerSDTool, and ALFA_SensitiveDetectorTool.

Definition at line 70 of file SensitiveDetectorBase.h.

70 { return StatusCode::SUCCESS; }

◆ SetupEvent() [2/2]

StatusCode SctSensorSDTool::SetupEvent ( HitCollectionMap hitCollections)
overridevirtual

Reimplemented from SensitiveDetectorBase.

Definition at line 30 of file SctSensorSDTool.cxx.

31 {
33  return StatusCode::SUCCESS;
34 }

Member Data Documentation

◆ m_geoDbTagSvc

ServiceHandle<IGeoDbTagSvc> SctSensorSDTool::m_geoDbTagSvc {this, "GeoDbTagSvc", "GeoDbTagSvc", ""}
protected

Definition at line 37 of file SctSensorSDTool.h.

◆ m_isGmxSensor

bool SctSensorSDTool::m_isGmxSensor
protected

Definition at line 36 of file SctSensorSDTool.h.

◆ 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.

◆ 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.

◆ m_SD

G4VSensitiveDetector* SensitiveDetectorBase::m_SD {}
privateinherited

The sensitive detector to which this thing corresponds.

Definition at line 125 of file SensitiveDetectorBase.h.

◆ 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.


The documentation for this class was generated from the following files:
SensitiveDetectorBase::m_SD
G4VSensitiveDetector * m_SD
The sensitive detector to which this thing corresponds.
Definition: SensitiveDetectorBase.h:125
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
AtlasHitsVector< SiHit >
python.SystemOfUnits.second
float second
Definition: SystemOfUnits.py:135
SensitiveDetectorBase::SensitiveDetectorBase
SensitiveDetectorBase(const std::string &type, const std::string &name, const IInterface *parent)
Standard constructor.
Definition: SensitiveDetectorBase.cxx:17
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SctSensorSDTool::m_geoDbTagSvc
ServiceHandle< IGeoDbTagSvc > m_geoDbTagSvc
Definition: SctSensorSDTool.h:37
SensitiveDetectorBase::getSD
G4VSensitiveDetector * getSD()
Retrieve the current SD.
Definition: SensitiveDetectorBase.cxx:118
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
SctSensorSDTool::m_isGmxSensor
bool m_isGmxSensor
Definition: SctSensorSDTool.h:36
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
python.selector.AtlRunQuerySelectorLhcOlc.sd
sd
Definition: AtlRunQuerySelectorLhcOlc.py:611
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
HitCollectionMap::Emplace
std::pair< StorageIterator, bool > Emplace(std::string const &hitCollectionName, CollectionArgs &&... args)
Insert a container in the map with in-place construction.
Definition: HitCollectionMap.h:38
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SctSensorGmxSD
Definition: SctSensorGmxSD.h:25
SctSensorSD
Definition: SctSensorSD.h:24
SensitiveDetectorBase::m_outputCollectionNames
Gaudi::Property< std::vector< std::string > > m_outputCollectionNames
Names of all output collections written out by this SD.
Definition: SensitiveDetectorBase.h:98
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
SensitiveDetectorBase::SetSensitiveDetector
void SetSensitiveDetector(G4LogicalVolume *, G4VSensitiveDetector *) const
Method stolen from G4VUserDetectorConstruction in G4 10.2.
Definition: SensitiveDetectorBase.cxx:173
HitCollectionMap::Record
void Record(std::string const &sgKey, std::string const &hitCollectionName, EventContext const &ctx)
Record the hit collection hitCollectionName to the StoreGate sgKey.
Definition: HitCollectionMap.h:82
SensitiveDetectorBase::matchStrings
static bool matchStrings(const char *first, const char *second)
Match two strings with wildcard support.
Definition: SensitiveDetectorBase.cxx:145
SensitiveDetectorBase::m_volumeNames
Gaudi::Property< std::vector< std::string > > m_volumeNames
All the volumes to which this SD is assigned.
Definition: SensitiveDetectorBase.h:96
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
SensitiveDetectorBase::m_noVolumes
Gaudi::Property< bool > m_noVolumes
This SensitiveDetector has no volumes associated with it.
Definition: SensitiveDetectorBase.h:101
DeMoScan.first
bool first
Definition: DeMoScan.py:534
DEBUG
#define DEBUG
Definition: page_access.h:11
SensitiveDetectorBase::setSD
void setSD(G4VSensitiveDetector *)
Set the current SD.
Definition: SensitiveDetectorBase.cxx:132
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:13
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
SensitiveDetectorBase::assignSD
StatusCode assignSD(G4VSensitiveDetector *sd, const std::vector< std::string > &volumes) const
Assign SD to a list of volumes.
Definition: SensitiveDetectorBase.cxx:65