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