Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:17:35

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //=========================================================================
0013 
0014 // Framework include files
0015 #include <DD4hep/Printout.h>
0016 #include <DD4hep/InstanceCount.h>
0017 #include <DDG4/Geant4TestActions.h>
0018 #include <G4Run.hh>
0019 #include <G4Event.hh>
0020 #include <G4Step.hh>
0021 #include <G4Track.hh>
0022 
0023 // C/C++ include files
0024 #include <stdexcept>
0025 
0026 using namespace dd4hep::sim::Test;
0027 
0028 namespace {
0029   struct TestHit {
0030     TestHit() {
0031     }
0032     virtual ~TestHit() {
0033     }
0034   };
0035 }
0036 
0037 #define PRINT print
0038 
0039 
0040 /// Standard constructor
0041 Geant4TestBase::Geant4TestBase(Geant4Action* a, const std::string& typ)
0042   : m_type(typ) {
0043   a->declareProperty("Property_int", m_value1 = 0);
0044   a->declareProperty("Property_double", m_value2 = 0e0);
0045   a->declareProperty("Property_string", m_value3);
0046   InstanceCount::increment(this);
0047 }
0048 /// Default destructor
0049 Geant4TestBase::~Geant4TestBase() {
0050   printout(VERBOSE, m_type, "properties at destruction: %d, %f, %s", m_value1, m_value2, m_value3.c_str());
0051   InstanceCount::decrement(this);
0052 }
0053 
0054 /// Standard constructor with initializing arguments
0055 Geant4TestGeneratorAction::Geant4TestGeneratorAction(Geant4Context* c, const std::string& n)
0056   : Geant4GeneratorAction(c, n), Geant4TestBase(this, "Geant4TestGeneratorAction") {
0057   InstanceCount::increment(this);
0058 }
0059 
0060 /// Default destructor
0061 Geant4TestGeneratorAction::~Geant4TestGeneratorAction() {
0062   InstanceCount::decrement(this);
0063 }
0064 
0065 /// Callback to generate primary particles
0066 void Geant4TestGeneratorAction::operator()(G4Event* evt)  {
0067   PRINT("%s> calling Geant4TestGeneratorAction(event_id=%d Context: run=%p evt=%p)",
0068         m_type.c_str(), evt->GetEventID(), context()->runPtr(), context()->eventPtr());
0069 }
0070 
0071 /// Standard constructor with initializing arguments
0072 Geant4TestRunAction::Geant4TestRunAction(Geant4Context* c, const std::string& n)
0073   : Geant4RunAction(c, n), Geant4TestBase(this, "Geant4TestRunAction") {
0074   InstanceCount::increment(this);
0075 }
0076 
0077 /// Default destructor
0078 Geant4TestRunAction::~Geant4TestRunAction() {
0079   InstanceCount::decrement(this);
0080 }
0081 
0082 /// begin-of-run callback
0083 void Geant4TestRunAction::begin(const G4Run* run) {
0084   PRINT("%s> calling begin(run_id=%d,num_event=%d Context:%p)", m_type.c_str(), run->GetRunID(),
0085         run->GetNumberOfEventToBeProcessed(), &context()->run());
0086 }
0087 
0088 /// End-of-run callback
0089 void Geant4TestRunAction::end(const G4Run* run) {
0090   PRINT("%s> calling end(run_id=%d, num_event=%d Context:%p)",
0091         m_type.c_str(), run->GetRunID(), run->GetNumberOfEvent(), &context()->run());
0092 }
0093 
0094 /// begin-of-event callback
0095 void Geant4TestRunAction::beginEvent(const G4Event* evt) {
0096   PRINT("%s> calling beginEvent(event_id=%d Context: run=%p evt=%p)",
0097         m_type.c_str(), evt->GetEventID(), context()->runPtr(), context()->eventPtr());
0098 }
0099 
0100 /// End-of-event callback
0101 void Geant4TestRunAction::endEvent(const G4Event* evt) {
0102   PRINT("%s> calling endEvent(event_id=%d Context: run=%p evt=%p)",
0103         m_type.c_str(), evt->GetEventID(), context()->runPtr(), context()->eventPtr());
0104 }
0105 
0106 /// Standard constructor with initializing arguments
0107 Geant4TestEventAction::Geant4TestEventAction(Geant4Context* c, const std::string& n)
0108   : Geant4EventAction(c, n), Geant4TestBase(this, "Geant4TestEventAction") {
0109   InstanceCount::increment(this);
0110 }
0111 
0112 /// Default destructor
0113 Geant4TestEventAction::~Geant4TestEventAction() {
0114   InstanceCount::decrement(this);
0115 }
0116 /// begin-of-event callback
0117 void Geant4TestEventAction::begin(const G4Event* evt) {
0118   PRINT("%s> calling begin(event_id=%d Context:  run=%p (%d) evt=%p (%d))",
0119         m_type.c_str(), evt->GetEventID(),
0120         &context()->run(), context()->run().run().GetRunID(),
0121         &context()->event(), context()->event().event().GetEventID());
0122 }
0123 
0124 /// End-of-event callback
0125 void Geant4TestEventAction::end(const G4Event* evt) {
0126   PRINT("%s> calling end(event_id=%d Context:  run=%p (%d) evt=%p (%d))",
0127         m_type.c_str(), evt->GetEventID(), &context()->run(), &context()->event(),
0128         &context()->run(), context()->run().run().GetRunID(),
0129         &context()->event(), context()->event().event().GetEventID());
0130 }
0131 
0132 /// begin-of-run callback
0133 void Geant4TestEventAction::beginRun(const G4Run* run) {
0134   PRINT("%s> calling beginRun(run_id=%d,num_event=%d Context:%p)",
0135         m_type.c_str(), run->GetRunID(),
0136         run->GetNumberOfEventToBeProcessed(), context()->runPtr());
0137 }
0138 
0139 /// End-of-run callback
0140 void Geant4TestEventAction::endRun(const G4Run* run) {
0141   PRINT("%s> calling endRun(run_id=%d, num_event=%d Context:%p)",
0142         m_type.c_str(), run->GetRunID(),
0143         run->GetNumberOfEvent(), context()->runPtr());
0144 }
0145 
0146 /// Standard constructor with initializing arguments
0147 Geant4TestTrackAction::Geant4TestTrackAction(Geant4Context* c, const std::string& n)
0148   : Geant4TrackingAction(c, n), Geant4TestBase(this, "Geant4TestTrackAction") {
0149   InstanceCount::increment(this);
0150 }
0151 
0152 /// Default destructor
0153 Geant4TestTrackAction::~Geant4TestTrackAction() {
0154   InstanceCount::decrement(this);
0155 }
0156 /// Begin-of-tracking callback
0157 void Geant4TestTrackAction::begin(const G4Track* trk) {
0158   PRINT("%s> calling begin(track=%d, parent=%d, position=(%f,%f,%f) Context: run=%p evt=%p)",
0159         m_type.c_str(), trk->GetTrackID(),
0160         trk->GetParentID(), trk->GetPosition().x(), trk->GetPosition().y(), trk->GetPosition().z(),
0161         &context()->run(), &context()->event());
0162 }
0163 
0164 /// End-of-tracking callback
0165 void Geant4TestTrackAction::end(const G4Track* trk) {
0166   PRINT("%s> calling end(track=%d, parent=%d, position=(%f,%f,%f) Context: run=%p evt=%p)",
0167         m_type.c_str(), trk->GetTrackID(),
0168         trk->GetParentID(), trk->GetPosition().x(), trk->GetPosition().y(), trk->GetPosition().z(),
0169         &context()->run(), &context()->event());
0170 }
0171 
0172 /// Standard constructor with initializing arguments
0173 Geant4TestStepAction::Geant4TestStepAction(Geant4Context* c, const std::string& n)
0174   : Geant4SteppingAction(c, n), Geant4TestBase(this, "Geant4TestStepAction") {
0175   InstanceCount::increment(this);
0176 }
0177 
0178 /// Default destructor
0179 Geant4TestStepAction::~Geant4TestStepAction() {
0180   InstanceCount::decrement(this);
0181 }
0182 /// User stepping callback
0183 void Geant4TestStepAction::operator()(const G4Step*, G4SteppingManager*) {
0184   PRINT("%s> calling operator()", m_type.c_str());
0185 }
0186 
0187 /// Standard constructor with initializing arguments
0188 Geant4TestStackAction::Geant4TestStackAction(Geant4Context* c, const std::string& n)
0189   : Geant4StackingAction(c, n), Geant4TestBase(this, "Geant4TestStackAction") {
0190   InstanceCount::increment(this);
0191 }
0192 
0193 /// Default destructor
0194 Geant4TestStackAction::~Geant4TestStackAction() {
0195   InstanceCount::decrement(this);
0196 }
0197 /// New-stage callback
0198 void Geant4TestStackAction::newStage(G4StackManager*) {
0199   PRINT("%s> calling newStage()", m_type.c_str());
0200 }
0201 /// Preparation callback
0202 void Geant4TestStackAction::prepare(G4StackManager*) {
0203   PRINT("%s> calling prepare()", m_type.c_str());
0204 }
0205 /// Return TrackClassification with enum G4ClassificationOfNewTrack or NoTrackClassification
0206 dd4hep::sim::TrackClassification Geant4TestStackAction::classifyNewTrack(G4StackManager*, const G4Track* trk) {
0207   PRINT("%s> calling classifyNewTrack(track=%d, parent=%d, position=(%f,%f,%f) Context: run=%p evt=%p)",
0208         m_type.c_str(), trk->GetTrackID(),
0209         trk->GetParentID(), trk->GetPosition().x(), trk->GetPosition().y(), trk->GetPosition().z(),
0210         &context()->run(), &context()->event());
0211   return TrackClassification();
0212 }
0213 
0214 /// Standard constructor with initializing arguments
0215 Geant4TestSensitive::Geant4TestSensitive(Geant4Context* c, const std::string& n, DetElement det, Detector& description)
0216   : Geant4Sensitive(c, n, det, description), Geant4TestBase(this, "Geant4TestSensitive") {
0217   InstanceCount::increment(this);
0218   m_collectionID = defineCollection < TestHit > (n);
0219   PRINT("%s> Collection ID is %d", m_type.c_str(), int(m_collectionID));
0220 }
0221 
0222 /// Default destructor
0223 Geant4TestSensitive::~Geant4TestSensitive() {
0224   InstanceCount::decrement(this);
0225 }
0226 
0227 /// Begin-of-tracking callback
0228 void Geant4TestSensitive::begin(G4HCofThisEvent* hce) {
0229   Geant4HitCollection* c = collectionByID(m_collectionID);
0230   PRINT("%s> calling begin(num_coll=%d, coll=%s Context: run=%p evt=%p)",
0231         m_type.c_str(), hce->GetNumberOfCollections(),
0232         c ? c->GetName().c_str() : "None", &context()->run(), &context()->event());
0233 }
0234 
0235 /// End-of-tracking callback
0236 void Geant4TestSensitive::end(G4HCofThisEvent* hce) {
0237   Geant4HitCollection* c = collection(m_collectionID);
0238   PRINT("%s> calling end(num_coll=%d, coll=%s Context: run=%p evt=%p)",
0239         m_type.c_str(), hce->GetNumberOfCollections(),
0240         c ? c->GetName().c_str() : "None", &context()->run(), &context()->event());
0241 }
0242 
0243 /// Method for generating hit(s) using the information of G4Step object.
0244 bool Geant4TestSensitive::process(const G4Step* step, G4TouchableHistory*) {
0245   Geant4HitCollection* c = collection(m_collectionID);
0246   PRINT("%s> calling process(track=%d, dE=%f, dT=%f len=%f, First,last in Vol=(%c,%c), coll=%s Context: run=%p evt=%p)",
0247         m_type.c_str(), step->GetTrack()->GetTrackID(),
0248         step->GetTotalEnergyDeposit(), step->GetDeltaTime(),
0249         step->GetStepLength(), step->IsFirstStepInVolume() ? 'Y' : 'N',
0250         step->IsLastStepInVolume() ? 'Y' : 'N',
0251         c ? c->GetName().c_str() : "None", &context()->run(), &context()->event());
0252   return true;
0253 }