00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef __CINT__
00017
00018 #include "Riostream.h"
00019
00020 #include "TMath.h"
00021 #include "TH1.h"
00022 #include "TH2.h"
00023 #include "TCanvas.h"
00024 #include "TCutG.h"
00025 #include "TApplication.h"
00026 #include "TRandom.h"
00027
00028 #include "TGo4Fitter.h"
00029 #include "TGo4FitDataHistogram.h"
00030 #include "TGo4FitDataRidge.h"
00031 #include "TGo4FitModelFormula.h"
00032
00033 void Example13();
00034
00035 int main(int argc, char **argv)
00036 {
00037 TApplication theApp("Application", 0, 0);
00038
00039 Example13();
00040
00041 theApp.Run();
00042
00043 return 0;
00044 }
00045
00046 #endif
00047
00048 void AddRidge(TH2D* histo, double a, double k, double b,
00049 double xstart, int numsteps, int numpoints, double deviation)
00050 {
00051 TRandom rnd(1234);
00052
00053 double x = xstart;
00054
00055 for(int i=0;i<numsteps;i++) {
00056 double y = a*exp(k*x) + b;
00057
00058 double alf = TMath::ATan(k*a*exp(k*x)) + TMath::Pi()/2.;
00059
00060 for(int j=0;j<numpoints;j++) {
00061 double radius = rnd.Gaus(0.,deviation);
00062 histo->Fill(x + radius*cos(alf), y + radius*sin(alf));
00063 }
00064
00065 x = x + 0.001*sin(alf);
00066 }
00067 }
00068
00069 TH2D* MakeRidgeHistogram()
00070 {
00071 TH2D* histo = new TH2D("Histo","Ridge y = a*exp(k*x)+b",100,0.,10.,100,0.,10.);
00072
00073 std::cout << "Generating histogram " << std::endl;
00074
00075 AddRidge(histo, 10, -0.3, 2, 1.5, 10000, 100, 0.3);
00076
00077 AddRidge(histo, 10, -0.5, 0, 0.5, 10000, 50, 0.2);
00078
00079 AddRidge(histo, 10, -0.1, +2, 3.5, 10000, 50, 0.2);
00080
00081 std::cout << " Done " << std::endl;
00082
00083 return histo;
00084 }
00085
00086 TCutG* MakeCut()
00087 {
00088 Float_t xx[7] = { 1.0, 4.0, 9.0, 9.5, 5.0, 2.0, 1.0 };
00089 Float_t yy[7] = { 8.0, 2.5, 2.0, 4.0, 6.0, 9.5, 8.0 };
00090 return new TCutG("RangeCut", 7, xx, yy);
00091 }
00092
00093 void Example13()
00094 {
00095
00096 TH2D* histo = MakeRidgeHistogram();
00097 new TCanvas("Canvas1");
00098 histo->Draw("LEGO2");
00099
00100
00101 TGo4Fitter fitter("Fitter", TGo4Fitter::ff_chi_square, kFALSE);
00102
00103
00104
00105
00106 TGo4FitDataHistogram* datah = new TGo4FitDataHistogram("histogram",histo);
00107 datah->SetExcludeLessThen(3);
00108 datah->AddRangeCut(MakeCut());
00109
00110
00111 TGo4FitDataRidge* ridge = new TGo4FitDataRidge("ridge",datah,1);
00112 fitter.AddData(ridge);
00113
00114
00115
00116 TGo4FitModelFormula* model = new TGo4FitModelFormula("RidgeFunc","parA*exp(parK*x)+parB",3,kFALSE);
00117 model->SetRange(0,2,8.);
00118 model->SetParsNames("parA","parK","parB");
00119 model->SetParsValues(9.,-0.2,1.2);
00120 fitter.AddModel("ridge", model);
00121
00122
00123 fitter.AddSimpleMinuit();
00124
00125
00126 fitter.SetMemoryUsage(1);
00127
00128
00129 fitter.DoActions();
00130
00131
00132 fitter.Print("Pars");
00133
00134
00135 fitter.Draw("#ridge");
00136 }