- Timestamp:
- 03/19/04 20:19:03 (21 years ago)
- Location:
- trunk/MagicSoft/Mars/mhist
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mhist/MHFalseSource.cc
r3550 r3557 103 103 #include <TStyle.h> 104 104 #include <TCanvas.h> 105 #include <TPaveText.h> 105 106 106 107 #include "MGeomCam.h" … … 490 491 491 492 TH1 *h = fHist.ProjectionZ("Alpha", maxx, maxx, maxy, maxy); 492 h->SetTitle(Form("Distribution of \\alpha for x=%.2f y=%.2f (\\sigma =%.1f)", x, y, s));493 h->SetTitle(Form("Distribution of \\alpha for x=%.2f y=%.2f (\\sigma_{max}=%.1f)", x, y, s)); 493 494 } 494 495 } … … 616 617 617 618 618 void MHFalseSource::FitSignificance( )619 { 620 TH1D h0a("A", "Parameter A", 50, 0, 4000);621 TH1D h0b("a", "Parameter a", 50, 0, 4000);622 TH1D h1("mu", "Parameter mu",50, -1, 1);623 TH1D h2("sigma", "Parameter sigma",50, 0, 90);624 TH1D h3("b", "Parameter b", 50, -0.1, 0.1);625 TH1D h4a("chisq1", "\\chi^{2} ", 50, 0, 35);626 TH1D h5a("prob1", "Fit probability", 50, 0, 1.1);627 TH1D h4b("chisq2", "\\chi^{2} ", 50, 0, 35);628 TH1D h5b("prob 2", "Fit probability",50, 0, 1.1);629 TH1D h6("Signif", "Significance", 50, -20, 20);619 void MHFalseSource::FitSignificance(Float_t sigmax, Float_t bgmin, Float_t bgmax) 620 { 621 TH1D h0a("A", "Parameter A", 50, 0, 4000); 622 TH1D h0b("a", "Parameter a", 50, 0, 4000); 623 TH1D h1("mu", "Parameter \\mu", 50, -1, 1); 624 TH1D h2("sigma", "Parameter \\sigma", 50, 0, 90); 625 TH1D h3("b", "Parameter b", 50, -0.1, 0.1); 626 TH1D h4a("chisq1", "\\chi^{2} (red, green) / significance (black)", 50, 0, 35); 627 TH1D h5a("prob1", "Fit probability", 50, 0, 1.1); 628 TH1D h4b("chisq2", "\\chi^{2} (red, green) / significance (black)", 50, 0, 35); 629 TH1D h5b("prob", "Fit probability", 50, 0, 1.1); 630 TH1D h6("Signif", "Significance", 50, -20, 20); 630 631 h0a.SetDirectory(NULL); 631 632 h0b.SetDirectory(NULL); … … 647 648 648 649 TH1 *hist = fHist.Project3D("xy_fit"); 650 hist->Reset(); 651 hist->SetNameTitle("Significance", 652 Form("Fit Region: Signal<%.1f\\circ, %.1f\\circ<Bg<%.1f\\circ", 653 sigmax, bgmin, bgmax)); 654 hist->SetXTitle(fHist.GetXaxis()->GetTitle()); 655 hist->SetYTitle(fHist.GetXaxis()->GetTitle()); 649 656 650 657 // xmin, xmax, npar 651 658 TF1 func("MyFunc", fcn, 0, 90, 5); 652 653 TArrayD samx(50); 654 TArrayD samw(50); 655 656 // func.CalcGaussLegendreSamplingPoints(50, samx.GetArray(), samw.GetArray()); 657 // func.IntegralFast(50, samx.GetArray(), samw.GetArray(), 0, 15); 659 TArrayD par(5); 658 660 659 661 func.SetParName(0, "A"); … … 668 670 const Int_t ny = fHist.GetYaxis()->GetNbins(); 669 671 672 Double_t maxalpha0=0; 670 673 Double_t maxs=3; 671 TH1 *result=0; 672 TF1 *fres=0;673 674 675 Int_t maxx=0; 676 Int_t maxy=0; 674 677 675 678 TH1 *h=0; … … 679 682 h = fHist.ProjectionZ("AlphaFit", ix+1, ix+1, iy+1, iy+1); 680 683 684 const Double_t alpha0 = h->GetBinContent(1); 685 681 686 // Check for the regios which is not filled... 682 if ( h->GetBinContent(1)==0)687 if (alpha0==0) 683 688 continue; 689 690 if (alpha0>maxalpha0) 691 maxalpha0=alpha0; 684 692 685 693 // First fit a polynom in the off region … … 690 698 func.ReleaseParameter(4); 691 699 692 h->Fit(&func, "N0Q", "", 35, 75);700 h->Fit(&func, "N0Q", "", bgmin, bgmax); 693 701 //*fLog << dbg << ix << "/" << iy << ": " << func.GetParameter(3) << " " << func.GetParameter(4) << endl; 694 702 … … 697 705 698 706 // Now fit a gaus in the on region on top of the polynom 699 func.SetParameter(0, h->GetBinContent(1)-func.GetParameter(4));700 func.SetParameter(2, 80);707 func.SetParameter(0, alpha0-func.GetParameter(4)); 708 func.SetParameter(2, sigmax*0.75); 701 709 702 710 //func.SetParLimits(0, 0.5*h->GetBinContent(1), 1.5*h->GetBinContent(1)); … … 710 718 711 719 func.SetParLimits(2, 0, 80); 712 h->Fit(&func, "N0Q", "", 0, 35);720 h->Fit(&func, "N0Q", "", 0, sigmax); 713 721 //*fLog << dbg << " " << func.GetParameter(0) << " " << func.GetParameter(1) << " " << func.GetParameter(2) << endl; 714 722 … … 722 730 h5b.Fill(func.GetProb()); 723 731 732 Double_t sig=0; 733 724 734 const Int_t n = hist->GetBin(ix+1, iy+1); 725 if (func.GetParameter(0)>h->GetBinContent(1)*2 || 726 func.GetParameter(2)<2.5 || func.GetParameter(2)>70 727 /*func.GetProb()<0.005 ||*/) 735 if (!(func.GetParameter(0)>alpha0*2 || 736 func.GetParameter(2)<2.5 || 737 func.GetParameter(2)>70 738 /*func.GetProb()<0.005 ||*/)) 728 739 { 729 hist->SetBinContent(n, 0); 730 continue; 740 const Double_t b = FcnI1(15, func.GetParameters()); 741 const Double_t s = FcnI2(15, func.GetParameters()); 742 743 sig = Significance(s+b, b); 731 744 } 732 745 733 //*fLog << dbg << " Chisq=" << func.GetChisquare() << " NDF=" << func.GetNDF() 734 // << " Prob=" << func.GetProb() << " FitP=" << func.GetNumberFitPoints() << endl; 735 736 Double_t b = FcnI1(15, func.GetParameters()); 737 Double_t s = FcnI2(15, func.GetParameters()); 738 739 //*fLog << dbg << func.GetParameter(3) << ": " << b << " "; 740 //*fLog << dbg << func.GetParameter(0) << ": " << s; 741 //*fLog << endl; 742 743 if (b<0) 744 continue; 745 746 const Double_t sig = Significance(s+b, b); 747 748 hist->SetBinContent(n, sig); 749 h6.Fill(sig); 746 hist->SetBinContent(n, sig==0?1e-15:sig); 747 if (sig!=0) 748 h6.Fill(sig); 750 749 751 750 if (sig>maxs) 752 751 { 753 752 maxs = sig; 754 if (result) 755 { 756 delete result; 757 delete fres; 758 } 759 result=(TH1*)h->Clone("Result \\alpha"); 760 fres =(TF1*)func.Clone("Result Func"); 753 maxx = ix+1; 754 maxy = iy+1; 755 for(int i=0; i<par.GetSize(); i++) 756 par[i] = func.GetParameter(i); 761 757 } 762 758 } 763 759 764 h ist->SetMinimum(-10);765 h ist->SetMaximum(maxs);760 h0a.GetXaxis()->SetRangeUser(0, maxalpha0*1.5); 761 h0b.GetXaxis()->SetRangeUser(0, maxalpha0*1.5); 766 762 767 763 TCanvas *c=new TCanvas; 768 764 769 c->Divide(3,2 );765 c->Divide(3,2, 0, 0); 770 766 c->cd(1); 767 gPad->SetBorderMode(0); 768 gPad->Divide(1,2, 0, 0); 769 TVirtualPad *p=gPad; 770 p->SetBorderMode(0); 771 p->cd(1); 772 gPad->SetBorderMode(0); 771 773 h0b.DrawCopy(); 772 774 h0a.DrawCopy("same"); 775 p->cd(2); 776 gPad->SetBorderMode(0); 777 h3.DrawCopy(); 773 778 c->cd(2); 779 gPad->SetBorderMode(0); 774 780 hist->Draw("colz"); 775 781 hist->SetDirectory(NULL); 776 782 hist->SetBit(kCanDelete); 777 783 c->cd(3); 784 gPad->SetBorderMode(0); 785 h4b.DrawCopy(); 786 h4a.DrawCopy("same"); 787 h6.DrawCopy("same"); 788 c->cd(4); 789 gPad->SetBorderMode(0); 778 790 h2.DrawCopy(); 779 c->cd(4); 780 h3.DrawCopy(); 791 c->cd(6); 792 gPad->SetBorderMode(0); 793 h5b.DrawCopy(); 794 h5a.DrawCopy("same"); 795 781 796 c->cd(5); 782 h4a.DrawCopy(); 783 h4b.DrawCopy("same"); 784 h6.DrawCopy("same"); 785 c->cd(6); 786 h5a.DrawCopy(); 787 h5b.DrawCopy("same"); 788 789 if (result) 790 { 791 c=new TCanvas; 797 gPad->SetBorderMode(0); 798 if (maxx>0 && maxy>0) 799 { 800 const char *title = Form(" \\alpha for x=%.2f y=%.2f (\\sigma_{max}=%.1f) ", 801 fHist.GetXaxis()->GetBinCenter(maxx), 802 fHist.GetYaxis()->GetBinCenter(maxy), maxs); 803 TH1 *result = fHist.ProjectionZ("AlphaFit", maxx, maxx, maxy, maxy); 804 result->SetNameTitle("Result \\alpha", title); 792 805 result->SetBit(kCanDelete); 806 result->SetXTitle("\\alpha [\\circ]"); 807 result->SetYTitle("Counts"); 793 808 result->Draw(); 794 809 795 810 TF1 f1("MyFunc1", fcn, 0, 90, 5); 796 811 TF1 f2("MyFunc2", fcn, 0, 90, 5); 797 f1.SetParameters( fres->GetParameters());798 f2.SetParameters( fres->GetParameters());812 f1.SetParameters(par.GetArray()); 813 f2.SetParameters(par.GetArray()); 799 814 f2.FixParameter(0, 0); 800 815 f2.FixParameter(1, 0); … … 806 821 f1.DrawCopy("same"); 807 822 808 delete fres; 809 } 810 } 811 823 TPaveText *leg = new TPaveText(0.35, 0.10, 0.90, 0.35, "brNDC"); 824 leg->SetBorderSize(1); 825 leg->SetTextSize(0.04); 826 leg->AddText(0.5, 0.82, "A * exp(-(\\frac{x-\\mu}{\\sigma})^{2}/2) + b*x^{2} + a")->SetTextAlign(22); 827 leg->AddLine(0, 0.65, 0, 0.65); 828 leg->AddText(0.06, 0.54, Form("A=%.2f", par[0]))->SetTextAlign(11); 829 leg->AddText(0.06, 0.34, Form("\\sigma=%.2f", par[2]))->SetTextAlign(11); 830 leg->AddText(0.06, 0.14, Form("\\mu=%.2f (fixed)", par[1]))->SetTextAlign(11); 831 leg->AddText(0.60, 0.54, Form("a=%.2f", par[3]))->SetTextAlign(11); 832 leg->AddText(0.60, 0.34, Form("b=%.2f", par[4]))->SetTextAlign(11); 833 leg->SetBit(kCanDelete); 834 leg->Draw(); 835 } 836 837 } -
trunk/MagicSoft/Mars/mhist/MHFalseSource.h
r3550 r3557 51 51 TH1 *GetHistByName(const TString name) { return &fHist; } 52 52 53 void FitSignificance(); //*MENU* 53 void FitSignificance(Float_t sigmax=35, Float_t bgmin=40, Float_t bgmax=80); //*MENU* 54 void FitSignificanceStd() { FitSignificance(); } //*MENU* 54 55 55 56 void SetAlphaCut(Float_t alpha); //*MENU*
Note:
See TracChangeset
for help on using the changeset viewer.