Logo ROOT  
Reference Guide
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
27#include "TEveTrackPropagator.h"
28#include "TEveTrack.h"
29#include "TEveVSDStructs.h"
30#include "TEveManager.h"
31#include "TEveViewer.h"
32#include "TSystem.h"
33#include "TGLViewer.h"
34#include "TMath.h"
35
36#include "TEveViewer.h"
37#include "TEvePointSet.h"
38
39#include <iostream>
40
41TEveTrackPropagator* g_prop = 0;
42
43class GappedField : public TEveMagField
44{
45public:
46 GappedField():TEveMagField(){}
47 ~GappedField(){};
48
49 virtual Double_t GetMaxFieldMagD() { return 4; }
50
51 virtual TEveVectorD GetFieldD(Double_t /*x*/, Double_t /*y*/, Double_t z) const
52 {
53 if (TMath::Abs(z) < 300) return TEveVectorD(0, 0, -4);
54 if (TMath::Abs(z) < 600) return TEveVectorD(0, 0, 0);
55 return TEveVectorD(0, 0, 4);
56 }
57};
58
59//==============================================================================
60
61class CmsMagField: public TEveMagField
62{
63 bool m_magnetIsOn;
64 bool m_reverse;
65 bool m_simpleModel;
66
67public:
68 CmsMagField():
69 m_magnetIsOn(true),
70 m_reverse(false),
71 m_simpleModel(true){}
72
73 virtual ~CmsMagField(){}
74
75 void setMagnetState( bool state )
76 {
77 if (state != m_magnetIsOn)
78 {
79 if ( state )
80 std::cout << "Magnet state is changed to ON" << std::endl;
81 else
82 std::cout << "Magnet state is changed to OFF" << std::endl;
83 }
84 m_magnetIsOn = state;
85 }
86
87 bool isMagnetOn() const { return m_magnetIsOn;}
88 void setReverseState(bool state) { m_reverse = state; }
89 bool isReverse() const { return m_reverse;}
90 void setSimpleModel(bool simpleModel) { m_simpleModel = simpleModel; }
91 bool isSimpleModel() const { return m_simpleModel;}
92
93 virtual Double_t GetMaxFieldMagD() const { return m_magnetIsOn ? 3.8 : 0.0; }
94
96 {
97 double R = sqrt(x*x+y*y);
98 double field = m_reverse ? -GetMaxFieldMagD() : GetMaxFieldMagD();
99 //barrel
100 if ( TMath::Abs(z) < 724 )
101 {
102 //inside solenoid
103 if ( R < 300) return TEveVectorD(0,0,field);
104 // outside solenoid
105 if ( m_simpleModel ||
106 ( R>461.0 && R<490.5 ) ||
107 ( R>534.5 && R<597.5 ) ||
108 ( R>637.0 && R<700.0 ) )
109 return TEveVectorD(0,0,-field/3.8*1.2);
110
111 } else {
112 // endcaps
113 if (m_simpleModel)
114 {
115 if ( R < 50 ) return TEveVectorD(0,0,field);
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 // proper model
122 if ( ( TMath::Abs(z)>724 && TMath::Abs(z)<786 ) ||
123 ( TMath::Abs(z)>850 && TMath::Abs(z)<910 ) ||
124 ( TMath::Abs(z)>975 && TMath::Abs(z)<1003 ) )
125 {
126 if ( z > 0 )
127 return TEveVectorD(x/R*field/3.8*2.0, y/R*field/3.8*2.0, 0);
128 else
129 return TEveVectorD(-x/R*field/3.8*2.0, -y/R*field/3.8*2.0, 0);
130 }
131 }
132 return TEveVectorD(0,0,0);
133 }
134};
135
136
137//==============================================================================
138//==============================================================================
139
140//______________________________________________________________________________
141TEveTrack* make_track(TEveTrackPropagator* prop, Int_t sign)
142{
143 // Make track with given propagator.
144 // Add to math-marks to test fit.
145
146 auto rc = new TEveRecTrackD();
147 rc->fV.Set(0.028558, -0.000918, 3.691919);
148 rc->fP.Set(0.767095, -2.400006, -0.313103);
149 rc->fSign = sign;
150
151 auto track = new TEveTrack(rc, prop);
152 track->SetName(Form("Charge %d", sign));
153 // daughter 0
155 pm1->fV.Set(1.479084, -4.370661, 3.119761);
156 track->AddPathMark(*pm1);
157 // daughter 1
159 pm2->fV.Set(57.72345, -89.77011, -9.783746);
160 track->AddPathMark(*pm2);
161
162 return track;
163}
164
165
166void track(Int_t mode = 1, Bool_t isRungeKutta = kTRUE)
167{
168
171
172 auto list = new TEveTrackList();
173 auto prop = g_prop = list->GetPropagator();
174 prop->SetFitDaughters(kFALSE);
175 prop->SetMaxZ(1000);
176
177 if (isRungeKutta)
178 {
180 list->SetName("RK Propagator");
181 }
182 else
183 {
184 list->SetName("Heix Propagator");
185 }
186
187 TEveTrack *track = 0;
188 switch (mode)
189 {
190 case 0:
191 {
192 // B = 0 no difference between signed and charge particles
193 prop->SetMagField(0.);
194 list->SetElementName(Form("%s, zeroB", list->GetElementName()));
195 track = make_track(prop, 1);
196 break;
197 }
198
199 case 1:
200 {
201 // constant B field, const angle
202 prop->SetMagFieldObj(new TEveMagFieldConst(0., 0., -3.8));
203 list->SetElementName(Form("%s, constB", list->GetElementName()));
204 track = make_track(prop, 1);
205 break;
206 }
207
208 case 2:
209 {
210 // variable B field, sign change at R = 200 cm
211 prop->SetMagFieldObj(new TEveMagFieldDuo(200, -4.4, 2));
212 list->SetElementName(Form("%s, duoB", list->GetElementName()));
213 track = make_track(prop, 1);
214 break;
215 }
216
217 case 3:
218 {
219 // gapped field
220 prop->SetMagFieldObj(new GappedField());
221 list->SetElementName(Form("%s, gappedB", list->GetElementName()));
222
223
224 auto rc = new TEveRecTrackD();
225 rc->fV.Set(0.028558, -0.000918, 3.691919);
226 rc->fP.Set(0.767095, -0.400006, 2.313103);
227 rc->fSign = 1;
228 track = new TEveTrack(rc, prop);
229
230 auto marker = new TEvePointSet(2);
231 marker->SetElementName("B field break points");
232 marker->SetPoint(0, 0., 0., 300.f);
233 marker->SetPoint(1, 0., 0., 600.f);
234 marker->SetMarkerColor(3);
235 gEve->AddElement(marker);
236 break;
237 }
238
239 case 4:
240 {
241 // Magnetic field of CMS I.
242 auto mf = new CmsMagField;
243 mf->setReverseState(true);
244
245 prop->SetMagFieldObj(mf);
246 prop->SetMaxR(1000);
247 prop->SetMaxZ(1000);
248 prop->SetRnrDaughters(kTRUE);
249 prop->SetRnrDecay(kTRUE);
250 prop->RefPMAtt().SetMarkerStyle(4);
251 list->SetElementName(Form("%s, CMS field", list->GetElementName()));
252
253
254 auto rc = new TEveRecTrackD();
255 rc->fV.Set(0.027667, 0.007919, 0.895964);
256 rc->fP.Set(3.903134, 2.252232, -3.731366);
257 rc->fSign = -1;
258 track = new TEveTrack(rc, prop);
259
261 TEveVectorD(3.576755e+00, 2.080579e+00, -2.507230e+00)));
263 TEveVectorD(8.440379e+01, 6.548286e+01, -8.788129e+01)));
265 TEveVectorD(1.841321e+02, 3.915693e+02, -3.843072e+02)));
267 TEveVectorD(1.946167e+02, 4.793932e+02, -4.615060e+02)));
269 TEveVectorD(2.249656e+02, 5.835767e+02, -5.565275e+02)));
270
271 track->SetRnrPoints(kTRUE);
272 track->SetMarkerStyle(4);
273
274 break;
275 }
276
277 case 5:
278 {
279 // Magnetic field of CMS I.
280 auto mf = new CmsMagField;
281 mf->setReverseState(true);
282 mf->setSimpleModel(false);
283
284 prop->SetMagFieldObj(mf);
285 prop->SetMaxR(1000);
286 prop->SetMaxZ(1000);
287 prop->SetRnrReferences(kTRUE);
288 prop->SetRnrDaughters(kTRUE);
289 prop->SetRnrDecay(kTRUE);
290 prop->RefPMAtt().SetMarkerStyle(4);
291 list->SetElementName(Form("%s, CMS field", list->GetElementName()));
292
293 auto rc = new TEveRecTrackD();
294 rc->fV.Set(-16.426592, 16.403185, -19.782692);
295 rc->fP.Set(3.631100, 3.643450, 0.682254);
296 rc->fSign = -1;
297 track = new TEveTrack(rc, prop);
298
300 TEveVectorD(-1.642659e+01, 1.640318e+01, -1.978269e+01),
301 TEveVectorD(3.631100, 3.643450, 0.682254)));
303 TEveVectorD(-1.859987e+00, 3.172243e+01, -1.697866e+01),
304 TEveVectorD(3.456056, 3.809894, 0.682254)));
306 TEveVectorD(4.847579e+01, 9.871711e+01, -5.835719e+00),
307 TEveVectorD(2.711614, 4.409945, 0.687656)));
309 TEveVectorD(1.342045e+02, 4.203950e+02, 3.846268e+01)));
311 TEveVectorD(1.483827e+02, 5.124750e+02, 5.064311e+01)));
313 TEveVectorD(1.674676e+02, 6.167731e+02, 6.517403e+01)));
315 TEveVectorD(1.884976e+02, 7.202000e+02, 7.919290e+01)));
316
317 track->SetRnrPoints(kTRUE);
318 track->SetMarkerStyle(4);
319
320 break;
321 }
322
323 case 6:
324 {
325 // Problematic track from Druid
326 prop->SetMagFieldObj(new TEveMagFieldDuo(350, -3.5, 2.0));
327 prop->SetMaxR(1000);
328 prop->SetMaxZ(1000);
329 prop->SetRnrReferences(kTRUE);
330 prop->SetRnrDaughters(kTRUE);
331 prop->SetRnrDecay(kTRUE);
332 prop->RefPMAtt().SetMarkerStyle(4);
333 list->SetElementName(Form("%s, Some ILC Detector field",
334 list->GetElementName()));
335
336 auto rc = new TEveRecTrackD();
337 rc->fV.Set(57.1068, 31.2401, -7.07629);
338 rc->fP.Set(4.82895, 2.35083, -0.611757);
339 rc->fSign = 1;
340 track = new TEveTrack(rc, prop);
341
343 TEveVectorD(1.692235e+02, 7.047929e+01, -2.064785e+01)));
345 TEveVectorD(5.806180e+02, 6.990633e+01, -6.450000e+01)));
347 TEveVectorD(6.527213e+02, 1.473249e+02, -8.348498e+01)));
348
349 track->SetRnrPoints(kTRUE);
350 track->SetMarkerStyle(4);
351
352 break;
353 }
354 };
355
356 if (isRungeKutta)
357 list->SetLineColor(kMagenta);
358 else
359 list->SetLineColor(kCyan);
360
361 track->SetLineColor(list->GetLineColor());
362
363 gEve->AddElement(list);
364 list->AddElement(track);
365
366 track->MakeTrack();
367
369 TGLViewer *gv = ev->GetGLViewer();
371
374
375 gv->CurrentCamera().RotateRad(-0.5, 1.4);
376 gv->RequestDraw();
377}
int Int_t
Definition: RtypesCore.h:43
const Bool_t kFALSE
Definition: RtypesCore.h:90
bool Bool_t
Definition: RtypesCore.h:61
double Double_t
Definition: RtypesCore.h:57
const Bool_t kTRUE
Definition: RtypesCore.h:89
@ kMagenta
Definition: Rtypes.h:64
@ kCyan
Definition: Rtypes.h:64
R__EXTERN TEveManager * gEve
Definition: TEveManager.h:243
TEvePathMarkT< Double_t > TEvePathMarkD
Definition: TEvePathMark.h:56
TEveRecTrackT< Double_t > TEveRecTrackD
TEveVectorT< Double_t > TEveVectorD
Definition: TEveVector.h:124
double sqrt(double)
char * Form(const char *fmt,...)
@ kSigSegmentationViolation
R__EXTERN TSystem * gSystem
Definition: TSystem.h:556
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition: TAttMarker.h:40
virtual void SetLineColor(Color_t col)
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=0)
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)
Definition: TEveManager.h:168
TEvePointSet is a render-element holding a collection of 3D points with optional per-point TRef and a...
Definition: TEvePointSet.h:36
virtual void SetMarkerStyle(Style_t mstyle=1)
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.
void SetRnrDecay(Bool_t x)
Set decay rendering and rebuild tracks.
void SetRnrDaughters(Bool_t x)
Set daughter rendering and rebuild tracks.
void SetMagFieldObj(TEveMagField *field, Bool_t own_field=kTRUE)
Set constant magnetic field and rebuild tracks.
void SetMaxR(Double_t x)
Set maximum radius and rebuild tracks.
void SetFitDaughters(Bool_t x)
Set daughter creation point fitting and rebuild tracks.
void SetStepper(EStepper_e s)
void SetRnrReferences(Bool_t x)
Set track-reference rendering and rebuild tracks.
void SetMaxZ(Double_t x)
Set maximum z and rebuild tracks.
void SetMagField(Double_t bX, Double_t bY, Double_t bZ)
Set constant magnetic field and rebuild tracks.
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.
Definition: TEveTrack.cxx:340
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.
Definition: TGLCamera.cxx:927
@ kAxesOrigin
Definition: TGLUtil.h:948
Base GL viewer object - used by both standalone and embedded (in pad) GL.
Definition: TGLViewer.h:57
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...
Definition: TGLViewer.cxx:438
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.
Definition: TGLViewer.cxx:2059
TGLCamera & CurrentCamera() const
Definition: TGLViewer.h:269
virtual void IgnoreSignal(ESignals sig, Bool_t ignore=kTRUE)
If ignore is true ignore the specified signal, else restore previous behaviour.
Definition: TSystem.cxx:591
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition: TSystem.cxx:414
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
Short_t Abs(Short_t d)
Definition: TMathBase.h:120