ATLAS Offline Software
Loading...
Searching...
No Matches
TileGeoG4CalibSDTool Class Reference

#include <TileGeoG4CalibSDTool.h>

Inheritance diagram for TileGeoG4CalibSDTool:
Collaboration diagram for TileGeoG4CalibSDTool:

Public Member Functions

 TileGeoG4CalibSDTool (const std::string &type, const std::string &name, const IInterface *parent)
 Constructor.
virtual StatusCode initialize () override final
 Default constructor is fine.
virtual StatusCode SetupEvent (HitCollectionMap &) override final
 Beginning of an athena event.
virtual StatusCode Gather (HitCollectionMap &) override final
 End of an athena event.
StatusCode initializeSD () override
 Setup an SD in the current thread.

Protected Member Functions

virtual G4VSensitiveDetector * makeSD () const override final
 Make me an SD!
StatusCode assignSD (std::unique_ptr< G4VSensitiveDetector > sd, const std::vector< std::string > &volumes) const
 Assign SD to a list of volumes.
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.

Static Private Member Functions

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

Private Attributes

ServiceHandle< ITileCalculatorm_tileCalculator {this, "TileCalculator", "TileGeoG4SDCalc"}
 Calculator Service.
std::string m_tileHits {}
std::string m_tileActiveCellCalibHits {}
std::string m_tileInactiveCellCalibHits {}
std::string m_tileDeadMaterialCalibHits {}

Detailed Description

Definition at line 25 of file TileGeoG4CalibSDTool.h.

Constructor & Destructor Documentation

◆ TileGeoG4CalibSDTool()

TileGeoG4CalibSDTool::TileGeoG4CalibSDTool ( 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 55 of file SensitiveDetectorBase.cxx.

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

virtual StatusCode TileGeoG4CalibSDTool::Gather ( HitCollectionMap & )
finaloverridevirtual

End of an athena event.

Reimplemented from SensitiveDetectorBase.

◆ initialize()

virtual StatusCode TileGeoG4CalibSDTool::initialize ( )
finaloverridevirtual

Default constructor is fine.

◆ 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 the SD stored by this tool
39 auto sd = std::unique_ptr<G4VSensitiveDetector>(makeSD());
40 if(!sd)
41 {
42 ATH_MSG_ERROR("Failed to create SD!");
43 return StatusCode::FAILURE;
44 }
45 // Assign the SD to our list of volumes
46 ATH_CHECK( assignSD( std::move(sd), m_volumeNames.value() ) );
47
48 ATH_MSG_DEBUG( "Initialized and added SD " << name() );
49 return StatusCode::SUCCESS;
50}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
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.
Gaudi::Property< bool > m_noVolumes
This SensitiveDetector has no volumes associated with it.

◆ makeSD()

virtual G4VSensitiveDetector * TileGeoG4CalibSDTool::makeSD ( ) const
finaloverrideprotectedvirtual

Make me an SD!

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

116{
117 // If we reach at the end of both strings, we are done
118 if (*first == '\0' && *second == '\0')
119 return true;
120
121 // If there are consecutive '*' present in the first string
122 // advance to the next character
123 if(*first == '*' && *(first + 1) == '*')
124 return matchStrings(first + 1, second);
125
126 // Make sure that the characters after '*' are present in second string.
127 if (*first == '*' && *(first + 1) != '\0' && *second == '\0')
128 return false;
129
130 // If the current characters of both strings match
131 if (*first == *second)
132 return matchStrings(first + 1, second + 1);
133
134 // If there is *, then there are two possibilities
135 // a) We consider current character of second string
136 // b) We ignore current character of second string.
137 if (*first == '*')
138 return matchStrings(first + 1, second) || matchStrings(first, second + 1);
139 return false;
140}

◆ SetSensitiveDetector()

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

Method stolen from G4VUserDetectorConstruction in G4 10.2.

Definition at line 142 of file SensitiveDetectorBase.cxx.

144{
145 // New Logic: allow for "multiple" SDs being attached to a single LV.
146 // To do that we use a special proxy SD called G4MultiSensitiveDetector
147
148 // Get existing SD if already set and check if it is of the special type
149 G4VSensitiveDetector* originalSD = logVol->GetSensitiveDetector();
150 if ( originalSD == nullptr )
151 {
152 logVol->SetSensitiveDetector(aSD);
153 }
154 else
155 {
156 G4MultiSensitiveDetector* msd = dynamic_cast<G4MultiSensitiveDetector*>(originalSD);
157 if ( msd != nullptr )
158 {
159 msd->AddSD(aSD);
160 }
161 else
162 {
163 // Construct a unique name using the volume address
164 std::stringstream ss;
166 const G4String msdname = "/MultiSD_" + logVol->GetName() + ss.str();
167 msd = new G4MultiSensitiveDetector(std::move(msdname));
168 // We need to register the proxy to have correct handling of IDs
169 G4SDManager::GetSDMpointer()->AddNewDetector(msd);
170 msd->AddSD(originalSD);
171 msd->AddSD(aSD);
172 logVol->SetSensitiveDetector(msd);
173 }
174 }
175}
static Double_t ss

◆ SetupEvent()

virtual StatusCode TileGeoG4CalibSDTool::SetupEvent ( HitCollectionMap & )
finaloverridevirtual

Beginning of an athena event.

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

Reimplemented from SensitiveDetectorBase.

Member Data Documentation

◆ m_noVolumes

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

This SensitiveDetector has no volumes associated with it.

Definition at line 83 of file SensitiveDetectorBase.h.

83{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 80 of file SensitiveDetectorBase.h.

80{this, "OutputCollectionNames", {}};

◆ m_tileActiveCellCalibHits

std::string TileGeoG4CalibSDTool::m_tileActiveCellCalibHits {}
private

Definition at line 48 of file TileGeoG4CalibSDTool.h.

48{};

◆ m_tileCalculator

ServiceHandle<ITileCalculator> TileGeoG4CalibSDTool::m_tileCalculator {this, "TileCalculator", "TileGeoG4SDCalc"}
private

Calculator Service.

Definition at line 45 of file TileGeoG4CalibSDTool.h.

45{this, "TileCalculator", "TileGeoG4SDCalc"};

◆ m_tileDeadMaterialCalibHits

std::string TileGeoG4CalibSDTool::m_tileDeadMaterialCalibHits {}
private

Definition at line 50 of file TileGeoG4CalibSDTool.h.

50{};

◆ m_tileHits

std::string TileGeoG4CalibSDTool::m_tileHits {}
private

Definition at line 47 of file TileGeoG4CalibSDTool.h.

47{};

◆ m_tileInactiveCellCalibHits

std::string TileGeoG4CalibSDTool::m_tileInactiveCellCalibHits {}
private

Definition at line 49 of file TileGeoG4CalibSDTool.h.

49{};

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

78{this, "LogicalVolumeNames", {}};

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