DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
dd4hep::sim::Geant4HitCollection Class Reference

Generic hit container class using Geant4HitWrapper objects. More...

#include <Geant4HitCollection.h>

Inheritance diagram for dd4hep::sim::Geant4HitCollection:
G4VHitsCollection

Classes

union  CollectionFlags
 Union defining the hit collection flags for processing. More...
 
class  Compare
 Generic class template to compare/select hits in Geant4HitCollection objects. More...
 

Public Types

enum  OptimizationFlags { OPTIMIZE_NONE = 0, OPTIMIZE_REPEATEDLOOKUP = 1<<0, OPTIMIZE_MAPPEDLOOKUP = 1<<1, OPTIMIZE_LAST }
 Enumeration for collection optimization types. More...
 
typedef std::vector< Geant4HitWrapperWrappedHits
 Hit wrapper. More...
 
typedef Geant4HitWrapper::HitManipulator Manip
 Hit manipulator. More...
 
typedef std::map< VolumeID, size_t > Keys
 Hit key map for fast random lookup. More...
 

Public Member Functions

template<typename TYPE >
 Geant4HitCollection (const std::string &det, const std::string &coll, Geant4Sensitive *sd)
 Initializing constructor (C++ version) More...
 
template<typename TYPE >
 Geant4HitCollection (const std::string &det, const std::string &coll, Geant4Sensitive *sd, const TYPE *)
 Initializing constructor. More...
 
virtual ~Geant4HitCollection ()
 Default destructor. More...
 
const ComponentCast & type () const
 Type information of the object stored. More...
 
const ComponentCast & vector_type () const
 Type information of the vector type for extracting data. More...
 
virtual void clear ()
 Clear the collection (Deletes all valid references to real hits) More...
 
void setOptimize (int flag)
 Set optimization flags. More...
 
void setSensitive (Geant4Sensitive *detector)
 Set the sensitive detector. More...
 
Geant4Sensitivesensitive () const
 Access the sensitive detector. More...
 
virtual G4VHitGetHit (size_t which) const override
 Access individual hits. More...
 
virtual size_t GetSize () const override
 Access the collection size. More...
 
Geant4HitWrapperhit (size_t which)
 Access the hit wrapper. More...
 
const Geant4HitWrapperhit (size_t which) const
 Access the hit wrapper (CONST) More...
 
template<typename TYPE >
void add (TYPE *hit_pointer)
 Add a new hit with a check, that the hit is of the same type. More...
 
template<typename TYPE >
void add (VolumeID key, TYPE *hit_pointer)
 Add a new hit with a check, that the hit is of the same type. More...
 
template<typename TYPE >
TYPE * find (const Compare &cmp)
 Find hits in a collection by comparison of attributes. More...
 
template<typename TYPE >
TYPE * findByKey (VolumeID key)
 Find hits in a collection by comparison of key value. More...
 
template<typename TYPE >
std::vector< TYPE * > releaseHits ()
 Release all hits from the Geant4 container and pass ownership to the caller. More...
 
void releaseHitsUnchecked (std::vector< void * > &result)
 Release all hits from the Geant4 container and pass ownership to the caller. More...
 
template<typename TYPE >
std::vector< TYPE * > getHits ()
 Release all hits from the Geant4 container. Ownership stays with the container. More...
 
void getHitsUnchecked (std::vector< void * > &result)
 Release all hits from the Geant4 container. Ownership stays with the container. More...
 

Protected Member Functions

void newInstance ()
 Notification to increase the instance counter. More...
 
void * findHit (const Compare &cmp)
 Find hit in a collection by comparison of attributes. More...
 
Geant4HitWrapperfindHitByKey (VolumeID key)
 Find hit in a collection by comparison of the key. More...
 
void releaseData (const ComponentCast &cast, std::vector< void * > *result)
 Release all hits from the Geant4 container and pass ownership to the caller. More...
 
void getData (const ComponentCast &cast, std::vector< void * > *result)
 Release all hits from the Geant4 container. Ownership stays with the container. More...
 

Protected Attributes

WrappedHits m_hits
 The collection of hit pointers in the wrapped format. More...
 
Geant4Sensitivem_detector
 Handle to the sensitive detector. More...
 
Manipm_manipulator
 The type of the objects in this collection. Set by the constructor. More...
 
size_t m_lastHit
 Memorize for speedup the last searched hit. More...
 
Keys m_keys
 Hit key map for fast random lookup. More...
 
CollectionFlags m_flags
 Optimization flags. More...
 

Detailed Description

