Commit 03f0909d authored by Rosen Matev's avatar Rosen Matev
Browse files

Merge branch 'cmarinbe_cleanup_ParticleMakers' into 'master'

Clean up old particle makers

See merge request !823
parents d5b56da6 0d663da5
Pipeline #3265342 passed with stage
in 23 seconds
......@@ -15,24 +15,13 @@ Phys/ParticleMaker
gaudi_add_module(ParticleMaker
SOURCES
src/BestPIDParticleMaker.cpp
src/ChargedParticleMakerBase.cpp
src/CombinedParticleMaker.cpp
src/DiElectronMaker.cpp
src/FunctionalDiElectronMaker.cpp
src/FunctionalParticleMaker.cpp
src/MergedPi0Maker.cpp
src/NeutralMakers.cpp
src/NoPIDsParticleMaker.cpp
src/Particle2State.cpp
src/ParticleMakerBase.cpp
src/ParticleMakerForParticleFlow.cpp
src/ParticleMassMonitor.cpp
src/ParticleWithBremMaker.cpp
src/PhotonMaker.cpp
src/PhotonMakerAlg.cpp
src/Pi0MakerBase.cpp
src/ResolvedPi0Maker.cpp
src/V0FromDstMaker.cpp
LINK
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 files
// local
#include "BestPIDParticleMaker.h"
using namespace Gaudi::Units;
using namespace LHCb;
using namespace std;
//-----------------------------------------------------------------------------
/** @class BestPIDParticleMaker BestPIDParticleMaker.h
*
* @Version 1r0
* @author Neal Gueissaz
* @date 22 june 2009
*/
//-----------------------------------------------------------------------------
// Declaration of the Algorithm Factory
DECLARE_COMPONENT( BestPIDParticleMaker )
//=============================================================================
// Standard constructor, initializes variables
//=============================================================================
BestPIDParticleMaker::BestPIDParticleMaker( const std::string& name, ISvcLocator* pSvcLocator )
: CombinedParticleMaker( name, pSvcLocator ) {
// Particle types to create
m_ParticleList.push_back( "muon" );
m_ParticleList.push_back( "electron" );
m_ParticleList.push_back( "kaon" );
m_ParticleList.push_back( "proton" );
m_ParticleList.push_back( "pion" );
declareProperty( "Particles", m_ParticleList, "Possible Particles to create : muon, electron, kaon, proton, pion" );
}
//=============================================================================
// Destructor
//=============================================================================
BestPIDParticleMaker::~BestPIDParticleMaker() {}
//=============================================================================
// Initialization
//=============================================================================
StatusCode BestPIDParticleMaker::initialize() {
// intialize base class
const StatusCode sc = CombinedParticleMaker::initialize();
if ( sc.isFailure() )
return Error( "Failed to initialize base class : make sure you have set the dummy Particle job option to 'pion'" );
if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Initialize the BestPIDParticleMaker algorithm" << endmsg;
if ( m_ParticleList.empty() ) return Error( "A list of particles types must be specified" );
if ( msgLevel( MSG::DEBUG ) ) debug() << "Will produce : " << m_ParticleList << endmsg;
// loop over selection and load ProtoParticle selectors
m_protoMap.clear();
for ( std::vector<std::string>::const_iterator ip = m_ParticleList.begin(); ip != m_ParticleList.end(); ++ip ) {
// Get particle type name
const string name = *ip; // convertName( *ip );
// get pp name and tooltype
std::string ppName, toolType;
if ( "muon" == name ) {
ppName = "mu+";
toolType = m_muProtoFilter;
} else if ( "electron" == name ) {
ppName = "e+";
toolType = m_elProtoFilter;
} else if ( "kaon" == name ) {
ppName = "K+";
toolType = m_kaProtoFilter;
} else if ( "proton" == name ) {
ppName = "p+";
toolType = m_prProtoFilter;
} else if ( "pion" == name ) {
ppName = "pi+";
toolType = m_piProtoFilter;
} else {
return Error( "Unknown particle selection '" + *ip + "'" );
}
// Get particle properties
const LHCb::ParticleProperty* partProp = ppSvc()->find( ppName );
// load tool into map
if ( msgLevel( MSG::DEBUG ) )
debug() << "Particle type " << name << " using ProtoParticle Filter '" << toolType << "'" << endmsg;
const IProtoParticleFilter* t = tool<IProtoParticleFilter>( toolType, name, this );
m_protoMap.push_back( ProtoPair( partProp, t ) );
}
return StatusCode::SUCCESS;
}
//=============================================================================
// Main execution
//=============================================================================
StatusCode BestPIDParticleMaker::makeParticles( Particle::Vector& parts ) {
// Load the ProtoParticles
const LHCb::ProtoParticle::ConstVector& pps = protos();
if ( msgLevel( MSG::DEBUG ) )
debug() << "Making Particles from " << pps.size() << " ProtoParticles at " << m_input << endmsg;
// loop over ProtoParticles
for ( LHCb::ProtoParticle::ConstVector::const_iterator ipp = pps.begin(); pps.end() != ipp; ++ipp ) {
const ProtoParticle* pp = *ipp;
// get pointer to track (should always exist for charged tracks)
const Track* track = ( *ipp )->track();
if ( !track ) return Error( "Charged ProtoParticle has null track reference !" );
if ( track->states().empty() ) {
Warning( "Track has empty states. This is likely to be bug https://its.cern.ch/jira/browse/LHCBPS-391" ).ignore();
continue;
}
TrackTally& tally = trackTally( track->type() );
++tally.totProtos;
// Select tracks
if ( msgLevel( MSG::VERBOSE ) ) verbose() << "Trying Track " << track->key() << endmsg;
if ( !trSel()->accept( *track ) ) continue;
if ( msgLevel( MSG::VERBOSE ) ) {
verbose() << " -> Track selected " << track->key() << " " << track->firstState().momentum() << endmsg;
}
++tally.selProtos;
// Do PID checks ?
if ( m_testPIDinfo ) checkPIDInfo( *ipp );
// Create a vector of PID and DLL pairs
DLLPIDVector dllpid;
dllpid.push_back( DLLPIDPair( "mu+", pp->info( ProtoParticle::additionalInfo::CombDLLmu, 0 ) ) );
dllpid.push_back( DLLPIDPair( "e+", pp->info( ProtoParticle::additionalInfo::CombDLLe, 0 ) ) );
dllpid.push_back( DLLPIDPair( "K+", pp->info( ProtoParticle::additionalInfo::CombDLLk, 0 ) ) );
dllpid.push_back( DLLPIDPair( "p+", pp->info( ProtoParticle::additionalInfo::CombDLLp, 0 ) ) );
dllpid.push_back( DLLPIDPair( "pi+", pp->info( ProtoParticle::additionalInfo::CombDLLpi, 0 ) ) );
// Sort the DLL
sort( dllpid.begin(), dllpid.end(), DLLPIDPair::cmp );
if ( msgLevel( MSG::VERBOSE ) ) {
verbose() << "ProtoParticle DLL ";
for ( DLLPIDVector::iterator j = dllpid.begin(); j != dllpid.end(); j++ ) {
verbose() << ( *j ).GetPid() << " : " << ( *j ).GetDll() << " ";
}
verbose() << endmsg;
}
DLLPIDVector::iterator i = dllpid.begin();
string pid;
ProtoMap::const_iterator imap;
while ( i != dllpid.end() ) {
pid = ( *i ).GetPid();
// Continue if filters are not satisfied
bool sel = false;
for ( imap = m_protoMap.begin(); imap != m_protoMap.end(); ++imap ) {
if ( ( *imap ).first->particle() == pid ) {
sel = ( *imap ).second->isSatisfied( *ipp );
break;
}
}
if ( msgLevel( MSG::VERBOSE ) ) verbose() << " -> Particle type " << pid << " selected=" << sel << endmsg;
if ( !sel ) {
i++;
continue;
}
// get out of here
break;
}
if ( i == dllpid.end() ) continue;
// make a new Particle
Particle* part = new Particle();
// fill Parameters
StatusCode sc = fillParticle( *ipp, ( *imap ).first, part );
if ( sc.isFailure() ) {
Warning( "Failed to fill Particle -> rejected" ).ignore();
delete part;
} else {
// add to container
parts.push_back( part );
// increment tally
tally.addToType( pid );
// fill the map
// m_map.insert( track, part );
}
} // end loop over protoparticles
if ( msgLevel( MSG::DEBUG ) ) debug() << parts.size() << " Particles have been made !" << endmsg;
return StatusCode::SUCCESS;
}
//===========================================================================
// Finalize
//===========================================================================
StatusCode BestPIDParticleMaker::finalize() {
if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Finalize the BestPIDParticleMaker algorithm" << endmsg;
// finalize base class
return CombinedParticleMaker::finalize();
}
/*****************************************************************************\
* (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 BESTPIDPARTICLEMAKER_H
#define BESTPIDPARTICLEMAKER_H 1
#include "CombinedParticleMaker.h"
/** @class BestPIDParticleMaker BestPIDParticleMaker.h
* It is based on CombinedParticleMaker
*
* BestPIDParticleMaker makes Particles from ProtoParticles.
* For each ProtoParticle a Particle with the best DLL that passes the
* ProtoParticle*Filter.
* It uses all detector information available for a given hypothesis.
* Possible Particles to create are muon, electron, kaon, proton, pion.
* They can be specifed in the Particle option.
*
* Avoid using this algorithm if you are a b-physicist :
*
* If you do B->pipi and one pi decays to a muon, it will never be a pi
* candidate. Even worse, if you or someone relaxes the mu ID cuts
* between two jobs or two DaVinci versions, then suddenly what used to be a
* nice pion in one version of DV might now becomes a muon candidate. Your
* efficiency decreases although nothing affecting pion or kaon ID
* changed.
* That makes it very hard to estimate signal efficiencies as all
* efficiencies depend on everything.
* If you want to cut hard on PID, use PID cuts. If you don't want to use
* the same track several times (which is a valid point for tagging),
* then use the Overlap Tool and re-weight the track accordingly if needed.
*
*
* @Version 1r0
* @author Neal Gueissaz
* @date 22 june 2009
*/
class BestPIDParticleMaker : public CombinedParticleMaker {
public:
/// Standard constructor
BestPIDParticleMaker( const std::string& name, ISvcLocator* pSvcLocator );
virtual ~BestPIDParticleMaker(); ///< Destructor
// Standard initialization of algorithm
StatusCode initialize() override;
// Make the particles
StatusCode makeParticles( LHCb::Particle::Vector& parts ) override;
// Standard finalization of algorithm
StatusCode finalize() override;
protected:
private:
/** @brief Job Option List of particles type to make.
* Possible values are muons, electrons, kaons, protons, pions
*/
std::vector<std::string> m_ParticleList;
// Map type that takes a particle type to a ProtoParticle filter
typedef std::pair<const LHCb::ParticleProperty*, const IProtoParticleFilter*> ProtoPair;
typedef std::vector<ProtoPair> ProtoMap;
ProtoMap m_protoMap;
class DLLPIDPair {
private:
std::string pid;
double dll;
DLLPIDPair(){};
public:
DLLPIDPair( std::string name, double val ) : pid( name ), dll( val ){};
~DLLPIDPair(){};
std::string GetPid() const { return pid; }
double GetDll() const { return dll; }
static bool cmp( const DLLPIDPair& one, const DLLPIDPair& two ) { return one.GetDll() > two.GetDll(); }
};
// DLL, PID pairs
typedef std::vector<DLLPIDPair> DLLPIDVector;
};
#endif // BESTPIDPARTICLEMAKER_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 files
// from EventSys
#include "Event/Particle.h"
#include "Event/Vertex.h"
// local
#include "ChargedParticleMakerBase.h"
//-----------------------------------------------------------------------------
// Implementation file for class : ChargedParticleMakerBase
//
// 2009-04-21 P. Koppenburg
//-----------------------------------------------------------------------------
//=============================================================================
// Standard constructor, initializes variables
//=============================================================================
ChargedParticleMakerBase::ChargedParticleMakerBase( const std::string& name, ISvcLocator* pSvcLocator )
: ParticleMakerBase( name, pSvcLocator ), m_p2s(), m_trSel( NULL ) {}
//=========================================================================
//
//=========================================================================
StatusCode ChargedParticleMakerBase::initialize() {
StatusCode sc = ParticleMakerBase::initialize();
if ( sc.isFailure() ) return sc;
m_p2s = tool<IParticle2State>( "Particle2State" ); // not private
// get an instance of the track selector
m_trSel = tool<ITrackSelector>( "TrackSelector", "TrackSelector", this );
const std::string Upper( to_upper( m_pid ) );
if ( "PIONS" == Upper ) {
m_pid = "pi+";
} else if ( "PI" == Upper ) {
m_pid = "pi+";
} else if ( "PION" == Upper ) {
m_pid = "pi+";
} else if ( "KAONS" == Upper ) {
m_pid = "K+";
} else if ( "KAON" == Upper ) {
m_pid = "K+";
} else if ( "K" == Upper ) {
m_pid = "K+";
} else if ( "MUONS" == Upper ) {
m_pid = "mu+";
} else if ( "MUON" == Upper ) {
m_pid = "mu+";
} else if ( "MU" == Upper ) {
m_pid = "mu+";
} else if ( "ELECTRONS" == Upper ) {
m_pid = "e+";
} else if ( "ELECTRON" == Upper ) {
m_pid = "e+";
} else if ( "POSITRON" == Upper ) {
m_pid = "e+";
} else if ( "E" == Upper ) {
m_pid = "e+";
} else if ( "PROTONS" == Upper ) {
m_pid = "p+";
} else if ( "PROTON" == Upper ) {
m_pid = "p+";
} else if ( "P" == Upper ) {
m_pid = "p+";
}
sc = setPPs( m_pid );
if ( sc.isFailure() ) { return Error( "Particle/Antiparticle are unknown for '" + m_pid + "'", sc ); }
if ( 0 == m_pp || 0 == m_app ) { return Error( "Particle/Antiparticle are invalid for '" + m_pid + "'" ); }
if ( m_pp->charge() < m_app->charge() ) {
std::swap( m_pp, m_app );
if ( msgLevel( MSG::DEBUG ) ) debug() << "swapping" << m_pp->particle() << " and " << m_app->particle() << endmsg;
}
m_pid = m_pp->particle();
m_apid = m_app->particle();
info() << "Particle/AntiParticle to be created : "
<< "'" << m_pid << "'/'" << m_apid << "'" << endmsg;
return sc;
}
// ============================================================================
/// set particle properties for particle and for antiparticle
// ============================================================================
StatusCode ChargedParticleMakerBase::setPPs( const std::string& pid ) {
if ( !ppSvc() ) { return StatusCode( 110 ); }
// get the properties of the particle
m_pp = ppSvc()->find( pid );
if ( !m_pp ) { return StatusCode( 111 ); }
// get the the antiparticle
m_app = m_pp->antiParticle();
if ( !m_app ) { return StatusCode( 112 ); }
m_apid = m_app->particle();
return StatusCode::SUCCESS;
}
// ============================================================================
/// Select the appropriate state
// ============================================================================
const LHCb::State* ChargedParticleMakerBase::usedState( const LHCb::Track* track ) const {
if ( !track ) Exception( "NULL track" );
const LHCb::State* uState = 0;
if ( msgLevel( MSG::VERBOSE ) ) { verbose() << "ChargedParticleMakerBase::usedState :: Looking for State" << endmsg; }
// default: closest to the beam for track types with a Velo part.
if ( !uState &&
!( track->checkType( LHCb::Track::Types::Downstream ) || track->checkType( LHCb::Track::Types::Ttrack ) ) ) {
uState = track->stateAt( LHCb::State::Location::ClosestToBeam );
}
// if not available: first measurement. Default for Downstream and T tracks
if ( !uState ) { uState = track->stateAt( LHCb::State::Location::FirstMeasurement ); }
// backup
if ( !uState ) {
Warning( "No state closest to beam or at first measurement for track. Using first state instead", StatusCode{10},
1 )
.ignore();
uState = &track->firstState();
}
if ( msgLevel( MSG::VERBOSE ) ) {
verbose() << "Using '" << uState->location() << "' state at " << uState->position() << endmsg;
}
return uState;
}
//=============================================================================
// Destructor
//=============================================================================
ChargedParticleMakerBase::~ChargedParticleMakerBase() {}
/*****************************************************************************\
* (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 CHARGEDPARTICLEMAKERBASE_H
#define CHARGEDPARTICLEMAKERBASE_H 1
// Include files
// from STL
#include <string>
// from DaVinci
#include "Kernel/IParticle2State.h"
#include "ParticleMakerBase.h"
#include "TrackInterfaces/ITrackSelector.h"
/** @class ChargedParticleMakerBase ChargedParticleMakerBase.h
*
* Base class for all Particle Maker Algorithms
*
* @author P. Koppenburg
* @date 2009-04-21
*/
class ChargedParticleMakerBase : public ParticleMakerBase {
public:
/// Standard constructor
ChargedParticleMakerBase( const std::string& name, ISvcLocator* pSvcLocator );
virtual ~ChargedParticleMakerBase(); ///< Destructor
StatusCode initialize() override; ///< Finalize
protected:
// The method that each implementation should implement
// virtual StatusCode makeParticles(LHCb::Particle::Vector& ) = 0 ;
/// Particle to state convertion tool
const IParticle2State* p2s() const { return m_p2s; }
/// Track selector tool
const ITrackSelector* trSel() const { return m_trSel; }
/// set particle properties for particle and for antiparticle
StatusCode setPPs( const std::string& pid );
/// Select the appropriate state
const LHCb::State* usedState( const LHCb::Track* track ) const;
private:
/// Particle to state convertion tool
const IParticle2State* m_p2s;
/// Track selector tool
const ITrackSelector* m_trSel;
};
#endif // CHARGEDPARTICLEMAKERBASE
/*****************************************************************************\
* (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. *
\*****************************************************************************/
//-----------------------------------------------------------------------------
/** @file CombinedParticleMaker.cpp
*
* Implmentation file for Particle maker CombinedParticleMaker
*
* @author Chris Jones Christopher.Rob.Jones@cern.ch
* @date 2006-05-03
*/
//-----------------------------------------------------------------------------
// from Gaudi
#include "CaloUtils/CaloMomentum.h"
// local
#include "CombinedParticleMaker.h"
//=============================================================================
// Standard constructor, initializes variables
//=============================================================================
CombinedParticleMaker::CombinedParticleMaker( const std::string& name, ISvcLocator* pSvcLocator )
: ChargedParticleMakerBase( name, pSvcLocator ), m_protoTool( NULL ), m_partProp( NULL ) {
// ProtoParticle filters to use for each type
declareProperty( "ElectronFilter", m_elProtoFilter = "ProtoParticleCALOFilter" );
declareProperty( "MuonFilter", m_muProtoFilter = "ProtoParticleMUONFilter" );
declareProperty( "PionFilter", m_piProtoFilter = "ProtoParticleCALOFilter" );
declareProperty( "KaonFilter", m_kaProtoFilter = "ProtoParticleCALOFilter" );
declareProperty( "ProtonFilter", m_prProtoFilter = "ProtoParticleCALOFilter" );
declareProperty( "MinPercentForPrint", m_minPercForPrint = 0.01 );
// Test PID info consistency
declareProperty( "CheckPIDConsistency", m_testPIDinfo = true );
}
//=============================================================================
CombinedParticleMaker::~CombinedParticleMaker() {}