Belle II Software  release-05-02-19
SensitiveDetector< SimHitClass, TrueHitClass > Class Template Reference

Sensitive Detector implementation of PXD and SVD. More...

#include <SensitiveDetector.h>

Inheritance diagram for SensitiveDetector< SimHitClass, TrueHitClass >:
Collaboration diagram for SensitiveDetector< SimHitClass, TrueHitClass >:

Public Member Functions

 SensitiveDetector (VXD::SensorInfoBase *sensorInfo)
 Construct instance and take over ownership of the sensorInfo pointer.
 
void setOptions (bool seeNeutrons, bool onlyPrimaryTrueHits, float distanceTolerance, float electronTolerance, float minimumElectrons)
 Set all common options. More...
 
SensorInfoBasegetSensorInfo ()
 Return a pointer to the SensorInfo associated with this instance.
 
VxdID getSensorID () const
 Return the VxdID belonging to this sensitive detector.
 

Static Public Member Functions

static const std::map< std::string, RelationArray::EConsolidationAction > & getMCParticleRelations ()
 Return a list of all registered Relations with MCParticles.
 
static void setActive (bool activeStatus)
 Enable/Disable all Sensitive Detectors. More...
 
static void registerMCParticleRelation (const std::string &name, RelationArray::EConsolidationAction ignoreAction=RelationArray::c_negativeWeight)
 Register an relation involving MCParticles. More...
 
static void registerMCParticleRelation (const RelationArray &relation, RelationArray::EConsolidationAction ignoreAction=RelationArray::c_negativeWeight)
 Overload to make it easer to register MCParticle relations. More...
 

Protected Member Functions

std::vector< unsigned int > simplifyEnergyDeposit (const SensorTraversal::range &points)
 Simplify the energy deposition profile using Douglas-Peuker-Algorithm We normally force a Geant4 step after 5µm but energy deposition does not necessarily vary much between these short steps. More...
 
StepInformation findMidPoint (const SensorTraversal &traversal)
 Find the mid-point of the track traversal. More...
 

Private Member Functions

int saveTrueHit (const SensorTraversal &traversal) override
 Save the actual TrueHit for a given sensor traversal information. More...
 
int saveSimHit (const SensorTraversal &traversal, const SensorTraversal::range &points) override
 Save a SimHit for a track along the given points. More...
 
void saveRelations (const SensorTraversal &traversal, int trueHitIndex, std::vector< std::pair< unsigned int, float >> simHitIndices) override
 Save the relations between MCParticle, TrueHit and SimHits. More...
 
std::array< float, 3 > vecToFloat (const G4ThreeVector &vec)
 Convert G4ThreeVector (aka Hep3Vector) to float array to store in TrueHit/SimHit classes. More...
 
bool step (G4Step *step, G4TouchableHistory *) override
 Process a single Geant4 Step. More...
 
bool finishTrack ()
 Process a track once all steps are known. More...
 
std::vector< std::pair< unsigned int, float > > createSimHits ()
 Determine which SimHits to create. More...
 
virtual bool ProcessHits (G4Step *aStep, G4TouchableHistory *aROhist)
 Check if recording hits is enabled and if so call step() and set the correct MCParticle flag. More...
 

Private Attributes

StoreArray< SimHitClass > m_simhits
 StoreArray for the SimHits.
 
StoreArray< TrueHitClass > m_truehits
 StoreArray for the TrueHits.
 
StoreArray< MCParticlem_mcparticles
 StoreArray for the MCParticles, needed by relations.
 
RelationArray m_relMCSimHits {m_mcparticles, m_simhits}
 Relation between MCParticle and SimHits.
 
RelationArray m_relMCTrueHits {m_mcparticles, m_truehits}
 Relation between MCParticle and TrueHits.
 
RelationArray m_relTrueSimHits {m_truehits, m_simhits}
 Relation between TrueHits and SimHits.
 
SensorInfoBasem_info {0}
 Pointer to the SensorInfo associated with this instance.
 
std::stack< SensorTraversalm_tracks
 stack of SensorTraversal information for all tracks not finished so far
 
float m_distanceTolerance {0}
 maximum distance between step point and linear interpolation of sensor traversal before a new simhit object is created
 
float m_electronTolerance {0}
 maximum relative difference between electron density of two steps where they can be considered similar enough to be merged
 
float m_minimumElectrons {0}
 minimum number of electrons a track must deposit for SimHit/TrueHits to be created
 
