Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:17:26

0001 //==========================================================================
0002 //  AIDA Detector description implementation
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 #ifndef DDG4_GEANT4GFLASHSHOWERMODEL_H
0014 #define DDG4_GEANT4GFLASHSHOWERMODEL_H
0015 
0016 // Framework include files
0017 #include <DDG4/Geant4FastSimShowerModel.h>
0018 
0019 // Geant4 include files
0020 class GVFlashShowerParameterisation;
0021 class G4ParticleDefinition;
0022 class GFlashParticleBounds;
0023 class GFlashShowerModel;
0024 class GFlashHitMaker;
0025 
0026 // C/C++ include files
0027 #include <vector>
0028 
0029 /// Namespace for the AIDA detector description toolkit
0030 namespace dd4hep  {
0031 
0032   /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit
0033   namespace sim  {
0034     
0035     /// Geant4 wrapper for the GFlash shower model
0036     /**
0037      *  Geant4 wrapper for the GFlash shower model
0038      *  See e.g. the G4 example examples/extended/parameterisations/gflash/gflash3
0039      *  for details.
0040      *
0041      *  The parametrization is passed as a Geant4Action to be able to configure it,
0042      *  which is polymorph the GVFlashShowerParameterisation.
0043      *
0044      *  \author  M.Frank
0045      *
0046      *  \version 1.0
0047      *  \ingroup DD4HEP_SIMULATION
0048      */
0049     class Geant4GFlashShowerModel : public Geant4FastSimShowerModel   {
0050     protected:
0051       /// Property: Name of the Geant4Action implementing the parametrization
0052       std::string m_paramName;
0053       /// Property: Material name for GFlashHomoShowerParameterisation
0054       std::string m_material;
0055       /// Property: Material 2 name for GFlashSamplingShowerParameterisation
0056       std::string m_material_2;
0057       /// Property: Parameter 1 name for GFlashSamplingShowerParameterisation
0058       double      m_parameter_1;
0059       /// Property: Parameter 2 name for GFlashSamplingShowerParameterisation
0060       double      m_parameter_2;
0061 
0062       /// Property: Defines if particle containment is checked
0063       int         m_particleContainment { 1 };
0064       /// Property: Defines step lenght
0065       double      m_stepX0              { 0.1 };
0066 
0067       /// Reference to the parametrization
0068       GVFlashShowerParameterisation* m_parametrization { nullptr };
0069       /// Reference to the particle bounds object
0070       GFlashParticleBounds*          m_particleBounds  { nullptr };
0071       /// Reference to the hit maker
0072       GFlashHitMaker*                m_hitMaker        { nullptr };
0073 
0074     protected:
0075       /// Define standard assignments and constructors
0076       DDG4_DEFINE_ACTION_CONSTRUCTORS(Geant4GFlashShowerModel);
0077 
0078     public:
0079       /// Standard constructor
0080       Geant4GFlashShowerModel(Geant4Context* context, const std::string& nam);
0081 
0082       /// Default destructor
0083       virtual ~Geant4GFlashShowerModel();
0084 
0085       /// Adopt shower parametrization object
0086       void adoptShowerParametrization(Geant4Action* param);
0087 
0088       /// Sensitive detector construction callback. Called at "ConstructSDandField()"
0089       virtual void constructSensitives(Geant4DetectorConstructionContext* ctxt);
0090     };
0091   }     /* End namespace sim   */
0092 }       /* End namespace dd4hep */
0093 #endif // DDG4_GEANT4GFLASHSHOWERMODEL_H
0094 
0095 //==========================================================================
0096 //  AIDA Detector description implementation
0097 //--------------------------------------------------------------------------
0098 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0099 // All rights reserved.
0100 //
0101 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0102 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0103 //
0104 // Author     : M.Frank
0105 //
0106 //==========================================================================
0107 
0108 // Framework include files
0109 // #include <DDG4/Geant4GFlashShowerModel.h>
0110 #include <DD4hep/Detector.h>
0111 #include <DDG4/Geant4Action.h>
0112 #include <DDG4/Geant4Kernel.h>
0113 #include <DDG4/Geant4Mapping.h>
0114 
0115 // Geant4 include files
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 // C/C++ include files
0124 #include <sstream>
0125 
0126 using namespace dd4hep::sim;
0127 
0128 /// Standard constructor
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 /// Default destructor
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   //detail::deletePtr(m_hitMaker);
0153   m_hitMaker = nullptr;
0154 }
0155 
0156 /// Adopt shower parametrization object
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 /// Sensitive detector construction callback. Called at "ConstructSDandField()"
0175 void Geant4GFlashShowerModel::constructSensitives(Geant4DetectorConstructionContext* /* ctxt */)    {
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   /// Now configure the shower model:
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)