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"
14 #include "TGraphErrors.h"
16 #include "AliCluster.h"
17 #include "AliRieman.h"
18 #include "AliExternalTrackParam.h"
20 #include <TEveTrack.h>
21 #include <TEveTrackPropagator.h>
22 #include <TEveVSDStructs.h>
23 #include <TEveManager.h>
26 //______________________________________________________________________
29 // AliEveTrackFitter is an interface to helix fit. It creates a set of
30 // points, listening to signal PointCtrlClicked() of any
31 // TEvePointSet. Via editor it fits selected points and creates a
32 // reconstructed track.
35 ClassImp(AliEveTrackFitter)
37 AliEveTrackFitter::AliEveTrackFitter(const Text_t* name, Int_t n_points) :
38 TEvePointSet(name, n_points),
52 fGraphSelected = new TGraph();
53 fGraphSelected->SetName("Selected points");
54 fGraphSelected->SetMarkerColor(4);
55 fGraphSelected->SetMarkerStyle(4);
56 fGraphSelected->SetMarkerSize(2);
58 fGraphFitted = new TGraphErrors();
59 fGraphFitted->SetName("Fitted points");
60 fGraphFitted->SetMarkerColor(2);
62 fTrackList = new TEveTrackList("Tracks");
63 fTrackList->SetLineWidth(2);
64 fTrackList->SetLineColor(8);
65 fTrackList->IncDenyDestroy();
66 fTrackList->GetPropagator()->SetEditPathMarks(kTRUE);
67 gEve->AddElement(fTrackList, this);
71 AliEveTrackFitter::~AliEveTrackFitter()
75 if(fRieman) delete fRieman;
76 fTrackList->DecDenyDestroy();
80 /**************************************************************************/
81 void AliEveTrackFitter::DestroyElements()
83 // Virtual method of base class TEveElement.
84 // It preserves track list to have coomon track propagator attributes.
86 TEveElement::DestroyElements();
87 gEve->AddElement(fTrackList, this);
88 fTrackList->DestroyElements();
92 /**************************************************************************/
93 void AliEveTrackFitter::Start()
95 // Start selection of points.
98 if(fConnected == kFALSE)
100 TQObject::Connect("TEvePointSet", "PointCtrlClicked(TEvePointSet*,Int_t)",
101 "AliEveTrackFitter", this, "AddFitPoint(TEvePointSet*,Int_t)");
107 void AliEveTrackFitter::Stop()
109 // Stop selection of points.
113 TQObject::Disconnect("TEvePointSet", "AddFitPoint(TEvePointSet*,Int_t)");
118 /**************************************************************************/
120 void AliEveTrackFitter::AddFitPoint(TEvePointSet* ps, Int_t n)
122 // Add/remove given point depending if exists in the fMapPS.
126 std::map<Point_t, Int_t>::iterator g = fMapPS.find(Point_t(ps, n));
127 if(g != fMapPS.end())
129 Int_t idx = g->second;
130 if(idx != fLastPoint)
132 GetPoint(fLastPoint, x, y, z);
133 SetPoint(idx, x, y, z);
140 fMapPS[Point_t(ps, n)] = Size();
141 ps->GetPoint(n, x, y, z);
142 SetNextPoint(x, y, z);
143 SetPointId(ps->GetPointId(n));
146 ElementChanged(kTRUE, kTRUE);
149 /**************************************************************************/
151 void AliEveTrackFitter::FitTrack()
153 // Fit selected points with AliRieman fitter.
155 using namespace TMath;
157 if(fRieman) delete fRieman;
158 fRieman = new AliRieman(Size());
162 GetPoint(alphaIdx, x, y, z);
163 Float_t minR2=x*x + y*y;
164 for (Int_t i=1; i<=fLastPoint; i++)
166 GetPoint(i, x, y, z);
167 Float_t cR2 = x*x + y*y;
174 GetPoint(alphaIdx, x, y, z);
175 fAlpha = ATan2(y, x);
176 Float_t sin = Sin(-fAlpha);
177 Float_t cos = Cos(-fAlpha);
178 for (Int_t i=0; i<=fLastPoint; i++) {
179 GetPoint(i, x, y, z);
180 fRieman->AddPoint(cos*x - sin*y, cos*y + sin*x, z, 1, 1);
184 Double_t r = Sqrt(minR2);
187 fRieman->GetExternalParameters(r, param, cov);
189 param[4] /= TEveTrackPropagator::fgDefMagField*TEveTrackPropagator::fgkB2C;
191 if(param[4] < 0) param[3] *= -1;
192 AliExternalTrackParam trackParam(r, fAlpha, param, cov);
196 Double_t AliEveV0[3];
197 trackParam.GetXYZAt(r, TEveTrackPropagator::fgDefMagField, AliEveV0);
199 trackParam.GetPxPyPzAt(r, TEveTrackPropagator::fgDefMagField, P0);
203 rc.fSign = trackParam.Charge();
205 TEveTrack* track = new TEveTrack(&rc, fTrackList->GetPropagator());
206 track->SetName(Form("track %f", fAlpha));
207 TEvePathMark* pm = new TEvePathMark(TEvePathMark::kDaughter);
208 for(Int_t i=0; i==fLastPoint; i++)
210 GetPoint(i, x, y, z);
213 track->AddPathMark(pm);
216 track->SetAttLineAttMarker(fTrackList);
217 gEve->AddElement(track, fTrackList);
221 void AliEveTrackFitter::Reset(Int_t n, Int_t ids)
225 if(fRieman) fRieman->Reset();
226 TEvePointSet::Reset(n, ids);
230 /**************************************************************************/
231 void AliEveTrackFitter::DrawRiemanGraph()
233 // Draw graph of rieman fit.
235 static const TEveException eH("AliEveTrackFitter::DrawRiemanGraph ");
238 throw(eH + "fitter not set.");
240 Int_t nR = fRieman->GetN();
241 fGraphSelected->Set(nR);
242 fGraphFitted->Set(nR);
244 Double_t* x = fRieman->GetX();
245 Double_t* y = fRieman->GetY();
246 Double_t* sy = fRieman->GetSy();
247 for (Int_t i=0; i<nR; i++)
249 fGraphSelected->SetPoint(i, x[i], y[i]);
250 fGraphFitted->SetPoint(i, x[i], fRieman->GetYat(x[i]));
251 fGraphFitted->SetPointError(i, 0.1, sy[i]);
254 if (gPad) gPad->Clear();
255 fGraphSelected->Draw("AP");
256 fGraphFitted->Draw("SAME P");
257 gPad->GetCanvas()->SetTitle(Form("AliRieman alpha: %f", fAlpha));