22 #include <boost/foreach.hpp>
24 using namespace hgc_digi;
28 constexpr std::array<double,3> occupancyGuesses = { { 0.5,0.2,0.2 } };
38 void getValidDetIds(
const HGCalGeometry* geom, std::unordered_set<DetId>& valid) {
40 valid.reserve(ids.size());
41 valid.insert(ids.begin(),ids.end());
44 void getValidDetIds(
const HcalGeometry* geom, std::unordered_set<DetId>& valid) {
46 for(
const auto&
id : ids ) {
51 valid.reserve(valid.size());
59 int subdet,
z, depth0, eta0, phi0, lay;
61 int sign = (z==0) ? (-1):(1);
75 int subdet, layer, cell, sec, subsec, zp;
85 std::pair<int,int> recoLayerCell=dddConst.simToReco(cell,layer,sec,topo.detectorType());
86 cell = recoLayerCell.first;
87 layer = recoLayerCell.second;
88 if (layer<0 || cell<0) {
104 refSpeed_(0.1*CLHEP::c_light),
105 averageOccupancies_(occupancyGuesses),
164 static_cast<const CaloSubdetectorGeometry*>(
gHGCal_) );
193 edm::LogInfo(
"HGCDigitizer") <<
" @ finalize event - produced " << digiResult->size() <<
" EE hits";
200 edm::LogInfo(
"HGCDigitizer") <<
" @ finalize event - produced " << digiResult->size() <<
" HE front hits";
207 edm::LogInfo(
"HGCDigitizer") <<
" @ finalize event - produced " << digiResult->size() <<
" HE back hits";
228 }
else if(
nullptr !=
gHcal_ ) {
232 <<
"HGCDigitizer is not producing EE, FH, or BH digis!";
250 }
else if (
nullptr !=
gHcal_ ) {
254 <<
"HGCDigitizer is not producing EE, FH, or BH digis!";
259 template<
typename GEOM>
263 CLHEP::HepRandomEngine* hre) {
264 if(
nullptr == geom )
return;
269 bool weightToAbyEnergy(
false);
270 float tdcOnset(0.
f),keV2fC(0.
f);
292 int nchits=(int)hits->size();
293 std::vector< HGCCaloHitTuple_t > hitRefs;
294 hitRefs.reserve(nchits);
295 for(
int i=0;
i<nchits; ++
i) {
296 const auto& the_hit = hits->at(
i);
298 DetId id = simToReco(geom,the_hit.id());
302 edm::LogInfo(
"HGCDigitizer") <<
" i/p " << std::hex << the_hit.id() <<
std::dec <<
" o/p " <<
id.rawId() << std::endl;
304 edm::LogInfo(
"HGCDigitizer") <<
" i/p " << std::hex << the_hit.id() <<
std::dec <<
" o/p " <<
id.rawId() << std::endl;
307 if( 0 !=
id.rawId() ) {
308 hitRefs.emplace_back(
i,
id.rawId(), (
float)the_hit.time() );
314 nchits = hitRefs.size();
315 for(
int i=0;
i<nchits; ++
i) {
316 const int hitidx = std::get<0>(hitRefs[
i]);
317 const uint32_t
id = std::get<1>(hitRefs[
i]);
326 const float toa = std::get<2>(hitRefs[
i]);
328 const float charge = hit.energy()*1e6*keV2fC;
331 const float dist2center( getPositionDistance(geom,
id) );
336 const int itime= std::floor( tof/
bxTime_ ) + 9;
342 if(itime<0 || itime>14)
continue;
345 if(itime >= (
int)simHitIt->second.hit_info[0].size() )
continue;
347 (simHitIt->second).hit_info[0][itime] += charge;
348 float accCharge=(simHitIt->second).hit_info[0][itime];
351 if(weightToAbyEnergy) (simHitIt->second).hit_info[1][itime] += charge*tof;
352 else if((simHitIt->second).hit_info[1][itime]==0) {
353 if( accCharge>tdcOnset)
359 uint32_t prev_id = std::get<1>(hitRefs[
i-1]);
362 float prev_toa = std::get<2>(hitRefs[
i-1]);
363 float prev_tof(prev_toa-dist2center/
refSpeed_+tofDelay_);
365 float deltaQ2TDCOnset = tdcOnset-((simHitIt->second).hit_info[0][itime]-charge);
367 float deltaT = (tof-prev_tof);
368 fireTDC = deltaT*(deltaQ2TDCOnset/deltaQ)+prev_tof;
372 (simHitIt->second).hit_info[1][itime]=fireTDC;
397 }
else if(
nullptr !=
gHcal_ ) {
401 <<
"HGCDigitizer is not producing EE, FH, or BH digis!";
406 <<
"Added " << nadded <<
":" <<
validIds_.size()
408 <<
" in first event processed" << std::endl;
422 it->second.hit_info[0].fill(0.);
423 it->second.hit_info[1].fill(0.);
int bunchCrossing() const
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
const HcalDDDRecConstants * dddConstants() const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
edm::SortedCollection< HGCEEDataFrame > HGCEEDigiCollection
void finalizeEvent(edm::Event &e, edm::EventSetup const &c, CLHEP::HepRandomEngine *hre)
ForwardSubdetector mySubDet_
std::string hitCollection_
void resetSimHitDataAccumulator()
void initializeEvent(edm::Event const &e, edm::EventSetup const &c)
actions at the start/end of event
GlobalPoint getPosition(const DetId &id) const
virtual const CaloCellGeometry * getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
const HGCalGeometry * gHGCal_
virtual const std::vector< DetId > & getValidDetIds(DetId::Detector det=DetId::Detector(0), int subdet=0) const
Get a list of valid detector ids (for the given subdetector)
void swap(Association< C > &lhs, Association< C > &rhs)
std::string digiCollection_
const HcalTopology & topology() const
std::unordered_map< uint32_t, HGCCellInfo > HGCSimHitDataAccumulator
edm::SortedCollection< HGCBHDataFrame > HGCBHDigiCollection
void beginRun(const edm::EventSetup &es)
actions at the start/end of run
const HGCalTopology & topology() const
virtual const std::vector< DetId > & getValidDetIds(DetId::Detector det=DetId::Detector(0), int subdet=0) const override
Get a list of valid detector ids (for the given subdetector)
static void unpackHcalIndex(const uint32_t &idx, int &det, int &z, int &depth, int &eta, int &phi, int &lay)
std::unordered_set< DetId > validIds_
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
bool producesHEfrontDigis()
std::unique_ptr< HGCHEbackDigitizer > theHGCHEbackDigitizer_
bool producesHEbackDigis()
const HGCalDDDConstants & dddConstants() const
static void unpackSquareIndex(const uint32_t &idx, int &z, int &lay, int &sec, int &subsec, int &cell)
std::unique_ptr< HGCHEfrontDigitizer > theHGCHEfrontDigitizer_
std::unique_ptr< HGCEEDigitizer > theHGCEEDigitizer_
void accumulate(edm::Event const &e, edm::EventSetup const &c, CLHEP::HepRandomEngine *hre)
handle SimHit accumulation
bool getByLabel(edm::InputTag const &tag, edm::Handle< T > &result) const
HGCDigitizer(const edm::ParameterSet &ps, edm::ConsumesCollector &iC)
std::array< double, 3 > averageOccupancies_
std::unique_ptr< hgc::HGCSimHitDataAccumulator > simHitAccumulator_
static bool orderByDetIdThenTime(const HGCCaloHitTuple_t &a, const HGCCaloHitTuple_t &b)
const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
std::string digiCollection()
edm::SortedCollection< HGCHEDataFrame > HGCHEDigiCollection
const HcalGeometry * gHcal_
static void unpackHexagonIndex(const uint32_t &idx, int &subdet, int &z, int &lay, int &wafer, int &celltyp, int &cell)