File indexing completed on 2025-01-30 09:17:26
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef DDG4_GEANT4GFLASHSHOWERMODEL_H
0014 #define DDG4_GEANT4GFLASHSHOWERMODEL_H
0015
0016
0017 #include <DDG4/Geant4FastSimShowerModel.h>
0018
0019
0020 class GVFlashShowerParameterisation;
0021 class G4ParticleDefinition;
0022 class GFlashParticleBounds;
0023 class GFlashShowerModel;
0024 class GFlashHitMaker;
0025
0026
0027 #include <vector>
0028
0029
0030 namespace dd4hep {
0031
0032
0033 namespace sim {
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049 class Geant4GFlashShowerModel : public Geant4FastSimShowerModel {
0050 protected:
0051
0052 std::string m_paramName;
0053
0054 std::string m_material;
0055
0056 std::string m_material_2;
0057
0058 double m_parameter_1;
0059
0060 double m_parameter_2;
0061
0062
0063 int m_particleContainment { 1 };
0064
0065 double m_stepX0 { 0.1 };
0066
0067
0068 GVFlashShowerParameterisation* m_parametrization { nullptr };
0069
0070 GFlashParticleBounds* m_particleBounds { nullptr };
0071
0072 GFlashHitMaker* m_hitMaker { nullptr };
0073
0074 protected:
0075
0076 DDG4_DEFINE_ACTION_CONSTRUCTORS(Geant4GFlashShowerModel);
0077
0078 public:
0079
0080 Geant4GFlashShowerModel(Geant4Context* context, const std::string& nam);
0081
0082
0083 virtual ~Geant4GFlashShowerModel();
0084
0085
0086 void adoptShowerParametrization(Geant4Action* param);
0087
0088
0089 virtual void constructSensitives(Geant4DetectorConstructionContext* ctxt);
0090 };
0091 }
0092 }
0093 #endif
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110 #include <DD4hep/Detector.h>
0111 #include <DDG4/Geant4Action.h>
0112 #include <DDG4/Geant4Kernel.h>
0113 #include <DDG4/Geant4Mapping.h>
0114
0115
0116 #include <GVFlashShowerParameterisation.hh>
0117 #include <GFlashHomoShowerParameterisation.hh>
0118 #include <GFlashSamplingShowerParameterisation.hh>
0119 #include <GFlashParticleBounds.hh>
0120 #include <GFlashShowerModel.hh>
0121 #include <GFlashHitMaker.hh>
0122
0123
0124 #include <sstream>
0125
0126 using namespace dd4hep::sim;
0127
0128
0129 Geant4GFlashShowerModel::Geant4GFlashShowerModel(Geant4Context* ctxt, const std::string& nam)
0130 : Geant4FastSimShowerModel(ctxt, nam)
0131 {
0132 declareProperty("Parametrization", m_paramName);
0133 declareProperty("Material", m_material);
0134 declareProperty("Material_1", m_material);
0135 declareProperty("Material_2", m_material_2);
0136 declareProperty("Parameter_1", m_parameter_1);
0137 declareProperty("Parameter_2", m_parameter_2);
0138 declareProperty("CheckParticleContainment", m_particleContainment);
0139 this->m_applicablePartNames.emplace_back("e+");
0140 this->m_applicablePartNames.emplace_back("e-");
0141 }
0142
0143
0144 Geant4GFlashShowerModel::~Geant4GFlashShowerModel() {
0145 if ( this->m_parametrization ) {
0146 auto* a = dynamic_cast<Geant4Action*>(this->m_parametrization);
0147 if ( a ) detail::releasePtr(a);
0148 else detail::deletePtr(this->m_parametrization);
0149 }
0150 this->m_parametrization = nullptr;
0151 detail::deletePtr(m_particleBounds);
0152
0153 m_hitMaker = nullptr;
0154 }
0155
0156
0157 void Geant4GFlashShowerModel::adoptShowerParametrization(Geant4Action* action) {
0158 if ( this->m_parametrization ) {
0159 auto* a = dynamic_cast<Geant4Action*>(this->m_parametrization);
0160 this->m_parametrization = nullptr;
0161 detail::releasePtr(a);
0162 }
0163 if ( action ) {
0164 this->m_parametrization = dynamic_cast<GVFlashShowerParameterisation*>(action);
0165 if ( this->m_parametrization ) {
0166 action->addRef();
0167 return;
0168 }
0169 except("The supplied parametrization %s was found as Geant4Action, but is no "
0170 "GVFlashShowerParameterisation!", this->m_paramName.c_str());
0171 }
0172 }
0173
0174
0175 void Geant4GFlashShowerModel::constructSensitives(Geant4DetectorConstructionContext* ) {
0176 auto& kernel = this->context()->kernel();
0177 Geant4GeometryInfo& mapping = Geant4Mapping::instance().data();
0178 Region rg = kernel.detectorDescription().region(this->m_regionName);
0179 if ( !rg.isValid() ) {
0180 except("Failed to access the region %s from the detector description.", this->m_regionName.c_str());
0181 }
0182 auto region_iter = mapping.g4Regions.find(rg);
0183 if ( region_iter == mapping.g4Regions.end() ) {
0184 except("Failed to locate G4Region: %s from the Geant4 mapping.", this->m_regionName.c_str());
0185 }
0186 G4Region* region = (*region_iter).second;
0187
0188 std::stringstream logger;
0189 auto* shower_model = new GFlashShowerModel(this->name(), region);
0190 this->m_model = shower_model;
0191 logger << "Geant4 shower model initialized with parametrization: ";
0192 if ( !this->m_parametrization ) {
0193 if ( this->m_paramName.empty() ) {
0194 except("No proper parametrization name supplied in the properties: %s",this->m_paramName.c_str());
0195 }
0196 if ( this->m_paramName == "GFlashHomoShowerParameterisation" ) {
0197 G4Material* mat = this->getMaterial(m_material);
0198 this->m_parametrization = new GFlashHomoShowerParameterisation(mat, nullptr);
0199 logger << "GFlashHomoShowerParameterisation Material: " << mat->GetName();
0200 }
0201 else if ( this->m_paramName == "GFlashSamplingShowerParameterisation" ) {
0202 G4Material* mat1 = this->getMaterial(m_material);
0203 G4Material* mat2 = this->getMaterial(m_material_2);
0204 this->m_parametrization =
0205 new GFlashSamplingShowerParameterisation(mat1, mat2, m_parameter_1, m_parameter_2, nullptr);
0206 logger << "GFlashSamplingShowerParameterisation Materials: " << mat1->GetName()
0207 << " " << mat2->GetName() << " Params: " << m_parameter_1 << " " << m_parameter_2;
0208 }
0209 else {
0210 auto* action = kernel.globalAction(this->m_paramName, false);
0211 this->adoptShowerParametrization(action);
0212 if ( action ) logger << typeName(typeid(*action));
0213 }
0214 }
0215 else {
0216 logger << typeName(typeid(*this->m_parametrization));
0217 }
0218 if ( !this->m_parametrization ) {
0219 except("No proper parametrization supplied. Failed to construct shower model.");
0220 }
0221 this->m_hitMaker = new GFlashHitMaker();
0222 shower_model->SetHitMaker(*this->m_hitMaker);
0223 this->m_particleBounds = new GFlashParticleBounds();
0224 shower_model->SetParticleBounds(*this->m_particleBounds);
0225 shower_model->SetParameterisation(*this->m_parametrization);
0226
0227
0228 shower_model->SetStepInX0(this->m_stepX0);
0229 shower_model->SetFlagParamType(this->m_enable ? 1 : 0);
0230 shower_model->SetFlagParticleContainment(this->m_particleContainment);
0231
0232 for(const auto& prop : this->m_eMin) {
0233 G4ParticleDefinition* def = this->getParticleDefinition(prop.first);
0234 double val = dd4hep::_toDouble(prop.second) / CLHEP::GeV;
0235 this->m_particleBounds->SetMinEneToParametrise(*def, val);
0236 this->info("SetMinEneToParametrise [%-16s] = %8.4f GeV", prop.first.c_str(), val);
0237 }
0238 for(const auto& prop : this->m_eMax) {
0239 G4ParticleDefinition* def = this->getParticleDefinition(prop.first);
0240 double val = dd4hep::_toDouble(prop.second) / CLHEP::GeV;
0241 this->m_particleBounds->SetMaxEneToParametrise(*def, val);
0242 this->info("SetMaxEneToParametrise [%-16s] = %8.4f GeV", prop.first.c_str(), val);
0243 }
0244 for(const auto& prop : this->m_eKill) {
0245 G4ParticleDefinition* def = this->getParticleDefinition(prop.first);
0246 double val = dd4hep::_toDouble(prop.second) / CLHEP::GeV;
0247 this->m_particleBounds->SetEneToKill(*def, val);
0248 this->info("SetEneToKill [%-16s] = %8.4f GeV", prop.first.c_str(), val);
0249 }
0250
0251 this->addShowerModel(region);
0252 this->info(logger.str().c_str());
0253 }
0254
0255 #include <DDG4/Factories.h>
0256 DECLARE_GEANT4ACTION(Geant4GFlashShowerModel)