CMS 3D CMS Logo

Basic2DGenericTopoClusterizer.cc
Go to the documentation of this file.
6 
9 
10 public:
12  : InitialClusteringStepBase(conf, cc), _useCornerCells(conf.getParameter<bool>("useCornerCells")) {}
13  ~Basic2DGenericTopoClusterizer() override = default;
14  Basic2DGenericTopoClusterizer(const B2DGT&) = delete;
15  B2DGT& operator=(const B2DGT&) = delete;
16 
18  const std::vector<bool>&,
19  const std::vector<bool>&,
21  const HcalPFCuts*) override;
22 
23 private:
24  const bool _useCornerCells;
26  const std::vector<bool>&, // masked rechits
27  unsigned int, //present rechit
28  std::vector<bool>&, // hit usage state
29  reco::PFCluster&, // the topocluster
30  const HcalPFCuts*);
31 };
32 
34 
35 #ifdef PFLOW_DEBUG
36 #define LOGVERB(x) edm::LogVerbatim(x)
37 #define LOGWARN(x) edm::LogWarning(x)
38 #define LOGERR(x) edm::LogError(x)
39 #define LOGDRESSED(x) edm::LogInfo(x)
40 #else
41 #define LOGVERB(x) LogTrace(x)
42 #define LOGWARN(x) edm::LogWarning(x)
43 #define LOGERR(x) edm::LogError(x)
44 #define LOGDRESSED(x) LogDebug(x)
45 #endif
46 
48  const std::vector<bool>& rechitMask,
49  const std::vector<bool>& seedable,
51  const HcalPFCuts* hcalCuts) {
52  auto const& hits = *input;
53  std::vector<bool> used(hits.size(), false);
54  std::vector<unsigned int> seeds;
55 
56  // get the seeds and sort them descending in energy
57  seeds.reserve(hits.size());
58  for (unsigned int i = 0; i < hits.size(); ++i) {
59  if (!rechitMask[i] || !seedable[i] || used[i])
60  continue;
61  seeds.emplace_back(i);
62  }
63  // maxHeap would be better
64  std::sort(
65  seeds.begin(), seeds.end(), [&](unsigned int i, unsigned int j) { return hits[i].energy() > hits[j].energy(); });
66 
68  for (auto seed : seeds) {
69  if (!rechitMask[seed] || !seedable[seed] || used[seed])
70  continue;
71  temp.reset();
72  buildTopoCluster(input, rechitMask, seed, used, temp, hcalCuts);
73  if (!temp.recHitFractions().empty())
74  output.push_back(temp);
75  }
76 }
77 
79  const std::vector<bool>& rechitMask,
80  unsigned int kcell,
81  std::vector<bool>& used,
82  reco::PFCluster& topocluster,
83  const HcalPFCuts* hcalCuts) {
84  auto const& cell = (*input)[kcell];
85  int cell_layer = (int)cell.layer();
86  if (cell_layer == PFLayer::HCAL_BARREL2 && std::abs(cell.positionREP().eta()) > 0.34) {
87  cell_layer *= 100;
88  }
89 
90  auto const& thresholds = _thresholds.find(cell_layer)->second;
91  double thresholdE = 0.;
92  double thresholdPT2 = 0.;
93 
94  for (unsigned int j = 0; j < (std::get<1>(thresholds)).size(); ++j) {
95  int depth = std::get<0>(thresholds)[j];
96 
97  if ((cell_layer == PFLayer::HCAL_BARREL1 && cell.depth() == depth) ||
98  (cell_layer == PFLayer::HCAL_ENDCAP && cell.depth() == depth) ||
99  (cell_layer != PFLayer::HCAL_BARREL1 && cell_layer != PFLayer::HCAL_ENDCAP)) {
100  thresholdE = std::get<1>(thresholds)[j];
101  thresholdPT2 = std::get<2>(thresholds)[j];
102  }
103  }
104 
105  if (hcalCuts != nullptr) { // this means, cutsFromDB is set to True in PFClusterProducer.cc
106  if ((cell_layer == PFLayer::HCAL_BARREL1) || (cell_layer == PFLayer::HCAL_ENDCAP)) {
107  HcalDetId thisId = cell.detId();
108  const HcalPFCut* item = hcalCuts->getValues(thisId.rawId());
109  thresholdE = item->noiseThreshold();
110  }
111  }
112 
113  if (cell.energy() < thresholdE || cell.pt2() < thresholdPT2) {
114  LOGDRESSED("GenericTopoCluster::buildTopoCluster()")
115  << "RecHit " << cell.detId() << " with enegy " << cell.energy() << " GeV was rejected!." << std::endl;
116  return;
117  }
118 
119  auto k = kcell;
120  used[k] = true;
121  auto ref = makeRefhit(input, k);
122  topocluster.addRecHitFraction(reco::PFRecHitFraction(ref, 1.0));
123 
124  auto const& neighbours = (_useCornerCells ? cell.neighbours8() : cell.neighbours4());
125 
126  for (auto nb : neighbours) {
127  if (used[nb] || !rechitMask[nb]) {
128  LOGDRESSED("GenericTopoCluster::buildTopoCluster()")
129  << " RecHit " << cell.detId() << "\'s"
130  << " neighbor RecHit " << input->at(nb).detId() << " with enegy " << input->at(nb).energy()
131  << " GeV was rejected!"
132  << " Reasons : " << used[nb] << " (used) " << !rechitMask[nb] << " (masked)." << std::endl;
133  continue;
134  }
135  buildTopoCluster(input, rechitMask, nb, used, topocluster, hcalCuts);
136  }
137 }
reco::PFRecHitRef makeRefhit(const edm::Handle< reco::PFRecHitCollection > &h, const unsigned i) const
~Basic2DGenericTopoClusterizer() override=default
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
Definition: PFCluster.h:42
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
Fraction of a PFRecHit (rechits can be shared between several PFCluster&#39;s)
Basic2DGenericTopoClusterizer B2DGT
void buildTopoCluster(const edm::Handle< reco::PFRecHitCollection > &, const std::vector< bool > &, unsigned int, std::vector< bool > &, reco::PFCluster &, const HcalPFCuts *)
const Item * getValues(DetId fId, bool throwOnFail=true) const
static std::string const input
Definition: EdmProvDump.cc:50
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Basic2DGenericTopoClusterizer(const edm::ParameterSet &conf, edm::ConsumesCollector &cc)
void buildClusters(const edm::Handle< reco::PFRecHitCollection > &, const std::vector< bool > &, const std::vector< bool > &, reco::PFClusterCollection &, const HcalPFCuts *) override
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
void addRecHitFraction(const reco::PFRecHitFraction &frac)
add a given fraction of the rechit
Definition: PFCluster.cc:33
std::vector< PFCluster > PFClusterCollection
collection of PFCluster objects
Definition: PFClusterFwd.h:9
#define DEFINE_EDM_PLUGIN(factory, type, name)
Definition: output.py:1
B2DGT & operator=(const B2DGT &)=delete
#define LOGDRESSED(x)
std::unordered_map< int, I3tuple > _thresholds