Skip to content
Snippets Groups Projects
Commit e672f80d authored by Will Leight's avatar Will Leight
Browse files

Fix for ATLASRECTS-3796 plus smaller technical changes

This change should fix ATLASRECTS-3796 by adding dummy truth links to xAOD::Muon objects and muon tracks that are not truth-matched, thus avoiding ELReset errors.

It also brings in a memory leak fix (ATLASRECTS-3925) that was present in MuonTruthAlgs-02-12-16-00 and never made it to release 21.

Finally, it adds the migration of MuonDecayTruthTrajectoryBuilder to const interfaces and of the TrackParticleTruthAlg to DataHandles.
This occurred because the development started in svn and these changes were present in the most up-to-date tags, so they got added by accident.
If not desired, these particular changes can be reverted: however, as they should have no effect on the performance, I left them in.

Tier0 test results can be found at /afs/cern.ch/work/w/wleight/public/MuonSW/ATLASRECTS-3796_git/: no T0 violation was observed.
The only changes that would be involved here are adding dummy values for cases when truth-matching fails.
For the element-links, I don't know if this would be caught by the diff-root.
However, as dummy values are also added for the truthOrigin and truthType, there would be in principle some T0 violation (though for MC only of course).
Since these are dummy values and so will not be used by analyzers, I don't think it's a significant violation.

