CMS 3D CMS Logo

FWPFMaths.cc
Go to the documentation of this file.
1 #include <cmath>
2 #include "TMath.h"
3 #include "TEveVector.h"
4 
5 namespace FWPFMaths {
6  //______________________________________________________________________________
7  float sgn(float val) { return (val < 0) ? -1 : 1; }
8 
9  //______________________________________________________________________________
10  TEveVector cross(const TEveVector &v1, const TEveVector &v2) {
11  TEveVector vec;
12 
13  vec.fX = (v1.fY * v2.fZ) - (v1.fZ * v2.fY);
14  vec.fY = (v1.fZ * v2.fX) - (v1.fX * v2.fZ);
15  vec.fZ = (v1.fX * v2.fY) - (v1.fY * v2.fX);
16 
17  return vec;
18  }
19 
20  //______________________________________________________________________________
21  float dot(const TEveVector &v1, const TEveVector &v2) {
22  float result = (v1.fX * v2.fX) + (v1.fY * v2.fY) + (v1.fZ * v1.fZ);
23 
24  return result;
25  }
26 
27  //______________________________________________________________________________
28  TEveVector lineCircleIntersect(const TEveVector &v1, const TEveVector &v2, float r) {
29  // Definitions
30  float x, y;
31  float dx = v1.fX - v2.fX;
32  float dy = v1.fY - v2.fY;
33  float dr = sqrt((dx * dx) + (dy * dy));
34  float D = ((v2.fX * v1.fY) - (v1.fX * v2.fY));
35 
36  float rtDescrim = sqrt(((r * r) * (dr * dr)) - (D * D));
37 
38  if (dy < 0) // Going down
39  {
40  x = (D * dy) - ((sgn(dy) * dx) * rtDescrim);
41  x /= (dr * dr);
42 
43  y = (-D * dx) - (fabs(dy) * rtDescrim);
44  y /= (dr * dr);
45  } else {
46  x = (D * dy) + ((sgn(dy) * dx) * rtDescrim);
47  x /= (dr * dr);
48 
49  y = (-D * dx) + (fabs(dy) * rtDescrim);
50  y /= (dr * dr);
51  }
52 
53  TEveVector result = TEveVector(x, y, 0.001);
54  return result;
55  }
56 
57  //______________________________________________________________________________
58  TEveVector lineLineIntersect(const TEveVector &p1, const TEveVector &p2, const TEveVector &p3, const TEveVector &p4) {
59  TEveVector a = p2 - p1;
60  TEveVector b = p4 - p3;
61  TEveVector c = p3 - p1;
62  TEveVector result;
63  float s, val;
64 
65  s = dot(cross(c, b), cross(a, b));
66  val = dot(cross(a, b), cross(a, b));
67  s /= val;
68 
69  result = p1 + (a * s);
70  return result;
71  }
72 
73  //______________________________________________________________________________
74  float linearInterpolation(const TEveVector &p1, const TEveVector &p2, float z) {
75  float y;
76 
77  y = ((z - fabs(p1.fZ)) * p2.fY) + ((fabs(p2.fZ) - z) * p1.fY);
78  y /= (fabs(p2.fZ) - fabs(p1.fZ));
79 
80  return y;
81  }
82 
83  //______________________________________________________________________________
84  bool checkIntersect(const TEveVector &p, float r) {
85  float h = sqrt((p.fX * p.fX) + (p.fY * p.fY));
86 
87  if (h >= r)
88  return true;
89 
90  return false;
91  }
92 
93  //______________________________________________________________________________
94  float calculateEt(const TEveVector &centre, float e) {
95  TEveVector vec = centre;
96  float et;
97 
98  vec.Normalize();
99  vec *= e;
100  et = vec.Perp();
101 
102  return et;
103  }
104 } // namespace FWPFMaths
TEveVector cross(const TEveVector &v1, const TEveVector &v2)
Definition: FWPFMaths.cc:10
float sgn(float val)
Definition: FWPFMaths.cc:7
float linearInterpolation(const TEveVector &p1, const TEveVector &p2, float r)
Definition: FWPFMaths.cc:74
bool checkIntersect(const TEveVector &vec, float r)
Definition: FWPFMaths.cc:84
T sqrt(T t)
Definition: SSEVec.h:23
float calculateEt(const TEveVector &centre, float e)
Definition: FWPFMaths.cc:94
DecomposeProduct< arg, typename Div::arg > D
Definition: Factorize.h:141
double b
Definition: hdecay.h:120
float dot(const TEveVector &v1, const TEveVector &v2)
Definition: FWPFMaths.cc:21
double a
Definition: hdecay.h:121
TEveVector lineCircleIntersect(const TEveVector &v1, const TEveVector &v2, float r)
Definition: FWPFMaths.cc:28
float x
TEveVector lineLineIntersect(const TEveVector &v1, const TEveVector &v2, const TEveVector &v3, const TEveVector &v4)
Definition: FWPFMaths.cc:58
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4