10#include "G4VVisManager.hh"
12#include "G4VisAttributes.hh"
13#include "Randomize.hh"
18std::atomic<int> GHit::globalHitCounter{0};
19thread_local std::map<int, G4ThreeVector> GHit::trackVertexById;
29 const G4Step* thisStep,
30 const string& cScheme) :
57 vector<GIdentifier> gids =
getGID();
58 ttid.reserve(gids.size());
59 for (
auto& gid : gids) {
61 ttid.push_back(gid.getValue());
67 auto visManager = G4VVisManager::GetConcreteInstance();
68 if (!visManager)
return;
74 if (globalPositions.empty())
return;
76 G4Circle circle(globalPositions[0]);
77 circle.SetFillStyle(G4Circle::filled);
82 circle.SetScreenSize(50);
83 circle.SetVisAttributes(G4VisAttributes(colour_hit));
86 circle.SetScreenSize(15);
87 circle.SetVisAttributes(G4VisAttributes(colour_passby));
88 circle.SetFillStyle(G4Circle::hashed);
91 visManager->Draw(circle);
94bool GHit::setColorSchema() {
96 colour_hit = G4Colour(1.0, 0.0, 0.0);
97 colour_passby = G4Colour(0.0, 1.0, 0.0);
102 trackVertexById.clear();
111 for (
int i = 0; i <
nsteps + 1; ++i) {
112 globalPositions.emplace_back(G4UniformRand() * 100, G4UniformRand() * 100, G4UniformRand() * 100);
113 localPositions.emplace_back(G4UniformRand() * 10, G4UniformRand() * 10, G4UniformRand() * 10);
114 trackVertexPositions.emplace_back(G4UniformRand() * 100, G4UniformRand() * 100, G4UniformRand() * 100);
117 times.emplace_back(G4UniformRand() * 100);
118 edeps.emplace_back(G4UniformRand() * 10);
119 pids.emplace_back(11);
120 tids.emplace_back(i);
121 motherTids.emplace_back(0);
122 Es.emplace_back(G4UniformRand() * 10);
124 pids.emplace_back(
static_cast<int>(G4UniformRand() * 1000));
Stores step-by-step and aggregated information for a detector hit.
GHit(std::shared_ptr< GTouchable > gt, HitBitSet hbs, const G4Step *thisStep=nullptr, const std::string &cScheme="default")
Construct a hit container and optionally seed it from a step.
void addHitInfosForBitset(HitBitSet hbs, const G4Step *thisStep)
Append per-step information from a G4Step according to a bitset.
static void clearTrackVertexCache()
Clear the per-thread track vertex cache.
size_t nsteps() const
Number of recorded steps for the optional-energy vector.
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.
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.
std::bitset< NHITBITS > HitBitSet
Bitset selecting which optional hit information is recorded.
G4ThreadLocal G4Allocator< GHit > * GHitAllocator
#define UNINITIALIZEDNUMBERQUANTITY
#define UNINITIALIZEDSTRINGQUANTITY