]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Reve/Track.cxx
New files: allow interaction with the track, more configurability (render as line...
[u/mrichter/AliRoot.git] / EVE / Reve / Track.cxx
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
16 using namespace Reve;
17
18 //______________________________________________________________________
19 // Track
20 //
21
22 ClassImp(Reve::Track)
23
24 Track::Track() :
25   RenderElement(),
26   TPolyLine3D(),
27
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
41 Track::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
65 Track::Track(Reve::MCTrack* t, TrackRnrStyle* rs):
66   RenderElement(),
67   TPolyLine3D(),
68
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 {
81   fLineColor = fRnrStyle->GetColor();
82   fMainColorPtr = &fLineColor;
83
84   TParticlePDG* pdgp = t->GetPDG();
85   if(pdgp == 0) {
86     t->ResetPdgCode(); pdgp = t->GetPDG();
87   }
88   fCharge = (Int_t) TMath::Nint(pdgp->Charge()/3);
89 }
90
91 Track::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()
106 {
107   fLineColor = fRnrStyle->GetColor();
108   fMainColorPtr = &fLineColor;
109 }
110
111 Track::~Track()
112 {
113   for (vpPathMark_i i=fPathMarks.begin(); i!=fPathMarks.end(); ++i)
114     delete *i;
115 }
116
117 void 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
128 void 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;
142   Bool_t decay = kFALSE;
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   
147   if (fCharge != 0 && TMath::Abs(RS.fMagField) > 1e-5) {
148
149     // Charged particle in magnetic field
150
151     Float_t a = RS.fgkB2C * RS.fMagField * fCharge;
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
184     if(!decay || RS.fFitDecay == kFALSE){
185       helix.LoopToBounds(px,py,pz);
186       // printf("%s loop to bounds  \n",fName.Data() );
187     }
188
189   } else {
190
191     // Neutral particle or no field
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:
221     if(!decay || RS.fFitDecay == kFALSE)
222       line.GotoBounds(px,py,pz);
223
224   }
225 make_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
233 void Track::ImportHits()
234 {
235   Reve::LoadMacro("hits_from_label.C");
236   gROOT->ProcessLine(Form("hits_from_label(%d);", fLabel));
237 }
238
239 void 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
249 //______________________________________________________________________
250 // TrackRnrStyle
251 //
252
253 ClassImp(Reve::TrackRnrStyle)
254
255 Float_t       TrackRnrStyle::fgDefMagField = 5;
256 const Float_t TrackRnrStyle::fgkB2C        = 0.299792458e-3;
257 TrackRnrStyle TrackRnrStyle::fgDefStyle;
258
259 TrackRnrStyle::TrackRnrStyle() :
260   TObject(),
261
262   fColor(1),
263   fWidth(1),
264   fMagField(fgDefMagField),
265
266   fMaxR  (350),
267   fMaxZ  (450),
268
269   fMaxOrbs (0.5),
270   fMinAng  (45),
271   fDelta   (0.1),
272
273   fFitDaughters(kTRUE),
274   fFitDecay    (kTRUE)
275 {}
276
277 /**************************************************************************/
278 /**************************************************************************/
279
280 //______________________________________________________________________
281 // TrackList
282 //
283
284 ClassImp(Reve::TrackList)
285
286 void TrackList::Init()
287 {
288   fMarkerStyle = 6;
289   fMarkerColor = 5;
290   // fMarker->SetMarkerSize(0.05);
291
292   if (fRnrStyle== 0) fRnrStyle = new TrackRnrStyle;
293   SetMainColorPtr(&fRnrStyle->fColor);
294 }
295
296 TrackList::TrackList(Int_t n_tracks, TrackRnrStyle* rs) :
297   RenderElementListBase(),
298   TPolyMarker3D(n_tracks),
299
300   fTitle(),
301
302   fRnrStyle   (rs),
303   fRnrMarkers (kTRUE),
304   fRnrTracks  (kTRUE)
305 {
306   Init();
307 }
308
309 TrackList::TrackList(const Text_t* name, Int_t n_tracks, TrackRnrStyle* rs) :
310   RenderElementListBase(),
311   TPolyMarker3D(n_tracks),
312   
313   fTitle(),
314
315   fRnrStyle   (rs),
316   fRnrMarkers (kTRUE),
317   fRnrTracks  (kTRUE)
318 {
319   Init();
320   SetName(name);
321 }
322
323 void 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
334 void TrackList::Paint(Option_t* option)
335 {
336   if(fRnrElement) {
337     if(fRnrMarkers) {
338       TPolyMarker3D::Paint(option);
339     }
340     if(fRnrTracks) {
341       for(lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
342         if((*i)->GetRnrElement())
343           (*i)->GetObject()->Paint(option);
344       }
345     }
346   }
347 }
348
349 /**************************************************************************/
350
351 void 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
361 void TrackList::SetRnrMarkers(Bool_t rnr)
362 {
363   fRnrMarkers = rnr;
364   gReve->Redraw3D();
365 }
366
367 void TrackList::SetRnrTracks(Bool_t rnr)
368 {
369
370   fRnrTracks = rnr;
371   gReve->Redraw3D();
372 }
373
374 /**************************************************************************/
375
376 void TrackList::MakeTracks()
377 {
378   for(lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
379     ((Track*)(*i))->MakeTrack();
380   }
381   gReve->Redraw3D();
382 }
383
384
385 void TrackList::MakeMarkers()
386 {
387   Reset(fChildren.size());
388   for(lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
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
399 void 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
410 void TrackList::SetMaxR(Float_t x)
411 {
412   fRnrStyle->fMaxR = x;
413   MakeTracks();
414   MakeMarkers();
415 }
416
417 void TrackList::SetMaxZ(Float_t x)
418 {
419   fRnrStyle->fMaxZ = x;
420   MakeTracks();
421   MakeMarkers();
422 }
423
424 void TrackList::SetMaxOrbs(Float_t x)
425 {
426   fRnrStyle->fMaxOrbs = x;
427   MakeTracks();
428 }
429
430 void TrackList::SetMinAng(Float_t x)
431 {
432   fRnrStyle->fMinAng = x;
433   MakeTracks();
434 }
435
436 void TrackList::SetDelta(Float_t x)
437 {
438   fRnrStyle->fDelta = x;
439   MakeTracks();
440 }
441
442 void TrackList::SetFitDaughters(Bool_t x)
443 {
444   fRnrStyle->fFitDaughters = x;
445   MakeTracks();
446 }
447
448 void TrackList::SetFitDecay(Bool_t x)
449 {
450   fRnrStyle->fFitDecay = x;
451   MakeTracks();
452 }
453
454 /**************************************************************************/
455 /**************************************************************************/
456
457 void 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
463   for(lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
464     ptsq = ((Track*)(*i))->fP.Perp2();
465     (*i)->SetRnrElement(ptsq >= minptsq && ptsq <= maxptsq);
466   }
467 }
468
469 /**************************************************************************/
470
471 void TrackList::ImportHits()
472 {
473   for(lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
474     ((Track*)(*i))->ImportHits();
475   }
476 }
477
478 void TrackList::ImportClusters()
479 {
480   for(lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
481     ((Track*)(*i))->ImportClusters();
482   }
483 }