1 #ifndef FastTimingSimProducers_FastTimingCommon_FTLDigitizer_h 2 #define FastTimingSimProducers_FastTimingCommon_FTLDigitizer_h 21 #include <unordered_map> 22 #include <unordered_set> 29 namespace FTLHelpers {
35 unsigned int detId_a(std::get<1>(a)), detId_b(std::get<1>(b));
37 if(detId_a<detId_b)
return true;
38 if(detId_a>detId_b)
return false;
40 double time_a(std::get<2>(a)), time_b(std::get<2>(b));
41 if(time_a<time_b)
return true;
47 template<
class SensorPhysics,
class ElectronicsSim>
58 maxSimHitsAccTime_( config.getParameter< uint32_t >(
"maxSimHitsAccTime") ),
59 bxTime_( config.getParameter< double >(
"bxTime") ),
60 tofDelay_( config.getParameter< double >(
"tofDelay") ) { }
107 template<
class SensorPhysics,
class ElectronicsSim>
110 CLHEP::HepRandomEngine* hre) {
113 accumulate(simHits,0,hre);
116 template<
class SensorPhysics,
class ElectronicsSim>
119 CLHEP::HepRandomEngine* hre){
125 template<
class SensorPhysics,
class ElectronicsSim>
128 CLHEP::HepRandomEngine* hre) {
129 using namespace FTLHelpers;
131 bool weightToAbyEnergy(
false);
135 int nchits=(
int)hits->size();
136 std::vector< FTLCaloHitTuple_t > hitRefs;
137 hitRefs.reserve(nchits);
138 for(
int i=0;
i<nchits; ++
i) {
139 const auto& the_hit = hits->at(
i);
141 DetId id = ( validIds_.count(the_hit.detUnitId()) ? the_hit.detUnitId() : 0 );
145 <<
" o/p " <<
id.rawId() << std::endl;
148 if( 0 !=
id.rawId() ) {
149 hitRefs.emplace_back(
i,
id.rawId(), the_hit.tof() );
155 nchits = hitRefs.size();
156 for(
int i=0;
i<nchits; ++
i) {
157 const int hitidx = std::get<0>(hitRefs[
i]);
158 const uint32_t
id = std::get<1>(hitRefs[
i]);
162 if( !validIds_.count(
id) )
continue;
163 auto simHitIt = simHitAccumulator_.emplace(
id,
FTLCellInfo()).first;
167 const float toa = std::get<2>(hitRefs[
i]);
169 const float charge = deviceSim_.getChargeForHit(hit);
172 const float dist2center( 0.1
f*hit.entryPoint().mag() );
176 const float tof = toa-dist2center/refSpeed_+tofDelay_ ;
177 const int itime= std::floor( tof/bxTime_ ) + 9;
183 if(itime<0 || itime>14)
continue;
186 if(itime >= (
int)simHitIt->second.hit_info[0].size() )
continue;
188 (simHitIt->second).hit_info[0][itime] += charge;
189 float accCharge=(simHitIt->second).hit_info[0][itime];
192 if(weightToAbyEnergy) (simHitIt->second).hit_info[1][itime] += charge*tof;
193 else if((simHitIt->second).hit_info[1][itime]==0)
195 if( accCharge>tdcOnset )
201 uint32_t prev_id = std::get<1>(hitRefs[
i-1]);
204 float prev_toa = std::get<2>(hitRefs[
i-1]);
205 float prev_tof(prev_toa-dist2center/refSpeed_+tofDelay_);
207 float deltaQ2TDCOnset = tdcOnset-((simHitIt->second).hit_info[0][itime]-charge);
209 float deltaT = (tof-prev_tof);
210 fireTDC = deltaT*(deltaQ2TDCOnset/deltaQ)+prev_tof;
214 (simHitIt->second).hit_info[1][itime]=fireTDC;
221 template<
class SensorPhysics,
class ElectronicsSim>
223 deviceSim_.getEvent(e);
224 electronicsSim_.getEvent(e);
227 template<
class SensorPhysics,
class ElectronicsSim>
229 CLHEP::HepRandomEngine* hre) {
237 resetSimHitDataAccumulator();
241 template<
class SensorPhysics,
class ElectronicsSim>
243 if ( idealGeomWatcher_.check(es) ) {
247 std::unordered_set<DetId>().
swap(validIds_);
252 for(
unsigned izeta = 0; izeta < 1<<10; ++izeta ) {
253 for(
unsigned iphi = 0; iphi < 1<<10; ++iphi ) {
255 if( dddFTL_->isValidXY(
type, izeta, iphi) ) {
266 validIds_.reserve(validIds_.size());
268 deviceSim_.getEventSetup(es);
269 electronicsSim_.getEventSetup(es);
int bunchCrossing() const
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_
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
std::tuple< int, uint32_t, float > FTLCaloHitTuple_t
FTLDigitizer(const edm::ParameterSet &config, edm::ConsumesCollector &iC, edm::ProducerBase &parent)
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