Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Geant4OpticalTrackerAction which stops-and-kills optical photons #967

Merged
merged 1 commit into from
Sep 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions DDG4/plugins/Geant4SDActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,90 @@ namespace dd4hep {

typedef Geant4SensitiveAction<Geant4Tracker> Geant4TrackerAction;

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Geant4SensitiveAction<Geant4PhotonCounter>
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/** \addtogroup Geant4SDActionPlugin
*
* @{
* \package Geant4OpticalTrackerAction
* \brief Sensitive detector meant for photon detectors, will produce one hit per step
* for regular particles, but absorb optical photons fully on their first hit
*
* @}
*/

/// Helper class to define properties of optical trackers. UNTESTED
struct Geant4OpticalTracker {};

/// Define collections created by this sensitivie action object
template <> void Geant4SensitiveAction<Geant4OpticalTracker>::defineCollections() {
m_collectionID = declareReadoutFilteredCollection<Geant4Tracker::Hit>();
}

/// Method for generating hit(s) using the information of G4Step object.
template <> bool
Geant4SensitiveAction<Geant4OpticalTracker>::process(const G4Step* step,G4TouchableHistory* /* hist */) {
G4Track * track = step->GetTrack();
typedef Geant4Tracker::Hit Hit;
Geant4StepHandler h(step);
Position prePos = h.prePos();
Position postPos = h.postPos();
Position direction = postPos - prePos;
Position position = mean_direction(prePos,postPos);
double hit_len = direction.R();

Hit* hit = new Hit(h.trkID(), h.trkPdgID(), h.deposit(), h.track->GetGlobalTime());
HitContribution contrib = Hit::extractContribution(step);
hit->cellID = cellID(step);
hit->energyDeposit = contrib.deposit;
hit->position = position;
hit->momentum = 0.5*( h. preMom() + h.postMom() ) ;
hit->length = hit_len;
if (track->GetDefinition() != G4OpticalPhoton::OpticalPhotonDefinition()) {
track->SetTrackStatus(fStopAndKill);
}
collection(m_collectionID)->add(hit);
mark(h.track);
if ( 0 == hit->cellID ) {
hit->cellID = volumeID( step ) ;
except("+++ Invalid CELL ID for hit!");
}
print("Hit with deposit:%f Pos:%f %f %f ID=%016X",
step->GetTotalEnergyDeposit(),position.X(),position.Y(),position.Z(),
(void*)hit->cellID);
Geant4TouchableHandler handler(step);
print(" Geant4 path:%s",handler.path().c_str());
return true;
}

/// GFlash/FastSim interface: Method for generating hit(s) using the information of G4Step object.
template <> bool
Geant4SensitiveAction<Geant4OpticalTracker>::processFastSim(const Geant4FastSimSpot* spot,
G4TouchableHistory* /* hist */)
{
typedef Geant4Tracker::Hit Hit;
Geant4FastSimHandler h(spot);
Hit* hit = new Hit(h.trkID(), h.trkPdgID(), h.deposit(), h.track->GetGlobalTime());
hit->cellID = cellID(h.touchable(), h.avgPositionG4());
hit->energyDeposit = h.deposit();
hit->position = h.avgPosition();
hit->momentum = h.momentum();
hit->length = 0e0;
collection(m_collectionID)->add(hit);
mark(h.track);
if ( 0 == hit->cellID ) {
hit->cellID = volumeID(h.touchable());
except("+++ Invalid CELL ID for hit!");
}
print("Hit with deposit:%f Pos:%f %f %f ID=%016X",
h.deposit(),hit->position.X(),hit->position.Y(),hit->position.Z(),(void*)hit->cellID);
Geant4TouchableHandler handler(h.touchable());
print(" Geant4 path:%s",handler.path().c_str());
return true;
}
typedef Geant4SensitiveAction<Geant4OpticalTracker> Geant4OpticalTrackerAction;

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Geant4SensitiveAction<Calorimeter>
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Expand Down Expand Up @@ -720,6 +804,7 @@ using namespace dd4hep::sim;
DECLARE_GEANT4SENSITIVE(Geant4VoidSensitiveAction)
// Standard factories used for simulation
DECLARE_GEANT4SENSITIVE(Geant4TrackerAction)
DECLARE_GEANT4SENSITIVE(Geant4OpticalTrackerAction)
DECLARE_GEANT4SENSITIVE(Geant4TrackerCombineAction)
DECLARE_GEANT4SENSITIVE(Geant4CalorimeterAction)
DECLARE_GEANT4SENSITIVE(Geant4OpticalCalorimeterAction)
Expand Down