diff options
Diffstat (limited to 'src/zdab_utils.c')
-rw-r--r-- | src/zdab_utils.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/zdab_utils.c b/src/zdab_utils.c index dd377b9..37d444c 100644 --- a/src/zdab_utils.c +++ b/src/zdab_utils.c @@ -20,6 +20,87 @@ #include "pack2b.h" #include <stdlib.h> /* for size_t */ #include <stdio.h> /* for fprintf() */ +#include "event.h" +#include "zebra.h" + +size_t get_nhit(event *ev) +{ + /* Returns the number of PMT hits in event `ev`. + * + * Note: Only hits on normal PMTs which aren't flagged are counted. */ + size_t i, nhit; + + nhit = 0; + for (i = 0; i < MAX_PMTS; i++) { + if (ev->pmt_hits[i].flags || pmts[i].pmt_type != PMT_NORMAL) continue; + + if (!ev->pmt_hits[i].hit) continue; + + nhit++; + } + + return nhit; +} + +int get_event(zebraFile *f, event *ev, zebraBank *bev) +{ + /* Read all the PMT banks from the zebra file and update `ev`. + * + * Returns 0 on success, -1 on error. */ + int i, rv; + PMTBank bpmt; + zebraBank b; + int id, crate, card, channel; + + for (i = 0; i < MAX_PMTS; i++) { + ev->pmt_hits[i].hit = 0; + } + + if (bev->links[KEV_PMT-1] == 0) { + /* If the PMT link is zero, we assume it's just a 0 nhit event. */ + return 0; + } + + rv = zebra_get_bank(f,&b,bev->links[KEV_PMT-1]); + + if (rv) { + fprintf(stderr, "error getting PMT bank: %s\n", zebra_err); + return -1; + } + + while (1) { + unpack_pmt(b.data, &bpmt); + card = bpmt.pin/1024; + crate = (bpmt.pin % 1024)/32; + channel = bpmt.pin % 32; + id = crate*512 + card*32 + channel; + ev->pmt_hits[id].hit = 1; + ev->pmt_hits[id].t = bpmt.pt; + ev->pmt_hits[id].qihl = bpmt.pihl; + ev->pmt_hits[id].qihs = bpmt.pihs; + ev->pmt_hits[id].qilx = bpmt.pilx; + ev->pmt_hits[id].qhl = bpmt.phl; + ev->pmt_hits[id].qhs = bpmt.phs; + ev->pmt_hits[id].qlx = bpmt.plx; + /* Clear the PMT_FLAG_DIS bit. */ + ev->pmt_hits[id].flags &= ~PMT_FLAG_DIS; + if (bpmt.pf & KPF_DIS) + ev->pmt_hits[id].flags |= PMT_FLAG_DIS; + + if (!b.next) break; + + rv = zebra_get_bank(f,&b,b.next); + + if (rv) { + fprintf(stderr, "error getting PMT bank: %s\n", zebra_err); + return -1; + } + } + + ev->nhit = get_nhit(ev); + + return 0; +} int isOrphan(aPmtEventRecord *pmtRecord) { |