]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDclusterizerV1.cxx
Geometry update, Removal of compiler warnings
[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 /* $Id$ */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 // TRD cluster finder for the slow simulator. 
21 //                                                                           //
22 ///////////////////////////////////////////////////////////////////////////////
23
24 #include <TF1.h>
25 #include <TTree.h>
26 #include <TH1.h>
27 #include <TFile.h>
28
29 #include "AliRun.h"
30 #include "AliRunLoader.h"
31 #include "AliLoader.h"
32
33 #include "AliTRD.h"
34 #include "AliTRDclusterizerV1.h"
35 #include "AliTRDmatrix.h"
36 #include "AliTRDgeometry.h"
37 #include "AliTRDdigitizer.h"
38 #include "AliTRDdataArrayF.h"
39 #include "AliTRDdataArrayI.h"
40 #include "AliTRDdigitsManager.h"
41 #include "AliTRDparameter.h"
42
43 ClassImp(AliTRDclusterizerV1)
44
45 //_____________________________________________________________________________
46 AliTRDclusterizerV1::AliTRDclusterizerV1():AliTRDclusterizer()
47 {
48   //
49   // AliTRDclusterizerV1 default constructor
50   //
51
52   fDigitsManager = 0;
53
54 }
55
56 //_____________________________________________________________________________
57 AliTRDclusterizerV1::AliTRDclusterizerV1(const Text_t* name, const Text_t* title)
58                     :AliTRDclusterizer(name,title)
59 {
60   //
61   // AliTRDclusterizerV1 default constructor
62   //
63
64   fDigitsManager = new AliTRDdigitsManager();
65   fDigitsManager->CreateArrays();
66
67 }
68
69 //_____________________________________________________________________________
70 AliTRDclusterizerV1::AliTRDclusterizerV1(const AliTRDclusterizerV1 &c)
71 :AliTRDclusterizer(c)
72 {
73   //
74   // AliTRDclusterizerV1 copy constructor
75   //
76
77   ((AliTRDclusterizerV1 &) c).Copy(*this);
78
79 }
80
81 //_____________________________________________________________________________
82 AliTRDclusterizerV1::~AliTRDclusterizerV1()
83 {
84   //
85   // AliTRDclusterizerV1 destructor
86   //
87
88   if (fDigitsManager) {
89     delete fDigitsManager;
90     fDigitsManager = NULL;
91   }
92
93 }
94
95 //_____________________________________________________________________________
96 AliTRDclusterizerV1 &AliTRDclusterizerV1::operator=(const AliTRDclusterizerV1 &c)
97 {
98   //
99   // Assignment operator
100   //
101
102   if (this != &c) ((AliTRDclusterizerV1 &) c).Copy(*this);
103   return *this;
104
105 }
106
107 //_____________________________________________________________________________
108 void AliTRDclusterizerV1::Copy(TObject &c)
109 {
110   //
111   // Copy function
112   //
113
114   ((AliTRDclusterizerV1 &) c).fDigitsManager = 0;
115
116   AliTRDclusterizer::Copy(c);
117
118 }
119
120 //_____________________________________________________________________________
121 Bool_t AliTRDclusterizerV1::ReadDigits()
122 {
123   //
124   // Reads the digits arrays from the input aliroot file
125   //
126
127   if (!fRunLoader) {
128     printf("<AliTRDclusterizerV1::ReadDigits> ");
129     printf("No input file open\n");
130     return kFALSE;
131   }
132   AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
133   if (!loader->TreeD()) loader->LoadDigits();
134
135   // Read in the digit arrays
136   return (fDigitsManager->ReadDigits(loader->TreeD()));
137
138 }
139
140 //_____________________________________________________________________________
141 Bool_t AliTRDclusterizerV1::MakeClusters()
142 {
143   //
144   // Generates the cluster.
145   //
146
147   Int_t row, col, time;
148
149   if (fTRD->IsVersion() != 1) {
150     printf("<AliTRDclusterizerV1::MakeCluster> ");
151     printf("TRD must be version 1 (slow simulator).\n");
152     return kFALSE; 
153   }
154
155   // Get the geometry
156   AliTRDgeometry *geo = fTRD->GetGeometry();
157
158   // Create a default parameter class if none is defined
159   if (!fPar) {
160     fPar = new AliTRDparameter("TRDparameter","Standard TRD parameter");
161     printf("<AliTRDclusterizerV1::MakeCluster> ");
162     printf("Create the default parameter object.\n");
163   }
164
165   Float_t timeBinSize = fPar->GetTimeBinSize();
166   // Half of ampl.region
167   const Float_t kAmWidth = AliTRDgeometry::AmThick()/2.; 
168
169   Float_t omegaTau = fPar->GetOmegaTau();
170   if (fVerbose > 0) {
171     printf("<AliTRDclusterizerV1::MakeCluster> ");
172     printf("OmegaTau = %f \n",omegaTau);
173     printf("<AliTRDclusterizerV1::MakeCluster> ");
174     printf("Start creating clusters.\n");
175   } 
176
177   AliTRDdataArrayI *digits;
178   AliTRDdataArrayI *track0;
179   AliTRDdataArrayI *track1;
180   AliTRDdataArrayI *track2; 
181
182   // Threshold value for the maximum
183   Int_t maxThresh = fPar->GetClusMaxThresh();   
184   // Threshold value for the digit signal
185   Int_t sigThresh = fPar->GetClusSigThresh();   
186
187   // Iteration limit for unfolding procedure
188   const Float_t kEpsilon = 0.01;             
189
190   const Int_t   kNclus   = 3;  
191   const Int_t   kNsig    = 5;
192   const Int_t   kNtrack  = 3 * kNclus;
193
194   Int_t   iType          = 0;
195   Int_t   iUnfold        = 0;
196
197   Float_t ratioLeft      = 1.0;
198   Float_t ratioRight     = 1.0;
199
200   Float_t padSignal[kNsig];   
201   Float_t clusterSignal[kNclus];
202   Float_t clusterPads[kNclus];   
203   Int_t   clusterDigit[kNclus];
204   Int_t   clusterTracks[kNtrack];   
205
206   Int_t chamBeg = 0;
207   Int_t chamEnd = AliTRDgeometry::Ncham();
208   if (fTRD->GetSensChamber()  >= 0) {
209     chamBeg = fTRD->GetSensChamber();
210     chamEnd = chamBeg + 1;
211   }
212   Int_t planBeg = 0;
213   Int_t planEnd = AliTRDgeometry::Nplan();
214   if (fTRD->GetSensPlane()    >= 0) {
215     planBeg = fTRD->GetSensPlane();
216     planEnd = planBeg + 1;
217   }
218   Int_t sectBeg = 0;
219   Int_t sectEnd = AliTRDgeometry::Nsect();
220
221   // Start clustering in every chamber
222   for (Int_t icham = chamBeg; icham < chamEnd; icham++) {
223     for (Int_t iplan = planBeg; iplan < planEnd; iplan++) {
224       for (Int_t isect = sectBeg; isect < sectEnd; isect++) {
225
226         if (fTRD->GetSensSector() >= 0) {
227           Int_t sens1 = fTRD->GetSensSector();
228           Int_t sens2 = sens1 + fTRD->GetSensSectorRange();
229           sens2 -= ((Int_t) (sens2 / AliTRDgeometry::Nsect())) 
230                  * AliTRDgeometry::Nsect();
231           if (sens1 < sens2) {
232             if ((isect < sens1) || (isect >= sens2)) continue;
233           }
234           else {
235             if ((isect < sens1) && (isect >= sens2)) continue;
236           }
237         }
238
239         Int_t idet = geo->GetDetector(iplan,icham,isect);
240
241         Int_t nClusters      = 0;
242         Int_t nClusters2pad  = 0;
243         Int_t nClusters3pad  = 0;
244         Int_t nClusters4pad  = 0;
245         Int_t nClusters5pad  = 0;
246         Int_t nClustersLarge = 0;
247
248         if (fVerbose > 0) {
249           printf("<AliTRDclusterizerV1::MakeCluster> ");
250           printf("Analyzing chamber %d, plane %d, sector %d.\n"
251                 ,icham,iplan,isect);
252         }
253
254         Int_t   nRowMax     = fPar->GetRowMax(iplan,icham,isect);
255         Int_t   nColMax     = fPar->GetColMax(iplan);
256         Int_t   nTimeBefore = fPar->GetTimeBefore();
257         Int_t   nTimeTotal  = fPar->GetTimeTotal();  
258
259         Float_t row0        = fPar->GetRow0(iplan,icham,isect);
260         Float_t col0        = fPar->GetCol0(iplan);
261         Float_t rowSize     = fPar->GetRowPadSize(iplan,icham,isect);
262         Float_t colSize     = fPar->GetColPadSize(iplan);
263
264         // Get the digits
265         digits = fDigitsManager->GetDigits(idet);
266         digits->Expand();
267         track0 = fDigitsManager->GetDictionary(idet,0);
268         track0->Expand();
269         track1 = fDigitsManager->GetDictionary(idet,1);
270         track1->Expand();
271         track2 = fDigitsManager->GetDictionary(idet,2); 
272         track2->Expand();
273
274         // Loop through the chamber and find the maxima 
275         for ( row = 0;  row <  nRowMax;    row++) {
276           for ( col = 2;  col <  nColMax;    col++) {
277             for (time = 0; time < nTimeTotal; time++) {
278
279               Int_t signalL = TMath::Abs(digits->GetDataUnchecked(row,col  ,time));
280               Int_t signalM = TMath::Abs(digits->GetDataUnchecked(row,col-1,time));
281               Int_t signalR = TMath::Abs(digits->GetDataUnchecked(row,col-2,time));
282  
283               // Look for the maximum
284               if (signalM >= maxThresh) {
285                 if (((signalL >= sigThresh) &&
286                      (signalL <  signalM))  ||
287                     ((signalR >= sigThresh) &&
288                      (signalR <  signalM))) {
289                   // Maximum found, mark the position by a negative signal
290                   digits->SetDataUnchecked(row,col-1,time,-signalM);
291                 }
292               }
293
294             }  
295           }    
296         }      
297
298         // Now check the maxima and calculate the cluster position
299         for ( row = 0;  row <  nRowMax  ;  row++) {
300           for (time = 0; time < nTimeTotal; time++) {
301             for ( col = 1;  col <  nColMax-1;  col++) {
302
303               // Maximum found ?             
304               if (digits->GetDataUnchecked(row,col,time) < 0) {
305
306                 Int_t iPad;
307                 for (iPad = 0; iPad < kNclus; iPad++) {
308                   Int_t iPadCol = col - 1 + iPad;
309                   clusterSignal[iPad]     = TMath::Abs(digits->GetDataUnchecked(row
310                                                                                ,iPadCol
311                                                                                ,time));
312                   clusterDigit[iPad]      = digits->GetIndexUnchecked(row,iPadCol,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(digits->GetDataUnchecked(row,col-ii  ,time))
322                                                                   >= sigThresh) {
323                   nPadCount++;
324                   ii++;
325                   if (col-ii   <        0) break;
326                 }
327                 ii = 0;
328                 while (TMath::Abs(digits->GetDataUnchecked(row,col+ii+1,time))
329                                                                   >= sigThresh) {
330                   nPadCount++;
331                   ii++;
332                   if (col+ii+1 >= nColMax) break;
333                 }
334
335                 nClusters++;
336                 switch (nPadCount) {
337                 case 2:
338                   iType = 0;
339                   nClusters2pad++;
340                   break;
341                 case 3:
342                   iType = 1;
343                   nClusters3pad++;
344                   break;
345                 case 4:
346                   iType = 2;
347                   nClusters4pad++;
348                   break;
349                 case 5:
350                   iType = 3;
351                   nClusters5pad++;
352                   break;
353                 default:
354                   iType = 4;
355                   nClustersLarge++;
356                   break;
357                 };
358
359                 // Don't analyze large clusters
360                 //if (iType == 4) continue;
361
362                 // Look for 5 pad cluster with minimum in the middle
363                 Bool_t fivePadCluster = kFALSE;
364                 if (col < nColMax-3) {
365                   if (digits->GetDataUnchecked(row,col+2,time) < 0) {
366                     fivePadCluster = kTRUE;
367                   }
368                   if ((fivePadCluster) && (col < nColMax-5)) {
369                     if (digits->GetDataUnchecked(row,col+4,time) >= sigThresh) {
370                       fivePadCluster = kFALSE;
371                     }
372                   }
373                   if ((fivePadCluster) && (col >         1)) {
374                     if (digits->GetDataUnchecked(row,col-2,time) >= sigThresh) {
375                       fivePadCluster = kFALSE;
376                     }
377                   }
378                 }
379
380                 // 5 pad cluster
381                 // Modify the signal of the overlapping pad for the left part 
382                 // of the cluster which remains from a previous unfolding
383                 if (iUnfold) {
384                   clusterSignal[0] *= ratioLeft;
385                   iType   = 3;
386                   iUnfold = 0;
387                 }
388
389                 // Unfold the 5 pad cluster
390                 if (fivePadCluster) {
391                   for (iPad = 0; iPad < kNsig; iPad++) {
392                     padSignal[iPad] = TMath::Abs(digits->GetDataUnchecked(row
393                                                                          ,col-1+iPad
394                                                                          ,time));
395                   }
396                   // Unfold the two maxima and set the signal on 
397                   // the overlapping pad to the ratio
398                   ratioRight        = Unfold(kEpsilon,iplan,padSignal);
399                   ratioLeft         = 1.0 - ratioRight; 
400                   clusterSignal[2] *= ratioRight;
401                   iType   = 3;
402                   iUnfold = 1;
403                 }
404
405                 Float_t clusterCharge = clusterSignal[0]
406                                       + clusterSignal[1]
407                                       + clusterSignal[2];
408                 
409                 // The position of the cluster
410                 clusterPads[0] = row + 0.5;
411                 // Take the shift of the additional time bins into account
412                 clusterPads[2] = time - nTimeBefore + 0.5;
413
414                 if (fPar->LUTOn()) {
415
416                   // Calculate the position of the cluster by using the
417                   // lookup table method
418                   clusterPads[1] = col + 0.5
419                                  + fPar->LUTposition(iplan,clusterSignal[0]
420                                                           ,clusterSignal[1]
421                                                           ,clusterSignal[2]);
422
423                 }
424                 else {
425
426                   // Calculate the position of the cluster by using the
427                   // center of gravity method
428                   clusterPads[1] = col + 0.5 
429                                  + (clusterSignal[2] - clusterSignal[0]) 
430                                  / clusterCharge;
431
432                 }
433
434                 Float_t q0 = clusterSignal[0];
435                 Float_t q1 = clusterSignal[1];
436                 Float_t q2 = clusterSignal[2];
437                 Float_t clusterSigmaY2 = (q1*(q0+q2)+4*q0*q2) /
438                                          (clusterCharge*clusterCharge);
439
440                 // Correct for ExB displacement
441                 if (fPar->ExBOn()) { 
442                   Int_t   local_time_bin = (Int_t) clusterPads[2];
443                   Float_t driftLength    = local_time_bin * timeBinSize + kAmWidth;
444                   Float_t colSize        = fPar->GetColPadSize(iplan);
445                   Float_t deltaY         = omegaTau*driftLength/colSize;
446                   clusterPads[1]         = clusterPads[1] - deltaY;
447                 }
448                                        
449                 if (fVerbose > 1) {
450                   printf("-----------------------------------------------------------\n");
451                   printf("Create cluster no. %d\n",nClusters);
452                   printf("Position: row = %f, col = %f, time = %f\n",clusterPads[0]
453                                                                     ,clusterPads[1]
454                                                                     ,clusterPads[2]);
455                   printf("Indices: %d, %d, %d\n",clusterDigit[0]
456                                                 ,clusterDigit[1]
457                                                 ,clusterDigit[2]);
458                   printf("Total charge = %f\n",clusterCharge);
459                   printf("Tracks: pad0 %d, %d, %d\n",clusterTracks[0]
460                                                     ,clusterTracks[1]
461                                                     ,clusterTracks[2]);
462                   printf("        pad1 %d, %d, %d\n",clusterTracks[3]
463                                                     ,clusterTracks[4]
464                                                     ,clusterTracks[5]);
465                   printf("        pad2 %d, %d, %d\n",clusterTracks[6]
466                                                     ,clusterTracks[7]
467                                                     ,clusterTracks[8]);
468                   printf("Type = %d, Number of pads = %d\n",iType,nPadCount);
469                 }
470
471                 // Calculate the position and the error
472                 Float_t clusterPos[3];
473                 clusterPos[0] = clusterPads[1] * colSize + col0;
474                 clusterPos[1] = clusterPads[0] * rowSize + row0;
475                 clusterPos[2] = clusterPads[2];
476                 Float_t clusterSig[2];
477                 clusterSig[0] = (clusterSigmaY2 + 1./12.) * colSize*colSize;
478                 clusterSig[1] = rowSize * rowSize / 12.;
479
480                 // Add the cluster to the output array 
481                 fTRD->AddCluster(clusterPos
482                                 ,idet
483                                 ,clusterCharge
484                                 ,clusterTracks
485                                 ,clusterSig
486                                 ,iType);
487
488               }
489             } 
490           }   
491         }     
492
493         // Compress the arrays
494         digits->Compress(1,0);
495         track0->Compress(1,0);
496         track1->Compress(1,0);
497         track2->Compress(1,0);
498
499         // Write the cluster and reset the array
500         WriteClusters(idet);
501         fTRD->ResetRecPoints();
502
503         if (fVerbose > 0) {
504           printf("<AliTRDclusterizerV1::MakeCluster> ");
505           printf("Found %d clusters in total.\n"
506                 ,nClusters);
507           printf("                                    2pad:  %d\n",nClusters2pad);
508           printf("                                    3pad:  %d\n",nClusters3pad);
509           printf("                                    4pad:  %d\n",nClusters4pad);
510           printf("                                    5pad:  %d\n",nClusters5pad);
511           printf("                                    Large: %d\n",nClustersLarge);
512         }
513
514       }    
515     }      
516   }        
517
518   if (fVerbose > 0) {
519     printf("<AliTRDclusterizerV1::MakeCluster> ");
520     printf("Done.\n");
521   }
522
523   return kTRUE;
524
525 }
526
527 //_____________________________________________________________________________
528 Float_t AliTRDclusterizerV1::Unfold(Float_t eps, Int_t plane, Float_t* padSignal)
529 {
530   //
531   // Method to unfold neighbouring maxima.
532   // The charge ratio on the overlapping pad is calculated
533   // until there is no more change within the range given by eps.
534   // The resulting ratio is then returned to the calling method.
535   //
536
537   Int_t   irc               = 0;
538   Int_t   itStep            = 0;      // Count iteration steps
539
540   Float_t ratio             = 0.5;    // Start value for ratio
541   Float_t prevRatio         = 0;      // Store previous ratio
542
543   Float_t newLeftSignal[3]  = {0};    // Array to store left cluster signal
544   Float_t newRightSignal[3] = {0};    // Array to store right cluster signal
545   Float_t newSignal[3]      = {0};
546
547   // Start the iteration
548   while ((TMath::Abs(prevRatio - ratio) > eps) && (itStep < 10)) {
549
550     itStep++;
551     prevRatio = ratio;
552
553     // Cluster position according to charge ratio
554     Float_t maxLeft  = (ratio*padSignal[2] - padSignal[0]) 
555                      / (padSignal[0] + padSignal[1] + ratio*padSignal[2]);
556     Float_t maxRight = (padSignal[4] - (1-ratio)*padSignal[2]) 
557                      / ((1-ratio)*padSignal[2] + padSignal[3] + padSignal[4]);
558
559     // Set cluster charge ratio
560     irc = fPar->PadResponse(1.0,maxLeft ,plane,newSignal);
561     Float_t ampLeft  = padSignal[1] / newSignal[1];
562     irc = fPar->PadResponse(1.0,maxRight,plane,newSignal);
563     Float_t ampRight = padSignal[3] / newSignal[1];
564
565     // Apply pad response to parameters
566     irc = fPar->PadResponse(ampLeft ,maxLeft ,plane,newLeftSignal );
567     irc = fPar->PadResponse(ampRight,maxRight,plane,newRightSignal);
568
569     // Calculate new overlapping ratio
570     ratio = TMath::Min((Float_t)1.0,newLeftSignal[2] / 
571                           (newLeftSignal[2] + newRightSignal[0]));
572
573   }
574
575   return ratio;
576
577 }
578