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