| 3 | 
  * \author Gianfranca DeRosa, Wolfgang Menn | 
  * \author Gianfranca DeRosa, Wolfgang Menn | 
| 4 | 
  */ | 
  */ | 
| 5 | 
  | 
  | 
 | 
 #include <TObject.h> | 
  | 
| 6 | 
 #include <ToFLevel2.h> | 
 #include <ToFLevel2.h> | 
| 7 | 
 #include <iostream> | 
  | 
| 8 | 
 using namespace std; | 
 using namespace std; | 
| 9 | 
  | 
  | 
| 10 | 
 ClassImp(ToFPMT); | 
 ClassImp(ToFPMT); | 
| 11 | 
 ClassImp(ToFTrkVar); | 
 ClassImp(ToFTrkVar); | 
| 12 | 
 ClassImp(ToFLevel2); | 
 ClassImp(ToFLevel2); | 
| 15 | 
   pmt_id = 0; | 
   pmt_id = 0; | 
| 16 | 
   adc = 0.; | 
   adc = 0.; | 
| 17 | 
   tdc_tw = 0.; | 
   tdc_tw = 0.; | 
| 18 | 
  | 
   tdc = 0.; | 
| 19 | 
 } | 
 } | 
| 20 | 
  | 
  | 
| 21 | 
 ToFPMT::ToFPMT(const ToFPMT &t){ | 
 ToFPMT::ToFPMT(const ToFPMT &t){ | 
| 22 | 
   pmt_id = t.pmt_id; | 
   pmt_id = t.pmt_id; | 
| 23 | 
   adc = t.adc; | 
   adc = t.adc; | 
| 24 | 
   tdc_tw = t.tdc_tw; | 
   tdc_tw = t.tdc_tw; | 
| 25 | 
  | 
   tdc = t.tdc; | 
| 26 | 
 } | 
 } | 
| 27 | 
  | 
  | 
| 28 | 
 void ToFPMT::Clear(){ | 
 void ToFPMT::Clear(Option_t *t){ | 
| 29 | 
   pmt_id = 0; | 
   pmt_id = 0; | 
| 30 | 
   adc = 0.; | 
   adc = 0.; | 
| 31 | 
   tdc_tw = 0.; | 
   tdc_tw = 0.; | 
| 32 | 
  | 
   tdc = 0.; | 
| 33 | 
 } | 
 } | 
| 34 | 
  | 
  | 
| 35 | 
  | 
  | 
| 53 | 
   // | 
   // | 
| 54 | 
 }; | 
 }; | 
| 55 | 
  | 
  | 
| 56 | 
 void ToFTrkVar::Clear() { | 
 void ToFTrkVar::Clear(Option_t *t) { | 
| 57 | 
   trkseqno = 0; | 
   trkseqno = 0; | 
| 58 | 
   npmttdc = 0; | 
   npmttdc = 0; | 
| 59 | 
   npmtadc = 0; | 
   npmtadc = 0; | 
| 107 | 
     if(!ToFTrk)ToFTrk = new TClonesArray("ToFTrkVar",2); //ELENA | 
     if(!ToFTrk)ToFTrk = new TClonesArray("ToFTrkVar",2); //ELENA | 
| 108 | 
 }//ELENA | 
 }//ELENA | 
| 109 | 
  | 
  | 
| 110 | 
 void ToFLevel2::Clear(){ | 
 void ToFLevel2::Clear(Option_t *t){ | 
| 111 | 
   // | 
   // | 
| 112 | 
   if(ToFTrk)ToFTrk->Delete(); //ELENA | 
   if(ToFTrk)ToFTrk->Delete(); //ELENA | 
| 113 | 
   if(PMT)PMT->Delete(); //ELENA | 
   if(PMT)PMT->Delete(); //ELENA | 
| 116 | 
   //  | 
   //  | 
| 117 | 
 }; | 
 }; | 
| 118 | 
  | 
  | 
