]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/Alieve/AliEveKineTools.cxx
Put all classes in Alieve/ sub-module out of the Alieve namespace and
[u/mrichter/AliRoot.git] / EVE / Alieve / 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 *
7 * full copyright notice. *
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
23#include <algorithm>
7704f096 24#include <map>
c63fcc1d 25
26//______________________________________________________________________
d810d0de 27// AliEveKineTools
c63fcc1d 28//
d810d0de 29
c63fcc1d 30using namespace std;
31
d810d0de 32ClassImp(AliEveKineTools)
c63fcc1d 33
d810d0de 34AliEveKineTools::AliEveKineTools()
76461dad 35{}
c63fcc1d 36
37/**************************************************************************/
76461dad 38
d810d0de 39void AliEveKineTools::SetDaughterPathMarks(TEveElement* cont, AliStack* stack, Bool_t recurse)
c63fcc1d 40{
76461dad 41 // Import daughters birth points.
42
84aff7a4 43 TEveElement::List_i iter = cont->BeginChildren();
c63fcc1d 44
45 while(iter != cont->EndChildren())
46 {
84aff7a4 47 TEveTrack* track = dynamic_cast<TEveTrack*>(*iter);
c63fcc1d 48 TParticle* p = stack->Particle(track->GetLabel());
49 if(p->GetNDaughters()) {
50 Int_t d0 = p->GetDaughter(0), d1 = p->GetDaughter(1);
27aa96b0 51 for(int d=d0; d>0 && d<=d1; ++d)
c63fcc1d 52 {
53 TParticle* dp = stack->Particle(d);
84aff7a4 54 TEvePathMark* pm = new TEvePathMark(TEvePathMark::kDaughter);
55 pm->fV.Set(dp->Vx(), dp->Vy(), dp->Vz());
56 pm->fP.Set(dp->Px(), dp->Py(), dp->Pz());
57 pm->fTime = dp->T();
c63fcc1d 58 track->AddPathMark(pm);
59 }
27aa96b0 60 if (recurse)
61 SetDaughterPathMarks(track, stack, recurse);
c63fcc1d 62 }
63 ++iter;
64 }
65}
66
67/**************************************************************************/
68
69namespace {
974767e6 70struct cmp_pathmark
71{
84aff7a4 72 bool operator()(TEvePathMark* const & a, TEvePathMark* const & b)
73 { return a->fTime < b->fTime; }
c63fcc1d 74};
c63fcc1d 75
84aff7a4 76void slurp_tracks(map<Int_t, TEveTrack*>& tracks, TEveElement* cont, Bool_t recurse)
c63fcc1d 77{
84aff7a4 78 TEveElement::List_i citer = cont->BeginChildren();
1d74e2b0 79 while(citer != cont->EndChildren())
80 {
84aff7a4 81 TEveTrack* track = dynamic_cast<TEveTrack*>(*citer);
1d74e2b0 82 tracks[track->GetLabel()] = track;
974767e6 83 if (recurse)
84 slurp_tracks(tracks, track, recurse);
1d74e2b0 85 ++citer;
c63fcc1d 86 }
974767e6 87}
88
89}
90
d810d0de 91void AliEveKineTools::SetTrackReferences(TEveElement* cont, TTree* treeTR, Bool_t recurse)
974767e6 92{
93 // set decay and reference points
94
d810d0de 95 static const TEveException eH("AliEveKineTools::ImportPathMarks");
974767e6 96
97 // Fill map
84aff7a4 98 map<Int_t, TEveTrack*> tracks;
974767e6 99 slurp_tracks(tracks, cont, recurse);
1d74e2b0 100
c63fcc1d 101 Int_t nPrimaries = (Int_t) treeTR->GetEntries();
102 TIter next(treeTR->GetListOfBranches());
103 TBranchElement* el;
104 Bool_t isRef = kTRUE;
c63fcc1d 105
106 while ((el = (TBranchElement*) next()))
107 {
108 if (strcmp("AliRun",el->GetName()) == 0)
109 isRef = kFALSE;
110
1d74e2b0 111 TClonesArray* arr = 0;
112 el->SetAddress(&arr);
c63fcc1d 113 for (Int_t iPrimPart = 0; iPrimPart<nPrimaries; iPrimPart++)
114 {
1d74e2b0 115 el->GetEntry(iPrimPart);
116
117 Int_t last_label = -1;
84aff7a4 118 map<Int_t, TEveTrack*>::iterator iter = tracks.end();
1d74e2b0 119 Int_t Nent = arr->GetEntriesFast();
120 for (Int_t iTrackRef = 0; iTrackRef < Nent; iTrackRef++)
c63fcc1d 121 {
1d74e2b0 122 AliTrackReference* atr = (AliTrackReference*)arr->UncheckedAt(iTrackRef);
123
124 Int_t label = atr->GetTrack();
125 if (label < 0)
126 throw(eH + Form("negative label for entry %d in branch %s.",
127 iTrackRef, el->GetName()));
128
129 if(label != last_label) {
130 iter = tracks.find(label);
131 last_label = label;
132 }
133
134 if (iter != tracks.end()) {
84aff7a4 135 TEvePathMark* pm = new TEvePathMark(isRef ? TEvePathMark::kReference : TEvePathMark::kDecay);
136 pm->fV.Set(atr->X(),atr->Y(), atr->Z());
137 pm->fP.Set(atr->Px(),atr->Py(), atr->Pz());
138 pm->fTime = atr->GetTime();
139 TEveTrack* track = iter->second;
1d74e2b0 140 track->AddPathMark(pm);
c63fcc1d 141 }
142 } // loop track refs
c63fcc1d 143 } // loop primaries, clones arrays
1d74e2b0 144 delete arr;
c63fcc1d 145 } // end loop through top branches
27aa96b0 146}
147
d810d0de 148void AliEveKineTools::SortPathMarks(TEveElement* cont, Bool_t recurse)
27aa96b0 149{
150 // Sort path-marks for all tracks by time.
151
152 // Fill map
84aff7a4 153 map<Int_t, TEveTrack*> tracks;
27aa96b0 154 slurp_tracks(tracks, cont, recurse);
c63fcc1d 155
1d74e2b0 156 // sort
84aff7a4 157 for(map<Int_t, TEveTrack*>::iterator j=tracks.begin(); j!=tracks.end(); ++j)
974767e6 158 {
27aa96b0 159 j->second->SortPathMarksByTime();
c63fcc1d 160 }
161}