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