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

Diff of /DarthVader/ToFLevel2/src/ToFLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by mocchiut, Mon Jun 19 13:27:45 2006 UTC revision 1.15 by pam-de, Wed Apr 4 07:23:27 2007 UTC
# Line 1  Line 1 
1    /**
2     * \file ToFLevel2.cpp
3     * \author Gianfranca DeRosa, Wolfgang Menn
4     */
5    
6  #include <TObject.h>  #include <TObject.h>
7  #include <ToFLevel2.h>  #include <ToFLevel2.h>
8  #include <iostream>  #include <iostream>
9  using namespace std;  using namespace std;
10    ClassImp(ToFPMT);
11  ClassImp(ToFTrkVar);  ClassImp(ToFTrkVar);
12  ClassImp(ToFLevel2);  ClassImp(ToFLevel2);
13    
14  ToFTrkVar::ToFTrkVar() {  ToFPMT::ToFPMT(){
15      pmt_id = 0;
16      adc = 0.;
17      tdc_tw = 0.;
18    }
19    
20    trkseqno = 0;  ToFPMT::ToFPMT(const ToFPMT &t){
21      pmt_id = t.pmt_id;
22      adc = t.adc;
23      tdc_tw = t.tdc_tw;
24    }
25    
26    for (Int_t kk=0; kk<13;kk++){  void ToFPMT::Clear(){
27      beta_a[kk] = 0;    pmt_id = 0;
28    }    adc = 0.;
29      tdc_tw = 0.;
   for (Int_t kk=0; kk<4;kk++){  
     for (Int_t hh=0; hh<12;hh++){  
       adc_c[hh][kk] = 0;  
     }  
   }  
30  }  }
31    
 ToFTrkVar::ToFTrkVar(const ToFTrkVar &t){  
32    
   trkseqno = t.trkseqno;    
33    
34    memcpy(adc_c,t.adc_c,sizeof(adc_c));  ToFTrkVar::ToFTrkVar() {
35    memcpy(beta_a,t.beta_a,sizeof(beta_a));    trkseqno = 0;
36  }    npmttdc = 0;
37      npmtadc = 0;
38      pmttdc = TArrayI(48);
39      pmtadc = TArrayI(48);
40      tdcflag = TArrayI(48); // gf: 30 Nov 2006
41      adcflag = TArrayI(48); // gf: 30 Nov 2006
42      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    
51  ToFLevel2::ToFLevel2() {      void ToFTrkVar::Clear() {
52      trkseqno = 0;
53      npmttdc = 0;
54      npmtadc = 0;
55      pmttdc.Reset();
56      pmtadc.Reset();
57      tdcflag.Reset(); // gf: 30 Nov 2006
58      adcflag.Reset(); // gf: 30 Nov 2006
59      dedx.Reset();
60    //    //
61    ToFTrk = new TClonesArray("ToFTrkVar",1);    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    for (Int_t kk=0; kk<3;kk++){  };
     xtofpos[kk] = 0.;  
     ytofpos[kk] = 0.;  
   }  
66    
67    for (Int_t kk=0; kk<6;kk++){  ToFTrkVar::ToFTrkVar(const ToFTrkVar &t){
     tof_i_flag[kk] = 0;  
     tof_j_flag[kk] = 0;  
   }  
     
   for (Int_t kk=0; kk<13;kk++){  
     betatof_a[kk] = 0;  
   }  
68    
69    for (Int_t kk=0; kk<4;kk++){    trkseqno = t.trkseqno;  
70      for (Int_t hh=0; hh<12;hh++){    //
71        adctof_c[hh][kk] = 0;    npmttdc = t.npmttdc;
72      }    npmtadc = t.npmtadc;
73    }      (t.pmttdc).Copy(pmttdc);
74      (t.pmtadc).Copy(pmtadc);
75      (t.tdcflag).Copy(tdcflag); // gf: 30 Nov 2006
76      (t.adcflag).Copy(adcflag); // gf: 30 Nov 2006
77      (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    
85    for (Int_t kk=0; kk<4;kk++){  ToFLevel2::ToFLevel2() {    
86      for (Int_t hh=0; hh<12;hh++){    //
87        tdc_c[hh][kk] = 0;  //  PMT = new TClonesArray("ToFPMT",12); //ELENA
88      }  //  ToFTrk = new TClonesArray("ToFTrkVar",2); //ELENA
89    }      PMT = 0; //ELENA
90      ToFTrk = 0; //ELENA
91      //
92      this->Clear();
93      //
94    };
95    
96    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    void ToFLevel2::Clear(){
102      //
103      if(ToFTrk)ToFTrk->Delete(); //ELENA
104      if(PMT)PMT->Delete(); //ELENA
105      memset(tof_j_flag, 0, 6*sizeof(Int_t));
106      unpackError = 0;
107      //
108  };  };
109    
110    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  ToFTrkVar *ToFLevel2::GetToFTrkVar(Int_t itrk){  ToFTrkVar *ToFLevel2::GetToFTrkVar(Int_t itrk){
124    //        //    
125    if(itrk >= ntrk()){    if(itrk >= ntrk()){
# Line 69  ToFTrkVar *ToFLevel2::GetToFTrkVar(Int_t Line 128  ToFTrkVar *ToFLevel2::GetToFTrkVar(Int_t
128      return(NULL);      return(NULL);
129    }      }  
130    //    //
131      if(!ToFTrk)return 0; //ELENA
132    TClonesArray &t = *(ToFTrk);    TClonesArray &t = *(ToFTrk);
133    ToFTrkVar *toftrack = (ToFTrkVar*)t[itrk];    ToFTrkVar *toftrack = (ToFTrkVar*)t[itrk];
134    return toftrack;    return toftrack;
135  }  }
136    
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      if(!PMT)return 0; //ELENA
146      TClonesArray &t = *(PMT);
147      ToFPMT *tofpmt = (ToFPMT*)t[ihit];
148      return tofpmt;
149    }
150  //--------------------------------------  //--------------------------------------
151  //  //
152  //  //
153  //--------------------------------------  //--------------------------------------
154  /**  /**
155   * Method to get the paddle ID (11 12 21 22 31 32) from the paddle index (0 1 2 3 4 5)   * Method to get the plane ID (11 12 21 22 31 32) from the plane index (0 1 2 3 4 5)
156     * @param Plane index (0,1,2,3,4,5)
157   */   */
158    Int_t  ToFLevel2::GetToFPlaneID(Int_t ip){    Int_t  ToFLevel2::GetToFPlaneID(Int_t ip){
159        if(ip>=0 && ip<6)return 10*((int)(ip/2+1.1))+(ip%2)+1;        if(ip>=0 && ip<6)return 10*((int)(ip/2+1.1))+(ip%2)+1;
160        else return -1;        else return -1;
161    };    };
162  /**  /**
163   * Method to get the paddle index (0 1 2 3 4 5) from the paddle ID (11 12 21 22 31 32)   * Method to get the plane index (0 1 2 3 4 5) from the plane ID (11 12 21 22 31 32)
164     * @param plane Plane ID (11, 12, 21, 22, 31, 32)
165   */   */
166    Int_t  ToFLevel2::GetToFPlaneIndex(Int_t plane_id){    Int_t  ToFLevel2::GetToFPlaneIndex(Int_t plane_id){
167        if(        if(
# Line 99  ToFTrkVar *ToFLevel2::GetToFTrkVar(Int_t Line 175  ToFTrkVar *ToFLevel2::GetToFTrkVar(Int_t
175        else return -1;        else return -1;
176    };    };
177  /**  /**
178   * Method to know if a given ToF paddle was hit, that is there is a TDC signal from both PMTs   * Method to know if a given ToF paddle was hit, that is there is a TDC signal
179     * from both PMTs. The method uses the "tof_j_flag" variable.
180   * @param plane Plane ID (11, 12, 21, 22, 31, 32) or Plane index (0,1,2,3,4,5).   * @param plane Plane ID (11, 12, 21, 22, 31, 32) or Plane index (0,1,2,3,4,5).
181   * @param paddle_id Paddle ID.   * @param paddle_id Paddle ID.
182   * @return 1 if the paddle was hit.   * @return 1 if the paddle was hit.
# Line 129  Int_t ToFLevel2::GetNHitPaddles(Int_t pl Line 206  Int_t ToFLevel2::GetNHitPaddles(Int_t pl
206      for(Int_t i=0; i<8; i++)npad = npad + (int)HitPaddle(plane,i);      for(Int_t i=0; i<8; i++)npad = npad + (int)HitPaddle(plane,i);
207      return npad;      return npad;
208  };  };
209    
210    
211    /**
212     * Method to get the mean dEdx from a given ToF plane. This current version
213     * is just summing up all PMT signals, which will not give proper results,
214     * and needs a revision.
215     * @param notrack Track Number
216     * @param plane Plane index (0,1,2,3,4,5).
217     */
218    Float_t ToFLevel2::GetdEdx(Int_t notrack, Int_t plane){
219    
220      Float_t dedx = 0.;
221      Int_t ip = 0;
222      Int_t pmt_id = 0;
223      Int_t pl = 0;
224      if ( plane >= 6 ){
225        ip = GetToFPlaneIndex(plane);
226      } else {
227        ip = plane;
228      };
229      //
230      ToFTrkVar *trk = GetToFTrkVar(notrack);
231      if(!trk) return 0; //ELENA
232      //
233      for (Int_t i=0; i<trk->npmtadc; i++){
234        //
235        pmt_id = (trk->pmtadc).At(i);
236        //
237        pl = GetPlaneIndex(pmt_id);
238        //
239        if ( pl == ip ) dedx += (trk->dedx).At(i);
240        //
241      };
242      //
243      return(dedx);
244    };
245    
246    
247    /**
248     * Method to fill the ADC_C 4x12 matrix with the dEdx values and the TDC 4x12 matrix
249     * with the time-walk corrected TDC values.
250     * @param notrack Track Number
251     * @param adc  ADC_C matrix with dEdx values
252     * @param tdc  TDC matrix
253     */
254    void ToFLevel2::GetMatrix(Int_t notrack, Float_t adc[4][12], Float_t tdc[4][12]){
255      //
256      for (Int_t aa=0; aa<4;aa++){
257        for (Int_t bb=0; bb<12;bb++){
258          adc[aa][bb] = 1000.;
259          tdc[aa][bb] = 4095.;
260        };
261      };
262      //
263      Int_t pmt_id = 0;
264      Int_t hh = 0;
265      Int_t kk = 0;
266      //
267      ToFTrkVar *trk = GetToFTrkVar(notrack);
268      if(!trk)return; //ELENA
269      //
270      for (Int_t i=0; i<trk->npmtadc; i++){
271        //
272        pmt_id = (trk->pmtadc).At(i);
273        //
274        GetPMTIndex(pmt_id,hh,kk);
275        adc[kk][hh] = (trk->dedx).At(i);  
276        //
277      };
278      //
279      for (Int_t i=0; i<npmt(); i++){
280        //
281        ToFPMT *pmt = GetToFPMT(i);
282        if(!pmt)break; //ELENA
283        //
284        GetPMTIndex(pmt->pmt_id,hh,kk);
285        //
286        tdc[kk][hh] = pmt->tdc_tw;  
287        //
288      };
289      //
290      return;
291    };
292    
293    
294    /**
295     * Method to get the plane index (0 - 5) for the PMT_ID as input
296     * @param pmt_id  PMT_ID (0 - 47)
297     */
298    Int_t ToFLevel2::GetPlaneIndex(Int_t pmt_id){
299      TString pmtname = GetPMTName(pmt_id);
300      pmtname.Resize(3);
301      if ( !strcmp(pmtname,"S11") ) return(0);
302      if ( !strcmp(pmtname,"S12") ) return(1);
303      if ( !strcmp(pmtname,"S21") ) return(2);
304      if ( !strcmp(pmtname,"S22") ) return(3);
305      if ( !strcmp(pmtname,"S31") ) return(4);
306      if ( !strcmp(pmtname,"S32") ) return(5);
307      return(-1);
308    };
309    
310    /**
311     * Method to get the PMT_ID if the index (4,12) is given. We have 4 channels on
312     * each of the 12 half-boards, this method decodes which PMT is cables to which
313     * channel.
314     * @param hh Channel
315     * @param kk HalfBoard
316     */
317    Int_t ToFLevel2::GetPMTid(Int_t hh, Int_t kk){
318      //
319      short tof[4][24] = {
320        {4, 4,  4,  4,  1,  1, 2, 2,  3,  3, 3, 3,  3,  3, 1, 1,  1,  1, 2, 3,  3, 3, 3,  4},
321        {1, 3,  5,  7, 10, 12, 2, 4,  2,  4, 6, 8, 10, 12, 1, 5,  3,  9, 7, 9, 11, 1, 5,  9},
322        {2, 2,  2,  2,  1,  1, 1, 1,  4,  4, 4, 4,  4,  4, 2, 1,  2,  1, 2, 2,  2, 3, 3,  4},
323        {6, 8, 12, 10,  8,  6, 4, 2, 12, 10, 8, 6,  4,  2, 9, 7, 11, 11, 5, 3,  1, 3, 7, 11}
324      };
325      //
326      Int_t ind = 0;
327      Int_t k = 0;
328      while (k < 24){
329        Int_t j = 0;
330        while (j < 2){
331          Int_t ch = tof[2*j][k]     - 1;
332          Int_t hb = tof[2*j + 1][k] - 1;      
333          /* tofEvent->tdc[ch][hb] */      
334          if( ch == hh && hb == kk ){      
335            ind = 2*k + j;
336            break;
337          };
338          j++;
339        };
340        k++;
341      };
342      return ind;
343    };
344    
345    /**
346     * Method to get the PMT name (like "S11_1A") if the PMT_ID is given. The first
347     * PMT=0 is S11_1A, then S11_1B, then S11_2A, and so on, up to S32_3B which is PMT=47
348     * @param ind  PMT_ID (0 - 47)
349     */
350    TString ToFLevel2::GetPMTName(Int_t ind){
351      
352      TString pmtname = " ";
353      
354      TString photoS[48] = {
355        "S11_1A", "S11_1B", "S11_2A", "S11_2B", "S11_3A", "S11_3B", "S11_4A", "S11_4B",
356        "S11_5A", "S11_5B", "S11_6A", "S11_6B", "S11_7A", "S11_7B", "S11_8A", "S11_8B",
357        "S12_1A", "S12_1B", "S12_2A", "S12_2B", "S12_3A", "S12_3B", "S12_4A", "S12_4B", "S12_5A",  "S12_5B", "S12_6A", "S12_6B",
358        "S21_1A", "S21_1B", "S21_2A", "S21_2B",
359        "S22_1A", "S22_1B", "S22_2A", "S22_2B",
360        "S31_1A", "S31_1B", "S31_2A", "S31_2B", "S31_3A", "S31_3B",
361        "S32_1A", "S32_1B", "S32_2A", "S32_2B", "S32_3A", "S32_3B"
362      };
363      
364    
365      pmtname = photoS[ind].Data();
366    
367      return pmtname;
368    };
369    
370    /**
371     * Method to get the PMT index if the PMT ID is given. This method is the
372     * "reverse" of method "GetPMTid"
373     * @param ind  PMT_ID (0 - 47)
374     * @param hb   HalfBoard
375     * @param ch   Channel
376     */
377    void ToFLevel2::GetPMTIndex(Int_t ind, Int_t &hb, Int_t &ch){
378      //
379      short tof[4][24] = {
380        {4, 4,  4,  4,  1,  1, 2, 2,  3,  3, 3, 3,  3,  3, 1, 1,  1,  1, 2, 3,  3, 3, 3,  4},
381        {1, 3,  5,  7, 10, 12, 2, 4,  2,  4, 6, 8, 10, 12, 1, 5,  3,  9, 7, 9, 11, 1, 5,  9},
382        {2, 2,  2,  2,  1,  1, 1, 1,  4,  4, 4, 4,  4,  4, 2, 1,  2,  1, 2, 2,  2, 3, 3,  4},
383        {6, 8, 12, 10,  8,  6, 4, 2, 12, 10, 8, 6,  4,  2, 9, 7, 11, 11, 5, 3,  1, 3, 7, 11}
384      };
385      //
386      Int_t k = 0;
387      while (k < 24){
388        Int_t j = 0;
389        while (j < 2){
390          /* tofEvent->tdc[ch][hb] */            
391          if( ind == 2*k + j ){
392            ch = tof[2*j][k]     - 1;
393            hb = tof[2*j + 1][k] - 1;      
394            return;
395          };
396          j++;
397        };
398        k++;
399      };
400      return;
401    };
402    
403    /**
404     * Fills a struct cToFLevel2 with values from a ToFLevel2 object (to put data into a F77 common).
405     */
406    void ToFLevel2::GetLevel2Struct(cToFLevel2 *l2) const{
407    
408      for(Int_t i=0;i<6;i++)
409        l2->tof_j_flag[i]=tof_j_flag[i];
410    
411      if(ToFTrk){ //ELENA
412          l2->ntoftrk = ToFTrk->GetEntries();
413          for(Int_t j=0;j<l2->ntoftrk;j++){
414              l2->toftrkseqno[j]= ((ToFTrkVar*)ToFTrk->At(j))->trkseqno;
415              l2->npmttdc[j]= ((ToFTrkVar*)ToFTrk->At(j))->npmttdc;
416              for(Int_t i=0;i<l2->npmttdc[j];i++){
417                  l2->pmttdc[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->pmttdc.At(i);
418                  l2->tdcflag[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->tdcflag.At(i); // gf: 30 Nov 2006
419              }
420              for(Int_t i=0;i<13;i++)
421                  l2->beta[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->beta[i];
422              
423              l2->npmtadc[j]= ((ToFTrkVar*)ToFTrk->At(j))->npmtadc;
424              for(Int_t i=0;i<l2->npmtadc[j];i++){
425                  l2->pmtadc[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->pmtadc.At(i);
426                  l2->adcflag[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->adcflag.At(i); // gf: 30 Nov 2006
427                  l2->dedx[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->dedx.At(i);
428              }
429              for(Int_t i=0;i<3;i++){
430                  l2->xtofpos[i][j]=((ToFTrkVar*)ToFTrk->At(j))->xtofpos[i];
431                  l2->ytofpos[i][j]=((ToFTrkVar*)ToFTrk->At(j))->ytofpos[i];
432              }
433          }
434      } //ELENA
435        
436      if(PMT){ //ELENA
437          l2->npmt = PMT->GetEntries();
438          for(Int_t j=0;j<l2->npmt;j++){
439              l2->pmt_id[j] = ((ToFPMT*)PMT->At(j))->pmt_id;
440              l2->adc[j] =((ToFPMT*)PMT->At(j))->adc;
441              l2->tdc_tw[j] =((ToFPMT*)PMT->At(j))->tdc_tw;
442          }
443      } //ELENA
444    }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.15

  ViewVC Help
Powered by ViewVC 1.1.23