1 #ifndef FastTimingSimProducers_FastTimingCommon_MTDDigitizer_h
2 #define FastTimingSimProducers_FastTimingCommon_MTDDigitizer_h
29 #include <unordered_map>
30 #include <unordered_set>
36 namespace MTDHelpers {
41 unsigned int detId_a(std::get<1>(
a)), detId_b(std::get<1>(
b));
43 if (detId_a < detId_b)
45 if (detId_a > detId_b)
48 double time_a(std::get<2>(
a)), time_b(std::get<2>(
b));
58 const float minCharge,
59 const float maxCharge) {
62 "PMTDSimAccumulator bit pattern needs to be updated");
64 "PMTDSimAccumulator bit pattern needs to be updated");
66 const float minPackChargeLog = minCharge > 0.f ?
std::log(minCharge) : -2;
67 const float maxPackChargeLog =
std::log(maxCharge);
70 simResult.
reserve(simData.size());
72 for (
const auto& elem : simData) {
74 for (
size_t iEn = 0; iEn < nEnergies; ++iEn) {
75 const auto&
samples = elem.second.hit_info[iEn];
76 for (
size_t iSample = 0; iSample <
nSamples; ++iSample) {
77 if (
samples[iSample] > minCharge) {
78 unsigned short packed;
79 if (iEn == 1 || iEn == 3) {
85 simResult.
emplace_back(elem.first.detid_, elem.first.row_, elem.first.column_, iEn, iSample, packed);
94 const float minCharge,
95 const float maxCharge) {
96 const float minPackChargeLog = minCharge > 0.f ?
std::log(minCharge) : -2;
97 const float maxPackChargeLog =
std::log(maxCharge);
100 for (
const auto& detIdIndexHitInfo : simAccumulator) {
101 auto foo = simData.emplace(
102 MTDCellId(detIdIndexHitInfo.detId(), detIdIndexHitInfo.row(), detIdIndexHitInfo.column()),
MTDCellInfo());
103 auto simIt = foo.first;
104 auto& hit_info = simIt->second.hit_info;
106 size_t iEn = detIdIndexHitInfo.energyIndex();
107 size_t iSample = detIdIndexHitInfo.sampleIndex();
111 <<
"Index out of range: iEn = " << iEn <<
" iSample = " << iSample << std::endl;
114 if (iEn == 1 || iEn == 3) {
120 if (iEn == 0 || iEn == 2) {
121 hit_info[iEn][iSample] +=
value;
122 }
else if (hit_info[iEn][iSample] == 0 ||
value < hit_info[iEn][iSample]) {
124 hit_info[iEn][iSample] =
value;
129 template <
class Traits>
153 CLHEP::HepRandomEngine* hre)
override;
178 template <
class Traits>
181 e.getByLabel(inputSimHits_,
simHits);
185 template <
class Traits>
188 CLHEP::HepRandomEngine* hre) {
190 e.getByLabel(inputSimHits_,
simHits);
191 accumulate(
simHits,
e.bunchCrossing(), hre);
194 template <
class Traits>
197 CLHEP::HepRandomEngine* hre) {
198 using namespace MTDHelpers;
201 int nchits = (
int)
hits->size();
202 std::vector<MTDCaloHitTuple_t> hitRefs;
203 hitRefs.reserve(nchits);
204 for (
int i = 0;
i < nchits; ++
i) {
205 const auto& the_hit =
hits->at(
i);
207 DetId id = the_hit.detUnitId();
209 if (verbosity_ > 0) {
210 edm::LogInfo(
"MTDDigitizer") <<
" i/p " << std::hex << the_hit.detUnitId() <<
std::dec <<
" o/p " <<
id.rawId()
214 if (0 !=
id.rawId()) {
215 hitRefs.emplace_back(
i,
id.rawId(), the_hit.tof());
220 deviceSim_.getHitsResponse(hitRefs,
hits, &simHitAccumulator_, hre);
225 template <
class Traits>
227 loadSimHitAccumulator(simHitAccumulator_, simAccumulator, premixStage1MinCharge_, premixStage1MaxCharge_);
230 template <
class Traits>
232 geom_ = &
c.getData(geomToken_);
234 deviceSim_.getEvent(
e);
235 deviceSim_.getEventSetup(
c);
236 if (not premixStage1_) {
237 electronicsSim_.getEvent(
e);
238 electronicsSim_.getEventSetup(
c);
242 template <
class Traits>
245 auto simResult = std::make_unique<PMTDSimAccumulator>();
246 saveSimHitAccumulator(*simResult, simHitAccumulator_, premixStage1MinCharge_, premixStage1MaxCharge_);
255 resetSimHitDataAccumulator();