CHeT Library
Loading...
Searching...
No Matches
CHeTVisualizer.hh
Go to the documentation of this file.
1#ifndef CHETVISUALIZER_HH
2#define CHETVISUALIZER_HH
3
4// --- External Dependencies ---
5#include <algorithm>
6#include <cmath>
7#include <functional>
8#include <string>
9#include <vector>
10
11// --- ROOT Headers ---
12#include <TAxis.h>
13#include <TBox.h>
14#include <TCanvas.h>
15#include <TColor.h>
16#include <TEllipse.h>
17#include <TGraph.h>
18#include <TH2D.h>
19#include <TH3F.h>
20#include <TMultiGraph.h>
21#include <TPad.h>
22#include <TPolyLine3D.h>
23#include <TPolyMarker3D.h>
24#include <TROOT.h>
25#include <TStyle.h>
26
27// --- Project Dependencies ---
29
30namespace CHeT
31{
32
39namespace Vis
40{
41
42// --- Visualization Data Structures ---
43
49{
50 double x, y;
51 int color;
53 double size;
54
55 VisPoint2D() = default;
56
57 VisPoint2D(double _x, double _y, int _col = kBlue, int _mst = 1, double _sz = 1.0)
58 : x(_x)
59 , y(_y)
60 , color(_col)
61 , markerStyle(_mst)
62 , size(_sz)
63 {
64 }
65};
66
71{
72 double x, y, z;
73 int color;
75 double size;
77
78 VisPoint3D() = default;
79
80 VisPoint3D(double _x, double _y, double _z, int _col = kRed, int _mst = 20, double _sz = 1.0,
81 bool _isLocal = false)
82 : x(_x)
83 , y(_y)
84 , z(_z)
85 , color(_col)
86 , markerStyle(_mst)
87 , size(_sz)
88 , isLocalFrame(_isLocal)
89 {
90 }
91};
92
97{
98 std::vector<VisPoint3D> points;
99 int color;
100 int width;
101 int style;
103
104 VisGenericTrack() = default;
105
107 std::vector<VisPoint3D> _pts, int _c = 1, int _w = 2, int _s = 1, bool _loc = false)
108 : points(std::move(_pts))
109 , color(_c)
110 , width(_w)
111 , style(_s)
112 , isLocalFrame(_loc)
113 {
114 }
115};
116
121{
122 double x0, y0, z0;
123 double ux, uy, uz;
124 int color;
125 int width;
126 int style;
128
133 VisLineTrack() = default;
134
135 VisLineTrack(double _x, double _y, double _z, double _dx, double _dy, double _dz, int _col = 54,
136 /* kYellow fallback */ int _w = 2, int _s = 1, bool _isLocal = false)
137 : x0(_x)
138 , y0(_y)
139 , z0(_z)
140 , color(_col)
141 , width(_w)
142 , style(_s)
143 , isLocalFrame(_isLocal)
144 {
145 double norm = std::sqrt(_dx * _dx + _dy * _dy + _dz * _dz);
146 if(norm > 0)
147 {
148 ux = _dx / norm;
149 uy = _dy / norm;
150 uz = _dz / norm;
151 }
152 else
153 {
154 ux = 0;
155 uy = 0;
156 uz = 0;
157 }
158 }
159};
160
165{
166 double cx, cy;
167 double radius;
168 double z0;
169 double dz_dt;
170 double t_min = 0;
171 double t_max = 6.28;
172 int color;
173 int width;
174 int style;
176
177 VisHelixTrack() = default;
178
179 VisHelixTrack(double _cx, double _cy, double _r, double _z0, double _dz, double _tmin,
180 double _tmax, int _c = 1, int _w = 2, int _s = 1, bool _loc = false)
181 : cx(_cx)
182 , cy(_cy)
183 , radius(_r)
184 , z0(_z0)
185 , dz_dt(_dz)
186 , t_min(_tmin)
187 , t_max(_tmax)
188 , color(_c)
189 , width(_w)
190 , style(_s)
191 , isLocalFrame(_loc)
192 {
193 }
194};
195
196// --- Core Functions ---
197
198void Draw2DCore(const std::vector<int> &bundle_ids, const std::vector<VisPoint2D> &extraPoints,
199 const std::function<void(TMultiGraph *, TMultiGraph *, TMultiGraph *, TMultiGraph *)>
200 &trackDrawer,
201 bool wrap_phi = true);
202
203void Draw3DCore(const std::vector<int> &hit_ids, const std::vector<VisPoint3D> &points,
204 bool drawSkeleton, const std::function<void(double[6])> &trackDrawer);
205
206// --- Rendering Functions ---
207void RenderTrack2D(const VisLineTrack &tr, TMultiGraph *mg_xy);
208void RenderTrack2D(const VisHelixTrack &tr, TMultiGraph *mg_xy);
209void RenderTrack2D(const VisGenericTrack &tr, TMultiGraph *mg_xy);
210
211void RenderTrackZX(const VisLineTrack &tr, TMultiGraph *mg_zx);
212void RenderTrackZX(const VisHelixTrack &tr, TMultiGraph *mg_zx);
213void RenderTrackZX(const VisGenericTrack &tr, TMultiGraph *mg_zx);
214
215void RenderTrackZY(const VisLineTrack &tr, TMultiGraph *mg_zy);
216void RenderTrackZY(const VisHelixTrack &tr, TMultiGraph *mg_zy);
217void RenderTrackZY(const VisGenericTrack &tr, TMultiGraph *mg_zy);
218
219void RenderTrackPhiZ(const VisLineTrack &tr, TMultiGraph *mg_phiz, bool wrap_phi = true);
220void RenderTrackPhiZ(const VisHelixTrack &tr, TMultiGraph *mg_phiz, bool wrap_phi = true);
221void RenderTrackPhiZ(const VisGenericTrack &tr, TMultiGraph *mg_phiz, bool wrap_phi = true);
222
223void RenderTrack3D(const VisLineTrack &tr, double bounds[6]);
224void RenderTrack3D(const VisHelixTrack &tr, double bounds[6]);
225void RenderTrack3D(const VisGenericTrack &tr, double bounds[6]);
226
227// --- Visualization Functions ---
228
239template <typename TrackContainer = std::vector<VisGenericTrack>>
240void Draw2D(const std::vector<int> &bundle_ids, const TrackContainer &tracks = {},
241 const std::vector<VisPoint2D> &extraPoints = {}, bool wrap_phi = true)
242{
243 // Invoke core function with a lambda iterating over the generic container
245 bundle_ids, extraPoints,
246 [&](TMultiGraph *mg_xy, TMultiGraph *mg_zx, TMultiGraph *mg_zy, TMultiGraph *mg_phiz)
247 {
248 for(const auto &tr : tracks)
249 {
250 RenderTrack2D(tr, mg_xy); // Compiler chooses the correct overload!
251 RenderTrackZX(tr, mg_zx);
252 RenderTrackZY(tr, mg_zy);
253 RenderTrackPhiZ(tr, mg_phiz, wrap_phi);
254 }
255 },
256 wrap_phi);
257}
258
268template <typename TrackContainer = std::vector<VisGenericTrack>>
269void Draw3D(const std::vector<int> &hit_ids, const TrackContainer &tracks = {},
270 const std::vector<VisPoint3D> &points = {}, bool drawSkeleton = true)
271{
272 Draw3DCore(hit_ids, points, drawSkeleton,
273 [&](double bounds[6])
274 {
275 for(const auto &tr : tracks)
276 {
277 RenderTrack3D(tr, bounds);
278 }
279 });
280}
281
282} // namespace Vis
283} // namespace CHeT
284
285#endif // CHETVISUALIZER_HH
void RenderTrack3D(const VisLineTrack &tr, double bounds[6])
void RenderTrack2D(const VisLineTrack &tr, TMultiGraph *mg_xy)
void RenderTrackZX(const VisLineTrack &tr, TMultiGraph *mg_zx)
void Draw3DCore(const std::vector< int > &hit_ids, const std::vector< VisPoint3D > &points, bool drawSkeleton, const std::function< void(double[6])> &trackDrawer)
void RenderTrackPhiZ(const VisLineTrack &tr, TMultiGraph *mg_phiz, bool wrap_phi=true)
void Draw3D(const std::vector< int > &hit_ids, const TrackContainer &tracks={}, const std::vector< VisPoint3D > &points={}, bool drawSkeleton=true)
Draws the full 3D detector view.
void Draw2D(const std::vector< int > &bundle_ids, const TrackContainer &tracks={}, const std::vector< VisPoint2D > &extraPoints={}, bool wrap_phi=true)
Draws 2D projections: Phi-Z Unrolled Map, ZX/ZY Side views, and XY Transverse view.
void RenderTrackZY(const VisLineTrack &tr, TMultiGraph *mg_zy)
void Draw2DCore(const std::vector< int > &bundle_ids, const std::vector< VisPoint2D > &extraPoints, const std::function< void(TMultiGraph *, TMultiGraph *, TMultiGraph *, TMultiGraph *)> &trackDrawer, bool wrap_phi=true)
Root namespace for the Cylindrical Helix Tracker (CHeT) project.
Structure representing a reconstructed 3D generic track for visualization.
int color
ROOT Color index.
bool isLocalFrame
If true, coordinates are in Detector Local Frame.
VisGenericTrack(std::vector< VisPoint3D > _pts, int _c=1, int _w=2, int _s=1, bool _loc=false)
std::vector< VisPoint3D > points
Sequence of 3D points.
Structure representing a reconstructed 3D helix track for visualization.
double z0
Initial Z position (at t=0)
double t_min
Minimum angular parameter range.
double dz_dt
Pitch: Z advancement per radian.
bool isLocalFrame
If true, coordinates are in Detector Local Frame.
VisHelixTrack(double _cx, double _cy, double _r, double _z0, double _dz, double _tmin, double _tmax, int _c=1, int _w=2, int _s=1, bool _loc=false)
double t_max
Maximum angular parameter range (default: 2*PI)
double cy
Helix center in XY plane.
int color
ROOT Color index.
Structure representing a reconstructed 3D line track for visualization.
VisLineTrack(double _x, double _y, double _z, double _dx, double _dy, double _dz, int _col=54, int _w=2, int _s=1, bool _isLocal=false)
double uz
Direction unit vector.
VisLineTrack()=default
Construct a new VisLineTrack. Automatically normalizes the direction vector (dx, dy,...
double z0
Origin point.
bool isLocalFrame
If true, coordinates are in Detector Local Frame.
int color
ROOT Color index.
Structure representing a 2D point (e.g., for Hough space or transverse projection).
int color
ROOT Color index.
VisPoint2D(double _x, double _y, int _col=kBlue, int _mst=1, double _sz=1.0)
int markerStyle
ROOT Marker style (e.g., 20 = Full Circle)
double size
Marker size.
double y
Coordinates.
Structure representing a 3D point (e.g., space points, clusters).
double size
Marker size.
VisPoint3D(double _x, double _y, double _z, int _col=kRed, int _mst=20, double _sz=1.0, bool _isLocal=false)
int markerStyle
ROOT Marker style.
int color
ROOT Color index.
bool isLocalFrame
If true, coordinates are in Detector Local Frame.
double z
Coordinates.