9 #include "Math/GenVector/VectorUtil.h"
11 #include "vdt/vdtMath.h"
14 #include <unordered_map>
35 const std::vector<bool>&,
50 const std::unordered_map<std::string, int>
_layerMap;
61 const std::vector<bool>&,
62 const unsigned toleranceScaling,
71 std::vector<double>& clus_chi2,
72 std::vector<size_t>& clus_chi2_nhits)
const;
79 #define LOGVERB(x) edm::LogVerbatim(x)
80 #define LOGWARN(x) edm::LogWarning(x)
81 #define LOGERR(x) edm::LogError(x)
82 #define LOGDRESSED(x) edm::LogInfo(x)
84 #define LOGVERB(x) LogTrace(x)
85 #define LOGWARN(x) edm::LogWarning(x)
86 #define LOGERR(x) edm::LogError(x)
87 #define LOGDRESSED(x) LogDebug(x)
92 _maxIterations(conf.getParameter<unsigned>(
"maxIterations")),
93 _stoppingTolerance(conf.getParameter<double>(
"stoppingTolerance")),
94 _showerSigma2(std::
pow(conf.getParameter<double>(
"showerSigma"), 2.0)),
95 _timeSigma_eb(std::
pow(conf.getParameter<double>(
"timeSigmaEB"), 2.0)),
96 _timeSigma_ee(std::
pow(conf.getParameter<double>(
"timeSigmaEE"), 2.0)),
97 _excludeOtherSeeds(conf.getParameter<bool>(
"excludeOtherSeeds")),
98 _minFracTot(conf.getParameter<double>(
"minFracTot")),
99 _maxNSigmaTime(std::
pow(conf.getParameter<double>(
"maxNSigmaTime"), 2.0)),
100 _minChi2Prob(conf.getParameter<double>(
"minChi2Prob")),
101 _clusterTimeResFromSeed(conf.getParameter<bool>(
"clusterTimeResFromSeed")),
115 for (
const auto&
pset : thresholds) {
117 const double& rhE_norm =
pset.getParameter<
double>(
"recHitEnergyNorm");
120 throw cms::Exception(
"InvalidDetectorLayer") <<
"Detector layer : " << det <<
" is not in the list of recognized"
121 <<
" detector layers!";
126 if (conf.
exists(
"allCellsPositionCalc")) {
132 if (conf.
exists(
"positionCalcForConvergence")) {
137 if (conf.
exists(
"timeResolutionCalcBarrel")) {
141 if (conf.
exists(
"timeResolutionCalcEndcap")) {
148 const std::vector<bool>& seedable,
151 for (
const auto& topocluster : input) {
152 clustersInTopo.clear();
154 const unsigned tolScal =
std::pow(
std::max(1.0, clustersInTopo.size() - 1.0), 2.0);
155 growPFClusters(topocluster, seedable, tolScal, 0, tolScal, clustersInTopo);
171 for (
auto& clusterout : clustersInTopo) {
172 output.insert(output.end(),
std::move(clusterout));
178 const std::vector<bool>& seedable,
181 for (
const auto& rhf : recHitFractions) {
182 if (!seedable[rhf.recHitRef().key()])
187 current.
setSeed(rhf.recHitRef()->detId());
197 const std::vector<bool>& seedable,
198 const unsigned toleranceScaling,
203 LOGDRESSED(
"PFlow2DClusterizerWithTime:growAndStabilizePFClusters")
204 <<
"reached " <<
_maxIterations <<
" iterations, terminated position "
205 <<
"fit with diff = " <<
diff;
210 std::vector<reco::PFCluster::REPPoint> clus_prev_pos;
212 std::vector<double> clus_prev_timeres2;
214 for (
auto& cluster : clusters) {
216 clus_prev_pos.emplace_back(repp.rho(), repp.eta(), repp.phi());
229 clus_prev_timeres2.push_back(resCluster2);
230 cluster.resetHitsAndFractions();
233 std::vector<double> dist2,
frac;
236 std::vector<double> clus_chi2;
237 std::vector<size_t> clus_chi2_nhits;
242 int cell_layer = (int)refhit->layer();
254 for (
size_t iCluster = 0; iCluster < clusters.size(); ++iCluster) {
260 double d2time =
dist2Time(cluster, refhit, cell_layer, clus_prev_timeres2[iCluster]);
266 dist2.emplace_back(d2);
269 LOGDRESSED(
"PFlow2DClusterizerWithTime:growAndStabilizePFClusters")
270 <<
"Warning! :: pfcluster-topocell distance is too large! d= " << d2;
282 frac.emplace_back(fraction);
284 for (
unsigned i = 0;
i < clusters.size(); ++
i) {
285 if (fractot >
_minFracTot || (refhit->detId() == clusters[
i].seed() && fractot > 0.0)) {
301 if (dist2[
i] < 100.0 || frac[
i] > 0.9999) {
308 for (
unsigned i = 0;
i < clusters.size(); ++
i) {
318 const double delta2 =
reco::deltaR2(clusters[
i].positionREP(), clus_prev_pos[
i]);
325 clus_prev_pos.clear();
327 clus_chi2_nhits.clear();
328 clus_prev_timeres2.clear();
329 growPFClusters(topo, seedable, toleranceScaling, iter + 1, diff, clusters);
333 for (
auto& cluster : clusters) {
339 clusterRes2 = 10000.;
356 double sumTimeSigma2 = 0.;
357 double sumSigma2 = 0.;
361 const double rhf_f = rhf.fraction();
368 double res2 = 10000.;
374 sumTimeSigma2 += rhf_f * rh.
time() / res2;
375 sumSigma2 += rhf_f / res2;
377 if (sumSigma2 > 0.) {
378 clusterRes2 = 1. / sumSigma2;
379 cluster.
setTime(sumTimeSigma2 / sumSigma2);
382 clusterRes2 = 999999.;
389 double prev_timeres2)
const {
390 const double deltaT = cluster.
time() - refhit->time();
391 const double t2 = deltaT * deltaT;
397 const double resCluster2 = prev_timeres2;
405 const double resCluster2 = prev_timeres2;
412 double distTime2 = t2 / res2;
421 std::vector<double>& clus_chi2,
422 std::vector<size_t>& clus_chi2_nhits)
const {
423 if (iCluster >= clus_chi2.size()) {
424 clus_chi2.push_back(dist2);
425 clus_chi2_nhits.push_back(1);
428 double chi2 = clus_chi2[iCluster];
429 size_t nhitsCluster = clus_chi2_nhits[iCluster];
432 clus_chi2[iCluster] =
chi2;
433 clus_chi2_nhits[iCluster] = nhitsCluster + 1;
void update(const edm::EventSetup &es) override
const math::XYZPoint & position() const
cluster centroid position
void prunePFClusters(reco::PFClusterCollection &) const
VParameterSet const & getParameterSetVector(std::string const &name) const
const bool _clusterTimeResFromSeed
const double _timeSigma_ee
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
std::unique_ptr< PFCPositionCalculatorBase > _allCellsPosCalc
float time() const
timing for cleaned hits
unsigned detId() const
rechit detId
bool passChi2Prob(size_t iCluster, double dist2, std::vector< double > &clus_chi2, std::vector< size_t > &clus_chi2_nhits) const
std::unique_ptr< PosCalc > _positionCalc
const std::unordered_map< std::string, int > _layerMap
void setTime(float time, float timeError=0)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
Fraction of a PFRecHit (rechits can be shared between several PFCluster's)
~PFlow2DClusterizerWithTime() override=default
key_type key() const
Accessor for product key.
void growPFClusters(const reco::PFCluster &, const std::vector< bool > &, const unsigned toleranceScaling, const unsigned iter, double dist, reco::PFClusterCollection &) const
const double _minChi2Prob
static std::string const input
void setSeed(const DetId &id)
const double _maxNSigmaTime
void seedPFClustersFromTopo(const reco::PFCluster &, const std::vector< bool > &, reco::PFClusterCollection &) const
PFLayer::Layer layer() const
rechit layer
Particle flow rechit (rechit + geometry and topology information). See clustering algorithm in PFClus...
void clusterTimeResolution(reco::PFCluster &cluster, double &res) const
const double _showerSigma2
Abs< T >::type abs(const T &t)
float energy() const
rechit energy
double dist2Time(const reco::PFCluster &, const reco::PFRecHitRef &, int cell_layer, double prev_timeres2) const
double energy() const
cluster energy
PFlow2DClusterizerWithTime B2DGPF
void setTimeError(float timeError)
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
B2DGPF & operator=(const B2DGPF &)=delete
DetId seed() const
return DetId of seed
std::unique_ptr< CaloRecHitResolutionProvider > _timeResolutionCalcBarrel
std::unique_ptr< CaloRecHitResolutionProvider > _timeResolutionCalcEndcap
PFlow2DClusterizerWithTime(const edm::ParameterSet &conf, edm::ConsumesCollector &cc)
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
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 unsigned _maxIterations
ROOT::Math::PositionVector3D< ROOT::Math::CylindricalEta3D< double > > REPPoint
std::vector< PFCluster > PFClusterCollection
collection of PFCluster objects
void clusterTimeResolutionFromSeed(reco::PFCluster &cluster, double &res) const
const bool _excludeOtherSeeds
std::unique_ptr< PFCPositionCalculatorBase > _convergencePosCalc
#define DEFINE_EDM_PLUGIN(factory, type, name)
void buildClusters(const reco::PFClusterCollection &, const std::vector< bool > &, reco::PFClusterCollection &outclus) override
const double _timeSigma_eb
const double _stoppingTolerance
Power< A, B >::type pow(const A &a, const B &b)
std::unordered_map< int, double > _recHitEnergyNorms