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