/[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.10 - (hide annotations) (download)
Thu Jan 11 09:34:27 2007 UTC (17 years, 11 months ago) by pam-fi
Branch: MAIN
Changes since 1.9: +72 -34 lines
memory-leak bug fixed

1 mocchiut 1.1 #include <TObject.h>
2     #include <ToFLevel2.h>
3     #include <iostream>
4     using namespace std;
5 mocchiut 1.4 ClassImp(ToFPMT);
6 mocchiut 1.1 ClassImp(ToFTrkVar);
7     ClassImp(ToFLevel2);
8    
9 mocchiut 1.4 ToFPMT::ToFPMT(){
10     pmt_id = 0;
11     adc = 0.;
12     tdc_tw = 0.;
13     }
14    
15     ToFPMT::ToFPMT(const ToFPMT &t){
16     pmt_id = t.pmt_id;
17     adc = t.adc;
18     tdc_tw = t.tdc_tw;
19     }
20    
21     void ToFPMT::Clear(){
22     pmt_id = 0;
23     adc = 0.;
24     tdc_tw = 0.;
25     }
26    
27    
28    
29 mocchiut 1.1 ToFTrkVar::ToFTrkVar() {
30 mocchiut 1.4 trkseqno = 0;
31     npmttdc = 0;
32     npmtadc = 0;
33     pmttdc = TArrayI(48);
34     pmtadc = TArrayI(48);
35 mocchiut 1.9 tdcflag = TArrayI(48); // gf: 30 Nov 2006
36     adcflag = TArrayI(48); // gf: 30 Nov 2006
37 mocchiut 1.4 dedx = TArrayF(48);
38     //
39     //
40     memset(beta, 0, 13*sizeof(Float_t));
41     memset(xtofpos, 0, 3*sizeof(Float_t));
42     memset(ytofpos, 0, 3*sizeof(Float_t));
43     //
44     };
45 mocchiut 1.1
46 mocchiut 1.4 void ToFTrkVar::Clear() {
47 mocchiut 1.1 trkseqno = 0;
48 mocchiut 1.4 npmttdc = 0;
49     npmtadc = 0;
50     pmttdc.Reset();
51     pmtadc.Reset();
52 mocchiut 1.9 tdcflag.Reset(); // gf: 30 Nov 2006
53     adcflag.Reset(); // gf: 30 Nov 2006
54 mocchiut 1.4 dedx.Reset();
55     //
56     memset(beta, 0, 13*sizeof(Float_t));
57     memset(xtofpos, 0, 3*sizeof(Float_t));
58     memset(ytofpos, 0, 3*sizeof(Float_t));
59     //
60     };
61 mocchiut 1.1
62     ToFTrkVar::ToFTrkVar(const ToFTrkVar &t){
63    
64     trkseqno = t.trkseqno;
65 mocchiut 1.4 //
66     npmttdc = t.npmttdc;
67     npmtadc = t.npmtadc;
68     (t.pmttdc).Copy(pmttdc);
69     (t.pmtadc).Copy(pmtadc);
70 mocchiut 1.9 (t.tdcflag).Copy(tdcflag); // gf: 30 Nov 2006
71     (t.adcflag).Copy(adcflag); // gf: 30 Nov 2006
72 mocchiut 1.4 (t.dedx).Copy(dedx);
73     //
74     memcpy(beta,t.beta,sizeof(beta));
75     memcpy(xtofpos,t.xtofpos,sizeof(xtofpos));
76     memcpy(ytofpos,t.ytofpos,sizeof(ytofpos));
77     //
78     };
79 mocchiut 1.1
80     ToFLevel2::ToFLevel2() {
81     //
82 pam-fi 1.10 // PMT = new TClonesArray("ToFPMT",12); //ELENA
83     // ToFTrk = new TClonesArray("ToFTrkVar",2); //ELENA
84     PMT = 0; //ELENA
85     ToFTrk = 0; //ELENA
86 mocchiut 1.1 //
87 mocchiut 1.8 this->Clear();
88     //
89 mocchiut 1.3 };
90    
91     void ToFLevel2::Clear(){
92     //
93 pam-fi 1.10 if(ToFTrk)ToFTrk->Delete(); //ELENA
94     if(PMT)PMT->Delete(); //ELENA
95 mocchiut 1.4 memset(tof_j_flag, 0, 6*sizeof(Int_t));
96 mocchiut 1.8 unpackError = 0;
97 mocchiut 1.4 //
98 mocchiut 1.1 };
99    
100 pam-fi 1.10 void ToFLevel2::Delete(){ //ELENA
101     //
102     if(ToFTrk){
103     ToFTrk->Delete(); //ELENA
104     delete ToFTrk; //ELENA
105     }
106     if(PMT){
107     PMT->Delete(); //ELENA
108     delete PMT; //ELENA
109     } //ELENA
110     //
111     }; //ELENA
112    
113 mocchiut 1.1 ToFTrkVar *ToFLevel2::GetToFTrkVar(Int_t itrk){
114     //
115     if(itrk >= ntrk()){
116     printf(" ToFLevel2 ERROR: track related variables set %i does not exists! \n",itrk);
117     printf(" stored track related variables = %i \n",ntrk());
118     return(NULL);
119     }
120     //
121 pam-fi 1.10 if(!ToFTrk)return 0; //ELENA
122 mocchiut 1.1 TClonesArray &t = *(ToFTrk);
123     ToFTrkVar *toftrack = (ToFTrkVar*)t[itrk];
124     return toftrack;
125     }
126 mocchiut 1.4
127     ToFPMT *ToFLevel2::GetToFPMT(Int_t ihit){
128     //
129     if(ihit >= npmt()){
130     printf(" ToFLevel2 ERROR: pmt variables set %i does not exists! \n",ihit);
131     printf(" stored pmt variables = %i \n",npmt());
132     return(NULL);
133     }
134     //
135 pam-fi 1.10 if(!PMT)return 0; //ELENA
136 mocchiut 1.4 TClonesArray &t = *(PMT);
137     ToFPMT *tofpmt = (ToFPMT*)t[ihit];
138     return tofpmt;
139     }
140 mocchiut 1.1 //--------------------------------------
141     //
142     //
143     //--------------------------------------
144     /**
145 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)
146 mocchiut 1.1 */
147     Int_t ToFLevel2::GetToFPlaneID(Int_t ip){
148     if(ip>=0 && ip<6)return 10*((int)(ip/2+1.1))+(ip%2)+1;
149     else return -1;
150     };
151     /**
152 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)
153 mocchiut 1.1 */
154     Int_t ToFLevel2::GetToFPlaneIndex(Int_t plane_id){
155     if(
156     plane_id == 11 ||
157     plane_id == 12 ||
158     plane_id == 21 ||
159     plane_id == 22 ||
160     plane_id == 31 ||
161     plane_id == 32 ||
162     false)return (Int_t)(plane_id/10)*2-1- plane_id%2;
163     else return -1;
164     };
165     /**
166 pam-fi 1.10 * Method to know if a given ToF paddle was hit, that is there is a TDC signal
167     * from both PMTs
168 mocchiut 1.1 * @param plane Plane ID (11, 12, 21, 22, 31, 32) or Plane index (0,1,2,3,4,5).
169     * @param paddle_id Paddle ID.
170     * @return 1 if the paddle was hit.
171     */
172     Bool_t ToFLevel2::HitPaddle(Int_t plane, Int_t paddle_id){ //<<< NEW
173     Int_t ip = -1;
174     if (plane>=6 ) ip = GetToFPlaneIndex(plane);
175     else if(plane>=0 && plane < 6) ip = plane;
176     Int_t flag=0;
177 mocchiut 1.2 if(ip != -1)flag = tof_j_flag[ip] & (int)pow(2.,(double)paddle_id);
178 mocchiut 1.1 if(
179     (ip == 0 && paddle_id < 8 && flag) ||
180     (ip == 1 && paddle_id < 6 && flag) ||
181     (ip == 2 && paddle_id < 2 && flag) ||
182     (ip == 3 && paddle_id < 2 && flag) ||
183     (ip == 4 && paddle_id < 3 && flag) ||
184     (ip == 5 && paddle_id < 3 && flag) ||
185     false) return true;
186     else return false;
187     };
188     /**
189     * Method to get the number of hit paddles on a ToF plane.
190     * @param plane Plane ID (11, 12, 21, 22, 31, 32) or Plane index (0,1,2,3,4,5).
191     */
192     Int_t ToFLevel2::GetNHitPaddles(Int_t plane){
193     Int_t npad=0;
194     for(Int_t i=0; i<8; i++)npad = npad + (int)HitPaddle(plane,i);
195     return npad;
196     };
197 mocchiut 1.4
198    
199     Float_t ToFLevel2::GetdEdx(Int_t notrack, Int_t plane){
200 pam-fi 1.10
201 mocchiut 1.4 Float_t dedx = 0.;
202     Int_t ip = 0;
203     Int_t pmt_id = 0;
204     Int_t pl = 0;
205     if ( plane >= 6 ){
206     ip = GetToFPlaneIndex(plane);
207     } else {
208     ip = plane;
209     };
210     //
211     ToFTrkVar *trk = GetToFTrkVar(notrack);
212 pam-fi 1.10 if(!trk) return 0; //ELENA
213 mocchiut 1.4 //
214     for (Int_t i=0; i<trk->npmtadc; i++){
215     //
216     pmt_id = (trk->pmtadc).At(i);
217     //
218     pl = GetPlaneIndex(pmt_id);
219     //
220 pam-fi 1.10 if ( pl == ip ){
221     // // --- patch ---
222     // bool ISNULL=false;
223     // for(Int_t im=0; im< this->npmt(); im++){
224     // if(this->GetToFPMT(im)->pmt_id == pmt_id && this->GetToFPMT(im)->adc == 4095){
225     // cout << " ToFLevel2::GetdEdx(Int_t,Int_t) --> **warning** ADC(PMT="<<pmt_id<<") = 4095"<<endl;
226     // ISNULL=true;
227     // }
228     // }
229     // // --- patch ---
230     // dedx += (trk->dedx).At(i)*(Int_t)(!ISNULL);
231     dedx += (trk->dedx).At(i);
232     }
233 mocchiut 1.4 //
234     };
235     //
236     return(dedx);
237     };
238    
239    
240     void ToFLevel2::GetMatrix(Int_t notrack, Float_t adc[4][12], Float_t tdc[4][12]){
241     //
242     for (Int_t aa=0; aa<4;aa++){
243     for (Int_t bb=0; bb<12;bb++){
244     adc[aa][bb] = 1000.;
245     tdc[aa][bb] = 4095.;
246     };
247     };
248     //
249     Int_t pmt_id = 0;
250     Int_t hh = 0;
251     Int_t kk = 0;
252     //
253     ToFTrkVar *trk = GetToFTrkVar(notrack);
254 pam-fi 1.10 if(!trk)return; //ELENA
255 mocchiut 1.4 //
256     for (Int_t i=0; i<trk->npmtadc; i++){
257     //
258     pmt_id = (trk->pmtadc).At(i);
259     //
260     GetPMTIndex(pmt_id,hh,kk);
261 mocchiut 1.5 adc[kk][hh] = (trk->dedx).At(i);
262 mocchiut 1.4 //
263     };
264     //
265     for (Int_t i=0; i<npmt(); i++){
266     //
267     ToFPMT *pmt = GetToFPMT(i);
268 pam-fi 1.10 if(!pmt)break; //ELENA
269 mocchiut 1.4 //
270     GetPMTIndex(pmt->pmt_id,hh,kk);
271     //
272 mocchiut 1.5 tdc[kk][hh] = pmt->tdc_tw;
273 mocchiut 1.4 //
274     };
275     //
276     return;
277     };
278    
279    
280    
281     Int_t ToFLevel2::GetPlaneIndex(Int_t pmt_id){
282     TString pmtname = GetPMTName(pmt_id);
283     pmtname.Resize(3);
284     if ( !strcmp(pmtname,"S11") ) return(0);
285     if ( !strcmp(pmtname,"S12") ) return(1);
286     if ( !strcmp(pmtname,"S21") ) return(2);
287     if ( !strcmp(pmtname,"S22") ) return(3);
288     if ( !strcmp(pmtname,"S31") ) return(4);
289     if ( !strcmp(pmtname,"S32") ) return(5);
290     return(-1);
291     };
292    
293    
294     Int_t ToFLevel2::GetPMTid(Int_t hh, Int_t kk){
295     //
296     short tof[4][24] = {
297     {4, 4, 4, 4, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 2, 3, 3, 3, 3, 4},
298     {1, 3, 5, 7, 10, 12, 2, 4, 2, 4, 6, 8, 10, 12, 1, 5, 3, 9, 7, 9, 11, 1, 5, 9},
299     {2, 2, 2, 2, 1, 1, 1, 1, 4, 4, 4, 4, 4, 4, 2, 1, 2, 1, 2, 2, 2, 3, 3, 4},
300     {6, 8, 12, 10, 8, 6, 4, 2, 12, 10, 8, 6, 4, 2, 9, 7, 11, 11, 5, 3, 1, 3, 7, 11}
301     };
302     //
303     Int_t ind = 0;
304     Int_t k = 0;
305     while (k < 24){
306     Int_t j = 0;
307     while (j < 2){
308     Int_t ch = tof[2*j][k] - 1;
309     Int_t hb = tof[2*j + 1][k] - 1;
310     /* tofEvent->tdc[ch][hb] */
311     if( ch == hh && hb == kk ){
312     ind = 2*k + j;
313     break;
314     };
315     j++;
316     };
317     k++;
318     };
319     return ind;
320     };
321    
322     TString ToFLevel2::GetPMTName(Int_t ind){
323    
324     TString pmtname = " ";
325    
326     TString photoS[48] = {
327     "S11_1A", "S11_1B", "S11_2A", "S11_2B", "S11_3A", "S11_3B", "S11_4A", "S11_4B",
328     "S11_5A", "S11_5B", "S11_6A", "S11_6B", "S11_7A", "S11_7B", "S11_8A", "S11_8B",
329     "S12_1A", "S12_1B", "S12_2A", "S12_2B", "S12_3A", "S12_3B", "S12_4A", "S12_4B", "S12_5A", "S12_5B", "S12_6A", "S12_6B",
330     "S21_1A", "S21_1B", "S21_2A", "S21_2B",
331     "S22_1A", "S22_1B", "S22_2A", "S22_2B",
332     "S31_1A", "S31_1B", "S31_2A", "S31_2B", "S31_3A", "S31_3B",
333     "S32_1A", "S32_1B", "S32_2A", "S32_2B", "S32_3A", "S32_3B"
334     };
335    
336    
337     pmtname = photoS[ind].Data();
338    
339     return pmtname;
340     };
341    
342    
343 mocchiut 1.5 void ToFLevel2::GetPMTIndex(Int_t ind, Int_t &hb, Int_t &ch){
344 mocchiut 1.4 //
345     short tof[4][24] = {
346     {4, 4, 4, 4, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 2, 3, 3, 3, 3, 4},
347     {1, 3, 5, 7, 10, 12, 2, 4, 2, 4, 6, 8, 10, 12, 1, 5, 3, 9, 7, 9, 11, 1, 5, 9},
348     {2, 2, 2, 2, 1, 1, 1, 1, 4, 4, 4, 4, 4, 4, 2, 1, 2, 1, 2, 2, 2, 3, 3, 4},
349     {6, 8, 12, 10, 8, 6, 4, 2, 12, 10, 8, 6, 4, 2, 9, 7, 11, 11, 5, 3, 1, 3, 7, 11}
350     };
351     //
352     Int_t k = 0;
353     while (k < 24){
354     Int_t j = 0;
355     while (j < 2){
356 mocchiut 1.5 /* tofEvent->tdc[ch][hb] */
357 mocchiut 1.4 if( ind == 2*k + j ){
358 mocchiut 1.5 ch = tof[2*j][k] - 1;
359     hb = tof[2*j + 1][k] - 1;
360     return;
361 mocchiut 1.4 };
362     j++;
363     };
364     k++;
365     };
366     return;
367     };
368 pam-fi 1.6
369     /**
370     * Fills a struct cToFLevel2 with values from a ToFLevel2 object (to put data into a F77 common).
371     */
372     void ToFLevel2::GetLevel2Struct(cToFLevel2 *l2) const{
373    
374     for(Int_t i=0;i<6;i++)
375     l2->tof_j_flag[i]=tof_j_flag[i];
376    
377 pam-fi 1.10 if(ToFTrk){ //ELENA
378     l2->ntoftrk = ToFTrk->GetEntries();
379     for(Int_t j=0;j<l2->ntoftrk;j++){
380     l2->toftrkseqno[j]= ((ToFTrkVar*)ToFTrk->At(j))->trkseqno;
381     l2->npmttdc[j]= ((ToFTrkVar*)ToFTrk->At(j))->npmttdc;
382     for(Int_t i=0;i<l2->npmttdc[j];i++){
383     l2->pmttdc[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->pmttdc.At(i);
384     l2->tdcflag[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->tdcflag.At(i); // gf: 30 Nov 2006
385     }
386     for(Int_t i=0;i<13;i++)
387     l2->beta[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->beta[i];
388    
389     l2->npmtadc[j]= ((ToFTrkVar*)ToFTrk->At(j))->npmtadc;
390     for(Int_t i=0;i<l2->npmtadc[j];i++){
391     l2->pmtadc[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->pmtadc.At(i);
392     l2->adcflag[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->adcflag.At(i); // gf: 30 Nov 2006
393     l2->dedx[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->dedx.At(i);
394     }
395     for(Int_t i=0;i<3;i++){
396     l2->xtofpos[i][j]=((ToFTrkVar*)ToFTrk->At(j))->xtofpos[i];
397     l2->ytofpos[i][j]=((ToFTrkVar*)ToFTrk->At(j))->ytofpos[i];
398     }
399     }
400     } //ELENA
401 pam-fi 1.6
402 pam-fi 1.10 if(PMT){ //ELENA
403     l2->npmt = PMT->GetEntries();
404     for(Int_t j=0;j<l2->npmt;j++){
405     l2->pmt_id[j] = ((ToFPMT*)PMT->At(j))->pmt_id;
406     l2->adc[j] =((ToFPMT*)PMT->At(j))->adc;
407     l2->tdc_tw[j] =((ToFPMT*)PMT->At(j))->tdc_tw;
408     }
409     } //ELENA
410 pam-fi 1.6 }

  ViewVC Help
Powered by ViewVC 1.1.23