CMS 3D CMS Logo

RBXAndHPDCleaner.cc
Go to the documentation of this file.
1 #include "RBXAndHPDCleaner.h"
2 
4 #include <cmath>
5 
6 namespace {
7  bool greaterByEnergy(const std::pair<unsigned, double>& a, const std::pair<unsigned, double>& b) {
8  return a.second > b.second;
9  }
10 } // namespace
11 
13  _hpds.clear();
14  _rbxs.clear();
15  //need to run over energy sorted rechits
16  std::vector<std::pair<unsigned, double> > ordered_hits;
17  ordered_hits.reserve(input->size());
18  for (unsigned i = 0; i < input->size(); ++i) {
19  std::pair<unsigned, double> val = std::make_pair(i, input->at(i).energy());
20  auto pos = std::upper_bound(ordered_hits.begin(), ordered_hits.end(), val, greaterByEnergy);
21  ordered_hits.insert(pos, val);
22  }
23 
24  for (const auto& idx_e : ordered_hits) {
25  if (!mask[idx_e.first])
26  continue;
27  const unsigned idx = idx_e.first;
28  const reco::PFRecHit& rechit = input->at(idx);
29  int layer = rechit.layer();
31  break;
32  }
33  HcalDetId theHcalDetId(rechit.detId());
34  int ieta = theHcalDetId.ieta();
35  int iphi = theHcalDetId.iphi();
36  int ihpd = 0, irbx = 0;
37  switch (layer) {
39  ihpd = (ieta < 0 ? -iphi : iphi);
40  irbx = (ieta < 0 ? -(iphi + 5) / 4 : (iphi + 5) / 4);
41  break;
43  ihpd = (ieta < 0 ? -(iphi + 1) / 2 - 100 : (iphi + 1) / 2 + 100);
44  irbx = (ieta < 0 ? -(iphi + 5) / 4 - 20 : (iphi + 5) / 4 + 20);
45  break;
46  default:
47  break;
48  }
49  switch (std::abs(irbx)) {
50  case 19:
51  irbx = (irbx < 0 ? -1 : 1);
52  break;
53  case 39:
54  irbx = (irbx < 0 ? -21 : 21);
55  break;
56  default:
57  break;
58  }
59  _hpds[ihpd].push_back(idx);
60  _rbxs[irbx].push_back(idx);
61  }
62  // loop on the rbx's we found and clean RBX's with tons of rechits
63  // and lots of energy
64  std::unordered_map<int, std::vector<unsigned> > theHPDs;
65  std::unordered_multimap<double, unsigned> theEnergies;
66  for (const auto& itrbx : _rbxs) {
67  if ((std::abs(itrbx.first) < 20 && itrbx.second.size() > 30) ||
68  (std::abs(itrbx.first) > 20 && itrbx.second.size() > 30)) {
69  const std::vector<unsigned>& rechits = itrbx.second;
70  theHPDs.clear();
71  theEnergies.clear();
72  int nSeeds0 = rechits.size();
73  for (unsigned jh = 0; jh < rechits.size(); ++jh) {
74  const reco::PFRecHit& rechit = (*input)[jh];
75  // check if rechit is a seed
76  unsigned nN = 0; // neighbours over threshold
77  bool isASeed = true;
78  auto const& neighbours4 = rechit.neighbours4();
79  for (auto k : neighbours4) {
80  auto const& neighbour = (*input)[k];
81  if (neighbour.energy() > rechit.energy()) {
82  --nSeeds0;
83  isASeed = false;
84  break;
85  } else {
86  if (neighbour.energy() > 0.4)
87  ++nN;
88  }
89  }
90  if (isASeed && !nN)
91  --nSeeds0;
92 
93  HcalDetId theHcalDetId(rechit.detId());
94  int iphi = theHcalDetId.iphi();
95  switch (rechit.layer()) {
97  theHPDs[iphi].push_back(rechits[jh]);
98  break;
100  theHPDs[(iphi - 1) / 2].push_back(rechits[jh]);
101  break;
102  default:
103  break;
104  }
105  const double rhenergy = rechit.energy();
106  theEnergies.emplace(rhenergy, rechits[jh]);
107  }
108  if (nSeeds0 > 6) {
109  unsigned nHPD15 = 0;
110  for (const auto& itHPD : theHPDs) {
111  int hpdN = itHPD.first;
112  const std::vector<unsigned>& hpdHits = itHPD.second;
113  if ((std::abs(hpdN) < 100 && hpdHits.size() > 14) || (std::abs(hpdN) > 100 && hpdHits.size() > 14))
114  ++nHPD15;
115  }
116  if (nHPD15 > 1) {
117  unsigned nn = 0;
118  double threshold = 1.0;
119  for (const auto& itEn : theEnergies) {
120  ++nn;
121  if (nn < 5) {
122  mask[itEn.second] = false;
123  } else if (nn == 5) {
124  threshold = itEn.first * 5;
125  mask[itEn.second] = false;
126  } else {
127  if (itEn.first < threshold)
128  mask[itEn.second] = false;
129  }
130  }
131  }
132  }
133  }
134  }
135 
136  // loop on the HPDs
137  std::unordered_map<int, std::vector<unsigned> >::iterator neighbour1;
138  std::unordered_map<int, std::vector<unsigned> >::iterator neighbour2;
139  std::unordered_map<int, std::vector<unsigned> >::iterator neighbour0;
140  std::unordered_map<int, std::vector<unsigned> >::iterator neighbour3;
141  unsigned size1 = 0, size2 = 0;
142  for (const auto& ithpd : _hpds) {
143  const std::vector<unsigned>& rechits = ithpd.second;
144  theEnergies.clear();
145  for (const unsigned rhidx : rechits) {
146  const reco::PFRecHit& rechit = input->at(rhidx);
147  theEnergies.emplace(rechit.energy(), rhidx);
148  }
149 
150  const int thehpd = ithpd.first;
151  switch (std::abs(thehpd)) {
152  case 1:
153  neighbour1 = (thehpd > 0 ? _hpds.find(72) : _hpds.find(-72));
154  break;
155  case 72:
156  neighbour2 = (thehpd > 0 ? _hpds.find(1) : _hpds.find(-1));
157  break;
158  case 101:
159  neighbour1 = (thehpd > 0 ? _hpds.find(136) : _hpds.find(-136));
160  break;
161  case 136:
162  neighbour2 = (thehpd > 0 ? _hpds.find(101) : _hpds.find(-101));
163  break;
164  default:
165  neighbour1 = (thehpd > 0 ? _hpds.find(thehpd - 1) : _hpds.find(thehpd + 1));
166  neighbour2 = (thehpd > 0 ? _hpds.find(thehpd + 1) : _hpds.find(thehpd - 1));
167  break;
168  }
169  if (neighbour1 != _hpds.end()) {
170  const int nb1 = neighbour1->first;
171  switch (std::abs(nb1)) {
172  case 1:
173  neighbour0 = (nb1 > 0 ? _hpds.find(72) : _hpds.find(-72));
174  break;
175  case 101:
176  neighbour0 = (nb1 > 0 ? _hpds.find(136) : _hpds.find(-136));
177  break;
178  default:
179  neighbour0 = (nb1 > 0 ? _hpds.find(nb1 - 1) : _hpds.find(nb1 + 1));
180  break;
181  }
182  } else {
183  neighbour0 = _hpds.end();
184  }
185 
186  if (neighbour2 != _hpds.end()) {
187  const int nb2 = neighbour2->first;
188  switch (std::abs(nb2)) {
189  case 72:
190  neighbour3 = (nb2 > 0 ? _hpds.find(1) : _hpds.find(-1));
191  break;
192  case 136:
193  neighbour3 = (nb2 > 0 ? _hpds.find(101) : _hpds.find(-101));
194  break;
195  default:
196  neighbour3 = (nb2 > 0 ? _hpds.find(nb2 + 1) : _hpds.find(nb2 - 1));
197  break;
198  }
199  } else {
200  neighbour3 = _hpds.end();
201  }
202 
203  size1 = neighbour1 != _hpds.end() ? neighbour1->second.size() : 0;
204  size2 = neighbour2 != _hpds.end() ? neighbour2->second.size() : 0;
205  if (size1 > 10) {
206  if ((abs(neighbour1->first) > 100 && neighbour1->second.size() > 15) ||
207  (abs(neighbour1->first) < 100 && neighbour1->second.size() > 12))
208  size1 = neighbour0 != _hpds.end() ? neighbour0->second.size() : 0;
209  }
210  if (size2 > 10) {
211  if ((abs(neighbour2->first) > 100 && neighbour2->second.size() > 15) ||
212  (abs(neighbour2->first) < 100 && neighbour2->second.size() > 12))
213  size2 = neighbour3 != _hpds.end() ? neighbour3->second.size() : 0;
214  }
215  if ((std::abs(ithpd.first) > 100 && ithpd.second.size() > 15) ||
216  (std::abs(ithpd.first) < 100 && ithpd.second.size() > 12)) {
217  if ((double)(size1 + size2) / (float)ithpd.second.size() < 1.0) {
218  unsigned nn = 0;
219  double threshold = 1.0;
220  for (const auto& itEn : theEnergies) {
221  if (nn < 5) {
222  mask[itEn.second] = false;
223  } else if (nn == 5) {
224  threshold = itEn.first * 2.5;
225  mask[itEn.second] = false;
226  } else {
227  if (itEn.first < threshold)
228  mask[itEn.second] = false;
229  }
230  }
231  }
232  }
233  }
234 }
pfDeepBoostedJetPreprocessParams_cfi.upper_bound
upper_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:16
mps_fire.i
i
Definition: mps_fire.py:428
input
static const std::string input
Definition: EdmProvDump.cc:48
RBXAndHPDCleaner.h
reco::PFRecHit::energy
float energy() const
rechit energy
Definition: PFRecHit.h:99
pos
Definition: PixelAliasList.h:18
PFLayer::HCAL_ENDCAP
Definition: PFLayer.h:37
edm::Handle< reco::PFRecHitCollection >
RBXAndHPDCleaner::clean
void clean(const edm::Handle< reco::PFRecHitCollection > &input, std::vector< bool > &mask) override
Definition: RBXAndHPDCleaner.cc:12
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
LEDCalibrationChannels.iphi
iphi
Definition: LEDCalibrationChannels.py:64
PFLayer::HCAL_BARREL1
Definition: PFLayer.h:35
HI_PhotonSkim_cff.rechits
rechits
Definition: HI_PhotonSkim_cff.py:76
dqmdumpme.k
k
Definition: dqmdumpme.py:60
b
double b
Definition: hdecay.h:118
phase1PixelTopology::layer
constexpr std::array< uint8_t, layerIndexSize > layer
Definition: phase1PixelTopology.h:99
RBXAndHPDCleaner::_hpds
std::unordered_map< int, std::vector< unsigned > > _hpds
Definition: RBXAndHPDCleaner.h:17
LEDCalibrationChannels.ieta
ieta
Definition: LEDCalibrationChannels.py:63
a
double a
Definition: hdecay.h:119
HcalDetId.h
HcalDetId
Definition: HcalDetId.h:12
reco::PFRecHit::neighbours4
Neighbours neighbours4() const
Definition: PFRecHit.h:81
groupFilesInBlocks.nn
nn
Definition: groupFilesInBlocks.py:150
reco::PFRecHit::detId
unsigned detId() const
rechit detId
Definition: PFRecHit.h:93
heppy_batch.val
val
Definition: heppy_batch.py:351
RBXAndHPDCleaner::_rbxs
std::unordered_map< int, std::vector< unsigned > > _rbxs
Definition: RBXAndHPDCleaner.h:17
reco::PFRecHit
Particle flow rechit (rechit + geometry and topology information). See clustering algorithm in PFClus...
Definition: PFRecHit.h:31
reco::PFRecHit::layer
PFLayer::Layer layer() const
rechit layer
Definition: PFRecHit.h:96
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
remoteMonitoring_LED_IterMethod_cfg.threshold
threshold
Definition: remoteMonitoring_LED_IterMethod_cfg.py:430