ROOT logo
 /***************************************************************************** 
  * Project: RooFit                                                           * 
  *                                                                           * 
  * 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
// RooCachedPdf is an implementation of RooAbsCachedPdf that can cache
// any external RooAbsPdf input function provided in the constructor. 
// END_HTML
//

#include "Riostream.h" 

#include "RooAbsPdf.h"
#include "RooCachedPdf.h" 
#include "RooAbsReal.h" 
#include "RooMsgService.h"
#include "RooDataHist.h"
#include "RooHistPdf.h"

ClassImp(RooCachedPdf) 
  ;



//_____________________________________________________________________________
RooCachedPdf::RooCachedPdf(const char *name, const char *title, RooAbsPdf& _pdf) :
   RooAbsCachedPdf(name,title), 
   pdf("pdf","pdf",this,_pdf),
   _cacheObs("cacheObs","cacheObs",this,kFALSE,kFALSE)  
 { 
   // Constructor taking name, title and function to be cached. To control
   // granularity of the binning of the cache histogram set the desired properties
   // in the binning named "cache" in the observables of the function. The dimensions
   // of the cache are automatically matched to the number of observables used
   // in each use context. Multiple cache in different observable may exists
   // simultanously if the cached p.d.f is used with multiple observable 
   // configurations simultaneously
 } 



//_____________________________________________________________________________
RooCachedPdf::RooCachedPdf(const char *name, const char *title, RooAbsPdf& _pdf, const RooArgSet& cacheObs) :
   RooAbsCachedPdf(name,title), 
   pdf("pdf","pdf",this,_pdf),
   _cacheObs("cacheObs","cacheObs",this,kFALSE,kFALSE)  
 { 
   // Constructor taking name, title and function to be cached and
   // fixed choice of variable to cache. To control granularity of the
   // binning of the cache histogram set the desired properties in the
   // binning named "cache" in the observables of the function.
   // If the fixed set of cache observables does not match the observables
   // defined in the use context of the p.d.f the cache is still filled
   // completely. Ee.g. when it is specified to cache x and p and only x 
   // is a observable in the given use context the cache histogram will
   // store sampled values for all values of observable x and parameter p.
   // In such a mode of operation the cache will also not be recalculated
   // if the observable p changes

   _cacheObs.add(cacheObs) ;
 } 



//_____________________________________________________________________________
RooCachedPdf::RooCachedPdf(const RooCachedPdf& other, const char* name) :  
   RooAbsCachedPdf(other,name), 
   pdf("pdf",this,other.pdf),
   _cacheObs("cacheObs",this,other._cacheObs)
 { 
   // Copy constructor
 } 



//_____________________________________________________________________________
RooCachedPdf::~RooCachedPdf() 
{
  // Destructor
}



//_____________________________________________________________________________
void RooCachedPdf::fillCacheObject(RooAbsCachedPdf::PdfCacheElem& cache) const 
{
  // Update contents of cache histogram by resampling the input p.d.f. Note that
  // the cache is filled with normalized p.d.f values so that the RooHistPdf
  // that represents the cache contents can be explicitly declared as self normalized
  // eliminating the need for superfluous numeric calculations of unit normalization.s


  if (cache.hist()->get()->getSize()>1) {
    coutP(Eval) << "RooCachedPdf::fillCacheObject(" << GetName() << ") filling multi-dimensional cache" ;
  }

  // Update contents of histogram
  ((RooAbsPdf&)pdf.arg()).fillDataHist(cache.hist(),&cache.nset(),1.0,kFALSE,kTRUE) ;

  if (cache.hist()->get()->getSize()>1) {
    ccoutP(Eval) << endl ;
  }

  cache.pdf()->setUnitNorm(kTRUE) ;
}



//_____________________________________________________________________________
void RooCachedPdf::preferredObservableScanOrder(const RooArgSet& obs, RooArgSet& orderedObs) const
{
  // Defer preferred scan order to cached pdf prefernece
  pdf.arg().preferredObservableScanOrder(obs,orderedObs) ;
}



//_____________________________________________________________________________
RooArgSet* RooCachedPdf::actualObservables(const RooArgSet& nset) const 
{ 
  // If this pdf is operated with a fixed set of observables, return
  // the subset of the fixed observables that are actual dependents
  // of the external input p.d.f. If this p.d.f is operated without
  // a fixed set of cache observables, return the actual observables
  // of the external input p.d.f given the choice of observables defined
  // in nset

  if (_cacheObs.getSize()>0) {
    return pdf.arg().getObservables(_cacheObs) ;
  } 

  return pdf.arg().getObservables(nset) ; 
}



//_____________________________________________________________________________
RooArgSet* RooCachedPdf::actualParameters(const RooArgSet& nset) const 
{ 
  // If this p.d.f is operated with a fixed set of observables, return
  // all variables of the external input p.d.f that are not one of
  // the cache observables. If this p.d.f is operated in automatic mode,
  // return the parameters of the external input p.d.f

  if (_cacheObs.getSize()>0) {
    return pdf.arg().getParameters(_cacheObs) ;
  } 
  return pdf.arg().getParameters(nset) ; 
}


 RooCachedPdf.cxx:1
 RooCachedPdf.cxx:2
 RooCachedPdf.cxx:3
 RooCachedPdf.cxx:4
 RooCachedPdf.cxx:5
 RooCachedPdf.cxx:6
 RooCachedPdf.cxx:7
 RooCachedPdf.cxx:8
 RooCachedPdf.cxx:9
 RooCachedPdf.cxx:10
 RooCachedPdf.cxx:11
 RooCachedPdf.cxx:12
 RooCachedPdf.cxx:13
 RooCachedPdf.cxx:14
 RooCachedPdf.cxx:15
 RooCachedPdf.cxx:16
 RooCachedPdf.cxx:17
 RooCachedPdf.cxx:18
 RooCachedPdf.cxx:19
 RooCachedPdf.cxx:20
 RooCachedPdf.cxx:21
 RooCachedPdf.cxx:22
 RooCachedPdf.cxx:23
 RooCachedPdf.cxx:24
 RooCachedPdf.cxx:25
 RooCachedPdf.cxx:26
 RooCachedPdf.cxx:27
 RooCachedPdf.cxx:28
 RooCachedPdf.cxx:29
 RooCachedPdf.cxx:30
 RooCachedPdf.cxx:31
 RooCachedPdf.cxx:32
 RooCachedPdf.cxx:33
 RooCachedPdf.cxx:34
 RooCachedPdf.cxx:35
 RooCachedPdf.cxx:36
 RooCachedPdf.cxx:37
 RooCachedPdf.cxx:38
 RooCachedPdf.cxx:39
 RooCachedPdf.cxx:40
 RooCachedPdf.cxx:41
 RooCachedPdf.cxx:42
 RooCachedPdf.cxx:43
 RooCachedPdf.cxx:44
 RooCachedPdf.cxx:45
 RooCachedPdf.cxx:46
 RooCachedPdf.cxx:47
 RooCachedPdf.cxx:48
 RooCachedPdf.cxx:49
 RooCachedPdf.cxx:50
 RooCachedPdf.cxx:51
 RooCachedPdf.cxx:52
 RooCachedPdf.cxx:53
 RooCachedPdf.cxx:54
 RooCachedPdf.cxx:55
 RooCachedPdf.cxx:56
 RooCachedPdf.cxx:57
 RooCachedPdf.cxx:58
 RooCachedPdf.cxx:59
 RooCachedPdf.cxx:60
 RooCachedPdf.cxx:61
 RooCachedPdf.cxx:62
 RooCachedPdf.cxx:63
 RooCachedPdf.cxx:64
 RooCachedPdf.cxx:65
 RooCachedPdf.cxx:66
 RooCachedPdf.cxx:67
 RooCachedPdf.cxx:68
 RooCachedPdf.cxx:69
 RooCachedPdf.cxx:70
 RooCachedPdf.cxx:71
 RooCachedPdf.cxx:72
 RooCachedPdf.cxx:73
 RooCachedPdf.cxx:74
 RooCachedPdf.cxx:75
 RooCachedPdf.cxx:76
 RooCachedPdf.cxx:77
 RooCachedPdf.cxx:78
 RooCachedPdf.cxx:79
 RooCachedPdf.cxx:80
 RooCachedPdf.cxx:81
 RooCachedPdf.cxx:82
 RooCachedPdf.cxx:83
 RooCachedPdf.cxx:84
 RooCachedPdf.cxx:85
 RooCachedPdf.cxx:86
 RooCachedPdf.cxx:87
 RooCachedPdf.cxx:88
 RooCachedPdf.cxx:89
 RooCachedPdf.cxx:90
 RooCachedPdf.cxx:91
 RooCachedPdf.cxx:92
 RooCachedPdf.cxx:93
 RooCachedPdf.cxx:94
 RooCachedPdf.cxx:95
 RooCachedPdf.cxx:96
 RooCachedPdf.cxx:97
 RooCachedPdf.cxx:98
 RooCachedPdf.cxx:99
 RooCachedPdf.cxx:100
 RooCachedPdf.cxx:101
 RooCachedPdf.cxx:102
 RooCachedPdf.cxx:103
 RooCachedPdf.cxx:104
 RooCachedPdf.cxx:105
 RooCachedPdf.cxx:106
 RooCachedPdf.cxx:107
 RooCachedPdf.cxx:108
 RooCachedPdf.cxx:109
 RooCachedPdf.cxx:110
 RooCachedPdf.cxx:111
 RooCachedPdf.cxx:112
 RooCachedPdf.cxx:113
 RooCachedPdf.cxx:114
 RooCachedPdf.cxx:115
 RooCachedPdf.cxx:116
 RooCachedPdf.cxx:117
 RooCachedPdf.cxx:118
 RooCachedPdf.cxx:119
 RooCachedPdf.cxx:120
 RooCachedPdf.cxx:121
 RooCachedPdf.cxx:122
 RooCachedPdf.cxx:123
 RooCachedPdf.cxx:124
 RooCachedPdf.cxx:125
 RooCachedPdf.cxx:126
 RooCachedPdf.cxx:127
 RooCachedPdf.cxx:128
 RooCachedPdf.cxx:129
 RooCachedPdf.cxx:130
 RooCachedPdf.cxx:131
 RooCachedPdf.cxx:132
 RooCachedPdf.cxx:133
 RooCachedPdf.cxx:134
 RooCachedPdf.cxx:135
 RooCachedPdf.cxx:136
 RooCachedPdf.cxx:137
 RooCachedPdf.cxx:138
 RooCachedPdf.cxx:139
 RooCachedPdf.cxx:140
 RooCachedPdf.cxx:141
 RooCachedPdf.cxx:142
 RooCachedPdf.cxx:143
 RooCachedPdf.cxx:144
 RooCachedPdf.cxx:145
 RooCachedPdf.cxx:146
 RooCachedPdf.cxx:147
 RooCachedPdf.cxx:148
 RooCachedPdf.cxx:149
 RooCachedPdf.cxx:150
 RooCachedPdf.cxx:151
 RooCachedPdf.cxx:152
 RooCachedPdf.cxx:153
 RooCachedPdf.cxx:154
 RooCachedPdf.cxx:155
 RooCachedPdf.cxx:156
 RooCachedPdf.cxx:157
 RooCachedPdf.cxx:158
 RooCachedPdf.cxx:159
 RooCachedPdf.cxx:160