Record changes.
[u/mrichter/AliRoot.git] / EVE / alice-macros / kine_tracks.C
CommitLineData
1b337638 1// Import tracks from kinematics-tree / particle-stack.
2// Preliminary/minimal solution.
a7867742 3#include "TParticlePDG.h"
1b337638 4
a7867742 5// PDG color indices
b65b3044 6static Color_t DefCol = 30;
7static Color_t ECol = 5;
8static Color_t MuCol = 6;
a7867742 9static Color_t GamaCol = 7;
10static Color_t MesCol1 = 3;
11static Color_t MesCol2 = 38;
b65b3044 12static Color_t BarCol = 10;
a7867742 13
14
b65b3044 15Reve::TrackList*
16kine_tracks(Double_t min_pt=0.5, Double_t max_pt=100, Bool_t pdg_col= kFALSE)
1b337638 17{
18 AliRunLoader* rl = Alieve::Event::AssertRunLoader();
19 rl->LoadKinematics();
20 AliStack* stack = rl->Stack();
21 if (!stack) {
22 Error("kine_tracks.C", "can not get kinematics.");
23 return 0;
24 }
25
af4b8b4b 26 gReve->DisableRedraw();
27
1b337638 28 Reve::TrackList* cont = new Reve::TrackList("Kine Tracks");
29 cont->SetMainColor(Color_t(6));
30 Reve::TrackRnrStyle* rnrStyle = cont->GetRnrStyle();
31 rnrStyle->fColor = 8;
32 // !!! Watch the '-', apparently different sign convention then for ESD.
32aee3cf 33 rnrStyle->SetMagField( - gAlice->Field()->SolenoidField() );
1b337638 34
35 gReve->AddRenderElement(cont);
1b337638 36 Int_t count = 0;
43d68fc4 37 Int_t N = stack->GetNtrack();
38 for (Int_t i=0; i<N; ++i)
39 {
40 if(stack->IsPhysicalPrimary(i))
41 {
42 TParticle* p = stack->Particle(i);
43 Double_t pT = p->Pt();
44 if (pT<min_pt || pT>max_pt) continue;
45
46 ++count;
47 Reve::Track* track = new Reve::Track(p, i, rnrStyle);
48
49 //PH The line below is replaced waiting for a fix in Root
50 //PH which permits to use variable siza arguments in CINT
51 //PH on some platforms (alphalinuxgcc, solariscc5, etc.)
52 //PH track->SetName(Form("%s [%d]", p->GetName(), i));
53 char form[1000];
54 sprintf(form,"%s [%d]", p->GetName(), i);
55 track->SetName(form);
a7867742 56 TParticlePDG* pdgp = p->GetPDG();
57 track->SetMainColor(get_pdg_color(pdgp->PdgCode()));
43d68fc4 58 gReve->AddRenderElement(cont, track);
59 }
1b337638 60 }
43d68fc4 61 // set path marks
62 Alieve::KineTools kt;
af4b8b4b 63 kt.SetDaughterPathMarks(cont, stack);
43d68fc4 64 rl->LoadTrackRefs();
af4b8b4b 65 kt.SetTrackReferences(cont, rl->TreeTR());
43d68fc4 66 cont->SetEditPathMarks(kTRUE);
67
7be1e8cd 68 //PH const Text_t* tooltip = Form("pT ~ (%.2lf, %.2lf), N=%d", min_pt, max_pt, count);
69 char tooltip[1000];
70 sprintf(tooltip,"pT ~ (%.2lf, %.2lf), N=%d", min_pt, max_pt, count);
1b337638 71 cont->SetTitle(tooltip); // Not broadcasted automatically ...
72 cont->UpdateItems();
73
74 cont->MakeTracks();
75 cont->MakeMarkers();
af4b8b4b 76
77 gReve->EnableRedraw();
1b337638 78 gReve->Redraw3D();
79
80 return cont;
81}
a7867742 82
83
84Color_t get_pdg_color(Int_t pdg){
85 Int_t pdga = TMath::Abs(pdg);
86 Color_t col = Reve::DefCol;
87
88 // elementary particles
89 if (pdga < 100) {
90 switch (pdga) {
91 case 11:
92 col = ECol; break;
93 case 12:
94 col = MuCol; break;
95 case 22:
96 col = GammaCol; break;
97 }
98 }
99 else if (pdga < 100000){
100 Int_t i = pdga;
101 Int_t i0 = i%10; i /= 10;
102 Int_t i1 = i%10; i /= 10;
103 Int_t i2 = i%10; i /= 10;
104 Int_t i3 = i%10; i /= 10;
105 Int_t i4 = i%10;
106 //printf("pdg(%d) quark indices (%d,%d,%d,%d,%d) \n",pdg, i4,i3,i2, i1, i0);
107 // meson
108 if ((i3 == 0) && ( i4 < 2)){
109 col = MesCol1; // quarks: i1,i2 (spin = i0)
110 if(i1 == 3 || i2 == 3)
111 col = MesCol2;
112 } // barion
113 else if ( i2 >= i1 && i3 >= i2 ) {
114 col = BarCol; // quarks: i1,i2, i3 (spin = i0))
115 }
116 }
117 return col;
118}
c7b57c0b 119
120
121// Create mother and daughters tracks with given label.
122
2caed564 123Reve::RenderElement*
b65b3044 124kine_track(Int_t label,
125 Bool_t import_mother = kTRUE,
2caed564 126 Bool_t import_daughters = kTRUE,
127 Reve::RenderElement* cont = 0)
128
c7b57c0b 129{
c7b57c0b 130 if (label < 0) {
131 Warning("kine_track", "label not set.");
132 return 0;
133 }
134
135 AliRunLoader* rl = Alieve::Event::AssertRunLoader();
136 rl->LoadKinematics();
137 AliStack* stack = rl->Stack();
138 TParticle* p = stack->Particle(label);
139
b65b3044 140 if (import_mother || (import_daughters && p->GetNDaughters()))
c7b57c0b 141 {
2caed564 142 Track* toptrack = 0;
143 TrackList* tracklist = 0;
144 TrackRnrStyle* rs = 0;
145
b65b3044 146 if (cont == 0)
147 {
148 cont = new TrackList(Form("Kinematics of %d", label, p->GetNDaughters()));
c7b57c0b 149
150 Reve::TrackRnrStyle* rnrStyle = cont->GetRnrStyle();
151 // !!! Watch the '-', apparently different sign convention then for ESD.
152 rnrStyle->SetMagField( - gAlice->Field()->SolenoidField() );
153 char tooltip[1000];
b65b3044 154 sprintf(tooltip,"Ndaughters=%d", p->GetNDaughters());
2caed564 155 cont->SetTitle(tooltip);
c7b57c0b 156 cont->SelectByPt(0.2, 100);
2caed564 157 rnrStyle->fColor = 8;
158 rnrStyle->fMaxOrbs = 8;
c7b57c0b 159 cont->SetEditPathMarks(kTRUE);
160 gReve->AddRenderElement(cont);
2caed564 161 rs = cont->GetRnrStyle();
162 }
163 else {
164 // check if argument is TrackList
165 Reve::Track* t = dynamic_cast<Reve::Track*>(cont);
166 if(t)
167 {
168 rs = t->GetRnrStyle();
169 }
170 else {
171 Reve::TrackList* l = dynamic_cast<Reve::TrackList*>(cont);
172 if(l)
173 {
174 rs = l->GetRnrStyle();
175 }
176 else {
177 Error("kine_tracks.C", "TrackRenderStyle not set.");
178 }
179 }
c7b57c0b 180 }
2caed564 181
b65b3044 182 if (import_mother)
183 {
2caed564 184 Track* track = new Reve::Track(p, label, rs);
c7b57c0b 185 char form[1000];
186 sprintf(form,"%s [%d]", p->GetName(), label);
187 track->SetName(form);
188 gReve->AddRenderElement(cont, track);
2caed564 189
c7b57c0b 190 }
191
b65b3044 192 if (import_daughters && p->GetNDaughters())
c7b57c0b 193 {
194 for (int d=p->GetFirstDaughter(); d>0 && d<=p->GetLastDaughter(); ++d)
195 {
196 TParticle* dp = stack->Particle(d);
2caed564 197 Track* track = new Reve::Track(dp, d, rs);
c7b57c0b 198 char form[1000];
199 sprintf(form,"%s [%d]", dp->GetName(), d);
200 track->SetName(form);
2caed564 201 track->MakeTrack();
c7b57c0b 202 gReve->AddRenderElement(cont, track);
203 }
204 }
205 }
206
2caed564 207 cont->UpdateItems();
c7b57c0b 208 gReve->Redraw3D();
209 return cont;
210}
2caed564 211