Add the number of local boards
[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
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
88//_____________________________________________________________________________
f7336fa3 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
102//_____________________________________________________________________________
dd9a6ee3 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
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
127//_____________________________________________________________________________
f7336fa3 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
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
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);
40609f3f 183 if (!geo) {
184 AliWarning("Loading default TRD geometry!");
185 geo = new AliTRDgeometry();
186 }
a6dd11e9 187
6d50f529 188 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
189 if (!calibration) {
4fad09c9 190 AliFatal("No AliTRDcalibDB instance available\n");
3551db50 191 return kFALSE;
192 }
193
6d50f529 194 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
195 if (!simParam) {
196 AliError("No AliTRDSimParam instance available\n");
3becff3c 197 return kFALSE;
198 }
199
6d50f529 200 AliTRDRecParam *recParam = AliTRDRecParam::Instance();
201 if (!recParam) {
202 AliError("No AliTRDRecParam instance available\n");
3551db50 203 return kFALSE;
204 }
205
6d50f529 206 AliTRDCommonParam *commonParam = AliTRDCommonParam::Instance();
207 if (!commonParam) {
208 AliError("Could not get common parameters\n");
3551db50 209 return kFALSE;
210 }
f7336fa3 211
8ec071c8 212 // ADC thresholds
a6dd11e9 213 Float_t ADCthreshold = simParam->GetADCthreshold();
3e1a3ad8 214 // Threshold value for the maximum
a6dd11e9 215 Float_t maxThresh = recParam->GetClusMaxThresh();
3e1a3ad8 216 // Threshold value for the digit signal
a6dd11e9 217 Float_t sigThresh = recParam->GetClusSigThresh();
6d50f529 218
56178ff4 219 // Detector wise calibration object for t0
8ec071c8 220 const AliTRDCalDet *calT0Det = calibration->GetT0Det();
221 // Detector wise calibration object for the gain factors
222 const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
56178ff4 223
f7336fa3 224 // Iteration limit for unfolding procedure
8230f242 225 const Float_t kEpsilon = 0.01;
8230f242 226 const Int_t kNclus = 3;
227 const Int_t kNsig = 5;
a6dd11e9 228 const Int_t kNdict = AliTRDdigitsManager::kNDict;
229 const Int_t kNtrack = kNdict * kNclus;
3e1a3ad8 230
a5cadd36 231 Int_t iType = 0;
7ad19338 232 Int_t iUnfold = 0;
a5cadd36 233 Double_t ratioLeft = 1.0;
234 Double_t ratioRight = 1.0;
db30bf0f 235
a6dd11e9 236 Int_t iClusterROC = 0;
237
a5cadd36 238 Double_t padSignal[kNsig];
239 Double_t clusterSignal[kNclus];
240 Double_t clusterPads[kNclus];
f7336fa3 241
6d50f529 242 Int_t chamBeg = 0;
243 Int_t chamEnd = AliTRDgeometry::Ncham();
244 Int_t planBeg = 0;
245 Int_t planEnd = AliTRDgeometry::Nplan();
246 Int_t sectBeg = 0;
247 Int_t sectEnd = AliTRDgeometry::Nsect();
248 Int_t nTimeTotal = calibration->GetNumberOfTimeBins();
f7336fa3 249
a6dd11e9 250 Int_t dummy[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
251
6d50f529 252 AliDebug(1,Form("Number of Time Bins = %d.\n",nTimeTotal));
3becff3c 253
3e1a3ad8 254 // Start clustering in every chamber
6d50f529 255 for (icham = chamBeg; icham < chamEnd; icham++) {
256 for (iplan = planBeg; iplan < planEnd; iplan++) {
257 for (isect = sectBeg; isect < sectEnd; isect++) {
f7336fa3 258
a6dd11e9 259 Int_t idet = geo->GetDetector(iplan,icham,isect);
260
261 // Get the digits
262 digitsIn = fDigitsManager->GetDigits(idet);
263 // This is to take care of switched off super modules
264 if (digitsIn->GetNtime() == 0) {
265 continue;
266 }
267 digitsIn->Expand();
268 AliTRDdataArrayI *tracksTmp = fDigitsManager->GetDictionary(idet,0);
269 tracksTmp->Expand();
270
3becff3c 271 Int_t nRowMax = commonParam->GetRowMax(iplan,icham,isect);
272 Int_t nColMax = commonParam->GetColMax(iplan);
f7336fa3 273
6d50f529 274 AliTRDpadPlane *padPlane = commonParam->GetPadPlane(iplan,icham);
275
56178ff4 276 // Calibration object with pad wise values for t0
8ec071c8 277 AliTRDCalROC *calT0ROC = calibration->GetT0ROC(idet);
278 // Calibration object with pad wise values for the gain factors
279 AliTRDCalROC *calGainFactorROC = calibration->GetGainFactorROC(idet);
56178ff4 280 // Calibration value for chamber wise t0
8ec071c8 281 Float_t calT0DetValue = calT0Det->GetValue(idet);
282 // Calibration value for chamber wise gain factor
283 Float_t calGainFactorDetValue = calGainFactorDet->GetValue(idet);
56178ff4 284
db30bf0f 285 Int_t nClusters = 0;
286 Int_t nClusters2pad = 0;
287 Int_t nClusters3pad = 0;
288 Int_t nClusters4pad = 0;
289 Int_t nClusters5pad = 0;
290 Int_t nClustersLarge = 0;
3e1a3ad8 291
a6dd11e9 292 // Apply the gain and the tail cancelation via digital filter
6d50f529 293 AliTRDdataArrayF *digitsOut = new AliTRDdataArrayF(digitsIn->GetNrow()
294 ,digitsIn->GetNcol()
8ec071c8 295 ,digitsIn->GetNtime());
296 Transform(digitsIn
297 ,digitsOut
298 ,nRowMax,nColMax,nTimeTotal
299 ,ADCthreshold
300 ,calGainFactorROC
301 ,calGainFactorDetValue);
a6dd11e9 302
303 // Input digits are not needed any more
304 digitsIn->Compress(1,0);
6d50f529 305
3e1a3ad8 306 // Loop through the chamber and find the maxima
307 for ( row = 0; row < nRowMax; row++) {
de4b10e5 308 for ( col = 2; col < nColMax; col++) {
3e1a3ad8 309 for (time = 0; time < nTimeTotal; time++) {
310
11dc3a9e 311 Float_t signalM = TMath::Abs(digitsOut->GetDataUnchecked(row,col-1,time));
3e1a3ad8 312
313 // Look for the maximum
db30bf0f 314 if (signalM >= maxThresh) {
6a242715 315
316 Float_t signalL = TMath::Abs(digitsOut->GetDataUnchecked(row,col ,time));
317 Float_t signalR = TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time));
318
6d50f529 319 if ((TMath::Abs(signalL) <= signalM) &&
21ee7de5 320 (TMath::Abs(signalR) < signalM)) {
6493a90f 321 if ((TMath::Abs(signalL) >= sigThresh) ||
322 (TMath::Abs(signalR) >= sigThresh)) {
a6dd11e9 323 // Maximum found, mark the position by a negative signal
324 digitsOut->SetDataUnchecked(row,col-1,time,-signalM);
325 }
3e1a3ad8 326 }
6a242715 327
3e1a3ad8 328 }
6d50f529 329
330 }
331 }
332 }
a6dd11e9 333 tracksTmp->Compress(1,0);
334
335 // The index to the first cluster of a given ROC
336 Int_t firstClusterROC = -1;
337 // The number of cluster in a given ROC
338 Int_t nClusterROC = 0;
3e1a3ad8 339
340 // Now check the maxima and calculate the cluster position
341 for ( row = 0; row < nRowMax ; row++) {
db30bf0f 342 for (time = 0; time < nTimeTotal; time++) {
343 for ( col = 1; col < nColMax-1; col++) {
3e1a3ad8 344
345 // Maximum found ?
a6dd11e9 346 if (digitsOut->GetDataUnchecked(row,col,time) < 0.0) {
f7336fa3 347
8230f242 348 for (iPad = 0; iPad < kNclus; iPad++) {
3e1a3ad8 349 Int_t iPadCol = col - 1 + iPad;
a6dd11e9 350 clusterSignal[iPad] =
351 TMath::Abs(digitsOut->GetDataUnchecked(row,iPadCol,time));
f7336fa3 352 }
353
db30bf0f 354 // Count the number of pads in the cluster
355 Int_t nPadCount = 0;
a6dd11e9 356 Int_t ii;
357 // Look to the left
358 ii = 0;
6d50f529 359 while (TMath::Abs(digitsOut->GetDataUnchecked(row,col-ii ,time)) >= sigThresh) {
db30bf0f 360 nPadCount++;
361 ii++;
362 if (col-ii < 0) break;
363 }
a6dd11e9 364 // Look to the right
db30bf0f 365 ii = 0;
6d50f529 366 while (TMath::Abs(digitsOut->GetDataUnchecked(row,col+ii+1,time)) >= sigThresh) {
db30bf0f 367 nPadCount++;
368 ii++;
369 if (col+ii+1 >= nColMax) break;
370 }
db30bf0f 371 nClusters++;
372 switch (nPadCount) {
373 case 2:
374 iType = 0;
375 nClusters2pad++;
376 break;
377 case 3:
378 iType = 1;
379 nClusters3pad++;
380 break;
381 case 4:
382 iType = 2;
383 nClusters4pad++;
384 break;
385 case 5:
386 iType = 3;
387 nClusters5pad++;
388 break;
389 default:
390 iType = 4;
391 nClustersLarge++;
392 break;
393 };
394
6d50f529 395 // Look for 5 pad cluster with minimum in the middle
db30bf0f 396 Bool_t fivePadCluster = kFALSE;
6d50f529 397 if (col < (nColMax - 3)) {
3becff3c 398 if (digitsOut->GetDataUnchecked(row,col+2,time) < 0) {
db30bf0f 399 fivePadCluster = kTRUE;
400 }
6d50f529 401 if ((fivePadCluster) && (col < (nColMax - 5))) {
3becff3c 402 if (digitsOut->GetDataUnchecked(row,col+4,time) >= sigThresh) {
db30bf0f 403 fivePadCluster = kFALSE;
404 }
405 }
6d50f529 406 if ((fivePadCluster) && (col > 1)) {
3becff3c 407 if (digitsOut->GetDataUnchecked(row,col-2,time) >= sigThresh) {
db30bf0f 408 fivePadCluster = kFALSE;
409 }
410 }
411 }
412
413 // 5 pad cluster
414 // Modify the signal of the overlapping pad for the left part
415 // of the cluster which remains from a previous unfolding
416 if (iUnfold) {
417 clusterSignal[0] *= ratioLeft;
7ad19338 418 iType = 5;
db30bf0f 419 iUnfold = 0;
420 }
421
422 // Unfold the 5 pad cluster
423 if (fivePadCluster) {
424 for (iPad = 0; iPad < kNsig; iPad++) {
3becff3c 425 padSignal[iPad] = TMath::Abs(digitsOut->GetDataUnchecked(row
a6dd11e9 426 ,col-1+iPad
427 ,time));
f7336fa3 428 }
db30bf0f 429 // Unfold the two maxima and set the signal on
430 // the overlapping pad to the ratio
17b26de4 431 ratioRight = Unfold(kEpsilon,iplan,padSignal);
db30bf0f 432 ratioLeft = 1.0 - ratioRight;
433 clusterSignal[2] *= ratioRight;
7ad19338 434 iType = 5;
db30bf0f 435 iUnfold = 1;
f7336fa3 436 }
f7336fa3 437
a5cadd36 438 Double_t clusterCharge = clusterSignal[0]
439 + clusterSignal[1]
440 + clusterSignal[2];
3e1a3ad8 441
db30bf0f 442 // The position of the cluster
a6dd11e9 443 clusterPads[0] = row + 0.5;
3e1a3ad8 444 // Take the shift of the additional time bins into account
dde59437 445 clusterPads[2] = time + 0.5;
3e1a3ad8 446
3551db50 447 if (recParam->LUTOn()) {
db30bf0f 448 // Calculate the position of the cluster by using the
449 // lookup table method
3becff3c 450 clusterPads[1] = recParam->LUTposition(iplan,clusterSignal[0]
6d50f529 451 ,clusterSignal[1]
452 ,clusterSignal[2]);
db30bf0f 453 }
454 else {
db30bf0f 455 // Calculate the position of the cluster by using the
456 // center of gravity method
a6dd11e9 457 for (Int_t i = 0; i < kNsig; i++) {
458 padSignal[i] = 0.0;
6d50f529 459 }
a6dd11e9 460 padSignal[2] = TMath::Abs(digitsOut->GetDataUnchecked(row,col ,time)); // Central pad
461 padSignal[1] = TMath::Abs(digitsOut->GetDataUnchecked(row,col-1,time)); // Left pad
462 padSignal[3] = TMath::Abs(digitsOut->GetDataUnchecked(row,col+1,time)); // Right pad
6d50f529 463 if ((col > 2) &&
464 (TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time)) < padSignal[1])) {
3becff3c 465 padSignal[0] = TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time));
7ad19338 466 }
6d50f529 467 if ((col < nColMax - 3) &&
468 (TMath::Abs(digitsOut->GetDataUnchecked(row,col+2,time)) < padSignal[3])) {
3becff3c 469 padSignal[4] = TMath::Abs(digitsOut->GetDataUnchecked(row,col+2,time));
7ad19338 470 }
6d50f529 471 clusterPads[1] = GetCOG(padSignal);
db30bf0f 472 }
473
a5cadd36 474 Double_t q0 = clusterSignal[0];
475 Double_t q1 = clusterSignal[1];
476 Double_t q2 = clusterSignal[2];
a6dd11e9 477 Double_t clusterSigmaY2 = (q1 * (q0 + q2) + 4.0 * q0 * q2)
478 / (clusterCharge*clusterCharge);
a819a5f7 479
6d50f529 480 //
3551db50 481 // Calculate the position and the error
6d50f529 482 //
483
56178ff4 484 // Correct for t0 (sum of chamber and pad wise values !!!)
485 Float_t calT0ROCValue = calT0ROC->GetValue(col,row);
486 Int_t clusterTimeBin = TMath::Nint(time - (calT0DetValue + calT0ROCValue));
6d50f529 487 Double_t colSize = padPlane->GetColSize(col);
488 Double_t rowSize = padPlane->GetRowSize(row);
cb86ff6e 489
a5cadd36 490 Double_t clusterPos[3];
a6dd11e9 491 clusterPos[0] = padPlane->GetColPos(col) - (clusterPads[1] + 0.5) * colSize;
492 clusterPos[1] = padPlane->GetRowPos(row) - 0.5 * rowSize;
6d50f529 493 clusterPos[2] = CalcXposFromTimebin(clusterPads[2],idet,col,row);
a5cadd36 494 Double_t clusterSig[2];
a6dd11e9 495 clusterSig[0] = (clusterSigmaY2 + 1.0/12.0) * colSize*colSize;
496 clusterSig[1] = rowSize * rowSize / 12.0;
3551db50 497
a6dd11e9 498 // Add the cluster to the output array
499 // The track indices will be stored later
500 AliTRDcluster *cluster = AddCluster(clusterPos
501 ,clusterTimeBin
502 ,idet
503 ,clusterCharge
504 ,dummy
505 ,clusterSig
506 ,iType
507 ,clusterPads[1]);
508
509 // Store the amplitudes of the pads in the cluster for later analysis
510 Short_t signals[7] = { 0, 0, 0, 0, 0, 0, 0 };
6d50f529 511 for (Int_t jPad = col-3; jPad <= col+3; jPad++) {
a6dd11e9 512 if ((jPad < 0) ||
513 (jPad >= nColMax-1)) {
6d50f529 514 continue;
515 }
11dc3a9e 516 signals[jPad-col+3] = TMath::Nint(TMath::Abs(digitsOut->GetDataUnchecked(row,jPad,time)));
c85a4951 517 }
518 cluster->SetSignals(signals);
6d50f529 519
a6dd11e9 520 // Temporarily store the row, column and time bin of the center pad
521 // Used to later on assign the track indices
522 cluster->SetLabel( row,0);
523 cluster->SetLabel( col,1);
524 cluster->SetLabel(time,2);
6d50f529 525
a6dd11e9 526 // Store the index of the first cluster in the current ROC
527 if (firstClusterROC < 0) {
528 firstClusterROC = RecPoints()->GetEntriesFast() - 1;
529 }
530 // Count the number of cluster in the current ROC
531 nClusterROC++;
532
533 } // if: Maximum found ?
534
535 } // loop: pad columns
536 } // loop: time bins
537 } // loop: pad rows
11dc3a9e 538
539 delete digitsOut;
f7336fa3 540
a6dd11e9 541 //
542 // Add the track indices to the found clusters
543 //
544
545 // Temporary array to collect the track indices
546 Int_t *idxTracks = new Int_t[kNtrack*nClusterROC];
547
548 // Loop through the dictionary arrays one-by-one
549 // to keep memory consumption low
550 for (Int_t iDict = 0; iDict < kNdict; iDict++) {
551
552 tracksIn = fDigitsManager->GetDictionary(idet,iDict);
553 tracksIn->Expand();
554
555 // Loop though the clusters found in this ROC
556 for (iClusterROC = 0; iClusterROC < nClusterROC; iClusterROC++) {
557
558 AliTRDcluster *cluster = (AliTRDcluster *)
559 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
560 row = cluster->GetLabel(0);
561 col = cluster->GetLabel(1);
562 time = cluster->GetLabel(2);
563
564 for (iPad = 0; iPad < kNclus; iPad++) {
565 Int_t iPadCol = col - 1 + iPad;
566 Int_t index = tracksIn->GetDataUnchecked(row,iPadCol,time) - 1;
567 idxTracks[3*iPad+iDict + iClusterROC*kNtrack] = index;
568 }
569
570 }
571
572 // Compress the arrays
573 tracksIn->Compress(1,0);
574
575 }
576
577 // Copy the track indices into the cluster
578 // Loop though the clusters found in this ROC
579 for (iClusterROC = 0; iClusterROC < nClusterROC; iClusterROC++) {
580
581 AliTRDcluster *cluster = (AliTRDcluster *)
582 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
583 cluster->SetLabel(-9999,0);
584 cluster->SetLabel(-9999,1);
585 cluster->SetLabel(-9999,2);
586
587 cluster->AddTrackIndex(&idxTracks[iClusterROC*kNtrack]);
588
589 }
590
591 delete [] idxTracks;
f7336fa3 592
3e1a3ad8 593 // Write the cluster and reset the array
793ff80c 594 WriteClusters(idet);
bdbb05bb 595 ResetRecPoints();
6d50f529 596
a6dd11e9 597 } // loop: Sectors
598 } // loop: Planes
599 } // loop: Chambers
f7336fa3 600
f7336fa3 601 return kTRUE;
602
603}
604
a305677e 605//_____________________________________________________________________________
7ad19338 606Double_t AliTRDclusterizerV1::GetCOG(Double_t signal[5])
607{
608 //
6d50f529 609 // Get COG position
610 // Used for clusters with more than 3 pads - where LUT not applicable
611 //
612
a6dd11e9 613 Double_t sum = signal[0]
614 + signal[1]
615 + signal[2]
616 + signal[3]
617 + signal[4];
618
619 Double_t res = (0.0 * (-signal[0] + signal[4])
620 + (-signal[1] + signal[3])) / sum;
6d50f529 621
7ad19338 622 return res;
6d50f529 623
7ad19338 624}
625
f7336fa3 626//_____________________________________________________________________________
a6dd11e9 627Double_t AliTRDclusterizerV1::Unfold(Double_t eps, Int_t plane, Double_t *padSignal)
f7336fa3 628{
629 //
630 // Method to unfold neighbouring maxima.
631 // The charge ratio on the overlapping pad is calculated
632 // until there is no more change within the range given by eps.
633 // The resulting ratio is then returned to the calling method.
634 //
635
a6dd11e9 636 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
6d50f529 637 if (!calibration) {
638 AliError("No AliTRDcalibDB instance available\n");
6a739e92 639 return kFALSE;
3551db50 640 }
6a739e92 641
a5cadd36 642 Int_t irc = 0;
a6dd11e9 643 Int_t itStep = 0; // Count iteration steps
f7336fa3 644
a6dd11e9 645 Double_t ratio = 0.5; // Start value for ratio
646 Double_t prevRatio = 0.0; // Store previous ratio
f7336fa3 647
a6dd11e9 648 Double_t newLeftSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store left cluster signal
649 Double_t newRightSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store right cluster signal
650 Double_t newSignal[3] = { 0.0, 0.0, 0.0 };
f7336fa3 651
3e1a3ad8 652 // Start the iteration
f7336fa3 653 while ((TMath::Abs(prevRatio - ratio) > eps) && (itStep < 10)) {
654
655 itStep++;
656 prevRatio = ratio;
657
3e1a3ad8 658 // Cluster position according to charge ratio
a5cadd36 659 Double_t maxLeft = (ratio*padSignal[2] - padSignal[0])
660 / (padSignal[0] + padSignal[1] + ratio*padSignal[2]);
661 Double_t maxRight = (padSignal[4] - (1-ratio)*padSignal[2])
a6dd11e9 662 / ((1.0 - ratio)*padSignal[2] + padSignal[3] + padSignal[4]);
f7336fa3 663
3e1a3ad8 664 // Set cluster charge ratio
6a739e92 665 irc = calibration->PadResponse(1.0,maxLeft ,plane,newSignal);
a5cadd36 666 Double_t ampLeft = padSignal[1] / newSignal[1];
6a739e92 667 irc = calibration->PadResponse(1.0,maxRight,plane,newSignal);
a5cadd36 668 Double_t ampRight = padSignal[3] / newSignal[1];
f7336fa3 669
3e1a3ad8 670 // Apply pad response to parameters
6a739e92 671 irc = calibration->PadResponse(ampLeft ,maxLeft ,plane,newLeftSignal );
672 irc = calibration->PadResponse(ampRight,maxRight,plane,newRightSignal);
f7336fa3 673
3e1a3ad8 674 // Calculate new overlapping ratio
a5cadd36 675 ratio = TMath::Min((Double_t)1.0,newLeftSignal[2] /
a6dd11e9 676 (newLeftSignal[2] + newRightSignal[0]));
f7336fa3 677
678 }
679
680 return ratio;
681
682}
683
3becff3c 684//_____________________________________________________________________________
a6dd11e9 685void AliTRDclusterizerV1::Transform(AliTRDdataArrayI *digitsIn
686 , AliTRDdataArrayF *digitsOut
8ec071c8 687 , Int_t nRowMax, Int_t nColMax, Int_t nTimeTotal
688 , Float_t ADCthreshold
689 , AliTRDCalROC *calGainFactorROC
690 , Float_t calGainFactorDetValue)
3becff3c 691{
3becff3c 692 //
cb86ff6e 693 // Apply gain factor
a6dd11e9 694 // Apply tail cancelation: Transform digitsIn to digitsOut
3becff3c 695 //
696
6d50f529 697 Int_t iRow = 0;
698 Int_t iCol = 0;
699 Int_t iTime = 0;
3becff3c 700
a6dd11e9 701 AliTRDRecParam *recParam = AliTRDRecParam::Instance();
6d50f529 702 if (!recParam) {
703 AliError("No AliTRDRecParam instance available\n");
3becff3c 704 return;
705 }
11dc3a9e 706
a6dd11e9 707 Double_t *inADC = new Double_t[nTimeTotal]; // ADC data before tail cancellation
708 Double_t *outADC = new Double_t[nTimeTotal]; // ADC data after tail cancellation
3becff3c 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}