This file is indexed.

/usr/include/root/Math/GenVector/VectorUtil.h is in libroot-math-genvector-dev 5.34.30-0ubuntu8.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
// @(#)root/mathcore:$Id: 9ef2a4a7bd1b62c1293920c2af2f64791c75bdd8 $
// Authors: W. Brown, M. Fischler, L. Moneta    2005


/**********************************************************************
 *                                                                    *
 * Copyright (c) 2005 , LCG ROOT MathLib Team                         *
 *                                                                    *
 *                                                                    *
 **********************************************************************/

// Header file for Vector Utility functions
//
// Created by: moneta  at Tue May 31 21:10:29 2005
//
// Last update: Tue May 31 21:10:29 2005
//
#ifndef ROOT_Math_GenVector_VectorUtil
#define ROOT_Math_GenVector_VectorUtil  1

#ifndef ROOT_Math_Math
#include "Math/Math.h"
#endif


#include "Math/GenVector/Boost.h"

namespace ROOT {

   namespace Math {


      // utility functions for vector classes



      /**
       Global Helper functions for generic Vector classes. Any Vector classes implementing some defined member functions,
       like  Phi() or Eta() or mag() can use these functions.
       The functions returning a scalar value, returns always double precision number even if the vector are
       based on another precision type

       @ingroup GenVector
       */


      namespace VectorUtil {


         // methods for 3D vectors

         /**
          Find aximutal Angle difference between two generic vectors ( v2.Phi() - v1.Phi() )
          The only requirements on the Vector classes is that they implement the Phi() method
          \param v1  Vector of any type implementing the Phi() operator
          \param v2  Vector of any type implementing the Phi() operator
          \return  Phi difference
          \f[ \Delta \phi = \phi_2 - \phi_1 \f]
          */
         template <class Vector1, class Vector2>
         inline typename Vector1::Scalar DeltaPhi( const Vector1 & v1, const Vector2 & v2) {
            typename Vector1::Scalar dphi = v2.Phi() - v1.Phi();
            if ( dphi > M_PI ) {
               dphi -= 2.0*M_PI;
            } else if ( dphi <= -M_PI ) {
               dphi += 2.0*M_PI;
            }
            return dphi;
         }



         /**
          Find square of the difference in pseudorapidity (Eta) and Phi betwen two generic vectors
          The only requirements on the Vector classes is that they implement the Phi() and Eta() method
          \param v1  Vector 1
          \param v2  Vector 2
          \return   Angle between the two vectors
          \f[ \Delta R2 = ( \Delta \phi )^2 + ( \Delta \eta )^2  \f]
          */
         template <class Vector1, class Vector2>
         inline typename Vector1::Scalar DeltaR2( const Vector1 & v1, const Vector2 & v2) {
            typename Vector1::Scalar dphi = DeltaPhi(v1,v2);
            typename Vector1::Scalar deta = v2.Eta() - v1.Eta();
            return dphi*dphi + deta*deta;
         }

         /**
          Find difference in pseudorapidity (Eta) and Phi betwen two generic vectors
          The only requirements on the Vector classes is that they implement the Phi() and Eta() method
          \param v1  Vector 1
          \param v2  Vector 2
          \return   Angle between the two vectors
          \f[ \Delta R = \sqrt{  ( \Delta \phi )^2 + ( \Delta \eta )^2 } \f]
          */
         template <class Vector1, class Vector2>
         inline typename Vector1::Scalar DeltaR( const Vector1 & v1, const Vector2 & v2) {
            return std::sqrt( DeltaR2(v1,v2) );
         }



