]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCSpacePointContainer.cxx
fixing typo
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCSpacePointContainer.cxx
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   AliHLTTPCSpacePointContainer.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 "AliHLTTPCSpacePointContainer.h"
26 #include "AliHLTTPCSpacePointData.h"
27 #include "AliHLTTPCDefinitions.h"
28 #include "AliHLTComponent.h"
29 #include "AliHLTTemplates.h"
30 #include "TMath.h"
31 #include <memory>
32 #include <algorithm>
33
34 /** ROOT macro for the implementation of ROOT specific class methods */
35 ClassImp(AliHLTTPCSpacePointContainer)
36
37 AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointContainer()
38   : AliHLTSpacePointContainer()
39   , fClusters()
40 {
41   // see header file for class documentation
42   // or
43   // refer to README to build package
44   // or
45   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
46 }
47
48 AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointContainer(const AliHLTTPCSpacePointContainer& c)
49   : AliHLTSpacePointContainer(c)
50   , fClusters(c.fClusters.begin(), c.fClusters.end())
51 {
52   /// copy constructor
53 }
54
55 AliHLTTPCSpacePointContainer& AliHLTTPCSpacePointContainer::operator=(const AliHLTTPCSpacePointContainer& c)
56 {
57   /// assignment operator
58   if (&c==this) return *this;
59   AliHLTSpacePointContainer::operator=(c);
60   fClusters=c.fClusters;
61
62   return *this;
63 }
64
65 AliHLTTPCSpacePointContainer::~AliHLTTPCSpacePointContainer()
66 {
67   // destructor
68 }
69
70 int AliHLTTPCSpacePointContainer::AddInputBlock(const AliHLTComponentBlockData* pDesc)
71 {
72   // add input block to the collection
73   if (!pDesc) return -EINVAL;
74   int count=0;
75   if (pDesc->fDataType!=AliHLTTPCDefinitions::fgkClustersDataType) {
76     HLTWarning("ignoring data block of type %s", AliHLTComponent::DataType2Text(pDesc->fDataType).c_str());
77     return 0;
78   }
79   if (!pDesc->fPtr || pDesc->fSize<sizeof(AliHLTTPCClusterData)) return -ENODATA;
80
81   // consistency check of the input block
82   const AliHLTTPCClusterData* pClusterData=reinterpret_cast<AliHLTTPCClusterData*>(pDesc->fPtr);
83   if (pClusterData->fSpacePointCnt*sizeof(AliHLTTPCSpacePointData)+sizeof(AliHLTTPCClusterData)!=pDesc->fSize) {
84     HLTError("data block of type %s corrupted: number of entries %d is not consistent with block size %d",
85              AliHLTComponent::DataType2Text(pDesc->fDataType).c_str(), pClusterData->fSpacePointCnt, pDesc->fSize);
86     return -EBADMSG;
87   }
88
89   AliHLTUInt8_t minslice = AliHLTTPCDefinitions::GetMinSliceNr( pDesc->fSpecification );
90   AliHLTUInt8_t maxslice = AliHLTTPCDefinitions::GetMaxSliceNr( pDesc->fSpecification );
91   AliHLTUInt8_t minpart  = AliHLTTPCDefinitions::GetMinPatchNr( pDesc->fSpecification );
92   AliHLTUInt8_t maxpart  = AliHLTTPCDefinitions::GetMaxPatchNr( pDesc->fSpecification );
93   bool bIsSinglePartition=(pDesc->fSpecification==kAliHLTVoidDataSpec?false:minslice==maxslice && minpart==maxpart);
94
95   for (UInt_t i=0; i<pClusterData->fSpacePointCnt; i++) {
96     AliHLTUInt32_t clusterID=~(AliHLTUInt32_t)0;
97     if (bIsSinglePartition) {
98       // cluster ID has to match ID encoded from slice, partition and index
99       clusterID=AliHLTTPCSpacePointData::GetID(minslice, minpart, i);
100       if (clusterID!=pClusterData->fSpacePoints[i].fID) {
101         HLTWarning("cluster ID 0x%08x does not match slice %d partition %d index %d",
102                    pClusterData->fSpacePoints[i].fID, minslice, minpart, i);
103       }
104     } else {
105       // check the cluster ID for correct bounds
106       clusterID=pClusterData->fSpacePoints[i].fID;
107       UInt_t clusterSlice =AliHLTTPCSpacePointData::GetSlice(clusterID);
108       UInt_t clusterPart  =AliHLTTPCSpacePointData::GetPatch(clusterID);
109       UInt_t clusterNumber=AliHLTTPCSpacePointData::GetNumber(clusterID);
110       if (pDesc->fSpecification!=kAliHLTVoidDataSpec) {
111         if (clusterSlice<minslice || clusterSlice>maxslice ||
112             clusterPart<minpart || clusterPart>maxpart) {
113           HLTWarning("cluster ID 0x%08d out of range indicated by data specification 0x%08x", clusterID, pDesc->fSpecification);
114         } else if (clusterNumber!=i) {
115           HLTWarning("cluster ID 0x%08d does not match index %d in block 0x%08x", clusterID, i, pDesc->fSpecification);
116         }
117       }
118     }
119     if (fClusters.find(clusterID)==fClusters.end()) {
120       // new cluster
121       fClusters[clusterID]=AliHLTTPCSpacePointProperties(&pClusterData->fSpacePoints[i]);
122       count++;
123     } else {
124       HLTError("cluster with ID 0x%08x already existing, skipping cluster %d of data block 0x%08x",
125                clusterID, i, pDesc->fSpecification);
126     }
127   }
128
129   return count;
130 }
131
132 int AliHLTTPCSpacePointContainer::GetClusterIDs(vector<AliHLTUInt32_t>& tgt) const
133 {
134   // get array of cluster IDs
135   tgt.clear();
136   transform(fClusters.begin(), fClusters.end(), back_inserter(tgt), HLT::AliGetKey());
137   return tgt.size();
138 }
139
140 float AliHLTTPCSpacePointContainer::GetX(AliHLTUInt32_t clusterID) const
141 {
142   // get X coordinate
143   if (fClusters.find(clusterID)==fClusters.end() ||
144       fClusters.find(clusterID)->second.Data()==NULL) return 0.0;
145   return fClusters.find(clusterID)->second.Data()->fX;
146 }
147
148 float AliHLTTPCSpacePointContainer::GetXWidth(AliHLTUInt32_t clusterID) const
149 {
150   // get error for X coordinate
151   if (fClusters.find(clusterID)==fClusters.end() ||
152       fClusters.find(clusterID)->second.Data()==NULL) return 0.0;
153   return 0.0; // fixed in padrow number
154 }
155
156 float AliHLTTPCSpacePointContainer::GetY(AliHLTUInt32_t clusterID) const
157 {
158   // get Y coordinate
159   if (fClusters.find(clusterID)==fClusters.end() ||
160       fClusters.find(clusterID)->second.Data()==NULL) return 0.0;
161   return fClusters.find(clusterID)->second.Data()->fY;
162 }
163
164 float AliHLTTPCSpacePointContainer::GetYWidth(AliHLTUInt32_t clusterID) const
165 {
166   // get error for Y coordinate
167   if (fClusters.find(clusterID)==fClusters.end() ||
168       fClusters.find(clusterID)->second.Data()==NULL) return 0.0;
169   return fClusters.find(clusterID)->second.Data()->fSigmaY2;
170 }
171
172 float AliHLTTPCSpacePointContainer::GetZ(AliHLTUInt32_t clusterID) const
173 {
174   // get Z coordinate
175   if (fClusters.find(clusterID)==fClusters.end() ||
176       fClusters.find(clusterID)->second.Data()==NULL) return 0.0;
177   return fClusters.find(clusterID)->second.Data()->fZ;
178 }
179
180 float AliHLTTPCSpacePointContainer::GetZWidth(AliHLTUInt32_t clusterID) const
181 {
182   // get error for Z coordinate
183   if (fClusters.find(clusterID)==fClusters.end() ||
184       fClusters.find(clusterID)->second.Data()==NULL) return 0.0;
185   return fClusters.find(clusterID)->second.Data()->fSigmaZ2;
186 }
187
188 float AliHLTTPCSpacePointContainer::GetCharge(AliHLTUInt32_t clusterID) const
189 {
190   // get charge
191   if (fClusters.find(clusterID)==fClusters.end() ||
192       fClusters.find(clusterID)->second.Data()==NULL) return 0.0;
193   return fClusters.find(clusterID)->second.Data()->fCharge;
194 }
195
196 float AliHLTTPCSpacePointContainer::GetPhi(AliHLTUInt32_t clusterID) const
197 {
198   // get charge
199   if (fClusters.find(clusterID)==fClusters.end() ||
200       fClusters.find(clusterID)->second.Data()==NULL) return 0.0;
201   int slice=AliHLTTPCSpacePointData::GetSlice(fClusters.find(clusterID)->second.Data()->fID);
202   return ( slice + 0.5 ) * TMath::Pi() / 9.0;
203 }
204
205 void AliHLTTPCSpacePointContainer::Clear(Option_t * /*option*/)
206 {
207   // clear the object and reset pointer references
208 }
209
210 void AliHLTTPCSpacePointContainer::Print(ostream& out, Option_t */*option*/) const
211 {
212   // print to stream
213   out << "AliHLTTPCSpacePointContainer::Print" << endl;
214   out << "n clusters: " << fClusters.size() << endl;
215   for (std::map<AliHLTUInt32_t, AliHLTTPCSpacePointProperties>::const_iterator cl=fClusters.begin();
216        cl!=fClusters.end(); cl++) {
217     out << " " << cl->first << cl->second << endl;
218   }
219 }
220
221 AliHLTSpacePointContainer* AliHLTTPCSpacePointContainer::SelectByTrack(int trackId, bool /*bAlloc*/) const
222 {
223   /// create a collection of clusters for a specific track
224   std::auto_ptr<AliHLTTPCSpacePointContainer> c(new AliHLTTPCSpacePointContainer);
225   if (!c.get()) return NULL;
226
227   HLT::copy_map_if(fClusters.begin(), fClusters.end(), c->fClusters, HLT::AliHLTUnaryPredicate<AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointProperties, int>(&AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointProperties::GetTrackId,trackId));
228   return c.release();
229 }
230
231 AliHLTSpacePointContainer* AliHLTTPCSpacePointContainer::SelectByMC(int mcId, bool /*bAlloc*/) const
232 {
233   /// create a collection of clusters for a specific MC track
234   std::auto_ptr<AliHLTTPCSpacePointContainer> c(new AliHLTTPCSpacePointContainer);
235   if (!c.get()) return NULL;
236
237   HLT::copy_map_if(fClusters.begin(), fClusters.end(), c->fClusters, HLT::AliHLTUnaryPredicate<AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointProperties, int>(&AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointProperties::GetMCId,mcId));
238   return c.release();
239 }
240
241 AliHLTSpacePointContainer* AliHLTTPCSpacePointContainer::UsedClusters(bool /*bAlloc*/) const
242 {
243   /// create a collection of all used clusters
244   std::auto_ptr<AliHLTTPCSpacePointContainer> c(new AliHLTTPCSpacePointContainer);
245   if (!c.get()) return NULL;
246
247   HLT::copy_map_if(fClusters.begin(), fClusters.end(), c->fClusters, HLT::AliHLTUnaryPredicate<AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointProperties, bool>(&AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointProperties::IsUsed,true));
248   return c.release();
249 }
250
251 AliHLTSpacePointContainer* AliHLTTPCSpacePointContainer::UnusedClusters(bool /*bAlloc*/) const
252 {
253   /// create a collection of all unused clusters
254   std::auto_ptr<AliHLTTPCSpacePointContainer> c(new AliHLTTPCSpacePointContainer);
255   if (!c.get()) return NULL;
256
257   HLT::copy_map_if(fClusters.begin(), fClusters.end(), c->fClusters, HLT::AliHLTUnaryPredicate<AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointProperties, bool>(&AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointProperties::IsUsed,false));
258   return c.release();
259 }
260
261 int AliHLTTPCSpacePointContainer::MarkUsed(const AliHLTUInt32_t* clusterIDs, int arraySize)
262 {
263   /// mark the clusters with specified IDs as used
264   if (!clusterIDs) return -EINVAL;
265   int iCount=0;
266   for (int i=0; i<arraySize; i++) {
267     if (fClusters.find(clusterIDs[i])==fClusters.end()) continue;
268     fClusters[clusterIDs[i]].MarkUsed();
269     iCount++;
270   }
271   return iCount;
272 }
273
274 int AliHLTTPCSpacePointContainer::SetTrackID(int trackID, const AliHLTUInt32_t* clusterIDs, int arraySize)
275 {
276   /// set track id for specified clusters
277   if (!clusterIDs) return -EINVAL;
278   int iCount=0;
279   for (int i=0; i<arraySize; i++) {
280     if (fClusters.find(clusterIDs[i])==fClusters.end()) continue;
281     fClusters[clusterIDs[i]].SetTrackId(trackID);
282     iCount++;
283   }
284   return iCount;
285 }
286
287 int AliHLTTPCSpacePointContainer::SetMCID(int mcID, const AliHLTUInt32_t* clusterIDs, int arraySize)
288 {
289   /// set mc id for specified clusters
290   if (!clusterIDs) return -EINVAL;
291   int iCount=0;
292   for (int i=0; i<arraySize; i++) {
293     if (fClusters.find(clusterIDs[i])==fClusters.end()) continue;
294     fClusters[clusterIDs[i]].SetMCId(mcID);
295     iCount++;
296   }
297   return iCount;
298 }
299
300 AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointProperties::AliHLTTPCSpacePointProperties()
301   : fCluster(NULL)
302   , fUsed(false)
303   , fTrackId(-1)
304   , fMCId(-1)
305 {
306   // constructor
307 }
308
309 AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointProperties::AliHLTTPCSpacePointProperties(const AliHLTTPCSpacePointData* pCluster)
310   : fCluster(pCluster)
311   , fUsed(false)
312   , fTrackId(-1)
313   , fMCId(-1)
314 {
315   // constructor
316 }
317
318 AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointProperties::AliHLTTPCSpacePointProperties(const AliHLTTPCSpacePointProperties& src)
319   : fCluster(src.fCluster)
320   , fUsed(src.fUsed)
321   , fTrackId(src.fTrackId)
322   , fMCId(src.fMCId)
323 {
324   // copy constructor
325 }
326
327 AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointProperties& AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointProperties::operator=(const AliHLTTPCSpacePointProperties& src)
328 {
329   // assignment operator
330   if (&src==this) return *this;
331   fCluster=src.fCluster;
332   fUsed=src.fUsed;
333   fTrackId=src.fTrackId;
334   fMCId=src.fMCId;
335
336   return *this;
337 }
338
339 void AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointProperties::Print(ostream& out, Option_t */*option*/) const
340 {
341   // print info
342   if (!Data()) {
343     out << "no data";
344     return;
345   }
346   const AliHLTTPCSpacePointData* data=Data();
347   out << " " << data->fX << " " << data->fY << " " << data->fZ << " " << (UInt_t)data->fPadRow
348       << " " << fTrackId << " " << fMCId << " " << fUsed;
349 }
350
351 ostream& operator<<(ostream &out, const AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointProperties& p)
352 {
353   p.Print(out);
354   return out;
355 }