CMS 3D CMS Logo

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

#include <SpikeAndDoubleSpikeCleaner.h>

Inheritance diagram for SpikeAndDoubleSpikeCleaner:
RecHitTopologicalCleanerBase

Classes

struct  spike_cleaning
 

Public Member Functions

void clean (const edm::Handle< reco::PFRecHitCollection > &input, std::vector< bool > &mask) override
 
SpikeAndDoubleSpikeCleaneroperator= (const SpikeAndDoubleSpikeCleaner &)=delete
 
 SpikeAndDoubleSpikeCleaner (const edm::ParameterSet &conf)
 
 SpikeAndDoubleSpikeCleaner (const SpikeAndDoubleSpikeCleaner &)=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 ~RecHitTopologicalCleanerBase ()=default
 

Private Attributes

const std::unordered_map< std::string, int > _layerMap
 
std::unordered_map< int, spike_cleaning_thresholds
 

Detailed Description

Definition at line 9 of file SpikeAndDoubleSpikeCleaner.h.

Constructor & Destructor Documentation

SpikeAndDoubleSpikeCleaner::SpikeAndDoubleSpikeCleaner ( const edm::ParameterSet conf)

Definition at line 62 of file SpikeAndDoubleSpikeCleaner.cc.

References SpikeAndDoubleSpikeCleaner::spike_cleaning::_doubleSpikeS6S2, SpikeAndDoubleSpikeCleaner::spike_cleaning::_doubleSpikeThresh, SpikeAndDoubleSpikeCleaner::spike_cleaning::_eneThreshMod, SpikeAndDoubleSpikeCleaner::spike_cleaning::_fracThreshMod, _layerMap, SpikeAndDoubleSpikeCleaner::spike_cleaning::_minS4S1_a, SpikeAndDoubleSpikeCleaner::spike_cleaning::_minS4S1_b, SpikeAndDoubleSpikeCleaner::spike_cleaning::_singleSpikeThresh, _thresholds, clean(), PFLayer::ECAL_BARREL, PFLayer::ECAL_ENDCAP, mps_splice::entry, Exception, PFLayer::HCAL_BARREL1, PFLayer::HCAL_BARREL2, PFLayer::HCAL_ENDCAP, PFLayer::HF_EM, PFLayer::HF_HAD, info(), createfilelist::int, PFLayer::NONE, PFLayer::PS1, PFLayer::PS2, muonDTDigis_cfi::pset, AlCaHLTBitMon_QueryRunRegistry::string, and particleFlowZeroSuppressionECAL_cff::thresholds.

62  :
64  _layerMap({ {"PS2",(int)PFLayer::PS2},
65  {"PS1",(int)PFLayer::PS1},
66  {"ECAL_ENDCAP",(int)PFLayer::ECAL_ENDCAP},
67  {"ECAL_BARREL",(int)PFLayer::ECAL_BARREL},
68  {"NONE",(int)PFLayer::NONE},
69  {"HCAL_BARREL1",(int)PFLayer::HCAL_BARREL1},
70  {"HCAL_BARREL2_RING0",(int)PFLayer::HCAL_BARREL2},
71  // hack to deal with ring1 in HO
72  {"HCAL_BARREL2_RING1",100*(int)PFLayer::HCAL_BARREL2},
73  {"HCAL_ENDCAP",(int)PFLayer::HCAL_ENDCAP},
74  {"HF_EM",(int)PFLayer::HF_EM},
75  {"HF_HAD",(int)PFLayer::HF_HAD} }) {
76  const std::vector<edm::ParameterSet>& thresholds =
77  conf.getParameterSetVector("cleaningByDetector");
78  for( const auto& pset : thresholds ) {
79  spike_cleaning info;
80  const std::string& det = pset.getParameter<std::string>("detector");
81  info._minS4S1_a = pset.getParameter<double>("minS4S1_a");
82  info._minS4S1_b = pset.getParameter<double>("minS4S1_b");
83  info._doubleSpikeS6S2 = pset.getParameter<double>("doubleSpikeS6S2");
84  info._eneThreshMod = pset.getParameter<double>("energyThresholdModifier");
85  info._fracThreshMod =
86  pset.getParameter<double>("fractionThresholdModifier");
87  info._doubleSpikeThresh = pset.getParameter<double>("doubleSpikeThresh");
88  info._singleSpikeThresh = pset.getParameter<double>("singleSpikeThresh");
89  auto entry = _layerMap.find(det);
90  if( entry == _layerMap.end() ) {
91  throw cms::Exception("InvalidDetectorLayer")
92  << "Detector layer : " << det << " is not in the list of recognized"
93  << " detector layers!";
94  }
95  _thresholds.emplace(_layerMap.find(det)->second,info);
96  }
97 }
VParameterSet const & getParameterSetVector(std::string const &name) const
static const TGPicture * info(bool iBackgroundIsBlack)
RecHitTopologicalCleanerBase(const edm::ParameterSet &conf)
std::unordered_map< int, spike_cleaning > _thresholds
const std::unordered_map< std::string, int > _layerMap
SpikeAndDoubleSpikeCleaner::SpikeAndDoubleSpikeCleaner ( const SpikeAndDoubleSpikeCleaner )
delete

