Warning, file /include/root/RooAbsArg.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef ROO_ABS_ARG
0017 #define ROO_ABS_ARG
0018
0019 #include <RooAbsCache.h>
0020 #include <RooFit/Config.h>
0021 #include <RooFit/Detail/NormalizationHelpers.h>
0022 #include <RooLinkedListIter.h>
0023 #include <RooNameReg.h>
0024 #include <RooPrintable.h>
0025 #include <RooSTLRefCountList.h>
0026 #include <RooStringView.h>
0027
0028 #include <TNamed.h>
0029 #include <TObjArray.h>
0030 #include <TRefArray.h>
0031
0032 #include <iostream>
0033 #include <limits>
0034 #include <map>
0035 #include <memory>
0036 #include <set>
0037 #include <string>
0038 #include <unordered_map>
0039
0040 class TTree;
0041 class RooArgSet;
0042 class RooAbsCollection;
0043 class RooVectorDataStore;
0044 class RooAbsData;
0045 class RooAbsDataStore;
0046 class RooAbsProxy;
0047 class RooArgProxy;
0048 template <class RooCollection_t>
0049 class RooCollectionProxy;
0050 using RooSetProxy = RooCollectionProxy<RooArgSet>;
0051 using RooListProxy = RooCollectionProxy<RooArgList>;
0052 class RooExpensiveObjectCache;
0053 class RooWorkspace;
0054 namespace RooFit {
0055 namespace Experimental {
0056 class CodegenContext;
0057 }
0058 }
0059
0060 class RooRefArray : public TObjArray {
0061 public:
0062 RooRefArray() = default;
0063 RooRefArray(const RooRefArray &other) : TObjArray(other) {}
0064 RooRefArray &operator=(const RooRefArray &other) = default;
0065
0066 protected:
0067 ClassDefOverride(RooRefArray, 1)
0068 };
0069
0070 class RooAbsArg;
0071
0072 namespace cling {
0073 std::string printValue(RooAbsArg *);
0074 }
0075
0076 class RooAbsArg : public TNamed, public RooPrintable {
0077 public:
0078 using RefCountList_t = RooSTLRefCountList<RooAbsArg>;
0079 using RefCountListLegacyIterator_t = TIteratorToSTLInterface<RefCountList_t::Container_t>;
0080
0081
0082 RooAbsArg();
0083 ~RooAbsArg() override;
0084 RooAbsArg(const char *name, const char *title);
0085 RooAbsArg(const RooAbsArg &other, const char *name = nullptr);
0086 RooAbsArg &operator=(const RooAbsArg &other) = delete;
0087 virtual TObject *clone(const char *newname = nullptr) const = 0;
0088 TObject *Clone(const char *newname = nullptr) const override
0089 {
0090 return clone(newname && newname[0] != '\0' ? newname : nullptr);
0091 }
0092 virtual RooAbsArg *cloneTree(const char *newname = nullptr) const;
0093
0094
0095
0096
0097 virtual bool isDerived() const { return true; }
0098
0099
0100
0101
0102
0103
0104 bool dependsOnValue(const RooAbsCollection &serverList, const RooAbsArg *ignoreArg = nullptr) const
0105 {
0106 return dependsOn(serverList, ignoreArg, true);
0107 }
0108
0109
0110
0111
0112
0113 bool dependsOnValue(const RooAbsArg &server, const RooAbsArg *ignoreArg = nullptr) const
0114 {
0115 return dependsOn(server, ignoreArg, true);
0116 }
0117 bool
0118 dependsOn(const RooAbsCollection &serverList, const RooAbsArg *ignoreArg = nullptr, bool valueOnly = false) const;
0119
0120
0121
0122 inline bool dependsOn(const RooAbsArg &server, const RooAbsArg *ignoreArg = nullptr, bool valueOnly = false) const
0123 {
0124 return dependsOn(server.namePtr(), ignoreArg, valueOnly);
0125 }
0126 bool dependsOn(TNamed const *namePtr, const RooAbsArg *ignoreArg = nullptr, bool valueOnly = false) const;
0127 bool overlaps(const RooAbsArg &testArg, bool valueOnly = false) const;
0128 bool hasClients() const { return !_clientList.empty(); }
0129
0130
0131
0132
0133
0134
0135
0136
0137 const RefCountList_t &clients() const { return _clientList; }
0138
0139 const RefCountList_t &valueClients() const { return _clientListValue; }
0140
0141
0142 const RefCountList_t &shapeClients() const { return _clientListShape; }
0143
0144
0145 const RefCountList_t &servers() const { return _serverList; }
0146
0147 inline RooAbsArg *findServer(const char *name) const
0148 {
0149 const auto serverIt = _serverList.findByName(name);
0150 return serverIt != _serverList.end() ? *serverIt : nullptr;
0151 }
0152
0153 inline RooAbsArg *findServer(const RooAbsArg &arg) const { return _serverList.findByNamePointer(&arg); }
0154
0155 inline RooAbsArg *findServer(Int_t index) const { return _serverList.containedObjects()[index]; }
0156
0157 inline bool isValueServer(const RooAbsArg &arg) const { return _clientListValue.containsByNamePtr(&arg); }
0158
0159 inline bool isValueServer(const char *name) const { return _clientListValue.containsSameName(name); }
0160
0161 inline bool isShapeServer(const RooAbsArg &arg) const { return _clientListShape.containsByNamePtr(&arg); }
0162
0163 inline bool isShapeServer(const char *name) const { return _clientListShape.containsSameName(name); }
0164 void
0165 leafNodeServerList(RooAbsCollection *list, const RooAbsArg *arg = nullptr, bool recurseNonDerived = false) const;
0166 void
0167 branchNodeServerList(RooAbsCollection *list, const RooAbsArg *arg = nullptr, bool recurseNonDerived = false) const;
0168 void treeNodeServerList(RooAbsCollection *list, const RooAbsArg *arg = nullptr, bool doBranch = true,
0169 bool doLeaf = true, bool valueOnly = false, bool recurseNonDerived = false) const;
0170
0171
0172
0173
0174
0175 inline virtual bool isFundamental() const { return false; }
0176
0177
0178
0179
0180 virtual RooFit::OwningPtr<RooAbsArg> createFundamental(const char *newname = nullptr) const = 0;
0181
0182
0183
0184
0185 inline virtual bool isLValue() const { return false; }
0186
0187
0188 bool redirectServers(const RooAbsCollection &newServerList, bool mustReplaceAll = false, bool nameChange = false,
0189 bool isRecursionStep = false);
0190 bool redirectServers(std::unordered_map<RooAbsArg *, RooAbsArg *> const &replacements);
0191 bool recursiveRedirectServers(const RooAbsCollection &newSet, bool mustReplaceAll = false,
0192 bool nameChange = false, bool recurseInNewSet = true);
0193
0194 virtual bool redirectServersHook(const RooAbsCollection &newServerList, bool mustReplaceAll, bool nameChange,
0195 bool isRecursiveStep);
0196
0197 virtual void serverNameChangeHook(const RooAbsArg * , const RooAbsArg * ) {};
0198
0199 void addServer(RooAbsArg &server, bool valueProp = true, bool shapeProp = false, std::size_t refCount = 1);
0200 void addServerList(RooAbsCollection &serverList, bool valueProp = true, bool shapeProp = false);
0201 void R__SUGGEST_ALTERNATIVE("This interface is unsafe! Use RooAbsArg::redirectServers()")
0202 replaceServer(RooAbsArg &oldServer, RooAbsArg &newServer, bool valueProp, bool shapeProp);
0203 void changeServer(RooAbsArg &server, bool valueProp, bool shapeProp);
0204 void removeServer(RooAbsArg &server, bool force = false);
0205 RooAbsArg *findNewServer(const RooAbsCollection &newSet, bool nameChange) const;
0206
0207
0208
0209
0210
0211 RooFit::OwningPtr<RooArgSet> getVariables(bool stripDisconnected = true) const;
0212 RooFit::OwningPtr<RooArgSet> getParameters(const RooAbsData *data, bool stripDisconnected = true) const;
0213 RooFit::OwningPtr<RooArgSet> getParameters(const RooAbsData &data, bool stripDisconnected = true) const;
0214 RooFit::OwningPtr<RooArgSet> getParameters(const RooArgSet &observables, bool stripDisconnected = true) const;
0215 RooFit::OwningPtr<RooArgSet> getParameters(const RooArgSet *observables, bool stripDisconnected = true) const;
0216 virtual bool getParameters(const RooArgSet *observables, RooArgSet &outputSet, bool stripDisconnected = true) const;
0217 RooFit::OwningPtr<RooArgSet> getObservables(const RooArgSet &set, bool valueOnly = true) const;
0218 RooFit::OwningPtr<RooArgSet> getObservables(const RooAbsData *data) const;
0219 RooFit::OwningPtr<RooArgSet> getObservables(const RooAbsData &data) const;
0220 RooFit::OwningPtr<RooArgSet> getObservables(const RooArgSet *depList, bool valueOnly = true) const;
0221 bool getObservables(const RooAbsCollection *depList, RooArgSet &outputSet, bool valueOnly = true) const;
0222 bool observableOverlaps(const RooAbsData *dset, const RooAbsArg &testArg) const;
0223 bool observableOverlaps(const RooArgSet *depList, const RooAbsArg &testArg) const;
0224 virtual bool checkObservables(const RooArgSet *nset) const;
0225 bool recursiveCheckObservables(const RooArgSet *nset) const;
0226 RooFit::OwningPtr<RooArgSet> getComponents() const;
0227
0228 void attachArgs(const RooAbsCollection &set);
0229 void attachDataSet(const RooAbsData &set);
0230 void attachDataStore(const RooAbsDataStore &set);
0231
0232
0233 virtual bool readFromStream(std::istream &is, bool compact, bool verbose = false) = 0;
0234 virtual void writeToStream(std::ostream &os, bool compact) const = 0;
0235
0236
0237
0238 void Print(Option_t *options = nullptr) const override
0239 {
0240
0241 printStream(defaultPrintStream(), defaultPrintContents(options), defaultPrintStyle(options));
0242 }
0243
0244 void printName(std::ostream &os) const override;
0245 void printTitle(std::ostream &os) const override;
0246 void printClassName(std::ostream &os) const override;
0247 void printAddress(std::ostream &os) const override;
0248 void printArgs(std::ostream &os) const override;
0249 virtual void printMetaArgs(std::ostream & ) const {};
0250 void printMultiline(std::ostream &os, Int_t contents, bool verbose = false, TString indent = "") const override;
0251 void printTree(std::ostream &os, TString indent = "") const override;
0252
0253 Int_t defaultPrintContents(Option_t *opt) const override;
0254
0255
0256 void setAttribute(const Text_t *name, bool value = true);
0257 bool getAttribute(const Text_t *name) const;
0258 inline const std::set<std::string> &attributes() const
0259 {
0260
0261 return _boolAttrib;
0262 }
0263
0264 void setStringAttribute(const Text_t *key, const Text_t *value);
0265 void removeStringAttribute(const Text_t *key);
0266 const Text_t *getStringAttribute(const Text_t *key) const;
0267 inline const std::map<std::string, std::string> &stringAttributes() const
0268 {
0269
0270 return _stringAttrib;
0271 }
0272
0273
0274 void setTransientAttribute(const Text_t *name, bool value = true);
0275 bool getTransientAttribute(const Text_t *name) const;
0276 inline const std::set<std::string> &transientAttributes() const
0277 {
0278
0279 return _boolAttribTransient;
0280 }
0281
0282
0283 inline bool isConstant() const
0284 {
0285 return _isConstant;
0286 }
0287
0288
0289 Int_t Compare(const TObject *other) const override;
0290 bool IsSortable() const override
0291 {
0292
0293 return true;
0294 }
0295
0296 virtual bool operator==(const RooAbsArg &other) const = 0;
0297 virtual bool isIdentical(const RooAbsArg &other, bool assumeSameType = false) const = 0;
0298
0299
0300 virtual bool inRange(const char *) const
0301 {
0302
0303 return true;
0304 }
0305 virtual bool hasRange(const char *) const
0306 {
0307
0308 return false;
0309 }
0310
0311 enum ConstOpCode {
0312 Activate = 0,
0313 DeActivate = 1,
0314 ConfigChange = 2,
0315 ValueChange = 3
0316 };
0317 enum CacheMode {
0318 Always = 0,
0319 NotAdvised = 1,
0320 Never = 2
0321 };
0322 enum OperMode {
0323 Auto = 0,
0324 AClean = 1,
0325 ADirty = 2
0326 };
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336 virtual void optimizeCacheMode(const RooArgSet &observables);
0337 virtual void optimizeCacheMode(const RooArgSet &observables, RooArgSet &optNodes, RooLinkedList &processedNodes);
0338
0339
0340 bool findConstantNodes(const RooArgSet &observables, RooArgSet &cacheList);
0341 bool findConstantNodes(const RooArgSet &observables, RooArgSet &cacheList, RooLinkedList &processedNodes);
0342
0343
0344 virtual void constOptimizeTestStatistic(ConstOpCode opcode, bool doAlsoTrackingOpt = true);
0345
0346 virtual CacheMode canNodeBeCached() const { return Always; }
0347 virtual void setCacheAndTrackHints(RooArgSet & ) {};
0348
0349
0350 inline bool isShapeDirty() const
0351 {
0352
0353 return isDerived() ? _shapeDirty : false;
0354 }
0355
0356 inline bool isValueDirty() const
0357 {
0358
0359 if (inhibitDirty())
0360 return true;
0361 switch (_operMode) {
0362 case AClean: return false;
0363 case ADirty: return true;
0364 case Auto:
0365 if (_valueDirty)
0366 return isDerived();
0367 return false;
0368 }
0369 return true;
0370 }
0371
0372 inline bool isValueDirtyAndClear() const
0373 {
0374
0375 if (inhibitDirty())
0376 return true;
0377 switch (_operMode) {
0378 case AClean: return false;
0379 case ADirty: return true;
0380 case Auto:
0381 if (_valueDirty) {
0382 _valueDirty = false;
0383 return isDerived();
0384 }
0385 return false;
0386 }
0387 return true;
0388 }
0389
0390 inline bool isValueOrShapeDirtyAndClear() const
0391 {
0392
0393
0394 if (inhibitDirty())
0395 return true;
0396 switch (_operMode) {
0397 case AClean: return false;
0398 case ADirty: return true;
0399 case Auto:
0400 if (_valueDirty || _shapeDirty) {
0401 _shapeDirty = false;
0402 _valueDirty = false;
0403 return isDerived();
0404 }
0405 _shapeDirty = false;
0406 _valueDirty = false;
0407 return false;
0408 }
0409 return true;
0410 }
0411
0412
0413 void registerCache(RooAbsCache &cache);
0414 void unRegisterCache(RooAbsCache &cache);
0415 Int_t numCaches() const;
0416 RooAbsCache *getCache(Int_t index) const;
0417
0418
0419 inline OperMode operMode() const { return _operMode; }
0420
0421 void setOperMode(OperMode mode, bool recurseADirty = true);
0422
0423
0424
0425 void setValueDirty()
0426 {
0427 if (_operMode == Auto && !inhibitDirty())
0428 setValueDirty(nullptr);
0429 }
0430
0431 void setShapeDirty() { setShapeDirty(nullptr); }
0432
0433 const char *aggregateCacheUniqueSuffix() const;
0434 virtual const char *cacheUniqueSuffix() const { return nullptr; }
0435
0436 void wireAllCaches();
0437
0438 RooExpensiveObjectCache &expensiveObjectCache() const;
0439 virtual void setExpensiveObjectCache(RooExpensiveObjectCache &cache) { _eocache = &cache; }
0440
0441
0442
0443
0444
0445 virtual void setCachedValue(double , bool = true) {};
0446
0447
0448
0449
0450
0451 static void verboseDirty(bool flag);
0452 void printDirty(bool depth = true) const;
0453 static void setDirtyInhibit(bool flag);
0454
0455 void graphVizTree(const char *fileName, const char *delimiter = "\n", bool useTitle = false, bool useLatex = false);
0456 void graphVizTree(std::ostream &os, const char *delimiter = "\n", bool useTitle = false, bool useLatex = false);
0457
0458 void printComponentTree(const char *indent = "", const char *namePat = nullptr, Int_t nLevel = 999);
0459 void printCompactTree(const char *indent = "", const char *fileName = nullptr, const char *namePat = nullptr,
0460 RooAbsArg *client = nullptr);
0461 void printCompactTree(std::ostream &os, const char *indent = "", const char *namePat = nullptr,
0462 RooAbsArg *client = nullptr);
0463 virtual void printCompactTreeHook(std::ostream &os, const char *ind = "");
0464
0465
0466
0467
0468
0469
0470
0471
0472
0473
0474
0475 bool addOwnedComponents(const RooAbsCollection &comps);
0476 bool addOwnedComponents(RooAbsCollection &&comps);
0477 bool addOwnedComponents(RooArgList &&comps);
0478
0479
0480
0481 template <typename... Args_t>
0482 bool addOwnedComponents(std::unique_ptr<Args_t>... comps)
0483 {
0484 return addOwnedComponents({*comps.release()...});
0485 }
0486 const RooArgSet *ownedComponents() const { return _ownedComponents; }
0487
0488 void setProhibitServerRedirect(bool flag) { _prohibitServerRedirect = flag; }
0489
0490 void setWorkspace(RooWorkspace &ws) { _myws = &ws; }
0491 inline RooWorkspace *workspace() const { return _myws; }
0492
0493 RooAbsProxy *getProxy(Int_t index) const;
0494 Int_t numProxies() const;
0495
0496
0497
0498
0499
0500
0501
0502 inline const TNamed *namePtr() const { return _namePtr; }
0503
0504 void SetName(const char *name) override;
0505 void SetNameTitle(const char *name, const char *title) override;
0506
0507 virtual bool importWorkspaceHook(RooWorkspace &ws)
0508 {
0509 _myws = &ws;
0510 return false;
0511 };
0512
0513 virtual bool canComputeBatchWithCuda() const { return false; }
0514 virtual bool isReducerNode() const { return false; }
0515
0516 virtual void applyWeightSquared(bool flag);
0517
0518 virtual std::unique_ptr<RooAbsArg>
0519 compileForNormSet(RooArgSet const &normSet, RooFit::Detail::CompileContext &ctx) const;
0520
0521 virtual bool isCategory() const { return false; }
0522
0523 protected:
0524 void graphVizAddConnections(std::set<std::pair<RooAbsArg *, RooAbsArg *>> &);
0525
0526 virtual void operModeHook() {};
0527
0528 virtual void optimizeDirtyHook(const RooArgSet * ) {};
0529
0530 virtual bool isValid() const;
0531
0532 virtual void
0533 getParametersHook(const RooArgSet * , RooArgSet * , bool ) const {};
0534
0535 void clearValueAndShapeDirty() const
0536 {
0537 _valueDirty = false;
0538 _shapeDirty = false;
0539 }
0540
0541 void clearValueDirty() const { _valueDirty = false; }
0542 void clearShapeDirty() const { _shapeDirty = false; }
0543
0544
0545 void setValueDirty(const RooAbsArg *source);
0546
0547 void setShapeDirty(const RooAbsArg *source);
0548
0549 virtual void ioStreamerPass2();
0550 static void ioStreamerPass2Finalize();
0551
0552 private:
0553 void addParameters(RooAbsCollection ¶ms, const RooArgSet *nset = nullptr, bool stripDisconnected = true) const;
0554
0555 RefCountListLegacyIterator_t *makeLegacyIterator(const RefCountList_t &list) const;
0556
0557 protected:
0558 friend class RooAbsReal;
0559
0560
0561 friend class RooAbsCollection;
0562 friend class RooWorkspace;
0563 friend class RooRealIntegral;
0564 RefCountList_t _serverList;
0565 RefCountList_t _clientList;
0566 RefCountList_t _clientListShape;
0567 RefCountList_t _clientListValue;
0568
0569 RooRefArray _proxyList;
0570
0571 std::vector<RooAbsCache *> _cacheList;
0572
0573
0574 friend class RooArgProxy;
0575 template <class RooCollection_t>
0576 friend class RooCollectionProxy;
0577 friend class RooHistPdf;
0578 friend class RooHistFunc;
0579 void registerProxy(RooArgProxy &proxy);
0580 void registerProxy(RooSetProxy &proxy);
0581 void registerProxy(RooListProxy &proxy);
0582 void unRegisterProxy(RooArgProxy &proxy);
0583 void unRegisterProxy(RooSetProxy &proxy);
0584 void unRegisterProxy(RooListProxy &proxy);
0585 void setProxyNormSet(const RooArgSet *nset);
0586
0587
0588 std::set<std::string> _boolAttrib;
0589 std::map<std::string, std::string> _stringAttrib;
0590 std::set<std::string> _boolAttribTransient;
0591
0592 void printAttribList(std::ostream &os) const;
0593
0594
0595 friend class RooCompositeDataStore;
0596 friend class RooTreeDataStore;
0597 friend class RooVectorDataStore;
0598 friend class RooDataSet;
0599 friend class RooRealMPFE;
0600 virtual void syncCache(const RooArgSet *nset = nullptr) = 0;
0601 virtual void copyCache(const RooAbsArg *source, bool valueOnly = false, bool setValDirty = true) = 0;
0602
0603 virtual void attachToTree(TTree &t, Int_t bufSize = 32000) = 0;
0604 virtual void attachToVStore(RooVectorDataStore &vstore) = 0;
0605
0606 void attachToStore(RooAbsDataStore &store);
0607
0608 virtual void setTreeBranchStatus(TTree &t, bool active) = 0;
0609 virtual void fillTreeBranch(TTree &t) = 0;
0610 TString cleanBranchName() const;
0611
0612
0613 friend std::ostream &operator<<(std::ostream &os, const RooAbsArg &arg);
0614 friend std::istream &operator>>(std::istream &is, RooAbsArg &arg);
0615 friend void RooRefArray::Streamer(TBuffer &);
0616
0617 struct ProxyListCache {
0618 std::vector<RooAbsProxy *> cache;
0619 bool isDirty = true;
0620 };
0621 ProxyListCache _proxyListCache;
0622
0623
0624 static bool _verboseDirty;
0625 static bool _inhibitDirty;
0626 bool _deleteWatch = false;
0627
0628 bool inhibitDirty() const;
0629
0630 public:
0631 void setLocalNoDirtyInhibit(bool flag) const { _localNoInhibitDirty = flag; }
0632 bool localNoDirtyInhibit() const { return _localNoInhibitDirty; }
0633
0634
0635 std::size_t dataToken() const { return _dataToken; }
0636 bool hasDataToken() const { return _dataToken != std::numeric_limits<std::size_t>::max(); }
0637 void setDataToken(std::size_t index);
0638 void resetDataToken() { _dataToken = std::numeric_limits<std::size_t>::max(); }
0639
0640 protected:
0641 mutable bool _valueDirty = true;
0642 mutable bool _shapeDirty = true;
0643
0644 mutable OperMode _operMode = Auto;
0645 mutable bool _fast = false;
0646
0647
0648 RooArgSet *_ownedComponents = nullptr;
0649
0650 mutable bool _prohibitServerRedirect = false;
0651
0652 mutable RooExpensiveObjectCache *_eocache{nullptr};
0653
0654 mutable const TNamed *_namePtr = nullptr;
0655 bool _isConstant = false;
0656
0657 mutable bool _localNoInhibitDirty = false;
0658
0659 mutable RooWorkspace *_myws = nullptr;
0660
0661 std::size_t _dataToken = std::numeric_limits<std::size_t>::max();
0662
0663
0664
0665
0666 friend class RooFitResult;
0667
0668 public:
0669
0670 static void addToIoEvoList(RooAbsArg *newObj, TRefArray const &onfileProxyList);
0671
0672
0673 private:
0674 void substituteServer(RooAbsArg *oldServer, RooAbsArg *newServer);
0675 bool
0676 callRedirectServersHook(RooAbsCollection const &newSet, bool mustReplaceAll, bool nameChange, bool isRecursionStep);
0677
0678 ClassDefOverride(RooAbsArg, 9)
0679 };
0680
0681 std::ostream &operator<<(std::ostream &os, const RooAbsArg &arg);
0682 std::istream &operator>>(std::istream &is, RooAbsArg &arg);
0683
0684 #endif