Skip to content

Commit

Permalink
Add Laplace transform
Browse files Browse the repository at this point in the history
  • Loading branch information
VanyaBelyaev committed Oct 27, 2024
1 parent 8d61ef7 commit aa9b2b9
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ReleaseNotes/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
1. Add Anderson-Darling and Cramer-von-Mises Two Sample Tests
1. Add progress bar to methdos dealing with unique/duplicated entries in dataset
1. Add Hilbert transform

1. Add Laplace transform

## Backward incompatible

## Bug fixes
Expand Down
2 changes: 2 additions & 0 deletions source/CMake_OSTAP.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ add_library(ostap SHARED src/format.cpp
src/GSL_sentry.cpp
src/GSL_utils.cpp
src/Hesse.cpp
src/Hilbert.cpp
src/HistoDump.cpp
src/HistoHash.cpp
src/HistoInterpolation.cpp
Expand All @@ -48,6 +49,7 @@ add_library(ostap SHARED src/format.cpp
src/Iterator.cpp
src/Kinematics.cpp
src/KramersKronig.cpp
src/Laplace.cpp
src/Lomont.cpp
src/LorentzVectorWithError.cpp
src/Math.cpp
Expand Down
96 changes: 96 additions & 0 deletions source/include/Ostap/Laplace.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// ============================================================================
#ifndef OSTAP_LAPLACE_H
#define OSTAP_LAPLACE_H 1
// ============================================================================
// Include files
// ============================================================================
// STD&STL
// ============================================================================
#include <functional>
// ============================================================================
// Ostap
// ============================================================================
#include "Ostap/Integrator.h"
// ============================================================================
namespace Ostap
{
// ==========================================================================
namespace Math
{
// ========================================================================
/** @class Laplace Ostap/Laplace.h
* Simple class to implement Hilbert transform
* https://en.wikipedia.org/wiki/Hilbert_transform
*/
class Laplace
{
// ======================================================================
/** templated constructor from the function
* @param func the function
* @param tag unique tag/label for cache
* @param size size of integration workspace
*/
template <class FUNCTION>
Laplace
( FUNCTION func ,
const std::size_t tag = 0 ,
const double aprecision = 0 ,
const double rprecision = 0 ,
const std::size_t size = 0 )
: m_func ( func )
, m_tag ( tag )
, m_aprecision ( aprecision )
, m_rprecision ( rprecision )
, m_integrator ( size )
{} ;
// ======================================================================
public:
// ======================================================================
/** templated creator from the function
* @param func the function
* @param tag unique tag/label for cache
* @param size size of integration workspace
*/
template <class FUNCTION>
inline static Laplace
create
( FUNCTION func ,
const std::size_t tag = 0 ,
const double aprecision = 0 ,
const double rprecision = 0 ,
const std::size_t size = 0 )
{ return Laplace ( func , tag , aprecision , rprecision , size ) ; }
// ======================================================================
public:
// ======================================================================
/// Get the value of Laplace transform
double operator() ( const double x ) const ;
// ======================================================================
public:
// ======================================================================
/// get the value of the unction
inline double func ( const double x ) const { return m_func ( x ) ; }
// ======================================================================
private:
// ======================================================================
/// the function
std::function<double(double)> m_func ; // the function
/// unique tag/label
std::size_t m_tag ; // unique tag/label
/// absolte precison
double m_aprecision ; // absoluet preciison
/// relative precison
double m_rprecision ; // relative precision
/// Integrator
Ostap::Math::Integrator m_integrator ; // integrator
// ======================================================================
}; // The end of class Ostap::Math::Laplace
// ========================================================================
} // The end of namespace Ostap::Math
// ==========================================================================
} // The end of namepsace Ostap
// ============================================================================
// The END
// ============================================================================
#endif // OSTAP_LAPLACE_H
// ============================================================================
39 changes: 39 additions & 0 deletions source/src/Laplace.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// ============================================================================
// Include files
// =============================================================================
// Incldue files
// =============================================================================
// STD& STL
// =============================================================================
#include <cmath>
// =============================================================================
// Ostap
// =============================================================================
#include "Ostap/Hash.h"
#include "Ostap/Laplace.h"
// =============================================================================
/** @file
* Implementation file for class Ostap::Math::Laplace
* @date 2024-10-27
* @author Vanya Belyaev [email protected]
*/
// =============================================================================
double Ostap::Math::Laplace::operator() ( const double x ) const
{
auto the_fun = [x,this] ( const double z ) -> double
{ return this->m_func ( z ) * std::exp ( - x * z ) ; };
//
const std::size_t ntag =
( 0 == m_tag ) ? m_tag : Ostap::Utils::hash_combiner ( m_tag , x ) ;
return m_integrator.integrate_to_infinity
( std::cref ( the_fun ) ,
0.0 , // xmin
ntag , // tag
m_aprecision ,
m_rprecision ) ;
}
// =============================================================================
// The END
// =============================================================================


2 changes: 2 additions & 0 deletions source/src/dict/Ostap.hh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "Ostap/GSL_utils.h"
#include "Ostap/Hesse.h"
#include "Ostap/HFuncs.h"
#include "Ostap/Hilbert.h"
#include "Ostap/Hash.h"
#include "Ostap/HistoDump.h"
#include "Ostap/HistoHash.h"
Expand All @@ -57,6 +58,7 @@
#include "Ostap/Interpolation.h"
#include "Ostap/Interpolants.h"
#include "Ostap/Iterator.h"
#include "Ostap/Laplace.h"
#include "Ostap/Line.h"
#include "Ostap/LineTypes.h"
#include "Ostap/Lomont.h"
Expand Down

0 comments on commit aa9b2b9

Please sign in to comment.