New files: reasonably small extract of geometry and a macro to load it.
[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
539d6798 6static Color_t DefCol = 30;
7static Color_t ECol = 5;
8static Color_t MuCol = 6;
9static Color_t GammaCol = 7;
10static Color_t MesCol1 = 3;
11static Color_t MesCol2 = 38;
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
539d6798 84Color_t get_pdg_color(Int_t pdg)
85{
a7867742 86 Int_t pdga = TMath::Abs(pdg);
87 Color_t col = Reve::DefCol;
88
89 // elementary particles
90 if (pdga < 100) {
91 switch (pdga) {
92 case 11:
93 col = ECol; break;
94 case 12:
95 col = MuCol; break;
96 case 22:
97 col = GammaCol; break;
98 }
99 }
100 else if (pdga < 100000){
101 Int_t i = pdga;
102 Int_t i0 = i%10; i /= 10;
103 Int_t i1 = i%10; i /= 10;
104 Int_t i2 = i%10; i /= 10;
105 Int_t i3 = i%10; i /= 10;
106 Int_t i4 = i%10;
107 //printf("pdg(%d) quark indices (%d,%d,%d,%d,%d) \n",pdg, i4,i3,i2, i1, i0);
108 // meson
109 if ((i3 == 0) && ( i4 < 2)){
110 col = MesCol1; // quarks: i1,i2 (spin = i0)
111 if(i1 == 3 || i2 == 3)
112 col = MesCol2;
113 } // barion
114 else if ( i2 >= i1 && i3 >= i2 ) {
115 col = BarCol; // quarks: i1,i2, i3 (spin = i0))
116 }
117 }
118 return col;
119}
c7b57c0b 120
121
122// Create mother and daughters tracks with given label.
123
2caed564 124Reve::RenderElement*
b65b3044 125kine_track(Int_t label,
126 Bool_t import_mother = kTRUE,
2caed564 127 Bool_t import_daughters = kTRUE,
539d6798 128 Reve::RenderElement* cont = 0)
2caed564 129
c7b57c0b 130{
c7b57c0b 131 if (label < 0) {
132 Warning("kine_track", "label not set.");
133 return 0;
134 }
135
136 AliRunLoader* rl = Alieve::Event::AssertRunLoader();
137 rl->LoadKinematics();
138 AliStack* stack = rl->Stack();
139 TParticle* p = stack->Particle(label);
140
b65b3044 141 if (import_mother || (import_daughters && p->GetNDaughters()))
c7b57c0b 142 {
2caed564 143 Track* toptrack = 0;
144 TrackList* tracklist = 0;
145 TrackRnrStyle* rs = 0;
146
b65b3044 147 if (cont == 0)
148 {
149 cont = new TrackList(Form("Kinematics of %d", label, p->GetNDaughters()));
c7b57c0b 150
151 Reve::TrackRnrStyle* rnrStyle = cont->GetRnrStyle();
152 // !!! Watch the '-', apparently different sign convention then for ESD.
153 rnrStyle->SetMagField( - gAlice->Field()->SolenoidField() );
154 char tooltip[1000];
b65b3044 155 sprintf(tooltip,"Ndaughters=%d", p->GetNDaughters());
2caed564 156 cont->SetTitle(tooltip);
c7b57c0b 157 cont->SelectByPt(0.2, 100);
2caed564 158 rnrStyle->fColor = 8;
159 rnrStyle->fMaxOrbs = 8;
c7b57c0b 160 cont->SetEditPathMarks(kTRUE);
161 gReve->AddRenderElement(cont);
2caed564 162 rs = cont->GetRnrStyle();
163 }
164 else {
165 // check if argument is TrackList
166 Reve::Track* t = dynamic_cast<Reve::Track*>(cont);
167 if(t)
168 {
169 rs = t->GetRnrStyle();
170 }
171 else {
172 Reve::TrackList* l = dynamic_cast<Reve::TrackList*>(cont);
173 if(l)
174 {
175 rs = l->GetRnrStyle();
176 }
177 else {
178 Error("kine_tracks.C", "TrackRenderStyle not set.");
179 }
180 }
c7b57c0b 181 }
2caed564 182
b65b3044 183 if (import_mother)
184 {
2caed564 185 Track* track = new Reve::Track(p, label, rs);
c7b57c0b 186 char form[1000];
187 sprintf(form,"%s [%d]", p->GetName(), label);
188 track->SetName(form);
189 gReve->AddRenderElement(cont, track);
2caed564 190
c7b57c0b 191 }
192
b65b3044 193 if (import_daughters && p->GetNDaughters())
c7b57c0b 194 {
195 for (int d=p->GetFirstDaughter(); d>0 && d<=p->GetLastDaughter(); ++d)
196 {
197 TParticle* dp = stack->Particle(d);
2caed564 198 Track* track = new Reve::Track(dp, d, rs);
c7b57c0b 199 char form[1000];
200 sprintf(form,"%s [%d]", dp->GetName(), d);
201 track->SetName(form);
2caed564 202 track->MakeTrack();
c7b57c0b 203 gReve->AddRenderElement(cont, track);
204 }
205 }
206 }
207
2caed564 208 cont->UpdateItems();
c7b57c0b 209 gReve->Redraw3D();
210 return cont;
211}
2caed564 212