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