3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project *
5 //* ALICE Experiment at CERN, All rights reserved. *
7 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 //* for The ALICE HLT Project. *
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 //**************************************************************************
19 /// @file AliHLTTrackGeometry.cxx
20 /// @author Matthias Richter
22 /// @brief Desciption of a track by a sequence of track points
25 #include "AliHLTTrackGeometry.h"
26 #include "AliHLTSpacePointContainer.h"
27 #include "TObjArray.h"
35 /** ROOT macro for the implementation of ROOT specific class methods */
36 ClassImp(AliHLTTrackGeometry)
38 AliHLTTrackGeometry::AliHLTTrackGeometry()
39 : TObject(), AliHLTLogging()
45 /// standard constructor
48 AliHLTTrackGeometry::AliHLTTrackGeometry(const AliHLTTrackGeometry& src)
49 : TObject(src), AliHLTLogging()
50 , fTrackPoints(src.fTrackPoints)
51 , fSelectionMasks(src.fSelectionMasks)
52 , fTrackId(src.fTrackId)
53 , fVerbosity(src.fVerbosity)
58 AliHLTTrackGeometry& AliHLTTrackGeometry::operator=(const AliHLTTrackGeometry& src)
60 /// assignment operator
62 fTrackPoints.assign(src.fTrackPoints.begin(), src.fTrackPoints.end());
63 fSelectionMasks.assign(src.fSelectionMasks.begin(), src.fSelectionMasks.end());
64 fTrackId=src.fTrackId;
65 fVerbosity=src.fVerbosity;
70 AliHLTTrackGeometry::~AliHLTTrackGeometry()
75 int AliHLTTrackGeometry::AddTrackPoint(const AliHLTTrackPoint& point, AliHLTUInt32_t selectionMask)
77 /// add a track point to the list
78 vector<AliHLTTrackPoint>::const_iterator element = find(fTrackPoints.begin(), fTrackPoints.end(), point);
79 if (element==fTrackPoints.end()) {
80 fTrackPoints.push_back(point);
81 if (std::find(fSelectionMasks.begin(), fSelectionMasks.end(), selectionMask)==fSelectionMasks.end()) {
82 fSelectionMasks.push_back(selectionMask);
85 HLTError("track point of id %08x already existing", point.GetId());
91 void AliHLTTrackGeometry::Clear(Option_t * /*option*/)
96 void AliHLTTrackGeometry::Print(Option_t *option) const
102 void AliHLTTrackGeometry::Print(ostream& out, Option_t */*option*/) const
105 out << "AliHLTTrackGeometry::Print" << endl;
108 void AliHLTTrackGeometry::Draw(Option_t *option)
110 /// Inherited from TObject, draw the track
112 float center[2]={0.5,0.5};
117 TString strOption(option);
118 std::auto_ptr<TObjArray> tokens(strOption.Tokenize(" "));
119 if (!tokens.get()) return;
120 for (int i=0; i<tokens->GetEntriesFast(); i++) {
121 if (!tokens->At(i)) continue;
123 TString arg=tokens->At(i)->GetName();
126 if (arg.BeginsWith(key)) {
127 arg.ReplaceAll(key, "");
132 if (arg.BeginsWith(key)) {
133 arg.ReplaceAll(key, "");
134 center[0]=arg.Atof();
138 if (arg.BeginsWith(key)) {
139 arg.ReplaceAll(key, "");
140 center[1]=arg.Atof();
145 if (arg.BeginsWith(key)) {
146 arg.ReplaceAll(key, "");
147 markerColor=arg.Atoi();
152 if (arg.BeginsWith(key)) {
153 arg.ReplaceAll(key, "");
154 markerSize=arg.Atoi();
159 if (arg.BeginsWith(key)) {
160 arg.ReplaceAll(key, "");
161 verbosity=arg.Atoi();
166 bool bFirstPoint=true;
167 float firstalpha=0.0;
168 for (vector<AliHLTTrackPoint>::const_iterator point=fTrackPoints.begin();
169 point!=fTrackPoints.end();
171 float alpha=GetPlaneAlpha(point->GetId());
172 float r=GetPlaneR(point->GetId());
173 float cosa=TMath::Cos(alpha);
174 float sina=TMath::Sin(alpha);
175 float x = r*sina + point->GetU()*cosa;
176 float y =-r*cosa + point->GetU()*sina;
178 HLTInfo("ID 0x%08x: x=% .4f y=% .4f alpha=% .4f", point->GetId(), r, point->GetU(), alpha);
180 int color=markerColor;
183 TMarker* m=new TMarker(x/(2*scale)+center[0], y/(2*scale)+center[1], 29);
185 m->SetMarkerColor(2);
189 color+=int(9*TMath::Abs(alpha-firstalpha)/TMath::Pi());
191 TMarker* m=new TMarker(x/(2*scale)+center[0], y/(2*scale)+center[1], point->GetV()>0?2:5);
192 m->SetMarkerColor(color);
193 m->SetMarkerSize(markerSize);
198 int AliHLTTrackGeometry::SetAssociatedSpacePoint(UInt_t planeId, UInt_t spacepointId, int status, float fdU, float fdV)
200 /// set the spacepoint associated with a track point
201 vector<AliHLTTrackPoint>::iterator element = find(fTrackPoints.begin(), fTrackPoints.end(), planeId);
202 if (element==fTrackPoints.end()) return -ENOENT;
203 element->SetAssociatedSpacePoint(spacepointId, status);
204 element->SetResidual(0, fdU);
205 element->SetResidual(1, fdV);
209 int AliHLTTrackGeometry::GetAssociatedSpacePoint(UInt_t planeId, UInt_t& spacepointId) const
211 /// get the spacepoint associated with a track point
212 /// return status flag if found, -ENOENT if no associated spacepoint found
213 vector<AliHLTTrackPoint>::const_iterator element = find(fTrackPoints.begin(), fTrackPoints.end(), planeId);
214 if (element==fTrackPoints.end()) return -ENOENT;
215 if (!element->HaveAssociatedSpacePoint()) return -ENODATA;
216 return element->GetAssociatedSpacePoint(spacepointId);
219 const AliHLTTrackGeometry::AliHLTTrackPoint* AliHLTTrackGeometry::GetTrackPoint(AliHLTUInt32_t id) const
221 /// get const pointer to track point
222 vector<AliHLTTrackPoint>::const_iterator element = find(fTrackPoints.begin(), fTrackPoints.end(), id);
223 if (element==fTrackPoints.end()) return NULL;
227 AliHLTTrackGeometry::AliHLTTrackPoint* AliHLTTrackGeometry::GetTrackPoint(AliHLTUInt32_t id)
229 /// get const pointer to track point
230 vector<AliHLTTrackPoint>::iterator element = find(fTrackPoints.begin(), fTrackPoints.end(), id);
231 if (element==fTrackPoints.end()) return NULL;
235 AliHLTSpacePointContainer* AliHLTTrackGeometry::ConvertToSpacePoints(bool /*bAssociated*/) const
237 /// create a collection of all points
238 HLTError("implementation of child method missing");
242 int AliHLTTrackGeometry::AssociateSpacePoints(AliHLTSpacePointContainer& points)
244 /// associate the track space points to the calculated track points
245 vector<AliHLTUInt32_t> ids;
246 points.GetClusterIDs(ids);
247 if (ids.size()>0) return 0;
248 int result=AssociateSpacePoints(&ids[0], ids.size(), points);
250 HLTInfo("associated %d of %d space point(s) to track points", result, ids.size());
255 int AliHLTTrackGeometry::AssociateSpacePoints(const AliHLTUInt32_t* trackpoints, AliHLTUInt32_t nofPoints, AliHLTSpacePointContainer& points)
257 /// associate the track space points to the calculated track points
258 if (nofPoints==0) return 0;
259 if (trackpoints==NULL) return -EINVAL;
261 for (int i=nofPoints-1; i>=0; i--) {
262 if (!points.Check(trackpoints[i])) {
263 HLTWarning("can not find point id %08x", trackpoints[i]);
266 float xyz[3]={points.GetX(trackpoints[i]), points.GetY(trackpoints[i]), points.GetZ(trackpoints[i])};
267 AliHLTUInt32_t planeId=0;
268 int result=FindMatchingTrackPoint(trackpoints[i], xyz, planeId);
270 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]);
272 } else if (result==0) {
273 HLTWarning("associated track point for space pointid %08x x=%f y=%f z=%f occupied", trackpoints[i], xyz[0], xyz[1], xyz[2]);
276 vector<AliHLTTrackPoint>::const_iterator element = find(fTrackPoints.begin(), fTrackPoints.end(), planeId);
277 SetAssociatedSpacePoint(planeId, trackpoints[i], 1, xyz[1]-element->GetU(), xyz[2]-element->GetV());
278 if (points.GetTrackID(trackpoints[i])<0 && GetTrackId()>=0) {
279 points.SetTrackID(GetTrackId(), trackpoints[i]);
280 HLTDebug("associating unused cluster %08x with track %d", trackpoints[i], GetTrackId());
287 int AliHLTTrackGeometry::AssociateUnusedSpacePoints(AliHLTSpacePointContainer& points)
289 /// associate the track space points to the calculated track points
291 for (vector<AliHLTUInt32_t>::iterator mask=fSelectionMasks.begin();
292 mask!=fSelectionMasks.end(); mask++) {
294 const vector<AliHLTUInt32_t>* selectedPoints=points.GetClusterIDs(*mask);
295 if (!selectedPoints) {
296 HLTWarning("space point collection does not contain data for mask 0x%08x", *mask);
299 for (vector<AliHLTUInt32_t>::const_iterator id=selectedPoints->begin();
300 id!=selectedPoints->end(); id++) {
301 if (points.GetTrackID(*id)>=0) continue;
302 float xyz[3]={points.GetX(*id), points.GetY(*id), points.GetZ(*id)};
303 AliHLTUInt32_t planeId=0;
304 int result=FindMatchingTrackPoint(*id, xyz, planeId);
306 //HLTWarning("no associated track point found for space point id %08x x=%f y=%f z=%f", *id, xyz[0], xyz[1], xyz[2]);
308 } else if (result==0) {
309 //HLTWarning("associated track point for space pointid %08x x=%f y=%f z=%f occupied", *id, xyz[0], xyz[1], xyz[2]);
312 SetAssociatedSpacePoint(planeId, *id, 1);
313 if (points.GetTrackID(*id)<0 && GetTrackId()>=0) {
314 points.SetTrackID(GetTrackId(), *id);
315 HLTDebug("associating unused cluster %08x with track %d", *id, GetTrackId());
320 HLTInfo("associated %d of %d spacepoint(s) from selection 0x%08x to track %d",
321 subcount, selectedPoints->size(), *mask, GetTrackId());
328 int AliHLTTrackGeometry::FillResidual(int coordinate, TH2* histo) const
330 // fill residual histogram
331 const vector<AliHLTTrackPoint>& trackPoints=TrackPoints();
332 for (vector<AliHLTTrackPoint>::const_iterator trackpoint=trackPoints.begin();
333 trackpoint!=trackPoints.end(); trackpoint++) {
334 if (!trackpoint->HaveAssociatedSpacePoint()) continue;
335 histo->Fill(GetPlaneR(trackpoint->GetId()), trackpoint->GetResidual(coordinate));
340 ostream& operator<<(ostream &out, const AliHLTTrackGeometry& p)