3 #include "CLHEP/Random/RandFlat.h"
23 hXInt.setBinContent(
i,
j, xInt);
34 return range.min + (iBin - 1 + pos) * binWidth;
58 if ((layer >
m_nTIB) || (layer < 1)) {
60 <<
"[" << __PRETTY_FUNCTION__ <<
"] layer index " << layer <<
" out of range [1," <<
m_nTIB <<
"]";
70 if ((layer >
m_nTOB) || (layer < 1)) {
72 <<
"[" << __PRETTY_FUNCTION__ <<
"] layer index " << layer <<
" out of range [1," <<
m_nTOB <<
")";
82 if ((wheel >
m_nTID) || (wheel < 1)) {
84 <<
"[" << __PRETTY_FUNCTION__ <<
"] wheel index " << wheel <<
" out of range [1," <<
m_nTID <<
"]";
94 if ((wheel >
m_nTEC) || (wheel < 1)) {
96 <<
"[" << __PRETTY_FUNCTION__ <<
"] wheel index " << wheel <<
" out of range [1," <<
m_nTEC <<
")";
107 CLHEP::HepRandomEngine* engine)
const {
109 throw cms::Exception(
"LogicError") <<
"x-integrals of 3D histograms have not been calculated";
112 const int ip = layerParam.findBinY(pu);
113 const int iz = layerParam.findBinZ(z);
115 const auto val = CLHEP::RandFlat::shoot(engine) * norm;
116 if (
val < layerParam.binContent(0, ip, iz)) {
117 return layerParam.rangeX().min;
118 }
else if (norm -
val < layerParam.binContent(layerParam.numberOfBinsX() + 1, ip, iz)) {
119 return layerParam.rangeX().max;
121 float sum = layerParam.binContent(0, ip, iz);
122 for (
int i{1};
i != layerParam.numberOfBinsX() + 1; ++
i) {
123 sum += layerParam.binContent(
i, ip, iz);
125 return xBinPos(layerParam,
i, (sum -
val) / layerParam.binContent(
i, ip, iz));
129 throw cms::Exception(
"LogicError") <<
"Problem drawing a random number from the distribution";
135 CLHEP::HepRandomEngine* engine)
const {
137 throw cms::Exception(
"LogicError") <<
"x-integrals of 3D histograms have not been calculated";
140 const int ip = layerParam.findBinY(pu);
141 const int ir = layerParam.findBinZ(r);
143 const auto val = CLHEP::RandFlat::shoot(engine) * norm;
144 if (
val < layerParam.binContent(0, ip, ir)) {
145 return layerParam.rangeX().min;
146 }
else if (norm -
val < layerParam.binContent(layerParam.numberOfBinsX() + 1, ip, ir)) {
147 return layerParam.rangeX().max;
149 float sum = layerParam.binContent(0, ip, ir);
150 for (
int i{1};
i != layerParam.numberOfBinsX() + 1; ++
i) {
151 sum += layerParam.binContent(
i, ip, ir);
153 return xBinPos(layerParam,
i, (sum -
val) / layerParam.binContent(
i, ip, ir));
157 throw cms::Exception(
"LogicError") <<
"Problem drawing a random number from the distribution";
bool putTIB(layerid layer, const LayerParameters ¶ms)
Log< level::Error, false > LogError
bool putTID(layerid wheel, const LayerParameters ¶ms)
void calculateIntegrals()
constexpr std::array< uint8_t, layerIndexSize > layer
const uint16_t range(const Frame &aFrame)
float sampleBarrel(layerid layerIdx, float z, float pu, CLHEP::HepRandomEngine *engine) const
std::vector< PhysicsTools::Calibration::HistogramF2D > m_endcapParam_xInt
std::vector< PhysicsTools::Calibration::HistogramF3D > m_endcapParam
float sampleEndcap(layerid wheelIdx, float r, float pu, CLHEP::HepRandomEngine *engine) const
std::vector< PhysicsTools::Calibration::HistogramF3D > m_barrelParam
bool putTEC(layerid wheel, const LayerParameters ¶ms)
std::vector< PhysicsTools::Calibration::HistogramF2D > m_barrelParam_xInt
bool putTOB(layerid layer, const LayerParameters ¶ms)