ATLAS Offline Software
StgcRawDataUtils.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 // Utils for the main sTGCRawDataMonAlg.cxx
7 // Part of StgcRawDataMonAlg.h
8 // see StgcRawDataMonAlg.cxx
10 
12 
14  return m_idHelperSvc -> sector(id)*(m_idHelperSvc -> stationEta(id) > 0 ? 1. : -1.);
15 }
16 
17 int sTgcRawDataMonAlg::getLayer(int multiplet, int gasGap) const {
18  return 4*(multiplet - 1) + gasGap;
19 }
20 
21 int32_t sTgcRawDataMonAlg::sourceidToSector(uint32_t sourceid, bool isSideA) const {
22  uint32_t sectorNumber = sourceid & 0xf;
23  return (isSideA) ? sectorNumber + 1: -sectorNumber - 1;
24 }
25 
27  // 1 bit of sign (0 = positive) followed by 5 bits of phiid
28  constexpr size_t nbitsPhi{5};
29  constexpr size_t mask{(1 << nbitsPhi) - 1};
30  return std::pow(-1, phiid >> nbitsPhi) * (phiid & mask);
31 }
32 
33 std::optional<Identifier> sTgcRawDataMonAlg::getPadId(uint32_t sourceid, uint32_t pfeb, uint32_t tdschan) const {
34  bool isValid = false;
35  const int side = (decoder::isA(sourceid)) ? 1 : -1;
36  const auto vmm = tdschan / NVMMCHAN + FIRSTPFEBVMM;
37  const auto vmmchan = tdschan % NVMMCHAN;
38  const auto sec = decoder::sector(sourceid);
39  const auto& help = m_idHelperSvc -> stgcIdHelper();
40  const auto pad_id = help.channelID(help.elementID(decoder::offlineStationName(sec),
42  decoder::offlineStationPhi(sourceid)),
46  decoder::offlineChannelNumber(sec, pfeb, vmm, vmmchan), isValid);
47 
48  if (!isValid) {
49  ATH_MSG_WARNING("Pad Identifier not valid, skipping");
50  return std::nullopt;
51  }
52 
53  return std::make_optional(pad_id);
54 }
55 
56 std::optional<std::tuple<Identifier, const Trk::RIO_OnTrack*>> sTgcRawDataMonAlg::getRotIdAndRotObject(const Trk::TrackStateOnSurface* trkState) const {
57  if (!trkState->type(Trk::TrackStateOnSurface::Measurement)) return std::nullopt;
58 
59  Identifier surfaceId = (trkState) -> surface().associatedDetectorElementIdentifier();
60  if(!m_idHelperSvc -> issTgc(surfaceId)) return std::nullopt;
61 
62  const Trk::MeasurementBase* meas = trkState->measurementOnTrack();
63  if(!meas) return std::nullopt;
64 
65  const Trk::RIO_OnTrack* rot = dynamic_cast<const Trk::RIO_OnTrack*>(meas);
66  if(!rot) return std::nullopt;
67 
68  Identifier rot_id = rot -> identify();
69 
70  if(!rot_id.is_valid()) {
71  ATH_MSG_WARNING("Invalid identifier found in Trk::RIO_OnTrack");
72  return std::nullopt;
73  }
74 
75  return std::make_tuple(rot_id, rot);
76 }
77 
78 std::optional<Identifier> sTgcRawDataMonAlg::getRotId(const Trk::TrackStateOnSurface* trkState) const {
79  std::optional<std::tuple<Identifier, const Trk::RIO_OnTrack*>> status = getRotIdAndRotObject(trkState);
80  if (!status.has_value()) return std::nullopt;
81  std::tuple<Identifier, const Trk::RIO_OnTrack*> rotIDtuple = status.value();
82 
83  return std::make_optional(std::get<Identifier>(rotIDtuple));
84 }
85 
86 std::optional<std::tuple<int, int, std::string, std::string, int>> sTgcRawDataMonAlg::getPadEtaPhiTuple(uint32_t sourceid, uint32_t pfeb, uint32_t tdschan) const {
87  bool isValid = false;
88  const int side = (decoder::isA(sourceid)) ? 1 : -1;
89  const auto vmm = tdschan / NVMMCHAN + FIRSTPFEBVMM;
90  const auto vmmchan = tdschan % NVMMCHAN;
91  const auto sec = decoder::sector(sourceid);
92 
93  mapper mapperSTG;
94 
95  int sector_type = decoder::isLarge(sec) ? 1 : 0;
96  int feb_radius = decoder::radius(pfeb);
97  int layer = decoder::layer(pfeb);
98  int channel_number = mapperSTG.channel_number(Muon::nsw::OFFLINE_CHANNEL_TYPE_PAD, sector_type, feb_radius, layer, vmm, vmmchan);
99 
100  const auto& help = m_idHelperSvc -> stgcIdHelper();
101  const auto pad_id = help.channelID(help.elementID(decoder::offlineStationName(sec),
103  decoder::offlineStationPhi(sourceid)),
107  channel_number, isValid);
108 
109 
110  if (!isValid) {
111  ATH_MSG_WARNING("Pad Identifier not valid, skipping");
112  return std::nullopt;
113  }
114 
115  int padPhi = help.padPhi(pad_id);
116  int padEta = help.padEta(pad_id);
117  int padPhiMax = help.padPhiMax();
118  int padEtaMax = help.padEtaMax();
119 
120  int padPhiTotal = padPhi + (padPhiMax + 1)*(decoder::offlineStationPhi(sourceid) - 1);
121  int padEtaTotal = padEta + (padEtaMax + 1)*(decoder::offlineStationAbsEta(pfeb) - 1);
122  std::string sideName = (side == 1) ? "A" : "C";
123  std::string sizeName = (decoder::offlineStationName(sec) == "STS") ? "S" : "L";
124 
125  return std::make_optional(std::make_tuple(padPhiTotal, padEtaTotal, sideName, sizeName, layer + 1));
126 }
127 
128 std::optional<double> sTgcRawDataMonAlg::band2theta(double rPosAtNSW, const MuonGM::MuonDetectorManager* muonDetectorManagerObject) const {
129  const auto& help = m_idHelperSvc -> stgcIdHelper();
130  bool isValid = false;
131 
132  const Identifier maxNSWZid = m_idHelperSvc -> stgcIdHelper().channelID("STL", 1, help.stationPhiMin(), help.multilayerMax(), help.gasGapMax(), sTgcIdHelper::sTgcChannelTypes::Pad, 1, isValid);
133 
134  if (!isValid) {
135  ATH_MSG_WARNING("Identifier for maximum value of NSW global Z-coordinate is invalid!");
136  return std::nullopt;
137  }
138 
140  (muonDetectorManagerObject -> getsTgcReadoutElement(maxNSWZid)) -> stripGlobalPosition(maxNSWZid, posNSW);
141  float posNSWZ = posNSW.z();
142 
143  double theta = std::atan(rPosAtNSW/posNSWZ);
144  return std::make_optional(theta);
145 }
146 
147 std::optional<double> sTgcRawDataMonAlg::band2eta(double rPosAtNSW, const MuonGM::MuonDetectorManager* muonDetectorManagerObject) const {
148  std::optional<double> status = band2theta(rPosAtNSW, muonDetectorManagerObject);
149  if (!status.has_value()) return std::nullopt;
150  double theta = status.value();
151  if (!std::isnormal(theta/2.)) return std::nullopt;
152  double eta = -std::log(std::tan(theta/2.));
153  return std::make_optional(eta);
154 }
155 
156 std::optional<double> sTgcRawDataMonAlg::rPosAtNsw2eta(double rPosAtNSW, bool isA, const MuonGM::MuonDetectorManager* muonDetectorManagerObject) const {
157  std::optional<double> status = band2eta(rPosAtNSW, muonDetectorManagerObject);
158  if (!status.has_value()) return std::nullopt;
159  double band2eta = status.value();
160  if (isA) {
161  return std::make_optional(band2eta);
162  }
163  else {
164  return std::make_optional(-band2eta);
165  }
166 }
167 
168 std::optional<double> sTgcRawDataMonAlg::bandId2eta(int bandid, bool isLarge, bool isA, const MuonGM::MuonDetectorManager* muonDetectorManagerObject) const {
169  double rPosAtNSW = MuonGM::sTgcReadoutElement::triggerBandIdToRadius(isLarge,bandid);
170  std::optional<double> status = rPosAtNsw2eta(rPosAtNSW, isA, muonDetectorManagerObject);
171  if (!status.has_value()) return std::nullopt;
172  double rPosAtNsw2eta = status.value();
173 
174  return std::make_optional(rPosAtNsw2eta);
175 }
176 
177 double sTgcRawDataMonAlg::triggersectorphiid2phi(uint32_t sourceid, int trigger_phiid) const {
178  MuonSectorMapping sectorMapping;
179  double trigger_sector_phicenter = sectorMapping.sectorPhi((sourceid & 0xf) + 1);
180  double trigger_phi = trigger_sector_phicenter + (trigger_phiid*9.)/1000.;
182  if((sourceid & 0xf) == 8 && trigger_phiid < 0) {
183  trigger_phi = -trigger_sector_phicenter + (trigger_phiid*9./1000.);
184  }
185  return trigger_phi;
186 }
sTgcRawDataMonAlg::rPosAtNsw2eta
std::optional< double > rPosAtNsw2eta(double rPosAtNSW, bool isA, const MuonGM::MuonDetectorManager *muonDetectorManagerObject) const
Definition: StgcRawDataUtils.cxx:156
dumpTgcDigiDeadChambers.gasGap
list gasGap
Definition: dumpTgcDigiDeadChambers.py:33
Muon::nsw::NSWPadTriggerL1a::offlineStationPhi
static uint32_t offlineStationPhi(const uint32_t sourceid)
Definition: NSWPadTriggerL1a.h:292
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
Muon::nsw::NSWPadTriggerL1a::offlineGasgap
static uint32_t offlineGasgap(const uint32_t pfeb)
Definition: NSWPadTriggerL1a.h:260
Muon::nsw::NSWPadTriggerL1a::isLarge
static bool isLarge(const uint32_t sec)
Definition: NSWPadTriggerL1a.h:196
Muon::nsw::MapperSTG::channel_number
uint16_t channel_number(uint8_t channel_type, uint8_t sector_type, uint8_t feb_radius, uint8_t layer, uint16_t vmm, uint16_t vmm_chan) const
Definition: MapperSTG.cxx:9
Muon::nsw::NSWPadTriggerL1a::isA
static bool isA(const uint32_t sourceid)
Definition: NSWPadTriggerL1a.h:210
Muon::nsw::NSWPadTriggerL1a::offlineMultilayer
static uint32_t offlineMultilayer(const uint32_t pfeb)
Definition: NSWPadTriggerL1a.h:267
theta
Scalar theta() const
theta method
Definition: AmgMatrixBasePlugin.h:75
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
Muon::nsw::NSWPadTriggerL1a::sector
static uint32_t sector(const uint32_t sourceid)
Definition: NSWPadTriggerL1a.h:239
xAOD::identify
Identifier identify(const UncalibratedMeasurement *meas)
Returns the associated identifier.
Definition: MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonPrepData/Root/UtilFunctions.cxx:61
Trk::TrackStateOnSurface::measurementOnTrack
const MeasurementBase * measurementOnTrack() const
returns MeasurementBase const overload
Trk::RIO_OnTrack
Definition: RIO_OnTrack.h:70
sTgcRawDataMonAlg::FIRSTPFEBVMM
static constexpr uint32_t FIRSTPFEBVMM
Definition: StgcRawDataMonAlg.h:58
isValid
bool isValid(const T &p)
Definition: AtlasPID.h:225
Identifier::is_valid
bool is_valid() const
Check if id is in a valid state.
MuonGM::sTgcReadoutElement::triggerBandIdToRadius
static double triggerBandIdToRadius(bool isLarge, int triggerBand)
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/sTgcReadoutElement.h:456
python.utils.AtlRunQueryLookup.mask
string mask
Definition: AtlRunQueryLookup.py:460
drawFromPickle.atan
atan
Definition: drawFromPickle.py:36
Muon::nsw::NSWPadTriggerL1a::offlineStationName
static std::string offlineStationName(const uint32_t sec)
Definition: NSWPadTriggerL1a.h:299
StgcRawDataMonAlg.h
Muon::nsw::NSWPadTriggerL1a::offlineChannelNumber
static uint32_t offlineChannelNumber(const uint32_t sec, const uint32_t pfeb, const uint32_t vmm, const uint32_t vmmchan)
Definition: NSWPadTriggerL1a.h:274
Muon::nsw::OFFLINE_CHANNEL_TYPE_PAD
@ OFFLINE_CHANNEL_TYPE_PAD
Definition: NSWDecodeHelper.h:22
sTgcRawDataMonAlg::getSectors
int getSectors(const Identifier &id) const
Definition: StgcRawDataUtils.cxx:13
TRT::Hit::side
@ side
Definition: HitInfo.h:83
sTgcRawDataMonAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: StgcRawDataMonAlg.h:66
sTgcRawDataMonAlg::getLayer
int getLayer(const int multiplet, const int gasGap) const
Definition: StgcRawDataUtils.cxx:17
Trk::TrackStateOnSurface::type
bool type(const TrackStateOnSurfaceType type) const
Use this method to find out if the TSoS is of a certain type: i.e.
Muon::nsw::NSWPadTriggerL1a::layer
static uint32_t layer(const uint32_t pfeb)
Definition: NSWPadTriggerL1a.h:232
Muon::nsw::NSWPadTriggerL1a::radius
static uint32_t radius(const uint32_t pfeb)
Definition: NSWPadTriggerL1a.h:225
sTgcRawDataMonAlg::sourceidToSector
int32_t sourceidToSector(uint32_t sourceid, bool isSideA) const
Definition: StgcRawDataUtils.cxx:21
python.CaloScaleNoiseConfig.help
help
Definition: CaloScaleNoiseConfig.py:76
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
sTgcRawDataMonAlg::triggersectorphiid2phi
double triggersectorphiid2phi(uint32_t sourceid, int trigger_phiid) const
Definition: StgcRawDataUtils.cxx:177
Muon::MuonSectorMapping::sectorPhi
double sectorPhi(int sector) const
returns the centeral phi position of a sector in radians
Definition: MuonSectorMapping.h:77
drawFromPickle.tan
tan
Definition: drawFromPickle.py:36
sTgcRawDataMonAlg::getPadId
std::optional< Identifier > getPadId(uint32_t sourceid, uint32_t pfeb, uint32_t tdschan) const
Definition: StgcRawDataUtils.cxx:33
sTgcRawDataMonAlg::getSignedPhiId
int getSignedPhiId(const uint32_t phiid) const
Definition: StgcRawDataUtils.cxx:26
Trk::MeasurementBase
Definition: MeasurementBase.h:58
Trk::TrackStateOnSurface
represents the track state (measurement, material, fit parameters and quality) at a surface.
Definition: TrackStateOnSurface.h:71
sTgcRawDataMonAlg::getRotId
std::optional< Identifier > getRotId(const Trk::TrackStateOnSurface *trkState) const
Definition: StgcRawDataUtils.cxx:78
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
MuonGM::MuonDetectorManager
The MuonDetectorManager stores the transient representation of the Muon Spectrometer geometry and pro...
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MuonDetectorManager.h:50
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
sTgcRawDataMonAlg::NVMMCHAN
static constexpr uint32_t NVMMCHAN
Definition: StgcRawDataMonAlg.h:57
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
sTgcRawDataMonAlg::band2eta
std::optional< double > band2eta(double rPosAtNSW, const MuonGM::MuonDetectorManager *muonDetectorManagerObject) const
Definition: StgcRawDataUtils.cxx:147
Muon::MuonSectorMapping
Definition: MuonSectorMapping.h:20
merge.status
status
Definition: merge.py:17
Muon::nsw::STGTPSegments::moduleIDBits::stationEta
constexpr uint8_t stationEta
1 to 3
Definition: NSWSTGTPDecodeBitmaps.h:156
sTgcRawDataMonAlg::getRotIdAndRotObject
std::optional< std::tuple< Identifier, const Trk::RIO_OnTrack * > > getRotIdAndRotObject(const Trk::TrackStateOnSurface *trkState) const
Definition: StgcRawDataUtils.cxx:56
Muon::nsw::NSWPadTriggerL1a::offlineStationAbsEta
static uint32_t offlineStationAbsEta(const uint32_t pfeb)
Definition: NSWPadTriggerL1a.h:285
sTgcRawDataMonAlg::band2theta
std::optional< double > band2theta(double rPosAtNSW, const MuonGM::MuonDetectorManager *muonDetectorManagerObject) const
Definition: StgcRawDataUtils.cxx:128
sTgcRawDataMonAlg::bandId2eta
std::optional< double > bandId2eta(int bandid, bool isLarge, bool isA, const MuonGM::MuonDetectorManager *muonDetectorManagerObject) const
Definition: StgcRawDataUtils.cxx:168
sTgcRawDataMonAlg::getPadEtaPhiTuple
std::optional< std::tuple< int, int, std::string, std::string, int > > getPadEtaPhiTuple(uint32_t sourceid, uint32_t pfeb, uint32_t tdschan) const
Definition: StgcRawDataUtils.cxx:86
Trk::TrackStateOnSurface::Measurement
@ Measurement
This is a measurement, and will at least contain a Trk::MeasurementBase.
Definition: TrackStateOnSurface.h:101
generate::Zero
void Zero(TH1D *hin)
Definition: generate.cxx:32
Muon::nsw::MapperSTG
Definition: MapperSTG.h:18
Identifier
Definition: IdentifierFieldParser.cxx:14