Changeset 3574 for trunk/MagicSoft/Mars/mhist
- Timestamp:
- 03/22/04 14:49:21 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mhist/MHFalseSource.cc
r3568 r3574 625 625 gPad->cd(); 626 626 } 627 /*628 Double_t fcn(Double_t *arg, Double_t *p)629 {630 const Double_t x = arg[0];631 632 const Double_t dx = (x-p[1])/p[2];633 634 const Double_t f1 = p[0]*TMath::Exp(-0.5*dx*dx);635 const Double_t f2 = p[3] + p[5]*x*x;636 637 return f1 + f2;638 }639 640 Double_t FcnI1(Double_t x, Double_t *p)641 {642 return (p[5]*x*x/3+p[3])*x;643 }644 Double_t FcnI2(Double_t x, Double_t *p)645 {646 static const Double_t sqrt2 = TMath::Sqrt(2.);647 static const Double_t sqrt2pi = TMath::Sqrt(TMath::TwoPi());648 649 const Double_t dx = (x-p[1])/p[2];650 651 const Double_t f2 = p[0]*p[2]*sqrt2pi*TMath::Erf(dx/sqrt2)/2;652 653 return f2;654 }655 */656 /*657 class MHSignificance : public MH658 {659 private:660 TH1D fHist;661 662 MParameterD *fParam;663 664 public:665 MHSignificance() : fParam(0)666 {667 fHist.SetName("Alpha");668 fHist.SetTitle("Distribution of \\alpha");669 fHist.SetXTitle("\\alpha [\\circ]");670 fHist.SetYTitle("Counts");671 }672 Int_t SetupFill(MParList *p)673 {674 fHist.Reset();675 676 fParam = (MParameterD*)p->FindCreateObj("Significance", "MParameterD");677 if (fParam)678 return kFALSE;679 680 return kTRUE;681 }682 Int_t Process(MParContainer *p, Double_t w=1)683 {684 MHillasSrc *hil = dynamic_cast<MHillasSrc*>(p);685 if (!hil)686 {687 *fLog << err << dbginf << "Got no MHillasSrc as argument of Fill()..." << endl;688 return kFALSE;689 }690 691 fHist->Fill(hil->GetAlpha(), w);692 693 return kTRUE;694 }695 Int_t Finalize()696 {697 if (fHist.GetEntries()==0)698 {699 *fLog << err << "Histogram empty." << endl;700 return kFALSE;701 }702 703 Float_t sigmax=15;704 Float_t bgmin =45;705 Float_t bgmax =80;706 707 fHist.SetNameTitle("Significance",708 Form("Fit Region: Signal<%.1f\\circ, %.1f\\circ<Bg<%.1f\\circ",709 sigmax, bgmin, bgmax));710 711 // Implementing the function yourself is not faster at all!712 TF1 func("gaus(0) + pol2(3)", fcn, 0, 90, 6);713 TArrayD maxpar(func.GetNpar());714 715 func.FixParameter(1, 0);716 func.FixParameter(4, 0);717 func.SetParLimits(3, -1, 1);718 719 const Double_t alpha0 = fHist.GetBinContent(1);720 721 // First fit a polynom in the off region722 func.FixParameter(0, 0);723 func.FixParameter(2, 1);724 func.ReleaseParameter(3);725 func.ReleaseParameter(5);726 727 h->Fit(&func, "N0Q", "", bgmin, bgmax);728 729 // Now fit a gaus in the on region on top of the polynom730 func.SetParameter(0, alpha0-func.GetParameter(4));731 func.SetParameter(2, sigmax*0.75);732 733 func.ReleaseParameter(0);734 func.ReleaseParameter(2);735 func.FixParameter(3, func.GetParameter(3));736 func.FixParameter(5, func.GetParameter(5));737 738 func.SetParLimits(2, 0, 80);739 h->Fit(&func, "N0Q", "", 0, sigmax);740 741 TArrayD p(func.GetNpar(), func.GetParameters());742 743 Double_t sig=0;744 745 const Int_t n = hist->GetBin(ix+1, iy+1);746 if (!(func.GetParameter(0)>alpha0*2 ||747 func.GetParameter(2)<2.5 ||748 func.GetParameter(2)>70))749 {750 // Implementing the integral as analytical function751 // gives the same result in the order of 10e-5752 // and it is not faster at all...753 const Double_t s = func.Integral(0, 15);754 755 func.SetParameter(0, 0);756 func.SetParameter(2, 1);757 758 const Double_t b = func.Integral(0, 15);759 760 sig = Significance(s, b);761 }762 763 fParam->SetValue(sig);764 fParam->SetReadyToSave();765 return kTRUE;766 }767 ClassDef(MHSignificance, 0)768 };769 */770 771 627 772 628 // -------------------------------------------------------------------------- … … 843 699 histb->SetYTitle(fHist.GetXaxis()->GetTitle()); 844 700 701 const Double_t w = fHist.GetZaxis()->GetBinWidth(1); 702 845 703 // xmin, xmax, npar 846 704 //TF1 func("MyFunc", fcn, 0, 90, 6); … … 889 747 890 748 const Double_t alpha0 = h->GetBinContent(1); 891 const Double_t alphaw = h->GetXaxis()->GetBinWidth(1);892 749 893 750 // Check for the regios which is not filled... … … 959 816 */ 960 817 961 const Double_t s = func.Integral(0, sigint); 818 // The fitted function returned units of 819 // counts bin binwidth. To get the correct number 820 // of events we must adapt the functions by dividing 821 // the result of the integration by the bin-width 822 const Double_t s = func.Integral(0, sigint)/w; 962 823 963 824 func.SetParameter(0, 0); 964 825 func.SetParameter(2, 1); 965 826 966 const Double_t b = func.Integral(0, sigint) ;827 const Double_t b = func.Integral(0, sigint)/w; 967 828 const Double_t sig = Significance(s, b); 968 829
Note:
See TracChangeset
for help on using the changeset viewer.