FairRoot/PandaRoot
ReadMainzProto60v4.cxx
Go to the documentation of this file.
1 /**************************************
2 
3  chammann@hiskp.uni-bonn.de
4  code to parse data files taken from
5  peter.drexler@exp2.physik.uni-giessen.de
6 
7  **************************************/
8 
9 #ifdef GNUPRAGMA
10 #pragma interface
11 #endif
12 
13 #include "ReadMainzProto60v4.h"
14 #include <stdlib.h>
15 #include <stdio.h>
16 #include "TNtuple.h"
17 
18 
19 // #include "NTECEvent.h"
20 
21 
23  for(int n=0;n<60;n++){
24  energies[n]=LG_CAL[n];
25  }
26 }
27 
29  for(int n=0;n<60;n++){
30  times[n]=TIME[n];
31  }
32 }
33 
35  for(int n=0; n<60;n++){
36  ADCs[n]=LG[n];
37  }
38 }
40  for(int n = 0; n<16;n++){
41  taggertimes[n]=TAGGER_CAL[n];
42  }
43 }
44 
46  taggerEnergies[0]=1441.06;
47  taggerEnergies[1]=1356.89;
48  taggerEnergies[2]=1257.31;
49  taggerEnergies[3]=1156.56;
50  taggerEnergies[4]=1057.70;
51  taggerEnergies[5]=956.16;
52  taggerEnergies[6]=857.98;
53  taggerEnergies[7]=756.58;
54  taggerEnergies[8]=657.34;
55  taggerEnergies[9]=556.97;
56  taggerEnergies[10]=456.26;
57  taggerEnergies[11]=355.88;
58  taggerEnergies[12]=256.41;
59  taggerEnergies[13]=158.31;
60  taggerEnergies[14]=0.0;
61  taggerEnergies[15]=187.99;
62 
63 }
64 
66  FILE * fin;
67 // char infilename[100];
68  char instr[100];
69  int ch;
70  double ped, sigped, thr, mu, gmev, fr_mev, thr_mev;
71 
72 // sprintf(infilename, "%s.thr_mev", filename);
73  printf("filename read in: %s\n", filename);
74 
75  fin = fopen(filename, "rt");
76  if(fin==NULL){
77  printf("No file \"%s\" found!\n", filename);
78  for(int n=0; n<60; n++){
79  lg_factor[n]=lg_ped[n]=0;
80  }
81  }
82  else{
83  fgets(instr, 100, fin); // root filename
84  printf("filename read in: %s\n", instr);
85  fgets(instr, 100, fin); // Ch Ped Sigped Thr Mu GMeV FR_MeV Thr_MeV
86  printf("header read in: %s\n", instr);
87  for(int i = 0; i < 60; i++){
88  fgets(instr, 100, fin); // values
89  if(strlen(instr)<2) fgets(instr, 100, fin); // empty line
90 
91  sscanf(instr, "%i%lf%lf%lf%lf%lf%lf%lf",
92  &ch, &ped, &sigped, &thr, &mu, &gmev, &fr_mev, &thr_mev);
93  printf("line %i: %s -> ch: %i, factor: %f, ped: %f\n",
94  i, instr, ch, gmev, ped);
95  if(i+1==ch){
96  lg_factor[i]=gmev;
97  lg_ped[i]=ped;
98  }
99  else{
100  printf("Wrong channel in %s detected!\n", filename);
101  exit(0);
102  }
103  }
104  }
105 }
106 
107 
109  printf("Printing Event Number %li\n",NumberOfEvents);
110  printf("ADCValues:\n");
111  for(Int_t row=0;row<6;row++){
112  for(Int_t col=0;col<10;col++){
113  printf("% 8.3f ",LG[row*10+col]);
114  }
115  printf("\n");
116  }
117 
118  printf("Energies:\n");
119  for(Int_t row=0;row<6;row++){
120  for(Int_t col=0;col<10;col++){
121  printf("% 8.3f ",LG_CAL[row*10+col]);
122  }
123  printf("\n");
124  }
125  printf("Times:\n");
126  for(Int_t row=0;row<6;row++){
127  for(Int_t col=0;col<10;col++){
128  printf("% 8.3f ",TIME_CAL[row*10+col]);
129  }
130  printf("\n");
131  }
132 
133  printf("TaggerTimes:\n");
134  for(Int_t row=0;row<2;row++){
135  for(Int_t col=0;col<8;col++){
136  printf("% 8.3f ",TAGGER_CAL[row*8+col]);
137  }
138  printf("\n");
139  }
140  printf("TaggerEnergies:\n");
141  Double_t tagger_energies[16];
142  GetTaggerEnergies(tagger_energies);
143  for(Int_t row=0;row<2;row++){
144  for(Int_t col=0;col<8;col++){
145  printf("% 8.3f ",tagger_energies[row*8+col]);
146  }
147  printf("\n");
148  }
149 
150 }
151 
152 
154  IsInit=kFALSE;
155  printf("do datafile given, nothing to do\n");
156 }
157 
158 ReadMainzProto60v4::ReadMainzProto60v4(const char *datafilename, const char *calibrationfilename){
159  IsInit=kFALSE;
160  ctime_factor=0.180;
161  RANGE=3860;
162  BINS=3860;
163  CAL_RANGE=1000;
164  CAL_BINS=4000;
165  central=34;
166  strcpy(versionsstr,"data_all_4.1.3");
167  NumberOfEvents=0;
168  ResetToFirstEvent=kFALSE;
169 
170  //unsigned int rv; //[R.K. 01/2017] unused variable?
171  //unsigned int noe=0; //[R.K. 01/2017] unused variable?
172  //int how_often=1000; //[R.K. 01/2017] unused variable?
173 
174  //int tagged_crystal=35; //[R.K. 01/2017] unused variable?
175  in = fopen(datafilename, "rb");
176  if(in==NULL){
177  printf("can't read datafile %s !!!\n", datafilename);
178  return;
179  }
180  read_energy_factor(calibrationfilename);
181 
182  IsInit=kTRUE;
183 }
184 
186  fclose(in);
187 }
188 
190  if(read_one_event()!=0){
191  NumberOfEvents++;
192  convert_60();
193  calibrate_60();
194  return NumberOfEvents;
195  } else {
196  return -1;
197  }
198 }
199 
201  Long_t RetVal = 0;
202  Reset();
203  while(ReadNextEvent()!=-1);
204  RetVal = NumberOfEvents;
205  Reset();
206  return RetVal;
207 }
208 
210  NumberOfEvents = 0;
211  ResetToFirstEvent = kTRUE;
212 }
213 
215  for(int n=0; n<60; n++){
216  TIME_CAL[n] = ((TIME[n]) * ctime_factor);
217  LG_CAL[n] = (((LG[n])-lg_ped[n]) * lg_factor[n]);
218  }
219  for(int n=0; n<16; n++){
220  TAGGER_CAL[n] = ((TAGGER[n]) * ctime_factor);
221  }
222  TP_CAL = ((TP) * ctime_factor);
223  MU_CAL = ((MU) * ctime_factor);
224  VETO_CAL = ((VETO) * ctime_factor);
225 }
226 
228  for(int n=0; n<32; n++){
229  TIME[n] = rawdata[n][0];
230  }
231  for(int n=32; n<60; n++){
232  TIME[n] = rawdata[n-32][1];
233  }
234  for(int n=0; n<16; n++){
235  LG[n] = rawdata[n][2];
236  }
237  for(int n=16; n<32; n++){
238  LG[n] = rawdata[n-16][3];
239  }
240  for(int n=32; n<48; n++){
241  LG[n] = rawdata[n-32][4];
242  }
243  for(int n=48; n<60; n++){
244  LG[n] = rawdata[n-48][5];
245  }
246  for(int n=0; n<16; n++){
247  TAGGER[n] = rawdata[n][6];
248  }
249 
250  TIME[ central ] = rawdata[28][1]; // correct position for Proto60 Mainz
251  LG[ central ] = rawdata[12][5]; // correct position for Proto60 Mainz
252  TP = rawdata[31][1];
253  MU = rawdata[30][1];
254  VETO = rawdata[29][1];
255 
256 }
257 
259  static unsigned int dataword=0xffffffff; // current data word
260  static unsigned int events=0; // event counter
261  static unsigned int no_of_ev=0; // number of words in file
262  static char ververgl[100];
263 
264  // unsigned int rv; // return value
265  int wie_oft=200000; // how often status report
266  unsigned int dec_geo, dec_tow, dec_noch, dec_data, dec_ch; // decoded event informations
267  int n; // counting variables
268  int board_no;
269 
270  memset(noe_of_board, 0, sizeof(noe_of_board)); //
271  memset(rawdata, 0, sizeof(rawdata)); //
272 
273 
274  if(dataword==0xffffffff || ResetToFirstEvent){ // init readout
275  ResetToFirstEvent=kFALSE;
276  events=0;
277  fseek(in, 0, 2); //setze Zeiger auf Ende der Datei
278  no_of_ev=ftell(in)/4; // Dateilaenge/4 pro header, data word, trail
279  fseek(in, 0, 0); //setze Zeiger auf Anfang der Datei
280 
281  n=0;
282  do{
283  fread(&ververgl[n], 1, 1, in);
284  n++;
285  }while(ververgl[n-1]!=0);
286 
287  printf("The version of the readout was: %s (expected: %s)\n\n",
288  ververgl, versionsstr);
289  fread(&no_of_boards, sizeof(no_of_boards), 1, in);
290  printf("%i boards were read out.\n", no_of_boards);
291  fread(what, sizeof(what), 1, in);
292  fread(geos, sizeof(geos), 1, in);
293  for(n=0; n<no_of_boards; n++){
294  printf("Board no %i is a %i\n", n, what[n]);
295  geo_to_bnr[ geos[n] ]=n;
296  }
297 
298  }
299  for(board_no=0; board_no< no_of_boards; board_no++){
300  if(what[board_no]<80){
301  /* Header **********************/
302  if(0==fread((char*) &dataword, sizeof(dataword), 1, in)) return(0);
303  events++; if(events%wie_oft==0) printf("%i of %i read in (%3.0f%%)\n", events, no_of_ev, ((double) events)*100/ ((double)no_of_ev));
304  dec_tow=((dataword>>24) & 0x7); // decode type of dataword
305  if(dec_tow!=2){ // not a header
306  // do{
307  printf("H");
308  // fread((char*) &dataword, sizeof(dataword), 1, in);
309  // events++; if(events%wie_oft==0) printf("%i von %i read in (%3.0f%%)\n", events, no_of_[1]ev, ((double) events)*100/ ((double)no_of_ev));
310  // dec_tow=((dataword>>24) & 0x7);
311  // }while(dec_tow!=2); // repeat until first header
312  }
313  dec_geo = (dataword>>27); // decode board number
314  dec_noch = ((dataword>>8) & 0x3f); // decode no of events in board
315  /* Header **********************/
316 
317  /* Data Words **********************/
318  for(n=0; n< (int) dec_noch; n++){
319  if(0==fread((char*) &dataword, sizeof(dataword), 1, in)) return(0);
320  events++; if(events%wie_oft==0) printf("%i von %i read in (%3.0f%%)\n", events, no_of_ev, ((double) events)*100/ ((double)no_of_ev));
321  dec_tow=((dataword>>24) & 0x7); // decode type of dataword
322  dec_data = (dataword & 0xfff); // decode actual data
323  if((what[board_no]%10)==1){ // ch on board max 32
324  dec_ch =((dataword>>16) & 0x3f); // decode channel number
325  }
326  else if((what[board_no]%10)==0){ //ch on board max 16, N version of board
327  dec_ch =((dataword>>17) & 0x1f); // decode dataword
328  }
329  else printf("ERROR in WHAT!!!\n\n\n");
330  if(dec_tow==0 && (dec_geo==(dataword>>27))){ // tow and geo is ok
331  // rawdata[dec_ch][ geo_to_bnr[dec_geo] ] = dec_data;
332  if(what[board_no]==30 || what[board_no]==31) // tdc
333  if(((dataword>>14)&0x1)==0) dec_data=0; // valid data?
334  rawdata[dec_ch][ board_no ] = dec_data;
335  }
336  else printf("D");
337  }
338  /* Data Words **********************/
339 
340  /* Trail **********************/
341  if(0==fread((char*) &dataword, sizeof(dataword), 1, in)) return(0);
342  events++; if(events%wie_oft==0) printf("%i of %i read in (%3.0f%%)\n", events, no_of_ev, ((double) events)*100/ ((double)no_of_ev));
343  dec_tow=((dataword>>24) & 0x7); // decode type of word
344  if(dec_tow!=4) printf("T"); //if it wasn't trail
345  noe_of_board[geo_to_bnr[dec_geo] ] =((dataword) & 0xffffff); //
346 
347  /* Trail **********************/
348 
349  }
350  else if(what[board_no]==90){
351  for(n=0;n<7; n++){ // header, counter 1-4, direct data in, trail
352  if(0==fread((char*) &dataword, sizeof(dataword), 1, in)) return(0);
353  events++; if(events%wie_oft==0) printf("%i of %i read in (%3.0f%%)\n", events, no_of_ev, ((double) events)*100/ ((double)no_of_ev));
354  rawdata[n][ board_no ] = dec_data;
355  }
356  }
357  }
358  // rv=events; // of there is more data, return number of read in events
359  return 1;
360 } //read_one_event
int row
Definition: anaLmdDigi.C:67
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)
Int_t i
Definition: run_full.C:25
exit(0)
int col
Definition: anaLmdDigi.C:67
int n
unsigned int noe_of_board[16]
unsigned int geo_to_bnr[32]
void GetEnergies(Double_t *energies)
unsigned int rawdata[32][16]
Double_t
void GetTaggerEnergies(Double_t *taggerEnergies)
void GetTimes(Double_t *times)
unsigned int read_one_event()
void GetTaggerTimes(Double_t *taggertimes)
void read_energy_factor(const char *filename)
void GetADCValues(Double_t *ADCs)
const string filename