CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
EventShapeVariables Class Reference

Class for the calculation of several event shape variables. More...

#include "PhysicsTools/CandUtils/interface/EventShapeVariables.h"

Public Member Functions

double aplanarity ()
 
double C ()
 
double circularity (const unsigned int &numberOfSteps=1000) const
 
double D ()
 
 EventShapeVariables (const edm::View< reco::Candidate > &inputVectors)
 constructor from reco::Candidates More...
 
 EventShapeVariables (const std::vector< math::RhoEtaPhiVector > &inputVectors)
 constructor from rho eta phi coordinates More...
 
 EventShapeVariables (const std::vector< math::RThetaPhiVector > &inputVectors)
 constructor from r theta phi coordinates More...
 
 EventShapeVariables (const std::vector< math::XYZVector > &inputVectors)
 constructor from XYZ coordinates More...
 
const std::vector< double > & getEigenValues ()
 
const std::vector< double > & getEigenValuesNoNorm ()
 
const TMatrixD & getEigenVectors ()
 
double getFWmoment (unsigned l)
 
const std::vector< double > & getFWmoments ()
 
double isotropy (const unsigned int &numberOfSteps=1000) const
 
void set_r (double r)
 set exponent for computation of momentum tensor and related products More...
 
void setFWmax (unsigned m)
 set number of Fox-Wolfram moments to compute More...
 
double sphericity ()
 
 ~EventShapeVariables ()
 default destructor More...
 

Private Member Functions

void compTensorsAndVectors ()
 
void computeFWmoments ()
 

Private Attributes

std::vector< double > eigenValues_
 
std::vector< double > eigenValuesNoNorm_
 
TVectorD eigenValuesNoNormTmp_
 
TVectorD eigenValuesTmp_
 
TMatrixD eigenVectors_
 
std::vector< double > fwmom_
 
bool fwmom_computed_
 
unsigned fwmom_maxl_
 Owen ; save computed Fox-Wolfram moments. More...
 
std::vector< math::XYZVectorinputVectors_
 caching of input vectors More...
 
double r_
 caching of output More...
 
bool tensors_computed_
 

Detailed Description

Class for the calculation of several event shape variables.

Class for the calculation of several event shape variables. Isotropy, sphericity, aplanarity and circularity are supported. The class supports vectors of 3d vectors and edm::Views of reco::Candidates as input. The 3d vectors can be given in cartesian, cylindrical or polar coordinates. It exploits the ROOT::TMatrixDSym for the calculation of the sphericity and aplanarity.

See https://arxiv.org/pdf/hep-ph/0603175v2.pdf#page=524 for an explanation of sphericity, aplanarity and the quantities C and D.

Author: Sebastian Naumann-Emme, University of Hamburg Roger Wolf, University of Hamburg Christian Veelken, UC Davis

Definition at line 32 of file EventShapeVariables.h.

Constructor & Destructor Documentation

◆ EventShapeVariables() [1/4]

EventShapeVariables::EventShapeVariables ( const edm::View< reco::Candidate > &  inputVectors)
explicit

constructor from reco::Candidates

Definition at line 6 of file EventShapeVariables.cc.

6  : eigenVectors_(3, 3) {
7  inputVectors_.reserve(inputVectors.size());
8  for (const auto& vec : inputVectors) {
9  inputVectors_.push_back(math::XYZVector(vec.px(), vec.py(), vec.pz()));
10  }
11  //default values
12  set_r(2.);
13  setFWmax(10);
14 }

References inputVectors_, set_r(), setFWmax(), and edm::View< T >::size().

◆ EventShapeVariables() [2/4]

EventShapeVariables::EventShapeVariables ( const std::vector< math::XYZVector > &  inputVectors)
explicit

constructor from XYZ coordinates

Definition at line 17 of file EventShapeVariables.cc.

18  : inputVectors_(inputVectors), eigenVectors_(3, 3) {
19  //default values
20  set_r(2.);
21  setFWmax(10);
22 }

References set_r(), and setFWmax().

◆ EventShapeVariables() [3/4]

EventShapeVariables::EventShapeVariables ( const std::vector< math::RhoEtaPhiVector > &  inputVectors)
explicit

