diff options
author | Thomas White <taw@physics.org> | 2014-01-23 15:30:29 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2014-01-23 16:07:37 +0100 |
commit | 762ed2c39f48e226ddeab459e9b00dbc20b9eaef (patch) | |
tree | 5dcc70e7736610145b931e9f6fbce1d6f6dc708a /libcrystfel/src/detector.c | |
parent | 3776f8cbfd41798a1591a1a5a337fffef3322bd5 (diff) |
pattern_sim: Add --background
Diffstat (limited to 'libcrystfel/src/detector.c')
-rw-r--r-- | libcrystfel/src/detector.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/libcrystfel/src/detector.c b/libcrystfel/src/detector.c index 99205e67..257d1daa 100644 --- a/libcrystfel/src/detector.c +++ b/libcrystfel/src/detector.c @@ -312,7 +312,8 @@ double get_tt(struct image *image, double fs, double ss, int *err) } -void record_image(struct image *image, int do_poisson, gsl_rng *rng) +void record_image(struct image *image, int do_poisson, int background, + gsl_rng *rng) { int x, y; double total_energy, energy_density; @@ -345,6 +346,7 @@ void record_image(struct image *image, int do_poisson, gsl_rng *rng) double pix_area, Lsq; double xs, ys, rx, ry; double dsq, proj_area; + float dval; struct panel *p; intensity = (double)image->data[x + image->width*y]; @@ -378,8 +380,13 @@ void record_image(struct image *image, int do_poisson, gsl_rng *rng) counts = cf; } - image->data[x + image->width*y] = counts * p->adu_per_eV - * ph_lambda_to_eV(image->lambda); + /* Number of photons in pixel */ + dval = counts + poisson_noise(rng, background); + + /* Convert to ADU */ + dval *= p->adu_per_eV * ph_lambda_to_eV(image->lambda); + + image->data[x + image->width*y] = dval; /* Sanity checks */ if ( isinf(image->data[x+image->width*y]) ) n_inf2++; |