Belle II Software development
SensitivePMT Class Reference

Class providing SimHits. More...

#include <SensitivePMT.h>

Inheritance diagram for SensitivePMT:
SensitiveDetectorBase

Public Member Functions

 SensitivePMT ()
 Constructor.
 
bool step (G4Step *aStep, G4TouchableHistory *) override
 Process each step, fill TOPSimHits and TOPSimPhotons.
 
void setPMTReplicaDepth (int depth)
 Sets replica depth of PMT volume.
 
void setModuleReplicaDepth (int depth)
 Sets replica depth of module volume.
 

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.
 
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.
 

Private Member Functions

virtual bool ProcessHits (G4Step *aStep, G4TouchableHistory *aROhist)
 Check if recording hits is enabled and if so call step() and set the correct MCParticle flag.
 

Private Attributes

int m_pmtReplicaDepth = 2
 replica depth of PMT volume
 
int m_moduleReplicaDepth = 5
 replica depth of module volume
 
TOPGeometryParm_topgp = TOPGeometryPar::Instance()
 geometry parameters
 
StoreArray< MCParticlem_mcParticles
 collection of MC particles
 
StoreArray< TOPSimHitm_simHits
 collection of simulated hits
 
StoreArray< TOPSimPhotonm_simPhotons
 collection of simulated photons
 
RelationArray m_relParticleHit {m_mcParticles, m_simHits}
 relations
 
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

Class providing SimHits.

Definition at line 30 of file SensitivePMT.h.

Constructor & Destructor Documentation

◆ SensitivePMT()

Constructor.

Definition at line 34 of file SensitivePMT.cc.