| 119 | 
 void ToFLevel2::Delete(){ //ELENA | 
 void ToFLevel2::Delete(Option_t *t){ //ELENA | 
| 120 | 
   // | 
   // | 
| 121 | 
   if(ToFTrk){  | 
   if(ToFTrk){  | 
| 122 | 
       ToFTrk->Delete(); //ELENA | 
       ToFTrk->Delete(); //ELENA | 
| 696 | 
 // gf Apr 07 | 
 // gf Apr 07 | 
| 697 | 
  | 
  | 
| 698 | 
 void ToFLevel2::GetPaddlePMT(Int_t paddle, Int_t &pmtleft, Int_t &pmtright){ | 
 void ToFLevel2::GetPaddlePMT(Int_t paddle, Int_t &pmtleft, Int_t &pmtright){ | 
| 699 | 
  | 
   pmtleft=paddle*2; | 
| 700 | 
   if(paddle==0){ | 
   pmtright= pmtleft+1; | 
 | 
     pmtleft=0; | 
  | 
 | 
     pmtright=1; | 
  | 
 | 
   } | 
  | 
 | 
  | 
  | 
 | 
   if(paddle==1){ | 
  | 
 | 
     pmtleft=2; | 
  | 
 | 
     pmtright=3; | 
  | 
 | 
   } | 
  | 
 | 
  | 
  | 
 | 
   if(paddle==2){ | 
  | 
 | 
     pmtleft=4; | 
  | 
 | 
     pmtright=5; | 
  | 
 | 
   } | 
  | 
 | 
  | 
  | 
 | 
   if(paddle==3){ | 
  | 
 | 
     pmtleft=6; | 
  | 
 | 
     pmtright=7; | 
  | 
 | 
   } | 
  | 
 | 
  | 
  | 
 | 
   if(paddle==4){ | 
  | 
 | 
     pmtleft=8; | 
  | 
 | 
     pmtright=9; | 
  | 
 | 
   } | 
  | 
 | 
  | 
  | 
 | 
   if(paddle==5){ | 
  | 
 | 
     pmtleft=10; | 
  | 
 | 
     pmtright=11; | 
  | 
 | 
   } | 
  | 
 | 
  | 
  | 
 | 
   if(paddle==6){ | 
  | 
 | 
     pmtleft=12; | 
  | 
 | 
     pmtright=13; | 
  | 
 | 
   } | 
  | 
 | 
  | 
  | 
 | 
   if(paddle==7){ | 
  | 
 | 
     pmtleft=14; | 
  | 
 | 
     pmtright=15; | 
  | 
 | 
   } | 
  | 
 | 
  | 
  | 
 | 
   if(paddle==8){ | 
  | 
 | 
     pmtleft=16; | 
  | 
 | 
     pmtright=17; | 
  | 
 | 
   } | 
  | 
 | 
  | 
  | 
 | 
   if(paddle==9){ | 
  | 
 | 
     pmtleft=18; | 
  | 
 | 
     pmtright=19; | 
  | 
 | 
   } | 
  | 
 | 
  | 
  | 
 | 
   if(paddle==10){ | 
  | 
 | 
     pmtleft=20; | 
  | 
 | 
     pmtright=21; | 
  | 
 | 
   } | 
  | 
 | 
  | 
  | 
 | 
   if(paddle==11){ | 
  | 
 | 
     pmtleft=22; | 
  | 
 | 
     pmtright=23; | 
  | 
 | 
   } | 
  | 
 | 
  | 
  | 
 | 
   if(paddle==12){ | 
  | 
 | 
     pmtleft=24; | 
  | 
 | 
     pmtright=25; | 
  | 
 | 
   } | 
  | 
 | 
  | 
  | 
 | 
   if(paddle==13){ | 
  | 
 | 
     pmtleft=26; | 
  | 
 | 
     pmtright=27; | 
  | 
 | 
   } | 
  | 
 | 
  | 
  | 
 | 
   if(paddle==14){ | 
  | 
 | 
     pmtleft=28; | 
  | 
 | 
     pmtright=29; | 
  | 
 | 
   } | 
  | 
 | 
  | 
  | 
 | 
   if(paddle==15){ | 
  | 
 | 
     pmtleft=30; | 
  | 
 | 
     pmtright=31; | 
  | 
 | 
   } | 
  | 
 | 
  | 
  | 
 | 
   if(paddle==16){ | 
  | 
 | 
     pmtleft=32; | 
  | 
 | 
     pmtright=33; | 
  | 
 | 
   } | 
  | 
 | 
  | 
  | 
 | 
   if(paddle==17){ | 
  | 
 | 
     pmtleft=34; | 
  | 
 | 
     pmtright=35; | 
  | 
 | 
   } | 
  | 
 | 
  | 
  | 
 | 
   if(paddle==18){ | 
  | 
 | 
     pmtleft=36; | 
  | 
 | 
     pmtright=37; | 
  | 
 | 
   } | 
  | 
 | 
  | 
  | 
 | 
   if(paddle==19){ | 
  | 
 | 
     pmtleft=38; | 
  | 
 | 
     pmtright=39; | 
  | 
 | 
   } | 
  | 
 | 
  | 
  | 
 | 
   if(paddle==20){ | 
  | 
 | 
     pmtleft=40; | 
  | 
 | 
     pmtright=41; | 
  | 
 | 
   } | 
  | 
 | 
  | 
  | 
 | 
   if(paddle==21){ | 
  | 
 | 
     pmtleft=42; | 
  | 
 | 
     pmtright=43; | 
  | 
 | 
   } | 
  | 
 | 
  | 
  | 
 | 
   if(paddle==22){ | 
  | 
 | 
     pmtleft=44; | 
  | 
 | 
     pmtright=45; | 
  | 
 | 
   } | 
  | 
 | 
  | 
  | 
 | 
   if(paddle==23){ | 
  | 
 | 
     pmtleft=46; | 
  | 
 | 
     pmtright=47; | 
  | 
 | 
   } | 
  | 
 | 
    | 
  | 
| 701 | 
   return; | 
   return; | 
| 702 | 
 } | 
 } | 
| 703 | 
  | 
  | 
| 811 | 
  */ | 
  */ | 
| 812 | 
 Int_t ToFLevel2::GetPaddleid(Int_t plane, Int_t paddle) | 
 Int_t ToFLevel2::GetPaddleid(Int_t plane, Int_t paddle) | 
| 813 | 
 { | 
 { | 
 | 
  | 
  | 
| 814 | 
   Int_t padid=-1; | 
   Int_t padid=-1; | 
| 815 | 
   Int_t pads11=8; | 
   Int_t pads[6]={8,6,2,2,3,3}; | 
 | 
   Int_t pads12=6; | 
  | 
 | 
   Int_t pads21=2; | 
  | 
 | 
   Int_t pads22=2; | 
  | 
 | 
   Int_t pads31=3; | 
  | 
 | 
   //  Int_t pads32=3; | 
  | 
 | 
  | 
  | 
| 816 | 
  | 
  | 
| 817 | 
   if(plane == 0){ | 
   int somma=0; | 
| 818 | 
     padid=paddle; | 
   int np=plane; | 
| 819 | 
   } | 
   for(Int_t j=0; j<np; j++){ | 
| 820 | 
  | 
     somma+=pads[j]; | 
 | 
   if(plane == 1){ | 
  | 
 | 
     padid=pads11+paddle; | 
  | 
| 821 | 
   } | 
   } | 
| 822 | 
  | 
   padid=paddle+somma; | 
 | 
   if(plane == 2){ | 
  | 
 | 
     padid=pads11+pads12+paddle; | 
  | 
 | 
   } | 
  | 
 | 
  | 
  | 
 | 
   if(plane == 3){ | 
  | 
 | 
     padid=pads11+pads12+pads21+paddle; | 
  | 
 | 
   } | 
  | 
 | 
  | 
  | 
 | 
   if(plane == 4){ | 
  | 
 | 
     padid=pads11+pads12+pads21+pads22+paddle; | 
  | 
 | 
   } | 
  | 
 | 
  | 
  | 
 | 
   if(plane == 5){ | 
  | 
 | 
     padid=pads11+pads12+pads21+pads22+pads31+paddle; | 
  | 
 | 
   } | 
  | 
 | 
  | 
  | 
| 823 | 
   return padid; | 
   return padid; | 
 | 
  | 
  | 
| 824 | 
 } | 
 } | 
| 825 | 
  | 
  | 
| 826 | 
  | 
  | 
| 904 | 
  | 
  | 
| 905 | 
 } | 
 } | 
| 906 | 
  | 
  | 
| 907 | 
  | 
 /// wm feb 08 | 
| 908 | 
  | 
  | 
| 909 | 
  | 
 /** | 
| 910 | 
  | 
  * Method to calculate Beta from the 12 single measurements | 
| 911 | 
  | 
  * we check the individual weights for artificial TDC values, then calculate | 
| 912 | 
  | 
  * am mean beta for the first time. In a second step we loop again through | 
| 913 | 
  | 
  * the single measurements, checking for the residual from the mean | 
| 914 | 
  | 
  * The cut on the residual reject measurements > "x"-sigma. A chi2 value is | 
| 915 | 
  | 
  * calculated, furthermore a "quality" value by adding the weights which | 
| 916 | 
  | 
  * are finally used. If all measurements are taken, "quality" will be = 22.47. | 
| 917 | 
  | 
  * A chi2 cut around 3-4 and a quality-cut > 20 is needed for clean beta | 
| 918 | 
  | 
  * measurements like antiprotons etc. | 
| 919 | 
  | 
  * The Level2 output is derived in the fortran routines using: 10.,10.,20. | 
| 920 | 
  | 
  * @param notrack Track Number | 
| 921 | 
  | 
  * @param cut on residual: difference between single measurement and mean  | 
| 922 | 
  | 
  * @param cut on "quality" | 
| 923 | 
  | 
  * @param cut on chi2 | 
| 924 | 
  | 
  */ | 
| 925 | 
  | 
  | 
| 926 | 
  | 
 Float_t ToFLevel2::CalcBeta(Int_t notrack, Float_t resmax, Float_t qualitycut, Float_t chi2cut){ | 
| 927 | 
  | 
  | 
| 928 | 
  | 
 //  cout<<" in CalcBeta "<<resmax<<" "<<chi2cut<<" "<<qualitycut<<endl; | 
| 929 | 
  | 
  | 
| 930 | 
  | 
   Float_t bxx = 100.; | 
| 931 | 
  | 
   // | 
| 932 | 
  | 
   ToFTrkVar *trk = GetToFTrkVar(notrack); | 
| 933 | 
  | 
   if(!trk) return 0; //ELENA | 
| 934 | 
  | 
  | 
| 935 | 
  | 
  | 
| 936 | 
  | 
   Float_t chi2,xhelp,beta_mean; | 
| 937 | 
  | 
   Float_t w_i[12],quality,sw,sxw,res,betachi,beta_mean_inv; | 
| 938 | 
  | 
   Float_t b[12],tdcfl; | 
| 939 | 
  | 
   Int_t  pmt_id,pmt_plane; | 
| 940 | 
  | 
  | 
| 941 | 
  | 
   for (Int_t i=0; i<12; i++){ | 
| 942 | 
  | 
     b[i] = trk->beta[i]; | 
| 943 | 
  | 
                               } | 
| 944 | 
  | 
        | 
| 945 | 
  | 
  | 
| 946 | 
  | 
 //======================================================================== | 
| 947 | 
  | 
 //---  Find out ToF layers with artificial TDC values & fill vector    --- | 
| 948 | 
  | 
 //======================================================================== | 
| 949 | 
  | 
  | 
| 950 | 
  | 
 Float_t  w_il[6]; | 
| 951 | 
  | 
  | 
| 952 | 
  | 
      for (Int_t jj=0; jj<6;jj++) { | 
| 953 | 
  | 
          w_il[jj] = 1000.; | 
| 954 | 
  | 
                                  } | 
| 955 | 
  | 
  | 
| 956 | 
  | 
  | 
| 957 | 
  | 
   for (Int_t i=0; i<trk->npmttdc; i++){ | 
| 958 | 
  | 
     // | 
| 959 | 
  | 
     pmt_id = (trk->pmttdc).At(i); | 
| 960 | 
  | 
     pmt_plane = GetPlaneIndex(pmt_id); | 
| 961 | 
  | 
     tdcfl = (trk->tdcflag).At(i); | 
| 962 | 
  | 
     if (w_il[pmt_plane] != 1.) w_il[pmt_plane] = tdcfl; //tdcflag | 
| 963 | 
  | 
                                      }; | 
| 964 | 
  | 
    | 
| 965 | 
  | 
 //======================================================================== | 
| 966 | 
  | 
 //---  Set weights for the 12 measurements using information for top and bottom: | 
| 967 | 
  | 
 //---  if no measurements: weight = set to very high value=> not used | 
| 968 | 
  | 
 //---  top or bottom artificial: weight*sqrt(2) | 
| 969 | 
  | 
 //---  top and bottom artificial: weight*sqrt(2)*sqrt(2) | 
| 970 | 
  | 
 //======================================================================== | 
| 971 | 
  | 
  | 
| 972 | 
  | 
 Int_t itop[12] = {0,0,1,1,2,2,3,3,0,0,1,1}; | 
| 973 | 
  | 
 Int_t ibot[12] = {4,5,4,5,4,5,4,5,2,3,2,3}; | 
| 974 | 
  | 
  | 
| 975 | 
  | 
      xhelp= 1E09; | 
| 976 | 
  | 
     | 
| 977 | 
  | 
      for (Int_t jj=0; jj<12;jj++) { | 
| 978 | 
  | 
      if (jj<4)           xhelp = 0.11;    // S1-S3 | 
| 979 | 
  | 
      if ((jj>3)&&(jj<8)) xhelp = 0.18;    // S2-S3 | 
| 980 | 
  | 
      if (jj>7)           xhelp = 0.28;    // S1-S2 | 
| 981 | 
  | 
      if ((w_il[itop[jj]] == 1000.) && (w_il[ibot[jj]] == 1000.)) xhelp = 1E09; | 
| 982 | 
  | 
      if ((w_il[itop[jj]] == 1) || (w_il[ibot[jj]] == 1.)) xhelp = xhelp*1.414 ; | 
| 983 | 
  | 
      if ((w_il[itop[jj]] == 1) && (w_il[ibot[jj]] == 1.)) xhelp = xhelp*2. ; | 
| 984 | 
  | 
  | 
| 985 | 
  | 
      w_i[jj] = 1./xhelp; | 
| 986 | 
  | 
                                   } | 
| 987 | 
  | 
  | 
| 988 | 
  | 
  | 
| 989 | 
  | 
 //======================================================================== | 
| 990 | 
  | 
 //--- Calculate mean beta for the first time ----------------------------- | 
| 991 | 
  | 
 //--- We are using "1/beta" since its error is gaussian ------------------ | 
| 992 | 
  | 
 //======================================================================== | 
| 993 | 
  | 
  | 
| 994 | 
  | 
       Int_t icount=0; | 
| 995 | 
  | 
       sw=0.; | 
| 996 | 
  | 
       sxw=0.; | 
| 997 | 
  | 
       beta_mean=100.; | 
| 998 | 
  | 
  | 
| 999 | 
  | 
           for (Int_t jj=0; jj<12;jj++){ | 
| 1000 | 
  | 
         if ((fabs(1./b[jj])>0.1)&&(fabs(1./b[jj])<15.)) | 
| 1001 | 
  | 
          { | 
| 1002 | 
  | 
             icount= icount+1; | 
| 1003 | 
  | 
             sxw=sxw + (1./b[jj])*w_i[jj]*w_i[jj] ; | 
| 1004 | 
  | 
             sw =sw + w_i[jj]*w_i[jj] ; | 
| 1005 | 
  | 
  | 
| 1006 | 
  | 
          } | 
| 1007 | 
  | 
          } | 
| 1008 | 
  | 
  | 
| 1009 | 
  | 
       if (icount>0) beta_mean=1./(sxw/sw); | 
| 1010 | 
  | 
       beta_mean_inv = 1./beta_mean; | 
| 1011 | 
  | 
  | 
| 1012 | 
  | 
 //======================================================================== | 
| 1013 | 
  | 
 //--- Calculate beta for the second time, use residuals of the single | 
| 1014 | 
  | 
 //--- measurements to get a chi2 value | 
| 1015 | 
  | 
 //======================================================================== | 
| 1016 | 
  | 
  | 
| 1017 | 
  | 
       icount=0; | 
| 1018 | 
  | 
       sw=0.; | 
| 1019 | 
  | 
       sxw=0.; | 
| 1020 | 
  | 
       betachi = 100.; | 
| 1021 | 
  | 
       chi2 = 0.; | 
| 1022 | 
  | 
       quality=0.; | 
| 1023 | 
  | 
  | 
| 1024 | 
  | 
  | 
| 1025 | 
  | 
           for (Int_t jj=0; jj<12;jj++){ | 
| 1026 | 
  | 
        if ((fabs(1./b[jj])>0.1)&&(fabs(1./b[jj])<15.)&&(w_i[jj]>0.01)) { | 
| 1027 | 
  | 
             res = beta_mean_inv - (1./b[jj]) ; | 
| 1028 | 
  | 
             if (fabs(res*w_i[jj])<resmax)          {; | 
| 1029 | 
  | 
             chi2 = chi2 + pow((res*w_i[jj]),2) ; | 
| 1030 | 
  | 
             icount= icount+1; | 
| 1031 | 
  | 
             sxw=sxw + (1./b[jj])*w_i[jj]*w_i[jj] ; | 
| 1032 | 
  | 
             sw =sw + w_i[jj]*w_i[jj] ; | 
| 1033 | 
  | 
                                                } | 
| 1034 | 
  | 
                                                                         } | 
| 1035 | 
  | 
                                       } | 
| 1036 | 
  | 
       quality = sqrt(sw) ; | 
| 1037 | 
  | 
  | 
| 1038 | 
  | 
       if (icount==0) chi2 = 1000.; | 
| 1039 | 
  | 
       if (icount>0) chi2 = chi2/(icount) ; | 
| 1040 | 
  | 
       if (icount>0) betachi=1./(sxw/sw); | 
| 1041 | 
  | 
  | 
| 1042 | 
  | 
    bxx = 100.; | 
| 1043 | 
  | 
    if ((chi2 < chi2cut)&&(quality>qualitycut)) bxx = betachi; | 
| 1044 | 
  | 
   // | 
| 1045 | 
  | 
   return(bxx); | 
| 1046 | 
  | 
 }; | 
| 1047 | 
  | 
  | 
| 1048 | 
  | 
  | 
| 1049 | 
  | 
 //////////////////////////////////////////////////// | 
| 1050 | 
 //////////////////////////////////////////////////// | 
 //////////////////////////////////////////////////// | 
| 1051 | 
  | 
  | 
| 1052 | 
  | 
  | 
| 1097 | 
       } | 
       } | 
