ATLAS Offline Software
STGC_ROD_Decoder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <memory>
6 #include <unordered_map>
7 
8 #include "MuonRDO/STGC_RawData.h"
12 
17 
18 #include "Identifier/Identifier.h"
19 #include "eformat/Issue.h"
20 #include "STGC_ROD_Decoder.h"
21 
23 
24 //==============================================================================
25 Muon::STGC_ROD_Decoder::STGC_ROD_Decoder(const std::string& t, const std::string& n, const IInterface* p)
26 : AthAlgTool(t, n, p)
27 {
28  declareInterface<ISTGC_ROD_Decoder>(this);
29 }
30 
31 
32 //==============================================================================
34 {
35  ATH_CHECK(detStore()->retrieve(m_stgcIdHelper, "STGCIDHELPER"));
36  ATH_CHECK(m_DetectorManagerKey.initialize());
37  ATH_CHECK(m_dscKey.initialize(!m_dscKey.empty()));
38  ATH_CHECK(m_cablingKey.initialize(!m_cablingKey.empty()));
39  return StatusCode::SUCCESS;
40 }
41 
42 
43 //===============================================================================
44 // Processes a ROB fragment and fills the RDO container.
45 // If the vector of IdentifierHashes is not empty, then seeded mode is assumed
46 // (only requested modules are decoded). This must be made here, because the
47 // trigger granularity is quadruplet, whereas ROB granularity is a whole sector
48 // (or wedge). Therefore, refined selection is needed with decoded information.
50  const ROBFragment& robFrag,
51  const std::vector<IdentifierHash>& rdoIdhVect,
52  std::unordered_map<IdentifierHash, std::unique_ptr<STGC_RawDataCollection>>& rdo_map) const
53 {
54 
55  // check fragment for errors
56  try {
57  robFrag.check();
58  } catch (const eformat::Issue &ex) {
59  ATH_MSG_WARNING(ex.what());
60  return StatusCode::SUCCESS;
61  }
62 
63  const NswDcsDbData* dcsData{nullptr};
64  if(!m_dscKey.empty()) {
65  SG::ReadCondHandle<NswDcsDbData> readCondHandle{m_dscKey, ctx};
66  if(!readCondHandle.isValid()){
67  ATH_MSG_ERROR("Cannot find the NSW DcsCondDataObj "<<m_dscKey.fullKey());
68  return StatusCode::FAILURE;
69  }
70  dcsData = readCondHandle.cptr();
71  }
72 
73  const Nsw_CablingMap* sTgcCablingMap{nullptr};
74  if (!m_cablingKey.empty()) {
75  SG::ReadCondHandle<Nsw_CablingMap> readCondHandle{m_cablingKey, ctx};
76  if(!readCondHandle.isValid()){
77  ATH_MSG_ERROR("Cannot find Micromegas cabling map!");
78  return StatusCode::FAILURE;
79  }
80  sTgcCablingMap = readCondHandle.cptr();
81  }
82 
83  SG::ReadCondHandle<MuonGM::MuonDetectorManager> muonGeoMgrHandle{m_DetectorManagerKey, ctx};
84 
85  if (!muonGeoMgrHandle.isValid()) {
86  ATH_MSG_FATAL("Failed to retrieve the detector manager from the conditions store");
87  return StatusCode::FAILURE;
88  }
89 
90  const MuonGM::MuonDetectorManager* muonGeoMgr = *muonGeoMgrHandle;
91 
92  // if the vector of hashes is not empty, then we are in seeded mode
93  bool seeded_mode(!rdoIdhVect.empty());
94 
95  // have the NSWCommonDecoder take care of the decoding
96  Muon::nsw::NSWCommonDecoder common_decoder(robFrag);
97  const std::vector<Muon::nsw::NSWElink *>& elinks = common_decoder.get_elinks();
98  ATH_MSG_DEBUG("Retrieved "<<elinks.size()<<" elinks");
99  if (elinks.empty()) return StatusCode::SUCCESS;
100 
101  // loop on elinks. for STGCs a "module" is a quadruplet
102  // therefore, we need an RDO (collection) per quadruplet!
103  for (auto* elink : elinks) {
104 
105  // skip null packets
106  if (elink->isNull()) continue;
107 
108  // get the offline ID hash (module ctx) to be passed to the RDO
109  // also specifies the index of the RDO in the container.
110  const char* station_name = elink->elinkId()->is_large_station() ? "STL" : "STS";
111  int station_eta = (int)elink->elinkId()->station_eta();
112  unsigned int station_phi = (unsigned int)elink->elinkId()->station_phi();
113  unsigned int multi_layer = (unsigned int)elink->elinkId()->multi_layer();
114  unsigned int gas_gap = (unsigned int)elink->elinkId()->gas_gap();
115  Identifier module_ID = m_stgcIdHelper->elementID(station_name, station_eta, station_phi);
116 
117  IdentifierHash module_hashID;
118  m_stgcIdHelper->get_module_hash(module_ID, module_hashID);
119  const MuonGM::sTgcReadoutElement* roElement = muonGeoMgr->getsTgcReadoutElement(module_ID);
120  // if we are in ROI-seeded mode, check if this hashID is requested
121  if (seeded_mode && std::find(rdoIdhVect.begin(), rdoIdhVect.end(), module_hashID) == rdoIdhVect.end()) continue;
122  std::unique_ptr<STGC_RawDataCollection>& rdo = rdo_map[module_hashID];
123  if (!rdo) rdo = std::make_unique<STGC_RawDataCollection>(module_hashID);
124 
125  // loop on all channels of this elink to fill the collection
126  const std::vector<Muon::nsw::VMMChannel*>& channels = elink->get_channels();
127  for (auto *channel : channels) {
128  unsigned int channel_number = channel->channel_number();
129  unsigned int channel_type = channel->channel_type();
130  if (channel_number == 0) continue; // skip disconnected vmm channels
131 
132  Identifier channel_ID = m_stgcIdHelper->channelID(module_ID, multi_layer, gas_gap, channel_type, channel_number); // not validating the IDs (too slow)
133  if (sTgcCablingMap) {
134  std::optional<Identifier> correctedChannelId = sTgcCablingMap->correctChannel(channel_ID, msgStream());
135  if (!correctedChannelId) {
136  ATH_MSG_DEBUG("Channel was shifted outside its connector and is therefore not decoded into and RDO");
137  continue;
138  }
139  channel_ID = (*correctedChannelId);
140  }
141  bool isOuterQ1{false};
142  if(std::abs(station_eta)==1 && dcsData){ // only the innermost quad is split in two hv sections, no need to check the others, also no need to check if no dcs data is loaded
144  if (!roElement->stripPosition(channel_ID, localPos)) continue; // can also handle wires and pads
145  isOuterQ1 = !(roElement->isEtaZero(channel_ID, localPos));
146  }
147 
148  if (dcsData && !dcsData->isGood(ctx, channel_ID, isOuterQ1)) continue;
149  bool timeAndChargeInCounts = true; // always true for data from detector
150  rdo->push_back(new STGC_RawData(channel_ID, channel->rel_bcid(), channel->tdo(), channel->pdo(), false,timeAndChargeInCounts)); // isDead = false (ok?)
151  }
152  }
153 
154  return StatusCode::SUCCESS;
155 }
156 
157 
158 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
Nsw_CablingMap
Definition: Nsw_CablingMap.h:18
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
sTgcIdHelper.h
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:24
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
sTgcReadoutElement.h
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
Issue
Configuration Issue
Definition: PscIssues.h:31
Muon::STGC_ROD_Decoder::fillCollection
virtual StatusCode fillCollection(const EventContext &ctx, const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment &, const std::vector< IdentifierHash > &, std::unordered_map< IdentifierHash, std::unique_ptr< STGC_RawDataCollection >> &rdo_map) const override
Convert ROBFragments to RDOs.
Definition: STGC_ROD_Decoder.cxx:49
STGC_ROD_Decoder.h
MuonGM::sTgcReadoutElement::isEtaZero
bool isEtaZero(const Identifier &id, const Amg::Vector2D &localPosition) const
is eta=0 of QL1 or QS1? Support for Strip and Pad cathodes is valid when the Strip,...
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/sTgcReadoutElement.h:382
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
dq_defect_copy_defect_database.channels
def channels
Definition: dq_defect_copy_defect_database.py:56
STGC_RawData.h
STGC_RawDataContainer.h
MuonGM::sTgcReadoutElement::stripPosition
virtual bool stripPosition(const Identifier &id, Amg::Vector2D &pos) const override final
strip position - should be renamed to channel position If the strip number is outside the range of va...
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/sTgcReadoutElement.h:321
Muon::nsw::NSWCommonDecoder
Definition: NSWCommonDecoder.h:20
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Muon::STGC_RawData
Definition: STGC_RawData.h:14
eformat::ROBFragment
Definition: L1CaloBsDecoderUtil.h:12
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
MuonGM::sTgcReadoutElement
An sTgcReadoutElement corresponds to a single STGC module; therefore typicaly a barrel muon station c...
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/sTgcReadoutElement.h:30
VMMChannel.h
NSWCommonDecoder.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
Muon::nsw::NSWCommonDecoder::get_elinks
const std::vector< Muon::nsw::NSWElink * > & get_elinks() const
Definition: NSWCommonDecoder.h:25
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment
eformat::ROBFragment< PointerType > ROBFragment
Definition: RawEvent.h:27
NswDcsDbData
Definition: NswDcsDbData.h:19
NSWResourceId.h
CalibCoolCompareRT.station_eta
station_eta
Definition: CalibCoolCompareRT.py:88
Muon::STGC_ROD_Decoder::initialize
virtual StatusCode initialize() override
Definition: STGC_ROD_Decoder.cxx:33
Muon::nsw::channel_type
channel_type
Definition: NSWDecodeHelper.h:21
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
MuonGM::MuonDetectorManager::getsTgcReadoutElement
const sTgcReadoutElement * getsTgcReadoutElement(const Identifier &id) const
access via extended identifier (requires unpacking)
Definition: MuonDetDescr/MuonReadoutGeometry/src/MuonDetectorManager.cxx:259
AthAlgTool
Definition: AthAlgTool.h:26
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
CalibCoolCompareRT.station_phi
station_phi
Definition: CalibCoolCompareRT.py:87
createCablingJSON.station_name
string station_name
Simple script to generate a BIS78 cabling map as used for the Monte Carlo processing.
Definition: createCablingJSON.py:13
generate::Zero
void Zero(TH1D *hin)
Definition: generate.cxx:32
Muon::STGC_ROD_Decoder::STGC_ROD_Decoder
STGC_ROD_Decoder(const std::string &t, const std::string &n, const IInterface *p)
Definition: STGC_ROD_Decoder.cxx:25
Identifier
Definition: IdentifierFieldParser.cxx:14