Pythia6 dependence removed.
[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
23#include <algorithm>
7704f096 24#include <map>
c63fcc1d 25
57ffa5fb 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
57ffa5fb 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 {
51346b82 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);
51346b82 51 for(int d=d0; d>0 && d<=d1; ++d)
52 {
c63fcc1d 53 TParticle* dp = stack->Particle(d);
84aff7a4 54 TEvePathMark* pm = new TEvePathMark(TEvePathMark::kDaughter);
55 pm->fV.Set(dp->Vx(), dp->Vy(), dp->Vz());
51346b82 56 pm->fP.Set(dp->Px(), dp->Py(), dp->Pz());
84aff7a4 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
57ffa5fb 67/******************************************************************************/
c63fcc1d 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
fd31e9de 76void slurp_tracks(std::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())
51346b82 80 {
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
fd31e9de 98 std::map<Int_t, TEveTrack*> tracks;
974767e6 99 slurp_tracks(tracks, cont, recurse);
51346b82 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);
51346b82 113 for (Int_t iPrimPart = 0; iPrimPart<nPrimaries; iPrimPart++)
c63fcc1d 114 {
1d74e2b0 115 el->GetEntry(iPrimPart);
116
117 Int_t last_label = -1;
fd31e9de 118 std::map<Int_t, TEveTrack*>::iterator iter = tracks.end();
1d74e2b0 119 Int_t Nent = arr->GetEntriesFast();
51346b82 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()));
51346b82 128
1d74e2b0 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());
51346b82 137 pm->fP.Set(atr->Px(),atr->Py(), atr->Pz());
84aff7a4 138 pm->fTime = atr->GetTime();
139 TEveTrack* track = iter->second;
1d74e2b0 140 track->AddPathMark(pm);
c63fcc1d 141 }
51346b82 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
fd31e9de 153 std::map<Int_t, TEveTrack*> tracks;
27aa96b0 154 slurp_tracks(tracks, cont, recurse);
c63fcc1d 155
51346b82 156 // sort
fd31e9de 157 for(std::map<Int_t, TEveTrack*>::iterator j=tracks.begin(); j!=tracks.end(); ++j)
974767e6 158 {
27aa96b0 159 j->second->SortPathMarksByTime();
c63fcc1d 160 }
161}