New files: allow interaction with the track, more configurability (render as line...
[u/mrichter/AliRoot.git] / EVE / Reve / Track.cxx
CommitLineData
5a5a1232 1// $Header$
2
3#include "Track.h"
4#include "MCHelixLine.hi"
5
6#include <TPolyLine3D.h>
7#include <TPolyMarker3D.h>
8#include <TColor.h>
9
10// Updates
11#include <Reve/RGTopFrame.h>
12#include <TCanvas.h>
13
14#include <vector>
15
16using namespace Reve;
17
18//______________________________________________________________________
19// Track
20//
21
22ClassImp(Reve::Track)
23
265ecb21 24Track::Track() :
25 RenderElement(),
26 TPolyLine3D(),
5a5a1232 27
265ecb21 28 fV(),
29 fP(),
30 fBeta(0),
31 fCharge(0),
32 fLabel(0),
33 fPathMarks(),
34
35 fRnrStyle(0),
36
37 fName(),
38 fTitle()
39{}
40
3d75306d 41Track::Track(TParticle* t, Int_t label, TrackRnrStyle* rs):
42 RenderElement(),
43 TPolyLine3D(),
44
45 fV(t->Vx(), t->Vy(), t->Vz()),
46 fP(t->Px(), t->Py(), t->Pz()),
47 fBeta(t->P()/t->Energy()),
48 fCharge(0),
49 fLabel(label),
50 fPathMarks(),
51
52 fRnrStyle(rs),
53
54 fName(t->GetName()),
55 fTitle()
56{
57 fLineColor = fRnrStyle->GetColor();
58 fMainColorPtr = &fLineColor;
59
60 TParticlePDG* pdgp = t->GetPDG();
61 if (pdgp)
62 fCharge = (Int_t) TMath::Nint(pdgp->Charge()/3);
63}
64
265ecb21 65Track::Track(Reve::MCTrack* t, TrackRnrStyle* rs):
66 RenderElement(),
67 TPolyLine3D(),
5a5a1232 68
265ecb21 69 fV(t->Vx(), t->Vy(), t->Vz()),
70 fP(t->Px(), t->Py(), t->Pz()),
71 fBeta(t->P()/t->Energy()),
72 fCharge(0),
73 fLabel(t->label),
74 fPathMarks(),
75
76 fRnrStyle(rs),
77
78 fName(t->GetName()),
79 fTitle()
80{
5a5a1232 81 fLineColor = fRnrStyle->GetColor();
82 fMainColorPtr = &fLineColor;
83
5a5a1232 84 TParticlePDG* pdgp = t->GetPDG();
85 if(pdgp == 0) {
86 t->ResetPdgCode(); pdgp = t->GetPDG();
87 }
48dc973d 88 fCharge = (Int_t) TMath::Nint(pdgp->Charge()/3);
5a5a1232 89}
90
265ecb21 91Track::Track(Reve::RecTrack* t, TrackRnrStyle* rs) :
92 RenderElement(),
93 TPolyLine3D(),
94
95 fV(t->V),
96 fP(t->P),
97 fBeta(t->beta),
98 fCharge(t->sign),
99 fLabel(t->label),
100 fPathMarks(),
101
102 fRnrStyle(rs),
103
104 fName(t->GetName()),
105 fTitle()
5a5a1232 106{
5a5a1232 107 fLineColor = fRnrStyle->GetColor();
108 fMainColorPtr = &fLineColor;
5a5a1232 109}
110
111Track::~Track()
265ecb21 112{
113 for (vpPathMark_i i=fPathMarks.begin(); i!=fPathMarks.end(); ++i)
114 delete *i;
115}
5a5a1232 116
117void Track::Reset(Int_t n_points)
118{
119 delete [] TPolyLine3D::fP; TPolyLine3D::fP = 0;
120 fN = n_points;
121 if(fN) TPolyLine3D::fP = new Float_t [3*fN];
122 memset(TPolyLine3D::fP, 0, 3*fN*sizeof(Float_t));
123 fLastPoint = -1;
124}
125
126/**************************************************************************/
127
128void Track::MakeTrack()
129{
130
131 TrackRnrStyle& RS((fRnrStyle != 0) ? *fRnrStyle : TrackRnrStyle::fgDefStyle);
132
133 Float_t px = fP.x, py = fP.y, pz = fP.z;
134
135 MCVertex mc_v0;
136 mc_v0.x = fV.x;
137 mc_v0.y = fV.y;
138 mc_v0.z = fV.z;
139 mc_v0.t = 0;
140
141 std::vector<MCVertex> track_points;
48dc973d 142 Bool_t decay = kFALSE;
5a5a1232 143
144 if ((TMath::Abs(fV.z) > RS.fMaxZ) || (fV.x*fV.x + fV.y*fV.y > RS.fMaxR*RS.fMaxR))
145 goto make_polyline;
146
01024c63 147 if (fCharge != 0 && TMath::Abs(RS.fMagField) > 1e-5) {
148
149 // Charged particle in magnetic field
5a5a1232 150
48dc973d 151 Float_t a = RS.fgkB2C * RS.fMagField * fCharge;
5a5a1232 152
153 MCHelix helix(fRnrStyle, &mc_v0, TMath::C()*fBeta, &track_points, a); //m->cm
154 helix.Init(TMath::Sqrt(px*px+py*py), pz);
155
156 if(!fPathMarks.empty()){
157 for(std::vector<Reve::PathMark*>::iterator i=fPathMarks.begin(); i!=fPathMarks.end(); ++i) {
158 Reve::PathMark* pm = *i;
159
160 if(RS.fFitDaughters && pm->type == Reve::PathMark::Daughter){
161 if(TMath::Abs(pm->V.z) > RS.fMaxZ
162 || TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR )
163 goto helix_bounds;
164
165 //printf("%s fit daughter \n", fName.Data());
166 helix.LoopToVertex(fP.x, fP.y, fP.z, pm->V.x, pm->V.y, pm->V.z);
167 fP.x -= pm->P.x;
168 fP.y -= pm->P.y;
169 fP.z -= pm->P.z;
170 }
171 if(RS.fFitDecay && pm->type == Reve::PathMark::Decay){
172
173 if(TMath::Abs(pm->V.z) > RS.fMaxZ
174 || TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR )
175 goto helix_bounds;
176 helix.LoopToVertex(fP.x, fP.y, fP.z, pm->V.x, pm->V.y, pm->V.z);
177 decay = true;
178 break;
179 }
180 }
181 }
182 helix_bounds:
183 //go to bounds
48dc973d 184 if(!decay || RS.fFitDecay == kFALSE){
5a5a1232 185 helix.LoopToBounds(px,py,pz);
186 // printf("%s loop to bounds \n",fName.Data() );
187 }
188
01024c63 189 } else {
190
191 // Neutral particle or no field
5a5a1232 192
193 MCLine line(fRnrStyle, &mc_v0, TMath::C()*fBeta, &track_points);
194
195 if(!fPathMarks.empty()){
196 for(std::vector<Reve::PathMark*>::iterator i=fPathMarks.begin(); i!=fPathMarks.end(); ++i) {
197 Reve::PathMark* pm = *i;
198
199 if(RS.fFitDaughters && pm->type == Reve::PathMark::Daughter){
200 if(TMath::Abs(pm->V.z) > RS.fMaxZ
201 || TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR )
202 goto line_bounds;
203 line.GotoVertex(pm->V.x, pm->V.y, pm->V.z);
204 fP.x -= pm->P.x;
205 fP.y -= pm->P.y;
206 fP.z -= pm->P.z;
207 }
208
209 if(RS.fFitDecay && pm->type == Reve::PathMark::Decay){
210 if(TMath::Abs(pm->V.z) > RS.fMaxZ
211 || TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR )
212 goto line_bounds;
213 line.GotoVertex(pm->V.x, pm->V.y, pm->V.z);
214 decay = true;
215 break;
216 }
217 }
218 }
219
220 line_bounds:
48dc973d 221 if(!decay || RS.fFitDecay == kFALSE)
5a5a1232 222 line.GotoBounds(px,py,pz);
223
224 }
225make_polyline:
226 Reset(track_points.size());
227 for(std::vector<MCVertex>::iterator i=track_points.begin(); i!=track_points.end(); ++i)
228 SetNextPoint(i->x, i->y, i->z);
229}
230
231/**************************************************************************/
232
48dc973d 233void Track::ImportHits()
234{
235 Reve::LoadMacro("hits_from_label.C");
236 gROOT->ProcessLine(Form("hits_from_label(%d);", fLabel));
237}
238
239void Track::ImportClusters()
240{
241 Reve::LoadMacro("clusters_from_label.C");
242 gROOT->ProcessLine(Form("clusters_from_label(%d);", fLabel));
243}
244
245
246/**************************************************************************/
247/**************************************************************************/
248
5a5a1232 249//______________________________________________________________________
250// TrackRnrStyle
251//
252
253ClassImp(Reve::TrackRnrStyle)
254
48dc973d 255Float_t TrackRnrStyle::fgDefMagField = 5;
256const Float_t TrackRnrStyle::fgkB2C = 0.299792458e-3;
5a5a1232 257TrackRnrStyle TrackRnrStyle::fgDefStyle;
258
265ecb21 259TrackRnrStyle::TrackRnrStyle() :
260 TObject(),
5a5a1232 261
265ecb21 262 fColor(1),
2074deef 263 fWidth(1),
265ecb21 264 fMagField(fgDefMagField),
5a5a1232 265
265ecb21 266 fMaxR (350),
267 fMaxZ (450),
5a5a1232 268
265ecb21 269 fMaxOrbs (0.5),
270 fMinAng (45),
271 fDelta (0.1),
5a5a1232 272
265ecb21 273 fFitDaughters(kTRUE),
274 fFitDecay (kTRUE)
275{}
5a5a1232 276
277/**************************************************************************/
278/**************************************************************************/
279
280//______________________________________________________________________
281// TrackList
282//
283
284ClassImp(Reve::TrackList)
285
286void TrackList::Init()
287{
288 fMarkerStyle = 6;
289 fMarkerColor = 5;
290 // fMarker->SetMarkerSize(0.05);
291
a8600b56 292 if (fRnrStyle== 0) fRnrStyle = new TrackRnrStyle;
293 SetMainColorPtr(&fRnrStyle->fColor);
5a5a1232 294}
295
a8600b56 296TrackList::TrackList(Int_t n_tracks, TrackRnrStyle* rs) :
7d42b6c2 297 RenderElementListBase(),
265ecb21 298 TPolyMarker3D(n_tracks),
299
300 fTitle(),
301
a8600b56 302 fRnrStyle (rs),
265ecb21 303 fRnrMarkers (kTRUE),
304 fRnrTracks (kTRUE)
5a5a1232 305{
306 Init();
307}
308
a8600b56 309TrackList::TrackList(const Text_t* name, Int_t n_tracks, TrackRnrStyle* rs) :
7d42b6c2 310 RenderElementListBase(),
265ecb21 311 TPolyMarker3D(n_tracks),
a8600b56 312
265ecb21 313 fTitle(),
314
a8600b56 315 fRnrStyle (rs),
265ecb21 316 fRnrMarkers (kTRUE),
317 fRnrTracks (kTRUE)
5a5a1232 318{
319 Init();
320 SetName(name);
321}
322
323void TrackList::Reset(Int_t n_tracks)
324{
325 delete [] fP; fP = 0;
326 fN = n_tracks;
327 if(fN) fP = new Float_t [3*fN];
328 memset(fP, 0, 3*fN*sizeof(Float_t));
329 fLastPoint = -1;
330}
331
332/**************************************************************************/
333
334void TrackList::Paint(Option_t* option)
335{
336 if(fRnrElement) {
337 if(fRnrMarkers) {
338 TPolyMarker3D::Paint(option);
339 }
340 if(fRnrTracks) {
7d42b6c2 341 for(lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
5a5a1232 342 if((*i)->GetRnrElement())
343 (*i)->GetObject()->Paint(option);
344 }
345 }
346 }
347}
348
349/**************************************************************************/
350
351void TrackList::AddElement(RenderElement* el)
352{
353 static const Exc_t eH("TrackList::AddElement ");
354 if (dynamic_cast<Track*>(el) == 0)
355 throw(eH + "new element not a Track.");
356 RenderElementListBase::AddElement(el);
357}
358
359/**************************************************************************/
360
361void TrackList::SetRnrMarkers(Bool_t rnr)
362{
363 fRnrMarkers = rnr;
364 gReve->Redraw3D();
365}
366
367void TrackList::SetRnrTracks(Bool_t rnr)
368{
369
370 fRnrTracks = rnr;
371 gReve->Redraw3D();
372}
373
374/**************************************************************************/
375
376void TrackList::MakeTracks()
377{
7d42b6c2 378 for(lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
5a5a1232 379 ((Track*)(*i))->MakeTrack();
380 }
381 gReve->Redraw3D();
382}
383
384
385void TrackList::MakeMarkers()
386{
7d42b6c2 387 Reset(fChildren.size());
388 for(lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
5a5a1232 389 Track& t = *((Track*)(*i));
390 if(t.GetN() > 0)
391 SetNextPoint(t.fV.x, t.fV.y, t.fV.z);
392 }
393 gReve->Redraw3D();
394}
395
396/**************************************************************************/
397/*************************************************************************/
398
2074deef 399void TrackList::SetWidth(Width_t w)
400{
401 Width_t oldw = fRnrStyle->fWidth;
402 fRnrStyle->fWidth = w;
403 for (lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
404 Track& t = *((Track*)(*i));
405 if (t.GetLineWidth() == oldw)
406 t.SetLineWidth(w);
407 }
408}
409
5a5a1232 410void TrackList::SetMaxR(Float_t x)
411{
a8600b56 412 fRnrStyle->fMaxR = x;
5a5a1232 413 MakeTracks();
414 MakeMarkers();
415}
416
417void TrackList::SetMaxZ(Float_t x)
418{
a8600b56 419 fRnrStyle->fMaxZ = x;
5a5a1232 420 MakeTracks();
421 MakeMarkers();
422}
423
424void TrackList::SetMaxOrbs(Float_t x)
425{
a8600b56 426 fRnrStyle->fMaxOrbs = x;
5a5a1232 427 MakeTracks();
428}
429
430void TrackList::SetMinAng(Float_t x)
431{
a8600b56 432 fRnrStyle->fMinAng = x;
5a5a1232 433 MakeTracks();
434}
435
436void TrackList::SetDelta(Float_t x)
437{
a8600b56 438 fRnrStyle->fDelta = x;
5a5a1232 439 MakeTracks();
440}
441
442void TrackList::SetFitDaughters(Bool_t x)
443{
a8600b56 444 fRnrStyle->fFitDaughters = x;
5a5a1232 445 MakeTracks();
446}
447
448void TrackList::SetFitDecay(Bool_t x)
449{
a8600b56 450 fRnrStyle->fFitDecay = x;
5a5a1232 451 MakeTracks();
452}
453
454/**************************************************************************/
455/**************************************************************************/
456
457void TrackList::SelectByPt(Float_t min_pt, Float_t max_pt)
458{
459 Float_t minptsq = min_pt*min_pt;
460 Float_t maxptsq = max_pt*max_pt;
461 Float_t ptsq;
462
7d42b6c2 463 for(lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
5a5a1232 464 ptsq = ((Track*)(*i))->fP.Perp2();
465 (*i)->SetRnrElement(ptsq >= minptsq && ptsq <= maxptsq);
466 }
467}
468
469/**************************************************************************/
470
b99aed53 471void TrackList::ImportHits()
5a5a1232 472{
7d42b6c2 473 for(lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
b99aed53 474 ((Track*)(*i))->ImportHits();
475 }
5a5a1232 476}
477
b99aed53 478void TrackList::ImportClusters()
5a5a1232 479{
7d42b6c2 480 for(lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
b99aed53 481 ((Track*)(*i))->ImportClusters();
482 }
5a5a1232 483}