1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // TRD cluster finder for the slow simulator.
22 ///////////////////////////////////////////////////////////////////////////////
30 #include "AliRunLoader.h"
31 #include "AliLoader.h"
32 #include "AliRawReader.h"
34 #include "AliTRDclusterizerV1.h"
35 #include "AliTRDmatrix.h"
36 #include "AliTRDgeometry.h"
37 #include "AliTRDdataArrayF.h"
38 #include "AliTRDdataArrayI.h"
39 #include "AliTRDdigitsManager.h"
40 #include "AliTRDparameter.h"
41 #include "AliTRDpadPlane.h"
42 #include "AliTRDrawData.h"
44 ClassImp(AliTRDclusterizerV1)
46 //_____________________________________________________________________________
47 AliTRDclusterizerV1::AliTRDclusterizerV1():AliTRDclusterizer()
50 // AliTRDclusterizerV1 default constructor
57 //_____________________________________________________________________________
58 AliTRDclusterizerV1::AliTRDclusterizerV1(const Text_t* name, const Text_t* title)
59 :AliTRDclusterizer(name,title)
62 // AliTRDclusterizerV1 default constructor
65 fDigitsManager = new AliTRDdigitsManager();
66 fDigitsManager->CreateArrays();
70 //_____________________________________________________________________________
71 AliTRDclusterizerV1::AliTRDclusterizerV1(const AliTRDclusterizerV1 &c)
75 // AliTRDclusterizerV1 copy constructor
78 ((AliTRDclusterizerV1 &) c).Copy(*this);
82 //_____________________________________________________________________________
83 AliTRDclusterizerV1::~AliTRDclusterizerV1()
86 // AliTRDclusterizerV1 destructor
90 delete fDigitsManager;
91 fDigitsManager = NULL;
96 //_____________________________________________________________________________
97 AliTRDclusterizerV1 &AliTRDclusterizerV1::operator=(const AliTRDclusterizerV1 &c)
100 // Assignment operator
103 if (this != &c) ((AliTRDclusterizerV1 &) c).Copy(*this);
108 //_____________________________________________________________________________
109 void AliTRDclusterizerV1::Copy(TObject &c) const
115 ((AliTRDclusterizerV1 &) c).fDigitsManager = 0;
117 AliTRDclusterizer::Copy(c);
121 //_____________________________________________________________________________
122 Bool_t AliTRDclusterizerV1::ReadDigits()
125 // Reads the digits arrays from the input aliroot file
129 printf("<AliTRDclusterizerV1::ReadDigits> ");
130 printf("No input file open\n");
133 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
134 if (!loader->TreeD()) loader->LoadDigits();
136 // Read in the digit arrays
137 return (fDigitsManager->ReadDigits(loader->TreeD()));
141 //_____________________________________________________________________________
142 Bool_t AliTRDclusterizerV1::ReadDigits(AliRawReader* rawReader)
145 // Reads the digits arrays from the ddl file
148 AliTRDrawData *raw = new AliTRDrawData();
151 fDigitsManager = raw->Raw2Digits(rawReader);
157 //_____________________________________________________________________________
158 Bool_t AliTRDclusterizerV1::MakeClusters()
161 // Generates the cluster.
164 Int_t row, col, time;
167 if (fTRD->IsVersion() != 1) {
168 printf("<AliTRDclusterizerV1::MakeCluster> ");
169 printf("TRD must be version 1 (slow simulator).\n");
175 AliTRDgeometry *geo = AliTRDgeometry::GetGeometry(fRunLoader);
177 // Create a default parameter class if none is defined
179 fPar = new AliTRDparameter("TRDparameter","Standard TRD parameter");
180 printf("<AliTRDclusterizerV1::MakeCluster> ");
181 printf("Create the default parameter object.\n");
185 //Float_t timeBinSize = fPar->GetDriftVelocity()
186 // / fPar->GetSamplingFrequency();
187 // Half of ampl.region
188 // const Float_t kAmWidth = AliTRDgeometry::AmThick()/2.;
190 Float_t omegaTau = fPar->GetOmegaTau();
192 printf("<AliTRDclusterizerV1::MakeCluster> ");
193 printf("OmegaTau = %f \n",omegaTau);
194 printf("<AliTRDclusterizerV1::MakeCluster> ");
195 printf("Start creating clusters.\n");
198 AliTRDdataArrayI *digits;
199 AliTRDdataArrayI *track0;
200 AliTRDdataArrayI *track1;
201 AliTRDdataArrayI *track2;
203 // Threshold value for the maximum
204 Int_t maxThresh = fPar->GetClusMaxThresh();
205 // Threshold value for the digit signal
206 Int_t sigThresh = fPar->GetClusSigThresh();
207 // Iteration limit for unfolding procedure
208 const Float_t kEpsilon = 0.01;
210 const Int_t kNclus = 3;
211 const Int_t kNsig = 5;
212 const Int_t kNtrack = 3 * kNclus;
216 Double_t ratioLeft = 1.0;
217 Double_t ratioRight = 1.0;
220 Double_t padSignal[kNsig];
221 Double_t clusterSignal[kNclus];
222 Double_t clusterPads[kNclus];
223 Int_t clusterDigit[kNclus];
224 Int_t clusterTracks[kNtrack];
227 Int_t chamEnd = AliTRDgeometry::Ncham();
229 Int_t planEnd = AliTRDgeometry::Nplan();
231 Int_t sectEnd = AliTRDgeometry::Nsect();
233 // Start clustering in every chamber
234 for (Int_t icham = chamBeg; icham < chamEnd; icham++) {
235 for (Int_t iplan = planBeg; iplan < planEnd; iplan++) {
236 for (Int_t isect = sectBeg; isect < sectEnd; isect++) {
238 Int_t idet = geo->GetDetector(iplan,icham,isect);
241 Int_t nClusters2pad = 0;
242 Int_t nClusters3pad = 0;
243 Int_t nClusters4pad = 0;
244 Int_t nClusters5pad = 0;
245 Int_t nClustersLarge = 0;
248 printf("<AliTRDclusterizerV1::MakeCluster> ");
249 printf("Analyzing chamber %d, plane %d, sector %d.\n"
253 Int_t nRowMax = fPar->GetRowMax(iplan,icham,isect);
254 Int_t nColMax = fPar->GetColMax(iplan);
255 Int_t nTimeBefore = fPar->GetTimeBefore();
256 Int_t nTimeTotal = fPar->GetTimeTotal();
258 AliTRDpadPlane *padPlane = fPar->GetPadPlane(iplan,icham);
261 digits = fDigitsManager->GetDigits(idet);
263 track0 = fDigitsManager->GetDictionary(idet,0);
265 track1 = fDigitsManager->GetDictionary(idet,1);
267 track2 = fDigitsManager->GetDictionary(idet,2);
270 // Loop through the chamber and find the maxima
271 for ( row = 0; row < nRowMax; row++) {
272 for ( col = 2; col < nColMax; col++) {
273 //for ( col = 4; col < nColMax-2; col++) {
274 for (time = 0; time < nTimeTotal; time++) {
276 Int_t signalL = TMath::Abs(digits->GetDataUnchecked(row,col ,time));
277 Int_t signalM = TMath::Abs(digits->GetDataUnchecked(row,col-1,time));
278 Int_t signalR = TMath::Abs(digits->GetDataUnchecked(row,col-2,time));
280 // // Look for the maximum
281 // if (signalM >= maxThresh) {
282 // if (((signalL >= sigThresh) &&
283 // (signalL < signalM)) ||
284 // ((signalR >= sigThresh) &&
285 // (signalR < signalM))) {
286 // // Maximum found, mark the position by a negative signal
287 // digits->SetDataUnchecked(row,col-1,time,-signalM);
290 // Look for the maximum
291 if (signalM >= maxThresh) {
292 if ( (TMath::Abs(signalL)<=signalM) && (TMath::Abs(signalR)<=signalM) &&
293 (TMath::Abs(signalL)+TMath::Abs(signalR))>sigThresh ) {
294 // Maximum found, mark the position by a negative signal
295 digits->SetDataUnchecked(row,col-1,time,-signalM);
303 // Now check the maxima and calculate the cluster position
304 for ( row = 0; row < nRowMax ; row++) {
305 for (time = 0; time < nTimeTotal; time++) {
306 for ( col = 1; col < nColMax-1; col++) {
309 if (digits->GetDataUnchecked(row,col,time) < 0) {
312 for (iPad = 0; iPad < kNclus; iPad++) {
313 Int_t iPadCol = col - 1 + iPad;
314 clusterSignal[iPad] = TMath::Abs(digits->GetDataUnchecked(row
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;
323 // Count the number of pads in the cluster
326 while (TMath::Abs(digits->GetDataUnchecked(row,col-ii ,time))
330 if (col-ii < 0) break;
333 while (TMath::Abs(digits->GetDataUnchecked(row,col+ii+1,time))
337 if (col+ii+1 >= nColMax) break;
364 // Look for 5 pad cluster with minimum in the middle
365 Bool_t fivePadCluster = kFALSE;
366 if (col < nColMax-3) {
367 if (digits->GetDataUnchecked(row,col+2,time) < 0) {
368 fivePadCluster = kTRUE;
370 if ((fivePadCluster) && (col < nColMax-5)) {
371 if (digits->GetDataUnchecked(row,col+4,time) >= sigThresh) {
372 fivePadCluster = kFALSE;
375 if ((fivePadCluster) && (col > 1)) {
376 if (digits->GetDataUnchecked(row,col-2,time) >= sigThresh) {
377 fivePadCluster = kFALSE;
383 // Modify the signal of the overlapping pad for the left part
384 // of the cluster which remains from a previous unfolding
386 clusterSignal[0] *= ratioLeft;
391 // Unfold the 5 pad cluster
392 if (fivePadCluster) {
393 for (iPad = 0; iPad < kNsig; iPad++) {
394 padSignal[iPad] = TMath::Abs(digits->GetDataUnchecked(row
398 // Unfold the two maxima and set the signal on
399 // the overlapping pad to the ratio
400 ratioRight = Unfold(kEpsilon,iplan,padSignal);
401 ratioLeft = 1.0 - ratioRight;
402 clusterSignal[2] *= ratioRight;
408 Double_t clusterCharge = clusterSignal[0]
412 // The position of the cluster
413 clusterPads[0] = row + 0.5;
414 // Take the shift of the additional time bins into account
415 clusterPads[2] = time - nTimeBefore + 0.5;
418 // Calculate the position of the cluster by using the
419 // lookup table method
421 fPar->LUTposition(iplan,clusterSignal[0]
426 // Calculate the position of the cluster by using the
427 // center of gravity method
428 for (Int_t i=0;i<5;i++) padSignal[i]=0;
429 padSignal[2] = TMath::Abs(digits->GetDataUnchecked(row,col,time)); // central pad
430 padSignal[1] = TMath::Abs(digits->GetDataUnchecked(row,col-1,time)); // left pad
431 padSignal[3] = TMath::Abs(digits->GetDataUnchecked(row,col+1,time)); // right pad
432 if (col>2 &&TMath::Abs(digits->GetDataUnchecked(row,col-2,time)<padSignal[1])){
433 padSignal[0] = TMath::Abs(digits->GetDataUnchecked(row,col-2,time));
435 if (col<nColMax-3 &&TMath::Abs(digits->GetDataUnchecked(row,col+2,time)<padSignal[3])){
436 padSignal[4] = TMath::Abs(digits->GetDataUnchecked(row,col+2,time));
438 clusterPads[1] = GetCOG(padSignal);
439 //Double_t check = fPar->LUTposition(iplan,clusterSignal[0]
441 // ,clusterSignal[2]);
442 // Float_t diff = clusterPads[1] - check;
446 Double_t q0 = clusterSignal[0];
447 Double_t q1 = clusterSignal[1];
448 Double_t q2 = clusterSignal[2];
449 Double_t clusterSigmaY2 = (q1*(q0+q2)+4*q0*q2) /
450 (clusterCharge*clusterCharge);
452 // Calculate the position and the error
453 Double_t colSize = padPlane->GetColSize(col);
454 Double_t rowSize = padPlane->GetRowSize(row);
455 Double_t clusterPos[3];
456 clusterPos[0] = padPlane->GetColPos(col) + (clusterPads[1]-0.5)*colSize; // MI change
457 clusterPos[1] = padPlane->GetRowPos(row) -0.5*rowSize; //MI change
458 clusterPos[2] = clusterPads[2];
459 Double_t clusterSig[2];
460 clusterSig[0] = (clusterSigmaY2 + 1./12.) * colSize*colSize;
461 clusterSig[1] = rowSize * rowSize / 12.;
462 // Add the cluster to the output array
463 AddCluster(clusterPos
468 ,iType,clusterPads[1]);
475 // Compress the arrays
476 digits->Compress(1,0);
477 track0->Compress(1,0);
478 track1->Compress(1,0);
479 track2->Compress(1,0);
481 // Write the cluster and reset the array
489 printf("<AliTRDclusterizerV1::MakeCluster> ");
497 Double_t AliTRDclusterizerV1::GetCOG(Double_t signal[5])
501 // used for clusters with more than 3 pads - where LUT not applicable
502 Double_t sum = signal[0]+signal[1]+signal[2]+signal[3]+signal[4];
503 Double_t res = (0.0*(-signal[0]+signal[4])+(-signal[1]+signal[3]))/sum;
509 //_____________________________________________________________________________
510 Double_t AliTRDclusterizerV1::Unfold(Double_t eps, Int_t plane, Double_t* padSignal)
513 // Method to unfold neighbouring maxima.
514 // The charge ratio on the overlapping pad is calculated
515 // until there is no more change within the range given by eps.
516 // The resulting ratio is then returned to the calling method.
520 Int_t itStep = 0; // Count iteration steps
522 Double_t ratio = 0.5; // Start value for ratio
523 Double_t prevRatio = 0; // Store previous ratio
525 Double_t newLeftSignal[3] = {0}; // Array to store left cluster signal
526 Double_t newRightSignal[3] = {0}; // Array to store right cluster signal
527 Double_t newSignal[3] = {0};
529 // Start the iteration
530 while ((TMath::Abs(prevRatio - ratio) > eps) && (itStep < 10)) {
535 // Cluster position according to charge ratio
536 Double_t maxLeft = (ratio*padSignal[2] - padSignal[0])
537 / (padSignal[0] + padSignal[1] + ratio*padSignal[2]);
538 Double_t maxRight = (padSignal[4] - (1-ratio)*padSignal[2])
539 / ((1-ratio)*padSignal[2] + padSignal[3] + padSignal[4]);
541 // Set cluster charge ratio
542 irc = fPar->PadResponse(1.0,maxLeft ,plane,newSignal);
543 Double_t ampLeft = padSignal[1] / newSignal[1];
544 irc = fPar->PadResponse(1.0,maxRight,plane,newSignal);
545 Double_t ampRight = padSignal[3] / newSignal[1];
547 // Apply pad response to parameters
548 irc = fPar->PadResponse(ampLeft ,maxLeft ,plane,newLeftSignal );
549 irc = fPar->PadResponse(ampRight,maxRight,plane,newRightSignal);
551 // Calculate new overlapping ratio
552 ratio = TMath::Min((Double_t)1.0,newLeftSignal[2] /
553 (newLeftSignal[2] + newRightSignal[0]));