RooPolyVar.cxx

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  * @(#)root/roofitcore:$Id: RooPolyVar.cxx 26044 2008-10-31 16:45:22Z 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 // Class RooPolyVar is a RooAbsReal implementing a polynomial in terms
00021 // of a list of RooAbsReal coefficients
00022 // <pre>
00023 // f(x) = sum_i a_i * x
00024 // </pre>
00025 // Class RooPolyvar implements analytical integrals of all polynomials
00026 // it can define.
00027 // END_HTML
00028 //
00029 
00030 #include "RooFit.h"
00031 
00032 #include "Riostream.h"
00033 #include "Riostream.h"
00034 #include <math.h>
00035 #include "TMath.h"
00036 
00037 #include "RooPolyVar.h"
00038 #include "RooAbsReal.h"
00039 #include "RooRealVar.h"
00040 #include "RooArgList.h"
00041 #include "RooMsgService.h"
00042 #include "TMath.h"
00043 
00044 ClassImp(RooPolyVar)
00045 ;
00046 
00047 
00048 //_____________________________________________________________________________
00049 RooPolyVar::RooPolyVar()
00050 {
00051   // Default constructor
00052   _coefIter = _coefList.createIterator() ;
00053 }
00054 
00055 
00056 //_____________________________________________________________________________
00057 RooPolyVar::RooPolyVar(const char* name, const char* title, 
00058                              RooAbsReal& x, const RooArgList& coefList, Int_t lowestOrder) :
00059   RooAbsReal(name, title),
00060   _x("x", "Dependent", this, x),
00061   _coefList("coefList","List of coefficients",this),
00062   _lowestOrder(lowestOrder) 
00063 {
00064   // Construct polynomial in x with coefficients in coefList. If
00065   // lowestOrder is not zero, then the first element in coefList is
00066   // interpreted as as the 'lowestOrder' coefficients and all
00067   // subsequent coeffient elements are shifted by a similar amount.
00068 
00069 
00070   _coefIter = _coefList.createIterator() ;
00071 
00072   // Check lowest order
00073   if (_lowestOrder<0) {
00074     coutE(InputArguments) << "RooPolyVar::ctor(" << GetName() 
00075                           << ") WARNING: lowestOrder must be >=0, setting value to 0" << endl ;
00076     _lowestOrder=0 ;
00077   }
00078 
00079   TIterator* coefIter = coefList.createIterator() ;
00080   RooAbsArg* coef ;
00081   while((coef = (RooAbsArg*)coefIter->Next())) {
00082     if (!dynamic_cast<RooAbsReal*>(coef)) {
00083       coutE(InputArguments) << "RooPolyVar::ctor(" << GetName() << ") ERROR: coefficient " << coef->GetName() 
00084                             << " is not of type RooAbsReal" << endl ;
00085       assert(0) ;
00086     }
00087     _coefList.add(*coef) ;
00088   }
00089   delete coefIter ;
00090 }
00091 
00092 
00093 
00094 //_____________________________________________________________________________
00095 RooPolyVar::RooPolyVar(const char* name, const char* title,
00096                            RooAbsReal& x) :
00097   RooAbsReal(name, title),
00098   _x("x", "Dependent", this, x),
00099   _coefList("coefList","List of coefficients",this),
00100   _lowestOrder(1)
00101 {
00102   // Constructor of flat polynomial function
00103 
00104   _coefIter = _coefList.createIterator() ;
00105 }                                                                                                                                 
00106 
00107 
00108 
00109 //_____________________________________________________________________________
00110 RooPolyVar::RooPolyVar(const RooPolyVar& other, const char* name) :
00111   RooAbsReal(other, name), 
00112   _x("x", this, other._x), 
00113   _coefList("coefList",this,other._coefList),
00114   _lowestOrder(other._lowestOrder) 
00115 {
00116   // Copy constructor
00117   _coefIter = _coefList.createIterator() ;
00118 }
00119 
00120 
00121 
00122 
00123 //_____________________________________________________________________________
00124 RooPolyVar::~RooPolyVar() 
00125 {
00126   // Destructor
00127   delete _coefIter ;
00128 }
00129 
00130 
00131 
00132 
00133 //_____________________________________________________________________________
00134 Double_t RooPolyVar::evaluate() const 
00135 {
00136   // Calculate and return value of polynomial
00137 
00138   Double_t sum(0) ;
00139   Int_t order(_lowestOrder) ;
00140   _coefIter->Reset() ;
00141 
00142   RooAbsReal* coef ;
00143   const RooArgSet* nset = _coefList.nset() ;
00144   while((coef=(RooAbsReal*)_coefIter->Next())) {
00145     sum += coef->getVal(nset)*TMath::Power(_x,order++) ;
00146   }
00147 
00148   return sum;
00149 }
00150 
00151 
00152 
00153 //_____________________________________________________________________________
00154 Int_t RooPolyVar::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* /*rangeName*/) const 
00155 {
00156   // Advertise that we can internally integrate over x
00157 
00158   if (matchArgs(allVars, analVars, _x)) return 1;
00159   return 0;
00160 }
00161 
00162 
00163 
00164 //_____________________________________________________________________________
00165 Double_t RooPolyVar::analyticalIntegral(Int_t code, const char* rangeName) const 
00166 {
00167   // Calculate and return analytical integral over x
00168 
00169   assert(code==1) ;
00170 
00171   Double_t sum(0) ;
00172 
00173   const RooArgSet* nset = _coefList.nset() ;
00174   Int_t order(_lowestOrder) ;
00175   _coefIter->Reset() ;
00176   RooAbsReal* coef ;
00177 
00178   // Primitive = sum(k) coef_k * 1/(k+1) x^(k+1)
00179   while((coef=(RooAbsReal*)_coefIter->Next())) {
00180     sum += coef->getVal(nset)*(TMath::Power(_x.max(rangeName),order+1)-TMath::Power(_x.min(rangeName),order+1))/(order+1) ; 
00181     order++ ;
00182   }
00183 
00184   return sum;  
00185   
00186 }

Generated on Tue Jul 5 15:07:02 2011 for ROOT_528-00b_version by  doxygen 1.5.1