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