ghit
Loading...
Searching...
No Matches
addHitInfos.cc
Go to the documentation of this file.
1// ghit
2#include "ghit.h"
3
4// geant4
5#include "G4TouchableHistory.hh"
6#include "G4VProcess.hh"
7
8// See header for API docs.
9
10void GHit::addHitInfosForBitset(const HitBitSet hbs, const G4Step* step) {
11 // Preconditions:
12 // - 'step' must be non-null (callers provide a valid G4Step from the stepping action).
13 // - 'gtouchable' must be valid; it provides energy scaling and identity/dimensions.
14
15 auto preStepPoint = step->GetPreStepPoint();
16 // auto poststepPoint = step->GetPostStepPoint();
17
18 auto touchable = preStepPoint->GetTouchable();
19
20 // Get the global position and transform it to local coordinates of the touchable.
21 G4ThreeVector xyz = preStepPoint->GetPosition();
22 G4ThreeVector xyzL = touchable->GetHistory()->GetTopTransform().TransformPoint(xyz);
23
24 globalPositions.push_back(xyz);
25 localPositions.push_back(xyzL);
26
27 // Retrieve energy deposition and time information.
28 // Energy is scaled by the detector-specific multiplier from GTouchable.
29 double edep = (step->GetTotalEnergyDeposit()) * (gtouchable->getEnergyMultiplier());
30 double time = preStepPoint->GetGlobalTime();
31
32 edeps.push_back(edep);
33 times.push_back(time);
34
35 // Iterate over each bit and call the helper method to add optional info.
36 for (size_t hbIndex = 0; hbIndex < hbs.size(); hbIndex++) {
37 addHitInfosForBitIndex(hbIndex, hbs.test(hbIndex), step);
38 }
39}
40
41bool GHit::addHitInfosForBitIndex(size_t bitIndex, const bool test, const G4Step* thisStep) {
42 // If the bit is not enabled, do nothing.
43 if (!test) return false;
44
45 G4Track* trk = thisStep->GetTrack();
46 G4StepPoint* prestep = thisStep->GetPreStepPoint();
47
48 // Bit 0: record particle ID, per-step total energy, and creator process name (if available).
49 if (bitIndex == 0) {
50 pids.push_back(trk->GetDefinition()->GetPDGEncoding());
51 Es.push_back(prestep->GetTotalEnergy());
52 if (trk->GetCreatorProcess()) {
53 processNames.push_back(trk->GetCreatorProcess()->GetProcessName());
54 }
55 }
56 else if (bitIndex == 1) {
57 // Placeholder: record step length and track info.
58 }
59 else if (bitIndex == 2) {
60 // Placeholder: record mother particle track information.
61 }
62 else if (bitIndex == 3) {
63 // Placeholder: record meta information.
64 }
65 else if (bitIndex == 4) {
66 // Placeholder: record optical photon-specific information.
67 }
68 return true;
69}
void addHitInfosForBitset(HitBitSet hbs, const G4Step *thisStep)
Append per-step information from a G4Step according to a bitset.
std::bitset< NHITBITS > HitBitSet
Bitset selecting which optional hit information is recorded.