ghit
Loading...
Searching...
No Matches

Stores step-by-step and aggregated information for a detector hit. More...

#include <ghit.h>

Data Structures

struct  MotherInfo

Public Member Functions

 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.
 ~GHit () override=default
 Destructor.
void * operator new (size_t)
 Allocate a GHit via the G4Allocator associated with this type.
void operator delete (void *)
 Deallocate a GHit via the G4Allocator associated with this type.
void Draw () override
 Visualize the hit using Geant4 visualization primitives.
bool is_same_hit (const GHit *hit) const
 Compare this hit against another hit by sensitive-element identity.
std::vector< double > getEdeps () const
 Get per-step energy depositions.
std::vector< double > getTimes () const
 Get per-step global times.
std::vector< G4ThreeVector > getGlobalPositions () const
 Get per-step global positions.
std::vector< G4ThreeVector > getLocalPositions () const
 Get per-step local positions.
std::vector< G4ThreeVector > getTrackVertexPositions () const
 Get per-step current-track vertex positions.
G4ThreeVector getTrackVertexPosition () const
 Convenience accessor for the first current-track vertex position.
const std::vector< MotherInfo > & getMotherInfos () const
const MotherInfogetMotherInfo () const
std::vector< int > getPids () const
 Get per-step particle PDG encodings (when enabled).
int getPid () const
 Convenience accessor for the first particle ID.
std::vector< int > getTids () const
 Get per-step particle track id (when enabled).
int getTid () const
 Convenience accessor for the first track ID.
double getE () const
 Convenience accessor for the first step track total energy.
size_t nsteps () const
 Number of recorded steps.
size_t getStepCount () const
 Number of recorded steps (same as nsteps()).
size_t getNumberOfOpticalPhotons () const
 Count distinct optical-photon tracks recorded in this hit.
std::vector< G4ThreeVector > getMomenta () const
 Get per-step track 3-momenta (always present).
G4ThreeVector getMomentum () const
 Convenience accessor for the first step 3-momentum.
std::vector< double > getTrackEs () const
 Get per-step track total energies (always present).
double getTrackE () const
 Convenience accessor for the first step track total energy.
const std::optional< std::string > & getProcessName () const
 Get the representative creator process name for the hit.
std::shared_ptr< GTouchablegetGTouchable () const
 Get the associated sensitive-element descriptor.
std::vector< GIdentifiergetGID () const
 Get the detector element identity.
std::vector< double > getDetectorDimensions () const
 Get the sensitive-element dimensions.
double getMass () const
 Get the sensitive element mass.
double getTotalEnergyDeposited () const
 Get the total deposited energy across all recorded steps.
double getAverageTime () const
 Get the average time associated with the hit.
G4ThreeVector getAvgLocalPosition () const
 Get the average local position of the hit.
G4ThreeVector getAvgGlobalPosition () const
 Get the average global position of the hit.
void addHitInfos (const G4Step *thisStep)
 Append per-step information from a G4Step.
void randomizeHitForTesting (int nsteps)
 Randomize internal vectors for test-only usage.
std::vector< int > getTTID () const
 Get the touchable identity values as integers.

Static Public Member Functions

static void clearTrackVertexCache ()
 Clear the per-thread track vertex cache.
static GHitcreate (const std::shared_ptr< GOptions > &gopts)
 Create a fake hit for testing, using the current options.

Detailed Description

A GHit is a G4VHit that accumulates per-step quantities while a track traverses a sensitive detector element and deposits energy.

Conceptually, this class has two layers of information:

  • Per-step vectors: always-collected quantities (energy deposition, time, local/global positions, track identity, momentum, and creator process).
  • Aggregated quantities: totals/averages (e.g., total energy deposited, average time, average positions, representative process name) computed lazily from the per-step vectors.
Note
This class does not own the sensitive-element description. The associated GTouchable is stored as a std::shared_ptr so that the hit can be compared against other hits and can query identity/dimensions.

Definition at line 37 of file ghit.h.

Constructor & Destructor Documentation

◆ GHit()

GHit::GHit ( std::shared_ptr< GTouchable > gt,
const G4Step * thisStep = nullptr,
const std::string & cScheme = "default" )

This constructor initializes the hit bookkeeping and, if thisStep is not null, immediately records per-step information for that step.

Parameters
gtPointer to the GTouchable describing the sensitive element producing the hit.
thisStepOptional G4Step used to seed the hit with an initial step record (default: null).
cSchemeVisualization color scheme name (default: "default"). The current implementation uses a simple hard-coded scheme but keeps this field for future expansion.

Definition at line 36 of file ghit.cc.

◆ ~GHit()

GHit::~GHit ( )
overridedefault

