ATLAS Offline Software
RPCDQUtils.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // C/C++
6 #include <math.h>
7 
8 #include <fstream>
9 
10 // Athena
15 // Local
16 
17 #include "RPCDQUtils.h"
18 
19 //========================================================================================================
20 // struct RpcPanel
21 //========================================================================================================
22 RpcPanel::RpcPanel(Identifier id, const RpcIdHelper &rpcIdHelper) {
23  FillRpcId(id, rpcIdHelper);
24 }
25 
26 //========================================================================================================
27 void RpcPanel::FillRpcId(Identifier id, const RpcIdHelper &rpcIdHelper) {
28  //
29  // Read RPC data
30  //
31  stationName = rpcIdHelper.stationName(id);
32  stationEta = rpcIdHelper.stationEta(id);
33  stationPhi = rpcIdHelper.stationPhi(id);
34  doubletR = rpcIdHelper.doubletR(id);
35  doubletZ = rpcIdHelper.doubletZ(id);
36  doubletPhi = rpcIdHelper.doubletPhi(id);
37  gasGap = rpcIdHelper.gasGap(id);
38  measPhi = rpcIdHelper.measuresPhi(id);
39 
40  panelId =
43 
44  // panel_index = stationName*6144 + stationPhi*768 + (stationEta+9)*48 +
45  // doubletR*24 + doubletPhi*12 + doubletZ*4 + gasGap*2 + measPhi;
46 }
47 
48 //========================================================================================================
50  const MuonGM::RpcReadoutElement *_readoutEl,
51  const int _doubletZ, const int _doubletPhi,
52  const int _gasgap, const int _measPhi)
53  : readoutEl(_readoutEl),
54  doubletR(_readoutEl->getDoubletR()),
55  doubletZ(_doubletZ),
56  doubletPhi(_doubletPhi),
57  gasGap(_gasgap),
58  measPhi(_measPhi) {
59  const RpcIdHelper &rpcIdHelper = idHelperSvc.rpcIdHelper();
60  const Identifier readEl_id = readoutEl->identify();
61 
62  stationName = rpcIdHelper.stationName(readEl_id);
64 
65  stationEta = rpcIdHelper.stationEta(readEl_id);
66  stationPhi = rpcIdHelper.stationPhi(readEl_id);
67 
68  //
69  // Get Identifier for this panel
70  //
71  panelId =
74  if (panel_valid) {
75  panel_str = idHelperSvc.toString(panelId);
77  } else {
78  panel_str = idHelperSvc.toString(panelId) + " - INVALID ID";
79  }
80 }
81 
82 //========================================================================================================
85 }
86 
87 //========================================================================================================
88 std::string RpcPanel::getElementStr() const {
89  std::ostringstream ele_key;
90 
91  ele_key << stationName << "_" << stationEta << "_" << stationPhi << "_"
92  << doubletR << "_" << doubletZ;
93  return ele_key.str();
94 }
95 
96 //========================================================================================================
97 bool RpcPanel::operator==(const RpcPanel &rhs) const {
98  if (this->stationName == rhs.stationName &&
99  this->stationPhi == rhs.stationPhi &&
100  this->stationEta == rhs.stationEta && this->doubletR == rhs.doubletR &&
101  this->doubletPhi == rhs.doubletPhi && this->doubletZ == rhs.doubletZ &&
102  this->gasGap == rhs.gasGap && this->measPhi == rhs.measPhi) {
103  return true;
104  } else {
105  return false;
106  }
107 }
108 
109 //========================================================================================================
110 bool RpcPanel::operator<(const RpcPanel &rhs) const {
111  return this->panel_index < rhs.panel_index;
112 }
113 
114 //========================================================================================================
115 bool RpcPanel::operator>(const RpcPanel &rhs) const {
116  return this->panel_index > rhs.panel_index;
117 }
118 
119 //========================================================================================================
120 std::string RpcPanel::getOnlineConvention() const {
121  const std::string mystring_name = stationNameStr;
122  const std::string mystring_eta = std::to_string(std::abs(stationEta));
123  const std::string mystring_dPhi = "DP" + std::to_string(doubletPhi) + ".";
124  const std::string mystring_gap = "Ly" + std::to_string(gasGap - 1) + ".";
125  const std::string mystring_dZ = "DZ" + std::to_string(doubletZ);
126 
127  std::string mystring_phi;
128  std::string mystring_side;
129  std::string mystring_PICO; // pivot or confirm
130  std::string mystring_ETAPHI;
131 
132  int myphi_part = (2 * stationPhi) - 1;
133 
134  if (stationEta > 0) {
135  mystring_side = "A";
136  } else if (stationEta < 0) {
137  mystring_side = "C";
138  } else {
139  mystring_side = "N";
140  } // N: NULL, "ETA NOT DEFINED"
141 
142  if (stationName == 3 || stationName == 5 || stationName == 8 ||
143  stationName == 9 || stationName == 10) {
144  myphi_part += 1;
145  }
146 
147  if (myphi_part < 10) {
148  mystring_phi = "0" + std::to_string(myphi_part);
149  } else {
150  mystring_phi = std::to_string(myphi_part);
151  }
152 
153  if ((stationNameStr == "BMS" && doubletR == 1) ||
154  (stationNameStr == "BML" && doubletR == 1) ||
155  (stationNameStr == "BMF" && doubletR == 1)) {
156  mystring_PICO = ".CO.";
157  } else if ((stationNameStr == "BMS" && doubletR == 2) ||
158  (stationNameStr == "BML" && doubletR == 2) ||
159  (stationNameStr == "BMF" && doubletR == 2)) {
160  mystring_PICO = ".PI.";
161  } else if ((stationNameStr == "BOS" && doubletR == 1) ||
162  (stationNameStr == "BOL" && doubletR == 1) ||
163  (stationNameStr == "BOF" && doubletR == 1) ||
164  (stationNameStr == "BOG" && doubletR == 1)) {
165  mystring_PICO = ".CO.";
166  } else {
167  // mystring_PICO = ".PIVOT_CONFIRMED_NOT_DEFINED.";
168  mystring_PICO =
169  ".NU" + std::to_string(doubletR) + "."; // NU: NULL, Not defined
170  }
171 
172  if (measPhi == 0) {
173  mystring_ETAPHI = "ETA.";
174  } else {
175  mystring_ETAPHI = "PHI.";
176  }
177 
178  return mystring_name + mystring_eta + mystring_side + mystring_phi +
179  mystring_PICO + mystring_dPhi + mystring_gap + mystring_dZ +
180  mystring_ETAPHI;
181 }
182 
183 //========================================================================================================
184 std::pair<int, int> RpcPanel::getSectorLayer() const {
185  // {'2':'BML', '3':'BMS', '4':'BOL', '5':'BOS', '8':'BMF' , '9':'BOF',
186  // '10':'BOG', '53':'BME'}
187  int sector = 0;
188  int layer = 0;
189 
190  if (stationName == 2 || stationName == 53) {
191  sector = stationPhi * 2 - 1;
192  layer = (doubletR - 1) * 2 + gasGap;
193  } else if (stationName == 4) {
194  sector = stationPhi * 2 - 1;
195  layer = 4 + (doubletR - 1) * 2 + gasGap;
196  } else if (stationName == 3 || stationName == 8) {
197  sector = stationPhi * 2;
198  layer = (doubletR - 1) * 2 + gasGap;
199  } else if (stationName == 5 || stationName == 9 || stationName == 10) {
200  sector = stationPhi * 2;
201  layer = 4 + (doubletR - 1) * 2 + gasGap;
202  }
203  if (stationEta < 0)
204  sector = -1 * sector;
205 
206  std::pair<int, int> sec_layer(sector, layer);
207 
208  return sec_layer;
209 }
210 
211 //========================================================================================================
212 // strcuct ExResult
213 //========================================================================================================
215  const Trk::PropDirection _direction)
216  : gasgap_id(_gasgap_id), direction(_direction) {}
217 
218 //========================================================================================================
219 // GasGapData
220 //========================================================================================================
222  const MuonGM::RpcReadoutElement *_readoutEl,
223  const int _doubletZ, const int _doubletPhi,
224  const unsigned _gasgap)
225  : readoutEl(_readoutEl),
226  doubletR(_readoutEl->getDoubletR()),
227  doubletZ(_doubletZ),
228  doubletPhi(_doubletPhi),
229  gasgap(_gasgap) {
230  const RpcIdHelper &rpcIdHelper = idHelperSvc.rpcIdHelper();
231  const Identifier readEl_id = readoutEl->identify();
232 
233  stationName = rpcIdHelper.stationName(readEl_id);
234  stationEta = rpcIdHelper.stationEta(readEl_id);
235  stationPhi = rpcIdHelper.stationPhi(readEl_id);
236 
237  //
238  // Get Identifier for this gas gap
239  //
242 
243  if (gapid_valid) {
244  gapid_str = idHelperSvc.toString(gapid);
245  } else {
246  gapid_str = idHelperSvc.toString(gapid) + " - INVALID ID";
247  }
248 
251 
252  // Determine gas gap span in eta
253  const Identifier etaIdFirst{rpcIdHelper.channelID(gapid, doubletZ, doubletPhi, gasgap, false, 1)};
254  const Amg::Vector3D glbPos_etaStrip_1st = readoutEl->stripPos(etaIdFirst);
255  double eta_etaStrip_1st = glbPos_etaStrip_1st.eta();
256 
257  const Identifier etaIdLast{rpcIdHelper.channelID(gapid, doubletZ, doubletPhi, gasgap, false, NetaStrips)};
258  const Amg::Vector3D glbPos_etaStrip_last = readoutEl->stripPos(etaIdLast);
259  double eta_etaStrip_last = glbPos_etaStrip_last.eta();
260 
261  if (eta_etaStrip_1st < eta_etaStrip_last) {
262  minStripEta = eta_etaStrip_1st;
263  maxStripEta = eta_etaStrip_last;
264  } else {
265  minStripEta = eta_etaStrip_last;
266  maxStripEta = eta_etaStrip_1st;
267  }
268 
269  //
270  // Determine gas gap span in phi
271  //
272  const Identifier phiIdFirst{rpcIdHelper.channelID(gapid, doubletZ, doubletPhi, gasgap, true, 1)};
273  const Amg::Vector3D glbPos_phiStrip_1st = readoutEl->stripPos(phiIdFirst);
274  double phi_phiStrip_1st = glbPos_phiStrip_1st.phi();
275 
276  const Identifier phiIdLast{rpcIdHelper.channelID(gapid, doubletZ, doubletPhi, gasgap, true, NphiStrips)};
277  const Amg::Vector3D glbPos_phiStrip_last = readoutEl->stripPos(phiIdLast);
278  double phi_phiStrip_last = glbPos_phiStrip_last.phi();
279 
280  if (phi_phiStrip_1st < phi_phiStrip_last) {
281  minStripPhi = phi_phiStrip_1st;
282  maxStripPhi = phi_phiStrip_last;
283  } else {
284  minStripPhi = phi_phiStrip_last;
285  maxStripPhi = phi_phiStrip_1st;
286  }
287 }
288 
289 //========================================================================================================
291  ExResult &result, const xAOD::TrackParticle &track) const {
292  /*
293  This function:
294  - computes minum DR distance between track and RpcReadoutElement
295  - do this before expensive call to extrapolator
296  */
297 
298  const double deta1 = std::abs(minStripEta - track.eta());
299  const double deta2 = std::abs(maxStripEta - track.eta());
300 
301  const double dphi1 =
302  std::abs(xAOD::P4Helpers::deltaPhi(minStripPhi, track.phi()));
303  const double dphi2 =
304  std::abs(xAOD::P4Helpers::deltaPhi(maxStripPhi, track.phi()));
305 
306  result.minTrackGasGapDEta = std::min<double>(deta1, deta2);
307  result.minTrackGasGapDPhi = std::min<double>(dphi1, dphi2);
308 
309  //
310  // Now check if track position is between min and max - if true, set
311  // distance to zero
312  //
313  if (minStripEta <= track.eta() && track.eta() <= maxStripEta) {
314  result.minTrackGasGapDEta = 0.0;
315  }
316  if (minStripPhi <= track.phi() && track.phi() <= maxStripPhi) {
317  result.minTrackGasGapDPhi = 0.0;
318  }
319 
320  //
321  // Compute min DR to this gas gap
322  //
323  result.minTrackGasGapDR =
324  std::sqrt(result.minTrackGasGapDEta * result.minTrackGasGapDEta +
325  result.minTrackGasGapDPhi * result.minTrackGasGapDPhi);
326 }
327 
328 //========================================================================================================
330  ExResult &result, const Trk::TrackParameters *trackParam) const {
331  /*
332  This function:
333  - computes minum DR distance between track and RpcReadoutElement
334  - do this before expensive call to extrapolator
335  */
336 
337  const double deta1 = std::abs(minStripEta - trackParam->position().eta());
338  const double deta2 = std::abs(maxStripEta - trackParam->position().eta());
339 
340  const double dphi1 = std::abs(
341  xAOD::P4Helpers::deltaPhi(minStripPhi, trackParam->position().phi()));
342  const double dphi2 = std::abs(
343  xAOD::P4Helpers::deltaPhi(maxStripPhi, trackParam->position().phi()));
344 
345  result.minTrackGasGapDEta = std::min<double>(deta1, deta2);
346  result.minTrackGasGapDPhi = std::min<double>(dphi1, dphi2);
347 
348  //
349  // Now check if trackParam->position() position is between min and max - if
350  // true, set distance to zero
351  //
352  if (minStripEta <= trackParam->position().eta() &&
353  trackParam->position().eta() <= maxStripEta) {
354  result.minTrackGasGapDEta = 0.0;
355  }
356  if (minStripPhi <= trackParam->position().phi() &&
357  trackParam->position().phi() <= maxStripPhi) {
358  result.minTrackGasGapDPhi = 0.0;
359  }
360 
361  //
362  // Compute min DR to this gas gap
363  //
364  result.minTrackGasGapDR =
365  std::sqrt(result.minTrackGasGapDEta * result.minTrackGasGapDEta +
366  result.minTrackGasGapDPhi * result.minTrackGasGapDPhi);
367 }
GasGapData::gasgap
unsigned gasgap
Definition: RPCDQUtils.h:120
RpcPanel::stationPhi
int stationPhi
Definition: RPCDQUtils.h:40
dumpTgcDigiDeadChambers.gasGap
list gasGap
Definition: dumpTgcDigiDeadChambers.py:33
get_generator_info.result
result
Definition: get_generator_info.py:21
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
GasGapData::minStripEta
double minStripEta
Definition: RPCDQUtils.h:124
ExResult
Definition: RPCDQUtils.h:82
RpcPanel::RpcPanel
RpcPanel()=default
GasGapData::NphiStrips
unsigned NphiStrips
Definition: RPCDQUtils.h:123
GasGapData::gapid
Identifier gapid
Definition: RPCDQUtils.h:110
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
Trk::ParametersBase::position
const Amg::Vector3D & position() const
Access method for the position.
RpcIdHelper::doubletZ
int doubletZ(const Identifier &id) const
Definition: RpcIdHelper.cxx:1062
index
Definition: index.py:1
xAODP4Helpers.h
RpcPanel::doubletPhi
int doubletPhi
Definition: RPCDQUtils.h:43
RpcPanel::FillRpcId
void FillRpcId(Identifier id, const RpcIdHelper &rpcIdHelper)
Definition: RPCDQUtils.cxx:27
RpcPanel::operator>
bool operator>(const RpcPanel &rhs) const
Definition: RPCDQUtils.cxx:115
GasGapData::doubletR
int doubletR
Definition: RPCDQUtils.h:117
RpcIdHelper::measuresPhi
bool measuresPhi(const Identifier &id) const override
Definition: RpcIdHelper.cxx:1068
createCablingJSON.doubletR
int doubletR
Definition: createCablingJSON.py:10
xAOD::P4Helpers::deltaPhi
double deltaPhi(double phiA, double phiB)
delta Phi in range [-pi,pi[
Definition: xAODP4Helpers.h:69
MuonGM::RpcReadoutElement
An RpcReadoutElement corresponds to a single RPC module; therefore typicaly a barrel muon station con...
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/RpcReadoutElement.h:54
RpcPanel::readoutEl
const MuonGM::RpcReadoutElement * readoutEl
Definition: RPCDQUtils.h:27
RpcPrepDataContainer.h
MuonIdHelper::stationName
int stationName(const Identifier &id) const
Definition: MuonIdHelper.cxx:804
RpcIdHelper::channelID
Identifier channelID(int stationName, int stationEta, int stationPhi, int doubletR, int doubletZ, int doubletPhi, int gasGap, int measuresPhi, int strip) const
Definition: RpcIdHelper.cxx:940
GasGapData::readoutEl
const MuonGM::RpcReadoutElement * readoutEl
Definition: RPCDQUtils.h:108
RpcIdHelper
Definition: RpcIdHelper.h:51
RpcPanel::gasGap
int gasGap
Definition: RPCDQUtils.h:44
RpcIdHelper.h
RpcPanel
Definition: RPCDQUtils.h:20
RpcIdHelper::gasGap
int gasGap(const Identifier &id) const override
get the hashes
Definition: RpcIdHelper.cxx:1066
RpcPanel::stationEta
int stationEta
Definition: RPCDQUtils.h:39
RpcPanel::SetPanelIndex
void SetPanelIndex(int index)
Definition: RPCDQUtils.cxx:83
Trk::PropDirection
PropDirection
Definition: PropDirection.h:19
RpcPanel::getOnlineConvention
std::string getOnlineConvention() const
Definition: RPCDQUtils.cxx:120
GasGapData::minStripPhi
double minStripPhi
Definition: RPCDQUtils.h:126
GasGapData::NetaStrips
unsigned NetaStrips
Definition: RPCDQUtils.h:122
RpcIdHelper::doubletR
int doubletR(const Identifier &id) const
Definition: RpcIdHelper.cxx:1060
ExResult::ExResult
ExResult(const Identifier _gasgap_id, const Trk::PropDirection _direction)
Definition: RPCDQUtils.cxx:214
GasGapData::gapid_str
std::string gapid_str
Definition: RPCDQUtils.h:112
GasGapData::stationName
int stationName
Definition: RPCDQUtils.h:114
RpcPanel::getSectorLayer
std::pair< int, int > getSectorLayer() const
Definition: RPCDQUtils.cxx:184
GasGapData::stationEta
int stationEta
Definition: RPCDQUtils.h:115
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
MuonGM::RpcReadoutElement::NphiStrips
int NphiStrips() const
returns the number of phi strips
RpcPanel::doubletR
int doubletR
Definition: RPCDQUtils.h:41
RpcIdHelper::panelID
Identifier panelID(const Identifier &padID, int gasGap, int measuresPhi) const
Definition: RpcIdHelper.cxx:879
RpcPanel::panel_index
int panel_index
Definition: RPCDQUtils.h:46
RpcPanel::getElementStr
std::string getElementStr() const
Definition: RPCDQUtils.cxx:88
Trk::ParametersBase
Definition: ParametersBase.h:55
MuonGM::RpcReadoutElement::NetaStrips
int NetaStrips() const
returns the number of eta strips
GasGapData::computeTrackDistanceToGasGap
void computeTrackDistanceToGasGap(ExResult &result, const xAOD::TrackParticle &track) const
Definition: RPCDQUtils.cxx:290
MuonIdHelper::stationPhi
int stationPhi(const Identifier &id) const
Definition: MuonIdHelper.cxx:814
MuonIdHelper::stationNameString
const std::string & stationNameString(const int &index) const
Definition: MuonIdHelper.cxx:858
GasGapData::doubletZ
int doubletZ
Definition: RPCDQUtils.h:118
RPCDQUtils.h
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
RpcPanel::doubletZ
int doubletZ
Definition: RPCDQUtils.h:42
MuonGM::RpcReadoutElement::stripPos
Amg::Vector3D stripPos(const Identifier &id) const
Definition: MuonDetDescr/MuonReadoutGeometry/src/RpcReadoutElement.cxx:177
RpcPanel::panel_valid
bool panel_valid
Definition: RPCDQUtils.h:30
RpcIdHelper::gapID
Identifier gapID(const Identifier &padID, int gasGap) const
Definition: RpcIdHelper.cxx:926
RpcPanel::panelId
Identifier panelId
Definition: RPCDQUtils.h:29
GasGapData::maxStripEta
double maxStripEta
Definition: RPCDQUtils.h:125
MuonIdHelper::stationEta
int stationEta(const Identifier &id) const
Definition: MuonIdHelper.cxx:809
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
GasGapData::maxStripPhi
double maxStripPhi
Definition: RPCDQUtils.h:127
RpcPanel::stationName
int stationName
Definition: RPCDQUtils.h:38
GasGapData::doubletPhi
int doubletPhi
Definition: RPCDQUtils.h:119
DeMoScan.index
string index
Definition: DeMoScan.py:362
Muon::IMuonIdHelperSvc::toString
virtual std::string toString(const Identifier &id) const =0
print all fields to string
RpcPanel::operator==
bool operator==(const RpcPanel &rhs) const
Definition: RPCDQUtils.cxx:97
MuonGM::MuonReadoutElement::identify
Identifier identify() const override final
Returns the ATLAS Identifier of the MuonReadOutElement.
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MuonReadoutElement.h:184
GasGapData::stationPhi
int stationPhi
Definition: RPCDQUtils.h:116
Muon::IMuonIdHelperSvc
Interface for Helper service that creates muon Identifiers and can be used to print Identifiers.
Definition: IMuonIdHelperSvc.h:26
createCablingJSON.doubletPhi
int doubletPhi
Definition: createCablingJSON.py:11
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
RpcPanel::operator<
bool operator<(const RpcPanel &rhs) const
Definition: RPCDQUtils.cxx:110
RpcPanel::panel_name
std::string panel_name
Definition: RPCDQUtils.h:32
GasGapData::GasGapData
GasGapData(const Muon::IMuonIdHelperSvc &idHelperSvc, const MuonGM::RpcReadoutElement *_readoutEl, const int _doubletZ, const int _doubletPhi, const unsigned _gasgap)
Definition: RPCDQUtils.cxx:221
Muon::IMuonIdHelperSvc::rpcIdHelper
virtual const RpcIdHelper & rpcIdHelper() const =0
access to RpcIdHelper
RpcPanel::stationNameStr
std::string stationNameStr
Definition: RPCDQUtils.h:33
RpcPanel::measPhi
int measPhi
Definition: RPCDQUtils.h:45
RpcIdHelper::doubletPhi
int doubletPhi(const Identifier &id) const
Definition: RpcIdHelper.cxx:1064
GasGapData::gapid_valid
bool gapid_valid
Definition: RPCDQUtils.h:111
RpcPanel::panel_str
std::string panel_str
Definition: RPCDQUtils.h:31
RpcReadoutElement.h