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")),
114 const std::vector<edm::ParameterSet>&
thresholds = conf.getParameterSetVector(
"recHitEnergyNorms");
117 const double& rhE_norm =
pset.getParameter<
double>(
"recHitEnergyNorm");
118 auto entry = _layerMap.find(det);
119 if (
entry == _layerMap.end()) {
120 throw cms::Exception(
"InvalidDetectorLayer") <<
"Detector layer : " << det <<
" is not in the list of recognized" 121 <<
" detector layers!";
123 _recHitEnergyNorms.emplace(_layerMap.find(det)->second, rhE_norm);
126 if (conf.exists(
"allCellsPositionCalc")) {
132 if (conf.exists(
"positionCalcForConvergence")) {
137 if (conf.exists(
"timeResolutionCalcBarrel")) {
139 _timeResolutionCalcBarrel = std::make_unique<CaloRecHitResolutionProvider>(timeResConf);
141 if (conf.exists(
"timeResolutionCalcEndcap")) {
143 _timeResolutionCalcEndcap = std::make_unique<CaloRecHitResolutionProvider>(timeResConf);
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) {
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;
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;
301 if (dist2[
i] < 100.0 ||
frac[
i] > 0.9999) {
325 clus_prev_pos.clear();
327 clus_chi2_nhits.clear();
328 clus_prev_timeres2.clear();
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;
const math::XYZPoint & position() const
cluster centroid position
void update(const edm::EventSetup &es) override
T getParameter(std::string const &) const
const bool _clusterTimeResFromSeed
const double _timeSigma_ee
void growPFClusters(const reco::PFCluster &, const std::vector< bool > &, const unsigned toleranceScaling, const unsigned iter, double dist, reco::PFClusterCollection &) const
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
std::unique_ptr< PFCPositionCalculatorBase > _allCellsPosCalc
void clusterTimeResolution(reco::PFCluster &cluster, double &res) const
std::unique_ptr< PosCalc > _positionCalc
DetId seed() const
return DetId of seed
const std::unordered_map< std::string, int > _layerMap
ParameterSet const & getParameterSet(std::string const &) const
void setTime(float time, float timeError=0)
PFLayer::Layer layer() const
rechit layer
Fraction of a PFRecHit (rechits can be shared between several PFCluster's)
const std::vector< reco::PFRecHitFraction > & recHitFractions() const
vector of rechit fractions
float time() const
timing for cleaned hits
~PFlow2DClusterizerWithTime() override=default
key_type key() const
Accessor for product key.
const double _minChi2Prob
static std::string const input
void setSeed(const DetId &id)
const double _maxNSigmaTime
unsigned detId() const
rechit detId
Particle flow rechit (rechit + geometry and topology information). See clustering algorithm in PFClus...
const double _showerSigma2
double energy() const
cluster energy
Abs< T >::type abs(const T &t)
void seedPFClustersFromTopo(const reco::PFCluster &, const std::vector< bool > &, reco::PFClusterCollection &) const
PFlow2DClusterizerWithTime B2DGPF
void setTimeError(float timeError)
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
B2DGPF & operator=(const B2DGPF &)=delete
std::unique_ptr< CaloRecHitResolutionProvider > _timeResolutionCalcBarrel
std::unique_ptr< CaloRecHitResolutionProvider > _timeResolutionCalcEndcap
PFlow2DClusterizerWithTime(const edm::ParameterSet &conf, edm::ConsumesCollector &cc)
XYZVectorD XYZVector
spatial vector with cartesian internal representation
XYZPointD XYZPoint
point in space with cartesian internal representation
const float _minFractionToKeep
void addRecHitFraction(const reco::PFRecHitFraction &frac)
add a given fraction of the rechit
const unsigned _maxIterations
float energy() const
rechit energy
double dist2Time(const reco::PFCluster &, const reco::PFRecHitRef &, int cell_layer, double prev_timeres2) const
void clusterTimeResolutionFromSeed(reco::PFCluster &cluster, double &res) const
ROOT::Math::PositionVector3D< ROOT::Math::CylindricalEta3D< double > > REPPoint
std::vector< PFCluster > PFClusterCollection
collection of PFCluster objects
const bool _excludeOtherSeeds
void prunePFClusters(reco::PFClusterCollection &) const
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)
bool passChi2Prob(size_t iCluster, double dist2, std::vector< double > &clus_chi2, std::vector< size_t > &clus_chi2_nhits) const
std::unordered_map< int, double > _recHitEnergyNorms