Updated radii for evaluation of layers material budget using LUT (non default option)
[u/mrichter/AliRoot.git] / EVE / EveBase / AliEveKineTools.cxx
CommitLineData
d810d0de 1// $Id$
2// Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
c63fcc1d 3
d810d0de 4/**************************************************************************
5 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
6 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for *
51346b82 7 * full copyright notice. *
d810d0de 8 **************************************************************************/
9
10#include "AliEveKineTools.h"
c63fcc1d 11
12#include <TObject.h>
13#include <TTree.h>
14#include <TBranchElement.h>
7704f096 15#include <TClonesArray.h>
16
c63fcc1d 17#include <AliStack.h>
18#include <AliTrackReference.h>
19
84aff7a4 20#include <TEveTrack.h>
21#include <TEveElement.h>
c63fcc1d 22
7704f096 23#include <map>
c63fcc1d 24
57ffa5fb 25//______________________________________________________________________________
d810d0de 26// AliEveKineTools
c63fcc1d 27//
d4369ead 28// Tools for import of kinematics.
40790e5b 29//
d810d0de 30
d810d0de 31ClassImp(AliEveKineTools)
c63fcc1d 32
40790e5b 33namespace {
34
35 typedef std::map<Int_t, TEveTrack*> TrackMap_t;
36
37 void MapTracks(TrackMap_t& map, TEveElement* cont, Bool_t recurse)
38 {
39 TEveElement::List_i i = cont->BeginChildren();
40 while (i != cont->EndChildren()) {
41 TEveTrack* track = dynamic_cast<TEveTrack*>(*i);
42 map[track->GetLabel()] = track;
43 if (recurse)
44 MapTracks(map, track, recurse);
45 ++i;
46 }
47 }
48}
49
50/**************************************************************************/
76461dad 51
d810d0de 52void AliEveKineTools::SetDaughterPathMarks(TEveElement* cont, AliStack* stack, Bool_t recurse)
c63fcc1d 53{
76461dad 54 // Import daughters birth points.
55
84aff7a4 56 TEveElement::List_i iter = cont->BeginChildren();
c63fcc1d 57 while(iter != cont->EndChildren())
58 {
51346b82 59 TEveTrack* track = dynamic_cast<TEveTrack*>(*iter);
c63fcc1d 60 TParticle* p = stack->Particle(track->GetLabel());
a15e6d7d 61 if (p->GetNDaughters())
62 {
c63fcc1d 63 Int_t d0 = p->GetDaughter(0), d1 = p->GetDaughter(1);
a15e6d7d 64 for(int d = d0; d > 0 && d <= d1; ++d)
51346b82 65 {
c63fcc1d 66 TParticle* dp = stack->Particle(d);
a15e6d7d 67 track->AddPathMark(TEvePathMark(TEvePathMark::kDaughter,
68 TEveVector(dp->Vx(), dp->Vy(), dp->Vz()),
69 TEveVector(dp->Px(), dp->Py(), dp->Pz()),
70 dp->T()));
d4369ead 71 // printf("Daughter path-mark for %d, %d, t=%e, r=%f,%f,%f\n",
72 // track->GetLabel(), d, dp->T(), dp->Vx(), dp->Vy(), dp->Vz());
c63fcc1d 73 }
27aa96b0 74 if (recurse)
75 SetDaughterPathMarks(track, stack, recurse);
c63fcc1d 76 }
77 ++iter;
78 }
79}
80
40790e5b 81/**************************************************************************/
974767e6 82
d810d0de 83void AliEveKineTools::SetTrackReferences(TEveElement* cont, TTree* treeTR, Bool_t recurse)
974767e6 84{
40790e5b 85 // Set decay and track reference path-marks.
974767e6 86
a15e6d7d 87 static const TEveException kEH("AliEveKineTools::ImportPathMarks");
974767e6 88
40790e5b 89 TrackMap_t map;
90 MapTracks(map, cont, recurse);
51346b82 91
d4369ead 92 TClonesArray* arr = 0;
93 treeTR->SetBranchAddress("TrackReferences", &arr);
c63fcc1d 94
d4369ead 95 Int_t nTreeEntries = (Int_t) treeTR->GetEntries();
96
97 for (Int_t te = 0; te < nTreeEntries; ++te)
c63fcc1d 98 {
d4369ead 99 treeTR->GetEntry(te);
100
101 Int_t last_label = -1;
102 TrackMap_t::iterator iter = map.end();
103 Int_t nArrEntries = arr->GetEntriesFast();
104
105 // printf("tree-entry %d, n-arr-entries %d\n", te, nArrEntries);
c63fcc1d 106
d4369ead 107 for (Int_t ae = 0; ae < nArrEntries; ++ae)
c63fcc1d 108 {
d4369ead 109 AliTrackReference* atr = (AliTrackReference*)arr->UncheckedAt(ae);
110 Bool_t isRef = (atr->DetectorId() != -1);
111 Int_t label = atr->GetTrack();
112
113 // printf(" arr-entry %d, label %d, detid %d, len=%f, t=%e r=%f,%f,%f\n",
114 // ae, label, atr->DetectorId(),
115 // atr->GetLength(), atr->GetTime(), atr->X(), atr->Y(), atr->Z());
116
117 if (label < 0)
118 throw(kEH + Form("negative label for array-entry %d in tree-entry %d.",
119 ae, te));
120
121 if (label != last_label)
122 {
123 iter = map.find(label);
124 last_label = label;
125 }
1d74e2b0 126
d4369ead 127 if (iter != map.end())
c63fcc1d 128 {
d4369ead 129 iter->second->AddPathMark
130 (TEvePathMark(isRef ? TEvePathMark::kReference : TEvePathMark::kDecay,
131 TEveVector(atr->X(), atr->Y(), atr->Z()),
132 TEveVector(atr->Px(), atr->Py(), atr->Pz()),
133 atr->GetTime()));
134 }
135 }
136 }
137 delete arr;
27aa96b0 138}
139
40790e5b 140/**************************************************************************/
141
142void AliEveKineTools::SortPathMarks(TEveElement* el, Bool_t recurse)
27aa96b0 143{
d4369ead 144 // Sort path-marks for track by time.
145 // If recurse is true, descends down all track children.
a15e6d7d 146
40790e5b 147 TEveTrack* track = dynamic_cast<TEveTrack*>(el);
d4369ead 148 if (track)
149 track->SortPathMarksByTime();
c63fcc1d 150
d4369ead 151 if (recurse)
a15e6d7d 152 {
d4369ead 153 for (TEveElement::List_i i = el->BeginChildren(); i != el->EndChildren(); ++i)
154 SortPathMarks(*i, kTRUE);
c63fcc1d 155 }
156}