constructor from rho eta phi coordinates

Definition at line 25 of file EventShapeVariables.cc.

25  : eigenVectors_(3, 3) {
26  inputVectors_.reserve(inputVectors.size());
27  for (const auto& vec : inputVectors) {
28  inputVectors_.push_back(math::XYZVector(vec.x(), vec.y(), vec.z()));
29  }
30  //default values
31  set_r(2.);
32  setFWmax(10);
33 }

References inputVectors_, set_r(), and setFWmax().

◆ EventShapeVariables() [4/4]

EventShapeVariables::EventShapeVariables ( const std::vector< math::RThetaPhiVector > &  inputVectors)
explicit

constructor from r theta phi coordinates

Definition at line 36 of file EventShapeVariables.cc.

36  : eigenVectors_(3, 3) {
37  inputVectors_.reserve(inputVectors.size());
38  for (const auto& vec : inputVectors) {
39  inputVectors_.push_back(math::XYZVector(vec.x(), vec.y(), vec.z()));
40  }
41  //default values
42  set_r(2.);
43  setFWmax(10);
44 }

References inputVectors_, set_r(), and setFWmax().

◆ ~EventShapeVariables()

EventShapeVariables::~EventShapeVariables ( )
inline

default destructor

Definition at line 43 of file EventShapeVariables.h.

43 {};

Member Function Documentation

◆ aplanarity()

double EventShapeVariables::aplanarity ( )

1.5*q2 where q0>=q1>=q2>=0 are the eigenvalues of the momentum tensor sum{p_j[a]*p_j[b]}/sum{p_j**2} normalized to 1. Return values are 0.5 for spherical and 0 for plane and linear events

Definition at line 166 of file EventShapeVariables.cc.

166  {
167  if (!tensors_computed_)
169  return 1.5 * eigenValues_[2];
170 }

References compTensorsAndVectors(), eigenValues_, and tensors_computed_.

Referenced by TtFullHadSignalSel::TtFullHadSignalSel().

◆ C()

double EventShapeVariables::C ( )

3.*(q0*q1+q0*q2+q1*q2) where q0>=q1>=q2>=0 are the eigenvalues of the momentum tensor sum{p_j[a]*p_j[b]}/sum{p_j**2} normalized to 1. Return value is between 0 and 1 and measures the 3-jet structure of the event (C vanishes for a "perfect" 2-jet event)

Definition at line 175 of file EventShapeVariables.cc.

175  {
176  if (!tensors_computed_)
178  return 3. *
180 }

References compTensorsAndVectors(), eigenValues_, and tensors_computed_.

Referenced by TtFullHadSignalSel::TtFullHadSignalSel().

◆ circularity()

double EventShapeVariables::circularity ( const unsigned int &  numberOfSteps = 1000) const

the return value is 1 for spherical and 0 linear events in r-phi. This function needs the number of steps to determine how fine the granularity of the algorithm in phi should be

Definition at line 71 of file EventShapeVariables.cc.

71  {
72  const double deltaPhi = 2 * TMath::Pi() / numberOfSteps;
73  double circularity = -1, phi = 0, area = 0;
74  for (const auto& vec : inputVectors_) {
75  area += TMath::Sqrt(vec.x() * vec.x() + vec.y() * vec.y());
76  }
77  for (unsigned int i = 0; i < numberOfSteps; ++i) {
78  phi += deltaPhi;
79  double sum = 0, tmp = 0.;
80  double cosphi = TMath::Cos(phi);
81  double sinphi = TMath::Sin(phi);
82  for (const auto& vec : inputVectors_) {
83  sum += TMath::Abs(cosphi * vec.x() + sinphi * vec.y());
84  }
85  tmp = TMath::Pi() / 2 * sum / area;
86  if (circularity < 0 || tmp < circularity) {
87  circularity = tmp;
88  }
89  }
90  return circularity;
91 }

References Abs(), custom_jme_cff::area, SiPixelRawToDigiRegional_cfi::deltaPhi, mps_fire::i, inputVectors_, photonAnalyzer_cfi::numberOfSteps, phi, Pi, and createJobs::tmp.

