Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
track.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_eve
3/// Demonstrates usage of TEveTrackPRopagator with different magnetic
4/// field configurations.
5/// Needs to be run in compiled mode.
6/// root
7/// ~~~{.cpp}
8/// .L track.C+
9/// track(3, kTRUE)
10/// ~~~
11/// void track(Int_t mode = 5, Bool_t isRungeKutta = kTRUE)
12/// Modes are
13/// 0. B = 0, no difference between signed and charge particles;
14/// 1. constant B field (along z, but could have arbitrary direction);
15/// 2. variable B field, sign change at R = 200 cm;
16/// 3. magnetic field with a zero-field region;
17/// 4. CMS magnetic field - simple track;
18/// 5. CMS magnetic field - track with different path-marks.
19/// 6. Conceptual ILC detector, problematic track
20///
21/// \image html eve_track.png
22/// \macro_code
23///
24/// \author Alja Mrak-Tadel
25
26#include "TEveTrackPropagator.h"
27#include "TEveTrack.h"
28#include "TEveVSDStructs.h"
29#include "TEveManager.h"
30#include "TEveViewer.h"
31#include "TSystem.h"
32#include "TGLViewer.h"
33#include "TMath.h"
34
35#include "TEveViewer.h"
36#include "TEvePointSet.h"
37
38#include <iostream>
39
40TEveTrackPropagator *g_prop = nullptr;
41
42class GappedField : public TEveMagField {
43public:
44 GappedField() : TEveMagField() {}
45 ~GappedField() override{};
46
47 virtual Double_t GetMaxFieldMagD() { return 4; }
48
49 TEveVectorD GetFieldD(Double_t /*x*/, Double_t /*y*/, Double_t z) const override
50 {
51 if (TMath::Abs(z) < 300)
52 return TEveVectorD(0, 0, -4);
53 if (TMath::Abs(z) < 600)
54 return TEveVectorD(0, 0, 0);
55 return TEveVectorD(0, 0, 4);
56 }
57};
58
59//==============================================================================
60
61class CmsMagField : public TEveMagField {
62 bool m_magnetIsOn;
63 bool m_reverse;
64 bool m_simpleModel;
65
66public:
67 CmsMagField() : m_magnetIsOn(true), m_reverse(false), m_simpleModel(true) {}
68
69 ~CmsMagField() override {}
70
71 void setMagnetState(bool state)
72 {
73 if (state != m_magnetIsOn) {
74 if (state)
75 std::cout << "Magnet state is changed to ON" << std::endl;
76 else
77 std::cout << "Magnet state is changed to OFF" << std::endl;
78 }
79 m_magnetIsOn = state;
80 }
81
82 bool isMagnetOn() const { return m_magnetIsOn; }
83 void setReverseState(bool state) { m_reverse = state; }
84 bool isReverse() const { return m_reverse; }
85 void setSimpleModel(bool simpleModel) { m_simpleModel = simpleModel; }
86 bool isSimpleModel() const { return m_simpleModel; }
87
88 Double_t GetMaxFieldMagD() const override { return m_magnetIsOn ? 3.8 : 0.0; }
89
91 {
92 double R = sqrt(x * x + y * y);
93 double field = m_reverse ? -GetMaxFieldMagD() : GetMaxFieldMagD();
94 // barrel
95 if (TMath::Abs(z) < 724) {
96 // inside solenoid
97 if (R < 300)
98 return TEveVectorD(0, 0, field);
99 // outside solenoid
100 if (m_simpleModel || (R > 461.0 && R < 490.5) || (R > 534.5 && R < 597.5) || (R > 637.0 && R < 700.0))
101 return TEveVectorD(0, 0, -field / 3.8 * 1.2);
102
103 } else {
104 // endcaps
105 if (m_simpleModel) {
106 if (R < 50)
107 return TEveVectorD(0, 0, field);
108 if (z > 0)
109 return TEveVectorD(x / R * field / 3.8 * 2.0, y / R * field / 3.8 * 2.0, 0);
110 else
111 return TEveVectorD(-x / R * field / 3.8 * 2.0, -y / R * field / 3.8 * 2.0, 0);
112 }
113 // proper model
114 if ((TMath::Abs(z) > 724 && TMath::Abs(z) < 786) || (TMath::Abs(z) > 850 && TMath::Abs(z) < 910) ||
115 (TMath::Abs(z) > 975 && TMath::Abs(z) < 1003)) {
116 if (z > 0)
117 return TEveVectorD(x / R * field / 3.8 * 2.0, y / R * field / 3.8 * 2.0, 0);
118 else
119 return TEveVectorD(-x / R * field / 3.8 * 2.0, -y / R * field / 3.8 * 2.0, 0);
120 }
121 }
122 return TEveVectorD(0, 0, 0);
123 }
124};
125
126//==============================================================================
127//==============================================================================
128
129//______________________________________________________________________________
130TEveTrack *make_track(TEveTrackPropagator *prop, Int_t sign)
131{
132 // Make track with given propagator.
133 // Add to math-marks to test fit.
134
135 auto rc = new TEveRecTrackD();
136 rc->fV.Set(0.028558, -0.000918, 3.691919);
137 rc->fP.Set(0.767095, -2.400006, -0.313103);
138 rc->fSign = sign;
139
140 auto track = new TEveTrack(rc, prop);
141 track->SetName(Form("Charge %d", sign));
142 // daughter 0
144 pm1->fV.Set(1.479084, -4.370661, 3.119761);
145 track->AddPathMark(*pm1);
146 // daughter 1
148 pm2->fV.Set(57.72345, -89.77011, -9.783746);
149 track->AddPathMark(*pm2);
150
151 return track;
152}
153
154void track(Int_t mode = 1, Bool_t isRungeKutta = kTRUE)
155{
156
159
160 auto list = new TEveTrackList();
161 auto prop = g_prop = list->GetPropagator();
162 prop->SetFitDaughters(kFALSE);
163 prop->SetMaxZ(1000);
164
165 if (isRungeKutta) {
167 list->SetName("RK Propagator");
168 } else {
169 list->SetName("Heix Propagator");
170 }
171
172 TEveTrack *track = nullptr;
173 switch (mode) {
174 case 0: {
175 // B = 0 no difference between signed and charge particles
176 prop->SetMagField(0.);
177 list->SetElementName(Form("%s, zeroB", list->GetElementName()));
178 track = make_track(prop, 1);
179 break;
180 }
181
182 case 1: {
183 // constant B field, const angle
184 prop->SetMagFieldObj(new TEveMagFieldConst(0., 0., -3.8));
185 list->SetElementName(Form("%s, constB", list->GetElementName()));
186 track = make_track(prop, 1);
187 break;
188 }
189
190 case 2: {
191 // variable B field, sign change at R = 200 cm
192 prop->SetMagFieldObj(new TEveMagFieldDuo(200, -4.4, 2));
193 list->SetElementName(Form("%s, duoB", list->GetElementName()));
194 track = make_track(prop, 1);
195 break;
196 }
197
198 case 3: {
199 // gapped field
200 prop->SetMagFieldObj(new GappedField());
201 list->SetElementName(Form("%s, gappedB", list->GetElementName()));
202
203 auto rc = new TEveRecTrackD();
204 rc->fV.Set(0.028558, -0.000918, 3.691919);
205 rc->fP.Set(0.767095, -0.400006, 2.313103);
206 rc->fSign = 1;
207 track = new TEveTrack(rc, prop);
208
209 auto marker = new TEvePointSet(2);
210 marker->SetElementName("B field break points");
211 marker->SetPoint(0, 0., 0., 300.f);
212 marker->SetPoint(1, 0., 0., 600.f);
213 marker->SetMarkerColor(3);
214 gEve->AddElement(marker);
215 break;
216 }
217
218 case 4: {
219 // Magnetic field of CMS I.
220 auto mf = new CmsMagField;
221 mf->setReverseState(true);
222
223 prop->SetMagFieldObj(mf);
224 prop->SetMaxR(1000);
225 prop->SetMaxZ(1000);
226 prop->SetRnrDaughters(kTRUE);
227 prop->SetRnrDecay(kTRUE);
228 prop->RefPMAtt().SetMarkerStyle(4);
229 list->SetElementName(Form("%s, CMS field", list->GetElementName()));
230
231 auto rc = new TEveRecTrackD();
232 rc->fV.Set(0.027667, 0.007919, 0.895964);
233 rc->fP.Set(3.903134, 2.252232, -3.731366);
234 rc->fSign = -1;
235 track = new TEveTrack(rc, prop);
236
237 track->AddPathMark(
238 TEvePathMarkD(TEvePathMarkD::kDaughter, TEveVectorD(3.576755e+00, 2.080579e+00, -2.507230e+00)));
239 track->AddPathMark(
240 TEvePathMarkD(TEvePathMarkD::kDaughter, TEveVectorD(8.440379e+01, 6.548286e+01, -8.788129e+01)));
241 track->AddPathMark(
242 TEvePathMarkD(TEvePathMarkD::kDaughter, TEveVectorD(1.841321e+02, 3.915693e+02, -3.843072e+02)));
243 track->AddPathMark(
244 TEvePathMarkD(TEvePathMarkD::kDaughter, TEveVectorD(1.946167e+02, 4.793932e+02, -4.615060e+02)));
245 track->AddPathMark(TEvePathMarkD(TEvePathMarkD::kDecay, TEveVectorD(2.249656e+02, 5.835767e+02, -5.565275e+02)));
246
247 track->SetRnrPoints(kTRUE);
248 track->SetMarkerStyle(4);
249
250 break;
251 }
252
253 case 5: {
254 // Magnetic field of CMS I.
255 auto mf = new CmsMagField;
256 mf->setReverseState(true);
257 mf->setSimpleModel(false);
258
259 prop->SetMagFieldObj(mf);
260 prop->SetMaxR(1000);
261 prop->SetMaxZ(1000);
262 prop->SetRnrReferences(kTRUE);
263 prop->SetRnrDaughters(kTRUE);
264 prop->SetRnrDecay(kTRUE);
265 prop->RefPMAtt().SetMarkerStyle(4);
266 list->SetElementName(Form("%s, CMS field", list->GetElementName()));
267
268 auto rc = new TEveRecTrackD();
269 rc->fV.Set(-16.426592, 16.403185, -19.782692);
270 rc->fP.Set(3.631100, 3.643450, 0.682254);
271 rc->fSign = -1;
272 track = new TEveTrack(rc, prop);
273
275 TEveVectorD(-1.642659e+01, 1.640318e+01, -1.978269e+01),
276 TEveVectorD(3.631100, 3.643450, 0.682254)));
278 TEveVectorD(-1.859987e+00, 3.172243e+01, -1.697866e+01),
279 TEveVectorD(3.456056, 3.809894, 0.682254)));
281 TEveVectorD(4.847579e+01, 9.871711e+01, -5.835719e+00),
282 TEveVectorD(2.711614, 4.409945, 0.687656)));
283 track->AddPathMark(
284 TEvePathMarkD(TEvePathMarkD::kDaughter, TEveVectorD(1.342045e+02, 4.203950e+02, 3.846268e+01)));
285 track->AddPathMark(
286 TEvePathMarkD(TEvePathMarkD::kDaughter, TEveVectorD(1.483827e+02, 5.124750e+02, 5.064311e+01)));
287 track->AddPathMark(
288 TEvePathMarkD(TEvePathMarkD::kDaughter, TEveVectorD(1.674676e+02, 6.167731e+02, 6.517403e+01)));
289 track->AddPathMark(TEvePathMarkD(TEvePathMarkD::kDecay, TEveVectorD(1.884976e+02, 7.202000e+02, 7.919290e+01)));
290
291 track->SetRnrPoints(kTRUE);
292 track->SetMarkerStyle(4);
293
294 break;
295 }
296
297 case 6: {
298 // Problematic track from Druid
299 prop->SetMagFieldObj(new TEveMagFieldDuo(350, -3.5, 2.0));
300 prop->SetMaxR(1000);
301 prop->SetMaxZ(1000);
302 prop->SetRnrReferences(kTRUE);
303 prop->SetRnrDaughters(kTRUE);
304 prop->SetRnrDecay(kTRUE);
305 prop->RefPMAtt().SetMarkerStyle(4);
306 list->SetElementName(Form("%s, Some ILC Detector field", list->GetElementName()));
307
308 auto rc = new TEveRecTrackD();
309 rc->fV.Set(57.1068, 31.2401, -7.07629);
310 rc->fP.Set(4.82895, 2.35083, -0.611757);
311 rc->fSign = 1;
312 track = new TEveTrack(rc, prop);
313
314 track->AddPathMark(
315 TEvePathMarkD(TEvePathMarkD::kDaughter, TEveVectorD(1.692235e+02, 7.047929e+01, -2.064785e+01)));
316 track->AddPathMark(
317 TEvePathMarkD(TEvePathMarkD::kDaughter, TEveVectorD(5.806180e+02, 6.990633e+01, -6.450000e+01)));
318 track->AddPathMark(TEvePathMarkD(TEvePathMarkD::kDecay, TEveVectorD(6.527213e+02, 1.473249e+02, -8.348498e+01)));
319
320 track->SetRnrPoints(kTRUE);
321 track->SetMarkerStyle(4);
322
323 break;
324 }
325 };
326
327 if (isRungeKutta)
328 list->SetLineColor(kMagenta);
329 else
330 list->SetLineColor(kCyan);
331
332 track->SetLineColor(list->GetLineColor());
333
334 gEve->AddElement(list);
335 list->AddElement(track);
336
337 track->MakeTrack();
338
340 TGLViewer *gv = ev->GetGLViewer();
342
345
346 gv->CurrentCamera().RotateRad(-0.5, 1.4);
347 gv->RequestDraw();
348}
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
double Double_t
Definition RtypesCore.h:59
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
@ kMagenta
Definition Rtypes.h:66
@ kCyan
Definition Rtypes.h:66
R__EXTERN TEveManager * gEve
TEvePathMarkT< Double_t > TEvePathMarkD
TEveRecTrackT< Double_t > TEveRecTrackD
TEveVectorT< Double_t > TEveVectorD
Definition TEveVector.h:125
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h prop
Option_t Option_t TPoint TPoint const char mode
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2489
@ kSigSegmentationViolation
R__EXTERN TSystem * gSystem
Definition TSystem.h:561
void SetLineColor(Color_t col) override
Set the line color.
Definition TEveLine.h:48
void SetRnrPoints(Bool_t r)
Set rendering of points. Propagate to projected lines.
Definition TEveLine.cxx:144
Implements constant magnetic field, given by a vector fB.
Implements constant magnetic filed that switches on given axial radius fR2 from vector fBIn to fBOut.
Abstract base-class for interfacing to magnetic field needed by the TEveTrackPropagator.
virtual TEveVectorD GetFieldD(Double_t x, Double_t y, Double_t z) const
virtual Double_t GetMaxFieldMagD() const
void AddElement(TEveElement *element, TEveElement *parent=nullptr)
Add an element.
TEveViewer * GetDefaultViewer() const
Returns the default viewer - the first one in the fViewers list.
static TEveManager * Create(Bool_t map_window=kTRUE, Option_t *opt="FIV")
If global TEveManager* gEve is not set initialize it.
void Redraw3D(Bool_t resetCameras=kFALSE, Bool_t dropLogicals=kFALSE)
TEvePointSet is a render-element holding a collection of 3D points with optional per-point TRef and a...
void SetMarkerStyle(Style_t mstyle=1) override
Set marker style, propagate to projecteds.
A list of tracks supporting change of common attributes and selection based on track parameters.
Definition TEveTrack.h:140
Holding structure for a number of track rendering parameters.
Visual representation of a track.
Definition TEveTrack.h:33
virtual void MakeTrack(Bool_t recurse=kTRUE)
Calculate track representation based on track data and current settings of the propagator.
void AddPathMark(const TEvePathMarkD &pm)
Definition TEveTrack.h:107
Eve representation of TGLViewer.
Definition TEveViewer.h:31
TGLViewer * GetGLViewer() const
Definition TEveViewer.h:51
virtual Bool_t RotateRad(Double_t hRotate, Double_t vRotate)
Rotate camera around center.
@ kAxesOrigin
Definition TGLUtil.h:952
Base GL viewer object - used by both standalone and embedded (in pad) GL.
Definition TGLViewer.h:55
void RequestDraw(Short_t LOD=TGLRnrCtx::kLODMed)
Post request for redraw of viewer at level of detail 'LOD' Request is directed via cross thread gVirt...
void SetGuideState(Int_t axesType, Bool_t axesDepthTest, Bool_t referenceOn, const Double_t *referencePos)
Set the state of guides (axes & reference markers) from arguments.
TGLCamera & CurrentCamera() const
Definition TGLViewer.h:268
virtual void IgnoreSignal(ESignals sig, Bool_t ignore=kTRUE)
If ignore is true ignore the specified signal, else restore previous behaviour.
Definition TSystem.cxx:593
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition TSystem.cxx:416
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
VecExpr< UnaryOp< Sqrt< T >, VecExpr< A, T, D >, T >, T, D > sqrt(const VecExpr< A, T, D > &rhs)
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:123