New folder icons/ with improved check-box pictures.
[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
26 Reve::TrackList* cont = new Reve::TrackList("Kine Tracks");
27 cont->SetMainColor(Color_t(6));
28 Reve::TrackRnrStyle* rnrStyle = cont->GetRnrStyle();
29 rnrStyle->fColor = 8;
30 // !!! Watch the '-', apparently different sign convention then for ESD.
32aee3cf 31 rnrStyle->SetMagField( - gAlice->Field()->SolenoidField() );
1b337638 32
33 gReve->AddRenderElement(cont);
34
35 Int_t count = 0;
43d68fc4 36 Int_t N = stack->GetNtrack();
37 for (Int_t i=0; i<N; ++i)
38 {
39 if(stack->IsPhysicalPrimary(i))
40 {
41 TParticle* p = stack->Particle(i);
42 Double_t pT = p->Pt();
43 if (pT<min_pt || pT>max_pt) continue;
44
45 ++count;
46 Reve::Track* track = new Reve::Track(p, i, rnrStyle);
47
48 //PH The line below is replaced waiting for a fix in Root
49 //PH which permits to use variable siza arguments in CINT
50 //PH on some platforms (alphalinuxgcc, solariscc5, etc.)
51 //PH track->SetName(Form("%s [%d]", p->GetName(), i));
52 char form[1000];
53 sprintf(form,"%s [%d]", p->GetName(), i);
54 track->SetName(form);
a7867742 55 TParticlePDG* pdgp = p->GetPDG();
56 track->SetMainColor(get_pdg_color(pdgp->PdgCode()));
43d68fc4 57 gReve->AddRenderElement(cont, track);
58 }
1b337638 59 }
60
43d68fc4 61 // set path marks
62 Alieve::KineTools kt;
63 rl->LoadTrackRefs();
64 kt.SetPathMarks(cont,stack, rl->TreeTR());
65 cont->SetEditPathMarks(kTRUE);
66
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();
76 gReve->Redraw3D();
77
78 return cont;
79}
a7867742 80
81
82Color_t get_pdg_color(Int_t pdg){
83 Int_t pdga = TMath::Abs(pdg);
84 Color_t col = Reve::DefCol;
85
86 // elementary particles
87 if (pdga < 100) {
88 switch (pdga) {
89 case 11:
90 col = ECol; break;
91 case 12:
92 col = MuCol; break;
93 case 22:
94 col = GammaCol; break;
95 }
96 }
97 else if (pdga < 100000){
98 Int_t i = pdga;
99 Int_t i0 = i%10; i /= 10;
100 Int_t i1 = i%10; i /= 10;
101 Int_t i2 = i%10; i /= 10;
102 Int_t i3 = i%10; i /= 10;
103 Int_t i4 = i%10;
104 //printf("pdg(%d) quark indices (%d,%d,%d,%d,%d) \n",pdg, i4,i3,i2, i1, i0);
105 // meson
106 if ((i3 == 0) && ( i4 < 2)){
107 col = MesCol1; // quarks: i1,i2 (spin = i0)
108 if(i1 == 3 || i2 == 3)
109 col = MesCol2;
110 } // barion
111 else if ( i2 >= i1 && i3 >= i2 ) {
112 col = BarCol; // quarks: i1,i2, i3 (spin = i0))
113 }
114 }
115 return col;
116}
c7b57c0b 117
118
119// Create mother and daughters tracks with given label.
120
121Reve::TrackList*
b65b3044 122kine_track(Int_t label,
123 Bool_t import_mother = kTRUE,
124 Bool_t import_daughters = kTRUE,
125 Reve::TrackList* cont = 0)
c7b57c0b 126{
c7b57c0b 127 if (label < 0) {
128 Warning("kine_track", "label not set.");
129 return 0;
130 }
131
132 AliRunLoader* rl = Alieve::Event::AssertRunLoader();
133 rl->LoadKinematics();
134 AliStack* stack = rl->Stack();
135 TParticle* p = stack->Particle(label);
136
b65b3044 137 if (import_mother || (import_daughters && p->GetNDaughters()))
c7b57c0b 138 {
b65b3044 139 if (cont == 0)
140 {
141 cont = new TrackList(Form("Kinematics of %d", label, p->GetNDaughters()));
c7b57c0b 142
143 Reve::TrackRnrStyle* rnrStyle = cont->GetRnrStyle();
144 // !!! Watch the '-', apparently different sign convention then for ESD.
145 rnrStyle->SetMagField( - gAlice->Field()->SolenoidField() );
146 char tooltip[1000];
b65b3044 147 sprintf(tooltip,"Ndaughters=%d", p->GetNDaughters());
c7b57c0b 148 cont->SetTitle(tooltip);
149 cont->SelectByPt(0.2, 100);
b65b3044 150 rnrStyle->fColor = 8;
c7b57c0b 151 rnrStyle->fMaxOrbs = 8;
152 cont->SetEditPathMarks(kTRUE);
153 gReve->AddRenderElement(cont);
154 }
155
b65b3044 156 if (import_mother)
157 {
c7b57c0b 158 Track* track = new Reve::Track(p, label, cont->GetRnrStyle());
159 char form[1000];
160 sprintf(form,"%s [%d]", p->GetName(), label);
161 track->SetName(form);
162 gReve->AddRenderElement(cont, track);
163 }
164
b65b3044 165 if (import_daughters && p->GetNDaughters())
c7b57c0b 166 {
167 for (int d=p->GetFirstDaughter(); d>0 && d<=p->GetLastDaughter(); ++d)
168 {
169 TParticle* dp = stack->Particle(d);
170 Track* track = new Reve::Track(dp, d, cont->GetRnrStyle());
171 char form[1000];
172 sprintf(form,"%s [%d]", dp->GetName(), d);
173 track->SetName(form);
174 gReve->AddRenderElement(cont, track);
175 }
176 }
177 }
178
b65b3044 179 if (cont)
180 {
181 // set path marks
182 if(cont->GetEditPathMarks())
183 {
184 Alieve::KineTools kt;
185 rl->LoadTrackRefs();
186 kt.SetPathMarks(cont, stack, rl->TreeTR());
187 }
188 // update list tree
189 cont->UpdateItems();
190 cont->MakeTracks();
191 cont->MakeMarkers();
c7b57c0b 192 }
193
c7b57c0b 194 gReve->Redraw3D();
195 return cont;
196}