Referenced by TtFullHadSignalSel::TtFullHadSignalSel().

◆ compTensorsAndVectors()

void EventShapeVariables::compTensorsAndVectors ( )
private

helper function to fill the 3 dimensional momentum tensor from the inputVectors where needed also fill the 3 dimensional vectors of eigen-values and eigen-vectors; the largest (smallest) eigen-value is stored at index position 0 (2)

Definition at line 105 of file EventShapeVariables.cc.

105  {
106  if (tensors_computed_)
107  return;
108 
109  if (inputVectors_.size() < 2) {
110  tensors_computed_ = true;
111  return;
112  }
113 
114  TMatrixDSym momentumTensor(3);
115  momentumTensor.Zero();
116 
117  // fill momentumTensor from inputVectors
118  double norm = 0.;
119  for (const auto& vec : inputVectors_) {
120  double p2 = vec.Dot(vec);
121  double pR = (r_ == 2.) ? p2 : TMath::Power(p2, 0.5 * r_);
122  norm += pR;
123  double pRminus2 = (r_ == 2.) ? 1. : TMath::Power(p2, 0.5 * r_ - 1.);
124  momentumTensor(0, 0) += pRminus2 * vec.x() * vec.x();
125  momentumTensor(0, 1) += pRminus2 * vec.x() * vec.y();
126  momentumTensor(0, 2) += pRminus2 * vec.x() * vec.z();
127  momentumTensor(1, 0) += pRminus2 * vec.y() * vec.x();
128  momentumTensor(1, 1) += pRminus2 * vec.y() * vec.y();
129  momentumTensor(1, 2) += pRminus2 * vec.y() * vec.z();
130  momentumTensor(2, 0) += pRminus2 * vec.z() * vec.x();
131  momentumTensor(2, 1) += pRminus2 * vec.z() * vec.y();
132  momentumTensor(2, 2) += pRminus2 * vec.z() * vec.z();
133  }
134 
135  if (momentumTensor.IsSymmetric() && (momentumTensor.NonZeros() != 0)) {
136  momentumTensor.EigenVectors(eigenValuesNoNormTmp_);
137  }
141 
142  // momentumTensor normalized to determinant 1
143  momentumTensor *= (1. / norm);
144 
145  // now get eigens
146  if (momentumTensor.IsSymmetric() && (momentumTensor.NonZeros() != 0)) {
147  eigenVectors_ = momentumTensor.EigenVectors(eigenValuesTmp_);
148  }
152 
153  tensors_computed_ = true;
154 }

References eigenValues_, eigenValuesNoNorm_, eigenValuesNoNormTmp_, eigenValuesTmp_, eigenVectors_, inputVectors_, p2, r_, and tensors_computed_.

Referenced by aplanarity(), C(), D(), getEigenValues(), getEigenValuesNoNorm(), getEigenVectors(), and sphericity().

◆ computeFWmoments()

void EventShapeVariables::computeFWmoments ( )
private

reduce computation by exploiting symmetry: all off-diagonal elements appear twice in the sum

compute higher legendre polynomials recursively need to keep track of two previous values

initial cases

store new value

Definition at line 218 of file EventShapeVariables.cc.

218  {
219  if (fwmom_computed_)
220  return;
221 
222  double esum_total(0.);
223  for (unsigned int i = 0; i < inputVectors_.size(); i++) {
224  esum_total += inputVectors_[i].R();
225  } // i
226  double esum_total_sq = esum_total * esum_total;
227 
228  for (unsigned int i = 0; i < inputVectors_.size(); i++) {
229  double p_i = inputVectors_[i].R();
230  if (p_i <= 0)
231  continue;
232 
233  for (unsigned int j = 0; j <= i; j++) {
234  double p_j = inputVectors_[j].R();
235  if (p_j <= 0)
236  continue;
237 
240  int symmetry_factor = 2;
241  if (j == i)
242  symmetry_factor = 1;
243  double p_ij = p_i * p_j;
244  double cosTheta = inputVectors_[i].Dot(inputVectors_[j]) / (p_ij);
245  double pi_pj_over_etot2 = p_ij / esum_total_sq;
246 
249  double Pn1 = 0;
250  double Pn2 = 0;
251  for (unsigned n = 0; n < fwmom_maxl_; n++) {
253  if (n == 0) {
254  Pn2 = pi_pj_over_etot2;
255  fwmom_[0] += Pn2 * symmetry_factor;
256  } else if (n == 1) {
257  Pn1 = pi_pj_over_etot2 * cosTheta;
258  fwmom_[1] += Pn1 * symmetry_factor;
259  } else {
260  double Pn = ((2 * n - 1) * cosTheta * Pn1 - (n - 1) * Pn2) / n;
261  fwmom_[n] += Pn * symmetry_factor;
263  Pn2 = Pn1;
264  Pn1 = Pn;
265  }
266  }
267 
268  } // j
269  } // i
270 
271  fwmom_computed_ = true;
272 
273 } // computeFWmoments

