aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2016-04-01 15:30:57 +0200
committerThomas White <taw@physics.org>2016-04-01 15:30:57 +0200
commitb62b7f7356f529ab904dabefb4618afc8f2211ec (patch)
tree9ee95d5a86c0379c8d611789fea47c717510b803
parent5ecd23cddcbb1b4eda422bf8351ea18c6997b7ce (diff)
Add adu_per_photon (distinct from adu_per_eV)
-rw-r--r--doc/man/crystfel_geometry.57
-rw-r--r--libcrystfel/src/detector.c43
-rw-r--r--libcrystfel/src/detector.h5
-rw-r--r--libcrystfel/src/hdf5-file.c4
-rw-r--r--libcrystfel/src/integration.c2
-rw-r--r--libcrystfel/src/peaks.c2
6 files changed, 55 insertions, 8 deletions
diff --git a/doc/man/crystfel_geometry.5 b/doc/man/crystfel_geometry.5
index 021d4493..d38f30fd 100644
--- a/doc/man/crystfel_geometry.5
+++ b/doc/man/crystfel_geometry.5
@@ -132,7 +132,12 @@ The range of pixels in the data block specified by the 'data' property that corr
.PD 0
.IP \fBadu_per_eV\fR
.PD
-The number of detector intensity units (ADU) which will arise from one electron-Volt of photon energy. This is used to estimate Poisson errors. Note that setting different values for this parameter for different panels does \fBnot\fR result in the intensities being scaled accordingly.
+The number of detector intensity units (ADU) which will arise from one electron-Volt of photon energy. This is used to estimate Poisson errors. Note that setting different values for this parameter for different panels does \fBnot\fR result in the intensities being scaled accordingly when integrating data, but it does affect the intensities calculated by \fBpattern_sim\fR. You should only specify one out of \fBadu_per_eV\fR and \fBadu_per_photon\fR, but if you use both then \fBadu_per_photon\fR will have priority.
+
+.PD 0
+.IP \fBadu_per_photon\fR
+.PD
+The number of detector intensity units (ADU) which will arise from one photon. This is used to estimate Poisson errors. Note that setting different values for this parameter for different panels does \fBnot\fR result in the intensities being scaled accordingly when integrating data, but it does affect the intensities calculated by \fBpattern_sim\fR. You should only specify one out of \fBadu_per_eV\fR and \fBadu_per_photon\fR, but if you use both then \fBadu_per_photon\fR will have priority.
.PD 0
.IP \fBbadrow_direction\fR
diff --git a/libcrystfel/src/detector.c b/libcrystfel/src/detector.c
index fa581ae2..af1a6da8 100644
--- a/libcrystfel/src/detector.c
+++ b/libcrystfel/src/detector.c
@@ -467,7 +467,7 @@ static void record_panel(struct panel *p, float *dp, int do_poisson,
dval = counts + poisson_noise(rng, background);
/* Convert to ADU */
- dval *= p->adu_per_eV * ph_lambda_to_eV(lambda);
+ dval *= p->adu_per_photon;
/* Saturation */
if ( dval > p->max_adu ) dval = p->max_adu;
@@ -511,7 +511,10 @@ void record_image(struct image *image, int do_poisson, double background,
"Total energy = %5.3f microJ\n",
nphotons, energy_density/1e7, total_energy*1e6);
+ fill_in_adu(image);
+
for ( pn=0; pn<image->det->n_panels; pn++ ) {
+
record_panel(&image->det->panels[pn], image->dp[pn],
do_poisson, rng, ph_per_e, background,
image->lambda,
@@ -615,6 +618,32 @@ void fill_in_values(struct detector *det, struct hdfile *f, struct event* ev)
}
+void fill_in_adu(struct image *image)
+{
+ int i;
+
+ if ( image->det == NULL ) return;
+
+ for ( i=0; i<image->det->n_panels; i++ ) {
+
+ struct panel *p = &image->det->panels[i];
+
+ /* Already have ADU per photon? */
+ if ( !isnan(p->adu_per_photon) ) continue;
+
+ if ( isnan(p->adu_per_eV) ) {
+ ERROR("Neither adu_per_eV nor adu_per_photon set for "
+ "panel %s\n", p->name);
+ continue;
+ }
+
+ /* Convert ADU per eV to ADU per photon */
+ p->adu_per_photon = ph_lambda_to_eV(image->lambda)
+ * p->adu_per_eV;
+ }
+}
+
+
int panel_is_in_rigid_group(const struct rigid_group *rg, struct panel *p)
{
int i;
@@ -924,6 +953,9 @@ static int parse_field_for_panel(struct panel *panel, const char *key,
panel->cny = atof(val);
} else if ( strcmp(key, "adu_per_eV") == 0 ) {
panel->adu_per_eV = atof(val);
+ } else if ( strcmp(key, "adu_per_photon") == 0 ) {
+ panel->adu_per_photon = atof(val);
+ STATUS("got adu per photon: %s\n", val);
} else if ( strcmp(key, "rigid_group") == 0 ) {
add_to_rigid_group(find_or_add_rg(det, val), panel);
} else if ( strcmp(key, "clen") == 0 ) {
@@ -1265,6 +1297,7 @@ struct detector *get_detector_geometry(const char *filename,
det->defaults.ssx = 0.0;
det->defaults.ssy = 1.0;
det->defaults.adu_per_eV = NAN;
+ det->defaults.adu_per_photon = NAN;
det->defaults.max_adu = +INFINITY;
det->defaults.mask = NULL;
det->defaults.mask_file = NULL;
@@ -1542,9 +1575,11 @@ struct detector *get_detector_geometry(const char *filename,
" panel %s\n", det->panels[i].name);
reject = 1;
}
- if ( isnan(det->panels[i].adu_per_eV) ) {
- ERROR("Please specify the number of ADU per eV for"
- " panel %s\n", det->panels[i].name);
+ if ( isnan(det->panels[i].adu_per_eV)
+ && isnan(det->panels[i].adu_per_photon) ) {
+ ERROR("Please specify either adu_per_eV or "
+ "adu_per_photon for panel %s\n",
+ det->panels[i].name);
reject = 1;
}
diff --git a/libcrystfel/src/detector.h b/libcrystfel/src/detector.h
index 540db4b6..a52d56b7 100644
--- a/libcrystfel/src/detector.h
+++ b/libcrystfel/src/detector.h
@@ -102,10 +102,12 @@ struct panel
double res; /* Resolution in pixels per metre */
char badrow; /* 'x' or 'y' */
int no_index; /* Don't index peaks in this panel if non-zero */
- double adu_per_eV; /* Number of ADU per eV */
+ double adu_per_photon; /* Number of ADU per photon */
double max_adu; /* Treat pixel as unreliable if higher than this */
char *data;
+ double adu_per_eV; /* Number of ADU per eV */
+
struct dim_structure *dim_structure;
double fsx;
@@ -223,6 +225,7 @@ extern void get_pixel_extents(struct detector *det,
extern void fill_in_values(struct detector *det, struct hdfile *f,
struct event* ev);
+extern void fill_in_adu(struct image *image);
extern int panel_is_in_rigid_group(const struct rigid_group *rg,
struct panel *p);
diff --git a/libcrystfel/src/hdf5-file.c b/libcrystfel/src/hdf5-file.c
index 023b0f7d..ee352f03 100644
--- a/libcrystfel/src/hdf5-file.c
+++ b/libcrystfel/src/hdf5-file.c
@@ -1482,6 +1482,8 @@ int hdf5_read(struct hdfile *f, struct image *image, const char *element,
}
+ fill_in_adu(image);
+
return 0;
}
@@ -1915,6 +1917,8 @@ int hdf5_read2(struct hdfile *f, struct image *image, struct event *ev,
}
+ fill_in_adu(image);
+
free(buf);
free(flags);
free(smap);
diff --git a/libcrystfel/src/integration.c b/libcrystfel/src/integration.c
index ce996db7..7380f836 100644
--- a/libcrystfel/src/integration.c
+++ b/libcrystfel/src/integration.c
@@ -1463,7 +1463,7 @@ static void integrate_rings_once(Reflection *refl, struct image *image,
intensity = tentative_intensity(ic, bx);
mean_var_area(ic, bx, BM_BG, &bgmean, &sig2_bg);
- aduph = bx->p->adu_per_eV * ph_lambda_to_eV(ic->image->lambda);
+ aduph = bx->p->adu_per_photon;
sig2_poisson = aduph * intensity;
/* If intensity is within one photon of nothing, set the Poisson
diff --git a/libcrystfel/src/peaks.c b/libcrystfel/src/peaks.c
index eda43a23..6f67255b 100644
--- a/libcrystfel/src/peaks.c
+++ b/libcrystfel/src/peaks.c
@@ -252,7 +252,7 @@ static int integrate_peak(struct image *image, int cfs, int css,
p_cfs = cfs - p->min_fs;
p_css = css - p->min_ss; /* Panel-relative coordinates */
- aduph = p->adu_per_eV * ph_lambda_to_eV(image->lambda);
+ aduph = p->adu_per_photon;
lim_sq = pow(ir_inn, 2.0);
mid_lim_sq = pow(ir_mid, 2.0);