]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONClusterFinderAZ.cxx
Removing, as not used anymore (Laurent)
[u/mrichter/AliRoot.git] / MUON / AliMUONClusterFinderAZ.cxx
CommitLineData
30178c30 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
d19b6003 18// -------------------------------
19// Class AliMUONClusterFinderAZ
20// -------------------------------
21// Clusterizer class based on the Expectation-Maximization algorithm
22// Author: Alexander Zinchenko, JINR Dubna
0df3ca52 23
30178c30 24#include "AliMUONClusterFinderAZ.h"
45c72492 25#include "AliMpVSegmentation.h"
0627f609 26#include "AliMUONGeometryModuleTransformer.h"
45c72492 27#include "AliMUONVDigit.h"
28#include "AliMUONCluster.h"
0df3ca52 29#include "AliMUONPixel.h"
0627f609 30#include "AliMUONMathieson.h"
45c72492 31#include "AliMpDEManager.h"
32#include "AliMUONVDigitStore.h"
33#include "AliMUONConstants.h"
aacf0960 34#include "AliRunLoader.h"
35#include "AliLog.h"
36
37#include <TClonesArray.h>
38#include <TH2.h>
39#include <TMinuit.h>
40#include <TMatrixD.h>
41#include <TRandom.h>
42#include <TROOT.h>
43#include <TMath.h>
44#include <Riostream.h>
45
46#include <stdlib.h>
0df3ca52 47
13985652 48/// \cond CLASSIMP
0df3ca52 49ClassImp(AliMUONClusterFinderAZ)
13985652 50/// \endcond
0558a292 51
343146bf 52 const Double_t AliMUONClusterFinderAZ::fgkCouplMin = 1.e-3; // threshold on coupling
0627f609 53 const Double_t AliMUONClusterFinderAZ::fgkZeroSuppression = 6; // average zero suppression value
54 const Double_t AliMUONClusterFinderAZ::fgkSaturation = 3000; // average saturation level
0558a292 55 AliMUONClusterFinderAZ* AliMUONClusterFinderAZ::fgClusterFinder = 0x0;
56 TMinuit* AliMUONClusterFinderAZ::fgMinuit = 0x0;
2b1e4f0e 57//FILE *lun1 = fopen("nxny.dat","w");
0df3ca52 58
0df3ca52 59//_____________________________________________________________________________
1af223d7 60AliMUONClusterFinderAZ::AliMUONClusterFinderAZ(Bool_t draw)
45c72492 61 : AliMUONVClusterFinder(),
54d7ba50 62 fNpar(0),
63 fQtot(0),
64 fReco(1),
65 fCathBeg(0),
45c72492 66// fDraw(0x0),
54d7ba50 67 fPixArray(0x0),
68 fnCoupled(0),
aacf0960 69 fDebug(0), // 0),
45c72492 70fRawClusters(new TClonesArray("AliMUONCluster",100)),
71fDigitStore(0x0),
72fDetElemId(-1),
73fChamberId(-1),
74fMathieson(0x0),
75fCurrentCluster(-1)
0df3ca52 76{
d19b6003 77/// Constructor
af34d705 78 fnPads[0]=fnPads[1]=0;
79
80 for (Int_t i=0; i<7; i++)
81 for (Int_t j=0; j<fgkDim; j++)
82 fXyq[i][j]= 9999.;
83
0627f609 84 for (Int_t i=0; i<4; i++)
85 for (Int_t j=0; j<fgkDim; j++)
af34d705 86 fPadIJ[i][j]=-1;
0627f609 87
88 for (Int_t i=0; i<2; i++)
89 for (Int_t j=0; j<fgkDim; j++)
af34d705 90 fUsed[i][j] = 0;
af34d705 91
0627f609 92 fSegmentation[1] = fSegmentation[0] = 0x0;
af34d705 93
54d7ba50 94 fPadBeg[0] = fPadBeg[1] = 0;
af34d705 95
0df3ca52 96 if (!fgMinuit) fgMinuit = new TMinuit(8);
af34d705 97 if (!fgClusterFinder) fgClusterFinder = this;
0df3ca52 98 fPixArray = new TObjArray(20);
af34d705 99
1af223d7 100 if (draw) {
101 fDebug = 1;
cc87ebcd 102 fReco = 0;
45c72492 103 // fDraw = new AliMUONClusterDrawAZ(this);
1af223d7 104 }
6abf71cd 105 AliInfo(" *** Running AZ cluster finder *** ");
0df3ca52 106}
107
108//_____________________________________________________________________________
109AliMUONClusterFinderAZ::~AliMUONClusterFinderAZ()
110{
d19b6003 111/// Destructor
0df3ca52 112 delete fgMinuit; fgMinuit = 0; delete fPixArray; fPixArray = 0;
45c72492 113 delete fMathieson;
114// delete fDraw;
0df3ca52 115}
116
117//_____________________________________________________________________________
45c72492 118Bool_t
119AliMUONClusterFinderAZ::Prepare(const AliMpVSegmentation* segmentations[2],
120 const AliMUONVDigitStore& digitStore)
0df3ca52 121{
45c72492 122 /// Prepare for the clusterization of one detection element, which digits
123 /// are in digitStore
124
125 fSegmentation[0] = segmentations[0];
126 fSegmentation[1] = segmentations[1];
127 fDigitStore = &digitStore;
128 fDetElemId = -1;
129 TIter next(digitStore.CreateIterator());
130 AliMUONVDigit* digit = static_cast<AliMUONVDigit*>(next());
131 if (digit) fDetElemId = digit->DetElemId();
132 fCurrentCluster = -1;
133 if ( fDetElemId > 0 )
134 {
135 fChamberId = AliMpDEManager::GetChamberId(fDetElemId);
136 AliMp::StationType stationType = AliMpDEManager::GetStationType(fDetElemId);
137
138 Float_t kx3 = AliMUONConstants::SqrtKx3();
139 Float_t ky3 = AliMUONConstants::SqrtKy3();
140 Float_t pitch = AliMUONConstants::Pitch();
141
142 if ( stationType == AliMp::kStation1 )
143 {
144 kx3 = AliMUONConstants::SqrtKx3St1();
145 ky3 = AliMUONConstants::SqrtKy3St1();
146 pitch = AliMUONConstants::PitchSt1();
147 }
148
149 delete fMathieson;
150 fMathieson = new AliMUONMathieson;
151
152 fMathieson->SetPitch(pitch);
153 fMathieson->SetSqrtKx3AndDeriveKx2Kx4(kx3);
154 fMathieson->SetSqrtKy3AndDeriveKy2Ky4(ky3);
155
156 return kTRUE;
157 }
158 return kFALSE;
159}
0df3ca52 160
45c72492 161//_____________________________________________________________________________
162AliMUONCluster*
163AliMUONClusterFinderAZ::NextCluster()
164{
165 /// Return the next cluster in the iteration
166 if ( fCurrentCluster == -1 )
167 {
168 FindRawClusters(0);
169 }
170
171 ++fCurrentCluster;
172 if ( fCurrentCluster <= fRawClusters->GetLast() )
173 {
174 return static_cast<AliMUONCluster*>(fRawClusters->At(fCurrentCluster));
175 }
176 return 0x0;
177}
178
179//_____________________________________________________________________________
180void AliMUONClusterFinderAZ::FindRawClusters(Int_t ch)
181{
182 /// To comply with old old old interface...
1af223d7 183 ResetRawClusters();
45c72492 184 EventLoop (ch);
0df3ca52 185}
186
187//_____________________________________________________________________________
45c72492 188void AliMUONClusterFinderAZ::EventLoop(Int_t)
0df3ca52 189{
d19b6003 190/// Loop over digits
0df3ca52 191
45c72492 192 // if (fDraw && !fDraw->FindEvCh(nev, ch)) return;
0df3ca52 193
45c72492 194// AliInfo("");
195// fDigitStore->Print();
196
1af223d7 197 Int_t ndigits[2] = {9,9}, nShown[2] = {0};
cc87ebcd 198 if (fReco != 2) { // skip initialization for the combined cluster / track
199 fCathBeg = fPadBeg[0] = fPadBeg[1] = 0;
200 for (Int_t i = 0; i < 2; i++) {
201 for (Int_t j = 0; j < fgkDim; j++) { fUsed[i][j] = kFALSE; }
202 }
0df3ca52 203 }
204
205next:
cc87ebcd 206 if (fReco == 2 && (nShown[0] || nShown[1])) return; // only one precluster for the combined finder
1af223d7 207 if (ndigits[0] == nShown[0] && ndigits[1] == nShown[1]) return;
208
0df3ca52 209 Bool_t first = kTRUE;
aacf0960 210 if (fDebug) cout << " *** Event # " << AliRunLoader::GetRunLoader()->GetEventNumber() << " det. elem.: "
211 << fDetElemId << endl;
0df3ca52 212 fnPads[0] = fnPads[1] = 0;
45c72492 213 for (Int_t i = 0; i < fgkDim; i++)
214 {
215 fPadIJ[1][i] = 0;
216 fDigitId[i] = 0;
217 }
218
219 for (Int_t iii = fCathBeg; iii < 2; iii++)
220 {
0df3ca52 221 Int_t cath = TMath::Odd(iii);
45c72492 222 TIter next(fDigitStore->CreateIterator(fDetElemId,fDetElemId,cath));
0df3ca52 223
45c72492 224 AliMUONVDigit *mdig;
c1aed84f 225 Bool_t eEOC = kTRUE; // end-of-cluster
45c72492 226
227 while ( ( mdig = static_cast<AliMUONVDigit*>(next()) ) )
228 {
229 if (first)
230 {
231 // Find first unused pad
232 if (mdig->IsUsed()) continue;
233 }
234 else
235 {
236 if (mdig->IsUsed()) continue;
237 // Find a pad overlapping with the cluster
238 if (!Overlap(cath,*mdig)) continue;
0df3ca52 239 }
240 // Add pad - recursive call
45c72492 241 AddPad(cath,*mdig);
c1aed84f 242 eEOC = kFALSE;
45c72492 243 break;
0df3ca52 244 }
45c72492 245 if (first && eEOC)
246 {
0df3ca52 247 // No more unused pads
248 if (cath == 0) continue; // on cathode #0 - check #1
2b1e4f0e 249 else return; // No more clusters
0df3ca52 250 }
c1aed84f 251 if (eEOC) break; // cluster found
0df3ca52 252 first = kFALSE;
2b1e4f0e 253 if (fDebug) cout << " nPads: " << fnPads[cath] << " " << nShown[cath]+fnPads[cath] << " " << cath << endl;
0df3ca52 254 } // for (Int_t iii = 0;
255
45c72492 256// if (fDraw) fDraw->DrawCluster();
2b1e4f0e 257
258 // Use MLEM for cluster finder
259 Int_t nMax = 1, localMax[100], maxPos[100];
260 Double_t maxVal[100];
0df3ca52 261
2b1e4f0e 262 if (CheckPrecluster(nShown)) {
45c72492 263// AliInfo("After CheckPrecluster");
264// Print();
2b1e4f0e 265 BuildPixArray();
45c72492 266// AliInfo("PixArray");
267// fPixArray->Print();
0627f609 268 //*
269 if (fnPads[0]+fnPads[1] > 50) nMax = FindLocalMaxima(fPixArray, localMax, maxVal);
2b1e4f0e 270 if (nMax > 1) TMath::Sort(nMax, maxVal, maxPos, kTRUE); // in decreasing order
271 Int_t iSimple = 0, nInX = -1, nInY;
272 PadsInXandY(nInX, nInY);
273 if (fDebug) cout << "Pads in X and Y: " << nInX << " " << nInY << endl;
5a051e34 274 if (nMax == 1 && nInX < 4 && nInY < 4) iSimple = 1; //1; // simple cluster
0627f609 275 //*/
276 /* For test
277 Int_t iSimple = 0, nInX = -1, nInY;
278 PadsInXandY(nInX, nInY);
279 if (fDebug) cout << "Pads in X and Y: " << nInX << " " << nInY << endl;
280 if (nMax == 1 && nInX < 4 && nInY < 4) iSimple = 1; //1; // simple cluster
281 if (!iSimple) nMax = FindLocalMaxima(fPixArray, localMax, maxVal);
282 nMax = 1;
283 if (nMax > 1) TMath::Sort(nMax, maxVal, maxPos, kTRUE); // in decreasing order
284 */
2b1e4f0e 285 for (Int_t i=0; i<nMax; i++) {
286 if (nMax > 1) FindCluster(localMax, maxPos[i]);
af82d8d2 287 MainLoop(iSimple);
2b1e4f0e 288 if (i < nMax-1) {
289 for (Int_t j=0; j<fnPads[0]+fnPads[1]; j++) {
290 if (fPadIJ[1][j] == 0) continue; // pad charge was not modified
291 fPadIJ[1][j] = 0;
292 fXyq[2][j] = fXyq[6][j]; // use backup charge value
293 }
294 }
0627f609 295 } // for (Int_t i=0; i<nMax;
296 if (nMax > 1) ((TH2D*) gROOT->FindObject("anode"))->Delete();
297 TH2D *mlem = (TH2D*) gROOT->FindObject("mlem");
298 if (mlem) mlem->Delete();
2b1e4f0e 299 }
45c72492 300// if (!fDraw || fDraw->Next()) goto next;
301 goto next;
0df3ca52 302}
303
304//_____________________________________________________________________________
45c72492 305void AliMUONClusterFinderAZ::AddPad(Int_t cath, AliMUONVDigit& mdig)
0df3ca52 306{
d19b6003 307/// Add pad to the cluster
308
45c72492 309// AliInfo("");
310// StdoutToAliWarning(mdig.Print(););
311
312 Float_t charge = mdig.Charge();
0df3ca52 313
45c72492 314 AliMpPad pad = fSegmentation[cath]->PadByIndices(AliMpIntPair(mdig.PadX(),mdig.PadY()));
315
0df3ca52 316 // get the center of the pad
45c72492 317 Float_t xpad = pad.Position().X();
318 Float_t ypad = pad.Position().Y();
319
320// Int_t isec = fSegmentation[cath]->Sector(mdig.PadX(), mdig.PadY());
0df3ca52 321 Int_t nPads = fnPads[0] + fnPads[1];
322 fXyq[0][nPads] = xpad;
323 fXyq[1][nPads] = ypad;
324 fXyq[2][nPads] = charge;
45c72492 325 fXyq[3][nPads] = pad.Dimensions().X();
326 fXyq[4][nPads] = pad.Dimensions().Y();
327 fXyq[5][nPads] = -1;
328 fDigitId[nPads] = mdig.GetUniqueID();
2b1e4f0e 329 fXyq[6][nPads] = 0;
0df3ca52 330 fPadIJ[0][nPads] = cath;
331 fPadIJ[1][nPads] = 0;
45c72492 332 fPadIJ[2][nPads] = mdig.PadX();
333 fPadIJ[3][nPads] = mdig.PadY();
334 mdig.Used(kTRUE);
335 if (fDebug) printf(" bbb %d %d %f %f %f %f %f %3d %3d \n", nPads, cath,
336 xpad, ypad, fXyq[3][nPads]*2, fXyq[4][nPads]*2,
337 charge, mdig.PadX(), mdig.PadY());
0df3ca52 338 fnPads[cath]++;
339
340 // Check neighbours
45c72492 341 TObjArray neighbours;
342 Int_t nn = fSegmentation[cath]->GetNeighbours(pad,neighbours);
343 for (Int_t in = 0; in < nn; ++in)
344 {
345 AliMpPad* p = static_cast<AliMpPad*>(neighbours.At(in));
346 AliMUONVDigit* mdig1 = static_cast<AliMUONVDigit*>
347 (fDigitStore->FindObject(fDetElemId,p->GetLocation().GetFirst(),p->GetLocation().GetSecond()));
348 if ( mdig1 && !mdig1->IsUsed() )
349 {
350 AddPad(cath,*mdig1);
351 }
0627f609 352 } // for (Int_t in = 0;
0df3ca52 353}
354
355//_____________________________________________________________________________
45c72492 356Bool_t AliMUONClusterFinderAZ::Overlap(Int_t cath, const AliMUONVDigit& mdig)
0df3ca52 357{
d19b6003 358/// Check if the pad from one cathode overlaps with a pad
359/// in the precluster on the other cathode
0df3ca52 360
45c72492 361 AliMpPad pad = fSegmentation[cath]->PadByIndices(AliMpIntPair(mdig.PadX(), mdig.PadY()));
002920d1 362
45c72492 363 Float_t xpad = pad.Position().X();
364 Float_t ypad = pad.Position().Y();
365
366 Float_t dx = pad.Dimensions().X();
367 Float_t dy = pad.Dimensions().Y();
368
2b1e4f0e 369 Float_t xy1[4], xy12[4];
45c72492 370 xy1[0] = xpad - dx;
371 xy1[1] = xy1[0] + dx*2;
372 xy1[2] = ypad - dy;
373 xy1[3] = xy1[2] + dy*2;
0df3ca52 374
375 Int_t cath1 = TMath::Even(cath);
376 for (Int_t i=0; i<fnPads[0]+fnPads[1]; i++) {
377 if (fPadIJ[0][i] != cath1) continue;
378 if (Overlap(xy1, i, xy12, 0)) return kTRUE;
379 }
380 return kFALSE;
381}
382
383//_____________________________________________________________________________
384Bool_t AliMUONClusterFinderAZ::Overlap(Float_t *xy1, Int_t iPad, Float_t *xy12, Int_t iSkip)
385{
d19b6003 386/// Check if the pads xy1 and iPad overlap and return overlap area
0df3ca52 387
388 Float_t xy2[4];
389 xy2[0] = fXyq[0][iPad] - fXyq[3][iPad];
390 xy2[1] = fXyq[0][iPad] + fXyq[3][iPad];
391 if (xy1[0] > xy2[1]-1.e-4 || xy1[1] < xy2[0]+1.e-4) return kFALSE;
392 xy2[2] = fXyq[1][iPad] - fXyq[4][iPad];
393 xy2[3] = fXyq[1][iPad] + fXyq[4][iPad];
394 if (xy1[2] > xy2[3]-1.e-4 || xy1[3] < xy2[2]+1.e-4) return kFALSE;
395 if (!iSkip) return kTRUE; // just check overlap (w/out computing the area)
396 xy12[0] = TMath::Max (xy1[0],xy2[0]);
397 xy12[1] = TMath::Min (xy1[1],xy2[1]);
398 xy12[2] = TMath::Max (xy1[2],xy2[2]);
399 xy12[3] = TMath::Min (xy1[3],xy2[3]);
400 return kTRUE;
401}
402
45c72492 403//_____________________________________________________________________________
404void
405AliMUONClusterFinderAZ::Used(Int_t indx, Bool_t value)
406{
407 /// Change the Used status of the pad at index indx
408 AliMUONVDigit* digit = static_cast<AliMUONVDigit*>
409 (fDigitStore->FindObject(fDigitId[indx]));
410 if (!digit)
411 {
412 AliError(Form("Did not find digit %d",fDigitId[indx]));
413 }
414 else
415 {
416 digit->Used(value);
417 }
418}
419
420//_____________________________________________________________________________
421void
422AliMUONClusterFinderAZ::PrintPixel(Int_t i) const
423{
424 /// Printout one pixel
425 AliMUONPixel* pixel = static_cast<AliMUONPixel*>(fPixArray->UncheckedAt(i));
426 if (pixel) pixel->Print();
427}
428
429//_____________________________________________________________________________
430void
431AliMUONClusterFinderAZ::PrintPad(Int_t i) const
432{
433 /// Printout one pad
434 Int_t cathode = fPadIJ[0][i];
435 UInt_t index = fDigitId[i];
436 Int_t ix = fPadIJ[2][i];
437 Int_t iy = fPadIJ[3][i];
438
439 cout << Form("i=%4d status %1d cathode %1d index %u ix %3d iy %3d (x,y)=(%7.2f,%7.2f) (dx,dy)=(%7.2f,%7.2f) Q=%7.2f",
440 i,fPadIJ[1][i],cathode,index,ix,iy,fXyq[0][i],fXyq[1][i],
441 fXyq[3][i],fXyq[4][i],
442 fXyq[2][i]) << endl;
443}
444
445//_____________________________________________________________________________
446void
447AliMUONClusterFinderAZ::Print(Option_t*) const
448{
449 /// Print current state
450 Int_t nPads = fnPads[0] + fnPads[1];
451 cout << "PreCluster npads=" << nPads << "(" << fnPads[0] << ","
452 << fnPads[1] << ")" << endl;
453 for ( Int_t i = 0; i < nPads; ++i )
454 {
455 PrintPad(i);
456 }
457}
458
0df3ca52 459//_____________________________________________________________________________
460Bool_t AliMUONClusterFinderAZ::CheckPrecluster(Int_t *nShown)
461{
d19b6003 462/// Check precluster in order to attempt to simplify it (mostly for
463/// two-cathode preclusters)
0df3ca52 464
45c72492 465// AliInfo("CheckPrecluster");
466// Print();
467
468 Int_t i1, i2, cath=0;
0df3ca52 469 Float_t xy1[4], xy12[4];
470
471 Int_t npad = fnPads[0] + fnPads[1];
2b1e4f0e 472 if (npad == 1) {
473 // Disregard one-pad clusters (leftovers from splitting)
474 nShown[0] += fnPads[0];
475 nShown[1] += fnPads[1];
476 return kFALSE;
477 }
0df3ca52 478
479 // If pads have the same size take average of pads on both cathodes
0627f609 480 //Int_t sameSize = (fnPads[0] && fnPads[1]) ? 1 : 0;
481 Int_t sameSize = 0; //AZ - 17-01-06
482
0df3ca52 483 if (sameSize) {
484 Double_t xSize = -1, ySize = 0;
485 for (Int_t i=0; i<npad; i++) {
486 if (fXyq[2][i] < 0) continue;
487 if (xSize < 0) { xSize = fXyq[3][i]; ySize = fXyq[4][i]; }
488 if (TMath::Abs(xSize-fXyq[3][i]) > 1.e-4 || TMath::Abs(ySize-fXyq[4][i]) > 1.e-4) { sameSize = 0; break; }
489 }
490 } // if (sameSize)
2b1e4f0e 491 if (sameSize && fnPads[0] == 1 && fnPads[1] == 1) sameSize = 0; //AZ
5a051e34 492 // Handle shift by half a pad in Station 1
493 if (sameSize) {
494 Int_t cath0 = fPadIJ[0][0];
495 for (Int_t i = 1; i < npad; i++) {
496 if (fPadIJ[0][i] == cath0) continue;
497 Double_t dx = TMath::Abs ((fXyq[0][i] - fXyq[0][0]) / fXyq[3][i] / 2);
498 Int_t idx = (Int_t) TMath::Abs ((fXyq[0][i] - fXyq[0][0]) / fXyq[3][i] / 2);
499 if (TMath::Abs (dx - idx) > 0.001) sameSize = 0;
500 break;
501 }
502 } // if (sameSize)
503
2b1e4f0e 504 if (sameSize && (fnPads[0] >= 2 || fnPads[1] >= 2)) {
0df3ca52 505 nShown[0] += fnPads[0];
506 nShown[1] += fnPads[1];
507 fnPads[0] = fnPads[1] = 0;
508 Int_t div;
509 for (Int_t i=0; i<npad; i++) {
510 if (fXyq[2][i] < 0) continue; // used pad
511 fXyq[2][fnPads[0]] = fXyq[2][i];
512 div = 1;
2b1e4f0e 513 cath = fPadIJ[0][i];
0df3ca52 514 for (Int_t j=i+1; j<npad; j++) {
515 if (fPadIJ[0][j] == fPadIJ[0][i]) continue; // same cathode
516 if (TMath::Abs(fXyq[0][j]-fXyq[0][i]) > 1.e-4) continue;
517 if (TMath::Abs(fXyq[1][j]-fXyq[1][i]) > 1.e-4) continue;
518 fXyq[2][fnPads[0]] += fXyq[2][j];
519 div = 2;
520 fXyq[2][j] = -2;
45c72492 521 if (cath) fDigitId[fnPads[0]] = fDigitId[j]; // save digit number for cath 0
0df3ca52 522 break;
523 }
2b1e4f0e 524 // Flag that the digit from the other cathode
45c72492 525 // LA commented if (cath && div == 1) fXyq[5][fnPads[0]] = -fXyq[5][i] - 1;
526 if (cath && div == 1) fDigitId[fnPads[0]] = fDigitId[i];
2b1e4f0e 527 // If low pad charge take the other equal to 0
0627f609 528 //if (div == 1 && fXyq[2][fnPads[0]] < fgkZeroSuppression + 1.5*3) div = 2;
0df3ca52 529 fXyq[2][fnPads[0]] /= div;
530 fXyq[0][fnPads[0]] = fXyq[0][i];
531 fXyq[1][fnPads[0]] = fXyq[1][i];
0627f609 532 fPadIJ[2][fnPads[0]] = fPadIJ[2][i];
533 fPadIJ[3][fnPads[0]] = fPadIJ[3][i];
0df3ca52 534 fPadIJ[0][fnPads[0]++] = 0;
535 }
536 } // if (sameSize)
537
538 // Check if one-cathode precluster
539 i1 = fnPads[0]!=0 ? 0 : 1;
540 i2 = fnPads[1]!=0 ? 1 : 0;
541
542 if (i1 != i2) { // two-cathode
543
544 Int_t *flags = new Int_t[npad];
545 for (Int_t i=0; i<npad; i++) { flags[i] = 0; }
546
547 // Check pad overlaps
548 for (Int_t i=0; i<npad; i++) {
549 if (fPadIJ[0][i] != i1) continue;
550 xy1[0] = fXyq[0][i] - fXyq[3][i];
551 xy1[1] = fXyq[0][i] + fXyq[3][i];
552 xy1[2] = fXyq[1][i] - fXyq[4][i];
553 xy1[3] = fXyq[1][i] + fXyq[4][i];
554 for (Int_t j=0; j<npad; j++) {
555 if (fPadIJ[0][j] != i2) continue;
556 if (!Overlap(xy1, j, xy12, 0)) continue;
557 flags[i] = flags[j] = 1; // mark overlapped pads
558 } // for (Int_t j=0;
559 } // for (Int_t i=0;
560
561 // Check if all pads overlap
2b1e4f0e 562 Int_t nFlags=0;
563 for (Int_t i=0; i<npad; i++) {
564 if (flags[i]) continue;
565 nFlags ++;
1af223d7 566 if (fDebug) cout << i << " " << fPadIJ[0][i] << " " << fXyq[0][i] << " " << fXyq[1][i] << endl;
2b1e4f0e 567 }
568 if (fDebug && nFlags) cout << " nFlags = " << nFlags << endl;
0df3ca52 569 //if (nFlags > 2 || (Float_t)nFlags / npad > 0.2) { // why 2 ??? - empirical choice
0627f609 570 if (nFlags > 0) {
0df3ca52 571 for (Int_t i=0; i<npad; i++) {
45c72492 572 if (flags[i]) continue;
573 cath = fPadIJ[0][i];
574 // Check for edge effect (missing pads on the other cathode)
575 Int_t cath1 = TMath::Even(cath), ix, iy;
576 ix = iy = 0;
577 AliMpPad pad = fSegmentation[cath1]->PadByPosition(TVector2(fXyq[0][i], fXyq[1][i]));
578 if (!pad.IsValid()) continue;
579 if (nFlags == 1 && fXyq[2][i] < fgkZeroSuppression * 3) continue;
580 Used(i,kFALSE);
581 fXyq[2][i] = -2;
582 fnPads[cath]--;
0df3ca52 583 }
45c72492 584 // if (fDraw) fDraw->UpdateCluster(npad);
0df3ca52 585 } // if (nFlags > 2)
45c72492 586
0df3ca52 587 // Check correlations of cathode charges
588 if (fnPads[0] && fnPads[1]) { // two-cathode
589 Double_t sum[2]={0};
590 Int_t over[2] = {1, 1};
591 for (Int_t i=0; i<npad; i++) {
592 cath = fPadIJ[0][i];
593 if (fXyq[2][i] > 0) sum[cath] += fXyq[2][i];
0627f609 594 if (fXyq[2][i] > fgkSaturation-1) over[cath] = 0;
0df3ca52 595 }
2b1e4f0e 596 if (fDebug) cout << " Total charge: " << sum[0] << " " << sum[1] << endl;
0df3ca52 597 if ((over[0] || over[1]) && TMath::Abs(sum[0]-sum[1])/(sum[0]+sum[1])*2 > 1) { // 3 times difference
2b1e4f0e 598 if (fDebug) cout << " Release " << endl;
0df3ca52 599 // Big difference
cc87ebcd 600 cath = sum[0] > sum[1] ? 0 : 1;
601 Int_t imax = 0, imin = 0;
602 Double_t cmax = -1, cmin = 9999, dxMin = 0, dyMin = 0;
0df3ca52 603 Double_t *dist = new Double_t[npad];
cc87ebcd 604 for (Int_t i = 0; i < npad; i++) {
605 if (fPadIJ[0][i] != cath || fXyq[2][i] < 0) continue;
606 if (fXyq[2][i] < cmin) {
607 cmin = fXyq[2][i];
608 imin = i;
609 }
0df3ca52 610 if (fXyq[2][i] < cmax) continue;
611 cmax = fXyq[2][i];
612 imax = i;
613 }
614 // Arrange pads according to their distance to the max,
615 // normalized to the pad size
cc87ebcd 616 for (Int_t i = 0; i < npad; i++) {
0df3ca52 617 dist[i] = 0;
cc87ebcd 618 if (fPadIJ[0][i] != cath || fXyq[2][i] < 0) continue;
0df3ca52 619 if (i == imax) continue;
cc87ebcd 620 Double_t dx = (fXyq[0][i] - fXyq[0][imax]) / fXyq[3][imax] / 2;
621 Double_t dy = (fXyq[1][i] - fXyq[1][imax]) / fXyq[4][imax] / 2;
622 dist[i] = TMath::Sqrt (dx * dx + dy * dy);
623 if (i == imin) {
e8fb921b 624 cmin = dist[i] + 0.001; // distance to the pad with minimum charge
cc87ebcd 625 dxMin = dx;
626 dyMin = dy;
627 }
0df3ca52 628 }
629 TMath::Sort(npad, dist, flags, kFALSE); // in increasing order
630 Int_t indx;
631 Double_t xmax = -1;
cc87ebcd 632 for (Int_t i = 0; i < npad; i++) {
0df3ca52 633 indx = flags[i];
cc87ebcd 634 if (fPadIJ[0][indx] != cath || fXyq[2][indx] < 0) continue;
635 if (dist[indx] > cmin) {
636 // Farther than the minimum pad
637 Double_t dx = (fXyq[0][indx] - fXyq[0][imax]) / fXyq[3][imax] / 2;
638 Double_t dy = (fXyq[1][indx] - fXyq[1][imax]) / fXyq[4][imax] / 2;
639 dx *= dxMin;
640 dy *= dyMin;
641 if (dx >= 0 && dy >= 0) continue;
642 if (TMath::Abs(dx) > TMath::Abs(dy) && dx >= 0) continue;
643 if (TMath::Abs(dy) > TMath::Abs(dx) && dy >= 0) continue;
644 }
645 if (fXyq[2][indx] <= cmax || TMath::Abs(dist[indx]-xmax) < 1.e-3) {
0df3ca52 646 // Release pads
cc87ebcd 647 if (TMath::Abs(dist[indx]-xmax) < 1.e-3)
cd747ddb 648 cmax = TMath::Max((Double_t)(fXyq[2][indx]),cmax);
0df3ca52 649 else cmax = fXyq[2][indx];
650 xmax = dist[indx];
45c72492 651 Used(indx,kFALSE);
0df3ca52 652 fXyq[2][indx] = -2;
653 fnPads[cath]--;
cc87ebcd 654 }
655 } // for (Int_t i = 0; i < npad;
656
657 // Check pad overlaps once more
658 for (Int_t j = 0; j < npad; j++) flags[j] = 0;
659 for (Int_t k = 0; k < npad; k++) {
660 if (fXyq[2][k] < 0 || fPadIJ[0][k] != i1) continue;
661 xy1[0] = fXyq[0][k] - fXyq[3][k];
662 xy1[1] = fXyq[0][k] + fXyq[3][k];
663 xy1[2] = fXyq[1][k] - fXyq[4][k];
664 xy1[3] = fXyq[1][k] + fXyq[4][k];
665 for (Int_t j = 0; j < npad; j++) {
666 if (fXyq[2][j] < 0) continue;
667 if (fPadIJ[0][j] != i2) continue;
668 if (!Overlap(xy1, j, xy12, 0)) continue;
669 flags[k] = flags[j] = 1; // mark overlapped pads
670 } // for (Int_t j = 0;
671 } // for (Int_t k = 0;
672 nFlags = 0;
673 for (Int_t j = 0; j < npad; j++) {
674 if (fXyq[2][j] < 0 || flags[j]) continue;
675 nFlags ++;
676 }
677 if (nFlags == fnPads[0] + fnPads[1]) {
678 // No overlap
679 for (Int_t j = 0; j < npad; j++) {
680 if (fXyq[2][j] < 0 || fPadIJ[0][j] != cath) continue;
681 fXyq[2][j] = -2;
682 fnPads[cath]--;
0df3ca52 683 }
cc87ebcd 684 }
0df3ca52 685 delete [] dist; dist = 0;
45c72492 686// if (fDraw) fDraw->UpdateCluster(npad);
0df3ca52 687 } // TMath::Abs(sum[0]-sum[1])...
688 } // if (fnPads[0] && fnPads[1])
689 delete [] flags; flags = 0;
690 } // if (i1 != i2)
691
692 if (!sameSize) { nShown[0] += fnPads[0]; nShown[1] += fnPads[1]; }
693
694 // Move released pads to the right
695 Int_t beg = 0, end = npad-1, padij;
696 Double_t xyq;
697 while (beg < end) {
698 if (fXyq[2][beg] > 0) { beg++; continue; }
699 for (Int_t j=end; j>beg; j--) {
700 if (fXyq[2][j] < 0) continue;
701 end = j - 1;
0627f609 702 for (Int_t j1=0; j1<4; j1++) {
0df3ca52 703 padij = fPadIJ[j1][beg];
704 fPadIJ[j1][beg] = fPadIJ[j1][j];
705 fPadIJ[j1][j] = padij;
706 }
707 for (Int_t j1=0; j1<6; j1++) {
708 xyq = fXyq[j1][beg];
709 fXyq[j1][beg] = fXyq[j1][j];
710 fXyq[j1][j] = xyq;
711 }
712 break;
713 } // for (Int_t j=end;
714 beg++;
715 } // while
716 npad = fnPads[0] + fnPads[1];
94eb555e 717 if (npad > 500) {
718 AliWarning(Form(" *** Too large cluster. Give up. %d ", npad));
719 return kFALSE;
720 }
0df3ca52 721 // Back up charge value
1af223d7 722 for (Int_t j = 0; j < npad; j++) fXyq[6][j] = fXyq[2][j];
0df3ca52 723
724 return kTRUE;
725}
726
727//_____________________________________________________________________________
728void AliMUONClusterFinderAZ::BuildPixArray()
729{
d19b6003 730/// Build pixel array for MLEM method
0df3ca52 731
732 Int_t nPix=0, i1, i2;
733 Float_t xy1[4], xy12[4];
734 AliMUONPixel *pixPtr=0;
735
736 Int_t npad = fnPads[0] + fnPads[1];
737
738 // One cathode is empty
739 i1 = fnPads[0]!=0 ? 0 : 1;
740 i2 = fnPads[1]!=0 ? 1 : 0;
741
742 // Build array of pixels on anode plane
743 if (i1 == i2) { // one-cathode precluster
744 for (Int_t j=0; j<npad; j++) {
745 pixPtr = new AliMUONPixel();
746 for (Int_t i=0; i<2; i++) {
747 pixPtr->SetCoord(i, fXyq[i][j]); // pixel coordinates
748 pixPtr->SetSize(i, fXyq[i+3][j]); // pixel size
749 }
750 pixPtr->SetCharge(fXyq[2][j]); // charge
751 fPixArray->Add((TObject*)pixPtr);
752 nPix++;
753 }
754 } else { // two-cathode precluster
5a051e34 755 i1 = fPadIJ[0][0];
756 i2 = TMath::Even (i1);
757 for (Int_t i = 0; i < npad; i++) {
0df3ca52 758 if (fPadIJ[0][i] != i1) continue;
759 xy1[0] = fXyq[0][i] - fXyq[3][i];
760 xy1[1] = fXyq[0][i] + fXyq[3][i];
761 xy1[2] = fXyq[1][i] - fXyq[4][i];
762 xy1[3] = fXyq[1][i] + fXyq[4][i];
5a051e34 763 for (Int_t j = 1; j < npad; j++) {
0df3ca52 764 if (fPadIJ[0][j] != i2) continue;
765 if (!Overlap(xy1, j, xy12, 1)) continue;
766 pixPtr = new AliMUONPixel();
767 for (Int_t k=0; k<2; k++) {
768 pixPtr->SetCoord(k, (xy12[2*k]+xy12[2*k+1])/2); // pixel coordinates
769 pixPtr->SetSize(k, xy12[2*k+1]-pixPtr->Coord(k)); // size
770 }
771 pixPtr->SetCharge(TMath::Min (fXyq[2][i],fXyq[2][j])); //charge
772 fPixArray->Add((TObject*)pixPtr);
2b1e4f0e 773 //cout << nPix << " " << pixPtr->Coord(0) << " " << pixPtr->Size(0) << " " << pixPtr->Coord(1) << " " << pixPtr->Size(1) << " " << pixPtr->Charge() << endl;
0df3ca52 774 nPix++;
775 } // for (Int_t j=0;
776 } // for (Int_t i=0;
777 } // else
778
5a051e34 779 Float_t xPadMin = 999, yPadMin = 999;
780 for (Int_t i = 0; i < npad; i++) {
781 xPadMin = TMath::Min (xPadMin, fXyq[3][i]);
782 yPadMin = TMath::Min (yPadMin, fXyq[4][i]);
783 }
784 if (fDebug) cout << xPadMin << " " << yPadMin << endl;
785
786 Float_t wxmin = 999, wymin = 999;
787 for (Int_t i = 0; i < nPix; i++) {
788 pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i);
789 wxmin = TMath::Min ((Double_t)wxmin, pixPtr->Size(0));
790 wymin = TMath::Min ((Double_t)wymin, pixPtr->Size(1));
0df3ca52 791 }
2b1e4f0e 792 if (fDebug) cout << wxmin << " " << wymin << endl;
5a051e34 793 wxmin = TMath::Abs (wxmin - xPadMin/2) > 0.001 ? xPadMin : xPadMin / 2;
794 wymin = TMath::Abs (wymin - yPadMin/2) > 0.001 ? yPadMin : yPadMin / 2;
795 //wxmin = xPadMin; wymin = yPadMin;
0df3ca52 796
797 // Check if small pixel X-size
2b1e4f0e 798 AdjustPixel(wxmin, 0);
0df3ca52 799 // Check if small pixel Y-size
2b1e4f0e 800 AdjustPixel(wymin, 1);
0df3ca52 801 // Check if large pixel size
2b1e4f0e 802 AdjustPixel(wxmin, wymin);
0df3ca52 803
804 // Remove discarded pixels
805 for (Int_t i=0; i<nPix; i++) {
806 pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i);
807 //pixPtr->Print();
808 if (pixPtr->Charge() < 1) { fPixArray->RemoveAt(i); delete pixPtr; }// discarded pixel
809 }
810 fPixArray->Compress();
811 nPix = fPixArray->GetEntriesFast();
812
813 if (nPix > npad) {
2b1e4f0e 814 if (fDebug) cout << nPix << endl;
0df3ca52 815 // Too many pixels - sort and remove pixels with the lowest signal
816 fPixArray->Sort();
817 for (Int_t i=npad; i<nPix; i++) {
818 pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i);
819 //pixPtr->Print();
820 fPixArray->RemoveAt(i);
821 delete pixPtr;
822 }
823 nPix = npad;
824 } // if (nPix > npad)
825
826 // Set pixel charges to the same value (for MLEM)
827 for (Int_t i=0; i<nPix; i++) {
828 pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i);
829 //pixPtr->SetCharge(10);
2b1e4f0e 830 if (fDebug) cout << i+1 << " " << pixPtr->Coord(0) << " " << pixPtr->Coord(1) << " " << pixPtr->Size(0) << " " << pixPtr->Size(1) << endl;
0df3ca52 831 }
832}
833
834//_____________________________________________________________________________
2b1e4f0e 835void AliMUONClusterFinderAZ::AdjustPixel(Float_t width, Int_t ixy)
0df3ca52 836{
d19b6003 837/// Check if some pixels have small size (adjust if necessary)
0df3ca52 838
839 AliMUONPixel *pixPtr, *pixPtr1 = 0;
840 Int_t ixy1 = TMath::Even(ixy);
841 Int_t nPix = fPixArray->GetEntriesFast();
842
843 for (Int_t i=0; i<nPix; i++) {
844 pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i);
845 if (pixPtr->Charge() < 1) continue; // discarded pixel
846 if (pixPtr->Size(ixy)-width < -1.e-4) {
847 // try to merge
2b1e4f0e 848 if (fDebug) cout << i << " Small X or Y: " << ixy << " " << pixPtr->Size(ixy) << " " << width << " " << pixPtr->Coord(0) << " " << pixPtr->Coord(1) << endl;
0df3ca52 849 for (Int_t j=i+1; j<nPix; j++) {
850 pixPtr1 = (AliMUONPixel*) fPixArray->UncheckedAt(j);
851 if (pixPtr1->Charge() < 1) continue; // discarded pixel
852 if (TMath::Abs(pixPtr1->Size(ixy)-width) < 1.e-4) continue; // right size
853 if (TMath::Abs(pixPtr1->Coord(ixy1)-pixPtr->Coord(ixy1)) > 1.e-4) continue; // different rows/columns
854 if (TMath::Abs(pixPtr1->Coord(ixy)-pixPtr->Coord(ixy)) < 2*width) {
855 // merge
2b1e4f0e 856 Double_t tmp = pixPtr->Coord(ixy) + pixPtr1->Size(ixy) *
857 TMath::Sign (1., pixPtr1->Coord(ixy) - pixPtr->Coord(ixy));
858 pixPtr->SetCoord(ixy, tmp);
0df3ca52 859 pixPtr->SetSize(ixy, width);
0df3ca52 860 pixPtr->SetCharge(TMath::Min (pixPtr->Charge(),pixPtr1->Charge()));
861 pixPtr1->SetCharge(0);
862 pixPtr1 = 0;
863 break;
864 }
865 } // for (Int_t j=i+1;
866 //if (!pixPtr1) { cout << " I am here!" << endl; pixPtr->SetSize(ixy, width); } // ???
867 //else if (pixPtr1->Charge() > 0.5 || i == nPix-1) {
868 if (pixPtr1 || i == nPix-1) {
869 // edge pixel - just increase its size
2b1e4f0e 870 if (fDebug) cout << " Edge ..." << endl;
0df3ca52 871 for (Int_t j=0; j<fnPads[0]+fnPads[1]; j++) {
2b1e4f0e 872 //if (fPadIJ[0][j] != ixy1) continue;
5a051e34 873 //???-check if (TMath::Abs(pixPtr->Coord(ixy1)-fXyq[ixy1][j]) > 1.e-4) continue;
0df3ca52 874 if (pixPtr->Coord(ixy) < fXyq[ixy][j])
2b1e4f0e 875 //pixPtr->Shift(ixy, -pixPtr->Size(ixy));
876 pixPtr->Shift(ixy, pixPtr->Size(ixy)-width);
877 //else pixPtr->Shift(ixy, pixPtr->Size(ixy));
878 else pixPtr->Shift(ixy, -pixPtr->Size(ixy)+width);
0df3ca52 879 pixPtr->SetSize(ixy, width);
880 break;
881 }
882 }
883 } // if (pixPtr->Size(ixy)-width < -1.e-4)
884 } // for (Int_t i=0; i<nPix;
885 return;
886}
887
888//_____________________________________________________________________________
2b1e4f0e 889void AliMUONClusterFinderAZ::AdjustPixel(Float_t wxmin, Float_t wymin)
0df3ca52 890{
d19b6003 891/// Check if some pixels have large size (adjust if necessary)
0df3ca52 892
cc87ebcd 893 Int_t n1[2], n2[2], iOK = 1, nPix = fPixArray->GetEntriesFast();
894 AliMUONPixel *pixPtr, pix;
af82d8d2 895 Double_t xy0[2] = {9999, 9999}, wxy[2], dist[2] = {0};
0df3ca52 896
897 // Check if large pixel size
cc87ebcd 898 for (Int_t i = 0; i < nPix; i++) {
0df3ca52 899 pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i);
900 if (pixPtr->Charge() < 1) continue; // discarded pixel
cc87ebcd 901 if (pixPtr->Size(0) - wxmin < 1.e-4) {
902 if (xy0[0] > 9998) xy0[0] = pixPtr->Coord(0); // position of a "normal" pixel
903 if (pixPtr->Size(1) - wymin < 1.e-4) {
904 if (xy0[1] > 9998) xy0[1] = pixPtr->Coord(1); // position of a "normal" pixel
905 continue;
906 } else iOK = 0; // large pixel
907 } else {
908 iOK = 0; // large pixel
909 if (xy0[1] > 9998 && pixPtr->Size(1) - wymin < 1.e-4) xy0[1] = pixPtr->Coord(1); // "normal" pixel
910 }
911 if (xy0[0] < 9998 && xy0[1] < 9998) break;
912 }
913 if (iOK) return;
914
915 wxy[0] = wxmin;
916 wxy[1] = wymin;
917 //cout << xy0[0] << " " << xy0[1] << endl;
918 for (Int_t i = 0; i < nPix; i++) {
919 pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i);
920 if (pixPtr->Charge() < 1) continue; // discarded pixel
921 n1[0] = n1[1] = 999;
922 n2[0] = n2[1] = 1;
923 for (Int_t j = 0; j < 2; j++) {
924 if (pixPtr->Size(j) - wxy[j] < 1.e-4) continue;
925 dist[j] = (pixPtr->Coord(j) - xy0[j]) / wxy[j] / 2; // normalized distance to "normal" pixel
926 n2[j] = TMath::Nint (pixPtr->Size(j) / wxy[j]);
927 n1[j] = n2[j] == 1 ? TMath::Nint(dist[j]) : (Int_t)dist[j];
928 }
929 if (n1[0] > 998 && n1[1] > 998) continue;
930 if (fDebug) cout << " Different " << pixPtr->Size(0) << " " << wxy[0] << " "
931 << pixPtr->Size(1) << " " << wxy[1] <<endl;
932
0627f609 933 if (n2[0] > 2 || n2[1] > 2) {
94eb555e 934 //cout << n2[0] << " " << n2[1] << endl;
0627f609 935 if (n2[0] > 2 && n1[0] < 999) n1[0]--;
936 if (n2[1] > 2 && n1[1] < 999) n1[1]--;
937 }
cc87ebcd 938 //cout << n1[0] << " " << n2[0] << " " << n1[1] << " " << n2[1] << endl;
939 pix = *pixPtr;
940 pix.SetSize(0, wxy[0]); pix.SetSize(1, wxy[1]);
941 //pixPtr->Print();
942 for (Int_t ii = 0; ii < n2[0]; ii++) {
943 if (n1[0] < 999) pix.SetCoord(0, xy0[0] + (n1[0] + TMath::Sign(1.,dist[0]) * ii) * 2 * wxy[0]);
944 for (Int_t jj = 0; jj < n2[1]; jj++) {
945 if (n1[1] < 999) pix.SetCoord(1, xy0[1] + (n1[1] + TMath::Sign(1.,dist[1]) * jj) * 2 * wxy[1]);
946 fPixArray->Add(new AliMUONPixel(pix));
947 //pix.Print();
0df3ca52 948 }
0df3ca52 949 }
cc87ebcd 950 pixPtr->SetCharge(0);
951 } // for (Int_t i = 0; i < nPix;
0df3ca52 952}
953
45c72492 954//_____________________________________________________________________________
955Float_t
956AliMUONClusterFinderAZ::ChargeIntegration(Double_t x, Double_t y,
957 Double_t padX, Double_t padY,
958 Double_t padDX, Double_t padDY)
959{
960 /// Compute the Mathieson integral on pad area, assuming the center
961 /// of the Mathieson is at (x,y)
962
963 Double_t llx = x - padX - padDX;
964 Double_t lly = y - padY - padDY;
965 Double_t urx = llx + 2.0*padDX;
966 Double_t ury = lly + 2.0*padDY;
967
968 return fMathieson->IntXY(llx,lly,urx,ury);
969}
970
0df3ca52 971//_____________________________________________________________________________
2b1e4f0e 972Bool_t AliMUONClusterFinderAZ::MainLoop(Int_t iSimple)
0df3ca52 973{
d19b6003 974/// Repeat MLEM algorithm until pixel size becomes sufficiently small
0df3ca52 975
976 TH2D *mlem;
977
978 Int_t ix, iy;
979 //Int_t nn, xList[10], yList[10];
980 Int_t nPix = fPixArray->GetEntriesFast();
0df3ca52 981 AliMUONPixel *pixPtr = 0;
982 Double_t *coef = 0, *probi = 0;
2b1e4f0e 983 AddVirtualPad(); // add virtual pads if necessary
984 Int_t npadTot = fnPads[0] + fnPads[1], npadOK = 0;
1af223d7 985 for (Int_t i = 0; i < npadTot; i++) if (fPadIJ[1][i] == 0) npadOK++;
45c72492 986// if (fDraw) fDraw->ResetMuon();
0df3ca52 987
988 while (1) {
989
990 mlem = (TH2D*) gROOT->FindObject("mlem");
991 if (mlem) mlem->Delete();
992 // Calculate coefficients
2b1e4f0e 993 if (fDebug) cout << " nPix, npadTot, npadOK " << nPix << " " << npadTot << " " << npadOK << endl;
0df3ca52 994
995 // Calculate coefficients and pixel visibilities
996 coef = new Double_t [npadTot*nPix];
997 probi = new Double_t [nPix];
2b1e4f0e 998 for (Int_t ipix=0; ipix<nPix; ipix++) probi[ipix] = 0;
45c72492 999 Int_t indx = 0, indx1 = 0;
2b1e4f0e 1000
45c72492 1001 for (Int_t j=0; j<npadTot; j++)
1002 {
2b1e4f0e 1003 indx = j*nPix;
45c72492 1004
1005// if (fPadIJ[1][j] == 0)
1006// {
1007// cath = fPadIJ[0][j];
1008// ix = fPadIJ[2][j];
1009// iy = fPadIJ[3][j];
1010// fSegmentation[cath]->SetPad(ix, iy);
1011// }
1012
1013 for (Int_t ipix=0; ipix<nPix; ipix++)
1014 {
1015 indx1 = indx + ipix;
1016 if (fPadIJ[1][j] < 0) { coef[indx1] = 0; continue; }
1017 pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(ipix);
1018
1019 Float_t q = ChargeIntegration(pixPtr->Coord(0),pixPtr->Coord(1),
1020 fXyq[0][j],fXyq[1][j],
aacf0960 1021 TMath::Abs(fXyq[3][j]),fXyq[4][j]);
45c72492 1022
1023// AliInfo(Form("pad %d pixel %d",j,ipix));
1024// PrintPad(j);
1025// PrintPixel(ipix);
1026
1027 coef[indx1] = q;
1028 probi[ipix] += coef[indx1];
1029
1030// AliInfo(Form("indx1=%d q=%e",indx1,q));
1031
2b1e4f0e 1032 } // for (Int_t ipix=0;
1033 } // for (Int_t j=0;
45c72492 1034
2b1e4f0e 1035 for (Int_t ipix=0; ipix<nPix; ipix++) if (probi[ipix] < 0.01) pixPtr->SetCharge(0); // "invisible" pixel
0df3ca52 1036
1037 // MLEM algorithm
2b1e4f0e 1038 Mlem(coef, probi, 15);
0df3ca52 1039
cd747ddb 1040 Double_t xylim[4] = {999, 999, 999, 999};
0df3ca52 1041 for (Int_t ipix=0; ipix<nPix; ipix++) {
1042 pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(ipix);
cc87ebcd 1043 //cout << ipix+1; pixPtr->Print();
0df3ca52 1044 for (Int_t i=0; i<4; i++)
45c72492 1045 xylim[i] = TMath::Min (xylim[i], (i%2 ? -1 : 1)*pixPtr->Coord(i/2));
0df3ca52 1046 }
1047 for (Int_t i=0; i<4; i++) {
2b1e4f0e 1048 xylim[i] -= pixPtr->Size(i/2); if (fDebug) cout << (i%2 ? -1 : 1)*xylim[i] << " "; }
1049 if (fDebug) cout << endl;
0df3ca52 1050
2b1e4f0e 1051 // Adjust histogram to approximately the same limits as for the pads
0df3ca52 1052 // (for good presentation)
45c72492 1053// if (fDraw) fDraw->AdjustHist(xylim, pixPtr);
1af223d7 1054
0df3ca52 1055 Int_t nx = TMath::Nint ((-xylim[1]-xylim[0])/pixPtr->Size(0)/2);
1056 Int_t ny = TMath::Nint ((-xylim[3]-xylim[2])/pixPtr->Size(1)/2);
2b1e4f0e 1057
0df3ca52 1058 mlem = new TH2D("mlem","mlem",nx,xylim[0],-xylim[1],ny,xylim[2],-xylim[3]);
1059 for (Int_t ipix=0; ipix<nPix; ipix++) {
1060 pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(ipix);
1061 mlem->Fill(pixPtr->Coord(0),pixPtr->Coord(1),pixPtr->Charge());
1062 }
45c72492 1063// if (fDraw) fDraw->DrawHist("c2", mlem);
0df3ca52 1064
1065 // Check if the total charge of pixels is too low
1066 Double_t qTot = 0;
1067 for (Int_t i=0; i<nPix; i++) {
1068 pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i);
1069 qTot += pixPtr->Charge();
1070 }
2b1e4f0e 1071 if (qTot < 1.e-4 || npadOK < 3 && qTot < 7) {
0df3ca52 1072 delete [] coef; delete [] probi; coef = 0; probi = 0;
1073 fPixArray->Delete();
2b1e4f0e 1074 for (Int_t i=0; i<npadTot; i++) if (fPadIJ[1][i] == 0) fPadIJ[1][i] = -1;
0df3ca52 1075 return kFALSE;
1076 }
1077
1078 // Plot data - expectation
1079 /*
1080 Double_t x, y, cont;
1081 for (Int_t j=0; j<npadTot; j++) {
1082 Double_t sum1 = 0;
1083 for (Int_t i=0; i<nPix; i++) {
1084 // Caculate expectation
1085 pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i);
1086 sum1 += pixPtr->Charge()*coef[j*nPix+i];
1087 }
0627f609 1088 sum1 = TMath::Min (sum1,fgkSaturation);
0df3ca52 1089 x = fXyq[0][j];
1090 y = fXyq[1][j];
1091 cath = fPadIJ[0][j];
1092 Int_t ihist = cath*2;
1093 ix = fHist[ihist]->GetXaxis()->FindBin(x);
1094 iy = fHist[ihist]->GetYaxis()->FindBin(y);
1095 cont = fHist[ihist]->GetCellContent(ix,iy);
1096 if (cont == 0 && fHist[ihist+1]) {
1097 ihist += 1;
1098 ix = fHist[ihist]->GetXaxis()->FindBin(x);
1099 iy = fHist[ihist]->GetYaxis()->FindBin(y);
1100 }
1101 fHist[ihist]->SetBinContent(ix,iy,fXyq[2][j]-sum1);
1102 }
1103 ((TCanvas*)gROOT->FindObject("c1"))->cd(1);
1104 //gPad->SetTheta(55);
1105 //gPad->SetPhi(30);
1106 //mlem->Draw("lego1");
1107 gPad->Modified();
1108 ((TCanvas*)gROOT->FindObject("c1"))->cd(2);
1109 gPad->Modified();
1110 */
1111
2b1e4f0e 1112 if (iSimple) {
1113 // Simple cluster - skip further passes thru EM-procedure
2b1e4f0e 1114 Simple();
1115 delete [] coef; delete [] probi; coef = 0; probi = 0;
1116 fPixArray->Delete();
1117 return kTRUE;
1118 }
1119
0df3ca52 1120 // Calculate position of the center-of-gravity around the maximum pixel
1121 Double_t xyCOG[2];
1122 FindCOG(mlem, xyCOG);
1123
1124 if (TMath::Min(pixPtr->Size(0),pixPtr->Size(1)) < 0.07 && pixPtr->Size(0) > pixPtr->Size(1)) break;
2b1e4f0e 1125 //if (TMath::Min(pixPtr->Size(0),pixPtr->Size(1)) < 0.007 && pixPtr->Size(0) > pixPtr->Size(1)) break;
0df3ca52 1126 //if (TMath::Min(pixPtr->Size(0),pixPtr->Size(1)) >= 0.07 || pixPtr->Size(0) < pixPtr->Size(1)) {
1127 // Sort pixels according to the charge
1128 fPixArray->Sort();
1129 /*
1130 for (Int_t i=0; i<nPix; i++) {
1131 pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i);
1132 cout << i+1; pixPtr->Print();
1133 }
1134 */
1135 Double_t pixMin = 0.01*((AliMUONPixel*)fPixArray->UncheckedAt(0))->Charge();
1136 pixMin = TMath::Min (pixMin,50.);
1137
1138 // Decrease pixel size and shift pixels to make them centered at
1139 // the maximum one
1140 indx = (pixPtr->Size(0)>pixPtr->Size(1)) ? 0 : 1;
1141 Double_t width = 0, shift[2]={0};
1142 ix = 1;
1143 for (Int_t i=0; i<4; i++) xylim[i] = 999;
1144 Int_t nPix1 = nPix; nPix = 0;
1145 for (Int_t ipix=0; ipix<nPix1; ipix++) {
1146 pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(ipix);
1147 if (nPix >= npadOK) { // too many pixels already
1148 fPixArray->RemoveAt(ipix);
1149 delete pixPtr;
1150 continue;
1151 }
1152 if (pixPtr->Charge() < pixMin) { // low charge
1153 fPixArray->RemoveAt(ipix);
1154 delete pixPtr;
1155 continue;
1156 }
1157 for (Int_t i=0; i<2; i++) {
1158 if (!i) {
1159 pixPtr->SetCharge(10);
1160 pixPtr->SetSize(indx, pixPtr->Size(indx)/2);
1161 width = -pixPtr->Size(indx);
1162 pixPtr->Shift(indx, width);
1163 // Shift pixel position
1164 if (ix) {
1165 ix = 0;
1166 for (Int_t j=0; j<2; j++) {
1167 shift[j] = pixPtr->Coord(j) - xyCOG[j];
1168 shift[j] -= ((Int_t)(shift[j]/pixPtr->Size(j)/2))*pixPtr->Size(j)*2;
1169 }
1170 //cout << ipix << " " << i << " " << shift[0] << " " << shift[1] << endl;
1171 } // if (ix)
1172 pixPtr->Shift(0, -shift[0]);
1173 pixPtr->Shift(1, -shift[1]);
1174 } else {
1175 pixPtr = new AliMUONPixel(*pixPtr);
1176 pixPtr->Shift(indx, -2*width);
1177 fPixArray->Add((TObject*)pixPtr);
1178 } // else
1179 //pixPtr->Print();
1180 for (Int_t i=0; i<4; i++)
1181 xylim[i] = TMath::Min (xylim[i], (i%2 ? -1 : 1)*pixPtr->Coord(i/2));
1182 } // for (Int_t i=0; i<2;
1183 nPix += 2;
1184 } // for (Int_t ipix=0;
1185
1186 fPixArray->Compress();
1187 nPix = fPixArray->GetEntriesFast();
1188
1189 // Remove excessive pixels
1190 if (nPix > npadOK) {
1191 for (Int_t ipix=npadOK; ipix<nPix; ipix++) {
1192 pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(ipix);
1193 fPixArray->RemoveAt(ipix);
1194 delete pixPtr;
1195 }
1196 } else {
1197 pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(0);
1198 // add pixels if the maximum is at the limit of pixel area
1199 // start from Y-direction
1200 Int_t j = 0;
1201 for (Int_t i=3; i>-1; i--) {
1202 if (nPix < npadOK &&
1203 TMath::Abs((i%2 ? -1 : 1)*xylim[i]-xyCOG[i/2]) < pixPtr->Size(i/2)) {
1204 pixPtr = new AliMUONPixel(*pixPtr);
1205 pixPtr->SetCoord(i/2, xyCOG[i/2]+(i%2 ? 2:-2)*pixPtr->Size(i/2));
1206 j = TMath::Even (i/2);
1207 pixPtr->SetCoord(j, xyCOG[j]);
1208 fPixArray->Add((TObject*)pixPtr);
1209 nPix++;
1210 }
1211 }
1212 } // else
1213
1214 fPixArray->Compress();
1215 nPix = fPixArray->GetEntriesFast();
1216 delete [] coef; delete [] probi; coef = 0; probi = 0;
1217 } // while (1)
1218
1219 // remove pixels with low signal or low visibility
1220 // Cuts are empirical !!!
1221 Double_t thresh = TMath::Max (mlem->GetMaximum()/100.,1.);
1222 thresh = TMath::Min (thresh,50.);
1223 Double_t cmax = -1, charge = 0;
1224 for (Int_t i=0; i<nPix; i++) cmax = TMath::Max (cmax,probi[i]);
2b1e4f0e 1225 //cout << thresh << " " << cmax << " " << cmax*0.9 << endl;
0df3ca52 1226 // Mark pixels which should be removed
1227 for (Int_t i=0; i<nPix; i++) {
1228 pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i);
1229 charge = pixPtr->Charge();
1230 if (charge < thresh) pixPtr->SetCharge(-charge);
2b1e4f0e 1231 //else if (cmax > 1.91) {
1232 // if (probi[i] < 1.9) pixPtr->SetCharge(-charge);
1233 //}
1234 //AZ else if (probi[i] < cmax*0.9) pixPtr->SetCharge(-charge);
0627f609 1235 //18-01-06 else if (probi[i] < cmax*0.8) pixPtr->SetCharge(-charge);
2b1e4f0e 1236 //cout << i << " " << pixPtr->Coord(0) << " " << pixPtr->Coord(1) << " " << charge << " " << probi[i] << endl;
0df3ca52 1237 }
1238 // Move charge of removed pixels to their nearest neighbour (to keep total charge the same)
1239 Int_t near = 0;
1240 for (Int_t i=0; i<nPix; i++) {
1241 pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i);
1242 charge = pixPtr->Charge();
1243 if (charge > 0) continue;
1244 near = FindNearest(pixPtr);
1245 pixPtr->SetCharge(0);
2b1e4f0e 1246 probi[i] = 0; // make it "invisible"
0df3ca52 1247 pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(near);
2b1e4f0e 1248 pixPtr->SetCharge(pixPtr->Charge() + (-charge));
0df3ca52 1249 }
2b1e4f0e 1250 Mlem(coef,probi,2);
0df3ca52 1251 // Update histogram
1252 for (Int_t i=0; i<nPix; i++) {
1253 pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i);
1254 ix = mlem->GetXaxis()->FindBin(pixPtr->Coord(0));
1255 iy = mlem->GetYaxis()->FindBin(pixPtr->Coord(1));
1256 mlem->SetBinContent(ix, iy, pixPtr->Charge());
1257 }
45c72492 1258// if (fDraw) fDraw->DrawHist("c2", mlem);
0df3ca52 1259
0df3ca52 1260 // Try to split into clusters
1261 Bool_t ok = kTRUE;
1262 if (mlem->GetSum() < 1) ok = kFALSE;
1263 else Split(mlem, coef);
1264 delete [] coef; delete [] probi; coef = 0; probi = 0;
1265 fPixArray->Delete();
1266 return ok;
1267}
1268
1269//_____________________________________________________________________________
2b1e4f0e 1270void AliMUONClusterFinderAZ::Mlem(Double_t *coef, Double_t *probi, Int_t nIter)
0df3ca52 1271{
d19b6003 1272/// Use MLEM to find pixel charges
0df3ca52 1273
1274 Int_t nPix = fPixArray->GetEntriesFast();
1275 Int_t npad = fnPads[0] + fnPads[1];
1276 Double_t *probi1 = new Double_t [nPix];
aacf0960 1277 Double_t *chargeNew = new Double_t [nPix];
2b1e4f0e 1278 Double_t probMax = 0;
0df3ca52 1279 Int_t indx, indx1;
1280 AliMUONPixel *pixPtr;
1281
aacf0960 1282 for (Int_t ipix=0; ipix<nPix; ++ipix) {
1283 if (probi[ipix] > probMax) probMax = probi[ipix];
1284 chargeNew[ipix] = 0;
1285 }
1286
2b1e4f0e 1287 for (Int_t iter=0; iter<nIter; iter++) {
0df3ca52 1288 // Do iterations
1289 for (Int_t ipix=0; ipix<nPix; ipix++) {
1290 // Correct each pixel
1291 if (probi[ipix] < 0.01) continue; // skip "invisible" pixel
1292 Double_t sum = 0;
2b1e4f0e 1293 //probi1[ipix] = probi[ipix];
1294 probi1[ipix] = probMax;
0df3ca52 1295 for (Int_t j=0; j<npad; j++) {
1296 if (fPadIJ[1][j] < 0) continue;
1297 Double_t sum1 = 0;
1298 indx1 = j*nPix;
1299 indx = indx1 + ipix;
1300 for (Int_t i=0; i<nPix; i++) {
1301 // Caculate expectation
1302 pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i);
1303 sum1 += pixPtr->Charge()*coef[indx1+i];
1304 } // for (Int_t i=0;
0627f609 1305 if (fXyq[2][j] > fgkSaturation-1 && sum1 > fXyq[2][j]) { probi1[ipix] -= coef[indx]; continue; } // correct for pad charge overflows
0df3ca52 1306 //cout << sum1 << " " << fXyq[2][j] << " " << coef[j*nPix+ipix] << endl;
1307 if (coef[indx] > 1.e-6) sum += fXyq[2][j]*coef[indx]/sum1;
1308 } // for (Int_t j=0;
1309 pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(ipix);
aacf0960 1310 if (probi1[ipix] > 1.e-6) chargeNew[ipix] = pixPtr->Charge() * sum / probi1[ipix];
1311 else chargeNew[ipix] = 0.;
0df3ca52 1312 } // for (Int_t ipix=0;
aacf0960 1313 for (Int_t i = 0; i < nPix; ++i) {
1314 pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i);
1315 pixPtr->SetCharge(chargeNew[i]);
1316 }
0df3ca52 1317 } // for (Int_t iter=0;
1318 delete [] probi1;
aacf0960 1319 delete [] chargeNew;
0df3ca52 1320 return;
1321}
1322
1323//_____________________________________________________________________________
1324void AliMUONClusterFinderAZ::FindCOG(TH2D *mlem, Double_t *xyc)
1325{
d19b6003 1326/// Calculate position of the center-of-gravity around the maximum pixel
0df3ca52 1327
1328 Int_t ixmax, iymax, ix, nsumx=0, nsumy=0, nsum=0;
1329 Int_t i1 = -9, j1 = -9;
1330 mlem->GetMaximumBin(ixmax,iymax,ix);
1331 Int_t nx = mlem->GetNbinsX();
1332 Int_t ny = mlem->GetNbinsY();
1333 Double_t thresh = mlem->GetMaximum()/10;
1334 Double_t x, y, cont, xq=0, yq=0, qq=0;
1335
1336 for (Int_t i=TMath::Max(1,iymax-1); i<=TMath::Min(ny,iymax+1); i++) {
1337 y = mlem->GetYaxis()->GetBinCenter(i);
1338 for (Int_t j=TMath::Max(1,ixmax-1); j<=TMath::Min(nx,ixmax+1); j++) {
1339 cont = mlem->GetCellContent(j,i);
1340 if (cont < thresh) continue;
1341 if (i != i1) {i1 = i; nsumy++;}
1342 if (j != j1) {j1 = j; nsumx++;}
1343 x = mlem->GetXaxis()->GetBinCenter(j);
1344 xq += x*cont;
1345 yq += y*cont;
1346 qq += cont;
1347 nsum++;
1348 }
1349 }
1350
1351 Double_t cmax = 0;
1352 Int_t i2 = 0, j2 = 0;
1353 x = y = 0;
1354 if (nsumy == 1) {
1355 // one bin in Y - add one more (with the largest signal)
1356 for (Int_t i=TMath::Max(1,iymax-1); i<=TMath::Min(ny,iymax+1); i++) {
1357 if (i == iymax) continue;
1358 for (Int_t j=TMath::Max(1,ixmax-1); j<=TMath::Min(nx,ixmax+1); j++) {
1359 cont = mlem->GetCellContent(j,i);
1360 if (cont > cmax) {
1361 cmax = cont;
1362 x = mlem->GetXaxis()->GetBinCenter(j);
1363 y = mlem->GetYaxis()->GetBinCenter(i);
1364 i2 = i;
1365 j2 = j;
1366 }
1367 }
1368 }
1369 xq += x*cmax;
1370 yq += y*cmax;
1371 qq += cmax;
1372 if (i2 != i1) nsumy++;
1373 if (j2 != j1) nsumx++;
1374 nsum++;
1375 } // if (nsumy == 1)
1376
1377 if (nsumx == 1) {
1378 // one bin in X - add one more (with the largest signal)
1379 cmax = x = y = 0;
1380 for (Int_t j=TMath::Max(1,ixmax-1); j<=TMath::Min(nx,ixmax+1); j++) {
1381 if (j == ixmax) continue;
1382 for (Int_t i=TMath::Max(1,iymax-1); i<=TMath::Min(ny,iymax+1); i++) {
1383 cont = mlem->GetCellContent(j,i);
1384 if (cont > cmax) {
1385 cmax = cont;
1386 x = mlem->GetXaxis()->GetBinCenter(j);
1387 y = mlem->GetYaxis()->GetBinCenter(i);
1388 i2 = i;
1389 j2 = j;
1390 }
1391 }
1392 }
1393 xq += x*cmax;
1394 yq += y*cmax;
1395 qq += cmax;
1396 if (i2 != i1) nsumy++;
1397 if (j2 != j1) nsumx++;
1398 nsum++;
1399 } // if (nsumx == 1)
1400
1401 xyc[0] = xq/qq; xyc[1] = yq/qq;
2b1e4f0e 1402 if (fDebug) cout << xyc[0] << " " << xyc[1] << " " << qq << " " << nsum << " " << nsumx << " " << nsumy << endl;
0df3ca52 1403 return;
1404}
1405
1406//_____________________________________________________________________________
1407Int_t AliMUONClusterFinderAZ::FindNearest(AliMUONPixel *pixPtr0)
1408{
d19b6003 1409/// Find the pixel nearest to the given one
1410/// (algorithm may be not very efficient)
0df3ca52 1411
1412 Int_t nPix = fPixArray->GetEntriesFast(), imin = 0;
1413 Double_t rmin = 99999, dx = 0, dy = 0, r = 0;
1414 Double_t xc = pixPtr0->Coord(0), yc = pixPtr0->Coord(1);
1415 AliMUONPixel *pixPtr;
1416
1417 for (Int_t i=0; i<nPix; i++) {
1418 pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i);
1419 if (pixPtr->Charge() < 0.5) continue;
1420 dx = (xc - pixPtr->Coord(0)) / pixPtr->Size(0);
1421 dy = (yc - pixPtr->Coord(1)) / pixPtr->Size(1);
1422 r = dx *dx + dy * dy;
1423 if (r < rmin) { rmin = r; imin = i; }
1424 }
1425 return imin;
1426}
1427
1428//_____________________________________________________________________________
1429void AliMUONClusterFinderAZ::Split(TH2D *mlem, Double_t *coef)
1430{
d19b6003 1431/// The main steering function to work with clusters of pixels in anode
1432/// plane (find clusters, decouple them from each other, merge them (if
1433/// necessary), pick up coupled pads, call the fitting function)
0df3ca52 1434
1435 Int_t nx = mlem->GetNbinsX();
1436 Int_t ny = mlem->GetNbinsY();
1437 Int_t nPix = fPixArray->GetEntriesFast();
1438
1439 Bool_t *used = new Bool_t[ny*nx];
1440 Double_t cont;
1441 Int_t nclust = 0, indx, indx1;
1442
1443 for (Int_t i=0; i<ny*nx; i++) used[i] = kFALSE;
1444
1445 TObjArray *clusters[200]={0};
1446 TObjArray *pix;
1447
1448 // Find clusters of histogram bins (easier to work in 2-D space)
1449 for (Int_t i=1; i<=ny; i++) {
1450 for (Int_t j=1; j<=nx; j++) {
1451 indx = (i-1)*nx + j - 1;
1452 if (used[indx]) continue;
1453 cont = mlem->GetCellContent(j,i);
1454 if (cont < 0.5) continue;
1455 pix = new TObjArray(20);
1456 used[indx] = 1;
1457 pix->Add(BinToPix(mlem,j,i));
1458 AddBin(mlem, i, j, 0, used, pix); // recursive call
2b1e4f0e 1459 if (nclust >= 200) AliFatal(" Too many clusters !!!");
0df3ca52 1460 clusters[nclust++] = pix;
0df3ca52 1461 } // for (Int_t j=1; j<=nx; j++) {
1462 } // for (Int_t i=1; i<=ny;
2b1e4f0e 1463 if (fDebug) cout << nclust << endl;
0df3ca52 1464 delete [] used; used = 0;
1465
1466 // Compute couplings between clusters and clusters to pads
1467 Int_t npad = fnPads[0] + fnPads[1];
1468
2b1e4f0e 1469 // Write out some information for algorithm development
1470 Int_t cath=0, npadx[2]={0}, npady[2]={0};
1471 Double_t xlow[2]={9999,9999}, xhig[2]={-9999,-9999};
1472 Double_t ylow[2]={9999,9999}, yhig[2]={-9999,-9999};
1473 for (Int_t j=0; j<npad; j++) {
1474 if (fXyq[3][j] < 0) continue; // exclude virtual pads
1475 cath = fPadIJ[0][j];
1476 if (fXyq[0][j] < xlow[cath]-0.001) {
1477 if (fXyq[0][j]+fXyq[3][j] <= xlow[cath] && npadx[cath]) npadx[cath]++;
1478 xlow[cath] = fXyq[0][j];
1479 }
1480 if (fXyq[0][j] > xhig[cath]+0.001) {
1481 if (fXyq[0][j]-fXyq[3][j] >= xhig[cath]) npadx[cath]++;
1482 xhig[cath] = fXyq[0][j];
1483 }
1484 if (fXyq[1][j] < ylow[cath]-0.001) {
1485 if (fXyq[1][j]+fXyq[4][j] <= ylow[cath] && npady[cath]) npady[cath]++;
1486 ylow[cath] = fXyq[1][j];
1487 }
1488 if (fXyq[1][j] > yhig[cath]+0.001) {
1489 if (fXyq[1][j]-fXyq[4][j] >= yhig[cath]) npady[cath]++;
1490 yhig[cath] = fXyq[1][j];
1491 }
1492 }
2b1e4f0e 1493
0df3ca52 1494 // Exclude pads with overflows
1495 for (Int_t j=0; j<npad; j++) {
0627f609 1496 if (fXyq[2][j] > fgkSaturation-1) fPadIJ[1][j] = -5;
0df3ca52 1497 else fPadIJ[1][j] = 0;
1498 }
1499
1500 // Compute couplings of clusters to pads
c1aed84f 1501 TMatrixD *aijclupad = new TMatrixD(nclust,npad);
1502 *aijclupad = 0;
0df3ca52 1503 Int_t npxclu;
1504 for (Int_t iclust=0; iclust<nclust; iclust++) {
1505 pix = clusters[iclust];
1506 npxclu = pix->GetEntriesFast();
1507 for (Int_t i=0; i<npxclu; i++) {
1508 indx = fPixArray->IndexOf(pix->UncheckedAt(i));
1509 for (Int_t j=0; j<npad; j++) {
2b1e4f0e 1510 if (fPadIJ[1][j] < 0 && fPadIJ[1][j] != -5) continue;
343146bf 1511 if (coef[j*nPix+indx] < fgkCouplMin) continue;
c1aed84f 1512 (*aijclupad)(iclust,j) += coef[j*nPix+indx];
0df3ca52 1513 }
1514 }
1515 }
1516 // Compute couplings between clusters
c1aed84f 1517 TMatrixD *aijcluclu = new TMatrixD(nclust,nclust);
1518 *aijcluclu = 0;
0df3ca52 1519 for (Int_t iclust=0; iclust<nclust; iclust++) {
1520 for (Int_t j=0; j<npad; j++) {
1521 // Exclude overflows
1522 if (fPadIJ[1][j] < 0) continue;
343146bf 1523 if ((*aijclupad)(iclust,j) < fgkCouplMin) continue;
0df3ca52 1524 for (Int_t iclust1=iclust+1; iclust1<nclust; iclust1++) {
343146bf 1525 if ((*aijclupad)(iclust1,j) < fgkCouplMin) continue;
c1aed84f 1526 (*aijcluclu)(iclust,iclust1) +=
1527 TMath::Sqrt ((*aijclupad)(iclust,j)*(*aijclupad)(iclust1,j));
0df3ca52 1528 }
1529 }
1530 }
1531 for (Int_t iclust=0; iclust<nclust; iclust++) {
1532 for (Int_t iclust1=iclust+1; iclust1<nclust; iclust1++) {
c1aed84f 1533 (*aijcluclu)(iclust1,iclust) = (*aijcluclu)(iclust,iclust1);
0df3ca52 1534 }
1535 }
1536
2b1e4f0e 1537 if (fDebug && nclust > 1) aijcluclu->Print();
0df3ca52 1538
1539 // Find groups of coupled clusters
1540 used = new Bool_t[nclust];
1541 for (Int_t i=0; i<nclust; i++) used[i] = kFALSE;
1542 Int_t *clustNumb = new Int_t[nclust];
1543 Int_t nCoupled, nForFit, minGroup[3], clustFit[3], nfit = 0;
1544 Double_t parOk[8];
1545
1546 for (Int_t igroup=0; igroup<nclust; igroup++) {
1547 if (used[igroup]) continue;
1548 used[igroup] = kTRUE;
1549 clustNumb[0] = igroup;
1550 nCoupled = 1;
1551 // Find group of coupled clusters
c1aed84f 1552 AddCluster(igroup, nclust, aijcluclu, used, clustNumb, nCoupled); // recursive
2b1e4f0e 1553 if (fDebug) {
1554 cout << " nCoupled: " << nCoupled << endl;
1555 for (Int_t i=0; i<nCoupled; i++) cout << clustNumb[i] << " "; cout << endl;
1556 }
1557 fnCoupled = nCoupled;
0df3ca52 1558
1559 while (nCoupled > 0) {
1560
1561 if (nCoupled < 4) {
1562 nForFit = nCoupled;
1563 for (Int_t i=0; i<nCoupled; i++) clustFit[i] = clustNumb[i];
1564 } else {
1565 // Too many coupled clusters to fit - try to decouple them
1566 // Find the lowest coupling of 1, 2, min(3,nLinks/2) pixels with
1567 // all the others in the group
1568 for (Int_t j=0; j<3; j++) minGroup[j] = -1;
c1aed84f 1569 Double_t coupl = MinGroupCoupl(nCoupled, clustNumb, aijcluclu, minGroup);
0df3ca52 1570
1571 // Flag clusters for fit
1572 nForFit = 0;
1573 while (minGroup[nForFit] >= 0 && nForFit < 3) {
2b1e4f0e 1574 if (fDebug) cout << clustNumb[minGroup[nForFit]] << " ";
0df3ca52 1575 clustFit[nForFit] = clustNumb[minGroup[nForFit]];
1576 clustNumb[minGroup[nForFit]] -= 999;
1577 nForFit++;
1578 }
2b1e4f0e 1579 if (fDebug) cout << nForFit << " " << coupl << endl;
0df3ca52 1580 } // else
1581
1582 // Select pads for fit.
c1aed84f 1583 if (SelectPad(nCoupled, nForFit, clustNumb, clustFit, aijclupad) < 3 && nCoupled > 1) {
0df3ca52 1584 // Deselect pads
2b1e4f0e 1585 for (Int_t j=0; j<npad; j++) {
1586 if (TMath::Abs(fPadIJ[1][j]) == 1) fPadIJ[1][j] = 0;
1587 if (TMath::Abs(fPadIJ[1][j]) == -9) fPadIJ[1][j] = -5;
1588 }
0df3ca52 1589 // Merge the failed cluster candidates (with too few pads to fit) with
1590 // the one with the strongest coupling
c1aed84f 1591 Merge(nForFit, nCoupled, clustNumb, clustFit, clusters, aijcluclu, aijclupad);
0df3ca52 1592 } else {
1593 // Do the fit
0627f609 1594 nfit = Fit(0, nForFit, clustFit, clusters, parOk);
0df3ca52 1595 }
1596
1597 // Subtract the fitted charges from pads with strong coupling and/or
1598 // return pads for further use
1599 UpdatePads(nfit, parOk);
1600
1601 // Mark used pads
2b1e4f0e 1602 for (Int_t j=0; j<npad; j++) {
1603 if (fPadIJ[1][j] == 1) fPadIJ[1][j] = -1;
1604 if (fPadIJ[1][j] == -9) fPadIJ[1][j] = -5;
1605 }
0df3ca52 1606
1607 // Sort the clusters (move to the right the used ones)
1608 Int_t beg = 0, end = nCoupled - 1;
1609 while (beg < end) {
1610 if (clustNumb[beg] >= 0) { beg++; continue; }
1611 for (Int_t j=end; j>beg; j--) {
1612 if (clustNumb[j] < 0) continue;
1613 end = j - 1;
1614 indx = clustNumb[beg];
1615 clustNumb[beg] = clustNumb[j];
1616 clustNumb[j] = indx;
1617 break;
1618 }
1619 beg++;
1620 }
1621
1622 nCoupled -= nForFit;
1623 if (nCoupled > 3) {
1624 // Remove couplings of used clusters
1625 for (Int_t iclust=nCoupled; iclust<nCoupled+nForFit; iclust++) {
1626 indx = clustNumb[iclust] + 999;
1627 for (Int_t iclust1=0; iclust1<nCoupled; iclust1++) {
1628 indx1 = clustNumb[iclust1];
c1aed84f 1629 (*aijcluclu)(indx,indx1) = (*aijcluclu)(indx1,indx) = 0;
0df3ca52 1630 }
1631 }
1632
1633 // Update the remaining clusters couplings (exclude couplings from
1634 // the used pads)
1635 for (Int_t j=0; j<npad; j++) {
1636 if (fPadIJ[1][j] != -1) continue;
1637 for (Int_t iclust=0; iclust<nCoupled; iclust++) {
1638 indx = clustNumb[iclust];
343146bf 1639 if ((*aijclupad)(indx,j) < fgkCouplMin) continue;
0df3ca52 1640 for (Int_t iclust1=iclust+1; iclust1<nCoupled; iclust1++) {
1641 indx1 = clustNumb[iclust1];
343146bf 1642 if ((*aijclupad)(indx1,j) < fgkCouplMin) continue;
0df3ca52 1643 // Check this
c1aed84f 1644 (*aijcluclu)(indx,indx1) -=
1645 TMath::Sqrt ((*aijclupad)(indx,j)*(*aijclupad)(indx1,j));
1646 (*aijcluclu)(indx1,indx) = (*aijcluclu)(indx,indx1);
0df3ca52 1647 }
1648 }
2b1e4f0e 1649 fPadIJ[1][j] = -8;
0df3ca52 1650 } // for (Int_t j=0; j<npad;
1651 } // if (nCoupled > 3)
1652 } // while (nCoupled > 0)
1653 } // for (Int_t igroup=0; igroup<nclust;
1654
c1aed84f 1655 aijcluclu->Delete(); aijclupad->Delete();
0df3ca52 1656 for (Int_t iclust=0; iclust<nclust; iclust++) {
1657 pix = clusters[iclust];
1658 pix->Clear();
1659 delete pix; pix = 0;
1660 }
1661 delete [] clustNumb; clustNumb = 0; delete [] used; used = 0;
1662}
1663
1664//_____________________________________________________________________________
1665void AliMUONClusterFinderAZ::AddBin(TH2D *mlem, Int_t ic, Int_t jc, Int_t mode, Bool_t *used, TObjArray *pix)
1666{
d19b6003 1667/// Add a bin to the cluster
0df3ca52 1668
1669 Int_t nx = mlem->GetNbinsX();
1670 Int_t ny = mlem->GetNbinsY();
1671 Double_t cont1, cont = mlem->GetCellContent(jc,ic);
1672 AliMUONPixel *pixPtr = 0;
1673
1674 for (Int_t i=TMath::Max(ic-1,1); i<=TMath::Min(ic+1,ny); i++) {
1675 for (Int_t j=TMath::Max(jc-1,1); j<=TMath::Min(jc+1,nx); j++) {
1676 if (i != ic && j != jc) continue;
1677 if (used[(i-1)*nx+j-1]) continue;
1678 cont1 = mlem->GetCellContent(j,i);
1679 if (mode && cont1 > cont) continue;
1680 used[(i-1)*nx+j-1] = kTRUE;
1681 if (cont1 < 0.5) continue;
1682 if (pix) pix->Add(BinToPix(mlem,j,i));
1683 else {
1684 pixPtr = new AliMUONPixel (mlem->GetXaxis()->GetBinCenter(j),
1685 mlem->GetYaxis()->GetBinCenter(i), 0, 0, cont1);
1686 fPixArray->Add((TObject*)pixPtr);
1687 }
1688 AddBin(mlem, i, j, mode, used, pix); // recursive call
1689 }
1690 }
1691}
1692
1693//_____________________________________________________________________________
1694TObject* AliMUONClusterFinderAZ::BinToPix(TH2D *mlem, Int_t jc, Int_t ic)
1695{
d19b6003 1696/// Translate histogram bin to pixel
0df3ca52 1697
1698 Double_t yc = mlem->GetYaxis()->GetBinCenter(ic);
1699 Double_t xc = mlem->GetXaxis()->GetBinCenter(jc);
1700
1701 Int_t nPix = fPixArray->GetEntriesFast();
0627f609 1702 AliMUONPixel *pixPtr = NULL;
0df3ca52 1703
1704 // Compare pixel and bin positions
1705 for (Int_t i=0; i<nPix; i++) {
1706 pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i);
1707 if (pixPtr->Charge() < 0.5) continue;
1708 if (TMath::Abs(pixPtr->Coord(0)-xc)<1.e-4 && TMath::Abs(pixPtr->Coord(1)-yc)<1.e-4) return (TObject*) pixPtr;
1709 }
94eb555e 1710 AliError(Form(" Something wrong ??? %f %f ", xc, yc));
0df3ca52 1711 return NULL;
1712}
1713
1714//_____________________________________________________________________________
c1aed84f 1715void AliMUONClusterFinderAZ::AddCluster(Int_t ic, Int_t nclust, TMatrixD *aijcluclu, Bool_t *used, Int_t *clustNumb, Int_t &nCoupled)
0df3ca52 1716{
d19b6003 1717/// Add a cluster to the group of coupled clusters
0df3ca52 1718
1719 for (Int_t i=0; i<nclust; i++) {
1720 if (used[i]) continue;
343146bf 1721 if ((*aijcluclu)(i,ic) < fgkCouplMin) continue;
0df3ca52 1722 used[i] = kTRUE;
1723 clustNumb[nCoupled++] = i;
c1aed84f 1724 AddCluster(i, nclust, aijcluclu, used, clustNumb, nCoupled);
0df3ca52 1725 }
1726}
1727
1728//_____________________________________________________________________________
c1aed84f 1729Double_t AliMUONClusterFinderAZ::MinGroupCoupl(Int_t nCoupled, Int_t *clustNumb, TMatrixD *aijcluclu, Int_t *minGroup)
0df3ca52 1730{
d19b6003 1731/// Find group of clusters with minimum coupling to all the others
0df3ca52 1732
1733 Int_t i123max = TMath::Min(3,nCoupled/2);
1734 Int_t indx, indx1, indx2, indx3, nTot = 0;
1735 Double_t *coupl1 = 0, *coupl2 = 0, *coupl3 = 0;
1736
1737 for (Int_t i123=1; i123<=i123max; i123++) {
1738
1739 if (i123 == 1) {
1740 coupl1 = new Double_t [nCoupled];
1741 for (Int_t i=0; i<nCoupled; i++) coupl1[i] = 0;
1742 }
1743 else if (i123 == 2) {
1744 nTot = nCoupled*nCoupled;
1745 coupl2 = new Double_t [nTot];
1746 for (Int_t i=0; i<nTot; i++) coupl2[i] = 9999;
1747 } else {
1748 nTot = nTot*nCoupled;
1749 coupl3 = new Double_t [nTot];
1750 for (Int_t i=0; i<nTot; i++) coupl3[i] = 9999;
1751 } // else
1752
1753 for (Int_t i=0; i<nCoupled; i++) {
1754 indx1 = clustNumb[i];
1755 for (Int_t j=i+1; j<nCoupled; j++) {
1756 indx2 = clustNumb[j];
1757 if (i123 == 1) {
c1aed84f 1758 coupl1[i] += (*aijcluclu)(indx1,indx2);
1759 coupl1[j] += (*aijcluclu)(indx1,indx2);
0df3ca52 1760 }
1761 else if (i123 == 2) {
1762 indx = i*nCoupled + j;
1763 coupl2[indx] = coupl1[i] + coupl1[j];
c1aed84f 1764 coupl2[indx] -= 2 * ((*aijcluclu)(indx1,indx2));
0df3ca52 1765 } else {
1766 for (Int_t k=j+1; k<nCoupled; k++) {
1767 indx3 = clustNumb[k];
1768 indx = i*nCoupled*nCoupled + j*nCoupled + k;
1769 coupl3[indx] = coupl2[i*nCoupled+j] + coupl1[k];
c1aed84f 1770 coupl3[indx] -= 2 * ((*aijcluclu)(indx1,indx3)+(*aijcluclu)(indx2,indx3));
0df3ca52 1771 }
1772 } // else
1773 } // for (Int_t j=i+1;
1774 } // for (Int_t i=0;
1775 } // for (Int_t i123=1;
1776
1777 // Find minimum coupling
1778 Double_t couplMin = 9999;
1779 Int_t locMin = 0;
1780
1781 for (Int_t i123=1; i123<=i123max; i123++) {
1782 if (i123 == 1) {
1783 locMin = TMath::LocMin(nCoupled, coupl1);
1784 couplMin = coupl1[locMin];
1785 minGroup[0] = locMin;
1786 delete [] coupl1; coupl1 = 0;
1787 }
1788 else if (i123 == 2) {
1789 locMin = TMath::LocMin(nCoupled*nCoupled, coupl2);
1790 if (coupl2[locMin] < couplMin) {
1791 couplMin = coupl2[locMin];
1792 minGroup[0] = locMin/nCoupled;
1793 minGroup[1] = locMin%nCoupled;
1794 }
1795 delete [] coupl2; coupl2 = 0;
1796 } else {
1797 locMin = TMath::LocMin(nTot, coupl3);
1798 if (coupl3[locMin] < couplMin) {
1799 couplMin = coupl3[locMin];
1800 minGroup[0] = locMin/nCoupled/nCoupled;
1801 minGroup[1] = locMin%(nCoupled*nCoupled)/nCoupled;
1802 minGroup[2] = locMin%nCoupled;
1803 }
1804 delete [] coupl3; coupl3 = 0;
1805 } // else
1806 } // for (Int_t i123=1;
1807 return couplMin;
1808}
1809
1810//_____________________________________________________________________________
c1aed84f 1811Int_t AliMUONClusterFinderAZ::SelectPad(Int_t nCoupled, Int_t nForFit, Int_t *clustNumb, Int_t *clustFit, TMatrixD *aijclupad)
0df3ca52 1812{
d19b6003 1813/// Select pads for fit. If too many coupled clusters, find pads giving
1814/// the strongest coupling with the rest of clusters and exclude them from the fit.
0df3ca52 1815
1816 Int_t npad = fnPads[0] + fnPads[1];
c1aed84f 1817 Double_t *padpix = 0;
0df3ca52 1818
1819 if (nCoupled > 3) {
c1aed84f 1820 padpix = new Double_t[npad];
1821 for (Int_t i=0; i<npad; i++) padpix[i] = 0;
0df3ca52 1822 }
1823
1824 Int_t nOK = 0, indx, indx1;
1825 for (Int_t iclust=0; iclust<nForFit; iclust++) {
1826 indx = clustFit[iclust];
1827 for (Int_t j=0; j<npad; j++) {
343146bf 1828 if ((*aijclupad)(indx,j) < fgkCouplMin) continue;
2b1e4f0e 1829 if (fPadIJ[1][j] == -5) fPadIJ[1][j] = -9; // flag overflow
1830 if (fPadIJ[1][j] < 0) continue; // exclude overflows and used pads
1831 if (!fPadIJ[1][j]) { fPadIJ[1][j] = 1; nOK++; } // pad to be used in fit
0df3ca52 1832 if (nCoupled > 3) {
1833 // Check other clusters
1834 for (Int_t iclust1=0; iclust1<nCoupled; iclust1++) {
1835 indx1 = clustNumb[iclust1];
1836 if (indx1 < 0) continue;
343146bf 1837 if ((*aijclupad)(indx1,j) < fgkCouplMin) continue;
c1aed84f 1838 padpix[j] += (*aijclupad)(indx1,j);
0df3ca52 1839 }
1840 } // if (nCoupled > 3)
1841 } // for (Int_t j=0; j<npad;
1842 } // for (Int_t iclust=0; iclust<nForFit
1843 if (nCoupled < 4) return nOK;
1844
1845 Double_t aaa = 0;
1846 for (Int_t j=0; j<npad; j++) {
343146bf 1847 if (padpix[j] < fgkCouplMin) continue;
2b1e4f0e 1848 if (fDebug) cout << j << " " << padpix[j] << " " << fXyq[0][j] << " " << fXyq[1][j] << endl;
c1aed84f 1849 aaa += padpix[j];
0df3ca52 1850 fPadIJ[1][j] = -1; // exclude pads with strong coupling to the other clusters
1851 nOK--;
1852 }
c1aed84f 1853 delete [] padpix; padpix = 0;
0df3ca52 1854 return nOK;
1855}
1856
1857//_____________________________________________________________________________
c1aed84f 1858void AliMUONClusterFinderAZ::Merge(Int_t nForFit, Int_t nCoupled, Int_t *clustNumb, Int_t *clustFit, TObjArray **clusters, TMatrixD *aijcluclu, TMatrixD *aijclupad)
0df3ca52 1859{
d19b6003 1860/// Merge the group of clusters with the one having the strongest coupling with them
0df3ca52 1861
1862 Int_t indx, indx1, npxclu, npxclu1, imax=0;
1863 TObjArray *pix, *pix1;
1864 Double_t couplMax;
1865
1866 for (Int_t icl=0; icl<nForFit; icl++) {
1867 indx = clustFit[icl];
1868 pix = clusters[indx];
1869 npxclu = pix->GetEntriesFast();
1870 couplMax = -1;
1871 for (Int_t icl1=0; icl1<nCoupled; icl1++) {
1872 indx1 = clustNumb[icl1];
1873 if (indx1 < 0) continue;
c1aed84f 1874 if ((*aijcluclu)(indx,indx1) > couplMax) {
1875 couplMax = (*aijcluclu)(indx,indx1);
0df3ca52 1876 imax = indx1;
1877 }
1878 } // for (Int_t icl1=0;
343146bf 1879 /*if (couplMax < fgkCouplMin) {
0df3ca52 1880 cout << " Oops " << couplMax << endl;
c1aed84f 1881 aijcluclu->Print();
0df3ca52 1882 cout << icl << " " << indx << " " << npxclu << " " << nLinks << endl;
1883 ::exit(0);
1884 }*/
1885 // Add to it
1886 pix1 = clusters[imax];
1887 npxclu1 = pix1->GetEntriesFast();
1888 // Add pixels
1889 for (Int_t i=0; i<npxclu; i++) { pix1->Add(pix->UncheckedAt(i)); pix->RemoveAt(i); }
2b1e4f0e 1890 if (fDebug) cout << " New number of pixels: " << npxclu1 << " " << pix1->GetEntriesFast() << endl;
0df3ca52 1891 //Add cluster-to-cluster couplings
c1aed84f 1892 //aijcluclu->Print();
0df3ca52 1893 for (Int_t icl1=0; icl1<nCoupled; icl1++) {
1894 indx1 = clustNumb[icl1];
1895 if (indx1 < 0 || indx1 == imax) continue;
c1aed84f 1896 (*aijcluclu)(indx1,imax) += (*aijcluclu)(indx,indx1);
1897 (*aijcluclu)(imax,indx1) = (*aijcluclu)(indx1,imax);
0df3ca52 1898 }
c1aed84f 1899 (*aijcluclu)(indx,imax) = (*aijcluclu)(imax,indx) = 0;
1900 //aijcluclu->Print();
0df3ca52 1901 //Add cluster-to-pad couplings
1902 for (Int_t j=0; j<fnPads[0]+fnPads[1]; j++) {
2b1e4f0e 1903 if (fPadIJ[1][j] < 0 && fPadIJ[1][j] != -5) continue; // exclude used pads
c1aed84f 1904 (*aijclupad)(imax,j) += (*aijclupad)(indx,j);
1905 (*aijclupad)(indx,j) = 0;
0df3ca52 1906 }
1907 } // for (Int_t icl=0; icl<nForFit;
1908}
1909
1910//_____________________________________________________________________________
0627f609 1911Int_t AliMUONClusterFinderAZ::Fit(Int_t iSimple, Int_t nfit, Int_t *clustFit, TObjArray **clusters, Double_t *parOk)
0df3ca52 1912{
d19b6003 1913/// Find selected clusters to selected pad charges
0df3ca52 1914
1915 TH2D *mlem = (TH2D*) gROOT->FindObject("mlem");
0df3ca52 1916 Double_t xmin = mlem->GetXaxis()->GetXmin() - mlem->GetXaxis()->GetBinWidth(1);
1917 Double_t xmax = mlem->GetXaxis()->GetXmax() + mlem->GetXaxis()->GetBinWidth(1);
1918 Double_t ymin = mlem->GetYaxis()->GetXmin() - mlem->GetYaxis()->GetBinWidth(1);
1919 Double_t ymax = mlem->GetYaxis()->GetXmax() + mlem->GetYaxis()->GetBinWidth(1);
2b1e4f0e 1920 Double_t step[3]={0.01,0.002,0.02}, xPad = 0, yPad = 99999;
0df3ca52 1921
2b1e4f0e 1922 // Number of pads to use and number of virtual pads
0627f609 1923 Int_t npads = 0, nVirtual = 0, nfit0 = nfit;
2b1e4f0e 1924 for (Int_t i=0; i<fnPads[0]+fnPads[1]; i++) {
2b1e4f0e 1925 if (fXyq[3][i] < 0) nVirtual++;
1926 if (fPadIJ[1][i] != 1) continue;
0627f609 1927 if (fXyq[3][i] > 0) {
1928 npads++;
1929 if (yPad > 9999) {
1930 xPad = fXyq[0][i];
1931 yPad = fXyq[1][i];
1932 } else {
1933 if (fXyq[4][i] < fXyq[3][i]) yPad = fXyq[1][i];
1934 else xPad = fXyq[0][i];
1935 }
1936 }
2b1e4f0e 1937 }
1938 if (fDebug) {
1939 for (Int_t i=0; i<nfit; i++) {cout << i+1 << " " << clustFit[i] << " ";}
1940 cout << nfit << endl;
1941 cout << " Number of pads to fit: " << npads << endl;
1942 }
0df3ca52 1943 fNpar = 0;
1944 fQtot = 0;
1945 if (npads < 2) return 0;
0627f609 1946
45c72492 1947 AliMUONVDigit *mdig = 0;
2b1e4f0e 1948 Int_t tracks[3] = {-1, -1, -1};
1949 for (Int_t cath=0; cath<2; cath++) {
1950 for (Int_t i=0; i<fnPads[0]+fnPads[1]; i++) {
1951 if (fPadIJ[0][i] != cath) continue;
1952 if (fPadIJ[1][i] != 1) continue;
1953 if (fXyq[3][i] < 0) continue; // exclude virtual pads
45c72492 1954 UInt_t digit = fDigitId[i];
1955 mdig = static_cast<AliMUONVDigit*>(fDigitStore->FindObject(digit));
2b1e4f0e 1956 if (!mdig) continue; // protection for cluster display
1957 if (mdig->Hit() >= 0) {
45c72492 1958 if (tracks[0] < 0) {
1959 tracks[0] = mdig->Hit();
1960 tracks[1] = mdig->Track(0);
1961 } else if (mdig->Track(0) < tracks[1]) {
1962 tracks[0] = mdig->Hit();
1963 tracks[1] = mdig->Track(0);
1964 }
2b1e4f0e 1965 }
2b1e4f0e 1966 if (mdig->Track(1) >= 0 && mdig->Track(1) != tracks[1]) {
45c72492 1967 if (tracks[2] < 0) tracks[2] = mdig->Track(1);
1968 else tracks[2] = TMath::Min (tracks[2], mdig->Track(1));
2b1e4f0e 1969 }
1970 //if (!mdig) break;
1971 //cout << mdig->Hit() << " " << mdig->Track(0) << " " << mdig->Track(1) <<endl;
1972 } // for (Int_t i=0;
1973 } // for (Int_t cath=0;
1974 //cout << tracks[0] << " " << tracks[1] << " " << tracks[2] <<endl;
1975
1976 // Get number of pads in X and Y
1977 Int_t nInX = 0, nInY;
1978 PadsInXandY(nInX, nInY);
1af223d7 1979 //cout << " nInX and Y: " << nInX << " " << nInY << endl;
2b1e4f0e 1980
0627f609 1981 Int_t nfitMax = 3;
1982 nfitMax = TMath::Min (nfitMax, (npads + 1) / 3);
1983 if (nfitMax > 1) {
1984 if (nInX < 3 && nInY < 3 || nInX == 3 && nInY < 3 || nInX < 3 && nInY == 3) nfitMax = 1; // not enough pads in each direction
1985 }
1986 if (nfit > nfitMax) nfit = nfitMax;
1987
0df3ca52 1988 // Take cluster maxima as fitting seeds
2b1e4f0e 1989 TObjArray *pix;
0df3ca52 1990 AliMUONPixel *pixPtr;
2b1e4f0e 1991 Int_t npxclu;
1992 Double_t cont, cmax = 0, xseed = 0, yseed = 0, errOk[8], qq = 0;
f29ba3e1 1993 Double_t xyseed[3][2], qseed[3], xyCand[3][2] = {{0},{0}}, sigCand[3][2] = {{0},{0}};
2b1e4f0e 1994
0627f609 1995 for (Int_t ifit=1; ifit<=nfit0; ifit++) {
0df3ca52 1996 cmax = 0;
1997 pix = clusters[clustFit[ifit-1]];
1998 npxclu = pix->GetEntriesFast();
2b1e4f0e 1999 //qq = 0;
0df3ca52 2000 for (Int_t clu=0; clu<npxclu; clu++) {
2001 pixPtr = (AliMUONPixel*) pix->UncheckedAt(clu);
2002 cont = pixPtr->Charge();
2003 fQtot += cont;
2004 if (cont > cmax) {
2005 cmax = cont;
2006 xseed = pixPtr->Coord(0);
2007 yseed = pixPtr->Coord(1);
2008 }
2b1e4f0e 2009 qq += cont;
2010 /*
f29ba3e1 2011 xyCand[ifit-1][0] += pixPtr->Coord(0) * cont;
2012 xyCand[ifit-1][1] += pixPtr->Coord(1) * cont;
2013 sigCand[ifit-1][0] += pixPtr->Coord(0) * pixPtr->Coord(0) * cont;
2014 sigCand[ifit-1][1] += pixPtr->Coord(1) * pixPtr->Coord(1) * cont;
2b1e4f0e 2015 */
f29ba3e1 2016 xyCand[0][0] += pixPtr->Coord(0) * cont;
2017 xyCand[0][1] += pixPtr->Coord(1) * cont;
2018 sigCand[0][0] += pixPtr->Coord(0) * pixPtr->Coord(0) * cont;
2019 sigCand[0][1] += pixPtr->Coord(1) * pixPtr->Coord(1) * cont;
0df3ca52 2020 }
2021 xyseed[ifit-1][0] = xseed;
2022 xyseed[ifit-1][1] = yseed;
2023 qseed[ifit-1] = cmax;
2b1e4f0e 2024 /*
f29ba3e1 2025 xyCand[ifit-1][0] /= qq; // <x>
2026 xyCand[ifit-1][1] /= qq; // <y>
2027 sigCand[ifit-1][0] = sigCand[ifit-1][0]/qq - xyCand[ifit-1][0]*xyCand[ifit-1][0]; // <x^2> - <x>^2
2028 sigCand[ifit-1][0] = sigCand[ifit-1][0] > 0 ? TMath::Sqrt (sigCand[ifit-1][0]) : 0;
2029 sigCand[ifit-1][1] = sigCand[ifit-1][1]/qq - xyCand[ifit-1][1]*xyCand[ifit-1][1]; // <y^2> - <y>^2
2030 sigCand[ifit-1][1] = sigCand[ifit-1][1] > 0 ? TMath::Sqrt (sigCand[ifit-1][1]) : 0;
2031 cout << xyCand[ifit-1][0] << " " << xyCand[ifit-1][1] << " " << sigCand[ifit-1][0] << " " << sigCand[ifit-1][1] << endl;
2b1e4f0e 2032 */
0df3ca52 2033 } // for (Int_t ifit=1;
2034
f29ba3e1 2035 xyCand[0][0] /= qq; // <x>
2036 xyCand[0][1] /= qq; // <y>
2037 sigCand[0][0] = sigCand[0][0]/qq - xyCand[0][0]*xyCand[0][0]; // <x^2> - <x>^2
2038 sigCand[0][0] = sigCand[0][0] > 0 ? TMath::Sqrt (sigCand[0][0]) : 0;
2039 sigCand[0][1] = sigCand[0][1]/qq - xyCand[0][1]*xyCand[0][1]; // <y^2> - <y>^2
2040 sigCand[0][1] = sigCand[0][1] > 0 ? TMath::Sqrt (sigCand[0][1]) : 0;
2041 if (fDebug) cout << xyCand[0][0] << " " << xyCand[0][1] << " " << sigCand[0][0] << " " << sigCand[0][1] << endl;
2b1e4f0e 2042
0627f609 2043 Int_t nDof, maxSeed[3], nMax = 0;
0df3ca52 2044 Double_t fmin, chi2o = 9999, chi2n;
2045
0627f609 2046 TMath::Sort(nfit0, qseed, maxSeed, kTRUE); // in decreasing order
2047 /*
2048 Int_t itmp[100], localMax[100];
2049 Double_t maxVal[100];
2050 if (!iSimple && nfit < nfitMax) {
2051 // Try to split pixel cluster according to local maxima
2052 Int_t nfit1 = nfit;
2053 for (Int_t iclus = 0; iclus < nfit1; iclus++) {
2054 nMax = FindLocalMaxima (clusters[clustFit[maxSeed[iclus]]], localMax, maxVal);
2055 TH2D *hist = (TH2D*) gROOT->FindObject("anode1");
2056 if (nMax == 1) { hist->Delete(); continue; }
2057 // Add extra fitting seeds from local maxima
2058 Int_t ixseed = hist->GetXaxis()->FindBin(xyseed[maxSeed[iclus]][0]);
2059 Int_t iyseed = hist->GetYaxis()->FindBin(xyseed[maxSeed[iclus]][1]);
2060 Int_t nx = hist->GetNbinsX();
2061 TMath::Sort(nMax, maxVal, itmp, kTRUE); // in decreasing order
2062 for (Int_t j = 0; j < nMax; j++) {
2063 Int_t iyc = localMax[itmp[j]] / nx + 1;
2064 Int_t ixc = localMax[itmp[j]] % nx + 1;
2065 if (ixc == ixseed && iyc == iyseed) continue; // local max already taken for seeding
2066 xyseed[nfit][0] = hist->GetXaxis()->GetBinCenter(ixc);
2067 xyseed[nfit][1] = hist->GetYaxis()->GetBinCenter(iyc);
2068 qseed[nfit] = maxVal[itmp[j]];
2069 maxSeed[nfit] = nfit++;
2070 if (nfit >= nfitMax) break;
2071 }
2072 hist->Delete();
2073 if (nfit >= nfitMax) break;
2074 } // for (Int_t iclus = 0;
2075 //nfit0 = nfit;
2076 //TMath::Sort(nfit0, qseed, maxSeed, kTRUE); // in decreasing order
2077 } //if (!iSimple && nfit < nfitMax)
2078 */
0df3ca52 2079
a952ddec 2080 Double_t *gin = 0, func0, func1, param[8], step0[8];
2081 Double_t param0[2][8]={{0},{0}}, deriv[2][8]={{0},{0}};
0df3ca52 2082 Double_t shift[8], stepMax, derMax, parmin[8], parmax[8], func2[2], shift0;
2083 Double_t delta[8], scMax, dder[8], estim, shiftSave = 0;
aacf0960 2084 Int_t min, max, nCall = 0, nLoop, idMax = 0, iestMax = 0, nFail;
2b1e4f0e 2085 Double_t rad, dist[3] = {0};
0df3ca52 2086
0627f609 2087 // Try to fit with one-track hypothesis, then 2-track. If chi2/dof is
2088 // lower, try 3-track (if number of pads is sufficient).
0df3ca52 2089 for (Int_t iseed=0; iseed<nfit; iseed++) {
2090
aacf0960 2091 Int_t memory[8] = {0};
2b1e4f0e 2092 if (iseed) { for (Int_t j=0; j<fNpar; j++) param[j] = parOk[j]; } // for bounded params
0df3ca52 2093 for (Int_t j=0; j<3; j++) step0[fNpar+j] = shift[fNpar+j] = step[j];
0627f609 2094 if (nfit == 1) param[fNpar] = xyCand[0][0]; // take COG
2095 else param[fNpar] = xyseed[maxSeed[iseed]][0];
0df3ca52 2096 parmin[fNpar] = xmin;
2097 parmax[fNpar++] = xmax;
0627f609 2098 if (nfit == 1) param[fNpar] = xyCand[0][1]; // take COG
2099 else param[fNpar] = xyseed[maxSeed[iseed]][1];
0df3ca52 2100 parmin[fNpar] = ymin;
2101 parmax[fNpar++] = ymax;
2102 if (fNpar > 2) {
2103 param[fNpar] = fNpar == 4 ? 0.5 : 0.3;
2104 parmin[fNpar] = 0;
2105 parmax[fNpar++] = 1;
2106 }
5a051e34 2107 if (iseed) { for (Int_t j=0; j<fNpar; j++) param0[1][j] = 0; }
0df3ca52 2108
2109 // Try new algorithm
2110 min = nLoop = 1; stepMax = func2[1] = derMax = 999999; nFail = 0;
2111
2112 while (1) {
2113 max = !min;
30178c30 2114 Fcn1(fNpar, gin, func0, param, 1); nCall++;
0df3ca52 2115 //cout << " Func: " << func0 << endl;
2116
2117 func2[max] = func0;
2118 for (Int_t j=0; j<fNpar; j++) {
2119 param0[max][j] = param[j];
2120 delta[j] = step0[j];
2121 param[j] += delta[j] / 10;
2122 if (j > 0) param[j-1] -= delta[j-1] / 10;
30178c30 2123 Fcn1(fNpar, gin, func1, param, 1); nCall++;
0df3ca52 2124 deriv[max][j] = (func1 - func0) / delta[j] * 10; // first derivative
2125 //cout << j << " " << deriv[max][j] << endl;
2126 dder[j] = param0[0][j] != param0[1][j] ? (deriv[0][j] - deriv[1][j]) /
a952ddec 2127 (param0[0][j] - param0[1][j]) : 0; // second derivative
0df3ca52 2128 }
2129 param[fNpar-1] -= delta[fNpar-1] / 10;
2b1e4f0e 2130 if (nCall > 2000) break;
0df3ca52 2131
2132 min = func2[0] < func2[1] ? 0 : 1;
2133 nFail = min == max ? 0 : nFail + 1;
2134
2135 stepMax = derMax = estim = 0;
2136 for (Int_t j=0; j<fNpar; j++) {
2137 // Estimated distance to minimum
2138 shift0 = shift[j];
2139 if (nLoop == 1) shift[j] = TMath::Sign (step0[j], -deriv[max][j]); // first step
2140 else if (TMath::Abs(deriv[0][j]) < 1.e-3 && TMath::Abs(deriv[1][j]) < 1.e-3) shift[j] = 0;
2141 else if (deriv[min][j]*deriv[!min][j] > 0 && TMath::Abs(deriv[min][j]) > TMath::Abs(deriv[!min][j])
2b1e4f0e 2142 //|| TMath::Abs(deriv[0][j]-deriv[1][j]) < 1.e-3) {
2143 || TMath::Abs(deriv[0][j]-deriv[1][j]) < 1.e-3 || TMath::Abs(dder[j]) < 1.e-6) {
0df3ca52 2144 shift[j] = -TMath::Sign (shift[j], (func2[0]-func2[1]) * (param0[0][j]-param0[1][j]));
2145 if (min == max) {
2146 if (memory[j] > 1) { shift[j] *= 2; } //cout << " Memory " << memory[j] << " " << shift[j] << endl; }
2147 memory[j]++;
2148 }
2149 } else {
2b1e4f0e 2150 shift[j] = dder[j] != 0 ? -deriv[min][j] / dder[j] : 0;
0df3ca52 2151 memory[j] = 0;
2152 }
2153 if (TMath::Abs(shift[j])/step0[j] > estim) {
2154 estim = TMath::Abs(shift[j])/step0[j];
2155 iestMax = j;
2156 }
2157
2158 // Too big step
2159 if (TMath::Abs(shift[j])/step0[j] > 10) shift[j] = TMath::Sign(10.,shift[j]) * step0[j]; //
2160
2161 // Failed to improve minimum
2162 if (min != max) {
2163 memory[j] = 0;
2164 param[j] = param0[min][j];
2165 if (TMath::Abs(shift[j]+shift0) > 0.1*step0[j]) shift[j] = (shift[j] + shift0) / 2;
2166 else shift[j] /= -2;
2167 }
2168
2169 // Too big step
2170 if (TMath::Abs(shift[j]*deriv[min][j]) > func2[min])
2171 shift[j] = TMath::Sign (func2[min]/deriv[min][j], shift[j]);
2172
2173 // Introduce step relaxation factor
2174 if (memory[j] < 3) {
2175 scMax = 1 + 4 / TMath::Max(nLoop/2.,1.);
2176 if (TMath::Abs(shift0) > 0 && TMath::Abs(shift[j]/shift0) > scMax)
2177 shift[j] = TMath::Sign (shift0*scMax, shift[j]);
2178 }
2179 param[j] += shift[j];
2b1e4f0e 2180 //AZ Check parameter limits 27-12-2004
2181 if (param[j] < parmin[j]) {
2182 shift[j] = parmin[j] - param[j];
2183 param[j] = parmin[j];
2184 } else if (param[j] > parmax[j]) {
2185 shift[j] = parmax[j] - param[j];
2186 param[j] = parmax[j];
2187 }
0df3ca52 2188 //cout << " xxx " << j << " " << shift[j] << " " << param[j] << endl;
2189 stepMax = TMath::Max (stepMax, TMath::Abs(shift[j]/step0[j]));
2190 if (TMath::Abs(deriv[min][j]) > derMax) {
2191 idMax = j;
2192 derMax = TMath::Abs (deriv[min][j]);
2193 }
2194 } // for (Int_t j=0; j<fNpar;
2195 //cout << max << " " << func2[min] << " " << derMax << " " << stepMax << " " << estim << " " << iestMax << " " << nCall << endl;
2b1e4f0e 2196 if (estim < 1 && derMax < 2 || nLoop > 150) break; // minimum was found
0df3ca52 2197
2198 nLoop++;
2199 // Check for small step
2200 if (shift[idMax] == 0) { shift[idMax] = step0[idMax]/10; param[idMax] += shift[idMax]; continue; }
2201 if (!memory[idMax] && derMax > 0.5 && nLoop > 10) {
2202 //cout << " ok " << deriv[min][idMax] << " " << deriv[!min][idMax] << " " << dder[idMax]*shift[idMax] << " " << shift[idMax] << endl;
2203 if (dder[idMax] != 0 && TMath::Abs(deriv[min][idMax]/dder[idMax]/shift[idMax]) > 10) {
2204 if (min == max) dder[idMax] = -dder[idMax];
2205 shift[idMax] = -deriv[min][idMax] / dder[idMax] / 10;
2206 param[idMax] += shift[idMax];
2207 stepMax = TMath::Max (stepMax, TMath::Abs(shift[idMax])/step0[idMax]);
2208 //cout << shift[idMax] << " " << param[idMax] << endl;
2209 if (min == max) shiftSave = shift[idMax];
2210 }
2211 if (nFail > 10) {
2212 param[idMax] -= shift[idMax];
2213 shift[idMax] = 4 * shiftSave * (gRandom->Rndm(0) - 0.5);
2214 param[idMax] += shift[idMax];
2215 //cout << shift[idMax] << endl;
2216 }
2217 }
2218 } // while (1)
2219 fmin = func2[min];
2220
2b1e4f0e 2221 nDof = npads - fNpar + nVirtual;
2222 if (!nDof) nDof++;
2223 chi2n = fmin / nDof;
2224 if (fDebug) cout << " Chi2 " << chi2n << " " << fNpar << endl;
0df3ca52 2225
2226 if (chi2n*1.2+1.e-6 > chi2o ) { fNpar -= 3; break; }
2b1e4f0e 2227
0df3ca52 2228 // Save parameters and errors
2b1e4f0e 2229
0627f609 2230 if (nInX == 1) {
2b1e4f0e 2231 // One pad per direction
2b1e4f0e 2232 for (Int_t i=0; i<fNpar; i++) if (i == 0 || i == 2 || i == 5) param0[min][i] = xPad;
2233 }
0627f609 2234 if (nInY == 1) {
2b1e4f0e 2235 // One pad per direction
2b1e4f0e 2236 for (Int_t i=0; i<fNpar; i++) if (i == 1 || i == 3 || i == 6) param0[min][i] = yPad;
2237 }
2238
2239 /*
2240 if (iseed > 0) {
2241 // Find distance to the nearest neighbour
2242 dist[0] = dist[1] = TMath::Sqrt ((param0[min][0]-param0[min][2])*
2243 (param0[min][0]-param0[min][2])
2244 +(param0[min][1]-param0[min][3])*
2245 (param0[min][1]-param0[min][3]));
2246 if (iseed > 1) {
2247 dist[2] = TMath::Sqrt ((param0[min][0]-param0[min][5])*
2248 (param0[min][0]-param0[min][5])
2249 +(param0[min][1]-param0[min][6])*
2250 (param0[min][1]-param0[min][6]));
2251 rad = TMath::Sqrt ((param0[min][2]-param0[min][5])*
2252 (param0[min][2]-param0[min][5])
2253 +(param0[min][3]-param0[min][6])*
2254 (param0[min][3]-param0[min][6]));
2255 if (dist[2] < dist[0]) dist[0] = dist[2];
2256 if (rad < dist[1]) dist[1] = rad;
2257 if (rad < dist[2]) dist[2] = rad;
2258 }
2259 cout << dist[0] << " " << dist[1] << " " << dist[2] << endl;
2260 if (dist[TMath::LocMin(iseed+1,dist)] < 1.) { fNpar -= 3; break; }
2261 }
2262 */
2263
0df3ca52 2264 for (Int_t i=0; i<fNpar; i++) {
2265 parOk[i] = param0[min][i];
0627f609 2266 //errOk[i] = fmin;
2267 errOk[i] = chi2n;
2b1e4f0e 2268 // Bounded params
2269 parOk[i] = TMath::Max (parOk[i], parmin[i]);
2270 parOk[i] = TMath::Min (parOk[i], parmax[i]);
0df3ca52 2271 }
2272
0df3ca52 2273 chi2o = chi2n;
2274 if (fmin < 0.1) break; // !!!???
2275 } // for (Int_t iseed=0;
2276
2b1e4f0e 2277 if (fDebug) {
2278 for (Int_t i=0; i<fNpar; i++) {
2b1e4f0e 2279 if (i == 4 || i == 7) {
2280 if (i == 7 || i == 4 && fNpar < 7) cout << parOk[i] << endl;
2281 else cout << parOk[i] * (1-parOk[7]) << endl;
2282 continue;
2283 }
2284 cout << parOk[i] << " " << errOk[i] << endl;
2285 }
0df3ca52 2286 }
2287 nfit = (fNpar + 1) / 3;
2b1e4f0e 2288 dist[0] = dist[1] = dist[2] = 0;
2289
2290 if (nfit > 1) {
2291 // Find distance to the nearest neighbour
2292 dist[0] = dist[1] = TMath::Sqrt ((parOk[0]-parOk[2])*
2293 (parOk[0]-parOk[2])
2294 +(parOk[1]-parOk[3])*
2295 (parOk[1]-parOk[3]));
2296 if (nfit > 2) {
2297 dist[2] = TMath::Sqrt ((parOk[0]-parOk[5])*
2298 (parOk[0]-parOk[5])
2299 +(parOk[1]-parOk[6])*
2300 (parOk[1]-parOk[6]));
2301 rad = TMath::Sqrt ((parOk[2]-parOk[5])*
2302 (parOk[2]-parOk[5])
2303 +(parOk[3]-parOk[6])*
2304 (parOk[3]-parOk[6]));
2305 if (dist[2] < dist[0]) dist[0] = dist[2];
2306 if (rad < dist[1]) dist[1] = rad;
2307 if (rad < dist[2]) dist[2] = rad;
2308 }
2309 }
2310
1af223d7 2311 Int_t indx;
2b1e4f0e 2312 fnPads[1] -= nVirtual;
45c72492 2313// if (!fDraw) {
cc87ebcd 2314 Double_t coef = 0;
0627f609 2315 if (iSimple) fnCoupled = 0;
cc87ebcd 2316 //for (Int_t j=0; j<nfit; j++) {
2317 for (Int_t j=nfit-1; j>=0; j--) {
2318 indx = j<2 ? j*2 : j*2+1;
2319 if (nfit == 1) coef = 1;
2320 else coef = j==nfit-1 ? parOk[indx+2] : 1-coef;
2321 coef = TMath::Max (coef, 0.);
2322 if (nfit == 3 && j < 2) coef = j==1 ? coef*parOk[indx+2] : coef - parOk[7];
2323 coef = TMath::Max (coef, 0.);
0627f609 2324 AddRawCluster (parOk[indx], parOk[indx+1], coef*fQtot, errOk[indx], nfit0+10*nfit+100*nMax+10000*fnCoupled, tracks,
cc87ebcd 2325 //sigCand[maxSeed[j]][0], sigCand[maxSeed[j]][1]);
2326 //sigCand[0][0], sigCand[0][1], dist[j]);
2327 sigCand[0][0], sigCand[0][1], dist[TMath::LocMin(nfit,dist)]);
2328 }
45c72492 2329// } else fDraw->FillMuon(nfit, parOk, errOk);
0df3ca52 2330 return nfit;
2331}
2332
2333//_____________________________________________________________________________
30178c30 2334void AliMUONClusterFinderAZ::Fcn1(Int_t & /*npar*/, Double_t * /*gin*/, Double_t &f, Double_t *par, Int_t /*iflag*/)
0df3ca52 2335{
d19b6003 2336/// Fit for one track
2337/// AZ for Muinuit AliMUONClusterFinderAZ& c = *(AliMUONClusterFinderAZ::fgClusterFinder);
2338
2b1e4f0e 2339 AliMUONClusterFinderAZ& c = *this; //AZ
0df3ca52 2340
2341 Int_t cath, ix, iy, indx, npads=0;
2b1e4f0e 2342 Double_t charge, delta, coef=0, chi2=0, qTot = 0;
0df3ca52 2343 for (Int_t j=0; j<c.fnPads[0]+c.fnPads[1]; j++) {
2344 if (c.fPadIJ[1][j] != 1) continue;
2345 cath = c.fPadIJ[0][j];
2b1e4f0e 2346 if (c.fXyq[3][j] > 0) npads++; // exclude virtual pads
2347 qTot += c.fXyq[2][j];
0627f609 2348 ix = c.fPadIJ[2][j];
2349 iy = c.fPadIJ[3][j];
45c72492 2350// c.fSegmentation[cath]->SetPad(ix, iy);
0df3ca52 2351 charge = 0;
2352 for (Int_t i=c.fNpar/3; i>=0; i--) { // sum over tracks
2353 indx = i<2 ? 2*i : 2*i+1;
45c72492 2354// c.fSegmentation[cath]->SetHit(par[indx], par[indx+1], c.fZpad);
0df3ca52 2355 if (c.fNpar == 2) coef = 1;
2356 else coef = i==c.fNpar/3 ? par[indx+2] : 1-coef;
2b1e4f0e 2357 coef = TMath::Max (coef, 0.);
0df3ca52 2358 if (c.fNpar == 8 && i < 2) coef = i==1 ? coef*par[indx+2] : coef - par[7];
2b1e4f0e 2359 coef = TMath::Max (coef, 0.);
45c72492 2360// charge += fMathieson->IntXY(fDetElemId, fSegmentation[cath])*coef;
2361 charge += ChargeIntegration(par[indx],par[indx+1],
2362 c.fXyq[0][j],c.fXyq[1][j],
aacf0960 2363 TMath::Abs(c.fXyq[3][j]),c.fXyq[4][j]) * coef;
0df3ca52 2364 }
2365 charge *= c.fQtot;
0df3ca52 2366 delta = charge - c.fXyq[2][j];
2b1e4f0e 2367 delta *= delta;
2368 delta /= c.fXyq[2][j];
2369 //if (cath) delta /= 5; // just for test
2370 chi2 += delta;
0df3ca52 2371 } // for (Int_t j=0;
2372 f = chi2;
2b1e4f0e 2373 Double_t qAver = qTot/npads; //(c.fnPads[0]+c.fnPads[1]);
0df3ca52 2374 f = chi2/qAver;
2375}
2376
2377//_____________________________________________________________________________
6aaf81e6 2378void AliMUONClusterFinderAZ::UpdatePads(Int_t /*nfit*/, Double_t *par)
0df3ca52 2379{
d19b6003 2380/// Subtract the fitted charges from pads with strong coupling
0df3ca52 2381
2382 Int_t cath, ix, iy, indx;
2383 Double_t charge, coef=0;
2384 for (Int_t j=0; j<fnPads[0]+fnPads[1]; j++) {
2385 if (fPadIJ[1][j] != -1) continue;
2386 if (fNpar != 0) {
2387 cath = fPadIJ[0][j];
0627f609 2388 ix = fPadIJ[2][j];
2389 iy = fPadIJ[3][j];
45c72492 2390 // fSegmentation[cath]->SetPad(ix, iy);
0df3ca52 2391 charge = 0;
2392 for (Int_t i=fNpar/3; i>=0; i--) { // sum over tracks
45c72492 2393 indx = i<2 ? 2*i : 2*i+1;
2394// fSegmentation[cath]->SetHit(par[indx], par[indx+1], fZpad);
2395 if (fNpar == 2) coef = 1;
2396 else coef = i==fNpar/3 ? par[indx+2] : 1-coef;
2397 coef = TMath::Max (coef, 0.);
2398 if (fNpar == 8 && i < 2) coef = i==1 ? coef*par[indx+2] : coef - par[7];
2399 coef = TMath::Max (coef, 0.);
2400// charge += fMathieson->IntXY(fDetElemId,fSegmentation[cath])*coef;
2401 charge += ChargeIntegration(par[indx],par[indx+1],
2402 fXyq[0][j],fXyq[1][j],
aacf0960 2403 TMath::Abs(fXyq[3][j]),fXyq[4][j]) * coef;
0df3ca52 2404 }
2405 charge *= fQtot;
2406 fXyq[2][j] -= charge;
2407 } // if (fNpar != 0)
0627f609 2408 if (fXyq[2][j] > fgkZeroSuppression) fPadIJ[1][j] = 0; // return pad for further using
0df3ca52 2409 } // for (Int_t j=0;
2410}
2411
2412//_____________________________________________________________________________
d19b6003 2413Bool_t AliMUONClusterFinderAZ::TestTrack(Int_t /*t*/) const
2414{
2415/// Test if track was user selected
2416
0df3ca52 2417 return kTRUE;
2418 /*
2419 if (fTrack[0]==-1 || fTrack[1]==-1) {
2420 return kTRUE;
2421 } else if (t==fTrack[0] || t==fTrack[1]) {
2422 return kTRUE;
2423 } else {
2424 return kFALSE;
2425 }
2426 */
2427}
2428
2429//_____________________________________________________________________________
45c72492 2430void AliMUONClusterFinderAZ::AddRawCluster(Double_t x, Double_t y,
2431 Double_t qTot,
2432 Double_t /*fmin*/, Int_t /*nfit*/,
2433 Int_t* /*tracks*/,
2434 Double_t /*sigx*/, Double_t /*sigy*/,
2435 Double_t /*dist*/)
0df3ca52 2436{
d19b6003 2437/// Add a raw cluster copy to the list
2438
2b1e4f0e 2439 if (qTot <= 0.501) return;
2b1e4f0e 2440
45c72492 2441// Int_t cath, npads[2] = {0}, nover[2] = {0};
2442// for (Int_t j=0; j<fnPads[0]+fnPads[1]; j++)
2443// {
2444// cath = fPadIJ[0][j];
2445// // There was an overflow
2446// if (fPadIJ[1][j] == -9) nover[cath]++;
2447// if (fPadIJ[1][j] != 1 && fPadIJ[1][j] != -9) continue;
2448// cnew.SetMultiplicity(cath,cnew.GetMultiplicity(cath)+1);
2449// if (fXyq[2][j] > cnew.GetPeakSignal(cath)) cnew.SetPeakSignal(cath,fXyq[2][j]);
2450// //cnew.SetCharge(cath,cnew.GetCharge(cath) + TMath::Nint (fXyq[2][j]));
2451// cnew.SetContrib(npads[cath],cath,fXyq[2][j]);
2452// cnew.SetIndex(npads[cath],cath,TMath::Nint (fXyq[5][j]));
2453// cnew.SetDetElemId(fDetElemId);
2454// npads[cath]++;
2455// }
2456
2457// cnew.SetClusterType(nover[0] + nover[1] * 100);
2458// for (Int_t j=0; j<3; j++) cnew.SetTrack(j,tracks[j]);
2459
2460// Double_t xg, yg, zg;
2461// for (cath=0; cath<2; cath++)
2462// {
2463// // Perform local-to-global transformation
2464// cnew.SetX(cath, xg);
2465// cnew.SetY(cath, yg);
2466// cnew.SetZ(cath, zg);
2467// cnew.SetCharge(cath, TMath::Nint(qTot));
2468// //cnew.SetPeakSignal(cath,20);
2469// //cnew.SetMultiplicity(cath, 5);
2470// cnew.SetNcluster(cath, nfit);
2471// cnew.SetChi2(cath, fmin); //0.;1
2472// }
2b1e4f0e 2473 // Evaluate measurement errors
2474 //AZ Errors(&cnew);
45c72492 2475
2476 AliMUONCluster cnew;
2477
2478 cnew.SetCharge(qTot,qTot);
2479 cnew.SetPosition(TVector2(x,y),TVector2(0.0,0.0));
2b1e4f0e 2480
45c72492 2481// cnew.SetGhost(nfit); //cnew.SetX(1,sigx); cnew.SetY(1,sigy); cnew.SetZ(1,dist);
0df3ca52 2482 //cnew.fClusterType=cnew.PhysicsContribution();
45c72492 2483 new((*fRawClusters)[fRawClusters->GetLast()+1]) AliMUONCluster(cnew);
2484// if (fDebug) cout << fNRawClusters << " " << fChamberId << endl;
0df3ca52 2485 //fNPeaks++;
2486}
2487
2488//_____________________________________________________________________________
0627f609 2489Int_t AliMUONClusterFinderAZ::FindLocalMaxima(TObjArray *pixArray, Int_t *localMax, Double_t *maxVal)
0df3ca52 2490{
d19b6003 2491/// Find local maxima in pixel space for large preclusters in order to
2492/// try to split them into smaller pieces (to speed up the MLEM procedure)
2493/// or to find additional fitting seeds if clusters were not completely resolved
0df3ca52 2494
0627f609 2495 TH2D *hist = NULL;
2496 //if (pixArray == fPixArray) hist = (TH2D*) gROOT->FindObject("anode");
2497 //else { hist = (TH2D*) gROOT->FindObject("anode1"); cout << hist << endl; }
2498 //if (hist) hist->Delete();
0df3ca52 2499
cd747ddb 2500 Double_t xylim[4] = {999, 999, 999, 999};
0627f609 2501 Int_t nPix = pixArray->GetEntriesFast();
0df3ca52 2502 AliMUONPixel *pixPtr = 0;
2503 for (Int_t ipix=0; ipix<nPix; ipix++) {
0627f609 2504 pixPtr = (AliMUONPixel*) pixArray->UncheckedAt(ipix);
0df3ca52 2505 for (Int_t i=0; i<4; i++)
2506 xylim[i] = TMath::Min (xylim[i], (i%2 ? -1 : 1)*pixPtr->Coord(i/2));
2507 }
2508 for (Int_t i=0; i<4; i++) xylim[i] -= pixPtr->Size(i/2);
2509
2510 Int_t nx = TMath::Nint ((-xylim[1]-xylim[0])/pixPtr->Size(0)/2);
2511 Int_t ny = TMath::Nint ((-xylim[3]-xylim[2])/pixPtr->Size(1)/2);
0627f609 2512 if (pixArray == fPixArray) hist = new TH2D("anode","anode",nx,xylim[0],-xylim[1],ny,xylim[2],-xylim[3]);
2513 else hist = new TH2D("anode1","anode1",nx,xylim[0],-xylim[1],ny,xylim[2],-xylim[3]);
0df3ca52 2514 for (Int_t ipix=0; ipix<nPix; ipix++) {
0627f609 2515 pixPtr = (AliMUONPixel*) pixArray->UncheckedAt(ipix);
0df3ca52 2516 hist->Fill(pixPtr->Coord(0), pixPtr->Coord(1), pixPtr->Charge());
2517 }
45c72492 2518// if (fDraw && pixArray == fPixArray) fDraw->DrawHist("c2", hist);
0df3ca52 2519
2520 Int_t nMax = 0, indx;
2521 Int_t *isLocalMax = new Int_t[ny*nx];
2522 for (Int_t i=0; i<ny*nx; i++) isLocalMax[i] = 0;
2523
2524 for (Int_t i=1; i<=ny; i++) {
2525 indx = (i-1) * nx;
2526 for (Int_t j=1; j<=nx; j++) {
2527 if (hist->GetCellContent(j,i) < 0.5) continue;
2528 //if (isLocalMax[indx+j-1] < 0) continue;
2529 if (isLocalMax[indx+j-1] != 0) continue;
2530 FlagLocalMax(hist, i, j, isLocalMax);
2531 }
2532 }
2533
2534 for (Int_t i=1; i<=ny; i++) {
2535 indx = (i-1) * nx;
2536 for (Int_t j=1; j<=nx; j++) {
2537 if (isLocalMax[indx+j-1] > 0) {
2538 localMax[nMax] = indx + j - 1;
2539 maxVal[nMax++] = hist->GetCellContent(j,i);
2b1e4f0e 2540 if (nMax > 99) AliFatal(" Too many local maxima !!!");
0df3ca52 2541 }
0df3ca52 2542 }
2543 }
2b1e4f0e 2544 if (fDebug) cout << " Local max: " << nMax << endl;
0df3ca52 2545 delete [] isLocalMax; isLocalMax = 0;
2546 return nMax;
2547}
2548
2549//_____________________________________________________________________________
2550void AliMUONClusterFinderAZ::FlagLocalMax(TH2D *hist, Int_t i, Int_t j, Int_t *isLocalMax)
2551{
d19b6003 2552/// Flag pixels (whether or not local maxima)
0df3ca52 2553
2554 Int_t nx = hist->GetNbinsX();
2555 Int_t ny = hist->GetNbinsY();
2556 Int_t cont = TMath::Nint (hist->GetCellContent(j,i));
0627f609 2557 Int_t cont1 = 0, indx = (i-1)*nx+j-1, indx1 = 0, indx2 = 0;
0df3ca52 2558
2559 for (Int_t i1=i-1; i1<i+2; i1++) {
2560 if (i1 < 1 || i1 > ny) continue;
0627f609 2561 indx1 = (i1 - 1) * nx;
0df3ca52 2562 for (Int_t j1=j-1; j1<j+2; j1++) {
2563 if (j1 < 1 || j1 > nx) continue;
2564 if (i == i1 && j == j1) continue;
0627f609 2565 indx2 = indx1 + j1 - 1;
0df3ca52 2566 cont1 = TMath::Nint (hist->GetCellContent(j1,i1));
0627f609 2567 if (cont < cont1) { isLocalMax[indx] = -1; return; }
2568 else if (cont > cont1) isLocalMax[indx2] = -1;
0df3ca52 2569 else { // the same charge
0627f609 2570 isLocalMax[indx] = 1;
2571 if (isLocalMax[indx2] == 0) {
0df3ca52 2572 FlagLocalMax(hist, i1, j1, isLocalMax);
0627f609 2573 if (isLocalMax[indx2] < 0) { isLocalMax[indx] = -1; return; }
2574 else isLocalMax[indx2] = -1;
0df3ca52 2575 }
2576 }
2577 }
2578 }
0627f609 2579 isLocalMax[indx] = 1; // local maximum
0df3ca52 2580}
2581
2582//_____________________________________________________________________________
2583void AliMUONClusterFinderAZ::FindCluster(Int_t *localMax, Int_t iMax)
2584{
13985652 2585/// Find pixel cluster around local maximum \a iMax and pick up pads
d19b6003 2586/// overlapping with it
0df3ca52 2587
2588 TH2D *hist = (TH2D*) gROOT->FindObject("anode");
2589 Int_t nx = hist->GetNbinsX();
2590 Int_t ny = hist->GetNbinsY();
2591 Int_t ic = localMax[iMax] / nx + 1;
2592 Int_t jc = localMax[iMax] % nx + 1;
2593 Bool_t *used = new Bool_t[ny*nx];
2594 for (Int_t i=0; i<ny*nx; i++) used[i] = kFALSE;
2595
2596 // Drop all pixels from the array - pick up only the ones from the cluster
2597 fPixArray->Delete();
2598
2599 Double_t wx = hist->GetXaxis()->GetBinWidth(1)/2;
2600 Double_t wy = hist->GetYaxis()->GetBinWidth(1)/2;
2601 Double_t yc = hist->GetYaxis()->GetBinCenter(ic);
2602 Double_t xc = hist->GetXaxis()->GetBinCenter(jc);
2603 Double_t cont = hist->GetCellContent(jc,ic);
2604 AliMUONPixel *pixPtr = new AliMUONPixel (xc, yc, wx, wy, cont);
2605 fPixArray->Add((TObject*)pixPtr);
2606 used[(ic-1)*nx+jc-1] = kTRUE;
2607 AddBin(hist, ic, jc, 1, used, (TObjArray*)0); // recursive call
2608
2609 Int_t nPix = fPixArray->GetEntriesFast(), npad = fnPads[0] + fnPads[1];
2610 for (Int_t i=0; i<nPix; i++) {
2611 ((AliMUONPixel*)fPixArray->UncheckedAt(i))->SetSize(0,wx);
2612 ((AliMUONPixel*)fPixArray->UncheckedAt(i))->SetSize(1,wy);
2613 }
2b1e4f0e 2614 if (fDebug) cout << iMax << " " << nPix << endl;
0df3ca52 2615
2616 Float_t xy[4], xy12[4];
2617 // Pick up pads which overlap with found pixels
2618 for (Int_t i=0; i<npad; i++) fPadIJ[1][i] = -1;
2619 for (Int_t i=0; i<nPix; i++) {
2620 pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i);
2621 for (Int_t j=0; j<4; j++)
2622 xy[j] = pixPtr->Coord(j/2) + (j%2 ? 1 : -1)*pixPtr->Size(j/2);
2623 for (Int_t j=0; j<npad; j++)
2624 if (Overlap(xy, j, xy12, 0)) fPadIJ[1][j] = 0; // flag for use
2625 }
2626
2627 delete [] used; used = 0;
2628}
30178c30 2629
2b1e4f0e 2630//_____________________________________________________________________________
2631void AliMUONClusterFinderAZ::AddVirtualPad()
2632{
d19b6003 2633/// Add virtual pad (with small charge) to improve fit for some
2634/// clusters (when pad with max charge is at the extreme of the cluster)
2b1e4f0e 2635
2636 // Get number of pads in X and Y-directions
2637 Int_t nInX = -1, nInY;
2638 PadsInXandY(nInX, nInY);
2639 //return;
2640
0627f609 2641 // Add virtual pad only if number of pads per direction == 2
2b1e4f0e 2642 if (nInX != 2 && nInY != 2) return;
2643
2644 // Find pads with max charge
2645 Int_t maxpad[2][2] = {{-1, -1}, {-1, -1}}, cath;
2646 Double_t sigmax[2] = {0}, aamax[2] = {0};
2647 for (Int_t j=0; j<fnPads[0]+fnPads[1]; j++) {
2648 if (fPadIJ[1][j] != 0) continue;
2649 cath = fPadIJ[0][j];
2650 if (fXyq[2][j] > sigmax[cath]) {
2651 maxpad[cath][1] = maxpad[cath][0];
2652 aamax[cath] = sigmax[cath];
2653 sigmax[cath] = fXyq[2][j];
2654 maxpad[cath][0] = j;
2655 }
2656 }
2657 if (maxpad[0][0] >= 0 && maxpad[0][1] < 0 || maxpad[1][0] >= 0 && maxpad[1][1] < 0) {
2658 for (Int_t j=0; j<fnPads[0]+fnPads[1]; j++) {
2659 if (fPadIJ[1][j] != 0) continue;
2660 cath = fPadIJ[0][j];
2661 if (j == maxpad[cath][0] || j == maxpad[cath][1]) continue;
2662 if (fXyq[2][j] > aamax[cath]) {
2663 aamax[cath] = fXyq[2][j];
2664 maxpad[cath][1] = j;
2665 }
2666 }
2667 }
2668 // Check for mirrors (side X on cathode 0)
2669 Bool_t mirror = kFALSE;
0627f609 2670 if (maxpad[0][0] >= 0 && maxpad[1][0] >= 0) {
2b1e4f0e 2671 mirror = fXyq[3][maxpad[0][0]] < fXyq[4][maxpad[0][0]];
0627f609 2672 if (!mirror && TMath::Abs(fXyq[3][maxpad[0][0]]-fXyq[3][maxpad[1][0]]) < 0.001) {
2673 // Special case when pads on both cathodes have the same size
2674 Int_t yud[2] = {0};
2675 for (Int_t j = 0; j < fnPads[0]+fnPads[1]; j++) {
2676 cath = fPadIJ[0][j];
2677 if (j == maxpad[cath][0]) continue;
2678 if (fPadIJ[2][j] != fPadIJ[2][maxpad[cath][0]]) continue;
2679 if (fPadIJ[3][j] + 1 == fPadIJ[3][maxpad[cath][0]] ||
2680 fPadIJ[3][j] - 1 == fPadIJ[3][maxpad[cath][0]]) yud[cath]++;
2681 }
2682 if (!yud[0]) mirror = kTRUE; // take the other cathode
2683 } // if (!mirror &&...
2684 } // if (maxpad[0][0] >= 0 && maxpad[1][0] >= 0)
2b1e4f0e 2685
2686 // Find neughbours of pads with max charges
45c72492 2687 Int_t xList[10], yList[10], ix0, iy0, ix, iy, neighb;
2b1e4f0e 2688 for (cath=0; cath<2; cath++) {
2689 if (!cath && maxpad[0][0] < 0) continue; // one-sided cluster - cathode 1
2690 if (cath && maxpad[1][0] < 0) break; // one-sided cluster - cathode 0
2691 if (maxpad[1][0] >= 0) {
2692 if (!mirror) {
2693 if (!cath && nInY != 2) continue;
2b1e4f0e 2694 if (cath && nInX != 2 && (maxpad[0][0] >= 0 || nInY != 2)) continue;
2695 } else {
2696 if (!cath && nInX != 2) continue;
2697 if (cath && nInY != 2 && (maxpad[0][0] >= 0 || nInX != 2)) continue;
2698 }
2699 }
2700
1af223d7 2701 Int_t iAddX = 0, iAddY = 0, ix1 = 0, iy1 = 0, iPad = 0;
2b1e4f0e 2702 if (maxpad[0][0] < 0) iPad = 1;
2703
2b1e4f0e 2704 for (iPad=0; iPad<2; iPad++) {
94eb555e 2705 if (maxpad[cath][iPad] < 0) continue;
2b1e4f0e 2706 if (iPad && !iAddX && !iAddY) break;
2707 if (iPad && fXyq[2][maxpad[cath][1]] / sigmax[cath] < 0.5) break;
2708
2709 Int_t neighbx = 0, neighby = 0;
0627f609 2710 ix0 = fPadIJ[2][maxpad[cath][iPad]];
2711 iy0 = fPadIJ[3][maxpad[cath][iPad]];
45c72492 2712 TObjArray neighbours;
2713 AliMpPad pad = fSegmentation[cath]->PadByIndices(AliMpIntPair(ix0, iy0));
2714 Int_t nn = fSegmentation[cath]->GetNeighbours(pad,neighbours);
2b1e4f0e 2715 for (Int_t j=0; j<nn; j++) {
45c72492 2716 AliMpPad* pad = static_cast<AliMpPad*>(neighbours.At(j));
aacf0960 2717 xList[j] = pad->GetIndices().GetFirst();
2718 yList[j] = pad->GetIndices().GetSecond();
2719 if (TMath::Abs(xList[j]-ix0) == 1 || xList[j]*ix0 == -1) neighbx++;
2720 if (TMath::Abs(yList[j]-iy0) == 1 || yList[j]*iy0 == -1) neighby++;
2b1e4f0e 2721 }
2722 if (!mirror) {
2723 if (cath) neighb = neighbx;
2724 else neighb = neighby;
2725 if (maxpad[0][0] < 0) neighb += neighby;
2726 else if (maxpad[1][0] < 0) neighb += neighbx;
2727 } else {
2728 if (!cath) neighb = neighbx;
2729 else neighb = neighby;
2730 if (maxpad[0][0] < 0) neighb += neighbx;
2731 else if (maxpad[1][0] < 0) neighb += neighby;
2732 }
2733
2734 for (Int_t j=0; j<fnPads[0]+fnPads[1]; j++) {
2735 if (fPadIJ[0][j] != cath) continue;
0627f609 2736 ix = fPadIJ[2][j];
2737 iy = fPadIJ[3][j];
2b1e4f0e 2738 if (iy == iy0 && ix == ix0) continue;
2739 for (Int_t k=0; k<nn; k++) {
2740 if (xList[k] != ix || yList[k] != iy) continue;
2741 if (!mirror) {
2742 if ((!cath || maxpad[0][0] < 0) &&
1af223d7 2743 (TMath::Abs(iy-iy0) == 1 || iy*iy0 == -1)) {
0627f609 2744 if (!iPad && TMath::Abs(ix-ix0) == 1 || ix*ix0 == -1) ix1 = xList[k]; //19-12-05
2b1e4f0e 2745 xList[k] = yList[k] = 0;
2746 neighb--;
2747 break;
2748 }
2749 if ((cath || maxpad[1][0] < 0) &&
1af223d7 2750 (TMath::Abs(ix-ix0) == 1 || ix*ix0 == -1)) {
0627f609 2751 if (!iPad) ix1 = xList[k]; //19-12-05
2b1e4f0e 2752 xList[k] = yList[k] = 0;
2753 neighb--;
2754 }
2755 } else {
2756 if ((!cath || maxpad[0][0] < 0) &&
1af223d7 2757 (TMath::Abs(ix-ix0) == 1 || ix*ix0 == -1)) {
0627f609 2758 if (!iPad) ix1 = xList[k]; //19-12-05
2b1e4f0e 2759 xList[k] = yList[k] = 0;
2760 neighb--;
2761 break;
2762 }
2763 if ((cath || maxpad[1][0] < 0) &&
1af223d7 2764 (TMath::Abs(iy-iy0) == 1 || iy*iy0 == -1)) {
2b1e4f0e 2765 xList[k] = yList[k] = 0;
2766 neighb--;
2767 }
2768 }
2769 break;
2770 } // for (Int_t k=0; k<nn;
2771 if (!neighb) break;
2772 } // for (Int_t j=0; j<fnPads[0]+fnPads[1];
2773 if (!neighb) continue;
2774
2775 // Add virtual pad
2776 Int_t npads, isec;
2777 isec = 0;
2778 for (Int_t j=0; j<nn; j++) {
2779 if (xList[j] == 0 && yList[j] == 0) continue;
2780 npads = fnPads[0] + fnPads[1];
2781 fPadIJ[0][npads] = cath;
2782 fPadIJ[1][npads] = 0;
2783 ix = xList[j];
2784 iy = yList[j];
1af223d7 2785 if (TMath::Abs(ix-ix0) == 1 || ix*ix0 == -1) {
2b1e4f0e 2786 if (iy != iy0) continue; // new segmentation - check
2787 if (nInX != 2) continue; // new
2788 if (!mirror) {
2789 if (!cath && maxpad[1][0] >= 0) continue;
2b1e4f0e 2790 } else {
2791 if (cath && maxpad[0][0] >= 0) continue;
2b1e4f0e 2792 }
2793 if (iPad && !iAddX) continue;
aacf0960 2794 AliMpPad pad = fSegmentation[cath]->PadByIndices(AliMpIntPair(ix,iy));
2795 fXyq[0][npads] = pad.Position().X();
2796 fXyq[1][npads] = pad.Position().Y();
1af223d7 2797 if (fXyq[0][npads] > 1.e+5) continue; // temporary fix
0627f609 2798 if (ix == ix1) continue; //19-12-05
2b1e4f0e 2799 if (ix1 == ix0) continue;
2b1e4f0e 2800 if (maxpad[1][0] < 0 || mirror && maxpad[0][0] >= 0) {
2801 if (!iPad) fXyq[2][npads] = TMath::Min (sigmax[0]/100, 5.);
2802 else fXyq[2][npads] = TMath::Min (aamax[0]/100, 5.);
2803 }
2804 else {
2805 if (!iPad) fXyq[2][npads] = TMath::Min (sigmax[1]/100, 5.);
2806 else fXyq[2][npads] = TMath::Min (aamax[1]/100, 5.);
2807 }
2808 fXyq[2][npads] = TMath::Max (fXyq[2][npads], (float)1);
aacf0960 2809 fXyq[3][npads] = -pad.Dimensions().X(); // "-" to flag
2810 fXyq[4][npads] = pad.Dimensions().Y();
0627f609 2811 fPadIJ[2][npads] = ix;
2812 fPadIJ[3][npads] = iy;
2b1e4f0e 2813 fnPads[1]++;
2814 iAddX = npads;
0627f609 2815 if (fDebug) printf(" ***** Add virtual pad in X ***** %f %f %f %3d %3d \n", fXyq[2][npads],
e8fb921b 2816 fXyq[0][npads], fXyq[1][npads], ix, iy);
2b1e4f0e 2817 ix1 = ix0;
2818 continue;
2819 }
2820 if (nInY != 2) continue;
2821 if (!mirror && cath && maxpad[0][0] >= 0) continue;
2822 if (mirror && !cath && maxpad[1][0] >= 0) continue;
2823 if (TMath::Abs(iy-iy0) == 1 || TMath::Abs(iy*iy0) == 1) {
2824 if (ix != ix0) continue; // new segmentation - check
2825 if (iPad && !iAddY) continue;
aacf0960 2826 AliMpPad pad = fSegmentation[cath]->PadByIndices(AliMpIntPair(ix,iy));
2827 fXyq[0][npads] = pad.Position().X();
2828 fXyq[1][npads] = pad.Position().Y();
2b1e4f0e 2829 if (iy1 == iy0) continue;
2830 //if (iPad && iy1 == iy0) continue;
2b1e4f0e 2831 if (maxpad[0][0] < 0 || mirror && maxpad[1][0] >= 0) {
0627f609 2832 if (!iPad) fXyq[2][npads] = TMath::Min (sigmax[1]/15, fgkZeroSuppression);
2833 else fXyq[2][npads] = TMath::Min (aamax[1]/15, fgkZeroSuppression);
2b1e4f0e 2834 }
2835 else {
0627f609 2836 if (!iPad) fXyq[2][npads] = TMath::Min (sigmax[0]/15, fgkZeroSuppression);
2837 else fXyq[2][npads] = TMath::Min (aamax[0]/15, fgkZeroSuppression);
2b1e4f0e 2838 }
2839 fXyq[2][npads] = TMath::Max (fXyq[2][npads], (float)1);
aacf0960 2840 fXyq[3][npads] = -pad.Dimensions().X(); // "-" to flag
2841 fXyq[4][npads] = pad.Dimensions().Y();
0627f609 2842 fPadIJ[2][npads] = ix;
2843 fPadIJ[3][npads] = iy;
2b1e4f0e 2844 fnPads[1]++;
2845 iAddY = npads;
0627f609 2846 if (fDebug) printf(" ***** Add virtual pad in Y ***** %f %f %f %3d %3d \n", fXyq[2][npads],
e8fb921b 2847 fXyq[0][npads], fXyq[1][npads], ix, iy);
2b1e4f0e 2848 iy1 = iy0;
2849 }
2850 } // for (Int_t j=0; j<nn;
2851 } // for (Int_t iPad=0;
2852 } // for (cath=0; cath<2;
2853 return;
2854}
2855
2856//_____________________________________________________________________________
2857void AliMUONClusterFinderAZ::PadsInXandY(Int_t &nInX, Int_t &nInY)
2858{
d19b6003 2859/// Find number of pads in X and Y-directions (excluding virtual ones and
2860/// overflows)
2b1e4f0e 2861
2862 static Int_t nXsaved = 0, nYsaved = 0;
2863 nXsaved = nYsaved = 0;
2864 //if (nInX >= 0) {nInX = nXsaved; nInY = nYsaved; return; }
5a051e34 2865 Float_t *xPad0 = NULL, *yPad0 = NULL, *xPad1 = NULL, *yPad1 = NULL;
1af223d7 2866 Float_t wMinX[2] = {99, 99}, wMinY[2] = {99, 99};
5a051e34 2867 Int_t *nPad0 = NULL, *nPad1 = NULL;
2868 Int_t nPads = fnPads[0] + fnPads[1];
2869 if (fnPads[0]) {
2870 xPad0 = new Float_t[nPads];
2871 yPad0 = new Float_t[nPads];
2872 nPad0 = new Int_t[nPads];
2873 }
2874 if (fnPads[1]) {
2875 xPad1 = new Float_t[nPads];
2876 yPad1 = new Float_t[nPads];
2877 nPad1 = new Int_t[nPads];
2878 }
2879 Int_t n0 = 0, n1 = 0, cath, npadx[2] = {1, 1}, npady[2] = {1, 1};
2880 for (Int_t j = 0; j < nPads; j++) {
2b1e4f0e 2881 if (nInX < 0 && fPadIJ[1][j] != 0) continue; // before fit
2882 else if (nInX == 0 && fPadIJ[1][j] != 1) continue; // fit - exclude overflows
2883 else if (nInX > 0 && fPadIJ[1][j] != 1 && fPadIJ[1][j] != -9) continue; // exclude non-marked
0627f609 2884 if (nInX <= 0 && fXyq[2][j] > fgkSaturation-1) continue; // skip overflows
2b1e4f0e 2885 cath = fPadIJ[0][j];
1af223d7 2886 if (fXyq[3][j] > 0) { // exclude virtual pads
2887 wMinX[cath] = TMath::Min (wMinX[cath], fXyq[3][j]);
2888 wMinY[cath] = TMath::Min (wMinY[cath], fXyq[4][j]);
0627f609 2889 //20-12-05 }
2890 if (cath) { xPad1[n1] = fXyq[0][j]; yPad1[n1++] = fXyq[1][j]; }
2891 else { xPad0[n0] = fXyq[0][j]; yPad0[n0++] = fXyq[1][j]; }
1af223d7 2892 }
2b1e4f0e 2893 }
5a051e34 2894
2895 // Sort
2896 if (n0) {
2897 TMath::Sort (n0, xPad0, nPad0); // in X
2898 for (Int_t i = 1; i < n0; i++)
2899 if (xPad0[nPad0[i]] - xPad0[nPad0[i-1]] < -0.01) npadx[0]++;
2900 TMath::Sort (n0, yPad0, nPad0); // in Y
2901 for (Int_t i = 1; i < n0; i++)
2902 if (yPad0[nPad0[i]] - yPad0[nPad0[i-1]] < -0.01) npady[0]++;
2903 }
2904
2905 if (n1) {
2906 TMath::Sort (n1, xPad1, nPad1); // in X
2907 for (Int_t i = 1; i < n1; i++)
2908 if (xPad1[nPad1[i]] - xPad1[nPad1[i-1]] < -0.01) npadx[1]++;
2909 TMath::Sort (n1, yPad1, nPad1); // in Y
2910 for (Int_t i = 1; i < n1; i++)
2911 if (yPad1[nPad1[i]] - yPad1[nPad1[i-1]] < -0.01) npady[1]++;
2912 }
2913 if (fnPads[0]) { delete [] xPad0; delete [] yPad0; delete [] nPad0; }
2914 if (fnPads[1]) { delete [] xPad1; delete [] yPad1; delete [] nPad1; }
cc87ebcd 2915 if (TMath::Abs (wMinY[0] - wMinY[1]) < 1.e-3) nInY = TMath::Max (npady[0], npady[1]);
2916 else nInY = wMinY[0] < wMinY[1] ? npady[0] : npady[1];
2917 if (TMath::Abs (wMinX[0] - wMinX[1]) < 1.e-3) nInX = TMath::Max (npadx[0], npadx[1]);
2918 else nInX = wMinX[0] < wMinX[1] ? npadx[0] : npadx[1];
2b1e4f0e 2919}
2920
2921//_____________________________________________________________________________
2922void AliMUONClusterFinderAZ::Simple()
2923{
d19b6003 2924/// Process simple cluster (small number of pads) without EM-procedure
2b1e4f0e 2925
ff7af159 2926 Int_t nForFit = 1, clustFit[1] = {0}, nfit;
2b1e4f0e 2927 Double_t parOk[3] = {0.};
2928 TObjArray *clusters[1];
ff7af159 2929 clusters[0] = fPixArray;
5a051e34 2930 for (Int_t i = 0; i < fnPads[0]+fnPads[1]; i++) {
0627f609 2931 if (fXyq[2][i] > fgkSaturation-1) fPadIJ[1][i] = -9;
5a051e34 2932 else fPadIJ[1][i] = 1;
2933 }
0627f609 2934 nfit = Fit(1, nForFit, clustFit, clusters, parOk);
2b1e4f0e 2935}
2936
2937//_____________________________________________________________________________
45c72492 2938void AliMUONClusterFinderAZ::Errors(AliMUONRawCluster* /*clus*/)
2b1e4f0e 2939{
d19b6003 2940/// Correct reconstructed coordinates for some clusters and evaluate errors
2b1e4f0e 2941
45c72492 2942 AliWarning("Reimplement me!");
2943
2944// Double_t qTot = clus->GetCharge(0), fmin = clus->GetChi2(0);
2945// Double_t xreco = clus->GetX(0), yreco = clus->GetY(0), zreco = clus->GetZ(0);
2946// Double_t sigmax[2] = {0};
2947//
2948// Int_t nInX = 1, nInY, maxdig[2] ={-1, -1}, digit, cath1, isec;
2949// PadsInXandY(nInX, nInY);
2950//
2951// // Find pad with maximum signal
2952// for (Int_t cath = 0; cath < 2; cath++) {
2953// for (Int_t j = 0; j < clus->GetMultiplicity(cath); j++) {
2954// cath1 = cath;
2955// digit = clus->GetIndex(j, cath);
2956// if (digit < 0) { cath1 = TMath::Even(cath); digit = -digit - 1; } // from the other cathode
2957//
2958// if (clus->GetContrib(j,cath) > sigmax[cath1]) {
2959// sigmax[cath1] = clus->GetContrib(j,cath);
2960// maxdig[cath1] = digit;
2961// }
2962// }
2963// }
2964//
2965// // Size of pad with maximum signal and reco coordinate distance from the pad center
2966// AliMUONVDigit *mdig = 0;
2967// Double_t wx[2], wy[2], dxc[2], dyc[2];
2968// Float_t xpad, ypad, zpad;
2969// Int_t ix, iy;
2970// for (Int_t cath = 0; cath < 2; cath++) {
2971// if (maxdig[cath] < 0) continue;
2972// mdig = fDigitStore->Find(maxdig[cath]);
2973// isec = fSegmentation[cath]->Sector(mdig->PadX(), mdig->PadY());
2974// wx[cath] = fSegmentation[cath]->Dpx(isec);
2975// wy[cath] = fSegmentation[cath]->Dpy(isec);
2976// fSegmentation[cath]->GetPadI(xreco, yreco, zreco, ix, iy);
2977// isec = fSegmentation[cath]->Sector(ix, iy);
2978// if (isec > 0) {
2979// fSegmentation[cath]->GetPadC(ix, iy, xpad, ypad, zpad);
2980// dxc[cath] = xreco - xpad;
2981// dyc[cath] = yreco - ypad;
2982// }
2983// }
2984//
2985// // Check if pad with max charge at the edge (number of neughbours)
2986// Int_t nn, xList[10], yList[10], neighbx[2][2] = {{0,0}, {0,0}}, neighby[2][2]= {{0,0}, {0,0}};
2987// for (Int_t cath = 0; cath < 2; cath++) {
2988// if (maxdig[cath] < 0) continue;
2989// mdig = fDigitStore->FindObject(maxdig[cath]);
2990// fSegmentation[cath]->Neighbours(mdig->PadX(), mdig->PadY(), &nn, xList, yList);
2991// isec = fSegmentation[cath]->Sector(mdig->PadX(), mdig->PadY());
2992// for (Int_t j=0; j<nn; j++) {
2993// fSegmentation[cath]->GetPadC(xList[j], yList[j], xpad, ypad, zpad);
2994// if (TMath::Abs(xpad) < 1 && TMath::Abs(ypad) < 1) continue;
2995// if (xList[j] == mdig->PadX()-1 || mdig->PadX() == 1 &&
2996// xList[j] == -1) neighbx[cath][0] = 1;
2997// else if (xList[j] == mdig->PadX()+1 || mdig->PadX() == -1 &&
2998// xList[j] == 1) neighbx[cath][1] = 1;
2999// if (yList[j] == mdig->PadY()-1 || mdig->PadY() == 1 &&
3000// yList[j] == -1) neighby[cath][0] = 1;
3001// else if (yList[j] == mdig->PadY()+1 || mdig->PadY() == -1 &&
3002// yList[j] == 1) neighby[cath][1] = 1;
3003// } // for (Int_t j=0; j<nn;
3004// if (neighbx[cath][0] && neighbx[cath][1]) neighbx[cath][0] = 0;
3005// else if (neighbx[cath][1]) neighbx[cath][0] = -1;
3006// else neighbx[cath][0] = 1;
3007// if (neighby[cath][0] && neighby[cath][1]) neighby[cath][0] = 0;
3008// else if (neighby[cath][1]) neighby[cath][0] = -1;
3009// else neighby[cath][0] = 1;
3010// }
3011//
3012// Int_t iOver = clus->GetClusterType();
3013// // One-sided cluster
3014// if (!clus->GetMultiplicity(0)) {
3015// neighby[0][0] = neighby[1][0];
3016// wy[0] = wy[1];
3017// if (iOver < 99) iOver += 100 * iOver;
3018// dyc[0] = dyc[1];
3019// } else if (!clus->GetMultiplicity(1)) {
3020// neighbx[1][0] = neighbx[0][0];
3021// wx[1] = wx[0];
3022// if (iOver < 99) iOver += 100 * iOver;
3023// dxc[1] = dxc[0];
3024// }
3025//
3026// // Apply corrections and evaluate errors
3027// Double_t errY, errX;
3028// Errors(nInY, nInX, neighby[0][0],neighbx[1][0], fmin, wy[0]*10, wx[1]*10, iOver,
3029// dyc[0], dxc[1], qTot, yreco, xreco, errY, errX);
3030// errY = TMath::Max (errY, 0.01);
3031// //errY = 0.01;
3032// //errX = TMath::Max (errX, 0.144);
3033// clus->SetX(0, xreco); clus->SetY(0, yreco);
3034// clus->SetErrX(errX); clus->SetErrY(errY);
2b1e4f0e 3035}
3036
3037//_____________________________________________________________________________
3038void AliMUONClusterFinderAZ::Errors(Int_t ny, Int_t nx, Int_t iby, Int_t ibx, Double_t fmin,
3039 Double_t wy, Double_t wx, Int_t iover,
3040 Double_t dyc, Double_t /*dxc*/, Double_t qtot,
3041 Double_t &yrec, Double_t &xrec, Double_t &erry, Double_t &errx)
3042{
d19b6003 3043/// Correct reconstructed coordinates for some clusters and evaluate errors
2b1e4f0e 3044
3045 erry = 0.01;
3046 errx = 0.144;
3047 Int_t iovery = iover % 100;
3048 Double_t corr = 0;
3049
3050/* ---> Ny = 1 */
3051 if (ny == 1) {
3052 if (iby != 0) {
3053 // edge effect
3054 yrec += iby * (0.1823+0.2008)/2;
3055 erry = 0.04587;
3056 } else {
3057 // Find "effective pad width"
3058 Double_t width = 0.218 / (1.31e-4 * TMath::Exp (2.688 * TMath::Log(qtot)) + 1) * 2;
3059 width = TMath::Min (width, 0.4);
3060 erry = width / TMath::Sqrt(12.);
3061 erry = TMath::Max (erry, 0.01293);
3062 }
3063 goto x; //return;
3064 }
3065
3066/* ---> "Bad" fit */
3067 if (fmin > 0.4) {
3068 erry = 0.1556;
3069 if (ny == 5) erry = 0.06481;
3070 goto x; //return;
3071 }
3072
3073/* ---> By != 0 */
3074 if (iby != 0) {
3075 if (ny > 2) {
3076 erry = 0.00417; //0.01010
3077 } else {
3078 // ny = 2
3079 if (dyc * iby > -0.05) {
3080 Double_t dyc2 = dyc * dyc;
3081 if (iby < 0) {
3082 corr = 0.019 - 0.602 * dyc + 8.739 * dyc2 - 44.209 * dyc2 * dyc;
3083 corr = TMath::Min (corr, TMath::Abs(-0.25-dyc));
3084 yrec -= corr;
3085 //dyc -= corr;
3086 erry = 0.00814;
3087 } else {
3088 corr = 0.006 + 0.300 * dyc + 6.147 * dyc2 + 42.039 * dyc2 * dyc;
3089 corr = TMath::Min (corr, 0.25-dyc);
3090 yrec += corr;
3091 //dyc += corr;
3092 erry = 0.01582;
3093 }
3094 } else {
3095 erry = (0.00303 + 0.00296) / 2;
3096 }
3097 }
3098 goto x; //return;
3099 }
3100
3101/* ---> Overflows */
3102 if (iovery != 0) {
3103 if (qtot < 3000) {
3104 erry = 0.0671;
3105 } else {
3106 if (iovery > 1) {
3107 erry = 0.09214;
3108 } else if (TMath::Abs(wy - 5) < 0.1) {
3109 erry = 0.061; //0.06622
3110 } else {
3111 erry = 0.00812; // 0.01073
3112 }
3113 }
3114 goto x; //return;
3115 }
3116
3117/* ---> "Good" but very high signal */
3118 if (qtot > 4000) {
3119 if (TMath::Abs(wy - 4) < 0.1) {
3120 erry = 0.00117;
3121 } else if (fmin < 0.03 && qtot < 6000) {
3122 erry = 0.01003;
3123 } else {
3124 erry = 0.1931;
3125 }
3126 goto x; //return;
3127 }
3128
3129/* ---> "Good" clusters */
3130 if (ny > 3) {
3131 if (TMath::Abs(wy - 5) < 0.1) {
3132 erry = 0.0011; //0.00304
3133 } else if (qtot < 400.) {
3134 erry = 0.0165;
3135 } else {
3136 erry = 0.00135; // 0.00358
3137 }
3138 } else if (ny == 3) {
3139 if (TMath::Abs(wy - 4) < 0.1) {
3140 erry = 35.407 / (1 + TMath::Exp(5.511*TMath::Log(qtot/265.51))) + 11.564;
3141 //erry = 83.512 / (1 + TMath::Exp(3.344*TMath::Log(qtot/211.58))) + 12.260;
3142 } else {
3143 erry = 147.03 / (1 + TMath::Exp(1.713*TMath::Log(qtot/73.151))) + 9.575;
3144 //erry = 91.743 / (1 + TMath::Exp(2.332*TMath::Log(qtot/151.67))) + 11.453;
3145 }
3146 erry *= 1.e-4;
3147 } else {
3148 // ny = 2
3149 if (TMath::Abs(wy - 4) < 0.1) {
3150 erry = 60.800 / (1 + TMath::Exp(3.305*TMath::Log(qtot/104.53))) + 11.702;
3151 //erry = 73.128 / (1 + TMath::Exp(5.676*TMath::Log(qtot/120.93))) + 17.839;
3152 } else {
3153 erry = 117.98 / (1 + TMath::Exp(2.005*TMath::Log(qtot/37.649))) + 21.431;
3154 //erry = 99.066 / (1 + TMath::Exp(4.900*TMath::Log(qtot/107.57))) + 25.315;
3155 }
3156 erry *= 1.e-4;
3157 }
3158 //return;
3159
3160 x:
3161/* ---> X-coordinate */
3162/* ---> Y-side */
3163 if (wx > 11) {
3164 errx = 0.0036;
3165 xrec -= 0.1385;
3166 return;
3167 }
3168/* ---> Nx = 1 */
3169 if (nx == 1) {
3170 if (TMath::Abs(wx - 6) < 0.1) {
3171 if (qtot < 40) errx = 0.1693;
3172 else errx = 0.06241;
3173 } else if (TMath::Abs(wx - 7.5) < 0.1) {
3174 if (qtot < 40) errx = 0.2173;
3175 else errx = 0.07703;
3176 } else if (TMath::Abs(wx - 10) < 0.1) {
3177 if (ibx == 0) {
3178 if (qtot < 40) errx = 0.2316;
3179 else errx = 0.1426;
3180 } else {
3181 xrec += (0.2115 + 0.1942) / 2 * ibx;
3182 errx = 0.1921;
3183 }
3184 }
3185 return;
3186 }
3187/* ---> "Bad" fit */
3188 if (fmin > 0.5) {
3189 errx = 0.1591;
3190 return;
3191 }
3192/* ---> Bx != 0 */
3193 if (ibx != 0) {
3194 if (ibx > 0) { errx = 0.06761; xrec -= 0.03832; }
3195 else { errx = 0.06653; xrec += 0.02581; }
3196 return;
3197 }
3198/* ---> Overflows */
3199 if (iover != 0) {
3200 if (TMath::Abs(wx - 6) < 0.1) errx = 0.06979;
3201 else if (TMath::Abs(wx - 7.5) < 0.1) errx = 0.1089;
3202 else if (TMath::Abs(wx - 10) < 0.1) errx = 0.09847;
3203 return;
3204 }
3205/* ---> Good */
3206 if (TMath::Abs(wx - 6) < 0.1) errx = 0.06022;
3207 else if (TMath::Abs(wx - 7.5) < 0.1) errx = 0.07247;
3208 else if (TMath::Abs(wx - 10) < 0.1) errx = 0.07359;
3209}
3210
45c72492 3211//___________________________________________________________________________
3212void AliMUONClusterFinderAZ::ResetRawClusters()
3213{
3214 /// Reset tracks information
3215 if (fRawClusters) fRawClusters->Clear("C");
3216}