Ignore:
Timestamp:
02/02/04 22:52:53 (21 years ago)
Author:
gaug
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mcalib/MCalibrationPix.cc

    r2996 r3007  
    3030// (offset) value of one Pixel (PMT).                                      //
    3131//                                                                         //
    32 /////////////////////////////////////////////////////////////////////////////
    33 #include "MCalibrationPix.h"
    34 #include "MCalibrationConfig.h"
    35 
    36 #include "MLog.h"
    37 #include "MLogManip.h"
    38 
    39 ClassImp(MCalibrationPix);
    40 
    41 using namespace std;
    42 
    43 // --------------------------------------------------------------------------
    44 //
    45 // Default Constructor:
    46 //
    4732// The following values are initialized to meaningful values:
    4833//
     
    5439//   Error F-Factor = 2.*0.02   = 0.04
    5540//
     41/////////////////////////////////////////////////////////////////////////////
     42#include "MCalibrationPix.h"
     43#include "MCalibrationConfig.h"
     44
     45#include "MLog.h"
     46#include "MLogManip.h"
     47
     48ClassImp(MCalibrationPix);
     49
     50using namespace std;
     51
     52const Float_t MCalibrationPix::gkElectronicPedRms    = 1.5;
     53const Float_t MCalibrationPix::gkErrElectronicPedRms = 0.3;
     54const Float_t MCalibrationPix::gkFFactor             = 1.32;
     55const Float_t MCalibrationPix::gkFFactorError        = 0.04;
     56const Float_t MCalibrationPix::gkChargeLimit         = 3.;
     57const Float_t MCalibrationPix::gkChargeErrLimit      = 0.;
     58const Float_t MCalibrationPix::gkChargeRelErrLimit   = 1.;
     59const Float_t MCalibrationPix::gkTimeLimit           = 1.5;
     60const Float_t MCalibrationPix::gkTimeErrLimit        = 3.;
     61
     62// --------------------------------------------------------------------------
     63//
     64// Default Constructor:
     65//
    5666MCalibrationPix::MCalibrationPix(const char *name, const char *title)
    5767    : fPixId(-1),
    58       fElectronicPedRms(1.5),
    59       fErrElectronicPedRms(0.3),
    60       fFactor(1.32),
    61       fFactorError(0.04),
    62       fChargeLimit(3.),
    63       fChargeErrLimit(0.),
    64       fChargeRelErrLimit(1.),
    6568      fFlags(0)
    6669{
     
    101104  CLRBIT(fFlags, kHiGainSaturation);
    102105  CLRBIT(fFlags, kExcluded);
    103   CLRBIT(fFlags, kFitValid);
     106  CLRBIT(fFlags, kChargeFitValid);
     107  CLRBIT(fFlags, kTimeFitValid);
    104108  CLRBIT(fFlags, kFitted);
    105109  CLRBIT(fFlags, kBlindPixelMethodValid);
     
    117121  fErrPedRms                        =   0.;
    118122  fTime                             =  -1.;
     123  fErrTime                          =  -1.;
    119124  fSigmaTime                        =  -1.;
    120   fTimeChiSquare                    =  -1.;
     125  fTimeProb                         =  -1.;
     126  fTimeFirstHiGain                  =   0 ;
     127  fTimeLastHiGain                   =   0 ;
     128  fTimeFirstLoGain                  =   0 ;
     129  fTimeLastLoGain                   =   0 ;
     130
    121131  fPheFFactorMethod                 =  -1.;
    122132  fPheFFactorMethodError            =  -1.;
     
    231241// Set the Excluded Bit from outside
    232242//
    233 void MCalibrationPix::SetFitValid(Bool_t b )   
    234 {
    235   b ?  SETBIT(fFlags, kFitValid) : CLRBIT(fFlags, kFitValid);
     243void MCalibrationPix::SetChargeFitValid(Bool_t b )   
     244{
     245  b ?  SETBIT(fFlags, kChargeFitValid) : CLRBIT(fFlags, kChargeFitValid);
     246}
     247
     248// --------------------------------------------------------------------------
     249//
     250// Set the Excluded Bit from outside
     251//
     252void MCalibrationPix::SetTimeFitValid(Bool_t b )   
     253{
     254  b ?  SETBIT(fFlags, kTimeFitValid) : CLRBIT(fFlags, kTimeFitValid);
    236255}
    237256
     
    271290  b ?  SETBIT(fFlags, kPINDiodeMethodValid) : CLRBIT(fFlags, kPINDiodeMethodValid);
    272291}
     292
     293void MCalibrationPix::SetAbsTimeBordersHiGain(Byte_t f, Byte_t l)
     294{
     295
     296  fTimeFirstHiGain = f;
     297  fTimeLastHiGain  = l;
     298 
     299}
     300
     301void MCalibrationPix::SetAbsTimeBordersLoGain(Byte_t f, Byte_t l)
     302{
     303
     304  fTimeFirstLoGain = f;
     305  fTimeLastLoGain  = l;
     306 
     307}
     308
    273309
    274310
     
    278314 }
    279315
    280 Bool_t MCalibrationPix::IsFitValid() const
    281 {
    282   return TESTBIT(fFlags, kFitValid); 
     316Bool_t MCalibrationPix::IsChargeFitValid() const
     317{
     318  return TESTBIT(fFlags, kChargeFitValid); 
     319}
     320
     321Bool_t MCalibrationPix::IsTimeFitValid() const
     322{
     323  return TESTBIT(fFlags, kTimeFitValid); 
    283324}
    284325
     
    342383  //    or if the histogram is empty
    343384  //
    344   if (fHist->IsFitOK() || fHist->IsEmpty())
     385  if (fHist->IsChargeFitOK() || fHist->IsEmpty())
    345386    return kTRUE;
    346387
     
    386427
    387428  if (CheckChargeFitValidity())
    388     SETBIT(fFlags,kFitValid);
     429    SETBIT(fFlags,kChargeFitValid);
    389430  else
    390431    {
    391       CLRBIT(fFlags,kFitValid);
     432      CLRBIT(fFlags,kChargeFitValid);
    392433      return kFALSE;
    393434    }
     
    408449      const Float_t chargeSquareRelErrSquare  = 4.*fErrCharge*fErrCharge / chargeSquare;
    409450
    410       const Float_t fFactorRelErrSquare       = fFactorError * fFactorError / (fFactor * fFactor);
     451      const Float_t fFactorRelErrSquare       = gkFFactorError * gkFFactorError / (gkFFactor * gkFFactor);
    411452      //
    412453      // Now the absolute error squares
     
    415456      const Float_t sigmaSquareErrSquare      = 4.*fErrSigmaCharge*fErrSigmaCharge * sigmaSquare;
    416457
    417       const Float_t elecRmsSquare             =       fElectronicPedRms*   fElectronicPedRms;
    418       const Float_t elecRmsSquareErrSquare    = 4.*fErrElectronicPedRms*fErrElectronicPedRms * elecRmsSquare;
     458      const Float_t elecRmsSquare             =       gkElectronicPedRms*   gkElectronicPedRms;
     459      const Float_t elecRmsSquareErrSquare    = 4.*gkErrElectronicPedRms*gkErrElectronicPedRms * elecRmsSquare;
    419460
    420461      Float_t pedRmsSquare                    =       fPedRms*   fPedRms;
     
    477518      // (independent on Hi Gain or Lo Gain)
    478519      //
    479       fPheFFactorMethod = fFactor * chargeSquare / fRSigmaSquare;
     520      fPheFFactorMethod = gkFFactor * chargeSquare / fRSigmaSquare;
    480521
    481522      const Float_t pheFFactorRelErrSquare =  fFactorRelErrSquare
     
    497538                                         * fConversionFFactorMethod * fConversionFFactorMethod;
    498539     
    499       if ( IsFitValid()                     &&
     540      if ( IsChargeFitValid()               &&
    500541           (fConversionFFactorMethod > 0.) &&
    501542           (fConversionErrorFFactorMethod/fConversionFFactorMethod < 0.1) )
     
    525566  if (TMath::IsNaN(fCharge)
    526567      || TMath::IsNaN(fErrCharge)
    527       || TMath::IsNaN(fErrCharge)
    528568      || TMath::IsNaN(fSigmaCharge)
    529569      || TMath::IsNaN(fErrSigmaCharge)
     
    543583    equivpedestal /= fConversionHiLo;
    544584     
    545   if (fCharge < fChargeLimit*equivpedestal)
     585  if (fCharge < gkChargeLimit*equivpedestal)
    546586    {
    547587      *fLog << warn << "WARNING: Fitted Charge is smaller than "
    548             << fChargeLimit << " Pedestal RMS in Pixel " << fPixId << endl;
    549       return kFALSE;
    550     }
    551  
    552   if (fErrCharge < fChargeErrLimit)
     588            << gkChargeLimit << " Pedestal RMS in Pixel " << fPixId << endl;
     589      return kFALSE;
     590    }
     591 
     592  if (fErrCharge < gkChargeErrLimit)
    553593    {
    554594      *fLog << warn << "WARNING: Error of Fitted Charge is smaller than "
    555             << fChargeErrLimit << " in Pixel " << fPixId << endl;
    556       return kFALSE;
    557     }
    558      
    559   if (fCharge < fChargeRelErrLimit*fErrCharge)
     595            << gkChargeErrLimit << " in Pixel " << fPixId << endl;
     596      return kFALSE;
     597    }
     598     
     599  if (fCharge < gkChargeRelErrLimit*fErrCharge)
    560600    {
    561601      *fLog << warn << "WARNING: Fitted Charge is smaller than "
    562             << fChargeRelErrLimit << "* its error in Pixel " << fPixId << endl;
    563       return kFALSE;
    564     }
    565      
    566   if (!fHist->IsFitOK())
    567     {
    568       *fLog << warn << "WARNING: Probability of Fitted Charge too low in Pixel " << fPixId << endl;
     602            << gkChargeRelErrLimit << "* its error in Pixel " << fPixId << endl;
     603      return kFALSE;
     604    }
     605     
     606  if (!fHist->IsChargeFitOK())
     607    {
     608      *fLog << warn << "WARNING: Probability of Fitted Charge too low in Pixel "
     609            << fPixId << endl;
    569610      return kFALSE;
    570611    }
     
    572613  if (fSigmaCharge < equivpedestal)
    573614    {
    574       *fLog << warn << "WARNING: Sigma of Fitted Charge smaller than Pedestal RMS in Pixel " << fPixId << endl;
     615      *fLog << warn << "WARNING: Sigma of Fitted Charge smaller than Pedestal RMS in Pixel "
     616            << fPixId << endl;
    575617      return kFALSE;
    576618    }
     
    579621
    580622//
    581 // The check returns kTRUE if:
    582 //
    583 // The mean arrival time is at least 1.0 slices from the used edge slices
     623// The check return kTRUE if:
     624//
     625// 0) No value is nan
     626// 1) Pixel has a fitted rel. time smaller than 3*FADC slices
     627// 2) Pixel has a fit error greater than 0.
     628// 4) Pixel has a fit Probability greater than 0.001
     629// 5) The absolute arrival time is at least 1.0 slices from the used edge slices
    584630//
    585631Bool_t MCalibrationPix::CheckTimeFitValidity()
    586632{
    587633
     634  if (TMath::IsNaN(fTime)
     635      || TMath::IsNaN(fErrTime)
     636      || TMath::IsNaN(fSigmaTime)
     637      || TMath::IsNaN(fTimeProb))
     638    {
     639      *fLog << warn << "WARNING: Some of the time fit values are NAN in Pixel "
     640            << fPixId << endl;
     641      return kFALSE;
     642    }
     643 
    588644  if (TESTBIT(fFlags,kExcludeQualityCheck))
    589645    return kTRUE;
    590646
    591   Float_t lowerrange;
    592   Float_t upperrange;
     647  if (TMath::Abs(fTime) > gkTimeLimit)
     648    {
     649      *fLog << warn << "WARNING: Abs(Fitted Rel. Time) is greater than "
     650            << gkTimeLimit << " in Pixel " << fPixId << endl;
     651      return kFALSE;
     652    }
     653
     654  if (fErrTime > gkTimeErrLimit)
     655    {
     656      *fLog << warn << "WARNING: Error of Fitted Time is smaller than "
     657            << gkTimeErrLimit << " in Pixel " << fPixId << endl;
     658      return kFALSE;
     659    }
     660
     661  if (!fHist->IsTimeFitOK())
     662    {
     663      *fLog << warn << "WARNING: Probability of Fitted Time too low in Pixel "
     664            << fPixId << endl;
     665      return kFALSE;
     666    }
     667
     668  Float_t first;
     669  Float_t last;
    593670
    594671  if (TESTBIT(fFlags,kHiGainSaturation))
    595672    {
    596       lowerrange = (Float_t)fHist->GetTimeLowerFitRangeLoGain()+1.;
    597       upperrange = (Float_t)fHist->GetTimeUpperFitRangeLoGain()+1.;
     673      first = (Float_t)fHist->GetAbsTimeFirstLoGain();
     674      last = (Float_t)fHist->GetAbsTimeLastLoGain();
     675
     676      if (first < (Float_t)fTimeFirstLoGain+1)
     677        {
     678          *fLog << warn
     679                << "WARNING: Some absolute times smaller than limit in Pixel "
     680                << fPixId << " time: " << first << " Limit: " << fTimeFirstLoGain+1 << endl;
     681          return kFALSE;
     682        }
     683
     684      if ((Float_t)fTimeLastLoGain-1 > last)
     685        {
     686          *fLog << warn
     687                << "WARNING: Some absolute times bigger than limit in Pixel "
     688                << fPixId << " time: " << last << " Limit: " << fTimeLastLoGain-1 << endl;
     689          return kFALSE;
     690        }
     691
    598692    }
    599693  else
    600694    {
    601       lowerrange = (Float_t)fHist->GetTimeLowerFitRangeHiGain()+1.;
    602       upperrange = (Float_t)fHist->GetTimeUpperFitRangeHiGain()+1.;
    603     }
    604 
    605 
    606   if (fTime < lowerrange)
    607     {
    608       *fLog << warn
    609             << "WARNING: Mean Fitted Time inside or smaller than first used FADC slice in Pixel "
    610             << fPixId << " time: " << fTime << " Range: " << lowerrange << endl;
    611       return kFALSE;
    612     }
    613 
    614   if (fTime > upperrange)
    615     {
    616       *fLog << warn
    617             << "WARNING: Mean Fitted Time inside or greater than last used FADC slice in Pixel "
    618             << fPixId << " time: " << fTime << " Range: " << upperrange << endl;
    619       return kFALSE;
    620     }
     695      first = (Float_t)fHist->GetAbsTimeFirstHiGain();
     696      last = (Float_t)fHist->GetAbsTimeLastHiGain();
     697
     698      if (first > ((Float_t)fTimeFirstHiGain+1.))
     699        {
     700          *fLog << warn
     701                << "WARNING: Some absolute times smaller than limit in Pixel "
     702                << fPixId << " time: " << first << " Limit: " << (Float_t)fTimeFirstHiGain+1. << endl;
     703          //          return kFALSE;
     704        }
     705
     706      if (((Float_t)fTimeLastHiGain-1.) > last)
     707        {
     708          *fLog << warn
     709                << "WARNING: Some absolute times bigger than limit in Pixel "
     710                << fPixId << " time: " << last << " Limit: " << (Float_t)fTimeLastHiGain-1. << endl;
     711          //          return kFALSE;
     712        }
     713
     714    }
     715
     716
    621717
    622718  return kTRUE;
     
    662758// 1) Fit the arrival times
    663759// 2) Retrieve the results
    664 // 3) Note that because of the low number of bins, the NDf is sometimes 0, so
    665 //    Root does not give a reasonable Probability, the Chisquare is more significant
    666760//
    667761// This fit has to be done AFTER the Charges fit,
     
    672766{
    673767
    674   //
    675   // Fit the Low Gain
    676   //
    677   if (TESTBIT(fFlags,kHiGainSaturation))
    678     {
    679       if(!fHist->FitTimeLoGain())
    680         {
    681           *fLog << warn << "WARNING: Could not fit Lo Gain times of pixel " << fPixId << endl;
    682           //      fHist->PrintTimeFitResult();
    683           return kFALSE;
    684         }
    685     }
    686 
    687   //
    688   // Fit the High Gain
    689   //
     768  if(!fHist->FitTime())
     769    {
     770      *fLog << warn << "WARNING: Could not fit relative times of pixel " << fPixId << endl;
     771      return kFALSE;
     772    }
     773 
     774  fTime          = fHist->GetRelTimeMean();
     775  fErrTime       = fHist->GetRelTimeMeanErr();
     776  fSigmaTime     = fHist->GetRelTimeSigma();
     777  fTimeProb      = fHist->GetRelTimeProb();
     778
     779  if (CheckTimeFitValidity())
     780    SETBIT(fFlags,kTimeFitValid);
    690781  else
    691     {
    692       if(!fHist->FitTimeHiGain())
    693         {
    694           *fLog << warn << "WARNING: Could not fit Hi Gain times of pixel " << fPixId << endl;
    695           //      fHist->PrintTimeFitResult();
    696           return kFALSE;
    697         }
    698     }
    699    
    700   fTime          = fHist->GetTimeMean();
    701   fSigmaTime     = fHist->GetTimeSigma();
    702   fTimeChiSquare = fHist->GetTimeChiSquare();
    703   fTimeProb      = fHist->GetTimeProb();
    704 
    705   if (CheckTimeFitValidity())
    706     SETBIT(fFlags,kFitValid);
    707   else
    708     CLRBIT(fFlags,kFitValid);
     782    CLRBIT(fFlags,kTimeFitValid);
    709783
    710784  return kTRUE;
Note: See TracChangeset for help on using the changeset viewer.