References fwmom_, fwmom_computed_, fwmom_maxl_, mps_fire::i, inputVectors_, dqmiolumiharvest::j, and dqmiodumpmetadata::n.

Referenced by getFWmoment(), and getFWmoments().

◆ D()

double EventShapeVariables::D ( )

27.*(q0*q1*q2) where q0>=q1>=q2>=0 are the eigenvalues of the momentum tensor sum{p_j[a]*p_j[b]}/sum{p_j**2} normalized to 1. Return value is between 0 and 1 and measures the 4-jet structure of the event (D vanishes for a planar event)

27.*(q0*q1*q2) where q0>=q1>=q2>=0 are the eigenvalues of the momemtum tensor sum{p_j[a]*p_j[b]}/sum{p_j**2} normalized to 1. Return value is between 0 and 1 and measures the 4-jet structure of the event (D vanishes for a planar event)

Definition at line 185 of file EventShapeVariables.cc.

185  {
186  if (!tensors_computed_)
188  return 27. * eigenValues_[0] * eigenValues_[1] * eigenValues_[2];
189 }

References compTensorsAndVectors(), eigenValues_, and tensors_computed_.

Referenced by TtFullHadSignalSel::TtFullHadSignalSel().

◆ getEigenValues()

const std::vector<double>& EventShapeVariables::getEigenValues ( )
inline

Definition at line 77 of file EventShapeVariables.h.

77  {
78  if (!tensors_computed_)
80  return eigenValues_;
81  }

References compTensorsAndVectors(), eigenValues_, and tensors_computed_.

◆ getEigenValuesNoNorm()

const std::vector<double>& EventShapeVariables::getEigenValuesNoNorm ( )
inline

Definition at line 82 of file EventShapeVariables.h.

82  {
83  if (!tensors_computed_)
85  return eigenValuesNoNorm_;
86  }

References compTensorsAndVectors(), eigenValuesNoNorm_, and tensors_computed_.

◆ getEigenVectors()

const TMatrixD& EventShapeVariables::getEigenVectors ( )
inline

Definition at line 87 of file EventShapeVariables.h.

87  {
88  if (!tensors_computed_)
90  return eigenVectors_;
91  }

References compTensorsAndVectors(), eigenVectors_, and tensors_computed_.

◆ getFWmoment()

double EventShapeVariables::getFWmoment ( unsigned  l)

Definition at line 200 of file EventShapeVariables.cc.

200  {
201  if (l > fwmom_maxl_)
202  return 0.;
203 
204  if (!fwmom_computed_)
206 
207  return fwmom_[l];
208 
209 } // getFWmoment

References computeFWmoments(), fwmom_, fwmom_computed_, fwmom_maxl_, and cmsLHEtoEOSManager::l.

◆ getFWmoments()

const std::vector< double > & EventShapeVariables::getFWmoments ( )

Definition at line 211 of file EventShapeVariables.cc.

211  {
212  if (!fwmom_computed_)
214 
215  return fwmom_;
216 }

References computeFWmoments(), fwmom_, and fwmom_computed_.

◆ isotropy()

double EventShapeVariables::isotropy ( const unsigned int &  numberOfSteps = 1000) const

