Analysis Software
Documentation for sPHENIX simulation 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  idx++;
89  if (idx >=1024) idx=0;
90  }
91 
92  // the adc samples
93  for ( c = 0; c < 8; c++)
94  {
95  idx = cell;
96  for ( i = 0; i < 1024; i++)
97  {
98  current_wave[i][chip*8+c] = p->iValue(i,chip*8+c) - base[idx][chip*9+c];
99  idx++;
100  if (idx >=1024) idx=0;
101  }
102  }
103 
104  // Trigger cells;
105  {
106  idx = cell;
107  for ( i = 0; i < 1024; i++)
108  {
109  current_wave[i][32+chip] = p->iValue(i,32+chip) - base[idx][chip*9+8];
110  idx++;
111  if (idx >=1024) idx=0;
112  }
113  }
114  }
115  return 0;
116 }
117 
118 float caen_correction::caen_corrected(const int sample, const int channel) const
119 {
120  //if ( sample < 0 || sample >1023 || channel < 0 || channel > 31) return 0;
121  if ( sample < 0 || sample >1023 || channel < 0 || channel > 35) return 0;
122  return current_wave[sample][channel];
123 }
124 
125 float caen_correction::caen_time(const int sample, const int channel) const
126 {
127  //if ( sample < 0 || sample >1023 || channel < 0 || channel > 31) return 0;
128  //return current_time[sample][channel/8];
129  if ( sample < 0 || sample >1023 || channel < 0 || channel > 35) return 0;
130  return current_time[sample][channel < 32 ? channel/8 : channel-32];
131 }