21 #include <boost/foreach.hpp> 28 constexpr std::array<double,3> occupancyGuesses = { { 0.5,0.2,0.2 } };
48 void getValidDetIds(
const HGCalGeometry* geom, std::unordered_set<DetId>& valid) {
50 valid.reserve(ids.size());
51 valid.insert(ids.begin(),ids.end());
54 void getValidDetIds(
const HcalGeometry* geom, std::unordered_set<DetId>& valid) {
56 for(
const auto&
id : ids ) {
61 valid.reserve(valid.size());
87 int subdet(
DetId(simId).subdetId()), layer, cell, sec, subsec, zp;
91 auto recoLayerCell = dddConst.simToReco(cell,layer,sec,topo.detectorType());
92 cell = recoLayerCell.first;
93 layer = recoLayerCell.second;
94 if (layer<0 || cell<0) {
106 const std::vector<float>&cces) {
107 if ( cces.empty() )
return 1.
f;
111 const auto& topo = geom->
topology();
113 int waferTypeL = dddConst.
waferType(detid);
114 return cces[waferTypeL-1];
120 const std::vector<float>&cces) {
130 const float minPackChargeLog = minCharge > 0.f ?
std::log(minCharge) : -2;
131 const float maxPackChargeLog =
std::log(maxCharge);
134 simResult.
reserve(simData.size());
136 for(
const auto&
id: validIds) {
137 auto found = simData.find(
id);
138 if(
found == simData.end())
141 for(
size_t iEn = 0; iEn < nEnergies; ++iEn) {
144 if(
samples[iSample] > minCharge) {
146 simResult.
emplace_back(
id.rawId(), iEn, iSample, packed);
156 const float minPackChargeLog = minCharge > 0.f ?
std::log(minCharge) : -2;
157 const float maxPackChargeLog =
std::log(maxCharge);
160 for(
const auto& detIdIndexHitInfo: simAccumulator) {
161 auto simIt = simData.emplace(detIdIndexHitInfo.detId(),
HGCCellInfo()).
first;
162 auto& hit_info = simIt->second.hit_info;
164 size_t iEn = detIdIndexHitInfo.energyIndex();
165 size_t iSample = detIdIndexHitInfo.sampleIndex();
169 if(iEn == 0 || !setIfZero) {
170 hit_info[iEn][iSample] +=
value;
172 else if(hit_info[iEn][iSample] == 0) {
173 hit_info[iEn][iSample] =
value;
183 myDet_(
DetId::Forward),
185 refSpeed_(0.1*
CLHEP::c_light),
186 averageOccupancies_(occupancyGuesses),
209 const auto&
temp = myCfg_.getParameter<
edm::ParameterSet>(
"chargeCollectionEfficiencies").getParameter<std::vector<double>>(
"values");
210 for(
double cce :
temp ) {
211 cce_.emplace_back(cce);
218 if (geometryType_ == 0) {
226 if (geometryType_ == 0) {
233 if(
hitCollection_.find(
"HcalHits")!=std::string::npos and geometryType_ == 0) {
237 if(
hitCollection_.find(
"HitsHEback")!=std::string::npos and geometryType_ == 1) {
258 static_cast<const CaloSubdetectorGeometry*>(
gHGCal_) );
271 std::unique_ptr<PHGCSimAccumulator> simResult;
279 auto digiResult = std::make_unique<HGCalDigiCollection>();
281 edm::LogInfo(
"HGCDigitizer") <<
" @ finalize event - produced " << digiResult->size() <<
" EE hits";
285 auto digiResult = std::make_unique<HGCalDigiCollection>();
287 edm::LogInfo(
"HGCDigitizer") <<
" @ finalize event - produced " << digiResult->size() <<
" HE front hits";
291 auto digiResult = std::make_unique<HGCalDigiCollection>();
293 edm::LogInfo(
"HGCDigitizer") <<
" @ finalize event - produced " << digiResult->size() <<
" HE back hits";
315 }
else if(
nullptr !=
gHcal_ ) {
319 <<
"HGCDigitizer is not producing EE, FH, or BH digis!";
337 }
else if (
nullptr !=
gHcal_ ) {
341 <<
"HGCDigitizer is not producing EE, FH, or BH digis!";
346 template<
typename GEOM>
350 CLHEP::HepRandomEngine* hre) {
351 if(
nullptr == geom )
return;
356 std::array<float, 3> tdcForToAOnset{ {0.f, 0.f, 0.f} };
358 bool weightToAbyEnergy=
getWeight(tdcForToAOnset, keV2fC);
361 int nchits=(
int)hits->size();
362 std::vector< HGCCaloHitTuple_t > hitRefs;
363 hitRefs.reserve(nchits);
364 for(
int i=0;
i<nchits; ++
i) {
365 const auto& the_hit = hits->at(
i);
367 DetId id = simToReco(geom,the_hit.id());
371 edm::LogInfo(
"HGCDigitizer") <<
" i/p " << std::hex << the_hit.id() <<
" o/p " <<
id.rawId() <<
std::dec << std::endl;
373 edm::LogInfo(
"HGCDigitizer") <<
" i/p " << std::hex << the_hit.id() <<
" o/p " <<
id.rawId() <<
std::dec << std::endl;
376 if( 0 !=
id.rawId() ) {
377 hitRefs.emplace_back(
i,
id.rawId(), (
float)the_hit.time() );
383 nchits = hitRefs.size();
384 for(
int i=0;
i<nchits; ++
i) {
385 const int hitidx = std::get<0>(hitRefs[
i]);
386 const uint32_t
id = std::get<1>(hitRefs[
i]);
395 const float toa = std::get<2>(hitRefs[
i]);
397 const float charge = hit.energy()*1e6*keV2fC*getCCE(geom,
id,
cce_);
400 const float dist2center( getPositionDistance(geom,
id) );
405 const int itime= std::floor( tof/
bxTime_ ) + 9;
411 if(itime<0 || itime>14)
continue;
414 if(itime >= (
int)simHitIt->second.hit_info[0].size() )
continue;
416 (simHitIt->second).hit_info[0][itime] += charge;
420 int waferThickness = getCellThickness(geom,
id);
421 bool orderChanged =
false;
427 std::vector<std::pair<float, float> >::iterator findPos =
429 [](
const auto&
i,
const auto& j){
return i.second < j.second;});
431 std::vector<std::pair<float, float> >::iterator insertedPos =
433 std::pair<float, float>(charge,tof) : std::pair<float, float>((findPos-1)->
first+charge,tof));
437 if(
step->first > tdcForToAOnset[waferThickness-1] &&
step->second !=
hitRefs_bx0[
id].back().second){
439 [](
const auto&
i,
const auto& j){return i.second < j.second;}) -
hitRefs_bx0[
id].begin());
440 for(
auto stepEnd =
step+1; stepEnd !=
hitRefs_bx0[
id].end(); ++stepEnd) stepEnd->first += charge;
447 if(
hitRefs_bx0[
id].back().first <= tdcForToAOnset[waferThickness-1]){
456 if(weightToAbyEnergy) (simHitIt->second).hit_info[1][itime] += charge*tof;
457 else if(accChargeForToA > tdcForToAOnset[waferThickness-1] &&
458 ((simHitIt->second).hit_info[1][itime] == 0 || orderChanged ==
true) ){
461 float chargeBeforeThr = 0.f;
462 float tofchargeBeforeThr = 0.f;
464 if(
step.first + chargeBeforeThr <= tdcForToAOnset[waferThickness-1]){
465 chargeBeforeThr +=
step.first;
466 tofchargeBeforeThr =
step.second;
470 float deltaQ = accChargeForToA - chargeBeforeThr;
471 float deltaTOF = fireTDC - tofchargeBeforeThr;
472 fireTDC = (tdcForToAOnset[waferThickness-1] - chargeBeforeThr) * deltaTOF / deltaQ + tofchargeBeforeThr;
474 (simHitIt->second).hit_info[1][itime] = fireTDC;
483 std::array<float, 3> tdcForToAOnset{ {0.f, 0.f, 0.f} };
485 bool weightToAbyEnergy=
getWeight(tdcForToAOnset, keV2fC);
513 }
else if(
nullptr !=
gHcal_ ) {
517 <<
"HGCDigitizer is not producing EE, FH, or BH digis!";
522 <<
"Added " << nadded <<
":" <<
validIds_.size()
524 <<
" in first event processed" << std::endl;
538 it->second.hit_info[0].fill(0.);
539 it->second.hit_info[1].fill(0.);
581 bool weightToAbyEnergy(
false);
623 return weightToAbyEnergy;
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_
void finalizeEvent(edm::Event &e, edm::EventSetup const &c, CLHEP::HepRandomEngine *hre)
ForwardSubdetector mySubDet_
std::string hitCollection_
void resetSimHitDataAccumulator()
static constexpr unsigned sampleMask
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 emplace_back(unsigned int detId, unsigned short energyIndex, unsigned short sampleIndex, unsigned short data)
void initializeEvent(edm::Event const &e, edm::EventSetup const &c)
actions at the start/end of event
double unpack16log(int16_t i, double lmin, double lmax, uint16_t base=32768)
GlobalPoint getPosition(const DetId &id) const
const HGCalGeometry * gHGCal_
void swap(Association< C > &lhs, Association< C > &rhs)
bool getWeight(std::array< float, 3 > &tdcForToAOnset, float &keV2fC) const
std::string digiCollection_
const HcalTopology & topology() const
static constexpr unsigned sampleOffset
static constexpr unsigned energyMask
U second(std::pair< T, U > const &p)
std::unordered_map< uint32_t, HGCCellInfo > HGCSimHitDataAccumulator
void beginRun(const edm::EventSetup &es)
actions at the start/end of run
const HGCalTopology & topology() const
std::unordered_set< DetId > validIds_
base
Make Sure CMSSW is Setup ##.
constexpr size_t nSamples
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
bool producesHEfrontDigis()
int waferType(DetId const &id) const
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)
void reserve(size_t size)
double premixStage1MinCharge_
bool producesHEbackDigis()
const HGCalDDDConstants & dddConstants() const
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)
int16_t pack16log(double x, double lmin, double lmax, uint16_t base=32768)
double premixStage1MaxCharge_
std::string digiCollection()
const HcalGeometry * gHcal_
static void unpackHexagonIndex(const uint32_t &idx, int &subdet, int &z, int &lay, int &wafer, int &celltyp, int &cell)
constexpr Detector det() const
get the detector field from this detid