DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4DetectorConstruction.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 : M.Frank
11 //
12 //==========================================================================
13 
14 // Framework include files
15 #include <DD4hep/Plugins.h>
16 #include <DD4hep/InstanceCount.h>
17 #include <DDG4/Geant4Mapping.h>
20 
21 #include <G4VUserDetectorConstruction.hh>
22 #include <G4SDManager.hh>
23 
24 using namespace dd4hep::sim;
25 
28  //detector->SetSensitiveDetector(vol,sd);
29  G4SDManager::GetSDMpointer()->AddNewDetector(sd);
30  vol->SetSensitiveDetector(sd);
31 }
32 
35  : Geant4Action(ctxt,nam)
36 {
37 }
38 
41 }
42 
46  const std::string& nam) {
48  G4VSensitiveDetector* g4sd = PluginService::Create<G4VSensitiveDetector*>(typ, nam, &dsc);
49  if( g4sd ) {
50  print("+++ Subdetector: %-32s type: %s.", nam.c_str(), typ.c_str());
51  }
52  else {
53  PluginDebug dbg;
54  g4sd = PluginService::Create<G4VSensitiveDetector*>(typ, nam, &dsc);
55  if ( !g4sd ) {
56  except("createSensitiveDetector: FATAL Failed to "
57  "create Geant4 sensitive detector %s of type %s.",
58  nam.c_str(), typ.c_str());
59  }
60  print("+++ Subdetector: %-32s type: %s.", nam.c_str(), typ.c_str());
61  }
62  if ( g4sd ) {
63  g4sd->Activate(true);
64  G4SDManager::GetSDMpointer()->AddNewDetector(g4sd);
65  }
66  return g4sd;
67 }
68 
71 }
72 
75 }
76 
79 }
80 
83  : Geant4Action(ctxt,nam)
84 {
85  m_needsControl = true;
87 }
88 
93 }
94 
97  m_context = ctxt;
99 }
100 
103  if (action) {
104  action->addRef();
105  m_actors.add(action);
106  return;
107  }
108  except("++ Attempt to add an invalid actor!");
109 }
110 
113  for(auto* i : m_actors) {
114  if ( i->name() == nam ) {
115  return i;
116  }
117  }
118  except("++ Attempt to access invalid actor %s!",nam.c_str());
119  return nullptr;
120 }
121 
125 }
126 
130 }
131 
135 }
136 
138 const std::map<dd4hep::Region, G4Region*>&
141  if ( p ) return p->g4Regions;
142  throw std::runtime_error("+++ Geant4DetectorConstructionSequence::regions: Access not possible. Geometry is not yet converted!");
143 }
144 
146 const std::map<dd4hep::Volume, G4LogicalVolume*>&
149  if ( p ) return p->g4Volumes;
150  throw std::runtime_error("+++ Geant4DetectorConstructionSequence::volumes: Access not possible. Geometry is not yet converted!");
151 }
152 
154 const std::map<const TGeoShape*, G4VSolid*>& Geant4DetectorConstructionSequence::shapes() const {
156  if ( p ) return p->g4Solids;
157  throw std::runtime_error("+++ Geant4DetectorConstructionSequence::shapes: Access not possible. Geometry is not yet converted!");
158 }
159 
161 const std::map<dd4hep::LimitSet, G4UserLimits*>&
164  if ( p ) return p->g4Limits;
165  throw std::runtime_error("+++ Geant4DetectorConstructionSequence::limits: Access not possible. Geometry is not yet converted!");
166 }
167 
169 const std::map<dd4hep::PlacedVolume, Geant4AssemblyVolume*>&
172  if ( p ) return p->g4AssemblyVolumes;
173  throw std::runtime_error("+++ Geant4DetectorConstructionSequence::assemblies: Access not possible. Geometry is not yet converted!");
174 }
175 
177 const std::map<dd4hep::PlacedVolume, G4VPhysicalVolume*>&
180  if ( p ) return p->g4Placements;
181  throw std::runtime_error("+++ Geant4DetectorConstructionSequence::placements: Access not possible. Geometry is not yet converted!");
182 }
183 
187  if ( p ) return p->g4Materials;
188  throw std::runtime_error("+++ Geant4DetectorConstructionSequence::materials: Access not possible. Geometry is not yet converted!");
189 }
190 
194  if ( p ) return p->g4Elements;
195  throw std::runtime_error("+++ Geant4DetectorConstructionSequence::elements: Access not possible. Geometry is not yet converted!");
196 }
197 
198 
199 
200 
dd4hep::sim::Geant4Action::updateContext
virtual void updateContext(Geant4Context *ctxt)
Set or update client context.
Definition: Geant4Action.h:274
Geant4DetectorConstruction.h
dd4hep::sim::Geant4Action::m_needsControl
bool m_needsControl
Default property: Flag to create control instance.
Definition: Geant4Action.h:123
dd4hep::sim::Geant4DetectorConstructionSequence::constructField
virtual void constructField(Geant4DetectorConstructionContext *ctxt)
Electromagnetic field construction callback. Called at "ConstructSDandField()".
Definition: Geant4DetectorConstruction.cpp:128
Geant4GeometryInfo.h
dd4hep::sim::Geant4GeometryInfo::g4AssemblyVolumes
Geant4GeometryMaps::AssemblyMap g4AssemblyVolumes
Definition: Geant4GeometryInfo.h:118
dd4hep::sim::Geant4DetectorConstruction::constructSensitives
virtual void constructSensitives(Geant4DetectorConstructionContext *ctxt)
Sensitive detector construction callback. Called at "ConstructSDandField()".
Definition: Geant4DetectorConstruction.cpp:78
dd4hep::sim::Geant4Context::detectorDescription
Detector & detectorDescription() const
Access to detector description.
Definition: Geant4Context.cpp:91
Geant4Mapping.h
dd4hep::sim::Geant4GeometryInfo::g4Regions
std::map< Region, G4Region * > g4Regions
Definition: Geant4GeometryInfo.h:133
dd4hep::sim::Geant4DetectorConstruction::createSensitiveDetector
virtual G4VSensitiveDetector * createSensitiveDetector(const std::string &type, const std::string &name)
Create Geant4 sensitive detector object using the factory mechanism.
Definition: Geant4DetectorConstruction.cpp:45
dd4hep::sim::Geant4Action::m_context
Geant4Context * m_context
Reference to the Geant4 context.
Definition: Geant4Action.h:116
dd4hep::sim::Geant4DetectorConstructionSequence::~Geant4DetectorConstructionSequence
virtual ~Geant4DetectorConstructionSequence()
Default destructor.
Definition: Geant4DetectorConstruction.cpp:90
dd4hep::sim::Geant4GeometryInfo::g4Materials
Geant4GeometryMaps::MaterialMap g4Materials
Definition: Geant4GeometryInfo.h:114
dd4hep::sim::Geant4DetectorConstructionSequence::shapes
const std::map< const TGeoShape *, G4VSolid * > & shapes() const
Access to the converted shapes.
Definition: Geant4DetectorConstruction.cpp:154
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::sim::Geant4DetectorConstructionSequence::updateContext
virtual void updateContext(Geant4Context *ctxt) override
Set or update client context.
Definition: Geant4DetectorConstruction.cpp:96
dd4hep::sim::Geant4DetectorConstruction::Geant4DetectorConstruction
Geant4DetectorConstruction(Geant4Context *context, const std::string &nam)
Standard Constructor.
Definition: Geant4DetectorConstruction.cpp:34
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::Geant4DetectorConstructionSequence::constructGeo
virtual void constructGeo(Geant4DetectorConstructionContext *ctxt)
Geometry construction callback. Called at "Construct()".
Definition: Geant4DetectorConstruction.cpp:123
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::sim::Geant4GeometryInfo::g4Placements
Geant4GeometryMaps::PlacementMap g4Placements
Definition: Geant4GeometryInfo.h:117
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
dd4hep::sim::Geant4DetectorConstructionSequence::elements
const std::map< Atom, G4Element * > & elements() const
Access to the converted elements.
Definition: Geant4DetectorConstruction.cpp:192
dd4hep::sim::Geant4DetectorConstructionSequence::adopt
void adopt(Geant4DetectorConstruction *action)
Add an actor responding to all callbacks. Sequence takes ownership.
Definition: Geant4DetectorConstruction.cpp:102
Plugins.h
dd4hep::sim::Geant4DetectorConstructionSequence::constructSensitives
virtual void constructSensitives(Geant4DetectorConstructionContext *ctxt)
Sensitive detector construction callback. Called at "ConstructSDandField()".
Definition: Geant4DetectorConstruction.cpp:133
dd4hep::PluginDebug
Helper to debug plugin manager calls.
Definition: Plugins.h:74
dd4hep::sim::Geant4DetectorConstructionSequence::limits
const std::map< LimitSet, G4UserLimits * > & limits() const
Access to the converted limit sets.
Definition: Geant4DetectorConstruction.cpp:162
dd4hep::sim::Geant4Action
Default base class for all Geant 4 actions and derivates thereof.
Definition: Geant4Action.h:113
dd4hep::sim::Geant4Action::release
long release()
Decrease reference count. Implicit destruction.
Definition: Geant4Action.cpp:76
dd4hep::sim::Geant4DetectorConstructionSequence::m_actors
Actors< Geant4DetectorConstruction > m_actors
The list of action objects to be called.
Definition: Geant4DetectorConstruction.h:138
dd4hep::sim::Geant4GeometryMaps::MaterialMap
std::map< Material, G4Material * > MaterialMap
Definition: Geant4GeometryInfo.h:70
dd4hep::sim::Geant4GeometryMaps::ElementMap
std::map< Atom, G4Element * > ElementMap
Definition: Geant4GeometryInfo.h:68
dd4hep::sim::Geant4DetectorConstruction::~Geant4DetectorConstruction
virtual ~Geant4DetectorConstruction()
Default destructor.
Definition: Geant4DetectorConstruction.cpp:40
dd4hep::sim::Geant4Action::print
void print(const char *fmt,...) const
Support for messages with variable output level using output level.
Definition: Geant4Action.cpp:144
dd4hep::sim::Geant4GeometryInfo::g4Limits
std::map< LimitSet, G4UserLimits * > g4Limits
Definition: Geant4GeometryInfo.h:135
dd4hep::sim::Geant4GeometryInfo::g4Solids
Geant4GeometryMaps::SolidMap g4Solids
Definition: Geant4GeometryInfo.h:115
dd4hep::sim::Geant4Action::addRef
long addRef()
Increase reference count.
Definition: Geant4Action.cpp:71
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: Geant4Output2EDM4hep.cpp:49
dd4hep::sim::Geant4DetectorConstructionSequence::get
Geant4DetectorConstruction * get(const std::string &nam) const
Access an actor by name.
Definition: Geant4DetectorConstruction.cpp:112
dd4hep::sim::Geant4GeometryInfo
Concreate class holding the relation information between geant4 objects and dd4hep objects.
Definition: Geant4GeometryInfo.h:93
dd4hep::sim::Geant4DetectorConstruction::constructGeo
virtual void constructGeo(Geant4DetectorConstructionContext *ctxt)
Geometry construction callback. Called at "Construct()".
Definition: Geant4DetectorConstruction.cpp:70
dd4hep::sim::Geant4DetectorConstructionContext::setSensitiveDetector
void setSensitiveDetector(G4LogicalVolume *vol, G4VSensitiveDetector *sd)
Helper: Assign sensitive detector to logical volume.
Definition: Geant4DetectorConstruction.cpp:27
dd4hep::sim::Geant4DetectorConstructionSequence::materials
const std::map< Material, G4Material * > & materials() const
Access to the converted materials.
Definition: Geant4DetectorConstruction.cpp:185
dd4hep::sim::Geant4DetectorConstruction::constructField
virtual void constructField(Geant4DetectorConstructionContext *ctxt)
Electromagnetic field construction callback. Called at "ConstructSDandField()".
Definition: Geant4DetectorConstruction.cpp:74
dd4hep::sim::Geant4DetectorConstructionSequence::volumes
const std::map< Volume, G4LogicalVolume * > & volumes() const
Access to the converted volumes.
Definition: Geant4DetectorConstruction.cpp:147
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
dd4hep::sim::Geant4DetectorConstructionSequence::placements
const std::map< PlacedVolume, G4VPhysicalVolume * > & placements() const
Access to the converted placements.
Definition: Geant4DetectorConstruction.cpp:178
dd4hep::sim::Geant4GeometryInfo::g4Elements
Geant4GeometryMaps::ElementMap g4Elements
Definition: Geant4GeometryInfo.h:113
InstanceCount.h
dd4hep::sim::Geant4DetectorConstruction
Basic implementation of the Geant4 detector construction action.
Definition: Geant4DetectorConstruction.h:102
dd4hep::sim::Geant4DetectorConstructionSequence::Geant4DetectorConstructionSequence
Geant4DetectorConstructionSequence(Geant4Context *context, const std::string &nam)
Standard Constructor.
Definition: Geant4DetectorConstruction.cpp:82
dd4hep::sim::Geant4DetectorConstructionSequence::regions
const std::map< Region, G4Region * > & regions() const
Access to the converted regions.
Definition: Geant4DetectorConstruction.cpp:139
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
dd4hep::sim::Geant4DetectorConstructionSequence::assemblies
const std::map< PlacedVolume, Geant4AssemblyVolume * > & assemblies() const
Access to the converted assemblys.
Definition: Geant4DetectorConstruction.cpp:170