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