Modify services of top most layer (inside TOF acceptance)
[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
41Track::Track(Reve::MCTrack* t, TrackRnrStyle* rs):
42 RenderElement(),
43 TPolyLine3D(),
5a5a1232 44
265ecb21 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{
5a5a1232 57 fLineColor = fRnrStyle->GetColor();
58 fMainColorPtr = &fLineColor;
59
5a5a1232 60 TParticlePDG* pdgp = t->GetPDG();
61 if(pdgp == 0) {
62 t->ResetPdgCode(); pdgp = t->GetPDG();
63 }
48dc973d 64 fCharge = (Int_t) TMath::Nint(pdgp->Charge()/3);
5a5a1232 65}
66
265ecb21 67Track::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()
5a5a1232 82{
5a5a1232 83 fLineColor = fRnrStyle->GetColor();
84 fMainColorPtr = &fLineColor;
5a5a1232 85}
86
87Track::~Track()
265ecb21 88{
89 for (vpPathMark_i i=fPathMarks.begin(); i!=fPathMarks.end(); ++i)
90 delete *i;
91}
5a5a1232 92
93void 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
104void 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;
48dc973d 118 Bool_t decay = kFALSE;
5a5a1232 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
01024c63 123 if (fCharge != 0 && TMath::Abs(RS.fMagField) > 1e-5) {
124
125 // Charged particle in magnetic field
5a5a1232 126
48dc973d 127 Float_t a = RS.fgkB2C * RS.fMagField * fCharge;
5a5a1232 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
48dc973d 160 if(!decay || RS.fFitDecay == kFALSE){
5a5a1232 161 helix.LoopToBounds(px,py,pz);
162 // printf("%s loop to bounds \n",fName.Data() );
163 }
164
01024c63 165 } else {
166
167 // Neutral particle or no field
5a5a1232 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:
48dc973d 197 if(!decay || RS.fFitDecay == kFALSE)
5a5a1232 198 line.GotoBounds(px,py,pz);
199
200 }
201make_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
48dc973d 209void Track::ImportHits()
210{
211 Reve::LoadMacro("hits_from_label.C");
212 gROOT->ProcessLine(Form("hits_from_label(%d);", fLabel));
213}
214
215void 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
5a5a1232 225//______________________________________________________________________
226// TrackRnrStyle
227//
228
229ClassImp(Reve::TrackRnrStyle)
230
48dc973d 231Float_t TrackRnrStyle::fgDefMagField = 5;
232const Float_t TrackRnrStyle::fgkB2C = 0.299792458e-3;
5a5a1232 233TrackRnrStyle TrackRnrStyle::fgDefStyle;
234
265ecb21 235TrackRnrStyle::TrackRnrStyle() :
236 TObject(),
5a5a1232 237
265ecb21 238 fColor(1),
239 fMagField(fgDefMagField),
5a5a1232 240
265ecb21 241 fMaxR (350),
242 fMaxZ (450),
5a5a1232 243
265ecb21 244 fMaxOrbs (0.5),
245 fMinAng (45),
246 fDelta (0.1),
5a5a1232 247
265ecb21 248 fFitDaughters(kTRUE),
249 fFitDecay (kTRUE)
250{}
5a5a1232 251
252/**************************************************************************/
253/**************************************************************************/
254
255//______________________________________________________________________
256// TrackList
257//
258
259ClassImp(Reve::TrackList)
260
261void TrackList::Init()
262{
263 fMarkerStyle = 6;
264 fMarkerColor = 5;
265 // fMarker->SetMarkerSize(0.05);
266
a8600b56 267 if (fRnrStyle== 0) fRnrStyle = new TrackRnrStyle;
268 SetMainColorPtr(&fRnrStyle->fColor);
5a5a1232 269}
270
a8600b56 271TrackList::TrackList(Int_t n_tracks, TrackRnrStyle* rs) :
7d42b6c2 272 RenderElementListBase(),
265ecb21 273 TPolyMarker3D(n_tracks),
274
275 fTitle(),
276
a8600b56 277 fRnrStyle (rs),
265ecb21 278 fRnrMarkers (kTRUE),
279 fRnrTracks (kTRUE)
5a5a1232 280{
281 Init();
282}
283
a8600b56 284TrackList::TrackList(const Text_t* name, Int_t n_tracks, TrackRnrStyle* rs) :
7d42b6c2 285 RenderElementListBase(),
265ecb21 286 TPolyMarker3D(n_tracks),
a8600b56 287
265ecb21 288 fTitle(),
289
a8600b56 290 fRnrStyle (rs),
265ecb21 291 fRnrMarkers (kTRUE),
292 fRnrTracks (kTRUE)
5a5a1232 293{
294 Init();
295 SetName(name);
296}
297
298void 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
309void TrackList::Paint(Option_t* option)
310{
311 if(fRnrElement) {
312 if(fRnrMarkers) {
313 TPolyMarker3D::Paint(option);
314 }
315 if(fRnrTracks) {
7d42b6c2 316 for(lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
5a5a1232 317 if((*i)->GetRnrElement())
318 (*i)->GetObject()->Paint(option);
319 }
320 }
321 }
322}
323
324/**************************************************************************/
325
326void 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
336void TrackList::SetRnrMarkers(Bool_t rnr)
337{
338 fRnrMarkers = rnr;
339 gReve->Redraw3D();
340}
341
342void TrackList::SetRnrTracks(Bool_t rnr)
343{
344
345 fRnrTracks = rnr;
346 gReve->Redraw3D();
347}
348
349/**************************************************************************/
350
351void TrackList::MakeTracks()
352{
7d42b6c2 353 for(lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
5a5a1232 354 ((Track*)(*i))->MakeTrack();
355 }
356 gReve->Redraw3D();
357}
358
359
360void TrackList::MakeMarkers()
361{
7d42b6c2 362 Reset(fChildren.size());
363 for(lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
5a5a1232 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
374void TrackList::SetMaxR(Float_t x)
375{
a8600b56 376 fRnrStyle->fMaxR = x;
5a5a1232 377 MakeTracks();
378 MakeMarkers();
379}
380
381void TrackList::SetMaxZ(Float_t x)
382{
a8600b56 383 fRnrStyle->fMaxZ = x;
5a5a1232 384 MakeTracks();
385 MakeMarkers();
386}
387
388void TrackList::SetMaxOrbs(Float_t x)
389{
a8600b56 390 fRnrStyle->fMaxOrbs = x;
5a5a1232 391 MakeTracks();
392}
393
394void TrackList::SetMinAng(Float_t x)
395{
a8600b56 396 fRnrStyle->fMinAng = x;
5a5a1232 397 MakeTracks();
398}
399
400void TrackList::SetDelta(Float_t x)
401{
a8600b56 402 fRnrStyle->fDelta = x;
5a5a1232 403 MakeTracks();
404}
405
406void TrackList::SetFitDaughters(Bool_t x)
407{
a8600b56 408 fRnrStyle->fFitDaughters = x;
5a5a1232 409 MakeTracks();
410}
411
412void TrackList::SetFitDecay(Bool_t x)
413{
a8600b56 414 fRnrStyle->fFitDecay = x;
5a5a1232 415 MakeTracks();
416}
417
418/**************************************************************************/
419/**************************************************************************/
420
421void 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
7d42b6c2 427 for(lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
5a5a1232 428 ptsq = ((Track*)(*i))->fP.Perp2();
429 (*i)->SetRnrElement(ptsq >= minptsq && ptsq <= maxptsq);
430 }
431}
432
433/**************************************************************************/
434
b99aed53 435void TrackList::ImportHits()
5a5a1232 436{
7d42b6c2 437 for(lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
b99aed53 438 ((Track*)(*i))->ImportHits();
439 }
5a5a1232 440}
441
b99aed53 442void TrackList::ImportClusters()
5a5a1232 443{
7d42b6c2 444 for(lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
b99aed53 445 ((Track*)(*i))->ImportClusters();
446 }
5a5a1232 447}