CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
RBXAndHPDCleaner Class Reference

#include <RBXAndHPDCleaner.h>

Inheritance diagram for RBXAndHPDCleaner:
RecHitTopologicalCleanerBase

Public Member Functions

void clean (const edm::Handle< reco::PFRecHitCollection > &input, std::vector< bool > &mask) override
 
RBXAndHPDCleaneroperator= (const RBXAndHPDCleaner &)=delete
 
 RBXAndHPDCleaner (const edm::ParameterSet &conf)
 
 RBXAndHPDCleaner (const RBXAndHPDCleaner &)=delete
 
- Public Member Functions inherited from RecHitTopologicalCleanerBase
const std::string & name () const
 
RecHitTopologicalCleanerBaseoperator= (const RecHitTopologicalCleanerBase &)=delete
 
 RecHitTopologicalCleanerBase (const edm::ParameterSet &conf)
 
 RecHitTopologicalCleanerBase (const RecHitTopologicalCleanerBase &)=delete
 
virtual void update (const edm::EventSetup &)
 
virtual ~RecHitTopologicalCleanerBase ()=default
 

Private Attributes

std::unordered_map< int, std::vector< unsigned > > _hpds
 
std::unordered_map< int, std::vector< unsigned > > _rbxs
 

Detailed Description

Definition at line 8 of file RBXAndHPDCleaner.h.

Constructor & Destructor Documentation

RBXAndHPDCleaner::RBXAndHPDCleaner ( const edm::ParameterSet conf)
inline

Definition at line 10 of file RBXAndHPDCleaner.h.

References clean(), input, RecoTauDiscriminantConfiguration::mask, and operator=().

10  :
RecHitTopologicalCleanerBase(const edm::ParameterSet &conf)
RBXAndHPDCleaner::RBXAndHPDCleaner ( const RBXAndHPDCleaner )
delete

Member Function Documentation

void RBXAndHPDCleaner::clean ( const edm::Handle< reco::PFRecHitCollection > &  input,
std::vector< bool > &  mask 
)
overridevirtual

Implements RecHitTopologicalCleanerBase.

Definition at line 15 of file RBXAndHPDCleaner.cc.

References _hpds, _rbxs, funct::abs(), reco::PFRecHit::detId(), reco::PFRecHit::energy(), PFLayer::HCAL_BARREL1, PFLayer::HCAL_ENDCAP, mps_fire::i, training_settings::idx, HcalDetId::ieta(), HcalDetId::iphi(), gen::k, reco::PFRecHit::layer(), reco::PFRecHit::neighbours4(), groupFilesInBlocks::nn, TrackInfoProducer_cfi::rechits, electronIdCutBased_cfi::threshold, pfDeepBoostedJetPreprocessParams_cfi::upper_bound, and heppy_batch::val.

Referenced by RBXAndHPDCleaner().

