**************************************************************************/
#include "AliEveTrackFitter.h"
+#include "AliEveTrack.h"
#include "TCanvas.h"
#include "TGraph.h"
#include "TGraphErrors.h"
+#include "TQObject.h"
-#include "AliCluster.h"
#include "AliRieman.h"
#include "AliExternalTrackParam.h"
-#include <TEveTrack.h>
#include <TEveTrackPropagator.h>
#include <TEveVSDStructs.h>
#include <TEveManager.h>
-//______________________________________________________________________________
+//==============================================================================
+//==============================================================================
// AliEveTrackFitter
+//==============================================================================
+
+//______________________________________________________________________________
//
-// AliEveTrackFitter is an interface to helix fit. It creates a set of
-// points, listening to signal PointCtrlClicked() of any
-// TEvePointSet. Via editor it fits selected points and creates a
-// reconstructed track.
+// AliEveTrackFitter is an interface to TEvePointSet allowing AliRieman fit.
+// It builds a list of points by listening to selection signal of any
+// object of type TEvePointSet. After selection the list is feeded to
+// AliRieman fitter, which returns helix parameters visualized with
+// AliEveTrack.
//
ClassImp(AliEveTrackFitter)
-AliEveTrackFitter::AliEveTrackFitter(const Text_t* name, Int_t n_points) :
- TEvePointSet (name, n_points),
+AliEveTrackFitter::AliEveTrackFitter(const Text_t* name, Int_t nPoints) :
+ TEvePointSet (name, nPoints),
- fGraphSelected (0),
- fGraphFitted (0),
fAlpha (0),
fRieman (0),
+
fConnected (kFALSE),
+ fSPMap (),
fTrackList (0),
- fMapPS ()
+
+ fGraphPicked (0),
+ fGraphHelix (0)
{
// Constructor.
SetMarkerColor(3);
SetOwnIds(kFALSE);
- fGraphSelected = new TGraph();
- fGraphSelected->SetName("Selected points");
- fGraphSelected->SetMarkerColor(4);
- fGraphSelected->SetMarkerStyle(4);
- fGraphSelected->SetMarkerSize(2);
-
- fGraphFitted = new TGraphErrors();
- fGraphFitted->SetName("Fitted points");
- fGraphFitted->SetMarkerColor(2);
-
fTrackList = new TEveTrackList("Tracks");
+ fTrackList->IncDenyDestroy();
fTrackList->SetLineWidth(2);
fTrackList->SetLineColor(8);
- fTrackList->IncDenyDestroy();
fTrackList->GetPropagator()->SetEditPathMarks(kTRUE);
- gEve->AddElement(fTrackList, this);
- UpdateItems();
+ AddElement(fTrackList);
+
+ fGraphPicked = new TGraph();
+ fGraphPicked->SetName("Selected points");
+ fGraphPicked->SetMarkerColor(4);
+ fGraphPicked->SetMarkerStyle(4);
+ fGraphPicked->SetMarkerSize(2);
+
+ fGraphHelix = new TGraphErrors();
+ fGraphHelix->SetName("Fitted points");
+ fGraphHelix->SetMarkerColor(2);
}
AliEveTrackFitter::~AliEveTrackFitter()
{
// Destructor.
- if(fRieman) delete fRieman;
+ if (fRieman) delete fRieman;
+
fTrackList->DecDenyDestroy();
- delete fTrackList;
}
/******************************************************************************/
+
void AliEveTrackFitter::DestroyElements()
{
// Virtual method of base class TEveElement.
- // It preserves track list to have coomon track propagator attributes.
+ // Preserves TEveTrackList object for fitted helices.
TEveElement::DestroyElements();
+
+ // fTrackList is destroyed because DenyDestroy is set.
gEve->AddElement(fTrackList, this);
fTrackList->DestroyElements();
- UpdateItems();
}
/******************************************************************************/
+
void AliEveTrackFitter::Start()
{
- // Start selection of points.
+ // Clear existing point selection and maintain connection to the
+ // TEvePointSet signal.
Reset();
- if(fConnected == kFALSE)
+ if (fConnected == kFALSE)
{
- TQObject::Connect("TEvePointSet", "PointCtrlClicked(TEvePointSet*,Int_t)",
- "AliEveTrackFitter", this, "AddFitPoint(TEvePointSet*,Int_t)");
-
+ TQObject::Connect("TEvePointSet", "PointSelected(Int_t)",
+ "AliEveTrackFitter", this, "AddFitPoint(Int_t)");
fConnected = kTRUE;
}
}
void AliEveTrackFitter::Stop()
{
- // Stop selection of points.
+ // Stop adding points for the fit.
- if(fConnected)
+ if (fConnected)
{
- TQObject::Disconnect("TEvePointSet", "AddFitPoint(TEvePointSet*,Int_t)");
+ TQObject::Disconnect("TEvePointSet", "AddFitPoint(Int_t)");
fConnected = kFALSE;
}
}
+void AliEveTrackFitter::Reset(Int_t nPoints, Int_t nIntIds)
+{
+ // Reset selection.
+
+ if (fRieman) fRieman->Reset();
+ TEvePointSet::Reset(nPoints, nIntIds);
+ fSPMap.clear();
+}
+
/******************************************************************************/
-void AliEveTrackFitter::AddFitPoint(TEvePointSet* ps, Int_t n)
+void AliEveTrackFitter::AddFitPoint(Int_t pointId)
{
- // Add/remove given point depending if exists in the fMapPS.
+ // Add or remove given point depending if exists in the map.
Float_t x, y, z;
- std::map<Point_t, Int_t>::iterator g = fMapPS.find(Point_t(ps, n));
- if(g != fMapPS.end())
+ TEvePointSet* ps = static_cast<TEvePointSet*>((TQObject*) gTQSender);
+
+ PointMap_t::iterator g = fSPMap.find(Point_t(ps, pointId));
+ if (g != fSPMap.end())
{
Int_t idx = g->second;
- if(idx != fLastPoint)
+ if (idx != fLastPoint)
{
GetPoint(fLastPoint, x, y, z);
SetPoint(idx, x, y, z);
}
- fMapPS.erase(g);
- fLastPoint--;
+ fSPMap.erase(g);
+ --fLastPoint;
}
else
{
- fMapPS[Point_t(ps, n)] = Size();
- ps->GetPoint(n, x, y, z);
+ fSPMap[Point_t(ps, pointId)] = Size();
+ ps->GetPoint(pointId, x, y, z);
SetNextPoint(x, y, z);
- SetPointId(ps->GetPointId(n));
}
+
ResetBBox();
ElementChanged(kTRUE, kTRUE);
}
using namespace TMath;
- if(fRieman) delete fRieman;
+ if (fRieman) delete fRieman;
fRieman = new AliRieman(Size());
Float_t x, y, z;
Int_t alphaIdx = 0;
GetPoint(alphaIdx, x, y, z);
Float_t minR2=x*x + y*y;
- for (Int_t i=1; i<=fLastPoint; i++)
+ for (Int_t i=0; i<=fLastPoint; i++)
{
GetPoint(i, x, y, z);
Float_t cR2 = x*x + y*y;
- if ( minR2 > cR2 )
+ if (minR2 > cR2)
{
minR2 = cR2;
alphaIdx = i;
fAlpha = ATan2(y, x);
Float_t sin = Sin(-fAlpha);
Float_t cos = Cos(-fAlpha);
- for (Int_t i=0; i<=fLastPoint; i++) {
+ for (Int_t i = 0; i <= fLastPoint; ++i)
+ {
GetPoint(i, x, y, z);
fRieman->AddPoint(cos*x - sin*y, cos*y + sin*x, z, 1, 1);
}
// curvature to pt
param[4] /= TEveTrackPropagator::fgDefMagField*TEveTrackPropagator::fgkB2C;
// sign in tang
- if(param[4] < 0) param[3] *= -1;
+ if (param[4] < 0) param[3] = -param[3];
AliExternalTrackParam trackParam(r, fAlpha, param, cov);
trackParam.Print();
// make track
- Double_t AliEveV0[3];
- trackParam.GetXYZAt(r, TEveTrackPropagator::fgDefMagField, AliEveV0);
- Double_t P0[3];
- trackParam.GetPxPyPzAt(r, TEveTrackPropagator::fgDefMagField, P0);
+ Double_t v0[3];
+ trackParam.GetXYZAt(r, TEveTrackPropagator::fgDefMagField, v0);
+ Double_t p0[3];
+ trackParam.GetPxPyPzAt(r, TEveTrackPropagator::fgDefMagField, p0);
TEveRecTrack rc;
- rc.fV.Set(AliEveV0);
- rc.fP.Set(P0);
+ rc.fV.Set(v0);
+ rc.fP.Set(p0);
rc.fSign = trackParam.Charge();
- TEveTrack* track = new TEveTrack(&rc, fTrackList->GetPropagator());
+ AliEveTrack* track = new AliEveTrack(&rc, fTrackList->GetPropagator());
track->SetName(Form("track %f", fAlpha));
- TEvePathMark* pm = new TEvePathMark(TEvePathMark::kDaughter);
- for(Int_t i=0; i==fLastPoint; i++)
- {
- GetPoint(i, x, y, z);
- pm->fV.Set(x, y, z);
- pm->fP.Set(P0);
- track->AddPathMark(pm);
- }
+
track->MakeTrack();
track->SetAttLineAttMarker(fTrackList);
- gEve->AddElement(track, fTrackList);
+ fTrackList->AddElement(track);
}
-void AliEveTrackFitter::Reset(Int_t n, Int_t ids)
-{
- // Reset selection.
-
- if(fRieman) fRieman->Reset();
- TEvePointSet::Reset(n, ids);
- fMapPS.clear();
-}
-
/******************************************************************************/
-void AliEveTrackFitter::DrawRiemanGraph()
+
+void AliEveTrackFitter::DrawDebugGraph()
{
- // Draw graph of rieman fit.
+ // Draw graph of picked points and helix points.
- static const TEveException eH("AliEveTrackFitter::DrawRiemanGraph ");
+ static const TEveException kEH("AliEveTrackFitter::DrawRiemanGraph ");
- if(fRieman == 0)
- throw(eH + "fitter not set.");
+ if (fRieman == 0)
+ throw(kEH + "fitter not set.");
Int_t nR = fRieman->GetN();
- fGraphSelected->Set(nR);
- fGraphFitted->Set(nR);
+ fGraphPicked->Set(nR);
+ fGraphHelix->Set(nR);
- Double_t* x = fRieman->GetX();
- Double_t* y = fRieman->GetY();
+ Double_t* x = fRieman->GetX();
+ Double_t* y = fRieman->GetY();
Double_t* sy = fRieman->GetSy();
for (Int_t i=0; i<nR; i++)
{
- fGraphSelected->SetPoint(i, x[i], y[i]);
- fGraphFitted->SetPoint(i, x[i], fRieman->GetYat(x[i]));
- fGraphFitted->SetPointError(i, 0.1, sy[i]);
+ fGraphPicked->SetPoint(i, x[i], y[i]);
+ fGraphHelix->SetPoint (i, x[i], fRieman->GetYat(x[i]));
+ fGraphHelix->SetPointError(i, 0.1, sy[i]); // now faked
}
- if (gPad) gPad->Clear();
- fGraphSelected->Draw("AP");
- fGraphFitted->Draw("SAME P");
+ if (gPad)
+ gPad->Clear();
+
+ fGraphPicked->Draw("AP");
+ fGraphHelix->Draw("SAME P");
gPad->GetCanvas()->SetTitle(Form("AliRieman alpha: %f", fAlpha));
gPad->Modified();
gPad->Update();