Changeset 7055


Ignore:
Timestamp:
05/18/05 17:54:27 (20 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r7054 r7055  
    4141   * mjobs/MJStar.cc:
    4242     - moved processing of CC-branch to the beginning of the tasklist
     43
     44   * msignal/MExtractTimeAndChargeSpline.[h,cc]:
     45     - introduced some small changes to the validity range of
     46       some variables
     47     - determin the higher bound above which no search is done
     48       analog to the lower bound using the fall-time
     49     - CalcIntegral[Hi,Lo]Gain now returns sum. No need for a reference
     50     - fixed calling Integral[HI,Lo]Gain in cases we are at the edge of
     51       the valid range -- at a lot of position in the code random memory
     52       above or below the arrays have been accessed.
     53     - improved the numercila stability of CalcIntegral[Hi,Lo]Gain
     54       more by calculating the number of steps from the rise and fall time.
     55       this should at least give consistent results on the same machine!
    4356
    4457
  • trunk/MagicSoft/Mars/NEWS

    r7047 r7055  
    7777       adding the step-size (which results in numerical uncertanties
    7878       exspecially if multiplied with large numbers)
     79     + A lot of fixes have been introduced which effects integrating the
     80       spline at the edges of the valid range. In this case any memory
     81       was randomly accessed.
     82     ! No result obtained with the Spline before can be trusted! Due to
     83       random memory access it might by completely random!
    7984
    8085   - callisto: set new defaults in MExtractTimeAndChargeDigitalFilter:
  • trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.cc

    r7043 r7055  
    432432        }
    433433    }
    434  
     434
    435435  fAbMax = fHiGainSignal[maxpos];
    436 
    437   Float_t pp;
    438436
    439437  fHiGainSecondDeriv[0] = 0.;
     
    442440  for (Int_t i=1;i<range-1;i++)
    443441    {
    444       pp = fHiGainSecondDeriv[i-1] + 4.;
     442      const Float_t pp = fHiGainSecondDeriv[i-1] + 4.;
    445443      fHiGainSecondDeriv[i] = -1.0/pp;
    446       fHiGainFirstDeriv [i] = fHiGainSignal[i+1] - fHiGainSignal[i] - fHiGainSignal[i] + fHiGainSignal[i-1];
     444      fHiGainFirstDeriv [i] = 2*(fHiGainSignal[i+1] - fHiGainSignal[i]);
    447445      fHiGainFirstDeriv [i] = (6.0*fHiGainFirstDeriv[i]-fHiGainFirstDeriv[i-1])/pp;
    448446    }
     
    474472        }
    475473      else
    476         {
    477           Float_t start = 2. + nsx;
    478           Float_t last  = start + fRiseTimeHiGain + fFallTimeHiGain;
    479      
    480           if (int(last) > range)
    481             {
    482               const Int_t diff = range - int(last);
    483               last  -= diff;
    484               start -= diff;
    485             }
    486          
    487           CalcIntegralHiGain(sum, start, last);
    488         }
     474          sum = CalcIntegralHiGain(2. + nsx, range);
     475
    489476      fRandomIter++;
    490477      return;
     
    492479
    493480  //
    494   // Allow no saturated slice
    495   // and
     481  // Allow no saturated slice and
    496482  // Don't start if the maxpos is too close to the limits.
    497483  //
    498   if (sat || maxpos < TMath::Ceil(fRiseTimeHiGain) || maxpos > range-2)
    499     {
    500 
     484  const Bool_t limlo = maxpos <       TMath::Ceil(fRiseTimeHiGain);
     485  const Bool_t limup = maxpos > range-TMath::Ceil(fFallTimeHiGain)-1;
     486  if (sat || limlo || limup)
     487    {
    501488      dtime = 1.0;
    502489      if (fExtractionType == kAmplitude)
     
    506493          return;
    507494        }
    508      
    509       if (maxpos > range - 2)
    510         CalcIntegralHiGain(sum, (Float_t)range - fRiseTimeHiGain - fFallTimeHiGain, (Float_t)range - 0.001);
    511       else
    512         CalcIntegralHiGain(sum, 0.001, fRiseTimeHiGain + fFallTimeHiGain);
    513 
    514       time =  (Float_t)(fHiGainFirst + maxpos - 1);
     495
     496      sum  = CalcIntegralHiGain(limlo ? 0 : range, range);
     497      time = (Float_t)(fHiGainFirst + maxpos - 1);
    515498      return;
    516499    }
     
    561544  if (fAbMaxPos > upper-0.1)
    562545    {
    563 
    564546      upper   = 1. + maxpos;
    565547      lower   = (Float_t)maxpos;
     
    678660  while (klo > 0)
    679661    {
    680       klo--;
    681       if (fHiGainSignal[klo] < fHalfMax)
     662      if (fHiGainSignal[--klo] < fHalfMax)
    682663        break;
    683664    }
     
    719700        + (b*b*b-b)*fHiGainSecondDeriv[khi];
    720701     
    721       if (y > fHalfMax)
    722         back = kTRUE;
    723       else
    724         back = kFALSE;
     702      back = y > fHalfMax;
    725703     
    726704      if (++cnt > maxcnt)
     
    730708    }
    731709 
    732   time  = (Float_t)fHiGainFirst + x;
    733710  //
    734711  // Now integrate the whole thing!
    735712  //
    736  
    737   Float_t start = fAbMaxPos - fRiseTimeHiGain;
    738   Float_t last  = fAbMaxPos + fFallTimeHiGain;
    739  
    740   const Int_t diff = int(last) - range;
    741  
    742   if (diff > 0)
    743     {
    744       last  -= diff;
    745       start -= diff;
    746     }
    747  
    748   CalcIntegralHiGain(sum, start, last);
     713  time = (Float_t)fHiGainFirst + x;
     714  sum  = CalcIntegralHiGain(fAbMaxPos - fRiseTimeHiGain, range);
    749715}
    750716
     
    795761  fAbMax = fLoGainSignal[maxpos];
    796762 
    797   Float_t pp;
    798 
    799763  fLoGainSecondDeriv[0] = 0.;
    800764  fLoGainFirstDeriv[0]  = 0.;
     
    802766  for (Int_t i=1;i<range-1;i++)
    803767    {
    804       pp = fLoGainSecondDeriv[i-1] + 4.;
     768      const Float_t pp = fLoGainSecondDeriv[i-1] + 4.;
    805769      fLoGainSecondDeriv[i] = -1.0/pp;
    806       fLoGainFirstDeriv [i] = fLoGainSignal[i+1] - fLoGainSignal[i] - fLoGainSignal[i] + fLoGainSignal[i-1];
     770      fLoGainFirstDeriv [i] = 2*(fLoGainSignal[i+1] - fLoGainSignal[i]);
    807771      fLoGainFirstDeriv [i] = (6.0*fLoGainFirstDeriv[i]-fLoGainFirstDeriv[i-1])/pp;
    808772    }
     
    833797        }
    834798      else
    835         {
    836           Float_t start = 2. + nsx;
    837           Float_t last  = start + fRiseTimeLoGain + fFallTimeLoGain;
    838      
    839           if (int(last) > range)
    840             {
    841               const Int_t diff = range - int(last);
    842               last  -= diff;
    843               start -= diff;
    844             }
    845          
    846           CalcIntegralLoGain(sum, start, last);
    847         }
     799          sum = CalcIntegralLoGain(2. + nsx, range);
     800
    848801      fRandomIter++;
    849802      return;
    850803    }
    851804  //
    852   // Allow no saturated slice
    853   // and
     805  // Allow no saturated slice and
    854806  // Don't start if the maxpos is too close to the limits.
    855807  //
    856   if (sat || maxpos < TMath::Ceil(fRiseTimeLoGain) || maxpos > range-2)
    857     {
    858 
     808  const Bool_t limlo = maxpos <       TMath::Ceil(fRiseTimeLoGain);
     809  const Bool_t limup = maxpos > range-TMath::Ceil(fFallTimeLoGain)-1;
     810  if (sat || limlo || limup)
     811    {
    859812      dtime = 1.0;
    860813      if (fExtractionType == kAmplitude)
     
    864817          return;
    865818        }
    866      
    867       if (maxpos > range-2)
    868         CalcIntegralLoGain(sum, (Float_t)range - fRiseTimeLoGain - fFallTimeLoGain -1., (Float_t)range - 0.001);
    869       else
    870         CalcIntegralLoGain(sum, 0.001, fRiseTimeLoGain + fFallTimeLoGain + 1.);
    871 
     819
     820      sum  = CalcIntegralLoGain(limlo ? 0 : range, range);
    872821      time = (Float_t)(fLoGainFirst + maxpos - 1);
    873822      return;
     
    10801029        + (b*b*b-b)*fLoGainSecondDeriv[khi];
    10811030     
    1082       if (y > fHalfMax)
    1083         back = kTRUE;
    1084       else
    1085         back = kFALSE;
     1031      back = y > fHalfMax;
    10861032     
    10871033      if (++cnt > maxcnt)
     
    10911037    }
    10921038 
    1093   time  = x + (Int_t)fLoGainFirst;
    1094 
    10951039  //
    10961040  // Now integrate the whole thing!
    10971041  //
    1098   Float_t start = fAbMaxPos - fRiseTimeLoGain;
    1099   Float_t last  = fAbMaxPos + fFallTimeLoGain;
    1100  
    1101   const Int_t diff = int(last) - range;
    1102  
    1103   if (diff > 0)
    1104     {
    1105       last  -= diff;
    1106       start -= diff;
    1107     }
    1108   CalcIntegralLoGain(sum, start, last);
     1042  time = x + (Int_t)fLoGainFirst;
     1043  sum  = CalcIntegralLoGain(fAbMaxPos - fRiseTimeLoGain, range);
    11091044}
    11101045
    1111 void MExtractTimeAndChargeSpline::CalcIntegralHiGain(Float_t &sum, Float_t start, Float_t last)
     1046Float_t MExtractTimeAndChargeSpline::CalcIntegralHiGain(Float_t start, Float_t range) const
    11121047{
    1113     const Float_t step = 0.2;
    1114 
     1048    // The number of steps is calculated directly from the integration
     1049    // window. This is the only way to ensure we are not dealing with
     1050    // numerical rounding uncertanties, because we always get the same
     1051    // value under the same conditions -- it might still be different on
     1052    // other machines!
     1053    const Float_t step  = 0.2;
     1054    const Float_t width = fRiseTimeHiGain+fFallTimeHiGain;
     1055    const Float_t max   = range-1 - (width+step);
     1056    const Int_t   num   = TMath::Nint(width/step);
     1057
     1058    // The order is important. In some cases (limlo-/limup-check) it can
     1059    // happen than max<0. In this case we start at 0
     1060    if (start > max)
     1061        start = max;
    11151062    if (start < 0)
    1116     {
    1117         last -= start;
    1118         start = 0.;
    1119     }
    1120 
    1121     const Int_t n = TMath::Nint((last-start)/step);
     1063        start = 0;
    11221064
    11231065    start += step/2;
    11241066
    1125     sum = 0.;
    1126     for (Int_t i=0; i<n; i++)
     1067    Double_t sum = 0.;
     1068    for (Int_t i=0; i<num; i++)
    11271069    {
    11281070        const Float_t x = start+i*step;
     
    11491091    }
    11501092    sum *= step; // Transform sum in integral
     1093    return sum;
    11511094}
    11521095
    1153 void MExtractTimeAndChargeSpline::CalcIntegralLoGain(Float_t &sum, Float_t start, Float_t last)
     1096Float_t MExtractTimeAndChargeSpline::CalcIntegralLoGain(Float_t start, Float_t range) const
    11541097{
    1155     const Float_t step = 0.2;
    1156 
     1098    // The number of steps is calculated directly from the integration
     1099    // window. This is the only way to ensure we are not dealing with
     1100    // numerical rounding uncertanties, because we always get the same
     1101    // value under the same conditions -- it might still be different on
     1102    // other machines!
     1103    const Int_t   cnt   = 5;
     1104    const Float_t width = fRiseTimeLoGain+fFallTimeLoGain;
     1105    const Float_t max   = range-1 - (width+step);
     1106    const Int_t   num   = TMath::Nint(width/step);
     1107
     1108    // The order is important. In some cases (limlo-/limup-check) it can
     1109    // happen than max<0. In this case we start at 0
     1110    if (start > max)
     1111        start = max;
    11571112    if (start < 0)
    1158     {
    1159         last -= start;
    1160         start = 0.;
    1161     }
    1162 
    1163     const Int_t n = TMath::Nint((last-start)/step);
     1113        start = 0;
    11641114
    11651115    start += step/2;
    11661116
    1167     sum = 0.;
    1168     for (Int_t i=0; i<n; i++)
     1117    Double_t sum = 0.;
     1118    for (Int_t i=0; i<num; i++)
    11691119    {
    11701120        const Float_t x = start+i*step;
     
    11911141    }
    11921142    sum *= step; // Transform sum in integral
     1143    return sum;
    11931144}
    11941145
  • trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.h

    r6840 r7055  
    66#endif
    77
    8 #ifndef MARS_MArrayF
    9 #include "MArrayF.h"
     8#ifndef ROOT_TArrayF
     9#include "TArrayF.h"
    1010#endif
    1111
     
    2727  static const Float_t fgLoGainStartShift; //! Default for fLoGainStartShift (now set to -1.6)
    2828 
    29   MArrayF fHiGainSignal;                //! Need fast access to the signals in a float way
    30   MArrayF fLoGainSignal;                //! Store them in separate arrays
    31   MArrayF fHiGainFirstDeriv;            //! High-gain discretized first derivatives
    32   MArrayF fLoGainFirstDeriv;            //! Low-gain discretized first derivatives
    33   MArrayF fHiGainSecondDeriv;           //! High-gain discretized second derivatives
    34   MArrayF fLoGainSecondDeriv;           //! Low-gain discretized second derivatives
     29  TArrayF fHiGainSignal;                //! Need fast access to the signals in a float way
     30  TArrayF fLoGainSignal;                //! Store them in separate arrays
     31  TArrayF fHiGainFirstDeriv;            //! High-gain discretized first derivatives
     32  TArrayF fLoGainFirstDeriv;            //! Low-gain discretized first derivatives
     33  TArrayF fHiGainSecondDeriv;           //! High-gain discretized second derivatives
     34  TArrayF fLoGainSecondDeriv;           //! Low-gain discretized second derivatives
    3535
    3636  Float_t fAbMax;                       //! Current maximum of the spline
     
    5353  Bool_t  InitArrays();
    5454 
    55   void CalcIntegralHiGain(Float_t &sum, Float_t start, Float_t last);
    56   void CalcIntegralLoGain(Float_t &sum, Float_t start, Float_t last);
     55  Float_t CalcIntegralHiGain(Float_t start, Float_t range) const;
     56  Float_t CalcIntegralLoGain(Float_t start, Float_t range) const;
    5757
    5858public: 
Note: See TracChangeset for help on using the changeset viewer.