]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/tracking-ca/AliHLTTPCCAClusterData.h
update
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking-ca / AliHLTTPCCAClusterData.h
1 /**************************************************************************
2  * This file is property of and copyright by the ALICE HLT Project        *
3  * All rights reserved.                                                   *
4  *                                                                        *
5  * Primary Authors:                                                       *
6  *     Copyright 2009       Matthias Kretz <kretz@kde.org>                *
7  *                                                                        *
8  * Permission to use, copy, modify and distribute this software and its   *
9  * documentation strictly for non-commercial purposes is hereby granted   *
10  * without fee, provided that the above copyright notice appears in all   *
11  * copies and that both the copyright notice and this permission notice   *
12  * appear in the supporting documentation. The authors make no claims     *
13  * about the suitability of this software for any purpose. It is          *
14  * provided "as is" without express or implied warranty.                  *
15  **************************************************************************/
16
17 #ifndef ALIHLTTPCCACLUSTERDATA_H
18 #define ALIHLTTPCCACLUSTERDATA_H
19
20 #include <vector>
21 #include "AliHLTArray.h"
22
23 class AliHLTTPCSpacePointData;
24
25 /**
26  * Cluster data which keeps history about changes
27  *
28  * The algorithm doesn't work on this data. Instead the AliHLTTPCCASliceData is created from this.
29  */
30 class AliHLTTPCCAClusterData
31 {
32   public:
33     /**
34      * Construct AliHLTTPCCAClusterData object from AliHLTTPCSpacePointData array.
35      */
36     AliHLTTPCCAClusterData( const AliHLTArray<AliHLTTPCSpacePointData *> &clusters,
37                             int numberOfClusters, double ClusterZCut )
38         : fSliceIndex( 0 ), fFirstRow( 0 ), fLastRow( 0 ), fNumberOfClusters(), fRowOffset(), fData()
39     { readEvent( clusters, numberOfClusters, ClusterZCut ); }
40
41
42     AliHLTTPCCAClusterData(): fSliceIndex( 0 ), fFirstRow( 0 ), fLastRow( 0 ), fNumberOfClusters(), fRowOffset(), fData() {}
43
44     void readEvent( const AliHLTArray<AliHLTTPCSpacePointData *> &clusters,
45                     int numberOfClusters, double ClusterZCut );
46
47     /**
48      * prepare for the reading of event
49      */
50     void StartReading( int sliceIndex, int guessForNumberOfClusters = 256 );
51
52     /**
53      *  read next cluster
54      */
55     void ReadCluster( int id, int iRow, float X, float Y, float Z, float Amp ) {
56       Data d = { id, iRow, X, Y, Z, Amp};
57       fData.push_back( d );
58     }
59
60     /**
61      * finish the reading of event
62      */
63     void FinishReading();
64
65
66     /**
67      * "remove" one cluster and "add" two new ones, keeping history.
68      */
69     //void Split( int index, /* TODO: need some parameters how to split */ );
70
71     // TODO: some access to history of merges and splits
72
73     /**
74      * The slice index this data belongs to
75      */
76     int SliceIndex() const { return fSliceIndex; }
77
78     /**
79      * The first row index that contains a cluster.
80      */
81     int FirstRow() const { return fFirstRow; }
82
83     /**
84      * The last row index that contains a cluster.
85      */
86     int LastRow() const { return fLastRow; }
87
88     /**
89      * Return the number of clusters in this slice.
90      */
91     int NumberOfClusters() const { return fData.size(); }
92
93     /**
94      * Return the number of clusters in the given row, for this slice.
95      */
96     int NumberOfClusters( unsigned int rowIndex ) const { return rowIndex < fNumberOfClusters.size() ? fNumberOfClusters[rowIndex] : 0; }
97
98     /**
99      * Return the index of the first cluster in the given row.
100      *
101      * Supports calls with rowIndex greater than the available number of rows. In that case it
102      * returns NumberOfClusters.
103      *
104      * To iterate over the clusters in one row do:
105      * \code
106      * AliHLTTPCCAClusterData cd;
107      * const int lastClusterIndex = cd.RowOffset( rowIndex + 1 );
108      * for ( int hitIndex = cd.RowOffset( rowIndex ); hitIndex < lastClusterIndex; ++hitIndex )
109      * \endcode
110      */
111     int RowOffset( unsigned int rowIndex ) const { return rowIndex < fRowOffset.size() ? fRowOffset[rowIndex] : fData.size(); }
112
113     /**
114      * Return the x coordinate of the given cluster.
115      */
116     float X( int index ) const { return fData[index].fX; }
117
118     /**
119      * Return the y coordinate of the given cluster.
120      */
121     float Y( int index ) const { return fData[index].fY; }
122
123     /**
124      * Return the z coordinate of the given cluster.
125      */
126     float Z( int index ) const { return fData[index].fZ; }
127
128     /**
129      * Return the amplitude of the given cluster.
130      */
131     float Amp( int index ) const { return fData[index].fAmp; }
132
133     /**
134      * Return the global ID of the given cluster.
135      */
136     int Id( int index ) const { return fData[index].fId; }
137
138     /**
139      * Return the row number/index of the given cluster.
140      */
141     int RowNumber( int index ) const { return fData[index].fRow; }
142
143   private:
144     /** TODO
145      * "remove" two clusters and "add" a new one, keeping history.
146      */
147     void Merge( int index1, int index2 );
148
149     struct Data {
150       int fId;
151       int fRow;
152       float fX;
153       float fY;
154       float fZ;
155       float fAmp;
156     };
157
158     static bool CompareClusters( const Data &a, const Data &b ) { return ( a.fRow < b.fRow ); }
159
160     int fSliceIndex;  // the slice index this data belongs to
161     int fFirstRow; // see FirstRow()
162     int fLastRow;  // see LastRow()
163     std::vector<int> fNumberOfClusters; // list of NumberOfClusters per row for NumberOfClusters(int)
164     std::vector<int> fRowOffset;        // see RowOffset()
165     std::vector<Data> fData; // list of data of clusters
166 };
167
168 typedef AliHLTTPCCAClusterData ClusterData;
169
170 #endif // CLUSTERDATA_H