CMS 3D CMS Logo

Cluster3DPCACalculator.cc
Go to the documentation of this file.
3 
4 #include <cmath>
5 #include <unordered_map>
6 
7 #include "vdt/vdtMath.h"
8 
12 
14 
15 #include "TPrincipal.h"
16 
18 public:
21  updateTiming_(conf.getParameter<bool>("updateTiming")),
22  pca_(new TPrincipal(3, "D")) {}
25 
28 
29 private:
30  const bool updateTiming_;
31  std::unique_ptr<TPrincipal> pca_;
32 
34 
36 };
37 
39 
41  pca_.reset(new TPrincipal(3, "D"));
43 }
44 
46  for (reco::PFCluster& cluster : clusters) {
47  pca_.reset(new TPrincipal(3, "D"));
49  }
50 }
51 
53  if (!cluster.seed()) {
54  throw cms::Exception("ClusterWithNoSeed") << " Found a cluster with no seed: " << cluster;
55  }
56  double cl_energy = 0;
57  double max_e = 0.0;
58  double avg_time = 0.0;
59  double time_norm = 0.0;
60  PFLayer::Layer max_e_layer = PFLayer::NONE;
61  reco::PFRecHitRef refseed;
62  double pcavars[3];
63 
64  for (const reco::PFRecHitFraction& rhf : cluster.recHitFractions()) {
65  const reco::PFRecHitRef& refhit = rhf.recHitRef();
66  double rh_energy = refhit->energy();
67  double rh_time = refhit->time();
68  cl_energy += rh_energy * rhf.fraction();
69  if (rh_time > 0.0) { // time == -1 means no measurement
70  // all times are offset by one nanosecond in digitizer
71  // remove that here so all times of flight
72  // are with respect to (0,0,0)
73  avg_time += (rh_time - 1.0);
74  time_norm += 1.0;
75  }
76  if (rh_energy > max_e) {
77  max_e = rh_energy;
78  max_e_layer = rhf.recHitRef()->layer();
79  }
80  if (refhit->detId() == cluster.seed())
81  refseed = refhit;
82  const double rh_fraction = rhf.fraction();
83  rh_energy = refhit->energy() * rh_fraction;
84  if (edm::isNotFinite(rh_energy)) {
85  //temporarily changed exception to warning
86  // throw cms::Exception("PFClusterAlgo")
87  edm::LogWarning("PFClusterAlgo") << "rechit " << refhit->detId() << " has a NaN energy... "
88  << "The input of the particle flow clustering seems to be corrupted.";
89  continue;
90  }
91  pcavars[0] = refhit->position().x();
92  pcavars[1] = refhit->position().y();
93  pcavars[2] = refhit->position().z();
94  int nhit = int(rh_energy * 100); // put rec_hit energy in units of 10 MeV
95 
96  for (int i = 0; i < nhit; ++i) {
97  pca_->AddRow(pcavars);
98  }
99  }
100  cluster.setEnergy(cl_energy);
101  cluster.setLayer(max_e_layer);
102  // calculate the position
103 
104  pca_->MakePrincipals();
105  const TVectorD& means = *(pca_->GetMeanValues());
106  const TMatrixD& eigens = *(pca_->GetEigenVectors());
107 
108  math::XYZPoint barycenter(means[0], means[1], means[2]);
109  math::XYZVector axis(eigens(0, 0), eigens(1, 0), eigens(2, 0));
110 
111  if (time_norm > 0.0) {
112  avg_time = avg_time / time_norm;
113  } else {
115  }
116 
117  if (axis.z() * barycenter.z() < 0.0) {
118  axis = math::XYZVector(-eigens(0, 0), -eigens(1, 0), -eigens(2, 0));
119  }
120 
121  if (updateTiming_) {
122  cluster.setTime(avg_time);
123  }
124  cluster.setPosition(barycenter);
125  cluster.calculatePositionREP();
126 }
reco::PFClusterCollection
std::vector< PFCluster > PFClusterCollection
collection of PFCluster objects
Definition: PFClusterFwd.h:9
PFRecHitFwd.h
electrons_cff.bool
bool
Definition: electrons_cff.py:372
mps_fire.i
i
Definition: mps_fire.py:355
reco::PFCluster::setTime
void setTime(float time, float timeError=0)
Definition: PFCluster.h:88
MessageLogger.h
reco::PFRecHitFraction
Fraction of a PFRecHit (rechits can be shared between several PFCluster's)
Definition: PFRecHitFraction.h:18
edm::isNotFinite
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
min
T min(T a, T b)
Definition: MathUtil.h:58
reco::PFCluster::setLayer
void setLayer(PFLayer::Layer layer)
set layer
Definition: PFCluster.cc:93
reco::PFCluster::recHitFractions
const std::vector< reco::PFRecHitFraction > & recHitFractions() const
vector of rechit fractions
Definition: PFCluster.h:69
Cluster3DPCACalculator::operator=
Cluster3DPCACalculator & operator=(const Cluster3DPCACalculator &)=delete
PFRecHit.h
edm::Ref< PFRecHitCollection >
PFLayer::NONE
Definition: PFLayer.h:34
Cluster3DPCACalculator::calculateAndSetPositionActual
void calculateAndSetPositionActual(reco::PFCluster &)
Definition: Cluster3DPCACalculator.cc:52
PFCPositionCalculatorBase.h
PFCPositionCalculatorBase
Definition: PFCPositionCalculatorBase.h:14
DEFINE_EDM_PLUGIN
#define DEFINE_EDM_PLUGIN(factory, type, name)
Definition: PluginFactory.h:124
reco::CaloCluster::setPosition
void setPosition(const math::XYZPoint &p)
Definition: CaloCluster.h:140
PFLayer::Layer
Layer
layer definition
Definition: PFLayer.h:29
edm::LogWarning
Definition: MessageLogger.h:141
bsc_activity_cfg.clusters
clusters
Definition: bsc_activity_cfg.py:36
edm::ParameterSet
Definition: ParameterSet.h:36
math::XYZPoint
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
Cluster3DPCACalculator
Definition: Cluster3DPCACalculator.cc:17
edmplugin::PluginFactory
Definition: PluginFactory.h:34
Cluster3DPCACalculator::updateTiming_
const bool updateTiming_
Definition: Cluster3DPCACalculator.cc:30
math::XYZVector
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
reco::PFCluster::calculatePositionREP
void calculatePositionREP()
computes posrep_ once and for all
Definition: PFCluster.h:99
createfilelist.int
int
Definition: createfilelist.py:10
reco::CaloCluster::seed
DetId seed() const
return DetId of seed
Definition: CaloCluster.h:219
reco::CaloCluster::setEnergy
void setEnergy(double energy)
Definition: CaloCluster.h:136
Cluster3DPCACalculator::calculateAndSetPositions
void calculateAndSetPositions(reco::PFClusterCollection &) override
Definition: Cluster3DPCACalculator.cc:45
HGCalDetId.h
isFinite.h
Cluster3DPCACalculator::calculateAndSetPosition
void calculateAndSetPosition(reco::PFCluster &) override
Definition: Cluster3DPCACalculator.cc:40
Exception
Definition: hltDiff.cc:246
reco::PFCluster
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
Definition: PFCluster.h:46
Cluster3DPCACalculator::Cluster3DPCACalculator
Cluster3DPCACalculator(const edm::ParameterSet &conf)
Definition: Cluster3DPCACalculator.cc:19
Cluster3DPCACalculator::showerParameters
void showerParameters(const reco::PFCluster &, math::XYZPoint &, math::XYZVector &)
Cluster3DPCACalculator::pca_
std::unique_ptr< TPrincipal > pca_
Definition: Cluster3DPCACalculator.cc:31