New class Reve::RGBAPalette: allow easier creation of color paletts mapped to integer...
[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),
263 fMagField(fgDefMagField),
5a5a1232 264
265ecb21 265 fMaxR (350),
266 fMaxZ (450),
5a5a1232 267
265ecb21 268 fMaxOrbs (0.5),
269 fMinAng (45),
270 fDelta (0.1),
5a5a1232 271
265ecb21 272 fFitDaughters(kTRUE),
273 fFitDecay (kTRUE)
274{}
5a5a1232 275
276/**************************************************************************/
277/**************************************************************************/
278
279//______________________________________________________________________
280// TrackList
281//
282
283ClassImp(Reve::TrackList)
284
285void TrackList::Init()
286{
287 fMarkerStyle = 6;
288 fMarkerColor = 5;
289 // fMarker->SetMarkerSize(0.05);
290
a8600b56 291 if (fRnrStyle== 0) fRnrStyle = new TrackRnrStyle;
292 SetMainColorPtr(&fRnrStyle->fColor);
5a5a1232 293}
294
a8600b56 295TrackList::TrackList(Int_t n_tracks, TrackRnrStyle* rs) :
7d42b6c2 296 RenderElementListBase(),
265ecb21 297 TPolyMarker3D(n_tracks),
298
299 fTitle(),
300
a8600b56 301 fRnrStyle (rs),
265ecb21 302 fRnrMarkers (kTRUE),
303 fRnrTracks (kTRUE)
5a5a1232 304{
305 Init();
306}
307
a8600b56 308TrackList::TrackList(const Text_t* name, Int_t n_tracks, TrackRnrStyle* rs) :
7d42b6c2 309 RenderElementListBase(),
265ecb21 310 TPolyMarker3D(n_tracks),
a8600b56 311
265ecb21 312 fTitle(),
313
a8600b56 314 fRnrStyle (rs),
265ecb21 315 fRnrMarkers (kTRUE),
316 fRnrTracks (kTRUE)
5a5a1232 317{
318 Init();
319 SetName(name);
320}
321
322void TrackList::Reset(Int_t n_tracks)
323{
324 delete [] fP; fP = 0;
325 fN = n_tracks;
326 if(fN) fP = new Float_t [3*fN];
327 memset(fP, 0, 3*fN*sizeof(Float_t));
328 fLastPoint = -1;
329}
330
331/**************************************************************************/
332
333void TrackList::Paint(Option_t* option)
334{
335 if(fRnrElement) {
336 if(fRnrMarkers) {
337 TPolyMarker3D::Paint(option);
338 }
339 if(fRnrTracks) {
7d42b6c2 340 for(lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
5a5a1232 341 if((*i)->GetRnrElement())
342 (*i)->GetObject()->Paint(option);
343 }
344 }
345 }
346}
347
348/**************************************************************************/
349
350void TrackList::AddElement(RenderElement* el)
351{
352 static const Exc_t eH("TrackList::AddElement ");
353 if (dynamic_cast<Track*>(el) == 0)
354 throw(eH + "new element not a Track.");
355 RenderElementListBase::AddElement(el);
356}
357
358/**************************************************************************/
359
360void TrackList::SetRnrMarkers(Bool_t rnr)
361{
362 fRnrMarkers = rnr;
363 gReve->Redraw3D();
364}
365
366void TrackList::SetRnrTracks(Bool_t rnr)
367{
368
369 fRnrTracks = rnr;
370 gReve->Redraw3D();
371}
372
373/**************************************************************************/
374
375void TrackList::MakeTracks()
376{
7d42b6c2 377 for(lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
5a5a1232 378 ((Track*)(*i))->MakeTrack();
379 }
380 gReve->Redraw3D();
381}
382
383
384void TrackList::MakeMarkers()
385{
7d42b6c2 386 Reset(fChildren.size());
387 for(lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
5a5a1232 388 Track& t = *((Track*)(*i));
389 if(t.GetN() > 0)
390 SetNextPoint(t.fV.x, t.fV.y, t.fV.z);
391 }
392 gReve->Redraw3D();
393}
394
395/**************************************************************************/
396/*************************************************************************/
397
398void TrackList::SetMaxR(Float_t x)
399{
a8600b56 400 fRnrStyle->fMaxR = x;
5a5a1232 401 MakeTracks();
402 MakeMarkers();
403}
404
405void TrackList::SetMaxZ(Float_t x)
406{
a8600b56 407 fRnrStyle->fMaxZ = x;
5a5a1232 408 MakeTracks();
409 MakeMarkers();
410}
411
412void TrackList::SetMaxOrbs(Float_t x)
413{
a8600b56 414 fRnrStyle->fMaxOrbs = x;
5a5a1232 415 MakeTracks();
416}
417
418void TrackList::SetMinAng(Float_t x)
419{
a8600b56 420 fRnrStyle->fMinAng = x;
5a5a1232 421 MakeTracks();
422}
423
424void TrackList::SetDelta(Float_t x)
425{
a8600b56 426 fRnrStyle->fDelta = x;
5a5a1232 427 MakeTracks();
428}
429
430void TrackList::SetFitDaughters(Bool_t x)
431{
a8600b56 432 fRnrStyle->fFitDaughters = x;
5a5a1232 433 MakeTracks();
434}
435
436void TrackList::SetFitDecay(Bool_t x)
437{
a8600b56 438 fRnrStyle->fFitDecay = x;
5a5a1232 439 MakeTracks();
440}
441
442/**************************************************************************/
443/**************************************************************************/
444
445void TrackList::SelectByPt(Float_t min_pt, Float_t max_pt)
446{
447 Float_t minptsq = min_pt*min_pt;
448 Float_t maxptsq = max_pt*max_pt;
449 Float_t ptsq;
450
7d42b6c2 451 for(lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
5a5a1232 452 ptsq = ((Track*)(*i))->fP.Perp2();
453 (*i)->SetRnrElement(ptsq >= minptsq && ptsq <= maxptsq);
454 }
455}
456
457/**************************************************************************/
458
b99aed53 459void TrackList::ImportHits()
5a5a1232 460{
7d42b6c2 461 for(lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
b99aed53 462 ((Track*)(*i))->ImportHits();
463 }
5a5a1232 464}
465
b99aed53 466void TrackList::ImportClusters()
5a5a1232 467{
7d42b6c2 468 for(lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
b99aed53 469 ((Track*)(*i))->ImportClusters();
470 }
5a5a1232 471}