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
18 // Bit 0: always present - calculate total energy, average time, and average positions.
19 if (bit == 0) {
20 double tote = getTotalEnergyDeposited();
21
22 double avgx = 0, avgy = 0, avgz = 0;
23 double avglx = 0, avgly = 0, avglz = 0;
24 averageTime = 0;
25
26 auto nsteps = edeps.size();
27 for (size_t s = 0; s < nsteps; s++) {
28 // Energy-weighted average.
29 if (tote > 0) {
30 averageTime += times[s] * edeps[s] / tote;
31 avgx += globalPositions[s].getX() * edeps[s] / tote;
32 avgy += globalPositions[s].getY() * edeps[s] / tote;
33 avgz += globalPositions[s].getZ() * edeps[s] / tote;
34 avglx += localPositions[s].getX() * edeps[s] / tote;
35 avgly += localPositions[s].getY() * edeps[s] / tote;
36 avglz += localPositions[s].getZ() * edeps[s] / tote;
37 } else { // Fallback to simple averaging if no energy is deposited.
38 averageTime += times[s] / nsteps;
39 avgx += globalPositions[s].getX() / nsteps;
40 avgy += globalPositions[s].getY() / nsteps;
41 avgz += globalPositions[s].getZ() / nsteps;
42 avglx += localPositions[s].getX() / nsteps;
43 avgly += localPositions[s].getY() / nsteps;
44 avglz += localPositions[s].getZ() / nsteps;
45 }
46 }
47 avgGlobalPosition = G4ThreeVector(avgx, avgy, avgz);
48 avgLocalPosition = G4ThreeVector(avglx, avgly, avglz);
49
50 // Use the first process name if available.
51 if (!processNames.empty()) {
52 processName = processNames.front();
53 }
54 }
55 // Future extensions for bits 1-4 can be added below.
56 else if (bit == 1) {
57 // Placeholder for step length and track information.
58 } else if (bit == 2) {
59 // Placeholder for mother particle tracks information.
60 } else if (bit == 3) {
61 // Placeholder for meta information.
62 } else if (bit == 4) {
63 // Placeholder for optical photon specific information.
64 }
65}
66
67
75// Then in getTotalEnergyDeposited():
77 if (!totalEnergyDeposited.has_value()) {
78 double sum = 0;
79 for (const auto &ei: edeps) {
80 sum += ei;
81 }
82 totalEnergyDeposited = sum;
83 }
84 return totalEnergyDeposited.value();
85}
86
88 if (averageTime == UNINITIALIZEDNUMBERQUANTITY) {
89
90 double tote = getTotalEnergyDeposited();
91
92
93 averageTime = 0;
94 auto nsteps = edeps.size();
95 for (size_t s = 0; s < nsteps; s++) {
96 if (totalEnergyDeposited > 0) {
97 averageTime += times[s] * edeps[s] / tote;
98 } else {
99 averageTime += times[s] / nsteps;
100 }
101 }
102
103 }
104
105 return averageTime;
106}
107
108
116
117 if (avgGlobalPosition.getX() == UNINITIALIZEDNUMBERQUANTITY && avgGlobalPosition.getY() == UNINITIALIZEDNUMBERQUANTITY) {
118
119 double tote = getTotalEnergyDeposited();
120
121 double avgx = 0, avgy = 0, avgz = 0;
122
123 auto nsteps = edeps.size();
124 for (size_t s = 0; s < nsteps; s++) {
125 if (totalEnergyDeposited > 0) {
126 avgx += globalPositions[s].getX() * edeps[s] / tote;
127 avgy += globalPositions[s].getY() * edeps[s] / tote;
128 avgz += globalPositions[s].getZ() * edeps[s] / tote;
129 } else {
130 averageTime += times[s] / nsteps;
131 avgx += globalPositions[s].getX() / nsteps;
132 avgy += globalPositions[s].getY() / nsteps;
133 avgz += globalPositions[s].getZ() / nsteps;
134 }
135 }
136 avgGlobalPosition = G4ThreeVector(avgx, avgy, avgz);
137 }
138
139 return avgGlobalPosition;
140}
141
149
150 if (avgLocalPosition.getX() == UNINITIALIZEDNUMBERQUANTITY && avgLocalPosition.getY() == UNINITIALIZEDNUMBERQUANTITY) {
151
152 double tote = getTotalEnergyDeposited();
153
154 double avgx = 0, avgy = 0, avgz = 0;
155
156 auto nsteps = edeps.size();
157 for (size_t s = 0; s < nsteps; s++) {
158 if (totalEnergyDeposited > 0) {
159 avgx += localPositions[s].getX() * edeps[s] / tote;
160 avgy += localPositions[s].getY() * edeps[s] / tote;
161 avgz += localPositions[s].getZ() * edeps[s] / tote;
162 } else {
163 averageTime += times[s] / nsteps;
164 avgx += localPositions[s].getX() / nsteps;
165 avgy += localPositions[s].getY() / nsteps;
166 avgz += localPositions[s].getZ() / nsteps;
167 }
168 }
169 avgLocalPosition = G4ThreeVector(avgx, avgy, avgz);
170
171 }
172 return avgLocalPosition;
173}
size_t nsteps() const
Definition ghit.h:159
void calculateInfosForBit(int bit)
Calculates averaged hit information for the specified bit.
G4ThreeVector getAvgGlobaPosition()
Computes the average global position of the hit.
double getTotalEnergyDeposited()
Computes the total energy deposited.
double getAverageTime()
G4ThreeVector getAvgLocalPosition()
Computes the average local position of the hit.