ATLAS Offline Software
CscRODReadOut.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef MUONCSC_CNVTOOL_CSCRODREADOUT_H
6 #define MUONCSC_CNVTOOL_CSCRODREADOUT_H
7 
8 #include <stdint.h>
9 
10 #include <atomic>
11 #include <cmath>
12 #include <string>
13 #include <vector>
14 #include <stdexcept>
15 
17 
18 // TGC ROD encoder/decoder for CscRDO
19 // Author Ketevi A. Assamagan
20 // BNL December 27 2003
21 
23 public:
24  CscRODReadOut();
25  CscRODReadOut(double startTime, double signalWidth, uint16_t numIntegration);
26  ~CscRODReadOut() = default;
27 
28  // more static header/footer information
31  uint32_t numSamples() const { return NUM_SAMPLES; }
32  uint32_t latency() const { return LATENCY; }
33  uint32_t samplingRate() const { return RATE; }
34  uint32_t numDPU() const { return NUM_DPU; }
35 
36  // DPU header info
37  uint32_t dpuHeader() const { return DPU_HEADER_MARKER; }
39 
40  // get additional info
41  double getStartTime() const { return m_TIME_OFFSET; }
42  double getConversion() const { return m_CHARGE_TO_ADC_COUNT; }
43  double getMaxTimeBin() const { return m_Z0; }
44 
45  // encoding
47  void encodeFragments(const std::vector<uint16_t>& amplitude, std::vector<uint32_t>& v) const;
48 
49  // initialize helper
50  void set(const CscIdHelper* cscIdHelper) { m_cscIdHelper = cscIdHelper; }
52 
53  void setParams(double timeOffset, double signalWidth);
54 
55  // testing
56  bool isDPU(const uint32_t fragment) const;
57  bool discard(const uint32_t fragment) const;
58  bool isAmplitude(const uint16_t fragment) const;
59  bool isAddress(const uint32_t fragment) const;
60 
61  // Decoding
62  void decodeSourceID(uint32_t sourceIdIDIn, uint16_t& sourceID, uint16_t& moduleType, uint16_t& subDetectorId, uint16_t& rodId) const;
63  void decodeAmplitude(const uint32_t fragment, uint16_t& amp1, uint16_t& amp2) const;
64  uint32_t fragmentToAddress(const uint32_t fragment) const;
66  uint32_t hashIdentifier(const uint32_t address, const Identifier& moduleId) const;
67 
68  uint32_t numberOfStrips(const uint32_t fragment) const;
69  Identifier decodeAddress(const uint32_t address, const Identifier& moduleId) const;
70  Identifier decodeAddress(const uint32_t address, const Identifier& moduleId, int j) const;
71  static int findCharge(double samplingTime, const std::vector<uint16_t>& amplitude, double& time) ;
72  double signal_amplitude(double samplingTime) const;
73  uint32_t address(const Identifier& channelId, int& eta, int& phi) const;
74 
75 private:
78  double m_norm;
79 
80  double m_TIME_OFFSET;
84  double m_Z0;
85 
86  static const uint32_t ROD_HEADER_SIZE = 12;
87 
88  static const uint32_t ROD_FOOTER_SIZE = 0x0;
89 
90  static const uint16_t SOURCE_ID = 0x00;
91  static const uint16_t MODULE_TYPE = 0x00;
92 
93  static const uint16_t BODY_AMPLITUDE = 0x0000;
94  static const uint32_t BODY_ADDRESS = 0x00000000;
95 
96  static const uint32_t NUM_SAMPLES = 25;
97  static const uint32_t LATENCY = 0;
98  static const uint32_t RATE = 40;
99  static const uint32_t NUM_DPU = 12;
100 
101  static const uint32_t DPU_HEADER_MARKER = 0xC5F38856;
102  static const uint32_t DPU_HEADER_SIZE = 13;
103 
104  static const uint32_t DPU_DISCARD = 0xFFFFFFFF;
105 
106  void set32bits(const uint16_t* v16, uint32_t& v32) const;
107  double signal(double z) const;
108 };
109 
110 inline void CscRODReadOut::setParams(double timeOffset, double signalWidth) {
111  m_TIME_OFFSET = timeOffset;
112  m_SIGNAL_WIDTH = signalWidth;
113 }
114 
116  uint32_t sourceIdentifier = 0;
117  sourceIdentifier = SOURCE_ID << 24 | MODULE_TYPE << 16 | side << 8 | rodId;
118  return sourceIdentifier;
119 }
120 
121 inline void CscRODReadOut::decodeSourceID(uint32_t sourceIDIn, uint16_t& sourceID, uint16_t& moduleType, uint16_t& subDetectorId,
122  uint16_t& rodId) const {
123  sourceID = (sourceIDIn & 0xff000000) >> 24;
124  moduleType = (sourceIDIn & 0x00ff0000) >> 16;
125  subDetectorId = (sourceIDIn & 0x0000ff00) >> 8;
126  rodId = (sourceIDIn & 0x000000ff);
127 }
128 
129 inline void CscRODReadOut::set32bits(const uint16_t* v16, uint32_t& v32) const {
130  uint32_t p = 0, v = 0;
131  uint16_t n = 2;
132  uint16_t pos[] = {16, 0};
133  for (uint16_t i = 0; i < n; i++) {
134  v = (uint32_t)(*(v16 + i));
135  p = (uint32_t)(*(pos + i));
136  v32 = v32 | (v << p);
137  }
138 }
139 
140 inline bool CscRODReadOut::isDPU(const uint32_t fragment) const { return (fragment == DPU_HEADER_MARKER); }
141 
142 inline bool CscRODReadOut::discard(const uint32_t fragment) const { return (fragment == DPU_DISCARD); }
143 
144 inline bool CscRODReadOut::isAmplitude(const uint16_t fragment) const {
145  uint16_t amplitudeTest = (fragment >> 12);
146  return (amplitudeTest == BODY_AMPLITUDE);
147 }
148 
149 inline bool CscRODReadOut::isAddress(const uint32_t fragment) const {
150  uint32_t addressTest = (fragment >> 17);
151  return (addressTest == BODY_ADDRESS);
152 }
153 
154 inline void CscRODReadOut::decodeAmplitude(const uint32_t fragment, uint16_t& amp1, uint16_t& amp2) const {
155  amp2 = 0x0000FFFF & fragment;
156  amp1 = (0xFFFF0000 & fragment) >> 16;
157 }
158 
159 inline uint32_t CscRODReadOut::fragmentToAddress(const uint32_t fragment) const { return 0x0001FFFF & fragment; }
160 
162  int stationName = ((address & 0x00010000) >> 16) + 50;
163  int stationEta = (((address & 0x00001000) >> 12) == 0x0) ? -1 : 1;
164  int stationPhi = ((address & 0x0000E000) >> 13) + 1;
165 
167 }
168 
169 // module Id is given and strip is from address.
170 // This should be flipped.
171 inline Identifier CscRODReadOut::decodeAddress(const uint32_t address, const Identifier& moduleId) const {
172  int chamberLayer = ((address & 0x00000800) >> 11) + m_chamberBitValue;
173 
174  int wireLayer = ((address & 0x00000600) >> 9) + 1;
175  int measuresPhi = ((address & 0x00000100) >> 8);
176 
177  int strip = (address & 0x000000FF) + 1;
178 
179  int stationEta = (((address & 0x00001000) >> 12) == 0x0) ? -1 : 1;
180 
181  // Added to Online -> Offline id in A side number is opposite bug#56002
182  if (measuresPhi) {
183  if (stationEta > 0) strip = 49 - strip;
184  }
185 
186  return m_cscIdHelper->channelID(moduleId, chamberLayer, wireLayer, measuresPhi, strip);
187 }
188 
189 // module Id is given and strip is from address.
190 // This should be flipped.
191 inline Identifier CscRODReadOut::decodeAddress(const uint32_t address, const Identifier& moduleId, int j) const {
192  int chamberLayer = ((address & 0x00000800) >> 11) + m_chamberBitValue;
193 
194  int wireLayer = ((address & 0x00000600) >> 9) + 1;
195  int measuresPhi = ((address & 0x00000100) >> 8);
196  int strip = (address & 0x000000FF) + 1 + j;
197 
198  // Added to Online -> Offline id in A side number is opposite bug#56002
199  if (measuresPhi) {
200  int stationEta = (((address & 0x00001000) >> 12) == 0x0) ? -1 : 1;
201  if (stationEta > 0) strip = 49 - strip;
202  }
203 
204  return m_cscIdHelper->channelID(moduleId, chamberLayer, wireLayer, measuresPhi, strip);
205 }
206 
207 // module Id is given and strip is from address.
208 // This should be flipped.
209 inline uint32_t CscRODReadOut::hashIdentifier(const uint32_t address, const Identifier& moduleId) const {
210  int chamberLayer = ((address & 0x00000800) >> 11) + m_chamberBitValue;
211 
212  int wireLayer = ((address & 0x00000600) >> 9) + 1;
213  int measuresPhi = ((address & 0x00000100) >> 8);
214  int strip = (address & 0x000000FF) + 1;
215 
216  // Added to Online -> Offline id in A side number is opposite bug#56002
217  if (measuresPhi) {
218  int stationEta = (((address & 0x00001000) >> 12) == 0x0) ? -1 : 1;
219  if (stationEta > 0) strip = 49 - strip;
220  }
221 
222  Identifier id = m_cscIdHelper->channelID(moduleId, chamberLayer, wireLayer, measuresPhi, strip);
225  if (m_cscIdHelper->get_hash(id, hash, &context)){
226  throw (std::runtime_error("CscRODReadOut::hashIdentifier: Unable to get identifier!"));
227  };
228  return (uint32_t)hash;
229 }
230 
231 inline uint32_t CscRODReadOut::numberOfStrips(const uint32_t fragment) const {
232  uint32_t address = fragmentToAddress(fragment);
233  Identifier moduleId = decodeAddress(address);
236 }
237 
238 // get the signal amplitude for a given sampling time (ns)
239 inline double CscRODReadOut::signal_amplitude(double samplingTime) const {
240  if (samplingTime <= m_TIME_OFFSET) return 0.0;
241  double z = (samplingTime - m_TIME_OFFSET) / m_SIGNAL_WIDTH;
242  return signal(z) / m_norm;
243 }
244 
245 // signal amplitude as a function of the time bin z
246 inline double CscRODReadOut::signal(double z) const {
247  double amplitude = (1.0 - z / (1 + m_NUMBER_OF_INTEGRATION)) * std::pow(z, m_NUMBER_OF_INTEGRATION) * exp(-z);
248  return amplitude;
249 }
250 
251 // find the address of this strip
252 // This function is called by CscDigitToCscRdoTool
253 // so return address should be consistent to online
254 inline uint32_t CscRODReadOut::address(const Identifier& channelId, int& eta, int& phi) const {
255  // unpack the strip identifier
259  int chamberLayer = m_cscIdHelper->chamberLayer(channelId);
260  int wireLayer = m_cscIdHelper->wireLayer(channelId);
261  int orientation = m_cscIdHelper->measuresPhi(channelId);
263 
264  // NOPE. Don't flip it!! This strip is for CscDigitToCscRdoTool online address
265 
266  // redefine the ranges
267  uint32_t nameIndex = uint32_t(name - 50);
268  uint32_t etaIndex = (eta == -1) ? 0 : 1;
269  uint32_t phiIndex = uint32_t(phi - 1);
270  uint32_t chamberIndex = uint32_t(chamberLayer - 0);
271  uint32_t layerIndex = uint32_t(wireLayer - 1);
272  uint32_t stripType = uint32_t(orientation);
273  uint32_t stripNumber = uint32_t(strip - 1);
274 
275  if (m_chamberBitValue == 1) chamberIndex = uint32_t(chamberLayer - 1);
276 
277  // build the address
278  uint32_t address =
279  nameIndex << 16 | phiIndex << 13 | etaIndex << 12 | chamberIndex << 11 | layerIndex << 9 | stripType << 8 | stripNumber;
280 
281  return address;
282 }
283 
284 #endif // MUONCSC_CNVTOOL_CSCRODREADOUT_H
CscIdHelper.h
CscRODReadOut::decodeAddress
Identifier decodeAddress(const uint32_t address) const
Definition: CscRODReadOut.h:161
CscRODReadOut::hashIdentifier
uint32_t hashIdentifier(const uint32_t address, const Identifier &moduleId) const
Definition: CscRODReadOut.h:209
CscRODReadOut::getSourceID
uint32_t getSourceID(uint16_t side, uint16_t rodId) const
Definition: CscRODReadOut.h:115
CscRODReadOut::ROD_FOOTER_SIZE
static const uint32_t ROD_FOOTER_SIZE
Definition: CscRODReadOut.h:88
Muon::nsw::STGTPSegments::moduleIDBits::stationPhi
constexpr uint8_t stationPhi
station Phi 1 to 8
Definition: NSWSTGTPDecodeBitmaps.h:161
CscIdHelper::stripMax
static int stripMax()
Definition: CscIdHelper.cxx:804
CscRODReadOut::numberOfStrips
uint32_t numberOfStrips(const uint32_t fragment) const
Definition: CscRODReadOut.h:231
CscRODReadOut::findCharge
static int findCharge(double samplingTime, const std::vector< uint16_t > &amplitude, double &time)
Definition: CscRODReadOut.cxx:70
CscRODReadOut::setParams
void setParams(double timeOffset, double signalWidth)
Definition: CscRODReadOut.h:110
CscRODReadOut::getMaxTimeBin
double getMaxTimeBin() const
Definition: CscRODReadOut.h:43
SiliconTech::strip
@ strip
CscRODReadOut::MODULE_TYPE
static const uint16_t MODULE_TYPE
Definition: CscRODReadOut.h:91
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
dumpTgcDigiDeadChambers.stationName
dictionary stationName
Definition: dumpTgcDigiDeadChambers.py:30
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
MuonIdHelper::channel_context
IdContext channel_context() const
id for channel
Definition: MuonIdHelper.cxx:741
CscRODReadOut::m_Z0
double m_Z0
Definition: CscRODReadOut.h:84
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
CscRODReadOut::NUM_SAMPLES
static const uint32_t NUM_SAMPLES
Definition: CscRODReadOut.h:96
CscRODReadOut::DPU_HEADER_MARKER
static const uint32_t DPU_HEADER_MARKER
Definition: CscRODReadOut.h:101
CscRODReadOut::m_norm
double m_norm
Definition: CscRODReadOut.h:78
lumiFormat.startTime
startTime
Definition: lumiFormat.py:95
CscRODReadOut::numSamples
uint32_t numSamples() const
Definition: CscRODReadOut.h:31
CscRODReadOut::samplingRate
uint32_t samplingRate() const
Definition: CscRODReadOut.h:33
athena.value
value
Definition: athena.py:124
CscRODReadOut::m_cscIdHelper
const CscIdHelper * m_cscIdHelper
Definition: CscRODReadOut.h:76
MuonIdHelper::stationName
int stationName(const Identifier &id) const
Definition: MuonIdHelper.cxx:800
drawFromPickle.exp
exp
Definition: drawFromPickle.py:36
CscRODReadOut::fragmentToAddress
uint32_t fragmentToAddress(const uint32_t fragment) const
Definition: CscRODReadOut.h:159
TRT::Hit::side
@ side
Definition: HitInfo.h:83
CscRODReadOut::address
uint32_t address(const Identifier &channelId, int &eta, int &phi) const
Definition: CscRODReadOut.h:254
CscRODReadOut::getHeaderSize
uint32_t getHeaderSize() const
Definition: CscRODReadOut.h:29
CscRODReadOut::decodeAmplitude
void decodeAmplitude(const uint32_t fragment, uint16_t &amp1, uint16_t &amp2) const
Definition: CscRODReadOut.h:154
CscRODReadOut::LATENCY
static const uint32_t LATENCY
Definition: CscRODReadOut.h:97
CscIdHelper::wireLayer
int wireLayer(const Identifier &id) const
Definition: CscIdHelper.cxx:772
CscRODReadOut::set
void set(const CscIdHelper *cscIdHelper)
Definition: CscRODReadOut.h:50
CscRODReadOut::~CscRODReadOut
~CscRODReadOut()=default
CscRODReadOut::dpuHeader
uint32_t dpuHeader() const
Definition: CscRODReadOut.h:37
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
CscRODReadOut
Definition: CscRODReadOut.h:22
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:93
CscRODReadOut::isAmplitude
bool isAmplitude(const uint16_t fragment) const
Definition: CscRODReadOut.h:144
lumiFormat.i
int i
Definition: lumiFormat.py:85
z
#define z
CscRODReadOut::BODY_AMPLITUDE
static const uint16_t BODY_AMPLITUDE
Definition: CscRODReadOut.h:93
CscRODReadOut::setChamberBitVaue
void setChamberBitVaue(uint32_t value)
Definition: CscRODReadOut.h:51
beamspotman.n
n
Definition: beamspotman.py:731
CscRODReadOut::BODY_ADDRESS
static const uint32_t BODY_ADDRESS
Definition: CscRODReadOut.h:94
CscRODReadOut::m_chamberBitValue
uint32_t m_chamberBitValue
Definition: CscRODReadOut.h:77
CscRODReadOut::m_TIME_OFFSET
double m_TIME_OFFSET
Definition: CscRODReadOut.h:80
CscRODReadOut::signal
double signal(double z) const
Definition: CscRODReadOut.h:246
CscRODReadOut::m_CHARGE_TO_ADC_COUNT
double m_CHARGE_TO_ADC_COUNT
Definition: CscRODReadOut.h:83
CaloCondBlobAlgs_fillNoiseFromASCII.channelId
channelId
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:122
CscRODReadOut::getConversion
double getConversion() const
Definition: CscRODReadOut.h:42
CscRODReadOut::discard
bool discard(const uint32_t fragment) const
Definition: CscRODReadOut.h:142
CscRODReadOut::numDPU
uint32_t numDPU() const
Definition: CscRODReadOut.h:34
MuonIdHelper::stationPhi
int stationPhi(const Identifier &id) const
Definition: MuonIdHelper.cxx:810
CscRODReadOut::isDPU
bool isDPU(const uint32_t fragment) const
Definition: CscRODReadOut.h:140
CscRODReadOut::set32bits
void set32bits(const uint16_t *v16, uint32_t &v32) const
Definition: CscRODReadOut.h:129
CscRODReadOut::encodeFragments
void encodeFragments(const std::vector< uint16_t > &amplitude, std::vector< uint32_t > &v) const
Definition: CscRODReadOut.cxx:53
CscRODReadOut::DPU_HEADER_SIZE
static const uint32_t DPU_HEADER_SIZE
Definition: CscRODReadOut.h:102
CscIdHelper::channelID
Identifier channelID(int stationName, int stationEta, int stationPhi, int chamberLayer, int wireLayer, int measuresPhi, int strip) const
Definition: CscIdHelper.cxx:706
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
CscRODReadOut::signal_amplitude
double signal_amplitude(double samplingTime) const
Definition: CscRODReadOut.h:239
MuonIdHelper::stationEta
int stationEta(const Identifier &id) const
Definition: MuonIdHelper.cxx:805
RTTAlgmain.address
address
Definition: RTTAlgmain.py:55
CscRODReadOut::getFooterSize
uint32_t getFooterSize() const
Definition: CscRODReadOut.h:30
CscRODReadOut::isAddress
bool isAddress(const uint32_t fragment) const
Definition: CscRODReadOut.h:149
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
CscIdHelper::elementID
Identifier elementID(int stationName, int stationEta, int stationPhi) const
Definition: CscIdHelper.cxx:678
eflowRec::phiIndex
unsigned int phiIndex(float phi, float binsize)
calculate phi index for a given phi
Definition: EtaPhiLUT.cxx:23
python.PyAthena.v
v
Definition: PyAthena.py:154
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
CscIdHelper
Definition: CscIdHelper.h:52
MuonIdHelper::get_hash
virtual int get_hash(const Identifier &id, IdentifierHash &hash_id, const IdContext *context=0) const override
Create hash id from compact id (return == 0 for OK)
Definition: MuonIdHelper.cxx:144
CscIdHelper::strip
int strip(const Identifier &id) const
Definition: CscIdHelper.cxx:776
CscRODReadOut::dpuHeaderSize
uint32_t dpuHeaderSize() const
Definition: CscRODReadOut.h:38
CscRODReadOut::m_NUMBER_OF_INTEGRATION
int m_NUMBER_OF_INTEGRATION
Definition: CscRODReadOut.h:82
CscRODReadOut::DPU_DISCARD
static const uint32_t DPU_DISCARD
Definition: CscRODReadOut.h:104
CscRODReadOut::getStartTime
double getStartTime() const
Definition: CscRODReadOut.h:41
CscRODReadOut::decodeSourceID
void decodeSourceID(uint32_t sourceIdIDIn, uint16_t &sourceID, uint16_t &moduleType, uint16_t &subDetectorId, uint16_t &rodId) const
Definition: CscRODReadOut.h:121
CscRODReadOut::SOURCE_ID
static const uint16_t SOURCE_ID
Definition: CscRODReadOut.h:90
CscIdHelper::measuresPhi
bool measuresPhi(const Identifier &id) const override
Definition: CscIdHelper.cxx:774
Muon::nsw::STGTPSegments::moduleIDBits::stationEta
constexpr uint8_t stationEta
1 to 3
Definition: NSWSTGTPDecodeBitmaps.h:159
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
CscRODReadOut::CscRODReadOut
CscRODReadOut()
Definition: CscRODReadOut.cxx:8
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15
CscRODReadOut::ROD_HEADER_SIZE
static const uint32_t ROD_HEADER_SIZE
Definition: CscRODReadOut.h:86
CscRODReadOut::RATE
static const uint32_t RATE
Definition: CscRODReadOut.h:98
IdContext
This class saves the "context" of an expanded identifier (ExpandedIdentifier) for compact or hash ver...
Definition: IdContext.h:26
CscRODReadOut::m_SIGNAL_WIDTH
double m_SIGNAL_WIDTH
Definition: CscRODReadOut.h:81
CscRODReadOut::NUM_DPU
static const uint32_t NUM_DPU
MHz.
Definition: CscRODReadOut.h:99
CscIdHelper::chamberLayer
int chamberLayer(const Identifier &id) const
Definition: CscIdHelper.cxx:770
CscRODReadOut::latency
uint32_t latency() const
Definition: CscRODReadOut.h:32
Identifier
Definition: IdentifierFieldParser.cxx:14