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 
13 int sTgcRawDataMonAlg::getFEBs(int eta, int layer) const {
14  int feb=-1;
15  if (std::abs(eta)==1) feb=layer-1;
16  else if(std::abs(eta)==2) feb=layer+7;
17  else if(std::abs(eta)==3) feb=layer+15;
18 
19  //ATH_MSG_DEBUG("FEB: " << feb << " Eta: " << eta << " Layer: " << layer);
20  return feb;
21 }
22 
24  return m_idHelperSvc -> sector(id)*(m_idHelperSvc -> stationEta(id) > 0 ? 1. : -1.);
25 }
26 
27 int sTgcRawDataMonAlg::getLayer(int multiplet, int gasGap) const {
28  return 4*(multiplet - 1) + gasGap;
29 }
30 
31 int32_t sTgcRawDataMonAlg::sourceidToSector(uint32_t sourceid, bool isSideA) const {
32  uint32_t sectorNumber = sourceid & 0xf;
33  return (isSideA) ? sectorNumber + 1: -sectorNumber - 1;
34 }
35 
37  // 1 bit of sign (0 = positive) followed by 5 bits of phiid
38  constexpr size_t nbitsPhi{5};
39  constexpr size_t mask{(1 << nbitsPhi) - 1};
40  return std::pow(-1, phiid >> nbitsPhi) * (phiid & mask);
41 }
42 
43 std::optional<Identifier> sTgcRawDataMonAlg::getPadId(uint32_t sourceid, uint32_t pfeb, uint32_t tdschan) const {
44  bool isValid = false;
45  const int side = (decoder::isA(sourceid)) ? 1 : -1;
46  const auto vmm = tdschan / NVMMCHAN + FIRSTPFEBVMM;
47  const auto vmmchan = tdschan % NVMMCHAN;
48  const auto sec = decoder::sector(sourceid);
49  const auto& help = m_idHelperSvc -> stgcIdHelper();
50  const auto pad_id = help.channelID(help.elementID(decoder::offlineStationName(sec),
52  decoder::offlineStationPhi(sourceid)),
56  decoder::offlineChannelNumber(sec, pfeb, vmm, vmmchan), isValid);
57 
58  if (!isValid) {
59  ATH_MSG_WARNING("Pad Identifier not valid, skipping");
60  return std::nullopt;
61  }
62 
63  return std::make_optional(pad_id);
64 }
65 
66 std::optional<std::tuple<Identifier, const Trk::RIO_OnTrack*>> sTgcRawDataMonAlg::getRotIdAndRotObject(const Trk::TrackStateOnSurface* trkState) const {
67  if (!trkState->type(Trk::TrackStateOnSurface::Measurement)) return std::nullopt;
68 
69  Identifier surfaceId = (trkState) -> surface().associatedDetectorElementIdentifier();
70  if(!m_idHelperSvc -> issTgc(surfaceId)) return std::nullopt;
71 
72  const Trk::MeasurementBase* meas = trkState->measurementOnTrack();
73  if(!meas) return std::nullopt;
74 
75  const Trk::RIO_OnTrack* rot = dynamic_cast<const Trk::RIO_OnTrack*>(meas);
76  if(!rot) return std::nullopt;
77 
78  Identifier rot_id = rot -> identify();
79 
80  if(!rot_id.is_valid()) {
81  ATH_MSG_WARNING("Invalid identifier found in Trk::RIO_OnTrack");
82  return std::nullopt;
83  }
84 
85  return std::make_tuple(rot_id, rot);
86 }
87 
88 std::optional<Identifier> sTgcRawDataMonAlg::getRotId(const Trk::TrackStateOnSurface* trkState) const {
89  std::optional<std::tuple<Identifier, const Trk::RIO_OnTrack*>> status = getRotIdAndRotObject(trkState);
90  if (!status.has_value()) return std::nullopt;
91  std::tuple<Identifier, const Trk::RIO_OnTrack*> rotIDtuple = status.value();
92 
93  return std::make_optional(std::get<Identifier>(rotIDtuple));
94 }
95 
96 std::optional<std::tuple<int, int, std::string, std::string, int>> sTgcRawDataMonAlg::getPadEtaPhiTuple(uint32_t sourceid, uint32_t pfeb, uint32_t tdschan) const {
97  bool isValid = false;
98  const int side = (decoder::isA(sourceid)) ? 1 : -1;
99  const auto vmm = tdschan / NVMMCHAN + FIRSTPFEBVMM;
100  const auto vmmchan = tdschan % NVMMCHAN;
101  const auto sec = decoder::sector(sourceid);
102 
103  mapper mapperSTG;
104 
105  int sector_type = decoder::isLarge(sec) ? 1 : 0;
106  int feb_radius = decoder::radius(pfeb);
107  int layer = decoder::layer(pfeb);
108  int channel_number = mapperSTG.channel_number(Muon::nsw::OFFLINE_CHANNEL_TYPE_PAD, sector_type, feb_radius, layer, vmm, vmmchan);
109 
110  const auto& help = m_idHelperSvc -> stgcIdHelper();
111  const auto pad_id = help.channelID(help.elementID(decoder::offlineStationName(sec),
113  decoder::offlineStationPhi(sourceid)),
117  channel_number, isValid);
118 
119 
120  if (!isValid) {
121  ATH_MSG_WARNING("Pad Identifier not valid, skipping");
122  return std::nullopt;
123  }
124 
125  int padPhi = help.padPhi(pad_id);
126  int padEta = help.padEta(pad_id);
127  int padPhiMax = help.padPhiMax();
128  int padEtaMax = help.padEtaMax();
129 
130  int padPhiTotal = padPhi + (padPhiMax + 1)*(decoder::offlineStationPhi(sourceid) - 1);
131  int padEtaTotal = padEta + (padEtaMax + 1)*(decoder::offlineStationAbsEta(pfeb) - 1);
132  std::string sideName = (side == 1) ? "A" : "C";
133  std::string sizeName = (decoder::offlineStationName(sec) == "STS") ? "S" : "L";
134 
135  return std::make_optional(std::make_tuple(padPhiTotal, padEtaTotal, sideName, sizeName, layer + 1));
136 }
137 
138 std::optional<double> sTgcRawDataMonAlg::band2theta(double rPosAtNSW, const MuonGM::MuonDetectorManager* muonDetectorManagerObject) const {
139  const auto& help = m_idHelperSvc -> stgcIdHelper();
140  bool isValid = false;
141 
142  const Identifier maxNSWZid = m_idHelperSvc -> stgcIdHelper().channelID("STL", 1, help.stationPhiMin(), help.multilayerMax(), help.gasGapMax(), sTgcIdHelper::sTgcChannelTypes::Pad, 1, isValid);
143 
144  if (!isValid) {
145  ATH_MSG_WARNING("Identifier for maximum value of NSW global Z-coordinate is invalid!");
146  return std::nullopt;
147  }
148 
150  (muonDetectorManagerObject -> getsTgcReadoutElement(maxNSWZid)) -> stripGlobalPosition(maxNSWZid, posNSW);
151  float posNSWZ = posNSW.z();
152 
153  double theta = std::atan(rPosAtNSW/posNSWZ);
154  return std::make_optional(theta);
155 }
156 
157 std::optional<double> sTgcRawDataMonAlg::band2eta(double rPosAtNSW, const MuonGM::MuonDetectorManager* muonDetectorManagerObject) const {
158  std::optional<double> status = band2theta(rPosAtNSW, muonDetectorManagerObject);
159  if (!status.has_value()) return std::nullopt;
160  double theta = status.value();
161  if (!std::isnormal(theta/2.)) return std::nullopt;
162  double eta = -std::log(std::tan(theta/2.));
163  return std::make_optional(eta);
164 }
165 
166 std::optional<double> sTgcRawDataMonAlg::rPosAtNsw2eta(double rPosAtNSW, bool isA, const MuonGM::MuonDetectorManager* muonDetectorManagerObject) const {
167  std::optional<double> status = band2eta(rPosAtNSW, muonDetectorManagerObject);
168  if (!status.has_value()) return std::nullopt;
169  double band2eta = status.value();
170  if (isA) {
171  return std::make_optional(band2eta);
172  }
173  else {
174  return std::make_optional(-band2eta);
175  }
176 }
177 
178 std::optional<double> sTgcRawDataMonAlg::bandId2eta(int bandid, bool isLarge, bool isA, const MuonGM::MuonDetectorManager* muonDetectorManagerObject) const {
179  double rPosAtNSW = MuonGM::sTgcReadoutElement::triggerBandIdToRadius(isLarge,bandid);
180  std::optional<double> status = rPosAtNsw2eta(rPosAtNSW, isA, muonDetectorManagerObject);
181  if (!status.has_value()) return std::nullopt;
182  double rPosAtNsw2eta = status.value();
183 
184  return std::make_optional(rPosAtNsw2eta);
185 }
186 
187 double sTgcRawDataMonAlg::triggersectorphiid2phi(uint32_t sourceid, int trigger_phiid) const {
188  MuonSectorMapping sectorMapping;
189  double trigger_sector_phicenter = sectorMapping.sectorPhi((sourceid & 0xf) + 1);
190  double trigger_phi = trigger_sector_phicenter + (trigger_phiid*9.)/1000.;
192  if((sourceid & 0xf) == 8 && trigger_phiid < 0) {
193  trigger_phi = -trigger_sector_phicenter + (trigger_phiid*9./1000.);
194  }
195  return trigger_phi;
196 }
sTgcRawDataMonAlg::rPosAtNsw2eta
std::optional< double > rPosAtNsw2eta(double rPosAtNSW, bool isA, const MuonGM::MuonDetectorManager *muonDetectorManagerObject) const
Definition: StgcRawDataUtils.cxx:166
xAOD::identify
const Identifier & identify(const UncalibratedMeasurement *meas)
Returns the associated identifier from the muon measurement.
Definition: MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonPrepData/Root/UtilFunctions.cxx:82
dumpTgcDigiDeadChambers.gasGap
list gasGap
Definition: dumpTgcDigiDeadChambers.py:33
Muon::nsw::NSWPadTriggerL1a::offlineStationPhi
static uint32_t offlineStationPhi(const uint32_t sourceid)
Definition: NSWPadTriggerL1a.h:298
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:266
Muon::nsw::NSWPadTriggerL1a::isLarge
static bool isLarge(const uint32_t sec)
Definition: NSWPadTriggerL1a.h:202
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:216
Muon::nsw::NSWPadTriggerL1a::offlineMultilayer
static uint32_t offlineMultilayer(const uint32_t pfeb)
Definition: NSWPadTriggerL1a.h:273
theta
Scalar theta() const
theta method
Definition: AmgMatrixBasePlugin.h:75
Muon::nsw::NSWPadTriggerL1a::sector
static uint32_t sector(const uint32_t sourceid)
Definition: NSWPadTriggerL1a.h:245
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)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition: AtlasPID.h:867
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:459
drawFromPickle.atan
atan
Definition: drawFromPickle.py:36
Muon::nsw::NSWPadTriggerL1a::offlineStationName
static std::string offlineStationName(const uint32_t sec)
Definition: NSWPadTriggerL1a.h:305
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:280
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:23
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:27
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:238
Muon::nsw::NSWPadTriggerL1a::radius
static uint32_t radius(const uint32_t pfeb)
Definition: NSWPadTriggerL1a.h:231
sTgcRawDataMonAlg::sourceidToSector
int32_t sourceidToSector(uint32_t sourceid, bool isSideA) const
Definition: StgcRawDataUtils.cxx:31
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
sTgcRawDataMonAlg::triggersectorphiid2phi
double triggersectorphiid2phi(uint32_t sourceid, int trigger_phiid) const
Definition: StgcRawDataUtils.cxx:187
Muon::MuonSectorMapping::sectorPhi
double sectorPhi(int sector) const
returns the centeral phi position of a sector in radians
Definition: MuonSectorMapping.h:81
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:43
sTgcRawDataMonAlg::getFEBs
int getFEBs(int eta, int layers) const
Definition: StgcRawDataUtils.cxx:13
sTgcRawDataMonAlg::getSignedPhiId
int getSignedPhiId(const uint32_t phiid) const
Definition: StgcRawDataUtils.cxx:36
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
python.CaloAddPedShiftConfig.help
help
Definition: CaloAddPedShiftConfig.py:42
sTgcRawDataMonAlg::getRotId
std::optional< Identifier > getRotId(const Trk::TrackStateOnSurface *trkState) const
Definition: StgcRawDataUtils.cxx:88
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:51
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:157
Muon::MuonSectorMapping
Definition: MuonSectorMapping.h:20
merge.status
status
Definition: merge.py:16
Muon::nsw::STGTPSegments::moduleIDBits::stationEta
constexpr uint8_t stationEta
1 to 3
Definition: NSWSTGTPDecodeBitmaps.h:159
sTgcRawDataMonAlg::getRotIdAndRotObject
std::optional< std::tuple< Identifier, const Trk::RIO_OnTrack * > > getRotIdAndRotObject(const Trk::TrackStateOnSurface *trkState) const
Definition: StgcRawDataUtils.cxx:66
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15
Muon::nsw::NSWPadTriggerL1a::offlineStationAbsEta
static uint32_t offlineStationAbsEta(const uint32_t pfeb)
Definition: NSWPadTriggerL1a.h:291
sTgcRawDataMonAlg::band2theta
std::optional< double > band2theta(double rPosAtNSW, const MuonGM::MuonDetectorManager *muonDetectorManagerObject) const
Definition: StgcRawDataUtils.cxx:138
sTgcRawDataMonAlg::bandId2eta
std::optional< double > bandId2eta(int bandid, bool isLarge, bool isA, const MuonGM::MuonDetectorManager *muonDetectorManagerObject) const
Definition: StgcRawDataUtils.cxx:178
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:96
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