Skip to content

Commit

Permalink
- HGCalSiNoiseMap
Browse files Browse the repository at this point in the history
  setGeometry method now takes care of filling the operation cache
  cache filled from the list of valid DetIds from geometry insted of dynamically from DetIds received.
  This avoids having to query if DetId is already existing in the cache.
  Given there is no need to have a fast query on the cache, switched from unordered_map to a standard map
  to reduce memory footprint

- HGCDigitizerBase
  propagation of the changes above
  • Loading branch information
pfs committed Jun 22, 2020
1 parent 415e38d commit 1a635fd
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 24 deletions.
21 changes: 18 additions & 3 deletions SimCalorimetry/HGCalSimAlgos/interface/HGCalSiNoiseMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,25 @@ class HGCalSiNoiseMap : public HGCalRadiationMap {
*/
void setDoseMap(const std::string &, const unsigned int &);

/**
@short overrides base class method which sets the geometry so that it can instantiate an operation
cache the first time it is called - intrinsically related to the valid detIds in the geometry
the filling of the cache is ignored by configuration or if it has already been filled
*/
void setGeometry(const CaloSubdetectorGeometry *,
GainRange_t gain=GainRange_t::AUTO,
int aimMIPtoADC=10);

/**
@short returns the charge collection efficiency and noise
if gain range is set to auto, it will find the most appropriate gain to put the mip peak close to 10 ADC counts
*/
SiCellOpCharacteristicsCore getSiCellOpCharacteristicsCore(const HGCSiliconDetId &did,
GainRange_t gain = GainRange_t::AUTO,
int aimMIPtoADC = 10);
GainRange_t gain,
int aimMIPtoADC);
SiCellOpCharacteristicsCore getSiCellOpCharacteristicsCore(const HGCSiliconDetId &did) {
return getSiCellOpCharacteristicsCore(did,defaultGain_,defaultAimMIPtoADC_);
}
SiCellOpCharacteristics getSiCellOpCharacteristics(const HGCSiliconDetId &did,
GainRange_t gain = GainRange_t::AUTO,
int aimMIPtoADC = 10);
Expand Down Expand Up @@ -97,8 +109,11 @@ class HGCalSiNoiseMap : public HGCalRadiationMap {

private:

GainRange_t defaultGain_;
int defaultAimMIPtoADC_;

//cache of SiCellOpCharacteristics
std::unordered_map<uint32_t, SiCellOpCharacteristicsCore> siopCache_;
std::map<uint32_t, SiCellOpCharacteristicsCore> siopCache_;

//vector of three params, per sensor type: 0:120 [mum], 1:200, 2:300
std::array<double, 3> mipEqfC_, cellCapacitance_, cellVolume_;
Expand Down
57 changes: 39 additions & 18 deletions SimCalorimetry/HGCalSimAlgos/src/HGCalSiNoiseMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

//
HGCalSiNoiseMap::HGCalSiNoiseMap()
: encCommonNoiseSub_(sqrt(1.0)),
: defaultGain_(GainRange_t::AUTO),
defaultAimMIPtoADC_(10),
encCommonNoiseSub_(sqrt(1.0)),
qe2fc_(1.60217646E-4),
ignoreFluence_(false),
ignoreCCE_(false),
Expand Down Expand Up @@ -83,13 +85,47 @@ double HGCalSiNoiseMap::getENCpad(const double &ileak) {
else return 457.15*pow(ileak,0.57);
}

//
void HGCalSiNoiseMap::setGeometry(const CaloSubdetectorGeometry *hgcGeom,
GainRange_t gain,
int aimMIPtoADC){

//call base class method
HGCalRadiationMap::setGeometry(hgcGeom);

defaultGain_=gain;
defaultAimMIPtoADC_=aimMIPtoADC;

//exit if cache is to be ignored
if(ignoreCachedOp_) return;

//fill cache if it's not filled
if(!siopCache_.empty()) return;

std::cout << "[HGCalSiNoiseMap::setGeometry] instantianting Si operation cache" << std::endl;
const std::vector<DetId> &validDetIds = geom()->getValidDetIds();
for(auto &did : validDetIds) {

//use only positive side detIds
unsigned int rawId(did.rawId());
HGCSiliconDetId hgcDetId(rawId);
if(hgcDetId.zside()!=1) continue;

//compute and store in ache
SiCellOpCharacteristicsCore siop=getSiCellOpCharacteristicsCore(hgcDetId);
std::pair<uint32_t, SiCellOpCharacteristicsCore> toAdd(rawId, siop);
siopCache_.insert( toAdd ) ;
}
}


//
HGCalSiNoiseMap::SiCellOpCharacteristicsCore HGCalSiNoiseMap::getSiCellOpCharacteristicsCore(const HGCSiliconDetId &cellId,
GainRange_t gain,
int aimMIPtoADC) {

//check if this already exists in the cache
if(ignoreCachedOp_)
return getSiCellOpCharacteristics(cellId,gain,aimMIPtoADC).core;

HGCSiliconDetId posCellId(cellId.subdet(),
1,
cellId.type(),
Expand All @@ -99,21 +135,6 @@ HGCalSiNoiseMap::SiCellOpCharacteristicsCore HGCalSiNoiseMap::getSiCellOpCharact
cellId.cellU(),
cellId.cellV());
uint32_t key(posCellId.rawId());

// two possible reasons why you want to compute siop:
// - you want to ignore caching
// - you have not cached siop for that specific DetID, yet
if(ignoreCachedOp_ || siopCache_.find(key)==siopCache_.end()) {
SiCellOpCharacteristicsCore siop=getSiCellOpCharacteristics(cellId,gain,aimMIPtoADC).core;
// do cache the computed siop, if wanted
if ( !ignoreCachedOp_ ) {
std::pair<uint32_t, SiCellOpCharacteristicsCore> toAdd(key, siop);
siopCache_.insert( toAdd ) ;
}
return siop;
}

//fallback if cache is in use and key exists
return siopCache_[key];
}

Expand Down
5 changes: 2 additions & 3 deletions SimCalorimetry/HGCalSimProducers/src/HGCDigitizerBase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void HGCDigitizerBase<DFr>::run(std::unique_ptr<HGCDigitizerBase::DColl>& digiCo
uint32_t digitizationType,
CLHEP::HepRandomEngine* engine) {
if (scaleByDose_)
scal_.setGeometry(theGeom);
scal_.setGeometry(theGeom, HGCalSiNoiseMap::AUTO, myFEelectronics_->getTargetMipValue());
if (NoiseGeneration_Method_ == true) {
if (RandNoiseGenerationFlag_ == false) {
GenerateGaussianNoise(engine, NoiseMean_, NoiseStd_);
Expand Down Expand Up @@ -132,8 +132,7 @@ void HGCDigitizerBase<DFr>::runSimple(std::unique_ptr<HGCDigitizerBase::DColl>&

if (scaleByDose_) {
HGCSiliconDetId detId(id);
HGCalSiNoiseMap::SiCellOpCharacteristicsCore siop =
scal_.getSiCellOpCharacteristicsCore(detId, HGCalSiNoiseMap::AUTO, myFEelectronics_->getTargetMipValue());
HGCalSiNoiseMap::SiCellOpCharacteristicsCore siop = scal_.getSiCellOpCharacteristicsCore(detId);
cce = siop.cce;
noiseWidth = siop.noise;
HGCalSiNoiseMap::GainRange_t gain((HGCalSiNoiseMap::GainRange_t)siop.gain);
Expand Down

0 comments on commit 1a635fd

Please sign in to comment.