CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CaloEllipse.cc
Go to the documentation of this file.
1 /*
2  * CaloEllipse.cc
3  *
4  * Created on: 24-Mar-2009
5  * Author: jamie
6  */
7 
9 
10 #include <cmath>
11 
12 
13 using namespace pftools;
14 
16 
17 
18 }
19 
21 
22 }
23 double CaloEllipse::getTheta() const {
24  if (dataPoints_.size() < 2) {
25  return 0.0;
26  }
27 
28  PointVector meanAdj;
29 
31 
32  double sum_dxdx(0.0);
33  double sum_dydy(0.0);
34  double sum_dxdy(0.0);
35  PointCit it = dataPoints_.begin();
36  for (; it != dataPoints_.end(); ++it) {
37  const Point& p = *it;
38  Point q(p.first - mean.first, p.second - mean.second);
39  meanAdj.push_back(q);
40  sum_dxdx += q.first * q.first;
41  sum_dydy += q.second * q.second;
42  sum_dxdy += q.first * q.second;
43  }
44  double theta = 0.5 * atan(2.0 * sum_dxdy / (sum_dydy - sum_dxdx));
45  return theta;
46 }
47 
49 
50  if (dataPoints_.size() < 2) {
51  return Point(0, 0);
52  }
53 
55 
56  PointCit it = dataPoints_.begin();
57  double sum_xx(0.0);
58  double sum_yy(0.0);
59  double theta = getTheta();
60 
61  for (; it != dataPoints_.end(); ++it) {
62  const Point& p = *it;
63  double X = cos(theta) * (p.first - mean.first) - sin(theta) * (p.second
64  - mean.second);
65  double Y = sin(theta) * (p.first - mean.first) + cos(theta) * (p.second
66  - mean.second);
67  sum_xx += X * X;
68  sum_yy += Y * Y;
69  }
70 
71  double a = sigma * sqrt(sum_xx / dataPoints_.size());
72  double b = sigma * sqrt(sum_yy / dataPoints_.size());
73 
74  double major, minor;
75 
76  if(a > b) {
77  major = a;
78  minor = b;
79  } else {
80  major = b;
81  minor = a;
82  }
83 
84  return Point(major, minor);
85 }
86 
89  double a = p.first;
90  double b = p.second;
91  if(a == 0)
92  return 0;
93  double ecc = sqrt((a * a - b * b) / (a * a));
94  return ecc;
95 }
96 
98 
99  if (dataPoints_.size() < 1) {
100  return Point(0, 0);
101  }
102 
103  double x_tot(0.0);
104  double y_tot(0.0);
105  PointCit it = dataPoints_.begin();
106  for (; it != dataPoints_.end(); ++it) {
107  const Point& p = *it;
108  x_tot += p.first;
109  y_tot += p.second;
110 
111  }
112 
113  return Point(x_tot / dataPoints_.size(), y_tot / dataPoints_.size());
114 }
115 
117  cachedTheta_ = 0.0;
118  cachedMinor_ = 0.0;
119  cachedMajor_ = 0.0;
120 
121 }
122 
125  Point axes = getMajorMinorAxes();
126  cachedMajor_ = axes.first;
127  cachedMinor_ = axes.second;
128 }
129 
131  dataPoints_.clear();
132  resetCaches();
133 }
134 
135 std::ostream& pftools::operator<<(std::ostream& s, const pftools::CaloEllipse& em) {
136  s << "CaloEllipse at position = " << toString(em.getPosition()) << ", theta = "
137  << em.getTheta() << ", major/minor axes = " << toString(
138  em.getMajorMinorAxes()) << ", eccentricity = " << em.getEccentricity() << "\n";
139 
140  return s;
141 }
142 
std::vector< Point > dataPoints_
Definition: CaloEllipse.h:59
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Theta< T > theta() const
double getEccentricity() const
Definition: CaloEllipse.cc:87
#define X(str)
Definition: MuonsGrabber.cc:49
Point getMajorMinorAxes(double sigma=1.0) const
Definition: CaloEllipse.cc:48
std::pair< double, double > Point
Definition: CaloEllipse.h:18
T sqrt(T t)
Definition: SSEVec.h:46
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
std::vector< Point > PointVector
Definition: CaloEllipse.h:19
std::string toString(const std::pair< T, T > &aT)
Definition: CaloEllipse.h:72
double getTheta() const
Definition: CaloEllipse.cc:23
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
PointVector::const_iterator PointCit
Definition: CaloEllipse.h:20
std::ostream & operator<<(std::ostream &s, const Calibratable &calib_)
Definition: Calibratable.cc:6
Point getPosition() const
Definition: CaloEllipse.cc:97
virtual ~CaloEllipse()
Definition: CaloEllipse.cc:20