TPC cluster finder speeded up, can process unsorted data (Kenneth); not yet enabled...
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCPadArray.cxx
CommitLineData
01f43166 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 * Authors: Kenneth Aamodt <Kenneth.Aamodt@student.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 AliHLTTPCPadArray.cxx
20 @author Kenneth Aamodt
21 @date
22 @brief Class containing TPC Pad objects.
23*/
24
25#if __GNUC__>= 3
26using namespace std;
27#endif
28
29#include <cerrno>
30#include "AliHLTTPCPadArray.h"
31#include "AliHLTTPCPad.h"
32#include "AliHLTStdIncludes.h"
33#include "AliHLTTPCTransform.h"
34#include "AliHLTTPCDigitReader.h"
35#include "AliHLTTPCClusters.h"
36#include <vector>
37#include <sys/time.h>
38
39/** ROOT macro for the implementation of ROOT specific class methods */
40ClassImp(AliHLTTPCPadArray)
41
42AliHLTTPCPadArray::AliHLTTPCPadArray()
43 :
44 fPatch(-1),
45 fFirstRow(-1),
46 fLastRow(-1),
47 fThreshold(10)
48{
49 // see header file for class documentation
50 // or
51 // refer to README to build package
52 // or
53 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
54}
55
56AliHLTTPCPadArray::AliHLTTPCPadArray(Int_t patch)
57 :
58 fPatch(patch),
59 fFirstRow(-1),
60 fLastRow(-1),
61 fThreshold(10)
62{
63 // see header file for class documentation
64}
65
66AliHLTTPCPadArray::AliHLTTPCPadArray(const AliHLTTPCPadArray& srcPadArray)
67 :
68 fPatch(srcPadArray.fPatch),
69 fFirstRow(srcPadArray.fFirstRow),
70 fLastRow(srcPadArray.fLastRow)
71{
72 // see header file for class documentation
73 HLTFatal("copy constructor not implemented");
74}
75
76AliHLTTPCPadArray& AliHLTTPCPadArray::operator=(const AliHLTTPCPadArray&)
77{
78 // see header file for class documentation
79 HLTFatal("assignment operator not implemented");
80 return (*this);
81}
82
83AliHLTTPCPadArray::~AliHLTTPCPadArray()
84{
85 // see header file for class documentation
86}
87
88Int_t AliHLTTPCPadArray::InitializeVector(){
89 // see header file for class documentation
90
91 if(fPatch>5||fPatch<0){
92 HLTFatal("Patch is not set");
93 return 0;
94 }
95
96 fFirstRow = AliHLTTPCTransform::GetFirstRow(fPatch);
97 fLastRow = AliHLTTPCTransform::GetLastRow(fPatch);
98
99 fNumberOfRows=fLastRow-fFirstRow+1;
100 fNumberOfPadsInRow= new Int_t[fNumberOfRows];
101
102 memset( fNumberOfPadsInRow, 0, sizeof(Int_t)*(fNumberOfRows));
103
104 for(Int_t i=0;i<fNumberOfRows;i++){
105 fNumberOfPadsInRow[i]=AliHLTTPCTransform::GetNPads(i+fFirstRow);
106 fPadVector tmpRow;
107 for(Int_t j=0;j<fNumberOfPadsInRow[i];j++){
108 AliHLTTPCPad *tmpPad = new AliHLTTPCPad();
109 tmpPad->SetID(i,j);
110 tmpRow.push_back(tmpPad);
111 }
112 fRowPadVector.push_back(tmpRow);
113 }
114}
115
116Int_t AliHLTTPCPadArray::DeInitializeVector(){
117 for(Int_t i=0;i<fNumberOfRows;i++){
118 for(Int_t j=0;j<fNumberOfPadsInRow[i];j++){
119 delete fRowPadVector[i][j];
120 }
121 fRowPadVector[i].clear();
122 }
123 fRowPadVector.clear();
124 return 1;
125}
126void AliHLTTPCPadArray::SetPatch(Int_t patch){
127 fPatch=patch;
128}
129
130void AliHLTTPCPadArray::SetDigitReader(AliHLTTPCDigitReader* digitReader){
131 fDigitReader=digitReader;
132}
133Int_t AliHLTTPCPadArray::ReadData(){
134
135 switch (fPatch){
136 case 0:
137 while(fDigitReader->Next()){
138 fRowPadVector[fDigitReader->GetRow()-fFirstRow][fDigitReader->GetPad()]->SetDataSignal(fDigitReader->GetTime(),fDigitReader->GetSignal());
139 }
140
141 case 1:
142 while(fDigitReader->Next()){
143 fRowPadVector[fDigitReader->GetRow()-fFirstRow][fDigitReader->GetPad()]->SetDataSignal(fDigitReader->GetTime(),fDigitReader->GetSignal());
144 }
145 case 2:
146 while(fDigitReader->Next()){
147 fRowPadVector[fDigitReader->GetRow()][fDigitReader->GetPad()]->SetDataSignal(fDigitReader->GetTime(),fDigitReader->GetSignal());
148 }
149 case 3:
150 while(fDigitReader->Next()){
151 fRowPadVector[fDigitReader->GetRow()-27][fDigitReader->GetPad()]->SetDataSignal(fDigitReader->GetTime(),fDigitReader->GetSignal());
152 }
153 case 4:
154 while(fDigitReader->Next()){
155 fRowPadVector[fDigitReader->GetRow()-54][fDigitReader->GetPad()]->SetDataSignal(fDigitReader->GetTime(),fDigitReader->GetSignal());
156 }
157 case 5:
158 while(fDigitReader->Next()){
159 fRowPadVector[fDigitReader->GetRow()-76][fDigitReader->GetPad()]->SetDataSignal(fDigitReader->GetTime(),fDigitReader->GetSignal());
160 }
161 }
162}
163void AliHLTTPCPadArray::FindClusters(Int_t match){
164 //see header file for documentation
165 Int_t nClusters=0;
166 Int_t totalChargeOfPreviousCandidate=0;
167 Int_t clusterChargeIsFalling=0;
168 for(Int_t row=0;row<fNumberOfRows;row++){
169 for(Int_t pad=0;pad<fNumberOfPadsInRow[row]-1;pad++){
170 AliHLTTPCPad *tmp1=fRowPadVector[row][pad];
171 AliHLTTPCPad *tmp2=fRowPadVector[row][pad+1];
172 for(Int_t c1=0;c1<tmp1->fClusterCandidates.size();c1++){
173
174 if(tmp1->fUsedClusterCandidates[c1]){
175 continue;
176 }
177
178 for(Int_t c2=0;c2<tmp2->fClusterCandidates.size();c2++){
179
180 if(tmp2->fUsedClusterCandidates[c2]){
181 continue;
182 }
183
184 Int_t diff= tmp1->fClusterCandidates[c1].fMean - tmp2->fClusterCandidates[c2].fMean;
185
186 if(diff < -match){
187 break;
188 }
189 if(diff <= match){
190
191 if((Int_t)(tmp1->fClusterCandidates[c1].fTotalCharge - tmp2->fClusterCandidates[c2].fTotalCharge)>0){
192 clusterChargeIsFalling=1;
193 }
194
195 tmp1->fUsedClusterCandidates[c1]=1;
196 tmp2->fUsedClusterCandidates[c2]=1;
197
198 AliHLTTPCClusters tmpCluster;
199 tmpCluster.fTotalCharge = tmp1->fClusterCandidates[c1].fTotalCharge;
200 tmpCluster.fPad = tmp1->fClusterCandidates[c1].fPad;
201 tmpCluster.fPad2 = tmp1->fClusterCandidates[c1].fPad2;
202 tmpCluster.fTime = tmp1->fClusterCandidates[c1].fTime;
203 tmpCluster.fTime2 = tmp1->fClusterCandidates[c1].fTime2;
204 tmpCluster.fRowNumber = row;
205
206 tmpCluster.fTotalCharge += tmp2->fClusterCandidates[c2].fTotalCharge;
207 tmpCluster.fPad += tmp2->fClusterCandidates[c2].fPad;
208 tmpCluster.fPad2 += tmp2->fClusterCandidates[c2].fPad2;
209 tmpCluster.fTime += tmp2->fClusterCandidates[c2].fTime;
210 tmpCluster.fTime2 += tmp2->fClusterCandidates[c2].fTime2;
211 tmpCluster.fMean = tmp2->fClusterCandidates[c2].fMean;
212 totalChargeOfPreviousCandidate = tmp2->fClusterCandidates[c2].fTotalCharge;
213
214 int rowNumber=row;
215 int lastPad=pad+1;
216 nClusters++;
217 Int_t doBreak=0;
218 for(Int_t morePads=pad+2;morePads<fNumberOfPadsInRow[row];morePads++){
219 AliHLTTPCPad *tmpx=fRowPadVector[row][morePads];
220 if(morePads>lastPad+1){
221 break;
222 }
223 for(Int_t cx=0;cx<tmpx->fClusterCandidates.size();cx++){
224 if(tmpx->fUsedClusterCandidates[cx]){
225 continue;
226 }
227 Int_t diffx=tmpCluster.fMean - tmpx->fClusterCandidates[cx].fMean;
228 if(diffx<-match){
229 doBreak=1;
230 break;
231 }
232 if(diffx <= match){
233 if((Int_t)(totalChargeOfPreviousCandidate - tmpx->fClusterCandidates[cx].fTotalCharge)>0){
234 clusterChargeIsFalling=1;
235 }
236
237 if(clusterChargeIsFalling&&(Int_t)(totalChargeOfPreviousCandidate - tmpx->fClusterCandidates[cx].fTotalCharge)<=0){
238 //Means we have a deconvoluted cluster.
239 totalChargeOfPreviousCandidate=0;
240 doBreak=1;
241 break;
242 }
243
244 tmpx->fUsedClusterCandidates[cx]=1;
245 tmpCluster.fTotalCharge += tmpx->fClusterCandidates[cx].fTotalCharge;
246 tmpCluster.fPad += tmpx->fClusterCandidates[cx].fPad;
247 tmpCluster.fPad2 += tmpx->fClusterCandidates[cx].fPad2;
248 tmpCluster.fTime += tmpx->fClusterCandidates[cx].fTime;
249 tmpCluster.fTime2 += tmpx->fClusterCandidates[cx].fTime2;
250 tmpCluster.fMean = tmpx->fClusterCandidates[cx].fMean;
251 lastPad=morePads;
252
253 totalChargeOfPreviousCandidate=tmpx->fClusterCandidates[cx].fTotalCharge;
254 }
255 }
256 if(doBreak){
257 break;
258 }
259 }
260
261 if(tmpCluster.fTotalCharge<fThreshold){
262 nClusters--;
263 }
264 else{
265 //Code to look for tails, TODO insert flag.
266 UInt_t meanTime=tmpCluster.fMean;
267 if(pad>0){
268 AliHLTTPCPad *tmpBefore=fRowPadVector[row][pad-1];
269 //checking the fMean -1 timebin for single timebin value in the pad before the cluster
270 if(meanTime>0){
271 Int_t charge =tmpBefore->GetDataSignal(meanTime-1);
272 if(charge){
273 tmpCluster.fTotalCharge+= charge;
274 tmpCluster.fPad += charge*(pad-1);
275 tmpCluster.fPad2 += charge*(pad-1)*(pad-1);
276 tmpCluster.fTime += meanTime*charge;
277 tmpCluster.fTime2 += meanTime*charge*charge;
278 }
279 }
280 //checking the fMean timebin for single timebin value in the pad before the cluster
281 Int_t charge2 =tmpBefore->GetDataSignal(meanTime);
282 if(charge2){
283 tmpCluster.fTotalCharge+= charge2;
284 tmpCluster.fPad += charge2*(pad);
285 tmpCluster.fPad2 += charge2*(pad)*(pad);
286 tmpCluster.fTime += meanTime*charge2;
287 tmpCluster.fTime2 += meanTime*charge2*charge2;
288 }
289 //checking the fMean +1 timebin for single timebin value in the pad before the cluster
290 if(meanTime<AliHLTTPCTransform::GetNTimeBins()){
291 Int_t charge3 =tmpBefore->GetDataSignal(meanTime+1);
292 if(charge3){
293 tmpCluster.fTotalCharge+= charge3;
294 tmpCluster.fPad += charge3*(pad+1);
295 tmpCluster.fPad2 += charge3*(pad+1)*(pad+1);
296 tmpCluster.fTime += meanTime*charge3;
297 tmpCluster.fTime2 += meanTime*charge3*charge3;
298 }
299 }
300 }
301
302 if(lastPad<fNumberOfPadsInRow[row]-2){
303 AliHLTTPCPad *tmpAfter=fRowPadVector[row][lastPad+1];
304 //checking the fMean +1 timebin for single timebin value in the pad after the cluster
305 if(meanTime>0){
306 Int_t charge4 =tmpAfter->GetDataSignal(meanTime-1);
307 if(charge4){
308 tmpCluster.fTotalCharge+= charge4;
309 tmpCluster.fPad += charge4*(pad-1);
310 tmpCluster.fPad2 += charge4*(pad-1)*(pad-1);
311 tmpCluster.fTime += meanTime*charge4;
312 tmpCluster.fTime2 += meanTime*charge4*charge4;
313 }
314 }
315
316
317 //checking the fMean +1 timebin for single timebin value in the pad after the cluster
318 Int_t charge5 =tmpAfter->GetDataSignal(meanTime);
319 if(charge5){
320 tmpCluster.fTotalCharge+= charge5;
321 tmpCluster.fPad += charge5*(pad);
322 tmpCluster.fPad2 += charge5*(pad)*(pad);
323 tmpCluster.fTime += meanTime*charge5;
324 tmpCluster.fTime2 += meanTime*charge5*charge5;
325 }
326 //checking the fMean +1 timebin for single timebin value in the pad after the cluster
327 if(meanTime<AliHLTTPCTransform::GetNTimeBins()){
328 Int_t charge6 =tmpAfter->GetDataSignal(meanTime+1);
329 if(charge6){
330 tmpCluster.fTotalCharge+= charge6;
331 tmpCluster.fPad += charge6*(pad+1);
332 tmpCluster.fPad2 += charge6*(pad+1)*(pad+1);
333 tmpCluster.fTime += meanTime*charge6;
334 tmpCluster.fTime2 += meanTime*charge6*charge6;
335 }
336 }
337 }
338 tmpCluster.fTime= tmpCluster.fTime/tmpCluster.fTotalCharge;
339 totalChargeOfPreviousCandidate=0;
340 clusterChargeIsFalling=0;
341 tmpCluster.fRowNumber=row;
342 tmpCluster.fFirstPad=pad;
343
344 fClusters.push_back(tmpCluster);
345 }
346 }
347 }
348 }
349 }
350 }
351
352 HLTInfo("Found %d clusters.",nClusters);
353 // PrintClusters();
354}
355void AliHLTTPCPadArray::PrintClusters(){
356 for(int i=0;i<fClusters.size();i++){
357 cout<<"Cluster number: "<<i<<endl;
358 cout<<"Row: "<<fClusters[i].fRowNumber<<" Pad: "<<fClusters[i].fFirstPad<<endl;
359 cout<<"Total Charge: "<<fClusters[i].fTotalCharge<<endl;
360 cout<<"PadError: "<<fClusters[i].fPad2<<endl;
361 cout<<"TimeMean: "<<fClusters[i].fTime<<endl;
362 cout<<"TimeError: "<<fClusters[i].fTime2<<endl;
363 cout<<endl;
364 cout<<endl;
365 }
366}