9 #include "ERDRS4Source.h" 11 #include "ERNeuRadRawEvent.h" 16 ERDRS4Source::ERDRS4Source():
25 ERDRS4Source::~ERDRS4Source(){
29 Bool_t ERDRS4Source::Init(){
30 std::cerr <<
"Init" << std::endl;
31 f = fopen(fPath.Data(),
"r");
33 printf(
"Cannot find file \'%s\'\n", fPath.Data());
39 FairRootManager* ioman = FairRootManager::Instance();
40 for (Int_t iChanel = 0; iChanel < fNChanels; iChanel++){
43 bName.Form(
"ch%d.",iChanel+1);
44 ioman->Register(bName,
"DSR4", fRawEvents[iChanel], kTRUE);
47 strcpy(filename, fPath.Data());
52 Int_t ERDRS4Source::ReadHeader()
57 nReadElements = fread(&fh,
sizeof(fh), 1, f);
58 if (fh.tag[0] !=
'D' || fh.tag[1] !=
'R' || fh.tag[2] !=
'S') {
59 printf(
"Found invalid file header in file \'%s\', aborting.\n", filename);
63 if (fh.version !=
'2') {
64 printf(
"Found invalid file version \'%c\' in file \'%s\', should be \'2\', aborting.\n", fh.version, filename);
69 nReadElements = fread(&th,
sizeof(th), 1, f);
70 if (memcmp(th.time_header,
"TIME", 4) != 0) {
71 printf(
"Invalid time header in file \'%s\', aborting.\n", filename);
77 nReadElements = fread(&bh,
sizeof(bh), 1, f);
78 if (memcmp(bh.bn,
"B#", 2) != 0) {
80 fseek(f, -4, SEEK_CUR);
84 printf(
"Found data for board #%d\n", bh.board_serial_number);
87 memset(bin_width[b],
sizeof(bin_width[0]), 0);
88 for (chn=0 ; chn<5 ; chn++) {
89 nReadElements = fread(&ch,
sizeof(ch), 1, f);
92 fseek(f, -4, SEEK_CUR);
95 i = ch.cn[2] -
'0' - 1;
96 printf(
"Found timing calibration for channel #%d\n", i+1);
97 nReadElements = fread(&bin_width[b][i][0],
sizeof(
float), 1024, f);
101 if (bin_width[b][i][1023] > 10 || bin_width[b][i][1023] < 0.01) {
102 for (j=0 ; j<512 ; j++)
103 bin_width[b][i][j+512] = bin_width[b][i][j];
116 Int_t ERDRS4Source::ReadEvent(UInt_t
id)
118 size_t nReadElements;
122 i = (int)fread(&eh,
sizeof(eh), 1, f);
126 if ( !(eh.event_serial_number%100) ) {
127 printf(
"Found event #%d\n", eh.event_serial_number);
131 for (b=0 ; b<n_boards ; b++) {
134 nReadElements = fread(&bh,
sizeof(bh), 1, f);
135 if (memcmp(bh.bn,
"B#", 2) != 0) {
136 printf(
"Invalid board header in file \'%s\', aborting.\n", filename);
141 nReadElements = fread(&tch,
sizeof(tch), 1, f);
142 if (memcmp(tch.tc,
"T#", 2) != 0) {
143 printf(
"Invalid trigger cell header in file \'%s\', aborting.\n", filename);
148 printf(
"Found data for board #%d\n", bh.board_serial_number);
151 for (chn=0 ; chn<4 ; chn++) {
154 nReadElements = fread(&ch,
sizeof(ch), 1, f);
155 if (ch.c[0] !=
'C') {
157 fseek(f, -4, SEEK_CUR);
160 chn_index = ch.cn[2] -
'0' - 1;
162 nReadElements = fread(&scaler,
sizeof(
int), 1, f);
163 nReadElements = fread(voltage,
sizeof(
short), 1024, f);
165 for (i=0 ; i<1024 ; i++) {
167 waveform[b][chn_index][i] = (voltage[i] / 65536. + eh.range/1000.0 - 0.5);
174 fRawEvents[chn_index]->SetAmp(waveform[b][chn_index][i], i);
178 for (j=0,time[b][chn_index][i]=0 ; j<i ; j++){
179 time[b][chn_index][i] += bin_width[b][chn_index][(j+tch.trigger_cell) % 1024];
185 t1 = time[b][0][(1024-tch.trigger_cell) % 1024];
189 for (chn=1 ; chn<4 ; chn++) {
190 t2 = time[b][chn][(1024-tch.trigger_cell) % 1024];
192 t3 = time[b][chn][(1024-tch.trigger_cell) % 1024];
193 t4 = time[b][chn][(1024-tch.trigger_cell) % 1024];
198 for (i=0 ; i<1024 ; i++) {
199 time[b][chn][i] += dt;
207 t1 = t2 = t3 = t4 = 0;
212 for(i=0 ; i<1024 ; i++) {
213 for (Int_t chNum = 0; chNum < 4; chNum++) { fRawEvents[chNum]->SetTime(time[b][chNum][i],i); }
217 for (i=0 ; i<1022 ; i++) {
219 if (waveform[b][0][i] < threshold && waveform[b][0][i+1] >= threshold) {
220 t1 = (threshold-waveform[b][0][i])/(waveform[b][0][i+1]-waveform[b][0][i])*(time[b][0][i+1]-time[b][0][i])+time[b][0][i];
229 for (i=0 ; i<1022 ; i++) {
230 if (waveform[b][1][i] < threshold && waveform[b][1][i+1] >= threshold) {
231 t2 = (threshold-waveform[b][1][i])/(waveform[b][1][i+1]-waveform[b][1][i])*(time[b][1][i+1]-time[b][1][i])+time[b][1][i];
239 if (t1 > 0 && t2 > 0) {
249 void ERDRS4Source::Close(){
251 printf(
"dT = %1.3lfns +- %1.1lfps\n", sumdt/ndt, 1000*sqrt(1.0/(ndt-1)*(sumdt2-1.0/ndt*sumdt*sumdt)));
254 void ERDRS4Source::Reset(){
255 for (Int_t iChanel = 0; iChanel < fNChanels; iChanel++)
257 fRawEvents[iChanel]->Reset();
class for raw data obtained from measurements or simulations
task for reading raw data from binary files