2 |
#include <ToFLevel2.h> |
#include <ToFLevel2.h> |
3 |
#include <iostream> |
#include <iostream> |
4 |
using namespace std; |
using namespace std; |
5 |
|
ClassImp(ToFPMT); |
6 |
ClassImp(ToFTrkVar); |
ClassImp(ToFTrkVar); |
7 |
ClassImp(ToFLevel2); |
ClassImp(ToFLevel2); |
8 |
|
|
9 |
ToFTrkVar::ToFTrkVar() { |
ToFPMT::ToFPMT(){ |
10 |
|
pmt_id = 0; |
11 |
|
adc = 0.; |
12 |
|
tdc_tw = 0.; |
13 |
|
} |
14 |
|
|
15 |
trkseqno = 0; |
ToFPMT::ToFPMT(const ToFPMT &t){ |
16 |
|
pmt_id = t.pmt_id; |
17 |
|
adc = t.adc; |
18 |
|
tdc_tw = t.tdc_tw; |
19 |
|
} |
20 |
|
|
21 |
for (Int_t kk=0; kk<13;kk++){ |
void ToFPMT::Clear(){ |
22 |
beta_a[kk] = 0; |
pmt_id = 0; |
23 |
} |
adc = 0.; |
24 |
|
tdc_tw = 0.; |
|
for (Int_t kk=0; kk<4;kk++){ |
|
|
for (Int_t hh=0; hh<12;hh++){ |
|
|
adc_c[hh][kk] = 0; |
|
|
} |
|
|
} |
|
25 |
} |
} |
26 |
|
|
|
ToFTrkVar::ToFTrkVar(const ToFTrkVar &t){ |
|
27 |
|
|
|
trkseqno = t.trkseqno; |
|
28 |
|
|
29 |
memcpy(adc_c,t.adc_c,sizeof(adc_c)); |
ToFTrkVar::ToFTrkVar() { |
30 |
memcpy(beta_a,t.beta_a,sizeof(beta_a)); |
trkseqno = 0; |
31 |
} |
npmttdc = 0; |
32 |
|
npmtadc = 0; |
33 |
|
pmttdc = TArrayI(48); |
34 |
|
pmtadc = TArrayI(48); |
35 |
|
tdcflag = TArrayI(48); // gf: 30 Nov 2006 |
36 |
|
adcflag = TArrayI(48); // gf: 30 Nov 2006 |
37 |
|
dedx = TArrayF(48); |
38 |
|
// |
39 |
|
// |
40 |
|
memset(beta, 0, 13*sizeof(Float_t)); |
41 |
|
memset(xtofpos, 0, 3*sizeof(Float_t)); |
42 |
|
memset(ytofpos, 0, 3*sizeof(Float_t)); |
43 |
|
// |
44 |
|
}; |
45 |
|
|
46 |
ToFLevel2::ToFLevel2() { |
void ToFTrkVar::Clear() { |
47 |
|
trkseqno = 0; |
48 |
|
npmttdc = 0; |
49 |
|
npmtadc = 0; |
50 |
|
pmttdc.Reset(); |
51 |
|
pmtadc.Reset(); |
52 |
|
tdcflag.Reset(); // gf: 30 Nov 2006 |
53 |
|
adcflag.Reset(); // gf: 30 Nov 2006 |
54 |
|
dedx.Reset(); |
55 |
// |
// |
56 |
ToFTrk = new TClonesArray("ToFTrkVar",1); |
memset(beta, 0, 13*sizeof(Float_t)); |
57 |
|
memset(xtofpos, 0, 3*sizeof(Float_t)); |
58 |
|
memset(ytofpos, 0, 3*sizeof(Float_t)); |
59 |
// |
// |
60 |
for (Int_t kk=0; kk<3;kk++){ |
}; |
|
xtofpos[kk] = 0.; |
|
|
ytofpos[kk] = 0.; |
|
|
} |
|
61 |
|
|
62 |
for (Int_t kk=0; kk<6;kk++){ |
ToFTrkVar::ToFTrkVar(const ToFTrkVar &t){ |
|
tof_i_flag[kk] = 0; |
|
|
tof_j_flag[kk] = 0; |
|
|
} |
|
|
|
|
|
for (Int_t kk=0; kk<13;kk++){ |
|
|
betatof_a[kk] = 0; |
|
|
} |
|
63 |
|
|
64 |
for (Int_t kk=0; kk<4;kk++){ |
trkseqno = t.trkseqno; |
65 |
for (Int_t hh=0; hh<12;hh++){ |
// |
66 |
adctof_c[hh][kk] = 0; |
npmttdc = t.npmttdc; |
67 |
} |
npmtadc = t.npmtadc; |
68 |
} |
(t.pmttdc).Copy(pmttdc); |
69 |
|
(t.pmtadc).Copy(pmtadc); |
70 |
|
(t.tdcflag).Copy(tdcflag); // gf: 30 Nov 2006 |
71 |
|
(t.adcflag).Copy(adcflag); // gf: 30 Nov 2006 |
72 |
|
(t.dedx).Copy(dedx); |
73 |
|
// |
74 |
|
memcpy(beta,t.beta,sizeof(beta)); |
75 |
|
memcpy(xtofpos,t.xtofpos,sizeof(xtofpos)); |
76 |
|
memcpy(ytofpos,t.ytofpos,sizeof(ytofpos)); |
77 |
|
// |
78 |
|
}; |
79 |
|
|
80 |
for (Int_t kk=0; kk<4;kk++){ |
ToFLevel2::ToFLevel2() { |
81 |
for (Int_t hh=0; hh<12;hh++){ |
// |
82 |
tdc_c[hh][kk] = 0; |
// PMT = new TClonesArray("ToFPMT",12); //ELENA |
83 |
} |
// ToFTrk = new TClonesArray("ToFTrkVar",2); //ELENA |
84 |
} |
PMT = 0; //ELENA |
85 |
|
ToFTrk = 0; //ELENA |
86 |
|
// |
87 |
|
this->Clear(); |
88 |
|
// |
89 |
|
}; |
90 |
|
|
91 |
|
void ToFLevel2::Set(){//ELENA |
92 |
|
if(!PMT)PMT = new TClonesArray("ToFPMT",12); //ELENA |
93 |
|
if(!ToFTrk)ToFTrk = new TClonesArray("ToFTrkVar",2); //ELENA |
94 |
|
}//ELENA |
95 |
|
|
96 |
|
void ToFLevel2::Clear(){ |
97 |
|
// |
98 |
|
if(ToFTrk)ToFTrk->Delete(); //ELENA |
99 |
|
if(PMT)PMT->Delete(); //ELENA |
100 |
|
memset(tof_j_flag, 0, 6*sizeof(Int_t)); |
101 |
|
unpackError = 0; |
102 |
|
// |
103 |
}; |
}; |
104 |
|
|
105 |
|
void ToFLevel2::Delete(){ //ELENA |
106 |
|
// |
107 |
|
if(ToFTrk){ |
108 |
|
ToFTrk->Delete(); //ELENA |
109 |
|
delete ToFTrk; //ELENA |
110 |
|
} |
111 |
|
if(PMT){ |
112 |
|
PMT->Delete(); //ELENA |
113 |
|
delete PMT; //ELENA |
114 |
|
} //ELENA |
115 |
|
// |
116 |
|
}; //ELENA |
117 |
|
|
118 |
ToFTrkVar *ToFLevel2::GetToFTrkVar(Int_t itrk){ |
ToFTrkVar *ToFLevel2::GetToFTrkVar(Int_t itrk){ |
119 |
// |
// |
120 |
if(itrk >= ntrk()){ |
if(itrk >= ntrk()){ |
123 |
return(NULL); |
return(NULL); |
124 |
} |
} |
125 |
// |
// |
126 |
|
if(!ToFTrk)return 0; //ELENA |
127 |
TClonesArray &t = *(ToFTrk); |
TClonesArray &t = *(ToFTrk); |
128 |
ToFTrkVar *toftrack = (ToFTrkVar*)t[itrk]; |
ToFTrkVar *toftrack = (ToFTrkVar*)t[itrk]; |
129 |
return toftrack; |
return toftrack; |
130 |
} |
} |
131 |
|
|
132 |
|
ToFPMT *ToFLevel2::GetToFPMT(Int_t ihit){ |
133 |
|
// |
134 |
|
if(ihit >= npmt()){ |
135 |
|
printf(" ToFLevel2 ERROR: pmt variables set %i does not exists! \n",ihit); |
136 |
|
printf(" stored pmt variables = %i \n",npmt()); |
137 |
|
return(NULL); |
138 |
|
} |
139 |
|
// |
140 |
|
if(!PMT)return 0; //ELENA |
141 |
|
TClonesArray &t = *(PMT); |
142 |
|
ToFPMT *tofpmt = (ToFPMT*)t[ihit]; |
143 |
|
return tofpmt; |
144 |
|
} |
145 |
//-------------------------------------- |
//-------------------------------------- |
146 |
// |
// |
147 |
// |
// |
148 |
//-------------------------------------- |
//-------------------------------------- |
149 |
/** |
/** |
150 |
* Method to get the paddle ID (11 12 21 22 31 32) from the paddle index (0 1 2 3 4 5) |
* Method to get the plane ID (11 12 21 22 31 32) from the plane index (0 1 2 3 4 5) |
151 |
*/ |
*/ |
152 |
Int_t ToFLevel2::GetToFPlaneID(Int_t ip){ |
Int_t ToFLevel2::GetToFPlaneID(Int_t ip){ |
153 |
if(ip>=0 && ip<6)return 10*((int)(ip/2+1.1))+(ip%2)+1; |
if(ip>=0 && ip<6)return 10*((int)(ip/2+1.1))+(ip%2)+1; |
154 |
else return -1; |
else return -1; |
155 |
}; |
}; |
156 |
/** |
/** |
157 |
* Method to get the paddle index (0 1 2 3 4 5) from the paddle ID (11 12 21 22 31 32) |
* Method to get the plane index (0 1 2 3 4 5) from the plane ID (11 12 21 22 31 32) |
158 |
*/ |
*/ |
159 |
Int_t ToFLevel2::GetToFPlaneIndex(Int_t plane_id){ |
Int_t ToFLevel2::GetToFPlaneIndex(Int_t plane_id){ |
160 |
if( |
if( |
168 |
else return -1; |
else return -1; |
169 |
}; |
}; |
170 |
/** |
/** |
171 |
* Method to know if a given ToF paddle was hit, that is there is a TDC signal from both PMTs |
* Method to know if a given ToF paddle was hit, that is there is a TDC signal |
172 |
|
* from both PMTs |
173 |
* @param plane Plane ID (11, 12, 21, 22, 31, 32) or Plane index (0,1,2,3,4,5). |
* @param plane Plane ID (11, 12, 21, 22, 31, 32) or Plane index (0,1,2,3,4,5). |
174 |
* @param paddle_id Paddle ID. |
* @param paddle_id Paddle ID. |
175 |
* @return 1 if the paddle was hit. |
* @return 1 if the paddle was hit. |
199 |
for(Int_t i=0; i<8; i++)npad = npad + (int)HitPaddle(plane,i); |
for(Int_t i=0; i<8; i++)npad = npad + (int)HitPaddle(plane,i); |
200 |
return npad; |
return npad; |
201 |
}; |
}; |
202 |
|
|
203 |
|
|
204 |
|
Float_t ToFLevel2::GetdEdx(Int_t notrack, Int_t plane){ |
205 |
|
|
206 |
|
Float_t dedx = 0.; |
207 |
|
Int_t ip = 0; |
208 |
|
Int_t pmt_id = 0; |
209 |
|
Int_t pl = 0; |
210 |
|
if ( plane >= 6 ){ |
211 |
|
ip = GetToFPlaneIndex(plane); |
212 |
|
} else { |
213 |
|
ip = plane; |
214 |
|
}; |
215 |
|
// |
216 |
|
ToFTrkVar *trk = GetToFTrkVar(notrack); |
217 |
|
if(!trk) return 0; //ELENA |
218 |
|
// |
219 |
|
for (Int_t i=0; i<trk->npmtadc; i++){ |
220 |
|
// |
221 |
|
pmt_id = (trk->pmtadc).At(i); |
222 |
|
// |
223 |
|
pl = GetPlaneIndex(pmt_id); |
224 |
|
// |
225 |
|
if ( pl == ip ){ |
226 |
|
// // --- patch --- |
227 |
|
// bool ISNULL=false; |
228 |
|
// for(Int_t im=0; im< this->npmt(); im++){ |
229 |
|
// if(this->GetToFPMT(im)->pmt_id == pmt_id && this->GetToFPMT(im)->adc == 4095){ |
230 |
|
// cout << " ToFLevel2::GetdEdx(Int_t,Int_t) --> **warning** ADC(PMT="<<pmt_id<<") = 4095"<<endl; |
231 |
|
// ISNULL=true; |
232 |
|
// } |
233 |
|
// } |
234 |
|
// // --- patch --- |
235 |
|
// dedx += (trk->dedx).At(i)*(Int_t)(!ISNULL); |
236 |
|
dedx += (trk->dedx).At(i); |
237 |
|
} |
238 |
|
// |
239 |
|
}; |
240 |
|
// |
241 |
|
return(dedx); |
242 |
|
}; |
243 |
|
|
244 |
|
|
245 |
|
void ToFLevel2::GetMatrix(Int_t notrack, Float_t adc[4][12], Float_t tdc[4][12]){ |
246 |
|
// |
247 |
|
for (Int_t aa=0; aa<4;aa++){ |
248 |
|
for (Int_t bb=0; bb<12;bb++){ |
249 |
|
adc[aa][bb] = 1000.; |
250 |
|
tdc[aa][bb] = 4095.; |
251 |
|
}; |
252 |
|
}; |
253 |
|
// |
254 |
|
Int_t pmt_id = 0; |
255 |
|
Int_t hh = 0; |
256 |
|
Int_t kk = 0; |
257 |
|
// |
258 |
|
ToFTrkVar *trk = GetToFTrkVar(notrack); |
259 |
|
if(!trk)return; //ELENA |
260 |
|
// |
261 |
|
for (Int_t i=0; i<trk->npmtadc; i++){ |
262 |
|
// |
263 |
|
pmt_id = (trk->pmtadc).At(i); |
264 |
|
// |
265 |
|
GetPMTIndex(pmt_id,hh,kk); |
266 |
|
adc[kk][hh] = (trk->dedx).At(i); |
267 |
|
// |
268 |
|
}; |
269 |
|
// |
270 |
|
for (Int_t i=0; i<npmt(); i++){ |
271 |
|
// |
272 |
|
ToFPMT *pmt = GetToFPMT(i); |
273 |
|
if(!pmt)break; //ELENA |
274 |
|
// |
275 |
|
GetPMTIndex(pmt->pmt_id,hh,kk); |
276 |
|
// |
277 |
|
tdc[kk][hh] = pmt->tdc_tw; |
278 |
|
// |
279 |
|
}; |
280 |
|
// |
281 |
|
return; |
282 |
|
}; |
283 |
|
|
284 |
|
|
285 |
|
|
286 |
|
Int_t ToFLevel2::GetPlaneIndex(Int_t pmt_id){ |
287 |
|
TString pmtname = GetPMTName(pmt_id); |
288 |
|
pmtname.Resize(3); |
289 |
|
if ( !strcmp(pmtname,"S11") ) return(0); |
290 |
|
if ( !strcmp(pmtname,"S12") ) return(1); |
291 |
|
if ( !strcmp(pmtname,"S21") ) return(2); |
292 |
|
if ( !strcmp(pmtname,"S22") ) return(3); |
293 |
|
if ( !strcmp(pmtname,"S31") ) return(4); |
294 |
|
if ( !strcmp(pmtname,"S32") ) return(5); |
295 |
|
return(-1); |
296 |
|
}; |
297 |
|
|
298 |
|
|
299 |
|
Int_t ToFLevel2::GetPMTid(Int_t hh, Int_t kk){ |
300 |
|
// |
301 |
|
short tof[4][24] = { |
302 |
|
{4, 4, 4, 4, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 2, 3, 3, 3, 3, 4}, |
303 |
|
{1, 3, 5, 7, 10, 12, 2, 4, 2, 4, 6, 8, 10, 12, 1, 5, 3, 9, 7, 9, 11, 1, 5, 9}, |
304 |
|
{2, 2, 2, 2, 1, 1, 1, 1, 4, 4, 4, 4, 4, 4, 2, 1, 2, 1, 2, 2, 2, 3, 3, 4}, |
305 |
|
{6, 8, 12, 10, 8, 6, 4, 2, 12, 10, 8, 6, 4, 2, 9, 7, 11, 11, 5, 3, 1, 3, 7, 11} |
306 |
|
}; |
307 |
|
// |
308 |
|
Int_t ind = 0; |
309 |
|
Int_t k = 0; |
310 |
|
while (k < 24){ |
311 |
|
Int_t j = 0; |
312 |
|
while (j < 2){ |
313 |
|
Int_t ch = tof[2*j][k] - 1; |
314 |
|
Int_t hb = tof[2*j + 1][k] - 1; |
315 |
|
/* tofEvent->tdc[ch][hb] */ |
316 |
|
if( ch == hh && hb == kk ){ |
317 |
|
ind = 2*k + j; |
318 |
|
break; |
319 |
|
}; |
320 |
|
j++; |
321 |
|
}; |
322 |
|
k++; |
323 |
|
}; |
324 |
|
return ind; |
325 |
|
}; |
326 |
|
|
327 |
|
TString ToFLevel2::GetPMTName(Int_t ind){ |
328 |
|
|
329 |
|
TString pmtname = " "; |
330 |
|
|
331 |
|
TString photoS[48] = { |
332 |
|
"S11_1A", "S11_1B", "S11_2A", "S11_2B", "S11_3A", "S11_3B", "S11_4A", "S11_4B", |
333 |
|
"S11_5A", "S11_5B", "S11_6A", "S11_6B", "S11_7A", "S11_7B", "S11_8A", "S11_8B", |
334 |
|
"S12_1A", "S12_1B", "S12_2A", "S12_2B", "S12_3A", "S12_3B", "S12_4A", "S12_4B", "S12_5A", "S12_5B", "S12_6A", "S12_6B", |
335 |
|
"S21_1A", "S21_1B", "S21_2A", "S21_2B", |
336 |
|
"S22_1A", "S22_1B", "S22_2A", "S22_2B", |
337 |
|
"S31_1A", "S31_1B", "S31_2A", "S31_2B", "S31_3A", "S31_3B", |
338 |
|
"S32_1A", "S32_1B", "S32_2A", "S32_2B", "S32_3A", "S32_3B" |
339 |
|
}; |
340 |
|
|
341 |
|
|
342 |
|
pmtname = photoS[ind].Data(); |
343 |
|
|
344 |
|
return pmtname; |
345 |
|
}; |
346 |
|
|
347 |
|
|
348 |
|
void ToFLevel2::GetPMTIndex(Int_t ind, Int_t &hb, Int_t &ch){ |
349 |
|
// |
350 |
|
short tof[4][24] = { |
351 |
|
{4, 4, 4, 4, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 2, 3, 3, 3, 3, 4}, |
352 |
|
{1, 3, 5, 7, 10, 12, 2, 4, 2, 4, 6, 8, 10, 12, 1, 5, 3, 9, 7, 9, 11, 1, 5, 9}, |
353 |
|
{2, 2, 2, 2, 1, 1, 1, 1, 4, 4, 4, 4, 4, 4, 2, 1, 2, 1, 2, 2, 2, 3, 3, 4}, |
354 |
|
{6, 8, 12, 10, 8, 6, 4, 2, 12, 10, 8, 6, 4, 2, 9, 7, 11, 11, 5, 3, 1, 3, 7, 11} |
355 |
|
}; |
356 |
|
// |
357 |
|
Int_t k = 0; |
358 |
|
while (k < 24){ |
359 |
|
Int_t j = 0; |
360 |
|
while (j < 2){ |
361 |
|
/* tofEvent->tdc[ch][hb] */ |
362 |
|
if( ind == 2*k + j ){ |
363 |
|
ch = tof[2*j][k] - 1; |
364 |
|
hb = tof[2*j + 1][k] - 1; |
365 |
|
return; |
366 |
|
}; |
367 |
|
j++; |
368 |
|
}; |
369 |
|
k++; |
370 |
|
}; |
371 |
|
return; |
372 |
|
}; |
373 |
|
|
374 |
|
/** |
375 |
|
* Fills a struct cToFLevel2 with values from a ToFLevel2 object (to put data into a F77 common). |
376 |
|
*/ |
377 |
|
void ToFLevel2::GetLevel2Struct(cToFLevel2 *l2) const{ |
378 |
|
|
379 |
|
for(Int_t i=0;i<6;i++) |
380 |
|
l2->tof_j_flag[i]=tof_j_flag[i]; |
381 |
|
|
382 |
|
if(ToFTrk){ //ELENA |
383 |
|
l2->ntoftrk = ToFTrk->GetEntries(); |
384 |
|
for(Int_t j=0;j<l2->ntoftrk;j++){ |
385 |
|
l2->toftrkseqno[j]= ((ToFTrkVar*)ToFTrk->At(j))->trkseqno; |
386 |
|
l2->npmttdc[j]= ((ToFTrkVar*)ToFTrk->At(j))->npmttdc; |
387 |
|
for(Int_t i=0;i<l2->npmttdc[j];i++){ |
388 |
|
l2->pmttdc[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->pmttdc.At(i); |
389 |
|
l2->tdcflag[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->tdcflag.At(i); // gf: 30 Nov 2006 |
390 |
|
} |
391 |
|
for(Int_t i=0;i<13;i++) |
392 |
|
l2->beta[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->beta[i]; |
393 |
|
|
394 |
|
l2->npmtadc[j]= ((ToFTrkVar*)ToFTrk->At(j))->npmtadc; |
395 |
|
for(Int_t i=0;i<l2->npmtadc[j];i++){ |
396 |
|
l2->pmtadc[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->pmtadc.At(i); |
397 |
|
l2->adcflag[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->adcflag.At(i); // gf: 30 Nov 2006 |
398 |
|
l2->dedx[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->dedx.At(i); |
399 |
|
} |
400 |
|
for(Int_t i=0;i<3;i++){ |
401 |
|
l2->xtofpos[i][j]=((ToFTrkVar*)ToFTrk->At(j))->xtofpos[i]; |
402 |
|
l2->ytofpos[i][j]=((ToFTrkVar*)ToFTrk->At(j))->ytofpos[i]; |
403 |
|
} |
404 |
|
} |
405 |
|
} //ELENA |
406 |
|
|
407 |
|
if(PMT){ //ELENA |
408 |
|
l2->npmt = PMT->GetEntries(); |
409 |
|
for(Int_t j=0;j<l2->npmt;j++){ |
410 |
|
l2->pmt_id[j] = ((ToFPMT*)PMT->At(j))->pmt_id; |
411 |
|
l2->adc[j] =((ToFPMT*)PMT->At(j))->adc; |
412 |
|
l2->tdc_tw[j] =((ToFPMT*)PMT->At(j))->tdc_tw; |
413 |
|
} |
414 |
|
} //ELENA |
415 |
|
} |