diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/src/TFCSHistoLateralShapeWeightHitAndMiss.cxx b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/src/TFCSHistoLateralShapeWeightHitAndMiss.cxx index 63726341a0873ad01ff03543e61c4dcde2e354a8..e65893081b4335d546b51ba065131b0645cf1084 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/src/TFCSHistoLateralShapeWeightHitAndMiss.cxx +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/src/TFCSHistoLateralShapeWeightHitAndMiss.cxx @@ -3,6 +3,7 @@ */ #include "CLHEP/Random/RandFlat.h" +#include "CLHEP/Random/RandGauss.h" #include "ISF_FastCaloSimEvent/TFCSHistoLateralShapeWeightHitAndMiss.h" #include "ISF_FastCaloSimEvent/TFCSSimulationState.h" @@ -49,6 +50,16 @@ FCSReturnCode TFCSHistoLateralShapeWeightHitAndMiss::simulate_hit(Hit& hit,TFCSS if(bin<1) bin=1; if(bin>m_hist->GetNbinsX()) bin=m_hist->GetNbinsX(); float weight=m_hist->GetBinContent(bin); + float RMS =m_hist->GetBinError(bin); + if(RMS>0) { + if(weight>=1) { + weight=CLHEP::RandGauss::shoot(simulstate.randomEngine(), weight, RMS); + //weight<1 can't be corrected for with HitAndMiss. So protect against a fluctuation leading to a weight<1 + if(weight<1) weight=1; + } else { + weight=CLHEP::RandGauss::shoot(simulstate.randomEngine(), weight, RMS); + } + } if(weight<=1) { //if weight<=1, give lower energy to hit. //TFCSLateralShapeParametrizationHitChain needs to be able to generate more hits in this case