CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
Cluster3DPCACalculator Class Reference
Inheritance diagram for Cluster3DPCACalculator:
PFCPositionCalculatorBase

Public Member Functions

void calculateAndSetPosition (reco::PFCluster &) override
 
void calculateAndSetPositions (reco::PFClusterCollection &) override
 
 Cluster3DPCACalculator (const Cluster3DPCACalculator &)=delete
 
 Cluster3DPCACalculator (const edm::ParameterSet &conf)
 
Cluster3DPCACalculatoroperator= (const Cluster3DPCACalculator &)=delete
 
- Public Member Functions inherited from PFCPositionCalculatorBase
const std::string & name () const
 
PosCalcoperator= (const PosCalc &)=delete
 
 PFCPositionCalculatorBase (const edm::ParameterSet &conf)
 
 PFCPositionCalculatorBase (const PosCalc &)=delete
 
virtual void update (const edm::EventSetup &)
 
virtual ~PFCPositionCalculatorBase ()=default
 

Private Member Functions

void calculateAndSetPositionActual (reco::PFCluster &)
 
void showerParameters (const reco::PFCluster &, math::XYZPoint &, math::XYZVector &)
 

Private Attributes

std::unique_ptr< TPrincipal > pca_
 
const bool updateTiming_
 

Additional Inherited Members

- Protected Attributes inherited from PFCPositionCalculatorBase
const float _minFractionInCalc
 

Detailed Description

Definition at line 19 of file Cluster3DPCACalculator.cc.

Constructor & Destructor Documentation

◆ Cluster3DPCACalculator() [1/2]

Cluster3DPCACalculator::Cluster3DPCACalculator ( const edm::ParameterSet conf)
inline

Definition at line 21 of file Cluster3DPCACalculator.cc.

23  updateTiming_(conf.getParameter<bool>("updateTiming")),
24  pca_(new TPrincipal(3, "D")) {}

◆ Cluster3DPCACalculator() [2/2]

Cluster3DPCACalculator::Cluster3DPCACalculator ( const Cluster3DPCACalculator )
delete

Member Function Documentation

◆ calculateAndSetPosition()

void Cluster3DPCACalculator::calculateAndSetPosition ( reco::PFCluster cluster)
overridevirtual

Implements PFCPositionCalculatorBase.

Definition at line 42 of file Cluster3DPCACalculator.cc.

42  {
43  pca_ = std::make_unique<TPrincipal>(3, "D");
45 }

References calculateAndSetPositionActual(), and pca_.

◆ calculateAndSetPositionActual()

void Cluster3DPCACalculator::calculateAndSetPositionActual ( reco::PFCluster cluster)
private

Definition at line 54 of file Cluster3DPCACalculator.cc.

54  {
55  if (!cluster.seed()) {
56  throw cms::Exception("ClusterWithNoSeed") << " Found a cluster with no seed: " << cluster;
57  }
58  double cl_energy = 0;
59  double max_e = 0.0;
60  double avg_time = 0.0;
61  double time_norm = 0.0;
62  PFLayer::Layer max_e_layer = PFLayer::NONE;
63  reco::PFRecHitRef refseed;
64  double pcavars[3];
65 
66  for (const reco::PFRecHitFraction& rhf : cluster.recHitFractions()) {
67  const reco::PFRecHitRef& refhit = rhf.recHitRef();
68  double rh_energy = refhit->energy();
69  double rh_time = refhit->time();
70  cl_energy += rh_energy * rhf.fraction();
71  if (rh_time > 0.0) { // time == -1 means no measurement
72  // all times are offset by one nanosecond in digitizer
73  // remove that here so all times of flight
74  // are with respect to (0,0,0)
75  avg_time += (rh_time - 1.0);
76  time_norm += 1.0;
77  }
78  if (rh_energy > max_e) {
79  max_e = rh_energy;
80  max_e_layer = rhf.recHitRef()->layer();
81  }
82  if (refhit->detId() == cluster.seed())
83  refseed = refhit;
84  const double rh_fraction = rhf.fraction();
85  rh_energy = refhit->energy() * rh_fraction;
86  if (edm::isNotFinite(rh_energy)) {
87  //temporarily changed exception to warning
88  // throw cms::Exception("PFClusterAlgo")
89  edm::LogWarning("PFClusterAlgo") << "rechit " << refhit->detId() << " has a NaN energy... "
90  << "The input of the particle flow clustering seems to be corrupted.";
91  continue;
92  }
93  pcavars[0] = refhit->position().x();
94  pcavars[1] = refhit->position().y();
95  pcavars[2] = refhit->position().z();
96  int nhit = int(rh_energy * 100); // put rec_hit energy in units of 10 MeV
97 
98  for (int i = 0; i < nhit; ++i) {
99  pca_->AddRow(pcavars);
100  }
101  }
102  cluster.setEnergy(cl_energy);
103  cluster.setLayer(max_e_layer);
104  // calculate the position
105 
106  pca_->MakePrincipals();
107  const TVectorD& means = *(pca_->GetMeanValues());
108  const TMatrixD& eigens = *(pca_->GetEigenVectors());
109 
110  math::XYZPoint barycenter(means[0], means[1], means[2]);
111  math::XYZVector axis(eigens(0, 0), eigens(1, 0), eigens(2, 0));
112 
113  if (time_norm > 0.0) {
114  avg_time = avg_time / time_norm;
115  } else {
117  }
118 
119  if (axis.z() * barycenter.z() < 0.0) {
120  axis = math::XYZVector(-eigens(0, 0), -eigens(1, 0), -eigens(2, 0));
121  }
122 
123  if (updateTiming_) {
124  cluster.setTime(avg_time);
125  }
126  cluster.setPosition(barycenter);
127  cluster.calculatePositionREP();
128 }

