Commit b7ec7886 authored by Attila Krasznahorkay's avatar Attila Krasznahorkay Committed by Graeme Stewart
Browse files

Adapting to the xAODTracking interface changes (InDetPriVxFinder-03-00-07)

parent 78658955
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
/***************************************************************************
InDetPriVxDummyFinder.h - Description
-------------------
***************************************************************************/
#ifndef INDETPRIVXFINDER_INDETPRIVXDUMMYFINDER_H
#define INDETPRIVXFINDER_INDETPRIVXDUMMYFINDER_H
#include "AthenaBaseComps/AthAlgorithm.h"
#include "GaudiKernel/ServiceHandle.h"
/** DUMMY Primary Vertex Finder.
InDetPriVxDummyFinder just fills one dummy vertex into the vertex container. The position and error of this
vertex are that of the beamspot or 0,0,0 if no beam spot is available. The vertex will have no tracks assigned
to it and will be of type Trk::NoVtx
*/
/* Forward declarations */
class IBeamCondSvc;
namespace InDet
{
class InDetPriVxDummyFinder : public AthAlgorithm
{
public:
InDetPriVxDummyFinder(const std::string &name, ISvcLocator *pSvcLocator);
virtual ~InDetPriVxDummyFinder();
StatusCode initialize();
StatusCode execute();
StatusCode finalize();
private:
ServiceHandle<IBeamCondSvc> m_iBeamCondSvc;
std::string m_vxCandidatesOutputName; //!< Name of output container to store results
};
}
#endif
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
/***************************************************************************
InDetPriVxFinder.h - Description
-------------------
begin : 27-01-2004
authors : Andreas Wildauer (CERN PH-ATC), Fredrik Akesson (CERN PH-ATC)
email : andreas.wildauer@cern.ch, fredrik.akesson@cern.ch
changes :
***************************************************************************/
#ifndef INDETPRIVXFINDER_INDETPRIVXFINDER_H
#define INDETPRIVXFINDER_INDETPRIVXFINDER_H
#include "AthenaBaseComps/AthAlgorithm.h"
#include "GaudiKernel/ToolHandle.h"
/** Primary Vertex Finder.
InDetPriVxFinder uses the InDetPrimaryVertexFinderTool in the package
InnerDetector/InDetRecTools/InDetPriVxFinderTool. It only gives the trackcollection from storegate to it
and records the returned VxContainer.
*/
/* Forward declarations */
namespace Trk
{
class IVertexCollectionSortingTool;
class IVxCandidateXAODVertex;
}
namespace InDet
{
class IVertexFinder;
class InDetPriVxFinder : public AthAlgorithm
{
public:
InDetPriVxFinder(const std::string &name, ISvcLocator *pSvcLocator);
virtual ~InDetPriVxFinder();
StatusCode initialize();
StatusCode execute();
StatusCode finalize();
private:
std::string m_tracksName; //!< Name of track container in StoreGate
std::string m_vxCandidatesOutputName; //!< Name of output container to store results
std::string m_vxCandidatesOutputNameAuxPostfix; //!< Postfix of output auxiliary container to store results (xAOD only)
ToolHandle< IVertexFinder > m_VertexFinderTool;
ToolHandle<Trk::IVertexCollectionSortingTool > m_VertexCollectionSortingTool;
ToolHandle< Trk::IVxCandidateXAODVertex > m_VertexEdmFactory;
bool m_doVertexSorting;
// for summary output at the end
unsigned int m_numEventsProcessed;
unsigned int m_totalNumVerticesWithoutDummy;
};
}
#endif
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
/***************************************************************************
InDetVxLinksToTrackParticles.h - Description
-------------------
begin : 27-01-2004
authors : Andreas Wildauer (CERN PH-ATC), Fredrik Akesson (CERN PH-ATC)
email : andreas.wildauer@cern.ch, fredrik.akesson@cern.ch
changes :
***************************************************************************/
#ifndef InDetVxLinksToTrackParticles_InDetVxLinksToTrackParticles_H
#define InDetVxLinksToTrackParticles_InDetVxLinksToTrackParticles_H
#include "AthenaBaseComps/AthAlgorithm.h"
#include "GaudiKernel/ToolHandle.h"
/**
* A non-so-simple algorithm setting the links from
* xAOD::TrackParticles to xAOD::Vertices correctly.
*
* Kirill Prokofiev, March 2014
*/
namespace InDet
{
class IVertexFinder;
class InDetVxLinksToTrackParticles : public AthAlgorithm
{
public:
InDetVxLinksToTrackParticles(const std::string &name, ISvcLocator *pSvcLocator);
StatusCode initialize();
StatusCode execute();
StatusCode finalize();
private:
std::string m_verticesName; //!< Name of the vertex container
std::string m_tracksName; //!< Name of the track container
};//end of class
}//end of namespace definitions
#endif
package InDetPriVxFinder
author Andreas Wildauer <andreas.wildauer@cern.ch>
public
use AtlasPolicy AtlasPolicy-*
use AthenaBaseComps AthenaBaseComps-* Control
use GaudiInterface GaudiInterface-* External
private
use VxVertex VxVertex-* Tracking/TrkEvent
use TrkTrack TrkTrack-* Tracking/TrkEvent
use InDetRecToolInterfaces InDetRecToolInterfaces-* InnerDetector/InDetRecTools
use TrkVertexFitterInterfaces TrkVertexFitterInterfaces-* Tracking/TrkVertexFitter
use InDetBeamSpotService InDetBeamSpotService-* InnerDetector/InDetConditions
use TrkParticleBase TrkParticleBase-* Tracking/TrkEvent
use xAODTracking xAODTracking-* Event/xAOD
use TrkVxEdmCnv TrkVxEdmCnv-* Tracking/TrkVertexFitter
public
library InDetPriVxFinder *.cxx components/*.cxx
apply_pattern component_library
#private
#macro cppdebugflags '$(cppdebugflags_s)'
#macro_remove componentshr_linkopts "-Wl,-s"
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
/**
\mainpage InDetPriVxFinder
\section introduction Introduction:
InDetPriVxFinder is a package which contains algorithm(s) to calculate the primary vertex of
an event and to store the results to storegate. It makes use of the InDetPriVxFinderTools.
All units are in mm and MeV.
\section howitworks How it works:
The alogorithm VxPrimary.cxx reads all tracks from StoreGate, calls one of the InDetPriVxFinderTool methods, retrieves a VxContainer
and writes all info to StoreGate.
\section jobOptions The jobOptions file:
The algorithm is automaticaly configured via genConf
<ul>
<li>Specifiy the name of the track input container:<br>
<b>VxPrimary.TracksName = "Tracks";</b><br>
<i>Remark: Only Trk::Track(s) are supported - so as long as the TrkLegacy package does not change its output
name this can be left untouched.</i></li>
<li>Specify the name of the output container:<br>
<b>VxPrimary.VxCandidatesOutputName = "VxPrimaryCandidate";</b></li>
</ul>
\section used_packagesInDetPriVxFinder used packages
@htmlinclude used_packages.html
\section requirements Requirements
@include requirements
\namespace Vtx
A namespace for all vertexing packages and related stuff.
*/
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
/***************************************************************************
InDetPriVxDummyFinder.cxx - Description
-------------------
***************************************************************************/
#include "InDetPriVxFinder/InDetPriVxDummyFinder.h"
#include "InDetBeamSpotService/IBeamCondSvc.h"
// #include "VxVertex/RecVertex.h"
#include "VxVertex/VxTrackAtVertex.h"
#include "VxVertex/VxCandidate.h"
#include "VxVertex/VxContainer.h"
#include "xAODTracking/Vertex.h"
#include "xAODTracking/TrackParticle.h"
#include "xAODTracking/VertexContainer.h"
#include "xAODTracking/VertexAuxContainer.h"
#include "xAODTracking/TrackParticleContainer.h"
#include "xAODTracking/TrackParticleAuxContainer.h"
#include <vector>
namespace InDet
{
InDetPriVxDummyFinder::InDetPriVxDummyFinder ( const std::string &n, ISvcLocator *pSvcLoc )
: AthAlgorithm ( n, pSvcLoc ),
m_iBeamCondSvc("BeamCondSvc",n),
m_vxCandidatesOutputName ( "VxPrimaryCandidate" )
{
declareProperty ( "BeamPositionSvc", m_iBeamCondSvc);
declareProperty ( "VxCandidatesOutputName",m_vxCandidatesOutputName );
}
InDetPriVxDummyFinder::~InDetPriVxDummyFinder() {}
StatusCode InDetPriVxDummyFinder::initialize()
{
if ( m_iBeamCondSvc.retrieve().isFailure() )
{
msg(MSG::ERROR) << "Could not find BeamCondSvc." << endreq;
return StatusCode::FAILURE;
}
return StatusCode::SUCCESS;
}
StatusCode InDetPriVxDummyFinder::execute()
{
xAOD::VertexContainer* theVxContainer = new xAOD::VertexContainer();
xAOD::VertexAuxContainer* aux = new xAOD::VertexAuxContainer();
theVxContainer->setStore( aux );
xAOD::Vertex* dummyVertex = new xAOD::Vertex();
dummyVertex->setPosition(m_iBeamCondSvc->beamVtx().position());
dummyVertex->setCovariancePosition(m_iBeamCondSvc->beamVtx().covariancePosition());
dummyVertex->setVertexType(xAOD::VxType::NoVtx);
theVxContainer->push_back ( dummyVertex );
//---- Recording section: write the results to StoreGate ---//
if ( evtStore()->record ( theVxContainer, m_vxCandidatesOutputName,false ).isFailure() )
{
if (msgLvl(MSG::ERROR)) msg() << "Unable to record Vertex Container in StoreGate" << endreq;
return StatusCode::FAILURE;
}
return StatusCode::SUCCESS;
}
StatusCode InDetPriVxDummyFinder::finalize()
{
return StatusCode::SUCCESS;
}
} // end namespace InDet
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
/***************************************************************************
InDetPriVxFinder.cxx - Description
-------------------
begin : 28-01-2004
authors : Andreas Wildauer (CERN PH-ATC), Fredrik Akesson (CERN PH-ATC)
email : andreas.wildauer@cern.ch, fredrik.akesson@cern.ch
changes :
***************************************************************************/
#include "InDetPriVxFinder/InDetPriVxFinder.h"
// forward declares
#include "InDetRecToolInterfaces/IVertexFinder.h"
#include "TrkVertexFitterInterfaces/IVertexCollectionSortingTool.h"
#include "xAODTracking/Vertex.h"
#include "xAODTracking/TrackParticle.h"
#include "xAODTracking/VertexContainer.h"
#include "xAODTracking/VertexAuxContainer.h"
#include "xAODTracking/TrackParticleContainer.h"
#include "xAODTracking/TrackParticleAuxContainer.h"
// normal includes
#include "TrkTrack/TrackCollection.h"
#include "VxVertex/VxContainer.h"
#include "TrkParticleBase/TrackParticleBaseCollection.h"
#include "TrkVxEdmCnv/IVxCandidateXAODVertex.h"
namespace InDet
{
InDetPriVxFinder::InDetPriVxFinder ( const std::string &n, ISvcLocator *pSvcLoc )
: AthAlgorithm ( n, pSvcLoc ),
m_tracksName ( "Tracks" ),
m_vxCandidatesOutputName ( "PrimaryVertices" ),
m_vxCandidatesOutputNameAuxPostfix ( "Aux." ),
m_VertexFinderTool ( "InDet::InDetPriVxFinderTool" ),
m_VertexCollectionSortingTool ("Trk::VertexCollectionSortingTool"),
m_VertexEdmFactory("Trk::VertexInternalEdmFactory"),
m_doVertexSorting(false),
// for summary output at the end
m_numEventsProcessed(0),
m_totalNumVerticesWithoutDummy(0)
{
declareProperty ( "TracksName",m_tracksName );
declareProperty ( "VxCandidatesOutputName",m_vxCandidatesOutputName );
declareProperty ( "VxCandidatesOutputNameAuxPostfix",m_vxCandidatesOutputNameAuxPostfix );
declareProperty ( "VertexFinderTool",m_VertexFinderTool );
declareProperty ( "VertexCollectionSortingTool",m_VertexCollectionSortingTool );
declareProperty ( "InternalEdmFactory", m_VertexEdmFactory);
declareProperty ( "doVertexSorting",m_doVertexSorting );
}
InDetPriVxFinder::~InDetPriVxFinder()
{}
StatusCode InDetPriVxFinder::initialize()
{
/* Get the VertexFinderTool */
if ( m_VertexFinderTool.retrieve().isFailure() )
{
msg(MSG::FATAL) << "Failed to retrieve tool " << m_VertexFinderTool << endreq;
return StatusCode::FAILURE;
}
else
{
msg(MSG::INFO) << "Retrieved tool " << m_VertexFinderTool << endreq;
}
/*Get the Vertex Collection Sorting Tool*/
if (m_doVertexSorting)
{
if ( m_VertexCollectionSortingTool.retrieve().isFailure() )
{
msg(MSG::FATAL) << "Failed to retrieve tool " << m_VertexCollectionSortingTool << endreq;
return StatusCode::FAILURE;
}
else
{
msg(MSG::INFO) << "Retrieved tool " << m_VertexCollectionSortingTool << endreq;
}
}
if ( m_VertexEdmFactory.retrieve().isFailure() ) {
ATH_MSG_ERROR("Failed to retrievel tool " << m_VertexEdmFactory);
return StatusCode::FAILURE;
}
msg(MSG::INFO) << "Initialization successful" << endreq;
return StatusCode::SUCCESS;
}
StatusCode InDetPriVxFinder::execute()
{
m_numEventsProcessed++;
VxContainer* theVxContainer ( 0 );
std::pair<xAOD::VertexContainer *, xAOD::VertexAuxContainer*> theXAODContainer;
//---- First try if m_tracksName is a TrackCollection -----------------//
if ( evtStore()->contains<TrackCollection> ( m_tracksName ) )
{
const TrackCollection *trackTES ( 0 );
if ( evtStore()->retrieve ( trackTES, m_tracksName ).isFailure() )
{
if (msgLvl(MSG::DEBUG)) msg() << "Could not find TrackCollection " << m_tracksName << " in StoreGate." << endreq;
return StatusCode::SUCCESS;
}
theVxContainer = m_VertexFinderTool->findVertex ( trackTES );
}
//---- Second try if m_tracksName is a xAOD::TrackParticleContainer ----//
else if ( evtStore()->contains<xAOD::TrackParticleContainer> ( m_tracksName ) )
{
const xAOD::TrackParticleContainer *trackParticleCollection(0);
if ( evtStore()->retrieve ( trackParticleCollection, m_tracksName ).isFailure() )
{
if (msgLvl(MSG::DEBUG)) msg() << "Could not find xAOD::TrackParticleContainer " << m_tracksName << " in StoreGate." << endreq;
return StatusCode::SUCCESS;
}
theXAODContainer = m_VertexFinderTool->findVertex ( trackParticleCollection );
}
//---- Third try if m_tracksName is a TrackParticleBaseCollection ----//
else if ( evtStore()->contains<Trk::TrackParticleBaseCollection> ( m_tracksName ) )
{
const Trk::TrackParticleBaseCollection *trackParticleBaseCollection(0);
if ( evtStore()->retrieve ( trackParticleBaseCollection, m_tracksName ).isFailure() )
{
if (msgLvl(MSG::DEBUG)) msg() << "Could not find Trk::TrackParticleBaseCollection " << m_tracksName << " in StoreGate." << endreq;
return StatusCode::SUCCESS;
}
theVxContainer = m_VertexFinderTool->findVertex ( trackParticleBaseCollection );
}
else
{
ATH_MSG_WARNING("Neither a TrackCollection nor a xAOD::TrackParticleContainer nor a TrackParticleBaseCollection with key " << m_tracksName << " exists in StoreGate. Mp vertexing possible.");
return StatusCode::SUCCESS;
}
// now resorting the vertex container and store to SG
std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*> myVxContainer;
VxContainer* MyTrackVxContainer = 0;
if (theXAODContainer.first) {
//sort xAOD::Vertex container
if (m_doVertexSorting && theXAODContainer.first->size() > 1) {
myVxContainer = m_VertexCollectionSortingTool->sortVertexContainer(*theXAODContainer.first);
delete theXAODContainer.first; //also cleans up the aux store
delete theXAODContainer.second;
} else {
myVxContainer.first = theXAODContainer.first;
myVxContainer.second = theXAODContainer.second;
}
if (myVxContainer.first!=0) m_totalNumVerticesWithoutDummy += (myVxContainer.first->size()-1);
//---- Recording section: write the results to StoreGate ---//
if ( evtStore()->record ( myVxContainer.first, m_vxCandidatesOutputName,false ).isFailure() ) {
ATH_MSG_ERROR("Unable to record xAOD::VertexContainer in StoreGate");
return StatusCode::FAILURE;
}
if (not myVxContainer.first->hasStore()) {
ATH_MSG_WARNING("Vertex container has no associated store.");
return StatusCode::SUCCESS;
}
std::string vxContainerAuxName = m_vxCandidatesOutputName + m_vxCandidatesOutputNameAuxPostfix;
if ( evtStore()->record ( myVxContainer.second, vxContainerAuxName ).isFailure() ) {
ATH_MSG_ERROR("Unable to record xAOD::VertexAuxContainer in StoreGate");
return StatusCode::FAILURE;
}
} else if (theVxContainer) {
//sort Trk::Track container (or Rec::TrackParticle)
if (m_doVertexSorting && theVxContainer->size() > 1) {
MyTrackVxContainer = m_VertexCollectionSortingTool->sortVxContainer(*theVxContainer);
delete theVxContainer;
} else {
MyTrackVxContainer = theVxContainer;
}
if (MyTrackVxContainer!=0) m_totalNumVerticesWithoutDummy += (MyTrackVxContainer->size()-1);
//---- Recording section: write the results to StoreGate ---//
if ( evtStore()->record ( MyTrackVxContainer, m_vxCandidatesOutputName,false ).isFailure() ) {
ATH_MSG_ERROR("Unable to record Vx Container in TDS");
return StatusCode::FAILURE;
}
} else { //nor theVxContainer or theXAODContainer are valid
ATH_MSG_ERROR("Unexpected error. Invalid output containers.");
return StatusCode::FAILURE;
}
ATH_MSG_DEBUG("Successfully reconstructed " << myVxContainer.first->size()-1 << " vertices (excluding dummy)");
return StatusCode::SUCCESS;
}
StatusCode InDetPriVxFinder::finalize()
{
if (msgLvl(MSG::INFO))
{
msg() << "Summary from Primary Vertex Finder (InnerDetector/InDetRecAlgs/InDetPriVxFinder)" << endreq;
msg() << "=== " << m_totalNumVerticesWithoutDummy << " vertices recoed in " << m_numEventsProcessed << " events (excluding dummy)." << endreq;
if (m_numEventsProcessed!=0) msg() << "=== " << double(m_totalNumVerticesWithoutDummy)/double(m_numEventsProcessed) << " vertices per event (excluding dummy)." << endreq;
}
return StatusCode::SUCCESS;
}
} // end namespace InDet
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
/***************************************************************************
InDetVxLinksToTrackParticles.cxx - Description
-------------------
begin : 19-03-2014
authors; Kirill.Prokofiev@cern.ch
***************************************************************************/
#include "InDetPriVxFinder/InDetVxLinksToTrackParticles.h"
#include "xAODTracking/Vertex.h"
#include "xAODTracking/TrackParticle.h"
#include "xAODTracking/VertexContainer.h"
#include "xAODTracking/TrackParticleContainer.h"
namespace InDet
{
InDetVxLinksToTrackParticles::
InDetVxLinksToTrackParticles( const std::string &n, ISvcLocator *pSvcLoc )
: AthAlgorithm( n, pSvcLoc ),
m_verticesName( "PrimaryVertices" ),
m_tracksName( "TrackParticles" )
{
declareProperty ( "VerticesName",m_verticesName );
declareProperty ( "TracksName", m_tracksName );
}
StatusCode InDetVxLinksToTrackParticles::initialize()
{
ATH_MSG_INFO( "Initializing - Package version: " << PACKAGE_VERSION );
return StatusCode::SUCCESS;
}
StatusCode InDetVxLinksToTrackParticles::execute()
{
//non-const access to the container
xAOD::TrackParticleContainer* trackParticleCollection( 0 );
if( ! evtStore()->transientContains< xAOD::TrackParticleContainer >( m_tracksName ) ) {
ATH_MSG_WARNING( "No modifyable xAOD::TrackParticleContainer "
<< "with key \"" << m_tracksName << "\" found" );
return StatusCode::SUCCESS;
}
ATH_CHECK( evtStore()->retrieve( trackParticleCollection,
m_tracksName ) );
const xAOD::VertexContainer* vertexCollection( 0 );
if( ! evtStore()->contains< xAOD::VertexContainer >( m_verticesName ) ) {
ATH_MSG_WARNING( "No xAOD::VertexContainer with key \""
<< m_verticesName << "\" found" );
return StatusCode::SUCCESS;
}
ATH_CHECK( evtStore()->retrieve( vertexCollection, m_verticesName ) );
// Iterating over the vertex container in the evt Store
const size_t nvx = vertexCollection->size();
for( size_t i = 0; i < nvx; ++i )
{
const std::vector< ElementLink< xAOD::TrackParticleContainer > >&
tpLinks = ( *vertexCollection )[ i ]->trackParticleLinks();
ElementLink< xAOD::VertexContainer > link;
link.resetWithKeyAndIndex( m_verticesName, i );
//iterating over the links
const size_t tp_size = tpLinks.size();
for( size_t tp = 0; tp < tp_size; ++tp )
{
const ElementLink< xAOD::TrackParticleContainer >& tpl =
tpLinks[ tp ];
// Skip invalid element links:
if( ! tpl.isValid() )
{
ATH_MSG_WARNING( "Invalid ElementLink found on "
<< "vertex number " << i );
continue;