From 778875cca5da7ca729f47ce9ba6ced572974f7f9 Mon Sep 17 00:00:00 2001 From: Vanya Belyaev Date: Wed, 17 Jul 2024 11:53:06 +0200 Subject: [PATCH] tmp --- ostap/frames/frames.py | 10 +- ostap/frames/tests/test_frames_frames.py | 12 +- source/include/Ostap/DataFrameActions.h | 1101 +++++----------------- source/include/Ostap/Moments.h | 11 +- source/src/DataFrameActions.cpp | 344 ------- 5 files changed, 280 insertions(+), 1198 deletions(-) diff --git a/ostap/frames/frames.py b/ostap/frames/frames.py index ca797f45..845846a3 100644 --- a/ostap/frames/frames.py +++ b/ostap/frames/frames.py @@ -441,11 +441,13 @@ def _fr_the_moment_ ( frame , N , expression , cuts = '' ) : cname = vn if cname : - TT = ROOT.Detail.RDF.WMoment_(N) - return current.Book( ROOT.std.move ( TT () ) , CNT ( [ vname , cname ] ) ) + ## TT = Ostap.Actions.WMoment_(N) + TT = ROOT.Detail.RDF.WStatAction ( Ostap.Math.WMoment_(N) ) + return current.Book ( ROOT.std.move ( TT () ) , CNT ( [ vname , cname ] ) ) else : - TT = ROOT.Detail.RDF.Moment_(N) - return current.Book( ROOT.std.move ( TT () ) , CNT ( 1 , vname ) ) + ## TT = Ostap.Actions.Moment_(N) + TT = ROOT.Detail.RDF.StatAction ( Ostap.Math.Moment_(N) ) + return current.Book ( ROOT.std.move ( TT () ) , CNT ( 1 , vname ) ) return results diff --git a/ostap/frames/tests/test_frames_frames.py b/ostap/frames/tests/test_frames_frames.py index bffc2726..e029f45d 100644 --- a/ostap/frames/tests/test_frames_frames.py +++ b/ostap/frames/tests/test_frames_frames.py @@ -335,12 +335,12 @@ def test_frame8 () : ## test_frame0 () ## test_frame1 () test_frame2 () - ## test_frame3 () - ## test_frame4 () - ## test_frame5 () - ## test_frame6 () - ## test_frame7 () - ## test_frame8 () + test_frame3 () + test_frame4 () + test_frame5 () + test_frame6 () + test_frame7 () + test_frame8 () else : diff --git a/source/include/Ostap/DataFrameActions.h b/source/include/Ostap/DataFrameActions.h index 867b14a2..8f774567 100644 --- a/source/include/Ostap/DataFrameActions.h +++ b/source/include/Ostap/DataFrameActions.h @@ -39,316 +39,6 @@ namespace ROOT // ======================================================================== namespace RDF { - // ====================================================================== - /** @class StatVar - * Helper class to get statitsics for the column in DataFrame - * @see Ostap::StatEntity - * @see Ostap::DataFrame - */ - class StatVar : public RActionImpl - { - public: - // ==================================================================== - /// define the result type - using Result_t = Ostap::StatEntity ; - // ==================================================================== - public: - // ==================================================================== - /// default constructor - StatVar () ; - /// Move constructor - StatVar ( StatVar&& ) = default ; - /// Copy constructor is disabled - StatVar ( const StatVar& ) = delete ; - // ==================================================================== - public: - // ==================================================================== - /// initialize (empty) - void InitTask ( TTreeReader * , unsigned int ) {} ; - /// initialize (empty) - void Initialize () {} ; - /// finalize : sum over the slots - void Finalize () ; - /// who am I ? - std::string GetActionName() { return "StatVar" ; } - // ==================================================================== - public: - // ==================================================================== - /// The basic method: increment the counter - void Exec ( unsigned int slot , double value ) - { m_slots [ slot % m_N ] += value ; } - // ==================================================================== - /// The basic method: increment the counter for the vector-like columns -#if ROOT_VERSION(6,22,0) <= ROOT_VERSION_CODE - template ::value, int>::type = 0> -#else - template ::value, int>::type = 0> -#endif - void Exec ( unsigned int slot , const T &vs ) - { Result_t& e = m_slots [ slot % m_N ] ; for ( const auto & v : vs ) { e += v ; } } - // ==================================================================== - public: - // ==================================================================== - /// Get the result - std::shared_ptr GetResultPtr () const { return m_result ; } - /// get partial result for the given slot - Result_t& PartialUpdate ( unsigned int slot ) { return m_slots [ slot % m_N ] ; } - // ==================================================================== - private: - // ==================================================================== - /// the final result - const std::shared_ptr m_result { } ; - /// size of m_slots - unsigned long m_N { 1 } ; - /// (current) results per slot - std::vector m_slots { 1 } ; - // ==================================================================== - } ; // The end of class ROOT::Detail::RDF::StatVar - // ====================================================================== - /** @class WStatVar - * Helper class to get weighted statitsics for the column in DataFrame - * @see Ostap::WStatEntity - * @see Ostap::DataFrame - */ - class WStatVar : public RActionImpl - { - public: - // ==================================================================== - /// define the resutl type - using Result_t = Ostap::WStatEntity ; - // ==================================================================== - public: - // ==================================================================== - /// default constructor - WStatVar () ; - /// Move constructor - WStatVar ( WStatVar&& ) = default ; - /// Copy constructor is disabled - WStatVar ( const WStatVar& ) = delete ; - // ==================================================================== - public: - // ==================================================================== - /// initialize (empty) - void InitTask ( TTreeReader * , unsigned int ) {} ; - /// initialize (empty) - void Initialize () {} ; - /// finalize : sum over the slots - void Finalize () ; - /// who am I ? - std::string GetActionName() { return "WStatVar" ; } - // ==================================================================== - public: - // ==================================================================== - /// The basic method: increment the counter - void Exec ( unsigned int slot , double value , double weight = 1 ) - { m_slots [ slot % m_N ].add ( value , weight ) ; } - // ==================================================================== - /// The basic method: increment the counter for the vector-like column of values -#if ROOT_VERSION(6,22,0) <= ROOT_VERSION_CODE - template ::value, int>::type = 0> -#else - template ::value, int>::type = 0> -#endif - void Exec ( unsigned int slot , const T &vs , const double weight = 1 ) - { - Result_t& e = m_slots [ slot % m_N ] ; for ( const auto & v : vs ) { e.add ( v , weight ) ; } - } - // ==================================================================== - /// The basic method: increment the counter for the vector-like column of weight -#if ROOT_VERSION(6,22,0) <= ROOT_VERSION_CODE - template ::value, int>::type = 0> -#else - template ::value, int>::type = 0> -#endif - void Exec ( unsigned int slot , const double value , const T &ws ) - { Result_t& e = m_slots [ slot % m_N ] ; for ( const auto & w : ws ) { e.add ( value , w ) ; } } - // ==================================================================== - public: - // ==================================================================== - /// Get the result - std::shared_ptr GetResultPtr () const { return m_result ; } - /// get partial result for the given slot - Result_t& PartialUpdate ( unsigned int slot ) { return m_slots [ slot % m_N ] ; } - // ==================================================================== - private: - // ==================================================================== - /// the final result - const std::shared_ptr m_result {} ; - /// size of m_slots - unsigned long m_N { 1 } ; - /// (current) results per slot - std::vector m_slots { 1 } ; - // ==================================================================== - } ; // The end of class ROOT::Detail::RDF::WStatVar - // ====================================================================== - /** @class Moment_ - * Helper class to get statitsics for the column in DataFrame - * @see Ostap::Math::Moment_ - */ - template - class Moment_ : public RActionImpl > - { - public: - // ==================================================================== - /// define the result type - using Result_t = Ostap::Math::Moment_ ; - // ==================================================================== - public: - // ==================================================================== - /// default constructor - Moment_ () - : m_result ( std::make_shared() ) -#if ROOT_VERSION_CODE >= ROOT_VERSION(6,22,0) - , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetThreadPoolSize () ) : 1u ) -#else - , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetImplicitMTPoolSize () ) : 1u ) -#endif - , m_slots ( this->m_N ) - {} - /// Move constructor - Moment_ ( Moment_&& ) = default ; - /// Copy constructor is disabled - Moment_ ( const Moment_& ) = delete ; - // ==================================================================== - public: - // ==================================================================== - /// initialize (empty) - void InitTask ( TTreeReader * , unsigned int ) {} ; - /// initialize (empty) - void Initialize () {} ; - /// finalize : sum over the slots - void Finalize () - { - Result_t sum { m_slots [ 0 ] } ; - for ( unsigned int i = 1 ; i < m_N ; ++i ) { sum += m_slots [ i ] ; } - *m_result = sum ; - } - /// who am I ? - std::string GetActionName() { return "Moment_" ; } - // ==================================================================== - public: - // ==================================================================== - /// The basic method: increment the counter - void Exec ( unsigned int slot , double value ) - { m_slots [ slot % m_N ].add ( value ) ; } - // ==================================================================== - /// The basic method: increment the counter for the vector-like columns -#if ROOT_VERSION(6,22,0) <= ROOT_VERSION_CODE - template ::value, int>::type = 0> -#else - template ::value, int>::type = 0> -#endif - void Exec ( unsigned int slot , const T &vs ) - { Result_t& m = m_slots [ slot % m_N ] ; for ( const auto & v : vs ) { m.add ( v ) ; } } - // ==================================================================== - public: - // ==================================================================== - /// Get the result - std::shared_ptr GetResultPtr () const { return m_result ; } - /// get partial result for the given slot - Result_t& PartialUpdate ( unsigned int slot ) { return m_slots [ slot % m_N ] ; } - // ==================================================================== - private: - // ==================================================================== - /// the final result - const std::shared_ptr m_result { } ; - /// size of m_slots - unsigned long m_N { 1 } ; - /// (current) results per slot - std::vector m_slots { 1 } ; - // ==================================================================== - } ; // The end of class ROOT::Detail::RDF::Moment_ - // ====================================================================== - /** @class WMoment_ - * Helper class to get statitsics for the column in DataFrame - * @see Ostap::Math::WMoment_ - */ - template - class WMoment_ : public RActionImpl > - { - public: - // ==================================================================== - /// define the result type - using Result_t = Ostap::Math::WMoment_ ; - // ==================================================================== - public: - // ==================================================================== - /// default constructor - WMoment_ () - : m_result ( std::make_shared() ) -#if ROOT_VERSION_CODE >= ROOT_VERSION(6,22,0) - , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetThreadPoolSize () ) : 1u ) -#else - , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetImplicitMTPoolSize () ) : 1u ) -#endif - , m_slots ( this->m_N ) - {} - /// Move constructor - WMoment_ ( WMoment_&& ) = default ; - /// Copy constructor is disabled - WMoment_ ( const WMoment_& ) = delete ; - // ==================================================================== - public: - // ==================================================================== - /// initialize (empty) - void InitTask ( TTreeReader * , unsigned int ) {} ; - /// initialize (empty) - void Initialize () {} ; - /// finalize : sum over the slots - void Finalize () - { - Result_t sum { m_slots [ 0 ] } ; - for ( unsigned int i = 1 ; i < m_N ; ++i ) { sum += m_slots [ i ] ; } - *m_result = sum ; - } - /// who am I ? - std::string GetActionName() { return "WMoment_" ; } - // ==================================================================== - public: - // ==================================================================== - /// The basic method: increment the counter - void Exec ( unsigned int slot , double value , double weight ) - { m_slots [ slot % m_N ].add ( value , weight ) ; } - // ==================================================================== - /// The basic method: increment the counter for the vector-like columns -#if ROOT_VERSION(6,22,0) <= ROOT_VERSION_CODE - template ::value, int>::type = 0> -#else - template ::value, int>::type = 0> -#endif - void Exec ( unsigned int slot , const T &vs , double weight ) - { Result_t& m = m_slots [ slot % m_N ] ; for ( const auto & v : vs ) { m.add ( v ) ; } } - // ==================================================================== - /// The basic method: increment the counter for the vector-like column of weight -#if ROOT_VERSION(6,22,0) <= ROOT_VERSION_CODE - template ::value, int>::type = 0> -#else - template ::value, int>::type = 0> -#endif - void Exec ( unsigned int slot , const double value , const T &ws ) - { Result_t& e = m_slots [ slot % m_N ] ; for ( const auto & w : ws ) { e.add ( value , w ) ; } } - // ==================================================================== - public: - // ==================================================================== - /// Get the result - std::shared_ptr GetResultPtr () const { return m_result ; } - /// get partial result for the given slot - Result_t& PartialUpdate ( unsigned int slot ) { return m_slots [ slot % m_N ] ; } - // ==================================================================== - private: - // ==================================================================== - /// the final result - const std::shared_ptr m_result { } ; - /// size of m_slots - unsigned long m_N { 1 } ; - /// (current) results per slot - std::vector m_slots { 1 } ; - // ==================================================================== - } ; // The end of class ROOT::Detail::RDF::Moment_ - // ====================================================================== - - - // ====================================================================== /** @class StatAction * Helper class to get statitsics for the column in DataFrame @@ -356,6 +46,8 @@ namespace ROOT * Requirements for COUNTER: * - counter.add ( value ) * - counter += counter + * @see Ostap::StatEntity + * @see Ostap::Math::Moment_ */ template class StatAction : public RActionImpl< StatAction > @@ -367,191 +59,21 @@ namespace ROOT // ==================================================================== public: // ==================================================================== - /// default constructor - StatAction () - : m_result ( std::make_shared() ) + /// constructor + template + StatAction ( const Args& ...args ) + : m_result ( std::make_shared( args ... ) ) #if ROOT_VERSION_CODE >= ROOT_VERSION(6,22,0) , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetThreadPoolSize () ) : 1u ) #else - , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetImplicitMTPoolSize () ) : 1u ) -#endif - , m_slots ( std::max ( 1ul , this->m_N ) ) - {} - /// Move constructor - StatAction ( StatAction&& ) = default ; - /// Copy constructor is disabled - StatAction ( const StatAction& ) = delete ; - // ==================================================================== - public: - // ==================================================================== - /// initialize (empty) - void InitTask ( TTreeReader * , unsigned int ) {} ; - /// initialize (empty) - void Initialize () {} ; - /// finalize : sum over the slots - void Finalize () - { - Result_t sum { m_slots [ 0 ] } ; - for ( unsigned int i = 1 ; i < m_N ; ++i ) { sum += m_slots [ i ] ; } - *m_result = sum ; - } - /// who am I ? - std::string GetActionName() { return "StatAction" ; } - // ==================================================================== - public: - // ==================================================================== - /// The basic method: increment the counter - void Exec ( unsigned int slot , const double value ) - { m_slots [ slot % m_N ].add ( value ) ; } - // ==================================================================== - /// The basic method: increment the counter for the vector-like columns -#if ROOT_VERSION(6,22,0) <= ROOT_VERSION_CODE - template ::value, int>::type = 0> -#else - template ::value, int>::type = 0> -#endif - void Exec ( unsigned int slot , const T &vs ) - { Result_t& m = m_slots [ slot % m_N ] ; for ( const auto & v : vs ) { m.add ( v ) ; } } - // ==================================================================== - public: - // ==================================================================== - /// Get the result - std::shared_ptr GetResultPtr () const { return m_result ; } - /// get partial result for the given slot - Result_t& PartialUpdate ( unsigned int slot ) { return m_slots [ slot % m_N ] ; } - // ==================================================================== - private: - // ==================================================================== - /// the final result - const std::shared_ptr m_result {} ; - /// size of m_slots - unsigned long m_N {} ; - /// (current) results per slot - std::vector m_slots {} ; - // ==================================================================== - } ; // The end of class ROOT::Detail::RDF::StatCounter - // ====================================================================== - /** @class WStatAction - * Helper class to get weighted statitsics for columns in Daa frames - * @see Ostap::WStatEntity - * @see Ostap::DataFrame - */ - template - class WStatAction : public RActionImpl< WStatAction > - { - public: - // ==================================================================== - /// define the resutl type - using Result_t = Counter ; - // ==================================================================== - public: - // ==================================================================== - /// default constructor - WStatAction () - : m_result ( std::make_shared() ) -#if ROOT_VERSION_CODE >= ROOT_VERSION(6,22,0) - , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetThreadPoolSize () ) : 1u ) -#else - , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetImplicitMTPoolSize () ) : 1u ) -#endif - , m_slots ( std::max ( 1ul , this->m_N ) ) - {} - /// Move constructor - WStatAction ( WStatAction&& ) = default ; - /// Copy constructor is disabled - WStatAction ( const WStatAction& ) = delete ; - // ==================================================================== - public: - // ==================================================================== - /// initialize (empty) - void InitTask ( TTreeReader * , unsigned int ) {} ; - /// initialize (empty) - void Initialize () {} ; - /// finalize : sum over the slots - void Finalize () - { - Result_t sum { m_slots [ 0 ] } ; - for ( unsigned int i = 1 ; i < m_N ; ++i ) { sum += m_slots [ i ] ; } - *m_result = sum ; - } - /// who am I ? - std::string GetActionName() { return "WStatAction" ; } - // ==================================================================== - public: - // ==================================================================== - /// The basic method: increment the counter - void Exec ( unsigned int slot , const double value , const double weight ) - { m_slots [ slot % m_N ].add ( value , weight ) ; } - // ==================================================================== - /// The basic method: increment the counter for the vector-like columns -#if ROOT_VERSION(6,22,0) <= ROOT_VERSION_CODE - template ::value, int>::type = 0> -#else - template ::value, int>::type = 0> -#endif - void Exec ( unsigned int slot , const T &vs , const double weight = 1 ) - { Result_t& m = m_slots [ slot % m_N ] ; for ( const auto & v : vs ) { m.add ( v , weight ) ; } } - // ==================================================================== - /// The basic method: increment the counter for the vector-like column of weight -#if ROOT_VERSION(6,22,0) <= ROOT_VERSION_CODE - template ::value, int>::type = 0> -#else - template ::value, int>::type = 0> -#endif - void Exec ( unsigned int slot , const double value , const T &ws ) - { Result_t& e = m_slots [ slot % m_N ] ; for ( const auto & w : ws ) { e.add ( value , w ) ; } } - // ==================================================================== - public: - // ==================================================================== - /// Get the result - std::shared_ptr GetResultPtr () const { return m_result ; } - /// get partial result for the given slot - Result_t& PartialUpdate ( unsigned int slot ) { return m_slots [ slot % m_N ] ; } - // ==================================================================== - private: - // ==================================================================== - /// the final result - const std::shared_ptr m_result { } ; - /// size of m_slots - unsigned long m_N { 1 } ; - /// (current) results per slot - std::vector m_slots { 1 } ; - // ==================================================================== - } ; // The end of class ROOT::Detail::RDF::Moment_ - // ====================================================================== - - - - - - - // ====================================================================== - /** @class LegendrePoly - * Helper class to parameterise data as 1D Legendre polynomial - * @see Ostap::Math::LegendreSum - * @see Ostap::DataFrame - */ - class LegendrePoly : public RActionImpl - { - public: - // ==================================================================== - /// define the resutl type - using Result_t = Ostap::Math::LegendreSum; - // ==================================================================== - public: - // ==================================================================== - /// constructor - LegendrePoly - ( const unsigned short N , - const double xmin , - const double xmax ) ; - /// constructor from - LegendrePoly - ( const Ostap::Math::LegendreSum& ) ; + , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetImplicitMTPoolSize () ) : 1u ) +#endif + , m_slots ( this->m_N , *(this->m_result.get() ) ) + {} /// Move constructor - LegendrePoly ( LegendrePoly&& ) = default ; + StatAction ( StatAction&& ) = default ; /// Copy constructor is disabled - LegendrePoly ( const LegendrePoly& ) = delete ; + StatAction ( const StatAction& ) = delete ; // ==================================================================== public: // ==================================================================== @@ -560,33 +82,29 @@ namespace ROOT /// initialize (empty) void Initialize () {} ; /// finalize : sum over the slots - void Finalize () ; + void Finalize () + { + Result_t sum { m_slots [ 0 ] } ; + for ( unsigned int i = 1 ; i < m_N ; ++i ) { sum += m_slots [ i ] ; } + *m_result = sum ; + } /// who am I ? - std::string GetActionName() { return "LegendrePoly" ; } + std::string GetActionName() { return "StatAction" ; } // ==================================================================== public: // ==================================================================== /// The basic method: increment the counter - void Exec ( unsigned int slot , double value , double weight = 1 ) - { m_slots [ slot % m_N ].Fill ( value , weight ) ; } + void Exec ( unsigned int slot , const double value ) + { m_slots [ slot % m_N ].add ( value ) ; } // ==================================================================== - /// The basic method: increment the counter for the vector-like column of values + /// The basic method: increment the counter for the vector-like columns #if ROOT_VERSION(6,22,0) <= ROOT_VERSION_CODE template ::value, int>::type = 0> #else template ::value, int>::type = 0> #endif - void Exec ( unsigned int slot , const T &vs , const double weight = 1 ) - { Result_t& e = m_slots [ slot % m_N ] ; for ( const auto & v : vs ) { e.Fill ( v , weight ) ; } } - // ==================================================================== - /// The basic method: increment the counter for the vector-like column of weight -#if ROOT_VERSION(6,22,0) <= ROOT_VERSION_CODE - template ::value, int>::type = 0> -#else - template ::value, int>::type = 0> -#endif - void Exec ( unsigned int slot , const double value , const T &ws ) - { Result_t& e = m_slots [ slot % m_N ] ; for ( const auto & w : ws ) { e.Fill ( value , w ) ; } } + void Exec ( unsigned int slot , const T &vs ) + { Result_t& m = m_slots [ slot % m_N ] ; for ( const auto & v : vs ) { m.add ( v ) ; } } // ==================================================================== public: // ==================================================================== @@ -598,40 +116,48 @@ namespace ROOT private: // ==================================================================== /// the final result - const std::shared_ptr m_result {} ; + const std::shared_ptr m_result {} ; /// size of m_slots - unsigned long m_N { 1 } ; + unsigned long m_N {} ; /// (current) results per slot - std::vector m_slots { 1 } ; + std::vector m_slots {} ; // ==================================================================== - } ; // The end of class ROOT::Detail::RDF::LegendrePoly + } ; // The end of class ROOT::Detail::RDF::StatCounter // ====================================================================== - /** @class ChebyshePoly - * Helper class to parameterise data as 1D Chebyshev polynomial - * @see Ostap::Math::ChebyshevSum - * @see Ostap::DataFrame + /** @class WStatAction + * Helper class to get statitsics for the column in DataFrame + * using soem COUNTER class + * Requirements for COUNTER: + * - counter.add ( value , weight ) + * - counter += counter + * @see Ostap::WStatEntity + * @see Ostap::Math::WMoment_ */ - class ChebyshevPoly : public RActionImpl + template + class WStatAction : public RActionImpl< WStatAction > { public: // ==================================================================== /// define the resutl type - using Result_t = Ostap::Math::ChebyshevSum; + using Result_t = Counter ; // ==================================================================== public: // ==================================================================== - /// constructor - ChebyshevPoly - ( const unsigned short N , - const double xmin , - const double xmax ) ; - /// constructor from - ChebyshevPoly - ( const Ostap::Math::ChebyshevSum& ) ; - /// Move constructor - ChebyshevPoly ( ChebyshevPoly&& ) = default ; + /// default constructor + template + WStatAction ( const Args& ...args ) + : m_result ( std::make_shared( args ... ) ) +#if ROOT_VERSION_CODE >= ROOT_VERSION(6,22,0) + , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetThreadPoolSize () ) : 1u ) +#else + , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetImplicitMTPoolSize () ) : 1u ) +#endif + , m_slots ( this->m_N , *(this->m_result.get() ) ) + {} + /// Move constructor + WStatAction ( WStatAction&& ) = default ; /// Copy constructor is disabled - ChebyshevPoly ( const ChebyshevPoly& ) = delete ; + WStatAction ( const WStatAction& ) = delete ; // ==================================================================== public: // ==================================================================== @@ -640,24 +166,29 @@ namespace ROOT /// initialize (empty) void Initialize () {} ; /// finalize : sum over the slots - void Finalize () ; + void Finalize () + { + Result_t sum { m_slots [ 0 ] } ; + for ( unsigned int i = 1 ; i < m_N ; ++i ) { sum += m_slots [ i ] ; } + *m_result = sum ; + } /// who am I ? - std::string GetActionName() { return "ChebyshevPoly" ; } + std::string GetActionName() { return "WStatAction" ; } // ==================================================================== public: // ==================================================================== /// The basic method: increment the counter - void Exec ( unsigned int slot , double value , double weight = 1 ) - { m_slots [ slot % m_N ].Fill ( value , weight ) ; } + void Exec ( unsigned int slot , const double value , const double weight ) + { m_slots [ slot % m_N ].add ( value , weight ) ; } // ==================================================================== - /// The basic method: increment the counter for the vector-like column of values + /// The basic method: increment the counter for the vector-like columns #if ROOT_VERSION(6,22,0) <= ROOT_VERSION_CODE template ::value, int>::type = 0> #else template ::value, int>::type = 0> #endif void Exec ( unsigned int slot , const T &vs , const double weight = 1 ) - { Result_t& e = m_slots [ slot % m_N ] ; for ( const auto & v : vs ) { e.Fill ( v , weight ) ; } } + { Result_t& m = m_slots [ slot % m_N ] ; for ( const auto & v : vs ) { m.add ( v , weight ) ; } } // ==================================================================== /// The basic method: increment the counter for the vector-like column of weight #if ROOT_VERSION(6,22,0) <= ROOT_VERSION_CODE @@ -666,7 +197,7 @@ namespace ROOT template ::value, int>::type = 0> #endif void Exec ( unsigned int slot , const double value , const T &ws ) - { Result_t& e = m_slots [ slot % m_N ] ; for ( const auto & w : ws ) { e.Fill ( value , w ) ; } } + { Result_t& e = m_slots [ slot % m_N ] ; for ( const auto & w : ws ) { e.add ( value , w ) ; } } // ==================================================================== public: // ==================================================================== @@ -678,40 +209,55 @@ namespace ROOT private: // ==================================================================== /// the final result - const std::shared_ptr m_result {} ; + const std::shared_ptr m_result { } ; /// size of m_slots unsigned long m_N { 1 } ; /// (current) results per slot std::vector m_slots { 1 } ; // ==================================================================== - } ; // The end of class ROOT::Detail::RDF::LegendrePoly + } ; // The end of class ROOT::Detail::RDF::WStatAction // ====================================================================== - /** @class BernsteinPoly - * Helper class to parameterise data as 1D Bernstein polynomial - * @see Ostap::Math::Bernstein + /** @class Poly1Action + * Helper class to parameterise data as 1D polynomial + * @see Ostap::Math::LegendreSum + * @see Ostap::Math::ChebyshevSum + * @see Ostap::Math::BernsteinSum * @see Ostap::DataFrame + * Requirements for class POLYNOMIAL + * - copy constructor + * - summation : polynomial += polynomial + * - scaling : polynomial *= scale + * - fill: polynomial.Fill ( value , weight ) */ - class BernsteinPoly : public RActionImpl + template + class Poly1Action : public RActionImpl > { public: // ==================================================================== /// define the resutl type - using Result_t = Ostap::Math::Bernstein; + using Result_t = POLYNOMIAL ; // ==================================================================== public: // ==================================================================== /// constructor - BernsteinPoly - ( const unsigned short N , - const double xmin , - const double xmax ) ; - /// constructor from - BernsteinPoly - ( const Ostap::Math::Bernstein& ) ; - /// Move constructor - BernsteinPoly ( BernsteinPoly&& ) = default ; + template + Poly1Action + ( const Args& ...args ) + : m_result ( std::make_shared( args ... ) ) +#if ROOT_VERSION_CODE >= ROOT_VERSION(6,22,0) + , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetThreadPoolSize () ) : 1u ) +#else + , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetImplicitMTPoolSize () ) : 1u ) +#endif + , m_slots ( this->m_N , *(this->m_result.get() ) ) + { + (*m_result) *= 0.0 ; // reset the polynomial + for ( auto& i : m_slots ) { i *= 0.0 ; } + } + /// Move constructor + Poly1Action ( Poly1Action&& ) = default ; /// Copy constructor is disabled - BernsteinPoly ( const BernsteinPoly& ) = delete ; + Poly1Action ( const Poly1Action& ) = delete ; // ==================================================================== public: // ==================================================================== @@ -720,14 +266,20 @@ namespace ROOT /// initialize (empty) void Initialize () {} ; /// finalize : sum over the slots - void Finalize () ; + void Finalize () + { + (*m_result) *= 0.0 ; + for ( unsigned int i = 0 ; i < m_N ; ++i ) { *m_result += m_slots [ i ] ; } + } /// who am I ? - std::string GetActionName() { return "BernsteinPoly" ; } + std::string GetActionName() { return "Poly1Action" ; } // ==================================================================== public: // ==================================================================== /// The basic method: increment the counter - void Exec ( unsigned int slot , double value , double weight = 1 ) + void Exec ( unsigned int slot , + const double value , + const double weight = 1 ) { m_slots [ slot % m_N ].Fill ( value , weight ) ; } // ==================================================================== /// The basic method: increment the counter for the vector-like column of values @@ -764,127 +316,48 @@ namespace ROOT /// (current) results per slot std::vector m_slots { 1 } ; // ==================================================================== - } ; // The end of class ROOT::Detail::RDF::BernsteinPoly + } ; // The end of class ROOT::Detail::RDF::Poly1Action // ====================================================================== - /** @class LegendrePoly2 - * Helper class to parameterise data as 2D Legendre polynomial + /** @class Poly2Action + * Helper class to parameterise data as 2D polynomial * @see Ostap::Math::LegendreSum2 + * @see Ostap::Math::BErnstein2D * @see Ostap::DataFrame + * Requirements for class POLYNOMIAL + * - copy constructor + * - summation : polynomial += polynomial + * - scaling : polynomial *= scale + * - fill: polynomial.Fill ( x , y , weight ) */ - class LegendrePoly2 : public RActionImpl + template + class Poly2Action : public RActionImpl> { public: // ==================================================================== /// define the resutl type - using Result_t = Ostap::Math::LegendreSum2; - // ==================================================================== + using Result_t = POLYNOMIAL ; + // ==================================================================== public: // ==================================================================== /// constructor - LegendrePoly2 - ( const unsigned short NX , - const unsigned short NY , - const double xmin , - const double xmax , - const double ymin , - const double ymax ) ; - /// constructor from - LegendrePoly2 - ( const Ostap::Math::LegendreSum2& ) ; - /// Move constructor - LegendrePoly2 ( LegendrePoly2&& ) = default ; - /// Copy constructor is disabled - LegendrePoly2 ( const LegendrePoly2& ) = delete ; - // ==================================================================== - public: - // ==================================================================== - /// initialize (empty) - void InitTask ( TTreeReader * , unsigned int ) {} ; - /// initialize (empty) - void Initialize () {} ; - /// finalize : sum over the slots - void Finalize () ; - /// who am I ? - std::string GetActionName() { return "LegendrePoly2" ; } - // ==================================================================== - public: - // ==================================================================== - /// The basic method: increment the counter - void Exec ( unsigned int slot , double x , double y , double weight = 1 ) - { m_slots [ slot % m_N ].Fill ( x , y , weight ) ; } - // ==================================================================== - /// The basic method: increment the counter for the vector-like column of values -#if ROOT_VERSION(6,22,0) <= ROOT_VERSION_CODE - template ::value, int>::type = 0> -#else - template ::value, int>::type = 0> -#endif - void Exec ( unsigned int slot , const T &xs , const double y , const double weight = 1 ) - { Result_t& e = m_slots [ slot % m_N ] ; for ( const auto &x : xs ) { e.Fill ( x , y , weight ) ; } } - // ==================================================================== -#if ROOT_VERSION(6,22,0) <= ROOT_VERSION_CODE - template ::value, int>::type = 0> -#else - template ::value, int>::type = 0> -#endif - void Exec ( unsigned int slot , const double x , const T &ys , const double weight = 1 ) - { Result_t& e = m_slots [ slot % m_N ] ; for ( const auto &y : ys ) { e.Fill ( x , y , weight ) ; } } - // ==================================================================== -#if ROOT_VERSION(6,22,0) <= ROOT_VERSION_CODE - template ::value, int>::type = 0> + template + Poly2Action + ( const Args& ...args ) + : m_result ( std::make_shared( args ... ) ) +#if ROOT_VERSION_CODE >= ROOT_VERSION(6,22,0) + , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetThreadPoolSize () ) : 1u ) #else - template ::value, int>::type = 0> + , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetImplicitMTPoolSize () ) : 1u ) #endif - void Exec ( unsigned int slot , const double x, const double y , const T &ws ) - { Result_t& e = m_slots [ slot % m_N ] ; for ( const auto & w : ws ) { e.Fill ( x , y , w ) ; } } - // ==================================================================== - public: - // ==================================================================== - /// Get the result - std::shared_ptr GetResultPtr () const { return m_result ; } - /// get partial result for the given slot - Result_t& PartialUpdate ( unsigned int slot ) { return m_slots [ slot % m_N ] ; } - // ==================================================================== - private: - // ==================================================================== - /// the final result - const std::shared_ptr m_result {} ; - /// size of m_slots - unsigned long m_N { 1 } ; - /// (current) results per slot - std::vector m_slots { 1 } ; - // ==================================================================== - } ; // The end of class ROOT::Detail::RDF::LegendrePoly2 - // ====================================================================== - /** @class BernsteinPoly2 - * Helper class to parameterise data as 2D Bernstein polynomial - * @see Ostap::Math::Bernstein2D - * @see Ostap::DataFrame - */ - class BernsteinPoly2 : public RActionImpl - { - public: - // ==================================================================== - /// define the resutl type - using Result_t = Ostap::Math::Bernstein2D; - // ==================================================================== - public: - // ==================================================================== - /// constructor - BernsteinPoly2 - ( const unsigned short NX , - const unsigned short NY , - const double xmin , - const double xmax , - const double ymin , - const double ymax ) ; - /// constructor from - BernsteinPoly2 - ( const Ostap::Math::Bernstein2D& ) ; + , m_slots ( this->m_N , *(this->m_result.get() ) ) + { + (*m_result) *= 0.0 ; // reset the polynomial + for ( auto& i : m_slots ) { i *= 0.0 ; } + } /// Move constructor - BernsteinPoly2 ( BernsteinPoly2&& ) = default ; + Poly2Action ( Poly2Action&& ) = default ; /// Copy constructor is disabled - BernsteinPoly2 ( const BernsteinPoly2& ) = delete ; + Poly2Action ( const Poly2Action& ) = delete ; // ==================================================================== public: // ==================================================================== @@ -893,14 +366,18 @@ namespace ROOT /// initialize (empty) void Initialize () {} ; /// finalize : sum over the slots - void Finalize () ; + void Finalize () + { + (*m_result) *= 0.0 ; + for ( unsigned int i = 0 ; i < m_N ; ++i ) { *m_result += m_slots [ i ] ; } + } /// who am I ? - std::string GetActionName() { return "BernsteinPoly2" ; } + std::string GetActionName() { return "Poly2Action" ; } // ==================================================================== public: // ==================================================================== /// The basic method: increment the counter - void Exec ( unsigned int slot , double x , double y , double weight = 1 ) + void Exec ( unsigned int slot , const double x , const double y , double weight = 1 ) { m_slots [ slot % m_N ].Fill ( x , y , weight ) ; } // ==================================================================== /// The basic method: increment the counter for the vector-like column of values @@ -944,141 +421,47 @@ namespace ROOT /// (current) results per slot std::vector m_slots { 1 } ; // ==================================================================== - } ; // The end of class ROOT::Detail::RDF::BernnsteinPoly2 + } ; // The end of class ROOT::Detail::RDF::Poly2Action // ====================================================================== - /** @class LegendrePoly3 - * Helper class to parameterise data as 3D Legendre polynomial - * @see Ostap::Math::LegendreSum3 + /** @class Poly3Action + * Helper class to parameterise data as 3D polynomial + * @see Ostap::Math::LegendreSum3 + * @see Ostap::Math::Bernstein3D * @see Ostap::DataFrame + * Requirements for class POLYNOMIAL + * - copy constructor + * - summation : polynomial += polynomial + * - scaling : polynomial *= scale + * - fill: polynomial.Fill ( x , y , z , weight ) */ - class LegendrePoly3 : public RActionImpl + template + class Poly3Action : public RActionImpl> { public: // ==================================================================== /// define the resutl type - using Result_t = Ostap::Math::LegendreSum3; - // ==================================================================== - public: - // ==================================================================== - /// constructor - LegendrePoly3 - ( const unsigned short NX , - const unsigned short NY , - const unsigned short NZ , - const double xmin , - const double xmax , - const double ymin , - const double ymax , - const double zmin , - const double zmax ) ; - /// constructor from - LegendrePoly3 - ( const Ostap::Math::LegendreSum3& ) ; - /// Move constructor - LegendrePoly3 ( LegendrePoly3&& ) = default ; - /// Copy constructor is disabled - LegendrePoly3 ( const LegendrePoly3& ) = delete ; - // ==================================================================== - public: - // ==================================================================== - /// initialize (empty) - void InitTask ( TTreeReader * , unsigned int ) {} ; - /// initialize (empty) - void Initialize () {} ; - /// finalize : sum over the slots - void Finalize () ; - /// who am I ? - std::string GetActionName() { return "LegendrePoly3" ; } - // ==================================================================== + using Result_t = POLYNOMIAL ; + // ==================================================================== public: // ==================================================================== - /// The basic method: increment the counter - void Exec ( unsigned int slot , double x , double y , double z , double weight = 1 ) - { m_slots [ slot % m_N ].Fill ( x , y , z , weight ) ; } - // ==================================================================== - /// The basic method: increment the counter for the vector-like column of values -#if ROOT_VERSION(6,22,0) <= ROOT_VERSION_CODE - template ::value, int>::type = 0> -#else - template ::value, int>::type = 0> -#endif - void Exec ( unsigned int slot , const T &xs , const double y , const double z , const double weight = 1 ) - { Result_t& e = m_slots [ slot % m_N ] ; for ( const auto &x : xs ) { e.Fill ( x , y , z , weight ) ; } } - // ==================================================================== -#if ROOT_VERSION(6,22,0) <= ROOT_VERSION_CODE - template ::value, int>::type = 0> -#else - template ::value, int>::type = 0> -#endif - void Exec ( unsigned int slot , const double x , const T &ys , const double z , const double weight = 1 ) - { Result_t& e = m_slots [ slot % m_N ] ; for ( const auto &y : ys ) { e.Fill ( x , y , z , weight ) ; } } - // ==================================================================== -#if ROOT_VERSION(6,22,0) <= ROOT_VERSION_CODE - template ::value, int>::type = 0> -#else - template ::value, int>::type = 0> -#endif - void Exec ( unsigned int slot , const double x , const double y , const T &zs , const double weight = 1 ) - { Result_t& e = m_slots [ slot % m_N ] ; for ( const auto &z : zs ) { e.Fill ( x , y , z , weight ) ; } } - // ==================================================================== -#if ROOT_VERSION(6,22,0) <= ROOT_VERSION_CODE - template ::value, int>::type = 0> + template + Poly3Action + ( const Args& ...args ) + : m_result ( std::make_shared( args... ) ) +#if ROOT_VERSION_CODE >= ROOT_VERSION(6,22,0) + , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetThreadPoolSize () ) : 1u ) #else - template ::value, int>::type = 0> + , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetImplicitMTPoolSize () ) : 1u ) #endif - void Exec ( unsigned int slot , const double x, const double y , const double z , const T &ws ) - { Result_t& e = m_slots [ slot % m_N ] ; for ( const auto & w : ws ) { e.Fill ( x , y , z , w ) ; } } - // ==================================================================== - public: - // ==================================================================== - /// Get the result - std::shared_ptr GetResultPtr () const { return m_result ; } - /// get partial result for the given slot - Result_t& PartialUpdate ( unsigned int slot ) { return m_slots [ slot % m_N ] ; } - // ==================================================================== - private: - // ==================================================================== - /// the final result - const std::shared_ptr m_result {} ; - /// size of m_slots - unsigned long m_N { 1 } ; - /// (current) results per slot - std::vector m_slots { 1 } ; - // ==================================================================== - } ; // The end of class ROOT::Detail::RDF::LegendrePoly3 - // ====================================================================== - /** @class BernsteinPoly3 - * Helper class to parameterise data as 3D Bernstein polynomial - * @see Ostap::Math::Bernstein3D - * @see Ostap::DataFrame - */ - class BernsteinPoly3 : public RActionImpl - { - public: - // ==================================================================== - /// define the resutl type - using Result_t = Ostap::Math::Bernstein3D; - // ==================================================================== - public: - // ==================================================================== - /// constructor - BernsteinPoly3 - ( const unsigned short NX , - const unsigned short NY , - const unsigned short NZ , - const double xmin , - const double xmax , - const double ymin , - const double ymax , - const double zmin , - const double zmax ) ; - /// constructor from - BernsteinPoly3 - ( const Ostap::Math::Bernstein3D& ) ; + , m_slots ( this->m_N , *(this->m_result.get() ) ) + { + (*m_result) *= 0.0 ; // reset the polynomial + for ( auto& i : m_slots ) { i *= 0.0 ; } + } /// Move constructor - BernsteinPoly3 ( BernsteinPoly3&& ) = default ; + Poly3Action ( Poly3Action&& ) = default ; /// Copy constructor is disabled - BernsteinPoly3 ( const BernsteinPoly3& ) = delete ; + Poly3Action ( const Poly3Action& ) = delete ; // ==================================================================== public: // ==================================================================== @@ -1087,14 +470,22 @@ namespace ROOT /// initialize (empty) void Initialize () {} ; /// finalize : sum over the slots - void Finalize () ; + void Finalize () + { + (*m_result) *= 0.0 ; + for ( unsigned int i = 0 ; i < m_N ; ++i ) { *m_result += m_slots [ i ] ; } + } /// who am I ? - std::string GetActionName() { return "BernsteinPoly3" ; } + std::string GetActionName() { return "Poly3Action" ; } // ==================================================================== public: // ==================================================================== /// The basic method: increment the counter - void Exec ( unsigned int slot , double x , double y , double z , double weight = 1 ) + void Exec ( unsigned int slot , + const double x , + const double y , + const double z , + const double weight = 1 ) { m_slots [ slot % m_N ].Fill ( x , y , z , weight ) ; } // ==================================================================== /// The basic method: increment the counter for the vector-like column of values @@ -1145,44 +536,47 @@ namespace ROOT unsigned long m_N { 1 } ; /// (current) results per slot std::vector m_slots { 1 } ; - // ==================================================================== - } ; // The end of class ROOT::Detail::RDF::BernsteinPoly3 - // ====================================================================== - /** @class LegendrePoly4 - * Helper class to parameterise data as 4D Legendre polynomial + // ===================================================================== + } ; // The end of class ROOT::Detail::RDF::Poly3Action + // ======================================================================= + /** @class Poly4Action + * Helper class to parameterise data as 4D polynomial * @see Ostap::Math::LegendreSum4 * @see Ostap::DataFrame + * Requirements for class POLYNOMIAL + * - copy constructor + * - summation : polynomial += polynomial + * - scaling : polynomial *= scale + * - fill: polynomial.Fill ( x, y , z ,v , weight ) */ - class LegendrePoly4 : public RActionImpl + template + class Poly4Action : public RActionImpl> { public: // ==================================================================== /// define the resutl type - using Result_t = Ostap::Math::LegendreSum4; - // ==================================================================== + using Result_t = POLYNOMIAL ; + // ==================================================================== public: // ==================================================================== - /// constructor - LegendrePoly4 - ( const unsigned short NX , - const unsigned short NY , - const unsigned short NZ , - const unsigned short NU , - const double xmin , - const double xmax , - const double ymin , - const double ymax , - const double zmin , - const double zmax , - const double umin , - const double umax ) ; - /// constructor from - LegendrePoly4 - ( const Ostap::Math::LegendreSum4& ) ; + template + Poly4Action + ( const Args& ...args ) + : m_result ( std::make_shared( args ... ) ) +#if ROOT_VERSION_CODE >= ROOT_VERSION(6,22,0) + , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetThreadPoolSize () ) : 1u ) +#else + , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetImplicitMTPoolSize () ) : 1u ) +#endif + , m_slots ( this->m_N , *(this->m_result.get() ) ) + { + (*m_result) *= 0.0 ; // reset the polynomial + for ( auto& i : m_slots ) { i *= 0.0 ; } + } /// Move constructor - LegendrePoly4 ( LegendrePoly4&& ) = default ; + Poly4Action ( Poly4Action&& ) = default ; /// Copy constructor is disabled - LegendrePoly4 ( const LegendrePoly4& ) = delete ; + Poly4Action ( const Poly4Action& ) = delete ; // ==================================================================== public: // ==================================================================== @@ -1191,14 +585,23 @@ namespace ROOT /// initialize (empty) void Initialize () {} ; /// finalize : sum over the slots - void Finalize () ; + void Finalize () + { + (*m_result) *= 0.0 ; + for ( unsigned int i = 0 ; i < m_N ; ++i ) { *m_result += m_slots [ i ] ; } + } /// who am I ? - std::string GetActionName() { return "LegendrePoly4" ; } + std::string GetActionName() { return "Poly4Action" ; } // ==================================================================== public: // ==================================================================== /// The basic method: increment the counter - void Exec ( unsigned int slot , double x , double y , double z , double u , double weight = 1 ) + void Exec ( unsigned int slot , + const double x , + const double y , + const double z , + const double u , + const double weight = 1 ) { m_slots [ slot % m_N ].Fill ( x , y , z , u , weight ) ; } // ==================================================================== /// The basic method: increment the counter for the vector-like column of values @@ -1259,7 +662,7 @@ namespace ROOT /// (current) results per slot std::vector m_slots { 1 } ; // ==================================================================== - } ; // The end of class ROOT::Detail::RDF::LegendrePoly3 + } ; // The end of class ROOT::Detail::RDF::Poly4Action // ====================================================================== } // The end of namespace ROOT::Detail::RDF // ======================================================================== @@ -1273,30 +676,48 @@ namespace Ostap namespace Actions { // ======================================================================== - // - using LegendrePoly = ROOT::Detail::RDF::LegendrePoly ; - using ChebyshevPoly = ROOT::Detail::RDF::ChebyshevPoly ; - using BernsteinPoly = ROOT::Detail::RDF::BernsteinPoly ; - // - using LegendrePoly2 = ROOT::Detail::RDF::LegendrePoly2 ; - using BernsteinPoly2 = ROOT::Detail::RDF::BernsteinPoly2 ; - // - using LegendrePoly3 = ROOT::Detail::RDF::LegendrePoly3 ; - using BernsteinPoly3 = ROOT::Detail::RDF::BernsteinPoly3 ; - // - using LegendrePoly4 = ROOT::Detail::RDF::LegendrePoly4 ; - // + + template + using StatAction = ROOT::Detail::RDF::StatAction ; + template + using WStatAction = ROOT::Detail::RDF::WStatAction ; + + using StatVar = StatAction ; + using WStatVar = WStatAction ; + template - using Moment_ = ROOT::Detail::RDF::Moment_ ; + using Moment_ = StatAction > ; template - using WMoment_ = ROOT::Detail::RDF::WMoment_ ; - // - // using StatVar = ROOT::Detail::RDF::StatVar ; - // using WStatVar = ROOT::Detail::RDF::WStatVar ; - - using StatVar = ROOT::Detail::RDF::StatAction ; - using WStatVar = ROOT::Detail::RDF::WStatAction ; + using WMoment_ = WStatAction > ; + + using GeometricMean = StatAction ; + using ArithmeticMean = StatAction ; + using HarmonicMean = StatAction ; + using PowerMean = StatAction ; + using LehmerMean = StatAction ; + + template + using Poly1Action = ROOT::Detail::RDF::Poly1Action ; + template + using Poly2Action = ROOT::Detail::RDF::Poly2Action ; + template + using Poly3Action = ROOT::Detail::RDF::Poly4Action ; + template + using Poly4Action = ROOT::Detail::RDF::Poly4Action ; + + using LegendrePoly = Poly1Action ; + using ChebyshevPoly = Poly1Action ; + using BernsteinPoly = Poly1Action ; + + using LegendrePoly2 = Poly2Action ; + using BernsteinPoly2 = Poly2Action ; + + using LegendrePoly3 = Poly3Action ; + using BernsteinPoly3 = Poly3Action ; + + using LegendrePoly4 = Poly4Action ; + // ======================================================================== } diff --git a/source/include/Ostap/Moments.h b/source/include/Ostap/Moments.h index 79d2c9b0..5a292a4d 100644 --- a/source/include/Ostap/Moments.h +++ b/source/include/Ostap/Moments.h @@ -1871,9 +1871,9 @@ namespace Ostap public: // ====================================================================== /// get the min mean - inline double mean () const { return m_min ; } + inline double value () const { return m_min ; } /// get the min value - inline double min () const { return m_min ; } + inline double min () const { return m_min ; } // ====================================================================== public: // ====================================================================== @@ -1938,9 +1938,9 @@ namespace Ostap public: // ====================================================================== /// get the max value - inline double mean () const { return m_max ; } + inline double value () const { return m_max ; } /// get the max value - inline double max () const { return m_max ; } + inline double max () const { return m_max ; } // ====================================================================== public: // ====================================================================== @@ -2002,6 +2002,9 @@ namespace Ostap // ====================================================================== public: // ====================================================================== + /// get the min/max value + inline std::pair value () const + { return std::make_pair ( m_min , m_max ) ; } /// get the minvalue inline double min () const { return m_min ; } /// get the max value diff --git a/source/src/DataFrameActions.cpp b/source/src/DataFrameActions.cpp index aded40d4..0eb04efb 100644 --- a/source/src/DataFrameActions.cpp +++ b/source/src/DataFrameActions.cpp @@ -14,356 +14,12 @@ // ============================================================================ #include "OstapDataFrame.h" // ============================================================================ -/// ONLY starting from ROOT 6.16 -#if ROOT_VERSION_CODE >= ROOT_VERSION(6,16,0) -// ============================================================================ /** @file * Implementation file for objects from file Ostap/DataFrameActions.h * @date 2021-06-09 * @author Vanya Belyaev Ivan.Belyaev@itep.ru */ // ============================================================================ -// constructor -// ============================================================================ -ROOT::Detail::RDF::StatVar::StatVar () - : m_result ( std::make_shared() ) -#if ROOT_VERSION_CODE >= ROOT_VERSION(6,22,0) - , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetThreadPoolSize () ) : 1u ) -#else - , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetImplicitMTPoolSize () ) : 1u ) -#endif - , m_slots ( this->m_N ) -{} -// ============================================================================ -// Finalize -// ============================================================================ -void ROOT::Detail::RDF::StatVar::Finalize() -{ - Result_t sum { m_slots [0] } ; - for ( unsigned int i = 1 ; i < m_N ; ++i ) { sum += m_slots [ i ] ; } - *m_result = sum ; -} -// ============================================================================ -// constructor -// ============================================================================ -ROOT::Detail::RDF::WStatVar::WStatVar () - : m_result ( std::make_shared() ) -#if ROOT_VERSION_CODE >= ROOT_VERSION(6,22,0) - , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetThreadPoolSize () ) : 1u ) -#else - , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetImplicitMTPoolSize () ) : 1u ) -#endif - , m_slots ( this->m_N ) -{} -// ============================================================================ -// Finalize -// ============================================================================ -void ROOT::Detail::RDF::WStatVar::Finalize() -{ - Result_t sum { m_slots [0] } ; - for ( unsigned int i = 1 ; i < m_N ; ++i ) { sum += m_slots [ i ] ; } - *m_result = sum ; -} -// ============================================================================ -// constructor -// ============================================================================ -ROOT::Detail::RDF::LegendrePoly::LegendrePoly -( const unsigned short N , - const double xmin , - const double xmax ) - : m_result ( std::make_shared ( N , xmin , xmax ) ) -#if ROOT_VERSION_CODE >= ROOT_VERSION(6,22,0) - , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetThreadPoolSize () ) : 1u ) -#else - , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetImplicitMTPoolSize () ) : 1u ) -#endif - , m_slots ( this->m_N , *(this->m_result.get() ) ) -{} -// ============================================================================ -// constructor -// ============================================================================ -ROOT::Detail::RDF::LegendrePoly::LegendrePoly -( const Ostap::Math::LegendreSum& p ) - : LegendrePoly ( p.degree() , p.xmin () , p.xmax () ) -{} -// ============================================================================ -// Finalize -// ============================================================================ -void ROOT::Detail::RDF::LegendrePoly::Finalize() -{ - (*m_result) *= 0.0 ; - for ( unsigned int i = 0 ; i < m_N ; ++i ) { *m_result += m_slots [ i ] ; } -} -// ============================================================================ -// constructor -// ============================================================================ -ROOT::Detail::RDF::ChebyshevPoly::ChebyshevPoly -( const unsigned short N , - const double xmin , - const double xmax ) - : m_result ( std::make_shared ( N , xmin , xmax ) ) -#if ROOT_VERSION_CODE >= ROOT_VERSION(6,22,0) - , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetThreadPoolSize () ) : 1u ) -#else - , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetImplicitMTPoolSize () ) : 1u ) -#endif - , m_slots ( this->m_N , *(this->m_result.get() ) ) -{} -// ============================================================================ -// constructor -// ============================================================================ -ROOT::Detail::RDF::ChebyshevPoly::ChebyshevPoly -( const Ostap::Math::ChebyshevSum& p ) - : ChebyshevPoly ( p.degree() , p.xmin () , p.xmax () ) -{} -// ============================================================================ -// Finalize -// ============================================================================ -void ROOT::Detail::RDF::ChebyshevPoly::Finalize() -{ - (*m_result) *= 0.0 ; - for ( unsigned int i = 0 ; i < m_N ; ++i ) { *m_result += m_slots [ i ] ; } -} -// ============================================================================ -// constructor -// ============================================================================ -ROOT::Detail::RDF::BernsteinPoly::BernsteinPoly -( const unsigned short N , - const double xmin , - const double xmax ) - : m_result ( std::make_shared ( N , xmin , xmax ) ) -#if ROOT_VERSION_CODE >= ROOT_VERSION(6,22,0) - , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetThreadPoolSize () ) : 1u ) -#else - , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetImplicitMTPoolSize () ) : 1u ) -#endif - , m_slots ( this->m_N , *(this->m_result.get() ) ) -{} -// ============================================================================ -// constructor -// ============================================================================ -ROOT::Detail::RDF::BernsteinPoly::BernsteinPoly -( const Ostap::Math::Bernstein& p ) - : BernsteinPoly ( p.degree() , p.xmin () , p.xmax () ) -{} -// ============================================================================ -// Finalize -// ============================================================================ -void ROOT::Detail::RDF::BernsteinPoly::Finalize() -{ - (*m_result) *= 0.0 ; - for ( unsigned int i = 0 ; i < m_N ; ++i ) { *m_result += m_slots [ i ] ; } -} -// ============================================================================ -// constructor -// ============================================================================ -ROOT::Detail::RDF::LegendrePoly2::LegendrePoly2 -( const unsigned short NX , - const unsigned short NY , - const double xmin , - const double xmax , - const double ymin , - const double ymax ) - : m_result ( std::make_shared ( NX , NY , xmin , xmax , ymin , ymax ) ) -#if ROOT_VERSION_CODE >= ROOT_VERSION(6,22,0) - , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetThreadPoolSize () ) : 1u ) -#else - , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetImplicitMTPoolSize () ) : 1u ) -#endif - , m_slots ( this->m_N , *(this->m_result.get() ) ) -{} -// ============================================================================ -// constructor -// ============================================================================ -ROOT::Detail::RDF::LegendrePoly2::LegendrePoly2 -( const Ostap::Math::LegendreSum2& p ) - : LegendrePoly2 ( p.nX () , p.nY () , - p.xmin () , p.xmax () , - p.ymin () , p.ymax () ) -{} -// ============================================================================ -// Finalize -// ============================================================================ -void ROOT::Detail::RDF::LegendrePoly2::Finalize() -{ - (*m_result) *= 0.0 ; - for ( unsigned int i = 0 ; i < m_N ; ++i ) { *m_result += m_slots [ i ] ; } -} -// ============================================================================ -// constructor -// ============================================================================ -ROOT::Detail::RDF::BernsteinPoly2::BernsteinPoly2 -( const unsigned short NX , - const unsigned short NY , - const double xmin , - const double xmax , - const double ymin , - const double ymax ) - : m_result ( std::make_shared ( NX , NY , xmin , xmax , ymin , ymax ) ) -#if ROOT_VERSION_CODE >= ROOT_VERSION(6,22,0) - , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetThreadPoolSize () ) : 1u ) -#else - , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetImplicitMTPoolSize () ) : 1u ) -#endif - , m_slots ( this->m_N , *(this->m_result.get() ) ) -{} -// ============================================================================ -// constructor -// ============================================================================ -ROOT::Detail::RDF::BernsteinPoly2::BernsteinPoly2 -( const Ostap::Math::Bernstein2D& p ) - : BernsteinPoly2 ( p.nX () , p.nY () , - p.xmin () , p.xmax () , - p.ymin () , p.ymax () ) -{} -// ============================================================================ -// Finalize -// ============================================================================ -void ROOT::Detail::RDF::BernsteinPoly2::Finalize() -{ - (*m_result) *= 0.0 ; - for ( unsigned int i = 0 ; i < m_N ; ++i ) { *m_result += m_slots [ i ] ; } -} -// ============================================================================ -// constructor -// ============================================================================ -ROOT::Detail::RDF::LegendrePoly3::LegendrePoly3 -( const unsigned short NX , - const unsigned short NY , - const unsigned short NZ , - const double xmin , - const double xmax , - const double ymin , - const double ymax , - const double zmin , - const double zmax ) - : m_result ( std::make_shared ( NX , NY , NZ , - xmin , xmax , - ymin , ymax , - zmin , zmax ) ) -#if ROOT_VERSION_CODE >= ROOT_VERSION(6,22,0) - , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetThreadPoolSize () ) : 1u ) -#else - , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetImplicitMTPoolSize () ) : 1u ) -#endif - , m_slots ( this->m_N , *(this->m_result.get() ) ) -{} -// ============================================================================ -// constructor -// ============================================================================ -ROOT::Detail::RDF::LegendrePoly3::LegendrePoly3 -( const Ostap::Math::LegendreSum3& p ) - : LegendrePoly3 ( p.nX () , p.nY () , p.nZ () , - p.xmin () , p.xmax () , - p.ymin () , p.ymax () , - p.zmin () , p.zmax () ) -{} -// ============================================================================ -// Finalize -// ============================================================================ -void ROOT::Detail::RDF::LegendrePoly3::Finalize() -{ - (*m_result) *= 0.0 ; - for ( unsigned int i = 0 ; i < m_N ; ++i ) { *m_result += m_slots [ i ] ; } -} -// ============================================================================ -// constructor -// ============================================================================ -ROOT::Detail::RDF::BernsteinPoly3::BernsteinPoly3 -( const unsigned short NX , - const unsigned short NY , - const unsigned short NZ , - const double xmin , - const double xmax , - const double ymin , - const double ymax , - const double zmin , - const double zmax ) - : m_result ( std::make_shared ( NX , NY , NZ , - xmin , xmax , - ymin , ymax , - zmin , zmax ) ) -#if ROOT_VERSION_CODE >= ROOT_VERSION(6,22,0) - , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetThreadPoolSize () ) : 1u ) -#else - , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetImplicitMTPoolSize () ) : 1u ) -#endif - , m_slots ( this->m_N , *(this->m_result.get() ) ) -{} -// ============================================================================ -// constructor -// ============================================================================ -ROOT::Detail::RDF::BernsteinPoly3::BernsteinPoly3 -( const Ostap::Math::Bernstein3D& p ) - : BernsteinPoly3 ( p.nX () , p.nY () , p.nZ() , - p.xmin () , p.xmax () , - p.ymin () , p.ymax () , - p.zmin () , p.zmax () ) -{} -// ============================================================================ -// Finalize -// ============================================================================ -void ROOT::Detail::RDF::BernsteinPoly3::Finalize() -{ - (*m_result) *= 0.0 ; - for ( unsigned int i = 0 ; i < m_N ; ++i ) { *m_result += m_slots [ i ] ; } -} -// ============================================================================ -// constructor -// ============================================================================ -ROOT::Detail::RDF::LegendrePoly4::LegendrePoly4 -( const unsigned short NX , - const unsigned short NY , - const unsigned short NZ , - const unsigned short NU , - const double xmin , - const double xmax , - const double ymin , - const double ymax , - const double zmin , - const double zmax , - const double umin , - const double umax ) - : m_result ( std::make_shared ( NX , NY , NZ , NU , - xmin , xmax , - ymin , ymax , - zmin , zmax , - umin , umax ) ) -#if ROOT_VERSION_CODE >= ROOT_VERSION(6,22,0) - , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetThreadPoolSize () ) : 1u ) -#else - , m_N ( ROOT::IsImplicitMTEnabled() ? std::max ( 1u , ROOT::GetImplicitMTPoolSize () ) : 1u ) -#endif - , m_slots ( this->m_N , *(this->m_result.get() ) ) -{} -// ============================================================================ -// constructor -// ============================================================================ -ROOT::Detail::RDF::LegendrePoly4::LegendrePoly4 -( const Ostap::Math::LegendreSum4& p ) - : LegendrePoly4 ( p.nX () , p.nY () , - p.nZ () , p.nU () , - p.xmin () , p.xmax () , - p.ymin () , p.ymax () , - p.zmin () , p.zmax () , - p.umin () , p.umax () ) -{} -// ============================================================================ -// Finalize -// ============================================================================ -void ROOT::Detail::RDF::LegendrePoly4::Finalize() -{ - (*m_result) *= 0.0 ; - for ( unsigned int i = 0 ; i < m_N ; ++i ) { *m_result += m_slots [ i ] ; } -} - - - - - -// ============================================================================ -#endif // #if ROOT_VERSION_CODE >= ROOT_VERSION(6,16,0) -// ============================================================================ // ============================================================================ // The END