| 1098 | 
   } //ELENA | 
   } //ELENA | 
| 1099 | 
 } | 
 } | 
| 1100 | 
  | 
  | 
| 1101 | 
  | 
  | 
| 1102 | 
  | 
 // | 
| 1103 | 
  | 
 // Reprocessing tool // Emiliano 08/04/07 | 
| 1104 | 
  | 
 //  | 
| 1105 | 
  | 
 Int_t ToFLevel2::Process(TrkLevel2 *trk, TrigLevel2 *trg, GL_RUN *run, OrbitalInfo *orb, Bool_t force){ | 
| 1106 | 
  | 
   //  | 
| 1107 | 
  | 
   // Copiare qui qualcosa di simile a calonuclei per evitare di riprocessare sempre tutto | 
| 1108 | 
  | 
   // | 
| 1109 | 
  | 
  | 
| 1110 | 
  | 
  | 
| 1111 | 
  | 
  | 
| 1112 | 
  | 
  | 
| 1113 | 
  | 
   // | 
| 1114 | 
  | 
   // structures to communicate with F77 | 
| 1115 | 
  | 
   // | 
| 1116 | 
  | 
   extern struct ToFInput  tofinput_; | 
| 1117 | 
  | 
   extern struct ToFOutput tofoutput_; | 
| 1118 | 
  | 
   //  | 
| 1119 | 
  | 
   // DB connection | 
| 1120 | 
  | 
   // | 
| 1121 | 
  | 
   TString host; | 
| 1122 | 
  | 
   TString user; | 
| 1123 | 
  | 
   TString psw; | 
| 1124 | 
  | 
   const char *pamdbhost=gSystem->Getenv("PAM_DBHOST"); | 
| 1125 | 
  | 
   const char *pamdbuser=gSystem->Getenv("PAM_DBUSER"); | 
| 1126 | 
  | 
   const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW"); | 
| 1127 | 
  | 
   if ( !pamdbhost ) pamdbhost = ""; | 
| 1128 | 
  | 
   if ( !pamdbuser ) pamdbuser = ""; | 
| 1129 | 
  | 
   if ( !pamdbpsw ) pamdbpsw = ""; | 
| 1130 | 
  | 
   if ( strcmp(pamdbhost,"") ) host = pamdbhost; | 
| 1131 | 
  | 
   if ( strcmp(pamdbuser,"") ) user = pamdbuser; | 
| 1132 | 
  | 
   if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw; | 
| 1133 | 
  | 
   // | 
| 1134 | 
  | 
   // | 
| 1135 | 
  | 
   TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); | 
