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