File indexing completed on 2025-01-30 10:22:14
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef RooFit_Detail_NormalizationHelpers_h
0014 #define RooFit_Detail_NormalizationHelpers_h
0015
0016 #include <memory>
0017 #include <string>
0018 #include <unordered_map>
0019
0020 class RooAbsArg;
0021 class RooArgSet;
0022
0023 class TNamed;
0024
0025 namespace RooFit {
0026
0027 namespace Detail {
0028
0029 class CompileContext {
0030 public:
0031 CompileContext(RooArgSet const &topLevelNormSet);
0032
0033 ~CompileContext();
0034
0035 template <class T>
0036 T *compile(T &arg, RooAbsArg &owner, RooArgSet const &normSet)
0037 {
0038 return static_cast<T *>(compileImpl(arg, owner, normSet));
0039 }
0040
0041 void compileServers(RooAbsArg &arg, RooArgSet const &normSet);
0042 void compileServer(RooAbsArg &server, RooAbsArg &arg, RooArgSet const &normSet);
0043
0044 void markAsCompiled(RooAbsArg &arg) const;
0045
0046
0047 void setLikelihoodMode(bool flag) { _likelihoodMode = flag; }
0048 bool likelihoodMode() const { return _likelihoodMode; }
0049 void setBinnedLikelihoodMode(bool flag) { _binnedLikelihoodMode = flag; }
0050 bool binnedLikelihoodMode() const { return _binnedLikelihoodMode; }
0051 void setBinWidthFuncFlag(bool flag) { _binWidthFuncFlag = flag; }
0052 bool binWidthFuncFlag() const { return _binWidthFuncFlag; }
0053
0054 private:
0055 RooAbsArg *compileImpl(RooAbsArg &arg, RooAbsArg &owner, RooArgSet const &normSet);
0056 void add(RooAbsArg &arg);
0057 RooAbsArg *find(RooAbsArg &arg) const;
0058 bool isMarkedAsCompiled(RooAbsArg const &arg) const;
0059
0060 RooArgSet const &_topLevelNormSet;
0061 std::unordered_map<TNamed const *, RooAbsArg *> _clonedArgsSet;
0062 std::unordered_map<RooAbsArg *, RooAbsArg *> _replacements;
0063
0064 bool _likelihoodMode = false;
0065 bool _binnedLikelihoodMode = false;
0066 bool _binWidthFuncFlag = false;
0067 };
0068
0069 template <class T>
0070 std::unique_ptr<T> compileForNormSet(T const &arg, RooArgSet const &normSet)
0071 {
0072 RooFit::Detail::CompileContext ctx{normSet};
0073 std::unique_ptr<RooAbsArg> head = arg.compileForNormSet(normSet, ctx);
0074 return std::unique_ptr<T>{static_cast<T *>(head.release())};
0075 }
0076
0077 }
0078
0079 }
0080
0081 #endif