the return value is 1 for spherical events and 0 for events linear in r-phi. This function needs the number of steps to determine how fine the granularity of the algorithm in phi should be

Definition at line 49 of file EventShapeVariables.cc.

49  {
50  const double deltaPhi = 2 * TMath::Pi() / numberOfSteps;
51  double phi = 0, eIn = -1., eOut = -1.;
52  for (unsigned int i = 0; i < numberOfSteps; ++i) {
53  phi += deltaPhi;
54  double sum = 0;
55  double cosphi = TMath::Cos(phi);
56  double sinphi = TMath::Sin(phi);
57  for (const auto& vec : inputVectors_) {
58  // sum over inner product of unit vectors and momenta
59  sum += TMath::Abs(cosphi * vec.x() + sinphi * vec.y());
60  }
61  if (eOut < 0. || sum < eOut)
62  eOut = sum;
63  if (eIn < 0. || sum > eIn)
64  eIn = sum;
65  }
66  return (eIn - eOut) / eIn;
67 }

References Abs(), SiPixelRawToDigiRegional_cfi::deltaPhi, mps_fire::i, inputVectors_, photonAnalyzer_cfi::numberOfSteps, phi, and Pi.

Referenced by TtFullHadSignalSel::TtFullHadSignalSel().

◆ set_r()

void EventShapeVariables::set_r ( double  r)

set exponent for computation of momentum tensor and related products

invalidate previous cached computations

Definition at line 94 of file EventShapeVariables.cc.

94  {
95  r_ = r;
97  tensors_computed_ = false;
98  eigenValues_ = std::vector<double>(3, 0);
99  eigenValuesNoNorm_ = std::vector<double>(3, 0);
100 }

References eigenValues_, eigenValuesNoNorm_, alignCSCRings::r, r_, and tensors_computed_.

Referenced by EventShapeVariables().

◆ setFWmax()

void EventShapeVariables::setFWmax ( unsigned  m)

set number of Fox-Wolfram moments to compute

Definition at line 194 of file EventShapeVariables.cc.

194  {
195  fwmom_maxl_ = m;
196  fwmom_computed_ = false;
197  fwmom_ = std::vector<double>(fwmom_maxl_, 0.);
198 }

References fwmom_, fwmom_computed_, fwmom_maxl_, and visualization-live-secondInstance_cfg::m.

Referenced by EventShapeVariables().

◆ sphericity()

double EventShapeVariables::sphericity ( )

1.5*(q1+q2) where q0>=q1>=q2>=0 are the eigenvalues of the momentum tensor sum{p_j[a]*p_j[b]}/sum{p_j**2} normalized to 1. Return values are 1 for spherical, 3/4 for plane and 0 for linear events

Definition at line 158 of file EventShapeVariables.cc.

158  {
159  if (!tensors_computed_)
161  return 1.5 * (eigenValues_[1] + eigenValues_[2]);
162 }

References compTensorsAndVectors(), eigenValues_, and tensors_computed_.

Referenced by TtFullHadSignalSel::TtFullHadSignalSel().

Member Data Documentation

◆ eigenValues_

std::vector<double> EventShapeVariables::eigenValues_
private

◆ eigenValuesNoNorm_

std::vector<double> EventShapeVariables::eigenValuesNoNorm_
private

Definition at line 112 of file EventShapeVariables.h.

Referenced by compTensorsAndVectors(), getEigenValuesNoNorm(), and set_r().

◆ eigenValuesNoNormTmp_

TVectorD EventShapeVariables::eigenValuesNoNormTmp_
private

Definition at line 111 of file EventShapeVariables.h.

Referenced by compTensorsAndVectors().

◆ eigenValuesTmp_

TVectorD EventShapeVariables::eigenValuesTmp_
private

Definition at line 111 of file EventShapeVariables.h.

Referenced by compTensorsAndVectors().

◆ eigenVectors_

TMatrixD EventShapeVariables::eigenVectors_
private

Definition at line 110 of file EventShapeVariables.h.

Referenced by compTensorsAndVectors(), and getEigenVectors().

◆ fwmom_

std::vector<double> EventShapeVariables::fwmom_
private

Definition at line 116 of file EventShapeVariables.h.

