Skip to content

Commit c1b75db

Browse files
committed
added true information vars
1 parent 2536e09 commit c1b75db

4 files changed

Lines changed: 117 additions & 7 deletions

File tree

gemc/gdynamicDigitization/gdynamicdigitization.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@ std::unique_ptr<GTrueInfoData> GDynamicDigitization::collectTrueInformationImpl(
3636
G4ThreeVector motherTrackVertex = ghit->getMotherTrackVertexPosition();
3737

3838
trueInfoData->includeVariable("pid", ghit->getPid());
39+
trueInfoData->includeVariable("mpid", ghit->getMpid());
3940
trueInfoData->includeVariable("tid", ghit->getTid());
41+
trueInfoData->includeVariable("otid", 0);
4042
trueInfoData->includeVariable("mtid", ghit->getMotherTid());
4143
trueInfoData->includeVariable("totalEDeposited", ghit->getTotalEnergyDeposited());
44+
trueInfoData->includeVariable("trackE", ghit->getTrackE());
4245
trueInfoData->includeVariable("avgTime", ghit->getAverageTime());
4346
trueInfoData->includeVariable("avgx", avgGlobalPos.getX());
4447
trueInfoData->includeVariable("avgy", avgGlobalPos.getY());
@@ -52,10 +55,17 @@ std::unique_ptr<GTrueInfoData> GDynamicDigitization::collectTrueInformationImpl(
5255
trueInfoData->includeVariable("mvx", motherTrackVertex.getX());
5356
trueInfoData->includeVariable("mvy", motherTrackVertex.getY());
5457
trueInfoData->includeVariable("mvz", motherTrackVertex.getZ());
58+
59+
G4ThreeVector momentum = ghit->getMomentum();
60+
trueInfoData->includeVariable("px", momentum.getX());
61+
trueInfoData->includeVariable("py", momentum.getY());
62+
trueInfoData->includeVariable("pz", momentum.getZ());
63+
64+
trueInfoData->includeVariable("nsteps", static_cast<int>(ghit->getStepCount()));
5565
trueInfoData->includeVariable("hitn", static_cast<int>(hitn)); // assume hitn < INT_MAX
5666

57-
// Bit 1 typically includes metadata like the process name.
5867
trueInfoData->includeVariable("processName", ghit->getProcessName());
68+
trueInfoData->includeVariable("procID", ghit->getProcID());
5969

6070
return trueInfoData;
6171
}

gemc/ghit/addHitInfos.cc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
#include "gutsConventions.h"
66

77
// geant4
8-
#include "G4TouchableHistory.hh"
98
#include "G4VProcess.hh"
10-
#include "subprojects/assimp/code/AssetLib/3MF/3MFXmlTags.h"
119

1210
// See header for API docs.
1311

@@ -40,23 +38,33 @@ void GHit::addHitInfosForBitset(const HitBitSet hbs, const G4Step* step) {
4038
auto trackVertex = track->GetVertexPosition();
4139
int trackId = track->GetTrackID();
4240
int motherTrackId = track->GetParentID();
41+
int currentPdg = track->GetDefinition()->GetPDGEncoding();
4342

4443
trackVertexById.emplace(trackId, trackVertex);
44+
pdgById.emplace(trackId, currentPdg);
4545

4646
G4ThreeVector motherTrackVertex(UNINITIALIZEDNUMBERQUANTITY, UNINITIALIZEDNUMBERQUANTITY,
4747
UNINITIALIZEDNUMBERQUANTITY);
48+
int motherPdg = UNINITIALIZEDNUMBERQUANTITY;
4849
if (motherTrackId > 0) {
4950
auto motherVertex = trackVertexById.find(motherTrackId);
5051
if (motherVertex != trackVertexById.end()) {
5152
motherTrackVertex = motherVertex->second;
5253
}
54+
auto motherPdgIt = pdgById.find(motherTrackId);
55+
if (motherPdgIt != pdgById.end()) {
56+
motherPdg = motherPdgIt->second;
57+
}
5358
}
5459

5560
trackVertexPositions.push_back(trackVertex);
5661
motherTrackVertexPositions.push_back(motherTrackVertex);
57-
pids.push_back(track->GetDefinition()->GetPDGEncoding());
62+
pids.push_back(currentPdg);
5863
tids.push_back(trackId);
5964
motherTids.push_back(motherTrackId);
65+
momenta.push_back(preStepPoint->GetMomentum());
66+
trackEs.push_back(preStepPoint->GetTotalEnergy());
67+
motherPids.push_back(motherPdg);
6068

6169

6270
// Iterate over each bit and call the helper method to add optional info.

gemc/ghit/ghit.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ using std::vector;
1717

1818
std::atomic<int> GHit::globalHitCounter{0};
1919
thread_local std::map<int, G4ThreeVector> GHit::trackVertexById;
20+
thread_local std::map<int, int> GHit::pdgById;
2021

2122
// MT definitions, as from:
2223
// https://twiki.cern.ch/twiki/bin/view/Geant4/QuickMigrationGuideForGeant4V10
@@ -100,6 +101,7 @@ bool GHit::setColorSchema() {
100101

101102
void GHit::clearTrackVertexCache() {
102103
trackVertexById.clear();
104+
pdgById.clear();
103105
}
104106

105107
void GHit::randomizeHitForTesting(int nsteps) {
@@ -120,6 +122,9 @@ void GHit::randomizeHitForTesting(int nsteps) {
120122
tids.emplace_back(i);
121123
motherTids.emplace_back(0);
122124
Es.emplace_back(G4UniformRand() * 10);
125+
momenta.emplace_back(G4UniformRand() * 100, G4UniformRand() * 100, G4UniformRand() * 100);
126+
trackEs.emplace_back(G4UniformRand() * 1000);
127+
motherPids.emplace_back(2212); // proton as placeholder mother
123128

124129
pids.emplace_back(static_cast<int>(G4UniformRand() * 1000)); // Random particle ID
125130
}

gemc/ghit/ghit.h

Lines changed: 90 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,37 @@ class GHit : public G4VHit
226226
*/
227227
std::vector<double> stepSize;
228228

229+
/**
230+
* \brief Track 3-momentum per recorded step (unconditional).
231+
*
232+
* Values are derived from the pre-step point momentum via \c G4StepPoint::GetMomentum().
233+
* Stored in Geant4 internal units (MeV).
234+
*/
235+
std::vector<G4ThreeVector> momenta;
236+
237+
/**
238+
* \brief Track total energy per recorded step (unconditional).
239+
*
240+
* Values are derived from \c preStepPoint->GetTotalEnergy() (kinetic + rest mass, in MeV).
241+
*/
242+
std::vector<double> trackEs;
243+
244+
/**
245+
* \brief Mother particle PDG encodings per recorded step (unconditional).
246+
*
247+
* Looked up from the per-thread \c pdgById cache using the parent track ID.
248+
* Stores the uninitialized sentinel when the parent track has not yet been seen.
249+
*/
250+
std::vector<int> motherPids;
251+
252+
/**
253+
* \brief Per-thread cache of track-id to particle PDG encoding.
254+
*
255+
* Populated alongside \c trackVertexById so that mother PDG can be resolved
256+
* when the parent track was already processed by GEMC hit logic.
257+
*/
258+
static thread_local std::map<int, int> pdgById;
259+
229260
// -------------------------------------------------------------------------
230261
// Aggregated / calculated quantities (lazy)
231262
// -------------------------------------------------------------------------
@@ -400,28 +431,84 @@ class GHit : public G4VHit
400431
[[nodiscard]] inline int getMotherTid() const { return motherTids.front(); }
401432

402433
/**
403-
* \brief Get per-step total energies (when enabled).
434+
* \brief Get per-step total energies (when enabled by bit 0).
404435
* \return A copy of the vector of per-step energies.
405436
*/
406437
[[nodiscard]] inline std::vector<double> getEs() const { return Es; }
407438

408439
/**
409-
* \brief Convenience accessor for the first energy value.
440+
* \brief Convenience accessor for the first energy value (requires bit 0).
410441
* \return The first energy value.
411442
*
412443
* \warning This assumes the internal \c Es vector is non-empty.
413444
*/
414445
[[nodiscard]] inline double getE() const { return Es.front(); }
415446

416447
/**
417-
* \brief Number of recorded steps for the optional-energy vector.
448+
* \brief Number of recorded steps for the optional-energy vector (requires bit 0).
418449
* \return The size of the \c Es vector.
419450
*
420451
* \note Depending on the \c HitBitSet configuration, \c Es may remain empty even if
421452
* always-present vectors have entries.
422453
*/
423454
[[nodiscard]] inline size_t nsteps() const { return Es.size(); }
424455

456+
/**
457+
* \brief True number of recorded steps (always-present edep vector).
458+
* \return The size of the \c edeps vector, which is always populated regardless of HitBitSet.
459+
*/
460+
[[nodiscard]] inline size_t getStepCount() const { return edeps.size(); }
461+
462+
/**
463+
* \brief Get per-step track 3-momenta (always present).
464+
* \return A copy of the vector of per-step momenta.
465+
*/
466+
[[nodiscard]] inline std::vector<G4ThreeVector> getMomenta() const { return momenta; }
467+
468+
/**
469+
* \brief Convenience accessor for the first step 3-momentum.
470+
* \return The first recorded track momentum.
471+
*
472+
* \warning This assumes the internal \c momenta vector is non-empty.
473+
*/
474+
[[nodiscard]] inline G4ThreeVector getMomentum() const { return momenta.front(); }
475+
476+
/**
477+
* \brief Get per-step track total energies (always present).
478+
* \return A copy of the vector of per-step track total energies (MeV).
479+
*/
480+
[[nodiscard]] inline std::vector<double> getTrackEs() const { return trackEs; }
481+
482+
/**
483+
* \brief Convenience accessor for the first step track total energy.
484+
* \return The first recorded track total energy (MeV).
485+
*
486+
* \warning This assumes the internal \c trackEs vector is non-empty.
487+
*/
488+
[[nodiscard]] inline double getTrackE() const { return trackEs.front(); }
489+
490+
/**
491+
* \brief Get per-step mother particle PDG encodings (always present).
492+
* \return A copy of the vector of per-step mother PDG codes.
493+
*/
494+
[[nodiscard]] inline std::vector<int> getMotherPids() const { return motherPids; }
495+
496+
/**
497+
* \brief Convenience accessor for the first step mother particle PDG encoding.
498+
* \return The first recorded mother PDG code (sentinel when parent not yet seen).
499+
*
500+
* \warning This assumes the internal \c motherPids vector is non-empty.
501+
*/
502+
[[nodiscard]] inline int getMpid() const { return motherPids.front(); }
503+
504+
/**
505+
* \brief Get the representative creator process name for this hit.
506+
*
507+
* Alias for \ref getProcessName() following G4 naming conventions.
508+
* \return The cached representative process name.
509+
*/
510+
[[nodiscard]] inline std::string getProcID() const { return processName; }
511+
425512
/**
426513
* \brief Get the representative process name for the hit.
427514
* \return The cached representative process name string.

0 commit comments

Comments
 (0)