ATLAS Offline Software
Loading...
Searching...
No Matches
CscRODReadOutV0.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef MUONCSC_CNVTOOL_CSCRODREADOUTV0_H
6#define MUONCSC_CNVTOOL_CSCRODREADOUTV0_H
7
8#include <stdint.h>
9
10#include <cmath>
11#include <vector>
12
14
15// CSC ROD encoder/decoder for CscRDO
16// Author Ketevi A. Assamagan
17// BNL December 27 2003
18
20public:
22 ~CscRODReadOutV0() = default;
23
24 // get static head/footer information
25 uint32_t getHeaderMarker() { return ROD_HEADER; }
26 uint32_t getHeaderSize() { return ROD_HEADER_SIZE; }
27 uint32_t getFooterSize() { return ROD_FOOTER_SIZE; }
28 uint32_t getFormatVersion() { return ROD_VERSION; }
29 double getSamplingTime() { return m_SAMPLING_TIME; }
30 double getStartTime() { return m_TIME_OFFSET; }
32 double getMaxTimeBin() { return m_Z0; }
33
34 // encoding
35 uint32_t getSourceID(uint16_t side, uint16_t rodId);
36 void encodeFragments(const uint16_t* amplitude, const uint32_t& address, std::vector<uint32_t>& v) const;
37
38 // initialize helper
39 void set(const CscIdHelper* cscHelper) { m_cscHelper = cscHelper; }
40
41 // testing
42 bool isBody(const uint32_t fragment) const;
43 bool isAmplitude(const uint16_t fragment) const;
44 bool isAddress(const uint32_t fragment) const;
45
46 // Decoding
47 void decodeSourceID(uint32_t sourceId);
48 void decodeAmplitude(const uint32_t fragment, int index);
49 void decodeAddress(const uint32_t fragment);
51 Identifier decodeAddress(const Identifier& moduleId);
52 double findCharge();
53 double signal_amplitude(double samplingTime) const;
54 uint32_t address(const Identifier& channelId, int& eta, int& phi) const;
55
56 // Retrieve decoded results
57 uint16_t sourceID() const { return m_sourceID; }
58 uint16_t moduleType() const { return m_moduleType; }
59 uint16_t subDetectorId() const { return m_subDetectorId; }
60 uint16_t rodId() const { return m_rodId; }
61 uint16_t getAmp1() const { return m_amp1; }
62 uint16_t getAmp2() const { return m_amp2; }
63 uint16_t getAmp3() const { return m_amp3; }
64 uint16_t getAmp4() const { return m_amp4; }
65 uint32_t address() const { return m_address; }
66
67private:
69 uint16_t m_sourceID;
70 uint16_t m_moduleType;
71 uint16_t m_rodId;
73 uint16_t m_amp1;
74 uint16_t m_amp2;
75 uint16_t m_amp3;
76 uint16_t m_amp4;
77 uint32_t m_address;
78 double m_norm;
79
85 double m_Z0;
86
87 static const uint32_t ROD_HEADER = 0xEE1234EE;
88 static const uint32_t ROD_HEADER_SIZE = 0x8;
89 static const uint32_t ROD_VERSION = 0x00000000;
90 static const uint32_t ROD_FOOTER_SIZE = 0x3;
91
92 static const uint16_t SOURCE_ID = 0x00;
93 static const uint16_t MODULE_TYPE = 0x00;
94
95 static const uint16_t BODY_AMPLITUDE = 0x000A;
96 static const uint32_t BODY_ADDRESS = 0x0000000C;
97
98 void set32bits(const uint16_t* v16, uint32_t& v32) const;
99 double signal(double z) const;
100};
101
102inline uint32_t CscRODReadOutV0::getSourceID(uint16_t side, uint16_t rodId) {
103 uint32_t sourceIdentifier = 0;
104 sourceIdentifier = SOURCE_ID << 24 | MODULE_TYPE << 16 | side << 8 | rodId;
105 return sourceIdentifier;
106}
107
109 m_sourceID = (sourceID & 0xff000000) >> 24;
110 m_moduleType = (sourceID & 0x00ff0000) >> 16;
111 m_subDetectorId = (sourceID & 0x0000ff00) >> 8;
112 m_rodId = (sourceID & 0x000000ff);
113}
114
115inline void CscRODReadOutV0::set32bits(const uint16_t* v16, uint32_t& v32) const {
116 uint32_t p = 0, v = 0;
117 uint16_t n = 2;
118 uint16_t pos[] = {0, 16};
119 for (uint16_t i = 0; i < n; i++) {
120 v = (uint32_t)(*(v16 + i));
121 p = (uint32_t)(*(pos + i));
122 v32 = v32 | (v << p);
123 }
124}
125
126inline bool CscRODReadOutV0::isBody(const uint32_t fragment) const { return (0x80000000 & fragment); }
127
128inline bool CscRODReadOutV0::isAmplitude(const uint16_t fragment) const { return (0xA000 & fragment); }
129
130inline bool CscRODReadOutV0::isAddress(const uint32_t fragment) const { return (0xC0000000 & fragment); }
131
132inline void CscRODReadOutV0::decodeAmplitude(const uint32_t fragment, int index) {
133 uint32_t amp1 = 0;
134 uint32_t amp2 = 0;
135 amp1 = 0x0000FFFF & fragment;
136 amp2 = (0xFFFF0000 & fragment) >> 16;
137 if (index == 1) {
138 m_amp1 = 0x0FFF & amp1;
139 m_amp2 = 0x0FFF & amp2;
140 } else {
141 m_amp3 = 0x0FFF & amp1;
142 m_amp4 = 0x0FFF & amp2;
143 }
144}
145
146inline void CscRODReadOutV0::decodeAddress(const uint32_t fragment) { m_address = 0x0003FFFF & fragment; }
147
149 int stationName = ((m_address & 0x00020000) >> 17) + 50;
150 int stationEta = (((m_address & 0x00010000) >> 16) == 0x0) ? -1 : 1;
151 int stationPhi = ((m_address & 0x0000E000) >> 13) + 1;
152
153 return m_cscHelper->elementID(stationName, stationEta, stationPhi);
154}
155
157 int chamberLayer = ((m_address & 0x00001000) >> 12) + 1;
158 int wireLayer = ((m_address & 0x00000E00) >> 9) + 1;
159 int measuresPhi = ((m_address & 0x00000100) >> 8);
160 int strip = (m_address & 0x000000FF);
161 return m_cscHelper->channelID(moduleId, chamberLayer, wireLayer, measuresPhi, strip);
162}
163
164// get the signal amplitude for a given sampling time (ns)
165inline double CscRODReadOutV0::signal_amplitude(double samplingTime) const {
166 if (samplingTime <= m_TIME_OFFSET) return 0.0;
167 double z = (samplingTime - m_TIME_OFFSET) / m_SIGNAL_WIDTH;
168 return signal(z) / m_norm;
169}
170
171// signal amplitude as a function of the time bin z
172inline double CscRODReadOutV0::signal(double z) const {
173 double amplitude = (1.0 - z / (1 + m_NUMBER_OF_INTEGRATION)) * std::pow(z, m_NUMBER_OF_INTEGRATION) * exp(-z);
174 return amplitude;
175}
176
177// find the address of this strip
178inline uint32_t CscRODReadOutV0::address(const Identifier& channelId, int& eta, int& phi) const {
179 // unpack the strip identifier
180 int name = m_cscHelper->stationName(channelId);
181 eta = m_cscHelper->stationEta(channelId);
182 phi = m_cscHelper->stationPhi(channelId);
183 int chamberLayer = m_cscHelper->chamberLayer(channelId);
184 int wireLayer = m_cscHelper->wireLayer(channelId);
185 int orientation = m_cscHelper->measuresPhi(channelId);
186 int strip = m_cscHelper->strip(channelId);
187
188 // redefine the ranges
189 uint32_t nameIndex = uint32_t(name - 50);
190 uint32_t etaIndex = (eta == -1) ? 0 : 1;
191 uint32_t phiIndex = uint32_t(phi - 1);
192 uint32_t chamberIndex = uint32_t(chamberLayer - 1);
193 uint32_t layerIndex = uint32_t(wireLayer - 1);
194 uint32_t stripType = uint32_t(orientation);
195 uint32_t stripNumber = uint32_t(strip);
196
197 // build the address
198 uint32_t address =
199 nameIndex << 17 | etaIndex << 16 | phiIndex << 13 | chamberIndex << 12 | layerIndex << 9 | stripType << 8 | stripNumber;
200
201 return address;
202}
203
204#endif // MUONCSC_CNVTOOL_CSCRODREADOUTV0_H
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define z
void decodeAmplitude(const uint32_t fragment, int index)
uint16_t sourceID() const
static const uint32_t ROD_VERSION
uint16_t subDetectorId() const
static const uint16_t BODY_AMPLITUDE
uint16_t rodId() const
uint16_t getAmp1() const
uint16_t getAmp2() const
void encodeFragments(const uint16_t *amplitude, const uint32_t &address, std::vector< uint32_t > &v) const
static const uint32_t ROD_FOOTER_SIZE
uint32_t getHeaderMarker()
static const uint32_t BODY_ADDRESS
double signal(double z) const
static const uint32_t ROD_HEADER_SIZE
double signal_amplitude(double samplingTime) const
uint32_t getHeaderSize()
bool isBody(const uint32_t fragment) const
static const uint16_t SOURCE_ID
uint16_t m_subDetectorId
Identifier decodeAddress()
uint32_t getFormatVersion()
bool isAddress(const uint32_t fragment) const
uint16_t getAmp4() const
uint16_t moduleType() const
uint32_t address(const Identifier &channelId, int &eta, int &phi) const
void set(const CscIdHelper *cscHelper)
uint32_t getFooterSize()
void decodeSourceID(uint32_t sourceId)
const CscIdHelper * m_cscHelper
static const uint32_t ROD_HEADER
~CscRODReadOutV0()=default
uint16_t getAmp3() const
static const uint16_t MODULE_TYPE
void set32bits(const uint16_t *v16, uint32_t &v32) const
uint32_t getSourceID(uint16_t side, uint16_t rodId)
bool isAmplitude(const uint16_t fragment) const
uint32_t address() const
double getSamplingTime()
double m_CHARGE_TO_ADC_COUNT
Definition index.py:1