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

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.46

  ViewVC Help
Powered by ViewVC 1.1.23