00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __CINT__
00019
00020 #include "TH1.h"
00021 #include "TFile.h"
00022 #include "TApplication.h"
00023 #include "TCollection.h"
00024
00025 #include "TGo4Fitter.h"
00026 #include "TGo4FitDataHistogram.h"
00027 #include "TGo4FitModelPolynom.h"
00028 #include "TGo4FitModelGauss1.h"
00029 #include "TGo4FitAxisTrans.h"
00030 #include "TGo4FitLinearTrans.h"
00031 #include "TGo4FitterConfig.h"
00032
00033 void Example6();
00034
00035 int main(int argc, char **argv)
00036 {
00037 TApplication theApp("Application", 0, 0);
00038
00039 Example6();
00040
00041 theApp.Run();
00042
00043 return 0;
00044 }
00045
00046 #endif
00047
00048
00049 TH1D* GetHistogram(const char* HistogramName)
00050 {
00051 TFile* f1 = TFile::Open("histograms.root");
00052 if (f1==0) return 0;
00053 TH1D* histo = (TH1D*) f1->Get(HistogramName);
00054 if (histo) histo->SetDirectory(0);
00055 return histo;
00056 }
00057
00058
00059
00060 TGo4FitAxisTrans* ConstructTrans()
00061 {
00062 TGo4FitLinearTrans* trans = new TGo4FitLinearTrans("trans","linear axis transformation");
00063 trans->SetCoefByRange(3800,0.,3.8);
00064 return trans;
00065 }
00066
00067 TGo4Fitter* BuildFitter()
00068 {
00069
00070 TGo4Fitter *fitter = new TGo4Fitter("Fitter",TGo4Fitter::ff_ML_Poisson, kFALSE);
00071
00072
00073 TGo4FitDataHistogram *data1 = new TGo4FitDataHistogram("data1",0);
00074 data1->SetUseBinScale(kTRUE);
00075 data1->SetRange(0,2.2,2.9);
00076 fitter->AddData(data1);
00077
00078
00079 fitter->AddModel( "data1", new TGo4FitModelPolynom("Pol1_0",0.) );
00080 fitter->AddModel( "data1", new TGo4FitModelPolynom("Pol1_1",1.) );
00081 fitter->AddModel( "data1", new TGo4FitModelGauss1("Gauss1_1",2.553,0.015) );
00082 fitter->AddModel( "data1", new TGo4FitModelGauss1("Gauss2_1",2.672,0.015) );
00083
00084
00085 TGo4FitDataHistogram *data2 = new TGo4FitDataHistogram("data2",0);
00086 data2->SetUseBinScale(kTRUE);
00087 data2->SetRange(0,2.2,2.9);
00088 fitter->AddData(data2);
00089
00090
00091 fitter->AddModel( "data2", new TGo4FitModelPolynom("Pol2_0",0.) );
00092 fitter->AddModel( "data2", new TGo4FitModelPolynom("Pol2_1",1.) );
00093 fitter->AddModel( "data2", new TGo4FitModelGauss1("Gauss1_2",2.553,0.015) );
00094 fitter->AddModel( "data2", new TGo4FitModelGauss1("Gauss2_2",2.672,0.015) );
00095 fitter->AddModel( "data2", new TGo4FitModelGauss1("Gauss3_2",2.597,0.014) );
00096 fitter->AddModel( "data2", new TGo4FitModelGauss1("Gauss4_2",2.717,0.014) );
00097
00098
00099 TGo4FitterConfig* config = new TGo4FitterConfig("Config","fitter configuration");
00100 config->SetParInit("Pol1_0.Ampl",40);
00101 config->SetParInit("Pol1_1.Ampl",-0.01);
00102 config->SetParInit("Pol2_0.Ampl",500);
00103 config->SetParInit("Pol2_1.Ampl",-0.1);
00104 config->SetParDepend("Gauss1_2.Pos","Gauss1_1.Pos");
00105 config->SetParDepend("Gauss1_2.Width","Gauss1_1.Width");
00106 config->SetParDepend("Gauss2_2.Pos","Gauss2_1.Pos");
00107 config->SetParDepend("Gauss2_2.Width","Gauss2_1.Width");
00108 fitter->AddAction(config);
00109
00110
00111 fitter->AddStandardActions();
00112
00113
00114
00115 fitter->SetMemoryUsage(1);
00116
00117 return fitter;
00118 }
00119
00120
00121 void StoreFitter(TGo4Fitter* fitter)
00122 {
00123 TFile* f = TFile::Open("Example6.root","recreate");
00124 if (f!=0) fitter->Write("Fitter");
00125 delete f;
00126 }
00127
00128
00129 TGo4Fitter* RestoreFitter()
00130 {
00131 TFile* f = TFile::Open("Example6.root");
00132 TGo4Fitter* fitter = (TGo4Fitter*) (f ? f->Get("Fitter") : 0);
00133 delete f;
00134 return fitter;
00135 }
00136
00137 void Example6()
00138 {
00139
00140 TGo4Fitter* fitter = BuildFitter();
00141
00142
00143 TGo4FitAxisTrans* trans = ConstructTrans();
00144 fitter->FindData("data1")->AddAxisTrans(trans, kTRUE);
00145 fitter->FindData("data2")->AddAxisTrans(trans, kFALSE);
00146
00147
00148 fitter->SetObject("data1", GetHistogram("hDeg120_P_c"), kTRUE);
00149 fitter->SetObject("data2", GetHistogram("hDeg120_CND"), kTRUE);
00150
00151
00152 fitter->DoActions();
00153
00154
00155 StoreFitter(fitter);
00156 delete fitter;
00157
00158
00159
00160
00161 fitter = RestoreFitter();
00162
00163
00164 fitter->PrintPars();
00165 fitter->Draw("#data1,Gauss1_1,Gauss2_1");
00166 fitter->Draw("#data2,Gauss1_2,Gauss2_2,Gauss3_2,Gauss4_2");
00167
00168 delete fitter;
00169 }