CMS 3D CMS Logo

Classes | Public Member Functions | Protected Member Functions | Protected Attributes

FastVerticalInterpHistPdfBase Class Reference

#include <VerticalInterpHistPdf.h>

Inheritance diagram for FastVerticalInterpHistPdfBase:
FastVerticalInterpHistPdf FastVerticalInterpHistPdf2D

List of all members.

Classes

struct  Morph
 Must be public, for serialization. More...

Public Member Functions

virtual TObject * clone (const char *newname) const =0
const RooArgList & coefList () const
Double_t evaluate () const =0
 FastVerticalInterpHistPdfBase (const char *name, const char *title, const RooArgSet &obs, const RooArgList &funcList, const RooArgList &coefList, Double_t smoothRegion=1., Int_t smoothAlgo=1)
 FastVerticalInterpHistPdfBase ()
 FastVerticalInterpHistPdfBase (const FastVerticalInterpHistPdfBase &other, const char *name=0)
const RooArgList & funcList () const
Bool_t selfNormalized () const
virtual ~FastVerticalInterpHistPdfBase ()

Protected Member Functions

double smoothStepFunc (double x) const
void syncMorph (Morph &out, const FastTemplate &nominal, FastTemplate &lo, FastTemplate &hi) const
 not to be serialized
void syncTotal (FastTemplate &cache, const FastTemplate &cacheNominal, const FastTemplate &cacheNominalLog) const

Protected Attributes

TIterator * _coefIter
 Iterator over FUNC list.
RooListProxy _coefList
TIterator * _funcIter
RooListProxy _funcList
bool _init
 Iterator over coefficient list.
std::vector< RooAbsReal * > _morphParams
 not to be serialized
std::vector< Morph_morphs
 not to be serialized
SimpleCacheSentry _sentry
 not to be serialized
Int_t _smoothAlgo
Double_t _smoothRegion
RooRealProxy _x

Detailed Description

Definition at line 70 of file VerticalInterpHistPdf.h.


Constructor & Destructor Documentation

FastVerticalInterpHistPdfBase::FastVerticalInterpHistPdfBase ( )
FastVerticalInterpHistPdfBase::FastVerticalInterpHistPdfBase ( const char *  name,
const char *  title,
const RooArgSet &  obs,
const RooArgList &  funcList,
const RooArgList &  coefList,
Double_t  smoothRegion = 1.,
Int_t  smoothAlgo = 1 
)

Definition at line 239 of file VerticalInterpHistPdf.cc.

References _coefIter, _coefList, _funcIter, _funcList, and TRACEME.

                                                                                                                                                                                                                           :
  RooAbsPdf(name,title),
  _funcList("funcList","List of pdfs",this),
  _coefList("coefList","List of coefficients",this), // we should get shapeDirty when coefficients change
  _smoothRegion(smoothRegion),
  _smoothAlgo(smoothAlgo),
  _init(false),
  _morphs(), _morphParams()
{ 
  TRACEME()

  if (inFuncList.getSize()!=2*inCoefList.getSize()+1) {
    coutE(InputArguments) << "VerticalInterpHistPdf::VerticalInterpHistPdf(" << GetName() 
                          << ") number of pdfs and coefficients inconsistent, must have Nfunc=1+2*Ncoef" << endl ;
    assert(0);
  }

  TIterator* funcIter = inFuncList.createIterator() ;
  RooAbsArg* func;
  while((func = (RooAbsArg*)funcIter->Next())) {
    RooAbsPdf *pdf = dynamic_cast<RooAbsPdf*>(func);
    if (!pdf) {
      coutE(InputArguments) << "ERROR: VerticalInterpHistPdf::VerticalInterpHistPdf(" << GetName() << ") function  " << func->GetName() << " is not of type RooAbsPdf" << endl;
      assert(0);
    }
    RooArgSet *params = pdf->getParameters(obs);
    if (params->getSize() > 0) {
      coutE(InputArguments) << "ERROR: VerticalInterpHistPdf::VerticalInterpHistPdf(" << GetName() << ") pdf  " << func->GetName() << " has some parameters." << endl;
      assert(0);
    }
    delete params;
    _funcList.add(*func) ;
  }
  delete funcIter;

  TIterator* coefIter = inCoefList.createIterator() ;
  RooAbsArg* coef;
  while((coef = (RooAbsArg*)coefIter->Next())) {
    if (!dynamic_cast<RooAbsReal*>(coef)) {
      coutE(InputArguments) << "ERROR: VerticalInterpHistPdf::VerticalInterpHistPdf(" << GetName() << ") coefficient " << coef->GetName() << " is not of type RooAbsReal" << endl;
      assert(0);
    }
    _coefList.add(*coef) ;    
  }
  delete coefIter;

  _funcIter  = _funcList.createIterator() ;
  _coefIter = _coefList.createIterator() ;

}
FastVerticalInterpHistPdfBase::FastVerticalInterpHistPdfBase ( const FastVerticalInterpHistPdfBase other,
const char *  name = 0 
)

