Ignore:
Timestamp:
01/27/04 20:32:42 (21 years ago)
Author:
gaug
Message:
*** empty log message ***
File:
1 edited

Legend:

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

    r2922 r2931  
    4444//
    4545MCalibrationPINDiode::MCalibrationPINDiode(const char *name, const char *title)
    46   : fHist(NULL),
    47     fCharge(-1.),
    48     fErrCharge(-1.),
    49     fPed(-1.),
    50     fPedRms(-1.),
    51     fSigmaCharge(-1.),
    52     fErrSigmaCharge(-1.),
    53     fTime(-1.),
    54     fErrTime(-1.)
     46    : fChargeLimit(3.),
     47      fChargeErrLimit(0.),
     48      fChargeRelErrLimit(1.),
     49      fFlags(0)
    5550{
    5651
     
    6257  if (!fHist)
    6358    *fLog << warn << dbginf << " Could not create MHCalibrationPINDiode " << endl;
    64  
     59 
     60  Clear();
     61
    6562}
    6663
     
    7774{
    7875  fHist->Reset();
     76
     77  CLRBIT(fFlags, kExcluded);
     78  CLRBIT(fFlags, kFitValid);
     79  CLRBIT(fFlags, kFitted);
     80
     81  fCharge                           =  -1.;
     82  fErrCharge                        =  -1.;
     83  fSigmaCharge                      =  -1.;
     84  fErrSigmaCharge                   =  -1.;
     85  fRSigmaSquare                     =  -1.;
     86  fChargeProb                       =  -1.;
     87  fPed                              =  -1.;
     88  fPedRms                           =  -1.;
     89  fTime                             =  -1.;
     90  fSigmaTime                        =  -1.;
     91  fTimeChiSquare                    =  -1.;
     92
     93}
     94
     95
     96// --------------------------------------------------------------------------
     97//
     98// Set the pedestals from outside
     99//
     100void MCalibrationPINDiode::SetPedestal(Float_t ped, Float_t pedrms)
     101{
     102
     103  fPed    = ped;   
     104  fPedRms = pedrms;
     105 
     106}
     107
     108// --------------------------------------------------------------------------
     109//
     110// Set the Excluded Bit from outside
     111//
     112void MCalibrationPINDiode::SetExcluded(Bool_t b )
     113{
     114  b ?  SETBIT(fFlags, kExcluded) : CLRBIT(fFlags, kExcluded);
     115}
     116
     117
     118// --------------------------------------------------------------------------
     119//
     120// Set the Excluded Bit from outside
     121//
     122void MCalibrationPINDiode::SetExcludeQualityCheck(Bool_t b )
     123{
     124  b ?  SETBIT(fFlags, kExcludeQualityCheck) : CLRBIT(fFlags, kExcludeQualityCheck);
     125}
     126
     127// --------------------------------------------------------------------------
     128//
     129// Set the Excluded Bit from outside
     130//
     131void MCalibrationPINDiode::SetFitValid(Bool_t b )   
     132{
     133  b ?  SETBIT(fFlags, kFitValid) : CLRBIT(fFlags, kFitValid);
     134}
     135
     136// --------------------------------------------------------------------------
     137//
     138// Set the Excluded Bit from outside
     139//
     140void MCalibrationPINDiode::SetFitted(Bool_t b )
     141{
     142  b ?  SETBIT(fFlags, kFitted) : CLRBIT(fFlags, kFitted);
     143}
     144
     145Bool_t MCalibrationPINDiode::IsExcluded() const
     146 {
     147   return TESTBIT(fFlags,kExcluded); 
     148 }
     149
     150Bool_t MCalibrationPINDiode::IsFitValid() const
     151{
     152  return TESTBIT(fFlags, kFitValid); 
     153}
     154
     155Bool_t MCalibrationPINDiode::IsFitted() const
     156{
     157  return TESTBIT(fFlags, kFitted);   
    79158}
    80159
    81160Bool_t MCalibrationPINDiode::FitCharge()
    82161{
    83   if(!fHist->FitCharge())
    84     return kFALSE;
    85 
     162
     163  //
     164  // 1) Return if the charge distribution is already succesfully fitted 
     165  //    or if the histogram is empty
     166  //
     167  if (fHist->IsFitOK() || fHist->IsEmpty())
     168    return kTRUE;
     169
     170  //
     171  // 4) Fit the Lo Gain histograms with a Gaussian
     172  //
     173  if(fHist->FitCharge())
     174    {
     175      SETBIT(fFlags,kFitted);
     176    }
     177  else
     178    {
     179      *fLog << warn << "WARNING: Could not fit charges of PINDiode " << endl;
     180      //         
     181      // 5) In case of failure print out the fit results
     182      //
     183      //          fHist->PrintChargeFitResult();
     184      CLRBIT(fFlags,kFitted);
     185    }
     186
     187  //
     188  // 6) Retrieve the results and store them in this class
     189  //
    86190  fCharge         = fHist->GetChargeMean();
    87191  fErrCharge      = fHist->GetChargeMeanErr();
    88192  fSigmaCharge    = fHist->GetChargeSigma();
    89193  fErrSigmaCharge = fHist->GetChargeSigmaErr();
     194  fChargeProb     = fHist->GetChargeProb();
     195
     196  if (CheckChargeFitValidity())
     197    SETBIT(fFlags,kFitValid);
     198  else
     199    {
     200      CLRBIT(fFlags,kFitValid);
     201      return kFALSE;
     202    }
    90203
    91204  return kTRUE;
     
    93206}
    94207
     208//
     209// The check return kTRUE if:
     210//
     211// 1) PINDiode has a fitted charge greater than 5*PedRMS
     212// 2) PINDiode has a fit error greater than 0.
     213// 3) PINDiode has a fitted charge greater its charge error
     214// 4) PINDiode has a fit Probability greater than 0.0001
     215// 5) PINDiode has a charge sigma bigger than its Pedestal RMS
     216//
     217Bool_t MCalibrationPINDiode::CheckChargeFitValidity()
     218{
     219
     220  if (TESTBIT(fFlags,kExcludeQualityCheck))
     221    return kTRUE;
     222
     223  if (fCharge < fChargeLimit*GetPedRms())
     224    {
     225      *fLog << warn << "WARNING: Fitted Charge is smaller than "
     226            << fChargeLimit << " Pedestal RMS in PINDiode " << endl;
     227      return kFALSE;
     228    }
     229 
     230  if (fErrCharge < fChargeErrLimit)
     231    {
     232      *fLog << warn << "WARNING: Error of Fitted Charge is smaller than "
     233            << fChargeErrLimit << " in PINDiode " << endl;
     234      return kFALSE;
     235    }
     236     
     237  if (fCharge < fChargeRelErrLimit*fErrCharge)
     238    {
     239      *fLog << warn << "WARNING: Fitted Charge is smaller than "
     240            << fChargeRelErrLimit << "* its error in PINDiode " << endl;
     241      return kFALSE;
     242    }
     243     
     244  if (!fHist->IsFitOK())
     245    {
     246      *fLog << warn << "WARNING: Probability of Fitted Charge too low in PINDiode " << endl;
     247      return kFALSE;
     248    }
     249
     250  if (fSigmaCharge < GetPedRms())
     251    {
     252      *fLog << warn << "WARNING: Sigma of Fitted Charge smaller than Pedestal RMS in PINDiode " << endl;
     253      return kFALSE;
     254    }
     255  return kTRUE;
     256}
     257
     258
     259// --------------------------------------------------------------------------
     260//
     261// 1) Fit the arrival times
     262// 2) Retrieve the results
     263// 3) Note that because of the low number of bins, the NDf is sometimes 0, so
     264//    Root does not give a reasonable Probability, the Chisquare is more significant
     265//
    95266Bool_t MCalibrationPINDiode::FitTime()
    96267{
    97268
    98269  if(!fHist->FitTimeHiGain())
    99     return kFALSE;
    100 
    101   fTime    = fHist->GetTime();
    102   fErrTime = fHist->GetErrTime();
    103  
     270    {
     271      *fLog << warn << "WARNING: Could not fit Hi Gain times of PIN Diode" << endl;
     272      fHist->PrintTimeFitResult();
     273      return kFALSE;
     274    }
     275 
     276  fTime          = fHist->GetTimeMean();
     277  fSigmaTime     = fHist->GetTimeSigma();
     278  fTimeChiSquare = fHist->GetTimeChiSquare();
     279  fTimeProb      = fHist->GetTimeProb();
     280 
     281  if (CheckTimeFitValidity())
     282    SETBIT(fFlags,kFitValid);
     283  else
     284    CLRBIT(fFlags,kFitValid);
     285
    104286  return kTRUE;
    105 
    106 }
     287}
     288
     289//
     290// The check returns kTRUE if:
     291//
     292// The mean arrival time is at least 1.0 slices from the used edge slices
     293//
     294Bool_t MCalibrationPINDiode::CheckTimeFitValidity()
     295{
     296
     297  if (TESTBIT(fFlags,kExcludeQualityCheck))
     298    return kTRUE;
     299
     300  return kTRUE;
     301}
     302
Note: See TracChangeset for help on using the changeset viewer.