Line data Source code
1 : // $Id$
2 :
3 : //**************************************************************************
4 : //* This file is property of and copyright by the ALICE HLT Project *
5 : //* ALICE Experiment at CERN, All rights reserved. *
6 : //* *
7 : //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 : //* for The ALICE HLT Project. *
9 : //* *
10 : //* Permission to use, copy, modify and distribute this software and its *
11 : //* documentation strictly for non-commercial purposes is hereby granted *
12 : //* without fee, provided that the above copyright notice appears in all *
13 : //* copies and that both the copyright notice and this permission notice *
14 : //* appear in the supporting documentation. The authors make no claims *
15 : //* about the suitability of this software for any purpose. It is *
16 : //* provided "as is" without express or implied warranty. *
17 : //**************************************************************************
18 :
19 : /// @file AliHLTTrackGeometry.cxx
20 : /// @author Matthias Richter
21 : /// @date 2011-05-20
22 : /// @brief Desciption of a track by a sequence of track points
23 : ///
24 :
25 : #include "AliHLTTrackGeometry.h"
26 : #include "AliHLTSpacePointContainer.h"
27 : #include "TObjArray.h"
28 : #include "TMarker.h"
29 : #include "TMath.h"
30 : #include "TH2.h"
31 : #include <memory>
32 : #include <iostream>
33 : #include <algorithm>
34 :
35 : /** ROOT macro for the implementation of ROOT specific class methods */
36 126 : ClassImp(AliHLTTrackGeometry)
37 :
38 : AliHLTTrackGeometry::AliHLTTrackGeometry()
39 0 : : TObject(), AliHLTLogging()
40 0 : , fTrackPoints()
41 0 : , fSelectionMasks()
42 0 : , fTrackId(-1)
43 0 : , fVerbosity(0)
44 0 : {
45 : /// standard constructor
46 0 : }
47 :
48 : AliHLTTrackGeometry::AliHLTTrackGeometry(const AliHLTTrackGeometry& src)
49 0 : : TObject(src), AliHLTLogging()
50 0 : , fTrackPoints(src.fTrackPoints)
51 0 : , fSelectionMasks(src.fSelectionMasks)
52 0 : , fTrackId(src.fTrackId)
53 0 : , fVerbosity(src.fVerbosity)
54 0 : {
55 : /// copy constructor
56 0 : }
57 :
58 : AliHLTTrackGeometry& AliHLTTrackGeometry::operator=(const AliHLTTrackGeometry& src)
59 : {
60 : /// assignment operator
61 0 : if (this!=&src) {
62 0 : fTrackPoints.assign(src.fTrackPoints.begin(), src.fTrackPoints.end());
63 0 : fSelectionMasks.assign(src.fSelectionMasks.begin(), src.fSelectionMasks.end());
64 0 : fTrackId=src.fTrackId;
65 0 : fVerbosity=src.fVerbosity;
66 0 : }
67 0 : return *this;
68 : }
69 :
70 0 : AliHLTTrackGeometry::~AliHLTTrackGeometry()
71 0 : {
72 : /// destructor
73 0 : }
74 :
75 : int AliHLTTrackGeometry::AddTrackPoint(const AliHLTTrackPoint& point, AliHLTUInt32_t selectionMask)
76 : {
77 : /// add a track point to the list
78 0 : vector<AliHLTTrackPoint>::const_iterator element = find(fTrackPoints.begin(), fTrackPoints.end(), point);
79 0 : if (element==fTrackPoints.end()) {
80 0 : fTrackPoints.push_back(point);
81 0 : if (std::find(fSelectionMasks.begin(), fSelectionMasks.end(), selectionMask)==fSelectionMasks.end()) {
82 0 : fSelectionMasks.push_back(selectionMask);
83 0 : }
84 : } else {
85 0 : HLTError("track point of id %08x already existing", point.GetId());
86 0 : return -EEXIST;
87 : }
88 0 : return 0;
89 0 : }
90 :
91 : void AliHLTTrackGeometry::Clear(Option_t * /*option*/)
92 : {
93 : // internal cleanup
94 0 : }
95 :
96 : void AliHLTTrackGeometry::Print(Option_t *option) const
97 : {
98 : // print info
99 0 : Print(cout, option);
100 0 : }
101 :
102 : void AliHLTTrackGeometry::Print(ostream& out, Option_t */*option*/) const
103 : {
104 : // print to stream
105 0 : out << "AliHLTTrackGeometry::Print" << endl;
106 0 : }
107 :
108 : void AliHLTTrackGeometry::Draw(Option_t *option)
109 : {
110 : /// Inherited from TObject, draw the track
111 : float scale=250;
112 : float center[2]={0.5,0.5};
113 : int markerColor=1;
114 : int markerSize=1;
115 : int verbosity=0;
116 :
117 0 : TString strOption(option);
118 0 : std::auto_ptr<TObjArray> tokens(strOption.Tokenize(" "));
119 0 : if (!tokens.get()) return;
120 0 : for (int i=0; i<tokens->GetEntriesFast(); i++) {
121 0 : if (!tokens->At(i)) continue;
122 : const char* key="";
123 0 : TString arg=tokens->At(i)->GetName();
124 :
125 : key="scale=";
126 0 : if (arg.BeginsWith(key)) {
127 0 : arg.ReplaceAll(key, "");
128 0 : scale=arg.Atof();
129 0 : continue;
130 : }
131 : key="centerx=";
132 0 : if (arg.BeginsWith(key)) {
133 0 : arg.ReplaceAll(key, "");
134 0 : center[0]=arg.Atof();
135 0 : continue;
136 : }
137 : key="centery=";
138 0 : if (arg.BeginsWith(key)) {
139 0 : arg.ReplaceAll(key, "");
140 0 : center[1]=arg.Atof();
141 0 : continue;
142 : }
143 :
144 : key="markercolor=";
145 0 : if (arg.BeginsWith(key)) {
146 0 : arg.ReplaceAll(key, "");
147 0 : markerColor=arg.Atoi();
148 0 : continue;
149 : }
150 :
151 : key="markersize=";
152 0 : if (arg.BeginsWith(key)) {
153 0 : arg.ReplaceAll(key, "");
154 0 : markerSize=arg.Atoi();
155 0 : continue;
156 : }
157 :
158 : key="verbosity=";
159 0 : if (arg.BeginsWith(key)) {
160 0 : arg.ReplaceAll(key, "");
161 0 : verbosity=arg.Atoi();
162 0 : continue;
163 : }
164 0 : }
165 :
166 : bool bFirstPoint=true;
167 : float firstalpha=0.0;
168 0 : for (vector<AliHLTTrackPoint>::const_iterator point=fTrackPoints.begin();
169 0 : point!=fTrackPoints.end();
170 0 : point++) {
171 0 : float alpha=GetPlaneAlpha(point->GetId());
172 0 : float r=GetPlaneR(point->GetId());
173 0 : float cosa=TMath::Cos(alpha);
174 0 : float sina=TMath::Sin(alpha);
175 0 : float x = r*sina + point->GetU()*cosa;
176 0 : float y =-r*cosa + point->GetU()*sina;
177 0 : if (verbosity>0) {
178 0 : HLTInfo("ID 0x%08x: x=% .4f y=% .4f alpha=% .4f", point->GetId(), r, point->GetU(), alpha);
179 : }
180 : int color=markerColor;
181 0 : if (bFirstPoint) {
182 : bFirstPoint=false;
183 0 : TMarker* m=new TMarker(x/(2*scale)+center[0], y/(2*scale)+center[1], 29);
184 0 : m->SetMarkerSize(2);
185 0 : m->SetMarkerColor(2);
186 0 : m->Draw("same");
187 : firstalpha=alpha;
188 0 : } else {
189 0 : color+=int(9*TMath::Abs(alpha-firstalpha)/TMath::Pi());
190 : }
191 0 : TMarker* m=new TMarker(x/(2*scale)+center[0], y/(2*scale)+center[1], point->GetV()>0?2:5);
192 0 : m->SetMarkerColor(color);
193 0 : m->SetMarkerSize(markerSize);
194 0 : m->Draw("same");
195 : }
196 0 : }
197 :
198 : int AliHLTTrackGeometry::SetAssociatedSpacePoint(UInt_t planeId, UInt_t spacepointId, int /*status*/, float dU, float dV)
199 : {
200 : /// set the spacepoint associated with a track point
201 0 : vector<AliHLTTrackPoint>::iterator element = find(fTrackPoints.begin(), fTrackPoints.end(), planeId);
202 0 : if (element==fTrackPoints.end()) return -ENOENT;
203 0 : element->AddAssociatedSpacePoint(spacepointId, dU, dV);
204 0 : return 0;
205 0 : }
206 :
207 : int AliHLTTrackGeometry::GetAssociatedSpacePoint(UInt_t planeId, UInt_t& spacepointId) const
208 : {
209 : /// get the spacepoint associated with a track point
210 : /// return status flag if found, -ENOENT if no associated spacepoint found
211 0 : vector<AliHLTTrackPoint>::const_iterator element = find(fTrackPoints.begin(), fTrackPoints.end(), planeId);
212 0 : if (element==fTrackPoints.end()) return -ENOENT;
213 0 : if (!element->HaveAssociatedSpacePoint()) return -ENODATA;
214 0 : spacepointId=(element->GetSpacepoints())[0].fId;
215 0 : return 0;
216 0 : }
217 :
218 : int AliHLTTrackGeometry::RegisterTrackPoints(AliHLTTrackGrid* /*pGrid*/) const
219 : {
220 : /// default implementation, nothing to do
221 0 : return -ENOSYS;
222 : }
223 :
224 : int AliHLTTrackGeometry::FillTrackPoints(AliHLTTrackGrid* /*pGrid*/) const
225 : {
226 : /// default implementation, nothing to do
227 0 : return -ENOSYS;
228 : }
229 :
230 : const AliHLTTrackGeometry::AliHLTTrackPoint* AliHLTTrackGeometry::GetTrackPoint(AliHLTUInt32_t id) const
231 : {
232 : /// get const pointer to track point
233 0 : vector<AliHLTTrackPoint>::const_iterator element = find(fTrackPoints.begin(), fTrackPoints.end(), id);
234 0 : if (element==fTrackPoints.end()) return NULL;
235 0 : return &(*element);
236 0 : }
237 :
238 : AliHLTTrackGeometry::AliHLTTrackPoint* AliHLTTrackGeometry::GetTrackPoint(AliHLTUInt32_t id)
239 : {
240 : /// get const pointer to track point
241 0 : vector<AliHLTTrackPoint>::iterator element = find(fTrackPoints.begin(), fTrackPoints.end(), id);
242 0 : if (element==fTrackPoints.end()) return NULL;
243 0 : return &(*element);
244 0 : }
245 :
246 : AliHLTSpacePointContainer* AliHLTTrackGeometry::ConvertToSpacePoints(bool /*bAssociated*/) const
247 : {
248 : /// create a collection of all points
249 0 : HLTError("implementation of child method missing");
250 0 : return NULL;
251 : }
252 :
253 : int AliHLTTrackGeometry::AssociateSpacePoints(AliHLTSpacePointContainer& points)
254 : {
255 : /// associate the track space points to the calculated track points
256 0 : vector<AliHLTUInt32_t> ids;
257 0 : points.GetClusterIDs(ids);
258 0 : if (ids.size()>0) return 0;
259 0 : int result=AssociateSpacePoints(&ids[0], ids.size(), points);
260 0 : if (result>0) {
261 0 : HLTInfo("associated %d of %d space point(s) to track points", result, ids.size());
262 : }
263 : return result;
264 0 : }
265 :
266 : int AliHLTTrackGeometry::AssociateSpacePoints(const AliHLTUInt32_t* trackpoints, AliHLTUInt32_t nofPoints, AliHLTSpacePointContainer& points)
267 : {
268 : /// associate the track space points to the calculated track points
269 0 : if (nofPoints==0) return 0;
270 0 : if (trackpoints==NULL) return -EINVAL;
271 : int count=0;
272 0 : for (int i=nofPoints-1; i>=0; i--) {
273 0 : if (!points.Check(trackpoints[i])) {
274 0 : HLTWarning("can not find point id %08x", trackpoints[i]);
275 : continue;
276 : }
277 0 : float xyz[3]={points.GetX(trackpoints[i]), points.GetY(trackpoints[i]), points.GetZ(trackpoints[i])};
278 0 : AliHLTUInt32_t planeId=0;
279 0 : int result=FindMatchingTrackPoint(trackpoints[i], xyz, planeId);
280 0 : if (result<0) {
281 0 : if (GetVerbosity()>0) HLTWarning("no associated track point found for space point id %08x x=%f y=%f z=%f", trackpoints[i], xyz[0], xyz[1], xyz[2]);
282 0 : continue;
283 0 : } else if (result==0) {
284 0 : HLTWarning("associated track point for space pointid %08x x=%f y=%f z=%f occupied", trackpoints[i], xyz[0], xyz[1], xyz[2]);
285 0 : continue;
286 : }
287 0 : vector<AliHLTTrackPoint>::const_iterator element = find(fTrackPoints.begin(), fTrackPoints.end(), planeId);
288 0 : SetAssociatedSpacePoint(planeId, trackpoints[i], 1, xyz[1]-element->GetU(), xyz[2]-element->GetV());
289 0 : if (points.GetTrackID(trackpoints[i])<0 && GetTrackId()>=0) {
290 0 : points.SetTrackID(GetTrackId(), trackpoints[i]);
291 : HLTDebug("associating unused cluster %08x with track %d", trackpoints[i], GetTrackId());
292 0 : }
293 0 : count++;
294 0 : }
295 : return count;
296 0 : }
297 :
298 : int AliHLTTrackGeometry::AssociateUnusedSpacePoints(AliHLTSpacePointContainer& points)
299 : {
300 : /// associate the track space points to the calculated track points
301 : int count=0;
302 0 : for (vector<AliHLTUInt32_t>::iterator mask=fSelectionMasks.begin();
303 0 : mask!=fSelectionMasks.end(); mask++) {
304 : int subcount=0;
305 0 : const vector<AliHLTUInt32_t>* selectedPoints=points.GetClusterIDs(*mask);
306 0 : if (!selectedPoints) {
307 0 : HLTWarning("space point collection does not contain data for mask 0x%08x", *mask);
308 0 : continue;
309 : }
310 0 : for (vector<AliHLTUInt32_t>::const_iterator id=selectedPoints->begin();
311 0 : id!=selectedPoints->end(); id++) {
312 0 : if (points.GetTrackID(*id)>=0) continue;
313 0 : float xyz[3]={points.GetX(*id), points.GetY(*id), points.GetZ(*id)};
314 0 : AliHLTUInt32_t planeId=0;
315 0 : int result=FindMatchingTrackPoint(*id, xyz, planeId);
316 0 : if (result<0) {
317 : //HLTWarning("no associated track point found for space point id %08x x=%f y=%f z=%f", *id, xyz[0], xyz[1], xyz[2]);
318 0 : continue;
319 0 : } else if (result==0) {
320 : //HLTWarning("associated track point for space pointid %08x x=%f y=%f z=%f occupied", *id, xyz[0], xyz[1], xyz[2]);
321 0 : continue;
322 : }
323 0 : SetAssociatedSpacePoint(planeId, *id, 1);
324 0 : if (points.GetTrackID(*id)<0 && GetTrackId()>=0) {
325 0 : points.SetTrackID(GetTrackId(), *id);
326 : HLTDebug("associating unused cluster %08x with track %d", *id, GetTrackId());
327 0 : }
328 0 : subcount++;
329 0 : }
330 0 : if (fVerbosity>0) {
331 0 : HLTInfo("associated %d of %d spacepoint(s) from selection 0x%08x to track %d",
332 : subcount, selectedPoints->size(), *mask, GetTrackId());
333 : }
334 0 : count+=subcount;
335 0 : }
336 0 : return count;
337 : }
338 :
339 : int AliHLTTrackGeometry::FillResidual(int coordinate, TH2* histo) const
340 : {
341 : // fill residual histogram
342 0 : const vector<AliHLTTrackPoint>& trackPoints=TrackPoints();
343 0 : for (vector<AliHLTTrackPoint>::const_iterator trackpoint=trackPoints.begin();
344 0 : trackpoint!=trackPoints.end(); trackpoint++) {
345 0 : if (!trackpoint->HaveAssociatedSpacePoint()) continue;
346 0 : for (vector<AliHLTTrackSpacepoint>::const_iterator sp=(trackpoint->GetSpacepoints()).begin();
347 0 : sp!=(trackpoint->GetSpacepoints()).end(); sp++) {
348 0 : histo->Fill(GetPlaneR(trackpoint->GetId()), sp->GetResidual(coordinate));
349 : }
350 0 : }
351 0 : return 0;
352 : }
353 :
354 : ostream& operator<<(ostream &out, const AliHLTTrackGeometry& p)
355 : {
356 0 : p.Print(out);
357 0 : return out;
358 : }
|