fixed enumeration problems (Markus)
[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 }
804bb570 74
75 // Check last process, set decay if needed.
76 Int_t lp = stack->Particle(d1)->GetUniqueID();
77 if (lp != kPBrem && lp != kPDeltaRay && lp < kPCerenkov)
78 {
79 TParticle* dp = stack->Particle(d1);
80 track->AddPathMark(TEvePathMark(TEvePathMark::kDecay,
81 TEveVector(dp->Vx(), dp->Vy(), dp->Vz()),
82 TEveVector(0, 0,0), dp->T()));
83 }
84
27aa96b0 85 if (recurse)
86 SetDaughterPathMarks(track, stack, recurse);
c63fcc1d 87 }
88 ++iter;
89 }
90}
91
40790e5b 92/**************************************************************************/
974767e6 93
d810d0de 94void AliEveKineTools::SetTrackReferences(TEveElement* cont, TTree* treeTR, Bool_t recurse)
974767e6 95{
40790e5b 96 // Set decay and track reference path-marks.
974767e6 97
a15e6d7d 98 static const TEveException kEH("AliEveKineTools::ImportPathMarks");
974767e6 99
40790e5b 100 TrackMap_t map;
101 MapTracks(map, cont, recurse);
51346b82 102
d4369ead 103 TClonesArray* arr = 0;
104 treeTR->SetBranchAddress("TrackReferences", &arr);
c63fcc1d 105
d4369ead 106 Int_t nTreeEntries = (Int_t) treeTR->GetEntries();
107
108 for (Int_t te = 0; te < nTreeEntries; ++te)
c63fcc1d 109 {
d4369ead 110 treeTR->GetEntry(te);
111
112 Int_t last_label = -1;
113 TrackMap_t::iterator iter = map.end();
114 Int_t nArrEntries = arr->GetEntriesFast();
115
116 // printf("tree-entry %d, n-arr-entries %d\n", te, nArrEntries);
c63fcc1d 117
d4369ead 118 for (Int_t ae = 0; ae < nArrEntries; ++ae)
c63fcc1d 119 {
d4369ead 120 AliTrackReference* atr = (AliTrackReference*)arr->UncheckedAt(ae);
121 Bool_t isRef = (atr->DetectorId() != -1);
122 Int_t label = atr->GetTrack();
123
124 // printf(" arr-entry %d, label %d, detid %d, len=%f, t=%e r=%f,%f,%f\n",
125 // ae, label, atr->DetectorId(),
126 // atr->GetLength(), atr->GetTime(), atr->X(), atr->Y(), atr->Z());
127
128 if (label < 0)
129 throw(kEH + Form("negative label for array-entry %d in tree-entry %d.",
130 ae, te));
131
132 if (label != last_label)
133 {
134 iter = map.find(label);
135 last_label = label;
136 }
1d74e2b0 137
d4369ead 138 if (iter != map.end())
c63fcc1d 139 {
d4369ead 140 iter->second->AddPathMark
141 (TEvePathMark(isRef ? TEvePathMark::kReference : TEvePathMark::kDecay,
142 TEveVector(atr->X(), atr->Y(), atr->Z()),
143 TEveVector(atr->Px(), atr->Py(), atr->Pz()),
144 atr->GetTime()));
145 }
146 }
147 }
148 delete arr;
27aa96b0 149}
150
40790e5b 151/**************************************************************************/
152
153void AliEveKineTools::SortPathMarks(TEveElement* el, Bool_t recurse)
27aa96b0 154{
d4369ead 155 // Sort path-marks for track by time.
156 // If recurse is true, descends down all track children.
a15e6d7d 157
40790e5b 158 TEveTrack* track = dynamic_cast<TEveTrack*>(el);
d4369ead 159 if (track)
160 track->SortPathMarksByTime();
c63fcc1d 161
d4369ead 162 if (recurse)
a15e6d7d 163 {
d4369ead 164 for (TEveElement::List_i i = el->BeginChildren(); i != el->EndChildren(); ++i)
165 SortPathMarks(*i, kTRUE);
c63fcc1d 166 }
167}