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