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

Legend:

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

    r2904 r2922  
    6767        fHivsLoGain(NULL),
    6868        fFitLegend(NULL),
    69         fLowerFitRange(-100.),
    7069        fChargeFirstHiGain(-100.5),
    7170        fChargeLastHiGain(1999.5),
     
    112111    Axis_t tfirst = -0.5;
    113112    Axis_t tlast  = 15.5;
    114     Int_t  ntbins = 16;
     113    Int_t  ntbins = 32;
    115114
    116115    fHTimeHiGain = new TH1F("HTimeHiGain","Distribution of Mean Arrival Hi Gain Times Pixel ",
     
    695694  fTimeSigma     = fTimeGausFit->GetParameter(2);
    696695
    697   if (fTimeChisquare > 20.)  // Cannot use Probability because Ndf is sometimes < 1
     696  if (TMath::IsNaN(fTimeMean) || TMath::IsNaN(fTimeSigma))
     697    return kFALSE;
     698
     699  if (TMath::IsNaN(fTimeChisquare) || fTimeChisquare > 20.)  // Cannot use Probability because Ndf is sometimes < 1
    698700    return kFALSE;
    699701
     
    758760}
    759761
    760 Bool_t MHCalibrationPixel::FitChargeHiGain(Option_t *option)
     762Bool_t MHCalibrationPixel::FitCharge(Option_t *option)
    761763{
    762764
     
    767769  // Get the fitting ranges
    768770  //
    769   Axis_t rmin = (fLowerFitRange != 0.) ? fLowerFitRange : fChargeFirstHiGain;
    770   Axis_t rmax = 0.;
     771  Axis_t rmin = fChargeFirstHiGain;
     772  if (TESTBIT(fFlags,kUseLoGain))
     773    rmin = fChargeFirstLoGain;
     774
     775  Axis_t rmax = fChargeLastHiGain;
     776  if (TESTBIT(fFlags,kUseLoGain))
     777    rmin = fChargeFirstLoGain;
     778
     779  TH1F *hist = fHChargeHiGain;
     780  if (TESTBIT(fFlags,kUseLoGain))
     781    hist = fHChargeLoGain;
    771782
    772783  //
     
    774785  // otherwise the fit goes gaga because of high number of dimensions ...
    775786  //
    776   const Stat_t   entries    = fHChargeHiGain->Integral();
    777   const Double_t area_guess = entries/gkSq2Pi;
    778   const Double_t mu_guess   = fHChargeHiGain->GetBinCenter(fHChargeHiGain->GetMaximumBin());
     787  const Stat_t   entries     = hist->Integral();
     788  const Double_t area_guess  = entries/gkSq2Pi;
     789  const Double_t mu_guess    = hist->GetBinCenter(hist->GetMaximumBin());
    779790  const Double_t sigma_guess = mu_guess/15.;
    780791
     
    782793  name += fPixId;
    783794
    784   fChargeGausFit = new TF1(name.Data(),"gaus",rmin,fChargeLastHiGain);
     795  fChargeGausFit = new TF1(name.Data(),"gaus",rmin,rmax);
    785796
    786797  if (!fChargeGausFit)
     
    793804  fChargeGausFit->SetParNames("Area","#mu","#sigma");
    794805  fChargeGausFit->SetParLimits(0,0.,entries);
    795   fChargeGausFit->SetParLimits(1,rmin,fChargeLastHiGain);
    796   fChargeGausFit->SetParLimits(2,0.,fChargeLastHiGain-rmin);
    797   fChargeGausFit->SetRange(rmin,fChargeLastHiGain);
    798 
    799   fHChargeHiGain->Fit(fChargeGausFit,option);
    800  
    801   Axis_t rtry = fChargeGausFit->GetParameter(1) - 2.0*fChargeGausFit->GetParameter(2);
    802  
    803   rmin = (rtry < rmin ? rmin : rtry);
    804   rmax = fChargeGausFit->GetParameter(1) + 3.5*fChargeGausFit->GetParameter(2);
    805   fChargeGausFit->SetRange(rmin,rmax); 
    806 
    807   fHChargeHiGain->Fit(fChargeGausFit,option);
    808 
     806  fChargeGausFit->SetParLimits(1,rmin,rmax);
     807  fChargeGausFit->SetParLimits(2,0.,rmax-rmin);
     808  fChargeGausFit->SetRange(rmin,rmax);
     809
     810  hist->Fit(fChargeGausFit,option);
     811 
     812  //
     813  // If we are not able to fit, try once again
     814  //
     815  if (fChargeGausFit->GetProb() < gkProbLimit)
     816    {
     817
     818      Axis_t rtry = fChargeGausFit->GetParameter(1) - 3.0*fChargeGausFit->GetParameter(2);
     819      rmin        = (rtry < rmin ? rmin : rtry);
     820      rmax        = fChargeGausFit->GetParameter(1) + 3.0*fChargeGausFit->GetParameter(2);
     821      fChargeGausFit->SetRange(rmin,rmax); 
     822
     823      fHChargeHiGain->Fit(fChargeGausFit,option);
     824    }
     825 
    809826  fChargeChisquare = fChargeGausFit->GetChisquare();
    810827  fChargeNdf       = fChargeGausFit->GetNDF();
     
    816833
    817834  //
    818   // The fit result is accepted under condition
     835  // The fit result is accepted under condition:
     836  // The Results are not nan's
    819837  // The Probability is greater than gkProbLimit (default 0.001 == 99.9%)
    820838  //
    821   if (fChargeProb < gkProbLimit)
    822     {
    823       //      *fLog << warn << "WARNING: Fit Probability " << fChargeProb
    824       //            << " is smaller than the allowed value: " << gkProbLimit << endl;
     839  if (TMath::IsNaN(fChargeMean) || TMath::IsNaN(fChargeMeanErr))
     840    {
    825841      CLRBIT(fFlags,kFitOK);
    826842      return kFALSE;
    827843    }
    828844 
     845  if ((fChargeProb < gkProbLimit) || (TMath::IsNaN(fChargeProb)))
     846    {
     847      CLRBIT(fFlags,kFitOK);
     848      return kFALSE;
     849    }
     850 
    829851  SETBIT(fFlags,kFitOK);
    830852  return kTRUE;
     
    832854
    833855
    834 Bool_t MHCalibrationPixel::FitChargeLoGain(Option_t *option)
    835 {
    836 
    837   if (fChargeGausFit)
    838     return kFALSE;
    839 
    840   //
    841   // Get the fitting ranges
    842   //
    843   Axis_t rmin = (fLowerFitRange != 0.) ? fLowerFitRange : fChargeFirstLoGain;
    844   Axis_t rmax = 0.;
    845 
    846   //
    847   // First guesses for the fit (should be as close to reality as possible,
    848   // otherwise the fit goes gaga because of high number of dimensions ...
    849   //
    850   const Stat_t   entries    = fHChargeLoGain->Integral();
    851   const Double_t area_guess = entries/gkSq2Pi;
    852   const Double_t mu_guess   = fHChargeLoGain->GetBinCenter(fHChargeLoGain->GetMaximumBin());
    853   const Double_t sigma_guess = mu_guess/15.;
    854 
    855   TString name = TString("ChargeGausFit");
    856   name += fPixId;
    857 
    858   fChargeGausFit = new TF1(name.Data(),"gaus",rmin,fChargeLastLoGain);
    859 
    860   if (!fChargeGausFit)
    861     {
    862     *fLog << warn << dbginf << "WARNING: Could not create fit function for Charges fit" << endl;
    863     return kFALSE;
    864     }
    865  
    866   fChargeGausFit->SetParameters(area_guess,mu_guess,sigma_guess);
    867   fChargeGausFit->SetParNames("Area","#mu","#sigma");
    868   fChargeGausFit->SetParLimits(0,0.,entries);
    869   fChargeGausFit->SetParLimits(1,rmin,fChargeLastLoGain);
    870   fChargeGausFit->SetParLimits(2,0.,fChargeLastLoGain-rmin);
    871   fChargeGausFit->SetRange(rmin,fChargeLastLoGain);
    872 
    873   fHChargeLoGain->Fit(fChargeGausFit,option);
    874  
    875   Axis_t rtry = fChargeGausFit->GetParameter(1) - 2.*fChargeGausFit->GetParameter(2);
    876  
    877   rmin = (rtry < rmin ? rmin : rtry);
    878   rmax = fChargeGausFit->GetParameter(1) + 3.5*fChargeGausFit->GetParameter(2);
    879   fChargeGausFit->SetRange(rmin,rmax); 
    880 
    881   fHChargeLoGain->Fit(fChargeGausFit,option);
    882 
    883   //  rmin = fChargeGausFit->GetParameter(1) - 2.5*fChargeGausFit->GetParameter(2);
    884   //  rmax = fChargeGausFit->GetParameter(1) + 2.5*fChargeGausFit->GetParameter(2);
    885   //  fChargeGausFit->SetRange(rmin,rmax); 
    886 
    887   // fHChargeLoGain->Fit(fChargeGausFit,option);
    888 
    889   fChargeChisquare = fChargeGausFit->GetChisquare();
    890   fChargeNdf       = fChargeGausFit->GetNDF();
    891   fChargeProb      = fChargeGausFit->GetProb();
    892   fChargeMean      = fChargeGausFit->GetParameter(1);
    893   fChargeMeanErr   = fChargeGausFit->GetParError(1);
    894   fChargeSigma     = fChargeGausFit->GetParameter(2);
    895   fChargeSigmaErr  = fChargeGausFit->GetParError(2);
    896 
    897   //
    898   // The fit result is accepted under condition
    899   // The Probability is greater than gkProbLimit (default 0.01 == 99%)
    900   //
    901   if (fChargeProb < gkProbLimit)
    902     {
    903       //      *fLog << warn << "WARNING: Fit Probability " << fChargeProb
    904       //            << " is smaller than the allowed value: " << gkProbLimit << endl;
    905       CLRBIT(fFlags,kFitOK);
    906       return kFALSE;
    907     }
    908  
    909   SETBIT(fFlags,kFitOK);
    910    
    911   return kTRUE;
    912 }
    913856
    914857 
Note: See TracChangeset for help on using the changeset viewer.