Changeset 5012 for trunk/MagicSoft/Mars/mhflux
- Timestamp:
- 09/14/04 19:04:01 (20 years ago)
- Location:
- trunk/MagicSoft/Mars/mhflux
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mhflux/MAlphaFitter.cc
r5006 r5012 86 86 Double_t sigint=fSigInt; 87 87 Double_t sigmax=fSigMax; 88 Double_t bgmin=fBgMin; 89 Double_t bgmax=fBgMax; 90 Byte_t polynom=fPolynomOrder; 88 Double_t bgmin =fBgMin; 89 Double_t bgmax =fBgMax; 91 90 92 // Implementing the function yourself is only about 5% faster 93 TF1 func("", Form("gaus(0) + pol%d(3)", polynom), 0, 90); 94 //TF1 func("", Form("[0]*(TMath::Gaus(x, [1], [2])+TMath::Gaus(x, -[1], [2]))+pol%d(3)", polynom), 0, 90); 91 //TF1 fFunc("", Form("gaus(0) + pol%d(3)", fPolynomOrder), 0, 90); 95 92 96 if (fCoefficients.GetSize() != polynom+3) 97 { 98 fCoefficients.Set(polynom+3); 99 fCoefficients.Reset(); 100 } 101 else 102 func.SetParameters(fCoefficients.GetArray()); 93 //fFunc->SetParameters(fCoefficients.GetArray()); 103 94 104 f unc.FixParameter(1, 0);105 f unc.FixParameter(4, 0);106 f unc.SetParLimits(2, 0, 90);107 f unc.SetParLimits(3, -1, 1);95 fFunc->FixParameter(1, 0); 96 fFunc->FixParameter(4, 0); 97 fFunc->SetParLimits(2, 0, 90); 98 fFunc->SetParLimits(3, -1, 1); 108 99 109 100 const Double_t alpha0 = h.GetBinContent(1); … … 115 106 116 107 // First fit a polynom in the off region 117 f unc.FixParameter(0, 0);118 f unc.FixParameter(2, 1);119 f unc.ReleaseParameter(3);108 fFunc->FixParameter(0, 0); 109 fFunc->FixParameter(2, 1); 110 fFunc->ReleaseParameter(3); 120 111 121 for (int i=5; i<f unc.GetNpar(); i++)122 f unc.ReleaseParameter(i);112 for (int i=5; i<fFunc->GetNpar(); i++) 113 fFunc->ReleaseParameter(i); 123 114 124 115 // options : N do not store the function, do not draw … … 126 117 // R use the range specified in the function range 127 118 // Q quiet mode 128 h.Fit( &func, "NQI", "", bgmin, bgmax);119 h.Fit(fFunc, "NQI", "", bgmin, bgmax); 129 120 130 fChiSqBg = f unc.GetChisquare()/func.GetNDF();121 fChiSqBg = fFunc->GetChisquare()/fFunc->GetNDF(); 131 122 132 123 // ------------------------------------ 133 124 if (paint) 134 125 { 135 f unc.SetRange(0, 90);136 f unc.SetLineColor(kRed);137 f unc.SetLineWidth(2);138 f unc.Paint("same");126 fFunc->SetRange(0, 90); 127 fFunc->SetLineColor(kRed); 128 fFunc->SetLineWidth(2); 129 fFunc->Paint("same"); 139 130 } 140 131 // ------------------------------------ 141 132 142 f unc.ReleaseParameter(0);133 fFunc->ReleaseParameter(0); 143 134 //func.ReleaseParameter(1); 144 f unc.ReleaseParameter(2);145 f unc.FixParameter(3, func.GetParameter(3));146 for (int i=5; i<f unc.GetNpar(); i++)147 f unc.FixParameter(i, func.GetParameter(i));135 fFunc->ReleaseParameter(2); 136 fFunc->FixParameter(3, fFunc->GetParameter(3)); 137 for (int i=5; i<fFunc->GetNpar(); i++) 138 fFunc->FixParameter(i, fFunc->GetParameter(i)); 148 139 149 140 // Do not allow signals smaller than the background 150 const Double_t A = alpha0-f unc.GetParameter(3);141 const Double_t A = alpha0-fFunc->GetParameter(3); 151 142 const Double_t dA = TMath::Abs(A); 152 f unc.SetParLimits(0, -dA*4, dA*4);153 f unc.SetParLimits(2, 0, 90);143 fFunc->SetParLimits(0, -dA*4, dA*4); 144 fFunc->SetParLimits(2, 0, 90); 154 145 155 146 // Now fit a gaus in the on region on top of the polynom 156 f unc.SetParameter(0, A);157 f unc.SetParameter(2, sigmax*0.75);147 fFunc->SetParameter(0, A); 148 fFunc->SetParameter(2, sigmax*0.75); 158 149 159 150 // options : N do not store the function, do not draw … … 161 152 // R use the range specified in the function range 162 153 // Q quiet mode 163 h.Fit( &func, "NQI", "", 0, sigmax);154 h.Fit(fFunc, "NQI", "", 0, sigmax); 164 155 165 fChiSqSignal = f unc.GetChisquare()/func.GetNDF();166 fCoefficients.Set(f unc.GetNpar(), func.GetParameters());156 fChiSqSignal = fFunc->GetChisquare()/fFunc->GetNDF(); 157 fCoefficients.Set(fFunc->GetNpar(), fFunc->GetParameters()); 167 158 168 159 //const Bool_t ok = NDF>0 && chi2<2.5*NDF; … … 171 162 if (paint) 172 163 { 173 f unc.SetLineColor(kGreen);174 f unc.SetLineWidth(2);175 f unc.Paint("same");164 fFunc->SetLineColor(kGreen); 165 fFunc->SetLineWidth(2); 166 fFunc->Paint("same"); 176 167 } 177 168 // ------------------------------------ 178 //const Double_t s = func.Integral(0, sigint)/alphaw; 179 func.SetParameter(0, 0); 180 func.SetParameter(2, 1); 181 //const Double_t b = func.Integral(0, sigint)/alphaw; 182 183 //fSignificance = MMath::SignificanceLiMaSigned(s, b); 184 //exc = s-b; 169 const Double_t s = fFunc->Integral(0, sigint)/alphaw; 170 fFunc->SetParameter(0, 0); 171 fFunc->SetParameter(2, 1); 172 const Double_t b = fFunc->Integral(0, sigint)/alphaw; 173 fSignificance = MMath::SignificanceLiMaSigned(s, b); 185 174 186 175 const Double_t uin = 1.25*sigint; … … 188 177 189 178 fIntegralMax = h.GetBinLowEdge(bin+1); 190 fEventsBackground = f unc.Integral(0, fIntegralMax)/alphaw;179 fEventsBackground = fFunc->Integral(0, fIntegralMax)/alphaw; 191 180 fEventsSignal = h.Integral(0, bin); 192 181 fEventsExcess = fEventsSignal-fEventsBackground; 193 fSignificance = MMath::SignificanceLiMaSigned(fEventsSignal, fEventsBackground);182 //fSignificance = MMath::SignificanceLiMaSigned(fEventsSignal, fEventsBackground); 194 183 195 184 return kTRUE; -
trunk/MagicSoft/Mars/mhflux/MAlphaFitter.h
r5006 r5012 10 10 #endif 11 11 12 #ifndef ROOT_TF1 13 #include <TF1.h> 14 #endif 15 12 16 class TH1D; 13 17 … … 15 19 { 16 20 private: 21 TF1 *fFunc; 22 17 23 Float_t fSigInt; 18 24 Float_t fSigMax; … … 33 39 34 40 public: 35 MAlphaFitter() : fSigInt(10), fSigMax(75), fBgMin(45), fBgMax(85), fPolynomOrder(1) 41 // Implementing the function yourself is only about 5% faster 42 MAlphaFitter() : fFunc(new TF1("", "gaus(0) + pol1(3)", 0, 90)), fSigInt(10), fSigMax(75), fBgMin(45), fBgMax(85), fPolynomOrder(1), fCoefficients(3+fPolynomOrder+1) 36 43 { 37 44 } 38 45 39 MAlphaFitter(const MAlphaFitter &f) 46 MAlphaFitter(const MAlphaFitter &f) : fFunc(0) 40 47 { 41 48 f.Copy(*this); 49 } 50 ~MAlphaFitter() 51 { 52 delete fFunc; 42 53 } 43 54 … … 51 62 f.fBgMax = fBgMax; 52 63 f.fPolynomOrder = fPolynomOrder; 64 f.fCoefficients.Set(fCoefficients.GetSize()); 65 f.fCoefficients.Reset(); 66 67 TF1 *fcn = f.fFunc; 68 f.fFunc = new TF1(*fFunc); 69 delete fcn; 53 70 } 54 71 … … 57 74 void SetBackgroundFitMin(Float_t s) { fBgMin = s; } 58 75 void SetBackgroundFitMax(Float_t s) { fBgMax = s; } 59 void SetPolynomOrder(Int_t s) { fPolynomOrder = s; }76 void SetPolynomOrder(Int_t s) { fPolynomOrder = s; delete fFunc; fFunc=new TF1 ("", Form("gaus(0) + pol%d(3)", s)); fCoefficients.Set(3+s+1); fCoefficients.Reset(); } 60 77 61 78 Double_t GetEventsExcess() const { return fEventsExcess; } … … 76 93 77 94 Bool_t Fit(TH1D &h, Bool_t paint=kFALSE); 95 78 96 ClassDef(MAlphaFitter, 1) 79 97 }; -
trunk/MagicSoft/Mars/mhflux/MHAlpha.cc
r5006 r5012 140 140 void MHAlpha::FitEnergySpec(Bool_t paint) 141 141 { 142 TF1 f("Spectrum", "pow(x, [0])*exp(-x/[1])*[2]"); 143 f.SetParameter(0, -2.0); 144 f.SetParameter(1, 500); // 50 145 f.SetParameter(2, 1); // 50 142 /* 143 TF1 f("Spectrum", "pow(x, [0])*exp(-x/[1])*[2]*x");// 144 f.SetParameter(0, -2.1); 145 f.SetParameter(1, 1400); // 50 146 f.SetParameter(2, fHEnergy.Integral()); // 50 146 147 f.SetLineWidth(2); 147 f.SetLineColor(kGreen); 148 149 fHEnergy.Fit(&f, "0QI", "", 90, 1900); // Integral? 148 149 fHEnergy.Fit(&f, "0QI", "", 100, 2400); // Integral? 90, 2800 150 151 const Double_t chi2 = f.GetChisquare(); 152 const Int_t NDF = f.GetNDF(); 153 154 // was fit successful ? 155 const Bool_t ok = NDF>0 && chi2<2.5*NDF; 156 f.SetLineColor(ok ? kGreen : kRed); 150 157 151 158 if (paint) … … 153 160 f.Paint("same"); 154 161 155 TLatex text(0.2, 0.94, Form("\\alpha=%.1f E_{0}=%.1fGeV N=%.1f", 156 f.GetParameter(0), 157 f.GetParameter(1), 158 0/*f.GetParameter(2)*/)); 162 if (ok) 163 { 164 TString s; 165 s += Form("\\alpha=%.1f ", f.GetParameter(0)); 166 s += Form("E_{c}=%.1f TeV ", f.GetParameter(1)/1000); 167 s += Form("N=%.1e", f.GetParameter(2)); 168 169 TLatex text(0.25, 0.94, s.Data()); 159 170 text.SetBit(TLatex::kTextNDC); 160 171 text.SetTextSize(0.04); 161 172 text.Paint(); 162 } 173 } 174 }*/ 163 175 } 164 176 … … 449 461 if (o==(TString)"energy") 450 462 { 451 /*452 463 if (fHEnergy.GetEntries()>10) 453 464 { … … 455 466 gPad->SetLogy(); 456 467 } 457 FitEnergySpec(kTRUE); */468 FitEnergySpec(kTRUE); 458 469 459 470 } … … 525 536 } 526 537 527 // --------------------------------------------------------------------------528 //529 // This is a preliminary implementation of a alpha-fit procedure for530 // all possible source positions. It will be moved into its own531 // more powerfull class soon.532 //533 // The fit function is "gaus(0)+pol2(3)" which is equivalent to:534 // [0]*exp(-0.5*((x-[1])/[2])^2) + [3] + [4]*x + [5]*x^2535 // or536 // A*exp(-0.5*((x-mu)/sigma)^2) + a + b*x + c*x^2537 //538 // Parameter [1] is fixed to 0 while the alpha peak should be539 // symmetric around alpha=0.540 //541 // Parameter [4] is fixed to 0 because the first derivative at542 // alpha=0 should be 0, too.543 //544 // In a first step the background is fitted between bgmin and bgmax,545 // while the parameters [0]=0 and [2]=1 are fixed.546 //547 // In a second step the signal region (alpha<sigmax) is fittet using548 // the whole function with parameters [1], [3], [4] and [5] fixed.549 //550 // The number of excess and background events are calculated as551 // s = int(hist, 0, 1.25*sigint)552 // b = int(pol2(3), 0, 1.25*sigint)553 //554 // The Significance is calculated using the Significance() member555 // function.556 //557 /*558 Bool_t MAlphaFitter::Fit(TH1D &h, Bool_t paint)559 {560 Double_t sigint=fSigInt;561 Double_t sigmax=fSigMax;562 Double_t bgmin=fBgMin;563 Double_t bgmax=fBgMax;564 Byte_t polynom=fPolynom;565 566 // Implementing the function yourself is only about 5% faster567 TF1 func("", Form("gaus(0) + pol%d(3)", polynom), 0, 90);568 //TF1 func("", Form("[0]*(TMath::Gaus(x, [1], [2])+TMath::Gaus(x, -[1], [2]))+pol%d(3)", polynom), 0, 90);569 TArrayD maxpar(func.GetNpar());570 571 func.FixParameter(1, 0);572 func.FixParameter(4, 0);573 func.SetParLimits(2, 0, 90);574 func.SetParLimits(3, -1, 1);575 576 const Double_t alpha0 = h.GetBinContent(1);577 const Double_t alphaw = h.GetXaxis()->GetBinWidth(1);578 579 // Check for the regios which is not filled...580 if (alpha0==0)581 return kFALSE; //*fLog << warn << "Histogram empty." << endl;582 583 // First fit a polynom in the off region584 func.FixParameter(0, 0);585 func.FixParameter(2, 1);586 func.ReleaseParameter(3);587 588 for (int i=5; i<func.GetNpar(); i++)589 func.ReleaseParameter(i);590 591 // options : N do not store the function, do not draw592 // I use integral of function in bin rather than value at bin center593 // R use the range specified in the function range594 // Q quiet mode595 h.Fit(&func, "NQI", "", bgmin, bgmax);596 597 fChiSqBg = func.GetChisquare()/func.GetNDF();598 599 // ------------------------------------600 if (paint)601 {602 func.SetRange(0, 90);603 func.SetLineColor(kRed);604 func.SetLineWidth(2);605 func.Paint("same");606 }607 // ------------------------------------608 609 func.ReleaseParameter(0);610 //func.ReleaseParameter(1);611 func.ReleaseParameter(2);612 func.FixParameter(3, func.GetParameter(3));613 for (int i=5; i<func.GetNpar(); i++)614 func.FixParameter(i, func.GetParameter(i));615 616 // Do not allow signals smaller than the background617 const Double_t A = alpha0-func.GetParameter(3);618 const Double_t dA = TMath::Abs(A);619 func.SetParLimits(0, -dA*4, dA*4);620 func.SetParLimits(2, 0, 90);621 622 // Now fit a gaus in the on region on top of the polynom623 func.SetParameter(0, A);624 func.SetParameter(2, sigmax*0.75);625 626 // options : N do not store the function, do not draw627 // I use integral of function in bin rather than value at bin center628 // R use the range specified in the function range629 // Q quiet mode630 h.Fit(&func, "NQI", "", 0, sigmax);631 632 fChiSqSignal = func.GetChisquare()/func.GetNDF();633 fSigmaGaus = func.GetParameter(2);634 635 //const Bool_t ok = NDF>0 && chi2<2.5*NDF;636 637 // ------------------------------------638 if (paint)639 {640 func.SetLineColor(kGreen);641 func.SetLineWidth(2);642 func.Paint("same");643 }644 // ------------------------------------645 const Double_t s = func.Integral(0, sigint)/alphaw;646 func.SetParameter(0, 0);647 func.SetParameter(2, 1);648 const Double_t b = func.Integral(0, sigint)/alphaw;649 650 fSignificance = MMath::SignificanceLiMaSigned(s, b);651 //exc = s-b;652 653 const Double_t uin = 1.25*sigint;654 const Int_t bin = h.GetXaxis()->FindFixBin(uin);655 fIntegralMax = h.GetBinLowEdge(bin+1);656 fExcessEvents = h.Integral(0, bin)-func.Integral(0, fIntegralMax)/alphaw;657 658 return kTRUE;659 }660 661 void MAlphaFitter::PaintResult(Float_t x, Float_t y, Float_t size) const662 {663 TLatex text(x, y, Form("\\sigma_{Li/Ma}=%.1f (\\alpha<%.1f\\circ) \\omega=%.1f\\circ E=%d (\\alpha<%.1f\\circ) (\\chi_{b}^{2}=%.1f \\chi_{s}^{2}=%.1f)",664 fSignificance, fSigInt, fSigmaGaus,665 (int)fExcessEvents, fIntegralMax,666 fChiSqBg, fChiSqSignal));667 668 text.SetBit(TLatex::kTextNDC);669 text.SetTextSize(size);670 text.Paint();671 }672 */673 538 Bool_t MHAlpha::Finalize() 674 539 { -
trunk/MagicSoft/Mars/mhflux/MHAlpha.h
r5002 r5012 84 84 { 85 85 private: 86 MAlphaFitter fFit; 86 MAlphaFitter fFit; //! SEEMS THAT STREAMER HAS SOME PROBLEMS... MAYBE IF FUNC IS USED AT THE SAME TIME FOR FITS (PAINT) 87 87 88 88 TH3D fHAlpha; // Alpha vs. theta and energy -
trunk/MagicSoft/Mars/mhflux/MHEffectiveOnTime.cc
r4999 r5012 188 188 fHThetaLambda.SetTitle("Slope (Rate) vs Theta"); 189 189 fHThetaLambda.SetXTitle("\\Theta [\\circ]"); 190 fHThetaLambda.SetYTitle("\\la bda");190 fHThetaLambda.SetYTitle("\\lambda [s^{-1}]"); 191 191 fHThetaLambda.UseCurrentStyle(); 192 192 fHThetaLambda.SetDirectory(NULL); … … 197 197 fHTimeLambda.SetTitle("Slope (Rate) vs Time"); 198 198 fHTimeLambda.SetXTitle("\\Time [\\circ]"); 199 fHTimeLambda.SetYTitle("\\lambda ");199 fHTimeLambda.SetYTitle("\\lambda [s^{-1}]"); 200 200 fHTimeLambda.UseCurrentStyle(); 201 201 fHTimeLambda.SetDirectory(NULL); … … 318 318 // parameter 1 = N0*del 319 319 // 320 staticTF1 func("Poisson", " [1]*[2] * [0] * exp(-[0] *x)");320 TF1 func("Poisson", " [1]*[2] * [0] * exp(-[0] *x)"); 321 321 //func.SetParNames("lambda", "N0", "del"); 322 322 … … 791 791 AppendPad("time"); 792 792 fHTimeLambda.Draw("same"); 793 DrawRightAxis("\\lambda ");793 DrawRightAxis("\\lambda [s^{-1}]"); 794 794 795 795 pad->cd(2); … … 821 821 AppendPad("theta"); 822 822 fHThetaLambda.Draw("same"); 823 DrawRightAxis("\\lambda ");824 } 823 DrawRightAxis("\\lambda [s^{-1}]"); 824 } -
trunk/MagicSoft/Mars/mhflux/MHFalseSource.cc
r5006 r5012 808 808 const Double_t w = fHist.GetZaxis()->GetBinWidth(1); 809 809 810 // xmin, xmax, npar 811 //TF1 func("MyFunc", fcn, 0, 90, 6); 812 // Implementing the function yourself is only about 5% faster 813 TF1 func("", Form("gaus(0) + pol%d(3)", polynom), 0, 90); 814 //TF1 func("", Form("[0]*(TMath::Gaus(x, [1], [2])+TMath::Gaus(x, -[1], [2]))+pol%d(3)", polynom), 0, 90); 815 TArrayD maxpar(func.GetNpar()); 810 TArrayD maxpar; 816 811 817 812 /* func.SetParName(0, "A"); … … 819 814 * func.SetParName(2, "sigma"); 820 815 */ 821 822 func.FixParameter(1, 0);823 func.FixParameter(4, 0);824 func.SetParLimits(2, 0, 90);825 func.SetParLimits(3, -1, 1);826 816 827 817 const Int_t nx = hist->GetXaxis()->GetNbins(); … … 864 854 h = fHist.ProjectionZ("AlphaFit", ix, ix, iy, iy); 865 855 866 if (h->Get BinContent(1)==0)856 if (h->GetEntries()==0) 867 857 continue; 868 858 … … 988 978 result->Draw(); 989 979 990 TF1 f1(" ", func.GetExpFormula(), 0, 90);991 TF1 f2(" ", func.GetExpFormula(), 0, 90);980 TF1 f1("f1", Form("gaus(0) + pol%d(3)", polynom), 0, 90); 981 TF1 f2("f2", Form("gaus(0) + pol%d(3)", polynom), 0, 90); 992 982 f1.SetParameters(maxpar.GetArray()); 993 983 f2.SetParameters(maxpar.GetArray()); -
trunk/MagicSoft/Mars/mhflux/MHFalseSource.h
r4999 r5012 61 61 TH1 *GetHistByName(const TString name) { return &fHist; } 62 62 63 void FitSignificance(Float_t sigint=1 5, Float_t sigmax=70, Float_t bgmin=40, Float_t bgmax=70, Byte_t polynom=1); //*MENU*63 void FitSignificance(Float_t sigint=10, Float_t sigmax=75, Float_t bgmin=45, Float_t bgmax=85, Byte_t polynom=2); //*MENU* 64 64 void FitSignificanceStd() { FitSignificance(); } //*MENU* 65 65
Note:
See TracChangeset
for help on using the changeset viewer.