ATLAS Offline Software
SensitiveDetectorBase.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef G4ATLASTOOLS_SENSITIVEDETECTORBASE_H
6 #define G4ATLASTOOLS_SENSITIVEDETECTORBASE_H
7 
8 #pragma GCC diagnostic push
9 // SDtools that have not yet been migrated to the new SD interface will trigger
10 // this warning because SetupEvent(AtlasG4EventUserInfo&) and
11 // Gather(AtlasG4EventUserInfo&) are hidden. this is fine, as these methods are
12 // not used in the old-style SDs, but should be migrated. Remove this when all
13 // SDs are migrated.
14 #pragma GCC diagnostic ignored "-Woverloaded-virtual"
15 
16 // Base classes
19 
20 // Members
21 #include "G4VSensitiveDetector.hh"
22 #include "G4Types.hh"
23 #ifdef G4MULTITHREADED
24 # include "tbb/concurrent_unordered_map.h"
25 #endif
26 
27 // STL library
28 #include <string>
29 #include <vector>
30 #include <thread>
31 
32 // Forward declarations
33 class G4LogicalVolume;
34 class G4VSensitiveDetector;
35 
36 
49 class SensitiveDetectorBase : public extends<AthAlgTool, ISensitiveDetector>
50 {
51 
52  public:
53 
55  SensitiveDetectorBase(const std::string& type, const std::string& name,
56  const IInterface *parent);
59 
65  StatusCode initializeSD() override;
66 
68 
70  virtual StatusCode SetupEvent() override { return StatusCode::SUCCESS; }
71  virtual StatusCode SetupEvent(HitCollectionMap&) override {
72  return SetupEvent();
73  }
74 
76 
78  virtual StatusCode Gather() override { return StatusCode::SUCCESS; }
79  virtual StatusCode Gather(HitCollectionMap&) override {
80  return Gather();
81  };
82 
83  protected:
84 
86 
87  StatusCode assignSD(G4VSensitiveDetector* sd,
88  const std::vector<std::string>& volumes) const;
89 
91 
93  G4VSensitiveDetector* getSD();
94 
96  Gaudi::Property<std::vector<std::string> > m_volumeNames{this, "LogicalVolumeNames", {}};
98  Gaudi::Property<std::vector<std::string> > m_outputCollectionNames{this, "OutputCollectionNames", {}};
99 
101  Gaudi::Property<bool> m_noVolumes{this, "NoVolumes", false};
102 
104  void SetSensitiveDetector(G4LogicalVolume*, G4VSensitiveDetector*) const;
105 
106  private:
107 
109 
110  void setSD(G4VSensitiveDetector*);
111 
113 
115  static bool matchStrings(const char *first, const char * second);
116 
117 #ifdef G4MULTITHREADED
118  using SDThreadMap_t = tbb::concurrent_unordered_map
120  < std::thread::id, G4VSensitiveDetector*, std::hash<std::thread::id> >;
122  SDThreadMap_t m_sdThreadMap;
123 #else
124  G4VSensitiveDetector* m_SD{};
126 #endif
127 
128 }; // class SensitiveDetectorBase
129 
130 #pragma GCC diagnostic pop
131 
132 #endif
SensitiveDetectorBase::SetupEvent
virtual StatusCode SetupEvent() override
Beginning of an athena event.
Definition: SensitiveDetectorBase.h:70
HitCollectionMap
Small wrapper around hit collection map to facilitate accessing the hit collection.
Definition: HitCollectionMap.h:21
SensitiveDetectorBase::m_SD
G4VSensitiveDetector * m_SD
The sensitive detector to which this thing corresponds.
Definition: SensitiveDetectorBase.h:125
SensitiveDetectorBase::~SensitiveDetectorBase
virtual ~SensitiveDetectorBase()
Empty virtual destructor.
Definition: SensitiveDetectorBase.h:58
python.SystemOfUnits.second
float second
Definition: SystemOfUnits.py:135
SensitiveDetectorBase
Common base class for tools that create and manage Geant4 sensitive detectors.
Definition: SensitiveDetectorBase.h:50
SensitiveDetectorBase::SensitiveDetectorBase
SensitiveDetectorBase(const std::string &type, const std::string &name, const IInterface *parent)
Standard constructor.
Definition: SensitiveDetectorBase.cxx:22
SensitiveDetectorBase::getSD
G4VSensitiveDetector * getSD()
Retrieve the current SD.
Definition: SensitiveDetectorBase.cxx:123
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
python.selector.AtlRunQuerySelectorLhcOlc.sd
sd
Definition: AtlRunQuerySelectorLhcOlc.py:611
SensitiveDetectorBase::SetupEvent
virtual StatusCode SetupEvent(HitCollectionMap &) override
Definition: SensitiveDetectorBase.h:71
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
AthAlgTool.h
test_pyathena.parent
parent
Definition: test_pyathena.py:15
SensitiveDetectorBase::Gather
virtual StatusCode Gather(HitCollectionMap &) override
Definition: SensitiveDetectorBase.h:79
SensitiveDetectorBase::initializeSD
StatusCode initializeSD() override
Setup an SD in the current thread.
Definition: SensitiveDetectorBase.cxx:30
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
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:239
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: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:96
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
SensitiveDetectorBase::Gather
virtual StatusCode Gather() override
End of an athena event.
Definition: SensitiveDetectorBase.h:78
SensitiveDetectorBase::setSD
void setSD(G4VSensitiveDetector *)
Set the current SD.
Definition: SensitiveDetectorBase.cxx:137
ISensitiveDetector.h
SensitiveDetectorBase::assignSD
StatusCode assignSD(G4VSensitiveDetector *sd, const std::vector< std::string > &volumes) const
Assign SD to a list of volumes.
Definition: SensitiveDetectorBase.cxx:70