2 #include "CLHEP/Random/RandPoissonQ.h"
3 #include "CLHEP/Random/RandGaussQ.h"
4 #include "CLHEP/Random/RandFlat.h"
8 #include <gsl/gsl_sf_erf.h>
9 #include <gsl/gsl_sf_result.h>
22 std::map<
int,
float, std::less<int> >& theMap,
23 CLHEP::HepRandomEngine* engine ) {
27 int status = gsl_sf_erf_Q_e(threshold, &result);
29 if (status != 0)
std::cerr<<
"GaussianTailNoiseGenerator::could not compute gaussian tail probability for the threshold chosen"<<std::endl;
31 float probabilityLeft = result.val;
32 float meanNumberOfNoisyChannels = probabilityLeft * NumberOfchannels;
34 CLHEP::RandPoissonQ randPoissonQ(*engine, meanNumberOfNoisyChannels);
35 int numberOfNoisyChannels = randPoissonQ.fire();
37 float lowLimit = threshold * noiseRMS;
38 for (
int i = 0;
i < numberOfNoisyChannels;
i++) {
41 int theChannelNumber = (int)CLHEP::RandFlat::shoot(engine, NumberOfchannels);
47 theMap[theChannelNumber] = noise;
56 std::vector<std::pair<int,float> > &theVector,
57 CLHEP::HepRandomEngine* engine ) {
61 int status = gsl_sf_erf_Q_e(threshold, &result);
62 if (status != 0)
std::cerr<<
"GaussianTailNoiseGenerator::could not compute gaussian tail probability for the threshold chosen"<<std::endl;
63 double probabilityLeft = result.val;
64 double meanNumberOfNoisyChannels = probabilityLeft * NumberOfchannels;
66 CLHEP::RandPoissonQ randPoissonQ(*engine, meanNumberOfNoisyChannels);
67 int numberOfNoisyChannels = randPoissonQ.fire();
69 if(numberOfNoisyChannels>NumberOfchannels) numberOfNoisyChannels=NumberOfchannels;
72 theVector.reserve(numberOfNoisyChannels);
73 float lowLimit = threshold * noiseRMS;
74 int* channels =
getRandomChannels(numberOfNoisyChannels,NumberOfchannels, engine);
76 for (
int i = 0;
i < numberOfNoisyChannels;
i++) {
80 theVector.push_back(std::pair<int, float>(channels[
i], noise));
102 std::vector<double> &theVector,
103 CLHEP::HepRandomEngine* engine ) {
109 unsigned int numberOfchannels = theVector.size();
110 for (
unsigned int i = 0;
i < numberOfchannels; ++
i) {
111 if(theVector[
i]==0) theVector[
i] = CLHEP::RandGaussQ::shoot(engine, 0., noiseRMS);
117 if(numberOfNoisyChannels>numberOfchannels) numberOfNoisyChannels = numberOfchannels;
120 int theChannelNumber;
121 for(
int j=0;
j<numberOfNoisyChannels;++
j) {
122 theChannelNumber = (int)CLHEP::RandFlat::shoot(engine, numberOfchannels-
j) +
j;
125 array[
j] = array[theChannelNumber];
126 array[theChannelNumber] =
b;
147 x = CLHEP::RandGaussQ::shoot(engine, 0., 1.0);
163 u = CLHEP::RandFlat::shoot(engine);
165 v = CLHEP::RandFlat::shoot(engine);
double generate_gaussian_tail(const double, const double, CLHEP::HepRandomEngine *)
GaussianTailNoiseGenerator()
void generate(int NumberOfchannels, float threshold, float noiseRMS, std::map< int, float > &theMap, CLHEP::HepRandomEngine *)
int * getRandomChannels(int, int, CLHEP::HepRandomEngine *)
void generateRaw(float noiseRMS, std::vector< double > &, CLHEP::HepRandomEngine *)