Commit adc132fe authored by Edward Moyse's avatar Edward Moyse
Browse files

Merge branch 'Make_MuonCreator_Reentrant' into 'master'

MuonCombinedAlgs - Make the MuonCreator alg reentrant

See merge request !46535
parents 70937715 7f90a171
......@@ -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)));
}
//---------------------------------------------------------------------------------------------------------------------//
......
......@@ -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",
......
......@@ -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;
......
......@@ -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
Markdown is supported
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