Changeset 3636 for trunk/MagicSoft/Mars/mcalib/MHGausEvents.cc
- Timestamp:
- 04/03/04 17:27:50 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mcalib/MHGausEvents.cc
r3625 r3636 40 40 // It is created with a default name and title and resides in directory NULL. 41 41 // - Any class deriving from MHGausEvents needs to apply a binning to fHGausHist 42 // (e.g. with the function TH1F::SetBins(..) ) 42 // (e.g. by setting the variables fNbins, fFirst, fLast and calling the function 43 // InitBins() or by directly calling fHGausHist.SetBins(..) ) 43 44 // - The histogram is filled with the functions FillHist() or FillHistAndArray(). 44 45 // - The histogram can be fitted with the function FitGaus(). This involves stripping … … 48 49 // The NDF is compared to fNDFLimit and a check is made whether results are NaNs. 49 50 // Accordingly, a flag IsGausFitOK() is set. 51 // - One can repeat the fit within a given amount of sigmas from the previous mean 52 // (specified by the variable fPickupLimit) with the function RepeatFit() 53 // - One can completely skip the fitting to set mean, sigma and its errors directly 54 // from the histograms with the function BypassFit() 50 55 // 51 56 // 2) The TArrayF fEvents: … … 96 101 const Float_t MHGausEvents::fgProbLimit = 0.001; 97 102 const Int_t MHGausEvents::fgNDFLimit = 2; 103 const Float_t MHGausEvents::fgPickupLimit = 5.; 98 104 const Int_t MHGausEvents::fgPowerProbabilityBins = 20; 99 105 const Int_t MHGausEvents::fgBinsAfterStripping = 40; … … 105 111 // - the default Probability Limit for fProbLimit (fgProbLimit) 106 112 // - the default NDF Limit for fNDFLimit (fgNDFLimit) 113 // - the default number for fPickupLimit (fgPickupLimit) 107 114 // - the default number of bins after stripping for fBinsAfterStipping (fgBinsAfterStipping) 108 115 // - the default name of the fHGausHist ("HGausHist") 109 116 // - the default title of the fHGausHist ("Histogram of Events with Gaussian Distribution") 110 117 // - the default directory of the fHGausHist (NULL) 118 // - the default for fNbins (100) 119 // - the default for fFirst (0.) 120 // - the default for fLast (100.) 111 121 // 112 122 // Initializes: … … 121 131 fPowerSpectrum(NULL), 122 132 fGraphEvents(NULL), fGraphPowerSpectrum(NULL), 133 fNbins(100), fFirst(0.), fLast(100.), fPixId(-1), 123 134 fHGausHist(), fEvents(0), 124 135 fFGausFit(NULL), fFExpFit(NULL) … … 133 144 SetProbLimit(); 134 145 SetNDFLimit(); 146 SetPickupLimit(); 135 147 SetBinsAfterStripping(); 136 148 … … 183 195 // -------------------------------------------------------------------------- 184 196 // 197 // Default Clear(), can be overloaded. 198 // 185 199 // Sets: 186 200 // - all other pointers to NULL 187 // - all variables to 0., except f EventFrequency201 // - all variables to 0., except fPixId to -1 and keep fEventFrequency 188 202 // - all flags to kFALSE 189 203 // … … 197 211 SetExpFitOK ( kFALSE ); 198 212 SetFourierSpectrumOK( kFALSE ); 213 SetExcluded ( kFALSE ); 199 214 200 215 fMean = 0.; … … 205 220 206 221 fCurrentSize = 0; 222 fPixId = -1; 207 223 208 224 if (fHPowerProbability) … … 247 263 248 264 // -------------------------------------------------------------------------- 265 // 266 // Default Reset(), can be overloaded. 249 267 // 250 268 // Executes: … … 264 282 // -------------------------------------------------------------------------- 265 283 // 284 // Default InitBins, can be overloaded. 285 // 286 // Executes: 287 // - fHGausHist.SetBins(fNbins,fFirst,fLast) 288 // 289 void MHGausEvents::InitBins() 290 { 291 fHGausHist.SetBins(fNbins,fFirst,fLast); 292 } 293 294 // -------------------------------------------------------------------------- 295 // 266 296 // Executes: 267 297 // - FillArray() … … 303 333 } 304 334 335 // -------------------------------------------------------------------------- 336 // 337 // Set Excluded bit from outside 338 // 339 void MHGausEvents::SetExcluded(const Bool_t b) 340 { 341 b ? SETBIT(fFlags,kExcluded) : CLRBIT(fFlags,kExcluded); 342 } 343 305 344 306 345 const Double_t MHGausEvents::GetChiSquare() const … … 366 405 { 367 406 return TESTBIT(fFlags,kExpFitOK); 407 } 408 409 const Bool_t MHGausEvents::IsExcluded() const 410 { 411 return TESTBIT(fFlags,kExcluded); 368 412 } 369 413 … … 409 453 if (fFExpFit) 410 454 return; 455 456 if (fEvents.GetSize() < 8) 457 { 458 *fLog << warn << "Cannot create Fourier spectrum in pixel: " << fPixId 459 << ". Number of events smaller than 8 " << endl; 460 return; 461 } 462 411 463 412 464 // … … 424 476 // This cuts only the non-used zero's, but MFFT will later cut the rest 425 477 MArray::StripZeros(fEvents); 478 479 if (fEvents.GetSize() < 8) 480 { 481 *fLog << warn << "Cannot create Fourier spectrum. " << endl; 482 *fLog << warn << "Number of events (after stripping of zeros) is smaller than 8 " 483 << "in pixel: " << fPixId << endl; 484 return; 485 } 426 486 427 487 MFFT fourier; … … 506 566 if (!fFGausFit) 507 567 { 508 *fLog << warn << dbginf << "WARNING: Could not create fit function for Gauss fit" << endl; 568 *fLog << warn << dbginf << "WARNING: Could not create fit function for Gauss fit " 569 << "in pixel: " << fPixId << endl; 509 570 return kFALSE; 510 571 } … … 528 589 // The fit result is accepted under condition: 529 590 // 1) The results are not nan's 530 // 2) The NDF is not smaller than fNDFLimit ( 5)531 // 3) The Probability is greater than fProbLimit (default 0.001 == 99.9%)591 // 2) The NDF is not smaller than fNDFLimit (default: fgNDFLimit) 592 // 3) The Probability is greater than fProbLimit (default: fgProbLimit) 532 593 // 533 594 if ( TMath::IsNaN(fMean) … … 545 606 546 607 // ----------------------------------------------------------------------------- 608 // 609 // If flag IsGausFitOK() is set (histogram already successfully fitted), 610 // returns kTRUE 611 // 612 // If both fMean and fSigma are still zero, call FitGaus() 613 // 614 // Repeats the Gauss fit in a smaller range, defined by: 615 // 616 // min = GetMean() - fPickupLimit * GetSigma(); 617 // max = GetMean() + fPickupLimit * GetSigma(); 618 // 619 // The fit results are retrieved and stored in class-own variables. 620 // 621 // A flag IsGausFitOK() is set according to whether the fit probability 622 // is smaller or bigger than fProbLimit, whether the NDF is bigger than 623 // fNDFLimit and whether results are NaNs. 624 // 625 Bool_t MHGausEvents::RepeatFit(const Option_t *option) 626 { 627 628 if (IsGausFitOK()) 629 return kTRUE; 630 631 if ((fMean == 0.) && (fSigma == 0.)) 632 return FitGaus(); 633 634 // 635 // Get new fitting ranges 636 // 637 Axis_t rmin = fMean - fPickupLimit * fSigma; 638 Axis_t rmax = fMean + fPickupLimit * fSigma; 639 640 Axis_t hmin = fHGausHist.GetBinCenter(fHGausHist.GetXaxis()->GetFirst()); 641 Axis_t hmax = fHGausHist.GetBinCenter(fHGausHist.GetXaxis()->GetLast()) ; 642 643 fFGausFit->SetRange(hmin < rmin ? rmin : hmin , hmax > rmax ? rmax : hmax); 644 645 fHGausHist.Fit(fFGausFit,option); 646 647 fMean = fFGausFit->GetParameter(1); 648 fMeanErr = fFGausFit->GetParameter(2); 649 fSigma = fFGausFit->GetParError(1) ; 650 fSigmaErr = fFGausFit->GetParError(2) ; 651 fProb = fFGausFit->GetProb() ; 652 653 // 654 // The fit result is accepted under condition: 655 // 1) The results are not nan's 656 // 2) The NDF is not smaller than fNDFLimit (default: fgNDFLimit) 657 // 3) The Probability is greater than fProbLimit (default: fgProbLimit) 658 // 659 if ( TMath::IsNaN ( fMean ) 660 || TMath::IsNaN ( fMeanErr ) 661 || TMath::IsNaN ( fProb ) 662 || TMath::IsNaN ( fSigma ) 663 || TMath::IsNaN ( fSigmaErr ) 664 || fFGausFit->GetNDF() < fNDFLimit 665 || fProb < fProbLimit ) 666 return kFALSE; 667 668 SetGausFitOK(kTRUE); 669 return kTRUE; 670 671 } 672 673 // ----------------------------------------------------------------------------- 547 674 // 548 675 // Bypasses the Gauss fit by taking mean and RMS from the histogram … … 559 686 if (entries <= 0.) 560 687 { 561 *fLog << warn << GetDescriptor() << ": Cannot bypass fit. Number of entries smaller or equal 0" << endl; 688 *fLog << warn << GetDescriptor() 689 << ": Cannot bypass fit. Number of entries smaller or equal 0 in pixel: " << fPixId << endl; 562 690 return; 563 691 } 564 692 565 SetMean ( fHGausHist.GetMean());566 SetMeanErr ( fHGausHist.GetRMS() / TMath::Sqrt(entries));567 SetSigma ( fHGausHist.GetRMS() );568 SetSigmaErr ( fHGausHist.GetRMS() / TMath::Sqrt(entries) / 2. );693 fMean = fHGausHist.GetMean(); 694 fMeanErr = fHGausHist.GetRMS() / TMath::Sqrt(entries); 695 fSigma = fHGausHist.GetRMS() ; 696 fSigmaErr = fHGausHist.GetRMS() / TMath::Sqrt(entries) / 2.; 569 697 } 570 698 … … 577 705 578 706 *fLog << all << endl; 579 *fLog << all << "Results of the Gauss Fit : "<< endl;707 *fLog << all << "Results of the Gauss Fit in pixel: " << fPixId << endl; 580 708 *fLog << all << "Mean: " << GetMean() << endl; 581 709 *fLog << all << "Sigma: " << GetSigma() << endl; … … 585 713 *fLog << all << endl; 586 714 715 } 716 717 // -------------------------------------------------------------------------- 718 // 719 // - Set fPixId to id 720 // 721 // Add id to names and titles of: 722 // - fHGausHist 723 // 724 void MHGausEvents::ChangeHistId(Int_t id) 725 { 726 727 fPixId = id; 728 729 fHGausHist.SetName( Form("%s%d", fHGausHist.GetName(), id)); 730 fHGausHist.SetTitle( Form("%s%d", fHGausHist.GetTitle(), id)); 731 732 fName = Form("%s%d", fName.Data(), id); 733 fTitle = Form("%s%d", fTitle.Data(), id); 734 587 735 } 588 736 … … 766 914 } 767 915 768 916 const Double_t MHGausEvents::GetPickup() const 917 { 918 919 if ((fMean == 0.) && (fSigma == 0.)) 920 return -1.; 921 922 const Int_t first = fHGausHist.GetXaxis()->FindBin(fMean+fPickupLimit*fSigma); 923 const Int_t last = fHGausHist.GetXaxis()->GetLast(); 924 925 if (first >= last) 926 return 0.; 927 928 return fHGausHist.Integral(first, last, "width"); 929 } 930 931
Note:
See TracChangeset
for help on using the changeset viewer.