Improve handling of multi-level track containers for kinematic trees.
[u/mrichter/AliRoot.git] / EVE / Alieve / KineTools.cxx
CommitLineData
c63fcc1d 1// $Header$
2
3#include "KineTools.h"
4
5#include <TObject.h>
6#include <TTree.h>
7#include <TBranchElement.h>
7704f096 8#include <TClonesArray.h>
9
c63fcc1d 10#include <AliStack.h>
11#include <AliTrackReference.h>
12
13#include "Reve/Track.h"
14#include "Reve/RenderElement.h"
15
16#include <algorithm>
7704f096 17#include <map>
c63fcc1d 18
19//______________________________________________________________________
20// KineTools
21//
22
23using namespace Reve;
24using namespace Alieve;
25using namespace std;
26
27ClassImp(KineTools)
28
29KineTools::KineTools()
76461dad 30{}
c63fcc1d 31
32/**************************************************************************/
76461dad 33
34void KineTools::SetDaughterPathMarks(TrackList* cont, AliStack* stack)
c63fcc1d 35{
76461dad 36 // Import daughters birth points.
37
c63fcc1d 38 RenderElement::List_i iter = cont->BeginChildren();
39
40 while(iter != cont->EndChildren())
41 {
42 Track* track = dynamic_cast<Track*>(*iter);
43 TParticle* p = stack->Particle(track->GetLabel());
44 if(p->GetNDaughters()) {
45 Int_t d0 = p->GetDaughter(0), d1 = p->GetDaughter(1);
46 for(int d=d0; d>0 && d<=d1;++d)
47 {
48 TParticle* dp = stack->Particle(d);
1d74e2b0 49 Reve::PathMark* pm = new PathMark(PathMark::Daughter);
c63fcc1d 50 pm->V.Set(dp->Vx(),dp->Vy(), dp->Vz());
51 pm->P.Set(dp->Px(),dp->Py(), dp->Pz());
52 pm->time = dp->T();
53 track->AddPathMark(pm);
54 }
55 }
56 ++iter;
57 }
58}
59
60/**************************************************************************/
61
62namespace {
63struct cmp_pathmark {
64 bool operator()(PathMark* const & a, PathMark* const & b)
65 { return a->time < b->time; }
66};
67}
68
1d74e2b0 69void KineTools::SetTrackReferences(TrackList* cont, TTree* treeTR)
c63fcc1d 70{
71 // set decay and reference points
72
73 static const Exc_t eH("KineTools::ImportPathMarks");
74
1d74e2b0 75 // fill map
76 map<Int_t, Track* > tracks;
77 RenderElement::List_i citer = cont->BeginChildren();
78 while(citer != cont->EndChildren())
79 {
80 Track* track = dynamic_cast<Track*>(*citer);
81 tracks[track->GetLabel()] = track;
82 ++citer;
c63fcc1d 83 }
1d74e2b0 84
c63fcc1d 85 Int_t nPrimaries = (Int_t) treeTR->GetEntries();
86 TIter next(treeTR->GetListOfBranches());
87 TBranchElement* el;
88 Bool_t isRef = kTRUE;
c63fcc1d 89
90 while ((el = (TBranchElement*) next()))
91 {
92 if (strcmp("AliRun",el->GetName()) == 0)
93 isRef = kFALSE;
94
1d74e2b0 95 TClonesArray* arr = 0;
96 el->SetAddress(&arr);
c63fcc1d 97 for (Int_t iPrimPart = 0; iPrimPart<nPrimaries; iPrimPart++)
98 {
1d74e2b0 99 el->GetEntry(iPrimPart);
100
101 Int_t last_label = -1;
102 map<Int_t, Track*>::iterator iter = tracks.end();
103 Int_t Nent = arr->GetEntriesFast();
104 for (Int_t iTrackRef = 0; iTrackRef < Nent; iTrackRef++)
c63fcc1d 105 {
1d74e2b0 106 AliTrackReference* atr = (AliTrackReference*)arr->UncheckedAt(iTrackRef);
107
108 Int_t label = atr->GetTrack();
109 if (label < 0)
110 throw(eH + Form("negative label for entry %d in branch %s.",
111 iTrackRef, el->GetName()));
112
113 if(label != last_label) {
114 iter = tracks.find(label);
115 last_label = label;
116 }
117
118 if (iter != tracks.end()) {
119 PathMark* pm = new PathMark(isRef ? PathMark::Reference : PathMark::Decay);
120 pm->V.Set(atr->X(),atr->Y(), atr->Z());
121 pm->P.Set(atr->Px(),atr->Py(), atr->Pz());
122 pm->time = atr->GetTime();
123 Track* track = iter->second;
124 track->AddPathMark(pm);
c63fcc1d 125 }
126 } // loop track refs
c63fcc1d 127 } // loop primaries, clones arrays
1d74e2b0 128 delete arr;
c63fcc1d 129 } // end loop through top branches
c63fcc1d 130
1d74e2b0 131 // sort
132 for(map<Int_t, Track*>::iterator j=tracks.begin(); j!=tracks.end(); ++j) {
133 (j->second)->SortPathMarksByTime();
c63fcc1d 134 }
135}