| 1136 | 
  | 
   if ( !dbc->IsConnected() ) return 1; | 
| 1137 | 
  | 
   stringstream myquery; | 
| 1138 | 
  | 
   myquery.str(""); | 
| 1139 | 
  | 
   myquery << "SET time_zone='+0:00'"; | 
| 1140 | 
  | 
   dbc->Query(myquery.str().c_str()); | 
| 1141 | 
  | 
   GL_PARAM *glparam = new GL_PARAM(); | 
| 1142 | 
  | 
   glparam->Query_GL_PARAM(1,1,dbc); // parameters stored in DB in GL_PRAM table | 
| 1143 | 
  | 
   trk->LoadField(glparam->PATH+glparam->NAME); | 
| 1144 | 
  | 
   // | 
| 1145 | 
  | 
   Bool_t defcal = true; | 
| 1146 | 
  | 
   Int_t error=glparam->Query_GL_PARAM(run->RUNHEADER_TIME,201,dbc); // parameters stored in DB in GL_PRAM table | 
| 1147 | 
  | 
   if ( error<0 ) { | 
| 1148 | 
  | 
     return(1); | 
| 1149 | 
  | 
   }; | 
| 1150 | 
  | 
   printf(" Reading ToF parameter file: %s \n",(glparam->PATH+glparam->NAME).Data()); | 
