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  m_BEtaExtrapolation(iConfig, "BEtaExtrapolationLUTSettings", 0), m_BPhiExtrapolation(iConfig, "BPhiExtrapolationLUTSettings", 1), m_OEtaExtrapolation(iConfig, "OEtaExtrapolationLUTSettings", 0),
11  m_OPhiExtrapolation(iConfig, "OPhiExtrapolationLUTSettings", 1), m_FEtaExtrapolation(iConfig, "FEtaExtrapolationLUTSettings", 0), m_FPhiExtrapolation(iConfig, "FPhiExtrapolationLUTSettings", 1),
12  m_IdxSelMemEta(iConfig, "IdxSelMemEtaLUTSettings", 0), m_IdxSelMemPhi(iConfig, "IdxSelMemPhiLUTSettings", 1), m_RelIsoCheckMem(iConfig, "RelIsoCheckMemLUTSettings"),
13  m_AbsIsoCheckMem(iConfig, "AbsIsoCheckMemLUTSettings"), m_initialSums(false)
14 {
25 }
26 
28 {
29 }
30 
31 int
33 {
34  // handle the wrap-around of phi:
35  int phi = (mu.hwGlobalPhi() + mu.hwDPhi())%576;
36  if (phi < 0) {
37  phi = 576+phi;
38  }
39 
40  int phiIndex = m_IdxSelMemPhi.lookup(phi);
41  int eta = mu.hwEta()+mu.hwDEta();
43  int etaIndex = m_IdxSelMemEta.lookup(eta);
44  mu.setHwCaloEta(etaIndex);
45  mu.setHwCaloPhi(phiIndex);
46 
47  return phiIndex + etaIndex*36;
48 }
49 
50 void
52  for (auto &mu : inputmuons) {
53  // only use 6 LSBs of pt:
54  int ptRed = mu->hwPt() & 0b111111;
55  // here we drop the two LSBs and masking the MSB
56  int etaAbsRed = (std::abs(mu->hwEta()) >> 2) & ((1 << 6) - 1);
57 
58  int deltaPhi = 0;
59  int deltaEta = 0;
60 
61  if (mu->hwPt() < 64) { // extrapolation only for "low" pT muons
62  int sign = 1;
63  if (mu->hwSign() == 0) {
64  sign = -1;
65  }
66  deltaPhi = (m_phiExtrapolationLUTs.at(mu->trackFinderType())->lookup(etaAbsRed, ptRed) << 3) * sign;
67  deltaEta = (m_etaExtrapolationLUTs.at(mu->trackFinderType())->lookup(etaAbsRed, ptRed) << 3);
68  }
69 
70  mu->setExtrapolation(deltaEta, deltaPhi);
71  }
72 }
73 
74 void
76 {
77  m_5by1TowerSums.clear();
78  if (inputs.size(bx) == 0) return;
79 
80  for (int iphi = 0; iphi < 36; ++iphi) {
81  int iphiIndexOffset = iphi*28;
82  m_5by1TowerSums.push_back(inputs.at(bx, iphiIndexOffset).etBits()+inputs.at(bx, iphiIndexOffset+1).etBits()+inputs.at(bx, iphiIndexOffset+2).etBits());//ieta = 0 (tower -28)
83  m_5by1TowerSums.push_back(inputs.at(bx, iphiIndexOffset-1).etBits()+inputs.at(bx, iphiIndexOffset).etBits()+inputs.at(bx, iphiIndexOffset+1).etBits()+inputs.at(bx, iphiIndexOffset+2).etBits()); //
84  for (int ieta = 2; ieta < 26; ++ieta) {
85  int sum = 0;
86  for (int dIEta = -2; dIEta <= 2; ++dIEta) {
87  sum += inputs.at(bx, iphiIndexOffset+dIEta).etBits();
88  }
89  m_5by1TowerSums.push_back(sum);
90  }
91  m_5by1TowerSums.push_back(inputs.at(bx, iphiIndexOffset+1).etBits()+inputs.at(bx, iphiIndexOffset).etBits()+inputs.at(bx, iphiIndexOffset-1).etBits()+inputs.at(bx, iphiIndexOffset-2).etBits());
92  m_5by1TowerSums.push_back(inputs.at(bx, iphiIndexOffset).etBits()+inputs.at(bx, iphiIndexOffset-1).etBits()+inputs.at(bx, iphiIndexOffset-2).etBits());//ieta = 0 (tower 28)
93  }
94 
95  m_initialSums = true;
96 }
97 
98 
99 int
101 {
102  if (index > m_5by1TowerSums.size()) {
103  edm::LogWarning("energysum out of bounds!");
104  return 0;
105  }
106  // phi wrap around:
107  int returnSum = 0;
108  for (int dIPhi = -2; dIPhi <= 2; ++dIPhi) {
109  int currIndex = (index + dIPhi*28)%1008; // wrap-around at top
110  if (currIndex < 0) currIndex = 1008+currIndex;
111  if ((unsigned)currIndex < m_5by1TowerSums.size()) {
112  returnSum += m_5by1TowerSums[currIndex];
113  } else {
114  edm::LogWarning("energysum out of bounds!");
115  }
116  }
117  return std::min(31, returnSum);
118 }
119 
120 void
122 {
123  for (auto& mu : muons) {
124  int caloIndex = getCaloIndex(*mu);
125  int energySum = calculate5by5Sum(caloIndex);
126  mu->setHwIsoSum(energySum);
127 
128  int absIso = m_AbsIsoCheckMem.lookup(energySum);
129  int relIso = m_RelIsoCheckMem.lookup(energySum, mu->hwPt());
130 
131  mu->setHwRelIso(relIso);
132  mu->setHwAbsIso(absIso);
133  }
134 }
135 
137  m_towerEnergies.clear();
138  if (inputs.size(bx) == 0) return;
139  for (auto input = inputs.begin(bx); input != inputs.end(bx); ++input) {
140  if ( input->etBits() != 0 ) {
141  m_towerEnergies[input->hwEta()*36+input->hwPhi()] = input->etBits();
142  }
143  }
144 
145  m_initialSums = true;
146 
147 }
148 
150 {
151  for (auto mu : muons) {
152  int caloIndex = getCaloIndex(*mu);
153  int energySum = 0;
154  if (m_towerEnergies.count(caloIndex) == 1) {
155  energySum = m_towerEnergies.at(caloIndex);
156  }
157 
158  mu->setHwIsoSum(energySum);
159 
160  int absIso = m_AbsIsoCheckMem.lookup(energySum);
161  int relIso = m_RelIsoCheckMem.lookup(energySum, mu->hwPt());
162 
163  mu->setHwRelIso(relIso);
164  mu->setHwAbsIso(absIso);
165  }
166 
167 }
std::map< tftype, MicroGMTExtrapolationLUT * > m_etaExtrapolationLUTs
static unsigned getTwosComp(const int signedInt, const int width)
const_iterator end(int bx) const
MicroGMTExtrapolationLUT m_BEtaExtrapolation
void extrapolateMuons(MicroGMTConfiguration::InterMuonList &) const
const int hwDEta() const
unsigned size(int bx) const
void setTowerSums(const MicroGMTConfiguration::CaloInputCollection &inputs, int bx)
MicroGMTExtrapolationLUT m_OEtaExtrapolation
double sign(double x)
void setHwCaloPhi(int idx)
MicroGMTExtrapolationLUT m_FEtaExtrapolation
static std::string const input
Definition: EdmProvDump.cc:43
std::map< tftype, MicroGMTExtrapolationLUT * > m_phiExtrapolationLUTs
const int hwDPhi() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
MicroGMTExtrapolationLUT m_FPhiExtrapolation
const int mu
Definition: Constants.h:22
T min(T a, T b)
Definition: MathUtil.h:58
GMTInternalMuonList InterMuonList
const int hwEta() const
void calculate5by1Sums(const MicroGMTConfiguration::CaloInputCollection &, int bx)
MicroGMTExtrapolationLUT m_BPhiExtrapolation
void isolate(MicroGMTConfiguration::InterMuonList &) const
const int hwGlobalPhi() const
int getCaloIndex(MicroGMTConfiguration::InterMuon &) const
Geom::Phi< T > phi() const
MicroGMTExtrapolationLUT m_OPhiExtrapolation
tuple muons
Definition: patZpeak.py:38
MicroGMTIsolationUnit(const edm::ParameterSet &)
volatile std::atomic< bool > shutdown_flag false
double energySum(const DataFrame &df, int fs, int ls)
void isolatePreSummed(MicroGMTConfiguration::InterMuonList &muons) const
const_iterator begin(int bx) const
void setHwCaloEta(int idx)
int calculate5by5Sum(unsigned index) const
const T & at(int bx, unsigned i) const