bool m_seeNeutrons {false}
 also create SimHit/TrueHit objects for neutrons (or charged particles which deposit less than m_minimumElectrons electrons
 
bool m_onlyPrimaryTrueHits {false}
 only create TrueHits for primary particles
 
Const::EDetector m_subdetector
 Subdetector the class belongs to.
 

Static Private Attributes

static std::map< std::string, RelationArray::EConsolidationActions_mcRelations
 Static set holding all relations which have to be updated at the end of the Event.
 
static bool s_active
 Static bool which indicates wether recording of hits is enabled.
 

Detailed Description

template<class SimHitClass, class TrueHitClass>
class Belle2::VXD::SensitiveDetector< SimHitClass, TrueHitClass >

Sensitive Detector implementation of PXD and SVD.

This class provides the actual implementation of the hit generation for PXD and SVD. It is templated to be able to create the corresponding output collection.

It generates two different kinds of Hits:

  • SimHits which correspond to Geant4 steps inside the sensitive volume. There will be several SimHits per traversal, since the step length of Geant4 is limited to provide detailed information about energy deposition.
  • TrueHits are aggregated objects which store the position where a particle crossed the detector plane (local z=0). There can be only one TrueHit per traversal of one sensor, but there may be more than one TrueHit for curling Tracks. TrueHits also carry information about the particle momenta before and after entering the silicon (or at start/end point if the track started/ended inside the silicon. MODIFIED July 2013 (based largely on suggestions by Martin Ritter):
    1. Every particle that either enters or leaves the sensitive volume and deposits some energy there, will create a TrueHit.
    2. The (u,v,w) position of the TrueHit are the coordinates of the midpoint of the track inside the sensitive volume (rather of the x-ing point with z=0): the w (z) coordinate is added to TrueHits.
    3. Each MC particle entering the sensitive volume will be un-ignored, so that the TrueHits created by secondaries entering the sensitive volume will be attributed to the correct MCParticle (that is, not to its primary ancestor).
    4. SimHit relations to MCParticles that don't produce a TrueHit and get re-attributed (to their primary ancestor) will have negative sign. This concerns the secondaries created inside the sensitive volume that don't reach another sensitive volume.
Template Parameters
SimHitClassClass to use when generating SimHits
TrueHitClassClass to use when generating TrueHits

Definition at line 67 of file SensitiveDetector.h.

Member Function Documentation

◆ createSimHits()

std::vector< std::pair< unsigned int, float > > createSimHits ( )
privateinherited

Determine which SimHits to create.

A SimHit is a linear approximation of the particle trajectory. As such we try to combine as many Geant4 steps as possible by defining a distance tolerance and using the Douglas-Peucker algortihm to determine the required number of SimHits to keep the maximum distance of all Geant4 steps below that tolerance.

Returns
indices and electrons of all created simhits

Definition at line 133 of file SensitiveDetectorBase.cc.

145  {
146  //Get first and last point
147  std::tie(firstPoint, finalPoint) = stack.top();
148  //Remove segment from stack
149  stack.pop();
150  //Direction of the segment
151  const G4ThreeVector n = (finalPoint->position - firstPoint->position).unit();
152  //find largest distance to segment by looping over all intermediate points
153  double maxDistance(0);
154  for (auto nextPoint = firstPoint + 1; nextPoint != finalPoint; ++nextPoint) {
155  //Calculate distances between point p and line segment,
156  //x = a + t*n, where a is a point on the line and n is the unit vector
157  //pointing in line direction. distance = ||(p-a) - ((p-a)*n)*n||
158  const G4ThreeVector pa = nextPoint->position - firstPoint->position;
159  const double dist = (pa - (pa * n) * n).mag();
160  //Update splitpoint if distance is larger then previously known
161  if (dist > maxDistance) {
162  splitPoint = nextPoint;
163  maxDistance = dist;
164  }
165  }
166  //If we are above the tolerance we split the track
167  if (maxDistance > m_distanceTolerance) {
168  //If we split in this order, all created simhits will be in correct
169  //order. That is not a requirement but a nice side effect.
170  stack.push(make_pair(splitPoint, finalPoint));
171  stack.push(make_pair(firstPoint, splitPoint));
172  continue;
173  }
174  //Otherwise we create a SimHit
175  //FIXME: check for m_minimumElectrons?
176  int simHitIndex = saveSimHit(traversal, std::make_pair(firstPoint, finalPoint));
177  simhits.push_back(std::make_pair(simHitIndex, finalPoint->electrons - firstPoint->electrons));
178  }
179  return simhits;
180  }
181 
182  std::vector<unsigned int> SensitiveDetectorBase::simplifyEnergyDeposit(const SensorTraversal::range& points)
183  {
184  //At the end we want a list of points indication how many electrons where
185  //deposited so far along the track, e.g. [(0.5,100), (1.0, 2000)] would
186  //indicate that after half the step length 100 electrons were deposited
187  //and at the end of the step we have 2000 electrons. To save some memory
188  //we encode this information as unsigned int using ElectronDeposit later

◆ findMidPoint()

StepInformation findMidPoint ( const SensorTraversal traversal)
protectedinherited

Find the mid-point of the track traversal.

This function will return the position and momentum at the center of the track traversal, using cubic spline interpolation between the actual geant4 steps. Center is defined as "half the flight length" in this case.

Parameters
traversalinformation on the particle traversal to be used when finding the midpoint
Returns
position and momentum at the mid point

Definition at line 281 of file SensitiveDetectorBase.cc.

◆ finishTrack()

bool finishTrack ( )
privateinherited

Process a track once all steps are known.

This function decides whether TrueHit/SimHits will be saved

Definition at line 102 of file SensitiveDetectorBase.cc.

◆ ProcessHits()

bool ProcessHits ( G4Step *  aStep,
G4TouchableHistory *  aROhist 
)
inlineprivatevirtualinherited

Check if recording hits is enabled and if so call step() and set the correct MCParticle flag.

Called by Geant4 for each step inside the sensitive volumes attached

Definition at line 98 of file SensitiveDetectorBase.h.

◆ registerMCParticleRelation() [1/2]

static void registerMCParticleRelation ( const RelationArray relation,
RelationArray::EConsolidationAction  ignoreAction = RelationArray::c_negativeWeight 
)
inlinestaticinherited

Overload to make it easer to register MCParticle relations.

Parameters
relationRelationArray to register
ignoreAction

Definition at line 70 of file SensitiveDetectorBase.h.

◆ registerMCParticleRelation() [2/2]

void registerMCParticleRelation ( const std::string &  name,
RelationArray::EConsolidationAction  ignoreAction = RelationArray::c_negativeWeight 
)
staticinherited

Register an relation involving MCParticles.

All Relations which point from an MCParticle to something have to be registered with addMCParticleRelation() because the index of the MCParticles might change at the end of the event. During simulation, the TrackID should be used as index of the MCParticle

Parameters
nameName of the relation to register
ignoreAction

Definition at line 24 of file SensitiveDetectorBase.cc.

◆ saveRelations()

void saveRelations ( const SensorTraversal traversal,
int  trueHitIndex,
std::vector< std::pair< unsigned int, float >>  simHitIndices 
)
overrideprivatevirtual

Save the relations between MCParticle, TrueHit and SimHits.

Parameters
traversalinformation on the particle traversal to be used when creating the Relations
trueHitIndexindex of the TrueHit, <0 if no TrueHit was created
simHitIndicesindices of the SimHits along with the number of electrons deposited in each SimHit

Implements SensitiveDetectorBase.

Definition at line 188 of file SensitiveDetector.h.

190  {
191  m_relMCSimHits.add(traversal.getTrackID(), simHitIndices.begin(), simHitIndices.end());
192  //If there is no truehit there are obviously no relations ;)
193  if (trueHitIndex >= 0) {
194  m_relMCTrueHits.add(traversal.getTrackID(), trueHitIndex, traversal.getElectrons());
195  m_relTrueSimHits.add(trueHitIndex, simHitIndices.begin(), simHitIndices.end());
196  }
197  }

◆ saveSimHit()

int saveSimHit ( const SensorTraversal traversal,
const SensorTraversal::range points 
)
overrideprivatevirtual

Save a SimHit for a track along the given points.

Parameters
traversalinformation on the particle traversal to be used when creating the SimHit
pointspair of iterators to the first and last step position to be used for the SimHit
Returns
the index of the created SimHit in its StoreArray

Implements SensitiveDetectorBase.

Definition at line 166 of file SensitiveDetector.h.

◆ saveTrueHit()

int saveTrueHit ( const SensorTraversal traversal)
overrideprivatevirtual

Save the actual TrueHit for a given sensor traversal information.

Parameters
traversalinformation on the particle traversal to be used when creating the TrueHit
Returns
the index of the created TrueHit in its StoreArray

Implements SensitiveDetectorBase.

Definition at line 140 of file SensitiveDetector.h.

◆ setActive()

static void setActive ( bool  activeStatus)
inlinestaticinherited

Enable/Disable all Sensitive Detectors.

By default, all sensitive detectors won't create hits to make it possible to use the Geant4 Navigator for non-simulation purposes. Only during simulation the sensitive detectors will be enabled to record hits

Parameters
activeStatusbool to indicate wether hits should be recorded

Definition at line 54 of file SensitiveDetectorBase.h.

◆ setOptions()

void setOptions ( bool  seeNeutrons,
bool  onlyPrimaryTrueHits,
float  distanceTolerance,
float  electronTolerance,
float  minimumElectrons 
)
inlineinherited

Set all common options.

Parameters
seeNeutronsif true, simhits are also stored for neutrons
onlyPrimaryTrueHitsif true, truehits will only be created for primary particles
distanceTolerancemaximal distance of step position from linear approximation.
electronTolerancemaximum deviation of energy deposition from linear approximation in electrons
minimumElectronsminimum number of electrons to be deposited before SimHits are created.

Definition at line 70 of file SensitiveDetectorBase.h.

74  {
75  if (m_info) delete m_info;
76  }
77 

◆ simplifyEnergyDeposit()

std::vector< unsigned int > simplifyEnergyDeposit ( const SensorTraversal::range points)
protectedinherited

Simplify the energy deposition profile using Douglas-Peuker-Algorithm We normally force a Geant4 step after 5µm but energy deposition does not necessarily vary much between these short steps.

Saving all steps would be a waste of space so we define a tolerance (in electrons) and keep only the points needed so that no point is further away from the profile than this tolerance.

Parameters
pointspair of iterators to the first and last point of the energy deposition profile
Returns
list of encoded EnergyDeposit values representing the simplified energy deposition profile.

Definition at line 190 of file SensitiveDetectorBase.cc.

◆ step()

bool step ( G4Step *  step,
G4TouchableHistory *   
)
overrideprivatevirtualinherited

Process a single Geant4 Step.

This function stores the necessary information to create the TrueHits and SimHits and will call finishTrack() if a track leaves the volume or is stopped inside the volume.

Implements SensitiveDetectorBase.

Definition at line 37 of file SensitiveDetectorBase.cc.

◆ vecToFloat()

std::array<float, 3> vecToFloat ( const G4ThreeVector &  vec)
inlineprivate

Convert G4ThreeVector (aka Hep3Vector) to float array to store in TrueHit/SimHit classes.

Parameters
vecvector to convert
Returns
array containing x,y,z as floats

Definition at line 105 of file SensitiveDetector.h.


The documentation for this class was generated from the following file:
Belle2::VXD::SensitiveDetectorBase::m_info
SensorInfoBase * m_info
Pointer to the SensorInfo associated with this instance.
Definition: SensitiveDetectorBase.h:173
Belle2::VXD::SensitiveDetector::m_relMCSimHits
RelationArray m_relMCSimHits
Relation between MCParticle and SimHits.
Definition: SensitiveDetector.h:117
Belle2::VXD::SensitiveDetector::m_relMCTrueHits
RelationArray m_relMCTrueHits
Relation between MCParticle and TrueHits.
Definition: SensitiveDetector.h:119
Belle2::SensorTraversal::range
std::pair< iterator, iterator > range
Iterator pair for a set of points.
Definition: SensorTraversal.h:57
Belle2::RelationArray::add
void add(index_type from, index_type to, weight_type weight=1.0)
Add a new element to the relation.
Definition: RelationArray.h:291
Belle2::VXD::SensitiveDetectorBase::simplifyEnergyDeposit
std::vector< unsigned int > simplifyEnergyDeposit(const SensorTraversal::range &points)
Simplify the energy deposition profile using Douglas-Peuker-Algorithm We normally force a Geant4 step...
Definition: SensitiveDetectorBase.cc:190
Belle2::VXD::SensitiveDetectorBase::saveSimHit
virtual int saveSimHit(const SensorTraversal &traversal, const SensorTraversal::range &points)=0
Save a SimHit for this track including the given points.
Belle2::VXD::SensitiveDetectorBase::m_distanceTolerance
float m_distanceTolerance
maximum distance between step point and linear interpolation of sensor traversal before a new simhit ...
Definition: SensitiveDetectorBase.h:178
Belle2::VXD::SensitiveDetector::m_relTrueSimHits
RelationArray m_relTrueSimHits
Relation between TrueHits and SimHits.
Definition: SensitiveDetector.h:121