1 #ifndef FastTimingSimProducers_FastTimingCommon_FTLDigitizer_h 2 #define FastTimingSimProducers_FastTimingCommon_FTLDigitizer_h 20 #include <unordered_map> 21 #include <unordered_set> 31 return hash<uint32_t>()(detid.
rawId());
38 namespace FTLHelpers {
44 unsigned int detId_a(std::get<1>(a)), detId_b(std::get<1>(b));
46 if(detId_a<detId_b)
return true;
47 if(detId_a>detId_b)
return false;
49 double time_a(std::get<2>(a)), time_b(std::get<2>(b));
50 if(time_a<time_b)
return true;
56 template<
class SensorPhysics,
class ElectronicsSim>
67 maxSimHitsAccTime_( config.getParameter< uint32_t >(
"maxSimHitsAccTime") ),
68 bxTime_( config.getParameter< double >(
"bxTime") ),
69 tofDelay_( config.getParameter< double >(
"tofDelay") ) { }
116 template<
class SensorPhysics,
class ElectronicsSim>
119 CLHEP::HepRandomEngine* hre) {
122 accumulate(simHits,0,hre);
125 template<
class SensorPhysics,
class ElectronicsSim>
128 CLHEP::HepRandomEngine* hre){
134 template<
class SensorPhysics,
class ElectronicsSim>
137 CLHEP::HepRandomEngine* hre) {
138 using namespace FTLHelpers;
140 bool weightToAbyEnergy(
false);
144 int nchits=(
int)hits->size();
145 std::vector< FTLCaloHitTuple_t > hitRefs;
146 hitRefs.reserve(nchits);
147 for(
int i=0;
i<nchits; ++
i) {
148 const auto& the_hit = hits->at(
i);
150 DetId id = ( validIds_.count(the_hit.detUnitId()) ? the_hit.detUnitId() : 0 );
154 <<
" o/p " <<
id.rawId() << std::endl;
157 if( 0 !=
id.rawId() ) {
158 hitRefs.emplace_back(
i,
id.rawId(), the_hit.tof() );
164 nchits = hitRefs.size();
165 for(
int i=0;
i<nchits; ++
i) {
166 const int hitidx = std::get<0>(hitRefs[
i]);
167 const uint32_t
id = std::get<1>(hitRefs[
i]);
171 if( !validIds_.count(
id) )
continue;
172 auto simHitIt = simHitAccumulator_.emplace(
id,
FTLCellInfo()).first;
176 const float toa = std::get<2>(hitRefs[
i]);
178 const float charge = deviceSim_.getChargeForHit(hit);
181 const float dist2center( 0.1
f*hit.entryPoint().mag() );
185 const float tof = toa-dist2center/refSpeed_+tofDelay_ ;
186 const int itime= std::floor( tof/bxTime_ ) + 9;
192 if(itime<0 || itime>14)
continue;
195 if(itime >= (
int)simHitIt->second.hit_info[0].size() )
continue;
197 (simHitIt->second).hit_info[0][itime] += charge;
198 float accCharge=(simHitIt->second).hit_info[0][itime];
201 if(weightToAbyEnergy) (simHitIt->second).hit_info[1][itime] += charge*tof;
202 else if((simHitIt->second).hit_info[1][itime]==0)
204 if( accCharge>tdcOnset )
210 uint32_t prev_id = std::get<1>(hitRefs[
i-1]);
213 float prev_toa = std::get<2>(hitRefs[
i-1]);
214 float prev_tof(prev_toa-dist2center/refSpeed_+tofDelay_);
216 float deltaQ2TDCOnset = tdcOnset-((simHitIt->second).hit_info[0][itime]-charge);
218 float deltaT = (tof-prev_tof);
219 fireTDC = deltaT*(deltaQ2TDCOnset/deltaQ)+prev_tof;
223 (simHitIt->second).hit_info[1][itime]=fireTDC;
230 template<
class SensorPhysics,
class ElectronicsSim>
232 deviceSim_.getEvent(e);
233 electronicsSim_.getEvent(e);
236 template<
class SensorPhysics,
class ElectronicsSim>
238 CLHEP::HepRandomEngine* hre) {
246 resetSimHitDataAccumulator();
250 template<
class SensorPhysics,
class ElectronicsSim>
252 if ( idealGeomWatcher_.check(es) ) {
256 std::unordered_set<DetId>().
swap(validIds_);
261 for(
unsigned izeta = 0; izeta < 1<<10; ++izeta ) {
262 for(
unsigned iphi = 0; iphi < 1<<10; ++iphi ) {
264 if( dddFTL_->isValidXY(
type, izeta, iphi) ) {
275 validIds_.reserve(validIds_.size());
277 deviceSim_.getEventSetup(es);
278 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()
std::unordered_map< uint32_t, FTLCellInfo > FTLSimHitDataAccumulator
uint32_t rawId() const
get the raw id
FTLDigitizer(const edm::ParameterSet &config, edm::ConsumesCollector &iC, edm::stream::EDProducerBase &parent)
std::size_t operator()(const DetId &detid) const
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
std::tuple< int, uint32_t, float > FTLCaloHitTuple_t
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
bool orderByDetIdThenTime(const FTLCaloHitTuple_t &a, const FTLCaloHitTuple_t &b)