22 #include <boost/foreach.hpp> 29 constexpr std::array<double,3> occupancyGuesses = { { 0.5,0.2,0.2 } };
46 int waferTypeL = dddConst.waferTypeL(wafer);
54 void getValidDetIds(
const HGCalGeometry* geom, std::unordered_set<DetId>& valid) {
56 valid.reserve(ids.size());
57 valid.insert(ids.begin(),ids.end());
60 void getValidDetIds(
const HcalGeometry* geom, std::unordered_set<DetId>& valid) {
62 for(
const auto&
id : ids ) {
67 valid.reserve(valid.size());
88 int subdet(
DetId(simId).subdetId()), layer, cell, sec, subsec, zp;
98 std::pair<int,int> recoLayerCell=dddConst.simToReco(cell,layer,sec,topo.detectorType());
99 cell = recoLayerCell.first;
100 layer = recoLayerCell.second;
101 if (layer<0 || cell<0) {
113 const std::vector<float>&cces) {
114 if( cces.empty() )
return 1.
f;
115 const auto& topo = geom->
topology();
120 int waferTypeL = dddConst.waferTypeL(wafer);
121 return cces[waferTypeL-1];
126 const std::vector<float>&cces) {
137 refSpeed_(0.1*
CLHEP::c_light),
138 averageOccupancies_(occupancyGuesses),
155 if( myCfg_.existsAs<std::vector<double> >(
"chargeCollectionEfficiencies" ) ) {
157 const auto&
temp = myCfg_.getParameter<std::vector<double> >(
"chargeCollectionEfficiencies");
158 for(
double cce :
temp ) {
209 static_cast<const CaloSubdetectorGeometry*>(
gHGCal_) );
238 edm::LogInfo(
"HGCDigitizer") <<
" @ finalize event - produced " << digiResult->size() <<
" EE hits";
245 edm::LogInfo(
"HGCDigitizer") <<
" @ finalize event - produced " << digiResult->size() <<
" HE front hits";
252 edm::LogInfo(
"HGCDigitizer") <<
" @ finalize event - produced " << digiResult->size() <<
" HE back hits";
273 }
else if(
nullptr !=
gHcal_ ) {
277 <<
"HGCDigitizer is not producing EE, FH, or BH digis!";
295 }
else if (
nullptr !=
gHcal_ ) {
299 <<
"HGCDigitizer is not producing EE, FH, or BH digis!";
304 template<
typename GEOM>
308 CLHEP::HepRandomEngine* hre) {
309 if(
nullptr == geom )
return;
314 bool weightToAbyEnergy(
false);
315 std::array<float, 3> tdcForToAOnset{ {0.f, 0.f, 0.f} };
338 int nchits=(
int)hits->size();
339 std::vector< HGCCaloHitTuple_t > hitRefs;
340 hitRefs.reserve(nchits);
341 for(
int i=0;
i<nchits; ++
i) {
342 const auto& the_hit = hits->at(
i);
344 DetId id = simToReco(geom,the_hit.id());
348 edm::LogInfo(
"HGCDigitizer") <<
" i/p " << std::hex << the_hit.id() <<
" o/p " <<
id.rawId() <<
std::dec << std::endl;
350 edm::LogInfo(
"HGCDigitizer") <<
" i/p " << std::hex << the_hit.id() <<
" o/p " <<
id.rawId() <<
std::dec << std::endl;
353 if( 0 !=
id.rawId() ) {
354 hitRefs.emplace_back(
i,
id.rawId(), (
float)the_hit.time() );
360 nchits = hitRefs.size();
361 for(
int i=0;
i<nchits; ++
i) {
362 const int hitidx = std::get<0>(hitRefs[
i]);
363 const uint32_t
id = std::get<1>(hitRefs[
i]);
372 const float toa = std::get<2>(hitRefs[
i]);
374 const float charge = hit.energy()*1e6*keV2fC*getCCE(geom,
id,
cce_);
377 const float dist2center( getPositionDistance(geom,
id) );
382 const int itime= std::floor( tof/
bxTime_ ) + 9;
388 if(itime<0 || itime>14)
continue;
391 if(itime >= (
int)simHitIt->second.hit_info[0].size() )
continue;
393 (simHitIt->second).hit_info[0][itime] += charge;
397 int waferThickness = getCellThickness(geom,
id);
398 bool orderChanged =
false;
401 hitRefs_bx0[
id].push_back(std::pair<float, float>(charge, tof));
404 std::vector<std::pair<float, float> >::iterator findPos =
406 [](
const auto&
i,
const auto& j){
return i.second < j.second;});
408 std::vector<std::pair<float, float> >::iterator insertedPos =
410 std::pair<float, float>(charge,tof) : std::pair<float, float>((findPos-1)->
first+charge,tof));
414 if(
step->first > tdcForToAOnset[waferThickness-1] &&
step->second !=
hitRefs_bx0[
id].back().second){
416 [](
const auto&
i,
const auto& j){return i.second < j.second;}) -
hitRefs_bx0[
id].begin());
417 for(
auto stepEnd =
step+1; stepEnd !=
hitRefs_bx0[
id].end(); ++stepEnd) stepEnd->first += charge;
424 if(
hitRefs_bx0[
id].back().first <= tdcForToAOnset[waferThickness-1]){
433 if(weightToAbyEnergy) (simHitIt->second).hit_info[1][itime] += charge*tof;
434 else if(accChargeForToA > tdcForToAOnset[waferThickness-1] &&
435 ((simHitIt->second).hit_info[1][itime] == 0 || orderChanged ==
true) ){
438 float chargeBeforeThr = 0.f;
439 float tofchargeBeforeThr = 0.f;
441 if(
step.first + chargeBeforeThr <= tdcForToAOnset[waferThickness-1]){
442 chargeBeforeThr +=
step.first;
443 tofchargeBeforeThr =
step.second;
447 float deltaQ = accChargeForToA - chargeBeforeThr;
448 float deltaTOF = fireTDC - tofchargeBeforeThr;
449 fireTDC = (tdcForToAOnset[waferThickness-1] - chargeBeforeThr) * deltaTOF / deltaQ + tofchargeBeforeThr;
451 (simHitIt->second).hit_info[1][itime] = fireTDC;
476 }
else if(
nullptr !=
gHcal_ ) {
480 <<
"HGCDigitizer is not producing EE, FH, or BH digis!";
485 <<
"Added " << nadded <<
":" <<
validIds_.size()
487 <<
" in first event processed" << std::endl;
501 it->second.hit_info[0].fill(0.);
502 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
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()
virtual const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
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 CaloCellGeometry * getGeometry(const DetId &id) const override
Get the cell geometry of a given detector id. Should return false if not found.
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)