ATLAS Offline Software
PatternCnvAlg.cxx
Go to the documentation of this file.
1 
2 /*
3  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4 */
5 #include "PatternCnvAlg.h"
6 
8 
9 namespace{
11  using LayIdx_t = Muon::MuonStationIndex::LayerIndex;
12  using LegacyMax = MuonHough::MuonLayerHough::Maximum;
13 }
14 
15 namespace MuonR4{
16 
18  ATH_CHECK(m_idHelperSvc.retrieve());
19 
20  ATH_CHECK(m_keyTgc.initialize(!m_keyTgc.empty()));
21  ATH_CHECK(m_keyRpc.initialize(!m_keyRpc.empty()));
22  ATH_CHECK(m_keyMdt.initialize(!m_keyMdt.empty()));
23  ATH_CHECK(m_keysTgc.initialize(!m_keysTgc.empty()));
24  ATH_CHECK(m_keyMM.initialize(!m_keyMM.empty()));
25 
26  ATH_CHECK(m_combiKey.initialize());
28  ATH_CHECK(m_readKeys.initialize());
30  return StatusCode::SUCCESS;
31  }
32  template <class ContainerType>
33  StatusCode PatternCnvAlg::retrieveContainer(const EventContext& ctx,
35  const ContainerType*& contToPush) const {
36  contToPush = nullptr;
37  if (key.empty()) {
38  ATH_MSG_VERBOSE("No key has been parsed for object "<< typeid(ContainerType).name());
39  return StatusCode::SUCCESS;
40  }
41  SG::ReadHandle<ContainerType> readHandle{key, ctx};
42  ATH_CHECK(readHandle.isPresent());
43  contToPush = readHandle.cptr();
44  return StatusCode::SUCCESS;
45  }
46 
47 
48  StatusCode PatternCnvAlg::execute(const EventContext& ctx) const {
49 
50 
51  auto translatedPatterns = std::make_unique<MuonPatternCombinationCollection>();
52  auto translatedHough = std::make_unique<Muon::HoughDataPerSectorVec>();
53 
55  const SegmentSeedContainer* translateMe{nullptr};
56  ATH_CHECK(retrieveContainer(ctx, key, translateMe));
57  ATH_CHECK(convertSeed(ctx, *translateMe, * translatedPatterns, *translatedHough));
58 
59  }
60 
62  ATH_CHECK(patternHandle.record(std::move(translatedPatterns)));
63 
65  ATH_CHECK(houghDataHandle.record(std::move(translatedHough)));
66 
67 
68  return StatusCode::SUCCESS;
69  }
70  StatusCode PatternCnvAlg::convertSeed(const EventContext& ctx,
71  const SegmentSeedContainer& seedContainer,
72  ::MuonPatternCombinationCollection& patternContainer,
73  Muon::HoughDataPerSectorVec& houghDataSec) const {
74 
75  const Muon::RpcPrepDataContainer* rpcPrds{nullptr};
76  const Muon::MdtPrepDataContainer* mdtPrds{nullptr};
77  const Muon::TgcPrepDataContainer* tgcPrds{nullptr};
78  const Muon::sTgcPrepDataContainer* stgcPrds{nullptr};
79  const Muon::MMPrepDataContainer* mmPrds{nullptr};
80  ATH_CHECK(retrieveContainer(ctx, m_keyMdt, mdtPrds));
81  ATH_CHECK(retrieveContainer(ctx, m_keyRpc, rpcPrds));
82  ATH_CHECK(retrieveContainer(ctx, m_keyTgc, tgcPrds));
83 
84  ATH_CHECK(retrieveContainer(ctx, m_keysTgc, stgcPrds));
85  ATH_CHECK(retrieveContainer(ctx, m_keyMM, mmPrds));
86 
87  const ActsGeometryContext* gctx{nullptr};
89 
90 
91 
92  for (const SegmentSeed* seed: seedContainer) {
93  const Amg::Transform3D& localToGlobal = seed->msSector()->localToGlobalTrans(*gctx);
94 
95  std::unordered_set<Identifier> channelsInMax{};
96  for (const HoughHitType& hit : seed->getHitsInMax()) {
97  channelsInMax.insert(hit->identify());
98  if (hit->secondaryMeasurement()) {
99  channelsInMax.insert(xAOD::identify(hit->secondaryMeasurement()));
100  }
101  }
102  std::vector<const Trk::PrepRawData*> trkHits{};
103  trkHits.reserve(channelsInMax.size());
104  using techIdx_t = Muon::MuonStationIndex::TechnologyIndex;
105  for (const Identifier& chId : channelsInMax){
106  switch (m_idHelperSvc->technologyIndex(chId)){
107  case techIdx_t::MDT:
108  trkHits.push_back(fetchPrd(chId, mdtPrds));
109  break;
110  case techIdx_t::RPC:
111  trkHits.push_back(fetchPrd(chId, rpcPrds));
112  break;
113  case techIdx_t::TGC:
114  trkHits.push_back(fetchPrd(chId, tgcPrds));
115  break;
116  case techIdx_t::MM:
117  trkHits.push_back(fetchPrd(chId, mmPrds));
118  break;
119  case techIdx_t::STGC:
120  trkHits.push_back(fetchPrd(chId, stgcPrds));
121  break;
122  default:
123  ATH_MSG_WARNING("Cscs are not part of the new paradigms. Where are they now coming from? "
124  <<m_idHelperSvc->toString(chId));
125  };
126  }
127  if (std::find(trkHits.begin(), trkHits.end(), nullptr) != trkHits.end()){
128  ATH_MSG_ERROR("Errors during the Prd conversion occured");
129  return StatusCode::FAILURE;
130  }
131  const Amg::Vector3D maxPos{seed->positionInChamber()};
132  const Amg::Vector3D locDir{seed->directionInChamber()};
133 
134  Trk::TrackSurfaceIntersection isect{localToGlobal * maxPos, localToGlobal.linear()*locDir,0.};
135  ATH_MSG_VERBOSE("Intersection at "<<m_idHelperSvc->toStringChamber(trkHits[0]->identify())<<" "<<Amg::toString(isect.position())<<" "<<Amg::toString(isect.direction())
136  <<Amg::angle(isect.position(), isect.direction()) / Gaudi::Units::deg );
137  Muon::MuonPatternChamberIntersect chamberIsect{std::move(isect), std::move(trkHits)};
138 
139  convertMaximum(chamberIsect, houghDataSec);
140  std::vector<Muon::MuonPatternChamberIntersect> chamberData{std::move(chamberIsect)};
141 
142  auto patternCombi = std::make_unique<Muon::MuonPatternCombination>(nullptr, std::move(chamberData));
143  patternContainer.push_back(std::move(patternCombi));
144  }
145 
146  return StatusCode::SUCCESS;
147  }
149  Muon::HoughDataPerSectorVec& houghDataSec) const {
150 
151  if (houghDataSec.vec.empty()) {
152  constexpr unsigned int nSectors = 16;
153  houghDataSec.vec.resize(nSectors);
154  for (unsigned int i = 0; i < nSectors; ++i) {
155  houghDataSec.vec[i].sector = i + 1;
156  }
157  }
158 
159  const Identifier chId = intersect.prepRawDataVec()[0]->identify();
160  const DetIdx_t regionIndex = m_idHelperSvc->regionIndex(chId);
161  const LayIdx_t layerIndex = m_idHelperSvc->layerIndex(chId);
162  const unsigned int sectorLayerHash = Muon::MuonStationIndex::sectorLayerHash(regionIndex, layerIndex);
163  const int sector = m_idHelperSvc->sector(chId);
164  const bool barrel = !m_idHelperSvc->isEndcap(chId);
165 
166  auto convertedMax = std::make_unique<LegacyMax>();
167  convertedMax->hough = &houghDataSec.detectorHoughTransforms.hough(sector, regionIndex, layerIndex);
168  convertedMax->theta = intersect.intersectDirection().theta();
169  for (const Trk::PrepRawData* prd : intersect.prepRawDataVec()) {
170  std::unique_ptr<MuonHough::Hit> hit{};
172  if (m_idHelperSvc->isMdt(prd->identify())){
173  gp = static_cast<const Muon::MdtPrepData*>(prd)->globalPosition();
174  } else {
175  gp = static_cast<const Muon::MuonCluster*>(prd)->globalPosition();
176  }
177 
178  // TODO: Might need some fine-tuning if the hough hit information is needed downstream
179  hit = std::make_unique<MuonHough::Hit>(0, barrel ? gp.perp() : gp.z(),
180  barrel ? gp.z() : gp.perp(),
181  barrel ? gp.z() : gp.perp(),
182  1., nullptr, prd);
183  convertedMax->hits.emplace_back(std::move(hit));
184  }
185  houghDataSec.vec[sector-1].maxVec[sectorLayerHash].push_back(std::move(convertedMax));
186  }
187 
188 
189  template <class PrdType>
190  const PrdType* PatternCnvAlg::fetchPrd(const Identifier& prdId,
191  const Muon::MuonPrepDataContainerT<PrdType>* prdContainer) const {
192  if (!prdContainer) {
193  ATH_MSG_ERROR("Cannot fetch a prep data object as the container given for "<<
194  m_idHelperSvc->toString(prdId)<<" is a nullptr");
195  return nullptr;
196  }
197  const Muon::MuonPrepDataCollection<PrdType>* coll = prdContainer->indexFindPtr(m_idHelperSvc->moduleHash(prdId));
198  if (!coll) {
199  ATH_MSG_ERROR("No prep data collection where "<<m_idHelperSvc->toString(prdId)<<" can reside in.");
200  return nullptr;
201  }
202  for (const PrdType* prd : *coll) {
203  if (prd->identify() == prdId){
204  return prd;
205  }
206  }
207  ATH_MSG_ERROR("There is no measurement "<<m_idHelperSvc->toString(prdId));
208  return nullptr;
209  }
210 }
MuonR4::PatternCnvAlg::convertSeed
StatusCode convertSeed(const EventContext &ctx, const SegmentSeedContainer &seedContainer, ::MuonPatternCombinationCollection &patternContainer, Muon::HoughDataPerSectorVec &houghDataSec) const
Converts each segment seed first into a PatternCombination - serving as input for the legacy segment ...
Definition: PatternCnvAlg.cxx:70
TGC
@ TGC
Definition: RegSelEnums.h:33
MuonHough::MuonDetectorHough::hough
MuonLayerHough & hough(int sector, DetRegIdx region, LayIdx layer)
access precision transform
Definition: MuonRegionHough.h:74
Muon::MuonPrepDataContainer
Template for Muon PRD containers (which are basically collections of MuonPrepDataCollections).
Definition: MuonPrepDataContainer.h:42
xAOD::identify
const Identifier & identify(const UncalibratedMeasurement *meas)
Returns the associated identifier from the muon measurement.
Definition: MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonPrepData/Root/UtilFunctions.cxx:61
STGC
@ STGC
Definition: RegSelEnums.h:39
MuonR4::PatternCnvAlg::m_geoCtxKey
SG::ReadHandleKey< ActsGeometryContext > m_geoCtxKey
Definition: PatternCnvAlg.h:81
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
Amg::angle
double angle(const Amg::Vector3D &v1, const Amg::Vector3D &v2)
calculates the opening angle between two vectors
Definition: GeoPrimitivesHelpers.h:41
MuonR4::PatternCnvAlg::m_keyTgc
SG::ReadHandleKey< Muon::TgcPrepDataContainer > m_keyTgc
Prep data container keys.
Definition: PatternCnvAlg.h:74
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
Muon::MuonStationIndex::LayerIndex
LayerIndex
enum to classify the different layers in the muon spectrometer
Definition: MuonStationIndex.h:38
Muon::MuonStationIndex::sectorLayerHash
static unsigned int sectorLayerHash(DetectorRegionIndex detectorRegionIndex, LayerIndex layerIndex)
create a hash out of region and layer
Definition: MuonStationIndex.cxx:226
MuonR4::PatternCnvAlg::m_dataPerSecKey
SG::WriteHandleKey< Muon::HoughDataPerSectorVec > m_dataPerSecKey
Definition: PatternCnvAlg.h:84
deg
#define deg
Definition: SbPolyhedron.cxx:17
MM
@ MM
Definition: RegSelEnums.h:38
MuonR4::PatternCnvAlg::m_readKeys
SG::ReadHandleKeyArray< SegmentSeedContainer > m_readKeys
Definition: PatternCnvAlg.h:80
Trk::TrackSurfaceIntersection
Definition: TrackSurfaceIntersection.h:32
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::ReadHandleKey< ContainerType >
MuonHough::MuonLayerHough::Maximum
struct representing the maximum in the hough space
Definition: MuonLayerHough.h:64
Amg::toString
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Definition: GeoPrimitivesToStringConverter.h:40
MuonR4::PatternCnvAlg::fetchPrd
const PrdType * fetchPrd(const Identifier &prdId, const Muon::MuonPrepDataContainerT< PrdType > *prdContainer) const
Definition: PatternCnvAlg.cxx:190
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
Muon::MuonPatternChamberIntersect
This class holds information needed for the Moore and MoMu pattern recognition for a muon chamber.
Definition: MuonPatternChamberIntersect.h:38
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
MuonR4::PatternCnvAlg::retrieveContainer
StatusCode retrieveContainer(const EventContext &ctx, const SG::ReadHandleKey< ContType > &key, const ContType *&contPtr) const
Loads a container from the StoreGate and returns whether the retrieval is successful.
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Muon::HoughDataPerSectorVec::vec
std::vector< HoughDataPerSec > vec
Definition: HoughDataPerSec.h:66
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
Muon::MuonPrepDataCollection
Template to hold collections of MuonPrepRawData objects.
Definition: MuonPrepDataCollection.h:46
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
MuonR4::PatternCnvAlg::m_combiKey
SG::WriteHandleKey<::MuonPatternCombinationCollection > m_combiKey
Definition: PatternCnvAlg.h:83
ActsGeometryContext
Include the GeoPrimitives which need to be put first.
Definition: ActsGeometryContext.h:27
MuonR4::SpacePoint
The muon space point is the combination of two uncalibrated measurements one of them measures the eta...
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonSpacePoint/MuonSpacePoint/SpacePoint.h:18
Muon::HoughDataPerSectorVec::detectorHoughTransforms
MuonHough::MuonDetectorHough detectorHoughTransforms
Definition: HoughDataPerSec.h:67
Muon::MuonStationIndex::DetectorRegionIndex
DetectorRegionIndex
enum to classify the different layers in the muon spectrometer
Definition: MuonStationIndex.h:47
Trk::PrepRawData
Definition: PrepRawData.h:62
MuonHoughDefs.h
RPC
@ RPC
Definition: RegSelEnums.h:32
MuonR4::PatternCnvAlg::m_keyRpc
SG::ReadHandleKey< Muon::RpcPrepDataContainer > m_keyRpc
Definition: PatternCnvAlg.h:75
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
Muon::MdtPrepData
Class to represent measurements from the Monitored Drift Tubes.
Definition: MdtPrepData.h:33
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
python.copyTCTOutput.locDir
locDir
Definition: copyTCTOutput.py:113
MuonR4
This header ties the generic definitions in this package.
Definition: HoughEventData.h:16
Muon::HoughDataPerSectorVec
Definition: HoughDataPerSec.h:65
IdentifiableContainerMT::indexFindPtr
virtual const T * indexFindPtr(IdentifierHash hashId) const override final
return pointer on the found entry or null if out of range using hashed index - fast version,...
Definition: IdentifiableContainerMT.h:289
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
MuonR4::PatternCnvAlg::convertMaximum
void convertMaximum(const Muon::MuonPatternChamberIntersect &intersect, Muon::HoughDataPerSectorVec &houghDataSec) const
: Converts the maximum back into the HoughDataPersector
Definition: PatternCnvAlg.cxx:148
MuonR4::PatternCnvAlg::m_keyMM
SG::ReadHandleKey< Muon::MMPrepDataContainer > m_keyMM
Definition: PatternCnvAlg.h:78
Amg::intersect
std::optional< double > intersect(const AmgVector(N)&posA, const AmgVector(N)&dirA, const AmgVector(N)&posB, const AmgVector(N)&dirB)
Calculates the point B' along the line B that's closest to a second line A.
Definition: GeoPrimitivesHelpers.h:347
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
MuonR4::PatternCnvAlg::initialize
StatusCode initialize() override final
Definition: PatternCnvAlg.cxx:17
MuonR4::SegmentSeed
Representation of a segment seed (a fully processed hough maximum) produced by the hough transform.
Definition: SegmentSeed.h:14
MuonR4::PatternCnvAlg::m_keyMdt
SG::ReadHandleKey< Muon::MdtPrepDataContainer > m_keyMdt
Definition: PatternCnvAlg.h:76
Muon::MuonCluster
Class representing clusters in the muon system.
Definition: MuonSpectrometer/MuonReconstruction/MuonRecEvent/MuonPrepRawData/MuonPrepRawData/MuonCluster.h:37
MuonR4::PatternCnvAlg::execute
StatusCode execute(const EventContext &ctx) const override final
Definition: PatternCnvAlg.cxx:48
MuonR4::PatternCnvAlg::m_keysTgc
SG::ReadHandleKey< Muon::sTgcPrepDataContainer > m_keysTgc
Definition: PatternCnvAlg.h:77
Muon::MuonStationIndex::TechnologyIndex
TechnologyIndex
enum to classify the different layers in the muon spectrometer
Definition: MuonStationIndex.h:54
PatternCnvAlg.h
MuonR4::PatternCnvAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: PatternCnvAlg.h:71
MDT
@ MDT
Definition: RegSelEnums.h:31
generate::Zero
void Zero(TH1D *hin)
Definition: generate.cxx:32
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
Identifier
Definition: IdentifierFieldParser.cxx:14