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