Belle II Software  release-08-01-10
Lpar.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 
9 //-----------------------------------------------------------------------------
10 // Description :
11 //-----------------------------------------------------------------------------
12 
13 #include <iosfwd>
14 #include <cmath>
15 
16 #include "CLHEP/Matrix/Vector.h"
17 #include "CLHEP/Matrix/Matrix.h"
18 #ifndef CLHEP_POINT3D_H
19 #include "CLHEP/Geometry/Point3D.h"
20 #endif
21 
22 #ifdef TRGCDC_SHORT_NAMES
23 #define TCLpar TRGCDCLpar
24 #endif
25 
26 namespace Belle2 {
32 // forward declarations
33 
35  class TRGCDCLpar {
36  // friend classes and functions
37 
38  public:
39  // constants, enums and typedefs
40 
42  TRGCDCLpar();
43 
45  virtual ~TRGCDCLpar();
46 
48  inline TRGCDCLpar& operator=(const TRGCDCLpar&);
49 
51  inline void neg();
53  void circle(double x1, double y1, double x2, double y2,
54  double x3, double y3);
55 
57  double kappa() const { return m_kappa; }
59  double radius() const { return 0.5 / std::fabs(m_kappa);}
61  CLHEP::HepVector center() const;
63  double s(double x, double y) const;
65  inline double d(double x, double y) const;
67  inline double dr(double x, double y) const;
69  double s(double r, int dir = 0) const;
71  double phi(double r, int dir = 0) const;
73  inline int sd(double r, double x, double y,
74  double limit, double& s, double& d) const;
76  inline CLHEP::HepVector Hpar(const HepGeom::Point3D<double>& pivot) const;
77 
78  // static member functions
79 
81  friend class TRGCDCLpav;
83  friend std::ostream& operator<<(std::ostream& o, const TRGCDCLpar&);
85  friend int intersect(const TRGCDCLpar&, const TRGCDCLpar&, CLHEP::HepVector&, CLHEP::HepVector&);
86 
87  protected:
88  // protected member functions
89 
90  // protected const member functions
91 
92  private:
94  class Cpar {
95  public:
97  explicit Cpar(const TRGCDCLpar&);
99  double xi() const { return 1 + 2 * m_cu * m_da; }
101  double sfi() const { return m_sfi; }
103  double cfi() const { return m_cfi; }
105  double da() const { return m_da; }
107  double cu() const { return m_cu; }
109  double fi() const { return m_fi; }
110  private:
112  double m_cu;
114  double m_fi;
116  double m_da;
118  double m_sfi;
120  double m_cfi;
121  };
122  friend class TRGCDCLpar::Cpar;
124  inline TRGCDCLpar(const TRGCDCLpar&);
125 
127  bool operator==(const TRGCDCLpar&) const;
129  bool operator!=(const TRGCDCLpar&) const;
130 
132  void scale(double s) { m_kappa /= s; m_gamma *= s; }
134  inline void rotate(double c, double s);
136  inline void move(double x, double y);
137 
139  double alpha() const { return m_alpha; }
141  double beta() const { return m_beta; }
143  double gamma() const { return m_gamma; }
145  inline double check() const;
147  CLHEP::HepMatrix dldc() const;
149  inline double d0(double x, double y) const;
151  double kr2g(double r) const { return m_kappa * r * r + m_gamma; }
153  double x(double r) const;
155  double y(double r) const;
157  void xhyh(double x, double y, double& xh, double& yh) const;
159  double xi2() const { return 1 + 4 * m_kappa * m_gamma; }
161  bool xy(double, double&, double&, int dir = 0) const;
163  inline double r_max() const;
165  double xc() const { return - m_alpha / 2 / m_kappa; }
167  double yc() const { return - m_beta / 2 / m_kappa; }
169  double da() const { return 2 * gamma() / (std::sqrt(xi2()) + 1); }
171  inline double arcfun(double xh, double yh) const;
172 
174  double m_alpha;
176  double m_beta;
178  double m_gamma;
180  double m_kappa;
181 
183  static const double BELLE_ALPHA;
184 
185  // static data members
186 
187  };
188 
189 // inline function definitions
190 
191 // inline TRGCDCLpar::TRGCDCLpar(double a, double b, double k, double g) {
192 // m_alpha = a; m_beta = b; m_kappa = k; m_gamma = g;
193 // }
194 
196  {
197  m_alpha = 0;
198  m_beta = 1;
199  m_gamma = 0;
200  m_kappa = 0;
201  }
202 
204  {
205  m_alpha = l.m_alpha;
206  m_beta = l.m_beta;
207  m_gamma = l.m_gamma;
208  m_kappa = l.m_kappa;
209  }
210 
212  {
213  if (this != &l) {
214  m_alpha = l.m_alpha;
215  m_beta = l.m_beta;
216  m_gamma = l.m_gamma;
217  m_kappa = l.m_kappa;
218  }
219  return *this;
220  }
221 
222  inline void TRGCDCLpar::rotate(double c, double s)
223  {
224  double aTRGCDCLpar = c * m_alpha + s * m_beta;
225  double betar = -s * m_alpha + c * m_beta;
226  m_alpha = aTRGCDCLpar;
227  m_beta = betar;
228  }
229 
230  inline void TRGCDCLpar::move(double x, double y)
231  {
232  m_gamma += m_kappa * (x * x + y * y) + m_alpha * x + m_beta * y;
233  m_alpha += 2 * m_kappa * x;
234  m_beta += 2 * m_kappa * y;
235  }
236 
237  inline double TRGCDCLpar::check() const
238  {
239  return m_alpha * m_alpha + m_beta * m_beta - 4 * m_kappa * m_gamma - 1;
240  }
241 
242  inline void TRGCDCLpar::neg()
243  {
244  m_alpha = -m_alpha;
245  m_beta = -m_beta;
246  m_gamma = -m_gamma;
247  m_kappa = -m_kappa;
248  }
249 
250  inline double TRGCDCLpar::d0(double x, double y) const
251  {
252  return m_alpha * x + m_beta * y + m_gamma + m_kappa * (x * x + y * y);
253  }
254 
255  inline double TRGCDCLpar::d(double x, double y) const
256  {
257  double dd = d0(x, y);
258  const double approx_limit = 0.2;
259  if (std::fabs(m_kappa * dd) > approx_limit) return -1;
260  return dd * (1 - m_kappa * dd);
261  }
262 
263  inline double TRGCDCLpar::dr(double x, double y) const
264  {
265  double dx = xc() - x;
266  double dy = yc() - y;
267  double r = 0.5 / std::fabs(m_kappa);
268  return std::fabs(std::sqrt(dx * dx + dy * dy) - r);
269  }
270 
271  inline double TRGCDCLpar::r_max() const
272  {
273  if (m_kappa == 0) return 100000000.0;
274  if (m_gamma == 0) return 1 / std::fabs(m_kappa);
275  return std::fabs(2 * m_gamma / (std::sqrt(1 + 4 * m_gamma * m_kappa) - 1));
276  }
277 
278  inline double TRGCDCLpar::arcfun(double xh, double yh) const
279  {
280  //
281  // Duet way of calculating Sperp.
282  //
283  double r2kap = 2.0 * m_kappa;
284  double xi = std::sqrt(xi2());
285  double xinv = 1.0 / xi;
286  double ar2kap = std::fabs(r2kap);
287  double cross = m_alpha * yh - m_beta * xh;
288  double a1 = ar2kap * cross * xinv;
289  double a2 = r2kap * (m_alpha * xh + m_beta * yh) * xinv + xi;
290  if (a1 >= 0 && a2 > 0 && a1 < 0.3) {
291  double arg2 = a1 * a1;
292  return cross * (1.0 + arg2 * (1. / 6. + arg2 * (3. / 40.))) * xinv;
293  } else {
294  double at2 = std::atan2(a1, a2);
295  if (at2 < 0) at2 += (2 * M_PI);
296  return at2 / ar2kap;
297  }
298  }
299 
300  inline int TRGCDCLpar::sd(double r, double x, double y,
301  double limit, double& s, double& d) const
302  {
303  if ((x * yc() - y * xc())*m_kappa < 0) return 0;
304  double dd = d0(x, y);
305  d = dd * (1 - m_kappa * dd);
306  double d_cross_limit = d * limit;
307  if (d_cross_limit < 0 || d_cross_limit > limit * limit) return 0;
308  double rc = std::sqrt(m_alpha * m_alpha + m_beta * m_beta) / (2 * m_kappa);
309  double rho = 1. / (-2 * m_kappa);
310  double cosPhi = (rc * rc + rho * rho - r * r) / (-2 * rc * rho);
311  cosPhi = cosPhi > 1.0 ? 1.0 : cosPhi;
312  cosPhi = cosPhi < -1.0 ? -1.0 : cosPhi;
313  double phi = std::acos(cosPhi);
314  s = std::fabs(rho) * phi;
315  if (0.0 == phi)return 0;
316  d *= r / (std::fabs(rc) * std::sin(phi));
317 //cnv if (abs(d) > abs(limit)) return 0;
318  if (fabs(d) > fabs(limit)) return 0;
319  d_cross_limit = d * limit;
320  if (d_cross_limit > limit * limit) return 0;
321  return 1;
322  }
323 
324  inline CLHEP::HepVector TRGCDCLpar::Hpar(const HepGeom::Point3D<double>& pivot) const
325  {
326  CLHEP::HepVector a(5);
327  double dd = d0(pivot.x(), pivot.y());
328  a(1) = dd * (m_kappa * dd - 1);
329  a(2) = (m_kappa > 0) ? std::atan2(yc() - pivot.y(), xc() - pivot.x()) + M_PI
330  : std::atan2(pivot.y() - yc(), pivot.x() - xc()) - M_PI;
331  a(3) = -2.0 * BELLE_ALPHA * m_kappa;
332  a(4) = 0;
333  a(5) = 0;
334  return a;
335  }
336 
338 } // namespace Belle2
339 
340 
Private class cpar.
Definition: Lpar.h:94
double cu() const
returns parameter of Cpar class
Definition: Lpar.h:107
double m_cfi
parameter of Cpar class
Definition: Lpar.h:120
double m_fi
parameter of Cpar class
Definition: Lpar.h:114
double cfi() const
returns parameter of Cpar class
Definition: Lpar.h:103
double da() const
returns parameter of Cpar class
Definition: Lpar.h:105
double fi() const
returns parameter of Cpar class
Definition: Lpar.h:109
double m_sfi
parameter of Cpar class
Definition: Lpar.h:118
double sfi() const
returns parameter of Cpar class
Definition: Lpar.h:101
double m_cu
parameter of Cpar class
Definition: Lpar.h:112
double m_da
parameter of Cpar class
Definition: Lpar.h:116
double xi() const
returns parameter of Cpar class
Definition: Lpar.h:99
TRGCDCLpar class.
Definition: Lpar.h:35
double m_beta
data members
Definition: Lpar.h:176
double m_kappa
data members
Definition: Lpar.h:180
double xc() const
private const member functions
Definition: Lpar.h:165
double radius() const
const member functions
Definition: Lpar.h:59
double m_gamma
data members
Definition: Lpar.h:178
double kappa() const
const member functions
Definition: Lpar.h:57
bool operator!=(const TRGCDCLpar &) const
comparison operators
double gamma() const
private const member functions
Definition: Lpar.h:143
double da() const
private const member functions
Definition: Lpar.h:169
double kr2g(double r) const
private const member functions
Definition: Lpar.h:151
double beta() const
private const member functions
Definition: Lpar.h:141
friend int intersect(const TRGCDCLpar &, const TRGCDCLpar &, CLHEP::HepVector &, CLHEP::HepVector &)
intersection
Definition: Lpar.cc:249
void scale(double s)
private member functions
Definition: Lpar.h:132
bool operator==(const TRGCDCLpar &) const
comparison operators
friend std::ostream & operator<<(std::ostream &o, const TRGCDCLpar &)
ostream operator
Definition: Lpar.cc:327
double m_alpha
data members
Definition: Lpar.h:174
double yc() const
private const member functions
Definition: Lpar.h:167
double alpha() const
private const member functions
Definition: Lpar.h:139
double xi2() const
private const member functions
Definition: Lpar.h:159
TRGCDCLpav class.
Definition: Lpav.h:31
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
int sd(double r, double x, double y, double limit, double &s, double &d) const
const member functions
Definition: Lpar.h:300
double r_max() const
private const member functions
Definition: Lpar.h:271
void neg()
member functions
Definition: Lpar.h:242
double d0(double x, double y) const
private const member functions
Definition: Lpar.h:250
double arcfun(double xh, double yh) const
private const member functions
Definition: Lpar.h:278
TRGCDCLpar()
Constructor.
Definition: Lpar.h:195
void circle(double x1, double y1, double x2, double y2, double x3, double y3)
circle
Definition: Lpar.cc:77
double s(double x, double y) const
const member functions
Definition: Lpar.cc:210
CLHEP::HepMatrix dldc() const
private const member functions
Definition: Lpar.cc:130
bool xy(double, double &, double &, int dir=0) const
private const member functions
Definition: Lpar.cc:157
double x(double r) const
private const member functions
Definition: Lpar.cc:174
Cpar(const TRGCDCLpar &)
constructor of Cpar class
Definition: Lpar.cc:36
void rotate(double c, double s)
private member functions
Definition: Lpar.h:222
CLHEP::HepVector Hpar(const HepGeom::Point3D< double > &pivot) const
const member functions
Definition: Lpar.h:324
void xhyh(double x, double y, double &xh, double &yh) const
private const member functions
Definition: Lpar.cc:197
double check() const
private const member functions
Definition: Lpar.h:237
static const double BELLE_ALPHA
belle alpha
Definition: Lpar.h:183
double d(double x, double y) const
const member functions
Definition: Lpar.h:255
virtual ~TRGCDCLpar()
Destructor.
Definition: Lpar.cc:52
double y(double r) const
private const member functions
Definition: Lpar.cc:181
CLHEP::HepVector center() const
const member functions
Definition: Lpar.cc:233
double phi(double r, int dir=0) const
const member functions
Definition: Lpar.cc:188
TRGCDCLpar & operator=(const TRGCDCLpar &)
assignment operator(s)
Definition: Lpar.h:211
void move(double x, double y)
private member functions
Definition: Lpar.h:230
double dr(double x, double y) const
const member functions
Definition: Lpar.h:263
Abstract base class for different kinds of events.