CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes
Thrust Class Reference

#include <Thrust.h>

Classes

struct  ThetaPhi
 

Public Types

typedef math::XYZVector Vector
 spatial vector More...
 

Public Member Functions

const Vectoraxis () const
 thrust axis (with magnitude = 1) More...
 
template<typename const_iterator >
 Thrust (const_iterator begin, const_iterator end)
 constructor from first and last iterators More...
 
double thrust () const
 thrust value (in the range [0.5, 1.0]) More...
 

Private Member Functions

Vector axis (double theta, double phi) const
 
Vector axis (const ThetaPhi &tp) const
 
ThetaPhi finalAxis (ThetaPhi) const
 
void init (const std::vector< const reco::Candidate * > &)
 
ThetaPhi initialAxis () const
 
void parabola (double &a, double &b, double &c, const Vector &, const Vector &, const Vector &) const
 
double thrust (const Vector &theAxis) const
 

Private Attributes

Vector axis_
 
const unsigned int n_
 
std::vector< Vectorp_
 
double pSum_
 
double thrust_
 

Detailed Description

Utility to compute thrust value and axis from a collection of candidates.

Ported from BaBar implementation.

The thrust axis is the vector T which maximises the following expression:

  sum_i=1...N ( | T . p_i | )

t = ------------------------------— sum_i=1...N ( (p_i . _p_i)^(1/2) )

where p_i, i=1...N are the particle momentum vectors. The thrust value is the maximum value of t.

The thrust axis has a two-fold ambiguity due to taking the absolute value of the dot product. This computation returns by convention a thurs axis with a positive component along the z-direction is positive.

The thrust measure the alignment of a collection of particles along a common axis. The lower the thrust, the more spherical the event is. The higher the thrust, the more jet-like the

Author
Luca Lista, INFN
Version
Revision:
1.11
Id:
Thrust.h,v 1.11 2008/03/13 13:28:00 llista Exp

Definition at line 40 of file Thrust.h.

Member Typedef Documentation

spatial vector

Definition at line 43 of file Thrust.h.

Constructor & Destructor Documentation

template<typename const_iterator >
Thrust::Thrust ( const_iterator  begin,
const_iterator  end 
)
inline

constructor from first and last iterators

Definition at line 46 of file Thrust.h.

References end, i, init(), and n_.

46  :
47  thrust_(0), axis_(0, 0, 0), pSum_(0),
48  n_(end - begin), p_(n_) {
49  if (n_ == 0) return;
50  std::vector<const reco::Candidate*> cands;
51  for(const_iterator i = begin; i != end; ++i) {
52  cands.push_back(&*i);
53  }
54  init(cands);
55  }
int i
Definition: DBlmapReader.cc:9
double pSum_
Definition: Thrust.h:64
double thrust_
Definition: Thrust.h:62
const unsigned int n_
Definition: Thrust.h:65
std::vector< Vector > p_
Definition: Thrust.h:66
#define end
Definition: vmac.h:38
Vector axis_
Definition: Thrust.h:63
#define begin
Definition: vmac.h:31
void init(const std::vector< const reco::Candidate * > &)
Definition: Thrust.cc:7

Member Function Documentation

const Vector& Thrust::axis ( ) const
inline

thrust axis (with magnitude = 1)

Definition at line 59 of file Thrust.h.

References axis_.

Referenced by axis().

59 { return axis_; }
Vector axis_
Definition: Thrust.h:63
Thrust::Vector Thrust::axis ( double  theta,
double  phi 
) const
private

Definition at line 135 of file Thrust.cc.

References funct::cos(), and funct::sin().

135  {
136  double theSin = sin(theta);
137  return Vector(theSin * cos(phi), theSin * sin(phi), cos(theta));
138 }
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Theta< T > theta() const
math::XYZVector Vector
spatial vector
Definition: Thrust.h:43
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Definition: DDAxes.h:10
Vector Thrust::axis ( const ThetaPhi tp) const
inlineprivate

Definition at line 76 of file Thrust.h.

References axis(), Thrust::ThetaPhi::phi, and Thrust::ThetaPhi::theta.

76  {
77  return axis(tp.theta, tp.phi);
78  }
const Vector & axis() const
thrust axis (with magnitude = 1)
Definition: Thrust.h:59
Thrust::ThetaPhi Thrust::finalAxis ( ThetaPhi  best) const
private

Definition at line 64 of file Thrust.cc.

References a, b, trackerHits::c, run_regression::done, epsilon, Thrust::ThetaPhi::phi, pi, pi2, pi_2, pi_4, and Thrust::ThetaPhi::theta.