| 1151 | 
  | 
   if ( (UInt_t)glparam->TO_TIME != (UInt_t)4294967295UL ) defcal = false; | 
| 1152 | 
  | 
   // | 
| 1153 | 
  | 
   Int_t nlen = (Int_t)(glparam->PATH+glparam->NAME).Length(); | 
| 1154 | 
  | 
   rdtofcal((char *)(glparam->PATH+glparam->NAME).Data(),&nlen); | 
| 1155 | 
  | 
   // | 
| 1156 | 
  | 
   Int_t adc[4][12]; | 
| 1157 | 
  | 
   Int_t tdc[4][12]; | 
| 1158 | 
  | 
   Float_t tdcc[4][12]; | 
| 1159 | 
  | 
   // | 
| 1160 | 
  | 
   // process tof data | 
| 1161 | 
  | 
   // | 
| 1162 | 
  | 
   for (Int_t hh=0; hh<12;hh++){ | 
| 1163 | 
  | 
     for (Int_t kk=0; kk<4;kk++){ | 
| 1164 | 
  | 
            adc[kk][hh] = 4095; | 
| 1165 | 
  | 
            tdc[kk][hh] = 4095; | 
| 1166 | 
  | 
            tdcc[kk][hh] = 4095.; | 
| 1167 | 
  | 
            tofinput_.adc[hh][kk] = 4095; | 
| 1168 | 
  | 
            tofinput_.tdc[hh][kk] = 4095; | 
| 1169 | 
  | 
     }; | 
| 1170 | 
  | 
   }; | 
