test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MicroGMTIsolationUnit.cc
Go to the documentation of this file.
1 #include "../interface/MicroGMTIsolationUnit.h"
2 
7 
8 
10 {
11 }
12 
14 {
15 }
16 
17 void
19  int fwVersion = microGMTParamsHelper->fwVersion();
28  m_RelIsoCheckMem = l1t::MicroGMTRelativeIsolationCheckLUTFactory::create(microGMTParamsHelper->relIsoCheckMemLUT(), fwVersion);
29  m_AbsIsoCheckMem = l1t::MicroGMTAbsoluteIsolationCheckLUTFactory::create(microGMTParamsHelper->absIsoCheckMemLUT(), fwVersion);
30 
31  m_etaExtrapolationLUTs[tftype::bmtf] = m_BEtaExtrapolation;
32  m_phiExtrapolationLUTs[tftype::bmtf] = m_BPhiExtrapolation;
33  m_etaExtrapolationLUTs[tftype::omtf_pos] = m_OEtaExtrapolation;
34  m_etaExtrapolationLUTs[tftype::omtf_neg] = m_OEtaExtrapolation;
35  m_phiExtrapolationLUTs[tftype::omtf_pos] = m_OPhiExtrapolation;
36  m_phiExtrapolationLUTs[tftype::omtf_neg] = m_OPhiExtrapolation;
37  m_etaExtrapolationLUTs[tftype::emtf_pos] = m_FEtaExtrapolation;
38  m_etaExtrapolationLUTs[tftype::emtf_neg] = m_FEtaExtrapolation;
39  m_phiExtrapolationLUTs[tftype::emtf_pos] = m_FPhiExtrapolation;
40  m_phiExtrapolationLUTs[tftype::emtf_neg] = m_FPhiExtrapolation;
41 
42  m_caloInputsToDisable = microGMTParamsHelper->caloInputsToDisable();
43  m_maskedCaloInputs = microGMTParamsHelper->maskedCaloInputs();
44 }
45 
46 int
48 {
49  // handle the wrap-around of phi:
50  int phi = (mu.hwGlobalPhi() + mu.hwDPhi())%576;
51  if (phi < 0) {
52  phi = 576+phi;
53  }
54 
55  int phiIndex = m_IdxSelMemPhi->lookup(phi);
56  int eta = mu.hwEta()+mu.hwDEta();
58  int etaIndex = m_IdxSelMemEta->lookup(eta);
59  mu.setHwCaloEta(etaIndex);
60  mu.setHwCaloPhi(phiIndex);
61 
62  return phiIndex + etaIndex*36;
63 }
64 
65 void
67  for (auto &mu : inputmuons) {
68  // only use 6 LSBs of pt:
69  int ptRed = mu->hwPt() & 0b111111;
70  // here we drop the two LSBs and masking the MSB
71  int etaAbsRed = (std::abs(mu->hwEta()) >> 2) & ((1 << 6) - 1);
72 
73  int deltaPhi = 0;
74  int deltaEta = 0;
75 
76  if (mu->hwPt() < 64) { // extrapolation only for "low" pT muons
77  int sign = 1;
78  if (mu->hwSign() == 1) {
79  sign = -1;
80  }
81  deltaPhi = (m_phiExtrapolationLUTs.at(mu->trackFinderType())->lookup(etaAbsRed, ptRed) << 3) * sign;
82  deltaEta = (m_etaExtrapolationLUTs.at(mu->trackFinderType())->lookup(etaAbsRed, ptRed) << 3);
83  }
84 
85  mu->setExtrapolation(deltaEta, deltaPhi);
86  }
87 }
88 
89 void
91 {
92  m_5by1TowerSums.clear();
93  if (inputs.size(bx) == 0) return;
94 
95  for (int iphi = 0; iphi < 36; ++iphi) {
96  int iphiIndexOffset = iphi*28;
97  // ieta = 0 (tower -28) and ieta = 1 (tower 27)
98  // 3by1 and 4by1 sums
99  for (int ieta = 0; ieta < 2; ++ieta) {
100  int sum = 0;
101  for (int dIEta = 0-ieta; dIEta <= 2; ++dIEta) {
102  if (m_caloInputsToDisable.test(ieta+dIEta) || m_maskedCaloInputs.test(ieta+dIEta)) continue; // only process if input link is enabled and not masked
103  sum += inputs.at(bx, iphiIndexOffset+dIEta).etBits();
104  }
105  m_5by1TowerSums.push_back(sum);
106  }
107  // 5by1 sums
108  for (int ieta = 2; ieta < 26; ++ieta) {
109  int sum = 0;
110  for (int dIEta = -2; dIEta <= 2; ++dIEta) {
111  if (m_caloInputsToDisable.test(ieta+dIEta) || m_maskedCaloInputs.test(ieta+dIEta)) continue; // only process if input link is enabled and not masked
112  sum += inputs.at(bx, iphiIndexOffset+dIEta).etBits();
113  }
114  m_5by1TowerSums.push_back(sum);
115  }
116  // ieta = 26 (tower 27) and ieta = 27 (tower 28)
117  // 4by1 and 3by1 sums
118  for (int ieta = 26; ieta < 28; ++ieta) {
119  int sum = 0;
120  for (int dIEta = -2; dIEta <= 27-ieta; ++dIEta) {
121  if (m_caloInputsToDisable.test(ieta+dIEta) || m_maskedCaloInputs.test(ieta+dIEta)) continue; // only process if input link is enabled and not masked
122  sum += inputs.at(bx, iphiIndexOffset+dIEta).etBits();
123  }
124  m_5by1TowerSums.push_back(sum);
125  }
126  }
127 
128  m_initialSums = true;
129 }
130 
131 
132 int
134 {
135  if (index > m_5by1TowerSums.size()) {
136  edm::LogWarning("energysum out of bounds!");
137  return 0;
138  }
139  // phi wrap around:
140  int returnSum = 0;
141  for (int dIPhi = -2; dIPhi <= 2; ++dIPhi) {
142  int currIndex = (index + dIPhi*28)%1008; // wrap-around at top
143  if (currIndex < 0) currIndex = 1008+currIndex;
144  if ((unsigned)currIndex < m_5by1TowerSums.size()) {
145  returnSum += m_5by1TowerSums[currIndex];
146  } else {
147  edm::LogWarning("energysum out of bounds!");
148  }
149  }
150  return std::min(31, returnSum);
151 }
152 
153 void
155 {
156  for (auto& mu : muons) {
157  int caloIndex = getCaloIndex(*mu);
158  int energySum = calculate5by5Sum(caloIndex);
159  mu->setHwIsoSum(energySum);
160 
161  int absIso = m_AbsIsoCheckMem->lookup(energySum);
162  int relIso = m_RelIsoCheckMem->lookup(energySum, mu->hwPt());
163 
164  mu->setHwRelIso(relIso);
165  mu->setHwAbsIso(absIso);
166  }
167 }
168 
170  m_towerEnergies.clear();
171  if (bx < inputs.getFirstBX() || bx > inputs.getLastBX()) return;
172  if (inputs.size(bx) == 0) return;
173  for (auto input = inputs.begin(bx); input != inputs.end(bx); ++input) {
174  if (m_caloInputsToDisable.test(input->hwEta()) || m_maskedCaloInputs.test(input->hwEta())) {
175  continue; // only process if input link is enabled and not masked
176  }
177  if ( input->etBits() != 0 ) {
178  m_towerEnergies[input->hwEta()*36+input->hwPhi()] = input->etBits();
179  }
180  }
181 
182  m_initialSums = true;
183 
184 }
185 
187 {
188  for (auto mu : muons) {
189  int caloIndex = getCaloIndex(*mu);
190  int energySum = 0;
191  if (m_towerEnergies.count(caloIndex) == 1) {
192  energySum = m_towerEnergies.at(caloIndex);
193  }
194 
195  mu->setHwIsoSum(energySum);
196 
197  int absIso = m_AbsIsoCheckMem->lookup(energySum);
198  int relIso = m_RelIsoCheckMem->lookup(energySum, mu->hwPt());
199 
200  mu->setHwRelIso(relIso);
201  mu->setHwAbsIso(absIso);
202  }
203 
204 }
static unsigned getTwosComp(const int signedInt, const int width)
const_iterator end(int bx) const
void extrapolateMuons(MicroGMTConfiguration::InterMuonList &) const
const int hwDEta() const
unsigned size(int bx) const
void setTowerSums(const MicroGMTConfiguration::CaloInputCollection &inputs, int bx)
std::bitset< 28 > caloInputsToDisable() const
double sign(double x)
void setHwCaloPhi(int idx)
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:44
static ReturnType create(const std::string &filename, const int fwVersion)
const int hwDPhi() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const int mu
Definition: Constants.h:22
T min(T a, T b)
Definition: MathUtil.h:58
GMTInternalMuonList InterMuonList
const int hwEta() const
int getFirstBX() const
void calculate5by1Sums(const MicroGMTConfiguration::CaloInputCollection &, int bx)
void isolate(MicroGMTConfiguration::InterMuonList &) const
const int hwGlobalPhi() const
int getCaloIndex(MicroGMTConfiguration::InterMuon &) const
Geom::Phi< T > phi() const
tuple muons
Definition: patZpeak.py:38
int getLastBX() const
volatile std::atomic< bool > shutdown_flag false
double energySum(const DataFrame &df, int fs, int ls)
void initialise(L1TMuonGlobalParamsHelper *)
Initialisation from ES record.
void isolatePreSummed(MicroGMTConfiguration::InterMuonList &muons) const
const_iterator begin(int bx) const
std::bitset< 28 > maskedCaloInputs() const
void setHwCaloEta(int idx)
static ReturnType create(const std::string &filename, const int type, const int fwVersion)
int calculate5by5Sum(unsigned index) const
const T & at(int bx, unsigned i) const