Check if global g_trkcnt has been reset and attempt to reinitialize it from TrackCoun...
[u/mrichter/AliRoot.git] / EVE / macros / trackcount_init.C
1 Reve::TrackCounter* g_trkcnt = 0;
2
3 void trackcount_init()
4 {
5   Reve::LoadMacro("alieve_init.C");
6   alieve_init(".", -1);
7
8   {
9     TGLViewer* glv = dynamic_cast<TGLViewer*>(gReve->GetGLCanvas()->GetViewer3D());
10     glv->SetIgnoreSizesOnUpdate(kTRUE);
11     // The size of ortho cameras can not be set in advance.
12     // glv->SetOrthoCamera(TGLViewer::kCameraOrthoXOY, -0.1, 0.1, 0.1, -0.1);
13     // glv->SetOrthoCamera(TGLViewer::kCameraOrthoZOY, -22, 22, 22, -22);
14   }
15
16   g_trkcnt = new Reve::TrackCounter("Primary Counter");
17   gReve->AddGlobalRenderElement(g_trkcnt);
18
19   Alieve::gEvent->AddNewEventCommand("on_new_event();");
20   Alieve::gEvent->GotoEvent(0);
21 }
22
23 void on_new_event()
24 {
25   Reve::LoadMacro("primary_vertex.C");
26   Reve::LoadMacro("esd_tracks.C");
27   Reve::LoadMacro("its_hits.C");
28   Reve::LoadMacro("tpc_hits.C");
29
30   Reve::PointSet* p = its_hits();
31   p->SetMarkerStyle(4);
32
33   primary_vertex(1, 1);
34
35   Reve::RenderElementList* cont = esd_tracks_vertex_cut();
36   TGListTree* lt = gReve->GetListTree();
37   TGListTreeItem* ti = cont->FindListTreeItem(lt);
38   lt->OpenItem(ti);
39
40   // Here we expect five TrackList containers.
41   // First two have reasonable primaries (sigma-to-prim-vertex < 5).
42   // Other three are almost certainly secondaries.
43   Int_t count = 1;
44   if (g_trkcnt == 0) // This sometimes happens; linked to macro execution, cint reset.
45     g_trkcnt = Reve::TrackCounter::fgInstance;
46   g_trkcnt->Reset();
47   Reve::RenderElement::List_i i = cont->BeginChildren();
48   while (i != cont->EndChildren()) {
49     Reve::TrackList* l = dynamic_cast<Reve::TrackList*>(*i);
50     if (l != 0) {
51       l->SetWidth(2);
52       g_trkcnt->RegisterTracks(l, (count <= 2));
53       ++count;
54     }
55     ++i;
56   }
57 }
58
59 TParticle* id(Int_t label=0, Bool_t showParents=kTRUE)
60 {
61   AliRunLoader* rl = Alieve::Event::AssertRunLoader();
62   rl->LoadKinematics();
63   AliStack* stack = rl->Stack();
64
65   printf("Number primaries %d, all particles %d, label %d\n",
66          stack->GetNprimary(), stack->GetNtrack(), label);
67   if (label < 0 || label >= stack->GetNtrack()) {
68     printf("  Label exceeds available range.\n");
69     return 0;
70   }
71
72   TParticle* part = stack->Particle(label);
73   if(part != 0) {
74     part->Print();
75     if(showParents) {
76       while(part->GetMother(0) >= 0) {
77         part = stack->Particle(part->GetMother(0));
78         part->Print();
79       }
80     }
81   }
82
83   return stack->Particle(label);
84 }