9#include <beast/fangs/simulation/SensitiveDetector.h>
10#include <framework/gearbox/Unit.h>
24 std::array<float, 3> vecToFloat(
const G4ThreeVector& vec)
26 return std::array<float, 3> {{(float)vec.x(), (float)vec.y(), (float)vec.z()}};
31 Simulation::SensitiveDetectorBase(
"FANGSSensitiveDetector",
Const::invalidDetector)
48 const G4TouchableHistory* touchable =
dynamic_cast<const G4TouchableHistory*
>(
step->GetPreStepPoint()->GetTouchable());
49 int ladderID = touchable->GetVolume(2)->GetCopyNo();
50 int sensorID = touchable->GetVolume(1)->GetCopyNo();
53 const G4Track& track = *
step->GetTrack();
54 const int trackID = track.GetTrackID();
55 const int pdgCode =
step->GetTrack()->GetDefinition()->GetPDGEncoding();
57 double depEnergy =
step->GetTotalEnergyDeposit();
62 const G4StepPoint& preStep = *
step->GetPreStepPoint();
63 const G4StepPoint& postStep = *
step->GetPostStepPoint();
66 if (
m_tracks.empty() || (!
m_tracks.top().check(trackID, ladderID, sensorID))) {
76 const G4ThreeVector preStepPos = preStep.GetPosition() / CLHEP::mm *
Unit::mm;
77 const G4ThreeVector preStepMom = preStep.GetMomentum() / CLHEP::MeV *
Unit::MeV;
79 const G4AffineTransform& localToGlobalTransform = preStep.GetTouchableHandle()->GetHistory()->GetTopTransform();
80 const G4ThreeVector localpreStepPos = localToGlobalTransform.TransformPoint(preStep.GetPosition()) / CLHEP::mm *
Unit::mm;
81 const double time = preStep.GetGlobalTime() / CLHEP::ns *
Unit::ns;
82 traversal.
setInitial(trackID, ladderID, sensorID, pdgCode, isPrimary, preStepPos, localpreStepPos, preStepMom, time);
84 if (preStep.GetStepStatus() == fGeomBoundary) traversal.
hasEntered();
87 const G4ThreeVector postStepPos = postStep.GetPosition() / CLHEP::mm *
Unit::mm;
88 const double length =
step->GetStepLength() / CLHEP::cm *
Unit::cm;
89 traversal.
add(postStepPos, depEnergy, length);
92 bool isLeaving = (postStep.GetStepStatus() == fGeomBoundary);
93 if (isLeaving) traversal.
hasLeft();
96 if (isLeaving || track.GetTrackStatus() >= fStopAndKill) {
100 if (saved && !contained) {
126 localposEntry.data(),
127 posExit.data(), momEntry.data()
This class provides a set of constants for the framework.
@ c_PrimaryParticle
bit 0: Particle is primary particle.
@ c_negativeWeight
Flip the sign of the weight to become negative if the original element got re-attributed.
void add(index_type from, index_type to, weight_type weight=1.0)
Add a new element to the relation.
static void registerMCParticleRelation(const std::string &name, RelationArray::EConsolidationAction ignoreAction=RelationArray::c_negativeWeight)
Register an relation involving MCParticles.
static Payload getInfo(Carrier &obj)
Static function to just return UserInformation attached to the obj of type Carrier.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
static const double mm
[millimeters]
static const double eV
[electronvolt]
static const double MeV
[megaelectronvolt]
static const double cm
Standard units with the value = 1.
static const double ns
Standard of [time].
static const double GeV
Standard of [energy, momentum, mass].
bool finishTrack()
finish a track
std::stack< SensorTraversal > m_tracks
Stack of tracks to keep track of particles.
RelationArray m_relMCSimHit
relation array of the MCParticle -> SimHit relation
StoreArray< MCParticle > m_mcParticles
store array of the MCParticles
StoreArray< FANGSSimHit > m_simHits
store array of the SimHits
SensitiveDetector()
Constructor.
bool step(G4Step *step, G4TouchableHistory *) override
Step processing method.
Class to keep track of the traversal of the sensitive volume for one track.
int getPDGCode() const
get PDG code of the particle
int getLadderID() const
get the ladder ID
void add(const G4ThreeVector &position, double depEnergy, double length)
add a new step
int getSensorID() const
get the sensor ID
const G4ThreeVector & getEntryMomentum() const
get entry momentum
const G4ThreeVector & getExitPosition() const
get exit position
void hasLeft()
indicate that the track left the current volume
void setInitial(int trackID, int ladderID, int sensorID, int pdgCode, bool primary, const G4ThreeVector &position, const G4ThreeVector &localposition, const G4ThreeVector &momentum, double time)
set initial values for a new track
const G4ThreeVector & getEntryPosition() const
get entry position
const G4ThreeVector & getLocalEntryPosition() const
get local entry position
int getTrackID() const
get Geant4 trackID
double getEntryTime() const
get entry time
double getDepEnergy() const
get total energy deposition
void reset()
reset to be used again
void hasEntered()
indicate that the track originated outisde the current volume
bool isContained() const
return whether the track was contained in the volume so far
double getLength() const
get flight length so far
Abstract base class for different kinds of events.