]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/EveBase/AliEveTrackCounter.cxx
From Jochen - EveHLT development accumulated since the end of March.
[u/mrichter/AliRoot.git] / EVE / EveBase / AliEveTrackCounter.cxx
CommitLineData
f76c9e9b 1// @(#)root/eve:$Id$
2// Author: Matevz Tadel 2007
3
4/**************************************************************************
5 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
6 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for *
7 * full copyright notice. *
8 **************************************************************************/
9
10#include "AliEveTrackCounter.h"
11
12#include "TEveManager.h"
13#include "TEveTrack.h"
14#include "TEveGedEditor.h"
15
16//==============================================================================
17// AliEveTrackCounter
18//==============================================================================
19
20//______________________________________________________________________________
21//
22// Provides event-based method for tagging of good / bad (or primary /
23// secondary) tracks. A report can be written into a text file.
24//
25// TEveTrack status is toggled by using secondary-selection / ctrl-click
26// functionality of the GL viewer.
27//
28// Some of the functionality is implemented in AliEveTrackCounterEditor
29// class.
30
31ClassImp(AliEveTrackCounter)
32
33//______________________________________________________________________________
34AliEveTrackCounter* AliEveTrackCounter::fgInstance = 0;
35
36//______________________________________________________________________________
37AliEveTrackCounter::AliEveTrackCounter(const Text_t* name, const Text_t* title) :
38 TEveElement(),
39 TNamed(name, title),
40
41 fBadLineStyle (6),
42 fClickAction (kCA_ToggleTrack),
43 fAllTracks (0),
44 fGoodTracks (0),
45 fTrackLists ()
46{
47 // Constructor.
48 // Connects to global signal "TEveTrack", "SecSelected(TEveTrack*)".
49
50 if (fgInstance == 0) fgInstance = this;
51 TQObject::Connect("TEveTrack", "SecSelected(TEveTrack*)",
52 "AliEveTrackCounter", this, "DoTrackAction(TEveTrack*)");
53}
54
55//______________________________________________________________________________
56AliEveTrackCounter::~AliEveTrackCounter()
57{
58 // Destructor.
59 // Disconnect from the global track signals.
60
61 TQObject::Disconnect("TEveTrack", "DoTrackAction(TEveTrack*)");
62 if (fgInstance == this) fgInstance = 0;
63}
64
65/******************************************************************************/
66
67//______________________________________________________________________________
68void AliEveTrackCounter::Reset()
69{
70 // Reset internal track-counters and track-list.
71
72 printf("AliEveTrackCounter::Reset()\n");
73 fAllTracks = 0;
74 fGoodTracks = 0;
75 TIter next(&fTrackLists);
76 TEveTrackList* tlist;
77 while ((tlist = dynamic_cast<TEveTrackList*>(next())))
78 tlist->DecDenyDestroy();
79 fTrackLists.Clear("nodelete");
80}
81
82//______________________________________________________________________________
83void AliEveTrackCounter::RegisterTracks(TEveTrackList* tlist, Bool_t goodTracks)
84{
85 // Register tracks from tlist and tlist itself.
86 // If goodTracks is true, they are considered as primary/good
87 // tracks.
88
89 tlist->IncDenyDestroy();
90 fTrackLists.Add(tlist);
91
92 List_i i = tlist->BeginChildren();
93 while (i != tlist->EndChildren())
94 {
95 TEveTrack* t = dynamic_cast<TEveTrack*>(*i);
96 if (t != 0)
97 {
98 if (goodTracks)
99 {
100 ++fGoodTracks;
101 } else {
102 t->SetLineStyle(fBadLineStyle);
103 }
104 ++fAllTracks;
105 }
106 ++i;
107 }
108}
109
110//______________________________________________________________________________
111void AliEveTrackCounter::DoTrackAction(TEveTrack* track)
112{
113 // Slot called when track is ctrl-clicked.
114 //
115 // No check is done if track actually belongs to one of the
116 // registered track-lists.
117 //
118 // Probably it would be safer to copy good/bad tracks into special
119 // sub-containers.
120 // In this case one should also override RemoveElementLocal.
121
122 static const TEveException eh("AliEveTrackCounter::DoTrackAction ");
123
124 switch (fClickAction)
125 {
126
127 case kCA_PrintTrackInfo:
128 {
129 printf("TEveTrack '%s'\n", track->GetObject(eh)->GetName());
130 const TEveVector &v = track->GetVertex();
131 const TEveVector &p = track->GetMomentum();;
132 printf(" Vx=%f, Vy=%f, Vz=%f; Pt=%f, Pz=%f, phi=%f)\n",
133 v.fX, v.fY, v.fZ, p.Perp(), p.fZ, TMath::RadToDeg()*p.Phi());
134 printf(" <other information should be printed ... full AliESDtrack>\n");
135 break;
136 }
137
138 case kCA_ToggleTrack:
139 {
140 if (track->GetLineStyle() == 1)
141 {
142 track->SetLineStyle(fBadLineStyle);
143 --fGoodTracks;
144 } else {
145 track->SetLineStyle(1);
146 ++fGoodTracks;
147 }
148 track->ElementChanged();
149 gEve->Redraw3D();
150
151 printf("AliEveTrackCounter::CountTrack All=%d, Good=%d, Bad=%d\n",
152 fAllTracks, fGoodTracks, fAllTracks-fGoodTracks);
153
154 if (gEve->GetEditor()->GetModel() == GetObject(eh))
155 gEve->EditElement(this);
156
157 break;
158 }
159
160 } // end switch fClickAction
161}
162
163/******************************************************************************/
164
165//______________________________________________________________________________
166void AliEveTrackCounter::OutputEventTracks(FILE* out)
167{
168 // Print good-track summary into a plain-text file by iteration
169 // through all registered track-lists.
170 // State of each track is determined by its line-style, it is
171 // considered a good track if it's line style is solid.
172
173 if (out == 0)
174 {
175 out = stdout;
176 fprintf(out, "AliEveTrackCounter::FinalizeEvent()\n");
177 }
178
179 fprintf(out, "Event = %d Ntracks = %d\n", fEventId, fGoodTracks);
180
181 TIter tlists(&fTrackLists);
182 TEveTrackList* tlist;
183 Int_t cnt = 0;
184 while ((tlist = (TEveTrackList*) tlists()) != 0)
185 {
186 List_i i = tlist->BeginChildren();
187 while (i != tlist->EndChildren())
188 {
189 TEveTrack* t = dynamic_cast<TEveTrack*>(*i);
190 if (t != 0 && t->GetLineStyle() == 1)
191 {
192 ++cnt;
193 fprintf(out, " %2d: chg=%+2d pt=%8.5f eta=%+8.5f\n",
194 cnt, t->GetCharge(), t->GetMomentum().Perp(), t->GetMomentum().Eta());
195 }
196 ++i;
197 }
198 }
199}