/[PAMELA software]/DarthVader/ToFLevel2/src/ToFLevel2.cpp
ViewVC logotype

Contents of /DarthVader/ToFLevel2/src/ToFLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.41 - (show annotations) (download)
Tue Oct 14 14:07:36 2014 UTC (10 years, 4 months ago) by mocchiut
Branch: MAIN
Changes since 1.40: +2 -1 lines
10RED: lost sync bug fixed

1 /**
2 * \file ToFLevel2.cpp
3 * \author Gianfranca DeRosa, Wolfgang Menn
4 *
5 * WM dec 2008: Description of "GetdEdx" changed
6 * WM dec 2008: "GetdEdxPaddle" modified: Now includes saturation limit
7 * PMTs higher than the saturation limit are not used for dEdx
8 * WM apr 2009: bug found by Nicola in method "GetPaddlePlane"
9 */
10
11 #include <ToFLevel2.h>
12 using namespace std;
13 ClassImp(ToFPMT);
14 ClassImp(ToFdEdx);
15 ClassImp(ToFGeom);
16 ClassImp(ToFTrkVar);
17 ClassImp(ToFLevel2);
18
19 ToFPMT::ToFPMT(){
20 pmt_id = 0;
21 adc = 0.;
22 tdc_tw = 0.;
23 tdc = 0.;
24 l0flag_adc = 0.;
25 l0flag_tdc = 0.;
26 }
27
28 ToFPMT::ToFPMT(const ToFPMT &t){
29 pmt_id = t.pmt_id;
30 adc = t.adc;
31 tdc_tw = t.tdc_tw;
32 tdc = t.tdc;
33 }
34
35 void ToFPMT::Clear(Option_t *t){
36 pmt_id = 0;
37 adc = 0.;
38 tdc_tw = 0.;
39 tdc = 0.;
40 }
41
42
43
44 ToFTrkVar::ToFTrkVar() {
45 trkseqno = 0;
46 npmttdc = 0;
47 npmtadc = 0;
48 pmttdc = TArrayI(48);
49 pmtadc = TArrayI(48);
50 tdcflag = TArrayI(48); // gf: 30 Nov 2006
51 adcflag = TArrayI(48); // gf: 30 Nov 2006
52 dedx = TArrayF(48);
53 //
54 //
55 memset(beta, 0, 13*sizeof(Float_t));
56 memset(xtofpos, 0, 3*sizeof(Float_t));
57 memset(ytofpos, 0, 3*sizeof(Float_t));
58 memset(xtr_tof, 0, 6*sizeof(Float_t));
59 memset(ytr_tof, 0, 6*sizeof(Float_t));
60 //
61 };
62
63 void ToFTrkVar::Clear(Option_t *t) {
64 trkseqno = 0;
65 npmttdc = 0;
66 npmtadc = 0;
67 pmttdc.Reset();
68 pmtadc.Reset();
69 tdcflag.Reset(); // gf: 30 Nov 2006
70 adcflag.Reset(); // gf: 30 Nov 2006
71 dedx.Reset();
72 //
73 memset(beta, 0, 13*sizeof(Float_t));
74 memset(xtofpos, 0, 3*sizeof(Float_t));
75 memset(ytofpos, 0, 3*sizeof(Float_t));
76 memset(xtr_tof, 0, 6*sizeof(Float_t));
77 memset(ytr_tof, 0, 6*sizeof(Float_t));
78 //
79 };
80
81 ToFTrkVar::ToFTrkVar(const ToFTrkVar &t){
82
83 trkseqno = t.trkseqno;
84 //
85 npmttdc = t.npmttdc;
86 npmtadc = t.npmtadc;
87 (t.pmttdc).Copy(pmttdc);
88 (t.pmtadc).Copy(pmtadc);
89 (t.tdcflag).Copy(tdcflag); // gf: 30 Nov 2006
90 (t.adcflag).Copy(adcflag); // gf: 30 Nov 2006
91 (t.dedx).Copy(dedx);
92 //
93 memcpy(beta,t.beta,sizeof(beta));
94 memcpy(xtofpos,t.xtofpos,sizeof(xtofpos));
95 memcpy(ytofpos,t.ytofpos,sizeof(ytofpos));
96 memcpy(xtr_tof,t.xtr_tof,sizeof(xtr_tof));
97 memcpy(ytr_tof,t.ytr_tof,sizeof(ytr_tof));
98 //
99 };
100
101 ToFLevel2::ToFLevel2() {
102 //
103 // PMT = new TClonesArray("ToFPMT",12); //ELENA
104 // ToFTrk = new TClonesArray("ToFTrkVar",2); //ELENA
105 PMT = 0; //ELENA
106 ToFTrk = 0; //ELENA
107 //
108 this->Clear();
109 //
110 };
111
112 void ToFLevel2::Set(){//ELENA
113 if(!PMT)PMT = new TClonesArray("ToFPMT",12); //ELENA
114 if(!ToFTrk)ToFTrk = new TClonesArray("ToFTrkVar",2); //ELENA
115 }//ELENA
116
117 void ToFLevel2::Clear(Option_t *t){
118 //
119 if(ToFTrk)ToFTrk->Delete(); //ELENA
120 if(PMT)PMT->Delete(); //ELENA
121 memset(tof_j_flag, 0, 6*sizeof(Int_t));
122 unpackError = 0;
123 unpackWarning = 0;
124 //
125 };
126
127 void ToFLevel2::Delete(Option_t *t){ //ELENA
128 //
129 if(ToFTrk){
130 ToFTrk->Delete(); //ELENA
131 delete ToFTrk; //ELENA
132 }
133 if(PMT){
134 PMT->Delete(); //ELENA
135 delete PMT; //ELENA
136 } //ELENA
137 //
138 }; //ELENA
139
140 ToFTrkVar *ToFLevel2::GetToFTrkVar(Int_t itrk){
141 //
142 if(itrk >= ntrk()){
143 printf(" ToFLevel2 ERROR: track related variables set %i does not exists! \n",itrk);
144 printf(" stored track related variables = %i \n",ntrk());
145 return(NULL);
146 }
147 //
148 if(!ToFTrk)return 0; //ELENA
149 TClonesArray &t = *(ToFTrk);
150 ToFTrkVar *toftrack = (ToFTrkVar*)t[itrk];
151 return toftrack;
152 }
153
154 ToFPMT *ToFLevel2::GetToFPMT(Int_t ihit){
155 //
156 if(ihit >= npmt()){
157 printf(" ToFLevel2 ERROR: pmt variables set %i does not exists! \n",ihit);
158 printf(" stored pmt variables = %i \n",npmt());
159 return(NULL);
160 }
161 //
162 if(!PMT)return 0; //ELENA
163 TClonesArray &t = *(PMT);
164 ToFPMT *tofpmt = (ToFPMT*)t[ihit];
165 return tofpmt;
166 }
167 //--------------------------------------
168 //
169 //
170 //--------------------------------------
171 /**
172 * Method to get the plane ID (11 12 21 22 31 32) from the plane index (0 1 2 3 4 5)
173 * @param Plane index (0,1,2,3,4,5).
174 */
175 Int_t ToFLevel2::GetToFPlaneID(Int_t ip){
176 if(ip>=0 && ip<6)return 10*((int)(ip/2+1.1))+(ip%2)+1;
177 else return -1;
178 };
179 /**
180 * Method to get the plane index (0 1 2 3 4 5) from the plane ID (11 12 21 22 31 32)
181 * @param plane Plane ID (11, 12, 21, 22, 31, 32)
182 */
183 Int_t ToFLevel2::GetToFPlaneIndex(Int_t plane_id){
184 if(
185 plane_id == 11 ||
186 plane_id == 12 ||
187 plane_id == 21 ||
188 plane_id == 22 ||
189 plane_id == 31 ||
190 plane_id == 32 ||
191 false)return (Int_t)(plane_id/10)*2-1- plane_id%2;
192 else return -1;
193 };
194 /**
195 * Method to know if a given ToF paddle was hit, that is there is a TDC signal
196 * from both PMTs. The method uses the "tof_j_flag" variable.
197 * @param plane Plane ID (11, 12, 21, 22, 31, 32) or Plane index (0,1,2,3,4,5).
198 * @param paddle_id Paddle ID.
199 * @return 1 if the paddle was hit.
200 */
201 Bool_t ToFLevel2::HitPaddle(Int_t plane, Int_t paddle_id){ //<<< NEW
202 Int_t ip = -1;
203 if (plane>=6 ) ip = GetToFPlaneIndex(plane);
204 else if(plane>=0 && plane < 6) ip = plane;
205 Int_t flag=0;
206 if(ip != -1)flag = tof_j_flag[ip] & (int)pow(2.,(double)paddle_id);
207 if(
208 (ip == 0 && paddle_id < 8 && flag) ||
209 (ip == 1 && paddle_id < 6 && flag) ||
210 (ip == 2 && paddle_id < 2 && flag) ||
211 (ip == 3 && paddle_id < 2 && flag) ||
212 (ip == 4 && paddle_id < 3 && flag) ||
213 (ip == 5 && paddle_id < 3 && flag) ||
214 false) return true;
215 else return false;
216 };
217 /**
218 * Method to get the number of hit paddles on a ToF plane.
219 * @param plane Plane ID (11, 12, 21, 22, 31, 32) or Plane index (0,1,2,3,4,5).
220 */
221 Int_t ToFLevel2::GetNHitPaddles(Int_t plane){
222 Int_t npad=0;
223 for(Int_t i=0; i<8; i++)npad = npad + (int)HitPaddle(plane,i);
224 return npad;
225 };
226
227 /**
228 * Method to get the number of hit paddles on a ToF plane.
229 * @param plane Plane ID (11, 12, 21, 22, 31, 32) or Plane index (0,1,2,3,4,5).
230 */
231 Int_t ToFLevel2::GetTrueNHitPaddles(Int_t plane){
232 Int_t npad=0;
233 TClonesArray* Pmt = this->PMT;
234 int paddle[24];
235 memset(paddle,0, 24*sizeof(int));
236 for(int i=0; i<Pmt->GetEntries(); i++) { //loop per vedere quale TOF è colpito
237 ToFPMT* pmthit = (ToFPMT*)Pmt->At(i);
238 int pplane = -1;
239 int ppaddle = -1;
240 GetPMTPaddle(pmthit->pmt_id,pplane,ppaddle);
241 if ( pplane == plane ) paddle[ppaddle]++;
242 }
243 for(int i=0;i<24;i++) if ( paddle[i]>0 ) npad++;
244
245 return npad;
246 };
247
248 //wm Nov 08
249 //gf Apr 07
250 /**
251 * Method to get the mean dEdx from a ToF layer - ATTENTION:
252 * It will sum up the dEdx of all the paddles, but since by definition
253 * only the paddle hitted by the track gets a dEdx value and the other
254 * paddles are set to zero, the output is just the dEdx of the hitted
255 * paddle in each layer!
256 * The "adcfl" option is not very useful (an artificial dEdx is per
257 * definition= 1 mip and not a real measurement), anyway left in the code
258 * @param notrack Track Number
259 * @param plane Plane index (0,1,2,3,4,5)
260 * @param adcflag in the plane (100<-> independent of the adcflag; !=0&&!=100 <-> at least one PMT with adcflag!=0; )
261 */
262 Float_t ToFLevel2::GetdEdx(ToFTrkVar *trk, Int_t plane, Int_t adcfl){
263 // printf("fiffi\n");
264 Float_t dedx = 0.;
265 Float_t PadEdx =0.;
266 Int_t SatWarning;
267 Int_t pad=-1;
268 //
269 if(!trk) return 0; //ELENA
270 //
271 if ( trk->trkseqno == -1 ){ //standalone, only paddles along the track, or about...
272 // printf("ciccio\n");
273 Float_t xleft=0;
274 Float_t xright=0;
275 Float_t yleft=0;
276 Float_t yright=0;
277 Float_t xtof_temp[6]={100.,100.,100.,100.,100.,100.};
278 Float_t ytof_temp[6]={100.,100.,100.,100.,100.,100.};
279 ToFTrkVar *t_tof = trk;
280
281 xtof_temp[0]=t_tof->xtofpos[0];
282 ytof_temp[0]=t_tof->ytofpos[0];
283 xtof_temp[1]=t_tof->xtofpos[0];
284 ytof_temp[1]=t_tof->ytofpos[0];
285
286 xtof_temp[2]=t_tof->xtofpos[1];
287 ytof_temp[2]=t_tof->ytofpos[1];
288 xtof_temp[3]=t_tof->xtofpos[1];
289 ytof_temp[3]=t_tof->ytofpos[1];
290
291 xtof_temp[4]=t_tof->xtofpos[2];
292 ytof_temp[4]=t_tof->ytofpos[2];
293 xtof_temp[5]=t_tof->xtofpos[2];
294 ytof_temp[5]=t_tof->ytofpos[2];
295
296 if(t_tof->xtofpos[0]<100. && t_tof->ytofpos[0]<100.){
297 xtof_temp[1]=t_tof->xtofpos[0];
298 ytof_temp[0]=t_tof->ytofpos[0];
299 }else if(t_tof->xtofpos[0]>=100. && t_tof->ytofpos[0]<100.){
300 ytof_temp[0]=t_tof->ytofpos[0];
301 this->GetPaddleGeometry(0,(Int_t)log2(this->tof_j_flag[0]),xleft, xright, yleft, yright);
302 xtof_temp[1]=xleft+2.55;
303 }else if(t_tof->ytofpos[0]>=100. && t_tof->xtofpos[0]<100.){
304 xtof_temp[1]=t_tof->xtofpos[0];
305 this->GetPaddleGeometry(1,(Int_t)log2(this->tof_j_flag[1]),xleft, xright, yleft, yright);
306 ytof_temp[0]=yleft+2.75;
307 }
308
309 if(t_tof->xtofpos[1]<100. && t_tof->ytofpos[1]<100.){
310 xtof_temp[2]=t_tof->xtofpos[1];
311 ytof_temp[3]=t_tof->ytofpos[1];
312 }else if(t_tof->xtofpos[1]>=100. && t_tof->ytofpos[1]<100.){
313 ytof_temp[3]=t_tof->ytofpos[1];
314 this->GetPaddleGeometry(3,(Int_t)log2(this->tof_j_flag[3]),xleft, xright, yleft, yright);
315 xtof_temp[2]=xleft+4.5;
316 }else if(t_tof->ytofpos[1]>=100. && t_tof->xtofpos[1]<100.){
317 xtof_temp[2]=t_tof->xtofpos[1];
318 this->GetPaddleGeometry(2,(Int_t)log2(this->tof_j_flag[2]),xleft, xright, yleft, yright);
319 ytof_temp[3]=yleft+3.75;
320 }
321
322 if(t_tof->xtofpos[2]<100. && t_tof->ytofpos[2]<100.){
323 xtof_temp[5]=t_tof->xtofpos[2];
324 ytof_temp[4]=t_tof->ytofpos[2];
325 }else if(t_tof->xtofpos[2]>=100. && t_tof->ytofpos[2]<100.){
326 ytof_temp[4]=t_tof->ytofpos[2];
327 this->GetPaddleGeometry(4,(Int_t)log2(this->tof_j_flag[4]),xleft, xright, yleft, yright);
328 xtof_temp[5]=xleft+3;
329 }else if(t_tof->ytofpos[2]>=100. && t_tof->xtofpos[2]<100.){
330 xtof_temp[5]=t_tof->xtofpos[2];
331 this->GetPaddleGeometry(5,(Int_t)log2(this->tof_j_flag[5]),xleft, xright, yleft, yright);
332 ytof_temp[4]=yleft+2.5;
333 }
334
335 if ( (xtof_temp[0])> 17.85 && fabs(xtof_temp[0])<17.85+4. ) xtof_temp[0] =17.84;
336 if ( (xtof_temp[1])> 17.85 && fabs(xtof_temp[1])<17.85+4. ) xtof_temp[1] =17.84;
337 if ( (ytof_temp[0])> 13.75 && fabs(ytof_temp[0])<13.75+4. ) ytof_temp[0] =13.74;
338 if ( (ytof_temp[1])> 13.75 && fabs(ytof_temp[1])<13.75+4. ) ytof_temp[1] =13.74;
339 if ( (xtof_temp[0])< -17.85 && fabs(xtof_temp[0])>-(17.85+4.) ) xtof_temp[0] =-17.84;
340 if ( (xtof_temp[1])< -17.85 && fabs(xtof_temp[1])>-(17.85+4.) ) xtof_temp[1] =-17.84;
341 if ( (ytof_temp[0])< -13.75 && fabs(ytof_temp[0])>-(13.75+4.) ) ytof_temp[0] =-13.74;
342 if ( (ytof_temp[1])< -13.75 && fabs(ytof_temp[1])>-(13.75+4.) ) ytof_temp[1] =-13.74;
343
344 if ( (xtof_temp[2])> 4.5 && (xtof_temp[2])<4.5+4. ) xtof_temp[2] =4.4;
345 if ( (xtof_temp[3])> 4.45 && (xtof_temp[3])<4.5+4. ) xtof_temp[3] =4.4;
346 if ( (ytof_temp[2])> 3.75 && (ytof_temp[2])<3.75+4. ) ytof_temp[2] =3.74;
347 if ( (ytof_temp[3])> 3.75 && (ytof_temp[3])<3.75+4. ) ytof_temp[3] =3.74;
348 if ( (xtof_temp[2])< -4.5 && (xtof_temp[2])>-(4.5+4.) ) xtof_temp[2] =-4.4;
349 if ( (xtof_temp[3])< -4.45 && (xtof_temp[3])>-(4.5+4.) ) xtof_temp[3] =-4.4;
350 if ( (ytof_temp[2])< -3.75 && (ytof_temp[2])>-(3.75+4.) ) ytof_temp[2] =-3.74;
351 if ( (ytof_temp[3])< -3.75 && (ytof_temp[3])>-(3.75+4.) ) ytof_temp[3] =-3.74;
352
353 if ( (xtof_temp[4])> 6. && (xtof_temp[4])<6.+4. ) xtof_temp[2] =5.9;
354 if ( (xtof_temp[5])> 6. && (xtof_temp[5])<6.+4. ) xtof_temp[3] =5.9;
355 if ( (ytof_temp[4])> 5. && (ytof_temp[4])<5.+4. ) ytof_temp[2] =4.9;
356 if ( (ytof_temp[5])> 5. && (ytof_temp[5])<5.+4. ) ytof_temp[3] =4.9;
357 if ( (xtof_temp[4])< -6. && (xtof_temp[4])>-(6.+4.) ) xtof_temp[2] =-5.9;
358 if ( (xtof_temp[5])< -6. && (xtof_temp[5])>-(6.+4.) ) xtof_temp[3] =-5.9;
359 if ( (ytof_temp[4])< -5. && (ytof_temp[4])>-(5.+4.) ) ytof_temp[2] =-4.9;
360 if ( (ytof_temp[5])< -5. && (ytof_temp[5])>-(5.+4.) ) ytof_temp[3] =-4.9;
361
362
363 for (Int_t ii=0; ii<GetNPaddle(plane); ii++){
364 Int_t paddleid=ii;
365 pad = GetPaddleid(plane,paddleid);
366 Int_t IpaddleT=-1;
367 IpaddleT=this->GetPaddleIdOfTrack(xtof_temp[plane],ytof_temp[plane], plane,0.0);
368 // printf("SSS %i %i %f %f %f %f \n",IpaddleT,paddleid,xtof_temp[plane],ytof_temp[plane],t_tof->xtofpos[plane],t_tof->ytofpos[plane]);
369 // if ( IpaddleT == paddleid || IpaddleT-1 == paddleid || IpaddleT+1 == paddleid ){
370 if ( IpaddleT == paddleid || GetTrueNHitPaddles(plane) == 1 ){
371 //IpaddleT-1 == paddleid || IpaddleT+1 == paddleid ){
372 GetdEdxPaddle(trk, pad, adcfl, PadEdx, SatWarning);
373 dedx += PadEdx;
374 }
375 };
376 } else {
377 for (Int_t ii=0; ii<GetNPaddle(plane); ii++){
378 Int_t paddleid=ii;
379 pad = GetPaddleid(plane,paddleid);
380 GetdEdxPaddle(trk, pad, adcfl, PadEdx, SatWarning);
381 dedx += PadEdx;
382 // printf("TTT %i %i %f\n",paddleid,plane,PadEdx);
383 };
384 }
385 //
386 return(dedx);
387 };
388
389
390 //wm Nov 08
391 //gf Apr 07
392 /**
393 * Method to get the mean dEdx from a ToF layer - ATTENTION:
394 * It will sum up the dEdx of all the paddles, but since by definition
395 * only the paddle hitted by the track gets a dEdx value and the other
396 * paddles are set to zero, the output is just the dEdx of the hitted
397 * paddle in each layer!
398 * The "adcfl" option is not very useful (an artificial dEdx is per
399 * definition= 1 mip and not a real measurement), anyway left in the code
400 * @param notrack Track Number
401 * @param plane Plane index (0,1,2,3,4,5)
402 * @param adcflag in the plane (100<-> independent of the adcflag; !=0&&!=100 <-> at least one PMT with adcflag!=0; )
403 */
404 Float_t ToFLevel2::GetdEdx(Int_t notrack, Int_t plane, Int_t adcfl){
405 // printf("fiffi\n");
406 Float_t dedx = 0.;
407 Float_t PadEdx =0.;
408 Int_t SatWarning;
409 Int_t pad=-1;
410 //
411 ToFTrkVar *trk = GetToFTrkVar(notrack);
412 if(!trk) return 0; //ELENA
413 //
414 if ( trk->trkseqno == -1 ){ //standalone, only paddles along the track, or about...
415 // printf("ciccio\n");
416 Float_t xleft=0;
417 Float_t xright=0;
418 Float_t yleft=0;
419 Float_t yright=0;
420 Float_t xtof_temp[6]={100.,100.,100.,100.,100.,100.};
421 Float_t ytof_temp[6]={100.,100.,100.,100.,100.,100.};
422 ToFTrkVar *t_tof = trk;
423
424 xtof_temp[0]=t_tof->xtofpos[0];
425 ytof_temp[0]=t_tof->ytofpos[0];
426 xtof_temp[1]=t_tof->xtofpos[0];
427 ytof_temp[1]=t_tof->ytofpos[0];
428
429 xtof_temp[2]=t_tof->xtofpos[1];
430 ytof_temp[2]=t_tof->ytofpos[1];
431 xtof_temp[3]=t_tof->xtofpos[1];
432 ytof_temp[3]=t_tof->ytofpos[1];
433
434 xtof_temp[4]=t_tof->xtofpos[2];
435 ytof_temp[4]=t_tof->ytofpos[2];
436 xtof_temp[5]=t_tof->xtofpos[2];
437 ytof_temp[5]=t_tof->ytofpos[2];
438
439 if(t_tof->xtofpos[0]<100. && t_tof->ytofpos[0]<100.){
440 xtof_temp[1]=t_tof->xtofpos[0];
441 ytof_temp[0]=t_tof->ytofpos[0];
442 }else if(t_tof->xtofpos[0]>=100. && t_tof->ytofpos[0]<100.){
443 ytof_temp[0]=t_tof->ytofpos[0];
444 this->GetPaddleGeometry(0,(Int_t)log2(this->tof_j_flag[0]),xleft, xright, yleft, yright);
445 xtof_temp[1]=xleft+2.55;
446 }else if(t_tof->ytofpos[0]>=100. && t_tof->xtofpos[0]<100.){
447 xtof_temp[1]=t_tof->xtofpos[0];
448 this->GetPaddleGeometry(1,(Int_t)log2(this->tof_j_flag[1]),xleft, xright, yleft, yright);
449 ytof_temp[0]=yleft+2.75;
450 }
451
452 if(t_tof->xtofpos[1]<100. && t_tof->ytofpos[1]<100.){
453 xtof_temp[2]=t_tof->xtofpos[1];
454 ytof_temp[3]=t_tof->ytofpos[1];
455 }else if(t_tof->xtofpos[1]>=100. && t_tof->ytofpos[1]<100.){
456 ytof_temp[3]=t_tof->ytofpos[1];
457 this->GetPaddleGeometry(3,(Int_t)log2(this->tof_j_flag[3]),xleft, xright, yleft, yright);
458 xtof_temp[2]=xleft+4.5;
459 }else if(t_tof->ytofpos[1]>=100. && t_tof->xtofpos[1]<100.){
460 xtof_temp[2]=t_tof->xtofpos[1];
461 this->GetPaddleGeometry(2,(Int_t)log2(this->tof_j_flag[2]),xleft, xright, yleft, yright);
462 ytof_temp[3]=yleft+3.75;
463 }
464
465 if(t_tof->xtofpos[2]<100. && t_tof->ytofpos[2]<100.){
466 xtof_temp[5]=t_tof->xtofpos[2];
467 ytof_temp[4]=t_tof->ytofpos[2];
468 }else if(t_tof->xtofpos[2]>=100. && t_tof->ytofpos[2]<100.){
469 ytof_temp[4]=t_tof->ytofpos[2];
470 this->GetPaddleGeometry(4,(Int_t)log2(this->tof_j_flag[4]),xleft, xright, yleft, yright);
471 xtof_temp[5]=xleft+3;
472 }else if(t_tof->ytofpos[2]>=100. && t_tof->xtofpos[2]<100.){
473 xtof_temp[5]=t_tof->xtofpos[2];
474 this->GetPaddleGeometry(5,(Int_t)log2(this->tof_j_flag[5]),xleft, xright, yleft, yright);
475 ytof_temp[4]=yleft+2.5;
476 }
477
478 if ( (xtof_temp[0])> 17.85 && fabs(xtof_temp[0])<17.85+4. ) xtof_temp[0] =17.84;
479 if ( (xtof_temp[1])> 17.85 && fabs(xtof_temp[1])<17.85+4. ) xtof_temp[1] =17.84;
480 if ( (ytof_temp[0])> 13.75 && fabs(ytof_temp[0])<13.75+4. ) ytof_temp[0] =13.74;
481 if ( (ytof_temp[1])> 13.75 && fabs(ytof_temp[1])<13.75+4. ) ytof_temp[1] =13.74;
482 if ( (xtof_temp[0])< -17.85 && fabs(xtof_temp[0])>-(17.85+4.) ) xtof_temp[0] =-17.84;
483 if ( (xtof_temp[1])< -17.85 && fabs(xtof_temp[1])>-(17.85+4.) ) xtof_temp[1] =-17.84;
484 if ( (ytof_temp[0])< -13.75 && fabs(ytof_temp[0])>-(13.75+4.) ) ytof_temp[0] =-13.74;
485 if ( (ytof_temp[1])< -13.75 && fabs(ytof_temp[1])>-(13.75+4.) ) ytof_temp[1] =-13.74;
486
487 if ( (xtof_temp[2])> 4.5 && (xtof_temp[2])<4.5+4. ) xtof_temp[2] =4.4;
488 if ( (xtof_temp[3])> 4.45 && (xtof_temp[3])<4.5+4. ) xtof_temp[3] =4.4;
489 if ( (ytof_temp[2])> 3.75 && (ytof_temp[2])<3.75+4. ) ytof_temp[2] =3.74;
490 if ( (ytof_temp[3])> 3.75 && (ytof_temp[3])<3.75+4. ) ytof_temp[3] =3.74;
491 if ( (xtof_temp[2])< -4.5 && (xtof_temp[2])>-(4.5+4.) ) xtof_temp[2] =-4.4;
492 if ( (xtof_temp[3])< -4.45 && (xtof_temp[3])>-(4.5+4.) ) xtof_temp[3] =-4.4;
493 if ( (ytof_temp[2])< -3.75 && (ytof_temp[2])>-(3.75+4.) ) ytof_temp[2] =-3.74;
494 if ( (ytof_temp[3])< -3.75 && (ytof_temp[3])>-(3.75+4.) ) ytof_temp[3] =-3.74;
495
496 if ( (xtof_temp[4])> 6. && (xtof_temp[4])<6.+4. ) xtof_temp[2] =5.9;
497 if ( (xtof_temp[5])> 6. && (xtof_temp[5])<6.+4. ) xtof_temp[3] =5.9;
498 if ( (ytof_temp[4])> 5. && (ytof_temp[4])<5.+4. ) ytof_temp[2] =4.9;
499 if ( (ytof_temp[5])> 5. && (ytof_temp[5])<5.+4. ) ytof_temp[3] =4.9;
500 if ( (xtof_temp[4])< -6. && (xtof_temp[4])>-(6.+4.) ) xtof_temp[2] =-5.9;
501 if ( (xtof_temp[5])< -6. && (xtof_temp[5])>-(6.+4.) ) xtof_temp[3] =-5.9;
502 if ( (ytof_temp[4])< -5. && (ytof_temp[4])>-(5.+4.) ) ytof_temp[2] =-4.9;
503 if ( (ytof_temp[5])< -5. && (ytof_temp[5])>-(5.+4.) ) ytof_temp[3] =-4.9;
504
505
506 for (Int_t ii=0; ii<GetNPaddle(plane); ii++){
507 Int_t paddleid=ii;
508 pad = GetPaddleid(plane,paddleid);
509 Int_t IpaddleT=-1;
510 IpaddleT=this->GetPaddleIdOfTrack(xtof_temp[plane],ytof_temp[plane], plane,0.0);
511 // printf("SSS %i %i %f %f %f %f \n",IpaddleT,paddleid,xtof_temp[plane],ytof_temp[plane],t_tof->xtofpos[plane],t_tof->ytofpos[plane]);
512 // if ( IpaddleT == paddleid || IpaddleT-1 == paddleid || IpaddleT+1 == paddleid ){
513 if ( IpaddleT == paddleid || GetTrueNHitPaddles(plane) == 1 ){
514 //IpaddleT-1 == paddleid || IpaddleT+1 == paddleid ){
515 GetdEdxPaddle(notrack, pad, adcfl, PadEdx, SatWarning);
516 dedx += PadEdx;
517 }
518 };
519 } else {
520 for (Int_t ii=0; ii<GetNPaddle(plane); ii++){
521 Int_t paddleid=ii;
522 pad = GetPaddleid(plane,paddleid);
523 GetdEdxPaddle(notrack, pad, adcfl, PadEdx, SatWarning);
524 dedx += PadEdx;
525 // printf("TTT %i %i %f\n",paddleid,plane,PadEdx);
526 };
527 }
528 //
529 return(dedx);
530 };
531
532 /**
533 * Method to fill the ADC_C 4x12 matrix with the dEdx values and the TDC 4x12 matrix
534 * with the time-walk corrected TDC values.
535 * @param notrack Track Number
536 * @param adc ADC_C matrix with dEdx values
537 * @param tdc TDC matrix
538 */
539 void ToFLevel2::GetMatrix(Int_t notrack, Float_t adc[4][12], Float_t tdc[4][12]){
540 //
541 for (Int_t aa=0; aa<4;aa++){
542 for (Int_t bb=0; bb<12;bb++){
543 adc[aa][bb] = 1000.;
544 tdc[aa][bb] = 4095.;
545 };
546 };
547 //
548 Int_t pmt_id = 0;
549 Int_t hh = 0;
550 Int_t kk = 0;
551 //
552 ToFTrkVar *trk = GetToFTrkVar(notrack);
553 if(!trk)return; //ELENA
554 //
555 for (Int_t i=0; i<trk->npmtadc; i++){
556 //
557 pmt_id = (trk->pmtadc).At(i);
558 //
559 GetPMTIndex(pmt_id,hh,kk);
560 adc[kk][hh] = (trk->dedx).At(i);
561 //
562 };
563 //
564 for (Int_t i=0; i<npmt(); i++){
565 //
566 ToFPMT *pmt = GetToFPMT(i);
567 if(!pmt)break; //ELENA
568 //
569 GetPMTIndex(pmt->pmt_id,hh,kk);
570 //
571 tdc[kk][hh] = pmt->tdc_tw;
572 //
573 };
574 //
575 return;
576 };
577
578
579 /**
580 * Method to get the plane index (0 - 5) for the PMT_ID as input
581 * @param pmt_id PMT_ID (0 - 47)
582 */
583 Int_t ToFLevel2::GetPlaneIndex(Int_t pmt_id){
584 TString pmtname = GetPMTName(pmt_id);
585 pmtname.Resize(3);
586 if ( !strcmp(pmtname,"S11") ) return(0);
587 if ( !strcmp(pmtname,"S12") ) return(1);
588 if ( !strcmp(pmtname,"S21") ) return(2);
589 if ( !strcmp(pmtname,"S22") ) return(3);
590 if ( !strcmp(pmtname,"S31") ) return(4);
591 if ( !strcmp(pmtname,"S32") ) return(5);
592 return(-1);
593 };
594
595
596 /**
597 * Method to get the PMT_ID if the index (4,12) is given. We have 4 channels on
598 * each of the 12 half-boards, this method decodes which PMT is cables to which
599 * channel.
600 * @param hh Channel
601 * @param kk HalfBoard
602 */
603 Int_t ToFLevel2::GetPMTid(Int_t hh, Int_t kk){
604 //
605 short tof[4][24] = {
606 {4, 4, 4, 4, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 2, 3, 3, 3, 3, 4},
607 {1, 3, 5, 7, 10, 12, 2, 4, 2, 4, 6, 8, 10, 12, 1, 5, 3, 9, 7, 9, 11, 1, 5, 9},
608 {2, 2, 2, 2, 1, 1, 1, 1, 4, 4, 4, 4, 4, 4, 2, 1, 2, 1, 2, 2, 2, 3, 3, 4},
609 {6, 8, 12, 10, 8, 6, 4, 2, 12, 10, 8, 6, 4, 2, 9, 7, 11, 11, 5, 3, 1, 3, 7, 11}
610 };
611 //
612 Int_t ind = 0;
613 Int_t k = 0;
614 while (k < 24){
615 Int_t j = 0;
616 while (j < 2){
617 Int_t ch = tof[2*j][k] - 1;
618 Int_t hb = tof[2*j + 1][k] - 1;
619 /* tofEvent->tdc[ch][hb] */
620 if( ch == hh && hb == kk ){
621 ind = 2*k + j;
622 break;
623 };
624 j++;
625 };
626 k++;
627 };
628 return ind;
629 };
630
631
632 /**
633 * Method to get the PMT index if the PMT ID is given. This method is the
634 * "reverse" of method "GetPMTid"
635 * @param ind PMT_ID (0 - 47)
636 * @param hb HalfBoard
637 * @param ch Channel
638 */
639 void ToFLevel2::GetPMTIndex(Int_t ind, Int_t &hb, Int_t &ch){
640 //
641 short tof[4][24] = {
642 {4, 4, 4, 4, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 2, 3, 3, 3, 3, 4},
643 {1, 3, 5, 7, 10, 12, 2, 4, 2, 4, 6, 8, 10, 12, 1, 5, 3, 9, 7, 9, 11, 1, 5, 9},
644 {2, 2, 2, 2, 1, 1, 1, 1, 4, 4, 4, 4, 4, 4, 2, 1, 2, 1, 2, 2, 2, 3, 3, 4},
645 {6, 8, 12, 10, 8, 6, 4, 2, 12, 10, 8, 6, 4, 2, 9, 7, 11, 11, 5, 3, 1, 3, 7, 11}
646 };
647 //
648 Int_t k = 0;
649 while (k < 24){
650 Int_t j = 0;
651 while (j < 2){
652 /* tofEvent->tdc[ch][hb] */
653 if( ind == 2*k + j ){
654 ch = tof[2*j][k] - 1;
655 hb = tof[2*j + 1][k] - 1;
656 return;
657 };
658 j++;
659 };
660 k++;
661 };
662 return;
663 };
664
665
666
667 // wm Nov 08 revision - saturation values included
668 /// gf Apr 07
669 /**
670 * Method to get the dEdx from a given ToF paddle.
671 * If two PMTs are good, the mean dEdx of both PMTs is taken, otherwise
672 * just the dEdx of the "good" PMT. If both PMTs are above saturation => dEdx=1000
673 * @param notrack Track Number
674 * @param Paddle index (0,1,...,23).
675 * @param adcflag in the paddle (100<-> independent of the adcflag; !=0&&!=100 <-> at least one PMT with adcflag!=0; )
676 * @param PadEdx dEdx from a given ToF paddle
677 * @param SatWarning 1 if the PMT ios near saturation region (adcraw ~3000)
678 */
679 void ToFLevel2::GetdEdxPaddle(Int_t notrack, Int_t paddleid, Int_t adcfl, Float_t &PadEdx, Int_t &SatWarning){
680
681 /*
682 Float_t PMTsat[48] = {
683 3162.14, 3165.48, 3153.85, 3085.73, 3089.65, 3107.64, 3097.52, 3078.37,
684 3130.05, 3087.07, 3112.22, 3102.92, 3080.58, 3092.55, 3087.94, 3125.03,
685 3094.09, 3143.16, 3125.51, 3181.27, 3092.09, 3124.98, 3069.3, 3095.53,
686 3097.11, 3133.53, 3114.73, 3113.01, 3091.19, 3097.99, 3033.84, 3134.98,
687 3081.37, 3111.04, 3066.77, 3108.17, 3133, 3111.06, 3052.52, 3140.66,
688 3106.33, 3094.85, 3150.85, 3118.8, 3096.24, 3118.47,3111.36, 3117.11 } ;
689 */
690
691 // new values from Napoli dec 2008
692 Float_t PMTsat[48] = {
693 3176.35,3178.19,3167.38,3099.73,3117.00,3126.29,3111.44,3092.27,
694 3146.48,3094.41,3132.13,3115.37,3099.32,3110.97,3111.80,3143.14,
695 3106.72,3153.44,3136.00,3188.96,3104.73,3140.45,3073.18,3106.62,
696 3112.48,3146.92,3127.24,3136.52,3109.59,3112.89,3045.15,3147.26,
697 3095.92,3121.05,3083.25,3123.62,3150.92,3125.30,3067.60,3160.18,
698 3119.36,3108.92,3164.77,3133.64,3111.47,3131.98,3128.87,3135.56 };
699
700 for (Int_t i=0; i<48;i++) PMTsat[i] = PMTsat[i] - 5.; // safety margin
701
702
703 PadEdx = 0.;
704 // SatWarning = 1000;
705 SatWarning = 0; // 0=good, increase for each bad PMT
706
707 Float_t dEdx[48] = {0};
708 Int_t pmt_id = -1;
709 Float_t adcraw[48];
710 //
711 ToFTrkVar *trk = GetToFTrkVar(notrack);
712 if(!trk) return; //ELENA
713 //
714
715 Int_t pmtleft=-1;
716 Int_t pmtright=-1;
717 GetPaddlePMT(paddleid, pmtleft, pmtright);
718
719 adcraw[pmtleft] = 4095;
720 adcraw[pmtright] = 4095;
721
722
723 for (Int_t jj=0; jj<npmt(); jj++){
724
725 ToFPMT *pmt = GetToFPMT(jj);
726 if(!pmt)break; //ELENA
727
728 pmt_id = pmt->pmt_id;
729 if(pmt_id==pmtleft){
730 adcraw[pmtleft] = pmt->adc;
731 }
732
733 if(pmt_id==pmtright){
734 adcraw[pmtright] = pmt->adc;
735 }
736 }
737
738
739 for (Int_t i=0; i<trk->npmtadc; i++){
740
741 if((trk->adcflag).At(i)==0 || adcfl==100){
742 if((trk->pmtadc).At(i) == pmtleft)dEdx[pmtleft] = (trk->dedx).At(i);
743 if((trk->pmtadc).At(i) == pmtright)dEdx[pmtright] = (trk->dedx).At(i);
744 }else{
745 if((trk->pmtadc).At(i) == pmtleft)dEdx[pmtleft] = 0.;
746 if((trk->pmtadc).At(i) == pmtright)dEdx[pmtright] = 0.;
747 }
748 }
749
750
751 // if( adcraw[pmtleft] >3000 || adcraw[pmtright] >3000)SatWarning=1; //old version
752
753 // Increase SatWarning Counter for each PMT>Sat
754 if( adcraw[pmtleft] > PMTsat[pmtleft])SatWarning++;
755 if( adcraw[pmtright] > PMTsat[pmtright])SatWarning++;
756
757 // if ADC > sat set dEdx=1000
758 if( adcraw[pmtleft] > PMTsat[pmtleft]) dEdx[pmtleft] = 1000.;
759 if( adcraw[pmtright] > PMTsat[pmtright]) dEdx[pmtright] = 1000. ;
760
761 // if two PMT are good, take mean dEdx, otherwise only the good dEdx
762 if(dEdx[pmtleft]<1000 && dEdx[pmtright]<1000) PadEdx = (dEdx[pmtleft]+dEdx[pmtright])*0.5;
763 if(dEdx[pmtleft]==1000 && dEdx[pmtright]<1000) PadEdx = dEdx[pmtright];
764 if(dEdx[pmtleft]<1000 && dEdx[pmtright]==1000) PadEdx = dEdx[pmtleft];
765
766 };
767
768 //
769 // wm Nov 08 revision - saturation values included
770 /// gf Apr 07
771 /**
772 * Method to get the dEdx from a given ToF paddle.
773 * If two PMTs are good, the mean dEdx of both PMTs is taken, otherwise
774 * just the dEdx of the "good" PMT. If both PMTs are above saturation => dEdx=1000
775 * @param notrack Track Number
776 * @param Paddle index (0,1,...,23).
777 * @param adcflag in the paddle (100<-> independent of the adcflag; !=0&&!=100 <-> at least one PMT with adcflag!=0; )
778 * @param PadEdx dEdx from a given ToF paddle
779 * @param SatWarning 1 if the PMT ios near saturation region (adcraw ~3000)
780 */
781 void ToFLevel2::GetdEdxPaddle(ToFTrkVar *trk, Int_t paddleid, Int_t adcfl, Float_t &PadEdx, Int_t &SatWarning){
782
783 /*
784 Float_t PMTsat[48] = {
785 3162.14, 3165.48, 3153.85, 3085.73, 3089.65, 3107.64, 3097.52, 3078.37,
786 3130.05, 3087.07, 3112.22, 3102.92, 3080.58, 3092.55, 3087.94, 3125.03,
787 3094.09, 3143.16, 3125.51, 3181.27, 3092.09, 3124.98, 3069.3, 3095.53,
788 3097.11, 3133.53, 3114.73, 3113.01, 3091.19, 3097.99, 3033.84, 3134.98,
789 3081.37, 3111.04, 3066.77, 3108.17, 3133, 3111.06, 3052.52, 3140.66,
790 3106.33, 3094.85, 3150.85, 3118.8, 3096.24, 3118.47,3111.36, 3117.11 } ;
791 */
792
793 // new values from Napoli dec 2008
794 Float_t PMTsat[48] = {
795 3176.35,3178.19,3167.38,3099.73,3117.00,3126.29,3111.44,3092.27,
796 3146.48,3094.41,3132.13,3115.37,3099.32,3110.97,3111.80,3143.14,
797 3106.72,3153.44,3136.00,3188.96,3104.73,3140.45,3073.18,3106.62,
798 3112.48,3146.92,3127.24,3136.52,3109.59,3112.89,3045.15,3147.26,
799 3095.92,3121.05,3083.25,3123.62,3150.92,3125.30,3067.60,3160.18,
800 3119.36,3108.92,3164.77,3133.64,3111.47,3131.98,3128.87,3135.56 };
801
802 for (Int_t i=0; i<48;i++) PMTsat[i] = PMTsat[i] - 5.; // safety margin
803
804
805 PadEdx = 0.;
806 // SatWarning = 1000;
807 SatWarning = 0; // 0=good, increase for each bad PMT
808
809 Float_t dEdx[48] = {0};
810 Int_t pmt_id = -1;
811 Float_t adcraw[48];
812 //
813 if(!trk) return; //ELENA
814 //
815
816 Int_t pmtleft=-1;
817 Int_t pmtright=-1;
818 GetPaddlePMT(paddleid, pmtleft, pmtright);
819
820 adcraw[pmtleft] = 4095;
821 adcraw[pmtright] = 4095;
822
823
824 for (Int_t jj=0; jj<npmt(); jj++){
825
826 ToFPMT *pmt = GetToFPMT(jj);
827 if(!pmt)break; //ELENA
828
829 pmt_id = pmt->pmt_id;
830 if(pmt_id==pmtleft){
831 adcraw[pmtleft] = pmt->adc;
832 }
833
834 if(pmt_id==pmtright){
835 adcraw[pmtright] = pmt->adc;
836 }
837 }
838
839
840 for (Int_t i=0; i<trk->npmtadc; i++){
841
842 if((trk->adcflag).At(i)==0 || adcfl==100){
843 if((trk->pmtadc).At(i) == pmtleft)dEdx[pmtleft] = (trk->dedx).At(i);
844 if((trk->pmtadc).At(i) == pmtright)dEdx[pmtright] = (trk->dedx).At(i);
845 }else{
846 if((trk->pmtadc).At(i) == pmtleft)dEdx[pmtleft] = 0.;
847 if((trk->pmtadc).At(i) == pmtright)dEdx[pmtright] = 0.;
848 }
849 }
850
851
852 // if( adcraw[pmtleft] >3000 || adcraw[pmtright] >3000)SatWarning=1; //old version
853
854 // Increase SatWarning Counter for each PMT>Sat
855 if( adcraw[pmtleft] > PMTsat[pmtleft])SatWarning++;
856 if( adcraw[pmtright] > PMTsat[pmtright])SatWarning++;
857
858 // if ADC > sat set dEdx=1000
859 if( adcraw[pmtleft] > PMTsat[pmtleft]) dEdx[pmtleft] = 1000.;
860 if( adcraw[pmtright] > PMTsat[pmtright]) dEdx[pmtright] = 1000. ;
861
862 // if two PMT are good, take mean dEdx, otherwise only the good dEdx
863 if(dEdx[pmtleft]<1000 && dEdx[pmtright]<1000) PadEdx = (dEdx[pmtleft]+dEdx[pmtright])*0.5;
864 if(dEdx[pmtleft]==1000 && dEdx[pmtright]<1000) PadEdx = dEdx[pmtright];
865 if(dEdx[pmtleft]<1000 && dEdx[pmtright]==1000) PadEdx = dEdx[pmtleft];
866
867 };
868
869 // gf Apr 07
870
871 /**
872 * Method to get the PMT name (like "S11_1A") if the PMT_ID is given.
873 * Indexes of corresponding plane, paddle and pmt are also given as output.
874 * @param ind PMT_ID (0 - 47)
875 * @param iplane plane index (0 - 5)
876 * @param ipaddle paddle index (relative to the plane)
877 * @param ipmt pmt index (0(A), 1(B))
878 */
879 TString ToFLevel2::GetPMTName(Int_t ind, Int_t &iplane, Int_t &ipaddle,Int_t &ipmt){
880
881 TString pmtname = " ";
882
883 TString photoS[48] = {
884 "S11_1A", "S11_1B", "S11_2A", "S11_2B", "S11_3A", "S11_3B", "S11_4A",
885 "S11_4B",
886 "S11_5A", "S11_5B", "S11_6A", "S11_6B", "S11_7A", "S11_7B", "S11_8A",
887 "S11_8B",
888 "S12_1A", "S12_1B", "S12_2A", "S12_2B", "S12_3A", "S12_3B", "S12_4A",
889 "S12_4B", "S12_5A", "S12_5B", "S12_6A", "S12_6B",
890 "S21_1A", "S21_1B", "S21_2A", "S21_2B",
891 "S22_1A", "S22_1B", "S22_2A", "S22_2B",
892 "S31_1A", "S31_1B", "S31_2A", "S31_2B", "S31_3A", "S31_3B",
893 "S32_1A", "S32_1B", "S32_2A", "S32_2B", "S32_3A", "S32_3B"
894 };
895
896
897 pmtname = photoS[ind].Data();
898
899 TString ss = pmtname(1,2);
900 iplane = (int)(atoi(ss.Data())/10)*2-3+atoi(ss.Data())%10;
901 ss = pmtname(4);
902 ipaddle = atoi(ss.Data())-1 ;
903 if( pmtname.Contains("A") )ipmt=0;
904 if( pmtname.Contains("B") )ipmt=1;
905
906 return pmtname;
907 };
908 /**
909 * Method to get the PMT name (like "S11_1A") if the PMT_ID is given
910 * @param ind PMT_ID (0 - 47)
911 */
912 TString ToFLevel2::GetPMTName(Int_t ind){
913
914 Int_t iplane = -1;
915 Int_t ipaddle = -1;
916 Int_t ipmt = -1;
917 return GetPMTName(ind,iplane,ipaddle,ipmt);
918
919 };
920
921 // wm jun 08
922 Int_t ToFLevel2::GetPaddleIdOfTrack(Float_t xtr, Float_t ytr, Int_t plane){
923 return GetPaddleIdOfTrack(xtr ,ytr ,plane, 0.4);
924 }
925
926 // gf Apr 07
927 Int_t ToFLevel2::GetPaddleIdOfTrack(Float_t xtr, Float_t ytr, Int_t plane, Float_t margin){
928
929 Double_t xt,yt,xl,xh,yl,yh;
930
931 Float_t tof11_x[8] = {-17.85,-12.75,-7.65,-2.55,2.55,7.65,12.75,17.85};
932 Float_t tof12_y[6] = { -13.75,-8.25,-2.75,2.75,8.25,13.75};
933 Float_t tof21_y[2] = { 3.75,-3.75};
934 Float_t tof22_x[2] = { -4.5,4.5};
935 Float_t tof31_x[3] = { -6.0,0.,6.0};
936 Float_t tof32_y[3] = { -5.0,0.0,5.0};
937
938 // S11 8 paddles 33.0 x 5.1 cm
939 // S12 6 paddles 40.8 x 5.5 cm
940 // S21 2 paddles 18.0 x 7.5 cm
941 // S22 2 paddles 15.0 x 9.0 cm
942 // S31 3 paddles 15.0 x 6.0 cm
943 // S32 3 paddles 18.0 x 5.0 cm
944
945 Int_t paddleidoftrack=-1;
946 //
947
948 //--- S11 ------
949
950 if(plane==0){
951 xt = xtr;
952 yt = ytr;
953 paddleidoftrack=-1;
954 yl = -33.0/2. ;
955 yh = 33.0/2. ;
956 if ((yt>yl)&&(yt<yh)) {
957 for (Int_t i1=0; i1<8;i1++){
958 xl = tof11_x[i1] - (5.1-margin)/2. ;
959 xh = tof11_x[i1] + (5.1-margin)/2. ;
960 if ((xt>xl)&&(xt<xh)) paddleidoftrack=i1;
961 }
962 }
963 }
964 // cout<<"S11 "<<paddleidoftrack[0]<<"\n";
965
966 //--- S12 -------
967 if(plane==1){
968 xt = xtr;
969 yt = ytr;
970 paddleidoftrack=-1;
971 xl = -40.8/2. ;
972 xh = 40.8/2. ;
973
974 if ((xt>xl)&&(xt<xh)) {
975 for (Int_t i1=0; i1<6;i1++){
976 yl = tof12_y[i1] - (5.5-margin)/2. ;
977 yh = tof12_y[i1] + (5.5-margin)/2. ;
978 if ((yt>yl)&&(yt<yh)) paddleidoftrack=i1;
979 }
980 }
981 }
982
983 //--- S21 ------
984
985 if(plane==2){
986 xt = xtr;
987 yt = ytr;
988 paddleidoftrack=-1;
989 xl = -18./2. ;
990 xh = 18./2. ;
991
992 if ((xt>xl)&&(xt<xh)) {
993 for (Int_t i1=0; i1<2;i1++){
994 yl = tof21_y[i1] - (7.5-margin)/2. ;
995 yh = tof21_y[i1] + (7.5-margin)/2. ;
996 if ((yt>yl)&&(yt<yh)) paddleidoftrack=i1;
997 }
998 }
999 }
1000
1001 //--- S22 ------
1002 if(plane==3){
1003 xt = xtr;
1004 yt = ytr;
1005 paddleidoftrack=-1;
1006 yl = -15./2. ;
1007 yh = 15./2. ;
1008
1009 if ((yt>yl)&&(yt<yh)) {
1010 for (Int_t i1=0; i1<2;i1++){
1011 xl = tof22_x[i1] - (9.0-margin)/2. ;
1012 xh = tof22_x[i1] + (9.0-margin)/2. ;
1013 if ((xt>xl)&&(xt<xh)) paddleidoftrack=i1;
1014 }
1015 }
1016 }
1017
1018 //--- S31 ------
1019 if(plane==4){
1020 xt = xtr;
1021 yt = ytr;
1022 paddleidoftrack=-1;
1023 yl = -15.0/2. ;
1024 yh = 15.0/2. ;
1025
1026 if ((yt>yl)&&(yt<yh)) {
1027 for (Int_t i1=0; i1<3;i1++){
1028 xl = tof31_x[i1] - (6.0-margin)/2. ;
1029 xh = tof31_x[i1] + (6.0-margin)/2. ;
1030 if ((xt>xl)&&(xt<xh)) paddleidoftrack=i1;
1031 }
1032 }
1033 }
1034
1035 //--- S32 ------
1036 if(plane==5){
1037 xt = xtr;
1038 yt = ytr;
1039 paddleidoftrack=-1;
1040 xl = -18.0/2. ;
1041 xh = 18.0/2. ;
1042
1043 if ((xt>xl)&&(xt<xh)) {
1044 for (Int_t i1=0; i1<3;i1++){
1045 yl = tof32_y[i1] - (5.0-margin)/2. ;
1046 yh = tof32_y[i1] + (5.0-margin)/2. ;
1047 if ((yt>yl)&&(yt<yh)) paddleidoftrack=i1;
1048 }
1049 }
1050 }
1051
1052 return paddleidoftrack;
1053
1054 }
1055
1056 //
1057
1058 // gf Apr 07
1059
1060 void ToFLevel2::GetPMTPaddle(Int_t pmt_id, Int_t &plane, Int_t &paddle){
1061
1062 plane = GetPlaneIndex(pmt_id);
1063
1064 if(plane == 0){
1065 if(pmt_id==0 || pmt_id==1)paddle=0;
1066 if(pmt_id==2 || pmt_id==3)paddle=1;
1067 if(pmt_id==4 || pmt_id==5)paddle=2;
1068 if(pmt_id==6 || pmt_id==7)paddle=3;
1069 if(pmt_id==8 || pmt_id==9)paddle=4;
1070 if(pmt_id==10 || pmt_id==11)paddle=5;
1071 if(pmt_id==12 || pmt_id==13)paddle=6;
1072 if(pmt_id==14 || pmt_id==15)paddle=7;
1073 }
1074
1075 if(plane == 1){
1076 if(pmt_id==16 || pmt_id==17)paddle=0;
1077 if(pmt_id==18 || pmt_id==19)paddle=1;
1078 if(pmt_id==20 || pmt_id==21)paddle=2;
1079 if(pmt_id==22 || pmt_id==23)paddle=3;
1080 if(pmt_id==24 || pmt_id==25)paddle=4;
1081 if(pmt_id==26 || pmt_id==27)paddle=5;
1082 }
1083
1084 if(plane == 2){
1085 if(pmt_id==28 || pmt_id==29)paddle=0;
1086 if(pmt_id==30 || pmt_id==31)paddle=1;
1087 }
1088
1089 if(plane == 3){
1090 if(pmt_id==32 || pmt_id==33)paddle=0;
1091 if(pmt_id==34 || pmt_id==35)paddle=1;
1092 }
1093
1094 if(plane == 4){
1095 if(pmt_id==36 || pmt_id==37)paddle=0;
1096 if(pmt_id==38 || pmt_id==39)paddle=1;
1097 if(pmt_id==40 || pmt_id==41)paddle=2;
1098 }
1099
1100 if(plane == 5){
1101 if(pmt_id==42 || pmt_id==43)paddle=0;
1102 if(pmt_id==44 || pmt_id==45)paddle=1;
1103 if(pmt_id==46 || pmt_id==47)paddle=2;
1104 }
1105 return;
1106 }
1107
1108 //
1109
1110 // gf Apr 07
1111
1112 void ToFLevel2::GetPaddlePMT(Int_t paddle, Int_t &pmtleft, Int_t &pmtright){
1113 pmtleft=paddle*2;
1114 pmtright= pmtleft+1;
1115 return;
1116 }
1117
1118 //
1119
1120
1121
1122 // // gf Apr 07
1123
1124 void ToFLevel2::GetPaddleGeometry(Int_t plane, Int_t paddle, Float_t &xleft, Float_t &xright, Float_t &yleft, Float_t &yright){
1125
1126 Int_t i1;
1127
1128 Float_t tof11_x[8] = {-17.85,-12.75,-7.65,-2.55,2.55,7.65,12.75,17.85};
1129 Float_t tof12_y[6] = { -13.75,-8.25,-2.75,2.75,8.25,13.75};
1130 Float_t tof21_y[2] = { 3.75,-3.75};
1131 Float_t tof22_x[2] = { -4.5,4.5};
1132 Float_t tof31_x[3] = { -6.0,0.,6.0};
1133 Float_t tof32_y[3] = { -5.0,0.0,5.0};
1134
1135 // S11 8 paddles 33.0 x 5.1 cm
1136 // S12 6 paddles 40.8 x 5.5 cm
1137 // S21 2 paddles 18.0 x 7.5 cm
1138 // S22 2 paddles 15.0 x 9.0 cm
1139 // S31 3 paddles 15.0 x 6.0 cm
1140 // S32 3 paddles 18.0 x 5.0 cm
1141
1142 if(plane==0)
1143 {
1144 for (i1=0; i1<8;i1++){
1145 if(i1 == paddle){
1146 xleft = tof11_x[i1] - 5.1/2.;
1147 xright = tof11_x[i1] + 5.1/2.;
1148 yleft = -33.0/2.;
1149 yright = 33.0/2.;
1150 }
1151 }
1152 }
1153
1154 if(plane==1)
1155 {
1156 for (i1=0; i1<6;i1++){
1157 if(i1 == paddle){
1158 xleft = -40.8/2.;
1159 xright = 40.8/2.;
1160 yleft = tof12_y[i1] - 5.5/2.;
1161 yright = tof12_y[i1] + 5.5/2.;
1162 }
1163 }
1164 }
1165
1166 if(plane==2)
1167 {
1168 for (i1=0; i1<2;i1++){
1169 if(i1 == paddle){
1170 xleft = -18./2.;
1171 xright = 18./2.;
1172 yleft = tof21_y[i1] - 7.5/2.;
1173 yright = tof21_y[i1] + 7.5/2.;
1174 }
1175 }
1176 }
1177
1178 if(plane==3)
1179 {
1180 for (i1=0; i1<2;i1++){
1181 if(i1 == paddle){
1182 xleft = tof22_x[i1] - 9.0/2.;
1183 xright = tof22_x[i1] + 9.0/2.;
1184 yleft = -15./2.;
1185 yright = 15./2.;
1186 }
1187 }
1188 }
1189
1190
1191 if(plane==4)
1192 {
1193 for (i1=0; i1<3;i1++){
1194 if(i1 == paddle){
1195 xleft = tof31_x[i1] - 6.0/2.;
1196 xright = tof31_x[i1] + 6.0/2.;
1197 yleft = -15./2.;
1198 yright = 15./2.;
1199 }
1200 }
1201 }
1202
1203 if(plane==5)
1204 {
1205 for (i1=0; i1<3;i1++){
1206 if(i1 == paddle){
1207 xleft = -18.0/2.;
1208 xright = 18.0/2.;
1209 yleft = tof32_y[i1] - 5.0/2.;
1210 yright = tof32_y[i1] + 5.0/2.;
1211 }
1212 }
1213 }
1214 return;
1215 }
1216
1217 // gf Apr 07
1218 /**
1219 * Method to get the paddle index (0,...23) if the plane ID and the paddle id in the plane is given.
1220 * This method is the
1221 * "reverse" of method "GetPaddlePlane"
1222 * @param plane (0 - 5)
1223 * @param paddle (plane=0, paddle = 0,...5)
1224 * @param padid (0 - 23)
1225 */
1226 Int_t ToFLevel2::GetPaddleid(Int_t plane, Int_t paddle)
1227 {
1228 Int_t padid=-1;
1229 Int_t pads[6]={8,6,2,2,3,3};
1230
1231 int somma=0;
1232 int np=plane;
1233 for(Int_t j=0; j<np; j++){
1234 somma+=pads[j];
1235 }
1236 padid=paddle+somma;
1237 return padid;
1238
1239 }
1240
1241
1242 // gf Apr 07
1243 /**
1244 * Method to get the plane ID and the paddle id in the plane if the paddle index (0,...23) is given.
1245 * This method is the
1246 * "reverse" of method "GetPaddleid"
1247 * @param pad (0 - 23)
1248 * @param plane (0 - 5)
1249 * @param paddle (plane=0, paddle = 0,...5)
1250 */
1251 void ToFLevel2::GetPaddlePlane(Int_t pad, Int_t &plane, Int_t &paddle)
1252 {
1253
1254 Int_t pads11=8;
1255 Int_t pads12=6;
1256 Int_t pads21=2;
1257 Int_t pads22=2;
1258 Int_t pads31=3;
1259 // Int_t pads32=3;
1260
1261 if(pad<8){
1262 plane=0;
1263 paddle=pad;
1264 return;
1265 }
1266
1267 if((7<pad)&&(pad<14)){
1268 plane=1;
1269 paddle=pad-pads11;
1270 return;
1271 }
1272
1273 if((13<pad)&&(pad<16)){
1274 plane=2;
1275 paddle=pad-pads11-pads12;
1276 return;
1277 }
1278
1279 if((15<pad)&&(pad<18)){
1280 plane=3;
1281 paddle=pad-pads11-pads12-pads21;
1282 return;
1283 }
1284
1285 if((17<pad)&&(pad<21)){
1286 plane=4;
1287 paddle=pad-pads11-pads12-pads21-pads22;
1288 return;
1289 }
1290
1291 if((20<pad)&&(pad<24)){
1292 plane=5;
1293 paddle=pad-pads11-pads12-pads21-pads22-pads31;
1294 return;
1295 }
1296
1297 }
1298
1299
1300 Int_t ToFLevel2::GetNPaddle(Int_t plane){
1301
1302 Int_t npaddle=-1;
1303
1304 Int_t pads11=8;
1305 Int_t pads12=6;
1306 Int_t pads21=2;
1307 Int_t pads22=2;
1308 Int_t pads31=3;
1309 Int_t pads32=3;
1310
1311 if(plane==0)npaddle=pads11;
1312 if(plane==1)npaddle=pads12;
1313 if(plane==2)npaddle=pads21;
1314 if(plane==3)npaddle=pads22;
1315 if(plane==4)npaddle=pads31;
1316 if(plane==5)npaddle=pads32;
1317
1318 return npaddle;
1319
1320 }
1321
1322
1323
1324 /// wm feb 08
1325
1326 /**
1327 * Method to calculate Beta from the 12 single measurements
1328 * we check the individual weights for artificial TDC values, then calculate
1329 * am mean beta for the first time. In a second step we loop again through
1330 * the single measurements, checking for the residual from the mean
1331 * The cut on the residual reject measurements > "x"-sigma. A chi2 value is
1332 * calculated, furthermore a "quality" value by adding the weights which
1333 * are finally used. If all measurements are taken, "quality" will be = 22.47.
1334 * A chi2 cut around 3-4 and a quality-cut > 20 is needed for clean beta
1335 * measurements like antiprotons etc.
1336 * The Level2 output is derived in the fortran routines using: 10.,10.,20.
1337 * @param notrack Track Number
1338 * @param cut on residual: difference between single measurement and mean
1339 * @param cut on "quality"
1340 * @param cut on chi2
1341 */
1342
1343 Float_t ToFLevel2::CalcBeta(Int_t notrack, Float_t resmax, Float_t qualitycut, Float_t chi2cut){
1344
1345 // cout<<" in CalcBeta "<<resmax<<" "<<chi2cut<<" "<<qualitycut<<endl;
1346
1347 Float_t bxx = 100.;
1348 //
1349 ToFTrkVar *trk = GetToFTrkVar(notrack);
1350 if(!trk) return 0; //ELENA
1351
1352
1353 Float_t chi2,xhelp,beta_mean;
1354 Float_t w_i[12],quality,sw,sxw,res,betachi,beta_mean_inv;
1355 Float_t b[12],tdcfl;
1356 Int_t pmt_id,pmt_plane;
1357
1358 for (Int_t i=0; i<12; i++){
1359 b[i] = trk->beta[i];
1360 }
1361
1362
1363 //========================================================================
1364 //--- Find out ToF layers with artificial TDC values & fill vector ---
1365 //========================================================================
1366
1367 Float_t w_il[6];
1368
1369 for (Int_t jj=0; jj<6;jj++) {
1370 w_il[jj] = 1000.;
1371 }
1372
1373
1374 for (Int_t i=0; i<trk->npmttdc; i++){
1375 //
1376 pmt_id = (trk->pmttdc).At(i);
1377 pmt_plane = GetPlaneIndex(pmt_id);
1378 tdcfl = (trk->tdcflag).At(i);
1379 if (w_il[pmt_plane] != 1.) w_il[pmt_plane] = tdcfl; //tdcflag
1380 };
1381
1382 //========================================================================
1383 //--- Set weights for the 12 measurements using information for top and bottom:
1384 //--- if no measurements: weight = set to very high value=> not used
1385 //--- top or bottom artificial: weight*sqrt(2)
1386 //--- top and bottom artificial: weight*sqrt(2)*sqrt(2)
1387 //========================================================================
1388
1389 Int_t itop[12] = {0,0,1,1,2,2,3,3,0,0,1,1};
1390 Int_t ibot[12] = {4,5,4,5,4,5,4,5,2,3,2,3};
1391
1392 xhelp= 1E09;
1393
1394 for (Int_t jj=0; jj<12;jj++) {
1395 if (jj<4) xhelp = 0.11; // S1-S3
1396 if ((jj>3)&&(jj<8)) xhelp = 0.18; // S2-S3
1397 if (jj>7) xhelp = 0.28; // S1-S2
1398 if ((w_il[itop[jj]] == 1000.) && (w_il[ibot[jj]] == 1000.)) xhelp = 1E09;
1399 if ((w_il[itop[jj]] == 1) || (w_il[ibot[jj]] == 1.)) xhelp = xhelp*1.414 ;
1400 if ((w_il[itop[jj]] == 1) && (w_il[ibot[jj]] == 1.)) xhelp = xhelp*2. ;
1401
1402 w_i[jj] = 1./xhelp;
1403 }
1404
1405
1406 //========================================================================
1407 //--- Calculate mean beta for the first time -----------------------------
1408 //--- We are using "1/beta" since its error is gaussian ------------------
1409 //========================================================================
1410
1411 Int_t icount=0;
1412 sw=0.;
1413 sxw=0.;
1414 beta_mean=100.;
1415
1416 for (Int_t jj=0; jj<12;jj++){
1417 if ((fabs(1./b[jj])>0.1)&&(fabs(1./b[jj])<15.))
1418 {
1419 icount= icount+1;
1420 sxw=sxw + (1./b[jj])*w_i[jj]*w_i[jj] ;
1421 sw =sw + w_i[jj]*w_i[jj] ;
1422
1423 }
1424 }
1425
1426 if (icount>0) beta_mean=1./(sxw/sw);
1427 beta_mean_inv = 1./beta_mean;
1428
1429 //========================================================================
1430 //--- Calculate beta for the second time, use residuals of the single
1431 //--- measurements to get a chi2 value
1432 //========================================================================
1433
1434 icount=0;
1435 sw=0.;
1436 sxw=0.;
1437 betachi = 100.;
1438 chi2 = 0.;
1439 quality=0.;
1440
1441
1442 for (Int_t jj=0; jj<12;jj++){
1443 if ((fabs(1./b[jj])>0.1)&&(fabs(1./b[jj])<15.)&&(w_i[jj]>0.01)) {
1444 res = beta_mean_inv - (1./b[jj]) ;
1445 if (fabs(res*w_i[jj])<resmax) {;
1446 chi2 = chi2 + pow((res*w_i[jj]),2) ;
1447 icount= icount+1;
1448 sxw=sxw + (1./b[jj])*w_i[jj]*w_i[jj] ;
1449 sw =sw + w_i[jj]*w_i[jj] ;
1450 }
1451 }
1452 }
1453 quality = sqrt(sw) ;
1454
1455 if (icount==0) chi2 = 1000.;
1456 if (icount>0) chi2 = chi2/(icount) ;
1457 if (icount>0) betachi=1./(sxw/sw);
1458
1459 bxx = 100.;
1460 if ((chi2 < chi2cut)&&(quality>qualitycut)) bxx = betachi;
1461 //
1462 return(bxx);
1463 };
1464
1465
1466 ////////////////////////////////////////////////////
1467 ////////////////////////////////////////////////////
1468
1469
1470 /**
1471 * Fills a struct cToFLevel2 with values from a ToFLevel2 object (to put data into a F77 common).
1472 */
1473 void ToFLevel2::GetLevel2Struct(cToFLevel2 *l2) const{
1474
1475 for(Int_t i=0;i<6;i++)
1476 l2->tof_j_flag[i]=tof_j_flag[i];
1477
1478 if(ToFTrk){ //ELENA
1479 l2->ntoftrk = ToFTrk->GetEntries();
1480 for(Int_t j=0;j<l2->ntoftrk;j++){
1481 l2->toftrkseqno[j]= ((ToFTrkVar*)ToFTrk->At(j))->trkseqno;
1482 l2->npmttdc[j]= ((ToFTrkVar*)ToFTrk->At(j))->npmttdc;
1483 for(Int_t i=0;i<l2->npmttdc[j];i++){
1484 l2->pmttdc[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->pmttdc.At(i);
1485 l2->tdcflag[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->tdcflag.At(i); // gf: 30 Nov 2006
1486 }
1487 for(Int_t i=0;i<13;i++)
1488 l2->beta[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->beta[i];
1489
1490 l2->npmtadc[j]= ((ToFTrkVar*)ToFTrk->At(j))->npmtadc;
1491 for(Int_t i=0;i<l2->npmtadc[j];i++){
1492 l2->pmtadc[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->pmtadc.At(i);
1493 l2->adcflag[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->adcflag.At(i); // gf: 30 Nov 2006
1494 l2->dedx[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->dedx.At(i);
1495 }
1496 for(Int_t i=0;i<3;i++){
1497 l2->xtofpos[i][j]=((ToFTrkVar*)ToFTrk->At(j))->xtofpos[i];
1498 l2->ytofpos[i][j]=((ToFTrkVar*)ToFTrk->At(j))->ytofpos[i];
1499 }
1500 for(Int_t i=0;i<6;i++){
1501 l2->xtr_tof[i][j]=((ToFTrkVar*)ToFTrk->At(j))->xtr_tof[i];
1502 l2->ytr_tof[i][j]=((ToFTrkVar*)ToFTrk->At(j))->ytr_tof[i];
1503 }
1504 }
1505 } //ELENA
1506
1507 if(PMT){ //ELENA
1508 l2->npmt = PMT->GetEntries();
1509 for(Int_t j=0;j<l2->npmt;j++){
1510 l2->pmt_id[j] = ((ToFPMT*)PMT->At(j))->pmt_id;
1511 l2->adc[j] =((ToFPMT*)PMT->At(j))->adc;
1512 l2->tdc_tw[j] =((ToFPMT*)PMT->At(j))->tdc_tw;
1513 }
1514 } //ELENA
1515 }
1516
1517
1518 //
1519 // Reprocessing tool // Emiliano 08/04/07
1520 //
1521 Int_t ToFLevel2::Process(TrkLevel2 *trk, TrigLevel2 *trg, GL_RUN *run, OrbitalInfo *orb, Bool_t force){
1522 //
1523 // Copiare qui qualcosa di simile a calonuclei per evitare di riprocessare sempre tutto
1524 //
1525 printf("\n\n\n ERROR: NOT IMPLEMENTED ANYMORE, write Emiliano if you need this method (Emiliano.Mocchiutti@ts.infn.it) \n\n\n");
1526 return(-1);
1527 // //
1528 // // structures to communicate with F77
1529 // //
1530 // extern struct ToFInput tofinput_;
1531 // extern struct ToFOutput tofoutput_;
1532 // //
1533 // // DB connection
1534 // //
1535 // TString host;
1536 // TString user;
1537 // TString psw;
1538 // const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
1539 // const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
1540 // const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
1541 // if ( !pamdbhost ) pamdbhost = "";
1542 // if ( !pamdbuser ) pamdbuser = "";
1543 // if ( !pamdbpsw ) pamdbpsw = "";
1544 // if ( strcmp(pamdbhost,"") ) host = pamdbhost;
1545 // if ( strcmp(pamdbuser,"") ) user = pamdbuser;
1546 // if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
1547 // //
1548 // //
1549 // TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
1550 // if ( !dbc->IsConnected() ) return 1;
1551 // stringstream myquery;
1552 // myquery.str("");
1553 // myquery << "SET time_zone='+0:00';";
1554 // dbc->Query(myquery.str().c_str());
1555 // delete dbc->Query("SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';");
1556 // GL_PARAM *glparam = new GL_PARAM();
1557 // glparam->Query_GL_PARAM(1,1,dbc); // parameters stored in DB in GL_PRAM table
1558 // trk->LoadField(glparam->PATH+glparam->NAME);
1559 // //
1560 // Bool_t defcal = true;
1561 // Int_t error=glparam->Query_GL_PARAM(run->RUNHEADER_TIME,201,dbc); // parameters stored in DB in GL_PRAM table
1562 // if ( error<0 ) {
1563 // return(1);
1564 // };
1565 // printf(" Reading ToF parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());
1566 // if ( (UInt_t)glparam->TO_TIME != (UInt_t)4294967295UL ) defcal = false;
1567 // //
1568 // Int_t nlen = (Int_t)(glparam->PATH+glparam->NAME).Length();
1569 // rdtofcal((char *)(glparam->PATH+glparam->NAME).Data(),&nlen);
1570 // //
1571 // Int_t adc[4][12];
1572 // Int_t tdc[4][12];
1573 // Float_t tdcc[4][12];
1574 // //
1575 // // process tof data
1576 // //
1577 // for (Int_t hh=0; hh<12;hh++){
1578 // for (Int_t kk=0; kk<4;kk++){
1579 // adc[kk][hh] = 4095;
1580 // tdc[kk][hh] = 4095;
1581 // tdcc[kk][hh] = 4095.;
1582 // tofinput_.adc[hh][kk] = 4095;
1583 // tofinput_.tdc[hh][kk] = 4095;
1584 // };
1585 // };
1586 // Int_t ntrkentry = 0;
1587 // Int_t npmtentry = 0;
1588 // Int_t gg = 0;
1589 // Int_t hh = 0;
1590 // Int_t adcf[48];
1591 // memset(adcf, 0, 48*sizeof(Int_t));
1592 // Int_t tdcf[48];
1593 // memset(tdcf, 0, 48*sizeof(Int_t));
1594 // for (Int_t pm=0; pm < this->ntrk() ; pm++){
1595 // ToFTrkVar *ttf = this->GetToFTrkVar(pm);
1596 // for ( Int_t nc=0; nc < ttf->npmttdc; nc++){
1597 // if ( (ttf->tdcflag).At(nc) != 0 ) tdcf[(ttf->pmttdc).At(nc)] = 1;
1598 // };
1599 // for ( Int_t nc=0; nc < ttf->npmtadc; nc++){
1600 // if ( (ttf->adcflag).At(nc) != 0 ) adcf[(ttf->pmtadc).At(nc)] = 1;
1601 // };
1602 // };
1603 // //
1604 // for (Int_t pm=0; pm < this->npmt() ; pm++){
1605 // ToFPMT *pmt = this->GetToFPMT(pm);
1606 // this->GetPMTIndex(pmt->pmt_id, gg, hh);
1607 // if ( adcf[pmt->pmt_id] == 0 ){
1608 // tofinput_.adc[gg][hh] = (int)pmt->adc;
1609 // adc[hh][gg] = (int)pmt->adc;
1610 // };
1611 // if ( tdcf[pmt->pmt_id] == 0 ){
1612 // tofinput_.tdc[gg][hh] = (int)pmt->tdc;
1613 // tdc[hh][gg] = (int)pmt->tdc;
1614 // };
1615 // tdcc[hh][gg] = (float)pmt->tdc_tw;
1616 // // Int_t pppid = this->GetPMTid(hh,gg);
1617 // // printf(" pm %i pmt_id %i pppid %i hh %i gg %i tdcc %f tdc %f adc %f \n",pm,pmt->pmt_id,pppid,hh,gg,pmt->tdc_tw,pmt->tdc,pmt->adc);
1618 // };
1619 // //
1620 // Int_t unpackError = this->unpackError;
1621 // //
1622 // for (Int_t hh=0; hh<5;hh++){
1623 // tofinput_.patterntrig[hh]=trg->patterntrig[hh];
1624 // };
1625 // //
1626 // this->Clear();
1627 // //
1628 // Int_t pmt_id = 0;
1629 // ToFPMT *t_pmt = new ToFPMT();
1630 // if(!(this->PMT)) this->PMT = new TClonesArray("ToFPMT",12); //ELENA
1631 // TClonesArray &tpmt = *this->PMT;
1632 // ToFTrkVar *t_tof = new ToFTrkVar();
1633 // if(!(this->ToFTrk)) this->ToFTrk = new TClonesArray("ToFTrkVar",2); //ELENA
1634 // TClonesArray &t = *this->ToFTrk;
1635 // //
1636 // //
1637 // // Here we have calibrated data, ready to be passed to the FORTRAN routine which will extract common and track-related variables.
1638 // //
1639 // npmtentry = 0;
1640 // //
1641 // ntrkentry = 0;
1642 // //
1643 // // Calculate tracks informations from ToF alone
1644 // //
1645 // tofl2com();
1646 // //
1647 // memcpy(this->tof_j_flag,tofoutput_.tof_j_flag,6*sizeof(Int_t));
1648 // //
1649 // t_tof->trkseqno = -1;
1650 // //
1651 // // and now we must copy from the output structure to the level2 class:
1652 // //
1653 // t_tof->npmttdc = 0;
1654 // //
1655 // for (Int_t hh=0; hh<12;hh++){
1656 // for (Int_t kk=0; kk<4;kk++){
1657 // if ( tofoutput_.tofmask[hh][kk] != 0 ){
1658 // pmt_id = this->GetPMTid(kk,hh);
1659 // t_tof->pmttdc.AddAt(pmt_id,t_tof->npmttdc);
1660 // t_tof->tdcflag.AddAt(tofoutput_.tdcflagtof[hh][kk],t_tof->npmttdc); // gf: Jan 09/07
1661 // t_tof->npmttdc++;
1662 // };
1663 // };
1664 // };
1665 // for (Int_t kk=0; kk<13;kk++){
1666 // t_tof->beta[kk] = tofoutput_.betatof_a[kk];
1667 // }
1668 // //
1669 // t_tof->npmtadc = 0;
1670 // for (Int_t hh=0; hh<12;hh++){
1671 // for (Int_t kk=0; kk<4;kk++){
1672 // if ( tofoutput_.adctof_c[hh][kk] < 1000 ){
1673 // t_tof->dedx.AddAt(tofoutput_.adctof_c[hh][kk],t_tof->npmtadc);
1674 // pmt_id = this->GetPMTid(kk,hh);
1675 // t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc);
1676 // t_tof->adcflag.AddAt(tofoutput_.adcflagtof[hh][kk],t_tof->npmtadc); // gf: Jan 09/07
1677 // t_tof->npmtadc++;
1678 // };
1679 // };
1680 // };
1681 // //
1682 // memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos));
1683 // memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos));
1684 // memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof));
1685 // memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof));
1686 // //
1687 // new(t[ntrkentry]) ToFTrkVar(*t_tof);
1688 // ntrkentry++;
1689 // t_tof->Clear();
1690 // //
1691 // //
1692 // //
1693 // t_pmt->Clear();
1694 // //
1695 // for (Int_t hh=0; hh<12;hh++){
1696 // for (Int_t kk=0; kk<4;kk++){
1697 // // new WM
1698 // if ( tofoutput_.tdc_c[hh][kk] < 4095 || adc[kk][hh] < 4095 || tdc[kk][hh] < 4095 ){
1699 // // if ( tdcc[kk][hh] < 4095. || adc[kk][hh] < 4095 || tdc[kk][hh] < 4095 ){
1700 // //
1701 // t_pmt->pmt_id = this->GetPMTid(kk,hh);
1702 // t_pmt->tdc_tw = tofoutput_.tdc_c[hh][kk];
1703 // t_pmt->adc = (Float_t)adc[kk][hh];
1704 // t_pmt->tdc = (Float_t)tdc[kk][hh];
1705 // //
1706 // new(tpmt[npmtentry]) ToFPMT(*t_pmt);
1707 // npmtentry++;
1708 // t_pmt->Clear();
1709 // };
1710 // };
1711 // };
1712 // //
1713 // // Calculate track-related variables
1714 // //
1715 // if ( trk->ntrk() > 0 ){
1716 // //
1717 // // We have at least one track
1718 // //
1719 // //
1720 // // Run over tracks
1721 // //
1722 // for(Int_t nt=0; nt < trk->ntrk(); nt++){
1723 // //
1724 // TrkTrack *ptt = trk->GetStoredTrack(nt);
1725 // //
1726 // // Copy the alpha vector in the input structure
1727 // //
1728 // for (Int_t e = 0; e < 5 ; e++){
1729 // tofinput_.al_pp[e] = ptt->al[e];
1730 // };
1731 // //
1732 // // Get tracker related variables for this track
1733 // //
1734 // toftrk();
1735 // //
1736 // // Copy values in the class from the structure (we need to use a temporary class to store variables).
1737 // //
1738 // t_tof->npmttdc = 0;
1739 // for (Int_t hh=0; hh<12;hh++){
1740 // for (Int_t kk=0; kk<4;kk++){
1741 // if ( tofoutput_.tofmask[hh][kk] != 0 ){
1742 // pmt_id = this->GetPMTid(kk,hh);
1743 // t_tof->pmttdc.AddAt(pmt_id,t_tof->npmttdc);
1744 // t_tof->tdcflag.AddAt(tofoutput_.tdcflag[hh][kk],t_tof->npmttdc); // gf: Jan 09/07
1745 // t_tof->npmttdc++;
1746 // };
1747 // };
1748 // };
1749 // for (Int_t kk=0; kk<13;kk++){
1750 // t_tof->beta[kk] = tofoutput_.beta_a[kk];
1751 // };
1752 // //
1753 // t_tof->npmtadc = 0;
1754 // for (Int_t hh=0; hh<12;hh++){
1755 // for (Int_t kk=0; kk<4;kk++){
1756 // if ( tofoutput_.adc_c[hh][kk] < 1000 ){
1757 // t_tof->dedx.AddAt(tofoutput_.adc_c[hh][kk],t_tof->npmtadc);
1758 // pmt_id = this->GetPMTid(kk,hh);
1759 // t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc);
1760 // t_tof->adcflag.AddAt(tofoutput_.adcflag[hh][kk],t_tof->npmtadc); // gf: Jan 09/07
1761 // t_tof->npmtadc++;
1762 // };
1763 // };
1764 // };
1765 // //
1766 // memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos));
1767 // memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos));
1768 // memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof));
1769 // memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof));
1770 // //
1771 // // Store the tracker track number in order to be sure to have shyncronized data during analysis
1772 // //
1773 // t_tof->trkseqno = nt;
1774 // //
1775 // // create a new object for this event with track-related variables
1776 // //
1777 // new(t[ntrkentry]) ToFTrkVar(*t_tof);
1778 // ntrkentry++;
1779 // t_tof->Clear();
1780 // //
1781 // }; // loop on all the tracks
1782 // //
1783 // this->unpackError = unpackError;
1784 // if ( defcal ){
1785 // this->default_calib = 1;
1786 // } else {
1787 // this->default_calib = 0;
1788 // };
1789 //};
1790 // return(0);
1791 }
1792
1793 bool ToFLevel2::bit(int decimal, char pos){
1794 return( (decimal>>pos)%2 );
1795 }
1796
1797 bool ToFLevel2::checkPMT(TString givenpmt){
1798 TClonesArray* Pmt = this->PMT;
1799 // printf(" ou %s entries %i \n",givenpmt.Data(),Pmt->GetEntries());
1800 for(int i=0; i<Pmt->GetEntries(); i++) {
1801 ToFPMT* pmthit = (ToFPMT*)Pmt->At(i);
1802 TString pmtname = this->GetPMTName(pmthit->pmt_id);
1803 // printf(" name %s \n",pmtname.Data());
1804 if ( !strcmp(pmtname.Data(),givenpmt.Data()) )
1805 return true;
1806 }
1807 // printf(" PMT %s missing \n",givenpmt.Data());
1808 return false;
1809 }
1810
1811 bool ToFLevel2::checkPMTpatternPMThit(TrigLevel2 *trg, int &pmtpattern, int &pmtnosignal){
1812 UInt_t *patterntrig = trg->patterntrig;
1813 pmtpattern = 0;
1814 pmtnosignal = 0;
1815 bool good = true;
1816 //S3
1817 if ( this->bit(patterntrig[2],0) ){ pmtpattern++; if ( !this->checkPMT("S31_1A")){ pmtnosignal++; good = false;}}
1818 if ( this->bit(patterntrig[2],1) ){ pmtpattern++; if ( !this->checkPMT("S31_2A")){ pmtnosignal++; good = false;}}
1819 if ( this->bit(patterntrig[2],2) ){ pmtpattern++; if ( !this->checkPMT("S31_3A")){ pmtnosignal++; good = false;}}
1820 if ( this->bit(patterntrig[2],3) ){ pmtpattern++; if ( !this->checkPMT("S31_1B")){ pmtnosignal++; good = false;}}
1821 if ( this->bit(patterntrig[2],4) ){ pmtpattern++; if ( !this->checkPMT("S31_2B")){ pmtnosignal++; good = false;}}
1822 if ( this->bit(patterntrig[2],5) ){ pmtpattern++; if ( !this->checkPMT("S31_3B")){ pmtnosignal++; good = false;}}
1823 if ( this->bit(patterntrig[2],6) ){ pmtpattern++; if ( !this->checkPMT("S32_1A")){ pmtnosignal++; good = false;}}
1824 if ( this->bit(patterntrig[2],7) ){ pmtpattern++; if ( !this->checkPMT("S32_2A")){ pmtnosignal++; good = false;}}
1825 if ( this->bit(patterntrig[2],8) ){ pmtpattern++; if ( !this->checkPMT("S32_3A")){ pmtnosignal++; good = false;}}
1826 if ( this->bit(patterntrig[2],9) ){ pmtpattern++; if ( !this->checkPMT("S32_1B")){ pmtnosignal++; good = false;}}
1827 if ( this->bit(patterntrig[2],10) ){ pmtpattern++; if ( !this->checkPMT("S32_2B")){ pmtnosignal++; good = false;}}
1828 if ( this->bit(patterntrig[2],11) ){ pmtpattern++; if ( !this->checkPMT("S32_3B")){ pmtnosignal++; good = false;}}
1829 //S2
1830 if ( this->bit(patterntrig[3],0) ){ pmtpattern++; if ( !this->checkPMT("S21_1A")){ pmtnosignal++; good = false;}}
1831 if ( this->bit(patterntrig[3],1) ){ pmtpattern++; if ( !this->checkPMT("S21_2A")){ pmtnosignal++; good = false;}}
1832 if ( this->bit(patterntrig[3],2) ){ pmtpattern++; if ( !this->checkPMT("S21_1B")){ pmtnosignal++; good = false;}}
1833 if ( this->bit(patterntrig[3],3) ){ pmtpattern++; if ( !this->checkPMT("S21_2B")){ pmtnosignal++; good = false;}}
1834 if ( this->bit(patterntrig[3],4) ){ pmtpattern++; if ( !this->checkPMT("S22_1A")){ pmtnosignal++; good = false;}}
1835 if ( this->bit(patterntrig[3],5) ){ pmtpattern++; if ( !this->checkPMT("S22_2A")){ pmtnosignal++; good = false;}}
1836 if ( this->bit(patterntrig[3],6) ){ pmtpattern++; if ( !this->checkPMT("S22_1B")){ pmtnosignal++; good = false;}}
1837 if ( this->bit(patterntrig[3],7) ){ pmtpattern++; if ( !this->checkPMT("S22_2B")){ pmtnosignal++; good = false;}}
1838 //S12
1839 if ( this->bit(patterntrig[4],0) ){ pmtpattern++; if ( !this->checkPMT("S12_1A")){ pmtnosignal++; good = false;}}
1840 if ( this->bit(patterntrig[4],1) ){ pmtpattern++; if ( !this->checkPMT("S12_2A")){ pmtnosignal++; good = false;}}
1841 if ( this->bit(patterntrig[4],2) ){ pmtpattern++; if ( !this->checkPMT("S12_3A")){ pmtnosignal++; good = false;}}
1842 if ( this->bit(patterntrig[4],3) ){ pmtpattern++; if ( !this->checkPMT("S12_4A")){ pmtnosignal++; good = false;}}
1843 if ( this->bit(patterntrig[4],4) ){ pmtpattern++; if ( !this->checkPMT("S12_5A")){ pmtnosignal++; good = false;}}
1844 if ( this->bit(patterntrig[4],5) ){ pmtpattern++; if ( !this->checkPMT("S12_6A")){ pmtnosignal++; good = false;}}
1845 if ( this->bit(patterntrig[4],6) ){ pmtpattern++; if ( !this->checkPMT("S12_1A")){ pmtnosignal++; good = false;}}
1846 if ( this->bit(patterntrig[4],7) ){ pmtpattern++; if ( !this->checkPMT("S12_2A")){ pmtnosignal++; good = false;}}
1847 if ( this->bit(patterntrig[4],8) ){ pmtpattern++; if ( !this->checkPMT("S12_3A")){ pmtnosignal++; good = false;}}
1848 if ( this->bit(patterntrig[4],9) ){ pmtpattern++; if ( !this->checkPMT("S12_4B")){ pmtnosignal++; good = false;}}
1849 if ( this->bit(patterntrig[4],10) ){ pmtpattern++; if ( !this->checkPMT("S12_5B")){ pmtnosignal++; good = false;}}
1850 if ( this->bit(patterntrig[4],11) ){ pmtpattern++; if ( !this->checkPMT("S12_6B")){ pmtnosignal++; good = false;}}
1851 //S11
1852 if ( this->bit(patterntrig[5],0) ){ pmtpattern++; if ( !this->checkPMT("S11_1A")){ pmtnosignal++; good = false;}}
1853 if ( this->bit(patterntrig[5],1) ){ pmtpattern++; if ( !this->checkPMT("S11_2A")){ pmtnosignal++; good = false;}}
1854 if ( this->bit(patterntrig[5],2) ){ pmtpattern++; if ( !this->checkPMT("S11_3A")){ pmtnosignal++; good = false;}}
1855 if ( this->bit(patterntrig[5],3) ){ pmtpattern++; if ( !this->checkPMT("S11_4A")){ pmtnosignal++; good = false;}}
1856 if ( this->bit(patterntrig[5],4) ){ pmtpattern++; if ( !this->checkPMT("S11_5A")){ pmtnosignal++; good = false;}}
1857 if ( this->bit(patterntrig[5],5) ){ pmtpattern++; if ( !this->checkPMT("S11_6A")){ pmtnosignal++; good = false;}}
1858 if ( this->bit(patterntrig[5],6) ){ pmtpattern++; if ( !this->checkPMT("S11_7A")){ pmtnosignal++; good = false;}}
1859 if ( this->bit(patterntrig[5],7) ){ pmtpattern++; if ( !this->checkPMT("S11_8A")){ pmtnosignal++; good = false;}}
1860 if ( this->bit(patterntrig[5],8) ){ pmtpattern++; if ( !this->checkPMT("S11_1B")){ pmtnosignal++; good = false;}}
1861 if ( this->bit(patterntrig[5],9) ){ pmtpattern++; if ( !this->checkPMT("S11_2B")){ pmtnosignal++; good = false;}}
1862 if ( this->bit(patterntrig[5],10) ){ pmtpattern++; if ( !this->checkPMT("S11_3B")){ pmtnosignal++; good = false;}}
1863 if ( this->bit(patterntrig[5],11) ){ pmtpattern++; if ( !this->checkPMT("S11_4B")){ pmtnosignal++; good = false;}}
1864 if ( this->bit(patterntrig[5],12) ){ pmtpattern++; if ( !this->checkPMT("S11_5B")){ pmtnosignal++; good = false;}}
1865 if ( this->bit(patterntrig[5],13) ){ pmtpattern++; if ( !this->checkPMT("S11_6B")){ pmtnosignal++; good = false;}}
1866 if ( this->bit(patterntrig[5],14) ){ pmtpattern++; if ( !this->checkPMT("S11_7B")){ pmtnosignal++; good = false;}}
1867 if ( this->bit(patterntrig[5],15) ){ pmtpattern++; if ( !this->checkPMT("S11_8B")){ pmtnosignal++; good = false;}}
1868
1869 return good;
1870 }
1871
1872 bool ToFLevel2::checkPMTpmttrig(TrigLevel2 *trg){
1873 // UInt_t *patterntrig = trg->patterntrig;
1874 int rS11 = 0;
1875 int rS12 = 0;
1876 int rS21 = 0;
1877 int rS22 = 0;
1878 int rS31 = 0;
1879 int rS32 = 0;
1880
1881 // trigger configuration for the event from saved pmts
1882 TClonesArray* Pmt = this->PMT;
1883 for(int i=0; i<Pmt->GetEntries(); i++) {
1884 ToFPMT* pmthit = (ToFPMT*)Pmt->At(i);
1885 TString pmtname = this->GetPMTName(pmthit->pmt_id);
1886 if ( pmtname.Contains("S11") ) rS11++;
1887 if ( pmtname.Contains("S12") ) rS12++;
1888 if ( pmtname.Contains("S21") ) rS21++;
1889 if ( pmtname.Contains("S22") ) rS22++;
1890 if ( pmtname.Contains("S31") ) rS31++;
1891 if ( pmtname.Contains("S32") ) rS32++;
1892 }
1893 int rTOF1 = (rS11 + rS12) * (rS21 + rS22) * (rS31 + rS32);
1894 int rTOF2 = (rS11 * rS12) * (rS21 * rS22) * (rS31 * rS32);
1895
1896 int rTOF3 = (rS21 + rS22) * (rS31 + rS32);
1897 int rTOF4 = (rS21 * rS22) * (rS31 * rS32);
1898
1899 int rTOF5 = rS12 * (rS21 * rS22);
1900
1901 int rTOF6 = (rS11 + rS12) * (rS31 + rS32);
1902 int rTOF7 = (rS11 * rS12) * (rS31 * rS32);
1903
1904
1905 // trigger configuration of the run
1906 bool TCTOF1 = false;
1907 bool TCTOF2 = false;
1908 bool TCTOF3 = false;
1909 bool TCTOF4 = false;
1910 bool TCTOF5 = false;
1911 bool TCTOF6 = false;
1912 bool TCTOF7 = false;
1913 if ( trg->trigconf & (1<<0) ) TCTOF1 = true;
1914 if ( trg->trigconf & (1<<1) ) TCTOF2 = true;
1915 if ( trg->trigconf & (1<<2) ) TCTOF3 = true;
1916 if ( trg->trigconf & (1<<3) ) TCTOF4 = true;
1917 if ( trg->trigconf & (1<<4) ) TCTOF5 = true;
1918 if ( trg->trigconf & (1<<5) ) TCTOF6 = true;
1919 if ( trg->trigconf & (1<<6) ) TCTOF7 = true;
1920
1921 // do patterntrig pmts match the trigger configuration?
1922 bool pmtsconf_trigconf_match = true;
1923 if ( rTOF1 == 0 && TCTOF1 ) pmtsconf_trigconf_match = false;
1924 if ( rTOF2 == 0 && TCTOF2 ) pmtsconf_trigconf_match = false;
1925 if ( rTOF3 == 0 && TCTOF3 ) pmtsconf_trigconf_match = false;
1926 if ( rTOF4 == 0 && TCTOF4 ) pmtsconf_trigconf_match = false;
1927 if ( rTOF5 == 0 && TCTOF5 ) pmtsconf_trigconf_match = false;
1928 if ( rTOF6 == 0 && TCTOF6 ) pmtsconf_trigconf_match = false;
1929 if ( rTOF7 == 0 && TCTOF7 ) pmtsconf_trigconf_match = false;
1930
1931 return pmtsconf_trigconf_match;
1932 }
1933
1934 void ToFLevel2::printPMT(){
1935 TClonesArray* Pmt = this->PMT;
1936 for(int i=0; i<Pmt->GetEntries(); i++) {
1937 ToFPMT* pmthit = (ToFPMT*)Pmt->At(i);
1938 TString pmtname = this->GetPMTName(pmthit->pmt_id);
1939 printf(" PMT hit: %s \n",pmtname.Data());
1940 }
1941 }
1942
1943
1944 ToFdEdx::ToFdEdx()
1945 {
1946 memset(conn,0,12*sizeof(Bool_t));
1947 memset(ts,0,12*sizeof(UInt_t));
1948 memset(te,0,12*sizeof(UInt_t));
1949 eDEDXpmt = new TArrayF(48);
1950 Define_PMTsat();
1951 Clear();
1952 }
1953
1954 ToFdEdx::~ToFdEdx(){
1955 Clear();
1956 Delete();
1957 }
1958
1959 void ToFdEdx::Delete(Option_t *option){
1960 if ( eDEDXpmt ){
1961 eDEDXpmt->Set(0);
1962 if ( eDEDXpmt) delete eDEDXpmt;
1963 }
1964 }
1965
1966 //------------------------------------------------------------------------
1967 void ToFdEdx::CheckConnectors(UInt_t atime, GL_PARAM *glparam, TSQLServer *dbc)
1968 {
1969 for(int i=0; i<12; i++){
1970 if(atime<=ts[i] || atime>te[i]){
1971 Int_t error=glparam->Query_GL_PARAM(atime,210+i,dbc); // parameters stored in DB in GL_PRAM table
1972 if ( error<0 ) {
1973 conn[i]=false;
1974 ts[i]=0;
1975 te[i]=numeric_limits<UInt_t>::max();
1976 };
1977 if ( !error ){
1978 conn[i]=true;
1979 ts[i]=glparam->FROM_TIME;
1980 te[i]=glparam->TO_TIME;
1981 }
1982 if ( error>0 ){
1983 conn[i]=false;
1984 ts[i]=glparam->TO_TIME;
1985 TSQLResult *pResult;
1986 TSQLRow *row;
1987 TString query= Form("SELECT FROM_TIME FROM GL_PARAM WHERE TYPE=%i AND FROM_TIME>=%i ORDER BY FROM_TIME ASC LIMIT 1;",210+i,atime);
1988 pResult=dbc->Query(query.Data());
1989 if(!pResult->GetRowCount()){
1990 te[i]=numeric_limits<UInt_t>::max();
1991 }else{
1992 row=pResult->Next();
1993 te[i]=(UInt_t)atoll(row->GetField(0));
1994 }
1995 }
1996 //
1997
1998 }
1999 }
2000
2001 }
2002 //------------------------------------------------------------------------
2003 void ToFdEdx::Clear(Option_t *option)
2004 {
2005 //
2006 // Set arrays and initialize structure
2007 // eDEDXpmt.Set(48); eDEDXpmt.Reset(-1); // Set array size and reset structure
2008 eDEDXpmt->Set(48); eDEDXpmt->Reset(-1); // Set array size and reset structure
2009 //
2010 };
2011
2012 //------------------------------------------------------------------------
2013 void ToFdEdx::Print(Option_t *option)
2014 {
2015 //
2016 printf("========================================================================\n");
2017
2018 };
2019
2020 //------------------------------------------------------------------------
2021 void ToFdEdx::Init(pamela::tof::TofEvent *tofl0)
2022 {
2023 //
2024 ToFLevel2 tf;
2025 for (Int_t gg=0; gg<4;gg++){
2026 for (Int_t hh=0; hh<12;hh++){
2027 // tofinput_.tdc[hh][gg]=tofEvent->tdc[gg][hh];
2028 int mm = tf.GetPMTid(gg,hh);
2029 adc[mm]= (0xFFF & tofl0->adc[gg][hh]); // EM, exclude warning bits
2030 };
2031 };
2032
2033 };
2034
2035 //------------------------------------------------------------------------
2036 void ToFdEdx::Init(Int_t gg, Int_t hh, Float_t adce)
2037 {
2038 //
2039 ToFLevel2 tf;
2040 // for (Int_t gg=0; gg<4;gg++){
2041 // for (Int_t hh=0; hh<12;hh++){
2042 int mm = tf.GetPMTid(gg,hh);
2043 adc[mm]=adce;
2044
2045 };
2046 //------------------------------------------------------------------------
2047 void ToFdEdx::Process(UInt_t atime, Float_t betamean, Float_t *xtr_tof, Float_t *ytr_tof, Int_t exitat)
2048 {
2049 bool debug = false;
2050 if ( debug ) printf(" INSIDE TOFDEDX PROCESS \n");
2051 // the parameters should be already initialised by InitPar()
2052 // printf(" in process \n");
2053 Clear();
2054
2055 // define angle:
2056 double dx = xtr_tof[1] - xtr_tof[5];
2057 double dy = ytr_tof[0] - ytr_tof[4];
2058 double dr = sqrt(dx*dx+dy*dy);
2059 double theta=atan(dr/76.81);
2060 //
2061 if ( xtr_tof[1] > 99. || xtr_tof[5] > 99. || ytr_tof[0] > 99. || ytr_tof[4] > 99. ) theta = 0.;
2062 for (Int_t ii=0; ii<6; ii++){
2063 if ( xtr_tof[ii] > 99. ) xtr_tof[ii] = 0.;
2064 if ( ytr_tof[ii] > 99. ) ytr_tof[ii] = 0.;
2065 };
2066 //
2067 if ( debug ) printf(" theta %f \n",theta);
2068 if ( debug ) printf(" xtr_tof %.1f %.1f %.1f %.1f %.1f %.1f \n",xtr_tof[0],xtr_tof[1],xtr_tof[2],xtr_tof[3],xtr_tof[4],xtr_tof[5]);
2069 if ( debug ) printf(" ytr_tof %.1f %.1f %.1f %.1f %.1f %.1f \n",ytr_tof[0],ytr_tof[1],ytr_tof[2],ytr_tof[3],ytr_tof[4],ytr_tof[5]);
2070 //--------------------- TABLE OF PERIODS WITH HV PROBLEMS ----------------------------
2071
2072 int Aconn=conn[0]; // PMT 0,20,22,24
2073 int Bconn=conn[1]; // PMT 6,12,26,34
2074 int Cconn=conn[2]; // PMT 4,14,28,32
2075 int Dconn=conn[3]; // PMT 2,8,10,30
2076 int Econn=conn[4]; // PMT 42,43,44,47
2077 int Fconn=conn[5]; // PMT 7,19,23,27
2078 int Gconn=conn[6]; // PMT 3,11,25,33
2079 int Hconn=conn[7]; // PMT 1,9,13,21
2080 int Iconn=conn[8]; // PMT 5,29,31,35
2081 int Lconn=conn[9]; // PMT 37,40,45,46
2082 int Mconn=conn[10]; // PMT 15,16,17,18
2083 int Nconn=conn[11]; // PMT 36,38,39,41
2084 if( false ) cout << Gconn << Iconn << Lconn <<endl; // to avoid compilation warnings
2085
2086 // printf(" size %i \n",eDEDXpmt.GetSize());
2087 for( int ii=0; ii<48; ii++ ) {
2088 //
2089 // eDEDXpmt.SetAt(-1.,ii);
2090 // printf(" ii %i beta %f atime %u xtr 1 %f ytr 1 %f adc %f \n",ii,betamean,atime,xtr_tof[0],ytr_tof[0],adc[ii]);
2091 if ( debug ) printf("II %i adc %f \n",ii,adc[ii]);
2092
2093 if( adc[ii] >= 4095. ){
2094 // eDEDXpmt[ii] = 0.;
2095 eDEDXpmt->AddAt(0.,ii);
2096 if ( debug ) printf(" %i adc>4095 \n",ii);
2097 continue; // EMILIANO
2098 };
2099
2100 if( adc[ii] >= (PMTsat[ii]-5.) && adc[ii] < 4095. ){
2101 eDEDXpmt->AddAt(1000.,ii);
2102 if ( debug ) printf(" %i adc> pmtsat && adc<4095 \n",ii);
2103 continue; // EMILIANO
2104 };
2105
2106 if( adc[ii] <= 0. ) {
2107 eDEDXpmt->AddAt(1500.,ii);
2108 if ( debug ) printf(" %i adc<=0 \n",ii);
2109 continue;
2110 };
2111 //
2112 double adcpC = f_adcPC( adc[ii] ); // - adc conversion in pC
2113 if ( exitat == 0 ){
2114 eDEDXpmt->AddAt((Float_t)adcpC,ii);
2115 continue;
2116 }
2117 // printf(" e qua? \n");
2118
2119 double adccorr = adcpC*fabs(cos(theta));
2120 if ( debug ) printf(" adccorr %f \n",adccorr);
2121 if(adccorr<=0.){
2122 if ( debug ) printf(" %i adccorr<=0 \n",ii);
2123 // eDEDXpmt->AddAt((Float_t)adcpC,ii);//?
2124 continue;
2125 }
2126 if ( exitat == 1 ){
2127 eDEDXpmt->AddAt((Float_t)adccorr,ii);
2128 continue;
2129 }
2130 // printf(" e quo? \n");
2131
2132 // int standard=0;
2133 int S115B_ok=0;
2134 int S115B_break=0;
2135
2136 if(atime<1158720000)S115B_ok=1;
2137 else S115B_break=1;
2138
2139
2140 //------------------------------------------------------------------------
2141 // printf(" e qui? \n");
2142 //---------------------------------------------------- Z reconstruction
2143
2144 double adcHe, adcnorm, adclin, dEdx;//, Zeta; // EM GCC4.7
2145
2146 adcHe=-2;
2147 adcnorm=-2;
2148 adclin=-2;
2149 dEdx=-2;
2150 // Zeta=-2;//EM GCC4.7
2151 Double_t correction = 1.;
2152
2153 if(Aconn==1 && (ii==0 || ii==20 || ii==22 || ii==24)){
2154 correction = 1.675;
2155 }
2156 else if(Bconn==1 && (ii==6 || ii==12 || ii==26 || ii==34)){
2157 correction = 2.482;
2158 }
2159 else if(Cconn==1 && (ii==4 || ii==14 || ii==28 || ii==32)){
2160 correction = 1.464;
2161 }
2162 else if(Dconn==1 && (ii==2 || ii==8 || ii==10 || ii==30)){
2163 correction = 1.995;
2164 }
2165 else if(Econn==1 && (ii==42 || ii==43 || ii==44 || ii==47)){
2166 correction = 1.273;
2167 }
2168 else if(Fconn==1 && (ii==7 || ii==19 || ii==23 || ii==27)){
2169 correction = 1.565;
2170 }
2171 else if(Mconn==1 && (ii==15 || ii==16 || ii==17 || ii==18)){
2172 correction = 1.565;
2173 }
2174 else if(Nconn==1 && (ii==36 || ii==38 || ii==39 || ii==41)){
2175 correction = 1.018;
2176 }
2177 else if(Hconn==1 && (ii==1 || ii==13 || ii==21 || (ii==9&&S115B_ok==1))){
2178 correction = 1.84;
2179 }
2180 else if(S115B_break==1 && ii==9 && Hconn==1){
2181 correction = 1.64;
2182 }
2183 else correction = 1.;
2184
2185 if( ii==9 && S115B_break==1 ){
2186 adcHe = f_att5B( ytr_tof[0] )/correction;
2187 } else {
2188 adcHe = Get_adc_he(ii, xtr_tof, ytr_tof)/correction;
2189 };
2190 if(adcHe<=0){
2191 if ( debug ) printf(" %i adcHe<=0 \n",ii);
2192 // eDEDXpmt->AddAt((Float_t)adccorr,ii); //?
2193 continue;
2194 }
2195 if ( exitat == 2 ){
2196 if(ii==9 && S115B_break==1) eDEDXpmt->AddAt(36.*(Float_t)adccorr/adcHe,ii);
2197 else adclin = 4.*(Float_t)adccorr/adcHe;
2198 continue;
2199 }
2200
2201 if(ii==9 && S115B_break==1) adcnorm = f_pos5B(adccorr);
2202 else adcnorm = f_pos( (parPos[ii]), adccorr);
2203 if(adcnorm<=0){
2204 if ( debug ) printf(" %i adcnorm<=0 \n",ii);
2205 // eDEDXpmt->AddAt((Float_t)adccorr,ii);//?
2206 continue;
2207 }
2208 if ( debug ) printf(" adcnorm %f \n",adcnorm);
2209
2210 if(ii==9 && S115B_break==1) adclin = 36.*adcnorm/adcHe;
2211 else adclin = 4.*adcnorm/adcHe;
2212 if ( debug ) printf(" adclin %f \n",adclin);
2213 if(adclin<=0){
2214 if ( debug ) printf(" %i adclin<=0 \n",ii);
2215 // eDEDXpmt->AddAt((Float_t)adccorr,ii);//?
2216 continue;
2217 }
2218 if ( exitat == 3 ){
2219 if(ii==9 && S115B_break==1) eDEDXpmt->AddAt((Float_t)adclin,ii);
2220 else eDEDXpmt->AddAt((Float_t)adclin,ii);
2221 continue;
2222 }
2223 //
2224 if ( betamean > 99. ){
2225 // eDEDXpmt.AddAt((Float_t)adclin,ii);
2226 eDEDXpmt->AddAt((Float_t)adclin,ii);
2227 // printf(" AAPMT IS %i dedx is %f vector is %f \n",ii,adclin,eDEDXpmt[ii]);
2228 if ( debug ) printf(" %i betamean > 99 \n",ii);
2229 continue;
2230 };
2231 //
2232 double dEdxHe=-2;
2233 if(ii==9 && S115B_break==1){
2234 if( betamean <1. ) dEdxHe = f_BB5B( betamean );
2235 else dEdxHe = 33;
2236 } else {
2237 if( betamean <1. ) dEdxHe = f_BB( (parBBneg[ii]), betamean );
2238 else dEdxHe = parBBpos[ii];
2239 }
2240
2241 if ( debug ) printf(" dEdxHe %f \n",dEdxHe);
2242
2243 if(dEdxHe<=0){
2244 eDEDXpmt->AddAt((Float_t)adclin,ii);
2245 if ( debug ) printf(" %i dEdxHe<=0 \n",ii);
2246 continue;
2247 };
2248
2249 if(ii==9 && S115B_break==1) dEdx = f_desatBB5B( adclin );
2250 else dEdx = f_desatBB((parDesatBB[ii]), adclin );
2251
2252 if(dEdx<=0){
2253 eDEDXpmt->AddAt((Float_t)adclin,ii);
2254 if ( debug ) printf(" %i dEdx<=0 \n",ii);
2255 continue;
2256 };
2257
2258 if ( debug ) printf(" dEdx %f \n",dEdx);
2259 eDEDXpmt->AddAt((Float_t)dEdx,ii);
2260 // eDEDXpmt.AddAt((Float_t)dEdx,ii);
2261
2262 // printf(" PMT IS %i dedx is %f vector is %f \n",ii,dEdx,eDEDXpmt[ii]);
2263
2264 } //end loop on 48 PMT
2265
2266 };
2267
2268
2269 //------------------------------------------------------------------------
2270 void ToFdEdx::Define_PMTsat()
2271 {
2272 Float_t sat[48] = {
2273 3176.35,3178.19,3167.38,3099.73,3117.00,3126.29,3111.44,3092.27,
2274 3146.48,3094.41,3132.13,3115.37,3099.32,3110.97,3111.80,3143.14,
2275 3106.72,3153.44,3136.00,3188.96,3104.73,3140.45,3073.18,3106.62,
2276 3112.48,3146.92,3127.24,3136.52,3109.59,3112.89,3045.15,3147.26,
2277 3095.92,3121.05,3083.25,3123.62,3150.92,3125.30,3067.60,3160.18,
2278 3119.36,3108.92,3164.77,3133.64,3111.47,3131.98,3128.87,3135.56 };
2279 PMTsat.Set(48,sat);
2280 }
2281
2282 //------------------------------------------------------------------------
2283 void ToFdEdx::ReadParBBpos( const char *fname )
2284 {
2285 // printf("read %s\n",fname);
2286 parBBpos.Set(48);
2287 FILE *fattin = fopen( fname , "r" );
2288 for (int i=0; i<48; i++) {
2289 int tid=0;
2290 float tp;
2291 if(fscanf(fattin,"%d %f",
2292 &tid, &tp )!=2) break;
2293 parBBpos[i]=tp;
2294 }
2295 fclose(fattin);
2296 }
2297
2298 //------------------------------------------------------------------------
2299 void ToFdEdx::ReadParDesatBB( const char *fname )
2300 {
2301 // printf("read %s\n",fname);
2302 FILE *fattin = fopen( fname , "r" );
2303 for (int i=0; i<48; i++) {
2304 int tid=0;
2305 float tp[3];
2306 if(fscanf(fattin,"%d %f %f %f",
2307 &tid, &tp[0], &tp[1], &tp[2] )!=4) break;
2308 parDesatBB[i].Set(3,tp);
2309 }
2310 fclose(fattin);
2311 }
2312
2313
2314 //------------------------------------------------------------------------
2315 void ToFdEdx::ReadParBBneg( const char *fname )
2316
2317 {
2318 // printf("read %s\n",fname);
2319 FILE *fattin = fopen( fname , "r" );
2320 for (int i=0; i<48; i++) {
2321 int tid=0;
2322 float tp[3];
2323 if(fscanf(fattin,"%d %f %f %f",
2324 &tid, &tp[0], &tp[1], &tp[2] )!=4) break;
2325 parBBneg[i].Set(3,tp);
2326 }
2327 fclose(fattin);
2328 }
2329
2330 //------------------------------------------------------------------------
2331 void ToFdEdx::ReadParPos( const char *fname )
2332 {
2333 // printf("read %s\n",fname);
2334 FILE *fattin = fopen( fname , "r" );
2335 for (int i=0; i<48; i++) {
2336 int tid=0;
2337 float tp[4];
2338 if(fscanf(fattin,"%d %f %f %f %f",
2339 &tid, &tp[0], &tp[1], &tp[2], &tp[3])!=5) break;
2340 parPos[i].Set(4,tp);
2341 }
2342 fclose(fattin);
2343 }
2344
2345 //------------------------------------------------------------------------
2346 void ToFdEdx::ReadParAtt( const char *fname )
2347 {
2348 // printf("read %s\n",fname);
2349 FILE *fattin = fopen( fname , "r" );
2350 for (int i=0; i<48; i++) {
2351 int tid=0;
2352 float tp[6];
2353 if(fscanf(fattin,"%d %f %f %f %f %f %f",
2354 &tid, &tp[0], &tp[1], &tp[2], &tp[3], &tp[4], &tp[5] )!=7) break;
2355 parAtt[i].Set(6,tp);
2356 }
2357 fclose(fattin);
2358 }
2359
2360
2361
2362
2363
2364
2365 double ToFdEdx::f_att( TArrayF &p, float x )
2366 {
2367 return
2368 p[0] +
2369 p[1]*x +
2370 p[2]*x*x +
2371 p[3]*x*x*x +
2372 p[4]*x*x*x*x +
2373 p[5]*x*x*x*x*x;
2374 }
2375 //------------------------------------------------------------------------
2376 double ToFdEdx::f_att5B( float x )
2377 {
2378 return
2379 101.9409 +
2380 6.643781*x +
2381 0.2765518*x*x +
2382 0.004617647*x*x*x +
2383 0.0006195132*x*x*x*x +
2384 0.00002813734*x*x*x*x*x;
2385 }
2386
2387
2388 double ToFdEdx::f_pos( TArrayF &p, float x )
2389 {
2390 return
2391 p[0] +
2392 p[1]*x +
2393 p[2]*x*x +
2394 p[3]*x*x*x;
2395 }
2396
2397 double ToFdEdx::f_pos5B( float x )
2398 {
2399 return
2400 15.45132 +
2401 0.8369721*x +
2402 0.0005*x*x;
2403 }
2404
2405
2406
2407 double ToFdEdx::f_adcPC( float x )
2408 {
2409 return 28.12+0.6312*x-5.647e-05*x*x+3.064e-08*x*x*x;
2410 }
2411
2412
2413 float ToFdEdx::Get_adc_he( int id, float pl_x[6], float pl_y[6])
2414 {
2415
2416 //
2417 // input: id - pmt [0:47}
2418 // pl_x - coord x of the tof plane
2419 // pl_y - coord y
2420
2421 adc_he = 0;
2422 if( eGeom.GetXY(id)==1 ) adc_he = f_att( (parAtt[id]), pl_x[eGeom.GetPlane(id)] );
2423 if( eGeom.GetXY(id)==2 ) adc_he = f_att( (parAtt[id]), pl_y[eGeom.GetPlane(id)] );
2424 return adc_he;
2425 }
2426
2427 //------------------------------------------------------------------------
2428 double ToFdEdx::f_BB( TArrayF &p, float x )
2429 {
2430 return p[0]/(x*x)*(log(x*x/(1-x*x)) - p[1]*x*x - p[2]);
2431 }
2432
2433 //------------------------------------------------------------------------
2434 double ToFdEdx::f_BB5B( float x )
2435 {
2436 return 0.165797/(x*x)*(log(x*x/(1-x*x)) + 140.481*x*x + 52.9258);
2437 }
2438 //------------------------------------------------------------------------
2439 double ToFdEdx::f_desatBB( TArrayF &p, float x )
2440 {
2441 return
2442 p[0] +
2443 p[1]*x +
2444 p[2]*x*x;
2445 }
2446
2447 //------------------------------------------------------------------------
2448 double ToFdEdx::f_desatBB5B( float x )
2449 {
2450 return
2451 -2.4 +
2452 0.75*x +
2453 0.009*x*x;
2454 }
2455

  ViewVC Help
Powered by ViewVC 1.1.23