]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/AliHLTTPCTrackGeometry.cxx
added setters and getters for data members
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCTrackGeometry.cxx
CommitLineData
c7585a2a 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 AliHLTTPCTrackGeometry.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 "AliHLTTPCTrackGeometry.h"
26#include "AliHLTTPCTransform.h"
27#include "AliHLTTPCSpacePointData.h"
eb50ad6b 28#include "AliHLTTPCClusterDataFormat.h"
29#include "AliHLTTPCSpacePointContainer.h"
30#include "AliHLTTPCDefinitions.h"
31#include "AliHLTComponent.h"
c7585a2a 32#include "AliHLTGlobalBarrelTrack.h"
33#include "TMath.h"
eb50ad6b 34#include <memory>
c7585a2a 35
36/** ROOT macro for the implementation of ROOT specific class methods */
37ClassImp(AliHLTTPCTrackGeometry)
38
39AliHLTTPCTrackGeometry::AliHLTTPCTrackGeometry()
40 : AliHLTTrackGeometry()
41{
42 /// standard constructor
43}
44
45AliHLTTPCTrackGeometry::AliHLTTPCTrackGeometry(const AliHLTTPCTrackGeometry& src)
46 : AliHLTTrackGeometry(src)
47{
48 /// copy constructor
49}
50
51AliHLTTPCTrackGeometry& AliHLTTPCTrackGeometry::operator=(const AliHLTTPCTrackGeometry& src)
52{
53 /// assignment operator
54 AliHLTTrackGeometry::operator=(src);
55 return *this;
56}
57
58AliHLTTPCTrackGeometry::~AliHLTTPCTrackGeometry()
59{
60 /// destructor
61}
62
63float AliHLTTPCTrackGeometry::GetPlaneAlpha(AliHLTUInt32_t planeId) const
64{
65 /// alpha of the plane
66 UInt_t slice=AliHLTTPCSpacePointData::GetSlice(planeId);
67 float alpha=( slice + 0.5 ) * TMath::Pi() / 9.0;
68 if (alpha>TMath::TwoPi()) alpha-=TMath::TwoPi();
69 return alpha;
70}
71
72float AliHLTTPCTrackGeometry::GetPlaneR(AliHLTUInt32_t planeId) const
73{
74 /// radial distance from global {0,0,0}
75 UInt_t partition=AliHLTTPCSpacePointData::GetPatch(planeId);
76 UInt_t number=AliHLTTPCSpacePointData::GetNumber(planeId);
77 Int_t row=AliHLTTPCTransform::GetFirstRow(partition)+number;
78 return AliHLTTPCTransform::Row2X(row);
79}
80
81float AliHLTTPCTrackGeometry::GetPlaneTheta(AliHLTUInt32_t /*planeId*/) const
82{
83 /// theta of the plane
84 return 0.0;
85}
86
87bool AliHLTTPCTrackGeometry::CheckBounds(AliHLTUInt32_t planeId, float u, float /*v*/) const
88{
89 /// check bounds in u and v coordinate
90 float r=GetPlaneR(planeId);
91 if (r<AliHLTTPCTransform::GetFirstRow(0)) return false;
92
93 // TODO: check if the pad width needs to be considered here
94 return TMath::Abs(TMath::ASin(u/r))<=TMath::Pi()/18;
95}
96
97int AliHLTTPCTrackGeometry::CalculateTrackPoints(const AliHLTExternalTrackParam& track)
98{
99 /// calculate the track points, expects the global magnetic field to be initialized
100 AliHLTGlobalBarrelTrack bt(track);
101 return CalculateTrackPoints(bt);
102}
103
104int AliHLTTPCTrackGeometry::CalculateTrackPoints(AliHLTGlobalBarrelTrack& track)
105{
106 /// calculate the track points, expects the global magnetic field to be initialized
107 int iResult=0;
108 int firstpadrow=0;
eb50ad6b 109 for (;
110 firstpadrow<AliHLTTPCTransform::GetNRows() &&
111 AliHLTTPCTransform::Row2X(firstpadrow)+AliHLTTPCTransform::GetPadLength(firstpadrow)<track.GetX();
112 firstpadrow++);
113 if (firstpadrow>=AliHLTTPCTransform::GetNRows()) return 0;
c7585a2a 114 iResult=CalculateTrackPoints(track, firstpadrow, 1);
115 if (iResult>=0 && firstpadrow>0)
116 iResult=CalculateTrackPoints(track, firstpadrow-1, -1);
117 return iResult;
118}
119
120int AliHLTTPCTrackGeometry::CalculateTrackPoints(AliHLTGlobalBarrelTrack& track, int firstpadrow, int step)
121{
122 /// calculate the track points, expects the global magnetic field to be initialized
123 float offsetAlpha=0.0;
124 for (int padrow=firstpadrow; padrow>=0 && padrow<AliHLTTPCTransform::GetNRows(); padrow+=step) {
125 float x=AliHLTTPCTransform::Row2X(padrow);
126 float y=0.0;
127 float z=0.0;
128
129 int maxshift=9;
130 int shift=0;
131 int result=0;
132 do {
133 // start calculation of crossing points with padrow planes in the slice of the first point
134 // plane alpha corresponds to alpha of the track, switch to neighboring slice if the result
135 // is out of bounds
136 if ((result=track.CalculateCrossingPoint(x, track.GetAlpha()-offsetAlpha, y, z))<1) break;
137 float pointAlpha=TMath::ATan(y/x);
138 if (TMath::Abs(pointAlpha)>TMath::Pi()/18) {
139 offsetAlpha+=(pointAlpha>0?-1:1)*TMath::Pi()/9;
140 result=0;
141 }
142 } while (result==0 && shift++<maxshift);
143 if (result<1) continue;
144 float planealpha=track.GetAlpha()-offsetAlpha;
145 if (planealpha<0) planealpha+=TMath::TwoPi();
102d9fef 146 int slice=int(9*planealpha/TMath::Pi());
c7585a2a 147 //if (z<0) slice+=18;
148 int partition=AliHLTTPCTransform::GetPatch(padrow);
149 int row=padrow-AliHLTTPCTransform::GetFirstRow(partition);
150 UInt_t id=AliHLTTPCSpacePointData::GetID(slice, partition, row);
151 if (TMath::Abs(planealpha-GetPlaneAlpha(id))>0.0001) {
152 HLTError("alpha missmatch for plane %08x (slice %d): alpha from id %f (%.0f), expected %f (%.0f)", id, slice, GetPlaneAlpha(id), 180*GetPlaneAlpha(id)/TMath::Pi(), planealpha, 180*planealpha/TMath::Pi());
153 }
9003c201 154 AddTrackPoint(AliHLTTrackPoint(id, y, z), AliHLTTPCSpacePointData::GetID(slice, partition, 0));
c7585a2a 155 }
156 return 0;
157}
158
159int AliHLTTPCTrackGeometry::FindMatchingTrackPoint(AliHLTUInt32_t spacepointId, float spacepoint[3], AliHLTUInt32_t& planeId)
160{
161 /// find the track point which can be associated to a spacepoint with coordinates and id
162 UInt_t slice=AliHLTTPCSpacePointData::GetSlice(spacepointId);
163 UInt_t partition=AliHLTTPCSpacePointData::GetPatch(spacepointId);
164 int row=AliHLTTPCTransform::GetPadRow(spacepoint[0]);
9003c201 165 bool bSpecialRow=row==30 || row==90 || row==139;
c7585a2a 166 if (row<AliHLTTPCTransform::GetFirstRow(partition) || row>AliHLTTPCTransform::GetLastRow(partition)) {
167 HLTError("row number %d calculated from x value %f is outside slice %d partition %d", row, spacepoint[0], slice, partition);
168 return -EINVAL;
169 }
9003c201 170
171 // find the crossing point of the track with the padrow plane where
172 // the spacepoint is
173 // 1) calculate plane id from slice, partition and row (within partition)
c7585a2a 174 row-=AliHLTTPCTransform::GetFirstRow(partition);
175 UInt_t id=AliHLTTPCSpacePointData::GetID(slice, partition, row);
176 const AliHLTTrackPoint* point=GetTrackPoint(id);
9003c201 177 // track might be outside the partition and cross the central membrane
178 // search in the other half of the TPC
c7585a2a 179 if (!point && slice<18) {
9003c201 180 // search in the neighboring partition on the C side
c7585a2a 181 id=AliHLTTPCSpacePointData::GetID(slice+18, partition, row);
182 point=GetTrackPoint(id);
183 } else if (!point && slice>=18) {
9003c201 184 // search in the neighboring partition on the A side
c7585a2a 185 id=AliHLTTPCSpacePointData::GetID(slice-18, partition, row);
186 point=GetTrackPoint(id);
187 }
9003c201 188
189 // search in the neighboring partition, this takes account for rows
190 // 30, 90, and 139 which are partly in one and the other partition
191 if (!point && bSpecialRow) {
192 row+=AliHLTTPCTransform::GetFirstRow(partition);
193 row-=AliHLTTPCTransform::GetFirstRow(partition-1);
194 id=AliHLTTPCSpacePointData::GetID(slice, partition-1, row);
195 point=GetTrackPoint(id);
196 if (!point && slice<18) {
197 // search in the neighboring partition on the C side
198 id=AliHLTTPCSpacePointData::GetID(slice+18, partition-1, row);
199 point=GetTrackPoint(id);
200 } else if (!point && slice>=18) {
201 // search in the neighboring partition on the A side
202 id=AliHLTTPCSpacePointData::GetID(slice-18, partition-1, row);
203 point=GetTrackPoint(id);
204 }
205 }
206
c7585a2a 207 if (point) {
208 planeId=id;
9003c201 209 if (point->HaveAssociatedSpacePoint()) {
210 if (GetVerbosity()>2) HLTInfo("descarding spacepoint 0x%08x z=%f y=%f z=%f: track point 0x%08x already occupied", spacepoint[0], spacepoint[1], spacepoint[2], planeId);
211 return 0; // already occupied
212 }
213 float maxdy=2.;
214 float maxdz=2.;
215 if (TMath::Abs(point->GetU()-spacepoint[1])>maxdy) {
216 if (GetVerbosity()>0) HLTInfo("descarding spacepoint 0x%08x y=%f z=%f: track point 0x%08x y %f outside tolerance %f", spacepoint[1], spacepoint[2], planeId, point->GetU(), maxdy);
217 return -ENOENT;
218 }
219 if (TMath::Abs(point->GetV()-spacepoint[2])>maxdz) {
220 if (GetVerbosity()>0) HLTInfo("descarding spacepoint 0x%08x y=%f z=%f: track point 0x%08x z %f outside tolerance %f", spacepoint[1], spacepoint[2], planeId, point->GetV(), maxdz);
221 return -ENOENT;
222 }
c7585a2a 223 return 1;
224 }
225 return -ENOENT;
226}
eb50ad6b 227
9003c201 228AliHLTSpacePointContainer* AliHLTTPCTrackGeometry::ConvertToSpacePoints(bool bAssociated) const
eb50ad6b 229{
230 /// create a collection of all points
231 std::auto_ptr<AliHLTTPCSpacePointContainer> spacepoints(new AliHLTTPCSpacePointContainer);
232 if (!spacepoints.get()) return NULL;
233
dd2011bf 234 const vector<AliHLTTrackPoint>& trackPoints=TrackPoints();
eb50ad6b 235 unsigned i=0;
236 while (i<trackPoints.size()) {
237 // allocate buffer for all points, even though the buffer might not be filled
238 // completely because of a partition change
239 int nofPoints=trackPoints.size()-i;
240 int blocksize=sizeof(AliHLTTPCClusterData)+nofPoints*sizeof(AliHLTTPCSpacePointData);
241 AliHLTUInt8_t* pBuffer=spacepoints->Alloc(blocksize);
242 if (!pBuffer) return NULL;
243 AliHLTTPCClusterData* pClusterData=reinterpret_cast<AliHLTTPCClusterData*>(pBuffer);
244 pClusterData->fSpacePointCnt=0;
245 AliHLTTPCSpacePointData* pClusters=pClusterData->fSpacePoints;
246 int currentSlice=-1;
247 int currentPartition=-1;
248 for (; i<trackPoints.size(); i++) {
9003c201 249 if (bAssociated && !trackPoints[i].HaveAssociatedSpacePoint()) continue;
eb50ad6b 250 AliHLTUInt32_t planeId=trackPoints[i].GetId();
251 int slice=AliHLTTPCSpacePointData::GetSlice(planeId);
252 int partition=AliHLTTPCSpacePointData::GetPatch(planeId);
253 int number=AliHLTTPCSpacePointData::GetNumber(planeId);
254 if ((currentSlice>=0 && currentSlice!=slice) || (currentPartition>=0 && currentPartition!=partition)) {
255 // change of partition or slice, need to go to next block
256 // 2011-07-26 currently all spacepoints go into one block, if separated
257 // blocks per partition are needed one has to leave the inner loop here
258 // and set the data block specification below
259 // Caution: not tested, only the last block seems to make it through
260 //break;
261 }
262 currentSlice=slice;
263 currentPartition=partition;
264 pClusters[pClusterData->fSpacePointCnt].fX=GetPlaneR(planeId);
265 pClusters[pClusterData->fSpacePointCnt].fY=trackPoints[i].GetU();
266 pClusters[pClusterData->fSpacePointCnt].fZ=trackPoints[i].GetV();
267 pClusters[pClusterData->fSpacePointCnt].fID=planeId;
268 pClusters[pClusterData->fSpacePointCnt].fPadRow=AliHLTTPCTransform::GetFirstRow(partition)+number;
269 pClusters[pClusterData->fSpacePointCnt].fSigmaY2=0.;
270 pClusters[pClusterData->fSpacePointCnt].fSigmaZ2=0.;
271 pClusters[pClusterData->fSpacePointCnt].fCharge=0;
272 pClusters[pClusterData->fSpacePointCnt].fQMax=0;
273 pClusters[pClusterData->fSpacePointCnt].fUsed=0;
274 pClusters[pClusterData->fSpacePointCnt].fTrackN=0;
275 pClusterData->fSpacePointCnt++;
276 }
277 AliHLTComponentBlockData bd;
278 AliHLTComponent::FillBlockData(bd);
279 bd.fPtr=pBuffer;
9003c201 280 bd.fSize=sizeof(AliHLTTPCClusterData)+pClusterData->fSpacePointCnt*sizeof(AliHLTTPCSpacePointData);
eb50ad6b 281 AliHLTComponent::SetDataType(bd.fDataType, "CLUSTERS", "TPC ");
282 bd.fSpecification=//AliHLTTPCDefinitions::EncodeDataSpecification(currentSlice, currentSlice, currentPartition, currentPartition);
283 spacepoints->AddInputBlock(&bd);
284 }
285
286 return spacepoints.release();
287}