Belle II Software  release-08-01-10
Quadratic.h
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 #pragma once
9 
10 #include <utility>
11 #include <cmath>
12 
13 namespace Belle2 {
19  namespace TrackFindingCDC {
20 
23  template<class ANumber>
24  inline auto square(ANumber t) -> decltype(t* t) {return t * t;}
25 
33  inline double hypot2(double x, double y) { return sqrt(x * x + y * y); }
34 
36  inline double hypot3(double x, double y, double z) { return sqrt(x * x + y * y + z * z); }
37 
46  inline std::pair<double, double> solveQuadraticABC(const double a, const double b, const double c)
47  {
48  /*if ( a == 0 ){
49  // this distinction must not be made since the else block gives the same result
50  // we may save some computation steps here but maybe that is not worth while
51  // since we most often ask for solutions with a != 0
52  // essentially this is the zero position of a line
53  smallSolution = - c / b
54  bigSolution = std::numeric_limits<double>::infinity() ;
55  return result;
56  }*/
57 
58  const double discriminant = b * b - 4 * a * c;
59  const double root = sqrt(discriminant);
60  const double bigSum = (b > 0) ? -b - root : -b + root;
61 
62  const double bigSolution = bigSum / 2 / a;
63  const double smallSolution = 2 * c / bigSum;
64 
65  return {bigSolution, smallSolution};
66  }
67  }
69 }
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
Abstract base class for different kinds of events.