Generic hit container class using Geant4HitWrapper objects.

Opaque hit collection. This hit collection is for good reasons homomorph, Polymorphism without an explicit type would only confuse most users.

Note: This hit collection is optimized to search repeatedly the same cell using

template <typename TYPE> TYPE* find(const Compare& cmp) const;

by remembering the last search index. The collection uses this optimization if the corresponding flag OPTIMIZE_REPEATEDLOOKUP is set:

setOptimize(OPTIMIZE_REPEATEDLOOKUP);

The last search index is automatically set to last object insertion, if one happened between 2 search calls. For the typical use case, there always contributions to the same hit are added, this should reduce the lookup speed from O(n) to O(1). This obviously only helps, if contributions to the same cell come in sequence ie. from the same G4Track.

Author
M.Frank
Version
1.0

Definition at line 201 of file Geant4HitCollection.h.

Member Typedef Documentation

◆ Keys

Hit key map for fast random lookup.

Definition at line 209 of file Geant4HitCollection.h.

◆ Manip

Hit manipulator.

Definition at line 207 of file Geant4HitCollection.h.

◆ WrappedHits

Hit wrapper.

Local type declarations

Definition at line 205 of file Geant4HitCollection.h.

Member Enumeration Documentation

◆ OptimizationFlags

Enumeration for collection optimization types.

Enumerator
OPTIMIZE_NONE 
OPTIMIZE_REPEATEDLOOKUP 
OPTIMIZE_MAPPEDLOOKUP 
OPTIMIZE_LAST 

Definition at line 267 of file Geant4HitCollection.h.

Constructor & Destructor Documentation

◆ Geant4HitCollection() [1/2]

template<typename TYPE >
dd4hep::sim::Geant4HitCollection::Geant4HitCollection ( const std::string &  det,
const std::string &  coll,
Geant4Sensitive sd 
)
inline

Initializing constructor (C++ version)

Definition at line 276 of file Geant4HitCollection.h.

◆ Geant4HitCollection() [2/2]

template<typename TYPE >
dd4hep::sim::Geant4HitCollection::Geant4HitCollection ( const std::string &  det,
const std::string &  coll,
Geant4Sensitive sd,
const TYPE *   
)
inline

Initializing constructor.

Definition at line 287 of file Geant4HitCollection.h.

◆ ~Geant4HitCollection()

Geant4HitCollection::~Geant4HitCollection ( )
virtual

Default destructor.

Definition at line 80 of file Geant4HitCollection.cpp.

Member Function Documentation

◆ add() [1/2]

template<typename TYPE >
void dd4hep::sim::Geant4HitCollection::add ( TYPE *  hit_pointer)
inline

Add a new hit with a check, that the hit is of the same type.

Definition at line 333 of file Geant4HitCollection.h.

◆ add() [2/2]

template<typename TYPE >
void dd4hep::sim::Geant4HitCollection::add ( VolumeID  key,
TYPE *  hit_pointer 
)
inline

Add a new hit with a check, that the hit is of the same type.

Definition at line 339 of file Geant4HitCollection.h.

◆ clear()

void Geant4HitCollection::clear ( )
virtual

Clear the collection (Deletes all valid references to real hits)

Definition at line 102 of file Geant4HitCollection.cpp.

◆ find()

template<typename TYPE >
TYPE* dd4hep::sim::Geant4HitCollection::find ( const Compare cmp)
inline

Find hits in a collection by comparison of attributes.

Definition at line 350 of file Geant4HitCollection.h.

◆ findByKey()

template<typename TYPE >
TYPE* dd4hep::sim::Geant4HitCollection::findByKey ( VolumeID  key)
inline

Find hits in a collection by comparison of key value.

Definition at line 354 of file Geant4HitCollection.h.

◆ findHit()

void * Geant4HitCollection::findHit ( const Compare cmp)
protected

Find hit in a collection by comparison of attributes.

Definition at line 109 of file Geant4HitCollection.cpp.

◆ findHitByKey()

Geant4HitWrapper * Geant4HitCollection::findHitByKey ( VolumeID  key)
protected

Find hit in a collection by comparison of the key.

Definition at line 125 of file Geant4HitCollection.cpp.

◆ getData()

void Geant4HitCollection::getData ( const ComponentCast &  cast,
std::vector< void * > *  result 
)
protected

Release all hits from the Geant4 container. Ownership stays with the container.

Definition at line 148 of file Geant4HitCollection.cpp.

◆ GetHit()

virtual G4VHit* dd4hep::sim::Geant4HitCollection::GetHit ( size_t  which) const
inlineoverridevirtual

