File indexing completed on 2025-01-18 09:14:19
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef DD4HEP_DDG4_GEANT4ESCAPECOUNTER_H
0014 #define DD4HEP_DDG4_GEANT4ESCAPECOUNTER_H
0015
0016
0017 #include <DD4hep/DetElement.h>
0018 #include <DDG4/Geant4SensDetAction.h>
0019 #include <DDG4/Geant4SteppingAction.h>
0020
0021
0022 namespace dd4hep {
0023
0024
0025 namespace sim {
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 class Geant4EscapeCounter : public Geant4Sensitive {
0036
0037 size_t m_collectionID;
0038
0039 std::vector<std::string> m_detectorNames;
0040
0041 public:
0042
0043 Geant4EscapeCounter(Geant4Context* ctxt, const std::string& name, DetElement det, Detector& description);
0044
0045 virtual ~Geant4EscapeCounter();
0046
0047 virtual bool process(const G4Step* step, G4TouchableHistory* history) override;
0048 };
0049
0050 }
0051 }
0052
0053 #endif
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068 #include <DD4hep/Printout.h>
0069 #include <DD4hep/InstanceCount.h>
0070
0071 #include <DDG4/Geant4TouchableHandler.h>
0072 #include <DDG4/Geant4TrackHandler.h>
0073 #include <DDG4/Geant4StepHandler.h>
0074 #include <DDG4/Geant4Mapping.h>
0075 #include <DDG4/Geant4Data.h>
0076
0077 #include <CLHEP/Units/SystemOfUnits.h>
0078 #include <G4VProcess.hh>
0079
0080 using namespace dd4hep::sim;
0081
0082
0083 Geant4EscapeCounter::Geant4EscapeCounter(Geant4Context* ctxt, const std::string& nam, DetElement det, Detector& description_ref)
0084 : Geant4Sensitive(ctxt, nam, det, description_ref)
0085 {
0086 std::string coll_name = name()+"Hits";
0087 m_needsControl = true;
0088 declareProperty("Shells",m_detectorNames);
0089 m_collectionID = defineCollection<SimpleTracker::Hit>(coll_name);
0090 InstanceCount::increment(this);
0091 }
0092
0093
0094 Geant4EscapeCounter::~Geant4EscapeCounter() {
0095 InstanceCount::decrement(this);
0096 }
0097
0098
0099 bool Geant4EscapeCounter::process(const G4Step* step, G4TouchableHistory* ) {
0100 Geant4StepHandler h(step);
0101 Geant4TrackHandler th(h.track);
0102 Geant4TouchableHandler handler(step);
0103 std::string hdlr_path = handler.path();
0104 Position prePos = h.prePos();
0105 Geant4HitCollection* coll = collection(m_collectionID);
0106 SimpleTracker::Hit* hit = new SimpleTracker::Hit();
0107 hit->g4ID = th.id();
0108 hit->energyDeposit = h.deposit();
0109 hit->cellID = volumeID(step);
0110 hit->energyDeposit = th.energy();
0111 hit->position = prePos;
0112 hit->momentum = h.trkMom();
0113 hit->length = (h.postPos()-prePos).R();
0114 hit->truth.trackID = th.id();
0115 hit->truth.deposit = h.deposit();
0116 hit->truth.pdgID = th.pdgID();
0117 hit->truth.deposit = h.deposit();
0118 hit->truth.time = th.time();
0119 hit->truth.length = hit->length;
0120 hit->truth.x = hit->position.x();
0121 hit->truth.y = hit->position.y();
0122 hit->truth.z = hit->position.z();
0123 coll->add(hit);
0124 mark(h.track);
0125
0126 print("+++ Track:%4d %8.2f MeV [%s] %s Geant4 path:%s",
0127 h.trkID(),h.trkEnergy()/CLHEP::MeV,th.name().c_str(),
0128 th.creatorName().c_str(),hdlr_path.c_str());
0129
0130 step->GetTrack()->SetTrackStatus(fStopAndKill);
0131 return true;
0132 }
0133
0134 #include <DDG4/Factories.h>
0135 DECLARE_GEANT4SENSITIVE(Geant4EscapeCounter)
0136