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