]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/AliHLTTPCRawSpacePointContainer.cxx
added handling class for raw space points
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCRawSpacePointContainer.cxx
CommitLineData
71510a33 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 AliHLTTPCRawSpacePointContainer.h
20/// @author Matthias Richter
21/// @date 2011-04-29
22/// @brief Helper class for handling of HLT TPC space point data blocks
23///
24
25#include "AliHLTTPCRawSpacePointContainer.h"
26#include "AliHLTTPCRawCluster.h"
27#include "AliHLTTPCDefinitions.h"
28#include "AliHLTTPCSpacePointData.h"
29#include "AliHLTTPCTransform.h"
30#include "AliHLTComponent.h"
31#include "AliHLTTemplates.h"
32#include "TMath.h"
33#include <memory>
34#include <algorithm>
35
36/** ROOT macro for the implementation of ROOT specific class methods */
37ClassImp(AliHLTTPCRawSpacePointContainer)
38
39AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointContainer()
40 : AliHLTSpacePointContainer()
41 , fClusters()
42 , fSelections()
43{
44 // see header file for class documentation
45 // or
46 // refer to README to build package
47 // or
48 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
49}
50
51AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointContainer(const AliHLTTPCRawSpacePointContainer& c)
52 : AliHLTSpacePointContainer(c)
53 , fClusters(c.fClusters.begin(), c.fClusters.end())
54 , fSelections()
55{
56 /// copy constructor
57}
58
59AliHLTTPCRawSpacePointContainer& AliHLTTPCRawSpacePointContainer::operator=(const AliHLTTPCRawSpacePointContainer& c)
60{
61 /// assignment operator
62 if (&c==this) return *this;
63 AliHLTSpacePointContainer::operator=(c);
64 fClusters=c.fClusters;
65
66 return *this;
67}
68
69AliHLTTPCRawSpacePointContainer::~AliHLTTPCRawSpacePointContainer()
70{
71 // destructor
72
73 for (std::map<AliHLTUInt32_t, vector<AliHLTUInt32_t>*>::iterator selection=fSelections.begin();
74 selection!=fSelections.end(); selection++) {
75 if (selection->second) delete selection->second;
76 }
77}
78
79int AliHLTTPCRawSpacePointContainer::AddInputBlock(const AliHLTComponentBlockData* pDesc)
80{
81 // add input block to the collection
82 if (!pDesc) return -EINVAL;
83 int count=0;
84 if (pDesc->fDataType!=AliHLTTPCDefinitions::fgkRawClustersDataType) {
85 HLTWarning("ignoring data block of type %s", AliHLTComponent::DataType2Text(pDesc->fDataType).c_str());
86 return 0;
87 }
88 if (!pDesc->fPtr || pDesc->fSize<sizeof(AliHLTTPCRawClusterData)) return -ENODATA;
89
90 // consistency check of the input block
91 const AliHLTTPCRawClusterData* pClusterData=reinterpret_cast<AliHLTTPCRawClusterData*>(pDesc->fPtr);
92 if (pClusterData->fCount*sizeof(AliHLTTPCRawCluster)+sizeof(AliHLTTPCRawClusterData)!=pDesc->fSize) {
93 HLTError("data block of type %s corrupted: number of entries %d is not consistent with block size %d",
94 AliHLTComponent::DataType2Text(pDesc->fDataType).c_str(), pClusterData->fCount, pDesc->fSize);
95 return -EBADMSG;
96 }
97
98 AliHLTUInt8_t minslice = AliHLTTPCDefinitions::GetMinSliceNr( pDesc->fSpecification );
99 //AliHLTUInt8_t maxslice = AliHLTTPCDefinitions::GetMaxSliceNr( pDesc->fSpecification );
100 AliHLTUInt8_t minpart = AliHLTTPCDefinitions::GetMinPatchNr( pDesc->fSpecification );
101 //AliHLTUInt8_t maxpart = AliHLTTPCDefinitions::GetMaxPatchNr( pDesc->fSpecification );
102 //bool bIsSinglePartition=(pDesc->fSpecification==kAliHLTVoidDataSpec?false:minslice==maxslice && minpart==maxpart);
103
104 for (UInt_t i=0; i<pClusterData->fCount; i++) {
105 AliHLTUInt32_t clusterID=~(AliHLTUInt32_t)0;
106 // cluster ID from slice, partition and index
107 clusterID=AliHLTTPCSpacePointData::GetID(minslice, minpart, i);
108
109 if (fClusters.find(clusterID)==fClusters.end()) {
110 // new cluster
111 fClusters[clusterID]=AliHLTTPCRawSpacePointProperties(&pClusterData->fClusters[i]);
112 count++;
113 } else {
114 HLTError("cluster with ID 0x%08x already existing, skipping cluster %d of data block 0x%08x",
115 clusterID, i, pDesc->fSpecification);
116 }
117 }
118
119 return count;
120}
121
122int AliHLTTPCRawSpacePointContainer::GetClusterIDs(vector<AliHLTUInt32_t>& tgt) const
123{
124 // get array of cluster IDs
125 tgt.clear();
126 transform(fClusters.begin(), fClusters.end(), back_inserter(tgt), HLT::AliGetKey());
127 return tgt.size();
128}
129
130bool AliHLTTPCRawSpacePointContainer::Check(AliHLTUInt32_t clusterID) const
131{
132 // check if the cluster is available
133 return fClusters.find(clusterID)!=fClusters.end();
134}
135
136const vector<AliHLTUInt32_t>* AliHLTTPCRawSpacePointContainer::GetClusterIDs(AliHLTUInt32_t mask)
137{
138 // get array of cluster IDs filtered by mask
139 if (fSelections.find(mask)!=fSelections.end()) {
140 // return existing selection
141 return fSelections.find(mask)->second;
142 }
143 // create new collection
144 vector<AliHLTUInt32_t>* selected=new vector<AliHLTUInt32_t>;
145 if (!selected) return NULL;
146 UInt_t slice=AliHLTTPCSpacePointData::GetSlice(mask);
147 UInt_t partition=AliHLTTPCSpacePointData::GetPatch(mask);
148 HLTInfo("creating collection 0x%08x", mask);
149 for (std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointProperties>::const_iterator cl=fClusters.begin();
150 cl!=fClusters.end(); cl++) {
151 UInt_t s=AliHLTTPCSpacePointData::GetSlice(cl->first);
152 UInt_t p=AliHLTTPCSpacePointData::GetPatch(cl->first);
153 if ((slice>=(unsigned)AliHLTTPCTransform::GetNSlice() || s==slice) &&
154 (partition>=(unsigned)AliHLTTPCTransform::GetNumberOfPatches() || p==partition)) {
155 selected->push_back(cl->first);
156 }
157 }
158 HLTInfo("collection 0x%08x with %d spacepoints", mask, selected->size());
159 fSelections[mask]=selected;
160 return selected;
161}
162
163float AliHLTTPCRawSpacePointContainer::GetX(AliHLTUInt32_t clusterID) const
164{
165 // get X coordinate
166 if (fClusters.find(clusterID)==fClusters.end() ||
167 fClusters.find(clusterID)->second.Data()==NULL) return 0.0;
168 // FIXME: understand deviation from the nominal x value
169 // there is a small deviation in the x coordinate - padrow number correlation
170 // in principle, the clusterfinder only uses the mapping to set the x parameter.
171 // now extracting the x value from the padrow no.
172 //return fClusters.find(clusterID)->second.Data()->fX;
173 return AliHLTTPCTransform::Row2X(fClusters.find(clusterID)->second.Data()->fPadRow);
174}
175
176float AliHLTTPCRawSpacePointContainer::GetXWidth(AliHLTUInt32_t clusterID) const
177{
178 // get error for X coordinate
179 if (fClusters.find(clusterID)==fClusters.end() ||
180 fClusters.find(clusterID)->second.Data()==NULL) return 0.0;
181 return 0.0; // fixed in padrow number
182}
183
184float AliHLTTPCRawSpacePointContainer::GetY(AliHLTUInt32_t clusterID) const
185{
186 // get Y coordinate
187 if (fClusters.find(clusterID)==fClusters.end() ||
188 fClusters.find(clusterID)->second.Data()==NULL) return 0.0;
189 return fClusters.find(clusterID)->second.Data()->GetPad();
190}
191
192float AliHLTTPCRawSpacePointContainer::GetYWidth(AliHLTUInt32_t clusterID) const
193{
194 // get error for Y coordinate
195 if (fClusters.find(clusterID)==fClusters.end() ||
196 fClusters.find(clusterID)->second.Data()==NULL) return 0.0;
197 return fClusters.find(clusterID)->second.Data()->GetSigmaY2();
198}
199
200float AliHLTTPCRawSpacePointContainer::GetZ(AliHLTUInt32_t clusterID) const
201{
202 // get Z coordinate
203 if (fClusters.find(clusterID)==fClusters.end() ||
204 fClusters.find(clusterID)->second.Data()==NULL) return 0.0;
205 return fClusters.find(clusterID)->second.Data()->GetTime();
206}
207
208float AliHLTTPCRawSpacePointContainer::GetZWidth(AliHLTUInt32_t clusterID) const
209{
210 // get error for Z coordinate
211 if (fClusters.find(clusterID)==fClusters.end() ||
212 fClusters.find(clusterID)->second.Data()==NULL) return 0.0;
213 return fClusters.find(clusterID)->second.Data()->GetSigmaZ2();
214}
215
216float AliHLTTPCRawSpacePointContainer::GetCharge(AliHLTUInt32_t clusterID) const
217{
218 // get charge
219 if (fClusters.find(clusterID)==fClusters.end() ||
220 fClusters.find(clusterID)->second.Data()==NULL) return 0.0;
221 return fClusters.find(clusterID)->second.Data()->GetCharge();
222}
223
224float AliHLTTPCRawSpacePointContainer::GetPhi(AliHLTUInt32_t clusterID) const
225{
226 // get charge
227
228 // phi can be derived directly from the id, no need to search
229 // for existing cluster
230 int slice=AliHLTTPCSpacePointData::GetSlice(clusterID);
231 return ( slice + 0.5 ) * TMath::Pi() / 9.0;
232}
233
234void AliHLTTPCRawSpacePointContainer::Clear(Option_t * /*option*/)
235{
236 // clear the object and reset pointer references
237}
238
239void AliHLTTPCRawSpacePointContainer::Print(ostream& out, Option_t */*option*/) const
240{
241 // print to stream
242 out << "AliHLTTPCRawSpacePointContainer::Print" << endl;
243 out << "n clusters: " << fClusters.size() << endl;
244 for (std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointProperties>::const_iterator cl=fClusters.begin();
245 cl!=fClusters.end(); cl++) {
246 out << " " << cl->first << cl->second << endl;
247 }
248}
249
250AliHLTSpacePointContainer* AliHLTTPCRawSpacePointContainer::SelectByMask(AliHLTUInt32_t mask, bool /*bAlloc*/) const
251{
252 /// create a collection of clusters for a space point mask
253 std::auto_ptr<AliHLTTPCRawSpacePointContainer> c(new AliHLTTPCRawSpacePointContainer);
254 if (!c.get()) return NULL;
255
256 UInt_t slice=AliHLTTPCSpacePointData::GetSlice(mask);
257 UInt_t partition=AliHLTTPCSpacePointData::GetPatch(mask);
258 for (std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointProperties>::const_iterator cl=fClusters.begin();
259 cl!=fClusters.end(); cl++) {
260 UInt_t s=AliHLTTPCSpacePointData::GetSlice(cl->first);
261 UInt_t p=AliHLTTPCSpacePointData::GetPatch(cl->first);
262 if ((slice>=(unsigned)AliHLTTPCTransform::GetNSlice() || s==slice) &&
263 (partition>=(unsigned)AliHLTTPCTransform::GetNumberOfPatches() || p==partition)) {
264 c->fClusters[cl->first]=cl->second;
265 }
266 }
267 return c.release();
268}
269
270AliHLTSpacePointContainer* AliHLTTPCRawSpacePointContainer::SelectByTrack(int trackId, bool /*bAlloc*/) const
271{
272 /// create a collection of clusters for a specific track
273 std::auto_ptr<AliHLTTPCRawSpacePointContainer> c(new AliHLTTPCRawSpacePointContainer);
274 if (!c.get()) return NULL;
275
276 HLT::copy_map_if(fClusters.begin(), fClusters.end(), c->fClusters, HLT::AliHLTUnaryPredicate<AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties, int>(&AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties::GetTrackId,trackId));
277 return c.release();
278}
279
280AliHLTSpacePointContainer* AliHLTTPCRawSpacePointContainer::SelectByMC(int mcId, bool /*bAlloc*/) const
281{
282 /// create a collection of clusters for a specific MC track
283 std::auto_ptr<AliHLTTPCRawSpacePointContainer> c(new AliHLTTPCRawSpacePointContainer);
284 if (!c.get()) return NULL;
285
286 HLT::copy_map_if(fClusters.begin(), fClusters.end(), c->fClusters, HLT::AliHLTUnaryPredicate<AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties, int>(&AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties::GetMCId,mcId));
287 return c.release();
288}
289
290AliHLTSpacePointContainer* AliHLTTPCRawSpacePointContainer::UsedClusters(bool /*bAlloc*/) const
291{
292 /// create a collection of all used clusters
293 std::auto_ptr<AliHLTTPCRawSpacePointContainer> c(new AliHLTTPCRawSpacePointContainer);
294 if (!c.get()) return NULL;
295
296 HLT::copy_map_if(fClusters.begin(), fClusters.end(), c->fClusters, HLT::AliHLTUnaryPredicate<AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties, bool>(&AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties::IsUsed,true));
297 return c.release();
298}
299
300AliHLTSpacePointContainer* AliHLTTPCRawSpacePointContainer::UnusedClusters(bool /*bAlloc*/) const
301{
302 /// create a collection of all unused clusters
303 std::auto_ptr<AliHLTTPCRawSpacePointContainer> c(new AliHLTTPCRawSpacePointContainer);
304 if (!c.get()) return NULL;
305
306 HLT::copy_map_if(fClusters.begin(), fClusters.end(), c->fClusters, HLT::AliHLTUnaryPredicate<AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties, bool>(&AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties::IsUsed,false));
307 return c.release();
308}
309
310int AliHLTTPCRawSpacePointContainer::MarkUsed(const AliHLTUInt32_t* clusterIDs, int arraySize)
311{
312 /// mark the clusters with specified IDs as used
313 if (!clusterIDs) return -EINVAL;
314 int iCount=0;
315 for (int i=0; i<arraySize; i++) {
316 if (fClusters.find(clusterIDs[i])==fClusters.end()) continue;
317 fClusters[clusterIDs[i]].MarkUsed();
318 iCount++;
319 }
320 return iCount;
321}
322
323int AliHLTTPCRawSpacePointContainer::SetTrackID(int trackID, const AliHLTUInt32_t* clusterIDs, int arraySize)
324{
325 /// set track id for specified clusters
326 if (!clusterIDs) return -EINVAL;
327 int iCount=0;
328 for (int i=0; i<arraySize; i++) {
329 if (fClusters.find(clusterIDs[i])==fClusters.end()) continue;
330 fClusters[clusterIDs[i]].SetTrackId(trackID);
331 iCount++;
332 }
333 return iCount;
334}
335
336int AliHLTTPCRawSpacePointContainer::GetTrackID(AliHLTUInt32_t clusterID) const
337{
338 /// get track id for specified cluster
339 map<AliHLTUInt32_t, AliHLTTPCRawSpacePointProperties>::const_iterator element=fClusters.find(clusterID);
340 if (element==fClusters.end()) return -1;
341 return element->second.GetTrackId();
342}
343
344int AliHLTTPCRawSpacePointContainer::SetMCID(int mcID, const AliHLTUInt32_t* clusterIDs, int arraySize)
345{
346 /// set mc id for specified clusters
347 if (!clusterIDs) return -EINVAL;
348 int iCount=0;
349 for (int i=0; i<arraySize; i++) {
350 if (fClusters.find(clusterIDs[i])==fClusters.end()) continue;
351 fClusters[clusterIDs[i]].SetMCId(mcID);
352 iCount++;
353 }
354 return iCount;
355}
356
357AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties::AliHLTTPCRawSpacePointProperties()
358 : fCluster(NULL)
359 , fUsed(false)
360 , fTrackId(-1)
361 , fMCId(-1)
362{
363 // constructor
364}
365
366AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties::AliHLTTPCRawSpacePointProperties(const AliHLTTPCRawCluster* pCluster)
367 : fCluster(pCluster)
368 , fUsed(false)
369 , fTrackId(-1)
370 , fMCId(-1)
371{
372 // constructor
373}
374
375AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties::AliHLTTPCRawSpacePointProperties(const AliHLTTPCRawSpacePointProperties& src)
376 : fCluster(src.fCluster)
377 , fUsed(src.fUsed)
378 , fTrackId(src.fTrackId)
379 , fMCId(src.fMCId)
380{
381 // copy constructor
382}
383
384AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties& AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties::operator=(const AliHLTTPCRawSpacePointProperties& src)
385{
386 // assignment operator
387 if (&src==this) return *this;
388 fCluster=src.fCluster;
389 fUsed=src.fUsed;
390 fTrackId=src.fTrackId;
391 fMCId=src.fMCId;
392
393 return *this;
394}
395
396void AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties::Print(ostream& out, Option_t */*option*/) const
397{
398 // print info
399 if (!Data()) {
400 out << "no data";
401 return;
402 }
403 const AliHLTTPCRawCluster* data=Data();
404 out << " " << data->GetPadRow() << " " << data->GetPad() << " " << data->GetTime()
405 << " " << fTrackId << " " << fMCId << " " << fUsed;
406}
407
408ostream& operator<<(ostream &out, const AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties& p)
409{
410 p.Print(out);
411 return out;
412}