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