12 #include <klm/bklm/simulation/SensitiveDetector.h>
15 #include <klm/bklm/geometry/GeometryPar.h>
16 #include <klm/bklm/geometry/Module.h>
17 #include <klm/dataobjects/bklm/BKLMElementNumbers.h>
18 #include <klm/dataobjects/bklm/BKLMSimHit.h>
19 #include <klm/dataobjects/bklm/BKLMSimHitPosition.h>
20 #include <klm/dataobjects/bklm/BKLMStatus.h>
23 #include <framework/datastore/StoreArray.h>
24 #include <simulation/background/BkgSensitiveDetector.h>
25 #include <mdst/dataobjects/MCParticle.h>
29 #include <G4VProcess.hh>
32 #include <CLHEP/Units/SystemOfUnits.h>
33 #include <CLHEP/Vector/ThreeVector.h>
38 #define DEPTH_SECTION 2
39 #define DEPTH_SECTOR 3
42 #define DEPTH_SCINT 10
45 using namespace Belle2::bklm;
47 SensitiveDetector::SensitiveDetector(
const G4String& name) :
48 SensitiveDetectorBase(name,
Const::KLM),
50 m_BkgSensitiveDetector(nullptr),
54 B2FATAL(
"BKLM simulation parameters are not available.");
60 simHits.registerInDataStore();
61 simHitPositions.registerInDataStore();
62 particles.registerRelationTo(simHits);
80 B2FATAL(
"BKLM simulation parameters are not available.");
83 B2FATAL(
"gRandom is not initialized; please set up gRandom first");
103 double eDep =
step->GetTotalEnergyDeposit() / CLHEP::MeV;
104 G4StepPoint* preStep =
step->GetPreStepPoint();
105 G4StepPoint* postStep =
step->GetPostStepPoint();
106 G4Track* track =
step->GetTrack();
109 if ((eDep > 0.0) && (postStep->GetCharge() != 0.0)) {
110 const G4VTouchable* hist = preStep->GetTouchable();
111 int depth = hist->GetHistoryDepth();
112 if (depth < DEPTH_PLANE) {
113 B2WARNING(
"BKLM SensitiveDetector::step(): "
114 <<
LogVar(
"Touchable HistoryDepth", depth)
115 <<
LogVar(
" should be at least", DEPTH_PLANE));
118 int plane = hist->GetCopyNumber(depth - DEPTH_PLANE);
119 int layer = hist->GetCopyNumber(depth - DEPTH_LAYER);
120 int sector = hist->GetCopyNumber(depth - DEPTH_SECTOR);
121 int section = hist->GetCopyNumber(depth - DEPTH_SECTION);
124 double time = 0.5 * (preStep->GetGlobalTime() + postStep->GetGlobalTime());
127 const CLHEP::Hep3Vector globalPosition = 0.5 * (preStep->GetPosition() + postStep->GetPosition()) / CLHEP::cm;
129 const CLHEP::Hep3Vector localPosition = m->globalToLocal(globalPosition);
130 if (postStep->GetProcessDefinedStep() != 0) {
131 if (postStep->GetProcessDefinedStep()->GetProcessType() == fDecay) { moduleID |= BKLM_DECAYED_MASK; }
133 int trackID = track->GetTrackID();
135 const CLHEP::Hep3Vector propagationTimes =
136 m->getPropagationTimes(localPosition);
137 int phiStripLower = -1;
138 int phiStripUpper = -1;
139 int zStripLower = -1;
140 int zStripUpper = -1;
142 if (zStripLower > 0) {
143 int moduleIDZ = moduleID;
153 if (phiStripLower > 0) {
164 int scint = hist->GetCopyNumber(depth - DEPTH_SCINT);
165 bool phiPlane = (plane == BKLM_INNER);
166 double propagationTime =
167 m->getPropagationTime(localPosition, scint, phiPlane);
189 int& phiStripLower,
int& phiStripUpper,
int& zStripLower,
int& zStripUpper)
191 double phiStripD = m->getPhiStrip(localPosition);
192 int phiStrip = int(phiStripD);
193 int pMin = m->getPhiStripMin();
194 if (phiStrip < pMin)
return;
195 int pMax = m->getPhiStripMax();
196 if (phiStrip > pMax)
return;
198 double zStripD = m->getZStrip(localPosition);
199 int zStrip = int(zStripD);
200 int zMin = m->getZStripMin();
201 if (zStrip < zMin)
return;
202 int zMax = m->getZStripMax();
203 if (zStrip > zMax)
return;
205 phiStripLower = phiStrip;
206 phiStripUpper = phiStrip;
207 zStripLower = zStrip;
208 zStripUpper = zStrip;
209 double phiStripDiv = fmod(phiStripD, 1.0) - 0.5;
210 double zStripDiv = fmod(zStripD, 1.0) - 0.5;
212 double rand = gRandom->Uniform();
213 for (n = 1; n <
m_SimPar->getMaxMultiplicity(); ++n) {
214 if (
m_SimPar->getPhiMultiplicityCDF(phiStripDiv, n) > rand)
break;
216 int nextStrip = (phiStripDiv > 0.0 ? 1 : -1);
218 phiStrip += nextStrip;
219 if ((phiStrip >= pMin) && (phiStrip <= pMax)) {
220 phiStripLower = min(phiStrip, phiStripLower);
221 phiStripUpper = max(phiStrip, phiStripUpper);
223 nextStrip = (nextStrip > 0 ? -(1 + nextStrip) : 1 - nextStrip);
225 rand = gRandom->Uniform();
226 for (n = 1; n <
m_SimPar->getMaxMultiplicity(); ++n) {
227 if (
m_SimPar->getZMultiplicityCDF(zStripDiv, n) > rand)
break;
229 nextStrip = (zStripDiv > 0.0 ? 1 : -1);
232 if ((zStrip >= zMin) && (zStrip <= zMax)) {
233 zStripLower = min(zStrip, zStripLower);
234 zStripUpper = max(zStrip, zStripUpper);
236 nextStrip = (nextStrip > 0 ? -(1 + nextStrip) : 1 - nextStrip);