-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Add
Ostap::MoreRooFit::Rational
and `Ostap::MoreRooFit::Ratioal…
…Bernstein` 1. Add `RationaFun` FUN
- Loading branch information
1 parent
ba22586
commit 624ec49
Showing
9 changed files
with
504 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
'RooPoly' , ## simple wrapper for RooPolyVar (RooAbsReal) | ||
'ScaleAndShift' , ## scale and shift (RooAbsReal) | ||
'BSplineFun' , ## BSpline (RooAbsReal) | ||
'RationalFun' , ## Ratioal function (RooAbsReal) | ||
'Shape1D_fun' , ## arbitrary fixed shape (RooAbsReal) | ||
'Histo1D_fun' , ## fixed shap form historgam (RooAbsReal) | ||
'Histo1DErr_fun' , ## fixed shap from historgam errors (RooAbsReal) | ||
|
@@ -538,6 +539,71 @@ def power ( self ) : | |
"""'power' : degree for BSpline object""" | ||
return self.fun.degree() | ||
|
||
|
||
|
||
# ============================================================================= | ||
## @class RationalFun | ||
# A simple pole-free rational function at interval \f$ x_{min} \le x \le x_{max}\f$ | ||
# \f[ F(x) = \frac{p(x)}{q(x)} \f] | ||
# Actually internally it uses | ||
# the Floater-Hormann rational barycentric interpolant | ||
# and parameters are the function values at Chebyshev's nodes | ||
# | ||
# @see Ostap::MoreRooFit::Rational | ||
# @see Ostap::Math::Rational | ||
# @see Ostap::Math::FloaterHormann | ||
# @author Vanya BELYAEV [email protected] | ||
# @date 2023-09-21 | ||
class RationalFun(FUN1,ParamsPoly) : | ||
r"""A simple pole-free rational function at interval \f$ x_{min} \le x \le x_{max}\f$ | ||
>>> p1 = BernsteinPoly ( 'P1' , xvar = (0,1) , power = 3 ) | ||
>>> p2 = BernsteinPoly ( 'P2' , xvar = (0,1) , pars = ... ) | ||
- see Ostap.MoreRooFit.Bernstein | ||
- see Ostap.Math.Bernstein | ||
""" | ||
def __init__ ( self , name , xvar , | ||
n = 3 , | ||
d = 1 , pars = None ) : | ||
|
||
## initialize the base class | ||
FUN1 .__init__ ( self , name , xvar = xvar ) | ||
ParamsPoly.__init__ ( self , | ||
npars = n + 1 , | ||
pars = pars ) | ||
|
||
assert isinstance ( n , int ) and 1 <= n , 'Invalid parameter n' | ||
assert isinstance ( d , int ) and 0 <= d <= n , 'Invalid parameter d' | ||
|
||
xmin , xmax = self.xminmax () | ||
|
||
## create the function | ||
self.fun = Ostap.MoreRooFit.Rational ( | ||
self.roo_name ( 'rfun_' ) , | ||
'Rational %s' % self.name , | ||
self.xvar , | ||
self.pars_lst , | ||
d , | ||
xmin , | ||
xmax ) | ||
|
||
## self.tricks = True | ||
self.config = { | ||
'name' : self.name , | ||
'xvar' : self.xvar , | ||
'n' : self.fun.n () , | ||
'd' : self.fun.d () , | ||
'pars' : self.pars , | ||
} | ||
|
||
@property | ||
def n ( self ) : | ||
"""'n' : n-parameter of rational function""" | ||
return self.fun.n () | ||
@property | ||
def d ( self ) : | ||
"""'d' : d-parameter of rational function""" | ||
return self.fun.d () | ||
|
||
|
||
# ============================================================================= | ||
## Generic 1D-shape from C++ callable | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
#include "Ostap/Bernstein.h" | ||
#include "Ostap/Bernstein1D.h" | ||
#include "Ostap/BSpline.h" | ||
#include "Ostap/Rational.h" | ||
#include "Ostap/HistoInterpolators.h" | ||
// ============================================================================ | ||
/// forward declarations | ||
|
@@ -494,7 +495,177 @@ namespace Ostap | |
// ====================================================================== | ||
} ; // The end of class Ostap::MoreRooFit::BSpline | ||
// ======================================================================== | ||
/** @class Shape | ||
/** @class Rational | ||
* A simple pole-free rational function at interval \f$ x_{min} \le x \le x_{max}\f$ | ||
* \f[ F(x) = \frac{p(x)}{q(x)} \f] | ||
* Actually internally it uses | ||
* the Floater-Hormann rational barycentric interpolant | ||
* and parameters are the function valeus at Chebyshev's nodes | ||
* | ||
* @see Ostap::Math::Rational | ||
* @see Ostap::Math::FloaterHormann | ||
* @author Vanya BELYAEV [email protected] | ||
* @date 2023-09-21 | ||
*/ | ||
class Rational final : public RooAbsReal | ||
{ | ||
public: | ||
// ====================================================================== | ||
ClassDefOverride(Ostap::MoreRooFit::Rational, 1) ; | ||
// ====================================================================== | ||
public: | ||
// ====================================================================== | ||
Rational | ||
( const std::string& name , | ||
const std::string& title , | ||
RooAbsReal& xvar , | ||
const RooArgList& pars , | ||
const unsigned short d , | ||
const double xmin , | ||
const double xmax ) ; | ||
/// copy constructor | ||
Rational ( const Rational& right , const char* name = nullptr ) ; | ||
/// default | ||
Rational () ; | ||
/// clone method | ||
Rational* clone ( const char* name ) const override ; | ||
/// virtual destructor | ||
virtual ~Rational() ; | ||
// ====================================================================== | ||
public: | ||
// ====================================================================== | ||
Int_t getAnalyticalIntegral | ||
( RooArgSet& allVars , | ||
RooArgSet& analVars , | ||
const char* rangeName = nullptr ) const override ; | ||
Double_t analyticalIntegral | ||
( Int_t code , | ||
const char* rangeName = nullptr ) const override ; | ||
// ====================================================================== | ||
public: | ||
// ====================================================================== | ||
/// get the variable/observable | ||
const RooAbsReal& xvar () const { return m_xvar.arg() ; } | ||
/// get parameters | ||
const RooArgList& pars () const { return m_pars ; } | ||
/// get n | ||
unsigned short n () const { return m_rational.n () ; } | ||
/// get d | ||
unsigned short d () const { return m_rational.d () ; } | ||
/// xmin for Rational | ||
double xmin () const { return m_rational.xmin () ; } | ||
/// xmax for Rational | ||
double xmax () const { return m_rational.xmax () ; } | ||
// ====================================================================== | ||
public: | ||
// ====================================================================== | ||
void setPars () const ; | ||
// ====================================================================== | ||
public: | ||
// ====================================================================== | ||
const Ostap::Math::Rational& function () const { return m_rational ; } | ||
const Ostap::Math::Rational& rational () const { return m_rational ; } | ||
// ====================================================================== | ||
public: | ||
// ====================================================================== | ||
Double_t evaluate () const override ; | ||
// ====================================================================== | ||
private: | ||
// ====================================================================== | ||
RooRealProxy m_xvar {} ; | ||
RooListProxy m_pars {} ; | ||
mutable Ostap::Math::Rational m_rational { 3 , 1 } ; | ||
// ====================================================================== | ||
} ; | ||
// ======================================================================== | ||
/** @class RationalBernstein | ||
* Rational fnuction as ratio of Bernstein polyhomial and | ||
* positive Bernstein polynomial | ||
* \f[ R ( x ) = \frac{B(x)}{P(x)\f] | ||
* @see Ostap::Math::RationalBernstein | ||
* @see Ostap::Math::Bernstein | ||
* @see Ostap::Math::Positive | ||
* @author Vanya BELYAEV [email protected] | ||
* @date 2023-09-21 | ||
*/ | ||
class RationalBernstein final : public RooAbsReal | ||
{ | ||
public: | ||
// ====================================================================== | ||
ClassDefOverride(Ostap::MoreRooFit::RationalBernstein, 1) ; | ||
// ====================================================================== | ||
public: | ||
// ====================================================================== | ||
RationalBernstein | ||
( const std::string& name , | ||
const std::string& title , | ||
RooAbsReal& xvar , | ||
const RooArgList& p , // numerator | ||
const RooArgList& q , // denominator | ||
const double xmin , | ||
const double xmax ) ; | ||
RationalBernstein | ||
( const std::string& name , | ||
const std::string& title , | ||
RooAbsReal& xvar , | ||
const RooArgList& pars , // all pars | ||
const unsigned short p , // degree of numerator | ||
const double xmin , | ||
const double xmax ) ; | ||
/// copy constructor | ||
RationalBernstein ( const RationalBernstein& right , const char* name = nullptr ) ; | ||
/// default | ||
RationalBernstein () ; | ||
/// clone method | ||
RationalBernstein* clone ( const char* name ) const override ; | ||
/// virtual destructor | ||
virtual ~RationalBernstein() ; | ||
// ====================================================================== | ||
public: | ||
// ====================================================================== | ||
Int_t getAnalyticalIntegral | ||
( RooArgSet& allVars , | ||
RooArgSet& analVars , | ||
const char* rangeName = nullptr ) const override ; | ||
Double_t analyticalIntegral | ||
( Int_t code , | ||
const char* rangeName = nullptr ) const override ; | ||
// ====================================================================== | ||
public: | ||
// ====================================================================== | ||
/// get the variable/observable | ||
const RooAbsReal& xvar () const { return m_xvar.arg() ; } | ||
/// get parameters | ||
const RooArgList& pars () const { return m_pars ; } | ||
/// get p | ||
unsigned short p () const { return m_rational.pdegree () ; } | ||
/// xmin for Rational | ||
double xmin () const { return m_rational.xmin () ; } | ||
/// xmax for Rational | ||
double xmax () const { return m_rational.xmax () ; } | ||
// ====================================================================== | ||
public: | ||
// ====================================================================== | ||
void setPars () const ; | ||
// ====================================================================== | ||
public: | ||
// ====================================================================== | ||
const Ostap::Math::RationalBernstein& function () const { return m_rational ; } | ||
const Ostap::Math::RationalBernstein& rational () const { return m_rational ; } | ||
// ====================================================================== | ||
public: | ||
// ====================================================================== | ||
Double_t evaluate () const override ; | ||
// ====================================================================== | ||
private: | ||
// ====================================================================== | ||
RooRealProxy m_xvar {} ; | ||
RooListProxy m_pars {} ; | ||
mutable Ostap::Math::RationalBernstein m_rational { 3 , 1 } ; | ||
// ====================================================================== | ||
} ; | ||
// ======================================================================== | ||
/** @class Shape1D | ||
* The generic "fixed shape" function | ||
* @author Vanya BELYAEV [email protected] | ||
* @date 2023-01-30 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ namespace Ostap | |
* the Floater-Hormann rational barycentric interpolant | ||
* and parameters are the function valeus at Chebyshev's nodes | ||
* | ||
# @see Ostap::Math::FloaterHormann | ||
* @see Ostap::Math::FloaterHormann | ||
* @author Vanya BELYAEV [email protected] | ||
* @date 2023-09-14 | ||
*/ | ||
|
Oops, something went wrong.