Member Function Documentation

◆ addHitInfos()

void GHit::addHitInfos ( const G4Step * thisStep)

Records global and local positions, energy deposited, time, track identity, momentum, total energy, mother-particle PDG, and creator process name.

Parameters
thisStepStep to extract per-step values from (must not be null).

Definition at line 9 of file addHitInfos.cc.

◆ clearTrackVertexCache()

void GHit::clearTrackVertexCache ( )
static

Called at the beginning of each sensitive-detector event.

Definition at line 116 of file ghit.cc.

◆ create()

GHit * GHit::create ( const std::shared_ptr< GOptions > & gopts)
inlinestatic

Builds a test touchable via GTouchable::create(gopts), constructs a hit with no initial step, and randomizes its contents using randomizeHitForTesting().

Parameters
goptsOptions object used to create the test GTouchable.
Returns
Newly allocated GHit pointer. Ownership is transferred to the caller.
Warning
The returned pointer must be deleted by the caller.

Definition at line 523 of file ghit.h.

◆ Draw()

void GHit::Draw ( )
override

This draws a circle at the first recorded global position and selects visual attributes based on the particle type and total energy deposited. Optical-photon hits are always shown as small green markers.

Note
If no visualization manager is available, or if the hit has no recorded positions, the method returns without performing any drawing.

Definition at line 65 of file ghit.cc.

◆ getAverageTime()

double GHit::getAverageTime ( ) const
nodiscard
Returns
The energy-weighted average of the time if total deposited energy is non-zero, otherwise a simple arithmetic average.
Note
Requesting any derived value calculates and caches the complete derived state.

Definition at line 40 of file calculations.cc.

◆ getAvgGlobalPosition()

G4ThreeVector GHit::getAvgGlobalPosition ( ) const
nodiscard
Returns
The averaged global position energy-weighted if possible.

Definition at line 44 of file calculations.cc.

◆ getAvgLocalPosition()

G4ThreeVector GHit::getAvgLocalPosition ( ) const
nodiscard
Returns
The averaged local position, energy-weighted if possible.

Definition at line 48 of file calculations.cc.

◆ getDetectorDimensions()

std::vector< double > GHit::getDetectorDimensions ( ) const
inlinenodiscard
Returns
A vector of doubles representing the element dimensions.
Note
This forwards to GTouchable::getDetectorDimensions().

Definition at line 427 of file ghit.h.

◆ getE()

double GHit::getE ( ) const
inlinenodiscard

Alias for getTrackE() kept for API compatibility with existing digitization plugins.

Returns
The first recorded track total energy (MeV).
Warning
This assumes the internal trackEs vector is non-empty.

Definition at line 349 of file ghit.h.

◆ getEdeps()

std::vector< double > GHit::getEdeps ( ) const
inlinenodiscard
Returns
A copy of the vector of per-step deposited energies.

Definition at line 271 of file ghit.h.

◆ getGID()

std::vector< GIdentifier > GHit::getGID ( ) const
inlinenodiscard
Returns
A vector of GIdentifier describing the sensitive-element identity.
Note
This forwards to GTouchable::getIdentity().

Definition at line 419 of file ghit.h.

◆ getGlobalPositions()

std::vector< G4ThreeVector > GHit::getGlobalPositions ( ) const
inlinenodiscard
Returns
A copy of the vector of per-step global positions.

Definition at line 283 of file ghit.h.

◆ getGTouchable()

std::shared_ptr< GTouchable > GHit::getGTouchable ( ) const
inlinenodiscard
Returns
A copy of the std::shared_ptr managing the GTouchable.

Definition at line 411 of file ghit.h.

◆ getLocalPositions()

std::vector< G4ThreeVector > GHit::getLocalPositions ( ) const
inlinenodiscard
Returns
A copy of the vector of per-step local positions.

Definition at line 289 of file ghit.h.

◆ getMass()

double GHit::getMass ( ) const
inlinenodiscard
Returns
A double with the mass value

Definition at line 435 of file ghit.h.

◆ getMomenta()

std::vector< G4ThreeVector > GHit::getMomenta ( ) const
inlinenodiscard
Returns
A copy of the vector of per-step momenta.

Definition at line 377 of file ghit.h.

◆ getMomentum()

G4ThreeVector GHit::getMomentum ( ) const
inlinenodiscard
Returns
The first recorded track momentum.
Warning
This assumes the internal momenta vector is non-empty.

Definition at line 385 of file ghit.h.

◆ getMotherInfo()

const MotherInfo & GHit::getMotherInfo ( ) const
inlinenodiscard

Return the mother record associated with the first step.

Definition at line 311 of file ghit.h.

