1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
21 #include <Riostream.h>
23 #include "AliMUONClusterFinderVS.h"
24 #include "AliMUONDigit.h"
25 #include "AliMUONRawCluster.h"
26 #include "AliSegmentation.h"
27 #include "AliMUONGeometrySegmentation.h"
28 #include "AliMUONMathieson.h"
29 #include "AliMUONClusterInput.h"
30 #include "AliMUONHitMapA1.h"
33 //_____________________________________________________________________
34 // This function is minimized in the double-Mathieson fit
35 void fcnS2(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag);
36 void fcnS1(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag);
37 void fcnCombiS1(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag);
38 void fcnCombiS2(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag);
40 ClassImp(AliMUONClusterFinderVS)
42 AliMUONClusterFinderVS::AliMUONClusterFinderVS()
45 // Default constructor
46 fInput=AliMUONClusterInput::Instance();
47 // cout << " TYPE" << fSegmentationType << endl;
50 fTrack[0]=fTrack[1]=-1;
51 fDebugLevel = 0; // make silent default
52 fGhostChi2Cut = 1e6; // nothing done by default
58 for(Int_t i=0; i<100; i++) {
59 for (Int_t j=0; j<2; j++) {
63 fRawClusters = new TClonesArray("AliMUONRawCluster",1000);
66 //____________________________________________________________________________
67 AliMUONClusterFinderVS::~AliMUONClusterFinderVS()
69 // Reset tracks information
72 fRawClusters->Delete();
77 AliMUONClusterFinderVS::AliMUONClusterFinderVS(const AliMUONClusterFinderVS & clusterFinder):TObject(clusterFinder)
79 // Protected copy constructor
81 AliFatal("Not implemented.");
83 //____________________________________________________________________________
84 void AliMUONClusterFinderVS::ResetRawClusters()
86 // Reset tracks information
88 if (fRawClusters) fRawClusters->Clear();
90 //____________________________________________________________________________
91 void AliMUONClusterFinderVS::Decluster(AliMUONRawCluster *cluster)
93 // Decluster by local maxima
94 SplitByLocalMaxima(cluster);
96 //____________________________________________________________________________
97 void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
99 // Split complex cluster by local maxima
102 fInput->SetCluster(c);
104 fMul[0]=c->GetMultiplicity(0);
105 fMul[1]=c->GetMultiplicity(1);
108 // dump digit information into arrays
113 for (cath=0; cath<2; cath++) {
116 for (i=0; i<fMul[cath]; i++) {
118 fDig[i][cath]=fInput->Digit(cath, c->GetIndex(i, cath));
120 fIx[i][cath]= fDig[i][cath]->PadX();
121 fIy[i][cath]= fDig[i][cath]->PadY();
123 fQ[i][cath] = fDig[i][cath]->Signal();
124 // pad centre coordinates
125 if (fSegmentationType == 1)
127 GetPadC(fIx[i][cath], fIy[i][cath], fX[i][cath], fY[i][cath], fZ[i][cath]);
130 GetPadC(fInput->DetElemId(), fIx[i][cath], fIy[i][cath], fX[i][cath], fY[i][cath], fZ[i][cath]);
131 } // loop over cluster digits
133 } // loop over cathodes
139 // Initialise and perform mathieson fits
140 Float_t chi2, oldchi2;
141 // ++++++++++++++++++*************+++++++++++++++++++++
142 // (1) No more than one local maximum per cathode plane
143 // +++++++++++++++++++++++++++++++*************++++++++
144 if ((fNLocal[0]==1 && (fNLocal[1]==0 || fNLocal[1]==1)) ||
145 (fNLocal[0]==0 && fNLocal[1]==1)) {
146 // Perform combined single Mathieson fit
147 // Initial values for coordinates (x,y)
149 // One local maximum on cathodes 1 and 2 (X->cathode 2, Y->cathode 1)
150 if (fNLocal[0]==1 && fNLocal[1]==1) {
151 fXInit[0]=c->GetX(1);
152 fYInit[0]=c->GetY(0);
153 // One local maximum on cathode 1 (X,Y->cathode 1)
154 } else if (fNLocal[0]==1) {
155 fXInit[0]=c->GetX(0);
156 fYInit[0]=c->GetY(0);
157 // One local maximum on cathode 2 (X,Y->cathode 2)
159 fXInit[0]=c->GetX(1);
160 fYInit[0]=c->GetY(1);
162 AliDebug(1,"cas (1) CombiSingleMathiesonFit(c)");
163 chi2=CombiSingleMathiesonFit(c);
164 // Int_t ndf = fgNbins[0]+fgNbins[1]-2;
165 // Float_t prob = TMath::Prob(Double_t(chi2),ndf);
166 // prob1->Fill(prob);
167 // chi2_1->Fill(chi2);
169 AliDebug(1,Form(" chi2 %f ",chi2));
171 c->SetX(0, fXFit[0]);
172 c->SetY(0, fYFit[0]);
179 if (fSegmentationType == 1) {
180 c->SetX(0, fSeg[0]->GetAnod(c->GetX(0)));
181 c->SetX(1, fSeg[1]->GetAnod(c->GetX(1)));
183 c->SetX(0, fSeg2[0]->GetAnod(fInput->DetElemId(), c->GetX(0)));
184 c->SetX(1, fSeg2[1]->GetAnod(fInput->DetElemId(), c->GetX(1)));
186 // c->SetDetElementID(fInput->DetElemId());
187 // If reasonable chi^2 add result to the list of rawclusters
190 // If not try combined double Mathieson Fit
192 AliDebug(1," MAUVAIS CHI2 !!!\n");
193 if (fNLocal[0]==1 && fNLocal[1]==1) {
194 fXInit[0]=fX[fIndLocal[0][1]][1];
195 fYInit[0]=fY[fIndLocal[0][0]][0];
196 fXInit[1]=fX[fIndLocal[0][1]][1];
197 fYInit[1]=fY[fIndLocal[0][0]][0];
198 } else if (fNLocal[0]==1) {
199 fXInit[0]=fX[fIndLocal[0][0]][0];
200 fYInit[0]=fY[fIndLocal[0][0]][0];
201 fXInit[1]=fX[fIndLocal[0][0]][0];
202 fYInit[1]=fY[fIndLocal[0][0]][0];
204 fXInit[0]=fX[fIndLocal[0][1]][1];
205 fYInit[0]=fY[fIndLocal[0][1]][1];
206 fXInit[1]=fX[fIndLocal[0][1]][1];
207 fYInit[1]=fY[fIndLocal[0][1]][1];
210 // Initial value for charge ratios
213 AliDebug(1,"\n cas (1) CombiDoubleMathiesonFit(c)\n");
214 chi2=CombiDoubleMathiesonFit(c);
215 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
216 // Float_t prob = TMath::Prob(chi2,ndf);
217 // prob2->Fill(prob);
218 // chi2_2->Fill(chi2);
220 // Was this any better ??
221 AliDebug(1,Form(" Old and new chi2 %f %f ", oldchi2, chi2));
222 if (fFitStat!=0 && chi2>0 && (2.*chi2 < oldchi2)) {
224 // Split cluster into two according to fit result
227 AliDebug(1,"Do not Split");
233 // +++++++++++++++++++++++++++++++++++++++
234 // (2) Two local maxima per cathode plane
235 // +++++++++++++++++++++++++++++++++++++++
236 } else if (fNLocal[0]==2 && fNLocal[1]==2) {
238 // Let's look for ghosts first
240 Float_t xm[4][2], ym[4][2];
241 Float_t dpx, dpy, dx, dy;
242 Int_t ixm[4][2], iym[4][2];
243 Int_t isec, im1, im2, ico;
245 // Form the 2x2 combinations
246 // 0-0, 0-1, 1-0, 1-1
248 for (im1=0; im1<2; im1++) {
249 for (im2=0; im2<2; im2++) {
250 xm[ico][0]=fX[fIndLocal[im1][0]][0];
251 ym[ico][0]=fY[fIndLocal[im1][0]][0];
252 xm[ico][1]=fX[fIndLocal[im2][1]][1];
253 ym[ico][1]=fY[fIndLocal[im2][1]][1];
255 ixm[ico][0]=fIx[fIndLocal[im1][0]][0];
256 iym[ico][0]=fIy[fIndLocal[im1][0]][0];
257 ixm[ico][1]=fIx[fIndLocal[im2][1]][1];
258 iym[ico][1]=fIy[fIndLocal[im2][1]][1];
262 // ico = 0 : first local maximum on cathodes 1 and 2
263 // ico = 1 : fisrt local maximum on cathode 1 and second on cathode 2
264 // ico = 2 : second local maximum on cathode 1 and first on cathode 1
265 // ico = 3 : second local maximum on cathodes 1 and 2
267 // Analyse the combinations and keep those that are possible !
268 // For each combination check consistency in x and y
271 Float_t dr[4] = {1.e4, 1.e4, 1.e4, 1.e4};
274 // In case of staggering maxima are displaced by exactly half the pad-size in y.
275 // We have to take into account the numerical precision in the consistency check;
278 for (ico=0; ico<4; ico++) {
279 accepted[ico]=kFALSE;
280 // cathode one: x-coordinate
281 if (fSegmentationType == 1) {
282 isec=fSeg[0]->Sector(ixm[ico][0], iym[ico][0]);
283 dpx=fSeg[0]->Dpx(isec)/2.;
285 isec=fSeg2[0]->Sector(fInput->DetElemId(), ixm[ico][0], iym[ico][0]);
286 dpx=fSeg2[0]->Dpx(fInput->DetElemId(), isec)/2.;
288 dx=TMath::Abs(xm[ico][0]-xm[ico][1]);
289 // cathode two: y-coordinate
290 if (fSegmentationType == 1) {
291 isec=fSeg[1]->Sector(ixm[ico][1], iym[ico][1]);
292 dpy=fSeg[1]->Dpy(isec)/2.;
294 isec=fSeg2[1]->Sector(fInput->DetElemId(), ixm[ico][1], iym[ico][1]);
295 dpy=fSeg2[1]->Dpy(fInput->DetElemId(), isec)/2.;
297 dy=TMath::Abs(ym[ico][0]-ym[ico][1]);
298 AliDebug(2,Form("\n %i %f %f %f %f %f %f \n", ico, ym[ico][0], ym[ico][1], dy, dpy, dx, dpx ));
299 if ((dx <= dpx) && (dy <= dpy+eps)) {
302 dr[ico] = TMath::Sqrt(dx*dx+dy*dy);
306 accepted[ico]=kFALSE;
309 AliDebug(1,Form("\n iacc= %d:\n", iacc));
311 if (accepted[0] && accepted[1]) {
312 if (dr[0] >= dr[1]) {
319 if (accepted[2] && accepted[3]) {
320 if (dr[2] >= dr[3]) {
327 // eliminate one candidate
331 for (ico=0; ico<4; ico++) {
332 if (accepted[ico] && dr[ico] > drmax) {
338 accepted[icobad] = kFALSE;
344 AliDebug(1,Form("\n iacc= %d:\n", iacc));
346 AliDebug(1,"\n iacc=2: No problem ! \n");
347 } else if (iacc==4) {
348 AliDebug(1,"\n iacc=4: Ok, but ghost problem !!! \n");
349 } else if (iacc==0) {
350 AliDebug(1,"\n iacc=0: I don't know what to do with this !!!!!!!!! \n");
353 // Initial value for charge ratios
354 fQrInit[0]=Float_t(fQ[fIndLocal[0][0]][0])/
355 Float_t(fQ[fIndLocal[0][0]][0]+fQ[fIndLocal[1][0]][0]);
356 fQrInit[1]=Float_t(fQ[fIndLocal[0][1]][1])/
357 Float_t(fQ[fIndLocal[0][1]][1]+fQ[fIndLocal[1][1]][1]);
359 // ******* iacc = 0 *******
360 // No combinations found between the 2 cathodes
361 // We keep the center of gravity of the cluster
366 // ******* iacc = 1 *******
367 // Only one combination found between the 2 cathodes
369 // Initial values for the 2 maxima (x,y)
371 // 1 maximum is initialised with the maximum of the combination found (X->cathode 2, Y->cathode 1)
372 // 1 maximum is initialised with the other maximum of the first cathode
379 } else if (accepted[1]){
385 } else if (accepted[2]){
391 } else if (accepted[3]){
398 AliDebug(1,"cas (2) CombiDoubleMathiesonFit(c)");
399 chi2=CombiDoubleMathiesonFit(c);
400 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
401 // Float_t prob = TMath::Prob(chi2,ndf);
402 // prob2->Fill(prob);
403 // chi2_2->Fill(chi2);
404 AliDebug(1,Form(" chi2 %f\n",chi2));
406 // If reasonable chi^2 add result to the list of rawclusters
411 // 1 maximum is initialised with the maximum of the combination found (X->cathode 2, Y->cathode 1)
412 // 1 maximum is initialised with the other maximum of the second cathode
419 } else if (accepted[1]){
425 } else if (accepted[2]){
431 } else if (accepted[3]){
438 AliDebug(1,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
439 chi2=CombiDoubleMathiesonFit(c);
440 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
441 // Float_t prob = TMath::Prob(chi2,ndf);
442 // prob2->Fill(prob);
443 // chi2_2->Fill(chi2);
444 AliDebug(1,Form(" chi2 %f\n",chi2));
446 // If reasonable chi^2 add result to the list of rawclusters
450 //We keep only the combination found (X->cathode 2, Y->cathode 1)
451 for (Int_t ico=0; ico<2; ico++) {
453 AliMUONRawCluster cnew;
455 for (cath=0; cath<2; cath++) {
456 cnew.SetX(cath, Float_t(xm[ico][1]));
457 cnew.SetY(cath, Float_t(ym[ico][0]));
458 cnew.SetZ(cath, fZPlane);
459 cnew.SetMultiplicity(cath,c->GetMultiplicity(cath));
460 for (i=0; i<fMul[cath]; i++) {
461 cnew.SetIndex(i, cath, c->GetIndex(i,cath));
462 if (fSegmentationType == 1)
463 fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
465 fSeg2[cath]->SetPad(fInput->DetElemId(), fIx[i][cath], fIy[i][cath]);
467 AliDebug(1,Form("\nRawCluster %d cath %d\n",ico,cath));
468 AliDebug(1,Form("mult_av %d\n",c->GetMultiplicity(cath)));
469 FillCluster(&cnew,cath);
471 cnew.SetClusterType(cnew.PhysicsContribution());
480 // ******* iacc = 2 *******
481 // Two combinations found between the 2 cathodes
483 // Was the same maximum taken twice
484 if ((accepted[0]&&accepted[1]) || (accepted[2]&&accepted[3])) {
485 AliDebug(1,"\n Maximum taken twice !!!\n");
487 // Have a try !! with that
488 if (accepted[0]&&accepted[3]) {
499 AliDebug(1,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
500 chi2=CombiDoubleMathiesonFit(c);
501 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
502 // Float_t prob = TMath::Prob(chi2,ndf);
503 // prob2->Fill(prob);
504 // chi2_2->Fill(chi2);
508 // No ghosts ! No Problems ! - Perform one fit only !
509 if (accepted[0]&&accepted[3]) {
520 AliDebug(1,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
521 chi2=CombiDoubleMathiesonFit(c);
522 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
523 // Float_t prob = TMath::Prob(chi2,ndf);
524 // prob2->Fill(prob);
525 // chi2_2->Fill(chi2);
526 AliDebug(1,Form(" chi2 %f\n",chi2));
530 // ******* iacc = 4 *******
531 // Four combinations found between the 2 cathodes
533 } else if (iacc==4) {
534 // Perform fits for the two possibilities !!
535 // Accept if charges are compatible on both cathodes
536 // If none are compatible, keep everything
541 AliDebug(1,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
542 chi2=CombiDoubleMathiesonFit(c);
543 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
544 // Float_t prob = TMath::Prob(chi2,ndf);
545 // prob2->Fill(prob);
546 // chi2_2->Fill(chi2);
547 AliDebug(1,Form(" chi2 %f\n",chi2));
548 // store results of fit and postpone decision
549 Double_t sXFit[2],sYFit[2],sQrFit[2];
551 for (Int_t i=0;i<2;i++) {
561 AliDebug(1,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
562 chi2=CombiDoubleMathiesonFit(c);
563 // ndf = fgNbins[0]+fgNbins[1]-6;
564 // prob = TMath::Prob(chi2,ndf);
565 // prob2->Fill(prob);
566 // chi2_2->Fill(chi2);
567 AliDebug(1,Form(" 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->ChargeCorrel() );
576 chi2fi = (TMath::Log(fInput->TotalCharge(0)*(1-fQrFit[0])
577 / (fInput->TotalCharge(1)*(1-fQrFit[1])) )
578 / fInput->ChargeCorrel() );
579 chi2f += chi2fi*chi2fi;
581 chi2s = (TMath::Log(fInput->TotalCharge(0)*sQrFit[0]
582 / (fInput->TotalCharge(1)*sQrFit[1]) )
583 / fInput->ChargeCorrel() );
585 chi2si = (TMath::Log(fInput->TotalCharge(0)*(1-sQrFit[0])
586 / (fInput->TotalCharge(1)*(1-sQrFit[1])) )
587 / fInput->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 if (fSegmentationType == 1) {
658 isec=fSeg[0]->Sector(ixm[ico][0], iym[ico][0]);
659 dpx=fSeg[0]->Dpx(isec)/2.;
661 isec=fSeg2[0]->Sector(fInput->DetElemId(), ixm[ico][0], iym[ico][0]);
662 dpx=fSeg2[0]->Dpx(fInput->DetElemId(), isec)/2.;
664 dx=TMath::Abs(xm[ico][0]-xm[ico][1]);
665 if (fSegmentationType == 1) {
666 isec=fSeg[1]->Sector(ixm[ico][1], iym[ico][1]);
667 dpy=fSeg[1]->Dpy(isec)/2.;
669 isec=fSeg2[1]->Sector(fInput->DetElemId(), ixm[ico][1], iym[ico][1]);
670 dpy=fSeg2[1]->Dpy(fInput->DetElemId(), isec)/2.;
672 dy=TMath::Abs(ym[ico][0]-ym[ico][1]);
673 AliDebug(2,Form("\n %i %f %f %f %f \n", ico, ym[ico][0], ym[ico][1], dy, dpy ));
674 if ((dx <= dpx) && (dy <= dpy+eps)) {
680 accepted[ico]=kFALSE;
688 // Initial value for charge ratios
689 fQrInit[0]=Float_t(fQ[fIndLocal[0][0]][0])/
690 Float_t(fQ[fIndLocal[0][0]][0]+fQ[fIndLocal[1][0]][0]);
691 fQrInit[1]=fQrInit[0];
693 if (accepted[0] && accepted[1]) {
695 fXInit[0]=0.5*(xm[0][1]+xm[0][0]);
697 fXInit[1]=0.5*(xm[0][1]+xm[1][0]);
701 chi23=CombiDoubleMathiesonFit(c);
710 } else if (accepted[0]) {
715 chi21=CombiDoubleMathiesonFit(c);
716 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
717 // Float_t prob = TMath::Prob(chi2,ndf);
718 // prob2->Fill(prob);
719 // chi2_2->Fill(chi21);
720 AliDebug(1,Form(" chi2 %f\n",chi21));
721 if (chi21<10) Split(c);
722 } else if (accepted[1]) {
727 chi22=CombiDoubleMathiesonFit(c);
728 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
729 // Float_t prob = TMath::Prob(chi2,ndf);
730 // prob2->Fill(prob);
731 // chi2_2->Fill(chi22);
732 AliDebug(1,Form(" chi2 %f\n",chi22));
733 if (chi22<10) Split(c);
736 if (chi21 > 10 && chi22 > 10 && chi23 > 10) {
737 // We keep only the combination found (X->cathode 2, Y->cathode 1)
738 for (Int_t ico=0; ico<2; ico++) {
740 AliMUONRawCluster cnew;
742 for (cath=0; cath<2; cath++) {
743 cnew.SetX(cath, Float_t(xm[ico][1]));
744 cnew.SetY(cath, Float_t(ym[ico][0]));
745 cnew.SetZ(cath, fZPlane);
746 cnew.SetMultiplicity(cath, c->GetMultiplicity(cath));
747 for (i=0; i<fMul[cath]; i++) {
748 cnew.SetIndex(i, cath, c->GetIndex(i, cath));
749 if (fSegmentationType == 1)
750 fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
752 fSeg2[cath]->SetPad(fInput->DetElemId(), fIx[i][cath], fIy[i][cath]);
755 AliDebug(1,Form("\nRawCluster %d cath %d\n",ico,cath));
756 AliDebug(1,Form("mult_av %d\n",c->GetMultiplicity(cath)));
758 FillCluster(&cnew,cath);
760 cnew.SetClusterType(cnew.PhysicsContribution());
767 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
768 // (3') One local maximum on cathode 1 and two maxima on cathode 2
769 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
770 } else if (fNLocal[0]==1 && fNLocal[1]==2) {
771 Float_t xm[4][2], ym[4][2];
772 Float_t dpx, dpy, dx, dy;
773 Int_t ixm[4][2], iym[4][2];
774 Int_t isec, im1, ico;
776 // Form the 2x2 combinations
777 // 0-0, 0-1, 1-0, 1-1
779 for (im1=0; im1<2; im1++) {
780 xm[ico][0]=fX[fIndLocal[0][0]][0];
781 ym[ico][0]=fY[fIndLocal[0][0]][0];
782 xm[ico][1]=fX[fIndLocal[im1][1]][1];
783 ym[ico][1]=fY[fIndLocal[im1][1]][1];
785 ixm[ico][0]=fIx[fIndLocal[0][0]][0];
786 iym[ico][0]=fIy[fIndLocal[0][0]][0];
787 ixm[ico][1]=fIx[fIndLocal[im1][1]][1];
788 iym[ico][1]=fIy[fIndLocal[im1][1]][1];
791 // ico = 0 : first local maximum on cathodes 1 and 2
792 // ico = 1 : first local maximum on cathode 1 and second on cathode 2
794 // Analyse the combinations and keep those that are possible !
795 // For each combination check consistency in x and y
799 // In case of staggering maxima are displaced by exactly half the pad-size in y.
800 // We have to take into account the numerical precision in the consistency check;
804 for (ico=0; ico<2; ico++) {
805 accepted[ico]=kFALSE;
806 if (fSegmentationType == 1) {
807 isec=fSeg[0]->Sector(ixm[ico][0], iym[ico][0]);
808 dpx=fSeg[0]->Dpx(isec)/2.;
810 isec=fSeg2[0]->Sector(fInput->DetElemId(), ixm[ico][0], iym[ico][0]);
811 dpx=fSeg2[0]->Dpx(fInput->DetElemId(), isec)/2.;
813 dx=TMath::Abs(xm[ico][0]-xm[ico][1]);
814 if (fSegmentationType == 1) {
815 isec=fSeg[1]->Sector(ixm[ico][1], iym[ico][1]);
816 dpy=fSeg[1]->Dpy(isec)/2.;
818 isec=fSeg2[1]->Sector(fInput->DetElemId(), ixm[ico][1], iym[ico][1]);
819 dpy=fSeg2[1]->Dpy(fInput->DetElemId(), isec)/2.;
821 dy=TMath::Abs(ym[ico][0]-ym[ico][1]);
822 AliDebug(1,Form("\n %i %f %f %f %f \n", ico, ym[ico][0], ym[ico][1], dy, dpy ));
823 if ((dx <= dpx) && (dy <= dpy+eps)) {
826 AliDebug(1,Form("ico %d\n",ico));
830 accepted[ico]=kFALSE;
838 fQrInit[1]=Float_t(fQ[fIndLocal[0][1]][1])/
839 Float_t(fQ[fIndLocal[0][1]][1]+fQ[fIndLocal[1][1]][1]);
841 fQrInit[0]=fQrInit[1];
844 if (accepted[0] && accepted[1]) {
846 fYInit[0]=0.5*(ym[0][0]+ym[0][1]);
848 fYInit[1]=0.5*(ym[0][0]+ym[1][1]);
851 chi23=CombiDoubleMathiesonFit(c);
860 } else if (accepted[0]) {
865 chi21=CombiDoubleMathiesonFit(c);
866 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
867 // Float_t prob = TMath::Prob(chi2,ndf);
868 // prob2->Fill(prob);
869 // chi2_2->Fill(chi21);
870 AliDebug(1,Form(" chi2 %f\n",chi21));
871 if (chi21<10) Split(c);
872 } else if (accepted[1]) {
877 chi22=CombiDoubleMathiesonFit(c);
878 // Int_t ndf = fgNbins[0]+fgNbins[1]-6;
879 // Float_t prob = TMath::Prob(chi2,ndf);
880 // prob2->Fill(prob);
881 // chi2_2->Fill(chi22);
882 AliDebug(1,Form(" chi2 %f\n",chi22));
883 if (chi22<10) Split(c);
886 if (chi21 > 10 && chi22 > 10 && chi23 > 10) {
887 //We keep only the combination found (X->cathode 2, Y->cathode 1)
888 for (Int_t ico=0; ico<2; ico++) {
890 AliMUONRawCluster cnew;
892 for (cath=0; cath<2; cath++) {
893 cnew.SetX(cath, Float_t(xm[ico][1]));
894 cnew.SetY(cath, Float_t(ym[ico][0]));
895 cnew.SetZ(cath, fZPlane);
896 cnew.SetMultiplicity(cath, c->GetMultiplicity(cath));
897 for (i=0; i<fMul[cath]; i++) {
898 cnew.SetIndex(i, cath, c->GetIndex(i, cath));
899 if (fSegmentationType == 1)
900 fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
902 fSeg2[cath]->SetPad(fInput->DetElemId(), fIx[i][cath], fIy[i][cath]);
904 AliDebug(1,Form("\nRawCluster %d cath %d\n",ico,cath));
905 AliDebug(1,Form("mult_av %d\n",c->GetMultiplicity(cath)));
906 FillCluster(&cnew,cath);
908 cnew.SetClusterType(cnew.PhysicsContribution());
915 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
916 // (4) At least three local maxima on cathode 1 or on cathode 2
917 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
918 } else if (fNLocal[0]>2 || fNLocal[1]>2) {
919 Int_t param = fNLocal[0]*fNLocal[1];
922 Float_t ** xm = new Float_t * [param];
923 for (ii=0; ii<param; ii++) xm[ii]=new Float_t [2];
924 Float_t ** ym = new Float_t * [param];
925 for (ii=0; ii<param; ii++) ym[ii]=new Float_t [2];
926 Int_t ** ixm = new Int_t * [param];
927 for (ii=0; ii<param; ii++) ixm[ii]=new Int_t [2];
928 Int_t ** iym = new Int_t * [param];
929 for (ii=0; ii<param; ii++) iym[ii]=new Int_t [2];
932 Float_t dpx, dpy, dx, dy;
935 for (Int_t im1=0; im1<fNLocal[0]; im1++) {
936 for (Int_t im2=0; im2<fNLocal[1]; im2++) {
937 xm[ico][0]=fX[fIndLocal[im1][0]][0];
938 ym[ico][0]=fY[fIndLocal[im1][0]][0];
939 xm[ico][1]=fX[fIndLocal[im2][1]][1];
940 ym[ico][1]=fY[fIndLocal[im2][1]][1];
942 ixm[ico][0]=fIx[fIndLocal[im1][0]][0];
943 iym[ico][0]=fIy[fIndLocal[im1][0]][0];
944 ixm[ico][1]=fIx[fIndLocal[im2][1]][1];
945 iym[ico][1]=fIy[fIndLocal[im2][1]][1];
951 AliDebug(1,Form("nIco %d\n",nIco));
952 for (ico=0; ico<nIco; ico++) {
953 AliDebug(1,Form("ico = %d\n",ico));
954 if (fSegmentationType == 1) {
955 isec=fSeg[0]->Sector(ixm[ico][0], iym[ico][0]);
956 dpx=fSeg[0]->Dpx(isec)/2.;
958 isec=fSeg2[0]->Sector(fInput->DetElemId(), ixm[ico][0], iym[ico][0]);
959 dpx=fSeg2[0]->Dpx(fInput->DetElemId(), isec)/2.;
961 dx=TMath::Abs(xm[ico][0]-xm[ico][1]);
962 if (fSegmentationType == 1) {
963 isec=fSeg[1]->Sector(ixm[ico][1], iym[ico][1]);
964 dpy=fSeg[1]->Dpy(isec)/2.;
966 isec=fSeg2[1]->Sector(fInput->DetElemId(), ixm[ico][1], iym[ico][1]);
967 dpy=fSeg2[1]->Dpy(fInput->DetElemId(), isec)/2.;
969 dy=TMath::Abs(ym[ico][0]-ym[ico][1]);
970 AliDebug(1,Form("dx %f dpx %f dy %f dpy %f\n",dx,dpx,dy,dpy));
971 AliDebug(1,Form(" X %f Y %f\n",xm[ico][1],ym[ico][0]));
972 if ((dx <= dpx) && (dy <= dpy)) {
975 AliMUONRawCluster cnew;
976 for (cath=0; cath<2; cath++) {
977 cnew.SetX(cath, Float_t(xm[ico][1]));
978 cnew.SetY(cath, Float_t(ym[ico][0]));
979 cnew.SetZ(cath, fZPlane);
980 cnew.SetMultiplicity(cath, c->GetMultiplicity(cath));
981 for (i=0; i<fMul[cath]; i++) {
982 cnew.SetIndex(i, cath, c->GetIndex(i, cath));
983 if (fSegmentationType == 1)
984 fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
986 fSeg2[cath]->SetPad(fInput->DetElemId(), fIx[i][cath], fIy[i][cath]);
988 FillCluster(&cnew,cath);
990 cnew.SetClusterType(cnew.PhysicsContribution());
991 // cnew.SetDetElementID(fInput->DetElemId());
1003 void AliMUONClusterFinderVS::FindLocalMaxima(AliMUONRawCluster* /*c*/)
1005 // Find all local maxima of a cluster
1006 AliDebug(1,"\n Find Local maxima !");
1010 Int_t cath, cath1; // loops over cathodes
1011 Int_t i; // loops over digits
1012 Int_t j; // loops over cathodes
1014 // Find local maxima
1016 // counters for number of local maxima
1017 fNLocal[0]=fNLocal[1]=0;
1018 // flags digits as local maximum
1019 Bool_t isLocal[100][2];
1020 for (i=0; i<100;i++) {
1021 isLocal[i][0]=isLocal[i][1]=kFALSE;
1023 // number of next neighbours and arrays to store them
1026 // loop over cathodes
1027 for (cath=0; cath<2; cath++) {
1028 // loop over cluster digits
1029 for (i=0; i<fMul[cath]; i++) {
1030 // get neighbours for that digit and assume that it is local maximum
1034 if (fSegmentationType == 1)
1035 fSeg[cath]->Neighbours(fIx[i][cath], fIy[i][cath], &nn, x, y);
1037 fSeg2[cath]->Neighbours(fInput->DetElemId(), fIx[i][cath], fIy[i][cath], &nn, x, y);
1039 isLocal[i][cath]=kTRUE;
1041 if (fSegmentationType == 1) {
1042 isec = fSeg[cath]->Sector(fIx[i][cath], fIy[i][cath]);
1043 a0 = fSeg[cath]->Dpx(isec)*fSeg[cath]->Dpy(isec);
1045 isec = fSeg2[cath]->Sector(fInput->DetElemId(), fIx[i][cath], fIy[i][cath]);
1046 a0 = fSeg2[cath]->Dpx(fInput->DetElemId(), isec)*fSeg2[cath]->Dpy(fInput->DetElemId(), isec);
1048 // loop over next neighbours, if at least one neighbour has higher charger assumption
1049 // digit is not local maximum
1050 for (j=0; j<nn; j++) {
1051 if (fHitMap[cath]->TestHit(x[j], y[j])==kEmpty) continue;
1052 digt=(AliMUONDigit*) fHitMap[cath]->GetHit(x[j], y[j]);
1054 if (fSegmentationType == 1) {
1055 isec=fSeg[cath]->Sector(x[j], y[j]);
1056 a1 = fSeg[cath]->Dpx(isec)*fSeg[cath]->Dpy(isec);
1058 isec=fSeg2[cath]->Sector(fInput->DetElemId(), x[j], y[j]);
1059 a1 = fSeg2[cath]->Dpx(fInput->DetElemId(),isec)*fSeg2[cath]->Dpy(fInput->DetElemId(), isec);
1061 if (digt->Signal()/a1 > fQ[i][cath]/a0) {
1062 isLocal[i][cath]=kFALSE;
1065 // handle special case of neighbouring pads with equal signal
1066 } else if (digt->Signal() == fQ[i][cath]) {
1067 if (fNLocal[cath]>0) {
1068 for (Int_t k=0; k<fNLocal[cath]; k++) {
1069 if (x[j]==fIx[fIndLocal[k][cath]][cath]
1070 && y[j]==fIy[fIndLocal[k][cath]][cath])
1072 isLocal[i][cath]=kFALSE;
1074 } // loop over local maxima
1075 } // are there already local maxima
1077 } // loop over next neighbours
1078 if (isLocal[i][cath]) {
1079 fIndLocal[fNLocal[cath]][cath]=i;
1082 } // loop over all digits
1083 } // loop over cathodes
1085 AliDebug(1,Form("\n Found %d %d %d %d local Maxima\n",
1086 fNLocal[0], fNLocal[1], fMul[0], fMul[1]));
1087 AliDebug(1,Form("\n Cathode 1 local Maxima %d Multiplicite %d\n",fNLocal[0], fMul[0]));
1088 AliDebug(1,Form(" Cathode 2 local Maxima %d Multiplicite %d\n",fNLocal[1], fMul[1]));
1093 if (fNLocal[1]==2 && (fNLocal[0]==1 || fNLocal[0]==0)) {
1094 Int_t iback=fNLocal[0];
1096 // Two local maxima on cathode 2 and one maximum on cathode 1
1097 // Look for local maxima considering up and down neighbours on the 1st cathode only
1099 // Loop over cluster digits
1103 for (i=0; i<fMul[cath]; i++) {
1104 if (fSegmentationType == 1) {
1105 isec=fSeg[cath]->Sector(fIx[i][cath],fIy[i][cath]);
1106 dpy=fSeg[cath]->Dpy(isec);
1107 dpx=fSeg[cath]->Dpx(isec);
1109 isec=fSeg2[cath]->Sector(fInput->DetElemId(), fIx[i][cath],fIy[i][cath]);
1110 dpy=fSeg2[cath]->Dpy(fInput->DetElemId(), isec);
1111 dpx=fSeg2[cath]->Dpx(fInput->DetElemId(), isec);
1113 if (isLocal[i][cath]) continue;
1114 // Pad position should be consistent with position of local maxima on the opposite cathode
1115 if ((TMath::Abs(fX[i][cath]-fX[fIndLocal[0][cath1]][cath1]) > dpx/2.) &&
1116 (TMath::Abs(fX[i][cath]-fX[fIndLocal[1][cath1]][cath1]) > dpx/2.))
1119 // get neighbours for that digit and assume that it is local maximum
1120 isLocal[i][cath]=kTRUE;
1121 // compare signal to that on the two neighbours on the left and on the right
1122 // iNN counts the number of neighbours with signal, it should be 1 or 2
1124 if (fSegmentationType == 1) {
1126 for (fSeg[cath]->FirstPad(fX[i][cath], fY[i][cath], fZPlane, 0., dpy);
1127 fSeg[cath]->MorePads();
1128 fSeg[cath]->NextPad())
1130 ix = fSeg[cath]->Ix();
1131 iy = fSeg[cath]->Iy();
1132 // skip the current pad
1133 if (iy == fIy[i][cath]) continue;
1135 if (fHitMap[cath]->TestHit(ix, iy)!=kEmpty) {
1137 digt=(AliMUONDigit*) fHitMap[cath]->GetHit(ix,iy);
1138 if (digt->Signal() > fQ[i][cath]) isLocal[i][cath]=kFALSE;
1140 } // Loop over pad neighbours in y
1143 for (fSeg2[cath]->FirstPad(fInput->DetElemId(), fX[i][cath], fY[i][cath], fZPlane, 0., dpy);
1144 fSeg2[cath]->MorePads(fInput->DetElemId());
1145 fSeg2[cath]->NextPad(fInput->DetElemId()))
1147 ix = fSeg2[cath]->Ix();
1148 iy = fSeg2[cath]->Iy();
1149 // skip the current pad
1150 if (iy == fIy[i][cath]) continue;
1152 if (fHitMap[cath]->TestHit(ix, iy)!=kEmpty) {
1154 digt=(AliMUONDigit*) fHitMap[cath]->GetHit(ix,iy);
1155 if (digt->Signal() > fQ[i][cath]) isLocal[i][cath]=kFALSE;
1157 } // Loop over pad neighbours in y
1159 if (isLocal[i][cath] && iNN>0) {
1160 fIndLocal[fNLocal[cath]][cath]=i;
1163 } // loop over all digits
1164 // if one additional maximum has been found we are happy
1165 // if more maxima have been found restore the previous situation
1166 AliDebug(1,Form("\n New search gives %d local maxima for cathode 1 \n",
1168 AliDebug(1,Form(" %d local maxima for cathode 2 \n",
1170 if (fNLocal[cath]>2) {
1171 fNLocal[cath]=iback;
1174 } // 1,2 local maxima
1176 if (fNLocal[0]==2 && (fNLocal[1]==1 || fNLocal[1]==0)) {
1177 Int_t iback=fNLocal[1];
1179 // Two local maxima on cathode 1 and one maximum on cathode 2
1180 // Look for local maxima considering left and right neighbours on the 2nd cathode only
1183 Float_t eps = 1.e-5;
1186 // Loop over cluster digits
1187 for (i=0; i<fMul[cath]; i++) {
1188 if (fSegmentationType == 1) {
1189 isec=fSeg[cath]->Sector(fIx[i][cath],fIy[i][cath]);
1190 dpx=fSeg[cath]->Dpx(isec);
1191 dpy=fSeg[cath]->Dpy(isec);
1193 isec=fSeg2[cath]->Sector(fInput->DetElemId(), fIx[i][cath],fIy[i][cath]);
1194 dpx=fSeg2[cath]->Dpx(fInput->DetElemId(), isec);
1195 dpy=fSeg2[cath]->Dpy(fInput->DetElemId(), isec);
1198 if (isLocal[i][cath]) continue;
1199 // Pad position should be consistent with position of local maxima on the opposite cathode
1200 if ((TMath::Abs(fY[i][cath]-fY[fIndLocal[0][cath1]][cath1]) > dpy/2.+eps) &&
1201 (TMath::Abs(fY[i][cath]-fY[fIndLocal[1][cath1]][cath1]) > dpy/2.+eps))
1205 // get neighbours for that digit and assume that it is local maximum
1206 isLocal[i][cath]=kTRUE;
1207 // compare signal to that on the two neighbours on the left and on the right
1209 // iNN counts the number of neighbours with signal, it should be 1 or 2
1211 if (fSegmentationType == 1) {
1212 for (fSeg[cath]->FirstPad(fX[i][cath], fY[i][cath], fZPlane, dpx, 0.);
1213 fSeg[cath]->MorePads();
1214 fSeg[cath]->NextPad())
1217 ix = fSeg[cath]->Ix();
1218 iy = fSeg[cath]->Iy();
1220 // skip the current pad
1221 if (ix == fIx[i][cath]) continue;
1223 if (fHitMap[cath]->TestHit(ix, iy)!=kEmpty) {
1225 digt=(AliMUONDigit*) fHitMap[cath]->GetHit(ix,iy);
1226 if (digt->Signal() > fQ[i][cath]) isLocal[i][cath]=kFALSE;
1228 } // Loop over pad neighbours in x
1230 for (fSeg2[cath]->FirstPad(fInput->DetElemId(), fX[i][cath], fY[i][cath], fZPlane, dpx, 0.);
1231 fSeg2[cath]->MorePads(fInput->DetElemId());
1232 fSeg2[cath]->NextPad(fInput->DetElemId()))
1235 ix = fSeg2[cath]->Ix();
1236 iy = fSeg2[cath]->Iy();
1238 // skip the current pad
1239 if (ix == fIx[i][cath]) continue;
1241 if (fHitMap[cath]->TestHit(ix, iy)!=kEmpty) {
1243 digt=(AliMUONDigit*) fHitMap[cath]->GetHit(ix,iy);
1244 if (digt->Signal() > fQ[i][cath]) isLocal[i][cath]=kFALSE;
1246 } // Loop over pad neighbours in x
1248 if (isLocal[i][cath] && iNN>0) {
1249 fIndLocal[fNLocal[cath]][cath]=i;
1252 } // loop over all digits
1253 // if one additional maximum has been found we are happy
1254 // if more maxima have been found restore the previous situation
1255 AliDebug(1,Form("\n New search gives %d local maxima for cathode 1 \n",fNLocal[0]));
1256 AliDebug(1,Form("\n %d local maxima for cathode 2 \n",fNLocal[1]));
1257 AliDebug(1,Form("\n New search gives %d %d \n",fNLocal[0],fNLocal[1]));
1258 if (fNLocal[cath]>2) {
1259 fNLocal[cath]=iback;
1261 } // 2,1 local maxima
1265 void AliMUONClusterFinderVS::FillCluster(AliMUONRawCluster* c, Int_t flag, Int_t cath)
1268 // Completes cluster information starting from list of digits
1275 c->SetPeakSignal(cath,c->GetPeakSignal(0));
1277 c->SetPeakSignal(cath,0);
1284 c->SetCharge(cath,0);
1287 AliDebug(1,Form("\n fPeakSignal %d\n",c->GetPeakSignal(cath)));
1288 for (Int_t i=0; i<c->GetMultiplicity(cath); i++)
1290 dig= fInput->Digit(cath,c->GetIndex(i,cath));
1291 ix=dig->PadX()+c->GetOffset(i,cath);
1293 Int_t q=dig->Signal();
1294 if (!flag) q=Int_t(q*c->GetContrib(i,cath));
1295 // fprintf(stderr,"q %d c->fPeakSignal[ %d ] %d\n",q,cath,c->fPeakSignal[cath]);
1296 if (dig->Physics() >= dig->Signal()) {
1298 } else if (dig->Physics() == 0) {
1300 } else c->SetPhysics(i,1);
1303 AliDebug(2,Form("q %d c->fPeakSignal[cath] %d\n",q,c->GetPeakSignal(cath)));
1304 // peak signal and track list
1305 if (q>c->GetPeakSignal(cath)) {
1306 c->SetPeakSignal(cath, q);
1307 c->SetTrack(0,dig->Hit());
1308 c->SetTrack(1,dig->Track(0));
1309 c->SetTrack(2,dig->Track(1));
1310 // fprintf(stderr," c->fTracks[0] %d c->fTracks[1] %d\n",dig->fHit,dig->fTracks[0]);
1314 if (fSegmentationType == 1)
1315 fSeg[cath]->GetPadC(ix, iy, x, y, z);
1317 fSeg2[cath]->GetPadC(fInput->DetElemId(), ix, iy, x, y, z);
1321 c->AddCharge(cath, q);
1323 } // loop over digits
1324 AliDebug(1," fin du cluster c\n");
1328 c->SetX(cath, c->GetX(cath)/c->GetCharge(cath));
1330 if (fSegmentationType == 1)
1331 c->SetX(cath, fSeg[cath]->GetAnod(c->GetX(cath)));
1333 c->SetX(cath, fSeg2[cath]->GetAnod(fInput->DetElemId(), c->GetX(cath)));
1334 c->SetY(cath, c->GetY(cath)/c->GetCharge(cath));
1336 // apply correction to the coordinate along the anode wire
1342 if (fSegmentationType == 1) {
1343 fSeg[cath]->GetPadI(x, y, fZPlane, ix, iy);
1344 fSeg[cath]->GetPadC(ix, iy, x, y, z);
1345 isec=fSeg[cath]->Sector(ix,iy);
1346 cogCorr = fSeg[cath]->CorrFunc(isec-1);
1348 fSeg2[cath]->GetPadI(fInput->DetElemId(), x, y, fZPlane, ix, iy);
1349 fSeg2[cath]->GetPadC(fInput->DetElemId(), ix, iy, x, y, z);
1350 isec=fSeg2[cath]->Sector(fInput->DetElemId(), ix,iy);
1351 cogCorr = fSeg2[cath]->CorrFunc(fInput->DetElemId(), isec-1);
1356 if (fSegmentationType == 1)
1357 yOnPad=(c->GetY(cath)-y)/fSeg[cath]->Dpy(isec);
1359 yOnPad=(c->GetY(cath)-y)/fSeg2[cath]->Dpy(fInput->DetElemId(), isec);
1361 c->SetY(cath, c->GetY(cath)-cogCorr->Eval(yOnPad, 0, 0));
1362 // slat ID from digit
1368 void AliMUONClusterFinderVS::FillCluster(AliMUONRawCluster* c, Int_t cath)
1371 // Completes cluster information starting from list of digits
1381 Float_t xpad, ypad, zpad;
1384 for (Int_t i=0; i<c->GetMultiplicity(cath); i++)
1386 dig = fInput->Digit(cath,c->GetIndex(i,cath));
1387 if (fSegmentationType == 1)
1389 GetPadC(dig->PadX(),dig->PadY(),xpad,ypad, zpad);
1392 GetPadC(fInput->DetElemId(),dig->PadX(),dig->PadY(),xpad,ypad, zpad);
1393 AliDebug(1,Form("x %f y %f cx %f cy %f\n",xpad,ypad,c->GetX(0),c->GetY(0)));
1394 dx = xpad - c->GetX(0);
1395 dy = ypad - c->GetY(0);
1396 dr = TMath::Sqrt(dx*dx+dy*dy);
1400 AliDebug(1,Form(" dr %f\n",dr));
1401 Int_t q=dig->Signal();
1402 if (dig->Physics() >= dig->Signal()) {
1404 } else if (dig->Physics() == 0) {
1406 } else c->SetPhysics(i,1);
1407 c->SetPeakSignal(cath,q);
1408 c->SetTrack(0,dig->Hit());
1409 c->SetTrack(1,dig->Track(0));
1410 c->SetTrack(2,dig->Track(1));
1412 AliDebug(1,Form(" c->fTracks[0] %d c->fTracks[1] %d\n",dig->Hit(),
1416 } // loop over digits
1418 // apply correction to the coordinate along the anode wire
1420 if (fSegmentationType == 1)
1421 c->SetX(cath,fSeg[cath]->GetAnod(c->GetX(cath)));
1423 c->SetX(cath,fSeg2[cath]->GetAnod(fInput->DetElemId(), c->GetX(cath)));
1426 void AliMUONClusterFinderVS::FindCluster(Int_t i, Int_t j, Int_t cath, AliMUONRawCluster &c){
1430 // Find a super cluster on both cathodes
1433 // Add i,j as element of the cluster
1436 Int_t idx = fHitMap[cath]->GetHitIndex(i,j);
1437 AliMUONDigit* dig = (AliMUONDigit*) fHitMap[cath]->GetHit(i,j);
1438 Int_t q=dig->Signal();
1439 Int_t theX=dig->PadX();
1440 Int_t theY=dig->PadY();
1442 if (q > TMath::Abs(c.GetPeakSignal(0)) && q > TMath::Abs(c.GetPeakSignal(1))) {
1443 c.SetPeakSignal(cath,q);
1444 c.SetTrack(0,dig->Hit());
1445 c.SetTrack(1,dig->Track(0));
1446 c.SetTrack(2,dig->Track(1));
1450 // Make sure that list of digits is ordered
1452 Int_t mu=c.GetMultiplicity(cath);
1453 c.SetIndex(mu, cath, idx);
1455 if (dig->Physics() >= dig->Signal()) {
1457 } else if (dig->Physics() == 0) {
1459 } else c.SetPhysics(mu,1);
1463 for (Int_t ind = mu-1; ind >= 0; ind--) {
1464 Int_t ist=c.GetIndex(ind,cath);
1465 Int_t ql=fInput->Digit(cath, ist)->Signal();
1466 Int_t ix=fInput->Digit(cath, ist)->PadX();
1467 Int_t iy=fInput->Digit(cath, ist)->PadY();
1469 if (q>ql || (q==ql && theX > ix && theY < iy)) {
1470 c.SetIndex(ind, cath, idx);
1471 c.SetIndex(ind+1, cath, ist);
1479 c.SetMultiplicity(cath, c.GetMultiplicity(cath)+1);
1480 if (c.GetMultiplicity(cath) >= 50 ) {
1481 AliDebug(1,Form("FindCluster - multiplicity >50 %d \n",c.GetMultiplicity(0)));
1482 c.SetMultiplicity(cath, 49);
1485 // Prepare center of gravity calculation
1487 if (fSegmentationType == 1)
1488 fSeg[cath]->GetPadC(i, j, x, y, z);
1490 fSeg2[cath]->GetPadC(fInput->DetElemId(), i, j, x, y, z);
1493 c.AddCharge(cath,q);
1495 // Flag hit as "taken"
1496 fHitMap[cath]->FlagHit(i,j);
1498 // Now look recursively for all neighbours and pad hit on opposite cathode
1500 // Loop over neighbours
1504 Int_t xList[10], yList[10];
1505 if (fSegmentationType == 1)
1506 fSeg[cath]->Neighbours(i,j,&nn,xList,yList);
1508 fSeg2[cath]->Neighbours(fInput->DetElemId(), i,j,&nn,xList,yList);
1509 for (Int_t in=0; in<nn; in++) {
1513 if (fHitMap[cath]->TestHit(ix,iy)==kUnused) {
1514 AliDebug(2,Form("\n Neighbours %d %d %d", cath, ix, iy));
1515 FindCluster(ix, iy, cath, c);
1520 Int_t iXopp[50], iYopp[50];
1522 // Neighbours on opposite cathode
1523 // Take into account that several pads can overlap with the present pad
1525 if (fSegmentationType == 1)
1526 isec=fSeg[cath]->Sector(i,j);
1528 isec=fSeg2[cath]->Sector(fInput->DetElemId(), i,j);
1533 if (fSegmentationType == 1) {
1536 dx = (fSeg[cath]->Dpx(isec))/2.;
1541 dy = (fSeg[cath]->Dpy(isec))/2;
1546 // loop over pad neighbours on opposite cathode
1547 for (fSeg[iop]->FirstPad(x, y, fZPlane, dx, dy);
1548 fSeg[iop]->MorePads();
1549 fSeg[iop]->NextPad())
1552 ix = fSeg[iop]->Ix(); iy = fSeg[iop]->Iy();
1553 AliDebug(2,Form("\n ix, iy: %f %f %f %d %d %d", x,y,z,ix, iy, fSector));
1554 if (fHitMap[iop]->TestHit(ix,iy)==kUnused){
1557 AliDebug(2,Form("\n Opposite %d %d %d", iop, ix, iy));
1560 } // Loop over pad neighbours
1561 // This had to go outside the loop since recursive calls inside the iterator are not possible
1564 for (jopp=0; jopp<nOpp; jopp++) {
1565 if (fHitMap[iop]->TestHit(iXopp[jopp],iYopp[jopp]) == kUnused)
1566 FindCluster(iXopp[jopp], iYopp[jopp], iop, c);
1572 dx = (fSeg2[cath]->Dpx(fInput->DetElemId(), isec))/2.;
1577 dy = (fSeg2[cath]->Dpy(fInput->DetElemId(), isec))/2;
1582 // loop over pad neighbours on opposite cathode
1583 for (fSeg2[iop]->FirstPad(fInput->DetElemId(), x, y, fZPlane, dx, dy);
1584 fSeg2[iop]->MorePads(fInput->DetElemId());
1585 fSeg2[iop]->NextPad(fInput->DetElemId()))
1588 ix = fSeg2[iop]->Ix(); iy = fSeg2[iop]->Iy();
1589 AliDebug(2,Form("\n ix, iy: %f %f %f %d %d %d", x,y,z,ix, iy, fSector));
1590 if (fHitMap[iop]->TestHit(ix,iy)==kUnused){
1593 AliDebug(2,Form("\n Opposite %d %d %d", iop, ix, iy));
1596 } // Loop over pad neighbours
1597 // This had to go outside the loop since recursive calls inside the iterator are not possible
1600 for (jopp=0; jopp<nOpp; jopp++) {
1601 if (fHitMap[iop]->TestHit(iXopp[jopp],iYopp[jopp]) == kUnused)
1602 FindCluster(iXopp[jopp], iYopp[jopp], iop, c);
1607 //_____________________________________________________________________________
1609 void AliMUONClusterFinderVS::FindRawClusters()
1612 // MUON cluster finder from digits -- finds neighbours on both cathodes and
1613 // fills the tree with raw clusters
1617 // Return if no input datad available
1618 if (!fInput->NDigits(0) && !fInput->NDigits(1)) return;
1620 fSegmentationType = fInput->GetSegmentationType();
1622 if (fSegmentationType == 1) {
1623 fSeg[0] = fInput->Segmentation(0);
1624 fSeg[1] = fInput->Segmentation(1);
1626 fHitMap[0] = new AliMUONHitMapA1(fSeg[0], fInput->Digits(0));
1627 fHitMap[1] = new AliMUONHitMapA1(fSeg[1], fInput->Digits(1));
1630 fSeg2[0] = fInput->Segmentation2(0);
1631 fSeg2[1] = fInput->Segmentation2(1);
1633 fHitMap[0] = new AliMUONHitMapA1(fInput->DetElemId(), fSeg2[0], fInput->Digits(0));
1634 fHitMap[1] = new AliMUONHitMapA1(fInput->DetElemId(), fSeg2[1], fInput->Digits(1));
1642 fHitMap[0]->FillHits();
1643 fHitMap[1]->FillHits();
1645 // Outer Loop over Cathodes
1646 for (cath=0; cath<2; cath++) {
1648 for (ndig=0; ndig<fInput->NDigits(cath); ndig++) {
1649 dig = fInput->Digit(cath, ndig);
1650 Int_t padx = dig->PadX();
1651 Int_t pady = dig->PadY();
1652 if (fHitMap[cath]->TestHit(padx,pady)==kUsed ||fHitMap[0]->TestHit(padx,pady)==kEmpty) {
1656 AliDebug(1,Form("\n CATHODE %d CLUSTER %d\n",cath,ncls));
1657 AliMUONRawCluster clus;
1658 clus.SetMultiplicity(0, 0);
1659 clus.SetMultiplicity(1, 0);
1660 clus.SetPeakSignal(cath,dig->Signal());
1661 clus.SetTrack(0, dig->Hit());
1662 clus.SetTrack(1, dig->Track(0));
1663 clus.SetTrack(2, dig->Track(1));
1665 AliDebug(1,Form("idDE %d Padx %d Pady %d", fInput->DetElemId(), padx, pady));
1667 // tag the beginning of cluster list in a raw cluster
1668 clus.SetNcluster(0,-1);
1670 if (fSegmentationType == 1) {
1671 fSeg[cath]->GetPadC(padx,pady, xcu, ycu, fZPlane);
1672 fSector= fSeg[cath]->Sector(padx,pady)/100;
1674 fSeg2[cath]->GetPadC(fInput->DetElemId(), padx, pady, xcu, ycu, fZPlane);
1675 fSector= fSeg2[cath]->Sector(fInput->DetElemId(), padx, pady)/100;
1680 FindCluster(padx,pady,cath,clus);
1681 //^^^^^^^^^^^^^^^^^^^^^^^^
1682 // center of gravity
1683 if (clus.GetX(0)!=0.) clus.SetX(0, clus.GetX(0)/clus.GetCharge(0)); // clus.fX[0] /= clus.fQ[0];
1686 if (fSegmentationType == 1)
1687 clus.SetX(0,fSeg[0]->GetAnod(clus.GetX(0)));
1689 clus.SetX(0,fSeg2[0]->GetAnod(fInput->DetElemId(), clus.GetX(0)));
1690 if (clus.GetY(0)!=0.) clus.SetY(0, clus.GetY(0)/clus.GetCharge(0)); // clus.fY[0] /= clus.fQ[0];
1692 if(clus.GetCharge(1)!=0.) clus.SetX(1, clus.GetX(1)/clus.GetCharge(1)); // clus.fX[1] /= clus.fQ[1];
1695 if (fSegmentationType == 1)
1696 clus.SetX(1, fSeg[0]->GetAnod(clus.GetX(1)));
1698 clus.SetX(1, fSeg2[0]->GetAnod(fInput->DetElemId(),clus.GetX(1)));
1699 if(clus.GetCharge(1)!=0.) clus.SetY(1, clus.GetY(1)/clus.GetCharge(1));// clus.fY[1] /= clus.fQ[1];
1701 clus.SetZ(0, fZPlane);
1702 clus.SetZ(1, fZPlane);
1704 AliDebug(1,Form("\n Cathode 1 multiplicite %d X(CG) %f Y(CG) %f\n",
1705 clus.GetMultiplicity(0),clus.GetX(0),clus.GetY(0)));
1706 AliDebug(1,Form(" Cathode 2 multiplicite %d X(CG) %f Y(CG) %f\n",
1707 clus.GetMultiplicity(1),clus.GetX(1),clus.GetY(1)));
1708 // Analyse cluster and decluster if necessary
1711 clus.SetNcluster(1,fNRawClusters);
1712 clus.SetClusterType(clus.PhysicsContribution());
1719 // reset Cluster object
1720 { // begin local scope
1721 for (int k=0;k<clus.GetMultiplicity(0);k++) clus.SetIndex(k, 0, 0);
1722 } // end local scope
1724 { // begin local scope
1725 for (int k=0;k<clus.GetMultiplicity(1);k++) clus.SetIndex(k, 1, 0);
1726 } // end local scope
1728 clus.SetMultiplicity(0,0);
1729 clus.SetMultiplicity(1,0);
1733 } // end loop cathodes
1738 Float_t AliMUONClusterFinderVS::SingleMathiesonFit(AliMUONRawCluster *c, Int_t cath)
1740 // Performs a single Mathieson fit on one cathode
1742 Double_t arglist[20];
1744 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
1746 clusterInput.Fitter()->SetFCN(fcnS1);
1747 clusterInput.Fitter()->mninit(2,10,7);
1748 clusterInput.Fitter()->SetPrintLevel(-1+fDebugLevel);
1750 clusterInput.Fitter()->mnexcm("SET NOW", arglist, 0, ierflag);
1751 // Set starting values
1752 static Double_t vstart[2];
1753 vstart[0]=c->GetX(1);
1754 vstart[1]=c->GetY(0);
1757 // lower and upper limits
1758 static Double_t lower[2], upper[2];
1760 if (fSegmentationType == 1) {
1761 fSeg[cath]->GetPadI(c->GetX(cath), c->GetY(cath), fZPlane, ix, iy);
1762 isec=fSeg[cath]->Sector(ix, iy);
1764 lower[0]=vstart[0]-fSeg[cath]->Dpx(isec)/2;
1765 lower[1]=vstart[1]-fSeg[cath]->Dpy(isec)/2;
1767 upper[0]=lower[0]+fSeg[cath]->Dpx(isec);
1768 upper[1]=lower[1]+fSeg[cath]->Dpy(isec);
1771 fSeg2[cath]->GetPadI(fInput->DetElemId(), c->GetX(cath), c->GetY(cath), fZPlane, ix, iy);
1772 isec=fSeg2[cath]->Sector(fInput->DetElemId(), ix, iy);
1774 lower[0]=vstart[0]-fSeg2[cath]->Dpx(fInput->DetElemId(), isec)/2;
1775 lower[1]=vstart[1]-fSeg2[cath]->Dpy(fInput->DetElemId(), isec)/2;
1777 upper[0]=lower[0]+fSeg2[cath]->Dpx(fInput->DetElemId(), isec);
1778 upper[1]=lower[1]+fSeg2[cath]->Dpy(fInput->DetElemId(), isec);
1782 static Double_t step[2]={0.0005, 0.0005};
1784 clusterInput.Fitter()->mnparm(0,"x1",vstart[0],step[0],lower[0],upper[0],ierflag);
1785 clusterInput.Fitter()->mnparm(1,"y1",vstart[1],step[1],lower[1],upper[1],ierflag);
1786 // ready for minimisation
1790 clusterInput.Fitter()->mnexcm("SET NOGR", arglist, 0, ierflag);
1791 clusterInput.Fitter()->mnexcm("MIGRAD", arglist, 0, ierflag);
1792 // clusterInput.Fitter()->mnexcm("EXIT" , arglist, 0, ierflag);
1793 Double_t fmin, fedm, errdef;
1794 Int_t npari, nparx, istat;
1796 clusterInput.Fitter()->mnstat(fmin, fedm, errdef, npari, nparx, istat);
1800 // Get fitted parameters
1801 Double_t xrec, yrec;
1803 Double_t epxz, b1, b2;
1805 clusterInput.Fitter()->mnpout(0, chname, xrec, epxz, b1, b2, ierflg);
1806 clusterInput.Fitter()->mnpout(1, chname, yrec, epxz, b1, b2, ierflg);
1812 Float_t AliMUONClusterFinderVS::CombiSingleMathiesonFit(AliMUONRawCluster * /*c*/)
1814 // Perform combined Mathieson fit on both cathode planes
1816 Double_t arglist[20];
1818 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
1819 clusterInput.Fitter()->SetFCN(fcnCombiS1);
1820 clusterInput.Fitter()->mninit(2,10,7);
1821 clusterInput.Fitter()->SetPrintLevel(-1+fDebugLevel);
1823 clusterInput.Fitter()->mnexcm("SET NOW", arglist, 0, ierflag);
1824 static Double_t vstart[2];
1825 vstart[0]=fXInit[0];
1826 vstart[1]=fYInit[0];
1829 // lower and upper limits
1830 static Float_t lower[2], upper[2];
1834 if (fSegmentationType == 1) {
1835 fSeg[0]->GetPadI(fXInit[0], fYInit[0], fZPlane, ix, iy);
1836 isec=fSeg[0]->Sector(ix, iy);
1837 dpy=fSeg[0]->Dpy(isec);
1838 fSeg[1]->GetPadI(fXInit[0], fYInit[0], fZPlane, ix, iy);
1839 isec=fSeg[1]->Sector(ix, iy);
1840 dpx=fSeg[1]->Dpx(isec);
1843 fSeg2[0]->GetPadI(fInput->DetElemId(), fXInit[0], fYInit[0], fZPlane, ix, iy);
1844 isec=fSeg2[0]->Sector(fInput->DetElemId(), ix, iy);
1845 dpy=fSeg2[0]->Dpy(fInput->DetElemId(), isec);
1846 fSeg2[1]->GetPadI(fInput->DetElemId(), fXInit[0], fYInit[0], fZPlane, ix, iy);
1847 isec=fSeg2[1]->Sector(fInput->DetElemId(), ix, iy);
1848 dpx=fSeg2[1]->Dpx(fInput->DetElemId(), isec);
1852 Float_t xdum, ydum, zdum;
1854 // Find save upper and lower limits
1857 if (fSegmentationType == 1) {
1858 for (fSeg[1]->FirstPad(fXInit[0], fYInit[0], fZPlane, dpx, 0.);
1859 fSeg[1]->MorePads();
1862 ix=fSeg[1]->Ix(); iy=fSeg[1]->Iy();
1863 fSeg[1]->GetPadC(ix,iy, upper[0], ydum, zdum);
1864 if (icount ==0) lower[0]=upper[0];
1868 for (fSeg2[1]->FirstPad(fInput->DetElemId(),fXInit[0], fYInit[0], fZPlane, dpx, 0.);
1869 fSeg2[1]->MorePads(fInput->DetElemId());
1870 fSeg2[1]->NextPad(fInput->DetElemId()))
1872 ix=fSeg2[1]->Ix(); iy=fSeg2[1]->Iy();
1873 fSeg2[1]->GetPadC(fInput->DetElemId(), ix,iy, upper[0], ydum, zdum);
1874 if (icount ==0) lower[0]=upper[0];
1878 if (lower[0]>upper[0]) {xdum=lower[0]; lower[0]=upper[0]; upper[0]=xdum;}
1881 AliDebug(1,Form("\n single y %f %f", fXInit[0], fYInit[0]));
1883 if (fSegmentationType == 1) {
1884 for (fSeg[0]->FirstPad(fXInit[0], fYInit[0], fZPlane, 0., dpy);
1885 fSeg[0]->MorePads();
1888 ix=fSeg[0]->Ix(); iy=fSeg[0]->Iy();
1889 fSeg[0]->GetPadC(ix,iy,xdum,upper[1],zdum);
1890 if (icount ==0) lower[1]=upper[1];
1892 AliDebug(1,Form("\n upper lower %d %f %f", icount, upper[1], lower[1]));
1895 for (fSeg2[0]->FirstPad(fInput->DetElemId(), fXInit[0], fYInit[0], fZPlane, 0., dpy);
1896 fSeg2[0]->MorePads(fInput->DetElemId());
1897 fSeg2[0]->NextPad(fInput->DetElemId()))
1899 ix=fSeg2[0]->Ix(); iy=fSeg2[0]->Iy();
1900 fSeg2[0]->GetPadC(fInput->DetElemId(), ix,iy,xdum,upper[1],zdum);
1901 if (icount ==0) lower[1]=upper[1];
1903 AliDebug(1,Form("\n upper lower %d %f %f", icount, upper[1], lower[1]));
1906 if (lower[1]>upper[1]) {xdum=lower[1]; lower[1]=upper[1]; upper[1]=xdum;}
1909 static Double_t step[2]={0.00001, 0.0001};
1911 clusterInput.Fitter()->mnparm(0,"x1",vstart[0],step[0],lower[0],upper[0],ierflag);
1912 clusterInput.Fitter()->mnparm(1,"y1",vstart[1],step[1],lower[1],upper[1],ierflag);
1913 // ready for minimisation
1917 clusterInput.Fitter()->mnexcm("SET NOGR", arglist, 0, ierflag);
1918 clusterInput.Fitter()->mnexcm("MIGRAD", arglist, 0, ierflag);
1919 // clusterInput.Fitter()->mnexcm("EXIT" , arglist, 0, ierflag);
1920 Double_t fmin, fedm, errdef;
1921 Int_t npari, nparx, istat;
1923 clusterInput.Fitter()->mnstat(fmin, fedm, errdef, npari, nparx, istat);
1927 // Get fitted parameters
1928 Double_t xrec, yrec;
1930 Double_t epxz, b1, b2;
1932 clusterInput.Fitter()->mnpout(0, chname, xrec, epxz, b1, b2, ierflg);
1933 clusterInput.Fitter()->mnpout(1, chname, yrec, epxz, b1, b2, ierflg);
1939 Bool_t AliMUONClusterFinderVS::DoubleMathiesonFit(AliMUONRawCluster * /*c*/, Int_t cath)
1941 // Performs a double Mathieson fit on one cathode
1945 // Initialise global variables for fit
1946 Double_t arglist[20];
1948 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
1949 clusterInput.Fitter()->SetFCN(fcnS2);
1950 clusterInput.Fitter()->mninit(5,10,7);
1951 clusterInput.Fitter()->SetPrintLevel(-1+fDebugLevel);
1953 clusterInput.Fitter()->mnexcm("SET NOW", arglist, 0, ierflag);
1954 // Set starting values
1955 static Double_t vstart[5];
1956 vstart[0]=fX[fIndLocal[0][cath]][cath];
1957 vstart[1]=fY[fIndLocal[0][cath]][cath];
1958 vstart[2]=fX[fIndLocal[1][cath]][cath];
1959 vstart[3]=fY[fIndLocal[1][cath]][cath];
1960 vstart[4]=Float_t(fQ[fIndLocal[0][cath]][cath])/
1961 Float_t(fQ[fIndLocal[0][cath]][cath]+fQ[fIndLocal[1][cath]][cath]);
1962 // lower and upper limits
1963 static Float_t lower[5], upper[5];
1966 if (fSegmentationType == 1) {
1967 isec=fSeg[cath]->Sector(fIx[fIndLocal[0][cath]][cath], fIy[fIndLocal[0][cath]][cath]);
1968 lower[0]=vstart[0]-fSeg[cath]->Dpx(isec);
1969 lower[1]=vstart[1]-fSeg[cath]->Dpy(isec);
1971 upper[0]=lower[0]+2.*fSeg[cath]->Dpx(isec);
1972 upper[1]=lower[1]+2.*fSeg[cath]->Dpy(isec);
1974 isec=fSeg[cath]->Sector(fIx[fIndLocal[1][cath]][cath], fIy[fIndLocal[1][cath]][cath]);
1975 lower[2]=vstart[2]-fSeg[cath]->Dpx(isec)/2;
1976 lower[3]=vstart[3]-fSeg[cath]->Dpy(isec)/2;
1978 upper[2]=lower[2]+fSeg[cath]->Dpx(isec);
1979 upper[3]=lower[3]+fSeg[cath]->Dpy(isec);
1982 isec=fSeg2[cath]->Sector(fInput->DetElemId(),fIx[fIndLocal[0][cath]][cath],
1983 fIy[fIndLocal[0][cath]][cath]);
1984 lower[0]=vstart[0]-fSeg2[cath]->Dpx(fInput->DetElemId(),isec);
1985 lower[1]=vstart[1]-fSeg2[cath]->Dpy(fInput->DetElemId(),isec);
1987 upper[0]=lower[0]+2.*fSeg2[cath]->Dpx(fInput->DetElemId(),isec);
1988 upper[1]=lower[1]+2.*fSeg2[cath]->Dpy(fInput->DetElemId(),isec);
1990 isec=fSeg2[cath]->Sector(fInput->DetElemId(),fIx[fIndLocal[1][cath]][cath],
1991 fIy[fIndLocal[1][cath]][cath]);
1992 lower[2]=vstart[2]-fSeg2[cath]->Dpx(fInput->DetElemId(),isec)/2;
1993 lower[3]=vstart[3]-fSeg2[cath]->Dpy(fInput->DetElemId(),isec)/2;
1995 upper[2]=lower[2]+fSeg2[cath]->Dpx(fInput->DetElemId(),isec);
1996 upper[1]=lower[1]+2.*fSeg2[cath]->Dpy(fInput->DetElemId(),isec);
2003 static Double_t step[5]={0.0005, 0.0005, 0.0005, 0.0005, 0.0001};
2005 clusterInput.Fitter()->mnparm(0,"x1",vstart[0],step[0],lower[0],upper[0],ierflag);
2006 clusterInput.Fitter()->mnparm(1,"y1",vstart[1],step[1],lower[1],upper[1],ierflag);
2007 clusterInput.Fitter()->mnparm(2,"x2",vstart[2],step[2],lower[2],upper[2],ierflag);
2008 clusterInput.Fitter()->mnparm(3,"y2",vstart[3],step[3],lower[3],upper[3],ierflag);
2009 clusterInput.Fitter()->mnparm(4,"a0",vstart[4],step[4],lower[4],upper[4],ierflag);
2010 // ready for minimisation
2014 clusterInput.Fitter()->mnexcm("SET NOGR", arglist, 0, ierflag);
2015 clusterInput.Fitter()->mnexcm("MIGRAD", arglist, 0, ierflag);
2016 // clusterInput.Fitter()->mnexcm("EXIT" , arglist, 0, ierflag);
2017 // Get fitted parameters
2018 Double_t xrec[2], yrec[2], qfrac;
2020 Double_t epxz, b1, b2;
2022 clusterInput.Fitter()->mnpout(0, chname, xrec[0], epxz, b1, b2, ierflg);
2023 clusterInput.Fitter()->mnpout(1, chname, yrec[0], epxz, b1, b2, ierflg);
2024 clusterInput.Fitter()->mnpout(2, chname, xrec[1], epxz, b1, b2, ierflg);
2025 clusterInput.Fitter()->mnpout(3, chname, yrec[1], epxz, b1, b2, ierflg);
2026 clusterInput.Fitter()->mnpout(4, chname, qfrac, epxz, b1, b2, ierflg);
2028 Double_t fmin, fedm, errdef;
2029 Int_t npari, nparx, istat;
2031 clusterInput.Fitter()->mnstat(fmin, fedm, errdef, npari, nparx, istat);
2036 Float_t AliMUONClusterFinderVS::CombiDoubleMathiesonFit(AliMUONRawCluster * /*c*/)
2039 // Perform combined double Mathieson fit on both cathode planes
2041 Double_t arglist[20];
2043 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
2044 clusterInput.Fitter()->SetFCN(fcnCombiS2);
2045 clusterInput.Fitter()->mninit(6,10,7);
2046 clusterInput.Fitter()->SetPrintLevel(-1+fDebugLevel);
2048 clusterInput.Fitter()->mnexcm("SET NOW", arglist, 0, ierflag);
2049 // Set starting values
2050 static Double_t vstart[6];
2051 vstart[0]=fXInit[0];
2052 vstart[1]=fYInit[0];
2053 vstart[2]=fXInit[1];
2054 vstart[3]=fYInit[1];
2055 vstart[4]=fQrInit[0];
2056 vstart[5]=fQrInit[1];
2057 // lower and upper limits
2058 static Float_t lower[6], upper[6];
2061 if (fSegmentationType == 1) {
2062 fSeg[1]->GetPadI(fXInit[0], fYInit[0], fZPlane, ix, iy);
2063 isec=fSeg[1]->Sector(ix, iy);
2064 dpx=fSeg[1]->Dpx(isec);
2066 fSeg[0]->GetPadI(fXInit[0], fYInit[0], fZPlane, ix, iy);
2067 isec=fSeg[0]->Sector(ix, iy);
2068 dpy=fSeg[0]->Dpy(isec);
2071 fSeg2[1]->GetPadI(fInput->DetElemId(),fXInit[0], fYInit[0], fZPlane, ix, iy);
2072 isec=fSeg2[1]->Sector(fInput->DetElemId(),ix, iy);
2073 dpx=fSeg2[1]->Dpx(fInput->DetElemId(), isec);
2075 fSeg2[0]->GetPadI(fInput->DetElemId(), fXInit[0], fYInit[0], fZPlane, ix, iy);
2076 isec=fSeg2[0]->Sector(fInput->DetElemId(), ix, iy);
2077 dpy=fSeg2[0]->Dpy(fInput->DetElemId(), isec);
2082 Float_t xdum, ydum, zdum;
2083 AliDebug(1,Form("\n Cluster Finder: %f %f %f %f ", fXInit[0], fXInit[1],fYInit[0], fYInit[1] ));
2085 if (fSegmentationType == 1) {
2087 // Find save upper and lower limits
2090 for (fSeg[1]->FirstPad(fXInit[0], fYInit[0], fZPlane, dpx, 0.);
2091 fSeg[1]->MorePads();
2094 ix=fSeg[1]->Ix(); iy=fSeg[1]->Iy();
2095 // if (fHitMap[1]->TestHit(ix, iy) == kEmpty) continue;
2096 fSeg[1]->GetPadC(ix,iy,upper[0],ydum,zdum);
2097 if (icount ==0) lower[0]=upper[0];
2100 if (lower[0]>upper[0]) {xdum=lower[0]; lower[0]=upper[0]; upper[0]=xdum;}
2101 // vstart[0] = 0.5*(lower[0]+upper[0]);
2106 for (fSeg[0]->FirstPad(fXInit[0], fYInit[0], fZPlane, 0., dpy);
2107 fSeg[0]->MorePads();
2110 ix=fSeg[0]->Ix(); iy=fSeg[0]->Iy();
2111 // if (fHitMap[0]->TestHit(ix, iy) == kEmpty) continue;
2112 fSeg[0]->GetPadC(ix,iy,xdum,upper[1],zdum);
2113 if (icount ==0) lower[1]=upper[1];
2117 if (lower[1]>upper[1]) {xdum=lower[1]; lower[1]=upper[1]; upper[1]=xdum;}
2118 // vstart[1] = 0.5*(lower[1]+upper[1]);
2121 fSeg[1]->GetPadI(fXInit[1], fYInit[1], fZPlane, ix, iy);
2122 isec=fSeg[1]->Sector(ix, iy);
2123 dpx=fSeg[1]->Dpx(isec);
2124 fSeg[0]->GetPadI(fXInit[1], fYInit[1], fZPlane, ix, iy);
2125 isec=fSeg[0]->Sector(ix, iy);
2126 dpy=fSeg[0]->Dpy(isec);
2129 // Find save upper and lower limits
2133 for (fSeg[1]->FirstPad(fXInit[1], fYInit[1], fZPlane, dpx, 0);
2134 fSeg[1]->MorePads(); fSeg[1]->NextPad())
2136 ix=fSeg[1]->Ix(); iy=fSeg[1]->Iy();
2137 // if (fHitMap[1]->TestHit(ix, iy) == kEmpty) continue;
2138 fSeg[1]->GetPadC(ix,iy,upper[2],ydum,zdum);
2139 if (icount ==0) lower[2]=upper[2];
2142 if (lower[2]>upper[2]) {xdum=lower[2]; lower[2]=upper[2]; upper[2]=xdum;}
2143 // vstart[2] = 0.5*(lower[2]+upper[2]);
2147 for (fSeg[0]->FirstPad(fXInit[1], fYInit[1], fZPlane, 0, dpy);
2148 fSeg[0]-> MorePads(); fSeg[0]->NextPad())
2150 ix=fSeg[0]->Ix(); iy=fSeg[0]->Iy();
2151 // if (fHitMap[0]->TestHit(ix, iy) != kEmpty) continue;
2153 fSeg[0]->GetPadC(ix,iy,xdum,upper[3],zdum);
2154 if (icount ==0) lower[3]=upper[3];
2158 if (lower[3]>upper[3]) {xdum=lower[3]; lower[3]=upper[3]; upper[3]=xdum;}
2160 // vstart[3] = 0.5*(lower[3]+upper[3]);
2163 // Find save upper and lower limits
2166 for (fSeg2[1]->FirstPad(fInput->DetElemId(),fXInit[0], fYInit[0], fZPlane, dpx, 0.);
2167 fSeg2[1]->MorePads(fInput->DetElemId());
2168 fSeg2[1]->NextPad(fInput->DetElemId()))
2170 ix=fSeg2[1]->Ix(); iy=fSeg2[1]->Iy();
2171 // if (fHitMap[1]->TestHit(ix, iy) == kEmpty) continue;
2172 fSeg2[1]->GetPadC(fInput->DetElemId(),ix,iy,upper[0],ydum,zdum);
2173 if (icount ==0) lower[0]=upper[0];
2176 if (lower[0]>upper[0]) {xdum=lower[0]; lower[0]=upper[0]; upper[0]=xdum;}
2177 // vstart[0] = 0.5*(lower[0]+upper[0]);
2182 for (fSeg2[0]->FirstPad(fInput->DetElemId(),fXInit[0], fYInit[0], fZPlane, 0., dpy);
2183 fSeg2[0]->MorePads(fInput->DetElemId());
2184 fSeg2[0]->NextPad(fInput->DetElemId()))
2186 ix=fSeg2[0]->Ix(); iy=fSeg2[0]->Iy();
2187 // if (fHitMap[0]->TestHit(ix, iy) == kEmpty) continue;
2188 fSeg2[0]->GetPadC(fInput->DetElemId(),ix,iy,xdum,upper[1],zdum);
2189 if (icount ==0) lower[1]=upper[1];
2193 if (lower[1]>upper[1]) {xdum=lower[1]; lower[1]=upper[1]; upper[1]=xdum;}
2194 // vstart[1] = 0.5*(lower[1]+upper[1]);
2197 fSeg2[1]->GetPadI(fInput->DetElemId(),fXInit[1], fYInit[1], fZPlane, ix, iy);
2198 isec=fSeg2[1]->Sector(fInput->DetElemId(),ix, iy);
2199 dpx=fSeg2[1]->Dpx(fInput->DetElemId(),isec);
2200 fSeg2[0]->GetPadI(fInput->DetElemId(),fXInit[1], fYInit[1], fZPlane, ix, iy);
2201 isec=fSeg2[0]->Sector(fInput->DetElemId(),ix, iy);
2202 dpy=fSeg2[0]->Dpy(fInput->DetElemId(),isec);
2205 // Find save upper and lower limits
2209 for (fSeg2[1]->FirstPad(fInput->DetElemId(),fXInit[1], fYInit[1], fZPlane, dpx, 0);
2210 fSeg2[1]->MorePads(fInput->DetElemId());
2211 fSeg2[1]->NextPad(fInput->DetElemId()))
2213 ix=fSeg2[1]->Ix(); iy=fSeg2[1]->Iy();
2214 // if (fHitMap[1]->TestHit(ix, iy) == kEmpty) continue;
2215 fSeg2[1]->GetPadC(fInput->DetElemId(),ix,iy,upper[2],ydum,zdum);
2216 if (icount ==0) lower[2]=upper[2];
2219 if (lower[2]>upper[2]) {xdum=lower[2]; lower[2]=upper[2]; upper[2]=xdum;}
2220 // vstart[2] = 0.5*(lower[2]+upper[2]);
2224 for (fSeg2[0]->FirstPad(fInput->DetElemId(),fXInit[1], fYInit[1], fZPlane, 0, dpy);
2225 fSeg2[0]-> MorePads(fInput->DetElemId());
2226 fSeg2[0]->NextPad(fInput->DetElemId()))
2228 ix=fSeg2[0]->Ix(); iy=fSeg2[0]->Iy();
2229 // if (fHitMap[0]->TestHit(ix, iy) != kEmpty) continue;
2231 fSeg2[0]->GetPadC(fInput->DetElemId(),ix,iy,xdum,upper[3],zdum);
2232 if (icount ==0) lower[3]=upper[3];
2236 if (lower[3]>upper[3]) {xdum=lower[3]; lower[3]=upper[3]; upper[3]=xdum;}
2244 static Double_t step[6]={0.0005, 0.0005, 0.0005, 0.0005, 0.001, 0.001};
2245 clusterInput.Fitter()->mnparm(0,"x1",vstart[0],step[0],lower[0],upper[0],ierflag);
2246 clusterInput.Fitter()->mnparm(1,"y1",vstart[1],step[1],lower[1],upper[1],ierflag);
2247 clusterInput.Fitter()->mnparm(2,"x2",vstart[2],step[2],lower[2],upper[2],ierflag);
2248 clusterInput.Fitter()->mnparm(3,"y2",vstart[3],step[3],lower[3],upper[3],ierflag);
2249 clusterInput.Fitter()->mnparm(4,"a0",vstart[4],step[4],lower[4],upper[4],ierflag);
2250 clusterInput.Fitter()->mnparm(5,"a1",vstart[5],step[5],lower[5],upper[5],ierflag);
2251 // ready for minimisation
2255 clusterInput.Fitter()->mnexcm("SET NOGR", arglist, 0, ierflag);
2256 clusterInput.Fitter()->mnexcm("MIGRAD", arglist, 0, ierflag);
2257 // clusterInput.Fitter()->mnexcm("EXIT" , arglist, 0, ierflag);
2258 // Get fitted parameters
2260 Double_t epxz, b1, b2;
2262 clusterInput.Fitter()->mnpout(0, chname, fXFit[0], epxz, b1, b2, ierflg);
2263 clusterInput.Fitter()->mnpout(1, chname, fYFit[0], epxz, b1, b2, ierflg);
2264 clusterInput.Fitter()->mnpout(2, chname, fXFit[1], epxz, b1, b2, ierflg);
2265 clusterInput.Fitter()->mnpout(3, chname, fYFit[1], epxz, b1, b2, ierflg);
2266 clusterInput.Fitter()->mnpout(4, chname, fQrFit[0], epxz, b1, b2, ierflg);
2267 clusterInput.Fitter()->mnpout(5, chname, fQrFit[1], epxz, b1, b2, ierflg);
2269 Double_t fmin, fedm, errdef;
2270 Int_t npari, nparx, istat;
2272 clusterInput.Fitter()->mnstat(fmin, fedm, errdef, npari, nparx, istat);
2280 void AliMUONClusterFinderVS::Split(AliMUONRawCluster* c)
2283 // One cluster for each maximum
2286 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
2287 for (j=0; j<2; j++) {
2288 AliMUONRawCluster cnew;
2289 cnew.SetGhost(c->GetGhost());
2290 for (cath=0; cath<2; cath++) {
2291 cnew.SetChi2(cath,fChi2[0]);
2292 // ?? why not cnew.fChi2[cath]=fChi2[cath];
2295 cnew.SetNcluster(0,-1);
2296 cnew.SetNcluster(1,fNRawClusters);
2298 cnew.SetNcluster(0,fNPeaks);
2299 cnew.SetNcluster(1,0);
2301 cnew.SetMultiplicity(cath,0);
2302 cnew.SetX(cath, Float_t(fXFit[j]));
2303 cnew.SetY(cath, Float_t(fYFit[j]));
2304 cnew.SetZ(cath, fZPlane);
2306 cnew.SetCharge(cath, Int_t(clusterInput.TotalCharge(cath)*fQrFit[cath]));
2308 cnew.SetCharge(cath, Int_t(clusterInput.TotalCharge(cath)*(1-fQrFit[cath])));
2310 if (fSegmentationType == 1)
2311 fSeg[cath]->SetHit(fXFit[j],fYFit[j],fZPlane);
2313 fSeg2[cath]->SetHit(fInput->DetElemId(), fXFit[j],fYFit[j],fZPlane);
2315 for (i=0; i<fMul[cath]; i++) {
2317 cnew.SetIndex(cnew.GetMultiplicity(cath), cath, c->GetIndex(i,cath));
2318 if (fSegmentationType == 1) {
2319 fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
2320 q1 = fInput->Mathieson()->IntXY(fSeg[cath]);
2322 fSeg2[cath]->SetPad(fInput->DetElemId(),fIx[i][cath], fIy[i][cath]);
2323 q1 = fInput->Mathieson()->IntXY(fInput->DetElemId(),fSeg2[cath]);
2325 cnew.SetContrib(i, cath, q1*Float_t(cnew.GetCharge(cath))/Float_t(fQ[i][cath]));
2326 cnew.SetMultiplicity(cath, cnew.GetMultiplicity(cath)+1 );
2328 FillCluster(&cnew,0,cath);
2330 cnew.SetClusterType(cnew.PhysicsContribution());
2331 if (cnew.GetCharge(0)>0 && cnew.GetCharge(1)>0) AddRawCluster(cnew);
2335 void AliMUONClusterFinderVS::AddRawCluster(AliMUONRawCluster& c)
2338 // Add a raw cluster copy to the list
2340 // AliMUON *pMUON=(AliMUON*)gAlice->GetModule("MUON");
2341 // pMUON->GetMUONData()->AddRawCluster(fInput->Chamber(),c);
2344 // Setting detection element in raw cluster for alignment
2346 c.SetDetElementID(fInput->DetElemId());
2348 TClonesArray &lrawcl = *fRawClusters;
2349 new(lrawcl[fNRawClusters++]) AliMUONRawCluster(c);
2350 AliDebug(1,Form("\nfNRawClusters %d\n",fNRawClusters));
2353 AliMUONClusterFinderVS& AliMUONClusterFinderVS
2354 ::operator = (const AliMUONClusterFinderVS& rhs)
2356 // Protected assignement operator
2358 if (this == &rhs) return *this;
2360 AliFatal("Not implemented.");
2366 // Minimisation functions
2368 void fcnS1(Int_t & /*npar*/, Double_t * /*gin*/, Double_t &f, Double_t *par, Int_t /*iflag*/)
2370 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
2377 for (i=0; i<clusterInput.Nmul(0); i++) {
2378 Float_t q0=clusterInput.Charge(i,0);
2379 Float_t q1=clusterInput.DiscrChargeS1(i,par);
2388 void fcnCombiS1(Int_t & /*npar*/, Double_t * /*gin*/, Double_t &f, Double_t *par, Int_t /*iflag*/)
2390 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
2397 for (cath=0; cath<2; cath++) {
2398 for (i=0; i<clusterInput.Nmul(cath); i++) {
2399 Float_t q0=clusterInput.Charge(i,cath);
2400 Float_t q1=clusterInput.DiscrChargeCombiS1(i,par,cath);
2411 void fcnS2(Int_t & /*npar*/, Double_t * /*gin*/, Double_t &f, Double_t *par, Int_t /*iflag*/)
2413 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
2420 for (i=0; i<clusterInput.Nmul(0); i++) {
2422 Float_t q0=clusterInput.Charge(i,0);
2423 Float_t q1=clusterInput.DiscrChargeS2(i,par);
2433 void fcnCombiS2(Int_t & /*npar*/, Double_t * /*gin*/, Double_t &f, Double_t *par, Int_t /*iflag*/)
2435 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
2441 for (cath=0; cath<2; cath++) {
2442 for (i=0; i<clusterInput.Nmul(cath); i++) {
2443 Float_t q0=clusterInput.Charge(i,cath);
2444 Float_t q1=clusterInput.DiscrChargeCombiS2(i,par,cath);