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