DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4CaloSmearShowerModel.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 //
14 // Please note:
15 //
16 // These shower parametrizations is a generalized form of the Geant4 example:
17 // <geant4-source-dir>/examples/extended/parameterisations/Par02
18 //
19 //==========================================================================
20 
21 // Framework include files
23 #include <DDG4/Geant4FastSimSpot.h>
24 #include <DDG4/Geant4Random.h>
25 
26 // Geant4 include files
27 #include <G4SystemOfUnits.hh>
28 #include <G4FastStep.hh>
29 
31 namespace dd4hep {
32 
34  namespace sim {
35 
41 
44  public:
46  double StocasticEnergyResolution { -1e0 };
47  double ConstantEnergyResolution { -1e0 };
48  double NoiseEnergyResolution { -1e0 };
49 
50  double resolution(double momentum) const {
51  double res = -1e0;
52  double mom = momentum/CLHEP::GeV;
53  if ( this->StocasticEnergyResolution > 0 &&
54  this->ConstantEnergyResolution > 0 &&
55  this->NoiseEnergyResolution > 0 ) {
56  res = std::sqrt(std::pow( this->StocasticEnergyResolution / std::sqrt( mom ), 2 ) + // stochastic
57  std::pow( this->ConstantEnergyResolution, 2 ) + // constant
58  std::pow( this->NoiseEnergyResolution / mom, 2 ) ); // noise
59  }
60  else if ( this->StocasticEnergyResolution > 0 &&
61  this->ConstantEnergyResolution > 0 ) {
62  res = std::sqrt(std::pow( this->StocasticEnergyResolution / std::sqrt( mom ), 2 ) + // stochastic
63  std::pow( this->ConstantEnergyResolution, 2 ) ); // constant
64  }
65  else if ( this->StocasticEnergyResolution > 0 ) {
66  res = this->StocasticEnergyResolution / std::sqrt( mom ); // stochastic
67  }
68  else if ( this->ConstantEnergyResolution > 0 ) {
69  res = this->ConstantEnergyResolution; // constant
70  }
71  return res;
72  }
73 
74  double smearEnergy(double mom) const {
75  double resolution = this->resolution(mom);
76  double smeared = mom;
77  if ( resolution > 0e0 ) {
78  for( smeared = -1e0; smeared < 0e0; ) { // Ensure that the resulting value is not negative
79  smeared = mom * Geant4Random::instance()->gauss(1e0, resolution);
80  }
81  }
82  return smeared;
83  }
84  };
85 
87  template <>
89  declareProperty("StocasticResolution", locals.StocasticEnergyResolution );
90  declareProperty("ConstantResolution", locals.ConstantEnergyResolution );
91  declareProperty("NoiseResolution", locals.NoiseEnergyResolution );
92  }
93 
95  template <>
98  }
99 
101  template <>
102  void Geant4FSShowerModel<calo_smear_model>::modelShower(const G4FastTrack& track, G4FastStep& step) {
103  auto* primary = track.GetPrimaryTrack();
104  // Kill the parameterised particle:
105  this->killParticle(step, primary->GetKineticEnergy(), 0e0);
106  //-----------------------------------------------------
107  G4FastHit hit;
108  Geant4FastSimSpot spot(&hit, &track);
109  G4ThreeVector position = spot.trackPosition();
110  double deposit = spot.kineticEnergy();
111 
112  hit.SetPosition(spot.trackPosition());
113  // Consider only primary tracks and smear according to the parametrized resolution
114  // ELSE: simply set the value of the (initial) energy of the particle is deposited in the step
115  if ( !spot.primary->GetParentID() ) {
116  deposit = locals.smearEnergy(deposit);
117  }
118  hit.SetEnergy(deposit);
119  step.ProposeTotalEnergyDeposited(deposit);
120  this->locals.hitMaker.make(hit, track);
121  }
122 
124  }
125 }
126 
127 #include <DDG4/Factories.h>
129 
dd4hep::sim::Geant4FSShowerModel::modelShower
virtual void modelShower(const G4FastTrack &track, G4FastStep &step) override
User callback to model the particle/energy shower.
Definition: Geant4FastSimShowerModel.inl.h:83
dd4hep::sim::calo_smear_model::hitMaker
G4FastSimHitMaker hitMaker
Definition: Geant4CaloSmearShowerModel.cpp:45
dd4hep::sim::Geant4Random::instance
static Geant4Random * instance(bool throw_exception=true)
Access the main Geant4 random generator instance. Must be created before used!
Definition: Geant4Random.cpp:113
dd4hep::sim::Geant4FastSimSpot::trackPosition
G4ThreeVector trackPosition() const
Primary track position.
Definition: Geant4FastSimSpot.h:90
dd4hep::sim::Geant4FastSimSpot::kineticEnergy
double kineticEnergy() const
Primary track kinetic energy.
Definition: Geant4FastSimSpot.h:94
G4FastHit::SetPosition
void SetPosition(const G4ThreeVector &aPosition)
Set position.
Definition: Geant4FastSimSpot.h:41
dd4hep::sim::calo_smear_model::StocasticEnergyResolution
double StocasticEnergyResolution
Definition: Geant4CaloSmearShowerModel.cpp:46
Geant4FastSimSpot.h
dd4hep::sim::Geant4FSShowerModel::initialize
void initialize()
Declare optional properties from embedded structure.
Definition: Geant4FastSimShowerModel.inl.h:48
dd4hep::sim::Geant4FastSimSpot
Spot definition for fast simulation and GFlash.
Definition: Geant4FastSimSpot.h:71
dd4hep::sim::Geant4FastSimShowerModel::constructSensitives
virtual void constructSensitives(Geant4DetectorConstructionContext *ctxt) override
Sensitive detector construction callback. Called at "ConstructSDandField()".
Definition: Geant4FastSimShowerModel.cpp:184
G4FastHit
Definition: Geant4FastSimSpot.h:27
DECLARE_GEANT4ACTION_NS
#define DECLARE_GEANT4ACTION_NS(name_space, name)
Plugin defintion to create Geant4Action objects.
Definition: Factories.h:207
dd4hep::sim::Geant4DetectorConstructionContext
Geant4 detector construction context definition.
Definition: Geant4DetectorConstruction.h:61
dd4hep::sim::Geant4FSShowerModel
Geant4 wrapper for the Geant4 fast simulation shower model.
Definition: Geant4FastSimShowerModel.h:130
Geant4Random.h
dd4hep::sim::Geant4FastSimSpot::primary
const G4Track * primary
Definition: Geant4FastSimSpot.h:120
G4FastSimHitMaker
Definition: Geant4FastSimShowerModel.inl.h:94
dd4hep::sim::Geant4FSShowerModel::constructSensitives
virtual void constructSensitives(Geant4DetectorConstructionContext *ctxt) override
Sensitive detector construction callback. Called at "ConstructSDandField()".
Definition: Geant4FastSimShowerModel.inl.h:65
dd4hep::sim::calo_smear_model::ConstantEnergyResolution
double ConstantEnergyResolution
Definition: Geant4CaloSmearShowerModel.cpp:47
G4FastHit::SetEnergy
void SetEnergy(const G4double &aEnergy)
Set energy.
Definition: Geant4FastSimSpot.h:37
dd4hep::sim::Geant4CaloSmearShowerModel
Geant4FSShowerModel< calo_smear_model > Geant4CaloSmearShowerModel
Definition: Geant4CaloSmearShowerModel.cpp:123
dd4hep::sim::calo_smear_model::resolution
double resolution(double momentum) const
Definition: Geant4CaloSmearShowerModel.cpp:50
Factories.h
dd4hep::sim::Geant4Random::gauss
double gauss(double mean=0, double sigma=1)
Create gaussian distributed random numbers.
Definition: Geant4Random.cpp:304
dd4hep::sim::calo_smear_model::smearEnergy
double smearEnergy(double mom) const
Definition: Geant4CaloSmearShowerModel.cpp:74
Geant4FastSimShowerModel.inl.h
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: Geant4Output2EDM4hep.cpp:49
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::sim::calo_smear_model
Configuration structure for the fast simulation shower model Geant4FSShowerModel<par02_em_model>
Definition: Geant4CaloSmearShowerModel.cpp:43
dd4hep::sim::calo_smear_model::NoiseEnergyResolution
double NoiseEnergyResolution
Definition: Geant4CaloSmearShowerModel.cpp:48