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