CMS 3D CMS Logo

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...
 
double thrust () const
 thrust value (in the range [0.5, 1.0]) More...
 
template<typename const_iterator >
 Thrust (const_iterator begin, const_iterator end)
 constructor from first and last iterators More...
 

Private Member Functions

Vector axis (const ThetaPhi &tp) const
 
Vector axis (double theta, double phi) 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

Definition at line 38 of file Thrust.h.

Member Typedef Documentation

◆ Vector

spatial vector

Definition at line 41 of file Thrust.h.

Constructor & Destructor Documentation

◆ Thrust()

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

constructor from first and last iterators

Definition at line 44 of file Thrust.h.

44  : thrust_(0), axis_(0, 0, 0), pSum_(0), n_(end - begin), p_(n_) {
45  if (n_ == 0)
46  return;
47  std::vector<const reco::Candidate *> cands;
48  for (const_iterator i = begin; i != end; ++i) {
49  cands.push_back(&*i);
50  }
51  init(cands);
52  }

References HLT_FULL_cff::cands, mps_fire::end, mps_fire::i, init(), and n_.

Member Function Documentation

◆ axis() [1/3]

const Vector& Thrust::axis ( ) const
inline

thrust axis (with magnitude = 1)

Definition at line 56 of file Thrust.h.

56 { return axis_; }

References axis_.

◆ axis() [2/3]

Vector Thrust::axis ( const ThetaPhi tp) const
inlineprivate

Definition at line 73 of file Thrust.h.

73 { return axis(tp.theta, tp.phi); }

References axis(), and cmsswSequenceInfo::tp.

Referenced by axis().

◆ axis() [3/3]

Thrust::Vector Thrust::axis ( double  theta,
double  phi 
) const
private

Definition at line 142 of file Thrust.cc.

142  {
143  double theSin = sin(theta);
144  return Vector(theSin * cos(phi), theSin * sin(phi), cos(theta));
145 }

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

◆ finalAxis()

Thrust::ThetaPhi Thrust::finalAxis ( ThetaPhi  best) const
private

Definition at line 67 of file Thrust.cc.

67  {
68  static const double epsilon = 0.0001;
69  double maxChange1 = 0.0, maxChange2 = 0.0, a = 0.0, b = 0.0, c = 0.0, thr = 0.0;
70  int mandCt = 3, maxCt = 1000;
71  bool done;
72  do {
73  parabola(a, b, c, axis(best), axis(best.theta + epsilon, best.phi), axis(best.theta - epsilon, best.phi));
74  maxChange1 = 10 * (b < 0 ? -1 : 1);
75  if (a != 0)
76  maxChange1 = -b / (2 * a);
77  while (fabs(maxChange1 * epsilon) > pi_4)
78  maxChange1 /= 2;
79  if (maxChange1 == 0 && (best.theta == 0 || best.theta == pi)) {
80  best.phi += pi_2;
81  if (best.phi > pi2)
82  best.phi -= pi2;
83  parabola(a, b, c, axis(best), axis(best.theta + epsilon, best.phi), axis(best.theta - epsilon, best.phi));
84  maxChange1 = 10 * (b < 0 ? -1 : 1);
85  if (a != 0)
86  maxChange1 = -b / (2 * a);
87  }
88  do {
89  // L.L.: fixed odd behavoir adding epsilon (???)
90  thr = thrust(axis(best.theta + maxChange1 * epsilon, best.phi)) + epsilon;
91  if (thr < c)
92  maxChange1 /= 2;
93  } while (thr < c);
94 
95  best.theta += maxChange1 * epsilon;
96  if (best.theta > pi) {
97  best.theta = pi - (best.theta - pi);
98  best.phi += pi;
99  if (best.phi > pi2)
100  best.phi -= pi2;
101  }
102  if (best.theta < 0) {
103  best.theta *= -1;
104  best.phi += pi;
105  if (best.phi > pi2)
106  best.phi -= pi2;
107  }
108  parabola(a, b, c, axis(best), axis(best.theta, best.phi + epsilon), axis(best.theta, best.phi - epsilon));
109  maxChange2 = 10 * (b < 0 ? -1 : 1);
110  if (a != 0)
111  maxChange2 = -b / (2 * a);
112  while (fabs(maxChange2 * epsilon) > pi_4) {
113  maxChange2 /= 2;
114  }
115  do {
116  // L.L.: fixed odd behavoir adding epsilon
117  thr = thrust(axis(best.theta, best.phi + maxChange2 * epsilon)) + epsilon;
118  if (thr < c)
119  maxChange2 /= 2;
120  } while (thr < c);
121  best.phi += maxChange2 * epsilon;
122  if (best.phi > pi2)
123  best.phi -= pi2;
124  if (best.phi < 0)
125  best.phi += pi2;
126  if (mandCt > 0)
127  mandCt--;
128  maxCt--;
129  done = (fabs(maxChange1) > 1 || fabs(maxChange2) > 1 || mandCt) && (maxCt > 0);
130  } while (done);
131 
132  return best;
133 }