64  {
65  static const double epsilon = 0.0001;
66  double maxChange1=0.0, maxChange2=0.0, a=0.0, b=0.0, c=0.0, thr=0.0;
67  int mandCt = 3, maxCt = 1000;
68  bool done;
69  do {
70  parabola(a, b, c,
71  axis(best),
72  axis(best.theta + epsilon, best.phi),
73  axis(best.theta - epsilon, best.phi));
74  maxChange1 = 10*(b < 0 ? -1 : 1);
75  if (a != 0) maxChange1 = - b/(2*a);
76  while (fabs(maxChange1 * epsilon) > pi_4) maxChange1 /= 2;
77  if (maxChange1 == 0 && (best.theta == 0 || best.theta == pi)) {
78  best.phi += pi_2;
79  if (best.phi > pi2) best.phi -= pi2;
80  parabola(a, b, c,
81  axis(best),
82  axis(best.theta + epsilon, best.phi),
83  axis(best.theta - epsilon, best.phi));
84  maxChange1 = 10 * (b < 0 ? -1 : 1);
85  if (a != 0) maxChange1 = - b / (2 * a);
86  }
87  do {
88  // L.L.: fixed odd behavoir adding epsilon (???)
89  thr = thrust(axis(best.theta + maxChange1 * epsilon, best.phi)) + epsilon;
90  if (thr < c) maxChange1 /= 2;
91  } while (thr < c);
92 
93  best.theta += maxChange1 * epsilon;
94  if (best.theta > pi) {
95  best.theta = pi - (best.theta - pi);
96  best.phi += pi;
97  if (best.phi > pi2) best.phi -= pi2;
98  }
99  if (best.theta < 0) {
100  best.theta *= -1;
101  best.phi += pi;
102  if (best.phi > pi2) best.phi -= pi2;
103  }
104  parabola(a, b, c,
105  axis(best),
106  axis(best.theta, best.phi + epsilon),
107  axis(best.theta, best.phi - epsilon));
108  maxChange2 = 10 * (b < 0 ? -1 : 1);
109  if (a != 0) maxChange2 = - b / (2 * a);
110  while (fabs(maxChange2 * epsilon) > pi_4) { maxChange2 /= 2; }
111  do {
112  // L.L.: fixed odd behavoir adding epsilon
113  thr = thrust(axis(best.theta, best.phi + maxChange2 * epsilon)) + epsilon;
114  if (thr < c) maxChange2 /= 2;
115  } while (thr < c);
116  best.phi += maxChange2 * epsilon;
117  if (best.phi > pi2) best.phi -= pi2;
118  if (best.phi < 0) best.phi += pi2;
119  if (mandCt > 0) mandCt --;
120  maxCt --;
121  done = (fabs(maxChange1) > 1 || fabs(maxChange2) > 1 || mandCt) && (maxCt > 0);
122  } while (done);
123 
124  return best;
125 }
const double pi_2
Definition: Thrust.cc:5
const Vector & axis() const
thrust axis (with magnitude = 1)
Definition: Thrust.h:59
const double pi2
Definition: Thrust.cc:5
const double pi_4
Definition: Thrust.cc:5
double thrust() const
thrust value (in the range [0.5, 1.0])
Definition: Thrust.h:57
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
void parabola(double &a, double &b, double &c, const Vector &, const Vector &, const Vector &) const
Definition: Thrust.cc:127
const double epsilon
double pi
void Thrust::init ( const std::vector< const reco::Candidate * > &  cands)
private

Definition at line 7 of file Thrust.cc.

References axis_, i, alignCSCRings::r, and lumiQTWidget::t.

Referenced by Thrust().

7  {
8  int i = 0;
9  for(std::vector<const Candidate*>::const_iterator t = cands.begin();
10  t != cands.end(); ++t, ++i)
11  pSum_ += (p_[i] = (*t)->momentum()).r();
13  if (axis_.z() < 0) axis_ *= -1;
14  thrust_ = thrust(axis_);
15 }
int i
Definition: DBlmapReader.cc:9
const Vector & axis() const
thrust axis (with magnitude = 1)
Definition: Thrust.h:59
ThetaPhi initialAxis() const
Definition: Thrust.cc:17
double pSum_
Definition: Thrust.h:64
double thrust_
Definition: Thrust.h:62
std::vector< Vector > p_
Definition: Thrust.h:66
double thrust() const
thrust value (in the range [0.5, 1.0])
Definition: Thrust.h:57
Vector axis_
Definition: Thrust.h:63
ThetaPhi finalAxis(ThetaPhi) const
Definition: Thrust.cc:64
Thrust::ThetaPhi Thrust::initialAxis ( ) const
private

Definition at line 17 of file Thrust.cc.

References a, b, trackerHits::c, funct::cos(), i, getHLTprescales::index, j, max(), phi, pi, pi2, alignCSCRings::r, funct::sin(), mathSSE::sqrt(), and detailsBasic3DVector::z.

