+
+/**************************************************************************/
+/**************************************************************************/
+/**************************************************************************/
+
+#include "RGEditor.h"
+
+//______________________________________________________________________
+// TrackCounter
+//
+
+ClassImp(TrackCounter)
+
+TrackCounter* TrackCounter::fgInstance = 0;
+
+TrackCounter::TrackCounter(const Text_t* name, const Text_t* title) :
+ RenderElement(),
+ TNamed(name, title),
+
+ fBadLineStyle (6),
+ fClickAction (CA_ToggleTrack),
+ fAllTracks (0),
+ fGoodTracks (0),
+ fTrackLists ()
+{
+ if (fgInstance == 0) fgInstance = this;
+ TQObject::Connect("Reve::Track", "CtrlClicked(Reve::Track*)",
+ "Reve::TrackCounter", this, "DoTrackAction(Reve::Track*)");
+}
+
+TrackCounter::~TrackCounter()
+{
+ TQObject::Disconnect("Reve::Track", "DoTrackAction(Reve::Track*)");
+ if (fgInstance == this) fgInstance = 0;
+}
+
+/**************************************************************************/
+
+void TrackCounter::Reset()
+{
+ printf("TrackCounter::Reset()\n");
+ fAllTracks = 0;
+ fGoodTracks = 0;
+ TIter next(&fTrackLists);
+ TrackList* tlist;
+ while ((tlist = dynamic_cast<TrackList*>(next())))
+ tlist->RemoveParent(this);
+ fTrackLists.Clear();
+}
+
+void TrackCounter::RegisterTracks(TrackList* tlist, Bool_t goodTracks)
+{
+ // printf("TrackCounter::RegisterTracks '%s', %s\n",
+ // tlist->GetObject()->GetName(), goodTracks ? "good" : "bad");
+
+ tlist->AddParent(this);
+ fTrackLists.Add(tlist);
+
+ List_i i = tlist->BeginChildren();
+ while (i != tlist->EndChildren())
+ {
+ Track* t = dynamic_cast<Track*>(*i);
+ if (t != 0)
+ {
+ if (goodTracks)
+ {
+ ++fGoodTracks;
+ } else {
+ t->SetLineStyle(fBadLineStyle);
+ }
+ ++fAllTracks;
+ }
+ ++i;
+ }
+}
+
+void TrackCounter::DoTrackAction(Track* track)
+{
+ // !!!! No check done if ok.
+ // !!!! Should also override RemoveElementLocal
+ // !!!! But then ... should also sotre local information if track is ok.
+
+ switch (fClickAction)
+ {
+
+ case CA_PrintTrackInfo:
+ {
+ printf("Track '%s'\n", track->GetObject()->GetName());
+ Vector &v = track->fV, &p = track->fP;
+ printf(" Vx=%f, Vy=%f, Vz=%f; Pt=%f, Pz=%f, phi=%f)\n",
+ v.x, v.y, v.z, p.Perp(), p.z, TMath::RadToDeg()*p.Phi());
+ printf(" <other information should be printed ... full AliESDtrack>\n");
+ break;
+ }
+
+ case CA_ToggleTrack:
+ {
+ if (track->GetLineStyle() == 1)
+ {
+ track->SetLineStyle(fBadLineStyle);
+ --fGoodTracks;
+ } else {
+ track->SetLineStyle(1);
+ ++fGoodTracks;
+ }
+ gReve->Redraw3D();
+
+ printf("TrackCounter::CountTrack All=%d, Good=%d, Bad=%d\n",
+ fAllTracks, fGoodTracks, fAllTracks-fGoodTracks);
+
+ if (gReve->GetEditor()->GetModel() == GetObject())
+ gReve->EditRenderElement(this);
+
+ break;
+ }
+
+ } // end switch fClickAction
+}
+
+/**************************************************************************/
+
+void TrackCounter::OutputEventTracks(FILE* out)
+{
+ if (out == 0)
+ {
+ out = stdout;
+ fprintf(out, "TrackCounter::FinalizeEvent()\n");
+ }
+
+ fprintf(out, "Event = %d Ntracks = %d\n", fEventId, fGoodTracks);
+
+ TIter tlists(&fTrackLists);
+ TrackList* tlist;
+ Int_t cnt = 0;
+ while ((tlist = (TrackList*) tlists()) != 0)
+ {
+ List_i i = tlist->BeginChildren();
+ while (i != tlist->EndChildren())
+ {
+ Track* t = dynamic_cast<Track*>(*i);
+ if (t != 0 && t->GetLineStyle() == 1)
+ {
+ ++cnt;
+ fprintf(out, " %2d: chg=%+2d pt=%8.5f eta=%+8.5f\n",
+ cnt, t->fCharge, t->fP.Perp(), t->fP.Eta());
+ }
+ ++i;
+ }
+ }
+}