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)
29 _maxIterations(conf.getParameter<unsigned>(
"maxIterations")),
30 _stoppingTolerance(conf.getParameter<double>(
"stoppingTolerance")),
31 _showerSigma2(std::
pow(conf.getParameter<double>(
"showerSigma"),2.0)),
32 _timeSigma_eb(std::
pow(conf.getParameter<double>(
"timeSigmaEB"),2.0)),
33 _timeSigma_ee(std::
pow(conf.getParameter<double>(
"timeSigmaEE"),2.0)),
34 _excludeOtherSeeds(conf.getParameter<bool>(
"excludeOtherSeeds")),
35 _minFracTot(conf.getParameter<double>(
"minFracTot")),
36 _maxNSigmaTime(std::
pow(conf.getParameter<double>(
"maxNSigmaTime"),2.0)),
37 _minChi2Prob(conf.getParameter<double>(
"minChi2Prob")),
38 _clusterTimeResFromSeed(conf.getParameter<bool>(
"clusterTimeResFromSeed")),
53 const std::vector<edm::ParameterSet>& thresholds =
55 for(
const auto& pset : thresholds ) {
57 const double& rhE_norm = pset.getParameter<
double>(
"recHitEnergyNorm");
61 <<
"Detector layer : " << det <<
" is not in the list of recognized"
62 <<
" detector layers!";
68 if( conf.
exists(
"allCellsPositionCalc") ) {
79 if( conf.
exists(
"positionCalcForConvergence") ) {
89 if( conf.
exists(
"timeResolutionCalcBarrel") ) {
96 if( conf.
exists(
"timeResolutionCalcEndcap") ) {
106 const std::vector<bool>& seedable,
109 for(
const auto& topocluster : input ) {
110 clustersInTopo.clear();
112 const unsigned tolScal =
114 growPFClusters(topocluster,seedable,tolScal,0,tolScal,clustersInTopo);
130 for(
auto& clusterout : clustersInTopo ) {
131 output.insert(output.end(),std::move(clusterout));
138 const std::vector<bool>& seedable,
141 for(
const auto& rhf : recHitFractions ) {
142 if( !seedable[rhf.recHitRef().key()] )
continue;
146 current.
setSeed(rhf.recHitRef()->detId());
157 const std::vector<bool>& seedable,
158 const unsigned toleranceScaling,
163 LOGDRESSED(
"PFlow2DClusterizerWithTime:growAndStabilizePFClusters")
164 <<
"reached " <<
_maxIterations <<
" iterations, terminated position "
165 <<
"fit with diff = " <<
diff;
170 std::vector<reco::PFCluster::REPPoint> clus_prev_pos;
172 std::vector<double> clus_prev_timeres2;
174 for(
auto& cluster : clusters) {
176 clus_prev_pos.emplace_back(repp.rho(),repp.eta(),repp.phi());
189 clus_prev_timeres2.push_back(resCluster2);
190 cluster.resetHitsAndFractions();
193 std::vector<double> dist2,
frac;
196 std::vector<double> clus_chi2;
197 std::vector<size_t> clus_chi2_nhits;
202 int cell_layer = (int)refhit->layer();
204 std::abs(refhit->positionREP().eta()) > 0.34 ) {
207 const double recHitEnergyNorm =
210 dist2.clear(); frac.clear(); fractot = 0;
214 for (
size_t iCluster = 0; iCluster < clusters.size(); ++iCluster) {
221 double d2time =
dist2Time(cluster, refhit, cell_layer,
222 clus_prev_timeres2[iCluster]);
229 dist2.emplace_back( d2);
232 LOGDRESSED(
"PFlow2DClusterizerWithTime:growAndStabilizePFClusters")
233 <<
"Warning! :: pfcluster-topocell distance is too large! d= "
247 for(
unsigned i = 0;
i < clusters.size(); ++
i ) {
249 ( refhit->detId() == clusters[
i].seed() && fractot > 0.0 ) ) {
265 if( dist2[
i] < 100.0 || frac[
i] > 0.9999 ) {
272 for(
unsigned i = 0;
i < clusters.size(); ++
i ) {
282 const double delta2 =
284 if( delta2 > diff2 ) diff2 = delta2;
287 dist2.clear(); frac.clear(); clus_prev_pos.clear();
288 clus_chi2.clear(); clus_chi2_nhits.clear(); clus_prev_timeres2.clear();
289 growPFClusters(topo,seedable,toleranceScaling,iter+1,diff,clusters);
294 for(
auto& cluster : clusters ) {
302 cluster,
double& clusterRes2)
const
304 clusterRes2 = 10000.;
323 double& clusterRes2)
const
325 double sumTimeSigma2 = 0.;
326 double sumSigma2 = 0.;
331 const double rhf_f = rhf.fraction();
339 double res2 = 10000.;
345 sumTimeSigma2 += rhf_f * rh.
time()/res2;
346 sumSigma2 += rhf_f/res2;
348 if (sumSigma2 > 0.) {
349 clusterRes2 = 1./sumSigma2;
350 cluster.
setTime(sumTimeSigma2/sumSigma2);
352 clusterRes2 = 999999.;
359 const double deltaT = cluster.
time()-refhit->time();
360 const double t2 = deltaT*deltaT;
367 const double resCluster2 = prev_timeres2;
380 const double resCluster2 = prev_timeres2;
389 double distTime2 = t2/res2;
397 std::vector<double>& clus_chi2, std::vector<size_t>& clus_chi2_nhits)
const
399 if (iCluster >= clus_chi2.size()) {
400 clus_chi2.push_back(dist2);
401 clus_chi2_nhits.push_back(1);
405 double chi2 = clus_chi2[iCluster];
406 size_t nhitsCluster = clus_chi2_nhits[iCluster];
409 clus_chi2[iCluster] = chi2;
410 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
VParameterSet const & getParameterSetVector(std::string const &name) 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
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
bool isBarrel(GeomDetEnumerators::SubDetector m)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
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 setTime(double time)
void clusterTimeResolution(reco::PFCluster &cluster, double &res) const
const double _showerSigma2
Abs< T >::type abs(const T &t)
double deltaR2(const T1 &t1, const T2 &t2)
double dist2Time(const reco::PFCluster &, const reco::PFRecHitRef &, int cell_layer, double prev_timeres2) const
double energy() const
cluster energy
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
std::unordered_map< int, double > _recHitEnergyNorms
void buildClusters(const reco::PFClusterCollection &, const std::vector< bool > &, reco::PFClusterCollection &outclus)
void addRecHitFraction(const reco::PFRecHitFraction &frac)
add a given fraction of the rechit
const unsigned _maxIterations
double time() const
cluster time
double energy() const
rechit energy
ROOT::Math::PositionVector3D< ROOT::Math::CylindricalEta3D< double > > REPPoint
std::vector< PFCluster > PFClusterCollection
collection of PFCluster objects
const std::vector< reco::PFRecHitFraction > & recHitFractions() const
vector of rechit fractions
void clusterTimeResolutionFromSeed(reco::PFCluster &cluster, double &res) const
const bool _excludeOtherSeeds
std::unique_ptr< PFCPositionCalculatorBase > _convergencePosCalc
const double _timeSigma_eb
double time() const
timing for cleaned hits
const double _stoppingTolerance
const std::unordered_map< std::string, int > _layerMap
Power< A, B >::type pow(const A &a, const B &b)
T get(const Candidate &c)
PFCPositionCalculatorBase PosCalc