Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
33  StatusCode PatternCnvAlg::execute(const EventContext& ctx) const {
34 
35 
36  auto translatedPatterns = std::make_unique<MuonPatternCombinationCollection>();
37  auto translatedHough = std::make_unique<Muon::HoughDataPerSectorVec>();
38 
40  const SegmentSeedContainer* translateMe{nullptr};
41  ATH_CHECK(SG::get(translateMe, key, ctx));
42  ATH_CHECK(convertSeed(ctx, *translateMe, * translatedPatterns, *translatedHough));
43 
44  }
45 
47  ATH_CHECK(patternHandle.record(std::move(translatedPatterns)));
48 
50  ATH_CHECK(houghDataHandle.record(std::move(translatedHough)));
51 
52 
53  return StatusCode::SUCCESS;
54  }
55  StatusCode PatternCnvAlg::convertSeed(const EventContext& ctx,
56  const SegmentSeedContainer& seedContainer,
57  ::MuonPatternCombinationCollection& patternContainer,
58  Muon::HoughDataPerSectorVec& houghDataSec) const {
59 
60  const Muon::RpcPrepDataContainer* rpcPrds{nullptr};
61  const Muon::MdtPrepDataContainer* mdtPrds{nullptr};
62  const Muon::TgcPrepDataContainer* tgcPrds{nullptr};
63  const Muon::sTgcPrepDataContainer* stgcPrds{nullptr};
64  const Muon::MMPrepDataContainer* mmPrds{nullptr};
65  ATH_CHECK(SG::get(mdtPrds, m_keyMdt, ctx));
66  ATH_CHECK(SG::get(rpcPrds, m_keyRpc, ctx));
67  ATH_CHECK(SG::get(tgcPrds, m_keyTgc, ctx));
68  ATH_CHECK(SG::get(stgcPrds, m_keysTgc, ctx));
69  ATH_CHECK(SG::get(mmPrds, m_keyMM, ctx));
70 
71  const ActsGeometryContext* gctx{nullptr};
72  ATH_CHECK(SG::get(gctx, m_geoCtxKey, ctx));
73 
74 
75 
76  for (const SegmentSeed* seed: seedContainer) {
77  const Amg::Transform3D& localToGlobal = seed->msSector()->localToGlobalTrans(*gctx);
78 
79  std::unordered_set<Identifier> channelsInMax{};
80  for (const HoughHitType& hit : seed->getHitsInMax()) {
81  channelsInMax.insert(hit->identify());
82  if (hit->secondaryMeasurement()) {
83  channelsInMax.insert(xAOD::identify(hit->secondaryMeasurement()));
84  }
85  }
86  std::vector<const Trk::PrepRawData*> trkHits{};
87  trkHits.reserve(channelsInMax.size());
89  for (const Identifier& chId : channelsInMax){
90  switch (m_idHelperSvc->technologyIndex(chId)){
91  case techIdx_t::MDT:
92  trkHits.push_back(fetchPrd(chId, mdtPrds));
93  break;
94  case techIdx_t::RPC:
95  trkHits.push_back(fetchPrd(chId, rpcPrds));
96  break;
97  case techIdx_t::TGC:
98  trkHits.push_back(fetchPrd(chId, tgcPrds));
99  break;
100  case techIdx_t::MM:
101  trkHits.push_back(fetchPrd(chId, mmPrds));
102  break;
103  case techIdx_t::STGC:
104  trkHits.push_back(fetchPrd(chId, stgcPrds));
105  break;
106  default:
107  ATH_MSG_WARNING("Cscs are not part of the new paradigms. Where are they now coming from? "
108  <<m_idHelperSvc->toString(chId));
109  };
110  }
111  if (std::find(trkHits.begin(), trkHits.end(), nullptr) != trkHits.end()){
112  ATH_MSG_ERROR("Errors during the Prd conversion occured");
113  return StatusCode::FAILURE;
114  }
115  const Amg::Vector3D maxPos{seed->positionInChamber()};
116  const Amg::Vector3D locDir{seed->directionInChamber()};
117 
118  Trk::TrackSurfaceIntersection isect{localToGlobal * maxPos, localToGlobal.linear()*locDir,0.};
119  ATH_MSG_VERBOSE("Intersection at "<<m_idHelperSvc->toStringChamber(trkHits[0]->identify())<<" "<<Amg::toString(isect.position())<<" "<<Amg::toString(isect.direction())
120  <<Amg::angle(isect.position(), isect.direction()) / Gaudi::Units::deg );
121  Muon::MuonPatternChamberIntersect chamberIsect{std::move(isect), std::move(trkHits)};
122 
123  convertMaximum(chamberIsect, houghDataSec);
124  std::vector<Muon::MuonPatternChamberIntersect> chamberData{std::move(chamberIsect)};
125 
126  auto patternCombi = std::make_unique<Muon::MuonPatternCombination>(nullptr, std::move(chamberData));
127  patternContainer.push_back(std::move(patternCombi));
128  }
129 
130  return StatusCode::SUCCESS;
131  }
133  Muon::HoughDataPerSectorVec& houghDataSec) const {
134 
135  if (houghDataSec.vec.empty()) {
136  constexpr unsigned int nSectors = 16;
137  houghDataSec.vec.resize(nSectors);
138  for (unsigned int i = 0; i < nSectors; ++i) {
139  houghDataSec.vec[i].sector = i + 1;
140  }
141  }
142 
143  const Identifier chId = intersect.prepRawDataVec()[0]->identify();
144  const DetIdx_t regionIndex = m_idHelperSvc->regionIndex(chId);
145  const LayIdx_t layerIndex = m_idHelperSvc->layerIndex(chId);
146  const unsigned int sectorLayerHash = Muon::MuonStationIndex::sectorLayerHash(regionIndex, layerIndex);
147  const int sector = m_idHelperSvc->sector(chId);
148  const bool barrel = !m_idHelperSvc->isEndcap(chId);
149 
150  auto convertedMax = std::make_unique<LegacyMax>();
151  convertedMax->hough = &houghDataSec.detectorHoughTransforms.hough(sector, regionIndex, layerIndex);
152  convertedMax->theta = intersect.intersectDirection().theta();
153  for (const Trk::PrepRawData* prd : intersect.prepRawDataVec()) {
154  std::unique_ptr<MuonHough::Hit> hit{};
156  if (m_idHelperSvc->isMdt(prd->identify())){
157  gp = static_cast<const Muon::MdtPrepData*>(prd)->globalPosition();
158  } else {
159  gp = static_cast<const Muon::MuonCluster*>(prd)->globalPosition();
160  }
161 
162  // TODO: Might need some fine-tuning if the hough hit information is needed downstream
163  hit = std::make_unique<MuonHough::Hit>(0, barrel ? gp.perp() : gp.z(),
164  barrel ? gp.z() : gp.perp(),
165  barrel ? gp.z() : gp.perp(),
166  1., nullptr, prd);
167  convertedMax->hits.emplace_back(std::move(hit));
168  }
169  houghDataSec.vec[sector-1].maxVec[sectorLayerHash].push_back(std::move(convertedMax));
170  }
171 
172 
173  template <class PrdType>
174  const PrdType* PatternCnvAlg::fetchPrd(const Identifier& prdId,
175  const Muon::MuonPrepDataContainerT<PrdType>* prdContainer) const {
176  if (!prdContainer) {
177  ATH_MSG_ERROR("Cannot fetch a prep data object as the container given for "<<
178  m_idHelperSvc->toString(prdId)<<" is a nullptr");
179  return nullptr;
180  }
181  const Muon::MuonPrepDataCollection<PrdType>* coll = prdContainer->indexFindPtr(m_idHelperSvc->moduleHash(prdId));
182  if (!coll) {
183  ATH_MSG_ERROR("No prep data collection where "<<m_idHelperSvc->toString(prdId)<<" can reside in.");
184  return nullptr;
185  }
186  for (const PrdType* prd : *coll) {
187  if (prd->identify() == prdId){
188  return prd;
189  }
190  }
191  ATH_MSG_ERROR("There is no measurement "<<m_idHelperSvc->toString(prdId));
192  return nullptr;
193  }
194 }
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:55
TGC
@ TGC
Definition: RegSelEnums.h:33
Muon::MuonStationIndex::LayerIndex
LayerIndex
enum to classify the different layers in the muon spectrometer
Definition: MuonStationIndex.h:38
MuonHough::MuonDetectorHough::hough
MuonLayerHough & hough(int sector, DetRegIdx region, LayIdx layer)
access precision transform
Definition: MuonRegionHough.h:76
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:87
STGC
@ STGC
Definition: RegSelEnums.h:39
MuonR4::PatternCnvAlg::m_geoCtxKey
SG::ReadHandleKey< ActsGeometryContext > m_geoCtxKey
Definition: PatternCnvAlg.h:70
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:63
Muon::MuonStationIndex::sectorLayerHash
unsigned int sectorLayerHash(DetectorRegionIndex detectorRegionIndex, LayerIndex layerIndex)
create a hash out of region and layer
Muon::MuonStationIndex::TechnologyIndex
TechnologyIndex
enum to classify the different layers in the muon spectrometer
Definition: MuonStationIndex.h:54
MuonR4::PatternCnvAlg::m_dataPerSecKey
SG::WriteHandleKey< Muon::HoughDataPerSectorVec > m_dataPerSecKey
Definition: PatternCnvAlg.h:73
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:69
Trk::TrackSurfaceIntersection
Definition: TrackSurfaceIntersection.h:32
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::ReadHandleKey
Property holding a SG store/key/clid from which a ReadHandle is made.
Definition: StoreGate/StoreGate/ReadHandleKey.h:39
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:174
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
SG::get
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
Definition: ReadCondHandle.h:287
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
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:72
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
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:64
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:73
MuonR4::PatternCnvAlg::convertMaximum
void convertMaximum(const Muon::MuonPatternChamberIntersect &intersect, Muon::HoughDataPerSectorVec &houghDataSec) const
: Converts the maximum back into the HoughDataPersector
Definition: PatternCnvAlg.cxx:132
MuonR4::PatternCnvAlg::m_keyMM
SG::ReadHandleKey< Muon::MMPrepDataContainer > m_keyMM
Definition: PatternCnvAlg.h:67
Muon::MuonStationIndex::DetectorRegionIndex
DetectorRegionIndex
enum to classify the different layers in the muon spectrometer
Definition: MuonStationIndex.h:47
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:65
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:33
MuonR4::PatternCnvAlg::m_keysTgc
SG::ReadHandleKey< Muon::sTgcPrepDataContainer > m_keysTgc
Definition: PatternCnvAlg.h:66
PatternCnvAlg.h
MuonR4::PatternCnvAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: PatternCnvAlg.h:60
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