Jpp  18.2.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JEventShapeVariables.hh
Go to the documentation of this file.
1 #ifndef __JSIRENE__JEVENTSHAPEVARIABLES__
2 #define __JSIRENE__JEVENTSHAPEVARIABLES__
3 
6 
7 #include "JMath/JMatrix3S.hh"
9 
11 
12 #include "JAAnet/JAAnetToolkit.hh"
13 
15 
16 
17 /**
18  * \file
19  * Event shape variables.
20  * \author bjjung
21  */
22 
23 namespace JSIRENE {}
24 namespace JPP { using namespace JSIRENE; }
25 
26 namespace JSIRENE {
27 
28  using JMATH::JMatrix3S;
29 
32 
33 
34  /**
35  * Compute thrust for a given range of tracks.\n
36  * The definition was taken from the description in section 15.2.2 of <a href="https://arxiv.org/pdf/hep-ph/0603175.pdf%E2%80%8B">arXiv:hep-ph/0603175v2</a>.
37  *
38  * \param __begin beginning of track data
39  * \param __end end of track data
40  * \return thrust
41  */
42  inline double getThrust(const std::vector<Trk>::const_iterator __begin,
44  {
45  using namespace std;
46  using namespace JPP;
47 
48  static const int MAX_STEPS = 20;
49  static const double epsilon = 1e-9;
50 
51 
52  Vec axis0(0.0, 0.0, 0.0); //!< Thrust axis
53 
54  // Set thrust axis start value (= summed final state particle momenta)
55 
56  for (vector<Trk>::const_iterator i = __begin; i != __end; ++i) {
57  if (is_finalstate(*i)) {
58  axis0 += getKineticEnergy(*i) * i->dir;
59  }
60  }
61 
62  if (axis0.len() < epsilon) { // If total final state momentum is zero, set start value equal to first final state track momentum
63 
64  vector<Trk>::const_iterator i = find_if(__begin, __end, &is_finalstate);
65 
66  if (i != __end) {
67  axis0 = getKineticEnergy(*i) * i->dir;
68  } else {
69  THROW(JValueOutOfRange, "getThrust(): No final state tracks given.");
70  }
71  }
72 
73  axis0.normalize();
74 
75  // Find axis which maximizes the thrust
76 
77  double res = numeric_limits<double>::max(); //!< residual angle
78 
79  for (int k = 0; k < MAX_STEPS && res > epsilon; ++k) {
80 
81  Vec axis1(0.0, 0.0, 0.0);
82 
83  for (vector<Trk>::const_iterator i = __begin; i != __end; ++i) {
84 
85  if (is_finalstate(*i)) {
86 
87  const Vec p = getKineticEnergy(*i) * i->dir;
88 
89  axis1 += (p.dot(axis0) > 0.0 ? p : -p);
90  }
91  }
92 
93  axis1.normalize();
94 
95  res = acos( axis0.dot(axis1) );
96 
97  axis0 = axis1;
98  }
99 
100  // Compute thrust
101 
102  double pSum = 0.0;
103  double norm = 0.0;
104 
105  for (vector<Trk>::const_iterator i = __begin; i != __end; ++i) {
106 
107  if (is_finalstate(*i)) {
108 
109  const Vec p = getKineticEnergy(*i) * i->dir;
110 
111  pSum += fabs(p.dot(axis0));
112  norm += p.len();
113  }
114  }
115 
116  return pSum / norm;
117  }
118 
119 
120  /**
121  * Compute thrust for a given event.\n
122  * The definition was taken from the description in section 15.2.2 of <a href="https://arxiv.org/pdf/hep-ph/0603175.pdf%E2%80%8B">arXiv:hep-ph/0603175v2</a>.
123  *
124  * \param event event
125  * \return thrust
126  */
127  inline double getThrust(const Evt& event)
128  {
129  return getThrust(event.mc_trks.begin(), event.mc_trks.end());
130  }
131 
132 
133  /**
134  * Class for computing Fox-Wolfram moments.\n
135  * The Fox-Wolfram moments are calculated as defined in section 15.2.3 of <a href="https://arxiv.org/pdf/hep-ph/0603175.pdf%E2%80%8B">arXiv:hep-ph/0603175v2</a>.
136  */
138  std::vector<double>
139  {
141 
142  /**
143  * Default constructor.
144  */
146  std::vector<double>(0)
147  {}
148 
149 
150  /**
151  * Constructor.
152  *
153  * \param __begin beginning of track data
154  * \param __end end of track data
155  * \param can detector can
156  * \param N maximum order
157  */
161  const int N = 4) :
162  std::vector<double>(N+1)
163  {
164  using namespace std;
165  using namespace JPP;
166 
167  const double Evis = getVisibleEnergy(__begin, __end, can);
168 
169  if (Evis > 0.0) {
170 
171  for (vector<Trk>::const_iterator i = __begin; i != __end; ++i) {
172 
173  if (is_finalstate(*i)) {
174 
175  const Vec p0 = getKineticEnergy(*i) * i->dir;
176 
177  for (vector<Trk>::const_iterator j = __begin; j != __end; ++j) {
178 
179  if (is_finalstate(*j)) {
180 
181  const Vec p1 = getKineticEnergy(*j) * j->dir;
182 
183  for (int k = 0; k < (int) this->size(); ++k) {
184  (*this)[k] += getContribution(p0, p1, k) / Evis / Evis;
185  }
186  }
187  }
188  }
189  }
190  }
191  }
192 
193 
194  /**
195  * Constructor.
196  *
197  * \param event event
198  * \param N maximum order
199  */
200  JFoxWolframMoments(const Evt& event,
202  const int N = 4) :
203  JFoxWolframMoments(event.mc_trks.begin(),
204  event.mc_trks.end(),
205  can,
206  N)
207  {}
208 
209  private:
210 
211  /**
212  * Get contribution to Fox-Wolfram moment from two momenta.
213  *
214  * \param p0 first momentum vector
215  * \param p1 second momentum vector
216  * \param n Legendre polynomial index
217  * \return Fox-Wolfram moment contribution
218  */
219  double getContribution(const Vec& p0,
220  const Vec& p1,
221  const size_t n)
222  {
223  using namespace JPP;
224 
225  return p0.len() * p1.len() * legendre(n, p0.dot(p1) / p0.len() / p1.len());
226  }
227  };
228 
229 
230  /**
231  * Class for sphericity tensor calculations.\n
232  * The tensor is constructed following the definition in section 15.2.1 of <a href="https://arxiv.org/pdf/hep-ph/0603175.pdf%E2%80%8B">arXiv:hep-ph/0603175v2</a>.
233  */
235  public JMatrix3S
236  {
238 
239 
240  /**
241  * Default constructor.
242  */
244  {}
245 
246 
247  /**
248  * Constructor.
249  *
250  * \param __begin beginning of track data
251  * \param __end end of track data
252  * \param r the power of the momentum-dependence
253  */
256  const double r = 2.0)
257  {
258  using namespace std;
259  using namespace JPP;
260 
261  double norm = 0.0;
262 
263  for (vector<Trk>::const_iterator i = __begin; i != __end; ++i) {
264 
265  if (is_finalstate(*i)) {
266 
267  const Vec p = getKineticEnergy(*i) * i->dir;
268 
269  const double c = pow(p.len(), r-2);
270 
271  a00 += c * p.x * p.x;
272  a01 += c * p.x * p.y;
273  a02 += c * p.x * p.z;
274 
275  a10 += c * p.y * p.x;
276  a11 += c * p.y * p.y;
277  a12 += c * p.y * p.z;
278 
279  a20 += c * p.z * p.x;
280  a21 += c * p.z * p.y;
281  a22 += c * p.z * p.z;
282 
283  norm += c * p.dot(p);
284  }
285  }
286 
287  this->div(norm);
288 
289  lambda = JMatrix3S::getEigenValues();
290  }
291 
292 
293  /**
294  * Constructor.
295  *
296  * \param event event
297  * \param r the power of the momentum dependence
298  */
299  JSphericityTensor(const Evt& event,
300  const double r = 2.0) :
301  JSphericityTensor(event.mc_trks.begin(), event.mc_trks.end(), r)
302  {}
303 
304 
305  /**
306  * Get eigenvalues.
307  *
308  * \return eigenvalues
309  */
311  {
312  return lambda;
313  }
314 
315 
316  /**
317  * Get sphericity.
318  *
319  * \return sphericity
320  */
321  double getSphericity() const
322  {
323  return 3 * (lambda[1] + lambda[2]) / 2.0;
324  }
325 
326 
327  /**
328  * Get aplanarity.
329  *
330  * \return aplanarity
331  */
332  double getAplanarity() const
333  {
334  return 3 * lambda[2] / 2.0;
335  }
336 
337 
338  /**
339  * Get circularity.
340  *
341  * \return circularity
342  */
343  double getCircularity() const
344  {
345  return (fabs(lambda[0] + lambda[1]) > 0.0 ?
346  2 * lambda[1] / (lambda[0] + lambda[1]) : 0.0);
347  }
348 
349 
350  /**
351  * Get planar flow.
352  *
353  * \return planar flow
354  */
355  double getPlanarFlow() const
356  {
357  return 4 * lambda[0] * lambda[1] / (lambda[0] + lambda[1]) / (lambda[0] + lambda[1]);
358  }
359 
360 
361  /**
362  * Get C-variable.
363  *
364  * \return C
365  */
366  double getC() const
367  {
368  return 3 * (lambda[0]*lambda[1] + lambda[0]*lambda[2] + lambda[1]*lambda[2]);
369  }
370 
371 
372  /**
373  * Get D-variable.
374  *
375  * \return D
376  */
377  double getD() const
378  {
379  return 27 * lambda[0] * lambda[1] * lambda[2];
380  }
381 
382 
383  private:
384 
385  eigen_values lambda; //!< sorted eigenvalues
386  };
387 
388 
389  /**
390  * Class for hit inertia tensor calculations.\n
391  * The given methods are inspired by section 5.2.2 of <a href="https://s3.cern.ch/inspire-prod-files-e/ed2c2d7867bc6d49dd7fd414af45f3d2">Stephanie Hickford's thesis</a>.
392  */
394  public JMatrix3S
395  {
397 
398 
399  /**
400  * Default constructor.
401  */
403  {}
404 
405 
406  /**
407  * Constructor.
408  *
409  * \param __begin beginning of hit data
410  * \param __end end of hit data
411  * \param reference reference position (e.g. the location of the interaction vertex)
412  */
415  const JPosition3D& reference)
416  {
417  using namespace std;
418  using namespace JPP;
419 
420  for (vector<Hit>::const_iterator hit = __begin; hit != __end; ++hit) {
421 
422  const JPosition3D D = sqrt(hit->a) * (getPosition(hit->pos) - reference);
423 
424  a00 += D.getLengthSquared() - D.getX() * D.getX();
425  a01 += 0.0 - D.getX() * D.getY();
426  a02 += 0.0 - D.getX() * D.getZ();
427 
428  a10 += 0.0 - D.getY() * D.getX();
429  a11 += D.getLengthSquared() - D.getY() * D.getY();
430  a12 += 0.0 - D.getY() * D.getZ();
431 
432  a20 += 0.0 - D.getZ() * D.getX();
433  a21 += 0.0 - D.getZ() * D.getY();
434  a22 += D.getLengthSquared() - D.getZ() * D.getZ();
435  }
436 
437  lambda = getEigenValues();
438  }
439 
440 
441  /**
442  * Constructor.
443  *
444  * \param __begin beginning of hit data
445  * \param __end end of hit data
446  * \param reference reference position (e.g. the location of the interaction vertex)
447  */
448  JHitInertiaTensor(const Evt& event,
449  const JPosition3D& reference) :
450  JHitInertiaTensor(event.hits.begin(), event.hits.end(), reference)
451  {}
452 
453 
454  /**
455  * Get eigenvalue ratio.
456  *
457  * \return eigenvalue ratio
458  */
459  double getEigenvalueRatio() const
460  {
461  return lambda[2] / (lambda[0] + lambda[1] + lambda[2]);
462  }
463 
464  private:
465 
466  eigen_values lambda; //!< eigenvalues
467  };
468 }
469 
470 #endif
eigen_values getEigenValues(const double epsilon=1e-6) const
Get eigen values.
Definition: JMatrix3S.hh:227
then fatal No hydrophone data file $HYDROPHONE_TXT fi sort gr k
Class for hit inertia tensor calculations.
TPaveText * p1
std::vector< double >::reference reference
Auxiliary methods for mathematics.
double getContribution(const Vec &p0, const Vec &p1, const size_t n)
Get contribution to Fox-Wolfram moment from two momenta.
double z
Definition: Vec.hh:14
JSphericityTensor(const Evt &event, const double r=2.0)
Constructor.
Class for computing Fox-Wolfram moments.
JFoxWolframMoments(const Evt &event, const JCylinder3D &can=getMaximumContainmentVolume(), const int N=4)
Constructor.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
JFoxWolframMoments()
Default constructor.
data_type r[M+1]
Definition: JPolint.hh:824
double y
Definition: Vec.hh:14
double len() const
Get length.
Definition: Vec.hh:145
Auxiliary methods for evaluating visible energies.
eigen_values lambda
sorted eigenvalues
bool is_finalstate(const Trk &track)
Test whether given track corresponds to a final state particle.
double getD() const
Get D-variable.
const int n
Definition: JPolint.hh:742
double dot(const Vec &v) const
Get dot product.
Definition: Vec.hh:36
JFoxWolframMoments(const std::vector< Trk >::const_iterator __begin, const std::vector< Trk >::const_iterator __end, const JCylinder3D &can=getMaximumContainmentVolume(), const int N=4)
Constructor.
double x
Definition: Vec.hh:14
The Vec class is a straightforward 3-d vector, which also works in pyroot.
Definition: Vec.hh:12
Cylinder object.
Definition: JCylinder3D.hh:39
JSphericityTensor(std::vector< Trk >::const_iterator __begin, std::vector< Trk >::const_iterator __end, const double r=2.0)
Constructor.
double getKineticEnergy(const double E, const double m)
Get kinetic energy of particle with given mass.
3 x 3 symmetric matrix
Definition: JMatrix3S.hh:29
Class for sphericity tensor calculations.
double getC() const
Get C-variable.
const JCylinder3D getMaximumContainmentVolume()
Auxiliary function to retrieve the maximum cylindrical containment volume.
JSphericityTensor()
Default constructor.
JPosition3D getPosition(const Vec &pos)
Get position.
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
const eigen_values & getEigenValues() const
Get eigenvalues.
T pow(const T &x, const double y)
Power .
Definition: JMath.hh:97
double getVisibleEnergy(const Trk &track, const JCylinder3D &can=getMaximumContainmentVolume())
Get the visible energy of a track.
double getAplanarity() const
Get aplanarity.
double getY() const
Get y position.
Definition: JVector3D.hh:104
double getLengthSquared() const
Get length squared.
Definition: JVector3D.hh:235
Vec & normalize()
Normalise this vector.
Definition: Vec.hh:159
JMatrix3S::eigen_values eigen_values
double getSphericity() const
Get sphericity.
$WORKDIR ev_configure_dqsimulator txt echo process $DQ_SIMULATOR $i $SOURCE_HOST[$index] csh c(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&($DQ_SIMULATOR\-u\$NAME\$\-H\$SERVER\$\-M\$LOGGER\$\-d $DEBUG</dev/null > &/dev/null &))'
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
Definition: JMuonPostfit.sh:40
double getCircularity() const
Get circularity.
JHitInertiaTensor(const Evt &event, const JPosition3D &reference)
Constructor.
double legendre(const size_t n, const double x)
Legendre polynome.
double getX() const
Get x position.
Definition: JVector3D.hh:94
JHitInertiaTensor()
Default constructor.
int j
Definition: JPolint.hh:748
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
double getEigenvalueRatio() const
Get eigenvalue ratio.
JHitInertiaTensor(std::vector< Hit >::const_iterator __begin, std::vector< Hit >::const_iterator __end, const JPosition3D &reference)
Constructor.
do echo Generating $dir eval D
Definition: JDrawLED.sh:53
double getZ() const
Get z position.
Definition: JVector3D.hh:115
double getPlanarFlow() const
Get planar flow.
std::vector< Trk > mc_trks
MC: list of MC truth tracks.
Definition: Evt.hh:49
JMatrix3S::eigen_values eigen_values
const double epsilon
Definition: JQuadrature.cc:21
eigen_values lambda
eigenvalues
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:20
double getThrust(const std::vector< Trk >::const_iterator __begin, const std::vector< Trk >::const_iterator __end)
Compute thrust for a given range of tracks.