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

Annotation of /DarthVader/ToFLevel2/src/ToFLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.23 - (hide annotations) (download)
Thu Dec 4 11:41:08 2008 UTC (16 years ago) by pamelats
Branch: MAIN
Changes since 1.22: +213 -312 lines
saturation limits for the PMTs included in GetdEdxPaddle

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

  ViewVC Help
Powered by ViewVC 1.1.23