8 #include "Math/GenVector/VectorUtil.h"
9 #include "vdt/vdtMath.h"
12 #include <unordered_map>
33 const std::vector<bool>&,
42 const std::unordered_map<std::string, int>
_layerMap;
51 const std::vector<bool>&,
52 const unsigned toleranceScaling,
63 #define LOGVERB(x) edm::LogVerbatim(x)
64 #define LOGWARN(x) edm::LogWarning(x)
65 #define LOGERR(x) edm::LogError(x)
66 #define LOGDRESSED(x) edm::LogInfo(x)
68 #define LOGVERB(x) LogTrace(x)
69 #define LOGWARN(x) edm::LogWarning(x)
70 #define LOGERR(x) edm::LogError(x)
71 #define LOGDRESSED(x) LogDebug(x)
77 _maxIterations(conf.getParameter<unsigned>(
"maxIterations")),
78 _stoppingTolerance(conf.getParameter<double>(
"stoppingTolerance")),
79 _showerSigma2(std::
pow(conf.getParameter<double>(
"showerSigma"), 2.0)),
80 _excludeOtherSeeds(conf.getParameter<bool>(
"excludeOtherSeeds")),
81 _minFracTot(conf.getParameter<double>(
"minFracTot")),
94 for (
const auto&
pset : thresholds) {
97 std::vector<int> depths;
98 std::vector<double> rhE_norm;
101 depths =
pset.getParameter<std::vector<int> >(
"depths");
102 rhE_norm =
pset.getParameter<std::vector<double> >(
"recHitEnergyNorm");
105 rhE_norm.push_back(
pset.getParameter<
double>(
"recHitEnergyNorm"));
108 if (rhE_norm.size() != depths.size()) {
110 <<
"PFlowClusterizerThreshold mismatch with the numbers of depths";
115 throw cms::Exception(
"InvalidDetectorLayer") <<
"Detector layer : " << det <<
" is not in the list of recognized"
116 <<
" detector layers!";
121 if (conf.
exists(
"allCellsPositionCalc")) {
127 if (conf.
exists(
"positionCalcForConvergence")) {
135 const std::vector<bool>& seedable,
138 for (
const auto& topocluster : input) {
139 clustersInTopo.clear();
141 const unsigned tolScal =
std::pow(
std::max(1.0, clustersInTopo.size() - 1.0), 2.0);
142 growPFClusters(topocluster, seedable, tolScal, 0, tolScal, clustersInTopo);
158 for (
auto& clusterout : clustersInTopo) {
159 output.insert(output.end(),
std::move(clusterout));
165 const std::vector<bool>& seedable,
168 for (
const auto& rhf : recHitFractions) {
169 if (!seedable[rhf.recHitRef().key()])
174 current.
setSeed(rhf.recHitRef()->detId());
184 const std::vector<bool>& seedable,
185 const unsigned toleranceScaling,
190 LOGDRESSED(
"Basic2DGenericPFlowClusterizer:growAndStabilizePFClusters")
191 <<
"reached " <<
_maxIterations <<
" iterations, terminated position "
192 <<
"fit with diff = " <<
diff;
197 std::vector<reco::PFCluster::REPPoint> clus_prev_pos;
198 for (
auto& cluster : clusters) {
200 clus_prev_pos.emplace_back(repp.rho(), repp.eta(), repp.phi());
208 cluster.resetHitsAndFractions();
211 std::vector<double> dist2,
frac;
215 int cell_layer = (int)refhit->layer();
225 double recHitEnergyNorm = 0.;
228 for (
unsigned int j = 0;
j < recHitEnergyNormDepthPair.second.size(); ++
j) {
229 int depth = recHitEnergyNormDepthPair.first[
j];
234 recHitEnergyNorm = recHitEnergyNormDepthPair.second[
j];
238 for (
auto& cluster : clusters) {
242 dist2.emplace_back(d2);
244 LOGDRESSED(
"Basic2DGenericPFlowClusterizer:growAndStabilizePFClusters")
245 <<
"Warning! :: pfcluster-topocell distance is too large! d= " << d2;
255 fraction = cluster.energy() / recHitEnergyNorm *
vdt::fast_expf(-0.5 * d2);
258 frac.emplace_back(fraction);
260 for (
unsigned i = 0;
i < clusters.size(); ++
i) {
261 if (fractot >
_minFracTot || (refhit->detId() == clusters[
i].seed() && fractot > 0.0)) {
277 if (dist2[
i] < 100.0 || frac[
i] > 0.9999) {
284 for (
unsigned i = 0;
i < clusters.size(); ++
i) {
294 const double delta2 =
reco::deltaR2(clusters[
i].positionREP(), clus_prev_pos[
i]);
301 clus_prev_pos.clear();
302 growPFClusters(topo, seedable, toleranceScaling, iter + 1, diff, clusters);
306 for (
auto& cluster : clusters) {
VParameterSet const & getParameterSetVector(std::string const &name) const
const unsigned _maxIterations
void growPFClusters(const reco::PFCluster &, const std::vector< bool > &, const unsigned toleranceScaling, const unsigned iter, double dist, reco::PFClusterCollection &) const
void buildClusters(const reco::PFClusterCollection &, const std::vector< bool > &, reco::PFClusterCollection &outclus) override
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
std::unique_ptr< PosCalc > _positionCalc
const std::unordered_map< std::string, int > _layerMap
bool exists(std::string const ¶meterName) const
checks if a parameter exists
Fraction of a PFRecHit (rechits can be shared between several PFCluster's)
const double _stoppingTolerance
std::unique_ptr< PFCPositionCalculatorBase > _convergencePosCalc
key_type key() const
Accessor for product key.
static std::string const input
void setSeed(const DetId &id)
Basic2DGenericPFlowClusterizer(const edm::ParameterSet &conf, edm::ConsumesCollector &cc)
std::unique_ptr< PFCPositionCalculatorBase > _allCellsPosCalc
~Basic2DGenericPFlowClusterizer() override=default
Abs< T >::type abs(const T &t)
B2DGPF & operator=(const B2DGPF &)=delete
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
ParameterSet const & getParameterSet(std::string const &) const
XYZVectorD XYZVector
spatial vector with cartesian internal representation
XYZPointD XYZPoint
point in space with cartesian internal representation
T getParameter(std::string const &) const
const float _minFractionToKeep
std::unordered_map< int, std::pair< std::vector< int >, std::vector< double > > > _recHitEnergyNorms
const std::vector< reco::PFRecHitFraction > & recHitFractions() const
vector of rechit fractions
void addRecHitFraction(const reco::PFRecHitFraction &frac)
add a given fraction of the rechit
const bool _excludeOtherSeeds
const double _showerSigma2
ROOT::Math::PositionVector3D< ROOT::Math::CylindricalEta3D< double > > REPPoint
std::vector< PFCluster > PFClusterCollection
collection of PFCluster objects
#define DEFINE_EDM_PLUGIN(factory, type, name)
void prunePFClusters(reco::PFClusterCollection &) const
void update(const edm::EventSetup &es) override
Power< A, B >::type pow(const A &a, const B &b)
Basic2DGenericPFlowClusterizer B2DGPF
void seedPFClustersFromTopo(const reco::PFCluster &, const std::vector< bool > &, reco::PFClusterCollection &) const