CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_8_patch3/src/HiggsAnalysis/CombinedLimit/interface/ToyMCSamplerOpt.h

Go to the documentation of this file.
00001 #ifndef ROOT_ToyMCSamplerOpt_h
00002 #define ROOT_ToyMCSamplerOpt_h
00003 
00004 #include <RooStats/ToyMCSampler.h>
00005 struct RooProdPdf;
00006 struct RooPoisson;
00007 
00008 namespace toymcoptutils {
00009     class SinglePdfGenInfo {
00010         public:
00011             enum Mode { Binned, BinnedNoWorkaround, Poisson, Unbinned, Counting };
00012             SinglePdfGenInfo(RooAbsPdf &pdf, const RooArgSet& observables, bool preferBinned, const RooDataSet* protoData = NULL, int forceEvents = 0) ;
00013             ~SinglePdfGenInfo() ;
00014             RooAbsData *generate(const RooDataSet* protoData = NULL, int forceEvents = 0) ;
00015             RooDataSet *generateAsimov(RooRealVar *&weightVar) ;
00016             RooDataSet *generatePseudoAsimov(RooRealVar *&weightVar, int nPoints) ;
00017             const RooAbsPdf * pdf() const { return pdf_; }
00018             void setCacheTemplates(bool cache) { keepHistoSpec_ = cache; }
00019         private:
00020             Mode mode_;
00021             RooAbsPdf *pdf_; 
00022             RooArgSet observables_;
00023             RooAbsPdf::GenSpec *spec_;
00024             TH1        *histoSpec_;
00025             bool        keepHistoSpec_;
00026             RooRealVar *weightVar_;
00027             RooDataSet *generateWithHisto(RooRealVar *&weightVar, bool asimov) ;
00028             RooDataSet *generateCountingAsimov() ;
00029             void setToExpected(RooProdPdf &prod, RooArgSet &obs) ;
00030             void setToExpected(RooPoisson &pois, RooArgSet &obs) ;
00031     };
00032     class SimPdfGenInfo {
00033         public:
00034             SimPdfGenInfo(RooAbsPdf &pdf, const RooArgSet& observables, bool preferBinned, const RooDataSet* protoData = NULL, int forceEvents = 0) ;
00035             ~SimPdfGenInfo() ;
00036             RooAbsData *generate(RooRealVar *&weightVar, const RooDataSet* protoData = NULL, int forceEvents = 0) ;
00037             RooAbsData *generateAsimov(RooRealVar *&weightVar) ;
00038             void setCopyData(bool copyData) { copyData_ = copyData; }
00039             void setCacheTemplates(bool cache) ;
00040         private:
00041             RooAbsPdf                       *pdf_; 
00042             RooAbsCategoryLValue            *cat_;
00043             RooArgSet                        observables_;
00044             std::vector<SinglePdfGenInfo *>  pdfs_; 
00045             RooArgSet                        ownedCrap_;
00046             std::map<std::string,RooAbsData*> datasetPieces_;
00047             bool                              copyData_;
00048             //std::map<std::string,RooDataSet*> datasetPieces_;
00049 
00050     }; 
00051 }
00052 
00053 class ToyMCSamplerOpt : public RooStats::ToyMCSampler{
00054     public:
00055         ToyMCSamplerOpt(RooStats::TestStatistic& ts, Int_t ntoys, RooAbsPdf *globalObsPdf = 0, bool generateNuisances = false) ;
00056         ToyMCSamplerOpt(const RooStats::ToyMCSampler &base) ;
00057         ToyMCSamplerOpt(const ToyMCSamplerOpt &other) ;
00058         ~ToyMCSamplerOpt() ;
00059         virtual void SetPdf(RooAbsPdf& pdf) ;
00060         void setGlobalObsPdf(RooAbsPdf *pdf) { globalObsPdf_ = pdf; }
00061         virtual RooAbsData* GenerateToyData(RooArgSet& /*nullPOI*/, double& weight) const ;
00062     private:
00063         RooAbsData* Generate(RooAbsPdf& pdf, RooArgSet& observables, const RooDataSet* protoData = NULL, int forceEvents = 0) const ;
00064         RooAbsPdf *globalObsPdf_;
00065         mutable RooDataSet *globalObsValues_; 
00066         mutable int globalObsIndex_;
00067 
00068         // We can't use the NuisanceParameterSampler because, even if public, there's no interface file for it
00069         mutable RooDataSet *nuisValues_; 
00070         mutable int nuisIndex_;
00071 
00072         mutable RooRealVar *weightVar_;
00073         mutable std::map<RooAbsPdf *, toymcoptutils::SimPdfGenInfo *> genCache_;
00074         
00075 };
00076 
00077 #endif