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