30178c30 |
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 | **************************************************************************/ |
15 | |
16 | /* $Id$ */ |
17 | |
0627f609 |
18 | // Clusterizer class developed by A. Zinchenko (Dubna), based on the |
19 | // Expectation-Maximization algorithm |
0df3ca52 |
20 | |
ae17f568 |
21 | #include <stdlib.h> |
0df3ca52 |
22 | #include <Riostream.h> |
0df3ca52 |
23 | #include <TH2.h> |
0df3ca52 |
24 | #include <TMinuit.h> |
25 | #include <TMatrixD.h> |
26 | |
30178c30 |
27 | #include "AliMUONClusterFinderAZ.h" |
1af223d7 |
28 | #include "AliMUONClusterDrawAZ.h" |
0627f609 |
29 | #include "AliMUONVGeometryDESegmentation.h" |
30 | #include "AliMUONGeometryModuleTransformer.h" |
0df3ca52 |
31 | #include "AliRun.h" |
32 | #include "AliMUON.h" |
0df3ca52 |
33 | #include "AliMUONDigit.h" |
0df3ca52 |
34 | #include "AliMUONRawCluster.h" |
35 | #include "AliMUONClusterInput.h" |
36 | #include "AliMUONPixel.h" |
0627f609 |
37 | #include "AliMUONMathieson.h" |
8c343c7c |
38 | #include "AliLog.h" |
0df3ca52 |
39 | |
0df3ca52 |
40 | ClassImp(AliMUONClusterFinderAZ) |
0558a292 |
41 | |
343146bf |
42 | const Double_t AliMUONClusterFinderAZ::fgkCouplMin = 1.e-3; // threshold on coupling |
0627f609 |
43 | const Double_t AliMUONClusterFinderAZ::fgkZeroSuppression = 6; // average zero suppression value |
44 | const Double_t AliMUONClusterFinderAZ::fgkSaturation = 3000; // average saturation level |
0558a292 |
45 | AliMUONClusterFinderAZ* AliMUONClusterFinderAZ::fgClusterFinder = 0x0; |
46 | TMinuit* AliMUONClusterFinderAZ::fgMinuit = 0x0; |
2b1e4f0e |
47 | //FILE *lun1 = fopen("nxny.dat","w"); |
0df3ca52 |
48 | |
0df3ca52 |
49 | //_____________________________________________________________________________ |
1af223d7 |
50 | AliMUONClusterFinderAZ::AliMUONClusterFinderAZ(Bool_t draw) |
74f7bbc5 |
51 | : AliMUONClusterFinderVS() |
0df3ca52 |
52 | { |
53 | // Constructor |
af34d705 |
54 | fnPads[0]=fnPads[1]=0; |
55 | |
56 | for (Int_t i=0; i<7; i++) |
57 | for (Int_t j=0; j<fgkDim; j++) |
58 | fXyq[i][j]= 9999.; |
59 | |
0627f609 |
60 | for (Int_t i=0; i<4; i++) |
61 | for (Int_t j=0; j<fgkDim; j++) |
af34d705 |
62 | fPadIJ[i][j]=-1; |
0627f609 |
63 | |
64 | for (Int_t i=0; i<2; i++) |
65 | for (Int_t j=0; j<fgkDim; j++) |
af34d705 |
66 | fUsed[i][j] = 0; |
af34d705 |
67 | |
0627f609 |
68 | fSegmentation[1] = fSegmentation[0] = 0x0; |
af34d705 |
69 | |
0627f609 |
70 | fZpad = 0; |
af34d705 |
71 | fQtot = 0; |
0627f609 |
72 | fPadBeg[0] = fPadBeg[1] = fCathBeg = fNpar = fnCoupled = 0; |
af34d705 |
73 | |
0df3ca52 |
74 | if (!fgMinuit) fgMinuit = new TMinuit(8); |
af34d705 |
75 | if (!fgClusterFinder) fgClusterFinder = this; |
0df3ca52 |
76 | fPixArray = new TObjArray(20); |
af34d705 |
77 | |
0627f609 |
78 | fDebug = 0; //0; |
79 | fReco = 1; |
80 | fDraw = 0x0; |
1af223d7 |
81 | if (draw) { |
82 | fDebug = 1; |
cc87ebcd |
83 | fReco = 0; |
1af223d7 |
84 | fDraw = new AliMUONClusterDrawAZ(this); |
85 | } |
cc87ebcd |
86 | cout << " *** Running AZ cluster finder *** " << endl; |
0df3ca52 |
87 | } |
88 | |
74f7bbc5 |
89 | //_____________________________________________________________________________ |
90 | AliMUONClusterFinderAZ::AliMUONClusterFinderAZ(const AliMUONClusterFinderAZ& rhs) |
91 | : AliMUONClusterFinderVS(rhs) |
92 | { |
93 | // Protected copy constructor |
94 | |
8c343c7c |
95 | AliFatal("Not implemented."); |
74f7bbc5 |
96 | } |
97 | |
0df3ca52 |
98 | //_____________________________________________________________________________ |
99 | AliMUONClusterFinderAZ::~AliMUONClusterFinderAZ() |
100 | { |
101 | // Destructor |
102 | delete fgMinuit; fgMinuit = 0; delete fPixArray; fPixArray = 0; |
1af223d7 |
103 | delete fDraw; |
0df3ca52 |
104 | } |
105 | |
106 | //_____________________________________________________________________________ |
107 | void AliMUONClusterFinderAZ::FindRawClusters() |
108 | { |
109 | // To provide the same interface as in AliMUONClusterFinderVS |
110 | |
1af223d7 |
111 | ResetRawClusters(); |
0bf8d810 |
112 | EventLoop (gAlice->GetEvNumber(), fInput->Chamber()); |
0df3ca52 |
113 | } |
114 | |
115 | //_____________________________________________________________________________ |
1af223d7 |
116 | void AliMUONClusterFinderAZ::EventLoop(Int_t nev, Int_t ch) |
0df3ca52 |
117 | { |
2b1e4f0e |
118 | // Loop over digits |
0df3ca52 |
119 | |
1af223d7 |
120 | if (fDraw && !fDraw->FindEvCh(nev, ch)) return; |
0df3ca52 |
121 | |
0627f609 |
122 | fSegmentation[0] = (AliMUONVGeometryDESegmentation*) fInput-> |
123 | Segmentation2(0)->GetDESegmentation(fInput->DetElemId()); |
124 | fSegmentation[1] = (AliMUONVGeometryDESegmentation*) fInput-> |
125 | Segmentation2(1)->GetDESegmentation(fInput->DetElemId()); |
0df3ca52 |
126 | |
1af223d7 |
127 | Int_t ndigits[2] = {9,9}, nShown[2] = {0}; |
cc87ebcd |
128 | if (fReco != 2) { // skip initialization for the combined cluster / track |
129 | fCathBeg = fPadBeg[0] = fPadBeg[1] = 0; |
130 | for (Int_t i = 0; i < 2; i++) { |
131 | for (Int_t j = 0; j < fgkDim; j++) { fUsed[i][j] = kFALSE; } |
132 | } |
0df3ca52 |
133 | } |
134 | |
135 | next: |
cc87ebcd |
136 | if (fReco == 2 && (nShown[0] || nShown[1])) return; // only one precluster for the combined finder |
1af223d7 |
137 | if (ndigits[0] == nShown[0] && ndigits[1] == nShown[1]) return; |
138 | |
0df3ca52 |
139 | Float_t xpad, ypad, zpad, zpad0; |
0df3ca52 |
140 | Bool_t first = kTRUE; |
2b1e4f0e |
141 | if (fDebug) cout << " *** Event # " << nev << " chamber: " << ch << endl; |
0df3ca52 |
142 | fnPads[0] = fnPads[1] = 0; |
cc87ebcd |
143 | for (Int_t i = 0; i < fgkDim; i++) fPadIJ[1][i] = 0; |
2b1e4f0e |
144 | |
cc87ebcd |
145 | for (Int_t iii = fCathBeg; iii < 2; iii++) { |
0df3ca52 |
146 | Int_t cath = TMath::Odd(iii); |
0627f609 |
147 | ndigits[cath] = fInput->NDigits(cath); |
2b1e4f0e |
148 | if (!ndigits[0] && !ndigits[1]) return; |
0df3ca52 |
149 | if (ndigits[cath] == 0) continue; |
2b1e4f0e |
150 | if (fDebug) cout << " ndigits: " << ndigits[cath] << " " << cath << endl; |
0df3ca52 |
151 | |
152 | AliMUONDigit *mdig; |
153 | Int_t digit; |
154 | |
c1aed84f |
155 | Bool_t eEOC = kTRUE; // end-of-cluster |
cc87ebcd |
156 | for (digit = fPadBeg[cath]; digit < ndigits[cath]; digit++) { |
2b1e4f0e |
157 | mdig = AliMUONClusterInput::Instance()->Digit(cath,digit); |
0df3ca52 |
158 | if (first) { |
159 | // Find first unused pad |
160 | if (fUsed[cath][digit]) continue; |
0627f609 |
161 | //if (!fSegmentation[cath]->GetPadC(fInput->DetElemId(),mdig->PadX(),mdig->PadY(),xpad,ypad,zpad0)) { |
162 | if (!fSegmentation[cath]->HasPad(mdig->PadX(), mdig->PadY())) { |
5a051e34 |
163 | // Handle "non-existing" pads |
164 | fUsed[cath][digit] = kTRUE; |
165 | continue; |
166 | } |
0627f609 |
167 | fSegmentation[cath]->GetPadC(mdig->PadX(), mdig->PadY(), xpad, ypad, zpad0); |
0df3ca52 |
168 | } else { |
169 | if (fUsed[cath][digit]) continue; |
0627f609 |
170 | //if (!fSegmentation[cath]->GetPadC(fInput->DetElemId(),mdig->PadX(),mdig->PadY(),xpad,ypad,zpad)) { |
171 | if (!fSegmentation[cath]->HasPad(mdig->PadX(), mdig->PadY())) { |
5a051e34 |
172 | // Handle "non-existing" pads |
173 | fUsed[cath][digit] = kTRUE; |
174 | continue; |
175 | } |
0627f609 |
176 | fSegmentation[cath]->GetPadC(mdig->PadX(), mdig->PadY(), xpad, ypad, zpad); |
177 | //if (TMath::Abs(zpad-zpad0) > 0.1) continue; // different slats |
0df3ca52 |
178 | // Find a pad overlapping with the cluster |
179 | if (!Overlap(cath,mdig)) continue; |
180 | } |
181 | // Add pad - recursive call |
182 | AddPad(cath,digit); |
2b1e4f0e |
183 | //AZ !!!!!! Temporary fix of St1 overlap regions !!!!!!!! |
0627f609 |
184 | /* |
2b1e4f0e |
185 | if (cath && ch < 2) { |
186 | Int_t npads = fnPads[0] + fnPads[1] - 1; |
187 | Int_t cath1 = fPadIJ[0][npads]; |
188 | Int_t idig = TMath::Nint (fXyq[5][npads]); |
189 | mdig = AliMUONClusterInput::Instance()->Digit(cath1,idig); |
0627f609 |
190 | //fSegmentation[cath1]->GetPadC(fInput->DetElemId(),mdig->PadX(),mdig->PadY(),xpad,ypad,zpad); |
191 | fSegmentation[cath1]->GetPadC(mdig->PadX(), mdig->PadY(), xpad, ypad, zpad); |
2b1e4f0e |
192 | if (TMath::Abs(zpad-zpad0) > 0.1) zpad0 = zpad; |
193 | } |
0627f609 |
194 | */ |
c1aed84f |
195 | eEOC = kFALSE; |
0df3ca52 |
196 | if (digit >= 0) break; |
197 | } |
c1aed84f |
198 | if (first && eEOC) { |
0df3ca52 |
199 | // No more unused pads |
200 | if (cath == 0) continue; // on cathode #0 - check #1 |
2b1e4f0e |
201 | else return; // No more clusters |
0df3ca52 |
202 | } |
c1aed84f |
203 | if (eEOC) break; // cluster found |
0df3ca52 |
204 | first = kFALSE; |
2b1e4f0e |
205 | if (fDebug) cout << " nPads: " << fnPads[cath] << " " << nShown[cath]+fnPads[cath] << " " << cath << endl; |
0df3ca52 |
206 | } // for (Int_t iii = 0; |
207 | |
2b1e4f0e |
208 | fZpad = zpad0; |
1af223d7 |
209 | if (fDraw) fDraw->DrawCluster(); |
2b1e4f0e |
210 | |
211 | // Use MLEM for cluster finder |
212 | Int_t nMax = 1, localMax[100], maxPos[100]; |
213 | Double_t maxVal[100]; |
0df3ca52 |
214 | |
2b1e4f0e |
215 | if (CheckPrecluster(nShown)) { |
216 | BuildPixArray(); |
0627f609 |
217 | //* |
218 | if (fnPads[0]+fnPads[1] > 50) nMax = FindLocalMaxima(fPixArray, localMax, maxVal); |
2b1e4f0e |
219 | if (nMax > 1) TMath::Sort(nMax, maxVal, maxPos, kTRUE); // in decreasing order |
220 | Int_t iSimple = 0, nInX = -1, nInY; |
221 | PadsInXandY(nInX, nInY); |
222 | if (fDebug) cout << "Pads in X and Y: " << nInX << " " << nInY << endl; |
5a051e34 |
223 | if (nMax == 1 && nInX < 4 && nInY < 4) iSimple = 1; //1; // simple cluster |
0627f609 |
224 | //*/ |
225 | /* For test |
226 | Int_t iSimple = 0, nInX = -1, nInY; |
227 | PadsInXandY(nInX, nInY); |
228 | if (fDebug) cout << "Pads in X and Y: " << nInX << " " << nInY << endl; |
229 | if (nMax == 1 && nInX < 4 && nInY < 4) iSimple = 1; //1; // simple cluster |
230 | if (!iSimple) nMax = FindLocalMaxima(fPixArray, localMax, maxVal); |
231 | nMax = 1; |
232 | if (nMax > 1) TMath::Sort(nMax, maxVal, maxPos, kTRUE); // in decreasing order |
233 | */ |
2b1e4f0e |
234 | for (Int_t i=0; i<nMax; i++) { |
235 | if (nMax > 1) FindCluster(localMax, maxPos[i]); |
94eb555e |
236 | if (!MainLoop(iSimple)) AliWarning(Form(" MainLoop failed ")); |
2b1e4f0e |
237 | if (i < nMax-1) { |
238 | for (Int_t j=0; j<fnPads[0]+fnPads[1]; j++) { |
239 | if (fPadIJ[1][j] == 0) continue; // pad charge was not modified |
240 | fPadIJ[1][j] = 0; |
241 | fXyq[2][j] = fXyq[6][j]; // use backup charge value |
242 | } |
243 | } |
0627f609 |
244 | } // for (Int_t i=0; i<nMax; |
245 | if (nMax > 1) ((TH2D*) gROOT->FindObject("anode"))->Delete(); |
246 | TH2D *mlem = (TH2D*) gROOT->FindObject("mlem"); |
247 | if (mlem) mlem->Delete(); |
2b1e4f0e |
248 | } |
1af223d7 |
249 | if (!fDraw || fDraw->Next()) goto next; |
0df3ca52 |
250 | } |
251 | |
252 | //_____________________________________________________________________________ |
253 | void AliMUONClusterFinderAZ::AddPad(Int_t cath, Int_t digit) |
254 | { |
255 | // Add pad to the cluster |
0627f609 |
256 | AliMUONDigit *mdig = fInput->Digit(cath,digit); |
0df3ca52 |
257 | |
258 | Int_t charge = mdig->Signal(); |
259 | // get the center of the pad |
0627f609 |
260 | Float_t xpad, ypad, zpad0; |
261 | //if (!fSegmentation[cath]->GetPadC(fInput->DetElemId(),mdig->PadX(),mdig->PadY(),xpad,ypad,zpad0)) { // Handle "non-existing" pads |
262 | if (!fSegmentation[cath]->HasPad(mdig->PadX(), mdig->PadY())) { |
5a051e34 |
263 | fUsed[cath][digit] = kTRUE; |
264 | return; |
265 | } |
0627f609 |
266 | fSegmentation[cath]->GetPadC(mdig->PadX(), mdig->PadY(), xpad, ypad, zpad0); |
267 | Int_t isec = fSegmentation[cath]->Sector(mdig->PadX(), mdig->PadY()); |
0df3ca52 |
268 | Int_t nPads = fnPads[0] + fnPads[1]; |
269 | fXyq[0][nPads] = xpad; |
270 | fXyq[1][nPads] = ypad; |
271 | fXyq[2][nPads] = charge; |
0627f609 |
272 | fXyq[3][nPads] = fSegmentation[cath]->Dpx(isec)/2; |
273 | fXyq[4][nPads] = fSegmentation[cath]->Dpy(isec)/2; |
0df3ca52 |
274 | fXyq[5][nPads] = digit; |
2b1e4f0e |
275 | fXyq[6][nPads] = 0; |
0df3ca52 |
276 | fPadIJ[0][nPads] = cath; |
277 | fPadIJ[1][nPads] = 0; |
0627f609 |
278 | fPadIJ[2][nPads] = mdig->PadX(); |
279 | fPadIJ[3][nPads] = mdig->PadY(); |
0df3ca52 |
280 | fUsed[cath][digit] = kTRUE; |
0627f609 |
281 | if (fDebug) printf(" bbb %d %d %f %f %f %f %f %4d %3d %3d \n", nPads, cath, xpad, ypad, zpad0, fXyq[3][nPads]*2, fXyq[4][nPads]*2, charge, mdig->PadX(), mdig->PadY()); |
0df3ca52 |
282 | fnPads[cath]++; |
283 | |
284 | // Check neighbours |
285 | Int_t nn, ix, iy, xList[10], yList[10]; |
286 | AliMUONDigit *mdig1; |
287 | |
0627f609 |
288 | Int_t ndigits = fInput->NDigits(cath); |
289 | fSegmentation[cath]->Neighbours(mdig->PadX(), mdig->PadY(), &nn, xList, yList); |
290 | for (Int_t in = 0; in < nn; in++) { |
291 | ix = xList[in]; |
292 | iy = yList[in]; |
0df3ca52 |
293 | for (Int_t digit1 = 0; digit1 < ndigits; digit1++) { |
294 | if (digit1 == digit) continue; |
0627f609 |
295 | mdig1 = fInput->Digit(cath,digit1); |
0df3ca52 |
296 | if (!fUsed[cath][digit1] && mdig1->PadX() == ix && mdig1->PadY() == iy) { |
297 | fUsed[cath][digit1] = kTRUE; |
298 | // Add pad - recursive call |
299 | AddPad(cath,digit1); |
300 | } |
301 | } //for (Int_t digit1 = 0; |
0627f609 |
302 | } // for (Int_t in = 0; |
0df3ca52 |
303 | } |
304 | |
305 | //_____________________________________________________________________________ |
2b1e4f0e |
306 | Bool_t AliMUONClusterFinderAZ::Overlap(Int_t cath, AliMUONDigit *mdig) |
0df3ca52 |
307 | { |
308 | // Check if the pad from one cathode overlaps with a pad |
309 | // in the precluster on the other cathode |
310 | |
0df3ca52 |
311 | Float_t xpad, ypad, zpad; |
0627f609 |
312 | fSegmentation[cath]->GetPadC(mdig->PadX(), mdig->PadY(), xpad, ypad, zpad); |
313 | Int_t isec = fSegmentation[cath]->Sector(mdig->PadX(), mdig->PadY()); |
002920d1 |
314 | |
2b1e4f0e |
315 | Float_t xy1[4], xy12[4]; |
0627f609 |
316 | xy1[0] = xpad - fSegmentation[cath]->Dpx(isec)/2; |
317 | xy1[1] = xy1[0] + fSegmentation[cath]->Dpx(isec); |
318 | xy1[2] = ypad - fSegmentation[cath]->Dpy(isec)/2; |
319 | xy1[3] = xy1[2] + fSegmentation[cath]->Dpy(isec); |
0df3ca52 |
320 | //cout << " ok " << fnPads[0]+fnPads[1] << xy1[0] << xy1[1] << xy1[2] << xy1[3] << endl; |
321 | |
322 | Int_t cath1 = TMath::Even(cath); |
323 | for (Int_t i=0; i<fnPads[0]+fnPads[1]; i++) { |
324 | if (fPadIJ[0][i] != cath1) continue; |
325 | if (Overlap(xy1, i, xy12, 0)) return kTRUE; |
326 | } |
327 | return kFALSE; |
328 | } |
329 | |
330 | //_____________________________________________________________________________ |
331 | Bool_t AliMUONClusterFinderAZ::Overlap(Float_t *xy1, Int_t iPad, Float_t *xy12, Int_t iSkip) |
332 | { |
333 | // Check if the pads xy1 and iPad overlap and return overlap area |
334 | |
335 | Float_t xy2[4]; |
336 | xy2[0] = fXyq[0][iPad] - fXyq[3][iPad]; |
337 | xy2[1] = fXyq[0][iPad] + fXyq[3][iPad]; |
338 | if (xy1[0] > xy2[1]-1.e-4 || xy1[1] < xy2[0]+1.e-4) return kFALSE; |
339 | xy2[2] = fXyq[1][iPad] - fXyq[4][iPad]; |
340 | xy2[3] = fXyq[1][iPad] + fXyq[4][iPad]; |
341 | if (xy1[2] > xy2[3]-1.e-4 || xy1[3] < xy2[2]+1.e-4) return kFALSE; |
342 | if (!iSkip) return kTRUE; // just check overlap (w/out computing the area) |
343 | xy12[0] = TMath::Max (xy1[0],xy2[0]); |
344 | xy12[1] = TMath::Min (xy1[1],xy2[1]); |
345 | xy12[2] = TMath::Max (xy1[2],xy2[2]); |
346 | xy12[3] = TMath::Min (xy1[3],xy2[3]); |
347 | return kTRUE; |
348 | } |
349 | |
0df3ca52 |
350 | //_____________________________________________________________________________ |
351 | Bool_t AliMUONClusterFinderAZ::CheckPrecluster(Int_t *nShown) |
352 | { |
353 | // Check precluster in order to attempt to simplify it (mostly for |
354 | // two-cathode preclusters) |
355 | |
2b1e4f0e |
356 | Int_t i1, i2, cath=0, digit=0; |
0df3ca52 |
357 | Float_t xy1[4], xy12[4]; |
358 | |
359 | Int_t npad = fnPads[0] + fnPads[1]; |
2b1e4f0e |
360 | if (npad == 1) { |
361 | // Disregard one-pad clusters (leftovers from splitting) |
362 | nShown[0] += fnPads[0]; |
363 | nShown[1] += fnPads[1]; |
364 | return kFALSE; |
365 | } |
0df3ca52 |
366 | |
367 | // If pads have the same size take average of pads on both cathodes |
0627f609 |
368 | //Int_t sameSize = (fnPads[0] && fnPads[1]) ? 1 : 0; |
369 | Int_t sameSize = 0; //AZ - 17-01-06 |
370 | |
0df3ca52 |
371 | if (sameSize) { |
372 | Double_t xSize = -1, ySize = 0; |
373 | for (Int_t i=0; i<npad; i++) { |
374 | if (fXyq[2][i] < 0) continue; |
375 | if (xSize < 0) { xSize = fXyq[3][i]; ySize = fXyq[4][i]; } |
376 | if (TMath::Abs(xSize-fXyq[3][i]) > 1.e-4 || TMath::Abs(ySize-fXyq[4][i]) > 1.e-4) { sameSize = 0; break; } |
377 | } |
378 | } // if (sameSize) |
2b1e4f0e |
379 | if (sameSize && fnPads[0] == 1 && fnPads[1] == 1) sameSize = 0; //AZ |
5a051e34 |
380 | // Handle shift by half a pad in Station 1 |
381 | if (sameSize) { |
382 | Int_t cath0 = fPadIJ[0][0]; |
383 | for (Int_t i = 1; i < npad; i++) { |
384 | if (fPadIJ[0][i] == cath0) continue; |
385 | Double_t dx = TMath::Abs ((fXyq[0][i] - fXyq[0][0]) / fXyq[3][i] / 2); |
386 | Int_t idx = (Int_t) TMath::Abs ((fXyq[0][i] - fXyq[0][0]) / fXyq[3][i] / 2); |
387 | if (TMath::Abs (dx - idx) > 0.001) sameSize = 0; |
388 | break; |
389 | } |
390 | } // if (sameSize) |
391 | |
2b1e4f0e |
392 | if (sameSize && (fnPads[0] >= 2 || fnPads[1] >= 2)) { |
0df3ca52 |
393 | nShown[0] += fnPads[0]; |
394 | nShown[1] += fnPads[1]; |
395 | fnPads[0] = fnPads[1] = 0; |
396 | Int_t div; |
397 | for (Int_t i=0; i<npad; i++) { |
398 | if (fXyq[2][i] < 0) continue; // used pad |
399 | fXyq[2][fnPads[0]] = fXyq[2][i]; |
400 | div = 1; |
2b1e4f0e |
401 | cath = fPadIJ[0][i]; |
0df3ca52 |
402 | for (Int_t j=i+1; j<npad; j++) { |
403 | if (fPadIJ[0][j] == fPadIJ[0][i]) continue; // same cathode |
404 | if (TMath::Abs(fXyq[0][j]-fXyq[0][i]) > 1.e-4) continue; |
405 | if (TMath::Abs(fXyq[1][j]-fXyq[1][i]) > 1.e-4) continue; |
406 | fXyq[2][fnPads[0]] += fXyq[2][j]; |
407 | div = 2; |
408 | fXyq[2][j] = -2; |
2b1e4f0e |
409 | if (cath) fXyq[5][fnPads[0]] = fXyq[5][j]; // save digit number for cath 0 |
0df3ca52 |
410 | break; |
411 | } |
2b1e4f0e |
412 | // Flag that the digit from the other cathode |
413 | if (cath && div == 1) fXyq[5][fnPads[0]] = -fXyq[5][i] - 1; |
414 | // If low pad charge take the other equal to 0 |
0627f609 |
415 | //if (div == 1 && fXyq[2][fnPads[0]] < fgkZeroSuppression + 1.5*3) div = 2; |
0df3ca52 |
416 | fXyq[2][fnPads[0]] /= div; |
417 | fXyq[0][fnPads[0]] = fXyq[0][i]; |
418 | fXyq[1][fnPads[0]] = fXyq[1][i]; |
0627f609 |
419 | fPadIJ[2][fnPads[0]] = fPadIJ[2][i]; |
420 | fPadIJ[3][fnPads[0]] = fPadIJ[3][i]; |
0df3ca52 |
421 | fPadIJ[0][fnPads[0]++] = 0; |
422 | } |
423 | } // if (sameSize) |
424 | |
425 | // Check if one-cathode precluster |
426 | i1 = fnPads[0]!=0 ? 0 : 1; |
427 | i2 = fnPads[1]!=0 ? 1 : 0; |
428 | |
429 | if (i1 != i2) { // two-cathode |
430 | |
431 | Int_t *flags = new Int_t[npad]; |
432 | for (Int_t i=0; i<npad; i++) { flags[i] = 0; } |
433 | |
434 | // Check pad overlaps |
435 | for (Int_t i=0; i<npad; i++) { |
436 | if (fPadIJ[0][i] != i1) continue; |
437 | xy1[0] = fXyq[0][i] - fXyq[3][i]; |
438 | xy1[1] = fXyq[0][i] + fXyq[3][i]; |
439 | xy1[2] = fXyq[1][i] - fXyq[4][i]; |
440 | xy1[3] = fXyq[1][i] + fXyq[4][i]; |
441 | for (Int_t j=0; j<npad; j++) { |
442 | if (fPadIJ[0][j] != i2) continue; |
443 | if (!Overlap(xy1, j, xy12, 0)) continue; |
444 | flags[i] = flags[j] = 1; // mark overlapped pads |
445 | } // for (Int_t j=0; |
446 | } // for (Int_t i=0; |
447 | |
448 | // Check if all pads overlap |
2b1e4f0e |
449 | Int_t nFlags=0; |
450 | for (Int_t i=0; i<npad; i++) { |
451 | if (flags[i]) continue; |
452 | nFlags ++; |
1af223d7 |
453 | if (fDebug) cout << i << " " << fPadIJ[0][i] << " " << fXyq[0][i] << " " << fXyq[1][i] << endl; |
2b1e4f0e |
454 | } |
455 | if (fDebug && nFlags) cout << " nFlags = " << nFlags << endl; |
0df3ca52 |
456 | //if (nFlags > 2 || (Float_t)nFlags / npad > 0.2) { // why 2 ??? - empirical choice |
0627f609 |
457 | if (nFlags > 0) { |
0df3ca52 |
458 | for (Int_t i=0; i<npad; i++) { |
459 | if (flags[i]) continue; |
460 | digit = TMath::Nint (fXyq[5][i]); |
461 | cath = fPadIJ[0][i]; |
1af223d7 |
462 | // Check for edge effect (missing pads on the other cathode) |
463 | Int_t cath1 = TMath::Even(cath), ix, iy; |
0627f609 |
464 | ix = iy = 0; |
465 | //if (!fSegmentation[cath1]->GetPadI(fInput->DetElemId(),fXyq[0][i],fXyq[1][i],fZpad,ix,iy)) continue; |
466 | if (!fSegmentation[cath1]->HasPad(fXyq[0][i], fXyq[1][i], fZpad)) continue; |
467 | if (nFlags == 1 && fXyq[2][i] < fgkZeroSuppression * 3) continue; |
0df3ca52 |
468 | fUsed[cath][digit] = kFALSE; // release pad |
469 | fXyq[2][i] = -2; |
470 | fnPads[cath]--; |
471 | } |
cc87ebcd |
472 | if (fDraw) fDraw->UpdateCluster(npad); |
0df3ca52 |
473 | } // if (nFlags > 2) |
474 | |
475 | // Check correlations of cathode charges |
476 | if (fnPads[0] && fnPads[1]) { // two-cathode |
477 | Double_t sum[2]={0}; |
478 | Int_t over[2] = {1, 1}; |
479 | for (Int_t i=0; i<npad; i++) { |
480 | cath = fPadIJ[0][i]; |
481 | if (fXyq[2][i] > 0) sum[cath] += fXyq[2][i]; |
0627f609 |
482 | if (fXyq[2][i] > fgkSaturation-1) over[cath] = 0; |
0df3ca52 |
483 | } |
2b1e4f0e |
484 | if (fDebug) cout << " Total charge: " << sum[0] << " " << sum[1] << endl; |
0df3ca52 |
485 | if ((over[0] || over[1]) && TMath::Abs(sum[0]-sum[1])/(sum[0]+sum[1])*2 > 1) { // 3 times difference |
2b1e4f0e |
486 | if (fDebug) cout << " Release " << endl; |
0df3ca52 |
487 | // Big difference |
cc87ebcd |
488 | cath = sum[0] > sum[1] ? 0 : 1; |
489 | Int_t imax = 0, imin = 0; |
490 | Double_t cmax = -1, cmin = 9999, dxMin = 0, dyMin = 0; |
0df3ca52 |
491 | Double_t *dist = new Double_t[npad]; |
cc87ebcd |
492 | for (Int_t i = 0; i < npad; i++) { |
493 | if (fPadIJ[0][i] != cath || fXyq[2][i] < 0) continue; |
494 | if (fXyq[2][i] < cmin) { |
495 | cmin = fXyq[2][i]; |
496 | imin = i; |
497 | } |
0df3ca52 |
498 | if (fXyq[2][i] < cmax) continue; |
499 | cmax = fXyq[2][i]; |
500 | imax = i; |
501 | } |
502 | // Arrange pads according to their distance to the max, |
503 | // normalized to the pad size |
cc87ebcd |
504 | for (Int_t i = 0; i < npad; i++) { |
0df3ca52 |
505 | dist[i] = 0; |
cc87ebcd |
506 | if (fPadIJ[0][i] != cath || fXyq[2][i] < 0) continue; |
0df3ca52 |
507 | if (i == imax) continue; |
cc87ebcd |
508 | Double_t dx = (fXyq[0][i] - fXyq[0][imax]) / fXyq[3][imax] / 2; |
509 | Double_t dy = (fXyq[1][i] - fXyq[1][imax]) / fXyq[4][imax] / 2; |
510 | dist[i] = TMath::Sqrt (dx * dx + dy * dy); |
511 | if (i == imin) { |
e8fb921b |
512 | cmin = dist[i] + 0.001; // distance to the pad with minimum charge |
cc87ebcd |
513 | dxMin = dx; |
514 | dyMin = dy; |
515 | } |
0df3ca52 |
516 | } |
517 | TMath::Sort(npad, dist, flags, kFALSE); // in increasing order |
518 | Int_t indx; |
519 | Double_t xmax = -1; |
cc87ebcd |
520 | for (Int_t i = 0; i < npad; i++) { |
0df3ca52 |
521 | indx = flags[i]; |
cc87ebcd |
522 | if (fPadIJ[0][indx] != cath || fXyq[2][indx] < 0) continue; |
523 | if (dist[indx] > cmin) { |
524 | // Farther than the minimum pad |
525 | Double_t dx = (fXyq[0][indx] - fXyq[0][imax]) / fXyq[3][imax] / 2; |
526 | Double_t dy = (fXyq[1][indx] - fXyq[1][imax]) / fXyq[4][imax] / 2; |
527 | dx *= dxMin; |
528 | dy *= dyMin; |
529 | if (dx >= 0 && dy >= 0) continue; |
530 | if (TMath::Abs(dx) > TMath::Abs(dy) && dx >= 0) continue; |
531 | if (TMath::Abs(dy) > TMath::Abs(dx) && dy >= 0) continue; |
532 | } |
533 | if (fXyq[2][indx] <= cmax || TMath::Abs(dist[indx]-xmax) < 1.e-3) { |
0df3ca52 |
534 | // Release pads |
cc87ebcd |
535 | if (TMath::Abs(dist[indx]-xmax) < 1.e-3) |
cd747ddb |
536 | cmax = TMath::Max((Double_t)(fXyq[2][indx]),cmax); |
0df3ca52 |
537 | else cmax = fXyq[2][indx]; |
538 | xmax = dist[indx]; |
539 | digit = TMath::Nint (fXyq[5][indx]); |
540 | fUsed[cath][digit] = kFALSE; |
541 | fXyq[2][indx] = -2; |
542 | fnPads[cath]--; |
cc87ebcd |
543 | } |
544 | } // for (Int_t i = 0; i < npad; |
545 | |
546 | // Check pad overlaps once more |
547 | for (Int_t j = 0; j < npad; j++) flags[j] = 0; |
548 | for (Int_t k = 0; k < npad; k++) { |
549 | if (fXyq[2][k] < 0 || fPadIJ[0][k] != i1) continue; |
550 | xy1[0] = fXyq[0][k] - fXyq[3][k]; |
551 | xy1[1] = fXyq[0][k] + fXyq[3][k]; |
552 | xy1[2] = fXyq[1][k] - fXyq[4][k]; |
553 | xy1[3] = fXyq[1][k] + fXyq[4][k]; |
554 | for (Int_t j = 0; j < npad; j++) { |
555 | if (fXyq[2][j] < 0) continue; |
556 | if (fPadIJ[0][j] != i2) continue; |
557 | if (!Overlap(xy1, j, xy12, 0)) continue; |
558 | flags[k] = flags[j] = 1; // mark overlapped pads |
559 | } // for (Int_t j = 0; |
560 | } // for (Int_t k = 0; |
561 | nFlags = 0; |
562 | for (Int_t j = 0; j < npad; j++) { |
563 | if (fXyq[2][j] < 0 || flags[j]) continue; |
564 | nFlags ++; |
565 | } |
566 | if (nFlags == fnPads[0] + fnPads[1]) { |
567 | // No overlap |
568 | for (Int_t j = 0; j < npad; j++) { |
569 | if (fXyq[2][j] < 0 || fPadIJ[0][j] != cath) continue; |
570 | fXyq[2][j] = -2; |
571 | fnPads[cath]--; |
0df3ca52 |
572 | } |
cc87ebcd |
573 | } |
0df3ca52 |
574 | delete [] dist; dist = 0; |
cc87ebcd |
575 | if (fDraw) fDraw->UpdateCluster(npad); |
0df3ca52 |
576 | } // TMath::Abs(sum[0]-sum[1])... |
577 | } // if (fnPads[0] && fnPads[1]) |
578 | delete [] flags; flags = 0; |
579 | } // if (i1 != i2) |
580 | |
581 | if (!sameSize) { nShown[0] += fnPads[0]; nShown[1] += fnPads[1]; } |
582 | |
583 | // Move released pads to the right |
584 | Int_t beg = 0, end = npad-1, padij; |
585 | Double_t xyq; |
586 | while (beg < end) { |
587 | if (fXyq[2][beg] > 0) { beg++; continue; } |
588 | for (Int_t j=end; j>beg; j--) { |
589 | if (fXyq[2][j] < 0) continue; |
590 | end = j - 1; |
0627f609 |
591 | for (Int_t j1=0; j1<4; j1++) { |
0df3ca52 |
592 | padij = fPadIJ[j1][beg]; |
593 | fPadIJ[j1][beg] = fPadIJ[j1][j]; |
594 | fPadIJ[j1][j] = padij; |
595 | } |
596 | for (Int_t j1=0; j1<6; j1++) { |
597 | xyq = fXyq[j1][beg]; |
598 | fXyq[j1][beg] = fXyq[j1][j]; |
599 | fXyq[j1][j] = xyq; |
600 | } |
601 | break; |
602 | } // for (Int_t j=end; |
603 | beg++; |
604 | } // while |
605 | npad = fnPads[0] + fnPads[1]; |
94eb555e |
606 | if (npad > 500) { |
607 | AliWarning(Form(" *** Too large cluster. Give up. %d ", npad)); |
608 | return kFALSE; |
609 | } |
0df3ca52 |
610 | // Back up charge value |
1af223d7 |
611 | for (Int_t j = 0; j < npad; j++) fXyq[6][j] = fXyq[2][j]; |
0df3ca52 |
612 | |
613 | return kTRUE; |
614 | } |
615 | |
616 | //_____________________________________________________________________________ |
617 | void AliMUONClusterFinderAZ::BuildPixArray() |
618 | { |
619 | // Build pixel array for MLEM method |
620 | |
621 | Int_t nPix=0, i1, i2; |
622 | Float_t xy1[4], xy12[4]; |
623 | AliMUONPixel *pixPtr=0; |
624 | |
625 | Int_t npad = fnPads[0] + fnPads[1]; |
626 | |
627 | // One cathode is empty |
628 | i1 = fnPads[0]!=0 ? 0 : 1; |
629 | i2 = fnPads[1]!=0 ? 1 : 0; |
630 | |
631 | // Build array of pixels on anode plane |
632 | if (i1 == i2) { // one-cathode precluster |
633 | for (Int_t j=0; j<npad; j++) { |
634 | pixPtr = new AliMUONPixel(); |
635 | for (Int_t i=0; i<2; i++) { |
636 | pixPtr->SetCoord(i, fXyq[i][j]); // pixel coordinates |
637 | pixPtr->SetSize(i, fXyq[i+3][j]); // pixel size |
638 | } |
639 | pixPtr->SetCharge(fXyq[2][j]); // charge |
640 | fPixArray->Add((TObject*)pixPtr); |
641 | nPix++; |
642 | } |
643 | } else { // two-cathode precluster |
5a051e34 |
644 | i1 = fPadIJ[0][0]; |
645 | i2 = TMath::Even (i1); |
646 | for (Int_t i = 0; i < npad; i++) { |
0df3ca52 |
647 | if (fPadIJ[0][i] != i1) continue; |
648 | xy1[0] = fXyq[0][i] - fXyq[3][i]; |
649 | xy1[1] = fXyq[0][i] + fXyq[3][i]; |
650 | xy1[2] = fXyq[1][i] - fXyq[4][i]; |
651 | xy1[3] = fXyq[1][i] + fXyq[4][i]; |
5a051e34 |
652 | for (Int_t j = 1; j < npad; j++) { |
0df3ca52 |
653 | if (fPadIJ[0][j] != i2) continue; |
654 | if (!Overlap(xy1, j, xy12, 1)) continue; |
655 | pixPtr = new AliMUONPixel(); |
656 | for (Int_t k=0; k<2; k++) { |
657 | pixPtr->SetCoord(k, (xy12[2*k]+xy12[2*k+1])/2); // pixel coordinates |
658 | pixPtr->SetSize(k, xy12[2*k+1]-pixPtr->Coord(k)); // size |
659 | } |
660 | pixPtr->SetCharge(TMath::Min (fXyq[2][i],fXyq[2][j])); //charge |
661 | fPixArray->Add((TObject*)pixPtr); |
2b1e4f0e |
662 | //cout << nPix << " " << pixPtr->Coord(0) << " " << pixPtr->Size(0) << " " << pixPtr->Coord(1) << " " << pixPtr->Size(1) << " " << pixPtr->Charge() << endl; |
0df3ca52 |
663 | nPix++; |
664 | } // for (Int_t j=0; |
665 | } // for (Int_t i=0; |
666 | } // else |
667 | |
5a051e34 |
668 | Float_t xPadMin = 999, yPadMin = 999; |
669 | for (Int_t i = 0; i < npad; i++) { |
670 | xPadMin = TMath::Min (xPadMin, fXyq[3][i]); |
671 | yPadMin = TMath::Min (yPadMin, fXyq[4][i]); |
672 | } |
673 | if (fDebug) cout << xPadMin << " " << yPadMin << endl; |
674 | |
675 | Float_t wxmin = 999, wymin = 999; |
676 | for (Int_t i = 0; i < nPix; i++) { |
677 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i); |
678 | wxmin = TMath::Min ((Double_t)wxmin, pixPtr->Size(0)); |
679 | wymin = TMath::Min ((Double_t)wymin, pixPtr->Size(1)); |
0df3ca52 |
680 | } |
2b1e4f0e |
681 | if (fDebug) cout << wxmin << " " << wymin << endl; |
5a051e34 |
682 | wxmin = TMath::Abs (wxmin - xPadMin/2) > 0.001 ? xPadMin : xPadMin / 2; |
683 | wymin = TMath::Abs (wymin - yPadMin/2) > 0.001 ? yPadMin : yPadMin / 2; |
684 | //wxmin = xPadMin; wymin = yPadMin; |
0df3ca52 |
685 | |
686 | // Check if small pixel X-size |
2b1e4f0e |
687 | AdjustPixel(wxmin, 0); |
0df3ca52 |
688 | // Check if small pixel Y-size |
2b1e4f0e |
689 | AdjustPixel(wymin, 1); |
0df3ca52 |
690 | // Check if large pixel size |
2b1e4f0e |
691 | AdjustPixel(wxmin, wymin); |
0df3ca52 |
692 | |
693 | // Remove discarded pixels |
694 | for (Int_t i=0; i<nPix; i++) { |
695 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i); |
696 | //pixPtr->Print(); |
697 | if (pixPtr->Charge() < 1) { fPixArray->RemoveAt(i); delete pixPtr; }// discarded pixel |
698 | } |
699 | fPixArray->Compress(); |
700 | nPix = fPixArray->GetEntriesFast(); |
701 | |
702 | if (nPix > npad) { |
2b1e4f0e |
703 | if (fDebug) cout << nPix << endl; |
0df3ca52 |
704 | // Too many pixels - sort and remove pixels with the lowest signal |
705 | fPixArray->Sort(); |
706 | for (Int_t i=npad; i<nPix; i++) { |
707 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i); |
708 | //pixPtr->Print(); |
709 | fPixArray->RemoveAt(i); |
710 | delete pixPtr; |
711 | } |
712 | nPix = npad; |
713 | } // if (nPix > npad) |
714 | |
715 | // Set pixel charges to the same value (for MLEM) |
716 | for (Int_t i=0; i<nPix; i++) { |
717 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i); |
718 | //pixPtr->SetCharge(10); |
2b1e4f0e |
719 | if (fDebug) cout << i+1 << " " << pixPtr->Coord(0) << " " << pixPtr->Coord(1) << " " << pixPtr->Size(0) << " " << pixPtr->Size(1) << endl; |
0df3ca52 |
720 | } |
721 | } |
722 | |
723 | //_____________________________________________________________________________ |
2b1e4f0e |
724 | void AliMUONClusterFinderAZ::AdjustPixel(Float_t width, Int_t ixy) |
0df3ca52 |
725 | { |
2b1e4f0e |
726 | // Check if some pixels have small size (adjust if necessary) |
0df3ca52 |
727 | |
728 | AliMUONPixel *pixPtr, *pixPtr1 = 0; |
729 | Int_t ixy1 = TMath::Even(ixy); |
730 | Int_t nPix = fPixArray->GetEntriesFast(); |
731 | |
732 | for (Int_t i=0; i<nPix; i++) { |
733 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i); |
734 | if (pixPtr->Charge() < 1) continue; // discarded pixel |
735 | if (pixPtr->Size(ixy)-width < -1.e-4) { |
736 | // try to merge |
2b1e4f0e |
737 | if (fDebug) cout << i << " Small X or Y: " << ixy << " " << pixPtr->Size(ixy) << " " << width << " " << pixPtr->Coord(0) << " " << pixPtr->Coord(1) << endl; |
0df3ca52 |
738 | for (Int_t j=i+1; j<nPix; j++) { |
739 | pixPtr1 = (AliMUONPixel*) fPixArray->UncheckedAt(j); |
740 | if (pixPtr1->Charge() < 1) continue; // discarded pixel |
741 | if (TMath::Abs(pixPtr1->Size(ixy)-width) < 1.e-4) continue; // right size |
742 | if (TMath::Abs(pixPtr1->Coord(ixy1)-pixPtr->Coord(ixy1)) > 1.e-4) continue; // different rows/columns |
743 | if (TMath::Abs(pixPtr1->Coord(ixy)-pixPtr->Coord(ixy)) < 2*width) { |
744 | // merge |
2b1e4f0e |
745 | Double_t tmp = pixPtr->Coord(ixy) + pixPtr1->Size(ixy) * |
746 | TMath::Sign (1., pixPtr1->Coord(ixy) - pixPtr->Coord(ixy)); |
747 | pixPtr->SetCoord(ixy, tmp); |
0df3ca52 |
748 | pixPtr->SetSize(ixy, width); |
0df3ca52 |
749 | pixPtr->SetCharge(TMath::Min (pixPtr->Charge(),pixPtr1->Charge())); |
750 | pixPtr1->SetCharge(0); |
751 | pixPtr1 = 0; |
752 | break; |
753 | } |
754 | } // for (Int_t j=i+1; |
755 | //if (!pixPtr1) { cout << " I am here!" << endl; pixPtr->SetSize(ixy, width); } // ??? |
756 | //else if (pixPtr1->Charge() > 0.5 || i == nPix-1) { |
757 | if (pixPtr1 || i == nPix-1) { |
758 | // edge pixel - just increase its size |
2b1e4f0e |
759 | if (fDebug) cout << " Edge ..." << endl; |
0df3ca52 |
760 | for (Int_t j=0; j<fnPads[0]+fnPads[1]; j++) { |
2b1e4f0e |
761 | //if (fPadIJ[0][j] != ixy1) continue; |
5a051e34 |
762 | //???-check if (TMath::Abs(pixPtr->Coord(ixy1)-fXyq[ixy1][j]) > 1.e-4) continue; |
0df3ca52 |
763 | if (pixPtr->Coord(ixy) < fXyq[ixy][j]) |
2b1e4f0e |
764 | //pixPtr->Shift(ixy, -pixPtr->Size(ixy)); |
765 | pixPtr->Shift(ixy, pixPtr->Size(ixy)-width); |
766 | //else pixPtr->Shift(ixy, pixPtr->Size(ixy)); |
767 | else pixPtr->Shift(ixy, -pixPtr->Size(ixy)+width); |
0df3ca52 |
768 | pixPtr->SetSize(ixy, width); |
769 | break; |
770 | } |
771 | } |
772 | } // if (pixPtr->Size(ixy)-width < -1.e-4) |
773 | } // for (Int_t i=0; i<nPix; |
774 | return; |
775 | } |
776 | |
777 | //_____________________________________________________________________________ |
2b1e4f0e |
778 | void AliMUONClusterFinderAZ::AdjustPixel(Float_t wxmin, Float_t wymin) |
0df3ca52 |
779 | { |
2b1e4f0e |
780 | // Check if some pixels have large size (adjust if necessary) |
0df3ca52 |
781 | |
cc87ebcd |
782 | Int_t n1[2], n2[2], iOK = 1, nPix = fPixArray->GetEntriesFast(); |
783 | AliMUONPixel *pixPtr, pix; |
784 | Double_t xy0[2] = {9999, 9999}, wxy[2], dist[2]; |
0df3ca52 |
785 | |
786 | // Check if large pixel size |
cc87ebcd |
787 | for (Int_t i = 0; i < nPix; i++) { |
0df3ca52 |
788 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i); |
789 | if (pixPtr->Charge() < 1) continue; // discarded pixel |
cc87ebcd |
790 | if (pixPtr->Size(0) - wxmin < 1.e-4) { |
791 | if (xy0[0] > 9998) xy0[0] = pixPtr->Coord(0); // position of a "normal" pixel |
792 | if (pixPtr->Size(1) - wymin < 1.e-4) { |
793 | if (xy0[1] > 9998) xy0[1] = pixPtr->Coord(1); // position of a "normal" pixel |
794 | continue; |
795 | } else iOK = 0; // large pixel |
796 | } else { |
797 | iOK = 0; // large pixel |
798 | if (xy0[1] > 9998 && pixPtr->Size(1) - wymin < 1.e-4) xy0[1] = pixPtr->Coord(1); // "normal" pixel |
799 | } |
800 | if (xy0[0] < 9998 && xy0[1] < 9998) break; |
801 | } |
802 | if (iOK) return; |
803 | |
804 | wxy[0] = wxmin; |
805 | wxy[1] = wymin; |
806 | //cout << xy0[0] << " " << xy0[1] << endl; |
807 | for (Int_t i = 0; i < nPix; i++) { |
808 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i); |
809 | if (pixPtr->Charge() < 1) continue; // discarded pixel |
810 | n1[0] = n1[1] = 999; |
811 | n2[0] = n2[1] = 1; |
812 | for (Int_t j = 0; j < 2; j++) { |
813 | if (pixPtr->Size(j) - wxy[j] < 1.e-4) continue; |
814 | dist[j] = (pixPtr->Coord(j) - xy0[j]) / wxy[j] / 2; // normalized distance to "normal" pixel |
815 | n2[j] = TMath::Nint (pixPtr->Size(j) / wxy[j]); |
816 | n1[j] = n2[j] == 1 ? TMath::Nint(dist[j]) : (Int_t)dist[j]; |
817 | } |
818 | if (n1[0] > 998 && n1[1] > 998) continue; |
819 | if (fDebug) cout << " Different " << pixPtr->Size(0) << " " << wxy[0] << " " |
820 | << pixPtr->Size(1) << " " << wxy[1] <<endl; |
821 | |
0627f609 |
822 | if (n2[0] > 2 || n2[1] > 2) { |
94eb555e |
823 | //cout << n2[0] << " " << n2[1] << endl; |
0627f609 |
824 | if (n2[0] > 2 && n1[0] < 999) n1[0]--; |
825 | if (n2[1] > 2 && n1[1] < 999) n1[1]--; |
826 | } |
cc87ebcd |
827 | //cout << n1[0] << " " << n2[0] << " " << n1[1] << " " << n2[1] << endl; |
828 | pix = *pixPtr; |
829 | pix.SetSize(0, wxy[0]); pix.SetSize(1, wxy[1]); |
830 | //pixPtr->Print(); |
831 | for (Int_t ii = 0; ii < n2[0]; ii++) { |
832 | if (n1[0] < 999) pix.SetCoord(0, xy0[0] + (n1[0] + TMath::Sign(1.,dist[0]) * ii) * 2 * wxy[0]); |
833 | for (Int_t jj = 0; jj < n2[1]; jj++) { |
834 | if (n1[1] < 999) pix.SetCoord(1, xy0[1] + (n1[1] + TMath::Sign(1.,dist[1]) * jj) * 2 * wxy[1]); |
835 | fPixArray->Add(new AliMUONPixel(pix)); |
836 | //pix.Print(); |
0df3ca52 |
837 | } |
0df3ca52 |
838 | } |
cc87ebcd |
839 | pixPtr->SetCharge(0); |
840 | } // for (Int_t i = 0; i < nPix; |
0df3ca52 |
841 | } |
842 | |
843 | //_____________________________________________________________________________ |
2b1e4f0e |
844 | Bool_t AliMUONClusterFinderAZ::MainLoop(Int_t iSimple) |
0df3ca52 |
845 | { |
846 | // Repeat MLEM algorithm until pixel size becomes sufficiently small |
847 | |
848 | TH2D *mlem; |
849 | |
850 | Int_t ix, iy; |
851 | //Int_t nn, xList[10], yList[10]; |
852 | Int_t nPix = fPixArray->GetEntriesFast(); |
0df3ca52 |
853 | AliMUONPixel *pixPtr = 0; |
854 | Double_t *coef = 0, *probi = 0; |
2b1e4f0e |
855 | AddVirtualPad(); // add virtual pads if necessary |
856 | Int_t npadTot = fnPads[0] + fnPads[1], npadOK = 0; |
1af223d7 |
857 | for (Int_t i = 0; i < npadTot; i++) if (fPadIJ[1][i] == 0) npadOK++; |
858 | if (fDraw) fDraw->ResetMuon(); |
0df3ca52 |
859 | |
860 | while (1) { |
861 | |
862 | mlem = (TH2D*) gROOT->FindObject("mlem"); |
863 | if (mlem) mlem->Delete(); |
864 | // Calculate coefficients |
2b1e4f0e |
865 | if (fDebug) cout << " nPix, npadTot, npadOK " << nPix << " " << npadTot << " " << npadOK << endl; |
0df3ca52 |
866 | |
867 | // Calculate coefficients and pixel visibilities |
868 | coef = new Double_t [npadTot*nPix]; |
869 | probi = new Double_t [nPix]; |
2b1e4f0e |
870 | for (Int_t ipix=0; ipix<nPix; ipix++) probi[ipix] = 0; |
871 | Int_t indx = 0, indx1 = 0, cath = 0; |
872 | |
873 | for (Int_t j=0; j<npadTot; j++) { |
874 | indx = j*nPix; |
875 | if (fPadIJ[1][j] == 0) { |
0df3ca52 |
876 | cath = fPadIJ[0][j]; |
0627f609 |
877 | ix = fPadIJ[2][j]; |
878 | iy = fPadIJ[3][j]; |
879 | fSegmentation[cath]->SetPad(ix, iy); |
2b1e4f0e |
880 | /* |
881 | fSegmentation[cath]->Neighbours(fInput->DetElemId(),ix,iy,&nn,xList,yList); |
882 | if (nn != 4) { |
883 | cout << nn << ": "; |
884 | for (Int_t i=0; i<nn; i++) {cout << xList[i] << " " << yList[i] << ", ";} |
885 | cout << endl; |
886 | } |
887 | */ |
888 | } |
889 | |
890 | for (Int_t ipix=0; ipix<nPix; ipix++) { |
891 | indx1 = indx + ipix; |
892 | if (fPadIJ[1][j] < 0) { coef[indx1] = 0; continue; } |
893 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(ipix); |
0627f609 |
894 | fSegmentation[cath]->SetHit(pixPtr->Coord(0), pixPtr->Coord(1), fZpad); |
895 | coef[indx1] = fInput->Mathieson()->IntXY(fInput->DetElemId(),fInput->Segmentation2(cath)); |
2b1e4f0e |
896 | probi[ipix] += coef[indx1]; |
897 | } // for (Int_t ipix=0; |
898 | } // for (Int_t j=0; |
899 | for (Int_t ipix=0; ipix<nPix; ipix++) if (probi[ipix] < 0.01) pixPtr->SetCharge(0); // "invisible" pixel |
0df3ca52 |
900 | |
901 | // MLEM algorithm |
2b1e4f0e |
902 | Mlem(coef, probi, 15); |
0df3ca52 |
903 | |
cd747ddb |
904 | Double_t xylim[4] = {999, 999, 999, 999}; |
0df3ca52 |
905 | for (Int_t ipix=0; ipix<nPix; ipix++) { |
906 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(ipix); |
cc87ebcd |
907 | //cout << ipix+1; pixPtr->Print(); |
0df3ca52 |
908 | for (Int_t i=0; i<4; i++) |
909 | xylim[i] = TMath::Min (xylim[i], (i%2 ? -1 : 1)*pixPtr->Coord(i/2)); |
0df3ca52 |
910 | } |
911 | for (Int_t i=0; i<4; i++) { |
2b1e4f0e |
912 | xylim[i] -= pixPtr->Size(i/2); if (fDebug) cout << (i%2 ? -1 : 1)*xylim[i] << " "; } |
913 | if (fDebug) cout << endl; |
0df3ca52 |
914 | |
2b1e4f0e |
915 | // Adjust histogram to approximately the same limits as for the pads |
0df3ca52 |
916 | // (for good presentation) |
1af223d7 |
917 | if (fDraw) fDraw->AdjustHist(xylim, pixPtr); |
918 | |
0df3ca52 |
919 | Int_t nx = TMath::Nint ((-xylim[1]-xylim[0])/pixPtr->Size(0)/2); |
920 | Int_t ny = TMath::Nint ((-xylim[3]-xylim[2])/pixPtr->Size(1)/2); |
2b1e4f0e |
921 | |
0df3ca52 |
922 | mlem = new TH2D("mlem","mlem",nx,xylim[0],-xylim[1],ny,xylim[2],-xylim[3]); |
923 | for (Int_t ipix=0; ipix<nPix; ipix++) { |
924 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(ipix); |
925 | mlem->Fill(pixPtr->Coord(0),pixPtr->Coord(1),pixPtr->Charge()); |
926 | } |
1af223d7 |
927 | if (fDraw) fDraw->DrawHist("c2", mlem); |
0df3ca52 |
928 | |
929 | // Check if the total charge of pixels is too low |
930 | Double_t qTot = 0; |
931 | for (Int_t i=0; i<nPix; i++) { |
932 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i); |
933 | qTot += pixPtr->Charge(); |
934 | } |
2b1e4f0e |
935 | if (qTot < 1.e-4 || npadOK < 3 && qTot < 7) { |
0df3ca52 |
936 | delete [] coef; delete [] probi; coef = 0; probi = 0; |
937 | fPixArray->Delete(); |
2b1e4f0e |
938 | for (Int_t i=0; i<npadTot; i++) if (fPadIJ[1][i] == 0) fPadIJ[1][i] = -1; |
0df3ca52 |
939 | return kFALSE; |
940 | } |
941 | |
942 | // Plot data - expectation |
943 | /* |
944 | Double_t x, y, cont; |
945 | for (Int_t j=0; j<npadTot; j++) { |
946 | Double_t sum1 = 0; |
947 | for (Int_t i=0; i<nPix; i++) { |
948 | // Caculate expectation |
949 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i); |
950 | sum1 += pixPtr->Charge()*coef[j*nPix+i]; |
951 | } |
0627f609 |
952 | sum1 = TMath::Min (sum1,fgkSaturation); |
0df3ca52 |
953 | x = fXyq[0][j]; |
954 | y = fXyq[1][j]; |
955 | cath = fPadIJ[0][j]; |
956 | Int_t ihist = cath*2; |
957 | ix = fHist[ihist]->GetXaxis()->FindBin(x); |
958 | iy = fHist[ihist]->GetYaxis()->FindBin(y); |
959 | cont = fHist[ihist]->GetCellContent(ix,iy); |
960 | if (cont == 0 && fHist[ihist+1]) { |
961 | ihist += 1; |
962 | ix = fHist[ihist]->GetXaxis()->FindBin(x); |
963 | iy = fHist[ihist]->GetYaxis()->FindBin(y); |
964 | } |
965 | fHist[ihist]->SetBinContent(ix,iy,fXyq[2][j]-sum1); |
966 | } |
967 | ((TCanvas*)gROOT->FindObject("c1"))->cd(1); |
968 | //gPad->SetTheta(55); |
969 | //gPad->SetPhi(30); |
970 | //mlem->Draw("lego1"); |
971 | gPad->Modified(); |
972 | ((TCanvas*)gROOT->FindObject("c1"))->cd(2); |
973 | gPad->Modified(); |
974 | */ |
975 | |
2b1e4f0e |
976 | if (iSimple) { |
977 | // Simple cluster - skip further passes thru EM-procedure |
2b1e4f0e |
978 | Simple(); |
979 | delete [] coef; delete [] probi; coef = 0; probi = 0; |
980 | fPixArray->Delete(); |
981 | return kTRUE; |
982 | } |
983 | |
0df3ca52 |
984 | // Calculate position of the center-of-gravity around the maximum pixel |
985 | Double_t xyCOG[2]; |
986 | FindCOG(mlem, xyCOG); |
987 | |
988 | if (TMath::Min(pixPtr->Size(0),pixPtr->Size(1)) < 0.07 && pixPtr->Size(0) > pixPtr->Size(1)) break; |
2b1e4f0e |
989 | //if (TMath::Min(pixPtr->Size(0),pixPtr->Size(1)) < 0.007 && pixPtr->Size(0) > pixPtr->Size(1)) break; |
0df3ca52 |
990 | //if (TMath::Min(pixPtr->Size(0),pixPtr->Size(1)) >= 0.07 || pixPtr->Size(0) < pixPtr->Size(1)) { |
991 | // Sort pixels according to the charge |
992 | fPixArray->Sort(); |
993 | /* |
994 | for (Int_t i=0; i<nPix; i++) { |
995 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i); |
996 | cout << i+1; pixPtr->Print(); |
997 | } |
998 | */ |
999 | Double_t pixMin = 0.01*((AliMUONPixel*)fPixArray->UncheckedAt(0))->Charge(); |
1000 | pixMin = TMath::Min (pixMin,50.); |
1001 | |
1002 | // Decrease pixel size and shift pixels to make them centered at |
1003 | // the maximum one |
1004 | indx = (pixPtr->Size(0)>pixPtr->Size(1)) ? 0 : 1; |
1005 | Double_t width = 0, shift[2]={0}; |
1006 | ix = 1; |
1007 | for (Int_t i=0; i<4; i++) xylim[i] = 999; |
1008 | Int_t nPix1 = nPix; nPix = 0; |
1009 | for (Int_t ipix=0; ipix<nPix1; ipix++) { |
1010 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(ipix); |
1011 | if (nPix >= npadOK) { // too many pixels already |
1012 | fPixArray->RemoveAt(ipix); |
1013 | delete pixPtr; |
1014 | continue; |
1015 | } |
1016 | if (pixPtr->Charge() < pixMin) { // low charge |
1017 | fPixArray->RemoveAt(ipix); |
1018 | delete pixPtr; |
1019 | continue; |
1020 | } |
1021 | for (Int_t i=0; i<2; i++) { |
1022 | if (!i) { |
1023 | pixPtr->SetCharge(10); |
1024 | pixPtr->SetSize(indx, pixPtr->Size(indx)/2); |
1025 | width = -pixPtr->Size(indx); |
1026 | pixPtr->Shift(indx, width); |
1027 | // Shift pixel position |
1028 | if (ix) { |
1029 | ix = 0; |
1030 | for (Int_t j=0; j<2; j++) { |
1031 | shift[j] = pixPtr->Coord(j) - xyCOG[j]; |
1032 | shift[j] -= ((Int_t)(shift[j]/pixPtr->Size(j)/2))*pixPtr->Size(j)*2; |
1033 | } |
1034 | //cout << ipix << " " << i << " " << shift[0] << " " << shift[1] << endl; |
1035 | } // if (ix) |
1036 | pixPtr->Shift(0, -shift[0]); |
1037 | pixPtr->Shift(1, -shift[1]); |
1038 | } else { |
1039 | pixPtr = new AliMUONPixel(*pixPtr); |
1040 | pixPtr->Shift(indx, -2*width); |
1041 | fPixArray->Add((TObject*)pixPtr); |
1042 | } // else |
1043 | //pixPtr->Print(); |
1044 | for (Int_t i=0; i<4; i++) |
1045 | xylim[i] = TMath::Min (xylim[i], (i%2 ? -1 : 1)*pixPtr->Coord(i/2)); |
1046 | } // for (Int_t i=0; i<2; |
1047 | nPix += 2; |
1048 | } // for (Int_t ipix=0; |
1049 | |
1050 | fPixArray->Compress(); |
1051 | nPix = fPixArray->GetEntriesFast(); |
1052 | |
1053 | // Remove excessive pixels |
1054 | if (nPix > npadOK) { |
1055 | for (Int_t ipix=npadOK; ipix<nPix; ipix++) { |
1056 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(ipix); |
1057 | fPixArray->RemoveAt(ipix); |
1058 | delete pixPtr; |
1059 | } |
1060 | } else { |
1061 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(0); |
1062 | // add pixels if the maximum is at the limit of pixel area |
1063 | // start from Y-direction |
1064 | Int_t j = 0; |
1065 | for (Int_t i=3; i>-1; i--) { |
1066 | if (nPix < npadOK && |
1067 | TMath::Abs((i%2 ? -1 : 1)*xylim[i]-xyCOG[i/2]) < pixPtr->Size(i/2)) { |
1068 | pixPtr = new AliMUONPixel(*pixPtr); |
1069 | pixPtr->SetCoord(i/2, xyCOG[i/2]+(i%2 ? 2:-2)*pixPtr->Size(i/2)); |
1070 | j = TMath::Even (i/2); |
1071 | pixPtr->SetCoord(j, xyCOG[j]); |
1072 | fPixArray->Add((TObject*)pixPtr); |
1073 | nPix++; |
1074 | } |
1075 | } |
1076 | } // else |
1077 | |
1078 | fPixArray->Compress(); |
1079 | nPix = fPixArray->GetEntriesFast(); |
1080 | delete [] coef; delete [] probi; coef = 0; probi = 0; |
1081 | } // while (1) |
1082 | |
1083 | // remove pixels with low signal or low visibility |
1084 | // Cuts are empirical !!! |
1085 | Double_t thresh = TMath::Max (mlem->GetMaximum()/100.,1.); |
1086 | thresh = TMath::Min (thresh,50.); |
1087 | Double_t cmax = -1, charge = 0; |
1088 | for (Int_t i=0; i<nPix; i++) cmax = TMath::Max (cmax,probi[i]); |
2b1e4f0e |
1089 | //cout << thresh << " " << cmax << " " << cmax*0.9 << endl; |
0df3ca52 |
1090 | // Mark pixels which should be removed |
1091 | for (Int_t i=0; i<nPix; i++) { |
1092 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i); |
1093 | charge = pixPtr->Charge(); |
1094 | if (charge < thresh) pixPtr->SetCharge(-charge); |
2b1e4f0e |
1095 | //else if (cmax > 1.91) { |
1096 | // if (probi[i] < 1.9) pixPtr->SetCharge(-charge); |
1097 | //} |
1098 | //AZ else if (probi[i] < cmax*0.9) pixPtr->SetCharge(-charge); |
0627f609 |
1099 | //18-01-06 else if (probi[i] < cmax*0.8) pixPtr->SetCharge(-charge); |
2b1e4f0e |
1100 | //cout << i << " " << pixPtr->Coord(0) << " " << pixPtr->Coord(1) << " " << charge << " " << probi[i] << endl; |
0df3ca52 |
1101 | } |
1102 | // Move charge of removed pixels to their nearest neighbour (to keep total charge the same) |
1103 | Int_t near = 0; |
1104 | for (Int_t i=0; i<nPix; i++) { |
1105 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i); |
1106 | charge = pixPtr->Charge(); |
1107 | if (charge > 0) continue; |
1108 | near = FindNearest(pixPtr); |
1109 | pixPtr->SetCharge(0); |
2b1e4f0e |
1110 | probi[i] = 0; // make it "invisible" |
0df3ca52 |
1111 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(near); |
2b1e4f0e |
1112 | pixPtr->SetCharge(pixPtr->Charge() + (-charge)); |
0df3ca52 |
1113 | } |
2b1e4f0e |
1114 | Mlem(coef,probi,2); |
0df3ca52 |
1115 | // Update histogram |
1116 | for (Int_t i=0; i<nPix; i++) { |
1117 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i); |
1118 | ix = mlem->GetXaxis()->FindBin(pixPtr->Coord(0)); |
1119 | iy = mlem->GetYaxis()->FindBin(pixPtr->Coord(1)); |
1120 | mlem->SetBinContent(ix, iy, pixPtr->Charge()); |
1121 | } |
1af223d7 |
1122 | if (fDraw) fDraw->DrawHist("c2", mlem); |
0df3ca52 |
1123 | |
0df3ca52 |
1124 | // Try to split into clusters |
1125 | Bool_t ok = kTRUE; |
1126 | if (mlem->GetSum() < 1) ok = kFALSE; |
1127 | else Split(mlem, coef); |
1128 | delete [] coef; delete [] probi; coef = 0; probi = 0; |
1129 | fPixArray->Delete(); |
1130 | return ok; |
1131 | } |
1132 | |
1133 | //_____________________________________________________________________________ |
2b1e4f0e |
1134 | void AliMUONClusterFinderAZ::Mlem(Double_t *coef, Double_t *probi, Int_t nIter) |
0df3ca52 |
1135 | { |
1136 | // Use MLEM to find pixel charges |
1137 | |
1138 | Int_t nPix = fPixArray->GetEntriesFast(); |
1139 | Int_t npad = fnPads[0] + fnPads[1]; |
1140 | Double_t *probi1 = new Double_t [nPix]; |
2b1e4f0e |
1141 | Double_t probMax = 0; |
0df3ca52 |
1142 | Int_t indx, indx1; |
1143 | AliMUONPixel *pixPtr; |
1144 | |
2b1e4f0e |
1145 | for (Int_t ipix=0; ipix<nPix; ipix++) if (probi[ipix] > probMax) probMax = probi[ipix]; |
1146 | for (Int_t iter=0; iter<nIter; iter++) { |
0df3ca52 |
1147 | // Do iterations |
1148 | for (Int_t ipix=0; ipix<nPix; ipix++) { |
1149 | // Correct each pixel |
1150 | if (probi[ipix] < 0.01) continue; // skip "invisible" pixel |
1151 | Double_t sum = 0; |
2b1e4f0e |
1152 | //probi1[ipix] = probi[ipix]; |
1153 | probi1[ipix] = probMax; |
0df3ca52 |
1154 | for (Int_t j=0; j<npad; j++) { |
1155 | if (fPadIJ[1][j] < 0) continue; |
1156 | Double_t sum1 = 0; |
1157 | indx1 = j*nPix; |
1158 | indx = indx1 + ipix; |
1159 | for (Int_t i=0; i<nPix; i++) { |
1160 | // Caculate expectation |
1161 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i); |
1162 | sum1 += pixPtr->Charge()*coef[indx1+i]; |
1163 | } // for (Int_t i=0; |
0627f609 |
1164 | if (fXyq[2][j] > fgkSaturation-1 && sum1 > fXyq[2][j]) { probi1[ipix] -= coef[indx]; continue; } // correct for pad charge overflows |
0df3ca52 |
1165 | //cout << sum1 << " " << fXyq[2][j] << " " << coef[j*nPix+ipix] << endl; |
1166 | if (coef[indx] > 1.e-6) sum += fXyq[2][j]*coef[indx]/sum1; |
1167 | } // for (Int_t j=0; |
1168 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(ipix); |
1169 | if (probi1[ipix] > 1.e-6) pixPtr->SetCharge(pixPtr->Charge()*sum/probi1[ipix]); |
1170 | } // for (Int_t ipix=0; |
1171 | } // for (Int_t iter=0; |
1172 | delete [] probi1; |
1173 | return; |
1174 | } |
1175 | |
1176 | //_____________________________________________________________________________ |
1177 | void AliMUONClusterFinderAZ::FindCOG(TH2D *mlem, Double_t *xyc) |
1178 | { |
1179 | // Calculate position of the center-of-gravity around the maximum pixel |
1180 | |
1181 | Int_t ixmax, iymax, ix, nsumx=0, nsumy=0, nsum=0; |
1182 | Int_t i1 = -9, j1 = -9; |
1183 | mlem->GetMaximumBin(ixmax,iymax,ix); |
1184 | Int_t nx = mlem->GetNbinsX(); |
1185 | Int_t ny = mlem->GetNbinsY(); |
1186 | Double_t thresh = mlem->GetMaximum()/10; |
1187 | Double_t x, y, cont, xq=0, yq=0, qq=0; |
1188 | |
1189 | for (Int_t i=TMath::Max(1,iymax-1); i<=TMath::Min(ny,iymax+1); i++) { |
1190 | y = mlem->GetYaxis()->GetBinCenter(i); |
1191 | for (Int_t j=TMath::Max(1,ixmax-1); j<=TMath::Min(nx,ixmax+1); j++) { |
1192 | cont = mlem->GetCellContent(j,i); |
1193 | if (cont < thresh) continue; |
1194 | if (i != i1) {i1 = i; nsumy++;} |
1195 | if (j != j1) {j1 = j; nsumx++;} |
1196 | x = mlem->GetXaxis()->GetBinCenter(j); |
1197 | xq += x*cont; |
1198 | yq += y*cont; |
1199 | qq += cont; |
1200 | nsum++; |
1201 | } |
1202 | } |
1203 | |
1204 | Double_t cmax = 0; |
1205 | Int_t i2 = 0, j2 = 0; |
1206 | x = y = 0; |
1207 | if (nsumy == 1) { |
1208 | // one bin in Y - add one more (with the largest signal) |
1209 | for (Int_t i=TMath::Max(1,iymax-1); i<=TMath::Min(ny,iymax+1); i++) { |
1210 | if (i == iymax) continue; |
1211 | for (Int_t j=TMath::Max(1,ixmax-1); j<=TMath::Min(nx,ixmax+1); j++) { |
1212 | cont = mlem->GetCellContent(j,i); |
1213 | if (cont > cmax) { |
1214 | cmax = cont; |
1215 | x = mlem->GetXaxis()->GetBinCenter(j); |
1216 | y = mlem->GetYaxis()->GetBinCenter(i); |
1217 | i2 = i; |
1218 | j2 = j; |
1219 | } |
1220 | } |
1221 | } |
1222 | xq += x*cmax; |
1223 | yq += y*cmax; |
1224 | qq += cmax; |
1225 | if (i2 != i1) nsumy++; |
1226 | if (j2 != j1) nsumx++; |
1227 | nsum++; |
1228 | } // if (nsumy == 1) |
1229 | |
1230 | if (nsumx == 1) { |
1231 | // one bin in X - add one more (with the largest signal) |
1232 | cmax = x = y = 0; |
1233 | for (Int_t j=TMath::Max(1,ixmax-1); j<=TMath::Min(nx,ixmax+1); j++) { |
1234 | if (j == ixmax) continue; |
1235 | for (Int_t i=TMath::Max(1,iymax-1); i<=TMath::Min(ny,iymax+1); i++) { |
1236 | cont = mlem->GetCellContent(j,i); |
1237 | if (cont > cmax) { |
1238 | cmax = cont; |
1239 | x = mlem->GetXaxis()->GetBinCenter(j); |
1240 | y = mlem->GetYaxis()->GetBinCenter(i); |
1241 | i2 = i; |
1242 | j2 = j; |
1243 | } |
1244 | } |
1245 | } |
1246 | xq += x*cmax; |
1247 | yq += y*cmax; |
1248 | qq += cmax; |
1249 | if (i2 != i1) nsumy++; |
1250 | if (j2 != j1) nsumx++; |
1251 | nsum++; |
1252 | } // if (nsumx == 1) |
1253 | |
1254 | xyc[0] = xq/qq; xyc[1] = yq/qq; |
2b1e4f0e |
1255 | if (fDebug) cout << xyc[0] << " " << xyc[1] << " " << qq << " " << nsum << " " << nsumx << " " << nsumy << endl; |
0df3ca52 |
1256 | return; |
1257 | } |
1258 | |
1259 | //_____________________________________________________________________________ |
1260 | Int_t AliMUONClusterFinderAZ::FindNearest(AliMUONPixel *pixPtr0) |
1261 | { |
1262 | // Find the pixel nearest to the given one |
1263 | // (algorithm may be not very efficient) |
1264 | |
1265 | Int_t nPix = fPixArray->GetEntriesFast(), imin = 0; |
1266 | Double_t rmin = 99999, dx = 0, dy = 0, r = 0; |
1267 | Double_t xc = pixPtr0->Coord(0), yc = pixPtr0->Coord(1); |
1268 | AliMUONPixel *pixPtr; |
1269 | |
1270 | for (Int_t i=0; i<nPix; i++) { |
1271 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i); |
1272 | if (pixPtr->Charge() < 0.5) continue; |
1273 | dx = (xc - pixPtr->Coord(0)) / pixPtr->Size(0); |
1274 | dy = (yc - pixPtr->Coord(1)) / pixPtr->Size(1); |
1275 | r = dx *dx + dy * dy; |
1276 | if (r < rmin) { rmin = r; imin = i; } |
1277 | } |
1278 | return imin; |
1279 | } |
1280 | |
1281 | //_____________________________________________________________________________ |
1282 | void AliMUONClusterFinderAZ::Split(TH2D *mlem, Double_t *coef) |
1283 | { |
1284 | // The main steering function to work with clusters of pixels in anode |
1285 | // plane (find clusters, decouple them from each other, merge them (if |
1286 | // necessary), pick up coupled pads, call the fitting function) |
1287 | |
1288 | Int_t nx = mlem->GetNbinsX(); |
1289 | Int_t ny = mlem->GetNbinsY(); |
1290 | Int_t nPix = fPixArray->GetEntriesFast(); |
1291 | |
1292 | Bool_t *used = new Bool_t[ny*nx]; |
1293 | Double_t cont; |
1294 | Int_t nclust = 0, indx, indx1; |
1295 | |
1296 | for (Int_t i=0; i<ny*nx; i++) used[i] = kFALSE; |
1297 | |
1298 | TObjArray *clusters[200]={0}; |
1299 | TObjArray *pix; |
1300 | |
1301 | // Find clusters of histogram bins (easier to work in 2-D space) |
1302 | for (Int_t i=1; i<=ny; i++) { |
1303 | for (Int_t j=1; j<=nx; j++) { |
1304 | indx = (i-1)*nx + j - 1; |
1305 | if (used[indx]) continue; |
1306 | cont = mlem->GetCellContent(j,i); |
1307 | if (cont < 0.5) continue; |
1308 | pix = new TObjArray(20); |
1309 | used[indx] = 1; |
1310 | pix->Add(BinToPix(mlem,j,i)); |
1311 | AddBin(mlem, i, j, 0, used, pix); // recursive call |
2b1e4f0e |
1312 | if (nclust >= 200) AliFatal(" Too many clusters !!!"); |
0df3ca52 |
1313 | clusters[nclust++] = pix; |
0df3ca52 |
1314 | } // for (Int_t j=1; j<=nx; j++) { |
1315 | } // for (Int_t i=1; i<=ny; |
2b1e4f0e |
1316 | if (fDebug) cout << nclust << endl; |
0df3ca52 |
1317 | delete [] used; used = 0; |
1318 | |
1319 | // Compute couplings between clusters and clusters to pads |
1320 | Int_t npad = fnPads[0] + fnPads[1]; |
1321 | |
2b1e4f0e |
1322 | // Write out some information for algorithm development |
1323 | Int_t cath=0, npadx[2]={0}, npady[2]={0}; |
1324 | Double_t xlow[2]={9999,9999}, xhig[2]={-9999,-9999}; |
1325 | Double_t ylow[2]={9999,9999}, yhig[2]={-9999,-9999}; |
1326 | for (Int_t j=0; j<npad; j++) { |
1327 | if (fXyq[3][j] < 0) continue; // exclude virtual pads |
1328 | cath = fPadIJ[0][j]; |
1329 | if (fXyq[0][j] < xlow[cath]-0.001) { |
1330 | if (fXyq[0][j]+fXyq[3][j] <= xlow[cath] && npadx[cath]) npadx[cath]++; |
1331 | xlow[cath] = fXyq[0][j]; |
1332 | } |
1333 | if (fXyq[0][j] > xhig[cath]+0.001) { |
1334 | if (fXyq[0][j]-fXyq[3][j] >= xhig[cath]) npadx[cath]++; |
1335 | xhig[cath] = fXyq[0][j]; |
1336 | } |
1337 | if (fXyq[1][j] < ylow[cath]-0.001) { |
1338 | if (fXyq[1][j]+fXyq[4][j] <= ylow[cath] && npady[cath]) npady[cath]++; |
1339 | ylow[cath] = fXyq[1][j]; |
1340 | } |
1341 | if (fXyq[1][j] > yhig[cath]+0.001) { |
1342 | if (fXyq[1][j]-fXyq[4][j] >= yhig[cath]) npady[cath]++; |
1343 | yhig[cath] = fXyq[1][j]; |
1344 | } |
1345 | } |
1346 | //if (lun1) fprintf(lun1," %4d %2d %3d %3d %3d %3d \n",gAlice->GetHeader()->GetEvent(),AliMUONClusterInput::Instance()->Chamber(), npadx[0], npadx[1], npady[0], npady[1]); |
1347 | |
0df3ca52 |
1348 | // Exclude pads with overflows |
1349 | for (Int_t j=0; j<npad; j++) { |
0627f609 |
1350 | if (fXyq[2][j] > fgkSaturation-1) fPadIJ[1][j] = -5; |
0df3ca52 |
1351 | else fPadIJ[1][j] = 0; |
1352 | } |
1353 | |
1354 | // Compute couplings of clusters to pads |
c1aed84f |
1355 | TMatrixD *aijclupad = new TMatrixD(nclust,npad); |
1356 | *aijclupad = 0; |
0df3ca52 |
1357 | Int_t npxclu; |
1358 | for (Int_t iclust=0; iclust<nclust; iclust++) { |
1359 | pix = clusters[iclust]; |
1360 | npxclu = pix->GetEntriesFast(); |
1361 | for (Int_t i=0; i<npxclu; i++) { |
1362 | indx = fPixArray->IndexOf(pix->UncheckedAt(i)); |
1363 | for (Int_t j=0; j<npad; j++) { |
2b1e4f0e |
1364 | if (fPadIJ[1][j] < 0 && fPadIJ[1][j] != -5) continue; |
343146bf |
1365 | if (coef[j*nPix+indx] < fgkCouplMin) continue; |
c1aed84f |
1366 | (*aijclupad)(iclust,j) += coef[j*nPix+indx]; |
0df3ca52 |
1367 | } |
1368 | } |
1369 | } |
1370 | // Compute couplings between clusters |
c1aed84f |
1371 | TMatrixD *aijcluclu = new TMatrixD(nclust,nclust); |
1372 | *aijcluclu = 0; |
0df3ca52 |
1373 | for (Int_t iclust=0; iclust<nclust; iclust++) { |
1374 | for (Int_t j=0; j<npad; j++) { |
1375 | // Exclude overflows |
1376 | if (fPadIJ[1][j] < 0) continue; |
343146bf |
1377 | if ((*aijclupad)(iclust,j) < fgkCouplMin) continue; |
0df3ca52 |
1378 | for (Int_t iclust1=iclust+1; iclust1<nclust; iclust1++) { |
343146bf |
1379 | if ((*aijclupad)(iclust1,j) < fgkCouplMin) continue; |
c1aed84f |
1380 | (*aijcluclu)(iclust,iclust1) += |
1381 | TMath::Sqrt ((*aijclupad)(iclust,j)*(*aijclupad)(iclust1,j)); |
0df3ca52 |
1382 | } |
1383 | } |
1384 | } |
1385 | for (Int_t iclust=0; iclust<nclust; iclust++) { |
1386 | for (Int_t iclust1=iclust+1; iclust1<nclust; iclust1++) { |
c1aed84f |
1387 | (*aijcluclu)(iclust1,iclust) = (*aijcluclu)(iclust,iclust1); |
0df3ca52 |
1388 | } |
1389 | } |
1390 | |
2b1e4f0e |
1391 | if (fDebug && nclust > 1) aijcluclu->Print(); |
0df3ca52 |
1392 | |
1393 | // Find groups of coupled clusters |
1394 | used = new Bool_t[nclust]; |
1395 | for (Int_t i=0; i<nclust; i++) used[i] = kFALSE; |
1396 | Int_t *clustNumb = new Int_t[nclust]; |
1397 | Int_t nCoupled, nForFit, minGroup[3], clustFit[3], nfit = 0; |
1398 | Double_t parOk[8]; |
1399 | |
1400 | for (Int_t igroup=0; igroup<nclust; igroup++) { |
1401 | if (used[igroup]) continue; |
1402 | used[igroup] = kTRUE; |
1403 | clustNumb[0] = igroup; |
1404 | nCoupled = 1; |
1405 | // Find group of coupled clusters |
c1aed84f |
1406 | AddCluster(igroup, nclust, aijcluclu, used, clustNumb, nCoupled); // recursive |
2b1e4f0e |
1407 | if (fDebug) { |
1408 | cout << " nCoupled: " << nCoupled << endl; |
1409 | for (Int_t i=0; i<nCoupled; i++) cout << clustNumb[i] << " "; cout << endl; |
1410 | } |
1411 | fnCoupled = nCoupled; |
0df3ca52 |
1412 | |
1413 | while (nCoupled > 0) { |
1414 | |
1415 | if (nCoupled < 4) { |
1416 | nForFit = nCoupled; |
1417 | for (Int_t i=0; i<nCoupled; i++) clustFit[i] = clustNumb[i]; |
1418 | } else { |
1419 | // Too many coupled clusters to fit - try to decouple them |
1420 | // Find the lowest coupling of 1, 2, min(3,nLinks/2) pixels with |
1421 | // all the others in the group |
1422 | for (Int_t j=0; j<3; j++) minGroup[j] = -1; |
c1aed84f |
1423 | Double_t coupl = MinGroupCoupl(nCoupled, clustNumb, aijcluclu, minGroup); |
0df3ca52 |
1424 | |
1425 | // Flag clusters for fit |
1426 | nForFit = 0; |
1427 | while (minGroup[nForFit] >= 0 && nForFit < 3) { |
2b1e4f0e |
1428 | if (fDebug) cout << clustNumb[minGroup[nForFit]] << " "; |
0df3ca52 |
1429 | clustFit[nForFit] = clustNumb[minGroup[nForFit]]; |
1430 | clustNumb[minGroup[nForFit]] -= 999; |
1431 | nForFit++; |
1432 | } |
2b1e4f0e |
1433 | if (fDebug) cout << nForFit << " " << coupl << endl; |
0df3ca52 |
1434 | } // else |
1435 | |
1436 | // Select pads for fit. |
c1aed84f |
1437 | if (SelectPad(nCoupled, nForFit, clustNumb, clustFit, aijclupad) < 3 && nCoupled > 1) { |
0df3ca52 |
1438 | // Deselect pads |
2b1e4f0e |
1439 | for (Int_t j=0; j<npad; j++) { |
1440 | if (TMath::Abs(fPadIJ[1][j]) == 1) fPadIJ[1][j] = 0; |
1441 | if (TMath::Abs(fPadIJ[1][j]) == -9) fPadIJ[1][j] = -5; |
1442 | } |
0df3ca52 |
1443 | // Merge the failed cluster candidates (with too few pads to fit) with |
1444 | // the one with the strongest coupling |
c1aed84f |
1445 | Merge(nForFit, nCoupled, clustNumb, clustFit, clusters, aijcluclu, aijclupad); |
0df3ca52 |
1446 | } else { |
1447 | // Do the fit |
0627f609 |
1448 | nfit = Fit(0, nForFit, clustFit, clusters, parOk); |
0df3ca52 |
1449 | } |
1450 | |
1451 | // Subtract the fitted charges from pads with strong coupling and/or |
1452 | // return pads for further use |
1453 | UpdatePads(nfit, parOk); |
1454 | |
1455 | // Mark used pads |
2b1e4f0e |
1456 | for (Int_t j=0; j<npad; j++) { |
1457 | if (fPadIJ[1][j] == 1) fPadIJ[1][j] = -1; |
1458 | if (fPadIJ[1][j] == -9) fPadIJ[1][j] = -5; |
1459 | } |
0df3ca52 |
1460 | |
1461 | // Sort the clusters (move to the right the used ones) |
1462 | Int_t beg = 0, end = nCoupled - 1; |
1463 | while (beg < end) { |
1464 | if (clustNumb[beg] >= 0) { beg++; continue; } |
1465 | for (Int_t j=end; j>beg; j--) { |
1466 | if (clustNumb[j] < 0) continue; |
1467 | end = j - 1; |
1468 | indx = clustNumb[beg]; |
1469 | clustNumb[beg] = clustNumb[j]; |
1470 | clustNumb[j] = indx; |
1471 | break; |
1472 | } |
1473 | beg++; |
1474 | } |
1475 | |
1476 | nCoupled -= nForFit; |
1477 | if (nCoupled > 3) { |
1478 | // Remove couplings of used clusters |
1479 | for (Int_t iclust=nCoupled; iclust<nCoupled+nForFit; iclust++) { |
1480 | indx = clustNumb[iclust] + 999; |
1481 | for (Int_t iclust1=0; iclust1<nCoupled; iclust1++) { |
1482 | indx1 = clustNumb[iclust1]; |
c1aed84f |
1483 | (*aijcluclu)(indx,indx1) = (*aijcluclu)(indx1,indx) = 0; |
0df3ca52 |
1484 | } |
1485 | } |
1486 | |
1487 | // Update the remaining clusters couplings (exclude couplings from |
1488 | // the used pads) |
1489 | for (Int_t j=0; j<npad; j++) { |
1490 | if (fPadIJ[1][j] != -1) continue; |
1491 | for (Int_t iclust=0; iclust<nCoupled; iclust++) { |
1492 | indx = clustNumb[iclust]; |
343146bf |
1493 | if ((*aijclupad)(indx,j) < fgkCouplMin) continue; |
0df3ca52 |
1494 | for (Int_t iclust1=iclust+1; iclust1<nCoupled; iclust1++) { |
1495 | indx1 = clustNumb[iclust1]; |
343146bf |
1496 | if ((*aijclupad)(indx1,j) < fgkCouplMin) continue; |
0df3ca52 |
1497 | // Check this |
c1aed84f |
1498 | (*aijcluclu)(indx,indx1) -= |
1499 | TMath::Sqrt ((*aijclupad)(indx,j)*(*aijclupad)(indx1,j)); |
1500 | (*aijcluclu)(indx1,indx) = (*aijcluclu)(indx,indx1); |
0df3ca52 |
1501 | } |
1502 | } |
2b1e4f0e |
1503 | fPadIJ[1][j] = -8; |
0df3ca52 |
1504 | } // for (Int_t j=0; j<npad; |
1505 | } // if (nCoupled > 3) |
1506 | } // while (nCoupled > 0) |
1507 | } // for (Int_t igroup=0; igroup<nclust; |
1508 | |
c1aed84f |
1509 | aijcluclu->Delete(); aijclupad->Delete(); |
0df3ca52 |
1510 | for (Int_t iclust=0; iclust<nclust; iclust++) { |
1511 | pix = clusters[iclust]; |
1512 | pix->Clear(); |
1513 | delete pix; pix = 0; |
1514 | } |
1515 | delete [] clustNumb; clustNumb = 0; delete [] used; used = 0; |
1516 | } |
1517 | |
1518 | //_____________________________________________________________________________ |
1519 | void AliMUONClusterFinderAZ::AddBin(TH2D *mlem, Int_t ic, Int_t jc, Int_t mode, Bool_t *used, TObjArray *pix) |
1520 | { |
1521 | // Add a bin to the cluster |
1522 | |
1523 | Int_t nx = mlem->GetNbinsX(); |
1524 | Int_t ny = mlem->GetNbinsY(); |
1525 | Double_t cont1, cont = mlem->GetCellContent(jc,ic); |
1526 | AliMUONPixel *pixPtr = 0; |
1527 | |
1528 | for (Int_t i=TMath::Max(ic-1,1); i<=TMath::Min(ic+1,ny); i++) { |
1529 | for (Int_t j=TMath::Max(jc-1,1); j<=TMath::Min(jc+1,nx); j++) { |
1530 | if (i != ic && j != jc) continue; |
1531 | if (used[(i-1)*nx+j-1]) continue; |
1532 | cont1 = mlem->GetCellContent(j,i); |
1533 | if (mode && cont1 > cont) continue; |
1534 | used[(i-1)*nx+j-1] = kTRUE; |
1535 | if (cont1 < 0.5) continue; |
1536 | if (pix) pix->Add(BinToPix(mlem,j,i)); |
1537 | else { |
1538 | pixPtr = new AliMUONPixel (mlem->GetXaxis()->GetBinCenter(j), |
1539 | mlem->GetYaxis()->GetBinCenter(i), 0, 0, cont1); |
1540 | fPixArray->Add((TObject*)pixPtr); |
1541 | } |
1542 | AddBin(mlem, i, j, mode, used, pix); // recursive call |
1543 | } |
1544 | } |
1545 | } |
1546 | |
1547 | //_____________________________________________________________________________ |
1548 | TObject* AliMUONClusterFinderAZ::BinToPix(TH2D *mlem, Int_t jc, Int_t ic) |
1549 | { |
1550 | // Translate histogram bin to pixel |
1551 | |
1552 | Double_t yc = mlem->GetYaxis()->GetBinCenter(ic); |
1553 | Double_t xc = mlem->GetXaxis()->GetBinCenter(jc); |
1554 | |
1555 | Int_t nPix = fPixArray->GetEntriesFast(); |
0627f609 |
1556 | AliMUONPixel *pixPtr = NULL; |
0df3ca52 |
1557 | |
1558 | // Compare pixel and bin positions |
1559 | for (Int_t i=0; i<nPix; i++) { |
1560 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i); |
1561 | if (pixPtr->Charge() < 0.5) continue; |
1562 | if (TMath::Abs(pixPtr->Coord(0)-xc)<1.e-4 && TMath::Abs(pixPtr->Coord(1)-yc)<1.e-4) return (TObject*) pixPtr; |
1563 | } |
94eb555e |
1564 | AliError(Form(" Something wrong ??? %f %f ", xc, yc)); |
0df3ca52 |
1565 | return NULL; |
1566 | } |
1567 | |
1568 | //_____________________________________________________________________________ |
c1aed84f |
1569 | void AliMUONClusterFinderAZ::AddCluster(Int_t ic, Int_t nclust, TMatrixD *aijcluclu, Bool_t *used, Int_t *clustNumb, Int_t &nCoupled) |
0df3ca52 |
1570 | { |
1571 | // Add a cluster to the group of coupled clusters |
1572 | |
1573 | for (Int_t i=0; i<nclust; i++) { |
1574 | if (used[i]) continue; |
343146bf |
1575 | if ((*aijcluclu)(i,ic) < fgkCouplMin) continue; |
0df3ca52 |
1576 | used[i] = kTRUE; |
1577 | clustNumb[nCoupled++] = i; |
c1aed84f |
1578 | AddCluster(i, nclust, aijcluclu, used, clustNumb, nCoupled); |
0df3ca52 |
1579 | } |
1580 | } |
1581 | |
1582 | //_____________________________________________________________________________ |
c1aed84f |
1583 | Double_t AliMUONClusterFinderAZ::MinGroupCoupl(Int_t nCoupled, Int_t *clustNumb, TMatrixD *aijcluclu, Int_t *minGroup) |
0df3ca52 |
1584 | { |
1585 | // Find group of clusters with minimum coupling to all the others |
1586 | |
1587 | Int_t i123max = TMath::Min(3,nCoupled/2); |
1588 | Int_t indx, indx1, indx2, indx3, nTot = 0; |
1589 | Double_t *coupl1 = 0, *coupl2 = 0, *coupl3 = 0; |
1590 | |
1591 | for (Int_t i123=1; i123<=i123max; i123++) { |
1592 | |
1593 | if (i123 == 1) { |
1594 | coupl1 = new Double_t [nCoupled]; |
1595 | for (Int_t i=0; i<nCoupled; i++) coupl1[i] = 0; |
1596 | } |
1597 | else if (i123 == 2) { |
1598 | nTot = nCoupled*nCoupled; |
1599 | coupl2 = new Double_t [nTot]; |
1600 | for (Int_t i=0; i<nTot; i++) coupl2[i] = 9999; |
1601 | } else { |
1602 | nTot = nTot*nCoupled; |
1603 | coupl3 = new Double_t [nTot]; |
1604 | for (Int_t i=0; i<nTot; i++) coupl3[i] = 9999; |
1605 | } // else |
1606 | |
1607 | for (Int_t i=0; i<nCoupled; i++) { |
1608 | indx1 = clustNumb[i]; |
1609 | for (Int_t j=i+1; j<nCoupled; j++) { |
1610 | indx2 = clustNumb[j]; |
1611 | if (i123 == 1) { |
c1aed84f |
1612 | coupl1[i] += (*aijcluclu)(indx1,indx2); |
1613 | coupl1[j] += (*aijcluclu)(indx1,indx2); |
0df3ca52 |
1614 | } |
1615 | else if (i123 == 2) { |
1616 | indx = i*nCoupled + j; |
1617 | coupl2[indx] = coupl1[i] + coupl1[j]; |
c1aed84f |
1618 | coupl2[indx] -= 2 * ((*aijcluclu)(indx1,indx2)); |
0df3ca52 |
1619 | } else { |
1620 | for (Int_t k=j+1; k<nCoupled; k++) { |
1621 | indx3 = clustNumb[k]; |
1622 | indx = i*nCoupled*nCoupled + j*nCoupled + k; |
1623 | coupl3[indx] = coupl2[i*nCoupled+j] + coupl1[k]; |
c1aed84f |
1624 | coupl3[indx] -= 2 * ((*aijcluclu)(indx1,indx3)+(*aijcluclu)(indx2,indx3)); |
0df3ca52 |
1625 | } |
1626 | } // else |
1627 | } // for (Int_t j=i+1; |
1628 | } // for (Int_t i=0; |
1629 | } // for (Int_t i123=1; |
1630 | |
1631 | // Find minimum coupling |
1632 | Double_t couplMin = 9999; |
1633 | Int_t locMin = 0; |
1634 | |
1635 | for (Int_t i123=1; i123<=i123max; i123++) { |
1636 | if (i123 == 1) { |
1637 | locMin = TMath::LocMin(nCoupled, coupl1); |
1638 | couplMin = coupl1[locMin]; |
1639 | minGroup[0] = locMin; |
1640 | delete [] coupl1; coupl1 = 0; |
1641 | } |
1642 | else if (i123 == 2) { |
1643 | locMin = TMath::LocMin(nCoupled*nCoupled, coupl2); |
1644 | if (coupl2[locMin] < couplMin) { |
1645 | couplMin = coupl2[locMin]; |
1646 | minGroup[0] = locMin/nCoupled; |
1647 | minGroup[1] = locMin%nCoupled; |
1648 | } |
1649 | delete [] coupl2; coupl2 = 0; |
1650 | } else { |
1651 | locMin = TMath::LocMin(nTot, coupl3); |
1652 | if (coupl3[locMin] < couplMin) { |
1653 | couplMin = coupl3[locMin]; |
1654 | minGroup[0] = locMin/nCoupled/nCoupled; |
1655 | minGroup[1] = locMin%(nCoupled*nCoupled)/nCoupled; |
1656 | minGroup[2] = locMin%nCoupled; |
1657 | } |
1658 | delete [] coupl3; coupl3 = 0; |
1659 | } // else |
1660 | } // for (Int_t i123=1; |
1661 | return couplMin; |
1662 | } |
1663 | |
1664 | //_____________________________________________________________________________ |
c1aed84f |
1665 | Int_t AliMUONClusterFinderAZ::SelectPad(Int_t nCoupled, Int_t nForFit, Int_t *clustNumb, Int_t *clustFit, TMatrixD *aijclupad) |
0df3ca52 |
1666 | { |
1667 | // Select pads for fit. If too many coupled clusters, find pads giving |
1668 | // the strongest coupling with the rest of clusters and exclude them from the fit. |
1669 | |
1670 | Int_t npad = fnPads[0] + fnPads[1]; |
c1aed84f |
1671 | Double_t *padpix = 0; |
0df3ca52 |
1672 | |
1673 | if (nCoupled > 3) { |
c1aed84f |
1674 | padpix = new Double_t[npad]; |
1675 | for (Int_t i=0; i<npad; i++) padpix[i] = 0; |
0df3ca52 |
1676 | } |
1677 | |
1678 | Int_t nOK = 0, indx, indx1; |
1679 | for (Int_t iclust=0; iclust<nForFit; iclust++) { |
1680 | indx = clustFit[iclust]; |
1681 | for (Int_t j=0; j<npad; j++) { |
343146bf |
1682 | if ((*aijclupad)(indx,j) < fgkCouplMin) continue; |
2b1e4f0e |
1683 | if (fPadIJ[1][j] == -5) fPadIJ[1][j] = -9; // flag overflow |
1684 | if (fPadIJ[1][j] < 0) continue; // exclude overflows and used pads |
1685 | if (!fPadIJ[1][j]) { fPadIJ[1][j] = 1; nOK++; } // pad to be used in fit |
0df3ca52 |
1686 | if (nCoupled > 3) { |
1687 | // Check other clusters |
1688 | for (Int_t iclust1=0; iclust1<nCoupled; iclust1++) { |
1689 | indx1 = clustNumb[iclust1]; |
1690 | if (indx1 < 0) continue; |
343146bf |
1691 | if ((*aijclupad)(indx1,j) < fgkCouplMin) continue; |
c1aed84f |
1692 | padpix[j] += (*aijclupad)(indx1,j); |
0df3ca52 |
1693 | } |
1694 | } // if (nCoupled > 3) |
1695 | } // for (Int_t j=0; j<npad; |
1696 | } // for (Int_t iclust=0; iclust<nForFit |
1697 | if (nCoupled < 4) return nOK; |
1698 | |
1699 | Double_t aaa = 0; |
1700 | for (Int_t j=0; j<npad; j++) { |
343146bf |
1701 | if (padpix[j] < fgkCouplMin) continue; |
2b1e4f0e |
1702 | if (fDebug) cout << j << " " << padpix[j] << " " << fXyq[0][j] << " " << fXyq[1][j] << endl; |
c1aed84f |
1703 | aaa += padpix[j]; |
0df3ca52 |
1704 | fPadIJ[1][j] = -1; // exclude pads with strong coupling to the other clusters |
1705 | nOK--; |
1706 | } |
c1aed84f |
1707 | delete [] padpix; padpix = 0; |
0df3ca52 |
1708 | return nOK; |
1709 | } |
1710 | |
1711 | //_____________________________________________________________________________ |
c1aed84f |
1712 | void AliMUONClusterFinderAZ::Merge(Int_t nForFit, Int_t nCoupled, Int_t *clustNumb, Int_t *clustFit, TObjArray **clusters, TMatrixD *aijcluclu, TMatrixD *aijclupad) |
0df3ca52 |
1713 | { |
1714 | // Merge the group of clusters with the one having the strongest coupling with them |
1715 | |
1716 | Int_t indx, indx1, npxclu, npxclu1, imax=0; |
1717 | TObjArray *pix, *pix1; |
1718 | Double_t couplMax; |
1719 | |
1720 | for (Int_t icl=0; icl<nForFit; icl++) { |
1721 | indx = clustFit[icl]; |
1722 | pix = clusters[indx]; |
1723 | npxclu = pix->GetEntriesFast(); |
1724 | couplMax = -1; |
1725 | for (Int_t icl1=0; icl1<nCoupled; icl1++) { |
1726 | indx1 = clustNumb[icl1]; |
1727 | if (indx1 < 0) continue; |
c1aed84f |
1728 | if ((*aijcluclu)(indx,indx1) > couplMax) { |
1729 | couplMax = (*aijcluclu)(indx,indx1); |
0df3ca52 |
1730 | imax = indx1; |
1731 | } |
1732 | } // for (Int_t icl1=0; |
343146bf |
1733 | /*if (couplMax < fgkCouplMin) { |
0df3ca52 |
1734 | cout << " Oops " << couplMax << endl; |
c1aed84f |
1735 | aijcluclu->Print(); |
0df3ca52 |
1736 | cout << icl << " " << indx << " " << npxclu << " " << nLinks << endl; |
1737 | ::exit(0); |
1738 | }*/ |
1739 | // Add to it |
1740 | pix1 = clusters[imax]; |
1741 | npxclu1 = pix1->GetEntriesFast(); |
1742 | // Add pixels |
1743 | for (Int_t i=0; i<npxclu; i++) { pix1->Add(pix->UncheckedAt(i)); pix->RemoveAt(i); } |
2b1e4f0e |
1744 | if (fDebug) cout << " New number of pixels: " << npxclu1 << " " << pix1->GetEntriesFast() << endl; |
0df3ca52 |
1745 | //Add cluster-to-cluster couplings |
c1aed84f |
1746 | //aijcluclu->Print(); |
0df3ca52 |
1747 | for (Int_t icl1=0; icl1<nCoupled; icl1++) { |
1748 | indx1 = clustNumb[icl1]; |
1749 | if (indx1 < 0 || indx1 == imax) continue; |
c1aed84f |
1750 | (*aijcluclu)(indx1,imax) += (*aijcluclu)(indx,indx1); |
1751 | (*aijcluclu)(imax,indx1) = (*aijcluclu)(indx1,imax); |
0df3ca52 |
1752 | } |
c1aed84f |
1753 | (*aijcluclu)(indx,imax) = (*aijcluclu)(imax,indx) = 0; |
1754 | //aijcluclu->Print(); |
0df3ca52 |
1755 | //Add cluster-to-pad couplings |
1756 | for (Int_t j=0; j<fnPads[0]+fnPads[1]; j++) { |
2b1e4f0e |
1757 | if (fPadIJ[1][j] < 0 && fPadIJ[1][j] != -5) continue; // exclude used pads |
c1aed84f |
1758 | (*aijclupad)(imax,j) += (*aijclupad)(indx,j); |
1759 | (*aijclupad)(indx,j) = 0; |
0df3ca52 |
1760 | } |
1761 | } // for (Int_t icl=0; icl<nForFit; |
1762 | } |
1763 | |
1764 | //_____________________________________________________________________________ |
0627f609 |
1765 | Int_t AliMUONClusterFinderAZ::Fit(Int_t iSimple, Int_t nfit, Int_t *clustFit, TObjArray **clusters, Double_t *parOk) |
0df3ca52 |
1766 | { |
1767 | // Find selected clusters to selected pad charges |
1768 | |
1769 | TH2D *mlem = (TH2D*) gROOT->FindObject("mlem"); |
0df3ca52 |
1770 | Double_t xmin = mlem->GetXaxis()->GetXmin() - mlem->GetXaxis()->GetBinWidth(1); |
1771 | Double_t xmax = mlem->GetXaxis()->GetXmax() + mlem->GetXaxis()->GetBinWidth(1); |
1772 | Double_t ymin = mlem->GetYaxis()->GetXmin() - mlem->GetYaxis()->GetBinWidth(1); |
1773 | Double_t ymax = mlem->GetYaxis()->GetXmax() + mlem->GetYaxis()->GetBinWidth(1); |
2b1e4f0e |
1774 | Double_t step[3]={0.01,0.002,0.02}, xPad = 0, yPad = 99999; |
0df3ca52 |
1775 | |
2b1e4f0e |
1776 | // Number of pads to use and number of virtual pads |
0627f609 |
1777 | Int_t npads = 0, nVirtual = 0, nfit0 = nfit; |
2b1e4f0e |
1778 | for (Int_t i=0; i<fnPads[0]+fnPads[1]; i++) { |
2b1e4f0e |
1779 | if (fXyq[3][i] < 0) nVirtual++; |
1780 | if (fPadIJ[1][i] != 1) continue; |
0627f609 |
1781 | if (fXyq[3][i] > 0) { |
1782 | npads++; |
1783 | if (yPad > 9999) { |
1784 | xPad = fXyq[0][i]; |
1785 | yPad = fXyq[1][i]; |
1786 | } else { |
1787 | if (fXyq[4][i] < fXyq[3][i]) yPad = fXyq[1][i]; |
1788 | else xPad = fXyq[0][i]; |
1789 | } |
1790 | } |
2b1e4f0e |
1791 | } |
1792 | if (fDebug) { |
1793 | for (Int_t i=0; i<nfit; i++) {cout << i+1 << " " << clustFit[i] << " ";} |
1794 | cout << nfit << endl; |
1795 | cout << " Number of pads to fit: " << npads << endl; |
1796 | } |
0df3ca52 |
1797 | fNpar = 0; |
1798 | fQtot = 0; |
1799 | if (npads < 2) return 0; |
0627f609 |
1800 | |
1801 | Int_t digit = 0; |
2b1e4f0e |
1802 | AliMUONDigit *mdig = 0; |
1803 | Int_t tracks[3] = {-1, -1, -1}; |
1804 | for (Int_t cath=0; cath<2; cath++) { |
1805 | for (Int_t i=0; i<fnPads[0]+fnPads[1]; i++) { |
1806 | if (fPadIJ[0][i] != cath) continue; |
1807 | if (fPadIJ[1][i] != 1) continue; |
1808 | if (fXyq[3][i] < 0) continue; // exclude virtual pads |
1809 | digit = TMath::Nint (fXyq[5][i]); |
1810 | if (digit >= 0) mdig = fInput->Digit(cath,digit); |
1811 | else mdig = fInput->Digit(TMath::Even(cath),-digit-1); |
1812 | //if (!mdig) mdig = fInput->Digit(TMath::Even(cath),digit); |
1813 | if (!mdig) continue; // protection for cluster display |
1814 | if (mdig->Hit() >= 0) { |
1815 | if (tracks[0] < 0) { |
1816 | tracks[0] = mdig->Hit(); |
1817 | tracks[1] = mdig->Track(0); |
1818 | } else if (mdig->Track(0) < tracks[1]) { |
1819 | tracks[0] = mdig->Hit(); |
1820 | tracks[1] = mdig->Track(0); |
1821 | } |
1822 | } |
2b1e4f0e |
1823 | if (mdig->Track(1) >= 0 && mdig->Track(1) != tracks[1]) { |
1824 | if (tracks[2] < 0) tracks[2] = mdig->Track(1); |
1825 | else tracks[2] = TMath::Min (tracks[2], mdig->Track(1)); |
1826 | } |
1827 | //if (!mdig) break; |
1828 | //cout << mdig->Hit() << " " << mdig->Track(0) << " " << mdig->Track(1) <<endl; |
1829 | } // for (Int_t i=0; |
1830 | } // for (Int_t cath=0; |
1831 | //cout << tracks[0] << " " << tracks[1] << " " << tracks[2] <<endl; |
1832 | |
1833 | // Get number of pads in X and Y |
1834 | Int_t nInX = 0, nInY; |
1835 | PadsInXandY(nInX, nInY); |
1af223d7 |
1836 | //cout << " nInX and Y: " << nInX << " " << nInY << endl; |
2b1e4f0e |
1837 | |
0627f609 |
1838 | Int_t nfitMax = 3; |
1839 | nfitMax = TMath::Min (nfitMax, (npads + 1) / 3); |
1840 | if (nfitMax > 1) { |
1841 | if (nInX < 3 && nInY < 3 || nInX == 3 && nInY < 3 || nInX < 3 && nInY == 3) nfitMax = 1; // not enough pads in each direction |
1842 | } |
1843 | if (nfit > nfitMax) nfit = nfitMax; |
1844 | |
0df3ca52 |
1845 | // Take cluster maxima as fitting seeds |
2b1e4f0e |
1846 | TObjArray *pix; |
0df3ca52 |
1847 | AliMUONPixel *pixPtr; |
2b1e4f0e |
1848 | Int_t npxclu; |
1849 | Double_t cont, cmax = 0, xseed = 0, yseed = 0, errOk[8], qq = 0; |
f29ba3e1 |
1850 | Double_t xyseed[3][2], qseed[3], xyCand[3][2] = {{0},{0}}, sigCand[3][2] = {{0},{0}}; |
2b1e4f0e |
1851 | |
0627f609 |
1852 | for (Int_t ifit=1; ifit<=nfit0; ifit++) { |
0df3ca52 |
1853 | cmax = 0; |
1854 | pix = clusters[clustFit[ifit-1]]; |
1855 | npxclu = pix->GetEntriesFast(); |
2b1e4f0e |
1856 | //qq = 0; |
0df3ca52 |
1857 | for (Int_t clu=0; clu<npxclu; clu++) { |
1858 | pixPtr = (AliMUONPixel*) pix->UncheckedAt(clu); |
1859 | cont = pixPtr->Charge(); |
1860 | fQtot += cont; |
1861 | if (cont > cmax) { |
1862 | cmax = cont; |
1863 | xseed = pixPtr->Coord(0); |
1864 | yseed = pixPtr->Coord(1); |
1865 | } |
2b1e4f0e |
1866 | qq += cont; |
1867 | /* |
f29ba3e1 |
1868 | xyCand[ifit-1][0] += pixPtr->Coord(0) * cont; |
1869 | xyCand[ifit-1][1] += pixPtr->Coord(1) * cont; |
1870 | sigCand[ifit-1][0] += pixPtr->Coord(0) * pixPtr->Coord(0) * cont; |
1871 | sigCand[ifit-1][1] += pixPtr->Coord(1) * pixPtr->Coord(1) * cont; |
2b1e4f0e |
1872 | */ |
f29ba3e1 |
1873 | xyCand[0][0] += pixPtr->Coord(0) * cont; |
1874 | xyCand[0][1] += pixPtr->Coord(1) * cont; |
1875 | sigCand[0][0] += pixPtr->Coord(0) * pixPtr->Coord(0) * cont; |
1876 | sigCand[0][1] += pixPtr->Coord(1) * pixPtr->Coord(1) * cont; |
0df3ca52 |
1877 | } |
1878 | xyseed[ifit-1][0] = xseed; |
1879 | xyseed[ifit-1][1] = yseed; |
1880 | qseed[ifit-1] = cmax; |
2b1e4f0e |
1881 | /* |
f29ba3e1 |
1882 | xyCand[ifit-1][0] /= qq; // <x> |
1883 | xyCand[ifit-1][1] /= qq; // <y> |
1884 | sigCand[ifit-1][0] = sigCand[ifit-1][0]/qq - xyCand[ifit-1][0]*xyCand[ifit-1][0]; // <x^2> - <x>^2 |
1885 | sigCand[ifit-1][0] = sigCand[ifit-1][0] > 0 ? TMath::Sqrt (sigCand[ifit-1][0]) : 0; |
1886 | sigCand[ifit-1][1] = sigCand[ifit-1][1]/qq - xyCand[ifit-1][1]*xyCand[ifit-1][1]; // <y^2> - <y>^2 |
1887 | sigCand[ifit-1][1] = sigCand[ifit-1][1] > 0 ? TMath::Sqrt (sigCand[ifit-1][1]) : 0; |
1888 | cout << xyCand[ifit-1][0] << " " << xyCand[ifit-1][1] << " " << sigCand[ifit-1][0] << " " << sigCand[ifit-1][1] << endl; |
2b1e4f0e |
1889 | */ |
0df3ca52 |
1890 | } // for (Int_t ifit=1; |
1891 | |
f29ba3e1 |
1892 | xyCand[0][0] /= qq; // <x> |
1893 | xyCand[0][1] /= qq; // <y> |
1894 | sigCand[0][0] = sigCand[0][0]/qq - xyCand[0][0]*xyCand[0][0]; // <x^2> - <x>^2 |
1895 | sigCand[0][0] = sigCand[0][0] > 0 ? TMath::Sqrt (sigCand[0][0]) : 0; |
1896 | sigCand[0][1] = sigCand[0][1]/qq - xyCand[0][1]*xyCand[0][1]; // <y^2> - <y>^2 |
1897 | sigCand[0][1] = sigCand[0][1] > 0 ? TMath::Sqrt (sigCand[0][1]) : 0; |
1898 | if (fDebug) cout << xyCand[0][0] << " " << xyCand[0][1] << " " << sigCand[0][0] << " " << sigCand[0][1] << endl; |
2b1e4f0e |
1899 | |
0627f609 |
1900 | Int_t nDof, maxSeed[3], nMax = 0; |
0df3ca52 |
1901 | Double_t fmin, chi2o = 9999, chi2n; |
1902 | |
0627f609 |
1903 | TMath::Sort(nfit0, qseed, maxSeed, kTRUE); // in decreasing order |
1904 | /* |
1905 | Int_t itmp[100], localMax[100]; |
1906 | Double_t maxVal[100]; |
1907 | if (!iSimple && nfit < nfitMax) { |
1908 | // Try to split pixel cluster according to local maxima |
1909 | Int_t nfit1 = nfit; |
1910 | for (Int_t iclus = 0; iclus < nfit1; iclus++) { |
1911 | nMax = FindLocalMaxima (clusters[clustFit[maxSeed[iclus]]], localMax, maxVal); |
1912 | TH2D *hist = (TH2D*) gROOT->FindObject("anode1"); |
1913 | if (nMax == 1) { hist->Delete(); continue; } |
1914 | // Add extra fitting seeds from local maxima |
1915 | Int_t ixseed = hist->GetXaxis()->FindBin(xyseed[maxSeed[iclus]][0]); |
1916 | Int_t iyseed = hist->GetYaxis()->FindBin(xyseed[maxSeed[iclus]][1]); |
1917 | Int_t nx = hist->GetNbinsX(); |
1918 | TMath::Sort(nMax, maxVal, itmp, kTRUE); // in decreasing order |
1919 | for (Int_t j = 0; j < nMax; j++) { |
1920 | Int_t iyc = localMax[itmp[j]] / nx + 1; |
1921 | Int_t ixc = localMax[itmp[j]] % nx + 1; |
1922 | if (ixc == ixseed && iyc == iyseed) continue; // local max already taken for seeding |
1923 | xyseed[nfit][0] = hist->GetXaxis()->GetBinCenter(ixc); |
1924 | xyseed[nfit][1] = hist->GetYaxis()->GetBinCenter(iyc); |
1925 | qseed[nfit] = maxVal[itmp[j]]; |
1926 | maxSeed[nfit] = nfit++; |
1927 | if (nfit >= nfitMax) break; |
1928 | } |
1929 | hist->Delete(); |
1930 | if (nfit >= nfitMax) break; |
1931 | } // for (Int_t iclus = 0; |
1932 | //nfit0 = nfit; |
1933 | //TMath::Sort(nfit0, qseed, maxSeed, kTRUE); // in decreasing order |
1934 | } //if (!iSimple && nfit < nfitMax) |
1935 | */ |
0df3ca52 |
1936 | |
1937 | Double_t *gin = 0, func0, func1, param[8], param0[2][8], deriv[2][8], step0[8]; |
1938 | Double_t shift[8], stepMax, derMax, parmin[8], parmax[8], func2[2], shift0; |
1939 | Double_t delta[8], scMax, dder[8], estim, shiftSave = 0; |
1940 | Int_t min, max, nCall = 0, memory[8] = {0}, nLoop, idMax = 0, iestMax = 0, nFail; |
2b1e4f0e |
1941 | Double_t rad, dist[3] = {0}; |
0df3ca52 |
1942 | |
0627f609 |
1943 | // Try to fit with one-track hypothesis, then 2-track. If chi2/dof is |
1944 | // lower, try 3-track (if number of pads is sufficient). |
0df3ca52 |
1945 | for (Int_t iseed=0; iseed<nfit; iseed++) { |
1946 | |
2b1e4f0e |
1947 | if (iseed) { for (Int_t j=0; j<fNpar; j++) param[j] = parOk[j]; } // for bounded params |
0df3ca52 |
1948 | for (Int_t j=0; j<3; j++) step0[fNpar+j] = shift[fNpar+j] = step[j]; |
0627f609 |
1949 | if (nfit == 1) param[fNpar] = xyCand[0][0]; // take COG |
1950 | else param[fNpar] = xyseed[maxSeed[iseed]][0]; |
0df3ca52 |
1951 | parmin[fNpar] = xmin; |
1952 | parmax[fNpar++] = xmax; |
0627f609 |
1953 | if (nfit == 1) param[fNpar] = xyCand[0][1]; // take COG |
1954 | else param[fNpar] = xyseed[maxSeed[iseed]][1]; |
0df3ca52 |
1955 | parmin[fNpar] = ymin; |
1956 | parmax[fNpar++] = ymax; |
1957 | if (fNpar > 2) { |
1958 | param[fNpar] = fNpar == 4 ? 0.5 : 0.3; |
1959 | parmin[fNpar] = 0; |
1960 | parmax[fNpar++] = 1; |
1961 | } |
5a051e34 |
1962 | if (iseed) { for (Int_t j=0; j<fNpar; j++) param0[1][j] = 0; } |
0df3ca52 |
1963 | |
1964 | // Try new algorithm |
1965 | min = nLoop = 1; stepMax = func2[1] = derMax = 999999; nFail = 0; |
1966 | |
1967 | while (1) { |
1968 | max = !min; |
30178c30 |
1969 | Fcn1(fNpar, gin, func0, param, 1); nCall++; |
0df3ca52 |
1970 | //cout << " Func: " << func0 << endl; |
1971 | |
1972 | func2[max] = func0; |
1973 | for (Int_t j=0; j<fNpar; j++) { |
1974 | param0[max][j] = param[j]; |
1975 | delta[j] = step0[j]; |
1976 | param[j] += delta[j] / 10; |
1977 | if (j > 0) param[j-1] -= delta[j-1] / 10; |
30178c30 |
1978 | Fcn1(fNpar, gin, func1, param, 1); nCall++; |
0df3ca52 |
1979 | deriv[max][j] = (func1 - func0) / delta[j] * 10; // first derivative |
1980 | //cout << j << " " << deriv[max][j] << endl; |
1981 | dder[j] = param0[0][j] != param0[1][j] ? (deriv[0][j] - deriv[1][j]) / |
1982 | (param0[0][j] - param0[1][j]) : 0; // second derivative |
1983 | } |
1984 | param[fNpar-1] -= delta[fNpar-1] / 10; |
2b1e4f0e |
1985 | if (nCall > 2000) break; |
0df3ca52 |
1986 | |
1987 | min = func2[0] < func2[1] ? 0 : 1; |
1988 | nFail = min == max ? 0 : nFail + 1; |
1989 | |
1990 | stepMax = derMax = estim = 0; |
1991 | for (Int_t j=0; j<fNpar; j++) { |
1992 | // Estimated distance to minimum |
1993 | shift0 = shift[j]; |
1994 | if (nLoop == 1) shift[j] = TMath::Sign (step0[j], -deriv[max][j]); // first step |
1995 | else if (TMath::Abs(deriv[0][j]) < 1.e-3 && TMath::Abs(deriv[1][j]) < 1.e-3) shift[j] = 0; |
1996 | else if (deriv[min][j]*deriv[!min][j] > 0 && TMath::Abs(deriv[min][j]) > TMath::Abs(deriv[!min][j]) |
2b1e4f0e |
1997 | //|| TMath::Abs(deriv[0][j]-deriv[1][j]) < 1.e-3) { |
1998 | || TMath::Abs(deriv[0][j]-deriv[1][j]) < 1.e-3 || TMath::Abs(dder[j]) < 1.e-6) { |
0df3ca52 |
1999 | shift[j] = -TMath::Sign (shift[j], (func2[0]-func2[1]) * (param0[0][j]-param0[1][j])); |
2000 | if (min == max) { |
2001 | if (memory[j] > 1) { shift[j] *= 2; } //cout << " Memory " << memory[j] << " " << shift[j] << endl; } |
2002 | memory[j]++; |
2003 | } |
2004 | } else { |
2b1e4f0e |
2005 | shift[j] = dder[j] != 0 ? -deriv[min][j] / dder[j] : 0; |
0df3ca52 |
2006 | memory[j] = 0; |
2007 | } |
2008 | if (TMath::Abs(shift[j])/step0[j] > estim) { |
2009 | estim = TMath::Abs(shift[j])/step0[j]; |
2010 | iestMax = j; |
2011 | } |
2012 | |
2013 | // Too big step |
2014 | if (TMath::Abs(shift[j])/step0[j] > 10) shift[j] = TMath::Sign(10.,shift[j]) * step0[j]; // |
2015 | |
2016 | // Failed to improve minimum |
2017 | if (min != max) { |
2018 | memory[j] = 0; |
2019 | param[j] = param0[min][j]; |
2020 | if (TMath::Abs(shift[j]+shift0) > 0.1*step0[j]) shift[j] = (shift[j] + shift0) / 2; |
2021 | else shift[j] /= -2; |
2022 | } |
2023 | |
2024 | // Too big step |
2025 | if (TMath::Abs(shift[j]*deriv[min][j]) > func2[min]) |
2026 | shift[j] = TMath::Sign (func2[min]/deriv[min][j], shift[j]); |
2027 | |
2028 | // Introduce step relaxation factor |
2029 | if (memory[j] < 3) { |
2030 | scMax = 1 + 4 / TMath::Max(nLoop/2.,1.); |
2031 | if (TMath::Abs(shift0) > 0 && TMath::Abs(shift[j]/shift0) > scMax) |
2032 | shift[j] = TMath::Sign (shift0*scMax, shift[j]); |
2033 | } |
2034 | param[j] += shift[j]; |
2b1e4f0e |
2035 | //AZ Check parameter limits 27-12-2004 |
2036 | if (param[j] < parmin[j]) { |
2037 | shift[j] = parmin[j] - param[j]; |
2038 | param[j] = parmin[j]; |
2039 | } else if (param[j] > parmax[j]) { |
2040 | shift[j] = parmax[j] - param[j]; |
2041 | param[j] = parmax[j]; |
2042 | } |
0df3ca52 |
2043 | //cout << " xxx " << j << " " << shift[j] << " " << param[j] << endl; |
2044 | stepMax = TMath::Max (stepMax, TMath::Abs(shift[j]/step0[j])); |
2045 | if (TMath::Abs(deriv[min][j]) > derMax) { |
2046 | idMax = j; |
2047 | derMax = TMath::Abs (deriv[min][j]); |
2048 | } |
2049 | } // for (Int_t j=0; j<fNpar; |
2050 | //cout << max << " " << func2[min] << " " << derMax << " " << stepMax << " " << estim << " " << iestMax << " " << nCall << endl; |
2b1e4f0e |
2051 | if (estim < 1 && derMax < 2 || nLoop > 150) break; // minimum was found |
0df3ca52 |
2052 | |
2053 | nLoop++; |
2054 | // Check for small step |
2055 | if (shift[idMax] == 0) { shift[idMax] = step0[idMax]/10; param[idMax] += shift[idMax]; continue; } |
2056 | if (!memory[idMax] && derMax > 0.5 && nLoop > 10) { |
2057 | //cout << " ok " << deriv[min][idMax] << " " << deriv[!min][idMax] << " " << dder[idMax]*shift[idMax] << " " << shift[idMax] << endl; |
2058 | if (dder[idMax] != 0 && TMath::Abs(deriv[min][idMax]/dder[idMax]/shift[idMax]) > 10) { |
2059 | if (min == max) dder[idMax] = -dder[idMax]; |
2060 | shift[idMax] = -deriv[min][idMax] / dder[idMax] / 10; |
2061 | param[idMax] += shift[idMax]; |
2062 | stepMax = TMath::Max (stepMax, TMath::Abs(shift[idMax])/step0[idMax]); |
2063 | //cout << shift[idMax] << " " << param[idMax] << endl; |
2064 | if (min == max) shiftSave = shift[idMax]; |
2065 | } |
2066 | if (nFail > 10) { |
2067 | param[idMax] -= shift[idMax]; |
2068 | shift[idMax] = 4 * shiftSave * (gRandom->Rndm(0) - 0.5); |
2069 | param[idMax] += shift[idMax]; |
2070 | //cout << shift[idMax] << endl; |
2071 | } |
2072 | } |
2073 | } // while (1) |
2074 | fmin = func2[min]; |
2075 | |
2b1e4f0e |
2076 | nDof = npads - fNpar + nVirtual; |
2077 | if (!nDof) nDof++; |
2078 | chi2n = fmin / nDof; |
2079 | if (fDebug) cout << " Chi2 " << chi2n << " " << fNpar << endl; |
0df3ca52 |
2080 | |
2081 | if (chi2n*1.2+1.e-6 > chi2o ) { fNpar -= 3; break; } |
2b1e4f0e |
2082 | |
0df3ca52 |
2083 | // Save parameters and errors |
2b1e4f0e |
2084 | |
0627f609 |
2085 | if (nInX == 1) { |
2b1e4f0e |
2086 | // One pad per direction |
2b1e4f0e |
2087 | for (Int_t i=0; i<fNpar; i++) if (i == 0 || i == 2 || i == 5) param0[min][i] = xPad; |
2088 | } |
0627f609 |
2089 | if (nInY == 1) { |
2b1e4f0e |
2090 | // One pad per direction |
2b1e4f0e |
2091 | for (Int_t i=0; i<fNpar; i++) if (i == 1 || i == 3 || i == 6) param0[min][i] = yPad; |
2092 | } |
2093 | |
2094 | /* |
2095 | if (iseed > 0) { |
2096 | // Find distance to the nearest neighbour |
2097 | dist[0] = dist[1] = TMath::Sqrt ((param0[min][0]-param0[min][2])* |
2098 | (param0[min][0]-param0[min][2]) |
2099 | +(param0[min][1]-param0[min][3])* |
2100 | (param0[min][1]-param0[min][3])); |
2101 | if (iseed > 1) { |
2102 | dist[2] = TMath::Sqrt ((param0[min][0]-param0[min][5])* |
2103 | (param0[min][0]-param0[min][5]) |
2104 | +(param0[min][1]-param0[min][6])* |
2105 | (param0[min][1]-param0[min][6])); |
2106 | rad = TMath::Sqrt ((param0[min][2]-param0[min][5])* |
2107 | (param0[min][2]-param0[min][5]) |
2108 | +(param0[min][3]-param0[min][6])* |
2109 | (param0[min][3]-param0[min][6])); |
2110 | if (dist[2] < dist[0]) dist[0] = dist[2]; |
2111 | if (rad < dist[1]) dist[1] = rad; |
2112 | if (rad < dist[2]) dist[2] = rad; |
2113 | } |
2114 | cout << dist[0] << " " << dist[1] << " " << dist[2] << endl; |
2115 | if (dist[TMath::LocMin(iseed+1,dist)] < 1.) { fNpar -= 3; break; } |
2116 | } |
2117 | */ |
2118 | |
0df3ca52 |
2119 | for (Int_t i=0; i<fNpar; i++) { |
2120 | parOk[i] = param0[min][i]; |
0627f609 |
2121 | //errOk[i] = fmin; |
2122 | errOk[i] = chi2n; |
2b1e4f0e |
2123 | // Bounded params |
2124 | parOk[i] = TMath::Max (parOk[i], parmin[i]); |
2125 | parOk[i] = TMath::Min (parOk[i], parmax[i]); |
0df3ca52 |
2126 | } |
2127 | |
0df3ca52 |
2128 | chi2o = chi2n; |
2129 | if (fmin < 0.1) break; // !!!??? |
2130 | } // for (Int_t iseed=0; |
2131 | |
2b1e4f0e |
2132 | if (fDebug) { |
2133 | for (Int_t i=0; i<fNpar; i++) { |
2b1e4f0e |
2134 | if (i == 4 || i == 7) { |
2135 | if (i == 7 || i == 4 && fNpar < 7) cout << parOk[i] << endl; |
2136 | else cout << parOk[i] * (1-parOk[7]) << endl; |
2137 | continue; |
2138 | } |
2139 | cout << parOk[i] << " " << errOk[i] << endl; |
2140 | } |
0df3ca52 |
2141 | } |
2142 | nfit = (fNpar + 1) / 3; |
2b1e4f0e |
2143 | dist[0] = dist[1] = dist[2] = 0; |
2144 | |
2145 | if (nfit > 1) { |
2146 | // Find distance to the nearest neighbour |
2147 | dist[0] = dist[1] = TMath::Sqrt ((parOk[0]-parOk[2])* |
2148 | (parOk[0]-parOk[2]) |
2149 | +(parOk[1]-parOk[3])* |
2150 | (parOk[1]-parOk[3])); |
2151 | if (nfit > 2) { |
2152 | dist[2] = TMath::Sqrt ((parOk[0]-parOk[5])* |
2153 | (parOk[0]-parOk[5]) |
2154 | +(parOk[1]-parOk[6])* |
2155 | (parOk[1]-parOk[6])); |
2156 | rad = TMath::Sqrt ((parOk[2]-parOk[5])* |
2157 | (parOk[2]-parOk[5]) |
2158 | +(parOk[3]-parOk[6])* |
2159 | (parOk[3]-parOk[6])); |
2160 | if (dist[2] < dist[0]) dist[0] = dist[2]; |
2161 | if (rad < dist[1]) dist[1] = rad; |
2162 | if (rad < dist[2]) dist[2] = rad; |
2163 | } |
2164 | } |
2165 | |
1af223d7 |
2166 | Int_t indx; |
2b1e4f0e |
2167 | fnPads[1] -= nVirtual; |
cc87ebcd |
2168 | if (!fDraw) { |
2169 | Double_t coef = 0; |
0627f609 |
2170 | if (iSimple) fnCoupled = 0; |
cc87ebcd |
2171 | //for (Int_t j=0; j<nfit; j++) { |
2172 | for (Int_t j=nfit-1; j>=0; j--) { |
2173 | indx = j<2 ? j*2 : j*2+1; |
2174 | if (nfit == 1) coef = 1; |
2175 | else coef = j==nfit-1 ? parOk[indx+2] : 1-coef; |
2176 | coef = TMath::Max (coef, 0.); |
2177 | if (nfit == 3 && j < 2) coef = j==1 ? coef*parOk[indx+2] : coef - parOk[7]; |
2178 | coef = TMath::Max (coef, 0.); |
0627f609 |
2179 | AddRawCluster (parOk[indx], parOk[indx+1], coef*fQtot, errOk[indx], nfit0+10*nfit+100*nMax+10000*fnCoupled, tracks, |
cc87ebcd |
2180 | //sigCand[maxSeed[j]][0], sigCand[maxSeed[j]][1]); |
2181 | //sigCand[0][0], sigCand[0][1], dist[j]); |
2182 | sigCand[0][0], sigCand[0][1], dist[TMath::LocMin(nfit,dist)]); |
2183 | } |
2184 | } else fDraw->FillMuon(nfit, parOk, errOk); |
0df3ca52 |
2185 | return nfit; |
2186 | } |
2187 | |
2188 | //_____________________________________________________________________________ |
30178c30 |
2189 | void AliMUONClusterFinderAZ::Fcn1(Int_t & /*npar*/, Double_t * /*gin*/, Double_t &f, Double_t *par, Int_t /*iflag*/) |
0df3ca52 |
2190 | { |
2191 | // Fit for one track |
2b1e4f0e |
2192 | //AZ for Muinuit AliMUONClusterFinderAZ& c = *(AliMUONClusterFinderAZ::fgClusterFinder); |
2193 | AliMUONClusterFinderAZ& c = *this; //AZ |
0df3ca52 |
2194 | |
2195 | Int_t cath, ix, iy, indx, npads=0; |
2b1e4f0e |
2196 | Double_t charge, delta, coef=0, chi2=0, qTot = 0; |
0df3ca52 |
2197 | for (Int_t j=0; j<c.fnPads[0]+c.fnPads[1]; j++) { |
2198 | if (c.fPadIJ[1][j] != 1) continue; |
2199 | cath = c.fPadIJ[0][j]; |
2b1e4f0e |
2200 | if (c.fXyq[3][j] > 0) npads++; // exclude virtual pads |
2201 | qTot += c.fXyq[2][j]; |
0627f609 |
2202 | ix = c.fPadIJ[2][j]; |
2203 | iy = c.fPadIJ[3][j]; |
2204 | c.fSegmentation[cath]->SetPad(ix, iy); |
0df3ca52 |
2205 | charge = 0; |
2206 | for (Int_t i=c.fNpar/3; i>=0; i--) { // sum over tracks |
2207 | indx = i<2 ? 2*i : 2*i+1; |
0627f609 |
2208 | c.fSegmentation[cath]->SetHit(par[indx], par[indx+1], c.fZpad); |
0df3ca52 |
2209 | if (c.fNpar == 2) coef = 1; |
2210 | else coef = i==c.fNpar/3 ? par[indx+2] : 1-coef; |
2b1e4f0e |
2211 | coef = TMath::Max (coef, 0.); |
0df3ca52 |
2212 | if (c.fNpar == 8 && i < 2) coef = i==1 ? coef*par[indx+2] : coef - par[7]; |
2b1e4f0e |
2213 | coef = TMath::Max (coef, 0.); |
0627f609 |
2214 | charge += c.fInput->Mathieson()->IntXY(fInput->DetElemId(), c.fInput->Segmentation2(cath))*coef; |
0df3ca52 |
2215 | } |
2216 | charge *= c.fQtot; |
0df3ca52 |
2217 | delta = charge - c.fXyq[2][j]; |
2b1e4f0e |
2218 | delta *= delta; |
2219 | delta /= c.fXyq[2][j]; |
2220 | //if (cath) delta /= 5; // just for test |
2221 | chi2 += delta; |
0df3ca52 |
2222 | } // for (Int_t j=0; |
2223 | f = chi2; |
2b1e4f0e |
2224 | Double_t qAver = qTot/npads; //(c.fnPads[0]+c.fnPads[1]); |
0df3ca52 |
2225 | f = chi2/qAver; |
2226 | } |
2227 | |
2228 | //_____________________________________________________________________________ |
6aaf81e6 |
2229 | void AliMUONClusterFinderAZ::UpdatePads(Int_t /*nfit*/, Double_t *par) |
0df3ca52 |
2230 | { |
2231 | // Subtract the fitted charges from pads with strong coupling |
2232 | |
2233 | Int_t cath, ix, iy, indx; |
2234 | Double_t charge, coef=0; |
2235 | for (Int_t j=0; j<fnPads[0]+fnPads[1]; j++) { |
2236 | if (fPadIJ[1][j] != -1) continue; |
2237 | if (fNpar != 0) { |
2238 | cath = fPadIJ[0][j]; |
0627f609 |
2239 | ix = fPadIJ[2][j]; |
2240 | iy = fPadIJ[3][j]; |
2241 | fSegmentation[cath]->SetPad(ix, iy); |
0df3ca52 |
2242 | charge = 0; |
2243 | for (Int_t i=fNpar/3; i>=0; i--) { // sum over tracks |
2244 | indx = i<2 ? 2*i : 2*i+1; |
0627f609 |
2245 | fSegmentation[cath]->SetHit(par[indx], par[indx+1], fZpad); |
0df3ca52 |
2246 | if (fNpar == 2) coef = 1; |
2247 | else coef = i==fNpar/3 ? par[indx+2] : 1-coef; |
2b1e4f0e |
2248 | coef = TMath::Max (coef, 0.); |
0df3ca52 |
2249 | if (fNpar == 8 && i < 2) coef = i==1 ? coef*par[indx+2] : coef - par[7]; |
2b1e4f0e |
2250 | coef = TMath::Max (coef, 0.); |
0627f609 |
2251 | charge += fInput->Mathieson()->IntXY(fInput->DetElemId(),fInput->Segmentation2(cath))*coef; |
0df3ca52 |
2252 | } |
2253 | charge *= fQtot; |
2254 | fXyq[2][j] -= charge; |
2255 | } // if (fNpar != 0) |
0627f609 |
2256 | if (fXyq[2][j] > fgkZeroSuppression) fPadIJ[1][j] = 0; // return pad for further using |
0df3ca52 |
2257 | } // for (Int_t j=0; |
2258 | } |
2259 | |
2260 | //_____________________________________________________________________________ |
30178c30 |
2261 | Bool_t AliMUONClusterFinderAZ::TestTrack(Int_t /*t*/) const { |
0df3ca52 |
2262 | // Test if track was user selected |
2263 | return kTRUE; |
2264 | /* |
2265 | if (fTrack[0]==-1 || fTrack[1]==-1) { |
2266 | return kTRUE; |
2267 | } else if (t==fTrack[0] || t==fTrack[1]) { |
2268 | return kTRUE; |
2269 | } else { |
2270 | return kFALSE; |
2271 | } |
2272 | */ |
2273 | } |
2274 | |
2275 | //_____________________________________________________________________________ |
2b1e4f0e |
2276 | void AliMUONClusterFinderAZ::AddRawCluster(Double_t x, Double_t y, Double_t qTot, Double_t fmin, Int_t nfit, Int_t *tracks, Double_t /*sigx*/, Double_t /*sigy*/, Double_t /*dist*/) |
0df3ca52 |
2277 | { |
2278 | // |
2279 | // Add a raw cluster copy to the list |
2280 | // |
2b1e4f0e |
2281 | if (qTot <= 0.501) return; |
0df3ca52 |
2282 | AliMUONRawCluster cnew; |
0df3ca52 |
2283 | |
2b1e4f0e |
2284 | Int_t cath, npads[2] = {0}, nover[2] = {0}; |
2285 | for (Int_t j=0; j<fnPads[0]+fnPads[1]; j++) { |
2286 | cath = fPadIJ[0][j]; |
2287 | // There was an overflow |
2288 | if (fPadIJ[1][j] == -9) nover[cath]++; |
2289 | if (fPadIJ[1][j] != 1 && fPadIJ[1][j] != -9) continue; |
2290 | cnew.SetMultiplicity(cath,cnew.GetMultiplicity(cath)+1); |
2291 | if (fXyq[2][j] > cnew.GetPeakSignal(cath)) cnew.SetPeakSignal(cath,TMath::Nint (fXyq[2][j])); |
2292 | //cnew.SetCharge(cath,cnew.GetCharge(cath) + TMath::Nint (fXyq[2][j])); |
2293 | cnew.SetContrib(npads[cath],cath,fXyq[2][j]); |
5a051e34 |
2294 | cnew.SetIndex(npads[cath],cath,TMath::Nint (fXyq[5][j])); |
2295 | cnew.SetDetElemId(fInput->DetElemId()); |
2b1e4f0e |
2296 | npads[cath]++; |
2297 | } |
2298 | |
2299 | cnew.SetClusterType(nover[0] + nover[1] * 100); |
2300 | for (Int_t j=0; j<3; j++) cnew.SetTrack(j,tracks[j]); |
2301 | |
0627f609 |
2302 | Double_t xg, yg, zg; |
0df3ca52 |
2303 | for (cath=0; cath<2; cath++) { |
0627f609 |
2304 | // Perform local-to-global transformation |
2305 | fInput->Segmentation2(cath)->GetTransformer()->Local2Global(fInput->DetElemId(), x, y, fZpad, xg, yg, zg); |
2306 | cnew.SetX(cath, xg); |
2307 | cnew.SetY(cath, yg); |
2308 | cnew.SetZ(cath, zg); |
2b1e4f0e |
2309 | cnew.SetCharge(cath, TMath::Nint(qTot)); |
2310 | //cnew.SetPeakSignal(cath,20); |
2311 | //cnew.SetMultiplicity(cath, 5); |
2312 | cnew.SetNcluster(cath, nfit); |
2313 | cnew.SetChi2(cath, fmin); //0.;1 |
0df3ca52 |
2314 | } |
2b1e4f0e |
2315 | // Evaluate measurement errors |
2316 | //AZ Errors(&cnew); |
2317 | |
2318 | cnew.SetGhost(nfit); //cnew.SetX(1,sigx); cnew.SetY(1,sigy); cnew.SetZ(1,dist); |
0df3ca52 |
2319 | //cnew.fClusterType=cnew.PhysicsContribution(); |
0627f609 |
2320 | new((*fRawClusters)[fNRawClusters++]) AliMUONRawCluster(cnew); |
2321 | if (fDebug) cout << fNRawClusters << " " << fInput->Chamber() << endl; |
0df3ca52 |
2322 | //fNPeaks++; |
2323 | } |
2324 | |
2325 | //_____________________________________________________________________________ |
0627f609 |
2326 | Int_t AliMUONClusterFinderAZ::FindLocalMaxima(TObjArray *pixArray, Int_t *localMax, Double_t *maxVal) |
0df3ca52 |
2327 | { |
2328 | // Find local maxima in pixel space for large preclusters in order to |
2329 | // try to split them into smaller pieces (to speed up the MLEM procedure) |
0627f609 |
2330 | // or to find additional fitting seeds if clusters were not completely resolved |
0df3ca52 |
2331 | |
0627f609 |
2332 | TH2D *hist = NULL; |
2333 | //if (pixArray == fPixArray) hist = (TH2D*) gROOT->FindObject("anode"); |
2334 | //else { hist = (TH2D*) gROOT->FindObject("anode1"); cout << hist << endl; } |
2335 | //if (hist) hist->Delete(); |
0df3ca52 |
2336 | |
cd747ddb |
2337 | Double_t xylim[4] = {999, 999, 999, 999}; |
0627f609 |
2338 | Int_t nPix = pixArray->GetEntriesFast(); |
0df3ca52 |
2339 | AliMUONPixel *pixPtr = 0; |
2340 | for (Int_t ipix=0; ipix<nPix; ipix++) { |
0627f609 |
2341 | pixPtr = (AliMUONPixel*) pixArray->UncheckedAt(ipix); |
0df3ca52 |
2342 | for (Int_t i=0; i<4; i++) |
2343 | xylim[i] = TMath::Min (xylim[i], (i%2 ? -1 : 1)*pixPtr->Coord(i/2)); |
2344 | } |
2345 | for (Int_t i=0; i<4; i++) xylim[i] -= pixPtr->Size(i/2); |
2346 | |
2347 | Int_t nx = TMath::Nint ((-xylim[1]-xylim[0])/pixPtr->Size(0)/2); |
2348 | Int_t ny = TMath::Nint ((-xylim[3]-xylim[2])/pixPtr->Size(1)/2); |
0627f609 |
2349 | if (pixArray == fPixArray) hist = new TH2D("anode","anode",nx,xylim[0],-xylim[1],ny,xylim[2],-xylim[3]); |
2350 | else hist = new TH2D("anode1","anode1",nx,xylim[0],-xylim[1],ny,xylim[2],-xylim[3]); |
0df3ca52 |
2351 | for (Int_t ipix=0; ipix<nPix; ipix++) { |
0627f609 |
2352 | pixPtr = (AliMUONPixel*) pixArray->UncheckedAt(ipix); |
0df3ca52 |
2353 | hist->Fill(pixPtr->Coord(0), pixPtr->Coord(1), pixPtr->Charge()); |
2354 | } |
0627f609 |
2355 | if (fDraw && pixArray == fPixArray) fDraw->DrawHist("c2", hist); |
0df3ca52 |
2356 | |
2357 | Int_t nMax = 0, indx; |
2358 | Int_t *isLocalMax = new Int_t[ny*nx]; |
2359 | for (Int_t i=0; i<ny*nx; i++) isLocalMax[i] = 0; |
2360 | |
2361 | for (Int_t i=1; i<=ny; i++) { |
2362 | indx = (i-1) * nx; |
2363 | for (Int_t j=1; j<=nx; j++) { |
2364 | if (hist->GetCellContent(j,i) < 0.5) continue; |
2365 | //if (isLocalMax[indx+j-1] < 0) continue; |
2366 | if (isLocalMax[indx+j-1] != 0) continue; |
2367 | FlagLocalMax(hist, i, j, isLocalMax); |
2368 | } |
2369 | } |
2370 | |
2371 | for (Int_t i=1; i<=ny; i++) { |
2372 | indx = (i-1) * nx; |
2373 | for (Int_t j=1; j<=nx; j++) { |
2374 | if (isLocalMax[indx+j-1] > 0) { |
2375 | localMax[nMax] = indx + j - 1; |
2376 | maxVal[nMax++] = hist->GetCellContent(j,i); |
2b1e4f0e |
2377 | if (nMax > 99) AliFatal(" Too many local maxima !!!"); |
0df3ca52 |
2378 | } |
0df3ca52 |
2379 | } |
2380 | } |
2b1e4f0e |
2381 | if (fDebug) cout << " Local max: " << nMax << endl; |
0df3ca52 |
2382 | delete [] isLocalMax; isLocalMax = 0; |
2383 | return nMax; |
2384 | } |
2385 | |
2386 | //_____________________________________________________________________________ |
2387 | void AliMUONClusterFinderAZ::FlagLocalMax(TH2D *hist, Int_t i, Int_t j, Int_t *isLocalMax) |
2388 | { |
2389 | // Flag pixels (whether or not local maxima) |
2390 | |
2391 | Int_t nx = hist->GetNbinsX(); |
2392 | Int_t ny = hist->GetNbinsY(); |
2393 | Int_t cont = TMath::Nint (hist->GetCellContent(j,i)); |
0627f609 |
2394 | Int_t cont1 = 0, indx = (i-1)*nx+j-1, indx1 = 0, indx2 = 0; |
0df3ca52 |
2395 | |
2396 | for (Int_t i1=i-1; i1<i+2; i1++) { |
2397 | if (i1 < 1 || i1 > ny) continue; |
0627f609 |
2398 | indx1 = (i1 - 1) * nx; |
0df3ca52 |
2399 | for (Int_t j1=j-1; j1<j+2; j1++) { |
2400 | if (j1 < 1 || j1 > nx) continue; |
2401 | if (i == i1 && j == j1) continue; |
0627f609 |
2402 | indx2 = indx1 + j1 - 1; |
0df3ca52 |
2403 | cont1 = TMath::Nint (hist->GetCellContent(j1,i1)); |
0627f609 |
2404 | if (cont < cont1) { isLocalMax[indx] = -1; return; } |
2405 | else if (cont > cont1) isLocalMax[indx2] = -1; |
0df3ca52 |
2406 | else { // the same charge |
0627f609 |
2407 | isLocalMax[indx] = 1; |
2408 | if (isLocalMax[indx2] == 0) { |
0df3ca52 |
2409 | FlagLocalMax(hist, i1, j1, isLocalMax); |
0627f609 |
2410 | if (isLocalMax[indx2] < 0) { isLocalMax[indx] = -1; return; } |
2411 | else isLocalMax[indx2] = -1; |
0df3ca52 |
2412 | } |
2413 | } |
2414 | } |
2415 | } |
0627f609 |
2416 | isLocalMax[indx] = 1; // local maximum |
0df3ca52 |
2417 | } |
2418 | |
2419 | //_____________________________________________________________________________ |
2420 | void AliMUONClusterFinderAZ::FindCluster(Int_t *localMax, Int_t iMax) |
2421 | { |
2422 | // Find pixel cluster around local maximum #iMax and pick up pads |
2423 | // overlapping with it |
2424 | |
2425 | TH2D *hist = (TH2D*) gROOT->FindObject("anode"); |
2426 | Int_t nx = hist->GetNbinsX(); |
2427 | Int_t ny = hist->GetNbinsY(); |
2428 | Int_t ic = localMax[iMax] / nx + 1; |
2429 | Int_t jc = localMax[iMax] % nx + 1; |
2430 | Bool_t *used = new Bool_t[ny*nx]; |
2431 | for (Int_t i=0; i<ny*nx; i++) used[i] = kFALSE; |
2432 | |
2433 | // Drop all pixels from the array - pick up only the ones from the cluster |
2434 | fPixArray->Delete(); |
2435 | |
2436 | Double_t wx = hist->GetXaxis()->GetBinWidth(1)/2; |
2437 | Double_t wy = hist->GetYaxis()->GetBinWidth(1)/2; |
2438 | Double_t yc = hist->GetYaxis()->GetBinCenter(ic); |
2439 | Double_t xc = hist->GetXaxis()->GetBinCenter(jc); |
2440 | Double_t cont = hist->GetCellContent(jc,ic); |
2441 | AliMUONPixel *pixPtr = new AliMUONPixel (xc, yc, wx, wy, cont); |
2442 | fPixArray->Add((TObject*)pixPtr); |
2443 | used[(ic-1)*nx+jc-1] = kTRUE; |
2444 | AddBin(hist, ic, jc, 1, used, (TObjArray*)0); // recursive call |
2445 | |
2446 | Int_t nPix = fPixArray->GetEntriesFast(), npad = fnPads[0] + fnPads[1]; |
2447 | for (Int_t i=0; i<nPix; i++) { |
2448 | ((AliMUONPixel*)fPixArray->UncheckedAt(i))->SetSize(0,wx); |
2449 | ((AliMUONPixel*)fPixArray->UncheckedAt(i))->SetSize(1,wy); |
2450 | } |
2b1e4f0e |
2451 | if (fDebug) cout << iMax << " " << nPix << endl; |
0df3ca52 |
2452 | |
2453 | Float_t xy[4], xy12[4]; |
2454 | // Pick up pads which overlap with found pixels |
2455 | for (Int_t i=0; i<npad; i++) fPadIJ[1][i] = -1; |
2456 | for (Int_t i=0; i<nPix; i++) { |
2457 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i); |
2458 | for (Int_t j=0; j<4; j++) |
2459 | xy[j] = pixPtr->Coord(j/2) + (j%2 ? 1 : -1)*pixPtr->Size(j/2); |
2460 | for (Int_t j=0; j<npad; j++) |
2461 | if (Overlap(xy, j, xy12, 0)) fPadIJ[1][j] = 0; // flag for use |
2462 | } |
2463 | |
2464 | delete [] used; used = 0; |
2465 | } |
30178c30 |
2466 | |
2467 | //_____________________________________________________________________________ |
2468 | AliMUONClusterFinderAZ& |
2469 | AliMUONClusterFinderAZ::operator=(const AliMUONClusterFinderAZ& rhs) |
2470 | { |
2471 | // Protected assignement operator |
2472 | |
2473 | if (this == &rhs) return *this; |
2474 | |
8c343c7c |
2475 | AliFatal("Not implemented."); |
30178c30 |
2476 | |
2477 | return *this; |
2478 | } |
2479 | |
2b1e4f0e |
2480 | //_____________________________________________________________________________ |
2481 | void AliMUONClusterFinderAZ::AddVirtualPad() |
2482 | { |
2483 | // Add virtual pad (with small charge) to improve fit for some |
2484 | // clusters (when pad with max charge is at the extreme of the cluster) |
2485 | |
2486 | // Get number of pads in X and Y-directions |
2487 | Int_t nInX = -1, nInY; |
2488 | PadsInXandY(nInX, nInY); |
2489 | //return; |
2490 | |
0627f609 |
2491 | // Add virtual pad only if number of pads per direction == 2 |
2b1e4f0e |
2492 | if (nInX != 2 && nInY != 2) return; |
2493 | |
2494 | // Find pads with max charge |
2495 | Int_t maxpad[2][2] = {{-1, -1}, {-1, -1}}, cath; |
2496 | Double_t sigmax[2] = {0}, aamax[2] = {0}; |
2497 | for (Int_t j=0; j<fnPads[0]+fnPads[1]; j++) { |
2498 | if (fPadIJ[1][j] != 0) continue; |
2499 | cath = fPadIJ[0][j]; |
2500 | if (fXyq[2][j] > sigmax[cath]) { |
2501 | maxpad[cath][1] = maxpad[cath][0]; |
2502 | aamax[cath] = sigmax[cath]; |
2503 | sigmax[cath] = fXyq[2][j]; |
2504 | maxpad[cath][0] = j; |
2505 | } |
2506 | } |
2507 | if (maxpad[0][0] >= 0 && maxpad[0][1] < 0 || maxpad[1][0] >= 0 && maxpad[1][1] < 0) { |
2508 | for (Int_t j=0; j<fnPads[0]+fnPads[1]; j++) { |
2509 | if (fPadIJ[1][j] != 0) continue; |
2510 | cath = fPadIJ[0][j]; |
2511 | if (j == maxpad[cath][0] || j == maxpad[cath][1]) continue; |
2512 | if (fXyq[2][j] > aamax[cath]) { |
2513 | aamax[cath] = fXyq[2][j]; |
2514 | maxpad[cath][1] = j; |
2515 | } |
2516 | } |
2517 | } |
2518 | // Check for mirrors (side X on cathode 0) |
2519 | Bool_t mirror = kFALSE; |
0627f609 |
2520 | if (maxpad[0][0] >= 0 && maxpad[1][0] >= 0) { |
2b1e4f0e |
2521 | mirror = fXyq[3][maxpad[0][0]] < fXyq[4][maxpad[0][0]]; |
0627f609 |
2522 | if (!mirror && TMath::Abs(fXyq[3][maxpad[0][0]]-fXyq[3][maxpad[1][0]]) < 0.001) { |
2523 | // Special case when pads on both cathodes have the same size |
2524 | Int_t yud[2] = {0}; |
2525 | for (Int_t j = 0; j < fnPads[0]+fnPads[1]; j++) { |
2526 | cath = fPadIJ[0][j]; |
2527 | if (j == maxpad[cath][0]) continue; |
2528 | if (fPadIJ[2][j] != fPadIJ[2][maxpad[cath][0]]) continue; |
2529 | if (fPadIJ[3][j] + 1 == fPadIJ[3][maxpad[cath][0]] || |
2530 | fPadIJ[3][j] - 1 == fPadIJ[3][maxpad[cath][0]]) yud[cath]++; |
2531 | } |
2532 | if (!yud[0]) mirror = kTRUE; // take the other cathode |
2533 | } // if (!mirror &&... |
2534 | } // if (maxpad[0][0] >= 0 && maxpad[1][0] >= 0) |
2b1e4f0e |
2535 | |
2536 | // Find neughbours of pads with max charges |
2537 | Int_t nn, xList[10], yList[10], ix0, iy0, ix, iy, neighb; |
2538 | for (cath=0; cath<2; cath++) { |
2539 | if (!cath && maxpad[0][0] < 0) continue; // one-sided cluster - cathode 1 |
2540 | if (cath && maxpad[1][0] < 0) break; // one-sided cluster - cathode 0 |
2541 | if (maxpad[1][0] >= 0) { |
2542 | if (!mirror) { |
2543 | if (!cath && nInY != 2) continue; |
2b1e4f0e |
2544 | if (cath && nInX != 2 && (maxpad[0][0] >= 0 || nInY != 2)) continue; |
2545 | } else { |
2546 | if (!cath && nInX != 2) continue; |
2547 | if (cath && nInY != 2 && (maxpad[0][0] >= 0 || nInX != 2)) continue; |
2548 | } |
2549 | } |
2550 | |
1af223d7 |
2551 | Int_t iAddX = 0, iAddY = 0, ix1 = 0, iy1 = 0, iPad = 0; |
2b1e4f0e |
2552 | if (maxpad[0][0] < 0) iPad = 1; |
2553 | |
2b1e4f0e |
2554 | for (iPad=0; iPad<2; iPad++) { |
94eb555e |
2555 | if (maxpad[cath][iPad] < 0) continue; |
2b1e4f0e |
2556 | if (iPad && !iAddX && !iAddY) break; |
2557 | if (iPad && fXyq[2][maxpad[cath][1]] / sigmax[cath] < 0.5) break; |
2558 | |
2559 | Int_t neighbx = 0, neighby = 0; |
0627f609 |
2560 | ix0 = fPadIJ[2][maxpad[cath][iPad]]; |
2561 | iy0 = fPadIJ[3][maxpad[cath][iPad]]; |
2562 | fSegmentation[cath]->Neighbours(ix0, iy0, &nn, xList, yList); |
2563 | Float_t zpad; |
2b1e4f0e |
2564 | for (Int_t j=0; j<nn; j++) { |
0627f609 |
2565 | if (TMath::Abs(xList[j]-ix0) == 1 || xList[j]*ix0 == -1) neighbx++; |
2566 | if (TMath::Abs(yList[j]-iy0) == 1 || yList[j]*iy0 == -1) neighby++; |
2b1e4f0e |
2567 | } |
2568 | if (!mirror) { |
2569 | if (cath) neighb = neighbx; |
2570 | else neighb = neighby; |
2571 | if (maxpad[0][0] < 0) neighb += neighby; |
2572 | else if (maxpad[1][0] < 0) neighb += neighbx; |
2573 | } else { |
2574 | if (!cath) neighb = neighbx; |
2575 | else neighb = neighby; |
2576 | if (maxpad[0][0] < 0) neighb += neighbx; |
2577 | else if (maxpad[1][0] < 0) neighb += neighby; |
2578 | } |
2579 | |
2580 | for (Int_t j=0; j<fnPads[0]+fnPads[1]; j++) { |
2581 | if (fPadIJ[0][j] != cath) continue; |
0627f609 |
2582 | ix = fPadIJ[2][j]; |
2583 | iy = fPadIJ[3][j]; |
2b1e4f0e |
2584 | if (iy == iy0 && ix == ix0) continue; |
2585 | for (Int_t k=0; k<nn; k++) { |
2586 | if (xList[k] != ix || yList[k] != iy) continue; |
2587 | if (!mirror) { |
2588 | if ((!cath || maxpad[0][0] < 0) && |
1af223d7 |
2589 | (TMath::Abs(iy-iy0) == 1 || iy*iy0 == -1)) { |
0627f609 |
2590 | if (!iPad && TMath::Abs(ix-ix0) == 1 || ix*ix0 == -1) ix1 = xList[k]; //19-12-05 |
2b1e4f0e |
2591 | xList[k] = yList[k] = 0; |
2592 | neighb--; |
2593 | break; |
2594 | } |
2595 | if ((cath || maxpad[1][0] < 0) && |
1af223d7 |
2596 | (TMath::Abs(ix-ix0) == 1 || ix*ix0 == -1)) { |
0627f609 |
2597 | if (!iPad) ix1 = xList[k]; //19-12-05 |
2b1e4f0e |
2598 | xList[k] = yList[k] = 0; |
2599 | neighb--; |
2600 | } |
2601 | } else { |
2602 | if ((!cath || maxpad[0][0] < 0) && |
1af223d7 |
2603 | (TMath::Abs(ix-ix0) == 1 || ix*ix0 == -1)) { |
0627f609 |
2604 | if (!iPad) ix1 = xList[k]; //19-12-05 |
2b1e4f0e |
2605 | xList[k] = yList[k] = 0; |
2606 | neighb--; |
2607 | break; |
2608 | } |
2609 | if ((cath || maxpad[1][0] < 0) && |
1af223d7 |
2610 | (TMath::Abs(iy-iy0) == 1 || iy*iy0 == -1)) { |
2b1e4f0e |
2611 | xList[k] = yList[k] = 0; |
2612 | neighb--; |
2613 | } |
2614 | } |
2615 | break; |
2616 | } // for (Int_t k=0; k<nn; |
2617 | if (!neighb) break; |
2618 | } // for (Int_t j=0; j<fnPads[0]+fnPads[1]; |
2619 | if (!neighb) continue; |
2620 | |
2621 | // Add virtual pad |
2622 | Int_t npads, isec; |
2623 | isec = 0; |
2624 | for (Int_t j=0; j<nn; j++) { |
2625 | if (xList[j] == 0 && yList[j] == 0) continue; |
2626 | npads = fnPads[0] + fnPads[1]; |
2627 | fPadIJ[0][npads] = cath; |
2628 | fPadIJ[1][npads] = 0; |
2629 | ix = xList[j]; |
2630 | iy = yList[j]; |
1af223d7 |
2631 | if (TMath::Abs(ix-ix0) == 1 || ix*ix0 == -1) { |
2b1e4f0e |
2632 | if (iy != iy0) continue; // new segmentation - check |
2633 | if (nInX != 2) continue; // new |
2634 | if (!mirror) { |
2635 | if (!cath && maxpad[1][0] >= 0) continue; |
2b1e4f0e |
2636 | } else { |
2637 | if (cath && maxpad[0][0] >= 0) continue; |
2b1e4f0e |
2638 | } |
2639 | if (iPad && !iAddX) continue; |
0627f609 |
2640 | fSegmentation[cath]->GetPadC(ix, iy, fXyq[0][npads], fXyq[1][npads], zpad); |
1af223d7 |
2641 | if (fXyq[0][npads] > 1.e+5) continue; // temporary fix |
0627f609 |
2642 | if (ix == ix1) continue; //19-12-05 |
2b1e4f0e |
2643 | if (ix1 == ix0) continue; |
2b1e4f0e |
2644 | if (maxpad[1][0] < 0 || mirror && maxpad[0][0] >= 0) { |
2645 | if (!iPad) fXyq[2][npads] = TMath::Min (sigmax[0]/100, 5.); |
2646 | else fXyq[2][npads] = TMath::Min (aamax[0]/100, 5.); |
2647 | } |
2648 | else { |
2649 | if (!iPad) fXyq[2][npads] = TMath::Min (sigmax[1]/100, 5.); |
2650 | else fXyq[2][npads] = TMath::Min (aamax[1]/100, 5.); |
2651 | } |
2652 | fXyq[2][npads] = TMath::Max (fXyq[2][npads], (float)1); |
2b1e4f0e |
2653 | fXyq[3][npads] = -2; // flag |
0627f609 |
2654 | fPadIJ[2][npads] = ix; |
2655 | fPadIJ[3][npads] = iy; |
2b1e4f0e |
2656 | fnPads[1]++; |
2657 | iAddX = npads; |
0627f609 |
2658 | if (fDebug) printf(" ***** Add virtual pad in X ***** %f %f %f %3d %3d \n", fXyq[2][npads], |
e8fb921b |
2659 | fXyq[0][npads], fXyq[1][npads], ix, iy); |
2b1e4f0e |
2660 | ix1 = ix0; |
2661 | continue; |
2662 | } |
2663 | if (nInY != 2) continue; |
2664 | if (!mirror && cath && maxpad[0][0] >= 0) continue; |
2665 | if (mirror && !cath && maxpad[1][0] >= 0) continue; |
2666 | if (TMath::Abs(iy-iy0) == 1 || TMath::Abs(iy*iy0) == 1) { |
2667 | if (ix != ix0) continue; // new segmentation - check |
2668 | if (iPad && !iAddY) continue; |
0627f609 |
2669 | fSegmentation[cath]->GetPadC(ix, iy, fXyq[0][npads], fXyq[1][npads], zpad); |
2b1e4f0e |
2670 | if (iy1 == iy0) continue; |
2671 | //if (iPad && iy1 == iy0) continue; |
2b1e4f0e |
2672 | if (maxpad[0][0] < 0 || mirror && maxpad[1][0] >= 0) { |
0627f609 |
2673 | if (!iPad) fXyq[2][npads] = TMath::Min (sigmax[1]/15, fgkZeroSuppression); |
2674 | else fXyq[2][npads] = TMath::Min (aamax[1]/15, fgkZeroSuppression); |
2b1e4f0e |
2675 | } |
2676 | else { |
0627f609 |
2677 | if (!iPad) fXyq[2][npads] = TMath::Min (sigmax[0]/15, fgkZeroSuppression); |
2678 | else fXyq[2][npads] = TMath::Min (aamax[0]/15, fgkZeroSuppression); |
2b1e4f0e |
2679 | } |
2680 | fXyq[2][npads] = TMath::Max (fXyq[2][npads], (float)1); |
2b1e4f0e |
2681 | fXyq[3][npads] = -2; // flag |
0627f609 |
2682 | fPadIJ[2][npads] = ix; |
2683 | fPadIJ[3][npads] = iy; |
2b1e4f0e |
2684 | fnPads[1]++; |
2685 | iAddY = npads; |
0627f609 |
2686 | if (fDebug) printf(" ***** Add virtual pad in Y ***** %f %f %f %3d %3d \n", fXyq[2][npads], |
e8fb921b |
2687 | fXyq[0][npads], fXyq[1][npads], ix, iy); |
2b1e4f0e |
2688 | iy1 = iy0; |
2689 | } |
2690 | } // for (Int_t j=0; j<nn; |
2691 | } // for (Int_t iPad=0; |
2692 | } // for (cath=0; cath<2; |
2693 | return; |
2694 | } |
2695 | |
2696 | //_____________________________________________________________________________ |
2697 | void AliMUONClusterFinderAZ::PadsInXandY(Int_t &nInX, Int_t &nInY) |
2698 | { |
2699 | // Find number of pads in X and Y-directions (excluding virtual ones and |
2700 | // overflows) |
2701 | |
2702 | static Int_t nXsaved = 0, nYsaved = 0; |
2703 | nXsaved = nYsaved = 0; |
2704 | //if (nInX >= 0) {nInX = nXsaved; nInY = nYsaved; return; } |
5a051e34 |
2705 | Float_t *xPad0 = NULL, *yPad0 = NULL, *xPad1 = NULL, *yPad1 = NULL; |
1af223d7 |
2706 | Float_t wMinX[2] = {99, 99}, wMinY[2] = {99, 99}; |
5a051e34 |
2707 | Int_t *nPad0 = NULL, *nPad1 = NULL; |
2708 | Int_t nPads = fnPads[0] + fnPads[1]; |
2709 | if (fnPads[0]) { |
2710 | xPad0 = new Float_t[nPads]; |
2711 | yPad0 = new Float_t[nPads]; |
2712 | nPad0 = new Int_t[nPads]; |
2713 | } |
2714 | if (fnPads[1]) { |
2715 | xPad1 = new Float_t[nPads]; |
2716 | yPad1 = new Float_t[nPads]; |
2717 | nPad1 = new Int_t[nPads]; |
2718 | } |
2719 | Int_t n0 = 0, n1 = 0, cath, npadx[2] = {1, 1}, npady[2] = {1, 1}; |
2720 | for (Int_t j = 0; j < nPads; j++) { |
2b1e4f0e |
2721 | if (nInX < 0 && fPadIJ[1][j] != 0) continue; // before fit |
2722 | else if (nInX == 0 && fPadIJ[1][j] != 1) continue; // fit - exclude overflows |
2723 | else if (nInX > 0 && fPadIJ[1][j] != 1 && fPadIJ[1][j] != -9) continue; // exclude non-marked |
0627f609 |
2724 | if (nInX <= 0 && fXyq[2][j] > fgkSaturation-1) continue; // skip overflows |
2b1e4f0e |
2725 | cath = fPadIJ[0][j]; |
1af223d7 |
2726 | if (fXyq[3][j] > 0) { // exclude virtual pads |
2727 | wMinX[cath] = TMath::Min (wMinX[cath], fXyq[3][j]); |
2728 | wMinY[cath] = TMath::Min (wMinY[cath], fXyq[4][j]); |
0627f609 |
2729 | //20-12-05 } |
2730 | if (cath) { xPad1[n1] = fXyq[0][j]; yPad1[n1++] = fXyq[1][j]; } |
2731 | else { xPad0[n0] = fXyq[0][j]; yPad0[n0++] = fXyq[1][j]; } |
1af223d7 |
2732 | } |
2b1e4f0e |
2733 | } |
5a051e34 |
2734 | |
2735 | // Sort |
2736 | if (n0) { |
2737 | TMath::Sort (n0, xPad0, nPad0); // in X |
2738 | for (Int_t i = 1; i < n0; i++) |
2739 | if (xPad0[nPad0[i]] - xPad0[nPad0[i-1]] < -0.01) npadx[0]++; |
2740 | TMath::Sort (n0, yPad0, nPad0); // in Y |
2741 | for (Int_t i = 1; i < n0; i++) |
2742 | if (yPad0[nPad0[i]] - yPad0[nPad0[i-1]] < -0.01) npady[0]++; |
2743 | } |
2744 | |
2745 | if (n1) { |
2746 | TMath::Sort (n1, xPad1, nPad1); // in X |
2747 | for (Int_t i = 1; i < n1; i++) |
2748 | if (xPad1[nPad1[i]] - xPad1[nPad1[i-1]] < -0.01) npadx[1]++; |
2749 | TMath::Sort (n1, yPad1, nPad1); // in Y |
2750 | for (Int_t i = 1; i < n1; i++) |
2751 | if (yPad1[nPad1[i]] - yPad1[nPad1[i-1]] < -0.01) npady[1]++; |
2752 | } |
2753 | if (fnPads[0]) { delete [] xPad0; delete [] yPad0; delete [] nPad0; } |
2754 | if (fnPads[1]) { delete [] xPad1; delete [] yPad1; delete [] nPad1; } |
cc87ebcd |
2755 | if (TMath::Abs (wMinY[0] - wMinY[1]) < 1.e-3) nInY = TMath::Max (npady[0], npady[1]); |
2756 | else nInY = wMinY[0] < wMinY[1] ? npady[0] : npady[1]; |
2757 | if (TMath::Abs (wMinX[0] - wMinX[1]) < 1.e-3) nInX = TMath::Max (npadx[0], npadx[1]); |
2758 | else nInX = wMinX[0] < wMinX[1] ? npadx[0] : npadx[1]; |
2b1e4f0e |
2759 | } |
2760 | |
2761 | //_____________________________________________________________________________ |
2762 | void AliMUONClusterFinderAZ::Simple() |
2763 | { |
2764 | // Process simple cluster (small number of pads) without EM-procedure |
2765 | |
ff7af159 |
2766 | Int_t nForFit = 1, clustFit[1] = {0}, nfit; |
2b1e4f0e |
2767 | Double_t parOk[3] = {0.}; |
2768 | TObjArray *clusters[1]; |
ff7af159 |
2769 | clusters[0] = fPixArray; |
5a051e34 |
2770 | for (Int_t i = 0; i < fnPads[0]+fnPads[1]; i++) { |
0627f609 |
2771 | if (fXyq[2][i] > fgkSaturation-1) fPadIJ[1][i] = -9; |
5a051e34 |
2772 | else fPadIJ[1][i] = 1; |
2773 | } |
0627f609 |
2774 | nfit = Fit(1, nForFit, clustFit, clusters, parOk); |
2b1e4f0e |
2775 | } |
2776 | |
2777 | //_____________________________________________________________________________ |
2778 | void AliMUONClusterFinderAZ::Errors(AliMUONRawCluster *clus) |
2779 | { |
2780 | // Correct reconstructed coordinates for some clusters and evaluate errors |
2781 | |
2782 | Double_t qTot = clus->GetCharge(0), fmin = clus->GetChi2(0); |
2783 | Double_t xreco = clus->GetX(0), yreco = clus->GetY(0), zreco = clus->GetZ(0); |
2784 | Double_t sigmax[2] = {0}; |
2785 | |
2786 | Int_t nInX = 1, nInY, maxdig[2] ={-1, -1}, digit, cath1, isec; |
2787 | PadsInXandY(nInX, nInY); |
2788 | |
2789 | // Find pad with maximum signal |
2790 | for (Int_t cath = 0; cath < 2; cath++) { |
2791 | for (Int_t j = 0; j < clus->GetMultiplicity(cath); j++) { |
2792 | cath1 = cath; |
2793 | digit = clus->GetIndex(j, cath); |
2794 | if (digit < 0) { cath1 = TMath::Even(cath); digit = -digit - 1; } // from the other cathode |
2795 | |
2796 | if (clus->GetContrib(j,cath) > sigmax[cath1]) { |
2797 | sigmax[cath1] = clus->GetContrib(j,cath); |
2798 | maxdig[cath1] = digit; |
2799 | } |
2800 | } |
2801 | } |
2802 | |
2803 | // Size of pad with maximum signal and reco coordinate distance from the pad center |
2804 | AliMUONDigit *mdig = 0; |
2805 | Double_t wx[2], wy[2], dxc[2], dyc[2]; |
2806 | Float_t xpad, ypad, zpad; |
2807 | Int_t ix, iy; |
2808 | for (Int_t cath = 0; cath < 2; cath++) { |
2809 | if (maxdig[cath] < 0) continue; |
2810 | mdig = fInput->Digit(cath,maxdig[cath]); |
0627f609 |
2811 | isec = fSegmentation[cath]->Sector(mdig->PadX(), mdig->PadY()); |
2812 | wx[cath] = fSegmentation[cath]->Dpx(isec); |
2813 | wy[cath] = fSegmentation[cath]->Dpy(isec); |
2814 | fSegmentation[cath]->GetPadI(xreco, yreco, zreco, ix, iy); |
2815 | isec = fSegmentation[cath]->Sector(ix, iy); |
2b1e4f0e |
2816 | if (isec > 0) { |
0627f609 |
2817 | fSegmentation[cath]->GetPadC(ix, iy, xpad, ypad, zpad); |
2b1e4f0e |
2818 | dxc[cath] = xreco - xpad; |
2819 | dyc[cath] = yreco - ypad; |
2820 | } |
2821 | } |
2822 | |
2823 | // Check if pad with max charge at the edge (number of neughbours) |
2824 | Int_t nn, xList[10], yList[10], neighbx[2][2] = {{0,0}, {0,0}}, neighby[2][2]= {{0,0}, {0,0}}; |
2825 | for (Int_t cath = 0; cath < 2; cath++) { |
2826 | if (maxdig[cath] < 0) continue; |
2827 | mdig = fInput->Digit(cath,maxdig[cath]); |
0627f609 |
2828 | fSegmentation[cath]->Neighbours(mdig->PadX(), mdig->PadY(), &nn, xList, yList); |
2829 | isec = fSegmentation[cath]->Sector(mdig->PadX(), mdig->PadY()); |
2830 | /*?? |
f29ba3e1 |
2831 | Float_t sprX = fResponse->SigmaIntegration() * fResponse->ChargeSpreadX(); |
2832 | Float_t sprY = fResponse->SigmaIntegration() * fResponse->ChargeSpreadY(); |
2833 | //fSegmentation[cath]->FirstPad(fInput->DetElemId(),muons[ihit][1], muons[ihit][2], muons[ihit][3], sprX, sprY); |
0627f609 |
2834 | //fSegmentation[cath]->FirstPad(fInput->DetElemId(),xreco, yreco, zreco, sprX, sprY); |
2835 | fSegmentation[cath]->FirstPad(xreco, yreco, zreco, sprX, sprY); |
2b1e4f0e |
2836 | Int_t border = 0; |
0627f609 |
2837 | //if (fSegmentation[cath]->Sector(fInput->DetElemId(),fSegmentation[cath]->Ix(),fSegmentation[cath]->Iy()) <= 0) { |
2838 | if (fSegmentation[cath]->Sector(fSegmentation[cath]->Ix(), fSegmentation[cath]->Iy()) <= 0) { |
2839 | //fSegmentation[cath]->NextPad(fInput->DetElemId()); |
2840 | fSegmentation[cath]->NextPad(); |
2b1e4f0e |
2841 | border = 1; |
2842 | } |
0627f609 |
2843 | */ |
2b1e4f0e |
2844 | for (Int_t j=0; j<nn; j++) { |
0627f609 |
2845 | //if (border && yList[j] < fSegmentation[cath]->Iy()) continue; |
2846 | fSegmentation[cath]->GetPadC(xList[j], yList[j], xpad, ypad, zpad); |
2b1e4f0e |
2847 | //cout << ch << " " << xList[j] << " " << yList[j] << " " << border << " " << x << " " << y << " " << xpad << " " << ypad << endl; |
2848 | if (TMath::Abs(xpad) < 1 && TMath::Abs(ypad) < 1) continue; |
2849 | if (xList[j] == mdig->PadX()-1 || mdig->PadX() == 1 && |
2850 | xList[j] == -1) neighbx[cath][0] = 1; |
2851 | else if (xList[j] == mdig->PadX()+1 || mdig->PadX() == -1 && |
2852 | xList[j] == 1) neighbx[cath][1] = 1; |
2853 | if (yList[j] == mdig->PadY()-1 || mdig->PadY() == 1 && |
2854 | yList[j] == -1) neighby[cath][0] = 1; |
2855 | else if (yList[j] == mdig->PadY()+1 || mdig->PadY() == -1 && |
2856 | yList[j] == 1) neighby[cath][1] = 1; |
2857 | } // for (Int_t j=0; j<nn; |
2858 | if (neighbx[cath][0] && neighbx[cath][1]) neighbx[cath][0] = 0; |
2859 | else if (neighbx[cath][1]) neighbx[cath][0] = -1; |
2860 | else neighbx[cath][0] = 1; |
2861 | if (neighby[cath][0] && neighby[cath][1]) neighby[cath][0] = 0; |
2862 | else if (neighby[cath][1]) neighby[cath][0] = -1; |
2863 | else neighby[cath][0] = 1; |
2864 | } |
2865 | |
2866 | Int_t iOver = clus->GetClusterType(); |
2867 | // One-sided cluster |
2868 | if (!clus->GetMultiplicity(0)) { |
2869 | neighby[0][0] = neighby[1][0]; |
2870 | wy[0] = wy[1]; |
2871 | if (iOver < 99) iOver += 100 * iOver; |
2872 | dyc[0] = dyc[1]; |
2873 | } else if (!clus->GetMultiplicity(1)) { |
2874 | neighbx[1][0] = neighbx[0][0]; |
2875 | wx[1] = wx[0]; |
2876 | if (iOver < 99) iOver += 100 * iOver; |
2877 | dxc[1] = dxc[0]; |
2878 | } |
2879 | |
2880 | // Apply corrections and evaluate errors |
2881 | Double_t errY, errX; |
2882 | Errors(nInY, nInX, neighby[0][0],neighbx[1][0], fmin, wy[0]*10, wx[1]*10, iOver, |
2883 | dyc[0], dxc[1], qTot, yreco, xreco, errY, errX); |
2884 | errY = TMath::Max (errY, 0.01); |
2885 | //errY = 0.01; |
2886 | //errX = TMath::Max (errX, 0.144); |
2887 | clus->SetX(0, xreco); clus->SetY(0, yreco); |
1af223d7 |
2888 | clus->SetErrX(errX); clus->SetErrY(errY); |
2b1e4f0e |
2889 | } |
2890 | |
2891 | //_____________________________________________________________________________ |
2892 | void AliMUONClusterFinderAZ::Errors(Int_t ny, Int_t nx, Int_t iby, Int_t ibx, Double_t fmin, |
2893 | Double_t wy, Double_t wx, Int_t iover, |
2894 | Double_t dyc, Double_t /*dxc*/, Double_t qtot, |
2895 | Double_t &yrec, Double_t &xrec, Double_t &erry, Double_t &errx) |
2896 | { |
2897 | // Correct reconstructed coordinates for some clusters and evaluate errors |
2898 | |
2899 | erry = 0.01; |
2900 | errx = 0.144; |
2901 | Int_t iovery = iover % 100; |
2902 | Double_t corr = 0; |
2903 | |
2904 | /* ---> Ny = 1 */ |
2905 | if (ny == 1) { |
2906 | if (iby != 0) { |
2907 | // edge effect |
2908 | yrec += iby * (0.1823+0.2008)/2; |
2909 | erry = 0.04587; |
2910 | } else { |
2911 | // Find "effective pad width" |
2912 | Double_t width = 0.218 / (1.31e-4 * TMath::Exp (2.688 * TMath::Log(qtot)) + 1) * 2; |
2913 | width = TMath::Min (width, 0.4); |
2914 | erry = width / TMath::Sqrt(12.); |
2915 | erry = TMath::Max (erry, 0.01293); |
2916 | } |
2917 | goto x; //return; |
2918 | } |
2919 | |
2920 | /* ---> "Bad" fit */ |
2921 | if (fmin > 0.4) { |
2922 | erry = 0.1556; |
2923 | if (ny == 5) erry = 0.06481; |
2924 | goto x; //return; |
2925 | } |
2926 | |
2927 | /* ---> By != 0 */ |
2928 | if (iby != 0) { |
2929 | if (ny > 2) { |
2930 | erry = 0.00417; //0.01010 |
2931 | } else { |
2932 | // ny = 2 |
2933 | if (dyc * iby > -0.05) { |
2934 | Double_t dyc2 = dyc * dyc; |
2935 | if (iby < 0) { |
2936 | corr = 0.019 - 0.602 * dyc + 8.739 * dyc2 - 44.209 * dyc2 * dyc; |
2937 | corr = TMath::Min (corr, TMath::Abs(-0.25-dyc)); |
2938 | yrec -= corr; |
2939 | //dyc -= corr; |
2940 | erry = 0.00814; |
2941 | } else { |
2942 | corr = 0.006 + 0.300 * dyc + 6.147 * dyc2 + 42.039 * dyc2 * dyc; |
2943 | corr = TMath::Min (corr, 0.25-dyc); |
2944 | yrec += corr; |
2945 | //dyc += corr; |
2946 | erry = 0.01582; |
2947 | } |
2948 | } else { |
2949 | erry = (0.00303 + 0.00296) / 2; |
2950 | } |
2951 | } |
2952 | goto x; //return; |
2953 | } |
2954 | |
2955 | /* ---> Overflows */ |
2956 | if (iovery != 0) { |
2957 | if (qtot < 3000) { |
2958 | erry = 0.0671; |
2959 | } else { |
2960 | if (iovery > 1) { |
2961 | erry = 0.09214; |
2962 | } else if (TMath::Abs(wy - 5) < 0.1) { |
2963 | erry = 0.061; //0.06622 |
2964 | } else { |
2965 | erry = 0.00812; // 0.01073 |
2966 | } |
2967 | } |
2968 | goto x; //return; |
2969 | } |
2970 | |
2971 | /* ---> "Good" but very high signal */ |
2972 | if (qtot > 4000) { |
2973 | if (TMath::Abs(wy - 4) < 0.1) { |
2974 | erry = 0.00117; |
2975 | } else if (fmin < 0.03 && qtot < 6000) { |
2976 | erry = 0.01003; |
2977 | } else { |
2978 | erry = 0.1931; |
2979 | } |
2980 | goto x; //return; |
2981 | } |
2982 | |
2983 | /* ---> "Good" clusters */ |
2984 | if (ny > 3) { |
2985 | if (TMath::Abs(wy - 5) < 0.1) { |
2986 | erry = 0.0011; //0.00304 |
2987 | } else if (qtot < 400.) { |
2988 | erry = 0.0165; |
2989 | } else { |
2990 | erry = 0.00135; // 0.00358 |
2991 | } |
2992 | } else if (ny == 3) { |
2993 | if (TMath::Abs(wy - 4) < 0.1) { |
2994 | erry = 35.407 / (1 + TMath::Exp(5.511*TMath::Log(qtot/265.51))) + 11.564; |
2995 | //erry = 83.512 / (1 + TMath::Exp(3.344*TMath::Log(qtot/211.58))) + 12.260; |
2996 | } else { |
2997 | erry = 147.03 / (1 + TMath::Exp(1.713*TMath::Log(qtot/73.151))) + 9.575; |
2998 | //erry = 91.743 / (1 + TMath::Exp(2.332*TMath::Log(qtot/151.67))) + 11.453; |
2999 | } |
3000 | erry *= 1.e-4; |
3001 | } else { |
3002 | // ny = 2 |
3003 | if (TMath::Abs(wy - 4) < 0.1) { |
3004 | erry = 60.800 / (1 + TMath::Exp(3.305*TMath::Log(qtot/104.53))) + 11.702; |
3005 | //erry = 73.128 / (1 + TMath::Exp(5.676*TMath::Log(qtot/120.93))) + 17.839; |
3006 | } else { |
3007 | erry = 117.98 / (1 + TMath::Exp(2.005*TMath::Log(qtot/37.649))) + 21.431; |
3008 | //erry = 99.066 / (1 + TMath::Exp(4.900*TMath::Log(qtot/107.57))) + 25.315; |
3009 | } |
3010 | erry *= 1.e-4; |
3011 | } |
3012 | //return; |
3013 | |
3014 | x: |
3015 | /* ---> X-coordinate */ |
3016 | /* ---> Y-side */ |
3017 | if (wx > 11) { |
3018 | errx = 0.0036; |
3019 | xrec -= 0.1385; |
3020 | return; |
3021 | } |
3022 | /* ---> Nx = 1 */ |
3023 | if (nx == 1) { |
3024 | if (TMath::Abs(wx - 6) < 0.1) { |
3025 | if (qtot < 40) errx = 0.1693; |
3026 | else errx = 0.06241; |
3027 | } else if (TMath::Abs(wx - 7.5) < 0.1) { |
3028 | if (qtot < 40) errx = 0.2173; |
3029 | else errx = 0.07703; |
3030 | } else if (TMath::Abs(wx - 10) < 0.1) { |
3031 | if (ibx == 0) { |
3032 | if (qtot < 40) errx = 0.2316; |
3033 | else errx = 0.1426; |
3034 | } else { |
3035 | xrec += (0.2115 + 0.1942) / 2 * ibx; |
3036 | errx = 0.1921; |
3037 | } |
3038 | } |
3039 | return; |
3040 | } |
3041 | /* ---> "Bad" fit */ |
3042 | if (fmin > 0.5) { |
3043 | errx = 0.1591; |
3044 | return; |
3045 | } |
3046 | /* ---> Bx != 0 */ |
3047 | if (ibx != 0) { |
3048 | if (ibx > 0) { errx = 0.06761; xrec -= 0.03832; } |
3049 | else { errx = 0.06653; xrec += 0.02581; } |
3050 | return; |
3051 | } |
3052 | /* ---> Overflows */ |
3053 | if (iover != 0) { |
3054 | if (TMath::Abs(wx - 6) < 0.1) errx = 0.06979; |
3055 | else if (TMath::Abs(wx - 7.5) < 0.1) errx = 0.1089; |
3056 | else if (TMath::Abs(wx - 10) < 0.1) errx = 0.09847; |
3057 | return; |
3058 | } |
3059 | /* ---> Good */ |
3060 | if (TMath::Abs(wx - 6) < 0.1) errx = 0.06022; |
3061 | else if (TMath::Abs(wx - 7.5) < 0.1) errx = 0.07247; |
3062 | else if (TMath::Abs(wx - 10) < 0.1) errx = 0.07359; |
3063 | } |
3064 | |