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 // RooAbsSelfCachedReal is an abstract base class for functions whose 00016 // output is cached in terms of a histogram in all observables between 00017 // getVal() and evaluate(). For certain p.d.f.s that are very 00018 // expensive to calculate it may be beneficial to implement them as a 00019 // RooAbsSelfCachedReal rather than a RooAbsReal. Class 00020 // RooAbsSelfCachedReal is designed to have its interface identical to 00021 // that of RooAbsReal, so any p.d.f can make use of its caching 00022 // functionality by merely switching its base class. Existing 00023 // RooAbsReal objects can also be cached a posteriori with the 00024 // RooCachedReal wrapper function that takes any RooAbsReal object as 00025 // input. 00026 // END_HTML 00027 // 00028 // 00029 00030 #include "Riostream.h" 00031 00032 #include "RooFit.h" 00033 #include "RooAbsSelfCachedReal.h" 00034 #include "RooAbsReal.h" 00035 #include "RooMsgService.h" 00036 #include "RooDataHist.h" 00037 #include "RooHistPdf.h" 00038 00039 using namespace std ; 00040 00041 ClassImp(RooAbsSelfCachedReal) 00042 00043 00044 00045 //_____________________________________________________________________________ 00046 RooAbsSelfCachedReal::RooAbsSelfCachedReal(const char *name, const char *title, Int_t ipOrder) : 00047 RooAbsCachedReal(name,title,ipOrder) 00048 { 00049 // Constructor 00050 } 00051 00052 00053 00054 //_____________________________________________________________________________ 00055 RooAbsSelfCachedReal::RooAbsSelfCachedReal(const RooAbsSelfCachedReal& other, const char* name) : 00056 RooAbsCachedReal(other,name) 00057 { 00058 // Copy constructor 00059 } 00060 00061 00062 00063 //_____________________________________________________________________________ 00064 RooAbsSelfCachedReal::~RooAbsSelfCachedReal() 00065 { 00066 // Destructor 00067 } 00068 00069 00070 00071 //_____________________________________________________________________________ 00072 void RooAbsSelfCachedReal::fillCacheObject(RooAbsCachedReal::FuncCacheElem& cache) const 00073 { 00074 // Fill cache with sampling of function as defined by the evaluate() implementation 00075 00076 RooDataHist& cacheHist = *cache.hist() ; 00077 00078 // Make deep clone of self in non-caching mde and attach to dataset observables 00079 RooArgSet* cloneSet = (RooArgSet*) RooArgSet(*this).snapshot(kTRUE) ; 00080 RooAbsSelfCachedReal* clone2 = (RooAbsSelfCachedReal*) cloneSet->find(GetName()) ; 00081 clone2->disableCache(kTRUE) ; 00082 clone2->attachDataSet(cacheHist) ; 00083 00084 // Iterator over all bins of RooDataHist and fill weights 00085 for (Int_t i=0 ; i<cacheHist.numEntries() ; i++) { 00086 const RooArgSet* obs = cacheHist.get(i) ; 00087 Double_t wgt = clone2->getVal(obs) ; 00088 cacheHist.set(wgt) ; 00089 } 00090 00091 delete cloneSet ; 00092 } 00093 00094 00095 00096 //_____________________________________________________________________________ 00097 RooArgSet* RooAbsSelfCachedReal::actualObservables(const RooArgSet& nset) const 00098 { 00099 // Defines observables to be cached, given a set of user defined observables 00100 // Returns the subset of nset that are observables this p.d.f 00101 00102 // Make list of servers 00103 RooArgSet servers ; 00104 00105 TIterator* siter = serverIterator() ; 00106 siter->Reset() ; 00107 RooAbsArg* server ; 00108 while((server=(RooAbsArg*)siter->Next())) { 00109 servers.add(*server) ; 00110 } 00111 00112 // Return servers that are in common with given normalization set 00113 return (RooArgSet*) servers.selectCommon(nset) ; 00114 00115 } 00116 00117 00118 //_____________________________________________________________________________ 00119 RooArgSet* RooAbsSelfCachedReal::actualParameters(const RooArgSet& nset) const 00120 { 00121 // Defines parameters on which cache contents depends. Returns 00122 // subset of variables of self that is not contained in the 00123 // supplied nset 00124 00125 // Make list of servers 00126 RooArgSet *servers = new RooArgSet ; 00127 00128 TIterator* siter = serverIterator() ; 00129 siter->Reset() ; 00130 RooAbsArg* server ; 00131 while((server=(RooAbsArg*)siter->Next())) { 00132 servers->add(*server) ; 00133 } 00134 00135 // Remove all given observables from server list 00136 servers->remove(nset,kTRUE,kTRUE) ; 00137 00138 return servers ; 00139 } 00140 00141 00142 00143 00144 00145 00146