]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/alice-macros/kine_tracks.C
Changes from Reve::RenderElement.
[u/mrichter/AliRoot.git] / EVE / alice-macros / kine_tracks.C
1 // Import tracks from kinematics-tree / particle-stack.
2 // Preliminary/minimal solution.
3 #include "TParticlePDG.h"
4
5 // PDG color indices
6 static Color_t DefCol  = 30;
7 static Color_t ECol    = 5;
8 static Color_t MuCol   = 6;
9 static Color_t GamaCol = 7; 
10 static Color_t MesCol1 = 3;
11 static Color_t MesCol2 = 38;
12 static Color_t BarCol  = 10;
13
14
15 Reve::TrackList*
16 kine_tracks(Double_t min_pt=0.5, Double_t max_pt=100, Bool_t pdg_col= kFALSE)
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.
31   rnrStyle->SetMagField( - gAlice->Field()->SolenoidField() );
32
33   gReve->AddRenderElement(cont);
34
35   Int_t count = 0;
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);
55       TParticlePDG* pdgp = p->GetPDG();
56       track->SetMainColor(get_pdg_color(pdgp->PdgCode()));
57       gReve->AddRenderElement(cont, track);
58     }
59   }
60   
61   // set path marks
62   Alieve::KineTools kt; 
63   rl->LoadTrackRefs();
64   kt.SetPathMarks(cont,stack, rl->TreeTR());
65   cont->SetEditPathMarks(kTRUE);
66
67
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);
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 }
80
81
82 Color_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 }
117
118
119 // Create mother and daughters tracks with given label.
120
121 Reve::RenderElement*
122 kine_track(Int_t  label,
123            Bool_t import_mother    = kTRUE,
124            Bool_t import_daughters = kTRUE,
125            Reve::RenderElement*    cont = 0)
126
127 {
128   if (label < 0) {
129     Warning("kine_track", "label not set.");
130     return 0;
131   }
132  
133   AliRunLoader* rl =  Alieve::Event::AssertRunLoader();
134   rl->LoadKinematics();
135   AliStack* stack = rl->Stack();
136   TParticle* p = stack->Particle(label);
137
138   if (import_mother || (import_daughters && p->GetNDaughters()))
139   {
140     Track* toptrack = 0;
141     TrackList* tracklist = 0;  
142     TrackRnrStyle* rs = 0;
143
144     if (cont == 0)
145     {
146       cont = new TrackList(Form("Kinematics of %d", label, p->GetNDaughters()));
147
148       Reve::TrackRnrStyle* rnrStyle = cont->GetRnrStyle();
149       // !!! Watch the '-', apparently different sign convention then for ESD.
150       rnrStyle->SetMagField( - gAlice->Field()->SolenoidField() );
151       char tooltip[1000];
152       sprintf(tooltip,"Ndaughters=%d", p->GetNDaughters());
153       cont->SetTitle(tooltip);
154       cont->SelectByPt(0.2, 100);
155       rnrStyle->fColor   = 8;
156       rnrStyle->fMaxOrbs = 8;
157       cont->SetEditPathMarks(kTRUE);
158       gReve->AddRenderElement(cont);
159       rs = cont->GetRnrStyle();
160     }
161     else {
162       // check if argument is TrackList
163       Reve::Track* t = dynamic_cast<Reve::Track*>(cont);
164       if(t) 
165       {
166         rs = t->GetRnrStyle();
167       }
168       else {
169         Reve::TrackList* l = dynamic_cast<Reve::TrackList*>(cont);
170         if(l)
171         {
172           rs = l->GetRnrStyle();
173         }
174         else {
175           Error("kine_tracks.C", "TrackRenderStyle not set.");
176         }
177       }
178     }
179
180     if (import_mother)
181     {
182       Track* track = new Reve::Track(p, label, rs);  
183       char form[1000];
184       sprintf(form,"%s [%d]", p->GetName(), label);
185       track->SetName(form);
186       gReve->AddRenderElement(cont, track);
187
188     }
189
190     if (import_daughters && p->GetNDaughters()) 
191     {
192       for (int d=p->GetFirstDaughter(); d>0 && d<=p->GetLastDaughter(); ++d) 
193       { 
194         TParticle* dp = stack->Particle(d);
195         Track* track = new Reve::Track(dp, d, rs);  
196         char form[1000];
197         sprintf(form,"%s [%d]", dp->GetName(), d);
198         track->SetName(form);
199         track->MakeTrack();
200         gReve->AddRenderElement(cont, track);
201       }
202     }
203   }
204
205   cont->UpdateItems();
206   gReve->Redraw3D();
207   return cont;
208 }
209