File indexing completed on 2025-01-18 09:14:19
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include <DDG4/Geant4DetectorConstruction.h>
0017
0018
0019 namespace dd4hep {
0020
0021
0022 namespace sim {
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 class Geant4DetectorSensitivesConstruction : public Geant4DetectorConstruction {
0036 public:
0037
0038 Geant4DetectorSensitivesConstruction(Geant4Context* ctxt, const std::string& nam);
0039
0040 virtual ~Geant4DetectorSensitivesConstruction();
0041
0042 void constructSensitives(Geant4DetectorConstructionContext* ctxt);
0043 };
0044 }
0045 }
0046
0047
0048
0049 #include <DD4hep/InstanceCount.h>
0050 #include <DD4hep/Printout.h>
0051 #include <DD4hep/Plugins.h>
0052 #include <DD4hep/Detector.h>
0053
0054 #include <DDG4/Geant4Mapping.h>
0055 #include <DDG4/Geant4Kernel.h>
0056 #include <DDG4/Factories.h>
0057
0058
0059 #include <TGeoManager.h>
0060
0061 #include <G4SDManager.hh>
0062 #include <G4PVPlacement.hh>
0063 #include <G4VSensitiveDetector.hh>
0064
0065 using namespace dd4hep::sim;
0066
0067 DECLARE_GEANT4ACTION(Geant4DetectorSensitivesConstruction)
0068
0069
0070 Geant4DetectorSensitivesConstruction::Geant4DetectorSensitivesConstruction(Geant4Context* ctxt, const std::string& nam)
0071 : Geant4DetectorConstruction(ctxt,nam)
0072 {
0073 InstanceCount::increment(this);
0074 }
0075
0076
0077 Geant4DetectorSensitivesConstruction::~Geant4DetectorSensitivesConstruction() {
0078 InstanceCount::decrement(this);
0079 }
0080
0081
0082 void Geant4DetectorSensitivesConstruction::constructSensitives(Geant4DetectorConstructionContext* ctxt) {
0083 Geant4GeometryInfo* p = Geant4Mapping::instance().ptr();
0084 const Geant4Kernel& kernel = context()->kernel();
0085 const auto& types = kernel.sensitiveDetectorTypes();
0086 const std::string& dflt = kernel.defaultSensitiveDetectorType();
0087 for( const auto& iv : p->sensitives ) {
0088 SensitiveDetector sd = iv.first;
0089 std::string nam = sd.name();
0090 auto iter = types.find(nam);
0091 std::string typ = (iter != types.end()) ? (*iter).second : dflt;
0092 G4VSensitiveDetector* g4sd = this->createSensitiveDetector(typ, nam);
0093 for( const TGeoVolume* vol : iv.second ) {
0094 G4LogicalVolume* g4v = p->g4Volumes[vol];
0095 if( !g4v ) {
0096 except("ConstructSDandField: Failed to access G4LogicalVolume for SD %s of type %s.",
0097 nam.c_str(), typ.c_str());
0098 }
0099 ctxt->setSensitiveDetector(g4v, g4sd);
0100 }
0101 }
0102 print("+++ Handled %ld sensitive detectors.",p->sensitives.size());
0103 }