ghit
Loading...
Searching...
No Matches
calculations.cc
Go to the documentation of this file.
1// ghit
2#include "ghit.h"
3
4// glibrary
5#include "gutsConventions.h"
6
7// See header for API docs.
8
17 double tote = getTotalEnergyDeposited();
18
19 double avgx = 0, avgy = 0, avgz = 0;
20 double avglx = 0, avgly = 0, avglz = 0;
21 averageTime = 0;
22
23 auto nsteps_ = edeps.size();
24 for (size_t s = 0; s < nsteps_; s++) {
25 // Energy-weighted average when possible; otherwise arithmetic average.
26 if (tote > 0) {
27 averageTime += times[s] * edeps[s] / tote;
28 avgx += globalPositions[s].getX() * edeps[s] / tote;
29 avgy += globalPositions[s].getY() * edeps[s] / tote;
30 avgz += globalPositions[s].getZ() * edeps[s] / tote;
31 avglx += localPositions[s].getX() * edeps[s] / tote;
32 avgly += localPositions[s].getY() * edeps[s] / tote;
33 avglz += localPositions[s].getZ() * edeps[s] / tote;
34 }
35 else {
36 averageTime += times[s] / nsteps_;
37 avgx += globalPositions[s].getX() / nsteps_;
38 avgy += globalPositions[s].getY() / nsteps_;
39 avgz += globalPositions[s].getZ() / nsteps_;
40 avglx += localPositions[s].getX() / nsteps_;
41 avgly += localPositions[s].getY() / nsteps_;
42 avglz += localPositions[s].getZ() / nsteps_;
43 }
44 }
45 avgGlobalPosition = G4ThreeVector(avgx, avgy, avgz);
46 avgLocalPosition = G4ThreeVector(avglx, avgly, avglz);
47
48 // Use the first process name as the representative label for this hit.
49 if (!processNames.empty()) {
50 processName = processNames.front();
51 }
52}
53
55 if (!totalEnergyDeposited.has_value()) {
56 double sum = 0;
57 for (const auto& ei : edeps) {
58 sum += ei;
59 }
60 totalEnergyDeposited = sum;
61 }
62 return totalEnergyDeposited.value();
63}
64
65
67 if (averageTime == UNINITIALIZEDNUMBERQUANTITY) {
68 double tote = getTotalEnergyDeposited();
69
70 averageTime = 0;
71 auto nsteps_ = edeps.size();
72 for (size_t s = 0; s < nsteps_; s++) {
73 if (totalEnergyDeposited > 0) {
74 averageTime += times[s] * edeps[s] / tote;
75 }
76 else {
77 averageTime += times[s] / nsteps_;
78 }
79 }
80 }
81
82 return averageTime;
83}
84
86 if (avgGlobalPosition.getX() == UNINITIALIZEDNUMBERQUANTITY && avgGlobalPosition.getY() ==
88 double tote = getTotalEnergyDeposited();
89
90 double avgx = 0, avgy = 0, avgz = 0;
91
92 auto nsteps_ = edeps.size();
93 for (size_t s = 0; s < nsteps_; s++) {
94 if (totalEnergyDeposited > 0) {
95 avgx += globalPositions[s].getX() * edeps[s] / tote;
96 avgy += globalPositions[s].getY() * edeps[s] / tote;
97 avgz += globalPositions[s].getZ() * edeps[s] / tote;
98 }
99 else {
100 averageTime += times[s] / nsteps_;
101 avgx += globalPositions[s].getX() / nsteps_;
102 avgy += globalPositions[s].getY() / nsteps_;
103 avgz += globalPositions[s].getZ() / nsteps_;
104 }
105 }
106 avgGlobalPosition = G4ThreeVector(avgx, avgy, avgz);
107 }
108
109 return avgGlobalPosition;
110}
111
113 if (avgLocalPosition.getX() == UNINITIALIZEDNUMBERQUANTITY && avgLocalPosition.getY() ==
115 double tote = getTotalEnergyDeposited();
116
117 double avgx = 0, avgy = 0, avgz = 0;
118
119 auto nsteps_ = edeps.size();
120 for (size_t s = 0; s < nsteps_; s++) {
121 if (totalEnergyDeposited > 0) {
122 avgx += localPositions[s].getX() * edeps[s] / tote;
123 avgy += localPositions[s].getY() * edeps[s] / tote;
124 avgz += localPositions[s].getZ() * edeps[s] / tote;
125 }
126 else {
127 averageTime += times[s] / nsteps_;
128 avgx += localPositions[s].getX() / nsteps_;
129 avgy += localPositions[s].getY() / nsteps_;
130 avgz += localPositions[s].getZ() / nsteps_;
131 }
132 }
133 avgLocalPosition = G4ThreeVector(avgx, avgy, avgz);
134 }
135 return avgLocalPosition;
136}
void calculateInfos()
Compute and cache derived hit quantities.
G4ThreeVector getAvgGlobaPosition()
Get the average global position of the hit.
double getTotalEnergyDeposited()
Get the total deposited energy across all recorded steps.
double getAverageTime()
Get the average time associated with the hit.
G4ThreeVector getAvgLocalPosition()
Get the average local position of the hit.
#define UNINITIALIZEDNUMBERQUANTITY