ATLAS Offline Software
MuonEtaHoughTransformAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
9 
11 
12 using namespace MuonR4;
13 
15  ISvcLocator* pSvcLocator)
16  : AthReentrantAlgorithm(name, pSvcLocator) {}
17 
20  ATH_CHECK(m_spacePointKey.initialize());
22 
23  return StatusCode::SUCCESS;
24 }
25 
26 template <class ContainerType>
28  const EventContext& ctx, const SG::ReadHandleKey<ContainerType>& key,
29  const ContainerType*& contToPush) const {
30  contToPush = nullptr;
31  if (key.empty()) {
32  ATH_MSG_VERBOSE("No key has been parsed for object "
33  << typeid(ContainerType).name());
34  return StatusCode::SUCCESS;
35  }
36  SG::ReadHandle<ContainerType> readHandle{key, ctx};
37  ATH_CHECK(readHandle.isPresent());
38  contToPush = readHandle.cptr();
39  return StatusCode::SUCCESS;
40 }
41 
42 StatusCode MuonEtaHoughTransformAlg::execute(const EventContext& ctx) const {
43 
45  const MuonSpacePointContainer* spacePoints{nullptr};
46  ATH_CHECK(retrieveContainer(ctx, m_spacePointKey, spacePoints));
47 
48  // book the output container
50  ATH_CHECK(writeMaxima.record(std::make_unique<StationHoughMaxContainer>()));
51 
53  ATH_CHECK(gctxHandle.isValid());
54 
55  MuonHoughEventData data{*gctxHandle};
56 
58  ATH_CHECK(preProcess(data, *spacePoints));
59 
63  for (auto& [station, stationHoughBuckets] : data.houghSetups) {
64  // reset the list of maxima
65  data.maxima.clear();
66  for (auto& bucket : stationHoughBuckets) {
67  ATH_CHECK(processBucket(data, bucket));
68  }
70  writeMaxima->emplace(StationHoughMaxima(station, data.maxima));
71  }
72  return StatusCode::SUCCESS;
73 }
76  const MuonR4::MuonSpacePointContainer& spacePoints) const {
77 
78  ATH_MSG_DEBUG("Load " << spacePoints.size() << " space point buckets");
79  for (const MuonR4::MuonSpacePointBucket* sp : spacePoints) {
80  std::vector<HoughSetupForBucket>& buckets =
81  data.houghSetups[sp->front()->muonChamber()];
82  buckets.push_back(HoughSetupForBucket{sp});
83  HoughSetupForBucket& hs = buckets.back();
84  Amg::Vector3D leftSide =
85  hs.bucket->muonChamber()
86  ->globalToLocalTrans(data.gctx)
87  .translation() -
88  (hs.bucket->coveredMin() * Amg::Vector3D::UnitY());
89  Amg::Vector3D rightSide =
90  hs.bucket->muonChamber()
91  ->globalToLocalTrans(data.gctx)
92  .translation() -
93  (hs.bucket->coveredMax() * Amg::Vector3D::UnitY());
94  const double tanThetaLeft = leftSide.y() / leftSide.z();
95  const double tanThetaRight = rightSide.y() / rightSide.z();
96  hs.searchWindowTanAngle = {tanThetaLeft, tanThetaRight};
97  hs.searchWindowIntercept = {hs.bucket->coveredMin(),
98  hs.bucket->coveredMax()};
99  }
100  return StatusCode::SUCCESS;
101 }
102 
104  MuonHoughEventData& data) const {
105  HoughPlaneConfig cfg;
106  cfg.nBinsX = m_nBinsTanTheta;
107  cfg.nBinsY = m_nBinsIntercept;
108  ActsPeakFinderForMuonCfg peakFinderCfg;
109  peakFinderCfg.fractionCutoff = 0.6;
110  peakFinderCfg.threshold = 3;
111  peakFinderCfg.minSpacingBetweenPeaks = {0., 30.};
112  data.houghPlane = std::make_unique<HoughPlane>(cfg);
113  data.peakFinder = std::make_unique<ActsPeakFinderForMuon>(peakFinderCfg);
114 
115  return StatusCode::SUCCESS;
116 }
117 
119  MuonHoughEventData& data, HoughSetupForBucket& bucket) const {
121 
122  double chamberCenter = 0.5 * (bucket.searchWindowIntercept.first +
123  bucket.searchWindowIntercept.second);
124  // build a symmetric window around the (geometric) chamber center so that
125  // the bin width is equivalent to our target resolution
126  double searchStart =
127  chamberCenter - 0.5 * data.houghPlane->nBinsY() * m_targetResoIntercept;
128  double searchEnd =
129  chamberCenter + 0.5 * data.houghPlane->nBinsY() * m_targetResoIntercept;
130  // Protection for very wide buckets - if the search space does not cover all
131  // of the bucket, widen the bin size so that we cover everything
132 
133 
134  searchStart = std::min(searchStart, bucket.searchWindowIntercept.first -
136  searchEnd = std::max(searchEnd, bucket.searchWindowIntercept.second +
138  // also treat tan(theta)
139  double tanThetaMean = 0.5 * (bucket.searchWindowTanAngle.first +
140  bucket.searchWindowTanAngle.second);
141  double searchStartTanTheta =
142  tanThetaMean - 0.5 * data.houghPlane->nBinsX() * m_targetResoTanTheta;
143  double searchEndTanTheta =
144  tanThetaMean + 0.5 * data.houghPlane->nBinsX() * m_targetResoTanTheta;
145  searchStartTanTheta =
146  std::min(searchStartTanTheta,
148  searchEndTanTheta =
149  std::max(searchEndTanTheta, bucket.searchWindowTanAngle.second +
151 
152  data.currAxisRanges = Acts::HoughTransformUtils::HoughAxisRanges{
153  searchStartTanTheta, searchEndTanTheta, searchStart, searchEnd};
154  data.houghPlane->reset();
155  for (const HoughHitType& hit : *(bucket.bucket)) {
156  fillFromSpacePoint(data, hit);
157  }
158  auto maxima =
159  data.peakFinder->findPeaks(*(data.houghPlane), data.currAxisRanges);
160  if (maxima.empty()) {
161  return StatusCode::SUCCESS;
162  }
163  for (const auto& max : maxima) {
165  std::vector<HoughHitType> hitList;
166  hitList.insert(hitList.end(), max.hitIdentifiers.begin(),
167  max.hitIdentifiers.end());
168  size_t nHits = hitList.size();
169  extendWithPhiHits(hitList, bucket);
170  data.maxima.emplace_back(max.x, max.y, nHits, std::move(hitList));
171  }
172 
173  return StatusCode::SUCCESS;
174 }
176  MuonHoughEventData& data, const MuonR4::HoughHitType& SP) const {
177  if (SP->primaryMeasurement()->type() ==
179  data.houghPlane->fill<HoughHitType>(
180  SP, data.currAxisRanges, HoughHelpers::Eta::houghParamMdtLeft,
182  data.houghPlane->fill<HoughHitType>(
183  SP, data.currAxisRanges, HoughHelpers::Eta::houghParamMdtRight,
185  } else {
186  if (SP->measuresEta()) {
187  data.houghPlane->fill<HoughHitType>(
188  SP, data.currAxisRanges, HoughHelpers::Eta::houghParamStrip,
190  }
191  }
192 }
194  std::vector<HoughHitType>& hitList, HoughSetupForBucket& bucket) const {
195  std::copy_if(bucket.bucket->begin(), bucket.bucket->end(),
196  std::back_inserter(hitList),
197  [](MuonR4::HoughHitType hit) { return !hit->measuresEta(); });
198 }
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
MuonR4::MuonEtaHoughTransformAlg::m_maxima
SG::WriteHandleKey< StationHoughMaxContainer > m_maxima
Definition: MuonEtaHoughTransformAlg.h:100
MuonR4::HoughHelpers::Eta::houghWidthStrip
double houghWidthStrip(double tanTheta, const MuonR4::HoughHitType &strip)
Uncertainty parametrisation for strip measurements.
Definition: HoughHelperFunctions.cxx:27
MuonR4::MuonEtaHoughTransformAlg::retrieveContainer
StatusCode retrieveContainer(const EventContext &ctx, const SG::ReadHandleKey< ContainerType > &key, const ContainerType *&contToPush) const
Helper method to fetch data from StoreGate.
Definition: MuonEtaHoughTransformAlg.cxx:27
max
#define max(a, b)
Definition: cfImp.cxx:41
MuonR4::MuonEtaHoughTransformAlg::m_spacePointKey
SG::ReadHandleKey< MuonR4::MuonSpacePointContainer > m_spacePointKey
Definition: MuonEtaHoughTransformAlg.h:97
MuonR4::MuonEtaHoughTransformAlg::m_geoCtxKey
SG::ReadHandleKey< ActsGeometryContext > m_geoCtxKey
Definition: MuonEtaHoughTransformAlg.h:103
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
MuonR4::StationHoughMaxima
StationHoughResults< HoughMaximum > StationHoughMaxima
Definition: StationHoughMaxima.h:54
MuonR4::HoughHitType
std::shared_ptr< MuonR4::MuonSpacePoint > HoughHitType
Definition: MuonHoughDefs.h:20
HoughHelperFunctions.h
MuonR4::MuonEtaHoughTransformAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: MuonEtaHoughTransformAlg.cxx:42
MuonR4::ActsPeakFinderForMuonCfg
Acts::HoughTransformUtils::PeakFinders::IslandsAroundMaxConfig ActsPeakFinderForMuonCfg
Definition: MuonHoughDefs.h:33
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
MuonR4::MuonHoughEventData_impl::HoughSetupForBucket::searchWindowIntercept
std::pair< double, double > searchWindowIntercept
Definition: MuonHoughEventData.h:51
SG::ReadHandleKey< ContainerType >
ReadCondHandle.h
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
MuonR4::MuonEtaHoughTransformAlg::m_targetResoIntercept
DoubleProperty m_targetResoIntercept
Definition: MuonEtaHoughTransformAlg.h:84
MuonR4::MuonEtaHoughTransformAlg::m_targetResoTanTheta
DoubleProperty m_targetResoTanTheta
Definition: MuonEtaHoughTransformAlg.h:82
MuonR4::MuonSpacePointBucket
: The muon space point bucket represents a collection of points that will bre processed together in t...
Definition: MuonSpacePointContainer.h:22
MuonR4::MuonHoughEventData_impl
Templated event data class for the phase-2 muon hough transform.
Definition: MuonHoughEventData.h:34
CreatePhysValWebPage.hs
hs
Definition: CreatePhysValWebPage.py:107
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
MuonR4::HoughHelpers::Eta::houghWidthMdt
double houghWidthMdt(double tanTheta, const MuonR4::HoughHitType &dc)
uncertainty parametrisation for drift circles
Definition: HoughHelperFunctions.cxx:21
MuonR4::MuonEtaHoughTransformAlg::MuonEtaHoughTransformAlg
MuonEtaHoughTransformAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: MuonEtaHoughTransformAlg.cxx:14
MuonChamber.h
AnalysisUtils::copy_if
Out copy_if(In first, const In &last, Out res, const Pred &p)
Definition: IFilterUtils.h:30
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
MuonR4::HoughHelpers::Eta::houghParamMdtLeft
double houghParamMdtLeft(double tanTheta, const MuonR4::HoughHitType &dc)
left-side straight line parametrisation for drift circles
Definition: HoughHelperFunctions.cxx:9
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
MuonR4::MuonEtaHoughTransformAlg::m_nBinsTanTheta
IntegerProperty m_nBinsTanTheta
Definition: MuonEtaHoughTransformAlg.h:92
min
#define min(a, b)
Definition: cfImp.cxx:40
MuonR4::MuonEtaHoughTransformAlg::m_nBinsIntercept
IntegerProperty m_nBinsIntercept
Definition: MuonEtaHoughTransformAlg.h:94
MuonR4::MuonEtaHoughTransformAlg::extendWithPhiHits
void extendWithPhiHits(std::vector< HoughHitType > &hitList, HoughSetupForBucket &bucket) const
extend a maximum with all compatible (pure) phi hits.
Definition: MuonEtaHoughTransformAlg.cxx:193
MuonR4::MuonEtaHoughTransformAlg::initialize
virtual StatusCode initialize() override
Definition: MuonEtaHoughTransformAlg.cxx:18
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
MuonR4::MuonEtaHoughTransformAlg::m_minSigmasSearchIntercept
DoubleProperty m_minSigmasSearchIntercept
Definition: MuonEtaHoughTransformAlg.h:90
WriteCaloSwCorrections.cfg
cfg
Definition: WriteCaloSwCorrections.py:23
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
MuonR4::MuonHoughEventData_impl::HoughSetupForBucket
Hough transform configuration for one bucket of the search space.
Definition: MuonHoughEventData.h:45
MuonR4
The CsvMuonSimHitDumper reads a Simulation Hit container for muons and dumps information to csv files...
Definition: MuonSpacePoint.h:11
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
MuonR4::MuonEtaHoughTransformAlg::m_minSigmasSearchTanTheta
DoubleProperty m_minSigmasSearchTanTheta
Definition: MuonEtaHoughTransformAlg.h:87
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
MuonR4::MuonEtaHoughTransformAlg::fillFromSpacePoint
void fillFromSpacePoint(MuonHoughEventData &data, const MuonR4::HoughHitType &SP) const
fill the accumulator from a given space point.
Definition: MuonEtaHoughTransformAlg.cxx:175
MuonR4::HoughHelpers::Eta::houghParamMdtRight
double houghParamMdtRight(double tanTheta, const MuonR4::HoughHitType &dc)
right-side straight line parametrisation for drift circles
Definition: HoughHelperFunctions.cxx:13
MuonEtaHoughTransformAlg.h
MuonR4::MuonEtaHoughTransformAlg::prepareHoughPlane
StatusCode prepareHoughPlane(MuonHoughEventData &data) const
prepare the accumulator and the peak finder once per event
Definition: MuonEtaHoughTransformAlg.cxx:103
MuonR4::HoughHelpers::Eta::houghParamStrip
double houghParamStrip(double tanTheta, const MuonR4::HoughHitType &strip)
straight line parametrisation for strip detector measurements
Definition: HoughHelperFunctions.cxx:17
MuonR4::MuonEtaHoughTransformAlg::preProcess
StatusCode preProcess(MuonHoughEventData &data, const MuonSpacePointContainer &spacePoints) const
pre-processing method called once per event.
Definition: MuonEtaHoughTransformAlg.cxx:74
MuonR4::MuonEtaHoughTransformAlg::processBucket
StatusCode processBucket(MuonHoughEventData &data, HoughSetupForBucket &currentBucket) const
process a bucket.
Definition: MuonEtaHoughTransformAlg.cxx:118
MuonR4::MuonHoughEventData_impl::HoughSetupForBucket::searchWindowTanAngle
std::pair< double, double > searchWindowTanAngle
Definition: MuonHoughEventData.h:53
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
MuonR4::MuonHoughEventData_impl::HoughSetupForBucket::bucket
const MuonSpacePointBucket * bucket
Definition: MuonHoughEventData.h:47
xAOD::UncalibMeasType::MdtDriftCircleType
@ MdtDriftCircleType
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37