CMS 3D CMS Logo

MicroGMTIsolationUnit.cc
Go to the documentation of this file.
2 
7 
8 
9 l1t::MicroGMTIsolationUnit::MicroGMTIsolationUnit () : m_fwVersion(0), m_initialSums(false)
10 {
11 }
12 
14 {
15 }
16 
17 void
19  m_fwVersion = microGMTParamsHelper->fwVersion();
30 
33  m_etaExtrapolationLUTs[tftype::omtf_pos] = m_OEtaExtrapolation;
34  m_etaExtrapolationLUTs[tftype::omtf_neg] = m_OEtaExtrapolation;
37  m_etaExtrapolationLUTs[tftype::emtf_pos] = m_FEtaExtrapolation;
38  m_etaExtrapolationLUTs[tftype::emtf_neg] = m_FEtaExtrapolation;
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  int outputShiftPhi = 3;
68  int outputShiftEta = 3;
69  if (m_fwVersion >= 0x4010000) {
70  outputShiftPhi = 2;
71  outputShiftEta = 0;
72  }
73 
74  for (auto &mu : inputmuons) {
75  // get input format
76  std::shared_ptr<MicroGMTExtrapolationLUT> phiExtrapolationLUT = m_phiExtrapolationLUTs.at(mu->trackFinderType());
77  int ptRedInWidth = phiExtrapolationLUT->getPtRedInWidth();
78  int ptMask = (1 << ptRedInWidth) - 1;
79  int etaRedInWidth = phiExtrapolationLUT->getEtaRedInWidth();
80  int redEtaShift = 8 - etaRedInWidth;
81 
82  // only use LSBs of pt:
83  int ptRed = mu->hwPt() & ptMask;
84  // here we drop the LSBs and mask the MSB
85  int etaAbsRed = (std::abs(mu->hwEta()) >> redEtaShift) & ((1 << etaRedInWidth) - 1);
86 
87  int deltaPhi = 0;
88  int deltaEta = 0;
89 
90  if (mu->hwPt() < (1 << ptRedInWidth)) { // extrapolation only for "low" pT muons
91  int sign = 1;
92  if (mu->hwSign() == 1) {
93  sign = -1;
94  }
95  deltaPhi = (phiExtrapolationLUT->lookup(etaAbsRed, ptRed) << outputShiftPhi) * sign;
96  deltaEta = (m_etaExtrapolationLUTs.at(mu->trackFinderType())->lookup(etaAbsRed, ptRed) << outputShiftEta);
97  if (mu->hwEta() > 0) {
98  deltaEta *= -1;
99  }
100  }
101 
102  mu->setExtrapolation(deltaEta, deltaPhi);
103  }
104 }
105 
106 void
108 {
109  m_5by1TowerSums.clear();
110  if (inputs.size(bx) == 0) 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)) continue; // only process if input link is enabled and not masked
120  sum += inputs.at(bx, iphiIndexOffset+dIEta).etBits();
121  }
122  m_5by1TowerSums.push_back(sum);
123  }
124  // 5by1 sums
125  for (int ieta = 2; ieta < 26; ++ieta) {
126  int sum = 0;
127  for (int dIEta = -2; dIEta <= 2; ++dIEta) {
128  if (m_caloInputsToDisable.test(ieta+dIEta) || m_maskedCaloInputs.test(ieta+dIEta)) continue; // only process if input link is enabled and not masked
129  sum += inputs.at(bx, iphiIndexOffset+dIEta).etBits();
130  }
131  m_5by1TowerSums.push_back(sum);
132  }
133  // ieta = 26 (tower 27) and ieta = 27 (tower 28)
134  // 4by1 and 3by1 sums
135  for (int ieta = 26; ieta < 28; ++ieta) {
136  int sum = 0;
137  for (int dIEta = -2; dIEta <= 27-ieta; ++dIEta) {
138  if (m_caloInputsToDisable.test(ieta+dIEta) || m_maskedCaloInputs.test(ieta+dIEta)) continue; // only process if input link is enabled and not masked
139  sum += inputs.at(bx, iphiIndexOffset+dIEta).etBits();
140  }
141  m_5by1TowerSums.push_back(sum);
142  }
143  }
144 
145  m_initialSums = true;
146 }
147 
148 
149 int
151 {
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) currIndex = 1008+currIndex;
161  if ((unsigned)currIndex < m_5by1TowerSums.size()) {
162  returnSum += m_5by1TowerSums[currIndex];
163  } else {
164  edm::LogWarning("energysum out of bounds!");
165  }
166  }
167  return std::min(31, returnSum);
168 }
169 
170 void
172 {
173  for (auto& mu : muons) {
174  int caloIndex = getCaloIndex(*mu);
175  int energySum = calculate5by5Sum(caloIndex);
176  mu->setHwIsoSum(energySum);
177 
178  int absIso = m_AbsIsoCheckMem->lookup(energySum);
179  int relIso = m_RelIsoCheckMem->lookup(energySum, mu->hwPt());
180 
181  mu->setHwRelIso(relIso);
182  mu->setHwAbsIso(absIso);
183  }
184 }
185 
187  m_towerEnergies.clear();
188  if (bx < inputs.getFirstBX() || bx > inputs.getLastBX()) return;
189  if (inputs.size(bx) == 0) return;
190  for (auto input = inputs.begin(bx); input != inputs.end(bx); ++input) {
191  if (m_caloInputsToDisable.test(input->hwEta()) || m_maskedCaloInputs.test(input->hwEta())) {
192  continue; // only process if input link is enabled and not masked
193  }
194  if ( input->etBits() != 0 ) {
195  m_towerEnergies[input->hwEta()*36+input->hwPhi()] = input->etBits();
196  }
197  }
198 
199  m_initialSums = true;
200 
201 }
202 
204 {
205  for (const auto &mu : muons) {
206  int caloIndex = getCaloIndex(*mu);
207  int energySum = 0;
208  if (m_towerEnergies.count(caloIndex) == 1) {
209  energySum = m_towerEnergies.at(caloIndex);
210  }
211 
212  mu->setHwIsoSum(energySum);
213 
214  int absIso = m_AbsIsoCheckMem->lookup(energySum);
215  int relIso = m_RelIsoCheckMem->lookup(energySum, mu->hwPt());
216 
217  mu->setHwRelIso(relIso);
218  mu->setHwAbsIso(absIso);
219  }
220 
221 }
static unsigned getTwosComp(const int signedInt, const int width)
const_iterator end(int bx) const
std::shared_ptr< MicroGMTCaloIndexSelectionLUT > m_IdxSelMemEta
void extrapolateMuons(MicroGMTConfiguration::InterMuonList &) const
const int hwDEta() const
unsigned size(int bx) const
std::shared_ptr< MicroGMTExtrapolationLUT > m_OPhiExtrapolation
void setTowerSums(const MicroGMTConfiguration::CaloInputCollection &inputs, int bx)
std::bitset< 28 > caloInputsToDisable() const
void setHwCaloPhi(int idx)
std::shared_ptr< MicroGMTAbsoluteIsolationCheckLUT > m_AbsIsoCheckMem
std::map< tftype, std::shared_ptr< MicroGMTExtrapolationLUT > > m_etaExtrapolationLUTs
std::map< int, int > m_towerEnergies
static ReturnType create(const std::string &filename, const int fwVersion)
std::shared_ptr< MicroGMTRelativeIsolationCheckLUT > m_RelIsoCheckMem
std::bitset< 28 > m_caloInputsToDisable
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:45
static ReturnType create(const std::string &filename, const int fwVersion)
std::shared_ptr< MicroGMTExtrapolationLUT > m_FEtaExtrapolation
const int hwDPhi() const
std::shared_ptr< MicroGMTExtrapolationLUT > m_BPhiExtrapolation
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::shared_ptr< MicroGMTExtrapolationLUT > m_OEtaExtrapolation
const int mu
Definition: Constants.h:22
T min(T a, T b)
Definition: MathUtil.h:58
GMTInternalMuonList InterMuonList
std::shared_ptr< MicroGMTExtrapolationLUT > m_FPhiExtrapolation
const int hwEta() const
int getFirstBX() const
std::shared_ptr< MicroGMTCaloIndexSelectionLUT > m_IdxSelMemPhi
void calculate5by1Sums(const MicroGMTConfiguration::CaloInputCollection &, int bx)
void isolate(MicroGMTConfiguration::InterMuonList &) const
std::shared_ptr< MicroGMTExtrapolationLUT > m_BEtaExtrapolation
const int hwGlobalPhi() const
int getCaloIndex(MicroGMTConfiguration::InterMuon &) const
int getLastBX() const
std::bitset< 28 > m_maskedCaloInputs
double energySum(const DataFrame &df, int fs, int ls)
std::map< tftype, std::shared_ptr< MicroGMTExtrapolationLUT > > m_phiExtrapolationLUTs
void initialise(L1TMuonGlobalParamsHelper *)
Initialisation from ES record.
void isolatePreSummed(MicroGMTConfiguration::InterMuonList &muons) const
const_iterator begin(int bx) const
std::vector< int > m_5by1TowerSums
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