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!";
67 if( conf.exists(
"allCellsPositionCalc") ) {
75 if( conf.exists(
"positionCalcForConvergence") ) {
82 if( conf.exists(
"timeResolutionCalcBarrel") ) {
88 if( conf.exists(
"timeResolutionCalcEndcap") ) {
98 const std::vector<bool>& seedable,
101 for(
const auto& topocluster : input ) {
102 clustersInTopo.clear();
104 const unsigned tolScal =
106 growPFClusters(topocluster,seedable,tolScal,0,tolScal,clustersInTopo);
122 for(
auto& clusterout : clustersInTopo ) {
123 output.insert(output.end(),
std::move(clusterout));
130 const std::vector<bool>& seedable,
133 for(
const auto& rhf : recHitFractions ) {
134 if( !seedable[rhf.recHitRef().key()] )
continue;
138 current.
setSeed(rhf.recHitRef()->detId());
149 const std::vector<bool>& seedable,
150 const unsigned toleranceScaling,
155 LOGDRESSED(
"PFlow2DClusterizerWithTime:growAndStabilizePFClusters")
156 <<
"reached " <<
_maxIterations <<
" iterations, terminated position " 157 <<
"fit with diff = " <<
diff;
162 std::vector<reco::PFCluster::REPPoint> clus_prev_pos;
164 std::vector<double> clus_prev_timeres2;
166 for(
auto& cluster : clusters) {
168 clus_prev_pos.emplace_back(repp.rho(),repp.eta(),repp.phi());
181 clus_prev_timeres2.push_back(resCluster2);
182 cluster.resetHitsAndFractions();
185 std::vector<double> dist2,
frac;
188 std::vector<double> clus_chi2;
189 std::vector<size_t> clus_chi2_nhits;
194 int cell_layer = (
int)refhit->layer();
196 std::abs(refhit->positionREP().eta()) > 0.34 ) {
202 dist2.clear(); frac.clear(); fractot = 0;
206 for (
size_t iCluster = 0; iCluster < clusters.size(); ++iCluster) {
212 double d2time =
dist2Time(cluster, refhit, cell_layer,
213 clus_prev_timeres2[iCluster]);
220 dist2.emplace_back( d2);
223 LOGDRESSED(
"PFlow2DClusterizerWithTime:growAndStabilizePFClusters")
224 <<
"Warning! :: pfcluster-topocell distance is too large! d= " 237 frac.emplace_back(fraction);
239 for(
unsigned i = 0;
i < clusters.size(); ++
i ) {
241 ( refhit->detId() == clusters[
i].seed() && fractot > 0.0 ) ) {
257 if( dist2[
i] < 100.0 || frac[
i] > 0.9999 ) {
264 for(
unsigned i = 0;
i < clusters.size(); ++
i ) {
274 const double delta2 =
276 if( delta2 > diff2 ) diff2 = delta2;
279 dist2.clear(); frac.clear(); clus_prev_pos.clear();
280 clus_chi2.clear(); clus_chi2_nhits.clear(); clus_prev_timeres2.clear();
281 growPFClusters(topo,seedable,toleranceScaling,iter+1,diff,clusters);
286 for(
auto& cluster : clusters ) {
294 cluster,
double& clusterRes2)
const 296 clusterRes2 = 10000.;
316 double& clusterRes2)
const 318 double sumTimeSigma2 = 0.;
319 double sumSigma2 = 0.;
324 const double rhf_f = rhf.fraction();
332 double res2 = 10000.;
338 sumTimeSigma2 += rhf_f * rh.
time()/res2;
339 sumSigma2 += rhf_f/res2;
341 if (sumSigma2 > 0.) {
342 clusterRes2 = 1./sumSigma2;
343 cluster.
setTime(sumTimeSigma2/sumSigma2);
346 clusterRes2 = 999999.;
353 const double deltaT = cluster.
time()-refhit->time();
354 const double t2 = deltaT*deltaT;
361 const double resCluster2 = prev_timeres2;
374 const double resCluster2 = prev_timeres2;
383 double distTime2 = t2/res2;
391 std::vector<double>& clus_chi2, std::vector<size_t>& clus_chi2_nhits)
const 393 if (iCluster >= clus_chi2.size()) {
394 clus_chi2.push_back(dist2);
395 clus_chi2_nhits.push_back(1);
399 double chi2 = clus_chi2[iCluster];
400 size_t nhitsCluster = clus_chi2_nhits[iCluster];
403 clus_chi2[iCluster] =
chi2;
404 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
bool isBarrel(GeomDetEnumerators::SubDetector m)
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
std::unordered_map< int, double > _recHitEnergyNorms
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)