         /**
          Find CosTheta Angle between two generic 3D vectors
          pre-requisite: vectors implement the X(), Y() and Z()
          \param v1  Vector v1
          \param v2  Vector v2
          \return   cosine of Angle between the two vectors
          \f[ \cos \theta = \frac { \vec{v1} \cdot \vec{v2} }{ | \vec{v1} | | \vec{v2} | } \f]
          */
         // this cannot be made all generic since Mag2() for 2, 3 or 4 D is different
         // need to have a specialization for polar Coordinates ??
         template <class Vector1, class Vector2>
         double CosTheta( const Vector1 &  v1, const Vector2  & v2) {
            double arg;
            double v1_r2 = v1.X()*v1.X() + v1.Y()*v1.Y() + v1.Z()*v1.Z();
            double v2_r2 = v2.X()*v2.X() + v2.Y()*v2.Y() + v2.Z()*v2.Z();
            double ptot2 = v1_r2*v2_r2;
            if(ptot2 <= 0) {
               arg = 0.0;
            }else{
               double pdot = v1.X()*v2.X() + v1.Y()*v2.Y() + v1.Z()*v2.Z();
               arg = pdot/std::sqrt(ptot2);
               if(arg >  1.0) arg =  1.0;
               if(arg < -1.0) arg = -1.0;
            }
            return arg;
         }


         /**
          Find Angle between two vectors.
          Use the CosTheta() function
          \param v1  Vector v1
          \param v2  Vector v2
          \return   Angle between the two vectors
          \f[ \theta = \cos ^{-1} \frac { \vec{v1} \cdot \vec{v2} }{ | \vec{v1} | | \vec{v2} | } \f]
          */
         template <class Vector1, class Vector2>
         inline double Angle( const  Vector1 & v1, const Vector2 & v2) {
            return std::acos( CosTheta(v1, v2) );
         }

         /**
          Find the projection of v along the given direction u.
          \param v  Vector v for which the propjection is to be found
          \param u  Vector specifying the direction
          \return   Vector projection (same type of v)
          \f[ \vec{proj} = \frac{ \vec{v}  \cdot \vec{u} }{|\vec{u}|}\vec{u} \f]
          Precondition is that Vector1 implements Dot function and Vector2 implements X(),Y() and Z()
          */
         template <class Vector1, class Vector2>
         Vector1 ProjVector( const  Vector1 & v, const Vector2 & u) {
            double magU2 = u.X()*u.X() + u.Y()*u.Y() + u.Z()*u.Z();
            if (magU2 == 0) return Vector1(0,0,0);
            double d = v.Dot(u)/magU2;
            return Vector1( u.X() * d, u.Y() * d, u.Z() * d);
         }

         /**
          Find the vector component of v perpendicular to the given direction of u
          \param v  Vector v for which the perpendicular component is to be found
          \param u  Vector specifying the direction
          \return   Vector component of v which is perpendicular to u
          \f[ \vec{perp} = \vec{v} -  \frac{ \vec{v}  \cdot \vec{u} }{|\vec{u}|}\vec{u} \f]
          Precondition is that Vector1 implements Dot function and Vector2 implements X(),Y() and Z()
          */
         template <class Vector1, class Vector2>
         inline Vector1 PerpVector( const  Vector1 & v, const Vector2 & u) {
            return v - ProjVector(v,u);
         }

         /**
          Find the magnitude square of the vector component of v perpendicular to the given direction of u
          \param v  Vector v for which the perpendicular component is to be found
          \param u  Vector specifying the direction
          \return   square value of the component of v which is perpendicular to u
          \f[ perp = | \vec{v} -  \frac{ \vec{v}  \cdot \vec{u} }{|\vec{u}|}\vec{u} |^2 \f]
          Precondition is that Vector1 implements Dot function and Vector2 implements X(),Y() and Z()
          */
         template <class Vector1, class Vector2>
         inline double Perp2( const  Vector1 & v, const Vector2 & u) {
            double magU2 = u.X()*u.X() + u.Y()*u.Y() + u.Z()*u.Z();
            double prjvu = v.Dot(u);
            double magV2 = v.Dot(v);
            return magU2 > 0.0 ? magV2-prjvu*prjvu/magU2 : magV2;
         }

         /**
          Find the magnitude of the vector component of v perpendicular to the given direction of u
          \param v  Vector v for which the perpendicular component is to be found
          \param u  Vector specifying the direction
          \return   value of the component of v which is perpendicular to u
          \f[ perp = | \vec{v} -  \frac{ \vec{v}  \cdot \vec{u} }{|\vec{u}|}\vec{u} | \f]
          Precondition is that Vector1 implements Dot function and Vector2 implements X(),Y() and Z()
          */
         template <class Vector1, class Vector2>
         inline double Perp( const  Vector1 & v, const Vector2 & u) {
            return std::sqrt(Perp2(v,u) );
         }



