]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDclusterizerV1.cxx
daa920d18a565472b2913d8389ff9e2293769d3c
[u/mrichter/AliRoot.git] / TRD / AliTRDclusterizerV1.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /*
17 $Log$
18 Revision 1.15.6.2  2002/07/24 10:09:30  alibrary
19 Updating VirtualMC
20
21 Revision 1.17  2002/06/12 09:54:35  cblume
22 Update of tracking code provided by Sergei
23
24 Revision 1.16  2002/03/25 20:01:30  cblume
25 Introduce parameter class
26
27 Revision 1.15  2001/11/14 12:09:11  cblume
28 Use correct name for digitizer
29
30 Revision 1.14  2001/11/14 10:50:45  cblume
31 Changes in digits IO. Add merging of summable digits
32
33 Revision 1.13  2001/05/28 17:07:58  hristov
34 Last minute changes; ExB correction in AliTRDclusterizerV1; taking into account of material in G10 TEC frames and material between TEC planes (C.Blume,S.Sedykh)
35
36 Revision 1.12  2001/05/21 17:42:58  hristov
37 Constant casted to avoid the ambiguity
38
39 Revision 1.11  2001/05/21 16:45:47  hristov
40 Last minute changes (C.Blume)
41
42 Revision 1.10  2001/05/07 08:06:44  cblume
43 Speedup of the code. Create only AliTRDcluster
44
45 Revision 1.9  2000/11/01 14:53:20  cblume
46 Merge with TRD-develop
47
48 Revision 1.1.4.5  2000/10/15 23:40:01  cblume
49 Remove AliTRDconst
50
51 Revision 1.1.4.4  2000/10/06 16:49:46  cblume
52 Made Getters const
53
54 Revision 1.1.4.3  2000/10/04 16:34:58  cblume
55 Replace include files by forward declarations
56
57 Revision 1.1.4.2  2000/09/22 14:49:49  cblume
58 Adapted to tracking code
59
60 Revision 1.8  2000/10/02 21:28:19  fca
61 Removal of useless dependecies via forward declarations
62
63 Revision 1.7  2000/06/27 13:08:50  cblume
64 Changed to Copy(TObject &A) to appease the HP-compiler
65
66 Revision 1.6  2000/06/09 11:10:07  cblume
67 Compiler warnings and coding conventions, next round
68
69 Revision 1.5  2000/06/08 18:32:58  cblume
70 Make code compliant to coding conventions
71
72 Revision 1.4  2000/06/07 16:27:01  cblume
73 Try to remove compiler warnings on Sun and HP
74
75 Revision 1.3  2000/05/08 16:17:27  cblume
76 Merge TRD-develop
77
78 Revision 1.1.4.1  2000/05/08 15:09:01  cblume
79 Introduce AliTRDdigitsManager
80
81 Revision 1.1  2000/02/28 18:58:54  cblume
82 Add new TRD classes
83
84 */
85
86 ///////////////////////////////////////////////////////////////////////////////
87 //                                                                           //
88 // TRD cluster finder for the slow simulator. 
89 //                                                                           //
90 ///////////////////////////////////////////////////////////////////////////////
91
92 #include <TF1.h>
93 #include <TTree.h>
94 #include <TH1.h>
95 #include <TFile.h>
96
97 #include "AliRun.h"
98
99 #include "AliTRD.h"
100 #include "AliTRDclusterizerV1.h"
101 #include "AliTRDmatrix.h"
102 #include "AliTRDgeometry.h"
103 #include "AliTRDdigitizer.h"
104 #include "AliTRDdataArrayF.h"
105 #include "AliTRDdataArrayI.h"
106 #include "AliTRDdigitsManager.h"
107 #include "AliTRDparameter.h"
108
109 ClassImp(AliTRDclusterizerV1)
110
111 //_____________________________________________________________________________
112 AliTRDclusterizerV1::AliTRDclusterizerV1():AliTRDclusterizer()
113 {
114   //
115   // AliTRDclusterizerV1 default constructor
116   //
117
118   fDigitsManager = 0;
119
120 }
121
122 //_____________________________________________________________________________
123 AliTRDclusterizerV1::AliTRDclusterizerV1(const Text_t* name, const Text_t* title)
124                     :AliTRDclusterizer(name,title)
125 {
126   //
127   // AliTRDclusterizerV1 default constructor
128   //
129
130   fDigitsManager = new AliTRDdigitsManager();
131   fDigitsManager->CreateArrays();
132
133 }
134
135 //_____________________________________________________________________________
136 AliTRDclusterizerV1::AliTRDclusterizerV1(const AliTRDclusterizerV1 &c)
137 {
138   //
139   // AliTRDclusterizerV1 copy constructor
140   //
141
142   ((AliTRDclusterizerV1 &) c).Copy(*this);
143
144 }
145
146 //_____________________________________________________________________________
147 AliTRDclusterizerV1::~AliTRDclusterizerV1()
148 {
149   //
150   // AliTRDclusterizerV1 destructor
151   //
152
153   if (fDigitsManager) {
154     delete fDigitsManager;
155     fDigitsManager = NULL;
156   }
157
158 }
159
160 //_____________________________________________________________________________
161 AliTRDclusterizerV1 &AliTRDclusterizerV1::operator=(const AliTRDclusterizerV1 &c)
162 {
163   //
164   // Assignment operator
165   //
166
167   if (this != &c) ((AliTRDclusterizerV1 &) c).Copy(*this);
168   return *this;
169
170 }
171
172 //_____________________________________________________________________________
173 void AliTRDclusterizerV1::Copy(TObject &c)
174 {
175   //
176   // Copy function
177   //
178
179   ((AliTRDclusterizerV1 &) c).fDigitsManager = 0;
180
181   AliTRDclusterizer::Copy(c);
182
183 }
184
185 //_____________________________________________________________________________
186 Bool_t AliTRDclusterizerV1::ReadDigits()
187 {
188   //
189   // Reads the digits arrays from the input aliroot file
190   //
191
192   if (!fInputFile) {
193     printf("<AliTRDclusterizerV1::ReadDigits> ");
194     printf("No input file open\n");
195     return kFALSE;
196   }
197
198   fDigitsManager->Open(fInputFile->GetName());
199
200   // Read in the digit arrays
201   return (fDigitsManager->ReadDigits());  
202
203 }
204
205 //_____________________________________________________________________________
206 Bool_t AliTRDclusterizerV1::MakeClusters()
207 {
208   //
209   // Generates the cluster.
210   //
211
212   Int_t row, col, time;
213
214   if (fTRD->IsVersion() != 1) {
215     printf("<AliTRDclusterizerV1::MakeCluster> ");
216     printf("TRD must be version 1 (slow simulator).\n");
217     return kFALSE; 
218   }
219
220   // Get the geometry
221   AliTRDgeometry *geo = fTRD->GetGeometry();
222
223   // Create a default parameter class if none is defined
224   if (!fPar) {
225     fPar = new AliTRDparameter("TRDparameter","Standard TRD parameter");
226     printf("<AliTRDclusterizerV1::MakeCluster> ");
227     printf("Create the default parameter object.\n");
228   }
229
230   Float_t timeBinSize = fPar->GetTimeBinSize();
231   // Half of ampl.region
232   const Float_t kAmWidth = AliTRDgeometry::AmThick()/2.; 
233
234   Float_t omegaTau = fPar->GetOmegaTau();
235   if (fVerbose > 0) {
236     printf("<AliTRDclusterizerV1::MakeCluster> ");
237     printf("OmegaTau = %f \n",omegaTau);
238     printf("<AliTRDclusterizerV1::MakeCluster> ");
239     printf("Start creating clusters.\n");
240   } 
241
242   AliTRDdataArrayI *digits;
243   AliTRDdataArrayI *track0;
244   AliTRDdataArrayI *track1;
245   AliTRDdataArrayI *track2; 
246
247   // Threshold value for the maximum
248   Int_t maxThresh = fPar->GetClusMaxThresh();   
249   // Threshold value for the digit signal
250   Int_t sigThresh = fPar->GetClusSigThresh();   
251
252   // Iteration limit for unfolding procedure
253   const Float_t kEpsilon = 0.01;             
254
255   const Int_t   kNclus   = 3;  
256   const Int_t   kNsig    = 5;
257   const Int_t   kNtrack  = 3 * kNclus;
258
259   Int_t   iType          = 0;
260   Int_t   iUnfold        = 0;
261
262   Float_t ratioLeft      = 1.0;
263   Float_t ratioRight     = 1.0;
264
265   Float_t padSignal[kNsig];   
266   Float_t clusterSignal[kNclus];
267   Float_t clusterPads[kNclus];   
268   Int_t   clusterDigit[kNclus];
269   Int_t   clusterTracks[kNtrack];   
270
271   Int_t chamBeg = 0;
272   Int_t chamEnd = AliTRDgeometry::Ncham();
273   if (fTRD->GetSensChamber()  >= 0) {
274     chamBeg = fTRD->GetSensChamber();
275     chamEnd = chamBeg + 1;
276   }
277   Int_t planBeg = 0;
278   Int_t planEnd = AliTRDgeometry::Nplan();
279   if (fTRD->GetSensPlane()    >= 0) {
280     planBeg = fTRD->GetSensPlane();
281     planEnd = planBeg + 1;
282   }
283   Int_t sectBeg = 0;
284   Int_t sectEnd = AliTRDgeometry::Nsect();
285
286   // Start clustering in every chamber
287   for (Int_t icham = chamBeg; icham < chamEnd; icham++) {
288     for (Int_t iplan = planBeg; iplan < planEnd; iplan++) {
289       for (Int_t isect = sectBeg; isect < sectEnd; isect++) {
290
291         if (fTRD->GetSensSector() >= 0) {
292           Int_t sens1 = fTRD->GetSensSector();
293           Int_t sens2 = sens1 + fTRD->GetSensSectorRange();
294           sens2 -= ((Int_t) (sens2 / AliTRDgeometry::Nsect())) 
295                  * AliTRDgeometry::Nsect();
296           if (sens1 < sens2) {
297             if ((isect < sens1) || (isect >= sens2)) continue;
298           }
299           else {
300             if ((isect < sens1) && (isect >= sens2)) continue;
301           }
302         }
303
304         Int_t idet = geo->GetDetector(iplan,icham,isect);
305
306         Int_t nClusters      = 0;
307         Int_t nClusters2pad  = 0;
308         Int_t nClusters3pad  = 0;
309         Int_t nClusters4pad  = 0;
310         Int_t nClusters5pad  = 0;
311         Int_t nClustersLarge = 0;
312
313         if (fVerbose > 0) {
314           printf("<AliTRDclusterizerV1::MakeCluster> ");
315           printf("Analyzing chamber %d, plane %d, sector %d.\n"
316                 ,icham,iplan,isect);
317         }
318
319         Int_t   nRowMax     = fPar->GetRowMax(iplan,icham,isect);
320         Int_t   nColMax     = fPar->GetColMax(iplan);
321         Int_t   nTimeBefore = fPar->GetTimeBefore();
322         Int_t   nTimeTotal  = fPar->GetTimeTotal();  
323
324         Float_t row0        = fPar->GetRow0(iplan,icham,isect);
325         Float_t col0        = fPar->GetCol0(iplan);
326         Float_t rowSize     = fPar->GetRowPadSize(iplan,icham,isect);
327         Float_t colSize     = fPar->GetColPadSize(iplan);
328
329         // Get the digits
330         digits = fDigitsManager->GetDigits(idet);
331         digits->Expand();
332         track0 = fDigitsManager->GetDictionary(idet,0);
333         track0->Expand();
334         track1 = fDigitsManager->GetDictionary(idet,1);
335         track1->Expand();
336         track2 = fDigitsManager->GetDictionary(idet,2); 
337         track2->Expand();
338
339         // Loop through the chamber and find the maxima 
340         for ( row = 0;  row <  nRowMax;    row++) {
341           for ( col = 2;  col <  nColMax;    col++) {
342             for (time = 0; time < nTimeTotal; time++) {
343
344               Int_t signalL = TMath::Abs(digits->GetDataUnchecked(row,col  ,time));
345               Int_t signalM = TMath::Abs(digits->GetDataUnchecked(row,col-1,time));
346               Int_t signalR = TMath::Abs(digits->GetDataUnchecked(row,col-2,time));
347  
348               // Look for the maximum
349               if (signalM >= maxThresh) {
350                 if (((signalL >= sigThresh) &&
351                      (signalL <  signalM))  ||
352                     ((signalR >= sigThresh) &&
353                      (signalR <  signalM))) {
354                   // Maximum found, mark the position by a negative signal
355                   digits->SetDataUnchecked(row,col-1,time,-signalM);
356                 }
357               }
358
359             }  
360           }    
361         }      
362
363         // Now check the maxima and calculate the cluster position
364         for ( row = 0;  row <  nRowMax  ;  row++) {
365           for (time = 0; time < nTimeTotal; time++) {
366             for ( col = 1;  col <  nColMax-1;  col++) {
367
368               // Maximum found ?             
369               if (digits->GetDataUnchecked(row,col,time) < 0) {
370
371                 Int_t iPad;
372                 for (iPad = 0; iPad < kNclus; iPad++) {
373                   Int_t iPadCol = col - 1 + iPad;
374                   clusterSignal[iPad]     = TMath::Abs(digits->GetDataUnchecked(row
375                                                                                ,iPadCol
376                                                                                ,time));
377                   clusterDigit[iPad]      = digits->GetIndexUnchecked(row,iPadCol,time);
378                   clusterTracks[3*iPad  ] = track0->GetDataUnchecked(row,iPadCol,time) - 1;
379                   clusterTracks[3*iPad+1] = track1->GetDataUnchecked(row,iPadCol,time) - 1;
380                   clusterTracks[3*iPad+2] = track2->GetDataUnchecked(row,iPadCol,time) - 1;
381                 }
382
383                 // Count the number of pads in the cluster
384                 Int_t nPadCount = 0;
385                 Int_t ii        = 0;
386                 while (TMath::Abs(digits->GetDataUnchecked(row,col-ii  ,time))
387                                                                   >= sigThresh) {
388                   nPadCount++;
389                   ii++;
390                   if (col-ii   <        0) break;
391                 }
392                 ii = 0;
393                 while (TMath::Abs(digits->GetDataUnchecked(row,col+ii+1,time))
394                                                                   >= sigThresh) {
395                   nPadCount++;
396                   ii++;
397                   if (col+ii+1 >= nColMax) break;
398                 }
399
400                 nClusters++;
401                 switch (nPadCount) {
402                 case 2:
403                   iType = 0;
404                   nClusters2pad++;
405                   break;
406                 case 3:
407                   iType = 1;
408                   nClusters3pad++;
409                   break;
410                 case 4:
411                   iType = 2;
412                   nClusters4pad++;
413                   break;
414                 case 5:
415                   iType = 3;
416                   nClusters5pad++;
417                   break;
418                 default:
419                   iType = 4;
420                   nClustersLarge++;
421                   break;
422                 };
423
424                 // Don't analyze large clusters
425                 //if (iType == 4) continue;
426
427                 // Look for 5 pad cluster with minimum in the middle
428                 Bool_t fivePadCluster = kFALSE;
429                 if (col < nColMax-3) {
430                   if (digits->GetDataUnchecked(row,col+2,time) < 0) {
431                     fivePadCluster = kTRUE;
432                   }
433                   if ((fivePadCluster) && (col < nColMax-5)) {
434                     if (digits->GetDataUnchecked(row,col+4,time) >= sigThresh) {
435                       fivePadCluster = kFALSE;
436                     }
437                   }
438                   if ((fivePadCluster) && (col >         1)) {
439                     if (digits->GetDataUnchecked(row,col-2,time) >= sigThresh) {
440                       fivePadCluster = kFALSE;
441                     }
442                   }
443                 }
444
445                 // 5 pad cluster
446                 // Modify the signal of the overlapping pad for the left part 
447                 // of the cluster which remains from a previous unfolding
448                 if (iUnfold) {
449                   clusterSignal[0] *= ratioLeft;
450                   iType   = 3;
451                   iUnfold = 0;
452                 }
453
454                 // Unfold the 5 pad cluster
455                 if (fivePadCluster) {
456                   for (iPad = 0; iPad < kNsig; iPad++) {
457                     padSignal[iPad] = TMath::Abs(digits->GetDataUnchecked(row
458                                                                          ,col-1+iPad
459                                                                          ,time));
460                   }
461                   // Unfold the two maxima and set the signal on 
462                   // the overlapping pad to the ratio
463                   ratioRight        = Unfold(kEpsilon,iplan,padSignal);
464                   ratioLeft         = 1.0 - ratioRight; 
465                   clusterSignal[2] *= ratioRight;
466                   iType   = 3;
467                   iUnfold = 1;
468                 }
469
470                 Float_t clusterCharge = clusterSignal[0]
471                                       + clusterSignal[1]
472                                       + clusterSignal[2];
473                 
474                 // The position of the cluster
475                 clusterPads[0] = row + 0.5;
476                 // Take the shift of the additional time bins into account
477                 clusterPads[2] = time - nTimeBefore + 0.5;
478
479                 if (fPar->LUTOn()) {
480
481                   // Calculate the position of the cluster by using the
482                   // lookup table method
483                   clusterPads[1] = col + 0.5
484                                  + fPar->LUTposition(iplan,clusterSignal[0]
485                                                           ,clusterSignal[1]
486                                                           ,clusterSignal[2]);
487
488                 }
489                 else {
490
491                   // Calculate the position of the cluster by using the
492                   // center of gravity method
493                   clusterPads[1] = col + 0.5 
494                                  + (clusterSignal[2] - clusterSignal[0]) 
495                                  / clusterCharge;
496
497                 }
498
499                 Float_t q0 = clusterSignal[0];
500                 Float_t q1 = clusterSignal[1];
501                 Float_t q2 = clusterSignal[2];
502                 Float_t clusterSigmaY2 = (q1*(q0+q2)+4*q0*q2) /
503                                          (clusterCharge*clusterCharge);
504
505                 // Correct for ExB displacement
506                 if (fPar->ExBOn()) { 
507                   Int_t   local_time_bin = (Int_t) clusterPads[2];
508                   Float_t driftLength    = local_time_bin * timeBinSize + kAmWidth;
509                   Float_t colSize        = fPar->GetColPadSize(iplan);
510                   Float_t deltaY         = omegaTau*driftLength/colSize;
511                   clusterPads[1]         = clusterPads[1] - deltaY;
512                 }
513                                        
514                 if (fVerbose > 1) {
515                   printf("-----------------------------------------------------------\n");
516                   printf("Create cluster no. %d\n",nClusters);
517                   printf("Position: row = %f, col = %f, time = %f\n",clusterPads[0]
518                                                                     ,clusterPads[1]
519                                                                     ,clusterPads[2]);
520                   printf("Indices: %d, %d, %d\n",clusterDigit[0]
521                                                 ,clusterDigit[1]
522                                                 ,clusterDigit[2]);
523                   printf("Total charge = %f\n",clusterCharge);
524                   printf("Tracks: pad0 %d, %d, %d\n",clusterTracks[0]
525                                                     ,clusterTracks[1]
526                                                     ,clusterTracks[2]);
527                   printf("        pad1 %d, %d, %d\n",clusterTracks[3]
528                                                     ,clusterTracks[4]
529                                                     ,clusterTracks[5]);
530                   printf("        pad2 %d, %d, %d\n",clusterTracks[6]
531                                                     ,clusterTracks[7]
532                                                     ,clusterTracks[8]);
533                   printf("Type = %d, Number of pads = %d\n",iType,nPadCount);
534                 }
535
536                 // Calculate the position and the error
537                 Float_t clusterPos[3];
538                 clusterPos[0] = clusterPads[1] * colSize + col0;
539                 clusterPos[1] = clusterPads[0] * rowSize + row0;
540                 clusterPos[2] = clusterPads[2];
541                 Float_t clusterSig[2];
542                 clusterSig[0] = (clusterSigmaY2 + 1./12.) * colSize*colSize;
543                 clusterSig[1] = rowSize * rowSize / 12.;
544
545                 // Add the cluster to the output array 
546                 fTRD->AddCluster(clusterPos
547                                 ,idet
548                                 ,clusterCharge
549                                 ,clusterTracks
550                                 ,clusterSig
551                                 ,iType);
552
553               }
554             } 
555           }   
556         }     
557
558         // Compress the arrays
559         digits->Compress(1,0);
560         track0->Compress(1,0);
561         track1->Compress(1,0);
562         track2->Compress(1,0);
563
564         // Write the cluster and reset the array
565         WriteClusters(idet);
566         fTRD->ResetRecPoints();
567
568         if (fVerbose > 0) {
569           printf("<AliTRDclusterizerV1::MakeCluster> ");
570           printf("Found %d clusters in total.\n"
571                 ,nClusters);
572           printf("                                    2pad:  %d\n",nClusters2pad);
573           printf("                                    3pad:  %d\n",nClusters3pad);
574           printf("                                    4pad:  %d\n",nClusters4pad);
575           printf("                                    5pad:  %d\n",nClusters5pad);
576           printf("                                    Large: %d\n",nClustersLarge);
577         }
578
579       }    
580     }      
581   }        
582
583   if (fVerbose > 0) {
584     printf("<AliTRDclusterizerV1::MakeCluster> ");
585     printf("Done.\n");
586   }
587
588   return kTRUE;
589
590 }
591
592 //_____________________________________________________________________________
593 Float_t AliTRDclusterizerV1::Unfold(Float_t eps, Int_t plane, Float_t* padSignal)
594 {
595   //
596   // Method to unfold neighbouring maxima.
597   // The charge ratio on the overlapping pad is calculated
598   // until there is no more change within the range given by eps.
599   // The resulting ratio is then returned to the calling method.
600   //
601
602   Int_t   irc               = 0;
603   Int_t   itStep            = 0;      // Count iteration steps
604
605   Float_t ratio             = 0.5;    // Start value for ratio
606   Float_t prevRatio         = 0;      // Store previous ratio
607
608   Float_t newLeftSignal[3]  = {0};    // Array to store left cluster signal
609   Float_t newRightSignal[3] = {0};    // Array to store right cluster signal
610   Float_t newSignal[3]      = {0};
611
612   // Start the iteration
613   while ((TMath::Abs(prevRatio - ratio) > eps) && (itStep < 10)) {
614
615     itStep++;
616     prevRatio = ratio;
617
618     // Cluster position according to charge ratio
619     Float_t maxLeft  = (ratio*padSignal[2] - padSignal[0]) 
620                      / (padSignal[0] + padSignal[1] + ratio*padSignal[2]);
621     Float_t maxRight = (padSignal[4] - (1-ratio)*padSignal[2]) 
622                      / ((1-ratio)*padSignal[2] + padSignal[3] + padSignal[4]);
623
624     // Set cluster charge ratio
625     irc = fPar->PadResponse(1.0,maxLeft ,plane,newSignal);
626     Float_t ampLeft  = padSignal[1] / newSignal[1];
627     irc = fPar->PadResponse(1.0,maxRight,plane,newSignal);
628     Float_t ampRight = padSignal[3] / newSignal[1];
629
630     // Apply pad response to parameters
631     irc = fPar->PadResponse(ampLeft ,maxLeft ,plane,newLeftSignal );
632     irc = fPar->PadResponse(ampRight,maxRight,plane,newRightSignal);
633
634     // Calculate new overlapping ratio
635     ratio = TMath::Min((Float_t)1.0,newLeftSignal[2] / 
636                           (newLeftSignal[2] + newRightSignal[0]));
637
638   }
639
640   return ratio;
641
642 }
643