11 #include "Math/GenVector/VectorUtil.h" 13 #include "vdt/vdtMath.h" 16 #include <unordered_map> 37 const std::vector<bool>&,
53 const std::unordered_map<std::string, int>
_layerMap;
62 const std::vector<bool>&,
67 const std::vector<bool>&,
68 const unsigned toleranceScaling,
78 std::vector<double>& clus_chi2,
79 std::vector<size_t>& clus_chi2_nhits)
const;
86 #define LOGVERB(x) edm::LogVerbatim(x) 87 #define LOGWARN(x) edm::LogWarning(x) 88 #define LOGERR(x) edm::LogError(x) 89 #define LOGDRESSED(x) edm::LogInfo(x) 91 #define LOGVERB(x) LogTrace(x) 92 #define LOGWARN(x) edm::LogWarning(x) 93 #define LOGERR(x) edm::LogError(x) 94 #define LOGDRESSED(x) LogDebug(x) 99 _maxIterations(conf.getParameter<unsigned>(
"maxIterations")),
100 _stoppingTolerance(conf.getParameter<double>(
"stoppingTolerance")),
101 _showerSigma2(
std::
pow(conf.getParameter<double>(
"showerSigma"), 2.0)),
102 _timeSigma_eb(
std::
pow(conf.getParameter<double>(
"timeSigmaEB"), 2.0)),
103 _timeSigma_ee(
std::
pow(conf.getParameter<double>(
"timeSigmaEE"), 2.0)),
104 _excludeOtherSeeds(conf.getParameter<
bool>(
"excludeOtherSeeds")),
105 _minFracTot(conf.getParameter<double>(
"minFracTot")),
106 _maxNSigmaTime(
std::
pow(conf.getParameter<double>(
"maxNSigmaTime"), 2.0)),
107 _minChi2Prob(conf.getParameter<double>(
"minChi2Prob")),
108 _clusterTimeResFromSeed(conf.getParameter<
bool>(
"clusterTimeResFromSeed")),
121 const std::vector<edm::ParameterSet>&
thresholds = conf.getParameterSetVector(
"recHitEnergyNorms");
124 const double& rhE_norm =
pset.getParameter<
double>(
"recHitEnergyNorm");
125 auto entry = _layerMap.find(det);
126 if (
entry == _layerMap.end()) {
127 throw cms::Exception(
"InvalidDetectorLayer") <<
"Detector layer : " << det <<
" is not in the list of recognized" 128 <<
" detector layers!";
130 _recHitEnergyNorms.emplace(_layerMap.find(det)->second, rhE_norm);
133 if (conf.exists(
"allCellsPositionCalc")) {
139 if (conf.exists(
"positionCalcForConvergence")) {
144 if (conf.exists(
"timeResolutionCalcBarrel")) {
146 _timeResolutionCalcBarrel = std::make_unique<CaloRecHitResolutionProvider>(timeResConf);
148 if (conf.exists(
"timeResolutionCalcEndcap")) {
150 _timeResolutionCalcEndcap = std::make_unique<CaloRecHitResolutionProvider>(timeResConf);
155 const std::vector<bool>& seedable,
159 for (
const auto& topocluster :
input) {
160 clustersInTopo.clear();
162 const unsigned tolScal =
std::pow(
std::max(1.0, clustersInTopo.size() - 1.0), 2.0);
163 growPFClusters(topocluster, seedable, tolScal, 0, tolScal, clustersInTopo, hcalCuts);
176 _positionCalc->calculateAndSetPositions(clustersInTopo, hcalCuts);
179 for (
auto& clusterout : clustersInTopo) {
186 const std::vector<bool>& seedable,
190 for (
const auto& rhf : recHitFractions) {
191 if (!seedable[rhf.recHitRef().key()])
196 current.
setSeed(rhf.recHitRef()->detId());
206 const std::vector<bool>& seedable,
207 const unsigned toleranceScaling,
213 LOGDRESSED(
"PFlow2DClusterizerWithTime:growAndStabilizePFClusters")
214 <<
"reached " <<
_maxIterations <<
" iterations, terminated position " 215 <<
"fit with diff = " <<
diff;
220 std::vector<reco::PFCluster::REPPoint> clus_prev_pos;
222 std::vector<double> clus_prev_timeres2;
226 clus_prev_pos.emplace_back(repp.rho(), repp.eta(), repp.phi());
239 clus_prev_timeres2.push_back(resCluster2);
240 cluster.resetHitsAndFractions();
243 std::vector<double> dist2,
frac;
246 std::vector<double> clus_chi2;
247 std::vector<size_t> clus_chi2_nhits;
252 int cell_layer = (
int)refhit->layer();
257 if (hcalCuts !=
nullptr) {
272 for (
size_t iCluster = 0; iCluster <
clusters.size(); ++iCluster) {
278 double d2time =
dist2Time(cluster, refhit, cell_layer, clus_prev_timeres2[iCluster]);
284 dist2.emplace_back(d2);
287 LOGDRESSED(
"PFlow2DClusterizerWithTime:growAndStabilizePFClusters")
288 <<
"Warning! :: pfcluster-topocell distance is too large! d= " << d2;
319 if (dist2[
i] < 100.0 ||
frac[
i] > 0.9999) {
343 clus_prev_pos.clear();
345 clus_chi2_nhits.clear();
346 clus_prev_timeres2.clear();
357 clusterRes2 = 10000.;
374 double sumTimeSigma2 = 0.;
375 double sumSigma2 = 0.;
379 const double rhf_f = rhf.fraction();
386 double res2 = 10000.;
392 sumTimeSigma2 += rhf_f * rh.
time() / res2;
393 sumSigma2 += rhf_f / res2;
395 if (sumSigma2 > 0.) {
396 clusterRes2 = 1. / sumSigma2;
397 cluster.
setTime(sumTimeSigma2 / sumSigma2);
400 clusterRes2 = 999999.;
407 double prev_timeres2)
const {
408 const double deltaT = cluster.
time() - refhit->time();
409 const double t2 = deltaT * deltaT;
415 const double resCluster2 = prev_timeres2;
423 const double resCluster2 = prev_timeres2;
430 double distTime2 =
t2 / res2;
439 std::vector<double>& clus_chi2,
440 std::vector<size_t>& clus_chi2_nhits)
const {
441 if (iCluster >= clus_chi2.size()) {
442 clus_chi2.push_back(dist2);
443 clus_chi2_nhits.push_back(1);
446 double chi2 = clus_chi2[iCluster];
447 size_t nhitsCluster = clus_chi2_nhits[iCluster];
450 clus_chi2[iCluster] =
chi2;
451 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 seedPFClustersFromTopo(const reco::PFCluster &, const std::vector< bool > &, reco::PFClusterCollection &, const HcalPFCuts *) const
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
std::unique_ptr< PFCPositionCalculatorBase > _allCellsPosCalc
uint32_t cc[maxCellsPerHit]
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
const Item * getValues(DetId fId, bool throwOnFail=true) const
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)
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
constexpr uint32_t rawId() const
get the raw id
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
void buildClusters(const reco::PFClusterCollection &, const std::vector< bool > &, reco::PFClusterCollection &outclus, const HcalPFCuts *) override
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)
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
void growPFClusters(const reco::PFCluster &, const std::vector< bool > &, const unsigned toleranceScaling, const unsigned iter, double dist, reco::PFClusterCollection &, const HcalPFCuts *hcalCuts) const
std::unordered_map< int, double > _recHitEnergyNorms