9const GHit::CalculatedState& GHit::getCalculatedState()
const {
10 if (calculatedState)
return *calculatedState;
12 CalculatedState state;
13 for (
const double edep : edeps) { state.totalEnergyDeposited += edep; }
14 if (!processNames.empty()) { state.processName = processNames.front(); }
16 const size_t step_count = edeps.size();
18 const bool energy_weighted = state.totalEnergyDeposited > 0;
19 for (
size_t step = 0; step < step_count; ++step) {
20 double weight = 1.0 /
static_cast<double>(step_count);
21 if (energy_weighted) { weight = edeps[step] / state.totalEnergyDeposited; }
22 state.averageTime += times[step] * weight;
23 state.averageGlobalPosition += globalPositions[step] * weight;
24 state.averageLocalPosition += localPositions[step] * weight;
28 calculatedState = std::move(state);
29 return *calculatedState;
32void GHit::invalidateCalculatedState() {
33 calculatedState.reset();
37 return getCalculatedState().totalEnergyDeposited;
41 return getCalculatedState().averageTime;
45 return getCalculatedState().averageGlobalPosition;
49 return getCalculatedState().averageLocalPosition;
53 return getCalculatedState().processName;
const std::optional< std::string > & getProcessName() const
Get the representative creator process name for the hit.
double getTotalEnergyDeposited() const
Get the total deposited energy across all recorded steps.
double getAverageTime() const
Get the average time associated with the hit.
G4ThreeVector getAvgLocalPosition() const
Get the average local position of the hit.
G4ThreeVector getAvgGlobalPosition() const
Get the average global position of the hit.