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 // RooAbsSelfCachedPdf is an abstract base class for probability 00016 // density functions whose output is cached in terms of a histogram in 00017 // all observables between getVal() and evaluate(). For certain 00018 // p.d.f.s that are very expensive to calculate it may be beneficial 00019 // to implement them as a RooAbsSelfCachedPdf rather than a 00020 // RooAbsPdf. Class RooAbsSelfCachedPdf is designed to have its 00021 // interface identical to that of RooAbsPdf, so any p.d.f can make use 00022 // of its caching functionality by merely switching its base class. 00023 // Existing RooAbsPdf objects can also be cached a posteriori with the 00024 // RooCachedPdf wrapper p.d.f. that takes any RooAbsPdf object as 00025 // input. 00026 // END_HTML 00027 // 00028 // 00029 00030 #include "Riostream.h" 00031 00032 #include "RooFit.h" 00033 #include "RooAbsSelfCachedPdf.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(RooAbsSelfCachedPdf) 00042 00043 00044 00045 //_____________________________________________________________________________ 00046 RooAbsSelfCachedPdf::RooAbsSelfCachedPdf(const char *name, const char *title, Int_t ipOrder) : 00047 RooAbsCachedPdf(name,title,ipOrder) 00048 { 00049 // Constructor 00050 } 00051 00052 00053 00054 //_____________________________________________________________________________ 00055 RooAbsSelfCachedPdf::RooAbsSelfCachedPdf(const RooAbsSelfCachedPdf& other, const char* name) : 00056 RooAbsCachedPdf(other,name) 00057 { 00058 // Copy constructor 00059 } 00060 00061 00062 00063 //_____________________________________________________________________________ 00064 RooAbsSelfCachedPdf::~RooAbsSelfCachedPdf() 00065 { 00066 // Destructor 00067 } 00068 00069 00070 00071 //_____________________________________________________________________________ 00072 void RooAbsSelfCachedPdf::fillCacheObject(RooAbsCachedPdf::PdfCacheElem& cache) const 00073 { 00074 // Fill cache with sampling of p.d.f 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 RooAbsSelfCachedPdf* clone2 = (RooAbsSelfCachedPdf*) 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 cache.pdf()->setUnitNorm(kTRUE) ; 00092 00093 delete cloneSet ; 00094 } 00095 00096 00097 00098 //_____________________________________________________________________________ 00099 RooArgSet* RooAbsSelfCachedPdf::actualObservables(const RooArgSet& /*nset*/) const 00100 { 00101 // Defines observables to be cached, given a set of user defined observables 00102 // Returns the subset of nset that are observables this p.d.f 00103 00104 // Make list of servers 00105 RooArgSet servers ; 00106 00107 TIterator* siter = serverIterator() ; 00108 siter->Reset() ; 00109 RooAbsArg* server ; 00110 while((server=(RooAbsArg*)siter->Next())) { 00111 servers.add(*server) ; 00112 } 00113 00114 // Return servers that are in common with given normalization set 00115 return new RooArgSet(servers) ; 00116 //return (RooArgSet*) servers.selectCommon(nset) ; 00117 00118 } 00119 00120 00121 00122 //_____________________________________________________________________________ 00123 RooArgSet* RooAbsSelfCachedPdf::actualParameters(const RooArgSet& nset) const 00124 { 00125 // Defines parameters on which cache contents depends. Returns 00126 // subset of variables of self that is not contained in the 00127 // supplied nset 00128 00129 RooArgSet *servers = new RooArgSet ; 00130 00131 TIterator* siter = serverIterator() ; 00132 siter->Reset() ; 00133 RooAbsArg* server ; 00134 while((server=(RooAbsArg*)siter->Next())) { 00135 servers->add(*server) ; 00136 } 00137 00138 // Remove all given observables from server list 00139 servers->remove(nset,kTRUE,kTRUE) ; 00140 00141 return servers ; 00142 } 00143 00144 00145 00146 00147 00148 00149