Belle II Software  release-05-02-19
SensitiveDetectorBase.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010-2011 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Andreas Moll, Martin Ritter *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #ifndef SENSITIVEDETECTOR_H_
12 #define SENSITIVEDETECTOR_H_
13 
14 #include <framework/datastore/RelationArray.h>
15 #include <mdst/dataobjects/MCParticle.h>
16 #include <simulation/kernel/UserInfo.h>
17 #include <G4VSensitiveDetector.hh>
18 class G4Step;
19 
20 #include <map>
21 #include <string>
22 
23 
24 namespace Belle2 {
29  namespace Simulation {
30 
32  class SensitiveDetectorBase : public G4VSensitiveDetector {
33  public:
34 
39  SensitiveDetectorBase(const std::string& name, Const::EDetector subdetector):
40  G4VSensitiveDetector(name), m_subdetector(subdetector) {}
41 
44 
46  static const std::map<std::string, RelationArray::EConsolidationAction>& getMCParticleRelations() { return s_mcRelations; }
54  static void setActive(bool activeStatus) { s_active = activeStatus; }
63  static void registerMCParticleRelation(const std::string& name,
65 
70  static void registerMCParticleRelation(const RelationArray& relation,
72 
73  protected:
83  virtual bool step(G4Step* step, G4TouchableHistory* ROhist) = 0;
84  private:
89  virtual bool ProcessHits(G4Step* aStep, G4TouchableHistory* aROhist);
91  static std::map<std::string, RelationArray::EConsolidationAction> s_mcRelations;
93  static bool s_active;
96  };
97 
98  inline bool SensitiveDetectorBase::ProcessHits(G4Step* aStep, G4TouchableHistory* aROhist)
99  {
100  if (!s_active) return false;
101  bool result = step(aStep, aROhist);
102  // Do not include hits from invalid detector (beast,teastbeam, etc.)
103  if (result && (m_subdetector != Const::invalidDetector)) TrackInfo::getInfo(*aStep->GetTrack()).addSeenInDetector(m_subdetector);
104  return result;
105  }
106 
107  } // end namespace Simulation
109 } // end namespace Belle2
110 
111 #endif /* SENSITIVEDETECTOR_H_ */
Belle2::RelationArray
Low-level class to create/modify relations between StoreArrays.
Definition: RelationArray.h:72
Belle2::Simulation::SensitiveDetectorBase::m_subdetector
Const::EDetector m_subdetector
Subdetector the class belongs to.
Definition: SensitiveDetectorBase.h:95
Belle2::RelationArray::c_negativeWeight
@ c_negativeWeight
Flip the sign of the weight to become negative if the original element got re-attributed.
Definition: RelationArray.h:89
Belle2::Simulation::UserInfo::getInfo
static Payload getInfo(Carrier &obj)
Static function to just return UserInformation attached to the obj of type Carrier.
Definition: UserInfo.h:110
Belle2::Simulation::SensitiveDetectorBase::ProcessHits
virtual bool ProcessHits(G4Step *aStep, G4TouchableHistory *aROhist)
Check if recording hits is enabled and if so call step() and set the correct MCParticle flag.
Definition: SensitiveDetectorBase.h:98
Belle2::Simulation::SensitiveDetectorBase::s_active
static bool s_active
Static bool which indicates wether recording of hits is enabled.
Definition: SensitiveDetectorBase.h:93
Belle2::StoreAccessorBase::getName
const std::string & getName() const
Return name under which the object is saved in the DataStore.
Definition: StoreAccessorBase.h:130
Belle2::RelationArray::EConsolidationAction
EConsolidationAction
Modification actions for the consolidate member.
Definition: RelationArray.h:87
Belle2::Simulation::SensitiveDetectorBase
Base class for all Sensitive Detectors to create hits during simulation.
Definition: SensitiveDetectorBase.h:32
Belle2::Simulation::SensitiveDetectorBase::s_mcRelations
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.
Definition: SensitiveDetectorBase.h:91
Belle2::Simulation::SensitiveDetectorBase::registerMCParticleRelation
static void registerMCParticleRelation(const std::string &name, RelationArray::EConsolidationAction ignoreAction=RelationArray::c_negativeWeight)
Register an relation involving MCParticles.
Definition: SensitiveDetectorBase.cc:24
Belle2::Const::EDetector
EDetector
Enum for identifying the detector components (detector and subdetector).
Definition: Const.h:44
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::Simulation::SensitiveDetectorBase::SensitiveDetectorBase
SensitiveDetectorBase(const std::string &name, Const::EDetector subdetector)
Create a new Sensitive detecor with a given name and belonging to a given subdetector.
Definition: SensitiveDetectorBase.h:39
Belle2::Simulation::SensitiveDetectorBase::registerMCParticleRelation
static void registerMCParticleRelation(const RelationArray &relation, RelationArray::EConsolidationAction ignoreAction=RelationArray::c_negativeWeight)
Overload to make it easer to register MCParticle relations.
Definition: SensitiveDetectorBase.h:70
Belle2::Simulation::SensitiveDetectorBase::setActive
static void setActive(bool activeStatus)
Enable/Disable all Sensitive Detectors.
Definition: SensitiveDetectorBase.h:54
Belle2::Simulation::SensitiveDetectorBase::~SensitiveDetectorBase
virtual ~SensitiveDetectorBase()
virtual destructor for inheritance
Definition: SensitiveDetectorBase.h:43
Belle2::Simulation::SensitiveDetectorBase::getMCParticleRelations
static const std::map< std::string, RelationArray::EConsolidationAction > & getMCParticleRelations()
Return a list of all registered Relations with MCParticles.
Definition: SensitiveDetectorBase.h:46
Belle2::Simulation::SensitiveDetectorBase::step
virtual bool step(G4Step *step, G4TouchableHistory *ROhist)=0
Process a Geant4 step in any of the sensitive volumes attached to this sensitive detector.