DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4UserLimits.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 // Framework include files
15 #include <DDG4/Geant4UserLimits.h>
16 #include <DDG4/Geant4Particle.h>
17 #include <DD4hep/InstanceCount.h>
18 #include <DD4hep/DD4hepUnits.h>
19 #include <DD4hep/Primitives.h>
20 #include <DD4hep/Printout.h>
21 
22 // Geant 4 include files
23 #include <G4Track.hh>
24 #include <G4ParticleDefinition.hh>
25 #include <CLHEP/Units/SystemOfUnits.h>
26 
27 using namespace dd4hep::sim;
28 
29 namespace {
30  bool user_limit_debug = false;
31 }
32 
35  bool tmp = user_limit_debug;
36  user_limit_debug = value;
37  return tmp;
38 }
39 
41 double Geant4UserLimits::Handler::value(const G4Track& track) const {
42  auto* def = track.GetParticleDefinition();
43  if ( !particleLimits.empty() ) {
44  auto i = particleLimits.find(track.GetDefinition());
45  if ( i != particleLimits.end() ) {
46  if ( user_limit_debug ) {
47  dd4hep::printout(dd4hep::INFO,"Geant4UserLimits", "Apply explicit limit %f to track: %s",
48  def->GetParticleName().c_str());
49  }
50  return (*i).second;
51  }
52  }
53  if ( user_limit_debug ) {
54  dd4hep::printout(dd4hep::INFO,"Geant4UserLimits", "Apply default limit %f to track: %s",
55  def->GetParticleName().c_str());
56  }
57  return defaultValue;
58 }
59 
61 void Geant4UserLimits::Handler::set(const std::string& particles, double val) {
62  if ( particles == "*" || particles == ".(.*)" ) {
63  defaultValue = val;
64  return;
65  }
66  auto defs = Geant4ParticleHandle::g4DefinitionsRegEx(particles);
67  for( auto* d : defs ) {
68  particleLimits[d] = val;
69  }
70 }
71 
74  : G4UserLimits(limitset.name()), limits(limitset)
75 {
76  this->update(limitset);
78 }
79 
83 }
84 
87  const auto& lim = limitset.limits();
89  maxStepLength.defaultValue = fMaxStep;
90  maxTrackLength.defaultValue = fMaxTrack;
91  maxTime.defaultValue = fMaxTime;
92  minEKine.defaultValue = fMinEkine;
93  minRange.defaultValue = fMinRange;
95  for(const Limit& l : lim) {
96  if (l.name == "step_length_max")
97  maxStepLength.set(l.particles, l.value*CLHEP::mm/dd4hep::mm);
98  else if (l.name == "track_length_max")
99  maxTrackLength.set(l.particles, l.value*CLHEP::mm/dd4hep::mm);
100  else if (l.name == "time_max")
101  maxTime.set(l.particles, l.value*CLHEP::ns/dd4hep::ns);
102  else if (l.name == "ekin_min")
103  minEKine.set(l.particles, l.value*CLHEP::MeV/dd4hep::MeV);
104  else if (l.name == "range_min")
105  minRange.set(l.particles, l.value);
106  else
107  except("Geant4UserLimits", "Unknown Geant4 user limit: %s ", l.toString().c_str());
108  }
109 }
110 
112 void Geant4UserLimits::SetMaxAllowedStep(G4double /* ustepMax */) {
113  dd4hep::notImplemented(std::string(__PRETTY_FUNCTION__)+" May not be called!");
114 }
115 
116 void Geant4UserLimits::SetUserMaxTrackLength(G4double /* utrakMax */) {
117  dd4hep::notImplemented(std::string(__PRETTY_FUNCTION__)+" May not be called!");
118 }
119 
120 void Geant4UserLimits::SetUserMaxTime(G4double /* utimeMax */) {
121  dd4hep::notImplemented(std::string(__PRETTY_FUNCTION__)+" May not be called!");
122 }
123 
124 void Geant4UserLimits::SetUserMinEkine(G4double /* uekinMin */) {
125  dd4hep::notImplemented(std::string(__PRETTY_FUNCTION__)+" May not be called!");
126 }
127 
128 void Geant4UserLimits::SetUserMinRange(G4double /* urangMin */) {
129  dd4hep::notImplemented(std::string(__PRETTY_FUNCTION__)+" May not be called!");
130 }
131 
dd4hep::sim::Geant4UserLimits::minRange
Handler minRange
Handler map for MinRange limit.
Definition: Geant4UserLimits.h:71
dd4hep::LimitSet::limits
const std::set< Limit > & limits() const
Accessor to limits container.
Definition: Objects.cpp:464
dd4hep::Limit
Small object describing a limit structure acting on a particle type.
Definition: Objects.h:389
dd4hep::sim::Geant4ParticleHandle::g4DefinitionsRegEx
static std::vector< G4ParticleDefinition * > g4DefinitionsRegEx(const std::string &expression)
Access Geant4 particle definitions by regular expression.
Definition: Geant4Particle.cpp:182
dd4hep::InstanceCount::increment
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
Geant4UserLimits.h
dd4hep::sim::Geant4UserLimits::Geant4UserLimits
Geant4UserLimits(LimitSet limitset)
Initializing Constructor.
Definition: Geant4UserLimits.cpp:73
dd4hep::sim::Geant4UserLimits::minEKine
Handler minEKine
Handler map for MinEKine limit.
Definition: Geant4UserLimits.h:69
dd4hep::sim::Geant4UserLimits::maxTrackLength
Handler maxTrackLength
Handler map for MaxTrackLength limit.
Definition: Geant4UserLimits.h:65
G4UserLimits
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
Definition: Geant4Classes.h:23
dd4hep::sim::Geant4UserLimits::SetUserMinRange
virtual void SetUserMinRange(G4double urangMin) override
Definition: Geant4UserLimits.cpp:128
dd4hep::sim::Geant4UserLimits::~Geant4UserLimits
virtual ~Geant4UserLimits()
Standard destructor.
Definition: Geant4UserLimits.cpp:81
dd4hep::sim::Geant4UserLimits::limits
LimitSet limits
Handle to the limitset to be applied.
Definition: Geant4UserLimits.h:61
dd4hep::sim::Geant4UserLimits::maxTime
Handler maxTime
Handler map for MaxTime limit.
Definition: Geant4UserLimits.h:67
dd4hep::sim::Geant4UserLimits::SetUserMaxTime
virtual void SetUserMaxTime(G4double utimeMax) override
Definition: Geant4UserLimits.cpp:120
dd4hep::LimitSet
Handle class describing a set of limits as they are used for simulation.
Definition: Objects.h:425
dd4hep::sim::Geant4UserLimits::SetUserMaxTrackLength
virtual void SetUserMaxTrackLength(G4double utrakMax) override
Definition: Geant4UserLimits.cpp:116
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
dd4hep::sim::Geant4UserLimits::Handler::particleLimits
std::map< const G4ParticleDefinition *, double > particleLimits
Handler particle ids for the limit (pdgID)
Definition: Geant4UserLimits.h:51
dd4hep::sim::Geant4UserLimits::SetMaxAllowedStep
virtual void SetMaxAllowedStep(G4double ustepMax) override
Setters may not be called!
Definition: Geant4UserLimits.cpp:112
dd4hep::sim::Geant4UserLimits::maxStepLength
Handler maxStepLength
Handler map for MaxStepLength limit.
Definition: Geant4UserLimits.h:63
dd4hep::sim::Geant4UserLimits::Handler::defaultValue
double defaultValue
Default value (either from base class or value if Limit.particles='*')
Definition: Geant4UserLimits.h:49
dd4hep::sim::Geant4UserLimits::SetUserMinEkine
virtual void SetUserMinEkine(G4double uekinMin) override
Definition: Geant4UserLimits.cpp:124
dd4hep::sim::Geant4UserLimits::update
virtual void update(LimitSet limitset)
Update the object.
Definition: Geant4UserLimits.cpp:86
Primitives.h
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: Geant4Output2EDM4hep.cpp:49
Geant4Particle.h
dd4hep::sim::Geant4UserLimits::Handler::value
double value(const G4Track &track) const
Access value according to track.
Definition: Geant4UserLimits.cpp:41
dd4hep::sim::Geant4UserLimits::enable_debug
static bool enable_debug(bool value)
Allow for debugging user limits (very verbose)
Definition: Geant4UserLimits.cpp:34
dd4hep::sim::Geant4UserLimits::Handler::set
void set(const std::string &particles, double val)
Set the handler value(s)
Definition: Geant4UserLimits.cpp:61
InstanceCount.h
DD4hepUnits.h
Printout.h