00001 /***************************************************************************** 00002 * Project: RooFit * 00003 * * 00004 * Copyright (c) 2000-2005, Regents of the University of California * 00005 * and Stanford University. All rights reserved. * 00006 * * 00007 * Redistribution and use in source and binary forms, * 00008 * with or without modification, are permitted according to the terms * 00009 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) * 00010 *****************************************************************************/ 00011 00012 ////////////////////////////////////////////////////////////////////////////// 00013 // 00014 // BEGIN_HTML 00015 // RooCachedPdf is an implementation of RooAbsCachedPdf that can cache 00016 // any external RooAbsPdf input function provided in the constructor. 00017 // END_HTML 00018 // 00019 00020 #include "Riostream.h" 00021 00022 #include "RooAbsPdf.h" 00023 #include "RooCachedPdf.h" 00024 #include "RooAbsReal.h" 00025 #include "RooMsgService.h" 00026 #include "RooDataHist.h" 00027 #include "RooHistPdf.h" 00028 00029 ClassImp(RooCachedPdf) 00030 ; 00031 00032 00033 00034 //_____________________________________________________________________________ 00035 RooCachedPdf::RooCachedPdf(const char *name, const char *title, RooAbsPdf& _pdf) : 00036 RooAbsCachedPdf(name,title), 00037 pdf("pdf","pdf",this,_pdf), 00038 _cacheObs("cacheObs","cacheObs",this,kFALSE,kFALSE) 00039 { 00040 // Constructor taking name, title and function to be cached. To control 00041 // granularity of the binning of the cache histogram set the desired properties 00042 // in the binning named "cache" in the observables of the function. The dimensions 00043 // of the cache are automatically matched to the number of observables used 00044 // in each use context. Multiple cache in different observable may exists 00045 // simultanously if the cached p.d.f is used with multiple observable 00046 // configurations simultaneously 00047 } 00048 00049 00050 00051 //_____________________________________________________________________________ 00052 RooCachedPdf::RooCachedPdf(const char *name, const char *title, RooAbsPdf& _pdf, const RooArgSet& cacheObs) : 00053 RooAbsCachedPdf(name,title), 00054 pdf("pdf","pdf",this,_pdf), 00055 _cacheObs("cacheObs","cacheObs",this,kFALSE,kFALSE) 00056 { 00057 // Constructor taking name, title and function to be cached and 00058 // fixed choice of variable to cache. To control granularity of the 00059 // binning of the cache histogram set the desired properties in the 00060 // binning named "cache" in the observables of the function. 00061 // If the fixed set of cache observables does not match the observables 00062 // defined in the use context of the p.d.f the cache is still filled 00063 // completely. Ee.g. when it is specified to cache x and p and only x 00064 // is a observable in the given use context the cache histogram will 00065 // store sampled values for all values of observable x and parameter p. 00066 // In such a mode of operation the cache will also not be recalculated 00067 // if the observable p changes 00068 00069 _cacheObs.add(cacheObs) ; 00070 } 00071 00072 00073 00074 //_____________________________________________________________________________ 00075 RooCachedPdf::RooCachedPdf(const RooCachedPdf& other, const char* name) : 00076 RooAbsCachedPdf(other,name), 00077 pdf("pdf",this,other.pdf), 00078 _cacheObs("cacheObs",this,other._cacheObs) 00079 { 00080 // Copy constructor 00081 } 00082 00083 00084 00085 //_____________________________________________________________________________ 00086 RooCachedPdf::~RooCachedPdf() 00087 { 00088 // Destructor 00089 } 00090 00091 00092 00093 //_____________________________________________________________________________ 00094 void RooCachedPdf::fillCacheObject(RooAbsCachedPdf::PdfCacheElem& cache) const 00095 { 00096 // Update contents of cache histogram by resampling the input p.d.f. Note that 00097 // the cache is filled with normalized p.d.f values so that the RooHistPdf 00098 // that represents the cache contents can be explicitly declared as self normalized 00099 // eliminating the need for superfluous numeric calculations of unit normalization.s 00100 00101 00102 if (cache.hist()->get()->getSize()>1) { 00103 coutP(Eval) << "RooCachedPdf::fillCacheObject(" << GetName() << ") filling multi-dimensional cache" ; 00104 } 00105 00106 // Update contents of histogram 00107 ((RooAbsPdf&)pdf.arg()).fillDataHist(cache.hist(),&cache.nset(),1.0,kFALSE,kTRUE) ; 00108 00109 if (cache.hist()->get()->getSize()>1) { 00110 ccoutP(Eval) << endl ; 00111 } 00112 00113 cache.pdf()->setUnitNorm(kTRUE) ; 00114 } 00115 00116 00117 00118 //_____________________________________________________________________________ 00119 void RooCachedPdf::preferredObservableScanOrder(const RooArgSet& obs, RooArgSet& orderedObs) const 00120 { 00121 // Defer preferred scan order to cached pdf prefernece 00122 pdf.arg().preferredObservableScanOrder(obs,orderedObs) ; 00123 } 00124 00125 00126 00127 //_____________________________________________________________________________ 00128 RooArgSet* RooCachedPdf::actualObservables(const RooArgSet& nset) const 00129 { 00130 // If this pdf is operated with a fixed set of observables, return 00131 // the subset of the fixed observables that are actual dependents 00132 // of the external input p.d.f. If this p.d.f is operated without 00133 // a fixed set of cache observables, return the actual observables 00134 // of the external input p.d.f given the choice of observables defined 00135 // in nset 00136 00137 if (_cacheObs.getSize()>0) { 00138 return pdf.arg().getObservables(_cacheObs) ; 00139 } 00140 00141 return pdf.arg().getObservables(nset) ; 00142 } 00143 00144 00145 00146 //_____________________________________________________________________________ 00147 RooArgSet* RooCachedPdf::actualParameters(const RooArgSet& nset) const 00148 { 00149 // If this p.d.f is operated with a fixed set of observables, return 00150 // all variables of the external input p.d.f that are not one of 00151 // the cache observables. If this p.d.f is operated in automatic mode, 00152 // return the parameters of the external input p.d.f 00153 00154 if (_cacheObs.getSize()>0) { 00155 return pdf.arg().getParameters(_cacheObs) ; 00156 } 00157 return pdf.arg().getParameters(nset) ; 00158 } 00159 00160