evtgen is hosted by Hepforge, IPPP Durham
EvtGen  2.0.0
Monte Carlo generator of particle decays, in particular the weak decays of heavy flavour particles such as B mesons.
EvtVector4R.cpp
Go to the documentation of this file.
1 
2 /***********************************************************************
3 * Copyright 1998-2020 CERN for the benefit of the EvtGen authors *
4 * *
5 * This file is part of EvtGen. *
6 * *
7 * EvtGen is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * EvtGen is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with EvtGen. If not, see <https://www.gnu.org/licenses/>. *
19 ***********************************************************************/
20 
22 
23 #include "EvtGenBase/EvtPatches.hh"
27 
28 #include <cmath>
29 #include <iostream>
30 
31 using std::ostream;
32 
34 {
35  v[0] = 0.0;
36  v[1] = 0.0;
37  v[2] = 0.0;
38  v[3] = 0.0;
39 }
40 
41 EvtVector4R::EvtVector4R( double e, double p1, double p2, double p3 )
42 {
43  v[0] = e;
44  v[1] = p1;
45  v[2] = p2;
46  v[3] = p3;
47 }
48 
49 double EvtVector4R::mass() const
50 {
51  double m2 = v[0] * v[0] - v[1] * v[1] - v[2] * v[2] - v[3] * v[3];
52 
53  if ( m2 > 0.0 ) {
54  return sqrt( m2 );
55  } else {
56  return 0.0;
57  }
58 }
59 
60 EvtVector4R rotateEuler( const EvtVector4R& rs, double alpha, double beta,
61  double gamma )
62 {
63  EvtVector4R tmp( rs );
64  tmp.applyRotateEuler( alpha, beta, gamma );
65  return tmp;
66 }
67 
68 EvtVector4R boostTo( const EvtVector4R& rs, const EvtVector4R& p4, bool inverse )
69 {
70  EvtVector4R tmp( rs );
71  tmp.applyBoostTo( p4, inverse );
72  return tmp;
73 }
74 
75 EvtVector4R boostTo( const EvtVector4R& rs, const EvtVector3R& boost,
76  bool inverse )
77 {
78  EvtVector4R tmp( rs );
79  tmp.applyBoostTo( boost, inverse );
80  return tmp;
81 }
82 
83 void EvtVector4R::applyRotateEuler( double phi, double theta, double ksi )
84 {
85  double sp = sin( phi );
86  double st = sin( theta );
87  double sk = sin( ksi );
88  double cp = cos( phi );
89  double ct = cos( theta );
90  double ck = cos( ksi );
91 
92  double x = ( ck * ct * cp - sk * sp ) * v[1] +
93  ( -sk * ct * cp - ck * sp ) * v[2] + st * cp * v[3];
94  double y = ( ck * ct * sp + sk * cp ) * v[1] +
95  ( -sk * ct * sp + ck * cp ) * v[2] + st * sp * v[3];
96  double z = -ck * st * v[1] + sk * st * v[2] + ct * v[3];
97 
98  v[1] = x;
99  v[2] = y;
100  v[3] = z;
101 }
102 
103 ostream& operator<<( ostream& s, const EvtVector4R& v )
104 {
105  s << "(" << v.v[0] << "," << v.v[1] << "," << v.v[2] << "," << v.v[3] << ")";
106 
107  return s;
108 }
109 
110 void EvtVector4R::applyBoostTo( const EvtVector4R& p4, bool inverse )
111 {
112  double e = p4.get( 0 );
113 
114  EvtVector3R boost( p4.get( 1 ) / e, p4.get( 2 ) / e, p4.get( 3 ) / e );
115 
116  applyBoostTo( boost, inverse );
117 
118  return;
119 }
120 
121 void EvtVector4R::applyBoostTo( const EvtVector3R& boost, bool inverse )
122 {
123  double bx, by, bz, gamma, b2;
124 
125  bx = boost.get( 0 );
126  by = boost.get( 1 );
127  bz = boost.get( 2 );
128 
129  double bxx = bx * bx;
130  double byy = by * by;
131  double bzz = bz * bz;
132 
133  b2 = bxx + byy + bzz;
134 
135  if ( b2 > 0.0 && b2 < 1.0 ) {
136  gamma = 1.0 / sqrt( 1.0 - b2 );
137 
138  double gb2 = ( gamma - 1.0 ) / b2;
139 
140  double gb2xy = gb2 * bx * by;
141  double gb2xz = gb2 * bx * bz;
142  double gb2yz = gb2 * by * bz;
143 
144  double gbx = gamma * bx;
145  double gby = gamma * by;
146  double gbz = gamma * bz;
147 
148  double e2 = v[0];
149  double px2 = v[1];
150  double py2 = v[2];
151  double pz2 = v[3];
152 
153  if ( inverse ) {
154  v[0] = gamma * e2 - gbx * px2 - gby * py2 - gbz * pz2;
155 
156  v[1] = -gbx * e2 + gb2 * bxx * px2 + px2 + gb2xy * py2 + gb2xz * pz2;
157 
158  v[2] = -gby * e2 + gb2 * byy * py2 + py2 + gb2xy * px2 + gb2yz * pz2;
159 
160  v[3] = -gbz * e2 + gb2 * bzz * pz2 + pz2 + gb2yz * py2 + gb2xz * px2;
161  } else {
162  v[0] = gamma * e2 + gbx * px2 + gby * py2 + gbz * pz2;
163 
164  v[1] = gbx * e2 + gb2 * bxx * px2 + px2 + gb2xy * py2 + gb2xz * pz2;
165 
166  v[2] = gby * e2 + gb2 * byy * py2 + py2 + gb2xy * px2 + gb2yz * pz2;
167 
168  v[3] = gbz * e2 + gb2 * bzz * pz2 + pz2 + gb2yz * py2 + gb2xz * px2;
169  }
170  }
171 }
172 
174 {
175  //Calcs the cross product. Added by djl on July 27, 1995.
176  //Modified for real vectros by ryd Aug 28-96
177 
178  EvtVector4R temp;
179 
180  temp.v[0] = 0.0;
181  temp.v[1] = v[2] * p2.v[3] - v[3] * p2.v[2];
182  temp.v[2] = v[3] * p2.v[1] - v[1] * p2.v[3];
183  temp.v[3] = v[1] * p2.v[2] - v[2] * p2.v[1];
184 
185  return temp;
186 }
187 
188 double EvtVector4R::d3mag() const
189 
190 // returns the 3 momentum mag.
191 {
192  double temp;
193 
194  temp = v[1] * v[1] + v[2] * v[2] + v[3] * v[3];
195 
196  temp = sqrt( temp );
197 
198  return temp;
199 } // r3mag
200 
201 double EvtVector4R::dot( const EvtVector4R& p2 ) const
202 {
203  //Returns the dot product of the 3 momentum. Added by
204  //djl on July 27, 1995. for real!!!
205 
206  double temp;
207 
208  temp = v[1] * p2.v[1];
209  temp += v[2] * p2.v[2];
210  temp += v[3] * p2.v[3];
211 
212  return temp;
213 
214 } //dot
215 
216 // Functions below added by AJB
217 
218 // Calculate ( \vec{p1} cross \vec{p2} ) \cdot \vec{p3} in rest frame of object
220  const EvtVector4R& p3 ) const
221 {
222  EvtVector4C lc = dual( EvtGenFunctions::directProd( *this, p1 ) ).cont2( p2 );
223  EvtVector4R l( real( lc.get( 0 ) ), real( lc.get( 1 ) ),
224  real( lc.get( 2 ) ), real( lc.get( 3 ) ) );
225 
226  return -1.0 / mass() * ( l * p3 );
227 }
228 
229 // Calculate the 3-d dot product of 4-vectors p1 and p2 in the rest frame of
230 // 4-vector p0
231 double EvtVector4R::dotr3( const EvtVector4R& p1, const EvtVector4R& p2 ) const
232 {
233  return 1 / mass2() * ( ( *this ) * p1 ) * ( ( *this ) * p2 ) - p1 * p2;
234 }
235 
236 // Calculate the 3-d magnitude squared of 4-vector p1 in the rest frame of
237 // 4-vector p0
238 double EvtVector4R::mag2r3( const EvtVector4R& p1 ) const
239 {
240  return Square( ( *this ) * p1 ) / mass2() - p1.mass2();
241 }
242 
243 // Calculate the 3-d magnitude 4-vector p1 in the rest frame of 4-vector p0.
244 double EvtVector4R::magr3( const EvtVector4R& p1 ) const
245 {
246  return sqrt( mag2r3( p1 ) );
247 }
EvtTensor3C directProd(const EvtVector3C &c1, const EvtVector3C &c2)
double get(int i) const
Definition: EvtVector3R.hh:121
void applyRotateEuler(double alpha, double beta, double gamma)
Definition: EvtVector4R.cpp:83
double dotr3(const EvtVector4R &p1, const EvtVector4R &p2) const
double magr3(const EvtVector4R &p1) const
double v[4]
Definition: EvtVector4R.hh:68
double Square(double x) const
Definition: EvtVector4R.hh:70
EvtTensor4C dual(const EvtTensor4C &t2)
EvtVector4R cross(const EvtVector4R &v2)
double mass() const
Definition: EvtVector4R.cpp:49
EvtVector4C cont2(const EvtVector4C &v4) const
ostream & operator<<(ostream &s, const EvtVector4R &v)
double mag2r3(const EvtVector4R &p1) const
double mass2() const
Definition: EvtVector4R.hh:100
double get(int i) const
Definition: EvtVector4R.hh:162
EvtVector4R boostTo(const EvtVector4R &rs, const EvtVector4R &p4, bool inverse)
Definition: EvtVector4R.cpp:68
void applyBoostTo(const EvtVector4R &p4, bool inverse=false)
double d3mag() const
const EvtComplex & get(int) const
Definition: EvtVector4C.hh:125
double scalartripler3(const EvtVector4R &p1, const EvtVector4R &p2, const EvtVector4R &p3) const
double real(const EvtComplex &c)
Definition: EvtComplex.hh:230
double dot(const EvtVector4R &v2) const
EvtVector4R rotateEuler(const EvtVector4R &rs, double alpha, double beta, double gamma)
Definition: EvtVector4R.cpp:60