Belle II Software  release-06-02-00
FoxWolfram.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #include <analysis/ContinuumSuppression/FoxWolfram.h>
10 
11 using namespace Belle2;
12 
14 {
15  // clear the momenta, in case someone calls this function twice
16  for (double& i : m_moment)
17  i = 0.;
18 
19  const auto begin = m_momenta.begin();
20  const auto end = m_momenta.end();
21 
22  // loops over the vector pairs
23  for (auto iter1 = begin; iter1 != end; iter1++) {
24  const TVector3 pVec1 = (*iter1);
25  double pMag1 = pVec1.Mag();
26 
27  // avoids to iterate twice over the same pairs
28  for (auto iter2 = iter1; iter2 != end; iter2++) {
29  const TVector3 pVec2 = (*iter2);
30  double magProd = pMag1 * pVec2.Mag(); // product of the vector's magnitudes
31  double cTheta = pVec1.Dot(pVec2) / magProd; // costheta_ij
32 
33  // Since the FW moment definition requires to double count all the
34  // pairs of different particles, but the smart loop implemented here doesn't,
35  // multiply each entry by 2.
36  if (iter1 != iter2) magProd *= 2;
37 
38  // Fills the moments' list.
39  // This part is quite ugly, but hard-coding the Legendre polynomials makes the code
40  // much faster than using the boost libraries, which are implementing the recursive formulas.
41  // This implementation should also be faster than a switch...case one.
42  double cTheta2 = cTheta * cTheta;
43  double cTheta3 = cTheta2 * cTheta;
44  double cTheta4 = cTheta2 * cTheta2;
45  m_moment[0] += magProd;
46  m_moment[1] += magProd * cTheta;
47  m_moment[2] += magProd * 0.5 * (3.*cTheta2 - 1);
48  m_moment[3] += magProd * 0.5 * (5.*cTheta3 - 3.*cTheta);
49  m_moment[4] += magProd * 0.125 * (35.*cTheta4 - 30.*cTheta2 + 3.);
50  }
51  }
52  return;
53 }
54 
55 
56 
58 {
59  // clear the momenta, in case someone calls this function twice
60  for (double& i : m_moment)
61  i = 0.;
62 
63  const auto begin = m_momenta.begin();
64  const auto end = m_momenta.end();
65 
66  // loops over the vector pairs
67  for (auto iter1 = begin; iter1 != end; iter1++) {
68  const TVector3 pVec1 = (*iter1);
69  double pMag1 = pVec1.Mag();
70 
71  // avoids to iterate twice over the same pairs
72  for (auto iter2 = iter1; iter2 != end; iter2++) {
73  const TVector3 pVec2 = (*iter2);
74  double magProd = pMag1 * pVec2.Mag(); // product of the vector's magnitudes
75  double cTheta = pVec1.Dot(pVec2) / magProd; // costheta_ij
76 
77  // Since the FW moment definition requires to double count all the
78  // pairs of different particles, but the smart loop implemented here doesn't,
79  // multiply each entry by 2.
80  if (iter1 != iter2) magProd *= 2;
81 
82  // Fills the moments' list.
83  // This part is quite ugly, but hard-coding the Legendre polynomials makes the code
84  // much faster than using the boost libraries, which are implementing the recursive formulas.
85  // This implementation should also be faster than a switch...case one.
86  double cTheta2 = cTheta * cTheta;
87  double cTheta3 = cTheta2 * cTheta;
88  double cTheta4 = cTheta2 * cTheta2;
89  double cTheta5 = cTheta4 * cTheta;
90  double cTheta6 = cTheta3 * cTheta3;
91  double cTheta7 = cTheta6 * cTheta;
92  double cTheta8 = cTheta4 * cTheta4;
93 
94  m_moment[0] += magProd;
95  m_moment[1] += magProd * cTheta;
96  m_moment[2] += magProd * 0.5 * (3.*cTheta2 - 1);
97  m_moment[3] += magProd * 0.5 * (5.*cTheta3 - 3.*cTheta);
98  m_moment[4] += magProd * 0.125 * (35.*cTheta4 - 30.*cTheta2 + 3.);
99  m_moment[5] += magProd * 0.125 * (63.*cTheta5 - 70 * cTheta3 + 15.*cTheta);
100  m_moment[6] += magProd * 0.0625 * (231.*cTheta6 - 315 * cTheta4 + 105 * cTheta2 - 5.);
101  m_moment[7] += magProd * 0.0625 * (429.*cTheta7 - 693.*cTheta5 + 315.*cTheta3 - 35.*cTheta);
102  m_moment[8] += magProd * 0.0078125 * (6435.*cTheta8 - 12012.*cTheta6 + 6930.*cTheta4 - 1260.*cTheta2 + 35.);
103  }
104  }
105  return;
106 }
107 
double m_moment[9]
The moments.
Definition: FoxWolfram.h:93
void calculateAllMoments()
Method to perform the calculation of the moments up to order 8.
Definition: FoxWolfram.cc:57
void calculateBasicMoments()
Method to perform the calculation of the moments up to order 4, which are the most relevant ones.
Definition: FoxWolfram.cc:13
std::vector< TVector3 > m_momenta
The particle's momenta.
Definition: FoxWolfram.h:94
Abstract base class for different kinds of events.