Changeset 5006 for trunk/MagicSoft/Mars/mhflux
- Timestamp:
- 09/14/04 16:54:56 (20 years ago)
- Location:
- trunk/MagicSoft/Mars/mhflux
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mhflux/MAlphaFitter.cc
r5002 r5006 46 46 #include "MMath.h" 47 47 48 #include "MLogManip.h" 49 48 50 ClassImp(MAlphaFitter); 49 51 … … 86 88 Double_t bgmin=fBgMin; 87 89 Double_t bgmax=fBgMax; 88 Byte_t polynom=fPolynom ;90 Byte_t polynom=fPolynomOrder; 89 91 90 92 // Implementing the function yourself is only about 5% faster 91 93 TF1 func("", Form("gaus(0) + pol%d(3)", polynom), 0, 90); 92 94 //TF1 func("", Form("[0]*(TMath::Gaus(x, [1], [2])+TMath::Gaus(x, -[1], [2]))+pol%d(3)", polynom), 0, 90); 93 TArrayD maxpar(func.GetNpar()); 95 96 if (fCoefficients.GetSize() != polynom+3) 97 { 98 fCoefficients.Set(polynom+3); 99 fCoefficients.Reset(); 100 } 101 else 102 func.SetParameters(fCoefficients.GetArray()); 94 103 95 104 func.FixParameter(1, 0); … … 154 163 h.Fit(&func, "NQI", "", 0, sigmax); 155 164 156 fChiSqSignal 157 f SigmaGaus = func.GetParameter(2);165 fChiSqSignal = func.GetChisquare()/func.GetNDF(); 166 fCoefficients.Set(func.GetNpar(), func.GetParameters()); 158 167 159 168 //const Bool_t ok = NDF>0 && chi2<2.5*NDF; … … 167 176 } 168 177 // ------------------------------------ 169 const Double_t s= func.Integral(0, sigint)/alphaw;178 //const Double_t s = func.Integral(0, sigint)/alphaw; 170 179 func.SetParameter(0, 0); 171 180 func.SetParameter(2, 1); 172 const Double_t b= func.Integral(0, sigint)/alphaw;173 174 fSignificance = MMath::SignificanceLiMaSigned(s, b);181 //const Double_t b = func.Integral(0, sigint)/alphaw; 182 183 //fSignificance = MMath::SignificanceLiMaSigned(s, b); 175 184 //exc = s-b; 176 185 177 186 const Double_t uin = 1.25*sigint; 178 187 const Int_t bin = h.GetXaxis()->FindFixBin(uin); 179 fIntegralMax = h.GetBinLowEdge(bin+1); 180 fExcessEvents = h.Integral(0, bin)-func.Integral(0, fIntegralMax)/alphaw; 188 189 fIntegralMax = h.GetBinLowEdge(bin+1); 190 fEventsBackground = func.Integral(0, fIntegralMax)/alphaw; 191 fEventsSignal = h.Integral(0, bin); 192 fEventsExcess = fEventsSignal-fEventsBackground; 193 fSignificance = MMath::SignificanceLiMaSigned(fEventsSignal, fEventsBackground); 181 194 182 195 return kTRUE; … … 186 199 { 187 200 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)", 188 fSignificance, fSigInt, fSigmaGaus,189 (int)fE xcessEvents, fIntegralMax,201 fSignificance, fSigInt, GetGausSigma(), 202 (int)fEventsExcess, fIntegralMax, 190 203 fChiSqBg, fChiSqSignal)); 191 204 -
trunk/MagicSoft/Mars/mhflux/MAlphaFitter.h
r5002 r5006 4 4 #ifndef MARS_MParContainer 5 5 #include "MParContainer.h" 6 #endif 7 8 #ifndef ROOT_TArrayD 9 #include <TArrayD.h> 6 10 #endif 7 11 … … 15 19 Float_t fBgMin; 16 20 Float_t fBgMax; 17 Int_t fPolynom ;21 Int_t fPolynomOrder; 18 22 19 23 Double_t fSignificance; 20 Double_t fExcessEvents; 24 Double_t fEventsExcess; 25 Double_t fEventsSignal; 26 Double_t fEventsBackground; 27 21 28 Double_t fChiSqSignal; 22 29 Double_t fChiSqBg; 23 Double_t fSigmaGaus;24 30 Double_t fIntegralMax; 25 31 32 TArrayD fCoefficients; 33 26 34 public: 27 MAlphaFitter() : fSigInt(10), fSigMax(75), fBgMin(45), fBgMax(85), fPolynom (1)35 MAlphaFitter() : fSigInt(10), fSigMax(75), fBgMin(45), fBgMax(85), fPolynomOrder(1) 28 36 { 29 37 } … … 38 46 MAlphaFitter &f = static_cast<MAlphaFitter&>(o); 39 47 40 f.fSigInt = fSigInt;41 f.fSigMax = fSigMax;42 f.fBgMin = fBgMin;43 f.fBgMax = fBgMax;44 f.fPolynom = fPolynom;48 f.fSigInt = fSigInt; 49 f.fSigMax = fSigMax; 50 f.fBgMin = fBgMin; 51 f.fBgMax = fBgMax; 52 f.fPolynomOrder = fPolynomOrder; 45 53 } 46 54 47 void SetSignalIntegralMax(Float_t s) { fSigInt= s; }48 void SetSignalFitMax(Float_t s) { fSigMax= s; }49 void SetBackgroundFitMin(Float_t s) { fBgMin= s; }50 void SetBackgroundFitMax(Float_t s) { fBgMax= s; }51 void Set NumPolynom(Int_t s) { fPolynom= s; }55 void SetSignalIntegralMax(Float_t s) { fSigInt = s; } 56 void SetSignalFitMax(Float_t s) { fSigMax = s; } 57 void SetBackgroundFitMin(Float_t s) { fBgMin = s; } 58 void SetBackgroundFitMax(Float_t s) { fBgMax = s; } 59 void SetPolynomOrder(Int_t s) { fPolynomOrder = s; } 52 60 53 Double_t GetExcessEvents() const { return fExcessEvents; } 54 Double_t GetSignificance() const { return fSignificance; } 55 Double_t GetChiSqSignal() const { return fChiSqSignal; } 56 Double_t GetChiSqBg() const { return fChiSqBg; } 57 Double_t GetSigmaGaus() const { return fSigmaGaus; } 61 Double_t GetEventsExcess() const { return fEventsExcess; } 62 Double_t GetEventsSignal() const { return fEventsSignal; } 63 Double_t GetEventsBackground() const { return fEventsBackground; } 64 65 Double_t GetSignificance() const { return fSignificance; } 66 Double_t GetChiSqSignal() const { return fChiSqSignal; } 67 Double_t GetChiSqBg() const { return fChiSqBg; } 68 69 Double_t GetGausSigma() const { return fCoefficients[2]; } 70 Double_t GetGausMu() const { return fCoefficients[1]; } 71 Double_t GetGausA() const { return fCoefficients[0]; } 72 Double_t GetCoefficient(Int_t i) const { return fCoefficients[i]; } 73 const TArrayD &GetCoefficients() const { return fCoefficients; } 58 74 59 75 void PaintResult(Float_t x=0.04, Float_t y=0.94, Float_t size=0.035) const; -
trunk/MagicSoft/Mars/mhflux/MHAlpha.cc
r5002 r5006 175 175 if (fit.Fit(*h)) 176 176 { 177 fHEnergy.SetBinContent(i, fit.GetE xcessEvents());178 fHEnergy.SetBinError(i, fit.GetE xcessEvents()*0.2);177 fHEnergy.SetBinContent(i, fit.GetEventsExcess()); 178 fHEnergy.SetBinError(i, fit.GetEventsExcess()*0.2); 179 179 } 180 180 delete h; … … 194 194 if (fit.Fit(*h)) 195 195 { 196 fHTheta.SetBinContent(i, fit.GetE xcessEvents());197 fHTheta.SetBinError(i, fit.GetE xcessEvents()*0.2);196 fHTheta.SetBinContent(i, fit.GetEventsExcess()); 197 fHTheta.SetBinError(i, fit.GetEventsExcess()*0.2); 198 198 } 199 199 delete h; … … 334 334 // Fill histogram 335 335 // 336 fHTime.SetBinContent(n+1, fit.GetE xcessEvents());337 fHTime.SetBinError(n+1, fit.GetE xcessEvents()*0.1);338 339 *fLog << all << *fTimeEffOn << ": " << fit.GetE xcessEvents() << endl;336 fHTime.SetBinContent(n+1, fit.GetEventsExcess()); 337 fHTime.SetBinError(n+1, fit.GetEventsExcess()*0.1); 338 339 *fLog << all << *fTimeEffOn << ": " << fit.GetEventsExcess() << endl; 340 340 341 341 rebin = steps; … … 353 353 { 354 354 alpha = (*fMatrix)[fMap[0]]; 355 energy = 1000; //(*fMatrix)[fMap[1]];356 theta = 0; //(*fMatrix)[fMap[2]];355 energy = 1000; 356 theta = 0; 357 357 } 358 358 else … … 375 375 fHAlphaTime.Fill(TMath::Abs(alpha), w); 376 376 377 /*378 // N_gamma vs Energy and Theta379 const Double_t Ngam = fHUnfold.GetBinContent(m,n);380 // A_eff vs Energy and Theta381 const Double_t Aeff = fHAeff.GetBinContent(m,n);382 // T_eff vs Theta383 const Double_t Effon = teff.GetBinContent(n);384 385 const Double_t c1 = fHUnfold.GetBinError(m,n)/Ngam;386 const Double_t c2 = teff.GetBinError(n) /Effon;387 const Double_t c3 = fHAeff.GetBinError(m,n) /Aeff;388 389 const Double_t cont = Ngam / (DeltaE * Effon * Aeff);390 const Double_t dcont = sqrt(c1*c1 + c2*c2 + c3*c3);391 392 //393 // Out of Range394 //395 const Bool_t oor = Ngam<=0 || DeltaE<=0 || Effon<=0 || Aeff<=0;396 397 if (oor)398 *fLog << warn << "MHFlux::CalcAbsGammaFlux(" << m << "," << n << ") ";399 400 if (Ngam<=0)401 *fLog << " Ngam=0";402 if (DeltaE<=0)403 *fLog << " DeltaE=0";404 if (Effon<=0)405 *fLog << " Effon=0";406 if (Aeff<=0)407 *fLog << " Aeff=0";408 409 if (oor)410 *fLog << endl;411 412 fHFlux.SetBinContent(m,n, oor ? 1e-20 : cont);413 fHFlux.SetBinError(m,n, oor ? 1e-20 : dcont*cont);414 */415 377 return kTRUE; 416 378 } … … 487 449 if (o==(TString)"energy") 488 450 { 489 if (fHEnergy.GetEntries()>0) 451 /* 452 if (fHEnergy.GetEntries()>10) 490 453 { 491 454 gPad->SetLogx(); 492 455 gPad->SetLogy(); 493 456 } 494 FitEnergySpec(kTRUE); 457 FitEnergySpec(kTRUE);*/ 458 495 459 } 496 460 -
trunk/MagicSoft/Mars/mhflux/MHFalseSource.cc
r4999 r5006 131 131 #include "MAstroSky2Local.h" 132 132 #include "MStatusDisplay.h" 133 133 134 #include "MMath.h" 135 #include "MAlphaFitter.h" 134 136 135 137 #include "MBinning.h" … … 847 849 delete h0; 848 850 849 TH1 *h=0; 851 MAlphaFitter fit; 852 fit.SetSignalIntegralMax(sigint); 853 fit.SetSignalFitMax(sigmax); 854 fit.SetBackgroundFitMin(bgmin); 855 fit.SetBackgroundFitMax(bgmax); 856 fit.SetPolynomOrder(polynom); 857 858 TH1D *h=0; 850 859 for (int ix=1; ix<=nx; ix++) 851 860 for (int iy=1; iy<=ny; iy++) … … 855 864 h = fHist.ProjectionZ("AlphaFit", ix, ix, iy, iy); 856 865 866 if (h->GetBinContent(1)==0) 867 continue; 868 869 870 h->Scale(entries/h->GetEntries()); 871 872 if (!fit.Fit(*h)) 873 continue; 874 857 875 const Double_t alpha0 = h->GetBinContent(1); 858 859 // Check for the regios which is not filled...860 if (alpha0==0)861 continue;862 863 h->Scale(entries/h->GetEntries());864 865 876 if (alpha0>maxalpha0) 866 877 maxalpha0=alpha0; 867 868 // First fit a polynom in the off region 869 func.FixParameter(0, 0); 870 func.FixParameter(2, 1); 871 func.ReleaseParameter(3); 872 873 for (int i=5; i<func.GetNpar(); i++) 874 func.ReleaseParameter(i); 875 876 h->Fit(&func, "N0Q", "", bgmin, bgmax); 877 878 h4a.Fill(func.GetChisquare()); 879 //h5a.Fill(func.GetProb()); 880 881 //func.SetParLimits(0, 0.5*h->GetBinContent(1), 1.5*h->GetBinContent(1)); 882 //func.SetParLimits(2, 5, 90); 883 884 func.ReleaseParameter(0); 885 //func.ReleaseParameter(1); 886 func.ReleaseParameter(2); 887 func.FixParameter(3, func.GetParameter(3)); 888 for (int i=5; i<func.GetNpar(); i++) 889 func.FixParameter(i, func.GetParameter(i)); 890 891 // Do not allow signals smaller than the background 892 const Double_t A = alpha0-func.GetParameter(3); 893 const Double_t dA = TMath::Abs(A); 894 func.SetParLimits(0, -dA*4, dA*4); 895 func.SetParLimits(2, 0, 90); 896 897 // Now fit a gaus in the on region on top of the polynom 898 func.SetParameter(0, A); 899 func.SetParameter(2, sigmax*0.75); 900 901 h->Fit(&func, "N0Q", "", 0, sigmax); 902 903 TArrayD p(func.GetNpar(), func.GetParameters()); 904 878 905 879 // Fill results into some histograms 906 h0a.Fill( p[0]);907 h0b.Fill( p[3]);908 h1.Fill( p[1]);909 h2.Fill( p[2]);880 h0a.Fill(fit.GetGausA()); // gaus-A 881 h0b.Fill(fit.GetCoefficient(3)); // 3 882 h1.Fill(fit.GetGausMu()); // mu 883 h2.Fill(fit.GetGausSigma()); // sigma-gaus 910 884 if (polynom>1) 911 h3.Fill(p[5]); 912 h4b.Fill(func.GetChisquare()); 913 //h5b.Fill(func.GetProb()); 914 915 // Implementing the integral as analytical function 916 // gives the same result in the order of 10e-5 917 // and it is not faster at all... 918 //const Bool_t ok = /*p[0]>=0 && /*p[0]<alpha0*2 &&*/ p[2]>1.75;// && p[2]<88.5; 919 /* 920 if (p[0]<-fabs(alpha0-p[3])*7 && p[2]<alphaw/3) 921 { 922 func.SetParameter(0, alpha0-p[3]); 923 cout << p[2] << " " << p[0] << " " << alpha0-p[3] << endl; 924 } 925 */ 926 927 // The fitted function returned units of 928 // counts bin binwidth. To get the correct number 929 // of events we must adapt the functions by dividing 930 // the result of the integration by the bin-width 931 const Double_t s = func.Integral(0, sigint)/w; 932 933 func.SetParameter(0, 0); 934 func.SetParameter(2, 1); 935 936 const Double_t b = func.Integral(0, sigint)/w; 937 const Double_t sig = SignificanceLiMa(s, b); 885 h3.Fill(fit.GetCoefficient(5)); 886 h4b.Fill(fit.GetChiSqSignal()); 887 888 const Double_t sig = fit.GetSignificance(); 889 const Double_t b = fit.GetEventsBackground(); 890 const Double_t s = fit.GetEventsSignal(); 938 891 939 892 const Int_t n = hist->GetBin(ix, iy); … … 945 898 h6.Fill(sig); 946 899 947 if (sig>maxs /* && (ix-nx/2)*(ix-nx/2)+(iy-ny/2)*(iy-ny/2)<nr*nr/9*/)900 if (sig>maxs) 948 901 { 949 902 maxs = sig; 950 903 maxx = ix; 951 904 maxy = iy; 952 maxpar = p;905 maxpar = fit.GetCoefficients(); 953 906 } 954 907 } 955 956 *fLog << inf << "done." << endl;957 908 958 909 h0a.GetXaxis()->SetRangeUser(0, maxalpha0*1.5);
Note:
See TracChangeset
for help on using the changeset viewer.