diff --git a/Tracking/TrkAlgorithms/TrkAmbiguitySolver/TrkAmbiguitySolver/TrkAmbiguitySolver.h b/Tracking/TrkAlgorithms/TrkAmbiguitySolver/TrkAmbiguitySolver/TrkAmbiguitySolver.h new file mode 100755 index 0000000000000000000000000000000000000000..4a4c40be6b6635d3bd5dde615e381eabacffb77e --- /dev/null +++ b/Tracking/TrkAlgorithms/TrkAmbiguitySolver/TrkAmbiguitySolver/TrkAmbiguitySolver.h @@ -0,0 +1,81 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + + +/*************************************************************************** +TrkAmbiguitySolver Algorithm +***************************************************************************/ + + +#ifndef TRKAMBIGUITYSOLVER_H +#define TRKAMBIGUITYSOLVER_H + +#include "AthenaBaseComps/AthAlgorithm.h" +#include "GaudiKernel/ToolHandle.h" +#include "DataModel/DataVector.h" +#include "TrkTrack/TrackCollection.h" +#include <string> + +namespace Trk +{ + class ITrackAmbiguityProcessorTool; + + /**Algorithm does ambiguity processing + This algorithm uses the TrkAmbiguityProcessorTool AlgTool to resolve ambiguities in the passed tracks. + + Actually at the moment, this functionality is disabled - all TrkAmbiguitySolver does is to load Trk::Tracks (from + a location passed by jobOptions) and save them into (by default) "Tracks"*/ + + class TrkAmbiguitySolver : public AthAlgorithm + { + + public: + TrkAmbiguitySolver(const std::string& name, ISvcLocator* pSvcLocator); + ~TrkAmbiguitySolver(void); + + StatusCode initialize(void); + StatusCode execute(void); + StatusCode finalize(void); + + private: + //!<where to find tracks (set in jobOptions and can be multiple collections) + std::vector<std::string> m_tracksLocation; + std::string m_resolvedTracksLocation;//!<where to save the resolved tracks + std::string m_ambiProcessorName; + std::string m_ambiProcessorInstance; + + /** decides whether ambi processing actually occurs + (if not, the tracks are just resaved). + Default=false.*/ + bool m_resolveTracks; + TrackCollection m_oldTracks; + TrackCollection * m_tracks; + + /**Number of tracks input. Useful for debugging*/ + long int m_trackInCount; + /**Number of tracks passing Ambi solving. Useful for debugging*/ + long int m_trackOutCount; + + /** responsible for actual amiguity processing*/ + ToolHandle<ITrackAmbiguityProcessorTool> m_ambiTool; + + /** get tracks */ + StatusCode getTracks(); + + /** Save the processed tracks. If ambiguity process has not been called then they will + still be the original converted tracks */ + void saveTracks() const; + + /** Eventually this will use the TrkAmbiguityProcessorTool to resolve the track ambiguities. + At the moment it just saves a new vector of converted tracks. */ + void resolveTracks(); +}; + +} + +#endif + + + + diff --git a/Tracking/TrkAlgorithms/TrkAmbiguitySolver/cmt/requirements b/Tracking/TrkAlgorithms/TrkAmbiguitySolver/cmt/requirements new file mode 100755 index 0000000000000000000000000000000000000000..ff8a40fbe30146068ba42bfbe9b8405fa804f563 --- /dev/null +++ b/Tracking/TrkAlgorithms/TrkAmbiguitySolver/cmt/requirements @@ -0,0 +1,19 @@ +package TrkAmbiguitySolver +author Edward Moyse <edward.moyse@cern.ch> + +private +use StoreGate StoreGate-* Control +use TrkToolInterfaces TrkToolInterfaces-* Tracking/TrkTools + +public +use AtlasPolicy AtlasPolicy-* +use GaudiInterface GaudiInterface-* External +use AthenaBaseComps AthenaBaseComps-* Control +use DataModel DataModel-* Control +use TrkTrack TrkTrack-* Tracking/TrkEvent + +branches TrkAmbiguitySolver src + +library TrkAmbiguitySolver *.cxx -s=components *.cxx +apply_pattern component_library + diff --git a/Tracking/TrkAlgorithms/TrkAmbiguitySolver/src/TrkAmbiguitySolver.cxx b/Tracking/TrkAlgorithms/TrkAmbiguitySolver/src/TrkAmbiguitySolver.cxx new file mode 100755 index 0000000000000000000000000000000000000000..5a35a26595cb196d84338261b63718b751afc2d3 --- /dev/null +++ b/Tracking/TrkAlgorithms/TrkAmbiguitySolver/src/TrkAmbiguitySolver.cxx @@ -0,0 +1,142 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "TrkAmbiguitySolver/TrkAmbiguitySolver.h" +#include "TrkToolInterfaces/ITrackAmbiguityProcessorTool.h" +#include "StoreGate/StoreGateSvc.h" + +Trk::TrkAmbiguitySolver::TrkAmbiguitySolver(const std::string& name, ISvcLocator* pSvcLocator) : + AthAlgorithm (name, pSvcLocator), + m_resolvedTracksLocation("Tracks"), + m_resolveTracks(true), + m_oldTracks(SG::VIEW_ELEMENTS), // must be view or will delete tracks when cleared. + m_trackInCount(0), + m_trackOutCount(0), + m_ambiTool("Trk::SimpleAmbiguityProcessorTool/TrkAmbiguityProcessor") +{ + declareProperty("TrackInput" , m_tracksLocation); + declareProperty("TrackOutput" , m_resolvedTracksLocation); + declareProperty("AmbiguityProcessor", m_ambiTool); + declareProperty("ResolveTracks" , m_resolveTracks); +} + +//-------------------------------------------------------------------------- +Trk::TrkAmbiguitySolver::~TrkAmbiguitySolver(void) +{} + +//----------------------------------------------------------------------- +StatusCode +Trk::TrkAmbiguitySolver::initialize() +{ + msg(MSG::INFO) << "TrkAmbiguitySolver::initialize(). " << endreq; + + if (!m_resolveTracks) + msg(MSG::INFO) << "ATTENTION: Resolving tracks turned off! " << endreq; + else { + // Get Tools sevices + if (m_ambiTool.retrieve().isFailure()) { + msg(MSG::FATAL) << "Failed to retrieve tool " << m_ambiTool << endreq; + return StatusCode::FAILURE; + } else + msg(MSG::INFO) << "Retrieved tool " << m_ambiTool << endreq; + } + return StatusCode::SUCCESS; +} + +//------------------------------------------------------------------------- +StatusCode +Trk::TrkAmbiguitySolver::execute() +{ + ATH_MSG_VERBOSE ("TrkAmbiguitySolver::execute()"); + + StatusCode loadedTracks = getTracks(); + + if ( loadedTracks.isFailure() ) + { + msg(MSG::ERROR) << "TrkAmbiguitySolver could not find any tracks. Aborting." << endreq; + return StatusCode::SUCCESS; + } + + // Now pass tracks to AmbiTool + resolveTracks(); + saveTracks(); + + return StatusCode::SUCCESS; +} + +//--------------------------------------------------------------------------- + +StatusCode +Trk::TrkAmbiguitySolver::finalize() +{ + m_ambiTool->statistics(); + + msg(MSG::INFO) << "Finalizing with "<< m_trackInCount << " tracks input, and "<< m_trackOutCount<< " output"<< endreq; + + return StatusCode::SUCCESS; +} + +//------------------------------------------------------------------------------- + + +StatusCode Trk::TrkAmbiguitySolver::getTracks(){ + + m_oldTracks.clear(); + + std::vector<std::string>::const_iterator it = m_tracksLocation.begin(); + std::vector<std::string>::const_iterator itEnd = m_tracksLocation.end(); + for ( ; it!=itEnd ; it++) + { + const TrackCollection * tmpTracks=0; + StatusCode sc = sgSvc()->retrieve(tmpTracks, *it);// load tracks + if (sc.isFailure()) + msg(MSG::WARNING) << "Could not retrieve tracks from "<< *it << endreq; + else + { + ATH_MSG_VERBOSE ("Successfully retrieved "<<tmpTracks->size() + <<" tracks from "<< *it); + copy(tmpTracks->begin(),tmpTracks->end(), std::back_inserter(m_oldTracks)); + } + } + return StatusCode::SUCCESS; +} +//------------------------------------------------------------------------------- + +void Trk::TrkAmbiguitySolver::saveTracks() const +{ + StatusCode sc = sgSvc()->record(m_tracks, m_resolvedTracksLocation,false); + + if (sc.isFailure()) + msg(MSG::ERROR) << "Could not record tracks" << endreq; + else + ATH_MSG_VERBOSE ("Saved "<<m_tracks->size()<<" tracks"); + + return; +} + +//------------------------------------------------------------------------------- + +void Trk::TrkAmbiguitySolver::resolveTracks() +{ + if (m_resolveTracks) + { + // okay, and let's call the ambiguity processor, just for a laugh. + ATH_MSG_VERBOSE ("TrkAmbiguitySolver::resolveTracks() resolving " + << m_oldTracks.size()<<" tracks" ); + m_trackInCount += m_oldTracks.size(); + m_tracks = m_ambiTool->process( &m_oldTracks ); + m_trackOutCount += m_tracks->size(); + } + else + { + // copy tracks. NOT a shallow copy as it was before, since + // this causes mem leaks when reading back in again + // see bug#9886 for details + m_tracks = new TrackCollection; + TrackCollection::const_iterator it = m_oldTracks.begin(); + TrackCollection::const_iterator itEnd = m_oldTracks.end(); + for (;it!=itEnd;it++) m_tracks->push_back( new Track(**it) ); + } + return; +} diff --git a/Tracking/TrkAlgorithms/TrkAmbiguitySolver/src/components/TrkAmbiguitySolver_entries.cxx b/Tracking/TrkAlgorithms/TrkAmbiguitySolver/src/components/TrkAmbiguitySolver_entries.cxx new file mode 100755 index 0000000000000000000000000000000000000000..e70f92f8ac9aa88b2d65f353bd39a85696534a46 --- /dev/null +++ b/Tracking/TrkAlgorithms/TrkAmbiguitySolver/src/components/TrkAmbiguitySolver_entries.cxx @@ -0,0 +1,20 @@ +/*************************************************************************** + ATLAS Collaboration + ***************************************************************************/ + +// $Id: TrkAmbiguitySolver_entries.cxx,v 1.1.1.1 2007-02-21 13:36:44 msiebel Exp $ + +#include "GaudiKernel/DeclareFactoryEntries.h" +#include "TrkAmbiguitySolver/TrkAmbiguitySolver.h" + +DECLARE_NAMESPACE_ALGORITHM_FACTORY( Trk, TrkAmbiguitySolver ) + +DECLARE_FACTORY_ENTRIES( TrkAmbiguitySolver ) +{ + DECLARE_NAMESPACE_ALGORITHM( Trk, TrkAmbiguitySolver ); +} + + + + + diff --git a/Tracking/TrkAlgorithms/TrkAmbiguitySolver/src/components/TrkAmbiguitySolver_load.cxx b/Tracking/TrkAlgorithms/TrkAmbiguitySolver/src/components/TrkAmbiguitySolver_load.cxx new file mode 100755 index 0000000000000000000000000000000000000000..ccc9cda7f226e9346cef4285c56977ff76d49d08 --- /dev/null +++ b/Tracking/TrkAlgorithms/TrkAmbiguitySolver/src/components/TrkAmbiguitySolver_load.cxx @@ -0,0 +1,8 @@ +/*************************************************************************** + ATLAS Collaboration + ***************************************************************************/ + +#include "GaudiKernel/LoadFactoryEntries.h" + +LOAD_FACTORY_ENTRIES( TrkAmbiguitySolver ) +