Changeset 3056 for trunk


Ignore:
Timestamp:
02/08/04 20:52:18 (21 years ago)
Author:
gaug
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r3055 r3056  
    3333     - check for oscillations for all pixels (and you will not trust
    3434       your eyes when you look at the results :-((((
     35
     36   * mcalib/MCalibrationCalc.[h,cc]
     37     - remove ArrivalTime -> go to separate class
     38     - remove BlidnPixel and PI Didoe overflow, now handled directly
     39       inside the corr. classes.
     40     - remove SkipTimeFits -> go the arrival time class
    3541
    3642
  • trunk/MagicSoft/Mars/mcalib/MCalibrationCalc.h

    r3029 r3056  
    3131class MCalibrationCam;
    3232class MExtractedSignalCam;
    33 class MArrivalTime;
    3433
    3534class MTime;
     
    3938private:
    4039
    41   static const Int_t fBlindPixelId;         // ID of the blind pixel
    42   static const Int_t fPINDiodeId;           // ID of the PIN Diode
     40  static const UInt_t fBlindPixelId;        // ID of the blind pixel
     41  static const UInt_t fPINDiodeId;          // ID of the PIN Diode
    4342  static const Byte_t fgSaturationLimit;    // Saturation of Hi Gain
    4443  static const Byte_t fgBlindPixelFirst;    // First FADC slice blind pixel
     
    5251  MRawRunHeader            *fRunHeader;    // RunHeader information
    5352
    54   MArrivalTime             *fArrivalTime;  // Calculated Arrival Times
    55  
    5653  MTime                    *fEvtTime;      // Time of the event
    5754
     
    6966  UInt_t  fNumExcludedPixels;
    7067
    71   enum  { kUseTimes, kUseBlindPixelFit, kUsePinDiodeFit,
     68  enum  { kUseBlindPixelFit, kUsePinDiodeFit,
    7269          kUseCosmicsRejection, kUseQualityChecks,
    7370          kHiLoGainCalibration,
    74           kBlindPixelOverFlow, kPINDiodeOverFlow,
    7571          kHiGainOverFlow, kLoGainOverFlow  };
    7672
     
    9692  void Clear(const Option_t *o="");
    9793 
    98   // Skipping parts of the work
    99   void SkipTime(Bool_t b=kTRUE)
    100       {b ? CLRBIT(fFlags, kUseTimes) : SETBIT(fFlags, kUseTimes);}
    10194  void SkipBlindPixelFit(Bool_t b=kTRUE)
    10295      {b ? CLRBIT(fFlags, kUseBlindPixelFit) : SETBIT(fFlags, kUseBlindPixelFit);}
  • trunk/MagicSoft/Mars/mcalib/MCalibrationPINDiode.cc

    r3007 r3056  
    8888  fPed                              =  -1.;
    8989  fPedRms                           =  -1.;
    90   fTime                             =  -1.;
    91   fSigmaTime                        =  -1.;
    92   fTimeChiSquare                    =  -1.;
    93 
    9490}
    9591
     
    271267}
    272268
    273 
    274 // --------------------------------------------------------------------------
    275 //
    276 // 1) Fit the arrival times
    277 // 2) Retrieve the results
    278 // 3) Note that because of the low number of bins, the NDf is sometimes 0, so
    279 //    Root does not give a reasonable Probability, the Chisquare is more significant
    280 //
    281 Bool_t MCalibrationPINDiode::FitTime()
    282 {
    283 
    284   if(!fHist->FitTime())
    285     {
    286       *fLog << warn << "WARNING: Could not fit Hi Gain times of PIN Diode" << endl;
    287       fHist->PrintTimeFitResult();
    288       return kFALSE;
    289     }
    290  
    291   fTime          = fHist->GetRelTimeMean();
    292   fSigmaTime     = fHist->GetRelTimeSigma();
    293   fTimeProb      = fHist->GetRelTimeProb();
    294  
    295   if (CheckTimeFitValidity())
    296     SETBIT(fFlags,kTimeFitValid);
    297   else
    298     CLRBIT(fFlags,kTimeFitValid);
    299 
    300   return kTRUE;
    301 }
    302 
    303269//
    304270// The check returns kTRUE if:
  • trunk/MagicSoft/Mars/mcalib/MCalibrationPINDiode.h

    r3007 r3056  
    2626  Float_t fChargeProb;            // The probability of the fit function
    2727
    28   Float_t fTime;                  // The mean arrival time after the fit 
    29   Float_t fSigmaTime;             // The error of the mean arrival time after the fit
    30   Float_t fTimeChiSquare;         // The Chi Square of the fit function
    31   Float_t fTimeProb;              // The probability of the fit function
    32  
    3328  Byte_t  fFlags;                 // Flag for the set Bits
    3429
     
    5853  Float_t GetRSigmaSquare()        const { return fRSigmaSquare;   }
    5954
    60   // Times 
    61   Float_t GetTime()                const { return fTime;           }
    62   Float_t GetSigmaTime()           const { return fSigmaTime;      }
    63   Float_t GetTimeChiSquare()       const { return fTimeChiSquare;  }
    64   Float_t GetTimeProb()            const { return fTimeProb;  }     
    6555
    6656  // Pedestals
     
    8474  Bool_t FillCharge(Float_t q)      { return fHist->FillChargeHiGain(q); }
    8575  Bool_t FillAbsTime(Float_t t)     { return fHist->FillAbsTimeHiGain(t); }
    86   Bool_t FillRelTime(Float_t t)     { return fHist->FillRelTimeHiGain(t); }
    87   Bool_t FillRChargevsTime(Float_t rq, Int_t t) { return fHist->FillChargevsNHiGain(rq,t); }   
    8876
     77  Bool_t FillGraphs(Float_t qhi,Float_t qlo) const { return fHist->FillGraphs(qhi,qlo); } 
     78 
    8979  // Fits
    9080  Bool_t FitCharge();
    91   Bool_t FitTime();
    9281
    9382  // Draws
  • trunk/MagicSoft/Mars/mcalib/MCalibrationPix.cc

    r3028 r3056  
    106106  CLRBIT(fFlags, kHiGainSaturation);
    107107  CLRBIT(fFlags, kExcluded);
     108  CLRBIT(fFlags, kExcludeQualityCheck);
    108109  CLRBIT(fFlags, kChargeFitValid);
    109   CLRBIT(fFlags, kTimeFitValid);
    110110  CLRBIT(fFlags, kFitted);
     111  CLRBIT(fFlags, kOscillating);
    111112  CLRBIT(fFlags, kBlindPixelMethodValid);
    112113  CLRBIT(fFlags, kFFactorMethodValid);
     
    128129  fNumLoGainSamples                 =  -1.;
    129130
    130   fMeanTimeOffset                   =  -1.;
    131   fMeanTimeOffsetError              =  -1.;
    132   fTimingPrecision                  =  -1.;
    133   fTimeProb                         =  -1.;
    134131  fTimeFirstHiGain                  =   0 ;
    135132  fTimeLastHiGain                   =   0 ;
     
    270267// Set the Excluded Bit from outside
    271268//
    272 void MCalibrationPix::SetTimeFitValid(Bool_t b )   
    273 {
    274   b ?  SETBIT(fFlags, kTimeFitValid) : CLRBIT(fFlags, kTimeFitValid);
    275 }
    276 
     269void MCalibrationPix::SetFitted(Bool_t b )
     270{
     271  b ?  SETBIT(fFlags, kFitted) : CLRBIT(fFlags, kFitted);
     272}
     273   
    277274// --------------------------------------------------------------------------
    278275//
    279276// Set the Excluded Bit from outside
    280277//
    281 void MCalibrationPix::SetFitted(Bool_t b )
    282 {
    283   b ?  SETBIT(fFlags, kFitted) : CLRBIT(fFlags, kFitted);
     278void MCalibrationPix::SetOscillating(Bool_t b )
     279{
     280  b ?  SETBIT(fFlags, kOscillating) : CLRBIT(fFlags, kOscillating);
    284281}
    285282   
     
    348345
    349346
    350 Float_t MCalibrationPix::GetTotalFFactor()
     347Float_t MCalibrationPix::GetTotalFFactorFFactorMethod()
    351348{
    352349  if (!fFactorCalculated)
     
    356353}
    357354
    358 Float_t MCalibrationPix::GetTotalFFactorError()
     355Float_t MCalibrationPix::GetTotalFFactorErrorFFactorMethod()
    359356{
    360357
     
    373370
    374371
     372Float_t MCalibrationPix::GetTotalFFactorBlindPixelMethod()
     373{
     374  return 1.;
     375}
     376
     377Float_t MCalibrationPix::GetTotalFFactorErrorBlindPixelMethod()
     378{
     379
     380  return 1.;
     381}
     382
     383Float_t MCalibrationPix::GetTotalFFactorPINDiodeMethod()
     384{
     385  return 1.;
     386}
     387
     388Float_t MCalibrationPix::GetTotalFFactorErrorPINDiodeMethod()
     389{
     390
     391  return 1.;
     392}
     393
     394
     395
    375396Float_t MCalibrationPix::GetMeanConversionFFactorMethod()
    376397{
     
    401422  return fSigmaConversionFFactorMethod;
    402423 
    403 }
    404 
    405 
    406 Float_t MCalibrationPix::GetTimingPrecisionError() const
    407 {
    408   return fMeanTimeOffsetError/2.;
    409424}
    410425
     
    415430 }
    416431
     432Bool_t MCalibrationPix::IsExcludeQualityCheck() const
     433 {
     434   return TESTBIT(fFlags,kExcludeQualityCheck); 
     435 }
     436
     437Bool_t MCalibrationPix::IsHiGainSaturation() const
     438 {
     439   return TESTBIT(fFlags,kHiGainSaturation); 
     440 }
     441
    417442Bool_t MCalibrationPix::IsChargeFitValid() const
    418443{
     
    420445}
    421446
    422 Bool_t MCalibrationPix::IsTimeFitValid() const
    423 {
    424   return TESTBIT(fFlags, kTimeFitValid); 
    425 }
    426 
    427447Bool_t MCalibrationPix::IsFitted() const
    428448{
    429449  return TESTBIT(fFlags, kFitted);   
     450}
     451
     452Bool_t MCalibrationPix::IsOscillating()
     453{
     454
     455  if (TESTBIT(fFlags, kOscillating))
     456    return kTRUE;
     457
     458  if (fHist->CheckOscillations())
     459    {
     460      SETBIT(fFlags,kOscillating);
     461      return kTRUE;
     462    }
     463 
     464  return kFALSE;
    430465}
    431466
     
    530565  fChargeProb     = fHist->GetChargeProb();
    531566
     567
     568  fAbsTimeMean    = fHist->GetAbsTimeMean();
     569  fAbsTimeMeanErr = fHist->GetAbsTimeMeanErr();
     570  fAbsTimeRms     = fHist->GetAbsTimeRms(); 
     571
     572  if (CheckTimeFitValidity())
     573    SETBIT(fFlags,kTimeFitValid);
     574  else
     575    CLRBIT(fFlags,kTimeFitValid);
     576
    532577  //
    533578  // Calculate the conversion factors
    534579  //
    535   if (TESTBIT(fFlags,kHiGainSaturation))
     580  if (IsHiGainSaturation())
    536581    ApplyLoGainConversion();
    537582
     
    585630  Float_t pedRmsSquareErrSquare           = 4.*fErrPedRms*fErrPedRms * pedRmsSquare;
    586631 
    587   if (!TESTBIT(fFlags,kHiGainSaturation))
     632  if (!IsHiGainSaturation())
    588633    {  /* HiGain */
    589634
     
    683728  fFactorCalculated = kTRUE;
    684729
    685   fSigmaConversionFFactorMethod = GetTotalFFactor()*TMath::Sqrt(fMeanConversionFFactorMethod);
     730  fSigmaConversionFFactorMethod = GetTotalFFactorFFactorMethod()*TMath::Sqrt(fMeanConversionFFactorMethod);
    686731
    687732  return kTRUE;
     
    706751{
    707752
    708   if (!TESTBIT(fFlags,kFitted))
     753  if (!IsFitted())
    709754    return kFALSE;
    710755
    711   if (TESTBIT(fFlags,kExcludeQualityCheck))
     756  if (IsExcludeQualityCheck())
    712757    return kTRUE;
    713758
    714759  Float_t pedestal;
    715760
    716   if (!TESTBIT(fFlags,kHiGainSaturation))  /* higain */
     761  if (!IsHiGainSaturation())  /* higain */
    717762    pedestal = GetPedRms()*TMath::Sqrt(fNumHiGainSamples);
    718   else                                     /*  logain */
     763  else                         /*  logain */
    719764    pedestal = GetPedRms()*TMath::Sqrt(fNumLoGainSamples);
    720765     
     
    769814{
    770815
    771   if (TMath::IsNaN(fMeanTimeOffset)
    772       || TMath::IsNaN(fMeanTimeOffsetError)
    773       || TMath::IsNaN(fTimingPrecision)
    774       || TMath::IsNaN(fTimeProb))
    775     {
    776       *fLog << warn << "WARNING: Some of the time fit values are NAN in Pixel "
    777             << fPixId << endl;
    778       return kFALSE;
    779     }
    780  
    781   if (TESTBIT(fFlags,kExcludeQualityCheck))
     816 
     817  if (IsExcludeQualityCheck())
    782818    return kTRUE;
    783819
    784   if (TMath::Abs(fMeanTimeOffset) > gkTimeLimit)
    785     {
    786       *fLog << warn << "WARNING: Abs(Fitted Rel. Time) " << TMath::Abs(fMeanTimeOffset)
    787             << " is greater than " << gkTimeLimit << " in Pixel " << fPixId << endl;
    788       return kFALSE;
    789     }
    790 
    791   if (fMeanTimeOffsetError > gkTimeErrLimit)
    792     {
    793       *fLog << warn << "WARNING: Error of Fitted Time " << fMeanTimeOffsetError
    794             << " is smaller than " << gkTimeErrLimit << " in Pixel " << fPixId << endl;
    795       return kFALSE;
    796     }
    797 
    798   if (!fHist->IsTimeFitOK())
    799     {
    800       *fLog << warn << "WARNING: Probability of Fitted Time too low in Pixel "
    801             << fPixId << endl;
    802       return kFALSE;
    803     }
    804 
    805   if (TESTBIT(fFlags,kHiGainSaturation))
     820  if (IsHiGainSaturation())
    806821    {
    807822
     
    854869
    855870
    856 //
    857 // The check returns kTRUE if:
    858 //
    859 //
    860 //
    861 Bool_t MCalibrationPix::CheckOscillations()
    862 {
    863   return kTRUE;
     871void MCalibrationPix::CheckOscillations()
     872{
     873  fHist->CheckOscillations();
    864874}
    865875
     
    882892}
    883893
    884 
    885 
    886 // --------------------------------------------------------------------------
    887 //
    888 // 1) Fit the arrival times
    889 // 2) Retrieve the results
    890 //
    891 // This fit has to be done AFTER the Charges fit,
    892 // otherwise only the Hi Gain will be fitted, even if there are no entries
    893 //
    894 //
    895 Bool_t MCalibrationPix::FitTime()
    896 {
    897 
    898 
    899   if(!fHist->FitTime())
    900     {
    901       *fLog << warn << "WARNING: Could not fit relative times of pixel " << fPixId << endl;
    902       return kFALSE;
    903     }
    904  
    905   fMeanTimeOffset      = fHist->GetRelTimeMean();
    906   fMeanTimeOffsetError = fHist->GetRelTimeMeanErr();
    907   fTimingPrecision     = fHist->GetRelTimeSigma();
    908   fTimeProb            = fHist->GetRelTimeProb();
    909 
    910   fAbsTimeMean    = fHist->GetAbsTimeMean();
    911   fAbsTimeMeanErr = fHist->GetAbsTimeMeanErr();
    912   fAbsTimeRms     = fHist->GetAbsTimeRms(); 
    913 
    914   if (CheckTimeFitValidity())
    915     SETBIT(fFlags,kTimeFitValid);
    916   else
    917     CLRBIT(fFlags,kTimeFitValid);
    918 
    919   return kTRUE;
    920 }
    921 
  • trunk/MagicSoft/Mars/mcalib/MCalibrationPix.h

    r3027 r3056  
    4040  Float_t fErrPedRms;           // The error of the pedestal  RMS (from MPedestalPix) 
    4141
    42   Float_t fMeanTimeOffset;      // The mean relative arrival time offset after the fit
    43   Float_t fMeanTimeOffsetError; // The mean relative arrival time offset error after the fit   
    44   Float_t fTimingPrecision;     // The error of the mean arrival time after the fit
    45   Float_t fTimeProb;            // The probability of the fit function
    46 
    4742  Float_t fAbsTimeMean;
    4843  Float_t fAbsTimeMeanErr; 
     
    8479          kExcluded, kExcludeQualityCheck,
    8580          kChargeFitValid, kTimeFitValid,
    86           kFitted,
     81          kFitted, kOscillating,
    8782          kBlindPixelMethodValid, kFFactorMethodValid, kPINDiodeMethodValid };
    8883 
     
    9186  Bool_t CheckChargeFitValidity();
    9287  Bool_t CheckTimeFitValidity();
    93   Bool_t CheckOscillations(); 
    94 
    9588  Bool_t CalcFFactorMethod();
    9689 
     
    114107  Float_t GetErrRSigmaCharge()     const { return fErrRSigmaCharge; } 
    115108
    116   // Times 
    117   Float_t GetMeanTimeOffset()       const { return fMeanTimeOffset;      }
    118   Float_t GetMeanTimeOffsetError()  const { return fMeanTimeOffsetError; } 
    119   Float_t GetTimingPrecision()      const { return fTimingPrecision;     }
    120   Float_t GetTimingPrecisionError() const;
    121   Float_t GetTimeProb()             const { return fTimeProb;            }     
    122109
    123110  Float_t GetAbsTimeMean()         const { return fAbsTimeMean;    }
     
    149136  Float_t GetPedRms()                          const { return fPedRms; }
    150137
    151   Float_t GetTotalFFactor();
    152   Float_t GetTotalFFactorError();
     138  Float_t GetTotalFFactorFFactorMethod();
     139  Float_t GetTotalFFactorErrorFFactorMethod();
     140 
     141  Float_t GetTotalFFactorBlindPixelMethod();
     142  Float_t GetTotalFFactorErrorBlindPixelMethod();
     143 
     144  Float_t GetTotalFFactorPINDiodeMethod();
     145  Float_t GetTotalFFactorErrorPINDiodeMethod();
    153146 
    154147  Bool_t IsExcluded()              const;
     148  Bool_t IsExcludeQualityCheck()   const;
     149  Bool_t IsHiGainSaturation()      const;
    155150  Bool_t IsChargeFitValid()        const;
    156   Bool_t IsTimeFitValid()          const;
    157151  Bool_t IsFitted()                const;
     152  Bool_t IsOscillating();
    158153  Bool_t IsBlindPixelMethodValid() const;
    159154  Bool_t IsPINDiodeMethodValid()   const;
     
    175170  void SetExcludeQualityCheck(Bool_t b = kTRUE);
    176171  void SetChargeFitValid(Bool_t b = kTRUE);
    177   void SetTimeFitValid(Bool_t b = kTRUE);
    178172  void SetFitted(Bool_t b = kTRUE);
     173  void SetOscillating(Bool_t b = kTRUE);
    179174  void SetBlindPixelMethodValid(Bool_t b = kTRUE);
    180175  void SetFFactorMethodValid(Bool_t b = kTRUE);
     
    184179 
    185180  // Fill histos
    186   Bool_t FillChargeHiGain(Float_t q)                  const { return fHist->FillChargeHiGain(q); }
    187   Bool_t FillAbsTimeHiGain(Float_t t)                 const { return fHist->FillAbsTimeHiGain(t); }
    188   Bool_t FillRelTimeHiGain(Float_t t)                 const { return fHist->FillRelTimeHiGain(t); } 
    189   Bool_t FillRChargevsTimeHiGain(Float_t rq, Int_t t) const { return fHist->FillChargevsNHiGain(rq,t); }   
    190 
    191   Bool_t FillChargeLoGain(Float_t q)                  const { return fHist->FillChargeLoGain(q); }
    192   Bool_t FillAbsTimeLoGain(Float_t t)                 const { return fHist->FillAbsTimeLoGain(t); }
    193   Bool_t FillRelTimeLoGain(Float_t t)                 const { return fHist->FillRelTimeLoGain(t); }   
    194   Bool_t FillRChargevsTimeLoGain(Float_t rq, Int_t t) const { return fHist->FillChargevsNLoGain(rq,t); }   
    195  
    196   Bool_t FillChargesInGraph(Float_t qhi,Float_t qlo) const  { return fHist->FillPointInGraph(qhi,qlo); }
     181  Bool_t FillChargeHiGain(Float_t q)         const { return fHist->FillChargeHiGain(q); }
     182  Bool_t FillAbsTimeHiGain(Float_t t)        const { return fHist->FillAbsTimeHiGain(t); }
     183
     184  Bool_t FillChargeLoGain(Float_t q)         const { return fHist->FillChargeLoGain(q); }
     185  Bool_t FillAbsTimeLoGain(Float_t t)        const { return fHist->FillAbsTimeLoGain(t); }
     186
     187  Bool_t FillGraphs(Float_t qhi,Float_t qlo) const { return fHist->FillGraphs(qhi,qlo); }
    197188
    198189  void   DefinePixId(Int_t i);
     
    200191  // Fits
    201192  Bool_t FitCharge();
    202   Bool_t FitTime();
    203193 
    204194  // Draws
     
    207197 
    208198  // Miscellaneous
    209   void   ApplyLoGainConversion();
     199  void  ApplyLoGainConversion();
     200  void  CheckOscillations(); 
    210201
    211202  ClassDef(MCalibrationPix, 1)  // Storage Container for Calibration information of one pixel
  • trunk/MagicSoft/Mars/mcalib/MHCalibrationPINDiode.cc

    r3007 r3056  
    4848MHCalibrationPINDiode::MHCalibrationPINDiode(const char *name, const char *title)
    4949    : fChargeNbins(1000),
    50       fTimeNbins(64),
    51       fChargevsNbins(10000),
    52       fTimeFirst(-0.25),
    53       fTimeLast(31.75)
     50      fChargevsNbins(10000)
    5451{
    5552
     
    6865    fHPINDiodeCharge->SetDirectory(NULL);
    6966
    70     fHPINDiodeTime = new TH1F("HPINDiodeTime","Distribution of Mean Arrival Times PINDiode",
    71                               fTimeNbins,fTimeFirst,fTimeLast);
    72     fHPINDiodeTime->SetXTitle("Mean Arrival Times [FADC slice nr]");
    73     fHPINDiodeTime->SetYTitle("Nr. of events");
    74     fHPINDiodeTime->Sumw2();
    75     fHPINDiodeTime->SetDirectory(NULL);
    76 
    7767    fHPINDiodeChargevsN = new TH1I("HPINDiodeChargevsN","Sum of Hi Gain Charges vs. Event Number Pixel ",
    7868                                 fChargevsNbins,-0.5,(Axis_t)fChargevsNbins - 0.5);
     
    8878
    8979  delete fHPINDiodeCharge;
    90   delete fHPINDiodeTime;
    9180  delete fHPINDiodeChargevsN;
    9281
    9382  if (fChargeGausFit)
    9483    delete fChargeGausFit;
    95   if (fRelTimeGausFit)
    96     delete fRelTimeGausFit;
    9784  if (fFitLegend)
    9885    delete fFitLegend;
     
    11097  fChargeProb              = -1.;
    11198  fChargeNdf               = -1;
    112   fRelTimeProb             = -1.;
    113   fRelTimeNdf              = -1;
    114   fRelTimeMean             = -1.;
    115   fRelTimeSigma            = -1.;
    116 
    117   fRelTimeLowerFitRangeHiGain = -99.;
    118   fRelTimeUpperFitRangeHiGain = -99.;
    119   fRelTimeLowerFitRangeLoGain = -99.;
    120   fRelTimeUpperFitRangeLoGain = -99.;
    12199
    122100  if (fChargeGausFit)
    123101    delete fChargeGausFit;
    124   if (fRelTimeGausFit)
    125     delete fRelTimeGausFit;
    126102  if (fFitLegend)
    127103    delete fFitLegend;
     
    137113
    138114  fHPINDiodeCharge->Reset();
    139   fHPINDiodeTime->Reset();
    140115  fHPINDiodeChargevsN->Reset();
    141116}
     
    145120{
    146121    return (fHPINDiodeCharge->Fill(q) > -1);
    147 }
    148 
    149 Bool_t MHCalibrationPINDiode::FillTime(Float_t t)
    150 {
    151     return (fHPINDiodeTime->Fill(t)   > -1);
    152122}
    153123
     
    160130{
    161131
    162   Int_t nbins = 30;
     132  Int_t nbins = 20;
    163133
    164134  CutEdges(fHPINDiodeCharge,nbins);
  • trunk/MagicSoft/Mars/mcalib/MHCalibrationPINDiode.h

    r2931 r3056  
    1717  TH1F* fHPINDiodeCharge;    // Histogram containing the summed 32 PINDiode slices
    1818  TH1F* fHPINDiodeErrCharge; // Variance of summed FADC slices
    19   TH1F* fHPINDiodeTime;      // Histogram with time evolution of summed charges
    2019 
    2120  TH1I* fHPINDiodeChargevsN; // Summed Charge vs. Event Nr.
    2221 
    2322  const Int_t   fChargeNbins;
    24   const Int_t   fTimeNbins;
    2523  const Int_t   fChargevsNbins;
    2624
     
    3836  // Fill histos
    3937  Bool_t FillCharge(Float_t q);
    40   Bool_t FillTime(Float_t t);
    4138  Bool_t FillChargevsN(Float_t q, Int_t n);
    4239
    4340  // Fits -- not yet implemented
    4441  Bool_t FitCharge(Option_t *option="RQ0") { return kTRUE; }
    45   Bool_t FitTime(Option_t *option="RQ0")   { return kTRUE; }
    4642
    4743  // Others
  • trunk/MagicSoft/Mars/mcalib/MHCalibrationPixel.cc

    r3051 r3056  
    4242#include <TPaveText.h>
    4343#include <TText.h>
     44#include <TGraph.h>
     45
     46#include "MFFT.h"
    4447
    4548#include "MLog.h"
     
    5255const Int_t   MHCalibrationPixel::fChargeNbinsHiGain = 2100;
    5356const Int_t   MHCalibrationPixel::fChargeNbinsLoGain = 1010;
    54 const Int_t   MHCalibrationPixel::fChargevsNbins     = 5000;
    55 const Int_t   MHCalibrationPixel::fAbsTimeNbins      = 32;
     57const Int_t   MHCalibrationPixel::fAbsTimeNbins      = 16;
    5658const Axis_t  MHCalibrationPixel::fAbsTimeFirst      = - 0.25;
    5759const Axis_t  MHCalibrationPixel::fAbsTimeLast       =  15.75;
    58 const Int_t   MHCalibrationPixel::fRelTimeNbins      = 900;
    59 const Axis_t  MHCalibrationPixel::fRelTimeFirst      = -13.;
    60 const Axis_t  MHCalibrationPixel::fRelTimeLast       =  13.;
    6160const Float_t MHCalibrationPixel::fProbLimit         = 0.001;
    6261const Int_t   MHCalibrationPixel::fNDFLimit          = 5;
    6362
     63const Axis_t  MHCalibrationPixel::fNyquistFreq       = 1.0;
     64const Axis_t  MHCalibrationPixel::fMinFreq           = 0.;
     65const Int_t   MHCalibrationPixel::fPSDNbins          = 30;
     66 
    6467// --------------------------------------------------------------------------
    6568//
     
    6972      : fPixId(-1),
    7073        fHivsLoGain(NULL),
     74        fPSDHiGain(NULL),
     75        fPSDLoGain(NULL),
     76        fChargeGausFit(NULL),
    7177        fHPSD(NULL),
    72         fChargeGausFit(NULL),
    73         fRelTimeGausFit(NULL),
    74         fFitLegend(NULL)
     78        fPSDExpFit(NULL),
     79        fChargeXaxis(NULL),
     80        fPSDXaxis(NULL),
     81        fFitLegend(NULL),
     82        fCurrentSize(1024)
    7583{
    7684
    7785    fName  = name  ? name  : "MHCalibrationPixel";
    78     fTitle = title ? title : "Fill the accumulated charges and times of all events and perform fits";
     86    fTitle = title ? title : "Fill the accumulated charges of all events and perform fits";
    7987
    8088    fChargeFirstHiGain = -100.5;
     
    110118    fHAbsTimeLoGain->SetYTitle("Nr. of events");
    111119
    112     // Relative Times
    113     fHRelTimeHiGain = new TH1F("HRelTimeHiGain","Distribution of Relative Arrival Times High Gain Pixel ",
    114                                fRelTimeNbins,fRelTimeFirst,fRelTimeLast);
    115     fHRelTimeLoGain = new TH1F("HRelTimeLoGain","Distribution of Relative Arrival Time Low Gain Pixel ",
    116                                fRelTimeNbins,fRelTimeFirst,fRelTimeLast);
    117 
    118     fHRelTimeHiGain->SetXTitle("Relative Arrival Times [Hi Gain FADC slice nr]");
    119     fHRelTimeLoGain->SetXTitle("Relative Arrival Times [Lo Gain FADC slice nr]");
    120 
    121     fHRelTimeHiGain->SetYTitle("Nr. of events");
    122     fHRelTimeLoGain->SetYTitle("Nr. of events");
    123 
    124     // We define a reasonable number and later enlarge it if necessary
    125     fHChargevsNHiGain = new TH1I("HChargevsNHiGain","Sum of Hi Gain Charges vs. Event Number Pixel ",
    126                                  fChargevsNbins,-0.5,(Axis_t)fChargevsNbins - 0.5);
    127     fHChargevsNLoGain = new TH1I("HChargevsNLoGain","Sum of Lo Gain Charges vs. Event Number Pixel ",
    128                                  fChargevsNbins,-0.5,(Axis_t)fChargevsNbins - 0.5);
    129 
    130     fHChargevsNHiGain->SetXTitle("Event Nr.");
    131     fHChargevsNLoGain->SetXTitle("Event Nr.");
    132 
    133     fHChargevsNHiGain->SetYTitle("Sum of Hi Gain FADC slices");
    134     fHChargevsNLoGain->SetYTitle("Sum of Lo Gain FADC slices");
    135120
    136121    fHChargeHiGain->SetDirectory(NULL);
     
    138123    fHAbsTimeHiGain->SetDirectory(NULL);
    139124    fHAbsTimeLoGain->SetDirectory(NULL);
    140     fHRelTimeHiGain->SetDirectory(NULL);
    141     fHRelTimeLoGain->SetDirectory(NULL);
    142     fHChargevsNHiGain->SetDirectory(NULL);
    143     fHChargevsNLoGain->SetDirectory(NULL);
    144 
    145     fHiGains = new TArrayF();
    146     fLoGains = new TArrayF();
     125
     126    fHiGains = new TArrayF(fCurrentSize);
     127    fLoGains = new TArrayF(fCurrentSize);
    147128
    148129    Clear();
     
    155136  delete fHChargeHiGain;
    156137  delete fHAbsTimeHiGain;
    157   delete fHRelTimeHiGain;
    158   delete fHChargevsNHiGain;
    159138
    160139  delete fHChargeLoGain;
    161140  delete fHAbsTimeLoGain;
    162   delete fHRelTimeLoGain;
    163   delete fHChargevsNLoGain;
    164141
    165142  delete fHiGains;
     
    168145  if (fChargeGausFit)
    169146    delete fChargeGausFit;
    170   if (fRelTimeGausFit)
    171     delete fRelTimeGausFit;
     147  if (fPSDExpFit)
     148    delete fPSDExpFit;
     149  if (fHPSD)
     150    delete fHPSD;
    172151  if (fFitLegend)
    173152    delete fFitLegend;
    174153  if (fHivsLoGain)
    175154    delete fHivsLoGain;
     155  if (fChargeXaxis)
     156    delete fChargeXaxis;
     157  if (fPSDXaxis)
     158    delete fPSDXaxis;
    176159}
    177160
     
    181164 
    182165  fTotalEntries            = 0;
     166  fCurrentSize             = 1024;
    183167
    184168  fChargeFirstHiGain       = -100.5;
     
    191175  fChargeNdf               = -1;
    192176
    193   fRelTimeChisquare        = -1.;
    194   fRelTimeProb             = -1.;
    195   fRelTimeNdf              = -1;
    196   fRelTimeMean             = -1.;
    197   fRelTimeSigma            = -1.;
    198 
    199   fRelTimeLowerFitRangeHiGain = -99.;
    200   fRelTimeUpperFitRangeHiGain = -99.;
    201   fRelTimeLowerFitRangeLoGain = -99.;
    202   fRelTimeUpperFitRangeLoGain = -99.;
    203 
    204177  fAbsTimeFirstHiGain     = -1.;
    205178  fAbsTimeFirstLoGain     = -1.;
     
    216189  if (fChargeGausFit)
    217190    delete fChargeGausFit;
    218   if (fRelTimeGausFit)
    219     delete fRelTimeGausFit;
     191  if (fPSDExpFit)
     192    delete fPSDExpFit;
     193  if (fHPSD)
     194    delete fHPSD;
    220195  if (fFitLegend)
    221196    delete fFitLegend;
    222197  if (fHivsLoGain)
    223198    delete fHivsLoGain;
    224   if (fHPSD)
    225     delete fHPSD;
     199  if (fChargeXaxis)
     200    delete fChargeXaxis;
     201  if (fPSDXaxis)
     202    delete fPSDXaxis;
     203  if (fPSDHiGain)
     204    delete fPSDHiGain;
     205  if (fPSDLoGain)
     206    delete fPSDLoGain;
    226207
    227208  CLRBIT(fFlags,kUseLoGain);
    228209  CLRBIT(fFlags,kChargeFitOK);
    229   CLRBIT(fFlags,kTimeFitOK);
     210  CLRBIT(fFlags,kOscillating);
    230211
    231212  return;
     
    240221  fHChargeHiGain->Reset();
    241222  fHChargeLoGain->Reset();
     223
    242224  fHAbsTimeHiGain->Reset();
    243225  fHAbsTimeLoGain->Reset();
    244   fHRelTimeHiGain->Reset();
    245   fHRelTimeLoGain->Reset();
    246   fHChargevsNHiGain->Reset();
    247   fHChargevsNLoGain->Reset();
    248 
    249   fHiGains->Reset();
    250   fLoGains->Reset();
     226
     227  fHiGains->Set(1024);
     228  fLoGains->Set(1024);
     229
     230  fHiGains->Reset(0.);
     231  fLoGains->Reset(0.);
    251232
    252233}
     
    261242
    262243
     244Bool_t MHCalibrationPixel::CheckOscillations()
     245{
     246
     247  if (fPSDExpFit)
     248    return IsOscillating();
     249
     250  MFFT fourier;
     251
     252  fPSDLoGain = fourier.PowerSpectrumDensity(fLoGains);
     253  fPSDHiGain = fourier.PowerSpectrumDensity(fHiGains);
     254
     255  Int_t entries;
     256  TArrayF *array;
     257 
     258  if (IsUseLoGain())
     259    {
     260      fHPSD = new TH1F(Form("%s%d","HPSD",fPixId),
     261                       Form("%s%s","Power Spectrum Density Projection ","LoGain"),
     262                       fPSDNbins,fMinFreq,fNyquistFreq);
     263     
     264      array = fPSDLoGain;
     265    }
     266  else
     267    {
     268
     269      fHPSD = new TH1F(Form("%s%d","HPSD",fPixId),
     270                       Form("%s%s","Power Spectrum Density Projection ","HiGain"),
     271                       fPSDNbins,fMinFreq,fNyquistFreq);
     272     
     273      array = fPSDLoGain;
     274    }
     275 
     276  entries = array->GetSize();
     277 
     278  for (Int_t i=0;i<entries;i++)
     279    fHPSD->Fill(array->At(i));
     280
     281  //
     282  // First guesses for the fit (should be as close to reality as possible,
     283  //
     284  const Double_t area_guess  = entries*10.;
     285
     286  fPSDExpFit = new TF1(Form("%s%d","PSDExpFit",fPixId),"[0]*exp(-[1]*x)",0.,1.);
     287
     288  fPSDExpFit->SetParameters(entries,10.);
     289  fPSDExpFit->SetParNames("Area","slope");
     290  fPSDExpFit->SetParLimits(0,0.,3.*area_guess);
     291  fPSDExpFit->SetParLimits(1,5.,20.);
     292  fPSDExpFit->SetRange(fMinFreq,fNyquistFreq);
     293
     294  fHPSD->Fit(fPSDExpFit,"RQL0");
     295 
     296  fPSDProb  = fPSDExpFit->GetProb();
     297
     298  if (fPSDProb < gkProbLimit)
     299    {
     300      SETBIT(fFlags,kOscillating);
     301      return kTRUE;
     302    }
     303 
     304  CLRBIT(fFlags,kOscillating);
     305
     306  return kFALSE;
     307}
     308
     309void MHCalibrationPixel::CreatePSDXaxis(Int_t n)
     310{
     311 
     312  if (fPSDXaxis)
     313    return;
     314
     315  fPSDXaxis = new TArrayF(n);
     316
     317  for (Int_t i=0;i<n;i++)
     318    fPSDXaxis->AddAt((Float_t)i,i);
     319}
     320
     321void MHCalibrationPixel::CreateChargeXaxis(Int_t n)
     322{
     323 
     324  if (!fChargeXaxis)
     325    {
     326      fChargeXaxis = new TArrayF(n);
     327      for (Int_t i=0;i<n;i++)
     328        fChargeXaxis->AddAt((Float_t)i,i);
     329      return;
     330    }
     331
     332  if (fChargeXaxis->GetSize() == n)
     333    return;
     334
     335  const Int_t diff = fChargeXaxis->GetSize()-n;
     336  fChargeXaxis->Set(n);
     337  if (diff < 0)
     338    for (Int_t i=n;i<n+diff;i++)
     339      fChargeXaxis->AddAt((Float_t)i,i);
     340}
     341
     342void MHCalibrationPixel::CutArrayBorder(TArrayF *array)
     343{
     344 
     345  Int_t i;
     346
     347  for (i=array->GetSize()-1;i>=0;i--)
     348    if (array->At(i) != 0)
     349      {
     350        array->Set(i+1);
     351        break;
     352      }
     353}
     354
     355
     356
    263357Bool_t MHCalibrationPixel::IsEmpty() const
    264358{
     
    276370}
    277371
    278 Bool_t MHCalibrationPixel::IsTimeFitOK() const
    279 {
    280     return TESTBIT(fFlags,kTimeFitOK);
     372Bool_t MHCalibrationPixel::IsOscillating()
     373{
     374
     375  if (fPSDExpFit)
     376    return TESTBIT(fFlags,kOscillating);
     377
     378  return CheckOscillations();
     379
    281380}
    282381
     
    291390}
    292391
    293 Bool_t MHCalibrationPixel::FillRelTimeLoGain(Float_t t)
    294 {
    295     return (fHRelTimeLoGain->Fill(t) > -1);
    296 }
    297 
    298 Bool_t MHCalibrationPixel::FillChargevsNLoGain(Float_t q, Int_t n)
    299 {
    300     return (fHChargevsNLoGain->Fill(n,q) > -1);
    301 }
    302 
    303392Bool_t MHCalibrationPixel::FillChargeHiGain(Float_t q)
    304393{
     
    309398{
    310399    return (fHAbsTimeHiGain->Fill(t) > -1);
    311 }
    312 
    313 Bool_t MHCalibrationPixel::FillRelTimeHiGain(Float_t t)
    314 {
    315     return (fHRelTimeHiGain->Fill(t) > -1);
    316 }
    317 
    318 Bool_t MHCalibrationPixel::FillChargevsNHiGain(Float_t q, Int_t n)
    319 {
    320     return (fHChargevsNHiGain->Fill(n,q) > -1);
    321400}
    322401
     
    333412      fHChargeHiGain->SetName(   Form("%s%d",fHChargeHiGain->GetName(),   id));
    334413      fHAbsTimeHiGain->SetName(  Form("%s%d",fHAbsTimeHiGain->GetName(),  id));
    335       fHRelTimeHiGain->SetName(  Form("%s%d",fHRelTimeHiGain->GetName(),  id));
    336       fHChargevsNHiGain->SetName(Form("%s%d",fHChargevsNHiGain->GetName(),id));
    337414     
    338415      //
     
    341418      fHChargeHiGain->SetTitle(    Form("%s%d",fHChargeHiGain->GetTitle(),   id));
    342419      fHAbsTimeHiGain->SetTitle(   Form("%s%d",fHAbsTimeHiGain->GetTitle(),  id));
    343       fHRelTimeHiGain->SetTitle(   Form("%s%d",fHRelTimeHiGain->GetTitle(),  id));
    344       fHChargevsNHiGain->SetTitle( Form("%s%d",fHChargevsNHiGain->GetTitle(),id));
    345420 
    346421      //
     
    349424      fHChargeLoGain->SetName( Form("%s%d",fHChargeLoGain->GetName(),id));
    350425      fHAbsTimeLoGain->SetName( Form("%s%d",fHAbsTimeLoGain->GetName(),id));
    351       fHRelTimeLoGain->SetName( Form("%s%d",fHRelTimeLoGain->GetName(),id));
    352       fHChargevsNLoGain->SetName( Form("%s%d",fHChargevsNLoGain->GetName(),id));
    353426
    354427      //
     
    357430      fHChargeLoGain->SetTitle( Form("%s%d",fHChargeLoGain->GetTitle(),id));
    358431      fHAbsTimeLoGain->SetTitle( Form("%s%d",fHAbsTimeLoGain->GetTitle(),id));
    359       fHRelTimeLoGain->SetTitle( Form("%s%d",fHRelTimeLoGain->GetTitle(),id));
    360       fHChargevsNLoGain->SetTitle( Form("%s%d",fHChargevsNLoGain->GetTitle(),id));
    361432     
    362433      fPixId = id;
    363434    }
    364435 
    365 }
    366 
    367 
    368 Bool_t MHCalibrationPixel::SetupFill(const MParList *plist)
    369 {
    370  
    371   Reset();
    372  
    373   return kTRUE;
    374436}
    375437
     
    390452}
    391453
    392 Bool_t MHCalibrationPixel::FillPointInGraph(Float_t qhi,Float_t qlo)
    393 {
    394 
    395   fHiGains->Set(++fTotalEntries);
    396   fLoGains->Set(fTotalEntries);
    397 
    398   fHiGains->AddAt(qhi,fTotalEntries-1);
    399   fLoGains->AddAt(qlo,fTotalEntries-1);
     454Bool_t MHCalibrationPixel::FillGraphs(Float_t qhi,Float_t qlo)
     455{
     456
     457  if (fTotalEntries >= fCurrentSize)
     458    {
     459      fCurrentSize *= 2;
     460
     461      fHiGains->Set(fCurrentSize);
     462      fLoGains->Set(fCurrentSize);
     463    }
     464 
     465  fHiGains->AddAt(qhi,fTotalEntries);
     466  fLoGains->AddAt(qlo,fTotalEntries);
     467
     468  fTotalEntries++;
    400469
    401470  return kTRUE;
     
    508577  fHChargeHiGain->Draw(opt);
    509578 
    510   c->Modified();
    511   c->Update();
    512  
    513579  if (IsUseLoGain())
    514580    {
     
    528594        }
    529595
    530       c->Modified();
    531       c->Update();
    532      
    533596      c->cd(3);
    534597      gROOT->SetSelectedPad(NULL);
     
    536599      if (fHivsLoGain)
    537600        fHivsLoGain->Draw("prof");
    538       gPad->Modified();
    539       gPad->Update();
    540      
     601
    541602      c->cd(4);
    542603      DrawLegend();
    543      
    544604    }
    545605  else
     
    558618     
    559619      fHChargeLoGain->Draw(opt);
    560       c->Modified();
    561       c->Update();
    562      
     620
    563621      c->cd(3);
    564622      DrawLegend();
     
    570628      if (fHivsLoGain)
    571629        fHivsLoGain->Draw("prof");
    572       gPad->Modified();
    573       gPad->Update();
    574630    }   
     631 
     632  c->cd(5);
     633  gPad->SetTicks();
     634  fHAbsTimeHiGain->Draw(opt);
     635
     636  c->cd(6);
     637  gPad->SetTicks();
     638  fHAbsTimeLoGain->Draw(opt);
     639
     640  CutArrayBorder(fHiGains);
     641  CreateChargeXaxis(fHiGains->GetSize());
     642
     643  c->cd(7);
     644  gPad->SetTicks();
     645  TGraph *gr1 = new TGraph(fChargeXaxis->GetSize(),
     646                           fChargeXaxis->GetArray(),
     647                           fHiGains->GetArray()); 
     648  gr1->SetTitle("Evolution of HiGain charges with event number");
     649  gr1->SetBit(kCanDelete);
     650  gr1->Draw("AL");
     651 
     652  CutArrayBorder(fLoGains); 
     653  CreateChargeXaxis(fHiGains->GetSize());
     654
     655  c->cd(8);
     656  gPad->SetTicks();
     657  TGraph *gr2 = new TGraph(fChargeXaxis->GetSize(),
     658                           fChargeXaxis->GetArray(),
     659                           fLoGains->GetArray()); 
     660  gr2->SetTitle("Evolution of HiGain charges with event number");
     661  gr2->SetBit(kCanDelete);
     662  gr2->Draw("AL");
    575663 
    576664  c->Modified();
    577665  c->Update();
    578666 
    579   c->cd(5);
    580   gStyle->SetOptStat(1111111);
    581 
    582   gPad->SetTicks(); 
    583   gPad->SetLogy(0);
    584   fHRelTimeHiGain->Draw(opt);
     667  c->cd(9);
     668 
     669  TArrayF *array;
     670
     671  if(IsUseLoGain())
     672    {
     673      if (!fPSDLoGain)
     674        return;
     675      array = fPSDLoGain;
     676    }
     677  else
     678    {
     679      if (!fPSDHiGain)
     680        return;
     681      array = fPSDHiGain;
     682    }
     683 
     684  if (!fPSDXaxis)
     685    CreatePSDXaxis(array->GetSize());
     686
     687  TGraph *gr3 = new TGraph(fPSDXaxis->GetSize(),fPSDXaxis->GetArray(),array->GetArray());
     688  gr3->SetTitle("Power Spectrum Density");
     689  gr3->SetBit(kCanDelete);
     690  gr3->Draw("AL");
     691
    585692  c->Modified();
    586693  c->Update();
    587694 
    588   if (IsUseLoGain())
    589       {
    590        
    591         c->cd(6);
    592         gPad->SetTicks();
    593         gPad->SetLogy(0);
    594         fHRelTimeLoGain->Draw(opt);
    595         c->Modified();
    596         c->Update();
    597        
    598         if (fRelTimeGausFit)
    599           {
    600             fRelTimeGausFit->SetLineColor(IsTimeFitOK() ? kGreen : kRed);
    601             fRelTimeGausFit->Draw("same");
    602           }
    603 
    604         c->Modified();
    605         c->Update();
    606       }
    607     else
    608       { 
    609         if (fRelTimeGausFit)
    610           {
    611             fRelTimeGausFit->SetLineColor(IsTimeFitOK() ? kGreen : kRed);
    612             fRelTimeGausFit->Draw("same");
    613           }
    614        
    615         c->Modified();
    616         c->Update();
    617        
    618         c->cd(6);
    619         gPad->SetTicks();
    620         gPad->SetLogy(0);
    621         fHRelTimeLoGain->Draw(opt);     
    622         c->Modified();
    623         c->Update();
    624    
    625       }
    626     c->Modified();
    627     c->Update();
    628    
    629     c->cd(7);
    630     gPad->SetTicks();
    631     fHAbsTimeHiGain->Draw(opt);
    632     c->Modified();
    633     c->Update();
    634 
    635     c->cd(8);
    636     gPad->SetTicks();
    637     fHAbsTimeLoGain->Draw(opt);
    638     c->Modified();
    639     c->Update();
    640 
    641 
    642     c->cd(9);
    643     gPad->SetTicks();
    644     fHChargevsNHiGain->Draw(opt);
    645     c->Modified();
    646     c->Update();
    647 
    648     c->cd(10);
    649     gPad->SetTicks();
    650     fHChargevsNLoGain->Draw(opt);
    651     c->Modified();
    652     c->Update();
    653 
    654     return;
     695  c->cd(10);
     696 
     697  gStyle->SetOptStat(111111);
     698  gPad->SetTicks(); 
     699
     700  if (fHPSD->Integral() > 0)
     701    gPad->SetLogy();
     702
     703  fHPSD->Draw(opt);
     704
     705  if (fPSDExpFit)
     706    {
     707      fPSDExpFit->SetLineColor(IsOscillating() ? kRed : kGreen);         
     708      fPSDExpFit->Draw("same");
     709    }
     710
     711  c->Modified();
     712  c->Update();
     713 
     714  return;
    655715}
    656716
     
    684744}
    685745
    686 
    687 Bool_t MHCalibrationPixel::FitTime(Option_t *option)
    688 {
    689 
    690   if (fRelTimeGausFit)
    691     return kFALSE;
    692 
    693   //
    694   // From the absolute time, we only take the mean and RMS
    695   //
    696   fAbsTimeMean    = (Float_t)fHAbsTimeHiGain->GetMean();
    697   fAbsTimeRms     = (Float_t)fHAbsTimeHiGain->GetRMS();
    698   fAbsTimeMeanErr = (Float_t)fAbsTimeRms / TMath::Sqrt(fHAbsTimeHiGain->GetEntries());
    699  
    700   if (TESTBIT(fFlags,kUseLoGain))
    701     {
    702       fAbsTimeMean    = fHAbsTimeLoGain->GetMean();
    703       fAbsTimeRms     = fHAbsTimeLoGain->GetRMS();
    704       fAbsTimeMeanErr = fAbsTimeRms / TMath::Sqrt(fHAbsTimeLoGain->GetEntries());
    705     }
    706  
    707   //
    708   // Get the fitting ranges
    709   //
    710   Axis_t rmin = fRelTimeLowerFitRangeHiGain;
    711   Axis_t rmax = fRelTimeUpperFitRangeHiGain;
    712   TH1F *hist = fHRelTimeHiGain;
    713 
    714   if (TESTBIT(fFlags,kUseLoGain))
    715     {
    716       rmin = fRelTimeLowerFitRangeLoGain;
    717       rmax = fRelTimeUpperFitRangeLoGain;
    718       hist = fHRelTimeLoGain;
    719     }
    720  
    721   const Stat_t   entries     = hist->Integral("width");
    722   const Double_t mu_guess    = hist->GetBinCenter(hist->GetMaximumBin());
    723   const Double_t sigma_guess = (rmax - rmin)/2.;
    724   const Double_t area_guess  = 2.*entries/gkSq2Pi/sigma_guess;
    725 
    726   TString name = TString("GausRelTime");
    727   name += fPixId;
    728   fRelTimeGausFit = new TF1(name.Data(),"gaus",rmin,rmax); 
    729 
    730   if (!fRelTimeGausFit)
    731     {
    732     *fLog << warn << dbginf << "WARNING: Could not create fit function for RelTime fit" << endl;
    733     return kFALSE;
    734     }
    735 
    736   fRelTimeGausFit->SetParameters(area_guess,mu_guess,sigma_guess);
    737   fRelTimeGausFit->SetParNames("Area","#mu","#sigma");
    738   fRelTimeGausFit->SetParLimits(0,0.,5.*area_guess);
    739   fRelTimeGausFit->SetParLimits(1,rmin,rmax);
    740   fRelTimeGausFit->SetParLimits(2,0.,(rmax-rmin));
    741   fRelTimeGausFit->SetRange(rmin,rmax);
    742 
    743   hist->Fit(fRelTimeGausFit,option);
    744 
    745   //
    746   // If the fit does not converge, try another one with smaller bounderies
    747   //
    748   if (fRelTimeGausFit->GetProb() < 0.001)
    749     {
    750       rmin = fRelTimeGausFit->GetParameter(1) - 1.5*fRelTimeGausFit->GetParameter(2);
    751       rmax = fRelTimeGausFit->GetParameter(1) + 1.5*fRelTimeGausFit->GetParameter(2);
    752       fRelTimeGausFit->SetRange(rmin,rmax); 
    753       hist->Fit(fRelTimeGausFit,option);
    754     }
    755  
    756   fRelTimeChisquare = fRelTimeGausFit->GetChisquare();
    757   fRelTimeNdf       = fRelTimeGausFit->GetNDF();
    758   fRelTimeProb      = fRelTimeGausFit->GetProb();
    759 
    760   fRelTimeMean      = fRelTimeGausFit->GetParameter(1);
    761   fRelTimeSigma     = fRelTimeGausFit->GetParameter(2);
    762 
    763   fRelTimeMeanErr   = fRelTimeGausFit->GetParError(1);
    764 
    765   if (TMath::IsNaN(fRelTimeMean) || TMath::IsNaN(fRelTimeSigma))
    766     {
    767       CLRBIT(fFlags,kTimeFitOK);
    768       return kFALSE;
    769     }
    770  
    771   if (TMath::IsNaN(fRelTimeChisquare) || (fRelTimeProb < fProbLimit))
    772     {
    773       CLRBIT(fFlags,kTimeFitOK);
    774       return kFALSE;
    775     }
    776  
    777   SETBIT(fFlags,kTimeFitOK);
    778 
    779   return kTRUE;
    780 
    781 }
    782746
    783747
     
    850814
    851815  //
     816  // From the absolute time, we only take the mean and RMS
     817  //
     818  fAbsTimeMean    = (Float_t)fHAbsTimeHiGain->GetMean();
     819  fAbsTimeRms     = (Float_t)fHAbsTimeHiGain->GetRMS();
     820  fAbsTimeMeanErr = (Float_t)fAbsTimeRms / TMath::Sqrt(fHAbsTimeHiGain->GetEntries());
     821 
     822  if (TESTBIT(fFlags,kUseLoGain))
     823    {
     824      fAbsTimeMean    = fHAbsTimeLoGain->GetMean();
     825      fAbsTimeRms     = fHAbsTimeLoGain->GetRMS();
     826      fAbsTimeMeanErr = fAbsTimeRms / TMath::Sqrt(fHAbsTimeLoGain->GetEntries());
     827    }
     828
     829  //
    852830  // The fit result is accepted under condition:
    853831  // 1) The results are not nan's
     
    880858
    881859
    882 
    883  
    884860void MHCalibrationPixel::CutAllEdges()
    885861{
    886862
    887   Int_t nbins = 50;
     863  Int_t nbins = 30;
    888864
    889865  CutEdges(fHChargeHiGain,nbins);
     
    899875                      +fHChargeLoGain->GetBinWidth(0);
    900876
    901   CutEdges(fHRelTimeHiGain,0);
    902 
    903   fRelTimeLowerFitRangeHiGain = fHRelTimeHiGain->GetBinLowEdge(fHRelTimeHiGain->GetXaxis()->GetFirst());
    904   fRelTimeUpperFitRangeHiGain = fHRelTimeHiGain->GetBinLowEdge(fHRelTimeHiGain->GetXaxis()->GetLast())
    905                                +fHRelTimeHiGain->GetBinWidth(0);
    906 
    907   CutEdges(fHRelTimeLoGain,0);
    908 
    909   fRelTimeLowerFitRangeLoGain = fHRelTimeLoGain->GetBinLowEdge(fHRelTimeLoGain->GetXaxis()->GetFirst());
    910   fRelTimeUpperFitRangeLoGain = fHRelTimeLoGain->GetBinLowEdge(fHRelTimeLoGain->GetXaxis()->GetLast())
    911                                +fHRelTimeLoGain->GetBinWidth(0);
    912877
    913878  CutEdges(fHAbsTimeHiGain,0);
     
    923888                       +fHAbsTimeLoGain->GetBinWidth(0);
    924889
    925   CutEdges(fHChargevsNHiGain,0);
    926   CutEdges(fHChargevsNLoGain,0);
    927890
    928891}
     
    939902}
    940903
    941 void MHCalibrationPixel::PrintTimeFitResult()
    942 {
    943 
    944   *fLog << all << "Results of the Time Slices Fit: "                        << endl;
    945   *fLog << all << "Chisquare: "   << fRelTimeChisquare                      << endl;
    946   *fLog << all << "Ndf: "         << fRelTimeNdf                            << endl;
    947   *fLog << all << "Probability: " << fRelTimeProb                           << endl;
    948   *fLog << all                                                              << endl;
    949 
    950 }
Note: See TracChangeset for help on using the changeset viewer.