3 #include "CLHEP/Random/RandFlat.h" 7 auto hXInt = (
params.hasEquidistantBinsY()
8 ? (
params.hasEquidistantBinsZ()
13 : (
params.hasEquidistantBinsZ()
17 for (
int i{0};
i !=
params.numberOfBinsY() + 2; ++
i) {
18 for (
int j{0};
j !=
params.numberOfBinsZ() + 2; ++
j) {
20 for (
int k{0};
k !=
params.numberOfBinsX() + 2; ++
k) {
23 hXInt.setBinContent(
i,
j, xInt);
31 if (
hist.hasEquidistantBinsX()) {
33 const auto binWidth = (
range.max -
range.min) /
hist.numberOfBinsX();
34 return range.min + (iBin - 1 +
pos) * binWidth;
36 return (1. -
pos) *
hist.upperLimitsX()[iBin - 1] +
pos *
hist.upperLimitsX()[iBin];
60 <<
"[" << __PRETTY_FUNCTION__ <<
"] layer index " <<
layer <<
" out of range [1," <<
m_nTIB <<
"]";
72 <<
"[" << __PRETTY_FUNCTION__ <<
"] layer index " <<
layer <<
" out of range [1," <<
m_nTOB <<
")";
84 <<
"[" << __PRETTY_FUNCTION__ <<
"] wheel index " <<
wheel <<
" out of range [1," <<
m_nTID <<
"]";
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
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)
float sampleBarrel(layerid layerIdx, float z, float pu, CLHEP::HepRandomEngine *engine) const