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