ATLAS Offline Software
Nsw_CablingMap.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 std::ostream& operator<<(std::ostream& ostr,
8  const NswZebraData& connector) {
9  ostr << "First channel: " << connector.firstChannel
10  << ", last channel: " << connector.lastChannel
11  << " shift: " << connector.shiftChannel;
12  return ostr;
13 }
14 
15 
17  : m_idHelperSvc{svc} {}
18 
19 std::optional<Identifier> Nsw_CablingMap::correctChannel(const Identifier& id,
20  MsgStream& msg) const {
21  bool debug = msg.level() <= MSG::DEBUG;
22 
23  const MmIdHelper& mmHelper{m_idHelperSvc->mmIdHelper()};
24  const sTgcIdHelper& sTgcHelper{m_idHelperSvc->stgcIdHelper()};
25  LookUpMap::const_iterator itr = m_cablingMap.find(m_idHelperSvc->layerId(id));
26  if (itr == m_cablingMap.end()) {
27  if (debug)
28  msg << MSG::DEBUG << "The gas gap " << m_idHelperSvc->toString(id)
29  << " has no known cabling correction" << endmsg;
30  return std::make_optional<Identifier>(id);
31  }
32  const NswZebraSet& correctionSet{itr->second};
33  const int channel = m_idHelperSvc->isMM(id) ? mmHelper.channel(id) :
34  sTgcHelper.channel(id);
35  NswZebraSet::const_iterator zebra_conn = correctionSet.find(channel);
36  if (zebra_conn == correctionSet.end()) {
37  if (debug)
38  msg << MSG::DEBUG << "The zebra connector associated to "
39  << m_idHelperSvc->toString(id)
40  << " was mounted correctly -> no correction needed " << endmsg;
41  return std::make_optional<Identifier>(id);
42  }
43  const int newChannel = channel + zebra_conn->shiftChannel;
44  if (newChannel < zebra_conn->firstChannel ||
45  newChannel > zebra_conn->lastChannel) {
46  if (debug)
47  msg << MSG::DEBUG << "The associated channel "
48  << m_idHelperSvc->toString(id)
49  << " is shifted outside of the zebra connector range: "
50  << newChannel << ". Mask the channel." << endmsg;
51  return std::nullopt;
52  }
53  if (m_idHelperSvc->isMM(id)) {
54  const Identifier newId = mmHelper.channelID(id,
55  mmHelper.multilayer(id),
56  mmHelper.gasGap(id),
57  newChannel);
58  if (debug)
59  msg << MSG::DEBUG << "The input identifier "
60  << m_idHelperSvc->toString(id) << " is shifted to a new one "
61  << m_idHelperSvc->toString(newId) << endmsg;
62  return std::make_optional<Identifier>(std::move(newId));
63  }
64  const Identifier newId = sTgcHelper.channelID(id,
65  sTgcHelper.multilayer(id),
66  sTgcHelper.gasGap(id),
67  sTgcHelper.channelType(id),
68  newChannel);
69  if (debug)
70  msg << MSG::DEBUG << "The input identifier "
71  << m_idHelperSvc->toString(id) << " is shifted to a new one "
72  << m_idHelperSvc->toString(newId) << endmsg;
73 
74  return std::make_optional<Identifier>(std::move(newId));
75 }
77  const NswZebraData& connector,
78  MsgStream& msg) {
79  if (connector.firstChannel >= connector.lastChannel ||
80  !connector.shiftChannel) {
81  msg << MSG::ERROR << "Invalid zebra definition has been parsed for "
82  << m_idHelperSvc->toString(gapID) << ". " << connector << endmsg;
83  return false;
84  }
85  NswZebraSet& correctionSet = m_cablingMap[gapID];
86  if (correctionSet.count(connector.firstChannel) ||
87  correctionSet.count(connector.lastChannel)) {
88  msg << MSG::ERROR << "Zebra " << m_idHelperSvc->toString(gapID)
89  << " is already partially covered " << connector << endmsg;
90  return false;
91  }
92  msg << MSG::DEBUG << "Add new zebra connector " << connector << " to "
93  << m_idHelperSvc->toString(gapID) << "." << endmsg;
94  correctionSet.insert(connector);
95  return true;
96 }
NswZebraData::firstChannel
int16_t firstChannel
Definition: NswZebraData.h:20
Muon::IMuonIdHelperSvc::stgcIdHelper
virtual const sTgcIdHelper & stgcIdHelper() const =0
access to TgcIdHelper
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:24
Nsw_CablingMap.h
NswZebraData::shiftChannel
int16_t shiftChannel
Definition: NswZebraData.h:22
Muon::IMuonIdHelperSvc::mmIdHelper
virtual const MmIdHelper & mmIdHelper() const =0
access to CscIdHelper
Nsw_CablingMap::m_cablingMap
LookUpMap m_cablingMap
Definition: Nsw_CablingMap.h:48
NswZebraSet
std::set< NswZebraData, std::less<> > NswZebraSet
Definition: NswZebraData.h:38
Nsw_CablingMap::Nsw_CablingMap
Nsw_CablingMap(const Muon::IMuonIdHelperSvc *svc)
Definition: Nsw_CablingMap.cxx:16
Nsw_CablingMap::addConnector
bool addConnector(const Identifier &gapID, const NswZebraData &connector, MsgStream &msg)
Definition: Nsw_CablingMap.cxx:76
Muon::IMuonIdHelperSvc::layerId
virtual Identifier layerId(const Identifier &id) const =0
create a layer ID, returns tube id for the MDTs
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
NswZebraData::lastChannel
int16_t lastChannel
Definition: NswZebraData.h:21
Muon::IMuonIdHelperSvc::isMM
virtual bool isMM(const Identifier &id) const =0
returns whether this is a MM Identifier or not
debug
const bool debug
Definition: MakeUncertaintyPlots.cxx:53
NswZebraData
Definition: NswZebraData.h:18
sTgcIdHelper
Definition: sTgcIdHelper.h:55
Nsw_CablingMap::m_idHelperSvc
const Muon::IMuonIdHelperSvc * m_idHelperSvc
Definition: Nsw_CablingMap.h:42
MmIdHelper
Definition: MmIdHelper.h:54
Muon::IMuonIdHelperSvc::toString
virtual std::string toString(const Identifier &id) const =0
print all fields to string
operator<<
std::ostream & operator<<(std::ostream &ostr, const NswZebraData &connector)
Definition: Nsw_CablingMap.cxx:7
Nsw_CablingMap::correctChannel
std::optional< Identifier > correctChannel(const Identifier &id, MsgStream &msg) const
Definition: Nsw_CablingMap.cxx:19
DEBUG
#define DEBUG
Definition: page_access.h:11
Muon::IMuonIdHelperSvc
Interface for Helper service that creates muon Identifiers and can be used to print Identifiers.
Definition: IMuonIdHelperSvc.h:26
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
Identifier
Definition: IdentifierFieldParser.cxx:14