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

  ViewVC Help
Powered by ViewVC 1.1.23