]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/alice-macros/kine_tracks.C
Fix typo in var-name.
[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 GammaCol = 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   gReve->DisableRedraw();
27  
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.
33   rnrStyle->SetMagField( - gAlice->Field()->SolenoidField() );
34
35   gReve->AddRenderElement(cont);
36   Int_t count = 0;
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);
56       TParticlePDG* pdgp = p->GetPDG();
57       track->SetMainColor(get_pdg_color(pdgp->PdgCode()));
58       gReve->AddRenderElement(cont, track);
59     }
60   }
61   // set path marks
62   Alieve::KineTools kt; 
63   kt.SetDaughterPathMarks(cont, stack);
64   rl->LoadTrackRefs();
65   kt.SetTrackReferences(cont, rl->TreeTR());
66   cont->SetEditPathMarks(kTRUE);
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
77   gReve->EnableRedraw();
78   gReve->Redraw3D();
79
80   return cont;
81 }
82
83
84 Color_t get_pdg_color(Int_t pdg)
85 {
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 }
120
121
122 // Create mother and daughters tracks with given label.
123
124 Reve::RenderElement*
125 kine_track(Int_t  label,
126            Bool_t import_mother    = kTRUE,
127            Bool_t import_daughters = kTRUE,
128            Reve::RenderElement* cont = 0)
129
130 {
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
141   if (import_mother || (import_daughters && p->GetNDaughters()))
142   {
143     Track* toptrack = 0;
144     TrackList* tracklist = 0;  
145     TrackRnrStyle* rs = 0;
146
147     if (cont == 0)
148     {
149       cont = new TrackList(Form("Kinematics of %d", label, p->GetNDaughters()));
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];
155       sprintf(tooltip,"Ndaughters=%d", p->GetNDaughters());
156       cont->SetTitle(tooltip);
157       cont->SelectByPt(0.2, 100);
158       rnrStyle->fColor   = 8;
159       rnrStyle->fMaxOrbs = 8;
160       cont->SetEditPathMarks(kTRUE);
161       gReve->AddRenderElement(cont);
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       }
181     }
182
183     if (import_mother)
184     {
185       Track* track = new Reve::Track(p, label, rs);  
186       char form[1000];
187       sprintf(form,"%s [%d]", p->GetName(), label);
188       track->SetName(form);
189       gReve->AddRenderElement(cont, track);
190
191     }
192
193     if (import_daughters && p->GetNDaughters()) 
194     {
195       for (int d=p->GetFirstDaughter(); d>0 && d<=p->GetLastDaughter(); ++d) 
196       { 
197         TParticle* dp = stack->Particle(d);
198         Track* track = new Reve::Track(dp, d, rs);  
199         char form[1000];
200         sprintf(form,"%s [%d]", dp->GetName(), d);
201         track->SetName(form);
202         track->MakeTrack();
203         gReve->AddRenderElement(cont, track);
204       }
205     }
206   }
207
208   cont->UpdateItems();
209   gReve->Redraw3D();
210   return cont;
211 }
212