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 edm::LogWarning(
"MTDMix") <<
"MTDDigitizer:: Cannot find hits for " << inputSimHits_;
188 template <
class Traits>
191 CLHEP::HepRandomEngine* hre) {
193 e.getByLabel(inputSimHits_,
simHits);
195 accumulate(
simHits,
e.bunchCrossing(), hre);
197 edm::LogWarning(
"MTDMix") <<
"MTDDigitizer:: Cannot find hits for " << inputSimHits_;
200 template <
class Traits>
203 CLHEP::HepRandomEngine* hre) {
204 using namespace MTDHelpers;
207 int nchits = (
int)
hits->size();
208 std::vector<MTDCaloHitTuple_t> hitRefs;
209 hitRefs.reserve(nchits);
210 for (
int i = 0;
i < nchits; ++
i) {
211 const auto& the_hit =
hits->at(
i);
213 DetId id = the_hit.detUnitId();
215 if (verbosity_ > 0) {
216 edm::LogInfo(
"MTDDigitizer") <<
" i/p " << std::hex << the_hit.detUnitId() <<
std::dec <<
" o/p " <<
id.rawId()
220 if (0 !=
id.
rawId()) {
221 hitRefs.emplace_back(
i,
id.
rawId(), the_hit.tof());
226 deviceSim_.getHitsResponse(hitRefs,
hits, &simHitAccumulator_, hre);
231 template <
class Traits>
233 loadSimHitAccumulator(simHitAccumulator_, simAccumulator, premixStage1MinCharge_, premixStage1MaxCharge_);
236 template <
class Traits>
238 geom_ = &
c.getData(geomToken_);
240 deviceSim_.getEvent(
e);
241 deviceSim_.getEventSetup(
c);
242 if (not premixStage1_) {
243 electronicsSim_.getEvent(
e);
244 electronicsSim_.getEventSetup(
c);
248 template <
class Traits>
251 auto simResult = std::make_unique<PMTDSimAccumulator>();
252 saveSimHitAccumulator(*simResult, simHitAccumulator_, premixStage1MinCharge_, premixStage1MaxCharge_);
261 resetSimHitDataAccumulator();
void accumulate(edm::Event const &e, edm::EventSetup const &c, CLHEP::HepRandomEngine *hre) override
handle SimHit accumulation
static constexpr unsigned energyMask
void emplace_back(unsigned int detId, unsigned char row, unsigned char column, unsigned short energyIndex, unsigned short sampleIndex, unsigned short data)
void saveSimHitAccumulator(PMTDSimAccumulator &simResult, const MTDSimHitDataAccumulator &simData, const float minCharge, const float maxCharge)
void reserve(size_t size)
MTDSimHitDataAccumulator simHitAccumulator_
std::unordered_map< MTDCellId, MTDCellInfo > MTDSimHitDataAccumulator
double unpack16log(int16_t i, double lmin, double lmax, uint16_t base=32768)
void finalizeEvent(edm::Event &e, edm::EventSetup const &c, CLHEP::HepRandomEngine *hre) override
constexpr float PREMIX_MAX_TOF
const int maxSimHitsAccTime_
Traits::ElectronicsSim ElectronicsSim
Traits::DigiCollection DigiCollection
std::tuple< int, uint32_t, float > MTDCaloHitTuple_t
void initializeEvent(edm::Event const &e, edm::EventSetup const &c) override
actions at the start/end of event
Log< level::Info, false > LogInfo
const edm::ESGetToken< MTDGeometry, MTDDigiGeometryRecord > geomToken_
bool orderByDetIdThenTime(const MTDCaloHitTuple_t &a, const MTDCaloHitTuple_t &b)
ParameterSet const & getParameterSet(ParameterSetID const &id)
MTDDigitizer(const edm::ParameterSet &config, edm::ProducesCollector producesCollector, edm::ConsumesCollector &iC)
const MTDGeometry * geom_
static constexpr unsigned dataMask
static constexpr unsigned sampleMask
constexpr size_t nSamples
ElectronicsSim electronicsSim_
void resetSimHitDataAccumulator()
Log< level::Warning, false > LogWarning
Traits::DeviceSim DeviceSim
int16_t pack16log(double x, double lmin, double lmax, uint16_t base=32768)
void loadSimHitAccumulator(MTDSimHitDataAccumulator &simData, const PMTDSimAccumulator &simAccumulator, const float minCharge, const float maxCharge)