ATLAS Offline Software
SpacePointCsvDumperAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include "StoreGate/ReadHandle.h"
9 #include <fstream>
10 #include <TString.h>
11 
12 namespace {
13  union bucketId{
14  int8_t fields[4];
15  int hash;
16  };
17 
18 }
19 
20 
21 namespace MuonR4{
22 SpacePointCsvDumperAlg::SpacePointCsvDumperAlg(const std::string& name, ISvcLocator* pSvcLocator):
23  AthAlgorithm{name, pSvcLocator} {}
24 
27  ATH_CHECK(m_idHelperSvc.retrieve());
28  return StatusCode::SUCCESS;
29  }
30 
32 
33  const EventContext& ctx{Gaudi::Hive::currentContext()};
34 
35 
36 
37  constexpr std::string_view delim = ",";
38  std::ofstream file{std::string(Form("event%09zu-",++m_event))+"SpacePoints.csv"};
39 
40  file<<"bucketId"<<delim;
41  file<<"localPositionX"<<delim;
42  file<<"localPositionY"<<delim;
43  file<<"localPositionZ"<<delim;
44  file<<"covX"<<delim;
45  file<<"covXY"<<delim;
46  file<<"covYX"<<delim;
47  file<<"covY"<<delim;
48  file<<"driftR"<<delim;
49  file<<"stationName"<<delim;
50  file<<"stationEta"<<delim;
51  file<<"stationPhi"<<delim;
52  file<<"gasGap"<<delim;
53  file<<"primaryCh"<<delim;
54  file<<"secondaryCh"<<delim;
55  file<<"measuresEta"<<delim;
56  file<<"measuresPhi"<<delim<<std::endl;
57 
58 
60  ATH_CHECK(readHandle.isPresent());
61 
62  for(const SpacePointBucket* bucket : *readHandle) {
63 
64  for (const auto& spacePoint : *bucket) {
65  const Identifier measId = spacePoint->identify();
66  int gasGap{0}, primaryCh{0}, secondCh{-1};
67  using TechIndex = Muon::MuonStationIndex::TechnologyIndex;
68  const TechIndex techIdx = m_idHelperSvc->technologyIndex(measId);
69  switch (techIdx) {
70  case TechIndex::MDT: {
71  const MdtIdHelper& idHelper{m_idHelperSvc->mdtIdHelper()};
72  gasGap = (idHelper.multilayer(measId) -1)*idHelper.tubeLayerMax(measId) + idHelper.tubeLayer(measId);
73  primaryCh = idHelper.tube(measId);
74  break;
75  }
76  case TechIndex::RPC: {
77  const RpcIdHelper& idHelper{m_idHelperSvc->rpcIdHelper()};
78  gasGap = (idHelper.doubletR(measId) -1) * idHelper.gasGapMax(measId) + idHelper.gasGap(measId);
79  primaryCh = idHelper.channel(measId);
80  if (spacePoint->secondaryMeasurement()){
81  secondCh = idHelper.channel(xAOD::identify(spacePoint->secondaryMeasurement()));
82  }
83  break;
84  }
85  case TechIndex::TGC: {
86  const TgcIdHelper& idHelper{m_idHelperSvc->tgcIdHelper()};
87  gasGap = idHelper.gasGap(measId);
88  primaryCh = idHelper.channel(measId);
89  if (spacePoint->secondaryMeasurement()){
90  secondCh = idHelper.channel(xAOD::identify(spacePoint->secondaryMeasurement()));
91  }
92  break;
93  }
94  case TechIndex::STGC: {
95  const sTgcIdHelper& idHelper{m_idHelperSvc->stgcIdHelper()};
96  gasGap = (idHelper.multilayer(measId) -1) * 4 + idHelper.gasGap(measId);
97  primaryCh = idHelper.channel(measId);
98  if (spacePoint->secondaryMeasurement()){
99  secondCh = idHelper.channel(xAOD::identify(spacePoint->secondaryMeasurement()));
100  }
101  break;
102  }
103  case TechIndex::MM: {
104  const MmIdHelper& idHelper{m_idHelperSvc->mmIdHelper()};
105  gasGap = (idHelper.multilayer(measId) -1) * 4 + idHelper.gasGap(measId);
106  primaryCh = idHelper.channel(measId);
107  if (spacePoint->secondaryMeasurement()){
108  secondCh = idHelper.channel(xAOD::identify(spacePoint->secondaryMeasurement()));
109  }
110  break;
111 
112  }
113  default:
114  ATH_MSG_WARNING("Dude you can't have CSCs in R4 "<<m_idHelperSvc->toString(measId));
115  };
116 
117  bucketId buckId{};
118  buckId.fields[0] = spacePoint->chamber()->stationName();
119  buckId.fields[1] = spacePoint->chamber()->stationEta();
120  buckId.fields[2] = spacePoint->chamber()->stationPhi();
121  buckId.fields[3] = bucket->bucketId();
122 
123  file<<buckId.hash<<delim;
124  file<<spacePoint->positionInChamber().x()<<delim;
125  file<<spacePoint->positionInChamber().y()<<delim;
126  file<<spacePoint->positionInChamber().z()<<delim;
127  file<<spacePoint->covariance()(Amg::x, Amg::x)<<delim;
128  file<<spacePoint->covariance()(Amg::x, Amg::y)<<delim;
129  file<<spacePoint->covariance()(Amg::y, Amg::x)<<delim;
130  file<<spacePoint->covariance()(Amg::y, Amg::y)<<delim;
131  file<<spacePoint->driftRadius()<<delim;
132  file<<m_idHelperSvc->stationName(measId)<<delim;
133  file<<m_idHelperSvc->stationEta(measId)<<delim;
134  file<<m_idHelperSvc->stationPhi(measId)<<delim;
135  file<<gasGap<<delim;
136  file<<primaryCh<<delim;
137  file<<secondCh<<delim;
138  file<<spacePoint->measuresEta()<<delim;
139  file<<spacePoint->measuresPhi()<<delim;
140  file<<std::endl;
141  }
142  }
143 
144  return StatusCode::SUCCESS;
145 
146 
147  }
148 }
149 
150 
TGC
@ TGC
Definition: RegSelEnums.h:33
STGC
@ STGC
Definition: RegSelEnums.h:39
dumpTgcDigiDeadChambers.gasGap
list gasGap
Definition: dumpTgcDigiDeadChambers.py:33
UtilFunctions.h
MuonR4::SpacePointCsvDumperAlg::m_readKey
SG::ReadHandleKey< SpacePointContainer > m_readKey
Definition: SpacePointCsvDumperAlg.h:31
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
TgcIdHelper
Definition: TgcIdHelper.h:50
SG::ReadHandle< SpacePointContainer >
Amg::y
@ y
Definition: GeoPrimitives.h:35
MM
@ MM
Definition: RegSelEnums.h:38
xAOD::identify
Identifier identify(const UncalibratedMeasurement *meas)
Returns the associated identifier.
Definition: MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonPrepData/Root/UtilFunctions.cxx:61
RpcIdHelper
Definition: RpcIdHelper.h:51
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
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
AthAlgorithm
Definition: AthAlgorithm.h:47
MuonR4::SpacePointCsvDumperAlg::initialize
StatusCode initialize() override
Definition: SpacePointCsvDumperAlg.cxx:25
RPC
@ RPC
Definition: RegSelEnums.h:32
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
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
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
MuonR4::SpacePointCsvDumperAlg::execute
StatusCode execute() override
Definition: SpacePointCsvDumperAlg.cxx:31
MuonR4::SpacePointCsvDumperAlg::SpacePointCsvDumperAlg
SpacePointCsvDumperAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: SpacePointCsvDumperAlg.cxx:22
CaloCondBlobAlgs_fillNoiseFromASCII.fields
fields
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:106
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
MDT
@ MDT
Definition: RegSelEnums.h:31
MuonR4::SpacePointCsvDumperAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: SpacePointCsvDumperAlg.h:33
Identifier
Definition: IdentifierFieldParser.cxx:14