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

'CMakeLists.txt' (InDetAssociationTools-00-01-08)

parent b552e50e
################################################################################
# Package: InDetAssociationTools
################################################################################
# Declare the package name:
atlas_subdir( InDetAssociationTools )
# Declare the package's dependencies:
atlas_depends_on_subdirs( PUBLIC
Control/AthenaBaseComps
DetectorDescription/Identifier
GaudiKernel
InnerDetector/InDetRecEvent/InDetPrepRawData
Tracking/TrkEvent/TrkPrepRawData
Tracking/TrkTools/TrkToolInterfaces
PRIVATE
DetectorDescription/AtlasDetDescr
InnerDetector/InDetDetDescr/InDetIdentifier
InnerDetector/InDetRecEvent/InDetRIO_OnTrack
Tracking/TrkDetDescr/TrkDetElementBase
Tracking/TrkEvent/TrkRIO_OnTrack
Tracking/TrkEvent/TrkTrack )
# Component(s) in the package:
atlas_add_component( InDetAssociationTools
src/*.cxx
src/components/*.cxx
LINK_LIBRARIES AthenaBaseComps Identifier GaudiKernel InDetPrepRawData TrkPrepRawData TrkToolInterfaces AtlasDetDescr InDetIdentifier InDetRIO_OnTrack TrkDetElementBase TrkRIO_OnTrack TrkTrack )
# Install files from the package:
atlas_install_headers( InDetAssociationTools )
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef INDET_PRD_ASSOCIATIONTOOL_H
#define INDET_PRD_ASSOCIATIONTOOL_H
#include "AthenaBaseComps/AthAlgTool.h"
#include "GaudiKernel/ServiceHandle.h"
#include "TrkToolInterfaces/IPRD_AssociationTool.h"
#include "InDetPrepRawData/PixelGangedClusterAmbiguities.h"
#include <set>
#include <map>
class AtlasDetectorID;
class Identifier;
namespace InDet {
class Track;
class PrepRawData;
/** Concrete Implementation of the IPRD_AssociationTool interface.*/
class InDetPRD_AssociationToolGangedPixels : virtual public Trk::IPRD_AssociationTool, public AthAlgTool
{
public:
InDetPRD_AssociationToolGangedPixels(const std::string&,const std::string&,const IInterface*);
virtual ~InDetPRD_AssociationToolGangedPixels ();
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 Trk::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 Trk::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 Trk::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 Trk::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 Trk::PrepRawData* > getPrdsOnTrack(const Trk::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 Trk::IPRD_AssociationTool::TrackSet findConnectedTracks( const Trk::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 Trk::IPRD_AssociationTool::PrepRawDataTrackMapRange onTracks(const Trk::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;
const PixelGangedClusterAmbiguities* m_gangedAmbis;
std::string m_pixelClusterAmbiguitiesMapName;
/** add TRT outliers in the addTrack method to avoid splits due to rejected extensions */
bool m_addTRToutliers;
};
inline bool InDet::InDetPRD_AssociationToolGangedPixels::isUsed(const Trk::PrepRawData& prd) const
{
return (m_prepRawDataTrackMap.count(&prd)>0);
}
inline bool InDet::InDetPRD_AssociationToolGangedPixels::isShared(const Trk::PrepRawData& prd) const
{
return (m_prepRawDataTrackMap.count(&prd)>1);
}
}
#endif
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
///////////////////////////////////////////////////////////////////
// InDetPRD_Provider.h, (c) ATLAS Detector software
///////////////////////////////////////////////////////////////////
#ifndef INDET_INDETASSOCIATIONTOOLS_INDETPRDPROVIDER_H
#define INDET_INDETASSOCIATIONTOOLS_INDETPRDPROVIDER_H 1
// Gaudi
#include "AthenaBaseComps/AthAlgTool.h"
#include "GaudiKernel/ToolHandle.h"
// InDet includes
#include "InDetPrepRawData/PixelClusterContainer.h"
#include "InDetPrepRawData/SCT_ClusterContainer.h"
#include "InDetPrepRawData/TRT_DriftCircleContainer.h"
// Trk includes
#include "TrkToolInterfaces/IPRD_Provider.h"
#include "TrkPrepRawData/PrepRawDataContainer.h"
#include "TrkPrepRawData/PrepRawDataCollection.h"
// Identifier
#include "Identifier/Identifier.h"
#include "Identifier/IdentifierHash.h"
class AtlasDetectorID;
class PixelID;
class SCT_ID;
class TRT_ID;
namespace InDet {
/**
@class InDet
@brief PRD provider for the Inner detector needed, to optimize search for IdContext
@author Andreas.Salzburger -at- cern.ch
*/
class InDetPRD_Provider : public AthAlgTool, virtual public Trk::IPRD_Provider {
public:
//** Constructor with parameters */
InDetPRD_Provider( const std::string& t, const std::string& n, const IInterface* p );
/** Athena algtool's Hooks */
StatusCode initialize();
/** finalize */
StatusCode finalize();
/** retrieve the PRD collection from StoreGate */
StatusCode retrieveCollection();
/** return the Prd given the Identifier - make a HashId out of the Id and return the associated PRD */
const Trk::PrepRawData* prdFromIdentifier(const Identifier& ide, size_t& ndof ) const;
private:
/** templated method since used for Pixel/SCT/TRT */
template < class PrdT > const Trk::PrepRawData* prdFromIdentifierContainer(
const Trk::PrepRawDataContainer< Trk::PrepRawDataCollection< PrdT > >& cont,
const Identifier& ideh, const IdentifierHash& ideHash ) const
{
// find the collection
typename Trk::PrepRawDataContainer< Trk::PrepRawDataCollection< PrdT > >::const_iterator prdCollIter = cont.indexFind(ideHash);
if ( prdCollIter == cont.end() ){
ATH_MSG_VERBOSE("PRD Collection to IdentifierHash could not be found. Return 0.");
return 0;
}
const Trk::PrepRawDataCollection< PrdT >* prdCollection = (*prdCollIter);
// search for the PRD in the collection --- do a loop, can be done better with std::find probably
const PrdT* prd = 0;
// iterate through the collections
typename Trk::PrepRawDataCollection< PrdT >::const_iterator prdIter = prdCollection->begin();
typename Trk::PrepRawDataCollection< PrdT >::const_iterator prdIterE = prdCollection->end();
for ( ; prdIter != prdIterE; ++prdIter ){
if ( (*prdIter)->identify() == ideh ){
prd = (*prdIter);
break;
}
}
// return what you have
return prd;
}
const AtlasDetectorID* m_idHelper; //! Helper to detect type of sub-detector from PRD->identify().
const PixelID* m_pixIdHelper;
std::string m_pixClusterContainerName;
mutable const PixelClusterContainer* m_pixClusterContainer;
const SCT_ID* m_sctIdHelper;
std::string m_sctClusterContainerName;
mutable const SCT_ClusterContainer* m_sctClusterContainer;
const TRT_ID* m_trtIdHelper;
std::string m_trtDriftCircleContainerName;
mutable const TRT_DriftCircleContainer* m_trtDriftCircleContainer;
};
} // end of namespace
#endif // INDET_INDETASSOCIATIONTOOLS_INDETPRDPROVIDER_H
\ No newline at end of file
package InDetAssociationTools
author Markus Elsing <Markus.Elsing@cern.ch>
private
#use StoreGate StoreGate-* Control
use AtlasDetDescr AtlasDetDescr-* DetectorDescription
use TrkDetElementBase TrkDetElementBase-* Tracking/TrkDetDescr
use TrkRIO_OnTrack TrkRIO_OnTrack-* Tracking/TrkEvent
use TrkTrack TrkTrack-* Tracking/TrkEvent
use InDetRIO_OnTrack InDetRIO_OnTrack-* InnerDetector/InDetRecEvent
use InDetIdentifier InDetIdentifier-* InnerDetector/InDetDetDescr
public
use AtlasPolicy AtlasPolicy-*
use GaudiInterface GaudiInterface-* External
use AthenaBaseComps AthenaBaseComps-* Control
use Identifier Identifier-* DetectorDescription
use TrkToolInterfaces TrkToolInterfaces-* Tracking/TrkTools
use TrkPrepRawData TrkPrepRawData-* Tracking/TrkEvent
use InDetPrepRawData InDetPrepRawData-* InnerDetector/InDetRecEvent
branches InDetAssociationTools src
library InDetAssociationTools *.cxx -s=components *.cxx
apply_pattern component_library
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "InDetAssociationTools/InDetPRD_AssociationToolGangedPixels.h"
#include "TrkDetElementBase/TrkDetElementBase.h"
#include "TrkTrack/Track.h"
#include "TrkRIO_OnTrack/RIO_OnTrack.h"
#include "InDetPrepRawData/PixelCluster.h"
#include "InDetRIO_OnTrack/TRT_DriftCircleOnTrack.h"
#include "Identifier/Identifier.h"
#include "AtlasDetDescr/AtlasDetectorID.h"
#include <cassert>
#include <vector>
#include "ext/functional"
InDet::InDetPRD_AssociationToolGangedPixels::InDetPRD_AssociationToolGangedPixels(const std::string& t,
const std::string& n,
const IInterface* p ) :
AthAlgTool(t,n,p)
{
declareInterface<IPRD_AssociationTool>(this);
declareProperty( "PixelClusterAmbiguitiesMapName", m_pixelClusterAmbiguitiesMapName = "PixelClusterAmbiguitiesMap" );
declareProperty( "addTRToutliers", m_addTRToutliers = false);
}
InDet::InDetPRD_AssociationToolGangedPixels::~InDetPRD_AssociationToolGangedPixels()
{}
StatusCode InDet::InDetPRD_AssociationToolGangedPixels::initialize()
{
return StatusCode::SUCCESS;
}
StatusCode InDet::InDetPRD_AssociationToolGangedPixels::finalize()
{
StatusCode sc = AlgTool::finalize();
return sc;
}
StatusCode InDet::InDetPRD_AssociationToolGangedPixels::addPRDs( const Trk::Track& track )
{
using namespace std;
// test caching
TrackPrepRawDataMap::const_iterator itvec = m_trackPrepRawDataMap.find(&track);
if (itvec!=m_trackPrepRawDataMap.end())
{
msg(MSG::ERROR)<<"track already found in cache, should not happen"<<endreq;
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) );
// test ganged ambiguity
const PixelCluster* pixel = dynamic_cast<const PixelCluster*> (*it);
if (pixel!=0) {
if (pixel->gangedPixel()) {
if (msgLvl(MSG::DEBUG)) msg() << "Found ganged pixel, search for mirror" << endreq;
std::pair<PixelGangedClusterAmbiguities::const_iterator,
PixelGangedClusterAmbiguities::const_iterator> ambi = m_gangedAmbis->equal_range(pixel);
for (; ambi.first != ambi.second ; ++(ambi.first) ) {
// add ambiguity as used by this track as well
if (msgLvl(MSG::DEBUG)) msg() << "Found mirror pixel, add mirror to association map" << endreq;
m_prepRawDataTrackMap.insert(std::make_pair(ambi.first->second, &track) );
}
}
}
}
// cache this using m_trackPrepRawDataMap
m_trackPrepRawDataMap.insert( std::make_pair(&track, prds) );
if (msgLvl(MSG::DEBUG)) msg()<<"Added PRDs from Track at ("<<&track<<") - map now has size: \t"
<<m_prepRawDataTrackMap.size()<<endreq;
return StatusCode::SUCCESS;
}
StatusCode InDet::InDetPRD_AssociationToolGangedPixels::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())
{
msg(MSG::ERROR)<<"Track not found in cache, this should not happen"<<endreq;
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
Trk::PrepRawData* prd = const_cast<Trk::PrepRawData*>(*it);
Trk::IPRD_AssociationTool::PrepRawDataTrackMapRange
range = m_prepRawDataTrackMap.equal_range(prd);
// get iterators for range
PRD_MapIt mapIt = range.first;
PRD_MapIt mapItEnd = range.second;
// 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
}
}
// test ganged ambiguity
const PixelCluster* pixel = dynamic_cast<const PixelCluster*> (*it);
if (pixel!=0) {
if (pixel->gangedPixel()) {
std::pair<PixelGangedClusterAmbiguities::const_iterator,
PixelGangedClusterAmbiguities::const_iterator> ambi = m_gangedAmbis->equal_range(pixel);
for (; ambi.first != ambi.second ; ++(ambi.first) ) {
// add ambiguity as used by this track as well
if (msgLvl(MSG::DEBUG)) msg()<<MSG::DEBUG<<"Found ganged pixel, remove also mirror from association map"<<endreq;
range = m_prepRawDataTrackMap.equal_range(ambi.first->second);
// get iterators for range
mapIt = range.first;
mapItEnd = range.second;
// 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 );
if (msgLvl(MSG::DEBUG)) msg()<<"Removed PRDs from track ("
<<&track<<") \t- map has changed size from \t"
<<oldSize <<" \tto "<<m_prepRawDataTrackMap.size()<<endreq;
return StatusCode::SUCCESS;
}
Trk::IPRD_AssociationTool::TrackSet
InDet::InDetPRD_AssociationToolGangedPixels::findConnectedTracks( const Trk::Track& track )
{
using namespace std;
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++) {
Trk::IPRD_AssociationTool::PrepRawDataTrackMapRange range = onTracks(**it);
// add them into the list
for ( ; range.first!=range.second; ++(range.first) )
connectedTracks.insert((range.first)->second);
// test ganged ambiguity
const PixelCluster* pixel = dynamic_cast<const PixelCluster*> (*it);
if (pixel!=0) {
if (pixel->gangedPixel()) {
std::pair<PixelGangedClusterAmbiguities::const_iterator,
PixelGangedClusterAmbiguities::const_iterator> ambi = m_gangedAmbis->equal_range(pixel);
for (; ambi.first != ambi.second ; ++(ambi.first) ) {
range = onTracks( *(ambi.first->second) );
// add them into the list
for ( ; range.first!=range.second; ++(range.first) )
connectedTracks.insert((range.first)->second);
}
}
}
}
// don't forget to remove the input track
connectedTracks.erase(&track);
if (msgLvl(MSG::VERBOSE)) msg()<<"Added in connected tracks for track "<<&track
<< "\tsize of list is "<<connectedTracks.size()<<endreq;
return connectedTracks;
}
std::vector< const Trk::PrepRawData* > InDet::InDetPRD_AssociationToolGangedPixels::getPrdsOnTrack(const Trk::Track& track) const
{
typedef std::vector<const Trk::PrepRawData*> PRDs_t;
// test caching
TrackPrepRawDataMap::const_iterator itvec = m_trackPrepRawDataMap.find(&track);
if (itvec!=m_trackPrepRawDataMap.end())
{
msg(MSG::VERBOSE)<<"found track in cache, return cached PRD vector for track"<<endreq;
return itvec->second;
}
if (track.measurementsOnTrack()==0) {
msg(MSG::WARNING)<<"Track has no RoTs"<<endreq;
return PRDs_t(); // return vector optimization
}
// FIXME can I do this without copying the vector?
/* transform(
track.measurementsOnTrack()->begin(),
track.measurementsOnTrack()->end() ,
back_inserter(vec),
bind2nd(CreatePRD_VectorFromTrack(), &track) );*/
// output vector
PRDs_t vec;
// size it
vec.reserve(track.measurementsOnTrack()->size());
// get the PRDs for the measuremenst on track
DataVector<const Trk::MeasurementBase>::const_iterator it = track.measurementsOnTrack()->begin();
DataVector<const Trk::MeasurementBase>::const_iterator itEnd = track.measurementsOnTrack()->end();
for (;it!=itEnd;it++)
{
const Trk::RIO_OnTrack* rot = dynamic_cast<const Trk::RIO_OnTrack*>(*it);
if (0!=rot)
vec.push_back(rot->prepRawData());
}
if (msgLvl(MSG::DEBUG)) msg()<<" Getting "<<vec.size()
<<" PRDs from track at:"<<&track<<endreq;
// new mode, we add the outleirs in the TRT
if (m_addTRToutliers) {
// get the PRDs for the measuremenst on track
DataVector<const Trk::MeasurementBase>::const_iterator it = track.outliersOnTrack()->begin();
DataVector<const Trk::MeasurementBase>::const_iterator itEnd = track.outliersOnTrack()->end();
for (;it!=itEnd;it++)
{
// get the ROT, make sure it is not a pseudo measurment
const Trk::RIO_OnTrack* rot = dynamic_cast<const Trk::RIO_OnTrack*>(*it);
if (0!=rot) {
// check if outlier is TRT ?
const TRT_DriftCircleOnTrack* trt = dynamic_cast<const TRT_DriftCircleOnTrack*> (rot);
if (trt) {
// add to the list, it is TRT
vec.push_back(rot->prepRawData());
}
}
}
if (msgLvl(MSG::DEBUG)) msg()<<" Getting "<<vec.size()
<<" PRDs including TRT outlier from track at:"<<&track<<endreq;
}
return vec;
}
Trk::IPRD_AssociationTool::PrepRawDataTrackMapRange
InDet::InDetPRD_AssociationToolGangedPixels::onTracks(const Trk::PrepRawData& prd)
{
// std::pair<IPRD_AssociationTool::PRD_MapIt, IPRD_AssociationTool::PRD_MapIt> range =
return m_prepRawDataTrackMap.equal_range(&prd);
}
void InDet::InDetPRD_AssociationToolGangedPixels::reset()
{
if (evtStore()->contains<PixelGangedClusterAmbiguities>( m_pixelClusterAmbiguitiesMapName ) )