TGo4FitModelPolynom.cxx

Go to the documentation of this file.
00001 // $Id: TGo4FitModelPolynom.cxx 478 2009-10-29 12:26:09Z linev $
00002 //-----------------------------------------------------------------------
00003 //       The GSI Online Offline Object Oriented (Go4) Project
00004 //         Experiment Data Processing at EE department, GSI
00005 //-----------------------------------------------------------------------
00006 // Copyright (C) 2000- GSI Helmholtzzentrum für Schwerionenforschung GmbH
00007 //                     Planckstr. 1, 64291 Darmstadt, Germany
00008 // Contact:            http://go4.gsi.de
00009 //-----------------------------------------------------------------------
00010 // This software can be used under the license agreements as stated
00011 // in Go4License.txt file which is part of the distribution.
00012 //-----------------------------------------------------------------------
00013 
00014 #include "TGo4FitModelPolynom.h"
00015 
00016 #include "Riostream.h"
00017 
00018 #include "TMath.h"
00019 #include "TArrayD.h"
00020 
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       TString infostr;
00059       infostr.Form("Polynom order for axis %d",n);
00060       if (orders) NewParameter(GetOrderParName(n),infostr.Data(),orders[n],kTRUE, AtIndx);
00061             else  NewParameter(GetOrderParName(n),infostr.Data(),0.,kTRUE, AtIndx);
00062    }
00063 }
00064 
00065 TString TGo4FitModelPolynom::GetOrderParName(Int_t naxis)
00066 {
00067    TString res;
00068    res.Form("Order%d",naxis);
00069    return res;
00070 }
00071 
00072 Double_t TGo4FitModelPolynom::GetPolynomOrder(Int_t naxis) {
00073    TGo4FitParameter *par = FindPar(GetOrderParName(naxis));
00074    if (par==0) return 0.;
00075           else return par->GetValue();
00076 }
00077 
00078 Int_t TGo4FitModelPolynom::GetMaxNumAxis() {
00079    Int_t naxis = 0;
00080    while (FindPar(GetOrderParName(naxis))!=0) naxis++;
00081    return naxis-1;
00082 }
00083 
00084 Bool_t TGo4FitModelPolynom::SetMaxNumAxis(Int_t numaxis) {
00085    Int_t numaxisold = GetMaxNumAxis();
00086    if ((numaxis<0) || (numaxis==numaxisold)) return kFALSE;
00087    if (numaxis<numaxisold)
00088      for(Int_t n=numaxis+1;n<=numaxisold;n++)
00089         RemovePar(GetOrderParName(n));
00090    else {
00091       Int_t indx = GetParIndex(FindPar(GetOrderParName(numaxisold)));
00092       CreateOrdersPars(0,numaxisold+1,numaxis, indx+1);
00093    }
00094 
00095    return kTRUE;
00096 }
00097 
00098 Bool_t TGo4FitModelPolynom::BeforeEval(Int_t NDimension) {
00099    if (fxAllOrders) delete fxAllOrders;
00100    Par_ndim = NDimension;
00101    fxAllOrders = new TArrayD(Par_ndim);
00102    fxAllOrders->Reset(0.);
00103    Par_orders = fxAllOrders->GetArray();
00104    for(Int_t i=0;i<Par_ndim;i++)
00105       Par_orders[i]=GetPolynomOrder(i);
00106    return kTRUE;
00107 }
00108 
00109 Double_t TGo4FitModelPolynom::EvalN(const Double_t* v) {
00110     Double_t zn = 1.;
00111     for(Int_t n=0;n<Par_ndim;n++)
00112        zn *= TMath::Power(v[n],Par_orders[n]);
00113     return zn;
00114 }
00115 
00116 void TGo4FitModelPolynom::AfterEval() {
00117    if (fxAllOrders) { delete fxAllOrders; fxAllOrders=0; }
00118 }
00119 
00120 void TGo4FitModelPolynom::Print(Option_t* option) const {
00121    TGo4FitModel::Print(option);
00122 }

Generated on Thu Oct 28 15:54:12 2010 for Go4-Fitpackagev4.04-2 by  doxygen 1.5.1