]>
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" | |
a15e6d7d | 15 | #include "TQObject.h" |
5a1436d6 | 16 | |
5a1436d6 | 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 | |
a15e6d7d | 26 | //============================================================================== |
27 | //============================================================================== | |
d810d0de | 28 | // AliEveTrackFitter |
a15e6d7d | 29 | //============================================================================== |
30 | ||
31 | //______________________________________________________________________________ | |
5a1436d6 | 32 | // |
40790e5b | 33 | // AliEveTrackFitter is an interface to TEvePointSet allowing AliRieman fit. |
a15e6d7d | 34 | // It builds a list of points by listening to selection signal of any |
35 | // object of type TEvePointSet. After selection the list is feeded to | |
36 | // AliRieman fitter, which returns helix parameters visualized with | |
37 | // TEveTrack. | |
51346b82 | 38 | // |
5a1436d6 | 39 | |
d810d0de | 40 | ClassImp(AliEveTrackFitter) |
5a1436d6 | 41 | |
a15e6d7d | 42 | AliEveTrackFitter::AliEveTrackFitter(const Text_t* name, Int_t nPoints) : |
43 | TEvePointSet (name, nPoints), | |
fd31e9de | 44 | |
fd31e9de | 45 | fAlpha (0), |
46 | fRieman (0), | |
40790e5b | 47 | |
fd31e9de | 48 | fConnected (kFALSE), |
40790e5b | 49 | fSPMap (), |
fd31e9de | 50 | fTrackList (0), |
40790e5b | 51 | |
52 | fGraphPicked (0), | |
53 | fGraphHelix (0) | |
5a1436d6 | 54 | { |
55 | // Constructor. | |
56 | ||
57 | SetMarkerColor(3); | |
58 | SetOwnIds(kFALSE); | |
59 | ||
84aff7a4 | 60 | fTrackList = new TEveTrackList("Tracks"); |
a15e6d7d | 61 | fTrackList->IncDenyDestroy(); |
5a1436d6 | 62 | fTrackList->SetLineWidth(2); |
63 | fTrackList->SetLineColor(8); | |
84aff7a4 | 64 | fTrackList->GetPropagator()->SetEditPathMarks(kTRUE); |
a15e6d7d | 65 | AddElement(fTrackList); |
5a1436d6 | 66 | UpdateItems(); |
40790e5b | 67 | |
68 | fGraphPicked = new TGraph(); | |
69 | fGraphPicked->SetName("Selected points"); | |
70 | fGraphPicked->SetMarkerColor(4); | |
71 | fGraphPicked->SetMarkerStyle(4); | |
72 | fGraphPicked->SetMarkerSize(2); | |
73 | ||
74 | fGraphHelix = new TGraphErrors(); | |
75 | fGraphHelix->SetName("Fitted points"); | |
76 | fGraphHelix->SetMarkerColor(2); | |
5a1436d6 | 77 | } |
78 | ||
d810d0de | 79 | AliEveTrackFitter::~AliEveTrackFitter() |
5a1436d6 | 80 | { |
81 | // Destructor. | |
82 | ||
a15e6d7d | 83 | if (fRieman) delete fRieman; |
40790e5b | 84 | |
5a1436d6 | 85 | fTrackList->DecDenyDestroy(); |
5a1436d6 | 86 | } |
87 | ||
57ffa5fb | 88 | /******************************************************************************/ |
a15e6d7d | 89 | |
90 | void AliEveTrackFitter::DestroyElements() | |
91 | { | |
92 | // Virtual method of base class TEveElement. | |
93 | // Preserves TEveTrackList object for fitted helices. | |
94 | ||
95 | TEveElement::DestroyElements(); | |
96 | ||
97 | // fTrackList is destroyed because DenyDestroy is set. | |
98 | gEve->AddElement(fTrackList, this); | |
99 | fTrackList->DestroyElements(); | |
100 | ||
101 | UpdateItems(); | |
102 | } | |
103 | ||
104 | /******************************************************************************/ | |
105 | ||
d810d0de | 106 | void AliEveTrackFitter::Start() |
5a1436d6 | 107 | { |
40790e5b | 108 | // Clear existing point selection and maintain connection to the |
109 | // TEvePointSet signal. | |
5a1436d6 | 110 | |
111 | Reset(); | |
a15e6d7d | 112 | if (fConnected == kFALSE) |
5a1436d6 | 113 | { |
a15e6d7d | 114 | TQObject::Connect("TEvePointSet", "PointSelected(Int_t)", |
115 | "AliEveTrackFitter", this, "AddFitPoint(Int_t)"); | |
5a1436d6 | 116 | fConnected = kTRUE; |
117 | } | |
118 | } | |
119 | ||
d810d0de | 120 | void AliEveTrackFitter::Stop() |
5a1436d6 | 121 | { |
40790e5b | 122 | // Stop adding points for the fit. |
5a1436d6 | 123 | |
a15e6d7d | 124 | if (fConnected) |
5a1436d6 | 125 | { |
a15e6d7d | 126 | TQObject::Disconnect("TEvePointSet", "AddFitPoint(Int_t)"); |
5a1436d6 | 127 | fConnected = kFALSE; |
128 | } | |
129 | } | |
130 | ||
a15e6d7d | 131 | void AliEveTrackFitter::Reset(Int_t nPoints, Int_t nIntIds) |
40790e5b | 132 | { |
133 | // Reset selection. | |
134 | ||
a15e6d7d | 135 | if (fRieman) fRieman->Reset(); |
136 | TEvePointSet::Reset(nPoints, nIntIds); | |
40790e5b | 137 | fSPMap.clear(); |
138 | } | |
139 | ||
57ffa5fb | 140 | /******************************************************************************/ |
5a1436d6 | 141 | |
a15e6d7d | 142 | void AliEveTrackFitter::AddFitPoint(Int_t pointId) |
51346b82 | 143 | { |
40790e5b | 144 | // Add or remove given point depending if exists in the map. |
51346b82 | 145 | |
5a1436d6 | 146 | Float_t x, y, z; |
147 | ||
a15e6d7d | 148 | TEvePointSet* ps = dynamic_cast<TEvePointSet*>((TQObject*) gTQSender); |
149 | ||
150 | PointMap_t::iterator g = fSPMap.find(Point_t(ps, pointId)); | |
151 | if (g != fSPMap.end()) | |
5a1436d6 | 152 | { |
153 | Int_t idx = g->second; | |
a15e6d7d | 154 | if (idx != fLastPoint) |
5a1436d6 | 155 | { |
156 | GetPoint(fLastPoint, x, y, z); | |
157 | SetPoint(idx, x, y, z); | |
158 | } | |
40790e5b | 159 | fSPMap.erase(g); |
a15e6d7d | 160 | --fLastPoint; |
5a1436d6 | 161 | } |
51346b82 | 162 | else |
5a1436d6 | 163 | { |
a15e6d7d | 164 | fSPMap[Point_t(ps, pointId)] = Size(); |
165 | ps->GetPoint(pointId, x, y, z); | |
51346b82 | 166 | SetNextPoint(x, y, z); |
5a1436d6 | 167 | } |
40790e5b | 168 | |
5a1436d6 | 169 | ResetBBox(); |
170 | ElementChanged(kTRUE, kTRUE); | |
171 | } | |
172 | ||
57ffa5fb | 173 | /******************************************************************************/ |
5a1436d6 | 174 | |
d810d0de | 175 | void AliEveTrackFitter::FitTrack() |
5a1436d6 | 176 | { |
177 | // Fit selected points with AliRieman fitter. | |
178 | ||
179 | using namespace TMath; | |
180 | ||
a15e6d7d | 181 | if (fRieman) delete fRieman; |
5a1436d6 | 182 | fRieman = new AliRieman(Size()); |
183 | ||
184 | Float_t x, y, z; | |
185 | Int_t alphaIdx = 0; | |
186 | GetPoint(alphaIdx, x, y, z); | |
187 | Float_t minR2=x*x + y*y; | |
188 | for (Int_t i=1; i<=fLastPoint; i++) | |
189 | { | |
190 | GetPoint(i, x, y, z); | |
191 | Float_t cR2 = x*x + y*y; | |
192 | if ( minR2 > cR2 ) | |
193 | { | |
194 | minR2 = cR2; | |
195 | alphaIdx = i; | |
196 | } | |
197 | } | |
198 | GetPoint(alphaIdx, x, y, z); | |
199 | fAlpha = ATan2(y, x); | |
200 | Float_t sin = Sin(-fAlpha); | |
51346b82 | 201 | Float_t cos = Cos(-fAlpha); |
202 | for (Int_t i=0; i<=fLastPoint; i++) { | |
5a1436d6 | 203 | GetPoint(i, x, y, z); |
204 | fRieman->AddPoint(cos*x - sin*y, cos*y + sin*x, z, 1, 1); | |
205 | } | |
206 | fRieman->Update(); | |
207 | ||
208 | Double_t r = Sqrt(minR2); | |
209 | Double_t param[5]; | |
210 | Double_t cov[15]; | |
211 | fRieman->GetExternalParameters(r, param, cov); | |
212 | // curvature to pt | |
84aff7a4 | 213 | param[4] /= TEveTrackPropagator::fgDefMagField*TEveTrackPropagator::fgkB2C; |
5a1436d6 | 214 | // sign in tang |
a15e6d7d | 215 | if (param[4] < 0) param[3] *= -1; |
5a1436d6 | 216 | AliExternalTrackParam trackParam(r, fAlpha, param, cov); |
217 | trackParam.Print(); | |
218 | ||
219 | // make track | |
a15e6d7d | 220 | Double_t v0[3]; |
221 | trackParam.GetXYZAt(r, TEveTrackPropagator::fgDefMagField, v0); | |
222 | Double_t p0[3]; | |
223 | trackParam.GetPxPyPzAt(r, TEveTrackPropagator::fgDefMagField, p0); | |
84aff7a4 | 224 | TEveRecTrack rc; |
a15e6d7d | 225 | rc.fV.Set(v0); |
226 | rc.fP.Set(p0); | |
84aff7a4 | 227 | rc.fSign = trackParam.Charge(); |
5a1436d6 | 228 | |
84aff7a4 | 229 | TEveTrack* track = new TEveTrack(&rc, fTrackList->GetPropagator()); |
5a1436d6 | 230 | track->SetName(Form("track %f", fAlpha)); |
a15e6d7d | 231 | for(Int_t i=0; i<=fLastPoint; ++i) |
5a1436d6 | 232 | { |
a15e6d7d | 233 | TEvePathMark pm(TEvePathMark::kDaughter); |
5a1436d6 | 234 | GetPoint(i, x, y, z); |
a15e6d7d | 235 | pm.fV.Set(x, y, z); |
236 | pm.fP.Set(p0); | |
5a1436d6 | 237 | track->AddPathMark(pm); |
238 | } | |
239 | track->MakeTrack(); | |
51346b82 | 240 | track->SetAttLineAttMarker(fTrackList); |
a15e6d7d | 241 | fTrackList->AddElement(track); |
5a1436d6 | 242 | } |
243 | ||
244 | ||
40790e5b | 245 | /******************************************************************************/ |
5a1436d6 | 246 | |
40790e5b | 247 | void AliEveTrackFitter::DrawDebugGraph() |
5a1436d6 | 248 | { |
40790e5b | 249 | // Draw graph of picked points and helix points. |
5a1436d6 | 250 | |
a15e6d7d | 251 | static const TEveException kEH("AliEveTrackFitter::DrawRiemanGraph "); |
5a1436d6 | 252 | |
a15e6d7d | 253 | if (fRieman == 0) |
254 | throw(kEH + "fitter not set."); | |
5a1436d6 | 255 | |
256 | Int_t nR = fRieman->GetN(); | |
40790e5b | 257 | fGraphPicked->Set(nR); |
258 | fGraphHelix->Set(nR); | |
5a1436d6 | 259 | |
40790e5b | 260 | Double_t* x = fRieman->GetX(); |
261 | Double_t* y = fRieman->GetY(); | |
5a1436d6 | 262 | Double_t* sy = fRieman->GetSy(); |
263 | for (Int_t i=0; i<nR; i++) | |
264 | { | |
40790e5b | 265 | fGraphPicked->SetPoint(i, x[i], y[i]); |
266 | fGraphHelix->SetPoint (i, x[i], fRieman->GetYat(x[i])); | |
267 | fGraphHelix->SetPointError(i, 0.1, sy[i]); // now faked | |
5a1436d6 | 268 | } |
51346b82 | 269 | |
40790e5b | 270 | if (gPad) |
271 | gPad->Clear(); | |
272 | ||
273 | fGraphPicked->Draw("AP"); | |
274 | fGraphHelix->Draw("SAME P"); | |
5a1436d6 | 275 | gPad->GetCanvas()->SetTitle(Form("AliRieman alpha: %f", fAlpha)); |
276 | gPad->Modified(); | |
277 | gPad->Update(); | |
278 | } |