]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/Reve/Track.cxx
Add some class docs.
[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>
32e219c2 8#include <TMarker.h>
5a5a1232 9#include <TPolyMarker3D.h>
10#include <TColor.h>
11
12// Updates
32e219c2 13#include <Reve/ReveManager.h>
17038a14 14#include <Reve/RGBrowser.h>
32e219c2 15#include <Reve/NLTTrack.h>
5a5a1232 16#include <TCanvas.h>
17
18#include <vector>
5ba491d8 19#include <algorithm>
20#include <functional>
21#include <iostream>
5a5a1232 22
23using namespace Reve;
24
2b801b28 25//______________________________________________________________________________
5a5a1232 26// Track
27//
17038a14 28// Visual representation of a track.
29//
5a5a1232 30
31ClassImp(Reve::Track)
32
2b801b28 33//______________________________________________________________________________
265ecb21 34Track::Track() :
eadaa89b 35 Line(),
5a5a1232 36
265ecb21 37 fV(),
38 fP(),
39 fBeta(0),
b343c0ea 40 fPdg(0),
265ecb21 41 fCharge(0),
17038a14 42 fLabel(kMinInt),
43 fIndex(kMinInt),
265ecb21 44 fPathMarks(),
45
eadaa89b 46 fRnrStyle(0)
e9ef1a49 47{
48 // Default constructor.
49}
265ecb21 50
2b801b28 51//______________________________________________________________________________
3d75306d 52Track::Track(TParticle* t, Int_t label, TrackRnrStyle* rs):
eadaa89b 53 Line(),
3d75306d 54
55 fV(t->Vx(), t->Vy(), t->Vz()),
56 fP(t->Px(), t->Py(), t->Pz()),
57 fBeta(t->P()/t->Energy()),
b343c0ea 58 fPdg(0),
3d75306d 59 fCharge(0),
60 fLabel(label),
17038a14 61 fIndex(kMinInt),
3d75306d 62 fPathMarks(),
63
32e219c2 64 fRnrStyle(0)
3d75306d 65{
e9ef1a49 66 // Constructor from TParticle.
67
32e219c2 68 SetRnrStyle(rs);
3d75306d 69 fMainColorPtr = &fLineColor;
70
71 TParticlePDG* pdgp = t->GetPDG();
b343c0ea 72 if (pdgp) {
73 fPdg = pdgp->PdgCode();
3d75306d 74 fCharge = (Int_t) TMath::Nint(pdgp->Charge()/3);
b343c0ea 75 }
eadaa89b 76
77 SetName(t->GetName());
3d75306d 78}
79
2b801b28 80//______________________________________________________________________________
265ecb21 81Track::Track(Reve::MCTrack* t, TrackRnrStyle* rs):
eadaa89b 82 Line(),
5a5a1232 83
265ecb21 84 fV(t->Vx(), t->Vy(), t->Vz()),
85 fP(t->Px(), t->Py(), t->Pz()),
86 fBeta(t->P()/t->Energy()),
b343c0ea 87 fPdg(0),
265ecb21 88 fCharge(0),
89 fLabel(t->label),
fa446a68 90 fIndex(t->index),
265ecb21 91 fPathMarks(),
92
32e219c2 93 fRnrStyle(0)
265ecb21 94{
e9ef1a49 95 // Constructor from Reve Monte Carlo track.
96
32e219c2 97 SetRnrStyle(rs);
5a5a1232 98 fMainColorPtr = &fLineColor;
99
5a5a1232 100 TParticlePDG* pdgp = t->GetPDG();
101 if(pdgp == 0) {
102 t->ResetPdgCode(); pdgp = t->GetPDG();
103 }
48dc973d 104 fCharge = (Int_t) TMath::Nint(pdgp->Charge()/3);
eadaa89b 105
106 SetName(t->GetName());
5a5a1232 107}
108
2b801b28 109//______________________________________________________________________________
265ecb21 110Track::Track(Reve::RecTrack* t, TrackRnrStyle* rs) :
eadaa89b 111 Line(),
265ecb21 112
113 fV(t->V),
114 fP(t->P),
115 fBeta(t->beta),
b343c0ea 116 fPdg(0),
265ecb21 117 fCharge(t->sign),
118 fLabel(t->label),
fa446a68 119 fIndex(t->index),
265ecb21 120 fPathMarks(),
121
32e219c2 122 fRnrStyle(0)
5a5a1232 123{
e9ef1a49 124 // Constructor from Reve reconstructed track.
125
32e219c2 126 SetRnrStyle(rs);
5a5a1232 127 fMainColorPtr = &fLineColor;
eadaa89b 128
129 SetName(t->GetName());
5a5a1232 130}
131
2b801b28 132//______________________________________________________________________________
32e219c2 133Track::Track(const Track& t) :
134 Line(),
135 TQObject(),
136 fV(t.fV),
137 fP(t.fP),
138 fBeta(t.fBeta),
b343c0ea 139 fPdg(t.fPdg),
32e219c2 140 fCharge(t.fCharge),
141 fLabel(t.fLabel),
142 fIndex(t.fIndex),
143 fPathMarks(),
144 fRnrStyle(0)
145{
2b801b28 146 // Copy constructor.
147
32e219c2 148 SetMainColor(t.GetMainColor());
149 // Line
2b801b28 150 fRnrLine = t.fRnrLine;
32e219c2 151 fRnrPoints = t.fRnrPoints;
152 // TLineAttrib
153 fLineColor = t.fLineColor;
154 fLineStyle = t.fLineStyle;
155 fLineWidth = t.fLineWidth;
2b801b28 156 SetPathMarks(t);
157 SetRnrStyle (t.fRnrStyle);
32e219c2 158}
159
b343c0ea 160//______________________________________________________________________________
161Track::~Track()
162{
e9ef1a49 163 // Destructor.
164
b343c0ea 165 SetRnrStyle(0);
166 for (vpPathMark_i i=fPathMarks.begin(); i!=fPathMarks.end(); ++i)
167 delete *i;
168}
169
170/******************************************************************************/
171
172//______________________________________________________________________________
173void Track::SetStdTitle()
174{
175 // Set standard track title based on most data-member values.
176
177 TString idx(fIndex == kMinInt ? "<undef>" : Form("%d", fIndex));
178 TString lbl(fLabel == kMinInt ? "<undef>" : Form("%d", fLabel));
179 SetTitle(Form("Index=%s, Label=%s\nChg=%d, Pdg=%d\n"
180 "pT=%.3f, pZ=%.3f\nV=(%.3f, %.3f, %.3f)",
181 idx.Data(), lbl.Data(), fCharge, fPdg,
182 fP.Perp(), fP.z, fV.x, fV.y, fV.z));
183}
184
2b801b28 185//______________________________________________________________________________
32e219c2 186void Track::SetTrackParams(const Track& t)
187{
2b801b28 188 // Copy track parameters from t.
189 // PathMarks are cleared.
190
191 fV = t.fV;
192 fP = t.fP;
193 fBeta = t.fBeta;
b343c0ea 194 fPdg = t.fPdg;
2b801b28 195 fCharge = t.fCharge;
196 fLabel = t.fLabel;
197 fIndex = t.fIndex;
32e219c2 198
199 SetMainColor(t.GetMainColor());
200 // Line
201 fRnrLine = t.fRnrLine;
202 fRnrPoints = t.fRnrPoints;
203 // TLineAttrib
204 fLineColor = t.fLineColor;
205 fLineStyle = t.fLineStyle;
206 fLineWidth = t.fLineWidth;
2b801b28 207 fPathMarks.clear();
32e219c2 208 SetRnrStyle(t.fRnrStyle);
209}
210
2b801b28 211//______________________________________________________________________________
212void Track::SetPathMarks(const Track& t)
5a5a1232 213{
2b801b28 214 // Copy path-marks from t.
215
216 const std::vector<PathMark*>& refs = t.GetPathMarksRef();
217 for(std::vector<PathMark*>::const_iterator i=refs.begin(); i!=refs.end(); ++i)
218 {
219 fPathMarks.push_back(new PathMark(**i));
220 }
5a5a1232 221}
222
2b801b28 223/******************************************************************************/
224
225//______________________________________________________________________________
32e219c2 226void Track::SetRnrStyle(TrackRnrStyle* rs)
227{
e9ef1a49 228 // Set track's render style.
229 // Reference counts of old and new render-style are updated.
230
231 if (fRnrStyle == rs) return;
32e219c2 232 if (fRnrStyle) fRnrStyle->DecRefCount(this);
233 fRnrStyle = rs;
234 if (fRnrStyle) rs->IncRefCount(this);
235}
236
2b801b28 237/******************************************************************************/
238
239//______________________________________________________________________________
32e219c2 240void Track::SetAttLineAttMarker(TrackList* tl)
241{
e9ef1a49 242 // Set line and marker attributes from TrackList.
243
32e219c2 244 SetLineColor(tl->GetLineColor());
245 SetLineStyle(tl->GetLineStyle());
246 SetLineWidth(tl->GetLineWidth());
247
248 SetMarkerColor(tl->GetMarkerColor());
249 SetMarkerStyle(tl->GetMarkerStyle());
250 SetMarkerSize(tl->GetMarkerSize());
251}
252
2b801b28 253/******************************************************************************/
5a5a1232 254
2b801b28 255//______________________________________________________________________________
a8a51cc7 256void Track::MakeTrack(Bool_t recurse)
5a5a1232 257{
e9ef1a49 258 // Calculate track representation based on track data and current
259 // settings of the render-style.
260 // If recurse is true, descend into children.
261
5a5a1232 262 TrackRnrStyle& RS((fRnrStyle != 0) ? *fRnrStyle : TrackRnrStyle::fgDefStyle);
263
264 Float_t px = fP.x, py = fP.y, pz = fP.z;
265
266 MCVertex mc_v0;
267 mc_v0.x = fV.x;
268 mc_v0.y = fV.y;
269 mc_v0.z = fV.z;
270 mc_v0.t = 0;
271
272 std::vector<MCVertex> track_points;
48dc973d 273 Bool_t decay = kFALSE;
5a5a1232 274
275 if ((TMath::Abs(fV.z) > RS.fMaxZ) || (fV.x*fV.x + fV.y*fV.y > RS.fMaxR*RS.fMaxR))
276 goto make_polyline;
277
b343c0ea 278 if (fCharge != 0 && TMath::Abs(RS.fMagField) > 1e-5 && fP.Perp2() > 1e-12)
32e219c2 279 {
280 // Charged particle in magnetic field with non-zero pT.
5a5a1232 281
48dc973d 282 Float_t a = RS.fgkB2C * RS.fMagField * fCharge;
5a5a1232 283
284 MCHelix helix(fRnrStyle, &mc_v0, TMath::C()*fBeta, &track_points, a); //m->cm
285 helix.Init(TMath::Sqrt(px*px+py*py), pz);
b855ed81 286 // Set max number of points for loop-to-vertex.
287 // loop-to-bounds (last step) does this separately.
288 helix.NMax = 4096;
5a5a1232 289
b855ed81 290 if (!fPathMarks.empty())
7cbaaebd 291 {
292 for(std::vector<Reve::PathMark*>::iterator i=fPathMarks.begin(); i!=fPathMarks.end(); ++i)
293 {
5a5a1232 294 Reve::PathMark* pm = *i;
295
7cbaaebd 296 if (RS.fFitReferences && pm->type == Reve::PathMark::Reference)
297 {
b855ed81 298 if(TMath::Abs(pm->V.z) > RS.fMaxZ ||
32e219c2 299 TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR)
5a5a1232 300 goto helix_bounds;
301
7cbaaebd 302 // printf("%s fit reference \n", fName.Data());
303 helix.LoopToVertex(px, py, pz, pm->V.x, pm->V.y, pm->V.z);
32e219c2 304 px = pm->P.x;
305 py = pm->P.y;
306 pz = pm->P.z;
5a5a1232 307 }
7cbaaebd 308 else if(RS.fFitDaughters && pm->type == Reve::PathMark::Daughter)
309 {
32e219c2 310 if(TMath::Abs(pm->V.z) > RS.fMaxZ ||
311 TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR)
5a5a1232 312 goto helix_bounds;
7cbaaebd 313
314 // printf("%s fit daughter \n", fName.Data());
315 helix.LoopToVertex(px, py, pz, pm->V.x, pm->V.y, pm->V.z);
32e219c2 316 px -= pm->P.x;
317 py -= pm->P.y;
318 pz -= pm->P.z;
7cbaaebd 319 }
320 else if(RS.fFitDecay && pm->type == Reve::PathMark::Decay)
321 {
32e219c2 322 if(TMath::Abs(pm->V.z) > RS.fMaxZ ||
323 TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR)
7cbaaebd 324 goto helix_bounds;
325 helix.LoopToVertex(px, py, pz, pm->V.x, pm->V.y, pm->V.z);
5a5a1232 326 decay = true;
327 break;
328 }
b855ed81 329 if (track_points.size() > 4096)
330 {
331 Warning("Track::MakeTrack", "exceeding 4k points (%u) for '%s'; aborting extrapolation.",
332 track_points.size(), GetName());
333 goto make_polyline;
334 }
5a5a1232 335 }
336 }
337 helix_bounds:
7cbaaebd 338 // go to bounds
32e219c2 339 if(!decay || RS.fFitDecay == kFALSE)
340 {
5a5a1232 341 helix.LoopToBounds(px,py,pz);
342 // printf("%s loop to bounds \n",fName.Data() );
343 }
344
01024c63 345 } else {
346
347 // Neutral particle or no field
5a5a1232 348
349 MCLine line(fRnrStyle, &mc_v0, TMath::C()*fBeta, &track_points);
350
32e219c2 351 if(!fPathMarks.empty())
352 {
353 for(std::vector<Reve::PathMark*>::iterator i=fPathMarks.begin(); i!=fPathMarks.end(); ++i)
354 {
5a5a1232 355 Reve::PathMark* pm = *i;
356
32e219c2 357 if(RS.fFitDaughters && pm->type == Reve::PathMark::Daughter)
358 {
359 if(TMath::Abs(pm->V.z) > RS.fMaxZ ||
360 TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR)
361 {
5a5a1232 362 goto line_bounds;
32e219c2 363 }
5a5a1232 364 line.GotoVertex(pm->V.x, pm->V.y, pm->V.z);
32e219c2 365 fP.x -= pm->P.x;
366 fP.y -= pm->P.y;
367 fP.z -= pm->P.z;
5a5a1232 368 }
369
32e219c2 370 if(RS.fFitDecay && pm->type == Reve::PathMark::Decay)
371 {
372 if(TMath::Abs(pm->V.z) > RS.fMaxZ ||
373 TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR)
374 {
5a5a1232 375 goto line_bounds;
32e219c2 376 }
5a5a1232 377 line.GotoVertex(pm->V.x, pm->V.y, pm->V.z);
378 decay = true;
379 break;
380 }
381 }
382 }
383
384 line_bounds:
48dc973d 385 if(!decay || RS.fFitDecay == kFALSE)
5a5a1232 386 line.GotoBounds(px,py,pz);
387
388 }
389make_polyline:
b855ed81 390 {
391 Int_t size = TMath::Min(4096, (Int_t) track_points.size());
392 // printf("track '%s' N = %u\n", GetName(), track_points.size());
393 Reset(size);
394 for(Int_t i=0; i<size; ++i)
395 {
2b801b28 396 const MCVertex& v = track_points[i];
b855ed81 397 SetNextPoint(v.x, v.y, v.z);
398 }
399 }
2fbbf445 400
32e219c2 401 if(recurse)
402 {
a8a51cc7 403 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i)
404 {
405 Track* t = dynamic_cast<Track*>(*i);
406 if(t) t->MakeTrack(recurse);
2fbbf445 407 }
408 }
32e219c2 409}
410
2b801b28 411/******************************************************************************/
412
413//______________________________________________________________________________
32e219c2 414TClass* Track::ProjectedClass() const
415{
e9ef1a49 416 // Virtual from NLTProjectable, return NLTTrack class.
417
32e219c2 418 return NLTTrack::Class();
5a5a1232 419}
420
2b801b28 421/******************************************************************************/
a8a51cc7 422
ba008f46 423namespace {
a8a51cc7 424
425struct cmp_pathmark
426{
ba008f46 427 bool operator()(PathMark* const & a, PathMark* const & b)
428 { return a->time < b->time; }
429};
a8a51cc7 430
ba008f46 431}
432
2b801b28 433//______________________________________________________________________________
ba008f46 434void Track::SortPathMarksByTime()
435{
e9ef1a49 436 // Sort registerd pat-marks by time.
437
b855ed81 438 std::sort(fPathMarks.begin(), fPathMarks.end(), cmp_pathmark());
ba008f46 439}
440
2b801b28 441/******************************************************************************/
5a5a1232 442
2b801b28 443//______________________________________________________________________________
48dc973d 444void Track::ImportHits()
445{
e9ef1a49 446 // Import hits with same label as the track.
447 // Uses macro "hits_from_label.C".
448
48dc973d 449 Reve::LoadMacro("hits_from_label.C");
2fbbf445 450 gROOT->ProcessLine(Form("hits_from_label(%d, (Reve::RenderElement*)%p);",
451 fLabel, this));
48dc973d 452}
453
2b801b28 454//______________________________________________________________________________
48dc973d 455void Track::ImportClusters()
456{
e9ef1a49 457 // Import clusters with same label as the track.
458 // Uses macro "clusters_from_label.C".
459
48dc973d 460 Reve::LoadMacro("clusters_from_label.C");
2fbbf445 461 gROOT->ProcessLine(Form("clusters_from_label(%d, (Reve::RenderElement*)%p);",
462 fLabel, this));
48dc973d 463}
464
2b801b28 465//______________________________________________________________________________
fa446a68 466void Track::ImportClustersFromIndex()
467{
e9ef1a49 468 // Import clusters marked with same reconstructed track index as the track.
469 // Uses macro "clusters_from_index.C".
470
7cbaaebd 471 static const Exc_t eH("Track::ImportClustersFromIndex ");
472
17038a14 473 if (fIndex == kMinInt)
7cbaaebd 474 throw(eH + "index not set.");
475
fa446a68 476 Reve::LoadMacro("clusters_from_index.C");
2fbbf445 477 gROOT->ProcessLine(Form("clusters_from_index(%d, (Reve::RenderElement*)%p);",
478 fIndex, this));
fa446a68 479}
480
2b801b28 481/******************************************************************************/
b8879e69 482
2b801b28 483//______________________________________________________________________________
b8879e69 484void Track::ImportKine()
485{
e9ef1a49 486 // Import kinematics of the track's label recursively.
487 // Uses macro "kine_tracks.C".
488
b8879e69 489 static const Exc_t eH("Track::ImportKine ");
490
17038a14 491 if (fLabel == kMinInt)
b8879e69 492 throw(eH + "label not set.");
493
17038a14 494 Int_t label;
495 if (fLabel < 0) {
496 Warning(eH, "label negative, taking absolute value.");
497 label = -fLabel;
498 } else {
499 label = fLabel;
500 }
501
b8879e69 502 Reve::LoadMacro("kine_tracks.C");
b343c0ea 503 gROOT->ProcessLine(Form("kine_track(%d, kTRUE, kTRUE, kTRUE, kTRUE, (Reve::RenderElement*)%p);",
17038a14 504 label, this));
2fbbf445 505
b8879e69 506}
507
2b801b28 508//______________________________________________________________________________
b343c0ea 509void Track::ImportKineWithArgs(Bool_t importMother, Bool_t importDaugters,
510 Bool_t colorPdg, Bool_t recurse)
a525aa60 511{
e9ef1a49 512 // Import kinematics of the track's label. Arguments steer the
513 // import process:
514 // importMother import particle with track's label
515 // importDaugters import direct daughters of label
516 // colorPdg color kinematics by PDG code
517 // recurse recursive import of daughters' daughters
518 // Uses macro "kine_tracks.C".
519
b8879e69 520 static const Exc_t eH("Track::ImportKineWithArgs ");
a525aa60 521
17038a14 522 if (fLabel == kMinInt)
a525aa60 523 throw(eH + "label not set.");
524
17038a14 525 Int_t label;
526 if (fLabel < 0) {
527 Warning(eH, "label negative, taking absolute value.");
528 label = -fLabel;
529 } else {
530 label = fLabel;
531 }
532
b8879e69 533 Reve::LoadMacro("kine_tracks.C");
b343c0ea 534 gROOT->ProcessLine(Form("kine_track(%d, %d, %d, %d, %d, (Reve::RenderElement*)%p);",
535 label, importMother, importDaugters, colorPdg, recurse, this));
a525aa60 536}
537
2b801b28 538/******************************************************************************/
a525aa60 539
2b801b28 540//______________________________________________________________________________
b1f08706 541void Track::PrintKineStack()
542{
e9ef1a49 543 // Print kinematics pertaining to track's label.
544 // Uses macro "print_kine_from_label.C".
545
b343c0ea 546 static const Exc_t eH("Track::PrintKineStack ");
547
548 if (fLabel == kMinInt)
549 throw(eH + "label not set.");
550
551 Int_t label;
552 if (fLabel < 0) {
553 Warning(eH, "label negative, taking absolute value.");
554 label = -fLabel;
555 } else {
556 label = fLabel;
557 }
558
b1f08706 559 Reve::LoadMacro("print_kine_from_label.C");
b343c0ea 560 gROOT->ProcessLine(Form("print_kine_from_label(%d);", label));
b1f08706 561}
562
2b801b28 563//______________________________________________________________________________
a525aa60 564void Track::PrintPathMarks()
565{
e9ef1a49 566 // Print registered path-marks.
567
a525aa60 568 static const Exc_t eH("Track::PrintPathMarks ");
569
b855ed81 570 printf("Track '%s', number of path marks %d, label %d\n",
571 GetName(), fPathMarks.size(), fLabel);
a525aa60 572
573 PathMark* pm;
574 for(vpPathMark_i i=fPathMarks.begin(); i!=fPathMarks.end(); i++)
575 {
576 pm = *i;
b855ed81 577 printf(" %-9s p: %8f %8f %8f Vertex: %8e %8e %8e %g \n",
a525aa60 578 pm->type_name(),
579 pm->P.x, pm->P.y, pm->P.z,
580 pm->V.x, pm->V.y, pm->V.z,
581 pm->time);
582 }
583}
584
2b801b28 585/******************************************************************************/
9c39ede9 586
2b801b28 587//______________________________________________________________________________
9c39ede9 588void Track::CtrlClicked(Reve::Track* track)
589{
e9ef1a49 590 // Emits "CtrlClicked(Reve::Track*)" signal.
591 // Called from TrackGL on secondary-selection.
592
9c39ede9 593 Emit("CtrlClicked(Reve::Track*)", (Long_t)track);
594}
595
2b801b28 596//______________________________________________________________________________
32e219c2 597void Track::SetLineStyle(Style_t lstyle)
598{
e9ef1a49 599 // Set line-style of the track.
600 // The style is propagated to projected tracks.
601
32e219c2 602 TAttLine::SetLineStyle(lstyle);
603 std::list<NLTProjected*>::iterator pi = fProjectedList.begin();
604 while (pi != fProjectedList.end())
605 {
606 Track* pt = dynamic_cast<Track*>(*pi);
607 if (pt)
608 {
609 pt->SetLineStyle(lstyle);
610 pt->ElementChanged();
611 }
612 ++pi;
613 }
614}
48dc973d 615
48dc973d 616
2b801b28 617/******************************************************************************/
618/******************************************************************************/
619
2b801b28 620//______________________________________________________________________________
5a5a1232 621// TrackRnrStyle
622//
17038a14 623// Holding structure for a number of track rendering parameters.
624//
625// This is decoupled from Track/TrackList to allow sharing of the
626// RnrStyle among several instances. Back references are kept so the
627// tracks can be recreated when the parameters change.
628//
629// TrackList has Get/Set methods for RnrStlye. TrackEditor and
630// TrackListEditor provide editor access.
5a5a1232 631
632ClassImp(Reve::TrackRnrStyle)
633
48dc973d 634Float_t TrackRnrStyle::fgDefMagField = 5;
635const Float_t TrackRnrStyle::fgkB2C = 0.299792458e-3;
5a5a1232 636TrackRnrStyle TrackRnrStyle::fgDefStyle;
637
17038a14 638//______________________________________________________________________________
265ecb21 639TrackRnrStyle::TrackRnrStyle() :
640 TObject(),
32e219c2 641 ReferenceBackPtr(),
5a5a1232 642
265ecb21 643 fMagField(fgDefMagField),
5a5a1232 644
265ecb21 645 fMaxR (350),
646 fMaxZ (450),
5a5a1232 647
265ecb21 648 fMaxOrbs (0.5),
649 fMinAng (45),
650 fDelta (0.1),
5a5a1232 651
32e219c2 652 fEditPathMarks(kFALSE),
653 fPMAtt(),
4f5ee1c6 654
7cbaaebd 655 fFitDaughters (kTRUE),
656 fFitReferences (kTRUE),
657 fFitDecay (kTRUE),
5a5a1232 658
7cbaaebd 659 fRnrDaughters (kTRUE),
660 fRnrReferences (kTRUE),
32e219c2 661 fRnrDecay (kTRUE),
662
663 fRnrFV(kFALSE),
664 fFVAtt()
665{
17038a14 666 // Default constructor.
667
32e219c2 668 fPMAtt.SetMarkerColor(4);
669 fPMAtt.SetMarkerStyle(2);
670
671 fFVAtt.SetMarkerSize(0.6);
672 fFVAtt.SetMarkerColor(4);
673 fFVAtt.SetMarkerStyle(2);
674}
675
5a5a1232 676/**************************************************************************/
677
17038a14 678//______________________________________________________________________________
32e219c2 679void TrackRnrStyle::RebuildTracks()
680{
17038a14 681 // Rebuild all tracks using this render-style.
682
32e219c2 683 Track* track;
684 std::list<RenderElement*>::iterator i = fBackRefs.begin();
685 while (i != fBackRefs.end())
686 {
687 track = dynamic_cast<Track*>(*i);
688 track->MakeTrack();
b343c0ea 689 track->ElementChanged();
32e219c2 690 ++i;
691 }
692}
5a5a1232 693
17038a14 694/******************************************************************************/
5a5a1232 695
17038a14 696//______________________________________________________________________________
32e219c2 697void TrackRnrStyle::SetMaxR(Float_t x)
5a5a1232 698{
17038a14 699 // Set maximum radius and rebuild tracks.
700
32e219c2 701 fMaxR = x;
702 RebuildTracks();
703}
5a5a1232 704
17038a14 705//______________________________________________________________________________
32e219c2 706void TrackRnrStyle::SetMaxZ(Float_t x)
707{
17038a14 708 // Set maximum z and rebuild tracks.
709
32e219c2 710 fMaxZ = x;
711 RebuildTracks();
5a5a1232 712}
713
17038a14 714//______________________________________________________________________________
32e219c2 715void TrackRnrStyle::SetMaxOrbs(Float_t x)
716{
17038a14 717 // Set maximum number of orbits and rebuild tracks.
718
32e219c2 719 fMaxOrbs = x;
720 RebuildTracks();
721}
265ecb21 722
17038a14 723//______________________________________________________________________________
32e219c2 724void TrackRnrStyle::SetMinAng(Float_t x)
725{
17038a14 726 // Set minimum step angle and rebuild tracks.
727
32e219c2 728 fMinAng = x;
729 RebuildTracks();
730}
265ecb21 731
17038a14 732//______________________________________________________________________________
32e219c2 733void TrackRnrStyle::SetDelta(Float_t x)
5a5a1232 734{
17038a14 735 // Set maximum error and rebuild tracks.
736
32e219c2 737 fDelta = x;
738 RebuildTracks();
5a5a1232 739}
740
17038a14 741//______________________________________________________________________________
32e219c2 742void TrackRnrStyle::SetFitDaughters(Bool_t x)
743{
17038a14 744 // Set daughter creation point fitting and rebuild tracks.
745
32e219c2 746 fFitDaughters = x;
747 RebuildTracks();
748}
265ecb21 749
17038a14 750//______________________________________________________________________________
32e219c2 751void TrackRnrStyle::SetFitReferences(Bool_t x)
5a5a1232 752{
17038a14 753 // Set track-reference fitting and rebuild tracks.
754
32e219c2 755 fFitReferences = x;
756 RebuildTracks();
5a5a1232 757}
758
17038a14 759//______________________________________________________________________________
32e219c2 760void TrackRnrStyle::SetFitDecay(Bool_t x)
5a5a1232 761{
17038a14 762 // Set decay fitting and rebuild tracks.
763
32e219c2 764 fFitDecay = x;
765 RebuildTracks();
5a5a1232 766}
767
17038a14 768//______________________________________________________________________________
32e219c2 769void TrackRnrStyle::SetRnrDecay(Bool_t rnr)
770{
17038a14 771 // Set decay rendering and rebuild tracks.
772
32e219c2 773 fRnrDecay = rnr;
774 RebuildTracks();
775}
776
17038a14 777//______________________________________________________________________________
32e219c2 778void TrackRnrStyle::SetRnrDaughters(Bool_t rnr)
779{
17038a14 780 // Set daughter rendering and rebuild tracks.
781
32e219c2 782 fRnrDaughters = rnr;
783 RebuildTracks();
784}
785
17038a14 786//______________________________________________________________________________
32e219c2 787void TrackRnrStyle::SetRnrReferences(Bool_t rnr)
788{
17038a14 789 // Set track-reference rendering and rebuild tracks.
790
32e219c2 791 fRnrReferences = rnr;
792 RebuildTracks();
793}
794
795
5a5a1232 796/**************************************************************************/
32e219c2 797/**************************************************************************/
17038a14 798
799//______________________________________________________________________________
32e219c2 800// TrackList
801//
802
803ClassImp(Reve::TrackList)
5a5a1232 804
17038a14 805//______________________________________________________________________________
32e219c2 806TrackList::TrackList(TrackRnrStyle* rs) :
807 RenderElementList(),
808 TAttMarker(1, 20, 1),
809 TAttLine(1,1,1),
810
811 fRecurse(kTRUE),
812 fRnrStyle(0),
813 fRnrLine(kTRUE),
814 fRnrPoints(kFALSE),
815
816 fMinPt (0), fMaxPt (0), fLimPt (0),
817 fMinP (0), fMaxP (0), fLimP (0)
5a5a1232 818{
17038a14 819 // Constructor. If TrackRenderStyle argument is 0, a new default
820 // render-style is created.
821
32e219c2 822 fChildClass = Track::Class(); // override member from base RenderElementList
823
824 fMainColorPtr = &fLineColor;
825 if (fRnrStyle== 0) rs = new TrackRnrStyle;
826 SetRnrStyle(rs);
827}
828
17038a14 829//______________________________________________________________________________
32e219c2 830TrackList::TrackList(const Text_t* name, TrackRnrStyle* rs) :
831 RenderElementList(name),
832 TAttMarker(1, 20, 1),
833 TAttLine(1,1,1),
834
835 fRecurse(kTRUE),
836 fRnrStyle (0),
837 fRnrLine(kTRUE),
838 fRnrPoints(kFALSE),
839
840 fMinPt (0), fMaxPt (0), fLimPt (0),
841 fMinP (0), fMaxP (0), fLimP (0)
842{
17038a14 843 // Constructor. If TrackRenderStyle argument is 0, a new default
844 // render-style is created.
845
32e219c2 846 fChildClass = Track::Class(); // override member from base RenderElementList
847
848 fMainColorPtr = &fLineColor;
849 if (fRnrStyle== 0) rs = new TrackRnrStyle;
850 SetRnrStyle(rs);
851}
852
17038a14 853//______________________________________________________________________________
32e219c2 854TrackList::~TrackList()
855{
17038a14 856 // Destructor.
857
32e219c2 858 SetRnrStyle(0);
5a5a1232 859}
860
17038a14 861/******************************************************************************/
5a5a1232 862
17038a14 863//______________________________________________________________________________
32e219c2 864void TrackList::SetRnrStyle(TrackRnrStyle* rs)
5a5a1232 865{
17038a14 866 // Set default render-style for tracks.
867 // This is not enforced onto the tracks themselves but this is the
868 // render-style that is show in the TrackListEditor.
869
32e219c2 870 if (fRnrStyle == rs) return;
871 if (fRnrStyle) fRnrStyle->DecRefCount();
872 fRnrStyle = rs;
873 if (fRnrStyle) rs->IncRefCount();
5a5a1232 874}
875
876/**************************************************************************/
877
17038a14 878//______________________________________________________________________________
a8a51cc7 879void TrackList::MakeTracks(Bool_t recurse)
5a5a1232 880{
17038a14 881 // Regenerate the visual representations of tracks.
882 // The momentum limits are rescanned during the same traversal.
883
32e219c2 884 fLimPt = fLimP = 0;
885
17038a14 886 for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i)
a8a51cc7 887 {
32e219c2 888 Track* track = (Track*)(*i);
889 track->MakeTrack(recurse);
890
891 fLimPt = TMath::Max(fLimPt, track->fP.Perp());
892 fLimP = TMath::Max(fLimP, track->fP.Mag());
893 if (recurse)
894 FindMomentumLimits(*i, recurse);
5a5a1232 895 }
32e219c2 896
897 fLimPt = RoundMomentumLimit(fLimPt);
898 fLimP = RoundMomentumLimit(fLimP);
899 if (fMaxPt == 0) fMaxPt = fLimPt;
900 if (fMaxP == 0) fMaxP = fLimP;
901
5a5a1232 902 gReve->Redraw3D();
903}
904
17038a14 905//______________________________________________________________________________
32e219c2 906void TrackList::FindMomentumLimits(RenderElement* el, Bool_t recurse)
5a5a1232 907{
17038a14 908 // Loop over track elements of argument el and find highest pT and p.
909 // These are stored in members fLimPt and fLimP.
910
911 for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
32e219c2 912 {
913 Track* track = dynamic_cast<Track*>(*i);
914 if (track)
915 {
916 fLimPt = TMath::Max(fLimPt, track->fP.Perp());
917 fLimP = TMath::Max(fLimP, track->fP.Mag());
918 if (recurse)
919 FindMomentumLimits(*i, recurse);
920 }
5a5a1232 921 }
32e219c2 922}
923
17038a14 924//______________________________________________________________________________
32e219c2 925Float_t TrackList::RoundMomentumLimit(Float_t x)
926{
17038a14 927 // Round the momentum limit up to a nice value.
928
32e219c2 929 using namespace TMath;
930 Double_t fac = Power(10, 1 - Floor(Log10(x)));
931 return Ceil(fac*x) / fac;
5a5a1232 932}
933
934/**************************************************************************/
5a5a1232 935
17038a14 936//______________________________________________________________________________
32e219c2 937void TrackList::SetRnrLine(Bool_t rnr)
2074deef 938{
17038a14 939 // Set rendering of track as line for the list and the elements.
940
941 for (List_i i=BeginChildren(); i!=EndChildren(); ++i)
32e219c2 942 {
943 Track* track = (Track*)(*i);
17038a14 944 if (track->GetRnrLine() == fRnrLine)
945 track->SetRnrLine(rnr);
946 if (fRecurse)
947 SetRnrLine(rnr, *i);
2074deef 948 }
32e219c2 949 fRnrLine = rnr;
2074deef 950}
951
17038a14 952//______________________________________________________________________________
32e219c2 953void TrackList::SetRnrLine(Bool_t rnr, RenderElement* el)
ec019a35 954{
17038a14 955 // Set rendering of track as line for children of el.
956
32e219c2 957 Track* track;
17038a14 958 for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
32e219c2 959 {
960 track = dynamic_cast<Track*>(*i);
961 if (track && (track->GetRnrLine() == fRnrLine))
962 track->SetRnrLine(rnr);
963 if (fRecurse)
964 SetRnrLine(rnr, *i);
ec019a35 965 }
966}
967
17038a14 968/******************************************************************************/
32e219c2 969
17038a14 970//______________________________________________________________________________
32e219c2 971void TrackList::SetRnrPoints(Bool_t rnr)
972{
17038a14 973 // Set rendering of track as points for the list and the elements.
974
975 for (List_i i=BeginChildren(); i!=EndChildren(); ++i)
32e219c2 976 {
977 Track* track = (Track*)(*i);
17038a14 978 if (track->GetRnrPoints() == fRnrPoints)
979 track->SetRnrPoints(rnr);
980 if (fRecurse)
981 SetRnrPoints(rnr, *i);
32e219c2 982 }
983 fRnrPoints = rnr;
984}
985
17038a14 986//______________________________________________________________________________
32e219c2 987void TrackList::SetRnrPoints(Bool_t rnr, RenderElement* el)
5a5a1232 988{
17038a14 989 // Set rendering of track as points for children of el.
990
32e219c2 991 Track* track;
17038a14 992 for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
32e219c2 993 {
994 track = dynamic_cast<Track*>(*i);
995 if (track)
17038a14 996 if (track->GetRnrPoints() == fRnrPoints)
997 track->SetRnrPoints(rnr);
998 if (fRecurse)
999 SetRnrPoints(rnr, *i);
32e219c2 1000 }
5a5a1232 1001}
1002
17038a14 1003/******************************************************************************/
1004
1005//______________________________________________________________________________
32e219c2 1006void TrackList::SetMainColor(Color_t col)
5a5a1232 1007{
17038a14 1008 // Set main (line) color for the list and the elements.
1009
1010 for (List_i i=BeginChildren(); i!=EndChildren(); ++i)
32e219c2 1011 {
1012 Track* track = (Track*)(*i);
17038a14 1013 if (track->GetLineColor() == fLineColor)
1014 track->SetLineColor(col);
1015 if (fRecurse)
1016 SetLineColor(col, *i);
32e219c2 1017 }
1018 RenderElement::SetMainColor(col);
5a5a1232 1019}
1020
17038a14 1021//______________________________________________________________________________
32e219c2 1022void TrackList::SetLineColor(Color_t col, RenderElement* el)
5a5a1232 1023{
17038a14 1024 // Set line color for children of el.
1025
32e219c2 1026 Track* track;
17038a14 1027 for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
32e219c2 1028 {
1029 track = dynamic_cast<Track*>(*i);
1030 if (track && track->GetLineColor() == fLineColor)
1031 track->SetLineColor(col);
1032 if (fRecurse)
1033 SetLineColor(col, *i);
1034 }
5a5a1232 1035}
1036
17038a14 1037/******************************************************************************/
32e219c2 1038
17038a14 1039//______________________________________________________________________________
32e219c2 1040void TrackList::SetLineWidth(Width_t width)
5a5a1232 1041{
17038a14 1042 // Set line width for the list and the elements.
1043
1044 for (List_i i=BeginChildren(); i!=EndChildren(); ++i)
32e219c2 1045 {
1046 Track* track = (Track*)(*i);
17038a14 1047 if (track->GetLineWidth() == fLineWidth)
1048 track->SetLineWidth(width);
1049 if (fRecurse)
1050 SetLineWidth(width, *i);
32e219c2 1051 }
1052 fLineWidth=width;
5a5a1232 1053}
1054
17038a14 1055//______________________________________________________________________________
32e219c2 1056void TrackList::SetLineWidth(Width_t width, RenderElement* el)
5a5a1232 1057{
17038a14 1058 // Set line width for children of el.
1059
32e219c2 1060 Track* track;
17038a14 1061 for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
32e219c2 1062 {
1063 track = dynamic_cast<Track*>(*i);
1064 if (track && track->GetLineWidth() == fLineWidth)
1065 track->SetLineWidth(width);
1066 if (fRecurse)
1067 SetLineWidth(width, *i);
1068 }
5a5a1232 1069}
1070
17038a14 1071/******************************************************************************/
32e219c2 1072
17038a14 1073//______________________________________________________________________________
32e219c2 1074void TrackList::SetLineStyle(Style_t style)
5a5a1232 1075{
17038a14 1076 // Set line style for the list and the elements.
1077
1078 for (List_i i=BeginChildren(); i!=EndChildren(); ++i)
32e219c2 1079 {
1080 Track* track = (Track*)(*i);
17038a14 1081 if (track->GetLineStyle() == fLineStyle)
1082 track->SetLineStyle(style);
1083 if (fRecurse)
1084 SetLineStyle(style, *i);
32e219c2 1085 }
1086 fLineStyle=style;
5a5a1232 1087}
1088
17038a14 1089//______________________________________________________________________________
32e219c2 1090void TrackList::SetLineStyle(Style_t style, RenderElement* el)
7cbaaebd 1091{
17038a14 1092 // Set line style for children of el.
1093
32e219c2 1094 Track* track;
17038a14 1095 for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
32e219c2 1096 {
1097 track = dynamic_cast<Track*>(*i);
1098 if (track && track->GetLineStyle() == fLineStyle)
1099 track->SetLineStyle(style);
1100 if (fRecurse)
1101 SetLineStyle(style, *i);
1102 }
7cbaaebd 1103}
1104
17038a14 1105/******************************************************************************/
32e219c2 1106
17038a14 1107//______________________________________________________________________________
32e219c2 1108void TrackList::SetMarkerStyle(Style_t style)
5a5a1232 1109{
17038a14 1110 // Set marker style for the list and the elements.
1111
1112 for (List_i i=BeginChildren(); i!=EndChildren(); ++i)
32e219c2 1113 {
1114 Track* track = (Track*)(*i);
17038a14 1115 if (track->GetMarkerStyle() == fMarkerStyle)
1116 track->SetMarkerStyle(style);
1117 if (fRecurse)
1118 SetMarkerStyle(style, *i);
32e219c2 1119 }
1120 fMarkerStyle=style;
5a5a1232 1121}
1122
17038a14 1123//______________________________________________________________________________
32e219c2 1124void TrackList::SetMarkerStyle(Style_t style, RenderElement* el)
7cbaaebd 1125{
17038a14 1126 // Set marker style for children of el.
1127
32e219c2 1128 Track* track;
17038a14 1129 for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
32e219c2 1130 {
1131 track = dynamic_cast<Track*>(*i);
1132 if (track && track->GetMarkerStyle() == fMarkerStyle)
1133 track->SetMarkerStyle(style);
1134 if(fRecurse)
1135 SetMarkerStyle(style, *i);
1136 }
7cbaaebd 1137}
1138
17038a14 1139/******************************************************************************/
32e219c2 1140
17038a14 1141//______________________________________________________________________________
32e219c2 1142void TrackList::SetMarkerColor(Color_t col)
7cbaaebd 1143{
17038a14 1144 // Set marker color for the list and the elements.
1145
1146 for (List_i i=BeginChildren(); i!=EndChildren(); ++i)
32e219c2 1147 {
1148 Track* track = (Track*)(*i);
17038a14 1149 if (track->GetMarkerColor() == fMarkerColor)
1150 track->SetMarkerColor(col);
1151 if (fRecurse)
1152 SetMarkerColor(col, *i);
32e219c2 1153 }
1154 fMarkerColor=col;
7cbaaebd 1155}
1156
17038a14 1157//______________________________________________________________________________
32e219c2 1158void TrackList::SetMarkerColor(Color_t col, RenderElement* el)
7cbaaebd 1159{
17038a14 1160 // Set marker color for children of el.
1161
32e219c2 1162 Track* track;
17038a14 1163 for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
32e219c2 1164 {
1165 track = dynamic_cast<Track*>(*i);
1166 if (track && track->GetMarkerColor() == fMarkerColor)
1167 track->SetMarkerColor(col);
1168 if (fRecurse)
1169 SetMarkerColor(col, *i);
1170 }
7cbaaebd 1171}
32e219c2 1172
17038a14 1173/******************************************************************************/
32e219c2 1174
17038a14 1175//______________________________________________________________________________
32e219c2 1176void TrackList::SetMarkerSize(Size_t size)
7cbaaebd 1177{
17038a14 1178 // Set marker size for the list and the elements.
1179
1180 for (List_i i=BeginChildren(); i!=EndChildren(); ++i)
32e219c2 1181 {
1182 Track* track = (Track*)(*i);
17038a14 1183 if (track->GetMarkerSize() == fMarkerSize)
1184 track->SetMarkerSize(size);
1185 if (fRecurse)
1186 SetMarkerSize(size, *i);
32e219c2 1187 }
1188 fMarkerSize=size;
7cbaaebd 1189}
1190
17038a14 1191//______________________________________________________________________________
32e219c2 1192void TrackList::SetMarkerSize(Size_t size, RenderElement* el)
7cbaaebd 1193{
17038a14 1194 // Set marker size for children of el.
1195
32e219c2 1196 Track* track;
17038a14 1197 for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
32e219c2 1198 {
1199 track = dynamic_cast<Track*>(*i);
1200 if (track && track->GetMarkerSize() == fMarkerSize)
1201 track->SetMarkerSize(size);
1202 if (fRecurse)
1203 SetMarkerSize(size, *i);
1204 }
7cbaaebd 1205}
1206
17038a14 1207/******************************************************************************/
5a5a1232 1208
17038a14 1209//______________________________________________________________________________
5a5a1232 1210void TrackList::SelectByPt(Float_t min_pt, Float_t max_pt)
1211{
e9ef1a49 1212 // Select visibility of tracks by transverse momentum.
1213 // If data-member fRecurse is set, the selection is applied
1214 // recursively to all children.
1215
32e219c2 1216 fMinPt = min_pt;
1217 fMaxPt = max_pt;
22df2a83 1218
32e219c2 1219 const Float_t minptsq = min_pt*min_pt;
1220 const Float_t maxptsq = max_pt*max_pt;
5a5a1232 1221
17038a14 1222 for (List_i i=BeginChildren(); i!=EndChildren(); ++i)
32e219c2 1223 {
1224 const Float_t ptsq = ((Track*)(*i))->fP.Perp2();
a8a51cc7 1225 Bool_t on = ptsq >= minptsq && ptsq <= maxptsq;
32e219c2 1226 (*i)->SetRnrState(on);
1227 if (on && fRecurse)
1228 SelectByPt(min_pt, max_pt, *i);
1229 }
1230}
1231
17038a14 1232//______________________________________________________________________________
32e219c2 1233void TrackList::SelectByPt(Float_t min_pt, Float_t max_pt, RenderElement* el)
1234{
e9ef1a49 1235 // Select visibility of el's children tracks by transverse momentum.
1236
32e219c2 1237 const Float_t minptsq = min_pt*min_pt;
1238 const Float_t maxptsq = max_pt*max_pt;
1239
17038a14 1240 for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
32e219c2 1241 {
1242 Track* track = dynamic_cast<Track*>(*i);
1243 if (track)
1244 {
1245 const Float_t ptsq = track->fP.Perp2();
1246 Bool_t on = ptsq >= minptsq && ptsq <= maxptsq;
1247 track->SetRnrState(on);
1248 if (on && fRecurse)
1249 SelectByPt(min_pt, max_pt, *i);
1250 }
5a5a1232 1251 }
1252}
1253
17038a14 1254//______________________________________________________________________________
4f5ee1c6 1255void TrackList::SelectByP(Float_t min_p, Float_t max_p)
1256{
e9ef1a49 1257 // Select visibility of tracks by momentum.
1258 // If data-member fRecurse is set, the selection is applied
1259 // recursively to all children.
1260
32e219c2 1261 fMinP = min_p;
1262 fMaxP = max_p;
4f5ee1c6 1263
32e219c2 1264 const Float_t minpsq = min_p*min_p;
1265 const Float_t maxpsq = max_p*max_p;
4f5ee1c6 1266
17038a14 1267 for (List_i i=BeginChildren(); i!=EndChildren(); ++i)
32e219c2 1268 {
1269 const Float_t psq = ((Track*)(*i))->fP.Mag2();
bfcc55e4 1270 Bool_t on = psq >= minpsq && psq <= maxpsq;
32e219c2 1271 (*i)->SetRnrState(psq >= minpsq && psq <= maxpsq);
1272 if (on && fRecurse)
1273 SelectByP(min_p, max_p, *i);
1274 }
1275}
1276
17038a14 1277//______________________________________________________________________________
32e219c2 1278void TrackList::SelectByP(Float_t min_p, Float_t max_p, RenderElement* el)
1279{
e9ef1a49 1280 // Select visibility of el's children tracks by momentum.
1281
32e219c2 1282 const Float_t minpsq = min_p*min_p;
1283 const Float_t maxpsq = max_p*max_p;
1284
17038a14 1285 for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
32e219c2 1286 {
1287 Track* track = dynamic_cast<Track*>(*i);
1288 if (track)
1289 {
1290 const Float_t psq = ((Track*)(*i))->fP.Mag2();
1291 Bool_t on = psq >= minpsq && psq <= maxpsq;
1292 track->SetRnrState(on);
1293 if (on && fRecurse)
1294 SelectByP(min_p, max_p, *i);
1295 }
4f5ee1c6 1296 }
1297}
1298
17038a14 1299/******************************************************************************/
5a5a1232 1300
17038a14 1301//______________________________________________________________________________
1302Track* TrackList::FindTrackByLabel(Int_t label)
1303{
1304 // Find track by label, select it and display it in the editor.
1305
1306 for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
1307 if (((Track*)(*i))->GetLabel() == label) {
1308 TGListTree *lt = gReve->GetLTEFrame()->GetListTree();
1309 TGListTreeItem *mlti = lt->GetSelected();
1310 if (mlti->GetUserData() != this)
1311 mlti = FindListTreeItem(lt);
1312 TGListTreeItem *tlti = (*i)->FindListTreeItem(lt, mlti);
1313 lt->HighlightItem(tlti);
1314 lt->SetSelected(tlti);
1315 gReve->EditRenderElement(*i);
1316 return (Track*) *i;
1317 }
1318 }
1319 return 0;
1320}
1321
1322//______________________________________________________________________________
1323Track* TrackList::FindTrackByIndex(Int_t index)
1324{
1325 // Find track by index, select it and display it in the editor.
1326
1327 for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
1328 if (((Track*)(*i))->GetIndex() == index) {
1329 TGListTree *lt = gReve->GetLTEFrame()->GetListTree();
1330 TGListTreeItem *mlti = lt->GetSelected();
1331 if (mlti->GetUserData() != this)
1332 mlti = FindListTreeItem(lt);
1333 TGListTreeItem *tlti = (*i)->FindListTreeItem(lt, mlti);
1334 lt->HighlightItem(tlti);
1335 lt->SetSelected(tlti);
1336 gReve->EditRenderElement(*i);
1337 return (Track*) *i;
1338 }
1339 }
1340 return 0;
1341}
1342
1343//______________________________________________________________________________
b99aed53 1344void TrackList::ImportHits()
5a5a1232 1345{
e9ef1a49 1346 // Import hits for all track.
1347
17038a14 1348 for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
b99aed53 1349 ((Track*)(*i))->ImportHits();
1350 }
5a5a1232 1351}
1352
17038a14 1353//______________________________________________________________________________
b99aed53 1354void TrackList::ImportClusters()
5a5a1232 1355{
e9ef1a49 1356 // Import clusters for all track.
1357
17038a14 1358 for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
b99aed53 1359 ((Track*)(*i))->ImportClusters();
1360 }
5a5a1232 1361}
9c39ede9 1362
17038a14 1363/******************************************************************************/
32e219c2 1364
17038a14 1365//______________________________________________________________________________
32e219c2 1366TClass* TrackList::ProjectedClass() const
1367{
e9ef1a49 1368 // Virtual from NLTProjectable, returns NLTTrackList class.
1369
32e219c2 1370 return NLTTrackList::Class();
1371}
17038a14 1372
1373
1374/******************************************************************************/
1375/******************************************************************************/
9c39ede9 1376
1377#include "RGEditor.h"
1378
17038a14 1379//______________________________________________________________________________
9c39ede9 1380// TrackCounter
1381//
e9ef1a49 1382// Provides event-based method for tagging of good / bad (or primary /
1383// secondary) tracks. A report can be written into a text file.
1384//
1385// Track status is toggled by using secondary-selection / ctrl-click
1386// functionality of the GL viewer.
1387//
1388// Some of the functionality is implemented in TrackCounterEditor
1389// class.
9c39ede9 1390
1391ClassImp(TrackCounter)
1392
b1f08706 1393TrackCounter* TrackCounter::fgInstance = 0;
1394
e9ef1a49 1395//______________________________________________________________________________
9c39ede9 1396TrackCounter::TrackCounter(const Text_t* name, const Text_t* title) :
1397 RenderElement(),
1398 TNamed(name, title),
1399
1400 fBadLineStyle (6),
1401 fClickAction (CA_ToggleTrack),
1402 fAllTracks (0),
1403 fGoodTracks (0),
1404 fTrackLists ()
1405{
e9ef1a49 1406 // Constructor.
1407 // Connects to global signal "Reve::Track", "CtrlClicked(Reve::Track*)".
1408
b1f08706 1409 if (fgInstance == 0) fgInstance = this;
9c39ede9 1410 TQObject::Connect("Reve::Track", "CtrlClicked(Reve::Track*)",
1411 "Reve::TrackCounter", this, "DoTrackAction(Reve::Track*)");
1412}
1413
e9ef1a49 1414//______________________________________________________________________________
9c39ede9 1415TrackCounter::~TrackCounter()
1416{
e9ef1a49 1417 // Destructor.
1418 // Disconnect from the global track signals.
1419
9c39ede9 1420 TQObject::Disconnect("Reve::Track", "DoTrackAction(Reve::Track*)");
b1f08706 1421 if (fgInstance == this) fgInstance = 0;
9c39ede9 1422}
1423
1424/**************************************************************************/
1425
e9ef1a49 1426//______________________________________________________________________________
9c39ede9 1427void TrackCounter::Reset()
1428{
e9ef1a49 1429 // Reset internal track-counters and track-list.
1430
9c39ede9 1431 printf("TrackCounter::Reset()\n");
1432 fAllTracks = 0;
1433 fGoodTracks = 0;
1434 TIter next(&fTrackLists);
1435 TrackList* tlist;
1436 while ((tlist = dynamic_cast<TrackList*>(next())))
32e219c2 1437 tlist->DecDenyDestroy();
2b801b28 1438 fTrackLists.Clear("nodelete");
9c39ede9 1439}
1440
e9ef1a49 1441//______________________________________________________________________________
9c39ede9 1442void TrackCounter::RegisterTracks(TrackList* tlist, Bool_t goodTracks)
1443{
e9ef1a49 1444 // Register tracks from tlist and tlist itself.
1445 // If goodTracks is true, they are considered as primary/good
1446 // tracks.
9c39ede9 1447
32e219c2 1448 tlist->IncDenyDestroy();
9c39ede9 1449 fTrackLists.Add(tlist);
1450
1451 List_i i = tlist->BeginChildren();
1452 while (i != tlist->EndChildren())
1453 {
1454 Track* t = dynamic_cast<Track*>(*i);
1455 if (t != 0)
1456 {
1457 if (goodTracks)
1458 {
1459 ++fGoodTracks;
1460 } else {
1461 t->SetLineStyle(fBadLineStyle);
1462 }
1463 ++fAllTracks;
1464 }
1465 ++i;
1466 }
1467}
1468
e9ef1a49 1469//______________________________________________________________________________
9c39ede9 1470void TrackCounter::DoTrackAction(Track* track)
1471{
e9ef1a49 1472 // Slot called when track is ctrl-clicked.
1473 //
1474 // No check is done if track actually belongs to one of the
1475 // registered track-lists.
1476 //
1477 // Probably it would be safer to copy good/bad tracks into special
1478 // sub-containers.
1479 // In this case one should also override RemoveElementLocal.
9c39ede9 1480
1481 switch (fClickAction)
1482 {
1483
1484 case CA_PrintTrackInfo:
1485 {
1486 printf("Track '%s'\n", track->GetObject()->GetName());
1487 Vector &v = track->fV, &p = track->fP;
1488 printf(" Vx=%f, Vy=%f, Vz=%f; Pt=%f, Pz=%f, phi=%f)\n",
1489 v.x, v.y, v.z, p.Perp(), p.z, TMath::RadToDeg()*p.Phi());
1490 printf(" <other information should be printed ... full AliESDtrack>\n");
1491 break;
1492 }
1493
1494 case CA_ToggleTrack:
1495 {
1496 if (track->GetLineStyle() == 1)
1497 {
1498 track->SetLineStyle(fBadLineStyle);
1499 --fGoodTracks;
1500 } else {
1501 track->SetLineStyle(1);
1502 ++fGoodTracks;
1503 }
32e219c2 1504 track->ElementChanged();
9c39ede9 1505 gReve->Redraw3D();
1506
1507 printf("TrackCounter::CountTrack All=%d, Good=%d, Bad=%d\n",
1508 fAllTracks, fGoodTracks, fAllTracks-fGoodTracks);
1509
1510 if (gReve->GetEditor()->GetModel() == GetObject())
1511 gReve->EditRenderElement(this);
1512
1513 break;
1514 }
1515
1516 } // end switch fClickAction
1517}
7af62191 1518
1519/**************************************************************************/
1520
e9ef1a49 1521//______________________________________________________________________________
7af62191 1522void TrackCounter::OutputEventTracks(FILE* out)
1523{
e9ef1a49 1524 // Print good-track summary into a plain-text file by iteration
1525 // through all registered track-lists.
1526 // State of each track is determined by its line-style, it is
1527 // considered a good track if it's line style is solid.
1528
7af62191 1529 if (out == 0)
1530 {
1531 out = stdout;
1532 fprintf(out, "TrackCounter::FinalizeEvent()\n");
1533 }
1534
1535 fprintf(out, "Event = %d Ntracks = %d\n", fEventId, fGoodTracks);
1536
1537 TIter tlists(&fTrackLists);
1538 TrackList* tlist;
1539 Int_t cnt = 0;
1540 while ((tlist = (TrackList*) tlists()) != 0)
1541 {
1542 List_i i = tlist->BeginChildren();
1543 while (i != tlist->EndChildren())
1544 {
1545 Track* t = dynamic_cast<Track*>(*i);
1546 if (t != 0 && t->GetLineStyle() == 1)
1547 {
1548 ++cnt;
1549 fprintf(out, " %2d: chg=%+2d pt=%8.5f eta=%+8.5f\n",
1550 cnt, t->fCharge, t->fP.Perp(), t->fP.Eta());
1551 }
1552 ++i;
1553 }
7af62191 1554 }
1555}