Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-13 09:25:26

0001 /*****************************************************************************
0002  * Project: RooFit                                                           *
0003  * Package: RooFitCore                                                       *
0004  *    File: $Id: RooFormulaVar.h,v 1.29 2007/08/09 19:55:47 wouter 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_FORMULA_VAR
0017 #define ROO_FORMULA_VAR
0018 
0019 #include "RooAbsReal.h"
0020 #include "RooArgList.h"
0021 #include "RooListProxy.h"
0022 #include "RooTrace.h"
0023 #include "RooAbsBinning.h"
0024 
0025 #include <memory>
0026 #include <list>
0027 #include <map>
0028 #include <string>
0029 
0030 class RooArgSet ;
0031 class RooFormula ;
0032 class RooAbsRealLValue;
0033 
0034 class RooFormulaVar : public RooAbsReal {
0035 public:
0036   // Constructors, assignment etc
0037   RooFormulaVar();
0038   ~RooFormulaVar() override;
0039   RooFormulaVar(const char *name, const char *title, const char* formula, const RooArgList& dependents, bool checkVariables = true);
0040   RooFormulaVar(const char *name, const char *title, const RooArgList& dependents, bool checkVariables = true);
0041   RooFormulaVar(const RooFormulaVar& other, const char* name=nullptr);
0042   TObject* clone(const char* newname=nullptr) const override { return new RooFormulaVar(*this,newname); }
0043 
0044   bool ok() const;
0045   const char* expression() const { return _formExpr.Data(); }
0046   const RooArgList& dependents() const { return _actualVars; }
0047 
0048   /// Return pointer to parameter with given name.
0049   inline RooAbsArg* getParameter(const char* name) const {
0050     return _actualVars.find(name) ;
0051   }
0052   /// Return pointer to parameter at given index.
0053   inline RooAbsArg* getParameter(Int_t index) const {
0054     return _actualVars.at(index) ;
0055   }
0056   /// Return the number of parameters.
0057   inline size_t nParameters() const {
0058     return _actualVars.size();
0059   }
0060 
0061   // I/O streaming interface (machine readable)
0062   bool readFromStream(std::istream& is, bool compact, bool verbose=false) override ;
0063   void writeToStream(std::ostream& os, bool compact) const override ;
0064 
0065   // Printing interface (human readable)
0066   void printMultiline(std::ostream& os, Int_t contents, bool verbose=false, TString indent= "") const override ;
0067   void printMetaArgs(std::ostream& os) const override ;
0068 
0069   // Debugging
0070   /// Dump the formula to stdout.
0071   void dumpFormula();
0072 
0073   double defaultErrorLevel() const override ;
0074 
0075   void setBinning(const RooAbsRealLValue &obs, const RooAbsBinning &binning, bool checkFlatness = true);
0076   const RooAbsBinning *getBinning(const RooAbsRealLValue &obs) const;
0077   bool removeBinning(const RooAbsRealLValue &obs);
0078 
0079   bool isBinnedDistribution(const RooArgSet &obs) const override;
0080   std::list<double>* binBoundaries(RooAbsRealLValue& obs, double xlo, double xhi) const override ;
0081   std::list<double>* plotSamplingHint(RooAbsRealLValue& obs, double xlo, double xhi) const override ;
0082 
0083   // Function evaluation
0084   double evaluate() const override ;
0085   void doEval(RooFit::EvalContext &ctx) const override;
0086 
0087   std::string getUniqueFuncName() const;
0088 
0089   std::unique_ptr<RooAbsArg>
0090   compileForNormSet(RooArgSet const &normSet, RooFit::Detail::CompileContext &ctx) const override;
0091 
0092   protected:
0093   // Post-processing of server redirection
0094   bool redirectServersHook(const RooAbsCollection& newServerList, bool mustReplaceAll, bool nameChange, bool isRecursive) override ;
0095 
0096   bool isValidReal(double /*value*/, bool /*printError*/) const override {return true;}
0097 
0098   private:
0099   RooFormula& getFormula() const;
0100 
0101   RooListProxy _actualVars ;     ///< Actual parameters used by formula engine
0102   mutable RooFormula *_formula = nullptr; ///<! Formula engine
0103   mutable RooArgSet* _nset{nullptr}; ///<! Normalization set to be passed along to contents
0104   TString _formExpr ;            ///< Formula expression string
0105 
0106   std::map<int, std::unique_ptr<RooAbsBinning>> _binnings; ///< User-defined binnings, keyed by the observable's index
0107                                                            ///< in _actualVars, for a piecewise-flat distribution
0108 
0109   ClassDefOverride(RooFormulaVar, 2) // Real-valued function of other RooAbsArgs calculated by a TFormula expression
0110 };
0111 
0112 #endif