Definition at line 291 of file VerticalInterpHistPdf.cc.

References _coefIter, _coefList, _funcIter, _funcList, _sentry, and SimpleCacheSentry::addVars().

                                                                                                                         :
  RooAbsPdf(other,name),
  _funcList("funcList",this,other._funcList),
  _coefList("coefList",this,other._coefList),
  _smoothRegion(other._smoothRegion),
  _smoothAlgo(other._smoothAlgo),
  _init(false),
#ifdef FastVerticalInterpHistPdf_CopyConstructor
  _morphs(other._morphs), _morphParams(other._morphParams)
#else
  _morphs(), _morphParams()
#endif
{
  // Copy constructor
  _funcIter  = _funcList.createIterator() ;
  _coefIter = _coefList.createIterator() ;
#ifdef FastVerticalInterpHistPdf_CopyConstructor
  _sentry.addVars(_coefList);
  _sentry.setValueDirty(); 
#endif
}
FastVerticalInterpHistPdfBase::~FastVerticalInterpHistPdfBase ( ) [virtual]

Definition at line 315 of file VerticalInterpHistPdf.cc.

References _coefIter, and _funcIter.

{
  // Destructor
  delete _funcIter ;
  delete _coefIter ;
}

Member Function Documentation

virtual TObject* FastVerticalInterpHistPdfBase::clone ( const char *  newname) const [pure virtual]
const RooArgList& FastVerticalInterpHistPdfBase::coefList ( ) const [inline]

Definition at line 84 of file VerticalInterpHistPdf.h.

References _coefList.

{ return _coefList ; }
Double_t FastVerticalInterpHistPdfBase::evaluate ( ) const [pure virtual]
const RooArgList& FastVerticalInterpHistPdfBase::funcList ( ) const [inline]

Definition at line 83 of file VerticalInterpHistPdf.h.

References _funcList.

{ return _funcList ; }
Bool_t FastVerticalInterpHistPdfBase::selfNormalized ( ) const [inline]

Reimplemented in FastVerticalInterpHistPdf2D.

Definition at line 79 of file VerticalInterpHistPdf.h.

{ return kTRUE; }
double FastVerticalInterpHistPdfBase::smoothStepFunc ( double  x) const [inline, protected]

Definition at line 114 of file VerticalInterpHistPdf.h.

References _smoothRegion.

Referenced by syncTotal().

                                               { 
    if (fabs(x) >= _smoothRegion) return x > 0 ? +1 : -1;
    double xnorm = x/_smoothRegion, xnorm2 = xnorm*xnorm;
    return 0.125 * xnorm * (xnorm2 * (3.*xnorm2 - 10.) + 15);
  }
void FastVerticalInterpHistPdfBase::syncMorph ( Morph out,
const FastTemplate nominal,
FastTemplate lo,
FastTemplate hi 
) const [protected]

not to be serialized

Definition at line 380 of file VerticalInterpHistPdf.cc.

References _smoothAlgo, FastVerticalInterpHistPdfBase::Morph::diff, FastTemplate::LogRatio(), FastTemplate::Subtract(), FastVerticalInterpHistPdfBase::Morph::sum, and FastTemplate::SumDiff().

