diff --git a/Tracking/TrkEvent/TrkMultiComponentStateOnSurface/TrkMultiComponentStateOnSurface/MultiComponentState.h b/Tracking/TrkEvent/TrkMultiComponentStateOnSurface/TrkMultiComponentStateOnSurface/MultiComponentState.h index 0422c0fab1a296ecc64b9eafc91ae2d2070af4c9..1b3f78912fea205247a8de15ef9f8d96057530cd 100755 --- a/Tracking/TrkEvent/TrkMultiComponentStateOnSurface/TrkMultiComponentStateOnSurface/MultiComponentState.h +++ b/Tracking/TrkEvent/TrkMultiComponentStateOnSurface/TrkMultiComponentStateOnSurface/MultiComponentState.h @@ -9,9 +9,9 @@ begin : Friday 31st December 2004 author : atkinson, amorley email : Anthony.Morley@cern.ch decription : Basic definitions for a track state described by more - than one set of Track Parameters. The resulting state is - a mixture of components. Each component is described by - a ComponentParameters object which is of the type + than one set of Track Parameters. The resulting state is + a mixture of components. Each component is described by + a ComponentParameters object which is of the type std::pair< const TrackParameters*, double> The double describes the weighting of the component - or its relative importance in the mixture. @@ -21,13 +21,13 @@ decription : Basic definitions for a track state described by more #define TrkMultiComponentState #include "TrkMultiComponentStateOnSurface/ComponentParameters.h" -#include <list> +#include <vector> class MsgStream; namespace Trk{ -class MultiComponentState : public std::list<ComponentParameters>{ +class MultiComponentState : public std::vector<ComponentParameters>{ public: /** Default constructor */ diff --git a/Tracking/TrkEvent/TrkMultiComponentStateOnSurface/src/MultiComponentState.cxx b/Tracking/TrkEvent/TrkMultiComponentStateOnSurface/src/MultiComponentState.cxx index af9e4cb025ea6f3ef20f27ff0c0fe7c81e350eb4..62540446e42abeb05b8f354289aff4a49032feec 100755 --- a/Tracking/TrkEvent/TrkMultiComponentStateOnSurface/src/MultiComponentState.cxx +++ b/Tracking/TrkEvent/TrkMultiComponentStateOnSurface/src/MultiComponentState.cxx @@ -21,12 +21,12 @@ decription : Implementation code for MultiComponentState class Trk::MultiComponentState::MultiComponentState() : - std::list< Trk::ComponentParameters >() + std::vector< Trk::ComponentParameters >() {} Trk::MultiComponentState::MultiComponentState( const Trk::ComponentParameters& componentParameters ) : - std::list< Trk::ComponentParameters >() + std::vector< Trk::ComponentParameters >() { this->push_back( componentParameters ); } @@ -34,7 +34,9 @@ Trk::MultiComponentState::MultiComponentState( const Trk::ComponentParameters& c Trk::MultiComponentState::~MultiComponentState() { Trk::MultiComponentState::const_iterator component = this->begin(); - for ( ; component != this->end(); ++component ) delete component->first; + for ( ; component != this->end(); ++component ) { + delete component->first; + } this->clear(); } @@ -50,7 +52,6 @@ Trk::MultiComponentState* Trk::MultiComponentState::clone() const return clonedState; } - Trk::MultiComponentState* Trk::MultiComponentState::cloneWithWeightScaling( double scalingFactor ) const { Trk::MultiComponentState* clonedState = new Trk::MultiComponentState(); @@ -61,12 +62,14 @@ Trk::MultiComponentState* Trk::MultiComponentState::cloneWithWeightScaling( doub clonedState->push_back( componentParameters ); } return clonedState; - } -Trk::MultiComponentState* Trk::MultiComponentState::cloneWithScaledError( double errorScaleLocX,double errorScaleLocY, double errorScalePhi, - double errorScaleTheta,double errorScaleQoverP ) const +Trk::MultiComponentState* Trk::MultiComponentState::cloneWithScaledError( double errorScaleLocX, + double errorScaleLocY, + double errorScalePhi, + double errorScaleTheta, + double errorScaleQoverP ) const { Trk::MultiComponentState* stateWithScaledErrors = new Trk::MultiComponentState(); Trk::MultiComponentState::const_iterator component = this->begin(); @@ -119,10 +122,8 @@ Trk::MultiComponentState* Trk::MultiComponentState::cloneWithScaledError( double // Recalling of error does not change weighting const Trk::ComponentParameters componentParameters( newTrackParameters, component->second ); - // Push back new component stateWithScaledErrors->push_back( componentParameters ); - } return stateWithScaledErrors; @@ -206,10 +207,8 @@ bool Trk::MultiComponentState::isMeasured() const const AmgSymMatrix(5)* originalMatrix = component->first->covariance(); if (!originalMatrix) - isNotMeasured = true; - + isNotMeasured = true; } - return !isNotMeasured; } diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/src/LargestWeightsMultiStateMerger.cxx b/Tracking/TrkFitter/TrkGaussianSumFilter/src/LargestWeightsMultiStateMerger.cxx index 05b68949c15998b0a7f1514e4834d8289b924416..41c0455d481a268be7ffdae953b1ee8b21ee19cb 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/src/LargestWeightsMultiStateMerger.cxx +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/src/LargestWeightsMultiStateMerger.cxx @@ -14,7 +14,9 @@ decription : Implementation code for LargestWeightsMultiStateMerger cl #include "TrkGaussianSumFilter/LargestWeightsMultiStateMerger.h" #include "TrkGaussianSumFilter/SortingClasses.h" -Trk::LargestWeightsMultiStateMerger::LargestWeightsMultiStateMerger(const std::string& type, const std::string& name, const IInterface* parent) +Trk::LargestWeightsMultiStateMerger::LargestWeightsMultiStateMerger(const std::string& type, + const std::string& name, + const IInterface* parent) : AthAlgTool(type, name, parent), m_outputlevel(0), @@ -100,24 +102,22 @@ const Trk::MultiComponentState* Trk::LargestWeightsMultiStateMerger::merge(const Trk::MultiComponentState* componentsForCollapse = new Trk::MultiComponentState; // Sort all components of unmerged state according to weight - unmergedState->sort( SortByLargerComponentWeight() ); + std::sort(unmergedState->begin(), + unmergedState->end(), + SortByLargerComponentWeight() ); unsigned int numberOfComponents = 0; Trk::MultiComponentState::const_iterator component = unmergedState->begin(); - for ( ; component != unmergedState->end(); ++component, ++numberOfComponents ) - { + for ( ; component != unmergedState->end(); ++component, ++numberOfComponents ){ if (numberOfComponents < m_maximumNumberOfComponents){ - // Add component to state being prepared for assembly and check that it is valid bool componentAdded = m_stateAssembler->addComponent(cache,*component); - - if ( !componentAdded ) - msg(MSG::WARNING) << "Component could not be added to the state in the assembler" << endmsg; - + if ( !componentAdded ){ + ATH_MSG_WARNING("Component could not be added to the state in the assembler"); + } } - else{ Trk::ComponentParameters clonedComponent( component->first->clone(), component->second ); componentsForCollapse->push_back( clonedComponent ); @@ -138,11 +138,10 @@ const Trk::MultiComponentState* Trk::LargestWeightsMultiStateMerger::merge(const delete collapsedComponent->first; delete collapsedComponent; - if ( !componentAdded ) - msg(MSG::WARNING) << "Component could not be added to the state in the assembler" << endmsg; - + if ( !componentAdded ){ + ATH_MSG_WARNING("Component could not be added to the state in the assembler"); + } const Trk::MultiComponentState* assembledState = m_stateAssembler->assembledState(cache,1.); delete unmergedState; - return assembledState; } diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/src/MultiComponentStateAssembler.cxx b/Tracking/TrkFitter/TrkGaussianSumFilter/src/MultiComponentStateAssembler.cxx index 08766b466a7228010964df533d1d42288a1932cd..a7b62d4e864b61452b84d253fa676a7fc2bb7c50 100755 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/src/MultiComponentStateAssembler.cxx +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/src/MultiComponentStateAssembler.cxx @@ -66,9 +66,9 @@ void Trk::MultiComponentStateAssembler::status(const Cache& cache) const << "**************** End assembler status **************** \n"); } -bool Trk::MultiComponentStateAssembler::addComponent (Cache& cache, const ComponentParameters& componentParameters) const{ +bool Trk::MultiComponentStateAssembler::addComponent (Cache& cache, + const ComponentParameters& componentParameters) const{ - ATH_MSG_VERBOSE ( "Adding single component to mixture \n"); if ( cache.assemblyDone ){ ATH_MSG_WARNING("Trying to add state after assembly... returning false \n"); return false; @@ -76,9 +76,6 @@ bool Trk::MultiComponentStateAssembler::addComponent (Cache& cache, const Compo const Trk::ComponentParameters* clonedComponentParameters = new Trk::ComponentParameters( (componentParameters.first)->clone(), componentParameters.second); - ATH_MSG_VERBOSE("Creating multiple component state from single component. Weight of state is: " - << componentParameters.second << "\n"); - Trk::MultiComponentState* singleComponentList = new Trk::MultiComponentState(*clonedComponentParameters); this->addComponentsList(cache,singleComponentList); delete clonedComponentParameters; @@ -87,9 +84,9 @@ bool Trk::MultiComponentStateAssembler::addComponent (Cache& cache, const Compo return true; } -bool Trk::MultiComponentStateAssembler::addMultiState (Cache& cache, const MultiComponentState& multiComponentState) const{ +bool Trk::MultiComponentStateAssembler::addMultiState (Cache& cache, + const MultiComponentState& multiComponentState) const{ - ATH_MSG_VERBOSE("Adding multiple component state to mixture \n"); if (cache.assemblyDone ){ ATH_MSG_WARNING("Trying to add state after assembly... returning false \n"); return false; @@ -103,40 +100,35 @@ bool Trk::MultiComponentStateAssembler::addMultiState (Cache& cache, const Multi return true; } -bool Trk::MultiComponentStateAssembler::addInvalidComponentWeight (Cache& cache, const double invalidComponentWeight) const { +bool Trk::MultiComponentStateAssembler::addInvalidComponentWeight (Cache& cache, + const double invalidComponentWeight) const { - ATH_MSG_VERBOSE( "Adding the weight of an invalid state to the mixture \n"); cache.invalidWeightSum += invalidComponentWeight; return true; } -void Trk::MultiComponentStateAssembler::addComponentsList (Cache& cache, const MultiComponentState* multiComponentState) const{ +void Trk::MultiComponentStateAssembler::addComponentsList (Cache& cache, + const MultiComponentState* multiComponentState) const{ - ATH_MSG_VERBOSE ("Add multiple component state to exisiting mixture \n"); if ( cache.assemblyDone ){ ATH_MSG_WARNING( "Trying to add state after assembly \n"); return; } - double sumW(0.); Trk::MultiComponentState::const_iterator component = multiComponentState->begin(); - for ( ; component != multiComponentState->end(); ++ component) sumW += (*component).second; - cache.multiComponentState->insert(cache.multiComponentState->end(), multiComponentState->begin(), multiComponentState->end() ); + cache.multiComponentState->insert(cache.multiComponentState->end(), + multiComponentState->begin(), + multiComponentState->end() ); cache.validWeightSum += sumW; - - ATH_MSG_VERBOSE( "Successfully inserted state \n"); - } bool Trk::MultiComponentStateAssembler::prepareStateForAssembly (Cache& cache) const{ - ATH_MSG_VERBOSE( "Preparing state for assembly \n"); - // Protect against empty state if ( !isStateValid (cache) ){ ATH_MSG_DEBUG("State is not valid... returning false \n"); @@ -152,7 +144,7 @@ bool Trk::MultiComponentStateAssembler::prepareStateForAssembly (Cache& cache) c } // Check to see assembly has not already been done if ( cache.assemblyDone ){ - ATH_MSG_VERBOSE("Assembly of state already complete... returning true \n"); + ATH_MSG_DEBUG("Assembly of state already complete... returning true \n"); return true; } @@ -166,13 +158,13 @@ bool Trk::MultiComponentStateAssembler::prepareStateForAssembly (Cache& cache) c } // Sort Multi-Component State by weights - cache.multiComponentState->sort( SortByLargerComponentWeight() ); + std::sort(cache.multiComponentState->begin(), + cache.multiComponentState->end(), + SortByLargerComponentWeight() ); // Set assembly flag cache.assemblyDone = true; - ATH_MSG_VERBOSE ("State is prepared for assembly... returning true \n"); - return true; } @@ -208,26 +200,21 @@ Trk::MultiComponentStateAssembler::assembledState (Cache& cache, const double ne ATH_MSG_VERBOSE( "Finalising assembly with reweighting of components \n"); if ( !prepareStateForAssembly(cache) ) { - ATH_MSG_DEBUG("Unable to prepare state for assembly... returing 0 \n"); - return 0; + ATH_MSG_DEBUG("Unable to prepare state for assembly... returing nullptr \n"); + return nullptr; } - const Trk::MultiComponentState* stateAssembly = doStateAssembly(cache,newWeight); - return stateAssembly; } const Trk::MultiComponentState* Trk::MultiComponentStateAssembler::doStateAssembly (Cache& cache, const double newWeight) const{ - ATH_MSG_VERBOSE( "Do state assembly \n"); - if ( !isStateValid(cache) ) { - ATH_MSG_VERBOSE( "Cached state is empty... returning 0 \n"); - return 0; + ATH_MSG_DEBUG( "Cached state is empty... returning 0 \n"); + return nullptr; } - - + if (cache.validWeightSum <= 0.) { if (!cache.multiComponentState->empty()) { double fixedWeights = 1. / (double) cache.multiComponentState->size(); @@ -244,7 +231,6 @@ Trk::MultiComponentStateAssembler::doStateAssembly (Cache& cache, const double n double scalingFactor = cache.validWeightSum > 0. ? newWeight / cache.validWeightSum : 1. ; const Trk::MultiComponentState* assembledState = cache.multiComponentState->cloneWithWeightScaling( scalingFactor ); - // Reset the cashe before leaving this->reset(cache); @@ -253,31 +239,30 @@ Trk::MultiComponentStateAssembler::doStateAssembly (Cache& cache, const double n void Trk::MultiComponentStateAssembler::removeSmallWeights (Cache& cache) const{ - ATH_MSG_VERBOSE("Removing small weights \n"); - double totalWeight( cache.validWeightSum + cache.invalidWeightSum ); if ( totalWeight == 0. ) { - ATH_MSG_VERBOSE("Total weight of state is zero... exiting \n"); + ATH_MSG_DEBUG("Total weight of state is zero... exiting \n"); return; } - - // Loop over states and remove those with insiginificant weights fractions - bool continueToRemoveComponents; - - do { - continueToRemoveComponents = false; - MultiComponentState::iterator component; - for ( component = cache.multiComponentState->begin() ; - component != cache.multiComponentState->end() ; - ++component ) { - if ( (*component).second / totalWeight < m_minimumFractionalWeight ) { - delete component->first; - cache.multiComponentState->erase(component); - ATH_MSG_DEBUG("State with weight " << (*component).second << " has been removed from mixture"); - continueToRemoveComponents = true; - break; - } // end if - } // end for - } while ( continueToRemoveComponents ); -} + + //Loop over states and remove those with insiginificant weights fractions + bool continueToRemoveComponents; + do { + continueToRemoveComponents = false; + MultiComponentState::iterator component; + for ( component = cache.multiComponentState->begin() ; + component != cache.multiComponentState->end();/*Nothing*/ ) { + if ( (*component).second / totalWeight < m_minimumFractionalWeight ) { + delete component->first; + /* Get the iterator position after erase*/ + component=cache.multiComponentState->erase(component); + ATH_MSG_DEBUG("State with weight " << (*component).second << " has been removed from mixture"); + continueToRemoveComponents = true; + break; + } // end if + /* increment the iterator normally*/ + ++component; + } // end for + } while ( continueToRemoveComponents ); + }