3 #include "CLHEP/Random/RandFlat.h" 22 hXInt.setBinContent(
i, j, xInt);
31 const auto range = hist.
rangeX();
32 const auto binWidth = (range.max-range.min)/hist.
numberOfBinsX();
33 return range.min+(iBin-1+
pos)*binWidth;
41 if (m_barrelParam.size() != m_barrelParam_xInt.size()) {
42 m_barrelParam_xInt.resize(m_barrelParam.size());
43 for (
unsigned int i{0};
i != m_barrelParam.size(); ++
i) {
44 m_barrelParam_xInt[
i] = calculateXInt(m_barrelParam[
i]);
47 if (m_endcapParam.size() != m_endcapParam_xInt.size()) {
48 m_endcapParam_xInt.resize(m_endcapParam.size());
49 for (
unsigned int i{0};
i != m_endcapParam.size(); ++
i) {
50 m_endcapParam_xInt[
i] = calculateXInt(m_endcapParam[
i]);
57 if ((layer > m_nTIB) || (layer < 1)) {
59 <<
"[" << __PRETTY_FUNCTION__ <<
"] layer index " << layer <<
" out of range [1," << m_nTIB <<
"]";
62 m_barrelParam[layer - 1] = params;
63 m_barrelParam_xInt[layer - 1] = calculateXInt(params);
69 if ((layer > m_nTOB) || (layer < 1)) {
70 edm::LogError(
"SiStripApvSimulationParameters") <<
"[" << __PRETTY_FUNCTION__ <<
"] layer index " << layer
71 <<
" out of range [1," << m_nTOB <<
")";
74 m_barrelParam[m_nTIB + layer - 1] = params;
75 m_barrelParam_xInt[m_nTIB + layer - 1] = calculateXInt(params);
81 if ((wheel > m_nTID) || (wheel < 1)) {
83 <<
"[" << __PRETTY_FUNCTION__ <<
"] wheel index " << wheel <<
" out of range [1," << m_nTID <<
"]";
86 m_endcapParam[wheel - 1] = params;
87 m_endcapParam_xInt[wheel - 1] = calculateXInt(params);
93 if ((wheel > m_nTEC) || (wheel < 1)) {
95 <<
"[" << __PRETTY_FUNCTION__ <<
"] wheel index " << wheel <<
" out of range [1," << m_nTEC <<
")";
98 m_endcapParam[m_nTID + wheel - 1] = params;
99 m_endcapParam_xInt[m_nTID + wheel - 1] = calculateXInt(params);
106 CLHEP::HepRandomEngine* engine)
const {
107 if (m_barrelParam.size() != m_barrelParam_xInt.size()) {
108 throw cms::Exception(
"LogicError") <<
"x-integrals of 3D histograms have not been calculated";
110 const auto layerParam = m_barrelParam[layerIdx];
111 const int ip = layerParam.findBinY(pu);
112 const int iz = layerParam.findBinZ(z);
113 const float norm = m_barrelParam_xInt[layerIdx].binContent(ip, iz);
114 const auto val = CLHEP::RandFlat::shoot(engine) * norm;
115 if (
val < layerParam.binContent(0, ip, iz)) {
116 return layerParam.rangeX().min;
117 }
else if (norm -
val < layerParam.binContent(layerParam.numberOfBinsX() + 1, ip, iz)) {
118 return layerParam.rangeX().max;
120 float sum = layerParam.binContent(0, ip, iz);
121 for (
int i{1};
i != layerParam.numberOfBinsX() + 1; ++
i) {
122 sum += layerParam.binContent(
i, ip, iz);
124 return xBinPos(layerParam,
i, (sum-
val)/layerParam.binContent(
i, ip, iz));
128 throw cms::Exception(
"LogicError") <<
"Problem drawing a random number from the distribution";
134 CLHEP::HepRandomEngine* engine)
const {
135 if (m_endcapParam.size() != m_endcapParam_xInt.size()) {
136 throw cms::Exception(
"LogicError") <<
"x-integrals of 3D histograms have not been calculated";
138 const auto layerParam = m_endcapParam[wheelIdx];
139 const int ip = layerParam.findBinY(pu);
140 const int ir = layerParam.findBinZ(r);
141 const float norm = m_endcapParam_xInt[wheelIdx].binContent(ip, ir);
142 const auto val = CLHEP::RandFlat::shoot(engine) * norm;
143 if (
val < layerParam.binContent(0, ip, ir)) {
144 return layerParam.rangeX().min;
145 }
else if (norm -
val < layerParam.binContent(layerParam.numberOfBinsX() + 1, ip, ir)) {
146 return layerParam.rangeX().max;
148 float sum = layerParam.binContent(0, ip, ir);
149 for (
int i{1};
i != layerParam.numberOfBinsX() + 1; ++
i) {
150 sum += layerParam.binContent(
i, ip, ir);
152 return xBinPos(layerParam,
i, (sum -
val) / layerParam.binContent(
i, ip, ir));
156 throw cms::Exception(
"LogicError") <<
"Problem drawing a random number from the distribution";
bool putTIB(layerid layer, const LayerParameters ¶ms)
bool putTID(layerid wheel, const LayerParameters ¶ms)
void calculateIntegrals()
float sampleBarrel(layerid layerIdx, float z, float pu, CLHEP::HepRandomEngine *engine) const
float sampleEndcap(layerid wheelIdx, float r, float pu, CLHEP::HepRandomEngine *engine) const
bool putTEC(layerid wheel, const LayerParameters ¶ms)
bool putTOB(layerid layer, const LayerParameters ¶ms)