ATLAS Offline Software
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 
7 #include "StoreGate/ReadHandle.h"
10 #include <fstream>
11 #include <TString.h>
12 
13 namespace {
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 
24 namespace 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};
80  using TechIndex = Muon::MuonStationIndex::TechnologyIndex;
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  //
135  using CovIdx = SpacePoint::CovIdx;
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 
TGC
@ TGC
Definition: RegSelEnums.h:33
MuonR4::SpacePointCsvDumperAlg::m_readKeys
SG::ReadHandleKeyArray< SpacePointContainer > m_readKeys
Definition: SpacePointCsvDumperAlg.h:31
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
STGC
@ STGC
Definition: RegSelEnums.h:39
dumpTgcDigiDeadChambers.gasGap
list gasGap
Definition: dumpTgcDigiDeadChambers.py:33
UtilFunctions.h
MuonR4::SpacePointBucket
: The muon space point bucket represents a collection of points that will bre processed together in t...
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonSpacePoint/MuonSpacePoint/SpacePointContainer.h:21
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
MuonR4::SpacePointPerLayerSorter
The SpacePointPerLayerSorter sort two given space points by their layer Identifier.
Definition: SpacePointPerLayerSorter.h:15
MuonR4::SpacePointPerLayerSorter::sectorLayerNum
unsigned int sectorLayerNum(const SpacePoint &sp) const
method returning the logic layer number
Definition: SpacePointPerLayerSorter.cxx:13
TgcIdHelper
Definition: TgcIdHelper.h:50
Muon::MuonStationIndex::stName
const std::string & stName(StIndex index)
convert StIndex into a string
Definition: MuonStationIndex.cxx:104
Muon::MuonStationIndex::TechnologyIndex
TechnologyIndex
enum to classify the different layers in the muon spectrometer
Definition: MuonStationIndex.h:54
MM
@ MM
Definition: RegSelEnums.h:38
athena.value
value
Definition: athena.py:124
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::ReadHandleKey< SpacePointContainer >
MuonR4::SpacePoint::CovIdx::etaCov
@ etaCov
RpcIdHelper
Definition: RpcIdHelper.h:51
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
MuonR4::SpacePointCsvDumperAlg::m_event
size_t m_event
Definition: SpacePointCsvDumperAlg.h:35
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
MdtIdHelper
Definition: MdtIdHelper.h:61
file
TFile * file
Definition: tile_monitor.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
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:24
MuonR4::SpacePointCsvDumperAlg::initialize
StatusCode initialize() override
Definition: SpacePointCsvDumperAlg.cxx:26
RPC
@ RPC
Definition: RegSelEnums.h:32
MuonR4::SpacePoint::CovIdx::phiCov
@ phiCov
SpacePointCsvDumperAlg.h
sTgcIdHelper
Definition: sTgcIdHelper.h:55
MuonR4
This header ties the generic definitions in this package.
Definition: HoughEventData.h:16
MmIdHelper
Definition: MmIdHelper.h:54
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
MuonR4::SpacePointCsvDumperAlg::execute
StatusCode execute() override
Definition: SpacePointCsvDumperAlg.cxx:32
MuonR4::SpacePoint::CovIdx
CovIdx
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonSpacePoint/MuonSpacePoint/SpacePoint.h:30
ReadHandle.h
Handle class for reading from StoreGate.
SpacePointPerLayerSorter.h
MDT
@ MDT
Definition: RegSelEnums.h:31
MuonR4::SpacePointCsvDumperAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: SpacePointCsvDumperAlg.h:33
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
Identifier
Definition: IdentifierFieldParser.cxx:14