References a, b, HltBtagPostValidation_cff::c, fileCollector::done, geometryDiff::epsilon, Thrust::ThetaPhi::phi, pi, pi2, pi_2, pi_4, and Thrust::ThetaPhi::theta.

◆ init()

void Thrust::init ( const std::vector< const reco::Candidate * > &  cands)
private

Definition at line 6 of file Thrust.cc.

6  {
7  int i = 0;
8  for (std::vector<const Candidate*>::const_iterator t = cands.begin(); t != cands.end(); ++t, ++i)
9  pSum_ += (p_[i] = (*t)->momentum()).r();
11  if (axis_.z() < 0)
12  axis_ *= -1;
13  thrust_ = thrust(axis_);
14 }

References HLT_FULL_cff::cands, mps_fire::i, alignCSCRings::r, and submitPVValidationJobs::t.

Referenced by Thrust().

◆ initialAxis()

Thrust::ThetaPhi Thrust::initialAxis ( ) const
private

Definition at line 16 of file Thrust.cc.

16  {
17  static const int nSegsTheta = 10, nSegsPhi = 10, nSegs = nSegsTheta * nSegsPhi;
18  int i, j;
19  double thr[nSegs], max = 0;
20  int indI = 0, indJ = 0, index = -1;
21  for (i = 0; i < nSegsTheta; ++i) {
22  double z = cos(pi * i / (nSegsTheta - 1));
23  double r = sqrt(1 - z * z);
24  for (j = 0; j < nSegsPhi; ++j) {
25  double phi = pi2 * j / nSegsPhi;
26  thr[i * nSegsPhi + j] = thrust(Vector(r * cos(phi), r * sin(phi), z));
27  if (thr[i * nSegsPhi + j] > max) {
28  index = i * nSegsPhi + j;
29  indI = i;
30  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)
43  ind1 -= nSegsPhi;
44  int ind2 = indJ - 1;
45  if (ind2 < 0)
46  ind2 += nSegsPhi;
47  a = (thr[ind1] + thr[ind2] - 2 * c) / 2;
48  b = thr[ind1] - a - c;
49  double maxPhiInd = 0;
50  if (a != 0)
51  maxPhiInd = -b / (2 * a);
52  double maxThetaInd;
53  if (indI == 0 || indI == (nSegsTheta - 1))
54  maxThetaInd = indI;
55  else {
56  ind1 = indI + 1;
57  ind2 = indI - 1;
58  a = (thr[ind1] + thr[ind2] - 2 * c) / 2;
59  b = thr[ind1] - a - c;
60  maxThetaInd = 0;
61  if (a != 0)
62  maxThetaInd = -b / (2 * a);
63  }
64  return ThetaPhi(pi * (maxThetaInd + indI) / (nSegsTheta - 1), pi2 * (maxPhiInd + indJ) / nSegsPhi);
65 }

References a, b, HltBtagPostValidation_cff::c, funct::cos(), mps_fire::i, dqmiolumiharvest::j, SiStripPI::max, pi, pi2, alignCSCRings::r, funct::sin(), and mathSSE::sqrt().

◆ parabola()

void Thrust::parabola ( double &  a,
double &  b,
double &  c,
const Vector a1,
const Vector a2,
const Vector a3 
) const
private

Definition at line 135 of file Thrust.cc.

135  {
136  double t1 = thrust(a1), t2 = thrust(a2), t3 = thrust(a3);
137  a = (t2 - 2 * c + t3) / 2;
138  b = t2 - a - c;
139  c = t1;
140 }

References a, testProducerWithPsetDescEmpty_cfi::a2, b, HltBtagPostValidation_cff::c, RandomServiceHelper::t1, RandomServiceHelper::t2, and RandomServiceHelper::t3.

◆ thrust() [1/2]

double Thrust::thrust ( ) const
inline

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

Definition at line 54 of file Thrust.h.

54 { return thrust_; }

References thrust_.

◆ thrust() [2/2]

double Thrust::thrust ( const Vector theAxis) const
private

Definition at line 147 of file Thrust.cc.

147  {
148  double result = 0;
149  double sum = 0;
150  for (unsigned int i = 0; i < n_; ++i)
151  sum += fabs(axis.Dot(p_[i]));
152  if (pSum_ > 0)
153  result = sum / pSum_;
154  return result;
155 }

References mps_fire::i, and mps_fire::result.

Member Data Documentation

◆ axis_

Vector Thrust::axis_
private

Definition at line 60 of file Thrust.h.

Referenced by axis().

◆ n_

const unsigned int Thrust::n_
private

Definition at line 62 of file Thrust.h.

Referenced by Thrust().

◆ p_

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

Definition at line 63 of file Thrust.h.

◆ pSum_

double Thrust::pSum_
private

Definition at line 61 of file Thrust.h.

◆ thrust_

double Thrust::thrust_
private

Definition at line 59 of file Thrust.h.

Referenced by thrust().

RandomServiceHelper.t2
t2
Definition: RandomServiceHelper.py:257
Thrust::thrust_
double thrust_
Definition: Thrust.h:59
mps_fire.i
i
Definition: mps_fire.py:428
Thrust::axis_
Vector axis_
Definition: Thrust.h:60
pi_2
const double pi_2
Definition: Thrust.cc:4
pi2
const double pi2
Definition: Thrust.cc:4
geometryDiff.epsilon
int epsilon
Definition: geometryDiff.py:26
testProducerWithPsetDescEmpty_cfi.a2
a2
Definition: testProducerWithPsetDescEmpty_cfi.py:35
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Thrust::thrust
double thrust() const
thrust value (in the range [0.5, 1.0])
Definition: Thrust.h:54
Thrust::pSum_
double pSum_
Definition: Thrust.h:61
RandomServiceHelper.t1
t1
Definition: RandomServiceHelper.py:256
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
fileCollector.done
done
Definition: fileCollector.py:123
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
mps_fire.end
end
Definition: mps_fire.py:242
DDAxes::z
Thrust::p_
std::vector< Vector > p_
Definition: Thrust.h:63
theta
Geom::Theta< T > theta() const
Definition: Basic3DVectorLD.h:150
Thrust::Vector
math::XYZVector Vector
spatial vector
Definition: Thrust.h:41
b
double b
Definition: hdecay.h:118
RandomServiceHelper.t3
t3
Definition: RandomServiceHelper.py:258
cmsswSequenceInfo.tp
tp
Definition: cmsswSequenceInfo.py:17
pi_4
const double pi_4
Definition: Thrust.cc:4
HLT_FULL_cff.cands
cands
Definition: HLT_FULL_cff.py:15208
Thrust::finalAxis
ThetaPhi finalAxis(ThetaPhi) const
Definition: Thrust.cc:67
a
double a
Definition: hdecay.h:119
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
Thrust::initialAxis
ThetaPhi initialAxis() const
Definition: Thrust.cc:16
Thrust::n_
const unsigned int n_
Definition: Thrust.h:62
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
alignCSCRings.r
r
Definition: alignCSCRings.py:93
DDAxes::phi
pi
const double pi
Definition: Thrust.cc:4
Thrust::parabola
void parabola(double &a, double &b, double &c, const Vector &, const Vector &, const Vector &) const
Definition: Thrust.cc:135
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
mps_fire.result
result
Definition: mps_fire.py:311
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
Thrust::axis
const Vector & axis() const
thrust axis (with magnitude = 1)
Definition: Thrust.h:56
Thrust::init
void init(const std::vector< const reco::Candidate * > &)
Definition: Thrust.cc:6