1 #ifndef FastTimingSimProducers_FastTimingCommon_FTLDigitizer_h 2 #define FastTimingSimProducers_FastTimingCommon_FTLDigitizer_h 22 #include <unordered_map> 23 #include <unordered_set> 29 namespace FTLHelpers {
34 unsigned int detId_a(std::get<1>(a)), detId_b(std::get<1>(b));
36 if (detId_a < detId_b)
38 if (detId_a > detId_b)
41 double time_a(std::get<2>(a)), time_b(std::get<2>(b));
49 template <
class SensorPhysics,
class ElectronicsSim>
56 maxSimHitsAccTime_(config.getParameter<uint32_t>(
"maxSimHitsAccTime")),
57 bxTime_(config.getParameter<double>(
"bxTime")),
58 tofDelay_(config.getParameter<double>(
"tofDelay")) {}
69 CLHEP::HepRandomEngine* hre)
override;
104 template <
class SensorPhysics,
class ElectronicsSim>
107 CLHEP::HepRandomEngine* hre) {
110 accumulate(simHits, 0, hre);
113 template <
class SensorPhysics,
class ElectronicsSim>
116 CLHEP::HepRandomEngine* hre) {
122 template <
class SensorPhysics,
class ElectronicsSim>
125 CLHEP::HepRandomEngine* hre) {
126 using namespace FTLHelpers;
128 bool weightToAbyEnergy(
false);
132 int nchits = (
int)hits->size();
133 std::vector<FTLCaloHitTuple_t> hitRefs;
134 hitRefs.reserve(nchits);
135 for (
int i = 0;
i < nchits; ++
i) {
136 const auto& the_hit = hits->at(
i);
138 DetId id = (validIds_.count(the_hit.detUnitId()) ? the_hit.detUnitId() : 0);
140 if (verbosity_ > 0) {
141 edm::LogInfo(
"HGCDigitizer") <<
" i/p " << std::hex << the_hit.detUnitId() <<
std::dec <<
" o/p " <<
id.rawId()
145 if (0 !=
id.rawId()) {
146 hitRefs.emplace_back(
i,
id.rawId(), the_hit.tof());
152 nchits = hitRefs.size();
153 for (
int i = 0;
i < nchits; ++
i) {
154 const int hitidx = std::get<0>(hitRefs[
i]);
155 const uint32_t
id = std::get<1>(hitRefs[
i]);
159 if (!validIds_.count(
id))
161 auto simHitIt = simHitAccumulator_.emplace(
id,
FTLCellInfo()).first;
166 const float toa = std::get<2>(hitRefs[
i]);
168 const float charge = deviceSim_.getChargeForHit(hit);
171 const float dist2center(0.1
f * hit.entryPoint().mag());
175 const float tof = toa - dist2center / refSpeed_ + tofDelay_;
176 const int itime = std::floor(tof / bxTime_) + 9;
178 if (itime < 0 || itime > 14)
182 if (itime >= (
int)simHitIt->second.hit_info[0].size())
185 (simHitIt->second).hit_info[0][itime] += charge;
186 float accCharge = (simHitIt->second).hit_info[0][itime];
189 if (weightToAbyEnergy)
190 (simHitIt->second).hit_info[1][itime] += charge * tof;
191 else if ((simHitIt->second).hit_info[1][itime] == 0) {
192 if (accCharge > tdcOnset) {
196 uint32_t prev_id = std::get<1>(hitRefs[
i - 1]);
198 float prev_toa = std::get<2>(hitRefs[
i - 1]);
199 float prev_tof(prev_toa - dist2center / refSpeed_ + tofDelay_);
200 float deltaQ2TDCOnset = tdcOnset - ((simHitIt->second).hit_info[0][itime] - charge);
202 float deltaT = (tof - prev_tof);
203 fireTDC = deltaT * (deltaQ2TDCOnset / deltaQ) + prev_tof;
207 (simHitIt->second).hit_info[1][itime] = fireTDC;
214 template <
class SensorPhysics,
class ElectronicsSim>
216 deviceSim_.getEvent(e);
217 electronicsSim_.getEvent(e);
220 template <
class SensorPhysics,
class ElectronicsSim>
223 CLHEP::HepRandomEngine* hre) {
231 resetSimHitDataAccumulator();
234 template <
class SensorPhysics,
class ElectronicsSim>
236 if (idealGeomWatcher_.check(es)) {
240 std::unordered_set<DetId>().
swap(validIds_);
245 for (
unsigned izeta = 0; izeta < 1 << 10; ++izeta) {
247 if (dddFTL_->isValidXY(
type, izeta,
iphi)) {
254 validIds_.reserve(validIds_.size());
256 deviceSim_.getEventSetup(es);
257 electronicsSim_.getEventSetup(es);
int bunchCrossing() const
FTLDigitizer(const edm::ParameterSet &config, edm::ProducesCollector producesCollector, edm::ConsumesCollector &iC)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
edm::ESHandle< FastTimeDDDConstants > dddFTL_
ElectronicsSim electronicsSim_
ParameterSet const & getParameterSet(ParameterSetID const &id)
edm::ESWatcher< IdealGeometryRecord > idealGeomWatcher_
std::unordered_set< DetId > validIds_
std::tuple< int, uint32_t, float > FTLCaloHitTuple_t
void resetSimHitDataAccumulator()
void swap(Association< C > &lhs, Association< C > &rhs)
std::unordered_map< uint32_t, FTLCellInfo > FTLSimHitDataAccumulator
void beginRun(const edm::EventSetup &es) override
actions at the start/end of run
void finalizeEvent(edm::Event &e, edm::EventSetup const &c, CLHEP::HepRandomEngine *hre) override
FTLSimHitDataAccumulator simHitAccumulator_
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
const int maxSimHitsAccTime_
bool getByLabel(edm::InputTag const &tag, edm::Handle< T > &result) const
void initializeEvent(edm::Event const &e, edm::EventSetup const &c) override
actions at the start/end of event
bool orderByDetIdThenTime(const FTLCaloHitTuple_t &a, const FTLCaloHitTuple_t &b)
void accumulate(edm::Event const &e, edm::EventSetup const &c, CLHEP::HepRandomEngine *hre) override
handle SimHit accumulation