DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4P1ShowerModel.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 come direct from the Geant4 example:
17 // <geant4-source-dir>/examples/extended/parameterisations/Par01
18 //
19 // From the README:
20 // o Par01EMShowerModel which provides a crude
21 // parameterisation for e+/e-/gamma. This model
22 // is bound to the EM calorimeter.
23 //
24 // o Par01PionShowerModel: an even more crude
25 // parameterisation for pi+/pi-. This model
26 // is bound to a ghost volume.
27 //
28 //==========================================================================
29 
30 // Framework include files
32 #include <DDG4/Geant4FastSimSpot.h>
33 #include <DDG4/Geant4Random.h>
34 
35 // Geant4 include files
36 #include <G4Gamma.hh>
37 #include <G4SystemOfUnits.hh>
38 
39 // C/C++ include files
40 
41 
43 namespace dd4hep {
44 
46  namespace sim {
47 
53 
56  public:
58  std::string materialName { };
59  G4Material* material { nullptr };
60  double criticalEnergyRef { 800*MeV };
61  double criticalEnergy { 800*MeV };
62  };
63 
65  template <>
67  declareProperty("Material", this->locals.materialName);
68  declareProperty("CriticalEnergy", this->locals.criticalEnergyRef);
69  this->m_applicablePartNames.emplace_back("e+");
70  this->m_applicablePartNames.emplace_back("e-");
71  }
72 
74  template <>
76  locals.material = this->getMaterial(this->locals.materialName);
77  locals.criticalEnergy = this->locals.criticalEnergyRef * (this->locals.material->GetZ() + 1.2);
79  }
80 
82  template <>
83  void Geant4FSShowerModel<par01_em_model>::modelShower(const G4FastTrack& track, G4FastStep& step) {
84  auto* primary = track.GetPrimaryTrack();
85  // Kill the parameterised particle:
86  this->killParticle(step, primary->GetKineticEnergy(), 0e0);
87  //-----------------------------------------------------
88  // split into "energy spots" energy according to the shower shape:
89  // See Par01EMShowerModel::Explode(track);
90  //-----------------------------------------------------
91  G4FastHit hit;
92  Geant4FastSimSpot spot(&hit, &track);
93 
94  // Reduced quantities: -- critical energy in material:
95  G4double Ec = this->locals.criticalEnergy;
96  G4double Energy = spot.kineticEnergy();
97  G4double y = Energy/Ec;
98  // compute value of parameter "a" of longitudinal profile, b assumed = 0.5
99  G4double b = 0.5, C = -0.5;
100  if (spot.trackDefinition() == G4Gamma::GammaDefinition()) C = 0.5;
101  G4double tmax = 1.0 * (std::log(y) + C);
102  G4double a = 1.0 + b*tmax;
103  // radiation length
104  G4double X0 = this->locals.material->GetRadlen();
105  // Moliere radius:
106  G4double Es = 21*MeV;
107  G4double Rm = X0*Es/Ec;
108  // We shoot 100 spots of energy:
109  G4int nSpots = 100;
110  G4double deposit = Energy/double(nSpots);
111 
112  // axis of the shower, in global reference frame:
113  G4ThreeVector xShower, yShower, zShower;
114  zShower = spot.particleLocalDirection();
115  xShower = zShower.orthogonal();
116  yShower = zShower.cross(xShower);
117  // starting point of the shower:
119  G4ThreeVector sShower = spot.particleLocalPosition();
120  for (int i = 0; i < nSpots; i++) {
121  // Longitudinal profile: -- shoot z according to Gamma distribution:
122  G4double bt = rndm->gamma(a, 1e0);
123  G4double t = bt/b; // t : reduced quantity = z/X0:
124  G4double z = t*X0;
125  // transverse profile: we set 90% of energy in one Rm, the rest between 1 and 3.5 Rm:
126  G4double xr = rndm->uniform(0e0,1e0);
127  G4double phi = rndm->uniform(0e0,twopi);
128  G4double r;
129  if (xr < 0.9) r = xr/0.9*Rm;
130  else r = ((xr - 0.9)/0.1*2.5 + 1.0)*Rm;
131  // build the position:
132  G4ThreeVector position = sShower + z*zShower + r*std::cos(phi)*xShower + r*std::sin(phi)*yShower;
134  hit.SetPosition(position);
135  hit.SetEnergy(deposit);
136  this->locals.hitMaker.make(hit, track);
137  }
138  }
139 
145 
148  public:
150  };
151 
153  template <>
155  this->m_applicablePartNames.emplace_back("pi+");
156  this->m_applicablePartNames.emplace_back("pi-");
157  }
158 
160  template <>
161  bool Geant4FSShowerModel<par01_pion_model>::check_trigger(const G4FastTrack& /* track */) {
162  return true;
163  }
164 
166  template <>
167  void Geant4FSShowerModel<par01_pion_model>::modelShower(const G4FastTrack& track, G4FastStep& step) {
168  auto* primary = track.GetPrimaryTrack();
169  // Kill the parameterised particle:
170  this->killParticle(step, primary->GetKineticEnergy(), 0e0);
171 
172  //-----------------------------------------------------
173  // Non-physical shower generated: exp along z and transverse.
174  //-----------------------------------------------------
175  // center of the shower, we put at the middle of the ghost:
176  G4ThreeVector pos = track.GetPrimaryTrackLocalPosition();
177  G4ThreeVector dir = track.GetPrimaryTrackLocalDirection();
178  G4double distOut = track.GetEnvelopeSolid()->DistanceToOut(pos, dir);
179  G4ThreeVector showerCenter = pos + (distOut/2.)*dir;
180 
181  showerCenter = track.GetInverseAffineTransformation()->TransformPoint(showerCenter);
182 
183  // axis of the shower, in global reference frame:
184  G4ThreeVector zShower = primary->GetMomentumDirection();
185  G4ThreeVector xShower = zShower.orthogonal();
186  G4ThreeVector yShower = zShower.cross(xShower);
187 
188  // shoot the energy spots:
189  G4double Energy = primary->GetKineticEnergy();
190  G4int nSpot = 50;
191  G4double deposit = Energy/double(nSpot);
193  for (int i = 0; i < nSpot; i++) {
194  double z = rndm->gauss(0, 20*cm);
195  double r = rndm->gauss(0, 10*cm);
196  double phi = rndm->uniform(0e0, twopi);
197  G4ThreeVector position = showerCenter + z*zShower + r*std::cos(phi)*xShower + r*std::sin(phi)*yShower;
199  G4FastHit hit(position, deposit);
200  this->locals.hitMaker.make(hit, track);
201  }
202  }
203 
206  }
207 }
208 
209 #include <DDG4/Factories.h>
dd4hep::sim::par01_pion_model::hitMaker
G4FastSimHitMaker hitMaker
Definition: Geant4P1ShowerModel.cpp:149
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::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::par01_em_model::material
G4Material * material
Definition: Geant4P1ShowerModel.cpp:59
dd4hep::sim::Geant4Random::uniform
double uniform(double x1=1)
Create uniformly disributed random numbers in the interval ]0,x1].
Definition: Geant4Random.cpp:286
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::par01_em_model::criticalEnergy
double criticalEnergy
Definition: Geant4P1ShowerModel.cpp:61
dd4hep::sim::par01_em_model::hitMaker
G4FastSimHitMaker hitMaker
Definition: Geant4P1ShowerModel.cpp:57
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::par01_em_model
Configuration structure for the fast simulation shower model Geant4FSShowerModel<par01_em_model>
Definition: Geant4P1ShowerModel.cpp:55
dd4hep::sim::par01_em_model::materialName
std::string materialName
Definition: Geant4P1ShowerModel.cpp:58
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
dd4hep::sim::par01_pion_model
Configuration structure for the fast simulation shower model Geant4FSShowerModel<par01_pion_model>
Definition: Geant4P1ShowerModel.cpp:147
dd4hep::sim::Geant4FastSimSpot::particleLocalDirection
G4ThreeVector particleLocalDirection() const
Particle's local direction in the region's envelope solid.
Definition: Geant4FastSimSpot.h:99
Geant4Random.h
G4FastSimHitMaker
Definition: Geant4FastSimShowerModel.inl.h:94
dd4hep::sim::Geant4Random::gamma
double gamma(double k, double lambda)
Create gamma distributed random numbers.
Definition: Geant4Random.cpp:340
dd4hep::sim::Geant4FSShowerModel::check_trigger
virtual bool check_trigger(const G4FastTrack &track) override
User callback to determine if the shower creation should be triggered.
Definition: Geant4FastSimShowerModel.inl.h:77
dd4hep::sim::par01_em_model::criticalEnergyRef
double criticalEnergyRef
Definition: Geant4P1ShowerModel.cpp:60
dd4hep::sim::Geant4FSShowerModel::constructSensitives
virtual void constructSensitives(Geant4DetectorConstructionContext *ctxt) override
Sensitive detector construction callback. Called at "ConstructSDandField()".
Definition: Geant4FastSimShowerModel.inl.h:65
G4FastHit::SetEnergy
void SetEnergy(const G4double &aEnergy)
Set energy.
Definition: Geant4FastSimSpot.h:37
dd4hep::sim::Geant4Random
Mini interface to THE random generator of the application.
Definition: Geant4Random.h:59
dd4hep::sim::Geant4FastSimSpot::particleLocalPosition
G4ThreeVector particleLocalPosition() const
Particle's local position in the region's envelope solid.
Definition: Geant4FastSimSpot.h:105
Factories.h
dd4hep::sim::Geant4Random::gauss
double gauss(double mean=0, double sigma=1)
Create gaussian distributed random numbers.
Definition: Geant4Random.cpp:304
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::Geant4Par01PionShowerModel
Geant4FSShowerModel< par01_pion_model > Geant4Par01PionShowerModel
Definition: Geant4P1ShowerModel.cpp:205
dd4hep::sim::Geant4Par01EMShowerModel
Geant4FSShowerModel< par01_em_model > Geant4Par01EMShowerModel
Definition: Geant4P1ShowerModel.cpp:204
dd4hep::sim::Geant4FastSimSpot::trackDefinition
const G4ParticleDefinition * trackDefinition() const
Primary track particle definition.
Definition: Geant4FastSimSpot.h:96