Commit d76d8801 authored by Rosen Matev's avatar Rosen Matev
Browse files

Merge branch 'pkoppenb-RemoveTupleTools' into 'master'

Remove I(MC)ParticleTupleTool

See merge request !961
parents b0eb84cb 4e5fbec8
Pipeline #3164411 passed with stage
in 21 seconds
......@@ -49,7 +49,6 @@
#include "Kernel/IParticleStuffer.h"
#include "Kernel/IParticleTisTos.h"
#include "Kernel/IParticleTransporter.h"
#include "Kernel/IParticleTupleTool.h"
#include "Kernel/IParticleValue.h"
#include "Kernel/IParticleVeto.h"
#include "Kernel/IPlotTool.h"
......
......@@ -36,7 +36,6 @@
<class name = "IParticleStuffer"/>
<class name = "IParticleTransporter"/>
<class name = "IParticleTisTos"/>
<class name = "IParticleTupleTool"/>
<class name = "IParticleValue"/>
<class name = "IPlotTool"/>
<class name = "IProtoParticleFilter"/>
......
/*****************************************************************************\
* (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. *
\*****************************************************************************/
#pragma once
#include "GaudiKernel/IAlgTool.h"
#include <string>
struct IGeometryInfo;
namespace Tuples {
class Tuple;
}
namespace LHCb {
class Particle;
}
/**
* Fill some particle related variables into a tuple.
*
* \sa IEventTupleTool
*
* @author Jeremie Borel
* @date November 2007
*/
struct GAUDI_API IParticleTupleTool : extend_interfaces<IAlgTool> {
DeclareInterfaceID( IParticleTupleTool, 3, 0 );
//! Fill the tuple.
//! - \b top : may be used to provide additional information about \b part, like the top particle of the decay.
//! - \b part : the particle about which some info are filled.
//! - \b head : prefix for the tuple column name.
//! - \b tuple: the tuple to fill
virtual StatusCode fill( LHCb::Particle const* top, LHCb::Particle const* part, std::string const& head,
Tuples::Tuple& tuple, IGeometryInfo const& geometry ) = 0;
};
......@@ -28,7 +28,6 @@
#include "Kernel/IFilterMCParticles.h"
#include "Kernel/IMC2Collision.h"
#include "Kernel/IMCParticleArrayFilter.h"
#include "Kernel/IMCParticleTupleTool.h"
#include "Kernel/IPV2MC.h"
#include "Kernel/IParticle2MCAssociator.h"
#include "Kernel/IParticle2MCWeightedAssociator.h"
......
......@@ -17,7 +17,6 @@
<class name = "IDaVinciAssociatorsWrapper"/>
<class name = "IFilterMCParticles"/>
<class name = "IMCParticleArrayFilter"/>
<class name = "IMCParticleTupleTool"/>
<class name = "IMC2Collision"/>
<class name = "IParticle2MCAssociator"/>
<class name = "IParticle2MCWeightedAssociator"/>
......
/*****************************************************************************\
* (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 DECAYTUPLE_IMCPARTICLETUPLETOOL_H
#define DECAYTUPLE_IMCPARTICLETUPLETOOL_H 1
// ============================================================================
// Include files
// from STL
#include <string>
// from Gaudi
#include "GaudiKernel/IAlgTool.h"
static const InterfaceID IID_IMCParticleTupleTool( "IMCParticleTupleTool", 1, 0 );
namespace Tuples {
class Tuple;
}
namespace LHCb {
class MCParticle;
}
/** @class IMCParticleTupleTool
*
* Fill some mc-particle related variables into a tuple.
*
* \sa IEventTupleTool
* \sa IParticleTupleTool
*
* @author patrick.koppenburg@cern.ch
* @date 19 January 2009
*/
class IMCParticleTupleTool : virtual public IAlgTool {
public:
virtual ~IMCParticleTupleTool(){};
// Return the interface ID
static const InterfaceID& interfaceID() { return IID_IMCParticleTupleTool; }
//! Fill the tuple.
//! - \b top : may be used to provide additional information about \b part, like the top particle of the decay.
//! - \b part : the particle about which some info are filled.
//! - \b head : prefix for the tuple column name.
//! - \b tuple: the tuple to fill
virtual StatusCode fill( const LHCb::MCParticle* top, const LHCb::MCParticle* part, const std::string& head,
Tuples::Tuple& tuple ) = 0;
};
#endif // DECAYTUPLE_IMCPARTICLETUPLETOOL_H
......@@ -40,11 +40,9 @@ gaudi_add_library(LoKiArrayFunctorsLib
gaudi_add_module(LoKiArrayFunctors
SOURCES
src/Components/ArrayTupleTool.cpp
src/Components/CheckOverlap.cpp
src/Components/DTFDict.cpp
src/Components/Dict2tuple.cpp
src/Components/DictOfFunctors.cpp
src/Components/DictOfFunctors.cpp
src/Components/DictValue.cpp
src/Components/DummyTransform.cpp
src/Components/HybridFilterCriterion.cpp
......@@ -56,7 +54,6 @@ gaudi_add_module(LoKiArrayFunctors
src/Components/PrintDecay.cpp
src/Components/PrintTool.cpp
src/Components/TestValue.cpp
src/Components/TupleTool.cpp
LINK
AIDA::aida
Boost::headers
......
/*****************************************************************************\
* (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 "TupleTool.h"
#include "LoKi/Operators.h"
#include "LoKi/Particles11.h"
#include "LoKi/Particles8.h"
#include "LoKi/Particles9.h"
#include <algorithm>
#include <utility>
namespace LoKi {
namespace Hybrid {
/** @class ArrayTupleTool
* "Specific" tuple tool to fill infomation about "other" particles
*
* @code
* xxx.Source = "SOURCE('Phys/StdLoosePions/Particles', PT>1*GeV )"
* xxx. Variables = { "var1" : "PT" , "var2" : "ETA" }
* xxx.AVariables = { "doca" : "ADOCA(1,2)" , "docachi2" : "ACHI2DOCA(1,2)"}
* @endcode
* - "Other" particles are required to be different from the signal particle
* and its top-particle: there is requirement of no common paricles,
* protoparticles and tracks
* - For "A"-variables, temporary array of two elemements:
* (signal particle and one "other" particle from the list)
* is constructed and each "A"-functor is applied to this array.
*
* @see Tuples::TupleObj
* @see LoKi::ATypes::Combination
* @see LoKi::ATypes::AFun
*
* @author Vanya BELYAEV Ivan.Belyaev@itep.ru
* @date 2016-03-19
*/
class ArrayTupleTool : public LoKi::Hybrid::TupleTool {
public:
/** helper class to keep the N-tuple items
* it is needed due to absence of the default constructor for
* the class LoKi::PhysTypes::Fun
* @author Vanya BELYAEV Ivan.Belyaev@itep.ru
* @date 2016-06-05
*/
struct AItem {
/// the default constructor
AItem( const LHCb::Particle* p = nullptr )
: m_name(), m_particle( p ), m_fun( LoKi::BasicFunctors<LoKi::ATypes::Combination>::Constant( -1.e+10 ) ) {}
double operator()( const LHCb::Particle* p ) const {
const LHCb::Particle::ConstVector vct{{m_particle, p}};
return m_fun.fun( LoKi::ATypes::Combination( vct ) );
}
/// the variable name
std::string m_name; // the variable name
/// the particle
const LHCb::Particle* m_particle; /// the paticle
/// the functor
LoKi::ATypes::AFun m_fun; /// the functor
};
/** Fill the tuple.
* @see IParticleTupelTool
* @param top the top particle of the decay.
* @param particle the particle about which some info are filled.
* @param head prefix for the tuple column name.
* @param tuple the tuple to fill
* @return status code
*/
StatusCode fill( LHCb::Particle const* top, LHCb::Particle const* particle, std::string const& head,
Tuples::Tuple& tuple, IGeometryInfo const& geometry ) override;
protected:
/// initialization of the tool
StatusCode initVariables() override {
// get varibales
StatusCode sc = LoKi::Hybrid::TupleTool::initVariables();
if ( sc.isFailure() ) { return Error( "Can't decode varibales", sc ); }
// get the factory
IHybridFactory* the_factory = tool<IHybridFactory>( factory(), this );
sc = the_factory->get( m_source_code, m_source, preambulo() );
if ( sc.isFailure() ) { return Error( "Unable to decode ``source'' code:" + m_source_code, sc ); }
debug() << "The decoded ``source code'' is " << m_source << endmsg;
m_aitems.clear();
m_aitems.reserve( m_avars.size() );
for ( Map::const_iterator ivar = m_avars.begin(); m_avars.end() != ivar; ++ivar ) {
AItem item;
StatusCode sc = the_factory->get( ivar->second, item.m_fun, preambulo() );
if ( sc.isFailure() ) { return Error( "Unable to decode " + ivar->first + " : " + ivar->second, sc ); }
item.m_name = ivar->first;
m_aitems.push_back( std::make_pair( ivar->first, item ) );
debug() << "The decoded 'A'-variable name is '" << m_aitems.back().first << "'\t, the functor : '"
<< m_aitems.back().second.m_fun << "'" << endmsg;
}
release( the_factory ).ignore(); // we do not need the factory anymore
return StatusCode::SUCCESS;
}
public:
/// the update handler
void propHandler( Gaudi::Details::PropertyBase& p ) { return LoKi::Hybrid::TupleTool::propHandler( p ); }
ArrayTupleTool( const std::string& type, const std::string& name, const IInterface* parent );
private:
/// the source of ``other'' particles (code)
std::string m_source_code; //
/// the source itself
LoKi::Types::Source m_source; // { "name":"functor"} map
/// "A"-variables
Map m_avars;
/// the actual type of containter of items
typedef std::vector<std::pair<std::string, AItem>> AItems;
/// "A"-items
AItems m_aitems;
mutable Gaudi::Accumulators::StatCounter<> m_nFiltered1{this, "#filtered1"};
mutable Gaudi::Accumulators::StatCounter<> m_nFiltered2{this, "#filtered2"};
};
} // namespace Hybrid
} // end of namespace LoKi
namespace {
/// empty source
class EmptySource : public LoKi::Types::Sources {
EmptySource* clone() const override { return new EmptySource( *this ); }
result_type operator()() const override {
Error( "Empty source is invoked" ).ignore();
return LHCb::Particle::ConstVector();
}
};
} // namespace
LoKi::Hybrid::ArrayTupleTool::ArrayTupleTool( const std::string& type, const std::string& name,
const IInterface* parent )
: LoKi::Hybrid::TupleTool( type, name, parent ), m_source_code(), m_source( EmptySource() ) {
declareProperty( "Source", m_source_code, "The source of ``other'' particles" )
->declareUpdateHandler( &LoKi::Hybrid::ArrayTupleTool::propHandler, this );
declareProperty( "AVariables", m_avars, "The {'name':'functor'}-map of A-columns for N-tuple " )
->declareUpdateHandler( &LoKi::Hybrid::ArrayTupleTool::propHandler, this );
}
/* Fill the tuple.
* @see IParticleTupleTool
* @param top the top particle of the decay.
* @param particle the particle about which some info are filled.
* @param head prefix for the tuple column name.
* @param tuple the tuple to fill
* @return status code
*/
StatusCode LoKi::Hybrid::ArrayTupleTool::fill( const LHCb::Particle* top, const LHCb::Particle* particle,
const std::string& head, Tuples::Tuple& tuple, IGeometryInfo const& ) {
if ( 0 == top ) { Warning( "LHCb::Particle* 'Top' points to NULL" ).ignore(); }
if ( 0 == particle ) { Warning( "LHCb::Particle* points to NULL" ).ignore(); }
if ( !tuple.valid() ) { return Error( "Invalid tuple " ); }
std::string head_ = head + "_";
// get ``other'' particles
LHCb::Particle::ConstVector input1 = m_source();
LHCb::Particle::ConstVector input2;
input2.reserve( input1.size() );
LoKi::Types::Cut cuts = LoKi::Particles::IsAParticleInTree( particle ) ||
LoKi::Particles::HasProtosInTree( particle ) || LoKi::Particles::HasTracksInTree( particle );
if ( top ) {
cuts = cuts || LoKi::Particles::HasTracksInTree( top ) || LoKi::Particles::IsAParticleInTree( top ) ||
LoKi::Particles::HasProtosInTree( top );
}
cuts = !cuts;
std::copy_if( input1.begin(), input1.end(), std::back_inserter( input2 ), std::cref( cuts ) );
m_nFiltered1 += input1.size();
m_nFiltered2 += input2.size();
tuple->farray( items(), input2.begin(), input2.end(), head_ + "len", 1000 ).ignore();
/// activate 'A'-variables
for ( AItems::iterator item = m_aitems.begin(); m_aitems.end() != item; ++item ) {
item->second.m_particle = particle;
}
tuple->farray( m_aitems, input2.begin(), input2.end(), head_ + "len", 1000 ).ignore();
return StatusCode::SUCCESS;
}
DECLARE_COMPONENT( LoKi::Hybrid::ArrayTupleTool )
/*****************************************************************************\
* (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 "Kernel/IParticleDictTool.h"
#include "Kernel/IParticleTupleTool.h" // Interface
#include "LoKi/IHybridFactory.h"
#include "LoKi/PhysTypes.h"
#include "GaudiAlg/GaudiTool.h"
#include "GaudiAlg/Tuple.h"
#include "GaudiAlg/TupleObj.h"
#include "GaudiAlg/Tuples.h"
#include "GaudiKernel/VectorMap.h"
namespace LoKi {
namespace Hybrid {
/**
* Writing a Dictionary into the ntuple
*
* @author Sebastian Neubert
* @date 2013-07-11
*/
class Dict2Tuple : public GaudiTool, virtual public IParticleTupleTool {
public:
/// Standard constructor
Dict2Tuple( const std::string& type, const std::string& name, const IInterface* parent )
: GaudiTool( type, name, parent ), m_sourcename(), m_numvar( 1 ), m_source( 0 ) {
declareInterface<IParticleTupleTool>( this );
///
declareProperty( "Source", m_sourcename, "Type/Name for Source Dictionary Tool" );
declareProperty( "NumVar", m_numvar, "Number of variables expected to be filled into dictionary" );
}
/** Fill the tuple.
* @see IParticleTupelTool
* @param top the top particle of the decay.
* @param particle the particle about which some info are filled.
* @param head prefix for the tuple column name.
* @param tuple the tuple to fill
* @return status code
*/
StatusCode fill( LHCb::Particle const* top, LHCb::Particle const* particle, std::string const& head,
Tuples::Tuple& tuple, IGeometryInfo const& geometry ) override;
/// initialization of the tool
StatusCode initialize() override {
StatusCode sc = GaudiTool::initialize();
if ( sc.isFailure() ) { return sc; } // RETURN
// get the dicttool
m_source = tool<IParticleDictTool>( m_sourcename, this );
if ( m_source == NULL ) { return Error( "Unable to find the source DictTool " + m_sourcename, sc ); }
//
// reserve memory for dictionary
m_dict.reserve( m_numvar );
return StatusCode::SUCCESS;
}
private:
std::string m_sourcename;
unsigned int m_numvar; // number of variables expected to be filled into dictionary
IParticleDictTool* m_source;
IParticleDictTool::DICT m_dict;
};
} // namespace Hybrid
} // namespace LoKi
/* Fill the tuple.
* @see IParticleTupleTool
* @param top the top particle of the decay.
* @param particle the particle about which some info are filled.
* @param head prefix for the tuple column name.
* @param tuple the tuple to fill
* @return status code
*/
StatusCode LoKi::Hybrid::Dict2Tuple::fill( LHCb::Particle const* top, LHCb::Particle const* particle,
std::string const& head, Tuples::Tuple& tuple,
IGeometryInfo const& geometry ) {
if ( 0 == top ) { Warning( "LHCb::Particle* 'Top' points to NULL" ).ignore(); }
if ( 0 == particle ) { Warning( "LHCb::Particle* points to NULL" ).ignore(); }
//
if ( !tuple.valid() ) { return Error( "Invalid tuple " ); }
// make sure we start with a clean dictionary
m_dict.clear();
// call IParticleDictTool to aquire the dictionary
/// request the dictionary of variables from the source
m_source->fill( particle, m_dict, geometry ).ignore();
// prepend the head of the current branch to the variable to make sure
// columns are uniquely named
std::string head_ = head + "_";
// Put the items in the dictionary into the tuple
for ( IParticleDictTool::DICT::const_iterator item = m_dict.begin(); m_dict.end() != item; ++item ) {
// fill N-tuple
tuple->column( head_ + item->first, item->second ).ignore();
}
//
return StatusCode::SUCCESS;
}
/// Declaration of the Tool Factory
DECLARE_COMPONENT( LoKi::Hybrid::Dict2Tuple )
......@@ -12,7 +12,6 @@
#include "Preambulo.h"
#include "Kernel/IParticleDictTool.h" // Interface
#include "Kernel/IParticleTupleTool.h"
#include "LoKi/IHybridFactory.h"
#include "LoKi/PhysTypes.h"
......
/*****************************************************************************\
* (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 "TupleTool.h"
// initialization of the tool
LoKi::Hybrid::TupleTool::TupleTool( const std::string& type, const std::string& name, const IInterface* parent )
: GaudiTool( type, name, parent )
, m_factory( "LoKi::Hybrid::Tool/HybridFactory:PUBLIC" )
, m_vars()
, m_items()
, m_preambulo() {
declareInterface<IParticleTupleTool>( this );
if ( 0 == name.find( "Hlt1" ) ) {
m_factory = "LoKi::Hybrid::Tool/Hlt1HybridFactory:PUBLIC";
} else if ( 0 == name.find( "Hlt2" ) ) {
m_factory = "LoKi::Hybrid::Tool/Hlt2HybridFactory:PUBLIC";
}
declareProperty( "Factory", m_factory, "Type/Name for C++/Python Hybrid Factory" )
->declareUpdateHandler( &LoKi::Hybrid::TupleTool::propHandler, this );
declareProperty( "Variables", m_vars, "The {'name':'functor'}-map of columns for N-tuple " )
->declareUpdateHandler( &LoKi::Hybrid::TupleTool::propHandler, this );
// the preambulo
declareProperty( "Preambulo", m_preambulo, "The preambulo to be used for Bender/Python script" )
->declareUpdateHandler( &LoKi::Hybrid::TupleTool::propHandler, this );
}
// initialization of the tool
StatusCode LoKi::Hybrid::TupleTool::initialize() {
StatusCode sc = GaudiTool::initialize();
if ( sc.isFailure() ) { return sc; } // RETURN
svc<IService>( "LoKiSvc", true );
return initVariables();
}
// finalization of the tool
StatusCode LoKi::Hybrid::TupleTool::finalize() {
// reset all functors:
m_items.clear();
// finalize the base
return GaudiTool::finalize();
}
// the update handler
void LoKi::Hybrid::TupleTool::propHandler( Gaudi::Details::PropertyBase& /* p */ ) {
if ( Gaudi::StateMachine::INITIALIZED > FSMState() ) { return; }
Warning( "Reintialization of Variables/Factory/Preambulo/..." ).ignore();
StatusCode sc = initVariables();
Assert( sc.isSuccess(), "Unable to set 'Variables'", sc );
}
// initializr variables
StatusCode LoKi::Hybrid::TupleTool::initVariables() {
// get the factory
IHybridFactory* the_factory = tool<IHybridFactory>( factory(), this );
m_items.clear();
m_items.reserve( m_vars.size() );
for ( Map::const_iterator ivar = m_vars.begin(); m_vars.end() != ivar; ++ivar ) {
Item item;
StatusCode sc = the_factory->get( ivar->second, item.m_fun, preambulo() );
if ( sc.isFailure() ) { return Error( "Unable to decode " + ivar->first + " : " + ivar->second, sc ); }
item.m_name = ivar->first;
m_items.emplace_back( ivar->first, item );
debug() << "The decoded variable name is '" << m_items.back().first << "'\t, the functor : '"
<< m_items.back().second.m_fun << "'" << endmsg;
}
if ( m_items.empty() ) { Warning( "No variables/items are defined" ).ignore(); }
release( the_factory ).ignore(); // we do not need the factory anymore
return StatusCode::SUCCESS;
}
/* Fill the tuple.
* @see IParticleTupleTool
* @param top the top particle of the decay.
* @param particle the particle about which some info are filled.
* @param head prefix for the tuple column name.
* @param tuple the tuple to fill
* @return status code
*/
StatusCode LoKi::Hybrid::TupleTool::fill( LHCb::Particle const* top, LHCb::Particle const* particle,
std::string const& head, Tuples::Tuple& tuple, IGeometryInfo const& ) {
if ( !top ) { Warning( "LHCb::Particle* 'Top' points to NULL" ).ignore(); }
if ( !particle ) { Warning( "LHCb::Particle* points to NULL" ).ignore(); }
if ( !tuple.valid() ) { return Error( "Invalid tuple " ); }
std::string head_ = head + "_";
for ( const auto& item : items() ) {
// fill N-tuple
tuple->column( head_ + item.first, item.second( particle ) ).ignore();
}