ATLAS Offline Software
Loading...
Searching...
No Matches
SpacePointWriter.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3 */
4
5 #include "SpacePointWriter.h"
11
12 #include "Acts/Definitions/Tolerance.hpp"
13 #include "Acts/Definitions/Units.hpp"
14 #include "Acts/Utilities/Helpers.hpp"
15 #include "Acts/Surfaces/PlaneSurface.hpp"
16
17 using namespace Acts::UnitLiterals;
18
19namespace {
20 constexpr float toFloat(const double x) {
21
22 if (Acts::abs(x) < Acts::s_epsilon) {
23 return 0.f;
24 }
25 constexpr double min = 3.*static_cast<double>(std::numeric_limits<float>::min());
26 constexpr double max = static_cast<double>(std::numeric_limits<float>::max());
27 const double clampedX = std::copysign(std::clamp(Acts::abs(x), min, max), x);
28 return static_cast<float>(clampedX);
29 }
30
31}
32 namespace MuonValR4{
34 ATH_CHECK(m_tree.init(this));
35 ATH_CHECK(m_spacePointKeys.initialize());
37 ATH_MSG_DEBUG("Successfully initialized");
38 return StatusCode::SUCCESS;
39 }
40 StatusCode SpacePointWriter::execute(const EventContext& ctx){
41 unsigned bucketCounter{0u};
42 m_eventId = ctx.eventID().event_number();
43
44 const Acts::GeometryContext tgContext = m_trackingGeometryTool->getGeometryContext(ctx).context();
45
46 const MuonR4::SpacePointPerLayerSorter layerSorter{};
47
49 const MuonR4::SpacePointContainer* container{nullptr};
50 ATH_CHECK(SG::get(container,key, ctx));
51 for (const auto& bucket : *container) {
52 std::vector<std::uint32_t> layNumbers{};
53 for (const auto& spacePoint : *bucket) {
54 const std::uint32_t layNum = layerSorter.sectorLayerNum(*spacePoint);
55 if (!Acts::rangeContainsValue(layNumbers, layNum)) {
56 layNumbers.push_back(layNum);
57 }
58
59 m_bucketId += bucketCounter;
60 m_muonId += encodeId(*spacePoint, layNum);
61 m_localPosition+=spacePoint->localPosition();
62 m_sensorDirection+=spacePoint->sensorDirection();
63 m_toNextSensor += spacePoint->toNextSensor();
64
65 const Acts::Surface& measSurface = xAOD::muonSurface(spacePoint->primaryMeasurement());
66 m_geometryId += measSurface.geometryId().value();
67 m_driftR += toFloat(spacePoint->driftRadius());
68 m_time += toFloat(spacePoint->time());
69
70 m_toMeasFrame += spacePoint->msSector()->surface().localToGlobalTransform(tgContext).inverse()*
71 measSurface.localToGlobalTransform(tgContext);
72 using namespace MuonR4::SegmentFit;
73 m_covLoc0 += toFloat(spacePoint->covariance()[Acts::toUnderlying(AxisDefs::etaCov)]);
74 m_covLoc1 += toFloat(spacePoint->covariance()[Acts::toUnderlying(AxisDefs::phiCov)]);
75 m_covT += toFloat(spacePoint->covariance()[Acts::toUnderlying(AxisDefs::timeCov)]);
76 }
77 ++bucketCounter;
78 }
79 }
80 ATH_MSG_DEBUG("Dumped "<<bucketCounter<<" buckets");
81 ATH_CHECK(m_tree.fill(ctx));
82 return StatusCode::SUCCESS;
83 }
85 ATH_CHECK(m_tree.write());
86 return StatusCode::SUCCESS;
87 }
88 std::uint32_t SpacePointWriter::encodeId(const MuonR4::SpacePoint& spacePoint,
89 std::uint32_t gasGap) const {
90 constexpr std::uint32_t threeBit = 0x7;
91 constexpr std::uint32_t fourBit = 0xF;
92 constexpr std::uint32_t sixBit = 0x3F;
93 std::uint32_t rawRep{0u};
94 const MuonGMR4::Chamber* ch = spacePoint.chamber();
95 rawRep |= (static_cast<std::uint32_t>(ch->chamberIndex()) & fourBit);
96 if (ch->side() == 1) {
97 rawRep |= (1u << 4);
98 }
99
100 const Muon::MuonStationIndex::TechnologyIndex techIdx = m_idHelperSvc->technologyIndex(spacePoint.identify());
101 rawRep |= ((static_cast<std::uint32_t>(techIdx) & threeBit) << 5);
102 rawRep |= ((static_cast<std::uint32_t>(ch->sector() - 1u) & sixBit) << 8);
103 rawRep |= (static_cast<std::uint32_t>(spacePoint.measuresEta()) << 14);
104 rawRep |= (static_cast<std::uint32_t>(spacePoint.measuresPhi()) << 15);
105 rawRep |= (static_cast<std::uint32_t>(spacePoint.hasTime()) << 16);
106
107 int primaryCh{0};
108 switch (techIdx) {
110 case MDT: {
111 const MdtIdHelper& idHelper{m_idHelperSvc->mdtIdHelper()};
112 primaryCh = idHelper.tube(spacePoint.identify());
113 break;
114 } case RPC: {
115 const RpcIdHelper& idHelper{m_idHelperSvc->rpcIdHelper()};
116 primaryCh = idHelper.channel(spacePoint.identify());
117 break;
118 } case TGC: {
119 const TgcIdHelper& idHelper{m_idHelperSvc->tgcIdHelper()};
120 primaryCh = idHelper.channel(spacePoint.identify());
121 break;
122 } case STGC: {
123 const sTgcIdHelper& idHelper{m_idHelperSvc->stgcIdHelper()};
124 primaryCh = idHelper.channel(spacePoint.identify());
125 break;
126 } case MM: {
127 const MmIdHelper& idHelper{m_idHelperSvc->mmIdHelper()};
128 primaryCh = idHelper.channel(spacePoint.identify());
129 break;
130 } default:
131 ATH_MSG_WARNING("Dude you can't have CSCs in R4 "<<spacePoint);
132 };
133
134 rawRep |= ((static_cast<std::uint32_t>(gasGap - 1u) & fourBit) << 17);
135 rawRep |= (static_cast<std::uint32_t>(primaryCh - 1u) << 21);
136 return rawRep;
137 }
138}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
@ STGC
Definition RegSelEnums.h:39
@ MM
Definition RegSelEnums.h:38
@ RPC
Definition RegSelEnums.h:32
@ MDT
Definition RegSelEnums.h:31
Handle class for reading from StoreGate.
#define x
#define min(a, b)
Definition cfImp.cxx:40
#define max(a, b)
Definition cfImp.cxx:41
int tube(const Identifier &id) const
int channel(const Identifier &id) const override
Chamber represent the volume enclosing a muon station.
Definition Chamber.h:29
The SpacePointPerLayerSorter sort two given space points by their layer Identifier.
unsigned int sectorLayerNum(const SpacePoint &sp) const
method returning the logic layer number
The muon space point is the combination of two uncalibrated measurements one of them measures the eta...
bool hasTime() const
Returns whether the measurement carries time information.
const Identifier & identify() const
: Identifier of the primary measurement
bool measuresPhi() const
: Does the space point contain a phi measurement
const MuonGMR4::Chamber * chamber() const
: Pointer to the associated chamber
bool measuresEta() const
: Does the space point contain an eta measurement
MuonVal::UnitThreeVectorBranch m_sensorDirection
Orientation of the wire or strip.
virtual StatusCode initialize() override final
MuonVal::VectorBranch< float > & m_time
Recorded measurement time.
MuonVal::VectorBranch< std::uint32_t > & m_muonId
Identifier encoding the staion name && the coordinates measured by the space point.
MuonVal::UnitThreeVectorBranch m_toNextSensor
Vector pointing to the next channel in the same measurement plane.
MuonVal::MuonTesterTree m_tree
instance to the Event tree
PublicToolHandle< ActsTrk::ITrackingGeometryTool > m_trackingGeometryTool
The tool handle of the tracking geometry tool.
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Service handle towards the IdHelper svc.
MuonVal::VectorBranch< float > & m_covLoc0
Covariance value along the non-bending direction.
MuonVal::VectorBranch< float > & m_covT
Time covariance value.
MuonVal::VectorBranch< std::uint16_t > & m_bucketId
Bucket counter in the event.
MuonVal::ThreeVectorBranch m_localPosition
Position of the measurement.
MuonVal::VectorBranch< GeoId_t > & m_geometryId
SG::ReadHandleKeyArray< MuonR4::SpacePointContainer > m_spacePointKeys
virtual StatusCode finalize() override final
MuonVal::VectorBranch< float > & m_covLoc1
Covaraiance value along the bending direction.
MuonVal::ScalarBranch< std::uint32_t > & m_eventId
The event number in this event.
MuonVal::CoordSystemsBranch m_toMeasFrame
Coordinate transformation from the local measurement's frame to the common sector frame.
std::uint32_t encodeId(const MuonR4::SpacePoint &spacePoint, std::uint32_t gasGap) const
Encode the space point's identifier into the Identifier understood by ActsExamples.
MuonVal::VectorBranch< float > & m_driftR
Drift radius of the straw measurements.
virtual StatusCode execute(const EventContext &ctx) override final
Execute method.
int channel(const Identifier &id) const override
Property holding a SG store/key/clid from which a ReadHandle is made.
int channel(const Identifier &id) const override
int channel(const Identifier &id) const override
DataVector< SpacePointBucket > SpacePointContainer
Abrivation of the space point container type.
Lightweight algorithm to read xAOD MDT sim hits and (fast-digitised) drift circles from SG and fill a...
TechnologyIndex
enum to classify the different layers in the muon spectrometer
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
Definition TgcBase.h:6
const Acts::Surface & muonSurface(const UncalibratedMeasurement *meas)
Returns the associated Acts surface to the measurement.