Commit a6d6dd3e authored by Atlas-Software Librarian's avatar Atlas-Software Librarian Committed by Graeme Stewart
Browse files

'CMakeLists.txt' (TrkAssociationTools-00-01-09)

parent 21a47681
################################################################################
# Package: TrkAssociationTools
################################################################################
# Declare the package name:
atlas_subdir( TrkAssociationTools )
# Declare the package's dependencies:
atlas_depends_on_subdirs( PUBLIC
Control/AthenaBaseComps
Tracking/TrkTools/TrkToolInterfaces
PRIVATE
DetectorDescription/AtlasDetDescr
DetectorDescription/Identifier
GaudiKernel
Tracking/TrkDetDescr/TrkDetElementBase
Tracking/TrkEvent/TrkEventUtils
Tracking/TrkEvent/TrkRIO_OnTrack
Tracking/TrkEvent/TrkTrack )
# Component(s) in the package:
atlas_add_component( TrkAssociationTools
src/*.cxx
src/components/*.cxx
LINK_LIBRARIES AthenaBaseComps TrkToolInterfaces AtlasDetDescr Identifier GaudiKernel TrkDetElementBase TrkEventUtils TrkRIO_OnTrack TrkTrack )
# Install files from the package:
atlas_install_headers( TrkAssociationTools )
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef TRK_PRD_ASSOCIATIONTOOL_H
#define TRK_PRD_ASSOCIATIONTOOL_H
#include "AthenaBaseComps/AthAlgTool.h"
#include "TrkToolInterfaces/IPRD_AssociationTool.h"
#include <set>
#include <map>
class AtlasDetectorID;
class Identifier;
namespace Trk {
class Track;
class PrepRawData;
/** Concrete Implementation of the IPRD_AssociationTool interface.*/
class PRD_AssociationTool : virtual public IPRD_AssociationTool, public AthAlgTool
{
public:
PRD_AssociationTool(const std::string&,const std::string&,const IInterface*);
virtual ~PRD_AssociationTool ();
virtual StatusCode initialize();
virtual StatusCode finalize ();
/** add the PRDs from this track to the store
@param track all PRDs from 'track' will be added to PRD_AssociationTool's internal store.*/
virtual StatusCode addPRDs(const Track& track);
/** remove the PRDs from this track from the store
@param track all PRDs from 'track' will be removed from the PRD_AssociationTool's
internal store.*/
virtual StatusCode removePRDs(const Track& track);
/** does this PRD belong to at least one track?
@param prd the PrepRawData in question
@return true if 'prd' exists in at least one track (of course PRD_AssociationTool can only
give information about tracks it knows about i.e. that were added with addPRDs()*/
virtual bool isUsed(const PrepRawData& prd) const;
/** does this PRD belong to more than one track?
@param prd the PrepRawData in question
@return true if 'prd' exists on more than one track (of course PRD_AssociationTool can only
give information about tracks it knows about i.e. that were added with addPRDs()*/
virtual bool isShared(const PrepRawData& prd) const;
/**returns a vector of PRDs belonging to the passed track.
It's basically for the convenience of users and is created purely from the passed track.
i.e. there is no caching if you do it multiple times on the same track, you're being
inefficient!!
@param track this Track will be iterated through and all PrepRawData added to a vector
@return vector of PrepRawData* belonging to 'track'. The PrepRawData should NOT be deleted
- they belong to the Track (and thus the event).*/
virtual std::vector< const PrepRawData* > getPrdsOnTrack(const Track& track) const;
/** returns set of tracks which share PRD with this one
@param track this Track must be known to this tool.
@return a set of tracks which share PRD/hits with the passed 'track'*/
virtual IPRD_AssociationTool::TrackSet findConnectedTracks( const Track& track) ;
/** get the Tracks associated with this Trk::PrepRawData.
IMPORTANT: Please use the typedefs IPRD_AssociationTool::PrepRawDataRange and
IPRD_AssociationTool::ConstPRD_MapIt (defined in the interface) to access the
tracks, as the way the data is stored internally may change.*/
virtual IPRD_AssociationTool::PrepRawDataTrackMapRange onTracks(const PrepRawData& prd) ;
/** resets the tool - should be called before using tool (and maybe afterwards to free up
memory)*/
virtual void reset();
private:
/**holds the tracks associated with each PRD (i.e. the PRD* is the key)*/
IPRD_AssociationTool::PrepRawDataTrackMap m_prepRawDataTrackMap;
/**holds the PRDs associated with each Track (i.e. the Track* is the key)*/
IPRD_AssociationTool::TrackPrepRawDataMap m_trackPrepRawDataMap;
};
inline bool Trk::PRD_AssociationTool::isUsed(const PrepRawData& prd) const
{
return (m_prepRawDataTrackMap.count(&prd)>0);
}
inline bool Trk::PRD_AssociationTool::isShared(const PrepRawData& prd) const
{
return (m_prepRawDataTrackMap.count(&prd)>1);
}
}
#endif
package TrkAssociationTools
author Edward Moyse <edward.moyse@cern.ch>
public
use AtlasPolicy AtlasPolicy-*
use AthenaBaseComps AthenaBaseComps-* Control
use TrkToolInterfaces TrkToolInterfaces-* Tracking/TrkTools
private
use AtlasDetDescr AtlasDetDescr-* DetectorDescription
use GaudiInterface GaudiInterface-* External
use Identifier Identifier-* DetectorDescription
use TrkDetElementBase TrkDetElementBase-* Tracking/TrkDetDescr
use TrkEventUtils TrkEventUtils-* Tracking/TrkEvent
use TrkRIO_OnTrack TrkRIO_OnTrack-* Tracking/TrkEvent
use TrkTrack TrkTrack-* Tracking/TrkEvent
public
library TrkAssociationTools *.cxx -s=components *.cxx
apply_pattern component_library
#apply_pattern declare_joboptions files="*.txt *.py"
private
#macro cppdebugflags '$(cppdebugflags_s)'
#macro_remove componentshr_linkopts "-Wl,-s"
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
/**
@mainpage
@author Edward.Moyse@cern.ch
This package provides tools to handle the associations between the various Tracking EDM classes.
For example, the TrkAmbiguityProcessor makes use of the Trk::PRD_AssociationTool from this package, which keeps track of all the Trk::PrepRawData on the tracks, and knows which are shared with which Trk::Track etc.
@include requirements
*/
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "TrkAssociationTools/PRD_AssociationTool.h"
#include "TrkDetElementBase/TrkDetElementBase.h"
#include "TrkTrack/Track.h"
#include "TrkRIO_OnTrack/RIO_OnTrack.h"
#include "TrkEventUtils/CreatePRD_MapPairFromTrack.h"
#include "TrkEventUtils/CreatePRD_VectorFromTrack.h"
#include "Identifier/Identifier.h"
#include "AtlasDetDescr/AtlasDetectorID.h"
#include <cassert>
#include <vector>
//#include <functional>
#include "ext/functional"
//#include "boost/mpl/select1st.hpp"
Trk::PRD_AssociationTool::PRD_AssociationTool(const std::string& t,
const std::string& n,
const IInterface* p )
:
AthAlgTool(t,n,p)
{
declareInterface<IPRD_AssociationTool>(this);
}
Trk::PRD_AssociationTool::~PRD_AssociationTool()
{
}
StatusCode Trk::PRD_AssociationTool::initialize()
{
StatusCode sc = AlgTool::initialize();
if (sc.isFailure()) return sc;
return StatusCode::SUCCESS;
}
StatusCode Trk::PRD_AssociationTool::finalize()
{
StatusCode sc = AlgTool::finalize();
return sc;
}
StatusCode Trk::PRD_AssociationTool::addPRDs( const Trk::Track& track )
{
using namespace std;
// test caching
TrackPrepRawDataMap::const_iterator itvec = m_trackPrepRawDataMap.find(&track);
if (itvec!=m_trackPrepRawDataMap.end())
{
ATH_MSG_ERROR ("track already found in cache, should not happen");
return StatusCode::FAILURE;
}
// get all prds on 'track'
vector< const Trk::PrepRawData* > prds = getPrdsOnTrack( track );
vector< const Trk::PrepRawData* >::const_iterator it = prds.begin();
vector< const Trk::PrepRawData* >::const_iterator itEnd = prds.end();
// loop over PRD
for (; it!=itEnd; ++it)
m_prepRawDataTrackMap.insert(std::make_pair(*it, &track) );
// cache this using m_trackPrepRawDataMap
m_trackPrepRawDataMap.insert( std::make_pair(&track, prds) );
ATH_MSG_DEBUG ("Added PRDs from Track at ("<<&track<<") - map now has size: \t"<<
m_prepRawDataTrackMap.size());
return StatusCode::SUCCESS;
}
StatusCode Trk::PRD_AssociationTool::removePRDs( const Trk::Track& track )
{
using namespace std;
// This is NOT pretty code!
// At the moment I'm brute-forcing, but maybe I need a second map, containing <Track*, iterator>
// The problem is that I think filling such a map is also time-consuming.
// Since removes happen much less frequently than add, then the slow bit should be here.
// EJWM
// save for debugging purposes
int oldSize = m_prepRawDataTrackMap.size();//used in debug output at end.
// test caching
TrackPrepRawDataMap::iterator itvec = m_trackPrepRawDataMap.find(&track);
if (itvec==m_trackPrepRawDataMap.end())
{
ATH_MSG_ERROR ("Track not found in cache, this should not happen");
return StatusCode::FAILURE;
}
// get all prds on 'track'
vector< const Trk::PrepRawData* > prds = itvec->second;
vector< const Trk::PrepRawData* >::const_iterator it = prds.begin();
vector< const Trk::PrepRawData* >::const_iterator itEnd = prds.end();
// loop over PRD
for (; it!=itEnd; ++it)
{
// now get all map elements (i.e. Tracks) that contain this PRD
PrepRawData* prd = const_cast<PrepRawData*>(*it);
IPRD_AssociationTool::PrepRawDataTrackMapRange
range = m_prepRawDataTrackMap.equal_range(prd);
// get iterators for range
PRD_MapIt mapIt = range.first;
PRD_MapIt mapItEnd = range.second;
// FIXME - doesn't compile. Out of time - come back to it later
// remove_if(
// mapIt, mapItEnd,
// compose1(
// bind2nd(equal_to<const Track*>(), &track),
// select2nd<PrepRawDataTrackMap::value_type>()
// )
// );
// simple for loop instead of fancier remove_if above
for ( ;mapIt!=mapItEnd; ++mapIt)
{
if ( mapIt->second==&track )
{
m_prepRawDataTrackMap.erase( mapIt );
break;//should only ever be one Track
}
}
}
// remove cached PRD vector
m_trackPrepRawDataMap.erase( itvec );
ATH_MSG_DEBUG ("Removed PRDs from track (" <<&track<<") \t- map has changed "<<
"size from \t"<<oldSize <<" \tto "<<m_prepRawDataTrackMap.size());
return StatusCode::SUCCESS;
}
Trk::IPRD_AssociationTool::TrackSet
Trk::PRD_AssociationTool::findConnectedTracks( const Trk::Track& track )
{
using namespace std;
//using namespace __gnu_cxx;
TrackSet connectedTracks;
std::vector< const Trk::PrepRawData* > prds = getPrdsOnTrack(track);
std::vector< const Trk::PrepRawData* >::const_iterator it = prds.begin();
std::vector< const Trk::PrepRawData* >::const_iterator itEnd = prds.end();
for ( ; it!=itEnd; it++)
{
IPRD_AssociationTool::PrepRawDataTrackMapRange range = onTracks(**it);
// TODO use remove_copy_if instead.
for ( ; range.first!=range.second; ++(range.first) )
{
const Track* conTrack = (range.first)->second;
// don't copy this track!
if (conTrack!=&track) {
// this does actually not allow for double entries
connectedTracks.insert(conTrack);
ATH_MSG_VERBOSE ("Track "<<&track<<" \tshares PRD "<<*it<<" \twith track:"<<conTrack);
}
}
ATH_MSG_VERBOSE ("Added in connected tracks for PRD:"<<*it<<
"\tsize of list now:"<<connectedTracks.size());
}
return connectedTracks;
}
std::vector< const Trk::PrepRawData* > Trk::PRD_AssociationTool::getPrdsOnTrack(const Trk::Track& track) const
{
typedef std::vector<const PrepRawData*> PRDs_t;
// test caching
TrackPrepRawDataMap::const_iterator itvec = m_trackPrepRawDataMap.find(&track);
if (itvec!=m_trackPrepRawDataMap.end())
{
ATH_MSG_VERBOSE ("found track in cache, return cached PRD vector for track");
return itvec->second;
}
if (track.measurementsOnTrack()==0) {
ATH_MSG_WARNING ("Track has no RoTs");
return PRDs_t();
}
// FIXME can I do this without copying the vector?
/* transform(
track.measurementsOnTrack()->begin(),
track.measurementsOnTrack()->end() ,
back_inserter(vec),
bind2nd(CreatePRD_VectorFromTrack(), &track) );*/
DataVector<const MeasurementBase>::const_iterator it = track.measurementsOnTrack()->begin();
DataVector<const MeasurementBase>::const_iterator itEnd = track.measurementsOnTrack()->end();
PRDs_t vec;
vec.reserve(track.measurementsOnTrack()->size());
for (;it!=itEnd;it++)
{
const RIO_OnTrack* rot = dynamic_cast<const RIO_OnTrack*>(*it);
if (0!=rot)
vec.push_back(rot->prepRawData());
}
ATH_MSG_DEBUG (" Getting "<<vec.size()<<" PRDs from track at:"<<&track);
return vec;
}
Trk::IPRD_AssociationTool::PrepRawDataTrackMapRange
Trk::PRD_AssociationTool::onTracks(const PrepRawData& prd)
{
// std::pair<IPRD_AssociationTool::PRD_MapIt, IPRD_AssociationTool::PRD_MapIt> range =
return m_prepRawDataTrackMap.equal_range(&prd);
}
void Trk::PRD_AssociationTool::reset()
{
m_prepRawDataTrackMap.clear();
m_trackPrepRawDataMap.clear();
}
#include "GaudiKernel/DeclareFactoryEntries.h"
#include "TrkAssociationTools/PRD_AssociationTool.h"
DECLARE_NAMESPACE_TOOL_FACTORY( Trk, PRD_AssociationTool )
DECLARE_FACTORY_ENTRIES( TrkAssociationTools )
{
DECLARE_NAMESPACE_TOOL(Trk, PRD_AssociationTool)
}
/***************************************************************************
iPatRecAlgs
-----------
ATLAS Collaboration
***************************************************************************/
// $Id: TrkAssociationTools_load.cxx,v 1.2 2005-06-22 13:41:58 emoyse Exp $
#include "GaudiKernel/LoadFactoryEntries.h"
LOAD_FACTORY_ENTRIES( TrkAssociationTools )
//LOAD_FACTORY_ENTRIES(AmbiTool )
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment