6 #include "Math/GenVector/VectorUtil.h" 8 #include "vdt/vdtMath.h" 15 #define LOGVERB(x) edm::LogVerbatim(x) 16 #define LOGWARN(x) edm::LogWarning(x) 17 #define LOGERR(x) edm::LogError(x) 18 #define LOGDRESSED(x) edm::LogInfo(x) 20 #define LOGVERB(x) LogTrace(x) 21 #define LOGWARN(x) edm::LogWarning(x) 22 #define LOGERR(x) edm::LogError(x) 23 #define LOGDRESSED(x) LogDebug(x) 28 _maxIterations(conf.getParameter<unsigned>(
"maxIterations")),
29 _stoppingTolerance(conf.getParameter<double>(
"stoppingTolerance")),
30 _showerSigma2(
std::
pow(conf.getParameter<double>(
"showerSigma"), 2.0)),
31 _timeSigma_eb(
std::
pow(conf.getParameter<double>(
"timeSigmaEB"), 2.0)),
32 _timeSigma_ee(
std::
pow(conf.getParameter<double>(
"timeSigmaEE"), 2.0)),
33 _excludeOtherSeeds(conf.getParameter<
bool>(
"excludeOtherSeeds")),
34 _minFracTot(conf.getParameter<double>(
"minFracTot")),
35 _maxNSigmaTime(
std::
pow(conf.getParameter<double>(
"maxNSigmaTime"), 2.0)),
36 _minChi2Prob(conf.getParameter<double>(
"minChi2Prob")),
37 _clusterTimeResFromSeed(conf.getParameter<
bool>(
"clusterTimeResFromSeed")),
50 const std::vector<edm::ParameterSet>&
thresholds = conf.getParameterSetVector(
"recHitEnergyNorms");
51 for (
const auto&
pset : thresholds) {
53 const double& rhE_norm =
pset.getParameter<
double>(
"recHitEnergyNorm");
56 throw cms::Exception(
"InvalidDetectorLayer") <<
"Detector layer : " << det <<
" is not in the list of recognized" 57 <<
" detector layers!";
62 if (conf.exists(
"allCellsPositionCalc")) {
68 if (conf.exists(
"positionCalcForConvergence")) {
73 if (conf.exists(
"timeResolutionCalcBarrel")) {
77 if (conf.exists(
"timeResolutionCalcEndcap")) {
84 const std::vector<bool>& seedable,
87 for (
const auto& topocluster : input) {
88 clustersInTopo.clear();
90 const unsigned tolScal =
std::pow(
std::max(1.0, clustersInTopo.size() - 1.0), 2.0);
91 growPFClusters(topocluster, seedable, tolScal, 0, tolScal, clustersInTopo);
107 for (
auto& clusterout : clustersInTopo) {
108 output.insert(output.end(),
std::move(clusterout));
114 const std::vector<bool>& seedable,
117 for (
const auto& rhf : recHitFractions) {
118 if (!seedable[rhf.recHitRef().key()])
123 current.
setSeed(rhf.recHitRef()->detId());
133 const std::vector<bool>& seedable,
134 const unsigned toleranceScaling,
139 LOGDRESSED(
"PFlow2DClusterizerWithTime:growAndStabilizePFClusters")
140 <<
"reached " <<
_maxIterations <<
" iterations, terminated position " 141 <<
"fit with diff = " <<
diff;
146 std::vector<reco::PFCluster::REPPoint> clus_prev_pos;
148 std::vector<double> clus_prev_timeres2;
150 for (
auto& cluster : clusters) {
152 clus_prev_pos.emplace_back(repp.rho(), repp.eta(), repp.phi());
165 clus_prev_timeres2.push_back(resCluster2);
166 cluster.resetHitsAndFractions();
169 std::vector<double> dist2,
frac;
172 std::vector<double> clus_chi2;
173 std::vector<size_t> clus_chi2_nhits;
178 int cell_layer = (
int)refhit->layer();
190 for (
size_t iCluster = 0; iCluster < clusters.size(); ++iCluster) {
196 double d2time =
dist2Time(cluster, refhit, cell_layer, clus_prev_timeres2[iCluster]);
202 dist2.emplace_back(d2);
205 LOGDRESSED(
"PFlow2DClusterizerWithTime:growAndStabilizePFClusters")
206 <<
"Warning! :: pfcluster-topocell distance is too large! d= " << d2;
218 frac.emplace_back(fraction);
220 for (
unsigned i = 0;
i < clusters.size(); ++
i) {
221 if (fractot >
_minFracTot || (refhit->detId() == clusters[
i].seed() && fractot > 0.0)) {
237 if (dist2[
i] < 100.0 || frac[
i] > 0.9999) {
244 for (
unsigned i = 0;
i < clusters.size(); ++
i) {
254 const double delta2 =
reco::deltaR2(clusters[
i].positionREP(), clus_prev_pos[
i]);
261 clus_prev_pos.clear();
263 clus_chi2_nhits.clear();
264 clus_prev_timeres2.clear();
265 growPFClusters(topo, seedable, toleranceScaling, iter + 1, diff, clusters);
269 for (
auto& cluster : clusters) {
275 clusterRes2 = 10000.;
292 double sumTimeSigma2 = 0.;
293 double sumSigma2 = 0.;
297 const double rhf_f = rhf.fraction();
304 double res2 = 10000.;
310 sumTimeSigma2 += rhf_f * rh.
time() / res2;
311 sumSigma2 += rhf_f / res2;
313 if (sumSigma2 > 0.) {
314 clusterRes2 = 1. / sumSigma2;
315 cluster.
setTime(sumTimeSigma2 / sumSigma2);
318 clusterRes2 = 999999.;
325 double prev_timeres2)
const {
326 const double deltaT = cluster.
time() - refhit->time();
327 const double t2 = deltaT * deltaT;
333 const double resCluster2 = prev_timeres2;
341 const double resCluster2 = prev_timeres2;
348 double distTime2 = t2 / res2;
357 std::vector<double>& clus_chi2,
358 std::vector<size_t>& clus_chi2_nhits)
const {
359 if (iCluster >= clus_chi2.size()) {
360 clus_chi2.push_back(dist2);
361 clus_chi2_nhits.push_back(1);
364 double chi2 = clus_chi2[iCluster];
365 size_t nhitsCluster = clus_chi2_nhits[iCluster];
368 clus_chi2[iCluster] =
chi2;
369 clus_chi2_nhits[iCluster] = nhitsCluster + 1;
T getParameter(std::string const &) const
const math::XYZPoint & position() const
cluster centroid position
void prunePFClusters(reco::PFClusterCollection &) const
const bool _clusterTimeResFromSeed
const double _timeSigma_ee
PFlow2DClusterizerWithTime(const edm::ParameterSet &conf)
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)
Fraction of a PFRecHit (rechits can be shared between several PFCluster's)
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
void setTimeError(float timeError)
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
DetId seed() const
return DetId of seed
std::unique_ptr< CaloRecHitResolutionProvider > _timeResolutionCalcBarrel
std::unique_ptr< CaloRecHitResolutionProvider > _timeResolutionCalcEndcap
ParameterSet const & getParameterSet(std::string const &) const
XYZVectorD XYZVector
spatial vector with cartesian internal representation
XYZPointD XYZPoint
point in space with cartesian internal representation
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
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