1 #ifndef _AccidentialInjectorKG_Utilities_h_
2 #define _AccidentialInjectorKG_Utilities_h_
5 #include <utl/MathConstants.h>
6 #include <utl/RandomEngine.h>
7 #include <fwk/RandomEngineRegistry.h>
9 #include <CLHEP/Random/Randomize.h>
18 namespace SdAccidentalInjectorKG {
21 std::pair<double, double>
26 const double areaSide = 2 * sinTheta * radius * height;
27 return std::make_pair(areaTop, areaSide);
34 StationArea(
const double radius,
const double height,
const double cosTheta)
37 return ts.first + ts.second;
44 fEngine(&fwk::RandomEngineRegistry::GetInstance().
Get(fwk::RandomEngineRegistry::eDetector).GetEngine())
47 double operator()(
const double vmin,
const double vmax)
const
48 {
return CLHEP::RandFlat::shoot(
fEngine, vmin, vmax); }
51 {
return CLHEP::RandFlat::shoot(
fEngine, 0, vmax); }
54 {
return CLHEP::RandFlat::shoot(
fEngine, 0, 1); }
64 fEngine(&fwk::RandomEngineRegistry::GetInstance().
Get(fwk::RandomEngineRegistry::eDetector).GetEngine())
68 {
return CLHEP::RandPoisson::shoot(
fEngine, expectation); }
98 const unsigned int nx = h.GetNbinsX();
99 const unsigned int ny = h.GetNbinsY();
102 for (
unsigned int ix = 1; ix <= nx; ++ix)
103 for (
unsigned int iy = 1; iy <= ny; ++iy) {
104 sum += h.GetBinContent(ix, iy);
109 std::pair<double, double>
116 const int i = std::upper_bound(begin,
fLineIntegral.end(), z) - begin;
118 const int ix = (i / n) + 1;
119 const int iy = (i % n) + 1;
123 const double x =
fFlat(ax.GetBinLowEdge(ix), ax.GetBinUpEdge(ix));
125 const double y =
fFlat(ay.GetBinLowEdge(iy), ay.GetBinUpEdge(iy));
126 return std::make_pair(x, y);
148 std::tuple<double, double, double>
153 const double totArea = area.first + area.second;
155 if (
fFlat() < area.first / totArea) {
159 return std::make_tuple(r * std::sin(f), r * std::cos(f),
fHeight);
165 const double c = std::cos(phi);
166 const double s = std::sin(phi);
167 return std::make_tuple(x*c - y*s, x*s + y*c, z);
double operator()(const double expectation) const
double StationArea(const double radius, const double height, const double cosTheta)
std::pair< double, double > StationTopSideArea(const double radius, const double height, const double cosTheta)
constexpr T Sqr(const T &x)
utl::RandomEngine::RandomEngineType * fEngine
HistogramSampler(const TH2D &h)
std::vector< double > fLineIntegral
double operator()() const
double operator()(const double vmax) const
std::pair< double, double > operator()() const
CylinderSurfaceSampler(const double radius, const double height, const double hull)
double operator()(const double vmin, const double vmax) const
utl::RandomEngine::RandomEngineType * fEngine
utl::CoordinateSystemPtr Get(const std::string &id)
Get a well-known Coordinate System.
std::tuple< double, double, double > operator()(const double theta, const double phi) const
CLHEP::HepRandomEngine RandomEngineType