10#include <klm/simulation/SensitiveDetector.h>
13#include <klm/dataobjects/bklm/BKLMElementNumbers.h>
14#include <klm/dataobjects/KLMElementNumbers.h>
15#include <klm/eklm/geometry/GeometryData.h>
18#include <simulation/background/BkgSensitiveDetector.h>
22#include <G4VProcess.hh>
25#include <CLHEP/Units/SystemOfUnits.h>
26#include <CLHEP/Vector/ThreeVector.h>
31using namespace Belle2::KLM;
35 SensitiveDetectorBase(name,
Const::KLM),
36 m_Subdetector(subdetector),
38 m_BkgSensitiveDetector(nullptr),
42 B2FATAL(
"BKLM simulation parameters are not available.");
65 const int stripLevel = 1;
66 int section, layer, sector, plane, strip, stripGlobal;
68 G4TouchableHandle hist = aStep->GetPreStepPoint()->GetTouchableHandle();
69 section = hist->GetVolume(stripLevel + 6)->GetCopyNo();
70 layer = hist->GetVolume(stripLevel + 5)->GetCopyNo();
71 sector = hist->GetVolume(stripLevel + 4)->GetCopyNo();
72 plane = hist->GetVolume(stripLevel + 3)->GetCopyNo();
73 strip = hist->GetVolume(stripLevel)->GetCopyNo();
75 section, layer, sector, plane, strip);
76 const G4double eDep = aStep->GetTotalEnergyDeposit();
80 const G4Track& track = * aStep->GetTrack();
81 const G4double hitTime = track.GetGlobalTime();
85 gpos = 0.5 * (aStep->GetPostStepPoint()->GetPosition() +
86 aStep->GetPreStepPoint()->GetPosition());
87 lpos = hist->GetHistory()->GetTopTransform().TransformPoint(gpos);
91 hit->setSection(section);
92 hit->setSector(sector);
96 hit->setLastStrip(strip);
98 hit->setTime(hitTime);
99 hit->setEnergyDeposit(eDep);
100 CLHEP::Hep3Vector trackMomentum = track.GetMomentum();
101 hit->setMomentum(ROOT::Math::PxPyPzEVector(trackMomentum.x(), trackMomentum.y(),
102 trackMomentum.z(), track.GetTotalEnergy()));
103 hit->setTrackID(track.GetTrackID());
104 hit->setParentTrackID(track.GetParentID());
105 hit->setLocalPosition(lpos.x() / CLHEP::mm *
Unit::mm,
108 hit->setPosition(gpos.x() / CLHEP::mm *
Unit::mm,
111 hit->setPDG(track.GetDefinition()->GetPDGEncoding());
112 hit->setVolumeID(stripGlobal);
126 B2FATAL(
"gRandom is not initialized; please set up gRandom first");
141 double eDep =
step->GetTotalEnergyDeposit() / CLHEP::MeV;
142 G4StepPoint* preStep =
step->GetPreStepPoint();
143 G4StepPoint* postStep =
step->GetPostStepPoint();
144 G4Track* track =
step->GetTrack();
147 if ((eDep > 0.0) && (postStep->GetCharge() != 0.0)) {
148 const G4VTouchable* hist = preStep->GetTouchable();
149 int depth = hist->GetHistoryDepth();
151 B2WARNING(
"BKLM SensitiveDetector::step(): "
152 <<
LogVar(
"Touchable HistoryDepth", depth)
160 double time = 0.5 * (preStep->GetGlobalTime() + postStep->GetGlobalTime());
163 const CLHEP::Hep3Vector globalPosition = 0.5 * (preStep->GetPosition() + postStep->GetPosition()) / CLHEP::cm;
165 const CLHEP::Hep3Vector localPosition = m->globalToLocal(globalPosition);
166 int trackID = track->GetTrackID();
168 const CLHEP::Hep3Vector propagationTimes =
169 m->getPropagationTimes(localPosition);
170 int phiStripLower = -1;
171 int phiStripUpper = -1;
172 int zStripLower = -1;
173 int zStripUpper = -1;
175 if (zStripLower > 0) {
187 simHit->
setPosition(globalPosition.x(), globalPosition.y(),
189 simHit->
setPDG(track->GetDefinition()->GetPDGEncoding());
192 if (phiStripLower > 0) {
204 simHit->
setPosition(globalPosition.x(), globalPosition.y(),
206 simHit->
setPDG(track->GetDefinition()->GetPDGEncoding());
211 bool phiPlane = (plane == BKLM_INNER);
212 double propagationTime =
213 m->getPropagationTime(localPosition, scint, phiPlane);
229 simHit->
setPosition(globalPosition.x(), globalPosition.y(),
231 simHit->
setPDG(track->GetDefinition()->GetPDGEncoding());
240 const CLHEP::Hep3Vector& localPosition,
const bklm::Module* m,
241 int& phiStripLower,
int& phiStripUpper,
int& zStripLower,
int& zStripUpper)
243 double phiStripD = m->getPhiStrip(localPosition);
244 int phiStrip = int(phiStripD);
245 int pMin = m->getPhiStripMin();
248 int pMax = m->getPhiStripMax();
252 double zStripD = m->getZStrip(localPosition);
253 int zStrip = int(zStripD);
254 int zMin = m->getZStripMin();
257 int zMax = m->getZStripMax();
261 phiStripLower = phiStrip;
262 phiStripUpper = phiStrip;
263 zStripLower = zStrip;
264 zStripUpper = zStrip;
265 double phiStripDiv = fmod(phiStripD, 1.0) - 0.5;
266 double zStripDiv = fmod(zStripD, 1.0) - 0.5;
268 double rand = gRandom->Uniform();
269 for (n = 1; n <
m_SimPar->getMaxMultiplicity(); ++n) {
270 if (
m_SimPar->getPhiMultiplicityCDF(phiStripDiv, n) > rand)
273 int nextStrip = (phiStripDiv > 0.0 ? 1 : -1);
275 phiStrip += nextStrip;
276 if ((phiStrip >= pMin) && (phiStrip <= pMax)) {
277 phiStripLower = std::min(phiStrip, phiStripLower);
278 phiStripUpper = std::max(phiStrip, phiStripUpper);
280 nextStrip = (nextStrip > 0 ? -(1 + nextStrip) : 1 - nextStrip);
282 rand = gRandom->Uniform();
283 for (n = 1; n <
m_SimPar->getMaxMultiplicity(); ++n) {
284 if (
m_SimPar->getZMultiplicityCDF(zStripDiv, n) > rand)
287 nextStrip = (zStripDiv > 0.0 ? 1 : -1);
290 if ((zStrip >= zMin) && (zStrip <= zMax)) {
291 zStripLower = std::min(zStrip, zStripLower);
292 zStripUpper = std::max(zStrip, zStripUpper);
294 nextStrip = (nextStrip > 0 ? -(1 + nextStrip) : 1 - nextStrip);
The Class for BeamBackground Sensitive Detector.
This class provides a set of constants for the framework.
int stripNumber(int section, int layer, int sector, int plane, int strip) const
Get strip number.
bool beamBackgroundStudy() const
Whether to perform beam-background study.
static const GeometryData & Instance(enum DataSource dataSource=c_Database, const GearDir *gearDir=nullptr)
Instantiation.
void setPropagationTime(float propagationTime)
Set signal propagation time.
void setLastStrip(int lastStrip)
Set last strip number.
void setEnergyDeposit(float eDep)
Set EnergyDeposit.
void setSection(int Section)
Set section number.
void setStrip(int strip)
Set strip number.
void setTime(float time)
Set hit time.
void setSubdetector(int subdetector)
Set subdetector number.
void setPDG(int pdg)
Set the lund code of the (leading) particle.
void setSector(int sector)
Set sector number.
void setPlane(int plane)
Set plane number.
void setLayer(int layer)
Set layer number.
void setPosition(float x, float y, float z)
Set hit global position.
bool stepBKLM(G4Step *, G4TouchableHistory *)
Step in BKLM.
DBObjPtr< BKLMSimulationPar > m_SimPar
Simulation parameters (from DB).
bool stepEKLM(G4Step *, G4TouchableHistory *)
Step in EKLM.
SensitiveDetector(const G4String &name, KLMSubdetectorNumber subdetector)
Constructor.
bool m_FirstCall
Flag to enforce once-only initializations in Initialize().
KLMSubdetectorNumber m_Subdetector
Subdetector.
RelationArray m_MCParticlesToKLMSimHits
Relation array between MCPartices and KLMSimHits.
static constexpr int m_DepthSection
Section depth.
static constexpr int m_DepthSector
Sector depth.
bklm::GeometryPar * m_GeoPar
Pointer to GeometryPar singleton.
const EKLMElementNumbers * m_ElementNumbers
EKLM element numbers.
bool step(G4Step *, G4TouchableHistory *) override
Process each step and store KLMSimHits.
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.
static constexpr int m_DepthScintillator
Scintillator depth.
static constexpr int m_DepthPlane
Plane depth.
void convertHitToRPCStrips(const CLHEP::Hep3Vector &, const bklm::Module *, int &, int &, int &, int &)
Find the ranges of matching RPC strips for BKLM hits.
StoreArray< MCParticle > m_MCParticles
MC particles.
static constexpr int m_DepthLayer
Layer depth.
StoreArray< KLMSimHit > m_KLMSimHits
Simulation hits.
void add(index_type from, index_type to, weight_type weight=1.0)
Add a new element to the relation.
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.
static const double mm
[millimeters]
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.
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.
Class to store variables with their name which were sent to the logging service.
uint16_t KLMSubdetectorNumber
Subdetector number.
bool step(G4Step *aStep, G4TouchableHistory *) override
Process each step and calculate variables defined in PXDSimHit.