20 #include <boost/foreach.hpp> 27 constexpr std::array<double,3> occupancyGuesses = { { 0.5,0.2,0.2 } };
44 int waferTypeL = dddConst.waferTypeL(wafer);
52 void getValidDetIds(
const HGCalGeometry* geom, std::unordered_set<DetId>& valid) {
54 valid.reserve(ids.size());
55 valid.insert(ids.begin(),ids.end());
58 void getValidDetIds(
const HcalGeometry* geom, std::unordered_set<DetId>& valid) {
60 for(
const auto&
id : ids ) {
65 valid.reserve(valid.size());
86 int subdet(
DetId(simId).subdetId()), layer, cell, sec, subsec, zp;
96 std::pair<int,int> recoLayerCell=dddConst.simToReco(cell,layer,sec,topo.detectorType());
97 cell = recoLayerCell.first;
98 layer = recoLayerCell.second;
99 if (layer<0 || cell<0) {
111 const std::vector<float>&cces) {
112 if( cces.empty() )
return 1.
f;
113 const auto& topo = geom->
topology();
118 int waferTypeL = dddConst.waferTypeL(wafer);
119 return cces[waferTypeL-1];
124 const std::vector<float>&cces) {
135 refSpeed_(0.1*
CLHEP::c_light),
136 averageOccupancies_(occupancyGuesses),
153 if( myCfg_.existsAs<std::vector<double> >(
"chargeCollectionEfficiencies" ) ) {
155 const auto&
temp = myCfg_.getParameter<std::vector<double> >(
"chargeCollectionEfficiencies");
156 for(
double cce :
temp ) {
207 static_cast<const CaloSubdetectorGeometry*>(
gHGCal_) );
236 edm::LogInfo(
"HGCDigitizer") <<
" @ finalize event - produced " << digiResult->size() <<
" EE hits";
243 edm::LogInfo(
"HGCDigitizer") <<
" @ finalize event - produced " << digiResult->size() <<
" HE front hits";
250 edm::LogInfo(
"HGCDigitizer") <<
" @ finalize event - produced " << digiResult->size() <<
" HE back hits";
271 }
else if(
nullptr !=
gHcal_ ) {
275 <<
"HGCDigitizer is not producing EE, FH, or BH digis!";
293 }
else if (
nullptr !=
gHcal_ ) {
297 <<
"HGCDigitizer is not producing EE, FH, or BH digis!";
302 template<
typename GEOM>
306 CLHEP::HepRandomEngine* hre) {
307 if(
nullptr == geom )
return;
312 bool weightToAbyEnergy(
false);
313 std::array<float, 3> tdcForToAOnset{ {0.f, 0.f, 0.f} };
336 int nchits=(
int)hits->size();
337 std::vector< HGCCaloHitTuple_t > hitRefs;
338 hitRefs.reserve(nchits);
339 for(
int i=0;
i<nchits; ++
i) {
340 const auto& the_hit = hits->at(
i);
342 DetId id = simToReco(geom,the_hit.id());
346 edm::LogInfo(
"HGCDigitizer") <<
" i/p " << std::hex << the_hit.id() <<
" o/p " <<
id.rawId() <<
std::dec << std::endl;
348 edm::LogInfo(
"HGCDigitizer") <<
" i/p " << std::hex << the_hit.id() <<
" o/p " <<
id.rawId() <<
std::dec << std::endl;
351 if( 0 !=
id.rawId() ) {
352 hitRefs.emplace_back(
i,
id.rawId(), (
float)the_hit.time() );
358 nchits = hitRefs.size();
359 for(
int i=0;
i<nchits; ++
i) {
360 const int hitidx = std::get<0>(hitRefs[
i]);
361 const uint32_t
id = std::get<1>(hitRefs[
i]);
370 const float toa = std::get<2>(hitRefs[
i]);
372 const float charge = hit.energy()*1e6*keV2fC*getCCE(geom,
id,
cce_);
375 const float dist2center( getPositionDistance(geom,
id) );
380 const int itime= std::floor( tof/
bxTime_ ) + 9;
386 if(itime<0 || itime>14)
continue;
389 if(itime >= (
int)simHitIt->second.hit_info[0].size() )
continue;
391 (simHitIt->second).hit_info[0][itime] += charge;
395 int waferThickness = getCellThickness(geom,
id);
396 bool orderChanged =
false;
399 hitRefs_bx0[
id].push_back(std::pair<float, float>(charge, tof));
402 std::vector<std::pair<float, float> >::iterator findPos =
404 [](
const auto&
i,
const auto& j){
return i.second < j.second;});
406 std::vector<std::pair<float, float> >::iterator insertedPos =
408 std::pair<float, float>(charge,tof) : std::pair<float, float>((findPos-1)->
first+charge,tof));
412 if(
step->first > tdcForToAOnset[waferThickness-1] &&
step->second !=
hitRefs_bx0[
id].back().second){
414 [](
const auto&
i,
const auto& j){return i.second < j.second;}) -
hitRefs_bx0[
id].begin());
415 for(
auto stepEnd =
step+1; stepEnd !=
hitRefs_bx0[
id].end(); ++stepEnd) stepEnd->first += charge;
422 if(
hitRefs_bx0[
id].back().first <= tdcForToAOnset[waferThickness-1]){
431 if(weightToAbyEnergy) (simHitIt->second).hit_info[1][itime] += charge*tof;
432 else if(accChargeForToA > tdcForToAOnset[waferThickness-1] &&
433 ((simHitIt->second).hit_info[1][itime] == 0 || orderChanged ==
true) ){
436 float chargeBeforeThr = 0.f;
437 float tofchargeBeforeThr = 0.f;
439 if(
step.first + chargeBeforeThr <= tdcForToAOnset[waferThickness-1]){
440 chargeBeforeThr +=
step.first;
441 tofchargeBeforeThr =
step.second;
445 float deltaQ = accChargeForToA - chargeBeforeThr;
446 float deltaTOF = fireTDC - tofchargeBeforeThr;
447 fireTDC = (tdcForToAOnset[waferThickness-1] - chargeBeforeThr) * deltaTOF / deltaQ + tofchargeBeforeThr;
449 (simHitIt->second).hit_info[1][itime] = fireTDC;
474 }
else if(
nullptr !=
gHcal_ ) {
478 <<
"HGCDigitizer is not producing EE, FH, or BH digis!";
483 <<
"Added " << nadded <<
":" <<
validIds_.size()
485 <<
" in first event processed" << std::endl;
499 it->second.hit_info[0].fill(0.);
500 it->second.hit_info[1].fill(0.);
int bunchCrossing() const
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
T getUntrackedParameter(std::string const &, T const &) const
const HcalDDDRecConstants * dddConstants() const
std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const override
Get the cell geometry of a given detector id. Should return false if not found.
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
std::vector< float > cce_
edm::SortedCollection< HGCEEDataFrame > HGCEEDigiCollection
void finalizeEvent(edm::Event &e, edm::EventSetup const &c, CLHEP::HepRandomEngine *hre)
ForwardSubdetector mySubDet_
std::string hitCollection_
void resetSimHitDataAccumulator()
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)
void initializeEvent(edm::Event const &e, edm::EventSetup const &c)
actions at the start/end of event
GlobalPoint getPosition(const DetId &id) const
const HGCalGeometry * gHGCal_
void swap(Association< C > &lhs, Association< C > &rhs)
std::string digiCollection_
const HcalTopology & topology() const
uint32_t rawId() const
get the raw id
U second(std::pair< T, U > const &p)
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
std::unordered_set< DetId > validIds_
int wafer() const
get the wafer #
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
bool producesHEfrontDigis()
std::unique_ptr< HGCHEbackDigitizer > theHGCHEbackDigitizer_
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)
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
std::map< uint32_t, std::vector< std::pair< float, float > > > hitRefs_bx0
HGCDigitizer(const edm::ParameterSet &ps, edm::ConsumesCollector &iC)
std::array< double, 3 > averageOccupancies_
DetId relabel(const uint32_t testId) const
std::unique_ptr< hgc::HGCSimHitDataAccumulator > simHitAccumulator_
static bool orderByDetIdThenTime(const HGCCaloHitTuple_t &a, const HGCCaloHitTuple_t &b)
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)