]>
Commit | Line | Data |
---|---|---|
6de2bc40 | 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 | // ************************************************************************** | |
4acc2401 | 16 | |
16b802c5 | 17 | #ifndef ALIHLTTPCCACLUSTERDATA_H |
18 | #define ALIHLTTPCCACLUSTERDATA_H | |
4acc2401 | 19 | |
b22af1bf | 20 | #include "AliHLTTPCCADef.h" |
7be9b0d7 | 21 | #include <iostream> |
4acc2401 | 22 | #include <vector> |
4acc2401 | 23 | |
24 | /** | |
25 | * Cluster data which keeps history about changes | |
26 | * | |
27 | * The algorithm doesn't work on this data. Instead the AliHLTTPCCASliceData is created from this. | |
28 | */ | |
29 | class AliHLTTPCCAClusterData | |
30 | { | |
31 | public: | |
4acc2401 | 32 | |
b22af1bf | 33 | AliHLTTPCCAClusterData(): fSliceIndex( 0 ), fFirstRow( 0 ), fLastRow( -1 ), fNumberOfClusters(), fRowOffset(), fData() {} |
4acc2401 | 34 | |
288f5175 | 35 | /** |
36 | * prepare for the reading of event | |
37 | */ | |
16b802c5 | 38 | void StartReading( int sliceIndex, int guessForNumberOfClusters = 256 ); |
39 | ||
288f5175 | 40 | /** |
41 | * read next cluster | |
42 | */ | |
6de2bc40 | 43 | void ReadCluster( int id, int iRow, float x, float y, float z, float amp ) { |
44 | Data d = { id, iRow, x, y, z, amp}; | |
16b802c5 | 45 | fData.push_back( d ); |
46 | } | |
47 | ||
288f5175 | 48 | /** |
49 | * finish the reading of event | |
50 | */ | |
16b802c5 | 51 | void FinishReading(); |
52 | ||
7be9b0d7 | 53 | /** |
54 | * Read/Write Events from/to file | |
55 | */ | |
56 | void ReadEvent(std::istream &in); | |
57 | void WriteEvent(std::ostream &out) const; | |
58 | template <class T> void ReadEventVector(std::vector<T> &data, std::istream &in, int MinSize = 0); | |
59 | template <class T> void WriteEventVector(const std::vector<T> &data, std::ostream &out) const; | |
4acc2401 | 60 | |
61 | /** | |
62 | * "remove" one cluster and "add" two new ones, keeping history. | |
63 | */ | |
64 | //void Split( int index, /* TODO: need some parameters how to split */ ); | |
65 | ||
66 | // TODO: some access to history of merges and splits | |
67 | ||
68 | /** | |
69 | * The slice index this data belongs to | |
70 | */ | |
16b802c5 | 71 | int SliceIndex() const { return fSliceIndex; } |
4acc2401 | 72 | |
73 | /** | |
74 | * The first row index that contains a cluster. | |
75 | */ | |
76 | int FirstRow() const { return fFirstRow; } | |
77 | ||
78 | /** | |
79 | * The last row index that contains a cluster. | |
80 | */ | |
81 | int LastRow() const { return fLastRow; } | |
82 | ||
83 | /** | |
84 | * Return the number of clusters in this slice. | |
85 | */ | |
7be9b0d7 | 86 | int NumberOfClusters() const { return (int) fData.size(); } |
4acc2401 | 87 | |
88 | /** | |
89 | * Return the number of clusters in the given row, for this slice. | |
90 | */ | |
91 | int NumberOfClusters( unsigned int rowIndex ) const { return rowIndex < fNumberOfClusters.size() ? fNumberOfClusters[rowIndex] : 0; } | |
92 | ||
93 | /** | |
94 | * Return the index of the first cluster in the given row. | |
95 | * | |
96 | * Supports calls with rowIndex greater than the available number of rows. In that case it | |
97 | * returns NumberOfClusters. | |
98 | * | |
99 | * To iterate over the clusters in one row do: | |
100 | * \code | |
101 | * AliHLTTPCCAClusterData cd; | |
102 | * const int lastClusterIndex = cd.RowOffset( rowIndex + 1 ); | |
103 | * for ( int hitIndex = cd.RowOffset( rowIndex ); hitIndex < lastClusterIndex; ++hitIndex ) | |
104 | * \endcode | |
105 | */ | |
7be9b0d7 | 106 | int RowOffset( unsigned int rowIndex ) const { return rowIndex < fRowOffset.size() ? fRowOffset[rowIndex] : (int) fData.size(); } |
4acc2401 | 107 | |
108 | /** | |
109 | * Return the x coordinate of the given cluster. | |
110 | */ | |
111 | float X( int index ) const { return fData[index].fX; } | |
112 | ||
113 | /** | |
114 | * Return the y coordinate of the given cluster. | |
115 | */ | |
116 | float Y( int index ) const { return fData[index].fY; } | |
117 | ||
118 | /** | |
119 | * Return the z coordinate of the given cluster. | |
120 | */ | |
121 | float Z( int index ) const { return fData[index].fZ; } | |
122 | ||
16b802c5 | 123 | /** |
124 | * Return the amplitude of the given cluster. | |
125 | */ | |
126 | float Amp( int index ) const { return fData[index].fAmp; } | |
127 | ||
4acc2401 | 128 | /** |
129 | * Return the global ID of the given cluster. | |
130 | */ | |
131 | int Id( int index ) const { return fData[index].fId; } | |
132 | ||
133 | /** | |
134 | * Return the row number/index of the given cluster. | |
135 | */ | |
136 | int RowNumber( int index ) const { return fData[index].fRow; } | |
137 | ||
4acc2401 | 138 | struct Data { |
16b802c5 | 139 | int fId; |
140 | int fRow; | |
4acc2401 | 141 | float fX; |
142 | float fY; | |
143 | float fZ; | |
16b802c5 | 144 | float fAmp; |
4acc2401 | 145 | }; |
146 | ||
b8139972 | 147 | Data *GetClusterData( int index ) { return &( fData[index] ); } |
6de2bc40 | 148 | |
149 | private: | |
150 | /** TODO | |
151 | * "remove" two clusters and "add" a new one, keeping history. | |
152 | */ | |
153 | void Merge( int index1, int index2 ); | |
154 | ||
b22af1bf | 155 | #ifdef REPRODUCIBLE_CLUSTER_SORTING |
156 | static bool CompareClusters( const Data &a, const Data &b ) { return ( a.fRow >= b.fRow ? (a.fId < b.fId) : (a.fRow < b.fRow) ); } | |
157 | #else | |
158 | static bool CompareClusters( const Data &a, const Data &b ) { return ( (a.fRow < b.fRow) ); } | |
159 | #endif | |
16b802c5 | 160 | |
161 | int fSliceIndex; // the slice index this data belongs to | |
4acc2401 | 162 | int fFirstRow; // see FirstRow() |
163 | int fLastRow; // see LastRow() | |
164 | std::vector<int> fNumberOfClusters; // list of NumberOfClusters per row for NumberOfClusters(int) | |
165 | std::vector<int> fRowOffset; // see RowOffset() | |
166 | std::vector<Data> fData; // list of data of clusters | |
167 | }; | |
168 | ||
169 | typedef AliHLTTPCCAClusterData ClusterData; | |
170 | ||
171 | #endif // CLUSTERDATA_H |