DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4DetectorSensitivesConstruction.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // \author Markus Frank
11 // \date 2015-11-09
12 //
13 //==========================================================================
14 
15 // Framework include files
17 
19 namespace dd4hep {
20 
22  namespace sim {
23 
25 
36  public:
38  Geant4DetectorSensitivesConstruction(Geant4Context* ctxt, const std::string& nam);
43  };
44  } // End namespace sim
45 } // End namespace dd4hep
46 
47 
48 // Framework include files
49 #include <DD4hep/InstanceCount.h>
50 #include <DD4hep/Printout.h>
51 #include <DD4hep/Plugins.h>
52 #include <DD4hep/Detector.h>
53 
54 #include <DDG4/Geant4Mapping.h>
55 #include <DDG4/Geant4Kernel.h>
56 #include <DDG4/Factories.h>
57 
58 // ROOT include files
59 #include <TGeoManager.h>
60 // Geant4 include files
61 #include <G4SDManager.hh>
62 #include <G4PVPlacement.hh>
63 #include <G4VSensitiveDetector.hh>
64 
65 using namespace dd4hep::sim;
66 
68 
72 {
74 }
75 
79 }
80 
84  const Geant4Kernel& kernel = context()->kernel();
85  const auto& types = kernel.sensitiveDetectorTypes();
86  const std::string& dflt = kernel.defaultSensitiveDetectorType();
87  for( const auto& iv : p->sensitives ) {
88  SensitiveDetector sd = iv.first;
89  std::string nam = sd.name();
90  auto iter = types.find(nam);
91  std::string typ = (iter != types.end()) ? (*iter).second : dflt;
92  G4VSensitiveDetector* g4sd = this->createSensitiveDetector(typ, nam);
93  for( const TGeoVolume* vol : iv.second ) {
94  G4LogicalVolume* g4v = p->g4Volumes[vol];
95  if( !g4v ) {
96  except("ConstructSDandField: Failed to access G4LogicalVolume for SD %s of type %s.",
97  nam.c_str(), typ.c_str());
98  }
99  ctxt->setSensitiveDetector(g4v, g4sd);
100  }
101  }
102  print("+++ Handled %ld sensitive detectors.",p->sensitives.size());
103 }
dd4hep::sim::Geant4DetectorSensitivesConstruction
Class to create Geant4 detector geometry from TGeo representation in memory.
Definition: Geant4DetectorSensitivesConstruction.cpp:35
dd4hep::sim::Geant4GeometryInfo::sensitives
std::map< SensitiveDetector, std::set< const TGeoVolume * > > sensitives
Definition: Geant4GeometryInfo.h:137
Geant4DetectorConstruction.h
Geant4Mapping.h
dd4hep::SensitiveDetector
Handle class to hold the information of a sensitive detector.
Definition: DetElement.h:44
Detector.h
dd4hep::sim::Geant4Kernel
Class, which allows all Geant4Action derivatives to access the DDG4 kernel structures.
Definition: Geant4Kernel.h:64
dd4hep::InstanceCount::increment
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
dd4hep::sim::Geant4Mapping::instance
static Geant4Mapping & instance()
Possibility to define a singleton instance.
Definition: Geant4Mapping.cpp:35
dd4hep::Handle::name
const char * name() const
Access the object name (or "" if not supported by the object)
DECLARE_GEANT4ACTION
#define DECLARE_GEANT4ACTION(name)
Plugin defintion to create Geant4Action objects.
Definition: Factories.h:210
dd4hep::sim::Geant4DetectorSensitivesConstruction::constructSensitives
void constructSensitives(Geant4DetectorConstructionContext *ctxt)
Sensitives construction callback. Called at "ConstructSDandField()".
Definition: Geant4DetectorSensitivesConstruction.cpp:82
dd4hep::sim::Geant4Action::except
void except(const char *fmt,...) const
Support of exceptions: Print fatal message and throw runtime_error.
Definition: Geant4Action.cpp:256
dd4hep::sim::Geant4DetectorConstructionContext
Geant4 detector construction context definition.
Definition: Geant4DetectorConstruction.h:61
dd4hep::sim::Geant4Kernel::sensitiveDetectorTypes
const std::map< std::string, std::string > & sensitiveDetectorTypes() const
Property access: Names with specialized factories to create G4VSensitiveDetector instances.
Definition: Geant4Kernel.h:223
dd4hep::sim::Geant4Mapping::ptr
Geant4GeometryInfo * ptr() const
Access to the data pointer.
Definition: Geant4Mapping.h:63
G4VSensitiveDetector
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
Definition: Geant4Classes.h:59
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
dd4hep::sim::Geant4Kernel::defaultSensitiveDetectorType
const std::string defaultSensitiveDetectorType() const
Property access: Name of the default factory to create G4VSensitiveDetector instances.
Definition: Geant4Kernel.h:219
Plugins.h
dd4hep::sim::Geant4DetectorSensitivesConstruction::~Geant4DetectorSensitivesConstruction
virtual ~Geant4DetectorSensitivesConstruction()
Default destructor.
Definition: Geant4DetectorSensitivesConstruction.cpp:77
dd4hep::sim::Geant4Action::print
void print(const char *fmt,...) const
Support for messages with variable output level using output level.
Definition: Geant4Action.cpp:144
Factories.h
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: Geant4Output2EDM4hep.cpp:49
dd4hep::sim::Geant4Context::kernel
Geant4Kernel & kernel() const
Access to the kernel object.
Definition: Geant4Context.h:233
dd4hep::sim::Geant4GeometryInfo
Concreate class holding the relation information between geant4 objects and dd4hep objects.
Definition: Geant4GeometryInfo.h:93
dd4hep::sim::Geant4DetectorSensitivesConstruction::Geant4DetectorSensitivesConstruction
Geant4DetectorSensitivesConstruction(Geant4Context *ctxt, const std::string &nam)
Initializing constructor for DDG4.
Definition: Geant4DetectorSensitivesConstruction.cpp:70
dd4hep::sim::Geant4DetectorConstructionContext::setSensitiveDetector
void setSensitiveDetector(G4LogicalVolume *vol, G4VSensitiveDetector *sd)
Helper: Assign sensitive detector to logical volume.
Definition: Geant4DetectorConstruction.cpp:27
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
Geant4Kernel.h
InstanceCount.h
dd4hep::sim::Geant4DetectorConstruction
Basic implementation of the Geant4 detector construction action.
Definition: Geant4DetectorConstruction.h:102
Printout.h
dd4hep::sim::Geant4Context
Generic context to extend user, run and event information.
Definition: Geant4Context.h:201
dd4hep::sim::Geant4Action::context
Geant4Context * context() const
Access the context.
Definition: Geant4Action.h:270
dd4hep::sim::Geant4GeometryInfo::g4Volumes
Geant4GeometryMaps::VolumeMap g4Volumes
Definition: Geant4GeometryInfo.h:116