CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
LocalMaximumSeedFinder.cc
Go to the documentation of this file.
2 
4 
5 namespace {
6  bool greaterByEnergy(const std::pair<unsigned,double>& a,
7  const std::pair<unsigned,double>& b) {
8  return a.second > b.second;
9  }
10 }
11 
14  SeedFinderBase(conf),
15  _nNeighbours(conf.getParameter<int>("nNeighbours")),
16  _layerMap({ {"PS2",(int)PFLayer::PS2},
17  {"PS1",(int)PFLayer::PS1},
18  {"ECAL_ENDCAP",(int)PFLayer::ECAL_ENDCAP},
19  {"ECAL_BARREL",(int)PFLayer::ECAL_BARREL},
20  {"NONE",(int)PFLayer::NONE},
21  {"HCAL_BARREL1",(int)PFLayer::HCAL_BARREL1},
22  {"HCAL_BARREL2_RING0",(int)PFLayer::HCAL_BARREL2},
23  // hack to deal with ring1 in HO
24  {"HCAL_BARREL2_RING1",100*(int)PFLayer::HCAL_BARREL2},
25  {"HCAL_ENDCAP",(int)PFLayer::HCAL_ENDCAP},
26  {"HF_EM",(int)PFLayer::HF_EM},
27  {"HF_HAD",(int)PFLayer::HF_HAD} }) {
28  const std::vector<edm::ParameterSet>& thresholds =
29  conf.getParameterSetVector("thresholdsByDetector");
30  for( const auto& pset : thresholds ) {
31  const std::string& det = pset.getParameter<std::string>("detector");
32  const double& thresh_E = pset.getParameter<double>("seedingThreshold");
33  const double& thresh_pT = pset.getParameter<double>("seedingThresholdPt");
34  const double thresh_pT2 = thresh_pT*thresh_pT;
35  auto entry = _layerMap.find(det);
36  if( entry == _layerMap.end() ) {
37  throw cms::Exception("InvalidDetectorLayer")
38  << "Detector layer : " << det << " is not in the list of recognized"
39  << " detector layers!";
40  }
41  _thresholds.emplace(_layerMap.find(det)->second,
42  std::make_pair(thresh_E,thresh_pT2));
43  }
44 }
45 
46 // the starting state of seedable is all false!
49  const std::vector<bool>& mask,
50  std::vector<bool>& seedable ) {
51  std::vector<bool> usable(input->size(),true);
52  //need to run over energy sorted rechits
53  std::vector<std::pair<unsigned,double> > ordered_hits;
54  ordered_hits.reserve(input->size());
55  for( unsigned i = 0; i < input->size(); ++i ) {
56  std::pair<unsigned,double> val = std::make_pair(i,input->at(i).energy());
57  auto pos = std::upper_bound(ordered_hits.begin(),ordered_hits.end(),
58  val, greaterByEnergy);
59  ordered_hits.insert(pos,val);
60  }
61 
62  for( const auto& idx_e : ordered_hits ) {
63  const unsigned idx = idx_e.first;
64  if( !mask[idx] ) continue; // cannot seed masked objects
65  const reco::PFRecHit& maybeseed = input->at(idx);
66  int seedlayer = (int)maybeseed.layer();
67  if( seedlayer == PFLayer::HCAL_BARREL2 &&
68  std::abs(maybeseed.positionREP().eta()) > 0.34 ) {
69  seedlayer *= 100;
70  }
71  const std::pair<double,double>& thresholds =
72  _thresholds.find(seedlayer)->second;
73  if( maybeseed.energy() < thresholds.first ||
74  maybeseed.pt2() < thresholds.second ) usable[idx] = false;
75  if( !usable[idx] ) continue;
76  //get the neighbours of this seed
77  const reco::PFRecHitRefVector* myNeighbours;
78  switch( _nNeighbours ) {
79  case -1:
80  myNeighbours = &maybeseed.neighbours();
81  break;
82  case 0: // for HF clustering
83  myNeighbours = &_noNeighbours;
84  break;
85  case 4:
86  myNeighbours = &maybeseed.neighbours4();
87  break;
88  case 8:
89  myNeighbours = &maybeseed.neighbours8();
90  break;
91  default:
92  throw cms::Exception("InvalidConfiguration")
93  << "LocalMaximumSeedFinder only accepts nNeighbors = {-1,0,4,8}";
94  }
95  seedable[idx] = true;
96  for( const reco::PFRecHitRef& neighbour : *myNeighbours ) {
97  if( !mask[neighbour.key()] ) continue;
98  if( neighbour->energy() > maybeseed.energy() ) {
99  seedable[idx] = false;
100  break;
101  }
102  }
103  if( seedable[idx] ) {
104  for( const reco::PFRecHitRef& neighbour : *myNeighbours ) {
105  usable[neighbour.key()] = false;
106  }
107  }
108  }
109 }
int i
Definition: DBlmapReader.cc:9
VParameterSet const & getParameterSetVector(std::string const &name) const
const std::unordered_map< std::string, int > _layerMap
void findSeeds(const edm::Handle< reco::PFRecHitCollection > &input, const std::vector< bool > &mask, std::vector< bool > &seedable)
double pt2() const
rechit momentum transverse to the beam, squared.
Definition: PFRecHit.h:122
const PFRecHitRefVector & neighbours4() const
Definition: PFRecHit.h:84
LocalMaximumSeedFinder(const edm::ParameterSet &conf)
static std::string const input
Definition: EdmProvDump.cc:44
PFLayer::Layer layer() const
rechit layer
Definition: PFRecHit.h:109
Particle flow rechit (rechit + geometry and topology information). See clustering algorithm in PFClus...
Definition: PFRecHit.h:35
std::unordered_map< int, std::pair< double, double > > _thresholds
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const PFRecHitRefVector & neighbours8() const
Definition: PFRecHit.h:87
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
double b
Definition: hdecay.h:120
double energy() const
rechit energy
Definition: PFRecHit.h:112
double a
Definition: hdecay.h:121
list entry
Definition: mps_splice.py:62
const REPPoint & positionREP() const
Definition: PFRecHit.h:133
static const reco::PFRecHitRefVector _noNeighbours
const PFRecHitRefVector & neighbours() const
Definition: PFRecHit.h:91