]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDclusterizerV1.cxx
Keep previous definition of rows for reconstruction
[u/mrichter/AliRoot.git] / TRD / AliTRDclusterizerV1.cxx
CommitLineData
cb86ff6e 1
f7336fa3 2/**************************************************************************
3 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * *
5 * Author: The ALICE Off-line Project. *
6 * Contributors are mentioned in the code where appropriate. *
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
88cb7938 17/* $Id$ */
f7336fa3 18
19///////////////////////////////////////////////////////////////////////////////
20// //
6d50f529 21// TRD cluster finder //
f7336fa3 22// //
23///////////////////////////////////////////////////////////////////////////////
24
25#include <TF1.h>
94de3818 26#include <TTree.h>
793ff80c 27#include <TH1.h>
a819a5f7 28#include <TFile.h>
f7336fa3 29
88cb7938 30#include "AliRunLoader.h"
31#include "AliLoader.h"
928e9fae 32#include "AliRawReader.h"
6d50f529 33#include "AliLog.h"
793ff80c 34
f7336fa3 35#include "AliTRDclusterizerV1.h"
f7336fa3 36#include "AliTRDgeometry.h"
6f1e466d 37#include "AliTRDdataArrayF.h"
793ff80c 38#include "AliTRDdataArrayI.h"
39#include "AliTRDdigitsManager.h"
a5cadd36 40#include "AliTRDpadPlane.h"
928e9fae 41#include "AliTRDrawData.h"
3551db50 42#include "AliTRDcalibDB.h"
3becff3c 43#include "AliTRDSimParam.h"
3551db50 44#include "AliTRDRecParam.h"
45#include "AliTRDCommonParam.h"
c85a4951 46#include "AliTRDcluster.h"
f7336fa3 47
56178ff4 48#include "Cal/AliTRDCalROC.h"
49#include "Cal/AliTRDCalDet.h"
50
f7336fa3 51ClassImp(AliTRDclusterizerV1)
52
53//_____________________________________________________________________________
6d50f529 54AliTRDclusterizerV1::AliTRDclusterizerV1()
55 :AliTRDclusterizer()
56 ,fDigitsManager(NULL)
f7336fa3 57{
58 //
59 // AliTRDclusterizerV1 default constructor
60 //
61
f7336fa3 62}
63
64//_____________________________________________________________________________
a6dd11e9 65AliTRDclusterizerV1::AliTRDclusterizerV1(const Text_t *name, const Text_t *title)
6d50f529 66 :AliTRDclusterizer(name,title)
67 ,fDigitsManager(new AliTRDdigitsManager())
f7336fa3 68{
69 //
6d50f529 70 // AliTRDclusterizerV1 constructor
f7336fa3 71 //
72
17b26de4 73 fDigitsManager->CreateArrays();
f7336fa3 74
75}
76
8230f242 77//_____________________________________________________________________________
dd9a6ee3 78AliTRDclusterizerV1::AliTRDclusterizerV1(const AliTRDclusterizerV1 &c)
6d50f529 79 :AliTRDclusterizer(c)
80 ,fDigitsManager(NULL)
8230f242 81{
82 //
83 // AliTRDclusterizerV1 copy constructor
84 //
85
8230f242 86}
87
f7336fa3 88//_____________________________________________________________________________
89AliTRDclusterizerV1::~AliTRDclusterizerV1()
90{
8230f242 91 //
92 // AliTRDclusterizerV1 destructor
93 //
f7336fa3 94
6f1e466d 95 if (fDigitsManager) {
96 delete fDigitsManager;
abaf1f1d 97 fDigitsManager = NULL;
f7336fa3 98 }
99
100}
101
dd9a6ee3 102//_____________________________________________________________________________
103AliTRDclusterizerV1 &AliTRDclusterizerV1::operator=(const AliTRDclusterizerV1 &c)
104{
105 //
106 // Assignment operator
107 //
108
109 if (this != &c) ((AliTRDclusterizerV1 &) c).Copy(*this);
110 return *this;
111
112}
113
8230f242 114//_____________________________________________________________________________
e0d47c25 115void AliTRDclusterizerV1::Copy(TObject &c) const
8230f242 116{
117 //
118 // Copy function
119 //
120
17b26de4 121 ((AliTRDclusterizerV1 &) c).fDigitsManager = 0;
8230f242 122
123 AliTRDclusterizer::Copy(c);
124
125}
126
f7336fa3 127//_____________________________________________________________________________
128Bool_t AliTRDclusterizerV1::ReadDigits()
129{
130 //
131 // Reads the digits arrays from the input aliroot file
132 //
133
88cb7938 134 if (!fRunLoader) {
6d50f529 135 AliError("No run loader available");
f7336fa3 136 return kFALSE;
137 }
6d50f529 138
88cb7938 139 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
6d50f529 140 if (!loader->TreeD()) {
141 loader->LoadDigits();
142 }
abaf1f1d 143
f7336fa3 144 // Read in the digit arrays
88cb7938 145 return (fDigitsManager->ReadDigits(loader->TreeD()));
f7336fa3 146
147}
148
928e9fae 149//_____________________________________________________________________________
a6dd11e9 150Bool_t AliTRDclusterizerV1::ReadDigits(AliRawReader *rawReader)
928e9fae 151{
152 //
153 // Reads the digits arrays from the ddl file
154 //
155
4ab68796 156 AliTRDrawData raw;
4ab68796 157 fDigitsManager = raw.Raw2Digits(rawReader);
928e9fae 158
159 return kTRUE;
160
161}
162
f7336fa3 163//_____________________________________________________________________________
793ff80c 164Bool_t AliTRDclusterizerV1::MakeClusters()
f7336fa3 165{
166 //
167 // Generates the cluster.
168 //
169
6d50f529 170 Int_t row = 0;
171 Int_t col = 0;
172 Int_t time = 0;
173 Int_t icham = 0;
174 Int_t iplan = 0;
175 Int_t isect = 0;
176 Int_t iPad = 0;
177
178 AliTRDdataArrayI *digitsIn;
a6dd11e9 179 AliTRDdataArrayI *tracksIn;
f7336fa3 180
181 // Get the geometry
6d50f529 182 AliTRDgeometry *geo = AliTRDgeometry::GetGeometry(fRunLoader);
a6dd11e9 183
6d50f529 184 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
185 if (!calibration) {
4fad09c9 186 AliFatal("No AliTRDcalibDB instance available\n");
3551db50 187 return kFALSE;
188 }
189
6d50f529 190 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
191 if (!simParam) {
192 AliError("No AliTRDSimParam instance available\n");
3becff3c 193 return kFALSE;
194 }
195
6d50f529 196 AliTRDRecParam *recParam = AliTRDRecParam::Instance();
197 if (!recParam) {
198 AliError("No AliTRDRecParam instance available\n");
3551db50 199 return kFALSE;
200 }
201
6d50f529 202 AliTRDCommonParam *commonParam = AliTRDCommonParam::Instance();
203 if (!commonParam) {
204 AliError("Could not get common parameters\n");
3551db50 205 return kFALSE;
206 }
f7336fa3 207
6d50f529 208 // ADC threshols
a6dd11e9 209 Float_t ADCthreshold = simParam->GetADCthreshold();
3e1a3ad8 210 // Threshold value for the maximum
a6dd11e9 211 Float_t maxThresh = recParam->GetClusMaxThresh();
3e1a3ad8 212 // Threshold value for the digit signal
a6dd11e9 213 Float_t sigThresh = recParam->GetClusSigThresh();
6d50f529 214
56178ff4 215 // Detector wise calibration object for t0
216 const AliTRDCalDet *calT0Det = calibration->GetT0Det();
217
f7336fa3 218 // Iteration limit for unfolding procedure
8230f242 219 const Float_t kEpsilon = 0.01;
8230f242 220 const Int_t kNclus = 3;
221 const Int_t kNsig = 5;
a6dd11e9 222 const Int_t kNdict = AliTRDdigitsManager::kNDict;
223 const Int_t kNtrack = kNdict * kNclus;
3e1a3ad8 224
a5cadd36 225 Int_t iType = 0;
7ad19338 226 Int_t iUnfold = 0;
a5cadd36 227 Double_t ratioLeft = 1.0;
228 Double_t ratioRight = 1.0;
db30bf0f 229
a6dd11e9 230 Int_t iClusterROC = 0;
231
a5cadd36 232 Double_t padSignal[kNsig];
233 Double_t clusterSignal[kNclus];
234 Double_t clusterPads[kNclus];
f7336fa3 235
6d50f529 236 Int_t chamBeg = 0;
237 Int_t chamEnd = AliTRDgeometry::Ncham();
238 Int_t planBeg = 0;
239 Int_t planEnd = AliTRDgeometry::Nplan();
240 Int_t sectBeg = 0;
241 Int_t sectEnd = AliTRDgeometry::Nsect();
242 Int_t nTimeTotal = calibration->GetNumberOfTimeBins();
f7336fa3 243
a6dd11e9 244 Int_t dummy[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
245
6d50f529 246 AliDebug(1,Form("Number of Time Bins = %d.\n",nTimeTotal));
3becff3c 247
3e1a3ad8 248 // Start clustering in every chamber
6d50f529 249 for (icham = chamBeg; icham < chamEnd; icham++) {
250 for (iplan = planBeg; iplan < planEnd; iplan++) {
251 for (isect = sectBeg; isect < sectEnd; isect++) {
f7336fa3 252
a6dd11e9 253 Int_t idet = geo->GetDetector(iplan,icham,isect);
254
255 // Get the digits
256 digitsIn = fDigitsManager->GetDigits(idet);
257 // This is to take care of switched off super modules
258 if (digitsIn->GetNtime() == 0) {
259 continue;
260 }
261 digitsIn->Expand();
262 AliTRDdataArrayI *tracksTmp = fDigitsManager->GetDictionary(idet,0);
263 tracksTmp->Expand();
264
3becff3c 265 Int_t nRowMax = commonParam->GetRowMax(iplan,icham,isect);
266 Int_t nColMax = commonParam->GetColMax(iplan);
f7336fa3 267
6d50f529 268 AliTRDpadPlane *padPlane = commonParam->GetPadPlane(iplan,icham);
269
56178ff4 270 // Calibration object with pad wise values for t0
271 AliTRDCalROC *calT0ROC = calibration->GetT0ROC(idet);
272 // Calibration value for chamber wise t0
273 Float_t calT0DetValue = calT0Det->GetValue(idet);
274
db30bf0f 275 Int_t nClusters = 0;
276 Int_t nClusters2pad = 0;
277 Int_t nClusters3pad = 0;
278 Int_t nClusters4pad = 0;
279 Int_t nClusters5pad = 0;
280 Int_t nClustersLarge = 0;
3e1a3ad8 281
a6dd11e9 282 // Apply the gain and the tail cancelation via digital filter
6d50f529 283 AliTRDdataArrayF *digitsOut = new AliTRDdataArrayF(digitsIn->GetNrow()
284 ,digitsIn->GetNcol()
285 ,digitsIn->GetNtime());
a6dd11e9 286 Transform(digitsIn,digitsOut,idet,nRowMax,nColMax,nTimeTotal,ADCthreshold);
287
288 // Input digits are not needed any more
289 digitsIn->Compress(1,0);
6d50f529 290
3e1a3ad8 291 // Loop through the chamber and find the maxima
292 for ( row = 0; row < nRowMax; row++) {
de4b10e5 293 for ( col = 2; col < nColMax; col++) {
3e1a3ad8 294 for (time = 0; time < nTimeTotal; time++) {
295
11dc3a9e 296 Float_t signalL = TMath::Abs(digitsOut->GetDataUnchecked(row,col ,time));
297 Float_t signalM = TMath::Abs(digitsOut->GetDataUnchecked(row,col-1,time));
298 Float_t signalR = TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time));
3e1a3ad8 299
300 // Look for the maximum
db30bf0f 301 if (signalM >= maxThresh) {
6d50f529 302 if ((TMath::Abs(signalL) <= signalM) &&
21ee7de5 303 (TMath::Abs(signalR) < signalM)) {
6493a90f 304 if ((TMath::Abs(signalL) >= sigThresh) ||
305 (TMath::Abs(signalR) >= sigThresh)) {
a6dd11e9 306 // Maximum found, mark the position by a negative signal
307 digitsOut->SetDataUnchecked(row,col-1,time,-signalM);
308 }
3e1a3ad8 309 }
310 }
6d50f529 311
312 }
313 }
314 }
a6dd11e9 315 tracksTmp->Compress(1,0);
316
317 // The index to the first cluster of a given ROC
318 Int_t firstClusterROC = -1;
319 // The number of cluster in a given ROC
320 Int_t nClusterROC = 0;
3e1a3ad8 321
322 // Now check the maxima and calculate the cluster position
323 for ( row = 0; row < nRowMax ; row++) {
db30bf0f 324 for (time = 0; time < nTimeTotal; time++) {
325 for ( col = 1; col < nColMax-1; col++) {
3e1a3ad8 326
327 // Maximum found ?
a6dd11e9 328 if (digitsOut->GetDataUnchecked(row,col,time) < 0.0) {
f7336fa3 329
8230f242 330 for (iPad = 0; iPad < kNclus; iPad++) {
3e1a3ad8 331 Int_t iPadCol = col - 1 + iPad;
a6dd11e9 332 clusterSignal[iPad] =
333 TMath::Abs(digitsOut->GetDataUnchecked(row,iPadCol,time));
f7336fa3 334 }
335
db30bf0f 336 // Count the number of pads in the cluster
337 Int_t nPadCount = 0;
a6dd11e9 338 Int_t ii;
339 // Look to the left
340 ii = 0;
6d50f529 341 while (TMath::Abs(digitsOut->GetDataUnchecked(row,col-ii ,time)) >= sigThresh) {
db30bf0f 342 nPadCount++;
343 ii++;
344 if (col-ii < 0) break;
345 }
a6dd11e9 346 // Look to the right
db30bf0f 347 ii = 0;
6d50f529 348 while (TMath::Abs(digitsOut->GetDataUnchecked(row,col+ii+1,time)) >= sigThresh) {
db30bf0f 349 nPadCount++;
350 ii++;
351 if (col+ii+1 >= nColMax) break;
352 }
db30bf0f 353 nClusters++;
354 switch (nPadCount) {
355 case 2:
356 iType = 0;
357 nClusters2pad++;
358 break;
359 case 3:
360 iType = 1;
361 nClusters3pad++;
362 break;
363 case 4:
364 iType = 2;
365 nClusters4pad++;
366 break;
367 case 5:
368 iType = 3;
369 nClusters5pad++;
370 break;
371 default:
372 iType = 4;
373 nClustersLarge++;
374 break;
375 };
376
6d50f529 377 // Look for 5 pad cluster with minimum in the middle
db30bf0f 378 Bool_t fivePadCluster = kFALSE;
6d50f529 379 if (col < (nColMax - 3)) {
3becff3c 380 if (digitsOut->GetDataUnchecked(row,col+2,time) < 0) {
db30bf0f 381 fivePadCluster = kTRUE;
382 }
6d50f529 383 if ((fivePadCluster) && (col < (nColMax - 5))) {
3becff3c 384 if (digitsOut->GetDataUnchecked(row,col+4,time) >= sigThresh) {
db30bf0f 385 fivePadCluster = kFALSE;
386 }
387 }
6d50f529 388 if ((fivePadCluster) && (col > 1)) {
3becff3c 389 if (digitsOut->GetDataUnchecked(row,col-2,time) >= sigThresh) {
db30bf0f 390 fivePadCluster = kFALSE;
391 }
392 }
393 }
394
395 // 5 pad cluster
396 // Modify the signal of the overlapping pad for the left part
397 // of the cluster which remains from a previous unfolding
398 if (iUnfold) {
399 clusterSignal[0] *= ratioLeft;
7ad19338 400 iType = 5;
db30bf0f 401 iUnfold = 0;
402 }
403
404 // Unfold the 5 pad cluster
405 if (fivePadCluster) {
406 for (iPad = 0; iPad < kNsig; iPad++) {
3becff3c 407 padSignal[iPad] = TMath::Abs(digitsOut->GetDataUnchecked(row
a6dd11e9 408 ,col-1+iPad
409 ,time));
f7336fa3 410 }
db30bf0f 411 // Unfold the two maxima and set the signal on
412 // the overlapping pad to the ratio
17b26de4 413 ratioRight = Unfold(kEpsilon,iplan,padSignal);
db30bf0f 414 ratioLeft = 1.0 - ratioRight;
415 clusterSignal[2] *= ratioRight;
7ad19338 416 iType = 5;
db30bf0f 417 iUnfold = 1;
f7336fa3 418 }
f7336fa3 419
a5cadd36 420 Double_t clusterCharge = clusterSignal[0]
421 + clusterSignal[1]
422 + clusterSignal[2];
3e1a3ad8 423
db30bf0f 424 // The position of the cluster
a6dd11e9 425 clusterPads[0] = row + 0.5;
3e1a3ad8 426 // Take the shift of the additional time bins into account
dde59437 427 clusterPads[2] = time + 0.5;
3e1a3ad8 428
3551db50 429 if (recParam->LUTOn()) {
db30bf0f 430 // Calculate the position of the cluster by using the
431 // lookup table method
3becff3c 432 clusterPads[1] = recParam->LUTposition(iplan,clusterSignal[0]
6d50f529 433 ,clusterSignal[1]
434 ,clusterSignal[2]);
db30bf0f 435 }
436 else {
db30bf0f 437 // Calculate the position of the cluster by using the
438 // center of gravity method
a6dd11e9 439 for (Int_t i = 0; i < kNsig; i++) {
440 padSignal[i] = 0.0;
6d50f529 441 }
a6dd11e9 442 padSignal[2] = TMath::Abs(digitsOut->GetDataUnchecked(row,col ,time)); // Central pad
443 padSignal[1] = TMath::Abs(digitsOut->GetDataUnchecked(row,col-1,time)); // Left pad
444 padSignal[3] = TMath::Abs(digitsOut->GetDataUnchecked(row,col+1,time)); // Right pad
6d50f529 445 if ((col > 2) &&
446 (TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time)) < padSignal[1])) {
3becff3c 447 padSignal[0] = TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time));
7ad19338 448 }
6d50f529 449 if ((col < nColMax - 3) &&
450 (TMath::Abs(digitsOut->GetDataUnchecked(row,col+2,time)) < padSignal[3])) {
3becff3c 451 padSignal[4] = TMath::Abs(digitsOut->GetDataUnchecked(row,col+2,time));
7ad19338 452 }
6d50f529 453 clusterPads[1] = GetCOG(padSignal);
db30bf0f 454 }
455
a5cadd36 456 Double_t q0 = clusterSignal[0];
457 Double_t q1 = clusterSignal[1];
458 Double_t q2 = clusterSignal[2];
a6dd11e9 459 Double_t clusterSigmaY2 = (q1 * (q0 + q2) + 4.0 * q0 * q2)
460 / (clusterCharge*clusterCharge);
a819a5f7 461
6d50f529 462 //
3551db50 463 // Calculate the position and the error
6d50f529 464 //
465
56178ff4 466 // Correct for t0 (sum of chamber and pad wise values !!!)
467 Float_t calT0ROCValue = calT0ROC->GetValue(col,row);
468 Int_t clusterTimeBin = TMath::Nint(time - (calT0DetValue + calT0ROCValue));
6d50f529 469 Double_t colSize = padPlane->GetColSize(col);
470 Double_t rowSize = padPlane->GetRowSize(row);
cb86ff6e 471
a5cadd36 472 Double_t clusterPos[3];
a6dd11e9 473 clusterPos[0] = padPlane->GetColPos(col) - (clusterPads[1] + 0.5) * colSize;
474 clusterPos[1] = padPlane->GetRowPos(row) - 0.5 * rowSize;
6d50f529 475 clusterPos[2] = CalcXposFromTimebin(clusterPads[2],idet,col,row);
e2db9fdc 476 if (idet == 510) {
477 printf("------------> idet=%d, row=%d, col=%d, time=%d\n",idet,row,col,time);
478 printf(" pos = %f, %f, %f\n",clusterPos[0],clusterPos[1],clusterPos[2]);
479 }
a5cadd36 480 Double_t clusterSig[2];
a6dd11e9 481 clusterSig[0] = (clusterSigmaY2 + 1.0/12.0) * colSize*colSize;
482 clusterSig[1] = rowSize * rowSize / 12.0;
3551db50 483
a6dd11e9 484 // Add the cluster to the output array
485 // The track indices will be stored later
486 AliTRDcluster *cluster = AddCluster(clusterPos
487 ,clusterTimeBin
488 ,idet
489 ,clusterCharge
490 ,dummy
491 ,clusterSig
492 ,iType
493 ,clusterPads[1]);
494
495 // Store the amplitudes of the pads in the cluster for later analysis
496 Short_t signals[7] = { 0, 0, 0, 0, 0, 0, 0 };
6d50f529 497 for (Int_t jPad = col-3; jPad <= col+3; jPad++) {
a6dd11e9 498 if ((jPad < 0) ||
499 (jPad >= nColMax-1)) {
6d50f529 500 continue;
501 }
11dc3a9e 502 signals[jPad-col+3] = TMath::Nint(TMath::Abs(digitsOut->GetDataUnchecked(row,jPad,time)));
c85a4951 503 }
504 cluster->SetSignals(signals);
6d50f529 505
a6dd11e9 506 // Temporarily store the row, column and time bin of the center pad
507 // Used to later on assign the track indices
508 cluster->SetLabel( row,0);
509 cluster->SetLabel( col,1);
510 cluster->SetLabel(time,2);
6d50f529 511
a6dd11e9 512 // Store the index of the first cluster in the current ROC
513 if (firstClusterROC < 0) {
514 firstClusterROC = RecPoints()->GetEntriesFast() - 1;
515 }
516 // Count the number of cluster in the current ROC
517 nClusterROC++;
518
519 } // if: Maximum found ?
520
521 } // loop: pad columns
522 } // loop: time bins
523 } // loop: pad rows
11dc3a9e 524
525 delete digitsOut;
f7336fa3 526
a6dd11e9 527 //
528 // Add the track indices to the found clusters
529 //
530
531 // Temporary array to collect the track indices
532 Int_t *idxTracks = new Int_t[kNtrack*nClusterROC];
533
534 // Loop through the dictionary arrays one-by-one
535 // to keep memory consumption low
536 for (Int_t iDict = 0; iDict < kNdict; iDict++) {
537
538 tracksIn = fDigitsManager->GetDictionary(idet,iDict);
539 tracksIn->Expand();
540
541 // Loop though the clusters found in this ROC
542 for (iClusterROC = 0; iClusterROC < nClusterROC; iClusterROC++) {
543
544 AliTRDcluster *cluster = (AliTRDcluster *)
545 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
546 row = cluster->GetLabel(0);
547 col = cluster->GetLabel(1);
548 time = cluster->GetLabel(2);
549
550 for (iPad = 0; iPad < kNclus; iPad++) {
551 Int_t iPadCol = col - 1 + iPad;
552 Int_t index = tracksIn->GetDataUnchecked(row,iPadCol,time) - 1;
553 idxTracks[3*iPad+iDict + iClusterROC*kNtrack] = index;
554 }
555
556 }
557
558 // Compress the arrays
559 tracksIn->Compress(1,0);
560
561 }
562
563 // Copy the track indices into the cluster
564 // Loop though the clusters found in this ROC
565 for (iClusterROC = 0; iClusterROC < nClusterROC; iClusterROC++) {
566
567 AliTRDcluster *cluster = (AliTRDcluster *)
568 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
569 cluster->SetLabel(-9999,0);
570 cluster->SetLabel(-9999,1);
571 cluster->SetLabel(-9999,2);
572
573 cluster->AddTrackIndex(&idxTracks[iClusterROC*kNtrack]);
574
575 }
576
577 delete [] idxTracks;
f7336fa3 578
3e1a3ad8 579 // Write the cluster and reset the array
793ff80c 580 WriteClusters(idet);
bdbb05bb 581 ResetRecPoints();
6d50f529 582
a6dd11e9 583 } // loop: Sectors
584 } // loop: Planes
585 } // loop: Chambers
f7336fa3 586
f7336fa3 587 return kTRUE;
588
589}
590
a305677e 591//_____________________________________________________________________________
7ad19338 592Double_t AliTRDclusterizerV1::GetCOG(Double_t signal[5])
593{
594 //
6d50f529 595 // Get COG position
596 // Used for clusters with more than 3 pads - where LUT not applicable
597 //
598
a6dd11e9 599 Double_t sum = signal[0]
600 + signal[1]
601 + signal[2]
602 + signal[3]
603 + signal[4];
604
605 Double_t res = (0.0 * (-signal[0] + signal[4])
606 + (-signal[1] + signal[3])) / sum;
6d50f529 607
7ad19338 608 return res;
6d50f529 609
7ad19338 610}
611
f7336fa3 612//_____________________________________________________________________________
a6dd11e9 613Double_t AliTRDclusterizerV1::Unfold(Double_t eps, Int_t plane, Double_t *padSignal)
f7336fa3 614{
615 //
616 // Method to unfold neighbouring maxima.
617 // The charge ratio on the overlapping pad is calculated
618 // until there is no more change within the range given by eps.
619 // The resulting ratio is then returned to the calling method.
620 //
621
a6dd11e9 622 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
6d50f529 623 if (!calibration) {
624 AliError("No AliTRDcalibDB instance available\n");
6a739e92 625 return kFALSE;
3551db50 626 }
6a739e92 627
a5cadd36 628 Int_t irc = 0;
a6dd11e9 629 Int_t itStep = 0; // Count iteration steps
f7336fa3 630
a6dd11e9 631 Double_t ratio = 0.5; // Start value for ratio
632 Double_t prevRatio = 0.0; // Store previous ratio
f7336fa3 633
a6dd11e9 634 Double_t newLeftSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store left cluster signal
635 Double_t newRightSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store right cluster signal
636 Double_t newSignal[3] = { 0.0, 0.0, 0.0 };
f7336fa3 637
3e1a3ad8 638 // Start the iteration
f7336fa3 639 while ((TMath::Abs(prevRatio - ratio) > eps) && (itStep < 10)) {
640
641 itStep++;
642 prevRatio = ratio;
643
3e1a3ad8 644 // Cluster position according to charge ratio
a5cadd36 645 Double_t maxLeft = (ratio*padSignal[2] - padSignal[0])
646 / (padSignal[0] + padSignal[1] + ratio*padSignal[2]);
647 Double_t maxRight = (padSignal[4] - (1-ratio)*padSignal[2])
a6dd11e9 648 / ((1.0 - ratio)*padSignal[2] + padSignal[3] + padSignal[4]);
f7336fa3 649
3e1a3ad8 650 // Set cluster charge ratio
6a739e92 651 irc = calibration->PadResponse(1.0,maxLeft ,plane,newSignal);
a5cadd36 652 Double_t ampLeft = padSignal[1] / newSignal[1];
6a739e92 653 irc = calibration->PadResponse(1.0,maxRight,plane,newSignal);
a5cadd36 654 Double_t ampRight = padSignal[3] / newSignal[1];
f7336fa3 655
3e1a3ad8 656 // Apply pad response to parameters
6a739e92 657 irc = calibration->PadResponse(ampLeft ,maxLeft ,plane,newLeftSignal );
658 irc = calibration->PadResponse(ampRight,maxRight,plane,newRightSignal);
f7336fa3 659
3e1a3ad8 660 // Calculate new overlapping ratio
a5cadd36 661 ratio = TMath::Min((Double_t)1.0,newLeftSignal[2] /
a6dd11e9 662 (newLeftSignal[2] + newRightSignal[0]));
f7336fa3 663
664 }
665
666 return ratio;
667
668}
669
3becff3c 670//_____________________________________________________________________________
a6dd11e9 671void AliTRDclusterizerV1::Transform(AliTRDdataArrayI *digitsIn
672 , AliTRDdataArrayF *digitsOut
673 , Int_t idet, Int_t nRowMax
674 , Int_t nColMax, Int_t nTimeTotal
675 , Float_t ADCthreshold)
3becff3c 676{
3becff3c 677 //
cb86ff6e 678 // Apply gain factor
a6dd11e9 679 // Apply tail cancelation: Transform digitsIn to digitsOut
3becff3c 680 //
681
6d50f529 682 Int_t iRow = 0;
683 Int_t iCol = 0;
684 Int_t iTime = 0;
3becff3c 685
a6dd11e9 686 AliTRDRecParam *recParam = AliTRDRecParam::Instance();
6d50f529 687 if (!recParam) {
688 AliError("No AliTRDRecParam instance available\n");
3becff3c 689 return;
690 }
a6dd11e9 691 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
6d50f529 692 if (!calibration) {
693 AliError("No AliTRDcalibDB instance available\n");
694 return;
695 }
11dc3a9e 696
a6dd11e9 697 Double_t *inADC = new Double_t[nTimeTotal]; // ADC data before tail cancellation
698 Double_t *outADC = new Double_t[nTimeTotal]; // ADC data after tail cancellation
3becff3c 699
6d50f529 700 AliDebug(1,Form("Tail cancellation (nExp = %d) for detector %d.\n"
701 ,recParam->GetTCnexp(),idet));
702
56178ff4 703 // Calibration object with chamber wise values for the gain factor
704 const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
705 // Calibration object with pad wise values for the gain factor
706 AliTRDCalROC *calGainFactorROC = calibration->GetGainFactorROC(idet);
707 // Calibration value for chamber wise gain factors
708 Float_t calGainFactorDetValue = calGainFactorDet->GetValue(idet);
709
6d50f529 710 for (iRow = 0; iRow < nRowMax; iRow++ ) {
711 for (iCol = 0; iCol < nColMax; iCol++ ) {
a6dd11e9 712
56178ff4 713 Float_t calGainFactorROCValue = calGainFactorROC->GetValue(iCol,iRow);
714 Double_t gain = calGainFactorDetValue
715 * calGainFactorROCValue;
716
6d50f529 717 for (iTime = 0; iTime < nTimeTotal; iTime++) {
3becff3c 718
cb86ff6e 719 //
6d50f529 720 // Add gain
cb86ff6e 721 //
a6dd11e9 722 inADC[iTime] = digitsIn->GetDataUnchecked(iRow,iCol,iTime);
723 inADC[iTime] /= gain;
724 outADC[iTime] = inADC[iTime];
6d50f529 725
3becff3c 726 }
727
728 // Apply the tail cancelation via the digital filter
6d50f529 729 if (recParam->TCOn()) {
a305677e 730 DeConvExp(inADC,outADC,nTimeTotal,recParam->GetTCnexp());
3becff3c 731 }
732
6d50f529 733 for (iTime = 0; iTime < nTimeTotal; iTime++) {
734
3becff3c 735 // Store the amplitude of the digit if above threshold
a305677e 736 if (outADC[iTime] > ADCthreshold) {
11dc3a9e 737 digitsOut->SetDataUnchecked(iRow,iCol,iTime,outADC[iTime]);
3becff3c 738 }
739
740 }
741
742 }
3becff3c 743 }
744
745 delete [] inADC;
746 delete [] outADC;
747
748 return;
749
750}
751
3becff3c 752//_____________________________________________________________________________
a6dd11e9 753void AliTRDclusterizerV1::DeConvExp(Double_t *source, Double_t *target
754 , Int_t n, Int_t nexp)
3becff3c 755{
756 //
6d50f529 757 // Tail cancellation by deconvolution for PASA v4 TRF
3becff3c 758 //
759
760 Double_t rates[2];
761 Double_t coefficients[2];
762
6d50f529 763 // Initialization (coefficient = alpha, rates = lambda)
3becff3c 764 Double_t R1 = 1.0;
765 Double_t R2 = 1.0;
766 Double_t C1 = 0.5;
767 Double_t C2 = 0.5;
768
769 if (nexp == 1) { // 1 Exponentials
770 R1 = 1.156;
771 R2 = 0.130;
772 C1 = 0.066;
773 C2 = 0.000;
774 }
775 if (nexp == 2) { // 2 Exponentials
776 R1 = 1.156;
777 R2 = 0.130;
778 C1 = 0.114;
779 C2 = 0.624;
780 }
781
782 coefficients[0] = C1;
783 coefficients[1] = C2;
784
a6dd11e9 785 Double_t Dt = 0.1;
3becff3c 786
787 rates[0] = TMath::Exp(-Dt/(R1));
788 rates[1] = TMath::Exp(-Dt/(R2));
789
6d50f529 790 Int_t i = 0;
791 Int_t k = 0;
3becff3c 792
6d50f529 793 Double_t reminder[2];
794 Double_t correction;
795 Double_t result;
3becff3c 796
6d50f529 797 // Attention: computation order is important
798 correction = 0.0;
799 for (k = 0; k < nexp; k++) {
800 reminder[k] = 0.0;
801 }
802 for (i = 0; i < n; i++) {
a6dd11e9 803 result = (source[i] - correction); // No rescaling
3becff3c 804 target[i] = result;
805
6d50f529 806 for (k = 0; k < nexp; k++) {
807 reminder[k] = rates[k] * (reminder[k] + coefficients[k] * result);
808 }
809 correction = 0.0;
810 for (k = 0; k < nexp; k++) {
811 correction += reminder[k];
812 }
3becff3c 813 }
814
815}