]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDclusterizerV1.cxx
Removing obsolete include
[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// //
21// TRD cluster finder for the slow simulator.
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"
793ff80c 34
f7336fa3 35#include "AliTRDclusterizerV1.h"
f7336fa3 36#include "AliTRDgeometry.h"
6f1e466d 37#include "AliTRDdataArrayF.h"
793ff80c 38#include "AliTRDdataArrayI.h"
39#include "AliTRDdigitsManager.h"
a5cadd36 40#include "AliTRDpadPlane.h"
928e9fae 41#include "AliTRDrawData.h"
3551db50 42#include "AliTRDcalibDB.h"
3becff3c 43#include "AliTRDSimParam.h"
3551db50 44#include "AliTRDRecParam.h"
45#include "AliTRDCommonParam.h"
c85a4951 46#include "AliTRDcluster.h"
f7336fa3 47
48ClassImp(AliTRDclusterizerV1)
49
50//_____________________________________________________________________________
51AliTRDclusterizerV1::AliTRDclusterizerV1():AliTRDclusterizer()
52{
53 //
54 // AliTRDclusterizerV1 default constructor
55 //
56
17b26de4 57 fDigitsManager = 0;
db30bf0f 58
f7336fa3 59}
60
61//_____________________________________________________________________________
62AliTRDclusterizerV1::AliTRDclusterizerV1(const Text_t* name, const Text_t* title)
63 :AliTRDclusterizer(name,title)
64{
65 //
66 // AliTRDclusterizerV1 default constructor
67 //
68
6f1e466d 69 fDigitsManager = new AliTRDdigitsManager();
17b26de4 70 fDigitsManager->CreateArrays();
f7336fa3 71
72}
73
8230f242 74//_____________________________________________________________________________
dd9a6ee3 75AliTRDclusterizerV1::AliTRDclusterizerV1(const AliTRDclusterizerV1 &c)
73ae7b59 76:AliTRDclusterizer(c)
8230f242 77{
78 //
79 // AliTRDclusterizerV1 copy constructor
80 //
81
dd9a6ee3 82 ((AliTRDclusterizerV1 &) c).Copy(*this);
8230f242 83
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) {
17b26de4 133 printf("<AliTRDclusterizerV1::ReadDigits> ");
f7336fa3 134 printf("No input file open\n");
135 return kFALSE;
136 }
88cb7938 137 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
138 if (!loader->TreeD()) loader->LoadDigits();
abaf1f1d 139
f7336fa3 140 // Read in the digit arrays
88cb7938 141 return (fDigitsManager->ReadDigits(loader->TreeD()));
f7336fa3 142
143}
144
928e9fae 145//_____________________________________________________________________________
146Bool_t AliTRDclusterizerV1::ReadDigits(AliRawReader* rawReader)
147{
148 //
149 // Reads the digits arrays from the ddl file
150 //
151
4ab68796 152 AliTRDrawData raw;
153 raw.SetDebug(1);
928e9fae 154
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
168 Int_t row, col, time;
169
bdbb05bb 170 /*
3e1a3ad8 171 if (fTRD->IsVersion() != 1) {
17b26de4 172 printf("<AliTRDclusterizerV1::MakeCluster> ");
f7336fa3 173 printf("TRD must be version 1 (slow simulator).\n");
174 return kFALSE;
175 }
bdbb05bb 176 */
f7336fa3 177
178 // Get the geometry
cb86ff6e 179 AliTRDgeometry *geo = AliTRDgeometry::GetGeometry(fRunLoader);
3551db50 180 AliTRDcalibDB* calibration = AliTRDcalibDB::Instance();
181 if (!calibration)
182 {
3becff3c 183 printf("<AliTRDclusterizerV1::MakeCluster> ");
3551db50 184 printf("ERROR getting instance of AliTRDcalibDB");
185 return kFALSE;
186 }
187
3becff3c 188 AliTRDSimParam* simParam = AliTRDSimParam::Instance();
189 if (!simParam)
190 {
191 printf("<AliTRDclusterizerV1::MakeCluster> ");
192 printf("ERROR getting instance of AliTRDSimParam");
193 return kFALSE;
194 }
195
3551db50 196 AliTRDRecParam* recParam = AliTRDRecParam::Instance();
197 if (!recParam)
198 {
3becff3c 199 printf("<AliTRDclusterizerV1::MakeCluster> ");
3551db50 200 printf("ERROR getting instance of AliTRDRecParam");
201 return kFALSE;
202 }
203
204 AliTRDCommonParam* commonParam = AliTRDCommonParam::Instance();
205 if (!commonParam)
206 {
3becff3c 207 printf("<AliTRDclusterizerV1::MakeDigits> ");
3551db50 208 printf("Could not get common params\n");
209 return kFALSE;
210 }
211
a305677e 212 Float_t ADCthreshold = simParam->GetADCthreshold();
213
47517f42 214 if (fVerbose > 0) {
3551db50 215 //printf("<AliTRDclusterizerV1::MakeCluster> ");
216 //printf("OmegaTau = %f \n",omegaTau);
17b26de4 217 printf("<AliTRDclusterizerV1::MakeCluster> ");
47517f42 218 printf("Start creating clusters.\n");
219 }
f7336fa3 220
3becff3c 221 AliTRDdataArrayI *digitsIn;
793ff80c 222 AliTRDdataArrayI *track0;
223 AliTRDdataArrayI *track1;
224 AliTRDdataArrayI *track2;
f7336fa3 225
3e1a3ad8 226 // Threshold value for the maximum
11dc3a9e 227 Float_t maxThresh = recParam->GetClusMaxThresh();
3e1a3ad8 228 // Threshold value for the digit signal
11dc3a9e 229 Float_t sigThresh = recParam->GetClusSigThresh();
f7336fa3 230 // Iteration limit for unfolding procedure
8230f242 231 const Float_t kEpsilon = 0.01;
f7336fa3 232
8230f242 233 const Int_t kNclus = 3;
234 const Int_t kNsig = 5;
3e1a3ad8 235 const Int_t kNtrack = 3 * kNclus;
236
a5cadd36 237 Int_t iType = 0;
7ad19338 238 Int_t iUnfold = 0;
a5cadd36 239 Double_t ratioLeft = 1.0;
240 Double_t ratioRight = 1.0;
db30bf0f 241
7ad19338 242 //
a5cadd36 243 Double_t padSignal[kNsig];
244 Double_t clusterSignal[kNclus];
245 Double_t clusterPads[kNclus];
11dc3a9e 246 Int_t clusterTracks[kNtrack];
f7336fa3 247
a5cadd36 248 Int_t chamBeg = 0;
249 Int_t chamEnd = AliTRDgeometry::Ncham();
250 Int_t planBeg = 0;
251 Int_t planEnd = AliTRDgeometry::Nplan();
252 Int_t sectBeg = 0;
253 Int_t sectEnd = AliTRDgeometry::Nsect();
f7336fa3 254
3becff3c 255 Int_t nTimeTotal = calibration->GetNumberOfTimeBins();
256
257 if (fVerbose > 0) {
258 printf("<AliTRDclusterizerV1::MakeCluster> ");
259 printf("Number of Time Bins = %d.\n",nTimeTotal);
260 }
261
3e1a3ad8 262 // Start clustering in every chamber
f7336fa3 263 for (Int_t icham = chamBeg; icham < chamEnd; icham++) {
264 for (Int_t iplan = planBeg; iplan < planEnd; iplan++) {
265 for (Int_t isect = sectBeg; isect < sectEnd; isect++) {
266
3becff3c 267 Int_t idet = geo->GetDetector(iplan,icham,isect);
268
269 Int_t nRowMax = commonParam->GetRowMax(iplan,icham,isect);
270 Int_t nColMax = commonParam->GetColMax(iplan);
f7336fa3 271
db30bf0f 272 Int_t nClusters = 0;
273 Int_t nClusters2pad = 0;
274 Int_t nClusters3pad = 0;
275 Int_t nClusters4pad = 0;
276 Int_t nClusters5pad = 0;
277 Int_t nClustersLarge = 0;
3e1a3ad8 278
47517f42 279 if (fVerbose > 0) {
17b26de4 280 printf("<AliTRDclusterizerV1::MakeCluster> ");
47517f42 281 printf("Analyzing chamber %d, plane %d, sector %d.\n"
282 ,icham,iplan,isect);
283 }
f7336fa3 284
3551db50 285 AliTRDpadPlane *padPlane = commonParam->GetPadPlane(iplan,icham);
f7336fa3 286
3e1a3ad8 287 // Get the digits
11dc3a9e 288 digitsIn = fDigitsManager->GetDigits(idet);
3becff3c 289 digitsIn->Expand();
11dc3a9e 290 AliTRDdataArrayF *digitsOut = new AliTRDdataArrayF(digitsIn->GetNrow(), digitsIn->GetNcol(), digitsIn->GetNtime());
3becff3c 291
11dc3a9e 292 Transform(digitsIn, digitsOut, idet, nRowMax, nColMax, nTimeTotal, ADCthreshold);
3becff3c 293
793ff80c 294 track0 = fDigitsManager->GetDictionary(idet,0);
3e1a3ad8 295 track0->Expand();
793ff80c 296 track1 = fDigitsManager->GetDictionary(idet,1);
3e1a3ad8 297 track1->Expand();
793ff80c 298 track2 = fDigitsManager->GetDictionary(idet,2);
3e1a3ad8 299 track2->Expand();
300
301 // Loop through the chamber and find the maxima
302 for ( row = 0; row < nRowMax; row++) {
de4b10e5 303 for ( col = 2; col < nColMax; col++) {
3551db50 304 //for ( col = 4; col < nColMax-2; col++) {
3e1a3ad8 305 for (time = 0; time < nTimeTotal; time++) {
306
11dc3a9e 307 Float_t signalL = TMath::Abs(digitsOut->GetDataUnchecked(row,col ,time));
308 Float_t signalM = TMath::Abs(digitsOut->GetDataUnchecked(row,col-1,time));
309 Float_t signalR = TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time));
3e1a3ad8 310
11dc3a9e 311// // Lonok for the maximum
7ad19338 312// if (signalM >= maxThresh) {
313// if (((signalL >= sigThresh) &&
314// (signalL < signalM)) ||
315// ((signalR >= sigThresh) &&
316// (signalR < signalM))) {
317// // Maximum found, mark the position by a negative signal
3becff3c 318// digitsOut->SetDataUnchecked(row,col-1,time,-signalM);
7ad19338 319// }
320// }
3e1a3ad8 321 // Look for the maximum
db30bf0f 322 if (signalM >= maxThresh) {
de4b10e5 323 if ( (TMath::Abs(signalL)<=signalM) && (TMath::Abs(signalR)<=signalM) &&
324 (TMath::Abs(signalL)+TMath::Abs(signalR))>sigThresh ) {
3e1a3ad8 325 // Maximum found, mark the position by a negative signal
3becff3c 326 digitsOut->SetDataUnchecked(row,col-1,time,-signalM);
3e1a3ad8 327 }
328 }
3e1a3ad8 329 }
330 }
331 }
332
333 // Now check the maxima and calculate the cluster position
334 for ( row = 0; row < nRowMax ; row++) {
db30bf0f 335 for (time = 0; time < nTimeTotal; time++) {
336 for ( col = 1; col < nColMax-1; col++) {
3e1a3ad8 337
338 // Maximum found ?
3becff3c 339 if (digitsOut->GetDataUnchecked(row,col,time) < 0) {
f7336fa3 340
9d0b222b 341 Int_t iPad;
8230f242 342 for (iPad = 0; iPad < kNclus; iPad++) {
3e1a3ad8 343 Int_t iPadCol = col - 1 + iPad;
3becff3c 344 clusterSignal[iPad] = TMath::Abs(digitsOut->GetDataUnchecked(row
3e1a3ad8 345 ,iPadCol
346 ,time));
3e1a3ad8 347 clusterTracks[3*iPad ] = track0->GetDataUnchecked(row,iPadCol,time) - 1;
348 clusterTracks[3*iPad+1] = track1->GetDataUnchecked(row,iPadCol,time) - 1;
349 clusterTracks[3*iPad+2] = track2->GetDataUnchecked(row,iPadCol,time) - 1;
f7336fa3 350 }
351
db30bf0f 352 // Count the number of pads in the cluster
353 Int_t nPadCount = 0;
354 Int_t ii = 0;
3becff3c 355 while (TMath::Abs(digitsOut->GetDataUnchecked(row,col-ii ,time))
db30bf0f 356 >= sigThresh) {
357 nPadCount++;
358 ii++;
359 if (col-ii < 0) break;
360 }
361 ii = 0;
3becff3c 362 while (TMath::Abs(digitsOut->GetDataUnchecked(row,col+ii+1,time))
db30bf0f 363 >= sigThresh) {
364 nPadCount++;
365 ii++;
366 if (col+ii+1 >= nColMax) break;
367 }
368
369 nClusters++;
370 switch (nPadCount) {
371 case 2:
372 iType = 0;
373 nClusters2pad++;
374 break;
375 case 3:
376 iType = 1;
377 nClusters3pad++;
378 break;
379 case 4:
380 iType = 2;
381 nClusters4pad++;
382 break;
383 case 5:
384 iType = 3;
385 nClusters5pad++;
386 break;
387 default:
388 iType = 4;
389 nClustersLarge++;
390 break;
391 };
392
7ad19338 393 // Look for 5 pad cluster with minimum in the middle
db30bf0f 394 Bool_t fivePadCluster = kFALSE;
3e1a3ad8 395 if (col < nColMax-3) {
3becff3c 396 if (digitsOut->GetDataUnchecked(row,col+2,time) < 0) {
db30bf0f 397 fivePadCluster = kTRUE;
398 }
399 if ((fivePadCluster) && (col < nColMax-5)) {
3becff3c 400 if (digitsOut->GetDataUnchecked(row,col+4,time) >= sigThresh) {
db30bf0f 401 fivePadCluster = kFALSE;
402 }
403 }
404 if ((fivePadCluster) && (col > 1)) {
3becff3c 405 if (digitsOut->GetDataUnchecked(row,col-2,time) >= sigThresh) {
db30bf0f 406 fivePadCluster = kFALSE;
407 }
408 }
409 }
410
411 // 5 pad cluster
412 // Modify the signal of the overlapping pad for the left part
413 // of the cluster which remains from a previous unfolding
414 if (iUnfold) {
415 clusterSignal[0] *= ratioLeft;
7ad19338 416 iType = 5;
db30bf0f 417 iUnfold = 0;
418 }
419
420 // Unfold the 5 pad cluster
421 if (fivePadCluster) {
422 for (iPad = 0; iPad < kNsig; iPad++) {
3becff3c 423 padSignal[iPad] = TMath::Abs(digitsOut->GetDataUnchecked(row
424 ,col-1+iPad
425 ,time));
f7336fa3 426 }
db30bf0f 427 // Unfold the two maxima and set the signal on
428 // the overlapping pad to the ratio
17b26de4 429 ratioRight = Unfold(kEpsilon,iplan,padSignal);
db30bf0f 430 ratioLeft = 1.0 - ratioRight;
431 clusterSignal[2] *= ratioRight;
7ad19338 432 iType = 5;
db30bf0f 433 iUnfold = 1;
f7336fa3 434 }
f7336fa3 435
a5cadd36 436 Double_t clusterCharge = clusterSignal[0]
437 + clusterSignal[1]
438 + clusterSignal[2];
3e1a3ad8 439
db30bf0f 440 // The position of the cluster
3e1a3ad8 441 clusterPads[0] = row + 0.5;
3e1a3ad8 442 // Take the shift of the additional time bins into account
dde59437 443 clusterPads[2] = time + 0.5;
3e1a3ad8 444
3551db50 445
446 if (recParam->LUTOn()) {
db30bf0f 447 // Calculate the position of the cluster by using the
448 // lookup table method
3becff3c 449 clusterPads[1] = recParam->LUTposition(iplan,clusterSignal[0]
450 ,clusterSignal[1]
451 ,clusterSignal[2]);
db30bf0f 452 }
453 else {
db30bf0f 454 // Calculate the position of the cluster by using the
455 // center of gravity method
7ad19338 456 for (Int_t i=0;i<5;i++) padSignal[i]=0;
3becff3c 457 padSignal[2] = TMath::Abs(digitsOut->GetDataUnchecked(row,col,time)); // central pad
458 padSignal[1] = TMath::Abs(digitsOut->GetDataUnchecked(row,col-1,time)); // left pad
459 padSignal[3] = TMath::Abs(digitsOut->GetDataUnchecked(row,col+1,time)); // right pad
460 if (col>2 &&TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time)<padSignal[1])){
461 padSignal[0] = TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time));
7ad19338 462 }
3becff3c 463 if (col<nColMax-3 &&TMath::Abs(digitsOut->GetDataUnchecked(row,col+2,time)<padSignal[3])){
464 padSignal[4] = TMath::Abs(digitsOut->GetDataUnchecked(row,col+2,time));
7ad19338 465 }
466 clusterPads[1] = GetCOG(padSignal);
db30bf0f 467
468 }
469
a5cadd36 470 Double_t q0 = clusterSignal[0];
471 Double_t q1 = clusterSignal[1];
472 Double_t q2 = clusterSignal[2];
473 Double_t clusterSigmaY2 = (q1*(q0+q2)+4*q0*q2) /
474 (clusterCharge*clusterCharge);
a819a5f7 475
cb86ff6e 476
3551db50 477
478 // Calculate the position and the error
cb86ff6e 479
480 // correct for t0
481 Int_t clusterTimeBin = TMath::Nint(time - calibration->GetT0(idet, col, row));
482
7ad19338 483 Double_t colSize = padPlane->GetColSize(col);
484 Double_t rowSize = padPlane->GetRowSize(row);
a5cadd36 485 Double_t clusterPos[3];
b867ddda 486 clusterPos[0] = padPlane->GetColPos(col) - (clusterPads[1]+0.5)*colSize; // MI change
3becff3c 487 clusterPos[1] = padPlane->GetRowPos(row) - 0.5*rowSize; //MI change
cb86ff6e 488 clusterPos[2] = CalcXposFromTimebin(clusterPads[2], idet, col, row);
a5cadd36 489 Double_t clusterSig[2];
5443e65e 490 clusterSig[0] = (clusterSigmaY2 + 1./12.) * colSize*colSize;
7ad19338 491 clusterSig[1] = rowSize * rowSize / 12.;
3551db50 492
493
f7336fa3 494 // Add the cluster to the output array
c85a4951 495 AliTRDcluster * cluster = AddCluster(clusterPos
cb86ff6e 496 ,clusterTimeBin
3551db50 497 ,idet
a5cadd36 498 ,clusterCharge
499 ,clusterTracks
500 ,clusterSig
3becff3c 501 ,iType,clusterPads[1]);
c85a4951 502 //
503 //
504 Short_t signals[7]={0,0,0,0,0,0,0};
505 for (Int_t jPad = col-3;jPad<=col+3;jPad++){
506 if (jPad<0 ||jPad>=nColMax-1) continue;
11dc3a9e 507 signals[jPad-col+3] = TMath::Nint(TMath::Abs(digitsOut->GetDataUnchecked(row,jPad,time)));
c85a4951 508 }
509 cluster->SetSignals(signals);
f7336fa3 510 }
3e1a3ad8 511 }
512 }
11dc3a9e 513 }
514
515 delete digitsOut;
f7336fa3 516
11dc3a9e 517 // Compress the arrays
3e1a3ad8 518 track0->Compress(1,0);
7ad19338 519 track1->Compress(1,0);
3e1a3ad8 520 track2->Compress(1,0);
f7336fa3 521
3e1a3ad8 522 // Write the cluster and reset the array
793ff80c 523 WriteClusters(idet);
bdbb05bb 524 ResetRecPoints();
3e1a3ad8 525 }
526 }
527 }
f7336fa3 528
47517f42 529 if (fVerbose > 0) {
17b26de4 530 printf("<AliTRDclusterizerV1::MakeCluster> ");
47517f42 531 printf("Done.\n");
532 }
f7336fa3 533
3becff3c 534 //delete digitsIn;
535
f7336fa3 536 return kTRUE;
537
538}
539
a305677e 540//_____________________________________________________________________________
7ad19338 541Double_t AliTRDclusterizerV1::GetCOG(Double_t signal[5])
542{
543 //
544 // get COG position
545 // used for clusters with more than 3 pads - where LUT not applicable
546 Double_t sum = signal[0]+signal[1]+signal[2]+signal[3]+signal[4];
547 Double_t res = (0.0*(-signal[0]+signal[4])+(-signal[1]+signal[3]))/sum;
548 return res;
549}
550
f7336fa3 551//_____________________________________________________________________________
a5cadd36 552Double_t AliTRDclusterizerV1::Unfold(Double_t eps, Int_t plane, Double_t* padSignal)
f7336fa3 553{
554 //
555 // Method to unfold neighbouring maxima.
556 // The charge ratio on the overlapping pad is calculated
557 // until there is no more change within the range given by eps.
558 // The resulting ratio is then returned to the calling method.
559 //
560
6a739e92 561 AliTRDcalibDB* calibration = AliTRDcalibDB::Instance();
562 if (!calibration)
3551db50 563 {
6a739e92 564 printf("<AliTRDclusterizerMI::Unfold> ");
565 printf("ERROR getting instance of AliTRDcalibDB");
566 return kFALSE;
3551db50 567 }
6a739e92 568
a5cadd36 569 Int_t irc = 0;
570 Int_t itStep = 0; // Count iteration steps
f7336fa3 571
a5cadd36 572 Double_t ratio = 0.5; // Start value for ratio
573 Double_t prevRatio = 0; // Store previous ratio
f7336fa3 574
a5cadd36 575 Double_t newLeftSignal[3] = {0}; // Array to store left cluster signal
576 Double_t newRightSignal[3] = {0}; // Array to store right cluster signal
577 Double_t newSignal[3] = {0};
f7336fa3 578
3e1a3ad8 579 // Start the iteration
f7336fa3 580 while ((TMath::Abs(prevRatio - ratio) > eps) && (itStep < 10)) {
581
582 itStep++;
583 prevRatio = ratio;
584
3e1a3ad8 585 // Cluster position according to charge ratio
a5cadd36 586 Double_t maxLeft = (ratio*padSignal[2] - padSignal[0])
587 / (padSignal[0] + padSignal[1] + ratio*padSignal[2]);
588 Double_t maxRight = (padSignal[4] - (1-ratio)*padSignal[2])
589 / ((1-ratio)*padSignal[2] + padSignal[3] + padSignal[4]);
f7336fa3 590
3e1a3ad8 591 // Set cluster charge ratio
6a739e92 592 irc = calibration->PadResponse(1.0,maxLeft ,plane,newSignal);
a5cadd36 593 Double_t ampLeft = padSignal[1] / newSignal[1];
6a739e92 594 irc = calibration->PadResponse(1.0,maxRight,plane,newSignal);
a5cadd36 595 Double_t ampRight = padSignal[3] / newSignal[1];
f7336fa3 596
3e1a3ad8 597 // Apply pad response to parameters
6a739e92 598 irc = calibration->PadResponse(ampLeft ,maxLeft ,plane,newLeftSignal );
599 irc = calibration->PadResponse(ampRight,maxRight,plane,newRightSignal);
f7336fa3 600
3e1a3ad8 601 // Calculate new overlapping ratio
a5cadd36 602 ratio = TMath::Min((Double_t)1.0,newLeftSignal[2] /
db30bf0f 603 (newLeftSignal[2] + newRightSignal[0]));
f7336fa3 604
605 }
606
607 return ratio;
608
609}
610
3becff3c 611//_____________________________________________________________________________
612void AliTRDclusterizerV1::Transform(AliTRDdataArrayI* digitsIn,
11dc3a9e 613 AliTRDdataArrayF* digitsOut,
3becff3c 614 Int_t idet, Int_t nRowMax,
a305677e 615 Int_t nColMax, Int_t nTimeTotal,
616 Float_t ADCthreshold)
3becff3c 617{
618
619 //
cb86ff6e 620 // Apply gain factor
3becff3c 621 // Apply tail cancellation: Transform digitsIn to digitsOut
622 //
623
624
a305677e 625 AliTRDRecParam* recParam = AliTRDRecParam::Instance();
626 if (!recParam)
3becff3c 627 {
628 printf("<AliTRDclusterizerV1::Transform> ");
a305677e 629 printf("ERROR getting instance of AliTRDRecParam");
3becff3c 630 return;
631 }
cb86ff6e 632 AliTRDcalibDB* calibration = AliTRDcalibDB::Instance();
11dc3a9e 633
3becff3c 634 Double_t *inADC = new Double_t[nTimeTotal]; // adc data before tail cancellation
635 Double_t *outADC = new Double_t[nTimeTotal]; // adc data after tail cancellation
636
637 if (fVerbose > 0) {
638 printf("<AliTRDclusterizerV1::Transform> ");
639 printf("Tail cancellation (nExp = %d) for detector %d.\n",
a305677e 640 recParam->GetTCnexp(),idet);
3becff3c 641 }
642
643 for (Int_t iRow = 0; iRow < nRowMax; iRow++ ) {
644 for (Int_t iCol = 0; iCol < nColMax; iCol++ ) {
645 for (Int_t iTime = 0; iTime < nTimeTotal; iTime++) {
cb86ff6e 646 //
647 // add gain
648 //
649 Double_t gain = calibration->GetGainFactor(idet, iCol, iRow);
650 if (gain==0) {
651 AliError("Not a valid gain\n");
652 }
3becff3c 653 inADC[iTime] = digitsIn->GetDataUnchecked(iRow, iCol, iTime);
3becff3c 654
11dc3a9e 655 inADC[iTime] /= gain;
656 outADC[iTime] = inADC[iTime];
3becff3c 657 }
658
659 // Apply the tail cancelation via the digital filter
a305677e 660 if (recParam->TCOn())
3becff3c 661 {
a305677e 662 DeConvExp(inADC,outADC,nTimeTotal,recParam->GetTCnexp());
3becff3c 663 }
664
11dc3a9e 665 for (Int_t iTime = 0; iTime < nTimeTotal; iTime++) {
3becff3c 666 // Store the amplitude of the digit if above threshold
a305677e 667 if (outADC[iTime] > ADCthreshold) {
3becff3c 668 if (fVerbose > 1)
669 {
670 printf(" iRow = %d, iCol = %d, iTime = %d, adc = %f\n"
671 ,iRow,iCol,iTime,outADC[iTime]);
672 }
11dc3a9e 673 digitsOut->SetDataUnchecked(iRow,iCol,iTime,outADC[iTime]);
3becff3c 674 }
675
676 }
677
678 }
679
680 }
681
682 delete [] inADC;
683 delete [] outADC;
684
685 return;
686
687}
688
689
690//_____________________________________________________________________________
691void AliTRDclusterizerV1::DeConvExp(Double_t *source, Double_t *target,
692 Int_t n, Int_t nexp)
693{
694 //
695 // Tail Cancellation by Deconvolution for PASA v4 TRF
696 //
697
698 Double_t rates[2];
699 Double_t coefficients[2];
700
701 // initialize (coefficient = alpha, rates = lambda)
702
703 Double_t R1 = 1.0;
704 Double_t R2 = 1.0;
705 Double_t C1 = 0.5;
706 Double_t C2 = 0.5;
707
708 if (nexp == 1) { // 1 Exponentials
709 R1 = 1.156;
710 R2 = 0.130;
711 C1 = 0.066;
712 C2 = 0.000;
713 }
714 if (nexp == 2) { // 2 Exponentials
715 R1 = 1.156;
716 R2 = 0.130;
717 C1 = 0.114;
718 C2 = 0.624;
719 }
720
721 coefficients[0] = C1;
722 coefficients[1] = C2;
723
724 Double_t Dt = 0.100;
725
726 rates[0] = TMath::Exp(-Dt/(R1));
727 rates[1] = TMath::Exp(-Dt/(R2));
728
729 Int_t i, k;
730 Double_t reminder[2];
731 Double_t correction, result;
732
733 /* attention: computation order is important */
734 correction=0.0;
735
736 for ( k=0; k<nexp; k++ ) reminder[k]=0.0;
737
738 for ( i=0; i<n; i++ ) {
739 result = ( source[i] - correction ); // no rescaling
740 target[i] = result;
741
742 for ( k=0; k<nexp; k++ ) reminder[k] = rates[k] *
743 ( reminder[k] + coefficients[k] * result);
744 correction=0.0;
745 for ( k=0; k<nexp; k++ ) correction += reminder[k];
746 }
747
748}