DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Factories.h
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 #ifndef DDG4_FACTORIES_H
14 #define DDG4_FACTORIES_H
15 
16 // Framework include files
17 #include <DDG4/Defs.h>
18 #include <DD4hep/Plugins.h>
19 #include <DD4hep/Printout.h>
20 #include <DD4hep/Factories.h>
21 #include <DD4hep/Primitives.h>
22 
23 // C/C++ include files
24 #include <string>
25 #include <map>
26 
27 // Forward declarations
28 class TGeoVolume;
29 class G4VSolid;
30 class G4Material;
31 class G4LogicalVolume;
32 class G4ParticleDefinition;
34 class G4MagIntegratorStepper;
35 class G4EquationOfMotion;
36 class G4MagneticField;
37 class G4Mag_EqRhs;
39 class G4VUserPhysicsList;
40 class G4VPrimaryGenerator;
41 class G4VProcess;
42 
44 namespace dd4hep {
45 
46  class DetElement;
47  class Material;
48  class Volume;
49  class Detector;
50 
52  namespace detail {
53  class GeoHandler;
54  }
55 
57  namespace sim {
58  class Geant4Context;
59  class Geant4Action;
60  class Geant4Converter;
61  class Geant4Sensitive;
62  class Geant4UserPhysics;
63  class Geant4EventReader;
64  class Geant4PhysicsListActionSequence;
65  }
66 
68  template <typename T> class Geant4SetupAction : public PluginFactoryBase {
69  public:
70  static long create(dd4hep::Detector& description, const dd4hep::detail::GeoHandler& cnv, const std::map<str_t,str_t>& attrs);
71  };
73  template <typename T> class Geant4SensitiveDetectorFactory : public PluginFactoryBase {
74  public:
75  static G4VSensitiveDetector* create(const str_t& name, dd4hep::Detector& description);
76  };
77 
79  template <typename T> class Geant4MaterialFactory : public PluginFactoryBase {
80  public:
81  static G4Material* create(dd4hep::Detector& description, dd4hep::Material mat, G4Material* base_material);
82  };
83 
85  template <typename T> class Geant4LogicalVolumeFactory : public PluginFactoryBase {
86  public:
87  static G4LogicalVolume* create(dd4hep::Detector& description, dd4hep::Volume vol, G4VSolid* sol, G4Material* mat);
88  };
89 
90 }
91 
92 namespace {
93 
94  namespace DS = dd4hep::sim;
95  struct _ns {
96  typedef dd4hep::detail::GeoHandler GH;
97  typedef dd4hep::sim::Geant4Action GA;
98  typedef dd4hep::sim::Geant4Context CT;
100  typedef std::map<std::string,std::string> STRM;
101  typedef G4MagIntegratorStepper Stepper;
102  };
103 
104  DD4HEP_PLUGIN_FACTORY_ARGS_3(long, dd4hep::Detector*, const _ns::GH*, const _ns::STRM*) {
105  static long ret;
106  long result = dd4hep::Geant4SetupAction<P>::create(*a0, *a1, *a2);
107  ret = result;
108  return long(&ret);
109  }
110 
112  DD4HEP_PLUGIN_FACTORY_ARGS_4(G4LogicalVolume*,dd4hep::Detector*,dd4hep::Volume,G4VSolid*,G4Material*)
113  { return dd4hep::Geant4LogicalVolumeFactory<P>::create(*a0, a1, a2, a3); }
114 
117  { return dd4hep::Geant4MaterialFactory<P>::create(*a0,a1,a2); }
118 
122 
125  { return new P(a0, a1, *a2, *a3); }
126 
129  { return new P(a0,a1); }
130 
133  { return new P(a0); }
134 
136  DD4HEP_PLUGIN_FACTORY_ARGS_1(_ns::Stepper*,G4EquationOfMotion*)
137  { return new P(a0); }
138 
140  DD4HEP_PLUGIN_FACTORY_ARGS_1(_ns::Stepper*,G4Mag_EqRhs*)
141  { return new P(a0); }
142 
144  DD4HEP_PLUGIN_FACTORY_ARGS_0(G4VProcess*)
145  { return (G4VProcess*)new P(); }
146 
149  { return new P(); }
150 
152  DD4HEP_PLUGIN_FACTORY_ARGS_0(G4ParticleDefinition*)
153  { return P::Definition(); }
154 
156  DD4HEP_PLUGIN_FACTORY_ARGS_0(G4VPrimaryGenerator*)
157  { return new P(); }
158 
161  P::ConstructParticle();
162  static long ret;
163  ret = 1L;
164  return long(&ret);
165  }
166 
169  dd4hep::printout(dd4hep::INFO,"PhysicsList","+++ Create physics list of type:%s",
170  dd4hep::typeName(typeid(P)).c_str());
171  return new P(a0,a1);
172  }
173 
176  { return new P(a0); }
177 }
178 
179 #define __IMPLEMENT_GEANT4SENSDET(name,func) DD4HEP_OPEN_PLUGIN(dd4hep,geant4_sd_##name) { \
180  template <> G4VSensitiveDetector* Geant4SensitiveDetectorFactory< geant4_sd_##name >:: \
181  create(const str_t& n,dd4hep::Detector& l) { return func (n,l); } \
182  DD4HEP_PLUGINSVC_FACTORY(geant4_sd_##name,name,G4VSensitiveDetector*(std::string,dd4hep::Detector*),__LINE__) }
183 
184 #define DECLARE_EXTERNAL_GEANT4SENSITIVEDETECTOR(id,func) __IMPLEMENT_GEANT4SENSDET(id,func)
185 #define DECLARE_GEANT4SENSITIVEDETECTOR(id) __IMPLEMENT_GEANT4SENSDET(id,new id)
186 #define DECLARE_GEANT4SENSITIVEDETECTOR_NS(ns,id) __IMPLEMENT_GEANT4SENSDET(id,new ns::id)
187 
188 #define DECLARE_GEANT4EXTENDEDMATERIAL(name) \
189  DD4HEP_PLUGINSVC_FACTORY(name,name,G4Material*(dd4hep::Detector*,dd4hep::Material,G4Material*),__LINE__)
190 
191 #define DECLARE_GEANT4EXTENDEDMATERIAL_NS(ns,name) using name_space::name; \
192  DD4HEP_PLUGINSVC_FACTORY(name,name,G4Material*(dd4hep::Detector*,dd4hep::Material,G4Material*),__LINE__)
193 
194 #define DECLARE_GEANT4LOGICALVOLUME(name) \
195  DD4HEP_PLUGINSVC_FACTORY(name,name,G4LogicalVolume*(dd4hep::Detector*,dd4hep::Volume,G4VSolid*,G4Material*),__LINE__)
196 
197 #define DECLARE_GEANT4LOGICALVOLUME_NS(ns,name) using name_space::name; \
198  DD4HEP_PLUGINSVC_FACTORY(name,name,G4LogicalVolume*(dd4hep::Detector*,dd4hep::Volume,G4VSolid*,G4Material*),__LINE__)
199 
200 
201 #define DECLARE_GEANT4SENSITIVE_NS(name_space,name) using name_space::name; \
202  DD4HEP_PLUGINSVC_FACTORY(name,name,DS::Geant4Sensitive*(_ns::CT*,std::string,dd4hep::DetElement*,dd4hep::Detector*),__LINE__)
203 
204 #define DECLARE_GEANT4SENSITIVE(name) DECLARE_GEANT4SENSITIVE_NS(dd4hep::sim,name)
205 
207 #define DECLARE_GEANT4ACTION_NS(name_space,name) using name_space::name; \
208  DD4HEP_PLUGINSVC_FACTORY(name,name,dd4hep::sim::Geant4Action*(_ns::CT*,std::string),__LINE__)
209 #define DECLARE_GEANT4ACTION(name) DECLARE_GEANT4ACTION_NS(dd4hep::sim,name)
211 
213 #define DECLARE_GEANT4_STEPPER(name) DD4HEP_PLUGINSVC_FACTORY(G4##name,name,_ns::Stepper*(G4EquationOfMotion*),__LINE__)
214 #define DECLARE_GEANT4_MAGSTEPPER(name) DD4HEP_PLUGINSVC_FACTORY(G4##name,name,_ns::Stepper*(G4Mag_EqRhs*),__LINE__)
215 #define DECLARE_GEANT4_MAGMOTION(name) DD4HEP_PLUGINSVC_FACTORY(G4##name,name,G4Mag_EqRhs*(G4MagneticField*),__LINE__)
217 #define DECLARE_GEANT4_PROCESS(name) DD4HEP_PLUGINSVC_FACTORY(name,name,G4VProcess*(),__LINE__)
219 #define DECLARE_GEANT4_PHYSICS(name) DD4HEP_PLUGINSVC_FACTORY(name,name,G4VPhysicsConstructor*(),__LINE__)
221 #define DECLARE_GEANT4_GENERATOR(name) DD4HEP_PLUGINSVC_FACTORY(name,name,G4VPrimaryGenerator*(),__LINE__)
223 #define DECLARE_GEANT4_PARTICLE(name) DD4HEP_PLUGINSVC_FACTORY(name,name,G4ParticleDefinition*(),__LINE__)
225 #define DECLARE_GEANT4_PARTICLEGROUP(name) DD4HEP_PLUGINSVC_FACTORY(name,name,long(),__LINE__)
227 #define DECLARE_GEANT4_PHYSICS_LIST(name) typedef DS::Geant4UserPhysicsList< name > G4_physics_list_##name; \
229  DD4HEP_PLUGINSVC_FACTORY(G4_physics_list_##name,name,G4VUserPhysicsList*(DS::Geant4PhysicsListActionSequence*,int),__LINE__)
230 #define DECLARE_GEANT4_SETUP(name,func) DD4HEP_OPEN_PLUGIN(dd4hep,xml_g4_setup_##name) { \
232  template <> long Geant4SetupAction< xml_g4_setup_##name >:: \
233  create(dd4hep::Detector& l,const _ns::GH& e, const _ns::STRM& a) {return func(l,e,a);} \
234  DD4HEP_PLUGINSVC_FACTORY(xml_g4_setup_##name,name##_Geant4_action,long(dd4hep::Detector*,const _ns::GH*,const _ns::STRM*),__LINE__) }
235 
237 #define DECLARE_GEANT4_EVENT_READER(name) DD4HEP_PLUGINSVC_FACTORY(name,name,_ns::RDR*(std::string),__LINE__)
238 
240 #define DECLARE_GEANT4_EVENT_READER_NS(name_space,name) typedef name_space::name __##name##__; \
241  DD4HEP_PLUGINSVC_FACTORY(__##name##__,name,_ns::RDR*(std::string),__LINE__)
242 
243 #endif // DDG4_FACTORIES_H
dd4hep::Geant4MaterialFactory
Templated factory method to G4ExtendedMaterial objects.
Definition: Factories.h:79
DD4HEP_PLUGIN_FACTORY_ARGS_3
#define DD4HEP_PLUGIN_FACTORY_ARGS_3(R, A0, A1, A2)
Definition: Plugins.h:184
DD4HEP_PLUGIN_FACTORY_ARGS_4
#define DD4HEP_PLUGIN_FACTORY_ARGS_4(R, A0, A1, A2, A3)
Definition: Plugins.h:192
dd4hep::Geant4MaterialFactory::create
static G4Material * create(dd4hep::Detector &description, dd4hep::Material mat, G4Material *base_material)
Factories.h
DD4HEP_PLUGIN_FACTORY_ARGS_1
#define DD4HEP_PLUGIN_FACTORY_ARGS_1(R, A0)
Definition: Plugins.h:168
DD4HEP_PLUGIN_FACTORY_ARGS_0
#define DD4HEP_PLUGIN_FACTORY_ARGS_0(R)
Definition: Plugins.h:160
dd4hep::Geant4SensitiveDetectorFactory
Deprecated: Templated factory method to create sensitive detector.
Definition: Factories.h:73
DD4HEP_PLUGIN_FACTORY_ARGS_2
#define DD4HEP_PLUGIN_FACTORY_ARGS_2(R, A0, A1)
Definition: Plugins.h:176
dd4hep::Material
Handle class describing a material.
Definition: Objects.h:272
dd4hep::Geant4LogicalVolumeFactory
Templated factory method to G4ExtendedMaterial objects.
Definition: Factories.h:85
dd4hep::DetElement
Handle class describing a detector element.
Definition: DetElement.h:188
dd4hep::Volume
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:370
dd4hep::detail::GeoHandler
The base class for all dd4hep geometry crawlers.
Definition: GeoHandler.h:87
dd4hep::Geant4LogicalVolumeFactory::create
static G4LogicalVolume * create(dd4hep::Detector &description, dd4hep::Volume vol, G4VSolid *sol, G4Material *mat)
G4VSensitiveDetector
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
Definition: Geant4Classes.h:59
dd4hep::PluginFactoryBase::str_t
std::string str_t
Definition: Plugins.h:51
dd4hep::sim::Geant4PhysicsListActionSequence
The implementation of the single Geant4 physics list action sequence.
Definition: Geant4PhysicsList.h:223
dd4hep::PluginFactoryBase
Factory base class implementing some utilities.
Definition: Plugins.h:50
Plugins.h
dd4hep::sim::Geant4Action
Default base class for all Geant 4 actions and derivates thereof.
Definition: Geant4Action.h:113
dd4hep::sim::Geant4EventReader
Basic geant4 event reader class. This interface/base-class must be implemented by concrete readers.
Definition: Geant4InputAction.h:60
G4VPhysicsConstructor
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
Definition: Geant4Classes.h:51
Primitives.h
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: Geant4Output2EDM4hep.cpp:49
dd4hep::Geant4SetupAction
Templated factory method to invoke setup action.
Definition: Factories.h:68
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
dd4hep::sim::Geant4Sensitive
The base class for Geant4 sensitive detector actions implemented by users.
Definition: Geant4SensDetAction.h:121
dd4hep::Geant4SensitiveDetectorFactory::create
static G4VSensitiveDetector * create(const str_t &name, dd4hep::Detector &description)
Defs.h
Printout.h
dd4hep::Geant4SetupAction::create
static long create(dd4hep::Detector &description, const dd4hep::detail::GeoHandler &cnv, const std::map< str_t, str_t > &attrs)
dd4hep::sim::Geant4Context
Generic context to extend user, run and event information.
Definition: Geant4Context.h:201
G4MagneticField
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
Definition: Geant4Classes.h:11