1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
21 #include <Riostream.h>
23 #include "AliMUONClusterFinderVS.h"
24 #include "AliMUONDigit.h"
25 #include "AliMUONRawCluster.h"
26 #include "AliSegmentation.h"
27 #include "AliMUONGeometrySegmentation.h"
28 #include "AliMUONMathieson.h"
29 #include "AliMUONClusterInput.h"
30 #include "AliMUONHitMapA1.h"
33 //_____________________________________________________________________
34 // This function is minimized in the double-Mathieson fit
35 void fcnS2(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag);
36 void fcnS1(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag);
37 void fcnCombiS1(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag);
38 void fcnCombiS2(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag);
40 ClassImp(AliMUONClusterFinderVS)
42 AliMUONClusterFinderVS::AliMUONClusterFinderVS()
45 // Default constructor
46 fInput=AliMUONClusterInput::Instance();
47 // cout << " TYPE" << fSegmentationType << endl;
50 fTrack[0]=fTrack[1]=-1;
51 fDebugLevel = 0; // make silent default
52 fGhostChi2Cut = 1e6; // nothing done by default
58 for(Int_t i=0; i<100; i++) {
59 for (Int_t j=0; j<2; j++) {
63 fRawClusters = new TClonesArray("AliMUONRawCluster",1000);
66 //____________________________________________________________________________
67 AliMUONClusterFinderVS::~AliMUONClusterFinderVS()
69 // Reset tracks information
72 fRawClusters->Delete();
77 AliMUONClusterFinderVS::AliMUONClusterFinderVS(const AliMUONClusterFinderVS & clusterFinder):TObject(clusterFinder)
79 // Protected copy constructor
81 AliFatal("Not implemented.");
83 //____________________________________________________________________________
84 void AliMUONClusterFinderVS::ResetRawClusters()
86 // Reset tracks information
88 if (fRawClusters) fRawClusters->Clear();
90 //____________________________________________________________________________
91 void AliMUONClusterFinderVS::Decluster(AliMUONRawCluster *cluster)
93 // Decluster by local maxima
94 SplitByLocalMaxima(cluster);
96 //____________________________________________________________________________
97 void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
99 // Split complex cluster by local maxima
102 fInput->SetCluster(c);
104 fMul[0]=c->GetMultiplicity(0);
105 fMul[1]=c->GetMultiplicity(1);
108 // dump digit information into arrays
113 for (cath=0; cath<2; cath++) {
116 for (i=0; i<fMul[cath]; i++) {
118 fDig[i][cath]=fInput->Digit(cath, c->GetIndex(i, cath));
120 fIx[i][cath]= fDig[i][cath]->PadX();
121 fIy[i][cath]= fDig[i][cath]->PadY();
123 fQ[i][cath] = fDig[i][cath]->Signal();
124 // pad centre coordinates
125 if (fSegmentationType == 1)
127 GetPadC(fIx[i][cath], fIy[i][cath], fX[i][cath], fY[i][cath], fZ[i][cath]);
130 GetPadC(fInput->DetElemId(), fIx[i][cath], fIy[i][cath], fX[i][cath], fY[i][cath], fZ[i][cath]);
131 } // loop over cluster digits
133 } // loop over cathodes
139 // Initialise and perform mathieson fits
140 Float_t chi2, oldchi2;
141 // ++++++++++++++++++*************+++++++++++++++++++++
142 // (1) No more than one local maximum per cathode plane
143 // +++++++++++++++++++++++++++++++*************++++++++
144 if ((fNLocal[0]==1 && (fNLocal[1]==0 || fNLocal[1]==1)) ||
145 (fNLocal[0]==0 && fNLocal[1]==1)) {
146 // Perform combined single Mathieson fit
147 // Initial values for coordinates (x,y)
149 // One local maximum on cathodes 1 and 2 (X->cathode 2, Y->cathode 1)
150 if (fNLocal[0]==1 && fNLocal[1]==1) {
151 fXInit[0]=c->GetX(1);
152 fYInit[0]=c->GetY(0);
153 // One local maximum on cathode 1 (X,Y->cathode 1)
154 } else if (fNLocal[0]==1) {
155 fXInit[0]=c->GetX(0);
156 fYInit[0]=c->GetY(0);
157 // One local maximum on cathode 2 (X,Y->cathode 2)
159 fXInit[0]=c->GetX(1);
160 fYInit[0]=c->GetY(1);
162 AliDebug(1,"cas (1) CombiSingleMathiesonFit(c)");
163 chi2=CombiSingleMathiesonFit(c);
164 // Int_t ndf = fgNbins[0]+fgNbins[1]-2;
165 // Float_t prob = TMath::Prob(Double_t(chi2),ndf);
166 // prob1->Fill(prob);
167 // chi2_1->Fill(chi2);
169 AliDebug(1,Form(" chi2 %f ",chi2));
171 c->SetX(0, fXFit[0]);
172 c->SetY(0, fYFit[0]);
179 if (fSegmentationType == 1) {
180 c->SetX(0, fSeg[0]->GetAnod(c->GetX(0)));
181 c->SetX(1, fSeg[1]->GetAnod(c->GetX(1)));
183 c->SetX(0, fSeg2[0]->GetAnod(fInput->DetElemId(), c->GetX(0)));
184 c->SetX(1, fSeg2[1]->GetAnod(fInput->DetElemId(), c->GetX(1)));
187 // If reasonable chi^2 add result to the list of rawclusters
190 // If not try combined double Mathieson Fit
192 AliDebug(1," MAUVAIS CHI2 !!!\n");
193 if (fNLocal[0]==1 && fNLocal[1]==1) {
194 fXInit[0]=fX[fIndLocal[0][1]][1];
195 fYInit[0]=fY[fIndLocal[0][0]][0];
196 fXInit[1]=fX[fIndLocal[0][1]][1];
197 fYInit[1]=fY[fIndLocal[0][0]][0];
198 } else if (fNLocal[0]==1) {
199 fXInit[0]=fX[fIndLocal[0][0]][0];
200 fYInit[0]=fY[fIndLocal[0][0]][0];
201 fXInit[1]=fX[fIndLocal[0][0]][0];
202 fYInit[1]=fY[fIndLocal[0][0]][0];
204 fXInit[0]=fX[fIndLocal[0][1]][1];
205 fYInit[0]=fY[fIndLocal[0][1]][1];
206 fXInit[1]=fX[fIndLocal[0][1]][1];
207 fYInit[1]=fY[fIndLocal[0][1]][1];
210 // Initial value for charge ratios
213 AliDebug(1,"\n cas (1) CombiDoubleMathiesonFit(c)\n");
214 chi2=CombiDoubleMathiesonFit(c);
215 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
216 // Float_t prob = TMath::Prob(chi2,ndf);
217 // prob2->Fill(prob);
218 // chi2_2->Fill(chi2);
220 // Was this any better ??
221 AliDebug(1,Form(" Old and new chi2 %f %f ", oldchi2, chi2));
222 if (fFitStat!=0 && chi2>0 && (2.*chi2 < oldchi2)) {
224 // Split cluster into two according to fit result
227 AliDebug(1,"Do not Split");
233 // +++++++++++++++++++++++++++++++++++++++
234 // (2) Two local maxima per cathode plane
235 // +++++++++++++++++++++++++++++++++++++++
236 } else if (fNLocal[0]==2 && fNLocal[1]==2) {
238 // Let's look for ghosts first
240 Float_t xm[4][2], ym[4][2];
241 Float_t dpx, dpy, dx, dy;
242 Int_t ixm[4][2], iym[4][2];
243 Int_t isec, im1, im2, ico;
245 // Form the 2x2 combinations
246 // 0-0, 0-1, 1-0, 1-1
248 for (im1=0; im1<2; im1++) {
249 for (im2=0; im2<2; im2++) {
250 xm[ico][0]=fX[fIndLocal[im1][0]][0];
251 ym[ico][0]=fY[fIndLocal[im1][0]][0];
252 xm[ico][1]=fX[fIndLocal[im2][1]][1];
253 ym[ico][1]=fY[fIndLocal[im2][1]][1];
255 ixm[ico][0]=fIx[fIndLocal[im1][0]][0];
256 iym[ico][0]=fIy[fIndLocal[im1][0]][0];
257 ixm[ico][1]=fIx[fIndLocal[im2][1]][1];
258 iym[ico][1]=fIy[fIndLocal[im2][1]][1];
262 // ico = 0 : first local maximum on cathodes 1 and 2
263 // ico = 1 : fisrt local maximum on cathode 1 and second on cathode 2
264 // ico = 2 : second local maximum on cathode 1 and first on cathode 1
265 // ico = 3 : second local maximum on cathodes 1 and 2
267 // Analyse the combinations and keep those that are possible !
268 // For each combination check consistency in x and y
271 Float_t dr[4] = {1.e4, 1.e4, 1.e4, 1.e4};
274 // In case of staggering maxima are displaced by exactly half the pad-size in y.
275 // We have to take into account the numerical precision in the consistency check;
278 for (ico=0; ico<4; ico++) {
279 accepted[ico]=kFALSE;
280 // cathode one: x-coordinate
281 if (fSegmentationType == 1) {
282 isec=fSeg[0]->Sector(ixm[ico][0], iym[ico][0]);
283 dpx=fSeg[0]->Dpx(isec)/2.;
285 isec=fSeg2[0]->Sector(fInput->DetElemId(), ixm[ico][0], iym[ico][0]);
286 dpx=fSeg2[0]->Dpx(fInput->DetElemId(), isec)/2.;
288 dx=TMath::Abs(xm[ico][0]-xm[ico][1]);
289 // cathode two: y-coordinate
290 if (fSegmentationType == 1) {
291 isec=fSeg[1]->Sector(ixm[ico][1], iym[ico][1]);
292 dpy=fSeg[1]->Dpy(isec)/2.;
294 isec=fSeg2[1]->Sector(fInput->DetElemId(), ixm[ico][1], iym[ico][1]);
295 dpy=fSeg2[1]->Dpy(fInput->DetElemId(), isec)/2.;
297 dy=TMath::Abs(ym[ico][0]-ym[ico][1]);
298 AliDebug(2,Form("\n %i %f %f %f %f %f %f \n", ico, ym[ico][0], ym[ico][1], dy, dpy, dx, dpx ));
299 if ((dx <= dpx) && (dy <= dpy+eps)) {
302 dr[ico] = TMath::Sqrt(dx*dx+dy*dy);
306 accepted[ico]=kFALSE;
309 AliDebug(1,Form("\n iacc= %d:\n", iacc));
311 if (accepted[0] && accepted[1]) {
312 if (dr[0] >= dr[1]) {
319 if (accepted[2] && accepted[3]) {
320 if (dr[2] >= dr[3]) {
327 // eliminate one candidate
331 for (ico=0; ico<4; ico++) {
332 if (accepted[ico] && dr[ico] > drmax) {
338 accepted[icobad] = kFALSE;
344 AliDebug(1,Form("\n iacc= %d:\n", iacc));
346 AliDebug(1,"\n iacc=2: No problem ! \n");
347 } else if (iacc==4) {
348 AliDebug(1,"\n iacc=4: Ok, but ghost problem !!! \n");
349 } else if (iacc==0) {
350 AliDebug(1,"\n iacc=0: I don't know what to do with this !!!!!!!!! \n");
353 // Initial value for charge ratios
354 fQrInit[0]=Float_t(fQ[fIndLocal[0][0]][0])/
355 Float_t(fQ[fIndLocal[0][0]][0]+fQ[fIndLocal[1][0]][0]);
356 fQrInit[1]=Float_t(fQ[fIndLocal[0][1]][1])/
357 Float_t(fQ[fIndLocal[0][1]][1]+fQ[fIndLocal[1][1]][1]);
359 // ******* iacc = 0 *******
360 // No combinations found between the 2 cathodes
361 // We keep the center of gravity of the cluster
366 // ******* iacc = 1 *******
367 // Only one combination found between the 2 cathodes
369 // Initial values for the 2 maxima (x,y)
371 // 1 maximum is initialised with the maximum of the combination found (X->cathode 2, Y->cathode 1)
372 // 1 maximum is initialised with the other maximum of the first cathode
379 } else if (accepted[1]){
385 } else if (accepted[2]){
391 } else if (accepted[3]){
398 AliDebug(1,"cas (2) CombiDoubleMathiesonFit(c)");
399 chi2=CombiDoubleMathiesonFit(c);
400 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
401 // Float_t prob = TMath::Prob(chi2,ndf);
402 // prob2->Fill(prob);
403 // chi2_2->Fill(chi2);
404 AliDebug(1,Form(" chi2 %f\n",chi2));
406 // If reasonable chi^2 add result to the list of rawclusters
411 // 1 maximum is initialised with the maximum of the combination found (X->cathode 2, Y->cathode 1)
412 // 1 maximum is initialised with the other maximum of the second cathode
419 } else if (accepted[1]){
425 } else if (accepted[2]){
431 } else if (accepted[3]){
438 AliDebug(1,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
439 chi2=CombiDoubleMathiesonFit(c);
440 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
441 // Float_t prob = TMath::Prob(chi2,ndf);
442 // prob2->Fill(prob);
443 // chi2_2->Fill(chi2);
444 AliDebug(1,Form(" chi2 %f\n",chi2));
446 // If reasonable chi^2 add result to the list of rawclusters
450 //We keep only the combination found (X->cathode 2, Y->cathode 1)
451 for (Int_t ico=0; ico<2; ico++) {
453 AliMUONRawCluster cnew;
455 for (cath=0; cath<2; cath++) {
456 cnew.SetX(cath, Float_t(xm[ico][1]));
457 cnew.SetY(cath, Float_t(ym[ico][0]));
458 cnew.SetZ(cath, fZPlane);
460 cnew.SetMultiplicity(cath,c->GetMultiplicity(cath));
461 for (i=0; i<fMul[cath]; i++) {
462 cnew.SetIndex(i, cath, c->GetIndex(i,cath));
463 if (fSegmentationType == 1)
464 fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
466 fSeg2[cath]->SetPad(fInput->DetElemId(), fIx[i][cath], fIy[i][cath]);
468 AliDebug(1,Form("\nRawCluster %d cath %d\n",ico,cath));
469 AliDebug(1,Form("mult_av %d\n",c->GetMultiplicity(cath)));
470 FillCluster(&cnew,cath);
472 cnew.SetClusterType(cnew.PhysicsContribution());
481 // ******* iacc = 2 *******
482 // Two combinations found between the 2 cathodes
484 // Was the same maximum taken twice
485 if ((accepted[0]&&accepted[1]) || (accepted[2]&&accepted[3])) {
486 AliDebug(1,"\n Maximum taken twice !!!\n");
488 // Have a try !! with that
489 if (accepted[0]&&accepted[3]) {
500 AliDebug(1,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
501 chi2=CombiDoubleMathiesonFit(c);
502 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
503 // Float_t prob = TMath::Prob(chi2,ndf);
504 // prob2->Fill(prob);
505 // chi2_2->Fill(chi2);
509 // No ghosts ! No Problems ! - Perform one fit only !
510 if (accepted[0]&&accepted[3]) {
521 AliDebug(1,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
522 chi2=CombiDoubleMathiesonFit(c);
523 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
524 // Float_t prob = TMath::Prob(chi2,ndf);
525 // prob2->Fill(prob);
526 // chi2_2->Fill(chi2);
527 AliDebug(1,Form(" chi2 %f\n",chi2));
531 // ******* iacc = 4 *******
532 // Four combinations found between the 2 cathodes
534 } else if (iacc==4) {
535 // Perform fits for the two possibilities !!
536 // Accept if charges are compatible on both cathodes
537 // If none are compatible, keep everything
542 AliDebug(1,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
543 chi2=CombiDoubleMathiesonFit(c);
544 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
545 // Float_t prob = TMath::Prob(chi2,ndf);
546 // prob2->Fill(prob);
547 // chi2_2->Fill(chi2);
548 AliDebug(1,Form(" chi2 %f\n",chi2));
549 // store results of fit and postpone decision
550 Double_t sXFit[2],sYFit[2],sQrFit[2];
552 for (Int_t i=0;i<2;i++) {
562 AliDebug(1,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
563 chi2=CombiDoubleMathiesonFit(c);
564 // ndf = fgNbins[0]+fgNbins[1]-6;
565 // prob = TMath::Prob(chi2,ndf);
566 // prob2->Fill(prob);
567 // chi2_2->Fill(chi2);
568 AliDebug(1,Form(" chi2 %f\n",chi2));
569 // We have all informations to perform the decision
570 // Compute the chi2 for the 2 possibilities
571 Float_t chi2fi,chi2si,chi2f,chi2s;
573 chi2f = (TMath::Log(fInput->TotalCharge(0)*fQrFit[0]
574 / (fInput->TotalCharge(1)*fQrFit[1]) )
575 / fInput->ChargeCorrel() );
577 chi2fi = (TMath::Log(fInput->TotalCharge(0)*(1-fQrFit[0])
578 / (fInput->TotalCharge(1)*(1-fQrFit[1])) )
579 / fInput->ChargeCorrel() );
580 chi2f += chi2fi*chi2fi;
582 chi2s = (TMath::Log(fInput->TotalCharge(0)*sQrFit[0]
583 / (fInput->TotalCharge(1)*sQrFit[1]) )
584 / fInput->ChargeCorrel() );
586 chi2si = (TMath::Log(fInput->TotalCharge(0)*(1-sQrFit[0])
587 / (fInput->TotalCharge(1)*(1-sQrFit[1])) )
588 / fInput->ChargeCorrel() );
589 chi2s += chi2si*chi2si;
591 // usefull to store the charge matching chi2 in the cluster
592 // fChi2[0]=sChi2[1]=chi2f;
593 // fChi2[1]=sChi2[0]=chi2s;
595 if (chi2f<=fGhostChi2Cut && chi2s<=fGhostChi2Cut)
597 if (chi2f>fGhostChi2Cut && chi2s>fGhostChi2Cut) {
603 if (chi2f<=fGhostChi2Cut)
605 if (chi2s<=fGhostChi2Cut) {
606 // retreive saved values
607 for (Int_t i=0;i<2;i++) {
618 } else if (fNLocal[0]==2 && fNLocal[1]==1) {
619 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
620 // (3) Two local maxima on cathode 1 and one maximum on cathode 2
621 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
623 Float_t xm[4][2], ym[4][2];
624 Float_t dpx, dpy, dx, dy;
625 Int_t ixm[4][2], iym[4][2];
626 Int_t isec, im1, ico;
628 // Form the 2x2 combinations
629 // 0-0, 0-1, 1-0, 1-1
631 for (im1=0; im1<2; im1++) {
632 xm[ico][0]=fX[fIndLocal[im1][0]][0];
633 ym[ico][0]=fY[fIndLocal[im1][0]][0];
634 xm[ico][1]=fX[fIndLocal[0][1]][1];
635 ym[ico][1]=fY[fIndLocal[0][1]][1];
637 ixm[ico][0]=fIx[fIndLocal[im1][0]][0];
638 iym[ico][0]=fIy[fIndLocal[im1][0]][0];
639 ixm[ico][1]=fIx[fIndLocal[0][1]][1];
640 iym[ico][1]=fIy[fIndLocal[0][1]][1];
643 // ico = 0 : first local maximum on cathodes 1 and 2
644 // ico = 1 : second local maximum on cathode 1 and first on cathode 2
646 // Analyse the combinations and keep those that are possible !
647 // For each combination check consistency in x and y
651 // In case of staggering maxima are displaced by exactly half the pad-size in y.
652 // We have to take into account the numerical precision in the consistency check;
656 for (ico=0; ico<2; ico++) {
657 accepted[ico]=kFALSE;
658 if (fSegmentationType == 1) {
659 isec=fSeg[0]->Sector(ixm[ico][0], iym[ico][0]);
660 dpx=fSeg[0]->Dpx(isec)/2.;
662 isec=fSeg2[0]->Sector(fInput->DetElemId(), ixm[ico][0], iym[ico][0]);
663 dpx=fSeg2[0]->Dpx(fInput->DetElemId(), isec)/2.;
665 dx=TMath::Abs(xm[ico][0]-xm[ico][1]);
666 if (fSegmentationType == 1) {
667 isec=fSeg[1]->Sector(ixm[ico][1], iym[ico][1]);
668 dpy=fSeg[1]->Dpy(isec)/2.;
670 isec=fSeg2[1]->Sector(fInput->DetElemId(), ixm[ico][1], iym[ico][1]);
671 dpy=fSeg2[1]->Dpy(fInput->DetElemId(), isec)/2.;
673 dy=TMath::Abs(ym[ico][0]-ym[ico][1]);
674 AliDebug(2,Form("\n %i %f %f %f %f \n", ico, ym[ico][0], ym[ico][1], dy, dpy ));
675 if ((dx <= dpx) && (dy <= dpy+eps)) {
681 accepted[ico]=kFALSE;
689 // Initial value for charge ratios
690 fQrInit[0]=Float_t(fQ[fIndLocal[0][0]][0])/
691 Float_t(fQ[fIndLocal[0][0]][0]+fQ[fIndLocal[1][0]][0]);
692 fQrInit[1]=fQrInit[0];
694 if (accepted[0] && accepted[1]) {
696 fXInit[0]=0.5*(xm[0][1]+xm[0][0]);
698 fXInit[1]=0.5*(xm[0][1]+xm[1][0]);
702 chi23=CombiDoubleMathiesonFit(c);
711 } else if (accepted[0]) {
716 chi21=CombiDoubleMathiesonFit(c);
717 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
718 // Float_t prob = TMath::Prob(chi2,ndf);
719 // prob2->Fill(prob);
720 // chi2_2->Fill(chi21);
721 AliDebug(1,Form(" chi2 %f\n",chi21));
722 if (chi21<10) Split(c);
723 } else if (accepted[1]) {
728 chi22=CombiDoubleMathiesonFit(c);
729 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
730 // Float_t prob = TMath::Prob(chi2,ndf);
731 // prob2->Fill(prob);
732 // chi2_2->Fill(chi22);
733 AliDebug(1,Form(" chi2 %f\n",chi22));
734 if (chi22<10) Split(c);
737 if (chi21 > 10 && chi22 > 10 && chi23 > 10) {
738 // We keep only the combination found (X->cathode 2, Y->cathode 1)
739 for (Int_t ico=0; ico<2; ico++) {
741 AliMUONRawCluster cnew;
743 for (cath=0; cath<2; cath++) {
744 cnew.SetX(cath, Float_t(xm[ico][1]));
745 cnew.SetY(cath, Float_t(ym[ico][0]));
746 cnew.SetZ(cath, fZPlane);
747 cnew.SetMultiplicity(cath, c->GetMultiplicity(cath));
748 for (i=0; i<fMul[cath]; i++) {
749 cnew.SetIndex(i, cath, c->GetIndex(i, cath));
750 if (fSegmentationType == 1)
751 fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
753 fSeg2[cath]->SetPad(fInput->DetElemId(), fIx[i][cath], fIy[i][cath]);
756 AliDebug(1,Form("\nRawCluster %d cath %d\n",ico,cath));
757 AliDebug(1,Form("mult_av %d\n",c->GetMultiplicity(cath)));
759 FillCluster(&cnew,cath);
761 cnew.SetClusterType(cnew.PhysicsContribution());
768 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
769 // (3') One local maximum on cathode 1 and two maxima on cathode 2
770 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
771 } else if (fNLocal[0]==1 && fNLocal[1]==2) {
772 Float_t xm[4][2], ym[4][2];
773 Float_t dpx, dpy, dx, dy;
774 Int_t ixm[4][2], iym[4][2];
775 Int_t isec, im1, ico;
777 // Form the 2x2 combinations
778 // 0-0, 0-1, 1-0, 1-1
780 for (im1=0; im1<2; im1++) {
781 xm[ico][0]=fX[fIndLocal[0][0]][0];
782 ym[ico][0]=fY[fIndLocal[0][0]][0];
783 xm[ico][1]=fX[fIndLocal[im1][1]][1];
784 ym[ico][1]=fY[fIndLocal[im1][1]][1];
786 ixm[ico][0]=fIx[fIndLocal[0][0]][0];
787 iym[ico][0]=fIy[fIndLocal[0][0]][0];
788 ixm[ico][1]=fIx[fIndLocal[im1][1]][1];
789 iym[ico][1]=fIy[fIndLocal[im1][1]][1];
792 // ico = 0 : first local maximum on cathodes 1 and 2
793 // ico = 1 : first local maximum on cathode 1 and second on cathode 2
795 // Analyse the combinations and keep those that are possible !
796 // For each combination check consistency in x and y
800 // In case of staggering maxima are displaced by exactly half the pad-size in y.
801 // We have to take into account the numerical precision in the consistency check;
805 for (ico=0; ico<2; ico++) {
806 accepted[ico]=kFALSE;
807 if (fSegmentationType == 1) {
808 isec=fSeg[0]->Sector(ixm[ico][0], iym[ico][0]);
809 dpx=fSeg[0]->Dpx(isec)/2.;
811 isec=fSeg2[0]->Sector(fInput->DetElemId(), ixm[ico][0], iym[ico][0]);
812 dpx=fSeg2[0]->Dpx(fInput->DetElemId(), isec)/2.;
814 dx=TMath::Abs(xm[ico][0]-xm[ico][1]);
815 if (fSegmentationType == 1) {
816 isec=fSeg[1]->Sector(ixm[ico][1], iym[ico][1]);
817 dpy=fSeg[1]->Dpy(isec)/2.;
819 isec=fSeg2[1]->Sector(fInput->DetElemId(), ixm[ico][1], iym[ico][1]);
820 dpy=fSeg2[1]->Dpy(fInput->DetElemId(), isec)/2.;
822 dy=TMath::Abs(ym[ico][0]-ym[ico][1]);
823 AliDebug(1,Form("\n %i %f %f %f %f \n", ico, ym[ico][0], ym[ico][1], dy, dpy ));
824 if ((dx <= dpx) && (dy <= dpy+eps)) {
827 AliDebug(1,Form("ico %d\n",ico));
831 accepted[ico]=kFALSE;
839 fQrInit[1]=Float_t(fQ[fIndLocal[0][1]][1])/
840 Float_t(fQ[fIndLocal[0][1]][1]+fQ[fIndLocal[1][1]][1]);
842 fQrInit[0]=fQrInit[1];
845 if (accepted[0] && accepted[1]) {
847 fYInit[0]=0.5*(ym[0][0]+ym[0][1]);
849 fYInit[1]=0.5*(ym[0][0]+ym[1][1]);
852 chi23=CombiDoubleMathiesonFit(c);
861 } else if (accepted[0]) {
866 chi21=CombiDoubleMathiesonFit(c);
867 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
868 // Float_t prob = TMath::Prob(chi2,ndf);
869 // prob2->Fill(prob);
870 // chi2_2->Fill(chi21);
871 AliDebug(1,Form(" chi2 %f\n",chi21));
872 if (chi21<10) Split(c);
873 } else if (accepted[1]) {
878 chi22=CombiDoubleMathiesonFit(c);
879 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
880 // Float_t prob = TMath::Prob(chi2,ndf);
881 // prob2->Fill(prob);
882 // chi2_2->Fill(chi22);
883 AliDebug(1,Form(" chi2 %f\n",chi22));
884 if (chi22<10) Split(c);
887 if (chi21 > 10 && chi22 > 10 && chi23 > 10) {
888 //We keep only the combination found (X->cathode 2, Y->cathode 1)
889 for (Int_t ico=0; ico<2; ico++) {
891 AliMUONRawCluster cnew;
893 for (cath=0; cath<2; cath++) {
894 cnew.SetX(cath, Float_t(xm[ico][1]));
895 cnew.SetY(cath, Float_t(ym[ico][0]));
896 cnew.SetZ(cath, fZPlane);
897 cnew.SetMultiplicity(cath, c->GetMultiplicity(cath));
898 for (i=0; i<fMul[cath]; i++) {
899 cnew.SetIndex(i, cath, c->GetIndex(i, cath));
900 if (fSegmentationType == 1)
901 fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
903 fSeg2[cath]->SetPad(fInput->DetElemId(), fIx[i][cath], fIy[i][cath]);
905 AliDebug(1,Form("\nRawCluster %d cath %d\n",ico,cath));
906 AliDebug(1,Form("mult_av %d\n",c->GetMultiplicity(cath)));
907 FillCluster(&cnew,cath);
909 cnew.SetClusterType(cnew.PhysicsContribution());
916 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
917 // (4) At least three local maxima on cathode 1 or on cathode 2
918 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
919 } else if (fNLocal[0]>2 || fNLocal[1]>2) {
920 Int_t param = fNLocal[0]*fNLocal[1];
923 Float_t ** xm = new Float_t * [param];
924 for (ii=0; ii<param; ii++) xm[ii]=new Float_t [2];
925 Float_t ** ym = new Float_t * [param];
926 for (ii=0; ii<param; ii++) ym[ii]=new Float_t [2];
927 Int_t ** ixm = new Int_t * [param];
928 for (ii=0; ii<param; ii++) ixm[ii]=new Int_t [2];
929 Int_t ** iym = new Int_t * [param];
930 for (ii=0; ii<param; ii++) iym[ii]=new Int_t [2];
933 Float_t dpx, dpy, dx, dy;
936 for (Int_t im1=0; im1<fNLocal[0]; im1++) {
937 for (Int_t im2=0; im2<fNLocal[1]; im2++) {
938 xm[ico][0]=fX[fIndLocal[im1][0]][0];
939 ym[ico][0]=fY[fIndLocal[im1][0]][0];
940 xm[ico][1]=fX[fIndLocal[im2][1]][1];
941 ym[ico][1]=fY[fIndLocal[im2][1]][1];
943 ixm[ico][0]=fIx[fIndLocal[im1][0]][0];
944 iym[ico][0]=fIy[fIndLocal[im1][0]][0];
945 ixm[ico][1]=fIx[fIndLocal[im2][1]][1];
946 iym[ico][1]=fIy[fIndLocal[im2][1]][1];
952 AliDebug(1,Form("nIco %d\n",nIco));
953 for (ico=0; ico<nIco; ico++) {
954 AliDebug(1,Form("ico = %d\n",ico));
955 if (fSegmentationType == 1) {
956 isec=fSeg[0]->Sector(ixm[ico][0], iym[ico][0]);
957 dpx=fSeg[0]->Dpx(isec)/2.;
959 isec=fSeg2[0]->Sector(fInput->DetElemId(), ixm[ico][0], iym[ico][0]);
960 dpx=fSeg2[0]->Dpx(fInput->DetElemId(), isec)/2.;
962 dx=TMath::Abs(xm[ico][0]-xm[ico][1]);
963 if (fSegmentationType == 1) {
964 isec=fSeg[1]->Sector(ixm[ico][1], iym[ico][1]);
965 dpy=fSeg[1]->Dpy(isec)/2.;
967 isec=fSeg2[1]->Sector(fInput->DetElemId(), ixm[ico][1], iym[ico][1]);
968 dpy=fSeg2[1]->Dpy(fInput->DetElemId(), isec)/2.;
970 dy=TMath::Abs(ym[ico][0]-ym[ico][1]);
971 AliDebug(1,Form("dx %f dpx %f dy %f dpy %f\n",dx,dpx,dy,dpy));
972 AliDebug(1,Form(" X %f Y %f\n",xm[ico][1],ym[ico][0]));
973 if ((dx <= dpx) && (dy <= dpy)) {
976 AliMUONRawCluster cnew;
977 for (cath=0; cath<2; cath++) {
978 cnew.SetX(cath, Float_t(xm[ico][1]));
979 cnew.SetY(cath, Float_t(ym[ico][0]));
980 cnew.SetZ(cath, fZPlane);
981 cnew.SetMultiplicity(cath, c->GetMultiplicity(cath));
982 for (i=0; i<fMul[cath]; i++) {
983 cnew.SetIndex(i, cath, c->GetIndex(i, cath));
984 if (fSegmentationType == 1)
985 fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
987 fSeg2[cath]->SetPad(fInput->DetElemId(), fIx[i][cath], fIy[i][cath]);
989 FillCluster(&cnew,cath);
991 cnew.SetClusterType(cnew.PhysicsContribution());
1003 void AliMUONClusterFinderVS::FindLocalMaxima(AliMUONRawCluster* /*c*/)
1005 // Find all local maxima of a cluster
1006 AliDebug(1,"\n Find Local maxima !");
1010 Int_t cath, cath1; // loops over cathodes
1011 Int_t i; // loops over digits
1012 Int_t j; // loops over cathodes
1014 // Find local maxima
1016 // counters for number of local maxima
1017 fNLocal[0]=fNLocal[1]=0;
1018 // flags digits as local maximum
1019 Bool_t isLocal[100][2];
1020 for (i=0; i<100;i++) {
1021 isLocal[i][0]=isLocal[i][1]=kFALSE;
1023 // number of next neighbours and arrays to store them
1026 // loop over cathodes
1027 for (cath=0; cath<2; cath++) {
1028 // loop over cluster digits
1029 for (i=0; i<fMul[cath]; i++) {
1030 // get neighbours for that digit and assume that it is local maximum
1034 if (fSegmentationType == 1)
1035 fSeg[cath]->Neighbours(fIx[i][cath], fIy[i][cath], &nn, x, y);
1037 fSeg2[cath]->Neighbours(fInput->DetElemId(), fIx[i][cath], fIy[i][cath], &nn, x, y);
1039 isLocal[i][cath]=kTRUE;
1041 if (fSegmentationType == 1) {
1042 isec = fSeg[cath]->Sector(fIx[i][cath], fIy[i][cath]);
1043 a0 = fSeg[cath]->Dpx(isec)*fSeg[cath]->Dpy(isec);
1045 isec = fSeg2[cath]->Sector(fInput->DetElemId(), fIx[i][cath], fIy[i][cath]);
1046 a0 = fSeg2[cath]->Dpx(fInput->DetElemId(), isec)*fSeg2[cath]->Dpy(fInput->DetElemId(), isec);
1048 // loop over next neighbours, if at least one neighbour has higher charger assumption
1049 // digit is not local maximum
1050 for (j=0; j<nn; j++) {
1051 if (fHitMap[cath]->TestHit(x[j], y[j])==kEmpty) continue;
1052 digt=(AliMUONDigit*) fHitMap[cath]->GetHit(x[j], y[j]);
1054 if (fSegmentationType == 1) {
1055 isec=fSeg[cath]->Sector(x[j], y[j]);
1056 a1 = fSeg[cath]->Dpx(isec)*fSeg[cath]->Dpy(isec);
1058 isec=fSeg2[cath]->Sector(fInput->DetElemId(), x[j], y[j]);
1059 a1 = fSeg2[cath]->Dpx(fInput->DetElemId(),isec)*fSeg2[cath]->Dpy(fInput->DetElemId(), isec);
1061 if (digt->Signal()/a1 > fQ[i][cath]/a0) {
1062 isLocal[i][cath]=kFALSE;
1065 // handle special case of neighbouring pads with equal signal
1066 } else if (digt->Signal() == fQ[i][cath]) {
1067 if (fNLocal[cath]>0) {
1068 for (Int_t k=0; k<fNLocal[cath]; k++) {
1069 if (x[j]==fIx[fIndLocal[k][cath]][cath]
1070 && y[j]==fIy[fIndLocal[k][cath]][cath])
1072 isLocal[i][cath]=kFALSE;
1074 } // loop over local maxima
1075 } // are there already local maxima
1077 } // loop over next neighbours
1078 if (isLocal[i][cath]) {
1079 fIndLocal[fNLocal[cath]][cath]=i;
1082 } // loop over all digits
1083 } // loop over cathodes
1085 AliDebug(1,Form("\n Found %d %d %d %d local Maxima\n",
1086 fNLocal[0], fNLocal[1], fMul[0], fMul[1]));
1087 AliDebug(1,Form("\n Cathode 1 local Maxima %d Multiplicite %d\n",fNLocal[0], fMul[0]));
1088 AliDebug(1,Form(" Cathode 2 local Maxima %d Multiplicite %d\n",fNLocal[1], fMul[1]));
1093 if (fNLocal[1]==2 && (fNLocal[0]==1 || fNLocal[0]==0)) {
1094 Int_t iback=fNLocal[0];
1096 // Two local maxima on cathode 2 and one maximum on cathode 1
1097 // Look for local maxima considering up and down neighbours on the 1st cathode only
1099 // Loop over cluster digits
1103 for (i=0; i<fMul[cath]; i++) {
1104 if (fSegmentationType == 1) {
1105 isec=fSeg[cath]->Sector(fIx[i][cath],fIy[i][cath]);
1106 dpy=fSeg[cath]->Dpy(isec);
1107 dpx=fSeg[cath]->Dpx(isec);
1109 isec=fSeg2[cath]->Sector(fInput->DetElemId(), fIx[i][cath],fIy[i][cath]);
1110 dpy=fSeg2[cath]->Dpy(fInput->DetElemId(), isec);
1111 dpx=fSeg2[cath]->Dpx(fInput->DetElemId(), isec);
1113 if (isLocal[i][cath]) continue;
1114 // Pad position should be consistent with position of local maxima on the opposite cathode
1115 if ((TMath::Abs(fX[i][cath]-fX[fIndLocal[0][cath1]][cath1]) > dpx/2.) &&
1116 (TMath::Abs(fX[i][cath]-fX[fIndLocal[1][cath1]][cath1]) > dpx/2.))
1119 // get neighbours for that digit and assume that it is local maximum
1120 isLocal[i][cath]=kTRUE;
1121 // compare signal to that on the two neighbours on the left and on the right
1122 // iNN counts the number of neighbours with signal, it should be 1 or 2
1124 if (fSegmentationType == 1) {
1126 for (fSeg[cath]->FirstPad(fX[i][cath], fY[i][cath], fZPlane, 0., dpy);
1127 fSeg[cath]->MorePads();
1128 fSeg[cath]->NextPad())
1130 ix = fSeg[cath]->Ix();
1131 iy = fSeg[cath]->Iy();
1132 // skip the current pad
1133 if (iy == fIy[i][cath]) continue;
1135 if (fHitMap[cath]->TestHit(ix, iy)!=kEmpty) {
1137 digt=(AliMUONDigit*) fHitMap[cath]->GetHit(ix,iy);
1138 if (digt->Signal() > fQ[i][cath]) isLocal[i][cath]=kFALSE;
1140 } // Loop over pad neighbours in y
1143 for (fSeg2[cath]->FirstPad(fInput->DetElemId(), fX[i][cath], fY[i][cath], fZPlane, 0., dpy);
1144 fSeg2[cath]->MorePads(fInput->DetElemId());
1145 fSeg2[cath]->NextPad(fInput->DetElemId()))
1147 ix = fSeg2[cath]->Ix();
1148 iy = fSeg2[cath]->Iy();
1149 // skip the current pad
1150 if (iy == fIy[i][cath]) continue;
1152 if (fHitMap[cath]->TestHit(ix, iy)!=kEmpty) {
1154 digt=(AliMUONDigit*) fHitMap[cath]->GetHit(ix,iy);
1155 if (digt->Signal() > fQ[i][cath]) isLocal[i][cath]=kFALSE;
1157 } // Loop over pad neighbours in y
1159 if (isLocal[i][cath] && iNN>0) {
1160 fIndLocal[fNLocal[cath]][cath]=i;
1163 } // loop over all digits
1164 // if one additional maximum has been found we are happy
1165 // if more maxima have been found restore the previous situation
1166 AliDebug(1,Form("\n New search gives %d local maxima for cathode 1 \n",
1168 AliDebug(1,Form(" %d local maxima for cathode 2 \n",
1170 if (fNLocal[cath]>2) {
1171 fNLocal[cath]=iback;
1174 } // 1,2 local maxima
1176 if (fNLocal[0]==2 && (fNLocal[1]==1 || fNLocal[1]==0)) {
1177 Int_t iback=fNLocal[1];
1179 // Two local maxima on cathode 1 and one maximum on cathode 2
1180 // Look for local maxima considering left and right neighbours on the 2nd cathode only
1183 Float_t eps = 1.e-5;
1186 // Loop over cluster digits
1187 for (i=0; i<fMul[cath]; i++) {
1188 if (fSegmentationType == 1) {
1189 isec=fSeg[cath]->Sector(fIx[i][cath],fIy[i][cath]);
1190 dpx=fSeg[cath]->Dpx(isec);
1191 dpy=fSeg[cath]->Dpy(isec);
1193 isec=fSeg2[cath]->Sector(fInput->DetElemId(), fIx[i][cath],fIy[i][cath]);
1194 dpx=fSeg2[cath]->Dpx(fInput->DetElemId(), isec);
1195 dpy=fSeg2[cath]->Dpy(fInput->DetElemId(), isec);
1198 if (isLocal[i][cath]) continue;
1199 // Pad position should be consistent with position of local maxima on the opposite cathode
1200 if ((TMath::Abs(fY[i][cath]-fY[fIndLocal[0][cath1]][cath1]) > dpy/2.+eps) &&
1201 (TMath::Abs(fY[i][cath]-fY[fIndLocal[1][cath1]][cath1]) > dpy/2.+eps))
1205 // get neighbours for that digit and assume that it is local maximum
1206 isLocal[i][cath]=kTRUE;
1207 // compare signal to that on the two neighbours on the left and on the right
1209 // iNN counts the number of neighbours with signal, it should be 1 or 2
1211 if (fSegmentationType == 1) {
1212 for (fSeg[cath]->FirstPad(fX[i][cath], fY[i][cath], fZPlane, dpx, 0.);
1213 fSeg[cath]->MorePads();
1214 fSeg[cath]->NextPad())
1217 ix = fSeg[cath]->Ix();
1218 iy = fSeg[cath]->Iy();
1220 // skip the current pad
1221 if (ix == fIx[i][cath]) continue;
1223 if (fHitMap[cath]->TestHit(ix, iy)!=kEmpty) {
1225 digt=(AliMUONDigit*) fHitMap[cath]->GetHit(ix,iy);
1226 if (digt->Signal() > fQ[i][cath]) isLocal[i][cath]=kFALSE;
1228 } // Loop over pad neighbours in x
1230 for (fSeg2[cath]->FirstPad(fInput->DetElemId(), fX[i][cath], fY[i][cath], fZPlane, dpx, 0.);
1231 fSeg2[cath]->MorePads(fInput->DetElemId());
1232 fSeg2[cath]->NextPad(fInput->DetElemId()))
1235 ix = fSeg2[cath]->Ix();
1236 iy = fSeg2[cath]->Iy();
1238 // skip the current pad
1239 if (ix == fIx[i][cath]) continue;
1241 if (fHitMap[cath]->TestHit(ix, iy)!=kEmpty) {
1243 digt=(AliMUONDigit*) fHitMap[cath]->GetHit(ix,iy);
1244 if (digt->Signal() > fQ[i][cath]) isLocal[i][cath]=kFALSE;
1246 } // Loop over pad neighbours in x
1248 if (isLocal[i][cath] && iNN>0) {
1249 fIndLocal[fNLocal[cath]][cath]=i;
1252 } // loop over all digits
1253 // if one additional maximum has been found we are happy
1254 // if more maxima have been found restore the previous situation
1255 AliDebug(1,Form("\n New search gives %d local maxima for cathode 1 \n",fNLocal[0]));
1256 AliDebug(1,Form("\n %d local maxima for cathode 2 \n",fNLocal[1]));
1257 AliDebug(1,Form("\n New search gives %d %d \n",fNLocal[0],fNLocal[1]));
1258 if (fNLocal[cath]>2) {
1259 fNLocal[cath]=iback;
1261 } // 2,1 local maxima
1265 void AliMUONClusterFinderVS::FillCluster(AliMUONRawCluster* c, Int_t flag, Int_t cath)
1268 // Completes cluster information starting from list of digits
1275 c->SetPeakSignal(cath,c->GetPeakSignal(0));
1277 c->SetPeakSignal(cath,0);
1284 c->SetCharge(cath,0);
1287 AliDebug(1,Form("\n fPeakSignal %d\n",c->GetPeakSignal(cath)));
1288 for (Int_t i=0; i<c->GetMultiplicity(cath); i++)
1290 dig= fInput->Digit(cath,c->GetIndex(i,cath));
1291 ix=dig->PadX()+c->GetOffset(i,cath);
1293 Int_t q=dig->Signal();
1294 if (!flag) q=Int_t(q*c->GetContrib(i,cath));
1295 // fprintf(stderr,"q %d c->fPeakSignal[ %d ] %d\n",q,cath,c->fPeakSignal[cath]);
1296 if (dig->Physics() >= dig->Signal()) {
1298 } else if (dig->Physics() == 0) {
1300 } else c->SetPhysics(i,1);
1303 AliDebug(2,Form("q %d c->fPeakSignal[cath] %d\n",q,c->GetPeakSignal(cath)));
1304 // peak signal and track list
1305 if (q>c->GetPeakSignal(cath)) {
1306 c->SetPeakSignal(cath, q);
1307 c->SetTrack(0,dig->Hit());
1308 c->SetTrack(1,dig->Track(0));
1309 c->SetTrack(2,dig->Track(1));
1310 // fprintf(stderr," c->fTracks[0] %d c->fTracks[1] %d\n",dig->fHit,dig->fTracks[0]);
1314 if (fSegmentationType == 1)
1315 fSeg[cath]->GetPadC(ix, iy, x, y, z);
1317 fSeg2[cath]->GetPadC(fInput->DetElemId(), ix, iy, x, y, z);
1321 c->AddCharge(cath, q);
1323 } // loop over digits
1324 AliDebug(1," fin du cluster c\n");
1328 c->SetX(cath, c->GetX(cath)/c->GetCharge(cath));
1330 if (fSegmentationType == 1)
1331 c->SetX(cath, fSeg[cath]->GetAnod(c->GetX(cath)));
1333 c->SetX(cath, fSeg2[cath]->GetAnod(fInput->DetElemId(), c->GetX(cath)));
1334 c->SetY(cath, c->GetY(cath)/c->GetCharge(cath));
1336 // apply correction to the coordinate along the anode wire
1342 if (fSegmentationType == 1) {
1343 fSeg[cath]->GetPadI(x, y, fZPlane, ix, iy);
1344 fSeg[cath]->GetPadC(ix, iy, x, y, z);
1345 isec=fSeg[cath]->Sector(ix,iy);
1346 cogCorr = fSeg[cath]->CorrFunc(isec-1);
1348 fSeg2[cath]->GetPadI(fInput->DetElemId(), x, y, fZPlane, ix, iy);
1349 fSeg2[cath]->GetPadC(fInput->DetElemId(), ix, iy, x, y, z);
1350 isec=fSeg2[cath]->Sector(fInput->DetElemId(), ix,iy);
1351 cogCorr = fSeg2[cath]->CorrFunc(fInput->DetElemId(), isec-1);
1356 if (fSegmentationType == 1)
1357 yOnPad=(c->GetY(cath)-y)/fSeg[cath]->Dpy(isec);
1359 yOnPad=(c->GetY(cath)-y)/fSeg2[cath]->Dpy(fInput->DetElemId(), isec);
1361 c->SetY(cath, c->GetY(cath)-cogCorr->Eval(yOnPad, 0, 0));
1366 void AliMUONClusterFinderVS::FillCluster(AliMUONRawCluster* c, Int_t cath)
1369 // Completes cluster information starting from list of digits
1379 Float_t xpad, ypad, zpad;
1382 for (Int_t i=0; i<c->GetMultiplicity(cath); i++)
1384 dig = fInput->Digit(cath,c->GetIndex(i,cath));
1385 if (fSegmentationType == 1)
1387 GetPadC(dig->PadX(),dig->PadY(),xpad,ypad, zpad);
1390 GetPadC(fInput->DetElemId(),dig->PadX(),dig->PadY(),xpad,ypad, zpad);
1391 AliDebug(1,Form("x %f y %f cx %f cy %f\n",xpad,ypad,c->GetX(0),c->GetY(0)));
1392 dx = xpad - c->GetX(0);
1393 dy = ypad - c->GetY(0);
1394 dr = TMath::Sqrt(dx*dx+dy*dy);
1398 AliDebug(1,Form(" dr %f\n",dr));
1399 Int_t q=dig->Signal();
1400 if (dig->Physics() >= dig->Signal()) {
1402 } else if (dig->Physics() == 0) {
1404 } else c->SetPhysics(i,1);
1405 c->SetPeakSignal(cath,q);
1406 c->SetTrack(0,dig->Hit());
1407 c->SetTrack(1,dig->Track(0));
1408 c->SetTrack(2,dig->Track(1));
1409 AliDebug(1,Form(" c->fTracks[0] %d c->fTracks[1] %d\n",dig->Hit(),
1413 } // loop over digits
1415 // apply correction to the coordinate along the anode wire
1417 if (fSegmentationType == 1)
1418 c->SetX(cath,fSeg[cath]->GetAnod(c->GetX(cath)));
1420 c->SetX(cath,fSeg2[cath]->GetAnod(fInput->DetElemId(), c->GetX(cath)));
1423 void AliMUONClusterFinderVS::FindCluster(Int_t i, Int_t j, Int_t cath, AliMUONRawCluster &c){
1427 // Find a super cluster on both cathodes
1430 // Add i,j as element of the cluster
1433 Int_t idx = fHitMap[cath]->GetHitIndex(i,j);
1434 AliMUONDigit* dig = (AliMUONDigit*) fHitMap[cath]->GetHit(i,j);
1435 Int_t q=dig->Signal();
1436 Int_t theX=dig->PadX();
1437 Int_t theY=dig->PadY();
1439 if (q > TMath::Abs(c.GetPeakSignal(0)) && q > TMath::Abs(c.GetPeakSignal(1))) {
1440 c.SetPeakSignal(cath,q);
1441 c.SetTrack(0,dig->Hit());
1442 c.SetTrack(1,dig->Track(0));
1443 c.SetTrack(2,dig->Track(1));
1447 // Make sure that list of digits is ordered
1449 Int_t mu=c.GetMultiplicity(cath);
1450 c.SetIndex(mu, cath, idx);
1452 if (dig->Physics() >= dig->Signal()) {
1454 } else if (dig->Physics() == 0) {
1456 } else c.SetPhysics(mu,1);
1460 for (Int_t ind = mu-1; ind >= 0; ind--) {
1461 Int_t ist=c.GetIndex(ind,cath);
1462 Int_t ql=fInput->Digit(cath, ist)->Signal();
1463 Int_t ix=fInput->Digit(cath, ist)->PadX();
1464 Int_t iy=fInput->Digit(cath, ist)->PadY();
1466 if (q>ql || (q==ql && theX > ix && theY < iy)) {
1467 c.SetIndex(ind, cath, idx);
1468 c.SetIndex(ind+1, cath, ist);
1476 c.SetMultiplicity(cath, c.GetMultiplicity(cath)+1);
1477 if (c.GetMultiplicity(cath) >= 50 ) {
1478 AliDebug(1,Form("FindCluster - multiplicity >50 %d \n",c.GetMultiplicity(0)));
1479 c.SetMultiplicity(cath, 49);
1482 // Prepare center of gravity calculation
1484 if (fSegmentationType == 1)
1485 fSeg[cath]->GetPadC(i, j, x, y, z);
1487 fSeg2[cath]->GetPadC(fInput->DetElemId(), i, j, x, y, z);
1490 c.AddCharge(cath,q);
1492 // Flag hit as "taken"
1493 fHitMap[cath]->FlagHit(i,j);
1495 // Now look recursively for all neighbours and pad hit on opposite cathode
1497 // Loop over neighbours
1501 Int_t xList[10], yList[10];
1502 if (fSegmentationType == 1)
1503 fSeg[cath]->Neighbours(i,j,&nn,xList,yList);
1505 fSeg2[cath]->Neighbours(fInput->DetElemId(), i,j,&nn,xList,yList);
1506 for (Int_t in=0; in<nn; in++) {
1510 if (fHitMap[cath]->TestHit(ix,iy)==kUnused) {
1511 AliDebug(2,Form("\n Neighbours %d %d %d", cath, ix, iy));
1512 FindCluster(ix, iy, cath, c);
1517 Int_t iXopp[50], iYopp[50];
1519 // Neighbours on opposite cathode
1520 // Take into account that several pads can overlap with the present pad
1522 if (fSegmentationType == 1)
1523 isec=fSeg[cath]->Sector(i,j);
1525 isec=fSeg2[cath]->Sector(fInput->DetElemId(), i,j);
1530 if (fSegmentationType == 1) {
1533 dx = (fSeg[cath]->Dpx(isec))/2.;
1538 dy = (fSeg[cath]->Dpy(isec))/2;
1543 // loop over pad neighbours on opposite cathode
1544 for (fSeg[iop]->FirstPad(x, y, fZPlane, dx, dy);
1545 fSeg[iop]->MorePads();
1546 fSeg[iop]->NextPad())
1549 ix = fSeg[iop]->Ix(); iy = fSeg[iop]->Iy();
1550 AliDebug(2,Form("\n ix, iy: %f %f %f %d %d %d", x,y,z,ix, iy, fSector));
1551 if (fHitMap[iop]->TestHit(ix,iy)==kUnused){
1554 AliDebug(2,Form("\n Opposite %d %d %d", iop, ix, iy));
1557 } // Loop over pad neighbours
1558 // This had to go outside the loop since recursive calls inside the iterator are not possible
1561 for (jopp=0; jopp<nOpp; jopp++) {
1562 if (fHitMap[iop]->TestHit(iXopp[jopp],iYopp[jopp]) == kUnused)
1563 FindCluster(iXopp[jopp], iYopp[jopp], iop, c);
1569 dx = (fSeg2[cath]->Dpx(fInput->DetElemId(), isec))/2.;
1574 dy = (fSeg2[cath]->Dpy(fInput->DetElemId(), isec))/2;
1579 // loop over pad neighbours on opposite cathode
1580 for (fSeg2[iop]->FirstPad(fInput->DetElemId(), x, y, fZPlane, dx, dy);
1581 fSeg2[iop]->MorePads(fInput->DetElemId());
1582 fSeg2[iop]->NextPad(fInput->DetElemId()))
1585 ix = fSeg2[iop]->Ix(); iy = fSeg2[iop]->Iy();
1586 AliDebug(2,Form("\n ix, iy: %f %f %f %d %d %d", x,y,z,ix, iy, fSector));
1587 if (fHitMap[iop]->TestHit(ix,iy)==kUnused){
1590 AliDebug(2,Form("\n Opposite %d %d %d", iop, ix, iy));
1593 } // Loop over pad neighbours
1594 // This had to go outside the loop since recursive calls inside the iterator are not possible
1597 for (jopp=0; jopp<nOpp; jopp++) {
1598 if (fHitMap[iop]->TestHit(iXopp[jopp],iYopp[jopp]) == kUnused)
1599 FindCluster(iXopp[jopp], iYopp[jopp], iop, c);
1604 //_____________________________________________________________________________
1606 void AliMUONClusterFinderVS::FindRawClusters()
1609 // MUON cluster finder from digits -- finds neighbours on both cathodes and
1610 // fills the tree with raw clusters
1614 // Return if no input datad available
1615 if (!fInput->NDigits(0) && !fInput->NDigits(1)) return;
1617 fSegmentationType = fInput->GetSegmentationType();
1619 if (fSegmentationType == 1) {
1620 fSeg[0] = fInput->Segmentation(0);
1621 fSeg[1] = fInput->Segmentation(1);
1623 fHitMap[0] = new AliMUONHitMapA1(fSeg[0], fInput->Digits(0));
1624 fHitMap[1] = new AliMUONHitMapA1(fSeg[1], fInput->Digits(1));
1627 fSeg2[0] = fInput->Segmentation2(0);
1628 fSeg2[1] = fInput->Segmentation2(1);
1630 fHitMap[0] = new AliMUONHitMapA1(fInput->DetElemId(), fSeg2[0], fInput->Digits(0));
1631 fHitMap[1] = new AliMUONHitMapA1(fInput->DetElemId(), fSeg2[1], fInput->Digits(1));
1639 fHitMap[0]->FillHits();
1640 fHitMap[1]->FillHits();
1642 // Outer Loop over Cathodes
1643 for (cath=0; cath<2; cath++) {
1645 for (ndig=0; ndig<fInput->NDigits(cath); ndig++) {
1646 dig = fInput->Digit(cath, ndig);
1647 Int_t padx = dig->PadX();
1648 Int_t pady = dig->PadY();
1649 if (fHitMap[cath]->TestHit(padx,pady)==kUsed ||fHitMap[0]->TestHit(padx,pady)==kEmpty) {
1653 AliDebug(1,Form("\n CATHODE %d CLUSTER %d\n",cath,ncls));
1654 AliMUONRawCluster clus;
1655 clus.SetMultiplicity(0, 0);
1656 clus.SetMultiplicity(1, 0);
1657 clus.SetPeakSignal(cath,dig->Signal());
1658 clus.SetTrack(0, dig->Hit());
1659 clus.SetTrack(1, dig->Track(0));
1660 clus.SetTrack(2, dig->Track(1));
1662 AliDebug(1,Form("idDE %d Padx %d Pady %d", fInput->DetElemId(), padx, pady));
1664 // tag the beginning of cluster list in a raw cluster
1665 clus.SetNcluster(0,-1);
1667 if (fSegmentationType == 1) {
1668 fSeg[cath]->GetPadC(padx,pady, xcu, ycu, fZPlane);
1669 fSector= fSeg[cath]->Sector(padx,pady)/100;
1671 fSeg2[cath]->GetPadC(fInput->DetElemId(), padx, pady, xcu, ycu, fZPlane);
1672 fSector= fSeg2[cath]->Sector(fInput->DetElemId(), padx, pady)/100;
1677 FindCluster(padx,pady,cath,clus);
1678 // ^^^^^^^^^^^^^^^^^^^^^^^^
1679 // center of gravity
1680 if (clus.GetX(0)!=0.) clus.SetX(0, clus.GetX(0)/clus.GetCharge(0)); // clus.fX[0] /= clus.fQ[0];
1683 if (fSegmentationType == 1)
1684 clus.SetX(0,fSeg[0]->GetAnod(clus.GetX(0)));
1686 clus.SetX(0,fSeg2[0]->GetAnod(fInput->DetElemId(), clus.GetX(0)));
1687 if (clus.GetY(0)!=0.) clus.SetY(0, clus.GetY(0)/clus.GetCharge(0)); // clus.fY[0] /= clus.fQ[0];
1689 if(clus.GetCharge(1)!=0.) clus.SetX(1, clus.GetX(1)/clus.GetCharge(1)); // clus.fX[1] /= clus.fQ[1];
1692 if (fSegmentationType == 1)
1693 clus.SetX(1, fSeg[0]->GetAnod(clus.GetX(1)));
1695 clus.SetX(1, fSeg2[0]->GetAnod(fInput->DetElemId(),clus.GetX(1)));
1696 if(clus.GetCharge(1)!=0.) clus.SetY(1, clus.GetY(1)/clus.GetCharge(1));// clus.fY[1] /= clus.fQ[1];
1698 clus.SetZ(0, fZPlane);
1699 clus.SetZ(1, fZPlane);
1701 AliDebug(1,Form("\n Cathode 1 multiplicite %d X(CG) %f Y(CG) %f\n",
1702 clus.GetMultiplicity(0),clus.GetX(0),clus.GetY(0)));
1703 AliDebug(1,Form(" Cathode 2 multiplicite %d X(CG) %f Y(CG) %f\n",
1704 clus.GetMultiplicity(1),clus.GetX(1),clus.GetY(1)));
1705 // Analyse cluster and decluster if necessary
1708 clus.SetNcluster(1,fNRawClusters);
1709 clus.SetClusterType(clus.PhysicsContribution());
1716 // reset Cluster object
1717 { // begin local scope
1718 for (int k=0;k<clus.GetMultiplicity(0);k++) clus.SetIndex(k, 0, 0);
1719 } // end local scope
1721 { // begin local scope
1722 for (int k=0;k<clus.GetMultiplicity(1);k++) clus.SetIndex(k, 1, 0);
1723 } // end local scope
1725 clus.SetMultiplicity(0,0);
1726 clus.SetMultiplicity(1,0);
1730 } // end loop cathodes
1735 Float_t AliMUONClusterFinderVS::SingleMathiesonFit(AliMUONRawCluster *c, Int_t cath)
1737 // Performs a single Mathieson fit on one cathode
1739 Double_t arglist[20];
1741 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
1743 clusterInput.Fitter()->SetFCN(fcnS1);
1744 clusterInput.Fitter()->mninit(2,10,7);
1745 clusterInput.Fitter()->SetPrintLevel(-1+fDebugLevel);
1747 clusterInput.Fitter()->mnexcm("SET NOW", arglist, 0, ierflag);
1748 // Set starting values
1749 static Double_t vstart[2];
1750 vstart[0]=c->GetX(1);
1751 vstart[1]=c->GetY(0);
1754 // lower and upper limits
1755 static Double_t lower[2], upper[2];
1757 if (fSegmentationType == 1) {
1758 fSeg[cath]->GetPadI(c->GetX(cath), c->GetY(cath), fZPlane, ix, iy);
1759 isec=fSeg[cath]->Sector(ix, iy);
1761 lower[0]=vstart[0]-fSeg[cath]->Dpx(isec)/2;
1762 lower[1]=vstart[1]-fSeg[cath]->Dpy(isec)/2;
1764 upper[0]=lower[0]+fSeg[cath]->Dpx(isec);
1765 upper[1]=lower[1]+fSeg[cath]->Dpy(isec);
1768 fSeg2[cath]->GetPadI(fInput->DetElemId(), c->GetX(cath), c->GetY(cath), fZPlane, ix, iy);
1769 isec=fSeg2[cath]->Sector(fInput->DetElemId(), ix, iy);
1771 lower[0]=vstart[0]-fSeg2[cath]->Dpx(fInput->DetElemId(), isec)/2;
1772 lower[1]=vstart[1]-fSeg2[cath]->Dpy(fInput->DetElemId(), isec)/2;
1774 upper[0]=lower[0]+fSeg2[cath]->Dpx(fInput->DetElemId(), isec);
1775 upper[1]=lower[1]+fSeg2[cath]->Dpy(fInput->DetElemId(), isec);
1779 static Double_t step[2]={0.0005, 0.0005};
1781 clusterInput.Fitter()->mnparm(0,"x1",vstart[0],step[0],lower[0],upper[0],ierflag);
1782 clusterInput.Fitter()->mnparm(1,"y1",vstart[1],step[1],lower[1],upper[1],ierflag);
1783 // ready for minimisation
1787 clusterInput.Fitter()->mnexcm("SET NOGR", arglist, 0, ierflag);
1788 clusterInput.Fitter()->mnexcm("MIGRAD", arglist, 0, ierflag);
1789 // clusterInput.Fitter()->mnexcm("EXIT" , arglist, 0, ierflag);
1790 Double_t fmin, fedm, errdef;
1791 Int_t npari, nparx, istat;
1793 clusterInput.Fitter()->mnstat(fmin, fedm, errdef, npari, nparx, istat);
1797 // Get fitted parameters
1798 Double_t xrec, yrec;
1800 Double_t epxz, b1, b2;
1802 clusterInput.Fitter()->mnpout(0, chname, xrec, epxz, b1, b2, ierflg);
1803 clusterInput.Fitter()->mnpout(1, chname, yrec, epxz, b1, b2, ierflg);
1809 Float_t AliMUONClusterFinderVS::CombiSingleMathiesonFit(AliMUONRawCluster * /*c*/)
1811 // Perform combined Mathieson fit on both cathode planes
1813 Double_t arglist[20];
1815 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
1816 clusterInput.Fitter()->SetFCN(fcnCombiS1);
1817 clusterInput.Fitter()->mninit(2,10,7);
1818 clusterInput.Fitter()->SetPrintLevel(-1+fDebugLevel);
1820 clusterInput.Fitter()->mnexcm("SET NOW", arglist, 0, ierflag);
1821 static Double_t vstart[2];
1822 vstart[0]=fXInit[0];
1823 vstart[1]=fYInit[0];
1826 // lower and upper limits
1827 static Float_t lower[2], upper[2];
1831 if (fSegmentationType == 1) {
1832 fSeg[0]->GetPadI(fXInit[0], fYInit[0], fZPlane, ix, iy);
1833 isec=fSeg[0]->Sector(ix, iy);
1834 dpy=fSeg[0]->Dpy(isec);
1835 fSeg[1]->GetPadI(fXInit[0], fYInit[0], fZPlane, ix, iy);
1836 isec=fSeg[1]->Sector(ix, iy);
1837 dpx=fSeg[1]->Dpx(isec);
1840 fSeg2[0]->GetPadI(fInput->DetElemId(), fXInit[0], fYInit[0], fZPlane, ix, iy);
1841 isec=fSeg2[0]->Sector(fInput->DetElemId(), ix, iy);
1842 dpy=fSeg2[0]->Dpy(fInput->DetElemId(), isec);
1843 fSeg2[1]->GetPadI(fInput->DetElemId(), fXInit[0], fYInit[0], fZPlane, ix, iy);
1844 isec=fSeg2[1]->Sector(fInput->DetElemId(), ix, iy);
1845 dpx=fSeg2[1]->Dpx(fInput->DetElemId(), isec);
1849 Float_t xdum, ydum, zdum;
1851 // Find save upper and lower limits
1854 if (fSegmentationType == 1) {
1855 for (fSeg[1]->FirstPad(fXInit[0], fYInit[0], fZPlane, dpx, 0.);
1856 fSeg[1]->MorePads();
1859 ix=fSeg[1]->Ix(); iy=fSeg[1]->Iy();
1860 fSeg[1]->GetPadC(ix,iy, upper[0], ydum, zdum);
1861 if (icount ==0) lower[0]=upper[0];
1865 for (fSeg2[1]->FirstPad(fInput->DetElemId(),fXInit[0], fYInit[0], fZPlane, dpx, 0.);
1866 fSeg2[1]->MorePads(fInput->DetElemId());
1867 fSeg2[1]->NextPad(fInput->DetElemId()))
1869 ix=fSeg2[1]->Ix(); iy=fSeg2[1]->Iy();
1870 fSeg2[1]->GetPadC(fInput->DetElemId(), ix,iy, upper[0], ydum, zdum);
1871 if (icount ==0) lower[0]=upper[0];
1875 if (lower[0]>upper[0]) {xdum=lower[0]; lower[0]=upper[0]; upper[0]=xdum;}
1878 AliDebug(1,Form("\n single y %f %f", fXInit[0], fYInit[0]));
1880 if (fSegmentationType == 1) {
1881 for (fSeg[0]->FirstPad(fXInit[0], fYInit[0], fZPlane, 0., dpy);
1882 fSeg[0]->MorePads();
1885 ix=fSeg[0]->Ix(); iy=fSeg[0]->Iy();
1886 fSeg[0]->GetPadC(ix,iy,xdum,upper[1],zdum);
1887 if (icount ==0) lower[1]=upper[1];
1889 AliDebug(1,Form("\n upper lower %d %f %f", icount, upper[1], lower[1]));
1892 for (fSeg2[0]->FirstPad(fInput->DetElemId(), fXInit[0], fYInit[0], fZPlane, 0., dpy);
1893 fSeg2[0]->MorePads(fInput->DetElemId());
1894 fSeg2[0]->NextPad(fInput->DetElemId()))
1896 ix=fSeg2[0]->Ix(); iy=fSeg2[0]->Iy();
1897 fSeg2[0]->GetPadC(fInput->DetElemId(), ix,iy,xdum,upper[1],zdum);
1898 if (icount ==0) lower[1]=upper[1];
1900 AliDebug(1,Form("\n upper lower %d %f %f", icount, upper[1], lower[1]));
1903 if (lower[1]>upper[1]) {xdum=lower[1]; lower[1]=upper[1]; upper[1]=xdum;}
1906 static Double_t step[2]={0.00001, 0.0001};
1908 clusterInput.Fitter()->mnparm(0,"x1",vstart[0],step[0],lower[0],upper[0],ierflag);
1909 clusterInput.Fitter()->mnparm(1,"y1",vstart[1],step[1],lower[1],upper[1],ierflag);
1910 // ready for minimisation
1914 clusterInput.Fitter()->mnexcm("SET NOGR", arglist, 0, ierflag);
1915 clusterInput.Fitter()->mnexcm("MIGRAD", arglist, 0, ierflag);
1916 // clusterInput.Fitter()->mnexcm("EXIT" , arglist, 0, ierflag);
1917 Double_t fmin, fedm, errdef;
1918 Int_t npari, nparx, istat;
1920 clusterInput.Fitter()->mnstat(fmin, fedm, errdef, npari, nparx, istat);
1924 // Get fitted parameters
1925 Double_t xrec, yrec;
1927 Double_t epxz, b1, b2;
1929 clusterInput.Fitter()->mnpout(0, chname, xrec, epxz, b1, b2, ierflg);
1930 clusterInput.Fitter()->mnpout(1, chname, yrec, epxz, b1, b2, ierflg);
1936 Bool_t AliMUONClusterFinderVS::DoubleMathiesonFit(AliMUONRawCluster * /*c*/, Int_t cath)
1938 // Performs a double Mathieson fit on one cathode
1942 // Initialise global variables for fit
1943 Double_t arglist[20];
1945 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
1946 clusterInput.Fitter()->SetFCN(fcnS2);
1947 clusterInput.Fitter()->mninit(5,10,7);
1948 clusterInput.Fitter()->SetPrintLevel(-1+fDebugLevel);
1950 clusterInput.Fitter()->mnexcm("SET NOW", arglist, 0, ierflag);
1951 // Set starting values
1952 static Double_t vstart[5];
1953 vstart[0]=fX[fIndLocal[0][cath]][cath];
1954 vstart[1]=fY[fIndLocal[0][cath]][cath];
1955 vstart[2]=fX[fIndLocal[1][cath]][cath];
1956 vstart[3]=fY[fIndLocal[1][cath]][cath];
1957 vstart[4]=Float_t(fQ[fIndLocal[0][cath]][cath])/
1958 Float_t(fQ[fIndLocal[0][cath]][cath]+fQ[fIndLocal[1][cath]][cath]);
1959 // lower and upper limits
1960 static Float_t lower[5], upper[5];
1963 if (fSegmentationType == 1) {
1964 isec=fSeg[cath]->Sector(fIx[fIndLocal[0][cath]][cath], fIy[fIndLocal[0][cath]][cath]);
1965 lower[0]=vstart[0]-fSeg[cath]->Dpx(isec);
1966 lower[1]=vstart[1]-fSeg[cath]->Dpy(isec);
1968 upper[0]=lower[0]+2.*fSeg[cath]->Dpx(isec);
1969 upper[1]=lower[1]+2.*fSeg[cath]->Dpy(isec);
1971 isec=fSeg[cath]->Sector(fIx[fIndLocal[1][cath]][cath], fIy[fIndLocal[1][cath]][cath]);
1972 lower[2]=vstart[2]-fSeg[cath]->Dpx(isec)/2;
1973 lower[3]=vstart[3]-fSeg[cath]->Dpy(isec)/2;
1975 upper[2]=lower[2]+fSeg[cath]->Dpx(isec);
1976 upper[3]=lower[3]+fSeg[cath]->Dpy(isec);
1979 isec=fSeg2[cath]->Sector(fInput->DetElemId(),fIx[fIndLocal[0][cath]][cath],
1980 fIy[fIndLocal[0][cath]][cath]);
1981 lower[0]=vstart[0]-fSeg2[cath]->Dpx(fInput->DetElemId(),isec);
1982 lower[1]=vstart[1]-fSeg2[cath]->Dpy(fInput->DetElemId(),isec);
1984 upper[0]=lower[0]+2.*fSeg2[cath]->Dpx(fInput->DetElemId(),isec);
1985 upper[1]=lower[1]+2.*fSeg2[cath]->Dpy(fInput->DetElemId(),isec);
1987 isec=fSeg2[cath]->Sector(fInput->DetElemId(),fIx[fIndLocal[1][cath]][cath],
1988 fIy[fIndLocal[1][cath]][cath]);
1989 lower[2]=vstart[2]-fSeg2[cath]->Dpx(fInput->DetElemId(),isec)/2;
1990 lower[3]=vstart[3]-fSeg2[cath]->Dpy(fInput->DetElemId(),isec)/2;
1992 upper[2]=lower[2]+fSeg2[cath]->Dpx(fInput->DetElemId(),isec);
1993 upper[1]=lower[1]+2.*fSeg2[cath]->Dpy(fInput->DetElemId(),isec);
2000 static Double_t step[5]={0.0005, 0.0005, 0.0005, 0.0005, 0.0001};
2002 clusterInput.Fitter()->mnparm(0,"x1",vstart[0],step[0],lower[0],upper[0],ierflag);
2003 clusterInput.Fitter()->mnparm(1,"y1",vstart[1],step[1],lower[1],upper[1],ierflag);
2004 clusterInput.Fitter()->mnparm(2,"x2",vstart[2],step[2],lower[2],upper[2],ierflag);
2005 clusterInput.Fitter()->mnparm(3,"y2",vstart[3],step[3],lower[3],upper[3],ierflag);
2006 clusterInput.Fitter()->mnparm(4,"a0",vstart[4],step[4],lower[4],upper[4],ierflag);
2007 // ready for minimisation
2011 clusterInput.Fitter()->mnexcm("SET NOGR", arglist, 0, ierflag);
2012 clusterInput.Fitter()->mnexcm("MIGRAD", arglist, 0, ierflag);
2013 // clusterInput.Fitter()->mnexcm("EXIT" , arglist, 0, ierflag);
2014 // Get fitted parameters
2015 Double_t xrec[2], yrec[2], qfrac;
2017 Double_t epxz, b1, b2;
2019 clusterInput.Fitter()->mnpout(0, chname, xrec[0], epxz, b1, b2, ierflg);
2020 clusterInput.Fitter()->mnpout(1, chname, yrec[0], epxz, b1, b2, ierflg);
2021 clusterInput.Fitter()->mnpout(2, chname, xrec[1], epxz, b1, b2, ierflg);
2022 clusterInput.Fitter()->mnpout(3, chname, yrec[1], epxz, b1, b2, ierflg);
2023 clusterInput.Fitter()->mnpout(4, chname, qfrac, epxz, b1, b2, ierflg);
2025 Double_t fmin, fedm, errdef;
2026 Int_t npari, nparx, istat;
2028 clusterInput.Fitter()->mnstat(fmin, fedm, errdef, npari, nparx, istat);
2033 Float_t AliMUONClusterFinderVS::CombiDoubleMathiesonFit(AliMUONRawCluster * /*c*/)
2036 // Perform combined double Mathieson fit on both cathode planes
2038 Double_t arglist[20];
2040 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
2041 clusterInput.Fitter()->SetFCN(fcnCombiS2);
2042 clusterInput.Fitter()->mninit(6,10,7);
2043 clusterInput.Fitter()->SetPrintLevel(-1+fDebugLevel);
2045 clusterInput.Fitter()->mnexcm("SET NOW", arglist, 0, ierflag);
2046 // Set starting values
2047 static Double_t vstart[6];
2048 vstart[0]=fXInit[0];
2049 vstart[1]=fYInit[0];
2050 vstart[2]=fXInit[1];
2051 vstart[3]=fYInit[1];
2052 vstart[4]=fQrInit[0];
2053 vstart[5]=fQrInit[1];
2054 // lower and upper limits
2055 static Float_t lower[6], upper[6];
2058 if (fSegmentationType == 1) {
2059 fSeg[1]->GetPadI(fXInit[0], fYInit[0], fZPlane, ix, iy);
2060 isec=fSeg[1]->Sector(ix, iy);
2061 dpx=fSeg[1]->Dpx(isec);
2063 fSeg[0]->GetPadI(fXInit[0], fYInit[0], fZPlane, ix, iy);
2064 isec=fSeg[0]->Sector(ix, iy);
2065 dpy=fSeg[0]->Dpy(isec);
2068 fSeg2[1]->GetPadI(fInput->DetElemId(),fXInit[0], fYInit[0], fZPlane, ix, iy);
2069 isec=fSeg2[1]->Sector(fInput->DetElemId(),ix, iy);
2070 dpx=fSeg2[1]->Dpx(fInput->DetElemId(), isec);
2072 fSeg2[0]->GetPadI(fInput->DetElemId(), fXInit[0], fYInit[0], fZPlane, ix, iy);
2073 isec=fSeg2[0]->Sector(fInput->DetElemId(), ix, iy);
2074 dpy=fSeg2[0]->Dpy(fInput->DetElemId(), isec);
2079 Float_t xdum, ydum, zdum;
2080 AliDebug(1,Form("\n Cluster Finder: %f %f %f %f ", fXInit[0], fXInit[1],fYInit[0], fYInit[1] ));
2082 if (fSegmentationType == 1) {
2084 // Find save upper and lower limits
2087 for (fSeg[1]->FirstPad(fXInit[0], fYInit[0], fZPlane, dpx, 0.);
2088 fSeg[1]->MorePads();
2091 ix=fSeg[1]->Ix(); iy=fSeg[1]->Iy();
2092 // if (fHitMap[1]->TestHit(ix, iy) == kEmpty) continue;
2093 fSeg[1]->GetPadC(ix,iy,upper[0],ydum,zdum);
2094 if (icount ==0) lower[0]=upper[0];
2097 if (lower[0]>upper[0]) {xdum=lower[0]; lower[0]=upper[0]; upper[0]=xdum;}
2098 // vstart[0] = 0.5*(lower[0]+upper[0]);
2103 for (fSeg[0]->FirstPad(fXInit[0], fYInit[0], fZPlane, 0., dpy);
2104 fSeg[0]->MorePads();
2107 ix=fSeg[0]->Ix(); iy=fSeg[0]->Iy();
2108 // if (fHitMap[0]->TestHit(ix, iy) == kEmpty) continue;
2109 fSeg[0]->GetPadC(ix,iy,xdum,upper[1],zdum);
2110 if (icount ==0) lower[1]=upper[1];
2114 if (lower[1]>upper[1]) {xdum=lower[1]; lower[1]=upper[1]; upper[1]=xdum;}
2115 // vstart[1] = 0.5*(lower[1]+upper[1]);
2118 fSeg[1]->GetPadI(fXInit[1], fYInit[1], fZPlane, ix, iy);
2119 isec=fSeg[1]->Sector(ix, iy);
2120 dpx=fSeg[1]->Dpx(isec);
2121 fSeg[0]->GetPadI(fXInit[1], fYInit[1], fZPlane, ix, iy);
2122 isec=fSeg[0]->Sector(ix, iy);
2123 dpy=fSeg[0]->Dpy(isec);
2126 // Find save upper and lower limits
2130 for (fSeg[1]->FirstPad(fXInit[1], fYInit[1], fZPlane, dpx, 0);
2131 fSeg[1]->MorePads(); fSeg[1]->NextPad())
2133 ix=fSeg[1]->Ix(); iy=fSeg[1]->Iy();
2134 // if (fHitMap[1]->TestHit(ix, iy) == kEmpty) continue;
2135 fSeg[1]->GetPadC(ix,iy,upper[2],ydum,zdum);
2136 if (icount ==0) lower[2]=upper[2];
2139 if (lower[2]>upper[2]) {xdum=lower[2]; lower[2]=upper[2]; upper[2]=xdum;}
2140 // vstart[2] = 0.5*(lower[2]+upper[2]);
2144 for (fSeg[0]->FirstPad(fXInit[1], fYInit[1], fZPlane, 0, dpy);
2145 fSeg[0]-> MorePads(); fSeg[0]->NextPad())
2147 ix=fSeg[0]->Ix(); iy=fSeg[0]->Iy();
2148 // if (fHitMap[0]->TestHit(ix, iy) != kEmpty) continue;
2150 fSeg[0]->GetPadC(ix,iy,xdum,upper[3],zdum);
2151 if (icount ==0) lower[3]=upper[3];
2155 if (lower[3]>upper[3]) {xdum=lower[3]; lower[3]=upper[3]; upper[3]=xdum;}
2157 // vstart[3] = 0.5*(lower[3]+upper[3]);
2160 // Find save upper and lower limits
2163 for (fSeg2[1]->FirstPad(fInput->DetElemId(),fXInit[0], fYInit[0], fZPlane, dpx, 0.);
2164 fSeg2[1]->MorePads(fInput->DetElemId());
2165 fSeg2[1]->NextPad(fInput->DetElemId()))
2167 ix=fSeg2[1]->Ix(); iy=fSeg2[1]->Iy();
2168 // if (fHitMap[1]->TestHit(ix, iy) == kEmpty) continue;
2169 fSeg2[1]->GetPadC(fInput->DetElemId(),ix,iy,upper[0],ydum,zdum);
2170 if (icount ==0) lower[0]=upper[0];
2173 if (lower[0]>upper[0]) {xdum=lower[0]; lower[0]=upper[0]; upper[0]=xdum;}
2174 // vstart[0] = 0.5*(lower[0]+upper[0]);
2179 for (fSeg2[0]->FirstPad(fInput->DetElemId(),fXInit[0], fYInit[0], fZPlane, 0., dpy);
2180 fSeg2[0]->MorePads(fInput->DetElemId());
2181 fSeg2[0]->NextPad(fInput->DetElemId()))
2183 ix=fSeg2[0]->Ix(); iy=fSeg2[0]->Iy();
2184 // if (fHitMap[0]->TestHit(ix, iy) == kEmpty) continue;
2185 fSeg2[0]->GetPadC(fInput->DetElemId(),ix,iy,xdum,upper[1],zdum);
2186 if (icount ==0) lower[1]=upper[1];
2190 if (lower[1]>upper[1]) {xdum=lower[1]; lower[1]=upper[1]; upper[1]=xdum;}
2191 // vstart[1] = 0.5*(lower[1]+upper[1]);
2194 fSeg2[1]->GetPadI(fInput->DetElemId(),fXInit[1], fYInit[1], fZPlane, ix, iy);
2195 isec=fSeg2[1]->Sector(fInput->DetElemId(),ix, iy);
2196 dpx=fSeg2[1]->Dpx(fInput->DetElemId(),isec);
2197 fSeg2[0]->GetPadI(fInput->DetElemId(),fXInit[1], fYInit[1], fZPlane, ix, iy);
2198 isec=fSeg2[0]->Sector(fInput->DetElemId(),ix, iy);
2199 dpy=fSeg2[0]->Dpy(fInput->DetElemId(),isec);
2202 // Find save upper and lower limits
2206 for (fSeg2[1]->FirstPad(fInput->DetElemId(),fXInit[1], fYInit[1], fZPlane, dpx, 0);
2207 fSeg2[1]->MorePads(fInput->DetElemId());
2208 fSeg2[1]->NextPad(fInput->DetElemId()))
2210 ix=fSeg2[1]->Ix(); iy=fSeg2[1]->Iy();
2211 // if (fHitMap[1]->TestHit(ix, iy) == kEmpty) continue;
2212 fSeg2[1]->GetPadC(fInput->DetElemId(),ix,iy,upper[2],ydum,zdum);
2213 if (icount ==0) lower[2]=upper[2];
2216 if (lower[2]>upper[2]) {xdum=lower[2]; lower[2]=upper[2]; upper[2]=xdum;}
2217 // vstart[2] = 0.5*(lower[2]+upper[2]);
2221 for (fSeg2[0]->FirstPad(fInput->DetElemId(),fXInit[1], fYInit[1], fZPlane, 0, dpy);
2222 fSeg2[0]-> MorePads(fInput->DetElemId());
2223 fSeg2[0]->NextPad(fInput->DetElemId()))
2225 ix=fSeg2[0]->Ix(); iy=fSeg2[0]->Iy();
2226 // if (fHitMap[0]->TestHit(ix, iy) != kEmpty) continue;
2228 fSeg2[0]->GetPadC(fInput->DetElemId(),ix,iy,xdum,upper[3],zdum);
2229 if (icount ==0) lower[3]=upper[3];
2233 if (lower[3]>upper[3]) {xdum=lower[3]; lower[3]=upper[3]; upper[3]=xdum;}
2241 static Double_t step[6]={0.0005, 0.0005, 0.0005, 0.0005, 0.001, 0.001};
2242 clusterInput.Fitter()->mnparm(0,"x1",vstart[0],step[0],lower[0],upper[0],ierflag);
2243 clusterInput.Fitter()->mnparm(1,"y1",vstart[1],step[1],lower[1],upper[1],ierflag);
2244 clusterInput.Fitter()->mnparm(2,"x2",vstart[2],step[2],lower[2],upper[2],ierflag);
2245 clusterInput.Fitter()->mnparm(3,"y2",vstart[3],step[3],lower[3],upper[3],ierflag);
2246 clusterInput.Fitter()->mnparm(4,"a0",vstart[4],step[4],lower[4],upper[4],ierflag);
2247 clusterInput.Fitter()->mnparm(5,"a1",vstart[5],step[5],lower[5],upper[5],ierflag);
2248 // ready for minimisation
2252 clusterInput.Fitter()->mnexcm("SET NOGR", arglist, 0, ierflag);
2253 clusterInput.Fitter()->mnexcm("MIGRAD", arglist, 0, ierflag);
2254 // clusterInput.Fitter()->mnexcm("EXIT" , arglist, 0, ierflag);
2255 // Get fitted parameters
2257 Double_t epxz, b1, b2;
2259 clusterInput.Fitter()->mnpout(0, chname, fXFit[0], epxz, b1, b2, ierflg);
2260 clusterInput.Fitter()->mnpout(1, chname, fYFit[0], epxz, b1, b2, ierflg);
2261 clusterInput.Fitter()->mnpout(2, chname, fXFit[1], epxz, b1, b2, ierflg);
2262 clusterInput.Fitter()->mnpout(3, chname, fYFit[1], epxz, b1, b2, ierflg);
2263 clusterInput.Fitter()->mnpout(4, chname, fQrFit[0], epxz, b1, b2, ierflg);
2264 clusterInput.Fitter()->mnpout(5, chname, fQrFit[1], epxz, b1, b2, ierflg);
2266 Double_t fmin, fedm, errdef;
2267 Int_t npari, nparx, istat;
2269 clusterInput.Fitter()->mnstat(fmin, fedm, errdef, npari, nparx, istat);
2277 void AliMUONClusterFinderVS::Split(AliMUONRawCluster* c)
2280 // One cluster for each maximum
2283 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
2284 for (j=0; j<2; j++) {
2285 AliMUONRawCluster cnew;
2286 cnew.SetGhost(c->GetGhost());
2287 for (cath=0; cath<2; cath++) {
2288 cnew.SetChi2(cath,fChi2[0]);
2289 // ?? why not cnew.fChi2[cath]=fChi2[cath];
2292 cnew.SetNcluster(0,-1);
2293 cnew.SetNcluster(1,fNRawClusters);
2295 cnew.SetNcluster(0,fNPeaks);
2296 cnew.SetNcluster(1,0);
2298 cnew.SetMultiplicity(cath,0);
2299 cnew.SetX(cath, Float_t(fXFit[j]));
2300 cnew.SetY(cath, Float_t(fYFit[j]));
2301 cnew.SetZ(cath, fZPlane);
2303 cnew.SetCharge(cath, Int_t(clusterInput.TotalCharge(cath)*fQrFit[cath]));
2305 cnew.SetCharge(cath, Int_t(clusterInput.TotalCharge(cath)*(1-fQrFit[cath])));
2307 if (fSegmentationType == 1)
2308 fSeg[cath]->SetHit(fXFit[j],fYFit[j],fZPlane);
2310 fSeg2[cath]->SetHit(fInput->DetElemId(), fXFit[j],fYFit[j],fZPlane);
2312 for (i=0; i<fMul[cath]; i++) {
2314 cnew.SetIndex(cnew.GetMultiplicity(cath), cath, c->GetIndex(i,cath));
2315 if (fSegmentationType == 1) {
2316 fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
2317 q1 = fInput->Mathieson()->IntXY(fSeg[cath]);
2319 fSeg2[cath]->SetPad(fInput->DetElemId(),fIx[i][cath], fIy[i][cath]);
2320 q1 = fInput->Mathieson()->IntXY(fInput->DetElemId(),fSeg2[cath]);
2322 cnew.SetContrib(i, cath, q1*Float_t(cnew.GetCharge(cath))/Float_t(fQ[i][cath]));
2323 cnew.SetMultiplicity(cath, cnew.GetMultiplicity(cath)+1 );
2325 FillCluster(&cnew,0,cath);
2328 cnew.SetClusterType(cnew.PhysicsContribution());
2329 if (cnew.GetCharge(0)>0 && cnew.GetCharge(1)>0) AddRawCluster(cnew);
2333 void AliMUONClusterFinderVS::AddRawCluster(const AliMUONRawCluster& c)
2336 // Add a raw cluster copy to the list
2339 // AliMUON *pMUON=(AliMUON*)gAlice->GetModule("MUON");
2340 // pMUON->GetMUONData()->AddRawCluster(fInput->Chamber(),c);
2344 TClonesArray &lrawcl = *fRawClusters;
2345 new(lrawcl[fNRawClusters++]) AliMUONRawCluster(c);
2346 AliDebug(1,Form("\nfNRawClusters %d\n",fNRawClusters));
2349 AliMUONClusterFinderVS& AliMUONClusterFinderVS
2350 ::operator = (const AliMUONClusterFinderVS& rhs)
2352 // Protected assignement operator
2354 if (this == &rhs) return *this;
2356 AliFatal("Not implemented.");
2362 // Minimisation functions
2364 void fcnS1(Int_t & /*npar*/, Double_t * /*gin*/, Double_t &f, Double_t *par, Int_t /*iflag*/)
2366 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
2373 for (i=0; i<clusterInput.Nmul(0); i++) {
2374 Float_t q0=clusterInput.Charge(i,0);
2375 Float_t q1=clusterInput.DiscrChargeS1(i,par);
2384 void fcnCombiS1(Int_t & /*npar*/, Double_t * /*gin*/, Double_t &f, Double_t *par, Int_t /*iflag*/)
2386 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
2393 for (cath=0; cath<2; cath++) {
2394 for (i=0; i<clusterInput.Nmul(cath); i++) {
2395 Float_t q0=clusterInput.Charge(i,cath);
2396 Float_t q1=clusterInput.DiscrChargeCombiS1(i,par,cath);
2407 void fcnS2(Int_t & /*npar*/, Double_t * /*gin*/, Double_t &f, Double_t *par, Int_t /*iflag*/)
2409 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
2416 for (i=0; i<clusterInput.Nmul(0); i++) {
2418 Float_t q0=clusterInput.Charge(i,0);
2419 Float_t q1=clusterInput.DiscrChargeS2(i,par);
2429 void fcnCombiS2(Int_t & /*npar*/, Double_t * /*gin*/, Double_t &f, Double_t *par, Int_t /*iflag*/)
2431 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
2437 for (cath=0; cath<2; cath++) {
2438 for (i=0; i<clusterInput.Nmul(cath); i++) {
2439 Float_t q0=clusterInput.Charge(i,cath);
2440 Float_t q1=clusterInput.DiscrChargeCombiS2(i,par,cath);