Jpp  18.6.0-rc.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 
13 
14 #include "JAAnet/JAAnetToolkit.hh"
15 
17 
18 
19 /**
20  * \file
21  * Event shape variables.
22  * \author bjjung
23  */
24 
25 namespace JSIRENE {}
26 namespace JPP { using namespace JSIRENE; }
27 
28 namespace JSIRENE {
29 
30  using JMATH::JMatrix3S;
31 
33 
34 
35  /**
36  * Compute thrust for a given range of tracks.\n
37  * 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>.
38  *
39  * \param __begin beginning of track data
40  * \param __end end of track data
41  * \return thrust
42  */
43  inline double getThrust(const std::vector<Trk>::const_iterator __begin,
45  {
46  using namespace std;
47  using namespace JPP;
48 
49  static const int MAX_STEPS = 20;
50  static const double epsilon = 1e-9;
51 
52 
53  Vec axis0(0.0, 0.0, 0.0); //!< Thrust axis
54 
55  // Set thrust axis start value (= summed final state particle momenta)
56 
57  for (vector<Trk>::const_iterator i = __begin; i != __end; ++i) {
58  if (is_finalstate(*i)) {
59  axis0 += getKineticEnergy(*i) * i->dir;
60  }
61  }
62 
63  if (axis0.len() < epsilon) { // If total final state momentum is zero, set start value equal to first final state track momentum
64 
65  vector<Trk>::const_iterator i = find_if(__begin, __end, &is_finalstate);
66 
67  if (i != __end) {
68  axis0 = getKineticEnergy(*i) * i->dir;
69  } else {
70  THROW(JValueOutOfRange, "getThrust(): No final state tracks given.");
71  }
72  }
73 
74  axis0.normalize();
75 
76  // Find axis which maximizes the thrust
77 
78  double res = numeric_limits<double>::max(); //!< residual angle
79 
80  for (int k = 0; k < MAX_STEPS && res > epsilon; ++k) {
81 
82  Vec axis1(0.0, 0.0, 0.0);
83 
84  for (vector<Trk>::const_iterator i = __begin; i != __end; ++i) {
85 
86  if (is_finalstate(*i)) {
87 
88  const Vec p = getKineticEnergy(*i) * i->dir;
89 
90  axis1 += (p.dot(axis0) > 0.0 ? p : -p);
91  }
92  }
93 
94  axis1.normalize();
95 
96  res = acos( axis0.dot(axis1) );
97 
98  axis0 = axis1;
99  }
100 
101  // Compute thrust
102 
103  double pSum = 0.0;
104  double norm = 0.0;
105 
106  for (vector<Trk>::const_iterator i = __begin; i != __end; ++i) {
107 
108  if (is_finalstate(*i)) {
109 
110  const Vec p = getKineticEnergy(*i) * i->dir;
111 
112  pSum += fabs(p.dot(axis0));
113  norm += p.len();
114  }
115  }
116 
117  return pSum / norm;
118  }
119 
120 
121  /**
122  * Compute thrust for a given event.\n
123  * 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>.
124  *
125  * \param event event
126  * \return thrust
127  */
128  inline double getThrust(const Evt& event)
129  {
130  return getThrust(event.mc_trks.begin(), event.mc_trks.end());
131  }
132 
133 
134  /**
135  * Class for computing Fox-Wolfram moments.\n
136  * 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>.
137  */
139  std::vector<double>
140  {
142 
143  /**
144  * Default constructor.
145  */
147  std::vector<double>(0)
148  {}
149 
150 
151  /**
152  * Constructor.
153  *
154  * \param __begin beginning of track data
155  * \param __end end of track data
156  * \param can detector can
157  * \param N maximum order
158  */
162  const int N = 4) :
163  std::vector<double>(N+1)
164  {
165  using namespace std;
166  using namespace JPP;
167 
168  const double Evis = getVisibleEnergy(__begin, __end, can);
169 
170  if (Evis > 0.0) {
171 
172  for (vector<Trk>::const_iterator i = __begin; i != __end; ++i) {
173 
174  if (is_finalstate(*i)) {
175 
176  const Vec p0 = getKineticEnergy(*i) * i->dir;
177 
178  for (vector<Trk>::const_iterator j = __begin; j != __end; ++j) {
179 
180  if (is_finalstate(*j)) {
181 
182  const Vec p1 = getKineticEnergy(*j) * j->dir;
183 
184  for (int k = 0; k < (int) this->size(); ++k) {
185  (*this)[k] += getContribution(p0, p1, k) / Evis / Evis;
186  }
187  }
188  }
189  }
190  }
191  }
192  }
193 
194 
195  /**
196  * Constructor.
197  *
198  * \param event event
199  * \param can can
200  * \param N maximum order
201  */
202  JFoxWolframMoments(const Evt& event,
204  const int N = 4) :
205  JFoxWolframMoments(event.mc_trks.begin(),
206  event.mc_trks.end(),
207  can,
208  N)
209  {}
210 
211  private:
212 
213  /**
214  * Get contribution to Fox-Wolfram moment from two momenta.
215  *
216  * \param p0 first momentum vector
217  * \param p1 second momentum vector
218  * \param n Legendre polynomial index
219  * \return Fox-Wolfram moment contribution
220  */
221  double getContribution(const Vec& p0,
222  const Vec& p1,
223  const size_t n)
224  {
225  using namespace JPP;
226 
227  return p0.len() * p1.len() * legendre(n, p0.dot(p1) / p0.len() / p1.len());
228  }
229  };
230 
231 
232  /**
233  * Class for sphericity tensor calculations.\n
234  * 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>.
235  */
237  public JMatrix3S
238  {
240 
241 
242  /**
243  * Default constructor.
244  */
246  {}
247 
248 
249  /**
250  * Constructor.
251  *
252  * \param __begin beginning of track data
253  * \param __end end of track data
254  * \param r the power of the momentum-dependence
255  */
258  const double r = 2.0)
259  {
260  using namespace std;
261  using namespace JPP;
262 
263  double norm = 0.0;
264 
265  for (vector<Trk>::const_iterator i = __begin; i != __end; ++i) {
266 
267  if (is_finalstate(*i)) {
268 
269  const Vec p = getKineticEnergy(*i) * i->dir;
270 
271  const double c = pow(p.len(), r-2);
272 
273  a00 += c * p.x * p.x;
274  a01 += c * p.x * p.y;
275  a02 += c * p.x * p.z;
276 
277  a10 += c * p.y * p.x;
278  a11 += c * p.y * p.y;
279  a12 += c * p.y * p.z;
280 
281  a20 += c * p.z * p.x;
282  a21 += c * p.z * p.y;
283  a22 += c * p.z * p.z;
284 
285  norm += c * p.dot(p);
286  }
287  }
288 
289  this->div(norm);
290 
291  lambda = JMatrix3S::getEigenValues();
292  }
293 
294 
295  /**
296  * Constructor.
297  *
298  * \param event event
299  * \param r the power of the momentum dependence
300  */
301  JSphericityTensor(const Evt& event,
302  const double r = 2.0) :
303  JSphericityTensor(event.mc_trks.begin(), event.mc_trks.end(), r)
304  {}
305 
306 
307  /**
308  * Get eigenvalues.
309  *
310  * \return eigenvalues
311  */
313  {
314  return lambda;
315  }
316 
317 
318  /**
319  * Get sphericity.
320  *
321  * \return sphericity
322  */
323  double getSphericity() const
324  {
325  return 3 * (lambda[1] + lambda[2]) / 2.0;
326  }
327 
328 
329  /**
330  * Get aplanarity.
331  *
332  * \return aplanarity
333  */
334  double getAplanarity() const
335  {
336  return 3 * lambda[2] / 2.0;
337  }
338 
339 
340  /**
341  * Get circularity.
342  *
343  * \return circularity
344  */
345  double getCircularity() const
346  {
347  return (fabs(lambda[0] + lambda[1]) > 0.0 ?
348  2 * lambda[1] / (lambda[0] + lambda[1]) : 0.0);
349  }
350 
351 
352  /**
353  * Get planar flow.
354  *
355  * \return planar flow
356  */
357  double getPlanarFlow() const
358  {
359  return 4 * lambda[0] * lambda[1] / (lambda[0] + lambda[1]) / (lambda[0] + lambda[1]);
360  }
361 
362 
363  /**
364  * Get C-variable.
365  *
366  * \return C
367  */
368  double getC() const
369  {
370  return 3 * (lambda[0]*lambda[1] + lambda[0]*lambda[2] + lambda[1]*lambda[2]);
371  }
372 
373 
374  /**
375  * Get D-variable.
376  *
377  * \return D
378  */
379  double getD() const
380  {
381  return 27 * lambda[0] * lambda[1] * lambda[2];
382  }
383 
384 
385  private:
386 
387  eigen_values lambda; //!< sorted eigenvalues
388  };
389 
390 
391  /**
392  * Class for hit inertia tensor calculations.\n
393  * 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>.
394  */
396  public JMatrix3S
397  {
399 
400 
401  /**
402  * Default constructor.
403  */
405  {}
406 
407 
408  /**
409  * Constructor.
410  *
411  * \param __begin beginning of hit data
412  * \param __end end of hit data
413  * \param reference reference position (e.g. the location of the interaction vertex)
414  */
417  const JPosition3D& reference)
418  {
419  using namespace std;
420  using namespace JPP;
421 
422  for (vector<Hit>::const_iterator hit = __begin; hit != __end; ++hit) {
423 
424  const JPosition3D D = sqrt(hit->a) * (getPosition(hit->pos) - reference);
425 
426  a00 += D.getLengthSquared() - D.getX() * D.getX();
427  a01 += 0.0 - D.getX() * D.getY();
428  a02 += 0.0 - D.getX() * D.getZ();
429 
430  a10 += 0.0 - D.getY() * D.getX();
431  a11 += D.getLengthSquared() - D.getY() * D.getY();
432  a12 += 0.0 - D.getY() * D.getZ();
433 
434  a20 += 0.0 - D.getZ() * D.getX();
435  a21 += 0.0 - D.getZ() * D.getY();
436  a22 += D.getLengthSquared() - D.getZ() * D.getZ();
437  }
438 
439  lambda = getEigenValues();
440  }
441 
442 
443  /**
444  * Constructor.
445  *
446  * \param event event
447  * \param reference reference position (e.g. the location of the interaction vertex)
448  */
449  JHitInertiaTensor(const Evt& event,
450  const JPosition3D& reference) :
451  JHitInertiaTensor(event.hits.begin(), event.hits.end(), reference)
452  {}
453 
454 
455  /**
456  * Get eigenvalue ratio.
457  *
458  * \return eigenvalue ratio
459  */
460  double getEigenvalueRatio() const
461  {
462  return lambda[2] / (lambda[0] + lambda[1] + lambda[2]);
463  }
464 
465  private:
466 
467  eigen_values lambda; //!< eigenvalues
468  };
469 }
470 
471 #endif
eigen_values getEigenValues(const double epsilon=1e-6) const
Get eigen values.
Definition: JMatrix3S.hh:227
Auxiliary methods for physics calculations.
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.
3 x 3 symmetric matrix
Definition: JMatrix3S.hh:29
Class for sphericity tensor calculations.
double getC() const
Get C-variable.
JSphericityTensor()
Default constructor.
const JCylinder3D getMaximumContainmentVolume()
Auxiliary function to retrieve the maximum cylindrical containment volume.
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 getKineticEnergy(const Trk &trk)
Get track kinetic energy.
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.