1 |
pamelats |
1.1 |
#include "Digitizer.h" |
2 |
|
|
|
3 |
pamelats |
1.3 |
void Digitizer::DigitizeAC() { |
4 |
pamelats |
1.1 |
// created: J. Conrad, KTH |
5 |
|
|
// modified: S. Orsi, INFN Roma2 |
6 |
|
|
// fDataAC[0-63]: main AC board |
7 |
|
|
// fDataAC[64-127]: extra AC board (identical to main board, for now) |
8 |
|
|
// We activate all branches. Once the digitization algorithm is determined |
9 |
|
|
// only the branches that involve needed information will be activated |
10 |
pamelats |
1.3 |
|
11 |
|
|
// Threshold: thr=0.8 MeV. |
12 |
|
|
Float_t thr = 8e-4; |
13 |
|
|
Int_t nReg=6,i; |
14 |
pamelats |
1.1 |
fDataAC[0] = 0xACAC; |
15 |
|
|
fDataAC[64]= 0xACAC; |
16 |
|
|
fDataAC[1] = 0xAC11; |
17 |
|
|
fDataAC[65] = 0xAC22; |
18 |
pamelats |
1.3 |
|
19 |
pamelats |
1.1 |
// the third word is a status word (dummy: "no errors are present in the AC boards") |
20 |
|
|
fDataAC[2] = 0xFFFF; //FFEF? |
21 |
|
|
fDataAC[66] = 0xFFFF; |
22 |
|
|
// FPGA Registers (dummy) |
23 |
pamelats |
1.3 |
for (i=0; i<=nReg; i++){ |
24 |
pamelats |
1.1 |
fDataAC[i+4] = 0xFFFF; |
25 |
|
|
fDataAC[i+68] = 0xFFFF; |
26 |
|
|
} |
27 |
|
|
|
28 |
|
|
// shift registers (moved to the end of the routine) |
29 |
|
|
|
30 |
|
|
Int_t evntLSB=(UShort_t)Ievnt; |
31 |
|
|
Int_t evntMSB=Ievnt >> 16; |
32 |
|
|
|
33 |
|
|
// singles counters are dummy |
34 |
pamelats |
1.3 |
for(i=0; i<=15; i++){ //SO Oct '07: |
35 |
pamelats |
1.1 |
fDataAC[i+26] = evntLSB; |
36 |
|
|
fDataAC[i+90] = evntLSB; |
37 |
pamelats |
1.3 |
} |
38 |
|
|
for(i=0; i<=7; i++){ |
39 |
pamelats |
1.1 |
fDataAC[i+42] = evntLSB; |
40 |
|
|
fDataAC[i+106] = evntLSB; |
41 |
pamelats |
1.3 |
} |
42 |
pamelats |
1.1 |
// increments for every trigger might be needed at some point. |
43 |
|
|
// dummy for now |
44 |
mocchiut |
1.5 |
fDataAC[50] = 0x0000; |
45 |
pamelats |
1.1 |
fDataAC[114] = 0x0000; |
46 |
|
|
|
47 |
|
|
// dummy FPGA clock (increment by 1 at each event) |
48 |
pamelats |
1.3 |
if(Ievnt<=0xFFFF){ |
49 |
pamelats |
1.1 |
fDataAC[51] = 0x0000; |
50 |
|
|
fDataAC[52] = Ievnt; |
51 |
|
|
fDataAC[115] = 0x0000; |
52 |
|
|
fDataAC[116] = Ievnt; |
53 |
pamelats |
1.3 |
} |
54 |
|
|
else{ |
55 |
pamelats |
1.1 |
fDataAC[51] = evntMSB; |
56 |
|
|
fDataAC[52] = evntLSB; |
57 |
|
|
fDataAC[115] = fDataAC[51]; |
58 |
|
|
fDataAC[116] = fDataAC[52]; |
59 |
|
|
} |
60 |
|
|
// dummy temperatures |
61 |
|
|
fDataAC[53] = 0x0000; |
62 |
|
|
fDataAC[54] = 0x0000; |
63 |
|
|
fDataAC[117] = 0x0000; |
64 |
|
|
fDataAC[118] = 0x0000; |
65 |
|
|
// dummy DAC thresholds |
66 |
pamelats |
1.3 |
for(i=0; i<=7; i++){ |
67 |
pamelats |
1.1 |
fDataAC[i+55] = 0x1A13; |
68 |
|
|
fDataAC[i+119] = 0x1A13; |
69 |
|
|
} |
70 |
pamelats |
1.3 |
// In this simpliefied approach we will assume that once a particle releases > 0.5 mip in one of the 12 AC detectors it will fire. We will furthermore assume that both cards read out identical data. |
71 |
pamelats |
1.1 |
|
72 |
pamelats |
1.3 |
// If you develop your digitization algorithm, you should start by identifying the information present in level2 (post-darth-vader) data. |
73 |
pamelats |
1.1 |
|
74 |
pamelats |
1.3 |
Float_t SumEcat[4],SumEcas[4],SumEcard[4]; |
75 |
|
|
for(i=0;i<4;i++){ |
76 |
|
|
SumEcat[i]=0.; |
77 |
|
|
SumEcas[i]=0.; |
78 |
|
|
SumEcard[i]=0.; |
79 |
|
|
} |
80 |
pamelats |
1.1 |
// energy dependence on position (see file AcFitOutputDistancePmt.C by S.Orsi) |
81 |
|
|
// based on J.Lundquist's calculations (PhD thesis, page 94) |
82 |
|
|
// function: [0]+[1]*atan([2]/(x+1)), where the 3 parameters are: |
83 |
|
|
// 8.25470e-01 +- 1.79489e-02 |
84 |
|
|
// 6.41609e-01 +- 2.65846e-02 |
85 |
|
|
// 9.81177e+00 +- 1.21284e+00 |
86 |
|
|
// hp: 1 minimum ionising particle at 35cm from the PMT releases 1mip |
87 |
|
|
|
88 |
|
|
// PMT positions: x,y,z: (average position of the 2 PMTs) |
89 |
|
|
Float_t posCasPmt[4][3]={{28.308, -17.168, 63.644}, // 1 - CAS CPU: x,y,z |
90 |
|
|
{18.893, 24.913, 63.644}, // 2 - CAS DCDC |
91 |
|
|
{-24.307, 17.162, 63.644}, // 3 - CAS VME |
92 |
|
|
{-17.765, -28.300, 63.644}}; // 4 - CAS IPM |
93 |
|
|
Float_t dAC=0.; // distance from PMT |
94 |
pamelats |
1.3 |
|
95 |
|
|
if(Nthcat>*ncat){ |
96 |
|
|
cout<<"*** ERROR AC! Nthcat= "<<Nthcat<<" out of range! "<<endl; |
97 |
|
|
for(i=0;i<4;i++)SumEcat[i]=2*thr; |
98 |
|
|
} |
99 |
|
|
else{ |
100 |
|
|
for(i=0;i<Nthcat;i++){ |
101 |
|
|
if(Icat[i]>0 && Icat[i]<5)SumEcat[Icat[i]-1]+=Erelcat[i]; |
102 |
|
|
} |
103 |
|
|
} |
104 |
|
|
if(Nthcas>*ncas){ |
105 |
|
|
cout<<"*** ERROR AC! Nthcas= "<<Nthcas<<" out of range!"<<endl; |
106 |
|
|
for(i=0;i<4;i++)SumEcas[i]=2*thr; |
107 |
|
|
} |
108 |
|
|
else{ |
109 |
|
|
for (i=0;i<Nthcas;i++){ |
110 |
|
|
if(Icas[i]>0 && Icas[i]<5){ |
111 |
|
|
dAC=sqrt(pow((Xincas[i]+Xoutcas[i])/2 - posCasPmt[Icas[i]-1][0],2) + pow((Yincas[i]+Youtcas[i])/2 - posCasPmt[Icas[i]-1][1],2) + pow((Zincas[i]+Zoutcas[i])/2 - posCasPmt[Icas[i]-1][2],2)); |
112 |
|
|
SumEcas[Icas[i]-1] += Erelcas[i]*attenAC->Eval(dAC); |
113 |
|
|
} |
114 |
|
|
} |
115 |
|
|
} |
116 |
|
|
if(Nthcard>*ncar){ |
117 |
|
|
cout<<"*** ERROR AC! Nthcard= "<<Nthcard<<" out of range!"<<endl; |
118 |
|
|
for(i=0;i<4;i++)SumEcard[i]=2*thr; |
119 |
|
|
} |
120 |
|
|
else{ |
121 |
|
|
for(Int_t k= 0;k<Nthcard;k++){ |
122 |
|
|
if(Icard[i]>0 && Icard[i]<5)SumEcard[Icard[k]-1] += Erelcard[k]; |
123 |
pamelats |
1.1 |
} |
124 |
pamelats |
1.3 |
} |
125 |
pamelats |
1.1 |
|
126 |
|
|
// channel mapping Hit Map |
127 |
|
|
// 1 CARD4 0 LSB |
128 |
|
|
// 2 CAT2 0 |
129 |
|
|
// 3 CAS1 0 |
130 |
|
|
// 4 NC 0 |
131 |
|
|
// 5 CARD2 0 |
132 |
|
|
// 6 CAT4 1 |
133 |
|
|
// 7 CAS4 0 |
134 |
|
|
// 8 NC 0 |
135 |
|
|
// 9 CARD3 0 |
136 |
|
|
// 10 CAT3 0 |
137 |
|
|
// 11 CAS3 0 |
138 |
|
|
// 12 NC 0 |
139 |
|
|
// 13 CARD1 0 |
140 |
|
|
// 14 CAT1 0 |
141 |
|
|
// 15 CAS2 0 |
142 |
|
|
// 16 NC 0 MSB |
143 |
|
|
|
144 |
|
|
// In the first version only the hit-map is filled, not the SR. |
145 |
|
|
|
146 |
|
|
fDataAC[3] = 0x0000; |
147 |
|
|
|
148 |
|
|
if (SumEcas[0] > thr) fDataAC[3] = 0x0004; |
149 |
|
|
if (SumEcas[1] > thr) fDataAC[3] += 0x4000; |
150 |
|
|
if (SumEcas[2] > thr) fDataAC[3] += 0x0400; |
151 |
|
|
if (SumEcas[3] > thr) fDataAC[3] += 0x0040; |
152 |
|
|
|
153 |
|
|
if (SumEcat[0] > thr) fDataAC[3] += 0x2000; |
154 |
|
|
if (SumEcat[1] > thr) fDataAC[3] += 0x0002; |
155 |
|
|
if (SumEcat[2] > thr) fDataAC[3] += 0x0200; |
156 |
|
|
if (SumEcat[3] > thr) fDataAC[3] += 0x0020; |
157 |
|
|
|
158 |
|
|
if (SumEcard[0] > thr) fDataAC[3] += 0x1000; |
159 |
|
|
if (SumEcard[1] > thr) fDataAC[3] += 0x0010; |
160 |
|
|
if (SumEcard[2] > thr) fDataAC[3] += 0x0100; |
161 |
|
|
if (SumEcard[3] > thr) fDataAC[3] += 0x0001; |
162 |
|
|
|
163 |
|
|
fDataAC[67] = fDataAC[3]; |
164 |
|
|
|
165 |
|
|
// shift registers |
166 |
|
|
// the central bin is equal to the hitmap, all other bins in the shift register are 0 |
167 |
|
|
for (UInt_t i=0; i<=15; i++){ |
168 |
|
|
fDataAC[i+11] = 0x0000; |
169 |
|
|
fDataAC[i+75] = 0x0000; |
170 |
|
|
} |
171 |
|
|
fDataAC[18] = fDataAC[3]; |
172 |
|
|
fDataAC[82] = fDataAC[3]; |
173 |
|
|
|
174 |
|
|
// for (Int_t i=0; i<fACbuffer; i++){ |
175 |
|
|
// printf("%0x ",fDataAC[i]); |
176 |
|
|
// if ((i+1)%8 ==0) cout << endl; |
177 |
|
|
// } |
178 |
pizzolot |
1.4 |
|
179 |
|
|
// the last word is a CRC |
180 |
|
|
fDataAC[63] = EvaluateCrcAC (fDataAC, 0); |
181 |
|
|
fDataAC[127]= EvaluateCrcAC (fDataAC, 1); |
182 |
|
|
}; |
183 |
|
|
|
184 |
|
|
|
185 |
|
|
|
186 |
|
|
|
187 |
|
|
|
188 |
|
|
UShort_t Digitizer::EvaluateCrcAC( UShort_t *pAC , Bool_t flag ) |
189 |
|
|
{ |
190 |
|
|
// Flag=0for AC1 ; flag=1 for AC2 |
191 |
|
|
UShort_t check=0; |
192 |
|
|
|
193 |
|
|
UInt_t l=0; |
194 |
|
|
for (UInt_t i=0; i<63; i++) |
195 |
|
|
{ |
196 |
|
|
l = 64*flag + i ; |
197 |
|
|
//printf("ACAC i=%d l=%d chech=%d \n",i,l,check); |
198 |
|
|
check = crcAC(check, pAC[l]); |
199 |
|
|
} |
200 |
|
|
return check; |
201 |
|
|
|
202 |
|
|
}; |
203 |
|
|
|
204 |
|
|
|
205 |
|
|
UShort_t Digitizer::crcAC( UShort_t old , UShort_t neww ) |
206 |
|
|
{ |
207 |
|
|
union crc_data { |
208 |
|
|
short word; |
209 |
|
|
struct bit_field { |
210 |
|
|
unsigned b0:1; |
211 |
|
|
unsigned b1:1; |
212 |
|
|
unsigned b2:1; |
213 |
|
|
unsigned b3:1; |
214 |
|
|
unsigned b4:1; |
215 |
|
|
unsigned b5:1; |
216 |
|
|
unsigned b6:1; |
217 |
|
|
unsigned b7:1; |
218 |
|
|
unsigned b8:1; |
219 |
|
|
unsigned b9:1; |
220 |
|
|
unsigned b10:1; |
221 |
|
|
unsigned b11:1; |
222 |
|
|
unsigned b12:1; |
223 |
|
|
unsigned b13:1; |
224 |
|
|
unsigned b14:1; |
225 |
|
|
unsigned b15:1; |
226 |
|
|
} bit; |
227 |
|
|
} c,d,r; |
228 |
|
|
|
229 |
|
|
c.word = old; |
230 |
|
|
d.word = neww; |
231 |
|
|
r.word = 0; |
232 |
|
|
|
233 |
|
|
r.bit.b0 = c.bit.b0 ^ c.bit.b4 ^ c.bit.b8 ^ c.bit.b11 ^ c.bit.b12 ^ |
234 |
|
|
d.bit.b0 ^ d.bit.b4 ^ d.bit.b8 ^ d.bit.b11 ^ d.bit.b12; |
235 |
|
|
|
236 |
|
|
r.bit.b1 = c.bit.b1 ^ c.bit.b5 ^ c.bit.b9 ^ c.bit.b12 ^ c.bit.b13 ^ |
237 |
|
|
d.bit.b1 ^ d.bit.b5 ^ d.bit.b9 ^ d.bit.b12 ^ d.bit.b13; |
238 |
|
|
|
239 |
|
|
r.bit.b2 = c.bit.b2 ^ c.bit.b6 ^ c.bit.b10 ^ c.bit.b13 ^ c.bit.b14 ^ |
240 |
|
|
d.bit.b2 ^ d.bit.b6 ^ d.bit.b10 ^ d.bit.b13 ^ d.bit.b14; |
241 |
|
|
|
242 |
|
|
r.bit.b3 = c.bit.b3 ^ c.bit.b7 ^ c.bit.b11 ^ c.bit.b14 ^ c.bit.b15 ^ |
243 |
|
|
d.bit.b3 ^ d.bit.b7 ^ d.bit.b11 ^ d.bit.b14 ^ d.bit.b15; |
244 |
|
|
|
245 |
|
|
r.bit.b4 = c.bit.b4 ^ c.bit.b8 ^ c.bit.b12 ^ c.bit.b15 ^ |
246 |
|
|
d.bit.b4 ^ d.bit.b8 ^ d.bit.b12 ^ d.bit.b15; |
247 |
|
|
|
248 |
|
|
r.bit.b5 = c.bit.b0 ^ c.bit.b4 ^ c.bit.b5 ^ c.bit.b8 ^ c.bit.b9 ^ |
249 |
|
|
c.bit.b11 ^ c.bit.b12 ^ c.bit.b13 ^ |
250 |
|
|
d.bit.b0 ^ d.bit.b4 ^ d.bit.b5 ^ d.bit.b8 ^ d.bit.b9 ^ |
251 |
|
|
d.bit.b11 ^ d.bit.b12 ^ d.bit.b13; |
252 |
|
|
|
253 |
|
|
r.bit.b6 = c.bit.b1 ^ c.bit.b5 ^ c.bit.b6 ^ c.bit.b9 ^ c.bit.b10 ^ |
254 |
|
|
c.bit.b12 ^ c.bit.b13 ^ c.bit.b14 ^ |
255 |
|
|
d.bit.b1 ^ d.bit.b5 ^ d.bit.b6 ^ d.bit.b9 ^ d.bit.b10 ^ |
256 |
|
|
d.bit.b12 ^ d.bit.b13 ^ d.bit.b14; |
257 |
|
|
|
258 |
|
|
r.bit.b7 = c.bit.b2 ^ c.bit.b6 ^ c.bit.b7 ^ c.bit.b10 ^ c.bit.b11 ^ |
259 |
|
|
c.bit.b13 ^ c.bit.b14 ^ c.bit.b15 ^ |
260 |
|
|
d.bit.b2 ^ d.bit.b6 ^ d.bit.b7 ^ d.bit.b10 ^ d.bit.b11 ^ |
261 |
|
|
d.bit.b13 ^ d.bit.b14 ^ d.bit.b15; |
262 |
|
|
|
263 |
|
|
r.bit.b8 = c.bit.b3 ^ c.bit.b7 ^ c.bit.b8 ^ c.bit.b11 ^ c.bit.b12 ^ |
264 |
|
|
c.bit.b14 ^ c.bit.b15 ^ |
265 |
|
|
d.bit.b3 ^ d.bit.b7 ^ d.bit.b8 ^ d.bit.b11 ^ d.bit.b12 ^ |
266 |
|
|
d.bit.b14 ^ d.bit.b15; |
267 |
|
|
|
268 |
|
|
r.bit.b9 = c.bit.b4 ^ c.bit.b8 ^ c.bit.b9 ^ c.bit.b12 ^ c.bit.b13 ^ |
269 |
|
|
c.bit.b15 ^ |
270 |
|
|
d.bit.b4 ^ d.bit.b8 ^ d.bit.b9 ^ d.bit.b12 ^ d.bit.b13 ^ |
271 |
|
|
d.bit.b15; |
272 |
|
|
|
273 |
|
|
r.bit.b10 = c.bit.b5 ^ c.bit.b9 ^ c.bit.b10 ^ c.bit.b13 ^ c.bit.b14 ^ |
274 |
|
|
d.bit.b5 ^ d.bit.b9 ^ d.bit.b10 ^ d.bit.b13 ^ d.bit.b14; |
275 |
|
|
|
276 |
|
|
r.bit.b11 = c.bit.b6 ^ c.bit.b10 ^ c.bit.b11 ^ c.bit.b14 ^ c.bit.b15 ^ |
277 |
|
|
d.bit.b6 ^ d.bit.b10 ^ d.bit.b11 ^ d.bit.b14 ^ d.bit.b15; |
278 |
|
|
|
279 |
|
|
r.bit.b12 = c.bit.b0 ^ c.bit.b4 ^ c.bit.b7 ^ c.bit.b8 ^ c.bit.b15 ^ |
280 |
|
|
d.bit.b0 ^ d.bit.b4 ^ d.bit.b7 ^ d.bit.b8 ^ d.bit.b15; |
281 |
|
|
|
282 |
|
|
r.bit.b13 = c.bit.b1 ^ c.bit.b5 ^ c.bit.b8 ^ c.bit.b9 ^ |
283 |
|
|
d.bit.b1 ^ d.bit.b5 ^ d.bit.b8 ^ d.bit.b9; |
284 |
|
|
|
285 |
|
|
r.bit.b14 = c.bit.b2 ^ c.bit.b6 ^ c.bit.b9 ^ c.bit.b10 ^ |
286 |
|
|
d.bit.b2 ^ d.bit.b6 ^ d.bit.b9 ^ d.bit.b10; |
287 |
|
|
|
288 |
|
|
r.bit.b15 = c.bit.b3 ^ c.bit.b7 ^ c.bit.b10 ^ c.bit.b11 ^ |
289 |
|
|
d.bit.b3 ^ d.bit.b7 ^ d.bit.b10 ^ d.bit.b11; |
290 |
|
|
|
291 |
|
|
return r.word; |
292 |
|
|
|
293 |
pamelats |
1.1 |
}; |