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