Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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<<"locPlaneNormX"<<delim;
53  file<<"locPlaneNormY"<<delim;
54  file<<"locPlaneNormZ"<<delim;
56  file<<"covXX"<<delim;
57  file<<"covXY"<<delim;
58  file<<"covYX"<<delim;
59  file<<"covYY"<<delim;
61  file<<"driftR"<<delim;
63  file<<"gasGap"<<delim;
64  file<<"primaryCh"<<delim;
65  file<<"measuresEta"<<delim;
66  file<<"measuresPhi"<<delim;
67  file<<std::endl;
68 
69  auto dumpToFile = [&](const unsigned bucketId,
70  const SpacePoint& spacePoint,
71  const unsigned gasGap) {
72 
73  const Identifier& measId = spacePoint.identify();
74  ATH_MSG_VERBOSE("Dump space point "<<m_idHelperSvc->toString(measId)<<", gasGap: "<<gasGap);
75  int primaryCh{0};
76  using TechIndex = Muon::MuonStationIndex::TechnologyIndex;
77  const TechIndex techIdx = m_idHelperSvc->technologyIndex(measId);
78  switch (techIdx) {
79  case TechIndex::MDT: {
80  const MdtIdHelper& idHelper{m_idHelperSvc->mdtIdHelper()};
81  primaryCh = idHelper.tube(measId);
82  break;
83  }
84  case TechIndex::RPC: {
85  const RpcIdHelper& idHelper{m_idHelperSvc->rpcIdHelper()};
86  primaryCh = idHelper.channel(measId);
87  break;
88  }
89  case TechIndex::TGC: {
90  const TgcIdHelper& idHelper{m_idHelperSvc->tgcIdHelper()};
91  primaryCh = idHelper.channel(measId);
92  break;
93  }
94  case TechIndex::STGC: {
95  const sTgcIdHelper& idHelper{m_idHelperSvc->stgcIdHelper()};
96  primaryCh = idHelper.channel(measId);
97  break;
98  }
99  case TechIndex::MM: {
100  const MmIdHelper& idHelper{m_idHelperSvc->mmIdHelper()};
101  primaryCh = idHelper.channel(measId);
102  break;
103  }
104  default:
105  ATH_MSG_WARNING("Dude you can't have CSCs in R4 "<<m_idHelperSvc->toString(measId));
106  };
107 
108  const int secId = encodeId(static_cast<int8_t>(spacePoint.msSector()->chamberIndex()),
109  spacePoint.msSector()->side(),
110  spacePoint.msSector()->sector(),
111  static_cast<int8_t>(techIdx));
112 
113  file<<secId<<delim;
114  file<<bucketId<<delim;
115  file<<precCutOff(spacePoint.positionInChamber().x())<<delim;
116  file<<precCutOff(spacePoint.positionInChamber().y())<<delim;
117  file<<precCutOff(spacePoint.positionInChamber().z())<<delim;
118  //
119  file<<precCutOff(spacePoint.directionInChamber().x())<<delim;
120  file<<precCutOff(spacePoint.directionInChamber().y())<<delim;
121  file<<precCutOff(spacePoint.directionInChamber().z())<<delim;
122  //
123  file<<precCutOff(spacePoint.planeNormal().x())<<delim;
124  file<<precCutOff(spacePoint.planeNormal().y())<<delim;
125  file<<precCutOff(spacePoint.planeNormal().z())<<delim;
126  //
127  file<<precCutOff(spacePoint.covariance()(Amg::x, Amg::x))<<delim;
128  file<<precCutOff(spacePoint.covariance()(Amg::x, Amg::y))<<delim;
129  file<<precCutOff(spacePoint.covariance()(Amg::y, Amg::x))<<delim;
130  file<<precCutOff(spacePoint.covariance()(Amg::y, Amg::y))<<delim;
131  file<<precCutOff(spacePoint.driftRadius())<<delim;
132  file<<gasGap<<delim;
133  file<<primaryCh<<delim;
134  file<<spacePoint.measuresEta()<<delim;
135  file<<spacePoint.measuresPhi()<<delim;
136  file<<std::endl;
137  };
138 
140  const SpacePointContainer* spContainer{nullptr};
141  ATH_CHECK(SG::get(spContainer, key, ctx));
142 
143  const SpacePointPerLayerSorter layerSorter{m_idHelperSvc.get()};
144  for(const SpacePointBucket* bucket : *spContainer) {
145  std::unordered_map<Identifier, unsigned> gasNumbers{};
146  for (const SpacePointBucket::value_type& spacePoint: *bucket) {
147  unsigned int gasGap{gasNumbers.insert(
148  std::make_pair(layerSorter.detectorLayerId(spacePoint->identify()),
149  gasNumbers.size())).first->second};
150  dumpToFile(bucket->bucketId(), *spacePoint, gasGap);
151  }
152  }
153  }
154  return StatusCode::SUCCESS;
155 }
156 }
157 
158 
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
MuonR4::SpacePointPerLayerSorter
The SpacePointPerLayerSorter sort two given space points by their layer Identifier.
Definition: SpacePointPerLayerSorter.h:18
TgcIdHelper
Definition: TgcIdHelper.h:50
Amg::y
@ y
Definition: GeoPrimitives.h:35
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 >
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
Amg::x
@ x
Definition: GeoPrimitives.h:34
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:18
MuonR4::SpacePointCsvDumperAlg::initialize
StatusCode initialize() override
Definition: SpacePointCsvDumperAlg.cxx:26
RPC
@ RPC
Definition: RegSelEnums.h:32
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
ReadHandle.h
Handle class for reading from StoreGate.
Muon::MuonStationIndex::TechnologyIndex
TechnologyIndex
enum to classify the different layers in the muon spectrometer
Definition: MuonStationIndex.h:54
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