2 // Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
4 /**************************************************************************
5 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
6 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for *
7 * full copyright notice. *
8 **************************************************************************/
10 #include "AliEveKineTools.h"
14 #include <TBranchElement.h>
15 #include <TClonesArray.h>
18 #include <AliTrackReference.h>
20 #include <TEveTrack.h>
21 #include <TEveElement.h>
25 //______________________________________________________________________________
28 // Tools for import of kinematics. Preliminary version.
31 ClassImp(AliEveKineTools)
35 typedef std::map<Int_t, TEveTrack*> TrackMap_t;
37 void MapTracks(TrackMap_t& map, TEveElement* cont, Bool_t recurse)
39 TEveElement::List_i i = cont->BeginChildren();
40 while (i != cont->EndChildren()) {
41 TEveTrack* track = dynamic_cast<TEveTrack*>(*i);
42 map[track->GetLabel()] = track;
44 MapTracks(map, track, recurse);
50 /**************************************************************************/
52 void AliEveKineTools::SetDaughterPathMarks(TEveElement* cont, AliStack* stack, Bool_t recurse)
54 // Import daughters birth points.
56 TEveElement::List_i iter = cont->BeginChildren();
57 while(iter != cont->EndChildren())
59 TEveTrack* track = dynamic_cast<TEveTrack*>(*iter);
60 TParticle* p = stack->Particle(track->GetLabel());
61 if (p->GetNDaughters())
63 Int_t d0 = p->GetDaughter(0), d1 = p->GetDaughter(1);
64 for(int d = d0; d > 0 && d <= d1; ++d)
66 TParticle* dp = stack->Particle(d);
67 track->AddPathMark(TEvePathMark(TEvePathMark::kDaughter,
68 TEveVector(dp->Vx(), dp->Vy(), dp->Vz()),
69 TEveVector(dp->Px(), dp->Py(), dp->Pz()),
73 SetDaughterPathMarks(track, stack, recurse);
79 /**************************************************************************/
81 void AliEveKineTools::SetTrackReferences(TEveElement* cont, TTree* treeTR, Bool_t recurse)
83 // Set decay and track reference path-marks.
85 static const TEveException kEH("AliEveKineTools::ImportPathMarks");
88 MapTracks(map, cont, recurse);
90 Int_t nPrimaries = (Int_t) treeTR->GetEntries();
91 TIter next(treeTR->GetListOfBranches());
95 while ((el = (TBranchElement*) next()))
97 if (strcmp("AliRun",el->GetName()) == 0)
100 TClonesArray* arr = 0;
101 el->SetAddress(&arr);
102 for (Int_t iPrimPart = 0; iPrimPart<nPrimaries; iPrimPart++)
104 el->GetEntry(iPrimPart);
106 Int_t last_label = -1;
107 TrackMap_t::iterator iter = map.end();
108 Int_t Nent = arr->GetEntriesFast();
109 for (Int_t iTrackRef = 0; iTrackRef < Nent; iTrackRef++)
111 AliTrackReference* atr = (AliTrackReference*)arr->UncheckedAt(iTrackRef);
113 Int_t label = atr->GetTrack();
115 throw(kEH + Form("negative label for entry %d in branch %s.",
116 iTrackRef, el->GetName()));
118 if (label != last_label)
120 iter = map.find(label);
124 if (iter != map.end())
126 iter->second->AddPathMark
127 (TEvePathMark(isRef ? TEvePathMark::kReference : TEvePathMark::kDecay,
128 TEveVector(atr->X(), atr->Y(), atr->Z()),
129 TEveVector(atr->Px(), atr->Py(), atr->Pz()),
133 } // loop primaries in clones arrays
135 } // end loop through top branches
138 /**************************************************************************/
140 void AliEveKineTools::SortPathMarks(TEveElement* el, Bool_t recurse)
142 // Sort path-marks for all tracks by time.
144 // !!!!! MT ... this is one level deep only!
146 TEveTrack* track = dynamic_cast<TEveTrack*>(el);
147 if (track) track->SortPathMarksByTime();
149 TEveElement::List_i i = el->BeginChildren();
150 while (i != el->EndChildren() && recurse)
152 track = dynamic_cast<TEveTrack*>(el);
153 if (track) track->SortPathMarksByTime();