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 AliHLTTPCSpacePointContainer.h
20 /// @author Matthias Richter
22 /// @brief Helper class for handling of HLT TPC space point data blocks
25 #include "AliHLTTPCSpacePointContainer.h"
26 #include "AliHLTTPCSpacePointData.h"
27 #include "AliHLTTPCDefinitions.h"
28 #include "AliHLTComponent.h"
29 #include "AliHLTTemplates.h"
34 /** ROOT macro for the implementation of ROOT specific class methods */
35 ClassImp(AliHLTTPCSpacePointContainer)
37 AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointContainer()
38 : AliHLTSpacePointContainer()
41 // see header file for class documentation
43 // refer to README to build package
45 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
48 AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointContainer(const AliHLTTPCSpacePointContainer& c)
49 : AliHLTSpacePointContainer(c)
50 , fClusters(c.fClusters.begin(), c.fClusters.end())
55 AliHLTTPCSpacePointContainer& AliHLTTPCSpacePointContainer::operator=(const AliHLTTPCSpacePointContainer& c)
57 /// assignment operator
58 if (&c==this) return *this;
59 AliHLTSpacePointContainer::operator=(c);
60 fClusters=c.fClusters;
65 AliHLTTPCSpacePointContainer::~AliHLTTPCSpacePointContainer()
70 int AliHLTTPCSpacePointContainer::AddInputBlock(const AliHLTComponentBlockData* pDesc)
72 // add input block to the collection
73 if (!pDesc) return -EINVAL;
75 if (pDesc->fDataType!=AliHLTTPCDefinitions::fgkClustersDataType) {
76 HLTWarning("ignoring data block of type %s", AliHLTComponent::DataType2Text(pDesc->fDataType).c_str());
79 if (!pDesc->fPtr || pDesc->fSize<sizeof(AliHLTTPCClusterData)) return -ENODATA;
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);
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);
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);
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);
119 if (fClusters.find(clusterID)==fClusters.end()) {
121 fClusters[clusterID]=AliHLTTPCSpacePointProperties(&pClusterData->fSpacePoints[i]);
124 HLTError("cluster with ID 0x%08x already existing, skipping cluster %d of data block 0x%08x",
125 clusterID, i, pDesc->fSpecification);
132 int AliHLTTPCSpacePointContainer::GetClusterIDs(vector<AliHLTUInt32_t>& tgt) const
134 // get array of cluster IDs
136 transform(fClusters.begin(), fClusters.end(), back_inserter(tgt), HLT::AliGetKey());
140 float AliHLTTPCSpacePointContainer::GetX(AliHLTUInt32_t clusterID) const
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;
148 float AliHLTTPCSpacePointContainer::GetXWidth(AliHLTUInt32_t clusterID) const
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
156 float AliHLTTPCSpacePointContainer::GetY(AliHLTUInt32_t clusterID) const
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;
164 float AliHLTTPCSpacePointContainer::GetYWidth(AliHLTUInt32_t clusterID) const
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;
172 float AliHLTTPCSpacePointContainer::GetZ(AliHLTUInt32_t clusterID) const
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;
180 float AliHLTTPCSpacePointContainer::GetZWidth(AliHLTUInt32_t clusterID) const
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;
188 float AliHLTTPCSpacePointContainer::GetCharge(AliHLTUInt32_t clusterID) const
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;
196 float AliHLTTPCSpacePointContainer::GetPhi(AliHLTUInt32_t clusterID) const
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;
205 void AliHLTTPCSpacePointContainer::Clear(Option_t * /*option*/)
207 // clear the object and reset pointer references
210 void AliHLTTPCSpacePointContainer::Print(ostream& out, Option_t */*option*/) const
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;
221 AliHLTSpacePointContainer* AliHLTTPCSpacePointContainer::SelectByTrack(int trackId, bool /*bAlloc*/) const
223 /// create a collection of clusters for a specific track
224 std::auto_ptr<AliHLTTPCSpacePointContainer> c(new AliHLTTPCSpacePointContainer);
225 if (!c.get()) return NULL;
227 HLT::copy_map_if(fClusters.begin(), fClusters.end(), c->fClusters, HLT::AliHLTUnaryPredicate<AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointProperties, int>(&AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointProperties::GetTrackId,trackId));
231 AliHLTSpacePointContainer* AliHLTTPCSpacePointContainer::SelectByMC(int mcId, bool /*bAlloc*/) const
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;
237 HLT::copy_map_if(fClusters.begin(), fClusters.end(), c->fClusters, HLT::AliHLTUnaryPredicate<AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointProperties, int>(&AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointProperties::GetMCId,mcId));
241 AliHLTSpacePointContainer* AliHLTTPCSpacePointContainer::UsedClusters(bool /*bAlloc*/) const
243 /// create a collection of all used clusters
244 std::auto_ptr<AliHLTTPCSpacePointContainer> c(new AliHLTTPCSpacePointContainer);
245 if (!c.get()) return NULL;
247 HLT::copy_map_if(fClusters.begin(), fClusters.end(), c->fClusters, HLT::AliHLTUnaryPredicate<AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointProperties, bool>(&AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointProperties::IsUsed,true));
251 AliHLTSpacePointContainer* AliHLTTPCSpacePointContainer::UnusedClusters(bool /*bAlloc*/) const
253 /// create a collection of all unused clusters
254 std::auto_ptr<AliHLTTPCSpacePointContainer> c(new AliHLTTPCSpacePointContainer);
255 if (!c.get()) return NULL;
257 HLT::copy_map_if(fClusters.begin(), fClusters.end(), c->fClusters, HLT::AliHLTUnaryPredicate<AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointProperties, bool>(&AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointProperties::IsUsed,false));
261 int AliHLTTPCSpacePointContainer::MarkUsed(const AliHLTUInt32_t* clusterIDs, int arraySize)
263 /// mark the clusters with specified IDs as used
264 if (!clusterIDs) return -EINVAL;
266 for (int i=0; i<arraySize; i++) {
267 if (fClusters.find(clusterIDs[i])==fClusters.end()) continue;
268 fClusters[clusterIDs[i]].MarkUsed();
274 int AliHLTTPCSpacePointContainer::SetTrackID(int trackID, const AliHLTUInt32_t* clusterIDs, int arraySize)
276 /// set track id for specified clusters
277 if (!clusterIDs) return -EINVAL;
279 for (int i=0; i<arraySize; i++) {
280 if (fClusters.find(clusterIDs[i])==fClusters.end()) continue;
281 fClusters[clusterIDs[i]].SetTrackId(trackID);
287 int AliHLTTPCSpacePointContainer::SetMCID(int mcID, const AliHLTUInt32_t* clusterIDs, int arraySize)
289 /// set mc id for specified clusters
290 if (!clusterIDs) return -EINVAL;
292 for (int i=0; i<arraySize; i++) {
293 if (fClusters.find(clusterIDs[i])==fClusters.end()) continue;
294 fClusters[clusterIDs[i]].SetMCId(mcID);
300 AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointProperties::AliHLTTPCSpacePointProperties()
309 AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointProperties::AliHLTTPCSpacePointProperties(const AliHLTTPCSpacePointData* pCluster)
318 AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointProperties::AliHLTTPCSpacePointProperties(const AliHLTTPCSpacePointProperties& src)
319 : fCluster(src.fCluster)
321 , fTrackId(src.fTrackId)
327 AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointProperties& AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointProperties::operator=(const AliHLTTPCSpacePointProperties& src)
329 // assignment operator
330 if (&src==this) return *this;
331 fCluster=src.fCluster;
333 fTrackId=src.fTrackId;
339 void AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointProperties::Print(ostream& out, Option_t */*option*/) const
346 const AliHLTTPCSpacePointData* data=Data();
347 out << " " << data->fX << " " << data->fY << " " << data->fZ << " " << (UInt_t)data->fPadRow
348 << " " << fTrackId << " " << fMCId << " " << fUsed;
351 ostream& operator<<(ostream &out, const AliHLTTPCSpacePointContainer::AliHLTTPCSpacePointProperties& p)