1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 #include "AliMUONClusterFinderVS.h"
19 #include "AliMUONDigit.h"
20 #include "AliMUONRawCluster.h"
21 #include "AliSegmentation.h"
22 #include "AliMUONResponse.h"
23 #include "AliMUONClusterInput.h"
24 #include "AliMUONHitMapA1.h"
33 #include <TPostScript.h>
38 #include <Riostream.h>
40 //_____________________________________________________________________
41 // This function is minimized in the double-Mathieson fit
42 void fcnS2(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag);
43 void fcnS1(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag);
44 void fcnCombiS1(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag);
45 void fcnCombiS2(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag);
47 ClassImp(AliMUONClusterFinderVS)
49 AliMUONClusterFinderVS::AliMUONClusterFinderVS()
51 // Default constructor
52 fInput=AliMUONClusterInput::Instance();
55 fTrack[0]=fTrack[1]=-1;
56 fDebugLevel = 0; // make silent default
57 fGhostChi2Cut = 1e6; // nothing done by default
60 for(Int_t i=0; i<100; i++) {
61 for (Int_t j=0; j<2; j++) {
67 AliMUONClusterFinderVS::AliMUONClusterFinderVS(
68 const AliMUONClusterFinderVS & clusterFinder)
70 // Dummy copy Constructor
74 void AliMUONClusterFinderVS::Decluster(AliMUONRawCluster *cluster)
76 // Decluster by local maxima
77 SplitByLocalMaxima(cluster);
80 void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
82 // Split complex cluster by local maxima
85 fInput->SetCluster(c);
87 fMul[0]=c->fMultiplicity[0];
88 fMul[1]=c->fMultiplicity[1];
91 // dump digit information into arrays
96 for (cath=0; cath<2; cath++) {
98 for (i=0; i<fMul[cath]; i++)
101 fDig[i][cath]=fInput->Digit(cath, c->fIndexMap[i][cath]);
103 fIx[i][cath]= fDig[i][cath]->PadX();
104 fIy[i][cath]= fDig[i][cath]->PadY();
106 fQ[i][cath] = fDig[i][cath]->Signal();
107 // pad centre coordinates
109 GetPadC(fIx[i][cath], fIy[i][cath], fX[i][cath], fY[i][cath], fZ[i][cath]);
110 } // loop over cluster digits
111 } // loop over cathodes
117 // Initialise and perform mathieson fits
118 Float_t chi2, oldchi2;
119 // ++++++++++++++++++*************+++++++++++++++++++++
120 // (1) No more than one local maximum per cathode plane
121 // +++++++++++++++++++++++++++++++*************++++++++
122 if ((fNLocal[0]==1 && (fNLocal[1]==0 || fNLocal[1]==1)) ||
123 (fNLocal[0]==0 && fNLocal[1]==1)) {
124 // Perform combined single Mathieson fit
125 // Initial values for coordinates (x,y)
127 // One local maximum on cathodes 1 and 2 (X->cathode 2, Y->cathode 1)
128 if (fNLocal[0]==1 && fNLocal[1]==1) {
131 // One local maximum on cathode 1 (X,Y->cathode 1)
132 } else if (fNLocal[0]==1) {
135 // One local maximum on cathode 2 (X,Y->cathode 2)
141 fprintf(stderr,"\n cas (1) CombiSingleMathiesonFit(c)\n");
142 chi2=CombiSingleMathiesonFit(c);
143 // Int_t ndf = fgNbins[0]+fgNbins[1]-2;
144 // Float_t prob = TMath::Prob(Double_t(chi2),ndf);
145 // prob1->Fill(prob);
146 // chi2_1->Fill(chi2);
149 fprintf(stderr," chi2 %f ",chi2);
159 c->fX[0]=fSeg[0]->GetAnod(c->fX[0]);
160 c->fX[1]=fSeg[1]->GetAnod(c->fX[1]);
162 // If reasonable chi^2 add result to the list of rawclusters
165 // If not try combined double Mathieson Fit
167 fprintf(stderr," MAUVAIS CHI2 !!!\n");
168 if (fNLocal[0]==1 && fNLocal[1]==1) {
169 fXInit[0]=fX[fIndLocal[0][1]][1];
170 fYInit[0]=fY[fIndLocal[0][0]][0];
171 fXInit[1]=fX[fIndLocal[0][1]][1];
172 fYInit[1]=fY[fIndLocal[0][0]][0];
173 } else if (fNLocal[0]==1) {
174 fXInit[0]=fX[fIndLocal[0][0]][0];
175 fYInit[0]=fY[fIndLocal[0][0]][0];
176 fXInit[1]=fX[fIndLocal[0][0]][0];
177 fYInit[1]=fY[fIndLocal[0][0]][0];
179 fXInit[0]=fX[fIndLocal[0][1]][1];
180 fYInit[0]=fY[fIndLocal[0][1]][1];
181 fXInit[1]=fX[fIndLocal[0][1]][1];
182 fYInit[1]=fY[fIndLocal[0][1]][1];
185 // Initial value for charge ratios
189 fprintf(stderr,"\n cas (1) CombiDoubleMathiesonFit(c)\n");
190 chi2=CombiDoubleMathiesonFit(c);
191 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
192 // Float_t prob = TMath::Prob(chi2,ndf);
193 // prob2->Fill(prob);
194 // chi2_2->Fill(chi2);
196 // Was this any better ??
197 fprintf(stderr," Old and new chi2 %f %f ", oldchi2, chi2);
198 if (fFitStat!=0 && chi2>0 && (2.*chi2 < oldchi2)) {
199 fprintf(stderr," Split\n");
200 // Split cluster into two according to fit result
203 fprintf(stderr," Don't Split\n");
209 // +++++++++++++++++++++++++++++++++++++++
210 // (2) Two local maxima per cathode plane
211 // +++++++++++++++++++++++++++++++++++++++
212 } else if (fNLocal[0]==2 && fNLocal[1]==2) {
214 // Let's look for ghosts first
216 Float_t xm[4][2], ym[4][2];
217 Float_t dpx, dpy, dx, dy;
218 Int_t ixm[4][2], iym[4][2];
219 Int_t isec, im1, im2, ico;
221 // Form the 2x2 combinations
222 // 0-0, 0-1, 1-0, 1-1
224 for (im1=0; im1<2; im1++) {
225 for (im2=0; im2<2; im2++) {
226 xm[ico][0]=fX[fIndLocal[im1][0]][0];
227 ym[ico][0]=fY[fIndLocal[im1][0]][0];
228 xm[ico][1]=fX[fIndLocal[im2][1]][1];
229 ym[ico][1]=fY[fIndLocal[im2][1]][1];
231 ixm[ico][0]=fIx[fIndLocal[im1][0]][0];
232 iym[ico][0]=fIy[fIndLocal[im1][0]][0];
233 ixm[ico][1]=fIx[fIndLocal[im2][1]][1];
234 iym[ico][1]=fIy[fIndLocal[im2][1]][1];
238 // ico = 0 : first local maximum on cathodes 1 and 2
239 // ico = 1 : fisrt local maximum on cathode 1 and second on cathode 2
240 // ico = 2 : second local maximum on cathode 1 and first on cathode 1
241 // ico = 3 : second local maximum on cathodes 1 and 2
243 // Analyse the combinations and keep those that are possible !
244 // For each combination check consistency in x and y
247 Float_t dr[4] = {1.e4, 1.e4, 1.e4, 1.e4};
250 // In case of staggering maxima are displaced by exactly half the pad-size in y.
251 // We have to take into account the numerical precision in the consistency check;
254 for (ico=0; ico<4; ico++) {
255 accepted[ico]=kFALSE;
256 // cathode one: x-coordinate
257 isec=fSeg[0]->Sector(ixm[ico][0], iym[ico][0]);
258 dpx=fSeg[0]->Dpx(isec)/2.;
259 dx=TMath::Abs(xm[ico][0]-xm[ico][1]);
260 // cathode two: y-coordinate
261 isec=fSeg[1]->Sector(ixm[ico][1], iym[ico][1]);
262 dpy=fSeg[1]->Dpy(isec)/2.;
263 dy=TMath::Abs(ym[ico][0]-ym[ico][1]);
265 printf("\n %i %f %f %f %f %f %f \n", ico, ym[ico][0], ym[ico][1], dy, dpy, dx, dpx );
266 if ((dx <= dpx) && (dy <= dpy+eps)) {
269 dr[ico] = TMath::Sqrt(dx*dx+dy*dy);
273 accepted[ico]=kFALSE;
276 printf("\n iacc= %d:\n", iacc);
278 if (accepted[0] && accepted[1]) {
279 if (dr[0] >= dr[1]) {
286 if (accepted[2] && accepted[3]) {
287 if (dr[2] >= dr[3]) {
294 // eliminate one candidate
298 for (ico=0; ico<4; ico++) {
299 if (accepted[ico] && dr[ico] > drmax) {
305 accepted[icobad] = kFALSE;
311 printf("\n iacc= %d:\n", iacc);
314 fprintf(stderr,"\n iacc=2: No problem ! \n");
315 } else if (iacc==4) {
316 fprintf(stderr,"\n iacc=4: Ok, but ghost problem !!! \n");
317 } else if (iacc==0) {
318 fprintf(stderr,"\n iacc=0: I don't know what to do with this !!!!!!!!! \n");
322 // Initial value for charge ratios
323 fQrInit[0]=Float_t(fQ[fIndLocal[0][0]][0])/
324 Float_t(fQ[fIndLocal[0][0]][0]+fQ[fIndLocal[1][0]][0]);
325 fQrInit[1]=Float_t(fQ[fIndLocal[0][1]][1])/
326 Float_t(fQ[fIndLocal[0][1]][1]+fQ[fIndLocal[1][1]][1]);
328 // ******* iacc = 0 *******
329 // No combinations found between the 2 cathodes
330 // We keep the center of gravity of the cluster
335 // ******* iacc = 1 *******
336 // Only one combination found between the 2 cathodes
338 // Initial values for the 2 maxima (x,y)
340 // 1 maximum is initialised with the maximum of the combination found (X->cathode 2, Y->cathode 1)
341 // 1 maximum is initialised with the other maximum of the first cathode
343 fprintf(stderr,"ico=0\n");
348 } else if (accepted[1]){
349 fprintf(stderr,"ico=1\n");
354 } else if (accepted[2]){
355 fprintf(stderr,"ico=2\n");
360 } else if (accepted[3]){
361 fprintf(stderr,"ico=3\n");
368 fprintf(stderr,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
369 chi2=CombiDoubleMathiesonFit(c);
370 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
371 // Float_t prob = TMath::Prob(chi2,ndf);
372 // prob2->Fill(prob);
373 // chi2_2->Fill(chi2);
375 fprintf(stderr," chi2 %f\n",chi2);
377 // If reasonable chi^2 add result to the list of rawclusters
382 // 1 maximum is initialised with the maximum of the combination found (X->cathode 2, Y->cathode 1)
383 // 1 maximum is initialised with the other maximum of the second cathode
385 fprintf(stderr,"ico=0\n");
390 } else if (accepted[1]){
391 fprintf(stderr,"ico=1\n");
396 } else if (accepted[2]){
397 fprintf(stderr,"ico=2\n");
402 } else if (accepted[3]){
403 fprintf(stderr,"ico=3\n");
410 fprintf(stderr,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
411 chi2=CombiDoubleMathiesonFit(c);
412 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
413 // Float_t prob = TMath::Prob(chi2,ndf);
414 // prob2->Fill(prob);
415 // chi2_2->Fill(chi2);
417 fprintf(stderr," chi2 %f\n",chi2);
419 // If reasonable chi^2 add result to the list of rawclusters
423 //We keep only the combination found (X->cathode 2, Y->cathode 1)
424 for (Int_t ico=0; ico<2; ico++) {
426 AliMUONRawCluster cnew;
428 for (cath=0; cath<2; cath++) {
429 cnew.fX[cath]=Float_t(xm[ico][1]);
430 cnew.fY[cath]=Float_t(ym[ico][0]);
431 cnew.fZ[cath]=fZPlane;
433 cnew.fMultiplicity[cath]=c->fMultiplicity[cath];
434 for (i=0; i<fMul[cath]; i++) {
435 cnew.fIndexMap[i][cath]=c->fIndexMap[i][cath];
436 fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
438 fprintf(stderr,"\nRawCluster %d cath %d\n",ico,cath);
439 fprintf(stderr,"mult_av %d\n",c->fMultiplicity[cath]);
440 FillCluster(&cnew,cath);
442 cnew.fClusterType=cnew.PhysicsContribution();
451 // ******* iacc = 2 *******
452 // Two combinations found between the 2 cathodes
454 // Was the same maximum taken twice
455 if ((accepted[0]&&accepted[1]) || (accepted[2]&&accepted[3])) {
456 fprintf(stderr,"\n Maximum taken twice !!!\n");
458 // Have a try !! with that
459 if (accepted[0]&&accepted[3]) {
471 fprintf(stderr,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
472 chi2=CombiDoubleMathiesonFit(c);
473 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
474 // Float_t prob = TMath::Prob(chi2,ndf);
475 // prob2->Fill(prob);
476 // chi2_2->Fill(chi2);
480 // No ghosts ! No Problems ! - Perform one fit only !
481 if (accepted[0]&&accepted[3]) {
493 fprintf(stderr,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
494 chi2=CombiDoubleMathiesonFit(c);
495 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
496 // Float_t prob = TMath::Prob(chi2,ndf);
497 // prob2->Fill(prob);
498 // chi2_2->Fill(chi2);
500 fprintf(stderr," chi2 %f\n",chi2);
504 // ******* iacc = 4 *******
505 // Four combinations found between the 2 cathodes
507 } else if (iacc==4) {
508 // Perform fits for the two possibilities !!
509 // Accept if charges are compatible on both cathodes
510 // If none are compatible, keep everything
516 fprintf(stderr,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
517 chi2=CombiDoubleMathiesonFit(c);
518 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
519 // Float_t prob = TMath::Prob(chi2,ndf);
520 // prob2->Fill(prob);
521 // chi2_2->Fill(chi2);
523 fprintf(stderr," chi2 %f\n",chi2);
524 // store results of fit and postpone decision
525 Double_t sXFit[2],sYFit[2],sQrFit[2];
527 for (Int_t i=0;i<2;i++) {
538 fprintf(stderr,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
539 chi2=CombiDoubleMathiesonFit(c);
540 // ndf = fgNbins[0]+fgNbins[1]-6;
541 // prob = TMath::Prob(chi2,ndf);
542 // prob2->Fill(prob);
543 // chi2_2->Fill(chi2);
545 fprintf(stderr," chi2 %f\n",chi2);
546 // We have all informations to perform the decision
547 // Compute the chi2 for the 2 possibilities
548 Float_t chi2fi,chi2si,chi2f,chi2s;
550 chi2f = (TMath::Log(fInput->TotalCharge(0)*fQrFit[0]
551 / (fInput->TotalCharge(1)*fQrFit[1]) )
552 / fInput->Response()->ChargeCorrel() );
554 chi2fi = (TMath::Log(fInput->TotalCharge(0)*(1-fQrFit[0])
555 / (fInput->TotalCharge(1)*(1-fQrFit[1])) )
556 / fInput->Response()->ChargeCorrel() );
557 chi2f += chi2fi*chi2fi;
559 chi2s = (TMath::Log(fInput->TotalCharge(0)*sQrFit[0]
560 / (fInput->TotalCharge(1)*sQrFit[1]) )
561 / fInput->Response()->ChargeCorrel() );
563 chi2si = (TMath::Log(fInput->TotalCharge(0)*(1-sQrFit[0])
564 / (fInput->TotalCharge(1)*(1-sQrFit[1])) )
565 / fInput->Response()->ChargeCorrel() );
566 chi2s += chi2si*chi2si;
568 // usefull to store the charge matching chi2 in the cluster
569 // fChi2[0]=sChi2[1]=chi2f;
570 // fChi2[1]=sChi2[0]=chi2s;
572 if (chi2f<=fGhostChi2Cut && chi2s<=fGhostChi2Cut)
574 if (chi2f>fGhostChi2Cut && chi2s>fGhostChi2Cut) {
580 if (chi2f<=fGhostChi2Cut)
582 if (chi2s<=fGhostChi2Cut) {
583 // retreive saved values
584 for (Int_t i=0;i<2;i++) {
595 } else if (fNLocal[0]==2 && fNLocal[1]==1) {
596 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
597 // (3) Two local maxima on cathode 1 and one maximum on cathode 2
598 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
600 Float_t xm[4][2], ym[4][2];
601 Float_t dpx, dpy, dx, dy;
602 Int_t ixm[4][2], iym[4][2];
603 Int_t isec, im1, ico;
605 // Form the 2x2 combinations
606 // 0-0, 0-1, 1-0, 1-1
608 for (im1=0; im1<2; im1++) {
609 xm[ico][0]=fX[fIndLocal[im1][0]][0];
610 ym[ico][0]=fY[fIndLocal[im1][0]][0];
611 xm[ico][1]=fX[fIndLocal[0][1]][1];
612 ym[ico][1]=fY[fIndLocal[0][1]][1];
614 ixm[ico][0]=fIx[fIndLocal[im1][0]][0];
615 iym[ico][0]=fIy[fIndLocal[im1][0]][0];
616 ixm[ico][1]=fIx[fIndLocal[0][1]][1];
617 iym[ico][1]=fIy[fIndLocal[0][1]][1];
620 // ico = 0 : first local maximum on cathodes 1 and 2
621 // ico = 1 : second local maximum on cathode 1 and first on cathode 2
623 // Analyse the combinations and keep those that are possible !
624 // For each combination check consistency in x and y
628 // In case of staggering maxima are displaced by exactly half the pad-size in y.
629 // We have to take into account the numerical precision in the consistency check;
633 for (ico=0; ico<2; ico++) {
634 accepted[ico]=kFALSE;
635 isec=fSeg[0]->Sector(ixm[ico][0], iym[ico][0]);
636 dpx=fSeg[0]->Dpx(isec)/2.;
637 dx=TMath::Abs(xm[ico][0]-xm[ico][1]);
638 isec=fSeg[1]->Sector(ixm[ico][1], iym[ico][1]);
639 dpy=fSeg[1]->Dpy(isec)/2.;
640 dy=TMath::Abs(ym[ico][0]-ym[ico][1]);
642 printf("\n %i %f %f %f %f \n", ico, ym[ico][0], ym[ico][1], dy, dpy );
643 if ((dx <= dpx) && (dy <= dpy+eps)) {
649 accepted[ico]=kFALSE;
657 // Initial value for charge ratios
658 fQrInit[0]=Float_t(fQ[fIndLocal[0][0]][0])/
659 Float_t(fQ[fIndLocal[0][0]][0]+fQ[fIndLocal[1][0]][0]);
660 fQrInit[1]=fQrInit[0];
662 if (accepted[0] && accepted[1]) {
664 fXInit[0]=0.5*(xm[0][1]+xm[0][0]);
666 fXInit[1]=0.5*(xm[0][1]+xm[1][0]);
670 chi23=CombiDoubleMathiesonFit(c);
679 } else if (accepted[0]) {
684 chi21=CombiDoubleMathiesonFit(c);
685 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
686 // Float_t prob = TMath::Prob(chi2,ndf);
687 // prob2->Fill(prob);
688 // chi2_2->Fill(chi21);
690 fprintf(stderr," chi2 %f\n",chi21);
691 if (chi21<10) Split(c);
692 } else if (accepted[1]) {
697 chi22=CombiDoubleMathiesonFit(c);
698 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
699 // Float_t prob = TMath::Prob(chi2,ndf);
700 // prob2->Fill(prob);
701 // chi2_2->Fill(chi22);
703 fprintf(stderr," chi2 %f\n",chi22);
704 if (chi22<10) Split(c);
707 if (chi21 > 10 && chi22 > 10 && chi23 > 10) {
708 // We keep only the combination found (X->cathode 2, Y->cathode 1)
709 for (Int_t ico=0; ico<2; ico++) {
711 AliMUONRawCluster cnew;
713 for (cath=0; cath<2; cath++) {
714 cnew.fX[cath]=Float_t(xm[ico][1]);
715 cnew.fY[cath]=Float_t(ym[ico][0]);
716 cnew.fZ[cath]=fZPlane;
717 cnew.fMultiplicity[cath]=c->fMultiplicity[cath];
718 for (i=0; i<fMul[cath]; i++) {
719 cnew.fIndexMap[i][cath]=c->fIndexMap[i][cath];
720 fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
722 fprintf(stderr,"\nRawCluster %d cath %d\n",ico,cath);
723 fprintf(stderr,"mult_av %d\n",c->fMultiplicity[cath]);
724 FillCluster(&cnew,cath);
726 cnew.fClusterType=cnew.PhysicsContribution();
733 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
734 // (3') One local maximum on cathode 1 and two maxima on cathode 2
735 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
736 } else if (fNLocal[0]==1 && fNLocal[1]==2) {
737 Float_t xm[4][2], ym[4][2];
738 Float_t dpx, dpy, dx, dy;
739 Int_t ixm[4][2], iym[4][2];
740 Int_t isec, im1, ico;
742 // Form the 2x2 combinations
743 // 0-0, 0-1, 1-0, 1-1
745 for (im1=0; im1<2; im1++) {
746 xm[ico][0]=fX[fIndLocal[0][0]][0];
747 ym[ico][0]=fY[fIndLocal[0][0]][0];
748 xm[ico][1]=fX[fIndLocal[im1][1]][1];
749 ym[ico][1]=fY[fIndLocal[im1][1]][1];
751 ixm[ico][0]=fIx[fIndLocal[0][0]][0];
752 iym[ico][0]=fIy[fIndLocal[0][0]][0];
753 ixm[ico][1]=fIx[fIndLocal[im1][1]][1];
754 iym[ico][1]=fIy[fIndLocal[im1][1]][1];
757 // ico = 0 : first local maximum on cathodes 1 and 2
758 // ico = 1 : first local maximum on cathode 1 and second on cathode 2
760 // Analyse the combinations and keep those that are possible !
761 // For each combination check consistency in x and y
765 // In case of staggering maxima are displaced by exactly half the pad-size in y.
766 // We have to take into account the numerical precision in the consistency check;
770 for (ico=0; ico<2; ico++) {
771 accepted[ico]=kFALSE;
772 isec=fSeg[0]->Sector(ixm[ico][0], iym[ico][0]);
773 dpx=fSeg[0]->Dpx(isec)/2.;
774 dx=TMath::Abs(xm[ico][0]-xm[ico][1]);
775 isec=fSeg[1]->Sector(ixm[ico][1], iym[ico][1]);
776 dpy=fSeg[1]->Dpy(isec)/2.;
777 dy=TMath::Abs(ym[ico][0]-ym[ico][1]);
779 printf("\n %i %f %f %f %f \n", ico, ym[ico][0], ym[ico][1], dy, dpy );
780 if ((dx <= dpx) && (dy <= dpy+eps)) {
783 fprintf(stderr,"ico %d\n",ico);
787 accepted[ico]=kFALSE;
795 fQrInit[1]=Float_t(fQ[fIndLocal[0][1]][1])/
796 Float_t(fQ[fIndLocal[0][1]][1]+fQ[fIndLocal[1][1]][1]);
798 fQrInit[0]=fQrInit[1];
801 if (accepted[0] && accepted[1]) {
803 fYInit[0]=0.5*(ym[0][0]+ym[0][1]);
805 fYInit[1]=0.5*(ym[0][0]+ym[1][1]);
808 chi23=CombiDoubleMathiesonFit(c);
817 } else if (accepted[0]) {
822 chi21=CombiDoubleMathiesonFit(c);
823 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
824 // Float_t prob = TMath::Prob(chi2,ndf);
825 // prob2->Fill(prob);
826 // chi2_2->Fill(chi21);
828 fprintf(stderr," chi2 %f\n",chi21);
829 if (chi21<10) Split(c);
830 } else if (accepted[1]) {
835 chi22=CombiDoubleMathiesonFit(c);
836 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
837 // Float_t prob = TMath::Prob(chi2,ndf);
838 // prob2->Fill(prob);
839 // chi2_2->Fill(chi22);
841 fprintf(stderr," chi2 %f\n",chi22);
842 if (chi22<10) Split(c);
845 if (chi21 > 10 && chi22 > 10 && chi23 > 10) {
846 //We keep only the combination found (X->cathode 2, Y->cathode 1)
847 for (Int_t ico=0; ico<2; ico++) {
849 AliMUONRawCluster cnew;
851 for (cath=0; cath<2; cath++) {
852 cnew.fX[cath]=Float_t(xm[ico][1]);
853 cnew.fY[cath]=Float_t(ym[ico][0]);
854 cnew.fZ[cath]=fZPlane;
855 cnew.fMultiplicity[cath]=c->fMultiplicity[cath];
856 for (i=0; i<fMul[cath]; i++) {
857 cnew.fIndexMap[i][cath]=c->fIndexMap[i][cath];
858 fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
860 fprintf(stderr,"\nRawCluster %d cath %d\n",ico,cath);
861 fprintf(stderr,"mult_av %d\n",c->fMultiplicity[cath]);
862 FillCluster(&cnew,cath);
864 cnew.fClusterType=cnew.PhysicsContribution();
871 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
872 // (4) At least three local maxima on cathode 1 or on cathode 2
873 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
874 } else if (fNLocal[0]>2 || fNLocal[1]>2) {
875 Int_t param = fNLocal[0]*fNLocal[1];
878 Float_t ** xm = new Float_t * [param];
879 for (ii=0; ii<param; ii++) xm[ii]=new Float_t [2];
880 Float_t ** ym = new Float_t * [param];
881 for (ii=0; ii<param; ii++) ym[ii]=new Float_t [2];
882 Int_t ** ixm = new Int_t * [param];
883 for (ii=0; ii<param; ii++) ixm[ii]=new Int_t [2];
884 Int_t ** iym = new Int_t * [param];
885 for (ii=0; ii<param; ii++) iym[ii]=new Int_t [2];
888 Float_t dpx, dpy, dx, dy;
891 for (Int_t im1=0; im1<fNLocal[0]; im1++) {
892 for (Int_t im2=0; im2<fNLocal[1]; im2++) {
893 xm[ico][0]=fX[fIndLocal[im1][0]][0];
894 ym[ico][0]=fY[fIndLocal[im1][0]][0];
895 xm[ico][1]=fX[fIndLocal[im2][1]][1];
896 ym[ico][1]=fY[fIndLocal[im2][1]][1];
898 ixm[ico][0]=fIx[fIndLocal[im1][0]][0];
899 iym[ico][0]=fIy[fIndLocal[im1][0]][0];
900 ixm[ico][1]=fIx[fIndLocal[im2][1]][1];
901 iym[ico][1]=fIy[fIndLocal[im2][1]][1];
908 fprintf(stderr,"nIco %d\n",nIco);
909 for (ico=0; ico<nIco; ico++) {
911 fprintf(stderr,"ico = %d\n",ico);
912 isec=fSeg[0]->Sector(ixm[ico][0], iym[ico][0]);
913 dpx=fSeg[0]->Dpx(isec)/2.;
914 dx=TMath::Abs(xm[ico][0]-xm[ico][1]);
915 isec=fSeg[1]->Sector(ixm[ico][1], iym[ico][1]);
916 dpy=fSeg[1]->Dpy(isec)/2.;
917 dy=TMath::Abs(ym[ico][0]-ym[ico][1]);
919 fprintf(stderr,"dx %f dpx %f dy %f dpy %f\n",dx,dpx,dy,dpy);
920 fprintf(stderr," X %f Y %f\n",xm[ico][1],ym[ico][0]);
922 if ((dx <= dpx) && (dy <= dpy)) {
924 fprintf(stderr,"ok\n");
926 AliMUONRawCluster cnew;
927 for (cath=0; cath<2; cath++) {
928 cnew.fX[cath]=Float_t(xm[ico][1]);
929 cnew.fY[cath]=Float_t(ym[ico][0]);
930 cnew.fZ[cath]=fZPlane;
931 cnew.fMultiplicity[cath]=c->fMultiplicity[cath];
932 for (i=0; i<fMul[cath]; i++) {
933 cnew.fIndexMap[i][cath]=c->fIndexMap[i][cath];
934 fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
936 FillCluster(&cnew,cath);
938 cnew.fClusterType=cnew.PhysicsContribution();
950 void AliMUONClusterFinderVS::FindLocalMaxima(AliMUONRawCluster* c)
952 // Find all local maxima of a cluster
954 printf("\n Find Local maxima !");
958 Int_t cath, cath1; // loops over cathodes
959 Int_t i; // loops over digits
960 Int_t j; // loops over cathodes
964 // counters for number of local maxima
965 fNLocal[0]=fNLocal[1]=0;
966 // flags digits as local maximum
967 Bool_t isLocal[100][2];
968 for (i=0; i<100;i++) {
969 isLocal[i][0]=isLocal[i][1]=kFALSE;
971 // number of next neighbours and arrays to store them
974 // loop over cathodes
975 for (cath=0; cath<2; cath++) {
976 // loop over cluster digits
977 for (i=0; i<fMul[cath]; i++) {
978 // get neighbours for that digit and assume that it is local maximum
979 fSeg[cath]->Neighbours(fIx[i][cath], fIy[i][cath], &nn, x, y);
980 isLocal[i][cath]=kTRUE;
981 Int_t isec= fSeg[cath]->Sector(fIx[i][cath], fIy[i][cath]);
982 Float_t a0 = fSeg[cath]->Dpx(isec)*fSeg[cath]->Dpy(isec);
983 // loop over next neighbours, if at least one neighbour has higher charger assumption
984 // digit is not local maximum
985 for (j=0; j<nn; j++) {
986 if (fHitMap[cath]->TestHit(x[j], y[j])==kEmpty) continue;
987 digt=(AliMUONDigit*) fHitMap[cath]->GetHit(x[j], y[j]);
988 isec=fSeg[cath]->Sector(x[j], y[j]);
989 Float_t a1 = fSeg[cath]->Dpx(isec)*fSeg[cath]->Dpy(isec);
990 if (digt->Signal()/a1 > fQ[i][cath]/a0) {
991 isLocal[i][cath]=kFALSE;
994 // handle special case of neighbouring pads with equal signal
995 } else if (digt->Signal() == fQ[i][cath]) {
996 if (fNLocal[cath]>0) {
997 for (Int_t k=0; k<fNLocal[cath]; k++) {
998 if (x[j]==fIx[fIndLocal[k][cath]][cath]
999 && y[j]==fIy[fIndLocal[k][cath]][cath])
1001 isLocal[i][cath]=kFALSE;
1003 } // loop over local maxima
1004 } // are there already local maxima
1006 } // loop over next neighbours
1007 if (isLocal[i][cath]) {
1008 fIndLocal[fNLocal[cath]][cath]=i;
1011 } // loop over all digits
1012 } // loop over cathodes
1015 printf("\n Found %d %d %d %d local Maxima\n",
1016 fNLocal[0], fNLocal[1], fMul[0], fMul[1]);
1017 fprintf(stderr,"\n Cathode 1 local Maxima %d Multiplicite %d\n",fNLocal[0], fMul[0]);
1018 fprintf(stderr," Cathode 2 local Maxima %d Multiplicite %d\n",fNLocal[1], fMul[1]);
1024 if (fNLocal[1]==2 && (fNLocal[0]==1 || fNLocal[0]==0)) {
1025 Int_t iback=fNLocal[0];
1027 // Two local maxima on cathode 2 and one maximum on cathode 1
1028 // Look for local maxima considering up and down neighbours on the 1st cathode only
1030 // Loop over cluster digits
1034 for (i=0; i<fMul[cath]; i++) {
1035 isec=fSeg[cath]->Sector(fIx[i][cath],fIy[i][cath]);
1036 dpy=fSeg[cath]->Dpy(isec);
1037 dpx=fSeg[cath]->Dpx(isec);
1038 if (isLocal[i][cath]) continue;
1039 // Pad position should be consistent with position of local maxima on the opposite cathode
1040 if ((TMath::Abs(fX[i][cath]-fX[fIndLocal[0][cath1]][cath1]) > dpx/2.) &&
1041 (TMath::Abs(fX[i][cath]-fX[fIndLocal[1][cath1]][cath1]) > dpx/2.))
1044 // get neighbours for that digit and assume that it is local maximum
1045 isLocal[i][cath]=kTRUE;
1046 // compare signal to that on the two neighbours on the left and on the right
1047 // iNN counts the number of neighbours with signal, it should be 1 or 2
1051 ->FirstPad(fX[i][cath], fY[i][cath], fZPlane, 0., dpy);
1057 ix = fSeg[cath]->Ix();
1058 iy = fSeg[cath]->Iy();
1059 // skip the current pad
1060 if (iy == fIy[i][cath]) continue;
1062 if (fHitMap[cath]->TestHit(ix, iy)!=kEmpty) {
1064 digt=(AliMUONDigit*) fHitMap[cath]->GetHit(ix,iy);
1065 if (digt->Signal() > fQ[i][cath]) isLocal[i][cath]=kFALSE;
1067 } // Loop over pad neighbours in y
1068 if (isLocal[i][cath] && iNN>0) {
1069 fIndLocal[fNLocal[cath]][cath]=i;
1072 } // loop over all digits
1073 // if one additional maximum has been found we are happy
1074 // if more maxima have been found restore the previous situation
1077 "\n New search gives %d local maxima for cathode 1 \n",
1080 " %d local maxima for cathode 2 \n",
1083 if (fNLocal[cath]>2) {
1084 fNLocal[cath]=iback;
1087 } // 1,2 local maxima
1089 if (fNLocal[0]==2 && (fNLocal[1]==1 || fNLocal[1]==0)) {
1090 Int_t iback=fNLocal[1];
1092 // Two local maxima on cathode 1 and one maximum on cathode 2
1093 // Look for local maxima considering left and right neighbours on the 2nd cathode only
1096 Float_t eps = 1.e-5;
1099 // Loop over cluster digits
1100 for (i=0; i<fMul[cath]; i++) {
1101 isec=fSeg[cath]->Sector(fIx[i][cath],fIy[i][cath]);
1102 dpx=fSeg[cath]->Dpx(isec);
1103 dpy=fSeg[cath]->Dpy(isec);
1104 if (isLocal[i][cath]) continue;
1105 // Pad position should be consistent with position of local maxima on the opposite cathode
1106 if ((TMath::Abs(fY[i][cath]-fY[fIndLocal[0][cath1]][cath1]) > dpy/2.+eps) &&
1107 (TMath::Abs(fY[i][cath]-fY[fIndLocal[1][cath1]][cath1]) > dpy/2.+eps))
1111 // get neighbours for that digit and assume that it is local maximum
1112 isLocal[i][cath]=kTRUE;
1113 // compare signal to that on the two neighbours on the left and on the right
1115 // iNN counts the number of neighbours with signal, it should be 1 or 2
1118 ->FirstPad(fX[i][cath], fY[i][cath], fZPlane, dpx, 0.);
1125 ix = fSeg[cath]->Ix();
1126 iy = fSeg[cath]->Iy();
1128 // skip the current pad
1129 if (ix == fIx[i][cath]) continue;
1131 if (fHitMap[cath]->TestHit(ix, iy)!=kEmpty) {
1133 digt=(AliMUONDigit*) fHitMap[cath]->GetHit(ix,iy);
1134 if (digt->Signal() > fQ[i][cath]) isLocal[i][cath]=kFALSE;
1136 } // Loop over pad neighbours in x
1137 if (isLocal[i][cath] && iNN>0) {
1138 fIndLocal[fNLocal[cath]][cath]=i;
1141 } // loop over all digits
1142 // if one additional maximum has been found we are happy
1143 // if more maxima have been found restore the previous situation
1145 fprintf(stderr,"\n New search gives %d local maxima for cathode 1 \n",fNLocal[0]);
1146 fprintf(stderr,"\n %d local maxima for cathode 2 \n",fNLocal[1]);
1147 printf("\n New search gives %d %d \n",fNLocal[0],fNLocal[1]);
1149 if (fNLocal[cath]>2) {
1150 fNLocal[cath]=iback;
1152 } // 2,1 local maxima
1156 void AliMUONClusterFinderVS::FillCluster(AliMUONRawCluster* c, Int_t flag, Int_t cath)
1159 // Completes cluster information starting from list of digits
1166 c->fPeakSignal[cath]=c->fPeakSignal[0];
1168 c->fPeakSignal[cath]=0;
1179 fprintf(stderr,"\n fPeakSignal %d\n",c->fPeakSignal[cath]);
1180 for (Int_t i=0; i<c->fMultiplicity[cath]; i++)
1182 dig= fInput->Digit(cath,c->fIndexMap[i][cath]);
1183 ix=dig->PadX()+c->fOffsetMap[i][cath];
1185 Int_t q=dig->Signal();
1186 if (!flag) q=Int_t(q*c->fContMap[i][cath]);
1187 // fprintf(stderr,"q %d c->fPeakSignal[ %d ] %d\n",q,cath,c->fPeakSignal[cath]);
1188 if (dig->Physics() >= dig->Signal()) {
1189 c->fPhysicsMap[i]=2;
1190 } else if (dig->Physics() == 0) {
1191 c->fPhysicsMap[i]=0;
1192 } else c->fPhysicsMap[i]=1;
1196 fprintf(stderr,"q %d c->fPeakSignal[cath] %d\n",q,c->fPeakSignal[cath]);
1197 // peak signal and track list
1198 if (q>c->fPeakSignal[cath]) {
1199 c->fPeakSignal[cath]=q;
1200 c->fTracks[0]=dig->Hit();
1201 c->fTracks[1]=dig->Track(0);
1202 c->fTracks[2]=dig->Track(1);
1203 // fprintf(stderr," c->fTracks[0] %d c->fTracks[1] %d\n",dig->fHit,dig->fTracks[0]);
1207 fSeg[cath]->GetPadC(ix, iy, x, y, z);
1212 } // loop over digits
1214 fprintf(stderr," fin du cluster c\n");
1218 c->fX[cath]/=c->fQ[cath];
1220 c->fX[cath]=fSeg[cath]->GetAnod(c->fX[cath]);
1221 c->fY[cath]/=c->fQ[cath];
1223 // apply correction to the coordinate along the anode wire
1227 fSeg[cath]->GetPadI(x, y, fZPlane, ix, iy);
1228 fSeg[cath]->GetPadC(ix, iy, x, y, z);
1229 Int_t isec=fSeg[cath]->Sector(ix,iy);
1230 TF1* cogCorr = fSeg[cath]->CorrFunc(isec-1);
1233 Float_t yOnPad=(c->fY[cath]-y)/fSeg[cath]->Dpy(isec);
1234 c->fY[cath]=c->fY[cath]-cogCorr->Eval(yOnPad, 0, 0);
1239 void AliMUONClusterFinderVS::FillCluster(AliMUONRawCluster* c, Int_t cath)
1242 // Completes cluster information starting from list of digits
1252 Float_t xpad, ypad, zpad;
1255 for (Int_t i=0; i<c->fMultiplicity[cath]; i++)
1257 dig = fInput->Digit(cath,c->fIndexMap[i][cath]);
1259 GetPadC(dig->PadX(),dig->PadY(),xpad,ypad, zpad);
1261 fprintf(stderr,"x %f y %f cx %f cy %f\n",xpad,ypad,c->fX[0],c->fY[0]);
1262 dx = xpad - c->fX[0];
1263 dy = ypad - c->fY[0];
1264 dr = TMath::Sqrt(dx*dx+dy*dy);
1269 fprintf(stderr," dr %f\n",dr);
1270 Int_t q=dig->Signal();
1271 if (dig->Physics() >= dig->Signal()) {
1272 c->fPhysicsMap[i]=2;
1273 } else if (dig->Physics() == 0) {
1274 c->fPhysicsMap[i]=0;
1275 } else c->fPhysicsMap[i]=1;
1276 c->fPeakSignal[cath]=q;
1277 c->fTracks[0]=dig->Hit();
1278 c->fTracks[1]=dig->Track(0);
1279 c->fTracks[2]=dig->Track(1);
1281 fprintf(stderr," c->fTracks[0] %d c->fTracks[1] %d\n",dig->Hit(),
1285 } // loop over digits
1287 // apply correction to the coordinate along the anode wire
1289 c->fX[cath]=fSeg[cath]->GetAnod(c->fX[cath]);
1292 void AliMUONClusterFinderVS::FindCluster(Int_t i, Int_t j, Int_t cath, AliMUONRawCluster &c){
1296 // Find a super cluster on both cathodes
1299 // Add i,j as element of the cluster
1302 Int_t idx = fHitMap[cath]->GetHitIndex(i,j);
1303 AliMUONDigit* dig = (AliMUONDigit*) fHitMap[cath]->GetHit(i,j);
1304 Int_t q=dig->Signal();
1305 Int_t theX=dig->PadX();
1306 Int_t theY=dig->PadY();
1308 if (q > TMath::Abs(c.fPeakSignal[0]) && q > TMath::Abs(c.fPeakSignal[1])) {
1309 c.fPeakSignal[cath]=q;
1310 c.fTracks[0]=dig->Hit();
1311 c.fTracks[1]=dig->Track(0);
1312 c.fTracks[2]=dig->Track(1);
1316 // Make sure that list of digits is ordered
1318 Int_t mu=c.fMultiplicity[cath];
1319 c.fIndexMap[mu][cath]=idx;
1321 if (dig->Physics() >= dig->Signal()) {
1322 c.fPhysicsMap[mu]=2;
1323 } else if (dig->Physics() == 0) {
1324 c.fPhysicsMap[mu]=0;
1325 } else c.fPhysicsMap[mu]=1;
1329 for (Int_t ind = mu-1; ind >= 0; ind--) {
1330 Int_t ist=(c.fIndexMap)[ind][cath];
1331 Int_t ql=fInput->Digit(cath, ist)->Signal();
1332 Int_t ix=fInput->Digit(cath, ist)->PadX();
1333 Int_t iy=fInput->Digit(cath, ist)->PadY();
1335 if (q>ql || (q==ql && theX > ix && theY < iy)) {
1336 c.fIndexMap[ind][cath]=idx;
1337 c.fIndexMap[ind+1][cath]=ist;
1345 c.fMultiplicity[cath]++;
1346 if (c.fMultiplicity[cath] >= 50 ) {
1347 printf("FindCluster - multiplicity >50 %d \n",c.fMultiplicity[0]);
1348 c.fMultiplicity[cath]=49;
1351 // Prepare center of gravity calculation
1353 fSeg[cath]->GetPadC(i, j, x, y, z);
1359 // Flag hit as "taken"
1360 fHitMap[cath]->FlagHit(i,j);
1362 // Now look recursively for all neighbours and pad hit on opposite cathode
1364 // Loop over neighbours
1368 Int_t xList[10], yList[10];
1369 fSeg[cath]->Neighbours(i,j,&nn,xList,yList);
1370 for (Int_t in=0; in<nn; in++) {
1374 if (fHitMap[cath]->TestHit(ix,iy)==kUnused) {
1376 printf("\n Neighbours %d %d %d", cath, ix, iy);
1377 FindCluster(ix, iy, cath, c);
1382 Int_t iXopp[50], iYopp[50];
1384 // Neighbours on opposite cathode
1385 // Take into account that several pads can overlap with the present pad
1386 Int_t isec=fSeg[cath]->Sector(i,j);
1392 dx = (fSeg[cath]->Dpx(isec))/2.;
1397 dy = (fSeg[cath]->Dpy(isec))/2;
1399 // loop over pad neighbours on opposite cathode
1400 for (fSeg[iop]->FirstPad(x, y, fZPlane, dx, dy);
1401 fSeg[iop]->MorePads();
1402 fSeg[iop]->NextPad())
1405 ix = fSeg[iop]->Ix(); iy = fSeg[iop]->Iy();
1406 if (fDebugLevel > 1)
1407 printf("\n ix, iy: %f %f %f %d %d %d", x,y,z,ix, iy, fSector);
1408 if (fHitMap[iop]->TestHit(ix,iy)==kUnused){
1411 if (fDebugLevel > 1)
1412 printf("\n Opposite %d %d %d", iop, ix, iy);
1415 } // Loop over pad neighbours
1416 // This had to go outside the loop since recursive calls inside the iterator are not possible
1419 for (jopp=0; jopp<nOpp; jopp++) {
1420 if (fHitMap[iop]->TestHit(iXopp[jopp],iYopp[jopp]) == kUnused)
1421 FindCluster(iXopp[jopp], iYopp[jopp], iop, c);
1425 //_____________________________________________________________________________
1427 void AliMUONClusterFinderVS::FindRawClusters()
1430 // MUON cluster finder from digits -- finds neighbours on both cathodes and
1431 // fills the tree with raw clusters
1434 // Return if no input datad available
1435 if (!fInput->NDigits(0) && !fInput->NDigits(1)) return;
1437 fSeg[0] = fInput->Segmentation(0);
1438 fSeg[1] = fInput->Segmentation(1);
1440 fHitMap[0] = new AliMUONHitMapA1(fSeg[0], fInput->Digits(0));
1441 fHitMap[1] = new AliMUONHitMapA1(fSeg[1], fInput->Digits(1));
1449 fHitMap[0]->FillHits();
1450 fHitMap[1]->FillHits();
1452 // Outer Loop over Cathodes
1453 for (cath=0; cath<2; cath++) {
1454 for (ndig=0; ndig<fInput->NDigits(cath); ndig++) {
1455 dig = fInput->Digit(cath, ndig);
1456 Int_t i=dig->PadX();
1457 Int_t j=dig->PadY();
1458 if (fHitMap[cath]->TestHit(i,j)==kUsed ||fHitMap[0]->TestHit(i,j)==kEmpty) {
1463 fprintf(stderr,"\n CATHODE %d CLUSTER %d\n",cath,ncls);
1464 AliMUONRawCluster c;
1465 c.fMultiplicity[0]=0;
1466 c.fMultiplicity[1]=0;
1467 c.fPeakSignal[cath]=dig->Signal();
1468 c.fTracks[0]=dig->Hit();
1469 c.fTracks[1]=dig->Track(0);
1470 c.fTracks[2]=dig->Track(1);
1471 // tag the beginning of cluster list in a raw cluster
1474 fSeg[cath]->GetPadC(i,j,xcu, ycu, fZPlane);
1475 fSector= fSeg[cath]->Sector(i,j)/100;
1477 printf("\n New Seed %d %d ", i,j);
1479 FindCluster(i,j,cath,c);
1480 // ^^^^^^^^^^^^^^^^^^^^^^^^
1481 // center of gravity
1484 c.fX[0]=fSeg[0]->GetAnod(c.fX[0]);
1488 c.fX[1]=fSeg[0]->GetAnod(c.fX[1]);
1495 fprintf(stderr,"\n Cathode 1 multiplicite %d X(CG) %f Y(CG) %f\n",
1496 c.fMultiplicity[0],c.fX[0],c.fY[0]);
1497 fprintf(stderr," Cathode 2 multiplicite %d X(CG) %f Y(CG) %f\n",
1498 c.fMultiplicity[1],c.fX[1],c.fY[1]);
1500 // Analyse cluster and decluster if necessary
1503 c.fNcluster[1]=fNRawClusters;
1504 c.fClusterType=c.PhysicsContribution();
1511 // reset Cluster object
1512 { // begin local scope
1513 for (int k=0;k<c.fMultiplicity[0];k++) c.fIndexMap[k][0]=0;
1514 } // end local scope
1516 { // begin local scope
1517 for (int k=0;k<c.fMultiplicity[1];k++) c.fIndexMap[k][1]=0;
1518 } // end local scope
1520 c.fMultiplicity[0]=c.fMultiplicity[0]=0;
1524 } // end loop cathodes
1529 Float_t AliMUONClusterFinderVS::SingleMathiesonFit(AliMUONRawCluster *c, Int_t cath)
1531 // Performs a single Mathieson fit on one cathode
1533 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
1535 clusterInput.Fitter()->SetFCN(fcnS1);
1536 clusterInput.Fitter()->mninit(2,10,7);
1537 Double_t arglist[20];
1540 // Set starting values
1541 static Double_t vstart[2];
1546 // lower and upper limits
1547 static Double_t lower[2], upper[2];
1549 fSeg[cath]->GetPadI(c->fX[cath], c->fY[cath], fZPlane, ix, iy);
1550 Int_t isec=fSeg[cath]->Sector(ix, iy);
1551 lower[0]=vstart[0]-fSeg[cath]->Dpx(isec)/2;
1552 lower[1]=vstart[1]-fSeg[cath]->Dpy(isec)/2;
1554 upper[0]=lower[0]+fSeg[cath]->Dpx(isec);
1555 upper[1]=lower[1]+fSeg[cath]->Dpy(isec);
1558 static Double_t step[2]={0.0005, 0.0005};
1560 clusterInput.Fitter()->mnparm(0,"x1",vstart[0],step[0],lower[0],upper[0],ierflag);
1561 clusterInput.Fitter()->mnparm(1,"y1",vstart[1],step[1],lower[1],upper[1],ierflag);
1562 // ready for minimisation
1563 clusterInput.Fitter()->SetPrintLevel(-1+fDebugLevel);
1565 clusterInput.Fitter()->mnexcm("SET NOW", arglist, 0, ierflag);
1566 clusterInput.Fitter()->mnexcm("SET OUT", arglist, 0, ierflag);
1570 clusterInput.Fitter()->mnexcm("SET NOGR", arglist, 0, ierflag);
1571 clusterInput.Fitter()->mnexcm("MIGRAD", arglist, 0, ierflag);
1572 clusterInput.Fitter()->mnexcm("EXIT" , arglist, 0, ierflag);
1573 Double_t fmin, fedm, errdef;
1574 Int_t npari, nparx, istat;
1576 clusterInput.Fitter()->mnstat(fmin, fedm, errdef, npari, nparx, istat);
1580 // Get fitted parameters
1581 Double_t xrec, yrec;
1583 Double_t epxz, b1, b2;
1585 clusterInput.Fitter()->mnpout(0, chname, xrec, epxz, b1, b2, ierflg);
1586 clusterInput.Fitter()->mnpout(1, chname, yrec, epxz, b1, b2, ierflg);
1592 Float_t AliMUONClusterFinderVS::CombiSingleMathiesonFit(AliMUONRawCluster *c)
1594 // Perform combined Mathieson fit on both cathode planes
1596 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
1597 clusterInput.Fitter()->SetFCN(fcnCombiS1);
1598 clusterInput.Fitter()->mninit(2,10,7);
1599 Double_t arglist[20];
1602 static Double_t vstart[2];
1603 vstart[0]=fXInit[0];
1604 vstart[1]=fYInit[0];
1607 // lower and upper limits
1608 static Float_t lower[2], upper[2];
1610 fSeg[0]->GetPadI(fXInit[0], fYInit[0], fZPlane, ix, iy);
1611 isec=fSeg[0]->Sector(ix, iy);
1612 Float_t dpy=fSeg[0]->Dpy(isec);
1613 fSeg[1]->GetPadI(fXInit[0], fYInit[0], fZPlane, ix, iy);
1614 isec=fSeg[1]->Sector(ix, iy);
1615 Float_t dpx=fSeg[1]->Dpx(isec);
1618 Float_t xdum, ydum, zdum;
1620 // Find save upper and lower limits
1624 for (fSeg[1]->FirstPad(fXInit[0], fYInit[0], fZPlane, dpx, 0.);
1625 fSeg[1]->MorePads(); fSeg[1]->NextPad())
1627 ix=fSeg[1]->Ix(); iy=fSeg[1]->Iy();
1628 fSeg[1]->GetPadC(ix,iy, upper[0], ydum, zdum);
1629 if (icount ==0) lower[0]=upper[0];
1633 if (lower[0]>upper[0]) {xdum=lower[0]; lower[0]=upper[0]; upper[0]=xdum;}
1637 printf("\n single y %f %f", fXInit[0], fYInit[0]);
1639 for (fSeg[0]->FirstPad(fXInit[0], fYInit[0], fZPlane, 0., dpy);
1640 fSeg[0]->MorePads(); fSeg[0]->NextPad())
1642 ix=fSeg[0]->Ix(); iy=fSeg[0]->Iy();
1643 fSeg[0]->GetPadC(ix,iy,xdum,upper[1],zdum);
1644 if (icount ==0) lower[1]=upper[1];
1647 printf("\n upper lower %d %f %f", icount, upper[1], lower[1]);
1650 if (lower[1]>upper[1]) {xdum=lower[1]; lower[1]=upper[1]; upper[1]=xdum;}
1653 static Double_t step[2]={0.00001, 0.0001};
1655 clusterInput.Fitter()->mnparm(0,"x1",vstart[0],step[0],lower[0],upper[0],ierflag);
1656 clusterInput.Fitter()->mnparm(1,"y1",vstart[1],step[1],lower[1],upper[1],ierflag);
1657 // ready for minimisation
1658 clusterInput.Fitter()->SetPrintLevel(-1+fDebugLevel);
1660 clusterInput.Fitter()->mnexcm("SET NOW", arglist, 0, ierflag);
1661 clusterInput.Fitter()->mnexcm("SET OUT", arglist, 0, ierflag);
1665 clusterInput.Fitter()->mnexcm("SET NOGR", arglist, 0, ierflag);
1666 clusterInput.Fitter()->mnexcm("MIGRAD", arglist, 0, ierflag);
1667 clusterInput.Fitter()->mnexcm("EXIT" , arglist, 0, ierflag);
1668 Double_t fmin, fedm, errdef;
1669 Int_t npari, nparx, istat;
1671 clusterInput.Fitter()->mnstat(fmin, fedm, errdef, npari, nparx, istat);
1675 // Get fitted parameters
1676 Double_t xrec, yrec;
1678 Double_t epxz, b1, b2;
1680 clusterInput.Fitter()->mnpout(0, chname, xrec, epxz, b1, b2, ierflg);
1681 clusterInput.Fitter()->mnpout(1, chname, yrec, epxz, b1, b2, ierflg);
1687 Bool_t AliMUONClusterFinderVS::DoubleMathiesonFit(AliMUONRawCluster *c, Int_t cath)
1689 // Performs a double Mathieson fit on one cathode
1693 // Initialise global variables for fit
1694 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
1695 clusterInput.Fitter()->SetFCN(fcnS2);
1696 clusterInput.Fitter()->mninit(5,10,7);
1697 Double_t arglist[20];
1700 // Set starting values
1701 static Double_t vstart[5];
1702 vstart[0]=fX[fIndLocal[0][cath]][cath];
1703 vstart[1]=fY[fIndLocal[0][cath]][cath];
1704 vstart[2]=fX[fIndLocal[1][cath]][cath];
1705 vstart[3]=fY[fIndLocal[1][cath]][cath];
1706 vstart[4]=Float_t(fQ[fIndLocal[0][cath]][cath])/
1707 Float_t(fQ[fIndLocal[0][cath]][cath]+fQ[fIndLocal[1][cath]][cath]);
1708 // lower and upper limits
1709 static Float_t lower[5], upper[5];
1710 Int_t isec=fSeg[cath]->Sector(fIx[fIndLocal[0][cath]][cath], fIy[fIndLocal[0][cath]][cath]);
1711 lower[0]=vstart[0]-fSeg[cath]->Dpx(isec);
1712 lower[1]=vstart[1]-fSeg[cath]->Dpy(isec);
1714 upper[0]=lower[0]+2.*fSeg[cath]->Dpx(isec);
1715 upper[1]=lower[1]+2.*fSeg[cath]->Dpy(isec);
1717 isec=fSeg[cath]->Sector(fIx[fIndLocal[1][cath]][cath], fIy[fIndLocal[1][cath]][cath]);
1718 lower[2]=vstart[2]-fSeg[cath]->Dpx(isec)/2;
1719 lower[3]=vstart[3]-fSeg[cath]->Dpy(isec)/2;
1721 upper[2]=lower[2]+fSeg[cath]->Dpx(isec);
1722 upper[3]=lower[3]+fSeg[cath]->Dpy(isec);
1727 static Double_t step[5]={0.0005, 0.0005, 0.0005, 0.0005, 0.0001};
1729 clusterInput.Fitter()->mnparm(0,"x1",vstart[0],step[0],lower[0],upper[0],ierflag);
1730 clusterInput.Fitter()->mnparm(1,"y1",vstart[1],step[1],lower[1],upper[1],ierflag);
1731 clusterInput.Fitter()->mnparm(2,"x2",vstart[2],step[2],lower[2],upper[2],ierflag);
1732 clusterInput.Fitter()->mnparm(3,"y2",vstart[3],step[3],lower[3],upper[3],ierflag);
1733 clusterInput.Fitter()->mnparm(4,"a0",vstart[4],step[4],lower[4],upper[4],ierflag);
1734 // ready for minimisation
1735 clusterInput.Fitter()->SetPrintLevel(-1+fDebugLevel);
1737 clusterInput.Fitter()->mnexcm("SET NOW", arglist, 0, ierflag);
1738 clusterInput.Fitter()->mnexcm("SET OUT", arglist, 0, ierflag);
1742 clusterInput.Fitter()->mnexcm("SET NOGR", arglist, 0, ierflag);
1743 clusterInput.Fitter()->mnexcm("MIGRAD", arglist, 0, ierflag);
1744 clusterInput.Fitter()->mnexcm("EXIT" , arglist, 0, ierflag);
1745 // Get fitted parameters
1746 Double_t xrec[2], yrec[2], qfrac;
1748 Double_t epxz, b1, b2;
1750 clusterInput.Fitter()->mnpout(0, chname, xrec[0], epxz, b1, b2, ierflg);
1751 clusterInput.Fitter()->mnpout(1, chname, yrec[0], epxz, b1, b2, ierflg);
1752 clusterInput.Fitter()->mnpout(2, chname, xrec[1], epxz, b1, b2, ierflg);
1753 clusterInput.Fitter()->mnpout(3, chname, yrec[1], epxz, b1, b2, ierflg);
1754 clusterInput.Fitter()->mnpout(4, chname, qfrac, epxz, b1, b2, ierflg);
1756 Double_t fmin, fedm, errdef;
1757 Int_t npari, nparx, istat;
1759 clusterInput.Fitter()->mnstat(fmin, fedm, errdef, npari, nparx, istat);
1764 Float_t AliMUONClusterFinderVS::CombiDoubleMathiesonFit(AliMUONRawCluster *c)
1767 // Perform combined double Mathieson fit on both cathode planes
1769 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
1770 clusterInput.Fitter()->SetFCN(fcnCombiS2);
1771 clusterInput.Fitter()->mninit(6,10,7);
1772 Double_t arglist[20];
1775 // Set starting values
1776 static Double_t vstart[6];
1777 vstart[0]=fXInit[0];
1778 vstart[1]=fYInit[0];
1779 vstart[2]=fXInit[1];
1780 vstart[3]=fYInit[1];
1781 vstart[4]=fQrInit[0];
1782 vstart[5]=fQrInit[1];
1783 // lower and upper limits
1784 static Float_t lower[6], upper[6];
1788 fSeg[1]->GetPadI(fXInit[0], fYInit[0], fZPlane, ix, iy);
1789 isec=fSeg[1]->Sector(ix, iy);
1790 dpx=fSeg[1]->Dpx(isec);
1792 fSeg[0]->GetPadI(fXInit[0], fYInit[0], fZPlane, ix, iy);
1793 isec=fSeg[0]->Sector(ix, iy);
1794 dpy=fSeg[0]->Dpy(isec);
1798 Float_t xdum, ydum, zdum;
1800 printf("\n Cluster Finder: %f %f %f %f ", fXInit[0], fXInit[1],fYInit[0], fYInit[1] );
1802 // Find save upper and lower limits
1805 for (fSeg[1]->FirstPad(fXInit[0], fYInit[0], fZPlane, dpx, 0.);
1806 fSeg[1]->MorePads(); fSeg[1]->NextPad())
1808 ix=fSeg[1]->Ix(); iy=fSeg[1]->Iy();
1809 // if (fHitMap[1]->TestHit(ix, iy) == kEmpty) continue;
1810 fSeg[1]->GetPadC(ix,iy,upper[0],ydum,zdum);
1811 if (icount ==0) lower[0]=upper[0];
1814 if (lower[0]>upper[0]) {xdum=lower[0]; lower[0]=upper[0]; upper[0]=xdum;}
1815 // vstart[0] = 0.5*(lower[0]+upper[0]);
1820 for (fSeg[0]->FirstPad(fXInit[0], fYInit[0], fZPlane, 0., dpy);
1821 fSeg[0]->MorePads(); fSeg[0]->NextPad())
1823 ix=fSeg[0]->Ix(); iy=fSeg[0]->Iy();
1824 // if (fHitMap[0]->TestHit(ix, iy) == kEmpty) continue;
1825 fSeg[0]->GetPadC(ix,iy,xdum,upper[1],zdum);
1826 if (icount ==0) lower[1]=upper[1];
1830 if (lower[1]>upper[1]) {xdum=lower[1]; lower[1]=upper[1]; upper[1]=xdum;}
1831 // vstart[1] = 0.5*(lower[1]+upper[1]);
1834 fSeg[1]->GetPadI(fXInit[1], fYInit[1], fZPlane, ix, iy);
1835 isec=fSeg[1]->Sector(ix, iy);
1836 dpx=fSeg[1]->Dpx(isec);
1837 fSeg[0]->GetPadI(fXInit[1], fYInit[1], fZPlane, ix, iy);
1838 isec=fSeg[0]->Sector(ix, iy);
1839 dpy=fSeg[0]->Dpy(isec);
1842 // Find save upper and lower limits
1846 for (fSeg[1]->FirstPad(fXInit[1], fYInit[1], fZPlane, dpx, 0);
1847 fSeg[1]->MorePads(); fSeg[1]->NextPad())
1849 ix=fSeg[1]->Ix(); iy=fSeg[1]->Iy();
1850 // if (fHitMap[1]->TestHit(ix, iy) == kEmpty) continue;
1851 fSeg[1]->GetPadC(ix,iy,upper[2],ydum,zdum);
1852 if (icount ==0) lower[2]=upper[2];
1855 if (lower[2]>upper[2]) {xdum=lower[2]; lower[2]=upper[2]; upper[2]=xdum;}
1856 // vstart[2] = 0.5*(lower[2]+upper[2]);
1860 for (fSeg[0]->FirstPad(fXInit[1], fYInit[1], fZPlane, 0, dpy);
1861 fSeg[0]-> MorePads(); fSeg[0]->NextPad())
1863 ix=fSeg[0]->Ix(); iy=fSeg[0]->Iy();
1864 // if (fHitMap[0]->TestHit(ix, iy) != kEmpty) continue;
1866 fSeg[0]->GetPadC(ix,iy,xdum,upper[3],zdum);
1867 if (icount ==0) lower[3]=upper[3];
1871 if (lower[3]>upper[3]) {xdum=lower[3]; lower[3]=upper[3]; upper[3]=xdum;}
1873 // vstart[3] = 0.5*(lower[3]+upper[3]);
1881 static Double_t step[6]={0.0005, 0.0005, 0.0005, 0.0005, 0.001, 0.001};
1882 clusterInput.Fitter()->mnparm(0,"x1",vstart[0],step[0],lower[0],upper[0],ierflag);
1883 clusterInput.Fitter()->mnparm(1,"y1",vstart[1],step[1],lower[1],upper[1],ierflag);
1884 clusterInput.Fitter()->mnparm(2,"x2",vstart[2],step[2],lower[2],upper[2],ierflag);
1885 clusterInput.Fitter()->mnparm(3,"y2",vstart[3],step[3],lower[3],upper[3],ierflag);
1886 clusterInput.Fitter()->mnparm(4,"a0",vstart[4],step[4],lower[4],upper[4],ierflag);
1887 clusterInput.Fitter()->mnparm(5,"a1",vstart[5],step[5],lower[5],upper[5],ierflag);
1888 // ready for minimisation
1889 clusterInput.Fitter()->SetPrintLevel(-1+fDebugLevel);
1891 clusterInput.Fitter()->mnexcm("SET NOW", arglist, 0, ierflag);
1892 clusterInput.Fitter()->mnexcm("SET OUT", arglist, 0, ierflag);
1896 clusterInput.Fitter()->mnexcm("SET NOGR", arglist, 0, ierflag);
1897 clusterInput.Fitter()->mnexcm("MIGRAD", arglist, 0, ierflag);
1898 clusterInput.Fitter()->mnexcm("EXIT" , arglist, 0, ierflag);
1899 // Get fitted parameters
1901 Double_t epxz, b1, b2;
1903 clusterInput.Fitter()->mnpout(0, chname, fXFit[0], epxz, b1, b2, ierflg);
1904 clusterInput.Fitter()->mnpout(1, chname, fYFit[0], epxz, b1, b2, ierflg);
1905 clusterInput.Fitter()->mnpout(2, chname, fXFit[1], epxz, b1, b2, ierflg);
1906 clusterInput.Fitter()->mnpout(3, chname, fYFit[1], epxz, b1, b2, ierflg);
1907 clusterInput.Fitter()->mnpout(4, chname, fQrFit[0], epxz, b1, b2, ierflg);
1908 clusterInput.Fitter()->mnpout(5, chname, fQrFit[1], epxz, b1, b2, ierflg);
1910 Double_t fmin, fedm, errdef;
1911 Int_t npari, nparx, istat;
1913 clusterInput.Fitter()->mnstat(fmin, fedm, errdef, npari, nparx, istat);
1921 void AliMUONClusterFinderVS::Split(AliMUONRawCluster* c)
1924 // One cluster for each maximum
1927 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
1928 for (j=0; j<2; j++) {
1929 AliMUONRawCluster cnew;
1930 cnew.fGhost=c->fGhost;
1931 for (cath=0; cath<2; cath++) {
1932 cnew.fChi2[cath]=fChi2[0];
1933 // ?? why not cnew.fChi2[cath]=fChi2[cath];
1936 cnew.fNcluster[0]=-1;
1937 cnew.fNcluster[1]=fNRawClusters;
1939 cnew.fNcluster[0]=fNPeaks;
1940 cnew.fNcluster[1]=0;
1942 cnew.fMultiplicity[cath]=0;
1943 cnew.fX[cath]=Float_t(fXFit[j]);
1944 cnew.fY[cath]=Float_t(fYFit[j]);
1945 cnew.fZ[cath]=fZPlane;
1947 cnew.fQ[cath]=Int_t(clusterInput.TotalCharge(cath)*fQrFit[cath]);
1949 cnew.fQ[cath]=Int_t(clusterInput.TotalCharge(cath)*(1-fQrFit[cath]));
1951 fSeg[cath]->SetHit(fXFit[j],fYFit[j],fZPlane);
1952 for (i=0; i<fMul[cath]; i++) {
1953 cnew.fIndexMap[cnew.fMultiplicity[cath]][cath]=
1954 c->fIndexMap[i][cath];
1955 fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
1956 Float_t q1=fInput->Response()->IntXY(fSeg[cath]);
1957 cnew.fContMap[i][cath]
1958 =(q1*Float_t(cnew.fQ[cath]))/Float_t(fQ[i][cath]);
1959 cnew.fMultiplicity[cath]++;
1961 FillCluster(&cnew,0,cath);
1964 cnew.fClusterType=cnew.PhysicsContribution();
1965 if (cnew.fQ[0]>0 && cnew.fQ[1]>0) AddRawCluster(cnew);
1972 // Minimisation functions
1974 void fcnS1(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
1976 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
1983 for (i=0; i<clusterInput.Nmul(0); i++) {
1984 Float_t q0=clusterInput.Charge(i,0);
1985 Float_t q1=clusterInput.DiscrChargeS1(i,par);
1994 void fcnCombiS1(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
1996 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
2003 for (cath=0; cath<2; cath++) {
2004 for (i=0; i<clusterInput.Nmul(cath); i++) {
2005 Float_t q0=clusterInput.Charge(i,cath);
2006 Float_t q1=clusterInput.DiscrChargeCombiS1(i,par,cath);
2017 void fcnS2(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
2019 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
2026 for (i=0; i<clusterInput.Nmul(0); i++) {
2028 Float_t q0=clusterInput.Charge(i,0);
2029 Float_t q1=clusterInput.DiscrChargeS2(i,par);
2039 void fcnCombiS2(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
2041 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
2047 for (cath=0; cath<2; cath++) {
2048 for (i=0; i<clusterInput.Nmul(cath); i++) {
2049 Float_t q0=clusterInput.Charge(i,cath);
2050 Float_t q1=clusterInput.DiscrChargeCombiS2(i,par,cath);
2060 void AliMUONClusterFinderVS::AddRawCluster(const AliMUONRawCluster c)
2063 // Add a raw cluster copy to the list
2065 AliMUON *pMUON=(AliMUON*)gAlice->GetModule("MUON");
2066 pMUON->AddRawCluster(fInput->Chamber(),c);
2069 fprintf(stderr,"\nfNRawClusters %d\n",fNRawClusters);
2072 Bool_t AliMUONClusterFinderVS::TestTrack(Int_t t) {
2073 // Test if track was user selected
2074 if (fTrack[0]==-1 || fTrack[1]==-1) {
2076 } else if (t==fTrack[0] || t==fTrack[1]) {
2083 AliMUONClusterFinderVS& AliMUONClusterFinderVS
2084 ::operator = (const AliMUONClusterFinderVS& rhs)
2086 // Dummy assignment operator