format
This commit is contained in:
parent
b8a8891c8d
commit
f28acaa3d5
@ -75,8 +75,6 @@ static PyObject *ClusterFileReader_read(ClusterFileReader *self,
|
|||||||
// if data type is different or we pass in a list. The
|
// if data type is different or we pass in a list. The
|
||||||
// NPY_ARRAY_C_CONTIGUOUS flag ensures that we have contiguous memory.
|
// NPY_ARRAY_C_CONTIGUOUS flag ensures that we have contiguous memory.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef CR_VERBOSE
|
#ifdef CR_VERBOSE
|
||||||
printf("Getting ready to read: %lu clusters. Noise map: %p\n", size,
|
printf("Getting ready to read: %lu clusters. Noise map: %p\n", size,
|
||||||
noise_obj);
|
noise_obj);
|
||||||
@ -134,8 +132,8 @@ static PyObject *ClusterFileReader_read(ClusterFileReader *self,
|
|||||||
// Here goes the looping, removing frame numbers etc.
|
// Here goes the looping, removing frame numbers etc.
|
||||||
int n_read = 0;
|
int n_read = 0;
|
||||||
if (noise_map)
|
if (noise_map)
|
||||||
n_read = read_clusters_with_cut(self->fp, size, buf, &self->n_left, noise_map,
|
n_read = read_clusters_with_cut(self->fp, size, buf, &self->n_left,
|
||||||
nx, ny);
|
noise_map, nx, ny);
|
||||||
else
|
else
|
||||||
n_read = read_clusters(self->fp, size, buf, &self->n_left);
|
n_read = read_clusters(self->fp, size, buf, &self->n_left);
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@ int read_clusters(FILE *fp, int64_t n_clusters, Cluster *buf, int *n_left) {
|
|||||||
// keep on reading frames and photons until reaching n_clusters
|
// keep on reading frames and photons until reaching n_clusters
|
||||||
while (fread(&iframe, sizeof(iframe), 1, fp)) {
|
while (fread(&iframe, sizeof(iframe), 1, fp)) {
|
||||||
|
|
||||||
|
|
||||||
if (fread(&nph, sizeof(nph), 1, fp)) {
|
if (fread(&nph, sizeof(nph), 1, fp)) {
|
||||||
if (nph > n_clusters - nph_read)
|
if (nph > n_clusters - nph_read)
|
||||||
nn = n_clusters - nph_read;
|
nn = n_clusters - nph_read;
|
||||||
@ -39,18 +38,14 @@ int read_clusters(FILE *fp, int64_t n_clusters, Cluster *buf, int *n_left) {
|
|||||||
}
|
}
|
||||||
if (nph_read >= n_clusters)
|
if (nph_read >= n_clusters)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert(nph_read <= n_clusters); // sanity check in debug mode
|
assert(nph_read <= n_clusters); // sanity check in debug mode
|
||||||
return nph_read;
|
return nph_read;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int read_clusters_with_cut(FILE *fp, int64_t n_clusters, Cluster *buf,
|
||||||
|
int *n_left, double *noise_map, int nx, int ny) {
|
||||||
int read_clusters_with_cut(FILE *fp, int64_t n_clusters, Cluster *buf, int *n_left, double *noise_map, int nx, int ny) {
|
|
||||||
int iframe = 0;
|
int iframe = 0;
|
||||||
int nph = *n_left;
|
int nph = *n_left;
|
||||||
|
|
||||||
@ -58,27 +53,28 @@ int read_clusters_with_cut(FILE *fp, int64_t n_clusters, Cluster *buf, int *n_le
|
|||||||
|
|
||||||
int32_t tot2[4], t2max, tot1;
|
int32_t tot2[4], t2max, tot1;
|
||||||
int32_t val, tot3;
|
int32_t val, tot3;
|
||||||
Cluster *ptr=buf;
|
Cluster *ptr = buf;
|
||||||
int good=1;
|
int good = 1;
|
||||||
double noise;
|
double noise;
|
||||||
// read photons left from previous frame
|
// read photons left from previous frame
|
||||||
if (nph) {
|
if (nph) {
|
||||||
for (int iph=0; iph<nph; iph++) {
|
for (int iph = 0; iph < nph; iph++) {
|
||||||
// read photons 1 by 1
|
// read photons 1 by 1
|
||||||
fread((void *)(ptr), sizeof(Cluster), 1, fp);
|
fread((void *)(ptr), sizeof(Cluster), 1, fp);
|
||||||
good=1;
|
good = 1;
|
||||||
if (noise_map) {
|
if (noise_map) {
|
||||||
if (ptr->x>=0 && ptr->x<nx && ptr->y>=0 && ptr->y<ny) {
|
if (ptr->x >= 0 && ptr->x < nx && ptr->y >= 0 && ptr->y < ny) {
|
||||||
tot1=ptr->data[4];
|
tot1 = ptr->data[4];
|
||||||
analyze_cluster(*ptr, &t2max, &tot3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
|
analyze_cluster(*ptr, &t2max, &tot3, NULL, NULL, NULL, NULL,
|
||||||
noise=noise_map[ptr->y*nx+ptr->x];
|
NULL, NULL, NULL, NULL, NULL);
|
||||||
if (tot1>noise && t2max>2*noise && tot3>3*noise) {
|
noise = noise_map[ptr->y * nx + ptr->x];
|
||||||
|
if (tot1 > noise && t2max > 2 * noise && tot3 > 3 * noise) {
|
||||||
;
|
;
|
||||||
} else
|
} else
|
||||||
good=0;
|
good = 0;
|
||||||
} else {
|
} else {
|
||||||
printf("Bad pixel number %d %d\n",ptr->x,ptr->y);
|
printf("Bad pixel number %d %d\n", ptr->x, ptr->y);
|
||||||
good=0;
|
good = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (good) {
|
if (good) {
|
||||||
@ -94,27 +90,31 @@ int read_clusters_with_cut(FILE *fp, int64_t n_clusters, Cluster *buf, int *n_le
|
|||||||
if (nph_read < n_clusters) {
|
if (nph_read < n_clusters) {
|
||||||
// keep on reading frames and photons until reaching n_clusters
|
// keep on reading frames and photons until reaching n_clusters
|
||||||
while (fread(&iframe, sizeof(iframe), 1, fp)) {
|
while (fread(&iframe, sizeof(iframe), 1, fp)) {
|
||||||
//printf("%d\n",nph_read);
|
// printf("%d\n",nph_read);
|
||||||
|
|
||||||
if (fread(&nph, sizeof(nph), 1, fp)) {
|
if (fread(&nph, sizeof(nph), 1, fp)) {
|
||||||
//printf("** %d\n",nph);
|
// printf("** %d\n",nph);
|
||||||
*n_left = nph;
|
*n_left = nph;
|
||||||
for (int iph=0; iph<nph; iph++) {
|
for (int iph = 0; iph < nph; iph++) {
|
||||||
// read photons 1 by 1
|
// read photons 1 by 1
|
||||||
fread((void *)(ptr), sizeof(Cluster), 1, fp);
|
fread((void *)(ptr), sizeof(Cluster), 1, fp);
|
||||||
good=1;
|
good = 1;
|
||||||
if (noise_map) {
|
if (noise_map) {
|
||||||
if (ptr->x>=0 && ptr->x<nx && ptr->y>=0 && ptr->y<ny) {
|
if (ptr->x >= 0 && ptr->x < nx && ptr->y >= 0 &&
|
||||||
tot1=ptr->data[4];
|
ptr->y < ny) {
|
||||||
analyze_cluster(*ptr, &t2max, &tot3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
|
tot1 = ptr->data[4];
|
||||||
noise=noise_map[ptr->y*nx+ptr->x];
|
analyze_cluster(*ptr, &t2max, &tot3, NULL, NULL,
|
||||||
if (tot1>noise && t2max>2*noise && tot3>3*noise) {
|
NULL, NULL, NULL, NULL, NULL, NULL,
|
||||||
|
NULL);
|
||||||
|
noise = noise_map[ptr->y * nx + ptr->x];
|
||||||
|
if (tot1 > noise && t2max > 2 * noise &&
|
||||||
|
tot3 > 3 * noise) {
|
||||||
;
|
;
|
||||||
} else
|
} else
|
||||||
good=0;
|
good = 0;
|
||||||
} else{
|
} else {
|
||||||
printf("Bad pixel number %d %d\n",ptr->x,ptr->y);
|
printf("Bad pixel number %d %d\n", ptr->x, ptr->y);
|
||||||
good=0;
|
good = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (good) {
|
if (good) {
|
||||||
@ -124,7 +124,6 @@ int read_clusters_with_cut(FILE *fp, int64_t n_clusters, Cluster *buf, int *n_le
|
|||||||
}
|
}
|
||||||
if (nph_read >= n_clusters)
|
if (nph_read >= n_clusters)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,17 +131,11 @@ int read_clusters_with_cut(FILE *fp, int64_t n_clusters, Cluster *buf, int *n_le
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//printf("%d\n",nph_read);
|
// printf("%d\n",nph_read);
|
||||||
assert(nph_read <= n_clusters); // sanity check in debug mode
|
assert(nph_read <= n_clusters); // sanity check in debug mode
|
||||||
return nph_read;
|
return nph_read;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int analyze_clusters(int64_t n_clusters, Cluster *cin, ClusterAnalysis *cout) {
|
int analyze_clusters(int64_t n_clusters, Cluster *cin, ClusterAnalysis *cout) {
|
||||||
|
|
||||||
int32_t tot2[4], t2max;
|
int32_t tot2[4], t2max;
|
||||||
@ -150,8 +143,8 @@ int analyze_clusters(int64_t n_clusters, Cluster *cin, ClusterAnalysis *cout) {
|
|||||||
int32_t val, tot3;
|
int32_t val, tot3;
|
||||||
for (int ic = 0; ic < n_clusters; ic++) {
|
for (int ic = 0; ic < n_clusters; ic++) {
|
||||||
|
|
||||||
|
analyze_cluster(*(cin + ic), &t2max, &tot3, &quad, NULL, NULL, NULL,
|
||||||
analyze_cluster(*(cin+ic), &t2max, &tot3, &quad, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
|
NULL, NULL, NULL, NULL, NULL);
|
||||||
|
|
||||||
(cout + ic)->c = quad;
|
(cout + ic)->c = quad;
|
||||||
(cout + ic)->tot2 = t2max;
|
(cout + ic)->tot2 = t2max;
|
||||||
@ -162,12 +155,12 @@ int analyze_clusters(int64_t n_clusters, Cluster *cin, ClusterAnalysis *cout) {
|
|||||||
return n_clusters;
|
return n_clusters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int analyze_cluster(Cluster cin, int32_t *t2, int32_t *t3, char *quad,
|
||||||
|
double *eta2x, double *eta2y, double *eta3x, double *eta3y,
|
||||||
|
double *eta2Lx, double *eta2Ly, double *eta3Xx,
|
||||||
|
double *eta3Xy) {
|
||||||
|
|
||||||
|
int ok = 1;
|
||||||
int analyze_cluster(Cluster cin, int32_t *t2, int32_t *t3, char *quad, double *eta2x, double *eta2y, double *eta3x, double *eta3y, double *eta2Lx, double *eta2Ly, double *eta3Xx, double *eta3Xy) {
|
|
||||||
|
|
||||||
|
|
||||||
int ok=1;
|
|
||||||
|
|
||||||
int32_t tot2[4], t2max;
|
int32_t tot2[4], t2max;
|
||||||
char c;
|
char c;
|
||||||
@ -192,8 +185,6 @@ int analyze_cluster(Cluster cin, int32_t *t2, int32_t *t3, char *quad, double *e
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (t2 || quad) {
|
if (t2 || quad) {
|
||||||
t2max = tot2[0];
|
t2max = tot2[0];
|
||||||
c = cBottomLeft;
|
c = cBottomLeft;
|
||||||
@ -211,11 +202,5 @@ int analyze_cluster(Cluster cin, int32_t *t2, int32_t *t3, char *quad, double *e
|
|||||||
if (t3)
|
if (t3)
|
||||||
*t3 = tot3;
|
*t3 = tot3;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,8 @@
|
|||||||
#include "RawFileReader.h"
|
#include "RawFileReader.h"
|
||||||
|
|
||||||
#include "arr_desc.h"
|
#include "arr_desc.h"
|
||||||
#include "data_types.h"
|
|
||||||
#include "cluster_reader.h"
|
#include "cluster_reader.h"
|
||||||
|
#include "data_types.h"
|
||||||
|
|
||||||
static PyObject *clusterize(PyObject *Py_UNUSED(self), PyObject *args) {
|
static PyObject *clusterize(PyObject *Py_UNUSED(self), PyObject *args) {
|
||||||
|
|
||||||
@ -56,13 +56,14 @@ static PyObject *clusterize(PyObject *Py_UNUSED(self), PyObject *args) {
|
|||||||
static PyObject *get_cluster_dt(PyObject *Py_UNUSED(self), PyObject *args) {
|
static PyObject *get_cluster_dt(PyObject *Py_UNUSED(self), PyObject *args) {
|
||||||
if (!PyArg_ParseTuple(args, ""))
|
if (!PyArg_ParseTuple(args, ""))
|
||||||
return NULL;
|
return NULL;
|
||||||
return (PyObject*)cluster_dt();
|
return (PyObject *)cluster_dt();
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *get_frame_header_dt(PyObject *Py_UNUSED(self), PyObject *args) {
|
static PyObject *get_frame_header_dt(PyObject *Py_UNUSED(self),
|
||||||
|
PyObject *args) {
|
||||||
if (!PyArg_ParseTuple(args, ""))
|
if (!PyArg_ParseTuple(args, ""))
|
||||||
return NULL;
|
return NULL;
|
||||||
return (PyObject*)frame_header_dt();
|
return (PyObject *)frame_header_dt();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Module docstring, shown as a part of help(creader)
|
// Module docstring, shown as a part of help(creader)
|
||||||
|
Reference in New Issue
Block a user