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