12 #include <klm/modules/KLMDigitizer/KLMDigitizerModule.h>
15 #include <klm/dataobjects/KLMChannelIndex.h>
16 #include <klm/dataobjects/KLMScintillatorFirmwareFitResult.h>
17 #include <klm/simulation/ScintillatorSimulator.h>
20 #include <framework/dataobjects/BackgroundMetaData.h>
21 #include <mdst/dataobjects/MCParticle.h>
34 m_ChannelSpecificSimulation(false),
35 m_EfficiencyMode(c_Plane),
38 setDescription(
"KLM digitization module: create KLMDigits from BKLMSimHits and EKLMSimHits.");
39 setPropertyFlags(c_ParallelProcessingCertified);
40 addParam(
"SimulationMode", m_SimulationMode,
41 "Simulation mode (\"Generic\" or \"ChannelSpecific\").",
42 std::string(
"Generic"));
43 addParam(
"DigitizationInitialTime", m_DigitizationInitialTime,
44 "Initial digitization time in TDC periods.", -40);
45 addParam(
"SaveFPGAFit", m_SaveFPGAFit,
"Save FPGA fit data and set a relation with KLMDigits.",
false);
46 addParam(
"Efficiency", m_Efficiency,
47 "Efficiency determination mode (\"Strip\" or \"Plane\").",
48 std::string(
"Plane"));
49 addParam(
"Debug", m_Debug,
50 "Debug mode (generates additional output files with histograms).",
88 eklmChannel != klmChannels.
endEKLM(); ++eklmChannel) {
90 eklmChannel.getSection(), eklmChannel.getLayer(),
91 eklmChannel.getSector(), eklmChannel.getPlane(),
92 eklmChannel.getStrip());
94 if (channel ==
nullptr)
95 B2FATAL(
"Incomplete channel data.");
96 if (channel->getPhotoelectronAmplitude() <= 0) {
97 B2ERROR(
"Non-positive photoelectron amplitude. The requested "
98 "channel-specific simulation is impossible. "
99 "KLMDigitizer is switched to the generic mode."
100 <<
LogVar(
"Section", eklmChannel.getSection())
101 <<
LogVar(
"Layer", eklmChannel.getLayer())
102 <<
LogVar(
"Sector", eklmChannel.getSector())
103 <<
LogVar(
"Plane", eklmChannel.getPlane())
104 <<
LogVar(
"Strip", eklmChannel.getStrip()));
114 B2FATAL(
"KLM digitization parameters are not available.");
116 B2FATAL(
"KLM time conversion parameters are not available.");
118 B2FATAL(
"EKLM channel data are not available.");
120 B2FATAL(
"KLM channel status data are not available.");
122 B2FATAL(
"KLM strip efficiency data are not available.");
138 B2FATAL(
"Incomplete KLM channel status data.");
144 if (isnan(efficiency))
145 B2FATAL(
"Incomplete KLM efficiency data.");
146 double selection = gRandom->Rndm();
147 return (selection < efficiency);
154 std::multimap<uint16_t, const BKLMSimHit*>::iterator it, it2, ub;
159 bool rpc = simHit->
inRPC();
174 double time = hit->getTime();
177 if (it2->second->getTime() < time) {
178 time = it2->second->getTime();
195 KLM::c_ScintillatorFirmwareSuccessfulFit) {
207 if (simulator.
getFitStatus() == KLM::c_ScintillatorFirmwareSuccessfulFit &&
225 std::multimap<uint16_t, const EKLMSimHit*>::iterator it, ub;
242 channelData =
m_Channels->getChannelData(strip);
243 if (channelData ==
nullptr)
244 B2FATAL(
"Incomplete EKLM channel data.");
256 if (simulator.
getFitStatus() == KLM::c_ScintillatorFirmwareSuccessfulFit) {
268 if (simulator.
getFitStatus() == KLM::c_ScintillatorFirmwareSuccessfulFit &&
289 if (hit->getStripMin() <= 0)
297 if (particle !=
nullptr) {
299 hit->getSection(), hit->getSector(),
300 hit->getLayer(), hit->getPlane());
302 std::pair<uint16_t, const BKLMSimHit*>(plane, hit));
304 B2ASSERT(
"The BKLMSimHit is not related to any MCParticle and "
305 "it is also not a beam background hit.",
308 hit->getSection(), hit->getSector(), hit->getLayer(),
309 hit->getPlane(), hit->getStrip());
312 std::pair<uint16_t, const BKLMSimHit*>(channel, hit));
315 std::multimap<uint16_t, const BKLMSimHit*>::iterator it, it2;
316 std::multimap<const MCParticle*, const BKLMSimHit*> particleHitMap;
317 std::multimap<const MCParticle*, const BKLMSimHit*>::iterator
318 itParticle, it2Particle;
321 particleHitMap.clear();
326 particleHitMap.insert(
327 std::pair<const MCParticle*, const BKLMSimHit*>(particle, hit));
331 if (it2->first != it->first)
334 itParticle = particleHitMap.begin();
335 while (itParticle != particleHitMap.end()) {
336 it2Particle = itParticle;
339 hit->getSection(), hit->getSector(),
340 hit->getLayer(), hit->getPlane(),
344 hit = it2Particle->second;
346 for (
int s = hit->getStripMin(); s <= hit->getStripMax(); ++s) {
348 hit->getSection(), hit->getSector(), hit->getLayer(),
352 std::pair<uint16_t, const BKLMSimHit*>(channel, hit));
357 if (it2Particle == particleHitMap.end())
359 if (it2Particle->first != itParticle->first)
362 itParticle = it2Particle;
378 if (particle !=
nullptr) {
380 hit->getSection(), hit->getSector(),
381 hit->getLayer(), hit->getPlane());
383 std::pair<uint16_t, const EKLMSimHit*>(plane, hit));
385 B2ASSERT(
"The EKLMSimHit is not related to any MCParticle and "
386 "it is also not a beam background hit.",
389 hit->getSection(), hit->getSector(), hit->getLayer(),
390 hit->getPlane(), hit->getStrip());
393 std::pair<uint16_t, const EKLMSimHit*>(channel, hit));
396 std::multimap<uint16_t, const EKLMSimHit*>::iterator it, it2;
397 std::multimap<const MCParticle*, const EKLMSimHit*> particleHitMap;
398 std::multimap<const MCParticle*, const EKLMSimHit*>::iterator
399 itParticle, it2Particle;
402 particleHitMap.clear();
407 particleHitMap.insert(
408 std::pair<const MCParticle*, const EKLMSimHit*>(particle, hit));
412 if (it2->first != it->first)
415 itParticle = particleHitMap.begin();
416 while (itParticle != particleHitMap.end()) {
417 it2Particle = itParticle;
420 hit->getSection(), hit->getSector(),
421 hit->getLayer(), hit->getPlane(),
425 hit = it2Particle->second;
428 hit->getSection(), hit->getSector(), hit->getLayer(),
429 hit->getPlane(), hit->getStrip());
432 std::pair<uint16_t, const EKLMSimHit*>(channel, hit));
436 if (it2Particle == particleHitMap.end())
438 if (it2Particle->first != itParticle->first)
441 itParticle = it2Particle;
450 if (hit->getStripMin() <= 0)
452 for (
int s = hit->getStripMin(); s <= hit->getStripMax(); ++s) {
454 hit->getSection(), hit->getSector(), hit->getLayer(),
458 std::pair<uint16_t, const BKLMSimHit*>(channel, hit));
463 hit->getSection(), hit->getSector(), hit->getLayer(),
464 hit->getPlane(), hit->getStrip());
467 std::pair<uint16_t, const BKLMSimHit*>(channel, hit));
474 hit->getSection(), hit->getSector(), hit->getLayer(),
475 hit->getPlane(), hit->getStrip());
478 std::pair<uint16_t, const EKLMSimHit*>(channel, hit));