References reco::PFCluster::calculatePositionREP(), Exception, mps_fire::i, createfilelist::int, edm::isNotFinite(), min(), PFLayer::NONE, pca_, reco::PFCluster::recHitFractions(), reco::CaloCluster::seed(), reco::CaloCluster::setEnergy(), reco::PFCluster::setLayer(), reco::CaloCluster::setPosition(), reco::PFCluster::setTime(), and updateTiming_.

Referenced by calculateAndSetPosition(), and calculateAndSetPositions().

◆ calculateAndSetPositions()

void Cluster3DPCACalculator::calculateAndSetPositions ( reco::PFClusterCollection clusters)
overridevirtual

Implements PFCPositionCalculatorBase.

Definition at line 47 of file Cluster3DPCACalculator.cc.

47  {
48  for (reco::PFCluster& cluster : clusters) {
49  pca_ = std::make_unique<TPrincipal>(3, "D");
51  }
52 }

References calculateAndSetPositionActual(), bsc_activity_cfg::clusters, and pca_.

◆ operator=()

Cluster3DPCACalculator& Cluster3DPCACalculator::operator= ( const Cluster3DPCACalculator )
delete

◆ showerParameters()

void Cluster3DPCACalculator::showerParameters ( const reco::PFCluster ,
math::XYZPoint ,
math::XYZVector  
)
private

Member Data Documentation

◆ pca_

std::unique_ptr<TPrincipal> Cluster3DPCACalculator::pca_
private

◆ updateTiming_

const bool Cluster3DPCACalculator::updateTiming_
private

Definition at line 32 of file Cluster3DPCACalculator.cc.

Referenced by calculateAndSetPositionActual().

mps_fire.i
i
Definition: mps_fire.py:428
reco::PFCluster::setTime
void setTime(float time, float timeError=0)
Definition: PFCluster.h:84
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:49
reco::PFCluster::recHitFractions
const std::vector< reco::PFRecHitFraction > & recHitFractions() const
vector of rechit fractions
Definition: PFCluster.h:65
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
edm::Ref< PFRecHitCollection >
PFLayer::NONE
Definition: PFLayer.h:34
Cluster3DPCACalculator::calculateAndSetPositionActual
void calculateAndSetPositionActual(reco::PFCluster &)
Definition: Cluster3DPCACalculator.cc:54
reco::CaloCluster::setPosition
void setPosition(const math::XYZPoint &p)
Definition: CaloCluster.h:140
PFLayer::Layer
Layer
layer definition
Definition: PFLayer.h:29
bsc_activity_cfg.clusters
clusters
Definition: bsc_activity_cfg.py:36
math::XYZPoint
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
Cluster3DPCACalculator::updateTiming_
const bool updateTiming_
Definition: Cluster3DPCACalculator.cc:32
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:95
PFCPositionCalculatorBase::PFCPositionCalculatorBase
PFCPositionCalculatorBase(const edm::ParameterSet &conf)
Definition: PFCPositionCalculatorBase.h:18
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
Exception
Definition: hltDiff.cc:246
reco::PFCluster
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
Definition: PFCluster.h:42
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Cluster3DPCACalculator::pca_
std::unique_ptr< TPrincipal > pca_
Definition: Cluster3DPCACalculator.cc:33