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
// RooCachedReal is an implementation of RooAbsCachedReal that can cache
// any external RooAbsReal input function provided in the constructor. 
// END_HTML
//

#include "Riostream.h" 

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

ClassImp(RooCachedReal) 
  ;


//_____________________________________________________________________________
RooCachedReal::RooCachedReal(const char *name, const char *title, RooAbsReal& _func) :
   RooAbsCachedReal(name,title), 
   func("func","func",this,_func),
   _useCdfBoundaries(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
   
   // Choose same expensive object cache as input function
   setExpensiveObjectCache(_func.expensiveObjectCache()) ;
 } 




//_____________________________________________________________________________
RooCachedReal::RooCachedReal(const char *name, const char *title, RooAbsReal& _func, const RooArgSet& cacheObs) :
   RooAbsCachedReal(name,title), 
   func("func","func",this,_func),
   _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) ;

   // Choose same expensive object cache as input function
   setExpensiveObjectCache(_func.expensiveObjectCache()) ;
 } 




//_____________________________________________________________________________
RooCachedReal::RooCachedReal(const RooCachedReal& other, const char* name) :  
   RooAbsCachedReal(other,name), 
   func("func",this,other.func),
   _cacheObs("cacheObs",this,other._cacheObs),
   _useCdfBoundaries(other._useCdfBoundaries)
 { 
   // Copy constructor
 } 



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



//_____________________________________________________________________________
void RooCachedReal::fillCacheObject(RooAbsCachedReal::FuncCacheElem& cache) const 
{
  // Update contents of cache histogram by resampling the input function

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

  func.arg().fillDataHist(cache.hist(),0,1.0,kFALSE,kTRUE) ;
  cache.func()->setCdfBoundaries(_useCdfBoundaries) ;

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

}



//_____________________________________________________________________________
RooArgSet* RooCachedReal::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 func.arg().getObservables(_cacheObs) ;
  } 

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



//_____________________________________________________________________________
RooArgSet* RooCachedReal::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 func.arg().getParameters(_cacheObs) ;
  } 
  return func.arg().getParameters(nset) ; 
}





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