CMS 3D CMS Logo

List of all members | Public Member Functions | Private Types | Private Attributes | Static Private Attributes
LocalMaximumSeedFinder Class Referencefinal
Inheritance diagram for LocalMaximumSeedFinder:
SeedFinderBase

Public Member Functions

void findSeeds (const edm::Handle< reco::PFRecHitCollection > &input, const std::vector< bool > &mask, std::vector< bool > &seedable, const HcalPFCuts *) override
 
 LocalMaximumSeedFinder (const edm::ParameterSet &conf)
 
 LocalMaximumSeedFinder (const LocalMaximumSeedFinder &)=delete
 
LocalMaximumSeedFinderoperator= (const LocalMaximumSeedFinder &)=delete
 
- Public Member Functions inherited from SeedFinderBase
const std::string & name () const
 
SeedFinderBaseoperator= (const SeedFinderBase &)=delete
 
 SeedFinderBase (const edm::ParameterSet &conf)
 
 SeedFinderBase (const SeedFinderBase &)=delete
 
virtual ~SeedFinderBase ()=default
 

Private Types

typedef std::tuple< std::vector< int >, std::vector< double >, std::vector< double > > I3tuple
 

Private Attributes

const std::unordered_map< std::string, int > _layerMap
 
const int _nNeighbours
 
std::array< I3tuple, 35 > _thresholds
 

Static Private Attributes

static constexpr double detacut = 0.01
 
static constexpr double dphicut = 0.01
 
static constexpr int layerOffset = 15
 

Detailed Description

Definition at line 14 of file LocalMaximumSeedFinder.cc.

Member Typedef Documentation

◆ I3tuple

typedef std::tuple<std::vector<int>, std::vector<double>, std::vector<double> > LocalMaximumSeedFinder::I3tuple
private

Definition at line 30 of file LocalMaximumSeedFinder.cc.

Constructor & Destructor Documentation

◆ LocalMaximumSeedFinder() [1/2]

LocalMaximumSeedFinder::LocalMaximumSeedFinder ( const edm::ParameterSet conf)

Definition at line 45 of file LocalMaximumSeedFinder.cc.

References PFLayer::ECAL_BARREL, PFLayer::ECAL_ENDCAP, PFLayer::HCAL_BARREL1, PFLayer::HCAL_BARREL2, PFLayer::HCAL_ENDCAP, PFLayer::HF_EM, PFLayer::HF_HAD, createfilelist::int, PFLayer::NONE, PFLayer::PS1, and PFLayer::PS2.

