CMS 3D CMS Logo

MicroGMTIsolationUnit.cc
Go to the documentation of this file.
2 
7 
8 l1t::MicroGMTIsolationUnit::MicroGMTIsolationUnit() : m_fwVersion(0), m_initialSums(false) {}
9 
11 
13  m_fwVersion = microGMTParamsHelper->fwVersion();
15  microGMTParamsHelper->bEtaExtrapolationLUT(), MicroGMTConfiguration::ETA_OUT, m_fwVersion);
17  microGMTParamsHelper->bPhiExtrapolationLUT(), MicroGMTConfiguration::PHI_OUT, m_fwVersion);
19  microGMTParamsHelper->oEtaExtrapolationLUT(), MicroGMTConfiguration::ETA_OUT, m_fwVersion);
21  microGMTParamsHelper->oPhiExtrapolationLUT(), MicroGMTConfiguration::PHI_OUT, m_fwVersion);
23  microGMTParamsHelper->fEtaExtrapolationLUT(), MicroGMTConfiguration::ETA_OUT, m_fwVersion);
25  microGMTParamsHelper->fPhiExtrapolationLUT(), MicroGMTConfiguration::PHI_OUT, m_fwVersion);
27  microGMTParamsHelper->idxSelMemEtaLUT(), MicroGMTConfiguration::ETA, m_fwVersion);
29  microGMTParamsHelper->idxSelMemPhiLUT(), MicroGMTConfiguration::PHI, m_fwVersion);
30  m_RelIsoCheckMem =
32  m_AbsIsoCheckMem =
34 
35  m_etaExtrapolationLUTs[tftype::bmtf] = m_BEtaExtrapolation;
36  m_phiExtrapolationLUTs[tftype::bmtf] = m_BPhiExtrapolation;
37  m_etaExtrapolationLUTs[tftype::omtf_pos] = m_OEtaExtrapolation;
38  m_etaExtrapolationLUTs[tftype::omtf_neg] = m_OEtaExtrapolation;
39  m_phiExtrapolationLUTs[tftype::omtf_pos] = m_OPhiExtrapolation;
40  m_phiExtrapolationLUTs[tftype::omtf_neg] = m_OPhiExtrapolation;
41  m_etaExtrapolationLUTs[tftype::emtf_pos] = m_FEtaExtrapolation;
42  m_etaExtrapolationLUTs[tftype::emtf_neg] = m_FEtaExtrapolation;
43  m_phiExtrapolationLUTs[tftype::emtf_pos] = m_FPhiExtrapolation;
44  m_phiExtrapolationLUTs[tftype::emtf_neg] = m_FPhiExtrapolation;
45 
46  m_caloInputsToDisable = microGMTParamsHelper->caloInputsToDisable();
47  m_maskedCaloInputs = microGMTParamsHelper->maskedCaloInputs();
48 }
49 
51  // handle the wrap-around of phi:
52  int phi = (mu.hwGlobalPhi() + mu.hwDPhi()) % 576;
53  if (phi < 0) {
54  phi = 576 + phi;
55  }
56 
57  int phiIndex = m_IdxSelMemPhi->lookup(phi);
58  int eta = mu.hwEta() + mu.hwDEta();
60  int etaIndex = m_IdxSelMemEta->lookup(eta);
61  mu.setHwCaloEta(etaIndex);
62  mu.setHwCaloPhi(phiIndex);
63 
64  return phiIndex + etaIndex * 36;
65 }
66 
68  int outputShiftPhi = 3;
69  int outputShiftEta = 3;
70  if (m_fwVersion >= 0x4010000) {
71  outputShiftPhi = 2;
72  outputShiftEta = 0;
73  }
74 
75  for (auto& mu : inputmuons) {
76  // get input format
77  std::shared_ptr<MicroGMTExtrapolationLUT> phiExtrapolationLUT = m_phiExtrapolationLUTs.at(mu->trackFinderType());
78  int ptRedInWidth = phiExtrapolationLUT->getPtRedInWidth();
79  int ptMask = (1 << ptRedInWidth) - 1;
80  int etaRedInWidth = phiExtrapolationLUT->getEtaRedInWidth();
81  int redEtaShift = 8 - etaRedInWidth;
82 
83  // only use LSBs of pt:
84  int ptRed = mu->hwPt() & ptMask;
85  // here we drop the LSBs and mask the MSB
86  int etaAbsRed = (std::abs(mu->hwEta()) >> redEtaShift) & ((1 << etaRedInWidth) - 1);
87 
88  int deltaPhi = 0;
89  int deltaEta = 0;
90 
91  if (mu->hwPt() < (1 << ptRedInWidth)) { // extrapolation only for "low" pT muons
92  int sign = 1;
93  if (mu->hwSign() == 1) {
94  sign = -1;
95  }
96  deltaPhi = (phiExtrapolationLUT->lookup(etaAbsRed, ptRed) << outputShiftPhi) * sign;
97  deltaEta = (m_etaExtrapolationLUTs.at(mu->trackFinderType())->lookup(etaAbsRed, ptRed) << outputShiftEta);
98  if (mu->hwEta() > 0) {
99  deltaEta *= -1;
100  }
101  }
102 
103  mu->setExtrapolation(deltaEta, deltaPhi);
104  }
105 }
106 
108  m_5by1TowerSums.clear();
109  if (inputs.size(bx) == 0)
110  return;
111 
112  for (int iphi = 0; iphi < 36; ++iphi) {
113  int iphiIndexOffset = iphi * 28;
114  // ieta = 0 (tower -28) and ieta = 1 (tower 27)
115  // 3by1 and 4by1 sums
116  for (int ieta = 0; ieta < 2; ++ieta) {
117  int sum = 0;
118  for (int dIEta = 0 - ieta; dIEta <= 2; ++dIEta) {
119  if (m_caloInputsToDisable.test(ieta + dIEta) || m_maskedCaloInputs.test(ieta + dIEta))
120  continue; // only process if input link is enabled and not masked
121  sum += inputs.at(bx, iphiIndexOffset + dIEta).etBits();
122  }
123  m_5by1TowerSums.push_back(sum);
124  }
125  // 5by1 sums
126  for (int ieta = 2; ieta < 26; ++ieta) {
127  int sum = 0;
128  for (int dIEta = -2; dIEta <= 2; ++dIEta) {
129  if (m_caloInputsToDisable.test(ieta + dIEta) || m_maskedCaloInputs.test(ieta + dIEta))
130  continue; // only process if input link is enabled and not masked
131  sum += inputs.at(bx, iphiIndexOffset + dIEta).etBits();
132  }
133  m_5by1TowerSums.push_back(sum);
134  }
135  // ieta = 26 (tower 27) and ieta = 27 (tower 28)
136  // 4by1 and 3by1 sums
137  for (int ieta = 26; ieta < 28; ++ieta) {
138  int sum = 0;
139  for (int dIEta = -2; dIEta <= 27 - ieta; ++dIEta) {
140  if (m_caloInputsToDisable.test(ieta + dIEta) || m_maskedCaloInputs.test(ieta + dIEta))
141  continue; // only process if input link is enabled and not masked
142  sum += inputs.at(bx, iphiIndexOffset + dIEta).etBits();
143  }
144  m_5by1TowerSums.push_back(sum);
145  }
146  }
147 
148  m_initialSums = true;
149 }
150 
152  if (index > m_5by1TowerSums.size()) {
153  edm::LogWarning("energysum out of bounds!");
154  return 0;
155  }
156  // phi wrap around:
157  int returnSum = 0;
158  for (int dIPhi = -2; dIPhi <= 2; ++dIPhi) {
159  int currIndex = (index + dIPhi * 28) % 1008; // wrap-around at top
160  if (currIndex < 0)
161  currIndex = 1008 + currIndex;
162  if ((unsigned)currIndex < m_5by1TowerSums.size()) {
163  returnSum += m_5by1TowerSums[currIndex];
164  } else {
165  edm::LogWarning("energysum out of bounds!");
166  }
167  }
168  return std::min(31, returnSum);
169 }
170 
172  for (auto& mu : muons) {
173  int caloIndex = getCaloIndex(*mu);
174  int energySum = calculate5by5Sum(caloIndex);
175  mu->setHwIsoSum(energySum);
176 
177  int absIso = m_AbsIsoCheckMem->lookup(energySum);
178  int relIso = m_RelIsoCheckMem->lookup(energySum, mu->hwPt());
179 
180  mu->setHwRelIso(relIso);
181  mu->setHwAbsIso(absIso);
182  }
183 }
184 
186  m_towerEnergies.clear();
187  if (bx < inputs.getFirstBX() || bx > inputs.getLastBX())
188  return;
189  if (inputs.size(bx) == 0)
190  return;
191  for (auto input = inputs.begin(bx); input != inputs.end(bx); ++input) {
192  if (m_caloInputsToDisable.test(input->hwEta()) || m_maskedCaloInputs.test(input->hwEta())) {
193  continue; // only process if input link is enabled and not masked
194  }
195  if (input->etBits() != 0) {
196  m_towerEnergies[input->hwEta() * 36 + input->hwPhi()] = input->etBits();
197  }
198  }
199 
200  m_initialSums = true;
201 }
202 
204  for (const auto& mu : muons) {
205  int caloIndex = getCaloIndex(*mu);
206  int energySum = 0;
207  if (m_towerEnergies.count(caloIndex) == 1) {
208  energySum = m_towerEnergies.at(caloIndex);
209  }
210 
211  mu->setHwIsoSum(energySum);
212 
213  int absIso = m_AbsIsoCheckMem->lookup(energySum);
214  int relIso = m_RelIsoCheckMem->lookup(energySum, mu->hwPt());
215 
216  mu->setHwRelIso(relIso);
217  mu->setHwAbsIso(absIso);
218  }
219 }
static unsigned getTwosComp(const int signedInt, const int width)
void extrapolateMuons(MicroGMTConfiguration::InterMuonList &) const
void isolate(MicroGMTConfiguration::InterMuonList &) const
void setTowerSums(const MicroGMTConfiguration::CaloInputCollection &inputs, int bx)
static ReturnType create(const std::string &filename, const int fwVersion)
static const double deltaEta
Definition: CaloConstants.h:8
static ReturnType create(const std::string &filename, const int type, const int fwVersion)
static std::string const input
Definition: EdmProvDump.cc:50
void isolatePreSummed(MicroGMTConfiguration::InterMuonList &muons) const
static ReturnType create(const std::string &filename, const int fwVersion)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
GMTInternalMuonList InterMuonList
std::bitset< 28 > maskedCaloInputs() const
void calculate5by1Sums(const MicroGMTConfiguration::CaloInputCollection &, int bx)
int calculate5by5Sum(unsigned index) const
double energySum(const DataFrame &df, int fs, int ls)
Log< level::Warning, false > LogWarning
void initialise(L1TMuonGlobalParamsHelper *)
Initialisation from ES record.
static ReturnType create(const std::string &filename, const int type, const int fwVersion)
int getCaloIndex(MicroGMTConfiguration::InterMuon &) const
std::bitset< 28 > caloInputsToDisable() const