Remove obselete method Hit2Digit for digitalization
[u/mrichter/AliRoot.git] / MUON / AliMUONClusterFinderVS.cxx
CommitLineData
a9e2aefa 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
70479d0e 15
88cb7938 16/* $Id$ */
a9e2aefa 17
30178c30 18#include <TMinuit.h>
19#include <TF1.h>
fed772f3 20#include <TMinuit.h>
21#include <Riostream.h>
30178c30 22
a9e2aefa 23#include "AliMUONClusterFinderVS.h"
24#include "AliMUONDigit.h"
25#include "AliMUONRawCluster.h"
a30a000f 26#include "AliSegmentation.h"
fed772f3 27#include "AliMUONGeometrySegmentation.h"
7e4a628d 28#include "AliMUONMathieson.h"
c1a185bf 29#include "AliMUONClusterInput.h"
a9e2aefa 30#include "AliMUONHitMapA1.h"
8c343c7c 31#include "AliLog.h"
a9e2aefa 32
33//_____________________________________________________________________
a9e2aefa 34// This function is minimized in the double-Mathieson fit
35void fcnS2(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag);
36void fcnS1(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag);
37void fcnCombiS1(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag);
38void fcnCombiS2(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag);
39
40ClassImp(AliMUONClusterFinderVS)
41
4da78c65 42AliMUONClusterFinderVS::AliMUONClusterFinderVS()
30178c30 43 : TObject()
a9e2aefa 44{
45// Default constructor
30aaba74 46 fInput=AliMUONClusterInput::Instance();
fed772f3 47 fSegmentationType = fInput->GetSegmentationType();
48// cout << " TYPE" << fSegmentationType << endl;
30aaba74 49 fHitMap[0] = 0;
50 fHitMap[1] = 0;
a9e2aefa 51 fTrack[0]=fTrack[1]=-1;
07cfabcf 52 fDebugLevel = 0; // make silent default
53 fGhostChi2Cut = 1e6; // nothing done by default
3f5cf0b3 54 fSeg[0] = 0;
55 fSeg[1] = 0;
fed772f3 56 fSeg2[0] = 0;
57 fSeg2[1] = 0;
58
3f5cf0b3 59 for(Int_t i=0; i<100; i++) {
60 for (Int_t j=0; j<2; j++) {
61 fDig[i][j] = 0;
62 }
4da78c65 63 }
64 fRawClusters = new TClonesArray("AliMUONRawCluster",1000);
65 fNRawClusters = 0;
4da78c65 66}
67 //____________________________________________________________________________
68AliMUONClusterFinderVS::~AliMUONClusterFinderVS()
69{
70 // Reset tracks information
71 fNRawClusters = 0;
86b48c39 72 if (fRawClusters) {
73 fRawClusters->Delete();
74 delete fRawClusters;
75 }
a9e2aefa 76}
77
e3cba86e 78AliMUONClusterFinderVS::AliMUONClusterFinderVS(const AliMUONClusterFinderVS & clusterFinder):TObject(clusterFinder)
a9e2aefa 79{
30178c30 80// Protected copy constructor
81
8c343c7c 82 AliFatal("Not implemented.");
a9e2aefa 83}
4da78c65 84//____________________________________________________________________________
85void AliMUONClusterFinderVS::ResetRawClusters()
86{
87 // Reset tracks information
88 fNRawClusters = 0;
89 if (fRawClusters) fRawClusters->Clear();
90}
91//____________________________________________________________________________
a9e2aefa 92void AliMUONClusterFinderVS::Decluster(AliMUONRawCluster *cluster)
93{
94// Decluster by local maxima
95 SplitByLocalMaxima(cluster);
96}
4da78c65 97//____________________________________________________________________________
a9e2aefa 98void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
99{
100// Split complex cluster by local maxima
a9e2aefa 101 Int_t cath, i;
9825400f 102
30aaba74 103 fInput->SetCluster(c);
9825400f 104
9e993f2a 105 fMul[0]=c->GetMultiplicity(0);
106 fMul[1]=c->GetMultiplicity(1);
a9e2aefa 107
108//
109// dump digit information into arrays
110//
9825400f 111
f0d86bc4 112 Float_t qtot;
a9e2aefa 113
114 for (cath=0; cath<2; cath++) {
115 qtot=0;
116 for (i=0; i<fMul[cath]; i++)
117 {
118 // pointer to digit
0164904a 119 fDig[i][cath]=fInput->Digit(cath, c->GetIndex(i, cath));
a9e2aefa 120 // pad coordinates
08a636a8 121 fIx[i][cath]= fDig[i][cath]->PadX();
122 fIy[i][cath]= fDig[i][cath]->PadY();
a9e2aefa 123 // pad charge
08a636a8 124 fQ[i][cath] = fDig[i][cath]->Signal();
a9e2aefa 125 // pad centre coordinates
fed772f3 126 if (fSegmentationType == 1)
127 fSeg[cath]->
f0d86bc4 128 GetPadC(fIx[i][cath], fIy[i][cath], fX[i][cath], fY[i][cath], fZ[i][cath]);
fed772f3 129 else
130 fSeg2[cath]->
131 GetPadC(fInput->DetElemId(), fIx[i][cath], fIy[i][cath], fX[i][cath], fY[i][cath], fZ[i][cath]);
a9e2aefa 132 } // loop over cluster digits
a9e2aefa 133 } // loop over cathodes
134
135
136 FindLocalMaxima(c);
137
138//
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)) {
a9e2aefa 146// Perform combined single Mathieson fit
147// Initial values for coordinates (x,y)
148
149 // One local maximum on cathodes 1 and 2 (X->cathode 2, Y->cathode 1)
150 if (fNLocal[0]==1 && fNLocal[1]==1) {
ba12c242 151 fXInit[0]=c->GetX(1);
152 fYInit[0]=c->GetY(0);
a9e2aefa 153 // One local maximum on cathode 1 (X,Y->cathode 1)
154 } else if (fNLocal[0]==1) {
ba12c242 155 fXInit[0]=c->GetX(0);
156 fYInit[0]=c->GetY(0);
a9e2aefa 157 // One local maximum on cathode 2 (X,Y->cathode 2)
158 } else {
ba12c242 159 fXInit[0]=c->GetX(1);
160 fYInit[0]=c->GetY(1);
a9e2aefa 161 }
8c343c7c 162 AliDebug(1,"cas (1) CombiSingleMathiesonFit(c)");
a9e2aefa 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);
168 oldchi2=chi2;
8c343c7c 169 AliDebug(1,Form(" chi2 %f ",chi2));
a9e2aefa 170
ba12c242 171 c->SetX(0, fXFit[0]);
172 c->SetY(0, fYFit[0]);
a9e2aefa 173
ba12c242 174 c->SetX(1,fXFit[0]);
175 c->SetY(1,fYFit[0]);
3b5272e3 176 c->SetChi2(0,chi2);
177 c->SetChi2(1,chi2);
07cfabcf 178 // Force on anod
fed772f3 179 if (fSegmentationType == 1) {
180 c->SetX(0, fSeg[0]->GetAnod(c->GetX(0)));
181 c->SetX(1, fSeg[1]->GetAnod(c->GetX(1)));
182 } else {
183 c->SetX(0, fSeg2[0]->GetAnod(fInput->DetElemId(), c->GetX(0)));
184 c->SetX(1, fSeg2[1]->GetAnod(fInput->DetElemId(), c->GetX(1)));
185 }
a9e2aefa 186
187// If reasonable chi^2 add result to the list of rawclusters
a9e2aefa 188 if (chi2 < 0.3) {
189 AddRawCluster(*c);
190// If not try combined double Mathieson Fit
191 } else {
c4a97bcd 192 AliDebug(1," MAUVAIS CHI2 !!!\n");
a9e2aefa 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];
203 } else {
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];
208 }
209
210// Initial value for charge ratios
211 fQrInit[0]=0.5;
212 fQrInit[1]=0.5;
c4a97bcd 213 AliDebug(1,"\n cas (1) CombiDoubleMathiesonFit(c)\n");
a9e2aefa 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);
219
220// Was this any better ??
8c343c7c 221 AliDebug(1,Form(" Old and new chi2 %f %f ", oldchi2, chi2));
a9e2aefa 222 if (fFitStat!=0 && chi2>0 && (2.*chi2 < oldchi2)) {
8c343c7c 223 AliDebug(1,"Split");
a9e2aefa 224 // Split cluster into two according to fit result
225 Split(c);
226 } else {
8c343c7c 227 AliDebug(1,"Do not Split");
a9e2aefa 228 // Don't split
229 AddRawCluster(*c);
230 }
231 }
232
233// +++++++++++++++++++++++++++++++++++++++
234// (2) Two local maxima per cathode plane
235// +++++++++++++++++++++++++++++++++++++++
236 } else if (fNLocal[0]==2 && fNLocal[1]==2) {
237//
238// Let's look for ghosts first
05c39730 239
a9e2aefa 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;
244//
245// Form the 2x2 combinations
246// 0-0, 0-1, 1-0, 1-1
247 ico=0;
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];
254
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];
259 ico++;
260 }
261 }
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
266
267// Analyse the combinations and keep those that are possible !
268// For each combination check consistency in x and y
05c39730 269 Int_t iacc;
270 Bool_t accepted[4];
271 Float_t dr[4] = {1.e4, 1.e4, 1.e4, 1.e4};
a9e2aefa 272 iacc=0;
05c39730 273
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;
276 Float_t eps = 1.e-5;
277//
a9e2aefa 278 for (ico=0; ico<4; ico++) {
279 accepted[ico]=kFALSE;
280// cathode one: x-coordinate
fed772f3 281 if (fSegmentationType == 1) {
282 isec=fSeg[0]->Sector(ixm[ico][0], iym[ico][0]);
283 dpx=fSeg[0]->Dpx(isec)/2.;
284 } else {
285 isec=fSeg2[0]->Sector(fInput->DetElemId(), ixm[ico][0], iym[ico][0]);
286 dpx=fSeg2[0]->Dpx(fInput->DetElemId(), isec)/2.;
287 }
a9e2aefa 288 dx=TMath::Abs(xm[ico][0]-xm[ico][1]);
289// cathode two: y-coordinate
fed772f3 290 if (fSegmentationType == 1) {
291 isec=fSeg[1]->Sector(ixm[ico][1], iym[ico][1]);
292 dpy=fSeg[1]->Dpy(isec)/2.;
293 } else {
294 isec=fSeg2[1]->Sector(fInput->DetElemId(), ixm[ico][1], iym[ico][1]);
295 dpy=fSeg2[1]->Dpy(fInput->DetElemId(), isec)/2.;
296 }
a9e2aefa 297 dy=TMath::Abs(ym[ico][0]-ym[ico][1]);
c4a97bcd 298 AliDebug(2,Form("\n %i %f %f %f %f %f %f \n", ico, ym[ico][0], ym[ico][1], dy, dpy, dx, dpx ));
05c39730 299 if ((dx <= dpx) && (dy <= dpy+eps)) {
a9e2aefa 300 // consistent
301 accepted[ico]=kTRUE;
05c39730 302 dr[ico] = TMath::Sqrt(dx*dx+dy*dy);
a9e2aefa 303 iacc++;
304 } else {
305 // reject
306 accepted[ico]=kFALSE;
307 }
308 }
c4a97bcd 309 AliDebug(1,Form("\n iacc= %d:\n", iacc));
05c39730 310 if (iacc == 3) {
311 if (accepted[0] && accepted[1]) {
312 if (dr[0] >= dr[1]) {
313 accepted[0]=kFALSE;
314 } else {
315 accepted[1]=kFALSE;
316 }
317 }
a9e2aefa 318
05c39730 319 if (accepted[2] && accepted[3]) {
320 if (dr[2] >= dr[3]) {
321 accepted[2]=kFALSE;
322 } else {
323 accepted[3]=kFALSE;
324 }
325 }
326/*
327// eliminate one candidate
328 Float_t drmax = 0;
329 Int_t icobad = -1;
330
331 for (ico=0; ico<4; ico++) {
332 if (accepted[ico] && dr[ico] > drmax) {
333 icobad = ico;
334 drmax = dr[ico];
335 }
336 }
337
338 accepted[icobad] = kFALSE;
339*/
340 iacc = 2;
341 }
342
343
c4a97bcd 344 AliDebug(1,Form("\n iacc= %d:\n", iacc));
345 if (iacc==2) {
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");
a9e2aefa 351 }
352
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]);
358
359// ******* iacc = 0 *******
360// No combinations found between the 2 cathodes
361// We keep the center of gravity of the cluster
362 if (iacc==0) {
363 AddRawCluster(*c);
364 }
365
366// ******* iacc = 1 *******
367// Only one combination found between the 2 cathodes
368 if (iacc==1) {
a9e2aefa 369// Initial values for the 2 maxima (x,y)
370
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
373 if (accepted[0]){
8c343c7c 374 AliDebug(1,"ico=0");
a9e2aefa 375 fXInit[0]=xm[0][1];
376 fYInit[0]=ym[0][0];
377 fXInit[1]=xm[3][0];
378 fYInit[1]=ym[3][0];
379 } else if (accepted[1]){
8c343c7c 380 AliDebug(1,"ico=1");
a9e2aefa 381 fXInit[0]=xm[1][1];
382 fYInit[0]=ym[1][0];
383 fXInit[1]=xm[2][0];
384 fYInit[1]=ym[2][0];
385 } else if (accepted[2]){
8c343c7c 386 AliDebug(1,"ico=2");
a9e2aefa 387 fXInit[0]=xm[2][1];
388 fYInit[0]=ym[2][0];
389 fXInit[1]=xm[1][0];
390 fYInit[1]=ym[1][0];
391 } else if (accepted[3]){
8c343c7c 392 AliDebug(1,"ico=3");
a9e2aefa 393 fXInit[0]=xm[3][1];
394 fYInit[0]=ym[3][0];
395 fXInit[1]=xm[0][0];
396 fYInit[1]=ym[0][0];
397 }
8c343c7c 398 AliDebug(1,"cas (2) CombiDoubleMathiesonFit(c)");
a9e2aefa 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);
8c343c7c 404 AliDebug(1,Form(" chi2 %f\n",chi2));
a9e2aefa 405
406// If reasonable chi^2 add result to the list of rawclusters
407 if (chi2<10) {
408 Split(c);
409
410 } else {
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
413 if (accepted[0]){
8c343c7c 414 AliDebug(1,"ico=0");
a9e2aefa 415 fXInit[0]=xm[0][1];
416 fYInit[0]=ym[0][0];
417 fXInit[1]=xm[3][1];
418 fYInit[1]=ym[3][1];
419 } else if (accepted[1]){
8c343c7c 420 AliDebug(1,"ico=1");
a9e2aefa 421 fXInit[0]=xm[1][1];
422 fYInit[0]=ym[1][0];
423 fXInit[1]=xm[2][1];
424 fYInit[1]=ym[2][1];
425 } else if (accepted[2]){
8c343c7c 426 AliDebug(1,"ico=2");
a9e2aefa 427 fXInit[0]=xm[2][1];
428 fYInit[0]=ym[2][0];
429 fXInit[1]=xm[1][1];
430 fYInit[1]=ym[1][1];
431 } else if (accepted[3]){
8c343c7c 432 AliDebug(1,"ico=3");
a9e2aefa 433 fXInit[0]=xm[3][1];
434 fYInit[0]=ym[3][0];
435 fXInit[1]=xm[0][1];
436 fYInit[1]=ym[0][1];
437 }
8c343c7c 438 AliDebug(1,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
a9e2aefa 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);
c4a97bcd 444 AliDebug(1,Form(" chi2 %f\n",chi2));
a9e2aefa 445
446// If reasonable chi^2 add result to the list of rawclusters
447 if (chi2<10) {
448 Split(c);
449 } else {
450//We keep only the combination found (X->cathode 2, Y->cathode 1)
451 for (Int_t ico=0; ico<2; ico++) {
452 if (accepted[ico]) {
453 AliMUONRawCluster cnew;
454 Int_t cath;
455 for (cath=0; cath<2; cath++) {
ba12c242 456 cnew.SetX(cath, Float_t(xm[ico][1]));
457 cnew.SetY(cath, Float_t(ym[ico][0]));
458 cnew.SetZ(cath, fZPlane);
aadda617 459
9e993f2a 460 cnew.SetMultiplicity(cath,c->GetMultiplicity(cath));
a9e2aefa 461 for (i=0; i<fMul[cath]; i++) {
fed772f3 462 cnew.SetIndex(i, cath, c->GetIndex(i,cath));
463 if (fSegmentationType == 1)
f0d86bc4 464 fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
fed772f3 465 else
466 fSeg2[cath]->SetPad(fInput->DetElemId(), fIx[i][cath], fIy[i][cath]);
a9e2aefa 467 }
c4a97bcd 468 AliDebug(1,Form("\nRawCluster %d cath %d\n",ico,cath));
469 AliDebug(1,Form("mult_av %d\n",c->GetMultiplicity(cath)));
9825400f 470 FillCluster(&cnew,cath);
a9e2aefa 471 }
9e993f2a 472 cnew.SetClusterType(cnew.PhysicsContribution());
a9e2aefa 473 AddRawCluster(cnew);
474 fNPeaks++;
475 }
476 }
477 }
478 }
479 }
9825400f 480
a9e2aefa 481// ******* iacc = 2 *******
482// Two combinations found between the 2 cathodes
483 if (iacc==2) {
a9e2aefa 484// Was the same maximum taken twice
9825400f 485 if ((accepted[0]&&accepted[1]) || (accepted[2]&&accepted[3])) {
c4a97bcd 486 AliDebug(1,"\n Maximum taken twice !!!\n");
a9e2aefa 487
05c39730 488// Have a try !! with that
9825400f 489 if (accepted[0]&&accepted[3]) {
490 fXInit[0]=xm[0][1];
491 fYInit[0]=ym[0][0];
492 fXInit[1]=xm[1][1];
493 fYInit[1]=ym[1][0];
494 } else {
495 fXInit[0]=xm[2][1];
496 fYInit[0]=ym[2][0];
497 fXInit[1]=xm[3][1];
498 fYInit[1]=ym[3][0];
499 }
c4a97bcd 500 AliDebug(1,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
9825400f 501 chi2=CombiDoubleMathiesonFit(c);
a9e2aefa 502// Int_t ndf = fgNbins[0]+fgNbins[1]-6;
503// Float_t prob = TMath::Prob(chi2,ndf);
504// prob2->Fill(prob);
505// chi2_2->Fill(chi2);
9825400f 506 Split(c);
507
508 } else {
a9e2aefa 509// No ghosts ! No Problems ! - Perform one fit only !
9825400f 510 if (accepted[0]&&accepted[3]) {
511 fXInit[0]=xm[0][1];
512 fYInit[0]=ym[0][0];
513 fXInit[1]=xm[3][1];
514 fYInit[1]=ym[3][0];
515 } else {
516 fXInit[0]=xm[1][1];
517 fYInit[0]=ym[1][0];
518 fXInit[1]=xm[2][1];
519 fYInit[1]=ym[2][0];
520 }
c4a97bcd 521 AliDebug(1,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
9825400f 522 chi2=CombiDoubleMathiesonFit(c);
a9e2aefa 523// Int_t ndf = fgNbins[0]+fgNbins[1]-6;
524// Float_t prob = TMath::Prob(chi2,ndf);
525// prob2->Fill(prob);
526// chi2_2->Fill(chi2);
c4a97bcd 527 AliDebug(1,Form(" chi2 %f\n",chi2));
9825400f 528 Split(c);
529 }
530
a9e2aefa 531// ******* iacc = 4 *******
532// Four combinations found between the 2 cathodes
533// Ghost !!
9825400f 534 } else if (iacc==4) {
a9e2aefa 535// Perform fits for the two possibilities !!
07cfabcf 536// Accept if charges are compatible on both cathodes
537// If none are compatible, keep everything
9825400f 538 fXInit[0]=xm[0][1];
539 fYInit[0]=ym[0][0];
540 fXInit[1]=xm[3][1];
541 fYInit[1]=ym[3][0];
c4a97bcd 542 AliDebug(1,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
9825400f 543 chi2=CombiDoubleMathiesonFit(c);
a9e2aefa 544// Int_t ndf = fgNbins[0]+fgNbins[1]-6;
545// Float_t prob = TMath::Prob(chi2,ndf);
546// prob2->Fill(prob);
547// chi2_2->Fill(chi2);
c4a97bcd 548 AliDebug(1,Form(" chi2 %f\n",chi2));
07cfabcf 549 // store results of fit and postpone decision
550 Double_t sXFit[2],sYFit[2],sQrFit[2];
551 Float_t sChi2[2];
552 for (Int_t i=0;i<2;i++) {
553 sXFit[i]=fXFit[i];
554 sYFit[i]=fYFit[i];
555 sQrFit[i]=fQrFit[i];
556 sChi2[i]=fChi2[i];
557 }
9825400f 558 fXInit[0]=xm[1][1];
559 fYInit[0]=ym[1][0];
560 fXInit[1]=xm[2][1];
561 fYInit[1]=ym[2][0];
c4a97bcd 562 AliDebug(1,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
9825400f 563 chi2=CombiDoubleMathiesonFit(c);
a9e2aefa 564// ndf = fgNbins[0]+fgNbins[1]-6;
565// prob = TMath::Prob(chi2,ndf);
566// prob2->Fill(prob);
567// chi2_2->Fill(chi2);
c4a97bcd 568 AliDebug(1,Form(" chi2 %f\n",chi2));
07cfabcf 569 // We have all informations to perform the decision
570 // Compute the chi2 for the 2 possibilities
571 Float_t chi2fi,chi2si,chi2f,chi2s;
572
573 chi2f = (TMath::Log(fInput->TotalCharge(0)*fQrFit[0]
574 / (fInput->TotalCharge(1)*fQrFit[1]) )
7e4a628d 575 / fInput->ChargeCorrel() );
07cfabcf 576 chi2f *=chi2f;
577 chi2fi = (TMath::Log(fInput->TotalCharge(0)*(1-fQrFit[0])
578 / (fInput->TotalCharge(1)*(1-fQrFit[1])) )
7e4a628d 579 / fInput->ChargeCorrel() );
07cfabcf 580 chi2f += chi2fi*chi2fi;
581
582 chi2s = (TMath::Log(fInput->TotalCharge(0)*sQrFit[0]
583 / (fInput->TotalCharge(1)*sQrFit[1]) )
7e4a628d 584 / fInput->ChargeCorrel() );
07cfabcf 585 chi2s *=chi2s;
586 chi2si = (TMath::Log(fInput->TotalCharge(0)*(1-sQrFit[0])
587 / (fInput->TotalCharge(1)*(1-sQrFit[1])) )
7e4a628d 588 / fInput->ChargeCorrel() );
07cfabcf 589 chi2s += chi2si*chi2si;
590
591 // usefull to store the charge matching chi2 in the cluster
592 // fChi2[0]=sChi2[1]=chi2f;
593 // fChi2[1]=sChi2[0]=chi2s;
594
595 if (chi2f<=fGhostChi2Cut && chi2s<=fGhostChi2Cut)
3b5272e3 596 c->SetGhost(1);
07cfabcf 597 if (chi2f>fGhostChi2Cut && chi2s>fGhostChi2Cut) {
598 // we keep the ghost
3b5272e3 599 c->SetGhost(2);
07cfabcf 600 chi2s=-1;
601 chi2f=-1;
602 }
603 if (chi2f<=fGhostChi2Cut)
604 Split(c);
605 if (chi2s<=fGhostChi2Cut) {
606 // retreive saved values
607 for (Int_t i=0;i<2;i++) {
608 fXFit[i]=sXFit[i];
609 fYFit[i]=sYFit[i];
610 fQrFit[i]=sQrFit[i];
611 fChi2[i]=sChi2[i];
612 }
613 Split(c);
614 }
3b5272e3 615 c->SetGhost(0);
9825400f 616 }
a9e2aefa 617
9825400f 618 } else if (fNLocal[0]==2 && fNLocal[1]==1) {
a9e2aefa 619// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
620// (3) Two local maxima on cathode 1 and one maximum on cathode 2
621// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
622//
623 Float_t xm[4][2], ym[4][2];
624 Float_t dpx, dpy, dx, dy;
625 Int_t ixm[4][2], iym[4][2];
626 Int_t isec, im1, ico;
627//
628// Form the 2x2 combinations
629// 0-0, 0-1, 1-0, 1-1
630 ico=0;
631 for (im1=0; im1<2; im1++) {
9825400f 632 xm[ico][0]=fX[fIndLocal[im1][0]][0];
633 ym[ico][0]=fY[fIndLocal[im1][0]][0];
634 xm[ico][1]=fX[fIndLocal[0][1]][1];
635 ym[ico][1]=fY[fIndLocal[0][1]][1];
636
637 ixm[ico][0]=fIx[fIndLocal[im1][0]][0];
638 iym[ico][0]=fIy[fIndLocal[im1][0]][0];
639 ixm[ico][1]=fIx[fIndLocal[0][1]][1];
640 iym[ico][1]=fIy[fIndLocal[0][1]][1];
641 ico++;
a9e2aefa 642 }
643// ico = 0 : first local maximum on cathodes 1 and 2
644// ico = 1 : second local maximum on cathode 1 and first on cathode 2
645
646// Analyse the combinations and keep those that are possible !
647// For each combination check consistency in x and y
648 Int_t iacc;
649 Bool_t accepted[4];
650 iacc=0;
05c39730 651 // In case of staggering maxima are displaced by exactly half the pad-size in y.
375c469b 652 // We have to take into account the numerical precision in the consistency check;
653
05c39730 654 Float_t eps = 1.e-5;
655
a9e2aefa 656 for (ico=0; ico<2; ico++) {
657 accepted[ico]=kFALSE;
fed772f3 658 if (fSegmentationType == 1) {
659 isec=fSeg[0]->Sector(ixm[ico][0], iym[ico][0]);
660 dpx=fSeg[0]->Dpx(isec)/2.;
661 } else {
662 isec=fSeg2[0]->Sector(fInput->DetElemId(), ixm[ico][0], iym[ico][0]);
663 dpx=fSeg2[0]->Dpx(fInput->DetElemId(), isec)/2.;
664 }
a9e2aefa 665 dx=TMath::Abs(xm[ico][0]-xm[ico][1]);
fed772f3 666 if (fSegmentationType == 1) {
667 isec=fSeg[1]->Sector(ixm[ico][1], iym[ico][1]);
668 dpy=fSeg[1]->Dpy(isec)/2.;
669 } else {
670 isec=fSeg2[1]->Sector(fInput->DetElemId(), ixm[ico][1], iym[ico][1]);
671 dpy=fSeg2[1]->Dpy(fInput->DetElemId(), isec)/2.;
672 }
a9e2aefa 673 dy=TMath::Abs(ym[ico][0]-ym[ico][1]);
c4a97bcd 674 AliDebug(2,Form("\n %i %f %f %f %f \n", ico, ym[ico][0], ym[ico][1], dy, dpy ));
05c39730 675 if ((dx <= dpx) && (dy <= dpy+eps)) {
a9e2aefa 676 // consistent
677 accepted[ico]=kTRUE;
678 iacc++;
679 } else {
680 // reject
681 accepted[ico]=kFALSE;
682 }
683 }
9825400f 684
a9e2aefa 685 Float_t chi21 = 100;
686 Float_t chi22 = 100;
05c39730 687 Float_t chi23 = 100;
688
689 // Initial value for charge ratios
690 fQrInit[0]=Float_t(fQ[fIndLocal[0][0]][0])/
691 Float_t(fQ[fIndLocal[0][0]][0]+fQ[fIndLocal[1][0]][0]);
692 fQrInit[1]=fQrInit[0];
9825400f 693
05c39730 694 if (accepted[0] && accepted[1]) {
695
696 fXInit[0]=0.5*(xm[0][1]+xm[0][0]);
697 fYInit[0]=ym[0][0];
698 fXInit[1]=0.5*(xm[0][1]+xm[1][0]);
699 fYInit[1]=ym[1][0];
700 fQrInit[0]=0.5;
701 fQrInit[1]=0.5;
702 chi23=CombiDoubleMathiesonFit(c);
703 if (chi23<10) {
704 Split(c);
705 Float_t yst;
706 yst = fYFit[0];
707 fYFit[0] = fYFit[1];
708 fYFit[1] = yst;
709 Split(c);
710 }
711 } else if (accepted[0]) {
a9e2aefa 712 fXInit[0]=xm[0][1];
713 fYInit[0]=ym[0][0];
714 fXInit[1]=xm[1][0];
715 fYInit[1]=ym[1][0];
716 chi21=CombiDoubleMathiesonFit(c);
717// Int_t ndf = fgNbins[0]+fgNbins[1]-6;
718// Float_t prob = TMath::Prob(chi2,ndf);
719// prob2->Fill(prob);
720// chi2_2->Fill(chi21);
c4a97bcd 721 AliDebug(1,Form(" chi2 %f\n",chi21));
a9e2aefa 722 if (chi21<10) Split(c);
723 } else if (accepted[1]) {
724 fXInit[0]=xm[1][1];
725 fYInit[0]=ym[1][0];
726 fXInit[1]=xm[0][0];
727 fYInit[1]=ym[0][0];
728 chi22=CombiDoubleMathiesonFit(c);
729// Int_t ndf = fgNbins[0]+fgNbins[1]-6;
730// Float_t prob = TMath::Prob(chi2,ndf);
731// prob2->Fill(prob);
732// chi2_2->Fill(chi22);
c4a97bcd 733 AliDebug(1,Form(" chi2 %f\n",chi22));
a9e2aefa 734 if (chi22<10) Split(c);
735 }
736
375c469b 737 if (chi21 > 10 && chi22 > 10 && chi23 > 10) {
a9e2aefa 738// We keep only the combination found (X->cathode 2, Y->cathode 1)
739 for (Int_t ico=0; ico<2; ico++) {
740 if (accepted[ico]) {
741 AliMUONRawCluster cnew;
742 Int_t cath;
743 for (cath=0; cath<2; cath++) {
ba12c242 744 cnew.SetX(cath, Float_t(xm[ico][1]));
745 cnew.SetY(cath, Float_t(ym[ico][0]));
746 cnew.SetZ(cath, fZPlane);
9e993f2a 747 cnew.SetMultiplicity(cath, c->GetMultiplicity(cath));
a9e2aefa 748 for (i=0; i<fMul[cath]; i++) {
0164904a 749 cnew.SetIndex(i, cath, c->GetIndex(i, cath));
fed772f3 750 if (fSegmentationType == 1)
751 fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
752 else
753 fSeg2[cath]->SetPad(fInput->DetElemId(), fIx[i][cath], fIy[i][cath]);
754
a9e2aefa 755 }
c4a97bcd 756 AliDebug(1,Form("\nRawCluster %d cath %d\n",ico,cath));
757 AliDebug(1,Form("mult_av %d\n",c->GetMultiplicity(cath)));
758
a9e2aefa 759 FillCluster(&cnew,cath);
760 }
9e993f2a 761 cnew.SetClusterType(cnew.PhysicsContribution());
a9e2aefa 762 AddRawCluster(cnew);
763 fNPeaks++;
764 }
765 }
766 }
9825400f 767
a9e2aefa 768// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
769// (3') One local maximum on cathode 1 and two maxima on cathode 2
770// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
771 } else if (fNLocal[0]==1 && fNLocal[1]==2) {
a9e2aefa 772 Float_t xm[4][2], ym[4][2];
773 Float_t dpx, dpy, dx, dy;
774 Int_t ixm[4][2], iym[4][2];
775 Int_t isec, im1, ico;
776//
777// Form the 2x2 combinations
778// 0-0, 0-1, 1-0, 1-1
779 ico=0;
780 for (im1=0; im1<2; im1++) {
9825400f 781 xm[ico][0]=fX[fIndLocal[0][0]][0];
782 ym[ico][0]=fY[fIndLocal[0][0]][0];
783 xm[ico][1]=fX[fIndLocal[im1][1]][1];
784 ym[ico][1]=fY[fIndLocal[im1][1]][1];
785
786 ixm[ico][0]=fIx[fIndLocal[0][0]][0];
787 iym[ico][0]=fIy[fIndLocal[0][0]][0];
788 ixm[ico][1]=fIx[fIndLocal[im1][1]][1];
789 iym[ico][1]=fIy[fIndLocal[im1][1]][1];
790 ico++;
a9e2aefa 791 }
792// ico = 0 : first local maximum on cathodes 1 and 2
793// ico = 1 : first local maximum on cathode 1 and second on cathode 2
794
795// Analyse the combinations and keep those that are possible !
796// For each combination check consistency in x and y
797 Int_t iacc;
798 Bool_t accepted[4];
799 iacc=0;
05c39730 800 // In case of staggering maxima are displaced by exactly half the pad-size in y.
801 // We have to take into account the numerical precision in the consistency check;
802 Float_t eps = 1.e-5;
803
a9e2aefa 804
805 for (ico=0; ico<2; ico++) {
806 accepted[ico]=kFALSE;
fed772f3 807 if (fSegmentationType == 1) {
808 isec=fSeg[0]->Sector(ixm[ico][0], iym[ico][0]);
809 dpx=fSeg[0]->Dpx(isec)/2.;
810 } else {
811 isec=fSeg2[0]->Sector(fInput->DetElemId(), ixm[ico][0], iym[ico][0]);
812 dpx=fSeg2[0]->Dpx(fInput->DetElemId(), isec)/2.;
813 }
a9e2aefa 814 dx=TMath::Abs(xm[ico][0]-xm[ico][1]);
fed772f3 815 if (fSegmentationType == 1) {
816 isec=fSeg[1]->Sector(ixm[ico][1], iym[ico][1]);
817 dpy=fSeg[1]->Dpy(isec)/2.;
818 } else {
819 isec=fSeg2[1]->Sector(fInput->DetElemId(), ixm[ico][1], iym[ico][1]);
820 dpy=fSeg2[1]->Dpy(fInput->DetElemId(), isec)/2.;
821 }
a9e2aefa 822 dy=TMath::Abs(ym[ico][0]-ym[ico][1]);
c4a97bcd 823 AliDebug(1,Form("\n %i %f %f %f %f \n", ico, ym[ico][0], ym[ico][1], dy, dpy ));
05c39730 824 if ((dx <= dpx) && (dy <= dpy+eps)) {
a9e2aefa 825 // consistent
826 accepted[ico]=kTRUE;
c4a97bcd 827 AliDebug(1,Form("ico %d\n",ico));
a9e2aefa 828 iacc++;
829 } else {
830 // reject
831 accepted[ico]=kFALSE;
832 }
833 }
834
835 Float_t chi21 = 100;
836 Float_t chi22 = 100;
05c39730 837 Float_t chi23 = 100;
838
839 fQrInit[1]=Float_t(fQ[fIndLocal[0][1]][1])/
840 Float_t(fQ[fIndLocal[0][1]][1]+fQ[fIndLocal[1][1]][1]);
841
842 fQrInit[0]=fQrInit[1];
a9e2aefa 843
05c39730 844
845 if (accepted[0] && accepted[1]) {
846 fXInit[0]=xm[0][1];
847 fYInit[0]=0.5*(ym[0][0]+ym[0][1]);
848 fXInit[1]=xm[1][1];
849 fYInit[1]=0.5*(ym[0][0]+ym[1][1]);
850 fQrInit[0]=0.5;
851 fQrInit[1]=0.5;
852 chi23=CombiDoubleMathiesonFit(c);
853 if (chi23<10) {
854 Split(c);
855 Float_t yst;
856 yst = fYFit[0];
857 fYFit[0] = fYFit[1];
858 fYFit[1] = yst;
859 Split(c);
860 }
861 } else if (accepted[0]) {
a9e2aefa 862 fXInit[0]=xm[0][0];
863 fYInit[0]=ym[0][1];
864 fXInit[1]=xm[1][1];
865 fYInit[1]=ym[1][1];
866 chi21=CombiDoubleMathiesonFit(c);
867// Int_t ndf = fgNbins[0]+fgNbins[1]-6;
868// Float_t prob = TMath::Prob(chi2,ndf);
869// prob2->Fill(prob);
870// chi2_2->Fill(chi21);
c4a97bcd 871 AliDebug(1,Form(" chi2 %f\n",chi21));
a9e2aefa 872 if (chi21<10) Split(c);
873 } else if (accepted[1]) {
874 fXInit[0]=xm[1][0];
875 fYInit[0]=ym[1][1];
876 fXInit[1]=xm[0][1];
877 fYInit[1]=ym[0][1];
878 chi22=CombiDoubleMathiesonFit(c);
879// Int_t ndf = fgNbins[0]+fgNbins[1]-6;
880// Float_t prob = TMath::Prob(chi2,ndf);
881// prob2->Fill(prob);
882// chi2_2->Fill(chi22);
c4a97bcd 883 AliDebug(1,Form(" chi2 %f\n",chi22));
a9e2aefa 884 if (chi22<10) Split(c);
885 }
886
05c39730 887 if (chi21 > 10 && chi22 > 10 && chi23 > 10) {
a9e2aefa 888//We keep only the combination found (X->cathode 2, Y->cathode 1)
889 for (Int_t ico=0; ico<2; ico++) {
890 if (accepted[ico]) {
891 AliMUONRawCluster cnew;
892 Int_t cath;
893 for (cath=0; cath<2; cath++) {
ba12c242 894 cnew.SetX(cath, Float_t(xm[ico][1]));
895 cnew.SetY(cath, Float_t(ym[ico][0]));
896 cnew.SetZ(cath, fZPlane);
9e993f2a 897 cnew.SetMultiplicity(cath, c->GetMultiplicity(cath));
a9e2aefa 898 for (i=0; i<fMul[cath]; i++) {
0164904a 899 cnew.SetIndex(i, cath, c->GetIndex(i, cath));
fed772f3 900 if (fSegmentationType == 1)
901 fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
902 else
903 fSeg2[cath]->SetPad(fInput->DetElemId(), fIx[i][cath], fIy[i][cath]);
a9e2aefa 904 }
c4a97bcd 905 AliDebug(1,Form("\nRawCluster %d cath %d\n",ico,cath));
906 AliDebug(1,Form("mult_av %d\n",c->GetMultiplicity(cath)));
a9e2aefa 907 FillCluster(&cnew,cath);
908 }
9e993f2a 909 cnew.SetClusterType(cnew.PhysicsContribution());
a9e2aefa 910 AddRawCluster(cnew);
911 fNPeaks++;
912 }
913 }
914 }
915
916// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
917// (4) At least three local maxima on cathode 1 or on cathode 2
918// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
919 } else if (fNLocal[0]>2 || fNLocal[1]>2) {
a9e2aefa 920 Int_t param = fNLocal[0]*fNLocal[1];
f8ffca81 921 Int_t ii;
9825400f 922
39e6d319 923 Float_t ** xm = new Float_t * [param];
924 for (ii=0; ii<param; ii++) xm[ii]=new Float_t [2];
925 Float_t ** ym = new Float_t * [param];
926 for (ii=0; ii<param; ii++) ym[ii]=new Float_t [2];
927 Int_t ** ixm = new Int_t * [param];
928 for (ii=0; ii<param; ii++) ixm[ii]=new Int_t [2];
929 Int_t ** iym = new Int_t * [param];
930 for (ii=0; ii<param; ii++) iym[ii]=new Int_t [2];
f8ffca81 931
a9e2aefa 932 Int_t isec, ico;
933 Float_t dpx, dpy, dx, dy;
934
935 ico=0;
936 for (Int_t im1=0; im1<fNLocal[0]; im1++) {
937 for (Int_t im2=0; im2<fNLocal[1]; im2++) {
938 xm[ico][0]=fX[fIndLocal[im1][0]][0];
939 ym[ico][0]=fY[fIndLocal[im1][0]][0];
940 xm[ico][1]=fX[fIndLocal[im2][1]][1];
941 ym[ico][1]=fY[fIndLocal[im2][1]][1];
942
943 ixm[ico][0]=fIx[fIndLocal[im1][0]][0];
944 iym[ico][0]=fIy[fIndLocal[im1][0]][0];
945 ixm[ico][1]=fIx[fIndLocal[im2][1]][1];
946 iym[ico][1]=fIy[fIndLocal[im2][1]][1];
947 ico++;
948 }
949 }
9825400f 950
a9e2aefa 951 Int_t nIco = ico;
c4a97bcd 952 AliDebug(1,Form("nIco %d\n",nIco));
a9e2aefa 953 for (ico=0; ico<nIco; ico++) {
c4a97bcd 954 AliDebug(1,Form("ico = %d\n",ico));
fed772f3 955 if (fSegmentationType == 1) {
956 isec=fSeg[0]->Sector(ixm[ico][0], iym[ico][0]);
957 dpx=fSeg[0]->Dpx(isec)/2.;
958 } else {
959 isec=fSeg2[0]->Sector(fInput->DetElemId(), ixm[ico][0], iym[ico][0]);
960 dpx=fSeg2[0]->Dpx(fInput->DetElemId(), isec)/2.;
961 }
a9e2aefa 962 dx=TMath::Abs(xm[ico][0]-xm[ico][1]);
fed772f3 963 if (fSegmentationType == 1) {
964 isec=fSeg[1]->Sector(ixm[ico][1], iym[ico][1]);
965 dpy=fSeg[1]->Dpy(isec)/2.;
966 } else {
967 isec=fSeg2[1]->Sector(fInput->DetElemId(), ixm[ico][1], iym[ico][1]);
968 dpy=fSeg2[1]->Dpy(fInput->DetElemId(), isec)/2.;
969 }
a9e2aefa 970 dy=TMath::Abs(ym[ico][0]-ym[ico][1]);
c4a97bcd 971 AliDebug(1,Form("dx %f dpx %f dy %f dpy %f\n",dx,dpx,dy,dpy));
972 AliDebug(1,Form(" X %f Y %f\n",xm[ico][1],ym[ico][0]));
a9e2aefa 973 if ((dx <= dpx) && (dy <= dpy)) {
c4a97bcd 974 AliDebug(1,"ok\n");
a9e2aefa 975 Int_t cath;
976 AliMUONRawCluster cnew;
977 for (cath=0; cath<2; cath++) {
ba12c242 978 cnew.SetX(cath, Float_t(xm[ico][1]));
979 cnew.SetY(cath, Float_t(ym[ico][0]));
980 cnew.SetZ(cath, fZPlane);
9e993f2a 981 cnew.SetMultiplicity(cath, c->GetMultiplicity(cath));
a9e2aefa 982 for (i=0; i<fMul[cath]; i++) {
0164904a 983 cnew.SetIndex(i, cath, c->GetIndex(i, cath));
fed772f3 984 if (fSegmentationType == 1)
985 fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
986 else
987 fSeg2[cath]->SetPad(fInput->DetElemId(), fIx[i][cath], fIy[i][cath]);
a9e2aefa 988 }
989 FillCluster(&cnew,cath);
990 }
9e993f2a 991 cnew.SetClusterType(cnew.PhysicsContribution());
a9e2aefa 992 AddRawCluster(cnew);
993 fNPeaks++;
994 }
995 }
f8ffca81 996 delete [] xm;
997 delete [] ym;
998 delete [] ixm;
999 delete [] iym;
a9e2aefa 1000 }
1001}
1002
e3cba86e 1003void AliMUONClusterFinderVS::FindLocalMaxima(AliMUONRawCluster* /*c*/)
a9e2aefa 1004{
1005// Find all local maxima of a cluster
c4a97bcd 1006 AliDebug(1,"\n Find Local maxima !");
f0d86bc4 1007
a9e2aefa 1008 AliMUONDigit* digt;
1009
1010 Int_t cath, cath1; // loops over cathodes
1011 Int_t i; // loops over digits
1012 Int_t j; // loops over cathodes
1013//
1014// Find local maxima
1015//
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;
1022 }
1023// number of next neighbours and arrays to store them
1024 Int_t nn;
30aaba74 1025 Int_t x[10], y[10];
a9e2aefa 1026// loop over cathodes
1027 for (cath=0; cath<2; cath++) {
1028// loop over cluster digits
1029 for (i=0; i<fMul[cath]; i++) {
fed772f3 1030// get neighbours for that digit and assume that it is local maximum
1031 if (fSegmentationType == 1)
1032 fSeg[cath]->Neighbours(fIx[i][cath], fIy[i][cath], &nn, x, y);
1033 else
1034 fSeg2[cath]->Neighbours(fInput->DetElemId(), fIx[i][cath], fIy[i][cath], &nn, x, y);
1035
a9e2aefa 1036 isLocal[i][cath]=kTRUE;
f0d86bc4 1037 Int_t isec= fSeg[cath]->Sector(fIx[i][cath], fIy[i][cath]);
1038 Float_t a0 = fSeg[cath]->Dpx(isec)*fSeg[cath]->Dpy(isec);
a9e2aefa 1039// loop over next neighbours, if at least one neighbour has higher charger assumption
1040// digit is not local maximum
1041 for (j=0; j<nn; j++) {
30aaba74 1042 if (fHitMap[cath]->TestHit(x[j], y[j])==kEmpty) continue;
1043 digt=(AliMUONDigit*) fHitMap[cath]->GetHit(x[j], y[j]);
fed772f3 1044 Float_t a1;
1045 if (fSegmentationType == 1) {
1046 isec=fSeg[cath]->Sector(x[j], y[j]);
1047 a1 = fSeg[cath]->Dpx(isec)*fSeg[cath]->Dpy(isec);
1048 } else {
1049 isec=fSeg2[cath]->Sector(fInput->DetElemId(), x[j], y[j]);
1050 a1 = fSeg2[cath]->Dpx(fInput->DetElemId(),isec)*fSeg2[cath]->Dpy(fInput->DetElemId(), isec);
1051 }
08a636a8 1052 if (digt->Signal()/a1 > fQ[i][cath]/a0) {
a9e2aefa 1053 isLocal[i][cath]=kFALSE;
1054 break;
1055//
1056// handle special case of neighbouring pads with equal signal
08a636a8 1057 } else if (digt->Signal() == fQ[i][cath]) {
a9e2aefa 1058 if (fNLocal[cath]>0) {
1059 for (Int_t k=0; k<fNLocal[cath]; k++) {
1060 if (x[j]==fIx[fIndLocal[k][cath]][cath]
1061 && y[j]==fIy[fIndLocal[k][cath]][cath])
1062 {
1063 isLocal[i][cath]=kFALSE;
1064 }
1065 } // loop over local maxima
1066 } // are there already local maxima
1067 } // same charge ?
1068 } // loop over next neighbours
1069 if (isLocal[i][cath]) {
1070 fIndLocal[fNLocal[cath]][cath]=i;
1071 fNLocal[cath]++;
1072 }
1073 } // loop over all digits
1074 } // loop over cathodes
07cfabcf 1075
c4a97bcd 1076 AliDebug(1,Form("\n Found %d %d %d %d local Maxima\n",
1077 fNLocal[0], fNLocal[1], fMul[0], fMul[1]));
1078 AliDebug(1,Form("\n Cathode 1 local Maxima %d Multiplicite %d\n",fNLocal[0], fMul[0]));
1079 AliDebug(1,Form(" Cathode 2 local Maxima %d Multiplicite %d\n",fNLocal[1], fMul[1]));
a9e2aefa 1080 Int_t ix, iy, isec;
1081 Float_t dpx, dpy;
1082
1083
1084 if (fNLocal[1]==2 && (fNLocal[0]==1 || fNLocal[0]==0)) {
1085 Int_t iback=fNLocal[0];
1086
1087// Two local maxima on cathode 2 and one maximum on cathode 1
1088// Look for local maxima considering up and down neighbours on the 1st cathode only
1089//
1090// Loop over cluster digits
1091 cath=0;
1092 cath1=1;
1093
1094 for (i=0; i<fMul[cath]; i++) {
fed772f3 1095 if (fSegmentationType == 1) {
f0d86bc4 1096 isec=fSeg[cath]->Sector(fIx[i][cath],fIy[i][cath]);
1097 dpy=fSeg[cath]->Dpy(isec);
1098 dpx=fSeg[cath]->Dpx(isec);
fed772f3 1099 } else {
1100 isec=fSeg2[cath]->Sector(fInput->DetElemId(), fIx[i][cath],fIy[i][cath]);
1101 dpy=fSeg2[cath]->Dpy(fInput->DetElemId(), isec);
1102 dpx=fSeg2[cath]->Dpx(fInput->DetElemId(), isec);
1103 }
a9e2aefa 1104 if (isLocal[i][cath]) continue;
1105// Pad position should be consistent with position of local maxima on the opposite cathode
1106 if ((TMath::Abs(fX[i][cath]-fX[fIndLocal[0][cath1]][cath1]) > dpx/2.) &&
1107 (TMath::Abs(fX[i][cath]-fX[fIndLocal[1][cath1]][cath1]) > dpx/2.))
1108 continue;
1109
1110// get neighbours for that digit and assume that it is local maximum
1111 isLocal[i][cath]=kTRUE;
1112// compare signal to that on the two neighbours on the left and on the right
a9e2aefa 1113// iNN counts the number of neighbours with signal, it should be 1 or 2
1114 Int_t iNN=0;
fed772f3 1115 if (fSegmentationType == 1) {
1116
1117 for (fSeg[cath]->FirstPad(fX[i][cath], fY[i][cath], fZPlane, 0., dpy);
1118 fSeg[cath]->MorePads();
1119 fSeg[cath]->NextPad())
1120 {
1121 ix = fSeg[cath]->Ix();
1122 iy = fSeg[cath]->Iy();
1123 // skip the current pad
1124 if (iy == fIy[i][cath]) continue;
1125
1126 if (fHitMap[cath]->TestHit(ix, iy)!=kEmpty) {
1127 iNN++;
1128 digt=(AliMUONDigit*) fHitMap[cath]->GetHit(ix,iy);
1129 if (digt->Signal() > fQ[i][cath]) isLocal[i][cath]=kFALSE;
1130 }
1131 } // Loop over pad neighbours in y
1132 } else {
f0d86bc4 1133
fed772f3 1134 for (fSeg2[cath]->FirstPad(fInput->DetElemId(), fX[i][cath], fY[i][cath], fZPlane, 0., dpy);
1135 fSeg2[cath]->MorePads(fInput->DetElemId());
1136 fSeg2[cath]->NextPad(fInput->DetElemId()))
1137 {
1138 ix = fSeg2[cath]->Ix();
1139 iy = fSeg2[cath]->Iy();
1140 // skip the current pad
1141 if (iy == fIy[i][cath]) continue;
f0d86bc4 1142
fed772f3 1143 if (fHitMap[cath]->TestHit(ix, iy)!=kEmpty) {
f0d86bc4 1144 iNN++;
1145 digt=(AliMUONDigit*) fHitMap[cath]->GetHit(ix,iy);
08a636a8 1146 if (digt->Signal() > fQ[i][cath]) isLocal[i][cath]=kFALSE;
fed772f3 1147 }
1148 } // Loop over pad neighbours in y
1149 }
a9e2aefa 1150 if (isLocal[i][cath] && iNN>0) {
1151 fIndLocal[fNLocal[cath]][cath]=i;
1152 fNLocal[cath]++;
1153 }
1154 } // loop over all digits
1155// if one additional maximum has been found we are happy
1156// if more maxima have been found restore the previous situation
c4a97bcd 1157 AliDebug(1,Form("\n New search gives %d local maxima for cathode 1 \n",
1158 fNLocal[0]));
1159 AliDebug(1,Form(" %d local maxima for cathode 2 \n",
1160 fNLocal[1]));
a9e2aefa 1161 if (fNLocal[cath]>2) {
1162 fNLocal[cath]=iback;
1163 }
1164
1165 } // 1,2 local maxima
1166
1167 if (fNLocal[0]==2 && (fNLocal[1]==1 || fNLocal[1]==0)) {
1168 Int_t iback=fNLocal[1];
1169
1170// Two local maxima on cathode 1 and one maximum on cathode 2
1171// Look for local maxima considering left and right neighbours on the 2nd cathode only
1172 cath=1;
05c39730 1173 Int_t cath1 = 0;
1174 Float_t eps = 1.e-5;
1175
a9e2aefa 1176//
1177// Loop over cluster digits
1178 for (i=0; i<fMul[cath]; i++) {
fed772f3 1179 if (fSegmentationType == 1) {
f0d86bc4 1180 isec=fSeg[cath]->Sector(fIx[i][cath],fIy[i][cath]);
1181 dpx=fSeg[cath]->Dpx(isec);
1182 dpy=fSeg[cath]->Dpy(isec);
fed772f3 1183 } else {
1184 isec=fSeg2[cath]->Sector(fInput->DetElemId(), fIx[i][cath],fIy[i][cath]);
1185 dpx=fSeg2[cath]->Dpx(fInput->DetElemId(), isec);
1186 dpy=fSeg2[cath]->Dpy(fInput->DetElemId(), isec);
1187 }
1188
a9e2aefa 1189 if (isLocal[i][cath]) continue;
1190// Pad position should be consistent with position of local maxima on the opposite cathode
05c39730 1191 if ((TMath::Abs(fY[i][cath]-fY[fIndLocal[0][cath1]][cath1]) > dpy/2.+eps) &&
1192 (TMath::Abs(fY[i][cath]-fY[fIndLocal[1][cath1]][cath1]) > dpy/2.+eps))
a9e2aefa 1193 continue;
05c39730 1194
a9e2aefa 1195//
1196// get neighbours for that digit and assume that it is local maximum
1197 isLocal[i][cath]=kTRUE;
1198// compare signal to that on the two neighbours on the left and on the right
f0d86bc4 1199
a9e2aefa 1200// iNN counts the number of neighbours with signal, it should be 1 or 2
1201 Int_t iNN=0;
fed772f3 1202 if (fSegmentationType == 1) {
1203 for (fSeg[cath]->FirstPad(fX[i][cath], fY[i][cath], fZPlane, dpx, 0.);
1204 fSeg[cath]->MorePads();
1205 fSeg[cath]->NextPad())
1206 {
1207
1208 ix = fSeg[cath]->Ix();
1209 iy = fSeg[cath]->Iy();
1210
1211 // skip the current pad
1212 if (ix == fIx[i][cath]) continue;
f0d86bc4 1213
fed772f3 1214 if (fHitMap[cath]->TestHit(ix, iy)!=kEmpty) {
f0d86bc4 1215 iNN++;
1216 digt=(AliMUONDigit*) fHitMap[cath]->GetHit(ix,iy);
08a636a8 1217 if (digt->Signal() > fQ[i][cath]) isLocal[i][cath]=kFALSE;
fed772f3 1218 }
1219 } // Loop over pad neighbours in x
1220 } else {
1221 for (fSeg2[cath]->FirstPad(fInput->DetElemId(), fX[i][cath], fY[i][cath], fZPlane, dpx, 0.);
1222 fSeg2[cath]->MorePads(fInput->DetElemId());
1223 fSeg2[cath]->NextPad(fInput->DetElemId()))
1224 {
1225
1226 ix = fSeg2[cath]->Ix();
1227 iy = fSeg2[cath]->Iy();
1228
1229 // skip the current pad
1230 if (ix == fIx[i][cath]) continue;
1231
1232 if (fHitMap[cath]->TestHit(ix, iy)!=kEmpty) {
1233 iNN++;
1234 digt=(AliMUONDigit*) fHitMap[cath]->GetHit(ix,iy);
1235 if (digt->Signal() > fQ[i][cath]) isLocal[i][cath]=kFALSE;
1236 }
1237 } // Loop over pad neighbours in x
1238 }
a9e2aefa 1239 if (isLocal[i][cath] && iNN>0) {
1240 fIndLocal[fNLocal[cath]][cath]=i;
1241 fNLocal[cath]++;
1242 }
1243 } // loop over all digits
1244// if one additional maximum has been found we are happy
1245// if more maxima have been found restore the previous situation
c4a97bcd 1246 AliDebug(1,Form("\n New search gives %d local maxima for cathode 1 \n",fNLocal[0]));
1247 AliDebug(1,Form("\n %d local maxima for cathode 2 \n",fNLocal[1]));
1248 AliDebug(1,Form("\n New search gives %d %d \n",fNLocal[0],fNLocal[1]));
a9e2aefa 1249 if (fNLocal[cath]>2) {
1250 fNLocal[cath]=iback;
1251 }
a9e2aefa 1252 } // 2,1 local maxima
1253}
1254
1255
1256void AliMUONClusterFinderVS::FillCluster(AliMUONRawCluster* c, Int_t flag, Int_t cath)
1257{
1258//
1259// Completes cluster information starting from list of digits
1260//
1261 AliMUONDigit* dig;
802a864d 1262 Float_t x, y, z;
a9e2aefa 1263 Int_t ix, iy;
1264
1265 if (cath==1) {
9e993f2a 1266 c->SetPeakSignal(cath,c->GetPeakSignal(0));
a9e2aefa 1267 } else {
9e993f2a 1268 c->SetPeakSignal(cath,0);
a9e2aefa 1269 }
1270
1271
1272 if (flag) {
ba12c242 1273 c->SetX(cath,0.);
1274 c->SetY(cath,0.);
1275 c->SetCharge(cath,0);
a9e2aefa 1276 }
1277
c4a97bcd 1278 AliDebug(1,Form("\n fPeakSignal %d\n",c->GetPeakSignal(cath)));
9e993f2a 1279 for (Int_t i=0; i<c->GetMultiplicity(cath); i++)
a9e2aefa 1280 {
0164904a 1281 dig= fInput->Digit(cath,c->GetIndex(i,cath));
1282 ix=dig->PadX()+c->GetOffset(i,cath);
08a636a8 1283 iy=dig->PadY();
1284 Int_t q=dig->Signal();
0164904a 1285 if (!flag) q=Int_t(q*c->GetContrib(i,cath));
a9e2aefa 1286// fprintf(stderr,"q %d c->fPeakSignal[ %d ] %d\n",q,cath,c->fPeakSignal[cath]);
08a636a8 1287 if (dig->Physics() >= dig->Signal()) {
0164904a 1288 c->SetPhysics(i,2);
08a636a8 1289 } else if (dig->Physics() == 0) {
0164904a 1290 c->SetPhysics(i,0);
1291 } else c->SetPhysics(i,1);
a9e2aefa 1292//
1293//
c4a97bcd 1294 AliDebug(2,Form("q %d c->fPeakSignal[cath] %d\n",q,c->GetPeakSignal(cath)));
a9e2aefa 1295// peak signal and track list
9e993f2a 1296 if (q>c->GetPeakSignal(cath)) {
1297 c->SetPeakSignal(cath, q);
1298 c->SetTrack(0,dig->Hit());
1299 c->SetTrack(1,dig->Track(0));
1300 c->SetTrack(2,dig->Track(1));
a9e2aefa 1301// fprintf(stderr," c->fTracks[0] %d c->fTracks[1] %d\n",dig->fHit,dig->fTracks[0]);
1302 }
1303//
1304 if (flag) {
fed772f3 1305 if (fSegmentationType == 1)
f0d86bc4 1306 fSeg[cath]->GetPadC(ix, iy, x, y, z);
fed772f3 1307 else
1308 fSeg2[cath]->GetPadC(fInput->DetElemId(), ix, iy, x, y, z);
1309
ba12c242 1310 c->AddX(cath, q*x);
1311 c->AddY(cath, q*y);
1312 c->AddCharge(cath, q);
a9e2aefa 1313 }
1314 } // loop over digits
c4a97bcd 1315 AliDebug(1," fin du cluster c\n");
a9e2aefa 1316
1317
1318 if (flag) {
ba12c242 1319 c->SetX(cath, c->GetX(cath)/c->GetCharge(cath));
07cfabcf 1320// Force on anod
fed772f3 1321 if (fSegmentationType == 1)
1322 c->SetX(cath, fSeg[cath]->GetAnod(c->GetX(cath)));
1323 else
1324 c->SetX(cath, fSeg2[cath]->GetAnod(fInput->DetElemId(), c->GetX(cath)));
ba12c242 1325 c->SetY(cath, c->GetY(cath)/c->GetCharge(cath));
a9e2aefa 1326//
1327// apply correction to the coordinate along the anode wire
1328//
ba12c242 1329 x=c->GetX(cath);
1330 y=c->GetY(cath);
fed772f3 1331 TF1* cogCorr;
1332 Int_t isec;
1333 if (fSegmentationType == 1) {
1334 fSeg[cath]->GetPadI(x, y, fZPlane, ix, iy);
1335 fSeg[cath]->GetPadC(ix, iy, x, y, z);
1336 isec=fSeg[cath]->Sector(ix,iy);
1337 cogCorr = fSeg[cath]->CorrFunc(isec-1);
1338 } else {
1339 fSeg2[cath]->GetPadI(fInput->DetElemId(), x, y, fZPlane, ix, iy);
1340 fSeg2[cath]->GetPadC(fInput->DetElemId(), ix, iy, x, y, z);
1341 isec=fSeg2[cath]->Sector(fInput->DetElemId(), ix,iy);
1342 cogCorr = fSeg2[cath]->CorrFunc(fInput->DetElemId(), isec-1);
1343 }
a9e2aefa 1344
1345 if (cogCorr) {
fed772f3 1346 Float_t yOnPad;
1347 if (fSegmentationType == 1)
1348 yOnPad=(c->GetY(cath)-y)/fSeg[cath]->Dpy(isec);
1349 else
1350 yOnPad=(c->GetY(cath)-y)/fSeg2[cath]->Dpy(fInput->DetElemId(), isec);
1351
1352 c->SetY(cath, c->GetY(cath)-cogCorr->Eval(yOnPad, 0, 0));
a9e2aefa 1353 }
1354 }
1355}
1356
1357void AliMUONClusterFinderVS::FillCluster(AliMUONRawCluster* c, Int_t cath)
1358{
1359//
1360// Completes cluster information starting from list of digits
1361//
1362 static Float_t dr0;
1363
1364 AliMUONDigit* dig;
1365
1366 if (cath==0) {
1367 dr0 = 10000;
1368 }
1369
802a864d 1370 Float_t xpad, ypad, zpad;
a9e2aefa 1371 Float_t dx, dy, dr;
1372
9e993f2a 1373 for (Int_t i=0; i<c->GetMultiplicity(cath); i++)
a9e2aefa 1374 {
0164904a 1375 dig = fInput->Digit(cath,c->GetIndex(i,cath));
fed772f3 1376 if (fSegmentationType == 1)
1377 fSeg[cath]->
1378 GetPadC(dig->PadX(),dig->PadY(),xpad,ypad, zpad);
1379 else
1380 fSeg2[cath]->
1381 GetPadC(fInput->DetElemId(),dig->PadX(),dig->PadY(),xpad,ypad, zpad);
c4a97bcd 1382 AliDebug(1,Form("x %f y %f cx %f cy %f\n",xpad,ypad,c->GetX(0),c->GetY(0)));
ba12c242 1383 dx = xpad - c->GetX(0);
1384 dy = ypad - c->GetY(0);
a9e2aefa 1385 dr = TMath::Sqrt(dx*dx+dy*dy);
1386
1387 if (dr < dr0) {
1388 dr0 = dr;
c4a97bcd 1389 AliDebug(1,Form(" dr %f\n",dr));
08a636a8 1390 Int_t q=dig->Signal();
1391 if (dig->Physics() >= dig->Signal()) {
0164904a 1392 c->SetPhysics(i,2);
08a636a8 1393 } else if (dig->Physics() == 0) {
0164904a 1394 c->SetPhysics(i,0);
1395 } else c->SetPhysics(i,1);
9e993f2a 1396 c->SetPeakSignal(cath,q);
1397 c->SetTrack(0,dig->Hit());
1398 c->SetTrack(1,dig->Track(0));
1399 c->SetTrack(2,dig->Track(1));
c4a97bcd 1400 AliDebug(1,Form(" c->fTracks[0] %d c->fTracks[1] %d\n",dig->Hit(),
1401 dig->Track(0)));
a9e2aefa 1402 }
1403//
1404 } // loop over digits
1405
1406// apply correction to the coordinate along the anode wire
07cfabcf 1407// Force on anod
fed772f3 1408 if (fSegmentationType == 1)
1409 c->SetX(cath,fSeg[cath]->GetAnod(c->GetX(cath)));
1410 else
1411 c->SetX(cath,fSeg2[cath]->GetAnod(fInput->DetElemId(), c->GetX(cath)));
a9e2aefa 1412}
1413
1414void AliMUONClusterFinderVS::FindCluster(Int_t i, Int_t j, Int_t cath, AliMUONRawCluster &c){
f0d86bc4 1415
1416
a9e2aefa 1417//
f0d86bc4 1418// Find a super cluster on both cathodes
a9e2aefa 1419//
1420//
1421// Add i,j as element of the cluster
1422//
f0d86bc4 1423
30aaba74 1424 Int_t idx = fHitMap[cath]->GetHitIndex(i,j);
1425 AliMUONDigit* dig = (AliMUONDigit*) fHitMap[cath]->GetHit(i,j);
08a636a8 1426 Int_t q=dig->Signal();
1427 Int_t theX=dig->PadX();
1428 Int_t theY=dig->PadY();
f0d86bc4 1429
9e993f2a 1430 if (q > TMath::Abs(c.GetPeakSignal(0)) && q > TMath::Abs(c.GetPeakSignal(1))) {
1431 c.SetPeakSignal(cath,q);
1432 c.SetTrack(0,dig->Hit());
1433 c.SetTrack(1,dig->Track(0));
1434 c.SetTrack(2,dig->Track(1));
a9e2aefa 1435 }
1436
1437//
1438// Make sure that list of digits is ordered
1439//
9e993f2a 1440 Int_t mu=c.GetMultiplicity(cath);
0164904a 1441 c.SetIndex(mu, cath, idx);
a9e2aefa 1442
08a636a8 1443 if (dig->Physics() >= dig->Signal()) {
0164904a 1444 c.SetPhysics(mu,2);
08a636a8 1445 } else if (dig->Physics() == 0) {
0164904a 1446 c.SetPhysics(mu,0);
1447 } else c.SetPhysics(mu,1);
f0d86bc4 1448
1449
a9e2aefa 1450 if (mu > 0) {
f0d86bc4 1451 for (Int_t ind = mu-1; ind >= 0; ind--) {
0164904a 1452 Int_t ist=c.GetIndex(ind,cath);
08a636a8 1453 Int_t ql=fInput->Digit(cath, ist)->Signal();
1454 Int_t ix=fInput->Digit(cath, ist)->PadX();
1455 Int_t iy=fInput->Digit(cath, ist)->PadY();
f0d86bc4 1456
a9e2aefa 1457 if (q>ql || (q==ql && theX > ix && theY < iy)) {
0164904a 1458 c.SetIndex(ind, cath, idx);
1459 c.SetIndex(ind+1, cath, ist);
a9e2aefa 1460 } else {
f0d86bc4 1461
a9e2aefa 1462 break;
1463 }
1464 }
1465 }
f0d86bc4 1466
9e993f2a 1467 c.SetMultiplicity(cath, c.GetMultiplicity(cath)+1);
1468 if (c.GetMultiplicity(cath) >= 50 ) {
c4a97bcd 1469 AliDebug(1,Form("FindCluster - multiplicity >50 %d \n",c.GetMultiplicity(0)));
9e993f2a 1470 c.SetMultiplicity(cath, 49);
a9e2aefa 1471 }
1472
1473// Prepare center of gravity calculation
802a864d 1474 Float_t x, y, z;
fed772f3 1475 if (fSegmentationType == 1)
1476 fSeg[cath]->GetPadC(i, j, x, y, z);
1477 else
1478 fSeg2[cath]->GetPadC(fInput->DetElemId(), i, j, x, y, z);
ba12c242 1479 c.AddX(cath,q*x);
1480 c.AddY(cath,q*y);
1481 c.AddCharge(cath,q);
f0d86bc4 1482//
1483// Flag hit as "taken"
30aaba74 1484 fHitMap[cath]->FlagHit(i,j);
a9e2aefa 1485//
1486// Now look recursively for all neighbours and pad hit on opposite cathode
1487//
1488// Loop over neighbours
1489 Int_t ix,iy;
f0d86bc4 1490 ix=iy=0;
a9e2aefa 1491 Int_t nn;
30aaba74 1492 Int_t xList[10], yList[10];
fed772f3 1493 if (fSegmentationType == 1)
1494 fSeg[cath]->Neighbours(i,j,&nn,xList,yList);
1495 else
1496 fSeg2[cath]->Neighbours(fInput->DetElemId(), i,j,&nn,xList,yList);
a9e2aefa 1497 for (Int_t in=0; in<nn; in++) {
1498 ix=xList[in];
1499 iy=yList[in];
f0d86bc4 1500
1501 if (fHitMap[cath]->TestHit(ix,iy)==kUnused) {
c4a97bcd 1502 AliDebug(2,Form("\n Neighbours %d %d %d", cath, ix, iy));
f0d86bc4 1503 FindCluster(ix, iy, cath, c);
1504 }
1505
1506 }
1507 Int_t nOpp=0;
1508 Int_t iXopp[50], iYopp[50];
1509
a9e2aefa 1510// Neighbours on opposite cathode
1511// Take into account that several pads can overlap with the present pad
fed772f3 1512 Int_t isec;
1513 if (fSegmentationType == 1)
1514 isec=fSeg[cath]->Sector(i,j);
1515 else
1516 isec=fSeg2[cath]->Sector(fInput->DetElemId(), i,j);
1517
a9e2aefa 1518 Int_t iop;
f0d86bc4 1519 Float_t dx, dy;
1520
fed772f3 1521 if (fSegmentationType == 1) {
1522 if (cath==0) {
f0d86bc4 1523 iop = 1;
1524 dx = (fSeg[cath]->Dpx(isec))/2.;
1525 dy = 0.;
fed772f3 1526 } else {
f0d86bc4 1527 iop = 0;
1528 dx = 0.;
1529 dy = (fSeg[cath]->Dpy(isec))/2;
fed772f3 1530 }
1531
1532
1533
1534 // loop over pad neighbours on opposite cathode
1535 for (fSeg[iop]->FirstPad(x, y, fZPlane, dx, dy);
1536 fSeg[iop]->MorePads();
1537 fSeg[iop]->NextPad())
1538 {
f0d86bc4 1539
fed772f3 1540 ix = fSeg[iop]->Ix(); iy = fSeg[iop]->Iy();
1541 AliDebug(2,Form("\n ix, iy: %f %f %f %d %d %d", x,y,z,ix, iy, fSector));
1542 if (fHitMap[iop]->TestHit(ix,iy)==kUnused){
f0d86bc4 1543 iXopp[nOpp]=ix;
1544 iYopp[nOpp++]=iy;
c4a97bcd 1545 AliDebug(2,Form("\n Opposite %d %d %d", iop, ix, iy));
fed772f3 1546 }
f0d86bc4 1547
fed772f3 1548 } // Loop over pad neighbours
1549 // This had to go outside the loop since recursive calls inside the iterator are not possible
1550 //
1551 Int_t jopp;
1552 for (jopp=0; jopp<nOpp; jopp++) {
1553 if (fHitMap[iop]->TestHit(iXopp[jopp],iYopp[jopp]) == kUnused)
1554 FindCluster(iXopp[jopp], iYopp[jopp], iop, c);
1555 }
1556 } else {
1557
1558 if (cath==0) {
1559 iop = 1;
1560 dx = (fSeg2[cath]->Dpx(fInput->DetElemId(), isec))/2.;
1561 dy = 0.;
1562 } else {
1563 iop = 0;
1564 dx = 0.;
1565 dy = (fSeg2[cath]->Dpy(fInput->DetElemId(), isec))/2;
1566 }
1567
1568
1569
1570 // loop over pad neighbours on opposite cathode
1571 for (fSeg2[iop]->FirstPad(fInput->DetElemId(), x, y, fZPlane, dx, dy);
1572 fSeg2[iop]->MorePads(fInput->DetElemId());
1573 fSeg2[iop]->NextPad(fInput->DetElemId()))
1574 {
1575
1576 ix = fSeg2[iop]->Ix(); iy = fSeg2[iop]->Iy();
1577 AliDebug(2,Form("\n ix, iy: %f %f %f %d %d %d", x,y,z,ix, iy, fSector));
1578 if (fHitMap[iop]->TestHit(ix,iy)==kUnused){
1579 iXopp[nOpp]=ix;
1580 iYopp[nOpp++]=iy;
1581 AliDebug(2,Form("\n Opposite %d %d %d", iop, ix, iy));
1582 }
1583
1584 } // Loop over pad neighbours
1585 // This had to go outside the loop since recursive calls inside the iterator are not possible
1586 //
1587 Int_t jopp;
1588 for (jopp=0; jopp<nOpp; jopp++) {
f0d86bc4 1589 if (fHitMap[iop]->TestHit(iXopp[jopp],iYopp[jopp]) == kUnused)
fed772f3 1590 FindCluster(iXopp[jopp], iYopp[jopp], iop, c);
1591 }
a9e2aefa 1592 }
1593}
1594
1595//_____________________________________________________________________________
1596
1597void AliMUONClusterFinderVS::FindRawClusters()
1598{
1599 //
1600 // MUON cluster finder from digits -- finds neighbours on both cathodes and
1601 // fills the tree with raw clusters
1602 //
1603
4da78c65 1604 ResetRawClusters();
f0d86bc4 1605// Return if no input datad available
30aaba74 1606 if (!fInput->NDigits(0) && !fInput->NDigits(1)) return;
a9e2aefa 1607
fed772f3 1608 if (fSegmentationType == 1) {
1609 fSeg[0] = fInput->Segmentation(0);
1610 fSeg[1] = fInput->Segmentation(1);
f0d86bc4 1611
fed772f3 1612 fHitMap[0] = new AliMUONHitMapA1(fSeg[0], fInput->Digits(0));
1613 fHitMap[1] = new AliMUONHitMapA1(fSeg[1], fInput->Digits(1));
a9e2aefa 1614
fed772f3 1615 } else {
1616 fSeg2[0] = fInput->Segmentation2(0);
1617 fSeg2[1] = fInput->Segmentation2(1);
1618
1619 fHitMap[0] = new AliMUONHitMapA1(fInput->DetElemId(), fSeg2[0], fInput->Digits(0));
1620 fHitMap[1] = new AliMUONHitMapA1(fInput->DetElemId(), fSeg2[1], fInput->Digits(1));
1621 }
f0d86bc4 1622
a9e2aefa 1623 AliMUONDigit *dig;
1624
1625 Int_t ndig, cath;
1626 Int_t nskip=0;
1627 Int_t ncls=0;
30aaba74 1628 fHitMap[0]->FillHits();
1629 fHitMap[1]->FillHits();
a9e2aefa 1630//
1631// Outer Loop over Cathodes
1632 for (cath=0; cath<2; cath++) {
30aaba74 1633 for (ndig=0; ndig<fInput->NDigits(cath); ndig++) {
1634 dig = fInput->Digit(cath, ndig);
08a636a8 1635 Int_t i=dig->PadX();
1636 Int_t j=dig->PadY();
30aaba74 1637 if (fHitMap[cath]->TestHit(i,j)==kUsed ||fHitMap[0]->TestHit(i,j)==kEmpty) {
a9e2aefa 1638 nskip++;
1639 continue;
1640 }
c4a97bcd 1641 AliDebug(1,Form("\n CATHODE %d CLUSTER %d\n",cath,ncls));
a9e2aefa 1642 AliMUONRawCluster c;
9e993f2a 1643 c.SetMultiplicity(0, 0);
1644 c.SetMultiplicity(1, 0);
1645 c.SetPeakSignal(cath,dig->Signal());
1646 c.SetTrack(0, dig->Hit());
1647 c.SetTrack(1, dig->Track(0));
1648 c.SetTrack(2, dig->Track(1));
a9e2aefa 1649 // tag the beginning of cluster list in a raw cluster
3b5272e3 1650 c.SetNcluster(0,-1);
f0d86bc4 1651 Float_t xcu, ycu;
fed772f3 1652 if (fSegmentationType == 1) {
1653 fSeg[cath]->GetPadC(i,j,xcu, ycu, fZPlane);
1654 fSector= fSeg[cath]->Sector(i,j)/100;
1655 } else {
1656 fSeg2[cath]->GetPadC(fInput->DetElemId(), i,j,xcu, ycu, fZPlane);
1657 fSector= fSeg2[cath]->Sector(fInput->DetElemId(), i,j)/100;
1658 }
c4a97bcd 1659 AliDebug(1,Form("\n New Seed %d %d ", i,j));
f36a6c8b 1660
1661
a9e2aefa 1662 FindCluster(i,j,cath,c);
f0d86bc4 1663// ^^^^^^^^^^^^^^^^^^^^^^^^
a9e2aefa 1664 // center of gravity
ba12c242 1665 if (c.GetX(0)!=0.) c.SetX(0, c.GetX(0)/c.GetCharge(0)); // c.fX[0] /= c.fQ[0];
07cfabcf 1666// Force on anod
fed772f3 1667 if (fSegmentationType == 1)
1668 c.SetX(0,fSeg[0]->GetAnod(c.GetX(0)));
1669 else
1670 c.SetX(0,fSeg2[0]->GetAnod(fInput->DetElemId(), c.GetX(0)));
ba12c242 1671 if (c.GetY(0)!=0.) c.SetY(0, c.GetY(0)/c.GetCharge(0)); // c.fY[0] /= c.fQ[0];
f36a6c8b 1672
ba12c242 1673 if(c.GetCharge(1)!=0.) c.SetX(1, c.GetX(1)/c.GetCharge(1)); // c.fX[1] /= c.fQ[1];
f36a6c8b 1674
1675 // Force on anod
fed772f3 1676 if (fSegmentationType == 1)
1677 c.SetX(1, fSeg[0]->GetAnod(c.GetX(1)));
1678 else
1679 c.SetX(1, fSeg2[0]->GetAnod(fInput->DetElemId(),c.GetX(1)));
ba12c242 1680 if(c.GetCharge(1)!=0.) c.SetY(1, c.GetY(1)/c.GetCharge(1));// c.fY[1] /= c.fQ[1];
3e1872ed 1681
ba12c242 1682 c.SetZ(0, fZPlane);
1683 c.SetZ(1, fZPlane);
3e1872ed 1684
c4a97bcd 1685 AliDebug(1,Form("\n Cathode 1 multiplicite %d X(CG) %f Y(CG) %f\n",
1686 c.GetMultiplicity(0),c.GetX(0),c.GetY(0)));
1687 AliDebug(1,Form(" Cathode 2 multiplicite %d X(CG) %f Y(CG) %f\n",
1688 c.GetMultiplicity(1),c.GetX(1),c.GetY(1)));
a9e2aefa 1689// Analyse cluster and decluster if necessary
1690//
1691 ncls++;
3b5272e3 1692 c.SetNcluster(1,fNRawClusters);
9e993f2a 1693 c.SetClusterType(c.PhysicsContribution());
a9e2aefa 1694
1695 fNPeaks=0;
1696//
1697//
1698 Decluster(&c);
a9e2aefa 1699//
1700// reset Cluster object
f8ffca81 1701 { // begin local scope
0164904a 1702 for (int k=0;k<c.GetMultiplicity(0);k++) c.SetIndex(k, 0, 0);
f8ffca81 1703 } // end local scope
a9e2aefa 1704
f8ffca81 1705 { // begin local scope
0164904a 1706 for (int k=0;k<c.GetMultiplicity(1);k++) c.SetIndex(k, 1, 0);
f8ffca81 1707 } // end local scope
1708
9e993f2a 1709 c.SetMultiplicity(0,0);
1710 c.SetMultiplicity(1,0);
a9e2aefa 1711
1712
1713 } // end loop ndig
1714 } // end loop cathodes
30aaba74 1715 delete fHitMap[0];
1716 delete fHitMap[1];
a9e2aefa 1717}
1718
1719Float_t AliMUONClusterFinderVS::SingleMathiesonFit(AliMUONRawCluster *c, Int_t cath)
1720{
f0d86bc4 1721// Performs a single Mathieson fit on one cathode
1722//
19dd5b2f 1723 Double_t arglist[20];
1724 Int_t ierflag=0;
9825400f 1725 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
a9e2aefa 1726
9825400f 1727 clusterInput.Fitter()->SetFCN(fcnS1);
1728 clusterInput.Fitter()->mninit(2,10,7);
19dd5b2f 1729 clusterInput.Fitter()->SetPrintLevel(-1+fDebugLevel);
1730 arglist[0]=-1;
1731 clusterInput.Fitter()->mnexcm("SET NOW", arglist, 0, ierflag);
a9e2aefa 1732// Set starting values
1733 static Double_t vstart[2];
ba12c242 1734 vstart[0]=c->GetX(1);
1735 vstart[1]=c->GetY(0);
a9e2aefa 1736
1737
1738// lower and upper limits
1739 static Double_t lower[2], upper[2];
fed772f3 1740 Int_t ix,iy, isec;
1741 if (fSegmentationType == 1) {
1742 fSeg[cath]->GetPadI(c->GetX(cath), c->GetY(cath), fZPlane, ix, iy);
1743 isec=fSeg[cath]->Sector(ix, iy);
1744
1745 lower[0]=vstart[0]-fSeg[cath]->Dpx(isec)/2;
1746 lower[1]=vstart[1]-fSeg[cath]->Dpy(isec)/2;
a9e2aefa 1747
fed772f3 1748 upper[0]=lower[0]+fSeg[cath]->Dpx(isec);
1749 upper[1]=lower[1]+fSeg[cath]->Dpy(isec);
1750
1751 } else {
1752 fSeg2[cath]->GetPadI(fInput->DetElemId(), c->GetX(cath), c->GetY(cath), fZPlane, ix, iy);
1753 isec=fSeg2[cath]->Sector(fInput->DetElemId(), ix, iy);
1754
1755 lower[0]=vstart[0]-fSeg2[cath]->Dpx(fInput->DetElemId(), isec)/2;
1756 lower[1]=vstart[1]-fSeg2[cath]->Dpy(fInput->DetElemId(), isec)/2;
a9e2aefa 1757
fed772f3 1758 upper[0]=lower[0]+fSeg2[cath]->Dpx(fInput->DetElemId(), isec);
1759 upper[1]=lower[1]+fSeg2[cath]->Dpy(fInput->DetElemId(), isec);
1760 }
1761
a9e2aefa 1762// step sizes
1763 static Double_t step[2]={0.0005, 0.0005};
1764
9825400f 1765 clusterInput.Fitter()->mnparm(0,"x1",vstart[0],step[0],lower[0],upper[0],ierflag);
1766 clusterInput.Fitter()->mnparm(1,"y1",vstart[1],step[1],lower[1],upper[1],ierflag);
a9e2aefa 1767// ready for minimisation
a9e2aefa 1768 arglist[0]= -1;
1769 arglist[1]= 0;
1770
9825400f 1771 clusterInput.Fitter()->mnexcm("SET NOGR", arglist, 0, ierflag);
1772 clusterInput.Fitter()->mnexcm("MIGRAD", arglist, 0, ierflag);
4da78c65 1773 // clusterInput.Fitter()->mnexcm("EXIT" , arglist, 0, ierflag);
a9e2aefa 1774 Double_t fmin, fedm, errdef;
1775 Int_t npari, nparx, istat;
1776
9825400f 1777 clusterInput.Fitter()->mnstat(fmin, fedm, errdef, npari, nparx, istat);
a9e2aefa 1778 fFitStat=istat;
1779
1780// Print results
1781// Get fitted parameters
1782 Double_t xrec, yrec;
1783 TString chname;
1784 Double_t epxz, b1, b2;
1785 Int_t ierflg;
9825400f 1786 clusterInput.Fitter()->mnpout(0, chname, xrec, epxz, b1, b2, ierflg);
1787 clusterInput.Fitter()->mnpout(1, chname, yrec, epxz, b1, b2, ierflg);
a9e2aefa 1788 fXFit[cath]=xrec;
1789 fYFit[cath]=yrec;
1790 return fmin;
1791}
1792
e3cba86e 1793Float_t AliMUONClusterFinderVS::CombiSingleMathiesonFit(AliMUONRawCluster * /*c*/)
a9e2aefa 1794{
1795// Perform combined Mathieson fit on both cathode planes
1796//
19dd5b2f 1797 Double_t arglist[20];
1798 Int_t ierflag=0;
9825400f 1799 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
1800 clusterInput.Fitter()->SetFCN(fcnCombiS1);
1801 clusterInput.Fitter()->mninit(2,10,7);
19dd5b2f 1802 clusterInput.Fitter()->SetPrintLevel(-1+fDebugLevel);
1803 arglist[0]=-1;
1804 clusterInput.Fitter()->mnexcm("SET NOW", arglist, 0, ierflag);
a9e2aefa 1805 static Double_t vstart[2];
1806 vstart[0]=fXInit[0];
1807 vstart[1]=fYInit[0];
1808
1809
1810// lower and upper limits
f0d86bc4 1811 static Float_t lower[2], upper[2];
a9e2aefa 1812 Int_t ix,iy,isec;
fed772f3 1813 Float_t dpy, dpx;
1814
1815 if (fSegmentationType == 1) {
1816 fSeg[0]->GetPadI(fXInit[0], fYInit[0], fZPlane, ix, iy);
1817 isec=fSeg[0]->Sector(ix, iy);
1818 dpy=fSeg[0]->Dpy(isec);
1819 fSeg[1]->GetPadI(fXInit[0], fYInit[0], fZPlane, ix, iy);
1820 isec=fSeg[1]->Sector(ix, iy);
1821 dpx=fSeg[1]->Dpx(isec);
1822
1823 } else {
1824 fSeg2[0]->GetPadI(fInput->DetElemId(), fXInit[0], fYInit[0], fZPlane, ix, iy);
1825 isec=fSeg2[0]->Sector(fInput->DetElemId(), ix, iy);
1826 dpy=fSeg2[0]->Dpy(fInput->DetElemId(), isec);
1827 fSeg2[1]->GetPadI(fInput->DetElemId(), fXInit[0], fYInit[0], fZPlane, ix, iy);
1828 isec=fSeg2[1]->Sector(fInput->DetElemId(), ix, iy);
1829 dpx=fSeg2[1]->Dpx(fInput->DetElemId(), isec);
a9e2aefa 1830
fed772f3 1831 }
f0d86bc4 1832 Int_t icount;
1833 Float_t xdum, ydum, zdum;
a9e2aefa 1834
f0d86bc4 1835// Find save upper and lower limits
a9e2aefa 1836
f0d86bc4 1837 icount = 0;
fed772f3 1838 if (fSegmentationType == 1) {
1839 for (fSeg[1]->FirstPad(fXInit[0], fYInit[0], fZPlane, dpx, 0.);
1840 fSeg[1]->MorePads();
1841 fSeg[1]->NextPad())
1842 {
1843 ix=fSeg[1]->Ix(); iy=fSeg[1]->Iy();
1844 fSeg[1]->GetPadC(ix,iy, upper[0], ydum, zdum);
1845 if (icount ==0) lower[0]=upper[0];
1846 icount++;
1847 }
1848 } else {
1849 for (fSeg2[1]->FirstPad(fInput->DetElemId(),fXInit[0], fYInit[0], fZPlane, dpx, 0.);
1850 fSeg2[1]->MorePads(fInput->DetElemId());
1851 fSeg2[1]->NextPad(fInput->DetElemId()))
1852 {
1853 ix=fSeg2[1]->Ix(); iy=fSeg2[1]->Iy();
1854 fSeg2[1]->GetPadC(fInput->DetElemId(), ix,iy, upper[0], ydum, zdum);
1855 if (icount ==0) lower[0]=upper[0];
1856 icount++;
1857 }
f0d86bc4 1858 }
f0d86bc4 1859 if (lower[0]>upper[0]) {xdum=lower[0]; lower[0]=upper[0]; upper[0]=xdum;}
1860
1861 icount=0;
c4a97bcd 1862 AliDebug(1,Form("\n single y %f %f", fXInit[0], fYInit[0]));
f0d86bc4 1863
fed772f3 1864 if (fSegmentationType == 1) {
1865 for (fSeg[0]->FirstPad(fXInit[0], fYInit[0], fZPlane, 0., dpy);
1866 fSeg[0]->MorePads();
1867 fSeg[0]->NextPad())
1868 {
1869 ix=fSeg[0]->Ix(); iy=fSeg[0]->Iy();
1870 fSeg[0]->GetPadC(ix,iy,xdum,upper[1],zdum);
1871 if (icount ==0) lower[1]=upper[1];
1872 icount++;
1873 AliDebug(1,Form("\n upper lower %d %f %f", icount, upper[1], lower[1]));
1874 }
1875 } else {
1876 for (fSeg2[0]->FirstPad(fInput->DetElemId(), fXInit[0], fYInit[0], fZPlane, 0., dpy);
1877 fSeg2[0]->MorePads(fInput->DetElemId());
1878 fSeg2[0]->NextPad(fInput->DetElemId()))
1879 {
1880 ix=fSeg2[0]->Ix(); iy=fSeg2[0]->Iy();
1881 fSeg2[0]->GetPadC(fInput->DetElemId(), ix,iy,xdum,upper[1],zdum);
1882 if (icount ==0) lower[1]=upper[1];
1883 icount++;
1884 AliDebug(1,Form("\n upper lower %d %f %f", icount, upper[1], lower[1]));
1885 }
f0d86bc4 1886 }
f0d86bc4 1887 if (lower[1]>upper[1]) {xdum=lower[1]; lower[1]=upper[1]; upper[1]=xdum;}
1888
a9e2aefa 1889// step sizes
1890 static Double_t step[2]={0.00001, 0.0001};
1891
9825400f 1892 clusterInput.Fitter()->mnparm(0,"x1",vstart[0],step[0],lower[0],upper[0],ierflag);
1893 clusterInput.Fitter()->mnparm(1,"y1",vstart[1],step[1],lower[1],upper[1],ierflag);
a9e2aefa 1894// ready for minimisation
a9e2aefa 1895 arglist[0]= -1;
1896 arglist[1]= 0;
1897
9825400f 1898 clusterInput.Fitter()->mnexcm("SET NOGR", arglist, 0, ierflag);
1899 clusterInput.Fitter()->mnexcm("MIGRAD", arglist, 0, ierflag);
4da78c65 1900 // clusterInput.Fitter()->mnexcm("EXIT" , arglist, 0, ierflag);
a9e2aefa 1901 Double_t fmin, fedm, errdef;
1902 Int_t npari, nparx, istat;
1903
9825400f 1904 clusterInput.Fitter()->mnstat(fmin, fedm, errdef, npari, nparx, istat);
a9e2aefa 1905 fFitStat=istat;
1906
1907// Print results
1908// Get fitted parameters
1909 Double_t xrec, yrec;
1910 TString chname;
1911 Double_t epxz, b1, b2;
1912 Int_t ierflg;
9825400f 1913 clusterInput.Fitter()->mnpout(0, chname, xrec, epxz, b1, b2, ierflg);
1914 clusterInput.Fitter()->mnpout(1, chname, yrec, epxz, b1, b2, ierflg);
a9e2aefa 1915 fXFit[0]=xrec;
1916 fYFit[0]=yrec;
1917 return fmin;
1918}
1919
e3cba86e 1920Bool_t AliMUONClusterFinderVS::DoubleMathiesonFit(AliMUONRawCluster * /*c*/, Int_t cath)
a9e2aefa 1921{
f0d86bc4 1922// Performs a double Mathieson fit on one cathode
1923//
1924
a9e2aefa 1925//
1926// Initialise global variables for fit
19dd5b2f 1927 Double_t arglist[20];
1928 Int_t ierflag=0;
9825400f 1929 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
1930 clusterInput.Fitter()->SetFCN(fcnS2);
1931 clusterInput.Fitter()->mninit(5,10,7);
19dd5b2f 1932 clusterInput.Fitter()->SetPrintLevel(-1+fDebugLevel);
1933 arglist[0]=-1;
1934 clusterInput.Fitter()->mnexcm("SET NOW", arglist, 0, ierflag);
a9e2aefa 1935// Set starting values
1936 static Double_t vstart[5];
1937 vstart[0]=fX[fIndLocal[0][cath]][cath];
1938 vstart[1]=fY[fIndLocal[0][cath]][cath];
1939 vstart[2]=fX[fIndLocal[1][cath]][cath];
1940 vstart[3]=fY[fIndLocal[1][cath]][cath];
1941 vstart[4]=Float_t(fQ[fIndLocal[0][cath]][cath])/
1942 Float_t(fQ[fIndLocal[0][cath]][cath]+fQ[fIndLocal[1][cath]][cath]);
1943// lower and upper limits
f0d86bc4 1944 static Float_t lower[5], upper[5];
fed772f3 1945 Int_t isec;
1946
1947 if (fSegmentationType == 1) {
1948 isec=fSeg[cath]->Sector(fIx[fIndLocal[0][cath]][cath], fIy[fIndLocal[0][cath]][cath]);
1949 lower[0]=vstart[0]-fSeg[cath]->Dpx(isec);
1950 lower[1]=vstart[1]-fSeg[cath]->Dpy(isec);
1951
1952 upper[0]=lower[0]+2.*fSeg[cath]->Dpx(isec);
1953 upper[1]=lower[1]+2.*fSeg[cath]->Dpy(isec);
1954
1955 isec=fSeg[cath]->Sector(fIx[fIndLocal[1][cath]][cath], fIy[fIndLocal[1][cath]][cath]);
1956 lower[2]=vstart[2]-fSeg[cath]->Dpx(isec)/2;
1957 lower[3]=vstart[3]-fSeg[cath]->Dpy(isec)/2;
a9e2aefa 1958
fed772f3 1959 upper[2]=lower[2]+fSeg[cath]->Dpx(isec);
1960 upper[3]=lower[3]+fSeg[cath]->Dpy(isec);
1961
1962 } else {
1963 isec=fSeg2[cath]->Sector(fInput->DetElemId(),fIx[fIndLocal[0][cath]][cath],
1964 fIy[fIndLocal[0][cath]][cath]);
1965 lower[0]=vstart[0]-fSeg2[cath]->Dpx(fInput->DetElemId(),isec);
1966 lower[1]=vstart[1]-fSeg2[cath]->Dpy(fInput->DetElemId(),isec);
a9e2aefa 1967
fed772f3 1968 upper[0]=lower[0]+2.*fSeg2[cath]->Dpx(fInput->DetElemId(),isec);
1969 upper[1]=lower[1]+2.*fSeg2[cath]->Dpy(fInput->DetElemId(),isec);
a9e2aefa 1970
fed772f3 1971 isec=fSeg2[cath]->Sector(fInput->DetElemId(),fIx[fIndLocal[1][cath]][cath],
1972 fIy[fIndLocal[1][cath]][cath]);
1973 lower[2]=vstart[2]-fSeg2[cath]->Dpx(fInput->DetElemId(),isec)/2;
1974 lower[3]=vstart[3]-fSeg2[cath]->Dpy(fInput->DetElemId(),isec)/2;
a9e2aefa 1975
fed772f3 1976 upper[2]=lower[2]+fSeg2[cath]->Dpx(fInput->DetElemId(),isec);
1977 upper[1]=lower[1]+2.*fSeg2[cath]->Dpy(fInput->DetElemId(),isec);
1978
1979 }
1980
a9e2aefa 1981 lower[4]=0.;
1982 upper[4]=1.;
1983// step sizes
1984 static Double_t step[5]={0.0005, 0.0005, 0.0005, 0.0005, 0.0001};
1985
9825400f 1986 clusterInput.Fitter()->mnparm(0,"x1",vstart[0],step[0],lower[0],upper[0],ierflag);
1987 clusterInput.Fitter()->mnparm(1,"y1",vstart[1],step[1],lower[1],upper[1],ierflag);
1988 clusterInput.Fitter()->mnparm(2,"x2",vstart[2],step[2],lower[2],upper[2],ierflag);
1989 clusterInput.Fitter()->mnparm(3,"y2",vstart[3],step[3],lower[3],upper[3],ierflag);
1990 clusterInput.Fitter()->mnparm(4,"a0",vstart[4],step[4],lower[4],upper[4],ierflag);
a9e2aefa 1991// ready for minimisation
a9e2aefa 1992 arglist[0]= -1;
1993 arglist[1]= 0;
1994
9825400f 1995 clusterInput.Fitter()->mnexcm("SET NOGR", arglist, 0, ierflag);
1996 clusterInput.Fitter()->mnexcm("MIGRAD", arglist, 0, ierflag);
4da78c65 1997 // clusterInput.Fitter()->mnexcm("EXIT" , arglist, 0, ierflag);
a9e2aefa 1998// Get fitted parameters
1999 Double_t xrec[2], yrec[2], qfrac;
2000 TString chname;
2001 Double_t epxz, b1, b2;
2002 Int_t ierflg;
9825400f 2003 clusterInput.Fitter()->mnpout(0, chname, xrec[0], epxz, b1, b2, ierflg);
2004 clusterInput.Fitter()->mnpout(1, chname, yrec[0], epxz, b1, b2, ierflg);
2005 clusterInput.Fitter()->mnpout(2, chname, xrec[1], epxz, b1, b2, ierflg);
2006 clusterInput.Fitter()->mnpout(3, chname, yrec[1], epxz, b1, b2, ierflg);
2007 clusterInput.Fitter()->mnpout(4, chname, qfrac, epxz, b1, b2, ierflg);
a9e2aefa 2008
2009 Double_t fmin, fedm, errdef;
2010 Int_t npari, nparx, istat;
2011
9825400f 2012 clusterInput.Fitter()->mnstat(fmin, fedm, errdef, npari, nparx, istat);
a9e2aefa 2013 fFitStat=istat;
a9e2aefa 2014 return kTRUE;
2015}
2016
e3cba86e 2017Float_t AliMUONClusterFinderVS::CombiDoubleMathiesonFit(AliMUONRawCluster * /*c*/)
a9e2aefa 2018{
2019//
2020// Perform combined double Mathieson fit on both cathode planes
2021//
19dd5b2f 2022 Double_t arglist[20];
2023 Int_t ierflag=0;
9825400f 2024 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
2025 clusterInput.Fitter()->SetFCN(fcnCombiS2);
2026 clusterInput.Fitter()->mninit(6,10,7);
19dd5b2f 2027 clusterInput.Fitter()->SetPrintLevel(-1+fDebugLevel);
2028 arglist[0]=-1;
2029 clusterInput.Fitter()->mnexcm("SET NOW", arglist, 0, ierflag);
a9e2aefa 2030// Set starting values
2031 static Double_t vstart[6];
2032 vstart[0]=fXInit[0];
2033 vstart[1]=fYInit[0];
2034 vstart[2]=fXInit[1];
2035 vstart[3]=fYInit[1];
2036 vstart[4]=fQrInit[0];
2037 vstart[5]=fQrInit[1];
2038// lower and upper limits
f0d86bc4 2039 static Float_t lower[6], upper[6];
a9e2aefa 2040 Int_t ix,iy,isec;
2041 Float_t dpx, dpy;
fed772f3 2042 if (fSegmentationType == 1) {
f0d86bc4 2043 fSeg[1]->GetPadI(fXInit[0], fYInit[0], fZPlane, ix, iy);
2044 isec=fSeg[1]->Sector(ix, iy);
2045 dpx=fSeg[1]->Dpx(isec);
a9e2aefa 2046
f0d86bc4 2047 fSeg[0]->GetPadI(fXInit[0], fYInit[0], fZPlane, ix, iy);
2048 isec=fSeg[0]->Sector(ix, iy);
2049 dpy=fSeg[0]->Dpy(isec);
a9e2aefa 2050
fed772f3 2051 } else {
2052 fSeg2[1]->GetPadI(fInput->DetElemId(),fXInit[0], fYInit[0], fZPlane, ix, iy);
2053 isec=fSeg2[1]->Sector(fInput->DetElemId(),ix, iy);
2054 dpx=fSeg2[1]->Dpx(fInput->DetElemId(), isec);
2055
2056 fSeg2[0]->GetPadI(fInput->DetElemId(), fXInit[0], fYInit[0], fZPlane, ix, iy);
2057 isec=fSeg2[0]->Sector(fInput->DetElemId(), ix, iy);
2058 dpy=fSeg2[0]->Dpy(fInput->DetElemId(), isec);
2059
2060 }
a9e2aefa 2061
f0d86bc4 2062 Int_t icount;
2063 Float_t xdum, ydum, zdum;
c4a97bcd 2064 AliDebug(1,Form("\n Cluster Finder: %f %f %f %f ", fXInit[0], fXInit[1],fYInit[0], fYInit[1] ));
fed772f3 2065
2066 if (fSegmentationType == 1) {
2067
2068 // Find save upper and lower limits
2069 icount = 0;
f0d86bc4 2070
fed772f3 2071 for (fSeg[1]->FirstPad(fXInit[0], fYInit[0], fZPlane, dpx, 0.);
2072 fSeg[1]->MorePads();
2073 fSeg[1]->NextPad())
2074 {
2075 ix=fSeg[1]->Ix(); iy=fSeg[1]->Iy();
2076 // if (fHitMap[1]->TestHit(ix, iy) == kEmpty) continue;
2077 fSeg[1]->GetPadC(ix,iy,upper[0],ydum,zdum);
2078 if (icount ==0) lower[0]=upper[0];
2079 icount++;
2080 }
2081 if (lower[0]>upper[0]) {xdum=lower[0]; lower[0]=upper[0]; upper[0]=xdum;}
2082 // vstart[0] = 0.5*(lower[0]+upper[0]);
05c39730 2083
2084
fed772f3 2085 icount=0;
f0d86bc4 2086
fed772f3 2087 for (fSeg[0]->FirstPad(fXInit[0], fYInit[0], fZPlane, 0., dpy);
2088 fSeg[0]->MorePads();
2089 fSeg[0]->NextPad())
2090 {
2091 ix=fSeg[0]->Ix(); iy=fSeg[0]->Iy();
2092 // if (fHitMap[0]->TestHit(ix, iy) == kEmpty) continue;
2093 fSeg[0]->GetPadC(ix,iy,xdum,upper[1],zdum);
2094 if (icount ==0) lower[1]=upper[1];
2095 icount++;
2096 }
05c39730 2097
fed772f3 2098 if (lower[1]>upper[1]) {xdum=lower[1]; lower[1]=upper[1]; upper[1]=xdum;}
2099 // vstart[1] = 0.5*(lower[1]+upper[1]);
05c39730 2100
a9e2aefa 2101
fed772f3 2102 fSeg[1]->GetPadI(fXInit[1], fYInit[1], fZPlane, ix, iy);
2103 isec=fSeg[1]->Sector(ix, iy);
2104 dpx=fSeg[1]->Dpx(isec);
2105 fSeg[0]->GetPadI(fXInit[1], fYInit[1], fZPlane, ix, iy);
2106 isec=fSeg[0]->Sector(ix, iy);
2107 dpy=fSeg[0]->Dpy(isec);
a9e2aefa 2108
a9e2aefa 2109
fed772f3 2110 // Find save upper and lower limits
f0d86bc4 2111
fed772f3 2112 icount=0;
f0d86bc4 2113
fed772f3 2114 for (fSeg[1]->FirstPad(fXInit[1], fYInit[1], fZPlane, dpx, 0);
2115 fSeg[1]->MorePads(); fSeg[1]->NextPad())
2116 {
2117 ix=fSeg[1]->Ix(); iy=fSeg[1]->Iy();
2118 // if (fHitMap[1]->TestHit(ix, iy) == kEmpty) continue;
2119 fSeg[1]->GetPadC(ix,iy,upper[2],ydum,zdum);
2120 if (icount ==0) lower[2]=upper[2];
2121 icount++;
2122 }
2123 if (lower[2]>upper[2]) {xdum=lower[2]; lower[2]=upper[2]; upper[2]=xdum;}
2124 // vstart[2] = 0.5*(lower[2]+upper[2]);
f0d86bc4 2125
fed772f3 2126 icount=0;
f0d86bc4 2127
fed772f3 2128 for (fSeg[0]->FirstPad(fXInit[1], fYInit[1], fZPlane, 0, dpy);
2129 fSeg[0]-> MorePads(); fSeg[0]->NextPad())
2130 {
2131 ix=fSeg[0]->Ix(); iy=fSeg[0]->Iy();
2132 // if (fHitMap[0]->TestHit(ix, iy) != kEmpty) continue;
05c39730 2133
fed772f3 2134 fSeg[0]->GetPadC(ix,iy,xdum,upper[3],zdum);
2135 if (icount ==0) lower[3]=upper[3];
2136 icount++;
05c39730 2137
fed772f3 2138 }
2139 if (lower[3]>upper[3]) {xdum=lower[3]; lower[3]=upper[3]; upper[3]=xdum;}
05c39730 2140
fed772f3 2141 // vstart[3] = 0.5*(lower[3]+upper[3]);
2142 } else {
2143
2144 // Find save upper and lower limits
2145 icount = 0;
2146
2147 for (fSeg2[1]->FirstPad(fInput->DetElemId(),fXInit[0], fYInit[0], fZPlane, dpx, 0.);
2148 fSeg2[1]->MorePads(fInput->DetElemId());
2149 fSeg2[1]->NextPad(fInput->DetElemId()))
2150 {
2151 ix=fSeg2[1]->Ix(); iy=fSeg2[1]->Iy();
2152 // if (fHitMap[1]->TestHit(ix, iy) == kEmpty) continue;
2153 fSeg2[1]->GetPadC(fInput->DetElemId(),ix,iy,upper[0],ydum,zdum);
2154 if (icount ==0) lower[0]=upper[0];
2155 icount++;
2156 }
2157 if (lower[0]>upper[0]) {xdum=lower[0]; lower[0]=upper[0]; upper[0]=xdum;}
2158 // vstart[0] = 0.5*(lower[0]+upper[0]);
2159
05c39730 2160
fed772f3 2161 icount=0;
2162
2163 for (fSeg2[0]->FirstPad(fInput->DetElemId(),fXInit[0], fYInit[0], fZPlane, 0., dpy);
2164 fSeg2[0]->MorePads(fInput->DetElemId());
2165 fSeg2[0]->NextPad(fInput->DetElemId()))
2166 {
2167 ix=fSeg2[0]->Ix(); iy=fSeg2[0]->Iy();
2168 // if (fHitMap[0]->TestHit(ix, iy) == kEmpty) continue;
2169 fSeg2[0]->GetPadC(fInput->DetElemId(),ix,iy,xdum,upper[1],zdum);
2170 if (icount ==0) lower[1]=upper[1];
2171 icount++;
2172 }
2173
2174 if (lower[1]>upper[1]) {xdum=lower[1]; lower[1]=upper[1]; upper[1]=xdum;}
2175 // vstart[1] = 0.5*(lower[1]+upper[1]);
2176
2177
2178 fSeg2[1]->GetPadI(fInput->DetElemId(),fXInit[1], fYInit[1], fZPlane, ix, iy);
2179 isec=fSeg2[1]->Sector(fInput->DetElemId(),ix, iy);
2180 dpx=fSeg2[1]->Dpx(fInput->DetElemId(),isec);
2181 fSeg2[0]->GetPadI(fInput->DetElemId(),fXInit[1], fYInit[1], fZPlane, ix, iy);
2182 isec=fSeg2[0]->Sector(fInput->DetElemId(),ix, iy);
2183 dpy=fSeg2[0]->Dpy(fInput->DetElemId(),isec);
2184
2185
2186 // Find save upper and lower limits
2187
2188 icount=0;
2189
2190 for (fSeg2[1]->FirstPad(fInput->DetElemId(),fXInit[1], fYInit[1], fZPlane, dpx, 0);
2191 fSeg2[1]->MorePads(fInput->DetElemId());
2192 fSeg2[1]->NextPad(fInput->DetElemId()))
2193 {
2194 ix=fSeg2[1]->Ix(); iy=fSeg2[1]->Iy();
2195 // if (fHitMap[1]->TestHit(ix, iy) == kEmpty) continue;
2196 fSeg2[1]->GetPadC(fInput->DetElemId(),ix,iy,upper[2],ydum,zdum);
2197 if (icount ==0) lower[2]=upper[2];
2198 icount++;
2199 }
2200 if (lower[2]>upper[2]) {xdum=lower[2]; lower[2]=upper[2]; upper[2]=xdum;}
2201 // vstart[2] = 0.5*(lower[2]+upper[2]);
2202
2203 icount=0;
2204
2205 for (fSeg2[0]->FirstPad(fInput->DetElemId(),fXInit[1], fYInit[1], fZPlane, 0, dpy);
2206 fSeg2[0]-> MorePads(fInput->DetElemId());
2207 fSeg2[0]->NextPad(fInput->DetElemId()))
2208 {
2209 ix=fSeg2[0]->Ix(); iy=fSeg2[0]->Iy();
2210 // if (fHitMap[0]->TestHit(ix, iy) != kEmpty) continue;
2211
2212 fSeg2[0]->GetPadC(fInput->DetElemId(),ix,iy,xdum,upper[3],zdum);
2213 if (icount ==0) lower[3]=upper[3];
2214 icount++;
2215
2216 }
2217 if (lower[3]>upper[3]) {xdum=lower[3]; lower[3]=upper[3]; upper[3]=xdum;}
2218 }
a9e2aefa 2219 lower[4]=0.;
2220 upper[4]=1.;
2221 lower[5]=0.;
2222 upper[5]=1.;
2223
2224// step sizes
2225 static Double_t step[6]={0.0005, 0.0005, 0.0005, 0.0005, 0.001, 0.001};
9825400f 2226 clusterInput.Fitter()->mnparm(0,"x1",vstart[0],step[0],lower[0],upper[0],ierflag);
2227 clusterInput.Fitter()->mnparm(1,"y1",vstart[1],step[1],lower[1],upper[1],ierflag);
2228 clusterInput.Fitter()->mnparm(2,"x2",vstart[2],step[2],lower[2],upper[2],ierflag);
2229 clusterInput.Fitter()->mnparm(3,"y2",vstart[3],step[3],lower[3],upper[3],ierflag);
2230 clusterInput.Fitter()->mnparm(4,"a0",vstart[4],step[4],lower[4],upper[4],ierflag);
2231 clusterInput.Fitter()->mnparm(5,"a1",vstart[5],step[5],lower[5],upper[5],ierflag);
a9e2aefa 2232// ready for minimisation
a9e2aefa 2233 arglist[0]= -1;
2234 arglist[1]= 0;
2235
9825400f 2236 clusterInput.Fitter()->mnexcm("SET NOGR", arglist, 0, ierflag);
2237 clusterInput.Fitter()->mnexcm("MIGRAD", arglist, 0, ierflag);
4da78c65 2238 // clusterInput.Fitter()->mnexcm("EXIT" , arglist, 0, ierflag);
a9e2aefa 2239// Get fitted parameters
2240 TString chname;
2241 Double_t epxz, b1, b2;
2242 Int_t ierflg;
9825400f 2243 clusterInput.Fitter()->mnpout(0, chname, fXFit[0], epxz, b1, b2, ierflg);
2244 clusterInput.Fitter()->mnpout(1, chname, fYFit[0], epxz, b1, b2, ierflg);
2245 clusterInput.Fitter()->mnpout(2, chname, fXFit[1], epxz, b1, b2, ierflg);
2246 clusterInput.Fitter()->mnpout(3, chname, fYFit[1], epxz, b1, b2, ierflg);
2247 clusterInput.Fitter()->mnpout(4, chname, fQrFit[0], epxz, b1, b2, ierflg);
2248 clusterInput.Fitter()->mnpout(5, chname, fQrFit[1], epxz, b1, b2, ierflg);
a9e2aefa 2249
2250 Double_t fmin, fedm, errdef;
2251 Int_t npari, nparx, istat;
2252
9825400f 2253 clusterInput.Fitter()->mnstat(fmin, fedm, errdef, npari, nparx, istat);
a9e2aefa 2254 fFitStat=istat;
2255
2256 fChi2[0]=fmin;
2257 fChi2[1]=fmin;
2258 return fmin;
2259}
2260
2261void AliMUONClusterFinderVS::Split(AliMUONRawCluster* c)
2262{
2263//
2264// One cluster for each maximum
2265//
2266 Int_t i, j, cath;
9825400f 2267 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
a9e2aefa 2268 for (j=0; j<2; j++) {
2269 AliMUONRawCluster cnew;
3b5272e3 2270 cnew.SetGhost(c->GetGhost());
a9e2aefa 2271 for (cath=0; cath<2; cath++) {
3b5272e3 2272 cnew.SetChi2(cath,fChi2[0]);
07cfabcf 2273 // ?? why not cnew.fChi2[cath]=fChi2[cath];
a9e2aefa 2274
2275 if (fNPeaks == 0) {
3b5272e3 2276 cnew.SetNcluster(0,-1);
2277 cnew.SetNcluster(1,fNRawClusters);
a9e2aefa 2278 } else {
3b5272e3 2279 cnew.SetNcluster(0,fNPeaks);
2280 cnew.SetNcluster(1,0);
a9e2aefa 2281 }
9e993f2a 2282 cnew.SetMultiplicity(cath,0);
ba12c242 2283 cnew.SetX(cath, Float_t(fXFit[j]));
2284 cnew.SetY(cath, Float_t(fYFit[j]));
2285 cnew.SetZ(cath, fZPlane);
a9e2aefa 2286 if (j==0) {
ba12c242 2287 cnew.SetCharge(cath, Int_t(clusterInput.TotalCharge(cath)*fQrFit[cath]));
a9e2aefa 2288 } else {
ba12c242 2289 cnew.SetCharge(cath, Int_t(clusterInput.TotalCharge(cath)*(1-fQrFit[cath])));
a9e2aefa 2290 }
fed772f3 2291 if (fSegmentationType == 1)
2292 fSeg[cath]->SetHit(fXFit[j],fYFit[j],fZPlane);
2293 else
2294 fSeg2[cath]->SetHit(fInput->DetElemId(), fXFit[j],fYFit[j],fZPlane);
2295
a9e2aefa 2296 for (i=0; i<fMul[cath]; i++) {
fed772f3 2297 Float_t q1;
0164904a 2298 cnew.SetIndex(cnew.GetMultiplicity(cath), cath, c->GetIndex(i,cath));
fed772f3 2299 if (fSegmentationType == 1) {
2300 fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
2301 q1 = fInput->Mathieson()->IntXY(fSeg[cath]);
2302 } else {
2303 fSeg2[cath]->SetPad(fInput->DetElemId(),fIx[i][cath], fIy[i][cath]);
2304 q1 = fInput->Mathieson()->IntXY(fInput->DetElemId(),fSeg2[cath]);
2305 }
0164904a 2306 cnew.SetContrib(i, cath, q1*Float_t(cnew.GetCharge(cath))/Float_t(fQ[i][cath]));
9e993f2a 2307 cnew.SetMultiplicity(cath, cnew.GetMultiplicity(cath)+1 );
a9e2aefa 2308 }
2309 FillCluster(&cnew,0,cath);
2310 } // cathode loop
2311
9e993f2a 2312 cnew.SetClusterType(cnew.PhysicsContribution());
ba12c242 2313 if (cnew.GetCharge(0)>0 && cnew.GetCharge(1)>0) AddRawCluster(cnew);
a9e2aefa 2314 fNPeaks++;
2315 }
2316}
a713db22 2317void AliMUONClusterFinderVS::AddRawCluster(const AliMUONRawCluster& c)
2318{
2319 //
2320 // Add a raw cluster copy to the list
2321 //
2322
2323// AliMUON *pMUON=(AliMUON*)gAlice->GetModule("MUON");
2324// pMUON->GetMUONData()->AddRawCluster(fInput->Chamber(),c);
2325// fNRawClusters++;
2326
2327
2328 TClonesArray &lrawcl = *fRawClusters;
2329 new(lrawcl[fNRawClusters++]) AliMUONRawCluster(c);
2330 AliDebug(1,Form("\nfNRawClusters %d\n",fNRawClusters));
2331}
2332
2333AliMUONClusterFinderVS& AliMUONClusterFinderVS
2334::operator = (const AliMUONClusterFinderVS& rhs)
2335{
2336// Protected assignement operator
2337
2338 if (this == &rhs) return *this;
a9e2aefa 2339
a713db22 2340 AliFatal("Not implemented.");
2341
2342 return *this;
2343}
a9e2aefa 2344
a9e2aefa 2345//
2346// Minimisation functions
2347// Single Mathieson
e3cba86e 2348void fcnS1(Int_t & /*npar*/, Double_t * /*gin*/, Double_t &f, Double_t *par, Int_t /*iflag*/)
a9e2aefa 2349{
9825400f 2350 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
a9e2aefa 2351 Int_t i;
2352 Float_t delta;
2353 Float_t chisq=0;
2354 Float_t qcont=0;
2355 Float_t qtot=0;
9825400f 2356
2357 for (i=0; i<clusterInput.Nmul(0); i++) {
2358 Float_t q0=clusterInput.Charge(i,0);
2359 Float_t q1=clusterInput.DiscrChargeS1(i,par);
a9e2aefa 2360 delta=(q0-q1)/q0;
2361 chisq+=delta*delta;
2362 qcont+=q1;
2363 qtot+=q0;
2364 }
2365 f=chisq;
2366}
2367
e3cba86e 2368void fcnCombiS1(Int_t & /*npar*/, Double_t * /*gin*/, Double_t &f, Double_t *par, Int_t /*iflag*/)
a9e2aefa 2369{
9825400f 2370 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
a9e2aefa 2371 Int_t i, cath;
2372 Float_t delta;
2373 Float_t chisq=0;
2374 Float_t qcont=0;
2375 Float_t qtot=0;
a9e2aefa 2376
2377 for (cath=0; cath<2; cath++) {
9825400f 2378 for (i=0; i<clusterInput.Nmul(cath); i++) {
2379 Float_t q0=clusterInput.Charge(i,cath);
2380 Float_t q1=clusterInput.DiscrChargeCombiS1(i,par,cath);
a9e2aefa 2381 delta=(q0-q1)/q0;
2382 chisq+=delta*delta;
2383 qcont+=q1;
2384 qtot+=q0;
2385 }
a9e2aefa 2386 }
a9e2aefa 2387 f=chisq;
2388}
2389
2390// Double Mathieson
e3cba86e 2391void fcnS2(Int_t & /*npar*/, Double_t * /*gin*/, Double_t &f, Double_t *par, Int_t /*iflag*/)
a9e2aefa 2392{
9825400f 2393 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
a9e2aefa 2394 Int_t i;
2395 Float_t delta;
2396 Float_t chisq=0;
2397 Float_t qcont=0;
2398 Float_t qtot=0;
2399
9825400f 2400 for (i=0; i<clusterInput.Nmul(0); i++) {
a9e2aefa 2401
9825400f 2402 Float_t q0=clusterInput.Charge(i,0);
2403 Float_t q1=clusterInput.DiscrChargeS2(i,par);
a9e2aefa 2404 delta=(q0-q1)/q0;
2405 chisq+=delta*delta;
2406 qcont+=q1;
2407 qtot+=q0;
2408 }
a9e2aefa 2409 f=chisq;
2410}
2411
2412// Double Mathieson
e3cba86e 2413void fcnCombiS2(Int_t & /*npar*/, Double_t * /*gin*/, Double_t &f, Double_t *par, Int_t /*iflag*/)
a9e2aefa 2414{
9825400f 2415 AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
a9e2aefa 2416 Int_t i, cath;
2417 Float_t delta;
2418 Float_t chisq=0;
2419 Float_t qcont=0;
2420 Float_t qtot=0;
a9e2aefa 2421 for (cath=0; cath<2; cath++) {
9825400f 2422 for (i=0; i<clusterInput.Nmul(cath); i++) {
2423 Float_t q0=clusterInput.Charge(i,cath);
2424 Float_t q1=clusterInput.DiscrChargeCombiS2(i,par,cath);
a9e2aefa 2425 delta=(q0-q1)/q0;
2426 chisq+=delta*delta;
2427 qcont+=q1;
2428 qtot+=q0;
2429 }
a9e2aefa 2430 }
a9e2aefa 2431 f=chisq;
2432}