8#include "G4VVisManager.hh"
10#include "G4VisAttributes.hh"
11#include "Randomize.hh"
16std::atomic<int> GHit::globalHitCounter{0};
17thread_local std::map<int, G4ThreeVector> GHit::trackVertexById;
18thread_local std::map<int, int> GHit::pdgById;
27 const G4Step* thisStep,
28 const string& cScheme) :
54 vector<GIdentifier> gids =
getGID();
55 ttid.reserve(gids.size());
56 for (
auto& gid : gids) {
58 ttid.push_back(gid.getValue());
64 auto visManager = G4VVisManager::GetConcreteInstance();
65 if (!visManager)
return;
71 if (globalPositions.empty())
return;
73 G4Circle circle(globalPositions[0]);
74 circle.SetFillStyle(G4Circle::filled);
79 circle.SetScreenSize(50);
80 circle.SetVisAttributes(G4VisAttributes(colour_hit));
83 circle.SetScreenSize(15);
84 circle.SetVisAttributes(G4VisAttributes(colour_passby));
85 circle.SetFillStyle(G4Circle::hashed);
88 visManager->Draw(circle);
91bool GHit::setColorSchema() {
93 colour_hit = G4Colour(1.0, 0.0, 0.0);
94 colour_passby = G4Colour(0.0, 1.0, 0.0);
99 trackVertexById.clear();
109 for (
int i = 0; i <
nsteps + 1; ++i) {
110 globalPositions.emplace_back(G4UniformRand() * 100, G4UniformRand() * 100, G4UniformRand() * 100);
111 localPositions.emplace_back(G4UniformRand() * 10, G4UniformRand() * 10, G4UniformRand() * 10);
112 trackVertexPositions.emplace_back(G4UniformRand() * 100, G4UniformRand() * 100, G4UniformRand() * 100);
115 times.emplace_back(G4UniformRand() * 100);
116 edeps.emplace_back(G4UniformRand() * 10);
117 pids.emplace_back(11);
118 tids.emplace_back(i);
119 motherTids.emplace_back(0);
120 momenta.emplace_back(G4UniformRand() * 100, G4UniformRand() * 100, G4UniformRand() * 100);
121 trackEs.emplace_back(G4UniformRand() * 1000);
122 motherPids.emplace_back(2212);
123 processNames.emplace_back(
"placeholder");
Stores step-by-step and aggregated information for a detector hit.
static void clearTrackVertexCache()
Clear the per-thread track vertex cache.
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.
double getTotalEnergyDeposited()
Get the total deposited energy across all recorded steps.
std::shared_ptr< GTouchable > getGTouchable() const
Get the associated sensitive-element descriptor.
void addHitInfos(const G4Step *thisStep)
Append per-step information from a G4Step.
G4ThreadLocal G4Allocator< GHit > * GHitAllocator
#define UNINITIALIZEDNUMBERQUANTITY
#define UNINITIALIZEDSTRINGQUANTITY