LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
geo_vectors_utils_TVector.h
Go to the documentation of this file.
1 
18 #ifndef LARCOREOBJ_SIMPLETYPESANDCONSTANTS_GEO_VECTORS_UTILS_TVECTOR_H
19 #define LARCOREOBJ_SIMPLETYPESANDCONSTANTS_GEO_VECTORS_UTILS_TVECTOR_H
20 
21 // LArSoft libraries
23 
24 // ROOT library
25 #include "TVector2.h"
26 #include "TVector3.h"
27 #include "TLorentzVector.h"
28 
29 // C/C++ standard library
30 #include <ostream>
31 
32 
33 namespace geo {
34  namespace vect {
35 
36  // --- BEGIN TVector3 conversions ------------------------------------------
40 
41  //--------------------------------------------------------------------------
43  template <typename Vector>
44  TVector3 toTVector3(Vector const& v) { return convertTo<TVector3>(v); }
45 
47  //--------------------------------------------------------------------------
48 
50  namespace dump {
51 
52  // --- BEGIN Output of old-style ROOT vectors (TVector3 etc.) ------------
56 
58  template <typename Stream>
59  void Vector2(Stream&& out, TVector2 const& v)
60  { out << "( " << v.X() << ", " << v.Y() << " )"; }
61 
63  template <typename Stream>
64  void Vector3(Stream&& out, TVector3 const& v)
65  { out << "( " << v.X() << ", " << v.Y() << ", " << v.Z() << " )"; }
66 
68  template <typename Stream>
69  void LorentzVector(Stream&& out, TLorentzVector const& v) {
70  out
71  << "( " << v.X() << ", " << v.Y() << ", " << v.Z() << "; " << v.T()
72  << " )";
73  } // LorentzVector()
74 
76  inline std::ostream& operator<< (std::ostream& out, TVector2 const& v)
77  { Vector2(out, v); return out; }
78 
80  inline std::ostream& operator<< (std::ostream& out, TVector3 const& v)
81  { Vector3(out, v); return out; }
82 
84  inline std::ostream& operator<<
85  (std::ostream& out, TLorentzVector const& v)
86  { LorentzVector(out, v); return out; }
87 
88  // --- END Output of old-style ROOT vectors (TVector3 etc.) --------------
90 
91  } // namespace dump
92  //--------------------------------------------------------------------------
93 
95  // --- END TVector3 conversions --------------------------------------------
96 
97  } // namespace vect
98 } // namespace geo
99 
100 
101 // The only way some generic code has to see the operator<< is for them to be
102 // exposed in the same namespace as the vectors they dump are; in TVector case,
103 // that's the global namespace... (Boost unit test checks still fail though)
104 using geo::vect::dump::operator<<;
105 
106 
107 //------------------------------------------------------------------------------
108 //--- Specialisations
109 //---
110 namespace geo {
111  namespace vect {
112 
113  //--------------------------------------------------------------------------
114  // Specialisations for: TVector2
115  template <>
116  inline auto mag2<TVector2>(TVector2 const& v) { return v.Mod2(); }
117 
118  //--------------------------------------------------------------------------
119 
120  } // namespace vect
121 } // namespace geo
122 //------------------------------------------------------------------------------
123 
124 
125 #endif // LARCOREOBJ_SIMPLETYPESANDCONSTANTS_GEO_VECTORS_UTILS_TVECTOR_H
std::ostream & operator<<(std::ostream &out, TVector2 const &v)
Print a TVector2 to an output stream.
void Vector2(Stream &&out, TVector2 const &v)
Print a TVector2 to an output stream.
void Vector3(Stream &&out, TVector3 const &v)
Print a TVector3 to an output stream.
Utilities to extend the interface of geometry vectors.
void LorentzVector(Stream &&out, TLorentzVector const &v)
Print a TLorentzVector to an output stream.
TVector3 toTVector3(Vector const &v)
Converts a vector into a TVector3.
Namespace collecting geometry-related classes utilities.
auto mag2< TVector2 >(TVector2 const &v)