ex-6: use gaussian noise instead of poisson

This commit is contained in:
Michele Guerini Rocco 2020-05-05 22:37:22 +00:00
parent 67c9d46188
commit 19981225f2

View File

@ -115,6 +115,26 @@ gsl_histogram* histogram_convolve(gsl_histogram *a, gsl_histogram *b) {
}
int show_help(char **argv) {
fprintf(stderr, "Usage: %s -[hcdoebsrmn]\n", argv[0]);
fprintf(stderr, " -h\t\tShow this message.\n");
fprintf(stderr, " -c\t\tPrint the convolved histogram to stdout.\n");
fprintf(stderr, " -d\t\tAttempt and print the deconvolved histogram.\n");
fprintf(stderr, " -o\t\tPrint the original histogram to stdout.\n");
fprintf(stderr, " -e N\t\tThe number of events. (default: 50000)\n");
fprintf(stderr, " -b N\t\tThe number of θ bins. (default: 150)\n");
fprintf(stderr, " -s SIGMA\tThe sigma of gaussian kernel. "
"(default: 0.8)\n");
fprintf(stderr, " -r N\t\tThe number of RL deconvolution rounds."
"(default: 3)\n");
fprintf(stderr, " -m MODE\tThe deconvolution mode: 'fft' or 'rl'."
"(default: 'fft')\n");
fprintf(stderr, " -n SIGMA\tThe σ of the gaussian noise to add to "
"the convolution. (default: 0)\n");
return EXIT_SUCCESS;
}
int main(int argc, char **argv) {
struct options opts;
/* Set default options */
@ -139,20 +159,7 @@ int main(int argc, char **argv) {
else if (!strcmp(argv[i], "-r")) opts.rounds = atol(argv[++i]);
else if (!strcmp(argv[i], "-m")) opts.mode = argv[++i];
else if (!strcmp(argv[i], "-n")) opts.noise = atof(argv[++i]);
else {
fprintf(stderr, "Usage: %s -[cdoebsrmh]\n", argv[0]);
fprintf(stderr, "\t-h\t\tShow this message.\n");
fprintf(stderr, "\t-c\t\tPrint the convolved histogram to stdout.\n");
fprintf(stderr, "\t-d\t\tAttempt and print the deconvolved histogram.\n");
fprintf(stderr, "\t-o\t\tPrint the original histogram to stdout.\n");
fprintf(stderr, "\t-e N\t\tThe number of events. (default: 50000)\n");
fprintf(stderr, "\t-b N\t\tThe number of θ bins. (default: 150)\n");
fprintf(stderr, "\t-s SIGMA\tThe sigma of gaussian kernel.(default: 0.8)\n");
fprintf(stderr, "\t-r N\t\tThe number of RL deconvolution rounds. (default: 3)\n");
fprintf(stderr, "\t-m MODE\t\tThe deconvolution mode: 'fft' or 'rl'. (default: 'fft')\n");
fprintf(stderr, "\t-n MU\t\tThe mean (μ) of Poisson noise to add to the convolution. (default: 0)\n");
return EXIT_FAILURE;
}
else return show_help(argv);
}
/* Initialize an RNG. */
@ -192,13 +199,13 @@ int main(int argc, char **argv) {
gsl_histogram *conv = histogram_convolve(hist, kernel);
fputs("done\n", stderr);
/* Add Poisson noise with μ=opts.noise to
/* Add gaussian noise with σ=opts.noise to
* the convolution.
*/
if (opts.noise > 0) {
fputs("2.1 adding poisson noise...", stderr);
fputs("2.1 adding noise...", stderr);
for (size_t i = 0; i < conv->n; i++)
conv->bin[i] += gsl_ran_poisson(r, opts.noise);
conv->bin[i] += conv->bin[i] * gsl_ran_gaussian(r, opts.noise);
fputs("done\n", stderr);
}