         // Lorentz Vector functions


         /**
          return the invariant mass of two LorentzVector
          The only requirement on the LorentzVector is that they need to implement the
          X() , Y(), Z() and E() methods.
          \param v1 LorenzVector 1
          \param v2 LorenzVector 2
          \return invariant mass M
          \f[ M_{12} = \sqrt{ (\vec{v1} + \vec{v2} ) \cdot (\vec{v1} + \vec{v2} ) } \f]
          */
         template <class Vector1, class Vector2>
         inline typename Vector1::Scalar InvariantMass( const Vector1 & v1, const Vector2 & v2) {
            typedef typename  Vector1::Scalar Scalar;
            Scalar ee = (v1.E() + v2.E() );
            Scalar xx = (v1.X() + v2.X() );
            Scalar yy = (v1.Y() + v2.Y() );
            Scalar zz = (v1.Z() + v2.Z() );
            Scalar mm2 = ee*ee - xx*xx - yy*yy - zz*zz;
            return mm2 < 0.0 ? -std::sqrt(-mm2) : std::sqrt(mm2);
            //  PxPyPzE4D<double> q(xx,yy,zz,ee);
            //  return q.M();
            //return ( v1 + v2).mag();
         }

         template <class Vector1, class Vector2>
         inline typename Vector1::Scalar InvariantMass2( const Vector1 & v1, const Vector2 & v2) {
            typedef typename  Vector1::Scalar Scalar;
            Scalar ee = (v1.E() + v2.E() );
            Scalar xx = (v1.X() + v2.X() );
            Scalar yy = (v1.Y() + v2.Y() );
            Scalar zz = (v1.Z() + v2.Z() );
            Scalar mm2 = ee*ee - xx*xx - yy*yy - zz*zz;
            return mm2 ; // < 0.0 ? -std::sqrt(-mm2) : std::sqrt(mm2);
                         //  PxPyPzE4D<double> q(xx,yy,zz,ee);
                         //  return q.M();
                         //return ( v1 + v2).mag();
         }

         // rotation and transformations


#ifndef __CINT__
         /**
          rotation along X axis for a generic vector by an Angle alpha
          returning a new vector.
          The only pre requisite on the Vector is that it has to implement the X() , Y() and Z()
          and SetXYZ methods.
          */
         template <class Vector>
         Vector RotateX(const Vector & v, double alpha) {
            double sina = sin(alpha);
            double cosa = cos(alpha);
            double y2 = v.Y() * cosa - v.Z()*sina;
            double z2 = v.Z() * cosa + v.Y() * sina;
            Vector vrot;
            vrot.SetXYZ(v.X(), y2, z2);
            return vrot;
         }

         /**
          rotation along Y axis for a generic vector by an Angle alpha
          returning a new vector.
          The only pre requisite on the Vector is that it has to implement the X() , Y() and Z()
          and SetXYZ methods.
          */
         template <class Vector>
         Vector RotateY(const Vector & v, double alpha) {
            double sina = sin(alpha);
            double cosa = cos(alpha);
            double x2 = v.X() * cosa + v.Z() * sina;
            double z2 = v.Z() * cosa - v.X() * sina;
            Vector vrot;
            vrot.SetXYZ(x2, v.Y(), z2);
            return vrot;
         }

         /**
          rotation along Z axis for a generic vector by an Angle alpha
          returning a new vector.
          The only pre requisite on the Vector is that it has to implement the X() , Y() and Z()
          and SetXYZ methods.
          */
         template <class Vector>
         Vector RotateZ(const Vector & v, double alpha) {
            double sina = sin(alpha);
            double cosa = cos(alpha);
            double x2 = v.X() * cosa - v.Y() * sina;
            double y2 = v.Y() * cosa + v.X() * sina;
            Vector vrot;
            vrot.SetXYZ(x2, y2, v.Z());
            return vrot;
         }