| 1171 | 
  | 
   Int_t ntrkentry = 0; | 
| 1172 | 
  | 
   Int_t npmtentry = 0; | 
| 1173 | 
  | 
   Int_t gg = 0; | 
| 1174 | 
  | 
   Int_t hh = 0; | 
| 1175 | 
  | 
   Int_t adcf[48]; | 
| 1176 | 
  | 
   memset(adcf, 0, 48*sizeof(Int_t)); | 
| 1177 | 
  | 
   Int_t tdcf[48]; | 
| 1178 | 
  | 
   memset(tdcf, 0, 48*sizeof(Int_t)); | 
| 1179 | 
  | 
   for (Int_t pm=0; pm < this->ntrk() ; pm++){ | 
| 1180 | 
  | 
      ToFTrkVar *ttf = this->GetToFTrkVar(pm); | 
| 1181 | 
  | 
      for ( Int_t nc=0; nc < ttf->npmttdc; nc++){ | 
| 1182 | 
  | 
             if ( (ttf->tdcflag).At(nc) != 0 ) tdcf[(ttf->pmttdc).At(nc)] = 1; | 
| 1183 | 
  | 
      }; | 
| 1184 | 
  | 
      for ( Int_t nc=0; nc < ttf->npmtadc; nc++){ | 
| 1185 | 
  | 
             if ( (ttf->adcflag).At(nc) != 0 ) adcf[(ttf->pmtadc).At(nc)] = 1; | 
| 1186 | 
  | 
      }; | 
| 1187 | 
  | 
   }; | 
| 1188 | 
  | 
   // | 
| 1189 | 
  | 
   for (Int_t pm=0; pm < this->npmt() ; pm++){ | 
| 1190 | 
  | 
      ToFPMT *pmt = this->GetToFPMT(pm); | 
| 1191 | 
  | 
      this->GetPMTIndex(pmt->pmt_id, gg, hh); | 
| 1192 | 
  | 
      if ( adcf[pmt->pmt_id] == 0 ){ | 
| 1193 | 
  | 
              tofinput_.adc[gg][hh] = (int)pmt->adc; | 
| 1194 | 
  | 
              adc[hh][gg] = (int)pmt->adc; | 
| 1195 | 
  | 
      }; | 
| 1196 | 
  | 
      if ( tdcf[pmt->pmt_id] == 0 ){ | 
| 1197 | 
  | 
              tofinput_.tdc[gg][hh] = (int)pmt->tdc; | 
| 1198 | 
  | 
              tdc[hh][gg] = (int)pmt->tdc; | 
| 1199 | 
  | 
      }; | 
| 1200 | 
  | 
      tdcc[hh][gg] = (float)pmt->tdc_tw; | 
| 1201 | 
  | 
      // Int_t pppid = this->GetPMTid(hh,gg); | 
| 1202 | 
  | 
      //      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); | 
| 1203 | 
  | 
   }; | 
| 1204 | 
  | 
   // | 
| 1205 | 
  | 
   Int_t unpackError = this->unpackError; | 
| 1206 | 
  | 
   // | 
| 1207 | 
  | 
   for (Int_t hh=0; hh<5;hh++){ | 
| 1208 | 
  | 
      tofinput_.patterntrig[hh]=trg->patterntrig[hh]; | 
| 1209 | 
  | 
   }; | 
| 1210 | 
  | 
   // | 
| 1211 | 
  | 
   this->Clear(); | 
| 1212 | 
  | 
   // | 
| 1213 | 
  | 
       Int_t pmt_id = 0; | 
| 1214 | 
  | 
       ToFPMT *t_pmt = new ToFPMT(); | 
| 1215 | 
  | 
       if(!(this->PMT)) this->PMT = new TClonesArray("ToFPMT",12); //ELENA | 
| 1216 | 
  | 
       TClonesArray &tpmt = *this->PMT; | 
| 1217 | 
  | 
       ToFTrkVar *t_tof = new ToFTrkVar(); | 
| 1218 | 
  | 
       if(!(this->ToFTrk)) this->ToFTrk = new TClonesArray("ToFTrkVar",2); //ELENA | 
| 1219 | 
  | 
       TClonesArray &t = *this->ToFTrk; | 
| 1220 | 
  | 
       // | 
| 1221 | 
  | 
       // | 
| 1222 | 
  | 
       // Here we have calibrated data, ready to be passed to the FORTRAN routine which will extract common and track-related  variables. | 
| 1223 | 
  | 
       // | 
| 1224 | 
  | 
       npmtentry = 0; | 
