CMS 3D CMS Logo

EventShapeVariables.cc
Go to the documentation of this file.
2 
3 #include "TMath.h"
4 
6 EventShapeVariables::EventShapeVariables(const edm::View<reco::Candidate>& inputVectors) : 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 }
15 
17 EventShapeVariables::EventShapeVariables(const std::vector<math::XYZVector>& inputVectors)
18  : inputVectors_(inputVectors), eigenVectors_(3, 3) {
19  //default values
20  set_r(2.);
21  setFWmax(10);
22 }
23 
25 EventShapeVariables::EventShapeVariables(const std::vector<math::RhoEtaPhiVector>& inputVectors) : 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 }
34 
36 EventShapeVariables::EventShapeVariables(const std::vector<math::RThetaPhiVector>& inputVectors) : 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 }
45 
49 double EventShapeVariables::isotropy(const unsigned int& numberOfSteps) const {
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 }
68 
71 double EventShapeVariables::circularity(const unsigned int& numberOfSteps) const {
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 }
92 
95  r_ = r;
97  tensors_computed_ = false;
98  eigenValues_ = std::vector<double>(3, 0);
99  eigenValuesNoNorm_ = std::vector<double>(3, 0);
100 }
101 
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 }
155 
159  if (!tensors_computed_)
161  return 1.5 * (eigenValues_[1] + eigenValues_[2]);
162 }
163 
167  if (!tensors_computed_)
169  return 1.5 * eigenValues_[2];
170 }
171 
176  if (!tensors_computed_)
178  return 3. *
180 }
181 
186  if (!tensors_computed_)
188  return 27. * eigenValues_[0] * eigenValues_[1] * eigenValues_[2];
189 }
190 
191 //========================================================================================================
192 
195  fwmom_maxl_ = m;
196  fwmom_computed_ = false;
197  fwmom_ = std::vector<double>(fwmom_maxl_, 0.);
198 }
199 
201  if (l > fwmom_maxl_)
202  return 0.;
203 
204  if (!fwmom_computed_)
206 
207  return fwmom_[l];
208 
209 } // getFWmoment
210 
211 const std::vector<double>& EventShapeVariables::getFWmoments() {
212  if (!fwmom_computed_)
214 
215  return fwmom_;
216 }
217 
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
274 
275 //========================================================================================================
EventShapeVariables::isotropy
double isotropy(const unsigned int &numberOfSteps=1000) const
Definition: EventShapeVariables.cc:49
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
EventShapeVariables::C
double C()
Definition: EventShapeVariables.cc:175
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:72
p2
double p2[4]
Definition: TauolaWrapper.h:90
EventShapeVariables::eigenValuesNoNormTmp_
TVectorD eigenValuesNoNormTmp_
Definition: EventShapeVariables.h:111
edm::View::size
size_type size() const
edm::View
Definition: CaloClusterFwd.h:14
EventShapeVariables::aplanarity
double aplanarity()
Definition: EventShapeVariables.cc:166
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
EventShapeVariables::D
double D()
Definition: EventShapeVariables.cc:185
EventShapeVariables.h
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:204
EventShapeVariables::getFWmoments
const std::vector< double > & getFWmoments()
Definition: EventShapeVariables.cc:211
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
EventShapeVariables::sphericity
double sphericity()
Definition: EventShapeVariables.cc:158
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::getFWmoment
double getFWmoment(unsigned l)
Definition: EventShapeVariables.cc:200
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:133
EventShapeVariables::EventShapeVariables
EventShapeVariables(const edm::View< reco::Candidate > &inputVectors)
constructor from reco::Candidates
Definition: EventShapeVariables.cc:6