]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/Alieve/AliEveTrackFitter.cxx
Normalize all separator comments to width 80.
[u/mrichter/AliRoot.git] / EVE / Alieve / AliEveTrackFitter.cxx
CommitLineData
d810d0de 1// $Id$
2// Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
5a1436d6 3
d810d0de 4/**************************************************************************
5 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
6 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for *
51346b82 7 * full copyright notice. *
d810d0de 8 **************************************************************************/
9
10#include "AliEveTrackFitter.h"
5a1436d6 11
5a1436d6 12#include "TCanvas.h"
13#include "TGraph.h"
14#include "TGraphErrors.h"
15
16#include "AliCluster.h"
17#include "AliRieman.h"
18#include "AliExternalTrackParam.h"
19
84aff7a4 20#include <TEveTrack.h>
21#include <TEveTrackPropagator.h>
22#include <TEveVSDStructs.h>
23#include <TEveManager.h>
5a1436d6 24
5a1436d6 25
57ffa5fb 26//______________________________________________________________________________
d810d0de 27// AliEveTrackFitter
5a1436d6 28//
d810d0de 29// AliEveTrackFitter is an interface to helix fit. It creates a set of
84aff7a4 30// points, listening to signal PointCtrlClicked() of any
31// TEvePointSet. Via editor it fits selected points and creates a
32// reconstructed track.
51346b82 33//
5a1436d6 34
d810d0de 35ClassImp(AliEveTrackFitter)
5a1436d6 36
d810d0de 37AliEveTrackFitter::AliEveTrackFitter(const Text_t* name, Int_t n_points) :
a189470c 38 TEvePointSet(name, n_points),
5a1436d6 39
40 fGraphSelected(0),
41 fGraphFitted(0),
42
43 fRieman(0),
44 fConnected(kFALSE),
45 fTrackList(0)
46{
47 // Constructor.
48
49 SetMarkerColor(3);
50 SetOwnIds(kFALSE);
51
52 fGraphSelected = new TGraph();
53 fGraphSelected->SetName("Selected points");
54 fGraphSelected->SetMarkerColor(4);
51346b82 55 fGraphSelected->SetMarkerStyle(4);
5a1436d6 56 fGraphSelected->SetMarkerSize(2);
57
58 fGraphFitted = new TGraphErrors();
59 fGraphFitted->SetName("Fitted points");
60 fGraphFitted->SetMarkerColor(2);
61
84aff7a4 62 fTrackList = new TEveTrackList("Tracks");
5a1436d6 63 fTrackList->SetLineWidth(2);
64 fTrackList->SetLineColor(8);
65 fTrackList->IncDenyDestroy();
84aff7a4 66 fTrackList->GetPropagator()->SetEditPathMarks(kTRUE);
67 gEve->AddElement(fTrackList, this);
5a1436d6 68 UpdateItems();
69}
70
d810d0de 71AliEveTrackFitter::~AliEveTrackFitter()
5a1436d6 72{
73 // Destructor.
74
75 if(fRieman) delete fRieman;
76 fTrackList->DecDenyDestroy();
77 delete fTrackList;
78}
79
57ffa5fb 80/******************************************************************************/
d810d0de 81void AliEveTrackFitter::DestroyElements()
5a1436d6 82{
84aff7a4 83 // Virtual method of base class TEveElement.
5a1436d6 84 // It preserves track list to have coomon track propagator attributes.
85
84aff7a4 86 TEveElement::DestroyElements();
87 gEve->AddElement(fTrackList, this);
5a1436d6 88 fTrackList->DestroyElements();
89 UpdateItems();
90}
91
57ffa5fb 92/******************************************************************************/
d810d0de 93void AliEveTrackFitter::Start()
5a1436d6 94{
95 // Start selection of points.
96
97 Reset();
98 if(fConnected == kFALSE)
99 {
84aff7a4 100 TQObject::Connect("TEvePointSet", "PointCtrlClicked(TEvePointSet*,Int_t)",
d810d0de 101 "AliEveTrackFitter", this, "AddFitPoint(TEvePointSet*,Int_t)");
5a1436d6 102
103 fConnected = kTRUE;
104 }
105}
106
d810d0de 107void AliEveTrackFitter::Stop()
5a1436d6 108{
109 // Stop selection of points.
110
111 if(fConnected)
112 {
84aff7a4 113 TQObject::Disconnect("TEvePointSet", "AddFitPoint(TEvePointSet*,Int_t)");
5a1436d6 114 fConnected = kFALSE;
115 }
116}
117
57ffa5fb 118/******************************************************************************/
5a1436d6 119
d810d0de 120void AliEveTrackFitter::AddFitPoint(TEvePointSet* ps, Int_t n)
51346b82 121{
5a1436d6 122 // Add/remove given point depending if exists in the fMapPS.
51346b82 123
5a1436d6 124 Float_t x, y, z;
125
126 std::map<Point_t, Int_t>::iterator g = fMapPS.find(Point_t(ps, n));
127 if(g != fMapPS.end())
128 {
129 Int_t idx = g->second;
130 if(idx != fLastPoint)
131 {
132 GetPoint(fLastPoint, x, y, z);
133 SetPoint(idx, x, y, z);
134 }
135 fMapPS.erase(g);
136 fLastPoint--;
137 }
51346b82 138 else
5a1436d6 139 {
140 fMapPS[Point_t(ps, n)] = Size();
141 ps->GetPoint(n, x, y, z);
51346b82 142 SetNextPoint(x, y, z);
5a1436d6 143 SetPointId(ps->GetPointId(n));
144 }
145 ResetBBox();
146 ElementChanged(kTRUE, kTRUE);
147}
148
57ffa5fb 149/******************************************************************************/
5a1436d6 150
d810d0de 151void AliEveTrackFitter::FitTrack()
5a1436d6 152{
153 // Fit selected points with AliRieman fitter.
154
155 using namespace TMath;
156
157 if(fRieman) delete fRieman;
158 fRieman = new AliRieman(Size());
159
160 Float_t x, y, z;
161 Int_t alphaIdx = 0;
162 GetPoint(alphaIdx, x, y, z);
163 Float_t minR2=x*x + y*y;
164 for (Int_t i=1; i<=fLastPoint; i++)
165 {
166 GetPoint(i, x, y, z);
167 Float_t cR2 = x*x + y*y;
168 if ( minR2 > cR2 )
169 {
170 minR2 = cR2;
171 alphaIdx = i;
172 }
173 }
174 GetPoint(alphaIdx, x, y, z);
175 fAlpha = ATan2(y, x);
176 Float_t sin = Sin(-fAlpha);
51346b82 177 Float_t cos = Cos(-fAlpha);
178 for (Int_t i=0; i<=fLastPoint; i++) {
5a1436d6 179 GetPoint(i, x, y, z);
180 fRieman->AddPoint(cos*x - sin*y, cos*y + sin*x, z, 1, 1);
181 }
182 fRieman->Update();
183
184 Double_t r = Sqrt(minR2);
185 Double_t param[5];
186 Double_t cov[15];
187 fRieman->GetExternalParameters(r, param, cov);
188 // curvature to pt
84aff7a4 189 param[4] /= TEveTrackPropagator::fgDefMagField*TEveTrackPropagator::fgkB2C;
5a1436d6 190 // sign in tang
191 if(param[4] < 0) param[3] *= -1;
192 AliExternalTrackParam trackParam(r, fAlpha, param, cov);
193 trackParam.Print();
194
195 // make track
d810d0de 196 Double_t AliEveV0[3];
197 trackParam.GetXYZAt(r, TEveTrackPropagator::fgDefMagField, AliEveV0);
5a1436d6 198 Double_t P0[3];
84aff7a4 199 trackParam.GetPxPyPzAt(r, TEveTrackPropagator::fgDefMagField, P0);
200 TEveRecTrack rc;
51346b82 201 rc.fV.Set(AliEveV0);
84aff7a4 202 rc.fP.Set(P0);
203 rc.fSign = trackParam.Charge();
5a1436d6 204
84aff7a4 205 TEveTrack* track = new TEveTrack(&rc, fTrackList->GetPropagator());
5a1436d6 206 track->SetName(Form("track %f", fAlpha));
84aff7a4 207 TEvePathMark* pm = new TEvePathMark(TEvePathMark::kDaughter);
5a1436d6 208 for(Int_t i=0; i==fLastPoint; i++)
209 {
210 GetPoint(i, x, y, z);
84aff7a4 211 pm->fV.Set(x, y, z);
51346b82 212 pm->fP.Set(P0);
5a1436d6 213 track->AddPathMark(pm);
214 }
215 track->MakeTrack();
51346b82 216 track->SetAttLineAttMarker(fTrackList);
84aff7a4 217 gEve->AddElement(track, fTrackList);
5a1436d6 218}
219
220
d810d0de 221void AliEveTrackFitter::Reset(Int_t n, Int_t ids)
5a1436d6 222{
223 // Reset selection.
224
225 if(fRieman) fRieman->Reset();
84aff7a4 226 TEvePointSet::Reset(n, ids);
5a1436d6 227 fMapPS.clear();
228}
229
57ffa5fb 230/******************************************************************************/
d810d0de 231void AliEveTrackFitter::DrawRiemanGraph()
5a1436d6 232{
233 // Draw graph of rieman fit.
234
d810d0de 235 static const TEveException eH("AliEveTrackFitter::DrawRiemanGraph ");
5a1436d6 236
237 if(fRieman == 0)
238 throw(eH + "fitter not set.");
239
240 Int_t nR = fRieman->GetN();
241 fGraphSelected->Set(nR);
242 fGraphFitted->Set(nR);
243
51346b82 244 Double_t* x = fRieman->GetX();
5a1436d6 245 Double_t* y = fRieman->GetY();
246 Double_t* sy = fRieman->GetSy();
247 for (Int_t i=0; i<nR; i++)
248 {
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]);
252 }
51346b82 253
5a1436d6 254 if (gPad) gPad->Clear();
255 fGraphSelected->Draw("AP");
256 fGraphFitted->Draw("SAME P");
257 gPad->GetCanvas()->SetTitle(Form("AliRieman alpha: %f", fAlpha));
258 gPad->Modified();
259 gPad->Update();
260}