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 "TCollection.h"
00025 #include "TApplication.h"
00026
00027 #include "../Go4Fit/TGo4FitMinuit.h"
00028 #include "../Go4Fit/TGo4Fitter.h"
00029 #include "../Go4Fit/TGo4FitDataHistogram.h"
00030 #include "../Go4Fit/TGo4FitModelPolynom.h"
00031 #include "../Go4Fit/TGo4FitModelGauss1.h"
00032 #include "../Go4Fit/TGo4FitAxisTrans.h"
00033 #include "../Go4Fit/TGo4FitLinearTrans.h"
00034 #include "../Go4Fit/TGo4FitterOutput.h"
00035
00036 void Example7();
00037
00038 int main(int argc, char **argv)
00039 {
00040 TApplication theApp("Application", 0, 0);
00041
00042 Example7();
00043
00044 theApp.Run();
00045
00046 return 0;
00047 }
00048
00049 #endif
00050
00051
00052 TH1D* GetHistogram(const char* HistogramName) {
00053 TFile f1("histograms.root");
00054 TH1D* histo = (TH1D*) f1.Get(HistogramName);
00055 histo->SetDirectory(0);
00056 return histo;
00057 }
00058
00059
00060
00061 TGo4FitAxisTrans* ConstructTrans() {
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 TGo4Fitter *fitter = new TGo4Fitter("Fitter", TGo4Fitter::ff_ML_Poisson, kFALSE);
00070
00071
00072 TGo4FitDataHistogram *data1 = new TGo4FitDataHistogram("data1",0);
00073 data1->SetUseBinScale(kTRUE);
00074 data1->SetRange(0,2.2,2.9);
00075 data1->SetNumberOfTransSlots(1);
00076 fitter->AddData(data1);
00077
00078
00079 TGo4FitDataHistogram *data2 = new TGo4FitDataHistogram("data2",0);
00080 data2->SetUseBinScale(kTRUE);
00081 data2->SetRange(0,2.2,2.9);
00082 data2->SetNumberOfTransSlots(1);
00083 fitter->AddData(data2);
00084
00085 fitter->ConnectSlots("data1.Trans0","data2.Trans0");
00086
00087 TGo4FitModel* gauss1 = new TGo4FitModelGauss1("Gauss1",2.553,0.015);
00088 gauss1->AssignToData("data1"); gauss1->AssignToData("data2",1.2);
00089
00090 TGo4FitModel* gauss2 = new TGo4FitModelGauss1("Gauss2",2.672,0.015);
00091 gauss2->AssignToData("data1"); gauss2->AssignToData("data2",1.2);
00092
00093 fitter->AddModel( "data1", new TGo4FitModelPolynom("Pol1_0",0.) );
00094 fitter->AddModel( "data1", new TGo4FitModelPolynom("Pol1_1",1.) );
00095 fitter->AddModel( "data2", new TGo4FitModelPolynom("Pol2_0",0.) );
00096 fitter->AddModel( "data2", new TGo4FitModelPolynom("Pol2_1",1.) );
00097
00098 fitter->AddModel(gauss1);
00099 fitter->AddModel(gauss2);
00100 fitter->AddModel( "data2", new TGo4FitModelGauss1("Gauss3",2.597,0.014) );
00101 fitter->AddModel( "data2", new TGo4FitModelGauss1("Gauss4",2.717,0.014) );
00102
00103
00104 fitter->AddAmplEstimation(1);
00105
00106
00107 TGo4FitMinuit* fMinuit = new TGo4FitMinuit("Minuit");
00108 fMinuit->AddCommand("MIGRAD 500 1");
00109 fMinuit->AddCommand("MINOS 20");
00110 fitter->AddAction(fMinuit);
00111
00112
00113
00114 fitter->SetMemoryUsage(1);
00115
00116 return fitter;
00117 }
00118
00119
00120 void StoreFitter(TGo4Fitter* fitter) {
00121 TFile *f = new TFile("Example7.root","recreate");
00122 fitter->Write("Fitter");
00123 delete f;
00124 }
00125
00126
00127 TGo4Fitter* RestoreFitter() {
00128 TFile *f = new TFile("Example7.root");
00129 TGo4Fitter* fitter = (TGo4Fitter*) f->Get("Fitter");
00130 delete f;
00131 return fitter;
00132 }
00133
00134 void Example7() {
00135
00136 TGo4Fitter* fitter = BuildFitter();
00137
00138
00139 StoreFitter(fitter);
00140 delete fitter;
00141
00142 fitter = RestoreFitter();
00143
00144
00145
00146 fitter->SetObject(ConstructTrans(), kTRUE);
00147
00148
00149 fitter->SetObject("data1", GetHistogram("hDeg120_P_c"), kTRUE);
00150 fitter->SetObject("data2", GetHistogram("hDeg120_CND"), kTRUE);
00151
00152
00153 fitter->DoActions();
00154
00155
00156 StoreFitter(fitter);
00157
00158 delete fitter;
00159
00160
00161
00162
00163 fitter = RestoreFitter();
00164
00165
00166 fitter->Print("Pars");
00167 fitter->Draw("#data1,Gauss1,Gauss2");
00168 fitter->Draw("#data2,Gauss1,Gauss2,Gauss3,Gauss4");
00169
00170 delete fitter;
00171 }
00172
00173