From aa1fb24b9f0ae0ad1e652716f827476493f47e9c Mon Sep 17 00:00:00 2001 From: Chris Jones <jonesc@hep.phy.cam.ac.uk> Date: Thu, 14 Jul 2016 16:52:44 +0100 Subject: [PATCH 1/3] Skip empty input locations in ParticleMakerBase --- Phys/ParticleMaker/doc/release.notes | 3 + Phys/ParticleMaker/src/ParticleMakerBase.cpp | 58 ++++++++------------ Phys/ParticleMaker/src/ParticleMakerBase.h | 12 ++-- 3 files changed, 32 insertions(+), 41 deletions(-) diff --git a/Phys/ParticleMaker/doc/release.notes b/Phys/ParticleMaker/doc/release.notes index d5a19aacc..23807c972 100755 --- a/Phys/ParticleMaker/doc/release.notes +++ b/Phys/ParticleMaker/doc/release.notes @@ -3,6 +3,9 @@ ! Responsible : DaVinci coordinator !============================================================================== +! 2016-07-14 - Chris Jones + - Skip empty input locations in ParticleMakerBase + !======================= ParticleMaker v6r17 2015-11-27 ======================= ! 2015-11-01 - Gerhard Raven diff --git a/Phys/ParticleMaker/src/ParticleMakerBase.cpp b/Phys/ParticleMaker/src/ParticleMakerBase.cpp index 44f46358c..d14b5e878 100644 --- a/Phys/ParticleMaker/src/ParticleMakerBase.cpp +++ b/Phys/ParticleMaker/src/ParticleMakerBase.cpp @@ -20,18 +20,15 @@ ParticleMakerBase::ParticleMakerBase( const std::string& name, ISvcLocator* pSvcLocator) : DaVinciAlgorithm ( name , pSvcLocator ) - , m_apid ( ) - , m_pp ( 0 ) - , m_app ( 0 ) - , m_brem ( NULL ) { - declareProperty ( "Input" , m_input = LHCb::ProtoParticleLocation::Charged ) ; - declareProperty ( "Particle" , m_pid = "UNDEFINED" , + declareProperty( "Input", m_input = LHCb::ProtoParticleLocation::Charged ) ; + declareProperty( "Particle" , m_pid = "UNDEFINED" , "Particle to create : pion, kaon, muon..." ) ; declareProperty( "AddBremPhotonTo", m_addBremPhoton, "ParticleIDs to be Brem-corrected (default : electrons only)"); m_addBremPhoton.push_back( "e+" ); } + //========================================================================= // //======================================================================== @@ -47,7 +44,7 @@ StatusCode ParticleMakerBase::initialize ( ) if ( this->inputLocations().empty() ) { - this->inputLocations().push_back(m_input); + if ( !m_input.empty() ) { this->inputLocations().push_back(m_input); } } else { @@ -72,17 +69,17 @@ StatusCode ParticleMakerBase::execute() StatusCode sc = makeParticles(newParts); if ( sc.isFailure() ) return sc; - LHCb::Particle::ConstVector constParts ; /// @todo this is a hack due to CaloParticle... - constParts.reserve(newParts.size()); + // CRJ Seems not needed any more + //LHCb::Particle::ConstVector constParts ; /// @todo this is a hack due to CaloParticle... + //constParts.reserve(newParts.size()); - for ( LHCb::Particle::Vector::const_iterator i = newParts.begin() ; - i != newParts.end() ; ++i ) + for ( auto * p : newParts ) { - constParts.push_back(*i); - addBrem( *i ); + //constParts.push_back(p); + addBrem(p); } - this->markNewTrees(constParts); + this->markNewTrees(newParts); if ( msgLevel(MSG::DEBUG) ) { @@ -106,7 +103,7 @@ StatusCode ParticleMakerBase::execute() StatusCode ParticleMakerBase::loadEventInput() { - if (msgLevel(MSG::VERBOSE)) + if ( msgLevel(MSG::VERBOSE) ) { verbose() << ">>> ProtoParticleMakerBase::loadEventInput: load ProtoParticles from " << this->inputLocations() << endmsg; @@ -114,27 +111,21 @@ StatusCode ParticleMakerBase::loadEventInput() m_protos.clear(); - for ( std::vector<std::string>::const_iterator iLoc = this->inputLocations().begin(); - iLoc != this->inputLocations().end(); ++iLoc ) + for ( const auto loc : this->inputLocations() ) { - const LHCb::ProtoParticle::Container* pp = - getIfExists< LHCb::ProtoParticle::Container > ( *iLoc) ; + const auto * pp = getIfExists< LHCb::ProtoParticle::Container >(loc) ; if ( pp ) { if (msgLevel(MSG::VERBOSE)) { verbose() << "load " << pp->size() << " ProtoParticles from " - << *iLoc << endmsg; - } - for ( LHCb::ProtoParticle::Container::const_iterator iPP = pp->begin(); - iPP != pp->end(); ++iPP ) - { - m_protos.push_back(*iPP); + << loc << endmsg; } + for ( const auto * proto : *pp ) { m_protos.push_back(proto); } } else { - Info("No ProtoParticles at " + *iLoc); + Info("No ProtoParticles at " + loc); continue; } } @@ -144,21 +135,16 @@ StatusCode ParticleMakerBase::loadEventInput() //============================================================================= -void ParticleMakerBase::addBrem( LHCb::Particle* particle ) +void ParticleMakerBase::addBrem( LHCb::Particle * particle ) { bool ok = false; - for ( std::vector<std::string>::iterator p = m_addBremPhoton.begin() ; - m_addBremPhoton.end() != p; ++p ) + for ( const auto & p : m_addBremPhoton ) { - if ( *p == m_pid ) - { - ok = true; - break; - } + if ( p == m_pid ) { ok = true; break; } } - + if ( !ok ) return; - if ( !m_brem->addBrem( particle ) ) return; + if ( !bremAdder()->addBrem( particle ) ) return; if (msgLevel(MSG::DEBUG)) debug() << " ------- BremStrahlung has been added to the particle " diff --git a/Phys/ParticleMaker/src/ParticleMakerBase.h b/Phys/ParticleMaker/src/ParticleMakerBase.h index 38384356c..8f8b7cc5c 100644 --- a/Phys/ParticleMaker/src/ParticleMakerBase.h +++ b/Phys/ParticleMaker/src/ParticleMakerBase.h @@ -54,6 +54,9 @@ protected: std::transform( in.begin() , in.end() , out.begin () , ::toupper ) ; return out ; } + + /// Access the Brem Adder + IBremAdder* bremAdder() const { return m_brem; } private: @@ -67,10 +70,10 @@ protected: /// ID of the anti-particle std::string m_apid ; /// properties of particle - const LHCb::ParticleProperty* m_pp ; + const LHCb::ParticleProperty* m_pp = nullptr; /// properties of anti-particle - const LHCb::ParticleProperty* m_app ; + const LHCb::ParticleProperty* m_app = nullptr; /// Input Location of protoparticles std::string m_input ; @@ -78,15 +81,14 @@ protected: // list of PIDs for which BremStrahlung correction is activated std::vector<std::string> m_addBremPhoton; - IBremAdder* bremAdder(){return m_brem;} - private: /// Local ProtoParticle container. LHCb::ProtoParticle::ConstVector m_protos; /// Track selector tool - IBremAdder* m_brem; + IBremAdder* m_brem = nullptr; }; + #endif // PARTICLEMAKERBASE -- GitLab From cd24875e7f4897c6f18d74e23adfc44de6f11f0e Mon Sep 17 00:00:00 2001 From: Chris Jones <jonesc@hep.phy.cam.ac.uk> Date: Thu, 14 Jul 2016 17:12:35 +0100 Subject: [PATCH 2/3] add reference --- Phys/ParticleMaker/src/ParticleMakerBase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Phys/ParticleMaker/src/ParticleMakerBase.cpp b/Phys/ParticleMaker/src/ParticleMakerBase.cpp index d14b5e878..0698677d4 100644 --- a/Phys/ParticleMaker/src/ParticleMakerBase.cpp +++ b/Phys/ParticleMaker/src/ParticleMakerBase.cpp @@ -111,7 +111,7 @@ StatusCode ParticleMakerBase::loadEventInput() m_protos.clear(); - for ( const auto loc : this->inputLocations() ) + for ( const auto& loc : this->inputLocations() ) { const auto * pp = getIfExists< LHCb::ProtoParticle::Container >(loc) ; if ( pp ) -- GitLab From a763532c2aea163c3e2995030bb8a35f6c8872b7 Mon Sep 17 00:00:00 2001 From: Chris Jones <jonesc@hep.phy.cam.ac.uk> Date: Thu, 14 Jul 2016 18:17:35 +0100 Subject: [PATCH 3/3] check size before markNewTrees --- Phys/ParticleMaker/src/ParticleMakerBase.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Phys/ParticleMaker/src/ParticleMakerBase.cpp b/Phys/ParticleMaker/src/ParticleMakerBase.cpp index 0698677d4..d73bc6387 100644 --- a/Phys/ParticleMaker/src/ParticleMakerBase.cpp +++ b/Phys/ParticleMaker/src/ParticleMakerBase.cpp @@ -79,6 +79,8 @@ StatusCode ParticleMakerBase::execute() addBrem(p); } + const bool ok = !newParts.empty(); + this->markNewTrees(newParts); if ( msgLevel(MSG::DEBUG) ) @@ -94,7 +96,7 @@ StatusCode ParticleMakerBase::execute() else { debug() << "No primary vertices" << endmsg; } } - setFilterPassed( !newParts.empty() ); + setFilterPassed( ok ); return sc; } -- GitLab