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