CMS 3D CMS Logo

RegionalMuonRawDigiTranslator.cc
Go to the documentation of this file.
3 
5  const uint32_t raw_data_00_31,
6  const uint32_t raw_data_32_63,
7  const int proc,
8  const tftype tf,
9  const bool isKbmtf,
10  const bool useEmtfDisplacementInfo) {
11  // translations as defined in DN-15-017
12  mu.setHwPt((raw_data_00_31 >> ptShift_) & ptMask_);
13  mu.setHwQual((raw_data_00_31 >> qualShift_) & qualMask_);
14 
15  // eta is coded as two's complement
16  int abs_eta = (raw_data_00_31 >> absEtaShift_) & absEtaMask_;
17  if ((raw_data_00_31 >> etaSignShift_) & 0x1) {
18  mu.setHwEta(abs_eta - (1 << (etaSignShift_ - absEtaShift_)));
19  } else {
20  mu.setHwEta(abs_eta);
21  }
22 
23  // phi is coded as two's complement
24  int abs_phi = (raw_data_00_31 >> absPhiShift_) & absPhiMask_;
25  if ((raw_data_00_31 >> phiSignShift_) & 0x1) {
26  mu.setHwPhi(abs_phi - (1 << (phiSignShift_ - absPhiShift_)));
27  } else {
28  mu.setHwPhi(abs_phi);
29  }
30 
31  // sign is coded as -1^signBit
32  mu.setHwSign((raw_data_32_63 >> signShift_) & 0x1);
33  mu.setHwSignValid((raw_data_32_63 >> signValidShift_) & 0x1);
34  mu.setHwHF((raw_data_00_31 >> hfShift_) & hfMask_);
35 
36  // set track address with subaddresses
37  int rawTrackAddress = (raw_data_32_63 >> trackAddressShift_) & trackAddressMask_;
38  if (tf == bmtf) {
39  int detSide = (rawTrackAddress >> bmtfTrAddrDetSideShift_) & 0x1;
40  int wheelNum = (rawTrackAddress >> bmtfTrAddrWheelShift_) & bmtfTrAddrWheelMask_;
41  int statAddr1 = ((rawTrackAddress >> bmtfTrAddrStat1Shift_) & bmtfTrAddrStat1Mask_);
42  int statAddr2 = ((rawTrackAddress >> bmtfTrAddrStat2Shift_) & bmtfTrAddrStat2Mask_);
43  int statAddr3 = ((rawTrackAddress >> bmtfTrAddrStat3Shift_) & bmtfTrAddrStat3Mask_);
44  int statAddr4 = ((rawTrackAddress >> bmtfTrAddrStat4Shift_) & bmtfTrAddrStat4Mask_);
45 
46  mu.setTrackSubAddress(RegionalMuonCand::kWheelSide, detSide);
47  mu.setTrackSubAddress(RegionalMuonCand::kWheelNum, wheelNum);
48  if (!isKbmtf) { // The Run-2 standard configuration for BMTF
49  mu.setTrackSubAddress(RegionalMuonCand::kStat1, statAddr1);
50  mu.setTrackSubAddress(RegionalMuonCand::kStat2, statAddr2);
51  mu.setTrackSubAddress(RegionalMuonCand::kStat3, statAddr3);
52  mu.setTrackSubAddress(RegionalMuonCand::kStat4, statAddr4);
53  } else {
54  // For Run-3 track address encoding has changed as the Kalman Filter tracks from outside in.
55  // As a result station assignment is inverted
56  // (i.e. the field that contained the station 1 information for Run-2 now contains station 4 information and so on.)
57  mu.setTrackSubAddress(RegionalMuonCand::kStat1, statAddr4);
58  mu.setTrackSubAddress(RegionalMuonCand::kStat2, statAddr3);
59  mu.setTrackSubAddress(RegionalMuonCand::kStat3, statAddr2);
60  mu.setTrackSubAddress(RegionalMuonCand::kStat4, statAddr1);
61  // Additionally we now have displacement information from the BMTF
62  mu.setHwPtUnconstrained((raw_data_32_63 >> bmtfPtUnconstrainedShift_) & ptUnconstrainedMask_);
63  mu.setHwDXY((raw_data_32_63 >> bmtfDxyShift_) & dxyMask_);
64  }
65  mu.setTrackSubAddress(RegionalMuonCand::kSegSelStat1, 0);
66  mu.setTrackSubAddress(RegionalMuonCand::kSegSelStat2, 0);
67  mu.setTrackSubAddress(RegionalMuonCand::kSegSelStat3, 0);
68  mu.setTrackSubAddress(RegionalMuonCand::kSegSelStat4, 0);
69  //mu.setTrackSubAddress(RegionalMuonCand::kNumBmtfSubAddr, 0);
70  } else if (tf == emtf_neg || tf == emtf_pos) {
71  mu.setTrackSubAddress(RegionalMuonCand::kME1Seg, (rawTrackAddress >> emtfTrAddrMe1SegShift_) & 0x1);
72  mu.setTrackSubAddress(RegionalMuonCand::kME1Ch, (rawTrackAddress >> emtfTrAddrMe1ChShift_) & emtfTrAddrMe1ChMask_);
73  mu.setTrackSubAddress(RegionalMuonCand::kME2Seg, (rawTrackAddress >> emtfTrAddrMe2SegShift_) & 0x1);
74  mu.setTrackSubAddress(RegionalMuonCand::kME2Ch, (rawTrackAddress >> emtfTrAddrMe2ChShift_) & emtfTrAddrMe2ChMask_);
75  mu.setTrackSubAddress(RegionalMuonCand::kME3Seg, (rawTrackAddress >> emtfTrAddrMe3SegShift_) & 0x1);
76  mu.setTrackSubAddress(RegionalMuonCand::kME3Ch, (rawTrackAddress >> emtfTrAddrMe3ChShift_) & emtfTrAddrMe3ChMask_);
77  mu.setTrackSubAddress(RegionalMuonCand::kME4Seg, (rawTrackAddress >> emtfTrAddrMe4SegShift_) & 0x1);
78  mu.setTrackSubAddress(RegionalMuonCand::kME4Ch, (rawTrackAddress >> emtfTrAddrMe4ChShift_) & emtfTrAddrMe4ChMask_);
79  if (useEmtfDisplacementInfo) { // In Run-3 we receive displaced muon information from EMTF
80  mu.setHwPtUnconstrained((raw_data_32_63 >> emtfPtUnconstrainedShift_) & ptUnconstrainedMask_);
81  mu.setHwDXY((raw_data_32_63 >> emtfDxyShift_) & dxyMask_);
82  mu.setTrackSubAddress(RegionalMuonCand::kTrkNum, 0);
83  mu.setTrackSubAddress(RegionalMuonCand::kBX, 0);
84  } else {
85  mu.setTrackSubAddress(RegionalMuonCand::kTrkNum,
86  (rawTrackAddress >> emtfTrAddrTrkNumShift_) & emtfTrAddrTrkNumMask_);
87  mu.setTrackSubAddress(RegionalMuonCand::kBX, (rawTrackAddress >> emtfTrAddrBxShift_) & emtfTrAddrBxMask_);
88  }
89  } else if (tf == omtf_neg || tf == omtf_pos) {
90  mu.setTrackSubAddress(RegionalMuonCand::kLayers,
91  (rawTrackAddress >> omtfTrAddrLayersShift_) & omtfTrAddrLayersMask_);
92  mu.setTrackSubAddress(RegionalMuonCand::kZero, 0);
93  mu.setTrackSubAddress(RegionalMuonCand::kWeight,
94  (rawTrackAddress >> omtfTrAddrWeightShift_) & omtfTrAddrWeightMask_);
95  } else {
96  std::map<int, int> trackAddr;
97  trackAddr[0] = rawTrackAddress;
98  mu.setTrackAddress(trackAddr);
99  }
100 
101  mu.setTFIdentifiers(proc, tf);
102  mu.setDataword(raw_data_32_63, raw_data_00_31);
103 }
104 
106  const uint64_t dataword,
107  const int proc,
108  const tftype tf,
109  const bool isKbmtf,
110  const bool useEmtfDisplacementInfo) {
111  fillRegionalMuonCand(mu,
112  (uint32_t)(dataword & 0xFFFFFFFF),
113  (uint32_t)((dataword >> 32) & 0xFFFFFFFF),
114  proc,
115  tf,
116  isKbmtf,
117  useEmtfDisplacementInfo);
118 }
119 
121  const std::vector<uint32_t> bxPayload,
122  const int proc,
123  const tftype tf,
124  const bool useEmtfNominalTightShowers,
125  const bool useEmtfLooseShowers) {
126  muShower.setTFIdentifiers(proc, tf);
127  bool showerValid{false};
128  if (useEmtfNominalTightShowers && (tf == emtf_pos || tf == emtf_neg)) {
129  muShower.setOneNominalInTime(((bxPayload[kEmtfShowerStandardFrame] >> kEmtfShowerOneNominalShift) & 1) == 1);
130  muShower.setOneTightInTime(((bxPayload[kEmtfShowerStandardFrame] >> kEmtfShowerOneTightShift) & 1) == 1);
131 
132  showerValid = muShower.isValid();
133  }
134  if (useEmtfLooseShowers && (tf == emtf_pos || tf == emtf_neg)) {
135  muShower.setOneLooseInTime(((bxPayload[kEmtfShowerExtendedFrame] >> kEmtfShowerOneLooseShift) & 1) == 1);
136 
137  showerValid = muShower.isValid();
138  }
139  return showerValid;
140 }
141 
143  std::array<uint32_t, 6>& payload,
144  const bool useEmtfNominalTightShowers,
145  const bool useEmtfLooseShowers) {
146  if (!useEmtfNominalTightShowers || !useEmtfLooseShowers || !shower.isValid()) {
147  return;
148  }
149  // First we check whether we're going to overwrite something in the payload.
150  if ((((payload.at(kEmtfShowerStandardFrame) >> kEmtfShowerOneNominalShift) & kEmtfShowerMask) != 0) ||
151  (((payload.at(kEmtfShowerStandardFrame) >> kEmtfShowerOneTightShift) & kEmtfShowerMask) != 0) ||
152  (((payload.at(kEmtfShowerExtendedFrame) >> kEmtfShowerOneLooseShift) & kEmtfShowerMask) != 0)) {
153  edm::LogError("L1T") << "Check constants for RegionalMuonShower fields! It looks like we're in danger of "
154  "overwriting muon data in the packer! StandardFrame is "
155  << payload.at(kEmtfShowerStandardFrame) << ", ExtendedFrame is "
156  << payload.at(kEmtfShowerExtendedFrame);
157  return;
158  }
159  payload.at(kEmtfShowerStandardFrame) |= (shower.isOneNominalInTime() & 1) << kEmtfShowerOneNominalShift |
160  (shower.isOneTightInTime() & 1) << kEmtfShowerOneTightShift;
161  payload.at(kEmtfShowerExtendedFrame) |= (shower.isOneNominalOutOfTime() & 1) << kEmtfShowerOneNominalShift |
162  (shower.isOneTightOutOfTime() & 1) << kEmtfShowerOneTightShift;
163 }
164 
166  uint32_t& raw_data_00_31,
167  uint32_t& raw_data_32_63,
168  const bool isKbmtf,
169  const bool useEmtfDisplacementInfo) {
170  int abs_eta = mu.hwEta();
171  if (abs_eta < 0) {
172  abs_eta += (1 << (etaSignShift_ - absEtaShift_));
173  }
174  int abs_phi = mu.hwPhi();
175  if (abs_phi < 0) {
176  abs_phi += (1 << (phiSignShift_ - absPhiShift_));
177  }
178  raw_data_00_31 = (mu.hwPt() & ptMask_) << ptShift_ | (mu.hwQual() & qualMask_) << qualShift_ |
179  (abs_eta & absEtaMask_) << absEtaShift_ | (mu.hwEta() < 0) << etaSignShift_ |
180  (mu.hwHF() & hfMask_) << hfShift_ | (abs_phi & absPhiMask_) << absPhiShift_ |
181  (mu.hwPhi() < 0) << phiSignShift_;
182 
183  // generate the raw track address from the subaddresses
184  int rawTrkAddr = generateRawTrkAddress(mu, isKbmtf);
185 
186  raw_data_32_63 = mu.hwSign() << signShift_ | mu.hwSignValid() << signValidShift_ |
187  (rawTrkAddr & trackAddressMask_) << trackAddressShift_;
188  if (isKbmtf && mu.trackFinderType() == bmtf) {
189  raw_data_32_63 |= (mu.hwPtUnconstrained() & ptUnconstrainedMask_) << bmtfPtUnconstrainedShift_ |
190  (mu.hwDXY() & dxyMask_) << bmtfDxyShift_;
191  } else if (useEmtfDisplacementInfo && (mu.trackFinderType() == emtf_pos || mu.trackFinderType() == emtf_neg)) {
192  raw_data_32_63 |= (mu.hwPtUnconstrained() & ptUnconstrainedMask_) << emtfPtUnconstrainedShift_ |
193  (mu.hwDXY() & dxyMask_) << emtfDxyShift_;
194  }
195 }
196 
198  const bool isKbmtf,
199  const bool useEmtfDisplacementInfo) {
200  uint32_t lsw;
201  uint32_t msw;
202 
203  generatePackedDataWords(mu, lsw, msw, isKbmtf, useEmtfDisplacementInfo);
204  return (((uint64_t)msw) << 32) + lsw;
205 }
206 
208  int tf = mu.trackFinderType();
209  int rawTrkAddr = 0;
210  if (tf == bmtf) {
211  // protection against a track address map with the wrong size
212  if (mu.trackAddress().size() == RegionalMuonCand::kNumBmtfSubAddr) {
213  int detSide = mu.trackSubAddress(RegionalMuonCand::kWheelSide);
214  int wheelNum = mu.trackSubAddress(RegionalMuonCand::kWheelNum);
215  int stat1 = mu.trackSubAddress(RegionalMuonCand::kStat1);
216  int stat2 = mu.trackSubAddress(RegionalMuonCand::kStat2);
217  int stat3 = mu.trackSubAddress(RegionalMuonCand::kStat3);
218  int stat4 = mu.trackSubAddress(RegionalMuonCand::kStat4);
219  if (isKalman) {
220  stat1 = mu.trackSubAddress(RegionalMuonCand::kStat4);
221  stat2 = mu.trackSubAddress(RegionalMuonCand::kStat3);
222  stat3 = mu.trackSubAddress(RegionalMuonCand::kStat2);
223  stat4 = mu.trackSubAddress(RegionalMuonCand::kStat1);
224  }
225 
226  rawTrkAddr = (detSide & 0x1) << bmtfTrAddrDetSideShift_ |
227  (wheelNum & bmtfTrAddrWheelMask_) << bmtfTrAddrWheelShift_ |
228  (stat1 & bmtfTrAddrStat1Mask_) << bmtfTrAddrStat1Shift_ |
229  (stat2 & bmtfTrAddrStat2Mask_) << bmtfTrAddrStat2Shift_ |
230  (stat3 & bmtfTrAddrStat3Mask_) << bmtfTrAddrStat3Shift_ |
231  (stat4 & bmtfTrAddrStat4Mask_) << bmtfTrAddrStat4Shift_;
232  } else {
233  edm::LogWarning("L1T") << "BMTF muon track address map contains " << mu.trackAddress().size()
234  << " instead of the expected " << RegionalMuonCand::kNumBmtfSubAddr
235  << " subaddresses. Check the data format. Setting track address to 0.";
236  rawTrkAddr = 0;
237  }
238  } else if (tf == emtf_neg || tf == emtf_pos) {
239  // protection against a track address map with the wrong size
240  if (mu.trackAddress().size() == RegionalMuonCand::kNumEmtfSubAddr) {
241  rawTrkAddr = (mu.trackSubAddress(RegionalMuonCand::kME1Seg) & 0x1) << emtfTrAddrMe1SegShift_ |
242  (mu.trackSubAddress(RegionalMuonCand::kME1Ch) & emtfTrAddrMe1ChMask_) << emtfTrAddrMe1ChShift_ |
243  (mu.trackSubAddress(RegionalMuonCand::kME2Seg) & 0x1) << emtfTrAddrMe2SegShift_ |
244  (mu.trackSubAddress(RegionalMuonCand::kME2Ch) & emtfTrAddrMe2ChMask_) << emtfTrAddrMe2ChShift_ |
245  (mu.trackSubAddress(RegionalMuonCand::kME3Seg) & 0x1) << emtfTrAddrMe3SegShift_ |
246  (mu.trackSubAddress(RegionalMuonCand::kME3Ch) & emtfTrAddrMe3ChMask_) << emtfTrAddrMe3ChShift_ |
247  (mu.trackSubAddress(RegionalMuonCand::kME4Seg) & 0x1) << emtfTrAddrMe4SegShift_ |
248  (mu.trackSubAddress(RegionalMuonCand::kME4Ch) & emtfTrAddrMe4ChMask_) << emtfTrAddrMe4ChShift_;
249 
250  } else {
251  edm::LogWarning("L1T") << "EMTF muon track address map contains " << mu.trackAddress().size()
252  << " instead of the expected " << RegionalMuonCand::kNumEmtfSubAddr
253  << " subaddresses. Check the data format. Setting track address to 0.";
254  rawTrkAddr = 0;
255  }
256  } else if (tf == omtf_neg || tf == omtf_pos) {
257  // protection against a track address map with the wrong size
258  if (mu.trackAddress().size() == RegionalMuonCand::kNumOmtfSubAddr) {
259  rawTrkAddr = (mu.trackSubAddress(RegionalMuonCand::kLayers) & omtfTrAddrLayersMask_) << omtfTrAddrLayersShift_ |
260  (mu.trackSubAddress(RegionalMuonCand::kWeight) & omtfTrAddrWeightMask_) << omtfTrAddrWeightShift_;
261 
262  } else {
263  edm::LogWarning("L1T") << "OMTF muon track address map contains " << mu.trackAddress().size()
264  << " instead of the expected " << RegionalMuonCand::kNumOmtfSubAddr
265  << " subaddresses. Check the data format. Setting track address to 0.";
266  rawTrkAddr = 0;
267  }
268  } else {
269  rawTrkAddr = mu.trackAddress().at(0);
270  }
271 
272  return rawTrkAddr;
273 }
void setOneTightInTime(const bool bit)
void setOneLooseInTime(const bool bit)
Log< level::Error, false > LogError
static void generatePackedShowerPayload(const RegionalMuonShower &shower, std::array< uint32_t, 6 > &payload, bool useEmtfNominalTightShowers, bool useEmtfLooseShowers)
static void generatePackedDataWords(const RegionalMuonCand &mu, uint32_t &raw_data_00_31, uint32_t &raw_data_32_63, bool isKbmtf, bool useEmtfDisplacementInfo)
static bool fillRegionalMuonShower(RegionalMuonShower &muShower, std::vector< uint32_t > bxPayload, int proc, tftype tf, bool useEmtfNominalTightShowers, bool useEmtfLooseShowers)
void setOneNominalInTime(const bool bit)
unsigned long long uint64_t
Definition: Time.h:13
static int generateRawTrkAddress(const RegionalMuonCand &, bool isKalman)
bool isOneNominalOutOfTime() const
void setTFIdentifiers(int processor, tftype trackFinder)
Set the processor ID, track-finder type. From these two, the link is set.
static uint64_t generate64bitDataWord(const RegionalMuonCand &mu, bool isKbmtf, bool useEmtfDisplacementInfo)
Log< level::Warning, false > LogWarning
static void fillRegionalMuonCand(RegionalMuonCand &mu, uint32_t raw_data_00_31, uint32_t raw_data_32_63, int proc, tftype tf, bool isKbmtf, bool useEmtfDisplacementInfo)