ghit
Loading...
Searching...
No Matches
calculations.cc
Go to the documentation of this file.
1// ghit
2#include "ghit.h"
3
4// c++
5#include <utility>
6
7// See header for API docs.
8
9const GHit::CalculatedState& GHit::getCalculatedState() const {
10 if (calculatedState) return *calculatedState;
11
12 CalculatedState state;
13 for (const double edep : edeps) { state.totalEnergyDeposited += edep; }
14 if (!processNames.empty()) { state.processName = processNames.front(); }
15
16 const size_t step_count = edeps.size();
17 if (step_count > 0) {
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;
25 }
26 }
27
28 calculatedState = std::move(state);
29 return *calculatedState;
30}
31
32void GHit::invalidateCalculatedState() {
33 calculatedState.reset();
34}
35
37 return getCalculatedState().totalEnergyDeposited;
38}
39
40double GHit::getAverageTime() const {
41 return getCalculatedState().averageTime;
42}
43
44G4ThreeVector GHit::getAvgGlobalPosition() const {
45 return getCalculatedState().averageGlobalPosition;
46}
47
48G4ThreeVector GHit::getAvgLocalPosition() const {
49 return getCalculatedState().averageLocalPosition;
50}
51
52const std::optional<std::string>& GHit::getProcessName() const {
53 return getCalculatedState().processName;
54}
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.