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 edm::ParameterSet &conf)
 
 Cluster3DPCACalculator (const Cluster3DPCACalculator &)=delete
 
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 17 of file Cluster3DPCACalculator.cc.

Constructor & Destructor Documentation

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

Definition at line 19 of file Cluster3DPCACalculator.cc.

References calculateAndSetPosition(), calculateAndSetPositions(), and operator=().

19  :
21  updateTiming_(conf.getParameter<bool>("updateTiming")),
22  pca_(new TPrincipal(3,"D")){
23  }
T getParameter(std::string const &) const
std::unique_ptr< TPrincipal > pca_
PFCPositionCalculatorBase(const edm::ParameterSet &conf)
Cluster3DPCACalculator::Cluster3DPCACalculator ( const Cluster3DPCACalculator )
delete

Member Function Documentation

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

Implements PFCPositionCalculatorBase.

Definition at line 45 of file Cluster3DPCACalculator.cc.

References calculateAndSetPositionActual(), calculateAndSetPositions(), and pca_.

Referenced by Cluster3DPCACalculator().

45  {
46  pca_.reset(new TPrincipal(3,"D"));
48 }
void calculateAndSetPositionActual(reco::PFCluster &)
std::unique_ptr< TPrincipal > pca_
void Cluster3DPCACalculator::calculateAndSetPositionActual ( reco::PFCluster cluster)
private

Definition at line 59 of file Cluster3DPCACalculator.cc.

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().

59  {
60  if( !cluster.seed() ) {
61  throw cms::Exception("ClusterWithNoSeed")
62  << " Found a cluster with no seed: " << cluster;
63  }
64  double cl_energy = 0;
65  double max_e = 0.0;
66  double avg_time = 0.0;
67  double time_norm = 0.0;
68  PFLayer::Layer max_e_layer = PFLayer::NONE;
69  reco::PFRecHitRef refseed;
70  double pcavars[3];
71 
72  for( const reco::PFRecHitFraction& rhf : cluster.recHitFractions() ) {
73  const reco::PFRecHitRef& refhit = rhf.recHitRef();
74  double rh_energy = refhit->energy();
75  double rh_time = refhit->time();
76  cl_energy += rh_energy * rhf.fraction();
77  if( rh_time > 0.0 ) { // time == -1 means no measurement
78  // all times are offset by one nanosecond in digitizer
79  // remove that here so all times of flight
80  // are with respect to (0,0,0)
81  avg_time += (rh_time - 1.0);
82  time_norm += 1.0;
83  }
84  if( rh_energy > max_e ) {
85  max_e = rh_energy;
86  max_e_layer = rhf.recHitRef()->layer();
87  }
88  if( refhit->detId() == cluster.seed() ) refseed = refhit;
89  const double rh_fraction = rhf.fraction();
90  rh_energy = refhit->energy()*rh_fraction;
91  if( edm::isNotFinite(rh_energy) ) {
92 //temporarily changed exception to warning
93 // throw cms::Exception("PFClusterAlgo")
94  edm::LogWarning("PFClusterAlgo")
95  <<"rechit " << refhit->detId() << " has a NaN energy... "
96  << "The input of the particle flow clustering seems to be corrupted.";
97  continue;
98  }
99  pcavars[0] = refhit->position().x();
100  pcavars[1] = refhit->position().y();
101  pcavars[2] = refhit->position().z();
102  int nhit = int( rh_energy*100 ); // put rec_hit energy in units of 10 MeV
103 
104  for( int i = 0; i < nhit; ++i ) {
105  pca_->AddRow(pcavars);
106  }
107 
108  }
109  cluster.setEnergy(cl_energy);
110  cluster.setLayer(max_e_layer);
111  // calculate the position
112 
113  pca_->MakePrincipals();
114  const TVectorD& means = *(pca_->GetMeanValues());
115  const TMatrixD& eigens = *(pca_->GetEigenVectors());
116 
117  math::XYZPoint barycenter(means[0],means[1],means[2]);
118  math::XYZVector axis(eigens(0,0),eigens(1,0),eigens(2,0));
119 
120  if( time_norm > 0.0 ) {
121  avg_time = avg_time/time_norm;
122  } else {
124  }
125 
126  if( axis.z()*barycenter.z() < 0.0 ) {
127  axis = math::XYZVector(-eigens(0,0),-eigens(1,0),-eigens(2,0));
128  }
129 
130  if (updateTiming_) {
131  cluster.setTime(avg_time);
132  }
133  cluster.setPosition(barycenter);
134  cluster.calculatePositionREP();
135 
136 }
void setLayer(PFLayer::Layer layer)
set layer
Definition: PFCluster.cc:112
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
void setPosition(const math::XYZPoint &p)
Definition: CaloCluster.h:117
void setTime(float time, float timeError=0)
Definition: PFCluster.h:92
Fraction of a PFRecHit (rechits can be shared between several PFCluster&#39;s)
void setEnergy(double energy)
Definition: CaloCluster.h:113
void calculatePositionREP()
computes posrep_ once and for all
Definition: PFCluster.h:100
T min(T a, T b)
Definition: MathUtil.h:58
Layer
layer definition
Definition: PFLayer.h:31
DetId seed() const
return DetId of seed
Definition: CaloCluster.h:207
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
std::unique_ptr< TPrincipal > pca_
const std::vector< reco::PFRecHitFraction > & recHitFractions() const
vector of rechit fractions
Definition: PFCluster.h:72
void Cluster3DPCACalculator::calculateAndSetPositions ( reco::PFClusterCollection clusters)
overridevirtual

Implements PFCPositionCalculatorBase.

Definition at line 51 of file Cluster3DPCACalculator.cc.

References calculateAndSetPositionActual(), and pca_.

Referenced by calculateAndSetPosition(), and Cluster3DPCACalculator().

51  {
52  for( reco::PFCluster& cluster : clusters ) {
53  pca_.reset(new TPrincipal(3,"D"));
55  }
56 }
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
Definition: PFCluster.h:47
void calculateAndSetPositionActual(reco::PFCluster &)
std::unique_ptr< TPrincipal > pca_
Cluster3DPCACalculator& Cluster3DPCACalculator::operator= ( const Cluster3DPCACalculator )
delete

Referenced by Cluster3DPCACalculator().

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

Member Data Documentation

std::unique_ptr<TPrincipal> Cluster3DPCACalculator::pca_
private
const bool Cluster3DPCACalculator::updateTiming_
private

Definition at line 31 of file Cluster3DPCACalculator.cc.

Referenced by calculateAndSetPositionActual().