17  {
18  static const int nSegsTheta = 10, nSegsPhi = 10, nSegs = nSegsTheta * nSegsPhi;
19  int i, j;
20  double thr[nSegs], max = 0;
21  int indI = 0, indJ = 0, index = -1;
22  for (i = 0; i < nSegsTheta ; ++i) {
23  double z = cos(pi * i / (nSegsTheta - 1));
24  double r = sqrt(1 - z*z);
25  for (j = 0; j < nSegsPhi ; ++j) {
26  double phi = pi2 * j / nSegsPhi;
27  thr[i * nSegsPhi + j] = thrust(Vector(r*cos(phi), r*sin(phi), z));
28  if (thr[i*nSegsPhi + j] > max) {
29  index = i*nSegsPhi + j;
30  indI = i; indJ = j;
31  max = thr[index];
32  }
33  }
34  }
35 
36  // take max and one point on either size, fitting to a parabola and
37  // extrapolating to the real max. Do this separately for each dimension.
38  // y = a x^2 + b x + c. At the max, x = 0, on either side, x = +/-1.
39  // do phi first
40  double a, b, c = max;
41  int ind1 = indJ + 1;
42  if (ind1 >= nSegsPhi) ind1 -= nSegsPhi;
43  int ind2 = indJ - 1;
44  if (ind2 < 0) ind2 += nSegsPhi;
45  a = (thr[ind1] + thr[ind2] - 2*c) / 2;
46  b = thr[ind1] - a - c;
47  double maxPhiInd = 0;
48  if (a != 0) maxPhiInd = -b/(2*a);
49  double maxThetaInd;
50  if (indI == 0 || indI == (nSegsTheta - 1))
51  maxThetaInd = indI;
52  else {
53  ind1 = indI + 1;
54  ind2 = indI - 1;
55  a = (thr[ind1] + thr[ind2] - 2*c) / 2;
56  b = thr[ind1] - a - c;
57  maxThetaInd = 0;
58  if (a != 0) maxThetaInd = - b/(2*a);
59  }
60  return ThetaPhi(pi*(maxThetaInd + indI) / (nSegsTheta - 1),
61  pi2*(maxPhiInd + indJ) / nSegsPhi);
62 }
int i
Definition: DBlmapReader.cc:9
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
const double pi2
Definition: Thrust.cc:5
float float float z
math::XYZVector Vector
spatial vector
Definition: Thrust.h:43
const T & max(const T &a, const T &b)
T sqrt(T t)
Definition: SSEVec.h:48
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
double thrust() const
thrust value (in the range [0.5, 1.0])
Definition: Thrust.h:57
int j
Definition: DBlmapReader.cc:9
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
double pi
Definition: DDAxes.h:10
void Thrust::parabola ( double &  a,
double &  b,
double &  c,
const Vector a1,
const Vector a2,
const Vector a3 
) const
private

Definition at line 127 of file Thrust.cc.

References trackerHits::c, and reco::t2.

128  {
129  double t1 = thrust(a1), t2 = thrust(a2), t3 = thrust(a3);
130  a = (t2 - 2 * c + t3) / 2;
131  b = t2 - a - c;
132  c = t1;
133 }
auto const T2 &decltype(t1.eta()) t2
Definition: deltaR.h:18
double thrust() const
thrust value (in the range [0.5, 1.0])
Definition: Thrust.h:57
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
double Thrust::thrust ( ) const
inline

thrust value (in the range [0.5, 1.0])

Definition at line 57 of file Thrust.h.

References thrust_.

Referenced by Rivet::CMS_EWK_11_021::analyze().

57 { return thrust_; }
double thrust_
Definition: Thrust.h:62
double Thrust::thrust ( const Vector theAxis) const
private

Definition at line 140 of file Thrust.cc.

References i, and query::result.

140  {
141  double result = 0;
142  double sum = 0;
143  for (unsigned int i = 0; i < n_; ++i)
144  sum += fabs(axis.Dot(p_[i]));
145  if (pSum_ > 0) result = sum / pSum_;
146  return result;
147 }
int i
Definition: DBlmapReader.cc:9
const Vector & axis() const
thrust axis (with magnitude = 1)
Definition: Thrust.h:59
double pSum_
Definition: Thrust.h:64
tuple result
Definition: query.py:137
const unsigned int n_
Definition: Thrust.h:65
std::vector< Vector > p_
Definition: Thrust.h:66

Member Data Documentation

Vector Thrust::axis_
private

Definition at line 63 of file Thrust.h.

Referenced by axis().

const unsigned int Thrust::n_
private

Definition at line 65 of file Thrust.h.

Referenced by Thrust().

std::vector<Vector> Thrust::p_
private

Definition at line 66 of file Thrust.h.

double Thrust::pSum_
private

Definition at line 64 of file Thrust.h.

double Thrust::thrust_
private

Definition at line 62 of file Thrust.h.

Referenced by thrust().