1 #define _FILE_OFFSET_BITS 64
16 #include "../analyzer/compress/mucap_compress.h"
22 #define PRINT_SAMPLES 1
25 void process_file(
char *input_filename,
int addr,
int fadc);
31 int event_size, size_read;
34 size_read = fread(pevent, 1,
sizeof(EVENT_HEADER), fp);
35 if (size_read !=
sizeof(EVENT_HEADER))
38 header = (EVENT_HEADER *) pevent;
39 printf(
"block# %d\n", header->serial_number);
41 if (event_number == 0 && header->trigger_mask != MIDAS_MAGIC) {
42 fprintf(stderr,
"Input is not a valid MIDAS file\n");
46 event_size = header->data_size;
48 if ((
unsigned int) event_size >= MAX_EVENT_SIZE -
sizeof(EVENT_HEADER)) {
49 fprintf(stderr,
"Invalid event size %d\n", event_size);
53 size_read = fread(pevent +
sizeof(EVENT_HEADER), 1, event_size, fp);
54 if (size_read != event_size)
60 void process_file(
char *input_filename,
int addr,
int fadc)
70 cm_connect_experiment(host_name, exp_name,
"show_pulses", NULL);
71 cm_get_experiment_database(&
hDB, NULL);
75 input_fp = fopen(input_filename,
"rb");
77 fprintf(stderr,
"Unable to open %s: ", input_filename);
83 input_event = (
char *) malloc(MAX_EVENT_SIZE*2);
89 EVENT_HEADER *header = (EVENT_HEADER *) input_event;
91 if(header->event_id == 1) {
98 printf(
"event_number %d\n", event_number);
109 sprintf(title,
"Waveform: channel %d, t0=%d", channel, t0);
115 double binWidth = 100./100.00;
116 TH1D *waveform =
new TH1D(
"waveform", title, nsamples, -0.5*binWidth, (nsamples-0.5)*binWidth);
118 waveform->SetBinContent(
i+1, samples[
i]);
121 if(samples[i] < min) min = samples[
i];
122 if(samples[i] > max) max = samples[
i];
127 double sumSqrDeviations = 0;
130 double deviation = samples[
i] - mean;
131 sumSqrDeviations += deviation*deviation;
133 double rms = sqrt(sumSqrDeviations/(nsamples-1));
135 printf(
"Number of samples = %d, Min = %d, Max = %d, Mean = %lf, RMS = %lf\n", nsamples, min, max, mean, rms);
142 fgets(dummy,
sizeof(dummy), stdin);
143 if(dummy[0] ==
'q') {
156 for(
int i = 0;
i < 8;
i++) {
158 if(
i != fadc && fadc >= 0)
continue;
162 sprintf(name,
"N%c%02x",
'a' +
i, addr);
164 int bank_size = bk_locate(pevent, name, &raw);
165 printf(
"bank_size %d,", bank_size);
166 bank_size = bank_size / 10;
167 printf(
" npkt %d\n", bank_size);
170 printf(
"-------------------------------------------------------------------------------\n");
173 int islandSamples[8192];
174 int islandNsamples = 0;
176 bool firstIsland =
true;
179 int lastTimestamp = 0;
180 for(
int j = 0; j < bank_size; j++) {
192 int timestamp = (raw[j*10+0] << 20) |
193 (raw[j*10+1] << 12) |
196 bool overflowB0 = ((raw[j*10+3] & 0x08) != 0);
197 bool overflowA0 = ((raw[j*10+3] & 0x04) != 0);
198 bool overflowB1 = ((raw[j*10+3] & 0x02) != 0);
199 bool overflowA1 = ((raw[j*10+3] & 0x01) != 0);
200 int sampleB0 = (overflowB0 << 12) |
203 int sampleA0 = (overflowA0 << 12) |
204 ((raw[j*10+5] & 0xf) << 8) |
206 int sampleB1 = (overflowB1 << 12) |
209 int sampleA1 = (overflowA1 << 12) |
210 ((raw[j*10+8] & 0xf) << 8) |
213 if(timestamp < lastTimestamp) {
214 printf(
"Time ordering error!\n");
217 if(timestamp != lastTimestamp + 1) {
219 int stop =
processIsland(islandT0*2, islandNsamples, islandSamples,
i);
228 islandT0 = timestamp;
232 lastTimestamp = timestamp;
235 printf(
"fadc=%d t=%d %d %d %d %d\n",
i, timestamp,
236 sampleA1, sampleB1, sampleA0,sampleB0);
239 islandSamples[islandNsamples++] = sampleA1;
240 islandSamples[islandNsamples++] = sampleB1;
241 islandSamples[islandNsamples++] = sampleA0;
242 islandSamples[islandNsamples++] = sampleB0;
245 if(islandNsamples != 0) {
246 int stop =
processIsland(islandT0*2, islandNsamples, islandSamples,
i);