ATLAS Offline Software
Loading...
Searching...
No Matches
SpacePointCsvDumperAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
10#include <fstream>
11#include <TString.h>
12
13namespace {
14 constexpr int encodeId(const int8_t stName, const int8_t stEta,
15 const int8_t sector, const int8_t tech) {
16 return ( tech <<24 | sector <<16 |stEta << 8| stName);
17 }
18 constexpr double precCutOff(const double value, const double cutOff = 1.e-15) {
19 return std::abs(value) > cutOff ? value : 0.;
20 }
21}
22
23
24namespace MuonR4{
25
27 ATH_CHECK(m_readKeys.initialize());
28 ATH_CHECK(m_idHelperSvc.retrieve());
29 return StatusCode::SUCCESS;
30 }
31
33
34 const EventContext& ctx{Gaudi::Hive::currentContext()};
35
36 constexpr std::string_view delim = ",";
37 std::ofstream file{std::string(Form("event%09zu-",++m_event))+"SpacePoints.csv"};
38
40 file<<"sectorId"<<delim;
41 // Bucket inside the sector layer
42 file<<"bucketId"<<delim;
44 file<<"locPositionX"<<delim;
45 file<<"locPositionY"<<delim;
46 file<<"locPositionZ"<<delim;
48 file<<"locSensorDirX"<<delim;
49 file<<"locSensorDirY"<<delim;
50 file<<"locSensorDirZ"<<delim;
52 file<<"locSensorNormX"<<delim;
53 file<<"locSensorNormY"<<delim;
54 file<<"locSensorNormZ"<<delim;
56 file<<"locPlaneNormX"<<delim;
57 file<<"locPlaneNormY"<<delim;
58 file<<"locPlaneNormZ"<<delim;
60 file<<"covX"<<delim;
61 file<<"covY"<<delim;
62 file<<"covT"<<delim;
64 file<<"driftR"<<delim;
66 file<<"gasGap"<<delim;
67 file<<"primaryCh"<<delim;
68 file<<"measuresEta"<<delim;
69 file<<"measuresPhi"<<delim;
70 file<<"measuresTime"<<delim;
71 file<<std::endl;
72
73 auto dumpToFile = [&](const unsigned bucketId,
74 const SpacePoint& spacePoint,
75 const unsigned gasGap) {
76
77 const Identifier& measId = spacePoint.identify();
78 ATH_MSG_VERBOSE("Dump space point "<<m_idHelperSvc->toString(measId)<<", gasGap: "<<gasGap);
79 int primaryCh{0};
81 const TechIndex techIdx = m_idHelperSvc->technologyIndex(measId);
82 switch (techIdx) {
83 case TechIndex::MDT: {
84 const MdtIdHelper& idHelper{m_idHelperSvc->mdtIdHelper()};
85 primaryCh = idHelper.tube(measId);
86 break;
87 }
88 case TechIndex::RPC: {
89 const RpcIdHelper& idHelper{m_idHelperSvc->rpcIdHelper()};
90 primaryCh = idHelper.channel(measId);
91 break;
92 }
93 case TechIndex::TGC: {
94 const TgcIdHelper& idHelper{m_idHelperSvc->tgcIdHelper()};
95 primaryCh = idHelper.channel(measId);
96 break;
97 }
98 case TechIndex::STGC: {
99 const sTgcIdHelper& idHelper{m_idHelperSvc->stgcIdHelper()};
100 primaryCh = idHelper.channel(measId);
101 break;
102 }
103 case TechIndex::MM: {
104 const MmIdHelper& idHelper{m_idHelperSvc->mmIdHelper()};
105 primaryCh = idHelper.channel(measId);
106 break;
107 }
108 default:
109 ATH_MSG_WARNING("Dude you can't have CSCs in R4 "<<m_idHelperSvc->toString(measId));
110 };
111
112 const int secId = encodeId(static_cast<int8_t>(spacePoint.msSector()->chamberIndex()),
113 spacePoint.msSector()->side(),
114 spacePoint.msSector()->sector(),
115 static_cast<int8_t>(techIdx));
116
117 file<<secId<<delim;
118 file<<bucketId<<delim;
119 file<<precCutOff(spacePoint.localPosition().x())<<delim;
120 file<<precCutOff(spacePoint.localPosition().y())<<delim;
121 file<<precCutOff(spacePoint.localPosition().z())<<delim;
122 //
123 file<<precCutOff(spacePoint.sensorDirection().x())<<delim;
124 file<<precCutOff(spacePoint.sensorDirection().y())<<delim;
125 file<<precCutOff(spacePoint.sensorDirection().z())<<delim;
126 //
127 file<<precCutOff(spacePoint.toNextSensor().x())<<delim;
128 file<<precCutOff(spacePoint.toNextSensor().y())<<delim;
129 file<<precCutOff(spacePoint.toNextSensor().z())<<delim;
130 //
131 file<<precCutOff(spacePoint.planeNormal().x())<<delim;
132 file<<precCutOff(spacePoint.planeNormal().y())<<delim;
133 file<<precCutOff(spacePoint.planeNormal().z())<<delim;
134 //
136 file<<precCutOff(spacePoint.covariance()[Acts::toUnderlying(CovIdx::phiCov)])<<delim;
137 file<<precCutOff(spacePoint.covariance()[Acts::toUnderlying(CovIdx::etaCov)])<<delim;
139 file<<1.<<delim;
140 file<<precCutOff(spacePoint.driftRadius())<<delim;
141 file<<gasGap<<delim;
142 file<<primaryCh<<delim;
143 file<<spacePoint.measuresEta()<<delim;
144 file<<spacePoint.measuresPhi()<<delim;
146 file<<false<<delim;
147 file<<std::endl;
148 };
149
151 const SpacePointContainer* spContainer{nullptr};
152 ATH_CHECK(SG::get(spContainer, key, ctx));
153
154 const SpacePointPerLayerSorter layerSorter{};
155 for(const SpacePointBucket* bucket : *spContainer) {
156 std::vector<unsigned int> layNumbers{};
157 for (const SpacePointBucket::value_type& spacePoint: *bucket) {
158 const unsigned int layNum = layerSorter.sectorLayerNum(*spacePoint);
159 if (std::find(layNumbers.begin(), layNumbers.end(), layNum) == layNumbers.end()) {
160 layNumbers.push_back(layNum);
161 }
162 const unsigned gasGap = layNumbers.size()-1;
163 dumpToFile(bucket->bucketId(), *spacePoint, gasGap);
164 }
165 }
166 }
167 return StatusCode::SUCCESS;
168}
169}
170
171
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
Handle class for reading from StoreGate.
int tube(const Identifier &id) const
int channel(const Identifier &id) const override
: The muon space point bucket represents a collection of points that will bre processed together in t...
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
SG::ReadHandleKeyArray< SpacePointContainer > m_readKeys
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...
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
This header ties the generic definitions in this package.
SpacePoint::CovIdx CovIdx
########################################## SpacePointMakerAlg #######################################...
DataVector< SpacePointBucket > SpacePointContainer
Abrivation of the space point container type.
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.
TFile * file