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 TEvePointSet allowing AliRieman fit.
30 // It builds a list of points by listening to selection signal of any object of type
31 // TEvePointSet. After selection the list is feeded to AliRieman fitter,
32 // which returns helix parameters visualized with TEveTrack.
35 ClassImp(AliEveTrackFitter)
37 AliEveTrackFitter::AliEveTrackFitter(const Text_t* name, Int_t n_points) :
38 TEvePointSet (name, n_points),
55 fTrackList = new TEveTrackList("Tracks");
56 fTrackList->SetLineWidth(2);
57 fTrackList->SetLineColor(8);
58 fTrackList->IncDenyDestroy();
59 fTrackList->GetPropagator()->SetEditPathMarks(kTRUE);
60 gEve->AddElement(fTrackList, this);
63 fGraphPicked = new TGraph();
64 fGraphPicked->SetName("Selected points");
65 fGraphPicked->SetMarkerColor(4);
66 fGraphPicked->SetMarkerStyle(4);
67 fGraphPicked->SetMarkerSize(2);
69 fGraphHelix = new TGraphErrors();
70 fGraphHelix->SetName("Fitted points");
71 fGraphHelix->SetMarkerColor(2);
74 AliEveTrackFitter::~AliEveTrackFitter()
78 if(fRieman) delete fRieman;
80 fTrackList->DecDenyDestroy();
84 /******************************************************************************/
85 void AliEveTrackFitter::Start()
87 // Clear existing point selection and maintain connection to the
88 // TEvePointSet signal.
91 if(fConnected == kFALSE)
93 TQObject::Connect("TEvePointSet", "PointCtrlClicked(TEvePointSet*,Int_t)",
94 "AliEveTrackFitter", this, "AddFitPoint(TEvePointSet*,Int_t)");
99 void AliEveTrackFitter::Stop()
101 // Stop adding points for the fit.
105 TQObject::Disconnect("TEvePointSet", "AddFitPoint(TEvePointSet*,Int_t)");
110 void AliEveTrackFitter::Reset(Int_t n, Int_t ids)
114 if(fRieman) fRieman->Reset();
115 TEvePointSet::Reset(n, ids);
119 /******************************************************************************/
121 void AliEveTrackFitter::AddFitPoint(TEvePointSet* ps, Int_t n)
123 // Add or remove given point depending if exists in the map.
127 PointMap_t::iterator g = fSPMap.find(Point_t(ps, n));
128 if(g != fSPMap.end())
130 Int_t idx = g->second;
131 if(idx != fLastPoint)
133 GetPoint(fLastPoint, x, y, z);
134 SetPoint(idx, x, y, z);
141 fSPMap[Point_t(ps, n)] = Size();
142 ps->GetPoint(n, x, y, z);
143 SetNextPoint(x, y, z);
144 SetPointId(ps->GetPointId(n));
148 ElementChanged(kTRUE, kTRUE);
151 /******************************************************************************/
153 void AliEveTrackFitter::FitTrack()
155 // Fit selected points with AliRieman fitter.
157 using namespace TMath;
159 if(fRieman) delete fRieman;
160 fRieman = new AliRieman(Size());
164 GetPoint(alphaIdx, x, y, z);
165 Float_t minR2=x*x + y*y;
166 for (Int_t i=1; i<=fLastPoint; i++)
168 GetPoint(i, x, y, z);
169 Float_t cR2 = x*x + y*y;
176 GetPoint(alphaIdx, x, y, z);
177 fAlpha = ATan2(y, x);
178 Float_t sin = Sin(-fAlpha);
179 Float_t cos = Cos(-fAlpha);
180 for (Int_t i=0; i<=fLastPoint; i++) {
181 GetPoint(i, x, y, z);
182 fRieman->AddPoint(cos*x - sin*y, cos*y + sin*x, z, 1, 1);
186 Double_t r = Sqrt(minR2);
189 fRieman->GetExternalParameters(r, param, cov);
191 param[4] /= TEveTrackPropagator::fgDefMagField*TEveTrackPropagator::fgkB2C;
193 if(param[4] < 0) param[3] *= -1;
194 AliExternalTrackParam trackParam(r, fAlpha, param, cov);
198 Double_t AliEveV0[3];
199 trackParam.GetXYZAt(r, TEveTrackPropagator::fgDefMagField, AliEveV0);
201 trackParam.GetPxPyPzAt(r, TEveTrackPropagator::fgDefMagField, P0);
205 rc.fSign = trackParam.Charge();
207 TEveTrack* track = new TEveTrack(&rc, fTrackList->GetPropagator());
208 track->SetName(Form("track %f", fAlpha));
209 TEvePathMark* pm = new TEvePathMark(TEvePathMark::kDaughter);
210 for(Int_t i=0; i==fLastPoint; i++)
212 GetPoint(i, x, y, z);
215 track->AddPathMark(pm);
218 track->SetAttLineAttMarker(fTrackList);
219 gEve->AddElement(track, fTrackList);
223 /******************************************************************************/
224 void AliEveTrackFitter::DestroyElements()
226 // Virtual method of base class TEveElement.
227 // Preserves TEveTrackPropagator object for fitted helices.
229 TEveElement::DestroyElements();
231 gEve->AddElement(fTrackList, this);
232 fTrackList->DestroyElements();
236 /******************************************************************************/
237 void AliEveTrackFitter::DrawDebugGraph()
239 // Draw graph of picked points and helix points.
241 static const TEveException eH("AliEveTrackFitter::DrawRiemanGraph ");
244 throw(eH + "fitter not set.");
246 Int_t nR = fRieman->GetN();
247 fGraphPicked->Set(nR);
248 fGraphHelix->Set(nR);
250 Double_t* x = fRieman->GetX();
251 Double_t* y = fRieman->GetY();
252 Double_t* sy = fRieman->GetSy();
253 for (Int_t i=0; i<nR; i++)
255 fGraphPicked->SetPoint(i, x[i], y[i]);
256 fGraphHelix->SetPoint (i, x[i], fRieman->GetYat(x[i]));
257 fGraphHelix->SetPointError(i, 0.1, sy[i]); // now faked
263 fGraphPicked->Draw("AP");
264 fGraphHelix->Draw("SAME P");
265 gPad->GetCanvas()->SetTitle(Form("AliRieman alpha: %f", fAlpha));