/[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.1.1.1 by mocchiut, Sat Jun 17 12:14:56 2006 UTC revision 1.42 by pam-fi, Fri Oct 17 07:54:17 2014 UTC
# Line 1  Line 1 
1  #include <TObject.h>  /**
2     * \file ToFLevel2.cpp
3     * \author Gianfranca DeRosa, Wolfgang Menn
4     *
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     * WM apr 2009: bug found by Nicola in method "GetPaddlePlane"
9     */
10    
11  #include <ToFLevel2.h>  #include <ToFLevel2.h>
 #include <iostream>  
12  using namespace std;  using namespace std;
13    ClassImp(ToFPMT);
14    ClassImp(ToFdEdx);
15    ClassImp(ToFGeom);
16  ClassImp(ToFTrkVar);  ClassImp(ToFTrkVar);
17  ClassImp(ToFLevel2);  ClassImp(ToFLevel2);
18    
19  ToFTrkVar::ToFTrkVar() {  ToFPMT::ToFPMT(){
20      pmt_id = 0;
21    trkseqno = 0;    adc = 0.;
22      tdc_tw = 0.;
23      tdc = 0.;
24      l0flag_adc = 0.;
25      l0flag_tdc = 0.;
26    }
27    
28    for (Int_t kk=0; kk<13;kk++){  ToFPMT::ToFPMT(const ToFPMT &t){
29      beta_a[kk] = 0;    pmt_id = t.pmt_id;
30    }    adc = t.adc;
31      tdc_tw = t.tdc_tw;
32      tdc = t.tdc;
33    }
34    
35    for (Int_t kk=0; kk<4;kk++){  void ToFPMT::Clear(Option_t *t){
36      for (Int_t hh=0; hh<12;hh++){    pmt_id = 0;
37        adc_c[hh][kk] = 0;    adc = 0.;
38      }    tdc_tw = 0.;
39    }    tdc = 0.;
40  }  }
41    
 ToFTrkVar::ToFTrkVar(const ToFTrkVar &t){  
42    
   trkseqno = t.trkseqno;    
43    
44    memcpy(adc_c,t.adc_c,sizeof(adc_c));  ToFTrkVar::ToFTrkVar() {
45    memcpy(beta_a,t.beta_a,sizeof(beta_a));    trkseqno = 0;
46  }    npmttdc = 0;
47      npmtadc = 0;
48      pmttdc = TArrayI(48);
49      pmtadc = TArrayI(48);
50      tdcflag = TArrayI(48); // gf: 30 Nov 2006
51      adcflag = TArrayI(48); // gf: 30 Nov 2006
52      dedx = TArrayF(48);
53      //
54      //
55      memset(beta,  0, 13*sizeof(Float_t));
56      memset(xtofpos,  0, 3*sizeof(Float_t));
57      memset(ytofpos,  0, 3*sizeof(Float_t));
58      memset(xtr_tof,  0, 6*sizeof(Float_t));
59      memset(ytr_tof,  0, 6*sizeof(Float_t));
60      //
61    };
62    
63  ToFLevel2::ToFLevel2() {      void ToFTrkVar::Clear(Option_t *t) {
64      trkseqno = 0;
65      npmttdc = 0;
66      npmtadc = 0;
67      pmttdc.Reset();
68      pmtadc.Reset();
69      tdcflag.Reset(); // gf: 30 Nov 2006
70      adcflag.Reset(); // gf: 30 Nov 2006
71      dedx.Reset();
72    //    //
73    ToFTrk = new TClonesArray("ToFTrkVar",1);    memset(beta,  0, 13*sizeof(Float_t));
74      memset(xtofpos,  0, 3*sizeof(Float_t));
75      memset(ytofpos,  0, 3*sizeof(Float_t));
76      memset(xtr_tof,  0, 6*sizeof(Float_t));
77      memset(ytr_tof,  0, 6*sizeof(Float_t));
78    //    //
79    for (Int_t kk=0; kk<3;kk++){  };
     xtofpos[kk] = 0.;  
     ytofpos[kk] = 0.;  
   }  
80    
81    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;  
   }  
82    
83    for (Int_t kk=0; kk<4;kk++){    trkseqno = t.trkseqno;  
84      for (Int_t hh=0; hh<12;hh++){    //
85        adctof_c[hh][kk] = 0;    npmttdc = t.npmttdc;
86      }    npmtadc = t.npmtadc;
87    }      (t.pmttdc).Copy(pmttdc);
88      (t.pmtadc).Copy(pmtadc);
89      (t.tdcflag).Copy(tdcflag); // gf: 30 Nov 2006
90      (t.adcflag).Copy(adcflag); // gf: 30 Nov 2006
91      (t.dedx).Copy(dedx);
92      //
93      memcpy(beta,t.beta,sizeof(beta));
94      memcpy(xtofpos,t.xtofpos,sizeof(xtofpos));
95      memcpy(ytofpos,t.ytofpos,sizeof(ytofpos));
96      memcpy(xtr_tof,t.xtr_tof,sizeof(xtr_tof));
97      memcpy(ytr_tof,t.ytr_tof,sizeof(ytr_tof));
98      //
99    };
100    
101    for (Int_t kk=0; kk<4;kk++){  ToFLevel2::ToFLevel2() {    
102      for (Int_t hh=0; hh<12;hh++){    //
103        tdc_c[hh][kk] = 0;  //  PMT = new TClonesArray("ToFPMT",12); //ELENA
104      }  //  ToFTrk = new TClonesArray("ToFTrkVar",2); //ELENA
105    }      PMT = 0; //ELENA
106      ToFTrk = 0; //ELENA
107      //
108      this->Clear();
109      //
110    };
111    
112    void ToFLevel2::Set(){//ELENA
113        if(!PMT)PMT = new TClonesArray("ToFPMT",12); //ELENA
114        if(!ToFTrk)ToFTrk = new TClonesArray("ToFTrkVar",2); //ELENA
115    }//ELENA
116    //--------------------------------------
117    //
118    //
119    //--------------------------------------
120    void ToFLevel2::SetTrackArray(TClonesArray *track){//ELENA
121        if(track && strcmp(track->GetClass()->GetName(),"ToFTrkVar")==0){
122            if(ToFTrk)ToFTrk->Clear("C");
123            ToFTrk = track;
124        }
125    }
126    
127    void ToFLevel2::Clear(Option_t *t){
128      //
129      if(ToFTrk)ToFTrk->Delete(); //ELENA
130      if(PMT)PMT->Delete(); //ELENA
131      memset(tof_j_flag, 0, 6*sizeof(Int_t));
132      unpackError = 0;
133      unpackWarning = 0;
134      //
135  };  };
136    
137    void ToFLevel2::Delete(Option_t *t){ //ELENA
138      //
139      if(ToFTrk){
140          ToFTrk->Delete(); //ELENA
141          delete ToFTrk;  //ELENA
142      }
143      if(PMT){
144          PMT->Delete(); //ELENA
145          delete PMT; //ELENA
146      } //ELENA
147      //
148    }; //ELENA
149    
150  ToFTrkVar *ToFLevel2::GetToFTrkVar(Int_t itrk){  ToFTrkVar *ToFLevel2::GetToFTrkVar(Int_t itrk){
151    //        //    
152    if(itrk >= ntrk()){    if(itrk >= ntrk()){
# Line 69  ToFTrkVar *ToFLevel2::GetToFTrkVar(Int_t Line 155  ToFTrkVar *ToFLevel2::GetToFTrkVar(Int_t
155      return(NULL);      return(NULL);
156    }      }  
157    //    //
158      if(!ToFTrk)return 0; //ELENA
159    TClonesArray &t = *(ToFTrk);    TClonesArray &t = *(ToFTrk);
160    ToFTrkVar *toftrack = (ToFTrkVar*)t[itrk];    ToFTrkVar *toftrack = (ToFTrkVar*)t[itrk];
161    return toftrack;    return toftrack;
162  }  }
163    
164    /**
165     * Retrieves the tof track matching the seqno-th tracker stored track.
166     *
167     */
168    ToFTrkVar *ToFLevel2::GetToFStoredTrack(int seqno){
169    
170      if( ntrk()==0 ){
171        printf("ToFLevel2::GetToFStoredTrack(int) : requested tracker SeqNo %i but no ToFrimeter tracks are stored\n",seqno);
172        return NULL;
173      };
174      
175      ToFTrkVar *c = 0;
176      Int_t it_tof=0;
177        
178      do {
179        c = GetToFTrkVar(it_tof);
180        it_tof++;
181      } while( c && seqno != c->trkseqno && it_tof < ntrk());      
182      
183      if(!c || seqno != c->trkseqno){
184        c = 0;
185        if(seqno!=-1 ) printf("ToFLevel2::GetToFStoredTrack(int) : requested tracker SeqNo %i does not match ToFrimeter stored tracks\n",seqno);
186      };
187      return c;
188        
189    }
190    
191    
192    ToFPMT *ToFLevel2::GetToFPMT(Int_t ihit){
193      //    
194      if(ihit >= npmt()){
195        printf(" ToFLevel2 ERROR: pmt variables set %i does not exists! \n",ihit);
196        printf("                  stored pmt variables = %i \n",npmt());
197        return(NULL);
198      }  
199      //
200      if(!PMT)return 0; //ELENA
201      TClonesArray &t = *(PMT);
202      ToFPMT *tofpmt = (ToFPMT*)t[ihit];
203      return tofpmt;
204    }
205  //--------------------------------------  //--------------------------------------
206  //  //
207  //  //
208  //--------------------------------------  //--------------------------------------
209  /**  /**
210   * 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)
211     * @param Plane index (0,1,2,3,4,5).
212   */   */
213    Int_t  ToFLevel2::GetToFPlaneID(Int_t ip){    Int_t  ToFLevel2::GetToFPlaneID(Int_t ip){
214        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;
215        else return -1;        else return -1;
216    };    };
217  /**  /**
218   * 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)
219     * @param plane Plane ID (11, 12, 21, 22, 31, 32)
220   */   */
221    Int_t  ToFLevel2::GetToFPlaneIndex(Int_t plane_id){    Int_t  ToFLevel2::GetToFPlaneIndex(Int_t plane_id){
222        if(        if(
# Line 99  ToFTrkVar *ToFLevel2::GetToFTrkVar(Int_t Line 230  ToFTrkVar *ToFLevel2::GetToFTrkVar(Int_t
230        else return -1;        else return -1;
231    };    };
232  /**  /**
233   * 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
234     * from both PMTs. The method uses the "tof_j_flag" variable.
235   * @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).
236   * @param paddle_id Paddle ID.   * @param paddle_id Paddle ID.
237   * @return 1 if the paddle was hit.   * @return 1 if the paddle was hit.
# Line 109  ToFTrkVar *ToFLevel2::GetToFTrkVar(Int_t Line 241  ToFTrkVar *ToFLevel2::GetToFTrkVar(Int_t
241      if     (plane>=6             ) ip = GetToFPlaneIndex(plane);      if     (plane>=6             ) ip = GetToFPlaneIndex(plane);
242      else if(plane>=0 && plane < 6) ip = plane;      else if(plane>=0 && plane < 6) ip = plane;
243      Int_t flag=0;      Int_t flag=0;
244      if(ip != -1)flag = tof_j_flag[ip] & (int)pow(2,paddle_id);      if(ip != -1)flag = tof_j_flag[ip] & (int)pow(2.,(double)paddle_id);
245      if(      if(
246         (ip == 0 && paddle_id < 8 && flag) ||         (ip == 0 && paddle_id < 8 && flag) ||
247         (ip == 1 && paddle_id < 6 && flag) ||         (ip == 1 && paddle_id < 6 && flag) ||
# Line 129  Int_t ToFLevel2::GetNHitPaddles(Int_t pl Line 261  Int_t ToFLevel2::GetNHitPaddles(Int_t pl
261      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);
262      return npad;      return npad;
263  };  };
264    
265    /**
266     * Method to get the number of hit paddles on a ToF plane.
267     * @param plane Plane ID (11, 12, 21, 22, 31, 32) or Plane index (0,1,2,3,4,5).
268     */
269    Int_t ToFLevel2::GetTrueNHitPaddles(Int_t plane){
270        Int_t npad=0;
271        TClonesArray* Pmt = this->PMT;
272        int paddle[24];
273        memset(paddle,0, 24*sizeof(int));
274        for(int i=0; i<Pmt->GetEntries(); i++) {  //loop per vedere quale TOF è colpito
275          ToFPMT* pmthit = (ToFPMT*)Pmt->At(i);
276          int pplane = -1;
277          int ppaddle = -1;
278          GetPMTPaddle(pmthit->pmt_id,pplane,ppaddle);
279          if ( pplane == plane ) paddle[ppaddle]++;
280        }
281        for(int i=0;i<24;i++) if ( paddle[i]>0 ) npad++;
282    
283        return npad;
284    };
285    
286    //wm Nov 08
287    //gf Apr 07
288    /**
289     * Method to get the mean dEdx from a ToF layer - ATTENTION:
290     * It will sum up the dEdx of all the paddles, but since by definition
291     * only the paddle hitted by the track gets a dEdx value and the other
292     * paddles are set to zero, the output is just the dEdx of the hitted
293     * paddle in each layer!
294     * The "adcfl" option is not very useful (an artificial dEdx is per
295     * definition= 1 mip and not a real measurement), anyway left in the code
296     * @param notrack Track Number
297     * @param plane Plane index (0,1,2,3,4,5)
298     * @param adcflag in the plane (100<-> independent of the adcflag; !=0&&!=100 <-> at least one PMT with adcflag!=0; )
299     */
300    Float_t ToFLevel2::GetdEdx(ToFTrkVar *trk, Int_t plane, Int_t adcfl){
301      //  printf("fiffi\n");
302      Float_t dedx = 0.;
303      Float_t PadEdx =0.;
304      Int_t SatWarning;
305      Int_t pad=-1;
306      //
307      if(!trk) return 0; //ELENA
308      //
309      if ( trk->trkseqno == -1 ){ //standalone, only paddles along the track, or about...
310        //    printf("ciccio\n");
311        Float_t xleft=0;
312        Float_t xright=0;
313        Float_t yleft=0;
314        Float_t yright=0;
315        Float_t xtof_temp[6]={100.,100.,100.,100.,100.,100.};
316        Float_t ytof_temp[6]={100.,100.,100.,100.,100.,100.};
317        ToFTrkVar *t_tof = trk;
318        
319        xtof_temp[0]=t_tof->xtofpos[0];
320        ytof_temp[0]=t_tof->ytofpos[0];
321        xtof_temp[1]=t_tof->xtofpos[0];
322        ytof_temp[1]=t_tof->ytofpos[0];
323    
324        xtof_temp[2]=t_tof->xtofpos[1];
325        ytof_temp[2]=t_tof->ytofpos[1];
326        xtof_temp[3]=t_tof->xtofpos[1];
327        ytof_temp[3]=t_tof->ytofpos[1];
328    
329        xtof_temp[4]=t_tof->xtofpos[2];
330        ytof_temp[4]=t_tof->ytofpos[2];
331        xtof_temp[5]=t_tof->xtofpos[2];
332        ytof_temp[5]=t_tof->ytofpos[2];
333    
334        if(t_tof->xtofpos[0]<100. && t_tof->ytofpos[0]<100.){
335          xtof_temp[1]=t_tof->xtofpos[0];
336          ytof_temp[0]=t_tof->ytofpos[0];
337        }else if(t_tof->xtofpos[0]>=100. && t_tof->ytofpos[0]<100.){
338          ytof_temp[0]=t_tof->ytofpos[0];
339          this->GetPaddleGeometry(0,(Int_t)log2(this->tof_j_flag[0]),xleft, xright, yleft, yright);
340          xtof_temp[1]=xleft+2.55;
341        }else if(t_tof->ytofpos[0]>=100. && t_tof->xtofpos[0]<100.){
342          xtof_temp[1]=t_tof->xtofpos[0];
343          this->GetPaddleGeometry(1,(Int_t)log2(this->tof_j_flag[1]),xleft, xright, yleft, yright);
344          ytof_temp[0]=yleft+2.75;
345        }
346        
347        if(t_tof->xtofpos[1]<100. && t_tof->ytofpos[1]<100.){
348          xtof_temp[2]=t_tof->xtofpos[1];
349          ytof_temp[3]=t_tof->ytofpos[1];
350        }else if(t_tof->xtofpos[1]>=100. && t_tof->ytofpos[1]<100.){
351          ytof_temp[3]=t_tof->ytofpos[1];
352          this->GetPaddleGeometry(3,(Int_t)log2(this->tof_j_flag[3]),xleft, xright, yleft, yright);
353          xtof_temp[2]=xleft+4.5;
354        }else if(t_tof->ytofpos[1]>=100. && t_tof->xtofpos[1]<100.){
355          xtof_temp[2]=t_tof->xtofpos[1];
356          this->GetPaddleGeometry(2,(Int_t)log2(this->tof_j_flag[2]),xleft, xright, yleft, yright);
357          ytof_temp[3]=yleft+3.75;
358        }
359        
360        if(t_tof->xtofpos[2]<100. && t_tof->ytofpos[2]<100.){
361          xtof_temp[5]=t_tof->xtofpos[2];
362          ytof_temp[4]=t_tof->ytofpos[2];
363        }else if(t_tof->xtofpos[2]>=100. && t_tof->ytofpos[2]<100.){
364          ytof_temp[4]=t_tof->ytofpos[2];
365          this->GetPaddleGeometry(4,(Int_t)log2(this->tof_j_flag[4]),xleft, xright, yleft, yright);
366          xtof_temp[5]=xleft+3;
367        }else if(t_tof->ytofpos[2]>=100. && t_tof->xtofpos[2]<100.){
368          xtof_temp[5]=t_tof->xtofpos[2];
369          this->GetPaddleGeometry(5,(Int_t)log2(this->tof_j_flag[5]),xleft, xright, yleft, yright);
370          ytof_temp[4]=yleft+2.5;
371        }
372    
373        if ( (xtof_temp[0])> 17.85 && fabs(xtof_temp[0])<17.85+4. ) xtof_temp[0] =17.84;
374        if ( (xtof_temp[1])> 17.85 && fabs(xtof_temp[1])<17.85+4. ) xtof_temp[1] =17.84;
375        if ( (ytof_temp[0])> 13.75 && fabs(ytof_temp[0])<13.75+4. ) ytof_temp[0] =13.74;
376        if ( (ytof_temp[1])> 13.75 && fabs(ytof_temp[1])<13.75+4. ) ytof_temp[1] =13.74;
377        if ( (xtof_temp[0])< -17.85 && fabs(xtof_temp[0])>-(17.85+4.) ) xtof_temp[0] =-17.84;
378        if ( (xtof_temp[1])< -17.85 && fabs(xtof_temp[1])>-(17.85+4.) ) xtof_temp[1] =-17.84;
379        if ( (ytof_temp[0])< -13.75 && fabs(ytof_temp[0])>-(13.75+4.) ) ytof_temp[0] =-13.74;
380        if ( (ytof_temp[1])< -13.75 && fabs(ytof_temp[1])>-(13.75+4.) ) ytof_temp[1] =-13.74;
381    
382        if ( (xtof_temp[2])> 4.5 && (xtof_temp[2])<4.5+4. ) xtof_temp[2] =4.4;
383        if ( (xtof_temp[3])> 4.45 && (xtof_temp[3])<4.5+4. ) xtof_temp[3] =4.4;
384        if ( (ytof_temp[2])> 3.75 && (ytof_temp[2])<3.75+4. ) ytof_temp[2] =3.74;
385        if ( (ytof_temp[3])> 3.75 && (ytof_temp[3])<3.75+4. ) ytof_temp[3] =3.74;
386        if ( (xtof_temp[2])< -4.5 && (xtof_temp[2])>-(4.5+4.) ) xtof_temp[2] =-4.4;
387        if ( (xtof_temp[3])< -4.45 && (xtof_temp[3])>-(4.5+4.) ) xtof_temp[3] =-4.4;
388        if ( (ytof_temp[2])< -3.75 && (ytof_temp[2])>-(3.75+4.) ) ytof_temp[2] =-3.74;
389        if ( (ytof_temp[3])< -3.75 && (ytof_temp[3])>-(3.75+4.) ) ytof_temp[3] =-3.74;
390    
391        if ( (xtof_temp[4])> 6. && (xtof_temp[4])<6.+4. ) xtof_temp[2] =5.9;
392        if ( (xtof_temp[5])> 6. && (xtof_temp[5])<6.+4. ) xtof_temp[3] =5.9;
393        if ( (ytof_temp[4])> 5. && (ytof_temp[4])<5.+4. ) ytof_temp[2] =4.9;
394        if ( (ytof_temp[5])> 5. && (ytof_temp[5])<5.+4. ) ytof_temp[3] =4.9;
395        if ( (xtof_temp[4])< -6. && (xtof_temp[4])>-(6.+4.) ) xtof_temp[2] =-5.9;
396        if ( (xtof_temp[5])< -6. && (xtof_temp[5])>-(6.+4.) ) xtof_temp[3] =-5.9;
397        if ( (ytof_temp[4])< -5. && (ytof_temp[4])>-(5.+4.) ) ytof_temp[2] =-4.9;
398        if ( (ytof_temp[5])< -5. && (ytof_temp[5])>-(5.+4.) ) ytof_temp[3] =-4.9;
399    
400    
401        for (Int_t ii=0; ii<GetNPaddle(plane); ii++){
402          Int_t paddleid=ii;
403          pad = GetPaddleid(plane,paddleid);
404          Int_t IpaddleT=-1;
405          IpaddleT=this->GetPaddleIdOfTrack(xtof_temp[plane],ytof_temp[plane], plane,0.0);
406    //      printf("SSS %i %i %f %f  %f %f \n",IpaddleT,paddleid,xtof_temp[plane],ytof_temp[plane],t_tof->xtofpos[plane],t_tof->ytofpos[plane]);
407          //      if ( IpaddleT == paddleid || IpaddleT-1 == paddleid || IpaddleT+1 == paddleid ){
408          if ( IpaddleT == paddleid || GetTrueNHitPaddles(plane) == 1 ){
409            //IpaddleT-1 == paddleid || IpaddleT+1 == paddleid ){
410            GetdEdxPaddle(trk, pad, adcfl, PadEdx, SatWarning);
411            dedx += PadEdx;
412          }
413        };
414      } else {
415        for (Int_t ii=0; ii<GetNPaddle(plane); ii++){
416          Int_t paddleid=ii;
417          pad = GetPaddleid(plane,paddleid);
418          GetdEdxPaddle(trk, pad, adcfl, PadEdx, SatWarning);
419          dedx += PadEdx;
420    //      printf("TTT %i %i %f\n",paddleid,plane,PadEdx);
421        };
422      }
423      //
424      return(dedx);
425    };
426    
427    
428    //wm Nov 08
429    //gf Apr 07
430    /**
431     * Method to get the mean dEdx from a ToF layer - ATTENTION:
432     * It will sum up the dEdx of all the paddles, but since by definition
433     * only the paddle hitted by the track gets a dEdx value and the other
434     * paddles are set to zero, the output is just the dEdx of the hitted
435     * paddle in each layer!
436     * The "adcfl" option is not very useful (an artificial dEdx is per
437     * definition= 1 mip and not a real measurement), anyway left in the code
438     * @param notrack Track Number
439     * @param plane Plane index (0,1,2,3,4,5)
440     * @param adcflag in the plane (100<-> independent of the adcflag; !=0&&!=100 <-> at least one PMT with adcflag!=0; )
441     */
442    Float_t ToFLevel2::GetdEdx(Int_t notrack, Int_t plane, Int_t adcfl){
443      //  printf("fiffi\n");
444      Float_t dedx = 0.;
445      Float_t PadEdx =0.;
446      Int_t SatWarning;
447      Int_t pad=-1;
448      //
449      ToFTrkVar *trk = GetToFTrkVar(notrack);
450      if(!trk) return 0; //ELENA
451      //
452      if ( trk->trkseqno == -1 ){ //standalone, only paddles along the track, or about...
453        //    printf("ciccio\n");
454        Float_t xleft=0;
455        Float_t xright=0;
456        Float_t yleft=0;
457        Float_t yright=0;
458        Float_t xtof_temp[6]={100.,100.,100.,100.,100.,100.};
459        Float_t ytof_temp[6]={100.,100.,100.,100.,100.,100.};
460        ToFTrkVar *t_tof = trk;
461        
462        xtof_temp[0]=t_tof->xtofpos[0];
463        ytof_temp[0]=t_tof->ytofpos[0];
464        xtof_temp[1]=t_tof->xtofpos[0];
465        ytof_temp[1]=t_tof->ytofpos[0];
466    
467        xtof_temp[2]=t_tof->xtofpos[1];
468        ytof_temp[2]=t_tof->ytofpos[1];
469        xtof_temp[3]=t_tof->xtofpos[1];
470        ytof_temp[3]=t_tof->ytofpos[1];
471    
472        xtof_temp[4]=t_tof->xtofpos[2];
473        ytof_temp[4]=t_tof->ytofpos[2];
474        xtof_temp[5]=t_tof->xtofpos[2];
475        ytof_temp[5]=t_tof->ytofpos[2];
476    
477        if(t_tof->xtofpos[0]<100. && t_tof->ytofpos[0]<100.){
478          xtof_temp[1]=t_tof->xtofpos[0];
479          ytof_temp[0]=t_tof->ytofpos[0];
480        }else if(t_tof->xtofpos[0]>=100. && t_tof->ytofpos[0]<100.){
481          ytof_temp[0]=t_tof->ytofpos[0];
482          this->GetPaddleGeometry(0,(Int_t)log2(this->tof_j_flag[0]),xleft, xright, yleft, yright);
483          xtof_temp[1]=xleft+2.55;
484        }else if(t_tof->ytofpos[0]>=100. && t_tof->xtofpos[0]<100.){
485          xtof_temp[1]=t_tof->xtofpos[0];
486          this->GetPaddleGeometry(1,(Int_t)log2(this->tof_j_flag[1]),xleft, xright, yleft, yright);
487          ytof_temp[0]=yleft+2.75;
488        }
489        
490        if(t_tof->xtofpos[1]<100. && t_tof->ytofpos[1]<100.){
491          xtof_temp[2]=t_tof->xtofpos[1];
492          ytof_temp[3]=t_tof->ytofpos[1];
493        }else if(t_tof->xtofpos[1]>=100. && t_tof->ytofpos[1]<100.){
494          ytof_temp[3]=t_tof->ytofpos[1];
495          this->GetPaddleGeometry(3,(Int_t)log2(this->tof_j_flag[3]),xleft, xright, yleft, yright);
496          xtof_temp[2]=xleft+4.5;
497        }else if(t_tof->ytofpos[1]>=100. && t_tof->xtofpos[1]<100.){
498          xtof_temp[2]=t_tof->xtofpos[1];
499          this->GetPaddleGeometry(2,(Int_t)log2(this->tof_j_flag[2]),xleft, xright, yleft, yright);
500          ytof_temp[3]=yleft+3.75;
501        }
502        
503        if(t_tof->xtofpos[2]<100. && t_tof->ytofpos[2]<100.){
504          xtof_temp[5]=t_tof->xtofpos[2];
505          ytof_temp[4]=t_tof->ytofpos[2];
506        }else if(t_tof->xtofpos[2]>=100. && t_tof->ytofpos[2]<100.){
507          ytof_temp[4]=t_tof->ytofpos[2];
508          this->GetPaddleGeometry(4,(Int_t)log2(this->tof_j_flag[4]),xleft, xright, yleft, yright);
509          xtof_temp[5]=xleft+3;
510        }else if(t_tof->ytofpos[2]>=100. && t_tof->xtofpos[2]<100.){
511          xtof_temp[5]=t_tof->xtofpos[2];
512          this->GetPaddleGeometry(5,(Int_t)log2(this->tof_j_flag[5]),xleft, xright, yleft, yright);
513          ytof_temp[4]=yleft+2.5;
514        }
515    
516        if ( (xtof_temp[0])> 17.85 && fabs(xtof_temp[0])<17.85+4. ) xtof_temp[0] =17.84;
517        if ( (xtof_temp[1])> 17.85 && fabs(xtof_temp[1])<17.85+4. ) xtof_temp[1] =17.84;
518        if ( (ytof_temp[0])> 13.75 && fabs(ytof_temp[0])<13.75+4. ) ytof_temp[0] =13.74;
519        if ( (ytof_temp[1])> 13.75 && fabs(ytof_temp[1])<13.75+4. ) ytof_temp[1] =13.74;
520        if ( (xtof_temp[0])< -17.85 && fabs(xtof_temp[0])>-(17.85+4.) ) xtof_temp[0] =-17.84;
521        if ( (xtof_temp[1])< -17.85 && fabs(xtof_temp[1])>-(17.85+4.) ) xtof_temp[1] =-17.84;
522        if ( (ytof_temp[0])< -13.75 && fabs(ytof_temp[0])>-(13.75+4.) ) ytof_temp[0] =-13.74;
523        if ( (ytof_temp[1])< -13.75 && fabs(ytof_temp[1])>-(13.75+4.) ) ytof_temp[1] =-13.74;
524    
525        if ( (xtof_temp[2])> 4.5 && (xtof_temp[2])<4.5+4. ) xtof_temp[2] =4.4;
526        if ( (xtof_temp[3])> 4.45 && (xtof_temp[3])<4.5+4. ) xtof_temp[3] =4.4;
527        if ( (ytof_temp[2])> 3.75 && (ytof_temp[2])<3.75+4. ) ytof_temp[2] =3.74;
528        if ( (ytof_temp[3])> 3.75 && (ytof_temp[3])<3.75+4. ) ytof_temp[3] =3.74;
529        if ( (xtof_temp[2])< -4.5 && (xtof_temp[2])>-(4.5+4.) ) xtof_temp[2] =-4.4;
530        if ( (xtof_temp[3])< -4.45 && (xtof_temp[3])>-(4.5+4.) ) xtof_temp[3] =-4.4;
531        if ( (ytof_temp[2])< -3.75 && (ytof_temp[2])>-(3.75+4.) ) ytof_temp[2] =-3.74;
532        if ( (ytof_temp[3])< -3.75 && (ytof_temp[3])>-(3.75+4.) ) ytof_temp[3] =-3.74;
533    
534        if ( (xtof_temp[4])> 6. && (xtof_temp[4])<6.+4. ) xtof_temp[2] =5.9;
535        if ( (xtof_temp[5])> 6. && (xtof_temp[5])<6.+4. ) xtof_temp[3] =5.9;
536        if ( (ytof_temp[4])> 5. && (ytof_temp[4])<5.+4. ) ytof_temp[2] =4.9;
537        if ( (ytof_temp[5])> 5. && (ytof_temp[5])<5.+4. ) ytof_temp[3] =4.9;
538        if ( (xtof_temp[4])< -6. && (xtof_temp[4])>-(6.+4.) ) xtof_temp[2] =-5.9;
539        if ( (xtof_temp[5])< -6. && (xtof_temp[5])>-(6.+4.) ) xtof_temp[3] =-5.9;
540        if ( (ytof_temp[4])< -5. && (ytof_temp[4])>-(5.+4.) ) ytof_temp[2] =-4.9;
541        if ( (ytof_temp[5])< -5. && (ytof_temp[5])>-(5.+4.) ) ytof_temp[3] =-4.9;
542    
543    
544        for (Int_t ii=0; ii<GetNPaddle(plane); ii++){
545          Int_t paddleid=ii;
546          pad = GetPaddleid(plane,paddleid);
547          Int_t IpaddleT=-1;
548          IpaddleT=this->GetPaddleIdOfTrack(xtof_temp[plane],ytof_temp[plane], plane,0.0);
549    //      printf("SSS %i %i %f %f  %f %f \n",IpaddleT,paddleid,xtof_temp[plane],ytof_temp[plane],t_tof->xtofpos[plane],t_tof->ytofpos[plane]);
550          //      if ( IpaddleT == paddleid || IpaddleT-1 == paddleid || IpaddleT+1 == paddleid ){
551          if ( IpaddleT == paddleid || GetTrueNHitPaddles(plane) == 1 ){
552            //IpaddleT-1 == paddleid || IpaddleT+1 == paddleid ){
553            GetdEdxPaddle(notrack, pad, adcfl, PadEdx, SatWarning);
554            dedx += PadEdx;
555          }
556        };
557      } else {
558        for (Int_t ii=0; ii<GetNPaddle(plane); ii++){
559          Int_t paddleid=ii;
560          pad = GetPaddleid(plane,paddleid);
561          GetdEdxPaddle(notrack, pad, adcfl, PadEdx, SatWarning);
562          dedx += PadEdx;
563    //      printf("TTT %i %i %f\n",paddleid,plane,PadEdx);
564        };
565      }
566      //
567      return(dedx);
568    };
569    
570    /**
571     * Method to fill the ADC_C 4x12 matrix with the dEdx values and the TDC 4x12 matrix
572     * with the time-walk corrected TDC values.
573     * @param notrack Track Number
574     * @param adc  ADC_C matrix with dEdx values
575     * @param tdc  TDC matrix
576     */
577    void ToFLevel2::GetMatrix(Int_t notrack, Float_t adc[4][12], Float_t tdc[4][12]){
578      //
579      for (Int_t aa=0; aa<4;aa++){
580        for (Int_t bb=0; bb<12;bb++){
581          adc[aa][bb] = 1000.;
582          tdc[aa][bb] = 4095.;
583        };
584      };
585      //
586      Int_t pmt_id = 0;
587      Int_t hh = 0;
588      Int_t kk = 0;
589      //
590      ToFTrkVar *trk = GetToFTrkVar(notrack);
591      if(!trk)return; //ELENA
592      //
593      for (Int_t i=0; i<trk->npmtadc; i++){
594        //
595        pmt_id = (trk->pmtadc).At(i);
596        //
597        GetPMTIndex(pmt_id,hh,kk);
598        adc[kk][hh] = (trk->dedx).At(i);  
599        //
600      };
601      //
602      for (Int_t i=0; i<npmt(); i++){
603        //
604        ToFPMT *pmt = GetToFPMT(i);
605        if(!pmt)break; //ELENA
606        //
607        GetPMTIndex(pmt->pmt_id,hh,kk);
608        //
609        tdc[kk][hh] = pmt->tdc_tw;  
610        //
611      };
612      //
613      return;
614    };
615    
616    
617    /**
618     * Method to get the plane index (0 - 5) for the PMT_ID as input
619     * @param pmt_id  PMT_ID (0 - 47)
620     */
621    Int_t ToFLevel2::GetPlaneIndex(Int_t pmt_id){
622      TString pmtname = GetPMTName(pmt_id);
623      pmtname.Resize(3);
624      if ( !strcmp(pmtname,"S11") ) return(0);
625      if ( !strcmp(pmtname,"S12") ) return(1);
626      if ( !strcmp(pmtname,"S21") ) return(2);
627      if ( !strcmp(pmtname,"S22") ) return(3);
628      if ( !strcmp(pmtname,"S31") ) return(4);
629      if ( !strcmp(pmtname,"S32") ) return(5);
630      return(-1);
631    };
632    
633    
634    /**
635     * Method to get the PMT_ID if the index (4,12) is given. We have 4 channels on
636     * each of the 12 half-boards, this method decodes which PMT is cables to which
637     * channel.
638     * @param hh Channel
639     * @param kk HalfBoard
640     */
641    Int_t ToFLevel2::GetPMTid(Int_t hh, Int_t kk){
642      //
643      short tof[4][24] = {
644        {4, 4,  4,  4,  1,  1, 2, 2,  3,  3, 3, 3,  3,  3, 1, 1,  1,  1, 2, 3,  3, 3, 3,  4},
645        {1, 3,  5,  7, 10, 12, 2, 4,  2,  4, 6, 8, 10, 12, 1, 5,  3,  9, 7, 9, 11, 1, 5,  9},
646        {2, 2,  2,  2,  1,  1, 1, 1,  4,  4, 4, 4,  4,  4, 2, 1,  2,  1, 2, 2,  2, 3, 3,  4},
647        {6, 8, 12, 10,  8,  6, 4, 2, 12, 10, 8, 6,  4,  2, 9, 7, 11, 11, 5, 3,  1, 3, 7, 11}
648      };
649      //
650      Int_t ind = 0;
651      Int_t k = 0;
652      while (k < 24){
653        Int_t j = 0;
654        while (j < 2){
655          Int_t ch = tof[2*j][k]     - 1;
656          Int_t hb = tof[2*j + 1][k] - 1;      
657          /* tofEvent->tdc[ch][hb] */      
658          if( ch == hh && hb == kk ){      
659            ind = 2*k + j;
660            break;
661          };
662          j++;
663        };
664        k++;
665      };
666      return ind;
667    };
668    
669    
670    /**
671     * Method to get the PMT index if the PMT ID is given. This method is the
672     * "reverse" of method "GetPMTid"
673     * @param ind  PMT_ID (0 - 47)
674     * @param hb   HalfBoard
675     * @param ch   Channel
676     */
677    void ToFLevel2::GetPMTIndex(Int_t ind, Int_t &hb, Int_t &ch){
678      //
679      short tof[4][24] = {
680        {4, 4,  4,  4,  1,  1, 2, 2,  3,  3, 3, 3,  3,  3, 1, 1,  1,  1, 2, 3,  3, 3, 3,  4},
681        {1, 3,  5,  7, 10, 12, 2, 4,  2,  4, 6, 8, 10, 12, 1, 5,  3,  9, 7, 9, 11, 1, 5,  9},
682        {2, 2,  2,  2,  1,  1, 1, 1,  4,  4, 4, 4,  4,  4, 2, 1,  2,  1, 2, 2,  2, 3, 3,  4},
683        {6, 8, 12, 10,  8,  6, 4, 2, 12, 10, 8, 6,  4,  2, 9, 7, 11, 11, 5, 3,  1, 3, 7, 11}
684      };
685      //
686      Int_t k = 0;
687      while (k < 24){
688        Int_t j = 0;
689        while (j < 2){
690          /* tofEvent->tdc[ch][hb] */            
691          if( ind == 2*k + j ){
692            ch = tof[2*j][k]     - 1;
693            hb = tof[2*j + 1][k] - 1;      
694            return;
695          };
696          j++;
697        };
698        k++;
699      };
700      return;
701    };
702    
703    
704    
705    //  wm Nov 08 revision - saturation values included
706    /// gf Apr 07
707    /**
708     * Method to get the dEdx from a given ToF paddle.
709     * If two PMTs are good, the mean dEdx of both PMTs is taken, otherwise
710     * just the dEdx of the "good" PMT. If both PMTs are above saturation => dEdx=1000
711     * @param notrack Track Number
712     * @param Paddle index (0,1,...,23).
713     * @param adcflag in the paddle (100<-> independent of the adcflag; !=0&&!=100 <-> at least one PMT with adcflag!=0; )
714     * @param PadEdx dEdx from a given ToF paddle
715     * @param SatWarning 1 if the PMT ios near saturation region (adcraw ~3000)
716     */
717    void ToFLevel2::GetdEdxPaddle(Int_t notrack, Int_t paddleid, Int_t adcfl, Float_t &PadEdx, Int_t &SatWarning){
718    
719      /*
720        Float_t  PMTsat[48] = {
721        3162.14, 3165.48, 3153.85, 3085.73, 3089.65, 3107.64, 3097.52, 3078.37,
722        3130.05, 3087.07, 3112.22, 3102.92, 3080.58, 3092.55, 3087.94, 3125.03,
723        3094.09, 3143.16, 3125.51, 3181.27, 3092.09, 3124.98, 3069.3, 3095.53,
724        3097.11, 3133.53, 3114.73, 3113.01, 3091.19, 3097.99, 3033.84, 3134.98,
725        3081.37, 3111.04, 3066.77, 3108.17, 3133, 3111.06, 3052.52, 3140.66,
726        3106.33, 3094.85, 3150.85, 3118.8, 3096.24, 3118.47,3111.36, 3117.11 } ;
727      */
728    
729      // new values from Napoli dec 2008
730      Float_t  PMTsat[48] = {
731        3176.35,3178.19,3167.38,3099.73,3117.00,3126.29,3111.44,3092.27,
732        3146.48,3094.41,3132.13,3115.37,3099.32,3110.97,3111.80,3143.14,
733        3106.72,3153.44,3136.00,3188.96,3104.73,3140.45,3073.18,3106.62,
734        3112.48,3146.92,3127.24,3136.52,3109.59,3112.89,3045.15,3147.26,
735        3095.92,3121.05,3083.25,3123.62,3150.92,3125.30,3067.60,3160.18,
736        3119.36,3108.92,3164.77,3133.64,3111.47,3131.98,3128.87,3135.56 };
737    
738      for (Int_t i=0; i<48;i++) PMTsat[i] = PMTsat[i] - 5.;  // safety margin
739    
740    
741      PadEdx = 0.;
742      //  SatWarning = 1000;
743      SatWarning = 0;   // 0=good, increase for each bad PMT
744    
745      Float_t dEdx[48] = {0};
746      Int_t pmt_id = -1;
747      Float_t adcraw[48];
748      //
749      ToFTrkVar *trk = GetToFTrkVar(notrack);
750      if(!trk) return; //ELENA
751      //
752    
753      Int_t pmtleft=-1;
754      Int_t pmtright=-1;
755      GetPaddlePMT(paddleid, pmtleft, pmtright);
756    
757      adcraw[pmtleft] = 4095;
758      adcraw[pmtright] = 4095;
759    
760      
761      for (Int_t jj=0; jj<npmt(); jj++){
762        
763        ToFPMT *pmt = GetToFPMT(jj);
764        if(!pmt)break; //ELENA
765        
766        pmt_id = pmt->pmt_id;
767        if(pmt_id==pmtleft){
768          adcraw[pmtleft] = pmt->adc;
769        }
770        
771        if(pmt_id==pmtright){
772          adcraw[pmtright] = pmt->adc;
773        }
774      }
775    
776      
777      for (Int_t i=0; i<trk->npmtadc; i++){
778    
779        if((trk->adcflag).At(i)==0 || adcfl==100){
780          if((trk->pmtadc).At(i) == pmtleft)dEdx[pmtleft] = (trk->dedx).At(i);
781          if((trk->pmtadc).At(i) == pmtright)dEdx[pmtright] = (trk->dedx).At(i);
782        }else{
783          if((trk->pmtadc).At(i) == pmtleft)dEdx[pmtleft] = 0.;
784          if((trk->pmtadc).At(i) == pmtright)dEdx[pmtright] = 0.;
785        }
786      }
787    
788    
789      //  if( adcraw[pmtleft] >3000 || adcraw[pmtright] >3000)SatWarning=1;  //old version
790    
791      // Increase SatWarning Counter for each PMT>Sat
792      if( adcraw[pmtleft] > PMTsat[pmtleft])SatWarning++;  
793      if( adcraw[pmtright] > PMTsat[pmtright])SatWarning++;
794    
795      // if ADC  > sat set dEdx=1000
796      if( adcraw[pmtleft] > PMTsat[pmtleft]) dEdx[pmtleft] = 1000.;
797      if( adcraw[pmtright] > PMTsat[pmtright]) dEdx[pmtright] = 1000. ;
798    
799      // if two PMT are good, take mean dEdx, otherwise only the good dEdx
800      if(dEdx[pmtleft]<1000 && dEdx[pmtright]<1000) PadEdx = (dEdx[pmtleft]+dEdx[pmtright])*0.5;
801      if(dEdx[pmtleft]==1000 && dEdx[pmtright]<1000) PadEdx = dEdx[pmtright];  
802      if(dEdx[pmtleft]<1000 && dEdx[pmtright]==1000) PadEdx = dEdx[pmtleft];
803      
804    };
805    
806    //
807    //  wm Nov 08 revision - saturation values included
808    /// gf Apr 07
809    /**
810     * Method to get the dEdx from a given ToF paddle.
811     * If two PMTs are good, the mean dEdx of both PMTs is taken, otherwise
812     * just the dEdx of the "good" PMT. If both PMTs are above saturation => dEdx=1000
813     * @param notrack Track Number
814     * @param Paddle index (0,1,...,23).
815     * @param adcflag in the paddle (100<-> independent of the adcflag; !=0&&!=100 <-> at least one PMT with adcflag!=0; )
816     * @param PadEdx dEdx from a given ToF paddle
817     * @param SatWarning 1 if the PMT ios near saturation region (adcraw ~3000)
818     */
819    void ToFLevel2::GetdEdxPaddle(ToFTrkVar *trk, Int_t paddleid, Int_t adcfl, Float_t &PadEdx, Int_t &SatWarning){
820    
821      /*
822        Float_t  PMTsat[48] = {
823        3162.14, 3165.48, 3153.85, 3085.73, 3089.65, 3107.64, 3097.52, 3078.37,
824        3130.05, 3087.07, 3112.22, 3102.92, 3080.58, 3092.55, 3087.94, 3125.03,
825        3094.09, 3143.16, 3125.51, 3181.27, 3092.09, 3124.98, 3069.3, 3095.53,
826        3097.11, 3133.53, 3114.73, 3113.01, 3091.19, 3097.99, 3033.84, 3134.98,
827        3081.37, 3111.04, 3066.77, 3108.17, 3133, 3111.06, 3052.52, 3140.66,
828        3106.33, 3094.85, 3150.85, 3118.8, 3096.24, 3118.47,3111.36, 3117.11 } ;
829      */
830    
831      // new values from Napoli dec 2008
832      Float_t  PMTsat[48] = {
833        3176.35,3178.19,3167.38,3099.73,3117.00,3126.29,3111.44,3092.27,
834        3146.48,3094.41,3132.13,3115.37,3099.32,3110.97,3111.80,3143.14,
835        3106.72,3153.44,3136.00,3188.96,3104.73,3140.45,3073.18,3106.62,
836        3112.48,3146.92,3127.24,3136.52,3109.59,3112.89,3045.15,3147.26,
837        3095.92,3121.05,3083.25,3123.62,3150.92,3125.30,3067.60,3160.18,
838        3119.36,3108.92,3164.77,3133.64,3111.47,3131.98,3128.87,3135.56 };
839    
840      for (Int_t i=0; i<48;i++) PMTsat[i] = PMTsat[i] - 5.;  // safety margin
841    
842    
843      PadEdx = 0.;
844      //  SatWarning = 1000;
845      SatWarning = 0;   // 0=good, increase for each bad PMT
846    
847      Float_t dEdx[48] = {0};
848      Int_t pmt_id = -1;
849      Float_t adcraw[48];
850      //
851      if(!trk) return; //ELENA
852      //
853    
854      Int_t pmtleft=-1;
855      Int_t pmtright=-1;
856      GetPaddlePMT(paddleid, pmtleft, pmtright);
857    
858      adcraw[pmtleft] = 4095;
859      adcraw[pmtright] = 4095;
860    
861      
862      for (Int_t jj=0; jj<npmt(); jj++){
863        
864        ToFPMT *pmt = GetToFPMT(jj);
865        if(!pmt)break; //ELENA
866        
867        pmt_id = pmt->pmt_id;
868        if(pmt_id==pmtleft){
869          adcraw[pmtleft] = pmt->adc;
870        }
871        
872        if(pmt_id==pmtright){
873          adcraw[pmtright] = pmt->adc;
874        }
875      }
876    
877      
878      for (Int_t i=0; i<trk->npmtadc; i++){
879    
880        if((trk->adcflag).At(i)==0 || adcfl==100){
881          if((trk->pmtadc).At(i) == pmtleft)dEdx[pmtleft] = (trk->dedx).At(i);
882          if((trk->pmtadc).At(i) == pmtright)dEdx[pmtright] = (trk->dedx).At(i);
883        }else{
884          if((trk->pmtadc).At(i) == pmtleft)dEdx[pmtleft] = 0.;
885          if((trk->pmtadc).At(i) == pmtright)dEdx[pmtright] = 0.;
886        }
887      }
888    
889    
890      //  if( adcraw[pmtleft] >3000 || adcraw[pmtright] >3000)SatWarning=1;  //old version
891    
892      // Increase SatWarning Counter for each PMT>Sat
893      if( adcraw[pmtleft] > PMTsat[pmtleft])SatWarning++;  
894      if( adcraw[pmtright] > PMTsat[pmtright])SatWarning++;
895    
896      // if ADC  > sat set dEdx=1000
897      if( adcraw[pmtleft] > PMTsat[pmtleft]) dEdx[pmtleft] = 1000.;
898      if( adcraw[pmtright] > PMTsat[pmtright]) dEdx[pmtright] = 1000. ;
899    
900      // if two PMT are good, take mean dEdx, otherwise only the good dEdx
901      if(dEdx[pmtleft]<1000 && dEdx[pmtright]<1000) PadEdx = (dEdx[pmtleft]+dEdx[pmtright])*0.5;
902      if(dEdx[pmtleft]==1000 && dEdx[pmtright]<1000) PadEdx = dEdx[pmtright];  
903      if(dEdx[pmtleft]<1000 && dEdx[pmtright]==1000) PadEdx = dEdx[pmtleft];
904      
905    };
906    
907    // gf Apr 07
908    
909    /**
910     * Method to get the PMT name (like "S11_1A") if the PMT_ID is given.
911     * Indexes of corresponding  plane, paddle and  pmt are also given as output.
912     * @param ind  PMT_ID (0 - 47)
913     * @param iplane plane index (0 - 5)
914     * @param ipaddle paddle index (relative to the plane)
915     * @param ipmt pmt index (0(A), 1(B))
916     */
917    TString ToFLevel2::GetPMTName(Int_t ind, Int_t &iplane, Int_t &ipaddle,Int_t &ipmt){
918      
919      TString pmtname = " ";
920      
921      TString photoS[48] = {
922        "S11_1A", "S11_1B", "S11_2A", "S11_2B", "S11_3A", "S11_3B", "S11_4A",
923        "S11_4B",
924        "S11_5A", "S11_5B", "S11_6A", "S11_6B", "S11_7A", "S11_7B", "S11_8A",
925        "S11_8B",
926        "S12_1A", "S12_1B", "S12_2A", "S12_2B", "S12_3A", "S12_3B", "S12_4A",
927        "S12_4B", "S12_5A",  "S12_5B", "S12_6A", "S12_6B",
928        "S21_1A", "S21_1B", "S21_2A", "S21_2B",
929        "S22_1A", "S22_1B", "S22_2A", "S22_2B",
930        "S31_1A", "S31_1B", "S31_2A", "S31_2B", "S31_3A", "S31_3B",
931        "S32_1A", "S32_1B", "S32_2A", "S32_2B", "S32_3A", "S32_3B"
932      };
933      
934      
935      pmtname = photoS[ind].Data();
936      
937      TString ss = pmtname(1,2);
938      iplane  = (int)(atoi(ss.Data())/10)*2-3+atoi(ss.Data())%10;
939      ss = pmtname(4);
940      ipaddle = atoi(ss.Data())-1 ;
941      if( pmtname.Contains("A") )ipmt=0;
942      if( pmtname.Contains("B") )ipmt=1;
943      
944      return pmtname;
945    };
946    /**
947     * Method to get the PMT name (like "S11_1A") if the PMT_ID is given
948     * @param ind  PMT_ID (0 - 47)
949     */
950    TString ToFLevel2::GetPMTName(Int_t ind){
951    
952      Int_t iplane  = -1;
953      Int_t ipaddle = -1;
954      Int_t ipmt    = -1;
955      return GetPMTName(ind,iplane,ipaddle,ipmt);
956      
957    };
958    
959    // wm jun 08
960    Int_t ToFLevel2::GetPaddleIdOfTrack(Float_t xtr, Float_t ytr, Int_t plane){
961    return GetPaddleIdOfTrack(xtr ,ytr ,plane, 0.4);
962    }
963    
964    // gf Apr 07
965    Int_t ToFLevel2::GetPaddleIdOfTrack(Float_t xtr, Float_t ytr, Int_t plane, Float_t margin){
966      
967      Double_t xt,yt,xl,xh,yl,yh;
968      
969      Float_t tof11_x[8] = {-17.85,-12.75,-7.65,-2.55,2.55,7.65,12.75,17.85};
970      Float_t tof12_y[6] = { -13.75,-8.25,-2.75,2.75,8.25,13.75};
971      Float_t tof21_y[2] = { 3.75,-3.75};
972      Float_t tof22_x[2] = { -4.5,4.5};
973      Float_t tof31_x[3] = { -6.0,0.,6.0};
974      Float_t tof32_y[3] = { -5.0,0.0,5.0};
975      
976      //  S11 8 paddles  33.0 x 5.1 cm
977      //  S12 6 paddles  40.8 x 5.5 cm
978      //  S21 2 paddles  18.0 x 7.5 cm
979      //  S22 2 paddles  15.0 x 9.0 cm
980      //  S31 3 paddles  15.0 x 6.0 cm
981      //  S32 3 paddles  18.0 x 5.0 cm
982      
983      Int_t paddleidoftrack=-1;
984      //
985      
986      //--- S11 ------
987      
988      if(plane==0){
989        xt = xtr;
990        yt = ytr;
991        paddleidoftrack=-1;
992        yl = -33.0/2. ;
993        yh =  33.0/2. ;
994        if ((yt>yl)&&(yt<yh)) {
995          for (Int_t i1=0; i1<8;i1++){
996            xl = tof11_x[i1] - (5.1-margin)/2. ;
997            xh = tof11_x[i1] + (5.1-margin)/2. ;
998            if ((xt>xl)&&(xt<xh))  paddleidoftrack=i1;
999          }
1000        }
1001      }
1002      //      cout<<"S11  "<<paddleidoftrack[0]<<"\n";
1003      
1004      //--- S12 -------
1005      if(plane==1){
1006        xt = xtr;
1007        yt = ytr;
1008        paddleidoftrack=-1;
1009        xl = -40.8/2. ;
1010        xh =  40.8/2. ;
1011        
1012        if ((xt>xl)&&(xt<xh)) {
1013          for (Int_t i1=0; i1<6;i1++){
1014            yl = tof12_y[i1] - (5.5-margin)/2. ;
1015            yh = tof12_y[i1] + (5.5-margin)/2. ;
1016            if ((yt>yl)&&(yt<yh))  paddleidoftrack=i1;
1017          }
1018        }
1019      }
1020      
1021      //--- S21 ------
1022    
1023      if(plane==2){
1024        xt = xtr;
1025        yt = ytr;
1026        paddleidoftrack=-1;
1027        xl = -18./2. ;
1028        xh =  18./2. ;
1029        
1030        if ((xt>xl)&&(xt<xh)) {
1031          for (Int_t i1=0; i1<2;i1++){
1032            yl = tof21_y[i1] - (7.5-margin)/2. ;
1033            yh = tof21_y[i1] + (7.5-margin)/2. ;
1034            if ((yt>yl)&&(yt<yh))  paddleidoftrack=i1;
1035          }
1036        }
1037      }
1038      
1039      //--- S22 ------
1040      if(plane==3){
1041        xt = xtr;
1042        yt = ytr;
1043        paddleidoftrack=-1;
1044        yl = -15./2. ;
1045        yh =  15./2. ;
1046        
1047        if ((yt>yl)&&(yt<yh)) {
1048          for (Int_t i1=0; i1<2;i1++){
1049            xl = tof22_x[i1] - (9.0-margin)/2. ;
1050            xh = tof22_x[i1] + (9.0-margin)/2. ;
1051            if ((xt>xl)&&(xt<xh))  paddleidoftrack=i1;
1052          }
1053        }
1054      }  
1055      
1056      //--- S31 ------
1057      if(plane==4){
1058        xt = xtr;
1059        yt = ytr;
1060        paddleidoftrack=-1;
1061        yl = -15.0/2. ;
1062        yh =  15.0/2. ;
1063        
1064        if ((yt>yl)&&(yt<yh)) {
1065          for (Int_t i1=0; i1<3;i1++){
1066            xl = tof31_x[i1] - (6.0-margin)/2. ;
1067            xh = tof31_x[i1] + (6.0-margin)/2. ;
1068            if ((xt>xl)&&(xt<xh))  paddleidoftrack=i1;
1069          }
1070        }
1071      }  
1072      
1073      //---  S32 ------
1074      if(plane==5){
1075        xt = xtr;
1076        yt = ytr;
1077        paddleidoftrack=-1;
1078        xl = -18.0/2. ;
1079        xh =  18.0/2. ;
1080        
1081        if ((xt>xl)&&(xt<xh)) {
1082          for (Int_t i1=0; i1<3;i1++){
1083            yl = tof32_y[i1] - (5.0-margin)/2. ;
1084            yh = tof32_y[i1] + (5.0-margin)/2. ;
1085            if ((yt>yl)&&(yt<yh)) paddleidoftrack=i1;
1086          }
1087        }
1088      }
1089      
1090      return paddleidoftrack;
1091    
1092    }  
1093    
1094    //
1095    
1096    // gf Apr 07
1097    
1098    void ToFLevel2::GetPMTPaddle(Int_t pmt_id, Int_t &plane, Int_t &paddle){
1099      
1100      plane = GetPlaneIndex(pmt_id);
1101    
1102      if(plane == 0){
1103        if(pmt_id==0 || pmt_id==1)paddle=0;
1104        if(pmt_id==2 || pmt_id==3)paddle=1;
1105        if(pmt_id==4 || pmt_id==5)paddle=2;
1106        if(pmt_id==6 || pmt_id==7)paddle=3;
1107        if(pmt_id==8 || pmt_id==9)paddle=4;
1108        if(pmt_id==10 || pmt_id==11)paddle=5;
1109        if(pmt_id==12 || pmt_id==13)paddle=6;
1110        if(pmt_id==14 || pmt_id==15)paddle=7;
1111      }
1112      
1113      if(plane == 1){
1114        if(pmt_id==16 || pmt_id==17)paddle=0;
1115        if(pmt_id==18 || pmt_id==19)paddle=1;
1116        if(pmt_id==20 || pmt_id==21)paddle=2;
1117        if(pmt_id==22 || pmt_id==23)paddle=3;
1118        if(pmt_id==24 || pmt_id==25)paddle=4;
1119        if(pmt_id==26 || pmt_id==27)paddle=5;
1120      }
1121      
1122      if(plane == 2){
1123        if(pmt_id==28 || pmt_id==29)paddle=0;
1124        if(pmt_id==30 || pmt_id==31)paddle=1;
1125      }
1126      
1127      if(plane == 3){
1128        if(pmt_id==32 || pmt_id==33)paddle=0;
1129        if(pmt_id==34 || pmt_id==35)paddle=1;
1130      }
1131      
1132      if(plane == 4){
1133        if(pmt_id==36 || pmt_id==37)paddle=0;
1134        if(pmt_id==38 || pmt_id==39)paddle=1;
1135        if(pmt_id==40 || pmt_id==41)paddle=2;
1136      }
1137      
1138      if(plane == 5){
1139        if(pmt_id==42 || pmt_id==43)paddle=0;
1140        if(pmt_id==44 || pmt_id==45)paddle=1;
1141        if(pmt_id==46 || pmt_id==47)paddle=2;
1142      }
1143      return;
1144    }
1145    
1146    //
1147    
1148    // gf Apr 07
1149    
1150    void ToFLevel2::GetPaddlePMT(Int_t paddle, Int_t &pmtleft, Int_t &pmtright){
1151      pmtleft=paddle*2;
1152      pmtright= pmtleft+1;  
1153      return;
1154    }
1155    
1156    //
1157    
1158    
1159    
1160    // // gf Apr 07
1161    
1162    void ToFLevel2::GetPaddleGeometry(Int_t plane, Int_t paddle, Float_t &xleft, Float_t &xright, Float_t &yleft, Float_t &yright){
1163      
1164      Int_t i1;
1165    
1166      Float_t tof11_x[8] = {-17.85,-12.75,-7.65,-2.55,2.55,7.65,12.75,17.85};
1167      Float_t tof12_y[6] = { -13.75,-8.25,-2.75,2.75,8.25,13.75};
1168      Float_t tof21_y[2] = { 3.75,-3.75};
1169      Float_t tof22_x[2] = { -4.5,4.5};
1170      Float_t tof31_x[3] = { -6.0,0.,6.0};
1171      Float_t tof32_y[3] = { -5.0,0.0,5.0};
1172            
1173      //  S11 8 paddles  33.0 x 5.1 cm
1174      //  S12 6 paddles  40.8 x 5.5 cm
1175      //  S21 2 paddles  18.0 x 7.5 cm
1176      //  S22 2 paddles  15.0 x 9.0 cm
1177      //  S31 3 paddles  15.0 x 6.0 cm
1178      //  S32 3 paddles  18.0 x 5.0 cm
1179    
1180      if(plane==0)
1181        {
1182          for (i1=0; i1<8;i1++){
1183            if(i1 == paddle){
1184              xleft = tof11_x[i1] - 5.1/2.;
1185              xright = tof11_x[i1] + 5.1/2.;
1186              yleft = -33.0/2.;
1187              yright = 33.0/2.;
1188            }
1189          }
1190        }
1191      
1192      if(plane==1)
1193        {
1194          for (i1=0; i1<6;i1++){
1195            if(i1 == paddle){
1196              xleft = -40.8/2.;
1197              xright = 40.8/2.;
1198              yleft = tof12_y[i1] - 5.5/2.;
1199              yright = tof12_y[i1] + 5.5/2.;
1200            }
1201          }
1202        }
1203    
1204      if(plane==2)
1205        {
1206          for (i1=0; i1<2;i1++){
1207            if(i1 == paddle){
1208              xleft =  -18./2.;
1209              xright = 18./2.;
1210              yleft = tof21_y[i1] - 7.5/2.;
1211              yright = tof21_y[i1] + 7.5/2.;
1212            }
1213          }
1214        }
1215      
1216      if(plane==3)
1217        {
1218          for (i1=0; i1<2;i1++){
1219            if(i1 == paddle){
1220              xleft = tof22_x[i1] - 9.0/2.;
1221              xright = tof22_x[i1] + 9.0/2.;
1222              yleft = -15./2.;
1223              yright = 15./2.;
1224            }
1225          }
1226        }
1227    
1228    
1229      if(plane==4)
1230        {
1231          for (i1=0; i1<3;i1++){
1232            if(i1 == paddle){
1233              xleft = tof31_x[i1] - 6.0/2.;
1234              xright = tof31_x[i1] + 6.0/2.;
1235              yleft = -15./2.;
1236              yright = 15./2.;
1237            }
1238          }
1239        }
1240    
1241      if(plane==5)
1242        {
1243          for (i1=0; i1<3;i1++){
1244            if(i1 == paddle){
1245              xleft = -18.0/2.;
1246              xright = 18.0/2.;
1247              yleft = tof32_y[i1] - 5.0/2.;
1248              yright = tof32_y[i1] + 5.0/2.;
1249            }
1250          }
1251        }
1252      return;
1253    }
1254    
1255    // gf Apr 07
1256    /**
1257     * Method to get the paddle index (0,...23) if the plane ID and the paddle id in the plane is given.
1258     * This method is the
1259     * "reverse" of method "GetPaddlePlane"
1260     * @param plane    (0 - 5)
1261     * @param paddle   (plane=0, paddle = 0,...5)
1262     * @param padid    (0 - 23)
1263     */
1264    Int_t ToFLevel2::GetPaddleid(Int_t plane, Int_t paddle)
1265    {
1266      Int_t padid=-1;
1267      Int_t pads[6]={8,6,2,2,3,3};
1268    
1269      int somma=0;
1270      int np=plane;
1271      for(Int_t j=0; j<np; j++){
1272        somma+=pads[j];
1273      }
1274      padid=paddle+somma;
1275      return padid;
1276    
1277    }
1278    
1279    
1280    // gf Apr 07
1281    /**
1282     * Method to get the plane ID and the paddle id in the plane if the paddle index (0,...23) is given.
1283     * This method is the
1284     * "reverse" of method "GetPaddleid"
1285     * @param pad      (0 - 23)
1286     * @param plane    (0 - 5)
1287     * @param paddle   (plane=0, paddle = 0,...5)
1288     */
1289    void ToFLevel2::GetPaddlePlane(Int_t pad, Int_t &plane, Int_t &paddle)
1290    {
1291    
1292      Int_t pads11=8;
1293      Int_t pads12=6;
1294      Int_t pads21=2;
1295      Int_t pads22=2;
1296      Int_t pads31=3;
1297      // Int_t pads32=3;
1298    
1299      if(pad<8){
1300        plane=0;
1301        paddle=pad;
1302        return;
1303      }
1304    
1305      if((7<pad)&&(pad<14)){
1306        plane=1;
1307        paddle=pad-pads11;
1308        return;
1309      }
1310      
1311      if((13<pad)&&(pad<16)){
1312        plane=2;
1313        paddle=pad-pads11-pads12;
1314        return;
1315      }
1316    
1317      if((15<pad)&&(pad<18)){
1318        plane=3;
1319        paddle=pad-pads11-pads12-pads21;
1320        return;
1321      }
1322    
1323      if((17<pad)&&(pad<21)){
1324        plane=4;
1325        paddle=pad-pads11-pads12-pads21-pads22;
1326        return;
1327      }
1328    
1329      if((20<pad)&&(pad<24)){
1330        plane=5;
1331        paddle=pad-pads11-pads12-pads21-pads22-pads31;
1332        return;
1333      }  
1334    
1335    }
1336    
1337    
1338    Int_t ToFLevel2::GetNPaddle(Int_t plane){
1339    
1340      Int_t npaddle=-1;
1341    
1342      Int_t pads11=8;
1343      Int_t pads12=6;
1344      Int_t pads21=2;
1345      Int_t pads22=2;
1346      Int_t pads31=3;
1347      Int_t pads32=3;
1348    
1349      if(plane==0)npaddle=pads11;
1350      if(plane==1)npaddle=pads12;
1351      if(plane==2)npaddle=pads21;
1352      if(plane==3)npaddle=pads22;
1353      if(plane==4)npaddle=pads31;
1354      if(plane==5)npaddle=pads32;
1355    
1356      return npaddle;
1357    
1358    }
1359    
1360    
1361    
1362    /// wm feb 08
1363    
1364    /**
1365     * Method to calculate Beta from the 12 single measurements
1366     * we check the individual weights for artificial TDC values, then calculate
1367     * am mean beta for the first time. In a second step we loop again through
1368     * the single measurements, checking for the residual from the mean
1369     * The cut on the residual reject measurements > "x"-sigma. A chi2 value is
1370     * calculated, furthermore a "quality" value by adding the weights which
1371     * are finally used. If all measurements are taken, "quality" will be = 22.47.
1372     * A chi2 cut around 3-4 and a quality-cut > 20 is needed for clean beta
1373     * measurements like antiprotons etc.
1374     * The Level2 output is derived in the fortran routines using: 10.,10.,20.
1375     * @param notrack Track Number
1376     * @param cut on residual: difference between single measurement and mean
1377     * @param cut on "quality"
1378     * @param cut on chi2
1379     */
1380    
1381    Float_t ToFLevel2::CalcBeta(Int_t notrack, Float_t resmax, Float_t qualitycut, Float_t chi2cut){
1382    
1383    //  cout<<" in CalcBeta "<<resmax<<" "<<chi2cut<<" "<<qualitycut<<endl;
1384    
1385      Float_t bxx = 100.;
1386      //
1387      ToFTrkVar *trk = GetToFTrkVar(notrack);
1388      if(!trk) return 0; //ELENA
1389    
1390    
1391      Float_t chi2,xhelp,beta_mean;
1392      Float_t w_i[12],quality,sw,sxw,res,betachi,beta_mean_inv;
1393      Float_t b[12],tdcfl;
1394      Int_t  pmt_id,pmt_plane;
1395    
1396      for (Int_t i=0; i<12; i++){
1397        b[i] = trk->beta[i];
1398                                  }
1399          
1400    
1401    //========================================================================
1402    //---  Find out ToF layers with artificial TDC values & fill vector    ---
1403    //========================================================================
1404    
1405    Float_t  w_il[6];
1406    
1407         for (Int_t jj=0; jj<6;jj++) {
1408             w_il[jj] = 1000.;
1409                                     }
1410    
1411    
1412      for (Int_t i=0; i<trk->npmttdc; i++){
1413        //
1414        pmt_id = (trk->pmttdc).At(i);
1415        pmt_plane = GetPlaneIndex(pmt_id);
1416        tdcfl = (trk->tdcflag).At(i);
1417        if (w_il[pmt_plane] != 1.) w_il[pmt_plane] = tdcfl; //tdcflag
1418                                         };
1419      
1420    //========================================================================
1421    //---  Set weights for the 12 measurements using information for top and bottom:
1422    //---  if no measurements: weight = set to very high value=> not used
1423    //---  top or bottom artificial: weight*sqrt(2)
1424    //---  top and bottom artificial: weight*sqrt(2)*sqrt(2)
1425    //========================================================================
1426    
1427    Int_t itop[12] = {0,0,1,1,2,2,3,3,0,0,1,1};
1428    Int_t ibot[12] = {4,5,4,5,4,5,4,5,2,3,2,3};
1429    
1430         xhelp= 1E09;
1431      
1432         for (Int_t jj=0; jj<12;jj++) {
1433         if (jj<4)           xhelp = 0.11;    // S1-S3
1434         if ((jj>3)&&(jj<8)) xhelp = 0.18;    // S2-S3
1435         if (jj>7)           xhelp = 0.28;    // S1-S2
1436         if ((w_il[itop[jj]] == 1000.) && (w_il[ibot[jj]] == 1000.)) xhelp = 1E09;
1437         if ((w_il[itop[jj]] == 1) || (w_il[ibot[jj]] == 1.)) xhelp = xhelp*1.414 ;
1438         if ((w_il[itop[jj]] == 1) && (w_il[ibot[jj]] == 1.)) xhelp = xhelp*2. ;
1439    
1440         w_i[jj] = 1./xhelp;
1441                                      }
1442    
1443    
1444    //========================================================================
1445    //--- Calculate mean beta for the first time -----------------------------
1446    //--- We are using "1/beta" since its error is gaussian ------------------
1447    //========================================================================
1448    
1449          Int_t icount=0;
1450          sw=0.;
1451          sxw=0.;
1452          beta_mean=100.;
1453    
1454              for (Int_t jj=0; jj<12;jj++){
1455            if ((fabs(1./b[jj])>0.1)&&(fabs(1./b[jj])<15.))
1456             {
1457                icount= icount+1;
1458                sxw=sxw + (1./b[jj])*w_i[jj]*w_i[jj] ;
1459                sw =sw + w_i[jj]*w_i[jj] ;
1460    
1461             }
1462             }
1463    
1464          if (icount>0) beta_mean=1./(sxw/sw);
1465          beta_mean_inv = 1./beta_mean;
1466    
1467    //========================================================================
1468    //--- Calculate beta for the second time, use residuals of the single
1469    //--- measurements to get a chi2 value
1470    //========================================================================
1471    
1472          icount=0;
1473          sw=0.;
1474          sxw=0.;
1475          betachi = 100.;
1476          chi2 = 0.;
1477          quality=0.;
1478    
1479    
1480              for (Int_t jj=0; jj<12;jj++){
1481           if ((fabs(1./b[jj])>0.1)&&(fabs(1./b[jj])<15.)&&(w_i[jj]>0.01)) {
1482                res = beta_mean_inv - (1./b[jj]) ;
1483                if (fabs(res*w_i[jj])<resmax)          {;
1484                chi2 = chi2 + pow((res*w_i[jj]),2) ;
1485                icount= icount+1;
1486                sxw=sxw + (1./b[jj])*w_i[jj]*w_i[jj] ;
1487                sw =sw + w_i[jj]*w_i[jj] ;
1488                                                   }
1489                                                                            }
1490                                          }
1491          quality = sqrt(sw) ;
1492    
1493          if (icount==0) chi2 = 1000.;
1494          if (icount>0) chi2 = chi2/(icount) ;
1495          if (icount>0) betachi=1./(sxw/sw);
1496    
1497       bxx = 100.;
1498       if ((chi2 < chi2cut)&&(quality>qualitycut)) bxx = betachi;
1499      //
1500      return(bxx);
1501    };
1502    
1503    
1504    ////////////////////////////////////////////////////
1505    ////////////////////////////////////////////////////
1506    
1507    
1508    /**
1509     * Fills a struct cToFLevel2 with values from a ToFLevel2 object (to put data into a F77 common).
1510     */
1511    void ToFLevel2::GetLevel2Struct(cToFLevel2 *l2) const{
1512    
1513      for(Int_t i=0;i<6;i++)
1514        l2->tof_j_flag[i]=tof_j_flag[i];
1515    
1516      if(ToFTrk){ //ELENA
1517          l2->ntoftrk = ToFTrk->GetEntries();
1518          for(Int_t j=0;j<l2->ntoftrk;j++){
1519              l2->toftrkseqno[j]= ((ToFTrkVar*)ToFTrk->At(j))->trkseqno;
1520              l2->npmttdc[j]= ((ToFTrkVar*)ToFTrk->At(j))->npmttdc;
1521              for(Int_t i=0;i<l2->npmttdc[j];i++){
1522                  l2->pmttdc[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->pmttdc.At(i);
1523                  l2->tdcflag[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->tdcflag.At(i); // gf: 30 Nov 2006
1524              }
1525              for(Int_t i=0;i<13;i++)
1526                  l2->beta[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->beta[i];
1527              
1528              l2->npmtadc[j]= ((ToFTrkVar*)ToFTrk->At(j))->npmtadc;
1529              for(Int_t i=0;i<l2->npmtadc[j];i++){
1530                  l2->pmtadc[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->pmtadc.At(i);
1531                  l2->adcflag[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->adcflag.At(i); // gf: 30 Nov 2006
1532                  l2->dedx[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->dedx.At(i);
1533              }
1534              for(Int_t i=0;i<3;i++){
1535                  l2->xtofpos[i][j]=((ToFTrkVar*)ToFTrk->At(j))->xtofpos[i];
1536                  l2->ytofpos[i][j]=((ToFTrkVar*)ToFTrk->At(j))->ytofpos[i];
1537              }
1538              for(Int_t i=0;i<6;i++){
1539                  l2->xtr_tof[i][j]=((ToFTrkVar*)ToFTrk->At(j))->xtr_tof[i];
1540                  l2->ytr_tof[i][j]=((ToFTrkVar*)ToFTrk->At(j))->ytr_tof[i];
1541              }
1542          }
1543      } //ELENA
1544        
1545      if(PMT){ //ELENA
1546          l2->npmt = PMT->GetEntries();
1547          for(Int_t j=0;j<l2->npmt;j++){
1548              l2->pmt_id[j] = ((ToFPMT*)PMT->At(j))->pmt_id;
1549              l2->adc[j] =((ToFPMT*)PMT->At(j))->adc;
1550              l2->tdc_tw[j] =((ToFPMT*)PMT->At(j))->tdc_tw;
1551          }
1552      } //ELENA
1553    }
1554    
1555    
1556    //
1557    // Reprocessing tool // Emiliano 08/04/07
1558    //
1559    Int_t ToFLevel2::Process(TrkLevel2 *trk, TrigLevel2 *trg, GL_RUN *run, OrbitalInfo *orb, Bool_t force){
1560      //
1561      // Copiare qui qualcosa di simile a calonuclei per evitare di riprocessare sempre tutto
1562      //
1563      printf("\n\n\n ERROR: NOT IMPLEMENTED ANYMORE, write Emiliano if you need this method (Emiliano.Mocchiutti@ts.infn.it) \n\n\n");
1564      return(-1);
1565      //   //
1566      //   // structures to communicate with F77
1567      //   //
1568      //   extern struct ToFInput  tofinput_;
1569    //   extern struct ToFOutput tofoutput_;
1570    //   //
1571    //   // DB connection
1572    //   //
1573    //   TString host;
1574    //   TString user;
1575    //   TString psw;
1576    //   const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
1577    //   const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
1578    //   const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
1579    //   if ( !pamdbhost ) pamdbhost = "";
1580    //   if ( !pamdbuser ) pamdbuser = "";
1581    //   if ( !pamdbpsw ) pamdbpsw = "";
1582    //   if ( strcmp(pamdbhost,"") ) host = pamdbhost;
1583    //   if ( strcmp(pamdbuser,"") ) user = pamdbuser;
1584    //   if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
1585    //   //
1586    //   //
1587    //   TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
1588    //   if ( !dbc->IsConnected() ) return 1;
1589    //   stringstream myquery;
1590    //   myquery.str("");
1591    //   myquery << "SET time_zone='+0:00';";
1592    //   dbc->Query(myquery.str().c_str());
1593    //   delete dbc->Query("SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';");
1594    //   GL_PARAM *glparam = new GL_PARAM();
1595    //   glparam->Query_GL_PARAM(1,1,dbc); // parameters stored in DB in GL_PRAM table
1596    //   trk->LoadField(glparam->PATH+glparam->NAME);
1597    //   //
1598    //   Bool_t defcal = true;
1599    //   Int_t error=glparam->Query_GL_PARAM(run->RUNHEADER_TIME,201,dbc); // parameters stored in DB in GL_PRAM table
1600    //   if ( error<0 ) {
1601    //     return(1);
1602    //   };
1603    //   printf(" Reading ToF parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());
1604    //   if ( (UInt_t)glparam->TO_TIME != (UInt_t)4294967295UL ) defcal = false;
1605    //   //
1606    //   Int_t nlen = (Int_t)(glparam->PATH+glparam->NAME).Length();
1607    //   rdtofcal((char *)(glparam->PATH+glparam->NAME).Data(),&nlen);
1608    //   //
1609    //   Int_t adc[4][12];
1610    //   Int_t tdc[4][12];
1611    //   Float_t tdcc[4][12];
1612    //   //
1613    //   // process tof data
1614    //   //
1615    //   for (Int_t hh=0; hh<12;hh++){
1616    //     for (Int_t kk=0; kk<4;kk++){
1617    //            adc[kk][hh] = 4095;
1618    //            tdc[kk][hh] = 4095;
1619    //            tdcc[kk][hh] = 4095.;
1620    //            tofinput_.adc[hh][kk] = 4095;
1621    //            tofinput_.tdc[hh][kk] = 4095;
1622    //     };
1623    //   };
1624    //   Int_t ntrkentry = 0;
1625    //   Int_t npmtentry = 0;
1626    //   Int_t gg = 0;
1627    //   Int_t hh = 0;
1628    //   Int_t adcf[48];
1629    //   memset(adcf, 0, 48*sizeof(Int_t));
1630    //   Int_t tdcf[48];
1631    //   memset(tdcf, 0, 48*sizeof(Int_t));
1632    //   for (Int_t pm=0; pm < this->ntrk() ; pm++){
1633    //      ToFTrkVar *ttf = this->GetToFTrkVar(pm);
1634    //      for ( Int_t nc=0; nc < ttf->npmttdc; nc++){
1635    //             if ( (ttf->tdcflag).At(nc) != 0 ) tdcf[(ttf->pmttdc).At(nc)] = 1;
1636    //      };
1637    //      for ( Int_t nc=0; nc < ttf->npmtadc; nc++){
1638    //             if ( (ttf->adcflag).At(nc) != 0 ) adcf[(ttf->pmtadc).At(nc)] = 1;
1639    //      };
1640    //   };
1641    //   //
1642    //   for (Int_t pm=0; pm < this->npmt() ; pm++){
1643    //      ToFPMT *pmt = this->GetToFPMT(pm);
1644    //      this->GetPMTIndex(pmt->pmt_id, gg, hh);
1645    //      if ( adcf[pmt->pmt_id] == 0 ){
1646    //              tofinput_.adc[gg][hh] = (int)pmt->adc;
1647    //              adc[hh][gg] = (int)pmt->adc;
1648    //      };
1649    //      if ( tdcf[pmt->pmt_id] == 0 ){
1650    //              tofinput_.tdc[gg][hh] = (int)pmt->tdc;
1651    //              tdc[hh][gg] = (int)pmt->tdc;
1652    //      };
1653    //      tdcc[hh][gg] = (float)pmt->tdc_tw;
1654    //      // Int_t pppid = this->GetPMTid(hh,gg);
1655    //      //      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);
1656    //   };
1657    //   //
1658    //   Int_t unpackError = this->unpackError;
1659    //   //
1660    //   for (Int_t hh=0; hh<5;hh++){
1661    //      tofinput_.patterntrig[hh]=trg->patterntrig[hh];
1662    //   };
1663    //   //
1664    //   this->Clear();
1665    //   //
1666    //       Int_t pmt_id = 0;
1667    //       ToFPMT *t_pmt = new ToFPMT();
1668    //       if(!(this->PMT)) this->PMT = new TClonesArray("ToFPMT",12); //ELENA
1669    //       TClonesArray &tpmt = *this->PMT;
1670    //       ToFTrkVar *t_tof = new ToFTrkVar();
1671    //       if(!(this->ToFTrk)) this->ToFTrk = new TClonesArray("ToFTrkVar",2); //ELENA
1672    //       TClonesArray &t = *this->ToFTrk;
1673    //       //
1674    //       //
1675    //       // Here we have calibrated data, ready to be passed to the FORTRAN routine which will extract common and track-related  variables.
1676    //       //
1677    //       npmtentry = 0;
1678    //       //
1679    //       ntrkentry = 0;
1680    //       //
1681    //       // Calculate tracks informations from ToF alone
1682    //       //
1683    //       tofl2com();
1684    //       //
1685    //       memcpy(this->tof_j_flag,tofoutput_.tof_j_flag,6*sizeof(Int_t));
1686    //       //
1687    //       t_tof->trkseqno = -1;
1688    //       //
1689    //       // and now we must copy from the output structure to the level2 class:
1690    //       //
1691    //       t_tof->npmttdc = 0;
1692    //       //
1693    //       for (Int_t hh=0; hh<12;hh++){
1694    //         for (Int_t kk=0; kk<4;kk++){
1695    //           if ( tofoutput_.tofmask[hh][kk] != 0 ){
1696    //             pmt_id = this->GetPMTid(kk,hh);
1697    //             t_tof->pmttdc.AddAt(pmt_id,t_tof->npmttdc);
1698    //             t_tof->tdcflag.AddAt(tofoutput_.tdcflagtof[hh][kk],t_tof->npmttdc); // gf: Jan 09/07
1699    //             t_tof->npmttdc++;
1700    //           };
1701    //         };
1702    //       };
1703    //       for (Int_t kk=0; kk<13;kk++){
1704    //         t_tof->beta[kk] = tofoutput_.betatof_a[kk];
1705    //       }
1706    //       //
1707    //       t_tof->npmtadc = 0;
1708    //       for (Int_t hh=0; hh<12;hh++){
1709    //         for (Int_t kk=0; kk<4;kk++){
1710    //           if ( tofoutput_.adctof_c[hh][kk] < 1000 ){
1711    //             t_tof->dedx.AddAt(tofoutput_.adctof_c[hh][kk],t_tof->npmtadc);
1712    //             pmt_id = this->GetPMTid(kk,hh);
1713    //             t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc);
1714    //             t_tof->adcflag.AddAt(tofoutput_.adcflagtof[hh][kk],t_tof->npmtadc); // gf: Jan 09/07
1715    //             t_tof->npmtadc++;
1716    //           };
1717    //         };
1718    //       };
1719    //       //
1720    //       memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos));
1721    //       memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos));
1722    //       memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof));
1723    //       memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof));
1724    //       //
1725    //       new(t[ntrkentry]) ToFTrkVar(*t_tof);
1726    //       ntrkentry++;
1727    //       t_tof->Clear();
1728    //       //
1729    //       //
1730    //       //
1731    //       t_pmt->Clear();
1732    //       //
1733    //       for (Int_t hh=0; hh<12;hh++){
1734    //         for (Int_t kk=0; kk<4;kk++){
1735    //          // new WM
1736    //           if ( tofoutput_.tdc_c[hh][kk] < 4095 || adc[kk][hh] < 4095  || tdc[kk][hh] < 4095 ){
1737    // //          if ( tdcc[kk][hh] < 4095. || adc[kk][hh] < 4095  || tdc[kk][hh] < 4095 ){
1738    //             //
1739    //             t_pmt->pmt_id = this->GetPMTid(kk,hh);
1740    //             t_pmt->tdc_tw = tofoutput_.tdc_c[hh][kk];
1741    //             t_pmt->adc = (Float_t)adc[kk][hh];
1742    //             t_pmt->tdc = (Float_t)tdc[kk][hh];
1743    //             //
1744    //             new(tpmt[npmtentry]) ToFPMT(*t_pmt);
1745    //             npmtentry++;
1746    //             t_pmt->Clear();
1747    //           };
1748    //         };
1749    //       };
1750    //       //
1751    //       // Calculate track-related variables
1752    //       //
1753    //       if ( trk->ntrk() > 0 ){
1754    //         //
1755    //         // We have at least one track
1756    //         //
1757    //         //
1758    //         // Run over tracks
1759    //         //
1760    //         for(Int_t nt=0; nt < trk->ntrk(); nt++){
1761    //           //
1762    //           TrkTrack *ptt = trk->GetStoredTrack(nt);
1763    //           //
1764    //           // Copy the alpha vector in the input structure
1765    //           //
1766    //           for (Int_t e = 0; e < 5 ; e++){
1767    //             tofinput_.al_pp[e] = ptt->al[e];
1768    //           };
1769    //           //
1770    //           // Get tracker related variables for this track
1771    //           //
1772    //           toftrk();
1773    //           //
1774    //           // Copy values in the class from the structure (we need to use a temporary class to store variables).
1775    //           //
1776    //           t_tof->npmttdc = 0;
1777    //           for (Int_t hh=0; hh<12;hh++){
1778    //             for (Int_t kk=0; kk<4;kk++){
1779    //               if ( tofoutput_.tofmask[hh][kk] != 0 ){
1780    //                 pmt_id = this->GetPMTid(kk,hh);
1781    //                 t_tof->pmttdc.AddAt(pmt_id,t_tof->npmttdc);
1782    //                 t_tof->tdcflag.AddAt(tofoutput_.tdcflag[hh][kk],t_tof->npmttdc); // gf: Jan 09/07
1783    //                 t_tof->npmttdc++;
1784    //               };
1785    //             };
1786    //           };
1787    //           for (Int_t kk=0; kk<13;kk++){
1788    //             t_tof->beta[kk] = tofoutput_.beta_a[kk];
1789    //           };
1790    //           //
1791    //           t_tof->npmtadc = 0;
1792    //           for (Int_t hh=0; hh<12;hh++){
1793    //             for (Int_t kk=0; kk<4;kk++){
1794    //               if ( tofoutput_.adc_c[hh][kk] < 1000 ){
1795    //                 t_tof->dedx.AddAt(tofoutput_.adc_c[hh][kk],t_tof->npmtadc);
1796    //                 pmt_id = this->GetPMTid(kk,hh);
1797    //                 t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc);
1798    //                 t_tof->adcflag.AddAt(tofoutput_.adcflag[hh][kk],t_tof->npmtadc); // gf: Jan 09/07
1799    //                 t_tof->npmtadc++;
1800    //               };
1801    //             };
1802    //           };
1803    //           //
1804    //           memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos));
1805    //           memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos));
1806    //           memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof));
1807    //           memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof));
1808    //           //
1809    //           // Store the tracker track number in order to be sure to have shyncronized data during analysis
1810    //           //
1811    //           t_tof->trkseqno = nt;
1812    //           //
1813    //           // create a new object for this event with track-related variables
1814    //           //
1815    //           new(t[ntrkentry]) ToFTrkVar(*t_tof);
1816    //           ntrkentry++;
1817    //           t_tof->Clear();
1818    //           //
1819    //         }; // loop on all the tracks
1820    //       //
1821    //       this->unpackError = unpackError;
1822    //       if ( defcal ){
1823    //         this->default_calib = 1;
1824    //       } else {
1825    //         this->default_calib = 0;
1826    //       };
1827    //};
1828    //  return(0);
1829    }
1830    
1831    bool ToFLevel2::bit(int decimal, char pos){
1832      return( (decimal>>pos)%2 );
1833    }
1834    
1835    bool ToFLevel2::checkPMT(TString givenpmt){
1836      TClonesArray* Pmt = this->PMT;
1837      //  printf(" ou %s entries %i \n",givenpmt.Data(),Pmt->GetEntries());
1838      for(int i=0; i<Pmt->GetEntries(); i++) {  
1839        ToFPMT* pmthit = (ToFPMT*)Pmt->At(i);
1840        TString pmtname = this->GetPMTName(pmthit->pmt_id);
1841        //    printf(" name %s \n",pmtname.Data());
1842        if ( !strcmp(pmtname.Data(),givenpmt.Data()) )
1843          return true;
1844      }
1845      //  printf(" PMT %s missing \n",givenpmt.Data());
1846      return false;
1847    }
1848    
1849    bool ToFLevel2::checkPMTpatternPMThit(TrigLevel2 *trg, int &pmtpattern, int &pmtnosignal){
1850      UInt_t *patterntrig = trg->patterntrig;
1851      pmtpattern = 0;
1852      pmtnosignal = 0;
1853      bool good = true;
1854      //S3
1855      if ( this->bit(patterntrig[2],0) ){ pmtpattern++;  if ( !this->checkPMT("S31_1A")){ pmtnosignal++; good = false;}}
1856      if ( this->bit(patterntrig[2],1) ){ pmtpattern++;  if ( !this->checkPMT("S31_2A")){ pmtnosignal++; good = false;}}
1857      if ( this->bit(patterntrig[2],2) ){ pmtpattern++;  if ( !this->checkPMT("S31_3A")){ pmtnosignal++; good = false;}}
1858      if ( this->bit(patterntrig[2],3) ){ pmtpattern++;  if ( !this->checkPMT("S31_1B")){ pmtnosignal++; good = false;}}
1859      if ( this->bit(patterntrig[2],4) ){ pmtpattern++;  if ( !this->checkPMT("S31_2B")){ pmtnosignal++; good = false;}}
1860      if ( this->bit(patterntrig[2],5) ){ pmtpattern++;  if ( !this->checkPMT("S31_3B")){ pmtnosignal++; good = false;}}      
1861      if ( this->bit(patterntrig[2],6) ){ pmtpattern++;  if ( !this->checkPMT("S32_1A")){ pmtnosignal++; good = false;}}
1862      if ( this->bit(patterntrig[2],7) ){ pmtpattern++;  if ( !this->checkPMT("S32_2A")){ pmtnosignal++; good = false;}}
1863      if ( this->bit(patterntrig[2],8) ){ pmtpattern++;  if ( !this->checkPMT("S32_3A")){ pmtnosignal++; good = false;}}
1864      if ( this->bit(patterntrig[2],9) ){ pmtpattern++;  if ( !this->checkPMT("S32_1B")){ pmtnosignal++; good = false;}}
1865      if ( this->bit(patterntrig[2],10) ){ pmtpattern++;  if ( !this->checkPMT("S32_2B")){ pmtnosignal++; good = false;}}
1866      if ( this->bit(patterntrig[2],11) ){ pmtpattern++;  if ( !this->checkPMT("S32_3B")){ pmtnosignal++; good = false;}}      
1867      //S2
1868      if ( this->bit(patterntrig[3],0) ){ pmtpattern++;  if ( !this->checkPMT("S21_1A")){ pmtnosignal++; good = false;}}
1869      if ( this->bit(patterntrig[3],1) ){ pmtpattern++;  if ( !this->checkPMT("S21_2A")){ pmtnosignal++; good = false;}}
1870      if ( this->bit(patterntrig[3],2) ){ pmtpattern++;  if ( !this->checkPMT("S21_1B")){ pmtnosignal++; good = false;}}
1871      if ( this->bit(patterntrig[3],3) ){ pmtpattern++;  if ( !this->checkPMT("S21_2B")){ pmtnosignal++; good = false;}}      
1872      if ( this->bit(patterntrig[3],4) ){ pmtpattern++;  if ( !this->checkPMT("S22_1A")){ pmtnosignal++; good = false;}}
1873      if ( this->bit(patterntrig[3],5) ){ pmtpattern++;  if ( !this->checkPMT("S22_2A")){ pmtnosignal++; good = false;}}
1874      if ( this->bit(patterntrig[3],6) ){ pmtpattern++;  if ( !this->checkPMT("S22_1B")){ pmtnosignal++; good = false;}}
1875      if ( this->bit(patterntrig[3],7) ){ pmtpattern++;  if ( !this->checkPMT("S22_2B")){ pmtnosignal++; good = false;}}      
1876      //S12
1877      if ( this->bit(patterntrig[4],0) ){ pmtpattern++;  if ( !this->checkPMT("S12_1A")){ pmtnosignal++; good = false;}}
1878      if ( this->bit(patterntrig[4],1) ){ pmtpattern++;  if ( !this->checkPMT("S12_2A")){ pmtnosignal++; good = false;}}
1879      if ( this->bit(patterntrig[4],2) ){ pmtpattern++;  if ( !this->checkPMT("S12_3A")){ pmtnosignal++; good = false;}}
1880      if ( this->bit(patterntrig[4],3) ){ pmtpattern++;  if ( !this->checkPMT("S12_4A")){ pmtnosignal++; good = false;}}
1881      if ( this->bit(patterntrig[4],4) ){ pmtpattern++;  if ( !this->checkPMT("S12_5A")){ pmtnosignal++; good = false;}}
1882      if ( this->bit(patterntrig[4],5) ){ pmtpattern++;  if ( !this->checkPMT("S12_6A")){ pmtnosignal++; good = false;}}      
1883      if ( this->bit(patterntrig[4],6) ){ pmtpattern++;  if ( !this->checkPMT("S12_1A")){ pmtnosignal++; good = false;}}
1884      if ( this->bit(patterntrig[4],7) ){ pmtpattern++;  if ( !this->checkPMT("S12_2A")){ pmtnosignal++; good = false;}}
1885      if ( this->bit(patterntrig[4],8) ){ pmtpattern++;  if ( !this->checkPMT("S12_3A")){ pmtnosignal++; good = false;}}
1886      if ( this->bit(patterntrig[4],9) ){ pmtpattern++;  if ( !this->checkPMT("S12_4B")){ pmtnosignal++; good = false;}}
1887      if ( this->bit(patterntrig[4],10) ){ pmtpattern++; if ( !this->checkPMT("S12_5B")){ pmtnosignal++; good = false;}}
1888      if ( this->bit(patterntrig[4],11) ){ pmtpattern++; if ( !this->checkPMT("S12_6B")){ pmtnosignal++; good = false;}}      
1889      //S11
1890      if ( this->bit(patterntrig[5],0) ){ pmtpattern++;  if ( !this->checkPMT("S11_1A")){ pmtnosignal++; good = false;}}
1891      if ( this->bit(patterntrig[5],1) ){ pmtpattern++;  if ( !this->checkPMT("S11_2A")){ pmtnosignal++; good = false;}}
1892      if ( this->bit(patterntrig[5],2) ){ pmtpattern++;  if ( !this->checkPMT("S11_3A")){ pmtnosignal++; good = false;}}
1893      if ( this->bit(patterntrig[5],3) ){ pmtpattern++;  if ( !this->checkPMT("S11_4A")){ pmtnosignal++; good = false;}}
1894      if ( this->bit(patterntrig[5],4) ){ pmtpattern++;  if ( !this->checkPMT("S11_5A")){ pmtnosignal++; good = false;}}
1895      if ( this->bit(patterntrig[5],5) ){ pmtpattern++;  if ( !this->checkPMT("S11_6A")){ pmtnosignal++; good = false;}}
1896      if ( this->bit(patterntrig[5],6) ){ pmtpattern++;  if ( !this->checkPMT("S11_7A")){ pmtnosignal++; good = false;}}
1897      if ( this->bit(patterntrig[5],7) ){ pmtpattern++;  if ( !this->checkPMT("S11_8A")){ pmtnosignal++; good = false;}}      
1898      if ( this->bit(patterntrig[5],8) ){ pmtpattern++;  if ( !this->checkPMT("S11_1B")){ pmtnosignal++; good = false;}}
1899      if ( this->bit(patterntrig[5],9) ){ pmtpattern++;  if ( !this->checkPMT("S11_2B")){ pmtnosignal++; good = false;}}
1900      if ( this->bit(patterntrig[5],10) ){ pmtpattern++; if ( !this->checkPMT("S11_3B")){ pmtnosignal++; good = false;}}
1901      if ( this->bit(patterntrig[5],11) ){ pmtpattern++; if ( !this->checkPMT("S11_4B")){ pmtnosignal++; good = false;}}
1902      if ( this->bit(patterntrig[5],12) ){ pmtpattern++; if ( !this->checkPMT("S11_5B")){ pmtnosignal++; good = false;}}
1903      if ( this->bit(patterntrig[5],13) ){ pmtpattern++; if ( !this->checkPMT("S11_6B")){ pmtnosignal++; good = false;}}
1904      if ( this->bit(patterntrig[5],14) ){ pmtpattern++; if ( !this->checkPMT("S11_7B")){ pmtnosignal++; good = false;}}
1905      if ( this->bit(patterntrig[5],15) ){ pmtpattern++; if ( !this->checkPMT("S11_8B")){ pmtnosignal++; good = false;}}
1906    
1907      return good;
1908    }
1909    
1910    bool ToFLevel2::checkPMTpmttrig(TrigLevel2 *trg){
1911      //  UInt_t *patterntrig = trg->patterntrig;
1912      int rS11 = 0;
1913      int rS12 = 0;
1914      int rS21 = 0;
1915      int rS22 = 0;
1916      int rS31 = 0;
1917      int rS32 = 0;
1918    
1919      // trigger configuration for the event from saved pmts
1920      TClonesArray* Pmt = this->PMT;
1921      for(int i=0; i<Pmt->GetEntries(); i++) {  
1922        ToFPMT* pmthit = (ToFPMT*)Pmt->At(i);
1923        TString pmtname = this->GetPMTName(pmthit->pmt_id);
1924        if ( pmtname.Contains("S11") ) rS11++;
1925        if ( pmtname.Contains("S12") ) rS12++;
1926        if ( pmtname.Contains("S21") ) rS21++;
1927        if ( pmtname.Contains("S22") ) rS22++;
1928        if ( pmtname.Contains("S31") ) rS31++;
1929        if ( pmtname.Contains("S32") ) rS32++;
1930      }
1931      int rTOF1 = (rS11 + rS12) * (rS21 + rS22) * (rS31 + rS32);
1932      int rTOF2 = (rS11 * rS12) * (rS21 * rS22) * (rS31 * rS32);
1933    
1934      int rTOF3 = (rS21 + rS22) * (rS31 + rS32);
1935      int rTOF4 = (rS21 * rS22) * (rS31 * rS32);
1936    
1937      int rTOF5 = rS12 * (rS21 * rS22);
1938    
1939      int rTOF6 = (rS11 + rS12) * (rS31 + rS32);
1940      int rTOF7 = (rS11 * rS12) * (rS31 * rS32);
1941    
1942    
1943      // trigger configuration of the run
1944      bool TCTOF1 = false;
1945      bool TCTOF2 = false;
1946      bool TCTOF3 = false;
1947      bool TCTOF4 = false;
1948      bool TCTOF5 = false;
1949      bool TCTOF6 = false;
1950      bool TCTOF7 = false;
1951      if ( trg->trigconf & (1<<0) ) TCTOF1 = true;
1952      if ( trg->trigconf & (1<<1) ) TCTOF2 = true;
1953      if ( trg->trigconf & (1<<2) ) TCTOF3 = true;
1954      if ( trg->trigconf & (1<<3) ) TCTOF4 = true;
1955      if ( trg->trigconf & (1<<4) ) TCTOF5 = true;
1956      if ( trg->trigconf & (1<<5) ) TCTOF6 = true;
1957      if ( trg->trigconf & (1<<6) ) TCTOF7 = true;
1958    
1959      // do patterntrig pmts match the trigger configuration?
1960      bool pmtsconf_trigconf_match = true;
1961      if ( rTOF1 == 0 && TCTOF1 ) pmtsconf_trigconf_match = false;
1962      if ( rTOF2 == 0 && TCTOF2 ) pmtsconf_trigconf_match = false;
1963      if ( rTOF3 == 0 && TCTOF3 ) pmtsconf_trigconf_match = false;
1964      if ( rTOF4 == 0 && TCTOF4 ) pmtsconf_trigconf_match = false;
1965      if ( rTOF5 == 0 && TCTOF5 ) pmtsconf_trigconf_match = false;
1966      if ( rTOF6 == 0 && TCTOF6 ) pmtsconf_trigconf_match = false;
1967      if ( rTOF7 == 0 && TCTOF7 ) pmtsconf_trigconf_match = false;
1968    
1969      return pmtsconf_trigconf_match;
1970    }
1971    
1972    void ToFLevel2::printPMT(){
1973      TClonesArray* Pmt = this->PMT;
1974      for(int i=0; i<Pmt->GetEntries(); i++) {  
1975        ToFPMT* pmthit = (ToFPMT*)Pmt->At(i);
1976        TString pmtname = this->GetPMTName(pmthit->pmt_id);
1977        printf(" PMT hit: %s \n",pmtname.Data());
1978      }
1979    }
1980    
1981    
1982    ToFdEdx::ToFdEdx()
1983    {
1984      memset(conn,0,12*sizeof(Bool_t));
1985      memset(ts,0,12*sizeof(UInt_t));
1986      memset(te,0,12*sizeof(UInt_t));
1987      eDEDXpmt = new TArrayF(48);
1988      Define_PMTsat();
1989      Clear();
1990    }
1991    
1992    ToFdEdx::~ToFdEdx(){
1993      Clear();
1994      Delete();
1995    }
1996    
1997    void ToFdEdx::Delete(Option_t *option){
1998      if ( eDEDXpmt ){
1999        eDEDXpmt->Set(0);
2000        if ( eDEDXpmt) delete eDEDXpmt;
2001      }
2002    }
2003    
2004    //------------------------------------------------------------------------
2005    void ToFdEdx::CheckConnectors(UInt_t atime, GL_PARAM *glparam, TSQLServer *dbc)
2006    {
2007      for(int i=0; i<12; i++){
2008        if(atime<=ts[i] || atime>te[i]){
2009          Int_t error=glparam->Query_GL_PARAM(atime,210+i,dbc); // parameters stored in DB in GL_PRAM table
2010          if ( error<0 ) {
2011            conn[i]=false;
2012            ts[i]=0;
2013            te[i]=numeric_limits<UInt_t>::max();
2014          };
2015          if ( !error ){
2016            conn[i]=true;
2017            ts[i]=glparam->FROM_TIME;
2018            te[i]=glparam->TO_TIME;
2019          }
2020          if ( error>0 ){
2021            conn[i]=false;
2022            ts[i]=glparam->TO_TIME;
2023            TSQLResult *pResult;
2024            TSQLRow *row;
2025            TString query= Form("SELECT FROM_TIME FROM GL_PARAM WHERE TYPE=%i AND FROM_TIME>=%i ORDER BY FROM_TIME ASC LIMIT 1;",210+i,atime);
2026            pResult=dbc->Query(query.Data());
2027            if(!pResult->GetRowCount()){
2028              te[i]=numeric_limits<UInt_t>::max();
2029            }else{
2030              row=pResult->Next();
2031              te[i]=(UInt_t)atoll(row->GetField(0));
2032            }
2033          }
2034          //
2035          
2036        }
2037      }
2038    
2039    }
2040    //------------------------------------------------------------------------
2041    void ToFdEdx::Clear(Option_t *option)
2042    {
2043      //
2044      // Set arrays and initialize structure
2045      //  eDEDXpmt.Set(48);    eDEDXpmt.Reset(-1);   // Set array size  and reset structure
2046      eDEDXpmt->Set(48);    eDEDXpmt->Reset(-1);   // Set array size  and reset structure
2047      //
2048    };
2049    
2050    //------------------------------------------------------------------------
2051    void ToFdEdx::Print(Option_t *option)
2052    {
2053      //
2054      printf("========================================================================\n");
2055    
2056    };
2057    
2058    //------------------------------------------------------------------------
2059    void ToFdEdx::Init(pamela::tof::TofEvent *tofl0)
2060    {
2061      //
2062      ToFLevel2 tf;
2063      for (Int_t gg=0; gg<4;gg++){
2064        for (Int_t hh=0; hh<12;hh++){
2065          //          tofinput_.tdc[hh][gg]=tofEvent->tdc[gg][hh];          
2066          int mm = tf.GetPMTid(gg,hh);        
2067          adc[mm]= (0xFFF & tofl0->adc[gg][hh]); // EM, exclude warning bits
2068        };      
2069      };
2070      
2071    };
2072    
2073    //------------------------------------------------------------------------
2074    void ToFdEdx::Init(Int_t gg, Int_t hh, Float_t adce)
2075    {
2076      //
2077      ToFLevel2 tf;
2078      //  for (Int_t gg=0; gg<4;gg++){
2079      //    for (Int_t hh=0; hh<12;hh++){
2080      int mm = tf.GetPMTid(gg,hh);    
2081      adc[mm]=adce;
2082      
2083    };
2084    //------------------------------------------------------------------------
2085    void ToFdEdx::Process(UInt_t atime, Float_t betamean, Float_t *xtr_tof, Float_t *ytr_tof, Int_t exitat)
2086    {
2087      bool debug = false;
2088      if ( debug ) printf(" INSIDE TOFDEDX PROCESS \n");
2089      // the parameters should be already initialised by InitPar()
2090      //  printf(" in process \n");
2091      Clear();
2092    
2093     // define angle:  
2094      double dx   = xtr_tof[1] - xtr_tof[5];
2095      double dy   = ytr_tof[0] - ytr_tof[4];
2096      double dr   = sqrt(dx*dx+dy*dy);
2097      double theta=atan(dr/76.81);
2098      //
2099      if ( xtr_tof[1] > 99. ||  xtr_tof[5] > 99. || ytr_tof[0] > 99. ||  ytr_tof[4] > 99. ) theta = 0.;
2100      for (Int_t ii=0; ii<6; ii++){
2101        if ( xtr_tof[ii] > 99. ) xtr_tof[ii] = 0.;
2102        if ( ytr_tof[ii] > 99. ) ytr_tof[ii] = 0.;
2103      };
2104      //
2105      if ( debug ) printf(" theta %f \n",theta);
2106      if ( debug ) printf(" xtr_tof %.1f %.1f %.1f %.1f %.1f %.1f \n",xtr_tof[0],xtr_tof[1],xtr_tof[2],xtr_tof[3],xtr_tof[4],xtr_tof[5]);
2107      if ( debug ) printf(" ytr_tof %.1f %.1f %.1f %.1f %.1f %.1f \n",ytr_tof[0],ytr_tof[1],ytr_tof[2],ytr_tof[3],ytr_tof[4],ytr_tof[5]);
2108      //--------------------- TABLE OF PERIODS WITH HV PROBLEMS ----------------------------
2109      
2110      int Aconn=conn[0];    // PMT 0,20,22,24
2111      int Bconn=conn[1];    // PMT 6,12,26,34
2112      int Cconn=conn[2];    // PMT 4,14,28,32
2113      int Dconn=conn[3];    // PMT 2,8,10,30
2114      int Econn=conn[4];    // PMT 42,43,44,47
2115      int Fconn=conn[5];    // PMT 7,19,23,27
2116      int Gconn=conn[6];    // PMT 3,11,25,33
2117      int Hconn=conn[7];    // PMT 1,9,13,21
2118      int Iconn=conn[8];    // PMT 5,29,31,35
2119      int Lconn=conn[9];    // PMT 37,40,45,46
2120      int Mconn=conn[10];    // PMT 15,16,17,18
2121      int Nconn=conn[11];    // PMT 36,38,39,41
2122      if( false ) cout << Gconn << Iconn << Lconn <<endl; // to avoid compilation warnings
2123        
2124      //  printf(" size %i \n",eDEDXpmt.GetSize());
2125      for( int ii=0; ii<48; ii++ ) {
2126        //
2127        //    eDEDXpmt.SetAt(-1.,ii);
2128        //    printf(" ii %i beta %f atime %u xtr 1 %f ytr 1 %f adc %f \n",ii,betamean,atime,xtr_tof[0],ytr_tof[0],adc[ii]);
2129        if ( debug ) printf("II %i adc %f \n",ii,adc[ii]);
2130    
2131        if( adc[ii] >= 4095. ){
2132          //      eDEDXpmt[ii] = 0.;
2133          eDEDXpmt->AddAt(0.,ii);
2134          if ( debug ) printf(" %i adc>4095 \n",ii);
2135          continue; // EMILIANO
2136        };
2137    
2138        if( adc[ii] >= (PMTsat[ii]-5.) && adc[ii] < 4095. ){
2139          eDEDXpmt->AddAt(1000.,ii);
2140          if ( debug ) printf(" %i adc> pmtsat && adc<4095 \n",ii);
2141          continue; // EMILIANO
2142        };
2143    
2144        if( adc[ii] <= 0. ) {
2145          eDEDXpmt->AddAt(1500.,ii);
2146          if ( debug ) printf(" %i adc<=0 \n",ii);
2147          continue;
2148        };
2149        //
2150        double adcpC   = f_adcPC( adc[ii] );    // - adc conversion in pC
2151        if ( exitat == 0 ){
2152          eDEDXpmt->AddAt((Float_t)adcpC,ii);
2153          continue;
2154        }
2155        //    printf(" e qua? \n");
2156    
2157        double adccorr = adcpC*fabs(cos(theta));    
2158        if ( debug ) printf(" adccorr %f \n",adccorr);
2159        if(adccorr<=0.){
2160          if ( debug ) printf(" %i adccorr<=0 \n",ii);
2161          //      eDEDXpmt->AddAt((Float_t)adcpC,ii);//?
2162          continue;
2163        }
2164        if ( exitat == 1 ){
2165          eDEDXpmt->AddAt((Float_t)adccorr,ii);
2166          continue;
2167        }
2168        //    printf(" e quo? \n");
2169    
2170        //    int standard=0;
2171        int S115B_ok=0;
2172        int S115B_break=0;
2173    
2174        if(atime<1158720000)S115B_ok=1;
2175        else S115B_break=1;
2176    
2177    
2178        //------------------------------------------------------------------------
2179        //    printf(" e qui? \n");
2180        //---------------------------------------------------- Z reconstruction
2181    
2182        double adcHe, adcnorm, adclin, dEdx;//, Zeta; // EM GCC4.7
2183    
2184        adcHe=-2;
2185        adcnorm=-2;
2186        adclin=-2;
2187        dEdx=-2;
2188        //    Zeta=-2;//EM GCC4.7
2189        Double_t correction = 1.;
2190    
2191        if(Aconn==1 && (ii==0 || ii==20 || ii==22 || ii==24)){
2192          correction = 1.675;
2193        }
2194        else if(Bconn==1 && (ii==6 || ii==12 || ii==26 || ii==34)){
2195          correction = 2.482;
2196        }
2197        else if(Cconn==1 && (ii==4 || ii==14 || ii==28 || ii==32)){
2198          correction = 1.464;
2199        }
2200        else if(Dconn==1 && (ii==2 || ii==8 || ii==10 || ii==30)){
2201          correction = 1.995;
2202        }
2203        else if(Econn==1 && (ii==42 || ii==43 || ii==44 || ii==47)){
2204          correction = 1.273;
2205        }
2206        else if(Fconn==1 && (ii==7 || ii==19 || ii==23 || ii==27)){
2207          correction = 1.565;
2208        }
2209        else if(Mconn==1 && (ii==15 || ii==16 || ii==17 || ii==18)){
2210          correction = 1.565;
2211        }
2212        else if(Nconn==1 && (ii==36 || ii==38 || ii==39 || ii==41)){
2213          correction = 1.018;
2214        }
2215        else if(Hconn==1 && (ii==1 || ii==13 || ii==21 || (ii==9&&S115B_ok==1))){
2216          correction = 1.84;
2217        }
2218        else if(S115B_break==1 && ii==9 && Hconn==1){
2219          correction = 1.64;
2220        }
2221        else correction = 1.;
2222        
2223        if( ii==9 && S115B_break==1 ){
2224          adcHe   = f_att5B( ytr_tof[0] )/correction;
2225        } else {
2226          adcHe   = Get_adc_he(ii, xtr_tof, ytr_tof)/correction;
2227        };
2228        if(adcHe<=0){
2229          if ( debug ) printf(" %i adcHe<=0 \n",ii);
2230          //      eDEDXpmt->AddAt((Float_t)adccorr,ii); //?
2231          continue;
2232        }
2233        if ( exitat == 2 ){
2234          if(ii==9 && S115B_break==1)  eDEDXpmt->AddAt(36.*(Float_t)adccorr/adcHe,ii);
2235          else  adclin  = 4.*(Float_t)adccorr/adcHe;
2236          continue;
2237        }
2238    
2239        if(ii==9 && S115B_break==1)  adcnorm = f_pos5B(adccorr);
2240        else adcnorm = f_pos( (parPos[ii]), adccorr);
2241        if(adcnorm<=0){
2242          if ( debug ) printf(" %i adcnorm<=0 \n",ii);
2243          //      eDEDXpmt->AddAt((Float_t)adccorr,ii);//?
2244          continue;
2245        }
2246        if ( debug ) printf(" adcnorm %f \n",adcnorm);
2247    
2248        if(ii==9 && S115B_break==1)  adclin  = 36.*adcnorm/adcHe;
2249        else  adclin  = 4.*adcnorm/adcHe;
2250        if ( debug ) printf(" adclin %f \n",adclin);
2251        if(adclin<=0){
2252          if ( debug ) printf(" %i adclin<=0 \n",ii);
2253          //      eDEDXpmt->AddAt((Float_t)adccorr,ii);//?
2254          continue;
2255        }
2256        if ( exitat == 3 ){
2257          if(ii==9 && S115B_break==1)  eDEDXpmt->AddAt((Float_t)adclin,ii);
2258          else  eDEDXpmt->AddAt((Float_t)adclin,ii);
2259          continue;
2260        }
2261        //
2262        if ( betamean > 99. ){
2263          //      eDEDXpmt.AddAt((Float_t)adclin,ii);
2264          eDEDXpmt->AddAt((Float_t)adclin,ii);
2265          //      printf(" AAPMT IS %i dedx is %f vector is %f \n",ii,adclin,eDEDXpmt[ii]);
2266          if ( debug ) printf(" %i betamean > 99 \n",ii);
2267          continue;
2268        };
2269        //
2270        double dEdxHe=-2;
2271        if(ii==9 && S115B_break==1){
2272          if( betamean <1. ) dEdxHe = f_BB5B( betamean );
2273          else                       dEdxHe = 33;
2274        } else {
2275          if( betamean <1. ) dEdxHe = f_BB( (parBBneg[ii]), betamean );
2276          else                       dEdxHe = parBBpos[ii];
2277        }
2278        
2279        if ( debug ) printf(" dEdxHe %f \n",dEdxHe);
2280        
2281        if(dEdxHe<=0){
2282          eDEDXpmt->AddAt((Float_t)adclin,ii);
2283          if ( debug ) printf(" %i dEdxHe<=0 \n",ii);
2284          continue;
2285        };
2286    
2287        if(ii==9 && S115B_break==1)  dEdx = f_desatBB5B( adclin );
2288        else  dEdx = f_desatBB((parDesatBB[ii]), adclin );
2289    
2290        if(dEdx<=0){
2291          eDEDXpmt->AddAt((Float_t)adclin,ii);
2292          if ( debug ) printf(" %i dEdx<=0 \n",ii);
2293          continue;
2294        };
2295    
2296        if ( debug ) printf(" dEdx %f \n",dEdx);
2297        eDEDXpmt->AddAt((Float_t)dEdx,ii);
2298        //    eDEDXpmt.AddAt((Float_t)dEdx,ii);
2299    
2300        //    printf(" PMT IS %i dedx is %f vector is %f \n",ii,dEdx,eDEDXpmt[ii]);
2301    
2302      }  //end loop on 48 PMT
2303    
2304    };
2305    
2306    
2307    //------------------------------------------------------------------------
2308    void ToFdEdx::Define_PMTsat()
2309    {
2310      Float_t  sat[48] = {
2311        3176.35,3178.19,3167.38,3099.73,3117.00,3126.29,3111.44,3092.27,
2312        3146.48,3094.41,3132.13,3115.37,3099.32,3110.97,3111.80,3143.14,
2313        3106.72,3153.44,3136.00,3188.96,3104.73,3140.45,3073.18,3106.62,
2314        3112.48,3146.92,3127.24,3136.52,3109.59,3112.89,3045.15,3147.26,
2315        3095.92,3121.05,3083.25,3123.62,3150.92,3125.30,3067.60,3160.18,
2316        3119.36,3108.92,3164.77,3133.64,3111.47,3131.98,3128.87,3135.56 };
2317      PMTsat.Set(48,sat);
2318    }
2319    
2320    //------------------------------------------------------------------------
2321    void ToFdEdx::ReadParBBpos( const char *fname )
2322    {
2323      //  printf("read %s\n",fname);
2324      parBBpos.Set(48);
2325      FILE *fattin = fopen( fname , "r" );
2326      for (int i=0; i<48; i++) {
2327        int   tid=0;
2328        float  tp;
2329        if(fscanf(fattin,"%d %f",
2330                  &tid, &tp )!=2) break;
2331        parBBpos[i]=tp;
2332      }
2333      fclose(fattin);
2334    }
2335    
2336    //------------------------------------------------------------------------
2337    void ToFdEdx::ReadParDesatBB( const char *fname )
2338    {
2339      //  printf("read %s\n",fname);
2340      FILE *fattin = fopen( fname , "r" );
2341      for (int i=0; i<48; i++) {
2342        int   tid=0;
2343        float  tp[3];
2344        if(fscanf(fattin,"%d %f %f %f",
2345                  &tid, &tp[0], &tp[1], &tp[2] )!=4) break;
2346        parDesatBB[i].Set(3,tp);
2347      }
2348      fclose(fattin);
2349    }
2350    
2351    
2352    //------------------------------------------------------------------------
2353    void ToFdEdx::ReadParBBneg( const char *fname )
2354    
2355    {
2356      //  printf("read %s\n",fname);
2357      FILE *fattin = fopen( fname , "r" );
2358      for (int i=0; i<48; i++) {
2359        int   tid=0;
2360        float  tp[3];
2361        if(fscanf(fattin,"%d %f %f %f",
2362                  &tid, &tp[0], &tp[1], &tp[2] )!=4) break;
2363        parBBneg[i].Set(3,tp);
2364      }
2365      fclose(fattin);
2366    }
2367    
2368    //------------------------------------------------------------------------
2369    void ToFdEdx::ReadParPos( const char *fname )
2370    {
2371      //  printf("read %s\n",fname);
2372      FILE *fattin = fopen( fname , "r" );
2373      for (int i=0; i<48; i++) {
2374        int   tid=0;
2375        float  tp[4];
2376        if(fscanf(fattin,"%d %f %f %f %f",
2377                  &tid, &tp[0], &tp[1], &tp[2], &tp[3])!=5) break;
2378        parPos[i].Set(4,tp);
2379      }
2380      fclose(fattin);
2381    }
2382    
2383    //------------------------------------------------------------------------
2384    void ToFdEdx::ReadParAtt( const char *fname )
2385    {
2386      //  printf("read %s\n",fname);
2387      FILE *fattin = fopen( fname , "r" );
2388      for (int i=0; i<48; i++) {
2389        int   tid=0;
2390        float  tp[6];
2391        if(fscanf(fattin,"%d %f %f %f %f %f %f",
2392                  &tid, &tp[0], &tp[1], &tp[2], &tp[3], &tp[4], &tp[5] )!=7) break;
2393        parAtt[i].Set(6,tp);
2394      }
2395      fclose(fattin);
2396    }
2397    
2398    
2399    
2400    
2401    
2402    
2403    double ToFdEdx::f_att( TArrayF &p, float x )
2404    {
2405      return
2406        p[0] +
2407        p[1]*x +
2408        p[2]*x*x +
2409        p[3]*x*x*x +
2410        p[4]*x*x*x*x +
2411        p[5]*x*x*x*x*x;
2412    }
2413    //------------------------------------------------------------------------
2414    double ToFdEdx::f_att5B( float x )
2415    {
2416      return
2417        101.9409 +
2418        6.643781*x +
2419        0.2765518*x*x +
2420        0.004617647*x*x*x +
2421        0.0006195132*x*x*x*x +
2422        0.00002813734*x*x*x*x*x;
2423    }
2424    
2425    
2426    double ToFdEdx::f_pos( TArrayF &p, float x )
2427    {
2428      return
2429        p[0] +
2430        p[1]*x +
2431        p[2]*x*x +
2432        p[3]*x*x*x;
2433    }
2434    
2435    double ToFdEdx::f_pos5B( float x )
2436    {
2437      return
2438        15.45132 +
2439        0.8369721*x +
2440        0.0005*x*x;
2441    }
2442    
2443    
2444    
2445    double ToFdEdx::f_adcPC( float x )
2446    {
2447      return 28.12+0.6312*x-5.647e-05*x*x+3.064e-08*x*x*x;
2448    }
2449    
2450    
2451    float ToFdEdx::Get_adc_he( int id, float pl_x[6], float pl_y[6])
2452    {
2453    
2454      //
2455      // input: id - pmt [0:47}
2456      //             pl_x - coord x of the tof plane
2457      //             pl_y - coord y
2458    
2459      adc_he = 0;
2460      if( eGeom.GetXY(id)==1 )  adc_he = f_att( (parAtt[id]), pl_x[eGeom.GetPlane(id)] );
2461      if( eGeom.GetXY(id)==2 )  adc_he = f_att( (parAtt[id]), pl_y[eGeom.GetPlane(id)] );
2462      return adc_he;
2463    }
2464    
2465    //------------------------------------------------------------------------
2466    double ToFdEdx::f_BB( TArrayF &p, float x )
2467    {
2468      return  p[0]/(x*x)*(log(x*x/(1-x*x)) - p[1]*x*x - p[2]);
2469    }
2470    
2471    //------------------------------------------------------------------------
2472    double ToFdEdx::f_BB5B( float x )
2473    {
2474      return  0.165797/(x*x)*(log(x*x/(1-x*x)) + 140.481*x*x + 52.9258);
2475    }
2476    //------------------------------------------------------------------------
2477    double ToFdEdx::f_desatBB( TArrayF &p, float x )
2478    {
2479      return
2480        p[0] +
2481        p[1]*x +
2482        p[2]*x*x;
2483    }
2484    
2485    //------------------------------------------------------------------------
2486    double ToFdEdx::f_desatBB5B( float x )
2487    {
2488      return
2489        -2.4 +
2490        0.75*x +
2491        0.009*x*x;
2492    }
2493    

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.42

  ViewVC Help
Powered by ViewVC 1.1.23