/[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.25 - (show annotations) (download)
Wed Apr 15 10:05:22 2009 UTC (15 years, 7 months ago) by pamelats
Branch: MAIN
Changes since 1.24: +6 -5 lines
bugfix in method GetPaddlePlane

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(ToFTrkVar);
15 ClassImp(ToFLevel2);
16
17 ToFPMT::ToFPMT(){
18 pmt_id = 0;
19 adc = 0.;
20 tdc_tw = 0.;
21 tdc = 0.;
22 }
23
24 ToFPMT::ToFPMT(const ToFPMT &t){
25 pmt_id = t.pmt_id;
26 adc = t.adc;
27 tdc_tw = t.tdc_tw;
28 tdc = t.tdc;
29 }
30
31 void ToFPMT::Clear(Option_t *t){
32 pmt_id = 0;
33 adc = 0.;
34 tdc_tw = 0.;
35 tdc = 0.;
36 }
37
38
39
40 ToFTrkVar::ToFTrkVar() {
41 trkseqno = 0;
42 npmttdc = 0;
43 npmtadc = 0;
44 pmttdc = TArrayI(48);
45 pmtadc = TArrayI(48);
46 tdcflag = TArrayI(48); // gf: 30 Nov 2006
47 adcflag = TArrayI(48); // gf: 30 Nov 2006
48 dedx = TArrayF(48);
49 //
50 //
51 memset(beta, 0, 13*sizeof(Float_t));
52 memset(xtofpos, 0, 3*sizeof(Float_t));
53 memset(ytofpos, 0, 3*sizeof(Float_t));
54 memset(xtr_tof, 0, 6*sizeof(Float_t));
55 memset(ytr_tof, 0, 6*sizeof(Float_t));
56 //
57 };
58
59 void ToFTrkVar::Clear(Option_t *t) {
60 trkseqno = 0;
61 npmttdc = 0;
62 npmtadc = 0;
63 pmttdc.Reset();
64 pmtadc.Reset();
65 tdcflag.Reset(); // gf: 30 Nov 2006
66 adcflag.Reset(); // gf: 30 Nov 2006
67 dedx.Reset();
68 //
69 memset(beta, 0, 13*sizeof(Float_t));
70 memset(xtofpos, 0, 3*sizeof(Float_t));
71 memset(ytofpos, 0, 3*sizeof(Float_t));
72 memset(xtr_tof, 0, 6*sizeof(Float_t));
73 memset(ytr_tof, 0, 6*sizeof(Float_t));
74 //
75 };
76
77 ToFTrkVar::ToFTrkVar(const ToFTrkVar &t){
78
79 trkseqno = t.trkseqno;
80 //
81 npmttdc = t.npmttdc;
82 npmtadc = t.npmtadc;
83 (t.pmttdc).Copy(pmttdc);
84 (t.pmtadc).Copy(pmtadc);
85 (t.tdcflag).Copy(tdcflag); // gf: 30 Nov 2006
86 (t.adcflag).Copy(adcflag); // gf: 30 Nov 2006
87 (t.dedx).Copy(dedx);
88 //
89 memcpy(beta,t.beta,sizeof(beta));
90 memcpy(xtofpos,t.xtofpos,sizeof(xtofpos));
91 memcpy(ytofpos,t.ytofpos,sizeof(ytofpos));
92 memcpy(xtr_tof,t.xtr_tof,sizeof(xtr_tof));
93 memcpy(ytr_tof,t.ytr_tof,sizeof(ytr_tof));
94 //
95 };
96
97 ToFLevel2::ToFLevel2() {
98 //
99 // PMT = new TClonesArray("ToFPMT",12); //ELENA
100 // ToFTrk = new TClonesArray("ToFTrkVar",2); //ELENA
101 PMT = 0; //ELENA
102 ToFTrk = 0; //ELENA
103 //
104 this->Clear();
105 //
106 };
107
108 void ToFLevel2::Set(){//ELENA
109 if(!PMT)PMT = new TClonesArray("ToFPMT",12); //ELENA
110 if(!ToFTrk)ToFTrk = new TClonesArray("ToFTrkVar",2); //ELENA
111 }//ELENA
112
113 void ToFLevel2::Clear(Option_t *t){
114 //
115 if(ToFTrk)ToFTrk->Delete(); //ELENA
116 if(PMT)PMT->Delete(); //ELENA
117 memset(tof_j_flag, 0, 6*sizeof(Int_t));
118 unpackError = 0;
119 //
120 };
121
122 void ToFLevel2::Delete(Option_t *t){ //ELENA
123 //
124 if(ToFTrk){
125 ToFTrk->Delete(); //ELENA
126 delete ToFTrk; //ELENA
127 }
128 if(PMT){
129 PMT->Delete(); //ELENA
130 delete PMT; //ELENA
131 } //ELENA
132 //
133 }; //ELENA
134
135 ToFTrkVar *ToFLevel2::GetToFTrkVar(Int_t itrk){
136 //
137 if(itrk >= ntrk()){
138 printf(" ToFLevel2 ERROR: track related variables set %i does not exists! \n",itrk);
139 printf(" stored track related variables = %i \n",ntrk());
140 return(NULL);
141 }
142 //
143 if(!ToFTrk)return 0; //ELENA
144 TClonesArray &t = *(ToFTrk);
145 ToFTrkVar *toftrack = (ToFTrkVar*)t[itrk];
146 return toftrack;
147 }
148
149 ToFPMT *ToFLevel2::GetToFPMT(Int_t ihit){
150 //
151 if(ihit >= npmt()){
152 printf(" ToFLevel2 ERROR: pmt variables set %i does not exists! \n",ihit);
153 printf(" stored pmt variables = %i \n",npmt());
154 return(NULL);
155 }
156 //
157 if(!PMT)return 0; //ELENA
158 TClonesArray &t = *(PMT);
159 ToFPMT *tofpmt = (ToFPMT*)t[ihit];
160 return tofpmt;
161 }
162 //--------------------------------------
163 //
164 //
165 //--------------------------------------
166 /**
167 * Method to get the plane ID (11 12 21 22 31 32) from the plane index (0 1 2 3 4 5)
168 * @param Plane index (0,1,2,3,4,5).
169 */
170 Int_t ToFLevel2::GetToFPlaneID(Int_t ip){
171 if(ip>=0 && ip<6)return 10*((int)(ip/2+1.1))+(ip%2)+1;
172 else return -1;
173 };
174 /**
175 * Method to get the plane index (0 1 2 3 4 5) from the plane ID (11 12 21 22 31 32)
176 * @param plane Plane ID (11, 12, 21, 22, 31, 32)
177 */
178 Int_t ToFLevel2::GetToFPlaneIndex(Int_t plane_id){
179 if(
180 plane_id == 11 ||
181 plane_id == 12 ||
182 plane_id == 21 ||
183 plane_id == 22 ||
184 plane_id == 31 ||
185 plane_id == 32 ||
186 false)return (Int_t)(plane_id/10)*2-1- plane_id%2;
187 else return -1;
188 };
189 /**
190 * Method to know if a given ToF paddle was hit, that is there is a TDC signal
191 * from both PMTs. The method uses the "tof_j_flag" variable.
192 * @param plane Plane ID (11, 12, 21, 22, 31, 32) or Plane index (0,1,2,3,4,5).
193 * @param paddle_id Paddle ID.
194 * @return 1 if the paddle was hit.
195 */
196 Bool_t ToFLevel2::HitPaddle(Int_t plane, Int_t paddle_id){ //<<< NEW
197 Int_t ip = -1;
198 if (plane>=6 ) ip = GetToFPlaneIndex(plane);
199 else if(plane>=0 && plane < 6) ip = plane;
200 Int_t flag=0;
201 if(ip != -1)flag = tof_j_flag[ip] & (int)pow(2.,(double)paddle_id);
202 if(
203 (ip == 0 && paddle_id < 8 && flag) ||
204 (ip == 1 && paddle_id < 6 && flag) ||
205 (ip == 2 && paddle_id < 2 && flag) ||
206 (ip == 3 && paddle_id < 2 && flag) ||
207 (ip == 4 && paddle_id < 3 && flag) ||
208 (ip == 5 && paddle_id < 3 && flag) ||
209 false) return true;
210 else return false;
211 };
212 /**
213 * Method to get the number of hit paddles on a ToF plane.
214 * @param plane Plane ID (11, 12, 21, 22, 31, 32) or Plane index (0,1,2,3,4,5).
215 */
216 Int_t ToFLevel2::GetNHitPaddles(Int_t plane){
217 Int_t npad=0;
218 for(Int_t i=0; i<8; i++)npad = npad + (int)HitPaddle(plane,i);
219 return npad;
220 };
221
222 //wm Nov 08
223 //gf Apr 07
224 /**
225 * Method to get the mean dEdx from a ToF layer - ATTENTION:
226 * It will sum up the dEdx of all the paddles, but since by definition
227 * only the paddle hitted by the track gets a dEdx value and the other
228 * paddles are set to zero, the output is just the dEdx of the hitted
229 * paddle in each layer!
230 * The "adcfl" option is not very useful (an artificial dEdx is per
231 * definition= 1 mip and not a real measurement), anyway left in the code
232 * @param notrack Track Number
233 * @param plane Plane index (0,1,2,3,4,5)
234 * @param adcflag in the plane (100<-> independent of the adcflag; !=0&&!=100 <-> at least one PMT with adcflag!=0; )
235 */
236 Float_t ToFLevel2::GetdEdx(Int_t notrack, Int_t plane, Int_t adcfl){
237
238 Float_t dedx = 0.;
239 Float_t PadEdx =0.;
240 Int_t SatWarning;
241 Int_t pad=-1;
242 //
243 ToFTrkVar *trk = GetToFTrkVar(notrack);
244 if(!trk) return 0; //ELENA
245 //
246 for (Int_t ii=0; ii<GetNPaddle(plane); ii++){
247 Int_t paddleid=ii;
248 pad = GetPaddleid(plane,paddleid);
249 GetdEdxPaddle(notrack, pad, adcfl, PadEdx, SatWarning);
250 dedx += PadEdx;
251 };
252 //
253 return(dedx);
254 };
255
256 /**
257 * Method to fill the ADC_C 4x12 matrix with the dEdx values and the TDC 4x12 matrix
258 * with the time-walk corrected TDC values.
259 * @param notrack Track Number
260 * @param adc ADC_C matrix with dEdx values
261 * @param tdc TDC matrix
262 */
263 void ToFLevel2::GetMatrix(Int_t notrack, Float_t adc[4][12], Float_t tdc[4][12]){
264 //
265 for (Int_t aa=0; aa<4;aa++){
266 for (Int_t bb=0; bb<12;bb++){
267 adc[aa][bb] = 1000.;
268 tdc[aa][bb] = 4095.;
269 };
270 };
271 //
272 Int_t pmt_id = 0;
273 Int_t hh = 0;
274 Int_t kk = 0;
275 //
276 ToFTrkVar *trk = GetToFTrkVar(notrack);
277 if(!trk)return; //ELENA
278 //
279 for (Int_t i=0; i<trk->npmtadc; i++){
280 //
281 pmt_id = (trk->pmtadc).At(i);
282 //
283 GetPMTIndex(pmt_id,hh,kk);
284 adc[kk][hh] = (trk->dedx).At(i);
285 //
286 };
287 //
288 for (Int_t i=0; i<npmt(); i++){
289 //
290 ToFPMT *pmt = GetToFPMT(i);
291 if(!pmt)break; //ELENA
292 //
293 GetPMTIndex(pmt->pmt_id,hh,kk);
294 //
295 tdc[kk][hh] = pmt->tdc_tw;
296 //
297 };
298 //
299 return;
300 };
301
302
303 /**
304 * Method to get the plane index (0 - 5) for the PMT_ID as input
305 * @param pmt_id PMT_ID (0 - 47)
306 */
307 Int_t ToFLevel2::GetPlaneIndex(Int_t pmt_id){
308 TString pmtname = GetPMTName(pmt_id);
309 pmtname.Resize(3);
310 if ( !strcmp(pmtname,"S11") ) return(0);
311 if ( !strcmp(pmtname,"S12") ) return(1);
312 if ( !strcmp(pmtname,"S21") ) return(2);
313 if ( !strcmp(pmtname,"S22") ) return(3);
314 if ( !strcmp(pmtname,"S31") ) return(4);
315 if ( !strcmp(pmtname,"S32") ) return(5);
316 return(-1);
317 };
318
319
320 /**
321 * Method to get the PMT_ID if the index (4,12) is given. We have 4 channels on
322 * each of the 12 half-boards, this method decodes which PMT is cables to which
323 * channel.
324 * @param hh Channel
325 * @param kk HalfBoard
326 */
327 Int_t ToFLevel2::GetPMTid(Int_t hh, Int_t kk){
328 //
329 short tof[4][24] = {
330 {4, 4, 4, 4, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 2, 3, 3, 3, 3, 4},
331 {1, 3, 5, 7, 10, 12, 2, 4, 2, 4, 6, 8, 10, 12, 1, 5, 3, 9, 7, 9, 11, 1, 5, 9},
332 {2, 2, 2, 2, 1, 1, 1, 1, 4, 4, 4, 4, 4, 4, 2, 1, 2, 1, 2, 2, 2, 3, 3, 4},
333 {6, 8, 12, 10, 8, 6, 4, 2, 12, 10, 8, 6, 4, 2, 9, 7, 11, 11, 5, 3, 1, 3, 7, 11}
334 };
335 //
336 Int_t ind = 0;
337 Int_t k = 0;
338 while (k < 24){
339 Int_t j = 0;
340 while (j < 2){
341 Int_t ch = tof[2*j][k] - 1;
342 Int_t hb = tof[2*j + 1][k] - 1;
343 /* tofEvent->tdc[ch][hb] */
344 if( ch == hh && hb == kk ){
345 ind = 2*k + j;
346 break;
347 };
348 j++;
349 };
350 k++;
351 };
352 return ind;
353 };
354
355
356 /**
357 * Method to get the PMT index if the PMT ID is given. This method is the
358 * "reverse" of method "GetPMTid"
359 * @param ind PMT_ID (0 - 47)
360 * @param hb HalfBoard
361 * @param ch Channel
362 */
363 void ToFLevel2::GetPMTIndex(Int_t ind, Int_t &hb, Int_t &ch){
364 //
365 short tof[4][24] = {
366 {4, 4, 4, 4, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 2, 3, 3, 3, 3, 4},
367 {1, 3, 5, 7, 10, 12, 2, 4, 2, 4, 6, 8, 10, 12, 1, 5, 3, 9, 7, 9, 11, 1, 5, 9},
368 {2, 2, 2, 2, 1, 1, 1, 1, 4, 4, 4, 4, 4, 4, 2, 1, 2, 1, 2, 2, 2, 3, 3, 4},
369 {6, 8, 12, 10, 8, 6, 4, 2, 12, 10, 8, 6, 4, 2, 9, 7, 11, 11, 5, 3, 1, 3, 7, 11}
370 };
371 //
372 Int_t k = 0;
373 while (k < 24){
374 Int_t j = 0;
375 while (j < 2){
376 /* tofEvent->tdc[ch][hb] */
377 if( ind == 2*k + j ){
378 ch = tof[2*j][k] - 1;
379 hb = tof[2*j + 1][k] - 1;
380 return;
381 };
382 j++;
383 };
384 k++;
385 };
386 return;
387 };
388
389
390
391 // wm Nov 08 revision - saturation values included
392 /// gf Apr 07
393 /**
394 * Method to get the dEdx from a given ToF paddle.
395 * If two PMTs are good, the mean dEdx of both PMTs is taken, otherwise
396 * just the dEdx of the "good" PMT. If both PMTs are above saturation => dEdx=1000
397 * @param notrack Track Number
398 * @param Paddle index (0,1,...,23).
399 * @param adcflag in the paddle (100<-> independent of the adcflag; !=0&&!=100 <-> at least one PMT with adcflag!=0; )
400 * @param PadEdx dEdx from a given ToF paddle
401 * @param SatWarning 1 if the PMT ios near saturation region (adcraw ~3000)
402 */
403 void ToFLevel2::GetdEdxPaddle(Int_t notrack, Int_t paddleid, Int_t adcfl, Float_t &PadEdx, Int_t &SatWarning){
404
405 /*
406 Float_t PMTsat[48] = {
407 3162.14, 3165.48, 3153.85, 3085.73, 3089.65, 3107.64, 3097.52, 3078.37,
408 3130.05, 3087.07, 3112.22, 3102.92, 3080.58, 3092.55, 3087.94, 3125.03,
409 3094.09, 3143.16, 3125.51, 3181.27, 3092.09, 3124.98, 3069.3, 3095.53,
410 3097.11, 3133.53, 3114.73, 3113.01, 3091.19, 3097.99, 3033.84, 3134.98,
411 3081.37, 3111.04, 3066.77, 3108.17, 3133, 3111.06, 3052.52, 3140.66,
412 3106.33, 3094.85, 3150.85, 3118.8, 3096.24, 3118.47,3111.36, 3117.11 } ;
413 */
414
415 // new values from Napoli dec 2008
416 Float_t PMTsat[48] = {
417 3176.35,3178.19,3167.38,3099.73,3117.00,3126.29,3111.44,3092.27,
418 3146.48,3094.41,3132.13,3115.37,3099.32,3110.97,3111.80,3143.14,
419 3106.72,3153.44,3136.00,3188.96,3104.73,3140.45,3073.18,3106.62,
420 3112.48,3146.92,3127.24,3136.52,3109.59,3112.89,3045.15,3147.26,
421 3095.92,3121.05,3083.25,3123.62,3150.92,3125.30,3067.60,3160.18,
422 3119.36,3108.92,3164.77,3133.64,3111.47,3131.98,3128.87,3135.56 };
423
424 for (Int_t i=0; i<48;i++) PMTsat[i] = PMTsat[i] - 5.; // safety margin
425
426
427 PadEdx = 0.;
428 // SatWarning = 1000;
429 SatWarning = 0; // 0=good, increase for each bad PMT
430
431 Float_t dEdx[48] = {0};
432 Int_t pmt_id = -1;
433 Float_t adcraw[48];
434 //
435 ToFTrkVar *trk = GetToFTrkVar(notrack);
436 if(!trk) return; //ELENA
437 //
438
439 Int_t pmtleft=-1;
440 Int_t pmtright=-1;
441 GetPaddlePMT(paddleid, pmtleft, pmtright);
442
443 adcraw[pmtleft] = 4095;
444 adcraw[pmtright] = 4095;
445
446
447 for (Int_t jj=0; jj<npmt(); jj++){
448
449 ToFPMT *pmt = GetToFPMT(jj);
450 if(!pmt)break; //ELENA
451
452 pmt_id = pmt->pmt_id;
453 if(pmt_id==pmtleft){
454 adcraw[pmtleft] = pmt->adc;
455 }
456
457 if(pmt_id==pmtright){
458 adcraw[pmtright] = pmt->adc;
459 }
460 }
461
462
463 for (Int_t i=0; i<trk->npmtadc; i++){
464
465 if((trk->adcflag).At(i)==0 || adcfl==100){
466 if((trk->pmtadc).At(i) == pmtleft)dEdx[pmtleft] = (trk->dedx).At(i);
467 if((trk->pmtadc).At(i) == pmtright)dEdx[pmtright] = (trk->dedx).At(i);
468 }else{
469 if((trk->pmtadc).At(i) == pmtleft)dEdx[pmtleft] = 0.;
470 if((trk->pmtadc).At(i) == pmtright)dEdx[pmtright] = 0.;
471 }
472 }
473
474
475 // if( adcraw[pmtleft] >3000 || adcraw[pmtright] >3000)SatWarning=1; //old version
476
477 // Increase SatWarning Counter for each PMT>Sat
478 if( adcraw[pmtleft] > PMTsat[pmtleft])SatWarning++;
479 if( adcraw[pmtright] > PMTsat[pmtright])SatWarning++;
480
481 // if ADC > sat set dEdx=1000
482 if( adcraw[pmtleft] > PMTsat[pmtleft]) dEdx[pmtleft] = 1000.;
483 if( adcraw[pmtright] > PMTsat[pmtright]) dEdx[pmtright] = 1000. ;
484
485 // if two PMT are good, take mean dEdx, otherwise only the good dEdx
486 if(dEdx[pmtleft]<1000 && dEdx[pmtright]<1000) PadEdx = (dEdx[pmtleft]+dEdx[pmtright])*0.5;
487 if(dEdx[pmtleft]==1000 && dEdx[pmtright]<1000) PadEdx = dEdx[pmtright];
488 if(dEdx[pmtleft]<1000 && dEdx[pmtright]==1000) PadEdx = dEdx[pmtleft];
489
490 };
491 //
492
493
494 // gf Apr 07
495
496 /**
497 * Method to get the PMT name (like "S11_1A") if the PMT_ID is given.
498 * Indexes of corresponding plane, paddle and pmt are also given as output.
499 * @param ind PMT_ID (0 - 47)
500 * @param iplane plane index (0 - 5)
501 * @param ipaddle paddle index (relative to the plane)
502 * @param ipmt pmt index (0(A), 1(B))
503 */
504 TString ToFLevel2::GetPMTName(Int_t ind, Int_t &iplane, Int_t &ipaddle,Int_t &ipmt){
505
506 TString pmtname = " ";
507
508 TString photoS[48] = {
509 "S11_1A", "S11_1B", "S11_2A", "S11_2B", "S11_3A", "S11_3B", "S11_4A",
510 "S11_4B",
511 "S11_5A", "S11_5B", "S11_6A", "S11_6B", "S11_7A", "S11_7B", "S11_8A",
512 "S11_8B",
513 "S12_1A", "S12_1B", "S12_2A", "S12_2B", "S12_3A", "S12_3B", "S12_4A",
514 "S12_4B", "S12_5A", "S12_5B", "S12_6A", "S12_6B",
515 "S21_1A", "S21_1B", "S21_2A", "S21_2B",
516 "S22_1A", "S22_1B", "S22_2A", "S22_2B",
517 "S31_1A", "S31_1B", "S31_2A", "S31_2B", "S31_3A", "S31_3B",
518 "S32_1A", "S32_1B", "S32_2A", "S32_2B", "S32_3A", "S32_3B"
519 };
520
521
522 pmtname = photoS[ind].Data();
523
524 TString ss = pmtname(1,2);
525 iplane = (int)(atoi(ss.Data())/10)*2-3+atoi(ss.Data())%10;
526 ss = pmtname(4);
527 ipaddle = atoi(ss.Data())-1 ;
528 if( pmtname.Contains("A") )ipmt=0;
529 if( pmtname.Contains("B") )ipmt=1;
530
531 return pmtname;
532 };
533 /**
534 * Method to get the PMT name (like "S11_1A") if the PMT_ID is given
535 * @param ind PMT_ID (0 - 47)
536 */
537 TString ToFLevel2::GetPMTName(Int_t ind){
538
539 Int_t iplane = -1;
540 Int_t ipaddle = -1;
541 Int_t ipmt = -1;
542 return GetPMTName(ind,iplane,ipaddle,ipmt);
543
544 };
545
546 // wm jun 08
547 Int_t ToFLevel2::GetPaddleIdOfTrack(Float_t xtr, Float_t ytr, Int_t plane){
548 return GetPaddleIdOfTrack(xtr ,ytr ,plane, 0.4);
549 }
550
551 // gf Apr 07
552 Int_t ToFLevel2::GetPaddleIdOfTrack(Float_t xtr, Float_t ytr, Int_t plane, Float_t margin){
553
554 Double_t xt,yt,xl,xh,yl,yh;
555
556 Float_t tof11_x[8] = {-17.85,-12.75,-7.65,-2.55,2.55,7.65,12.75,17.85};
557 Float_t tof12_y[6] = { -13.75,-8.25,-2.75,2.75,8.25,13.75};
558 Float_t tof21_y[2] = { 3.75,-3.75};
559 Float_t tof22_x[2] = { -4.5,4.5};
560 Float_t tof31_x[3] = { -6.0,0.,6.0};
561 Float_t tof32_y[3] = { -5.0,0.0,5.0};
562
563 // S11 8 paddles 33.0 x 5.1 cm
564 // S12 6 paddles 40.8 x 5.5 cm
565 // S21 2 paddles 18.0 x 7.5 cm
566 // S22 2 paddles 15.0 x 9.0 cm
567 // S31 3 paddles 15.0 x 6.0 cm
568 // S32 3 paddles 18.0 x 5.0 cm
569
570 Int_t paddleidoftrack=-1;
571 //
572
573 //--- S11 ------
574
575 if(plane==0){
576 xt = xtr;
577 yt = ytr;
578 paddleidoftrack=-1;
579 yl = -33.0/2. ;
580 yh = 33.0/2. ;
581 if ((yt>yl)&&(yt<yh)) {
582 for (Int_t i1=0; i1<8;i1++){
583 xl = tof11_x[i1] - (5.1-margin)/2. ;
584 xh = tof11_x[i1] + (5.1-margin)/2. ;
585 if ((xt>xl)&&(xt<xh)) paddleidoftrack=i1;
586 }
587 }
588 }
589 // cout<<"S11 "<<paddleidoftrack[0]<<"\n";
590
591 //--- S12 -------
592 if(plane==1){
593 xt = xtr;
594 yt = ytr;
595 paddleidoftrack=-1;
596 xl = -40.8/2. ;
597 xh = 40.8/2. ;
598
599 if ((xt>xl)&&(xt<xh)) {
600 for (Int_t i1=0; i1<6;i1++){
601 yl = tof12_y[i1] - (5.5-margin)/2. ;
602 yh = tof12_y[i1] + (5.5-margin)/2. ;
603 if ((yt>yl)&&(yt<yh)) paddleidoftrack=i1;
604 }
605 }
606 }
607
608 //--- S21 ------
609
610 if(plane==2){
611 xt = xtr;
612 yt = ytr;
613 paddleidoftrack=-1;
614 xl = -18./2. ;
615 xh = 18./2. ;
616
617 if ((xt>xl)&&(xt<xh)) {
618 for (Int_t i1=0; i1<2;i1++){
619 yl = tof21_y[i1] - (7.5-margin)/2. ;
620 yh = tof21_y[i1] + (7.5-margin)/2. ;
621 if ((yt>yl)&&(yt<yh)) paddleidoftrack=i1;
622 }
623 }
624 }
625
626 //--- S22 ------
627 if(plane==3){
628 xt = xtr;
629 yt = ytr;
630 paddleidoftrack=-1;
631 yl = -15./2. ;
632 yh = 15./2. ;
633
634 if ((yt>yl)&&(yt<yh)) {
635 for (Int_t i1=0; i1<2;i1++){
636 xl = tof22_x[i1] - (9.0-margin)/2. ;
637 xh = tof22_x[i1] + (9.0-margin)/2. ;
638 if ((xt>xl)&&(xt<xh)) paddleidoftrack=i1;
639 }
640 }
641 }
642
643 //--- S31 ------
644 if(plane==4){
645 xt = xtr;
646 yt = ytr;
647 paddleidoftrack=-1;
648 yl = -15.0/2. ;
649 yh = 15.0/2. ;
650
651 if ((yt>yl)&&(yt<yh)) {
652 for (Int_t i1=0; i1<3;i1++){
653 xl = tof31_x[i1] - (6.0-margin)/2. ;
654 xh = tof31_x[i1] + (6.0-margin)/2. ;
655 if ((xt>xl)&&(xt<xh)) paddleidoftrack=i1;
656 }
657 }
658 }
659
660 //--- S32 ------
661 if(plane==5){
662 xt = xtr;
663 yt = ytr;
664 paddleidoftrack=-1;
665 xl = -18.0/2. ;
666 xh = 18.0/2. ;
667
668 if ((xt>xl)&&(xt<xh)) {
669 for (Int_t i1=0; i1<3;i1++){
670 yl = tof32_y[i1] - (5.0-margin)/2. ;
671 yh = tof32_y[i1] + (5.0-margin)/2. ;
672 if ((yt>yl)&&(yt<yh)) paddleidoftrack=i1;
673 }
674 }
675 }
676
677 return paddleidoftrack;
678
679 }
680
681 //
682
683 // gf Apr 07
684
685 void ToFLevel2::GetPMTPaddle(Int_t pmt_id, Int_t &plane, Int_t &paddle){
686
687 plane = GetPlaneIndex(pmt_id);
688
689 if(plane == 0){
690 if(pmt_id==0 || pmt_id==1)paddle=0;
691 if(pmt_id==2 || pmt_id==3)paddle=1;
692 if(pmt_id==4 || pmt_id==5)paddle=2;
693 if(pmt_id==6 || pmt_id==7)paddle=3;
694 if(pmt_id==8 || pmt_id==9)paddle=4;
695 if(pmt_id==10 || pmt_id==11)paddle=5;
696 if(pmt_id==12 || pmt_id==13)paddle=6;
697 if(pmt_id==14 || pmt_id==15)paddle=7;
698 }
699
700 if(plane == 1){
701 if(pmt_id==16 || pmt_id==17)paddle=0;
702 if(pmt_id==18 || pmt_id==19)paddle=1;
703 if(pmt_id==20 || pmt_id==21)paddle=2;
704 if(pmt_id==22 || pmt_id==23)paddle=3;
705 if(pmt_id==24 || pmt_id==25)paddle=4;
706 if(pmt_id==26 || pmt_id==27)paddle=5;
707 }
708
709 if(plane == 2){
710 if(pmt_id==28 || pmt_id==29)paddle=0;
711 if(pmt_id==30 || pmt_id==31)paddle=1;
712 }
713
714 if(plane == 3){
715 if(pmt_id==32 || pmt_id==33)paddle=0;
716 if(pmt_id==34 || pmt_id==35)paddle=1;
717 }
718
719 if(plane == 4){
720 if(pmt_id==36 || pmt_id==37)paddle=0;
721 if(pmt_id==38 || pmt_id==39)paddle=1;
722 if(pmt_id==40 || pmt_id==41)paddle=2;
723 }
724
725 if(plane == 5){
726 if(pmt_id==42 || pmt_id==43)paddle=0;
727 if(pmt_id==44 || pmt_id==45)paddle=1;
728 if(pmt_id==46 || pmt_id==47)paddle=2;
729 }
730 return;
731 }
732
733 //
734
735 // gf Apr 07
736
737 void ToFLevel2::GetPaddlePMT(Int_t paddle, Int_t &pmtleft, Int_t &pmtright){
738 pmtleft=paddle*2;
739 pmtright= pmtleft+1;
740 return;
741 }
742
743 //
744
745
746
747 // // gf Apr 07
748
749 void ToFLevel2::GetPaddleGeometry(Int_t plane, Int_t paddle, Float_t &xleft, Float_t &xright, Float_t &yleft, Float_t &yright){
750
751 Int_t i1;
752
753 Float_t tof11_x[8] = {-17.85,-12.75,-7.65,-2.55,2.55,7.65,12.75,17.85};
754 Float_t tof12_y[6] = { -13.75,-8.25,-2.75,2.75,8.25,13.75};
755 Float_t tof21_y[2] = { 3.75,-3.75};
756 Float_t tof22_x[2] = { -4.5,4.5};
757 Float_t tof31_x[3] = { -6.0,0.,6.0};
758 Float_t tof32_y[3] = { -5.0,0.0,5.0};
759
760 // S11 8 paddles 33.0 x 5.1 cm
761 // S12 6 paddles 40.8 x 5.5 cm
762 // S21 2 paddles 18.0 x 7.5 cm
763 // S22 2 paddles 15.0 x 9.0 cm
764 // S31 3 paddles 15.0 x 6.0 cm
765 // S32 3 paddles 18.0 x 5.0 cm
766
767 if(plane==0)
768 {
769 for (i1=0; i1<8;i1++){
770 if(i1 == paddle){
771 xleft = tof11_x[i1] - 5.1/2.;
772 xright = tof11_x[i1] + 5.1/2.;
773 yleft = -33.0/2.;
774 yright = 33.0/2.;
775 }
776 }
777 }
778
779 if(plane==1)
780 {
781 for (i1=0; i1<6;i1++){
782 if(i1 == paddle){
783 xleft = -40.8/2.;
784 xright = 40.8/2.;
785 yleft = tof12_y[i1] - 5.5/2.;
786 yright = tof12_y[i1] + 5.5/2.;
787 }
788 }
789 }
790
791 if(plane==2)
792 {
793 for (i1=0; i1<2;i1++){
794 if(i1 == paddle){
795 xleft = -18./2.;
796 xright = 18./2.;
797 yleft = tof21_y[i1] - 7.5/2.;
798 yright = tof21_y[i1] + 7.5/2.;
799 }
800 }
801 }
802
803 if(plane==3)
804 {
805 for (i1=0; i1<2;i1++){
806 if(i1 == paddle){
807 xleft = tof22_x[i1] - 9.0/2.;
808 xright = tof22_x[i1] + 9.0/2.;
809 yleft = -15./2.;
810 yright = 15./2.;
811 }
812 }
813 }
814
815
816 if(plane==4)
817 {
818 for (i1=0; i1<3;i1++){
819 if(i1 == paddle){
820 xleft = tof31_x[i1] - 6.0/2.;
821 xright = tof31_x[i1] + 6.0/2.;
822 yleft = -15./2.;
823 yright = 15./2.;
824 }
825 }
826 }
827
828 if(plane==5)
829 {
830 for (i1=0; i1<3;i1++){
831 if(i1 == paddle){
832 xleft = -18.0/2.;
833 xright = 18.0/2.;
834 yleft = tof32_y[i1] - 5.0/2.;
835 yright = tof32_y[i1] + 5.0/2.;
836 }
837 }
838 }
839 return;
840 }
841
842 // gf Apr 07
843 /**
844 * Method to get the paddle index (0,...23) if the plane ID and the paddle id in the plane is given.
845 * This method is the
846 * "reverse" of method "GetPaddlePlane"
847 * @param plane (0 - 5)
848 * @param paddle (plane=0, paddle = 0,...5)
849 * @param padid (0 - 23)
850 */
851 Int_t ToFLevel2::GetPaddleid(Int_t plane, Int_t paddle)
852 {
853 Int_t padid=-1;
854 Int_t pads[6]={8,6,2,2,3,3};
855
856 int somma=0;
857 int np=plane;
858 for(Int_t j=0; j<np; j++){
859 somma+=pads[j];
860 }
861 padid=paddle+somma;
862 return padid;
863
864 }
865
866
867 // gf Apr 07
868 /**
869 * Method to get the plane ID and the paddle id in the plane if the paddle index (0,...23) is given.
870 * This method is the
871 * "reverse" of method "GetPaddleid"
872 * @param pad (0 - 23)
873 * @param plane (0 - 5)
874 * @param paddle (plane=0, paddle = 0,...5)
875 */
876 void ToFLevel2::GetPaddlePlane(Int_t pad, Int_t &plane, Int_t &paddle)
877 {
878
879 Int_t pads11=8;
880 Int_t pads12=6;
881 Int_t pads21=2;
882 Int_t pads22=2;
883 Int_t pads31=3;
884 // Int_t pads32=3;
885
886 if(pad<8){
887 plane=0;
888 paddle=pad;
889 return;
890 }
891
892 if((7<pad)&&(pad<14)){
893 plane=1;
894 paddle=pad-pads11;
895 return;
896 }
897
898 if((13<pad)&&(pad<16)){
899 plane=2;
900 paddle=pad-pads11-pads12;
901 return;
902 }
903
904 if((15<pad)&&(pad<18)){
905 plane=3;
906 paddle=pad-pads11-pads12-pads21;
907 return;
908 }
909
910 if((17<pad)&&(pad<21)){
911 plane=4;
912 paddle=pad-pads11-pads12-pads21-pads22;
913 return;
914 }
915
916 if((20<pad)&&(pad<24)){
917 plane=5;
918 paddle=pad-pads11-pads12-pads21-pads22-pads31;
919 return;
920 }
921
922 }
923
924
925 Int_t ToFLevel2::GetNPaddle(Int_t plane){
926
927 Int_t npaddle=-1;
928
929 Int_t pads11=8;
930 Int_t pads12=6;
931 Int_t pads21=2;
932 Int_t pads22=2;
933 Int_t pads31=3;
934 Int_t pads32=3;
935
936 if(plane==0)npaddle=pads11;
937 if(plane==1)npaddle=pads12;
938 if(plane==2)npaddle=pads21;
939 if(plane==3)npaddle=pads22;
940 if(plane==4)npaddle=pads31;
941 if(plane==5)npaddle=pads32;
942
943 return npaddle;
944
945 }
946
947
948
949 /// wm feb 08
950
951 /**
952 * Method to calculate Beta from the 12 single measurements
953 * we check the individual weights for artificial TDC values, then calculate
954 * am mean beta for the first time. In a second step we loop again through
955 * the single measurements, checking for the residual from the mean
956 * The cut on the residual reject measurements > "x"-sigma. A chi2 value is
957 * calculated, furthermore a "quality" value by adding the weights which
958 * are finally used. If all measurements are taken, "quality" will be = 22.47.
959 * A chi2 cut around 3-4 and a quality-cut > 20 is needed for clean beta
960 * measurements like antiprotons etc.
961 * The Level2 output is derived in the fortran routines using: 10.,10.,20.
962 * @param notrack Track Number
963 * @param cut on residual: difference between single measurement and mean
964 * @param cut on "quality"
965 * @param cut on chi2
966 */
967
968 Float_t ToFLevel2::CalcBeta(Int_t notrack, Float_t resmax, Float_t qualitycut, Float_t chi2cut){
969
970 // cout<<" in CalcBeta "<<resmax<<" "<<chi2cut<<" "<<qualitycut<<endl;
971
972 Float_t bxx = 100.;
973 //
974 ToFTrkVar *trk = GetToFTrkVar(notrack);
975 if(!trk) return 0; //ELENA
976
977
978 Float_t chi2,xhelp,beta_mean;
979 Float_t w_i[12],quality,sw,sxw,res,betachi,beta_mean_inv;
980 Float_t b[12],tdcfl;
981 Int_t pmt_id,pmt_plane;
982
983 for (Int_t i=0; i<12; i++){
984 b[i] = trk->beta[i];
985 }
986
987
988 //========================================================================
989 //--- Find out ToF layers with artificial TDC values & fill vector ---
990 //========================================================================
991
992 Float_t w_il[6];
993
994 for (Int_t jj=0; jj<6;jj++) {
995 w_il[jj] = 1000.;
996 }
997
998
999 for (Int_t i=0; i<trk->npmttdc; i++){
1000 //
1001 pmt_id = (trk->pmttdc).At(i);
1002 pmt_plane = GetPlaneIndex(pmt_id);
1003 tdcfl = (trk->tdcflag).At(i);
1004 if (w_il[pmt_plane] != 1.) w_il[pmt_plane] = tdcfl; //tdcflag
1005 };
1006
1007 //========================================================================
1008 //--- Set weights for the 12 measurements using information for top and bottom:
1009 //--- if no measurements: weight = set to very high value=> not used
1010 //--- top or bottom artificial: weight*sqrt(2)
1011 //--- top and bottom artificial: weight*sqrt(2)*sqrt(2)
1012 //========================================================================
1013
1014 Int_t itop[12] = {0,0,1,1,2,2,3,3,0,0,1,1};
1015 Int_t ibot[12] = {4,5,4,5,4,5,4,5,2,3,2,3};
1016
1017 xhelp= 1E09;
1018
1019 for (Int_t jj=0; jj<12;jj++) {
1020 if (jj<4) xhelp = 0.11; // S1-S3
1021 if ((jj>3)&&(jj<8)) xhelp = 0.18; // S2-S3
1022 if (jj>7) xhelp = 0.28; // S1-S2
1023 if ((w_il[itop[jj]] == 1000.) && (w_il[ibot[jj]] == 1000.)) xhelp = 1E09;
1024 if ((w_il[itop[jj]] == 1) || (w_il[ibot[jj]] == 1.)) xhelp = xhelp*1.414 ;
1025 if ((w_il[itop[jj]] == 1) && (w_il[ibot[jj]] == 1.)) xhelp = xhelp*2. ;
1026
1027 w_i[jj] = 1./xhelp;
1028 }
1029
1030
1031 //========================================================================
1032 //--- Calculate mean beta for the first time -----------------------------
1033 //--- We are using "1/beta" since its error is gaussian ------------------
1034 //========================================================================
1035
1036 Int_t icount=0;
1037 sw=0.;
1038 sxw=0.;
1039 beta_mean=100.;
1040
1041 for (Int_t jj=0; jj<12;jj++){
1042 if ((fabs(1./b[jj])>0.1)&&(fabs(1./b[jj])<15.))
1043 {
1044 icount= icount+1;
1045 sxw=sxw + (1./b[jj])*w_i[jj]*w_i[jj] ;
1046 sw =sw + w_i[jj]*w_i[jj] ;
1047
1048 }
1049 }
1050
1051 if (icount>0) beta_mean=1./(sxw/sw);
1052 beta_mean_inv = 1./beta_mean;
1053
1054 //========================================================================
1055 //--- Calculate beta for the second time, use residuals of the single
1056 //--- measurements to get a chi2 value
1057 //========================================================================
1058
1059 icount=0;
1060 sw=0.;
1061 sxw=0.;
1062 betachi = 100.;
1063 chi2 = 0.;
1064 quality=0.;
1065
1066
1067 for (Int_t jj=0; jj<12;jj++){
1068 if ((fabs(1./b[jj])>0.1)&&(fabs(1./b[jj])<15.)&&(w_i[jj]>0.01)) {
1069 res = beta_mean_inv - (1./b[jj]) ;
1070 if (fabs(res*w_i[jj])<resmax) {;
1071 chi2 = chi2 + pow((res*w_i[jj]),2) ;
1072 icount= icount+1;
1073 sxw=sxw + (1./b[jj])*w_i[jj]*w_i[jj] ;
1074 sw =sw + w_i[jj]*w_i[jj] ;
1075 }
1076 }
1077 }
1078 quality = sqrt(sw) ;
1079
1080 if (icount==0) chi2 = 1000.;
1081 if (icount>0) chi2 = chi2/(icount) ;
1082 if (icount>0) betachi=1./(sxw/sw);
1083
1084 bxx = 100.;
1085 if ((chi2 < chi2cut)&&(quality>qualitycut)) bxx = betachi;
1086 //
1087 return(bxx);
1088 };
1089
1090
1091 ////////////////////////////////////////////////////
1092 ////////////////////////////////////////////////////
1093
1094
1095 /**
1096 * Fills a struct cToFLevel2 with values from a ToFLevel2 object (to put data into a F77 common).
1097 */
1098 void ToFLevel2::GetLevel2Struct(cToFLevel2 *l2) const{
1099
1100 for(Int_t i=0;i<6;i++)
1101 l2->tof_j_flag[i]=tof_j_flag[i];
1102
1103 if(ToFTrk){ //ELENA
1104 l2->ntoftrk = ToFTrk->GetEntries();
1105 for(Int_t j=0;j<l2->ntoftrk;j++){
1106 l2->toftrkseqno[j]= ((ToFTrkVar*)ToFTrk->At(j))->trkseqno;
1107 l2->npmttdc[j]= ((ToFTrkVar*)ToFTrk->At(j))->npmttdc;
1108 for(Int_t i=0;i<l2->npmttdc[j];i++){
1109 l2->pmttdc[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->pmttdc.At(i);
1110 l2->tdcflag[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->tdcflag.At(i); // gf: 30 Nov 2006
1111 }
1112 for(Int_t i=0;i<13;i++)
1113 l2->beta[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->beta[i];
1114
1115 l2->npmtadc[j]= ((ToFTrkVar*)ToFTrk->At(j))->npmtadc;
1116 for(Int_t i=0;i<l2->npmtadc[j];i++){
1117 l2->pmtadc[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->pmtadc.At(i);
1118 l2->adcflag[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->adcflag.At(i); // gf: 30 Nov 2006
1119 l2->dedx[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->dedx.At(i);
1120 }
1121 for(Int_t i=0;i<3;i++){
1122 l2->xtofpos[i][j]=((ToFTrkVar*)ToFTrk->At(j))->xtofpos[i];
1123 l2->ytofpos[i][j]=((ToFTrkVar*)ToFTrk->At(j))->ytofpos[i];
1124 }
1125 for(Int_t i=0;i<6;i++){
1126 l2->xtr_tof[i][j]=((ToFTrkVar*)ToFTrk->At(j))->xtr_tof[i];
1127 l2->ytr_tof[i][j]=((ToFTrkVar*)ToFTrk->At(j))->ytr_tof[i];
1128 }
1129 }
1130 } //ELENA
1131
1132 if(PMT){ //ELENA
1133 l2->npmt = PMT->GetEntries();
1134 for(Int_t j=0;j<l2->npmt;j++){
1135 l2->pmt_id[j] = ((ToFPMT*)PMT->At(j))->pmt_id;
1136 l2->adc[j] =((ToFPMT*)PMT->At(j))->adc;
1137 l2->tdc_tw[j] =((ToFPMT*)PMT->At(j))->tdc_tw;
1138 }
1139 } //ELENA
1140 }
1141
1142
1143 //
1144 // Reprocessing tool // Emiliano 08/04/07
1145 //
1146 Int_t ToFLevel2::Process(TrkLevel2 *trk, TrigLevel2 *trg, GL_RUN *run, OrbitalInfo *orb, Bool_t force){
1147 //
1148 // Copiare qui qualcosa di simile a calonuclei per evitare di riprocessare sempre tutto
1149 //
1150
1151
1152
1153
1154 //
1155 // structures to communicate with F77
1156 //
1157 extern struct ToFInput tofinput_;
1158 extern struct ToFOutput tofoutput_;
1159 //
1160 // DB connection
1161 //
1162 TString host;
1163 TString user;
1164 TString psw;
1165 const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
1166 const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
1167 const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
1168 if ( !pamdbhost ) pamdbhost = "";
1169 if ( !pamdbuser ) pamdbuser = "";
1170 if ( !pamdbpsw ) pamdbpsw = "";
1171 if ( strcmp(pamdbhost,"") ) host = pamdbhost;
1172 if ( strcmp(pamdbuser,"") ) user = pamdbuser;
1173 if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
1174 //
1175 //
1176 TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
1177 if ( !dbc->IsConnected() ) return 1;
1178 stringstream myquery;
1179 myquery.str("");
1180 myquery << "SET time_zone='+0:00'";
1181 dbc->Query(myquery.str().c_str());
1182 GL_PARAM *glparam = new GL_PARAM();
1183 glparam->Query_GL_PARAM(1,1,dbc); // parameters stored in DB in GL_PRAM table
1184 trk->LoadField(glparam->PATH+glparam->NAME);
1185 //
1186 Bool_t defcal = true;
1187 Int_t error=glparam->Query_GL_PARAM(run->RUNHEADER_TIME,201,dbc); // parameters stored in DB in GL_PRAM table
1188 if ( error<0 ) {
1189 return(1);
1190 };
1191 printf(" Reading ToF parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());
1192 if ( (UInt_t)glparam->TO_TIME != (UInt_t)4294967295UL ) defcal = false;
1193 //
1194 Int_t nlen = (Int_t)(glparam->PATH+glparam->NAME).Length();
1195 rdtofcal((char *)(glparam->PATH+glparam->NAME).Data(),&nlen);
1196 //
1197 Int_t adc[4][12];
1198 Int_t tdc[4][12];
1199 Float_t tdcc[4][12];
1200 //
1201 // process tof data
1202 //
1203 for (Int_t hh=0; hh<12;hh++){
1204 for (Int_t kk=0; kk<4;kk++){
1205 adc[kk][hh] = 4095;
1206 tdc[kk][hh] = 4095;
1207 tdcc[kk][hh] = 4095.;
1208 tofinput_.adc[hh][kk] = 4095;
1209 tofinput_.tdc[hh][kk] = 4095;
1210 };
1211 };
1212 Int_t ntrkentry = 0;
1213 Int_t npmtentry = 0;
1214 Int_t gg = 0;
1215 Int_t hh = 0;
1216 Int_t adcf[48];
1217 memset(adcf, 0, 48*sizeof(Int_t));
1218 Int_t tdcf[48];
1219 memset(tdcf, 0, 48*sizeof(Int_t));
1220 for (Int_t pm=0; pm < this->ntrk() ; pm++){
1221 ToFTrkVar *ttf = this->GetToFTrkVar(pm);
1222 for ( Int_t nc=0; nc < ttf->npmttdc; nc++){
1223 if ( (ttf->tdcflag).At(nc) != 0 ) tdcf[(ttf->pmttdc).At(nc)] = 1;
1224 };
1225 for ( Int_t nc=0; nc < ttf->npmtadc; nc++){
1226 if ( (ttf->adcflag).At(nc) != 0 ) adcf[(ttf->pmtadc).At(nc)] = 1;
1227 };
1228 };
1229 //
1230 for (Int_t pm=0; pm < this->npmt() ; pm++){
1231 ToFPMT *pmt = this->GetToFPMT(pm);
1232 this->GetPMTIndex(pmt->pmt_id, gg, hh);
1233 if ( adcf[pmt->pmt_id] == 0 ){
1234 tofinput_.adc[gg][hh] = (int)pmt->adc;
1235 adc[hh][gg] = (int)pmt->adc;
1236 };
1237 if ( tdcf[pmt->pmt_id] == 0 ){
1238 tofinput_.tdc[gg][hh] = (int)pmt->tdc;
1239 tdc[hh][gg] = (int)pmt->tdc;
1240 };
1241 tdcc[hh][gg] = (float)pmt->tdc_tw;
1242 // Int_t pppid = this->GetPMTid(hh,gg);
1243 // 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);
1244 };
1245 //
1246 Int_t unpackError = this->unpackError;
1247 //
1248 for (Int_t hh=0; hh<5;hh++){
1249 tofinput_.patterntrig[hh]=trg->patterntrig[hh];
1250 };
1251 //
1252 this->Clear();
1253 //
1254 Int_t pmt_id = 0;
1255 ToFPMT *t_pmt = new ToFPMT();
1256 if(!(this->PMT)) this->PMT = new TClonesArray("ToFPMT",12); //ELENA
1257 TClonesArray &tpmt = *this->PMT;
1258 ToFTrkVar *t_tof = new ToFTrkVar();
1259 if(!(this->ToFTrk)) this->ToFTrk = new TClonesArray("ToFTrkVar",2); //ELENA
1260 TClonesArray &t = *this->ToFTrk;
1261 //
1262 //
1263 // Here we have calibrated data, ready to be passed to the FORTRAN routine which will extract common and track-related variables.
1264 //
1265 npmtentry = 0;
1266 //
1267 ntrkentry = 0;
1268 //
1269 // Calculate tracks informations from ToF alone
1270 //
1271 tofl2com();
1272 //
1273 memcpy(this->tof_j_flag,tofoutput_.tof_j_flag,6*sizeof(Int_t));
1274 //
1275 t_tof->trkseqno = -1;
1276 //
1277 // and now we must copy from the output structure to the level2 class:
1278 //
1279 t_tof->npmttdc = 0;
1280 //
1281 for (Int_t hh=0; hh<12;hh++){
1282 for (Int_t kk=0; kk<4;kk++){
1283 if ( tofoutput_.tofmask[hh][kk] != 0 ){
1284 pmt_id = this->GetPMTid(kk,hh);
1285 t_tof->pmttdc.AddAt(pmt_id,t_tof->npmttdc);
1286 t_tof->tdcflag.AddAt(tofoutput_.tdcflagtof[hh][kk],t_tof->npmttdc); // gf: Jan 09/07
1287 t_tof->npmttdc++;
1288 };
1289 };
1290 };
1291 for (Int_t kk=0; kk<13;kk++){
1292 t_tof->beta[kk] = tofoutput_.betatof_a[kk];
1293 }
1294 //
1295 t_tof->npmtadc = 0;
1296 for (Int_t hh=0; hh<12;hh++){
1297 for (Int_t kk=0; kk<4;kk++){
1298 if ( tofoutput_.adctof_c[hh][kk] < 1000 ){
1299 t_tof->dedx.AddAt(tofoutput_.adctof_c[hh][kk],t_tof->npmtadc);
1300 pmt_id = this->GetPMTid(kk,hh);
1301 t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc);
1302 t_tof->adcflag.AddAt(tofoutput_.adcflagtof[hh][kk],t_tof->npmtadc); // gf: Jan 09/07
1303 t_tof->npmtadc++;
1304 };
1305 };
1306 };
1307 //
1308 memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos));
1309 memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos));
1310 memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof));
1311 memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof));
1312 //
1313 new(t[ntrkentry]) ToFTrkVar(*t_tof);
1314 ntrkentry++;
1315 t_tof->Clear();
1316 //
1317 //
1318 //
1319 t_pmt->Clear();
1320 //
1321 for (Int_t hh=0; hh<12;hh++){
1322 for (Int_t kk=0; kk<4;kk++){
1323 // new WM
1324 if ( tofoutput_.tdc_c[hh][kk] < 4095 || adc[kk][hh] < 4095 || tdc[kk][hh] < 4095 ){
1325 // if ( tdcc[kk][hh] < 4095. || adc[kk][hh] < 4095 || tdc[kk][hh] < 4095 ){
1326 //
1327 t_pmt->pmt_id = this->GetPMTid(kk,hh);
1328 t_pmt->tdc_tw = tofoutput_.tdc_c[hh][kk];
1329 t_pmt->adc = (Float_t)adc[kk][hh];
1330 t_pmt->tdc = (Float_t)tdc[kk][hh];
1331 //
1332 new(tpmt[npmtentry]) ToFPMT(*t_pmt);
1333 npmtentry++;
1334 t_pmt->Clear();
1335 };
1336 };
1337 };
1338 //
1339 // Calculate track-related variables
1340 //
1341 if ( trk->ntrk() > 0 ){
1342 //
1343 // We have at least one track
1344 //
1345 //
1346 // Run over tracks
1347 //
1348 for(Int_t nt=0; nt < trk->ntrk(); nt++){
1349 //
1350 TrkTrack *ptt = trk->GetStoredTrack(nt);
1351 //
1352 // Copy the alpha vector in the input structure
1353 //
1354 for (Int_t e = 0; e < 5 ; e++){
1355 tofinput_.al_pp[e] = ptt->al[e];
1356 };
1357 //
1358 // Get tracker related variables for this track
1359 //
1360 toftrk();
1361 //
1362 // Copy values in the class from the structure (we need to use a temporary class to store variables).
1363 //
1364 t_tof->npmttdc = 0;
1365 for (Int_t hh=0; hh<12;hh++){
1366 for (Int_t kk=0; kk<4;kk++){
1367 if ( tofoutput_.tofmask[hh][kk] != 0 ){
1368 pmt_id = this->GetPMTid(kk,hh);
1369 t_tof->pmttdc.AddAt(pmt_id,t_tof->npmttdc);
1370 t_tof->tdcflag.AddAt(tofoutput_.tdcflag[hh][kk],t_tof->npmttdc); // gf: Jan 09/07
1371 t_tof->npmttdc++;
1372 };
1373 };
1374 };
1375 for (Int_t kk=0; kk<13;kk++){
1376 t_tof->beta[kk] = tofoutput_.beta_a[kk];
1377 };
1378 //
1379 t_tof->npmtadc = 0;
1380 for (Int_t hh=0; hh<12;hh++){
1381 for (Int_t kk=0; kk<4;kk++){
1382 if ( tofoutput_.adc_c[hh][kk] < 1000 ){
1383 t_tof->dedx.AddAt(tofoutput_.adc_c[hh][kk],t_tof->npmtadc);
1384 pmt_id = this->GetPMTid(kk,hh);
1385 t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc);
1386 t_tof->adcflag.AddAt(tofoutput_.adcflag[hh][kk],t_tof->npmtadc); // gf: Jan 09/07
1387 t_tof->npmtadc++;
1388 };
1389 };
1390 };
1391 //
1392 memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos));
1393 memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos));
1394 memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof));
1395 memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof));
1396 //
1397 // Store the tracker track number in order to be sure to have shyncronized data during analysis
1398 //
1399 t_tof->trkseqno = nt;
1400 //
1401 // create a new object for this event with track-related variables
1402 //
1403 new(t[ntrkentry]) ToFTrkVar(*t_tof);
1404 ntrkentry++;
1405 t_tof->Clear();
1406 //
1407 }; // loop on all the tracks
1408 //
1409 this->unpackError = unpackError;
1410 if ( defcal ){
1411 this->default_calib = 1;
1412 } else {
1413 this->default_calib = 0;
1414 };
1415 };
1416
1417
1418
1419 return(0);
1420 }

  ViewVC Help
Powered by ViewVC 1.1.23