/[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.14 - (hide annotations) (download)
Thu Mar 1 10:53:54 2007 UTC (17 years, 9 months ago) by pam-de
Branch: MAIN
Changes since 1.13: +35 -3 lines
Doxygen comments added

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

  ViewVC Help
Powered by ViewVC 1.1.23