◆ getMotherInfos()

const std::vector< MotherInfo > & GHit::getMotherInfos ( ) const
inlinenodiscard

Return all per-step mother records.

Definition at line 308 of file ghit.h.

◆ getNumberOfOpticalPhotons()

size_t GHit::getNumberOfOpticalPhotons ( ) const
nodiscard

A photon can contribute more than one Geant4 step, so the count is based on unique track IDs rather than the number of stored steps.

Returns
Number of unique optical-photon track IDs in the hit.

Definition at line 98 of file ghit.cc.

◆ getPid()

int GHit::getPid ( ) const
inlinenodiscard
Returns
The first particle ID.
Warning
This assumes the internal pids vector is non-empty.

Definition at line 325 of file ghit.h.

◆ getPids()

std::vector< int > GHit::getPids ( ) const
inlinenodiscard
Returns
A copy of the vector of per-step particle IDs.

Definition at line 317 of file ghit.h.

◆ getProcessName()

const std::optional< std::string > & GHit::getProcessName ( ) const
nodiscard
Returns
The first recorded process name, or std::nullopt when no creator process was recorded.

Definition at line 52 of file calculations.cc.

◆ getStepCount()

size_t GHit::getStepCount ( ) const
inlinenodiscard
Returns
The size of the edeps vector.

Definition at line 361 of file ghit.h.

◆ getTid()

int GHit::getTid ( ) const
inlinenodiscard
Returns
The first particle ID.
Warning
This assumes the internal track vector is non-empty.

Definition at line 339 of file ghit.h.

◆ getTids()

std::vector< int > GHit::getTids ( ) const
inlinenodiscard
Returns
A copy of the vector of per-step track IDs.

Definition at line 331 of file ghit.h.

◆ getTimes()

std::vector< double > GHit::getTimes ( ) const
inlinenodiscard
Returns
A copy of the vector of per-step times.

Definition at line 277 of file ghit.h.

◆ getTotalEnergyDeposited()

double GHit::getTotalEnergyDeposited ( ) const
nodiscard
Returns
The summed energy deposition.

This method caches the result the first time it is called.

Definition at line 36 of file calculations.cc.

◆ getTrackE()

double GHit::getTrackE ( ) const
inlinenodiscard
Returns
The first recorded track total energy (MeV).
Warning
This assumes the internal trackEs vector is non-empty.

Definition at line 399 of file ghit.h.

◆ getTrackEs()

std::vector< double > GHit::getTrackEs ( ) const
inlinenodiscard
Returns
A copy of the vector of per-step track total energies (MeV).

Definition at line 391 of file ghit.h.

◆ getTrackVertexPosition()

G4ThreeVector GHit::getTrackVertexPosition ( ) const
inlinenodiscard
Returns
The first track vertex position.
Warning
This assumes the internal trackVertexPositions vector is non-empty.

Definition at line 305 of file ghit.h.

◆ getTrackVertexPositions()

std::vector< G4ThreeVector > GHit::getTrackVertexPositions ( ) const
inlinenodiscard
Returns
A copy of the vector of track vertex positions.

Definition at line 295 of file ghit.h.

◆ getTTID()

vector< int > GHit::getTTID ( ) const
nodiscard

Converts each GIdentifier returned by getGID() into its integer value.

Returns
Vector of integer identity values (one per identifier component).

Definition at line 53 of file ghit.cc.

◆ is_same_hit()

bool GHit::is_same_hit ( const GHit * hit) const
nodiscard

Two hits are considered the "same" if their associated GTouchable objects compare equal (i.e. they refer to the same detector element identity according to GTouchable equality).

Parameters
hitPointer to the candidate hit to compare against (may be null).
Returns
True if hit is not null and the associated GTouchable matches.

Definition at line 46 of file ghit.cc.

◆ nsteps()

size_t GHit::nsteps ( ) const
inlinenodiscard
Returns
The size of the edeps vector, which is always populated.

Definition at line 355 of file ghit.h.

◆ operator delete()

void GHit::operator delete ( void * hit)
inline

Definition at line 542 of file ghit.h.

◆ operator new()

void * GHit::operator new ( size_t )
inline
Returns
Pointer to the allocated storage.
Note
The allocator is thread-local (see GHitAllocator below).

Definition at line 537 of file ghit.h.

◆ randomizeHitForTesting()

void GHit::randomizeHitForTesting ( int nsteps)

Fills vectors with pseudo-random positions, times, energies, and particle IDs.

Parameters
nstepsNumber of pseudo-random steps to generate.
Warning
This is intended only for unit tests / examples. Do not use in production.

Definition at line 121 of file ghit.cc.


The documentation for this class was generated from the following files: