CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWPFMaths.cc
Go to the documentation of this file.
1 #include <math.h>
2 #include "TMath.h"
3 #include "TEveVector.h"
4 
5 namespace FWPFMaths
6 {
7 //______________________________________________________________________________
8 float
9 sgn( float val )
10 {
11  return ( val < 0 ) ? -1 : 1;
12 }
13 
14 //______________________________________________________________________________
15 TEveVector
16 cross( const TEveVector &v1, const TEveVector &v2 )
17 {
18  TEveVector vec;
19 
20  vec.fX = ( v1.fY * v2.fZ ) - ( v1.fZ * v2.fY );
21  vec.fY = ( v1.fZ * v2.fX ) - ( v1.fX * v2.fZ );
22  vec.fZ = ( v1.fX * v2.fY ) - ( v1.fY * v2.fX );
23 
24  return vec;
25 }
26 
27 //______________________________________________________________________________
28 float
29 dot( const TEveVector &v1, const TEveVector &v2 )
30 {
31  float result = ( v1.fX * v2.fX ) + ( v1.fY * v2.fY ) + ( v1.fZ * v1.fZ );
32 
33  return result;
34 }
35 
36 //______________________________________________________________________________
37 TEveVector
38 lineCircleIntersect( const TEveVector &v1, const TEveVector &v2, float r )
39 {
40  // Definitions
41  float x, y;
42  float dx = v1.fX - v2.fX;
43  float dy = v1.fY - v2.fY;
44  float dr = sqrt( ( dx * dx ) + ( dy * dy ) );
45  float D = ( ( v2.fX * v1.fY ) - ( v1.fX * v2.fY ) );
46 
47  float rtDescrim = sqrt( ( ( r * r ) * ( dr * dr ) ) - ( D * D ) );
48 
49  if( dy < 0 ) // Going down
50  {
51  x = ( D * dy ) - ( ( sgn(dy) * dx ) * rtDescrim );
52  x /= ( dr * dr );
53 
54  y = ( -D * dx ) - ( fabs( dy ) * rtDescrim );
55  y /= ( dr * dr );
56  }
57  else
58  {
59 
60  x = ( D * dy ) + ( ( sgn(dy) * dx ) * rtDescrim );
61  x /= ( dr * dr );
62 
63  y = ( -D * dx ) + ( fabs( dy ) * rtDescrim );
64  y /= ( dr * dr );
65  }
66 
67  TEveVector result = TEveVector( x, y, 0.001 );
68  return result;
69 }
70 
71 //______________________________________________________________________________
72 TEveVector
73 lineLineIntersect( const TEveVector &p1, const TEveVector &p2, const TEveVector &p3, const TEveVector &p4 )
74 {
75  TEveVector a = p2 - p1;
76  TEveVector b = p4 - p3;
77  TEveVector c = p3 - p1;
78  TEveVector result;
79  float s, val;
80 
81  s = dot( cross( c, b ), cross( a, b ) );
82  val = dot( cross( a, b ), cross( a, b ) );
83  s /= val;
84 
85  result = p1 + ( a * s );
86  return result;
87 }
88 
89 //______________________________________________________________________________
90 float
91 linearInterpolation( const TEveVector &p1, const TEveVector &p2, float z )
92 {
93  float y;
94 
95  y = ( ( z - fabs( p1.fZ ) ) * p2.fY ) + ( ( fabs( p2.fZ ) - z ) * p1.fY );
96  y /= ( fabs( p2.fZ) - fabs( p1.fZ ) );
97 
98  return y;
99 }
100 
101 //______________________________________________________________________________
102 bool
103 checkIntersect( const TEveVector &p, float r )
104 {
105  float h = sqrt( ( p.fX * p.fX ) + ( p.fY * p.fY ) );
106 
107  if( h >= r )
108  return true;
109 
110  return false;
111 }
112 
113 //______________________________________________________________________________
114 float
115 calculateEt( const TEveVector &centre, float e )
116 {
117  TEveVector vec = centre;
118  float et;
119 
120  vec.Normalize();
121  vec *= e;
122  et = vec.Perp();
123 
124  return et;
125 }
126 }
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
TEveVector cross(const TEveVector &v1, const TEveVector &v2)
Definition: FWPFMaths.cc:16
float sgn(float val)
Definition: FWPFMaths.cc:9
float linearInterpolation(const TEveVector &p1, const TEveVector &p2, float r)
Definition: FWPFMaths.cc:91
bool checkIntersect(const TEveVector &vec, float r)
Definition: FWPFMaths.cc:103
T x() const
Cartesian x coordinate.
T sqrt(T t)
Definition: SSEVec.h:18
double p4[4]
Definition: TauolaWrapper.h:92
tuple result
Definition: query.py:137
double p2[4]
Definition: TauolaWrapper.h:90
float calculateEt(const TEveVector &centre, float e)
Definition: FWPFMaths.cc:115
DecomposeProduct< arg, typename Div::arg > D
Definition: Factorize.h:150
double b
Definition: hdecay.h:120
double p1[4]
Definition: TauolaWrapper.h:89
float dot(const TEveVector &v1, const TEveVector &v2)
Definition: FWPFMaths.cc:29
double a
Definition: hdecay.h:121
TEveVector lineCircleIntersect(const TEveVector &v1, const TEveVector &v2, float r)
Definition: FWPFMaths.cc:38
TEveVector lineLineIntersect(const TEveVector &v1, const TEveVector &v2, const TEveVector &v3, const TEveVector &v4)
Definition: FWPFMaths.cc:73
double p3[4]
Definition: TauolaWrapper.h:91