1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
#ifndef ZDAB_UTILS
#define ZDAB_UTILS
#include "Record_Info.h"
#include <stdint.h>
#include <stdlib.h> /* for size_t */
// the builder won't put out events with NHIT > 10000
// (note that these are possible due to hardware problems)
// but XSNOED can write an event with up to 10240 channels
#define MAX_NHIT 10240
#ifdef SWAP_BYTES
#define SWAP_INT32(a,b) swap_int32((int32_t *)(a),(b))
#define SWAP_INT16(a,b) swap_int16((int16_t *)(a),(b))
#else
#define SWAP_INT32(a,b)
#define SWAP_INT16(a,b)
#endif
/* Bit masks for the PMT flags field in the PMT bank. */
#define KPF_DIS 0x00000001
#define KPF_NOI 0x00000004
#define KPF_PRP 0x00000008
#define KPF_AFP 0x00000010
#define KPF_FECD 0x00000020
#define KPF_FT_MASK1 0x00000040
#define KPF_XT 0x04000000
#define KPF_NO_CAL 0x08000000
#define KPF_BAD_CAL 0x10000000
typedef struct EVBank {
/* Run number. */
uint32_t run;
/* Event number. */
uint32_t evn;
/* Data type. */
uint32_t dtp;
/* Julian date. */
uint32_t jdy;
/* Universal time (seconds). */
uint32_t ut1;
/* Universal time (nanoseconds). */
uint32_t ut2;
/* Date (format: yyyymmdd) */
uint32_t dte;
/* Time (format: hhmmsscc - cc is centisec). */
uint32_t hmsc;
/* Global trigger time in nsec (first word). */
uint32_t gtr1;
/* Second word. */
uint32_t gtr2;
/* Number of PMTs that fired. */
uint32_t npm;
/* Integrated charge in the event. */
uint32_t nph;
/* Sub-run number, or -1 if unknown. Only defined for run number >= 10614. */
uint32_t sub_run;
/* Packed word. */
uint32_t mc_pck;
/* ZDAB input/output record type, e.g. PMT, NCD, CMA, RUN, etc. */
uint32_t rec;
/* ZDAB_PMT format number (x10). */
uint32_t vpck;
/* Global trigger ID. */
uint32_t gtr_id;
/* Trigger word. */
uint32_t trg_type;
/* Digitized peak of analog sum. */
uint32_t peak;
/* Analog sum derivative. */
uint32_t diff;
/* Digitized integral of analog sum. */
uint32_t integral;
/* Trigger error bits plus spares. */
uint32_t err;
/* Data splitter blindness word. */
uint32_t data_set;
uint32_t spare1[3];
uint32_t ncd_status;
/* Number of multiplexer global records. */
uint32_t num_muxg;
/* Number of multiplexer records. */
uint32_t num_mux;
/* Number of scope records. */
uint32_t num_scope;
uint32_t spare2[5];
/* Upper 24 bits of flock */
uint32_t ncd_clk_up;
/* Lower clock register (32 bits). */
uint32_t ncd_clk_lw;
/* Latch register id. */
uint32_t ncd_reg;
/* GTID. */
uint32_t ncd_gtid;
/* Sync clear error. */
uint32_t ncd_sync;
uint32_t spare3[10];
} EVBank;
/* PMT Bank struct. This is a struct which mimics the PMT data bank in SNOMAN.
* The fields and comments were taken from the SNOMAN companion. */
typedef struct PMTBank {
/* Tube number. For FECD, which has no associated tube number, this word is
* a copy of PIN. */
uint32_t pn;
/* Set of 1-bit flags. All undefined bits are set to zero. The following
* bits are defined:
*
* 0 KPF_DIS Discard hit for all processing including fitting.
* 2 KPF_NOI Noise.
* 3 KPF_PRP Pre-pulse.
* 4 KPF_AFP After-pulse.
* 5 KPF_FECD Front-End Card Data i.e. non-PMT channel.
* Should only be set on the FECD bank.
* 6 KPF_FT_MASK+i Discarded by fitter method i (i = 1,2,..).
* For description of fitter methods see the FTx bank.
* 26 KPF_XT Crosstalk.
* 27 KPF_NO_CAL No calibration.
* 28 KPF_BAD_CAL Bad calibration. */
uint32_t pf;
/* Time in nano-secs relative to event T0 - see EV. */
float pt;
/* Integrated charge. */
float phl;
/* Short-time integrated charge. */
float phs;
/* Low-gain integrated charge. */
float plx;
/* Time with the PMT jitter removed. */
float pt0;
/* Set of n-bit flags for the ith hit in list. All undefined bits are set
* to zero. The following bits are defined:
*
* Bit Field DAQ Meaning
* 0-3 NCELL (CMOS Cell address 0 to 15)
* 4-5 FLAG1 Bit 4 = CGT ES16.
* Bit 5 = CGT ES24.
* 6-9 FLAG2 Bit 6 = Missed Count
* Bit 7 = NC/CC Flag
* Bit 8 = LGISELECT (1=long sample)
* Bit 9 = CMOS ES16. */
uint32_t pif;
/* Uncalibrated times. */
float pit;
/* Uncalibrated high-gain, long int. charge. */
float pihl;
/* Uncalibrated high-gain, short int. charge. */
float pihs;
/* Uncalibrated log-gain, long int. charge. */
float pilx;
/* Uncalibrated unjittered time. */
float pit0;
/* PMT channel cell number. */
uint32_t cell;
/* CCC DAQ Circuit Number
* = 1024*card + 32*crate + channel.
* Before uncalibration it holds the tube no. */
uint32_t pin;
/* TSLH of PMT. */
uint32_t tslh;
/* HCA information. */
uint32_t hca;
/* ECA validation status word. */
uint32_t eca_val;
/* PCA validation status word. */
uint32_t pca_val;
/* ANXX validation status word. */
uint32_t anxx;
/* ECA calibrated time (nsec). */
uint32_t ept;
/* ECA calibrated QHL (pedestal subtracted). */
uint32_t ehl;
/* ECA calibrated QHS (pedestal subtracted). */
uint32_t ehs;
/* ECA calibrated QLX (pedestal subtracted). */
uint32_t elx;
/* Non-walk corrected PMT time. */
uint32_t pt1;
/* Multiphoton PCA time. */
uint32_t ptm;
/* Multiphoton PCA PMT transit time RMS. */
uint32_t ptms;
/* Best charge (either QHS or QLX). */
uint32_t qm;
/* Best charge status word. */
uint32_t qms;
/* Charge correction for rate-dependent shifting. */
uint32_t qrc;
} PMTBank;
void unpack_ev(uint32_t *data, EVBank *b);
void unpack_pmt(uint32_t *data, PMTBank *b);
int isOrphan(aPmtEventRecord *pmtRecord);
void swap_int32(int32_t *val_pt, int count);
void swap_int16(int16_t *val_pt, int count);
int swap_PmtRecord(aPmtEventRecord *aPmtRecord, size_t size);
void swap_TrigRecord(struct TriggerInfo *aTrigRecord);
void swap_RunRecord(struct RunRecord *aRunRecord);
#endif
|