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

Tool for constructing H62004 SDs for EMEC. More...

#include <H62004EMECSDTool.h>

Inheritance diagram for LArG4::H62004EMECSDTool:
Collaboration diagram for LArG4::H62004EMECSDTool:

Public Member Functions

 H62004EMECSDTool (const std::string &type, const std::string &name, const IInterface *parent)
 Constructor. More...
 
StatusCode initialize () override final
 Initialize the tool. More...
 
StatusCode Gather () override final
 Calls down to all the SDs to pack their hits into one collection. More...
 
StatusCode initializeSD () override
 Setup an SD in the current thread. More...
 
virtual StatusCode SetupEvent () override
 Beginning of an athena event. More...
 

Protected Member Functions

std::unique_ptr< LArG4SimpleSDmakeOneSD (const std::string &name, ILArCalculatorSvc *calc, const std::vector< std::string > &volumes) const
 Override helper method to create one SD. More...
 
bool useFrozenShowers () const
 Are we handling frozen shower fast sim? More...
 
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

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

StatusCode initializeCalculators () override final
 Initialize Calculator Services. More...
 
G4VSensitiveDetector * makeSD () const override final
 Create the SD wrapper for current worker thread. More...
 
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

std::string m_hitCollName
 Hit collection name. More...
 
ServiceHandle< ILArCalculatorSvcm_calculator
 
G4VSensitiveDetector * m_SD {}
 The sensitive detector to which this thing corresponds. More...
 

Detailed Description

Tool for constructing H62004 SDs for EMEC.

Based on the previous LArG4H62004EMECSDTool implementation.

This implementation uses the LAr SD wrapper design for managing multiple SDs when running multi-threaded. See ATLASSIM-2606 for discussions.

Definition at line 26 of file H62004EMECSDTool.h.

Constructor & Destructor Documentation

◆ H62004EMECSDTool()

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

Constructor.

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

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

◆ Gather()

StatusCode LArG4::SimpleSDTool::Gather ( )
finaloverridevirtualinherited

Calls down to all the SDs to pack their hits into one collection.

Reimplemented from SensitiveDetectorBase.

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

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

◆ initialize()

StatusCode LArG4::SimpleSDTool::initialize ( )
finaloverrideinherited

Initialize the tool.

◆ initializeCalculators()

StatusCode LArG4::H62004EMECSDTool::initializeCalculators ( )
finaloverrideprivatevirtual

Initialize Calculator Services.

Reimplemented from LArG4::SimpleSDTool.

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

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

◆ makeOneSD()

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

Override helper method to create one SD.

◆ makeSD()

G4VSensitiveDetector* LArG4::H62004EMECSDTool::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 150 of file SensitiveDetectorBase.cxx.

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

◆ setSD()

void SensitiveDetectorBase::setSD ( G4VSensitiveDetector *  sd)
privateinherited

Set the current SD.

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

Definition at line 137 of file SensitiveDetectorBase.cxx.

138 {
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) );
143 #else
144  m_SD = sd;
145 #endif
146 }

◆ SetSensitiveDetector()

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

Method stolen from G4VUserDetectorConstruction in G4 10.2.

Definition at line 177 of file SensitiveDetectorBase.cxx.

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

◆ SetupEvent()

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

62 { return StatusCode::SUCCESS; }

◆ useFrozenShowers()

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

Are we handling frozen shower fast sim?

Definition at line 66 of file SimpleSDTool.h.

66 { return m_useFrozenShowers; }

Member Data Documentation

◆ m_calculator

ServiceHandle<ILArCalculatorSvc> LArG4::H62004EMECSDTool::m_calculator
private

Definition at line 45 of file H62004EMECSDTool.h.

◆ m_hitCollName

std::string LArG4::H62004EMECSDTool::m_hitCollName
private

Hit collection name.

Definition at line 43 of file H62004EMECSDTool.h.

◆ m_larEmID

const LArEM_ID* LArG4::SimpleSDTool::m_larEmID
protectedinherited

Definition at line 84 of file SimpleSDTool.h.

◆ m_larFcalID

const LArFCAL_ID* LArG4::SimpleSDTool::m_larFcalID
protectedinherited

Definition at line 85 of file SimpleSDTool.h.

◆ m_larHecID

const LArHEC_ID* LArG4::SimpleSDTool::m_larHecID
protectedinherited

Definition at line 86 of file SimpleSDTool.h.

◆ m_noVolumes

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

This SensitiveDetector has no volumes associated with it.

Definition at line 87 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 84 of file SensitiveDetectorBase.h.

◆ m_SD

G4VSensitiveDetector* SensitiveDetectorBase::m_SD {}
privateinherited

The sensitive detector to which this thing corresponds.

Definition at line 111 of file SensitiveDetectorBase.h.

◆ m_timeBinType

std::string LArG4::SimpleSDTool::m_timeBinType
protectedinherited

What time binning type for regular hits?

Definition at line 74 of file SimpleSDTool.h.

◆ m_timeBinWidth

float LArG4::SimpleSDTool::m_timeBinWidth
protectedinherited

What time bin width for regular hits?

Definition at line 76 of file SimpleSDTool.h.

◆ m_useFrozenShowers

G4bool LArG4::SimpleSDTool::m_useFrozenShowers
protectedinherited

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

Definition at line 78 of file SimpleSDTool.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 82 of file SensitiveDetectorBase.h.


The documentation for this class was generated from the following file:
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
LArG4::SimpleSDTool::m_useFrozenShowers
G4bool m_useFrozenShowers
Is there going to be a fast simulation coming into this SD?
Definition: SimpleSDTool.h:78
SensitiveDetectorBase::m_SD
G4VSensitiveDetector * m_SD
The sensitive detector to which this thing corresponds.
Definition: SensitiveDetectorBase.h:111
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SensitiveDetectorBase::getSD
G4VSensitiveDetector * getSD()
Retrieve the current SD.
Definition: SensitiveDetectorBase.cxx:123
python.selector.AtlRunQuerySelectorLhcOlc.sd
sd
Definition: AtlRunQuerySelectorLhcOlc.py:612
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
SensitiveDetectorBase::SetSensitiveDetector
void SetSensitiveDetector(G4LogicalVolume *, G4VSensitiveDetector *) const
Method stolen from G4VUserDetectorConstruction in G4 10.2.
Definition: SensitiveDetectorBase.cxx:178
SensitiveDetectorBase::matchStrings
static bool matchStrings(const char *first, const char *second)
Match two strings with wildcard support.
Definition: SensitiveDetectorBase.cxx:150
SensitiveDetectorBase::m_volumeNames
Gaudi::Property< std::vector< std::string > > m_volumeNames
All the volumes to which this SD is assigned.
Definition: SensitiveDetectorBase.h:82
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:87
DeMoScan.first
bool first
Definition: DeMoScan.py:536
DEBUG
#define DEBUG
Definition: page_access.h:11
SensitiveDetectorBase::setSD
void setSD(G4VSensitiveDetector *)
Set the current SD.
Definition: SensitiveDetectorBase.cxx:137
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
SensitiveDetectorBase::assignSD
StatusCode assignSD(G4VSensitiveDetector *sd, const std::vector< std::string > &volumes) const
Assign SD to a list of volumes.
Definition: SensitiveDetectorBase.cxx:70