10 #include <klm/bklm/simulation/SensitiveDetector.h>
13 #include <klm/bklm/geometry/GeometryPar.h>
14 #include <klm/bklm/geometry/Module.h>
15 #include <klm/dataobjects/bklm/BKLMElementNumbers.h>
16 #include <klm/dataobjects/bklm/BKLMStatus.h>
19 #include <simulation/background/BkgSensitiveDetector.h>
23 #include <G4VProcess.hh>
26 #include <CLHEP/Units/SystemOfUnits.h>
27 #include <CLHEP/Vector/ThreeVector.h>
33 using namespace Belle2::bklm;
35 SensitiveDetector::SensitiveDetector(
const G4String& name) :
36 SensitiveDetectorBase(name,
Const::KLM),
38 m_BkgSensitiveDetector(nullptr),
42 B2FATAL(
"BKLM simulation parameters are not available.");
64 B2FATAL(
"BKLM simulation parameters are not available.");
67 B2FATAL(
"gRandom is not initialized; please set up gRandom first");
82 double eDep =
step->GetTotalEnergyDeposit() / CLHEP::MeV;
83 G4StepPoint* preStep =
step->GetPreStepPoint();
84 G4StepPoint* postStep =
step->GetPostStepPoint();
85 G4Track* track =
step->GetTrack();
88 if ((eDep > 0.0) && (postStep->GetCharge() != 0.0)) {
89 const G4VTouchable* hist = preStep->GetTouchable();
90 int depth = hist->GetHistoryDepth();
92 B2WARNING(
"BKLM SensitiveDetector::step(): "
93 <<
LogVar(
"Touchable HistoryDepth", depth)
103 double time = 0.5 * (preStep->GetGlobalTime() + postStep->GetGlobalTime());
106 const CLHEP::Hep3Vector globalPosition = 0.5 * (preStep->GetPosition() + postStep->GetPosition()) / CLHEP::cm;
108 const CLHEP::Hep3Vector localPosition = m->globalToLocal(globalPosition);
109 if (postStep->GetProcessDefinedStep() != 0) {
110 if (postStep->GetProcessDefinedStep()->GetProcessType() == fDecay)
111 moduleID |= BKLM_DECAYED_MASK;
113 int trackID = track->GetTrackID();
115 const CLHEP::Hep3Vector propagationTimes =
116 m->getPropagationTimes(localPosition);
117 int phiStripLower = -1;
118 int phiStripUpper = -1;
119 int zStripLower = -1;
120 int zStripUpper = -1;
122 if (zStripLower > 0) {
123 int moduleIDZ = moduleID;
133 if (phiStripLower > 0) {
145 bool phiPlane = (plane == BKLM_INNER);
146 double propagationTime =
147 m->getPropagationTime(localPosition, scint, phiPlane);
169 int& phiStripLower,
int& phiStripUpper,
int& zStripLower,
int& zStripUpper)
171 double phiStripD = m->getPhiStrip(localPosition);
172 int phiStrip = int(phiStripD);
173 int pMin = m->getPhiStripMin();
176 int pMax = m->getPhiStripMax();
180 double zStripD = m->getZStrip(localPosition);
181 int zStrip = int(zStripD);
182 int zMin = m->getZStripMin();
185 int zMax = m->getZStripMax();
189 phiStripLower = phiStrip;
190 phiStripUpper = phiStrip;
191 zStripLower = zStrip;
192 zStripUpper = zStrip;
193 double phiStripDiv = fmod(phiStripD, 1.0) - 0.5;
194 double zStripDiv = fmod(zStripD, 1.0) - 0.5;
196 double rand = gRandom->Uniform();
197 for (n = 1; n <
m_SimPar->getMaxMultiplicity(); ++n) {
198 if (
m_SimPar->getPhiMultiplicityCDF(phiStripDiv, n) > rand)
201 int nextStrip = (phiStripDiv > 0.0 ? 1 : -1);
203 phiStrip += nextStrip;
204 if ((phiStrip >= pMin) && (phiStrip <= pMax)) {
205 phiStripLower = min(phiStrip, phiStripLower);
206 phiStripUpper = max(phiStrip, phiStripUpper);
208 nextStrip = (nextStrip > 0 ? -(1 + nextStrip) : 1 - nextStrip);
210 rand = gRandom->Uniform();
211 for (n = 1; n <
m_SimPar->getMaxMultiplicity(); ++n) {
212 if (
m_SimPar->getZMultiplicityCDF(zStripDiv, n) > rand)
215 nextStrip = (zStripDiv > 0.0 ? 1 : -1);
218 if ((zStrip >= zMin) && (zStrip <= zMax)) {
219 zStripLower = min(zStrip, zStripLower);
220 zStripUpper = max(zStrip, zStripUpper);
222 nextStrip = (nextStrip > 0 ? -(1 + nextStrip) : 1 - nextStrip);
static void setStripInModule(int &module, int strip)
Set strip number in module identifier.
static KLMModuleNumber moduleNumber(int section, int sector, int layer, bool fatalError=true)
Get module number.
static void setPlaneInModule(int &module, int plane)
Set plane number in module identifier.
Store one simulation hit's global position as a ROOT object.
Store one simulation hit as a ROOT object.
static void setMaximalStrip(int &module, int strip)
Set maximal strip number.
This class provides a set of constants for the framework.
void add(index_type from, index_type to, weight_type weight=1.0)
Add a new element to the relation.
void addRelationTo(const RelationsInterface< BASE > *object, float weight=1.0, const std::string &namedRelation="") const
Add a relation from this object to another object (with caching).
int getArrayIndex() const
Returns this object's array index (in StoreArray), or -1 if not found.
static void registerMCParticleRelation(const std::string &name, RelationArray::EConsolidationAction ignoreAction=RelationArray::c_negativeWeight)
Register an relation involving MCParticles.
bool isOptional(const std::string &name="")
Tell the DataStore about an optional input.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
bool doBeamBackgroundStudy(void) const
Get the beam background study flag.
const Module * findModule(int section, int sector, int layer) const
Get the pointer to the definition of a module.
BkgSensitiveDetector * getBkgSensitiveDetector(void) const
Get the beam background study flag.
static GeometryPar * instance(void)
Static method to get a reference to the singleton GeometryPar instance.
Define the geometry of a BKLM module Each sector [octant] contains Modules.
DBObjPtr< BKLMSimulationPar > m_SimPar
Simulation parameters (from DB)
void convertHitToRPCStrips(const CLHEP::Hep3Vector &, const Module *, int &, int &, int &, int &)
Find the ranges of matching RPC strips for each simulated hit.
bool m_FirstCall
Flag to enforce once-only initializations in Initialize()
static constexpr int m_DepthSection
Section depth.
static constexpr int m_DepthSector
Sector depth.
StoreArray< BKLMSimHit > m_SimHits
BKLM simulated hits.
double m_HitTimeMax
maximum permissible hit time (based on overflow of LeCroy 1877 TDC)
BkgSensitiveDetector * m_BkgSensitiveDetector
Pointer to a sensitive-detector object used for beam-background steps.
RelationArray m_MCParticlesToSimHits
Relation array between MCPartices and BKLMSimHits.
StoreArray< BKLMSimHitPosition > m_SimHitPositions
BKLM simulated hit positions.
GeometryPar * m_GeoPar
Pointer to GeometryPar singleton.
bool step(G4Step *, G4TouchableHistory *) override
Process each step in the BKLM.
static constexpr int m_DepthScintillator
Scintillator depth.
static constexpr int m_DepthPlane
Plane depth.
StoreArray< MCParticle > m_MCParticles
MC particles.
static constexpr int m_DepthLayer
Layer depth.
Class to store variables with their name which were sent to the logging service.
bool step(G4Step *aStep, G4TouchableHistory *) override
Process each step and calculate variables defined in PXDSimHit.