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 Revision 1.6 2000/06/09 11:10:07 cblume
19 Compiler warnings and coding conventions, next round
21 Revision 1.5 2000/06/08 18:32:58 cblume
22 Make code compliant to coding conventions
24 Revision 1.4 2000/06/07 16:27:01 cblume
25 Try to remove compiler warnings on Sun and HP
27 Revision 1.3 2000/05/08 16:17:27 cblume
30 Revision 1.1.4.1 2000/05/08 15:09:01 cblume
31 Introduce AliTRDdigitsManager
33 Revision 1.1 2000/02/28 18:58:54 cblume
38 ///////////////////////////////////////////////////////////////////////////////
40 // TRD cluster finder for the slow simulator.
42 ///////////////////////////////////////////////////////////////////////////////
46 #include "AliTRDclusterizerV1.h"
47 #include "AliTRDmatrix.h"
48 #include "AliTRDgeometry.h"
49 #include "AliTRDdigitizer.h"
50 #include "AliTRDrecPoint.h"
51 #include "AliTRDdataArrayF.h"
53 ClassImp(AliTRDclusterizerV1)
55 //_____________________________________________________________________________
56 AliTRDclusterizerV1::AliTRDclusterizerV1():AliTRDclusterizer()
59 // AliTRDclusterizerV1 default constructor
62 fDigitsManager = NULL;
66 //_____________________________________________________________________________
67 AliTRDclusterizerV1::AliTRDclusterizerV1(const Text_t* name, const Text_t* title)
68 :AliTRDclusterizer(name,title)
71 // AliTRDclusterizerV1 default constructor
74 fDigitsManager = new AliTRDdigitsManager();
80 //_____________________________________________________________________________
81 AliTRDclusterizerV1::AliTRDclusterizerV1(const AliTRDclusterizerV1 &c)
84 // AliTRDclusterizerV1 copy constructor
87 ((AliTRDclusterizerV1 &) c).Copy(*this);
91 //_____________________________________________________________________________
92 AliTRDclusterizerV1::~AliTRDclusterizerV1()
95 // AliTRDclusterizerV1 destructor
99 delete fDigitsManager;
104 //_____________________________________________________________________________
105 AliTRDclusterizerV1 &AliTRDclusterizerV1::operator=(const AliTRDclusterizerV1 &c)
108 // Assignment operator
111 if (this != &c) ((AliTRDclusterizerV1 &) c).Copy(*this);
116 //_____________________________________________________________________________
117 void AliTRDclusterizerV1::Copy(TObject &c)
123 ((AliTRDclusterizerV1 &) c).fClusMaxThresh = fClusMaxThresh;
124 ((AliTRDclusterizerV1 &) c).fClusSigThresh = fClusSigThresh;
125 ((AliTRDclusterizerV1 &) c).fClusMethod = fClusMethod;
126 ((AliTRDclusterizerV1 &) c).fDigitsManager = NULL;
128 AliTRDclusterizer::Copy(c);
132 //_____________________________________________________________________________
133 void AliTRDclusterizerV1::Init()
136 // Initializes the cluster finder
139 // The default parameter for the clustering
140 fClusMaxThresh = 5.0;
141 fClusSigThresh = 2.0;
146 //_____________________________________________________________________________
147 Bool_t AliTRDclusterizerV1::ReadDigits()
150 // Reads the digits arrays from the input aliroot file
154 printf("AliTRDclusterizerV1::ReadDigits -- ");
155 printf("No input file open\n");
159 // Read in the digit arrays
160 return (fDigitsManager->ReadDigits());
164 //_____________________________________________________________________________
165 Bool_t AliTRDclusterizerV1::MakeCluster()
168 // Generates the cluster.
171 Int_t row, col, time;
173 // Get the pointer to the detector class and check for version 1
174 AliTRD *trd = (AliTRD*) gAlice->GetDetector("TRD");
175 if (trd->IsVersion() != 1) {
176 printf("AliTRDclusterizerV1::MakeCluster -- ");
177 printf("TRD must be version 1 (slow simulator).\n");
182 AliTRDgeometry *geo = trd->GetGeometry();
184 printf("AliTRDclusterizerV1::MakeCluster -- ");
185 printf("Start creating clusters.\n");
187 AliTRDdataArrayI *digits;
190 Float_t maxThresh = fClusMaxThresh; // threshold value for maximum
191 Float_t signalThresh = fClusSigThresh; // threshold value for digit signal
192 Int_t clusteringMethod = fClusMethod; // clustering method option (for testing)
194 // Iteration limit for unfolding procedure
195 const Float_t kEpsilon = 0.01;
197 const Int_t kNclus = 3;
198 const Int_t kNsig = 5;
201 Int_t chamEnd = kNcham;
202 if (trd->GetSensChamber() >= 0) {
203 chamBeg = trd->GetSensChamber();
204 chamEnd = chamBeg + 1;
207 Int_t planEnd = kNplan;
208 if (trd->GetSensPlane() >= 0) {
209 planBeg = trd->GetSensPlane();
210 planEnd = planBeg + 1;
213 Int_t sectEnd = kNsect;
215 // *** Start clustering *** in every chamber
216 for (Int_t icham = chamBeg; icham < chamEnd; icham++) {
217 for (Int_t iplan = planBeg; iplan < planEnd; iplan++) {
218 for (Int_t isect = sectBeg; isect < sectEnd; isect++) {
220 if (trd->GetSensSector() >= 0) {
221 Int_t sens1 = trd->GetSensSector();
222 Int_t sens2 = sens1 + trd->GetSensSectorRange();
223 sens2 -= ((Int_t) (sens2 / kNsect)) * kNsect;
225 if ((isect < sens1) || (isect >= sens2)) continue;
228 if ((isect < sens1) && (isect >= sens2)) continue;
232 Int_t idet = geo->GetDetector(iplan,icham,isect);
235 printf("AliTRDclusterizerV1::MakeCluster -- ");
236 printf("Analyzing chamber %d, plane %d, sector %d.\n"
239 Int_t nRowMax = geo->GetRowMax(iplan,icham,isect);
240 Int_t nColMax = geo->GetColMax(iplan);
241 Int_t nTimeMax = geo->GetTimeMax();
243 // Create a detector matrix to keep maxima
244 AliTRDmatrix *digitMatrix = new AliTRDmatrix(nRowMax,nColMax,nTimeMax
246 // Create a matrix to contain maximum flags
247 AliTRDmatrix *maximaMatrix = new AliTRDmatrix(nRowMax,nColMax,nTimeMax
250 // Read in the digits
251 digits = fDigitsManager->GetDigits(idet);
253 // Loop through the detector pixel
254 for (time = 0; time < nTimeMax; time++) {
255 for ( col = 0; col < nColMax; col++) {
256 for ( row = 0; row < nRowMax; row++) {
258 Int_t signal = digits->GetData(row,col,time);
259 Int_t index = digits->GetIndex(row,col,time);
261 // Fill the detector matrix
262 if (signal > signalThresh) {
263 // Store the signal amplitude
264 digitMatrix->SetSignal(row,col,time,signal);
265 // Store the digits number
266 digitMatrix->AddTrack(row,col,time,index);
273 // Loop chamber and find maxima in digitMatrix
274 for ( row = 0; row < nRowMax; row++) {
275 for ( col = 1; col < nColMax; col++) {
276 for (time = 0; time < nTimeMax; time++) {
278 if (digitMatrix->GetSignal(row,col,time)
279 < digitMatrix->GetSignal(row,col - 1,time)) {
282 if (digitMatrix->GetSignal(row,col - 2,time)
283 < digitMatrix->GetSignal(row,col - 1,time)) {
284 // yes, so set maximum flag
285 maximaMatrix->SetSignal(row,col - 1,time,1);
287 else maximaMatrix->SetSignal(row,col - 1,time,0);
295 // now check maxima and calculate cluster position
296 for ( row = 0; row < nRowMax; row++) {
297 for ( col = 1; col < nColMax; col++) {
298 for (time = 0; time < nTimeMax; time++) {
300 if ((maximaMatrix->GetSignal(row,col,time) > 0)
301 && (digitMatrix->GetSignal(row,col,time) > maxThresh)) {
303 // Ratio resulting from unfolding
305 // Signals on max and neighbouring pads
306 Float_t padSignal[kNsig] = {0};
307 // Signals from cluster
308 Float_t clusterSignal[kNclus] = {0};
310 Float_t clusterPads[kNclus] = {0};
311 // Cluster digit info
312 Int_t clusterDigit[kNclus] = {0};
315 for (iPad = 0; iPad < kNclus; iPad++) {
316 clusterSignal[iPad] = digitMatrix->GetSignal(row,col-1+iPad,time);
317 clusterDigit[iPad] = digitMatrix->GetTrack(row,col-1+iPad,time,0);
320 // neighbouring maximum on right side?
321 if (col < nColMax - 2) {
322 if (maximaMatrix->GetSignal(row,col + 2,time) > 0) {
324 for (iPad = 0; iPad < 5; iPad++) {
325 padSignal[iPad] = digitMatrix->GetSignal(row,col-1+iPad,time);
329 ratio = Unfold(kEpsilon, padSignal);
331 // set signal on overlapping pad to ratio
332 clusterSignal[2] *= ratio;
337 // Calculate the position of the cluster
338 switch (clusteringMethod) {
340 // method 1: simply center of mass
341 clusterPads[0] = row + 0.5;
342 clusterPads[1] = col - 0.5 + (clusterSignal[2] - clusterSignal[0]) /
343 (clusterSignal[0] + clusterSignal[1] + clusterSignal[2]);
344 clusterPads[2] = time + 0.5;
349 // method 2: integral gauss fit on 3 pads
350 TH1F *hPadCharges = new TH1F("hPadCharges", "Charges on center 3 pads"
352 for (Int_t iCol = -1; iCol <= 3; iCol++) {
353 if (clusterSignal[iCol] < 1) clusterSignal[iCol] = 1;
354 hPadCharges->Fill(iCol, clusterSignal[iCol]);
356 hPadCharges->Fit("gaus", "IQ", "SAME", -0.5, 2.5);
357 TF1 *fPadChargeFit = hPadCharges->GetFunction("gaus");
358 Double_t colMean = fPadChargeFit->GetParameter(1);
360 clusterPads[0] = row + 0.5;
361 clusterPads[1] = col - 1.5 + colMean;
362 clusterPads[2] = time + 0.5;
370 Float_t clusterCharge = clusterSignal[0]
374 // Add the cluster to the output array
375 trd->AddRecPoint(clusterPads,clusterDigit,idet,clusterCharge);
382 printf("AliTRDclusterizerV1::MakeCluster -- ");
383 printf("Number of clusters found: %d\n",nClusters);
392 printf("AliTRDclusterizerV1::MakeCluster -- ");
393 printf("Total number of points found: %d\n"
394 ,trd->RecPoints()->GetEntries());
396 // Get the pointer to the cluster branch
397 TTree *clusterTree = gAlice->TreeR();
399 // Fill the cluster-branch
400 printf("AliTRDclusterizerV1::MakeCluster -- ");
401 printf("Fill the cluster tree.\n");
403 printf("AliTRDclusterizerV1::MakeCluster -- ");
410 //_____________________________________________________________________________
411 Float_t AliTRDclusterizerV1::Unfold(Float_t eps, Float_t* padSignal)
414 // Method to unfold neighbouring maxima.
415 // The charge ratio on the overlapping pad is calculated
416 // until there is no more change within the range given by eps.
417 // The resulting ratio is then returned to the calling method.
420 Int_t itStep = 0; // count iteration steps
422 Float_t ratio = 0.5; // start value for ratio
423 Float_t prevRatio = 0; // store previous ratio
425 Float_t newLeftSignal[3] = {0}; // array to store left cluster signal
426 Float_t newRightSignal[3] = {0}; // array to store right cluster signal
429 while ((TMath::Abs(prevRatio - ratio) > eps) && (itStep < 10)) {
434 // cluster position according to charge ratio
435 Float_t maxLeft = (ratio*padSignal[2] - padSignal[0]) /
436 (padSignal[0] + padSignal[1] + ratio*padSignal[2]);
437 Float_t maxRight = (padSignal[4] - (1-ratio)*padSignal[2]) /
438 ((1-ratio)*padSignal[2] + padSignal[3] + padSignal[4]);
440 // set cluster charge ratio
441 Float_t ampLeft = padSignal[1];
442 Float_t ampRight = padSignal[3];
444 // apply pad response to parameters
445 newLeftSignal[0] = ampLeft*PadResponse(-1 - maxLeft);
446 newLeftSignal[1] = ampLeft*PadResponse( 0 - maxLeft);
447 newLeftSignal[2] = ampLeft*PadResponse( 1 - maxLeft);
449 newRightSignal[0] = ampRight*PadResponse(-1 - maxRight);
450 newRightSignal[1] = ampRight*PadResponse( 0 - maxRight);
451 newRightSignal[2] = ampRight*PadResponse( 1 - maxRight);
453 // calculate new overlapping ratio
454 ratio = newLeftSignal[2]/(newLeftSignal[2] + newRightSignal[0]);
462 //_____________________________________________________________________________
463 Float_t AliTRDclusterizerV1::PadResponse(Float_t x)
466 // The pad response for the chevron pads.
467 // We use a simple Gaussian approximation which should be good
468 // enough for our purpose.
471 // The parameters for the response function
472 const Float_t kA = 0.8872;
473 const Float_t kB = -0.00573;
474 const Float_t kC = 0.454;
475 const Float_t kC2 = kC*kC;
477 Float_t pr = kA * (kB + TMath::Exp(-x*x / (2. * kC2)));