Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/RooAddGenContext.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*****************************************************************************
0002  * Project: RooFit                                                           *
0003  * Package: RooFitCore                                                       *
0004  *    File: $Id: RooAddGenContext.h,v 1.12 2007/05/11 09:11:30 verkerke Exp $
0005  * Authors:                                                                  *
0006  *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
0007  *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
0008  *                                                                           *
0009  * Copyright (c) 2000-2005, Regents of the University of California          *
0010  *                          and Stanford University. All rights reserved.    *
0011  *                                                                           *
0012  * Redistribution and use in source and binary forms,                        *
0013  * with or without modification, are permitted according to the terms        *
0014  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
0015  *****************************************************************************/
0016 #ifndef ROO_ADD_GEN_CONTEXT
0017 #define ROO_ADD_GEN_CONTEXT
0018 
0019 #include "RooAbsGenContext.h"
0020 #include "RooArgSet.h"
0021 #include "RooAddPdf.h"
0022 #include "RooAddModel.h"
0023 #include "RooGenContext.h"
0024 #include "RooMsgService.h"
0025 
0026 #include <memory>
0027 #include <vector>
0028 
0029 class AddCacheElem;
0030 class RooDataSet;
0031 
0032 class RooAddGenContext : public RooAbsGenContext {
0033 public:
0034   RooAddGenContext(const RooAddPdf &model, const RooArgSet &vars, const RooDataSet *prototype=nullptr,
0035                    const RooArgSet* auxProto=nullptr, bool _verbose= false);
0036   RooAddGenContext(const RooAddModel &model, const RooArgSet &vars, const RooDataSet *prototype=nullptr,
0037                    const RooArgSet* auxProto=nullptr, bool _verbose= false);
0038 
0039   void setProtoDataOrder(Int_t* lut) override ;
0040 
0041   void attach(const RooArgSet& params) override ;
0042 
0043   void printMultiline(std::ostream &os, Int_t content, bool verbose=false, TString indent="") const override ;
0044 
0045   template<class Pdf_t>
0046   static std::unique_ptr<RooAbsGenContext> create(const Pdf_t &pdf, const RooArgSet &vars,
0047                                                   const RooDataSet *prototype,
0048                                                   const RooArgSet* auxProto, bool verbose);
0049 
0050 protected:
0051 
0052   void initGenerator(const RooArgSet &theEvent) override;
0053   void generateEvent(RooArgSet &theEvent, Int_t remaining) override;
0054   void updateThresholds() ;
0055 
0056   RooAddGenContext(const RooAddGenContext& other) ;
0057 
0058   std::unique_ptr<RooArgSet> _vars ;
0059   std::unique_ptr<RooArgSet> _pdfSet ;              ///<  Set owned all nodes of internal clone of p.d.f
0060   RooAbsPdf *_pdf ;                 ///<  Pointer to cloned p.d.f
0061   std::vector<std::unique_ptr<RooAbsGenContext>> _gcList ;  ///<  List of component generator contexts
0062   Int_t  _nComp ;                   ///<  Number of PDF components
0063   std::vector<double> _coefThresh ;           ///<[_nComp] Array of coefficient thresholds
0064   bool _isModel ;                 ///< Are we generating from a RooAddPdf or a RooAddModel
0065   AddCacheElem* _pcache = nullptr;   ///<! RooAddPdf cache element
0066 
0067   ClassDefOverride(RooAddGenContext,0) // Specialized context for generating a dataset from a RooAddPdf
0068 };
0069 
0070 
0071 /// Returns a RooAddGenContext if possible, or, if the RooAddGenContext doesn't
0072 /// support this particular RooAddPdf or RooAddModel because it has negative
0073 /// coefficients, returns a generic RooGenContext.
0074 ///
0075 /// Templated function to support both RooAddPdf and RooAddModel without code
0076 /// duplication and without type checking at runtime.
0077 
0078 template<class Pdf_t>
0079 std::unique_ptr<RooAbsGenContext> RooAddGenContext::create(const Pdf_t &pdf, const RooArgSet &vars,
0080                                                            const RooDataSet *prototype,
0081                                                            const RooArgSet* auxProto, bool verbose)
0082 {
0083   // Check if any coefficient is negative. We can use getVal() without the
0084   // normalization set, as normalization doesn't change the coefficients sign.
0085   auto hasNegativeCoefs = [&]() {
0086     for(auto * coef : static_range_cast<RooAbsReal*>(pdf._coefList)) {
0087       if(coef->getVal() < 0) return true;
0088     }
0089     return false;
0090   };
0091 
0092   // The RooAddGenContext doesn't support negative coefficients, so we create a
0093   // generic RooGenContext.
0094   if(hasNegativeCoefs()) {
0095     oocxcoutI(&pdf, Generation) << pdf.ClassName() << "::genContext():"
0096         << " using a generic generator context instead of the RooAddGenContext for the "
0097         << pdf.ClassName() << " \"" << pdf.GetName() <<  "\", because the pdf has negative coefficients." << std::endl;
0098     return std::make_unique<RooGenContext>(pdf, vars, prototype, auxProto, verbose);
0099   }
0100 
0101   return std::make_unique<RooAddGenContext>(pdf, vars, prototype, auxProto,verbose) ;
0102 }
0103 
0104 #endif