DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4EscapeCounter.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 #ifndef DD4HEP_DDG4_GEANT4ESCAPECOUNTER_H
14 #define DD4HEP_DDG4_GEANT4ESCAPECOUNTER_H
15 
16 // Framework include files
17 #include <DD4hep/DetElement.h>
20 
22 namespace dd4hep {
23 
25  namespace sim {
26 
28 
35  class Geant4EscapeCounter : /* virtual public Geant4SteppingAction, virtual */ public Geant4Sensitive {
39  std::vector<std::string> m_detectorNames;
40 
41  public:
43  Geant4EscapeCounter(Geant4Context* ctxt, const std::string& name, DetElement det, Detector& description);
45  virtual ~Geant4EscapeCounter();
47  virtual bool process(const G4Step* step, G4TouchableHistory* history) override;
48  };
49 
50  } // End namespace sim
51 } // End namespace dd4hep
52 
53 #endif /* DD4HEP_DDG4_GEANT4ESCAPECOUNTER_H */
54 
55 //====================================================================
56 // AIDA Detector description implementation
57 //--------------------------------------------------------------------
58 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
59 // All rights reserved.
60 //
61 // For the licensing terms see $DD4hepINSTALL/LICENSE.
62 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
63 //
64 // Author : M.Frank
65 //
66 //====================================================================
67 // Framework include files
68 #include <DD4hep/Printout.h>
69 #include <DD4hep/InstanceCount.h>
70 
73 #include <DDG4/Geant4StepHandler.h>
74 #include <DDG4/Geant4Mapping.h>
75 #include <DDG4/Geant4Data.h>
76 
77 #include <CLHEP/Units/SystemOfUnits.h>
78 #include <G4VProcess.hh>
79 
80 using namespace dd4hep::sim;
81 
83 Geant4EscapeCounter::Geant4EscapeCounter(Geant4Context* ctxt, const std::string& nam, DetElement det, Detector& description_ref)
84  : Geant4Sensitive(ctxt, nam, det, description_ref)
85 {
86  std::string coll_name = name()+"Hits";
87  m_needsControl = true;
89  m_collectionID = defineCollection<SimpleTracker::Hit>(coll_name);
91 }
92 
96 }
97 
99 bool Geant4EscapeCounter::process(const G4Step* step, G4TouchableHistory* /* history */) {
100  Geant4StepHandler h(step);
102  Geant4TouchableHandler handler(step);
103  std::string hdlr_path = handler.path();
104  Position prePos = h.prePos();
107  hit->g4ID = th.id();
108  hit->energyDeposit = h.deposit();
109  hit->cellID = volumeID(step);
110  hit->energyDeposit = th.energy();
111  hit->position = prePos;
112  hit->momentum = h.trkMom();
113  hit->length = (h.postPos()-prePos).R();
114  hit->truth.trackID = th.id();
115  hit->truth.deposit = h.deposit();
116  hit->truth.pdgID = th.pdgID();
117  hit->truth.deposit = h.deposit();
118  hit->truth.time = th.time();
119  hit->truth.length = hit->length;
120  hit->truth.x = hit->position.x();
121  hit->truth.y = hit->position.y();
122  hit->truth.z = hit->position.z();
123  coll->add(hit);
124  mark(h.track);
125 
126  print("+++ Track:%4d %8.2f MeV [%s] %s Geant4 path:%s",
127  h.trkID(),h.trkEnergy()/CLHEP::MeV,th.name().c_str(),
128  th.creatorName().c_str(),hdlr_path.c_str());
129  // Kill track, so that it does no longer participate in the propagation
130  step->GetTrack()->SetTrackStatus(fStopAndKill);
131  return true;
132 }
133 
134 #include <DDG4/Factories.h>
136 
DECLARE_GEANT4SENSITIVE
#define DECLARE_GEANT4SENSITIVE(name)
Definition: Factories.h:204
dd4hep::sim::Geant4Tracker::Hit::momentum
Direction momentum
Hit direction.
Definition: Geant4Data.h:270
dd4hep::sim::Geant4EscapeCounter::~Geant4EscapeCounter
virtual ~Geant4EscapeCounter()
Default destructor.
Definition: Geant4EscapeCounter.cpp:94
dd4hep::sim::Geant4Tracker::Hit::position
Position position
Hit position.
Definition: Geant4Data.h:268
Geant4TrackHandler.h
dd4hep::sim::Geant4TouchableHandler
Helper class to ease the extraction of information from a G4Touchable object.
Definition: Geant4TouchableHandler.h:44
dd4hep::sim::Geant4Action::m_needsControl
bool m_needsControl
Default property: Flag to create control instance.
Definition: Geant4Action.h:123
dd4hep::sim::Geant4StepHandler::prePos
Position prePos() const
Returns the pre-step position.
Definition: Geant4StepHandler.h:84
dd4hep::sim::Geant4HitData::MonteCarloContrib::pdgID
int pdgID
Particle ID from the PDG table.
Definition: Geant4Data.h:143
Geant4Mapping.h
dd4hep::sim::Geant4HitData::MonteCarloContrib::y
float y
Definition: Geant4Data.h:151
dd4hep::sim::Geant4HitData::MonteCarloContrib::length
double length
Length of this step.
Definition: Geant4Data.h:149
Geant4SensDetAction.h
dd4hep::sim::Geant4EscapeCounter::process
virtual bool process(const G4Step *step, G4TouchableHistory *history) override
G4VSensitiveDetector interface: Method for generating hit(s) using the information of G4Step object.
Definition: Geant4EscapeCounter.cpp:99
dd4hep::sim::Geant4HitCollection
Generic hit container class using Geant4HitWrapper objects.
Definition: Geant4HitCollection.h:201
dd4hep::sim::Geant4EscapeCounter::m_detectorNames
std::vector< std::string > m_detectorNames
Detector name set.
Definition: Geant4EscapeCounter.cpp:39
dd4hep::InstanceCount::increment
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
Geant4Data.h
Geant4StepHandler.h
dd4hep::sim::Geant4HitData::cellID
long long int cellID
cellID
Definition: Geant4Data.h:124
dd4hep::sim::Geant4HitHandler::trkID
int trkID() const
Access the G4 track ID.
Definition: Geant4HitHandler.h:73
dd4hep::sim::Geant4TrackHandler::time
double time() const
Track time.
Definition: Geant4TrackHandler.h:137
Geant4SteppingAction.h
dd4hep::sim::Geant4Sensitive::volumeID
long long int volumeID(const G4Step *step)
Returns the volumeID of the sensitive volume corresponding to the step.
Definition: Geant4SensDetAction.cpp:245
dd4hep::sim::Geant4Sensitive::collection
Geant4HitCollection * collection(std::size_t which)
Retrieve the hits collection associated with this detector by its serial number.
Definition: Geant4SensDetAction.cpp:196
dd4hep::sim::Geant4HitHandler::trkEnergy
double trkEnergy() const
Definition: Geant4HitHandler.h:83
dd4hep::sim::Geant4StepHandler
Helper class to ease the extraction of information from a G4Step object.
Definition: Geant4StepHandler.h:46
dd4hep::DetElement
Handle class describing a detector element.
Definition: DetElement.h:188
dd4hep::sim::Geant4Sensitive::mark
void mark(const G4Track *track) const
Mark the track to be kept for MC truth propagation during hit processing.
Definition: Geant4SensDetAction.cpp:233
dd4hep::sim::Geant4TrackHandler::name
const std::string & name() const
Track's particle name.
Definition: Geant4TrackHandler.h:97
dd4hep::sim::Geant4Tracker::Hit
DDG4 tracker hit class used by the generic DDG4 tracker sensitive detector.
Definition: Geant4Data.h:263
dd4hep::sim::Geant4Tracker::Hit::length
double length
Length of the track segment contributing to this hit.
Definition: Geant4Data.h:272
dd4hep::sim::Geant4HitData::g4ID
long g4ID
Original Geant 4 track identifier of the creating track (debugging)
Definition: Geant4Data.h:128
dd4hep::sim::Geant4HitData::MonteCarloContrib::deposit
double deposit
Total energy deposit in this hit.
Definition: Geant4Data.h:145
dd4hep::sim::Geant4Action::declareProperty
Geant4Action & declareProperty(const std::string &nam, T &val)
Declare property.
Definition: Geant4Action.h:366
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
dd4hep::sim::Geant4HitHandler::trkMom
Momentum trkMom() const
Definition: Geant4HitHandler.h:98
Geant4TouchableHandler.h
dd4hep::sim::Geant4TrackHandler
Helper class to ease the extraction of information from a G4Track object.
Definition: Geant4TrackHandler.h:53
dd4hep::sim::Geant4Tracker::Hit::truth
Contribution truth
Monte Carlo / Geant4 information.
Definition: Geant4Data.h:276
dd4hep::sim::Geant4TrackHandler::pdgID
int pdgID() const
Access the PDG particle identification.
Definition: Geant4TrackHandler.h:200
dd4hep::sim::Geant4Action::name
const std::string & name() const
Access name of the action.
Definition: Geant4Action.h:280
dd4hep::sim::Geant4Action::print
void print(const char *fmt,...) const
Support for messages with variable output level using output level.
Definition: Geant4Action.cpp:144
dd4hep::sim::Geant4HitData::MonteCarloContrib::trackID
int trackID
Geant 4 Track identifier.
Definition: Geant4Data.h:141
dd4hep::sim::Geant4StepHandler::deposit
double deposit() const
Definition: Geant4StepHandler.h:135
dd4hep::sim::Geant4StepHandler::postPos
Position postPos() const
Returns the post-step position.
Definition: Geant4StepHandler.h:93
dd4hep::Position
ROOT::Math::XYZVector Position
Definition: Objects.h:81
Factories.h
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: Geant4Output2EDM4hep.cpp:49
dd4hep::sim::Geant4HitData::MonteCarloContrib::x
float x
Proper position of the hit contribution.
Definition: Geant4Data.h:151
DetElement.h
dd4hep::sim::Geant4EscapeCounter::Geant4EscapeCounter
Geant4EscapeCounter(Geant4Context *ctxt, const std::string &name, DetElement det, Detector &description)
Standard constructor.
Definition: Geant4EscapeCounter.cpp:83
dd4hep::sim::Geant4TouchableHandler::path
std::string path() const
Helper: Access the placement path of a Geant4 touchable object as a string.
Definition: Geant4TouchableHandler.cpp:58
dd4hep::sim::Geant4EscapeCounter
Class to measure the energy of escaping tracks.
Definition: Geant4EscapeCounter.cpp:35
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
det
DetElement::Object * det
Definition: AlignmentsCalculator.cpp:66
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
dd4hep::sim::Geant4HitCollection::add
void add(TYPE *hit_pointer)
Add a new hit with a check, that the hit is of the same type.
Definition: Geant4HitCollection.h:333
dd4hep::sim::Geant4Sensitive
The base class for Geant4 sensitive detector actions implemented by users.
Definition: Geant4SensDetAction.h:121
dd4hep::sim::Geant4Tracker::Hit::energyDeposit
double energyDeposit
Energy deposit in the tracker hit.
Definition: Geant4Data.h:274
dd4hep::sim::Geant4HitHandler::track
const G4Track * track
Definition: Geant4HitHandler.h:45
InstanceCount.h
dd4hep::sim::Geant4TrackHandler::id
int id() const
Track's identifier.
Definition: Geant4TrackHandler.h:85
dd4hep::sim::Geant4TrackHandler::energy
double energy() const
Track's energy.
Definition: Geant4TrackHandler.h:121
dd4hep::sim::Geant4TrackHandler::creatorName
const std::string creatorName() const
Physical process of the track generation.
Definition: Geant4TrackHandler.h:178
dd4hep::sim::Geant4HitData::MonteCarloContrib::z
float z
Definition: Geant4Data.h:151
Printout.h
dd4hep::sim::Geant4HitData::MonteCarloContrib::time
double time
Timestamp when this energy was deposited.
Definition: Geant4Data.h:147
dd4hep::sim::Geant4EscapeCounter::m_collectionID
size_t m_collectionID
Collection identifiers.
Definition: Geant4EscapeCounter.cpp:37
dd4hep::sim::Geant4Context
Generic context to extend user, run and event information.
Definition: Geant4Context.h:201