Member Function Documentation

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

Implements RecHitTopologicalCleanerBase.

Definition at line 101 of file SpikeAndDoubleSpikeCleaner.cc.

References SpikeAndDoubleSpikeCleaner::spike_cleaning::_doubleSpikeS6S2, SpikeAndDoubleSpikeCleaner::spike_cleaning::_doubleSpikeThresh, SpikeAndDoubleSpikeCleaner::spike_cleaning::_eneThreshMod, SpikeAndDoubleSpikeCleaner::spike_cleaning::_fracThreshMod, SpikeAndDoubleSpikeCleaner::spike_cleaning::_minS4S1_a, SpikeAndDoubleSpikeCleaner::spike_cleaning::_minS4S1_b, SpikeAndDoubleSpikeCleaner::spike_cleaning::_singleSpikeThresh, _thresholds, funct::abs(), AlCaHLTBitMon_QueryRunRegistry::comp, reco::PFRecHit::detId(), PFLayer::ECAL_BARREL, reco::PFRecHit::energy(), RhoEtaPhi::eta(), PFLayer::HCAL_BARREL2, HcalForward, PFLayer::HF_EM, PFLayer::HF_HAD, hfClusterShapes_cfi::hits, mps_fire::i, training_settings::idx, HcalDetId::ieta(), recoMuon::in, input, createfilelist::int, HcalDetId::iphi(), gen::k, reco::PFRecHit::layer(), min(), reco::PFRecHit::neighbours4(), RhoEtaPhi::phi(), reco::PFRecHit::positionREP(), and DetId::rawId().

Referenced by SpikeAndDoubleSpikeCleaner().

