Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /*****************************************************************************
0002  * Project: RooFit                                                           *
0003  * Package: RooFitCore                                                       *
0004  *    File: $Id: RooAbsCategoryLValue.h,v 1.22 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_ABS_CATEGORY_LVALUE
0017 #define ROO_ABS_CATEGORY_LVALUE
0018 
0019 #include <RooAbsCategory.h>
0020 #include <RooAbsLValue.h>
0021 
0022 #include <list>
0023 #include <string>
0024 #include <utility> // for std::pair
0025 
0026 class RooAbsCategoryLValue : public RooAbsCategory, public RooAbsLValue {
0027 public:
0028   // Constructor, assignment etc.
0029   RooAbsCategoryLValue() {
0030     // Default constructor
0031   }
0032   RooAbsCategoryLValue(const char *name, const char *title);
0033   RooAbsCategoryLValue(const RooAbsCategoryLValue& other, const char* name=nullptr) ;
0034 
0035   // Value modifiers
0036   ////////////////////////////////////////////////////////////////////////////////
0037   /// Change category state by specifying the index code of the desired state.
0038   /// If printError is set, a message will be printed if
0039   /// the specified index does not represent a valid state.
0040   /// \return bool to signal an error.
0041   virtual bool setIndex(value_type index, bool printError = true) = 0;
0042   ////////////////////////////////////////////////////////////////////////////////
0043   /// Change category state to state specified by another category state.
0044   /// If printError is set, a message will be printed if
0045   /// the specified index does not represent a valid state.
0046   /// \note The state name of the other category is ignored.
0047   /// \return bool to signal an error.
0048   bool setIndex(const std::pair<std::string,value_type>& nameIdxPair, bool printError = true) {
0049     return setIndex(nameIdxPair.second, printError);
0050   }
0051   bool setOrdinal(unsigned int index);
0052 
0053   ////////////////////////////////////////////////////////////////////////////////
0054   /// Change category state by specifying a state name.
0055   /// If printError is set, a message will be printed if
0056   /// the specified state name does not represent a valid state.
0057   /// \return bool to signal an error.
0058   virtual bool setLabel(const char* label, bool printError=true) = 0;
0059   /// \copydoc setLabel(const char*, bool)
0060   bool setLabel(const std::string& label, bool printError = true) {
0061     return setLabel(label.c_str(), printError);
0062   }
0063   ////////////////////////////////////////////////////////////////////////////////
0064   /// Change category state to the state name of another category.
0065   /// If printError is set, a message will be printed if
0066   /// the specified state name does not represent a valid state.
0067   /// \note The state index of the other category is ignored.
0068   /// \return bool to signal an error.
0069   bool setLabel(const std::pair<std::string,value_type>& nameIdxPair, bool printError = true) {
0070     return setLabel(nameIdxPair.first.c_str(), printError);
0071   }
0072 
0073 
0074   RooAbsArg& operator=(int index) ;
0075   RooAbsArg& operator=(const char* label) ;
0076   RooAbsArg& operator=(const RooAbsCategory& other) ;
0077 
0078   // Binned fit interface
0079   void setBin(Int_t ibin, const char* rangeName=nullptr) override ;
0080   /// Get the index of the plot bin for the current value of this category.
0081   Int_t getBin(const char* /*rangeName*/=nullptr) const override {
0082     return getCurrentOrdinalNumber();
0083   }
0084   Int_t numBins(const char* rangeName=nullptr) const override ;
0085   double getBinWidth(Int_t /*i*/, const char* /*rangeName*/=nullptr) const override {
0086     // Return volume of i-th bin (according to binning named rangeName if rangeName!=nullptr)
0087     return 1.0 ;
0088   }
0089   double volume(const char* rangeName) const override {
0090     // Return span of range with given name (=number of states included in this range)
0091     return numTypes(rangeName) ;
0092   }
0093   void randomize(const char* rangeName=nullptr) override;
0094 
0095   const RooAbsBinning* getBinningPtr(const char* /*rangeName*/) const override { return nullptr ; }
0096   std::list<std::string> getBinningNames() const override { return std::list<std::string>(1, "") ; }
0097   Int_t getBin(const RooAbsBinning* /*ptr*/) const override { return getBin((const char*)nullptr) ; }
0098 
0099 
0100   inline void setConstant(bool value= true) {
0101     // Declare category constant
0102     setAttribute("Constant",value);
0103   }
0104 
0105   inline bool isLValue() const override {
0106     // Object is an l-value
0107     return true;
0108   }
0109 
0110 protected:
0111 
0112   friend class RooSimGenContext ;
0113   friend class RooSimSplitGenContext ;
0114   /// \cond
0115   /// \deprecated This function is useless. Use setIndex() instead.
0116   virtual void setIndexFast(Int_t index) {
0117     _currentIndex = index;
0118   }
0119   /// \endcond
0120 
0121   void copyCache(const RooAbsArg* source, bool valueOnly=false, bool setValDirty=true) override ;
0122 
0123   ClassDefOverride(RooAbsCategoryLValue,1) // Abstract modifiable index variable
0124 };
0125 
0126 #endif