Newer
Older
Markus Frank
committed
//==========================================================================
Markus Frank
committed
//--------------------------------------------------------------------------
// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
Markus Frank
committed
// All rights reserved.
Markus Frank
committed
// For the licensing terms see $DD4hepINSTALL/LICENSE.
// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
Markus Frank
committed
// Author : M.Frank
//
//=========================================================================
#include <DD4hep/Printout.h>
#include <DD4hep/InstanceCount.h>
#include <DDG4/Geant4TestActions.h>
#include <G4Run.hh>
#include <G4Event.hh>
#include <G4Step.hh>
#include <G4Track.hh>
// C/C++ include files
#include <stdexcept>
TestHit() {
}
virtual ~TestHit() {
}
Geant4TestBase::Geant4TestBase(Geant4Action* a, const std::string& typ)
Markus Frank
committed
: m_type(typ) {
a->declareProperty("Property_int", m_value1 = 0);
a->declareProperty("Property_double", m_value2 = 0e0);
a->declareProperty("Property_string", m_value3);
InstanceCount::increment(this);
}
/// Default destructor
Geant4TestBase::~Geant4TestBase() {
InstanceCount::decrement(this);
}
/// Standard constructor with initializing arguments
Geant4TestGeneratorAction::Geant4TestGeneratorAction(Geant4Context* c, const std::string& n)
Markus Frank
committed
: Geant4GeneratorAction(c, n), Geant4TestBase(this, "Geant4TestGeneratorAction") {
InstanceCount::increment(this);
}
/// Default destructor
Geant4TestGeneratorAction::~Geant4TestGeneratorAction() {
InstanceCount::decrement(this);
}
/// Callback to generate primary particles
void Geant4TestGeneratorAction::operator()(G4Event* evt) {
Markus Frank
committed
PRINT("%s> calling Geant4TestGeneratorAction(event_id=%d Context: run=%p evt=%p)",
m_type.c_str(), evt->GetEventID(), context()->runPtr(), context()->eventPtr());
}
/// Standard constructor with initializing arguments
Geant4TestRunAction::Geant4TestRunAction(Geant4Context* c, const std::string& n)
Markus Frank
committed
: Geant4RunAction(c, n), Geant4TestBase(this, "Geant4TestRunAction") {
Geant4TestRunAction::~Geant4TestRunAction() {
InstanceCount::decrement(this);
}
void Geant4TestRunAction::begin(const G4Run* run) {
PRINT("%s> calling begin(run_id=%d,num_event=%d Context:%p)", m_type.c_str(), run->GetRunID(),
Markus Frank
committed
run->GetNumberOfEventToBeProcessed(), &context()->run());
void Geant4TestRunAction::end(const G4Run* run) {
Markus Frank
committed
PRINT("%s> calling end(run_id=%d, num_event=%d Context:%p)",
m_type.c_str(), run->GetRunID(), run->GetNumberOfEvent(), &context()->run());
void Geant4TestRunAction::beginEvent(const G4Event* evt) {
Markus Frank
committed
PRINT("%s> calling beginEvent(event_id=%d Context: run=%p evt=%p)",
m_type.c_str(), evt->GetEventID(), context()->runPtr(), context()->eventPtr());
void Geant4TestRunAction::endEvent(const G4Event* evt) {
Markus Frank
committed
PRINT("%s> calling endEvent(event_id=%d Context: run=%p evt=%p)",
m_type.c_str(), evt->GetEventID(), context()->runPtr(), context()->eventPtr());
/// Standard constructor with initializing arguments
Geant4TestEventAction::Geant4TestEventAction(Geant4Context* c, const std::string& n)
Markus Frank
committed
: Geant4EventAction(c, n), Geant4TestBase(this, "Geant4TestEventAction") {
Geant4TestEventAction::~Geant4TestEventAction() {
InstanceCount::decrement(this);
}
/// begin-of-event callback
void Geant4TestEventAction::begin(const G4Event* evt) {
Markus Frank
committed
PRINT("%s> calling begin(event_id=%d Context: run=%p (%d) evt=%p (%d))",
m_type.c_str(), evt->GetEventID(),
&context()->run(), context()->run().run().GetRunID(),
&context()->event(), context()->event().event().GetEventID());
void Geant4TestEventAction::end(const G4Event* evt) {
Markus Frank
committed
PRINT("%s> calling end(event_id=%d Context: run=%p (%d) evt=%p (%d))",
m_type.c_str(), evt->GetEventID(), &context()->run(), &context()->event(),
&context()->run(), context()->run().run().GetRunID(),
&context()->event(), context()->event().event().GetEventID());
void Geant4TestEventAction::beginRun(const G4Run* run) {
PRINT("%s> calling beginRun(run_id=%d,num_event=%d Context:%p)",
Markus Frank
committed
m_type.c_str(), run->GetRunID(),
run->GetNumberOfEventToBeProcessed(), context()->runPtr());
void Geant4TestEventAction::endRun(const G4Run* run) {
Markus Frank
committed
PRINT("%s> calling endRun(run_id=%d, num_event=%d Context:%p)",
m_type.c_str(), run->GetRunID(),
run->GetNumberOfEvent(), context()->runPtr());
/// Standard constructor with initializing arguments
Geant4TestTrackAction::Geant4TestTrackAction(Geant4Context* c, const std::string& n)
Markus Frank
committed
: Geant4TrackingAction(c, n), Geant4TestBase(this, "Geant4TestTrackAction") {
Geant4TestTrackAction::~Geant4TestTrackAction() {
InstanceCount::decrement(this);
}
/// Begin-of-tracking callback
void Geant4TestTrackAction::begin(const G4Track* trk) {
Markus Frank
committed
PRINT("%s> calling begin(track=%d, parent=%d, position=(%f,%f,%f) Context: run=%p evt=%p)",
m_type.c_str(), trk->GetTrackID(),
trk->GetParentID(), trk->GetPosition().x(), trk->GetPosition().y(), trk->GetPosition().z(),
&context()->run(), &context()->event());
}
/// End-of-tracking callback
void Geant4TestTrackAction::end(const G4Track* trk) {
Markus Frank
committed
PRINT("%s> calling end(track=%d, parent=%d, position=(%f,%f,%f) Context: run=%p evt=%p)",
m_type.c_str(), trk->GetTrackID(),
trk->GetParentID(), trk->GetPosition().x(), trk->GetPosition().y(), trk->GetPosition().z(),
&context()->run(), &context()->event());
/// Standard constructor with initializing arguments
Geant4TestStepAction::Geant4TestStepAction(Geant4Context* c, const std::string& n)
Markus Frank
committed
: Geant4SteppingAction(c, n), Geant4TestBase(this, "Geant4TestStepAction") {
Geant4TestStepAction::~Geant4TestStepAction() {
InstanceCount::decrement(this);
}
/// User stepping callback
void Geant4TestStepAction::operator()(const G4Step*, G4SteppingManager*) {
PRINT("%s> calling operator()", m_type.c_str());
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/// Standard constructor with initializing arguments
Geant4TestStackAction::Geant4TestStackAction(Geant4Context* c, const std::string& n)
: Geant4StackingAction(c, n), Geant4TestBase(this, "Geant4TestStackAction") {
InstanceCount::increment(this);
}
/// Default destructor
Geant4TestStackAction::~Geant4TestStackAction() {
InstanceCount::decrement(this);
}
/// New-stage callback
void Geant4TestStackAction::newStage(G4StackManager*) {
PRINT("%s> calling newStage()", m_type.c_str());
}
/// Preparation callback
void Geant4TestStackAction::prepare(G4StackManager*) {
PRINT("%s> calling prepare()", m_type.c_str());
}
/// Return TrackClassification with enum G4ClassificationOfNewTrack or NoTrackClassification
TrackClassification Geant4TestStackAction::classifyNewTrack(G4StackManager*, const G4Track* trk) {
PRINT("%s> calling classifyNewTrack(track=%d, parent=%d, position=(%f,%f,%f) Context: run=%p evt=%p)",
m_type.c_str(), trk->GetTrackID(),
trk->GetParentID(), trk->GetPosition().x(), trk->GetPosition().y(), trk->GetPosition().z(),
&context()->run(), &context()->event());
return TrackClassification();
}
/// Standard constructor with initializing arguments
Geant4TestSensitive::Geant4TestSensitive(Geant4Context* c, const std::string& n, DetElement det, Detector& description)
: Geant4Sensitive(c, n, det, description), Geant4TestBase(this, "Geant4TestSensitive") {
m_collectionID = defineCollection < TestHit > (n);
PRINT("%s> Collection ID is %d", m_type.c_str(), int(m_collectionID));
Geant4TestSensitive::~Geant4TestSensitive() {
InstanceCount::decrement(this);
}
/// Begin-of-tracking callback
void Geant4TestSensitive::begin(G4HCofThisEvent* hce) {
Geant4HitCollection* c = collectionByID(m_collectionID);
Markus Frank
committed
PRINT("%s> calling begin(num_coll=%d, coll=%s Context: run=%p evt=%p)",
m_type.c_str(), hce->GetNumberOfCollections(),
c ? c->GetName().c_str() : "None", &context()->run(), &context()->event());
}
/// End-of-tracking callback
void Geant4TestSensitive::end(G4HCofThisEvent* hce) {
Geant4HitCollection* c = collection(m_collectionID);
Markus Frank
committed
PRINT("%s> calling end(num_coll=%d, coll=%s Context: run=%p evt=%p)",
m_type.c_str(), hce->GetNumberOfCollections(),
c ? c->GetName().c_str() : "None", &context()->run(), &context()->event());
}
/// Method for generating hit(s) using the information of G4Step object.
Markus Frank
committed
bool Geant4TestSensitive::process(const G4Step* step, G4TouchableHistory*) {
Geant4HitCollection* c = collection(m_collectionID);
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)",
Markus Frank
committed
m_type.c_str(), step->GetTrack()->GetTrackID(),
step->GetTotalEnergyDeposit(), step->GetDeltaTime(),
step->GetStepLength(), step->IsFirstStepInVolume() ? 'Y' : 'N',
step->IsLastStepInVolume() ? 'Y' : 'N',
c ? c->GetName().c_str() : "None", &context()->run(), &context()->event());