Referenced by FastVerticalInterpHistPdf2D::syncComponents(), and FastVerticalInterpHistPdf::syncComponents().

                                                                                                                               {
    if (_smoothAlgo < 0)  {
        hi.LogRatio(nominal); lo.LogRatio(nominal);
        //printf("Log-ratios for dimension %d: \n", dim);  hi.Dump(); lo.Dump();
    } else {
        hi.Subtract(nominal); lo.Subtract(nominal);
        //printf("Differences for dimension %d: \n", dim);  hi.Dump(); lo.Dump();
    }
    FastTemplate::SumDiff(hi, lo, out.sum, out.diff);
    //printf("Sum and diff for dimension %d: \n", dim);  out.sum.Dump(); out.diff.Dump();
}
void FastVerticalInterpHistPdfBase::syncTotal ( FastTemplate cache,
const FastTemplate cacheNominal,
const FastTemplate cacheNominalLog 
) const [protected]

Definition at line 427 of file VerticalInterpHistPdf.cc.

References _coefList, _init, _morphParams, _morphs, _sentry, _smoothAlgo, a, b, FastTemplate::CopyValues(), FastTemplate::CropUnderflows(), diffTreeTool::diff, FastTemplate::Exp(), i, FastTemplate::Meld(), SimpleCacheSentry::reset(), smoothStepFunc(), TRACEME, and x.

                                                                                                                                              {
    TRACEME()
    /* === how the algorithm works, in theory ===
     * let  dhi = h_hi - h_nominal
     *      dlo = h_lo - h_nominal
     * and x be the morphing parameter
     * we define alpha = x * 0.5 * ((dhi-dlo) + (dhi+dlo)*smoothStepFunc(x));
     * which satisfies:
     *     alpha(0) = 0
     *     alpha(+1) = dhi 
     *     alpha(-1) = dlo
     *     alpha(x >= +1) = |x|*dhi
     *     alpha(x <= -1) = |x|*dlo
     *     alpha is continuous and has continuous first and second derivative, as smoothStepFunc has them
     * === and in practice ===
     * we already have computed the histogram for diff=(dhi-dlo) and sum=(dhi+dlo)
     * so we just do template += (0.5 * x) * (diff + smoothStepFunc(x) * sum)
     * ========================================== */

    // start from nominal
    cache.CopyValues(_smoothAlgo < 0 ? cacheNominalLog : cacheNominal);
    //printf("Cache initialized to nominal template: \n");  cacheNominal.Dump();

    // apply all morphs one by one
    for (int i = 0, ndim = _coefList.getSize(); i < ndim; ++i) {
        double x = _morphParams[i]->getVal();
        double a = 0.5*x, b = smoothStepFunc(x);
        cache.Meld(_morphs[i].diff, _morphs[i].sum, a, b);    
        //printf("Merged transformation for dimension %d, x = %+5.3f, step = %.3f: \n", i, x, b);  cache.Dump();
    }

    // if necessary go back to linear scale
    if (_smoothAlgo < 0) {
        cache.Exp();
        //printf("Done exponential tranformation\n");  cache.Dump();
    } else {
        cache.CropUnderflows();
    }
    
    // mark as done
    _sentry.reset();
    _init = true;
}

Member Data Documentation

RooListProxy FastVerticalInterpHistPdfBase::_coefList [protected]
RooListProxy FastVerticalInterpHistPdfBase::_funcList [protected]
bool FastVerticalInterpHistPdfBase::_init [mutable, protected]
std::vector<RooAbsReal *> FastVerticalInterpHistPdfBase::_morphParams [mutable, protected]
std::vector<Morph> FastVerticalInterpHistPdfBase::_morphs [mutable, protected]

Definition at line 92 of file VerticalInterpHistPdf.h.

Referenced by smoothStepFunc().

RooRealProxy FastVerticalInterpHistPdfBase::_x [protected]

Reimplemented in FastVerticalInterpHistPdf, and FastVerticalInterpHistPdf2D.

Definition at line 89 of file VerticalInterpHistPdf.h.