102  {
103  //need to run over energy sorted rechits
104  auto const & hits = *input;
105  std::vector<unsigned > ordered_hits(hits.size());
106  for( unsigned i = 0; i < hits.size(); ++i ) ordered_hits[i]=i;
107  std::sort(ordered_hits.begin(),ordered_hits.end(),[&](unsigned i, unsigned j) { return hits[i].energy()>hits[j].energy();});
108 
109  for( const auto& idx : ordered_hits ) {
110  const unsigned i = idx;
111  if( !mask[i] ) continue; // don't need to re-mask things :-)
112  const reco::PFRecHit& rechit = hits[i];
113  int hitlayer = (int)rechit.layer();
114  if( hitlayer == PFLayer::HCAL_BARREL2 &&
115  std::abs(rechit.positionREP().eta()) > 0.34 ) {
116  hitlayer *= 100;
117  }
118  const spike_cleaning& clean = _thresholds.find(hitlayer)->second;
119  if( rechit.energy() < clean._singleSpikeThresh ) continue;
120 
121  //Fix needed for HF. Here, we find the (up to) five companion rechits
122  //to work in conjunction with the neighbours4() implementation below for the full HF surrounding energy
123  float compsumE = 0.0;
124  if ((hitlayer==PFLayer::HF_EM || hitlayer==PFLayer::HF_HAD)) {
125  int comp = 1;
126  if (hitlayer==PFLayer::HF_EM) comp = 2;
127  const HcalDetId& detid = (HcalDetId)rechit.detId();
128  int heta = detid.ieta();
129  int hphi = detid.iphi();
130 
131  //At eta>39, phi segmentation changes
132  int predphi =2;
133  if (std::abs(heta)>39) predphi=4;
134 
135  int curphiL = hphi-predphi;
136  int curphiH = hphi+predphi;
137 
138  //HcalDetId valid phi range (0-72)
139  while (curphiL<0) curphiL+=72;
140  while (curphiH>72) curphiH-=72;
141 
142  std::pair<std::vector<int>, std::vector<int>> phietas({heta,heta+1,heta-1,heta,heta},{hphi,hphi,hphi,curphiL,curphiH});
143 
144  std::vector<uint32_t> rawDetIds;
145  for(unsigned in=0;in<phietas.first.size();in++) {
146  HcalDetId tempID (HcalForward, phietas.first[in], phietas.second[in], comp);
147  rawDetIds.push_back(tempID.rawId());
148  }
149 
150  for( const auto& jdx : ordered_hits ) {
151  const unsigned j = jdx;
152  const reco::PFRecHit& matchrechit = hits[j];
153  for( const auto& iID : rawDetIds ) if (iID==matchrechit.detId())compsumE+=matchrechit.energy();
154  }
155  }
156  //End of fix needed for HF
157 
158  const double rhenergy = rechit.energy();
159  // single spike cleaning
160  auto const & neighbours4 = rechit.neighbours4();
161  double surroundingEnergy = compsumE;
162  for( auto k : neighbours4 ) {
163  if( !mask[k] ) continue;
164  auto const & neighbour = hits[k];
165  const double sum = neighbour.energy(); //energyUp is just rechit energy?
166  surroundingEnergy += sum;
167  }
168  // wannaBeSeed.energyUp()/wannaBeSeed.energy() : 1.;
169  // Fraction 1 is the balance between the hit and its neighbours
170  // from both layers
171  const double fraction1 = surroundingEnergy/rhenergy;
172  // removed spurious comments from old pfcluster algo...
173  // look there if you want more history
174  const double f1Cut = ( clean._minS4S1_a*std::log10(rechit.energy()) +
175  clean._minS4S1_b );
176  if( fraction1 < f1Cut ) {
177  const double eta = rechit.positionREP().eta();
178  const double aeta = std::abs(eta);
179  const double phi = rechit.positionREP().phi();
180  std::pair<double,double> dcr = dCrack(phi,eta);
181  const double dcrmin = ( rechit.layer() == PFLayer::ECAL_BARREL ?
182  std::min(dcr.first,dcr.second):
183  dcr.second );
184  if( aeta < 5.0 &&
185  ( (aeta < 2.85 && dcrmin > 1.0) ||
186  (rhenergy > clean._eneThreshMod*clean._singleSpikeThresh &&
187  fraction1 < f1Cut/clean._fracThreshMod ) ) ) {
188  mask[i] = false;
189  }
190  }//if initial fraction cut (single spike)
191  // double spike removal
192  if( mask[i] && rhenergy > clean._doubleSpikeThresh ) {
193  //Determine energy surrounding the seed and the most energetic neighbour
194  double surroundingEnergyi = 0.0;
195  double enmax = -999.0;
196  unsigned int mostEnergeticNeighbour=0;
197  auto const & neighbours4i = rechit.neighbours4();
198  for( auto k : neighbours4i ) {
199  if( !mask[k] ) continue;
200  auto const & neighbour = hits[k];
201  const double nenergy = neighbour.energy();
202  surroundingEnergyi += nenergy;
203  if( nenergy > enmax ) {
204  enmax = nenergy;
205  mostEnergeticNeighbour = k;
206  }
207  }
208  // is there an energetic neighbour
209  if( enmax > 0.0 ) {
210  double surroundingEnergyj = 0.0;
211  auto const & neighbours4j =
212  hits[mostEnergeticNeighbour].neighbours4();
213  for(auto k : neighbours4j ) {
214  //if( !mask[k] && k != i) continue; // leave out?
215  surroundingEnergyj += hits[k].energy();
216  }
217  // The energy surrounding the double spike candidate
218  const double surroundingEnergyFraction =
219  (surroundingEnergyi+surroundingEnergyj) /
220  (rechit.energy()+hits[mostEnergeticNeighbour].energy()) - 1.;
221  if ( surroundingEnergyFraction < clean._doubleSpikeS6S2 ) {
222  const double eta = rechit.positionREP().eta();
223  const double aeta = std::abs(eta);
224  const double phi = rechit.positionREP().phi();
225  std::pair<double,double> dcr = dCrack(phi,eta);
226  const double dcrmin = ( rechit.layer() == PFLayer::ECAL_BARREL ?
227  std::min(dcr.first,dcr.second):
228  dcr.second );
229  if( aeta < 5.0 &&
230  ( (aeta < 2.85 && dcrmin > 1.0) ||
231  (rhenergy > clean._eneThreshMod*clean._doubleSpikeThresh &&
232  surroundingEnergyFraction < clean._doubleSpikeS6S2/clean._fracThreshMod )
233  ) ) {
234  mask[i] = false;
235  mask[mostEnergeticNeighbour] = false;
236  }
237  }
238  } // was there an energetic neighbour ?
239  }// if double spike thresh
240  } // rechit loop
241 }
float phi() const
momentum azimuthal angle
Definition: PtEtaPhiMass.h:53
unsigned detId() const
rechit detId
Definition: PFRecHit.h:108
void clean(const edm::Handle< reco::PFRecHitCollection > &input, std::vector< bool > &mask) override
static std::string const input
Definition: EdmProvDump.cc:44
PFLayer::Layer layer() const
rechit layer
Definition: PFRecHit.h:111
U second(std::pair< T, U > const &p)
Particle flow rechit (rechit + geometry and topology information). See clustering algorithm in PFClus...
Definition: PFRecHit.h:32
int ieta() const
get the cell ieta
Definition: HcalDetId.h:56
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
T min(T a, T b)
Definition: MathUtil.h:58
float energy() const
rechit energy
Definition: PFRecHit.h:114
int k[5][pyjets_maxn]
int iphi() const
get the cell iphi
Definition: HcalDetId.cc:103
std::unordered_map< int, spike_cleaning > _thresholds
float eta() const
momentum pseudorapidity
Definition: PtEtaPhiMass.h:51
Neighbours neighbours4() const
Definition: PFRecHit.h:87
RhoEtaPhi const & positionREP() const
Definition: PFRecHit.h:131
SpikeAndDoubleSpikeCleaner& SpikeAndDoubleSpikeCleaner::operator= ( const SpikeAndDoubleSpikeCleaner )
delete

Member Data Documentation

const std::unordered_map<std::string,int> SpikeAndDoubleSpikeCleaner::_layerMap
private

Definition at line 30 of file SpikeAndDoubleSpikeCleaner.h.

Referenced by SpikeAndDoubleSpikeCleaner().

std::unordered_map<int,spike_cleaning> SpikeAndDoubleSpikeCleaner::_thresholds
private

Definition at line 31 of file SpikeAndDoubleSpikeCleaner.h.

Referenced by clean(), and SpikeAndDoubleSpikeCleaner().