DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4GFlashShowerModel.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 #ifndef DDG4_GEANT4GFLASHSHOWERMODEL_H
14 #define DDG4_GEANT4GFLASHSHOWERMODEL_H
15 
16 // Framework include files
18 
19 // Geant4 include files
20 class GVFlashShowerParameterisation;
21 class G4ParticleDefinition;
22 class GFlashParticleBounds;
23 class GFlashShowerModel;
24 class GFlashHitMaker;
25 
26 // C/C++ include files
27 #include <vector>
28 
30 namespace dd4hep {
31 
33  namespace sim {
34 
36 
50  protected:
52  std::string m_paramName;
54  std::string m_material;
56  std::string m_material_2;
58  double m_parameter_1;
60  double m_parameter_2;
61 
65  double m_stepX0 { 0.1 };
66 
68  GVFlashShowerParameterisation* m_parametrization { nullptr };
70  GFlashParticleBounds* m_particleBounds { nullptr };
72  GFlashHitMaker* m_hitMaker { nullptr };
73 
74  protected:
77 
78  public:
80  Geant4GFlashShowerModel(Geant4Context* context, const std::string& nam);
81 
83  virtual ~Geant4GFlashShowerModel();
84 
87 
90  };
91  } /* End namespace sim */
92 } /* End namespace dd4hep */
93 #endif // DDG4_GEANT4GFLASHSHOWERMODEL_H
94 
95 //==========================================================================
96 // AIDA Detector description implementation
97 //--------------------------------------------------------------------------
98 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
99 // All rights reserved.
100 //
101 // For the licensing terms see $DD4hepINSTALL/LICENSE.
102 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
103 //
104 // Author : M.Frank
105 //
106 //==========================================================================
107 
108 // Framework include files
109 // #include <DDG4/Geant4GFlashShowerModel.h>
110 #include <DD4hep/Detector.h>
111 #include <DDG4/Geant4Action.h>
112 #include <DDG4/Geant4Kernel.h>
113 #include <DDG4/Geant4Mapping.h>
114 
115 // Geant4 include files
116 #include <GVFlashShowerParameterisation.hh>
117 #include <GFlashHomoShowerParameterisation.hh>
118 #include <GFlashSamplingShowerParameterisation.hh>
119 #include <GFlashParticleBounds.hh>
120 #include <GFlashShowerModel.hh>
121 #include <GFlashHitMaker.hh>
122 
123 // C/C++ include files
124 #include <sstream>
125 
126 using namespace dd4hep::sim;
127 
130  : Geant4FastSimShowerModel(ctxt, nam)
131 {
132  declareProperty("Parametrization", m_paramName);
133  declareProperty("Material", m_material);
134  declareProperty("Material_1", m_material);
135  declareProperty("Material_2", m_material_2);
136  declareProperty("Parameter_1", m_parameter_1);
137  declareProperty("Parameter_2", m_parameter_2);
138  declareProperty("CheckParticleContainment", m_particleContainment);
139  this->m_applicablePartNames.emplace_back("e+");
140  this->m_applicablePartNames.emplace_back("e-");
141 }
142 
145  if ( this->m_parametrization ) {
146  auto* a = dynamic_cast<Geant4Action*>(this->m_parametrization);
147  if ( a ) detail::releasePtr(a);
148  else detail::deletePtr(this->m_parametrization);
149  }
150  this->m_parametrization = nullptr;
151  detail::deletePtr(m_particleBounds);
152  //detail::deletePtr(m_hitMaker);
153  m_hitMaker = nullptr;
154 }
155 
158  if ( this->m_parametrization ) {
159  auto* a = dynamic_cast<Geant4Action*>(this->m_parametrization);
160  this->m_parametrization = nullptr;
161  detail::releasePtr(a);
162  }
163  if ( action ) {
164  this->m_parametrization = dynamic_cast<GVFlashShowerParameterisation*>(action);
165  if ( this->m_parametrization ) {
166  action->addRef();
167  return;
168  }
169  except("The supplied parametrization %s was found as Geant4Action, but is no "
170  "GVFlashShowerParameterisation!", this->m_paramName.c_str());
171  }
172 }
173 
176  auto& kernel = this->context()->kernel();
178  Region rg = kernel.detectorDescription().region(this->m_regionName);
179  if ( !rg.isValid() ) {
180  except("Failed to access the region %s from the detector description.", this->m_regionName.c_str());
181  }
182  auto region_iter = mapping.g4Regions.find(rg);
183  if ( region_iter == mapping.g4Regions.end() ) {
184  except("Failed to locate G4Region: %s from the Geant4 mapping.", this->m_regionName.c_str());
185  }
186  G4Region* region = (*region_iter).second;
187 
188  std::stringstream logger;
189  auto* shower_model = new GFlashShowerModel(this->name(), region);
190  this->m_model = shower_model;
191  logger << "Geant4 shower model initialized with parametrization: ";
192  if ( !this->m_parametrization ) {
193  if ( this->m_paramName.empty() ) {
194  except("No proper parametrization name supplied in the properties: %s",this->m_paramName.c_str());
195  }
196  if ( this->m_paramName == "GFlashHomoShowerParameterisation" ) {
197  G4Material* mat = this->getMaterial(m_material);
198  this->m_parametrization = new GFlashHomoShowerParameterisation(mat, nullptr);
199  logger << "GFlashHomoShowerParameterisation Material: " << mat->GetName();
200  }
201  else if ( this->m_paramName == "GFlashSamplingShowerParameterisation" ) {
202  G4Material* mat1 = this->getMaterial(m_material);
203  G4Material* mat2 = this->getMaterial(m_material_2);
204  this->m_parametrization =
205  new GFlashSamplingShowerParameterisation(mat1, mat2, m_parameter_1, m_parameter_2, nullptr);
206  logger << "GFlashSamplingShowerParameterisation Materials: " << mat1->GetName()
207  << " " << mat2->GetName() << " Params: " << m_parameter_1 << " " << m_parameter_2;
208  }
209  else {
210  auto* action = kernel.globalAction(this->m_paramName, false);
211  this->adoptShowerParametrization(action);
212  if ( action ) logger << typeName(typeid(*action));
213  }
214  }
215  else {
216  logger << typeName(typeid(*this->m_parametrization));
217  }
218  if ( !this->m_parametrization ) {
219  except("No proper parametrization supplied. Failed to construct shower model.");
220  }
221  this->m_hitMaker = new GFlashHitMaker();
222  shower_model->SetHitMaker(*this->m_hitMaker);
223  this->m_particleBounds = new GFlashParticleBounds();
224  shower_model->SetParticleBounds(*this->m_particleBounds);
225  shower_model->SetParameterisation(*this->m_parametrization);
226 
228  shower_model->SetStepInX0(this->m_stepX0);
229  shower_model->SetFlagParamType(this->m_enable ? 1 : 0);
230  shower_model->SetFlagParticleContainment(this->m_particleContainment);
231 
232  for(const auto& prop : this->m_eMin) {
233  G4ParticleDefinition* def = this->getParticleDefinition(prop.first);
234  double val = dd4hep::_toDouble(prop.second) / CLHEP::GeV;
235  this->m_particleBounds->SetMinEneToParametrise(*def, val);
236  this->info("SetMinEneToParametrise [%-16s] = %8.4f GeV", prop.first.c_str(), val);
237  }
238  for(const auto& prop : this->m_eMax) {
239  G4ParticleDefinition* def = this->getParticleDefinition(prop.first);
240  double val = dd4hep::_toDouble(prop.second) / CLHEP::GeV;
241  this->m_particleBounds->SetMaxEneToParametrise(*def, val);
242  this->info("SetMaxEneToParametrise [%-16s] = %8.4f GeV", prop.first.c_str(), val);
243  }
244  for(const auto& prop : this->m_eKill) {
245  G4ParticleDefinition* def = this->getParticleDefinition(prop.first);
246  double val = dd4hep::_toDouble(prop.second) / CLHEP::GeV;
247  this->m_particleBounds->SetEneToKill(*def, val);
248  this->info("SetEneToKill [%-16s] = %8.4f GeV", prop.first.c_str(), val);
249  }
250 
251  this->addShowerModel(region);
252  this->info(logger.str().c_str());
253 }
254 
255 #include <DDG4/Factories.h>
dd4hep::sim::Geant4FastSimShowerModel::m_eMin
ParticleConfig m_eMin
Property: Set minimum kinetic energy to trigger parametrisation.
Definition: Geant4FastSimShowerModel.h:66
dd4hep::sim::Geant4FastSimShowerModel::m_applicablePartNames
std::vector< std::string > m_applicablePartNames
Property: Particle names for which this parametrization is applicable.
Definition: Geant4FastSimShowerModel.h:60
dd4hep::sim::Geant4GFlashShowerModel::m_parametrization
GVFlashShowerParameterisation * m_parametrization
Reference to the parametrization.
Definition: Geant4GFlashShowerModel.cpp:68
Geant4Mapping.h
Detector.h
dd4hep::sim::Geant4Mapping::data
Geant4GeometryInfo & data() const
Access to the data pointer.
Definition: Geant4Mapping.h:58
dd4hep::sim::Geant4GFlashShowerModel::m_particleContainment
int m_particleContainment
Property: Defines if particle containment is checked.
Definition: Geant4GFlashShowerModel.cpp:63
Gaudi::PluginService::v1::Details::logger
GAUDIPS_API Logger & logger()
Return the current logger instance.
Definition: PluginServiceV1.cpp:326
dd4hep::Handle::isValid
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:128
dd4hep::sim::Geant4Mapping::instance
static Geant4Mapping & instance()
Possibility to define a singleton instance.
Definition: Geant4Mapping.cpp:35
DECLARE_GEANT4ACTION
#define DECLARE_GEANT4ACTION(name)
Plugin defintion to create Geant4Action objects.
Definition: Factories.h:210
dd4hep::sim::Geant4GFlashShowerModel::m_material
std::string m_material
Property: Material name for GFlashHomoShowerParameterisation.
Definition: Geant4GFlashShowerModel.cpp:54
dd4hep::sim::Geant4Action::info
void info(const char *fmt,...) const
Support of info messages.
Definition: Geant4Action.cpp:215
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::Geant4GFlashShowerModel::m_particleBounds
GFlashParticleBounds * m_particleBounds
Reference to the particle bounds object.
Definition: Geant4GFlashShowerModel.cpp:70
dd4hep::sim::Geant4GFlashShowerModel::DDG4_DEFINE_ACTION_CONSTRUCTORS
DDG4_DEFINE_ACTION_CONSTRUCTORS(Geant4GFlashShowerModel)
Define standard assignments and constructors.
dd4hep::sim::Geant4GFlashShowerModel::adoptShowerParametrization
void adoptShowerParametrization(Geant4Action *param)
Adopt shower parametrization object.
Definition: Geant4GFlashShowerModel.cpp:157
dd4hep::sim::Geant4GFlashShowerModel::constructSensitives
virtual void constructSensitives(Geant4DetectorConstructionContext *ctxt)
Sensitive detector construction callback. Called at "ConstructSDandField()".
Definition: Geant4GFlashShowerModel.cpp:175
dd4hep::sim::Geant4Action::declareProperty
Geant4Action & declareProperty(const std::string &nam, T &val)
Declare property.
Definition: Geant4Action.h:366
dd4hep::sim::Geant4GFlashShowerModel::Geant4GFlashShowerModel
Geant4GFlashShowerModel(Geant4Context *context, const std::string &nam)
Standard constructor.
Definition: Geant4GFlashShowerModel.cpp:129
dd4hep::sim::Geant4FastSimShowerModel::m_regionName
std::string m_regionName
Property: Region name to which this parametrization should be applied.
Definition: Geant4FastSimShowerModel.h:58
dd4hep::Region
Handle class describing a region as used in simulation.
Definition: Objects.h:462
dd4hep::sim::Geant4Action
Default base class for all Geant 4 actions and derivates thereof.
Definition: Geant4Action.h:113
dd4hep::sim::Geant4GFlashShowerModel::m_parameter_1
double m_parameter_1
Property: Parameter 1 name for GFlashSamplingShowerParameterisation.
Definition: Geant4GFlashShowerModel.cpp:58
dd4hep::sim::Geant4Action::name
const std::string & name() const
Access name of the action.
Definition: Geant4Action.h:280
dd4hep::sim::Geant4FastSimShowerModel::m_eMax
ParticleConfig m_eMax
Property: Set maximum kinetic energy to trigger parametrisation.
Definition: Geant4FastSimShowerModel.h:68
dd4hep::sim::Geant4FastSimShowerModel::getParticleDefinition
G4ParticleDefinition * getParticleDefinition(const std::string &name) const
Access particle definition from string.
Definition: Geant4FastSimShowerModel.cpp:111
dd4hep::sim::Geant4GFlashShowerModel::m_parameter_2
double m_parameter_2
Property: Parameter 2 name for GFlashSamplingShowerParameterisation.
Definition: Geant4GFlashShowerModel.cpp:60
Factories.h
dd4hep::sim::Geant4GFlashShowerModel::m_stepX0
double m_stepX0
Property: Defines step lenght.
Definition: Geant4GFlashShowerModel.cpp:65
dd4hep::_toDouble
double _toDouble(const std::string &value)
String conversions: string to double value.
Definition: Handle.cpp:116
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::Geant4Context::kernel
Geant4Kernel & kernel() const
Access to the kernel object.
Definition: Geant4Context.h:233
dd4hep::sim::Geant4GFlashShowerModel::m_material_2
std::string m_material_2
Property: Material 2 name for GFlashSamplingShowerParameterisation.
Definition: Geant4GFlashShowerModel.cpp:56
dd4hep::sim::Geant4GeometryInfo
Concreate class holding the relation information between geant4 objects and dd4hep objects.
Definition: Geant4GeometryInfo.h:93
dd4hep::sim::Geant4GFlashShowerModel::m_hitMaker
GFlashHitMaker * m_hitMaker
Reference to the hit maker.
Definition: Geant4GFlashShowerModel.cpp:72
dd4hep::sim::Geant4FastSimShowerModel::addShowerModel
void addShowerModel(G4Region *region)
Add shower model to region's fast simulation manager.
Definition: Geant4FastSimShowerModel.cpp:152
mapping
ConditionsMap & mapping
Definition: AlignmentsCalculator.cpp:82
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
Geant4FastSimShowerModel.h
dd4hep::sim::Geant4FastSimShowerModel::getMaterial
G4Material * getMaterial(const std::string &name) const
Get parametrization material.
Definition: Geant4FastSimShowerModel.cpp:119
Geant4Kernel.h
dd4hep::sim::Geant4FastSimShowerModel::m_model
G4VFastSimulationModel * m_model
Reference to the G4 fast simulation model.
Definition: Geant4FastSimShowerModel.h:79
dd4hep::sim::Geant4GFlashShowerModel::~Geant4GFlashShowerModel
virtual ~Geant4GFlashShowerModel()
Default destructor.
Definition: Geant4GFlashShowerModel.cpp:144
Geant4Action.h
dd4hep::sim::Geant4GFlashShowerModel
Geant4 wrapper for the GFlash shower model.
Definition: Geant4GFlashShowerModel.cpp:49
dd4hep::sim::Geant4FastSimShowerModel::m_eKill
ParticleConfig m_eKill
Property: Set maximum kinetic energy for particles to be killed.
Definition: Geant4FastSimShowerModel.h:70
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::Geant4GFlashShowerModel::m_paramName
std::string m_paramName
Property: Name of the Geant4Action implementing the parametrization.
Definition: Geant4GFlashShowerModel.cpp:52
dd4hep::sim::Geant4FastSimShowerModel
Geant4 wrapper for the Geant4 fast simulation shower model.
Definition: Geant4FastSimShowerModel.h:50
dd4hep::sim::Geant4FastSimShowerModel::m_enable
bool m_enable
Property: Parametrisation control: Enable/disable fast simulation.
Definition: Geant4FastSimShowerModel.h:62