LDMX Software
NoiseGenerator.cxx
Go to the documentation of this file.
1
8
9#include "Framework/Exception/Exception.h"
10#include "Math/ProbFuncMathCore.h"
11#include "Math/QuantFuncMathCore.h"
12
13namespace ldmx {
14
15NoiseGenerator::NoiseGenerator(double noiseValue, bool gauss) {
16 noise_ = noiseValue;
17 use_gaussian_model_ = gauss;
19 std::make_unique<boost::math::poisson_distribution<> >(noiseValue);
20}
21
22void NoiseGenerator::seedGenerator(uint64_t seed) {
23 random_ = std::make_unique<TRandom3>(seed);
24}
25
26std::vector<double> NoiseGenerator::generateNoiseHits(int emptyChannels) {
27 if (random_.get() == nullptr) {
28 EXCEPTION_RAISE("RandomSeedException",
29 "Noise generator was not seeded before use");
30 }
31 ldmx_log(trace) << "Empty channels: " << emptyChannels;
32 ldmx_log(trace) << "Normalized integration limit: " << noise_threshold_;
33
34 double integral;
36 integral = ROOT::Math::normal_cdf_c(noise_threshold_, noise_, pedestal_);
37 else
38 integral =
39 boost::math::cdf(complement(*poisson_dist_, noise_threshold_ - 1));
40 ldmx_log(trace) << "Integral: " << integral;
41
42 double noise_hit_count = random_->Binomial(emptyChannels, integral);
43 ldmx_log(trace) << "# Noise hits_: " << noise_hit_count;
44
45 std::vector<double> noise_hits;
46 for (int hit_index = 0; hit_index < noise_hit_count; ++hit_index) {
47 double rand = random_->Uniform();
48 ldmx_log(trace) << "Rand: " << rand;
49 double draw = integral * rand;
50 ldmx_log(trace) << "Draw: " << draw;
51
52 double cumulative_prob = 1.0 - integral + draw;
53 ldmx_log(trace) << "Cumulative probability: " << cumulative_prob;
54
55 double value_above_threshold;
57 value_above_threshold =
58 ROOT::Math::gaussian_quantile(cumulative_prob, noise_);
59 } else {
60 value_above_threshold =
61 boost::math::quantile(*poisson_dist_, cumulative_prob);
62 }
63 ldmx_log(trace) << "Noise value: " << value_above_threshold;
64
65 noise_hits.push_back(value_above_threshold);
66 }
67
68 return noise_hits;
69}
70
71} // namespace ldmx
Utility used to generate noise hits_.
double noise_
Mean noise.
std::unique_ptr< boost::math::poisson_distribution<> > poisson_dist_
pdf for poisson errors
std::vector< double > generateNoiseHits(int emptyChannels)
Generate noise hits_.
NoiseGenerator(double noiseValue=0.0001, bool gauss=true)
Constructor.
double pedestal_
Pedestal or baseline.
std::unique_ptr< TRandom3 > random_
Random number generator.
void seedGenerator(uint64_t seed)
Seed the generator.
double noise_threshold_
The noise threshold.
bool use_gaussian_model_
Gaussian flag.