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

'CMakeLists.txt' (TrkVertexFitterValidationUtils-00-03-04)

parent bc2b8c16
################################################################################
# Package: TrkVertexFitterValidationUtils
################################################################################
# Declare the package name:
atlas_subdir( TrkVertexFitterValidationUtils )
# Declare the package's dependencies:
atlas_depends_on_subdirs( PUBLIC
Control/AthenaBaseComps
GaudiKernel
PRIVATE
Generators/GeneratorObjects
Reconstruction/ParticleTruth
Tracking/TrkEvent/TrkParticleBase
Tracking/TrkEvent/VxVertex )
# External dependencies:
find_package( HepMC )
# Component(s) in the package:
atlas_add_library( TrkVertexFitterValidationUtilsLib
src/*.cxx
PUBLIC_HEADERS TrkVertexFitterValidationUtils
PRIVATE_INCLUDE_DIRS ${HEPMC_INCLUDE_DIRS}
LINK_LIBRARIES AthenaBaseComps GaudiKernel
PRIVATE_LINK_LIBRARIES ${HEPMC_LIBRARIES} GeneratorObjects ParticleTruth TrkParticleBase VxVertex )
atlas_add_component( TrkVertexFitterValidationUtils
src/components/*.cxx
INCLUDE_DIRS ${HEPMC_INCLUDE_DIRS}
LINK_LIBRARIES ${HEPMC_LIBRARIES} AthenaBaseComps GaudiKernel GeneratorObjects ParticleTruth TrkParticleBase VxVertex TrkVertexFitterValidationUtilsLib )
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef TRKVERTEXFITTERVALIDATIONUTILS_TRKPRIVXPURITY_H
#define TRKVERTEXFITTERVALIDATIONUTILS_TRKPRIVXPURITY_H
#include <vector>
#include "GaudiKernel/MsgStream.h"
/**
* @class Trk::TrkPriVxPurity
*
* A prototype data class for primary vertex purity.
* Provides a truth information summary about the fitted
* primary vertex:
*
* -- Number tracks fitted to the vertex
*
* -- Number of tracks w/o original info stored
*
* -- Number of tracks w/o truth associated:
* While the PU navigation is not available, this
* number includes both fake reconstructed and pileup tracks
*
* -- Vector of weights for tracks fitted to the vertex, but
* originating elswhere:
* So far these are only signal event outliers, products of decay of
* long-living particles, conversions and do on... Once the PU truth
* navigation is available, these will also be tracks coming from PU.
*
* -- Vector of weights of tracks w.r.t. fitted vertex
*
* @author Kirill Prokofiev, October 2006.
*/
namespace Trk
{
class TrkPriVxPurity
{
public:
/**
* Constructor, requiring a number of fitted tracks, wectors of weghts
* for inlyers, outlyers, pileup tracks and tracks with no truth
* association. Number of tracks with broken links to the truth
* (possible software bugs) is also stored.
*/
TrkPriVxPurity(int ntrk, const std::vector<double> puWeights,
const std::vector<double> noTruth,
int brLinks, const std::vector<double> inWeights,
const std::vector<double> outWeights);
/**
* Destructor
*/
~TrkPriVxPurity(){}
/**
* Number of fitted tracks
*/
unsigned int fittedTracks() const;
/**
* Weights of tracks from pileUp events
*/
const std::vector<double> pileUpWeights() const;
/**
* Weights of not associated tracks
*/
const std::vector<double> noTruthFound() const;
/**
* Number of lost pointers: these must software bugs if any
*/
unsigned int brokenLinks() const;
/**
* List of track weights for inliers (only tracks from signal event are listed)
*/
const std::vector<double> inlierWeights()const;
/**
* List of track weights for outliers (only tracks from the signal event are listed)
*/
const std::vector<double> outlierWeights()const;
/**
* Dump info method
*/
MsgStream& dump(MsgStream& sl) const;
/**
* Dump info method
*/
std::ostream& dump(std::ostream& sl) const;
private:
unsigned int m_fittedTracks;
std::vector<double> m_puWeights;
std::vector<double> m_noTruth;
unsigned int m_brokenLinks;
std::vector<double> m_inWeights;
std::vector<double> m_outWeights;
};
inline unsigned int TrkPriVxPurity::fittedTracks() const
{ return m_fittedTracks; }
inline const std::vector<double> TrkPriVxPurity::noTruthFound() const
{ return m_noTruth; }
inline const std::vector<double> TrkPriVxPurity::outlierWeights()const
{ return m_outWeights; }
inline const std::vector<double> TrkPriVxPurity::inlierWeights()const
{ return m_inWeights; }
inline unsigned int TrkPriVxPurity::brokenLinks() const
{return m_brokenLinks; }
inline const std::vector<double> TrkPriVxPurity::pileUpWeights() const
{return m_puWeights; }
}// end of namespace definitions
#endif
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef TRKVERTEXFITTERVALIDATIONUTILS_TRKPRIVXPURITYTOOL_H
#define TRKVERTEXFITTERVALIDATIONUTILS_TRKPRIVXPURITYTOOL_H
/**
* @class Trk::TrkPriVxPurityTool
*
* A tool estimating the purity of the reconstructed
* primary vertex. The Generator level tracks,
* corresponding to those fitted to the primary
* vertex candidate are examined. The fraction
* of outliers fitted to the vertex and tracks
* originating from the pileup is determined.
*
* @authpr Kirill Prokofiev, September 2006
*/
#include "AthenaBaseComps/AthAlgTool.h"
namespace Trk
{
static const InterfaceID IID_TrkPriVxPurityTool("TrkPriVxPurityTool", 1, 0);
class VxCandidate;
class TrkPriVxPurity;
class TrkPriVxPurityTool : public AthAlgTool
{
public:
/**
* AlgTool method
*/
StatusCode initialize();
/**
* AlgTool method
*/
StatusCode finalize();
/**
* AlgTool constructor
*/
TrkPriVxPurityTool(const std::string& t, const std::string& n, const IInterface* p);
/**
* AlgTool destructor
*/
virtual ~TrkPriVxPurityTool();
/**
* AlgTool interface method
*/
static const InterfaceID& interfaceID(){ return IID_TrkPriVxPurityTool; }
/**
* Actual analysis method, returning a Trk::TrkPriVxPurity object for a
* given TrkVxCandidate
*/
const TrkPriVxPurity * purity(const Trk::VxCandidate * vertex) const;
private:
/**
* Primary vertex definition for MC: tolerances taken in r (mm)
* around the simulated point of proton-proton interaction.
* All the vertices in this region will be merged to form a single
* simulated PV with associated charged tracks.
*/
double m_r_tol;
/**
* Primary vertex definition for MC: tolerances taken in z (mm)
* around the simulated point of proton-proton interaction.
* All the vertices in this region will be merged to form a single
* simulated PV with associated charged tracks.
*/
double m_z_tol;
/**
* Name of the track true <-> rec map to be read from the storegate
*/
std::string m_trackParticleTruthCollName;
/**
* Name of the MC event collection to read
*/
std::string m_mc_collection_name;
};//end of class definitions
}//end of namespace definitions
#endif
#########################################################
# TrkVertexFitterValidationUtils package
# A set of tools suitable for estimation of
# vertex purity, association of reconstructed
# vertices to the generated ones and so on.
#
# Kirill Prokofiev, September 2006
#
# 2006-12-20 Checkreq fixes
#
#########################################################
package TrkVertexFitterValidationUtils
author <Kirill.Prokofiev@cern.ch>
public
use AtlasPolicy AtlasPolicy-*
use GaudiInterface GaudiInterface-* External
use AthenaBaseComps AthenaBaseComps-* Control
private
use AtlasHepMC AtlasHepMC-* External
use VxVertex VxVertex-* Tracking/TrkEvent
use TrkParticleBase TrkParticleBase-* Tracking/TrkEvent
use ParticleTruth ParticleTruth-* Reconstruction
use GeneratorObjects GeneratorObjects-* Generators
public
apply_pattern dual_use_library files=*.cxx
#################################################
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
/**
@mainpage TrkVertexFitterValidationUtils Package
@author Kirill.Prokofiev@cern.ch
\section introTrkVertexFitterValidationUtils Introduction
This package is designed to contain a set of helper
utils suitable for the estimation of efficiency of
primary vertex reconstruction.
\section designTrkVertexFitterValidationUtils Design
<b><i>Trk::TrkPriVxPurity </i></b>
A storage object designed
to save the results of the purity analysy of reconstructed primary
vertex.
<br><br>
<b><i>Trk::TrkPriVxPurityTool</i></b>
A tool retrieveing all
the purity information about the primary vertex candidate:
number of correct tracks and their weights, number of
pileup tracks and their weight etc.. The outlyer tracks are
defined as those coming from vertexes in the configurable region
around a primary collision in Monte Carlo.
\section requirementsTrkVertexFitterValidationUtils Requirements
@htmlinclude used_packages.html
@include requirements
*/
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "TrkVertexFitterValidationUtils/TrkPriVxPurity.h"
namespace Trk
{
TrkPriVxPurity::TrkPriVxPurity(int ntrk, const std::vector<double> puWeights,
const std::vector<double> noTruth,
int brLinks, const std::vector<double> inWeights,
const std::vector<double> outWeights):
m_fittedTracks(ntrk), m_puWeights(puWeights),
m_noTruth(noTruth),m_brokenLinks(brLinks),
m_inWeights(inWeights),
m_outWeights(outWeights)
{}
//dump methods
MsgStream& TrkPriVxPurity::dump(MsgStream& sl) const
{
sl<<"***** Primary Vertex Purity Info *****"<<std::endl;
sl<<"Total number of fitted tracks "<<m_fittedTracks<<std::endl;
sl<<"Number of track with internally broken links "<<m_brokenLinks<<std::endl;
if(0!=m_inWeights.size())
{
sl<<"The weights of inlier tracks: ";
std::vector<double>::const_iterator i = m_inWeights.begin();
for(;i!=m_inWeights.end();++i) sl<<*i<<" ";
sl<<std::endl;
}
if(0!=m_outWeights.size())
{
sl<<"The weights of outlier tracks: ";
std::vector<double>::const_iterator i = m_outWeights.begin();
for(;i!=m_outWeights.end();++i) sl<<*i<<" ";
sl<<std::endl;
}
if(0!=m_puWeights.size())
{
sl<<"The weights of tracks from PileUp: ";
std::vector<double>::const_iterator i = m_puWeights.begin();
for(;i!=m_puWeights.end();++i) sl<<*i<<" ";
sl<<std::endl;
}
if(0!=m_noTruth.size())
{
sl<<"The weights of tracks w/o truth matching: ";
std::vector<double>::const_iterator i = m_noTruth.begin();
for(;i!=m_noTruth.end();++i) sl<<*i<<" ";
sl<<std::endl;
}
return sl;
}// end of msg stream dump method
std::ostream& TrkPriVxPurity:: dump(std::ostream& sl) const
{
sl<<"***** Primary Vertex Purity Info *****"<<std::endl;
sl<<"Total number of fitted tracks "<<m_fittedTracks<<std::endl;
sl<<"Number of track with internally broken links "<<m_brokenLinks<<std::endl;
if(0!=m_inWeights.size())
{
sl<<"The weights of inlier tracks: ";
std::vector<double>::const_iterator i = m_inWeights.begin();
for(;i!=m_inWeights.end();++i) sl<<*i<<" ";
sl<<std::endl;
}
if(0!=m_outWeights.size())
{
sl<<"The weights of outlier tracks: ";
std::vector<double>::const_iterator i = m_outWeights.begin();
for(;i!=m_outWeights.end();++i) sl<<*i<<" ";
sl<<std::endl;
}
if(0!=m_puWeights.size())
{
sl<<"The weights of tracks from PileUp: ";
std::vector<double>::const_iterator i = m_puWeights.begin();
for(;i!=m_puWeights.end();++i) sl<<*i<<" ";
sl<<std::endl;
}
if(0!=m_noTruth.size())
{
sl<<"The weights of tracks w/o truth matching: ";
std::vector<double>::const_iterator i = m_noTruth.begin();
for(;i!=m_noTruth.end();++i) sl<<*i<<" ";
sl<<std::endl;
}
return sl;
}//end of ostream dump method
}//end of namespace definitions
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "TrkVertexFitterValidationUtils/TrkPriVxPurityTool.h"
// forward includes
#include "TrkVertexFitterValidationUtils/TrkPriVxPurity.h"
#include "VxVertex/VxCandidate.h"
// normal includes
#include "GeneratorObjects/HepMcParticleLink.h"
#include "GeneratorObjects/McEventCollection.h"
#include "HepMC/GenParticle.h"
#include "HepMC/GenVertex.h"
#include "HepMC/GenEvent.h"
#include "VxVertex/VxTrackAtVertex.h"
#include "TrkParticleBase/LinkToTrackParticleBase.h"
#include "ParticleTruth/TrackParticleTruthCollection.h"
#include "ParticleTruth/TrackParticleTruthKey.h"
#include "ParticleTruth/TrackParticleTruth.h"
#include <map>
#include <vector>
namespace Trk {
StatusCode TrkPriVxPurityTool::initialize() {
return StatusCode::SUCCESS;
}//end of initialize method
StatusCode TrkPriVxPurityTool::finalize() {
msg(MSG::INFO) << "Finalize successful" << endreq;
return StatusCode::SUCCESS;
}
TrkPriVxPurityTool::TrkPriVxPurityTool ( const std::string& t, const std::string& n, const IInterface* p ) : AthAlgTool ( t,n,p ) {
//tolerances around the signal pp interaction to create a primary vertex candidate:
//defaul values are: sigma z = 1um (0.001 mm), sigma r = 1um (0.001 mm)
declareProperty ( "VertexRTolerance", m_r_tol = 0.001 );
declareProperty ( "VertexZTolerance", m_z_tol = 0.001 );
//name of the rec <-> sim truth map to be read from the storegate
//default one is the output of the InDetTrackTruthMaker (see InDetTruthAlgs in InnerDetector packasge)
declareProperty ( "SimTrackMapName", m_trackParticleTruthCollName = "TrackParticleTruthCollection" );
//name of the Mc event collection. Required to get the signal event.
declareProperty ( "MonteCarloCollection", m_mc_collection_name = "TruthEvent" );
// declaring the interface fo the tool itself
declareInterface<TrkPriVxPurityTool> ( this );
}//end of constructor
TrkPriVxPurityTool::~TrkPriVxPurityTool()
{}
//analysis method
const TrkPriVxPurity * TrkPriVxPurityTool::purity ( const Trk::VxCandidate * vertex ) const {
// std::cout<<" The purity method called"<<std::endl;
//protection and related
if ( vertex != 0 ) {
const std::vector<Trk::VxTrackAtVertex *> * tracks = vertex->vxTrackAtVertex();
if ( tracks !=0 ) {
// first getting the Mc Event collection
const McEventCollection * mcCollection ( 0 );
StatusCode sc = evtStore()->retrieve ( mcCollection, m_mc_collection_name );
if ( sc.isFailure() ) {
if (msgLvl(MSG::DEBUG)) {
msg() << "Unable to retrieve MC collection: " << m_mc_collection_name << endreq;
msg() << "Zero pointer returned." << endreq;
}
return 0;
}
//getting the signal event itself
McEventCollection::const_iterator it = mcCollection->begin();
const HepMC::GenEvent* genEvent= ( *it );
// std::cout<<"The ID of the first event of the collection: "<<genEvent->event_number()<<std::endl;
if( genEvent->vertices_empty() ) {
ATH_MSG_DEBUG( "No vertices found in first GenEvent" );
return 0;
}
//analysing the MC event to create PV candidate
//first finding the vertex of primary pp interaction
HepMC::GenEvent::vertex_const_iterator pv = genEvent->vertices_begin();
//and storing its position
CLHEP::HepLorentzVector pv_pos ( ( *pv )->position().x(),
( *pv )->position().y(),
( *pv )->position().z(),
( *pv )->position().t() );
double pv_r = pv_pos.perp();
double pv_z = pv_pos.z();
// std::cout<<"Purity: Primary vertex position: "<<pv_pos<<std::endl;
// storing all the ids of vertices reasonably close to the primary one.
// here the region of interest is selected.
std::map<int,HepMC::GenVertex *> vertex_ids;
for ( HepMC::GenEvent::vertex_const_iterator i = genEvent->vertices_begin();
i != genEvent->vertices_end() ;++i ) {
CLHEP::HepLorentzVector lv_pos ( ( *i )->position().x(),
( *i )->position().y(),
( *i )->position().z(),
( *i )->position().t() );
if ( fabs ( lv_pos.perp() - pv_r ) <m_r_tol && fabs ( lv_pos.z() - pv_z ) <m_z_tol ) {
vertex_ids[ ( *i )->barcode() ]= ( *i );
}//end of accepted vertices check
}//end of loop over all the vertices
// std::cout<<"Actual number of merged vertices "<<vertex_ids.size()<<std::endl;
/*-------------------Some debug output-------------------------------------------------
std::cout<<"Actual number of merged vertices "<<vertex_ids.size()<<std::endl;
for( std::map<int,HepMC::GenVertex *>::const_iterator i = vertex_ids.begin();
i != vertex_ids.end(); ++i)
{
HepMC::GenVertex * cev =(*i).second;
std::cout<<"Selected GenVertex has event index: "<<cev->parent_event()->event_number() <<std::endl;
}//end of debug loop over all the vertices
//------------------ End of debug output ------------------------------------------------
*/
//getting the track truth collection
const TrackParticleTruthCollection * trackParticleTruthCollection ( 0 );
sc = evtStore()->retrieve ( trackParticleTruthCollection, m_trackParticleTruthCollName );
if ( sc.isFailure() ) {
if (msgLvl(MSG::DEBUG)) {
msg() << "Cannot retrieve " << m_trackParticleTruthCollName << endreq;
msg() << "Zero pointer returned" << endreq;
}
return 0;
}
//looping over the tracks to find those matched to the GenParticle originating from signal PV
std::vector<Trk::VxTrackAtVertex *>::const_iterator vt = tracks->begin();