CMS 3D CMS Logo

LocalMaximumSeedFinder.cc
Go to the documentation of this file.
2 
3 #include <algorithm>
4 #include <queue>
5 #include <cfloat>
8 
9 namespace {
10  const reco::PFRecHit::Neighbours _noNeighbours(nullptr, 0);
11 }
12 
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", 19},
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 = conf.getParameterSetVector("thresholdsByDetector");
29  for (const auto& pset : thresholds) {
30  const std::string& det = pset.getParameter<std::string>("detector");
31 
32  std::vector<int> depths;
33  std::vector<double> thresh_E;
34  std::vector<double> thresh_pT;
35  std::vector<double> thresh_pT2;
36 
37  if (det == std::string("HCAL_BARREL1") || det == std::string("HCAL_ENDCAP")) {
38  depths = pset.getParameter<std::vector<int> >("depths");
39  thresh_E = pset.getParameter<std::vector<double> >("seedingThreshold");
40  thresh_pT = pset.getParameter<std::vector<double> >("seedingThresholdPt");
41  if (thresh_E.size() != depths.size() || thresh_pT.size() != depths.size()) {
42  throw cms::Exception("InvalidGatheringThreshold") << "gatheringThresholds mismatch with the numbers of depths";
43  }
44  } else {
45  depths.push_back(0);
46  thresh_E.push_back(pset.getParameter<double>("seedingThreshold"));
47  thresh_pT.push_back(pset.getParameter<double>("seedingThresholdPt"));
48  }
49 
50  for (unsigned int i = 0; i < thresh_pT.size(); ++i) {
51  thresh_pT2.push_back(thresh_pT[i] * thresh_pT[i]);
52  }
53 
54  auto entry = _layerMap.find(det);
55  if (entry == _layerMap.end()) {
56  throw cms::Exception("InvalidDetectorLayer") << "Detector layer : " << det << " is not in the list of recognized"
57  << " detector layers!";
58  }
59 
60  _thresholds[entry->second + layerOffset] = std::make_tuple(depths, thresh_E, thresh_pT2);
61  }
62 }
63 
64 // the starting state of seedable is all false!
66  const std::vector<bool>& mask,
67  std::vector<bool>& seedable) {
68  auto nhits = input->size();
69  initDynArray(bool, nhits, usable, true);
70  //need to run over energy sorted rechits
71  declareDynArray(float, nhits, energies);
72  unInitDynArray(int, nhits, qst); // queue storage
73  auto cmp = [&](int i, int j) { return energies[i] < energies[j]; };
74  std::priority_queue<int, DynArray<int>, decltype(cmp)> ordered_hits(cmp, std::move(qst));
75 
76  for (unsigned i = 0; i < nhits; ++i) {
77  if (!mask[i])
78  continue; // cannot seed masked objects
79  auto const& maybeseed = (*input)[i];
80  energies[i] = maybeseed.energy();
81  int seedlayer = (int)maybeseed.layer();
82  if (seedlayer == PFLayer::HCAL_BARREL2 && std::abs(maybeseed.positionREP().eta()) > 0.34) {
83  seedlayer = 19;
84  }
85  auto const& thresholds = _thresholds[seedlayer + layerOffset];
86 
87  double thresholdE = 0.;
88  double thresholdPT2 = 0.;
89 
90  for (unsigned int j = 0; j < (std::get<2>(thresholds)).size(); ++j) {
91  int depth = std::get<0>(thresholds)[j];
92  if ((seedlayer == PFLayer::HCAL_BARREL1 && maybeseed.depth() == depth) ||
93  (seedlayer == PFLayer::HCAL_ENDCAP && maybeseed.depth() == depth) ||
94  (seedlayer != PFLayer::HCAL_BARREL1 && seedlayer != PFLayer::HCAL_ENDCAP)) {
95  thresholdE = std::get<1>(thresholds)[j];
96  thresholdPT2 = std::get<2>(thresholds)[j];
97  }
98  }
99 
100  if (maybeseed.energy() < thresholdE || maybeseed.pt2() < thresholdPT2)
101  usable[i] = false;
102  if (!usable[i])
103  continue;
104  ordered_hits.push(i);
105  }
106 
107  while (!ordered_hits.empty()) {
108  auto idx = ordered_hits.top();
109  ordered_hits.pop();
110  if (!usable[idx])
111  continue;
112  //get the neighbours of this seed
113  auto const& maybeseed = (*input)[idx];
114  reco::PFRecHit::Neighbours myNeighbours;
115  switch (_nNeighbours) {
116  case -1:
117  myNeighbours = maybeseed.neighbours();
118  break;
119  case 0: // for HF clustering
120  myNeighbours = _noNeighbours;
121  break;
122  case 4:
123  myNeighbours = maybeseed.neighbours4();
124  break;
125  case 8:
126  myNeighbours = maybeseed.neighbours8();
127  break;
128  default:
129  throw cms::Exception("InvalidConfiguration") << "LocalMaximumSeedFinder only accepts nNeighbors = {-1,0,4,8}";
130  }
131  seedable[idx] = true;
132  for (auto neighbour : myNeighbours) {
133  if (!mask[neighbour])
134  continue;
135  if (energies[neighbour] > energies[idx]) {
136  // std::cout << "how this can be?" << std::endl;
137  seedable[idx] = false;
138  break;
139  }
140  }
141  if (seedable[idx]) {
142  for (auto neighbour : myNeighbours) {
143  usable[neighbour] = false;
144  }
145  }
146  }
147 
148  LogDebug("LocalMaximumSeedFinder") << " found " << std::count(seedable.begin(), seedable.end(), true) << " seeds";
149 }
LocalMaximumSeedFinder.h
SeedFinderBase
Definition: SeedFinderBase.h:9
mps_fire.i
i
Definition: mps_fire.py:428
input
static const std::string input
Definition: EdmProvDump.cc:48
MessageLogger.h
LocalMaximumSeedFinder::layerOffset
static constexpr int layerOffset
Definition: LocalMaximumSeedFinder.h:27
particleFlowZeroSuppressionECAL_cff.thresholds
thresholds
Definition: particleFlowZeroSuppressionECAL_cff.py:31
mps_splice.entry
entry
Definition: mps_splice.py:68
PFLayer::HCAL_ENDCAP
Definition: PFLayer.h:37
initDynArray
#define initDynArray(T, n, x, i)
Definition: DynArray.h:94
edm::Handle
Definition: AssociativeIterator.h:50
PFLayer::ECAL_BARREL
Definition: PFLayer.h:33
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
PFLayer::PS1
Definition: PFLayer.h:31
PFLayer::HCAL_BARREL2
Definition: PFLayer.h:36
PFLayer::HF_EM
Definition: PFLayer.h:38
PFLayer::HCAL_BARREL1
Definition: PFLayer.h:35
declareDynArray
#define declareDynArray(T, n, x)
Definition: DynArray.h:91
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
PFLayer::NONE
Definition: PFLayer.h:34
nhits
Definition: HIMultiTrackSelector.h:42
LEDCalibrationChannels.depth
depth
Definition: LEDCalibrationChannels.py:65
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
PFLayer::HF_HAD
Definition: PFLayer.h:39
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
edm::ParameterSet
Definition: ParameterSet.h:47
LocalMaximumSeedFinder::_nNeighbours
const int _nNeighbours
Definition: LocalMaximumSeedFinder.h:20
createfilelist.int
int
Definition: createfilelist.py:10
LocalMaximumSeedFinder::findSeeds
void findSeeds(const edm::Handle< reco::PFRecHitCollection > &input, const std::vector< bool > &mask, std::vector< bool > &seedable) override
Definition: LocalMaximumSeedFinder.cc:65
DynArray.h
reco::PFRecHit::Neighbours
Definition: PFRecHit.h:39
HLT_FULL_cff.depths
depths
Definition: HLT_FULL_cff.py:13412
eostools.move
def move(src, dest)
Definition: eostools.py:511
fileCollector.cmp
cmp
Definition: fileCollector.py:125
LocalMaximumSeedFinder::LocalMaximumSeedFinder
LocalMaximumSeedFinder(const edm::ParameterSet &conf)
Definition: LocalMaximumSeedFinder.cc:13
Exception
Definition: hltDiff.cc:246
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
PFLayer::ECAL_ENDCAP
Definition: PFLayer.h:32
PFLayer::PS2
Definition: PFLayer.h:30
unInitDynArray
#define unInitDynArray(T, n, x)
Definition: DynArray.h:88
LocalMaximumSeedFinder::_thresholds
std::array< I3tuple, 35 > _thresholds
Definition: LocalMaximumSeedFinder.h:26
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443