Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:11:18

0001 /*****************************************************************************
0002  * Project: RooFit                                                           *
0003  * Package: RooFitCore                                                       *
0004  *    File: $Id: RooAbsRealLValue.h,v 1.37 2007/07/13 21:50:24 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_ABS_REAL_LVALUE
0017 #define ROO_ABS_REAL_LVALUE
0018 
0019 #include <cmath>
0020 #include <cfloat>
0021 #include <utility>
0022 #include "TString.h"
0023 
0024 #include "RooAbsReal.h"
0025 #include "RooNumber.h"
0026 #include "RooAbsLValue.h"
0027 #include "RooAbsBinning.h"
0028 
0029 class RooArgSet ;
0030 
0031 class RooAbsRealLValue : public RooAbsReal, public RooAbsLValue {
0032 public:
0033   // Constructors, assignment etc.
0034   inline RooAbsRealLValue() { }
0035   RooAbsRealLValue(const char *name, const char *title, const char *unit= "") ;
0036   RooAbsRealLValue(const RooAbsRealLValue& other, const char* name=nullptr);
0037 
0038   // Parameter value and error accessors
0039   /// Set the current value of the object. Needs to be overridden by implementations.
0040   virtual void setVal(double value)=0;
0041   /// Set the current value of the object. The rangeName is ignored.
0042   /// Can be overridden by derived classes to e.g. check if the value fits in the given range.
0043   virtual void setVal(double value, const char* /*rangeName*/) {
0044     return setVal(value) ;
0045   }
0046   virtual RooAbsArg& operator=(double newValue);
0047 
0048   // Implementation of RooAbsLValue
0049   void setBin(Int_t ibin, const char* rangeName=nullptr) override ;
0050   Int_t getBin(const char* rangeName=nullptr) const override { return getBinning(rangeName).binNumber(getVal()) ; }
0051   Int_t numBins(const char* rangeName=nullptr) const override { return getBins(rangeName) ; }
0052   double getBinWidth(Int_t i, const char* rangeName=nullptr) const override { return getBinning(rangeName).binWidth(i) ; }
0053   double volume(const char* rangeName) const override { return getMax(rangeName)-getMin(rangeName) ; }
0054   void randomize(const char* rangeName=nullptr) override;
0055 
0056   const RooAbsBinning* getBinningPtr(const char* rangeName) const override { return &getBinning(rangeName) ; }
0057   Int_t getBin(const RooAbsBinning* ptr) const override { return ptr->binNumber(getVal()) ; }
0058 
0059   virtual void setBin(Int_t ibin, const RooAbsBinning& binning) ;
0060   virtual Int_t getBin(const RooAbsBinning& binning) const { return binning.binNumber(getVal()) ; }
0061   virtual Int_t numBins(const RooAbsBinning& binning) const { return binning.numBins() ; }
0062   virtual double getBinWidth(Int_t i, const RooAbsBinning& binning) const { return binning.binWidth(i) ; }
0063   virtual double volume(const RooAbsBinning& binning) const { return binning.highBound() - binning.lowBound() ; }
0064   virtual void randomize(const RooAbsBinning& binning) ;
0065 
0066 
0067   // Get fit range limits
0068 
0069   /// Retrieve binning configuration with given name or default binning.
0070   virtual const RooAbsBinning& getBinning(const char* name=nullptr, bool verbose=true, bool createOnTheFly=false) const = 0 ;
0071   /// Retrieve binning configuration with given name or default binning.
0072   virtual RooAbsBinning& getBinning(const char* name=nullptr, bool verbose=true, bool createOnTheFly=false) = 0 ;
0073   /// Check if binning with given name has been defined.
0074   virtual bool hasBinning(const char* name) const = 0 ;
0075   bool inRange(const char* name) const override ;
0076   /// Get number of bins of currently defined range.
0077   /// \param name Optionally, request number of bins for range with given name.
0078   virtual Int_t getBins(const char* name=nullptr) const { return getBinning(name).numBins(); }
0079   /// Get minimum of currently defined range.
0080   /// \param name Optionally, request minimum of range with given name.
0081   virtual double getMin(const char* name=nullptr) const { return getBinning(name).lowBound(); }
0082   /// Get maximum of currently defined range.
0083   /// \param name Optionally, request maximum of range with given name.
0084   virtual double getMax(const char* name=nullptr) const { return getBinning(name).highBound(); }
0085   /// Get low and high bound of the variable.
0086   /// \param name Optional range name. If not given, the default range will be used.
0087   /// \return A pair with [lowerBound, upperBound]
0088   std::pair<double, double> getRange(const char* name = nullptr) const {
0089     const auto& binning = getBinning(name);
0090     return {binning.lowBound(), binning.highBound()};
0091   }
0092   /// Check if variable has a lower bound.
0093   inline bool hasMin(const char* name=nullptr) const { return !RooNumber::isInfinite(getMin(name)); }
0094   /// Check if variable has an upper bound.
0095   inline bool hasMax(const char* name=nullptr) const { return !RooNumber::isInfinite(getMax(name)); }
0096   /// Check if variable has a binning with given name.
0097   bool hasRange(const char* name) const override { return hasBinning(name) ; }
0098 
0099   // Jacobian term management
0100   virtual bool isJacobianOK(const RooArgSet& depList) const ;
0101   virtual double jacobian() const { return 1 ; }
0102 
0103   inline bool isLValue() const override { return true; }
0104 
0105   // Test a value against our fit range
0106   bool inRange(double value, const char* rangeName, double* clippedValue=nullptr) const;
0107   void inRange(std::span<const double> values, std::string const& rangeName, std::vector<bool>& out) const;
0108   bool isValidReal(double value, bool printError=false) const override ;
0109 
0110   // Constant and Projected flags
0111   inline void setConstant(bool value= true) { setAttribute("Constant",value); setValueDirty() ; setShapeDirty() ; }
0112 
0113   // I/O streaming interface (machine readable)
0114   bool readFromStream(std::istream& is, bool compact, bool verbose=false) override ;
0115   void writeToStream(std::ostream& os, bool compact) const override ;
0116 
0117   // Printing interface (human readable)
0118   void printMultiline(std::ostream& os, Int_t contents, bool verbose=false, TString indent="") const override ;
0119 
0120 
0121   // Build 1-dimensional plots
0122   RooPlot* frame(const RooCmdArg& arg1, const RooCmdArg& arg2={},
0123                  const RooCmdArg& arg3={}, const RooCmdArg& arg4={}, const RooCmdArg& arg5={},
0124                  const RooCmdArg& arg6={}, const RooCmdArg& arg7={}, const RooCmdArg& arg8={}) const ;
0125   RooPlot *frame(const RooLinkedList& cmdList) const ;
0126   RooPlot *frame(double lo, double hi, Int_t nbins) const;
0127   RooPlot *frame(double lo, double hi) const;
0128   RooPlot *frame(Int_t nbins) const;
0129   RooPlot *frame() const;
0130 
0131   // Create empty 1,2, and 3D histograms from a list of 1-3 RooAbsReals
0132   TH1 *createHistogram(const char *name,
0133                        const RooCmdArg& arg1={}, const RooCmdArg& arg2={},
0134                        const RooCmdArg& arg3={}, const RooCmdArg& arg4={},
0135                        const RooCmdArg& arg5={}, const RooCmdArg& arg6={},
0136                        const RooCmdArg& arg7={}, const RooCmdArg& arg8={}) const ;
0137   TH1 *createHistogram(const char *name, const RooLinkedList& cmdList) const ;
0138 
0139   TH1F *createHistogram(const char *name, const char *yAxisLabel) const ;
0140   TH1F *createHistogram(const char *name, const char *yAxisLabel, double xlo, double xhi, Int_t nBins) const ;
0141   TH1F *createHistogram(const char *name, const char *yAxisLabel, const RooAbsBinning& bins) const ;
0142 
0143   TH2F *createHistogram(const char *name, const RooAbsRealLValue &yvar, const char *zAxisLabel=nullptr,
0144          double* xlo=nullptr, double* xhi=nullptr, Int_t* nBins=nullptr) const ;
0145   TH2F *createHistogram(const char *name, const RooAbsRealLValue &yvar, const char *zAxisLabel, const RooAbsBinning** bins) const ;
0146 
0147 
0148   TH3F *createHistogram(const char *name, const RooAbsRealLValue &yvar, const RooAbsRealLValue &zvar,
0149          const char *tAxisLabel, double* xlo=nullptr, double* xhi=nullptr, Int_t* nBins=nullptr) const ;
0150   TH3F *createHistogram(const char *name, const RooAbsRealLValue &yvar, const RooAbsRealLValue &zvar, const char* tAxisLabel, const RooAbsBinning** bins) const ;
0151 
0152   static TH1* createHistogram(const char *name, RooArgList &vars, const char *tAxisLabel, double* xlo, double* xhi, Int_t* nBins) ;
0153   static TH1* createHistogram(const char *name, RooArgList &vars, const char *tAxisLabel, const RooAbsBinning** bins) ;
0154 
0155   RooFit::OwningPtr<RooAbsReal> createIntegral(const RooArgSet& iset, const RooArgSet* nset=nullptr, const RooNumIntConfig* cfg=nullptr, const char* rangeName=nullptr) const override;
0156 
0157 protected:
0158 
0159   virtual void setValFast(double value) { setVal(value) ; }
0160 
0161   bool fitRangeOKForPlotting() const ;
0162   void copyCache(const RooAbsArg* source, bool valueOnly=false, bool setValDirty=true) override ;
0163 
0164   ClassDefOverride(RooAbsRealLValue,1) // Abstract modifiable real-valued object
0165 };
0166 
0167 #endif