LDMX Software
NoiseGenerator.cxx
Go to the documentation of this file.
1
8
9#include "Framework/Exception/Exception.h"
10
11namespace ldmx {
12
13NoiseGenerator::NoiseGenerator(double noiseValue, bool gauss) {
14 noise_ = noiseValue;
15 useGaussianModel_ = gauss;
17 std::make_unique<boost::math::poisson_distribution<> >(noiseValue);
18}
19
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 // std::cout << "[ Noise Generator ]: Empty channels: "
32 // << emptyChannels << std::endl;
33 // std::cout << "[ Noise Generator ]: Normalized integration limit: "
34 // << noiseThreshold_ << std::endl;
35
36 double integral;
38 integral = ROOT::Math::normal_cdf_c(noiseThreshold_, noise_, pedestal_);
39 else
40 integral =
41 boost::math::cdf(complement(*poisson_dist_, noiseThreshold_ - 1));
42 // std::cout << "[ Noise Generator ]: Integral: "
43 // << integral << std::endl;
44
45 double noiseHitCount = random_->Binomial(emptyChannels, integral);
46 // std::cout << "[ Noise Generator ]: # Noise hits: "
47 // << noiseHitCount << std::endl;
48
49 std::vector<double> noiseHits;
50 for (int hitIndex = 0; hitIndex < noiseHitCount; ++hitIndex) {
51 double rand = random_->Uniform();
52 // std::cout << "[ Noise Generator ]: Rand: "
53 // << rand << std::endl;
54 double draw = integral * rand;
55 // std::cout << "[ Noise Generator ]: Draw: "
56 // << draw << std::endl;
57
58 double cumulativeProb = 1.0 - integral + draw;
59 // std::cout << "[ Noise Generator ]: Cumulative probability: "
60 // << cumulativeProb << std::endl;
61
62 double valueAboveThreshold;
64 valueAboveThreshold =
65 ROOT::Math::gaussian_quantile(cumulativeProb, noise_);
66 else
67 valueAboveThreshold =
68 boost::math::quantile(*poisson_dist_, cumulativeProb);
69 // std::cout << "[ Noise Generator ]: Noise value: "
70 // << gaussAboveThreshold << std::endl;
71
72 noiseHits.push_back(valueAboveThreshold);
73 }
74
75 return noiseHits;
76}
77
78} // 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.
double noiseThreshold_
The noise threshold.
std::unique_ptr< TRandom3 > random_
Random number generator.
~NoiseGenerator()
Destructor.
bool useGaussianModel_
Gaussian flag.
void seedGenerator(uint64_t seed)
Seed the generator.