File indexing completed on 2025-01-18 09:55:22
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef DDG4_FACTORIES_H
0014 #define DDG4_FACTORIES_H
0015
0016
0017 #include <DDG4/Defs.h>
0018 #include <DD4hep/Plugins.h>
0019 #include <DD4hep/Printout.h>
0020 #include <DD4hep/Factories.h>
0021 #include <DD4hep/Primitives.h>
0022
0023
0024 #include <string>
0025 #include <map>
0026
0027
0028 class TGeoVolume;
0029 class G4VSolid;
0030 class G4Material;
0031 class G4LogicalVolume;
0032 class G4ParticleDefinition;
0033 class G4VSensitiveDetector;
0034 class G4MagIntegratorStepper;
0035 class G4EquationOfMotion;
0036 class G4MagneticField;
0037 class G4Mag_EqRhs;
0038 class G4VPhysicsConstructor;
0039 class G4VUserPhysicsList;
0040 class G4VPrimaryGenerator;
0041 class G4VProcess;
0042
0043
0044 namespace dd4hep {
0045
0046 class DetElement;
0047 class Material;
0048 class Volume;
0049 class Detector;
0050
0051
0052 namespace detail {
0053 class GeoHandler;
0054 }
0055
0056
0057 namespace sim {
0058 class Geant4Context;
0059 class Geant4Action;
0060 class Geant4Converter;
0061 class Geant4Sensitive;
0062 class Geant4UserPhysics;
0063 class Geant4EventReader;
0064 class Geant4PhysicsListActionSequence;
0065 }
0066
0067
0068 template <typename T> class Geant4SetupAction : public PluginFactoryBase {
0069 public:
0070 static long create(dd4hep::Detector& description, const dd4hep::detail::GeoHandler& cnv, const std::map<str_t,str_t>& attrs);
0071 };
0072
0073 template <typename T> class Geant4SensitiveDetectorFactory : public PluginFactoryBase {
0074 public:
0075 static G4VSensitiveDetector* create(const str_t& name, dd4hep::Detector& description);
0076 };
0077
0078
0079 template <typename T> class Geant4MaterialFactory : public PluginFactoryBase {
0080 public:
0081 static G4Material* create(dd4hep::Detector& description, dd4hep::Material mat, G4Material* base_material);
0082 };
0083
0084
0085 template <typename T> class Geant4LogicalVolumeFactory : public PluginFactoryBase {
0086 public:
0087 static G4LogicalVolume* create(dd4hep::Detector& description, dd4hep::Volume vol, G4VSolid* sol, G4Material* mat);
0088 };
0089
0090 }
0091
0092 namespace {
0093
0094 namespace DS = dd4hep::sim;
0095 struct _ns {
0096 typedef dd4hep::detail::GeoHandler GH;
0097 typedef dd4hep::sim::Geant4Action GA;
0098 typedef dd4hep::sim::Geant4Context CT;
0099 typedef dd4hep::sim::Geant4EventReader RDR;
0100 typedef std::map<std::string,std::string> STRM;
0101 typedef G4MagIntegratorStepper Stepper;
0102 };
0103
0104 DD4HEP_PLUGIN_FACTORY_ARGS_3(long, dd4hep::Detector*, const _ns::GH*, const _ns::STRM*) {
0105 static long ret;
0106 long result = dd4hep::Geant4SetupAction<P>::create(*a0, *a1, *a2);
0107 ret = result;
0108 return long(&ret);
0109 }
0110
0111
0112 DD4HEP_PLUGIN_FACTORY_ARGS_4(G4LogicalVolume*,dd4hep::Detector*,dd4hep::Volume,G4VSolid*,G4Material*)
0113 { return dd4hep::Geant4LogicalVolumeFactory<P>::create(*a0, a1, a2, a3); }
0114
0115
0116 DD4HEP_PLUGIN_FACTORY_ARGS_3(G4Material*,dd4hep::Detector*,dd4hep::Material,G4Material*)
0117 { return dd4hep::Geant4MaterialFactory<P>::create(*a0,a1,a2); }
0118
0119
0120 DD4HEP_PLUGIN_FACTORY_ARGS_2(G4VSensitiveDetector*,std::string,dd4hep::Detector*)
0121 { return dd4hep::Geant4SensitiveDetectorFactory<P>::create(a0,*a1); }
0122
0123
0124 DD4HEP_PLUGIN_FACTORY_ARGS_4(DS::Geant4Sensitive*,_ns::CT*,std::string,dd4hep::DetElement*,dd4hep::Detector*)
0125 { return new P(a0, a1, *a2, *a3); }
0126
0127
0128 DD4HEP_PLUGIN_FACTORY_ARGS_2(DS::Geant4Action*,_ns::CT*, std::string)
0129 { return new P(a0,a1); }
0130
0131
0132 DD4HEP_PLUGIN_FACTORY_ARGS_1(G4Mag_EqRhs*,G4MagneticField*)
0133 { return new P(a0); }
0134
0135
0136 DD4HEP_PLUGIN_FACTORY_ARGS_1(_ns::Stepper*,G4EquationOfMotion*)
0137 { return new P(a0); }
0138
0139
0140 DD4HEP_PLUGIN_FACTORY_ARGS_1(_ns::Stepper*,G4Mag_EqRhs*)
0141 { return new P(a0); }
0142
0143
0144 DD4HEP_PLUGIN_FACTORY_ARGS_0(G4VProcess*)
0145 { return (G4VProcess*)new P(); }
0146
0147
0148 DD4HEP_PLUGIN_FACTORY_ARGS_0(G4VPhysicsConstructor*)
0149 { return new P(); }
0150
0151
0152 DD4HEP_PLUGIN_FACTORY_ARGS_0(G4ParticleDefinition*)
0153 { return P::Definition(); }
0154
0155
0156 DD4HEP_PLUGIN_FACTORY_ARGS_0(G4VPrimaryGenerator*)
0157 { return new P(); }
0158
0159
0160 DD4HEP_PLUGIN_FACTORY_ARGS_0(long) {
0161 P::ConstructParticle();
0162 static long ret;
0163 ret = 1L;
0164 return long(&ret);
0165 }
0166
0167
0168 DD4HEP_PLUGIN_FACTORY_ARGS_2(G4VUserPhysicsList*,DS::Geant4PhysicsListActionSequence*,int) {
0169 dd4hep::printout(dd4hep::INFO,"PhysicsList","+++ Create physics list of type:%s",
0170 dd4hep::typeName(typeid(P)).c_str());
0171 return new P(a0,a1);
0172 }
0173
0174
0175 DD4HEP_PLUGIN_FACTORY_ARGS_1(_ns::RDR*,std::string)
0176 { return new P(a0); }
0177 }
0178
0179 #define __IMPLEMENT_GEANT4SENSDET(name,func) DD4HEP_OPEN_PLUGIN(dd4hep,geant4_sd_##name) { \
0180 template <> G4VSensitiveDetector* Geant4SensitiveDetectorFactory< geant4_sd_##name >:: \
0181 create(const str_t& n,dd4hep::Detector& l) { return func (n,l); } \
0182 DD4HEP_PLUGINSVC_FACTORY(geant4_sd_##name,name,G4VSensitiveDetector*(std::string,dd4hep::Detector*),__LINE__) }
0183
0184 #define DECLARE_EXTERNAL_GEANT4SENSITIVEDETECTOR(id,func) __IMPLEMENT_GEANT4SENSDET(id,func)
0185 #define DECLARE_GEANT4SENSITIVEDETECTOR(id) __IMPLEMENT_GEANT4SENSDET(id,new id)
0186 #define DECLARE_GEANT4SENSITIVEDETECTOR_NS(ns,id) __IMPLEMENT_GEANT4SENSDET(id,new ns::id)
0187
0188 #define DECLARE_GEANT4EXTENDEDMATERIAL(name) \
0189 DD4HEP_PLUGINSVC_FACTORY(name,name,G4Material*(dd4hep::Detector*,dd4hep::Material,G4Material*),__LINE__)
0190
0191 #define DECLARE_GEANT4EXTENDEDMATERIAL_NS(ns,name) using name_space::name; \
0192 DD4HEP_PLUGINSVC_FACTORY(name,name,G4Material*(dd4hep::Detector*,dd4hep::Material,G4Material*),__LINE__)
0193
0194 #define DECLARE_GEANT4LOGICALVOLUME(name) \
0195 DD4HEP_PLUGINSVC_FACTORY(name,name,G4LogicalVolume*(dd4hep::Detector*,dd4hep::Volume,G4VSolid*,G4Material*),__LINE__)
0196
0197 #define DECLARE_GEANT4LOGICALVOLUME_NS(ns,name) using name_space::name; \
0198 DD4HEP_PLUGINSVC_FACTORY(name,name,G4LogicalVolume*(dd4hep::Detector*,dd4hep::Volume,G4VSolid*,G4Material*),__LINE__)
0199
0200
0201 #define DECLARE_GEANT4SENSITIVE_NS(name_space,name) using name_space::name; \
0202 DD4HEP_PLUGINSVC_FACTORY(name,name,DS::Geant4Sensitive*(_ns::CT*,std::string,dd4hep::DetElement*,dd4hep::Detector*),__LINE__)
0203
0204 #define DECLARE_GEANT4SENSITIVE(name) DECLARE_GEANT4SENSITIVE_NS(dd4hep::sim,name)
0205
0206
0207 #define DECLARE_GEANT4ACTION_NS(name_space,name) using name_space::name; \
0208 DD4HEP_PLUGINSVC_FACTORY(name,name,dd4hep::sim::Geant4Action*(_ns::CT*,std::string),__LINE__)
0209
0210 #define DECLARE_GEANT4ACTION(name) DECLARE_GEANT4ACTION_NS(dd4hep::sim,name)
0211
0212
0213 #define DECLARE_GEANT4_STEPPER(name) DD4HEP_PLUGINSVC_FACTORY(G4##name,name,_ns::Stepper*(G4EquationOfMotion*),__LINE__)
0214 #define DECLARE_GEANT4_MAGSTEPPER(name) DD4HEP_PLUGINSVC_FACTORY(G4##name,name,_ns::Stepper*(G4Mag_EqRhs*),__LINE__)
0215
0216 #define DECLARE_GEANT4_MAGMOTION(name) DD4HEP_PLUGINSVC_FACTORY(G4##name,name,G4Mag_EqRhs*(G4MagneticField*),__LINE__)
0217
0218 #define DECLARE_GEANT4_PROCESS(name) DD4HEP_PLUGINSVC_FACTORY(name,name,G4VProcess*(),__LINE__)
0219
0220 #define DECLARE_GEANT4_PHYSICS(name) DD4HEP_PLUGINSVC_FACTORY(name,name,G4VPhysicsConstructor*(),__LINE__)
0221
0222 #define DECLARE_GEANT4_GENERATOR(name) DD4HEP_PLUGINSVC_FACTORY(name,name,G4VPrimaryGenerator*(),__LINE__)
0223
0224 #define DECLARE_GEANT4_PARTICLE(name) DD4HEP_PLUGINSVC_FACTORY(name,name,G4ParticleDefinition*(),__LINE__)
0225
0226 #define DECLARE_GEANT4_PARTICLEGROUP(name) DD4HEP_PLUGINSVC_FACTORY(name,name,long(),__LINE__)
0227
0228 #define DECLARE_GEANT4_PHYSICS_LIST(name) typedef DS::Geant4UserPhysicsList< name > G4_physics_list_##name; \
0229 DD4HEP_PLUGINSVC_FACTORY(G4_physics_list_##name,name,G4VUserPhysicsList*(DS::Geant4PhysicsListActionSequence*,int),__LINE__)
0230
0231 #define DECLARE_GEANT4_SETUP(name,func) DD4HEP_OPEN_PLUGIN(dd4hep,xml_g4_setup_##name) { \
0232 template <> long Geant4SetupAction< xml_g4_setup_##name >:: \
0233 create(dd4hep::Detector& l,const _ns::GH& e, const _ns::STRM& a) {return func(l,e,a);} \
0234 DD4HEP_PLUGINSVC_FACTORY(xml_g4_setup_##name,name##_Geant4_action,long(dd4hep::Detector*,const _ns::GH*,const _ns::STRM*),__LINE__) }
0235
0236
0237 #define DECLARE_GEANT4_EVENT_READER(name) DD4HEP_PLUGINSVC_FACTORY(name,name,_ns::RDR*(std::string),__LINE__)
0238
0239
0240 #define DECLARE_GEANT4_EVENT_READER_NS(name_space,name) typedef name_space::name __##name##__; \
0241 DD4HEP_PLUGINSVC_FACTORY(__##name##__,name,_ns::RDR*(std::string),__LINE__)
0242
0243 #endif