Referenced by computeFWmoments(), getFWmoment(), getFWmoments(), and setFWmax().

◆ fwmom_computed_

bool EventShapeVariables::fwmom_computed_
private

Definition at line 117 of file EventShapeVariables.h.

Referenced by computeFWmoments(), getFWmoment(), getFWmoments(), and setFWmax().

◆ fwmom_maxl_

unsigned EventShapeVariables::fwmom_maxl_
private

Owen ; save computed Fox-Wolfram moments.

Definition at line 115 of file EventShapeVariables.h.

Referenced by computeFWmoments(), getFWmoment(), and setFWmax().

◆ inputVectors_

std::vector<math::XYZVector> EventShapeVariables::inputVectors_
private

caching of input vectors

Definition at line 105 of file EventShapeVariables.h.

Referenced by circularity(), compTensorsAndVectors(), computeFWmoments(), EventShapeVariables(), and isotropy().

◆ r_

double EventShapeVariables::r_
private

caching of output

Definition at line 108 of file EventShapeVariables.h.

Referenced by compTensorsAndVectors(), and set_r().

◆ tensors_computed_

bool EventShapeVariables::tensors_computed_
private
mps_fire.i
i
Definition: mps_fire.py:428
EventShapeVariables::eigenValues_
std::vector< double > eigenValues_
Definition: EventShapeVariables.h:112
EventShapeVariables::fwmom_
std::vector< double > fwmom_
Definition: EventShapeVariables.h:116
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
EventShapeVariables::circularity
double circularity(const unsigned int &numberOfSteps=1000) const
Definition: EventShapeVariables.cc:71
EventShapeVariables::fwmom_computed_
bool fwmom_computed_
Definition: EventShapeVariables.h:117
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
Abs
T Abs(T a)
Definition: MathUtil.h:49
SiPixelRawToDigiRegional_cfi.deltaPhi
deltaPhi
Definition: SiPixelRawToDigiRegional_cfi.py:9
EventShapeVariables::set_r
void set_r(double r)
set exponent for computation of momentum tensor and related products
Definition: EventShapeVariables.cc:94
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:79
p2
double p2[4]
Definition: TauolaWrapper.h:90
EventShapeVariables::eigenValuesNoNormTmp_
TVectorD eigenValuesNoNormTmp_
Definition: EventShapeVariables.h:111
edm::View::size
size_type size() const
EventShapeVariables::compTensorsAndVectors
void compTensorsAndVectors()
Definition: EventShapeVariables.cc:105
math::XYZVector
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
EventShapeVariables::setFWmax
void setFWmax(unsigned m)
set number of Fox-Wolfram moments to compute
Definition: EventShapeVariables.cc:194
EventShapeVariables::eigenValuesTmp_
TVectorD eigenValuesTmp_
Definition: EventShapeVariables.h:111
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:204
EventShapeVariables::eigenValuesNoNorm_
std::vector< double > eigenValuesNoNorm_
Definition: EventShapeVariables.h:112
alignCSCRings.r
r
Definition: alignCSCRings.py:93
EventShapeVariables::tensors_computed_
bool tensors_computed_
Definition: EventShapeVariables.h:109
photonAnalyzer_cfi.numberOfSteps
numberOfSteps
Definition: photonAnalyzer_cfi.py:28
EventShapeVariables::inputVectors_
std::vector< math::XYZVector > inputVectors_
caching of input vectors
Definition: EventShapeVariables.h:105
DDAxes::phi
EventShapeVariables::eigenVectors_
TMatrixD eigenVectors_
Definition: EventShapeVariables.h:110
EventShapeVariables::computeFWmoments
void computeFWmoments()
Definition: EventShapeVariables.cc:218
Pi
const double Pi
Definition: CosmicMuonParameters.h:18
EventShapeVariables::r_
double r_
caching of output
Definition: EventShapeVariables.h:108
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
EventShapeVariables::fwmom_maxl_
unsigned fwmom_maxl_
Owen ; save computed Fox-Wolfram moments.
Definition: EventShapeVariables.h:115
custom_jme_cff.area
area
Definition: custom_jme_cff.py:140