1 #ifndef FastTimingSimProducers_FastTimingCommon_MTDDigitizer_h 2 #define FastTimingSimProducers_FastTimingCommon_MTDDigitizer_h 29 #include <unordered_map> 30 #include <unordered_set> 37 namespace MTDHelpers {
43 unsigned int detId_a(std::get<1>(a)), detId_b(std::get<1>(b));
45 if(detId_a<detId_b)
return true;
46 if(detId_a>detId_b)
return false;
48 double time_a(std::get<2>(a)), time_b(std::get<2>(b));
49 if(time_a<time_b)
return true;
61 const float minPackChargeLog = minCharge > 0.f ?
std::log(minCharge) : -2;
62 const float maxPackChargeLog =
std::log(maxCharge);
65 simResult.
reserve(simData.size());
67 for(
const auto&
elem: simData) {
69 for(
size_t iEn = 0; iEn < nEnergies; ++iEn) {
71 for(
size_t iSample = 0; iSample <
nSamples; ++iSample) {
72 if(
samples[iSample] > minCharge) {
73 unsigned short packed;
82 iEn, iSample, packed);
91 const float minPackChargeLog = minCharge > 0.f ?
std::log(minCharge) : -2;
92 const float maxPackChargeLog =
std::log(maxCharge);
95 for(
const auto& detIdIndexHitInfo: simAccumulator) {
96 auto foo = simData.emplace(
MTDCellId(detIdIndexHitInfo.detId(), detIdIndexHitInfo.row(), detIdIndexHitInfo.column()),
98 auto simIt = foo.first;
99 auto& hit_info = simIt->second.hit_info;
101 size_t iEn = detIdIndexHitInfo.energyIndex();
102 size_t iSample = detIdIndexHitInfo.sampleIndex();
106 value =
static_cast<float>(detIdIndexHitInfo.data())/base*
PREMIX_MAX_TOF;
113 hit_info[iEn][iSample] +=
value;
115 else if(hit_info[iEn][iSample] == 0) {
117 hit_info[iEn][iSample] =
value;
122 template<
class Traits>
138 maxSimHitsAccTime_( config.getParameter< uint32_t >(
"maxSimHitsAccTime") ) { }
181 template<
class Traits>
184 CLHEP::HepRandomEngine* hre) {
187 accumulate(simHits,0,hre);
190 template<
class Traits>
193 CLHEP::HepRandomEngine* hre){
199 template<
class Traits>
202 CLHEP::HepRandomEngine* hre) {
203 using namespace MTDHelpers;
206 int nchits=(
int)hits->size();
207 std::vector< MTDCaloHitTuple_t > hitRefs;
208 hitRefs.reserve(nchits);
209 for(
int i=0;
i<nchits; ++
i) {
210 const auto& the_hit = hits->at(
i);
212 DetId id = the_hit.detUnitId();
216 <<
" o/p " <<
id.rawId() << std::endl;
219 if( 0 !=
id.rawId() ) {
220 hitRefs.emplace_back(
i,
id.rawId(), the_hit.tof() );
225 deviceSim_.getHitsResponse(hitRefs, hits, &simHitAccumulator_, hre);
231 template<
class Traits>
233 loadSimHitAccumulator(simHitAccumulator_, simAccumulator, premixStage1MinCharge_, premixStage1MaxCharge_);
236 template<
class Traits>
238 deviceSim_.getEvent(e);
239 if(not premixStage1_) {
240 electronicsSim_.getEvent(e);
244 template<
class Traits>
246 CLHEP::HepRandomEngine* hre) {
248 auto simResult = std::make_unique<PMTDSimAccumulator>();
249 saveSimHitAccumulator(*simResult, simHitAccumulator_, premixStage1MinCharge_, premixStage1MaxCharge_);
259 resetSimHitDataAccumulator();
263 template<
class Traits>
270 deviceSim_.getEventSetup(es);
271 if(not premixStage1_) {
272 electronicsSim_.getEventSetup(es);
int bunchCrossing() const
void accumulate(edm::Event const &e, edm::EventSetup const &c, CLHEP::HepRandomEngine *hre) override
handle SimHit accumulation
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
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)
ParameterSet const & getParameterSet(ParameterSetID const &id)
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_
void beginRun(const edm::EventSetup &es) override
actions at the start/end of run
Traits::ElectronicsSim ElectronicsSim
Traits::DigiCollection DigiCollection
base
Make Sure CMSSW is Setup ##.
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
def elem(elemtype, innerHTML='', html_class='', kwargs)
void initializeEvent(edm::Event const &e, edm::EventSetup const &c) override
actions at the start/end of event
bool orderByDetIdThenTime(const MTDCaloHitTuple_t &a, const MTDCaloHitTuple_t &b)
std::tuple< int, uint32_t, float > MTDCaloHitTuple_t
const MTDGeometry * geom_
bool getByLabel(edm::InputTag const &tag, edm::Handle< T > &result) const
MTDDigitizer(const edm::ParameterSet &config, edm::ConsumesCollector &iC, edm::ProducerBase &parent)
static constexpr unsigned sampleMask
constexpr size_t nSamples
ElectronicsSim electronicsSim_
void resetSimHitDataAccumulator()
static constexpr unsigned sampleOffset
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)
T const * product() const