Access individual hits.

Definition at line 317 of file Geant4HitCollection.h.

◆ getHits()

template<typename TYPE >
std::vector<TYPE*> dd4hep::sim::Geant4HitCollection::getHits ( )
inline

Release all hits from the Geant4 container. Ownership stays with the container.

Definition at line 375 of file Geant4HitCollection.h.

◆ getHitsUnchecked()

void Geant4HitCollection::getHitsUnchecked ( std::vector< void * > &  result)

Release all hits from the Geant4 container. Ownership stays with the container.

Definition at line 172 of file Geant4HitCollection.cpp.

◆ GetSize()

virtual size_t dd4hep::sim::Geant4HitCollection::GetSize ( ) const
inlineoverridevirtual

Access the collection size.

Definition at line 321 of file Geant4HitCollection.h.

◆ hit() [1/2]

Geant4HitWrapper& dd4hep::sim::Geant4HitCollection::hit ( size_t  which)
inline

Access the hit wrapper.

Definition at line 325 of file Geant4HitCollection.h.

◆ hit() [2/2]

const Geant4HitWrapper& dd4hep::sim::Geant4HitCollection::hit ( size_t  which) const
inline

Access the hit wrapper (CONST)

Definition at line 329 of file Geant4HitCollection.h.

◆ newInstance()

void Geant4HitCollection::newInstance ( )
protected

Notification to increase the instance counter.

Definition at line 97 of file Geant4HitCollection.cpp.

◆ releaseData()

void Geant4HitCollection::releaseData ( const ComponentCast &  cast,
std::vector< void * > *  result 
)
protected

Release all hits from the Geant4 container and pass ownership to the caller.

Definition at line 133 of file Geant4HitCollection.cpp.

◆ releaseHits()

template<typename TYPE >
std::vector<TYPE*> dd4hep::sim::Geant4HitCollection::releaseHits ( )
inline

Release all hits from the Geant4 container and pass ownership to the caller.

Definition at line 362 of file Geant4HitCollection.h.

◆ releaseHitsUnchecked()

void Geant4HitCollection::releaseHitsUnchecked ( std::vector< void * > &  result)

Release all hits from the Geant4 container and pass ownership to the caller.

Definition at line 161 of file Geant4HitCollection.cpp.

◆ sensitive()

Geant4Sensitive* dd4hep::sim::Geant4HitCollection::sensitive ( ) const
inline

Access the sensitive detector.

Definition at line 313 of file Geant4HitCollection.h.

◆ setOptimize()

void dd4hep::sim::Geant4HitCollection::setOptimize ( int  flag)
inline

Set optimization flags.

Definition at line 305 of file Geant4HitCollection.h.

◆ setSensitive()

void dd4hep::sim::Geant4HitCollection::setSensitive ( Geant4Sensitive detector)
inline

Set the sensitive detector.

Definition at line 309 of file Geant4HitCollection.h.

◆ type()

const dd4hep::ComponentCast & Geant4HitCollection::type ( ) const

Type information of the object stored.

Definition at line 87 of file Geant4HitCollection.cpp.

◆ vector_type()

const dd4hep::ComponentCast & Geant4HitCollection::vector_type ( ) const

Type information of the vector type for extracting data.

Definition at line 92 of file Geant4HitCollection.cpp.

Member Data Documentation

◆ m_detector

Geant4Sensitive* dd4hep::sim::Geant4HitCollection::m_detector
protected

Handle to the sensitive detector.

Definition at line 243 of file Geant4HitCollection.h.

◆ m_flags

CollectionFlags dd4hep::sim::Geant4HitCollection::m_flags
protected

Optimization flags.

Definition at line 251 of file Geant4HitCollection.h.

◆ m_hits

WrappedHits dd4hep::sim::Geant4HitCollection::m_hits
protected

The collection of hit pointers in the wrapped format.

Definition at line 241 of file Geant4HitCollection.h.

◆ m_keys

Keys dd4hep::sim::Geant4HitCollection::m_keys
protected

Hit key map for fast random lookup.

Definition at line 249 of file Geant4HitCollection.h.

◆ m_lastHit

size_t dd4hep::sim::Geant4HitCollection::m_lastHit
protected

Memorize for speedup the last searched hit.

Definition at line 247 of file Geant4HitCollection.h.

◆ m_manipulator

Manip* dd4hep::sim::Geant4HitCollection::m_manipulator
protected

The type of the objects in this collection. Set by the constructor.

Definition at line 245 of file Geant4HitCollection.h.


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