         /**
          rotation on a generic vector using a generic rotation class.
          The only requirement on the vector is that implements the
          X(), Y(), Z() and SetXYZ methods.
          The requirement on the rotation matrix is that need to implement the
          (i,j) operator returning the matrix element with R(0,0) = xx element
          */
         template<class Vector, class RotationMatrix>
         Vector Rotate(const Vector &v, const RotationMatrix & rot) {
            double xX = v.X();
            double yY = v.Y();
            double zZ = v.Z();
            double x2 =  rot(0,0)*xX + rot(0,1)*yY + rot(0,2)*zZ;
            double y2 =  rot(1,0)*xX + rot(1,1)*yY + rot(1,2)*zZ;
            double z2 =  rot(2,0)*xX + rot(2,1)*yY + rot(2,2)*zZ;
            Vector vrot;
            vrot.SetXYZ(x2,y2,z2);
            return vrot;
         }

         /**
          Boost a generic Lorentz Vector class using a generic 3D Vector class describing the boost
          The only requirement on the vector is that implements the
          X(), Y(), Z(), T() and SetXYZT methods.
          The requirement on the boost vector is that needs to implement the
          X(), Y() , Z()  retorning the vector elements describing the boost
          The beta of the boost must be <= 1 or a nul Lorentz Vector will be returned
          */
         template <class LVector, class BoostVector>
         LVector boost(const LVector & v, const BoostVector & b) {
            double bx = b.X();
            double by = b.Y();
            double bz = b.Z();
            double b2 = bx*bx + by*by + bz*bz;
            if (b2 >= 1) {
               GenVector::Throw ( "Beta Vector supplied to set Boost represents speed >= c");
               return LVector();
            }
            double gamma = 1.0 / std::sqrt(1.0 - b2);
            double bp = bx*v.X() + by*v.Y() + bz*v.Z();
            double gamma2 = b2 > 0 ? (gamma - 1.0)/b2 : 0.0;
            double x2 = v.X() + gamma2*bp*bx + gamma*bx*v.T();
            double y2 = v.Y() + gamma2*bp*by + gamma*by*v.T();
            double z2 = v.Z() + gamma2*bp*bz + gamma*bz*v.T();
            double t2 = gamma*(v.T() + bp);
            LVector lv;
            lv.SetXYZT(x2,y2,z2,t2);
            return lv;
         }


         /**
          Boost a generic Lorentz Vector class along the X direction with a factor beta
          The only requirement on the vector is that implements the
          X(), Y(), Z(), T()  and SetXYZT methods.
          The beta of the boost must be <= 1 or a nul Lorentz Vector will be returned
          */
         template <class LVector, class T>
         LVector boostX(const LVector & v, T beta) {
            if (beta >= 1) {
               GenVector::Throw ("Beta Vector supplied to set Boost represents speed >= c");
               return LVector();
            }
            T gamma = 1.0/ std::sqrt(1.0 - beta*beta);
            typename LVector::Scalar x2 = gamma * v.X() + gamma * beta * v.T();
            typename LVector::Scalar t2 = gamma * beta * v.X() + gamma * v.T();

            LVector lv;
            lv.SetXYZT(x2,v.Y(),v.Z(),t2);
            return lv;
         }

         /**
          Boost a generic Lorentz Vector class along the Y direction with a factor beta
          The only requirement on the vector is that implements the
          X(), Y(), Z(), T()  methods and be constructed from x,y,z,t values
          The beta of the boost must be <= 1 or a nul Lorentz Vector will be returned
          */
         template <class LVector>
         LVector boostY(const LVector & v, double beta) {
            if (beta >= 1) {
               GenVector::Throw ("Beta Vector supplied to set Boost represents speed >= c");
               return LVector();
            }
            double gamma = 1.0/ std::sqrt(1.0 - beta*beta);
            double y2 = gamma * v.Y() + gamma * beta * v.T();
            double t2 = gamma * beta * v.Y() + gamma * v.T();
            LVector lv;
            lv.SetXYZT(v.X(),y2,v.Z(),t2);
            return lv;
         }

