CMS 3D CMS Logo

LocalMaximumSeedFinder.cc
Go to the documentation of this file.
2 
3 #include <algorithm>
4 #include <queue>
5 #include <cfloat>
9 
10 namespace {
11  const reco::PFRecHit::Neighbours _noNeighbours(nullptr, 0);
12 }
13 
15  : SeedFinderBase(conf),
16  _nNeighbours(conf.getParameter<int>("nNeighbours")),
17  _layerMap({{"PS2", (int)PFLayer::PS2},
18  {"PS1", (int)PFLayer::PS1},
19  {"ECAL_ENDCAP", (int)PFLayer::ECAL_ENDCAP},
20  {"ECAL_BARREL", (int)PFLayer::ECAL_BARREL},
21  {"NONE", (int)PFLayer::NONE},
22  {"HCAL_BARREL1", (int)PFLayer::HCAL_BARREL1},
23  {"HCAL_BARREL2_RING0", (int)PFLayer::HCAL_BARREL2},
24  // hack to deal with ring1 in HO
25  {"HCAL_BARREL2_RING1", 19},
26  {"HCAL_ENDCAP", (int)PFLayer::HCAL_ENDCAP},
27  {"HF_EM", (int)PFLayer::HF_EM},
28  {"HF_HAD", (int)PFLayer::HF_HAD}}) {
29  const std::vector<edm::ParameterSet>& thresholds = conf.getParameterSetVector("thresholdsByDetector");
30  for (const auto& pset : thresholds) {
31  const std::string& det = pset.getParameter<std::string>("detector");
32 
33  std::vector<int> depths;
34  std::vector<double> thresh_E;
35  std::vector<double> thresh_pT;
36  std::vector<double> thresh_pT2;
37 
38  if (det == std::string("HCAL_BARREL1") || det == std::string("HCAL_ENDCAP")) {
39  depths = pset.getParameter<std::vector<int> >("depths");
40  thresh_E = pset.getParameter<std::vector<double> >("seedingThreshold");
41  thresh_pT = pset.getParameter<std::vector<double> >("seedingThresholdPt");
42  if (thresh_E.size() != depths.size() || thresh_pT.size() != depths.size()) {
43  throw cms::Exception("InvalidGatheringThreshold") << "gatheringThresholds mismatch with the numbers of depths";
44  }
45  } else {
46  depths.push_back(0);
47  thresh_E.push_back(pset.getParameter<double>("seedingThreshold"));
48  thresh_pT.push_back(pset.getParameter<double>("seedingThresholdPt"));
49  }
50 
51  for (unsigned int i = 0; i < thresh_pT.size(); ++i) {
52  thresh_pT2.push_back(thresh_pT[i] * thresh_pT[i]);
53  }
54 
55  auto entry = _layerMap.find(det);
56  if (entry == _layerMap.end()) {
57  throw cms::Exception("InvalidDetectorLayer") << "Detector layer : " << det << " is not in the list of recognized"
58  << " detector layers!";
59  }
60 
61  _thresholds[entry->second + layerOffset] = std::make_tuple(depths, thresh_E, thresh_pT2);
62  }
63 }
64 
65 // the starting state of seedable is all false!
67  const std::vector<bool>& mask,
68  std::vector<bool>& seedable) {
69  auto nhits = input->size();
70  initDynArray(bool, nhits, usable, true);
71  //need to run over energy sorted rechits
72  declareDynArray(float, nhits, energies);
73  unInitDynArray(int, nhits, qst); // queue storage
74  auto cmp = [&](int i, int j) { return energies[i] < energies[j]; };
75  std::priority_queue<int, DynArray<int>, decltype(cmp)> ordered_hits(cmp, std::move(qst));
76 
77  for (unsigned i = 0; i < nhits; ++i) {
78  if (!mask[i])
79  continue; // cannot seed masked objects
80  auto const& maybeseed = (*input)[i];
81  energies[i] = maybeseed.energy();
82  int seedlayer = (int)maybeseed.layer();
83  if (seedlayer == PFLayer::HCAL_BARREL2 && std::abs(maybeseed.positionREP().eta()) > 0.34) {
84  seedlayer = 19;
85  }
86  auto const& thresholds = _thresholds[seedlayer + layerOffset];
87 
88  double thresholdE = 0.;
89  double thresholdPT2 = 0.;
90 
91  for (unsigned int j = 0; j < (std::get<2>(thresholds)).size(); ++j) {
92  int depth = std::get<0>(thresholds)[j];
93  if ((seedlayer == PFLayer::HCAL_BARREL1 && maybeseed.depth() == depth) ||
94  (seedlayer == PFLayer::HCAL_ENDCAP && maybeseed.depth() == depth) ||
95  (seedlayer != PFLayer::HCAL_BARREL1 && seedlayer != PFLayer::HCAL_ENDCAP)) {
96  thresholdE = std::get<1>(thresholds)[j];
97  thresholdPT2 = std::get<2>(thresholds)[j];
98  }
99  }
100 
101  if (maybeseed.energy() < thresholdE || maybeseed.pt2() < thresholdPT2)
102  usable[i] = false;
103  if (!usable[i])
104  continue;
105  ordered_hits.push(i);
106  }
107 
108  while (!ordered_hits.empty()) {
109  auto idx = ordered_hits.top();
110  ordered_hits.pop();
111  if (!usable[idx])
112  continue;
113  //get the neighbours of this seed
114  auto const& maybeseed = (*input)[idx];
115  reco::PFRecHit::Neighbours myNeighbours;
116  switch (_nNeighbours) {
117  case -1:
118  myNeighbours = maybeseed.neighbours();
119  break;
120  case 0: // for HF clustering
121  myNeighbours = _noNeighbours;
122  break;
123  case 4:
124  myNeighbours = maybeseed.neighbours4();
125  break;
126  case 8:
127  myNeighbours = maybeseed.neighbours8();
128  break;
129  default:
130  throw cms::Exception("InvalidConfiguration") << "LocalMaximumSeedFinder only accepts nNeighbors = {-1,0,4,8}";
131  }
132  seedable[idx] = true;
133  for (auto neighbour : myNeighbours) {
134  if (!mask[neighbour])
135  continue;
136  if (energies[neighbour] > energies[idx]) {
137  // std::cout << "how this can be?" << std::endl;
138  seedable[idx] = false;
139  break;
140  }
141  }
142  if (seedable[idx]) {
143  for (auto neighbour : myNeighbours) {
144  //
145  // For HCAL,
146  // even if channel a is a neighbor of channel b, channel b may not be a neighbor of channel a.
147  // So, perform additional checks to ensure making a hit unusable for seeding is safe.
148  int seedlayer = (int)maybeseed.layer();
149  switch (seedlayer) {
152  case PFLayer::HF_EM: // with the current HF setting, we won't see this case
153  // but this can come in if we change _nNeighbours for HF.
154  case PFLayer::HF_HAD: // same as above
155  // HO has only one depth and eta-phi segmentation is regular, so no need to make this check
156  auto const& nei = (*input)[neighbour];
157  if (maybeseed.depth() != nei.depth())
158  continue; // masking is done only if the neighbor is on the same depth layer as the seed
159  if (std::abs(deltaPhi(maybeseed.positionREP().phi(), nei.positionREP().phi())) > dphicut &&
160  std::abs(maybeseed.positionREP().eta() - nei.positionREP().eta()) > detacut)
161  continue; // masking is done only if the neighbor is on the swiss-cross w.r.t. the seed
162  break;
163  }
164 
165  usable[neighbour] = false;
166 
167  } // for-loop
168  }
169  }
170 
171  LogDebug("LocalMaximumSeedFinder") << " found " << std::count(seedable.begin(), seedable.end(), true) << " seeds";
172 }
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
LocalMaximumSeedFinder::detacut
static constexpr double detacut
Definition: LocalMaximumSeedFinder.h:29
deltaPhi.h
mps_splice.entry
entry
Definition: mps_splice.py:68
PFLayer::HCAL_ENDCAP
Definition: PFLayer.h:37
LocalMaximumSeedFinder::dphicut
static constexpr double dphicut
Definition: LocalMaximumSeedFinder.h:30
initDynArray
#define initDynArray(T, n, x, i)
Definition: DynArray.h:94
edm::Handle< reco::PFRecHitCollection >
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
SiPixelRawToDigiRegional_cfi.deltaPhi
deltaPhi
Definition: SiPixelRawToDigiRegional_cfi.py:9
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:233
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:66
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:14
Exception
Definition: hltDiff.cc:245
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