3 #include "TrackFitter.h"
8 #include "TGraphErrors.h"
10 #include "AliCluster.h"
11 #include "AliRieman.h"
12 #include "AliExternalTrackParam.h"
14 #include <Reve/Track.h>
15 #include <Reve/PODs.h>
16 #include <Reve/ReveManager.h>
19 using namespace Alieve;
21 //______________________________________________________________________
24 // TrackFitter is an interface to helix fit. It creates a set of points, listening to signal
25 // PointCtrlClicked() of any Reve::PointSet. Via editor it fits selected points and creates a
26 // reconstructed track.
31 TrackFitter::TrackFitter(const Text_t* name, Int_t n_points, TreeVarType_e tv_type) :
32 Reve::PointSet(name, n_points, tv_type),
46 fGraphSelected = new TGraph();
47 fGraphSelected->SetName("Selected points");
48 fGraphSelected->SetMarkerColor(4);
49 fGraphSelected->SetMarkerStyle(4);
50 fGraphSelected->SetMarkerSize(2);
52 fGraphFitted = new TGraphErrors();
53 fGraphFitted->SetName("Fitted points");
54 fGraphFitted->SetMarkerColor(2);
56 fTrackList = new TrackList("Tracks");
57 fTrackList->SetLineWidth(2);
58 fTrackList->SetLineColor(8);
59 fTrackList->IncDenyDestroy();
60 fTrackList->GetRnrStyle()->SetEditPathMarks(kTRUE);
61 gReve->AddRenderElement(fTrackList, this);
65 TrackFitter::~TrackFitter()
69 if(fRieman) delete fRieman;
70 fTrackList->DecDenyDestroy();
74 /**************************************************************************/
75 void TrackFitter::DestroyElements()
77 // Virtual method of base class Reve::RenderElement.
78 // It preserves track list to have coomon track propagator attributes.
80 RenderElement::DestroyElements();
81 gReve->AddRenderElement(fTrackList, this);
82 fTrackList->DestroyElements();
86 /**************************************************************************/
87 void TrackFitter::Start()
89 // Start selection of points.
92 if(fConnected == kFALSE)
94 TQObject::Connect("Reve::PointSet", "PointCtrlClicked(Reve::PointSet*,Int_t)",
95 "Alieve::TrackFitter", this, "AddFitPoint(Reve::PointSet*,Int_t)");
101 void TrackFitter::Stop()
103 // Stop selection of points.
107 TQObject::Disconnect("Reve::PointSet", "AddFitPoint(Reve::PointSet*,Int_t)");
112 /**************************************************************************/
114 void TrackFitter::AddFitPoint(Reve::PointSet* ps, Int_t n)
116 // Add/remove given point depending if exists in the fMapPS.
120 std::map<Point_t, Int_t>::iterator g = fMapPS.find(Point_t(ps, n));
121 if(g != fMapPS.end())
123 Int_t idx = g->second;
124 if(idx != fLastPoint)
126 GetPoint(fLastPoint, x, y, z);
127 SetPoint(idx, x, y, z);
134 fMapPS[Point_t(ps, n)] = Size();
135 ps->GetPoint(n, x, y, z);
136 SetNextPoint(x, y, z);
137 SetPointId(ps->GetPointId(n));
140 ElementChanged(kTRUE, kTRUE);
143 /**************************************************************************/
145 void TrackFitter::FitTrack()
147 // Fit selected points with AliRieman fitter.
149 using namespace TMath;
151 if(fRieman) delete fRieman;
152 fRieman = new AliRieman(Size());
156 GetPoint(alphaIdx, x, y, z);
157 Float_t minR2=x*x + y*y;
158 for (Int_t i=1; i<=fLastPoint; i++)
160 GetPoint(i, x, y, z);
161 Float_t cR2 = x*x + y*y;
168 GetPoint(alphaIdx, x, y, z);
169 fAlpha = ATan2(y, x);
170 Float_t sin = Sin(-fAlpha);
171 Float_t cos = Cos(-fAlpha);
172 for (Int_t i=0; i<=fLastPoint; i++) {
173 GetPoint(i, x, y, z);
174 fRieman->AddPoint(cos*x - sin*y, cos*y + sin*x, z, 1, 1);
178 Double_t r = Sqrt(minR2);
181 fRieman->GetExternalParameters(r, param, cov);
183 param[4] /= TrackRnrStyle::fgDefMagField*TrackRnrStyle::fgkB2C;
185 if(param[4] < 0) param[3] *= -1;
186 AliExternalTrackParam trackParam(r, fAlpha, param, cov);
191 trackParam.GetXYZAt(r, TrackRnrStyle::fgDefMagField, V0);
193 trackParam.GetPxPyPzAt(r, TrackRnrStyle::fgDefMagField, P0);
197 rc.sign = trackParam.Charge();
199 Track* track = new Track(&rc, fTrackList->GetRnrStyle());
200 track->SetName(Form("track %f", fAlpha));
201 PathMark* pm = new PathMark(PathMark::Daughter);
202 for(Int_t i=0; i==fLastPoint; i++)
204 GetPoint(i, x, y, z);
207 track->AddPathMark(pm);
210 track->SetAttLineAttMarker(fTrackList);
211 gReve->AddRenderElement(track, fTrackList);
215 void TrackFitter::Reset(Int_t n, Int_t ids)
219 if(fRieman) fRieman->Reset();
220 PointSet::Reset(n, ids);
224 /**************************************************************************/
225 void TrackFitter::DrawRiemanGraph()
227 // Draw graph of rieman fit.
229 static const Exc_t eH("TrackFitter::DrawRiemanGraph ");
232 throw(eH + "fitter not set.");
234 Int_t nR = fRieman->GetN();
235 fGraphSelected->Set(nR);
236 fGraphFitted->Set(nR);
238 Double_t* x = fRieman->GetX();
239 Double_t* y = fRieman->GetY();
240 Double_t* sy = fRieman->GetSy();
241 for (Int_t i=0; i<nR; i++)
243 fGraphSelected->SetPoint(i, x[i], y[i]);
244 fGraphFitted->SetPoint(i, x[i], fRieman->GetYat(x[i]));
245 fGraphFitted->SetPointError(i, 0.1, sy[i]);
248 if (gPad) gPad->Clear();
249 fGraphSelected->Draw("AP");
250 fGraphFitted->Draw("SAME P");
251 gPad->GetCanvas()->SetTitle(Form("AliRieman alpha: %f", fAlpha));