Belle II Software development
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#pragma once
10
11#include <framework/datastore/RelationArray.h>
12#include <simulation/kernel/UserInfo.h>
13#include <G4VSensitiveDetector.hh>
14class G4Step;
15
16#include <map>
17#include <string>
18
19
20namespace Belle2 {
25 namespace Simulation {
26
28 class SensitiveDetectorBase : public G4VSensitiveDetector {
29 public:
30
35 SensitiveDetectorBase(const std::string& name, Const::EDetector subdetector):
36 G4VSensitiveDetector(name), m_subdetector(subdetector) {}
37
40
42 static const std::map<std::string, RelationArray::EConsolidationAction>& getMCParticleRelations() { return s_mcRelations; }
50 static void setActive(bool activeStatus) { s_active = activeStatus; }
59 static void registerMCParticleRelation(const std::string& name,
61
66 static void registerMCParticleRelation(const RelationArray& relation,
68
69 protected:
79 virtual bool step(G4Step* step, G4TouchableHistory* ROhist) = 0;
80 private:
85 virtual bool ProcessHits(G4Step* aStep, G4TouchableHistory* aROhist);
87 static std::map<std::string, RelationArray::EConsolidationAction> s_mcRelations;
89 static bool s_active;
92 };
93
94 inline bool SensitiveDetectorBase::ProcessHits(G4Step* aStep, G4TouchableHistory* aROhist)
95 {
96 if (!s_active) return false;
97 bool result = step(aStep, aROhist);
98 // Do not include hits from invalid detector (beast,teastbeam, etc.)
99 if (result && (m_subdetector != Const::invalidDetector)) TrackInfo::getInfo(*aStep->GetTrack()).addSeenInDetector(m_subdetector);
100 return result;
101 }
102
103 } // end namespace Simulation
105} // end namespace Belle2
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 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 const std::map< std::string, RelationArray::EConsolidationAction > & getMCParticleRelations()
Return a list of all registered Relations with MCParticles.
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.