| 1225 | 
  | 
       // | 
| 1226 | 
  | 
       ntrkentry = 0; | 
| 1227 | 
  | 
       // | 
| 1228 | 
  | 
       // Calculate tracks informations from ToF alone | 
| 1229 | 
  | 
       // | 
| 1230 | 
  | 
       tofl2com(); | 
| 1231 | 
  | 
       // | 
| 1232 | 
  | 
       memcpy(this->tof_j_flag,tofoutput_.tof_j_flag,6*sizeof(Int_t)); | 
| 1233 | 
  | 
       // | 
| 1234 | 
  | 
       t_tof->trkseqno = -1; | 
| 1235 | 
  | 
       // | 
| 1236 | 
  | 
       // and now we must copy from the output structure to the level2 class: | 
| 1237 | 
  | 
       // | 
| 1238 | 
  | 
       t_tof->npmttdc = 0; | 
| 1239 | 
  | 
       // | 
| 1240 | 
  | 
       for (Int_t hh=0; hh<12;hh++){ | 
| 1241 | 
  | 
         for (Int_t kk=0; kk<4;kk++){ | 
| 1242 | 
  | 
           if ( tofoutput_.tofmask[hh][kk] != 0 ){ | 
| 1243 | 
  | 
             pmt_id = this->GetPMTid(kk,hh); | 
| 1244 | 
  | 
             t_tof->pmttdc.AddAt(pmt_id,t_tof->npmttdc); | 
| 1245 | 
  | 
             t_tof->tdcflag.AddAt(tofoutput_.tdcflagtof[hh][kk],t_tof->npmttdc); // gf: Jan 09/07 | 
| 1246 | 
  | 
             t_tof->npmttdc++; | 
| 1247 | 
  | 
           }; | 
| 1248 | 
  | 
         }; | 
| 1249 | 
  | 
       }; | 
| 1250 | 
  | 
       for (Int_t kk=0; kk<13;kk++){ | 
| 1251 | 
  | 
         t_tof->beta[kk] = tofoutput_.betatof_a[kk]; | 
| 1252 | 
  | 
       } | 
| 1253 | 
  | 
       // | 
| 1254 | 
  | 
       t_tof->npmtadc = 0; | 
| 1255 | 
  | 
       for (Int_t hh=0; hh<12;hh++){ | 
| 1256 | 
  | 
         for (Int_t kk=0; kk<4;kk++){ | 
| 1257 | 
  | 
           if ( tofoutput_.adctof_c[hh][kk] < 1000 ){ | 
| 1258 | 
  | 
             t_tof->dedx.AddAt(tofoutput_.adctof_c[hh][kk],t_tof->npmtadc); | 
| 1259 | 
  | 
             pmt_id = this->GetPMTid(kk,hh); | 
| 1260 | 
  | 
             t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc); | 
| 1261 | 
  | 
             t_tof->adcflag.AddAt(tofoutput_.adcflagtof[hh][kk],t_tof->npmtadc); // gf: Jan 09/07 | 
| 1262 | 
  | 
             t_tof->npmtadc++; | 
| 1263 | 
  | 
           }; | 
| 1264 | 
  | 
         }; | 
| 1265 | 
  | 
       }; | 
| 1266 | 
  | 
       // | 
| 1267 | 
  | 
       memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos)); | 
| 1268 | 
  | 
       memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos)); | 
| 1269 | 
  | 
       memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof)); | 
| 1270 | 
  | 
       memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof)); | 
| 1271 | 
  | 
       // | 
| 1272 | 
  | 
       new(t[ntrkentry]) ToFTrkVar(*t_tof); | 
| 1273 | 
  | 
       ntrkentry++; | 
| 1274 | 
  | 
       t_tof->Clear(); | 
| 1275 | 
  | 
       // | 
| 1276 | 
  | 
       // | 
| 1277 | 
  | 
       // | 
| 1278 | 
  | 
       t_pmt->Clear(); | 
| 1279 | 
  | 
       // | 
| 1280 | 
  | 
       for (Int_t hh=0; hh<12;hh++){ | 
| 1281 | 
  | 
         for (Int_t kk=0; kk<4;kk++){ | 
| 1282 | 
  | 
          // new WM | 
| 1283 | 
  | 
           if ( tofoutput_.tdc_c[hh][kk] < 4095 || adc[kk][hh] < 4095  || tdc[kk][hh] < 4095 ){ | 
| 1284 | 
  | 
 //          if ( tdcc[kk][hh] < 4095. || adc[kk][hh] < 4095  || tdc[kk][hh] < 4095 ){ | 
| 1285 | 
  | 
             // | 
| 1286 | 
  | 
             t_pmt->pmt_id = this->GetPMTid(kk,hh); | 
| 1287 | 
  | 
             t_pmt->tdc_tw = tofoutput_.tdc_c[hh][kk]; | 
| 1288 | 
  | 
             t_pmt->adc = (Float_t)adc[kk][hh]; | 
| 1289 | 
  | 
             t_pmt->tdc = (Float_t)tdc[kk][hh]; | 
| 1290 | 
  | 
             // | 
| 1291 | 
  | 
             new(tpmt[npmtentry]) ToFPMT(*t_pmt); | 
| 1292 | 
  | 
             npmtentry++; | 
| 1293 | 
  | 
             t_pmt->Clear(); | 
| 1294 | 
  | 
           }; | 
| 1295 | 
  | 
         }; | 
| 1296 | 
  | 
       }; | 
| 1297 | 
  | 
       // | 
