Jpp  18.3.1
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 can can
199  * \param N maximum order
200  */
201  JFoxWolframMoments(const Evt& event,
203  const int N = 4) :
204  JFoxWolframMoments(event.mc_trks.begin(),
205  event.mc_trks.end(),
206  can,
207  N)
208  {}
209 
210  private:
211 
212  /**
213  * Get contribution to Fox-Wolfram moment from two momenta.
214  *
215  * \param p0 first momentum vector
216  * \param p1 second momentum vector
217  * \param n Legendre polynomial index
218  * \return Fox-Wolfram moment contribution
219  */
220  double getContribution(const Vec& p0,
221  const Vec& p1,
222  const size_t n)
223  {
224  using namespace JPP;
225 
226  return p0.len() * p1.len() * legendre(n, p0.dot(p1) / p0.len() / p1.len());
227  }
228  };
229 
230 
231  /**
232  * Class for sphericity tensor calculations.\n
233  * 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>.
234  */
236  public JMatrix3S
237  {
239 
240 
241  /**
242  * Default constructor.
243  */
245  {}
246 
247 
248  /**
249  * Constructor.
250  *
251  * \param __begin beginning of track data
252  * \param __end end of track data
253  * \param r the power of the momentum-dependence
254  */
257  const double r = 2.0)
258  {
259  using namespace std;
260  using namespace JPP;
261 
262  double norm = 0.0;
263 
264  for (vector<Trk>::const_iterator i = __begin; i != __end; ++i) {
265 
266  if (is_finalstate(*i)) {
267 
268  const Vec p = getKineticEnergy(*i) * i->dir;
269 
270  const double c = pow(p.len(), r-2);
271 
272  a00 += c * p.x * p.x;
273  a01 += c * p.x * p.y;
274  a02 += c * p.x * p.z;
275 
276  a10 += c * p.y * p.x;
277  a11 += c * p.y * p.y;
278  a12 += c * p.y * p.z;
279 
280  a20 += c * p.z * p.x;
281  a21 += c * p.z * p.y;
282  a22 += c * p.z * p.z;
283 
284  norm += c * p.dot(p);
285  }
286  }
287 
288  this->div(norm);
289 
290  lambda = JMatrix3S::getEigenValues();
291  }
292 
293 
294  /**
295  * Constructor.
296  *
297  * \param event event
298  * \param r the power of the momentum dependence
299  */
300  JSphericityTensor(const Evt& event,
301  const double r = 2.0) :
302  JSphericityTensor(event.mc_trks.begin(), event.mc_trks.end(), r)
303  {}
304 
305 
306  /**
307  * Get eigenvalues.
308  *
309  * \return eigenvalues
310  */
312  {
313  return lambda;
314  }
315 
316 
317  /**
318  * Get sphericity.
319  *
320  * \return sphericity
321  */
322  double getSphericity() const
323  {
324  return 3 * (lambda[1] + lambda[2]) / 2.0;
325  }
326 
327 
328  /**
329  * Get aplanarity.
330  *
331  * \return aplanarity
332  */
333  double getAplanarity() const
334  {
335  return 3 * lambda[2] / 2.0;
336  }
337 
338 
339  /**
340  * Get circularity.
341  *
342  * \return circularity
343  */
344  double getCircularity() const
345  {
346  return (fabs(lambda[0] + lambda[1]) > 0.0 ?
347  2 * lambda[1] / (lambda[0] + lambda[1]) : 0.0);
348  }
349 
350 
351  /**
352  * Get planar flow.
353  *
354  * \return planar flow
355  */
356  double getPlanarFlow() const
357  {
358  return 4 * lambda[0] * lambda[1] / (lambda[0] + lambda[1]) / (lambda[0] + lambda[1]);
359  }
360 
361 
362  /**
363  * Get C-variable.
364  *
365  * \return C
366  */
367  double getC() const
368  {
369  return 3 * (lambda[0]*lambda[1] + lambda[0]*lambda[2] + lambda[1]*lambda[2]);
370  }
371 
372 
373  /**
374  * Get D-variable.
375  *
376  * \return D
377  */
378  double getD() const
379  {
380  return 27 * lambda[0] * lambda[1] * lambda[2];
381  }
382 
383 
384  private:
385 
386  eigen_values lambda; //!< sorted eigenvalues
387  };
388 
389 
390  /**
391  * Class for hit inertia tensor calculations.\n
392  * 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>.
393  */
395  public JMatrix3S
396  {
398 
399 
400  /**
401  * Default constructor.
402  */
404  {}
405 
406 
407  /**
408  * Constructor.
409  *
410  * \param __begin beginning of hit data
411  * \param __end end of hit data
412  * \param reference reference position (e.g. the location of the interaction vertex)
413  */
416  const JPosition3D& reference)
417  {
418  using namespace std;
419  using namespace JPP;
420 
421  for (vector<Hit>::const_iterator hit = __begin; hit != __end; ++hit) {
422 
423  const JPosition3D D = sqrt(hit->a) * (getPosition(hit->pos) - reference);
424 
425  a00 += D.getLengthSquared() - D.getX() * D.getX();
426  a01 += 0.0 - D.getX() * D.getY();
427  a02 += 0.0 - D.getX() * D.getZ();
428 
429  a10 += 0.0 - D.getY() * D.getX();
430  a11 += D.getLengthSquared() - D.getY() * D.getY();
431  a12 += 0.0 - D.getY() * D.getZ();
432 
433  a20 += 0.0 - D.getZ() * D.getX();
434  a21 += 0.0 - D.getZ() * D.getY();
435  a22 += D.getLengthSquared() - D.getZ() * D.getZ();
436  }
437 
438  lambda = getEigenValues();
439  }
440 
441 
442  /**
443  * Constructor.
444  *
445  * \param event event
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:868
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:786
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:792
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.