DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Geant4EscapeCounter.cpp
Go to the documentation of this file.
1 // $Id: $
2 //==========================================================================
3 // AIDA Detector description implementation for LCD
4 //--------------------------------------------------------------------------
5 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
6 // All rights reserved.
7 //
8 // For the licensing terms see $DD4hepINSTALL/LICENSE.
9 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
10 //
11 // Author : M.Frank
12 //
13 //==========================================================================
14 #ifndef DD4HEP_DDG4_GEANT4ESCAPECOUNTER_H
15 #define DD4HEP_DDG4_GEANT4ESCAPECOUNTER_H
16 
17 // Framework include files
18 #include "DD4hep/Detector.h"
21 
23 namespace DD4hep {
24 
26  namespace Simulation {
27 
29 
36  class Geant4EscapeCounter : /* virtual public Geant4SteppingAction, virtual */ public Geant4Sensitive {
39  std::vector<std::string> m_detectorNames;
40  public:
42  Geant4EscapeCounter(Geant4Context* ctxt, const std::string& name, DetElement det, LCDD& lcdd);
44  virtual ~Geant4EscapeCounter();
46  virtual bool process(G4Step* step, G4TouchableHistory* history);
47  };
48 
49  } // End namespace Simulation
50 } // End namespace DD4hep
51 
52 #endif /* DD4HEP_DDG4_GEANT4ESCAPECOUNTER_H */
53 
54 // $Id: Geant4Converter.cpp 603 2013-06-13 21:15:14Z markus.frank $
55 //====================================================================
56 // AIDA Detector description implementation for LCD
57 //--------------------------------------------------------------------
58 //
59 // Author : M.Frank
60 //
61 //====================================================================
62 #include "DD4hep/Printout.h"
63 #include "DD4hep/InstanceCount.h"
64 
67 #include "DDG4/Geant4StepHandler.h"
68 #include "DDG4/Geant4Mapping.h"
69 #include "DDG4/Geant4Data.h"
70 
71 #include "CLHEP/Units/SystemOfUnits.h"
72 #include "G4VProcess.hh"
73 
74 using namespace std;
75 using namespace DD4hep;
76 using namespace DD4hep::Simulation;
77 
79 Geant4EscapeCounter::Geant4EscapeCounter(Geant4Context* ctxt, const string& nam, DetElement det, LCDD& lcdd_ref)
80  : Geant4Sensitive(ctxt, nam, det, lcdd_ref)
81 {
82  string coll_name = name()+"Hits";
83  m_needsControl = true;
85  m_collectionID = defineCollection<SimpleTracker::Hit>(coll_name);
87 }
88 
92 }
93 
95 bool Geant4EscapeCounter::process(G4Step* step, G4TouchableHistory* /* history */) {
96  Geant4StepHandler h(step);
98  Geant4TouchableHandler handler(step);
99  string hdlr_path = handler.path();
100  Position prePos = h.prePos();
102  SimpleTracker::Hit* hit = new SimpleTracker::Hit(th.id(),th.pdgID(),h.deposit(),th.time());
103  hit->cellID = volumeID(step);
104  hit->energyDeposit = th.energy();
105  hit->position = prePos;
106  hit->momentum = h.trkMom();
107  hit->length = 0;
108  coll->add(hit);
109  mark(h.track);
110 
111  print("+++ Track:%4d %8.2f MeV [%s] %s Geant4 path:%s",
112  h.trkID(),h.trkEnergy()/CLHEP::MeV,th.name().c_str(),
113  th.creatorName().c_str(),hdlr_path.c_str());
114  // Kill track, so that it does no longer participate in the propagation
115  h.track->SetTrackStatus(fStopAndKill);
116  return true;
117 }
118 
119 #include "DDG4/Factories.h"
121 
DDG4 tracker hit class used by the generic DDG4 tracker sensitive detector.
Definition: Geant4Data.h:228
static const double MeV
Definition: DD4hepUnits.h:146
std::string path() const
Helper: Access the placement path of a Geant4 touchable object as a string.
void mark(const G4Track *track) const
Mark the track to be kept for MC truth propagation during hit processing.
double length
Length of the track segment contributing to this hit.
Definition: Geant4Data.h:235
Direction momentum
Hit direction.
Definition: Geant4Data.h:233
HitCollection * collection(size_t which)
Retrieve the hits collection associated with this detector by its serial number.
static void decrement(T *)
Decrement count according to type information.
double energyDeposit
Energy deposit in the tracker hit.
Definition: Geant4Data.h:239
Class to measure the energy of escaping tracks.
Helper class to ease the extraction of information from a G4Track object.
const std::string creatorName() const
Physical process of the track generation.
Helper class to ease the extraction of information from a G4Step object.
int pdgID() const
Access the PDG particle identification.
virtual bool process(G4Step *step, G4TouchableHistory *history)
G4VSensitiveDetector interface: Method for generating hit(s) using the information of G4Step object...
long long int cellID
cellID
Definition: Geant4Data.h:122
const std::string & name() const
Access name of the action.
Definition: Geant4Action.h:271
void print(const char *fmt,...) const
Support for messages with variable output level using output level.
The base class for Geant4 sensitive detector actions implemented by users.
size_t m_collectionID
Collection identifiers.
const std::string & name() const
Track's particle name.
Position prePos() const
Returns the pre-step position.
Position position
Hit position.
Definition: Geant4Data.h:231
long long int volumeID(const G4Step *step)
Returns the volumeID of the sensitive volume corresponding to the step.
void add(TYPE *hit_pointer)
Add a new hit with a check, that the hit is of the same type.
Helper class to ease the extraction of information from a G4Touchable object.
ROOT::Math::XYZVector Position
Definition: Objects.h:75
virtual ~Geant4EscapeCounter()
Default destructor.
Generic hit container class using Geant4HitWrapper objects.
bool m_needsControl
Default property: Flag to create control instance.
Definition: Geant4Action.h:101
Geant4EscapeCounter(Geant4Context *ctxt, const std::string &name, DetElement det, LCDD &lcdd)
Standard constructor.
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
double energy() const
Track's energy.
Handle class describing a detector element.
Definition: Detector.h:172
Generic context to extend user, run and event information.
The main interface to the DD4hep detector description package.
Definition: LCDD.h:82
Geant4Action & declareProperty(const std::string &nam, T &val)
Declare property.
Definition: Geant4Action.h:358
int id() const
Track's identifier.
#define DECLARE_GEANT4SENSITIVE(name)
Definition: Factories.h:160