Skip to content

Commit

Permalink
address code review
Browse files Browse the repository at this point in the history
  • Loading branch information
lgray committed Apr 4, 2016
1 parent ce7b1a8 commit 4f5269c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
Expand Up @@ -34,7 +34,14 @@ template<class C> class HGCalUncalibRecHitRecWeightsAlgo

void set_tdcOnsetfC(const double tdcOnset) { tdcOnsetfC_ = tdcOnset; }

void set_fCPerMIP(const std::vector<double>& fCPerMIP) { fCPerMIP_ = fCPerMIP; }
void set_fCPerMIP(const std::vector<double>& fCPerMIP) {
if( std::any_of(fCPerMIP.cbegin(),
fCPerMIP.cend(),
[](double conv){ return conv <= 0.0; }) ) {
throw cms::Exception("BadConversionFactor") << "At least one of fCPerMIP is zero!" << std::endl;
}
fCPerMIP_ = fCPerMIP;
}

void setGeometry(const HGCalGeometry* geom) {
if ( geom ) ddd_ = &(geom->topology().dddConstants());
Expand Down
21 changes: 11 additions & 10 deletions SimCalorimetry/HGCalSimProducers/src/HGCHEbackDigitizer.cc
Expand Up @@ -41,28 +41,29 @@ void HGCHEbackDigitizer::runCaliceLikeDigitizer(std::auto_ptr<HGCHEDigiCollectio
for(size_t i=0; i<it->second.hit_info[0].size(); ++i)
{
//convert total energy keV->MIP, since converted to keV in accumulator
float totalIniMIPs( (it->second).hit_info[0][i]*keV2MIP_ );
const float totalIniMIPs( (it->second).hit_info[0][i]*keV2MIP_ );
//std::cout << "energy in MIP: " << std::scientific << totalIniMIPs << std::endl;

//generate random number of photon electrons
uint32_t npe = std::floor(CLHEP::RandPoissonQ::shoot(engine,totalIniMIPs*nPEperMIP_));
const uint32_t npe = std::floor(CLHEP::RandPoissonQ::shoot(engine,totalIniMIPs*nPEperMIP_));

//number of pixels
float x = vdt::fast_expf( -((float)npe)/nTotalPE_ );
const float x = vdt::fast_expf( -((float)npe)/nTotalPE_ );
uint32_t nPixel(0);
if(xTalk_*x!=1) nPixel=(uint32_t) std::max( nTotalPE_*(1.f-x)/(1.f-xTalk_*x), 0.f );

//update signal
nPixel = (uint32_t)std::max( CLHEP::RandGaussQ::shoot(engine,(double)nPixel,sdPixels_), 0. );

//convert to MIP again and saturate
float totalMIPs(totalIniMIPs);
const float xtalk = (nTotalPE_-xTalk_*((float)nPixel))/(nTotalPE_-((float)nPixel));
if( nTotalPE_ != nPixel && xtalk > 0. )
totalMIPs = (nTotalPE_/nPEperMIP_)*vdt::fast_logf(xtalk);
else
totalMIPs = 0.f;

float totalMIPs(0.f), xtalk = 0.f;
const float peDiff = nTotalPE_ - (float) nPixel;
if (peDiff != 0.f) {
xtalk = (nTotalPE_-xTalk_*((float)nPixel)) / peDiff;
if( xtalk > 0.f && nPEperMIP_ != 0.f)
totalMIPs = (nTotalPE_/nPEperMIP_)*vdt::fast_logf(xtalk);
}

//add noise (in MIPs)
chargeColl[i] = totalMIPs+std::max( CLHEP::RandGaussQ::shoot(engine,0.,noise_MIP_), 0. );
if(debug && (it->second).hit_info[0][i]>0)
Expand Down

0 comments on commit 4f5269c

Please sign in to comment.