ROOT logo
/*****************************************************************************
 * Project: RooFit                                                           *
 * Package: RooFitModels                                                     *
 * @(#)root/roofit:$Id: RooChebychev.cxx 26878 2008-12-12 15:21:17Z wouter $
 * Authors:                                                                  *
 *   GR, Gerhard Raven,   UC San Diego, Gerhard.Raven@slac.stanford.edu
 *                                                                           *
 * Copyright (c) 2000-2005, Regents of the University of California          *
 *                          and Stanford University. All rights reserved.    *
 *                                                                           *
 * Redistribution and use in source and binary forms,                        *
 * with or without modification, are permitted according to the terms        *
 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
 *****************************************************************************/

//////////////////////////////////////////////////////////////////////////////
//
// BEGIN_HTML
// Chebychev polynomial p.d.f. of the first kind
// END_HTML
//

#include "RooFit.h"

#include "Riostream.h"
#include "Riostream.h"
#include <math.h>

#include "RooChebychev.h"
#include "RooAbsReal.h"
#include "RooRealVar.h"
#include "RooArgList.h"

ClassImp(RooChebychev)
;


//_____________________________________________________________________________
RooChebychev::RooChebychev()
{
}


//_____________________________________________________________________________
RooChebychev::RooChebychev(const char* name, const char* title, 
                           RooAbsReal& x, const RooArgList& coefList): 
  RooAbsPdf(name, title),
  _x("x", "Dependent", this, x),
  _coefList("coefficients","List of coefficients",this)
{
  // Constructor
  TIterator* coefIter = coefList.createIterator() ;
  RooAbsArg* coef ;
  while((coef = (RooAbsArg*)coefIter->Next())) {
    if (!dynamic_cast<RooAbsReal*>(coef)) {
      cout << "RooChebychev::ctor(" << GetName() << ") ERROR: coefficient " << coef->GetName() 
	   << " is not of type RooAbsReal" << endl ;
      assert(0) ;
    }
    _coefList.add(*coef) ;
  }
  delete coefIter ;
}



//_____________________________________________________________________________
RooChebychev::RooChebychev(const RooChebychev& other, const char* name) :
  RooAbsPdf(other, name), 
  _x("x", this, other._x), 
  _coefList("coefList",this,other._coefList)
{
}

inline static double p0(double ,double a) {  return a; }
inline static double p1(double t,double a,double b) {  return a*t+b; }
inline static double p2(double t,double a,double b,double c) {  return p1(t,p1(t,a,b),c); }
inline static double p3(double t,double a,double b,double c,double d) {  return p2(t,p1(t,a,b),c,d); }
inline static double p4(double t,double a,double b,double c,double d,double e) {  return p3(t,p1(t,a,b),c,d,e); }


//_____________________________________________________________________________
Double_t RooChebychev::evaluate() const 
{

  Double_t xmin = _x.min(); Double_t xmax = _x.max();
  Double_t x(-1+2*(_x-xmin)/(xmax-xmin));
  Double_t x2(x*x);
  Double_t sum(0) ;
  switch (_coefList.getSize()) {
  case  7: sum+=((RooAbsReal&)_coefList[6]).getVal()*x*p3(x2,64,-112,56,-7);
  case  6: sum+=((RooAbsReal&)_coefList[5]).getVal()*p3(x2,32,-48,18,-1);
  case  5: sum+=((RooAbsReal&)_coefList[4]).getVal()*x*p2(x2,16,-20,5);
  case  4: sum+=((RooAbsReal&)_coefList[3]).getVal()*p2(x2,8,-8,1);
  case  3: sum+=((RooAbsReal&)_coefList[2]).getVal()*x*p1(x2,4,-3);
  case  2: sum+=((RooAbsReal&)_coefList[1]).getVal()*p1(x2,2,-1);
  case  1: sum+=((RooAbsReal&)_coefList[0]).getVal()*x;
  case  0: sum+=1;
  }
  return sum;
}


//_____________________________________________________________________________
Int_t RooChebychev::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* rangeName) const 
{
  // No analytical calculation available (yet) of integrals over subranges
  if (rangeName && strlen(rangeName)) {
    return 0 ;
  }

  if (matchArgs(allVars, analVars, _x)) return 1;
  return 0;
}


