RooPolynomial.cxx

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitModels                                                     *
00004  * @(#)root/roofit:$Id: RooPolynomial.cxx 36209 2010-10-08 21:37:36Z wouter $
00005  * Authors:                                                                  *
00006  *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
00007  *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
00008  *                                                                           *
00009  * Copyright (c) 2000-2005, Regents of the University of California          *
00010  *                          and Stanford University. All rights reserved.    *
00011  *                                                                           *
00012  * Redistribution and use in source and binary forms,                        *
00013  * with or without modification, are permitted according to the terms        *
00014  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
00015  *****************************************************************************/
00016 
00017 //////////////////////////////////////////////////////////////////////////////
00018 //
00019 // BEGIN_HTML
00020 // RooPolynomial implements a polynomial p.d.f of the form
00021 // <pre>
00022 // f(x) = sum_i a_i * x^i
00023 //</pre>
00024 // By default coefficient a_0 is chosen to be 1, as polynomial
00025 // probability density functions have one degree of freedome
00026 // less than polynomial functions due to the normalization condition
00027 // END_HTML
00028 //
00029 
00030 #include "RooFit.h"
00031 
00032 #include "Riostream.h"
00033 #include "Riostream.h"
00034 #include "TMath.h"
00035 
00036 #include "RooPolynomial.h"
00037 #include "RooAbsReal.h"
00038 #include "RooRealVar.h"
00039 #include "RooArgList.h"
00040 
00041 ClassImp(RooPolynomial)
00042 ;
00043 
00044 
00045 //_____________________________________________________________________________
00046 RooPolynomial::RooPolynomial()
00047 {
00048   // coverity[UNINIT_CTOR]
00049   _coefIter = _coefList.createIterator() ;
00050 }
00051 
00052 
00053 //_____________________________________________________________________________
00054 RooPolynomial::RooPolynomial(const char* name, const char* title, 
00055                              RooAbsReal& x, const RooArgList& coefList, Int_t lowestOrder) :
00056   RooAbsPdf(name, title),
00057   _x("x", "Dependent", this, x),
00058   _coefList("coefList","List of coefficients",this),
00059   _lowestOrder(lowestOrder) 
00060 {
00061   // Constructor
00062   _coefIter = _coefList.createIterator() ;
00063 
00064   // Check lowest order
00065   if (_lowestOrder<0) {
00066     cout << "RooPolynomial::ctor(" << GetName() 
00067          << ") WARNING: lowestOrder must be >=0, setting value to 0" << endl ;
00068     _lowestOrder=0 ;
00069   }
00070 
00071   TIterator* coefIter = coefList.createIterator() ;
00072   RooAbsArg* coef ;
00073   while((coef = (RooAbsArg*)coefIter->Next())) {
00074     if (!dynamic_cast<RooAbsReal*>(coef)) {
00075       cout << "RooPolynomial::ctor(" << GetName() << ") ERROR: coefficient " << coef->GetName() 
00076            << " is not of type RooAbsReal" << endl ;
00077       assert(0) ;
00078     }
00079     _coefList.add(*coef) ;
00080   }
00081   delete coefIter ;
00082 }
00083 
00084 
00085 
00086 //_____________________________________________________________________________
00087 RooPolynomial::RooPolynomial(const char* name, const char* title,
00088                            RooAbsReal& x) :
00089   RooAbsPdf(name, title),
00090   _x("x", "Dependent", this, x),
00091   _coefList("coefList","List of coefficients",this),
00092   _lowestOrder(1)
00093 {
00094   _coefIter = _coefList.createIterator() ;
00095 }                                                                                                                                 
00096 
00097 
00098 
00099 //_____________________________________________________________________________
00100 RooPolynomial::RooPolynomial(const RooPolynomial& other, const char* name) :
00101   RooAbsPdf(other, name), 
00102   _x("x", this, other._x), 
00103   _coefList("coefList",this,other._coefList),
00104   _lowestOrder(other._lowestOrder) 
00105 {
00106   // Copy constructor
00107   _coefIter = _coefList.createIterator() ;
00108 }
00109 
00110 
00111 
00112 
00113 //_____________________________________________________________________________
00114 RooPolynomial::~RooPolynomial()
00115 {
00116   // Destructor
00117   delete _coefIter ;
00118 }
00119 
00120 
00121 
00122 
00123 //_____________________________________________________________________________
00124 Double_t RooPolynomial::evaluate() const 
00125 {
00126   Int_t order(_lowestOrder) ;
00127   Double_t sum(order<1 ? 0 : 1) ;
00128 
00129   _coefIter->Reset() ;
00130 
00131   RooAbsReal* coef ;
00132   const RooArgSet* nset = _coefList.nset() ;
00133   while((coef=(RooAbsReal*)_coefIter->Next())) {
00134     sum += coef->getVal(nset)*TMath::Power(_x,order++) ;
00135   }
00136 
00137 //   if (sum<=0) {
00138     //cout << "RooPolynomial sum = " << sum << endl ;  
00139 //   }
00140   return sum;
00141 }
00142 
00143 
00144 
00145 //_____________________________________________________________________________
00146 Int_t RooPolynomial::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* /*rangeName*/) const 
00147 {
00148   if (matchArgs(allVars, analVars, _x)) return 1;
00149   return 0;
00150 }
00151 
00152 
00153 
00154 //_____________________________________________________________________________
00155 Double_t RooPolynomial::analyticalIntegral(Int_t code, const char* rangeName) const 
00156 {
00157   assert(code==1) ;
00158 
00159   Int_t order(_lowestOrder) ;
00160   
00161   Double_t sum(order>0 ? _x.max(rangeName)-_x.min(rangeName) : 0) ;
00162   //cout << "RooPolynomial::aI(" << GetName() << ") range = " << _x.min(rangeName) << " - " << _x.max(rangeName) << endl ;
00163   
00164   const RooArgSet* nset = _coefList.nset() ;
00165   _coefIter->Reset() ;
00166   RooAbsReal* coef ;
00167 
00168   // Primitive = sum(k) coef_k * 1/(k+1) x^(k+1)
00169   while((coef=(RooAbsReal*)_coefIter->Next())) {
00170     sum += coef->getVal(nset)*(TMath::Power(_x.max(rangeName),order+1)-TMath::Power(_x.min(rangeName),order+1))/(order+1) ; 
00171     order++ ;
00172   }
00173 
00174   return sum;  
00175   
00176 }

Generated on Tue Jul 5 14:55:24 2011 for ROOT_528-00b_version by  doxygen 1.5.1