/[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.21 - (hide annotations) (download)
Fri Apr 18 18:55:53 2008 UTC (16 years, 7 months ago) by mocchiut
Branch: MAIN
Changes since 1.20: +282 -2 lines
ToF upgrade and bugs fixed, Calorimeter crosstalk bugs fixed, new ToF calibrations

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

  ViewVC Help
Powered by ViewVC 1.1.23