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),
53 fGraphSelected = new TGraph();
54 fGraphSelected->SetName("Selected points");
55 fGraphSelected->SetMarkerColor(4);
56 fGraphSelected->SetMarkerStyle(4);
57 fGraphSelected->SetMarkerSize(2);
59 fGraphFitted = new TGraphErrors();
60 fGraphFitted->SetName("Fitted points");
61 fGraphFitted->SetMarkerColor(2);
63 fTrackList = new TEveTrackList("Tracks");
64 fTrackList->SetLineWidth(2);
65 fTrackList->SetLineColor(8);
66 fTrackList->IncDenyDestroy();
67 fTrackList->GetPropagator()->SetEditPathMarks(kTRUE);
68 gEve->AddElement(fTrackList, this);
72 AliEveTrackFitter::~AliEveTrackFitter()
76 if(fRieman) delete fRieman;
77 fTrackList->DecDenyDestroy();
81 /******************************************************************************/
82 void AliEveTrackFitter::DestroyElements()
84 // Virtual method of base class TEveElement.
85 // It preserves track list to have coomon track propagator attributes.
87 TEveElement::DestroyElements();
88 gEve->AddElement(fTrackList, this);
89 fTrackList->DestroyElements();
93 /******************************************************************************/
94 void AliEveTrackFitter::Start()
96 // Start selection of points.
99 if(fConnected == kFALSE)
101 TQObject::Connect("TEvePointSet", "PointCtrlClicked(TEvePointSet*,Int_t)",
102 "AliEveTrackFitter", this, "AddFitPoint(TEvePointSet*,Int_t)");
108 void AliEveTrackFitter::Stop()
110 // Stop selection of points.
114 TQObject::Disconnect("TEvePointSet", "AddFitPoint(TEvePointSet*,Int_t)");
119 /******************************************************************************/
121 void AliEveTrackFitter::AddFitPoint(TEvePointSet* ps, Int_t n)
123 // Add/remove given point depending if exists in the fMapPS.
127 std::map<Point_t, Int_t>::iterator g = fMapPS.find(Point_t(ps, n));
128 if(g != fMapPS.end())
130 Int_t idx = g->second;
131 if(idx != fLastPoint)
133 GetPoint(fLastPoint, x, y, z);
134 SetPoint(idx, x, y, z);
141 fMapPS[Point_t(ps, n)] = Size();
142 ps->GetPoint(n, x, y, z);
143 SetNextPoint(x, y, z);
144 SetPointId(ps->GetPointId(n));
147 ElementChanged(kTRUE, kTRUE);
150 /******************************************************************************/
152 void AliEveTrackFitter::FitTrack()
154 // Fit selected points with AliRieman fitter.
156 using namespace TMath;
158 if(fRieman) delete fRieman;
159 fRieman = new AliRieman(Size());
163 GetPoint(alphaIdx, x, y, z);
164 Float_t minR2=x*x + y*y;
165 for (Int_t i=1; i<=fLastPoint; i++)
167 GetPoint(i, x, y, z);
168 Float_t cR2 = x*x + y*y;
175 GetPoint(alphaIdx, x, y, z);
176 fAlpha = ATan2(y, x);
177 Float_t sin = Sin(-fAlpha);
178 Float_t cos = Cos(-fAlpha);
179 for (Int_t i=0; i<=fLastPoint; i++) {
180 GetPoint(i, x, y, z);
181 fRieman->AddPoint(cos*x - sin*y, cos*y + sin*x, z, 1, 1);
185 Double_t r = Sqrt(minR2);
188 fRieman->GetExternalParameters(r, param, cov);
190 param[4] /= TEveTrackPropagator::fgDefMagField*TEveTrackPropagator::fgkB2C;
192 if(param[4] < 0) param[3] *= -1;
193 AliExternalTrackParam trackParam(r, fAlpha, param, cov);
197 Double_t AliEveV0[3];
198 trackParam.GetXYZAt(r, TEveTrackPropagator::fgDefMagField, AliEveV0);
200 trackParam.GetPxPyPzAt(r, TEveTrackPropagator::fgDefMagField, P0);
204 rc.fSign = trackParam.Charge();
206 TEveTrack* track = new TEveTrack(&rc, fTrackList->GetPropagator());
207 track->SetName(Form("track %f", fAlpha));
208 TEvePathMark* pm = new TEvePathMark(TEvePathMark::kDaughter);
209 for(Int_t i=0; i==fLastPoint; i++)
211 GetPoint(i, x, y, z);
214 track->AddPathMark(pm);
217 track->SetAttLineAttMarker(fTrackList);
218 gEve->AddElement(track, fTrackList);
222 void AliEveTrackFitter::Reset(Int_t n, Int_t ids)
226 if(fRieman) fRieman->Reset();
227 TEvePointSet::Reset(n, ids);
231 /******************************************************************************/
232 void AliEveTrackFitter::DrawRiemanGraph()
234 // Draw graph of rieman fit.
236 static const TEveException eH("AliEveTrackFitter::DrawRiemanGraph ");
239 throw(eH + "fitter not set.");
241 Int_t nR = fRieman->GetN();
242 fGraphSelected->Set(nR);
243 fGraphFitted->Set(nR);
245 Double_t* x = fRieman->GetX();
246 Double_t* y = fRieman->GetY();
247 Double_t* sy = fRieman->GetSy();
248 for (Int_t i=0; i<nR; i++)
250 fGraphSelected->SetPoint(i, x[i], y[i]);
251 fGraphFitted->SetPoint(i, x[i], fRieman->GetYat(x[i]));
252 fGraphFitted->SetPointError(i, 0.1, sy[i]);
255 if (gPad) gPad->Clear();
256 fGraphSelected->Draw("AP");
257 fGraphFitted->Draw("SAME P");
258 gPad->GetCanvas()->SetTitle(Form("AliRieman alpha: %f", fAlpha));