]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/alice-macros/kine_tracks.C
Add option to color tracks according to PDG code.
[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* kine_tracks(Double_t min_pt=0.5, Double_t max_pt=100, Bool_t pdg_col= kFALSE)
16 {
17   AliRunLoader* rl =  Alieve::Event::AssertRunLoader();
18   rl->LoadKinematics();
19   AliStack* stack = rl->Stack();
20   if (!stack) {
21     Error("kine_tracks.C", "can not get kinematics.");
22     return 0;
23   }
24
25   Reve::TrackList* cont = new Reve::TrackList("Kine Tracks"); 
26   cont->SetMainColor(Color_t(6));
27   Reve::TrackRnrStyle* rnrStyle = cont->GetRnrStyle();
28   rnrStyle->fColor = 8;
29   // !!! Watch the '-', apparently different sign convention then for ESD.
30   rnrStyle->SetMagField( - gAlice->Field()->SolenoidField() );
31
32   gReve->AddRenderElement(cont);
33
34   Int_t count = 0;
35   Int_t N = stack->GetNtrack();
36   for (Int_t i=0; i<N; ++i) 
37   {
38     if(stack->IsPhysicalPrimary(i)) 
39     {
40       TParticle* p = stack->Particle(i);
41       Double_t  pT = p->Pt();
42       if (pT<min_pt || pT>max_pt) continue;
43
44       ++count;
45       Reve::Track* track = new Reve::Track(p, i, rnrStyle);
46   
47       //PH The line below is replaced waiting for a fix in Root
48       //PH which permits to use variable siza arguments in CINT
49       //PH on some platforms (alphalinuxgcc, solariscc5, etc.)
50       //PH    track->SetName(Form("%s [%d]", p->GetName(), i));
51       char form[1000];
52       sprintf(form,"%s [%d]", p->GetName(), i);
53       track->SetName(form);
54       TParticlePDG* pdgp = p->GetPDG();
55       track->SetMainColor(get_pdg_color(pdgp->PdgCode()));
56       gReve->AddRenderElement(cont, track);
57     }
58   }
59   
60   // set path marks
61   Alieve::KineTools kt; 
62   rl->LoadTrackRefs();
63   kt.SetPathMarks(cont,stack, rl->TreeTR());
64   cont->SetEditPathMarks(kTRUE);
65
66
67   //PH  const Text_t* tooltip = Form("pT ~ (%.2lf, %.2lf), N=%d", min_pt, max_pt, count);
68   char tooltip[1000];
69   sprintf(tooltip,"pT ~ (%.2lf, %.2lf), N=%d", min_pt, max_pt, count);
70   cont->SetTitle(tooltip); // Not broadcasted automatically ...
71   cont->UpdateItems();
72
73   cont->MakeTracks();
74   cont->MakeMarkers();
75   gReve->Redraw3D();
76
77   return cont;
78 }
79
80
81 Color_t get_pdg_color(Int_t pdg){
82   Int_t pdga = TMath::Abs(pdg);
83   Color_t col = Reve::DefCol;
84
85   // elementary  particles
86   if (pdga < 100) {
87     switch (pdga) {
88       case 11:  
89         col = ECol; break; 
90       case 12:
91         col = MuCol; break;
92       case 22:
93         col = GammaCol; break;
94     }
95   }
96   else if (pdga < 100000){ 
97     Int_t i  = pdga;
98     Int_t i0 = i%10; i /= 10;
99     Int_t i1 = i%10; i /= 10; 
100     Int_t i2 = i%10; i /= 10; 
101     Int_t i3 = i%10; i /= 10; 
102     Int_t i4 = i%10;
103     //printf("pdg(%d) quark indices (%d,%d,%d,%d,%d) \n",pdg, i4,i3,i2, i1, i0);
104     // meson
105     if ((i3 == 0) && ( i4 < 2)){
106       col = MesCol1; // quarks: i1,i2 (spin = i0)
107       if(i1 == 3 || i2 == 3)
108         col = MesCol2;
109     } // barion
110     else if ( i2 >= i1 && i3 >= i2 ) {
111       col = BarCol; // quarks: i1,i2, i3 (spin = i0))
112     }
113   }
114   return col;
115 }