diff --git a/MicroDST/MicroDSTAlgorithm/CMakeLists.txt b/MicroDST/MicroDSTAlgorithm/CMakeLists.txt index c7ad1959baa33d3e295854c1406880b6ffee1fdf..9f3a38f8fcba18bda625a5a85bd773bfac9ed510 100644 --- a/MicroDST/MicroDSTAlgorithm/CMakeLists.txt +++ b/MicroDST/MicroDSTAlgorithm/CMakeLists.txt @@ -26,7 +26,6 @@ gaudi_add_module(MicroDSTAlgorithm LHCb::MCEvent LHCb::PhysEvent Rec::DaVinciInterfacesLib - Rec::DaVinciKernelLib Rec::DaVinciMCKernelLib Rec::DaVinciTypesLib ) diff --git a/Phys/DaVinciFilters/CMakeLists.txt b/Phys/DaVinciFilters/CMakeLists.txt index 0979ea3f09c95deaf4ecb2271ccdc56fdc468749..f19defcb751911ab8020b9f86bc4e3dccb6d0447 100644 --- a/Phys/DaVinciFilters/CMakeLists.txt +++ b/Phys/DaVinciFilters/CMakeLists.txt @@ -28,7 +28,6 @@ gaudi_add_module(DaVinciFilters LHCb::PhysEvent LHCb::PhysInterfacesLib Rec::DaVinciInterfacesLib - Rec::DaVinciKernelLib Rec::DaVinciTypesLib Rec::DecayTreeFitterLib Rec::TrackInterfacesLib diff --git a/Phys/DaVinciInterfaces/dict/DaVinciInterfacesDict.h b/Phys/DaVinciInterfaces/dict/DaVinciInterfacesDict.h index 1280af8ee337c6a20d2cfd02e3f6e78399f3ead1..abb9c333e4854b4ece587df65e464d77d3af7d94 100644 --- a/Phys/DaVinciInterfaces/dict/DaVinciInterfacesDict.h +++ b/Phys/DaVinciInterfaces/dict/DaVinciInterfacesDict.h @@ -22,7 +22,6 @@ // ============================================================================ // DaVinciKernel // ============================================================================ -#include "Kernel/ICaloParticleMaker.h" #include "Kernel/IChangePIDTool.h" #include "Kernel/ICheckOverlap.h" #include "Kernel/IDecayFinder.h" @@ -52,10 +51,8 @@ #include "Kernel/IProtoParticleFilter.h" #include "Kernel/IRelatedPVFinder.h" #include "Kernel/ISecondaryVertexTool.h" -#include "Kernel/ISetInputParticles.h" #include "Kernel/ITagger.h" #include "Kernel/ITisTos.h" -#include "Kernel/ITrackIsolation.h" #include "Kernel/ITriggerSelectionTisTos.h" #include "Kernel/ITriggerTisTos.h" #include "Kernel/IVertexFit.h" diff --git a/Phys/DaVinciInterfaces/dict/DaVinciInterfacesDict.xml b/Phys/DaVinciInterfaces/dict/DaVinciInterfacesDict.xml index 864c9d0708e2c0919384898321989be75d8cab2f..189e2dfc972a9c0f5a48515d14bf9c13ebc01762 100644 --- a/Phys/DaVinciInterfaces/dict/DaVinciInterfacesDict.xml +++ b/Phys/DaVinciInterfaces/dict/DaVinciInterfacesDict.xml @@ -12,7 +12,6 @@ - @@ -41,13 +40,11 @@ - - diff --git a/Phys/DaVinciInterfaces/include/Kernel/ICaloParticleMaker.h b/Phys/DaVinciInterfaces/include/Kernel/ICaloParticleMaker.h deleted file mode 100644 index 1c00a0f19acd2701b1e081e4d7901ea2c73444c1..0000000000000000000000000000000000000000 --- a/Phys/DaVinciInterfaces/include/Kernel/ICaloParticleMaker.h +++ /dev/null @@ -1,49 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -#ifndef DAVINCIKERNEL_ICALOPARTICLEMAKER_H -#define DAVINCIKERNEL_ICALOPARTICLEMAKER_H 1 - -// Include files -// from STL -#include - -// from Gaudi -#include "Event/Particle.h" -#include "GaudiKernel/GenericVectorTypes.h" -#include "GaudiKernel/IAlgTool.h" -#include "GaudiKernel/SymmetricMatrixTypes.h" - -// Forward declarations -namespace LHCb { - class Vertex; -} - -/** @class ICaloParticleMaker ICaloParticleMaker.h Kernel/ICaloParticleMaker.h - * Interface class to make Particles from other classes - * (e.g. ProtoParticles). - * This tools is internally used by the PhysDesktop. - * - * @author Jose Helder Lopes - * @date 22/04/2002 - */ - -struct GAUDI_API ICaloParticleMaker : extend_interfaces { - - DeclareInterfaceID( ICaloParticleMaker, 2, 0 ); - - /// Dispatch the making of particles - virtual StatusCode makeParticles( LHCb::Particle::Vector& parts ) = 0; - virtual void setPoint( const Gaudi::XYZPoint cov ) = 0; - virtual void setPoint( const Gaudi::XYZPoint pos, const Gaudi::SymMatrix3x3 cov ) = 0; - virtual void setPoint( const LHCb::Vertex* vert ) = 0; -}; - -#endif // DAVINCIKERNEL_ICALOPARTICLEMAKER_H diff --git a/Phys/DaVinciInterfaces/include/Kernel/ISetInputParticles.h b/Phys/DaVinciInterfaces/include/Kernel/ISetInputParticles.h deleted file mode 100644 index b475d3f400a29b2a9b0af3a3f7bdff033d9b6db4..0000000000000000000000000000000000000000 --- a/Phys/DaVinciInterfaces/include/Kernel/ISetInputParticles.h +++ /dev/null @@ -1,49 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -#ifndef KERNEL_ISETINPUTPARTICLES_H -# define KERNEL_ISETINPUTPARTICLES_H 1 -// ============================================================================ -// Include files -// ============================================================================ -// GaudiKernel -// ============================================================================ -# include "GaudiKernel/IInterface.h" -// ============================================================================ -// Event -// ============================================================================ -# include "Event/Particle.h" -// ============================================================================ -/** @class ISetInputParticles ISetInputParticles.h Kernel/ISetInputParticles.h - * - * A bit technical interface to allow some interactive manipulations - * with CombineParticlesa algorithm form python. - * - * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl - * @date 2008-07-11 - */ -struct GAUDI_API ISetInputParticles : extend_interfaces { - // ========================================================================== - /// interface machinery - DeclareInterfaceID( ISetInputParticles, 2, 0 ); - // ========================================================================== - /** the only one essential method: - * it sets the input particles - * @param input the vector of input particles - * @return status code - */ - virtual StatusCode setInput( const LHCb::Particle::ConstVector& input ) = 0; - // ========================================================================== -}; -// ============================================================================ -// The END -// ============================================================================ -#endif // KERNEL_ISETINPUTPARTICLES_H -// ============================================================================ diff --git a/Phys/DaVinciInterfaces/include/Kernel/ITrackIsolation.h b/Phys/DaVinciInterfaces/include/Kernel/ITrackIsolation.h deleted file mode 100644 index 3db989194ae423052491234ecd798696f8f862b1..0000000000000000000000000000000000000000 --- a/Phys/DaVinciInterfaces/include/Kernel/ITrackIsolation.h +++ /dev/null @@ -1,71 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -#ifndef KERNEL_ITRACKISOLATION_H -#define KERNEL_ITRACKISOLATION_H 1 - -// Include files - -// from STL -#include - -// from Gaudi -#include "GaudiKernel/IAlgTool.h" -#include -#include -#include - -/** - * @class ITrackIsolation ITrackIsolation.h Kernel/ITrackIsolation.h - * - * Abstract Interface of the Track Isolation tools - * - * @author Simone Bifani simone.bifani@cern.ch - * @date 2010-03-17 - */ - -struct GAUDI_API ITrackIsolation : extend_interfaces { - - DeclareInterfaceID( ITrackIsolation, 1, 0 ); - - /** - * trackConeMultiplicity method for the evaluation of - * the number of tracks/particles in a given range - * within a cone of given radius with respect to the - * seed track/protoparticle/particle - * - * The cone radius is defined as the difference in Eta - * and Phi between the seed track and a track in the - * range (same definition as in TupleToolTrackIsolation): - * - * R = sqrt (delta_Eta^2 + delta_Phi^2) - * - * The method returns the track multiplicity - */ - - virtual unsigned int trackConeMultiplicity( const LHCb::Track* seedTrack, const LHCb::Track::Range& eventTracks, - double coneRadius ) const = 0; - - virtual unsigned int trackConeMultiplicity( const LHCb::ProtoParticle* seedProtoParticle, - const LHCb::Track::Range& eventTracks, double coneRadius ) const = 0; - - virtual unsigned int trackConeMultiplicity( const LHCb::Particle* seedParticle, const LHCb::Track::Range& eventTracks, - double coneRadius ) const = 0; - - virtual unsigned int trackConeMultiplicity( const LHCb::ProtoParticle* seedProtoParticle, - const LHCb::Particle::Range& eventParticles, - double coneRadius ) const = 0; - - virtual unsigned int trackConeMultiplicity( const LHCb::Particle* seedParticle, - const LHCb::Particle::Range& eventParticles, - double coneRadius ) const = 0; -}; - -#endif // KERNEL_ITRACKISOLATION_H diff --git a/Phys/DaVinciInterfaces/src/DaVinciInterfaces.cpp b/Phys/DaVinciInterfaces/src/DaVinciInterfaces.cpp index 52b801c0c1ad3d14de4d7b129d6c19c32b7b2abd..5fd355504c40478ab5c828a3c463a3cc6996e794 100644 --- a/Phys/DaVinciInterfaces/src/DaVinciInterfaces.cpp +++ b/Phys/DaVinciInterfaces/src/DaVinciInterfaces.cpp @@ -30,8 +30,6 @@ #include "Kernel/IParticleValue.h" #include "Kernel/IParticleVeto.h" #include "Kernel/IPrintDecay.h" -#include "Kernel/ISetInputParticles.h" -#include "Kernel/ITrackIsolation.h" #include "Kernel/IVertexFit.h" // ============================================================================ /** @file diff --git a/Phys/DaVinciKernel/CMakeLists.txt b/Phys/DaVinciKernel/CMakeLists.txt index 9ecb9a3a057ccb478e36c6a79076a237c17dc380..d52fb408a67649c7bd20c276300d5804555f9754 100644 --- a/Phys/DaVinciKernel/CMakeLists.txt +++ b/Phys/DaVinciKernel/CMakeLists.txt @@ -13,32 +13,6 @@ Phys/DaVinciKernel ------------------ #]=======================================================================] -gaudi_add_library(DaVinciKernelLib - SOURCES - src/Lib/DaVinciFun.cpp - src/Lib/DaVinciStringUtils.cpp - src/Lib/Escape.cpp - src/Lib/GetDecay.cpp - src/Lib/GetTESLocations.cpp - src/Lib/PVSentry.cpp - src/Lib/ParticleFilters.cpp - src/Lib/TransporterFunctions.cpp - LINK - PUBLIC - Gaudi::GaudiAlgLib - Gaudi::GaudiKernel - LHCb::PartPropLib - LHCb::PhysEvent - LHCb::PhysInterfacesLib - LHCb::RecEvent - Rec::DaVinciInterfacesLib - Rec::DaVinciTypesLib - ROOT::GenVector - PRIVATE - Boost::headers - Boost::regex - LHCb::LHCbMathLib -) gaudi_add_module(DaVinciKernel SOURCES @@ -56,15 +30,8 @@ gaudi_add_module(DaVinciKernel LHCb::RecEvent LHCb::TrackEvent Rec::DaVinciInterfacesLib - Rec::DaVinciKernelLib ) -gaudi_add_dictionary(DaVinciKernelDict - HEADERFILES dict/DaVinciKernelDict.h - SELECTION dict/DaVinciKernelDict.xml - LINK DaVinciKernelLib - OPTIONS ${PHYS_DICT_GEN_DEFAULT_OPTS} -) if(BUILD_TESTING) foreach(n IN ITEMS 1 2 3) diff --git a/Phys/DaVinciKernel/dict/DaVinciKernelDict.h b/Phys/DaVinciKernel/dict/DaVinciKernelDict.h deleted file mode 100644 index d514447f914aa02399f221d8e406de4013e2785d..0000000000000000000000000000000000000000 --- a/Phys/DaVinciKernel/dict/DaVinciKernelDict.h +++ /dev/null @@ -1,33 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -// ============================================================================ -#ifndef DICT_DAVINCIKERNELDICT_H -# define DICT_DAVINCIKERNELDICT_H 1 -// ============================================================================ -// Include files -// ============================================================================ -/** @file DaVinciKernelDict - * - * - * @author Juan PALACIOS - * @date 2006-10-02 - */ -// ============================================================================ -// DaVinciKernel -// ============================================================================ -# include "Kernel/GetTESLocations.h" -# include "Kernel/ParticleFilters.h" -# include "Kernel/TransporterFunctions.h" -// ============================================================================ -// The END -// ============================================================================ -#endif // DICT_DAVINCIKERNELDICT_H -// ============================================================================ diff --git a/Phys/DaVinciKernel/dict/DaVinciKernelDict.xml b/Phys/DaVinciKernel/dict/DaVinciKernelDict.xml deleted file mode 100644 index 3edd27aa834f050b709e026fa0ce93e9323baf86..0000000000000000000000000000000000000000 --- a/Phys/DaVinciKernel/dict/DaVinciKernelDict.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - diff --git a/Phys/DaVinciKernel/include/Kernel/Arrow.h b/Phys/DaVinciKernel/include/Kernel/Arrow.h deleted file mode 100644 index b72a2b83c4679140a97af4b7437a3a79048fff53..0000000000000000000000000000000000000000 --- a/Phys/DaVinciKernel/include/Kernel/Arrow.h +++ /dev/null @@ -1,66 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2022 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ - -#ifndef ARROW_H -#define ARROW_H 1 - -#include -#include - -namespace Decay { - enum struct Arrow { - Unknown = 0, - Single, /// single arrow "->" - LongSingle, /// long single arrow "-->" - Double, /// double arrow "=>" - LongDouble, /// long double arrow "==>" - SingleX, /// single arrow "-x>" - LongSingleX, /// long single arrow "--x>" - DoubleX, /// double arrow "=x>" - LongDoubleX /// long double arrow "==x>" - }; - - static constexpr auto ValidArrows = - std::array{ Arrow::Single, Arrow::LongSingle, Arrow::Double, Arrow::LongDouble, - Arrow::SingleX, Arrow::LongSingleX, Arrow::DoubleX, Arrow::LongDoubleX }; - - /// string representation of the arrow - inline std::string toString( Arrow arrow ) { - switch ( arrow ) { - case Arrow::Unknown: - return "Unknown"; - case Arrow::Single: - return "->"; - case Arrow::LongSingle: - return "-->"; - case Arrow::Double: - return "=>"; - case Arrow::LongDouble: - return "==>"; - case Arrow::SingleX: - return "-x>"; - case Arrow::LongSingleX: - return "--x>"; - case Arrow::DoubleX: - return "=x>"; - case Arrow::LongDoubleX: - return "==x>"; - default: - return "None"; - } - } - - /// operator<< - inline std::ostream& operator<<( std::ostream& os, Arrow arrow ) { return os << toString( arrow ); } - -} // namespace Decay - -#endif // ARROW_H diff --git a/Phys/DaVinciKernel/include/Kernel/DaVinciFun.h b/Phys/DaVinciKernel/include/Kernel/DaVinciFun.h deleted file mode 100644 index 4f3a3ce01dfe290bc9175bcf43982db7768567b5..0000000000000000000000000000000000000000 --- a/Phys/DaVinciKernel/include/Kernel/DaVinciFun.h +++ /dev/null @@ -1,108 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -// ============================================================================ -#ifndef KERNEL_DAVINCIFUN_H -# define KERNEL_DAVINCIFUN_H 1 -// ============================================================================ -# include "Event/Particle.h" -# include "Event/RecVertex.h" -# include "Event/Vertex.h" -# include "Kernel/Functions.h" -# include "Kernel/Particle2Vertex.h" -# include "Kernel/ParticlePredicates.h" -# include "Math/Boost.h" -// ============================================================================ -/** @namespace DaVinci Kernel/DaVinciFun.h - * - * Collection of free functions used widely in DVAlgorithm - * - * @author Juan PALACIOS - * @date 2009-02-27 - */ -namespace DaVinci { - // ========================================================================== - /** - * delete contents of container of newed pointers unless they are - * also in the TES. - * T must be a const_iterator defined, begin(), end() and clear() methods, - * and holding pointers. - * - * @param container STL container of ContainedObject pointers - * @return number of elements that are also in the TES. - * - * @author Juan Palacios juan.palacios@nikhef.nl - * @date 10/02/2009 - * - */ - template - unsigned int safeContainerClear( T& container ) { - if ( container.empty() ) return 0; - int iCount( 0 ); - for ( typename T::const_iterator iObj = container.begin(); iObj != container.end(); ++iObj ) { - if ( DaVinci::Utils::inTES( *iObj ) ) { - ++iCount; - } else { - delete *iObj; - } - } - container.clear(); - return iCount; - } - // ========================================================================== - /// Return the best VertexBase given a Particle->VertexBase relations range. - GAUDI_API - const LHCb::VertexBase* bestVertexBase( const Particle2Vertex::Table::Range& range ); - // ========================================================================== - /// Return the best RecVertex given a Particle->VertexBase relations range. - GAUDI_API - const LHCb::RecVertex* bestRecVertex( const Particle2Vertex::Table::Range& range ); - // ========================================================================== - namespace Utils { - // ======================================================================== - /** set the input particles for some component - * @param component the component inself - * @param input the intut data - * @return status code - * - * - 300 : invalid component - * - 301 : no valid ISetInputParticles interface - * - * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl - * @date 2008-07-11 - */ - GAUDI_API - StatusCode setInput( IInterface* component, const LHCb::Particle::ConstVector& input ); - // ======================================================================== - - // ======================================================================== - /// Add Particles and Vertices in the decay of a particle to vectors. - /// Entries are only added uniquely. - /// - /// @param head (INPUT) The head of the decay. - /// @param particles (UPDATE) Add particles in the decay. - /// @param vertices (UPDATE) Add Vertices in the decay. - /// @param truncate Predicate that decides where to stop recursion. If true, do not follow decay branch. - GAUDI_API - void findDecayTree( const LHCb::Particle* head, LHCb::Particle::ConstVector& particles, - LHCb::Vertex::ConstVector& vertices, DaVinci::Utils::IParticlePredicate* truncate = 0 ); - - // ======================================================================== - GAUDI_API - bool decayTreeInTES( const LHCb::Particle* head ); - // ======================================================================== - } // namespace Utils - // ========================================================================== -} // namespace DaVinci -// ============================================================================ -#endif // KERNEL_DAVINCIFUN_H -// ============================================================================ -// The END -// ============================================================================ diff --git a/Phys/DaVinciKernel/include/Kernel/DaVinciStringUtils.h b/Phys/DaVinciKernel/include/Kernel/DaVinciStringUtils.h deleted file mode 100644 index b003d0ead9b2d8e78337c0393051166b43e64fcb..0000000000000000000000000000000000000000 --- a/Phys/DaVinciKernel/include/Kernel/DaVinciStringUtils.h +++ /dev/null @@ -1,103 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -#ifndef KERNEL_DAVINCISTRINGUTILS_H -#define KERNEL_DAVINCISTRINGUTILS_H 1 - -// Include files - -#include -#include -/** @file StringUtils.h - * - * Namespace for functions dealing with string manipulations for DaVinci - * components. - * - * @author Juan PALACIOS - * @date 2006-06-19 - */ -namespace DaVinci { - namespace StringUtils { - - /** Strip particle name down to basic type. - * Strips off any "+", "-", "~", "anti-" from an std::string. - * - * Example: mu+ -> mu, Delta++ -> Delta, anti-nu_tau -> nu_tau - * - * @code - * std::string myParticleName("tau+"); - * DaVinci::StringUtils::stripParticleName(myParticleName); - * @endcode - * - * @param name (input) string to be stripped. - */ - - void stripParticleName( std::string& name ); - - /** - * - * Add leading prefix +"/" string to input locations, - * unless these contain a "/", in which case leave them untouched. - * Examples: - * - * "MyBsSelection" becomes "Phys/MyBsSelection" if prefix = "Phys" - * - * "Phys/MyBsSelection" remains unchanged. - * "Anything/MyBsSelection" remains unchanged. - * "/MyBsSelection" remains unchanged, but is most likely an error! - * - * - * @author Juan Palacios juan.palacios@nikhef.nl - * @date 2008-10-31 - * - */ - void expandLocations( std::vector::iterator begin, std::vector::iterator end, - const std::string& prefix ); - - /** - * - * Add leading prefix +"/" string to input location, - * unless these contain a "/", in which case leave them untouched. - * Examples: - * - * "MyBsSelection" becomes "Phys/MyBsSelection" if prefix = "Phys" - * - * "Phys/MyBsSelection" remains unchanged. - * "Anything/MyBsSelection" remains unchanged. - * "/MyBsSelection" remains unchanged, but is most likely an error! - * - * - * @author Juan Palacios juan.palacios@nikhef.nl - * @date 2008-10-31 - * - */ - void expandLocation( std::string& location, const std::string& prefix ); - - /** - * @author Juan Palacios juan.palacios@cern.ch - * - * Remove end of string starting from substring beginning with ending - * - * Examples: - * - * @code - * std::string loc = "Phys/SomeAlgorithm/Particles" - * removeEnding(loc, "/Part") - * @endcode - * transforms "loc" into "Phys/SomeAlgorithm" - * - * @date 2010-06-21 - * - */ - void removeEnding( std::string& location, const std::string& ending ); - - } // namespace StringUtils -} // namespace DaVinci -#endif // KERNEL_DAVINCISTRINGUTILS_H diff --git a/Phys/DaVinciKernel/include/Kernel/DefaultDVToolTypes.h b/Phys/DaVinciKernel/include/Kernel/DefaultDVToolTypes.h deleted file mode 100644 index 1ae0e49ab9b6a1b7678b91b92190e6729dd77899..0000000000000000000000000000000000000000 --- a/Phys/DaVinciKernel/include/Kernel/DefaultDVToolTypes.h +++ /dev/null @@ -1,27 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -#ifndef KERNEL_DEFAULTTOOLTYPES_H -#define KERNEL_DEFAULTTOOLTYPES_H 1 - -#include - -namespace DaVinci { - namespace DefaultTools { - static const std::string Distance = "LoKi::DistanceCalculator:PUBLIC"; - static const std::string VertexFitter = "LoKi::VertexFitter:PUBLIC"; - static const std::string ParticleCombiner = "LoKi::VertexFitter:PUBLIC"; - static const std::string PVRelator = - "GenericParticle2PVRelator<_p2PVWithIPChi2, OfflineDistanceCalculatorName>/P2PVWithIPChi2:PUBLIC"; - static const std::string ParticleReFitter = "LoKi::VertexFitter:PUBLIC"; - } // namespace DefaultTools -} // namespace DaVinci - -#endif // KERNEL_DEFAULTTOOLTYPES_H diff --git a/Phys/DaVinciKernel/include/Kernel/Escape.h b/Phys/DaVinciKernel/include/Kernel/Escape.h deleted file mode 100644 index 5d22bc52c28ea1b7083c7ac8d58ab426c7ac6e13..0000000000000000000000000000000000000000 --- a/Phys/DaVinciKernel/include/Kernel/Escape.h +++ /dev/null @@ -1,37 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -// ============================================================================ -#ifndef DAVINCIKERNEL_ESCAPE_H -# define DAVINCIKERNEL_ESCAPE_H 1 -// ============================================================================ -// Include files -// ============================================================================ -// STD & STL -// ============================================================================ -# include -# include -// ============================================================================ -namespace Decays { - // ========================================================================== - /** Replace all special characters in a particle name - * - * @author J. Borel - * @author P. Koppenburg : Move to DaVinciKernel - * - */ - std::string escape( const std::string& input ); - // ========================================================================== -} // end of namespace Decays -// ============================================================================ -// The END -// ============================================================================ -#endif // DAVINCIKERNEL_ESCAPE_H -// ============================================================================ diff --git a/Phys/DaVinciKernel/include/Kernel/Functions.h b/Phys/DaVinciKernel/include/Kernel/Functions.h deleted file mode 100644 index d7cab6d32a57d03f9859532747d47e995d0c7c51..0000000000000000000000000000000000000000 --- a/Phys/DaVinciKernel/include/Kernel/Functions.h +++ /dev/null @@ -1,38 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -#ifndef DAVINCIKERNEL_FUNCTIONS_H -#define DAVINCIKERNEL_FUNCTIONS_H 1 - -/** @namespace DaVinci::Utils Kernel/Functions.h - * - * General helper functions for use in DaVinci. - * These should only know about Gaudi classes and patterns. - * No knowledge of DaVinci specific code should be assumed. - * - * @author Juan PALACIOS palacios@uzh.uzh.ch - * @date 2010-09-21 - */ - -namespace DaVinci { - - namespace Utils { - - /// Is obj in TES - template - inline bool inTES( const T* obj ) { - return ( 0 != obj && 0 != obj->parent() ); - } - - } // namespace Utils - -} // namespace DaVinci - -#endif // DAVINCIKERNEL_FUNCTIONS_H diff --git a/Phys/DaVinciKernel/include/Kernel/Functors.h b/Phys/DaVinciKernel/include/Kernel/Functors.h deleted file mode 100644 index a2030bc8cae4bea678f3f02b418272a815c6717e..0000000000000000000000000000000000000000 --- a/Phys/DaVinciKernel/include/Kernel/Functors.h +++ /dev/null @@ -1,47 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -#ifndef DAVINCIUTILS_FUNCTORS_H -#define DAVINCIUTILS_FUNCTORS_H 1 - -#include - -/** @class Functors Functors.h Kernel/Functors.h - * - * General helper functions for use in DaVinci. - * These should only know about Gaudi classes and patterns. - * No knowledge of DaVinci specific code should be assumed. - * - * - * @author Juan Palacios - * @date 2011-01-10 - */ - -namespace DaVinci { - namespace Utils { - struct InTES { - inline bool operator()( const ContainedObject* obj ) const { return ( 0 != obj && 0 != obj->parent() ); } - }; - - /// Return true for all objects. - template - struct TRUE { - inline bool operator()( const T* ) { return true; } - }; - - /// Return false for all objects. - template - struct FALSE { - inline bool operator()( const T* ) { return false; } - }; - } // namespace Utils -} // namespace DaVinci - -#endif // DAVINCIUTILS_FUNCTORS_H diff --git a/Phys/DaVinciKernel/include/Kernel/GetParticlesForDecay.h b/Phys/DaVinciKernel/include/Kernel/GetParticlesForDecay.h deleted file mode 100644 index d347340f9b68668c72b693fe520189b65d1fdd42..0000000000000000000000000000000000000000 --- a/Phys/DaVinciKernel/include/Kernel/GetParticlesForDecay.h +++ /dev/null @@ -1,97 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -// ============================================================================ -#ifndef DAVINCIKERNEL_GETPARTICLESFORDECAY_H -# define DAVINCIKERNEL_GETPARTICLESFORDECAY_H 1 -// ============================================================================ -// Include files -// ============================================================================ -// STD & STL -// ============================================================================ -# include -# include -// ============================================================================ -// PartProp -// ============================================================================ -# include "Kernel/Decay.h" -// ============================================================================ -namespace DaVinci { - // ========================================================================== - namespace Utils { - // ======================================================================== - /** simple function for filtering (by PID) the particles, which - * matched the PID - * - * @code - * - * const LHCb::Particle::ConstVector input = ... ; - * const Decays::Decay& decay = ... ; - * - * LHCb::Particle::ConstVector result ; - * - * // use the function: - * - * DaVinci::Utils::getParticles - * ( input . begin () , - * input . end () , - * decay ( 1 ) , // get the first component - * std::back_inserter ( result ) ) ; - * - * @endcode - * - * It is also applicable to Monte-Carlo data: - * - * @code - * - * const LHCb::MCParticle::ConstVector input = ... ; - * const Decays::Decay& decay = ... ; - * - * LHCb::MCParticle::ConstVector result ; - * - * // use the function: - * - * DaVinci::Utils::getParticles - * ( input . begin () , - * input . end () , - * decay ( 1 ) , // get the first component - * std::back_inserter ( result ) ) ; - * - * @endcode - * - * @param begin the begin iterator for the input sequence - * @param end the end iterator for the input sequence - * @param item the decay component - * @param result the output iterator - * @return the updated output iterator - * - * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl - * @date 2008-03-31 - */ - template - inline OUTPUT getParticles( INPUT begin, INPUT end, const Decays::Decay::Item& item, OUTPUT result ) { - for ( ; begin != end; ++begin ) { - if ( !( *begin ) ) { continue; } // CONTINUE - const LHCb::ParticleID& pid = ( *begin )->particleID(); - if ( pid != item.pid() ) { continue; } // CONTINUE - *result = *begin; - ++result; - } - return result; - } - // ======================================================================== - } // namespace Utils - // ========================================================================== -} // end of namespace DaVinci -// ============================================================================ -// The END -// ============================================================================ -#endif // DAVINCIKERNEL_GETPARTICLESDECAY_H -// ============================================================================ diff --git a/Phys/DaVinciKernel/include/Kernel/GetTESLocations.h b/Phys/DaVinciKernel/include/Kernel/GetTESLocations.h deleted file mode 100644 index 2b92d93f476f9b842f4169860955087ac998ab2a..0000000000000000000000000000000000000000 --- a/Phys/DaVinciKernel/include/Kernel/GetTESLocations.h +++ /dev/null @@ -1,121 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -// ============================================================================ -#ifndef KERNEL_GETTESLOCATIONS_H -# define KERNEL_GETTESLOCATIONS_H 1 -// ============================================================================ -// Include files -// ============================================================================ -// STD& STL -// ============================================================================ -# include -# include -# include -// ============================================================================ -// GaudiKernel -// ============================================================================ -# include "GaudiKernel/Kernel.h" -// ============================================================================ -// PhysEvent -// ============================================================================ -# include "Event/Particle.h" -// ============================================================================ -namespace DaVinci { - // ========================================================================== - namespace Utils { - // ======================================================================== - /** @class GetTESLocations Kernel/GetTESLocations.h - * - * @author Vanya Belyaev - * @date 2016-02-16 - */ - class GAUDI_API GetTESLocations { - public: - // ====================================================================== - /// Standard constructor - GetTESLocations( const DataObject* o = 0 ) : m_mapping(), m_locations() { - if ( nullptr != o ) { _collect( o ); } - } - /// constructor from constained obejct - GetTESLocations( const LHCb::Particle* o ) : m_mapping(), m_locations() { - if ( nullptr != o ) { collect( o ); } - } - template - GetTESLocations( OBJECT begin, OBJECT end ) : m_mapping(), m_locations() { - collect( begin, end ); - } - // ====================================================================== - /// destructor - ~GetTESLocations(); - // ====================================================================== - public: - // ====================================================================== - /// add TES-location - inline std::size_t collect( const DataObject* o ); - /// add TES-location - inline std::size_t collect( const LHCb::Particle* p ); - /// add TES-location - template - inline std::size_t collect( OBJECT begin, OBJECT end ); - // ====================================================================== - public: // get the collected locations - // ====================================================================== - const std::vector& locations() const { return m_locations; } - // ====================================================================== - protected: - // ====================================================================== - /// add TES-location - std::size_t _collect( const DataObject* o ); - // ====================================================================== - private: - // ====================================================================== - /// mapping: data object -> tes location - std::map m_mapping; - /// the list of locations - std::vector m_locations; - // ====================================================================== - }; - // ======================================================================== - // add TES-location for the particle - // ======================================================================== - inline std::size_t GetTESLocations::collect( const LHCb::Particle* p ) { - std::size_t _added = 0; - if ( nullptr == p ) { return 0; } // nothing to add - const DataObject* c = p->parent(); - if ( nullptr == c ) { return 0; } // nothing to add - if ( m_mapping.end() == m_mapping.find( c ) ) { _added += _collect( c ); } - const SmartRefVector& dd = p->daughters(); - return _added + collect( dd.begin(), dd.end() ); - } - // ======================================================================== - // add TES-location for parent container - // ======================================================================== - inline std::size_t GetTESLocations::collect( const DataObject* c ) { - return nullptr == c ? 0 : m_mapping.end() != m_mapping.find( c ) ? 0 : _collect( c ); - } - // ======================================================================== - // add TES-location for particle - // ======================================================================== - template - inline std::size_t GetTESLocations::collect( OBJECT begin, OBJECT end ) { - std::size_t _added = 0; - for ( ; begin != end; ++begin ) { _added += collect( *begin ); } - return _added; - } - // ======================================================================== - } // namespace Utils - // ========================================================================== -} // end of namespace DaVinci -// ============================================================================ -// The END -// ============================================================================ -#endif // KERNEL_GETTESLOCATIONS_H -// ============================================================================ diff --git a/Phys/DaVinciKernel/include/Kernel/Guards.h b/Phys/DaVinciKernel/include/Kernel/Guards.h deleted file mode 100644 index 3f208c2914f7356ac198a4e6b3ac87f691c2e9b7..0000000000000000000000000000000000000000 --- a/Phys/DaVinciKernel/include/Kernel/Guards.h +++ /dev/null @@ -1,108 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -#ifndef DAVINCIKERNEL_GUARDS_H -#define DAVINCIKERNEL_GUARDS_H 1 - -#include "GaudiKernel/DataObject.h" -#include "Kernel/Functions.h" - -/** @namespace DaVinci::Utils Kernel/Guards.h - * - * General helper functions and classes for use in DaVinci. - * These should only know about Gaudi classes and patterns. - * No knowledge of DaVinci specific code should be assumed. - * - * @author Juan PALACIOS palacios@uzh.uzh.ch - * @date 2010-09-21 - */ - -namespace DaVinci { - - namespace Utils { - - /** - * - * Guard for container of newed pointers. Delete each item in a container of - * newed pointers. - * - * T must be a const_iterator defined, begin(), end() and clear() methods, - * and holding pointers. - * - * @author Juan Palacios juan.palacios@nikhef.nl - * @date 31/08/2009 - * - **/ - template - class PointerContainerGuard { - public: - explicit PointerContainerGuard( T& container ) : m_container( container ) {} - - ~PointerContainerGuard() { - for ( auto* obj : m_container ) delete obj; - m_container.clear(); - } - - private: - T& m_container; - }; - - /** - * - * Guard for container of newed pointers. Delete each item in a container of - * newed pointers unless they are also in the TES. - * - * T must be a const_iterator defined, begin(), end() and clear() methods, - * and holding pointers. - * - * - * @author Juan Palacios juan.palacios@nikhef.nl - * @date 01/09/2009 - * - **/ - template - class OrphanPointerContainerGuard { - public: - explicit OrphanPointerContainerGuard( T& container ) : m_container( container ) {} - - ~OrphanPointerContainerGuard() { - for ( auto* obj : m_container ) { - if ( !DaVinci::Utils::inTES( obj ) ) delete obj; - } - m_container.clear(); - } - - private: - T& m_container; - }; - - /** - * Call the container's clear() method when going out of scope. - * - * @author Juan Palacios palacios@physik.uzh.ch - * @date 2011-01-07 - * - **/ - template - class ClearContainerGuard { - public: - explicit ClearContainerGuard( T& container ) : m_container( container ) {} - - ~ClearContainerGuard() { m_container.clear(); } - - private: - T& m_container; - }; - - } // namespace Utils - -} // namespace DaVinci - -#endif // KERNEL_DAVINCIGUARDS_H diff --git a/Phys/DaVinciKernel/include/Kernel/Node.h b/Phys/DaVinciKernel/include/Kernel/Node.h deleted file mode 100644 index b510bdc94acc7dc4b1fcb16f6c27125d3aa5c7ca..0000000000000000000000000000000000000000 --- a/Phys/DaVinciKernel/include/Kernel/Node.h +++ /dev/null @@ -1,250 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2022 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -#pragma once - -#include "Event/MCParticle.h" -#include "Event/Particle.h" -#include "GaudiKernel/GaudiException.h" -#include "GaudiKernel/IMessageSvc.h" -#include "GaudiKernel/MsgStream.h" -#include "GaudiKernel/ServiceHandle.h" -#include "Kernel/IParticlePropertySvc.h" -#include "Kernel/ParticleProperty.h" -#include -#include -#include -#include -#include - -namespace Decay { - - namespace detail { - /// check if node is marked with ^ (invoked in constructor) - bool checkisMarked( std::string_view node_name ) { - // output true if the expression has a "^" - return node_name.find( '^' ) != node_name.npos; - }; - - /// check if node has CC (invoked in constructor) - bool checkhasCC( std::string_view node_name ) { - // output true if the expression has "CC" - return node_name.find( "CC" ) != node_name.npos; - } - - /// prune the node from operators and returns the particle name only (invoked in constructor) - std::tuple pruneNodeName( const std::string& node_name ) { // TODO: make sure this - // is well - // documented - std::string pruned_node_name; - bool hasCC = checkhasCC( node_name ); - bool isMarked = checkisMarked( node_name ); - // cleans the nodes from operators and returns the particle name only - constexpr auto expression = []( bool cc, bool marked ) { - if ( cc && marked ) { // if node has self CC and is marked - return std::regex( "\\^" // hat - "\\s*\\[" // any whitespaces and a square bracket - "\\s*(\\S+)\\s*" // any whitespace then one or more non-whitespace character(s) - // that is matched "(\\S+)" then any whitespace - "\\]\\s*CC" // closing square bracket then any whitespace and then a CC - ); - } else if ( cc && !marked ) { // if node has self CC - return std::regex( "\\[" // square bracket - "\\s*(\\S+)\\s*" // any whitespace then one or more non-whitespace character(s) - // that is matched "(\\S+)" then any whitespace - "\\]\\s*CC" // closing square bracket then any whitespace and then a CC - ); - } else if ( !cc && marked ) { // if node is marked - return std::regex( "\\^" // hat - "\\s*(\\S+)\\s*" // any whitespace then one or more non-whitespace character(s) - // that is matched "(\\S+)" then any whitespace - ); - } else { - return std::regex( "^\\s*" // any initial whitespaces - "(\\S+)" // matches particle name - "\\s*$" // any final whitespaces - ); - } - }; - - std::smatch what; - std::regex_search( node_name, what, expression( hasCC, isMarked ) ); - return std::make_tuple( what.str( 1 ), hasCC, isMarked ); - } - } // namespace detail - - class Node { - public: - /// constructors - Node( const std::string& node_name ); - Node( const int pid, const bool hasCC, const bool isMarked ); - Node( const LHCb::Particle& ); - Node( const LHCb::MCParticle& ); - - /// get charge conjugated node - Node getChargeConjugate( bool reversehasCC = false ) const; - /// reverse the has CC flag - void reversehasCC() { m_hasCC = !m_hasCC; } - /// get the possibilities of the node i.e. [mu+]CC should give vec(mu+, mu-) - std::vector getPossibilities() const; - /// get particle name - std::string name() const { return getNameFromPid( m_pid ); } - - /* getters */ - /// get particle id - int pid() const { return m_pid; } - /// get has CC flag - bool hasCC() const { return m_hasCC; } - /// get is marked flag with ^ - bool isMarked() const { return m_isMarked; } - - /* setters */ - /// set pid - void setpid( const int& pid ) { m_pid = pid; } - /// set CC flag - void sethasCC( const bool& cc ) { m_hasCC = cc; } - /// set marked flag - void setisMarked( const bool& marked ) { m_isMarked = marked; } - - /* operator */ - /// operator << implementations - friend std::ostream& operator<<( std::ostream& os, const Node& node ); - /// operator == implementations - friend bool operator==( const Node& lhs, const Node& rhs ); - /// non-templated class implementation, comparaison between a Particle and a Node - template - friend bool operator==( const Node& lhs, const PARTICLE* const rhs ); - - private: - /// get pid from name - int getPidFromName( const std::string& node_name ) const; - /// get pid from name - std::string getNameFromPid( int pid ) const; - /// get antiparticle pid - int getAntiParticlePid( int pid ) const; - - /// node ID - int m_pid = 0; - /// check if node has CC - bool m_hasCC = false; - /// node marked with ^ - bool m_isMarked = false; - /// messaging service - ServiceHandle m_msgSvc{ "MessageSvc", "MessageSvcName" }; - /// particle property service - //"LHCb::" prefix in string since its defined in namespace! - ServiceHandle m_ppSvc{ "LHCb::ParticlePropertySvc", "LHCb::ParticlePropertySvcName" }; - }; - - Node::Node( const std::string& node_name ) { - auto tuple_nodeprops = detail::pruneNodeName( node_name ); - m_pid = getPidFromName( std::get<0>( tuple_nodeprops ) ); - m_hasCC = std::get<1>( tuple_nodeprops ); - m_isMarked = std::get<2>( tuple_nodeprops ); - } - - // constructor for Node with pid, hasCC and isMarked - Node::Node( const int pid, const bool hasCC, const bool isMarked ) - : m_pid{ pid }, m_hasCC{ hasCC }, m_isMarked{ isMarked } {} - - Node::Node( LHCb::Particle const& particle ) : Node{ particle.particleID().pid(), false, false } {} - - Node::Node( LHCb::MCParticle const& mcparticle ) : Node{ mcparticle.particleID().pid(), false, false } {} - - Node Node::getChargeConjugate( bool reversehasCC ) const { // get charge conjugated node - // make a copy of the current node - Node node_cc{ *this }; - // set the pid of the antiparticle - node_cc.setpid( getAntiParticlePid( m_pid ) ); - // reverse the hasCC flag (if requested) as it can help with - // the recursive calling of operator== - if ( reversehasCC ) node_cc.reversehasCC(); - return node_cc; - } - - int Node::getAntiParticlePid( int pid ) const { - // get the particle property of the node - const auto* part_prop = m_ppSvc->find( LHCb::ParticleID( pid ) ); // ptr to LHCb::ParticleProperty - if ( !part_prop ) - throw GaudiException{ "Could not interpret the particle ID " + std::to_string( pid ) + - ". Please check your descriptor.", - "Decay::Node::getChargeConjugate()", StatusCode::FAILURE }; - - // get antiparticle pid of the current node - const auto* part_prop_cc = part_prop->antiParticle(); - if ( !part_prop_cc ) - throw GaudiException{ "Could not find antiparticle of the particle with ID " + std::to_string( pid ) + - ". Please check your descriptor.", - "Decay::Node::getChargeConjugate()", StatusCode::FAILURE }; - - return part_prop_cc->pid().pid(); - } - - /// returns a vector of node possibilities based on the CC property of the Node - std::vector Node::getPossibilities() const { - // set hasCC property to false for all possibilities because we want vector of "simple" nodes - if ( m_hasCC ) { - return { Node{ m_pid, false, m_isMarked }, Node{ getAntiParticlePid( m_pid ), false, m_isMarked } }; - } - return { Node{ m_pid, false, m_isMarked } }; - } - - int Node::getPidFromName( const std::string& name ) const { - const auto* part_prop = m_ppSvc->find( name ); // ptr to LHCb::ParticleProperty - if ( !part_prop ) - throw GaudiException{ "Could not interpret the node name " + name + ". Please check your descriptor.", - "Decay::Node::getPidFromName()", StatusCode::FAILURE }; - return part_prop->pid().pid(); - } - - std::string Node::getNameFromPid( int pid ) const { - const auto* part_prop = m_ppSvc->find( LHCb::ParticleID( pid ) ); // ptr to LHCb::ParticleProperty - if ( !part_prop ) - throw GaudiException{ "Could not interpret the particle ID " + std::to_string( pid ) + - ". Please check your descriptor.", - "Decay::Node::getNameFromPid()", StatusCode::FAILURE }; - return part_prop->name(); - } - - std::ostream& operator<<( std::ostream& os, const Node& node ) { - if ( node.m_hasCC ) { - if ( node.m_isMarked ) - os << "^[" << node.name() << "]CC"; - else - os << "[" << node.name() << "]CC"; - } else if ( node.m_isMarked ) - os << "^" << node.name(); - else - os << node.name(); - return os; - } - - bool operator==( const Node& lhs, const Node& rhs ) { - if ( lhs.m_pid == rhs.m_pid ) return true; - - bool reversehasCC = true; - if ( lhs.m_hasCC ) { - // Return a copy of this node with charged conjugate node and hasCC flag set to false - // hasCC flag has to be false otherwise stuck in infinite loop - return rhs == lhs.getChargeConjugate( reversehasCC ); - } else if ( rhs.m_hasCC ) { - // Return a copy of this node with charged conjugate node and hasCC flag set to false - // hasCC flag has to be false otherwise stuck in infinite loop - return lhs == rhs.getChargeConjugate( reversehasCC ); - } - return false; - } - - template - bool operator==( const Node& lhs, const PARTICLE* const rhs ) { - return lhs.m_pid == rhs->particleID().pid(); - } - -} // namespace Decay diff --git a/Phys/DaVinciKernel/include/Kernel/PP2MCLocation.h b/Phys/DaVinciKernel/include/Kernel/PP2MCLocation.h deleted file mode 100644 index abaf4d78d2830ea4c5a5cc4e59b066a53a3f5582..0000000000000000000000000000000000000000 --- a/Phys/DaVinciKernel/include/Kernel/PP2MCLocation.h +++ /dev/null @@ -1,29 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -#ifndef KERNEL_PP2MCLOCATION_H -#define KERNEL_PP2MCLOCATION_H 1 - -#include -#include - -namespace LHCb { - /** @namespace ProtoParticle2MCLocation PP2MCLocation.h Kernel/PP2MCLocation.h - * - * - * @author Juan PALACIOS - * @date 2006-08-18 - */ - namespace ProtoParticle2MCLocation { - const std::string Charged = "Relations/" + LHCb::ProtoParticleLocation::Charged; - const std::string Neutrals = "Relations/" + LHCb::ProtoParticleLocation::Neutrals; - } // namespace ProtoParticle2MCLocation -} // namespace LHCb -#endif // KERNEL_PP2MCLOCATION_H diff --git a/Phys/DaVinciKernel/include/Kernel/PVSentry.h b/Phys/DaVinciKernel/include/Kernel/PVSentry.h deleted file mode 100644 index 26ebbc2f82171b386d2c6c9f658dcb74521e5ea7..0000000000000000000000000000000000000000 --- a/Phys/DaVinciKernel/include/Kernel/PVSentry.h +++ /dev/null @@ -1,54 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2000-2023 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -// ============================================================================ -#pragma once - -#include -#include - -struct IDVAlgorithm; -namespace LHCb { - class Particle; -} -// =========================================================================== -namespace DaVinci { - // ========================================================================== - /** @class PVSentry - * Helper class to guarantee the removal of relations to the - * temporary object - * - * The class is moved from CombineParticles - * - * @author Vanya BELYAEV Ivan.Belyaev@itep.ru - * @date 2009-05-05 - */ - class GAUDI_API PVSentry { - // ======================================================================== - public: - // ======================================================================== - /** constructor - * @param parent the davinci algorithm that holds relation tables - * @param particle the particle - */ - PVSentry( const IDVAlgorithm* parent, const LHCb::Particle* particle, const bool tree = false ); - /// destructor - ~PVSentry(); - // ======================================================================== - private: - // ======================================================================== - /// the parent - const IDVAlgorithm* m_parent; - /// the temporary particle - std::vector m_particles; - // ======================================================================== - }; - // ========================================================================== -} // namespace DaVinci diff --git a/Phys/DaVinciKernel/include/Kernel/ParticleFilters.h b/Phys/DaVinciKernel/include/Kernel/ParticleFilters.h deleted file mode 100644 index 4440788e6ffac863d78a59404b7fe8dde22300d3..0000000000000000000000000000000000000000 --- a/Phys/DaVinciKernel/include/Kernel/ParticleFilters.h +++ /dev/null @@ -1,373 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -// ============================================================================ -#ifndef KERNEL_PARTICLEFILTERS_H -# define KERNEL_PARTICLEFILTERS_H 1 -// ============================================================================ -// Include files -// ============================================================================ -// GaudiKernel -// ============================================================================ -# include "GaudiKernel/Kernel.h" -// ============================================================================ -// PhysEvent -// ============================================================================ -# include "Event/Particle.h" -// ============================================================================ -// DaVinciInterfaces -// ============================================================================ -# include "Kernel/IParticleFilter.h" -// ============================================================================ -namespace DaVinci { - // ========================================================================== - /** filter the particles according to some criteria - * - * As criteria one can use e.g. any LoKi-functor: - * - * @code - * - * #include "LoKi/ParticleCuts.h" - * - * ... - * - * const LHCb::Particle::Range input = ... ; - * - * using namespace LoKi::Cuts ; - * - * // filter negative - * LHCb::Particle::ConstVector negative ; - * DaVinci::filter ( input , Q < 0 , negative ) ; - * - * // filter pions - * LHCb::Particle::ConstVector pions ; - * DaVinci::filter ( input , "pi+" == ID , pions ) ; - * - * @endcode - * - * Also many boost::lambda idioms can be used: - * - * @code - * - * #include - * #include - * - * ... - * - * const LHCb::Particle::Range input = ... ; - * - * using namespace boost::lambda ; - * - * // filter negative - * LHCb::Particle::ConstVector negative ; - * DaVinci::filter ( input , - * bind(&LHCb::Particle::charge,_1) < 0 , negative ) ; - * - * // filter J/psi - * LHCb::Particle::ConstVector jpsis ; - * const LHCb::ParticleID s_pid ( 443 ) ; - * DaVinci::filter ( input , - * bind(&LHCb::Particle::particleID,_1) == s_pid , psis ) ; - * - * @endcode - * - * @param input (INPUT) the container of input particles - * @param criterion (INPUT) the selection criteria - * @param output (OUPUT) the container of selected particles - * @return number of added particles - * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl - * @date 2010-05-14 - */ - template - std::size_t filter( const LHCb::Particle::Range& input, const PREDICATE& criterion, - LHCb::Particle::ConstVector& output ) { - std::size_t added = 0; - for ( LHCb::Particle::ConstVector::const_iterator ip = input.begin(); input.end() != ip; ++ip ) { - if ( criterion( *ip ) ) { - output.push_back( *ip ); - ++added; - } - } - return added; - } - // ========================================================================== - /** filter the particles according to some criteria - * - * As criteria one can use e.g. any LoKi-functor: - * - * @code - * - * #include "LoKi/ParticleCuts.h" - * - * ... - * - * const LHCb::Particle::ConstVector input = ... ; - * - * using namespace LoKi::Cuts ; - * - * // filter negative - * LHCb::Particle::ConstVector negative ; - * DaVinci::filter ( input , Q < 0 , negative ) ; - * - * // filter pions - * LHCb::Particle::ConstVector pions ; - * DaVinci::filter ( input , "pi+" == ID , pions ) ; - * - * @endcode - * - * Also many boost::lambda idioms can be used: - * - * @code - * - * #include - * #include - * - * ... - * - * const LHCb::Particle::ConstVector input = ... ; - * - * using namespace boost::lambda ; - * - * // filter negative - * LHCb::Particle::ConstVector negative ; - * DaVinci::filter ( input , - * bind(&LHCb::Particle::charge,_1) < 0 , negative ) ; - * - * // filter J/psi - * LHCb::Particle::ConstVector jpsis ; - * const LHCb::ParticleID s_pid ( 443 ) ; - * DaVinci::filter ( input , - * bind(&LHCb::Particle::particleID,_1) == s_pid , psis ) ; - * - * @endcode - * - * - * @param input (INPUT) the container of input particles - * @param criterion (INPUT) the selection criteria - * @param output (OUPUT) the container of selected particles - * @return number of added particles - * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl - * @date 2010-05-14 - */ - template - std::size_t filter( const LHCb::Particle::ConstVector& input, const PREDICATE& criterion, - LHCb::Particle::ConstVector& output ) { - return filter( LHCb::Particle::Range( input ), criterion, output ); - } - // ========================================================================== - /** split the particles into two containers according some criteria - * - * As criteria one can use e.g. any LoKi-functor: - * - * @code - * - * #include "LoKi/ParticleCuts.h" - * - * ... - * - * const LHCb::Particle::Range input = ... ; - * - * using namespace LoKi::Cuts ; - * - * // split into negative & positive - * LHCb::Particle::ConstVector negative ; - * LHCb::Particle::ConstVector positive ; - * DaVinci::filter ( input , Q < 0 , negative , positive ) ; - * - * // split into positive pions & others - * LHCb::Particle::ConstVector pions ; - * LHCb::Particle::ConstVector other ; - * DaVinci::filter ( input , "pi+" == ID , pions , other ) ; - * - * @endcode - * - * Also many boost::lambda idioms can be used: - * - * @code - * - * #include - * #include - * - * ... - * - * const LHCb::Particle::Range input = ... ; - * - * using namespace boost::lambda ; - * - * // split into negative & positive - * LHCb::Particle::ConstVector negative ; - * LHCb::Particle::ConstVector positive ; - * DaVinci::filter ( input , - * bind(&LHCb::Particle::charge,_1) < 0 , - * negative , positive ) ; - * - * // split into J/psi and others - * const LHCb::ParticleID s_pid ( 443 ) ; - * LHCb::Particle::ConstVector jpsis ; - * LHCb::Particle::ConstVector other ; - * DaVinci::filter ( input , - * bind(&LHCb::Particle::particleID,_1) == s_pid , - * psis , other ) ; - * - * @endcode - * - * @param input (INPUT) the container of input particles - * @param criterion (INPUT) the selection criteria - * @param output (OUPUT) the container of selected particles - * @param output2 (OUPUT) the container of non-selected particles - * @return number of added particles - * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl - * @date 2010-05-14 - */ - template - std::size_t filter( const LHCb::Particle::Range& input, const PREDICATE& criterion, - LHCb::Particle::ConstVector& output, LHCb::Particle::ConstVector& output2 ) { - std::size_t added = 0; - for ( LHCb::Particle::ConstVector::const_iterator ip = input.begin(); input.end() != ip; ++ip ) { - if ( criterion( *ip ) ) { - output.push_back( *ip ); - ++added; - } else { - output2.push_back( *ip ); - } - } - return added; - } - // ========================================================================== - /** split the particles into two containers according some criteria - * - * As criteria one can use e.g. any LoKi-functor: - * - * @code - * - * #include "LoKi/ParticleCuts.h" - * - * ... - * - * const LHCb::Particle::ConstVector input = ... ; - * - * using namespace LoKi::Cuts ; - * - * // filter negative - * LHCb::Particle::ConstVector negative ; - * LHCb::Particle::ConstVector positive ; - * DaVinci::filter ( input , Q < 0 , negative , positive ) ; - * - * // filter pions - * LHCb::Particle::ConstVector pions ; - * LHCb::Particle::ConstVector other ; - * DaVinci::filter ( input , "pi+" == ID , pions , other ) ; - * - * @endcode - * - * Also many boost::lambda idioms can be used: - * - * @code - * - * #include - * #include - * - * ... - * - * const LHCb::Particle::ConstVector input = ... ; - * - * using namespace boost::lambda ; - * - * // filter negative - * LHCb::Particle::ConstVector negative ; - * LHCb::Particle::ConstVector positive ; - * DaVinci::filter ( input , - * bind(&LHCb::Particle::charge,_1) < 0 , - * negative , positive ) ; - * - * // filter J/psi - * const LHCb::ParticleID s_pid ( 443 ) ; - * LHCb::Particle::ConstVector jpsis ; - * LHCb::Particle::ConstVector other ; - * DaVinci::filter ( input , - * bind(&LHCb::Particle::particleID,_1) == s_pid , - * psis , other ) ; - * - * @endcode - * - * @param input (INPUT) the container of input particles - * @param criterion (INPUT) the selection criteria - * @param output (OUPUT) the container of selected particles - * @param output2 (OUPUT) the container of non-selected particles - * @return number of added particles - * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl - * @date 2010-05-14 - */ - template - std::size_t filter( const LHCb::Particle::ConstVector& input, const PREDICATE& criterion, - LHCb::Particle::ConstVector& output, LHCb::Particle::ConstVector& output2 ) { - return filter( LHCb::Particle::Range( input ), criterion, output, output2 ); - } - // ========================================================================== - /** filter the particles according to some criteria - * - * @param input (INPUT) the container of input particles - * @param criterion (INPUT) the selection criteria - * @param output (OUPUT) the container of selected particles - * @reutrn number of added particles - * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl - * @date 2010-05-14 - */ - GAUDI_API - std::size_t filter( const LHCb::Particle::Range& input, const IParticleFilter* criterion, - LHCb::Particle::ConstVector& output ); - // ========================================================================== - /** filter the particles according to some criteria - * - * @param input (INPUT) the container of input particles - * @param criterion (INPUT) the selection criteria - * @param output (OUPUT) the container of selected particles - * @return number of added particles - * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl - * @date 2010-05-14 - */ - GAUDI_API - std::size_t filter( const LHCb::Particle::ConstVector& input, const IParticleFilter* criterion, - LHCb::Particle::ConstVector& output ); - // ========================================================================== - /** split the particles according to some criteria - * - * @param input (INPUT) the container of input particles - * @param criterion (INPUT) the selection criteria - * @param output (OUPUT) the container of selected particles - * @param output2 (OUPUT) the container of non-selected particles - * @return number of added particles - * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl - * @date 2010-05-14 - */ - GAUDI_API - std::size_t filter( const LHCb::Particle::Range& input, const IParticleFilter* criterion, - LHCb::Particle::ConstVector& output, LHCb::Particle::ConstVector& output2 ); - // ========================================================================== - /** split the particles according to some criteria - * - * @param input (INPUT) the container of input particles - * @param criterion (INPUT) the selection criteria - * @param output (OUPUT) the container of selected particles - * @param output2 (OUPUT) the container of non-selected particles - * @return number of added particles - * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl - * @date 2010-05-14 - */ - GAUDI_API - std::size_t filter( const LHCb::Particle::ConstVector& input, const IParticleFilter* criterion, - LHCb::Particle::ConstVector& output, LHCb::Particle::ConstVector& output2 ); - // ========================================================================== -} // end of namespace DaVinci -// ============================================================================ -// The END -// ============================================================================ -#endif // KERNEL_PARTICLEFILTERS_H -// ============================================================================ diff --git a/Phys/DaVinciKernel/include/Kernel/ParticlePredicates.h b/Phys/DaVinciKernel/include/Kernel/ParticlePredicates.h deleted file mode 100644 index e647bded01106215604bbb14880ebdc21421722e..0000000000000000000000000000000000000000 --- a/Phys/DaVinciKernel/include/Kernel/ParticlePredicates.h +++ /dev/null @@ -1,55 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -#ifndef KERNEL_PARTICLEPREDICATES_H -#define KERNEL_PARTICLEPREDICATES_H 1 - -// Include files -#include "Event/Particle.h" - -/** @namespace DaVinci Kernel/ParticlePredicates.h - * - * - * @author Juan Palacios - * @date 2011-01-10 - */ -namespace DaVinci { - - /** @namespace Utils Kernel/ParticlePredicates.h - * - * - * @author Juan Palacios - * @date 2011-01-10 - */ - namespace Utils { - - struct IParticlePredicate { - virtual ~IParticlePredicate() = default; - virtual bool operator()( const LHCb::Particle* obj ) const = 0; - }; - - /// Functor to check if a Particle is in the TES. - struct ParticleInTES : IParticlePredicate { - inline bool operator()( const LHCb::Particle* obj ) const override { return ( obj && obj->parent() ); } - }; - - struct ParticleTrue : IParticlePredicate { - inline bool operator()( const LHCb::Particle* ) const override { return true; } - }; - - struct ParticleFalse : IParticlePredicate { - inline bool operator()( const LHCb::Particle* ) const override { return false; } - }; - - } // namespace Utils - -} // namespace DaVinci - -#endif // KERNEL_PARTICLEPREDICATES_H diff --git a/Phys/DaVinciKernel/include/Kernel/RelationOneToOne.h b/Phys/DaVinciKernel/include/Kernel/RelationOneToOne.h deleted file mode 100644 index 9930b00fb95294bae5135cbc9a1cd5c3e84a2a6b..0000000000000000000000000000000000000000 --- a/Phys/DaVinciKernel/include/Kernel/RelationOneToOne.h +++ /dev/null @@ -1,72 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -#ifndef KERNEL_RELATIONONETOONE_H -#define KERNEL_RELATIONONETOONE_H 1 - -// Include files -#include "GaudiKernel/StatusCode.h" - -namespace DaVinci { - /** @class RelationOneToOne Kernel/RelationOneToOne.h - * - * - * @author Juan PALACIOS - * @date 2009-09-01 - */ - template - class RelationOneToOne { - - public: - typedef typename T::From_ From_; - typedef typename T::To_ To_; - typedef typename T::Range Range; - - public: - /// Standard constructor - RelationOneToOne( const T& table ) : m_table( table ) {} - - public: - inline StatusCode i_relate( From_ from, To_ to ) const { - return m_table.relations( from ).empty() ? m_table.i_relate( from, to ) : StatusCode::FAILURE; - } - - inline StatusCode i_removeFrom( From_ from ) { return m_table.i_reloveFrom( from ); } - - inline StatusCode i_relateWithOverwrite( From_ from, To_ to ) const { - return ( m_table.relations( from ).empty() ? m_table.i_relate( from, to ) - : m_table.i_removeFrom( from ).isSuccess() ? m_table.i_relate( from, to ) - : StatusCode::FAILURE ); - // if ( m_table.relations(from).empty() ) return m_table.i_relate(from, to); - // if( m_table.i_removeFrom(from).isFailure() ) return StatusCode::FAILURE; - // return m_table.i_relate(from, to); - } - - inline StatusCode i_clear() { return m_table.i_clear(); } - - inline StatusCode i_relations( From_ from ) { return m_table.i_relations( from ); } - - inline StatusCode i_relations() { return m_table.i_relations(); } - - virtual ~RelationOneToOne(); ///< Destructor - - public: - inline const T& table() const { return m_table; } - - private: - /// Standard constructor - RelationOneToOne(); - - private: - T& m_table; - }; - -} // namespace DaVinci -#endif // KERNEL_RELATIONONETOONE_H diff --git a/Phys/DaVinciKernel/include/Kernel/Tree.h b/Phys/DaVinciKernel/include/Kernel/Tree.h deleted file mode 100644 index 7a1694ce23b1c59060bb969797b337413574bc3a..0000000000000000000000000000000000000000 --- a/Phys/DaVinciKernel/include/Kernel/Tree.h +++ /dev/null @@ -1,995 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2022 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -#pragma once - -#include "Event/Particle.h" -#include "GaudiKernel/GaudiException.h" -#include "GaudiKernel/IMessageSvc.h" -#include "GaudiKernel/MsgStream.h" -#include "GaudiKernel/ServiceHandle.h" -#include "Kernel/Arrow.h" -#include "Kernel/Node.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Decay { - class Tree; - - template - concept isParticle = std::same_as || std::same_as; - - // forward declare for detail namespace - namespace detail { - struct classprops_t { - Decay::Node headNode; - Decay::Arrow first_arrow; - std::vector daughters; - bool hasCC; - bool isMarked; - }; - struct arrowprops_t { - Decay::Arrow first_arrow; - unsigned int n_first_arrow; - size_t first_arrow_pos; - unsigned int n_arrowtypes; - }; - using tuple_parentdaughter_t = std::tuple; - using vec_str_t = std::vector; - using vec_dt_t = std::vector; - using vec_vec_dt_t = std::vector; - template - using vec_ptr_t = std::vector; - - classprops_t parseDescriptor( std::string descriptor ); - vec_vec_dt_t cartesianProduct( const vec_vec_dt_t& vec_vec_dt ); - - void pruneDescriptor( std::string& s ); - - /// Helper function to get daughter for particle and MCParticle - auto getParticleDaughters( const LHCb::Particle& particle ) { - return LHCb::range::to( particle.daughters() ); - } - - auto getParticleDaughters( const LHCb::MCParticle& particle ) { - const auto* goodVtx = particle.goodEndVertex(); - // if goodVtx is null (could be basic particles) so just return an empty vector - if ( !goodVtx ) return LHCb::MCParticle::ConstVector{}; - return LHCb::MCParticle::ConstVector( goodVtx->products().begin(), goodVtx->products().end() ); - } - - } // namespace detail - - class Tree { - public: - /// constructors - Tree( const std::string& descriptor ); - Tree( detail::classprops_t ); - Tree( Node ); - /// TODO: Could sort daughter subtree descriptors by their depth (also applies to constructor Tree(particle) ) - Tree( Node headNode, Arrow arrow, detail::vec_dt_t daughters, bool hasCC, bool isMarked ); - Tree( LHCb::Particle const& ); // Particle constructor - Tree( LHCb::MCParticle const& ); // MCParticle constructor - - /// get charge conjugated node - Tree getChargeConjugate( bool reversehasCC = false ) const; - /// reverse the has CC flag - void reversehasCC() { m_hasCC = !m_hasCC; } - /// has daughters - bool hasDaughters() const { return !m_daughters.empty(); } - /// get descriptor - std::string descriptor() const; - /// get possibilities of "simple" descriptors from "complex" descriptor - /// e.g. "B0 -> [K+]CC pi-" gives two possibilities: [B0 -> K+ pi- , B0 -> K- pi+] - detail::vec_dt_t getPossibilities() const; - /// Compare current tree with the reference tree. - /// The "simple" reference tree (i.e. wih isMarked or hasCC flags to false) could have been created with - /// reconstructed particle. Note the reference tree is non-const, since the isMarked property from current tree is - /// transferred to the reference tree when there is match. - /// TODO: remove in current implementation - bool compareWithRefTree( Tree& ref_dt ) const; - - /* getters */ - /// get node - Node headNode() const { return m_headNode; } - /// get const reference to the daughters - const detail::vec_dt_t& daughters() const { return m_daughters; } - /// get hasCC - bool hasCC() const { return m_hasCC; } - /// get isMarked - bool isMarked() const { return m_isMarked; } - /// get has matched - bool hasMatched() const; - /// get arrow - Arrow arrow() const { return m_Arrow; } - - /* setters */ - /// set headNode - void setheadNode( Node headNode ) { m_headNode = headNode; } - /// set daughters - void setdaughters( detail::vec_dt_t daughters ) { m_daughters = daughters; } - /// set hasCC - void sethasCC( bool hasCC ) { m_hasCC = hasCC; } - /// set isMarked - void setisMarked( bool isMarked ) { m_isMarked = isMarked; } - /// set has matched - void sethasMatched( bool hasMatched ); - /// set arrow - void setArrow( Arrow arrow ) { m_Arrow = arrow; } - - /// friend function for operator<< - friend std::ostream& operator<<( std::ostream& os, const Tree& dt ); - /// friend function for operator== - /// TODO: remove in current implementation - friend bool operator==( const Tree& lhs, const Tree& rhs ); - /// friend function for operator!= - // friend function comparing two trees (Note: Arguments are non-const references) - // They are non-const since the isMarked and hasMatched flags of the trees are modified. - /// TODO: remove - friend bool checkIfTreesMatch( Tree& lhs, Tree& rhs ); - - /// DecayFinder no template implementation - /// friend function comparing a particle and a tree note: internally makes a copy of the tree to change the - /// m_hasMatched property of the tree to deal with identical particles - template - friend bool operator==( const PARTICLE& lhs, const Tree& rhs ); - /// loop over the particle and the decaytree to evaluate if they match - template - bool hasMatchWithParticle( const PARTICLE& particle ); - /// finds the marked particles and fills the output vector - template - void collectMarkedParticles( const PARTICLE* particle, std::vector& output ) const; - - private: - /// TODO: Check that the following private functions are well documented - /// private function that works with collectMarkedParticlesImpl - template - void collectMarkedParticlesRecursive( const PARTICLE* particle, std::vector& output ); - /// set all the headNodes isMarked along with current and sub-trees isMarked flag - /// TODO: remove - void setAllisMarked( bool isMarked ); - - /// head node - Node m_headNode; - /// Arrow type - Arrow m_Arrow{ Arrow::Unknown }; - /// vector of daughters - detail::vec_dt_t m_daughters; - /// has cc flag in decay e.g. [B0 -> K+ K-]CC - bool m_hasCC{ false }; - /// is marked flag in decay e.g. ^(B0 -> K+ K-) or ^([B0 -> K+ K-]CC) - bool m_isMarked{ false }; - /// decay tree has been matched - std::optional m_hasMatched{}; - /// messaging service - /// TODO: Need to set the verbosity of messaging service - ServiceHandle m_msgSvc{ "MessageSvc", "MessageSvcName" }; - }; - - Tree::Tree( Node headNode ) : m_headNode{ std::move( headNode ) } {} - - Tree::Tree( Node headNode, Arrow arrow, detail::vec_dt_t daughters, bool hasCC, bool isMarked ) - : m_headNode{ std::move( headNode ) } - , m_Arrow{ arrow } - , m_daughters{ std::move( daughters ) } - , m_hasCC{ hasCC } - , m_isMarked{ isMarked } {} - - Tree::Tree( detail::classprops_t props ) - : Tree{ std::move( props.headNode ), props.first_arrow, std::move( props.daughters ), props.hasCC, - props.isMarked } {} - - Tree::Tree( const std::string& descriptor_str ) : Tree{ detail::parseDescriptor( descriptor_str ) } {} - - Tree::Tree( LHCb::Particle const& particle ) : m_headNode{ Node( particle ) }, m_Arrow{ Arrow::Single } { - // get parent particle pointer from "pointer of pointer" - // check if it is basic - if ( !particle.isBasicParticle() ) { - // if not loop over daughter particles - const auto& children = particle.daughters(); - std::transform( children.begin(), children.end(), std::back_inserter( m_daughters ), - []( const auto& d ) { return Node{ *d }; } ); - } - } - - Tree::Tree( LHCb::MCParticle const& mcparticle ) : m_headNode{ mcparticle }, m_Arrow{ Arrow::Single } { - // get MCParticle's first end-vertex that likely destroyed the particle - if ( const auto* goodVtx = mcparticle.goodEndVertex(); goodVtx ) { - // if not loop over daughter particles - const auto& children = goodVtx->products(); - std::transform( children.begin(), children.end(), std::back_inserter( m_daughters ), - []( const auto& ref ) { return *ref; } ); - } - } - - Tree Tree::getChargeConjugate( bool reversehasCC ) const { // get charge conjugated - // copy of current tree - // create new Tree with current tree - Tree cc_tree{ *this }; - // change the headNode to the charge conjugated node (a copy with opposite pid/name) - // It does not change the hasCC flag - cc_tree.setheadNode( m_headNode.getChargeConjugate() ); - // change the daughters to the charge conjugated daughters - detail::vec_dt_t cc_daughters; // make a new vector of decay trees - cc_daughters.reserve( m_daughters.size() ); // reserve space for the daughters - // loop over the daughters and get the charge conjugated copy of daughters - for ( auto& daughter : m_daughters ) cc_daughters.emplace_back( daughter.getChargeConjugate() ); - // set cc_tree daughters to cc_daughters - cc_tree.setdaughters( cc_daughters ); - // reverse the hasCC flag of current decay tree - if ( reversehasCC ) cc_tree.reversehasCC(); - return cc_tree; - } - - std::string Tree::descriptor() const { - std::stringstream ss; - if ( !m_daughters.empty() ) { // if decay tree is not empty - if ( m_isMarked ) ss << "^("; - if ( m_hasCC ) ss << "["; - - ss << m_headNode << " " << m_Arrow << " "; - unsigned int count_daug = 0; - for ( const auto& daug : m_daughters ) { - if ( !daug.daughters().empty() && !daug.isMarked() ) - ss << "(" << daug << ")"; - else - ss << daug; - if ( count_daug != m_daughters.size() - 1 ) ss << " "; - count_daug++; - } - } else // if decay tree is empty - ss << m_headNode; - - if ( m_hasCC && !m_daughters.empty() ) ss << "]CC"; - if ( m_isMarked ) ss << ")"; - - return ss.str(); - } - - detail::vec_dt_t Tree::getPossibilities() const { - // first get head node possibilities - // e.g. "[B+]CC" -> [Node(B+), Node(B-)] - std::vector headnode_possibilities{ m_headNode.getPossibilities() }; - // if no daughters in the tree convert headnodes into decaytrees with no daughters and return it - // e.g. "[B+]CC" -> [Tree(B+), Tree(B-)] - detail::vec_dt_t tree_possibilities; - if ( !hasDaughters() ) { - for ( const auto& node : headnode_possibilities ) tree_possibilities.emplace_back( node ); - return tree_possibilities; - } - // if the Tree has daughters make a vector of vector of decaytrees with daughters - // e.g. for descriptor "B0 -> [K1+]CC K2-", the daug_possibilities will be "[ [Tree(K1+), Tree(K1-)], [Tree(K2-)] ]" - detail::vec_vec_dt_t daug_possibilities; - for ( const auto& daug : m_daughters ) daug_possibilities.emplace_back( daug.getPossibilities() ); - // get all the possible permutations of daughter corresponding to B0 - // e.g. for descriptor "B0 -> [K1+]CC K2-" descriptor, - // the daug_possibilities will become after cartesian product -> "[ [Tree(K1+), Tree(K2-)], [Tree(K1-), Tree(K2-)] - // ]" - daug_possibilities = detail::cartesianProduct( daug_possibilities ); - for ( std::size_t i = 0; i < headnode_possibilities.size(); i++ ) { // loop over head node tree possibility - for ( std::size_t j = 0; j < daug_possibilities.size(); j++ ) { // loop over daughter tree possibility - // create an instance of decayTree with headnode and daughters - bool hasCC{ false }; // set hasCC false since we have "simple" decay descriptors removing hasCC - tree_possibilities.emplace_back( headnode_possibilities[i], m_Arrow, daug_possibilities[j], hasCC, m_isMarked ); - // if the current tree hasCC to true in the decay add the conjugated tree to the possibilities - if ( m_hasCC ) { - Tree dt( headnode_possibilities[i], m_Arrow, daug_possibilities[j], hasCC, m_isMarked ); - tree_possibilities.emplace_back( dt.getChargeConjugate() ); // false as the DT are plain (without operators) - } // if hasCC - } // loop over daughter tree possibility - } // loop over head node tree possibility - return tree_possibilities; - } - - /// get has matched - bool Tree::hasMatched() const { - // if composite check if all daughters have matched - if ( hasDaughters() ) { // has daughters - for ( auto& daughter : m_daughters ) - if ( !daughter.hasMatched() ) return false; // no hasMatched in daughters - return true; // all daughters have hasMatched - } - // if basic return value of m_hasMatched - return m_hasMatched.value_or( false ); - } - - void Tree::sethasMatched( bool hasMatched ) { - // first set all daughters hasMatched flag if composite - // the m_hasMatched flag for composite itself will be std::nullopt since its definition - // entirely depends on if the daughters have been matched or not. - if ( hasDaughters() ) - for ( auto& daughter : m_daughters ) daughter.sethasMatched( hasMatched ); - else - // if basic particle, set hasMatched flag - m_hasMatched = std::optional{ hasMatched }; - } - - std::ostream& operator<<( std::ostream& os, const Tree& dt ) { return os << dt.descriptor(); } - - /////////////// implementation for DecayFinder - template - bool operator==( const PARTICLE& lhs, const Tree& rhs ) { - // make a copy of the decay tree - return Tree{ rhs }.hasMatchWithParticle( lhs ); - } - - template - bool Tree::hasMatchWithParticle( const PARTICLE& particle ) { - // set messaging service - MsgStream log( ( m_msgSvc ).get(), "Decay::Tree" ); - bool is_verbose = ( log.level() == MSG::VERBOSE ); - // check for nullptr - // create a reference tree from the reconstructed particle (for debugging) - Tree ref_dt( particle ); - // bool is_verbose = true; - if ( is_verbose ) log << MSG::INFO << "Comparing tree: " << *this << "with particle: " << ref_dt << endmsg; - // check if the head nodes match - if ( m_headNode != &particle ) return false; - // head nodes have matched - if ( is_verbose ) - log << MSG::INFO << "Head nodes are equal b/w: " << m_headNode << " and RHS: " << ref_dt.m_headNode << endmsg; - // check if the user tree doesn't have daughters - if ( !( hasDaughters() ) ) { - sethasMatched( true ); - return true; - } - // both trees have daughters - if ( is_verbose ) - log << MSG::INFO << "Trees: " << *this << " and particle: " << ref_dt << " both have daughters." << endmsg; - // check if daughter size is equal - if ( detail::getParticleDaughters( particle ).size() != ( m_daughters ).size() ) return false; - if ( is_verbose ) - log << MSG::INFO << "Trees: " << *this << " and particle: " << ref_dt << " have same daughter sizes." << endmsg; - // both trees have equal head node and equal daughter size - // compare the particle daughter with the tree daughter - for ( const auto* particle_daughter : detail::getParticleDaughters( particle ) ) { - for ( auto& tree_daughter : m_daughters ) { - // create a reference daughter tree - if ( is_verbose ) - log << MSG::INFO << "Comparing tree daughter: " << tree_daughter - << " and particle daughter: " << Tree( *particle_daughter ) << endmsg; - // check if tree daughter has already been matched - if ( tree_daughter.hasMatched() ) { - if ( is_verbose ) log << MSG::INFO << "Tree daughter has already been matched: " << tree_daughter << endmsg; - continue; - } - // check if the tree daughter matches with the particle daughter - else if ( tree_daughter.hasMatchWithParticle( *particle_daughter ) ) { - if ( is_verbose ) - log << MSG::INFO << "Match found for tree daughter: " << tree_daughter - << " and particle daughter: " << Tree( *particle_daughter ) << endmsg; - break; // when there is a match - } - // no match has been found - if ( is_verbose ) - log << MSG::INFO << "No match for tree daughter: " << tree_daughter - << " and particle daughter: " << Tree( *particle_daughter ) << endmsg; - } - } - // check if all the daughters have matched - if ( hasMatched() ) { - if ( is_verbose ) - log << MSG::INFO << "Everything has matched, Tree: " << *this << " and Particle: " << ref_dt << endmsg; - // need to set all the daughters to matched when the whole tree has matched. - sethasMatched( true ); - return true; - } else { - if ( is_verbose ) - log << MSG::INFO << "Not everything is matched, Tree: " << *this << " and Particle " << ref_dt << endmsg; - // Even when the individual particles in a tree have matched, but the whole tree hasn't matched - // need to set all the daughters back to not being matched - sethasMatched( false ); - return false; - } - } - - template - void Tree::collectMarkedParticles( const PARTICLE* particle, std::vector& output ) const { - // check for nullptr - if ( !particle ) { - throw GaudiException{ - "The input particle is null (nullptr). Please check!", - "Decay::Tree::collectMarkedParticlesImpl(const PARTICLE *particle, std::vector &output)", - StatusCode::FAILURE }; - } - // make a copy of the tree here - Tree temp_tree{ *this }; - // check for hat in descriptor - if ( temp_tree.descriptor().find( '^' ) == temp_tree.descriptor().npos ) { - // when there is no hat, append the head particle - output.push_back( particle ); - return; - } - temp_tree.collectMarkedParticlesRecursive( particle, output ); - } - - bool Tree::compareWithRefTree( Tree& ref_dt ) const { // TODO: remove - // make a copy of the current tree - Tree current_dt_copy{ *this }; - bool hasMatched = checkIfTreesMatch( current_dt_copy, ref_dt ); - // if there is no match set the ref_dt properties to default ones - if ( !hasMatched ) { - ref_dt.sethasMatched( false ); - ref_dt.setAllisMarked( false ); - } - return hasMatched; - } - - bool operator==( const Tree& lhs, const Tree& rhs ) { // TODO: remove - // make a copy of the lhs and rhs - Tree lhs_copy{ lhs }; - Tree rhs_copy{ rhs }; - return checkIfTreesMatch( lhs_copy, rhs_copy ); - } - - bool checkIfTreesMatch( Tree& lhs, Tree& rhs ) { // TODO: remove - // set messaging service - MsgStream log( lhs.m_msgSvc.get(), "Decay::Tree" ); - bool is_verbose = ( log.level() == MSG::VERBOSE ); - // bool is_verbose = true; - if ( is_verbose ) log << MSG::INFO << "Comparing the descriptors LHS: " << lhs << "with RHS: " << rhs << endmsg; - - // define helper lambdas - //////////////////////////////////////////////////////////////// - // define a helper lambda to check if there is match with CC - auto has_match_with_cctree = [&lhs, &rhs]() -> bool { - // The conjugate object requires hasCC flag to false or else hit infinite loop - bool reversehasCC{ true }; - // if lhs or rhs hasCC set to true check with conjugate object - if ( lhs.m_hasCC ) { - // Note the getChargeConjugate will return a copy of the lhs tree with conjugate properties - return rhs == lhs.getChargeConjugate( reversehasCC ); - } else if ( rhs.m_hasCC ) { - // Note the getChargeConjugate will return a copy of the rhs tree with conjugate properties - return lhs == rhs.getChargeConjugate( reversehasCC ); - } // cases where both have hasCC true should be covered above - return false; // if both lhs and rhs do not hasCC to false return false - }; - - // define a helper lambda to set matching properties between lhs and rhs - auto set_isMarked_hasMatched = [&log, &is_verbose]( Tree& lhs, Tree& rhs ) -> void { - // set isMarked properties - if ( lhs.isMarked() || lhs.headNode().isMarked() || rhs.isMarked() || rhs.headNode().isMarked() ) { - if ( is_verbose ) log << MSG::INFO << "Tree/Node LHS: " << lhs << " or RHS: " << rhs << "is marked" << endmsg; - lhs.m_headNode.setisMarked( true ); // modify the head node and no the - rhs.m_headNode.setisMarked( true ); - } - // set hasMatched properties - lhs.sethasMatched( true ); - rhs.sethasMatched( true ); - }; - - auto hasMarkedDaughter = []( const Tree& dt ) -> bool { - // decaytree dt has daughters now check if one of its daughters is marked - for ( const Tree& daughter : dt.m_daughters ) - if ( daughter.isMarked() || daughter.headNode().isMarked() ) return true; - return false; - }; - //////////////////////////////////////////////////////////////// - - // check if the head nodes match - if ( lhs.m_headNode != rhs.m_headNode ) { - // if not check if hasCC is true and match with CC tree otherwise return false - if ( !has_match_with_cctree() ) return false; - } - - if ( is_verbose ) - log << MSG::INFO << "Head nodes are equal b/w LHS: " << lhs.m_headNode << " and RHS: " << rhs.m_headNode - << endmsg; - - // head nodes have matched now check if either of them has daughters - // if either lhs or rhs has no daughters (unequal trees) - // e.g. lhs: Jpsi and rhs: Jpsi -> mu+ mu-. - if ( !lhs.hasDaughters() || !rhs.hasDaughters() ) { - - // if the trees are un-equal and the user has marked a daughter send an error message and return false - // e.g. ref. DT: B->Jpsi Phi; user DT: B->(Jpsi->mu+ ^mu-) Phi - if ( !lhs.hasDaughters() && rhs.hasDaughters() && hasMarkedDaughter( rhs ) ) return false; - if ( lhs.hasDaughters() && !rhs.hasDaughters() && hasMarkedDaughter( lhs ) ) return false; - - // if both lhs and rhs haven't matched before, set isMarked flag and hasMatched - // flag appropriately and return true - if ( !lhs.hasMatched() && !rhs.hasMatched() ) { - if ( is_verbose ) - log << MSG::INFO << "None of the trees LHS: " << lhs << " and RHS: " << rhs << " were matched before." - << endmsg; - set_isMarked_hasMatched( lhs, rhs ); - return true; - } - - // daughters have already been matched return false - if ( is_verbose ) - log << MSG::INFO << "Trees LHS: " << lhs << " and RHS: " << rhs << " already have been matched." << endmsg; - return false; - } - - if ( is_verbose ) - log << MSG::INFO << "Trees LHS: " << lhs << " and RHS: " << rhs << " both have daughters." << endmsg; - - // both lhs and rhs have daughters, if daughter size doesn't match return false - if ( lhs.m_daughters.size() != rhs.m_daughters.size() ) return false; - if ( is_verbose ) - log << MSG::INFO << "Trees LHS: " << lhs << " and RHS: " << rhs << " have same daughter sizes." << endmsg; - - // now compare daughters (loops over all daughters setting hasMatched flag to true if matched) - for ( Tree& daug_lhs : lhs.m_daughters ) { - for ( Tree& daug_rhs : rhs.m_daughters ) { - if ( is_verbose ) - log << MSG::INFO << "Comparing daughters of trees LHS: " << daug_lhs << " and RHS: " << daug_rhs << endmsg; - // checks if daughters are not equal OR if daughters have already been - // matched: in both cases continue - if ( ( daug_lhs != daug_rhs ) || ( daug_lhs.hasMatched() && daug_rhs.hasMatched() ) ) { - if ( is_verbose ) - log << MSG::INFO << "No match found or daughters have already been matched for LHS: " << daug_lhs - << " and RHS: " << daug_rhs << endmsg; - continue; - } else { // match was found and daughters have not previously been matched - // set isMarked flag and hasMatched flag appropriately - if ( is_verbose ) - log << MSG::INFO << "Match found for daughters LHS: " << daug_lhs << " and RHS: " << daug_rhs << endmsg; - // will have to transfer the marked properties after the match - checkIfTreesMatch( daug_lhs, daug_rhs ); - set_isMarked_hasMatched( daug_lhs, daug_rhs ); - break; // if match break - } - } - } - // check if all daughters have been matched - // require here that both lhs and rhs have matched daughters - if ( !lhs.hasMatched() && !rhs.hasMatched() ) { - if ( is_verbose ) - log << MSG::INFO << "Not everything is matched, trying with CC if hasCC is true, LHS: " << lhs - << " and RHS: " << rhs << endmsg; - // if not check if hasCC is true and match with CC tree otherwise return false - if ( !has_match_with_cctree() ) return false; - } - if ( is_verbose ) log << MSG::INFO << "Everything has matched, LHS: " << lhs << " and RHS: " << rhs << endmsg; - - // everything has matched return true - // set isMarked flag and hasMatched flag appropriately - set_isMarked_hasMatched( lhs, rhs ); - return true; - } - - template - void Tree::collectMarkedParticlesRecursive( const PARTICLE* particle, std::vector& output ) { - // check for nullptr - if ( !particle ) { - throw GaudiException{ "The input particle is null (nullptr). Please check!", - "Decay::Tree::collectMarkedParticlesRecursive(const PARTICLE *particle, std::vector &output)", - StatusCode::FAILURE }; - } - // compare the head nodes - if ( m_headNode != particle ) return; - // head nodes have matched - // check if the user tree doesn't have daughters - if ( !( hasDaughters() ) ) { - // set has matched of head node w/o daughters to true (helps with identical particles) - sethasMatched( true ); - // if node or tree marked push to output vector - if ( isMarked() || ( headNode() ).isMarked() ) output.push_back( particle ); - return; - } - // both trees have daughters - // if daughter size is unequal return - if ( detail::getParticleDaughters( *particle ).size() != ( daughters() ).size() ) return; - // both trees have equal head node and equal daughter size - // if node or tree marked push to output vector - if ( isMarked() || ( headNode() ).isMarked() ) output.push_back( particle ); - // compare the daughters - for ( const auto* particle_daughter : detail::getParticleDaughters( *particle ) ) { - for ( auto& tree_daughter : m_daughters ) { - if ( tree_daughter.hasMatched() ) - continue; // daughter has already been matched continue (dealing with identical particles) - else if ( tree_daughter == *particle_daughter ) { // daughters are equal, find the marked particle - tree_daughter.collectMarkedParticlesRecursive( particle_daughter, output ); - break; - } - } // tree daughter loop - } // particle daughter loop - } - - void Tree::setAllisMarked( bool isMarked ) { // TODO: remove - // set the current tree and head nodes isMarked flag - m_headNode.setisMarked( isMarked ); - m_isMarked = isMarked; - // if daughters exist then iteratively set their properties - if ( hasDaughters() ) - for ( auto& daughter : m_daughters ) daughter.setAllisMarked( isMarked ); - } - - namespace detail { - - /// Cartesian product between the vectors in a vector of vectors, similar to the itertools.product in Python - /// e.g. for a vector of vectors of ints { {1, 2}, {11, 12, 13}, {21, 22} } it would return - /// { {1, 11, 21}, {1, 11, 22}, {1, 12, 21}, {1, 12, 22}, ... {2, 13, 22} } - vec_vec_dt_t cartesianProduct( const vec_vec_dt_t& vec_vec_dt ) { - // TODO: Try to clean this up a little bit - vec_vec_dt_t result = { {} }; // TODO: Try to reserve the memory - for ( const auto& vector1 : vec_vec_dt ) { - vec_vec_dt_t res_tmp; - for ( const auto& vector2 : result ) { - for ( const auto& decayTree : vector1 ) { - res_tmp.push_back( vector2 ); - res_tmp.back().push_back( decayTree ); - } - } - result = std::move( res_tmp ); // moves all elements from r to result leaving r empty - } - return result; - } - - /// strips initial and trailing whitespaces from descriptor - void pruneDescriptor( std::string& s ) { - // strips initial and trailing whitespaces from a string - auto isspace = []( const char c ) { return std::isspace( c ); }; - s.erase( std::find_if_not( s.rbegin(), s.rend(), isspace ).base(), s.end() ); - s.erase( s.begin(), std::find_if_not( s.begin(), s.end(), isspace ) ); - } - - /// check that the descriptor contains balanced brackets (any type) i.e. opening brackets have corresponding - /// closing one ((...)) - bool hasBalancedBrackets( std::string_view str ) { // function to check if brackets are - // balanced in a descriptor - // create a stack that holds characters - std::stack stk{}; - // iterate trough the string character by character - for ( auto i : str ) { - // if you encounter an opening bracket add it to the stack - if ( i == '(' || i == '[' || i == '{' ) { - stk.push( i ); - } - // if you encounter a closing bracket... - else if ( i == ')' || i == ']' || i == '}' ) { - // ...and if the stack is empty return false - if ( stk.empty() ) return false; - // ...otherwise compare it to the previous bracket stored in the stack - char ch = stk.top(); - // decrement the stack such that balanced brackets lead to an empty stack - stk.pop(); - if ( ch == '(' && i == ')' ) continue; - if ( ch == '[' && i == ']' ) continue; - if ( ch == '{' && i == '}' ) continue; - // returns false if not matched - return false; - } - } - return stk.empty(); - } - - /// strips the descriptor from [...]CC and sets m_hasCC flags (invoked in constructor) - bool stripCCFromDescriptor( std::string& descriptor ) { // function used for descriptor - // parsing - // define a helper lambda function to check cc - auto checkHasCC = []( const std::string& descriptor ) -> bool { - // output true if the expression has "CC" and false otherwise - std::regex expression( "^\\[" // square bracket at the beginning of string - ".*" // any character in between - "\\]\\s*CC$" // square bracket and CC at end of string - ); - return std::regex_search( descriptor, expression ); - }; - - // set hasCC to false - bool hasCC = false; - - // prune descriptor if it has CC - pruneDescriptor( descriptor ); - - // check that we have balanced square brackets then set hasCC to true and strip square brackets - if ( checkHasCC( descriptor ) ) { - // if "CC" then strip it from descriptor - // e.g. "[[X]CC -> Y1 [Y2]CC]CC" => "[X]CC -> Y1 [Y2]CC" - std::regex expression( "^\\[" // opening square bracket at start of string - "\\s*" // any whitespaces - "(.*)" // matches what is in between i.e. striped descriptor - "\\]" // closing bracket - "\\s*CC$" // any whitespaces followed by CC at end of string - ); - std::smatch what; - std::regex_search( descriptor, what, expression ); - // descriptor has been strip of outer-most [..]CC, now check if the square brackets are balanced - // This is required for cases where the descriptor is "[X]CC -> Y1 [Y2]CC" and - // the checkHassCC passes with descriptor = "X]CC -> Y1 [Y2" but this is an invalid descriptor. - if ( hasBalancedBrackets( what.str( 1 ) ) ) { // check for balanced brackets - hasCC = true; - descriptor = what.str( 1 ); - pruneDescriptor( descriptor ); - } // No need to throw an error here - } - return hasCC; - } - - /// strips the descriptor from the hat ^(...) and sets m_isMarked flags (invoked in Tree constructor) - bool stripHatFromDescriptor( std::string& descriptor ) { // function used for descriptor - // parsing - - // define a helper lambda function for checking if marked - auto checkisMarked = []( const std::string& descriptor ) { - const std::regex expression( "^\\^" // hat at start of string - "\\s*\\(" // any number of space and a bracket - ".*" // any characters - "\\)" // closing bracket - ); - return std::regex_search( descriptor, expression ); - }; - - // define a helper lambda function to check if there is brackets - auto hasBrackets = []( const std::string& descriptor ) { - const std::regex expression( "^\\(" // bracket at start of string - ".*" // any characters - "\\)" // bracket - ); - return std::regex_search( descriptor, expression ); - }; - - // set is marked to false - bool isMarked = false; - - // prune descriptor - pruneDescriptor( descriptor ); - - // if descriptor has mark with brackets then strip mark and brackets setting isMarked - // i.e. "^(B->K+ K-)" -> "B->K+ K-" and isMarked = True - if ( checkisMarked( descriptor ) ) { - // decay is marked - isMarked = true; - // strips decay descriptor from hat + outside brackets - const std::regex expression( "^\\^" // hat and opening bracket at start of string - "\\s*\\(" // any whitespaces followed by opening bracket - "(.*)" // matches what is in between i.e. striped descriptor - "\\)$" // bracket at end of string - ); - std::smatch what; - std::regex_search( descriptor, what, expression ); - descriptor = what.str( 1 ); - pruneDescriptor( descriptor ); - } - - // if no mark and contains brackets then strip brackets setting isMarked to false - // i.e. "(B->K+ K-)" -> "B->K+ K-" - if ( hasBrackets( descriptor ) ) { // tests the matched string for brackets - // strips decay from outside brackets only - const std::regex expression( "^\\(\\s*" // opening bracket at start of string - "(.*)" // matches what is in between i.e. striped descriptor - "\\s*\\)$" // bracket at end of string - ); - std::smatch what; - std::regex_search( descriptor, what, expression ); - descriptor = what.str( 1 ); - pruneDescriptor( descriptor ); - } - - return isMarked; - } - - /// get the number of arrows in the descriptor of given type - inline unsigned int numberOfArrowsOfParticularType( std::string_view descriptor, Decay::Arrow arrow ) { - // counts the number of arrow of a given type in a descriptor - unsigned int count = 0; - std::string::size_type pos = 0; - auto target = toString( arrow ); - while ( ( pos = descriptor.find( target, pos ) ) != descriptor.npos ) { - ++count; - pos += target.length(); - } - return count; - }; - - /// Check if descriptor has arrows of any type - bool hasArrow( const std::string& descriptor ) { - return std::any_of( Decay::ValidArrows.begin(), Decay::ValidArrows.end(), [&descriptor]( Decay::Arrow arrow ) { - return numberOfArrowsOfParticularType( descriptor, arrow ) != 0; - } ); - }; - - vec_str_t getDaughtersFromString( const std::string& daug_str ) { // function used for - // descriptor parsing - // separates the daughter string into the individual daughter particles returning a vector of daughters - vec_str_t vec_daug; - // regex expression that matches whitespaces conditionally, see below - boost::regex expression( - "(?(2->3 4) gives 2->3 4 - vec_str_t findStringWithinOuterMostBrackets( const std::string& daug_str ) { // function used for - // descriptor parsing - vec_str_t outer_vec_daug; - // regex expression that matches the string in the outermost brackets - // TODO: check the documentation here is okay - boost::regex expression( - "(" // "(...)" capturing group for - // "b(?:m|(?R))*e" - // matches balanced patterns or nested patterns where "b" is the beginning - // of the patterns, "e" the end and "m" what can occur in the middle - - "(?:\\^\\s*\\(|\\()" // "b" = "(?:\\^\\s*\\(|\\()" - // beginning of the pattern is either a hat "\\^" - // followed by any number of whitespaces "\\s*" and a opening bracket - // "\\(" OR: ("|"), an single opening bracket "\\(" - - "(?:[^()]+|(?R))*" // "m" = "[^()]" - // character set that matches a single character not in the set - // the negation is indicated by the "^" inside the character set - // recursion gets incremented if a character from the set in encountered - // "*" means that pattern will repeat zero or more consecutive times - - "\\)" // "e" = "\\)" - // the pattern ends with a closing bracket "\\)" - - ")" // end of the capturing group - ); - /* simpler recursion example: "a(?R)*z" that can match the string aaazzz to understand how recursion works. - First "a" gets matched, then the engine reaches "(?R)" which tells it to repeat the regex (ie. look for a again) - at the current position in the string now the second "a" is matched at recursion level = 1 then engine reaches - "(?R)" again (increments recursion) now the third "a" is matched at recursion level = 2. When the regex repeats, - the next character in the string is "z", so match for "a" fails at recursion level = 2 which causes the "(?R)" to - fail but from the "*" character, "(?R)" is made optional so engine continues to the end of the expression and - matches the first "z". Now engine has reached the end of the regex but since it is two level deep in recursion, it - hasn't found an overall match. It exits the recursion after this successful match and matches the second "z". It - is still one level deep from which it exits after another successful match and founds the third "z". The engine in - now at the end of the regex and at level zero of recursion this time so it returns aaazzz - - ref: https://www.regular-expressions.info/recurse.html - */ - boost::sregex_token_iterator iter( daug_str.begin(), daug_str.end(), expression, - 0 ); // selects the sequence in the string that is matched - // by the regex expression - boost::sregex_token_iterator end; // end-of-reg-exp marker - for ( ; iter != end; ++iter ) { - if ( !detail::hasArrow( *iter ) ) // only stores decays - continue; - - outer_vec_daug.emplace_back( *iter ); - } - // replace the strings with empty strings so that only daughters with no decay trees are left ie simple nodes - std::string daug_str_new{ daug_str }; - for ( const auto& daug : outer_vec_daug ) { - std::string::size_type pos = daug_str_new.find( daug ); - daug_str_new.replace( pos, daug.length(), "" ); - } - detail::pruneDescriptor( daug_str_new ); - // create a new expression and iterator to separate daughters from a string of daughters - boost::regex n_expression( "(?(Jpsi => mu+ mu-) phi where "first arrow" is - // "->" the properties are (Instance of Arrow, number of arrows of first arrow type, position of first arrow, number - // of different arrow types in descriptor) - arrowprops_t getFirstArrowProps( const std::string& descriptor ) { - // instantiate a default first arrow - auto first_arrow = Decay::Arrow::Unknown; - // count number of first arrow type in descriptor - unsigned int n_first_arrow{ 0 }; - // instantiate a default position - std::size_t first_arrow_pos{ std::string::npos }; - // count the number of arrowtypes in string - unsigned int n_arrowtypes{ 0 }; - for ( const auto arrow : Decay::ValidArrows ) { // loop through all arrow types - if ( descriptor.find( toString( arrow ) ) != descriptor.npos ) { // found the arrow - if ( n_arrowtypes == 0 ) { // first iteration - // store arrow, number of its occurrences and position - first_arrow = arrow; - n_first_arrow = numberOfArrowsOfParticularType( descriptor, arrow ); - first_arrow_pos = descriptor.find( toString( arrow ) ); - } else { // second type of arrow found - if ( descriptor.find( toString( arrow ) ) < first_arrow_pos ) { // if the position is smaller than the - // previous one - // store arrow, number of its occurrences and position - first_arrow = arrow; - n_first_arrow = numberOfArrowsOfParticularType( descriptor, arrow ); - first_arrow_pos = descriptor.find( toString( arrow ) ); - } - } - n_arrowtypes++; - } - } - return arrowprops_t{ first_arrow, n_first_arrow, first_arrow_pos, n_arrowtypes }; - } - - /// split the descriptor into head node and daughters string according to the first arrow and first arrow length - tuple_parentdaughter_t getParentDaughterString( const std::string& descriptor, const std::size_t& firstArrowPos, - const std::size_t& firstArrowLength ) { - auto parent = descriptor.substr( 0, firstArrowPos ); - auto daugs = descriptor.substr( firstArrowPos + firstArrowLength ); - pruneDescriptor( parent ); - pruneDescriptor( daugs ); - return std::tuple( std::move( parent ), std::move( daugs ) ); - }; - - /// A helper function to make a tuple of class properties (used in constructor of decaytree) - classprops_t makeClassProps( std::string& descriptor ) { - // set hasCC and isMarked - auto isMarked = stripHatFromDescriptor( descriptor ); - auto hasCC = stripCCFromDescriptor( descriptor ); - - // get the properties of first type of arrow in the descriptor e.g. B->(Jpsi => mu+ mu-) (phi -> K+ K-) where - // "first arrow" is "->" the properties are (Instance of First Arrow, number of arrows of first arrow type, - // position of first arrow, number of different arrow types in descriptor) - const auto [first_arrow, n_first_arrow, first_arrow_pos, n_arrowtypes] = getFirstArrowProps( descriptor ); - bool hasOneArrow = ( n_first_arrow == 1 && n_arrowtypes == 1 ); - - // set head node - // get the properties of first type of arrow in the descriptor e.g. B->(Jpsi => mu+ mu-) phi where "first arrow" - // is - // "->" - const auto& [parent_str, daugs_str] = - getParentDaughterString( descriptor, first_arrow_pos, toString( first_arrow ).size() ); - Decay::Node headNode( parent_str ); - - // set daughters - // Get daughter string according to number of arrows - // - Allow for simple case with one arrow e.g. B -> K+ K-. Note the descriptor - // "[B->K+K-]" would fail but "(B->K+K-)" would pass. TODO: allow for both?. - // - Also allow for complex case e.g. B -> (Jpsi -> mu+ mu-) (phi(1020) -> K+ K-). - vec_str_t vec_daug = - hasOneArrow ? getDaughtersFromString( daugs_str ) : findStringWithinOuterMostBrackets( daugs_str ); - vec_dt_t daughters{ vec_daug.begin(), vec_daug.end() }; // make vector of daughters - - return { headNode, first_arrow, daughters, hasCC, isMarked }; - }; - - /// Master function to build decay tree setting member variables with descriptor (invoked in constructor) - classprops_t parseDescriptor( std::string descriptor ) { - // Check if contains balanced brackets. The brackets could be "(" or "[" or "{". - if ( !detail::hasBalancedBrackets( descriptor ) ) { - throw GaudiException{ "Descriptor does not have balanced brackets. Please check the descriptor!", - "Decay::Node::parseDescriptor(descriptor)", StatusCode::FAILURE }; - } - if ( !detail::hasArrow( descriptor ) ) { // Case1: check if no arrow in descriptor i.e. node only - Decay::Node headNode( descriptor ); // construct the head node - auto arrow_in_descriptor = Decay::Arrow::Unknown; // Arrow::Unknown - detail::vec_dt_t daughters{}; // no daughters - bool hasCC{ false }, isMarked{ false }; // properties handled at the node level - return { headNode, arrow_in_descriptor, daughters, hasCC, isMarked }; - } - // Build decay tree according how many arrows we have (calling parseDescriptor recursively) - return makeClassProps( descriptor ); - } - } // namespace detail -}; // namespace Decay diff --git a/Phys/DaVinciKernel/src/Lib/DaVinciFun.cpp b/Phys/DaVinciKernel/src/Lib/DaVinciFun.cpp deleted file mode 100644 index 3bbfc3d044131c100e8c8bb383d95703824b3406..0000000000000000000000000000000000000000 --- a/Phys/DaVinciKernel/src/Lib/DaVinciFun.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ - -// Gaudi -#include "GaudiKernel/SmartIF.h" - -// DaVinciInterfaces -#include "Kernel/ISetInputParticles.h" - -// local -#include "Kernel/DaVinciFun.h" - -//----------------------------------------------------------------------------- -// Implementation file for DaVinciFun -// -// 2009-08-02 : Juan Palacios -//----------------------------------------------------------------------------- -namespace DaVinci { - - const LHCb::VertexBase* bestVertexBase( const Particle2Vertex::Table::Range& range ) { - return ( range.empty() ? NULL : range.back().to() ); - } - - const LHCb::RecVertex* bestRecVertex( const Particle2Vertex::Table::Range& range ) { - return ( range.empty() ? NULL : dynamic_cast( range.back().to() ) ); - } - - namespace Utils { - // ======================================================================== - /* set the input particles for some component - * @param component the component inself - * @param input the intut data - * @return status code - * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl - * @date 2008-07-11 - */ - // ======================================================================== - StatusCode setInput( IInterface* component, const LHCb::Particle::ConstVector& input ) { - if ( !component ) { return StatusCode( 300 ); } // RETURN - // get the interface - SmartIF alg( component ); - // valid ? - if ( !alg ) { return StatusCode( 301 ); } // RETURN - // use the valid inyterface - return alg->setInput( input ); // RETURN - } - - // ======================================================================== - void findDecayTree( const LHCb::Particle* head, LHCb::Particle::ConstVector& particles, - LHCb::Vertex::ConstVector& vertices, DaVinci::Utils::IParticlePredicate* truncate ) { - - if ( truncate && ( *truncate )( head ) ) return; - - if ( particles.end() == std::find( particles.begin(), particles.end(), head ) ) { particles.push_back( head ); } - // - if ( head->endVertex() && vertices.end() == std::find( vertices.begin(), vertices.end(), head->endVertex() ) ) { - vertices.push_back( head->endVertex() ); // save Vertex - } - - // Loop on daughters - for ( SmartRefVector::const_iterator iDaughter = head->daughters().begin(); - iDaughter != head->daughters().end(); ++iDaughter ) { - findDecayTree( *iDaughter, particles, vertices, truncate ); - } - - // loop over outgoing particles - if ( head->endVertex() ) { - for ( SmartRefVector::const_iterator iPart = head->endVertex()->outgoingParticles().begin(); - iPart != head->endVertex()->outgoingParticles().end(); ++iPart ) { - findDecayTree( *iPart, particles, vertices, truncate ); - } - } - - return; - } - - bool decayTreeInTES( const LHCb::Particle* head ) { - if ( !DaVinci::Utils::inTES( head ) ) return false; - // Loop on daughters - for ( SmartRefVector::const_iterator iDaughter = head->daughters().begin(); - iDaughter != head->daughters().end(); ++iDaughter ) { - if ( !decayTreeInTES( *iDaughter ) ) return false; - } - - // loop over outgoing particles - if ( 0 != head->endVertex() ) { - if ( !DaVinci::Utils::inTES( head->endVertex() ) ) return false; - for ( SmartRefVector::const_iterator iPart = head->endVertex()->outgoingParticles().begin(); - iPart != head->endVertex()->outgoingParticles().end(); ++iPart ) { - if ( !decayTreeInTES( *iPart ) ) return false; - } - } - - return true; - } - - } // namespace Utils - -} // namespace DaVinci diff --git a/Phys/DaVinciKernel/src/Lib/DaVinciStringUtils.cpp b/Phys/DaVinciKernel/src/Lib/DaVinciStringUtils.cpp deleted file mode 100644 index d48f1951aefe7680f3fb8e69375edd052d258409..0000000000000000000000000000000000000000 --- a/Phys/DaVinciKernel/src/Lib/DaVinciStringUtils.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -// Include files - -// local -#include "Kernel/DaVinciStringUtils.h" - -//----------------------------------------------------------------------------- -// Implementation file for class : DaVinciStringUtils -// -// 2009-10-30 : Juan PALACIOS -//----------------------------------------------------------------------------- - -namespace DaVinci { - namespace StringUtils { - //========================================================================= - void stripParticleName( std::string& name ) { - if ( 0 == name.find( "anti-" ) ) { name.erase( 0, 5 ); } - std::string::size_type pos = name.find_first_of( "+-~" ); - if ( std::string::npos == pos ) { return; } - stripParticleName( name.erase( pos, 1 ) ); - } - //========================================================================= - void expandLocations( std::vector::iterator begin, std::vector::iterator end, - const std::string& prefix ) { - - for ( std::vector::iterator loc = begin; loc != end; ++loc ) { - if ( ( *loc ).find( "/" ) == std::string::npos ) { *loc = prefix + "/" + *loc; } - } - } - //========================================================================= - void expandLocation( std::string& location, const std::string& prefix ) { - if ( location.find( "/" ) == std::string::npos ) { location = prefix + "/" + location; } - } - //========================================================================= - void removeEnding( std::string& a, const std::string& ending ) { - std::string::size_type pos = a.rfind( ending ); - if ( pos != std::string::npos ) { a = std::string( a, 0, pos ); } - } - - } // namespace StringUtils - -} // namespace DaVinci -//============================================================================= diff --git a/Phys/DaVinciKernel/src/Lib/Escape.cpp b/Phys/DaVinciKernel/src/Lib/Escape.cpp deleted file mode 100644 index ac6f1143d0a16d8d68da2fb7ed8b6d26e89c40e3..0000000000000000000000000000000000000000 --- a/Phys/DaVinciKernel/src/Lib/Escape.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -// ============================================================================ -// Include files -// ============================================================================ -// GaudiKernel -// ============================================================================ -#include "Kernel/Escape.h" -#include "boost/regex.hpp" -// ============================================================================ -/* Replace all special characters from particle name - */ -// ============================================================================ -namespace Decays { - - std::string escape( const std::string& input ) { - - const int size = input.size(); - if ( size == 0 ) return ""; - - // all chars must be matched, or they fall in the catchall - const char* expr = "([[:word:]])" // 1 : allowed chars - "|^(~)" // 2 : starting ~ - "|([~])" // 3 : then ok - "|(\\*)" // 4 : star - "|([+])" // 5 : + - "|([-])" // 6 : - - "|(.)"; // 7 : default catchall. - - const char* replace = "(?1$1)" - "(?2anti)" - "(?3~)" - "(?4st)" - "(?5plus)" - "(?6minus)" - "(?7_)"; - - std::string ret; - boost::regex e( expr ); - ret = boost::regex_replace( input, e, replace, boost::match_default | boost::format_all ); - - // remove double __ and trailing and leading _ - e.assign( "(^_+)|(_+$)|(_{2,})" ); - ret = boost::regex_replace( ret, e, "(?1)(?2)(?3_)", boost::match_default | boost::format_all ); - - return ret; - } - // ========================================================================== -} // end of namespace Decays -// ============================================================================ -// The END -// ============================================================================ diff --git a/Phys/DaVinciKernel/src/Lib/GetTESLocations.cpp b/Phys/DaVinciKernel/src/Lib/GetTESLocations.cpp deleted file mode 100644 index 520a4f2c36b4e680a2d33df1f052d96e4563dd9a..0000000000000000000000000000000000000000 --- a/Phys/DaVinciKernel/src/Lib/GetTESLocations.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -// ============================================================================ -// Include files -// ============================================================================ -// GaudiKernel -// ============================================================================ -#include "GaudiKernel/IRegistry.h" -// ============================================================================ -// Local -// ============================================================================ -#include "Kernel/GetTESLocations.h" -// ============================================================================ -/** @file - * Implementation file for class DaVinci::Utils::GetTESLocations - * - * @date 2016-02-16 - * @author Vanya Belyaev Ivan.Belyaev@itep.ru - * - */ -// ============================================================================ -// destructor -// ============================================================================ -DaVinci::Utils::GetTESLocations::~GetTESLocations() { - m_mapping.clear(); - m_locations.clear(); -} -// ============================================================================ -// add TES-location -// ============================================================================ -std::size_t DaVinci::Utils::GetTESLocations::_collect( const DataObject* o ) { - const IRegistry* iregistry = nullptr == o ? nullptr : o->registry(); - if ( nullptr == iregistry ) { return 0; } - // - const std::string& n = iregistry->identifier(); - if ( m_mapping.insert( { o, n } ).second ) { - m_locations.push_back( n ); - return 1; - } - return 0; -} -// ============================================================================ -// The END -// ============================================================================ diff --git a/Phys/DaVinciKernel/src/Lib/PVSentry.cpp b/Phys/DaVinciKernel/src/Lib/PVSentry.cpp deleted file mode 100644 index 368d7bab1274ef7896208d51311f501c62b9e53e..0000000000000000000000000000000000000000 --- a/Phys/DaVinciKernel/src/Lib/PVSentry.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -// ============================================================================ -// Include files -// ============================================================================ -// PhysEvent -// ============================================================================ -#include "Event/Particle.h" -// ============================================================================ -// DaVinciIntefraces -// ============================================================================ -#include "Kernel/IDVAlgorithm.h" -// ============================================================================ -// local -// ============================================================================ -#include "Kernel/PVSentry.h" -// ============================================================================ -/** @file - * Implementation file for class DaVinci::PVSentry - * @author Vanya BELYAEV Ivan.Belyaev@itep.ru - * @date 2009-05-05 - * @see CombineParticles - * - */ -// ============================================================================ -namespace { - // ========================================================================== - inline std::size_t _insert_( std::vector& particles, const LHCb::Particle* particle, - const bool tree = false ) { - // - if ( nullptr == particle ) { return 0; } // RETURN - // - const std::size_t old_size = particles.size(); - particles.push_back( particle ); - // - if ( tree ) { - typedef SmartRefVector DAUGHTERS; - const DAUGHTERS& daughters = particle->daughters(); - for ( DAUGHTERS::const_iterator id = daughters.begin(); daughters.end() != id; ++id ) { - _insert_( particles, *id, tree ); - } - } - return particles.size() - old_size; - } - // ========================================================================== -} // namespace -// ============================================================================ -// Constructor -// ============================================================================ -DaVinci::PVSentry::PVSentry( const IDVAlgorithm* parent, const LHCb::Particle* particle, const bool tree ) - : m_parent( parent ), m_particles() { - m_particles.reserve( 10 ); - if ( parent ) { _insert_( m_particles, particle, tree ); } -} -// ============================================================================ -// destructor -// ============================================================================ -DaVinci::PVSentry::~PVSentry() { - if ( 0 != m_parent && !m_particles.empty() ) { - for ( const LHCb::Particle* p : m_particles ) { - if ( p ) { m_parent->unRelatePV( p ); } - } - } - m_particles.clear(); -} -// ============================================================================ - -// ============================================================================ -// The END -// ============================================================================ diff --git a/Phys/DaVinciKernel/src/Lib/ParticleFilters.cpp b/Phys/DaVinciKernel/src/Lib/ParticleFilters.cpp deleted file mode 100644 index 265de9162e45942747bf4a848c39c4503c1c50c6..0000000000000000000000000000000000000000 --- a/Phys/DaVinciKernel/src/Lib/ParticleFilters.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -// =========================================================================== -// Include files -// ============================================================================ -// DaVinciInterfaces -// ============================================================================ -#include "Kernel/IParticleFilter.h" -// ============================================================================ -// Local -// ============================================================================ -#include "Kernel/ParticleFilters.h" -// ============================================================================ -/** @file - * implementation of function DaVinci::filter - * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl - * @date 2010-05-14 - */ -// ============================================================================ -/** filter the particles according to some criteria - * - * @param input (INPUT) the container of input particles - * @param criterion (INPUT) the selection criteria - * @param output (OUPUT) the container of selected particles - * @reutrn number of added particles - * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl - * @date 2010-05-14 - */ -// ============================================================================ -std::size_t DaVinci::filter( const LHCb::Particle::Range& input, const IParticleFilter* criterion, - LHCb::Particle::ConstVector& output ) { - return ( !criterion ? 0 : filter( input, *criterion, output ) ); -} -// ============================================================================ -/** filter the particles according to some criteria - * - * @param input (INPUT) the container of input particles - * @param criterion (INPUT) the selection criteria - * @param output (OUPUT) the container of selected particles - * @reutrn number of added particles - * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl - * @date 2010-05-14 - */ -// ============================================================================ -std::size_t DaVinci::filter( const LHCb::Particle::ConstVector& input, const IParticleFilter* criterion, - LHCb::Particle::ConstVector& output ) { - return ( !criterion ? 0 : filter( input, *criterion, output ) ); -} -// ============================================================================ -/* split the particles according to some criteria - * - * @param input (INPUT) the container of input particles - * @param criterion (INPUT) the selection criteria - * @param output (OUPUT) the container of selected particles - * @param output2 (OUPUT) the container of non-selected particles - * @return number of added particles - * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl - * @date 2010-05-14 - */ -// ============================================================================ -std::size_t DaVinci::filter( const LHCb::Particle::Range& input, const IParticleFilter* criterion, - LHCb::Particle::ConstVector& output, LHCb::Particle::ConstVector& output2 ) { - return ( !criterion ? 0 : filter( input, *criterion, output, output2 ) ); -} -// ========================================================================== -/* split the particles according to some criteria - * - * @param input (INPUT) the container of input particles - * @param criterion (INPUT) the selection criteria - * @param output (OUPUT) the container of selected particles - * @param output2 (OUPUT) the container of non-selected particles - * @return number of added particles - * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl - * @date 2010-05-14 - */ -// ============================================================================ -std::size_t DaVinci::filter( const LHCb::Particle::ConstVector& input, const IParticleFilter* criterion, - LHCb::Particle::ConstVector& output, LHCb::Particle::ConstVector& output2 ) { - return filter( LHCb::Particle::Range( input ), criterion, output, output2 ); -} -// ========================================================================== - -// ============================================================================ -// The END -// ============================================================================ diff --git a/Phys/DaVinciKernel/src/component/DecayFinder.cpp b/Phys/DaVinciKernel/src/component/DecayFinder.cpp index cbe5e61e7f29a3a67c4beb02b75d41ccc207966b..c7a05aa9a182b841d549dcbfc5fc9c6d9357c433 100644 --- a/Phys/DaVinciKernel/src/component/DecayFinder.cpp +++ b/Phys/DaVinciKernel/src/component/DecayFinder.cpp @@ -8,12 +8,1250 @@ * granted to it by virtue of its status as an Intergovernmental Organization * * or submit itself to any jurisdiction. * \*****************************************************************************/ - +#include "Event/MCParticle.h" +#include "Event/Particle.h" #include "GaudiAlg/GaudiTool.h" +#include "GaudiKernel/GaudiException.h" +#include "GaudiKernel/IMessageSvc.h" +#include "GaudiKernel/MsgStream.h" +#include "GaudiKernel/ServiceHandle.h" #include "Kernel/IDecayFinder.h" // My Interface -#include "Kernel/Tree.h" +#include "Kernel/IParticlePropertySvc.h" +#include "Kernel/ParticleProperty.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include namespace Decay { + + namespace detail { + /// check if node is marked with ^ (invoked in constructor) + bool checkisMarked( std::string_view node_name ) { + // output true if the expression has a "^" + return node_name.find( '^' ) != node_name.npos; + }; + + /// check if node has CC (invoked in constructor) + bool checkhasCC( std::string_view node_name ) { + // output true if the expression has "CC" + return node_name.find( "CC" ) != node_name.npos; + } + + /// prune the node from operators and returns the particle name only (invoked in constructor) + std::tuple pruneNodeName( const std::string& node_name ) { // TODO: make sure this + // is well + // documented + std::string pruned_node_name; + bool hasCC = checkhasCC( node_name ); + bool isMarked = checkisMarked( node_name ); + // cleans the nodes from operators and returns the particle name only + constexpr auto expression = []( bool cc, bool marked ) { + if ( cc && marked ) { // if node has self CC and is marked + return std::regex( "\\^" // hat + "\\s*\\[" // any whitespaces and a square bracket + "\\s*(\\S+)\\s*" // any whitespace then one or more non-whitespace character(s) + // that is matched "(\\S+)" then any whitespace + "\\]\\s*CC" // closing square bracket then any whitespace and then a CC + ); + } else if ( cc && !marked ) { // if node has self CC + return std::regex( "\\[" // square bracket + "\\s*(\\S+)\\s*" // any whitespace then one or more non-whitespace character(s) + // that is matched "(\\S+)" then any whitespace + "\\]\\s*CC" // closing square bracket then any whitespace and then a CC + ); + } else if ( !cc && marked ) { // if node is marked + return std::regex( "\\^" // hat + "\\s*(\\S+)\\s*" // any whitespace then one or more non-whitespace character(s) + // that is matched "(\\S+)" then any whitespace + ); + } else { + return std::regex( "^\\s*" // any initial whitespaces + "(\\S+)" // matches particle name + "\\s*$" // any final whitespaces + ); + } + }; + + std::smatch what; + std::regex_search( node_name, what, expression( hasCC, isMarked ) ); + return std::make_tuple( what.str( 1 ), hasCC, isMarked ); + } + } // namespace detail + + class Node { + public: + /// constructors + Node( const std::string& node_name ); + Node( const int pid, const bool hasCC, const bool isMarked ); + Node( const LHCb::Particle& ); + Node( const LHCb::MCParticle& ); + + /// get charge conjugated node + Node getChargeConjugate( bool reversehasCC = false ) const; + /// reverse the has CC flag + void reversehasCC() { m_hasCC = !m_hasCC; } + /// get the possibilities of the node i.e. [mu+]CC should give vec(mu+, mu-) + std::vector getPossibilities() const; + /// get particle name + std::string name() const { return getNameFromPid( m_pid ); } + + /* getters */ + /// get particle id + int pid() const { return m_pid; } + /// get has CC flag + bool hasCC() const { return m_hasCC; } + /// get is marked flag with ^ + bool isMarked() const { return m_isMarked; } + + /* setters */ + /// set pid + void setpid( const int& pid ) { m_pid = pid; } + /// set CC flag + void sethasCC( const bool& cc ) { m_hasCC = cc; } + /// set marked flag + void setisMarked( const bool& marked ) { m_isMarked = marked; } + + /* operator */ + /// operator << implementations + friend std::ostream& operator<<( std::ostream& os, const Node& node ); + /// operator == implementations + friend bool operator==( const Node& lhs, const Node& rhs ); + /// non-templated class implementation, comparaison between a Particle and a Node + template + friend bool operator==( const Node& lhs, const PARTICLE* const rhs ); + + private: + /// get pid from name + int getPidFromName( const std::string& node_name ) const; + /// get pid from name + std::string getNameFromPid( int pid ) const; + /// get antiparticle pid + int getAntiParticlePid( int pid ) const; + + /// node ID + int m_pid = 0; + /// check if node has CC + bool m_hasCC = false; + /// node marked with ^ + bool m_isMarked = false; + /// messaging service + ServiceHandle m_msgSvc{ "MessageSvc", "MessageSvcName" }; + /// particle property service + //"LHCb::" prefix in string since its defined in namespace! + ServiceHandle m_ppSvc{ "LHCb::ParticlePropertySvc", "LHCb::ParticlePropertySvcName" }; + }; + + Node::Node( const std::string& node_name ) { + auto tuple_nodeprops = detail::pruneNodeName( node_name ); + m_pid = getPidFromName( std::get<0>( tuple_nodeprops ) ); + m_hasCC = std::get<1>( tuple_nodeprops ); + m_isMarked = std::get<2>( tuple_nodeprops ); + } + + // constructor for Node with pid, hasCC and isMarked + Node::Node( const int pid, const bool hasCC, const bool isMarked ) + : m_pid{ pid }, m_hasCC{ hasCC }, m_isMarked{ isMarked } {} + + Node::Node( LHCb::Particle const& particle ) : Node{ particle.particleID().pid(), false, false } {} + + Node::Node( LHCb::MCParticle const& mcparticle ) : Node{ mcparticle.particleID().pid(), false, false } {} + + Node Node::getChargeConjugate( bool reversehasCC ) const { // get charge conjugated node + // make a copy of the current node + Node node_cc{ *this }; + // set the pid of the antiparticle + node_cc.setpid( getAntiParticlePid( m_pid ) ); + // reverse the hasCC flag (if requested) as it can help with + // the recursive calling of operator== + if ( reversehasCC ) node_cc.reversehasCC(); + return node_cc; + } + + int Node::getAntiParticlePid( int pid ) const { + // get the particle property of the node + const auto* part_prop = m_ppSvc->find( LHCb::ParticleID( pid ) ); // ptr to LHCb::ParticleProperty + if ( !part_prop ) + throw GaudiException{ "Could not interpret the particle ID " + std::to_string( pid ) + + ". Please check your descriptor.", + "Decay::Node::getChargeConjugate()", StatusCode::FAILURE }; + + // get antiparticle pid of the current node + const auto* part_prop_cc = part_prop->antiParticle(); + if ( !part_prop_cc ) + throw GaudiException{ "Could not find antiparticle of the particle with ID " + std::to_string( pid ) + + ". Please check your descriptor.", + "Decay::Node::getChargeConjugate()", StatusCode::FAILURE }; + + return part_prop_cc->pid().pid(); + } + + /// returns a vector of node possibilities based on the CC property of the Node + std::vector Node::getPossibilities() const { + // set hasCC property to false for all possibilities because we want vector of "simple" nodes + if ( m_hasCC ) { + return { Node{ m_pid, false, m_isMarked }, Node{ getAntiParticlePid( m_pid ), false, m_isMarked } }; + } + return { Node{ m_pid, false, m_isMarked } }; + } + + int Node::getPidFromName( const std::string& name ) const { + const auto* part_prop = m_ppSvc->find( name ); // ptr to LHCb::ParticleProperty + if ( !part_prop ) + throw GaudiException{ "Could not interpret the node name " + name + ". Please check your descriptor.", + "Decay::Node::getPidFromName()", StatusCode::FAILURE }; + return part_prop->pid().pid(); + } + + std::string Node::getNameFromPid( int pid ) const { + const auto* part_prop = m_ppSvc->find( LHCb::ParticleID( pid ) ); // ptr to LHCb::ParticleProperty + if ( !part_prop ) + throw GaudiException{ "Could not interpret the particle ID " + std::to_string( pid ) + + ". Please check your descriptor.", + "Decay::Node::getNameFromPid()", StatusCode::FAILURE }; + return part_prop->name(); + } + + std::ostream& operator<<( std::ostream& os, const Node& node ) { + if ( node.m_hasCC ) { + if ( node.m_isMarked ) + os << "^[" << node.name() << "]CC"; + else + os << "[" << node.name() << "]CC"; + } else if ( node.m_isMarked ) + os << "^" << node.name(); + else + os << node.name(); + return os; + } + + bool operator==( const Node& lhs, const Node& rhs ) { + if ( lhs.m_pid == rhs.m_pid ) return true; + + bool reversehasCC = true; + if ( lhs.m_hasCC ) { + // Return a copy of this node with charged conjugate node and hasCC flag set to false + // hasCC flag has to be false otherwise stuck in infinite loop + return rhs == lhs.getChargeConjugate( reversehasCC ); + } else if ( rhs.m_hasCC ) { + // Return a copy of this node with charged conjugate node and hasCC flag set to false + // hasCC flag has to be false otherwise stuck in infinite loop + return lhs == rhs.getChargeConjugate( reversehasCC ); + } + return false; + } + + template + bool operator==( const Node& lhs, const PARTICLE* const rhs ) { + return lhs.m_pid == rhs->particleID().pid(); + } + + enum struct Arrow { + Unknown = 0, + Single, /// single arrow "->" + LongSingle, /// long single arrow "-->" + Double, /// double arrow "=>" + LongDouble, /// long double arrow "==>" + SingleX, /// single arrow "-x>" + LongSingleX, /// long single arrow "--x>" + DoubleX, /// double arrow "=x>" + LongDoubleX /// long double arrow "==x>" + }; + + static constexpr auto ValidArrows = + std::array{ Arrow::Single, Arrow::LongSingle, Arrow::Double, Arrow::LongDouble, + Arrow::SingleX, Arrow::LongSingleX, Arrow::DoubleX, Arrow::LongDoubleX }; + + /// string representation of the arrow + inline std::string toString( Arrow arrow ) { + switch ( arrow ) { + case Arrow::Unknown: + return "Unknown"; + case Arrow::Single: + return "->"; + case Arrow::LongSingle: + return "-->"; + case Arrow::Double: + return "=>"; + case Arrow::LongDouble: + return "==>"; + case Arrow::SingleX: + return "-x>"; + case Arrow::LongSingleX: + return "--x>"; + case Arrow::DoubleX: + return "=x>"; + case Arrow::LongDoubleX: + return "==x>"; + default: + return "None"; + } + } + + /// operator<< + inline std::ostream& operator<<( std::ostream& os, Arrow arrow ) { return os << toString( arrow ); } + + class Tree; + + template + concept isParticle = std::same_as || std::same_as; + + // forward declare for detail namespace + namespace detail { + struct classprops_t { + Decay::Node headNode; + Decay::Arrow first_arrow; + std::vector daughters; + bool hasCC; + bool isMarked; + }; + struct arrowprops_t { + Decay::Arrow first_arrow; + unsigned int n_first_arrow; + size_t first_arrow_pos; + unsigned int n_arrowtypes; + }; + using tuple_parentdaughter_t = std::tuple; + using vec_str_t = std::vector; + using vec_dt_t = std::vector; + using vec_vec_dt_t = std::vector; + template + using vec_ptr_t = std::vector; + + classprops_t parseDescriptor( std::string descriptor ); + vec_vec_dt_t cartesianProduct( const vec_vec_dt_t& vec_vec_dt ); + + void pruneDescriptor( std::string& s ); + + /// Helper function to get daughter for particle and MCParticle + auto getParticleDaughters( const LHCb::Particle& particle ) { + return LHCb::range::to( particle.daughters() ); + } + + auto getParticleDaughters( const LHCb::MCParticle& particle ) { + const auto* goodVtx = particle.goodEndVertex(); + // if goodVtx is null (could be basic particles) so just return an empty vector + if ( !goodVtx ) return LHCb::MCParticle::ConstVector{}; + return LHCb::MCParticle::ConstVector( goodVtx->products().begin(), goodVtx->products().end() ); + } + + } // namespace detail + + class Tree { + public: + /// constructors + Tree( const std::string& descriptor ); + Tree( detail::classprops_t ); + Tree( Node ); + /// TODO: Could sort daughter subtree descriptors by their depth (also applies to constructor Tree(particle) ) + Tree( Node headNode, Arrow arrow, detail::vec_dt_t daughters, bool hasCC, bool isMarked ); + Tree( LHCb::Particle const& ); // Particle constructor + Tree( LHCb::MCParticle const& ); // MCParticle constructor + + /// get charge conjugated node + Tree getChargeConjugate( bool reversehasCC = false ) const; + /// reverse the has CC flag + void reversehasCC() { m_hasCC = !m_hasCC; } + /// has daughters + bool hasDaughters() const { return !m_daughters.empty(); } + /// get descriptor + std::string descriptor() const; + /// get possibilities of "simple" descriptors from "complex" descriptor + /// e.g. "B0 -> [K+]CC pi-" gives two possibilities: [B0 -> K+ pi- , B0 -> K- pi+] + detail::vec_dt_t getPossibilities() const; + /// Compare current tree with the reference tree. + /// The "simple" reference tree (i.e. wih isMarked or hasCC flags to false) could have been created with + /// reconstructed particle. Note the reference tree is non-const, since the isMarked property from current tree is + /// transferred to the reference tree when there is match. + /// TODO: remove in current implementation + bool compareWithRefTree( Tree& ref_dt ) const; + + /* getters */ + /// get node + Node headNode() const { return m_headNode; } + /// get const reference to the daughters + const detail::vec_dt_t& daughters() const { return m_daughters; } + /// get hasCC + bool hasCC() const { return m_hasCC; } + /// get isMarked + bool isMarked() const { return m_isMarked; } + /// get has matched + bool hasMatched() const; + /// get arrow + Arrow arrow() const { return m_Arrow; } + + /* setters */ + /// set headNode + void setheadNode( Node headNode ) { m_headNode = headNode; } + /// set daughters + void setdaughters( detail::vec_dt_t daughters ) { m_daughters = daughters; } + /// set hasCC + void sethasCC( bool hasCC ) { m_hasCC = hasCC; } + /// set isMarked + void setisMarked( bool isMarked ) { m_isMarked = isMarked; } + /// set has matched + void sethasMatched( bool hasMatched ); + /// set arrow + void setArrow( Arrow arrow ) { m_Arrow = arrow; } + + /// friend function for operator<< + friend std::ostream& operator<<( std::ostream& os, const Tree& dt ); + /// friend function for operator== + /// TODO: remove in current implementation + friend bool operator==( const Tree& lhs, const Tree& rhs ); + /// friend function for operator!= + // friend function comparing two trees (Note: Arguments are non-const references) + // They are non-const since the isMarked and hasMatched flags of the trees are modified. + /// TODO: remove + friend bool checkIfTreesMatch( Tree& lhs, Tree& rhs ); + + /// DecayFinder no template implementation + /// friend function comparing a particle and a tree note: internally makes a copy of the tree to change the + /// m_hasMatched property of the tree to deal with identical particles + template + friend bool operator==( const PARTICLE& lhs, const Tree& rhs ); + /// loop over the particle and the decaytree to evaluate if they match + template + bool hasMatchWithParticle( const PARTICLE& particle ); + /// finds the marked particles and fills the output vector + template + void collectMarkedParticles( const PARTICLE* particle, std::vector& output ) const; + + private: + /// TODO: Check that the following private functions are well documented + /// private function that works with collectMarkedParticlesImpl + template + void collectMarkedParticlesRecursive( const PARTICLE* particle, std::vector& output ); + /// set all the headNodes isMarked along with current and sub-trees isMarked flag + /// TODO: remove + void setAllisMarked( bool isMarked ); + + /// head node + Node m_headNode; + /// Arrow type + Arrow m_Arrow{ Arrow::Unknown }; + /// vector of daughters + detail::vec_dt_t m_daughters; + /// has cc flag in decay e.g. [B0 -> K+ K-]CC + bool m_hasCC{ false }; + /// is marked flag in decay e.g. ^(B0 -> K+ K-) or ^([B0 -> K+ K-]CC) + bool m_isMarked{ false }; + /// decay tree has been matched + std::optional m_hasMatched{}; + /// messaging service + /// TODO: Need to set the verbosity of messaging service + ServiceHandle m_msgSvc{ "MessageSvc", "MessageSvcName" }; + }; + + Tree::Tree( Node headNode ) : m_headNode{ std::move( headNode ) } {} + + Tree::Tree( Node headNode, Arrow arrow, detail::vec_dt_t daughters, bool hasCC, bool isMarked ) + : m_headNode{ std::move( headNode ) } + , m_Arrow{ arrow } + , m_daughters{ std::move( daughters ) } + , m_hasCC{ hasCC } + , m_isMarked{ isMarked } {} + + Tree::Tree( detail::classprops_t props ) + : Tree{ std::move( props.headNode ), props.first_arrow, std::move( props.daughters ), props.hasCC, + props.isMarked } {} + + Tree::Tree( const std::string& descriptor_str ) : Tree{ detail::parseDescriptor( descriptor_str ) } {} + + Tree::Tree( LHCb::Particle const& particle ) : m_headNode{ Node( particle ) }, m_Arrow{ Arrow::Single } { + // get parent particle pointer from "pointer of pointer" + // check if it is basic + if ( !particle.isBasicParticle() ) { + // if not loop over daughter particles + const auto& children = particle.daughters(); + std::transform( children.begin(), children.end(), std::back_inserter( m_daughters ), + []( const auto& d ) { return Node{ *d }; } ); + } + } + + Tree::Tree( LHCb::MCParticle const& mcparticle ) : m_headNode{ mcparticle }, m_Arrow{ Arrow::Single } { + // get MCParticle's first end-vertex that likely destroyed the particle + if ( const auto* goodVtx = mcparticle.goodEndVertex(); goodVtx ) { + // if not loop over daughter particles + const auto& children = goodVtx->products(); + std::transform( children.begin(), children.end(), std::back_inserter( m_daughters ), + []( const auto& ref ) { return *ref; } ); + } + } + + Tree Tree::getChargeConjugate( bool reversehasCC ) const { // get charge conjugated + // copy of current tree + // create new Tree with current tree + Tree cc_tree{ *this }; + // change the headNode to the charge conjugated node (a copy with opposite pid/name) + // It does not change the hasCC flag + cc_tree.setheadNode( m_headNode.getChargeConjugate() ); + // change the daughters to the charge conjugated daughters + detail::vec_dt_t cc_daughters; // make a new vector of decay trees + cc_daughters.reserve( m_daughters.size() ); // reserve space for the daughters + // loop over the daughters and get the charge conjugated copy of daughters + for ( auto& daughter : m_daughters ) cc_daughters.emplace_back( daughter.getChargeConjugate() ); + // set cc_tree daughters to cc_daughters + cc_tree.setdaughters( cc_daughters ); + // reverse the hasCC flag of current decay tree + if ( reversehasCC ) cc_tree.reversehasCC(); + return cc_tree; + } + + std::string Tree::descriptor() const { + std::stringstream ss; + if ( !m_daughters.empty() ) { // if decay tree is not empty + if ( m_isMarked ) ss << "^("; + if ( m_hasCC ) ss << "["; + + ss << m_headNode << " " << m_Arrow << " "; + unsigned int count_daug = 0; + for ( const auto& daug : m_daughters ) { + if ( !daug.daughters().empty() && !daug.isMarked() ) + ss << "(" << daug << ")"; + else + ss << daug; + if ( count_daug != m_daughters.size() - 1 ) ss << " "; + count_daug++; + } + } else // if decay tree is empty + ss << m_headNode; + + if ( m_hasCC && !m_daughters.empty() ) ss << "]CC"; + if ( m_isMarked ) ss << ")"; + + return ss.str(); + } + + detail::vec_dt_t Tree::getPossibilities() const { + // first get head node possibilities + // e.g. "[B+]CC" -> [Node(B+), Node(B-)] + std::vector headnode_possibilities{ m_headNode.getPossibilities() }; + // if no daughters in the tree convert headnodes into decaytrees with no daughters and return it + // e.g. "[B+]CC" -> [Tree(B+), Tree(B-)] + detail::vec_dt_t tree_possibilities; + if ( !hasDaughters() ) { + for ( const auto& node : headnode_possibilities ) tree_possibilities.emplace_back( node ); + return tree_possibilities; + } + // if the Tree has daughters make a vector of vector of decaytrees with daughters + // e.g. for descriptor "B0 -> [K1+]CC K2-", the daug_possibilities will be "[ [Tree(K1+), Tree(K1-)], [Tree(K2-)] ]" + detail::vec_vec_dt_t daug_possibilities; + for ( const auto& daug : m_daughters ) daug_possibilities.emplace_back( daug.getPossibilities() ); + // get all the possible permutations of daughter corresponding to B0 + // e.g. for descriptor "B0 -> [K1+]CC K2-" descriptor, + // the daug_possibilities will become after cartesian product -> "[ [Tree(K1+), Tree(K2-)], [Tree(K1-), Tree(K2-)] + // ]" + daug_possibilities = detail::cartesianProduct( daug_possibilities ); + for ( std::size_t i = 0; i < headnode_possibilities.size(); i++ ) { // loop over head node tree possibility + for ( std::size_t j = 0; j < daug_possibilities.size(); j++ ) { // loop over daughter tree possibility + // create an instance of decayTree with headnode and daughters + bool hasCC{ false }; // set hasCC false since we have "simple" decay descriptors removing hasCC + tree_possibilities.emplace_back( headnode_possibilities[i], m_Arrow, daug_possibilities[j], hasCC, m_isMarked ); + // if the current tree hasCC to true in the decay add the conjugated tree to the possibilities + if ( m_hasCC ) { + Tree dt( headnode_possibilities[i], m_Arrow, daug_possibilities[j], hasCC, m_isMarked ); + tree_possibilities.emplace_back( dt.getChargeConjugate() ); // false as the DT are plain (without operators) + } // if hasCC + } // loop over daughter tree possibility + } // loop over head node tree possibility + return tree_possibilities; + } + + /// get has matched + bool Tree::hasMatched() const { + // if composite check if all daughters have matched + if ( hasDaughters() ) { // has daughters + for ( auto& daughter : m_daughters ) + if ( !daughter.hasMatched() ) return false; // no hasMatched in daughters + return true; // all daughters have hasMatched + } + // if basic return value of m_hasMatched + return m_hasMatched.value_or( false ); + } + + void Tree::sethasMatched( bool hasMatched ) { + // first set all daughters hasMatched flag if composite + // the m_hasMatched flag for composite itself will be std::nullopt since its definition + // entirely depends on if the daughters have been matched or not. + if ( hasDaughters() ) + for ( auto& daughter : m_daughters ) daughter.sethasMatched( hasMatched ); + else + // if basic particle, set hasMatched flag + m_hasMatched = std::optional{ hasMatched }; + } + + std::ostream& operator<<( std::ostream& os, const Tree& dt ) { return os << dt.descriptor(); } + + /////////////// implementation for DecayFinder + template + bool operator==( const PARTICLE& lhs, const Tree& rhs ) { + // make a copy of the decay tree + return Tree{ rhs }.hasMatchWithParticle( lhs ); + } + + template + bool Tree::hasMatchWithParticle( const PARTICLE& particle ) { + // set messaging service + MsgStream log( ( m_msgSvc ).get(), "Decay::Tree" ); + bool is_verbose = ( log.level() == MSG::VERBOSE ); + // check for nullptr + // create a reference tree from the reconstructed particle (for debugging) + Tree ref_dt( particle ); + // bool is_verbose = true; + if ( is_verbose ) log << MSG::INFO << "Comparing tree: " << *this << "with particle: " << ref_dt << endmsg; + // check if the head nodes match + if ( m_headNode != &particle ) return false; + // head nodes have matched + if ( is_verbose ) + log << MSG::INFO << "Head nodes are equal b/w: " << m_headNode << " and RHS: " << ref_dt.m_headNode << endmsg; + // check if the user tree doesn't have daughters + if ( !( hasDaughters() ) ) { + sethasMatched( true ); + return true; + } + // both trees have daughters + if ( is_verbose ) + log << MSG::INFO << "Trees: " << *this << " and particle: " << ref_dt << " both have daughters." << endmsg; + // check if daughter size is equal + if ( detail::getParticleDaughters( particle ).size() != ( m_daughters ).size() ) return false; + if ( is_verbose ) + log << MSG::INFO << "Trees: " << *this << " and particle: " << ref_dt << " have same daughter sizes." << endmsg; + // both trees have equal head node and equal daughter size + // compare the particle daughter with the tree daughter + for ( const auto* particle_daughter : detail::getParticleDaughters( particle ) ) { + for ( auto& tree_daughter : m_daughters ) { + // create a reference daughter tree + if ( is_verbose ) + log << MSG::INFO << "Comparing tree daughter: " << tree_daughter + << " and particle daughter: " << Tree( *particle_daughter ) << endmsg; + // check if tree daughter has already been matched + if ( tree_daughter.hasMatched() ) { + if ( is_verbose ) log << MSG::INFO << "Tree daughter has already been matched: " << tree_daughter << endmsg; + continue; + } + // check if the tree daughter matches with the particle daughter + else if ( tree_daughter.hasMatchWithParticle( *particle_daughter ) ) { + if ( is_verbose ) + log << MSG::INFO << "Match found for tree daughter: " << tree_daughter + << " and particle daughter: " << Tree( *particle_daughter ) << endmsg; + break; // when there is a match + } + // no match has been found + if ( is_verbose ) + log << MSG::INFO << "No match for tree daughter: " << tree_daughter + << " and particle daughter: " << Tree( *particle_daughter ) << endmsg; + } + } + // check if all the daughters have matched + if ( hasMatched() ) { + if ( is_verbose ) + log << MSG::INFO << "Everything has matched, Tree: " << *this << " and Particle: " << ref_dt << endmsg; + // need to set all the daughters to matched when the whole tree has matched. + sethasMatched( true ); + return true; + } else { + if ( is_verbose ) + log << MSG::INFO << "Not everything is matched, Tree: " << *this << " and Particle " << ref_dt << endmsg; + // Even when the individual particles in a tree have matched, but the whole tree hasn't matched + // need to set all the daughters back to not being matched + sethasMatched( false ); + return false; + } + } + + template + void Tree::collectMarkedParticles( const PARTICLE* particle, std::vector& output ) const { + // check for nullptr + if ( !particle ) { + throw GaudiException{ + "The input particle is null (nullptr). Please check!", + "Decay::Tree::collectMarkedParticlesImpl(const PARTICLE *particle, std::vector &output)", + StatusCode::FAILURE }; + } + // make a copy of the tree here + Tree temp_tree{ *this }; + // check for hat in descriptor + if ( temp_tree.descriptor().find( '^' ) == temp_tree.descriptor().npos ) { + // when there is no hat, append the head particle + output.push_back( particle ); + return; + } + temp_tree.collectMarkedParticlesRecursive( particle, output ); + } + + bool Tree::compareWithRefTree( Tree& ref_dt ) const { // TODO: remove + // make a copy of the current tree + Tree current_dt_copy{ *this }; + bool hasMatched = checkIfTreesMatch( current_dt_copy, ref_dt ); + // if there is no match set the ref_dt properties to default ones + if ( !hasMatched ) { + ref_dt.sethasMatched( false ); + ref_dt.setAllisMarked( false ); + } + return hasMatched; + } + + bool operator==( const Tree& lhs, const Tree& rhs ) { // TODO: remove + // make a copy of the lhs and rhs + Tree lhs_copy{ lhs }; + Tree rhs_copy{ rhs }; + return checkIfTreesMatch( lhs_copy, rhs_copy ); + } + + bool checkIfTreesMatch( Tree& lhs, Tree& rhs ) { // TODO: remove + // set messaging service + MsgStream log( lhs.m_msgSvc.get(), "Decay::Tree" ); + bool is_verbose = ( log.level() == MSG::VERBOSE ); + // bool is_verbose = true; + if ( is_verbose ) log << MSG::INFO << "Comparing the descriptors LHS: " << lhs << "with RHS: " << rhs << endmsg; + + // define helper lambdas + //////////////////////////////////////////////////////////////// + // define a helper lambda to check if there is match with CC + auto has_match_with_cctree = [&lhs, &rhs]() -> bool { + // The conjugate object requires hasCC flag to false or else hit infinite loop + bool reversehasCC{ true }; + // if lhs or rhs hasCC set to true check with conjugate object + if ( lhs.m_hasCC ) { + // Note the getChargeConjugate will return a copy of the lhs tree with conjugate properties + return rhs == lhs.getChargeConjugate( reversehasCC ); + } else if ( rhs.m_hasCC ) { + // Note the getChargeConjugate will return a copy of the rhs tree with conjugate properties + return lhs == rhs.getChargeConjugate( reversehasCC ); + } // cases where both have hasCC true should be covered above + return false; // if both lhs and rhs do not hasCC to false return false + }; + + // define a helper lambda to set matching properties between lhs and rhs + auto set_isMarked_hasMatched = [&log, &is_verbose]( Tree& lhs, Tree& rhs ) -> void { + // set isMarked properties + if ( lhs.isMarked() || lhs.headNode().isMarked() || rhs.isMarked() || rhs.headNode().isMarked() ) { + if ( is_verbose ) log << MSG::INFO << "Tree/Node LHS: " << lhs << " or RHS: " << rhs << "is marked" << endmsg; + lhs.m_headNode.setisMarked( true ); // modify the head node and no the + rhs.m_headNode.setisMarked( true ); + } + // set hasMatched properties + lhs.sethasMatched( true ); + rhs.sethasMatched( true ); + }; + + auto hasMarkedDaughter = []( const Tree& dt ) -> bool { + // decaytree dt has daughters now check if one of its daughters is marked + for ( const Tree& daughter : dt.m_daughters ) + if ( daughter.isMarked() || daughter.headNode().isMarked() ) return true; + return false; + }; + //////////////////////////////////////////////////////////////// + + // check if the head nodes match + if ( lhs.m_headNode != rhs.m_headNode ) { + // if not check if hasCC is true and match with CC tree otherwise return false + if ( !has_match_with_cctree() ) return false; + } + + if ( is_verbose ) + log << MSG::INFO << "Head nodes are equal b/w LHS: " << lhs.m_headNode << " and RHS: " << rhs.m_headNode + << endmsg; + + // head nodes have matched now check if either of them has daughters + // if either lhs or rhs has no daughters (unequal trees) + // e.g. lhs: Jpsi and rhs: Jpsi -> mu+ mu-. + if ( !lhs.hasDaughters() || !rhs.hasDaughters() ) { + + // if the trees are un-equal and the user has marked a daughter send an error message and return false + // e.g. ref. DT: B->Jpsi Phi; user DT: B->(Jpsi->mu+ ^mu-) Phi + if ( !lhs.hasDaughters() && rhs.hasDaughters() && hasMarkedDaughter( rhs ) ) return false; + if ( lhs.hasDaughters() && !rhs.hasDaughters() && hasMarkedDaughter( lhs ) ) return false; + + // if both lhs and rhs haven't matched before, set isMarked flag and hasMatched + // flag appropriately and return true + if ( !lhs.hasMatched() && !rhs.hasMatched() ) { + if ( is_verbose ) + log << MSG::INFO << "None of the trees LHS: " << lhs << " and RHS: " << rhs << " were matched before." + << endmsg; + set_isMarked_hasMatched( lhs, rhs ); + return true; + } + + // daughters have already been matched return false + if ( is_verbose ) + log << MSG::INFO << "Trees LHS: " << lhs << " and RHS: " << rhs << " already have been matched." << endmsg; + return false; + } + + if ( is_verbose ) + log << MSG::INFO << "Trees LHS: " << lhs << " and RHS: " << rhs << " both have daughters." << endmsg; + + // both lhs and rhs have daughters, if daughter size doesn't match return false + if ( lhs.m_daughters.size() != rhs.m_daughters.size() ) return false; + if ( is_verbose ) + log << MSG::INFO << "Trees LHS: " << lhs << " and RHS: " << rhs << " have same daughter sizes." << endmsg; + + // now compare daughters (loops over all daughters setting hasMatched flag to true if matched) + for ( Tree& daug_lhs : lhs.m_daughters ) { + for ( Tree& daug_rhs : rhs.m_daughters ) { + if ( is_verbose ) + log << MSG::INFO << "Comparing daughters of trees LHS: " << daug_lhs << " and RHS: " << daug_rhs << endmsg; + // checks if daughters are not equal OR if daughters have already been + // matched: in both cases continue + if ( ( daug_lhs != daug_rhs ) || ( daug_lhs.hasMatched() && daug_rhs.hasMatched() ) ) { + if ( is_verbose ) + log << MSG::INFO << "No match found or daughters have already been matched for LHS: " << daug_lhs + << " and RHS: " << daug_rhs << endmsg; + continue; + } else { // match was found and daughters have not previously been matched + // set isMarked flag and hasMatched flag appropriately + if ( is_verbose ) + log << MSG::INFO << "Match found for daughters LHS: " << daug_lhs << " and RHS: " << daug_rhs << endmsg; + // will have to transfer the marked properties after the match + checkIfTreesMatch( daug_lhs, daug_rhs ); + set_isMarked_hasMatched( daug_lhs, daug_rhs ); + break; // if match break + } + } + } + // check if all daughters have been matched + // require here that both lhs and rhs have matched daughters + if ( !lhs.hasMatched() && !rhs.hasMatched() ) { + if ( is_verbose ) + log << MSG::INFO << "Not everything is matched, trying with CC if hasCC is true, LHS: " << lhs + << " and RHS: " << rhs << endmsg; + // if not check if hasCC is true and match with CC tree otherwise return false + if ( !has_match_with_cctree() ) return false; + } + if ( is_verbose ) log << MSG::INFO << "Everything has matched, LHS: " << lhs << " and RHS: " << rhs << endmsg; + + // everything has matched return true + // set isMarked flag and hasMatched flag appropriately + set_isMarked_hasMatched( lhs, rhs ); + return true; + } + + template + void Tree::collectMarkedParticlesRecursive( const PARTICLE* particle, std::vector& output ) { + // check for nullptr + if ( !particle ) { + throw GaudiException{ "The input particle is null (nullptr). Please check!", + "Decay::Tree::collectMarkedParticlesRecursive(const PARTICLE *particle, std::vector &output)", + StatusCode::FAILURE }; + } + // compare the head nodes + if ( m_headNode != particle ) return; + // head nodes have matched + // check if the user tree doesn't have daughters + if ( !( hasDaughters() ) ) { + // set has matched of head node w/o daughters to true (helps with identical particles) + sethasMatched( true ); + // if node or tree marked push to output vector + if ( isMarked() || ( headNode() ).isMarked() ) output.push_back( particle ); + return; + } + // both trees have daughters + // if daughter size is unequal return + if ( detail::getParticleDaughters( *particle ).size() != ( daughters() ).size() ) return; + // both trees have equal head node and equal daughter size + // if node or tree marked push to output vector + if ( isMarked() || ( headNode() ).isMarked() ) output.push_back( particle ); + // compare the daughters + for ( const auto* particle_daughter : detail::getParticleDaughters( *particle ) ) { + for ( auto& tree_daughter : m_daughters ) { + if ( tree_daughter.hasMatched() ) + continue; // daughter has already been matched continue (dealing with identical particles) + else if ( tree_daughter == *particle_daughter ) { // daughters are equal, find the marked particle + tree_daughter.collectMarkedParticlesRecursive( particle_daughter, output ); + break; + } + } // tree daughter loop + } // particle daughter loop + } + + void Tree::setAllisMarked( bool isMarked ) { // TODO: remove + // set the current tree and head nodes isMarked flag + m_headNode.setisMarked( isMarked ); + m_isMarked = isMarked; + // if daughters exist then iteratively set their properties + if ( hasDaughters() ) + for ( auto& daughter : m_daughters ) daughter.setAllisMarked( isMarked ); + } + + namespace detail { + + /// Cartesian product between the vectors in a vector of vectors, similar to the itertools.product in Python + /// e.g. for a vector of vectors of ints { {1, 2}, {11, 12, 13}, {21, 22} } it would return + /// { {1, 11, 21}, {1, 11, 22}, {1, 12, 21}, {1, 12, 22}, ... {2, 13, 22} } + vec_vec_dt_t cartesianProduct( const vec_vec_dt_t& vec_vec_dt ) { + // TODO: Try to clean this up a little bit + vec_vec_dt_t result = { {} }; // TODO: Try to reserve the memory + for ( const auto& vector1 : vec_vec_dt ) { + vec_vec_dt_t res_tmp; + for ( const auto& vector2 : result ) { + for ( const auto& decayTree : vector1 ) { + res_tmp.push_back( vector2 ); + res_tmp.back().push_back( decayTree ); + } + } + result = std::move( res_tmp ); // moves all elements from r to result leaving r empty + } + return result; + } + + /// strips initial and trailing whitespaces from descriptor + void pruneDescriptor( std::string& s ) { + // strips initial and trailing whitespaces from a string + auto isspace = []( const char c ) { return std::isspace( c ); }; + s.erase( std::find_if_not( s.rbegin(), s.rend(), isspace ).base(), s.end() ); + s.erase( s.begin(), std::find_if_not( s.begin(), s.end(), isspace ) ); + } + + /// check that the descriptor contains balanced brackets (any type) i.e. opening brackets have corresponding + /// closing one ((...)) + bool hasBalancedBrackets( std::string_view str ) { // function to check if brackets are + // balanced in a descriptor + // Opening/closing sets line up by index: '(' <-> )', '[' <-> ']', '{' <-> '}' + constexpr std::string_view opens = "([{"; + constexpr std::string_view closes = ")]}"; + + std::vector stack; // store indices into opens/closes + stack.reserve( str.size() / 2 ); + + for ( char c : str ) { + if ( auto oi = opens.find( c ); oi != opens.npos ) { + stack.push_back( oi ); + } else if ( auto ci = closes.find( c ); ci != closes.npos ) { + if ( stack.empty() || stack.back() != ci ) return false; // mismatch + stack.pop_back(); + } + } + return stack.empty(); + } + + /// strips the descriptor from [...]CC and sets m_hasCC flags (invoked in constructor) + bool stripCCFromDescriptor( std::string& descriptor ) { // function used for descriptor + // parsing + // define a helper lambda function to check cc + auto checkHasCC = []( const std::string& descriptor ) -> bool { + // output true if the expression has "CC" and false otherwise + std::regex expression( "^\\[" // square bracket at the beginning of string + ".*" // any character in between + "\\]\\s*CC$" // square bracket and CC at end of string + ); + return std::regex_search( descriptor, expression ); + }; + + // set hasCC to false + bool hasCC = false; + + // prune descriptor if it has CC + pruneDescriptor( descriptor ); + + // check that we have balanced square brackets then set hasCC to true and strip square brackets + if ( checkHasCC( descriptor ) ) { + // if "CC" then strip it from descriptor + // e.g. "[[X]CC -> Y1 [Y2]CC]CC" => "[X]CC -> Y1 [Y2]CC" + std::regex expression( "^\\[" // opening square bracket at start of string + "\\s*" // any whitespaces + "(.*)" // matches what is in between i.e. striped descriptor + "\\]" // closing bracket + "\\s*CC$" // any whitespaces followed by CC at end of string + ); + std::smatch what; + std::regex_search( descriptor, what, expression ); + // descriptor has been strip of outer-most [..]CC, now check if the square brackets are balanced + // This is required for cases where the descriptor is "[X]CC -> Y1 [Y2]CC" and + // the checkHassCC passes with descriptor = "X]CC -> Y1 [Y2" but this is an invalid descriptor. + if ( hasBalancedBrackets( what.str( 1 ) ) ) { // check for balanced brackets + hasCC = true; + descriptor = what.str( 1 ); + pruneDescriptor( descriptor ); + } // No need to throw an error here + } + return hasCC; + } + + /// strips the descriptor from the hat ^(...) and sets m_isMarked flags (invoked in Tree constructor) + bool stripHatFromDescriptor( std::string& descriptor ) { // function used for descriptor + // parsing + + // define a helper lambda function for checking if marked + auto checkisMarked = []( const std::string& descriptor ) { + const std::regex expression( "^\\^" // hat at start of string + "\\s*\\(" // any number of space and a bracket + ".*" // any characters + "\\)" // closing bracket + ); + return std::regex_search( descriptor, expression ); + }; + + // define a helper lambda function to check if there is brackets + auto hasBrackets = []( const std::string& descriptor ) { + const std::regex expression( "^\\(" // bracket at start of string + ".*" // any characters + "\\)" // bracket + ); + return std::regex_search( descriptor, expression ); + }; + + // set is marked to false + bool isMarked = false; + + // prune descriptor + pruneDescriptor( descriptor ); + + // if descriptor has mark with brackets then strip mark and brackets setting isMarked + // i.e. "^(B->K+ K-)" -> "B->K+ K-" and isMarked = True + if ( checkisMarked( descriptor ) ) { + // decay is marked + isMarked = true; + // strips decay descriptor from hat + outside brackets + const std::regex expression( "^\\^" // hat and opening bracket at start of string + "\\s*\\(" // any whitespaces followed by opening bracket + "(.*)" // matches what is in between i.e. striped descriptor + "\\)$" // bracket at end of string + ); + std::smatch what; + std::regex_search( descriptor, what, expression ); + descriptor = what.str( 1 ); + pruneDescriptor( descriptor ); + } + + // if no mark and contains brackets then strip brackets setting isMarked to false + // i.e. "(B->K+ K-)" -> "B->K+ K-" + if ( hasBrackets( descriptor ) ) { // tests the matched string for brackets + // strips decay from outside brackets only + const std::regex expression( "^\\(\\s*" // opening bracket at start of string + "(.*)" // matches what is in between i.e. striped descriptor + "\\s*\\)$" // bracket at end of string + ); + std::smatch what; + std::regex_search( descriptor, what, expression ); + descriptor = what.str( 1 ); + pruneDescriptor( descriptor ); + } + + return isMarked; + } + + /// get the number of arrows in the descriptor of given type + inline unsigned int numberOfArrowsOfParticularType( std::string_view descriptor, Decay::Arrow arrow ) { + // counts the number of arrow of a given type in a descriptor + unsigned int count = 0; + std::string::size_type pos = 0; + auto target = toString( arrow ); + while ( ( pos = descriptor.find( target, pos ) ) != descriptor.npos ) { + ++count; + pos += target.length(); + } + return count; + }; + + /// Check if descriptor has arrows of any type + bool hasArrow( const std::string& descriptor ) { + return std::any_of( Decay::ValidArrows.begin(), Decay::ValidArrows.end(), [&descriptor]( Decay::Arrow arrow ) { + return numberOfArrowsOfParticularType( descriptor, arrow ) != 0; + } ); + }; + + vec_str_t getDaughtersFromString( const std::string& daug_str ) { // function used for + // descriptor parsing + // separates the daughter string into the individual daughter particles returning a vector of daughters + vec_str_t vec_daug; + // regex expression that matches whitespaces conditionally, see below + boost::regex expression( + "(?(2->3 4) gives 2->3 4 + vec_str_t findStringWithinOuterMostBrackets( const std::string& daug_str ) { // function used for + // descriptor parsing + vec_str_t outer_vec_daug; + // regex expression that matches the string in the outermost brackets + // TODO: check the documentation here is okay + boost::regex expression( + "(" // "(...)" capturing group for + // "b(?:m|(?R))*e" + // matches balanced patterns or nested patterns where "b" is the beginning + // of the patterns, "e" the end and "m" what can occur in the middle + + "(?:\\^\\s*\\(|\\()" // "b" = "(?:\\^\\s*\\(|\\()" + // beginning of the pattern is either a hat "\\^" + // followed by any number of whitespaces "\\s*" and a opening bracket + // "\\(" OR: ("|"), an single opening bracket "\\(" + + "(?:[^()]+|(?R))*" // "m" = "[^()]" + // character set that matches a single character not in the set + // the negation is indicated by the "^" inside the character set + // recursion gets incremented if a character from the set in encountered + // "*" means that pattern will repeat zero or more consecutive times + + "\\)" // "e" = "\\)" + // the pattern ends with a closing bracket "\\)" + + ")" // end of the capturing group + ); + /* simpler recursion example: "a(?R)*z" that can match the string aaazzz to understand how recursion works. + First "a" gets matched, then the engine reaches "(?R)" which tells it to repeat the regex (ie. look for a again) + at the current position in the string now the second "a" is matched at recursion level = 1 then engine reaches + "(?R)" again (increments recursion) now the third "a" is matched at recursion level = 2. When the regex repeats, + the next character in the string is "z", so match for "a" fails at recursion level = 2 which causes the "(?R)" to + fail but from the "*" character, "(?R)" is made optional so engine continues to the end of the expression and + matches the first "z". Now engine has reached the end of the regex but since it is two level deep in recursion, it + hasn't found an overall match. It exits the recursion after this successful match and matches the second "z". It + is still one level deep from which it exits after another successful match and founds the third "z". The engine in + now at the end of the regex and at level zero of recursion this time so it returns aaazzz + + ref: https://www.regular-expressions.info/recurse.html + */ + boost::sregex_token_iterator iter( daug_str.begin(), daug_str.end(), expression, + 0 ); // selects the sequence in the string that is matched + // by the regex expression + boost::sregex_token_iterator end; // end-of-reg-exp marker + for ( ; iter != end; ++iter ) { + if ( detail::hasArrow( *iter ) ) outer_vec_daug.emplace_back( *iter ); // only stores decays + } + // replace the strings with empty strings so that only daughters with no decay trees are left ie simple nodes + std::string daug_str_new{ daug_str }; + for ( const auto& daug : outer_vec_daug ) { + std::string::size_type pos = daug_str_new.find( daug ); + daug_str_new.replace( pos, daug.length(), "" ); + } + detail::pruneDescriptor( daug_str_new ); + // create a new expression and iterator to separate daughters from a string of daughters + boost::regex n_expression( "(?(Jpsi => mu+ mu-) phi where "first arrow" is + // "->" the properties are (Instance of Arrow, number of arrows of first arrow type, position of first arrow, number + // of different arrow types in descriptor) + arrowprops_t getFirstArrowProps( const std::string& descriptor ) { + // instantiate a default first arrow + auto first_arrow = Decay::Arrow::Unknown; + // count number of first arrow type in descriptor + unsigned int n_first_arrow{ 0 }; + // instantiate a default position + std::size_t first_arrow_pos{ std::string::npos }; + // count the number of arrowtypes in string + unsigned int n_arrowtypes{ 0 }; + for ( const auto arrow : Decay::ValidArrows ) { // loop through all arrow types + if ( descriptor.find( toString( arrow ) ) != descriptor.npos ) { // found the arrow + if ( n_arrowtypes == 0 ) { // first iteration + // store arrow, number of its occurrences and position + first_arrow = arrow; + n_first_arrow = numberOfArrowsOfParticularType( descriptor, arrow ); + first_arrow_pos = descriptor.find( toString( arrow ) ); + } else { // second type of arrow found + if ( descriptor.find( toString( arrow ) ) < first_arrow_pos ) { // if the position is smaller than the + // previous one + // store arrow, number of its occurrences and position + first_arrow = arrow; + n_first_arrow = numberOfArrowsOfParticularType( descriptor, arrow ); + first_arrow_pos = descriptor.find( toString( arrow ) ); + } + } + n_arrowtypes++; + } + } + return arrowprops_t{ first_arrow, n_first_arrow, first_arrow_pos, n_arrowtypes }; + } + + /// split the descriptor into head node and daughters string according to the first arrow and first arrow length + tuple_parentdaughter_t getParentDaughterString( const std::string& descriptor, const std::size_t& firstArrowPos, + const std::size_t& firstArrowLength ) { + auto parent = descriptor.substr( 0, firstArrowPos ); + auto daugs = descriptor.substr( firstArrowPos + firstArrowLength ); + pruneDescriptor( parent ); + pruneDescriptor( daugs ); + return std::tuple( std::move( parent ), std::move( daugs ) ); + }; + + /// A helper function to make a tuple of class properties (used in constructor of decaytree) + classprops_t makeClassProps( std::string& descriptor ) { + // set hasCC and isMarked + auto isMarked = stripHatFromDescriptor( descriptor ); + auto hasCC = stripCCFromDescriptor( descriptor ); + + // get the properties of first type of arrow in the descriptor e.g. B->(Jpsi => mu+ mu-) (phi -> K+ K-) where + // "first arrow" is "->" the properties are (Instance of First Arrow, number of arrows of first arrow type, + // position of first arrow, number of different arrow types in descriptor) + const auto [first_arrow, n_first_arrow, first_arrow_pos, n_arrowtypes] = getFirstArrowProps( descriptor ); + bool hasOneArrow = ( n_first_arrow == 1 && n_arrowtypes == 1 ); + + // set head node + // get the properties of first type of arrow in the descriptor e.g. B->(Jpsi => mu+ mu-) phi where "first arrow" + // is + // "->" + const auto& [parent_str, daugs_str] = + getParentDaughterString( descriptor, first_arrow_pos, toString( first_arrow ).size() ); + Decay::Node headNode( parent_str ); + + // set daughters + // Get daughter string according to number of arrows + // - Allow for simple case with one arrow e.g. B -> K+ K-. Note the descriptor + // "[B->K+K-]" would fail but "(B->K+K-)" would pass. TODO: allow for both?. + // - Also allow for complex case e.g. B -> (Jpsi -> mu+ mu-) (phi(1020) -> K+ K-). + vec_str_t vec_daug = + hasOneArrow ? getDaughtersFromString( daugs_str ) : findStringWithinOuterMostBrackets( daugs_str ); + vec_dt_t daughters{ vec_daug.begin(), vec_daug.end() }; // make vector of daughters + + return { headNode, first_arrow, daughters, hasCC, isMarked }; + }; + + /// Master function to build decay tree setting member variables with descriptor (invoked in constructor) + classprops_t parseDescriptor( std::string descriptor ) { + // Check if contains balanced brackets. The brackets could be "(" or "[" or "{". + if ( !detail::hasBalancedBrackets( descriptor ) ) { + throw GaudiException{ "Descriptor does not have balanced brackets. Please check the descriptor!", + "Decay::Node::parseDescriptor(descriptor)", StatusCode::FAILURE }; + } + if ( !detail::hasArrow( descriptor ) ) { // Case1: check if no arrow in descriptor i.e. node only + Decay::Node headNode( descriptor ); // construct the head node + auto arrow_in_descriptor = Decay::Arrow::Unknown; // Arrow::Unknown + detail::vec_dt_t daughters{}; // no daughters + bool hasCC{ false }, isMarked{ false }; // properties handled at the node level + return { headNode, arrow_in_descriptor, daughters, hasCC, isMarked }; + } + // Build decay tree according how many arrows we have (calling parseDescriptor recursively) + return makeClassProps( descriptor ); + } + } // namespace detail + class DecayFinder : public extends { public: // inherit standard constructors, initalize etc. @@ -48,13 +1286,10 @@ namespace Decay { /// get parsed descriptor (for testing purposes) std::vector getParsedDescriptors( const std::vector& decay_descriptors ) const override { - std::vector parsed_descriptors; - parsed_descriptors.reserve( decay_descriptors.size() ); - std::for_each( decay_descriptors.begin(), decay_descriptors.end(), - [&parsed_descriptors]( const std::string& desc ) { - parsed_descriptors.emplace_back( Tree( desc ).descriptor() ); - } ); - return parsed_descriptors; + std::vector parsed; + parsed.reserve( decay_descriptors.size() ); + for ( const auto& desc : decay_descriptors ) parsed.emplace_back( Tree( desc ).descriptor() ); + return parsed; } /// get possibilities of decays from a "complex" d descriptor (for testing purposes) diff --git a/Phys/DaVinciKernel/src/component/DecodeSimpleDecayString.cpp b/Phys/DaVinciKernel/src/component/DecodeSimpleDecayString.cpp index 87a536a9b9bcdc09327398f86ddbcfa1313202de..51c5c975c45dfc21d333880795e8b9060df71ec6 100644 --- a/Phys/DaVinciKernel/src/component/DecodeSimpleDecayString.cpp +++ b/Phys/DaVinciKernel/src/component/DecodeSimpleDecayString.cpp @@ -11,39 +11,87 @@ // ============================================================================ // Include files // ============================================================================ -// from ANSI C++ -// #include -// #include -// #include -// #include -// ============================================================================ -// Horrible hacks to solve a Windows compilation problem -#define MSG __MSG -#include "boost/regex.hpp" // the needed file that causes all the trouble -#undef MSG -#ifdef ERROR -# undef ERROR -#endif -#undef interface -#undef pascal -#define IID InterfaceID__ -// End of horrible hacks -// ============================================================================ -// PartProp -// ============================================================================ +#include "GaudiAlg/GaudiTool.h" +#include "GaudiKernel/AlgTool.h" #include "Kernel/Decay.h" +#include "Kernel/IDecodeSimpleDecayString.h" // Interface #include "Kernel/IParticlePropertySvc.h" #include "Kernel/ParticleProperty.h" +#include "boost/regex.hpp" // ============================================================================ // Local // ============================================================================ -#include "DecodeSimpleDecayString.h" /** @file * Implementation file for class : DecodeSimpleDecayString * @date 2004-06-30 * @author Patrick KOPPENBURG */ //----------------------------------------------------------------------------- +/** @class DecodeSimpleDecayString DecodeSimpleDecayString.h + * + * + * @author Patrick KOPPENBURG + * @date 2004-06-30 + */ +class DecodeSimpleDecayString : public GaudiTool, virtual public IDecodeSimpleDecayString { + +public: + /// Standard constructor + DecodeSimpleDecayString( const std::string& type, const std::string& name, const IInterface* parent ); + + ~DecodeSimpleDecayString(); ///< Destructor + + /// Initialize method + StatusCode initialize() override; + +public: + StatusCode setDescriptor( const std::string& ) override; + std::string getDescriptor() const override { return m_descriptor; }; + StatusCode getStrings( std::string&, std::vector& ) const override; + StatusCode getStrings_cc( std::string&, std::vector& ) const override; + StatusCode getPIDs( int&, std::vector& ) const override; + StatusCode getPIDs_cc( int&, std::vector& ) const override; + bool is_cc( void ) const override; + +public: + // ========================================================================== + /** get the decay form the descriptor + * @param decay (output) the decay + * @return status code + */ + StatusCode getDecay( Decays::Decay& decay ) const override; + // ========================================================================== + /** get the charge conjugated decay form the descriptor + * @param decay (output) the decay + * @return status code + */ + StatusCode getDecay_cc( Decays::Decay& decay ) const override; + // ========================================================================== + /** get all decays form the descriptor + * @param decays (output) the vector of decays + * @return status code + */ + StatusCode getDecays( std::vector& decays ) const override; + // ========================================================================== + +private: + StatusCode reset(); + StatusCode PID( const std::string&, int& ) const; + StatusCode splitDescriptor( const std::string&, std::string&, std::vector& ) const; + StatusCode strip_cc( void ); + StatusCode buildPIDs( const std::string&, const std::vector&, int&, std::vector& ) const; + StatusCode do_cc( void ); + std::string conjugate( const std::string& ) const; + +private: + std::string m_descriptor; + std::string m_mother; + std::vector m_daughters; + std::string m_mother_cc; + std::vector m_daughters_cc; + LHCb::IParticlePropertySvc* m_ppSvc; + bool m_iscc; +}; typedef std::vector ints; typedef std::vector strings; diff --git a/Phys/DaVinciKernel/src/component/DecodeSimpleDecayString.h b/Phys/DaVinciKernel/src/component/DecodeSimpleDecayString.h deleted file mode 100644 index 48d2c052ce8dc0047b53ae8ac314ab4cf0187af6..0000000000000000000000000000000000000000 --- a/Phys/DaVinciKernel/src/component/DecodeSimpleDecayString.h +++ /dev/null @@ -1,102 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -// ============================================================================ -#ifndef DECODESIMPLEDECAYSTRING_H -#define DECODESIMPLEDECAYSTRING_H 1 -// ============================================================================ -// Include files -// ============================================================================ -// GaudiKernel -// ============================================================================ -#include "GaudiKernel/AlgTool.h" -// ============================================================================ -// GaudiAlg -// ============================================================================ -#include "GaudiAlg/GaudiTool.h" -// ============================================================================ -// DaVinciKernel -// ============================================================================ -#include "Kernel/Decay.h" -#include "Kernel/IDecodeSimpleDecayString.h" // Interface -// ============================================================================ -// forwarde declaration -// ============================================================================ -namespace LHCb { - class IParticlePropertySvc; -} -// ============================================================================ -/** @class DecodeSimpleDecayString DecodeSimpleDecayString.h - * - * - * @author Patrick KOPPENBURG - * @date 2004-06-30 - */ -class DecodeSimpleDecayString : public GaudiTool, virtual public IDecodeSimpleDecayString { - -public: - /// Standard constructor - DecodeSimpleDecayString( const std::string& type, const std::string& name, const IInterface* parent ); - - ~DecodeSimpleDecayString(); ///< Destructor - - /// Initialize method - StatusCode initialize() override; - -public: - StatusCode setDescriptor( const std::string& ) override; - std::string getDescriptor() const override { return m_descriptor; }; - StatusCode getStrings( std::string&, std::vector& ) const override; - StatusCode getStrings_cc( std::string&, std::vector& ) const override; - StatusCode getPIDs( int&, std::vector& ) const override; - StatusCode getPIDs_cc( int&, std::vector& ) const override; - bool is_cc( void ) const override; - -public: - // ========================================================================== - /** get the decay form the descriptor - * @param decay (output) the decay - * @return status code - */ - StatusCode getDecay( Decays::Decay& decay ) const override; - // ========================================================================== - /** get the charge conjugated decay form the descriptor - * @param decay (output) the decay - * @return status code - */ - StatusCode getDecay_cc( Decays::Decay& decay ) const override; - // ========================================================================== - /** get all decays form the descriptor - * @param decays (output) the vector of decays - * @return status code - */ - StatusCode getDecays( std::vector& decays ) const override; - // ========================================================================== - -private: - StatusCode reset(); - StatusCode PID( const std::string&, int& ) const; - StatusCode splitDescriptor( const std::string&, std::string&, std::vector& ) const; - StatusCode strip_cc( void ); - StatusCode buildPIDs( const std::string&, const std::vector&, int&, std::vector& ) const; - StatusCode do_cc( void ); - std::string conjugate( const std::string& ) const; - -private: - std::string m_descriptor; - std::string m_mother; - std::vector m_daughters; - std::string m_mother_cc; - std::vector m_daughters_cc; - LHCb::IParticlePropertySvc* m_ppSvc; - bool m_iscc; -}; -// ========================================================================= -#endif // DECODESIMPLEDECAYSTRING_H diff --git a/Phys/DaVinciMCKernel/dict/DaVinciMCKernelDict.h b/Phys/DaVinciMCKernel/dict/DaVinciMCKernelDict.h index 59cb7d533b3aee7ca13be39d9dd2d9c60de0810b..84437fa0d3187e28bc8af0b0ac927da355ff46f9 100644 --- a/Phys/DaVinciMCKernel/dict/DaVinciMCKernelDict.h +++ b/Phys/DaVinciMCKernel/dict/DaVinciMCKernelDict.h @@ -23,11 +23,7 @@ // DaVinciMCKernel // ============================================================================ #include "Kernel/IBackgroundCategory.h" -#include "Kernel/ICheatedLifetimeFitter.h" -#include "Kernel/IDaVinciAssociatorsWrapper.h" -#include "Kernel/IFilterMCParticles.h" #include "Kernel/IMC2Collision.h" -#include "Kernel/IMCParticleArrayFilter.h" #include "Kernel/IPV2MC.h" #include "Kernel/IParticle2MCAssociator.h" #include "Kernel/IParticle2MCWeightedAssociator.h" diff --git a/Phys/DaVinciMCKernel/dict/DaVinciMCKernelDict.xml b/Phys/DaVinciMCKernel/dict/DaVinciMCKernelDict.xml index 704a6a9f50330d63bd07cf5bd56c935bdae89da4..d826099240f1a26bebf21cb8344bfe8d61da74ee 100644 --- a/Phys/DaVinciMCKernel/dict/DaVinciMCKernelDict.xml +++ b/Phys/DaVinciMCKernel/dict/DaVinciMCKernelDict.xml @@ -13,10 +13,6 @@ - - - - diff --git a/Phys/DaVinciMCKernel/include/Kernel/ICheatedLifetimeFitter.h b/Phys/DaVinciMCKernel/include/Kernel/ICheatedLifetimeFitter.h deleted file mode 100644 index af4e6ff03dd095b2abbebe75b3848f2a95cc3235..0000000000000000000000000000000000000000 --- a/Phys/DaVinciMCKernel/include/Kernel/ICheatedLifetimeFitter.h +++ /dev/null @@ -1,51 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -#ifndef DAVINCITOOLS_ICHEATEDLIFETIMEFITTER_H -#define DAVINCITOOLS_ICHEATEDLIFETIMEFITTER_H 1 - -// Include files -#include "GaudiKernel/IAlgTool.h" - -// Forward declarations -class MCVertex; -class MCParticle; - -class Vertex; -class Particle; -class StatusCode; - -static const InterfaceID IID_ICheatedLifetimeFitter( "ICheatedLifetimeFitter", 1, 0 ); - -/** @class ICheatedLifetimeFitter - * Interface Class for cheated lifetime fit. - * - * @author Yuehong Xie - * @date 20/04/2005 - */ - -class ICheatedLifetimeFitter : virtual public IAlgTool { -public: - /// Retrieve interface ID - static const InterfaceID& interfaceID() { return IID_ICheatedLifetimeFitter; } - - virtual StatusCode fit( const Vertex&, const Particle&, double& lifetime, double& error, double& chisq ) const = 0; - - virtual StatusCode fitWithMCPV( const MCVertex&, const Particle&, double& lifetime, double& error, - double& chisq ) const = 0; - - virtual StatusCode fitWithMCPB( const Vertex&, const Particle&, const MCParticle&, double& lifetime, double& error, - double& chisq ) const = 0; - - virtual StatusCode fitWithMCVB( const Vertex&, const Particle&, const MCParticle&, double& lifetime, double& error, - double& chisq ) const = 0; -}; - -#endif // DAVINCITOOLS_ICHEATEDLIFETIMEFITTER_H diff --git a/Phys/DaVinciMCKernel/include/Kernel/IDaVinciAssociatorsWrapper.h b/Phys/DaVinciMCKernel/include/Kernel/IDaVinciAssociatorsWrapper.h deleted file mode 100644 index c3a4ffdf465017ae03d94fe8a83546238a632c48..0000000000000000000000000000000000000000 --- a/Phys/DaVinciMCKernel/include/Kernel/IDaVinciAssociatorsWrapper.h +++ /dev/null @@ -1,58 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -#ifndef IDAVINCIASSOCIATORSWRAPPER_H -#define IDAVINCIASSOCIATORSWRAPPER_H 1 - -// Include files -// from STL -#include - -// from Gaudi -#include "GaudiKernel/IAlgTool.h" - -#include "Kernel/Particle2MCLinker.h" -#include "Kernel/Particle2MCMethod.h" - -static const InterfaceID IID_IDaVinciAssociatorsWrapper( "IDaVinciAssociatorsWrapper", 1, 0 ); - -/** @class IDaVinciAssociatorsWrapper IDaVinciAssociatorsWrapper.h - * - * Wrapper around Particle2MCLinker class - * - * To use: - * - * Object2FromMC mylinker = m_myLinkerTool->linker(linkerMethod,container); - * - * where linker Method corresponds to one of the Methods declared in Kernel/Particle2MCMethod.h, - * for example Link, Composite, Chi2. Container allows you to specify a specifi location for the - * particles to be associated, It defaults to 0 if omitted: - * - * Object2FromMC mylinker = m_myLinkerTool->linker(linkerMethod); - * - * Note that you will need to declare a different instance of this tool - * for each linker which you wish to use. Declare an instance in your - * algorithm's initialize: - * - * m_myLinkerTool = tool("DaVinciAssociatorsWrapper","exampleTool",this); - * - * @author V. Gligorov (based on code by P. Koppenburg) - * @date 2008-06-26 - */ -class IDaVinciAssociatorsWrapper : virtual public IAlgTool { -public: - // Return the interface ID - static const InterfaceID& interfaceID() { return IID_IDaVinciAssociatorsWrapper; } - - virtual Object2FromMC* - linker( const Particle2MCMethod::AssociationMethod& myMethod, - const std::vector& myLocations = std::vector( 1, "" ) ) = 0; ///< returns a linker -}; -#endif // IDAVINCIASSOCIATORSWRAPPER_H diff --git a/Phys/DaVinciMCKernel/include/Kernel/IFilterMCParticles.h b/Phys/DaVinciMCKernel/include/Kernel/IFilterMCParticles.h deleted file mode 100644 index 68911f67525c69ffbec553f298bf1428afe6a4bb..0000000000000000000000000000000000000000 --- a/Phys/DaVinciMCKernel/include/Kernel/IFilterMCParticles.h +++ /dev/null @@ -1,47 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -#ifndef KERNEL_IFILTERMCPARTICLES_H -#define KERNEL_IFILTERMCPARTICLES_H 1 - -// Include files -// from STL -#include - -// from Gaudi -#include "GaudiKernel/IAlgTool.h" - -// Forward declarations -// from Event -#include "Event/MCParticle.h" - -static const InterfaceID IID_IFilterMCParticles( "IFilterMCParticles", 1, 0 ); - -/** @class IFilterMCParticles IFilterMCParticles.h Kernel/IFilterMCParticles.h - * - * Select or reject an ensemble of particles. - * - * @author Juan Palacios - * @date 2007-07-24 - */ -class IFilterMCParticles : virtual public IAlgTool { -public: - // Return the interface ID - static const InterfaceID& interfaceID() { return IID_IFilterMCParticles; } - - /// Test if filter is satisfied on ensemble of MCParticles - virtual bool isSatisfied( const LHCb::MCParticle::ConstVector& ) const = 0; - /// Test if filter is satisfied on ensemble of MCParticles - virtual bool operator()( const LHCb::MCParticle::ConstVector& ) const = 0; - -protected: -private: -}; -#endif // KERNEL_IFILTERMCPARTICLES_H diff --git a/Phys/DaVinciMCKernel/include/Kernel/IMCParticleArrayFilter.h b/Phys/DaVinciMCKernel/include/Kernel/IMCParticleArrayFilter.h deleted file mode 100644 index 230274f5ce90ef8fb4f4bb5289214423564d3fe9..0000000000000000000000000000000000000000 --- a/Phys/DaVinciMCKernel/include/Kernel/IMCParticleArrayFilter.h +++ /dev/null @@ -1,45 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -#ifndef KERNEL_IMCPARTICLEARRAYFILTER_H -#define KERNEL_IMCPARTICLEARRAYFILTER_H 1 - -// Include files -// from STL -#include - -// from Gaudi -#include "GaudiKernel/IAlgTool.h" - -// from Event -#include "Event/MCParticle.h" - -static const InterfaceID IID_IMCParticleArrayFilter( "IMCParticleArrayFilter", 1, 0 ); - -/** @class IMCParticleArrayFilter IMCParticleArrayFilter.h Kernel/IMCParticleArrayFilter.h - * - * - * @author Juan Palacios - * @date 2007-07-24 - */ -class IMCParticleArrayFilter : virtual public IAlgTool { -public: - // Return the interface ID - static const InterfaceID& interfaceID() { return IID_IMCParticleArrayFilter; } - - /// Filter and put results into new array - virtual StatusCode filter( const LHCb::MCParticle::ConstVector&, LHCb::MCParticle::ConstVector& ) const = 0; - /// Filter and remove elements that do not pass filter from array - virtual StatusCode filter( LHCb::MCParticle::ConstVector& ) const = 0; - -protected: -private: -}; -#endif // KERNEL_IMCPARTICLEARRAYFILTER_H diff --git a/Phys/DaVinciMCKernel/include/Kernel/MCParticleMakerBase.h b/Phys/DaVinciMCKernel/include/Kernel/MCParticleMakerBase.h deleted file mode 100644 index 11340332f5d9df9788bb28f42fcb63cc88e02faf..0000000000000000000000000000000000000000 --- a/Phys/DaVinciMCKernel/include/Kernel/MCParticleMakerBase.h +++ /dev/null @@ -1,187 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -// ============================================================================ -#ifndef DAVINCIMCTOOLS_MCPARTICLEMAKERBASE_H -# define DAVINCIMCTOOLS_MCPARTICLEMAKERBASE_H 1 -// ============================================================================ -// Include files -// ============================================================================ -// from STL -// ============================================================================ -# include -# include -# include -// ============================================================================ -// from Gaudi -// ============================================================================ -# include "GaudiAlg/GaudiTool.h" -# include "GaudiKernel/RndmGenerators.h" -# include -# include -# include -# include -# include -// ============================================================================ - -/** @class MCParticleMakerBase MCParticleMakerBase.h - * - * This tool fills the particle class with information from (Hep)MCParticles - * and places it in the Transient Event Store. - * - * It allows several utilities: - *
    - *
  1. Smear all the MCParticle in the list \b ParticleNames which are - * found in the desktop
  2. - *
  3. Smear the information of the first MCParticle of the Decay Channel - * specified in jobOption(e.g. B if B->pipi is chosen)
  4. - *
  5. Smear the information of the only stable products of the Decay - * Channel specified in jobOption (e.g. pipi - * if B->pipi is chosen or pi+ pi- mu+ mu- in B->Jpsi(mumu)Ks(pipi))
  6. - *
- * Different additional selection can be applied to the MCParticles: - *
    - *
  1. Ask to be reconstructed particles
  2. - *
  3. Ask to be reconstructible particles
  4. - *
  5. Use reconstructed covariance to generate the fake measurements
  6. - *
  7. Use a given parametrization of the covariance matrix - * to generate the fake measurements
  8. - *
- * Moreover some generation options are possible: \n - *
    - *
  1. smearing according a Gaussian (with sigma given by covariance matrix) - * or Double Gaussian distribution
  2. - *
  3. adding BIAS to the measurement and/or ScalingFactors to the covariance - * matrix (momentum dependent parametrization)
  4. - *
  5. generate correlated (or not) measurements
  6. - *
  7. smear MCTruth information at its origin Vertex or at PointOnTrack
  8. - *
- * - * Some of the implemented properties to play with in jobOption: \n - *
    - *
  1. Selection properties:\n - * \b ParticleNames list of the MCparticle ID to smear\n - * \b OnlyReconstructible (Default:false) to chose only reconstructible MCParticles\n - * \b OnlyReconstructed (Default:false) to chose only reconstructed MCParticles\n - * \b SmearParticle (Default:true)\n - * \b OnlyDecayProducts (Default:false) - * to chose only the MCParticle of a given Decay process\n - * \b OnlyStableDecayProducts (Default:false) - * to generate Particles only from the stable products - * of the decay channel. If true also OnlyDecayProducts must be set true - *
  2. - *
  3. Generation properties:\n - * \b UseReconstructedCovariance (Default:false) - * to use reconstrucded covariance or a parametrization of it \n - * \b IpErrorC0 (Default:0.0173*mm) - * \b IpErrorC1 (Default:0.0265*mm) sets the parametrization - * of the IP error (C0+C1/pt[GeV]) \n - * \b SlopeError (Default:0.4*mrad) \n - * \b MomError (Default:0.004) parametrize covariance matrix (MomErr*p[GeV])\n - * \b SmearATPoT (Default:false) if true smears the MCParticle info at PointOnTrack - * (minimum distance from beam line) otherwise it smears at origin vertex \n - * \b rhoVAR1VAR2 (Default=0.0) set the correlation coefficient between - * VAR1&VAR2 (VAR== x,y,z,tx,ty,p): - * typical values in reconstructed particles: xtx=-0.95 yty=-0.95 - *
  4. - *
  5. In case of Double Gaussian generation USE:\n - * \b dualGaussW (Default=0.,0.,0.,0.,0.,0.) - * to set !=0 in case of double gaussian generation: - * second gaussian fraction on (x,y,z,tx,ty,p)\n - * \b dualGaussSF (Default=1.,1.,1.,1.,1.,1.) ratios of - * sigma2/sigma1 on (x,y,z,tx,ty,p) - *
  6. - *
  7. To add momentum dependent Scaling Factors on errors (SF=1./(C0+C1*p)):\n - * \b ScaleFactorCovarianceC0 (Default=1.,1.,1.,1.,1.,1.) \n - * \b ScaleFactorCovarianceC1 (Default=0.,0.,0.,0.,0.,0.) - * Vector of scaling factors on errors (x,y,z,tx,ty,p) - *
  8. - *
  9. To add a momentum dependent BIAS to the measurement - * (BIAS=q*(C0+C1*p)) q=particle's charge \n - * \b MeasurementBiasC0 (Default=0.,0.,0.,0.,0.,0.)\n - * \b MeasurementBiasC1 (Default=0.,0.,0.,0.,0.,0.) - *
  10. - *
- * - * @author Gerhard Raven with minor contributions from G.Balbi & S.Vecchi - * @date 2002-10-08 - * - * @todo implement the smearing for photons - */ -class MCParticleMakerBase : public GaudiTool { -public: - /// Initialize - StatusCode initialize() override; - /// Finalize - StatusCode finalize() override; - -protected: - /// internal method - StatusCode fillParticle( const Gaudi::LorentzVector& mom, const Gaudi::XYZPoint& point, const LHCb::ParticleID& pid, - const Gaudi::SymMatrix7x7& cov, LHCb::Particle& particle ); - /// Generate covariance according realistic parametrization - StatusCode generateCovariance( const Gaudi::LorentzVector& momentum, Gaudi::SymMatrix7x7& ccc ); - /// get correlation matrix - inline const Gaudi::SymMatrix6x6& rho() const { return m_rho; } - /// generate a vector of correlated random numbers according cov matrix - StatusCode correlatedRandomVectorGenerator( const Gaudi::SymMatrix7x7& cov, Gaudi::Vector7& vector ); - -protected: - /// (optional) location of output relation table - const std::string& outputTable() const { return m_outputTable; } - /// set (optional) location of output relation table - void setOutputTable( const std::string& value ) { m_outputTable = value; } - -public: - /// Standard constructor - MCParticleMakerBase( const std::string& type, const std::string& name, const IInterface* parent ); - /// protected and virtual destructor - virtual ~MCParticleMakerBase(){}; ///< Destructor -public: - enum { _X = 0, _Y = 1, _Z = 2, _TX = 3, _TY = 4, _P = 5 }; - -private: - // default constructor is disabled - MCParticleMakerBase(); - // copy constructor is disabled - MCParticleMakerBase( const MCParticleMakerBase& ); - // assignement operator is disabled - MCParticleMakerBase& operator=( const MCParticleMakerBase& ); - -private: - bool m_smearParticle; ///< flag to Smear Particles - bool m_smearATPoT; ///< flag to smeat particle at PointOnTrack (minimum distance to the beam line) - double m_ipErrorC0; ///< C0 constant for IP error parametrization - double m_ipErrorC1; ///< C1 constant for IP error parametrization - double m_ipErrorZ; ///< Error on Z - double m_slopeError; ///< constant for Slope error parametrization - double m_momError; ///< constant for momentum error parametrization - // - // (optional) location of output relation table - std::string m_outputTable; ///< (optional) location of output relation table - // - Gaudi::SymMatrix6x6 m_rho; - // - std::vector m_covSFsC0, - m_covSFsC1; ///< vector for SF parametrization of Scaling Factors on errors 1./(C0+C1*p[GeV]) - std::vector m_BIASsC0, m_BIASsC1; ///< vector for BIAS parametrization q*(C0+C1*p[GeV]) - std::vector m_dualGaussSF; ///< vector of Second Gaussian relative sigma (sigma2/sigma1) FOR Double Gaussian - ///< Generation - std::vector m_dualGaussWeight; ///< vector of Second Gaussian Weights FOR Double Gaussian Generation - // - Rndm::Numbers m_ranGauss; - Rndm::Numbers m_ranFlat; -}; - -// ============================================================================ -// The END -// ============================================================================ -#endif // MCPARTICLEMAKERBASE_H -// ============================================================================ diff --git a/Phys/DaVinciMCKernel/include/Kernel/RC2HepMC.h b/Phys/DaVinciMCKernel/include/Kernel/RC2HepMC.h deleted file mode 100644 index a8fb45b47534ec0640af4161eb908c1dfe4d3986..0000000000000000000000000000000000000000 --- a/Phys/DaVinciMCKernel/include/Kernel/RC2HepMC.h +++ /dev/null @@ -1,69 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -// ============================================================================ -#ifndef LOKIPHYSMC_RC2HEPMC_H -# define LOKIPHYSMC_RC2HEPMC_H 1 -// ============================================================================ -// Include files -// ============================================================================ -// Relations -// ============================================================================ -template -class IRelation; -template -class IRelation2D; -// ============================================================================ -// Event & HepMC -// ============================================================================ -namespace HepMC { - class GenParticle; -} -namespace LHCb { - class Particle; -} -// ============================================================================ -/** @file - * - * This file is a part of LoKi project - - * "C++ ToolKit for Smart and Friendly Physics Analysis" - * - * The package has been designed with the kind help from - * Galina PAKHLOVA and Sergey BARSUK. Many bright ideas, - * contributions and advices from G.Raven, J.van Tilburg, - * A.Golutvin, P.Koppenburg have been used in the design. - * - * @author Vanya BELYAEV ibelyaev@physics.syr.edu - * @date 2006-09-26 - */ -// ============================================================================ - -namespace LHCb { - namespace Relations_ { - /// the actual type for RC --> HepMC relations - typedef IRelation RC2HepMC; - /// the actual type for RC --> HepMC relations - typedef IRelation HepMC2RC; - /// the actual type for RC <--> HepMC relations - typedef IRelation2D RC2HepMC2D; - } // namespace Relations_ - /// the actual type for HepMC --> MC relations - typedef LHCb::Relations_::HepMC2RC HepMC2RC; - /// the actual type for RC --> HepMC relations - typedef LHCb::Relations_::RC2HepMC RC2HepMC; - /// the actual type for RC <--> HepMC relations - typedef LHCb::Relations_::RC2HepMC2D RC2HepMC2D; -} // namespace LHCb - -// ============================================================================ -// The END -// ============================================================================ -#endif // KERNEL_RC2HEPMC_H -// ============================================================================ diff --git a/Phys/DaVinciMCTools/CMakeLists.txt b/Phys/DaVinciMCTools/CMakeLists.txt index 3e21c762ceb74292179b5b9d14b6a76ff06d7ed7..da49cc299c66fc1f0d783e1e9542b69af8017ecb 100644 --- a/Phys/DaVinciMCTools/CMakeLists.txt +++ b/Phys/DaVinciMCTools/CMakeLists.txt @@ -18,7 +18,6 @@ gaudi_add_module(DaVinciMCTools src/BackgroundCategory.cpp src/BackgroundCategoryViaRelations.cpp src/DaVinciSmartAssociator.cpp - src/DaVinciAssociatorsWrapper.cpp src/P2MCPFromProtoP.cpp src/Particle2BackgroundCategoryRelationsAlg.cpp src/PrintDecayTreeTool.cpp @@ -36,7 +35,6 @@ gaudi_add_module(DaVinciMCTools LHCb::RecEvent LHCb::RelationsLib Rec::DaVinciInterfacesLib - Rec::DaVinciKernelLib Rec::DaVinciMCKernelLib Rec::LoKiPhysMCLib ) diff --git a/Phys/DaVinciMCTools/src/DaVinciAssociatorsWrapper.cpp b/Phys/DaVinciMCTools/src/DaVinciAssociatorsWrapper.cpp deleted file mode 100644 index 7874ada2c72bb0f6d4a0ee2adbdfa64112013b05..0000000000000000000000000000000000000000 --- a/Phys/DaVinciMCTools/src/DaVinciAssociatorsWrapper.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -// Include files - -// from Gaudi -#include "GaudiKernel/IIncidentSvc.h" - -// local -#include "DaVinciAssociatorsWrapper.h" - -//----------------------------------------------------------------------------- -// Implementation file for class : DaVinciAssociatorsWrapper -// -// 2008-06-26 : Vladimir Gligorov (based on code by P. Koppenburg) -//----------------------------------------------------------------------------- - -// Declaration of the Tool Factory -DECLARE_COMPONENT( DaVinciAssociatorsWrapper ) - -//============================================================================= -// Standard constructor, initializes variables -//============================================================================= -DaVinciAssociatorsWrapper::DaVinciAssociatorsWrapper( const std::string& type, const std::string& name, - const IInterface* parent ) - : GaudiTool( type, name, parent ), m_linker( NULL ) { - declareInterface( this ); - declareInterface( this ); -} -//============================================================================= -// Destructor -//============================================================================= -DaVinciAssociatorsWrapper::~DaVinciAssociatorsWrapper() {} -//============================================================================= -// Make & return the linker -//============================================================================= -Object2FromMC* -DaVinciAssociatorsWrapper::linker( const Particle2MCMethod::AssociationMethod& method, - const std::vector& locations ) { - // If the linker already exists, just return a pointer to it - if ( m_linker != NULL ) { - Warning( "Linker already exists, returning it!", StatusCode::SUCCESS, 0 ) - .ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ ); - return m_linker; - } - if ( ( method <= Particle2MCMethod::No ) || ( method >= Particle2MCMethod::Max ) ) { - err() << "No linker type specified!" << endmsg; - return NULL; - } - - // Otherwise make the required linker - debug() << "Creating linker for " << Particle2MCMethod::algType[method]; - debug() << " using locations " << locations; - m_linker = new Object2FromMC( this, method, locations ); - debug() << endmsg; - - // If something went wrong... - if ( NULL == m_linker ) { - err() << "Could not create linker " << Particle2MCMethod::algType[method] << endmsg; - return NULL; - } - return m_linker; -} -//============================================================================= -// initialize -//============================================================================= -StatusCode DaVinciAssociatorsWrapper::initialize() { - StatusCode sc = GaudiTool::initialize(); - incSvc()->addListener( this, IncidentType::EndEvent, 100 ); - return sc; -} -//============================================================================= -// finalize -//============================================================================= -StatusCode DaVinciAssociatorsWrapper::finalize() { return GaudiTool::finalize(); } -//============================================================================= -// Implementation of Listener interface -//============================================================================= -void DaVinciAssociatorsWrapper::handle( const Incident& thisIncident ) { - verbose() << "An incident has occurred" << endmsg; - if ( thisIncident.type() == "EndEvent" ) { - verbose() << "Deleting linker at end of event incident" << endmsg; - if ( NULL != m_linker ) delete m_linker; - m_linker = NULL; - } - return; -} diff --git a/Phys/DaVinciMCTools/src/DaVinciAssociatorsWrapper.h b/Phys/DaVinciMCTools/src/DaVinciAssociatorsWrapper.h deleted file mode 100755 index 16d13254f2df25409b4b8a3167280e11fad98771..0000000000000000000000000000000000000000 --- a/Phys/DaVinciMCTools/src/DaVinciAssociatorsWrapper.h +++ /dev/null @@ -1,50 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -#ifndef DAVINCIASSOCIATORSWRAPPER_H -#define DAVINCIASSOCIATORSWRAPPER_H 1 - -// Include files -// from Gaudi -#include "GaudiAlg/GaudiTool.h" -#include "GaudiKernel/IIncidentListener.h" -#include "Kernel/IDaVinciAssociatorsWrapper.h" // Interface - -/** @class DaVinciAssociatorsWrapper DaVinciAssociatorsWrapper.h - * - * Wrapper around Particle2MCLinker class - * - * @author V. Gligorov (based on code by P. Koppenburg) - * @date 2008-06-26 - */ -class DaVinciAssociatorsWrapper : public GaudiTool, - virtual public IIncidentListener, - virtual public IDaVinciAssociatorsWrapper { -public: - /// Standard constructor - DaVinciAssociatorsWrapper( const std::string& type, const std::string& name, const IInterface* parent ); - - ~DaVinciAssociatorsWrapper(); ///< Destructor - - StatusCode initialize() override; - StatusCode finalize() override; - - Object2FromMC* - linker( const Particle2MCMethod::AssociationMethod& method, - const std::vector& locations = std::vector( 1, "" ) ) override; ///< returns a - ///< linker - - //------------------------------------------------------------- - void handle( const Incident& ) override; ///< clean desktop - -private: - Object2FromMC* m_linker; ///< linker -}; -#endif // DAVINCIASSOCIATORSWRAPPER_H diff --git a/Phys/DaVinciMCTools/src/DaVinciSmartAssociator.cpp b/Phys/DaVinciMCTools/src/DaVinciSmartAssociator.cpp index 10e280373f61eff64acf4aaa417e715a93bf2600..918d87c55f472377a5d831c18baca19283ceee31 100644 --- a/Phys/DaVinciMCTools/src/DaVinciSmartAssociator.cpp +++ b/Phys/DaVinciMCTools/src/DaVinciSmartAssociator.cpp @@ -12,7 +12,6 @@ #include "Event/MCParticle.h" #include "GaudiAlg/GaudiTool.h" #include "Kernel/IBackgroundCategory.h" -#include "Kernel/IDaVinciAssociatorsWrapper.h" #include "Kernel/IParticle2MCWeightedAssociator.h" #include "Kernel/MCAssociation.h" #include "Kernel/Particle2MCAssociatorBase.h" diff --git a/Phys/DaVinciMCTools/src/Particle2BackgroundCategoryRelationsAlg.cpp b/Phys/DaVinciMCTools/src/Particle2BackgroundCategoryRelationsAlg.cpp index ccad658f432d6b8fd4248accebcde00f065a81d7..774601be02de0f21ace4f201afe9a20c20aef952 100644 --- a/Phys/DaVinciMCTools/src/Particle2BackgroundCategoryRelationsAlg.cpp +++ b/Phys/DaVinciMCTools/src/Particle2BackgroundCategoryRelationsAlg.cpp @@ -8,15 +8,13 @@ * granted to it by virtue of its status as an Intergovernmental Organization * * or submit itself to any jurisdiction. * \*****************************************************************************/ - #include "Event/Particle.h" -#include "Kernel/DaVinciStringUtils.h" -#include "Kernel/IBackgroundCategory.h" - #include "GaudiAlg/GaudiAlgorithm.h" +#include "Kernel/IBackgroundCategory.h" #include "Relations/Relations.h" - #include "boost/algorithm/string.hpp" +#include +#include /** @class Particle2BackgroundCategoryRelationsAlg Particle2BackgroundCategoryRelationsAlg.h * diff --git a/Phys/DaVinciNeutralTools/CMakeLists.txt b/Phys/DaVinciNeutralTools/CMakeLists.txt index 69561b7458d00ae9c32b2c99669d844772a8f823..e434a1c2017f5d160ac8cadb6660cb7771db4be9 100644 --- a/Phys/DaVinciNeutralTools/CMakeLists.txt +++ b/Phys/DaVinciNeutralTools/CMakeLists.txt @@ -27,6 +27,5 @@ gaudi_add_module(DaVinciNeutralTools LHCb::TrackEvent Rec::SelToolsLib Rec::DaVinciInterfacesLib - Rec::DaVinciKernelLib Rec::TrackInterfacesLib ) diff --git a/Phys/DaVinciOverlapsAndClones/CMakeLists.txt b/Phys/DaVinciOverlapsAndClones/CMakeLists.txt index 392d9d69c82b9461a736ee77a5b57a701a6ae92c..0582f7c0eceb29c26c3def88980b542c5d118ff0 100644 --- a/Phys/DaVinciOverlapsAndClones/CMakeLists.txt +++ b/Phys/DaVinciOverlapsAndClones/CMakeLists.txt @@ -24,6 +24,5 @@ gaudi_add_module(DaVinciOverlapsAndClones LHCb::PhysEvent LHCb::RecEvent Rec::DaVinciInterfacesLib - Rec::DaVinciKernelLib Rec::DaVinciTypesLib ) diff --git a/Phys/DaVinciPVTools/CMakeLists.txt b/Phys/DaVinciPVTools/CMakeLists.txt index 2156d2088314f149e8de75e60cbb0c6008e8d676..23279e93e1f2be764d25b4f6a2626bcda5a75a8e 100644 --- a/Phys/DaVinciPVTools/CMakeLists.txt +++ b/Phys/DaVinciPVTools/CMakeLists.txt @@ -28,7 +28,6 @@ gaudi_add_module(DaVinciPVTools LHCb::RecEvent LHCb::RelationsLib Rec::DaVinciInterfacesLib - Rec::DaVinciKernelLib Rec::DaVinciTypesLib ) diff --git a/Phys/DaVinciTransporter/CMakeLists.txt b/Phys/DaVinciTransporter/CMakeLists.txt index 86ac7c3fa650e06173bbaa80dc2a9c7be1ba49c2..70b0cf9cef536b157ac436def8d42008d6f105b4 100644 --- a/Phys/DaVinciTransporter/CMakeLists.txt +++ b/Phys/DaVinciTransporter/CMakeLists.txt @@ -15,6 +15,7 @@ Phys/DaVinciTransporter gaudi_add_module(DaVinciTransporter SOURCES + src/TransporterFunctions.cpp src/ParticleTransporter.cpp src/ParticleTransporterWithStateProvider.cpp LINK @@ -25,6 +26,5 @@ gaudi_add_module(DaVinciTransporter LHCb::PhysEvent LHCb::TrackEvent Rec::DaVinciInterfacesLib - Rec::DaVinciKernelLib Rec::TrackInterfacesLib ) diff --git a/Phys/DaVinciTransporter/src/ParticleTransporter.h b/Phys/DaVinciTransporter/src/ParticleTransporter.h index 9579b48b9e77f14e9aee986e4224a13dea7fc762..5495eaa16d38812e041eadfdf23e53742dc237d0 100644 --- a/Phys/DaVinciTransporter/src/ParticleTransporter.h +++ b/Phys/DaVinciTransporter/src/ParticleTransporter.h @@ -18,8 +18,8 @@ #include "Kernel/IParticlePropertySvc.h" #include "Kernel/IParticleTransporter.h" #include "Kernel/ParticleProperty.h" -#include "Kernel/TransporterFunctions.h" #include "LHCbMath/MatrixManip.h" +#include "TransporterFunctions.h" #include "GaudiAlg/GaudiTool.h" diff --git a/Phys/DaVinciTransporter/src/ParticleTransporterWithStateProvider.cpp b/Phys/DaVinciTransporter/src/ParticleTransporterWithStateProvider.cpp index 34e58840b7ed100f2017919ebe6f29918e0dd0fc..62940231fe0d9122655ca2569e7cec9965d9bd8e 100644 --- a/Phys/DaVinciTransporter/src/ParticleTransporterWithStateProvider.cpp +++ b/Phys/DaVinciTransporter/src/ParticleTransporterWithStateProvider.cpp @@ -11,9 +11,9 @@ #include "Kernel/IParticle2State.h" #include "Kernel/IParticleTransporter.h" -#include "Kernel/TransporterFunctions.h" #include "TrackInterfaces/ITrackExtrapolator.h" #include "TrackInterfaces/ITrackStateProvider.h" +#include "TransporterFunctions.h" #include "Gaudi/Parsers/Factory.h" #include "GaudiAlg/GaudiTool.h" diff --git a/Phys/DaVinciKernel/src/Lib/TransporterFunctions.cpp b/Phys/DaVinciTransporter/src/TransporterFunctions.cpp similarity index 99% rename from Phys/DaVinciKernel/src/Lib/TransporterFunctions.cpp rename to Phys/DaVinciTransporter/src/TransporterFunctions.cpp index 838fd2e9b27217ba541e1d99dd5674585bec1443..c5308e18ebfda207292651d993155150b9e9a49e 100644 --- a/Phys/DaVinciKernel/src/Lib/TransporterFunctions.cpp +++ b/Phys/DaVinciTransporter/src/TransporterFunctions.cpp @@ -9,7 +9,7 @@ * or submit itself to any jurisdiction. * \*****************************************************************************/ -#include "Kernel/TransporterFunctions.h" +#include "TransporterFunctions.h" #include "Core/FloatComparison.h" #include "LHCbMath/MatrixTransforms.h" diff --git a/Phys/DaVinciKernel/include/Kernel/TransporterFunctions.h b/Phys/DaVinciTransporter/src/TransporterFunctions.h similarity index 100% rename from Phys/DaVinciKernel/include/Kernel/TransporterFunctions.h rename to Phys/DaVinciTransporter/src/TransporterFunctions.h diff --git a/Phys/FlavourTagging/CMakeLists.txt b/Phys/FlavourTagging/CMakeLists.txt index 28be089ec27fa6f031f06edc5f7c22ba1e6b81fe..ce2da871b77358db114895deaa9a0a0857892220 100644 --- a/Phys/FlavourTagging/CMakeLists.txt +++ b/Phys/FlavourTagging/CMakeLists.txt @@ -70,7 +70,6 @@ gaudi_add_module(Run2FlavourTagging LHCb::RecEvent LHCb::TrackEvent Rec::DaVinciMCKernelLib - Rec::DaVinciKernelLib Rec::TrackKernel Rec::SelKernelLib ROOT::Core diff --git a/Phys/FunctorCore/CMakeLists.txt b/Phys/FunctorCore/CMakeLists.txt index 215463b231c4799ae50a2cdf316b1f5d41b51296..2bd0f7989571e3762ddd0a5d444981f67f5c6a87 100644 --- a/Phys/FunctorCore/CMakeLists.txt +++ b/Phys/FunctorCore/CMakeLists.txt @@ -39,7 +39,6 @@ if(USE_DD4HEP) LHCb::TrackEvent LHCb::PhysEvent Rec::DaVinciInterfacesLib - Rec::DaVinciKernelLib Rec::DaVinciMCKernelLib Rec::PrKernel Rec::RelatedInfoToolsLib @@ -76,7 +75,6 @@ else() LHCb::HltEvent LHCb::TrackEvent Rec::DaVinciInterfacesLib - Rec::DaVinciKernelLib Rec::DaVinciMCKernelLib Rec::PrKernel Rec::RelatedInfoToolsLib diff --git a/Phys/JetAccessories/CMakeLists.txt b/Phys/JetAccessories/CMakeLists.txt index 9420e5d9f070d34a162e49d0a352e87784d9b88e..cbe5b760ffe811d312e336e96fbf61d4bca69254 100644 --- a/Phys/JetAccessories/CMakeLists.txt +++ b/Phys/JetAccessories/CMakeLists.txt @@ -55,7 +55,6 @@ gaudi_add_module(JetAccessories LHCb::RelationsLib LHCb::TrackEvent Rec::DaVinciInterfacesLib - Rec::DaVinciKernelLib Rec::DaVinciTypesLib Rec::LoKiPhysLib Rec::TrackInterfacesLib diff --git a/Phys/LoKiArrayFunctors/CMakeLists.txt b/Phys/LoKiArrayFunctors/CMakeLists.txt index 1fd3ed10b68ba4aa91587f763b0842ec33ec4d79..b58d6f22ad4fd9ca9f8c77e336f4223f41e28773 100644 --- a/Phys/LoKiArrayFunctors/CMakeLists.txt +++ b/Phys/LoKiArrayFunctors/CMakeLists.txt @@ -64,7 +64,6 @@ gaudi_add_module(LoKiArrayFunctors LHCb::RecEvent LoKiArrayFunctorsLib Rec::DaVinciInterfacesLib - Rec::DaVinciKernelLib Rec::DaVinciTypesLib Rec::LoKiPhysLib Rec::LoKiUtils diff --git a/Phys/ParticleCombiners/CMakeLists.txt b/Phys/ParticleCombiners/CMakeLists.txt index 51f7ed252baf70d1c143c08734be6b0186d54f87..be1184ea9f9f5f2a2bed2157e50112500f8a0ee8 100644 --- a/Phys/ParticleCombiners/CMakeLists.txt +++ b/Phys/ParticleCombiners/CMakeLists.txt @@ -22,7 +22,6 @@ gaudi_add_header_only_library(ParticleCombinersLib LHCb::RecEvent LHCb::TrackEvent Rec::DaVinciInterfacesLib - Rec::DaVinciKernelLib Rec::FunctorCoreLib Rec::PrKernel Rec::VertexFitLib @@ -30,6 +29,7 @@ gaudi_add_header_only_library(ParticleCombinersLib gaudi_add_module(ParticleCombiners SOURCES + src/GetDecay.cpp src/ParticleCombiner.cpp src/ParticleContainerMerger.cpp src/ThOrCombiner_ChargedBasics.cpp @@ -50,7 +50,6 @@ gaudi_add_module(ParticleCombiners LHCb::TrackEvent ParticleCombinersLib Rec::DaVinciInterfacesLib - Rec::DaVinciKernelLib Rec::VertexFitLib Rec::FunctorCoreLib Rec::PrKernel diff --git a/Phys/DaVinciKernel/include/Kernel/GetDecay.h b/Phys/ParticleCombiners/include/CombKernel/GetDecay.h similarity index 100% rename from Phys/DaVinciKernel/include/Kernel/GetDecay.h rename to Phys/ParticleCombiners/include/CombKernel/GetDecay.h diff --git a/Phys/ParticleCombiners/include/CombKernel/ParticleCombiner.h b/Phys/ParticleCombiners/include/CombKernel/ParticleCombiner.h index 706fa455cfb70647ff03fa28477fab483b7c5f21..658fa19b7879011287e09e248d7ed4ea98fbe394 100644 --- a/Phys/ParticleCombiners/include/CombKernel/ParticleCombiner.h +++ b/Phys/ParticleCombiners/include/CombKernel/ParticleCombiner.h @@ -17,8 +17,8 @@ #include +#include "CombKernel/GetDecay.h" #include "Event/Particle.h" -#include "Kernel/GetDecay.h" #include "Kernel/ICheckOverlap.h" #include "Kernel/IDecodeSimpleDecayString.h" #include "Kernel/IDistanceCalculator.h" diff --git a/Phys/ParticleCombiners/include/CombKernel/ThOrCombiner.h b/Phys/ParticleCombiners/include/CombKernel/ThOrCombiner.h index 8b3039297b7e108c6d562c5a9c3cc79fab80a8ca..b607f078b530a2ce87fa35e780036c6933f36e71 100644 --- a/Phys/ParticleCombiners/include/CombKernel/ThOrCombiner.h +++ b/Phys/ParticleCombiners/include/CombKernel/ThOrCombiner.h @@ -11,9 +11,9 @@ #pragma once +#include "CombKernel/GetDecay.h" #include "DetDesc/GenericConditionAccessorHolder.h" #include "Functors/with_functors.h" -#include "Kernel/GetDecay.h" #include "Kernel/IDecodeSimpleDecayString.h" #include "SelKernel/ParticleCombination.h" #include "SelKernel/Utilities.h" diff --git a/Phys/DaVinciKernel/src/Lib/GetDecay.cpp b/Phys/ParticleCombiners/src/GetDecay.cpp similarity index 92% rename from Phys/DaVinciKernel/src/Lib/GetDecay.cpp rename to Phys/ParticleCombiners/src/GetDecay.cpp index a1b4f97add291556ebc868750211d9d872e48bf7..9e512b91496134f867dad4fc7d27a9ee5d880fa8 100644 --- a/Phys/DaVinciKernel/src/Lib/GetDecay.cpp +++ b/Phys/ParticleCombiners/src/GetDecay.cpp @@ -11,13 +11,8 @@ // ============================================================================ // Include files // ============================================================================ -// GaudiKernel -// ============================================================================ +#include "CombKernel/GetDecay.h" #include "GaudiKernel/StatusCode.h" -// ============================================================================ -// DaVinci Kernel -// ============================================================================ -#include "Kernel/GetDecay.h" #include "Kernel/IDecodeSimpleDecayString.h" // ============================================================================ /* create decay object from the descriptor diff --git a/Phys/ParticleMaker/CMakeLists.txt b/Phys/ParticleMaker/CMakeLists.txt index 81069f244a424d512e9dac5503525603ad0b182d..1541fd92a8417b9c0632dfe22364efe531a7bf5d 100644 --- a/Phys/ParticleMaker/CMakeLists.txt +++ b/Phys/ParticleMaker/CMakeLists.txt @@ -39,7 +39,6 @@ gaudi_add_module(ParticleMaker LHCb::PhysEvent LHCb::RecEvent Rec::DaVinciInterfacesLib - Rec::DaVinciKernelLib Rec::DecayTreeFitterLib Rec::TrackInterfacesLib Rec::FunctorCoreLib diff --git a/Phys/ParticleMatching/CMakeLists.txt b/Phys/ParticleMatching/CMakeLists.txt index 97f703b34339ab85882e6d7729761652cb91267a..fca3752eb5298d229a2183960c266ef173666b4c 100644 --- a/Phys/ParticleMatching/CMakeLists.txt +++ b/Phys/ParticleMatching/CMakeLists.txt @@ -28,7 +28,7 @@ gaudi_add_module(ParticleMatching LHCb::PhysEvent LHCb::RecEvent LHCb::RelationsLib + Rec::DaVinciInterfacesLib Rec::TrackInterfacesLib Rec::TrackKernel - Rec::DaVinciKernelLib ) diff --git a/Phys/RelatedInfoTools/CMakeLists.txt b/Phys/RelatedInfoTools/CMakeLists.txt index 41167d5b2274186d15b34d3ff699d286be4b2519..21e63d7b96846ca29bd2530e7e0145de9f168e4f 100644 --- a/Phys/RelatedInfoTools/CMakeLists.txt +++ b/Phys/RelatedInfoTools/CMakeLists.txt @@ -35,7 +35,6 @@ gaudi_add_module(RelatedInfoTools LHCb::PhysInterfacesLib LHCb::RelationsLib Rec::DaVinciInterfacesLib - Rec::DaVinciKernelLib Rec::DaVinciTypesLib Rec::LoKiPhysLib Rec::FunctorCoreLib diff --git a/Phys/TisTosTobbing/CMakeLists.txt b/Phys/TisTosTobbing/CMakeLists.txt index afc159f838fa994b65b157fde5054b5afb5055ee..c536055723f5bdd300337a1e560f5fb6c710d193 100644 --- a/Phys/TisTosTobbing/CMakeLists.txt +++ b/Phys/TisTosTobbing/CMakeLists.txt @@ -56,6 +56,5 @@ gaudi_add_module(TisTosTobbing LHCb::RecEvent LHCb::TrackEvent Rec::DaVinciInterfacesLib - Rec::DaVinciKernelLib TisTosTobbingLib ) diff --git a/Phys/VertexFit/CMakeLists.txt b/Phys/VertexFit/CMakeLists.txt index 7acec814d00931cfd9341d4ba712c71855e29c43..ce03fa4ff3ac31a50520b094060e59d17ed20ea8 100644 --- a/Phys/VertexFit/CMakeLists.txt +++ b/Phys/VertexFit/CMakeLists.txt @@ -46,7 +46,6 @@ gaudi_add_module(VertexFit LHCb::RecEvent LHCb::TrackEvent Rec::DaVinciInterfacesLib - Rec::DaVinciKernelLib Rec::DaVinciTypesLib Rec::LoKiPhysLib Rec::TrackInterfacesLib