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++) {
65 fRawClusters = new TClonesArray("AliMUONRawCluster",1000);
70 //____________________________________________________________________________
71 AliMUONClusterFinderVS::~AliMUONClusterFinderVS()
73 // Reset tracks information
75 if (fRawClusters) fRawClusters->Delete();
78 AliMUONClusterFinderVS::AliMUONClusterFinderVS(const AliMUONClusterFinderVS & clusterFinder):TObject(clusterFinder)
80 // Dummy copy Constructor
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->fMultiplicity[0];
105 fMul[1]=c->fMultiplicity[1];
108 // dump digit information into arrays
113 for (cath=0; cath<2; cath++) {
115 for (i=0; i<fMul[cath]; i++)
118 fDig[i][cath]=fInput->Digit(cath, c->fIndexMap[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
126 GetPadC(fIx[i][cath], fIy[i][cath], fX[i][cath], fY[i][cath], fZ[i][cath]);
127 } // loop over cluster digits
128 } // loop over cathodes
134 // Initialise and perform mathieson fits
135 Float_t chi2, oldchi2;
136 // ++++++++++++++++++*************+++++++++++++++++++++
137 // (1) No more than one local maximum per cathode plane
138 // +++++++++++++++++++++++++++++++*************++++++++
139 if ((fNLocal[0]==1 && (fNLocal[1]==0 || fNLocal[1]==1)) ||
140 (fNLocal[0]==0 && fNLocal[1]==1)) {
141 // Perform combined single Mathieson fit
142 // Initial values for coordinates (x,y)
144 // One local maximum on cathodes 1 and 2 (X->cathode 2, Y->cathode 1)
145 if (fNLocal[0]==1 && fNLocal[1]==1) {
148 // One local maximum on cathode 1 (X,Y->cathode 1)
149 } else if (fNLocal[0]==1) {
152 // One local maximum on cathode 2 (X,Y->cathode 2)
158 fprintf(stderr,"\n cas (1) CombiSingleMathiesonFit(c)\n");
159 chi2=CombiSingleMathiesonFit(c);
160 // Int_t ndf = fgNbins[0]+fgNbins[1]-2;
161 // Float_t prob = TMath::Prob(Double_t(chi2),ndf);
162 // prob1->Fill(prob);
163 // chi2_1->Fill(chi2);
166 fprintf(stderr," chi2 %f ",chi2);
176 c->fX[0]=fSeg[0]->GetAnod(c->fX[0]);
177 c->fX[1]=fSeg[1]->GetAnod(c->fX[1]);
179 // If reasonable chi^2 add result to the list of rawclusters
182 // If not try combined double Mathieson Fit
185 fprintf(stderr," MAUVAIS CHI2 !!!\n");
186 if (fNLocal[0]==1 && fNLocal[1]==1) {
187 fXInit[0]=fX[fIndLocal[0][1]][1];
188 fYInit[0]=fY[fIndLocal[0][0]][0];
189 fXInit[1]=fX[fIndLocal[0][1]][1];
190 fYInit[1]=fY[fIndLocal[0][0]][0];
191 } else if (fNLocal[0]==1) {
192 fXInit[0]=fX[fIndLocal[0][0]][0];
193 fYInit[0]=fY[fIndLocal[0][0]][0];
194 fXInit[1]=fX[fIndLocal[0][0]][0];
195 fYInit[1]=fY[fIndLocal[0][0]][0];
197 fXInit[0]=fX[fIndLocal[0][1]][1];
198 fYInit[0]=fY[fIndLocal[0][1]][1];
199 fXInit[1]=fX[fIndLocal[0][1]][1];
200 fYInit[1]=fY[fIndLocal[0][1]][1];
203 // Initial value for charge ratios
207 fprintf(stderr,"\n cas (1) CombiDoubleMathiesonFit(c)\n");
208 chi2=CombiDoubleMathiesonFit(c);
209 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
210 // Float_t prob = TMath::Prob(chi2,ndf);
211 // prob2->Fill(prob);
212 // chi2_2->Fill(chi2);
214 // Was this any better ??
216 fprintf(stderr," Old and new chi2 %f %f ", oldchi2, chi2);
217 if (fFitStat!=0 && chi2>0 && (2.*chi2 < oldchi2)) {
219 fprintf(stderr," Split\n");
220 // Split cluster into two according to fit result
224 fprintf(stderr," Don't Split\n");
230 // +++++++++++++++++++++++++++++++++++++++
231 // (2) Two local maxima per cathode plane
232 // +++++++++++++++++++++++++++++++++++++++
233 } else if (fNLocal[0]==2 && fNLocal[1]==2) {
235 // Let's look for ghosts first
237 Float_t xm[4][2], ym[4][2];
238 Float_t dpx, dpy, dx, dy;
239 Int_t ixm[4][2], iym[4][2];
240 Int_t isec, im1, im2, ico;
242 // Form the 2x2 combinations
243 // 0-0, 0-1, 1-0, 1-1
245 for (im1=0; im1<2; im1++) {
246 for (im2=0; im2<2; im2++) {
247 xm[ico][0]=fX[fIndLocal[im1][0]][0];
248 ym[ico][0]=fY[fIndLocal[im1][0]][0];
249 xm[ico][1]=fX[fIndLocal[im2][1]][1];
250 ym[ico][1]=fY[fIndLocal[im2][1]][1];
252 ixm[ico][0]=fIx[fIndLocal[im1][0]][0];
253 iym[ico][0]=fIy[fIndLocal[im1][0]][0];
254 ixm[ico][1]=fIx[fIndLocal[im2][1]][1];
255 iym[ico][1]=fIy[fIndLocal[im2][1]][1];
259 // ico = 0 : first local maximum on cathodes 1 and 2
260 // ico = 1 : fisrt local maximum on cathode 1 and second on cathode 2
261 // ico = 2 : second local maximum on cathode 1 and first on cathode 1
262 // ico = 3 : second local maximum on cathodes 1 and 2
264 // Analyse the combinations and keep those that are possible !
265 // For each combination check consistency in x and y
268 Float_t dr[4] = {1.e4, 1.e4, 1.e4, 1.e4};
271 // In case of staggering maxima are displaced by exactly half the pad-size in y.
272 // We have to take into account the numerical precision in the consistency check;
275 for (ico=0; ico<4; ico++) {
276 accepted[ico]=kFALSE;
277 // cathode one: x-coordinate
278 isec=fSeg[0]->Sector(ixm[ico][0], iym[ico][0]);
279 dpx=fSeg[0]->Dpx(isec)/2.;
280 dx=TMath::Abs(xm[ico][0]-xm[ico][1]);
281 // cathode two: y-coordinate
282 isec=fSeg[1]->Sector(ixm[ico][1], iym[ico][1]);
283 dpy=fSeg[1]->Dpy(isec)/2.;
284 dy=TMath::Abs(ym[ico][0]-ym[ico][1]);
286 printf("\n %i %f %f %f %f %f %f \n", ico, ym[ico][0], ym[ico][1], dy, dpy, dx, dpx );
287 if ((dx <= dpx) && (dy <= dpy+eps)) {
290 dr[ico] = TMath::Sqrt(dx*dx+dy*dy);
294 accepted[ico]=kFALSE;
298 printf("\n iacc= %d:\n", iacc);
300 if (accepted[0] && accepted[1]) {
301 if (dr[0] >= dr[1]) {
308 if (accepted[2] && accepted[3]) {
309 if (dr[2] >= dr[3]) {
316 // eliminate one candidate
320 for (ico=0; ico<4; ico++) {
321 if (accepted[ico] && dr[ico] > drmax) {
327 accepted[icobad] = kFALSE;
334 printf("\n iacc= %d:\n", iacc);
336 fprintf(stderr,"\n iacc=2: No problem ! \n");
337 } else if (iacc==4) {
338 fprintf(stderr,"\n iacc=4: Ok, but ghost problem !!! \n");
339 } else if (iacc==0) {
340 fprintf(stderr,"\n iacc=0: I don't know what to do with this !!!!!!!!! \n");
344 // Initial value for charge ratios
345 fQrInit[0]=Float_t(fQ[fIndLocal[0][0]][0])/
346 Float_t(fQ[fIndLocal[0][0]][0]+fQ[fIndLocal[1][0]][0]);
347 fQrInit[1]=Float_t(fQ[fIndLocal[0][1]][1])/
348 Float_t(fQ[fIndLocal[0][1]][1]+fQ[fIndLocal[1][1]][1]);
350 // ******* iacc = 0 *******
351 // No combinations found between the 2 cathodes
352 // We keep the center of gravity of the cluster
357 // ******* iacc = 1 *******
358 // Only one combination found between the 2 cathodes
360 // Initial values for the 2 maxima (x,y)
362 // 1 maximum is initialised with the maximum of the combination found (X->cathode 2, Y->cathode 1)
363 // 1 maximum is initialised with the other maximum of the first cathode
365 fprintf(stderr,"ico=0\n");
370 } else if (accepted[1]){
371 fprintf(stderr,"ico=1\n");
376 } else if (accepted[2]){
377 fprintf(stderr,"ico=2\n");
382 } else if (accepted[3]){
383 fprintf(stderr,"ico=3\n");
390 fprintf(stderr,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
391 chi2=CombiDoubleMathiesonFit(c);
392 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
393 // Float_t prob = TMath::Prob(chi2,ndf);
394 // prob2->Fill(prob);
395 // chi2_2->Fill(chi2);
397 fprintf(stderr," chi2 %f\n",chi2);
399 // If reasonable chi^2 add result to the list of rawclusters
404 // 1 maximum is initialised with the maximum of the combination found (X->cathode 2, Y->cathode 1)
405 // 1 maximum is initialised with the other maximum of the second cathode
407 fprintf(stderr,"ico=0\n");
412 } else if (accepted[1]){
413 fprintf(stderr,"ico=1\n");
418 } else if (accepted[2]){
419 fprintf(stderr,"ico=2\n");
424 } else if (accepted[3]){
425 fprintf(stderr,"ico=3\n");
432 fprintf(stderr,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
433 chi2=CombiDoubleMathiesonFit(c);
434 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
435 // Float_t prob = TMath::Prob(chi2,ndf);
436 // prob2->Fill(prob);
437 // chi2_2->Fill(chi2);
439 fprintf(stderr," chi2 %f\n",chi2);
441 // If reasonable chi^2 add result to the list of rawclusters
445 //We keep only the combination found (X->cathode 2, Y->cathode 1)
446 for (Int_t ico=0; ico<2; ico++) {
448 AliMUONRawCluster cnew;
450 for (cath=0; cath<2; cath++) {
451 cnew.fX[cath]=Float_t(xm[ico][1]);
452 cnew.fY[cath]=Float_t(ym[ico][0]);
453 cnew.fZ[cath]=fZPlane;
455 cnew.fMultiplicity[cath]=c->fMultiplicity[cath];
456 for (i=0; i<fMul[cath]; i++) {
457 cnew.fIndexMap[i][cath]=c->fIndexMap[i][cath];
458 fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
460 fprintf(stderr,"\nRawCluster %d cath %d\n",ico,cath);
461 fprintf(stderr,"mult_av %d\n",c->fMultiplicity[cath]);
462 FillCluster(&cnew,cath);
464 cnew.fClusterType=cnew.PhysicsContribution();
473 // ******* iacc = 2 *******
474 // Two combinations found between the 2 cathodes
476 // Was the same maximum taken twice
477 if ((accepted[0]&&accepted[1]) || (accepted[2]&&accepted[3])) {
478 fprintf(stderr,"\n Maximum taken twice !!!\n");
480 // Have a try !! with that
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);
502 // No ghosts ! No Problems ! - Perform one fit only !
503 if (accepted[0]&&accepted[3]) {
515 fprintf(stderr,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
516 chi2=CombiDoubleMathiesonFit(c);
517 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
518 // Float_t prob = TMath::Prob(chi2,ndf);
519 // prob2->Fill(prob);
520 // chi2_2->Fill(chi2);
522 fprintf(stderr," chi2 %f\n",chi2);
526 // ******* iacc = 4 *******
527 // Four combinations found between the 2 cathodes
529 } else if (iacc==4) {
530 // Perform fits for the two possibilities !!
531 // Accept if charges are compatible on both cathodes
532 // If none are compatible, keep everything
538 fprintf(stderr,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
539 chi2=CombiDoubleMathiesonFit(c);
540 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
541 // Float_t prob = TMath::Prob(chi2,ndf);
542 // prob2->Fill(prob);
543 // chi2_2->Fill(chi2);
545 fprintf(stderr," chi2 %f\n",chi2);
546 // store results of fit and postpone decision
547 Double_t sXFit[2],sYFit[2],sQrFit[2];
549 for (Int_t i=0;i<2;i++) {
560 fprintf(stderr,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
561 chi2=CombiDoubleMathiesonFit(c);
562 // ndf = fgNbins[0]+fgNbins[1]-6;
563 // prob = TMath::Prob(chi2,ndf);
564 // prob2->Fill(prob);
565 // chi2_2->Fill(chi2);
567 fprintf(stderr," chi2 %f\n",chi2);
568 // We have all informations to perform the decision
569 // Compute the chi2 for the 2 possibilities
570 Float_t chi2fi,chi2si,chi2f,chi2s;
572 chi2f = (TMath::Log(fInput->TotalCharge(0)*fQrFit[0]
573 / (fInput->TotalCharge(1)*fQrFit[1]) )
574 / fInput->Response()->ChargeCorrel() );
576 chi2fi = (TMath::Log(fInput->TotalCharge(0)*(1-fQrFit[0])
577 / (fInput->TotalCharge(1)*(1-fQrFit[1])) )
578 / fInput->Response()->ChargeCorrel() );
579 chi2f += chi2fi*chi2fi;
581 chi2s = (TMath::Log(fInput->TotalCharge(0)*sQrFit[0]
582 / (fInput->TotalCharge(1)*sQrFit[1]) )
583 / fInput->Response()->ChargeCorrel() );
585 chi2si = (TMath::Log(fInput->TotalCharge(0)*(1-sQrFit[0])
586 / (fInput->TotalCharge(1)*(1-sQrFit[1])) )
587 / fInput->Response()->ChargeCorrel() );
588 chi2s += chi2si*chi2si;
590 // usefull to store the charge matching chi2 in the cluster
591 // fChi2[0]=sChi2[1]=chi2f;
592 // fChi2[1]=sChi2[0]=chi2s;
594 if (chi2f<=fGhostChi2Cut && chi2s<=fGhostChi2Cut)
596 if (chi2f>fGhostChi2Cut && chi2s>fGhostChi2Cut) {
602 if (chi2f<=fGhostChi2Cut)
604 if (chi2s<=fGhostChi2Cut) {
605 // retreive saved values
606 for (Int_t i=0;i<2;i++) {
617 } else if (fNLocal[0]==2 && fNLocal[1]==1) {
618 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
619 // (3) Two local maxima on cathode 1 and one maximum on cathode 2
620 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
622 Float_t xm[4][2], ym[4][2];
623 Float_t dpx, dpy, dx, dy;
624 Int_t ixm[4][2], iym[4][2];
625 Int_t isec, im1, ico;
627 // Form the 2x2 combinations
628 // 0-0, 0-1, 1-0, 1-1
630 for (im1=0; im1<2; im1++) {
631 xm[ico][0]=fX[fIndLocal[im1][0]][0];
632 ym[ico][0]=fY[fIndLocal[im1][0]][0];
633 xm[ico][1]=fX[fIndLocal[0][1]][1];
634 ym[ico][1]=fY[fIndLocal[0][1]][1];
636 ixm[ico][0]=fIx[fIndLocal[im1][0]][0];
637 iym[ico][0]=fIy[fIndLocal[im1][0]][0];
638 ixm[ico][1]=fIx[fIndLocal[0][1]][1];
639 iym[ico][1]=fIy[fIndLocal[0][1]][1];
642 // ico = 0 : first local maximum on cathodes 1 and 2
643 // ico = 1 : second local maximum on cathode 1 and first on cathode 2
645 // Analyse the combinations and keep those that are possible !
646 // For each combination check consistency in x and y
650 // In case of staggering maxima are displaced by exactly half the pad-size in y.
651 // We have to take into account the numerical precision in the consistency check;
655 for (ico=0; ico<2; ico++) {
656 accepted[ico]=kFALSE;
657 isec=fSeg[0]->Sector(ixm[ico][0], iym[ico][0]);
658 dpx=fSeg[0]->Dpx(isec)/2.;
659 dx=TMath::Abs(xm[ico][0]-xm[ico][1]);
660 isec=fSeg[1]->Sector(ixm[ico][1], iym[ico][1]);
661 dpy=fSeg[1]->Dpy(isec)/2.;
662 dy=TMath::Abs(ym[ico][0]-ym[ico][1]);
664 printf("\n %i %f %f %f %f \n", ico, ym[ico][0], ym[ico][1], dy, dpy );
665 if ((dx <= dpx) && (dy <= dpy+eps)) {
671 accepted[ico]=kFALSE;
679 // Initial value for charge ratios
680 fQrInit[0]=Float_t(fQ[fIndLocal[0][0]][0])/
681 Float_t(fQ[fIndLocal[0][0]][0]+fQ[fIndLocal[1][0]][0]);
682 fQrInit[1]=fQrInit[0];
684 if (accepted[0] && accepted[1]) {
686 fXInit[0]=0.5*(xm[0][1]+xm[0][0]);
688 fXInit[1]=0.5*(xm[0][1]+xm[1][0]);
692 chi23=CombiDoubleMathiesonFit(c);
701 } else if (accepted[0]) {
706 chi21=CombiDoubleMathiesonFit(c);
707 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
708 // Float_t prob = TMath::Prob(chi2,ndf);
709 // prob2->Fill(prob);
710 // chi2_2->Fill(chi21);
712 fprintf(stderr," chi2 %f\n",chi21);
713 if (chi21<10) Split(c);
714 } else if (accepted[1]) {
719 chi22=CombiDoubleMathiesonFit(c);
720 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
721 // Float_t prob = TMath::Prob(chi2,ndf);
722 // prob2->Fill(prob);
723 // chi2_2->Fill(chi22);
725 fprintf(stderr," chi2 %f\n",chi22);
726 if (chi22<10) Split(c);
729 if (chi21 > 10 && chi22 > 10 && chi23 > 10) {
730 // We keep only the combination found (X->cathode 2, Y->cathode 1)
731 for (Int_t ico=0; ico<2; ico++) {
733 AliMUONRawCluster cnew;
735 for (cath=0; cath<2; cath++) {
736 cnew.fX[cath]=Float_t(xm[ico][1]);
737 cnew.fY[cath]=Float_t(ym[ico][0]);
738 cnew.fZ[cath]=fZPlane;
739 cnew.fMultiplicity[cath]=c->fMultiplicity[cath];
740 for (i=0; i<fMul[cath]; i++) {
741 cnew.fIndexMap[i][cath]=c->fIndexMap[i][cath];
742 fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
744 fprintf(stderr,"\nRawCluster %d cath %d\n",ico,cath);
745 fprintf(stderr,"mult_av %d\n",c->fMultiplicity[cath]);
746 FillCluster(&cnew,cath);
748 cnew.fClusterType=cnew.PhysicsContribution();
755 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
756 // (3') One local maximum on cathode 1 and two maxima on cathode 2
757 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
758 } else if (fNLocal[0]==1 && fNLocal[1]==2) {
759 Float_t xm[4][2], ym[4][2];
760 Float_t dpx, dpy, dx, dy;
761 Int_t ixm[4][2], iym[4][2];
762 Int_t isec, im1, ico;
764 // Form the 2x2 combinations
765 // 0-0, 0-1, 1-0, 1-1
767 for (im1=0; im1<2; im1++) {
768 xm[ico][0]=fX[fIndLocal[0][0]][0];
769 ym[ico][0]=fY[fIndLocal[0][0]][0];
770 xm[ico][1]=fX[fIndLocal[im1][1]][1];
771 ym[ico][1]=fY[fIndLocal[im1][1]][1];
773 ixm[ico][0]=fIx[fIndLocal[0][0]][0];
774 iym[ico][0]=fIy[fIndLocal[0][0]][0];
775 ixm[ico][1]=fIx[fIndLocal[im1][1]][1];
776 iym[ico][1]=fIy[fIndLocal[im1][1]][1];
779 // ico = 0 : first local maximum on cathodes 1 and 2
780 // ico = 1 : first local maximum on cathode 1 and second on cathode 2
782 // Analyse the combinations and keep those that are possible !
783 // For each combination check consistency in x and y
787 // In case of staggering maxima are displaced by exactly half the pad-size in y.
788 // We have to take into account the numerical precision in the consistency check;
792 for (ico=0; ico<2; ico++) {
793 accepted[ico]=kFALSE;
794 isec=fSeg[0]->Sector(ixm[ico][0], iym[ico][0]);
795 dpx=fSeg[0]->Dpx(isec)/2.;
796 dx=TMath::Abs(xm[ico][0]-xm[ico][1]);
797 isec=fSeg[1]->Sector(ixm[ico][1], iym[ico][1]);
798 dpy=fSeg[1]->Dpy(isec)/2.;
799 dy=TMath::Abs(ym[ico][0]-ym[ico][1]);
801 printf("\n %i %f %f %f %f \n", ico, ym[ico][0], ym[ico][1], dy, dpy );
802 if ((dx <= dpx) && (dy <= dpy+eps)) {
805 fprintf(stderr,"ico %d\n",ico);
809 accepted[ico]=kFALSE;
817 fQrInit[1]=Float_t(fQ[fIndLocal[0][1]][1])/
818 Float_t(fQ[fIndLocal[0][1]][1]+fQ[fIndLocal[1][1]][1]);
820 fQrInit[0]=fQrInit[1];
823 if (accepted[0] && accepted[1]) {
825 fYInit[0]=0.5*(ym[0][0]+ym[0][1]);
827 fYInit[1]=0.5*(ym[0][0]+ym[1][1]);
830 chi23=CombiDoubleMathiesonFit(c);
839 } else if (accepted[0]) {
844 chi21=CombiDoubleMathiesonFit(c);
845 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
846 // Float_t prob = TMath::Prob(chi2,ndf);
847 // prob2->Fill(prob);
848 // chi2_2->Fill(chi21);
850 fprintf(stderr," chi2 %f\n",chi21);
851 if (chi21<10) Split(c);
852 } else if (accepted[1]) {
857 chi22=CombiDoubleMathiesonFit(c);
858 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
859 // Float_t prob = TMath::Prob(chi2,ndf);
860 // prob2->Fill(prob);
861 // chi2_2->Fill(chi22);
863 fprintf(stderr," chi2 %f\n",chi22);
864 if (chi22<10) Split(c);
867 if (chi21 > 10 && chi22 > 10 && chi23 > 10) {
868 //We keep only the combination found (X->cathode 2, Y->cathode 1)
869 for (Int_t ico=0; ico<2; ico++) {
871 AliMUONRawCluster cnew;
873 for (cath=0; cath<2; cath++) {
874 cnew.fX[cath]=Float_t(xm[ico][1]);
875 cnew.fY[cath]=Float_t(ym[ico][0]);
876 cnew.fZ[cath]=fZPlane;
877 cnew.fMultiplicity[cath]=c->fMultiplicity[cath];
878 for (i=0; i<fMul[cath]; i++) {
879 cnew.fIndexMap[i][cath]=c->fIndexMap[i][cath];
880 fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
882 fprintf(stderr,"\nRawCluster %d cath %d\n",ico,cath);
883 fprintf(stderr,"mult_av %d\n",c->fMultiplicity[cath]);
884 FillCluster(&cnew,cath);
886 cnew.fClusterType=cnew.PhysicsContribution();
893 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
894 // (4) At least three local maxima on cathode 1 or on cathode 2
895 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
896 } else if (fNLocal[0]>2 || fNLocal[1]>2) {
897 Int_t param = fNLocal[0]*fNLocal[1];
900 Float_t ** xm = new Float_t * [param];
901 for (ii=0; ii<param; ii++) xm[ii]=new Float_t [2];
902 Float_t ** ym = new Float_t * [param];
903 for (ii=0; ii<param; ii++) ym[ii]=new Float_t [2];
904 Int_t ** ixm = new Int_t * [param];
905 for (ii=0; ii<param; ii++) ixm[ii]=new Int_t [2];
906 Int_t ** iym = new Int_t * [param];
907 for (ii=0; ii<param; ii++) iym[ii]=new Int_t [2];
910 Float_t dpx, dpy, dx, dy;
913 for (Int_t im1=0; im1<fNLocal[0]; im1++) {
914 for (Int_t im2=0; im2<fNLocal[1]; im2++) {
915 xm[ico][0]=fX[fIndLocal[im1][0]][0];
916 ym[ico][0]=fY[fIndLocal[im1][0]][0];
917 xm[ico][1]=fX[fIndLocal[im2][1]][1];
918 ym[ico][1]=fY[fIndLocal[im2][1]][1];
920 ixm[ico][0]=fIx[fIndLocal[im1][0]][0];
921 iym[ico][0]=fIy[fIndLocal[im1][0]][0];
922 ixm[ico][1]=fIx[fIndLocal[im2][1]][1];
923 iym[ico][1]=fIy[fIndLocal[im2][1]][1];
930 fprintf(stderr,"nIco %d\n",nIco);
931 for (ico=0; ico<nIco; ico++) {
933 fprintf(stderr,"ico = %d\n",ico);
934 isec=fSeg[0]->Sector(ixm[ico][0], iym[ico][0]);
935 dpx=fSeg[0]->Dpx(isec)/2.;
936 dx=TMath::Abs(xm[ico][0]-xm[ico][1]);
937 isec=fSeg[1]->Sector(ixm[ico][1], iym[ico][1]);
938 dpy=fSeg[1]->Dpy(isec)/2.;
939 dy=TMath::Abs(ym[ico][0]-ym[ico][1]);
941 fprintf(stderr,"dx %f dpx %f dy %f dpy %f\n",dx,dpx,dy,dpy);
942 fprintf(stderr," X %f Y %f\n",xm[ico][1],ym[ico][0]);
944 if ((dx <= dpx) && (dy <= dpy)) {
946 fprintf(stderr,"ok\n");
948 AliMUONRawCluster cnew;
949 for (cath=0; cath<2; cath++) {
950 cnew.fX[cath]=Float_t(xm[ico][1]);
951 cnew.fY[cath]=Float_t(ym[ico][0]);
952 cnew.fZ[cath]=fZPlane;
953 cnew.fMultiplicity[cath]=c->fMultiplicity[cath];
954 for (i=0; i<fMul[cath]; i++) {
955 cnew.fIndexMap[i][cath]=c->fIndexMap[i][cath];
956 fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
958 FillCluster(&cnew,cath);
960 cnew.fClusterType=cnew.PhysicsContribution();
972 void AliMUONClusterFinderVS::FindLocalMaxima(AliMUONRawCluster* /*c*/)
974 // Find all local maxima of a cluster
976 printf("\n Find Local maxima !");
980 Int_t cath, cath1; // loops over cathodes
981 Int_t i; // loops over digits
982 Int_t j; // loops over cathodes
986 // counters for number of local maxima
987 fNLocal[0]=fNLocal[1]=0;
988 // flags digits as local maximum
989 Bool_t isLocal[100][2];
990 for (i=0; i<100;i++) {
991 isLocal[i][0]=isLocal[i][1]=kFALSE;
993 // number of next neighbours and arrays to store them
996 // loop over cathodes
997 for (cath=0; cath<2; cath++) {
998 // loop over cluster digits
999 for (i=0; i<fMul[cath]; i++) {
1000 // get neighbours for that digit and assume that it is local maximum
1001 fSeg[cath]->Neighbours(fIx[i][cath], fIy[i][cath], &nn, x, y);
1002 isLocal[i][cath]=kTRUE;
1003 Int_t isec= fSeg[cath]->Sector(fIx[i][cath], fIy[i][cath]);
1004 Float_t a0 = fSeg[cath]->Dpx(isec)*fSeg[cath]->Dpy(isec);
1005 // loop over next neighbours, if at least one neighbour has higher charger assumption
1006 // digit is not local maximum
1007 for (j=0; j<nn; j++) {
1008 if (fHitMap[cath]->TestHit(x[j], y[j])==kEmpty) continue;
1009 digt=(AliMUONDigit*) fHitMap[cath]->GetHit(x[j], y[j]);
1010 isec=fSeg[cath]->Sector(x[j], y[j]);
1011 Float_t a1 = fSeg[cath]->Dpx(isec)*fSeg[cath]->Dpy(isec);
1012 if (digt->Signal()/a1 > fQ[i][cath]/a0) {
1013 isLocal[i][cath]=kFALSE;
1016 // handle special case of neighbouring pads with equal signal
1017 } else if (digt->Signal() == fQ[i][cath]) {
1018 if (fNLocal[cath]>0) {
1019 for (Int_t k=0; k<fNLocal[cath]; k++) {
1020 if (x[j]==fIx[fIndLocal[k][cath]][cath]
1021 && y[j]==fIy[fIndLocal[k][cath]][cath])
1023 isLocal[i][cath]=kFALSE;
1025 } // loop over local maxima
1026 } // are there already local maxima
1028 } // loop over next neighbours
1029 if (isLocal[i][cath]) {
1030 fIndLocal[fNLocal[cath]][cath]=i;
1033 } // loop over all digits
1034 } // loop over cathodes
1037 printf("\n Found %d %d %d %d local Maxima\n",
1038 fNLocal[0], fNLocal[1], fMul[0], fMul[1]);
1039 fprintf(stderr,"\n Cathode 1 local Maxima %d Multiplicite %d\n",fNLocal[0], fMul[0]);
1040 fprintf(stderr," Cathode 2 local Maxima %d Multiplicite %d\n",fNLocal[1], fMul[1]);
1046 if (fNLocal[1]==2 && (fNLocal[0]==1 || fNLocal[0]==0)) {
1047 Int_t iback=fNLocal[0];
1049 // Two local maxima on cathode 2 and one maximum on cathode 1
1050 // Look for local maxima considering up and down neighbours on the 1st cathode only
1052 // Loop over cluster digits
1056 for (i=0; i<fMul[cath]; i++) {
1057 isec=fSeg[cath]->Sector(fIx[i][cath],fIy[i][cath]);
1058 dpy=fSeg[cath]->Dpy(isec);
1059 dpx=fSeg[cath]->Dpx(isec);
1060 if (isLocal[i][cath]) continue;
1061 // Pad position should be consistent with position of local maxima on the opposite cathode
1062 if ((TMath::Abs(fX[i][cath]-fX[fIndLocal[0][cath1]][cath1]) > dpx/2.) &&
1063 (TMath::Abs(fX[i][cath]-fX[fIndLocal[1][cath1]][cath1]) > dpx/2.))
1066 // get neighbours for that digit and assume that it is local maximum
1067 isLocal[i][cath]=kTRUE;
1068 // compare signal to that on the two neighbours on the left and on the right
1069 // iNN counts the number of neighbours with signal, it should be 1 or 2
1073 ->FirstPad(fX[i][cath], fY[i][cath], fZPlane, 0., dpy);
1079 ix = fSeg[cath]->Ix();
1080 iy = fSeg[cath]->Iy();
1081 // skip the current pad
1082 if (iy == fIy[i][cath]) continue;
1084 if (fHitMap[cath]->TestHit(ix, iy)!=kEmpty) {
1086 digt=(AliMUONDigit*) fHitMap[cath]->GetHit(ix,iy);
1087 if (digt->Signal() > fQ[i][cath]) isLocal[i][cath]=kFALSE;
1089 } // Loop over pad neighbours in y
1090 if (isLocal[i][cath] && iNN>0) {
1091 fIndLocal[fNLocal[cath]][cath]=i;
1094 } // loop over all digits
1095 // if one additional maximum has been found we are happy
1096 // if more maxima have been found restore the previous situation
1099 "\n New search gives %d local maxima for cathode 1 \n",
1102 " %d local maxima for cathode 2 \n",
1105 if (fNLocal[cath]>2) {
1106 fNLocal[cath]=iback;
1109 } // 1,2 local maxima
1111 if (fNLocal[0]==2 && (fNLocal[1]==1 || fNLocal[1]==0)) {
1112 Int_t iback=fNLocal[1];
1114 // Two local maxima on cathode 1 and one maximum on cathode 2
1115 // Look for local maxima considering left and right neighbours on the 2nd cathode only
1118 Float_t eps = 1.e-5;
1121 // Loop over cluster digits
1122 for (i=0; i<fMul[cath]; i++) {
1123 isec=fSeg[cath]->Sector(fIx[i][cath],fIy[i][cath]);
1124 dpx=fSeg[cath]->Dpx(isec);
1125 dpy=fSeg[cath]->Dpy(isec);
1126 if (isLocal[i][cath]) continue;
1127 // Pad position should be consistent with position of local maxima on the opposite cathode
1128 if ((TMath::Abs(fY[i][cath]-fY[fIndLocal[0][cath1]][cath1]) > dpy/2.+eps) &&
1129 (TMath::Abs(fY[i][cath]-fY[fIndLocal[1][cath1]][cath1]) > dpy/2.+eps))
1133 // get neighbours for that digit and assume that it is local maximum
1134 isLocal[i][cath]=kTRUE;
1135 // compare signal to that on the two neighbours on the left and on the right
1137 // iNN counts the number of neighbours with signal, it should be 1 or 2
1140 ->FirstPad(fX[i][cath], fY[i][cath], fZPlane, dpx, 0.);
1147 ix = fSeg[cath]->Ix();
1148 iy = fSeg[cath]->Iy();
1150 // skip the current pad
1151 if (ix == fIx[i][cath]) continue;
1153 if (fHitMap[cath]->TestHit(ix, iy)!=kEmpty) {
1155 digt=(AliMUONDigit*) fHitMap[cath]->GetHit(ix,iy);
1156 if (digt->Signal() > fQ[i][cath]) isLocal[i][cath]=kFALSE;
1158 } // Loop over pad neighbours in x
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
1167 fprintf(stderr,"\n New search gives %d local maxima for cathode 1 \n",fNLocal[0]);
1168 fprintf(stderr,"\n %d local maxima for cathode 2 \n",fNLocal[1]);
1169 printf("\n New search gives %d %d \n",fNLocal[0],fNLocal[1]);
1171 if (fNLocal[cath]>2) {
1172 fNLocal[cath]=iback;
1174 } // 2,1 local maxima
1178 void AliMUONClusterFinderVS::FillCluster(AliMUONRawCluster* c, Int_t flag, Int_t cath)
1181 // Completes cluster information starting from list of digits
1188 c->fPeakSignal[cath]=c->fPeakSignal[0];
1190 c->fPeakSignal[cath]=0;
1201 fprintf(stderr,"\n fPeakSignal %d\n",c->fPeakSignal[cath]);
1202 for (Int_t i=0; i<c->fMultiplicity[cath]; i++)
1204 dig= fInput->Digit(cath,c->fIndexMap[i][cath]);
1205 ix=dig->PadX()+c->fOffsetMap[i][cath];
1207 Int_t q=dig->Signal();
1208 if (!flag) q=Int_t(q*c->fContMap[i][cath]);
1209 // fprintf(stderr,"q %d c->fPeakSignal[ %d ] %d\n",q,cath,c->fPeakSignal[cath]);
1210 if (dig->Physics() >= dig->Signal()) {
1211 c->fPhysicsMap[i]=2;
1212 } else if (dig->Physics() == 0) {
1213 c->fPhysicsMap[i]=0;
1214 } else c->fPhysicsMap[i]=1;
1218 fprintf(stderr,"q %d c->fPeakSignal[cath] %d\n",q,c->fPeakSignal[cath]);
1219 // peak signal and track list
1220 if (q>c->fPeakSignal[cath]) {
1221 c->fPeakSignal[cath]=q;
1222 c->fTracks[0]=dig->Hit();
1223 c->fTracks[1]=dig->Track(0);
1224 c->fTracks[2]=dig->Track(1);
1225 // fprintf(stderr," c->fTracks[0] %d c->fTracks[1] %d\n",dig->fHit,dig->fTracks[0]);
1229 fSeg[cath]->GetPadC(ix, iy, x, y, z);
1234 } // loop over digits
1236 fprintf(stderr," fin du cluster c\n");
1240 c->fX[cath]/=c->fQ[cath];
1242 c->fX[cath]=fSeg[cath]->GetAnod(c->fX[cath]);
1243 c->fY[cath]/=c->fQ[cath];
1245 // apply correction to the coordinate along the anode wire
1249 fSeg[cath]->GetPadI(x, y, fZPlane, ix, iy);
1250 fSeg[cath]->GetPadC(ix, iy, x, y, z);
1251 Int_t isec=fSeg[cath]->Sector(ix,iy);
1252 TF1* cogCorr = fSeg[cath]->CorrFunc(isec-1);
1255 Float_t yOnPad=(c->fY[cath]-y)/fSeg[cath]->Dpy(isec);
1256 c->fY[cath]=c->fY[cath]-cogCorr->Eval(yOnPad, 0, 0);
1261 void AliMUONClusterFinderVS::FillCluster(AliMUONRawCluster* c, Int_t cath)
1264 // Completes cluster information starting from list of digits
1274 Float_t xpad, ypad, zpad;
1277 for (Int_t i=0; i<c->fMultiplicity[cath]; i++)
1279 dig = fInput->Digit(cath,c->fIndexMap[i][cath]);
1281 GetPadC(dig->PadX(),dig->PadY(),xpad,ypad, zpad);
1283 fprintf(stderr,"x %f y %f cx %f cy %f\n",xpad,ypad,c->fX[0],c->fY[0]);
1284 dx = xpad - c->fX[0];
1285 dy = ypad - c->fY[0];
1286 dr = TMath::Sqrt(dx*dx+dy*dy);
1291 fprintf(stderr," dr %f\n",dr);
1292 Int_t q=dig->Signal();
1293 if (dig->Physics() >= dig->Signal()) {
1294 c->fPhysicsMap[i]=2;
1295 } else if (dig->Physics() == 0) {
1296 c->fPhysicsMap[i]=0;
1297 } else c->fPhysicsMap[i]=1;
1298 c->fPeakSignal[cath]=q;
1299 c->fTracks[0]=dig->Hit();
1300 c->fTracks[1]=dig->Track(0);
1301 c->fTracks[2]=dig->Track(1);
1303 fprintf(stderr," c->fTracks[0] %d c->fTracks[1] %d\n",dig->Hit(),
1307 } // loop over digits
1309 // apply correction to the coordinate along the anode wire
1311 c->fX[cath]=fSeg[cath]->GetAnod(c->fX[cath]);
1314 void AliMUONClusterFinderVS::FindCluster(Int_t i, Int_t j, Int_t cath, AliMUONRawCluster &c){
1318 // Find a super cluster on both cathodes
1321 // Add i,j as element of the cluster
1324 Int_t idx = fHitMap[cath]->GetHitIndex(i,j);
1325 AliMUONDigit* dig = (AliMUONDigit*) fHitMap[cath]->GetHit(i,j);
1326 Int_t q=dig->Signal();
1327 Int_t theX=dig->PadX();
1328 Int_t theY=dig->PadY();
1330 if (q > TMath::Abs(c.fPeakSignal[0]) && q > TMath::Abs(c.fPeakSignal[1])) {
1331 c.fPeakSignal[cath]=q;
1332 c.fTracks[0]=dig->Hit();
1333 c.fTracks[1]=dig->Track(0);
1334 c.fTracks[2]=dig->Track(1);
1338 // Make sure that list of digits is ordered
1340 Int_t mu=c.fMultiplicity[cath];
1341 c.fIndexMap[mu][cath]=idx;
1343 if (dig->Physics() >= dig->Signal()) {
1344 c.fPhysicsMap[mu]=2;
1345 } else if (dig->Physics() == 0) {
1346 c.fPhysicsMap[mu]=0;
1347 } else c.fPhysicsMap[mu]=1;
1351 for (Int_t ind = mu-1; ind >= 0; ind--) {
1352 Int_t ist=(c.fIndexMap)[ind][cath];
1353 Int_t ql=fInput->Digit(cath, ist)->Signal();
1354 Int_t ix=fInput->Digit(cath, ist)->PadX();
1355 Int_t iy=fInput->Digit(cath, ist)->PadY();
1357 if (q>ql || (q==ql && theX > ix && theY < iy)) {
1358 c.fIndexMap[ind][cath]=idx;
1359 c.fIndexMap[ind+1][cath]=ist;
1367 c.fMultiplicity[cath]++;
1368 if (c.fMultiplicity[cath] >= 50 ) {
1369 printf("FindCluster - multiplicity >50 %d \n",c.fMultiplicity[0]);
1370 c.fMultiplicity[cath]=49;
1373 // Prepare center of gravity calculation
1375 fSeg[cath]->GetPadC(i, j, x, y, z);
1381 // Flag hit as "taken"
1382 fHitMap[cath]->FlagHit(i,j);
1384 // Now look recursively for all neighbours and pad hit on opposite cathode
1386 // Loop over neighbours
1390 Int_t xList[10], yList[10];
1391 fSeg[cath]->Neighbours(i,j,&nn,xList,yList);
1392 for (Int_t in=0; in<nn; in++) {
1396 if (fHitMap[cath]->TestHit(ix,iy)==kUnused) {
1398 printf("\n Neighbours %d %d %d", cath, ix, iy);
1399 FindCluster(ix, iy, cath, c);
1404 Int_t iXopp[50], iYopp[50];
1406 // Neighbours on opposite cathode
1407 // Take into account that several pads can overlap with the present pad
1408 Int_t isec=fSeg[cath]->Sector(i,j);
1414 dx = (fSeg[cath]->Dpx(isec))/2.;
1419 dy = (fSeg[cath]->Dpy(isec))/2;
1421 // loop over pad neighbours on opposite cathode
1422 for (fSeg[iop]->FirstPad(x, y, fZPlane, dx, dy);
1423 fSeg[iop]->MorePads();
1424 fSeg[iop]->NextPad())
1427 ix = fSeg[iop]->Ix(); iy = fSeg[iop]->Iy();
1428 if (fDebugLevel > 1)
1429 printf("\n ix, iy: %f %f %f %d %d %d", x,y,z,ix, iy, fSector);
1430 if (fHitMap[iop]->TestHit(ix,iy)==kUnused){
1433 if (fDebugLevel > 1)
1434 printf("\n Opposite %d %d %d", iop, ix, iy);
1437 } // Loop over pad neighbours
1438 // This had to go outside the loop since recursive calls inside the iterator are not possible
1441 for (jopp=0; jopp<nOpp; jopp++) {
1442 if (fHitMap[iop]->TestHit(iXopp[jopp],iYopp[jopp]) == kUnused)
1443 FindCluster(iXopp[jopp], iYopp[jopp], iop, c);
1447 //_____________________________________________________________________________
1449 void AliMUONClusterFinderVS::FindRawClusters()
1452 // MUON cluster finder from digits -- finds neighbours on both cathodes and
1453 // fills the tree with raw clusters
1457 // Return if no input datad available
1458 if (!fInput->NDigits(0) && !fInput->NDigits(1)) return;
1460 fSeg[0] = fInput->Segmentation(0);
1461 fSeg[1] = fInput->Segmentation(1);
1463 fHitMap[0] = new AliMUONHitMapA1(fSeg[0], fInput->Digits(0));
1464 fHitMap[1] = new AliMUONHitMapA1(fSeg[1], fInput->Digits(1));
1472 fHitMap[0]->FillHits();
1473 fHitMap[1]->FillHits();
1475 // Outer Loop over Cathodes
1476 for (cath=0; cath<2; cath++) {
1477 for (ndig=0; ndig<fInput->NDigits(cath); ndig++) {
1478 dig = fInput->Digit(cath, ndig);
1479 Int_t i=dig->PadX();
1480 Int_t j=dig->PadY();
1481 if (fHitMap[cath]->TestHit(i,j)==kUsed ||fHitMap[0]->TestHit(i,j)==kEmpty) {
1486 fprintf(stderr,"\n CATHODE %d CLUSTER %d\n",cath,ncls);
1487 AliMUONRawCluster c;
1488 c.fMultiplicity[0]=0;
1489 c.fMultiplicity[1]=0;
1490 c.fPeakSignal[cath]=dig->Signal();
1491 c.fTracks[0]=dig->Hit();
1492 c.fTracks[1]=dig->Track(0);
1493 c.fTracks[2]=dig->Track(1);
1494 // tag the beginning of cluster list in a raw cluster
1497 fSeg[cath]->GetPadC(i,j,xcu, ycu, fZPlane);
1498 fSector= fSeg[cath]->Sector(i,j)/100;
1500 printf("\n New Seed %d %d ", i,j);
1503 FindCluster(i,j,cath,c);
1504 // ^^^^^^^^^^^^^^^^^^^^^^^^
1505 // center of gravity
1506 if (c.fX[0]!=0.) c.fX[0] /= c.fQ[0];
1508 c.fX[0]=fSeg[0]->GetAnod(c.fX[0]);
1509 if (c.fY[0]!=0.) c.fY[0] /= c.fQ[0];
1511 if(c.fQ[1]!=0.) c.fX[1] /= c.fQ[1];
1514 c.fX[1]=fSeg[0]->GetAnod(c.fX[1]);
1515 if(c.fQ[1]!=0.) c.fY[1] /= c.fQ[1];
1521 fprintf(stderr,"\n Cathode 1 multiplicite %d X(CG) %f Y(CG) %f\n",
1522 c.fMultiplicity[0],c.fX[0],c.fY[0]);
1523 fprintf(stderr," Cathode 2 multiplicite %d X(CG) %f Y(CG) %f\n",
1524 c.fMultiplicity[1],c.fX[1],c.fY[1]);
1526 // Analyse cluster and decluster if necessary
1529 c.fNcluster[1]=fNRawClusters;
1530 c.fClusterType=c.PhysicsContribution();
1537 // reset Cluster object
1538 { // begin local scope
1539 for (int k=0;k<c.fMultiplicity[0];k++) c.fIndexMap[k][0]=0;
1540 } // end local scope
1542 { // begin local scope
1543 for (int k=0;k<c.fMultiplicity[1];k++) c.fIndexMap[k][1]=0;
1544 } // end local scope
1546 c.fMultiplicity[0]=c.fMultiplicity[0]=0;
1550 } // end loop cathodes
1555 Float_t AliMUONClusterFinderVS::SingleMathiesonFit(AliMUONRawCluster *c, Int_t cath)
1557 // Performs a single Mathieson fit on one cathode
1559 Double_t arglist[20];
1561 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
1563 clusterInput.Fitter()->SetFCN(fcnS1);
1564 clusterInput.Fitter()->mninit(2,10,7);
1565 clusterInput.Fitter()->SetPrintLevel(-1+fDebugLevel);
1567 clusterInput.Fitter()->mnexcm("SET NOW", arglist, 0, ierflag);
1568 // Set starting values
1569 static Double_t vstart[2];
1574 // lower and upper limits
1575 static Double_t lower[2], upper[2];
1577 fSeg[cath]->GetPadI(c->fX[cath], c->fY[cath], fZPlane, ix, iy);
1578 Int_t isec=fSeg[cath]->Sector(ix, iy);
1579 lower[0]=vstart[0]-fSeg[cath]->Dpx(isec)/2;
1580 lower[1]=vstart[1]-fSeg[cath]->Dpy(isec)/2;
1582 upper[0]=lower[0]+fSeg[cath]->Dpx(isec);
1583 upper[1]=lower[1]+fSeg[cath]->Dpy(isec);
1586 static Double_t step[2]={0.0005, 0.0005};
1588 clusterInput.Fitter()->mnparm(0,"x1",vstart[0],step[0],lower[0],upper[0],ierflag);
1589 clusterInput.Fitter()->mnparm(1,"y1",vstart[1],step[1],lower[1],upper[1],ierflag);
1590 // ready for minimisation
1594 clusterInput.Fitter()->mnexcm("SET NOGR", arglist, 0, ierflag);
1595 clusterInput.Fitter()->mnexcm("MIGRAD", arglist, 0, ierflag);
1596 // clusterInput.Fitter()->mnexcm("EXIT" , arglist, 0, ierflag);
1597 Double_t fmin, fedm, errdef;
1598 Int_t npari, nparx, istat;
1600 clusterInput.Fitter()->mnstat(fmin, fedm, errdef, npari, nparx, istat);
1604 // Get fitted parameters
1605 Double_t xrec, yrec;
1607 Double_t epxz, b1, b2;
1609 clusterInput.Fitter()->mnpout(0, chname, xrec, epxz, b1, b2, ierflg);
1610 clusterInput.Fitter()->mnpout(1, chname, yrec, epxz, b1, b2, ierflg);
1616 Float_t AliMUONClusterFinderVS::CombiSingleMathiesonFit(AliMUONRawCluster * /*c*/)
1618 // Perform combined Mathieson fit on both cathode planes
1620 Double_t arglist[20];
1622 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
1623 clusterInput.Fitter()->SetFCN(fcnCombiS1);
1624 clusterInput.Fitter()->mninit(2,10,7);
1625 clusterInput.Fitter()->SetPrintLevel(-1+fDebugLevel);
1627 clusterInput.Fitter()->mnexcm("SET NOW", arglist, 0, ierflag);
1628 static Double_t vstart[2];
1629 vstart[0]=fXInit[0];
1630 vstart[1]=fYInit[0];
1633 // lower and upper limits
1634 static Float_t lower[2], upper[2];
1636 fSeg[0]->GetPadI(fXInit[0], fYInit[0], fZPlane, ix, iy);
1637 isec=fSeg[0]->Sector(ix, iy);
1638 Float_t dpy=fSeg[0]->Dpy(isec);
1639 fSeg[1]->GetPadI(fXInit[0], fYInit[0], fZPlane, ix, iy);
1640 isec=fSeg[1]->Sector(ix, iy);
1641 Float_t dpx=fSeg[1]->Dpx(isec);
1644 Float_t xdum, ydum, zdum;
1646 // Find save upper and lower limits
1650 for (fSeg[1]->FirstPad(fXInit[0], fYInit[0], fZPlane, dpx, 0.);
1651 fSeg[1]->MorePads(); fSeg[1]->NextPad())
1653 ix=fSeg[1]->Ix(); iy=fSeg[1]->Iy();
1654 fSeg[1]->GetPadC(ix,iy, upper[0], ydum, zdum);
1655 if (icount ==0) lower[0]=upper[0];
1659 if (lower[0]>upper[0]) {xdum=lower[0]; lower[0]=upper[0]; upper[0]=xdum;}
1663 printf("\n single y %f %f", fXInit[0], fYInit[0]);
1665 for (fSeg[0]->FirstPad(fXInit[0], fYInit[0], fZPlane, 0., dpy);
1666 fSeg[0]->MorePads(); fSeg[0]->NextPad())
1668 ix=fSeg[0]->Ix(); iy=fSeg[0]->Iy();
1669 fSeg[0]->GetPadC(ix,iy,xdum,upper[1],zdum);
1670 if (icount ==0) lower[1]=upper[1];
1673 printf("\n upper lower %d %f %f", icount, upper[1], lower[1]);
1676 if (lower[1]>upper[1]) {xdum=lower[1]; lower[1]=upper[1]; upper[1]=xdum;}
1679 static Double_t step[2]={0.00001, 0.0001};
1681 clusterInput.Fitter()->mnparm(0,"x1",vstart[0],step[0],lower[0],upper[0],ierflag);
1682 clusterInput.Fitter()->mnparm(1,"y1",vstart[1],step[1],lower[1],upper[1],ierflag);
1683 // ready for minimisation
1687 clusterInput.Fitter()->mnexcm("SET NOGR", arglist, 0, ierflag);
1688 clusterInput.Fitter()->mnexcm("MIGRAD", arglist, 0, ierflag);
1689 // clusterInput.Fitter()->mnexcm("EXIT" , arglist, 0, ierflag);
1690 Double_t fmin, fedm, errdef;
1691 Int_t npari, nparx, istat;
1693 clusterInput.Fitter()->mnstat(fmin, fedm, errdef, npari, nparx, istat);
1697 // Get fitted parameters
1698 Double_t xrec, yrec;
1700 Double_t epxz, b1, b2;
1702 clusterInput.Fitter()->mnpout(0, chname, xrec, epxz, b1, b2, ierflg);
1703 clusterInput.Fitter()->mnpout(1, chname, yrec, epxz, b1, b2, ierflg);
1709 Bool_t AliMUONClusterFinderVS::DoubleMathiesonFit(AliMUONRawCluster * /*c*/, Int_t cath)
1711 // Performs a double Mathieson fit on one cathode
1715 // Initialise global variables for fit
1716 Double_t arglist[20];
1718 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
1719 clusterInput.Fitter()->SetFCN(fcnS2);
1720 clusterInput.Fitter()->mninit(5,10,7);
1721 clusterInput.Fitter()->SetPrintLevel(-1+fDebugLevel);
1723 clusterInput.Fitter()->mnexcm("SET NOW", arglist, 0, ierflag);
1724 // Set starting values
1725 static Double_t vstart[5];
1726 vstart[0]=fX[fIndLocal[0][cath]][cath];
1727 vstart[1]=fY[fIndLocal[0][cath]][cath];
1728 vstart[2]=fX[fIndLocal[1][cath]][cath];
1729 vstart[3]=fY[fIndLocal[1][cath]][cath];
1730 vstart[4]=Float_t(fQ[fIndLocal[0][cath]][cath])/
1731 Float_t(fQ[fIndLocal[0][cath]][cath]+fQ[fIndLocal[1][cath]][cath]);
1732 // lower and upper limits
1733 static Float_t lower[5], upper[5];
1734 Int_t isec=fSeg[cath]->Sector(fIx[fIndLocal[0][cath]][cath], fIy[fIndLocal[0][cath]][cath]);
1735 lower[0]=vstart[0]-fSeg[cath]->Dpx(isec);
1736 lower[1]=vstart[1]-fSeg[cath]->Dpy(isec);
1738 upper[0]=lower[0]+2.*fSeg[cath]->Dpx(isec);
1739 upper[1]=lower[1]+2.*fSeg[cath]->Dpy(isec);
1741 isec=fSeg[cath]->Sector(fIx[fIndLocal[1][cath]][cath], fIy[fIndLocal[1][cath]][cath]);
1742 lower[2]=vstart[2]-fSeg[cath]->Dpx(isec)/2;
1743 lower[3]=vstart[3]-fSeg[cath]->Dpy(isec)/2;
1745 upper[2]=lower[2]+fSeg[cath]->Dpx(isec);
1746 upper[3]=lower[3]+fSeg[cath]->Dpy(isec);
1751 static Double_t step[5]={0.0005, 0.0005, 0.0005, 0.0005, 0.0001};
1753 clusterInput.Fitter()->mnparm(0,"x1",vstart[0],step[0],lower[0],upper[0],ierflag);
1754 clusterInput.Fitter()->mnparm(1,"y1",vstart[1],step[1],lower[1],upper[1],ierflag);
1755 clusterInput.Fitter()->mnparm(2,"x2",vstart[2],step[2],lower[2],upper[2],ierflag);
1756 clusterInput.Fitter()->mnparm(3,"y2",vstart[3],step[3],lower[3],upper[3],ierflag);
1757 clusterInput.Fitter()->mnparm(4,"a0",vstart[4],step[4],lower[4],upper[4],ierflag);
1758 // ready for minimisation
1762 clusterInput.Fitter()->mnexcm("SET NOGR", arglist, 0, ierflag);
1763 clusterInput.Fitter()->mnexcm("MIGRAD", arglist, 0, ierflag);
1764 // clusterInput.Fitter()->mnexcm("EXIT" , arglist, 0, ierflag);
1765 // Get fitted parameters
1766 Double_t xrec[2], yrec[2], qfrac;
1768 Double_t epxz, b1, b2;
1770 clusterInput.Fitter()->mnpout(0, chname, xrec[0], epxz, b1, b2, ierflg);
1771 clusterInput.Fitter()->mnpout(1, chname, yrec[0], epxz, b1, b2, ierflg);
1772 clusterInput.Fitter()->mnpout(2, chname, xrec[1], epxz, b1, b2, ierflg);
1773 clusterInput.Fitter()->mnpout(3, chname, yrec[1], epxz, b1, b2, ierflg);
1774 clusterInput.Fitter()->mnpout(4, chname, qfrac, epxz, b1, b2, ierflg);
1776 Double_t fmin, fedm, errdef;
1777 Int_t npari, nparx, istat;
1779 clusterInput.Fitter()->mnstat(fmin, fedm, errdef, npari, nparx, istat);
1784 Float_t AliMUONClusterFinderVS::CombiDoubleMathiesonFit(AliMUONRawCluster * /*c*/)
1787 // Perform combined double Mathieson fit on both cathode planes
1789 Double_t arglist[20];
1791 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
1792 clusterInput.Fitter()->SetFCN(fcnCombiS2);
1793 clusterInput.Fitter()->mninit(6,10,7);
1794 clusterInput.Fitter()->SetPrintLevel(-1+fDebugLevel);
1796 clusterInput.Fitter()->mnexcm("SET NOW", arglist, 0, ierflag);
1797 // Set starting values
1798 static Double_t vstart[6];
1799 vstart[0]=fXInit[0];
1800 vstart[1]=fYInit[0];
1801 vstart[2]=fXInit[1];
1802 vstart[3]=fYInit[1];
1803 vstart[4]=fQrInit[0];
1804 vstart[5]=fQrInit[1];
1805 // lower and upper limits
1806 static Float_t lower[6], upper[6];
1810 fSeg[1]->GetPadI(fXInit[0], fYInit[0], fZPlane, ix, iy);
1811 isec=fSeg[1]->Sector(ix, iy);
1812 dpx=fSeg[1]->Dpx(isec);
1814 fSeg[0]->GetPadI(fXInit[0], fYInit[0], fZPlane, ix, iy);
1815 isec=fSeg[0]->Sector(ix, iy);
1816 dpy=fSeg[0]->Dpy(isec);
1820 Float_t xdum, ydum, zdum;
1822 printf("\n Cluster Finder: %f %f %f %f ", fXInit[0], fXInit[1],fYInit[0], fYInit[1] );
1824 // Find save upper and lower limits
1827 for (fSeg[1]->FirstPad(fXInit[0], fYInit[0], fZPlane, dpx, 0.);
1828 fSeg[1]->MorePads(); fSeg[1]->NextPad())
1830 ix=fSeg[1]->Ix(); iy=fSeg[1]->Iy();
1831 // if (fHitMap[1]->TestHit(ix, iy) == kEmpty) continue;
1832 fSeg[1]->GetPadC(ix,iy,upper[0],ydum,zdum);
1833 if (icount ==0) lower[0]=upper[0];
1836 if (lower[0]>upper[0]) {xdum=lower[0]; lower[0]=upper[0]; upper[0]=xdum;}
1837 // vstart[0] = 0.5*(lower[0]+upper[0]);
1842 for (fSeg[0]->FirstPad(fXInit[0], fYInit[0], fZPlane, 0., dpy);
1843 fSeg[0]->MorePads(); fSeg[0]->NextPad())
1845 ix=fSeg[0]->Ix(); iy=fSeg[0]->Iy();
1846 // if (fHitMap[0]->TestHit(ix, iy) == kEmpty) continue;
1847 fSeg[0]->GetPadC(ix,iy,xdum,upper[1],zdum);
1848 if (icount ==0) lower[1]=upper[1];
1852 if (lower[1]>upper[1]) {xdum=lower[1]; lower[1]=upper[1]; upper[1]=xdum;}
1853 // vstart[1] = 0.5*(lower[1]+upper[1]);
1856 fSeg[1]->GetPadI(fXInit[1], fYInit[1], fZPlane, ix, iy);
1857 isec=fSeg[1]->Sector(ix, iy);
1858 dpx=fSeg[1]->Dpx(isec);
1859 fSeg[0]->GetPadI(fXInit[1], fYInit[1], fZPlane, ix, iy);
1860 isec=fSeg[0]->Sector(ix, iy);
1861 dpy=fSeg[0]->Dpy(isec);
1864 // Find save upper and lower limits
1868 for (fSeg[1]->FirstPad(fXInit[1], fYInit[1], fZPlane, dpx, 0);
1869 fSeg[1]->MorePads(); fSeg[1]->NextPad())
1871 ix=fSeg[1]->Ix(); iy=fSeg[1]->Iy();
1872 // if (fHitMap[1]->TestHit(ix, iy) == kEmpty) continue;
1873 fSeg[1]->GetPadC(ix,iy,upper[2],ydum,zdum);
1874 if (icount ==0) lower[2]=upper[2];
1877 if (lower[2]>upper[2]) {xdum=lower[2]; lower[2]=upper[2]; upper[2]=xdum;}
1878 // vstart[2] = 0.5*(lower[2]+upper[2]);
1882 for (fSeg[0]->FirstPad(fXInit[1], fYInit[1], fZPlane, 0, dpy);
1883 fSeg[0]-> MorePads(); fSeg[0]->NextPad())
1885 ix=fSeg[0]->Ix(); iy=fSeg[0]->Iy();
1886 // if (fHitMap[0]->TestHit(ix, iy) != kEmpty) continue;
1888 fSeg[0]->GetPadC(ix,iy,xdum,upper[3],zdum);
1889 if (icount ==0) lower[3]=upper[3];
1893 if (lower[3]>upper[3]) {xdum=lower[3]; lower[3]=upper[3]; upper[3]=xdum;}
1895 // vstart[3] = 0.5*(lower[3]+upper[3]);
1903 static Double_t step[6]={0.0005, 0.0005, 0.0005, 0.0005, 0.001, 0.001};
1904 clusterInput.Fitter()->mnparm(0,"x1",vstart[0],step[0],lower[0],upper[0],ierflag);
1905 clusterInput.Fitter()->mnparm(1,"y1",vstart[1],step[1],lower[1],upper[1],ierflag);
1906 clusterInput.Fitter()->mnparm(2,"x2",vstart[2],step[2],lower[2],upper[2],ierflag);
1907 clusterInput.Fitter()->mnparm(3,"y2",vstart[3],step[3],lower[3],upper[3],ierflag);
1908 clusterInput.Fitter()->mnparm(4,"a0",vstart[4],step[4],lower[4],upper[4],ierflag);
1909 clusterInput.Fitter()->mnparm(5,"a1",vstart[5],step[5],lower[5],upper[5],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 // Get fitted parameters
1919 Double_t epxz, b1, b2;
1921 clusterInput.Fitter()->mnpout(0, chname, fXFit[0], epxz, b1, b2, ierflg);
1922 clusterInput.Fitter()->mnpout(1, chname, fYFit[0], epxz, b1, b2, ierflg);
1923 clusterInput.Fitter()->mnpout(2, chname, fXFit[1], epxz, b1, b2, ierflg);
1924 clusterInput.Fitter()->mnpout(3, chname, fYFit[1], epxz, b1, b2, ierflg);
1925 clusterInput.Fitter()->mnpout(4, chname, fQrFit[0], epxz, b1, b2, ierflg);
1926 clusterInput.Fitter()->mnpout(5, chname, fQrFit[1], epxz, b1, b2, ierflg);
1928 Double_t fmin, fedm, errdef;
1929 Int_t npari, nparx, istat;
1931 clusterInput.Fitter()->mnstat(fmin, fedm, errdef, npari, nparx, istat);
1939 void AliMUONClusterFinderVS::Split(AliMUONRawCluster* c)
1942 // One cluster for each maximum
1945 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
1946 for (j=0; j<2; j++) {
1947 AliMUONRawCluster cnew;
1948 cnew.fGhost=c->fGhost;
1949 for (cath=0; cath<2; cath++) {
1950 cnew.fChi2[cath]=fChi2[0];
1951 // ?? why not cnew.fChi2[cath]=fChi2[cath];
1954 cnew.fNcluster[0]=-1;
1955 cnew.fNcluster[1]=fNRawClusters;
1957 cnew.fNcluster[0]=fNPeaks;
1958 cnew.fNcluster[1]=0;
1960 cnew.fMultiplicity[cath]=0;
1961 cnew.fX[cath]=Float_t(fXFit[j]);
1962 cnew.fY[cath]=Float_t(fYFit[j]);
1963 cnew.fZ[cath]=fZPlane;
1965 cnew.fQ[cath]=Int_t(clusterInput.TotalCharge(cath)*fQrFit[cath]);
1967 cnew.fQ[cath]=Int_t(clusterInput.TotalCharge(cath)*(1-fQrFit[cath]));
1969 fSeg[cath]->SetHit(fXFit[j],fYFit[j],fZPlane);
1970 for (i=0; i<fMul[cath]; i++) {
1971 cnew.fIndexMap[cnew.fMultiplicity[cath]][cath]=
1972 c->fIndexMap[i][cath];
1973 fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
1974 Float_t q1=fInput->Response()->IntXY(fSeg[cath]);
1975 cnew.fContMap[i][cath]
1976 =(q1*Float_t(cnew.fQ[cath]))/Float_t(fQ[i][cath]);
1977 cnew.fMultiplicity[cath]++;
1979 FillCluster(&cnew,0,cath);
1982 cnew.fClusterType=cnew.PhysicsContribution();
1983 if (cnew.fQ[0]>0 && cnew.fQ[1]>0) AddRawCluster(cnew);
1990 // Minimisation functions
1992 void fcnS1(Int_t & /*npar*/, Double_t * /*gin*/, Double_t &f, Double_t *par, Int_t /*iflag*/)
1994 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
2001 for (i=0; i<clusterInput.Nmul(0); i++) {
2002 Float_t q0=clusterInput.Charge(i,0);
2003 Float_t q1=clusterInput.DiscrChargeS1(i,par);
2012 void fcnCombiS1(Int_t & /*npar*/, Double_t * /*gin*/, Double_t &f, Double_t *par, Int_t /*iflag*/)
2014 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
2021 for (cath=0; cath<2; cath++) {
2022 for (i=0; i<clusterInput.Nmul(cath); i++) {
2023 Float_t q0=clusterInput.Charge(i,cath);
2024 Float_t q1=clusterInput.DiscrChargeCombiS1(i,par,cath);
2035 void fcnS2(Int_t & /*npar*/, Double_t * /*gin*/, Double_t &f, Double_t *par, Int_t /*iflag*/)
2037 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
2044 for (i=0; i<clusterInput.Nmul(0); i++) {
2046 Float_t q0=clusterInput.Charge(i,0);
2047 Float_t q1=clusterInput.DiscrChargeS2(i,par);
2057 void fcnCombiS2(Int_t & /*npar*/, Double_t * /*gin*/, Double_t &f, Double_t *par, Int_t /*iflag*/)
2059 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
2065 for (cath=0; cath<2; cath++) {
2066 for (i=0; i<clusterInput.Nmul(cath); i++) {
2067 Float_t q0=clusterInput.Charge(i,cath);
2068 Float_t q1=clusterInput.DiscrChargeCombiS2(i,par,cath);
2078 void AliMUONClusterFinderVS::AddRawCluster(const AliMUONRawCluster& c)
2081 // Add a raw cluster copy to the list
2084 // AliMUON *pMUON=(AliMUON*)gAlice->GetModule("MUON");
2085 // pMUON->GetMUONData()->AddRawCluster(fInput->Chamber(),c);
2089 TClonesArray &lrawcl = *fRawClusters;
2090 new(lrawcl[fNRawClusters++]) AliMUONRawCluster(c);
2092 fprintf(stderr,"\nfNRawClusters %d\n",fNRawClusters);
2095 Bool_t AliMUONClusterFinderVS::TestTrack(Int_t t) {
2096 // Test if track was user selected
2097 if (fTrack[0]==-1 || fTrack[1]==-1) {
2099 } else if (t==fTrack[0] || t==fTrack[1]) {
2106 AliMUONClusterFinderVS& AliMUONClusterFinderVS
2107 ::operator = (const AliMUONClusterFinderVS& /*rhs*/)
2109 // Dummy assignment operator