aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel
diff options
context:
space:
mode:
Diffstat (limited to 'libcrystfel')
-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
-rw-r--r--libcrystfel/src/predict-refine.c3
6 files changed, 49 insertions, 10 deletions
diff --git a/libcrystfel/src/detector.c b/libcrystfel/src/detector.c
index b8c4bbc1..debb64fb 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 f717d527..0fb388b4 100644
--- a/libcrystfel/src/hdf5-file.c
+++ b/libcrystfel/src/hdf5-file.c
@@ -1495,6 +1495,8 @@ int hdf5_read(struct hdfile *f, struct image *image, const char *element,
}
+ fill_in_adu(image);
+
return 0;
}
@@ -1928,6 +1930,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);
diff --git a/libcrystfel/src/predict-refine.c b/libcrystfel/src/predict-refine.c
index 113e9c7c..70345803 100644
--- a/libcrystfel/src/predict-refine.c
+++ b/libcrystfel/src/predict-refine.c
@@ -331,7 +331,6 @@ void refine_radius(Crystal *cr, struct image *image)
reflist = reflist_new();
n_acc = pair_peaks(image, cr, reflist, rps);
if ( n_acc < 3 ) {
- ERROR("Too few paired peaks (%i) to determine radius\n", n_acc);
free(rps);
return;
}
@@ -596,7 +595,6 @@ int refine_prediction(struct image *image, Crystal *cr)
reflist = reflist_new();
n = pair_peaks(image, cr, reflist, rps);
if ( n < 10 ) {
- ERROR("Too few paired peaks (%i) to refine orientation.\n", n);
free(rps);
reflist_free(reflist);
return 1;
@@ -640,7 +638,6 @@ int refine_prediction(struct image *image, Crystal *cr)
n = pair_peaks(image, cr, NULL, rps);
free_rps_noreflist(rps, n);
if ( n < 10 ) {
- ERROR("Too few paired peaks (%i) after refinement.\n", n);
return 1;
}