Fixing memory leaks
[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 }
e83e889b 162 return 0;
01f43166 163}
164void AliHLTTPCPadArray::FindClusters(Int_t match){
165 //see header file for documentation
166 Int_t nClusters=0;
167 Int_t totalChargeOfPreviousCandidate=0;
168 Int_t clusterChargeIsFalling=0;
169 for(Int_t row=0;row<fNumberOfRows;row++){
170 for(Int_t pad=0;pad<fNumberOfPadsInRow[row]-1;pad++){
171 AliHLTTPCPad *tmp1=fRowPadVector[row][pad];
172 AliHLTTPCPad *tmp2=fRowPadVector[row][pad+1];
173 for(Int_t c1=0;c1<tmp1->fClusterCandidates.size();c1++){
174
175 if(tmp1->fUsedClusterCandidates[c1]){
176 continue;
177 }
178
179 for(Int_t c2=0;c2<tmp2->fClusterCandidates.size();c2++){
180
181 if(tmp2->fUsedClusterCandidates[c2]){
182 continue;
183 }
184
185 Int_t diff= tmp1->fClusterCandidates[c1].fMean - tmp2->fClusterCandidates[c2].fMean;
186
187 if(diff < -match){
188 break;
189 }
190 if(diff <= match){
191
192 if((Int_t)(tmp1->fClusterCandidates[c1].fTotalCharge - tmp2->fClusterCandidates[c2].fTotalCharge)>0){
193 clusterChargeIsFalling=1;
194 }
195
196 tmp1->fUsedClusterCandidates[c1]=1;
197 tmp2->fUsedClusterCandidates[c2]=1;
198
199 AliHLTTPCClusters tmpCluster;
200 tmpCluster.fTotalCharge = tmp1->fClusterCandidates[c1].fTotalCharge;
201 tmpCluster.fPad = tmp1->fClusterCandidates[c1].fPad;
202 tmpCluster.fPad2 = tmp1->fClusterCandidates[c1].fPad2;
203 tmpCluster.fTime = tmp1->fClusterCandidates[c1].fTime;
204 tmpCluster.fTime2 = tmp1->fClusterCandidates[c1].fTime2;
205 tmpCluster.fRowNumber = row;
206
207 tmpCluster.fTotalCharge += tmp2->fClusterCandidates[c2].fTotalCharge;
208 tmpCluster.fPad += tmp2->fClusterCandidates[c2].fPad;
209 tmpCluster.fPad2 += tmp2->fClusterCandidates[c2].fPad2;
210 tmpCluster.fTime += tmp2->fClusterCandidates[c2].fTime;
211 tmpCluster.fTime2 += tmp2->fClusterCandidates[c2].fTime2;
212 tmpCluster.fMean = tmp2->fClusterCandidates[c2].fMean;
213 totalChargeOfPreviousCandidate = tmp2->fClusterCandidates[c2].fTotalCharge;
214
215 int rowNumber=row;
216 int lastPad=pad+1;
217 nClusters++;
218 Int_t doBreak=0;
219 for(Int_t morePads=pad+2;morePads<fNumberOfPadsInRow[row];morePads++){
220 AliHLTTPCPad *tmpx=fRowPadVector[row][morePads];
221 if(morePads>lastPad+1){
222 break;
223 }
224 for(Int_t cx=0;cx<tmpx->fClusterCandidates.size();cx++){
225 if(tmpx->fUsedClusterCandidates[cx]){
226 continue;
227 }
228 Int_t diffx=tmpCluster.fMean - tmpx->fClusterCandidates[cx].fMean;
229 if(diffx<-match){
230 doBreak=1;
231 break;
232 }
233 if(diffx <= match){
234 if((Int_t)(totalChargeOfPreviousCandidate - tmpx->fClusterCandidates[cx].fTotalCharge)>0){
235 clusterChargeIsFalling=1;
236 }
237
238 if(clusterChargeIsFalling&&(Int_t)(totalChargeOfPreviousCandidate - tmpx->fClusterCandidates[cx].fTotalCharge)<=0){
239 //Means we have a deconvoluted cluster.
240 totalChargeOfPreviousCandidate=0;
241 doBreak=1;
242 break;
243 }
244
245 tmpx->fUsedClusterCandidates[cx]=1;
246 tmpCluster.fTotalCharge += tmpx->fClusterCandidates[cx].fTotalCharge;
247 tmpCluster.fPad += tmpx->fClusterCandidates[cx].fPad;
248 tmpCluster.fPad2 += tmpx->fClusterCandidates[cx].fPad2;
249 tmpCluster.fTime += tmpx->fClusterCandidates[cx].fTime;
250 tmpCluster.fTime2 += tmpx->fClusterCandidates[cx].fTime2;
251 tmpCluster.fMean = tmpx->fClusterCandidates[cx].fMean;
252 lastPad=morePads;
253
254 totalChargeOfPreviousCandidate=tmpx->fClusterCandidates[cx].fTotalCharge;
255 }
256 }
257 if(doBreak){
258 break;
259 }
260 }
261
262 if(tmpCluster.fTotalCharge<fThreshold){
263 nClusters--;
264 }
265 else{
266 //Code to look for tails, TODO insert flag.
267 UInt_t meanTime=tmpCluster.fMean;
268 if(pad>0){
269 AliHLTTPCPad *tmpBefore=fRowPadVector[row][pad-1];
270 //checking the fMean -1 timebin for single timebin value in the pad before the cluster
271 if(meanTime>0){
272 Int_t charge =tmpBefore->GetDataSignal(meanTime-1);
273 if(charge){
274 tmpCluster.fTotalCharge+= charge;
275 tmpCluster.fPad += charge*(pad-1);
276 tmpCluster.fPad2 += charge*(pad-1)*(pad-1);
277 tmpCluster.fTime += meanTime*charge;
278 tmpCluster.fTime2 += meanTime*charge*charge;
279 }
280 }
281 //checking the fMean timebin for single timebin value in the pad before the cluster
282 Int_t charge2 =tmpBefore->GetDataSignal(meanTime);
283 if(charge2){
284 tmpCluster.fTotalCharge+= charge2;
285 tmpCluster.fPad += charge2*(pad);
286 tmpCluster.fPad2 += charge2*(pad)*(pad);
287 tmpCluster.fTime += meanTime*charge2;
288 tmpCluster.fTime2 += meanTime*charge2*charge2;
289 }
290 //checking the fMean +1 timebin for single timebin value in the pad before the cluster
291 if(meanTime<AliHLTTPCTransform::GetNTimeBins()){
292 Int_t charge3 =tmpBefore->GetDataSignal(meanTime+1);
293 if(charge3){
294 tmpCluster.fTotalCharge+= charge3;
295 tmpCluster.fPad += charge3*(pad+1);
296 tmpCluster.fPad2 += charge3*(pad+1)*(pad+1);
297 tmpCluster.fTime += meanTime*charge3;
298 tmpCluster.fTime2 += meanTime*charge3*charge3;
299 }
300 }
301 }
302
303 if(lastPad<fNumberOfPadsInRow[row]-2){
304 AliHLTTPCPad *tmpAfter=fRowPadVector[row][lastPad+1];
305 //checking the fMean +1 timebin for single timebin value in the pad after the cluster
306 if(meanTime>0){
307 Int_t charge4 =tmpAfter->GetDataSignal(meanTime-1);
308 if(charge4){
309 tmpCluster.fTotalCharge+= charge4;
310 tmpCluster.fPad += charge4*(pad-1);
311 tmpCluster.fPad2 += charge4*(pad-1)*(pad-1);
312 tmpCluster.fTime += meanTime*charge4;
313 tmpCluster.fTime2 += meanTime*charge4*charge4;
314 }
315 }
316
317
318 //checking the fMean +1 timebin for single timebin value in the pad after the cluster
319 Int_t charge5 =tmpAfter->GetDataSignal(meanTime);
320 if(charge5){
321 tmpCluster.fTotalCharge+= charge5;
322 tmpCluster.fPad += charge5*(pad);
323 tmpCluster.fPad2 += charge5*(pad)*(pad);
324 tmpCluster.fTime += meanTime*charge5;
325 tmpCluster.fTime2 += meanTime*charge5*charge5;
326 }
327 //checking the fMean +1 timebin for single timebin value in the pad after the cluster
328 if(meanTime<AliHLTTPCTransform::GetNTimeBins()){
329 Int_t charge6 =tmpAfter->GetDataSignal(meanTime+1);
330 if(charge6){
331 tmpCluster.fTotalCharge+= charge6;
332 tmpCluster.fPad += charge6*(pad+1);
333 tmpCluster.fPad2 += charge6*(pad+1)*(pad+1);
334 tmpCluster.fTime += meanTime*charge6;
335 tmpCluster.fTime2 += meanTime*charge6*charge6;
336 }
337 }
338 }
339 tmpCluster.fTime= tmpCluster.fTime/tmpCluster.fTotalCharge;
340 totalChargeOfPreviousCandidate=0;
341 clusterChargeIsFalling=0;
342 tmpCluster.fRowNumber=row;
343 tmpCluster.fFirstPad=pad;
344
345 fClusters.push_back(tmpCluster);
346 }
347 }
348 }
349 }
350 }
351 }
352
353 HLTInfo("Found %d clusters.",nClusters);
354 // PrintClusters();
355}
356void AliHLTTPCPadArray::PrintClusters(){
357 for(int i=0;i<fClusters.size();i++){
358 cout<<"Cluster number: "<<i<<endl;
359 cout<<"Row: "<<fClusters[i].fRowNumber<<" Pad: "<<fClusters[i].fFirstPad<<endl;
360 cout<<"Total Charge: "<<fClusters[i].fTotalCharge<<endl;
361 cout<<"PadError: "<<fClusters[i].fPad2<<endl;
362 cout<<"TimeMean: "<<fClusters[i].fTime<<endl;
363 cout<<"TimeError: "<<fClusters[i].fTime2<<endl;
364 cout<<endl;
365 cout<<endl;
366 }
367}