GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
TGo4FitModelPolynom.cxx
Go to the documentation of this file.
1 // $Id$
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "TGo4FitModelPolynom.h"
15 
16 #include "TMath.h"
17 
18 #include "TGo4FitParameter.h"
19 
21 {
22 }
23 
24 TGo4FitModelPolynom::TGo4FitModelPolynom(const char *iName, Double_t iOrderX) :
25  TGo4FitModel(iName,"polynomial function",kTRUE), fxAllOrders(nullptr)
26 {
27  CreateOrdersPars(&iOrderX, 0, 0);
29 }
30 
31 TGo4FitModelPolynom::TGo4FitModelPolynom(const char *iName, Double_t iOrderX, Double_t iOrderY) :
32  TGo4FitModel(iName,"polynomial function",kTRUE), fxAllOrders(nullptr)
33 {
34  Double_t arr[2] = { iOrderX, iOrderY };
35  CreateOrdersPars(arr, 0, 1);
37 }
38 
39 TGo4FitModelPolynom::TGo4FitModelPolynom(const char *iName, Double_t iOrderX, Double_t iOrderY, Double_t iOrderZ) :
40  TGo4FitModel(iName,"polynomial function",kTRUE), fxAllOrders(nullptr)
41 {
42  Double_t arr[3] = { iOrderX, iOrderY, iOrderZ };
43  CreateOrdersPars(arr, 0, 2);
45 }
46 
47 TGo4FitModelPolynom::TGo4FitModelPolynom(const char *iName, const TArrayD& iPolynomOrders) :
48  TGo4FitModel(iName,"polynomial function",kTRUE), fxAllOrders(nullptr)
49 {
50  CreateOrdersPars(iPolynomOrders.GetArray(),0,iPolynomOrders.GetSize()-1);
52 }
53 
55 {
56  if (fxAllOrders) delete fxAllOrders;
57 }
58 
59 void TGo4FitModelPolynom::CreateOrdersPars(const Double_t *orders, Int_t startaxis, Int_t maxaxis, Int_t AtIndx)
60 {
61  for(Int_t n=startaxis;n<=maxaxis;n++) {
62  TString infostr;
63  infostr.Form("Polynom order for axis %d",n);
64  if (orders) NewParameter(GetOrderParName(n),infostr.Data(),orders[n],kTRUE, AtIndx);
65  else NewParameter(GetOrderParName(n),infostr.Data(),0.,kTRUE, AtIndx);
66  }
67 }
68 
69 TString TGo4FitModelPolynom::GetOrderParName(Int_t naxis) const
70 {
71  TString res;
72  res.Form("Order%d",naxis);
73  return res;
74 }
75 
77 {
79  return par ? par->GetValue() : 0.;
80 }
81 
83 {
84  Int_t naxis = 0;
85  while (FindPar(GetOrderParName(naxis)))
86  naxis++;
87  return naxis-1;
88 }
89 
91 {
92  Int_t numaxisold = GetMaxNumAxis();
93  if ((numaxis < 0) || (numaxis == numaxisold))
94  return kFALSE;
95  if (numaxis < numaxisold)
96  for (Int_t n = numaxis + 1; n <= numaxisold; n++)
98  else {
99  Int_t indx = GetParIndex(FindPar(GetOrderParName(numaxisold)));
100  CreateOrdersPars(nullptr, numaxisold + 1, numaxis, indx + 1);
101  }
102 
103  return kTRUE;
104 }
105 
106 Bool_t TGo4FitModelPolynom::BeforeEval(Int_t NDimension)
107 {
108  if (fxAllOrders)
109  delete fxAllOrders;
110  Par_ndim = NDimension;
111  fxAllOrders = new TArrayD(Par_ndim);
112  fxAllOrders->Reset(0.);
113  Par_orders = fxAllOrders->GetArray();
114  for (Int_t i = 0; i < Par_ndim; i++)
115  Par_orders[i] = GetPolynomOrder(i);
116  return kTRUE;
117 }
118 
119 Double_t TGo4FitModelPolynom::EvalN(const Double_t *v)
120 {
121  Double_t zn = 1.;
122  for (Int_t n = 0; n < Par_ndim; n++)
123  zn *= TMath::Power(v[n], Par_orders[n]);
124  return zn;
125 }
126 
128 {
129  if (fxAllOrders) {
130  delete fxAllOrders;
131  fxAllOrders = nullptr;
132  }
133 }
134 
135 void TGo4FitModelPolynom::Print(Option_t *option) const
136 {
137  TGo4FitModel::Print(option);
138 }
Double_t GetValue() const
Bool_t BeforeEval(Int_t NDimension) override
TGo4FitParameter * NewParameter(const char *Name, const char *Title, Double_t iValue=0., Bool_t Fixed=kFALSE, Int_t AtIndx=-1)
void Print(Option_t *option="") const override
Bool_t RemovePar(const char *name)
TGo4FitParameter * FindPar(const char *ParName)
Bool_t SetMaxNumAxis(Int_t numaxis)
TString GetOrderParName(Int_t naxis) const
Int_t GetParIndex(const TGo4FitParameter *par)
void CreateOrdersPars(const Double_t *orders, Int_t startaxis, Int_t maxaxis, Int_t AtIndx=-1)
Double_t EvalN(const Double_t *v) override
Double_t GetPolynomOrder(Int_t naxis)
void SetBackgroundGroupIndex()
Definition: TGo4FitModel.h:114
void Print(Option_t *option="") const override