         /**
          Boost a generic Lorentz Vector class along the Z direction with a factor beta
          The only requirement on the vector is that implements the
          X(), Y(), Z(), T()  methods and be constructed from x,y,z,t values
          The beta of the boost must be <= 1 or a nul Lorentz Vector will be returned
          */
         template <class LVector>
         LVector boostZ(const LVector & v, double beta) {
            if (beta >= 1) {
               GenVector::Throw ( "Beta Vector supplied to set Boost represents speed >= c");
               return LVector();
            }
            double gamma = 1.0/ std::sqrt(1.0 - beta*beta);
            double z2 = gamma * v.Z() + gamma * beta * v.T();
            double t2 = gamma * beta * v.Z() + gamma * v.T();
            LVector lv;
            lv.SetXYZT(v.X(),v.Y(),z2,t2);
            return lv;
         }

#endif




         // MATRIX VECTOR MULTIPLICATION
         // cannot define an operator * otherwise conflicts with rotations
         // operations like Rotation3D * vector use Mult

         /**
          Multiplications of a generic matrices with a  DisplacementVector3D of any coordinate system.
          Assume that the matrix implements the operator( i,j) and that it has at least         3 columns and 3 rows. There is no check on the matrix size !!
          */
         template<class Matrix, class CoordSystem, class U>
         inline
         DisplacementVector3D<CoordSystem,U> Mult (const Matrix & m, const DisplacementVector3D<CoordSystem,U> & v) { 
            DisplacementVector3D<CoordSystem,U> vret; 
            vret.SetXYZ( m(0,0) * v.x() + m(0,1) * v.y() + m(0,2) * v.z() , 
                        m(1,0) * v.x() + m(1,1) * v.y() + m(1,2) * v.z() , 
                        m(2,0) * v.x() + m(2,1) * v.y() + m(2,2) * v.z() ); 
            return vret; 
         }
         
         
         /** 
          Multiplications of a generic matrices with a generic PositionVector 
          Assume that the matrix implements the operator( i,j) and that it has at least         3 columns and 3 rows. There is no check on the matrix size !!
          */ 
         template<class Matrix, class CoordSystem, class U> 
         inline
         PositionVector3D<CoordSystem,U> Mult (const Matrix & m, const PositionVector3D<CoordSystem,U> & p) { 
            DisplacementVector3D<CoordSystem,U> pret; 
            pret.SetXYZ( m(0,0) * p.x() + m(0,1) * p.y() + m(0,2) * p.z() , 
                        m(1,0) * p.x() + m(1,1) * p.y() + m(1,2) * p.z() , 
                        m(2,0) * p.x() + m(2,1) * p.y() + m(2,2) * p.z() ); 
            return pret; 
         }
         
         
         /** 
          Multiplications of a generic matrices with a  LorentzVector described 
          in any coordinate system.  
          Assume that the matrix implements the operator( i,j) and that it has at least         4 columns and 4 rows. There is no check on the matrix size !!
          */ 
         // this will not be ambigous with operator*(Scalar, LorentzVector) since that one     // Scalar is passed by value
         template<class CoordSystem, class Matrix> 
         inline
         LorentzVector<CoordSystem> Mult (const Matrix & m, const LorentzVector<CoordSystem> & v) { 
            LorentzVector<CoordSystem> vret; 
            vret.SetXYZT( m(0,0)*v.x() + m(0,1)*v.y() + m(0,2)*v.z() + m(0,3)* v.t() , 
                         m(1,0)*v.x() + m(1,1)*v.y() + m(1,2)*v.z() + m(1,3)* v.t() , 
                         m(2,0)*v.x() + m(2,1)*v.y() + m(2,2)*v.z() + m(2,3)* v.t() ,
                         m(3,0)*v.x() + m(3,1)*v.y() + m(3,2)*v.z() + m(3,3)* v.t() );
            return vret; 
         }
         
         
         
         // non-template utility functions for all objects
         
         
         /** 
          Return a phi angle in the interval (0,2*PI]
          */ 
         double Phi_0_2pi(double phi);
         /** 
          Returns phi angle in the interval (-PI,PI]
          */
         double  Phi_mpi_pi(double phi);
         
         
         
      }  // end namespace Vector Util
      
      
      
   } // end namespace Math
   
} // end namespace ROOT


#endif /* ROOT_Math_GenVector_VectorUtil  */