2 // Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
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 **************************************************************************/
10 #include "AliEveTrackFitter.h"
11 #include "AliEveTrack.h"
15 #include "TGraphErrors.h"
18 #include "AliRieman.h"
19 #include "AliExternalTrackParam.h"
21 #include <TEveTrackPropagator.h>
22 #include <TEveVSDStructs.h>
23 #include <TEveManager.h>
26 //==============================================================================
27 //==============================================================================
29 //==============================================================================
31 //______________________________________________________________________________
33 // AliEveTrackFitter is an interface to TEvePointSet allowing AliRieman fit.
34 // It builds a list of points by listening to selection signal of any
35 // object of type TEvePointSet. After selection the list is feeded to
36 // AliRieman fitter, which returns helix parameters visualized with
40 ClassImp(AliEveTrackFitter)
42 AliEveTrackFitter::AliEveTrackFitter(const Text_t* name, Int_t nPoints) :
43 TEvePointSet (name, nPoints),
60 fTrackList = new TEveTrackList("Tracks");
61 fTrackList->IncDenyDestroy();
62 fTrackList->SetLineWidth(2);
63 fTrackList->SetLineColor(8);
64 fTrackList->GetPropagator()->SetEditPathMarks(kTRUE);
65 AddElement(fTrackList);
67 fGraphPicked = new TGraph();
68 fGraphPicked->SetName("Selected points");
69 fGraphPicked->SetMarkerColor(4);
70 fGraphPicked->SetMarkerStyle(4);
71 fGraphPicked->SetMarkerSize(2);
73 fGraphHelix = new TGraphErrors();
74 fGraphHelix->SetName("Fitted points");
75 fGraphHelix->SetMarkerColor(2);
78 AliEveTrackFitter::~AliEveTrackFitter()
82 if (fRieman) delete fRieman;
84 fTrackList->DecDenyDestroy();
87 /******************************************************************************/
89 void AliEveTrackFitter::DestroyElements()
91 // Virtual method of base class TEveElement.
92 // Preserves TEveTrackList object for fitted helices.
94 TEveElement::DestroyElements();
96 // fTrackList is destroyed because DenyDestroy is set.
97 gEve->AddElement(fTrackList, this);
98 fTrackList->DestroyElements();
101 /******************************************************************************/
103 void AliEveTrackFitter::Start()
105 // Clear existing point selection and maintain connection to the
106 // TEvePointSet signal.
109 if (fConnected == kFALSE)
111 TQObject::Connect("TEvePointSet", "PointSelected(Int_t)",
112 "AliEveTrackFitter", this, "AddFitPoint(Int_t)");
117 void AliEveTrackFitter::Stop()
119 // Stop adding points for the fit.
123 TQObject::Disconnect("TEvePointSet", "AddFitPoint(Int_t)");
128 void AliEveTrackFitter::Reset(Int_t nPoints, Int_t nIntIds)
132 if (fRieman) fRieman->Reset();
133 TEvePointSet::Reset(nPoints, nIntIds);
137 /******************************************************************************/
139 void AliEveTrackFitter::AddFitPoint(Int_t pointId)
141 // Add or remove given point depending if exists in the map.
145 TEvePointSet* ps = dynamic_cast<TEvePointSet*>((TQObject*) gTQSender);
147 PointMap_t::iterator g = fSPMap.find(Point_t(ps, pointId));
148 if (g != fSPMap.end())
150 Int_t idx = g->second;
151 if (idx != fLastPoint)
153 GetPoint(fLastPoint, x, y, z);
154 SetPoint(idx, x, y, z);
161 fSPMap[Point_t(ps, pointId)] = Size();
162 ps->GetPoint(pointId, x, y, z);
163 SetNextPoint(x, y, z);
167 ElementChanged(kTRUE, kTRUE);
170 /******************************************************************************/
172 void AliEveTrackFitter::FitTrack()
174 // Fit selected points with AliRieman fitter.
176 using namespace TMath;
178 if (fRieman) delete fRieman;
179 fRieman = new AliRieman(Size());
183 GetPoint(alphaIdx, x, y, z);
184 Float_t minR2=x*x + y*y;
185 for (Int_t i=0; i<=fLastPoint; i++)
187 GetPoint(i, x, y, z);
188 Float_t cR2 = x*x + y*y;
195 GetPoint(alphaIdx, x, y, z);
196 fAlpha = ATan2(y, x);
197 Float_t sin = Sin(-fAlpha);
198 Float_t cos = Cos(-fAlpha);
199 for (Int_t i = 0; i <= fLastPoint; ++i)
201 GetPoint(i, x, y, z);
202 fRieman->AddPoint(cos*x - sin*y, cos*y + sin*x, z, 1, 1);
206 Double_t r = Sqrt(minR2);
209 fRieman->GetExternalParameters(r, param, cov);
211 param[4] /= TEveTrackPropagator::fgDefMagField*TEveTrackPropagator::fgkB2C;
213 if (param[4] < 0) param[3] = -param[3];
214 AliExternalTrackParam trackParam(r, fAlpha, param, cov);
219 trackParam.GetXYZAt(r, TEveTrackPropagator::fgDefMagField, v0);
221 trackParam.GetPxPyPzAt(r, TEveTrackPropagator::fgDefMagField, p0);
225 rc.fSign = trackParam.Charge();
227 AliEveTrack* track = new AliEveTrack(&rc, fTrackList->GetPropagator());
228 track->SetName(Form("track %f", fAlpha));
231 track->SetAttLineAttMarker(fTrackList);
232 fTrackList->AddElement(track);
236 /******************************************************************************/
238 void AliEveTrackFitter::DrawDebugGraph()
240 // Draw graph of picked points and helix points.
242 static const TEveException kEH("AliEveTrackFitter::DrawRiemanGraph ");
245 throw(kEH + "fitter not set.");
247 Int_t nR = fRieman->GetN();
248 fGraphPicked->Set(nR);
249 fGraphHelix->Set(nR);
251 Double_t* x = fRieman->GetX();
252 Double_t* y = fRieman->GetY();
253 Double_t* sy = fRieman->GetSy();
254 for (Int_t i=0; i<nR; i++)
256 fGraphPicked->SetPoint(i, x[i], y[i]);
257 fGraphHelix->SetPoint (i, x[i], fRieman->GetYat(x[i]));
258 fGraphHelix->SetPointError(i, 0.1, sy[i]); // now faked
264 fGraphPicked->Draw("AP");
265 fGraphHelix->Draw("SAME P");
266 gPad->GetCanvas()->SetTitle(Form("AliRieman alpha: %f", fAlpha));