Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

TGo4FitModelPolynom.cxx

Go to the documentation of this file.
00001 //-------------------------------------------------------------
00002 //        Go4 Release Package v3.04-01 (build 30401)
00003 //                      28-November-2008
00004 //---------------------------------------------------------------
00005 //   The GSI Online Offline Object Oriented (Go4) Project
00006 //   Experiment Data Processing at EE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
00015 //----------------------------------------------------------------
00016 #include "TGo4FitModelPolynom.h"
00017 
00018 #include "Riostream.h"
00019 
00020 #include "TMath.h"
00021 #include "TArrayD.h"
00022 
00023 #include "TGo4FitParameter.h"
00024 
00025 TGo4FitModelPolynom::TGo4FitModelPolynom() : TGo4FitModel(), fxAllOrders(0) {
00026 }
00027 
00028 TGo4FitModelPolynom::TGo4FitModelPolynom(const char* iName, Double_t iOrderX) :
00029    TGo4FitModel(iName,"polynomial function",kTRUE), fxAllOrders(0) {
00030      CreateOrdersPars(&iOrderX, 0, 0);
00031      SetBackgroundGroupIndex();
00032 }
00033 
00034 TGo4FitModelPolynom::TGo4FitModelPolynom(const char* iName, Double_t iOrderX, Double_t iOrderY) :
00035    TGo4FitModel(iName,"polynomial function",kTRUE), fxAllOrders(0) {
00036        Double_t arr[2] = { iOrderX, iOrderY };
00037        CreateOrdersPars(arr, 0, 1);
00038        SetBackgroundGroupIndex();
00039 }
00040 
00041 TGo4FitModelPolynom::TGo4FitModelPolynom(const char* iName, Double_t iOrderX, Double_t iOrderY, Double_t iOrderZ) :
00042    TGo4FitModel(iName,"polynomial function",kTRUE), fxAllOrders(0) {
00043        Double_t arr[3] = { iOrderX, iOrderY, iOrderZ };
00044        CreateOrdersPars(arr, 0, 2);
00045        SetBackgroundGroupIndex();
00046 }
00047 
00048 TGo4FitModelPolynom::TGo4FitModelPolynom(const char* iName, const TArrayD& iPolynomOrders) :
00049   TGo4FitModel(iName,"polynomial function",kTRUE), fxAllOrders(0) {
00050       CreateOrdersPars(iPolynomOrders.GetArray(),0,iPolynomOrders.GetSize()-1);
00051       SetBackgroundGroupIndex();
00052 }
00053 
00054 TGo4FitModelPolynom::~TGo4FitModelPolynom() {
00055   if (fxAllOrders) delete fxAllOrders;
00056 }
00057 
00058 void TGo4FitModelPolynom::CreateOrdersPars(const Double_t* orders, Int_t startaxis, Int_t maxaxis, Int_t AtIndx) {
00059    for(Int_t n=startaxis;n<=maxaxis;n++) {
00060       TString infostr;
00061       infostr.Form("Polynom order for axis %d",n);
00062       if (orders) NewParameter(GetOrderParName(n),infostr.Data(),orders[n],kTRUE, AtIndx);
00063             else  NewParameter(GetOrderParName(n),infostr.Data(),0.,kTRUE, AtIndx);
00064    }
00065 }
00066 
00067 TString TGo4FitModelPolynom::GetOrderParName(Int_t naxis)
00068 {
00069    TString res;
00070    res.Form("Order%d",naxis);
00071    return res;
00072 }
00073 
00074 Double_t TGo4FitModelPolynom::GetPolynomOrder(Int_t naxis) {
00075    TGo4FitParameter *par = FindPar(GetOrderParName(naxis));
00076    if (par==0) return 0.;
00077           else return par->GetValue();
00078 }
00079 
00080 Int_t TGo4FitModelPolynom::GetMaxNumAxis() {
00081    Int_t naxis = 0;
00082    while (FindPar(GetOrderParName(naxis))!=0) naxis++;
00083    return naxis-1;
00084 }
00085 
00086 Bool_t TGo4FitModelPolynom::SetMaxNumAxis(Int_t numaxis) {
00087    Int_t numaxisold = GetMaxNumAxis();
00088    if ((numaxis<0) || (numaxis==numaxisold)) return kFALSE;
00089    if (numaxis<numaxisold)
00090      for(Int_t n=numaxis+1;n<=numaxisold;n++)
00091         RemovePar(GetOrderParName(n));
00092    else {
00093       Int_t indx = GetParIndex(FindPar(GetOrderParName(numaxisold)));
00094       CreateOrdersPars(0,numaxisold+1,numaxis, indx+1);
00095    }
00096 
00097    return kTRUE;
00098 }
00099 
00100 Bool_t TGo4FitModelPolynom::BeforeEval(Int_t NDimension) {
00101    if (fxAllOrders) delete fxAllOrders;
00102    Par_ndim = NDimension;
00103    fxAllOrders = new TArrayD(Par_ndim);
00104    fxAllOrders->Reset(0.);
00105    Par_orders = fxAllOrders->GetArray();
00106    for(Int_t i=0;i<Par_ndim;i++)
00107       Par_orders[i]=GetPolynomOrder(i);
00108    return kTRUE;
00109 }
00110 
00111 Double_t TGo4FitModelPolynom::EvalN(const Double_t* v) {
00112     Double_t zn = 1.;
00113     for(Int_t n=0;n<Par_ndim;n++)
00114        zn *= TMath::Power(v[n],Par_orders[n]);
00115     return zn;
00116 }
00117 
00118 void TGo4FitModelPolynom::AfterEval() {
00119    if (fxAllOrders) { delete fxAllOrders; fxAllOrders=0; }
00120 }
00121 
00122 void TGo4FitModelPolynom::Print(Option_t* option) const {
00123    TGo4FitModel::Print(option);
00124 }
00125 
00126 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Fri Nov 28 12:59:12 2008 for Go4-v3.04-1 by  doxygen 1.4.2