LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
geo_vectors_utils_TVector.h
Go to the documentation of this file.
1 
16 #ifndef LARCOREALG_GEOMETRY_GEO_VECTORS_UTILS_TVECTOR_H
17 #define LARCOREALG_GEOMETRY_GEO_VECTORS_UTILS_TVECTOR_H
18 
19 // LArSoft libraries
21 
22 // ROOT library
23 #include "TLorentzVector.h"
24 #include "TVector2.h"
25 #include "TVector3.h"
26 
27 // C/C++ standard library
28 #include <ostream>
29 
30 namespace geo::vect {
31 
32  // --- BEGIN TVector3 conversions --------------------------------------------
36 
37  //----------------------------------------------------------------------------
39  template <typename Vector>
40  TVector3 toTVector3(Vector const& v)
41  {
42  return convertTo<TVector3>(v);
43  }
44 
46  // --- END TVector3 conversions ----------------------------------------------
47 
48  //----------------------------------------------------------------------------
49 
51  namespace dump {
52 
53  // --- BEGIN Output of old-style ROOT vectors (TVector3 etc.) ------------
57 
59  template <typename Stream>
60  void Vector2(Stream&& out, TVector2 const& v)
61  {
62  out << "( " << v.X() << ", " << v.Y() << " )";
63  }
64 
66  template <typename Stream>
67  void Vector3(Stream&& out, TVector3 const& v)
68  {
69  out << "( " << v.X() << ", " << v.Y() << ", " << v.Z() << " )";
70  }
71 
73  template <typename Stream>
74  void LorentzVector(Stream&& out, TLorentzVector const& v)
75  {
76  out << "( " << v.X() << ", " << v.Y() << ", " << v.Z() << "; " << v.T() << " )";
77  } // LorentzVector()
78 
80  inline std::ostream& operator<<(std::ostream& out, TVector2 const& v)
81  {
82  Vector2(out, v);
83  return out;
84  }
85 
87  inline std::ostream& operator<<(std::ostream& out, TVector3 const& v)
88  {
89  Vector3(out, v);
90  return out;
91  }
92 
94  inline std::ostream& operator<<(std::ostream& out, TLorentzVector const& v)
95  {
96  LorentzVector(out, v);
97  return out;
98  }
99 
101  // --- END Output of old-style ROOT vectors (TVector3 etc.) ----------------
102 
103  } // namespace dump
104  //----------------------------------------------------------------------------
105 
106 } // namespace geo::vect
107 
108 // The only way some generic code has to see the operator<< is for them to be
109 // exposed in the same namespace as the vectors they dump are; in TVector case,
110 // that's the global namespace... (Boost unit test checks still fail though)
111 using geo::vect::dump::operator<<;
112 
113 //------------------------------------------------------------------------------
114 //--- Specialisations
115 //---
116 namespace geo::vect {
117 
118  //----------------------------------------------------------------------------
119  // Specialisations for: TVector2
120  template <>
121  inline auto mag2<TVector2>(TVector2 const& v)
122  {
123  return v.Mod2();
124  }
125 
126  //----------------------------------------------------------------------------
127 
128 } // namespace geo::vect
129 
130 //------------------------------------------------------------------------------
131 //--- STL specialization for ROOT vectors
132 //------------------------------------------------------------------------------
133 
136 
137 // in the golden global namespace, as in old ROOT tradition
138 
139 // --- BEGIN 2D vectors --------------------------------------------------------
140 inline decltype(auto) begin(TVector2 const& v)
141 {
142  return geo::vect::vector_cbegin(v);
143 }
144 
145 inline decltype(auto) cbegin(TVector2 const& v)
146 {
147  return geo::vect::vector_cbegin(v);
148 }
149 
150 inline decltype(auto) end(TVector2 const& v)
151 {
152  return geo::vect::vector_cend(v);
153 }
154 
155 inline decltype(auto) cend(TVector2 const& v)
156 {
157  return geo::vect::vector_cend(v);
158 }
159 
160 // --- END 2D vectors ----------------------------------------------------------
161 
162 // --- BEGIN 3D vectors --------------------------------------------------------
163 inline decltype(auto) begin(TVector3 const& v)
164 {
165  return geo::vect::vector_cbegin(v);
166 }
167 
168 inline decltype(auto) cbegin(TVector3 const& v)
169 {
170  return geo::vect::vector_cbegin(v);
171 }
172 
173 inline decltype(auto) end(TVector3 const& v)
174 {
175  return geo::vect::vector_cend(v);
176 }
177 
178 inline decltype(auto) cend(TVector3 const& v)
179 {
180  return geo::vect::vector_cend(v);
181 }
182 
183 // --- END 3D vectors ----------------------------------------------------------
184 
185 // --- BEGIN 4D vectors --------------------------------------------------------
186 inline decltype(auto) begin(TLorentzVector const& v)
187 {
188  return geo::vect::vector_cbegin(v);
189 }
190 
191 inline decltype(auto) cbegin(TLorentzVector const& v)
192 {
193  return geo::vect::vector_cbegin(v);
194 }
195 
196 inline decltype(auto) end(TLorentzVector const& v)
197 {
198  return geo::vect::vector_cend(v);
199 }
200 
201 inline decltype(auto) cend(TLorentzVector const& v)
202 {
203  return geo::vect::vector_cend(v);
204 }
205 
206 // --- END 4D vectors ----------------------------------------------------------
207 
209 
210 //------------------------------------------------------------------------------
211 
212 #endif // LARCOREALG_GEOMETRY_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.This library provides facilities that can be us...
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)