//_____________________________________________________________________________
Double_t RooChebychev::analyticalIntegral(Int_t code, const char* rangeName) const 
{
  assert(code==1) ;
  // WVE check that this works all right for sub ranges
  Double_t xmin = _x.min(rangeName); Double_t xmax = _x.max(rangeName);
  Double_t norm(0) ;
  switch(_coefList.getSize()) {
  case  7: case  6: norm+=((RooAbsReal&)_coefList[5]).getVal()*(-1 + 18./3. - 48./5. + 32./7.);
  case  5: case  4: norm+=((RooAbsReal&)_coefList[3]).getVal()*( 1 -  8./3. +  8./5.);
  case  3: case  2: norm+=((RooAbsReal&)_coefList[1]).getVal()*(-1 +  2./3.);
  case  1: case  0: norm+= 1;
  }
  norm *= xmax-xmin;
  return norm;
}
 RooChebychev.cxx:1
 RooChebychev.cxx:2
 RooChebychev.cxx:3
 RooChebychev.cxx:4
 RooChebychev.cxx:5
 RooChebychev.cxx:6
 RooChebychev.cxx:7
 RooChebychev.cxx:8
 RooChebychev.cxx:9
 RooChebychev.cxx:10
 RooChebychev.cxx:11
 RooChebychev.cxx:12
 RooChebychev.cxx:13
 RooChebychev.cxx:14
 RooChebychev.cxx:15
 RooChebychev.cxx:16
 RooChebychev.cxx:17
 RooChebychev.cxx:18
 RooChebychev.cxx:19
 RooChebychev.cxx:20
 RooChebychev.cxx:21
 RooChebychev.cxx:22
 RooChebychev.cxx:23
 RooChebychev.cxx:24
 RooChebychev.cxx:25
 RooChebychev.cxx:26
 RooChebychev.cxx:27
 RooChebychev.cxx:28
 RooChebychev.cxx:29
 RooChebychev.cxx:30
 RooChebychev.cxx:31
 RooChebychev.cxx:32
 RooChebychev.cxx:33
 RooChebychev.cxx:34
 RooChebychev.cxx:35
 RooChebychev.cxx:36
 RooChebychev.cxx:37
 RooChebychev.cxx:38
 RooChebychev.cxx:39
 RooChebychev.cxx:40
 RooChebychev.cxx:41
 RooChebychev.cxx:42
 RooChebychev.cxx:43
 RooChebychev.cxx:44
 RooChebychev.cxx:45
 RooChebychev.cxx:46
 RooChebychev.cxx:47
 RooChebychev.cxx:48
 RooChebychev.cxx:49
 RooChebychev.cxx:50
 RooChebychev.cxx:51
 RooChebychev.cxx:52
 RooChebychev.cxx:53
 RooChebychev.cxx:54
 RooChebychev.cxx:55
 RooChebychev.cxx:56
 RooChebychev.cxx:57
 RooChebychev.cxx:58
 RooChebychev.cxx:59
 RooChebychev.cxx:60
 RooChebychev.cxx:61
 RooChebychev.cxx:62
 RooChebychev.cxx:63
 RooChebychev.cxx:64
 RooChebychev.cxx:65
 RooChebychev.cxx:66
 RooChebychev.cxx:67
 RooChebychev.cxx:68
 RooChebychev.cxx:69
 RooChebychev.cxx:70
 RooChebychev.cxx:71
 RooChebychev.cxx:72
 RooChebychev.cxx:73
 RooChebychev.cxx:74
 RooChebychev.cxx:75
 RooChebychev.cxx:76
 RooChebychev.cxx:77
 RooChebychev.cxx:78
 RooChebychev.cxx:79
 RooChebychev.cxx:80
 RooChebychev.cxx:81
 RooChebychev.cxx:82
 RooChebychev.cxx:83
 RooChebychev.cxx:84
 RooChebychev.cxx:85
 RooChebychev.cxx:86
 RooChebychev.cxx:87
 RooChebychev.cxx:88
 RooChebychev.cxx:89
 RooChebychev.cxx:90
 RooChebychev.cxx:91
 RooChebychev.cxx:92
 RooChebychev.cxx:93
 RooChebychev.cxx:94
 RooChebychev.cxx:95
 RooChebychev.cxx:96
 RooChebychev.cxx:97
 RooChebychev.cxx:98
 RooChebychev.cxx:99
 RooChebychev.cxx:100
 RooChebychev.cxx:101
 RooChebychev.cxx:102
 RooChebychev.cxx:103
 RooChebychev.cxx:104
 RooChebychev.cxx:105
 RooChebychev.cxx:106
 RooChebychev.cxx:107
 RooChebychev.cxx:108
 RooChebychev.cxx:109
 RooChebychev.cxx:110
 RooChebychev.cxx:111
 RooChebychev.cxx:112
 RooChebychev.cxx:113
 RooChebychev.cxx:114
 RooChebychev.cxx:115
 RooChebychev.cxx:116
 RooChebychev.cxx:117
 RooChebychev.cxx:118
 RooChebychev.cxx:119
 RooChebychev.cxx:120
 RooChebychev.cxx:121
 RooChebychev.cxx:122
 RooChebychev.cxx:123
 RooChebychev.cxx:124
 RooChebychev.cxx:125
 RooChebychev.cxx:126
 RooChebychev.cxx:127
 RooChebychev.cxx:128
 RooChebychev.cxx:129
 RooChebychev.cxx:130
 RooChebychev.cxx:131
 RooChebychev.cxx:132