CMS 3D CMS Logo

MuonRawDigiTranslator.cc
Go to the documentation of this file.
1 #include "TMath.h"
3 
5  Muon& mu, uint32_t raw_data_00_31, uint32_t raw_data_32_63, int fed, unsigned int fw) {
6  int hwPt = (raw_data_00_31 >> ptShift_) & ptMask_;
7  if (hwPt > 0) {
8  mu.setHwPt(hwPt);
9  mu.setHwQual((raw_data_00_31 >> qualShift_) & qualMask_);
10  mu.setHwIso((raw_data_32_63 >> isoShift_) & isoMask_);
11  // charge is coded as -1^chargeBit
12  mu.setHwCharge((raw_data_32_63 >> chargeShift_) & 0x1);
13  mu.setHwChargeValid((raw_data_32_63 >> chargeValidShift_) & 0x1);
14  mu.setTfMuonIndex((raw_data_32_63 >> tfMuonIndexShift_) & tfMuonIndexMask_);
15 
16  // The position of the eta and phi coordinates in the RAW data changed between the 2016 run and the 2017 run.
17  // Eta and phi at the muon system are replaced by eta and phi at the vertex
18  // Eta and phi at the muon system are moved to spare bits
19  // The uGMT (FED 1402) or uGT (FED 1404) FW versions are used to determine the era.
20  if ((fed == 1402 && fw < 0x4010000) || (fed == 1404 && fw < 0x10A6)) {
21  // coordinates at the muon system are in 2016 where in 2017 eta and phi at the vertex are
23  mu.setHwPhi((raw_data_00_31 >> phiAtVtxShift_) & phiMask_);
24 
25  // set the coordiantes at vertex to be the same as the coordinates at the muon system
26  mu.setHwEtaAtVtx(mu.hwEta());
27  mu.setHwPhiAtVtx(mu.hwPhi());
28  // deltas are 0
29  mu.setHwDEtaExtra(0);
30  mu.setHwDPhiExtra(0);
31  } else {
32  // coordinates at the muon system
33  mu.setHwEta(calcHwEta(raw_data_32_63, absEtaShift_, etaSignShift_));
34  mu.setHwPhi((raw_data_32_63 >> phiShift_) & phiMask_);
35 
36  // coordinates at the vertex
38  mu.setHwPhiAtVtx((raw_data_00_31 >> phiAtVtxShift_) & phiMask_);
39  // deltas
40  mu.setHwDEtaExtra(mu.hwEtaAtVtx() - mu.hwEta());
41  int dPhi = mu.hwPhiAtVtx() - mu.hwPhi();
42  if (mu.hwCharge() == 1 && dPhi > 0) {
43  dPhi -= 576;
44  } else if (mu.hwCharge() == 0 && dPhi < 0) {
45  dPhi += 576;
46  }
47  mu.setHwDPhiExtra(dPhi);
48  }
49 
50  math::PtEtaPhiMLorentzVector vec{(mu.hwPt() - 1) * 0.5, mu.hwEta() * 0.010875, mu.hwPhi() * 0.010908, 0.0};
51  mu.setP4(vec);
52  // generate a muon at the vertex to extract the physical eta and phi coordinates
54  (mu.hwPt() - 1) * 0.5, mu.hwEtaAtVtx() * 0.010875, mu.hwPhiAtVtx() * 0.010908, 0.0};
55  Muon muAtVtx;
56  muAtVtx.setP4(vecAtVtx);
57  mu.setEtaAtVtx(muAtVtx.eta());
58  mu.setPhiAtVtx(muAtVtx.phi());
59  if (mu.hwChargeValid()) {
60  mu.setCharge(1 - 2 * mu.hwCharge());
61  } else {
62  mu.setCharge(0);
63  }
64  }
65 }
66 
67 void l1t::MuonRawDigiTranslator::fillMuon(Muon& mu, uint64_t dataword, int fed, unsigned int fw) {
68  fillMuon(mu, (uint32_t)(dataword & 0xFFFFFFFF), (uint32_t)((dataword >> 32) & 0xFFFFFFFF), fed, fw);
69 }
70 
72  uint32_t& raw_data_00_31,
73  uint32_t& raw_data_32_63) {
74  int abs_eta = mu.hwEta();
75  if (abs_eta < 0) {
76  abs_eta += (1 << (etaSignShift_ - absEtaShift_));
77  }
78  int abs_eta_at_vtx = mu.hwEtaAtVtx();
79  if (abs_eta_at_vtx < 0) {
80  abs_eta_at_vtx += (1 << (etaAtVtxSignShift_ - absEtaAtVtxShift_));
81  }
82  raw_data_00_31 = (mu.hwPt() & ptMask_) << ptShift_ | (mu.hwQual() & qualMask_) << qualShift_ |
83  (abs_eta_at_vtx & absEtaMask_) << absEtaAtVtxShift_ | (mu.hwEtaAtVtx() < 0) << etaAtVtxSignShift_ |
85 
86  raw_data_32_63 = mu.hwCharge() << chargeShift_ | mu.hwChargeValid() << chargeValidShift_ |
88  (abs_eta & absEtaMask_) << absEtaShift_ | (mu.hwEta() < 0) << etaSignShift_ |
89  (mu.hwPhi() & phiMask_) << phiShift_;
90 }
91 
93  uint32_t lsw;
94  uint32_t msw;
95 
96  generatePackedDataWords(mu, lsw, msw);
97  return (((uint64_t)msw) << 32) + lsw;
98 }
99 
101  const unsigned absEtaShift,
102  const unsigned etaSignShift) {
103  // eta is coded as two's complement
104  int abs_eta = (raw >> absEtaShift) & absEtaMask_;
105  if ((raw >> etaSignShift) & 0x1) {
106  return abs_eta - (1 << (etaSignShift - absEtaShift));
107  } else {
108  return abs_eta;
109  }
110 }
int hwPhiAtVtx() const
Definition: Muon.h:92
double eta() const final
momentum pseudorapidity
static const unsigned etaAtVtxSignShift_
static const unsigned tfMuonIndexShift_
static const unsigned phiMask_
static const unsigned isoShift_
static const unsigned etaSignShift_
void setPhiAtVtx(double phiAtVtx)
Definition: Muon.h:76
void setHwDPhiExtra(int dPhi)
Definition: Muon.h:79
void setHwQual(int qual)
Definition: L1Candidate.h:31
int hwPhi() const
Definition: L1Candidate.h:37
static const unsigned absEtaAtVtxShift_
static int calcHwEta(const uint32_t &, const unsigned, const unsigned)
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
void setCharge(Charge q) final
set electric charge
int hwIso() const
Definition: L1Candidate.h:39
static const unsigned qualShift_
static const unsigned tfMuonIndexMask_
void setTfMuonIndex(int index)
Definition: Muon.h:70
static const unsigned absEtaShift_
Definition: Muon.py:1
void setHwCharge(int charge)
Definition: Muon.h:68
static const unsigned phiShift_
void setHwChargeValid(int valid)
Definition: Muon.h:69
void setHwPhiAtVtx(int hwPhiAtVtx)
Definition: Muon.h:74
int hwEta() const
Definition: L1Candidate.h:36
static const unsigned chargeValidShift_
int hwQual() const
Definition: L1Candidate.h:38
static const unsigned absEtaMask_
void setHwPhi(int phi)
Definition: L1Candidate.h:30
void setHwIso(int iso)
Definition: L1Candidate.h:32
int tfMuonIndex() const
Definition: Muon.h:88
int hwPt() const
Definition: L1Candidate.h:35
void setHwEtaAtVtx(int hwEtaAtVtx)
Definition: Muon.h:73
static uint64_t generate64bitDataWord(const Muon &)
unsigned long long uint64_t
Definition: Time.h:13
int hwEtaAtVtx() const
Definition: Muon.h:91
static const unsigned ptShift_
static void generatePackedDataWords(const Muon &, uint32_t &, uint32_t &)
void setHwDEtaExtra(int dEta)
Definition: Muon.h:80
static const unsigned isoMask_
void setHwPt(int pt)
Definition: L1Candidate.h:28
static const unsigned chargeShift_
void setHwEta(int eta)
Definition: L1Candidate.h:29
static const unsigned qualMask_
int hwChargeValid() const
Definition: Muon.h:87
double phi() const final
momentum azimuthal angle
static const unsigned phiAtVtxShift_
void setP4(const LorentzVector &p4) final
set 4-momentum
int hwCharge() const
Definition: Muon.h:86
static const unsigned ptMask_
static void fillMuon(Muon &, uint32_t, uint32_t, int, unsigned int)
void setEtaAtVtx(double etaAtVtx)
Definition: Muon.h:75