CMS 3D CMS Logo

PFClusterFromHGCalTrackster.cc
Go to the documentation of this file.
9 
11 public:
13  : InitialClusteringStepBase(conf, cc) {
14  filterByTracksterPID_ = conf.getParameter<bool>("filterByTracksterPID");
15  filterByTracksterIteration_ = conf.getParameter<bool>("filterByTracksterIteration");
16  pid_threshold_ = conf.getParameter<double>("pid_threshold");
17  filter_on_categories_ = conf.getParameter<std::vector<int> >("filter_on_categories");
18  filter_on_iterations_ = conf.getParameter<std::vector<int> >("filter_on_iterations");
19 
20  tracksterToken_ = cc.consumes<std::vector<ticl::Trackster> >(conf.getParameter<edm::InputTag>("tracksterSrc"));
22  }
23 
27 
28  void updateEvent(const edm::Event&) final;
29 
31  const std::vector<bool>&,
32  const std::vector<bool>&,
34  const HcalPFCuts*) override;
35 
36 private:
40  std::vector<int> filter_on_categories_;
41  std::vector<int> filter_on_iterations_;
42 
45 
48 };
49 
51 
53  ev.getByToken(tracksterToken_, trackstersH_);
54  ev.getByToken(clusterToken_, clusterH_);
55 }
56 
58  const std::vector<bool>& rechitMask,
59  const std::vector<bool>& seedable,
61  const HcalPFCuts*) {
62  auto const& hits = *input;
63 
64  const auto& tracksters = *trackstersH_;
65  const auto& clusters = *clusterH_;
66 
67  // for quick indexing back to hit energy
68  std::unordered_map<uint32_t, size_t> detIdToIndex(hits.size());
69  for (uint32_t i = 0; i < hits.size(); ++i) {
70  detIdToIndex[hits[i].detId()] = i;
71  }
72 
73  for (const auto& tst : tracksters) {
74  // Skip empty tracksters
75  if (tst.vertices().empty()) {
76  continue;
77  }
78  // Filter using trackster PID
80  float probTotal = 0.0f;
81  for (int cat : filter_on_categories_) {
82  probTotal += tst.id_probabilities(cat);
83  }
84  if (probTotal < pid_threshold_) {
85  continue;
86  }
87  }
88 
90  std::find(filter_on_iterations_.begin(), filter_on_iterations_.end(), tst.ticlIteration()) ==
91  filter_on_iterations_.end()) {
92  continue;
93  }
94 
95  DetId seed;
96  double energy = 0.0, highest_energy = 0.0;
97  output.emplace_back();
98  reco::PFCluster& back = output.back();
99 
100  std::vector<std::pair<DetId, float> > hitsAndFractions;
101  int iLC = 0;
102  std::for_each(std::begin(tst.vertices()), std::end(tst.vertices()), [&](unsigned int lcId) {
103  const auto fraction = 1.f / tst.vertex_multiplicity(iLC++);
104  for (const auto& cell : clusters[lcId].hitsAndFractions()) {
105  hitsAndFractions.emplace_back(cell.first, cell.second * fraction);
106  }
107  });
108 
109  for (const auto& hAndF : hitsAndFractions) {
110  auto itr = detIdToIndex.find(hAndF.first);
111  if (itr == detIdToIndex.end()) {
112  continue; // hit wasn't saved in reco
113  }
114  auto ref = makeRefhit(input, itr->second);
115  assert(ref->detId() == hAndF.first.rawId());
116  const double hit_energy = hAndF.second * ref->energy();
117  energy += hit_energy;
118  back.addRecHitFraction(reco::PFRecHitFraction(ref, hAndF.second));
119  // TODO: the following logic to identify the seed of a cluster
120  // could be appropriate for the Run2 Ecal Calorimetric
121  // detector, but could be wrong for the HGCal one. This has to
122  // be reviewd.
123  if (hit_energy > highest_energy || highest_energy == 0.0) {
124  highest_energy = hit_energy;
125  seed = ref->detId();
126  }
127  } // end of hitsAndFractions
128 
129  if (!back.hitsAndFractions().empty()) {
130  back.setSeed(seed);
131  back.setEnergy(energy);
133  } else {
134  back.setSeed(0);
135  back.setEnergy(0.f);
136  }
137  } // end of loop over hgcalTracksters (3D)
138 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:210
reco::PFRecHitRef makeRefhit(const edm::Handle< reco::PFRecHitCollection > &h, const unsigned i) const
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
Definition: PFCluster.h:42
void buildClusters(const edm::Handle< reco::PFRecHitCollection > &, const std::vector< bool > &, const std::vector< bool > &, reco::PFClusterCollection &, const HcalPFCuts *) override
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
edm::Handle< reco::CaloClusterCollection > clusterH_
Fraction of a PFRecHit (rechits can be shared between several PFCluster&#39;s)
void setEnergy(double energy)
Definition: CaloCluster.h:136
void updateEvent(const edm::Event &) final
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
assert(be >=bs)
static std::string const input
Definition: EdmProvDump.cc:50
void setSeed(const DetId &id)
Definition: CaloCluster.h:146
PFClusterFromHGCalTrackster & operator=(const PFClusterFromHGCalTrackster &)=delete
edm::EDGetTokenT< reco::CaloClusterCollection > clusterToken_
def cat(path)
Definition: eostools.py:401
void setCorrectedEnergy(double cenergy)
Definition: CaloCluster.h:137
std::vector< CaloCluster > CaloClusterCollection
collection of CaloCluster objects
double f[11][100]
Definition: DetId.h:17
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
edm::Handle< std::vector< ticl::Trackster > > trackstersH_
edm::EDGetTokenT< std::vector< ticl::Trackster > > tracksterToken_
PFClusterFromHGCalTrackster(const edm::ParameterSet &conf, edm::ConsumesCollector &cc)