9 #include "CLHEP/Random/RandGaussZiggurat.h"
25 return StatusCode::SUCCESS;
35 using DigitSDOPair = std::pair<std::unique_ptr<MdtDigit>,
TimedHit>;
51 std::vector<DigitSDOPair> digitsInChamber{};
56 if (!badTubes->isGood(hitId)) {
67 const Amg::Vector3D locPos{xAOD::toEigen(simHit->localPosition())};
70 const MdtDigiToolInput digiInput(std::abs(locPos.perp()), distRO, 0., 0., 0., 0., hitId);
76 const double arrivalTime{simHit->globalTime()};
79 assert(tubeConstants !=
nullptr);
81 assert(tubeConstants->
tubeCalib->getCalib(hitId) !=
nullptr);
85 const double sigPropTime = tubeCalib.inversePropSpeed*distRO;
89 const double totalTdcTime = digiOutput.
driftTime() + arrivalTime + tubeCalib.t0 + sigPropTime;
90 if (lastTube != hitId ||
deadTime < totalTdcTime) {
101 const uint16_t tdcCounts = timeToTdcCnv*(hasHPTdc ? 4 : 1)*CLHEP::RandGaussZiggurat::shoot(rndEngine, totalTdcTime,
m_timeResTDC);
102 const uint16_t adcCounts = (hasHPTdc ? 4 : 1) *CLHEP::RandGaussZiggurat::shoot(rndEngine, digiOutput.
adc(),
m_timeResADC);
104 auto digit = std::make_unique<MdtDigit>(hitId, tdcCounts, adcCounts,
false);
106 digitsInChamber.push_back(std::make_pair(std::move(
digit), simHit));
108 if (!twinTubes || !twinTubes->isTwinTubeLayer(hitId)) {
111 const Identifier twinId{twinTubes->twinId(hitId)};
112 if (twinId == hitId) {
117 if (!readOutEle->
isValid(twinHash)) {
126 <<
", tube length: "<<readOutEle->
activeTubeLength(measHash)<<
", distRO: "<<distRO
128 <<
", twin distance: "<<twinDist);
131 const double twinPropTime = tubeCalib.inversePropSpeed*twinDist;
134 const double twinTdcTime = digiOutput.
driftTime() + arrivalTime + twinPropTime
135 + twinCalib.t0 + twinTubes->hvDelayTime(twinId);
137 const uint16_t twinTdcCounts = timeToTdcCnv*(hasHPTdc ? 4 : 1)*CLHEP::RandGaussZiggurat::shoot(rndEngine, twinTdcTime,
m_resTwin);
138 const uint16_t twinAdcCoutns = (hasHPTdc ? 4 : 1) *CLHEP::RandGaussZiggurat::shoot(rndEngine, digiOutput.
adc(),
m_timeResADC);
139 digit = std::make_unique<MdtDigit>(twinId, twinTdcCounts, twinAdcCoutns,
false);
141 <<
", adc: "<<
digit->adc()<<
", local z: "<<simHit->localPosition().z());
142 digitsInChamber.push_back(std::make_pair(std::move(
digit), simHit));
146 std::ranges::sort(digitsInChamber,[](
const DigitSDOPair&
a,
const DigitSDOPair&
b){
147 if (
a.first->identify() !=
b.first->identify()) {
148 return a.first->identify() < b.first->identify();
150 return a.first->tdc() <
b.first->tdc();
154 addSDO(saveMe->second, sdoContainer);
155 const MdtDigit* saved =
fetchCollection(saveMe->first->identify(), digitCache)->push_back(std::move(saveMe->first));
158 saveMe = std::find_if(saveMe +1, digitsInChamber.end(),
159 [deadInterval, saved](
const DigitSDOPair& digitized) {
160 return saved->identify() != digitized.first->identify() || deadInterval < saved->tdc();
163 }
while (viewer.next());
166 return StatusCode::SUCCESS;