AODtoTAG also reported many more errors for q221: since there were no changes at all in any of the other substeps, I assume this is a glitch of some sort.
parent 229c87ba
No related merge requests found
Showing
with 96 additions and 113 deletions
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
// Niels van Eldik 2010
#include "MuonDecayTruthTrajectoryBuilder.h"
......@@ -23,8 +19,8 @@ namespace Muon {
MuonDecayTruthTrajectoryBuilder(const std::string& type,
const std::string& name,
const IInterface* parent)
: AthAlgTool(type,name,parent),
m_isDecayIntoTwoMuons(false)
: AthAlgTool(type,name,parent)
// ,m_isDecayIntoTwoMuons(false)
{
declareInterface<Trk::ITruthTrajectoryBuilder>(this);
}
......@@ -86,7 +82,7 @@ namespace Muon {
//================================================================
MuonDecayTruthTrajectoryBuilder::MotherDaughter
MuonDecayTruthTrajectoryBuilder::truthTrajectoryCuts(const HepMC::GenVertex *vtx)
MuonDecayTruthTrajectoryBuilder::truthTrajectoryCuts(const HepMC::GenVertex *vtx) const
{
const HepMC::GenParticle *mother(0), *daughter(0);
......@@ -139,7 +135,7 @@ namespace Muon {
daughter = passed_cuts;
if( nDecayMuons == 2 ){
ATH_MSG_DEBUG( " decay into two muons ");
m_isDecayIntoTwoMuons = true;
// m_isDecayIntoTwoMuons = true;
}
}
} // if( mother && (mother->status() == 1) )
......@@ -173,7 +169,7 @@ namespace Muon {
if(daughter) {
MotherDaughter res = truthTrajectoryCuts(daughter->production_vertex());
mother = res.first;
m_isDecayIntoTwoMuons = false;
// m_isDecayIntoTwoMuons = false; // Don't think this does anything? EJWM.
}
return mother;
......
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
// Dear emacs, this is -*-c++-*-
#ifndef MUONDECAYTRUTHTRAJECTORYBUILDER_H
......@@ -47,9 +43,9 @@ namespace Muon {
* between mother and daughter particles; i.e. TruthTrajectories
* are not allowed to branch.
*/
MotherDaughter truthTrajectoryCuts(const HepMC::GenVertex *vtx);
MotherDaughter truthTrajectoryCuts(const HepMC::GenVertex *vtx) const;
bool m_isDecayIntoTwoMuons;
// mutable bool m_isDecayIntoTwoMuons; // Really don't think this does anything? EJWM.
};
} // end namespace Trk
......
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
///////////////////////////////////////////////////////////////////
// MuonTruthAssociationAlg.cxx
// Implementation file for class MuonTruthAssociationAlg
......@@ -290,13 +286,16 @@ void MuonTruthAssociationAlg::addMuon( const xAOD::TruthParticleContainer& truth
break;
}
}
else{
else{ //no truth link, add a dummy
ATH_MSG_VERBOSE(" Reco muon has no truth association");
}
const_cast<xAOD::Muon&>(*muon).auxdata<ElementLink<xAOD::TruthParticleContainer> >("truthParticleLink" )=ElementLink<xAOD::TruthParticleContainer>();
const_cast<xAOD::Muon&>(*muon).auxdata<int>("truthType") = -99999;
const_cast<xAOD::Muon&>(*muon).auxdata<int>("truthOrigin") = -99999;
}
} catch ( SG::ExcBadAuxVar& ) {
ATH_MSG_WARNING("Track particle is missing truthParticleLink variable!");
}
}
}
}
muonLink.toPersistent();
const_cast<xAOD::TruthParticle&>(*truthParticle).auxdata<ElementLink< xAOD::MuonContainer > >("recoMuonLink") = muonLink;
......
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
///////////////////////////////////////////////////////////////////
// MuonTruthDecorationAlg.cxx
// Implementation file for class MuonTruthDecorationAlg
......
......@@ -16,16 +16,18 @@ class TrackTruthSelector: public AthAlgorithm {
public:
TrackTruthSelector(const std::string &name,ISvcLocator *pSvcLocator);
virtual StatusCode initialize();
virtual StatusCode execute();
virtual StatusCode finalize();
virtual StatusCode initialize() override;
virtual StatusCode execute() override;
virtual StatusCode finalize() override;
private:
// DetailedTrackTruthCollection input name
std::string m_detailedTrackTruthName;
SG::ReadHandle<DetailedTrackTruthCollection> m_detailed; // std::string m_detailedTrackTruthName;
// TrackTruthCollection output name
std::string m_outputName;
SG::WriteHandle<TrackTruthCollection> m_out; //std::string m_outputName;
// Subdetector weights
std::vector<double> m_subDetWeights;
......
......@@ -19,16 +19,16 @@ class TrackTruthSimilaritySelector: public AthAlgorithm {
public:
TrackTruthSimilaritySelector(const std::string &name,ISvcLocator *pSvcLocator);
virtual StatusCode initialize();
virtual StatusCode execute();
virtual StatusCode finalize();
virtual StatusCode initialize() override;
virtual StatusCode execute() override;
virtual StatusCode finalize() override;
private:
// DetailedTrackTruthCollection input name
std::string m_detailedTrackTruthName;
SG::ReadHandle<DetailedTrackTruthCollection> m_detailed; //std::string m_detailedTrackTruthName;
// TrackTruthCollection output name
std::string m_outputName;
SG::WriteHandle<TrackTruthCollection> m_out; //std::string m_outputName;
// Match quality tool
ToolHandle<Trk::IDetailedTrackTruthSimilarity> m_matchTool;
......
......@@ -4,23 +4,23 @@
#include "TrackParticleTruthAlg.h"
#include "TrkTruthData/TrackTruthCollection.h"
#include "TrkTruthData/TrackTruthKey.h"
#include "GeneratorObjects/xAODTruthParticleLink.h"
#include "xAODTracking/TrackParticleContainer.h"
#include "TrkTruthData/TrackTruthKey.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_particles("InDetTrackParticles"),
m_truthParticleLinkVec("xAODTruthLinks"),
m_truthTracks("TrackTruthCollection"),
m_truthClassifier("MCTruthClassifier/MCTruthClassifier")
{
declareProperty("MCTruthClassifier", m_truthClassifier);
declareProperty("TrackTruthName", m_truthName="TrackTruthCollection");
declareProperty("TrackParticleName", m_trackParticleName="InDetTrackParticles");
declareProperty("xAODTruthLinkVector",m_truthLinkVecName="xAODTruthLinks");
declareProperty("TrackTruthName", m_truthTracks);
declareProperty("TrackParticleName", m_particles);
declareProperty("xAODTruthLinkVector",m_truthParticleLinkVec);
}
// -----------------------------------------------------------------------------------------------------
......@@ -38,24 +38,24 @@ StatusCode TrackParticleTruthAlg::finalize() {
// -----------------------------------------------------------------------------------------------------
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;
if(!m_particles.isValid()){
ATH_MSG_ERROR("Could not read " << m_particles.name());
return StatusCode::FAILURE;
}
if(!m_truthParticleLinkVec.isValid()){
ATH_MSG_ERROR("Could not read " << m_truthParticleLinkVec.name());
return StatusCode::FAILURE;
}
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;
if(!m_truthTracks.isValid()){
ATH_MSG_ERROR("Could not read " << m_truthTracks.name());
return StatusCode::FAILURE;
}
for( auto particle : *particles ){
for( auto particle : *m_particles ){
if( !particle->trackLink().isValid() ){
ATH_MSG_WARNING("Found TrackParticle with Invalid element link, skipping");
......@@ -68,12 +68,12 @@ StatusCode TrackParticleTruthAlg::execute() {
ElementLink<xAOD::TruthParticleContainer> link;
// look-up associdated truth particle
Trk::TrackTruthKey key(particle->trackLink());
auto result = truthTracks->find(key);
auto result = m_truthTracks->find(key);
// if we found a match use it
if( result != truthTracks->end() ){
if( result != m_truthTracks->end() ){
ATH_MSG_VERBOSE("Found track Truth: barcode " << result->second.particleLink().barcode() << " evt " << result->second.particleLink().eventIndex());
link = truthParticleLinkVec->find(result->second.particleLink());
link = m_truthParticleLinkVec->find(result->second.particleLink());
// if configured also get truth classification
if( link.isValid()&& !m_truthClassifier.empty() ){
......@@ -84,16 +84,18 @@ StatusCode TrackParticleTruthAlg::execute() {
}
}
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;
//BREAKS THREAD SAFETY FIX LATER
const_cast<xAOD::TrackParticle*>(particle)->auxdata<ElementLink<xAOD::TruthParticleContainer> >("truthParticleLink" ) = link;
}
if( !m_truthClassifier.empty() ){
particle->auxdata<int>("truthType") = static_cast<int>(type);
particle->auxdata<int>("truthOrigin") = static_cast<int>(origin);
//BREAKS THREAD SAFETY FIX LATER
const_cast<xAOD::TrackParticle*>(particle)->auxdata<int>("truthType") = static_cast<int>(type);
const_cast<xAOD::TrackParticle*>(particle)->auxdata<int>("truthOrigin") = static_cast<int>(origin);
}
}
return StatusCode::SUCCESS;
......
......@@ -5,11 +5,12 @@
#ifndef TRACKPARTICLETRUTHALG_H
#define TRACKPARTICLETRUTHALG_H
#include <string>
#include <vector>
#include "AthenaBaseComps/AthAlgorithm.h"
#include "GaudiKernel/ToolHandle.h"
#include "xAODTracking/TrackParticleContainer.h"
#include "TrkTruthData/TrackTruthCollection.h"
#include "GeneratorObjects/xAODTruthParticleLink.h"
class IMCTruthClassifier;
......@@ -17,15 +18,17 @@ class TrackParticleTruthAlg: public AthAlgorithm {
public:
TrackParticleTruthAlg(const std::string &name,ISvcLocator *pSvcLocator);
virtual StatusCode initialize();
virtual StatusCode execute();
virtual StatusCode finalize();
virtual StatusCode initialize() override;
virtual StatusCode execute() override;
virtual StatusCode finalize() override;
private:
SG::ReadHandle<xAOD::TrackParticleContainer> m_particles;//std::string m_trackParticleName; /// TrackParticle input name
SG::ReadHandle<xAODTruthParticleLinkVector> m_truthParticleLinkVec;//std::string m_truthLinkVecName; /// link vector to map HepMC onto xAOD truth
SG::ReadHandle<TrackTruthCollection> m_truthTracks;//std::string m_truthName; /// Track(Particle)TruthCollection input name
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;
};
......
......@@ -6,10 +6,12 @@
TrackTruthSelector::TrackTruthSelector(const std::string &name,ISvcLocator *pSvcLocator) :
AthAlgorithm(name,pSvcLocator),
m_detailed("DetailedTrackTruth"),
m_out("TrackTruthNew"),
m_subDetWeights(SubDetHitStatistics::NUM_SUBDETECTORS, 1.)
{
declareProperty("DetailedTrackTruthName", m_detailedTrackTruthName="DetailedTrackTruth");
declareProperty("OutputName", m_outputName="TrackTruthNew");
declareProperty("DetailedTrackTruthName", m_detailed);
declareProperty("OutputName", m_out);
declareProperty("WeightPixel", m_subDetWeights[SubDetHitStatistics::Pixel]);
declareProperty("WeightSCT", m_subDetWeights[SubDetHitStatistics::SCT]);
......@@ -37,34 +39,27 @@ StatusCode TrackTruthSelector::finalize() {
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");
if (!m_detailed.isValid()){
ATH_MSG_WARNING ("DetailedTrackTruthCollection "<<m_detailed.name()<<" NOT found");
return StatusCode::SUCCESS;
} else {
ATH_MSG_DEBUG ("Got DetailedTrackTruthCollection "<<m_detailedTrackTruthName);
ATH_MSG_DEBUG ("Got DetailedTrackTruthCollection "<<m_detailed.name());
}
//----------------------------------------------------------------
// Produce and store the output.
TrackTruthCollection *out = new TrackTruthCollection(detailed->trackCollectionLink());
m_out = std::unique_ptr<TrackTruthCollection>(new TrackTruthCollection(m_detailed->trackCollectionLink()));
fillOutput(out, detailed);
fillOutput(m_out.ptr(), m_detailed.cptr());
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());
}
ATH_MSG_DEBUG ("TrackTruthCollection '" << m_out.name() << "' is registered in StoreGate, size="<<m_out->size());
return StatusCode::SUCCESS;
......
......@@ -6,18 +6,19 @@
#include "TrkToolInterfaces/IDetailedTrackTruthSimilarity.h"
TrackTruthSimilaritySelector::TrackTruthSimilaritySelector(const std::string &name,ISvcLocator *pSvcLocator)
: AthAlgorithm(name,pSvcLocator)
: AthAlgorithm(name,pSvcLocator),
m_detailed("DetailedTrackTruth"), m_out("TrackTruthNew")
, m_matchTool("Trk::TruthMatchRatio")
{
declareProperty("TrackTruthSimilarityTool", m_matchTool, "Track-truth similarity tool");
declareProperty("DetailedTrackTruthName", m_detailedTrackTruthName="DetailedTrackTruth");
declareProperty("OutputName", m_outputName="TrackTruthNew");
declareProperty("DetailedTrackTruthName", m_detailed);
declareProperty("OutputName", m_out);
}
// -----------------------------------------------------------------------------------------------------
StatusCode TrackTruthSimilaritySelector::initialize()
{
ATH_MSG_INFO ("TrackTruthSimilaritySelector::initialize(), output " << m_outputName);
ATH_MSG_INFO ("TrackTruthSimilaritySelector::initialize(), output " << m_out.name());
return StatusCode::SUCCESS;
}
......@@ -32,33 +33,26 @@ 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;
if (!m_detailed.isValid()){
ATH_MSG_ERROR ("DetailedTrackTruthCollection "<<m_detailed.name()<<" NOT found");
return StatusCode::FAILURE;
} else {
ATH_MSG_DEBUG ("Got DetailedTrackTruthCollection "<<m_detailedTrackTruthName);
ATH_MSG_DEBUG ("Got DetailedTrackTruthCollection "<<m_detailed.name());
}
//----------------------------------------------------------------
// Produce and store the output.
TrackTruthCollection *out = new TrackTruthCollection(detailed->trackCollectionLink());
m_out = std::unique_ptr<TrackTruthCollection>
(new TrackTruthCollection(m_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());
}
fillOutput(m_out.ptr(), m_detailed.cptr());
ATH_MSG_DEBUG ("TrackTruthCollection '"<<m_out.name()<<"' is registered in StoreGate, size="<<m_out->size());
return StatusCode::SUCCESS;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment