5#include "G4THitsCollection.hh"
6#include "G4Allocator.hh"
8#include "G4ThreeVector.hh"
13#include <gemc/gtouchable/gtouchable.h>
51 GHit(std::shared_ptr<GTouchable> gt,
const G4Step* thisStep =
nullptr,
52 const std::string& cScheme =
"default");
65 inline void*
operator new(size_t);
70 inline void operator delete(
void*);
104 G4Colour colour_touch, colour_hit, colour_passby;
111 bool setColorSchema();
114 std::string colorSchema;
137 std::vector<double> edeps;
144 std::vector<double> times;
151 std::vector<G4ThreeVector> globalPositions;
158 std::vector<G4ThreeVector> localPositions;
165 std::vector<G4ThreeVector> trackVertexPositions;
174 std::vector<G4ThreeVector> motherTrackVertexPositions;
179 std::vector<int> pids;
184 std::vector<int> tids;
191 std::vector<int> motherTids;
199 std::vector<std::string> processNames;
207 std::vector<G4ThreeVector> momenta;
214 std::vector<double> trackEs;
222 std::vector<int> motherPids;
230 static thread_local std::map<int, int> pdgById;
241 std::optional<double> totalEnergyDeposited;
259 G4ThreeVector avgGlobalPosition;
266 G4ThreeVector avgLocalPosition;
273 std::string processName;
279 static std::atomic<int> globalHitCounter;
288 static thread_local std::map<int, G4ThreeVector> trackVertexById;
299 [[nodiscard]]
inline std::vector<double>
getEdeps()
const {
return edeps; }
305 [[nodiscard]]
inline std::vector<double>
getTimes()
const {
return times; }
311 [[nodiscard]]
inline std::vector<G4ThreeVector>
getGlobalPositions()
const {
return globalPositions; }
317 [[nodiscard]]
inline std::vector<G4ThreeVector>
getLocalPositions()
const {
return localPositions; }
338 return motherTrackVertexPositions;
348 return motherTrackVertexPositions.front();
355 [[nodiscard]]
inline std::vector<int>
getPids()
const {
return pids; }
363 [[nodiscard]]
inline int getPid()
const {
return pids.front(); }
369 [[nodiscard]]
inline std::vector<int>
getTids()
const {
return tids; }
377 [[nodiscard]]
inline int getTid()
const {
return tids.front(); }
383 [[nodiscard]]
inline std::vector<int>
getMotherTids()
const {
return motherTids; }
391 [[nodiscard]]
inline int getMotherTid()
const {
return motherTids.front(); }
401 [[nodiscard]]
inline double getE()
const {
return trackEs.front(); }
407 [[nodiscard]]
inline size_t nsteps()
const {
return edeps.size(); }
413 [[nodiscard]]
inline size_t getStepCount()
const {
return edeps.size(); }
419 [[nodiscard]]
inline std::vector<G4ThreeVector>
getMomenta()
const {
return momenta; }
427 [[nodiscard]]
inline G4ThreeVector
getMomentum()
const {
return momenta.front(); }
433 [[nodiscard]]
inline std::vector<double>
getTrackEs()
const {
return trackEs; }
441 [[nodiscard]]
inline double getTrackE()
const {
return trackEs.front(); }
447 [[nodiscard]]
inline std::vector<int>
getMotherPids()
const {
return motherPids; }
455 [[nodiscard]]
inline int getMpid()
const {
return motherPids.front(); }
463 [[nodiscard]]
inline std::string
getProcID()
const {
return processName; }
483 [[nodiscard]]
inline std::vector<GIdentifier>
getGID()
const {
return gtouchable->getIdentity(); }
583 [[nodiscard]] std::vector<int>
getTTID()
const;
596 static GHit*
create(
const std::shared_ptr<GOptions>& gopts) {
598 auto hit =
new GHit(gt);
600 hit->randomizeHitForTesting(1 + globalHitCounter.fetch_add(1, std::memory_order_relaxed) % 10);
610inline void* GHit::operator
new(size_t) {
615inline void GHit::operator
delete(
void* hit) {
623 std::string identifierString;
624 for (
size_t i = 0; i < gidentity.size() - 1; i++) {
625 identifierString += gidentity[i].getName() +
"->" + std::to_string(gidentity[i].getValue()) +
", ";
627 identifierString += gidentity.back().getName() +
"->" + std::to_string(gidentity.back().getValue());
628 return identifierString;
631[[nodiscard]]
inline std::map<std::string, int>
getIdentityMap(std::vector<GIdentifier> gidentity) {
632 std::map<std::string, int> identityMap;
633 for (
auto&
id : gidentity) {
634 identityMap[
id.getName()] =
id.getValue();
Stores step-by-step and aggregated information for a detector hit.
size_t getStepCount() const
Number of recorded steps (same as nsteps()).
std::vector< int > getPids() const
Get per-step particle PDG encodings (when enabled).
int getPid() const
Convenience accessor for the first particle ID.
static void clearTrackVertexCache()
Clear the per-thread track vertex cache.
G4ThreeVector getMomentum() const
Convenience accessor for the first step 3-momentum.
std::vector< int > getMotherTids() const
Get per-step mother track IDs.
std::vector< G4ThreeVector > getMotherTrackVertexPositions() const
Get per-step mother-track vertex positions.
size_t nsteps() const
Number of recorded steps.
G4ThreeVector getMotherTrackVertexPosition() const
Convenience accessor for the first mother-track vertex position.
int getMotherTid() const
Convenience accessor for the first mother track ID.
std::string getProcID() const
Get the representative creator process name for this hit.
std::vector< double > getTimes() const
Get per-step global times.
std::vector< double > getTrackEs() const
Get per-step track total energies (always present).
std::vector< GIdentifier > getGID() const
Get the detector element identity.
~GHit() override=default
Destructor.
static GHit * create(const std::shared_ptr< GOptions > &gopts)
Create a fake hit for testing, using the current options.
std::vector< G4ThreeVector > getLocalPositions() const
Get per-step local positions.
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.
std::vector< G4ThreeVector > getTrackVertexPositions() const
Get per-step current-track vertex positions.
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 calculateInfos()
Compute and cache derived hit quantities.
std::vector< double > getDetectorDimensions() const
Get the sensitive-element dimensions.
std::vector< int > getMotherPids() const
Get per-step mother particle PDG encodings (always present).
void Draw() override
Visualize the hit using Geant4 visualization primitives.
int getMpid() const
Convenience accessor for the first step mother particle PDG encoding.
std::vector< G4ThreeVector > getMomenta() const
Get per-step track 3-momenta (always present).
G4ThreeVector getAvgGlobaPosition()
Get the average global position of the hit.
std::vector< double > getEdeps() const
Get per-step energy depositions.
double getTotalEnergyDeposited()
Get the total deposited energy across all recorded steps.
std::shared_ptr< GTouchable > getGTouchable() const
Get the associated sensitive-element descriptor.
double getAverageTime()
Get the average time associated with the hit.
double getTrackE() const
Convenience accessor for the first step track total energy.
double getMass() const
Get the sensitive element mass.
G4ThreeVector getTrackVertexPosition() const
Convenience accessor for the first current-track vertex position.
G4ThreeVector getAvgLocalPosition()
Get the average local position of the hit.
int getTid() const
Convenience accessor for the first track ID.
double getE() const
Convenience accessor for the first step track total energy.
std::vector< G4ThreeVector > getGlobalPositions() const
Get per-step global positions.
std::string getProcessName() const
Get the representative creator process name for the hit.
void addHitInfos(const G4Step *thisStep)
Append per-step information from a G4Step.
std::vector< int > getTids() const
Get per-step particle track id (when enabled).
static std::shared_ptr< GTouchable > create(const std::shared_ptr< GOptions > &gopt)
std::string getIdentityString(std::vector< GIdentifier > gidentity)
G4ThreadLocal G4Allocator< GHit > * GHitAllocator
std::map< std::string, int > getIdentityMap(std::vector< GIdentifier > gidentity)
G4THitsCollection< GHit > GHitsCollection