| 1298 | 
  | 
       // Calculate track-related variables | 
| 1299 | 
  | 
       // | 
| 1300 | 
  | 
       if ( trk->ntrk() > 0 ){ | 
| 1301 | 
  | 
         // | 
| 1302 | 
  | 
         // We have at least one track | 
| 1303 | 
  | 
         // | 
| 1304 | 
  | 
         // | 
| 1305 | 
  | 
         // Run over tracks | 
| 1306 | 
  | 
         // | 
| 1307 | 
  | 
         for(Int_t nt=0; nt < trk->ntrk(); nt++){ | 
| 1308 | 
  | 
           // | 
| 1309 | 
  | 
           TrkTrack *ptt = trk->GetStoredTrack(nt); | 
| 1310 | 
  | 
           // | 
| 1311 | 
  | 
           // Copy the alpha vector in the input structure | 
| 1312 | 
  | 
           // | 
| 1313 | 
  | 
           for (Int_t e = 0; e < 5 ; e++){ | 
| 1314 | 
  | 
             tofinput_.al_pp[e] = ptt->al[e]; | 
| 1315 | 
  | 
           }; | 
| 1316 | 
  | 
           // | 
| 1317 | 
  | 
           // Get tracker related variables for this track | 
| 1318 | 
  | 
           // | 
| 1319 | 
  | 
           toftrk(); | 
| 1320 | 
  | 
           // | 
| 1321 | 
  | 
           // Copy values in the class from the structure (we need to use a temporary class to store variables). | 
| 1322 | 
  | 
           // | 
| 1323 | 
  | 
           t_tof->npmttdc = 0; | 
| 1324 | 
  | 
           for (Int_t hh=0; hh<12;hh++){ | 
| 1325 | 
  | 
             for (Int_t kk=0; kk<4;kk++){ | 
| 1326 | 
  | 
               if ( tofoutput_.tofmask[hh][kk] != 0 ){ | 
| 1327 | 
  | 
                 pmt_id = this->GetPMTid(kk,hh); | 
| 1328 | 
  | 
                 t_tof->pmttdc.AddAt(pmt_id,t_tof->npmttdc); | 
| 1329 | 
  | 
                 t_tof->tdcflag.AddAt(tofoutput_.tdcflag[hh][kk],t_tof->npmttdc); // gf: Jan 09/07 | 
| 1330 | 
  | 
                 t_tof->npmttdc++; | 
| 1331 | 
  | 
               }; | 
| 1332 | 
  | 
             }; | 
| 1333 | 
  | 
           }; | 
| 1334 | 
  | 
           for (Int_t kk=0; kk<13;kk++){ | 
| 1335 | 
  | 
             t_tof->beta[kk] = tofoutput_.beta_a[kk]; | 
| 1336 | 
  | 
           }; | 
| 1337 | 
  | 
           // | 
| 1338 | 
  | 
           t_tof->npmtadc = 0; | 
| 1339 | 
  | 
           for (Int_t hh=0; hh<12;hh++){ | 
| 1340 | 
  | 
             for (Int_t kk=0; kk<4;kk++){ | 
| 1341 | 
  | 
               if ( tofoutput_.adc_c[hh][kk] < 1000 ){ | 
| 1342 | 
  | 
                 t_tof->dedx.AddAt(tofoutput_.adc_c[hh][kk],t_tof->npmtadc); | 
| 1343 | 
  | 
                 pmt_id = this->GetPMTid(kk,hh); | 
| 1344 | 
  | 
                 t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc); | 
| 1345 | 
  | 
                 t_tof->adcflag.AddAt(tofoutput_.adcflag[hh][kk],t_tof->npmtadc); // gf: Jan 09/07 | 
| 1346 | 
  | 
                 t_tof->npmtadc++; | 
| 1347 | 
  | 
               }; | 
| 1348 | 
  | 
             }; | 
| 1349 | 
  | 
           }; | 
| 1350 | 
  | 
           // | 
| 1351 | 
  | 
           memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos)); | 
| 1352 | 
  | 
           memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos)); | 
| 1353 | 
  | 
           memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof)); | 
| 1354 | 
  | 
           memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof)); | 
| 1355 | 
  | 
           // | 
| 1356 | 
  | 
           // Store the tracker track number in order to be sure to have shyncronized data during analysis | 
| 1357 | 
  | 
           // | 
| 1358 | 
  | 
           t_tof->trkseqno = nt; | 
| 1359 | 
  | 
           // | 
| 1360 | 
  | 
           // create a new object for this event with track-related variables | 
| 1361 | 
  | 
           // | 
| 1362 | 
  | 
           new(t[ntrkentry]) ToFTrkVar(*t_tof); | 
| 1363 | 
  | 
           ntrkentry++; | 
| 1364 | 
  | 
           t_tof->Clear(); | 
| 1365 | 
  | 
           // | 
| 1366 | 
  | 
         }; // loop on all the tracks | 
| 1367 | 
  | 
       // | 
| 1368 | 
  | 
       this->unpackError = unpackError; | 
| 1369 | 
  | 
       if ( defcal ){ | 
| 1370 | 
  | 
         this->default_calib = 1; | 
| 1371 | 
  | 
       } else { | 
| 1372 | 
  | 
         this->default_calib = 0; | 
| 1373 | 
  | 
       }; | 
| 1374 | 
  | 
  }; | 
| 1375 | 
  | 
  | 
| 1376 | 
  | 
  | 
| 1377 | 
  | 
  | 
| 1378 | 
  | 
   return(0); | 
| 1379 | 
  | 
 } |