diff --git a/PhysicsAnalysis/AssociationBuilder/AssociationUtils/AssociationUtils/DeltaROverlapFilter.h b/PhysicsAnalysis/AssociationBuilder/AssociationUtils/AssociationUtils/DeltaROverlapFilter.h new file mode 100755 index 0000000000000000000000000000000000000000..445903eef8d766bedf752d4b758160cca6193a4a --- /dev/null +++ b/PhysicsAnalysis/AssociationBuilder/AssociationUtils/AssociationUtils/DeltaROverlapFilter.h @@ -0,0 +1,135 @@ +///////////////////////// -*- C++ -*- ///////////////////////////// + +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// DeltaROverlapFilter.h +// Header file for class DeltaROverlapFilter +// Author: S.Binet<binet@cern.ch> +/////////////////////////////////////////////////////////////////// +#ifndef ASSOCIATIONUTILS_DELTAROVERLAPFILTER_H +#define ASSOCIATIONUTILS_DELTAROVERLAPFILTER_H + +// STL includes +#include <functional> + +// EventKernel includes +#include "EventKernel/INavigable4Momentum.h" + +// AssociationUtils includes +#include "AssociationUtils/IOverlapFilter.h" + +// Forward declaration + +class DeltaROverlapFilter : public IOverlapFilter +{ + public: + using IOverlapFilter::hasOverlap; + + /////////////////////////////////////////////////////////////////// + // Public methods: + /////////////////////////////////////////////////////////////////// + public: + + /** Default constructor: + */ + DeltaROverlapFilter(); + + /** Copy constructor: + */ + DeltaROverlapFilter( const DeltaROverlapFilter& rhs ); + + /** Assignment operator: + */ + DeltaROverlapFilter& operator=( const DeltaROverlapFilter& rhs ); + + /** Constructor with parameters: + */ + DeltaROverlapFilter( double maxDeltaR ); + + /** Constructor with parameters: + */ + DeltaROverlapFilter( double minDeltaR, double maxDeltaR ); + + /** Destructor: + */ + virtual ~DeltaROverlapFilter(); + + /////////////////////////////////////////////////////////////////// + // Const methods: + /////////////////////////////////////////////////////////////////// + + /** @brief Filtering method. If true then objects overlap. + */ + bool hasOverlap( const INavigable4Momentum& obj1, + const INavigable4Momentum& obj2 ) const; + + /** @brief Retrieve the defined lowest value cut for the $\Delta R$ + */ + double minDeltaR() const; + + /** @brief Retrieve the defined highest value cut for the $\Delta R$ + */ + double maxDeltaR() const; + + + /////////////////////////////////////////////////////////////////// + // Non-const methods: + /////////////////////////////////////////////////////////////////// + + void setMinDeltaR( double minDeltaR ); + + void setMaxDeltaR( double maxDeltaR ); + + void setDeltaR( double minDeltaR, double maxDeltaR ); + + /////////////////////////////////////////////////////////////////// + // Protected data: + /////////////////////////////////////////////////////////////////// + protected: + + /** Inner crown limit for delta-R check + */ + double m_minDeltaR; + + /** Outer crown limit for delta-R check + */ + double m_maxDeltaR; +}; + +/////////////////////////////////////////////////////////////////// +/// Inline methods: +/////////////////////////////////////////////////////////////////// + +inline DeltaROverlapFilter::~DeltaROverlapFilter() +{} + +inline double DeltaROverlapFilter::minDeltaR() const +{ + return m_minDeltaR; +} + +inline double DeltaROverlapFilter::maxDeltaR() const +{ + return m_maxDeltaR; +} + +inline void DeltaROverlapFilter::setMinDeltaR( double minDeltaR ) +{ + m_minDeltaR = minDeltaR; +} + +inline void DeltaROverlapFilter::setMaxDeltaR( double maxDeltaR ) +{ + m_maxDeltaR = maxDeltaR; +} + +inline +void DeltaROverlapFilter::setDeltaR( double minDeltaR, double maxDeltaR ) +{ + m_minDeltaR = minDeltaR; + m_maxDeltaR = maxDeltaR; +} + +#endif //> ASSOCIATIONUTILS_DELTAROVERLAPFILTER_H diff --git a/PhysicsAnalysis/AssociationBuilder/AssociationUtils/AssociationUtils/IOverlapFilter.h b/PhysicsAnalysis/AssociationBuilder/AssociationUtils/AssociationUtils/IOverlapFilter.h new file mode 100755 index 0000000000000000000000000000000000000000..f4ea999898fb9fe39042f7859919fed58cbaf417 --- /dev/null +++ b/PhysicsAnalysis/AssociationBuilder/AssociationUtils/AssociationUtils/IOverlapFilter.h @@ -0,0 +1,100 @@ +///////////////////////// -*- C++ -*- ///////////////////////////// + +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// IOverlapFilter.h +// Header file for class IOverlapFilter +// Author: S.Binet<binet@cern.ch> +/////////////////////////////////////////////////////////////////// +#ifndef ASSOCIATIONUTILS_IOVERLAPFILTER_H +#define ASSOCIATIONUTILS_IOVERLAPFILTER_H + +// STL includes +#include <functional> + +// EventKernel includes +#include "EventKernel/INavigable4Momentum.h" + +// Forward declaration + +class IOverlapFilter : public std::binary_function< + const INavigable4Momentum*, + const INavigable4Momentum*, + bool + > +{ + + /////////////////////////////////////////////////////////////////// + // Public methods: + /////////////////////////////////////////////////////////////////// + public: + + /** Destructor: + */ + virtual ~IOverlapFilter(); + + /////////////////////////////////////////////////////////////////// + // Const methods: + /////////////////////////////////////////////////////////////////// + + /** @brief Filtering method. + * Return true if objects overlap. + */ + virtual bool hasOverlap( const INavigable4Momentum& obj1, + const INavigable4Momentum& obj2 ) const = 0; + + /** @brief Filtering method. + * Return true if objects overlap ( forwards to @c hasOverlap ) + */ + bool hasOverlap( const INavigable4Momentum* obj1, + const INavigable4Momentum* obj2 ) const; + + /** @brief Filtering method. + * Return true if objects overlap ( forwards to @c hasOverlap ) + */ + bool operator()( const INavigable4Momentum& obj1, + const INavigable4Momentum& obj2 ) const; + + /** @brief Filtering method. + * Return true if objects overlap ( forwards to @c hasOverlap ) + */ + bool operator()( const INavigable4Momentum* obj1, + const INavigable4Momentum* obj2 ) const; + + /////////////////////////////////////////////////////////////////// + // Non-const methods: + /////////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////////// + // Protected data: + /////////////////////////////////////////////////////////////////// + protected: + +}; + +/////////////////////////////////////////////////////////////////// +/// Inline methods: +/////////////////////////////////////////////////////////////////// + +inline bool +IOverlapFilter::hasOverlap( const INavigable4Momentum* obj1, + const INavigable4Momentum* obj2 ) const +{ + return hasOverlap(*obj1, *obj2); +} + +inline bool IOverlapFilter::operator()( const INavigable4Momentum& obj1, + const INavigable4Momentum& obj2 ) const +{ + return hasOverlap(obj1, obj2); +} + +inline bool IOverlapFilter::operator()( const INavigable4Momentum* obj1, + const INavigable4Momentum* obj2 ) const +{ + return hasOverlap(*obj1, *obj2); +} + +#endif //> ASSOCIATIONUTILS_IOVERLAPFILTER_H diff --git a/PhysicsAnalysis/AssociationBuilder/AssociationUtils/AssociationUtils/NavigationOverlapFilter.h b/PhysicsAnalysis/AssociationBuilder/AssociationUtils/AssociationUtils/NavigationOverlapFilter.h new file mode 100755 index 0000000000000000000000000000000000000000..60f8ebeb6c6a5f35004faf707cc25ad92df9b56d --- /dev/null +++ b/PhysicsAnalysis/AssociationBuilder/AssociationUtils/AssociationUtils/NavigationOverlapFilter.h @@ -0,0 +1,75 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/////////////////////////////////////////////////////////////////// +// NavigationOverlapFilter.h +// Header file for class NavigationOverlapFilter +// Author: S.Binet<binet@cern.ch> +/////////////////////////////////////////////////////////////////// +#ifndef ASSOCIATIONUTILS_NAVIGATIONOVERLAPFILTER_H +#define ASSOCIATIONUTILS_NAVIGATIONOVERLAPFILTER_H + +// STL includes +#include <functional> + +// EventKernel includes +#include "EventKernel/INavigable4Momentum.h" + +// AssociationUtils includes +#include "AssociationUtils/IOverlapFilter.h" + +// Forward declaration + +class NavigationOverlapFilter : public IOverlapFilter +{ + + /////////////////////////////////////////////////////////////////// + // Public methods: + /////////////////////////////////////////////////////////////////// + public: + + /** Default constructor: + */ + NavigationOverlapFilter(); + + /** Copy constructor: + */ + NavigationOverlapFilter( const NavigationOverlapFilter& rhs ); + + /** Assignment operator: + */ + NavigationOverlapFilter& operator=( const NavigationOverlapFilter& rhs ); + + /** Destructor: + */ + virtual ~NavigationOverlapFilter(); + + /////////////////////////////////////////////////////////////////// + // Const methods: + /////////////////////////////////////////////////////////////////// + + /** @brief Filtering method. If true then objects overlap. + */ + bool hasOverlap( const INavigable4Momentum& obj1, + const INavigable4Momentum& obj2 ) const; + + /////////////////////////////////////////////////////////////////// + // Non-const methods: + /////////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////////// + // Protected data: + /////////////////////////////////////////////////////////////////// + protected: + +}; + +/////////////////////////////////////////////////////////////////// +/// Inline methods: +/////////////////////////////////////////////////////////////////// + +inline NavigationOverlapFilter::~NavigationOverlapFilter() +{} + +#endif //> ASSOCIATIONUTILS_NAVIGATIONOVERLAPFILTER_H diff --git a/PhysicsAnalysis/AssociationBuilder/AssociationUtils/cmt/requirements b/PhysicsAnalysis/AssociationBuilder/AssociationUtils/cmt/requirements new file mode 100755 index 0000000000000000000000000000000000000000..d4a5b8eb8eafe951a18638269348b94123206f27 --- /dev/null +++ b/PhysicsAnalysis/AssociationBuilder/AssociationUtils/cmt/requirements @@ -0,0 +1,48 @@ +package AssociationUtils + +author Ketevi A. Assamagan <ketevi@bnl.gov> +author Sebastien Binet <binet@cern.ch> + +use AtlasPolicy AtlasPolicy-* + +use EventKernel EventKernel-* Event +use FourMomUtils FourMomUtils-* Event + +branches AssociationUtils src doc share run + +library AssociationUtils *.cxx + +apply_pattern installed_library + +############# +# unit tests +# +private + +use TestPolicy TestPolicy-* -no_auto_imports +use TestTools TestTools-* AtlasTest -no_auto_imports + +use Navigation Navigation-00-* Control -no_auto_imports +use DataModel DataModel-00-* Control -no_auto_imports +use CLIDSvc CLIDSvc-* Control -no_auto_imports +use AtlasBoost AtlasBoost-00-* External -no_auto_imports +use FourMom FourMom-* Event -no_auto_imports + +macro cppUnit_deltaROverlapFilterTest_imports "" +macro_append cppUnit_deltaROverlapFilterTest_imports " -import=StoreGate" +macro_append cppUnit_deltaROverlapFilterTest_imports " -import=Navigation" +macro_append cppUnit_deltaROverlapFilterTest_imports " -import=DataModel" +macro_append cppUnit_deltaROverlapFilterTest_imports " -import=AtlasBoost" +macro_append cppUnit_deltaROverlapFilterTest_imports " -import=CLIDSvc" +macro_append cppUnit_deltaROverlapFilterTest_imports " -import=FourMom" +macro_append cppUnit_deltaROverlapFilterTest_imports " -import=FourMomUtils" + +apply_pattern CppUnit name=cppUnit_deltaROverlapFilterTest \ + files="-s=${AssociationUtils_root}/test DeltaROverlapFilter_CppUnit.cxx" \ + imports=$(cppUnit_deltaROverlapFilterTest_imports) + +end_private + + + + diff --git a/PhysicsAnalysis/AssociationBuilder/AssociationUtils/src/DeltaROverlapFilter.cxx b/PhysicsAnalysis/AssociationBuilder/AssociationUtils/src/DeltaROverlapFilter.cxx new file mode 100755 index 0000000000000000000000000000000000000000..9fa145fe99a55edbb878f2008fecca10f9c687aa --- /dev/null +++ b/PhysicsAnalysis/AssociationBuilder/AssociationUtils/src/DeltaROverlapFilter.cxx @@ -0,0 +1,85 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/////////////////////////////////////////////////////////////////// +// DeltaROverlapFilter.cxx +// Implementation file for class DeltaROverlapFilter +// Author: S.Binet<binet@cern.ch> +/////////////////////////////////////////////////////////////////// + + +// STL includes +#include <cfloat> + +// FourMomUtils includes +#include "FourMomUtils/P4Helpers.h" + +// AssociationUtils includes +#include "AssociationUtils/DeltaROverlapFilter.h" + +/////////////////////////////////////////////////////////////////// +/// Public methods: +/////////////////////////////////////////////////////////////////// + +// Constructors +//////////////// + +DeltaROverlapFilter::DeltaROverlapFilter() : + IOverlapFilter( ), + m_minDeltaR ( 0. ), + m_maxDeltaR ( DBL_MAX ) +{} + +DeltaROverlapFilter::DeltaROverlapFilter( const DeltaROverlapFilter& rhs ) : + IOverlapFilter( rhs ), + m_minDeltaR( rhs.m_minDeltaR ), + m_maxDeltaR( rhs.m_maxDeltaR ) +{} + +DeltaROverlapFilter& +DeltaROverlapFilter::operator=( const DeltaROverlapFilter& rhs ) +{ + if ( this != &rhs ) { + IOverlapFilter::operator=( rhs ); + m_minDeltaR = rhs.m_minDeltaR; + m_maxDeltaR = rhs.m_maxDeltaR; + } + return *this; +} + +DeltaROverlapFilter::DeltaROverlapFilter( double maxDeltaR ) : + IOverlapFilter( ), + m_minDeltaR( 0. ), + m_maxDeltaR( maxDeltaR ) +{} + +DeltaROverlapFilter::DeltaROverlapFilter( double minDeltaR, + double maxDeltaR ) : + IOverlapFilter( ), + m_minDeltaR( minDeltaR ), + m_maxDeltaR( maxDeltaR ) +{} + +// Destructor +/////////////// + +/////////////////////////////////////////////////////////////////// +// Const methods: +/////////////////////////////////////////////////////////////////// + +bool DeltaROverlapFilter::hasOverlap( const INavigable4Momentum& obj1, + const INavigable4Momentum& obj2 ) const +{ + const double deltaR = P4Helpers::deltaR( obj1, obj2 ); + return ( m_minDeltaR <= deltaR ) && ( deltaR < m_maxDeltaR ); +} + +/////////////////////////////////////////////////////////////////// +// Non-const methods: +/////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////// +// Protected methods: +/////////////////////////////////////////////////////////////////// + diff --git a/PhysicsAnalysis/AssociationBuilder/AssociationUtils/src/IOverlapFilter.cxx b/PhysicsAnalysis/AssociationBuilder/AssociationUtils/src/IOverlapFilter.cxx new file mode 100755 index 0000000000000000000000000000000000000000..55b92336c5040db9f9235047765c3c924bbc5046 --- /dev/null +++ b/PhysicsAnalysis/AssociationBuilder/AssociationUtils/src/IOverlapFilter.cxx @@ -0,0 +1,40 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/////////////////////////////////////////////////////////////////// +// IOverlapFilter.cxx +// Implementation file for class IOverlapFilter +// Author: S.Binet<binet@cern.ch> +/////////////////////////////////////////////////////////////////// + + +// STL includes + +// AssociationUtils includes +#include "AssociationUtils/IOverlapFilter.h" + +/////////////////////////////////////////////////////////////////// +/// Public methods: +/////////////////////////////////////////////////////////////////// + +// Constructors +//////////////// + +// Destructor +/////////////// +IOverlapFilter::~IOverlapFilter() +{} + +/////////////////////////////////////////////////////////////////// +// Const methods: +/////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////// +// Non-const methods: +/////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////// +// Protected methods: +/////////////////////////////////////////////////////////////////// + diff --git a/PhysicsAnalysis/AssociationBuilder/AssociationUtils/test/AssociationUtils.sh b/PhysicsAnalysis/AssociationBuilder/AssociationUtils/test/AssociationUtils.sh new file mode 100755 index 0000000000000000000000000000000000000000..e2137e073c1ba36f006341327ccecd4d3cf8bce4 --- /dev/null +++ b/PhysicsAnalysis/AssociationBuilder/AssociationUtils/test/AssociationUtils.sh @@ -0,0 +1,13 @@ +#!/bin/sh +# This just selects the directory to run cmt commands +# But with project builds and as this package (AssociationUtils) can be moved +# from some project to another, we wildcard the AtlasXyzRelease directory +cd ${NIGHTLYAREA}/Atlas*Release/cmt +# +cmt broadcast -select=AssociationUtils make CppUnit +stat=$? +if [ "$stat" != "0" ]; then + echo " -------------------------------- " + echo " FAILURE : test AssociationUtils " + echo " -------------------------------- " +fi diff --git a/PhysicsAnalysis/AssociationBuilder/AssociationUtils/test/DeltaROverlapFilter_CppUnit.cxx b/PhysicsAnalysis/AssociationBuilder/AssociationUtils/test/DeltaROverlapFilter_CppUnit.cxx new file mode 100755 index 0000000000000000000000000000000000000000..054823721b7ed9b20e9aa6235382b5d5eff332dc --- /dev/null +++ b/PhysicsAnalysis/AssociationBuilder/AssociationUtils/test/DeltaROverlapFilter_CppUnit.cxx @@ -0,0 +1,436 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/// Class to test the DeltaROverlapFilter class +/// Author : S.Binet<binet@cern.ch> + +// CppUnit includes +#include<cppunit/extensions/HelperMacros.h> +#include<cppunit/Exception.h> + +// STL includes +#include <list> +#include <vector> +#include <iostream> +#include <stdexcept> +#include <cmath> +#include <cfloat> +#include <algorithm> +#include <numeric> + +// to ease tests +#include <boost/bind.hpp> + +// DataModel includes +#include "DataModel/DataVector.h" +#include "DataModel/ElementLink.h" +#include "CLIDSvc/CLASS_DEF.h" + +// EventKernel includes +#include "EventKernel/INavigable4Momentum.h" + +// FourMom includes +#include "FourMom/P4PxPyPzE.h" +#include "Navigation/NavigableTerminalNode.h" + +// FourMomUtils includes +#include "FourMomUtils/P4Helpers.h" + +// AssociationUtils includes +#include "AssociationUtils/DeltaROverlapFilter.h" + +class MyNav4Mom : virtual public INavigable4Momentum, + public P4PxPyPzE, + public NavigableTerminalNode +{ +public: + MyNav4Mom(): + INavigable4Momentum(), + P4PxPyPzE(), + NavigableTerminalNode() + {} + + MyNav4Mom( double px, double py, double pz, double ene ): + INavigable4Momentum(), + P4PxPyPzE(px, py, pz, ene), + NavigableTerminalNode() + {} +}; + +CLASS_DEF( DataVector<MyNav4Mom> , 77574488 , 1 ) + +class DeltaROverlapFilterTest : public CppUnit::TestFixture +{ + /// Definition of the unit test suite + CPPUNIT_TEST_SUITE( DeltaROverlapFilterTest ); + + CPPUNIT_TEST( testConstructor ); + CPPUNIT_TEST( testSettersAndGetters ); + CPPUNIT_TEST( testPredicate ); + + CPPUNIT_TEST( testCountIf ); + CPPUNIT_TEST( testFindIf ); + CPPUNIT_TEST( testAccumulate ); + + /// end the definition test suite + CPPUNIT_TEST_SUITE_END(); + +private: + + unsigned int m_nmax; + DataVector<MyNav4Mom> m_dvMoms; + std::vector<MyNav4Mom*> m_stlMoms; + +public: + + /// Set up the data members + void setUp() + { + m_nmax = 11; + const double x = 10.; + + m_dvMoms.resize(m_nmax); + m_stlMoms.resize(m_nmax); + for ( unsigned int i = 0; i != m_nmax; ++i ) { + m_dvMoms[i] = new MyNav4Mom( (i+1)*x, (i+2)*x, (i+3)*x, (i+4)*x ); + m_stlMoms[i] = new MyNav4Mom( (i+1)*x, (i+2)*x, (i+3)*x, (i+4)*x ); + } + } + + /// destroy any on-the-heap-created data member + void tearDown() + { + m_dvMoms.clear(); + for ( unsigned int i = 0; i != m_nmax; ++i ) { + delete m_stlMoms[i]; + m_stlMoms[i] = 0; + } + } + + /// Test the McVtxFilter constructors + void testConstructor() + { + { + DeltaROverlapFilter filter; + CPPUNIT_ASSERT( filter.minDeltaR() == 0. ); + CPPUNIT_ASSERT( filter.maxDeltaR() == DBL_MAX ); + } + + { + DeltaROverlapFilter filter( 0.7 ); + CPPUNIT_ASSERT( filter.minDeltaR() == 0. ); + CPPUNIT_ASSERT( filter.maxDeltaR() == 0.7 ); + } + + { + DeltaROverlapFilter filter( 0.4, 0.7 ); + CPPUNIT_ASSERT( filter.minDeltaR() == 0.4 ); + CPPUNIT_ASSERT( filter.maxDeltaR() == 0.7 ); + } + + { + DeltaROverlapFilter filter( 0.4, 0.7 ); + CPPUNIT_ASSERT( filter.minDeltaR() == 0.4 ); + CPPUNIT_ASSERT( filter.maxDeltaR() == 0.7 ); + + DeltaROverlapFilter g(filter); + CPPUNIT_ASSERT( g.minDeltaR() == 0.4 ); + CPPUNIT_ASSERT( g.maxDeltaR() == 0.7 ); + + DeltaROverlapFilter h; + CPPUNIT_ASSERT( h.minDeltaR() == 0. ); + CPPUNIT_ASSERT( h.maxDeltaR() == DBL_MAX ); + + h = filter; + CPPUNIT_ASSERT( h.minDeltaR() == 0.4 ); + CPPUNIT_ASSERT( h.maxDeltaR() == 0.7 ); + } + } + + void testSettersAndGetters() + { + DeltaROverlapFilter filter( 0.4, 0.7 ); + CPPUNIT_ASSERT( filter.minDeltaR() == 0.4 ); + CPPUNIT_ASSERT( filter.maxDeltaR() == 0.7 ); + + filter.setMinDeltaR( 0.3 ); + CPPUNIT_ASSERT( filter.minDeltaR() == 0.3 ); + CPPUNIT_ASSERT( filter.maxDeltaR() == 0.7 ); + + filter.setMaxDeltaR( 0.8 ); + CPPUNIT_ASSERT( filter.minDeltaR() == 0.3 ); + CPPUNIT_ASSERT( filter.maxDeltaR() == 0.8 ); + + filter.setDeltaR( 0.4, 0.7 ); + CPPUNIT_ASSERT( filter.minDeltaR() == 0.4 ); + CPPUNIT_ASSERT( filter.maxDeltaR() == 0.7 ); + } + + void testPredicate() + { + { + DeltaROverlapFilter filter; + MyNav4Mom mom1( 10., 10., 10., 20. ); + MyNav4Mom mom2( 10., 10., 10., 20. ); + CPPUNIT_ASSERT( P4Helpers::deltaR(mom1, mom2) == 0. ); + CPPUNIT_ASSERT( filter.hasOverlap(mom1, mom2) ); + CPPUNIT_ASSERT( filter(mom1, mom2) ); + } + { + DeltaROverlapFilter filter( 0.1, 0.2 ); + MyNav4Mom mom1( 10., 10., 10., 20. ); + MyNav4Mom mom2( 10., 10., 10., 20. ); + CPPUNIT_ASSERT( P4Helpers::deltaR(mom1, mom2) == 0. ); + CPPUNIT_ASSERT( !filter.hasOverlap(mom1, mom2) ); + CPPUNIT_ASSERT( !filter(mom1, mom2) ); + } + { + typedef ElementLink<DataVector<MyNav4Mom> > Link_t; + std::vector<Link_t> moms; + moms.push_back( Link_t( m_dvMoms, 0 ) ); + DeltaROverlapFilter filter( 0.1, 0.2 ); + CPPUNIT_ASSERT( P4Helpers::deltaR( *moms[0], *moms[0] ) == 0. ); + CPPUNIT_ASSERT( !filter.hasOverlap(**moms[0],**moms[0]) ); + CPPUNIT_ASSERT( !filter.hasOverlap(*moms[0],*moms[0]) ); + CPPUNIT_ASSERT( !filter( *moms[0], *moms[0] ) ); + } + { + MyNav4Mom mom1( -10., -10., -10., 20. ); + MyNav4Mom mom2( 10., 10., 10., 20. ); + const double minDeltaR = 3.40646; + const double maxDeltaR = 3.40647; + CPPUNIT_ASSERT( P4Helpers::deltaR(mom1, mom2) < maxDeltaR ); + CPPUNIT_ASSERT( P4Helpers::deltaR(mom1, mom2) >= minDeltaR ); + + DeltaROverlapFilter filter; + + CPPUNIT_ASSERT( filter.hasOverlap(mom1, mom2) ); + CPPUNIT_ASSERT( filter(mom1, mom2) ); + + filter.setDeltaR( 0., minDeltaR ); + CPPUNIT_ASSERT( !filter.hasOverlap(mom1, mom2) ); + CPPUNIT_ASSERT( !filter(mom1, mom2) ); + + filter.setDeltaR( minDeltaR, maxDeltaR ); + CPPUNIT_ASSERT( filter.hasOverlap(mom1, mom2) ); + CPPUNIT_ASSERT( filter(mom1, mom2) ); + + filter.setDeltaR( maxDeltaR, DBL_MAX ); + CPPUNIT_ASSERT( !filter.hasOverlap(mom1, mom2) ); + CPPUNIT_ASSERT( !filter(mom1, mom2) ); + } + } + + template <class CONT> + void testCountIf_t( const CONT& cont, const DeltaROverlapFilter& filter, + const int INRANGE ) + { + const int OUTRANGE = static_cast<int>(cont.size()) - INRANGE; + { + const int n = std::count_if( cont.begin(), cont.end(), + std::bind2nd( filter, cont[0] ) ); + CPPUNIT_ASSERT( n == (INRANGE+1) ); + } + + { + const int n = std::count_if( cont.begin(), cont.end(), + boost::bind( filter, _1, cont[0] ) ); + CPPUNIT_ASSERT( n == (INRANGE+1) ); + } + + { + const int n = std::count_if( cont.begin(), cont.end(), + boost::bind( filter, cont[0], _1 ) ); + CPPUNIT_ASSERT( n == (INRANGE+1) ); + } + + { + const int n = std::count_if( cont.begin(), cont.end(), + boost::bind( std::logical_not<bool>(), + boost::bind( filter, + cont[0], _1 ) ) ); + CPPUNIT_ASSERT( n == (OUTRANGE-1) ); + } + } + + void testCountIf() + { + const int INRANGE = 6; + DeltaROverlapFilter filter( 0., P4Helpers::deltaR( m_stlMoms[0], + m_stlMoms[INRANGE] ) ); + +// std::cout << std::endl; +// for ( unsigned int i = 0; i != m_nmax; ++i ) { +// std::cout << i << " => " << P4Helpers::deltaR(m_stlMoms[0], m_stlMoms[i]) +// << std::endl; +// } + + testCountIf_t( m_dvMoms, filter, INRANGE ); + testCountIf_t( m_stlMoms, filter, INRANGE ); + } + + template <class CONT> + void testFindIf_t( const CONT& cont, const DeltaROverlapFilter& filter, + const int INRANGE ) + { + const int OUTRANGE = static_cast<int>(cont.size()) - INRANGE; + { + typename CONT::const_iterator itr; + itr = std::find_if( cont.begin(), cont.end(), + std::bind2nd( filter, cont[0] ) ); + CPPUNIT_ASSERT( itr == cont.begin() ); + } + + { + typename CONT::const_iterator itr; + itr = std::find_if( cont.begin(), cont.end(), + boost::bind( filter, _1, cont[0] ) ); + CPPUNIT_ASSERT( itr == cont.begin() ); + } + + { + typename CONT::const_iterator itr; + itr = std::find_if( cont.begin(), cont.end(), + boost::bind( filter, cont[0], _1 ) ); + CPPUNIT_ASSERT( itr == cont.begin() ); + } + + { + typename CONT::const_iterator itr; + itr = std::find_if( cont.begin(), cont.end(), + boost::bind( std::logical_not<bool>(), + boost::bind( filter, + cont[0], _1 ) ) ); + CPPUNIT_ASSERT( itr == (cont.begin()+INRANGE+1) ); + } + + { + typename CONT::const_reverse_iterator ritr; + ritr = std::find_if( cont.rbegin(), cont.rend(), + boost::bind( filter, cont[0], _1 ) ); + CPPUNIT_ASSERT( ritr == (cont.rbegin()+OUTRANGE-1) ); + } + + { + typename CONT::const_reverse_iterator ritr; + ritr = std::find_if( cont.rbegin(), cont.rend(), + boost::bind( std::logical_not<bool>(), + boost::bind( filter, + cont[0], _1 ) ) ); + CPPUNIT_ASSERT( ritr == cont.rbegin() ); + } + } + + void testFindIf() + { + const int INRANGE = 6; + DeltaROverlapFilter filter( 0., P4Helpers::deltaR( m_stlMoms[0], + m_stlMoms[INRANGE] ) ); + testFindIf_t( m_dvMoms, filter, INRANGE ); + testFindIf_t( m_stlMoms, filter, INRANGE ); + } + + template <class CONT> + void testAccumulate_t( const CONT& cont, const DeltaROverlapFilter& filter, + const int INRANGE ) + { + { + bool allOk = true; + allOk = std::accumulate( cont.begin(), + cont.begin()+INRANGE, + allOk, + boost::bind( std::logical_and<bool>(), + _1, + boost::bind( filter, + cont[0], _2 ) ) ); + + CPPUNIT_ASSERT( allOk ); + } + + { + bool allOk = true; + allOk = std::accumulate( cont.rbegin()+INRANGE, + cont.rend(), + allOk, + boost::bind( std::logical_and<bool>(), + _1, + boost::bind( filter, + cont[0], _2 ) ) ); + + CPPUNIT_ASSERT( allOk ); + } + + { + bool allOk = true; + allOk = std::accumulate( cont.begin(), + cont.begin()+INRANGE+1, + allOk, + boost::bind( std::logical_and<bool>(), + _1, // allOk_sum + boost::bind( filter, + cont[0], _2 ) ) ); + + CPPUNIT_ASSERT( allOk ); + } + + { + bool allOk = false; + allOk = std::accumulate( cont.begin(), + cont.end(), + allOk, + boost::bind( std::logical_or<bool>(), + _1, // allOk_sum + boost::bind( filter, + cont[0], _2 ) ) ); + + CPPUNIT_ASSERT( allOk ); + } + + { + bool allOk = false; + allOk = std::accumulate( cont.begin()+INRANGE, + cont.end(), + allOk, + boost::bind( std::logical_or<bool>(), + _1, // allOk_sum + boost::bind( filter, + cont[0], _2 ) ) ); + + CPPUNIT_ASSERT( allOk ); + } + + { + bool allOk = false; + allOk = std::accumulate( cont.rbegin(), + cont.rend()-INRANGE, + allOk, + boost::bind( std::logical_or<bool>(), + _1, // allOk_sum + boost::bind( filter, + cont[0], _2 ) ) ); + + CPPUNIT_ASSERT( allOk ); + } + + } + + void testAccumulate() + { + const int INRANGE = 6; + DeltaROverlapFilter filter( 0., P4Helpers::deltaR( m_stlMoms[0], + m_stlMoms[INRANGE] ) ); + + testAccumulate_t( m_dvMoms, filter, INRANGE ); + testAccumulate_t( m_stlMoms, filter, INRANGE ); + } + +}; + +/// Registration of the test suite "DeltaROverlapFilterTest" so it will be +/// recognized by the main test program which drives the different tests +CPPUNIT_TEST_SUITE_REGISTRATION( DeltaROverlapFilterTest ); + +/// CppUnit test-driver common for all the cppunit test classes. +/// In ATLAS sw release it is located in TestPolicy package +#include <TestPolicy/CppUnit_SGtestdriver.cxx>