8#include "G4VVisManager.hh"
10#include "G4VisAttributes.hh"
11#include "Randomize.hh"
22constexpr int opticalPhotonPid = -22;
26std::atomic<int> GHit::globalHitCounter{0};
27thread_local std::map<int, G4ThreeVector> GHit::trackVertexById;
28thread_local std::map<int, int> GHit::pdgById;
37 const G4Step* thisStep,
38 const string& cScheme) :
56 vector<GIdentifier> gids =
getGID();
57 ttid.reserve(gids.size());
58 for (
auto& gid : gids) {
60 ttid.push_back(gid.getValue());
66 auto visManager = G4VVisManager::GetConcreteInstance();
67 if (!visManager)
return;
73 if (globalPositions.empty())
return;
75 G4Circle circle(globalPositions[0]);
76 circle.SetFillStyle(G4Circle::filled);
79 const bool opticalPhotonHit = !pids.empty() && pids.front() == opticalPhotonPid;
81 if (opticalPhotonHit) {
82 circle.SetScreenSize(15);
83 circle.SetVisAttributes(G4VisAttributes(colour_passby));
86 circle.SetScreenSize(50);
87 circle.SetVisAttributes(G4VisAttributes(colour_hit));
90 circle.SetScreenSize(15);
91 circle.SetVisAttributes(G4VisAttributes(colour_passby));
92 circle.SetFillStyle(G4Circle::hashed);
95 visManager->Draw(circle);
99 std::set<int> photonTrackIds;
100 const size_t entries = std::min(pids.size(), tids.size());
102 for (
size_t index = 0; index < entries; ++index) {
103 if (pids[index] == opticalPhotonPid) { photonTrackIds.insert(tids[index]); }
106 return photonTrackIds.size();
109bool GHit::setColorSchema() {
111 colour_hit = G4Colour(1.0, 0.0, 0.0);
112 colour_passby = G4Colour(0.0, 1.0, 0.0);
117 trackVertexById.clear();
126 invalidateCalculatedState();
129 for (
int i = 0; i <
nsteps + 1; ++i) {
130 globalPositions.emplace_back(G4UniformRand() * 100, G4UniformRand() * 100, G4UniformRand() * 100);
131 localPositions.emplace_back(G4UniformRand() * 10, G4UniformRand() * 10, G4UniformRand() * 10);
132 trackVertexPositions.emplace_back(G4UniformRand() * 100, G4UniformRand() * 100, G4UniformRand() * 100);
133 motherInfos.push_back({0, std::nullopt, std::nullopt});
134 times.emplace_back(G4UniformRand() * 100);
135 edeps.emplace_back(G4UniformRand() * 10);
136 pids.emplace_back(11);
137 tids.emplace_back(i);
138 momenta.emplace_back(G4UniformRand() * 100, G4UniformRand() * 100, G4UniformRand() * 100);
139 trackEs.emplace_back(G4UniformRand() * 1000);
140 processNames.emplace_back(
"placeholder");
static void clearTrackVertexCache()
Clear the per-thread track vertex cache.
double getTotalEnergyDeposited() const
Get the total deposited energy across all recorded steps.
size_t nsteps() const
Number of recorded steps.
std::vector< GIdentifier > getGID() const
Get the detector element identity.
std::vector< int > getTTID() const
Get the touchable identity values as integers.
bool is_same_hit(const GHit *hit) const
Compare this hit against another hit by sensitive-element identity.
void randomizeHitForTesting(int nsteps)
Randomize internal vectors for test-only usage.
GHit(std::shared_ptr< GTouchable > gt, const G4Step *thisStep=nullptr, const std::string &cScheme="default")
Construct a hit container and optionally seed it from a step.
void Draw() override
Visualize the hit using Geant4 visualization primitives.
std::shared_ptr< GTouchable > getGTouchable() const
Get the associated sensitive-element descriptor.
size_t getNumberOfOpticalPhotons() const
Count distinct optical-photon tracks recorded in this hit.
void addHitInfos(const G4Step *thisStep)
Append per-step information from a G4Step.
G4ThreadLocal G4Allocator< GHit > * GHitAllocator