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