2 /**************************************************************************
3 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * Author: The ALICE Off-line Project. *
6 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
19 ///////////////////////////////////////////////////////////////////////////////
21 // TRD cluster finder for the slow simulator.
23 ///////////////////////////////////////////////////////////////////////////////
31 #include "AliRunLoader.h"
32 #include "AliLoader.h"
33 #include "AliRawReader.h"
35 #include "AliTRDclusterizerV1.h"
36 #include "AliTRDmatrix.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"
49 ClassImp(AliTRDclusterizerV1)
51 //_____________________________________________________________________________
52 AliTRDclusterizerV1::AliTRDclusterizerV1():AliTRDclusterizer()
55 // AliTRDclusterizerV1 default constructor
62 //_____________________________________________________________________________
63 AliTRDclusterizerV1::AliTRDclusterizerV1(const Text_t* name, const Text_t* title)
64 :AliTRDclusterizer(name,title)
67 // AliTRDclusterizerV1 default constructor
70 fDigitsManager = new AliTRDdigitsManager();
71 fDigitsManager->CreateArrays();
75 //_____________________________________________________________________________
76 AliTRDclusterizerV1::AliTRDclusterizerV1(const AliTRDclusterizerV1 &c)
80 // AliTRDclusterizerV1 copy constructor
83 ((AliTRDclusterizerV1 &) c).Copy(*this);
87 //_____________________________________________________________________________
88 AliTRDclusterizerV1::~AliTRDclusterizerV1()
91 // AliTRDclusterizerV1 destructor
95 delete fDigitsManager;
96 fDigitsManager = NULL;
101 //_____________________________________________________________________________
102 AliTRDclusterizerV1 &AliTRDclusterizerV1::operator=(const AliTRDclusterizerV1 &c)
105 // Assignment operator
108 if (this != &c) ((AliTRDclusterizerV1 &) c).Copy(*this);
113 //_____________________________________________________________________________
114 void AliTRDclusterizerV1::Copy(TObject &c) const
120 ((AliTRDclusterizerV1 &) c).fDigitsManager = 0;
122 AliTRDclusterizer::Copy(c);
126 //_____________________________________________________________________________
127 Bool_t AliTRDclusterizerV1::ReadDigits()
130 // Reads the digits arrays from the input aliroot file
134 printf("<AliTRDclusterizerV1::ReadDigits> ");
135 printf("No input file open\n");
138 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
139 if (!loader->TreeD()) loader->LoadDigits();
141 // Read in the digit arrays
142 return (fDigitsManager->ReadDigits(loader->TreeD()));
146 //_____________________________________________________________________________
147 Bool_t AliTRDclusterizerV1::ReadDigits(AliRawReader* rawReader)
150 // Reads the digits arrays from the ddl file
153 AliTRDrawData *raw = new AliTRDrawData();
156 fDigitsManager = raw->Raw2Digits(rawReader);
162 //_____________________________________________________________________________
163 Bool_t AliTRDclusterizerV1::MakeClusters()
166 // Generates the cluster.
169 Int_t row, col, time;
172 if (fTRD->IsVersion() != 1) {
173 printf("<AliTRDclusterizerV1::MakeCluster> ");
174 printf("TRD must be version 1 (slow simulator).\n");
180 AliTRDgeometry *geo = AliTRDgeometry::GetGeometry(fRunLoader);
181 AliTRDcalibDB* calibration = AliTRDcalibDB::Instance();
184 printf("<AliTRDclusterizerV1::MakeCluster> ");
185 printf("ERROR getting instance of AliTRDcalibDB");
189 AliTRDSimParam* simParam = AliTRDSimParam::Instance();
192 printf("<AliTRDclusterizerV1::MakeCluster> ");
193 printf("ERROR getting instance of AliTRDSimParam");
197 AliTRDRecParam* recParam = AliTRDRecParam::Instance();
200 printf("<AliTRDclusterizerV1::MakeCluster> ");
201 printf("ERROR getting instance of AliTRDRecParam");
205 AliTRDCommonParam* commonParam = AliTRDCommonParam::Instance();
208 printf("<AliTRDclusterizerV1::MakeDigits> ");
209 printf("Could not get common params\n");
213 Float_t ADCthreshold = simParam->GetADCthreshold();
216 //printf("<AliTRDclusterizerV1::MakeCluster> ");
217 //printf("OmegaTau = %f \n",omegaTau);
218 printf("<AliTRDclusterizerV1::MakeCluster> ");
219 printf("Start creating clusters.\n");
222 AliTRDdataArrayI *digitsIn;
223 AliTRDdataArrayI *track0;
224 AliTRDdataArrayI *track1;
225 AliTRDdataArrayI *track2;
227 // Threshold value for the maximum
228 Float_t maxThresh = recParam->GetClusMaxThresh();
229 // Threshold value for the digit signal
230 Float_t sigThresh = recParam->GetClusSigThresh();
231 // Iteration limit for unfolding procedure
232 const Float_t kEpsilon = 0.01;
234 const Int_t kNclus = 3;
235 const Int_t kNsig = 5;
236 const Int_t kNtrack = 3 * kNclus;
240 Double_t ratioLeft = 1.0;
241 Double_t ratioRight = 1.0;
244 Double_t padSignal[kNsig];
245 Double_t clusterSignal[kNclus];
246 Double_t clusterPads[kNclus];
247 Int_t clusterTracks[kNtrack];
250 Int_t chamEnd = AliTRDgeometry::Ncham();
252 Int_t planEnd = AliTRDgeometry::Nplan();
254 Int_t sectEnd = AliTRDgeometry::Nsect();
256 Int_t nTimeTotal = calibration->GetNumberOfTimeBins();
259 printf("<AliTRDclusterizerV1::MakeCluster> ");
260 printf("Number of Time Bins = %d.\n",nTimeTotal);
263 // Start clustering in every chamber
264 for (Int_t icham = chamBeg; icham < chamEnd; icham++) {
265 for (Int_t iplan = planBeg; iplan < planEnd; iplan++) {
266 for (Int_t isect = sectBeg; isect < sectEnd; isect++) {
268 Int_t idet = geo->GetDetector(iplan,icham,isect);
270 Int_t nRowMax = commonParam->GetRowMax(iplan,icham,isect);
271 Int_t nColMax = commonParam->GetColMax(iplan);
274 Int_t nClusters2pad = 0;
275 Int_t nClusters3pad = 0;
276 Int_t nClusters4pad = 0;
277 Int_t nClusters5pad = 0;
278 Int_t nClustersLarge = 0;
281 printf("<AliTRDclusterizerV1::MakeCluster> ");
282 printf("Analyzing chamber %d, plane %d, sector %d.\n"
286 AliTRDpadPlane *padPlane = commonParam->GetPadPlane(iplan,icham);
289 digitsIn = fDigitsManager->GetDigits(idet);
291 AliTRDdataArrayF *digitsOut = new AliTRDdataArrayF(digitsIn->GetNrow(), digitsIn->GetNcol(), digitsIn->GetNtime());
293 Transform(digitsIn, digitsOut, idet, nRowMax, nColMax, nTimeTotal, ADCthreshold);
295 track0 = fDigitsManager->GetDictionary(idet,0);
297 track1 = fDigitsManager->GetDictionary(idet,1);
299 track2 = fDigitsManager->GetDictionary(idet,2);
302 // Loop through the chamber and find the maxima
303 for ( row = 0; row < nRowMax; row++) {
304 for ( col = 2; col < nColMax; col++) {
305 //for ( col = 4; col < nColMax-2; col++) {
306 for (time = 0; time < nTimeTotal; time++) {
308 Float_t signalL = TMath::Abs(digitsOut->GetDataUnchecked(row,col ,time));
309 Float_t signalM = TMath::Abs(digitsOut->GetDataUnchecked(row,col-1,time));
310 Float_t signalR = TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time));
312 // // Lonok for the maximum
313 // if (signalM >= maxThresh) {
314 // if (((signalL >= sigThresh) &&
315 // (signalL < signalM)) ||
316 // ((signalR >= sigThresh) &&
317 // (signalR < signalM))) {
318 // // Maximum found, mark the position by a negative signal
319 // digitsOut->SetDataUnchecked(row,col-1,time,-signalM);
322 // Look for the maximum
323 if (signalM >= maxThresh) {
324 if ( (TMath::Abs(signalL)<=signalM) && (TMath::Abs(signalR)<=signalM) &&
325 (TMath::Abs(signalL)+TMath::Abs(signalR))>sigThresh ) {
326 // Maximum found, mark the position by a negative signal
327 digitsOut->SetDataUnchecked(row,col-1,time,-signalM);
334 // Now check the maxima and calculate the cluster position
335 for ( row = 0; row < nRowMax ; row++) {
336 for (time = 0; time < nTimeTotal; time++) {
337 for ( col = 1; col < nColMax-1; col++) {
340 if (digitsOut->GetDataUnchecked(row,col,time) < 0) {
343 for (iPad = 0; iPad < kNclus; iPad++) {
344 Int_t iPadCol = col - 1 + iPad;
345 clusterSignal[iPad] = TMath::Abs(digitsOut->GetDataUnchecked(row
348 clusterTracks[3*iPad ] = track0->GetDataUnchecked(row,iPadCol,time) - 1;
349 clusterTracks[3*iPad+1] = track1->GetDataUnchecked(row,iPadCol,time) - 1;
350 clusterTracks[3*iPad+2] = track2->GetDataUnchecked(row,iPadCol,time) - 1;
353 // Count the number of pads in the cluster
356 while (TMath::Abs(digitsOut->GetDataUnchecked(row,col-ii ,time))
360 if (col-ii < 0) break;
363 while (TMath::Abs(digitsOut->GetDataUnchecked(row,col+ii+1,time))
367 if (col+ii+1 >= nColMax) break;
394 // Look for 5 pad cluster with minimum in the middle
395 Bool_t fivePadCluster = kFALSE;
396 if (col < nColMax-3) {
397 if (digitsOut->GetDataUnchecked(row,col+2,time) < 0) {
398 fivePadCluster = kTRUE;
400 if ((fivePadCluster) && (col < nColMax-5)) {
401 if (digitsOut->GetDataUnchecked(row,col+4,time) >= sigThresh) {
402 fivePadCluster = kFALSE;
405 if ((fivePadCluster) && (col > 1)) {
406 if (digitsOut->GetDataUnchecked(row,col-2,time) >= sigThresh) {
407 fivePadCluster = kFALSE;
413 // Modify the signal of the overlapping pad for the left part
414 // of the cluster which remains from a previous unfolding
416 clusterSignal[0] *= ratioLeft;
421 // Unfold the 5 pad cluster
422 if (fivePadCluster) {
423 for (iPad = 0; iPad < kNsig; iPad++) {
424 padSignal[iPad] = TMath::Abs(digitsOut->GetDataUnchecked(row
428 // Unfold the two maxima and set the signal on
429 // the overlapping pad to the ratio
430 ratioRight = Unfold(kEpsilon,iplan,padSignal);
431 ratioLeft = 1.0 - ratioRight;
432 clusterSignal[2] *= ratioRight;
437 Double_t clusterCharge = clusterSignal[0]
441 // The position of the cluster
442 clusterPads[0] = row + 0.5;
443 // Take the shift of the additional time bins into account
444 clusterPads[2] = time + 0.5;
447 if (recParam->LUTOn()) {
448 // Calculate the position of the cluster by using the
449 // lookup table method
450 clusterPads[1] = recParam->LUTposition(iplan,clusterSignal[0]
455 // Calculate the position of the cluster by using the
456 // center of gravity method
457 for (Int_t i=0;i<5;i++) padSignal[i]=0;
458 padSignal[2] = TMath::Abs(digitsOut->GetDataUnchecked(row,col,time)); // central pad
459 padSignal[1] = TMath::Abs(digitsOut->GetDataUnchecked(row,col-1,time)); // left pad
460 padSignal[3] = TMath::Abs(digitsOut->GetDataUnchecked(row,col+1,time)); // right pad
461 if (col>2 &&TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time)<padSignal[1])){
462 padSignal[0] = TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time));
464 if (col<nColMax-3 &&TMath::Abs(digitsOut->GetDataUnchecked(row,col+2,time)<padSignal[3])){
465 padSignal[4] = TMath::Abs(digitsOut->GetDataUnchecked(row,col+2,time));
467 clusterPads[1] = GetCOG(padSignal);
471 Double_t q0 = clusterSignal[0];
472 Double_t q1 = clusterSignal[1];
473 Double_t q2 = clusterSignal[2];
474 Double_t clusterSigmaY2 = (q1*(q0+q2)+4*q0*q2) /
475 (clusterCharge*clusterCharge);
479 // Calculate the position and the error
482 Int_t clusterTimeBin = TMath::Nint(time - calibration->GetT0(idet, col, row));
484 Double_t colSize = padPlane->GetColSize(col);
485 Double_t rowSize = padPlane->GetRowSize(row);
486 Double_t clusterPos[3];
487 clusterPos[0] = padPlane->GetColPos(col) - (clusterPads[1]+0.5)*colSize; // MI change
488 clusterPos[1] = padPlane->GetRowPos(row) - 0.5*rowSize; //MI change
489 clusterPos[2] = CalcXposFromTimebin(clusterPads[2], idet, col, row);
490 Double_t clusterSig[2];
491 clusterSig[0] = (clusterSigmaY2 + 1./12.) * colSize*colSize;
492 clusterSig[1] = rowSize * rowSize / 12.;
495 // Add the cluster to the output array
496 AliTRDcluster * cluster = AddCluster(clusterPos
502 ,iType,clusterPads[1]);
505 Short_t signals[7]={0,0,0,0,0,0,0};
506 for (Int_t jPad = col-3;jPad<=col+3;jPad++){
507 if (jPad<0 ||jPad>=nColMax-1) continue;
508 signals[jPad-col+3] = TMath::Nint(TMath::Abs(digitsOut->GetDataUnchecked(row,jPad,time)));
510 cluster->SetSignals(signals);
518 // Compress the arrays
519 track0->Compress(1,0);
520 track1->Compress(1,0);
521 track2->Compress(1,0);
523 // Write the cluster and reset the array
531 printf("<AliTRDclusterizerV1::MakeCluster> ");
541 //_____________________________________________________________________________
542 Double_t AliTRDclusterizerV1::GetCOG(Double_t signal[5])
546 // used for clusters with more than 3 pads - where LUT not applicable
547 Double_t sum = signal[0]+signal[1]+signal[2]+signal[3]+signal[4];
548 Double_t res = (0.0*(-signal[0]+signal[4])+(-signal[1]+signal[3]))/sum;
552 //_____________________________________________________________________________
553 Double_t AliTRDclusterizerV1::Unfold(Double_t eps, Int_t plane, Double_t* padSignal)
556 // Method to unfold neighbouring maxima.
557 // The charge ratio on the overlapping pad is calculated
558 // until there is no more change within the range given by eps.
559 // The resulting ratio is then returned to the calling method.
562 AliTRDcalibDB* calibration = AliTRDcalibDB::Instance();
565 printf("<AliTRDclusterizerMI::Unfold> ");
566 printf("ERROR getting instance of AliTRDcalibDB");
571 Int_t itStep = 0; // Count iteration steps
573 Double_t ratio = 0.5; // Start value for ratio
574 Double_t prevRatio = 0; // Store previous ratio
576 Double_t newLeftSignal[3] = {0}; // Array to store left cluster signal
577 Double_t newRightSignal[3] = {0}; // Array to store right cluster signal
578 Double_t newSignal[3] = {0};
580 // Start the iteration
581 while ((TMath::Abs(prevRatio - ratio) > eps) && (itStep < 10)) {
586 // Cluster position according to charge ratio
587 Double_t maxLeft = (ratio*padSignal[2] - padSignal[0])
588 / (padSignal[0] + padSignal[1] + ratio*padSignal[2]);
589 Double_t maxRight = (padSignal[4] - (1-ratio)*padSignal[2])
590 / ((1-ratio)*padSignal[2] + padSignal[3] + padSignal[4]);
592 // Set cluster charge ratio
593 irc = calibration->PadResponse(1.0,maxLeft ,plane,newSignal);
594 Double_t ampLeft = padSignal[1] / newSignal[1];
595 irc = calibration->PadResponse(1.0,maxRight,plane,newSignal);
596 Double_t ampRight = padSignal[3] / newSignal[1];
598 // Apply pad response to parameters
599 irc = calibration->PadResponse(ampLeft ,maxLeft ,plane,newLeftSignal );
600 irc = calibration->PadResponse(ampRight,maxRight,plane,newRightSignal);
602 // Calculate new overlapping ratio
603 ratio = TMath::Min((Double_t)1.0,newLeftSignal[2] /
604 (newLeftSignal[2] + newRightSignal[0]));
612 //_____________________________________________________________________________
613 void AliTRDclusterizerV1::Transform(AliTRDdataArrayI* digitsIn,
614 AliTRDdataArrayF* digitsOut,
615 Int_t idet, Int_t nRowMax,
616 Int_t nColMax, Int_t nTimeTotal,
617 Float_t ADCthreshold)
622 // Apply tail cancellation: Transform digitsIn to digitsOut
626 AliTRDRecParam* recParam = AliTRDRecParam::Instance();
629 printf("<AliTRDclusterizerV1::Transform> ");
630 printf("ERROR getting instance of AliTRDRecParam");
633 AliTRDcalibDB* calibration = AliTRDcalibDB::Instance();
635 Double_t *inADC = new Double_t[nTimeTotal]; // adc data before tail cancellation
636 Double_t *outADC = new Double_t[nTimeTotal]; // adc data after tail cancellation
639 printf("<AliTRDclusterizerV1::Transform> ");
640 printf("Tail cancellation (nExp = %d) for detector %d.\n",
641 recParam->GetTCnexp(),idet);
644 for (Int_t iRow = 0; iRow < nRowMax; iRow++ ) {
645 for (Int_t iCol = 0; iCol < nColMax; iCol++ ) {
646 for (Int_t iTime = 0; iTime < nTimeTotal; iTime++) {
650 Double_t gain = calibration->GetGainFactor(idet, iCol, iRow);
652 AliError("Not a valid gain\n");
654 inADC[iTime] = digitsIn->GetDataUnchecked(iRow, iCol, iTime);
656 inADC[iTime] /= gain;
657 outADC[iTime] = inADC[iTime];
660 // Apply the tail cancelation via the digital filter
661 if (recParam->TCOn())
663 DeConvExp(inADC,outADC,nTimeTotal,recParam->GetTCnexp());
666 for (Int_t iTime = 0; iTime < nTimeTotal; iTime++) {
667 // Store the amplitude of the digit if above threshold
668 if (outADC[iTime] > ADCthreshold) {
671 printf(" iRow = %d, iCol = %d, iTime = %d, adc = %f\n"
672 ,iRow,iCol,iTime,outADC[iTime]);
674 digitsOut->SetDataUnchecked(iRow,iCol,iTime,outADC[iTime]);
691 //_____________________________________________________________________________
692 void AliTRDclusterizerV1::DeConvExp(Double_t *source, Double_t *target,
696 // Tail Cancellation by Deconvolution for PASA v4 TRF
700 Double_t coefficients[2];
702 // initialize (coefficient = alpha, rates = lambda)
709 if (nexp == 1) { // 1 Exponentials
715 if (nexp == 2) { // 2 Exponentials
722 coefficients[0] = C1;
723 coefficients[1] = C2;
727 rates[0] = TMath::Exp(-Dt/(R1));
728 rates[1] = TMath::Exp(-Dt/(R2));
731 Double_t reminder[2];
732 Double_t correction, result;
734 /* attention: computation order is important */
737 for ( k=0; k<nexp; k++ ) reminder[k]=0.0;
739 for ( i=0; i<n; i++ ) {
740 result = ( source[i] - correction ); // no rescaling
743 for ( k=0; k<nexp; k++ ) reminder[k] = rates[k] *
744 ( reminder[k] + coefficients[k] * result);
746 for ( k=0; k<nexp; k++ ) correction += reminder[k];