From ba74dcde5815b104518194f04834d4b358fa7924 Mon Sep 17 00:00:00 2001 From: pdigiglio Date: Tue, 23 Aug 2016 19:10:38 +0200 Subject: [PATCH 1/9] [InvariantMassBinning] first version of InvariantMassBinning --- include/InvariantMassBinning.h | 54 +++++++++++++++++++++++++++ src/CMakeLists.txt | 1 + src/InvariantMassBinning.cxx | 68 ++++++++++++++++++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 include/InvariantMassBinning.h create mode 100644 src/InvariantMassBinning.cxx diff --git a/include/InvariantMassBinning.h b/include/InvariantMassBinning.h new file mode 100644 index 00000000..4339b529 --- /dev/null +++ b/include/InvariantMassBinning.h @@ -0,0 +1,54 @@ +/* YAP - Yet another PWA toolkit + Copyright 2015, Technische Universitaet Muenchen, + Authors: Daniel Greenwald, Johannes Rauch + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +/// \file + + +#ifndef yap_InvariantMassBinning_h +#define yap_InvariantMassBinning_h + +#include "fwd/CachedValue.h" + +#include "StaticDataAccessor.h" + +namespace yap { + +/// \class InvariantMassBinning +/// \author Paolo Di Giglio +class InvariantMassBinning : public StaticDataAccessor +{ +public: + /// Constructor. + /// The #ParticleCombinationEqualTo is defaulted to #equal_by_orderless_content. + explicit InvariantMassBinning(Model& m, const std::vector& bins); + virtual void calculate(DataPoint& d, StatusManager& sm) const override; +private: + /// Partitioning of the mass axis. + /// It contains the \f$n\f$ lower bounds of the bins plus + /// the upper bound of the last bin: + /// \f[ + /// [m_0,m_1) \cup [m_1,m_2) \dots [m_{n-1}, m_n). + /// \f] + const std::vector Bins_; + + std::shared_ptr BinNumber_; +}; + +} + +#endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 40258c21..cd548575 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -23,6 +23,7 @@ set(YAP_SOURCES HelicityAngles.cxx HelicityFormalism.cxx ImportanceSampler.cxx + InvariantMassBinning.cxx Integrator.cxx MassRange.cxx MassShape.cxx diff --git a/src/InvariantMassBinning.cxx b/src/InvariantMassBinning.cxx new file mode 100644 index 00000000..855cc3aa --- /dev/null +++ b/src/InvariantMassBinning.cxx @@ -0,0 +1,68 @@ +#include "InvariantMassBinning.h" + +#include "CachedValue.h" +#include "CalculationStatus.h" +#include "Exceptions.h" +#include "FourMomenta.h" +#include "Model.h" +#include "ParticleCombination.h" +#include "StatusManager.h" + +#include +#include + +namespace yap { + +//------------------------- +InvariantMassBinning::InvariantMassBinning(Model& m, const std::vector& bins) : + StaticDataAccessor(m, equal_by_orderless_content), + Bins_(bins), + BinNumber_(RealCachedValue::create(*this)) +{ + if (Bins_.size() < 2) + throw exceptions::Exception("At least two bins must be specified", + "InvariantMassBinning::InvariantMassBinning"); + + // use std::less_equal so that if two elements are the same, std::is_sorted + // will return false + if (!std::is_sorted(Bins_.cbegin(), Bins_.cend(), std::less_equal())) + throw exceptions::Exception("Elements of the vector are not monotonically increasing", + "InvariantMassBinning::InvariantMassBinning"); +} + +//------------------------- +void InvariantMassBinning::calculate(DataPoint& d, StatusManager& sm) const +{ + // set all bins to uncalculated + sm.set(*BinNumber_, CalculationStatus::uncalculated); + + // loop over particle combinations -> indices + for (auto& pc_i : symmetrizationIndices()) { + // check if calculation is necessary + if (sm.status(*BinNumber_, pc_i.second ) == CalculationStatus::uncalculated) { + auto invariant_mass = model()->fourMomenta()->m(d, pc_i.first); + + // get the first lower bound that is greater than the invariant mass + auto bin = std::upper_bound(Bins_.cbegin(), Bins_.cend(), invariant_mass); + + // check if the value above the upper limit + if (bin == Bins_.cend()) + throw exceptions::Exception("Mass is above the upper bin", + "InvariantMassBinning::calculate"); + // check if the value below the lower limit + if (bin == Bins_.cbegin()) + throw exceptions::Exception("Mass is below the lower bin", + "InvariantMassBinning::calculate"); + + // if the previous checks passed, set bin to the actual value + // of the containing bin (i.e. bin is the last value in the vector + // that is not greater than invariant_mass); + --bin; + + // set the value into the DataPoint + BinNumber_->setValue(std::distance(Bins_.cbegin(), bin), d, pc_i.second, sm); + } + } +} + +} From f4777c91819691b524bf8c50ef3768090956bffc Mon Sep 17 00:00:00 2001 From: pdigiglio Date: Wed, 24 Aug 2016 13:41:12 +0200 Subject: [PATCH 2/9] improve documentation and format --- include/InvariantMassBinning.h | 38 ++++++++++++------- src/InvariantMassBinning.cxx | 68 +++++++++++++++++----------------- 2 files changed, 58 insertions(+), 48 deletions(-) diff --git a/include/InvariantMassBinning.h b/include/InvariantMassBinning.h index 4339b529..a3effc36 100644 --- a/include/InvariantMassBinning.h +++ b/include/InvariantMassBinning.h @@ -29,24 +29,34 @@ namespace yap { /// \class InvariantMassBinning -/// \author Paolo Di Giglio +/// \author Paolo Di Giglio. +/// Partitions the invariant-mass range in bins, whose (constant) lower bonuds +/// are stored in the class. Offers a function to calculate which bin the +/// invariant mass of a #ParticleCombination lies in. class InvariantMassBinning : public StaticDataAccessor { public: - /// Constructor. - /// The #ParticleCombinationEqualTo is defaulted to #equal_by_orderless_content. - explicit InvariantMassBinning(Model& m, const std::vector& bins); - virtual void calculate(DataPoint& d, StatusManager& sm) const override; + /// Constructor. + /// The #ParticleCombinationEqualTo is defaulted to #equal_by_orderless_content. + explicit InvariantMassBinning(Model& m, const std::vector& bins); + + /// Calculate which bin the invatiant mass of the #ParticleCombination's + /// belong to. + /// \param d The #DataPoint to calculate into. + /// \param sm The #StatusManager to update. + virtual void calculate(DataPoint& d, StatusManager& sm) const override; private: - /// Partitioning of the mass axis. - /// It contains the \f$n\f$ lower bounds of the bins plus - /// the upper bound of the last bin: - /// \f[ - /// [m_0,m_1) \cup [m_1,m_2) \dots [m_{n-1}, m_n). - /// \f] - const std::vector Bins_; - - std::shared_ptr BinNumber_; + + /// Partitioning of the mass axis. + /// It contains the \f$n\f$ lower bounds of the bins plus + /// the upper bound of the last bin: + /// \f[ + /// [m_0,m_1) \cup [m_1,m_2) \dots [m_{n-1}, m_n). + /// \f] + const std::vector Bins_; + + /// The bin the masses of the #ParticleCombination's belong to. + std::shared_ptr BinNumber_; }; } diff --git a/src/InvariantMassBinning.cxx b/src/InvariantMassBinning.cxx index 855cc3aa..438201be 100644 --- a/src/InvariantMassBinning.cxx +++ b/src/InvariantMassBinning.cxx @@ -15,54 +15,54 @@ namespace yap { //------------------------- InvariantMassBinning::InvariantMassBinning(Model& m, const std::vector& bins) : - StaticDataAccessor(m, equal_by_orderless_content), - Bins_(bins), - BinNumber_(RealCachedValue::create(*this)) + StaticDataAccessor(m, equal_by_orderless_content), + Bins_(bins), + BinNumber_(RealCachedValue::create(*this)) { - if (Bins_.size() < 2) - throw exceptions::Exception("At least two bins must be specified", + if (Bins_.size() < 2) + throw exceptions::Exception("At least two bins must be specified", "InvariantMassBinning::InvariantMassBinning"); - // use std::less_equal so that if two elements are the same, std::is_sorted - // will return false - if (!std::is_sorted(Bins_.cbegin(), Bins_.cend(), std::less_equal())) - throw exceptions::Exception("Elements of the vector are not monotonically increasing", + // use std::less_equal so that if two elements are the same, std::is_sorted + // will return false + if (!std::is_sorted(Bins_.cbegin(), Bins_.cend(), std::less_equal())) + throw exceptions::Exception("Elements of the vector are not monotonically increasing", "InvariantMassBinning::InvariantMassBinning"); } //------------------------- void InvariantMassBinning::calculate(DataPoint& d, StatusManager& sm) const { - // set all bins to uncalculated - sm.set(*BinNumber_, CalculationStatus::uncalculated); + // set all bins to uncalculated + sm.set(*BinNumber_, CalculationStatus::uncalculated); - // loop over particle combinations -> indices - for (auto& pc_i : symmetrizationIndices()) { - // check if calculation is necessary - if (sm.status(*BinNumber_, pc_i.second ) == CalculationStatus::uncalculated) { - auto invariant_mass = model()->fourMomenta()->m(d, pc_i.first); + // loop over particle combinations -> indices + for (auto& pc_i : symmetrizationIndices()) { + // check if calculation is necessary + if (sm.status(*BinNumber_, pc_i.second ) == CalculationStatus::uncalculated) { + auto invariant_mass = model()->fourMomenta()->m(d, pc_i.first); - // get the first lower bound that is greater than the invariant mass - auto bin = std::upper_bound(Bins_.cbegin(), Bins_.cend(), invariant_mass); + // get the first lower bound that is greater than the invariant mass + auto bin = std::upper_bound(Bins_.cbegin(), Bins_.cend(), invariant_mass); - // check if the value above the upper limit - if (bin == Bins_.cend()) - throw exceptions::Exception("Mass is above the upper bin", - "InvariantMassBinning::calculate"); - // check if the value below the lower limit - if (bin == Bins_.cbegin()) - throw exceptions::Exception("Mass is below the lower bin", - "InvariantMassBinning::calculate"); + // check if the value above the upper limit + if (bin == Bins_.cend()) + throw exceptions::Exception("Mass is above the upper bin", + "InvariantMassBinning::calculate"); + // check if the value below the lower limit + if (bin == Bins_.cbegin()) + throw exceptions::Exception("Mass is below the lower bin", + "InvariantMassBinning::calculate"); - // if the previous checks passed, set bin to the actual value - // of the containing bin (i.e. bin is the last value in the vector - // that is not greater than invariant_mass); - --bin; + // if the previous checks passed, set bin to the actual value + // of the containing bin (i.e. bin is the last value in the vector + // that is not greater than invariant_mass); + --bin; - // set the value into the DataPoint - BinNumber_->setValue(std::distance(Bins_.cbegin(), bin), d, pc_i.second, sm); - } - } + // set the value into the DataPoint + BinNumber_->setValue(std::distance(Bins_.cbegin(), bin), d, pc_i.second, sm); + } + } } } From 2516749e1e11cbd0687ec072afdc7eadaca3e0a5 Mon Sep 17 00:00:00 2001 From: pdigiglio Date: Wed, 24 Aug 2016 17:01:32 +0200 Subject: [PATCH 3/9] [InvariantMassBinning] improve documentation; +lowEdges, +bin, +is_underflow, +is_overflow --- include/InvariantMassBinning.h | 71 ++++++++++++++++++++++-------- include/fwd/InvariantMassBinning.h | 32 ++++++++++++++ src/InvariantMassBinning.cxx | 36 ++++++--------- 3 files changed, 98 insertions(+), 41 deletions(-) create mode 100644 include/fwd/InvariantMassBinning.h diff --git a/include/InvariantMassBinning.h b/include/InvariantMassBinning.h index a3effc36..c8324e08 100644 --- a/include/InvariantMassBinning.h +++ b/include/InvariantMassBinning.h @@ -22,43 +22,78 @@ #ifndef yap_InvariantMassBinning_h #define yap_InvariantMassBinning_h +#include "fwd/InvariantMassBinning.h" + #include "fwd/CachedValue.h" +#include "fwd/DataPoint.h" +#include "fwd/Model.h" +#include "fwd/StatusManager.h" #include "StaticDataAccessor.h" +#include +#include + namespace yap { -/// \class InvariantMassBinning +/// \brief Partitions the invariant-mass range in \f$n\f$ bins, whose (constant) lower +/// edges are stored in BinLowEdges_. +/// \details BinLowEdges_ is a \f$(n+1)\f$-element vector whose entries partition the +/// axis in an closed-open fashion as follows: +/// \f[ +/// [m_0,m_1) \cup [m_1,m_2) \dots [m_{n-1}, m_n). +/// \f] +/// InvariantMassBinning has a function to calculate which bin the invariant mass of a +/// ParticleCombination lies in: +/// * In case of underflow (i.e. \f$m < m_0\f$), the bin will be set to `-1`. +/// * In case of overflow (i.e. \f$m > m_n\f$), the bin will be set to `n`. +/// /// \author Paolo Di Giglio. -/// Partitions the invariant-mass range in bins, whose (constant) lower bonuds -/// are stored in the class. Offers a function to calculate which bin the -/// invariant mass of a #ParticleCombination lies in. class InvariantMassBinning : public StaticDataAccessor { public: /// Constructor. - /// The #ParticleCombinationEqualTo is defaulted to #equal_by_orderless_content. + /// \param m The owning Model. + /// \param bins The user-specified partition of the invariant-mass axis. explicit InvariantMassBinning(Model& m, const std::vector& bins); - /// Calculate which bin the invatiant mass of the #ParticleCombination's - /// belong to. - /// \param d The #DataPoint to calculate into. - /// \param sm The #StatusManager to update. + /// \brief Calculate which bin the invatiant mass of the + /// ParticleCombination's belong to. + /// \details The class description explains which bin value is used + /// in case of overflow or underflow. + /// \param d The DataPoint to calculate into. + /// \param sm The StatusManager to update. virtual void calculate(DataPoint& d, StatusManager& sm) const override; + + /// Access the partition. + const std::vector& lowEdges() const + { return BinLowEdges_; } + + /// Access the bin number. + /// \todo Enforce `const`ness on the pointed-to value!! + const std::shared_ptr& bin() const + { return Bin_; } + private: - /// Partitioning of the mass axis. - /// It contains the \f$n\f$ lower bounds of the bins plus - /// the upper bound of the last bin: - /// \f[ - /// [m_0,m_1) \cup [m_1,m_2) \dots [m_{n-1}, m_n). - /// \f] - const std::vector Bins_; + /// Lower edges of the bins. + const std::vector BinLowEdges_; - /// The bin the masses of the #ParticleCombination's belong to. - std::shared_ptr BinNumber_; + /// The bin the masses of the ParticleCombination's belong to. + std::shared_ptr Bin_; }; +/// Check if n corresponds to an underflow value. +/// \param n The index to check agains the bin underflow value. +inline const bool is_underflow(int n) +{ return n < 0; } + +/// Check if n corresponds to an overflow value. +/// \param n The index to check agains the bin overflow value. +/// \param B The partition the bin overflow value has to be evaluated from. +inline const bool is_overflow(int n, const InvariantMassBinning& B) +{ return n >= static_cast(B.lowEdges().size()) - 1; } + } #endif diff --git a/include/fwd/InvariantMassBinning.h b/include/fwd/InvariantMassBinning.h new file mode 100644 index 00000000..e299f4ba --- /dev/null +++ b/include/fwd/InvariantMassBinning.h @@ -0,0 +1,32 @@ +/* YAP - Yet another PWA toolkit + Copyright 2015, Technische Universitaet Muenchen, + Authors: Daniel Greenwald, Johannes Rauch + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +/// \file +/// \author Paolo Di Giglio. +/// Contains forward declarations only. + +#ifndef yap_InvariantMassBinningFwd_h +#define yap_InvariantMassBinningFwd_h + +namespace yap { + +class InvariantMassBinning; + +} + +#endif diff --git a/src/InvariantMassBinning.cxx b/src/InvariantMassBinning.cxx index 438201be..705bbbc5 100644 --- a/src/InvariantMassBinning.cxx +++ b/src/InvariantMassBinning.cxx @@ -2,6 +2,7 @@ #include "CachedValue.h" #include "CalculationStatus.h" +#include "DataPoint.h" #include "Exceptions.h" #include "FourMomenta.h" #include "Model.h" @@ -10,22 +11,23 @@ #include #include +#include namespace yap { //------------------------- InvariantMassBinning::InvariantMassBinning(Model& m, const std::vector& bins) : StaticDataAccessor(m, equal_by_orderless_content), - Bins_(bins), - BinNumber_(RealCachedValue::create(*this)) + BinLowEdges_(bins), + Bin_(RealCachedValue::create(*this)) { - if (Bins_.size() < 2) - throw exceptions::Exception("At least two bins must be specified", + if (BinLowEdges_.size() < 2) + throw exceptions::Exception("At least two bin edges must be specified", "InvariantMassBinning::InvariantMassBinning"); // use std::less_equal so that if two elements are the same, std::is_sorted // will return false - if (!std::is_sorted(Bins_.cbegin(), Bins_.cend(), std::less_equal())) + if (!std::is_sorted(BinLowEdges_.cbegin(), BinLowEdges_.cend(), std::less_equal())) throw exceptions::Exception("Elements of the vector are not monotonically increasing", "InvariantMassBinning::InvariantMassBinning"); } @@ -34,33 +36,21 @@ InvariantMassBinning::InvariantMassBinning(Model& m, const std::vector& void InvariantMassBinning::calculate(DataPoint& d, StatusManager& sm) const { // set all bins to uncalculated - sm.set(*BinNumber_, CalculationStatus::uncalculated); + sm.set(*Bin_, CalculationStatus::uncalculated); // loop over particle combinations -> indices for (auto& pc_i : symmetrizationIndices()) { // check if calculation is necessary - if (sm.status(*BinNumber_, pc_i.second ) == CalculationStatus::uncalculated) { + if (sm.status(*Bin_, pc_i.second ) == CalculationStatus::uncalculated) { auto invariant_mass = model()->fourMomenta()->m(d, pc_i.first); // get the first lower bound that is greater than the invariant mass - auto bin = std::upper_bound(Bins_.cbegin(), Bins_.cend(), invariant_mass); - - // check if the value above the upper limit - if (bin == Bins_.cend()) - throw exceptions::Exception("Mass is above the upper bin", - "InvariantMassBinning::calculate"); - // check if the value below the lower limit - if (bin == Bins_.cbegin()) - throw exceptions::Exception("Mass is below the lower bin", - "InvariantMassBinning::calculate"); - - // if the previous checks passed, set bin to the actual value - // of the containing bin (i.e. bin is the last value in the vector - // that is not greater than invariant_mass); - --bin; + auto bin = std::upper_bound(BinLowEdges_.cbegin(), BinLowEdges_.cend(), invariant_mass); // set the value into the DataPoint - BinNumber_->setValue(std::distance(Bins_.cbegin(), bin), d, pc_i.second, sm); + // NOTE: std::distance() - 1 accounts for the fact that the actual bin value + // is the one preceding the one that is found above + Bin_->setValue(std::distance(BinLowEdges_.cbegin(), bin) - 1, d, pc_i.second, sm); } } } From f90a9a7afacb631a747cb3bc0ab9bed4c420a97e Mon Sep 17 00:00:00 2001 From: pdigiglio Date: Wed, 24 Aug 2016 17:12:17 +0200 Subject: [PATCH 4/9] [InvariantMassBinning] little clarification on BinLowEdges_ indices --- include/InvariantMassBinning.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/InvariantMassBinning.h b/include/InvariantMassBinning.h index c8324e08..b48b29a3 100644 --- a/include/InvariantMassBinning.h +++ b/include/InvariantMassBinning.h @@ -37,12 +37,13 @@ namespace yap { /// \brief Partitions the invariant-mass range in \f$n\f$ bins, whose (constant) lower -/// edges are stored in BinLowEdges_. -/// \details BinLowEdges_ is a \f$(n+1)\f$-element vector whose entries partition the +/// edges are stored in `BinLowEdges_`. +/// \details `BinLowEdges_` is a \f$(n+1)\f$-element vector whose entries partition the /// axis in an closed-open fashion as follows: /// \f[ -/// [m_0,m_1) \cup [m_1,m_2) \dots [m_{n-1}, m_n). +/// (-\infty, m_0) \cup [m_0,m_1) \cup [m_1,m_2) \dots [m_{n-1}, m_n) \cup [m_n, +\infty). /// \f] +/// The `0`-th value of `BinLowEdges_` corresponds to \f$m_0\f$; the `n`-th to \f$m_n\f$. /// InvariantMassBinning has a function to calculate which bin the invariant mass of a /// ParticleCombination lies in: /// * In case of underflow (i.e. \f$m < m_0\f$), the bin will be set to `-1`. From 85afcfe00e763fc9b5e4a8afde49278880e17475 Mon Sep 17 00:00:00 2001 From: pdigiglio Date: Thu, 25 Aug 2016 15:55:43 +0200 Subject: [PATCH 5/9] alphabetically sort source files entries --- src/CMakeLists.txt | 102 ++++++++++++++++++++++----------------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cd548575..b6b2b610 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,53 +1,53 @@ set(INCLUDE_DIRECTORIES - ${YAP_SOURCE_DIR}/include) + ${YAP_SOURCE_DIR}/include) include_directories(${INCLUDE_DIRECTORIES}) set(YAP_SOURCES - BlattWeisskopf.cxx - BreitWigner.cxx - CachedValue.cxx - ClebschGordan.cxx - DataAccessor.cxx - DataPartition.cxx - DataPoint.cxx - DataSet.cxx - DecayChannel.cxx - DecayingParticle.cxx - DecayTree.cxx - DecayTreeVectorIntegral.cxx - Filters.cxx - FinalStateParticle.cxx - Flatte.cxx - FreeAmplitude.cxx - FourMomenta.cxx - HelicityAngles.cxx - HelicityFormalism.cxx - ImportanceSampler.cxx - InvariantMassBinning.cxx - Integrator.cxx - MassRange.cxx - MassShape.cxx - MassShapeWithNominalMass.cxx - MeasuredBreakupMomenta.cxx - Model.cxx - ModelIntegral.cxx - Parameter.cxx - ParticleCombination.cxx - ParticleCombinationCache.cxx - Particle.cxx - ParticleFactory.cxx - PDL.cxx - PoleMass.cxx - QuantumNumbers.cxx - RecalculableDataAccessor.cxx - RelativisticBreitWigner.cxx - Resonance.cxx - SpinAmplitude.cxx - SpinAmplitudeCache.cxx - StaticDataAccessor.cxx - StatusManager.cxx - WignerD.cxx - ZemachFormalism.cxx + BlattWeisskopf.cxx + BreitWigner.cxx + CachedValue.cxx + ClebschGordan.cxx + DataAccessor.cxx + DataPartition.cxx + DataPoint.cxx + DataSet.cxx + DecayChannel.cxx + DecayTree.cxx + DecayTreeVectorIntegral.cxx + DecayingParticle.cxx + Filters.cxx + FinalStateParticle.cxx + Flatte.cxx + FourMomenta.cxx + FreeAmplitude.cxx + HelicityAngles.cxx + HelicityFormalism.cxx + ImportanceSampler.cxx + Integrator.cxx + InvariantMassBinning.cxx + MassRange.cxx + MassShape.cxx + MassShapeWithNominalMass.cxx + MeasuredBreakupMomenta.cxx + Model.cxx + ModelIntegral.cxx + PDL.cxx + Parameter.cxx + Particle.cxx + ParticleCombination.cxx + ParticleCombinationCache.cxx + ParticleFactory.cxx + PoleMass.cxx + QuantumNumbers.cxx + RecalculableDataAccessor.cxx + RelativisticBreitWigner.cxx + Resonance.cxx + SpinAmplitude.cxx + SpinAmplitudeCache.cxx + StaticDataAccessor.cxx + StatusManager.cxx + WignerD.cxx + ZemachFormalism.cxx ) add_library(YAP SHARED ${YAP_SOURCES}) @@ -56,21 +56,21 @@ add_library(YAP SHARED ${YAP_SOURCES}) # cmake -DLIBRARY_OUTPUT_DIRECTORY:PATH= # otherwise, default LD_LIBRARY_PATH if(NOT DEFINED LIBRARY_OUTPUT_DIRECTORY) - set(LIBRARY_OUTPUT_DIRECTORY ${YAP_SOURCE_DIR}/lib/${CMAKE_BUILD_TYPE}) + set(LIBRARY_OUTPUT_DIRECTORY ${YAP_SOURCE_DIR}/lib/${CMAKE_BUILD_TYPE}) endif() if(NOT DEFINED INCLUDE_OUTPUT_DIRECTORY) - set(INCLUDE_OUTPUT_DIRECTORY ${YAP_SOURCE_DIR}/include/YAP) + set(INCLUDE_OUTPUT_DIRECTORY ${YAP_SOURCE_DIR}/include/YAP) endif() install(TARGETS YAP LIBRARY DESTINATION ${LIBRARY_OUTPUT_DIRECTORY}) # Matches all the headers in ${YAPDID}/include and its subdirs file(GLOB_RECURSE - INSTALL_INCLUDES ${YAP_SOURCE_DIR}/include/*.h) + INSTALL_INCLUDES ${YAP_SOURCE_DIR}/include/*.h) #message(STATUS "${INSTALL_INCLUDES}") #install(FILE ${INSTALL_INCLUDES} -# DESTINATION ${INCLUDE_OUTPUT_DIRECTORY} -# ) +# DESTINATION ${INCLUDE_OUTPUT_DIRECTORY} +# ) From 69ead625771dd1c4a08bae54b1b0ab71fa479a2f Mon Sep 17 00:00:00 2001 From: pdigiglio Date: Thu, 25 Aug 2016 15:56:41 +0200 Subject: [PATCH 6/9] meaningful name for constructor parameter (bins -> low_edges) --- include/InvariantMassBinning.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/InvariantMassBinning.h b/include/InvariantMassBinning.h index b48b29a3..2a01ded7 100644 --- a/include/InvariantMassBinning.h +++ b/include/InvariantMassBinning.h @@ -54,9 +54,9 @@ class InvariantMassBinning : public StaticDataAccessor { public: /// Constructor. - /// \param m The owning Model. - /// \param bins The user-specified partition of the invariant-mass axis. - explicit InvariantMassBinning(Model& m, const std::vector& bins); + /// \param m The owning Model. + /// \param low_edges Low edges of the bins; the last element is the upper edge of the las bin. + explicit InvariantMassBinning(Model& m, const std::vector& low_edges); /// \brief Calculate which bin the invatiant mass of the /// ParticleCombination's belong to. From 204306cdf04c6261b70cce5a35c90623cd815b34 Mon Sep 17 00:00:00 2001 From: pdigiglio Date: Thu, 25 Aug 2016 15:58:32 +0200 Subject: [PATCH 7/9] fix documentation typo --- include/InvariantMassBinning.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/InvariantMassBinning.h b/include/InvariantMassBinning.h index 2a01ded7..6cf11483 100644 --- a/include/InvariantMassBinning.h +++ b/include/InvariantMassBinning.h @@ -55,7 +55,7 @@ class InvariantMassBinning : public StaticDataAccessor public: /// Constructor. /// \param m The owning Model. - /// \param low_edges Low edges of the bins; the last element is the upper edge of the las bin. + /// \param low_edges Low edges of the bins; the last element is the upper edge of the last bin. explicit InvariantMassBinning(Model& m, const std::vector& low_edges); /// \brief Calculate which bin the invatiant mass of the From 3288b78e06ab3b281db02a1273d9b32658a21f2d Mon Sep 17 00:00:00 2001 From: pdigiglio Date: Tue, 30 Aug 2016 17:01:08 +0200 Subject: [PATCH 8/9] register to model, change bin access --- include/InvariantMassBinning.h | 6 ++---- src/InvariantMassBinning.cxx | 10 +++++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/include/InvariantMassBinning.h b/include/InvariantMassBinning.h index 6cf11483..3e63dd29 100644 --- a/include/InvariantMassBinning.h +++ b/include/InvariantMassBinning.h @@ -70,10 +70,8 @@ class InvariantMassBinning : public StaticDataAccessor const std::vector& lowEdges() const { return BinLowEdges_; } - /// Access the bin number. - /// \todo Enforce `const`ness on the pointed-to value!! - const std::shared_ptr& bin() const - { return Bin_; } + /// Return the bin number. + double bin(const DataPoint& d, const std::shared_ptr& pc) const; private: diff --git a/src/InvariantMassBinning.cxx b/src/InvariantMassBinning.cxx index 705bbbc5..89e93c6e 100644 --- a/src/InvariantMassBinning.cxx +++ b/src/InvariantMassBinning.cxx @@ -30,13 +30,15 @@ InvariantMassBinning::InvariantMassBinning(Model& m, const std::vector& if (!std::is_sorted(BinLowEdges_.cbegin(), BinLowEdges_.cend(), std::less_equal())) throw exceptions::Exception("Elements of the vector are not monotonically increasing", "InvariantMassBinning::InvariantMassBinning"); + + registerWithModel(); } //------------------------- void InvariantMassBinning::calculate(DataPoint& d, StatusManager& sm) const { // set all bins to uncalculated - sm.set(*Bin_, CalculationStatus::uncalculated); + sm.set(*this, CalculationStatus::uncalculated); // loop over particle combinations -> indices for (auto& pc_i : symmetrizationIndices()) { @@ -55,4 +57,10 @@ void InvariantMassBinning::calculate(DataPoint& d, StatusManager& sm) const } } +//------------------------- +double InvariantMassBinning::bin(const DataPoint& d, const std::shared_ptr& pc) const +{ + return Bin_->value(d, symmetrizationIndex(pc)); +} + } From e0db581a577065c24757abbc8c82cc205ba2710b Mon Sep 17 00:00:00 2001 From: pdigiglio Date: Tue, 30 Aug 2016 17:02:02 +0200 Subject: [PATCH 9/9] test case for InvariantMassBinning --- test/CMakeLists.txt | 1 + test/test_InvariantMassBinning.cxx | 115 +++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 test/test_InvariantMassBinning.cxx diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9b608244..c8d74103 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -25,6 +25,7 @@ set(YAP_TEST_SOURCES test_HelicityAngles.cxx test_HelicityAngles_boostRotate.cxx test_integration.cxx + test_InvariantMassBinning.cxx test_Matrix.cxx test_swapDalitzAxes.cxx test_swapFinalStates.cxx diff --git a/test/test_InvariantMassBinning.cxx b/test/test_InvariantMassBinning.cxx new file mode 100644 index 00000000..f7cbc880 --- /dev/null +++ b/test/test_InvariantMassBinning.cxx @@ -0,0 +1,115 @@ +/// \file test_InvariantMassBinning.cxx +/// \brief Test the binning of the mass axis. +/// \author Paolo Di Giglio + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "helperFunctions.h" +#include +#include +#include + +const std::vector monospaced_partition(const yap::MassRange& range, std::size_t bins) +{ + const double bin_width = (range[1] - range[0]) / bins; + // Reserve the space for the partition + std::vector p; + p.reserve(bins + 1); + + for (std::size_t i = 0; i < bins + 1; ++i) + p.push_back(i * bin_width); + + return p; +} + +inline const std::vector model_mass_range(std::shared_ptr model) +{ + return yap::mass_range( + model->massAxes(), + model->initialStateParticles().begin()->first, + model->finalStateParticles()); +} + +inline const bool mass_belongs_to_bin(double mass, int bin, const std::vector& bin_low_edges) +{ + if (bin == static_cast(bin_low_edges.size()) - 1) + return bin_low_edges[bin] <= mass; + if (bin == -1) + return mass < bin_low_edges[0]; + + return bin_low_edges[bin] <= mass && mass < bin_low_edges[bin + 1]; +} + +class InvariantMassBinningTest : public yap::InvariantMassBinning +{ +public: + InvariantMassBinningTest(yap::Model& m, const std::vector& bins) : + yap::InvariantMassBinning(m, bins) + {} + + void addPC(std::shared_ptr pc) + { yap::InvariantMassBinning::addParticleCombination(pc); } +}; + +TEST_CASE( "InvariantMassBinning" ) +{ + // disable debug logs in test + yap::disableLogs(el::Level::Debug); + //yap::plainLogs(el::Level::Debug); + + // Create the model + auto model = create_model(); + REQUIRE(model->consistent()); + + // Get the allowed mass range for the model mass axes + auto m_range = model_mass_range(model); +// for (const auto& it : m_range) +// std::cerr << it[0] << " " << it[1] << std::endl; + + // Number of bins + const unsigned int nBins = 10; + // Vector of the low edges of the partition + auto bin_low_edges = monospaced_partition(*m_range.begin(), nBins); + // Create the binning + InvariantMassBinningTest binning(*model, bin_low_edges); + + // Loop over particle combinations -> indices + for (const auto& pc_i : model->fourMomenta()->symmetrizationIndices()) { + // Add particle combinations to the binning + binning.addPC(pc_i.first); + } + + // Generate the DataSet + const unsigned int nPoints = 1000; + auto data_set = generate_data(model, nPoints); + + // Calculate and check the bins + for (const auto& pc_i : model->fourMomenta()->symmetrizationIndices()) { + for (auto& dp : data_set) { + // Calculate the bin + binning.calculate(dp, data_set); + // Check the bin + auto mass = model->fourMomenta()->m(dp, pc_i.first); + auto bin = binning.bin(dp, pc_i.first); + auto bin_is_correct = mass_belongs_to_bin(mass, bin, bin_low_edges); + if (!bin_is_correct) + std::cout << "bin = " << bin << " " + << bin_low_edges[bin] << " <= " + << mass << " < " + << bin_low_edges[bin + 1] << std::endl; + + REQUIRE(bin_is_correct); + } + } +}