00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4FitModelPolynom.h"
00015
00016 #include "TMath.h"
00017 #include "TArrayD.h"
00018
00019 #include "TGo4FitParameter.h"
00020
00021 TGo4FitModelPolynom::TGo4FitModelPolynom() : TGo4FitModel(), fxAllOrders(0) {
00022 }
00023
00024 TGo4FitModelPolynom::TGo4FitModelPolynom(const char* iName, Double_t iOrderX) :
00025 TGo4FitModel(iName,"polynomial function",kTRUE), fxAllOrders(0) {
00026 CreateOrdersPars(&iOrderX, 0, 0);
00027 SetBackgroundGroupIndex();
00028 }
00029
00030 TGo4FitModelPolynom::TGo4FitModelPolynom(const char* iName, Double_t iOrderX, Double_t iOrderY) :
00031 TGo4FitModel(iName,"polynomial function",kTRUE), fxAllOrders(0) {
00032 Double_t arr[2] = { iOrderX, iOrderY };
00033 CreateOrdersPars(arr, 0, 1);
00034 SetBackgroundGroupIndex();
00035 }
00036
00037 TGo4FitModelPolynom::TGo4FitModelPolynom(const char* iName, Double_t iOrderX, Double_t iOrderY, Double_t iOrderZ) :
00038 TGo4FitModel(iName,"polynomial function",kTRUE), fxAllOrders(0) {
00039 Double_t arr[3] = { iOrderX, iOrderY, iOrderZ };
00040 CreateOrdersPars(arr, 0, 2);
00041 SetBackgroundGroupIndex();
00042 }
00043
00044 TGo4FitModelPolynom::TGo4FitModelPolynom(const char* iName, const TArrayD& iPolynomOrders) :
00045 TGo4FitModel(iName,"polynomial function",kTRUE), fxAllOrders(0) {
00046 CreateOrdersPars(iPolynomOrders.GetArray(),0,iPolynomOrders.GetSize()-1);
00047 SetBackgroundGroupIndex();
00048 }
00049
00050 TGo4FitModelPolynom::~TGo4FitModelPolynom() {
00051 if (fxAllOrders) delete fxAllOrders;
00052 }
00053
00054 void TGo4FitModelPolynom::CreateOrdersPars(const Double_t* orders, Int_t startaxis, Int_t maxaxis, Int_t AtIndx) {
00055 for(Int_t n=startaxis;n<=maxaxis;n++) {
00056 TString infostr;
00057 infostr.Form("Polynom order for axis %d",n);
00058 if (orders) NewParameter(GetOrderParName(n),infostr.Data(),orders[n],kTRUE, AtIndx);
00059 else NewParameter(GetOrderParName(n),infostr.Data(),0.,kTRUE, AtIndx);
00060 }
00061 }
00062
00063 TString TGo4FitModelPolynom::GetOrderParName(Int_t naxis)
00064 {
00065 TString res;
00066 res.Form("Order%d",naxis);
00067 return res;
00068 }
00069
00070 Double_t TGo4FitModelPolynom::GetPolynomOrder(Int_t naxis) {
00071 TGo4FitParameter *par = FindPar(GetOrderParName(naxis));
00072 if (par==0) return 0.;
00073 else return par->GetValue();
00074 }
00075
00076 Int_t TGo4FitModelPolynom::GetMaxNumAxis() {
00077 Int_t naxis = 0;
00078 while (FindPar(GetOrderParName(naxis))!=0) naxis++;
00079 return naxis-1;
00080 }
00081
00082 Bool_t TGo4FitModelPolynom::SetMaxNumAxis(Int_t numaxis) {
00083 Int_t numaxisold = GetMaxNumAxis();
00084 if ((numaxis<0) || (numaxis==numaxisold)) return kFALSE;
00085 if (numaxis<numaxisold)
00086 for(Int_t n=numaxis+1;n<=numaxisold;n++)
00087 RemovePar(GetOrderParName(n));
00088 else {
00089 Int_t indx = GetParIndex(FindPar(GetOrderParName(numaxisold)));
00090 CreateOrdersPars(0,numaxisold+1,numaxis, indx+1);
00091 }
00092
00093 return kTRUE;
00094 }
00095
00096 Bool_t TGo4FitModelPolynom::BeforeEval(Int_t NDimension) {
00097 if (fxAllOrders) delete fxAllOrders;
00098 Par_ndim = NDimension;
00099 fxAllOrders = new TArrayD(Par_ndim);
00100 fxAllOrders->Reset(0.);
00101 Par_orders = fxAllOrders->GetArray();
00102 for(Int_t i=0;i<Par_ndim;i++)
00103 Par_orders[i]=GetPolynomOrder(i);
00104 return kTRUE;
00105 }
00106
00107 Double_t TGo4FitModelPolynom::EvalN(const Double_t* v) {
00108 Double_t zn = 1.;
00109 for(Int_t n=0;n<Par_ndim;n++)
00110 zn *= TMath::Power(v[n],Par_orders[n]);
00111 return zn;
00112 }
00113
00114 void TGo4FitModelPolynom::AfterEval() {
00115 if (fxAllOrders) { delete fxAllOrders; fxAllOrders=0; }
00116 }
00117
00118 void TGo4FitModelPolynom::Print(Option_t* option) const {
00119 TGo4FitModel::Print(option);
00120 }