LArSoft  v09_90_00
Liquid Argon Software toolkit - https://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 "TLorentzVector.h"
26 #include "TVector2.h"
27 #include "TVector3.h"
28 
29 // C/C++ standard library
30 #include <ostream>
31 
32 namespace geo::vect {
33 
34  // --- BEGIN TVector3 conversions --------------------------------------------
38 
39  //----------------------------------------------------------------------------
41  template <typename Vector>
42  TVector3 toTVector3(Vector const& v)
43  {
44  return convertTo<TVector3>(v);
45  }
46 
48  // --- END TVector3 conversions ----------------------------------------------
49 
50  //----------------------------------------------------------------------------
51 
53  namespace dump {
54 
55  // --- BEGIN Output of old-style ROOT vectors (TVector3 etc.) ------------
59 
61  template <typename Stream>
62  void Vector2(Stream&& out, TVector2 const& v)
63  {
64  out << "( " << v.X() << ", " << v.Y() << " )";
65  }
66 
68  template <typename Stream>
69  void Vector3(Stream&& out, TVector3 const& v)
70  {
71  out << "( " << v.X() << ", " << v.Y() << ", " << v.Z() << " )";
72  }
73 
75  template <typename Stream>
76  void LorentzVector(Stream&& out, TLorentzVector const& v)
77  {
78  out << "( " << v.X() << ", " << v.Y() << ", " << v.Z() << "; " << v.T() << " )";
79  } // LorentzVector()
80 
82  inline std::ostream& operator<<(std::ostream& out, TVector2 const& v)
83  {
84  Vector2(out, v);
85  return out;
86  }
87 
89  inline std::ostream& operator<<(std::ostream& out, TVector3 const& v)
90  {
91  Vector3(out, v);
92  return out;
93  }
94 
96  inline std::ostream& operator<<(std::ostream& out, TLorentzVector const& v)
97  {
98  LorentzVector(out, v);
99  return out;
100  }
101 
103  // --- END Output of old-style ROOT vectors (TVector3 etc.) ----------------
104 
105  } // namespace dump
106  //----------------------------------------------------------------------------
107 
108 } // namespace geo::vect
109 
110 // The only way some generic code has to see the operator<< is for them to be
111 // exposed in the same namespace as the vectors they dump are; in TVector case,
112 // that's the global namespace... (Boost unit test checks still fail though)
113 using geo::vect::dump::operator<<;
114 
115 //------------------------------------------------------------------------------
116 //--- Specialisations
117 //---
118 namespace geo::vect {
119 
120  //----------------------------------------------------------------------------
121  // Specialisations for: TVector2
122  template <>
123  inline auto mag2<TVector2>(TVector2 const& v)
124  {
125  return v.Mod2();
126  }
127 
128  //----------------------------------------------------------------------------
129 
130 } // namespace geo::vect
131 
132 //------------------------------------------------------------------------------
133 //--- STL specialization for ROOT vectors
134 //------------------------------------------------------------------------------
135 
138 
139 // in the golden global namespace, as in old ROOT tradition
140 
141 // --- BEGIN 2D vectors --------------------------------------------------------
142 inline decltype(auto) begin(TVector2 const& v)
143 {
144  return geo::vect::vector_cbegin(v);
145 }
146 
147 inline decltype(auto) cbegin(TVector2 const& v)
148 {
149  return geo::vect::vector_cbegin(v);
150 }
151 
152 inline decltype(auto) end(TVector2 const& v)
153 {
154  return geo::vect::vector_cend(v);
155 }
156 
157 inline decltype(auto) cend(TVector2 const& v)
158 {
159  return geo::vect::vector_cend(v);
160 }
161 
162 // --- END 2D vectors ----------------------------------------------------------
163 
164 // --- BEGIN 3D vectors --------------------------------------------------------
165 inline decltype(auto) begin(TVector3 const& v)
166 {
167  return geo::vect::vector_cbegin(v);
168 }
169 
170 inline decltype(auto) cbegin(TVector3 const& v)
171 {
172  return geo::vect::vector_cbegin(v);
173 }
174 
175 inline decltype(auto) end(TVector3 const& v)
176 {
177  return geo::vect::vector_cend(v);
178 }
179 
180 inline decltype(auto) cend(TVector3 const& v)
181 {
182  return geo::vect::vector_cend(v);
183 }
184 
185 // --- END 3D vectors ----------------------------------------------------------
186 
187 // --- BEGIN 4D vectors --------------------------------------------------------
188 inline decltype(auto) begin(TLorentzVector const& v)
189 {
190  return geo::vect::vector_cbegin(v);
191 }
192 
193 inline decltype(auto) cbegin(TLorentzVector const& v)
194 {
195  return geo::vect::vector_cbegin(v);
196 }
197 
198 inline decltype(auto) end(TLorentzVector const& v)
199 {
200  return geo::vect::vector_cend(v);
201 }
202 
203 inline decltype(auto) cend(TLorentzVector const& v)
204 {
205  return geo::vect::vector_cend(v);
206 }
207 
208 // --- END 4D vectors ----------------------------------------------------------
209 
211 
212 //------------------------------------------------------------------------------
213 
214 #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.
decltype(auto) begin(TVector2 const &v)
decltype(auto) cbegin(TVector2 const &v)
Utilities to manipulate geometry vectors.The utilities include generic vector interface facilities al...
auto vector_cend(Vector const &v)
Returns a const-iterator pointing after the last coordinate of v.
Utilities to extend the interface of geometry vectors.
void LorentzVector(Stream &&out, TLorentzVector const &v)
Print a TLorentzVector to an output stream.
decltype(auto) cend(TVector2 const &v)
decltype(auto) end(TVector2 const &v)
Collection of utilities for dumping data on screen.
Definition: DumperBase.h:28
auto vector_cbegin(Vector const &v)
Returns a const-iterator pointing to the first coordinate of v.
TVector3 toTVector3(Vector const &v)
Converts a vector into a TVector3.
auto mag2< TVector2 >(TVector2 const &v)