46  : SeedFinderBase(conf),
47  _nNeighbours(conf.getParameter<int>("nNeighbours")),
48  _layerMap({{"PS2", (int)PFLayer::PS2},
49  {"PS1", (int)PFLayer::PS1},
50  {"ECAL_ENDCAP", (int)PFLayer::ECAL_ENDCAP},
51  {"ECAL_BARREL", (int)PFLayer::ECAL_BARREL},
52  {"NONE", (int)PFLayer::NONE},
53  {"HCAL_BARREL1", (int)PFLayer::HCAL_BARREL1},
54  {"HCAL_BARREL2_RING0", (int)PFLayer::HCAL_BARREL2},
55  // hack to deal with ring1 in HO
56  {"HCAL_BARREL2_RING1", 19},
57  {"HCAL_ENDCAP", (int)PFLayer::HCAL_ENDCAP},
58  {"HF_EM", (int)PFLayer::HF_EM},
59  {"HF_HAD", (int)PFLayer::HF_HAD}}) {
60  const std::vector<edm::ParameterSet>& thresholds = conf.getParameterSetVector("thresholdsByDetector");
61  for (const auto& pset : thresholds) {
62  const std::string& det = pset.getParameter<std::string>("detector");
63  std::vector<int> depths;
64  std::vector<double> thresh_E;
65  std::vector<double> thresh_pT;
66  std::vector<double> thresh_pT2;
67 
68  if (det == std::string("HCAL_BARREL1") || det == std::string("HCAL_ENDCAP")) {
69  depths = pset.getParameter<std::vector<int> >("depths");
70  thresh_E = pset.getParameter<std::vector<double> >("seedingThreshold");
71  thresh_pT = pset.getParameter<std::vector<double> >("seedingThresholdPt");
72  if (thresh_E.size() != depths.size() || thresh_pT.size() != depths.size()) {
73  throw cms::Exception("InvalidGatheringThreshold") << "gatheringThresholds mismatch with the numbers of depths";
74  }
75  } else {
76  depths.push_back(0);
77  thresh_E.push_back(pset.getParameter<double>("seedingThreshold"));
78  thresh_pT.push_back(pset.getParameter<double>("seedingThresholdPt"));
79  }
80 
81  for (unsigned int i = 0; i < thresh_pT.size(); ++i) {
82  thresh_pT2.push_back(thresh_pT[i] * thresh_pT[i]);
83  }
84 
85  auto entry = _layerMap.find(det);
86  if (entry == _layerMap.end()) {
87  throw cms::Exception("InvalidDetectorLayer") << "Detector layer : " << det << " is not in the list of recognized"
88  << " detector layers!";
89  }
90 
91  _thresholds[entry->second + layerOffset] = std::make_tuple(depths, thresh_E, thresh_pT2);
92  }
93 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::array< I3tuple, 35 > _thresholds
static constexpr int layerOffset
VParameterSet const & getParameterSetVector(std::string const &name) const
const std::unordered_map< std::string, int > _layerMap
SeedFinderBase(const edm::ParameterSet &conf)

◆ LocalMaximumSeedFinder() [2/2]

LocalMaximumSeedFinder::LocalMaximumSeedFinder ( const LocalMaximumSeedFinder )
delete

Member Function Documentation

◆ findSeeds()

void LocalMaximumSeedFinder::findSeeds ( const edm::Handle< reco::PFRecHitCollection > &  input,
const std::vector< bool > &  mask,
std::vector< bool > &  seedable,
const HcalPFCuts hcalCuts 
)
overridevirtual

Implements SeedFinderBase.

Definition at line 96 of file LocalMaximumSeedFinder.cc.

References _nNeighbours, _thresholds, funct::abs(), fileCollector::cmp, submitPVResolutionJobs::count, declareDynArray, SiPixelRawToDigiRegional_cfi::deltaPhi, hcalRecHitTable_cff::depth, detacut, dphicut, Exception, HcalCondObjectContainer< Item >::getValues(), PFLayer::HCAL_BARREL1, PFLayer::HCAL_BARREL2, PFLayer::HCAL_ENDCAP, PFLayer::HF_EM, PFLayer::HF_HAD, mps_fire::i, heavyIonCSV_trainingSettings::idx, initDynArray, input, createfilelist::int, B2GTnPMonitor_cfi::item, dqmiolumiharvest::j, layerOffset, LogDebug, ALPAKA_ACCELERATOR_NAMESPACE::pixelClustering::pixelStatus::mask, eostools::move(), TrackingDataMCValidation_Standalone_cff::nhits, DetId::rawId(), particleFlowZeroSuppressionECAL_cff::thresholds, and unInitDynArray.

99  {
100  auto nhits = input->size();
101  initDynArray(bool, nhits, usable, true);
102  //need to run over energy sorted rechits
103  declareDynArray(float, nhits, energies);
104  unInitDynArray(int, nhits, qst); // queue storage
105  auto cmp = [&](int i, int j) { return energies[i] < energies[j]; };
106  std::priority_queue<int, DynArray<int>, decltype(cmp)> ordered_hits(cmp, std::move(qst));
107 
108  for (unsigned i = 0; i < nhits; ++i) {
109  if (!mask[i])
110  continue; // cannot seed masked objects
111  auto const& maybeseed = (*input)[i];
112  energies[i] = maybeseed.energy();
113  int seedlayer = (int)maybeseed.layer();
114  if (seedlayer == PFLayer::HCAL_BARREL2 && std::abs(maybeseed.positionREP().eta()) > 0.34) {
115  seedlayer = 19;
116  }
117  auto const& thresholds = _thresholds[seedlayer + layerOffset];
118 
119  double thresholdE = 0.;
120  double thresholdPT2 = 0.;
121 
122  for (unsigned int j = 0; j < (std::get<2>(thresholds)).size(); ++j) {
123  int depth = std::get<0>(thresholds)[j];
124  if ((seedlayer == PFLayer::HCAL_BARREL1 && maybeseed.depth() == depth) ||
125  (seedlayer == PFLayer::HCAL_ENDCAP && maybeseed.depth() == depth) ||
126  (seedlayer != PFLayer::HCAL_BARREL1 && seedlayer != PFLayer::HCAL_ENDCAP)) {
127  thresholdE = std::get<1>(thresholds)[j];
128  thresholdPT2 = std::get<2>(thresholds)[j];
129  }
130  }
131 
132  if (hcalCuts != nullptr) { // this means, cutsFromDB is set to True in PFClusterProducer.cc
133  if ((seedlayer == PFLayer::HCAL_BARREL1) || (seedlayer == PFLayer::HCAL_ENDCAP)) {
134  HcalDetId thisId = maybeseed.detId();
135  const HcalPFCut* item = hcalCuts->getValues(thisId.rawId());
136  thresholdE = item->seedThreshold();
137  }
138  }
139 
140  if (maybeseed.energy() < thresholdE || maybeseed.pt2() < thresholdPT2)
141  usable[i] = false;
142  if (!usable[i])
143  continue;
144  ordered_hits.push(i);
145  }
146 
147  while (!ordered_hits.empty()) {
148  auto idx = ordered_hits.top();
149  ordered_hits.pop();
150  if (!usable[idx])
151  continue;
152  //get the neighbours of this seed
153  auto const& maybeseed = (*input)[idx];
154  reco::PFRecHit::Neighbours myNeighbours;
155  switch (_nNeighbours) {
156  case -1:
157  myNeighbours = maybeseed.neighbours();
158  break;
159  case 0: // for HF clustering
160  myNeighbours = _noNeighbours;
161  break;
162  case 4:
163  myNeighbours = maybeseed.neighbours4();
164  break;
165  case 8:
166  myNeighbours = maybeseed.neighbours8();
167  break;
168  default:
169  throw cms::Exception("InvalidConfiguration") << "LocalMaximumSeedFinder only accepts nNeighbors = {-1,0,4,8}";
170  }
171  seedable[idx] = true;
172  for (auto neighbour : myNeighbours) {
173  if (!mask[neighbour])
174  continue;
175  if (energies[neighbour] > energies[idx]) {
176  // std::cout << "how this can be?" << std::endl;
177  seedable[idx] = false;
178  break;
179  }
180  }
181  if (seedable[idx]) {
182  for (auto neighbour : myNeighbours) {
183  //
184  // For HCAL,
185  // even if channel a is a neighbor of channel b, channel b may not be a neighbor of channel a.
186  // So, perform additional checks to ensure making a hit unusable for seeding is safe.
187  int seedlayer = (int)maybeseed.layer();
188  switch (seedlayer) {
191  case PFLayer::HF_EM: // with the current HF setting, we won't see this case
192  // but this can come in if we change _nNeighbours for HF.
193  case PFLayer::HF_HAD: // same as above
194  // HO has only one depth and eta-phi segmentation is regular, so no need to make this check
195  auto const& nei = (*input)[neighbour];
196  if (maybeseed.depth() != nei.depth())
197  continue; // masking is done only if the neighbor is on the same depth layer as the seed
198  if (std::abs(deltaPhi(maybeseed.positionREP().phi(), nei.positionREP().phi())) > dphicut &&
199  std::abs(maybeseed.positionREP().eta() - nei.positionREP().eta()) > detacut)
200  continue; // masking is done only if the neighbor is on the swiss-cross w.r.t. the seed
201  break;
202  }
203 
204  usable[neighbour] = false;
205 
206  } // for-loop
207  }
208  }
209 
210  LogDebug("LocalMaximumSeedFinder") << " found " << std::count(seedable.begin(), seedable.end(), true) << " seeds";
211 }
#define initDynArray(T, n, x, i)
Definition: DynArray.h:94
const Item * getValues(DetId fId, bool throwOnFail=true) const
static std::string const input
Definition: EdmProvDump.cc:50
std::array< I3tuple, 35 > _thresholds
#define unInitDynArray(T, n, x)
Definition: DynArray.h:88
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static constexpr int layerOffset
static constexpr double detacut
static constexpr double dphicut
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
#define declareDynArray(T, n, x)
Definition: DynArray.h:91
def move(src, dest)
Definition: eostools.py:511
#define LogDebug(id)

◆ operator=()

LocalMaximumSeedFinder& LocalMaximumSeedFinder::operator= ( const LocalMaximumSeedFinder )
delete

Member Data Documentation

◆ _layerMap

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

Definition at line 28 of file LocalMaximumSeedFinder.cc.

◆ _nNeighbours

const int LocalMaximumSeedFinder::_nNeighbours
private

Definition at line 26 of file LocalMaximumSeedFinder.cc.

Referenced by findSeeds().

◆ _thresholds

std::array<I3tuple, 35> LocalMaximumSeedFinder::_thresholds
private

Definition at line 32 of file LocalMaximumSeedFinder.cc.

Referenced by findSeeds().

◆ detacut

constexpr double LocalMaximumSeedFinder::detacut = 0.01
staticprivate

Definition at line 35 of file LocalMaximumSeedFinder.cc.

Referenced by findSeeds().

◆ dphicut

constexpr double LocalMaximumSeedFinder::dphicut = 0.01
staticprivate

Definition at line 36 of file LocalMaximumSeedFinder.cc.

Referenced by findSeeds().

◆ layerOffset

constexpr int LocalMaximumSeedFinder::layerOffset = 15
staticprivate

Definition at line 33 of file LocalMaximumSeedFinder.cc.

Referenced by findSeeds().