Call redraw after Enable/DisableListElements.
[u/mrichter/AliRoot.git] / EVE / Reve / Track.cxx
CommitLineData
5a5a1232 1// $Header$
2
3#include "Track.h"
4#include "MCHelixLine.hi"
7cbaaebd 5#include "PointSet.h"
5a5a1232 6
7#include <TPolyLine3D.h>
8#include <TPolyMarker3D.h>
9#include <TColor.h>
10
11// Updates
12#include <Reve/RGTopFrame.h>
13#include <TCanvas.h>
14
15#include <vector>
16
17using namespace Reve;
18
19//______________________________________________________________________
20// Track
21//
22
23ClassImp(Reve::Track)
24
265ecb21 25Track::Track() :
eadaa89b 26 Line(),
5a5a1232 27
265ecb21 28 fV(),
29 fP(),
30 fBeta(0),
31 fCharge(0),
7cbaaebd 32 fLabel(-1),
33 fIndex(-1),
265ecb21 34 fPathMarks(),
35
eadaa89b 36 fRnrStyle(0)
265ecb21 37{}
38
3d75306d 39Track::Track(TParticle* t, Int_t label, TrackRnrStyle* rs):
eadaa89b 40 Line(),
3d75306d 41
42 fV(t->Vx(), t->Vy(), t->Vz()),
43 fP(t->Px(), t->Py(), t->Pz()),
44 fBeta(t->P()/t->Energy()),
45 fCharge(0),
46 fLabel(label),
7cbaaebd 47 fIndex(-1),
3d75306d 48 fPathMarks(),
49
eadaa89b 50 fRnrStyle(rs)
3d75306d 51{
52 fLineColor = fRnrStyle->GetColor();
53 fMainColorPtr = &fLineColor;
54
55 TParticlePDG* pdgp = t->GetPDG();
56 if (pdgp)
57 fCharge = (Int_t) TMath::Nint(pdgp->Charge()/3);
eadaa89b 58
59 SetName(t->GetName());
3d75306d 60}
61
265ecb21 62Track::Track(Reve::MCTrack* t, TrackRnrStyle* rs):
eadaa89b 63 Line(),
5a5a1232 64
265ecb21 65 fV(t->Vx(), t->Vy(), t->Vz()),
66 fP(t->Px(), t->Py(), t->Pz()),
67 fBeta(t->P()/t->Energy()),
68 fCharge(0),
69 fLabel(t->label),
fa446a68 70 fIndex(t->index),
265ecb21 71 fPathMarks(),
72
eadaa89b 73 fRnrStyle(rs)
265ecb21 74{
5a5a1232 75 fLineColor = fRnrStyle->GetColor();
76 fMainColorPtr = &fLineColor;
77
5a5a1232 78 TParticlePDG* pdgp = t->GetPDG();
79 if(pdgp == 0) {
80 t->ResetPdgCode(); pdgp = t->GetPDG();
81 }
48dc973d 82 fCharge = (Int_t) TMath::Nint(pdgp->Charge()/3);
eadaa89b 83
84 SetName(t->GetName());
5a5a1232 85}
86
265ecb21 87Track::Track(Reve::RecTrack* t, TrackRnrStyle* rs) :
eadaa89b 88 Line(),
265ecb21 89
90 fV(t->V),
91 fP(t->P),
92 fBeta(t->beta),
93 fCharge(t->sign),
94 fLabel(t->label),
fa446a68 95 fIndex(t->index),
265ecb21 96 fPathMarks(),
97
eadaa89b 98 fRnrStyle(rs)
5a5a1232 99{
5a5a1232 100 fLineColor = fRnrStyle->GetColor();
101 fMainColorPtr = &fLineColor;
eadaa89b 102
103 SetName(t->GetName());
5a5a1232 104}
105
106Track::~Track()
265ecb21 107{
108 for (vpPathMark_i i=fPathMarks.begin(); i!=fPathMarks.end(); ++i)
109 delete *i;
110}
5a5a1232 111
eadaa89b 112/*
5a5a1232 113void Track::Reset(Int_t n_points)
114{
115 delete [] TPolyLine3D::fP; TPolyLine3D::fP = 0;
116 fN = n_points;
117 if(fN) TPolyLine3D::fP = new Float_t [3*fN];
118 memset(TPolyLine3D::fP, 0, 3*fN*sizeof(Float_t));
119 fLastPoint = -1;
120}
eadaa89b 121*/
5a5a1232 122
7cbaaebd 123 /**************************************************************************/
5a5a1232 124
125void Track::MakeTrack()
126{
127
128 TrackRnrStyle& RS((fRnrStyle != 0) ? *fRnrStyle : TrackRnrStyle::fgDefStyle);
129
130 Float_t px = fP.x, py = fP.y, pz = fP.z;
131
132 MCVertex mc_v0;
133 mc_v0.x = fV.x;
134 mc_v0.y = fV.y;
135 mc_v0.z = fV.z;
136 mc_v0.t = 0;
137
138 std::vector<MCVertex> track_points;
48dc973d 139 Bool_t decay = kFALSE;
5a5a1232 140
141 if ((TMath::Abs(fV.z) > RS.fMaxZ) || (fV.x*fV.x + fV.y*fV.y > RS.fMaxR*RS.fMaxR))
142 goto make_polyline;
143
01024c63 144 if (fCharge != 0 && TMath::Abs(RS.fMagField) > 1e-5) {
145
146 // Charged particle in magnetic field
5a5a1232 147
48dc973d 148 Float_t a = RS.fgkB2C * RS.fMagField * fCharge;
5a5a1232 149
150 MCHelix helix(fRnrStyle, &mc_v0, TMath::C()*fBeta, &track_points, a); //m->cm
151 helix.Init(TMath::Sqrt(px*px+py*py), pz);
152
7cbaaebd 153 if(!fPathMarks.empty())
154 {
155 for(std::vector<Reve::PathMark*>::iterator i=fPathMarks.begin(); i!=fPathMarks.end(); ++i)
156 {
5a5a1232 157 Reve::PathMark* pm = *i;
158
7cbaaebd 159 if (RS.fFitReferences && pm->type == Reve::PathMark::Reference)
160 {
5a5a1232 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
7cbaaebd 165 // printf("%s fit reference \n", fName.Data());
166 helix.LoopToVertex(px, py, pz, pm->V.x, pm->V.y, pm->V.z);
167 px = pm->P.x;
168 py = pm->P.y;
169 pz = pm->P.z;
5a5a1232 170 }
7cbaaebd 171 else if(RS.fFitDaughters && pm->type == Reve::PathMark::Daughter)
172 {
5a5a1232 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;
7cbaaebd 176
177 // printf("%s fit daughter \n", fName.Data());
178 helix.LoopToVertex(px, py, pz, pm->V.x, pm->V.y, pm->V.z);
179 px -= pm->P.x;
180 py -= pm->P.y;
181 pz -= pm->P.z;
182 }
183 else if(RS.fFitDecay && pm->type == Reve::PathMark::Decay)
184 {
185 if(TMath::Abs(pm->V.z) > RS.fMaxZ
186 || TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR )
187 goto helix_bounds;
188 helix.LoopToVertex(px, py, pz, pm->V.x, pm->V.y, pm->V.z);
5a5a1232 189 decay = true;
190 break;
191 }
192 }
193 }
194 helix_bounds:
7cbaaebd 195 // go to bounds
48dc973d 196 if(!decay || RS.fFitDecay == kFALSE){
5a5a1232 197 helix.LoopToBounds(px,py,pz);
198 // printf("%s loop to bounds \n",fName.Data() );
199 }
200
01024c63 201 } else {
202
203 // Neutral particle or no field
5a5a1232 204
205 MCLine line(fRnrStyle, &mc_v0, TMath::C()*fBeta, &track_points);
206
207 if(!fPathMarks.empty()){
208 for(std::vector<Reve::PathMark*>::iterator i=fPathMarks.begin(); i!=fPathMarks.end(); ++i) {
209 Reve::PathMark* pm = *i;
210
211 if(RS.fFitDaughters && pm->type == Reve::PathMark::Daughter){
212 if(TMath::Abs(pm->V.z) > RS.fMaxZ
213 || TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR )
214 goto line_bounds;
215 line.GotoVertex(pm->V.x, pm->V.y, pm->V.z);
216 fP.x -= pm->P.x;
217 fP.y -= pm->P.y;
218 fP.z -= pm->P.z;
219 }
220
221 if(RS.fFitDecay && pm->type == Reve::PathMark::Decay){
222 if(TMath::Abs(pm->V.z) > RS.fMaxZ
223 || TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR )
224 goto line_bounds;
225 line.GotoVertex(pm->V.x, pm->V.y, pm->V.z);
226 decay = true;
227 break;
228 }
229 }
230 }
231
232 line_bounds:
48dc973d 233 if(!decay || RS.fFitDecay == kFALSE)
5a5a1232 234 line.GotoBounds(px,py,pz);
235
236 }
237make_polyline:
238 Reset(track_points.size());
239 for(std::vector<MCVertex>::iterator i=track_points.begin(); i!=track_points.end(); ++i)
240 SetNextPoint(i->x, i->y, i->z);
241}
242
243/**************************************************************************/
244
48dc973d 245void Track::ImportHits()
246{
247 Reve::LoadMacro("hits_from_label.C");
248 gROOT->ProcessLine(Form("hits_from_label(%d);", fLabel));
249}
250
251void Track::ImportClusters()
252{
253 Reve::LoadMacro("clusters_from_label.C");
254 gROOT->ProcessLine(Form("clusters_from_label(%d);", fLabel));
255}
256
fa446a68 257void Track::ImportClustersFromIndex()
258{
7cbaaebd 259 static const Exc_t eH("Track::ImportClustersFromIndex ");
260
261 if (fIndex < 0)
262 throw(eH + "index not set.");
263
fa446a68 264 Reve::LoadMacro("clusters_from_index.C");
265 gROOT->ProcessLine(Form("clusters_from_index(%d);", fIndex));
266}
267
b1f08706 268void Track::PrintKineStack()
269{
270 Reve::LoadMacro("print_kine_from_label.C");
271 gROOT->ProcessLine(Form("print_kine_from_label(%d);", fLabel));
272}
273
9c39ede9 274/**************************************************************************/
275
276void Track::CtrlClicked(Reve::Track* track)
277{
278 Emit("CtrlClicked(Reve::Track*)", (Long_t)track);
279}
280
48dc973d 281
282/**************************************************************************/
283/**************************************************************************/
284
5a5a1232 285//______________________________________________________________________
286// TrackRnrStyle
287//
288
289ClassImp(Reve::TrackRnrStyle)
290
48dc973d 291Float_t TrackRnrStyle::fgDefMagField = 5;
292const Float_t TrackRnrStyle::fgkB2C = 0.299792458e-3;
5a5a1232 293TrackRnrStyle TrackRnrStyle::fgDefStyle;
294
265ecb21 295TrackRnrStyle::TrackRnrStyle() :
296 TObject(),
5a5a1232 297
265ecb21 298 fColor(1),
2074deef 299 fWidth(1),
265ecb21 300 fMagField(fgDefMagField),
5a5a1232 301
265ecb21 302 fMaxR (350),
303 fMaxZ (450),
5a5a1232 304
265ecb21 305 fMaxOrbs (0.5),
306 fMinAng (45),
307 fDelta (0.1),
5a5a1232 308
7cbaaebd 309 fFitDaughters (kTRUE),
310 fFitReferences (kTRUE),
311 fFitDecay (kTRUE),
5a5a1232 312
7cbaaebd 313 fRnrDaughters (kTRUE),
314 fRnrReferences (kTRUE),
315 fRnrDecay (kTRUE)
316{}
5a5a1232 317/**************************************************************************/
318/**************************************************************************/
319
320//______________________________________________________________________
321// TrackList
322//
323
324ClassImp(Reve::TrackList)
325
326void TrackList::Init()
327{
7cbaaebd 328 fMarkerStyle = 5;
5a5a1232 329 fMarkerColor = 5;
330 // fMarker->SetMarkerSize(0.05);
331
a8600b56 332 if (fRnrStyle== 0) fRnrStyle = new TrackRnrStyle;
333 SetMainColorPtr(&fRnrStyle->fColor);
5a5a1232 334}
335
a8600b56 336TrackList::TrackList(Int_t n_tracks, TrackRnrStyle* rs) :
7d42b6c2 337 RenderElementListBase(),
265ecb21 338 TPolyMarker3D(n_tracks),
339
340 fTitle(),
341
7cbaaebd 342 fRnrStyle (rs),
343 fRnrTracks (kTRUE),
344 fEditPathMarks (kFALSE)
5a5a1232 345{
346 Init();
347}
348
a8600b56 349TrackList::TrackList(const Text_t* name, Int_t n_tracks, TrackRnrStyle* rs) :
7d42b6c2 350 RenderElementListBase(),
265ecb21 351 TPolyMarker3D(n_tracks),
a8600b56 352
265ecb21 353 fTitle(),
354
a8600b56 355 fRnrStyle (rs),
265ecb21 356 fRnrTracks (kTRUE)
5a5a1232 357{
358 Init();
359 SetName(name);
360}
361
362void TrackList::Reset(Int_t n_tracks)
363{
364 delete [] fP; fP = 0;
365 fN = n_tracks;
366 if(fN) fP = new Float_t [3*fN];
367 memset(fP, 0, 3*fN*sizeof(Float_t));
368 fLastPoint = -1;
369}
370
371/**************************************************************************/
372
373void TrackList::Paint(Option_t* option)
374{
375 if(fRnrElement) {
376 if(fRnrMarkers) {
377 TPolyMarker3D::Paint(option);
378 }
379 if(fRnrTracks) {
9c39ede9 380 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
5a5a1232 381 if((*i)->GetRnrElement())
382 (*i)->GetObject()->Paint(option);
383 }
384 }
385 }
386}
387
388/**************************************************************************/
389
390void TrackList::AddElement(RenderElement* el)
391{
392 static const Exc_t eH("TrackList::AddElement ");
393 if (dynamic_cast<Track*>(el) == 0)
394 throw(eH + "new element not a Track.");
395 RenderElementListBase::AddElement(el);
396}
397
398/**************************************************************************/
399
5a5a1232 400void TrackList::MakeTracks()
401{
9c39ede9 402 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
5a5a1232 403 ((Track*)(*i))->MakeTrack();
404 }
405 gReve->Redraw3D();
406}
407
408
409void TrackList::MakeMarkers()
410{
7d42b6c2 411 Reset(fChildren.size());
9c39ede9 412 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
5a5a1232 413 Track& t = *((Track*)(*i));
414 if(t.GetN() > 0)
415 SetNextPoint(t.fV.x, t.fV.y, t.fV.z);
416 }
417 gReve->Redraw3D();
418}
419
420/**************************************************************************/
421/*************************************************************************/
422
2074deef 423void TrackList::SetWidth(Width_t w)
424{
425 Width_t oldw = fRnrStyle->fWidth;
426 fRnrStyle->fWidth = w;
9c39ede9 427 for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
2074deef 428 Track& t = *((Track*)(*i));
429 if (t.GetLineWidth() == oldw)
430 t.SetLineWidth(w);
431 }
432}
433
5a5a1232 434void TrackList::SetMaxR(Float_t x)
435{
a8600b56 436 fRnrStyle->fMaxR = x;
5a5a1232 437 MakeTracks();
438 MakeMarkers();
439}
440
441void TrackList::SetMaxZ(Float_t x)
442{
a8600b56 443 fRnrStyle->fMaxZ = x;
5a5a1232 444 MakeTracks();
445 MakeMarkers();
446}
447
448void TrackList::SetMaxOrbs(Float_t x)
449{
a8600b56 450 fRnrStyle->fMaxOrbs = x;
5a5a1232 451 MakeTracks();
452}
453
454void TrackList::SetMinAng(Float_t x)
455{
a8600b56 456 fRnrStyle->fMinAng = x;
5a5a1232 457 MakeTracks();
458}
459
460void TrackList::SetDelta(Float_t x)
461{
a8600b56 462 fRnrStyle->fDelta = x;
5a5a1232 463 MakeTracks();
464}
465
466void TrackList::SetFitDaughters(Bool_t x)
467{
a8600b56 468 fRnrStyle->fFitDaughters = x;
5a5a1232 469 MakeTracks();
470}
471
7cbaaebd 472void TrackList::SetFitReferences(Bool_t x)
473{
474 fRnrStyle->fFitReferences = x;
475 MakeTracks();
476}
477
5a5a1232 478void TrackList::SetFitDecay(Bool_t x)
479{
a8600b56 480 fRnrStyle->fFitDecay = x;
5a5a1232 481 MakeTracks();
482}
483
7cbaaebd 484void TrackList::SetRnrDecay(Bool_t rnr)
485{
486 fRnrStyle->fRnrDecay = rnr;
487 MakeTracks();
488}
489
490void TrackList::SetRnrDaughters(Bool_t rnr)
491{
492 fRnrStyle->fRnrDaughters = rnr;
493 MakeTracks();
494}
495
496void TrackList::SetRnrReferences(Bool_t rnr)
497{
498 fRnrStyle->fRnrReferences = rnr;
499 MakeTracks();
500}
501
502void TrackList::SetRnrMarkers(Bool_t rnr)
503{
504 fRnrMarkers = rnr;
505 gReve->Redraw3D();
506}
507
508void TrackList::SetRnrTracks(Bool_t rnr)
509{
510
511 fRnrTracks = rnr;
512 gReve->Redraw3D();
513}
514
5a5a1232 515/**************************************************************************/
516/**************************************************************************/
517
518void TrackList::SelectByPt(Float_t min_pt, Float_t max_pt)
519{
520 Float_t minptsq = min_pt*min_pt;
521 Float_t maxptsq = max_pt*max_pt;
522 Float_t ptsq;
523
9c39ede9 524 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
5a5a1232 525 ptsq = ((Track*)(*i))->fP.Perp2();
526 (*i)->SetRnrElement(ptsq >= minptsq && ptsq <= maxptsq);
527 }
528}
529
530/**************************************************************************/
531
b99aed53 532void TrackList::ImportHits()
5a5a1232 533{
9c39ede9 534 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
b99aed53 535 ((Track*)(*i))->ImportHits();
536 }
5a5a1232 537}
538
b99aed53 539void TrackList::ImportClusters()
5a5a1232 540{
9c39ede9 541 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
b99aed53 542 ((Track*)(*i))->ImportClusters();
543 }
5a5a1232 544}
9c39ede9 545
546/**************************************************************************/
547/**************************************************************************/
548/**************************************************************************/
549
550#include "RGEditor.h"
551
552//______________________________________________________________________
553// TrackCounter
554//
555
556ClassImp(TrackCounter)
557
b1f08706 558TrackCounter* TrackCounter::fgInstance = 0;
559
9c39ede9 560TrackCounter::TrackCounter(const Text_t* name, const Text_t* title) :
561 RenderElement(),
562 TNamed(name, title),
563
564 fBadLineStyle (6),
565 fClickAction (CA_ToggleTrack),
566 fAllTracks (0),
567 fGoodTracks (0),
568 fTrackLists ()
569{
b1f08706 570 if (fgInstance == 0) fgInstance = this;
9c39ede9 571 TQObject::Connect("Reve::Track", "CtrlClicked(Reve::Track*)",
572 "Reve::TrackCounter", this, "DoTrackAction(Reve::Track*)");
573}
574
575TrackCounter::~TrackCounter()
576{
577 TQObject::Disconnect("Reve::Track", "DoTrackAction(Reve::Track*)");
b1f08706 578 if (fgInstance == this) fgInstance = 0;
9c39ede9 579}
580
581/**************************************************************************/
582
583void TrackCounter::Reset()
584{
585 printf("TrackCounter::Reset()\n");
586 fAllTracks = 0;
587 fGoodTracks = 0;
588 TIter next(&fTrackLists);
589 TrackList* tlist;
590 while ((tlist = dynamic_cast<TrackList*>(next())))
591 tlist->RemoveParent(this);
592 fTrackLists.Clear();
593}
594
595void TrackCounter::RegisterTracks(TrackList* tlist, Bool_t goodTracks)
596{
597 // printf("TrackCounter::RegisterTracks '%s', %s\n",
598 // tlist->GetObject()->GetName(), goodTracks ? "good" : "bad");
599
600 tlist->AddParent(this);
601 fTrackLists.Add(tlist);
602
603 List_i i = tlist->BeginChildren();
604 while (i != tlist->EndChildren())
605 {
606 Track* t = dynamic_cast<Track*>(*i);
607 if (t != 0)
608 {
609 if (goodTracks)
610 {
611 ++fGoodTracks;
612 } else {
613 t->SetLineStyle(fBadLineStyle);
614 }
615 ++fAllTracks;
616 }
617 ++i;
618 }
619}
620
621void TrackCounter::DoTrackAction(Track* track)
622{
623 // !!!! No check done if ok.
624 // !!!! Should also override RemoveElementLocal
7af62191 625 // !!!! But then ... should also sotre local information if track is ok.
9c39ede9 626
627 switch (fClickAction)
628 {
629
630 case CA_PrintTrackInfo:
631 {
632 printf("Track '%s'\n", track->GetObject()->GetName());
633 Vector &v = track->fV, &p = track->fP;
634 printf(" Vx=%f, Vy=%f, Vz=%f; Pt=%f, Pz=%f, phi=%f)\n",
635 v.x, v.y, v.z, p.Perp(), p.z, TMath::RadToDeg()*p.Phi());
636 printf(" <other information should be printed ... full AliESDtrack>\n");
637 break;
638 }
639
640 case CA_ToggleTrack:
641 {
642 if (track->GetLineStyle() == 1)
643 {
644 track->SetLineStyle(fBadLineStyle);
645 --fGoodTracks;
646 } else {
647 track->SetLineStyle(1);
648 ++fGoodTracks;
649 }
650 gReve->Redraw3D();
651
652 printf("TrackCounter::CountTrack All=%d, Good=%d, Bad=%d\n",
653 fAllTracks, fGoodTracks, fAllTracks-fGoodTracks);
654
655 if (gReve->GetEditor()->GetModel() == GetObject())
656 gReve->EditRenderElement(this);
657
658 break;
659 }
660
661 } // end switch fClickAction
662}
7af62191 663
664/**************************************************************************/
665
666void TrackCounter::OutputEventTracks(FILE* out)
667{
668 if (out == 0)
669 {
670 out = stdout;
671 fprintf(out, "TrackCounter::FinalizeEvent()\n");
672 }
673
674 fprintf(out, "Event = %d Ntracks = %d\n", fEventId, fGoodTracks);
675
676 TIter tlists(&fTrackLists);
677 TrackList* tlist;
678 Int_t cnt = 0;
679 while ((tlist = (TrackList*) tlists()) != 0)
680 {
681 List_i i = tlist->BeginChildren();
682 while (i != tlist->EndChildren())
683 {
684 Track* t = dynamic_cast<Track*>(*i);
685 if (t != 0 && t->GetLineStyle() == 1)
686 {
687 ++cnt;
688 fprintf(out, " %2d: chg=%+2d pt=%8.5f eta=%+8.5f\n",
689 cnt, t->fCharge, t->fP.Perp(), t->fP.Eta());
690 }
691 ++i;
692 }
693
694 }
695}