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 =
54 conf.getParameterSetVector(
"recHitEnergyNorms");
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 ) {
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.;
324 double& clusterRes2)
const 326 double sumTimeSigma2 = 0.;
327 double sumSigma2 = 0.;
332 const double rhf_f = rhf.fraction();
340 double res2 = 10000.;
346 sumTimeSigma2 += rhf_f * rh.
time()/res2;
347 sumSigma2 += rhf_f/res2;
349 if (sumSigma2 > 0.) {
350 clusterRes2 = 1./sumSigma2;
351 cluster.
setTime(sumTimeSigma2/sumSigma2);
354 clusterRes2 = 999999.;
361 const double deltaT = cluster.
time()-refhit->time();
362 const double t2 = deltaT*deltaT;
369 const double resCluster2 = prev_timeres2;
382 const double resCluster2 = prev_timeres2;
391 double distTime2 = t2/res2;
399 std::vector<double>& clus_chi2, std::vector<size_t>& clus_chi2_nhits)
const 401 if (iCluster >= clus_chi2.size()) {
402 clus_chi2.push_back(dist2);
403 clus_chi2_nhits.push_back(1);
407 double chi2 = clus_chi2[iCluster];
408 size_t nhitsCluster = clus_chi2_nhits[iCluster];
411 clus_chi2[iCluster] =
chi2;
412 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
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
auto const T2 &decltype(t1.eta()) t2
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)
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
T1 deltaR2(T1 eta1, T2 phi1, T3 eta2, T4 phi2)
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
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
void buildClusters(const reco::PFClusterCollection &, const std::vector< bool > &, reco::PFClusterCollection &outclus) override
const double _timeSigma_eb
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)