16  {
17  _hpds.clear(); _rbxs.clear();
18  //need to run over energy sorted rechits
19  std::vector<std::pair<unsigned,double> > ordered_hits;
20  ordered_hits.reserve(input->size());
21  for( unsigned i = 0; i < input->size(); ++i ) {
22  std::pair<unsigned,double> val = std::make_pair(i,input->at(i).energy());
23  auto pos = std::upper_bound(ordered_hits.begin(),ordered_hits.end(),
24  val, greaterByEnergy);
25  ordered_hits.insert(pos,val);
26  }
27 
28  for( const auto& idx_e : ordered_hits ) {
29  if( !mask[idx_e.first] ) continue;
30  const unsigned idx = idx_e.first;
31  const reco::PFRecHit& rechit = input->at(idx);
32  int layer = rechit.layer();
33  if ( layer != PFLayer::HCAL_BARREL1 && layer != PFLayer::HCAL_ENDCAP ) {
34  break;
35  }
36  HcalDetId theHcalDetId(rechit.detId());
37  int ieta = theHcalDetId.ieta();
38  int iphi = theHcalDetId.iphi();
39  int ihpd = 0, irbx = 0;
40  switch( layer ) {
42  ihpd = ( ieta < 0 ? -iphi : iphi );
43  irbx = ( ieta < 0 ? -(iphi+5)/4 : (iphi+5)/4 );
44  break;
46  ihpd = ( ieta < 0 ? -(iphi+1)/2-100 : (iphi+1)/2+100 );
47  irbx = ( ieta < 0 ? -(iphi+5)/4-20 : (iphi+5)/4+20 );
48  break;
49  default:
50  break;
51  }
52  switch( std::abs(irbx) ) {
53  case 19:
54  irbx = ( irbx < 0 ? -1 : 1 );
55  break;
56  case 39:
57  irbx = ( irbx < 0 ? -21 : 21 );
58  break;
59  default:
60  break;
61  }
62  _hpds[ihpd].push_back(idx);
63  _rbxs[irbx].push_back(idx);
64  }
65  // loop on the rbx's we found and clean RBX's with tons of rechits
66  // and lots of energy
67  std::unordered_map<int, std::vector<unsigned> > theHPDs;
68  std::unordered_multimap<double, unsigned> theEnergies;
69  for( const auto& itrbx : _rbxs ) {
70  if( ( std::abs(itrbx.first)<20 && itrbx.second.size() > 30 ) ||
71  ( std::abs(itrbx.first)>20 && itrbx.second.size() > 30 ) ) {
72  const std::vector<unsigned>& rechits = itrbx.second;
73  theHPDs.clear();
74  theEnergies.clear();
75  int nSeeds0 = rechits.size();
76  for( unsigned jh = 0; jh < rechits.size(); ++jh ) {
77  const reco::PFRecHit& rechit = (*input)[jh];
78  // check if rechit is a seed
79  unsigned nN = 0 ; // neighbours over threshold
80  bool isASeed = true;
81  auto const & neighbours4 = rechit.neighbours4();
82  for( auto k : neighbours4 ) {
83  auto const & neighbour = (*input)[k];
84  if( neighbour.energy() > rechit.energy() ) {
85  --nSeeds0;
86  isASeed = false;
87  break;
88  } else {
89  if( neighbour.energy() > 0.4 ) ++nN;
90  }
91  }
92  if ( isASeed && !nN ) --nSeeds0;
93 
94  HcalDetId theHcalDetId(rechit.detId());
95  int iphi = theHcalDetId.iphi();
96  switch( rechit.layer() ) {
98  theHPDs[iphi].push_back(rechits[jh]);
99  break;
101  theHPDs[(iphi-1)/2].push_back(rechits[jh]);
102  break;
103  default:
104  break;
105  }
106  const double rhenergy = rechit.energy();
107  theEnergies.emplace(rhenergy,rechits[jh]);
108  }
109  if( nSeeds0 > 6 ) {
110  unsigned nHPD15 = 0;
111  for( const auto& itHPD : theHPDs ) {
112  int hpdN = itHPD.first;
113  const std::vector<unsigned>& hpdHits = itHPD.second;
114  if( ( std::abs(hpdN) < 100 && hpdHits.size() > 14 ) ||
115  ( std::abs(hpdN) > 100 && hpdHits.size() > 14 ) ) ++nHPD15;
116  }
117  if( nHPD15 > 1 ) {
118  unsigned nn = 0;
119  double threshold = 1.0;
120  for( const auto& itEn : theEnergies ) {
121  ++nn;
122  if( nn< 5 ) {
123  mask[itEn.second] = false;
124  } else if ( nn == 5 ) {
125  threshold = itEn.first*5;
126  mask[itEn.second] = false;
127  } else {
128  if( itEn.first < threshold ) 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 ) mask[itEn.second] = false;
228  }
229  }
230  }
231  }
232  }
233 }
unsigned detId() const
rechit detId
Definition: PFRecHit.h:93
PFLayer::Layer layer() const
rechit layer
Definition: PFRecHit.h:96
Particle flow rechit (rechit + geometry and topology information). See clustering algorithm in PFClus...
Definition: PFRecHit.h:31
int ieta() const
get the cell ieta
Definition: HcalDetId.h:159
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
float energy() const
rechit energy
Definition: PFRecHit.h:99
std::unordered_map< int, std::vector< unsigned > > _hpds
int k[5][pyjets_maxn]
std::unordered_map< int, std::vector< unsigned > > _rbxs
int iphi() const
get the cell iphi
Definition: HcalDetId.h:161
Neighbours neighbours4() const
Definition: PFRecHit.h:81
RBXAndHPDCleaner& RBXAndHPDCleaner::operator= ( const RBXAndHPDCleaner )
delete

Referenced by RBXAndHPDCleaner().

Member Data Documentation

std::unordered_map<int,std::vector<unsigned> > RBXAndHPDCleaner::_hpds
private

Definition at line 19 of file RBXAndHPDCleaner.h.

Referenced by clean().

std::unordered_map<int,std::vector<unsigned> > RBXAndHPDCleaner::_rbxs
private

Definition at line 19 of file RBXAndHPDCleaner.h.

Referenced by clean().