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 |
|
|
void Digitizer::DigitizeTOF(int np,float *atte1,float *atte2,float *lambda1,float *lambda2){ |
32 |
|
|
//fDataTof: 12 x 23 bytes (=276 bytes) |
33 |
|
|
UChar_t *pTof=fDataTof; |
34 |
|
|
Bool_t DEBUG=false; |
35 |
|
|
|
36 |
|
|
Int_t cdp[75] = {0,1,1,0,1,1,0,1,1,0,1,1,0,1,1, //0-14 |
37 |
|
|
0,0,0,1,0,1,0,1,1,0,0,1,0,1,0, //15-29 |
38 |
|
|
1,1,1,1,2,2,2,3,3,3,3,4,4,4,1, //30-44 |
39 |
|
|
1,2,0,2,0,0,5,5,5,5,6,6,6,6,7, //45-59 |
40 |
|
|
3,3,4,4,5,5,6,7,8,9,10,11,12,13,14 }; //60-74 |
41 |
|
|
|
42 |
|
|
int Z = cdp[Ipa-1]; |
43 |
|
|
|
44 |
|
|
float time_res[8] = {425.,210.,170.,130.,120.,120.,120.,120.}; |
45 |
|
|
|
46 |
|
|
Float_t dt1 = 1.e-12*time_res[0]; // single PMT resolution for Z=1 (WM, Nov'07) |
47 |
|
|
|
48 |
|
|
if ((Z > 1) && (Z < 9)) dt1=1.e-12*time_res[(Z-1)]; |
49 |
|
|
if (Z > 8) dt1=120.e-12; |
50 |
|
|
|
51 |
|
|
|
52 |
|
|
// ------ evaluate energy in each pmt: ------ |
53 |
|
|
// strip geometry (lenght/width) |
54 |
|
|
Float_t dimel[6] = {33.0, 40.8 ,18.0, 15.0, 15.0, 18.0}; |
55 |
|
|
// S11 8 paddles 33.0 x 5.1 cm |
56 |
|
|
// S12 6 paddles 40.8 x 5.5 cm |
57 |
|
|
// S21 2 paddles 18.0 x 7.5 cm |
58 |
|
|
// S22 2 paddles 15.0 x 9.0 cm |
59 |
|
|
// S31 3 paddles 15.0 x 6.0 cm |
60 |
|
|
// S32 3 paddles 18.0 x 5.0 cm |
61 |
|
|
Float_t FGeo[2]={0., 0.}; /* geometrical factor */ |
62 |
|
|
const Float_t Pho_keV = 10.; // photons per keV in scintillator |
63 |
|
|
const Float_t echarge = 1.6e-19; // electron charge |
64 |
|
|
Float_t Npho=0.; |
65 |
|
|
Float_t QevePmt_pC[48]; |
66 |
|
|
Float_t QhitPad_pC[2]={0., 0.}; |
67 |
|
|
Float_t QhitPmt_pC[2]={0., 0.}; |
68 |
|
|
Float_t pmGain = 3.5e6; /* PMT Gain: the same for all PMTs */ |
69 |
|
|
Float_t effi=0.21; /* Efficienza di fotocatodo */ |
70 |
|
|
// pC < 800 |
71 |
|
|
Float_t ADC_pC0A = -4.437616e+01 ; |
72 |
|
|
Float_t ADC_pC1A = 1.573329e+00 ; |
73 |
|
|
Float_t ADC_pC2A = 2.780518e-04 ; |
74 |
|
|
Float_t ADC_pC3A = -2.302160e-07 ; |
75 |
|
|
// pC > 800: |
76 |
|
|
Float_t ADC_pC0B = -2.245756e+02 ; |
77 |
|
|
Float_t ADC_pC1B = 2.184156e+00 ; |
78 |
|
|
Float_t ADC_pC2B = -4.171825e-04 ; |
79 |
|
|
Float_t ADC_pC3B = 3.789715e-08 ; |
80 |
|
|
|
81 |
|
|
Float_t pCthres=40.; // threshold in charge |
82 |
|
|
Int_t ADClast=4095; // no signal --> ADC ch=4095 |
83 |
|
|
Int_t ADCsat=3100; // saturation value for the ADCs |
84 |
|
|
Int_t ADCtof[48]; |
85 |
|
|
Float_t ScaleFact[48]={0.39, 0.49, 0.38, 0.40, 0.65, 0.51, 0.43, |
86 |
|
|
0.49, 0.58, 0.38, 0.53, 0.57, 0.53, 0.45, 0.49, 0.16, |
87 |
|
|
0.15, 0.44, 0.28, 0.57, 0.26, 0.72, 0.37, 0.29, 0.30, 0.89, |
88 |
|
|
0.37, 0.08, 0.27, 0.23, 0.12, 0.22, 0.15, 0.16, 0.21, |
89 |
|
|
0.19, 0.41, 0.32, 0.39, 0.38, 0.28, 0.66, 0.28, 0.40, 0.39, 0.40, 0.37, 0.35 }; |
90 |
|
|
for(Int_t i=0; i<48; i++){ |
91 |
|
|
QevePmt_pC[i] = 0; |
92 |
|
|
ADCtof[i]=0; |
93 |
|
|
} |
94 |
|
|
Int_t ip,ipad,pmtleft=0,pmtright=0,*pl,*pr; |
95 |
|
|
pl = &pmtleft; |
96 |
|
|
pr = &pmtright; |
97 |
|
|
// TDC variables: |
98 |
|
|
Int_t TDClast=4095,TDCint[48]; |
99 |
|
|
Float_t tdc[48],tdc1[48],tdcpmt[48]; |
100 |
|
|
for(Int_t i=0; i<48; i++) { |
101 |
|
|
tdcpmt[i] = 1000.; |
102 |
|
|
tdc[i] = 0.; // 18-oct WM |
103 |
|
|
tdc1[i] = 0.; // 18-oct WM |
104 |
|
|
} |
105 |
|
|
Float_t thresh=20.; // to be defined better... (Wolfgang) |
106 |
|
|
// === TDC: simulate timing for each paddle |
107 |
|
|
Float_t tdcres[50],c1_S[50],c2_S[50],c3_S[50]; |
108 |
|
|
for(Int_t j=0;j<48;j++){ |
109 |
|
|
tdcres[j] = 50.E-12; // TDC resolution 50 picosec |
110 |
|
|
c1_S[j] = 500.; // cable length in channels |
111 |
|
|
c2_S[j] = 0.; |
112 |
|
|
c3_S[j] = 1000.; |
113 |
|
|
c1_S[j] = c1_S[j]*tdcres[j]; // cable length in sec |
114 |
|
|
c2_S[j] = c2_S[j]*tdcres[j]; |
115 |
|
|
} |
116 |
|
|
/* ********************************** start loop over hits */ |
117 |
pamelats |
1.2 |
if(Nthtof>*ntf)cout<<"NTHTOF > "<<*ntf<<" , event rejected ! "<<Nthtof<<endl; |
118 |
pamelats |
1.1 |
else{ |
119 |
|
|
for(Int_t nh=0; nh<Nthtof; nh++){ |
120 |
|
|
//// if(Ipartof[nh]!=Ipa)continue; |
121 |
|
|
Float_t s_l_g[6] = {8.0, 8.0, 20.9, 22.0, 9.8, 8.3 }; // length of the lightguide |
122 |
|
|
Float_t t1,t2,veff,veff1,veff0 ; |
123 |
|
|
veff0 = 100.*1.0e8 ; // light velocity in the scintillator in m/sec |
124 |
|
|
veff1 = 100.*1.5e8; // light velocity in the lightguide in m/sec |
125 |
|
|
veff=veff0; // signal velocity in the paddle |
126 |
|
|
t1 = Timetof[nh] ; // Start |
127 |
|
|
t2 = Timetof[nh] ; |
128 |
|
|
// Donatella: redefinition plane and pad for vectors in C |
129 |
|
|
ip = Ipltof[nh]-1; |
130 |
|
|
ipad = Ipaddle[nh]-1; |
131 |
|
|
pmtleft=0; |
132 |
|
|
pmtright=0; |
133 |
|
|
// WM: S12 paddles are "reversed" (Nov'07) |
134 |
|
|
if (ip==2) |
135 |
|
|
if (ipad==0) |
136 |
|
|
ipad=1; |
137 |
|
|
else |
138 |
|
|
ipad=0; |
139 |
|
|
// if (ip<6) { |
140 |
|
|
if ((ip>-1)&&(ip<6)) { //ToF paddles only, not S4 |
141 |
|
|
Paddle2Pmt(ip, ipad, &pmtleft, &pmtright); |
142 |
|
|
// DC: evaluates mean position and path inside the paddle |
143 |
|
|
Float_t tpos=0.; |
144 |
|
|
Float_t path[2] = {0., 0.}; |
145 |
|
|
//--- Strip in Y = S11,S22,S31 ------ |
146 |
|
|
if(ip==0 || ip==3 || ip==4) |
147 |
|
|
tpos = (Yintof[nh]+Youttof[nh])/2.; |
148 |
|
|
else |
149 |
|
|
if(ip==1 || ip==2 || ip==5) //--- Strip in X for S12,S21,S32 |
150 |
|
|
tpos = (Xintof[nh]+Xouttof[nh])/2.; |
151 |
|
|
else //if (ip!=6) |
152 |
|
|
printf("*** WARNING TOF: this option should never occur! (ip=%2i, nh=%2i)\n",ip,nh); |
153 |
|
|
path[0]= tpos + dimel[ip]/2.; // path to left PMT |
154 |
|
|
path[1]= dimel[ip]/2.- tpos; // path to right PMT |
155 |
|
|
if (DEBUG) { |
156 |
|
|
cout <<" plane "<<ip<<" strip # ="<< ipad <<" tpos "<< tpos <<"\n"; |
157 |
|
|
cout <<"pmtleft, pmtright "<<pmtleft<<" "<<pmtright<<endl; |
158 |
|
|
} |
159 |
|
|
// constant geometric factor, the rest is handled by the scaling factor |
160 |
|
|
FGeo[0] =0.5; |
161 |
|
|
FGeo[1] =0.5; |
162 |
|
|
Npho = Ereltof[nh]*Pho_keV*1.0e6; // Eloss in GeV |
163 |
|
|
|
164 |
|
|
Float_t knorm[2]={0., 0.}; // Donatella |
165 |
|
|
Float_t Atten[2]={0., 0.}; // Donatella |
166 |
|
|
for(Int_t j=0; j<2; j++){ |
167 |
|
|
QhitPad_pC[j]= Npho*FGeo[j]*effi*pmGain*echarge*1.E12*ScaleFact[pmtleft+j]; |
168 |
|
|
// WM |
169 |
|
|
knorm[j]=atte1[pmtleft+j]*exp(lambda1[pmtleft+j]*dimel[ip]/2.*pow(-1,j+1)) + |
170 |
|
|
atte2[pmtleft+j]*exp(lambda2[pmtleft+j]*dimel[ip]/2.*pow(-1,j+1)); |
171 |
|
|
Atten[j]=atte1[pmtleft+j]*exp(tpos*lambda1[pmtleft+j]) + |
172 |
|
|
atte2[pmtleft+j]*exp(tpos*lambda2[pmtleft+j]) ; |
173 |
|
|
QhitPmt_pC[j]= QhitPad_pC[j]*Atten[j]/knorm[j]; |
174 |
|
|
if (DEBUG) { |
175 |
|
|
cout<<"pmtleft "<<pmtleft<<" j "<<j<<endl; |
176 |
|
|
cout<<" atte1 "<<atte1[pmtleft+j]<<"lambda1 "<<lambda1[pmtleft+j]<<" atte2 "<<atte2[pmtleft+j]<<"lambda2 "<<lambda2[pmtleft+j] <<endl; |
177 |
|
|
cout<<j<<" tpos "<<tpos<<" knorm "<<knorm[j]<<" "<<Atten[j]<<" "<<"QhitPmt_pC "<<QhitPmt_pC[j]<<endl; |
178 |
|
|
} |
179 |
|
|
} |
180 |
|
|
if(DEBUG)cout<<"Npho "<<Npho<<" QhitPmt_pC "<<QhitPmt_pC[0]<<" "<<QhitPmt_pC[1]<<endl; |
181 |
|
|
QevePmt_pC[pmtleft] += QhitPmt_pC[0]; |
182 |
|
|
QevePmt_pC[pmtright] += QhitPmt_pC[1]; |
183 |
|
|
// TDC |
184 |
|
|
// WM right and left <-> |
185 |
|
|
t1 = t1 + fabs(path[0]/veff) + s_l_g[ip]/veff1; |
186 |
|
|
t2 = t2 + fabs(path[1]/veff) + s_l_g[ip]/veff1 ; // Signal reaches PMT |
187 |
|
|
t1 = gRandom->Gaus(t1,dt1); //apply gaussian error dt |
188 |
|
|
t2 = gRandom->Gaus(t2,dt1); //apply gaussian error dt |
189 |
|
|
t1 = t1 + c1_S[pmtleft] ; // Signal reaches Discriminator ,TDC starts to run |
190 |
|
|
t2 = t2 + c1_S[pmtright] ; |
191 |
|
|
// check if signal is above threshold |
192 |
|
|
// then check if tdcpmt is already filled by another hit... |
193 |
|
|
// only re-fill if time is smaller |
194 |
|
|
if (QhitPmt_pC[0] > thresh) { |
195 |
|
|
if (tdcpmt[pmtleft] == 1000.) { // fill for the first time |
196 |
|
|
tdcpmt[pmtleft] = t1; |
197 |
|
|
tdc[pmtleft] = t1 + c2_S[pmtleft] ; // Signal reaches Coincidence |
198 |
|
|
} |
199 |
|
|
if (tdcpmt[pmtleft] < 1000.) // is already filled! |
200 |
|
|
if (t1 < tdcpmt[pmtleft]) { |
201 |
|
|
tdcpmt[pmtleft] = t1; |
202 |
|
|
t1 = t1 + c2_S[pmtleft] ; // Signal reaches Coincidence |
203 |
|
|
tdc[pmtleft] = t1; |
204 |
|
|
} |
205 |
|
|
} |
206 |
|
|
if (QhitPmt_pC[1] > thresh) { |
207 |
|
|
if (tdcpmt[pmtright] == 1000.) { // fill for the first time |
208 |
|
|
tdcpmt[pmtright] = t2; |
209 |
|
|
tdc[pmtright] = t2 + c2_S[pmtright] ; // Signal reaches Coincidence |
210 |
|
|
} |
211 |
|
|
if (tdcpmt[pmtright] < 1000.) // is already filled! |
212 |
|
|
if (t2 < tdcpmt[pmtright]) { |
213 |
|
|
tdcpmt[pmtright] = t2; |
214 |
|
|
t2 = t2 + c2_S[pmtright] ; |
215 |
|
|
tdc[pmtright] = t2; |
216 |
|
|
} |
217 |
|
|
} |
218 |
|
|
if(DEBUG)cout<<nh<<" "<<Timetof[nh]<<" "<<t1<<" "<<t2<<endl; |
219 |
|
|
} // ip > -1 && ip < 6 |
220 |
|
|
} // **************************************** end loop over hits |
221 |
|
|
} // NTHTOF < 200 |
222 |
|
|
// ====== ADC ====== |
223 |
|
|
for(Int_t i=0; i<48; i++){ |
224 |
|
|
if (QevePmt_pC[i] < 800.) ADCtof[i]= (Int_t)(ADC_pC0A + ADC_pC1A*QevePmt_pC[i] + ADC_pC2A*pow(QevePmt_pC[i],2) + ADC_pC3A*pow(QevePmt_pC[i],3)); |
225 |
|
|
if (QevePmt_pC[i] > 800.) ADCtof[i]= (Int_t)(ADC_pC0B + ADC_pC1B*QevePmt_pC[i] + ADC_pC2B*pow(QevePmt_pC[i],2) + ADC_pC3B*pow(QevePmt_pC[i],3)); |
226 |
|
|
if (QevePmt_pC[i] > 2485.) ADCtof[i]= (Int_t)(1758. + 0.54*QevePmt_pC[i]); //assuming a fictional 0.54 ch/pC above ADCsat |
227 |
|
|
if (ADCtof[i]>ADCsat) ADCtof[i]=ADCsat; |
228 |
|
|
if (QevePmt_pC[i] < pCthres) ADCtof[i]= ADClast; |
229 |
|
|
if (ADCtof[i] < 0) ADCtof[i]=ADClast; |
230 |
|
|
if (ADCtof[i] > ADClast) ADCtof[i]=ADClast; |
231 |
|
|
//if(ADCtof[i]!=4095)cout<<ADCtof[i]<<" "; |
232 |
|
|
//if((i+1)%4==0)cout<<endl; |
233 |
|
|
} |
234 |
|
|
// cin>>ciao; |
235 |
|
|
|
236 |
|
|
// ====== build TDC coincidence ====== |
237 |
|
|
|
238 |
|
|
Float_t t_coinc = 0; |
239 |
|
|
Int_t ilast = 100; |
240 |
|
|
for (Int_t ii=0; ii<48;ii++) |
241 |
|
|
if (tdc[ii] > t_coinc) { |
242 |
|
|
t_coinc = tdc[ii]; |
243 |
|
|
ilast = ii; |
244 |
|
|
} |
245 |
|
|
|
246 |
|
|
// cout<<ilast<<" "<<t_coinc<<endl; |
247 |
|
|
// At t_coinc trigger condition is fulfilled |
248 |
|
|
|
249 |
|
|
for (Int_t ii=0; ii<48;ii++){ |
250 |
|
|
// if (tdc[ii] != 0) tdc1[ii] = t_coinc - tdc[ii]; // test 1 |
251 |
|
|
if (tdc[ii] != 0) tdc1[ii] = t_coinc - tdcpmt[ii]; // test 2 |
252 |
|
|
tdc1[ii] = tdc1[ii]/tdcres[ii]; // divide by TDC resolution |
253 |
|
|
if (tdc[ii] != 0) tdc1[ii] = tdc1[ii] + c3_S[ii]; // add cable length c3 |
254 |
|
|
} // missing parenthesis inserted! (Silvio) |
255 |
|
|
|
256 |
|
|
for(Int_t i=0; i<48; i++){ |
257 |
|
|
if(tdc1[i] != 0.){ |
258 |
|
|
TDCint[i]=(Int_t)tdc1[i]; |
259 |
|
|
if (TDCint[i]>4093) TDCint[i]=TDClast; // 18-oct WM |
260 |
|
|
if (DEBUG)cout<<i<<" "<<TDCint[i]<<endl; |
261 |
|
|
} else |
262 |
|
|
TDCint[i]= TDClast; |
263 |
|
|
} |
264 |
|
|
if (DEBUG)cout<<"-----------"<<endl; |
265 |
|
|
//------ use channelmap for ToF: 18-oct WM |
266 |
|
|
Int_t channelmap[] = {3,21,11,29,19,45,27,37,36,28,44,20,5,12,13,4, |
267 |
|
|
6,47,14,39,22,31,30,23,38,15,46,7,0,33,16,24, |
268 |
|
|
8,41,32,40,25,17,34,9,42,1,2,10,18,26,35,43}; |
269 |
|
|
Int_t ADChelp[48],TDChelp[48]; |
270 |
|
|
for(Int_t i=0; i<48; i++){ |
271 |
|
|
Int_t ii=channelmap[i]; |
272 |
|
|
ADChelp[ii]= ADCtof[i]; |
273 |
|
|
TDChelp[ii]= TDCint[i]; |
274 |
|
|
} |
275 |
|
|
for(Int_t i=0; i<48; i++){ |
276 |
|
|
ADCtof[i]= ADChelp[i]; |
277 |
|
|
TDCint[i]= TDChelp[i]; |
278 |
|
|
} |
279 |
|
|
// ====== write fDataTof ======= |
280 |
|
|
UChar_t Ctrl3bit[8]={32,0,96,64,160,128,224,192}; // DC (msb in 8 bit word ) |
281 |
|
|
UChar_t tofBin; |
282 |
|
|
for (Int_t j=0; j < 12; j++){ // loop on TDC #12 |
283 |
|
|
Int_t j12=j*23; // for each TDC 23 bytes (8 bits) |
284 |
|
|
fDataTof[j12+0]=0x00; // TDC_ID |
285 |
|
|
fDataTof[j12+1]=0x00; // EV_COUNT |
286 |
|
|
fDataTof[j12+2]=0x00; // TDC_MASK (1) |
287 |
|
|
fDataTof[j12+3]=0x00; // TDC_MASK (2) |
288 |
|
|
for (Int_t k=0; k < 4; k++){ // for each TDC 4 channels (ADC+TDC) |
289 |
|
|
Int_t jk12=j12+4*k; // ADC,TDC channel (0-47) |
290 |
|
|
tofBin =(UChar_t)(ADCtof[k+4*j]/256); // ADC# (msb) |
291 |
|
|
fDataTof[jk12+4] = Bin2GrayTof(tofBin,fDataTof[jk12+4]); |
292 |
|
|
/* control bits inserted here, after the bin to gray conv - DC*/ |
293 |
|
|
fDataTof[jk12+4] = Ctrl3bit[2*k] | fDataTof[jk12+4]; |
294 |
|
|
tofBin=(UChar_t)(ADCtof[k+4*j]%256); // ADC# (lsb) |
295 |
|
|
fDataTof[jk12+5] = Bin2GrayTof(tofBin,fDataTof[jk12+5]); |
296 |
|
|
tofBin=(UChar_t)(TDCint[k+4*j]/256); // TDC# (msb) |
297 |
|
|
fDataTof[jk12+6]=Bin2GrayTof(tofBin,fDataTof[jk12+6]); |
298 |
|
|
/* control bits inserted here, after the bin to gray conv - DC*/ |
299 |
|
|
fDataTof[jk12+6] = Ctrl3bit[2*k+1] | fDataTof[jk12+6]; |
300 |
|
|
tofBin=(UChar_t)(TDCint[k+4*j]%256); // TDC# (lsb) |
301 |
|
|
fDataTof[jk12+7]=Bin2GrayTof(tofBin,fDataTof[jk12+7]); |
302 |
|
|
} |
303 |
|
|
fDataTof[j12+20]=0x00; // TEMP1 |
304 |
|
|
fDataTof[j12+21]=0x00; // TEMP2 |
305 |
|
|
fDataTof[j12+22]= EvaluateCrcTof(pTof); // CRC |
306 |
|
|
pTof+=23; |
307 |
|
|
} |
308 |
|
|
// ====== evaluate trigger variables ======= |
309 |
|
|
//fDataTrigger: 152 bytes (corrected 30/11/'07 SO - it was 153) |
310 |
|
|
// initialization: |
311 |
|
|
for (Int_t j=0; j < 152; j++)fDataTrigger[j]=0x00; |
312 |
|
|
UChar_t *pTrg=fDataTrigger; |
313 |
|
|
// Only the variables with a (*) are modified; the others are set to 0 |
314 |
|
|
// info given in #bites data + #bites crc |
315 |
|
|
// TB_READ_PMT_PLANE : 6 + 1 |
316 |
|
|
// TB_READ_EVENT_COUNT : 3 + 1 (*) |
317 |
|
|
// TB_READ_TRIGGER_RATE : 12 + 1 |
318 |
|
|
// TB_READ_D_L_TIME : 4 + 1 |
319 |
|
|
// TB_READ_S4_CAL_COUNT : 4 + 1 |
320 |
|
|
// TB_READ_PMT_COUNT1 : 48 + 1 |
321 |
|
|
// TB_READ_PMT_COUNT2 : 48 + 1 |
322 |
|
|
// TB_READ_PATTERN_BUSY : 8 + 1 |
323 |
|
|
// TB_READ_PATTERN_TRIGGER: 7 + 1 (*) |
324 |
|
|
// TB_READ_TRIGGER_CONF : 2 + 1 (*) |
325 |
|
|
|
326 |
|
|
// TB_READ_EVENT_COUNT |
327 |
|
|
fhBookTree->SetBranchStatus("Ievnt",&Ievnt); |
328 |
|
|
UInt_t cTrg = (UInt_t)Ievnt; //counter |
329 |
|
|
UInt_t cTrg2 = 0; //counter with bits inverted, according to document |
330 |
|
|
//"formato dati provenienti dalla trigger board" |
331 |
|
|
for (Int_t i=0; i < 24; i++){ // Use the first 24 bits |
332 |
|
|
if (cTrg & (0x1 << i) ) |
333 |
|
|
cTrg2 = cTrg2 | (0x1 << (24-i)); |
334 |
|
|
} |
335 |
|
|
fDataTrigger[7] = (UChar_t)(cTrg2 >> 16); // 8 MSbits (out of 24) |
336 |
|
|
fDataTrigger[8] = (UChar_t)(cTrg2 >> 8); // 8 "middle" bits |
337 |
|
|
fDataTrigger[9] = (UChar_t)(cTrg2); // 8 LSbits |
338 |
|
|
pTrg=fDataTrigger+7; |
339 |
|
|
fDataTrigger[10]=EvaluateCrcTrigger(pTrg, 3); |
340 |
|
|
|
341 |
|
|
// TB_READ_PATTERN_TRIGGER: bytes 141-148: |
342 |
|
|
// PatternTrigMap[i] corresponds to bit i in TB_READ_PATTERN_TRIGGER: |
343 |
|
|
// mapping according to documents: |
344 |
|
|
// 1. "formato dati provenienti dalla trigger board" |
345 |
|
|
// 2. "The ToF quicklook software", Appendix A (Campana, Nagni) |
346 |
|
|
Int_t PatternTrigMap[]={29,42,43,1,16,7,17,28,33,41,46,2,15,8,18,27, |
347 |
|
|
30,40,44,3,14,9,19,26,32,37,47,4,13,10,20,25, |
348 |
|
|
34,31,38,45,5,12,21,24,36,35,39,48,6,11,22,23}; |
349 |
|
|
for (Int_t i=0; i < 48; i++) |
350 |
|
|
//if (ADCtof[i]>thrTrg) |
351 |
|
|
if (tdc1[channelmap[i]]!=0) |
352 |
|
|
fDataTrigger[147-(Int_t)((PatternTrigMap[i]+1)/8)]=fDataTrigger[147-(Int_t)((PatternTrigMap[i]+1)/8)] | (0x1 << (PatternTrigMap[i]%8)); |
353 |
|
|
pTrg=fDataTrigger+141; |
354 |
|
|
fDataTrigger[148]=EvaluateCrcTrigger(pTrg, 7); |
355 |
|
|
|
356 |
|
|
// TB_READ_TRIGGER_CONF : set always acq.mode TOF4 |
357 |
|
|
// |
358 |
|
|
// TOF1: S1-S2-S3 (&,|) |
359 |
|
|
// TOF4: S2-S3 (&,&) |
360 |
|
|
fDataTrigger[149]=0x02; |
361 |
|
|
fDataTrigger[150]=0x0; |
362 |
|
|
pTrg=fDataTrigger+149; |
363 |
|
|
fDataTrigger[151]=EvaluateCrcTrigger(pTrg, 2); |
364 |
|
|
} |
365 |
|
|
|
366 |
|
|
|
367 |
|
|
UChar_t Digitizer::Bin2GrayTof(UChar_t binaTOF,UChar_t grayTOF){ |
368 |
|
|
union graytof_data { |
369 |
|
|
UChar_t word; |
370 |
|
|
struct bit_field { |
371 |
|
|
unsigned b0:1; |
372 |
|
|
unsigned b1:1; |
373 |
|
|
unsigned b2:1; |
374 |
|
|
unsigned b3:1; |
375 |
|
|
unsigned b4:1; |
376 |
|
|
unsigned b5:1; |
377 |
|
|
unsigned b6:1; |
378 |
|
|
unsigned b7:1; |
379 |
|
|
} bit; |
380 |
|
|
} bi,gr; |
381 |
|
|
// |
382 |
|
|
bi.word = binaTOF; |
383 |
|
|
gr.word = grayTOF; |
384 |
|
|
// |
385 |
|
|
gr.bit.b0 = bi.bit.b1 ^ bi.bit.b0; |
386 |
|
|
gr.bit.b1 = bi.bit.b2 ^ bi.bit.b1; |
387 |
|
|
gr.bit.b2 = bi.bit.b3 ^ bi.bit.b2; |
388 |
|
|
gr.bit.b3 = bi.bit.b3; |
389 |
|
|
// |
390 |
|
|
/* bin to gray conversion 4 bit per time*/ |
391 |
|
|
// |
392 |
|
|
gr.bit.b4 = bi.bit.b5 ^ bi.bit.b4; |
393 |
|
|
gr.bit.b5 = bi.bit.b6 ^ bi.bit.b5; |
394 |
|
|
gr.bit.b6 = bi.bit.b7 ^ bi.bit.b6; |
395 |
|
|
gr.bit.b7 = bi.bit.b7; |
396 |
|
|
// |
397 |
|
|
return(gr.word); |
398 |
|
|
} |
399 |
|
|
|
400 |
|
|
UChar_t Digitizer::EvaluateCrcTof(UChar_t *pTof) { |
401 |
|
|
Bool_t DEBUG=false; |
402 |
|
|
if (DEBUG) |
403 |
|
|
return(0x00); |
404 |
|
|
|
405 |
|
|
UChar_t crcTof=0x00; |
406 |
|
|
UChar_t *pc=&crcTof, *pc2; |
407 |
|
|
pc2=pTof; |
408 |
|
|
for (Int_t jp=0; jp < 23; jp++){ |
409 |
|
|
//crcTof = crc8(...) |
410 |
|
|
Crc8Tof(pc2++,pc); |
411 |
|
|
// printf("%2i --- %x\n",jp,crcTof); |
412 |
|
|
} |
413 |
|
|
return(crcTof); |
414 |
|
|
} |
415 |
|
|
|
416 |
|
|
UChar_t Digitizer::EvaluateCrcTrigger(UChar_t *pTrg, Int_t nb) { |
417 |
|
|
Bool_t DEBUG=false; |
418 |
|
|
if (DEBUG) |
419 |
|
|
return(0x00); |
420 |
|
|
|
421 |
|
|
UChar_t crcTrg=0x00; |
422 |
|
|
UChar_t *pc=&crcTrg, *pc2; |
423 |
|
|
pc2=pTrg; |
424 |
|
|
for (Int_t jp=0; jp < nb; jp++) |
425 |
|
|
Crc8Tof(pc2++,pc); |
426 |
|
|
return(crcTrg); |
427 |
|
|
} |
428 |
|
|
|
429 |
|
|
void Digitizer::Crc8Tof(UChar_t *oldCRC, UChar_t *crcTof){ |
430 |
|
|
union crctof_data { |
431 |
|
|
UChar_t word; |
432 |
|
|
struct bit_field { |
433 |
|
|
unsigned b0:1; |
434 |
|
|
unsigned b1:1; |
435 |
|
|
unsigned b2:1; |
436 |
|
|
unsigned b3:1; |
437 |
|
|
unsigned b4:1; |
438 |
|
|
unsigned b5:1; |
439 |
|
|
unsigned b6:1; |
440 |
|
|
unsigned b7:1; |
441 |
|
|
} bit; |
442 |
|
|
} c,d,r; |
443 |
|
|
|
444 |
|
|
c.word = *oldCRC; |
445 |
|
|
//d.word = *newCRC; |
446 |
|
|
d.word = *crcTof; |
447 |
|
|
r.word = 0; |
448 |
|
|
|
449 |
|
|
r.bit.b0 = c.bit.b7 ^ c.bit.b6 ^ c.bit.b0 ^ |
450 |
|
|
d.bit.b0 ^ d.bit.b6 ^ d.bit.b7; |
451 |
|
|
|
452 |
|
|
r.bit.b1 = c.bit.b6 ^ c.bit.b1 ^ c.bit.b0 ^ |
453 |
|
|
d.bit.b0 ^ d.bit.b1 ^ d.bit.b6; |
454 |
|
|
|
455 |
|
|
r.bit.b2 = c.bit.b6 ^ c.bit.b2 ^ c.bit.b1 ^ c.bit.b0 ^ |
456 |
|
|
d.bit.b0 ^ d.bit.b1 ^ d.bit.b2 ^ d.bit.b6; |
457 |
|
|
|
458 |
|
|
r.bit.b3 = c.bit.b7 ^ c.bit.b3 ^ c.bit.b2 ^ c.bit.b1 ^ |
459 |
|
|
d.bit.b1 ^ d.bit.b2 ^ d.bit.b3 ^ d.bit.b7; |
460 |
|
|
|
461 |
|
|
r.bit.b4 = c.bit.b4 ^ c.bit.b3 ^ c.bit.b2 ^ |
462 |
|
|
d.bit.b2 ^ d.bit.b3 ^ d.bit.b4; |
463 |
|
|
|
464 |
|
|
r.bit.b5 = c.bit.b5 ^ c.bit.b4 ^ c.bit.b3 ^ |
465 |
|
|
d.bit.b3 ^ d.bit.b4 ^ d.bit.b5; |
466 |
|
|
|
467 |
|
|
r.bit.b6 = c.bit.b6 ^ c.bit.b5 ^ c.bit.b4 ^ |
468 |
|
|
d.bit.b4 ^ d.bit.b5 ^ d.bit.b6; |
469 |
|
|
|
470 |
|
|
r.bit.b7 = c.bit.b7 ^ c.bit.b6 ^ c.bit.b5 ^ |
471 |
|
|
d.bit.b5 ^ d.bit.b6 ^ d.bit.b7 ; |
472 |
|
|
|
473 |
|
|
*crcTof=r.word; |
474 |
|
|
//return r.word; |
475 |
|
|
}; |
476 |
|
|
|
477 |
|
|
//void Digitizer::Paddle2Pmt(Int_t plane, Int_t paddle, Int_t* &pmtleft, Int_t* &pmtright){ |
478 |
|
|
void Digitizer::Paddle2Pmt(Int_t plane, Int_t paddle, Int_t *pl, Int_t *pr){ |
479 |
|
|
//* @param plane (0 - 5) |
480 |
|
|
//* @param paddle (plane=0, paddle = 0,...5) |
481 |
|
|
//* @param padid (0 - 23) |
482 |
|
|
// |
483 |
|
|
Int_t padid=-1; |
484 |
|
|
Int_t pads[6]={8,6,2,2,3,3}; |
485 |
|
|
// |
486 |
|
|
Int_t somma=0; |
487 |
|
|
Int_t np=plane; |
488 |
|
|
for(Int_t j=0; j<np; j++) |
489 |
|
|
somma+=pads[j]; |
490 |
|
|
padid=paddle+somma; |
491 |
|
|
*pl = padid*2; |
492 |
|
|
// *pr = *pr + 1; |
493 |
|
|
*pr = *pl + 1; // WM |
494 |
|
|
}; |
495 |
|
|
|
496 |
|
|
void Digitizer::LoadTOFCalib(int np,float *atte1,float *atte2,float *lambda1,float *lambda2){ |
497 |
|
|
stringstream calfile; |
498 |
|
|
Int_t error = 0,temp=0; |
499 |
|
|
GL_PARAM *glparam = new GL_PARAM(); |
500 |
|
|
error = glparam->Query_GL_PARAM(3,202,fDbc); |
501 |
|
|
calfile.str(""); |
502 |
|
|
calfile << glparam->PATH.Data() << "/"; |
503 |
|
|
calfile << glparam->NAME.Data(); |
504 |
|
|
printf("\n Using TOF calibration file: \n %s\n",calfile.str().c_str()); |
505 |
|
|
ifstream fileTriggerCalib; |
506 |
|
|
fileTriggerCalib.open(calfile.str().c_str()); |
507 |
|
|
if(!fileTriggerCalib)printf("debug: no trigger calib file!\n"); |
508 |
|
|
// correct readout WM Oct '07 |
509 |
|
|
for(Int_t i=0; i<np; i++){ |
510 |
|
|
fileTriggerCalib >> temp; |
511 |
|
|
fileTriggerCalib >> atte1[i]; |
512 |
|
|
fileTriggerCalib >> lambda1[i]; |
513 |
|
|
fileTriggerCalib >> atte2[i]; |
514 |
|
|
fileTriggerCalib >> lambda2[i]; |
515 |
|
|
fileTriggerCalib >> temp; |
516 |
|
|
} |
517 |
|
|
fileTriggerCalib.close(); |
518 |
|
|
//end tof calib |
519 |
|
|
} |