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