ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
caen_correction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file caen_correction.cc
1 #include <iostream>
2 #include <iomanip>
3 #include <fstream>
4 
5 #include "caen_correction.h"
6 #include "packet.h"
7 
8 using namespace std;
9 
10 caen_correction::caen_correction ( const char *calibdata)
11 {
12 
13  int nsample[9];
14 
15  _broken = 0;
16 
17  int index;
18  ifstream IN;
19 
20  int adccorr[9];
21  float timecorr;
22 
23  IN.open(calibdata,ios_base::in);
24 
25  int chip;
26  int i;
27  if ( ! IN.is_open())
28  {
29  _broken = 1;
30  }
31  else
32  {
33  for ( chip = 0; chip < 4; chip++)
34  {
35  for ( i = 0; i < 1024; i++)
36  {
37  IN >> index
38  >> adccorr[0]
39  >> adccorr[1]
40  >> adccorr[2]
41  >> adccorr[3]
42  >> adccorr[4]
43  >> adccorr[5]
44  >> adccorr[6]
45  >> adccorr[7]
46  >> adccorr[8]
47  >> timecorr
48  >> nsample[0]
49  >> nsample[1]
50  >> nsample[2]
51  >> nsample[3]
52  >> nsample[4]
53  >> nsample[5]
54  >> nsample[6]
55  >> nsample[7]
56  >> nsample[8];
57 
58  base [index][chip*9 + 0] = adccorr[0];
59  base [index][chip*9 + 1]= adccorr[1];
60  base [index][chip*9 + 2]= adccorr[2];
61  base [index][chip*9 + 3]= adccorr[3];
62  base [index][chip*9 + 4]= adccorr[4];
63  base [index][chip*9 + 5]= adccorr[5];
64  base [index][chip*9 + 6]= adccorr[6];
65  base [index][chip*9 + 7]= adccorr[7];
66  base [index][chip*9 + 8]= adccorr[8];
67  timevec[index][chip] = timecorr;
68  }
69  }
70  IN.close();
71  }
72 }
73 
75 {
76  int chip,c,i,idx;
77 
78  for ( chip = 0; chip < 4; chip++)
79  {
80 
81  int cell = p->iValue(chip,"INDEXCELL");
82 
83  //correct time for each chip
84  idx = cell;
85  for ( i = 0; i < 1024; i++)
86  {
87  current_time[i][chip] = timevec[idx][chip];
88  if (idx >=1024) idx=0;
89  }
90 
91  // the adc samples
92  for ( c = 0; c < 8; c++)
93  {
94  idx = cell;
95  for ( i = 0; i < 1024; i++)
96  {
97  current_wave[i][chip*8+c] = p->iValue(i,chip*8+c) - base[idx][chip*9+c];
98  idx++;
99  if (idx >=1024) idx=0;
100  }
101  }
102 
103  // // the TR cells
104  // idx = cell;
105  //for ( i = 0; i < 1024; i++)
106  // {
107  // if (chip < 2) current_wave[i][chip*8+8] = p->iValue(i,"TR0") - base[idx][chip*9+8];
108  // else current_wave[i][chip*9+8] = p->iValue(i,"TR1") - base[idx][chip*9+8];
109  // idx++;
110  // if (idx >=1024) idx=0;
111  // }
112  }
113  return 0;
114 }
115 
116 float caen_correction::caen_corrected(const int sample, const int channel) const
117 {
118  if ( sample < 0 || sample >1023 || channel < 0 || channel > 31) return 0;
119  return current_wave[sample][channel];
120 }
121 
122 float caen_correction::caen_time(const int sample, const int channel) const
123 {
124  if ( sample < 0 || sample >1023 || channel < 0 || channel > 31) return 0;
125  return current_wave[sample][channel/8];
126 }