34 :
35 Simulation::SensitiveDetectorBase("TOP", Const::TOP)
36 {
37
38 m_simHits.registerInDataStore();
40
41 m_simPhotons.registerInDataStore(DataStore::c_DontWriteOut);
42 m_simHits.registerRelationTo(m_simPhotons, DataStore::c_Event,
44
46
47 }
@ c_DontWriteOut
Object/array should be NOT saved by output modules.
Definition: DataStore.h:71
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
Definition: DataStore.h:59
static void registerMCParticleRelation(const std::string &name, RelationArray::EConsolidationAction ignoreAction=RelationArray::c_negativeWeight)
Register an relation involving MCParticles.
bool registerRelationTo(const StoreArray< TO > &toArray, DataStore::EDurability durability=DataStore::c_Event, DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut, const std::string &namedRelation="") const
Register a relation to the given StoreArray.
Definition: StoreArray.h:140
RelationArray m_relParticleHit
relations
Definition: SensitivePMT.h:67
StoreArray< MCParticle > m_mcParticles
collection of MC particles
Definition: SensitivePMT.h:64
StoreArray< TOPSimPhoton > m_simPhotons
collection of simulated photons
Definition: SensitivePMT.h:66
StoreArray< TOPSimHit > m_simHits
collection of simulated hits
Definition: SensitivePMT.h:65

Member Function Documentation

◆ getMCParticleRelations()

static const std::map< std::string, RelationArray::EConsolidationAction > & getMCParticleRelations ( )
inlinestaticinherited

Return a list of all registered Relations with MCParticles.

Definition at line 42 of file SensitiveDetectorBase.h.

42{ return 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.

◆ 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 94 of file SensitiveDetectorBase.h.

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 }
virtual bool step(G4Step *step, G4TouchableHistory *ROhist)=0
Process a Geant4 step in any of the sensitive volumes attached to this sensitive detector.
Const::EDetector m_subdetector
Subdetector the class belongs to.
static bool s_active
Static bool which indicates wether recording of hits is enabled.
static Payload getInfo(Carrier &obj)
Static function to just return UserInformation attached to the obj of type Carrier.
Definition: UserInfo.h:100

◆ 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 66 of file SensitiveDetectorBase.h.

67 { registerMCParticleRelation(relation.getName(), ignoreAction); }

◆ 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 22 of file SensitiveDetectorBase.cc.

23 {
24 std::pair<std::map<std::string, RelationArray::EConsolidationAction>::iterator, bool> insert = s_mcRelations.insert(std::make_pair(
25 name, ignoreAction));
26 //If the relation already exists and the ignoreAction is different we do have a problem
27 if (!insert.second && insert.first->second != ignoreAction) {
28 B2FATAL("MCParticle Relation " << name << " already registered with different ignore action.");
29 }
30 }

◆ 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 50 of file SensitiveDetectorBase.h.

50{ s_active = activeStatus; }

◆ setModuleReplicaDepth()

void setModuleReplicaDepth ( int  depth)
inline

Sets replica depth of module volume.

Parameters
depthreplica depth

Definition at line 56 of file SensitivePMT.h.

56{m_moduleReplicaDepth = depth;}
int m_moduleReplicaDepth
replica depth of module volume
Definition: SensitivePMT.h:61

◆ setPMTReplicaDepth()

void setPMTReplicaDepth ( int  depth)
inline

Sets replica depth of PMT volume.

Parameters
depthreplica depth

Definition at line 50 of file SensitivePMT.h.

50{m_pmtReplicaDepth = depth;}
int m_pmtReplicaDepth
replica depth of PMT volume
Definition: SensitivePMT.h:60

◆ step()

G4bool step ( G4Step *  aStep,
G4TouchableHistory *   
)
overridevirtual

Process each step, fill TOPSimHits and TOPSimPhotons.

Parameters
aStepCurrent Geant4 step in the sensitive medium.
Returns
true if optical photon detected.

Implements SensitiveDetectorBase.

Definition at line 50 of file SensitivePMT.cc.

51 {
52 // photon track
53 G4Track& photon = *aStep->GetTrack();
54
55 // check if the track is an optical photon
56 if (photon.GetDefinition() != G4OpticalPhoton::OpticalPhotonDefinition()) return false;
57
58 // photon energy in [eV]
59 double energy = photon.GetKineticEnergy() * Unit::MeV / Unit::eV;
60
61 // pmt and module ID
62 int pmtID = photon.GetTouchableHandle()->GetReplicaNumber(m_pmtReplicaDepth);
63 int moduleID = photon.GetTouchableHandle()->GetReplicaNumber(m_moduleReplicaDepth);
64
65 // hit position in local frame, converted to Basf units
66 G4ThreeVector localPosition = photon.GetTouchableHandle()->GetHistory()->GetTopTransform().TransformPoint(photon.GetPosition());
67 double xLocal = localPosition.x() * Unit::mm;
68 double yLocal = localPosition.y() * Unit::mm;
69
70 // apply quantum efficiency if not yet done
71 bool applyQE = true;
72 double fraction = 1;
73 auto* info = dynamic_cast<Simulation::TrackInfo*>(photon.GetUserInformation());
74 if (info) {
75 applyQE = info->getStatus() < 3;
76 fraction = info->getFraction();
77 }
78 if (applyQE) {
79 double qeffi = m_topgp->getPMTEfficiency(energy, moduleID, pmtID, xLocal, yLocal);
80 if (qeffi == 0 or gRandom->Uniform() * fraction > qeffi) {
81 photon.SetTrackStatus(fStopAndKill);
82 return false;
83 }
84 if (info) {
85 info->setStatus(3);
86 info->setFraction(qeffi);
87 }
88 }
89
90 // photon at detection
91 const G4ThreeVector& g_detPoint = photon.GetPosition();
92 const G4ThreeVector& g_detMomDir = photon.GetMomentumDirection();
93 ROOT::Math::XYZPoint detPoint(g_detPoint.x(), g_detPoint.y(), g_detPoint.z());
94 ROOT::Math::XYZVector detMomDir(g_detMomDir.x(), g_detMomDir.y(), g_detMomDir.z());
95 double detTime = photon.GetGlobalTime();
96 double length = photon.GetTrackLength();
97
98 // photon at emission
99 const G4ThreeVector& g_emiPoint = photon.GetVertexPosition();
100 const G4ThreeVector& g_emiMomDir = photon.GetVertexMomentumDirection();
101 ROOT::Math::XYZPoint emiPoint(g_emiPoint.x(), g_emiPoint.y(), g_emiPoint.z());
102 ROOT::Math::XYZVector emiMomDir(g_emiMomDir.x(), g_emiMomDir.y(), g_emiMomDir.z());
103 double emiTime = photon.GetGlobalTime() - photon.GetLocalTime();
104
105 // convert to basf2 units
106 emiPoint = emiPoint * Unit::mm;
107 detPoint = detPoint * Unit::mm;
108 length = length * Unit::mm;
109
110 // write to store arrays; add relations
111
112 auto* simHit = m_simHits.appendNew(moduleID, pmtID, xLocal, yLocal,
113 detTime, energy);
114
115 int parentID = photon.GetParentID();
116 if (parentID == 0) parentID = photon.GetTrackID();
117 m_relParticleHit.add(parentID, simHit->getArrayIndex());
118
119 const auto* geo = m_topgp->getGeometry();
120 if (geo->isModuleIDValid(moduleID)) {
121 // transform to local frame
122 const auto& module = geo->getModule(moduleID);
123 emiPoint = module.pointToLocal(emiPoint);
124 detPoint = module.pointToLocal(detPoint);
125 emiMomDir = module.momentumToLocal(emiMomDir);
126 detMomDir = module.momentumToLocal(detMomDir);
127 } else {
128 B2ERROR("TOP::SensitivePMT: undefined module ID."
129 << LogVar("moduleID", moduleID));
130 }
131 auto* simPhoton = m_simPhotons.appendNew(moduleID,
132 emiPoint, emiMomDir, emiTime,
133 detPoint, detMomDir, detTime,
134 length, energy);
135
136 simHit->addRelationTo(simPhoton);
137
138 // kill photon after detection
139 photon.SetTrackStatus(fStopAndKill);
140
141 return true;
142 }
void add(index_type from, index_type to, weight_type weight=1.0)
Add a new element to the relation.
TOPGeometryPar * m_topgp
geometry parameters
Definition: SensitivePMT.h:62
const TOPGeometry * getGeometry() const
Returns pointer to geometry object using basf2 units.
double getPMTEfficiency(double energy, int moduleID, int pmtID, double x, double y) const
Returns PMT pixel efficiency, a product of quantum and collection efficiency.
static const double mm
[millimeters]
Definition: Unit.h:70
static const double eV
[electronvolt]
Definition: Unit.h:112
static const double MeV
[megaelectronvolt]
Definition: Unit.h:114
Class to store variables with their name which were sent to the logging service.

Member Data Documentation

◆ m_mcParticles

StoreArray<MCParticle> m_mcParticles
private

collection of MC particles

Definition at line 64 of file SensitivePMT.h.

◆ m_moduleReplicaDepth

int m_moduleReplicaDepth = 5
private

replica depth of module volume

Definition at line 61 of file SensitivePMT.h.

◆ m_pmtReplicaDepth

int m_pmtReplicaDepth = 2
private

replica depth of PMT volume

Definition at line 60 of file SensitivePMT.h.

◆ m_relParticleHit

RelationArray m_relParticleHit {m_mcParticles, m_simHits}
private

relations

Definition at line 67 of file SensitivePMT.h.

◆ m_simHits

StoreArray<TOPSimHit> m_simHits
private

collection of simulated hits

Definition at line 65 of file SensitivePMT.h.

◆ m_simPhotons

StoreArray<TOPSimPhoton> m_simPhotons
private

collection of simulated photons

Definition at line 66 of file SensitivePMT.h.

◆ m_subdetector

Const::EDetector m_subdetector
privateinherited

Subdetector the class belongs to.

Definition at line 91 of file SensitiveDetectorBase.h.

◆ m_topgp

geometry parameters

Definition at line 62 of file SensitivePMT.h.

◆ s_active

bool s_active
staticprivateinherited

Static bool which indicates wether recording of hits is enabled.

Definition at line 89 of file SensitiveDetectorBase.h.

◆ s_mcRelations

map< string, RelationArray::EConsolidationAction > s_mcRelations
staticprivateinherited

Static set holding all relations which have to be updated at the end of the Event.

Definition at line 87 of file SensitiveDetectorBase.h.


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