diff --git a/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.cxx b/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.cxx index 904cd5d0492d1f07ac43e59ca85e0f1620db3e5e..81366ee81e1d6ffea480559068c5e565f2781993 100644 --- a/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.cxx +++ b/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.cxx @@ -24,7 +24,7 @@ namespace { constexpr const double MeVtoGeV = 1 / Gaudi::Units::GeV; } -MuonCreatorAlg::MuonCreatorAlg(const std::string& name, ISvcLocator* pSvcLocator) : AthAlgorithm(name, pSvcLocator) {} +MuonCreatorAlg::MuonCreatorAlg(const std::string& name, ISvcLocator* pSvcLocator) : AthReentrantAlgorithm(name, pSvcLocator) {} StatusCode MuonCreatorAlg::initialize() { ATH_CHECK(m_muonCreatorTool.retrieve()); @@ -72,117 +72,124 @@ StatusCode MuonCreatorAlg::initialize() { return StatusCode::SUCCESS; } -StatusCode MuonCreatorAlg::execute() { +StatusCode MuonCreatorAlg::execute(const EventContext& ctx) const { const InDetCandidateCollection* indetCandidateCollection = nullptr; std::vector<const MuonCombined::InDetCandidateToTagMap*> tagMaps; if (!m_doSA) { - SG::ReadHandle<InDetCandidateCollection> indetRH(m_indetCandidateCollectionName); + SG::ReadHandle<InDetCandidateCollection> indetRH(m_indetCandidateCollectionName, ctx); if (!indetRH.isValid()) { ATH_MSG_ERROR("Could not read " << m_indetCandidateCollectionName); return StatusCode::FAILURE; } else { indetCandidateCollection = indetRH.cptr(); } - std::vector<SG::ReadHandle<MuonCombined::InDetCandidateToTagMap> > mapHandles = m_tagMaps.makeHandles(); + std::vector<SG::ReadHandle<MuonCombined::InDetCandidateToTagMap> > mapHandles = m_tagMaps.makeHandles(ctx); for (auto& h : mapHandles) tagMaps.push_back(h.cptr()); } // Create the xAOD container and its auxiliary store: - SG::WriteHandle<xAOD::MuonContainer> wh_muons(m_muonCollectionName); + SG::WriteHandle<xAOD::MuonContainer> wh_muons(m_muonCollectionName, ctx); ATH_CHECK(wh_muons.record(std::make_unique<xAOD::MuonContainer>(), std::make_unique<xAOD::MuonAuxContainer>())); ATH_MSG_DEBUG("Recorded Muons with key: " << m_muonCollectionName.key()); MuonCombined::IMuonCreatorTool::OutputData output(*(wh_muons.ptr())); // Create and record track particles: // combined tracks - SG::WriteHandle<xAOD::TrackParticleContainer> wh_combtp(m_combinedCollectionName); - SG::WriteHandle<TrackCollection> wh_combtrk(m_combinedTrkCollectionName); + SG::WriteHandle<xAOD::TrackParticleContainer> wh_combtp(m_combinedCollectionName, ctx); + SG::WriteHandle<TrackCollection> wh_combtrk(m_combinedTrkCollectionName, ctx); ATH_CHECK(wh_combtp.record(std::make_unique<xAOD::TrackParticleContainer>(), std::make_unique<xAOD::TrackParticleAuxContainer>())); ATH_CHECK(wh_combtrk.record(std::make_unique<TrackCollection>())); output.combinedTrackParticleContainer = wh_combtp.ptr(); output.combinedTrackCollection = wh_combtrk.ptr(); // extrapolated tracks - SG::WriteHandle<xAOD::TrackParticleContainer> wh_extrtp(m_extrapolatedCollectionName); - SG::WriteHandle<TrackCollection> wh_extrtrk(m_extrapolatedTrkCollectionName); + SG::WriteHandle<xAOD::TrackParticleContainer> wh_extrtp(m_extrapolatedCollectionName, ctx); + SG::WriteHandle<TrackCollection> wh_extrtrk(m_extrapolatedTrkCollectionName, ctx); ATH_CHECK(wh_extrtp.record(std::make_unique<xAOD::TrackParticleContainer>(), std::make_unique<xAOD::TrackParticleAuxContainer>())); ATH_CHECK(wh_extrtrk.record(std::make_unique<TrackCollection>())); output.extrapolatedTrackParticleContainer = wh_extrtp.ptr(); output.extrapolatedTrackCollection = wh_extrtrk.ptr(); // msonly tracks - SG::WriteHandle<xAOD::TrackParticleContainer> wh_msextrtp(m_msOnlyExtrapolatedCollectionName); - SG::WriteHandle<TrackCollection> wh_msextrtrk(m_msOnlyExtrapolatedTrkCollectionName); + SG::WriteHandle<xAOD::TrackParticleContainer> wh_msextrtp(m_msOnlyExtrapolatedCollectionName, ctx); + SG::WriteHandle<TrackCollection> wh_msextrtrk(m_msOnlyExtrapolatedTrkCollectionName, ctx); ATH_CHECK(wh_msextrtp.record(std::make_unique<xAOD::TrackParticleContainer>(), std::make_unique<xAOD::TrackParticleAuxContainer>())); ATH_CHECK(wh_msextrtrk.record(std::make_unique<TrackCollection>())); output.msOnlyExtrapolatedTrackParticleContainer = wh_msextrtp.ptr(); output.msOnlyExtrapolatedTrackCollection = wh_msextrtrk.ptr(); // segments - SG::WriteHandle<xAOD::MuonSegmentContainer> wh_segment(m_segContainerName); + SG::WriteHandle<xAOD::MuonSegmentContainer> wh_segment(m_segContainerName, ctx); ATH_CHECK(wh_segment.record(std::make_unique<xAOD::MuonSegmentContainer>(), std::make_unique<xAOD::MuonSegmentAuxContainer>())); output.xaodSegmentContainer = wh_segment.ptr(); - SG::WriteHandle<Trk::SegmentCollection> wh_segmentTrk(m_segTrkContainerName); + SG::WriteHandle<Trk::SegmentCollection> wh_segmentTrk(m_segTrkContainerName, ctx); ATH_CHECK(wh_segmentTrk.record(std::make_unique<Trk::SegmentCollection>())); output.muonSegmentCollection = wh_segmentTrk.ptr(); if (m_copySegs) { // now copy the input segments to the final container - SG::ReadHandle<Trk::SegmentCollection> inputSegs(m_inputSegContainerName); + SG::ReadHandle<Trk::SegmentCollection> inputSegs(m_inputSegContainerName, ctx); if (inputSegs.isValid()) { - for (auto it = inputSegs->begin(); it != inputSegs->end(); ++it) { + for (const Trk::Segment* seg : *inputSegs) { // have to cast because the collection stores Trk::Segments - const Muon::MuonSegment* muonSegment = dynamic_cast<const Muon::MuonSegment*>(&(**it)); + const Muon::MuonSegment* muonSegment = dynamic_cast<const Muon::MuonSegment*>(seg); if (muonSegment) wh_segmentTrk->push_back(new Muon::MuonSegment(*muonSegment)); } } // now convert unsigned int index = 0; - for (auto it = wh_segmentTrk->begin(); it != wh_segmentTrk->end(); ++it, ++index) { + for (const Trk::Segment* seg: *wh_segmentTrk) { // have to cast because the collection stores Trk::Segments - const Muon::MuonSegment* muonSegment = dynamic_cast<const Muon::MuonSegment*>(&(**it)); - if (!muonSegment) continue; + const Muon::MuonSegment* muonSegment = dynamic_cast<const Muon::MuonSegment*>(seg); + if (!muonSegment) { + ++index; + continue; + } ElementLink<Trk::SegmentCollection> link(*wh_segmentTrk, index); + ++index; m_muonSegmentConverterTool->convert(link, wh_segment.ptr()); } } // calo clusters - SG::WriteHandle<xAOD::CaloClusterContainer> wh_clusters; - SG::WriteHandle<CaloClusterCellLinkContainer> wh_clusterslink; + std::unique_ptr<xAOD::CaloClusterContainer> caloclusters{nullptr}; + std::unique_ptr<xAOD::CaloClusterAuxContainer> caloclustersaux{nullptr}; + if (m_makeClusters) { - xAOD::CaloClusterContainer* caloclusters = new xAOD::CaloClusterContainer(); - xAOD::CaloClusterAuxContainer* caloclustersaux = new xAOD::CaloClusterAuxContainer(); - caloclusters->setStore(caloclustersaux); - wh_clusters = SG::WriteHandle<xAOD::CaloClusterContainer>(m_clusterContainerName); - wh_clusterslink = SG::WriteHandle<CaloClusterCellLinkContainer>(m_clusterContainerLinkName); - ATH_CHECK(wh_clusters.record(std::unique_ptr<xAOD::CaloClusterContainer>(caloclusters), - std::unique_ptr<xAOD::CaloClusterAuxContainer>(caloclustersaux))); - output.clusterContainer = wh_clusters.ptr(); + caloclusters = std::make_unique< xAOD::CaloClusterContainer>(); + caloclustersaux = std::make_unique<xAOD::CaloClusterAuxContainer>(); + caloclusters->setStore(caloclustersaux.get()); + output.clusterContainer = caloclusters.get(); } const MuonCandidateCollection* muonCandidateCollection = nullptr; SG::WriteHandle<xAOD::SlowMuonContainer> wh_slowmuon; if (m_buildSlowMuon) { - wh_slowmuon = SG::WriteHandle<xAOD::SlowMuonContainer>(m_slowMuonCollectionName); - ATH_CHECK(wh_slowmuon.record(std::make_unique<xAOD::SlowMuonContainer>(), std::make_unique<xAOD::SlowMuonAuxContainer>())); + wh_slowmuon = SG::WriteHandle<xAOD::SlowMuonContainer>(m_slowMuonCollectionName,ctx); + ATH_CHECK(wh_slowmuon.record(std::make_unique<xAOD::SlowMuonContainer>(), std::make_unique<xAOD::SlowMuonAuxContainer>() )); output.slowMuonContainer = wh_slowmuon.ptr(); } else { - SG::ReadHandle<MuonCandidateCollection> muonCandidateRH(m_muonCandidateCollectionName); + SG::ReadHandle<MuonCandidateCollection> muonCandidateRH(m_muonCandidateCollectionName,ctx); if (!muonCandidateRH.isValid()) { ATH_MSG_ERROR("Could not read " << m_muonCandidateCollectionName); return StatusCode::FAILURE; } muonCandidateCollection = muonCandidateRH.cptr(); } - - m_muonCreatorTool->create(muonCandidateCollection, indetCandidateCollection, tagMaps, output); - + m_muonCreatorTool->create(ctx, muonCandidateCollection, indetCandidateCollection, tagMaps, output); + + if (m_makeClusters) { - CaloClusterCellLinkContainer* clusterlinks = new CaloClusterCellLinkContainer(); + SG::WriteHandle<CaloClusterCellLinkContainer> wh_clusterslink {m_clusterContainerLinkName,ctx}; + SG::WriteHandle<xAOD::CaloClusterContainer> wh_clusters {m_clusterContainerName, ctx}; + std::unique_ptr<CaloClusterCellLinkContainer> clusterlinks = std::make_unique<CaloClusterCellLinkContainer>(); auto *sg = wh_clusters.storeHandle().get(); - for (xAOD::CaloCluster* cl : *(wh_clusters.ptr())) { cl->setLink(clusterlinks, sg); } - ATH_CHECK(wh_clusterslink.record(std::unique_ptr<CaloClusterCellLinkContainer>(clusterlinks))); + for (xAOD::CaloCluster* cl : *output.clusterContainer) { + cl->setLink(clusterlinks.get(), sg); + } + ATH_CHECK(wh_clusterslink.record(std::move(clusterlinks))); + ATH_CHECK(wh_clusters.record(std::move(caloclusters), + std::move(caloclustersaux))); } //---------------------------------------------------------------------------------------------------------------------// diff --git a/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.h b/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.h index 99c4e56be6c2fc6028d901e224cc24e023097702..ae81b68e5410eb536d9e96c0e22c19537e1f3a33 100644 --- a/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.h +++ b/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.h @@ -7,6 +7,7 @@ #include <string> +#include "AthenaBaseComps/AthReentrantAlgorithm.h" #include "AthenaBaseComps/AthAlgorithm.h" #include "AthenaMonitoringKernel/GenericMonitoringTool.h" #include "AthenaMonitoringKernel/Monitored.h" @@ -25,14 +26,15 @@ #include "xAODMuonCnv/IMuonSegmentConverterTool.h" #include "xAODTracking/TrackParticleContainer.h" -class MuonCreatorAlg : public AthAlgorithm { +class MuonCreatorAlg : public AthReentrantAlgorithm { public: MuonCreatorAlg(const std::string& name, ISvcLocator* pSvcLocator); ~MuonCreatorAlg() = default; - StatusCode initialize(); - StatusCode execute(); + virtual StatusCode initialize() override; + virtual StatusCode execute(const EventContext& ctx) const override; + private: ToolHandle<MuonCombined::IMuonCreatorTool> m_muonCreatorTool{this, "MuonCreatorTool", "MuonCombined::MuonCreatorTool/MuonCreatorTool", diff --git a/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCreatorTool.cxx b/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCreatorTool.cxx index eb48d296be0b0e822b3ddb639dc3b143b954993f..af426db5323bbef79bf32cc62cefb35ecbd96f02 100644 --- a/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCreatorTool.cxx +++ b/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCreatorTool.cxx @@ -126,7 +126,8 @@ namespace MuonCombined { return StatusCode::SUCCESS; } - void MuonCreatorTool::create(const MuonCandidateCollection* muonCandidates, const InDetCandidateCollection* inDetCandidates, + void MuonCreatorTool::create(const EventContext& ctx, + const MuonCandidateCollection* muonCandidates, const InDetCandidateCollection* inDetCandidates, std::vector<const InDetCandidateToTagMap*> tagMaps, OutputData& outputData) const { unsigned int numIdCan = inDetCandidates ? inDetCandidates->size() : 0; unsigned int numMuCan = muonCandidates ? muonCandidates->size() : 0; @@ -139,7 +140,7 @@ namespace MuonCombined { // Resolve Overlap if (!m_buildStauContainer) - resolveOverlaps(inDetCandidates, muonCandidates, tagMaps, resolvedInDetCandidates, resolvedMuonCandidates); + resolveOverlaps(ctx, inDetCandidates, muonCandidates, tagMaps, resolvedInDetCandidates, resolvedMuonCandidates); else selectStaus(inDetCandidates, resolvedInDetCandidates, tagMaps); @@ -151,9 +152,9 @@ namespace MuonCombined { << " out"); // Create a container for resolved candidates (always of type VIEW_ELEMENTS) - for (InDetCandidateTags can : resolvedInDetCandidates) { + for (InDetCandidateTags& can : resolvedInDetCandidates) { ATH_MSG_DEBUG("New InDetCandidate"); - xAOD::Muon* muon = create(can, outputData); + xAOD::Muon* muon = create(ctx, can, outputData); if (!muon) { ATH_MSG_DEBUG("no muon found"); } else { @@ -168,7 +169,7 @@ namespace MuonCombined { if (!m_requireIDTracks) { // only build SA muons if ID tracks are not required for (const auto* can : resolvedMuonCandidates) { ATH_MSG_DEBUG("New MuonCandidate"); - create(*can, outputData); + create(ctx, *can, outputData); ATH_MSG_DEBUG("Creation of Muon from MuonCandidates done"); } } @@ -179,7 +180,7 @@ namespace MuonCombined { if (outputData.extrapolatedTrackParticleContainer) addAlignmentEffectsOnTrack(outputData.extrapolatedTrackParticleContainer); if (outputData.msOnlyExtrapolatedTrackParticleContainer) addAlignmentEffectsOnTrack(outputData.msOnlyExtrapolatedTrackParticleContainer); - for (auto mu : *outputData.muonContainer) { + for (xAOD::Muon* mu : *outputData.muonContainer) { if (mu->primaryTrackParticle() == mu->trackParticle(xAOD::Muon::InnerDetectorTrackParticle)) continue; // no CT or ST muons if (mu->primaryTrackParticle() == mu->trackParticle(xAOD::Muon::MuonSpectrometerTrackParticle)) continue; // no SA muons w/o ME tracks @@ -315,8 +316,8 @@ namespace MuonCombined { } } - xAOD::Muon* MuonCreatorTool::create(const MuonCandidate& candidate, OutputData& outputData) const { - const EventContext& ctx = Gaudi::Hive::currentContext(); + xAOD::Muon* MuonCreatorTool::create(const EventContext& ctx, + const MuonCandidate& candidate, OutputData& outputData) const { // skip all muons without extrapolated track if (!candidate.extrapolatedTrack()) { ATH_MSG_DEBUG( @@ -328,14 +329,14 @@ namespace MuonCombined { // Create the xAOD object: xAOD::Muon* muon = new xAOD::Muon(); outputData.muonContainer->push_back(muon); - decorateDummyValues(*muon, outputData); + decorateDummyValues(ctx, *muon, outputData); muon->setAuthor(xAOD::Muon::MuidSA); muon->setMuonType(xAOD::Muon::MuonStandAlone); muon->addAllAuthor(xAOD::Muon::MuidSA); // create candidate from SA muon only - addMuonCandidate(candidate, *muon, outputData); + addMuonCandidate(ctx, candidate, *muon, outputData); if (!muon->extrapolatedMuonSpectrometerTrackParticleLink().isValid()) { ATH_MSG_DEBUG("Creation of track particle for SA muon failed, removing it"); @@ -370,16 +371,16 @@ namespace MuonCombined { // check if there is a cluster container, if yes collect the cells around the // muon and fill Etcore variables for muon - if (m_useCaloCells) collectCells(*muon, outputData.clusterContainer, caloExtension.get()); + if (m_useCaloCells) collectCells(ctx, *muon, outputData.clusterContainer, caloExtension.get()); return muon; } - void MuonCreatorTool::decorateDummyValues(xAOD::Muon& muon, OutputData& outputData) const { + void MuonCreatorTool::decorateDummyValues(const EventContext& ctx, xAOD::Muon& muon, OutputData& outputData) const { // Set variables to zero by calling the functions with null pointers. addCaloTag(muon, nullptr); - addCombinedFit(muon, nullptr, outputData); - addStatisticalCombination(muon, nullptr, nullptr, outputData); + addCombinedFit(ctx, muon, nullptr, outputData); + addStatisticalCombination(ctx, muon, nullptr, nullptr, outputData); addMuGirl(muon, nullptr, outputData); addSegmentTag(muon, nullptr, outputData); @@ -405,7 +406,7 @@ namespace MuonCombined { fillEnergyLossFromTrack(muon, nullptr); } - xAOD::Muon* MuonCreatorTool::create(InDetCandidateTags& candidate, OutputData& outputData) const { + xAOD::Muon* MuonCreatorTool::create(const EventContext& ctx, InDetCandidateTags& candidate, OutputData& outputData) const { // no tags, no muon if (candidate.second.empty()) { ATH_MSG_DEBUG( @@ -421,7 +422,7 @@ namespace MuonCombined { return nullptr; } - std::vector<const TagBase*> tags = candidate.second; + std::vector<const TagBase*>& tags = candidate.second; if (tags.size() == 1 && !m_buildStauContainer) { const MuGirlLowBetaTag* muGirlLowBetaTag = dynamic_cast<const MuGirlLowBetaTag*>(tags[0]); if (muGirlLowBetaTag) { @@ -449,7 +450,7 @@ namespace MuonCombined { ATH_MSG_DEBUG("creating Muon with " << tags.size() << " tags "); // loop over the tags - decorateDummyValues(*muon, outputData); + decorateDummyValues(ctx, *muon, outputData); bool first = true; for (const MuonCombined::TagBase* tag : tags) { ATH_MSG_DEBUG("Handling tag: type " << tag->type()); @@ -509,9 +510,9 @@ namespace MuonCombined { const StacoTag* stacoTag = dynamic_cast<const StacoTag*>(tag); const MuGirlTag* muGirlTag = dynamic_cast<const MuGirlTag*>(tag); - addCombinedFit(*muon, cbFitTag, outputData); + addCombinedFit(ctx, *muon, cbFitTag, outputData); addMuGirl(*muon, muGirlTag, outputData); - addStatisticalCombination(*muon, candidate.first, stacoTag, outputData); + addStatisticalCombination(ctx, *muon, candidate.first, stacoTag, outputData); if (!(cbFitTag || stacoTag || muGirlTag)) { ATH_MSG_WARNING("Unknown combined tag "); } } else if (type == xAOD::Muon::SegmentTagged) { @@ -544,23 +545,22 @@ namespace MuonCombined { float eLoss = -1; bool haveEloss = muon->parameter(eLoss, xAOD::Muon::EnergyLoss); if (!haveEloss || eLoss == 0) { - ATH_MSG_DEBUG("Adding Energy Loss to muon"); + ATH_MSG_DEBUG("Adding Energy Loss to muon"<<std::endl<<m_muonPrinter->print(*muon)); addEnergyLossToMuon(*muon); - // ATH_MSG_DEBUG(m_muonPrinter->print(*muon)); } // check if there is a cluster container, if yes collect the cells around the // muon and fill Etcore variables for muon - if (m_useCaloCells) collectCells(*muon, outputData.clusterContainer); + if (m_useCaloCells) collectCells(ctx, *muon, outputData.clusterContainer); ATH_MSG_DEBUG("Done creating muon with " << acc_nUnspoiledCscHits(*muon) << " unspoiled csc hits"); return muon; } - void MuonCreatorTool::addStatisticalCombination(xAOD::Muon& muon, const InDetCandidate* candidate, const StacoTag* tag, + void MuonCreatorTool::addStatisticalCombination(const EventContext& ctx, + xAOD::Muon& muon, const InDetCandidate* candidate, const StacoTag* tag, OutputData& outputData) const { - const EventContext& ctx = Gaudi::Hive::currentContext(); static const SG::AuxElement::Accessor<float> acc_d0("d0_staco"); static const SG::AuxElement::Accessor<float> acc_z0("z0_staco"); static const SG::AuxElement::Accessor<float> acc_phi0("phi0_staco"); @@ -629,7 +629,7 @@ namespace MuonCombined { } // endif outputData.combinedTrackParticleContainer } // add muon candidate - addMuonCandidate(tag->muonCandidate(), muon, outputData); + addMuonCandidate(ctx, tag->muonCandidate(), muon, outputData); // Add inner match chi^2 muon.setParameter(5, xAOD::Muon::msInnerMatchDOF); @@ -646,7 +646,7 @@ namespace MuonCombined { ATH_MSG_DEBUG("Done adding Staco Muon " << tag->author() << " type " << tag->type()); } - void MuonCreatorTool::addCombinedFit(xAOD::Muon& muon, const CombinedFitTag* tag, OutputData& outputData) const { + void MuonCreatorTool::addCombinedFit(const EventContext& ctx, xAOD::Muon& muon, const CombinedFitTag* tag, OutputData& outputData) const { if (!tag) { // init variables if necessary. return; @@ -670,11 +670,12 @@ namespace MuonCombined { } // add muon candidate - addMuonCandidate(tag->muonCandidate(), muon, outputData, tag->updatedExtrapolatedTrackLink()); + addMuonCandidate(ctx, tag->muonCandidate(), muon, outputData, tag->updatedExtrapolatedTrackLink()); // Add inner match chi^2 - muon.setParameter(static_cast<int>(tag->matchDoF()), xAOD::Muon::msInnerMatchDOF); - muon.setParameter(static_cast<float>(tag->matchChi2()), xAOD::Muon::msInnerMatchChi2); + const float inner_chi2 = tag->matchChi2(); + muon.setParameter(tag->matchDoF(), xAOD::Muon::msInnerMatchDOF); + muon.setParameter(inner_chi2, xAOD::Muon::msInnerMatchChi2); ATH_MSG_DEBUG("Done adding Combined Fit Muon " << tag->author() << " type " << tag->type()); } @@ -683,7 +684,6 @@ namespace MuonCombined { OutputData& outputData) const { if (!tag) { // init variables if necessary. - return; } @@ -830,9 +830,9 @@ namespace MuonCombined { void MuonCreatorTool::addSegmentTag(xAOD::Muon& muon, const SegmentTag* tag, OutputData& outputData) const { if (!tag) { // init variables if necessary. - muon.setParameter(static_cast<float>(-1.0), xAOD::Muon::segmentDeltaEta); - muon.setParameter(static_cast<float>(-1.0), xAOD::Muon::segmentDeltaPhi); - muon.setParameter(static_cast<float>(-1.0), xAOD::Muon::segmentChi2OverDoF); + muon.setParameter(-1.f, xAOD::Muon::segmentDeltaEta); + muon.setParameter(-1.f, xAOD::Muon::segmentDeltaPhi); + muon.setParameter(-1.f, xAOD::Muon::segmentChi2OverDoF); return; } @@ -873,8 +873,8 @@ namespace MuonCombined { if (!tag) { // init variables if necessary. - mu.setParameter(static_cast<float>(0.0), xAOD::Muon::CaloLRLikelihood); - mu.setParameter(static_cast<float>(0.0), xAOD::Muon::CaloMuonScore); + mu.setParameter(0.f, xAOD::Muon::CaloLRLikelihood); + mu.setParameter(0.f, xAOD::Muon::CaloMuonScore); mu.setParameter(static_cast<int>(0xFF), xAOD::Muon::CaloMuonIDTag); if (m_fillExtraELossInfo) { // Here we can make sure that we store the extra calotag information - @@ -960,11 +960,11 @@ namespace MuonCombined { return ElementLink<xAOD::MuonSegmentContainer>(); } - void MuonCreatorTool::addMuonCandidate(const MuonCandidate& candidate, xAOD::Muon& muon, OutputData& outputData, + void MuonCreatorTool::addMuonCandidate(const EventContext& ctx, + const MuonCandidate& candidate, xAOD::Muon& muon, OutputData& outputData, const ElementLink<TrackCollection>& meLink) const { // only set once if (muon.muonSpectrometerTrackParticleLink().isValid()) { return; } - const EventContext& ctx = Gaudi::Hive::currentContext(); // case where we have a MuGirl muon that is also reconstructed by STACO: don't // want to add this track as it is misleading however, we will still keep the // MS-only extrapolated track (see below) for debugging purposes @@ -1115,7 +1115,9 @@ namespace MuonCombined { } } - void MuonCreatorTool::resolveOverlaps(const InDetCandidateCollection* inDetCandidates, const MuonCandidateCollection* muonCandidates, + void MuonCreatorTool::resolveOverlaps(const EventContext& ctx , + const InDetCandidateCollection* inDetCandidates, + const MuonCandidateCollection* muonCandidates, const std::vector<const InDetCandidateToTagMap*>& tagMaps, InDetCandidateTagsMap& resolvedInDetCandidates, std::vector<const MuonCombined::MuonCandidate*>& resolvedMuonCandidates) const { @@ -1152,7 +1154,7 @@ namespace MuonCombined { continue; } std::unique_ptr<Trk::CaloExtension> caloExtension = - m_caloExtTool->caloExtension(Gaudi::Hive::currentContext(), *combtp); + m_caloExtTool->caloExtension(ctx, *combtp); if (!caloExtension) { ATH_MSG_WARNING( "failed to get a calo extension for " @@ -1183,7 +1185,7 @@ namespace MuonCombined { continue; } std::unique_ptr<Trk::CaloExtension> caloExtension = - m_caloExtTool->caloExtension(Gaudi::Hive::currentContext(), *combtp); + m_caloExtTool->caloExtension(ctx, *combtp); if (!caloExtension) { ATH_MSG_WARNING( "failed to get a calo extension for " @@ -1262,7 +1264,7 @@ namespace MuonCombined { std::vector<const Muon::MuonSegment*> segments = primaryTag->associatedSegments(); if (!segments.empty() && candidate.first->indetTrackParticle().trackLink().isValid()) { muonTracks.push_back( - createDummyTrack(primaryTag->associatedSegments(), *(candidate.first->indetTrackParticle().track()))); + createDummyTrack(ctx, primaryTag->associatedSegments(), *(candidate.first->indetTrackParticle().track()))); trackInDetCandLinks[muonTracks.back()] = candidate; } } @@ -1347,9 +1349,9 @@ namespace MuonCombined { } } - Trk::Track* MuonCreatorTool::createDummyTrack(const std::vector<const Muon::MuonSegment*>& segments, + Trk::Track* MuonCreatorTool::createDummyTrack(const EventContext& ctx, + const std::vector<const Muon::MuonSegment*>& segments, const Trk::Track& indetTrack) const { - const EventContext& ctx = Gaudi::Hive::currentContext(); ATH_MSG_VERBOSE("Creating dummy tracks from segments..."); Trk::TrackStates trackStateOnSurfaces{}; @@ -1587,53 +1589,42 @@ namespace MuonCombined { void MuonCreatorTool::fillEnergyLossFromTrack(xAOD::Muon& muon, const std::vector<const Trk::TrackStateOnSurface*>* tsosVector) const { // Ensure these are set for every muon if (!tsosVector) { - muon.setParameter(static_cast<float>(0.0), xAOD::Muon::EnergyLoss); - muon.setParameter(static_cast<float>(0.0), xAOD::Muon::ParamEnergyLoss); - muon.setParameter(static_cast<float>(0.0), xAOD::Muon::MeasEnergyLoss); - muon.setParameter(static_cast<float>(0.0), xAOD::Muon::EnergyLossSigma); - muon.setParameter(static_cast<float>(0.0), xAOD::Muon::MeasEnergyLossSigma); - muon.setParameter(static_cast<float>(0.0), xAOD::Muon::ParamEnergyLossSigmaPlus); - muon.setParameter(static_cast<float>(0.0), xAOD::Muon::ParamEnergyLossSigmaMinus); + muon.setParameter(0.f, xAOD::Muon::EnergyLoss); + muon.setParameter(0.f, xAOD::Muon::ParamEnergyLoss); + muon.setParameter(0.f, xAOD::Muon::MeasEnergyLoss); + muon.setParameter(0.f, xAOD::Muon::EnergyLossSigma); + muon.setParameter(0.f, xAOD::Muon::MeasEnergyLossSigma); + muon.setParameter(0.f, xAOD::Muon::ParamEnergyLossSigmaPlus); + muon.setParameter(0.f, xAOD::Muon::ParamEnergyLossSigmaMinus); muon.setEnergyLossType(xAOD::Muon::Parametrized); // Not so nice! Add 'unknown' type? - muon.setParameter(static_cast<float>(0.0), xAOD::Muon::FSR_CandidateEnergy); + muon.setParameter(0.f, xAOD::Muon::FSR_CandidateEnergy); if (m_fillExtraELossInfo) acc_numEnergyLossPerTrack(muon) = 0; return; } - float energyloss = 0.0; unsigned int numEnergyLossPerTrack = 0; bool problem = false; for (const auto* tsos : *tsosVector) { const Trk::MaterialEffectsOnTrack* meot = dynamic_cast<const Trk::MaterialEffectsOnTrack*>(tsos->materialEffectsOnTrack()); - if (meot) { - const Trk::EnergyLoss* el = meot->energyLoss(); - if (false) { - numEnergyLossPerTrack++; - energyloss += el->deltaE(); // FIXME - should we be summing these? - if (el->deltaE() < 0) { - ATH_MSG_WARNING("Found negative energy loss (i.e. energy gain!) for this object: " << (*el)); - problem = true; - } - } - - const CaloEnergy* caloEnergy = dynamic_cast<const CaloEnergy*>(el); - if (caloEnergy) { - numEnergyLossPerTrack++; - - muon.setParameter(static_cast<float>(caloEnergy->deltaE()), xAOD::Muon::EnergyLoss); - muon.setParameter(static_cast<float>(caloEnergy->deltaEParam()), xAOD::Muon::ParamEnergyLoss); - muon.setParameter(static_cast<float>(caloEnergy->deltaEMeas()), xAOD::Muon::MeasEnergyLoss); - muon.setParameter(static_cast<float>(caloEnergy->sigmaDeltaE()), xAOD::Muon::EnergyLossSigma); - muon.setParameter(static_cast<float>(caloEnergy->sigmaDeltaEMeas()), xAOD::Muon::MeasEnergyLossSigma); - muon.setParameter(static_cast<float>(caloEnergy->sigmaPlusDeltaEParam()), xAOD::Muon::ParamEnergyLossSigmaPlus); - muon.setParameter(static_cast<float>(caloEnergy->sigmaMinusDeltaEParam()), xAOD::Muon::ParamEnergyLossSigmaMinus); - - muon.setEnergyLossType(static_cast<xAOD::Muon::EnergyLossType>(caloEnergy->energyLossType())); - muon.setParameter(static_cast<float>(caloEnergy->fsrCandidateEnergy()), xAOD::Muon::FSR_CandidateEnergy); - } - } + if (!meot) continue; + const Trk::EnergyLoss* el = meot->energyLoss(); + const CaloEnergy* caloEnergy = dynamic_cast<const CaloEnergy*>(el); + if (!caloEnergy) continue; + ++numEnergyLossPerTrack; + + muon.setParameter(static_cast<float>(caloEnergy->deltaE()), xAOD::Muon::EnergyLoss); + muon.setParameter(static_cast<float>(caloEnergy->deltaEParam()), xAOD::Muon::ParamEnergyLoss); + muon.setParameter(static_cast<float>(caloEnergy->deltaEMeas()), xAOD::Muon::MeasEnergyLoss); + muon.setParameter(static_cast<float>(caloEnergy->sigmaDeltaE()), xAOD::Muon::EnergyLossSigma); + muon.setParameter(static_cast<float>(caloEnergy->sigmaDeltaEMeas()), xAOD::Muon::MeasEnergyLossSigma); + muon.setParameter(static_cast<float>(caloEnergy->sigmaPlusDeltaEParam()), xAOD::Muon::ParamEnergyLossSigmaPlus); + muon.setParameter(static_cast<float>(caloEnergy->sigmaMinusDeltaEParam()), xAOD::Muon::ParamEnergyLossSigmaMinus); + + muon.setEnergyLossType(static_cast<xAOD::Muon::EnergyLossType>(caloEnergy->energyLossType())); + muon.setParameter(static_cast<float>(caloEnergy->fsrCandidateEnergy()), xAOD::Muon::FSR_CandidateEnergy); + } if (numEnergyLossPerTrack > 1) { ATH_MSG_VERBOSE("More than one e loss per track... "); @@ -1643,10 +1634,10 @@ namespace MuonCombined { if (problem) ATH_MSG_VERBOSE("Dumping problematic muon: " << m_muonPrinter->print(muon)); } - void MuonCreatorTool::collectCells(xAOD::Muon& muon, xAOD::CaloClusterContainer* clusterContainer, + void MuonCreatorTool::collectCells(const EventContext& ctx, + xAOD::Muon& muon, xAOD::CaloClusterContainer* clusterContainer, Trk::CaloExtension* inputCaloExt) const { - const EventContext& ctx = Gaudi::Hive::currentContext(); - + const xAOD::TrackParticle* tp = muon.primaryTrackParticle(); if (!tp || !clusterContainer) { if (!tp) ATH_MSG_WARNING("Can not get primary track."); @@ -1657,8 +1648,8 @@ namespace MuonCombined { ATH_MSG_DEBUG(" Selected track: pt " << tp->pt() << " eta " << tp->eta() << " phi " << tp->phi()); xAOD::CaloCluster* cluster = nullptr; - SG::ReadHandle<CaloCellContainer> container(m_cellContainerName); - + SG::ReadHandle<CaloCellContainer> container(m_cellContainerName, ctx); + if (!inputCaloExt) { // need to make one // for some reason, ID tracks need to be extrapolated from the ID exit, and // combined from the perigee @@ -1688,23 +1679,21 @@ namespace MuonCombined { } // create element links - ElementLink<xAOD::CaloClusterContainer> clusterLink(*clusterContainer, clusterContainer->size() - 1); + ElementLink<xAOD::CaloClusterContainer> clusterLink(*clusterContainer, cluster->index(), ctx); muon.setClusterLink(clusterLink); - const CaloNoise* caloNoise = nullptr; if (!m_caloNoiseKey.empty()) { - SG::ReadCondHandle<CaloNoise> noiseH(m_caloNoiseKey); + SG::ReadCondHandle<CaloNoise> noiseH(m_caloNoiseKey, ctx); caloNoise = noiseH.cptr(); } - // collect the core energy - std::vector<float> etcore(4, 0); + std::vector<float> etcore(4,0); m_cellCollector.collectEtCore(*cluster, etcore, caloNoise, m_sigmaCaloNoiseCut); + acc_ET_Core(muon) = etcore[Rec::CaloCellCollector::ET_Core]; acc_ET_EMCore(muon) = etcore[Rec::CaloCellCollector::ET_EMCore]; acc_ET_TileCore(muon) = etcore[Rec::CaloCellCollector::ET_TileCore]; acc_ET_HECCore(muon) = etcore[Rec::CaloCellCollector::ET_HECCore]; - if (m_caloNoiseKey.empty()) ATH_MSG_DEBUG("NO Tool for calo noise,sigma: " << m_sigmaCaloNoiseCut); else diff --git a/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCreatorTool.h b/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCreatorTool.h index f07c77b18fdc696771a9205cbd0d7c65d45c19e8..9a813b16321b51987f44a50bdb15f0145c4b064e 100644 --- a/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCreatorTool.h +++ b/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCreatorTool.h @@ -57,33 +57,37 @@ namespace MuonCombined { class SegmentTag; class CaloTag; - typedef std::vector<InDetCandidateTags> InDetCandidateTagsMap; class MuonCreatorTool : public AthAlgTool, virtual public IMuonCreatorTool { public: + + using InDetCandidateTagsMap = std::vector<InDetCandidateTags>; + + MuonCreatorTool(const std::string& type, const std::string& name, const IInterface* parent); ~MuonCreatorTool() = default; virtual StatusCode initialize() override final; /** IMuonCreatorTool interface: build muons from ID and MS candidates */ - virtual void create(const MuonCandidateCollection* muonCandidates, const InDetCandidateCollection* inDetCandidates, + virtual void create(const EventContext& ctx, const MuonCandidateCollection* muonCandidates, const InDetCandidateCollection* inDetCandidates, std::vector<const InDetCandidateToTagMap*> tagMaps, OutputData& outputData) const override final; /** IMuonCreatorTool interface: create a muon from a muon candidate */ - virtual xAOD::Muon* create(const MuonCandidate& candidate, OutputData& outputData) const override final; + virtual xAOD::Muon* create(const EventContext& ctx, + const MuonCandidate& candidate, OutputData& outputData) const override final; /** IMuonCreatorTool interface: create a muon from a muon candidate */ - virtual xAOD::Muon* create(InDetCandidateTags& candidate, OutputData& outputData) const override final; + virtual xAOD::Muon* create(const EventContext& ctx, InDetCandidateTags& candidate, OutputData& outputData) const override final; private: /// Decorated a bunch of dummy values to the muon to ensure data consistency in the xAOD - void decorateDummyValues(xAOD::Muon& muon, OutputData& outputData) const; + void decorateDummyValues(const EventContext& ctx, xAOD::Muon& muon, OutputData& outputData) const; - void addStatisticalCombination(xAOD::Muon& muon, const InDetCandidate* candidate, const StacoTag* tag, + void addStatisticalCombination(const EventContext& ctx, xAOD::Muon& muon, const InDetCandidate* candidate, const StacoTag* tag, OutputData& outputData) const; - void addCombinedFit(xAOD::Muon& muon, const CombinedFitTag* tag, OutputData& outputData) const; + void addCombinedFit(const EventContext& ctx, xAOD::Muon& muon, const CombinedFitTag* tag, OutputData& outputData) const; void addMuGirl(xAOD::Muon& muon, const MuGirlTag* tag, OutputData& outputData) const; @@ -98,7 +102,8 @@ namespace MuonCombined { extrapolatedTrack of the MuonCandidate will be release during the operation. */ - void addMuonCandidate(const MuonCandidate& candidate, xAOD::Muon& muon, OutputData& outputData, + void addMuonCandidate(const EventContext& ctx, + const MuonCandidate& candidate, xAOD::Muon& muon, OutputData& outputData, const ElementLink<TrackCollection>& meLink = ElementLink<TrackCollection>()) const; /// function creates an element link to a track particle from the track and @@ -113,7 +118,7 @@ namespace MuonCombined { Trk::SegmentCollection* muonSegmentCollection = 0) const; private: - void resolveOverlaps(const InDetCandidateCollection* inDetCandidates, const MuonCandidateCollection* muonCandidates, + void resolveOverlaps(const EventContext& ctx, const InDetCandidateCollection* inDetCandidates, const MuonCandidateCollection* muonCandidates, const std::vector<const InDetCandidateToTagMap*>& tagMaps, InDetCandidateTagsMap& resolvedInDetCandidates, std::vector<const MuonCombined::MuonCandidate*>& resolvedMuonCandidates) const; @@ -124,7 +129,7 @@ namespace MuonCombined { void selectStaus(const InDetCandidateCollection* inDetCandidates, std::vector<const MuonCombined::InDetCandidate*>& resolvedInDetCandidates) const; - Trk::Track* createDummyTrack(const std::vector<const Muon::MuonSegment*>& segments, const Trk::Track& indetTrack) const; + Trk::Track* createDummyTrack(const EventContext& ctx, const std::vector<const Muon::MuonSegment*>& segments, const Trk::Track& indetTrack) const; void setMuonHitCounts(xAOD::Muon& muon) const; bool dressMuon(xAOD::Muon& muon, const xAOD::MuonSegmentContainer* segments) const; @@ -135,7 +140,8 @@ namespace MuonCombined { void setP4(xAOD::Muon& muon, const xAOD::TrackParticle& tp) const; - void collectCells(xAOD::Muon& muon, xAOD::CaloClusterContainer* clusterContainer, Trk::CaloExtension* inputCaloExt = nullptr) const; + void collectCells(const EventContext& ctx, + xAOD::Muon& muon, xAOD::CaloClusterContainer* clusterContainer, Trk::CaloExtension* inputCaloExt = nullptr) const; void getRpcTiming(const xAOD::TrackParticle& tp, std::vector<unsigned int>& rpcHitIdentifier, std::vector<float>& rpcHitPositionX, std::vector<float>& rpcHitPositionY, std::vector<float>& rpcHitPositionZ, std::vector<float>& rpcHitTime) const; diff --git a/Reconstruction/MuonIdentification/MuonCombinedToolInterfaces/MuonCombinedToolInterfaces/IMuonCreatorTool.h b/Reconstruction/MuonIdentification/MuonCombinedToolInterfaces/MuonCombinedToolInterfaces/IMuonCreatorTool.h index f0e5bdd0527c688071772ff1015604f7ffa5b37e..9976ba73c735a074f5dec268be52b6fb8b92b8a1 100644 --- a/Reconstruction/MuonIdentification/MuonCombinedToolInterfaces/MuonCombinedToolInterfaces/IMuonCreatorTool.h +++ b/Reconstruction/MuonIdentification/MuonCombinedToolInterfaces/MuonCombinedToolInterfaces/IMuonCreatorTool.h @@ -23,10 +23,8 @@ namespace MuonCombined { - typedef std::pair<const InDetCandidate*, std::vector<const TagBase*> > InDetCandidateTags; - - static const InterfaceID IID_IMuonCreatorTool("MuonCombined::IMuonCreatorTool", 1, 0); - + + /** @class IMuonCreatorTool @brief interface for tools building combined muons from ID and Muon candidates @@ -35,74 +33,71 @@ namespace MuonCombined { If the pointer to a certain type is non-zero, the container is filled. The MuonContainer is mandatory, all other output types are optional. - @author Niels van Eldik */ class IMuonCreatorTool : virtual public IAlgTool { public: + + using InDetCandidateTags = std::pair<const InDetCandidate*, std::vector<const TagBase*> > ; + struct OutputData { OutputData(xAOD::MuonContainer& container) : - muonContainer(&container), - combinedTrackParticleContainer(0), - extrapolatedTrackParticleContainer(0), - msOnlyExtrapolatedTrackParticleContainer(0), - combinedTrackCollection(0), - extrapolatedTrackCollection(0), - msOnlyExtrapolatedTrackCollection(0), - xaodSegmentContainer(0), - muonSegmentCollection(0), - slowMuonContainer(0), - clusterContainer(0) {} + muonContainer(&container){} /** MuonContainer to be filled with the Muon objects */ - xAOD::MuonContainer* muonContainer; + xAOD::MuonContainer* muonContainer{nullptr}; /** container for the combined track particles */ - xAOD::TrackParticleContainer* combinedTrackParticleContainer; + xAOD::TrackParticleContainer* combinedTrackParticleContainer{nullptr}; /** container for the extrapolated track particles */ - xAOD::TrackParticleContainer* extrapolatedTrackParticleContainer; + xAOD::TrackParticleContainer* extrapolatedTrackParticleContainer{nullptr}; /** container for the extrapolated track particles */ - xAOD::TrackParticleContainer* msOnlyExtrapolatedTrackParticleContainer; + xAOD::TrackParticleContainer* msOnlyExtrapolatedTrackParticleContainer{nullptr}; /** container for the combined tracks */ - TrackCollection* combinedTrackCollection; + TrackCollection* combinedTrackCollection{nullptr}; /** container for the extrapolated tracks */ - TrackCollection* extrapolatedTrackCollection; + TrackCollection* extrapolatedTrackCollection{nullptr}; /** container for the extrapolated tracks */ - TrackCollection* msOnlyExtrapolatedTrackCollection; + TrackCollection* msOnlyExtrapolatedTrackCollection{nullptr}; /** container for the xAOD segments from MuGirl */ - xAOD::MuonSegmentContainer* xaodSegmentContainer; + xAOD::MuonSegmentContainer* xaodSegmentContainer{nullptr}; /** collection for the segments from MuGirl */ - Trk::SegmentCollection* muonSegmentCollection; + Trk::SegmentCollection* muonSegmentCollection{nullptr}; /** container for the Slow muon content */ - xAOD::SlowMuonContainer* slowMuonContainer; + xAOD::SlowMuonContainer* slowMuonContainer{nullptr}; /** container for the clusters associated with muons */ - xAOD::CaloClusterContainer* clusterContainer; + xAOD::CaloClusterContainer* clusterContainer{nullptr}; }; - static const InterfaceID& interfaceID(); + static const InterfaceID& interfaceID(){ + static const InterfaceID IID_IMuonCreatorTool("MuonCombined::IMuonCreatorTool", 1, 0); + return IID_IMuonCreatorTool; + } + /**IMuonCreatorTool interface: build muons from ID and MS candidates */ - virtual void create(const MuonCandidateCollection* muonCandidates, const InDetCandidateCollection* inDetCandidates, + virtual void create(const EventContext& ctx, const MuonCandidateCollection* muonCandidates, const InDetCandidateCollection* inDetCandidates, std::vector<const InDetCandidateToTagMap*> tagMaps, OutputData& outputData) const = 0; /** create a muon from a muon candidate */ - virtual xAOD::Muon* create(const MuonCandidate& candidate, OutputData& outputData) const = 0; + virtual xAOD::Muon* create(const EventContext& ctx, const MuonCandidate& candidate, OutputData& outputData) const = 0; /** create a muon from an ID candidate */ - virtual xAOD::Muon* create(InDetCandidateTags& candidate, OutputData& outputData) const = 0; + virtual xAOD::Muon* create(const EventContext& ctx, InDetCandidateTags& candidate, OutputData& outputData) const = 0; + /** default virtual destructor */ + virtual ~IMuonCreatorTool() = default; }; - inline const InterfaceID& IMuonCreatorTool::interfaceID() { return IID_IMuonCreatorTool; } - + } // namespace MuonCombined #endif