ATLAS Offline Software
Loading...
Searching...
No Matches
CscRODReadOutV1.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef MUONCSC_CNVTOOL_CSCRODREADOUTV1_H
6#define MUONCSC_CNVTOOL_CSCRODREADOUTV1_H
7
8#include <stdint.h>
9
10#include <cmath>
11#include <vector>
12
14
15// TGC ROD encoder/decoder for CscRDO
16// Author Ketevi A. Assamagan
17// BNL December 27 2003
18
20public:
22 CscRODReadOutV1(double startTime, uint16_t samplingTime, double signalWidth, uint16_t numIntegration);
23 ~CscRODReadOutV1() = default;
24
25 // more static header/footer information
26 uint32_t getHeaderSize() { return ROD_HEADER_SIZE; }
27 uint32_t getFooterSize() { return ROD_FOOTER_SIZE; }
28 uint32_t numSamples() { return NUM_SAMPLES; }
29 uint32_t latency() { return LATENCY; }
30 uint32_t samplingRate() { return RATE; }
31 uint32_t numDPU() { return NUM_DPU; }
32 void triggerInfo(uint32_t* trigger) {
33 for (int i = 0; i < 3; i++) *(trigger + i) = m_TRIGGER_INFO[i];
34 };
35
36 // DPU header info
37 uint32_t dpuHeader() { return DPU_HEADER_MARKER; }
38 uint32_t dpuHeaderSize() { return DPU_HEADER_SIZE; }
39
40 // get additional info
41 double getSamplingTime() { return m_SAMPLING_TIME; }
42 void setSamplingTime(double time) { m_SAMPLING_TIME = time; }
43 double getStartTime() { return m_TIME_OFFSET; }
45 double getMaxTimeBin() { return m_Z0; }
46
47 // encoding
48 uint32_t getSourceID(uint16_t side, uint16_t rodId);
49 void encodeFragments(const std::vector<uint16_t>& amplitude, std::vector<uint32_t>& v) const;
50
51 // initialize helper
52 void set(const CscIdHelper* cscHelper) { m_cscHelper = cscHelper; }
53
54 void setParams(double timeOffset, double samplingTime, double signalWidth);
55
56 void setParams(double samplingTime);
57
58 // testing
59 bool isDPU(const uint32_t fragment) const;
60 bool discard(const uint32_t fragment) const;
61 bool isAmplitude(const uint16_t fragment) const;
62 bool isAddress(const uint32_t fragment) const;
63
64 // Decoding
65 void decodeSourceID(uint32_t sourceId);
66 void decodeAmplitude(const uint32_t fragment);
67 void decodeAddress(const uint32_t fragment);
69 uint32_t hashIdentifier(const Identifier& moduleId);
70
71 uint32_t numberOfStrips(const uint32_t fragment);
72 void setAddress(const uint32_t address);
73 Identifier decodeAddress(const Identifier& moduleId);
74 Identifier decodeAddress(const Identifier& moduleId, int j);
75 int findCharge(const std::vector<uint16_t>& amplitude, double& time);
76 double signal_amplitude(double samplingTime) const;
77 uint32_t address(const Identifier& channelId, int& eta, int& phi) const;
78
79 // Retrieve decoded results
80 uint16_t sourceID() const { return m_sourceID; }
81 uint16_t moduleType() const { return m_moduleType; }
82 uint16_t subDetectorId() const { return m_subDetectorId; }
83 uint16_t rodId() const { return m_rodId; }
84 uint16_t getAmp1() const { return m_amp1; }
85 uint16_t getAmp2() const { return m_amp2; }
86 uint32_t address() const { return m_address; }
87
88private:
90 uint16_t m_sourceID;
91 uint16_t m_moduleType;
92 uint16_t m_rodId;
94 uint16_t m_amp1;
95 uint16_t m_amp2;
96 uint32_t m_address;
97 double m_norm;
98
104 double m_Z0;
105
106 uint32_t m_TRIGGER_INFO[3]{};
107
108 static const uint32_t ROD_HEADER_SIZE = 12;
109
110 static const uint32_t ROD_FOOTER_SIZE = 0x0;
111
112 static const uint16_t SOURCE_ID = 0x00;
113 static const uint16_t MODULE_TYPE = 0x00;
114
115 static const uint16_t BODY_AMPLITUDE = 0x0000;
116 static const uint32_t BODY_ADDRESS = 0x00000000;
117
118 static const uint32_t NUM_SAMPLES = 25;
119 static const uint32_t LATENCY = 0;
120 static const uint32_t RATE = 40;
121 static const uint32_t NUM_DPU = 12;
122
123 static const uint32_t DPU_HEADER_MARKER = 0xC5F38856;
124 static const uint32_t DPU_HEADER_SIZE = 13;
125
126 static const uint32_t DPU_DISCARD = 0xFFFFFFFF;
127
128 void set32bits(const uint16_t* v16, uint32_t& v32) const;
129 double signal(double z) const;
130};
131
132inline void CscRODReadOutV1::setParams(double timeOffset, double samplingTime, double signalWidth) {
133 m_TIME_OFFSET = timeOffset;
134 m_SAMPLING_TIME = samplingTime;
135 m_SIGNAL_WIDTH = signalWidth;
136}
137
138inline void CscRODReadOutV1::setParams(double samplingTime) { m_SAMPLING_TIME = samplingTime; }
139
140inline uint32_t CscRODReadOutV1::getSourceID(uint16_t side, uint16_t rodId) {
141 uint32_t sourceIdentifier = 0;
142 sourceIdentifier = SOURCE_ID << 24 | MODULE_TYPE << 16 | side << 8 | rodId;
143 return sourceIdentifier;
144}
145
147 m_sourceID = (sourceID & 0xff000000) >> 24;
148 m_moduleType = (sourceID & 0x00ff0000) >> 16;
149 m_subDetectorId = (sourceID & 0x0000ff00) >> 8;
150 m_rodId = (sourceID & 0x000000ff);
151}
152
153inline void CscRODReadOutV1::set32bits(const uint16_t* v16, uint32_t& v32) const {
154 uint32_t p = 0, v = 0;
155 uint16_t n = 2;
156 uint16_t pos[] = {0, 16};
157 for (uint16_t i = 0; i < n; i++) {
158 v = (uint32_t)(*(v16 + i));
159 p = (uint32_t)(*(pos + i));
160 v32 = v32 | (v << p);
161 }
162}
163
164inline bool CscRODReadOutV1::isDPU(const uint32_t fragment) const { return (fragment == DPU_HEADER_MARKER); }
165
166inline bool CscRODReadOutV1::discard(const uint32_t fragment) const { return (fragment == DPU_DISCARD); }
167
168inline bool CscRODReadOutV1::isAmplitude(const uint16_t fragment) const {
169 uint16_t amplitudeTest = (fragment >> 12);
170 return (amplitudeTest == BODY_AMPLITUDE);
171}
172
173inline bool CscRODReadOutV1::isAddress(const uint32_t fragment) const {
174 uint32_t addressTest = (fragment >> 17);
175 return (addressTest == BODY_ADDRESS);
176}
177
178inline void CscRODReadOutV1::decodeAmplitude(const uint32_t fragment) {
179 m_amp1 = 0x0000FFFF & fragment;
180 m_amp2 = (0xFFFF0000 & fragment) >> 16;
181}
182
183inline void CscRODReadOutV1::decodeAddress(const uint32_t fragment) {
184 uint32_t address = 0x0001FFFF & fragment;
186 int stationName = ((address & 0x00010000) >> 16) + 50;
187 int stationEta = (((address & 0x00001000) >> 12) == 0x0) ? -1 : 1;
188 int stationPhi = ((address & 0x0000E000) >> 13) + 1;
189 int chamberLayer = ((address & 0x00000800) >> 11) + 1;
190 int wireLayer = ((address & 0x00000600) >> 9) + 1;
191 int measuresPhi = ((address & 0x00000100) >> 8);
192 int strip = (address & 0x000000FF) + 1;
193
194 // redefine the ranges
195 uint32_t nameIndex = uint32_t(stationName - 50);
196 uint32_t etaIndex = (stationEta == -1) ? 0 : 1;
197 uint32_t phiIndex = uint32_t(stationPhi - 1);
198 uint32_t chamberIndex = uint32_t(chamberLayer - 0);
199 uint32_t layerIndex = uint32_t(wireLayer - 1);
200 uint32_t stripType = uint32_t(measuresPhi);
201 uint32_t stripNumber = uint32_t(strip - 1);
202
203 // build the address
204 m_address = nameIndex << 16 | phiIndex << 13 | etaIndex << 12 | chamberIndex << 11 | layerIndex << 9 | stripType << 8 | stripNumber;
205}
206
208 int stationName = ((m_address & 0x00010000) >> 16) + 50;
209 int stationEta = (((m_address & 0x00001000) >> 12) == 0x0) ? -1 : 1;
210 int stationPhi = ((m_address & 0x0000E000) >> 13) + 1;
211
212 return m_cscHelper->elementID(stationName, stationEta, stationPhi);
213}
214
215inline void CscRODReadOutV1::setAddress(const uint32_t address) { m_address = address; }
216
218 int chamberLayer = ((m_address & 0x00000800) >> 11) + 0;
219 int wireLayer = ((m_address & 0x00000600) >> 9) + 0;
220 int measuresPhi = ((m_address & 0x00000100) >> 8);
221 int strip = (m_address & 0x000000FF) + 1;
222 return m_cscHelper->channelID(moduleId, chamberLayer, wireLayer, measuresPhi, strip);
223}
224
226 int chamberLayer = ((m_address & 0x00000800) >> 11) + 0;
227 int wireLayer = ((m_address & 0x00000600) >> 9) + 1;
228 int measuresPhi = ((m_address & 0x00000100) >> 8);
229 int strip = (m_address & 0x000000FF) + 1 + j;
230 return m_cscHelper->channelID(moduleId, chamberLayer, wireLayer, measuresPhi, strip);
231}
232
233inline uint32_t CscRODReadOutV1::hashIdentifier(const Identifier& moduleId) {
234 int chamberLayer = ((m_address & 0x00000800) >> 11) + 0;
235 int wireLayer = ((m_address & 0x00000600) >> 9) + 1;
236 int measuresPhi = ((m_address & 0x00000100) >> 8);
237 int strip = (m_address & 0x000000FF) + 1;
238 Identifier id = m_cscHelper->channelID(moduleId, chamberLayer, wireLayer, measuresPhi, strip);
239 IdContext context = m_cscHelper->channel_context();
240 IdentifierHash hash;
241 m_cscHelper->get_hash(id, hash, &context);
242 return (uint32_t)hash;
243}
244
245inline uint32_t CscRODReadOutV1::numberOfStrips(const uint32_t fragment) {
246 decodeAddress(fragment);
247 Identifier moduleId = decodeAddress();
248 Identifier channelId = decodeAddress(moduleId);
249 return uint32_t(m_cscHelper->stripMax(channelId));
250}
251
252// get the signal amplitude for a given sampling time (ns)
253inline double CscRODReadOutV1::signal_amplitude(double samplingTime) const {
254 if (samplingTime <= m_TIME_OFFSET) return 0.0;
255 double z = (samplingTime - m_TIME_OFFSET) / m_SIGNAL_WIDTH;
256 return signal(z) / m_norm;
257}
258
259// signal amplitude as a function of the time bin z
260inline double CscRODReadOutV1::signal(double z) const {
261 double amplitude = (1.0 - z / (1 + m_NUMBER_OF_INTEGRATION)) * std::pow(z, m_NUMBER_OF_INTEGRATION) * exp(-z);
262 return amplitude;
263}
264
265// find the address of this strip
266inline uint32_t CscRODReadOutV1::address(const Identifier& channelId, int& eta, int& phi) const {
267 // unpack the strip identifier
268 int name = m_cscHelper->stationName(channelId);
269 eta = m_cscHelper->stationEta(channelId);
270 phi = m_cscHelper->stationPhi(channelId);
271 int chamberLayer = m_cscHelper->chamberLayer(channelId);
272 int wireLayer = m_cscHelper->wireLayer(channelId);
273 int orientation = m_cscHelper->measuresPhi(channelId);
274 int strip = m_cscHelper->strip(channelId);
275
276 // redefine the ranges
277 uint32_t nameIndex = uint32_t(name - 50);
278 uint32_t etaIndex = (eta == -1) ? 0 : 1;
279 uint32_t phiIndex = uint32_t(phi - 1);
280 uint32_t chamberIndex = uint32_t(chamberLayer - 0);
281 uint32_t layerIndex = uint32_t(wireLayer - 1);
282 uint32_t stripType = uint32_t(orientation);
283 uint32_t stripNumber = uint32_t(strip - 1);
284
285 // build the address
286 uint32_t address =
287 nameIndex << 16 | phiIndex << 13 | etaIndex << 12 | chamberIndex << 11 | layerIndex << 9 | stripType << 8 | stripNumber;
288
289 return address;
290}
291
292#endif // MUONCSC_CNVTOOL_CSCRODREADOUTV1_H
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define z
uint32_t m_TRIGGER_INFO[3]
double signal_amplitude(double samplingTime) const
uint32_t getHeaderSize()
void setAddress(const uint32_t address)
int findCharge(const std::vector< uint16_t > &amplitude, double &time)
bool isAmplitude(const uint16_t fragment) const
double getSamplingTime()
static const uint32_t DPU_HEADER_MARKER
uint32_t numSamples()
uint32_t samplingRate()
void triggerInfo(uint32_t *trigger)
static const uint32_t RATE
uint32_t getSourceID(uint16_t side, uint16_t rodId)
uint16_t subDetectorId() const
void encodeFragments(const std::vector< uint16_t > &amplitude, std::vector< uint32_t > &v) const
bool discard(const uint32_t fragment) const
uint32_t address() const
uint32_t numberOfStrips(const uint32_t fragment)
void decodeAmplitude(const uint32_t fragment)
static const uint32_t NUM_DPU
MHz.
uint32_t getFooterSize()
uint16_t sourceID() const
uint32_t hashIdentifier(const Identifier &moduleId)
void set(const CscIdHelper *cscHelper)
static const uint32_t ROD_FOOTER_SIZE
uint32_t address(const Identifier &channelId, int &eta, int &phi) const
uint32_t dpuHeader()
double signal(double z) const
static const uint32_t LATENCY
static const uint16_t SOURCE_ID
bool isAddress(const uint32_t fragment) const
bool isDPU(const uint32_t fragment) const
static const uint16_t BODY_AMPLITUDE
uint16_t m_subDetectorId
uint16_t getAmp1() const
static const uint32_t ROD_HEADER_SIZE
static const uint32_t DPU_HEADER_SIZE
static const uint32_t DPU_DISCARD
Identifier decodeAddress()
uint32_t dpuHeaderSize()
uint16_t rodId() const
static const uint32_t NUM_SAMPLES
void decodeSourceID(uint32_t sourceId)
void set32bits(const uint16_t *v16, uint32_t &v32) const
static const uint32_t BODY_ADDRESS
uint16_t moduleType() const
~CscRODReadOutV1()=default
static const uint16_t MODULE_TYPE
void setParams(double timeOffset, double samplingTime, double signalWidth)
uint16_t getAmp2() const
void setSamplingTime(double time)
const CscIdHelper * m_cscHelper
This class saves the "context" of an expanded identifier (ExpandedIdentifier) for compact or hash ver...
Definition IdContext.h:26
This is a "hash" representation of an Identifier.