Belle II Software  release-06-01-15
SensitiveDetectorBase.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #ifndef SENSITIVEDETECTOR_H_
10 #define SENSITIVEDETECTOR_H_
11 
12 #include <framework/datastore/RelationArray.h>
13 #include <mdst/dataobjects/MCParticle.h>
14 #include <simulation/kernel/UserInfo.h>
15 #include <G4VSensitiveDetector.hh>
16 class G4Step;
17 
18 #include <map>
19 #include <string>
20 
21 
22 namespace Belle2 {
27  namespace Simulation {
28 
30  class SensitiveDetectorBase : public G4VSensitiveDetector {
31  public:
32 
37  SensitiveDetectorBase(const std::string& name, Const::EDetector subdetector):
38  G4VSensitiveDetector(name), m_subdetector(subdetector) {}
39 
42 
44  static const std::map<std::string, RelationArray::EConsolidationAction>& getMCParticleRelations() { return s_mcRelations; }
52  static void setActive(bool activeStatus) { s_active = activeStatus; }
61  static void registerMCParticleRelation(const std::string& name,
63 
68  static void registerMCParticleRelation(const RelationArray& relation,
70 
71  protected:
81  virtual bool step(G4Step* step, G4TouchableHistory* ROhist) = 0;
82  private:
87  virtual bool ProcessHits(G4Step* aStep, G4TouchableHistory* aROhist);
89  static std::map<std::string, RelationArray::EConsolidationAction> s_mcRelations;
91  static bool s_active;
94  };
95 
96  inline bool SensitiveDetectorBase::ProcessHits(G4Step* aStep, G4TouchableHistory* aROhist)
97  {
98  if (!s_active) return false;
99  bool result = step(aStep, aROhist);
100  // Do not include hits from invalid detector (beast,teastbeam, etc.)
101  if (result && (m_subdetector != Const::invalidDetector)) TrackInfo::getInfo(*aStep->GetTrack()).addSeenInDetector(m_subdetector);
102  return result;
103  }
104 
105  } // end namespace Simulation
107 } // end namespace Belle2
108 
109 #endif /* SENSITIVEDETECTOR_H_ */
EDetector
Enum for identifying the detector components (detector and subdetector).
Definition: Const.h:42
Low-level class to create/modify relations between StoreArrays.
Definition: RelationArray.h:62
EConsolidationAction
Modification actions for the consolidate member.
Definition: RelationArray.h:77
@ c_negativeWeight
Flip the sign of the weight to become negative if the original element got re-attributed.
Definition: RelationArray.h:79
Base class for all Sensitive Detectors to create hits during simulation.
static std::map< std::string, RelationArray::EConsolidationAction > s_mcRelations
Static set holding all relations which have to be updated at the end of the Event.
static void setActive(bool activeStatus)
Enable/Disable all Sensitive Detectors.
virtual bool step(G4Step *step, G4TouchableHistory *ROhist)=0
Process a Geant4 step in any of the sensitive volumes attached to this sensitive detector.
static const std::map< std::string, RelationArray::EConsolidationAction > & getMCParticleRelations()
Return a list of all registered Relations with MCParticles.
static void registerMCParticleRelation(const std::string &name, RelationArray::EConsolidationAction ignoreAction=RelationArray::c_negativeWeight)
Register an relation involving MCParticles.
static void registerMCParticleRelation(const RelationArray &relation, RelationArray::EConsolidationAction ignoreAction=RelationArray::c_negativeWeight)
Overload to make it easer to register MCParticle relations.
Const::EDetector m_subdetector
Subdetector the class belongs to.
static bool s_active
Static bool which indicates wether recording of hits is enabled.
virtual bool ProcessHits(G4Step *aStep, G4TouchableHistory *aROhist)
Check if recording hits is enabled and if so call step() and set the correct MCParticle flag.
SensitiveDetectorBase(const std::string &name, Const::EDetector subdetector)
Create a new Sensitive detecor with a given name and belonging to a given subdetector.
virtual ~SensitiveDetectorBase()
virtual destructor for inheritance
static Payload getInfo(Carrier &obj)
Static function to just return UserInformation attached to the obj of type Carrier.
Definition: UserInfo.h:100
const std::string & getName() const
Return name under which the object is saved in the DataStore.
Abstract base class for different kinds of events.