LDMX Software
NoiseGenerator.cxx
Go to the documentation of this file.
1
8
9namespace ldmx {
10
11NoiseGenerator::NoiseGenerator(double noiseValue, bool gauss) {
12 noise_ = noiseValue;
13 use_gaussian_model_ = gauss;
15 std::make_unique<boost::math::poisson_distribution<> >(noiseValue);
16}
17
18void NoiseGenerator::seedGenerator(uint64_t seed) {
19 random_ = std::make_unique<TRandom3>(seed);
20}
21
22std::vector<double> NoiseGenerator::generateNoiseHits(int emptyChannels) {
23 if (random_.get() == nullptr) {
24 EXCEPTION_RAISE("RandomSeedException",
25 "Noise generator was not seeded before use");
26 }
27 ldmx_log(trace) << "Empty channels: " << emptyChannels;
28 ldmx_log(trace) << "Normalized integration limit: " << noise_threshold_;
29
30 double integral;
32 integral = ROOT::Math::normal_cdf_c(noise_threshold_, noise_, pedestal_);
33 else
34 integral =
35 boost::math::cdf(complement(*poisson_dist_, noise_threshold_ - 1));
36 ldmx_log(trace) << "Integral: " << integral;
37
38 double noise_hit_count = random_->Binomial(emptyChannels, integral);
39 ldmx_log(trace) << "# Noise hits_: " << noise_hit_count;
40
41 std::vector<double> noise_hits;
42 for (int hit_index = 0; hit_index < noise_hit_count; ++hit_index) {
43 double rand = random_->Uniform();
44 ldmx_log(trace) << "Rand: " << rand;
45 double draw = integral * rand;
46 ldmx_log(trace) << "Draw: " << draw;
47
48 double cumulative_prob = 1.0 - integral + draw;
49 ldmx_log(trace) << "Cumulative probability: " << cumulative_prob;
50
51 double value_above_threshold;
53 value_above_threshold =
54 ROOT::Math::gaussian_quantile(cumulative_prob, noise_);
55 } else {
56 value_above_threshold =
57 boost::math::quantile(*poisson_dist_, cumulative_prob);
58 }
59 ldmx_log(trace) << "Noise value: " << value_above_threshold;
60
61 noise_hits.push_back(value_above_threshold);
62 }
63
64 return noise_hits;
65}
66
67} // 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.