ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
MuonSpectrometer
MuonCablings
MuonCablingData
src
MdtMezzanineCard.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3
*/
4
#include <
MuonCablingData/MdtMezzanineCard.h
>
5
6
#include <algorithm>
7
#include <iostream>
8
#include <set>
9
10
namespace
{
11
using
Mapping =
MdtMezzanineCard::Mapping
;
12
using
OfflineCh =
MdtMezzanineCard::OfflineCh
;
13
std::ostream&
operator<<
(std::ostream& ostr,
const
Mapping&
map
) {
14
for
(
unsigned
int
ch = 0;
ch
<
map
.size(); ++
ch
) {
15
ostr <<
ch
<<
" -> "
<<
static_cast<
int
>
(
map
[
ch
]);
16
if
(ch != (
map
.size() - 1))
17
ostr <<
", "
;
18
}
19
return
ostr;
20
}
21
}
// namespace
22
std::ostream&
operator<<
(std::ostream& ostr,
const
MdtMezzanineCard
&
map
) {
23
ostr <<
"MezzId: "
<<
static_cast<
int
>
(
map
.id()) <<
", "
;
24
ostr <<
"nTubeLayer: "
<<
static_cast<
int
>
(
map
.numTubeLayers()) <<
", "
;
25
ostr <<
"tdcToTubeMap: "
<<
map
.tdcToTubeMap() <<
", "
;
26
ostr <<
"tubeToTdcMap: "
<< std::endl;
27
for
(uint8_t lay =
map
.numTubeLayers(); lay > 0; --lay) {
28
if
(!(lay % 2))
29
ostr <<
" "
;
30
for
(uint8_t tube = 1; tube <=
map
.numTubesPerLayer(); ++tube) {
31
uint8_t tubeNum =
map
.tubeNumber(lay, tube);
32
ostr << std::setw(5)
33
<<
static_cast<
int
>
(
map
.tubeToTdcMap()[tubeNum]);
34
}
35
ostr << std::endl;
36
}
37
return
ostr;
38
}
39
MdtMezzanineCard::MdtMezzanineCard
(
const
Mapping
&
tdcToTubeMap
,
40
uint8_t num_layers, uint8_t mezz_id)
41
:
m_tdcToTubes
{
tdcToTubeMap
},
m_nlay
{num_layers},
m_mezzId
{mezz_id} {
43
m_nTubes
=
m_tdcToTubes
.size() / num_layers;
45
for
(
unsigned
int
tdc = 0; tdc <
m_tdcToTubes
.size(); ++tdc) {
46
uint8_t tube =
m_tdcToTubes
[tdc];
47
if
(tube <
m_tubesToTdc
.size())
48
m_tubesToTdc
[tube] = tdc;
49
}
50
}
51
52
bool
MdtMezzanineCard::checkConsistency
(MsgStream& log)
const
{
53
const
bool
debug
= (log.level() <= MSG::VERBOSE);
54
if
(
debug
) {
55
log << MSG::VERBOSE <<
" Check consistency of mezzanine card "
56
<<
static_cast<
int
>
(
id
()) <<
"."
<<
endmsg
;
57
}
58
if
(
numTubeLayers
() != 3 &&
numTubeLayers
() != 4) {
59
log << MSG::ERROR <<
"Mezzanine card "
<<
static_cast<
int
>
(
id
())
60
<<
" has invalid many tube layers "
61
<<
static_cast<
int
>
(
numTubeLayers
()) <<
endmsg
;
62
return
false
;
63
}
65
std::set<uint8_t> uniqueSet{};
66
std::copy_if(
m_tdcToTubes
.begin(),
m_tdcToTubes
.end(),
67
std::inserter(uniqueSet, uniqueSet.end()),
68
[](
const
uint8_t ch) { return ch != NOTSET; });
69
unsigned
int
unmapped
=
70
std::count_if(
m_tdcToTubes
.begin(),
m_tdcToTubes
.end(),
71
[](
const
uint8_t ch) { return ch == NOTSET; });
72
if
((uniqueSet.size() +
unmapped
) !=
m_tdcToTubes
.size()) {
73
log << MSG::ERROR
74
<<
"Mezzanine card has unassigned tdc -> tube channels "
<<
endmsg
;
75
log << MSG::ERROR <<
"Mapped channels "
<< uniqueSet.size()
76
<<
" dead channels: "
<<
unmapped
<< std::endl;
77
log << MSG::ERROR <<
"Please check "
<< (*this) <<
endmsg
;
78
return
false
;
79
}
80
if
(
unmapped
==
m_tdcToTubes
.size()) {
81
log << MSG::ERROR
82
<<
"Mezzanine card does not have any associated channel "
<<
endmsg
;
83
log << MSG::ERROR <<
"Please check "
<< (*this) <<
endmsg
;
84
}
85
uniqueSet.clear();
86
std::copy_if(
m_tubesToTdc
.begin(),
m_tubesToTdc
.end(),
87
std::inserter(uniqueSet, uniqueSet.end()),
88
[](
const
uint8_t ch) { return ch != NOTSET; });
89
unmapped
= std::count_if(
m_tubesToTdc
.begin(),
m_tubesToTdc
.end(),
90
[](
const
uint8_t ch) { return ch == NOTSET; });
91
if
((uniqueSet.size() +
unmapped
) !=
m_tubesToTdc
.size()) {
92
log << MSG::ERROR <<
" Mezzanine card maps tubes -> tdc inconsitently "
93
<<
endmsg
;
94
log << MSG::ERROR <<
"Mapped channels "
<< uniqueSet.size()
95
<<
" dead channels: "
<<
unmapped
<< std::endl;
96
log << MSG::ERROR <<
" Please check "
<< (*this) <<
endmsg
;
97
return
false
;
98
}
99
if
(
debug
) {
100
log << MSG::VERBOSE <<
" All checks passed "
<< std::endl
101
<< (*this) <<
endmsg
;
102
}
103
return
true
;
104
}
105
106
uint8_t
MdtMezzanineCard::tdcChannel
(uint8_t tubeLay, uint8_t tube,
107
MsgStream&
msg
)
const
{
108
if
(tubeLay >
numTubeLayers
()) {
109
msg
<< MSG::WARNING <<
"MdtMezzanineCard::tdcChannel() -- Tube layer "
110
<<
static_cast<
int
>
(tubeLay) <<
" is out of range. Max allowed "
111
<<
static_cast<
int
>
(
numTubeLayers
()) <<
endmsg
;
112
return
NOTSET
;
113
}
114
uint8_t globTubeNum =
tubeNumber
(tubeLay, tube);
115
if
(
msg
.level() <= MSG::VERBOSE) {
116
msg
<<
"MdtMezzanineCard::tdcChannel() -- Resolved layer "
117
<<
static_cast<
int
>
(tubeLay) <<
" & tube "
<<
static_cast<
int
>
(tube)
118
<<
" to "
<<
static_cast<
int
>
(globTubeNum) <<
endmsg
;
119
}
120
return
m_tubesToTdc
[globTubeNum];
121
}
122
uint8_t
MdtMezzanineCard::tubeNumber
(uint8_t tubeLay, uint8_t tube)
const
{
123
return
((tube - 1) %
numTubesPerLayer
()) +
124
(
numTubesPerLayer
() * (tubeLay - 1));
125
}
126
OfflineCh
MdtMezzanineCard::offlineTube
(uint8_t tdc, MsgStream&
msg
)
const
{
127
if
(tdc >=
m_tdcToTubes
.size()) {
128
msg
<< MSG::WARNING <<
" Tdc channel is out of range "
129
<<
static_cast<
int
>
(tdc) <<
endmsg
;
130
return
{};
131
}
132
uint8_t globTubeNum =
m_tdcToTubes
[tdc];
133
uint8_t tube = globTubeNum %
numTubesPerLayer
();
134
uint8_t lay = (globTubeNum - tube) /
numTubesPerLayer
();
135
OfflineCh
ret{};
138
ret.
tube
= tube;
139
ret.
layer
= lay + 1;
140
ret.
isValid
= globTubeNum !=
NOTSET
;
141
return
ret;
142
}
endmsg
#define endmsg
Definition
AnalysisConfig_Ntuple.cxx:54
HitType::unmapped
@ unmapped
Definition
FPGATrackSimHit.h:39
debug
const bool debug
Definition
MakeUncertaintyPlots.cxx:53
operator<<
std::ostream & operator<<(std::ostream &ostr, const MdtMezzanineCard &map)
Definition
MdtMezzanineCard.cxx:22
MdtMezzanineCard.h
MdtMezzanineCard
MdtMezzanineCard - Helper struct to represent the structure of a mezzanine card in a consistent way E...
Definition
MdtMezzanineCard.h:35
MdtMezzanineCard::NOTSET
static constexpr uint8_t NOTSET
Definition
MdtMezzanineCard.h:37
MdtMezzanineCard::checkConsistency
bool checkConsistency(MsgStream &msg) const
checks whether the tdc mapping is complete.
Definition
MdtMezzanineCard.cxx:52
MdtMezzanineCard::offlineTube
OfflineCh offlineTube(uint8_t tdc, MsgStream &msg) const
Definition
MdtMezzanineCard.cxx:126
MdtMezzanineCard::m_mezzId
uint8_t m_mezzId
Mezzanine database identifier.
Definition
MdtMezzanineCard.h:95
MdtMezzanineCard::m_tubesToTdc
Mapping m_tubesToTdc
Mapping of the mezzanine tube number to the tdc channel.
Definition
MdtMezzanineCard.h:89
MdtMezzanineCard::numTubesPerLayer
uint8_t numTubesPerLayer() const
returns the number of tubes per layer;
Definition
MdtMezzanineCard.h:69
MdtMezzanineCard::tdcToTubeMap
const Mapping & tdcToTubeMap() const
Returns the underlying TDC -> Tube conversion map.
Definition
MdtMezzanineCard.h:81
MdtMezzanineCard::id
uint8_t id() const
returns mezzanine database identifier
Definition
MdtMezzanineCard.h:65
MdtMezzanineCard::m_tdcToTubes
Mapping m_tdcToTubes
Mapping of the tdc channels to the mezzanine tube number.
Definition
MdtMezzanineCard.h:87
MdtMezzanineCard::m_nlay
uint8_t m_nlay
Number of tube layers.
Definition
MdtMezzanineCard.h:91
MdtMezzanineCard::tdcChannel
uint8_t tdcChannel(uint8_t tubeLay, uint8_t tube, MsgStream &msg) const
returns the tdc channel number
Definition
MdtMezzanineCard.cxx:106
MdtMezzanineCard::Mapping
std::array< uint8_t, 24 > Mapping
Definition
MdtMezzanineCard.h:40
MdtMezzanineCard::numTubeLayers
uint8_t numTubeLayers() const
returns the number of layers
Definition
MdtMezzanineCard.h:67
MdtMezzanineCard::MdtMezzanineCard
MdtMezzanineCard(const Mapping &tdcToTubeMap, uint8_t num_layers, uint8_t mezz_id)
Standard constructor of the mezzanine card.
Definition
MdtMezzanineCard.cxx:39
MdtMezzanineCard::tubeNumber
uint8_t tubeNumber(uint8_t tubeLay, uint8_t tube) const
returns the tube number
Definition
MdtMezzanineCard.cxx:122
MdtMezzanineCard::m_nTubes
uint8_t m_nTubes
Number of tubes per layer.
Definition
MdtMezzanineCard.h:93
map
STL class.
sendEI_SPB.ch
ch
Definition
sendEI_SPB.py:35
MdtMezzanineCard::OfflineCh
Helper struct to pipe the result from the tdc -> offline channel translation.
Definition
MdtMezzanineCard.h:73
MdtMezzanineCard::OfflineCh::tube
uint8_t tube
Definition
MdtMezzanineCard.h:74
MdtMezzanineCard::OfflineCh::isValid
bool isValid
Definition
MdtMezzanineCard.h:76
MdtMezzanineCard::OfflineCh::layer
uint8_t layer
Definition
MdtMezzanineCard.h:75
msg
MsgStream & msg
Definition
testRead.cxx:32
Generated on
for ATLAS Offline Software by
1.17.0