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

'CMakeLists.txt' (TrkTruthAlgs-01-05-08)

parent 91927081
################################################################################
# Package: TrkTruthAlgs
################################################################################
# Declare the package name:
atlas_subdir( TrkTruthAlgs )
# Declare the package's dependencies:
atlas_depends_on_subdirs( PUBLIC
Control/AthenaBaseComps
GaudiKernel
Tracking/TrkEvent/TrkTruthData
PRIVATE
Event/xAOD/xAODCore
Event/xAOD/xAODTracking
Generators/GeneratorObjects
PhysicsAnalysis/MCTruthClassifier
Tracking/TrkTools/TrkToolInterfaces )
# Component(s) in the package:
atlas_add_component( TrkTruthAlgs
src/*.cxx
src/components/*.cxx
LINK_LIBRARIES AthenaBaseComps GaudiKernel TrkTruthData xAODCore xAODTracking GeneratorObjects MCTruthClassifierLib TrkToolInterfaces )
# Install files from the package:
atlas_install_headers( TrkTruthAlgs )
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef TRACKTRUTHSELECTOR_H
#define TRACKTRUTHSELECTOR_H
#include <string>
#include <vector>
#include "AthenaBaseComps/AthAlgorithm.h"
#include "TrkTruthData/DetailedTrackTruthCollection.h"
#include "TrkTruthData/TrackTruthCollection.h"
class TrackTruthSelector: public AthAlgorithm {
public:
TrackTruthSelector(const std::string &name,ISvcLocator *pSvcLocator);
virtual StatusCode initialize();
virtual StatusCode execute();
virtual StatusCode finalize();
private:
// DetailedTrackTruthCollection input name
std::string m_detailedTrackTruthName;
// TrackTruthCollection output name
std::string m_outputName;
// Subdetector weights
std::vector<double> m_subDetWeights;
void fillOutput(TrackTruthCollection *out, const DetailedTrackTruthCollection *in);
double getProbability(const DetailedTrackTruth& dt) const;
};
#endif/*TRACKTRUTHSELECTOR_H*/
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef TRACKTRUTHSIMILARITYSELECTOR_H
#define TRACKTRUTHSIMILARITYSELECTOR_H
#include <string>
#include <vector>
#include "AthenaBaseComps/AthAlgorithm.h"
#include "GaudiKernel/ToolHandle.h"
#include "TrkTruthData/DetailedTrackTruthCollection.h"
#include "TrkTruthData/TrackTruthCollection.h"
namespace Trk { class IDetailedTrackTruthSimilarity; }
class TrackTruthSimilaritySelector: public AthAlgorithm {
public:
TrackTruthSimilaritySelector(const std::string &name,ISvcLocator *pSvcLocator);
virtual StatusCode initialize();
virtual StatusCode execute();
virtual StatusCode finalize();
private:
// DetailedTrackTruthCollection input name
std::string m_detailedTrackTruthName;
// TrackTruthCollection output name
std::string m_outputName;
// Match quality tool
ToolHandle<Trk::IDetailedTrackTruthSimilarity> m_matchTool;
void fillOutput(TrackTruthCollection *out, const DetailedTrackTruthCollection *in);
};
#endif/*TRACKTRUTHSIMILARITYSELECTOR_H*/
package TrkTruthAlgs
author Kelly Braun <kelliopia@aol.com>
author Steven Goldfarb <Steven.Goldfarb@cern.ch>
use AtlasPolicy AtlasPolicy-*
use GaudiInterface GaudiInterface-* External
use AthenaBaseComps AthenaBaseComps-* Control
use TrkTruthData TrkTruthData-* Tracking/TrkEvent
apply_pattern component_library
library TrkTruthAlgs *.cxx components/*.cxx
private
use TrkToolInterfaces TrkToolInterfaces-* Tracking/TrkTools
use GeneratorObjects GeneratorObjects-* Generators
use xAODTracking xAODTracking-* Event/xAOD
#use xAODTruth xAODTruth-* Event/xAOD
use xAODCore xAODCore-* Event/xAOD
use MCTruthClassifier MCTruthClassifier-* PhysicsAnalysis
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "TrackParticleTruthAlg.h"
#include "TrkTruthData/TrackTruthCollection.h"
#include "TrkTruthData/TrackTruthKey.h"
#include "GeneratorObjects/xAODTruthParticleLink.h"
#include "xAODTracking/TrackParticleContainer.h"
#include "xAODCore/AuxStoreAccessorMacros.h"
#include "GeneratorObjects/McEventCollection.h"
#include "MCTruthClassifier/IMCTruthClassifier.h"
TrackParticleTruthAlg::TrackParticleTruthAlg(const std::string &name,ISvcLocator *pSvcLocator) :
AthAlgorithm(name,pSvcLocator),
m_truthClassifier("MCTruthClassifier/MCTruthClassifier")
{
declareProperty("MCTruthClassifier", m_truthClassifier);
declareProperty("TrackTruthName", m_truthName="TrackTruthCollection");
declareProperty("TrackParticleName", m_trackParticleName="InDetTrackParticles");
declareProperty("xAODTruthLinkVector",m_truthLinkVecName="xAODTruthLinks");
}
// -----------------------------------------------------------------------------------------------------
StatusCode TrackParticleTruthAlg::initialize()
{
ATH_CHECK(m_truthClassifier.retrieve());
return StatusCode::SUCCESS;
}
// -----------------------------------------------------------------------------------------------------
StatusCode TrackParticleTruthAlg::finalize() {
return StatusCode::SUCCESS;
}
// -----------------------------------------------------------------------------------------------------
StatusCode TrackParticleTruthAlg::execute() {
xAOD::TrackParticleContainer* particles = 0;
if(evtStore()->contains<xAOD::TrackParticleContainer>(m_trackParticleName)){
ATH_CHECK(evtStore()->retrieve(particles, m_trackParticleName));
}else return StatusCode::SUCCESS;
const xAODTruthParticleLinkVector* truthParticleLinkVec = 0;
if(evtStore()->contains<xAODTruthParticleLinkVector>(m_truthLinkVecName)){
ATH_CHECK(evtStore()->retrieve(truthParticleLinkVec, m_truthLinkVecName));
}else return StatusCode::SUCCESS;
const TrackTruthCollection* truthTracks = 0;
// Retrieve the input
if( evtStore()->contains<TrackTruthCollection>(m_truthName)){
ATH_CHECK(evtStore()->retrieve(truthTracks, m_truthName));
}else return StatusCode::SUCCESS;
for( auto particle : *particles ){
if( !particle->trackLink().isValid() ){
ATH_MSG_WARNING("Found TrackParticle with Invalid element link, skipping");
continue;
}
ATH_MSG_DEBUG("Looking up truth for pt " << particle->pt() << " eta " << particle->eta() << " phi " << particle->phi());
MCTruthPartClassifier::ParticleType type = MCTruthPartClassifier::Unknown;
MCTruthPartClassifier::ParticleOrigin origin = MCTruthPartClassifier::NonDefined;
ElementLink<xAOD::TruthParticleContainer> link;
// look-up associdated truth particle
Trk::TrackTruthKey key(particle->trackLink());
auto result = truthTracks->find(key);
// if we found a match use it
if( result != truthTracks->end() ){
ATH_MSG_VERBOSE("Found track Truth: barcode " << result->second.particleLink().barcode() << " evt " << result->second.particleLink().eventIndex());
link = truthParticleLinkVec->find(result->second.particleLink());
// if configured also get truth classification
if( link.isValid()&& !m_truthClassifier.empty() ){
auto truthClass = m_truthClassifier->particleTruthClassifier(*link);
type = truthClass.first;
origin = truthClass.second;
ATH_MSG_VERBOSE("Got truth type " << static_cast<int>(type) << " origin " << static_cast<int>(origin));
}
}
ElementLink<xAOD::TruthParticleContainer>& theLink = particle->auxdata<ElementLink<xAOD::TruthParticleContainer> >("truthParticleLink" );
if( link.isValid() ){
ATH_MSG_DEBUG("Found matching xAOD Truth: barcode " << (*link)->barcode() << " pt " << (*link)->pt() << " eta " << (*link)->eta() << " phi " << (*link)->phi());
// set element link
link.toPersistent();
theLink = link;
}
if( !m_truthClassifier.empty() ){
particle->auxdata<int>("truthType") = static_cast<int>(type);
particle->auxdata<int>("truthOrigin") = static_cast<int>(origin);
}
}
return StatusCode::SUCCESS;
}
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef TRACKPARTICLETRUTHALG_H
#define TRACKPARTICLETRUTHALG_H
#include <string>
#include <vector>
#include "AthenaBaseComps/AthAlgorithm.h"
#include "GaudiKernel/ToolHandle.h"
class IMCTruthClassifier;
class TrackParticleTruthAlg: public AthAlgorithm {
public:
TrackParticleTruthAlg(const std::string &name,ISvcLocator *pSvcLocator);
virtual StatusCode initialize();
virtual StatusCode execute();
virtual StatusCode finalize();
private:
std::string m_truthName; /// Track(Particle)TruthCollection input name
std::string m_trackParticleName; /// TrackParticle input name
std::string m_truthLinkVecName; /// link vector to map HepMC onto xAOD truth
ToolHandle<IMCTruthClassifier> m_truthClassifier;
};
#endif/*TRACKTRUTHSELECTOR_H*/
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "TrkTruthAlgs/TrackTruthSelector.h"
TrackTruthSelector::TrackTruthSelector(const std::string &name,ISvcLocator *pSvcLocator) :
AthAlgorithm(name,pSvcLocator),
m_subDetWeights(SubDetHitStatistics::NUM_SUBDETECTORS, 1.)
{
declareProperty("DetailedTrackTruthName", m_detailedTrackTruthName="DetailedTrackTruth");
declareProperty("OutputName", m_outputName="TrackTruthNew");
declareProperty("WeightPixel", m_subDetWeights[SubDetHitStatistics::Pixel]);
declareProperty("WeightSCT", m_subDetWeights[SubDetHitStatistics::SCT]);
declareProperty("WeightTRT", m_subDetWeights[SubDetHitStatistics::TRT]);
declareProperty("WeightMDT", m_subDetWeights[SubDetHitStatistics::MDT]);
declareProperty("WeightRPC", m_subDetWeights[SubDetHitStatistics::RPC]);
declareProperty("WeightTGC", m_subDetWeights[SubDetHitStatistics::TGC]);
declareProperty("WeightCSC", m_subDetWeights[SubDetHitStatistics::CSC]);
}
// -----------------------------------------------------------------------------------------------------
StatusCode TrackTruthSelector::initialize()
{
ATH_MSG_INFO ("TrackTruthSelector::initialize()");
return StatusCode::SUCCESS;
}
// -----------------------------------------------------------------------------------------------------
StatusCode TrackTruthSelector::finalize() {
ATH_MSG_INFO ("TrackTruthSelector finalized");
return StatusCode::SUCCESS;
}
// -----------------------------------------------------------------------------------------------------
StatusCode TrackTruthSelector::execute() {
ATH_MSG_DEBUG ("TrackTruthSelector::execute()");
StatusCode sc;
//----------------------------------------------------------------
// Retrieve the input
const DetailedTrackTruthCollection *detailed = 0;
sc = evtStore()->retrieve(detailed, m_detailedTrackTruthName);
if (sc.isFailure()){
ATH_MSG_WARNING ("DetailedTrackTruthCollection "<<m_detailedTrackTruthName<<" NOT found");
return StatusCode::SUCCESS;
} else {
ATH_MSG_DEBUG ("Got DetailedTrackTruthCollection "<<m_detailedTrackTruthName);
}
//----------------------------------------------------------------
// Produce and store the output.
TrackTruthCollection *out = new TrackTruthCollection(detailed->trackCollectionLink());
fillOutput(out, detailed);
sc=evtStore()->record(out, m_outputName, false);
if (sc.isFailure()) {
ATH_MSG_ERROR ("TrackTruthCollection '" << m_outputName << "' could not be registered in StoreGate !");
return StatusCode::FAILURE;
} else {
ATH_MSG_DEBUG ("TrackTruthCollection '" << m_outputName << "' is registered in StoreGate, size="<<out->size());
}
return StatusCode::SUCCESS;
}
//================================================================
void TrackTruthSelector::fillOutput(TrackTruthCollection *out,
const DetailedTrackTruthCollection *in)
{
typedef DetailedTrackTruthCollection::const_iterator Iter;
Iter itrackData=in->begin();
while(itrackData!=in->end()) {
std::pair<Iter,Iter> range = in->equal_range(itrackData->first);
// We KNOW that the range is not empty - no need to check that.
Iter selected = range.first;
double bestProb = getProbability(selected->second);
ATH_MSG_VERBOSE ("track=" << selected->first.index() << " prob=" << bestProb << " link: " << *(selected->second.trajectory().rbegin()));
for(Iter imatch = ++range.first; imatch != range.second; imatch++) {
double prob = getProbability(imatch->second);
ATH_MSG_VERBOSE ("track=" << imatch->first.index() << " prob=" << prob << " link: " << *(imatch->second.trajectory().rbegin()));
if(prob>bestProb) {
bestProb = prob;
selected = imatch;
}
}
// trajectory[0] is the LAST particle on the trajectory. The first
// is at trajectory.rbegin(), but different trajectories can have
// the same first particle.
// const HepMcParticleLink& particleLink = selected->second.trajectory()[0];
const HepMcParticleLink& particleLink = *(selected->second.trajectory().rbegin());
ATH_MSG_DEBUG ("Truth selected for track=" << selected->first.index() << " prob=" << bestProb << " link: " << particleLink);
out->insert(std::make_pair(selected->first, TrackTruth(particleLink, bestProb, 0) ));
itrackData=range.second;
}
}
//================================================================
double TrackTruthSelector::getProbability(const DetailedTrackTruth& dt) const
{
double prd_track=0, prd_common=0;
for(unsigned i=0; i<SubDetHitStatistics::NUM_SUBDETECTORS; i++) {
prd_common += m_subDetWeights[i] * dt.statsCommon()[SubDetHitStatistics::SubDetType(i)];
prd_track += m_subDetWeights[i] * dt.statsTrack()[SubDetHitStatistics::SubDetType(i)];
}
return (prd_track>0)? prd_common/prd_track : -1.;
}
//================================================================
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "TrkTruthAlgs/TrackTruthSimilaritySelector.h"
#include "TrkToolInterfaces/IDetailedTrackTruthSimilarity.h"
TrackTruthSimilaritySelector::TrackTruthSimilaritySelector(const std::string &name,ISvcLocator *pSvcLocator)
: AthAlgorithm(name,pSvcLocator)
, m_matchTool("Trk::TruthMatchRatio")
{
declareProperty("TrackTruthSimilarityTool", m_matchTool, "Track-truth similarity tool");
declareProperty("DetailedTrackTruthName", m_detailedTrackTruthName="DetailedTrackTruth");
declareProperty("OutputName", m_outputName="TrackTruthNew");
}
// -----------------------------------------------------------------------------------------------------
StatusCode TrackTruthSimilaritySelector::initialize()
{
ATH_MSG_INFO ("TrackTruthSimilaritySelector::initialize(), output " << m_outputName);
return StatusCode::SUCCESS;
}
// -----------------------------------------------------------------------------------------------------
StatusCode TrackTruthSimilaritySelector::finalize() {
ATH_MSG_INFO ("TrackTruthSimilaritySelector finalized");
return StatusCode::SUCCESS;
}
// -----------------------------------------------------------------------------------------------------
StatusCode TrackTruthSimilaritySelector::execute() {
ATH_MSG_DEBUG ("TrackTruthSimilaritySelector::execute()");
StatusCode sc;
//----------------------------------------------------------------
// Retrieve the input
const DetailedTrackTruthCollection *detailed = 0;
sc = evtStore()->retrieve(detailed, m_detailedTrackTruthName);
if (!sc.isSuccess()){
ATH_MSG_ERROR ("DetailedTrackTruthCollection "<<m_detailedTrackTruthName<<" NOT found");
return sc;
} else {
ATH_MSG_DEBUG ("Got DetailedTrackTruthCollection "<<m_detailedTrackTruthName);
}
//----------------------------------------------------------------
// Produce and store the output.
TrackTruthCollection *out = new TrackTruthCollection(detailed->trackCollectionLink());
fillOutput(out, detailed);
sc=evtStore()->record(out, m_outputName, false);
if (!sc.isSuccess()) {
ATH_MSG_ERROR ("TrackTruthCollection '"<<m_outputName<<"' could not be registered in StoreGate !");
return sc;
} else {
ATH_MSG_DEBUG ("TrackTruthCollection '"<<m_outputName<<"' is registered in StoreGate, size="<<out->size());
}
return StatusCode::SUCCESS;
}
//================================================================
void TrackTruthSimilaritySelector::fillOutput(TrackTruthCollection *out,
const DetailedTrackTruthCollection *in)
{
typedef DetailedTrackTruthCollection::const_iterator Iter;
Iter itrackData=in->begin();
while(itrackData!=in->end()) {
std::pair<Iter,Iter> range = in->equal_range(itrackData->first);
// We KNOW that the range is not empty - no need to check that.
Iter selected = range.first;
double bestProb = m_matchTool->trackTruthSimilarity(selected->second);
ATH_MSG_VERBOSE ("track="<<selected->first.index()<<" prob="<<bestProb
<<" link: "<<*(selected->second.trajectory().rbegin()));
for(Iter imatch = ++range.first; imatch != range.second; imatch++) {
double prob = m_matchTool->trackTruthSimilarity(imatch->second);
ATH_MSG_VERBOSE ("track="<<imatch->first.index()<<" prob="<<prob
<<" link: "<<*(imatch->second.trajectory().rbegin()));
if(prob>bestProb) {
bestProb = prob;
selected = imatch;
}
}
// trajectory[0] is the LAST particle on the trajectory. The first is at trajectory.rbegin().
const HepMcParticleLink& particleLink = *(selected->second.trajectory().rbegin());
ATH_MSG_VERBOSE ("Truth selected for track="<<selected->first.index()<<" prob="<<bestProb<<" link: "<<particleLink);
out->insert(std::make_pair(selected->first, TrackTruth(particleLink, bestProb, 0) ));
itrackData=range.second;
}
}
//================================================================
#include "GaudiKernel/DeclareFactoryEntries.h"
#include "TrkTruthAlgs/TrackTruthSelector.h"
#include "TrkTruthAlgs/TrackTruthSimilaritySelector.h"
#include "../TrackParticleTruthAlg.h"
DECLARE_ALGORITHM_FACTORY( TrackTruthSelector )
DECLARE_ALGORITHM_FACTORY( TrackTruthSimilaritySelector )
DECLARE_ALGORITHM_FACTORY( TrackParticleTruthAlg )
DECLARE_FACTORY_ENTRIES( TrkTruthAlgs )
{
DECLARE_ALGORITHM( TrackTruthSelector )
DECLARE_ALGORITHM( TrackTruthSimilaritySelector )
DECLARE_ALGORITHM( TrackParticleTruthAlg )
}
#include "GaudiKernel/LoadFactoryEntries.h"
LOAD_FACTORY_ENTRIES( TrkTruthAlgs )
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