]>
Commit | Line | Data |
---|---|---|
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 | ||
18 | // Clusterizer class developped by Zitchenko (Dubna) | |
0df3ca52 | 19 | |
0df3ca52 | 20 | #include <Riostream.h> |
21 | #include <TROOT.h> | |
22 | #include <TCanvas.h> | |
23 | #include <TLine.h> | |
24 | #include <TTree.h> | |
25 | #include <TH2.h> | |
26 | #include <TView.h> | |
27 | #include <TStyle.h> | |
28 | #include <TMinuit.h> | |
29 | #include <TMatrixD.h> | |
30 | ||
30178c30 | 31 | #include "AliMUONClusterFinderAZ.h" |
0df3ca52 | 32 | #include "AliHeader.h" |
33 | #include "AliRun.h" | |
34 | #include "AliMUON.h" | |
35 | #include "AliMUONChamber.h" | |
36 | #include "AliMUONDigit.h" | |
37 | #include "AliMUONHit.h" | |
38 | #include "AliMUONChamber.h" | |
39 | #include "AliMUONRawCluster.h" | |
40 | #include "AliMUONClusterInput.h" | |
41 | #include "AliMUONPixel.h" | |
5d12ce38 | 42 | #include "AliMC.h" |
0df3ca52 | 43 | |
0df3ca52 | 44 | ClassImp(AliMUONClusterFinderAZ) |
0558a292 | 45 | |
343146bf | 46 | const Double_t AliMUONClusterFinderAZ::fgkCouplMin = 1.e-3; // threshold on coupling |
0558a292 | 47 | AliMUONClusterFinderAZ* AliMUONClusterFinderAZ::fgClusterFinder = 0x0; |
48 | TMinuit* AliMUONClusterFinderAZ::fgMinuit = 0x0; | |
0df3ca52 | 49 | |
0df3ca52 | 50 | //_____________________________________________________________________________ |
30178c30 | 51 | AliMUONClusterFinderAZ::AliMUONClusterFinderAZ(Bool_t draw, Int_t iReco) |
74f7bbc5 | 52 | : AliMUONClusterFinderVS() |
0df3ca52 | 53 | { |
54 | // Constructor | |
55 | for (Int_t i=0; i<4; i++) {fHist[i] = 0;} | |
56 | fMuonDigits = 0; | |
57 | fSegmentation[1] = fSegmentation[0] = 0; | |
0558a292 | 58 | fgClusterFinder = 0x0; |
59 | fgMinuit = 0x0; | |
0df3ca52 | 60 | if (!fgClusterFinder) fgClusterFinder = this; |
61 | if (!fgMinuit) fgMinuit = new TMinuit(8); | |
62 | fDraw = draw; | |
63 | fReco = iReco; | |
64 | fPixArray = new TObjArray(20); | |
65 | /* | |
66 | fPoints = 0; | |
67 | fPhits = 0; | |
68 | fRpoints = 0; | |
69 | fCanvas = 0; | |
70 | fNextCathode = kFALSE; | |
71 | fColPad = 0; | |
72 | */ | |
73 | } | |
74 | ||
74f7bbc5 | 75 | //_____________________________________________________________________________ |
76 | AliMUONClusterFinderAZ::AliMUONClusterFinderAZ(const AliMUONClusterFinderAZ& rhs) | |
77 | : AliMUONClusterFinderVS(rhs) | |
78 | { | |
79 | // Protected copy constructor | |
80 | ||
81 | Fatal("AliMUONClusterFinderAZModule", "Not implemented."); | |
82 | } | |
83 | ||
0df3ca52 | 84 | //_____________________________________________________________________________ |
85 | AliMUONClusterFinderAZ::~AliMUONClusterFinderAZ() | |
86 | { | |
87 | // Destructor | |
88 | delete fgMinuit; fgMinuit = 0; delete fPixArray; fPixArray = 0; | |
89 | /* | |
90 | // Delete space point structure | |
91 | if (fPoints) fPoints->Delete(); | |
92 | delete fPoints; | |
93 | fPoints = 0; | |
94 | // | |
95 | if (fPhits) fPhits->Delete(); | |
96 | delete fPhits; | |
97 | fPhits = 0; | |
98 | // | |
99 | if (fRpoints) fRpoints->Delete(); | |
100 | delete fRpoints; | |
101 | fRpoints = 0; | |
102 | */ | |
103 | } | |
104 | ||
105 | //_____________________________________________________________________________ | |
106 | void AliMUONClusterFinderAZ::FindRawClusters() | |
107 | { | |
108 | // To provide the same interface as in AliMUONClusterFinderVS | |
109 | ||
110 | EventLoop (gAlice->GetHeader()->GetEvent(), AliMUONClusterInput::Instance()->Chamber()); | |
111 | } | |
112 | ||
113 | //_____________________________________________________________________________ | |
114 | void AliMUONClusterFinderAZ::EventLoop(Int_t nev=0, Int_t ch=0) | |
115 | { | |
116 | // Loop over events | |
117 | ||
118 | FILE *lun = 0; | |
119 | TCanvas *c1 = 0; | |
120 | TView *view = 0; | |
121 | TH2F *hist = 0; | |
122 | Double_t p1[3]={0}, p2[3]; | |
c1aed84f | 123 | TTree *treeR = 0; |
0df3ca52 | 124 | if (fDraw) { |
125 | // File | |
126 | lun = fopen("pool.dat","w"); | |
127 | c1 = new TCanvas("c1","Clusters",0,0,600,700); | |
128 | c1->Divide(1,2); | |
129 | new TCanvas("c2","Mlem",700,0,600,350); | |
130 | } | |
131 | ||
132 | newev: | |
133 | Int_t nparticles = 0, nent; | |
88cb7938 | 134 | |
135 | //Loaders | |
136 | AliRunLoader * rl = AliRunLoader::GetRunLoader(); | |
137 | AliLoader * gime = rl->GetLoader("MUONLoader"); | |
138 | ||
139 | if (!fReco) nparticles = rl->GetEvent(nev); | |
5d12ce38 | 140 | else nparticles = gAlice->GetMCApp()->GetNtrack(); |
0df3ca52 | 141 | cout << "nev " << nev <<endl; |
142 | cout << "nparticles " << nparticles <<endl; | |
143 | if (nparticles <= 0) return; | |
144 | ||
c1aed84f | 145 | TTree *treeH = gime->TreeH(); |
146 | Int_t ntracks = (Int_t) treeH->GetEntries(); | |
0df3ca52 | 147 | cout<<"ntracks "<<ntracks<<endl; |
148 | ||
149 | // Get pointers to Alice detectors and Digits containers | |
c1aed84f | 150 | AliMUON *muon = (AliMUON*) gAlice->GetModule("MUON"); |
151 | if (!muon) return; | |
0df3ca52 | 152 | // TClonesArray *Particles = gAlice->Particles(); |
153 | if (!fReco) { | |
c1aed84f | 154 | treeR = gime->TreeR(); |
155 | if (treeR) { | |
156 | muon->ResetRawClusters(); | |
157 | nent = (Int_t) treeR->GetEntries(); | |
0df3ca52 | 158 | if (nent != 1) { |
159 | cout << "Error in MUONdrawClust" << endl; | |
160 | cout << " nent = " << nent << " not equal to 1" << endl; | |
161 | //exit(0); | |
162 | } | |
c1aed84f | 163 | } // if (treeR) |
0df3ca52 | 164 | } // if (!fReco) |
165 | ||
c1aed84f | 166 | TTree *treeD = gime->TreeD(); |
167 | //muon->ResetDigits(); | |
0df3ca52 | 168 | |
c1aed84f | 169 | TClonesArray *listMUONrawclust ; |
0df3ca52 | 170 | AliMUONChamber* iChamber = 0; |
171 | ||
172 | // As default draw the first cluster of the chamber #0 | |
173 | ||
174 | newchamber: | |
175 | if (ch > 9) {if (fReco) return; nev++; ch = 0; goto newev;} | |
176 | //gAlice->ResetDigits(); | |
c1aed84f | 177 | fMuonDigits = muon->GetMUONData()->Digits(ch); |
0df3ca52 | 178 | if (fMuonDigits == 0) return; |
c1aed84f | 179 | iChamber = &(muon->Chamber(ch)); |
0df3ca52 | 180 | fSegmentation[0] = iChamber->SegmentationModel(1); |
181 | fSegmentation[1] = iChamber->SegmentationModel(2); | |
182 | fResponse = iChamber->ResponseModel(); | |
183 | ||
184 | nent = 0; | |
185 | ||
c1aed84f | 186 | if (treeD) { |
187 | nent = (Int_t) treeD->GetEntries(); | |
0df3ca52 | 188 | //printf(" entries %d \n", nent); |
189 | } | |
190 | ||
191 | Int_t ndigits[2]={9,9}, nShown[2]={0}; | |
192 | for (Int_t i=0; i<2; i++) { | |
343146bf | 193 | for (Int_t j=0; j<fgkDim; j++) {fUsed[i][j]=kFALSE;} |
0df3ca52 | 194 | } |
195 | ||
196 | next: | |
197 | if (ndigits[0] == nShown[0] && ndigits[1] == nShown[1]) { | |
198 | // No more clusters | |
199 | if (fReco) return; | |
200 | ch++; | |
201 | goto newchamber; // next chamber | |
202 | } | |
203 | Float_t xpad, ypad, zpad, zpad0; | |
204 | TLine *line[99]={0}; | |
205 | Int_t nLine = 0; | |
206 | Bool_t first = kTRUE; | |
207 | cout << " *** Event # " << nev << " chamber: " << ch << endl; | |
208 | fnPads[0] = fnPads[1] = 0; | |
343146bf | 209 | for (Int_t i=0; i<fgkDim; i++) {fPadIJ[1][i] = 0;} |
0df3ca52 | 210 | //for (Int_t iii = 0; iii<999; iii++) { |
211 | for (Int_t iii = 0; iii<2; iii++) { | |
212 | Int_t cath = TMath::Odd(iii); | |
213 | gAlice->ResetDigits(); | |
c1aed84f | 214 | treeD->GetEvent(cath); |
215 | fMuonDigits = muon->GetMUONData()->Digits(ch); | |
0df3ca52 | 216 | |
217 | ndigits[cath] = fMuonDigits->GetEntriesFast(); | |
218 | if (!ndigits[0] && !ndigits[1]) {if (fReco) return; ch++; goto newchamber;} | |
219 | if (ndigits[cath] == 0) continue; | |
220 | cout << " ndigits: " << ndigits[cath] << " " << cath << endl; | |
221 | ||
222 | AliMUONDigit *mdig; | |
223 | Int_t digit; | |
224 | ||
c1aed84f | 225 | Bool_t eEOC = kTRUE; // end-of-cluster |
0df3ca52 | 226 | for (digit = 0; digit < ndigits[cath]; digit++) { |
227 | mdig = (AliMUONDigit*)fMuonDigits->UncheckedAt(digit); | |
228 | if (mdig->Cathode() != cath) continue; | |
229 | if (first) { | |
230 | // Find first unused pad | |
231 | if (fUsed[cath][digit]) continue; | |
232 | fSegmentation[cath]->GetPadC(mdig->PadX(),mdig->PadY(),xpad,ypad,zpad0); | |
233 | } else { | |
234 | if (fUsed[cath][digit]) continue; | |
235 | fSegmentation[cath]->GetPadC(mdig->PadX(),mdig->PadY(),xpad,ypad,zpad); | |
236 | if (TMath::Abs(zpad-zpad0)>0.1) continue; // different slats | |
237 | // Find a pad overlapping with the cluster | |
238 | if (!Overlap(cath,mdig)) continue; | |
239 | } | |
240 | // Add pad - recursive call | |
241 | AddPad(cath,digit); | |
c1aed84f | 242 | eEOC = kFALSE; |
0df3ca52 | 243 | if (digit >= 0) break; |
244 | } | |
c1aed84f | 245 | if (first && eEOC) { |
0df3ca52 | 246 | // No more unused pads |
247 | if (cath == 0) continue; // on cathode #0 - check #1 | |
248 | else { | |
249 | // No more clusters | |
250 | if (fReco) return; | |
251 | ch++; | |
252 | goto newchamber; // next chamber | |
253 | } | |
254 | } | |
c1aed84f | 255 | if (eEOC) break; // cluster found |
0df3ca52 | 256 | first = kFALSE; |
257 | cout << " nPads: " << fnPads[cath] << " " << nShown[cath]+fnPads[cath] << " " << cath << endl; | |
258 | } // for (Int_t iii = 0; | |
259 | ||
260 | ||
261 | if (fReco) goto skip; | |
262 | char hName[4]; | |
263 | for (Int_t cath = 0; cath<2; cath++) { | |
264 | // Build histograms | |
265 | if (fHist[cath*2]) {fHist[cath*2]->Delete(); fHist[cath*2] = 0;} | |
266 | if (fHist[cath*2+1]) {fHist[cath*2+1]->Delete(); fHist[cath*2+1] = 0;} | |
267 | if (fnPads[cath] == 0) continue; // cluster on one cathode only | |
268 | Float_t wxMin=999, wxMax=0, wyMin=999, wyMax=0; | |
269 | Int_t minDx=0, maxDx=0, minDy=0, maxDy=0; | |
270 | for (Int_t i=0; i<fnPads[0]+fnPads[1]; i++) { | |
271 | if (fPadIJ[0][i] != cath) continue; | |
272 | if (fXyq[3][i] < wxMin) {wxMin = fXyq[3][i]; minDx = i;} | |
273 | if (fXyq[3][i] > wxMax) {wxMax = fXyq[3][i]; maxDx = i;} | |
274 | if (fXyq[4][i] < wyMin) {wyMin = fXyq[4][i]; minDy = i;} | |
275 | if (fXyq[4][i] > wyMax) {wyMax = fXyq[4][i]; maxDy = i;} | |
276 | } | |
277 | cout << minDx << maxDx << minDy << maxDy << endl; | |
278 | Int_t nx, ny, padSize; | |
279 | Float_t xmin=9999, xmax=-9999, ymin=9999, ymax=-9999; | |
280 | if (TMath::Nint(fXyq[3][minDx]*1000) == TMath::Nint(fXyq[3][maxDx]*1000) && | |
281 | TMath::Nint(fXyq[4][minDy]*1000) == TMath::Nint(fXyq[4][maxDy]*1000)) { | |
282 | // the same segmentation | |
283 | cout << " Same" << endl; | |
284 | cout << fXyq[3][minDx] << " " << fXyq[3][maxDx] << " " << fXyq[4][minDy] << " " << fXyq[4][maxDy] << endl; | |
285 | for (Int_t i=0; i<fnPads[0]+fnPads[1]; i++) { | |
286 | if (fPadIJ[0][i] != cath) continue; | |
287 | if (fXyq[0][i] < xmin) xmin = fXyq[0][i]; | |
288 | if (fXyq[0][i] > xmax) xmax = fXyq[0][i]; | |
289 | if (fXyq[1][i] < ymin) ymin = fXyq[1][i]; | |
290 | if (fXyq[1][i] > ymax) ymax = fXyq[1][i]; | |
291 | } | |
292 | xmin -= fXyq[3][minDx]; xmax += fXyq[3][minDx]; | |
293 | ymin -= fXyq[4][minDy]; ymax += fXyq[4][minDy]; | |
294 | nx = TMath::Nint ((xmax-xmin)/wxMin/2); | |
295 | ny = TMath::Nint ((ymax-ymin)/wyMin/2); | |
296 | sprintf(hName,"h%d",cath*2); | |
297 | fHist[cath*2] = new TH2F(hName,"cluster",nx,xmin,xmax,ny,ymin,ymax); | |
298 | cout << fHist[cath*2] << " " << fnPads[cath] << endl; | |
299 | for (Int_t i=0; i<fnPads[0]+fnPads[1]; i++) { | |
300 | if (fPadIJ[0][i] != cath) continue; | |
301 | fHist[cath*2]->Fill(fXyq[0][i],fXyq[1][i],fXyq[2][i]); | |
302 | //cout << fXyq[0][i] << fXyq[1][i] << fXyq[2][i] << endl; | |
303 | } | |
304 | } else { | |
305 | // different segmentation in the cluster | |
306 | cout << " Different" << endl; | |
307 | cout << fXyq[3][minDx] << " " << fXyq[3][maxDx] << " " << fXyq[4][minDy] << " " << fXyq[4][maxDy] << endl; | |
308 | Int_t nOK = 0; | |
309 | Int_t indx, locMin, locMax; | |
310 | if (TMath::Nint(fXyq[3][minDx]*1000) != TMath::Nint(fXyq[3][maxDx]*1000)) { | |
311 | // different segmentation along x | |
312 | indx = 0; | |
313 | locMin = minDx; | |
314 | locMax = maxDx; | |
315 | } else { | |
316 | // different segmentation along y | |
317 | indx = 1; | |
318 | locMin = minDy; | |
319 | locMax = maxDy; | |
320 | } | |
321 | Int_t loc = locMin; | |
322 | for (Int_t i=0; i<2; i++) { | |
323 | // loop over different pad sizes | |
324 | if (i>0) loc = locMax; | |
325 | padSize = TMath::Nint(fXyq[indx+3][loc]*1000); | |
326 | xmin = 9999; xmax = -9999; ymin = 9999; ymax = -9999; | |
327 | for (Int_t j=0; j<fnPads[0]+fnPads[1]; j++) { | |
328 | if (fPadIJ[0][j] != cath) continue; | |
329 | if (TMath::Nint(fXyq[indx+3][j]*1000) != padSize) continue; | |
330 | nOK++; | |
331 | xmin = TMath::Min (xmin,fXyq[0][j]); | |
332 | xmax = TMath::Max (xmax,fXyq[0][j]); | |
333 | ymin = TMath::Min (ymin,fXyq[1][j]); | |
334 | ymax = TMath::Max (ymax,fXyq[1][j]); | |
335 | } | |
336 | xmin -= fXyq[3][loc]; xmax += fXyq[3][loc]; | |
337 | ymin -= fXyq[4][loc]; ymax += fXyq[4][loc]; | |
338 | nx = TMath::Nint ((xmax-xmin)/fXyq[3][loc]/2); | |
339 | ny = TMath::Nint ((ymax-ymin)/fXyq[4][loc]/2); | |
340 | sprintf(hName,"h%d",cath*2+i); | |
341 | fHist[cath*2+i] = new TH2F(hName,"cluster",nx,xmin,xmax,ny,ymin,ymax); | |
342 | for (Int_t j=0; j<fnPads[0]+fnPads[1]; j++) { | |
343 | if (fPadIJ[0][j] != cath) continue; | |
344 | if (TMath::Nint(fXyq[indx+3][j]*1000) != padSize) continue; | |
345 | fHist[cath*2+i]->Fill(fXyq[0][j],fXyq[1][j],fXyq[2][j]); | |
346 | } | |
347 | } // for (Int_t i=0; | |
348 | if (nOK != fnPads[cath]) cout << " *** Too many segmentations: nPads, nOK " << fnPads[cath] << " " << nOK << endl; | |
349 | } // if (TMath::Nint(fXyq[3][minDx]*1000) | |
350 | } // for (Int_t cath = 0; | |
351 | ||
352 | // Draw histograms and coordinates | |
353 | for (Int_t cath=0; cath<2; cath++) { | |
354 | if (cath == 0) ModifyHistos(); | |
355 | if (fnPads[cath] == 0) continue; // cluster on one cathode only | |
356 | if (fDraw) { | |
357 | c1->cd(cath+1); | |
358 | gPad->SetTheta(55); | |
359 | gPad->SetPhi(30); | |
cd747ddb | 360 | Double_t x, y, x0, y0, r1=999, r2=0; |
0df3ca52 | 361 | if (fHist[cath*2+1]) { |
362 | // | |
363 | x0 = fHist[cath*2]->GetXaxis()->GetXmin() - 1000*TMath::Cos(30*TMath::Pi()/180); | |
364 | y0 = fHist[cath*2]->GetYaxis()->GetXmin() - 1000*TMath::Sin(30*TMath::Pi()/180); | |
365 | r1 = 0; | |
366 | Int_t ihist=cath*2; | |
367 | for (Int_t iy=1; iy<=fHist[ihist]->GetNbinsY(); iy++) { | |
368 | y = fHist[ihist]->GetYaxis()->GetBinCenter(iy) | |
369 | + fHist[ihist]->GetYaxis()->GetBinWidth(iy); | |
370 | for (Int_t ix=1; ix<=fHist[ihist]->GetNbinsX(); ix++) { | |
371 | if (fHist[ihist]->GetCellContent(ix,iy) > 0.1) { | |
372 | x = fHist[ihist]->GetXaxis()->GetBinCenter(ix) | |
373 | + fHist[ihist]->GetXaxis()->GetBinWidth(ix); | |
374 | r1 = TMath::Max (r1,TMath::Sqrt((x-x0)*(x-x0)+(y-y0)*(y-y0))); | |
375 | } | |
376 | } | |
377 | } | |
378 | ihist = cath*2 + 1 ; | |
379 | for (Int_t iy=1; iy<=fHist[ihist]->GetNbinsY(); iy++) { | |
380 | y = fHist[ihist]->GetYaxis()->GetBinCenter(iy) | |
381 | + fHist[ihist]->GetYaxis()->GetBinWidth(iy); | |
382 | for (Int_t ix=1; ix<=fHist[ihist]->GetNbinsX(); ix++) { | |
383 | if (fHist[ihist]->GetCellContent(ix,iy) > 0.1) { | |
384 | x = fHist[ihist]->GetXaxis()->GetBinCenter(ix) | |
385 | + fHist[ihist]->GetXaxis()->GetBinWidth(ix); | |
386 | r2 = TMath::Max (r2,TMath::Sqrt((x-x0)*(x-x0)+(y-y0)*(y-y0))); | |
387 | } | |
388 | } | |
389 | } | |
390 | cout << r1 << " " << r2 << endl; | |
391 | } // if (fHist[cath*2+1]) | |
392 | if (r1 > r2) { | |
393 | //fHist[cath*2]->Draw("lego1"); | |
394 | fHist[cath*2]->Draw("lego1Fb"); | |
395 | //if (fHist[cath*2+1]) fHist[cath*2+1]->Draw("lego1SameAxisBb"); | |
396 | if (fHist[cath*2+1]) fHist[cath*2+1]->Draw("lego1SameAxisBbFb"); | |
397 | } else { | |
398 | //fHist[cath*2+1]->Draw("lego1"); | |
399 | fHist[cath*2+1]->Draw("lego1Fb"); | |
400 | //fHist[cath*2]->Draw("lego1SameAxisBb"); | |
401 | fHist[cath*2]->Draw("lego1SameAxisFbBb"); | |
402 | } | |
403 | c1->Update(); | |
404 | } // if (fDraw) | |
405 | } // for (Int_t cath = 0; | |
406 | ||
407 | // Draw generated hits | |
408 | Double_t xNDC[6]; | |
409 | hist = fHist[0] ? fHist[0] : fHist[2]; | |
410 | p2[2] = hist->GetMaximum(); | |
411 | view = 0; | |
412 | if (c1) view = c1->Pad()->GetView(); | |
413 | cout << " *** GEANT hits *** " << endl; | |
414 | fnMu = 0; | |
415 | Int_t ix, iy, iok; | |
416 | for (Int_t i=0; i<ntracks; i++) { | |
c1aed84f | 417 | treeH->GetEvent(i); |
418 | for (AliMUONHit* mHit=(AliMUONHit*)muon->FirstHit(-1); | |
0df3ca52 | 419 | mHit; |
c1aed84f | 420 | mHit=(AliMUONHit*)muon->NextHit()) { |
0df3ca52 | 421 | if (mHit->Chamber() != ch+1) continue; // chamber number |
422 | if (TMath::Abs(mHit->Z()-zpad0) > 1) continue; // different slat | |
423 | p2[0] = p1[0] = mHit->X(); // x-pos of hit | |
424 | p2[1] = p1[1] = mHit->Y(); // y-pos | |
425 | if (p1[0] < hist->GetXaxis()->GetXmin() || | |
426 | p1[0] > hist->GetXaxis()->GetXmax()) continue; | |
427 | if (p1[1] < hist->GetYaxis()->GetXmin() || | |
428 | p1[1] > hist->GetYaxis()->GetXmax()) continue; | |
429 | // Check if track comes thru pads with signal | |
430 | iok = 0; | |
431 | for (Int_t ihist=0; ihist<4; ihist++) { | |
432 | if (!fHist[ihist]) continue; | |
433 | ix = fHist[ihist]->GetXaxis()->FindBin(p1[0]); | |
434 | iy = fHist[ihist]->GetYaxis()->FindBin(p1[1]); | |
435 | if (fHist[ihist]->GetCellContent(ix,iy) > 0.5) {iok = 1; break;} | |
436 | } | |
437 | if (!iok) continue; | |
438 | gStyle->SetLineColor(1); | |
439 | if (TMath::Abs((Int_t)mHit->Particle()) == 13) { | |
440 | gStyle->SetLineColor(4); | |
441 | fnMu++; | |
442 | if (fnMu <= 2) { | |
443 | fxyMu[fnMu-1][0] = p1[0]; | |
444 | fxyMu[fnMu-1][1] = p1[1]; | |
445 | } | |
446 | } | |
447 | printf(" X=%10.4f, Y=%10.4f, Z=%10.4f\n",p1[0],p1[1],mHit->Z()); | |
448 | if (view) { | |
449 | view->WCtoNDC(p1, &xNDC[0]); | |
450 | view->WCtoNDC(p2, &xNDC[3]); | |
451 | for (Int_t ipad=1; ipad<3; ipad++) { | |
452 | c1->cd(ipad); | |
453 | //c1->DrawLine(xpad[0],xpad[1],xpad[3],xpad[4]); | |
454 | line[nLine] = new TLine(xNDC[0],xNDC[1],xNDC[3],xNDC[4]); | |
455 | line[nLine++]->Draw(); | |
456 | } | |
457 | } | |
458 | } // for (AliMUONHit* mHit= | |
459 | } // for (Int_t i=0; i<ntracks; | |
460 | ||
461 | // Draw reconstructed coordinates | |
c1aed84f | 462 | listMUONrawclust = muon->GetMUONData()->RawClusters(ch); |
463 | treeR->GetEvent(ch); | |
464 | //cout << listMUONrawclust << " " << listMUONrawclust ->GetEntries() << endl; | |
0df3ca52 | 465 | AliMUONRawCluster *mRaw; |
466 | gStyle->SetLineColor(3); | |
467 | cout << " *** Reconstructed hits *** " << endl; | |
c1aed84f | 468 | for (Int_t i=0; i<listMUONrawclust ->GetEntries(); i++) { |
469 | mRaw = (AliMUONRawCluster*)listMUONrawclust ->UncheckedAt(i); | |
ba12c242 | 470 | if (TMath::Abs(mRaw->GetZ(0)-zpad0) > 1) continue; // different slat |
471 | p2[0] = p1[0] = mRaw->GetX(0); // x-pos of hit | |
472 | p2[1] = p1[1] = mRaw->GetY(0); // y-pos | |
0df3ca52 | 473 | if (p1[0] < hist->GetXaxis()->GetXmin() || |
474 | p1[0] > hist->GetXaxis()->GetXmax()) continue; | |
475 | if (p1[1] < hist->GetYaxis()->GetXmin() || | |
476 | p1[1] > hist->GetYaxis()->GetXmax()) continue; | |
477 | /* | |
c1aed84f | 478 | treeD->GetEvent(cath); |
0df3ca52 | 479 | cout << mRaw->fMultiplicity[0] << mRaw->fMultiplicity[1] << endl; |
480 | for (Int_t j=0; j<mRaw->fMultiplicity[cath]; j++) { | |
481 | Int_t digit = mRaw->fIndexMap[j][cath]; | |
482 | cout << ((AliMUONDigit*)fMuonDigits->UncheckedAt(digit))->Signal() << endl; | |
483 | } | |
484 | */ | |
485 | // Check if track comes thru pads with signal | |
486 | iok = 0; | |
487 | for (Int_t ihist=0; ihist<4; ihist++) { | |
488 | if (!fHist[ihist]) continue; | |
489 | ix = fHist[ihist]->GetXaxis()->FindBin(p1[0]); | |
490 | iy = fHist[ihist]->GetYaxis()->FindBin(p1[1]); | |
491 | if (fHist[ihist]->GetCellContent(ix,iy) > 0.5) {iok = 1; break;} | |
492 | } | |
493 | if (!iok) continue; | |
ba12c242 | 494 | printf(" X=%10.4f, Y=%10.4f, Z=%10.4f\n",p1[0],p1[1],mRaw->GetZ(0)); |
0df3ca52 | 495 | if (view) { |
496 | view->WCtoNDC(p1, &xNDC[0]); | |
497 | view->WCtoNDC(p2, &xNDC[3]); | |
498 | for (Int_t ipad=1; ipad<3; ipad++) { | |
499 | c1->cd(ipad); | |
500 | line[nLine] = new TLine(xNDC[0],xNDC[1],xNDC[3],xNDC[4]); | |
501 | line[nLine++]->Draw(); | |
502 | } | |
503 | } | |
c1aed84f | 504 | } // for (Int_t i=0; i<listMUONrawclust ->GetEntries(); |
0df3ca52 | 505 | if (fDraw) c1->Update(); |
506 | ||
507 | skip: | |
508 | // Use MLEM for cluster finder | |
509 | fZpad = zpad0; | |
510 | Int_t nMax = 1, localMax[100], maxPos[100]; | |
511 | Double_t maxVal[100]; | |
512 | ||
513 | if (CheckPrecluster(nShown)) { | |
514 | BuildPixArray(); | |
515 | if (fnPads[0]+fnPads[1] > 50) nMax = FindLocalMaxima(localMax, maxVal); | |
516 | if (nMax > 1) TMath::Sort(nMax, maxVal, maxPos, kTRUE); // in decreasing order | |
517 | for (Int_t i=0; i<nMax; i++) { | |
518 | if (nMax > 1) FindCluster(localMax, maxPos[i]); | |
519 | if (!MainLoop()) cout << " MainLoop failed " << endl; | |
520 | if (i < nMax-1) { | |
521 | for (Int_t j=0; j<fnPads[0]+fnPads[1]; j++) { | |
522 | if (fPadIJ[1][j] == 0) continue; // pad charge was not modified | |
523 | fPadIJ[1][j] = 0; | |
524 | fXyq[2][j] = fXyq[5][j]; // use backup charge value | |
525 | } | |
526 | } | |
527 | } | |
528 | } | |
529 | if (fReco) goto next; | |
530 | ||
531 | for (Int_t i=0; i<fnMu; i++) { | |
532 | // Check again if muon come thru the used pads (due to extra splitting) | |
533 | for (Int_t j=0; j<fnPads[0]+fnPads[1]; j++) { | |
534 | if (TMath::Abs(fxyMu[i][0]-fXyq[0][j])<fXyq[3][j] && | |
535 | TMath::Abs(fxyMu[i][1]-fXyq[1][j])<fXyq[4][j]) { | |
536 | printf("%12.3e %12.3e %12.3e %12.3e\n",fxyMu[i][2],fxyMu[i][3],fxyMu[i][4],fxyMu[i][5]); | |
537 | if (lun) fprintf(lun,"%4d %2d %12.3e %12.3e %12.3e %12.3e\n",nev,ch,fxyMu[i][2],fxyMu[i][3],fxyMu[i][4],fxyMu[i][5]); | |
538 | break; | |
539 | } | |
540 | } | |
541 | } // for (Int_t i=0; i<fnMu; | |
542 | ||
543 | // What's next? | |
544 | char command[8]; | |
545 | cout << " What is next? " << endl; | |
546 | command[0] = ' '; | |
547 | if (fDraw) gets(command); | |
548 | if (command[0] == 'n' || command[0] == 'N') {nev++; goto newev;} // next event | |
549 | else if (command[0] == 'q' || command[0] == 'Q') {fclose(lun); return;} // exit display | |
550 | //else if (command[0] == 'r' || command[0] == 'R') goto redraw; // redraw points | |
551 | else if (command[0] == 'c' || command[0] == 'C') { | |
552 | // new chamber | |
553 | sscanf(command+1,"%d",&ch); | |
554 | goto newchamber; | |
555 | } | |
556 | else if (command[0] == 'e' || command[0] == 'E') { | |
557 | // new event | |
558 | sscanf(command+1,"%d",&nev); | |
559 | goto newev; | |
560 | } | |
561 | else goto next; // Next cluster | |
562 | } | |
563 | ||
564 | //_____________________________________________________________________________ | |
565 | void AliMUONClusterFinderAZ::ModifyHistos(void) | |
566 | { | |
567 | // Modify histograms to bring them to the same size | |
568 | Int_t nhist = 0; | |
569 | Float_t hlim[4][4], hbin[4][4]; // first index - xmin, xmax, ymin, ymax | |
570 | Float_t binMin[4] = {999,999,999,999}; | |
571 | ||
572 | for (Int_t i=0; i<4; i++) { | |
573 | if (!fHist[i]) continue; | |
574 | hlim[0][nhist] = fHist[i]->GetXaxis()->GetXmin(); // xmin | |
575 | hlim[1][nhist] = fHist[i]->GetXaxis()->GetXmax(); // xmax | |
576 | hlim[2][nhist] = fHist[i]->GetYaxis()->GetXmin(); // ymin | |
577 | hlim[3][nhist] = fHist[i]->GetYaxis()->GetXmax(); // ymax | |
578 | hbin[0][nhist] = hbin[1][nhist] = fHist[i]->GetXaxis()->GetBinWidth(1); | |
579 | hbin[2][nhist] = hbin[3][nhist] = fHist[i]->GetYaxis()->GetBinWidth(1); | |
580 | binMin[0] = TMath::Min(binMin[0],hbin[0][nhist]); | |
581 | binMin[2] = TMath::Min(binMin[2],hbin[2][nhist]); | |
582 | nhist++; | |
583 | } | |
584 | binMin[1] = binMin[0]; | |
585 | binMin[3] = binMin[2]; | |
586 | cout << " Nhist: " << nhist << endl; | |
587 | ||
588 | Int_t imin, imax; | |
589 | for (Int_t lim=0; lim<4; lim++) { | |
590 | while (1) { | |
591 | imin = TMath::LocMin(nhist,hlim[lim]); | |
592 | imax = TMath::LocMax(nhist,hlim[lim]); | |
593 | if (TMath::Abs(hlim[lim][imin]-hlim[lim][imax])<0.01*binMin[lim]) break; | |
594 | if (lim == 0 || lim == 2) { | |
595 | // find lower limit | |
596 | hlim[lim][imax] -= hbin[lim][imax]; | |
597 | } else { | |
598 | // find upper limit | |
599 | hlim[lim][imin] += hbin[lim][imin]; | |
600 | } | |
601 | } // while (1) | |
602 | } | |
603 | ||
604 | // Rebuild histograms | |
605 | nhist = 0; | |
606 | TH2F *hist = 0; | |
607 | Int_t nx, ny; | |
cd747ddb | 608 | Double_t x, y, cont, cmax=0; |
0df3ca52 | 609 | char hName[4]; |
610 | for (Int_t ihist=0; ihist<4; ihist++) { | |
611 | if (!fHist[ihist]) continue; | |
612 | nx = TMath::Nint((hlim[1][nhist]-hlim[0][nhist])/hbin[0][nhist]); | |
613 | ny = TMath::Nint((hlim[3][nhist]-hlim[2][nhist])/hbin[2][nhist]); | |
614 | //hist = new TH2F("h","hist",nx,hlim[0][nhist],hlim[1][nhist],ny,hlim[2][nhist],hlim[3][nhist]); | |
615 | sprintf(hName,"hh%d",ihist); | |
616 | hist = new TH2F(hName,"hist",nx,hlim[0][nhist],hlim[1][nhist],ny,hlim[2][nhist],hlim[3][nhist]); | |
617 | for (Int_t i=1; i<=fHist[ihist]->GetNbinsX(); i++) { | |
618 | x = fHist[ihist]->GetXaxis()->GetBinCenter(i); | |
619 | for (Int_t j=1; j<=fHist[ihist]->GetNbinsY(); j++) { | |
620 | y = fHist[ihist]->GetYaxis()->GetBinCenter(j); | |
621 | cont = fHist[ihist]->GetCellContent(i,j); | |
622 | hist->Fill(x,y,cont); | |
623 | } | |
624 | } | |
625 | cmax = TMath::Max (cmax,hist->GetMaximum()); | |
626 | fHist[ihist]->Delete(); | |
627 | fHist[ihist] = new TH2F(*hist); | |
628 | hist->Delete(); | |
629 | nhist++; | |
630 | } | |
631 | printf("%f \n",cmax); | |
632 | ||
633 | for (Int_t ihist=0; ihist<4; ihist++) { | |
634 | if (!fHist[ihist]) continue; | |
635 | fHist[ihist]->SetMaximum(cmax); | |
636 | } | |
637 | } | |
638 | ||
639 | //_____________________________________________________________________________ | |
640 | void AliMUONClusterFinderAZ::AddPad(Int_t cath, Int_t digit) | |
641 | { | |
642 | // Add pad to the cluster | |
643 | AliMUONDigit *mdig = (AliMUONDigit*)fMuonDigits->UncheckedAt(digit); | |
644 | ||
645 | Int_t charge = mdig->Signal(); | |
646 | // get the center of the pad | |
647 | Float_t xpad, ypad, zpad; | |
648 | fSegmentation[cath]->GetPadC(mdig->PadX(), mdig->PadY(), xpad, ypad, zpad); | |
649 | ||
650 | Int_t isec = fSegmentation[cath]->Sector(mdig->PadX(), mdig->PadY()); | |
651 | Int_t nPads = fnPads[0] + fnPads[1]; | |
652 | fXyq[0][nPads] = xpad; | |
653 | fXyq[1][nPads] = ypad; | |
654 | fXyq[2][nPads] = charge; | |
655 | fXyq[3][nPads] = fSegmentation[cath]->Dpx(isec)/2; | |
656 | fXyq[4][nPads] = fSegmentation[cath]->Dpy(isec)/2; | |
657 | fXyq[5][nPads] = digit; | |
658 | fPadIJ[0][nPads] = cath; | |
659 | fPadIJ[1][nPads] = 0; | |
660 | fUsed[cath][digit] = kTRUE; | |
661 | //cout << " bbb " << fXyq[cath][2][nPads] << " " << fXyq[cath][0][nPads] << " " << fXyq[cath][1][nPads] << " " << fXyq[cath][3][nPads] << " " << fXyq[cath][4][nPads] << " " << zpad << " " << nPads << endl; | |
662 | fnPads[cath]++; | |
663 | ||
664 | // Check neighbours | |
665 | Int_t nn, ix, iy, xList[10], yList[10]; | |
666 | AliMUONDigit *mdig1; | |
667 | ||
668 | Int_t ndigits = fMuonDigits->GetEntriesFast(); | |
669 | fSegmentation[cath]->Neighbours(mdig->PadX(),mdig->PadY(),&nn,xList,yList); | |
670 | for (Int_t in=0; in<nn; in++) { | |
671 | ix=xList[in]; | |
672 | iy=yList[in]; | |
673 | for (Int_t digit1 = 0; digit1 < ndigits; digit1++) { | |
674 | if (digit1 == digit) continue; | |
675 | mdig1 = (AliMUONDigit*)fMuonDigits->UncheckedAt(digit1); | |
676 | if (mdig1->Cathode() != cath) continue; | |
677 | if (!fUsed[cath][digit1] && mdig1->PadX() == ix && mdig1->PadY() == iy) { | |
678 | fUsed[cath][digit1] = kTRUE; | |
679 | // Add pad - recursive call | |
680 | AddPad(cath,digit1); | |
681 | } | |
682 | } //for (Int_t digit1 = 0; | |
683 | } // for (Int_t in=0; | |
684 | } | |
685 | ||
686 | //_____________________________________________________________________________ | |
687 | Bool_t AliMUONClusterFinderAZ::Overlap(Int_t cath, TObject *dig) | |
688 | { | |
689 | // Check if the pad from one cathode overlaps with a pad | |
690 | // in the precluster on the other cathode | |
691 | ||
692 | AliMUONDigit *mdig = (AliMUONDigit*) dig; | |
693 | ||
694 | Float_t xpad, ypad, zpad; | |
695 | fSegmentation[cath]->GetPadC(mdig->PadX(), mdig->PadY(), xpad, ypad, zpad); | |
696 | Int_t isec = fSegmentation[cath]->Sector(mdig->PadX(), mdig->PadY()); | |
697 | ||
698 | Float_t xy1[4], xy12[4]; | |
699 | xy1[0] = xpad - fSegmentation[cath]->Dpx(isec)/2; | |
700 | xy1[1] = xy1[0] + fSegmentation[cath]->Dpx(isec); | |
701 | xy1[2] = ypad - fSegmentation[cath]->Dpy(isec)/2; | |
702 | xy1[3] = xy1[2] + fSegmentation[cath]->Dpy(isec); | |
703 | //cout << " ok " << fnPads[0]+fnPads[1] << xy1[0] << xy1[1] << xy1[2] << xy1[3] << endl; | |
704 | ||
705 | Int_t cath1 = TMath::Even(cath); | |
706 | for (Int_t i=0; i<fnPads[0]+fnPads[1]; i++) { | |
707 | if (fPadIJ[0][i] != cath1) continue; | |
708 | if (Overlap(xy1, i, xy12, 0)) return kTRUE; | |
709 | } | |
710 | return kFALSE; | |
711 | } | |
712 | ||
713 | //_____________________________________________________________________________ | |
714 | Bool_t AliMUONClusterFinderAZ::Overlap(Float_t *xy1, Int_t iPad, Float_t *xy12, Int_t iSkip) | |
715 | { | |
716 | // Check if the pads xy1 and iPad overlap and return overlap area | |
717 | ||
718 | Float_t xy2[4]; | |
719 | xy2[0] = fXyq[0][iPad] - fXyq[3][iPad]; | |
720 | xy2[1] = fXyq[0][iPad] + fXyq[3][iPad]; | |
721 | if (xy1[0] > xy2[1]-1.e-4 || xy1[1] < xy2[0]+1.e-4) return kFALSE; | |
722 | xy2[2] = fXyq[1][iPad] - fXyq[4][iPad]; | |
723 | xy2[3] = fXyq[1][iPad] + fXyq[4][iPad]; | |
724 | if (xy1[2] > xy2[3]-1.e-4 || xy1[3] < xy2[2]+1.e-4) return kFALSE; | |
725 | if (!iSkip) return kTRUE; // just check overlap (w/out computing the area) | |
726 | xy12[0] = TMath::Max (xy1[0],xy2[0]); | |
727 | xy12[1] = TMath::Min (xy1[1],xy2[1]); | |
728 | xy12[2] = TMath::Max (xy1[2],xy2[2]); | |
729 | xy12[3] = TMath::Min (xy1[3],xy2[3]); | |
730 | return kTRUE; | |
731 | } | |
732 | ||
733 | //_____________________________________________________________________________ | |
734 | /* | |
735 | Bool_t AliMUONClusterFinderAZ::Overlap(Int_t i, Int_t j, Float_t *xy12, Int_t iSkip) | |
736 | { | |
737 | // Check if the pads i and j overlap and return overlap area | |
738 | ||
739 | Float_t xy1[4], xy2[4]; | |
740 | return Overlap(xy1, xy2, xy12, iSkip); | |
741 | } | |
742 | */ | |
743 | //_____________________________________________________________________________ | |
744 | Bool_t AliMUONClusterFinderAZ::CheckPrecluster(Int_t *nShown) | |
745 | { | |
746 | // Check precluster in order to attempt to simplify it (mostly for | |
747 | // two-cathode preclusters) | |
748 | ||
749 | Int_t i1, i2; | |
750 | Float_t xy1[4], xy12[4]; | |
751 | ||
752 | Int_t npad = fnPads[0] + fnPads[1]; | |
753 | ||
754 | // If pads have the same size take average of pads on both cathodes | |
755 | Int_t sameSize = (fnPads[0] && fnPads[1]) ? 1 : 0; | |
756 | if (sameSize) { | |
757 | Double_t xSize = -1, ySize = 0; | |
758 | for (Int_t i=0; i<npad; i++) { | |
759 | if (fXyq[2][i] < 0) continue; | |
760 | if (xSize < 0) { xSize = fXyq[3][i]; ySize = fXyq[4][i]; } | |
761 | if (TMath::Abs(xSize-fXyq[3][i]) > 1.e-4 || TMath::Abs(ySize-fXyq[4][i]) > 1.e-4) { sameSize = 0; break; } | |
762 | } | |
763 | } // if (sameSize) | |
764 | if (sameSize && (fnPads[0] > 2 || fnPads[1] > 2)) { | |
765 | nShown[0] += fnPads[0]; | |
766 | nShown[1] += fnPads[1]; | |
767 | fnPads[0] = fnPads[1] = 0; | |
768 | Int_t div; | |
769 | for (Int_t i=0; i<npad; i++) { | |
770 | if (fXyq[2][i] < 0) continue; // used pad | |
771 | fXyq[2][fnPads[0]] = fXyq[2][i]; | |
772 | div = 1; | |
773 | for (Int_t j=i+1; j<npad; j++) { | |
774 | if (fPadIJ[0][j] == fPadIJ[0][i]) continue; // same cathode | |
775 | if (TMath::Abs(fXyq[0][j]-fXyq[0][i]) > 1.e-4) continue; | |
776 | if (TMath::Abs(fXyq[1][j]-fXyq[1][i]) > 1.e-4) continue; | |
777 | fXyq[2][fnPads[0]] += fXyq[2][j]; | |
778 | div = 2; | |
779 | fXyq[2][j] = -2; | |
780 | break; | |
781 | } | |
782 | fXyq[2][fnPads[0]] /= div; | |
783 | fXyq[0][fnPads[0]] = fXyq[0][i]; | |
784 | fXyq[1][fnPads[0]] = fXyq[1][i]; | |
785 | fPadIJ[0][fnPads[0]++] = 0; | |
786 | } | |
787 | } // if (sameSize) | |
788 | ||
789 | // Check if one-cathode precluster | |
790 | i1 = fnPads[0]!=0 ? 0 : 1; | |
791 | i2 = fnPads[1]!=0 ? 1 : 0; | |
792 | ||
793 | if (i1 != i2) { // two-cathode | |
794 | ||
795 | Int_t *flags = new Int_t[npad]; | |
796 | for (Int_t i=0; i<npad; i++) { flags[i] = 0; } | |
797 | ||
798 | // Check pad overlaps | |
799 | for (Int_t i=0; i<npad; i++) { | |
800 | if (fPadIJ[0][i] != i1) continue; | |
801 | xy1[0] = fXyq[0][i] - fXyq[3][i]; | |
802 | xy1[1] = fXyq[0][i] + fXyq[3][i]; | |
803 | xy1[2] = fXyq[1][i] - fXyq[4][i]; | |
804 | xy1[3] = fXyq[1][i] + fXyq[4][i]; | |
805 | for (Int_t j=0; j<npad; j++) { | |
806 | if (fPadIJ[0][j] != i2) continue; | |
807 | if (!Overlap(xy1, j, xy12, 0)) continue; | |
808 | flags[i] = flags[j] = 1; // mark overlapped pads | |
809 | } // for (Int_t j=0; | |
810 | } // for (Int_t i=0; | |
811 | ||
812 | // Check if all pads overlap | |
813 | Int_t digit=0, cath, nFlags=0; | |
814 | for (Int_t i=0; i<npad; i++) {nFlags += !flags[i];} | |
815 | if (nFlags) cout << " nFlags = " << nFlags << endl; | |
816 | //if (nFlags > 2 || (Float_t)nFlags / npad > 0.2) { // why 2 ??? - empirical choice | |
817 | if (nFlags > 0) { | |
818 | for (Int_t i=0; i<npad; i++) { | |
819 | if (flags[i]) continue; | |
820 | digit = TMath::Nint (fXyq[5][i]); | |
821 | cath = fPadIJ[0][i]; | |
822 | fUsed[cath][digit] = kFALSE; // release pad | |
823 | fXyq[2][i] = -2; | |
824 | fnPads[cath]--; | |
825 | } | |
826 | } // if (nFlags > 2) | |
827 | ||
828 | // Check correlations of cathode charges | |
829 | if (fnPads[0] && fnPads[1]) { // two-cathode | |
830 | Double_t sum[2]={0}; | |
831 | Int_t over[2] = {1, 1}; | |
832 | for (Int_t i=0; i<npad; i++) { | |
833 | cath = fPadIJ[0][i]; | |
834 | if (fXyq[2][i] > 0) sum[cath] += fXyq[2][i]; | |
835 | if (fXyq[2][i] > fResponse->MaxAdc()-1) over[cath] = 0; | |
836 | } | |
837 | cout << " Total charge: " << sum[0] << " " << sum[1] << endl; | |
838 | if ((over[0] || over[1]) && TMath::Abs(sum[0]-sum[1])/(sum[0]+sum[1])*2 > 1) { // 3 times difference | |
839 | cout << " Release " << endl; | |
840 | // Big difference | |
841 | cath = sum[0]>sum[1] ? 0 : 1; | |
842 | Int_t imax = 0; | |
843 | Double_t cmax=-1; | |
844 | Double_t *dist = new Double_t[npad]; | |
845 | for (Int_t i=0; i<npad; i++) { | |
846 | if (fPadIJ[0][i] != cath) continue; | |
847 | if (fXyq[2][i] < cmax) continue; | |
848 | cmax = fXyq[2][i]; | |
849 | imax = i; | |
850 | } | |
851 | // Arrange pads according to their distance to the max, | |
852 | // normalized to the pad size | |
853 | for (Int_t i=0; i<npad; i++) { | |
854 | dist[i] = 0; | |
855 | if (fPadIJ[0][i] != cath) continue; | |
856 | if (i == imax) continue; | |
857 | if (fXyq[2][i] < 0) continue; | |
858 | dist[i] = (fXyq[0][i]-fXyq[0][imax])*(fXyq[0][i]-fXyq[0][imax])/ | |
859 | fXyq[3][imax]/fXyq[3][imax]/4; | |
860 | dist[i] += (fXyq[1][i]-fXyq[1][imax])*(fXyq[1][i]-fXyq[1][imax])/ | |
861 | fXyq[4][imax]/fXyq[4][imax]/4; | |
862 | dist[i] = TMath::Sqrt (dist[i]); | |
863 | } | |
864 | TMath::Sort(npad, dist, flags, kFALSE); // in increasing order | |
865 | Int_t indx; | |
866 | Double_t xmax = -1; | |
867 | for (Int_t i=0; i<npad; i++) { | |
868 | indx = flags[i]; | |
869 | if (fPadIJ[0][indx] != cath) continue; | |
870 | if (fXyq[2][indx] < 0) continue; | |
871 | if (fXyq[2][indx] <= cmax || TMath::Abs(dist[indx]-xmax)<1.e-3) { | |
872 | // Release pads | |
873 | if (TMath::Abs(dist[indx]-xmax)<1.e-3) | |
cd747ddb | 874 | cmax = TMath::Max((Double_t)(fXyq[2][indx]),cmax); |
0df3ca52 | 875 | else cmax = fXyq[2][indx]; |
876 | xmax = dist[indx]; | |
877 | digit = TMath::Nint (fXyq[5][indx]); | |
878 | fUsed[cath][digit] = kFALSE; | |
879 | fXyq[2][indx] = -2; | |
880 | fnPads[cath]--; | |
881 | // xmax = dist[i]; // Bug? | |
882 | } | |
883 | else break; | |
884 | } | |
885 | delete [] dist; dist = 0; | |
886 | } // TMath::Abs(sum[0]-sum[1])... | |
887 | } // if (fnPads[0] && fnPads[1]) | |
888 | delete [] flags; flags = 0; | |
889 | } // if (i1 != i2) | |
890 | ||
891 | if (!sameSize) { nShown[0] += fnPads[0]; nShown[1] += fnPads[1]; } | |
892 | ||
893 | // Move released pads to the right | |
894 | Int_t beg = 0, end = npad-1, padij; | |
895 | Double_t xyq; | |
896 | while (beg < end) { | |
897 | if (fXyq[2][beg] > 0) { beg++; continue; } | |
898 | for (Int_t j=end; j>beg; j--) { | |
899 | if (fXyq[2][j] < 0) continue; | |
900 | end = j - 1; | |
901 | for (Int_t j1=0; j1<2; j1++) { | |
902 | padij = fPadIJ[j1][beg]; | |
903 | fPadIJ[j1][beg] = fPadIJ[j1][j]; | |
904 | fPadIJ[j1][j] = padij; | |
905 | } | |
906 | for (Int_t j1=0; j1<6; j1++) { | |
907 | xyq = fXyq[j1][beg]; | |
908 | fXyq[j1][beg] = fXyq[j1][j]; | |
909 | fXyq[j1][j] = xyq; | |
910 | } | |
911 | break; | |
912 | } // for (Int_t j=end; | |
913 | beg++; | |
914 | } // while | |
915 | npad = fnPads[0] + fnPads[1]; | |
916 | if (npad > 500) { cout << " ***** Too large cluster. Give up. " << npad << endl; return kFALSE; } | |
917 | // Back up charge value | |
918 | for (Int_t j=0; j<npad; j++) fXyq[5][j] = fXyq[2][j]; | |
919 | ||
920 | return kTRUE; | |
921 | } | |
922 | ||
923 | //_____________________________________________________________________________ | |
924 | void AliMUONClusterFinderAZ::BuildPixArray() | |
925 | { | |
926 | // Build pixel array for MLEM method | |
927 | ||
928 | Int_t nPix=0, i1, i2; | |
929 | Float_t xy1[4], xy12[4]; | |
930 | AliMUONPixel *pixPtr=0; | |
931 | ||
932 | Int_t npad = fnPads[0] + fnPads[1]; | |
933 | ||
934 | // One cathode is empty | |
935 | i1 = fnPads[0]!=0 ? 0 : 1; | |
936 | i2 = fnPads[1]!=0 ? 1 : 0; | |
937 | ||
938 | // Build array of pixels on anode plane | |
939 | if (i1 == i2) { // one-cathode precluster | |
940 | for (Int_t j=0; j<npad; j++) { | |
941 | pixPtr = new AliMUONPixel(); | |
942 | for (Int_t i=0; i<2; i++) { | |
943 | pixPtr->SetCoord(i, fXyq[i][j]); // pixel coordinates | |
944 | pixPtr->SetSize(i, fXyq[i+3][j]); // pixel size | |
945 | } | |
946 | pixPtr->SetCharge(fXyq[2][j]); // charge | |
947 | fPixArray->Add((TObject*)pixPtr); | |
948 | nPix++; | |
949 | } | |
950 | } else { // two-cathode precluster | |
951 | for (Int_t i=0; i<npad; i++) { | |
952 | if (fPadIJ[0][i] != i1) continue; | |
953 | xy1[0] = fXyq[0][i] - fXyq[3][i]; | |
954 | xy1[1] = fXyq[0][i] + fXyq[3][i]; | |
955 | xy1[2] = fXyq[1][i] - fXyq[4][i]; | |
956 | xy1[3] = fXyq[1][i] + fXyq[4][i]; | |
957 | for (Int_t j=0; j<npad; j++) { | |
958 | if (fPadIJ[0][j] != i2) continue; | |
959 | if (!Overlap(xy1, j, xy12, 1)) continue; | |
960 | pixPtr = new AliMUONPixel(); | |
961 | for (Int_t k=0; k<2; k++) { | |
962 | pixPtr->SetCoord(k, (xy12[2*k]+xy12[2*k+1])/2); // pixel coordinates | |
963 | pixPtr->SetSize(k, xy12[2*k+1]-pixPtr->Coord(k)); // size | |
964 | } | |
965 | pixPtr->SetCharge(TMath::Min (fXyq[2][i],fXyq[2][j])); //charge | |
966 | fPixArray->Add((TObject*)pixPtr); | |
967 | nPix++; | |
968 | } // for (Int_t j=0; | |
969 | } // for (Int_t i=0; | |
970 | } // else | |
971 | ||
972 | Float_t wxmin=999, wymin=999; | |
973 | for (Int_t i=0; i<npad; i++) { | |
974 | if (fPadIJ[0][i] == i1) wymin = TMath::Min (wymin,fXyq[4][i]); | |
975 | if (fPadIJ[0][i] == i2) wxmin = TMath::Min (wxmin,fXyq[3][i]); | |
976 | } | |
977 | cout << wxmin << " " << wymin << endl; | |
978 | ||
979 | // Check if small pixel X-size | |
980 | AjustPixel(wxmin, 0); | |
981 | // Check if small pixel Y-size | |
982 | AjustPixel(wymin, 1); | |
983 | // Check if large pixel size | |
984 | AjustPixel(wxmin, wymin); | |
985 | ||
986 | // Remove discarded pixels | |
987 | for (Int_t i=0; i<nPix; i++) { | |
988 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i); | |
989 | //pixPtr->Print(); | |
990 | if (pixPtr->Charge() < 1) { fPixArray->RemoveAt(i); delete pixPtr; }// discarded pixel | |
991 | } | |
992 | fPixArray->Compress(); | |
993 | nPix = fPixArray->GetEntriesFast(); | |
994 | ||
995 | if (nPix > npad) { | |
996 | cout << nPix << endl; | |
997 | // Too many pixels - sort and remove pixels with the lowest signal | |
998 | fPixArray->Sort(); | |
999 | for (Int_t i=npad; i<nPix; i++) { | |
1000 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i); | |
1001 | //pixPtr->Print(); | |
1002 | fPixArray->RemoveAt(i); | |
1003 | delete pixPtr; | |
1004 | } | |
1005 | nPix = npad; | |
1006 | } // if (nPix > npad) | |
1007 | ||
1008 | // Set pixel charges to the same value (for MLEM) | |
1009 | for (Int_t i=0; i<nPix; i++) { | |
1010 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i); | |
1011 | //pixPtr->SetCharge(10); | |
1012 | cout << i+1 << " " << pixPtr->Coord(0) << " " << pixPtr->Coord(1) << " " << pixPtr->Size(0) << " " << pixPtr->Size(1) << endl; | |
1013 | } | |
1014 | } | |
1015 | ||
1016 | //_____________________________________________________________________________ | |
1017 | void AliMUONClusterFinderAZ::AjustPixel(Float_t width, Int_t ixy) | |
1018 | { | |
1019 | // Check if some pixels have small size (ajust if necessary) | |
1020 | ||
1021 | AliMUONPixel *pixPtr, *pixPtr1 = 0; | |
1022 | Int_t ixy1 = TMath::Even(ixy); | |
1023 | Int_t nPix = fPixArray->GetEntriesFast(); | |
1024 | ||
1025 | for (Int_t i=0; i<nPix; i++) { | |
1026 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i); | |
1027 | if (pixPtr->Charge() < 1) continue; // discarded pixel | |
1028 | if (pixPtr->Size(ixy)-width < -1.e-4) { | |
1029 | // try to merge | |
1030 | cout << " Small X or Y: " << ixy << " " << pixPtr->Size(ixy) << " " << width << " " << pixPtr->Coord(0) << " " << pixPtr->Coord(1) << endl; | |
1031 | for (Int_t j=i+1; j<nPix; j++) { | |
1032 | pixPtr1 = (AliMUONPixel*) fPixArray->UncheckedAt(j); | |
1033 | if (pixPtr1->Charge() < 1) continue; // discarded pixel | |
1034 | if (TMath::Abs(pixPtr1->Size(ixy)-width) < 1.e-4) continue; // right size | |
1035 | if (TMath::Abs(pixPtr1->Coord(ixy1)-pixPtr->Coord(ixy1)) > 1.e-4) continue; // different rows/columns | |
1036 | if (TMath::Abs(pixPtr1->Coord(ixy)-pixPtr->Coord(ixy)) < 2*width) { | |
1037 | // merge | |
1038 | pixPtr->SetSize(ixy, width); | |
1039 | pixPtr->SetCoord(ixy, (pixPtr->Coord(ixy)+pixPtr1->Coord(ixy))/2); | |
1040 | pixPtr->SetCharge(TMath::Min (pixPtr->Charge(),pixPtr1->Charge())); | |
1041 | pixPtr1->SetCharge(0); | |
1042 | pixPtr1 = 0; | |
1043 | break; | |
1044 | } | |
1045 | } // for (Int_t j=i+1; | |
1046 | //if (!pixPtr1) { cout << " I am here!" << endl; pixPtr->SetSize(ixy, width); } // ??? | |
1047 | //else if (pixPtr1->Charge() > 0.5 || i == nPix-1) { | |
1048 | if (pixPtr1 || i == nPix-1) { | |
1049 | // edge pixel - just increase its size | |
1050 | cout << " Edge ..." << endl; | |
1051 | for (Int_t j=0; j<fnPads[0]+fnPads[1]; j++) { | |
1052 | // ???if (fPadIJ[0][j] != i1) continue; | |
1053 | if (TMath::Abs(pixPtr->Coord(ixy1)-fXyq[ixy1][j]) > 1.e-4) continue; | |
1054 | if (pixPtr->Coord(ixy) < fXyq[ixy][j]) | |
1055 | pixPtr->Shift(ixy, -pixPtr->Size(ixy)); | |
1056 | else pixPtr->Shift(ixy, pixPtr->Size(ixy)); | |
1057 | pixPtr->SetSize(ixy, width); | |
1058 | break; | |
1059 | } | |
1060 | } | |
1061 | } // if (pixPtr->Size(ixy)-width < -1.e-4) | |
1062 | } // for (Int_t i=0; i<nPix; | |
1063 | return; | |
1064 | } | |
1065 | ||
1066 | //_____________________________________________________________________________ | |
1067 | void AliMUONClusterFinderAZ::AjustPixel(Float_t wxmin, Float_t wymin) | |
1068 | { | |
1069 | // Check if some pixels have large size (ajust if necessary) | |
1070 | ||
1071 | Int_t nx, ny; | |
1072 | Int_t nPix = fPixArray->GetEntriesFast(); | |
1073 | AliMUONPixel *pixPtr, *pixPtr1, pix; | |
1074 | ||
1075 | // Check if large pixel size | |
1076 | for (Int_t i=0; i<nPix; i++) { | |
1077 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i); | |
1078 | if (pixPtr->Charge() < 1) continue; // discarded pixel | |
1079 | if (pixPtr->Size(0)-wxmin > 1.e-4 || pixPtr->Size(1)-wymin > 1.e-4) { | |
1080 | cout << " Different " << pixPtr->Size(0) << " " << wxmin << " " << pixPtr->Size(1) << " " << wymin << endl; | |
1081 | pix = *pixPtr; | |
1082 | nx = TMath::Nint (pix.Size(0)/wxmin); | |
1083 | ny = TMath::Nint (pix.Size(1)/wymin); | |
1084 | pix.Shift(0, -pix.Size(0)-wxmin); | |
1085 | pix.Shift(1, -pix.Size(1)-wymin); | |
1086 | pix.SetSize(0, wxmin); | |
1087 | pix.SetSize(1, wymin); | |
1088 | for (Int_t ii=0; ii<nx; ii++) { | |
1089 | pix.Shift(0, wxmin*2); | |
1090 | for (Int_t jj=0; jj<ny; jj++) { | |
1091 | pix.Shift(1, wymin*2); | |
1092 | pixPtr1 = new AliMUONPixel(pix); | |
1093 | fPixArray->Add((TObject*)pixPtr1); | |
1094 | } | |
1095 | } | |
1096 | pixPtr->SetCharge(0); | |
1097 | } | |
1098 | } // for (Int_t i=0; i<nPix; | |
1099 | return; | |
1100 | } | |
1101 | ||
1102 | //_____________________________________________________________________________ | |
1103 | Bool_t AliMUONClusterFinderAZ::MainLoop() | |
1104 | { | |
1105 | // Repeat MLEM algorithm until pixel size becomes sufficiently small | |
1106 | ||
1107 | TH2D *mlem; | |
1108 | ||
1109 | Int_t ix, iy; | |
1110 | //Int_t nn, xList[10], yList[10]; | |
1111 | Int_t nPix = fPixArray->GetEntriesFast(); | |
1112 | Int_t npadTot = fnPads[0] + fnPads[1], npadOK = 0; | |
1113 | AliMUONPixel *pixPtr = 0; | |
1114 | Double_t *coef = 0, *probi = 0; | |
1115 | for (Int_t i=0; i<npadTot; i++) if (fPadIJ[1][i] == 0) npadOK++; | |
1116 | ||
1117 | while (1) { | |
1118 | ||
1119 | mlem = (TH2D*) gROOT->FindObject("mlem"); | |
1120 | if (mlem) mlem->Delete(); | |
1121 | // Calculate coefficients | |
1122 | cout << " nPix, npadTot, npadOK " << nPix << " " << npadTot << " " << npadOK << endl; | |
1123 | ||
1124 | // Calculate coefficients and pixel visibilities | |
1125 | coef = new Double_t [npadTot*nPix]; | |
1126 | probi = new Double_t [nPix]; | |
1127 | Int_t indx = 0, cath; | |
1128 | for (Int_t ipix=0; ipix<nPix; ipix++) { | |
1129 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(ipix); | |
1130 | probi[ipix] = 0; | |
1131 | for (Int_t j=0; j<npadTot; j++) { | |
1132 | if (fPadIJ[1][j] < 0) { coef[j*nPix+ipix] = 0; continue; } | |
1133 | cath = fPadIJ[0][j]; | |
1134 | fSegmentation[cath]->GetPadI(fXyq[0][j],fXyq[1][j],fZpad,ix,iy); | |
1135 | fSegmentation[cath]->SetPad(ix,iy); | |
1136 | /* | |
1137 | fSegmentation[cath]->Neighbours(ix,iy,&nn,xList,yList); | |
1138 | if (nn != 4) { | |
1139 | cout << nn << ": "; | |
1140 | for (Int_t i=0; i<nn; i++) {cout << xList[i] << " " << yList[i] << ", ";} | |
1141 | cout << endl; | |
1142 | } | |
1143 | */ | |
1144 | Double_t sum = 0; | |
1145 | fSegmentation[cath]->SetHit(pixPtr->Coord(0),pixPtr->Coord(1),fZpad); | |
1146 | sum += fResponse->IntXY(fSegmentation[cath]); | |
1147 | indx = j*nPix + ipix; | |
1148 | coef[indx] = sum; | |
1149 | probi[ipix] += coef[indx]; | |
1150 | //cout << j << " " << ipix << " " << coef[indx] << endl; | |
1151 | } // for (Int_t j=0; | |
1152 | //cout << " prob: " << probi[ipix] << endl; | |
1153 | if (probi[ipix] < 0.01) pixPtr->SetCharge(0); // "invisible" pixel | |
1154 | } // for (Int_t ipix=0; | |
1155 | ||
1156 | // MLEM algorithm | |
1157 | Mlem(coef, probi); | |
1158 | ||
cd747ddb | 1159 | Double_t xylim[4] = {999, 999, 999, 999}; |
0df3ca52 | 1160 | for (Int_t ipix=0; ipix<nPix; ipix++) { |
1161 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(ipix); | |
1162 | for (Int_t i=0; i<4; i++) | |
1163 | xylim[i] = TMath::Min (xylim[i], (i%2 ? -1 : 1)*pixPtr->Coord(i/2)); | |
1164 | //cout << ipix+1; pixPtr->Print(); | |
1165 | } | |
1166 | for (Int_t i=0; i<4; i++) { | |
1167 | xylim[i] -= pixPtr->Size(i/2); cout << (i%2 ? -1 : 1)*xylim[i] << " "; } | |
1168 | cout << endl; | |
1169 | ||
1170 | // Ajust histogram to approximately the same limits as for the pads | |
1171 | // (for good presentation) | |
1172 | //* | |
1173 | Float_t xypads[4]; | |
1174 | if (fHist[0]) { | |
1175 | xypads[0] = fHist[0]->GetXaxis()->GetXmin(); | |
1176 | xypads[1] = -fHist[0]->GetXaxis()->GetXmax(); | |
1177 | xypads[2] = fHist[0]->GetYaxis()->GetXmin(); | |
1178 | xypads[3] = -fHist[0]->GetYaxis()->GetXmax(); | |
1179 | for (Int_t i=0; i<4; i++) { | |
1180 | while(1) { | |
1181 | if (xylim[i] < xypads[i]) break; | |
1182 | xylim[i] -= 2*pixPtr->Size(i/2); | |
1183 | } | |
1184 | } | |
1185 | } // if (fHist[0]) | |
1186 | //*/ | |
1187 | ||
1188 | Int_t nx = TMath::Nint ((-xylim[1]-xylim[0])/pixPtr->Size(0)/2); | |
1189 | Int_t ny = TMath::Nint ((-xylim[3]-xylim[2])/pixPtr->Size(1)/2); | |
1190 | mlem = new TH2D("mlem","mlem",nx,xylim[0],-xylim[1],ny,xylim[2],-xylim[3]); | |
1191 | for (Int_t ipix=0; ipix<nPix; ipix++) { | |
1192 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(ipix); | |
1193 | mlem->Fill(pixPtr->Coord(0),pixPtr->Coord(1),pixPtr->Charge()); | |
1194 | } | |
1195 | //gPad->GetCanvas()->cd(3); | |
1196 | if (fDraw) { | |
1197 | ((TCanvas*)gROOT->FindObject("c2"))->cd(); | |
1198 | gPad->SetTheta(55); | |
1199 | gPad->SetPhi(30); | |
1200 | mlem->Draw("lego1Fb"); | |
1201 | gPad->Update(); | |
1202 | gets((char*)&ix); | |
1203 | } | |
1204 | ||
1205 | // Check if the total charge of pixels is too low | |
1206 | Double_t qTot = 0; | |
1207 | for (Int_t i=0; i<nPix; i++) { | |
1208 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i); | |
1209 | qTot += pixPtr->Charge(); | |
1210 | } | |
1211 | if (qTot < 1.e-4 || npadOK < 3 && qTot < 50) { | |
1212 | delete [] coef; delete [] probi; coef = 0; probi = 0; | |
1213 | fPixArray->Delete(); | |
1214 | return kFALSE; | |
1215 | } | |
1216 | ||
1217 | // Plot data - expectation | |
1218 | /* | |
1219 | Double_t x, y, cont; | |
1220 | for (Int_t j=0; j<npadTot; j++) { | |
1221 | Double_t sum1 = 0; | |
1222 | for (Int_t i=0; i<nPix; i++) { | |
1223 | // Caculate expectation | |
1224 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i); | |
1225 | sum1 += pixPtr->Charge()*coef[j*nPix+i]; | |
1226 | } | |
1227 | sum1 = TMath::Min (sum1,(Double_t)fResponse->MaxAdc()); | |
1228 | x = fXyq[0][j]; | |
1229 | y = fXyq[1][j]; | |
1230 | cath = fPadIJ[0][j]; | |
1231 | Int_t ihist = cath*2; | |
1232 | ix = fHist[ihist]->GetXaxis()->FindBin(x); | |
1233 | iy = fHist[ihist]->GetYaxis()->FindBin(y); | |
1234 | cont = fHist[ihist]->GetCellContent(ix,iy); | |
1235 | if (cont == 0 && fHist[ihist+1]) { | |
1236 | ihist += 1; | |
1237 | ix = fHist[ihist]->GetXaxis()->FindBin(x); | |
1238 | iy = fHist[ihist]->GetYaxis()->FindBin(y); | |
1239 | } | |
1240 | fHist[ihist]->SetBinContent(ix,iy,fXyq[2][j]-sum1); | |
1241 | } | |
1242 | ((TCanvas*)gROOT->FindObject("c1"))->cd(1); | |
1243 | //gPad->SetTheta(55); | |
1244 | //gPad->SetPhi(30); | |
1245 | //mlem->Draw("lego1"); | |
1246 | gPad->Modified(); | |
1247 | ((TCanvas*)gROOT->FindObject("c1"))->cd(2); | |
1248 | gPad->Modified(); | |
1249 | */ | |
1250 | ||
1251 | // Calculate position of the center-of-gravity around the maximum pixel | |
1252 | Double_t xyCOG[2]; | |
1253 | FindCOG(mlem, xyCOG); | |
1254 | ||
1255 | if (TMath::Min(pixPtr->Size(0),pixPtr->Size(1)) < 0.07 && pixPtr->Size(0) > pixPtr->Size(1)) break; | |
1256 | //if (TMath::Min(pixPtr->Size(0),pixPtr->Size(1)) >= 0.07 || pixPtr->Size(0) < pixPtr->Size(1)) { | |
1257 | // Sort pixels according to the charge | |
1258 | fPixArray->Sort(); | |
1259 | /* | |
1260 | for (Int_t i=0; i<nPix; i++) { | |
1261 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i); | |
1262 | cout << i+1; pixPtr->Print(); | |
1263 | } | |
1264 | */ | |
1265 | Double_t pixMin = 0.01*((AliMUONPixel*)fPixArray->UncheckedAt(0))->Charge(); | |
1266 | pixMin = TMath::Min (pixMin,50.); | |
1267 | ||
1268 | // Decrease pixel size and shift pixels to make them centered at | |
1269 | // the maximum one | |
1270 | indx = (pixPtr->Size(0)>pixPtr->Size(1)) ? 0 : 1; | |
1271 | Double_t width = 0, shift[2]={0}; | |
1272 | ix = 1; | |
1273 | for (Int_t i=0; i<4; i++) xylim[i] = 999; | |
1274 | Int_t nPix1 = nPix; nPix = 0; | |
1275 | for (Int_t ipix=0; ipix<nPix1; ipix++) { | |
1276 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(ipix); | |
1277 | if (nPix >= npadOK) { // too many pixels already | |
1278 | fPixArray->RemoveAt(ipix); | |
1279 | delete pixPtr; | |
1280 | continue; | |
1281 | } | |
1282 | if (pixPtr->Charge() < pixMin) { // low charge | |
1283 | fPixArray->RemoveAt(ipix); | |
1284 | delete pixPtr; | |
1285 | continue; | |
1286 | } | |
1287 | for (Int_t i=0; i<2; i++) { | |
1288 | if (!i) { | |
1289 | pixPtr->SetCharge(10); | |
1290 | pixPtr->SetSize(indx, pixPtr->Size(indx)/2); | |
1291 | width = -pixPtr->Size(indx); | |
1292 | pixPtr->Shift(indx, width); | |
1293 | // Shift pixel position | |
1294 | if (ix) { | |
1295 | ix = 0; | |
1296 | for (Int_t j=0; j<2; j++) { | |
1297 | shift[j] = pixPtr->Coord(j) - xyCOG[j]; | |
1298 | shift[j] -= ((Int_t)(shift[j]/pixPtr->Size(j)/2))*pixPtr->Size(j)*2; | |
1299 | } | |
1300 | //cout << ipix << " " << i << " " << shift[0] << " " << shift[1] << endl; | |
1301 | } // if (ix) | |
1302 | pixPtr->Shift(0, -shift[0]); | |
1303 | pixPtr->Shift(1, -shift[1]); | |
1304 | } else { | |
1305 | pixPtr = new AliMUONPixel(*pixPtr); | |
1306 | pixPtr->Shift(indx, -2*width); | |
1307 | fPixArray->Add((TObject*)pixPtr); | |
1308 | } // else | |
1309 | //pixPtr->Print(); | |
1310 | for (Int_t i=0; i<4; i++) | |
1311 | xylim[i] = TMath::Min (xylim[i], (i%2 ? -1 : 1)*pixPtr->Coord(i/2)); | |
1312 | } // for (Int_t i=0; i<2; | |
1313 | nPix += 2; | |
1314 | } // for (Int_t ipix=0; | |
1315 | ||
1316 | fPixArray->Compress(); | |
1317 | nPix = fPixArray->GetEntriesFast(); | |
1318 | ||
1319 | // Remove excessive pixels | |
1320 | if (nPix > npadOK) { | |
1321 | for (Int_t ipix=npadOK; ipix<nPix; ipix++) { | |
1322 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(ipix); | |
1323 | fPixArray->RemoveAt(ipix); | |
1324 | delete pixPtr; | |
1325 | } | |
1326 | } else { | |
1327 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(0); | |
1328 | // add pixels if the maximum is at the limit of pixel area | |
1329 | // start from Y-direction | |
1330 | Int_t j = 0; | |
1331 | for (Int_t i=3; i>-1; i--) { | |
1332 | if (nPix < npadOK && | |
1333 | TMath::Abs((i%2 ? -1 : 1)*xylim[i]-xyCOG[i/2]) < pixPtr->Size(i/2)) { | |
1334 | pixPtr = new AliMUONPixel(*pixPtr); | |
1335 | pixPtr->SetCoord(i/2, xyCOG[i/2]+(i%2 ? 2:-2)*pixPtr->Size(i/2)); | |
1336 | j = TMath::Even (i/2); | |
1337 | pixPtr->SetCoord(j, xyCOG[j]); | |
1338 | fPixArray->Add((TObject*)pixPtr); | |
1339 | nPix++; | |
1340 | } | |
1341 | } | |
1342 | } // else | |
1343 | ||
1344 | fPixArray->Compress(); | |
1345 | nPix = fPixArray->GetEntriesFast(); | |
1346 | delete [] coef; delete [] probi; coef = 0; probi = 0; | |
1347 | } // while (1) | |
1348 | ||
1349 | // remove pixels with low signal or low visibility | |
1350 | // Cuts are empirical !!! | |
1351 | Double_t thresh = TMath::Max (mlem->GetMaximum()/100.,1.); | |
1352 | thresh = TMath::Min (thresh,50.); | |
1353 | Double_t cmax = -1, charge = 0; | |
1354 | for (Int_t i=0; i<nPix; i++) cmax = TMath::Max (cmax,probi[i]); | |
1355 | // Mark pixels which should be removed | |
1356 | for (Int_t i=0; i<nPix; i++) { | |
1357 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i); | |
1358 | charge = pixPtr->Charge(); | |
1359 | if (charge < thresh) pixPtr->SetCharge(-charge); | |
1360 | else if (cmax > 1.91) { | |
1361 | if (probi[i] < 1.9) pixPtr->SetCharge(-charge); | |
1362 | } | |
1363 | else if (probi[i] < cmax*0.9) pixPtr->SetCharge(-charge); | |
1364 | } | |
1365 | // Move charge of removed pixels to their nearest neighbour (to keep total charge the same) | |
1366 | Int_t near = 0; | |
1367 | for (Int_t i=0; i<nPix; i++) { | |
1368 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i); | |
1369 | charge = pixPtr->Charge(); | |
1370 | if (charge > 0) continue; | |
1371 | near = FindNearest(pixPtr); | |
1372 | pixPtr->SetCharge(0); | |
1373 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(near); | |
1374 | pixPtr->SetCharge(pixPtr->Charge() - charge); | |
1375 | } | |
1376 | // Update histogram | |
1377 | for (Int_t i=0; i<nPix; i++) { | |
1378 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i); | |
1379 | ix = mlem->GetXaxis()->FindBin(pixPtr->Coord(0)); | |
1380 | iy = mlem->GetYaxis()->FindBin(pixPtr->Coord(1)); | |
1381 | mlem->SetBinContent(ix, iy, pixPtr->Charge()); | |
1382 | } | |
1383 | if (fDraw) { | |
1384 | ((TCanvas*)gROOT->FindObject("c2"))->cd(); | |
1385 | gPad->SetTheta(55); | |
1386 | gPad->SetPhi(30); | |
1387 | mlem->Draw("lego1Fb"); | |
1388 | gPad->Update(); | |
1389 | } | |
1390 | ||
1391 | fxyMu[0][6] = fxyMu[1][6] = 9999; | |
1392 | // Try to split into clusters | |
1393 | Bool_t ok = kTRUE; | |
1394 | if (mlem->GetSum() < 1) ok = kFALSE; | |
1395 | else Split(mlem, coef); | |
1396 | delete [] coef; delete [] probi; coef = 0; probi = 0; | |
1397 | fPixArray->Delete(); | |
1398 | return ok; | |
1399 | } | |
1400 | ||
1401 | //_____________________________________________________________________________ | |
1402 | void AliMUONClusterFinderAZ::Mlem(Double_t *coef, Double_t *probi) | |
1403 | { | |
1404 | // Use MLEM to find pixel charges | |
1405 | ||
1406 | Int_t nPix = fPixArray->GetEntriesFast(); | |
1407 | Int_t npad = fnPads[0] + fnPads[1]; | |
1408 | Double_t *probi1 = new Double_t [nPix]; | |
1409 | Int_t indx, indx1; | |
1410 | AliMUONPixel *pixPtr; | |
1411 | ||
1412 | for (Int_t iter=0; iter<15; iter++) { | |
1413 | // Do iterations | |
1414 | for (Int_t ipix=0; ipix<nPix; ipix++) { | |
1415 | // Correct each pixel | |
1416 | if (probi[ipix] < 0.01) continue; // skip "invisible" pixel | |
1417 | Double_t sum = 0; | |
1418 | probi1[ipix] = probi[ipix]; | |
1419 | for (Int_t j=0; j<npad; j++) { | |
1420 | if (fPadIJ[1][j] < 0) continue; | |
1421 | Double_t sum1 = 0; | |
1422 | indx1 = j*nPix; | |
1423 | indx = indx1 + ipix; | |
1424 | for (Int_t i=0; i<nPix; i++) { | |
1425 | // Caculate expectation | |
1426 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i); | |
1427 | sum1 += pixPtr->Charge()*coef[indx1+i]; | |
1428 | } // for (Int_t i=0; | |
1429 | if (fXyq[2][j] > fResponse->MaxAdc()-1 && sum1 > fResponse->MaxAdc()) { probi1[ipix] -= coef[indx]; continue; } // correct for pad charge overflows | |
1430 | //cout << sum1 << " " << fXyq[2][j] << " " << coef[j*nPix+ipix] << endl; | |
1431 | if (coef[indx] > 1.e-6) sum += fXyq[2][j]*coef[indx]/sum1; | |
1432 | } // for (Int_t j=0; | |
1433 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(ipix); | |
1434 | if (probi1[ipix] > 1.e-6) pixPtr->SetCharge(pixPtr->Charge()*sum/probi1[ipix]); | |
1435 | } // for (Int_t ipix=0; | |
1436 | } // for (Int_t iter=0; | |
1437 | delete [] probi1; | |
1438 | return; | |
1439 | } | |
1440 | ||
1441 | //_____________________________________________________________________________ | |
1442 | void AliMUONClusterFinderAZ::FindCOG(TH2D *mlem, Double_t *xyc) | |
1443 | { | |
1444 | // Calculate position of the center-of-gravity around the maximum pixel | |
1445 | ||
1446 | Int_t ixmax, iymax, ix, nsumx=0, nsumy=0, nsum=0; | |
1447 | Int_t i1 = -9, j1 = -9; | |
1448 | mlem->GetMaximumBin(ixmax,iymax,ix); | |
1449 | Int_t nx = mlem->GetNbinsX(); | |
1450 | Int_t ny = mlem->GetNbinsY(); | |
1451 | Double_t thresh = mlem->GetMaximum()/10; | |
1452 | Double_t x, y, cont, xq=0, yq=0, qq=0; | |
1453 | ||
1454 | for (Int_t i=TMath::Max(1,iymax-1); i<=TMath::Min(ny,iymax+1); i++) { | |
1455 | y = mlem->GetYaxis()->GetBinCenter(i); | |
1456 | for (Int_t j=TMath::Max(1,ixmax-1); j<=TMath::Min(nx,ixmax+1); j++) { | |
1457 | cont = mlem->GetCellContent(j,i); | |
1458 | if (cont < thresh) continue; | |
1459 | if (i != i1) {i1 = i; nsumy++;} | |
1460 | if (j != j1) {j1 = j; nsumx++;} | |
1461 | x = mlem->GetXaxis()->GetBinCenter(j); | |
1462 | xq += x*cont; | |
1463 | yq += y*cont; | |
1464 | qq += cont; | |
1465 | nsum++; | |
1466 | } | |
1467 | } | |
1468 | ||
1469 | Double_t cmax = 0; | |
1470 | Int_t i2 = 0, j2 = 0; | |
1471 | x = y = 0; | |
1472 | if (nsumy == 1) { | |
1473 | // one bin in Y - add one more (with the largest signal) | |
1474 | for (Int_t i=TMath::Max(1,iymax-1); i<=TMath::Min(ny,iymax+1); i++) { | |
1475 | if (i == iymax) continue; | |
1476 | for (Int_t j=TMath::Max(1,ixmax-1); j<=TMath::Min(nx,ixmax+1); j++) { | |
1477 | cont = mlem->GetCellContent(j,i); | |
1478 | if (cont > cmax) { | |
1479 | cmax = cont; | |
1480 | x = mlem->GetXaxis()->GetBinCenter(j); | |
1481 | y = mlem->GetYaxis()->GetBinCenter(i); | |
1482 | i2 = i; | |
1483 | j2 = j; | |
1484 | } | |
1485 | } | |
1486 | } | |
1487 | xq += x*cmax; | |
1488 | yq += y*cmax; | |
1489 | qq += cmax; | |
1490 | if (i2 != i1) nsumy++; | |
1491 | if (j2 != j1) nsumx++; | |
1492 | nsum++; | |
1493 | } // if (nsumy == 1) | |
1494 | ||
1495 | if (nsumx == 1) { | |
1496 | // one bin in X - add one more (with the largest signal) | |
1497 | cmax = x = y = 0; | |
1498 | for (Int_t j=TMath::Max(1,ixmax-1); j<=TMath::Min(nx,ixmax+1); j++) { | |
1499 | if (j == ixmax) continue; | |
1500 | for (Int_t i=TMath::Max(1,iymax-1); i<=TMath::Min(ny,iymax+1); i++) { | |
1501 | cont = mlem->GetCellContent(j,i); | |
1502 | if (cont > cmax) { | |
1503 | cmax = cont; | |
1504 | x = mlem->GetXaxis()->GetBinCenter(j); | |
1505 | y = mlem->GetYaxis()->GetBinCenter(i); | |
1506 | i2 = i; | |
1507 | j2 = j; | |
1508 | } | |
1509 | } | |
1510 | } | |
1511 | xq += x*cmax; | |
1512 | yq += y*cmax; | |
1513 | qq += cmax; | |
1514 | if (i2 != i1) nsumy++; | |
1515 | if (j2 != j1) nsumx++; | |
1516 | nsum++; | |
1517 | } // if (nsumx == 1) | |
1518 | ||
1519 | xyc[0] = xq/qq; xyc[1] = yq/qq; | |
1520 | cout << xyc[0] << " " << xyc[1] << " " << qq << " " << nsum << " " << nsumx << " " << nsumy << endl; | |
1521 | return; | |
1522 | } | |
1523 | ||
1524 | //_____________________________________________________________________________ | |
1525 | Int_t AliMUONClusterFinderAZ::FindNearest(AliMUONPixel *pixPtr0) | |
1526 | { | |
1527 | // Find the pixel nearest to the given one | |
1528 | // (algorithm may be not very efficient) | |
1529 | ||
1530 | Int_t nPix = fPixArray->GetEntriesFast(), imin = 0; | |
1531 | Double_t rmin = 99999, dx = 0, dy = 0, r = 0; | |
1532 | Double_t xc = pixPtr0->Coord(0), yc = pixPtr0->Coord(1); | |
1533 | AliMUONPixel *pixPtr; | |
1534 | ||
1535 | for (Int_t i=0; i<nPix; i++) { | |
1536 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i); | |
1537 | if (pixPtr->Charge() < 0.5) continue; | |
1538 | dx = (xc - pixPtr->Coord(0)) / pixPtr->Size(0); | |
1539 | dy = (yc - pixPtr->Coord(1)) / pixPtr->Size(1); | |
1540 | r = dx *dx + dy * dy; | |
1541 | if (r < rmin) { rmin = r; imin = i; } | |
1542 | } | |
1543 | return imin; | |
1544 | } | |
1545 | ||
1546 | //_____________________________________________________________________________ | |
1547 | void AliMUONClusterFinderAZ::Split(TH2D *mlem, Double_t *coef) | |
1548 | { | |
1549 | // The main steering function to work with clusters of pixels in anode | |
1550 | // plane (find clusters, decouple them from each other, merge them (if | |
1551 | // necessary), pick up coupled pads, call the fitting function) | |
1552 | ||
1553 | Int_t nx = mlem->GetNbinsX(); | |
1554 | Int_t ny = mlem->GetNbinsY(); | |
1555 | Int_t nPix = fPixArray->GetEntriesFast(); | |
1556 | ||
1557 | Bool_t *used = new Bool_t[ny*nx]; | |
1558 | Double_t cont; | |
1559 | Int_t nclust = 0, indx, indx1; | |
1560 | ||
1561 | for (Int_t i=0; i<ny*nx; i++) used[i] = kFALSE; | |
1562 | ||
1563 | TObjArray *clusters[200]={0}; | |
1564 | TObjArray *pix; | |
1565 | ||
1566 | // Find clusters of histogram bins (easier to work in 2-D space) | |
1567 | for (Int_t i=1; i<=ny; i++) { | |
1568 | for (Int_t j=1; j<=nx; j++) { | |
1569 | indx = (i-1)*nx + j - 1; | |
1570 | if (used[indx]) continue; | |
1571 | cont = mlem->GetCellContent(j,i); | |
1572 | if (cont < 0.5) continue; | |
1573 | pix = new TObjArray(20); | |
1574 | used[indx] = 1; | |
1575 | pix->Add(BinToPix(mlem,j,i)); | |
1576 | AddBin(mlem, i, j, 0, used, pix); // recursive call | |
1577 | clusters[nclust++] = pix; | |
1578 | if (nclust > 200) { cout << " Too many clusters " << endl; ::exit(0); } | |
1579 | } // for (Int_t j=1; j<=nx; j++) { | |
1580 | } // for (Int_t i=1; i<=ny; | |
1581 | cout << nclust << endl; | |
1582 | delete [] used; used = 0; | |
1583 | ||
1584 | // Compute couplings between clusters and clusters to pads | |
1585 | Int_t npad = fnPads[0] + fnPads[1]; | |
1586 | ||
1587 | // Exclude pads with overflows | |
1588 | for (Int_t j=0; j<npad; j++) { | |
1589 | if (fXyq[2][j] > fResponse->MaxAdc()-1) fPadIJ[1][j] = -9; | |
1590 | else fPadIJ[1][j] = 0; | |
1591 | } | |
1592 | ||
1593 | // Compute couplings of clusters to pads | |
c1aed84f | 1594 | TMatrixD *aijclupad = new TMatrixD(nclust,npad); |
1595 | *aijclupad = 0; | |
0df3ca52 | 1596 | Int_t npxclu; |
1597 | for (Int_t iclust=0; iclust<nclust; iclust++) { | |
1598 | pix = clusters[iclust]; | |
1599 | npxclu = pix->GetEntriesFast(); | |
1600 | for (Int_t i=0; i<npxclu; i++) { | |
1601 | indx = fPixArray->IndexOf(pix->UncheckedAt(i)); | |
1602 | for (Int_t j=0; j<npad; j++) { | |
1603 | // Exclude overflows | |
1604 | if (fPadIJ[1][j] < 0) continue; | |
343146bf | 1605 | if (coef[j*nPix+indx] < fgkCouplMin) continue; |
c1aed84f | 1606 | (*aijclupad)(iclust,j) += coef[j*nPix+indx]; |
0df3ca52 | 1607 | } |
1608 | } | |
1609 | } | |
1610 | // Compute couplings between clusters | |
c1aed84f | 1611 | TMatrixD *aijcluclu = new TMatrixD(nclust,nclust); |
1612 | *aijcluclu = 0; | |
0df3ca52 | 1613 | for (Int_t iclust=0; iclust<nclust; iclust++) { |
1614 | for (Int_t j=0; j<npad; j++) { | |
1615 | // Exclude overflows | |
1616 | if (fPadIJ[1][j] < 0) continue; | |
343146bf | 1617 | if ((*aijclupad)(iclust,j) < fgkCouplMin) continue; |
0df3ca52 | 1618 | for (Int_t iclust1=iclust+1; iclust1<nclust; iclust1++) { |
343146bf | 1619 | if ((*aijclupad)(iclust1,j) < fgkCouplMin) continue; |
c1aed84f | 1620 | (*aijcluclu)(iclust,iclust1) += |
1621 | TMath::Sqrt ((*aijclupad)(iclust,j)*(*aijclupad)(iclust1,j)); | |
0df3ca52 | 1622 | } |
1623 | } | |
1624 | } | |
1625 | for (Int_t iclust=0; iclust<nclust; iclust++) { | |
1626 | for (Int_t iclust1=iclust+1; iclust1<nclust; iclust1++) { | |
c1aed84f | 1627 | (*aijcluclu)(iclust1,iclust) = (*aijcluclu)(iclust,iclust1); |
0df3ca52 | 1628 | } |
1629 | } | |
1630 | ||
c1aed84f | 1631 | if (nclust > 1) aijcluclu->Print(); |
0df3ca52 | 1632 | |
1633 | // Find groups of coupled clusters | |
1634 | used = new Bool_t[nclust]; | |
1635 | for (Int_t i=0; i<nclust; i++) used[i] = kFALSE; | |
1636 | Int_t *clustNumb = new Int_t[nclust]; | |
1637 | Int_t nCoupled, nForFit, minGroup[3], clustFit[3], nfit = 0; | |
1638 | Double_t parOk[8]; | |
1639 | ||
1640 | for (Int_t igroup=0; igroup<nclust; igroup++) { | |
1641 | if (used[igroup]) continue; | |
1642 | used[igroup] = kTRUE; | |
1643 | clustNumb[0] = igroup; | |
1644 | nCoupled = 1; | |
1645 | // Find group of coupled clusters | |
c1aed84f | 1646 | AddCluster(igroup, nclust, aijcluclu, used, clustNumb, nCoupled); // recursive |
0df3ca52 | 1647 | cout << " nCoupled: " << nCoupled << endl; |
1648 | for (Int_t i=0; i<nCoupled; i++) cout << clustNumb[i] << " "; cout << endl; | |
1649 | ||
1650 | while (nCoupled > 0) { | |
1651 | ||
1652 | if (nCoupled < 4) { | |
1653 | nForFit = nCoupled; | |
1654 | for (Int_t i=0; i<nCoupled; i++) clustFit[i] = clustNumb[i]; | |
1655 | } else { | |
1656 | // Too many coupled clusters to fit - try to decouple them | |
1657 | // Find the lowest coupling of 1, 2, min(3,nLinks/2) pixels with | |
1658 | // all the others in the group | |
1659 | for (Int_t j=0; j<3; j++) minGroup[j] = -1; | |
c1aed84f | 1660 | Double_t coupl = MinGroupCoupl(nCoupled, clustNumb, aijcluclu, minGroup); |
0df3ca52 | 1661 | |
1662 | // Flag clusters for fit | |
1663 | nForFit = 0; | |
1664 | while (minGroup[nForFit] >= 0 && nForFit < 3) { | |
1665 | cout << clustNumb[minGroup[nForFit]] << " "; | |
1666 | clustFit[nForFit] = clustNumb[minGroup[nForFit]]; | |
1667 | clustNumb[minGroup[nForFit]] -= 999; | |
1668 | nForFit++; | |
1669 | } | |
1670 | cout << nForFit << " " << coupl << endl; | |
1671 | } // else | |
1672 | ||
1673 | // Select pads for fit. | |
c1aed84f | 1674 | if (SelectPad(nCoupled, nForFit, clustNumb, clustFit, aijclupad) < 3 && nCoupled > 1) { |
0df3ca52 | 1675 | // Deselect pads |
1676 | for (Int_t j=0; j<npad; j++) if (TMath::Abs(fPadIJ[1][j]) == 1) fPadIJ[1][j] = 0; | |
1677 | // Merge the failed cluster candidates (with too few pads to fit) with | |
1678 | // the one with the strongest coupling | |
c1aed84f | 1679 | Merge(nForFit, nCoupled, clustNumb, clustFit, clusters, aijcluclu, aijclupad); |
0df3ca52 | 1680 | } else { |
1681 | // Do the fit | |
1682 | nfit = Fit(nForFit, clustFit, clusters, parOk); | |
1683 | } | |
1684 | ||
1685 | // Subtract the fitted charges from pads with strong coupling and/or | |
1686 | // return pads for further use | |
1687 | UpdatePads(nfit, parOk); | |
1688 | ||
1689 | // Mark used pads | |
1690 | for (Int_t j=0; j<npad; j++) {if (fPadIJ[1][j] == 1) fPadIJ[1][j] = -1;} | |
1691 | ||
1692 | // Sort the clusters (move to the right the used ones) | |
1693 | Int_t beg = 0, end = nCoupled - 1; | |
1694 | while (beg < end) { | |
1695 | if (clustNumb[beg] >= 0) { beg++; continue; } | |
1696 | for (Int_t j=end; j>beg; j--) { | |
1697 | if (clustNumb[j] < 0) continue; | |
1698 | end = j - 1; | |
1699 | indx = clustNumb[beg]; | |
1700 | clustNumb[beg] = clustNumb[j]; | |
1701 | clustNumb[j] = indx; | |
1702 | break; | |
1703 | } | |
1704 | beg++; | |
1705 | } | |
1706 | ||
1707 | nCoupled -= nForFit; | |
1708 | if (nCoupled > 3) { | |
1709 | // Remove couplings of used clusters | |
1710 | for (Int_t iclust=nCoupled; iclust<nCoupled+nForFit; iclust++) { | |
1711 | indx = clustNumb[iclust] + 999; | |
1712 | for (Int_t iclust1=0; iclust1<nCoupled; iclust1++) { | |
1713 | indx1 = clustNumb[iclust1]; | |
c1aed84f | 1714 | (*aijcluclu)(indx,indx1) = (*aijcluclu)(indx1,indx) = 0; |
0df3ca52 | 1715 | } |
1716 | } | |
1717 | ||
1718 | // Update the remaining clusters couplings (exclude couplings from | |
1719 | // the used pads) | |
1720 | for (Int_t j=0; j<npad; j++) { | |
1721 | if (fPadIJ[1][j] != -1) continue; | |
1722 | for (Int_t iclust=0; iclust<nCoupled; iclust++) { | |
1723 | indx = clustNumb[iclust]; | |
343146bf | 1724 | if ((*aijclupad)(indx,j) < fgkCouplMin) continue; |
0df3ca52 | 1725 | for (Int_t iclust1=iclust+1; iclust1<nCoupled; iclust1++) { |
1726 | indx1 = clustNumb[iclust1]; | |
343146bf | 1727 | if ((*aijclupad)(indx1,j) < fgkCouplMin) continue; |
0df3ca52 | 1728 | // Check this |
c1aed84f | 1729 | (*aijcluclu)(indx,indx1) -= |
1730 | TMath::Sqrt ((*aijclupad)(indx,j)*(*aijclupad)(indx1,j)); | |
1731 | (*aijcluclu)(indx1,indx) = (*aijcluclu)(indx,indx1); | |
0df3ca52 | 1732 | } |
1733 | } | |
1734 | fPadIJ[1][j] = -9; | |
1735 | } // for (Int_t j=0; j<npad; | |
1736 | } // if (nCoupled > 3) | |
1737 | } // while (nCoupled > 0) | |
1738 | } // for (Int_t igroup=0; igroup<nclust; | |
1739 | ||
c1aed84f | 1740 | //delete aij_clu; aij_clu = 0; delete aijclupad; aijclupad = 0; |
1741 | aijcluclu->Delete(); aijclupad->Delete(); | |
0df3ca52 | 1742 | for (Int_t iclust=0; iclust<nclust; iclust++) { |
1743 | pix = clusters[iclust]; | |
1744 | pix->Clear(); | |
1745 | delete pix; pix = 0; | |
1746 | } | |
1747 | delete [] clustNumb; clustNumb = 0; delete [] used; used = 0; | |
1748 | } | |
1749 | ||
1750 | //_____________________________________________________________________________ | |
1751 | void AliMUONClusterFinderAZ::AddBin(TH2D *mlem, Int_t ic, Int_t jc, Int_t mode, Bool_t *used, TObjArray *pix) | |
1752 | { | |
1753 | // Add a bin to the cluster | |
1754 | ||
1755 | Int_t nx = mlem->GetNbinsX(); | |
1756 | Int_t ny = mlem->GetNbinsY(); | |
1757 | Double_t cont1, cont = mlem->GetCellContent(jc,ic); | |
1758 | AliMUONPixel *pixPtr = 0; | |
1759 | ||
1760 | for (Int_t i=TMath::Max(ic-1,1); i<=TMath::Min(ic+1,ny); i++) { | |
1761 | for (Int_t j=TMath::Max(jc-1,1); j<=TMath::Min(jc+1,nx); j++) { | |
1762 | if (i != ic && j != jc) continue; | |
1763 | if (used[(i-1)*nx+j-1]) continue; | |
1764 | cont1 = mlem->GetCellContent(j,i); | |
1765 | if (mode && cont1 > cont) continue; | |
1766 | used[(i-1)*nx+j-1] = kTRUE; | |
1767 | if (cont1 < 0.5) continue; | |
1768 | if (pix) pix->Add(BinToPix(mlem,j,i)); | |
1769 | else { | |
1770 | pixPtr = new AliMUONPixel (mlem->GetXaxis()->GetBinCenter(j), | |
1771 | mlem->GetYaxis()->GetBinCenter(i), 0, 0, cont1); | |
1772 | fPixArray->Add((TObject*)pixPtr); | |
1773 | } | |
1774 | AddBin(mlem, i, j, mode, used, pix); // recursive call | |
1775 | } | |
1776 | } | |
1777 | } | |
1778 | ||
1779 | //_____________________________________________________________________________ | |
1780 | TObject* AliMUONClusterFinderAZ::BinToPix(TH2D *mlem, Int_t jc, Int_t ic) | |
1781 | { | |
1782 | // Translate histogram bin to pixel | |
1783 | ||
1784 | Double_t yc = mlem->GetYaxis()->GetBinCenter(ic); | |
1785 | Double_t xc = mlem->GetXaxis()->GetBinCenter(jc); | |
1786 | ||
1787 | Int_t nPix = fPixArray->GetEntriesFast(); | |
1788 | AliMUONPixel *pixPtr; | |
1789 | ||
1790 | // Compare pixel and bin positions | |
1791 | for (Int_t i=0; i<nPix; i++) { | |
1792 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i); | |
1793 | if (pixPtr->Charge() < 0.5) continue; | |
1794 | if (TMath::Abs(pixPtr->Coord(0)-xc)<1.e-4 && TMath::Abs(pixPtr->Coord(1)-yc)<1.e-4) return (TObject*) pixPtr; | |
1795 | } | |
1796 | cout << " Something wrong ??? " << endl; | |
1797 | return NULL; | |
1798 | } | |
1799 | ||
1800 | //_____________________________________________________________________________ | |
c1aed84f | 1801 | void AliMUONClusterFinderAZ::AddCluster(Int_t ic, Int_t nclust, TMatrixD *aijcluclu, Bool_t *used, Int_t *clustNumb, Int_t &nCoupled) |
0df3ca52 | 1802 | { |
1803 | // Add a cluster to the group of coupled clusters | |
1804 | ||
1805 | for (Int_t i=0; i<nclust; i++) { | |
1806 | if (used[i]) continue; | |
343146bf | 1807 | if ((*aijcluclu)(i,ic) < fgkCouplMin) continue; |
0df3ca52 | 1808 | used[i] = kTRUE; |
1809 | clustNumb[nCoupled++] = i; | |
c1aed84f | 1810 | AddCluster(i, nclust, aijcluclu, used, clustNumb, nCoupled); |
0df3ca52 | 1811 | } |
1812 | } | |
1813 | ||
1814 | //_____________________________________________________________________________ | |
c1aed84f | 1815 | Double_t AliMUONClusterFinderAZ::MinGroupCoupl(Int_t nCoupled, Int_t *clustNumb, TMatrixD *aijcluclu, Int_t *minGroup) |
0df3ca52 | 1816 | { |
1817 | // Find group of clusters with minimum coupling to all the others | |
1818 | ||
1819 | Int_t i123max = TMath::Min(3,nCoupled/2); | |
1820 | Int_t indx, indx1, indx2, indx3, nTot = 0; | |
1821 | Double_t *coupl1 = 0, *coupl2 = 0, *coupl3 = 0; | |
1822 | ||
1823 | for (Int_t i123=1; i123<=i123max; i123++) { | |
1824 | ||
1825 | if (i123 == 1) { | |
1826 | coupl1 = new Double_t [nCoupled]; | |
1827 | for (Int_t i=0; i<nCoupled; i++) coupl1[i] = 0; | |
1828 | } | |
1829 | else if (i123 == 2) { | |
1830 | nTot = nCoupled*nCoupled; | |
1831 | coupl2 = new Double_t [nTot]; | |
1832 | for (Int_t i=0; i<nTot; i++) coupl2[i] = 9999; | |
1833 | } else { | |
1834 | nTot = nTot*nCoupled; | |
1835 | coupl3 = new Double_t [nTot]; | |
1836 | for (Int_t i=0; i<nTot; i++) coupl3[i] = 9999; | |
1837 | } // else | |
1838 | ||
1839 | for (Int_t i=0; i<nCoupled; i++) { | |
1840 | indx1 = clustNumb[i]; | |
1841 | for (Int_t j=i+1; j<nCoupled; j++) { | |
1842 | indx2 = clustNumb[j]; | |
1843 | if (i123 == 1) { | |
c1aed84f | 1844 | coupl1[i] += (*aijcluclu)(indx1,indx2); |
1845 | coupl1[j] += (*aijcluclu)(indx1,indx2); | |
0df3ca52 | 1846 | } |
1847 | else if (i123 == 2) { | |
1848 | indx = i*nCoupled + j; | |
1849 | coupl2[indx] = coupl1[i] + coupl1[j]; | |
c1aed84f | 1850 | coupl2[indx] -= 2 * ((*aijcluclu)(indx1,indx2)); |
0df3ca52 | 1851 | } else { |
1852 | for (Int_t k=j+1; k<nCoupled; k++) { | |
1853 | indx3 = clustNumb[k]; | |
1854 | indx = i*nCoupled*nCoupled + j*nCoupled + k; | |
1855 | coupl3[indx] = coupl2[i*nCoupled+j] + coupl1[k]; | |
c1aed84f | 1856 | coupl3[indx] -= 2 * ((*aijcluclu)(indx1,indx3)+(*aijcluclu)(indx2,indx3)); |
0df3ca52 | 1857 | } |
1858 | } // else | |
1859 | } // for (Int_t j=i+1; | |
1860 | } // for (Int_t i=0; | |
1861 | } // for (Int_t i123=1; | |
1862 | ||
1863 | // Find minimum coupling | |
1864 | Double_t couplMin = 9999; | |
1865 | Int_t locMin = 0; | |
1866 | ||
1867 | for (Int_t i123=1; i123<=i123max; i123++) { | |
1868 | if (i123 == 1) { | |
1869 | locMin = TMath::LocMin(nCoupled, coupl1); | |
1870 | couplMin = coupl1[locMin]; | |
1871 | minGroup[0] = locMin; | |
1872 | delete [] coupl1; coupl1 = 0; | |
1873 | } | |
1874 | else if (i123 == 2) { | |
1875 | locMin = TMath::LocMin(nCoupled*nCoupled, coupl2); | |
1876 | if (coupl2[locMin] < couplMin) { | |
1877 | couplMin = coupl2[locMin]; | |
1878 | minGroup[0] = locMin/nCoupled; | |
1879 | minGroup[1] = locMin%nCoupled; | |
1880 | } | |
1881 | delete [] coupl2; coupl2 = 0; | |
1882 | } else { | |
1883 | locMin = TMath::LocMin(nTot, coupl3); | |
1884 | if (coupl3[locMin] < couplMin) { | |
1885 | couplMin = coupl3[locMin]; | |
1886 | minGroup[0] = locMin/nCoupled/nCoupled; | |
1887 | minGroup[1] = locMin%(nCoupled*nCoupled)/nCoupled; | |
1888 | minGroup[2] = locMin%nCoupled; | |
1889 | } | |
1890 | delete [] coupl3; coupl3 = 0; | |
1891 | } // else | |
1892 | } // for (Int_t i123=1; | |
1893 | return couplMin; | |
1894 | } | |
1895 | ||
1896 | //_____________________________________________________________________________ | |
c1aed84f | 1897 | Int_t AliMUONClusterFinderAZ::SelectPad(Int_t nCoupled, Int_t nForFit, Int_t *clustNumb, Int_t *clustFit, TMatrixD *aijclupad) |
0df3ca52 | 1898 | { |
1899 | // Select pads for fit. If too many coupled clusters, find pads giving | |
1900 | // the strongest coupling with the rest of clusters and exclude them from the fit. | |
1901 | ||
1902 | Int_t npad = fnPads[0] + fnPads[1]; | |
c1aed84f | 1903 | Double_t *padpix = 0; |
0df3ca52 | 1904 | |
1905 | if (nCoupled > 3) { | |
c1aed84f | 1906 | padpix = new Double_t[npad]; |
1907 | for (Int_t i=0; i<npad; i++) padpix[i] = 0; | |
0df3ca52 | 1908 | } |
1909 | ||
1910 | Int_t nOK = 0, indx, indx1; | |
1911 | for (Int_t iclust=0; iclust<nForFit; iclust++) { | |
1912 | indx = clustFit[iclust]; | |
1913 | for (Int_t j=0; j<npad; j++) { | |
1914 | if (fPadIJ[1][j] < 0) continue; // exclude overflows and used pads | |
343146bf | 1915 | if ((*aijclupad)(indx,j) < fgkCouplMin) continue; |
0df3ca52 | 1916 | fPadIJ[1][j] = 1; // pad to be used in fit |
1917 | nOK++; | |
1918 | if (nCoupled > 3) { | |
1919 | // Check other clusters | |
1920 | for (Int_t iclust1=0; iclust1<nCoupled; iclust1++) { | |
1921 | indx1 = clustNumb[iclust1]; | |
1922 | if (indx1 < 0) continue; | |
343146bf | 1923 | if ((*aijclupad)(indx1,j) < fgkCouplMin) continue; |
c1aed84f | 1924 | padpix[j] += (*aijclupad)(indx1,j); |
0df3ca52 | 1925 | } |
1926 | } // if (nCoupled > 3) | |
1927 | } // for (Int_t j=0; j<npad; | |
1928 | } // for (Int_t iclust=0; iclust<nForFit | |
1929 | if (nCoupled < 4) return nOK; | |
1930 | ||
1931 | Double_t aaa = 0; | |
1932 | for (Int_t j=0; j<npad; j++) { | |
343146bf | 1933 | if (padpix[j] < fgkCouplMin) continue; |
c1aed84f | 1934 | cout << j << " " << padpix[j] << " "; |
0df3ca52 | 1935 | cout << fXyq[0][j] << " " << fXyq[1][j] << endl; |
c1aed84f | 1936 | aaa += padpix[j]; |
0df3ca52 | 1937 | fPadIJ[1][j] = -1; // exclude pads with strong coupling to the other clusters |
1938 | nOK--; | |
1939 | } | |
c1aed84f | 1940 | delete [] padpix; padpix = 0; |
0df3ca52 | 1941 | return nOK; |
1942 | } | |
1943 | ||
1944 | //_____________________________________________________________________________ | |
c1aed84f | 1945 | void AliMUONClusterFinderAZ::Merge(Int_t nForFit, Int_t nCoupled, Int_t *clustNumb, Int_t *clustFit, TObjArray **clusters, TMatrixD *aijcluclu, TMatrixD *aijclupad) |
0df3ca52 | 1946 | { |
1947 | // Merge the group of clusters with the one having the strongest coupling with them | |
1948 | ||
1949 | Int_t indx, indx1, npxclu, npxclu1, imax=0; | |
1950 | TObjArray *pix, *pix1; | |
1951 | Double_t couplMax; | |
1952 | ||
1953 | for (Int_t icl=0; icl<nForFit; icl++) { | |
1954 | indx = clustFit[icl]; | |
1955 | pix = clusters[indx]; | |
1956 | npxclu = pix->GetEntriesFast(); | |
1957 | couplMax = -1; | |
1958 | for (Int_t icl1=0; icl1<nCoupled; icl1++) { | |
1959 | indx1 = clustNumb[icl1]; | |
1960 | if (indx1 < 0) continue; | |
c1aed84f | 1961 | if ((*aijcluclu)(indx,indx1) > couplMax) { |
1962 | couplMax = (*aijcluclu)(indx,indx1); | |
0df3ca52 | 1963 | imax = indx1; |
1964 | } | |
1965 | } // for (Int_t icl1=0; | |
343146bf | 1966 | /*if (couplMax < fgkCouplMin) { |
0df3ca52 | 1967 | cout << " Oops " << couplMax << endl; |
c1aed84f | 1968 | aijcluclu->Print(); |
0df3ca52 | 1969 | cout << icl << " " << indx << " " << npxclu << " " << nLinks << endl; |
1970 | ::exit(0); | |
1971 | }*/ | |
1972 | // Add to it | |
1973 | pix1 = clusters[imax]; | |
1974 | npxclu1 = pix1->GetEntriesFast(); | |
1975 | // Add pixels | |
1976 | for (Int_t i=0; i<npxclu; i++) { pix1->Add(pix->UncheckedAt(i)); pix->RemoveAt(i); } | |
1977 | cout << " New number of pixels: " << npxclu1 << " " << pix1->GetEntriesFast() << endl; | |
1978 | //Add cluster-to-cluster couplings | |
c1aed84f | 1979 | //aijcluclu->Print(); |
0df3ca52 | 1980 | for (Int_t icl1=0; icl1<nCoupled; icl1++) { |
1981 | indx1 = clustNumb[icl1]; | |
1982 | if (indx1 < 0 || indx1 == imax) continue; | |
c1aed84f | 1983 | (*aijcluclu)(indx1,imax) += (*aijcluclu)(indx,indx1); |
1984 | (*aijcluclu)(imax,indx1) = (*aijcluclu)(indx1,imax); | |
0df3ca52 | 1985 | } |
c1aed84f | 1986 | (*aijcluclu)(indx,imax) = (*aijcluclu)(imax,indx) = 0; |
1987 | //aijcluclu->Print(); | |
0df3ca52 | 1988 | //Add cluster-to-pad couplings |
1989 | for (Int_t j=0; j<fnPads[0]+fnPads[1]; j++) { | |
1990 | if (fPadIJ[1][j] < 0) continue; // exclude overflows and used pads | |
c1aed84f | 1991 | (*aijclupad)(imax,j) += (*aijclupad)(indx,j); |
1992 | (*aijclupad)(indx,j) = 0; | |
0df3ca52 | 1993 | } |
1994 | } // for (Int_t icl=0; icl<nForFit; | |
1995 | } | |
1996 | ||
1997 | //_____________________________________________________________________________ | |
1998 | Int_t AliMUONClusterFinderAZ::Fit(Int_t nfit, Int_t *clustFit, TObjArray **clusters, Double_t *parOk) | |
1999 | { | |
2000 | // Find selected clusters to selected pad charges | |
2001 | ||
2002 | TH2D *mlem = (TH2D*) gROOT->FindObject("mlem"); | |
2003 | //Int_t nx = mlem->GetNbinsX(); | |
2004 | //Int_t ny = mlem->GetNbinsY(); | |
2005 | Double_t xmin = mlem->GetXaxis()->GetXmin() - mlem->GetXaxis()->GetBinWidth(1); | |
2006 | Double_t xmax = mlem->GetXaxis()->GetXmax() + mlem->GetXaxis()->GetBinWidth(1); | |
2007 | Double_t ymin = mlem->GetYaxis()->GetXmin() - mlem->GetYaxis()->GetBinWidth(1); | |
2008 | Double_t ymax = mlem->GetYaxis()->GetXmax() + mlem->GetYaxis()->GetBinWidth(1); | |
2009 | //Double_t qmin = 0, qmax = 1; | |
2010 | Double_t step[3]={0.01,0.002,0.02}; | |
2011 | ||
2012 | Double_t cont, cmax = 0, xseed = 0, yseed = 0, errOk[8]; | |
2013 | TObjArray *pix; | |
2014 | Int_t npxclu; | |
2015 | ||
2016 | // Number of pads to use | |
2017 | Int_t npads = 0; | |
2018 | for (Int_t i=0; i<fnPads[0]+fnPads[1]; i++) {if (fPadIJ[1][i] == 1) npads++;} | |
2019 | for (Int_t i=0; i<nfit; i++) {cout << i+1 << " " << clustFit[i] << " ";} | |
2020 | cout << nfit << endl; | |
2021 | cout << " Number of pads to fit: " << npads << endl; | |
2022 | fNpar = 0; | |
2023 | fQtot = 0; | |
2024 | if (npads < 2) return 0; | |
2025 | ||
2026 | // Take cluster maxima as fitting seeds | |
2027 | AliMUONPixel *pixPtr; | |
2028 | Double_t xyseed[3][2], qseed[3]; | |
2029 | for (Int_t ifit=1; ifit<=nfit; ifit++) { | |
2030 | cmax = 0; | |
2031 | pix = clusters[clustFit[ifit-1]]; | |
2032 | npxclu = pix->GetEntriesFast(); | |
2033 | for (Int_t clu=0; clu<npxclu; clu++) { | |
2034 | pixPtr = (AliMUONPixel*) pix->UncheckedAt(clu); | |
2035 | cont = pixPtr->Charge(); | |
2036 | fQtot += cont; | |
2037 | if (cont > cmax) { | |
2038 | cmax = cont; | |
2039 | xseed = pixPtr->Coord(0); | |
2040 | yseed = pixPtr->Coord(1); | |
2041 | } | |
2042 | } | |
2043 | xyseed[ifit-1][0] = xseed; | |
2044 | xyseed[ifit-1][1] = yseed; | |
2045 | qseed[ifit-1] = cmax; | |
2046 | } // for (Int_t ifit=1; | |
2047 | ||
2048 | Int_t nDof, maxSeed[3]; | |
2049 | Double_t fmin, chi2o = 9999, chi2n; | |
2050 | ||
2051 | // Try to fit with one-track hypothesis, then 2-track. If chi2/dof is | |
2052 | // lower, try 3-track (if number of pads is sufficient). | |
2053 | ||
2054 | TMath::Sort(nfit, qseed, maxSeed, kTRUE); // in decreasing order | |
2055 | nfit = TMath::Min (nfit, (npads + 1) / 3); | |
2056 | ||
2057 | Double_t *gin = 0, func0, func1, param[8], param0[2][8], deriv[2][8], step0[8]; | |
2058 | Double_t shift[8], stepMax, derMax, parmin[8], parmax[8], func2[2], shift0; | |
2059 | Double_t delta[8], scMax, dder[8], estim, shiftSave = 0; | |
2060 | Int_t min, max, nCall = 0, memory[8] = {0}, nLoop, idMax = 0, iestMax = 0, nFail; | |
2061 | ||
2062 | for (Int_t iseed=0; iseed<nfit; iseed++) { | |
2063 | ||
2064 | for (Int_t j=0; j<3; j++) step0[fNpar+j] = shift[fNpar+j] = step[j]; | |
2065 | param[fNpar] = xyseed[maxSeed[iseed]][0]; | |
2066 | parmin[fNpar] = xmin; | |
2067 | parmax[fNpar++] = xmax; | |
2068 | param[fNpar] = xyseed[maxSeed[iseed]][1]; | |
2069 | parmin[fNpar] = ymin; | |
2070 | parmax[fNpar++] = ymax; | |
2071 | if (fNpar > 2) { | |
2072 | param[fNpar] = fNpar == 4 ? 0.5 : 0.3; | |
2073 | parmin[fNpar] = 0; | |
2074 | parmax[fNpar++] = 1; | |
2075 | } | |
2076 | ||
2077 | // Try new algorithm | |
2078 | min = nLoop = 1; stepMax = func2[1] = derMax = 999999; nFail = 0; | |
2079 | ||
2080 | while (1) { | |
2081 | max = !min; | |
30178c30 | 2082 | Fcn1(fNpar, gin, func0, param, 1); nCall++; |
0df3ca52 | 2083 | //cout << " Func: " << func0 << endl; |
2084 | ||
2085 | func2[max] = func0; | |
2086 | for (Int_t j=0; j<fNpar; j++) { | |
2087 | param0[max][j] = param[j]; | |
2088 | delta[j] = step0[j]; | |
2089 | param[j] += delta[j] / 10; | |
2090 | if (j > 0) param[j-1] -= delta[j-1] / 10; | |
30178c30 | 2091 | Fcn1(fNpar, gin, func1, param, 1); nCall++; |
0df3ca52 | 2092 | deriv[max][j] = (func1 - func0) / delta[j] * 10; // first derivative |
2093 | //cout << j << " " << deriv[max][j] << endl; | |
2094 | dder[j] = param0[0][j] != param0[1][j] ? (deriv[0][j] - deriv[1][j]) / | |
2095 | (param0[0][j] - param0[1][j]) : 0; // second derivative | |
2096 | } | |
2097 | param[fNpar-1] -= delta[fNpar-1] / 10; | |
2098 | if (nCall > 2000) ::exit(0); | |
2099 | ||
2100 | min = func2[0] < func2[1] ? 0 : 1; | |
2101 | nFail = min == max ? 0 : nFail + 1; | |
2102 | ||
2103 | stepMax = derMax = estim = 0; | |
2104 | for (Int_t j=0; j<fNpar; j++) { | |
2105 | // Estimated distance to minimum | |
2106 | shift0 = shift[j]; | |
2107 | if (nLoop == 1) shift[j] = TMath::Sign (step0[j], -deriv[max][j]); // first step | |
2108 | else if (TMath::Abs(deriv[0][j]) < 1.e-3 && TMath::Abs(deriv[1][j]) < 1.e-3) shift[j] = 0; | |
2109 | else if (deriv[min][j]*deriv[!min][j] > 0 && TMath::Abs(deriv[min][j]) > TMath::Abs(deriv[!min][j]) | |
2110 | || TMath::Abs(deriv[0][j]-deriv[1][j]) < 1.e-3) { | |
2111 | shift[j] = -TMath::Sign (shift[j], (func2[0]-func2[1]) * (param0[0][j]-param0[1][j])); | |
2112 | if (min == max) { | |
2113 | if (memory[j] > 1) { shift[j] *= 2; } //cout << " Memory " << memory[j] << " " << shift[j] << endl; } | |
2114 | memory[j]++; | |
2115 | } | |
2116 | } else { | |
2117 | shift[j] = -deriv[min][j] / dder[j]; | |
2118 | memory[j] = 0; | |
2119 | } | |
2120 | if (TMath::Abs(shift[j])/step0[j] > estim) { | |
2121 | estim = TMath::Abs(shift[j])/step0[j]; | |
2122 | iestMax = j; | |
2123 | } | |
2124 | ||
2125 | // Too big step | |
2126 | if (TMath::Abs(shift[j])/step0[j] > 10) shift[j] = TMath::Sign(10.,shift[j]) * step0[j]; // | |
2127 | ||
2128 | // Failed to improve minimum | |
2129 | if (min != max) { | |
2130 | memory[j] = 0; | |
2131 | param[j] = param0[min][j]; | |
2132 | if (TMath::Abs(shift[j]+shift0) > 0.1*step0[j]) shift[j] = (shift[j] + shift0) / 2; | |
2133 | else shift[j] /= -2; | |
2134 | } | |
2135 | ||
2136 | // Too big step | |
2137 | if (TMath::Abs(shift[j]*deriv[min][j]) > func2[min]) | |
2138 | shift[j] = TMath::Sign (func2[min]/deriv[min][j], shift[j]); | |
2139 | ||
2140 | // Introduce step relaxation factor | |
2141 | if (memory[j] < 3) { | |
2142 | scMax = 1 + 4 / TMath::Max(nLoop/2.,1.); | |
2143 | if (TMath::Abs(shift0) > 0 && TMath::Abs(shift[j]/shift0) > scMax) | |
2144 | shift[j] = TMath::Sign (shift0*scMax, shift[j]); | |
2145 | } | |
2146 | param[j] += shift[j]; | |
2147 | ||
2148 | //cout << " xxx " << j << " " << shift[j] << " " << param[j] << endl; | |
2149 | stepMax = TMath::Max (stepMax, TMath::Abs(shift[j]/step0[j])); | |
2150 | if (TMath::Abs(deriv[min][j]) > derMax) { | |
2151 | idMax = j; | |
2152 | derMax = TMath::Abs (deriv[min][j]); | |
2153 | } | |
2154 | } // for (Int_t j=0; j<fNpar; | |
2155 | //cout << max << " " << func2[min] << " " << derMax << " " << stepMax << " " << estim << " " << iestMax << " " << nCall << endl; | |
2156 | if (estim < 1 && derMax < 2 || nLoop > 100) break; // minimum was found | |
2157 | ||
2158 | nLoop++; | |
2159 | // Check for small step | |
2160 | if (shift[idMax] == 0) { shift[idMax] = step0[idMax]/10; param[idMax] += shift[idMax]; continue; } | |
2161 | if (!memory[idMax] && derMax > 0.5 && nLoop > 10) { | |
2162 | //cout << " ok " << deriv[min][idMax] << " " << deriv[!min][idMax] << " " << dder[idMax]*shift[idMax] << " " << shift[idMax] << endl; | |
2163 | if (dder[idMax] != 0 && TMath::Abs(deriv[min][idMax]/dder[idMax]/shift[idMax]) > 10) { | |
2164 | if (min == max) dder[idMax] = -dder[idMax]; | |
2165 | shift[idMax] = -deriv[min][idMax] / dder[idMax] / 10; | |
2166 | param[idMax] += shift[idMax]; | |
2167 | stepMax = TMath::Max (stepMax, TMath::Abs(shift[idMax])/step0[idMax]); | |
2168 | //cout << shift[idMax] << " " << param[idMax] << endl; | |
2169 | if (min == max) shiftSave = shift[idMax]; | |
2170 | } | |
2171 | if (nFail > 10) { | |
2172 | param[idMax] -= shift[idMax]; | |
2173 | shift[idMax] = 4 * shiftSave * (gRandom->Rndm(0) - 0.5); | |
2174 | param[idMax] += shift[idMax]; | |
2175 | //cout << shift[idMax] << endl; | |
2176 | } | |
2177 | } | |
2178 | } // while (1) | |
2179 | fmin = func2[min]; | |
2180 | ||
2181 | nDof = npads - fNpar; | |
2182 | chi2n = nDof ? fmin/nDof : 0; | |
2183 | ||
2184 | if (chi2n*1.2+1.e-6 > chi2o ) { fNpar -= 3; break; } | |
2185 | // Save parameters and errors | |
2186 | for (Int_t i=0; i<fNpar; i++) { | |
2187 | parOk[i] = param0[min][i]; | |
2188 | errOk[i] = fmin; | |
2189 | } | |
2190 | ||
2191 | cout << chi2o << " " << chi2n << endl; | |
2192 | chi2o = chi2n; | |
2193 | if (fmin < 0.1) break; // !!!??? | |
2194 | } // for (Int_t iseed=0; | |
2195 | ||
2196 | for (Int_t i=0; i<fNpar; i++) { | |
2197 | if (i == 4 || i == 7) continue; | |
2198 | cout << parOk[i] << " " << errOk[i] << endl; | |
2199 | } | |
2200 | nfit = (fNpar + 1) / 3; | |
2201 | Double_t rad; | |
2202 | Int_t indx, imax; | |
2203 | if (fReco) { | |
2204 | for (Int_t j=0; j<nfit; j++) { | |
2205 | indx = j<2 ? j*2 : j*2+1; | |
2206 | AddRawCluster (parOk[indx], parOk[indx+1], errOk[indx]); | |
2207 | } | |
2208 | return nfit; | |
2209 | } | |
2210 | for (Int_t i=0; i<fnMu; i++) { | |
2211 | cmax = fxyMu[i][6]; | |
2212 | for (Int_t j=0; j<nfit; j++) { | |
2213 | indx = j<2 ? j*2 : j*2+1; | |
2214 | rad = (fxyMu[i][0]-parOk[indx])*(fxyMu[i][0]-parOk[indx]) + | |
2215 | (fxyMu[i][1]-parOk[indx+1])*(fxyMu[i][1]-parOk[indx+1]); | |
2216 | if (rad < cmax) { | |
2217 | cmax = rad; | |
2218 | imax = indx; | |
2219 | fxyMu[i][6] = cmax; | |
2220 | fxyMu[i][2] = parOk[imax] - fxyMu[i][0]; | |
2221 | fxyMu[i][4] = parOk[imax+1] - fxyMu[i][1]; | |
2222 | fxyMu[i][3] = errOk[imax]; | |
2223 | fxyMu[i][5] = errOk[imax+1]; | |
2224 | } | |
2225 | } | |
2226 | } | |
2227 | return nfit; | |
2228 | } | |
2229 | ||
2230 | //_____________________________________________________________________________ | |
30178c30 | 2231 | void AliMUONClusterFinderAZ::Fcn1(Int_t & /*npar*/, Double_t * /*gin*/, Double_t &f, Double_t *par, Int_t /*iflag*/) |
0df3ca52 | 2232 | { |
2233 | // Fit for one track | |
2234 | AliMUONClusterFinderAZ& c = *(AliMUONClusterFinderAZ::fgClusterFinder); | |
2235 | ||
2236 | Int_t cath, ix, iy, indx, npads=0; | |
2237 | Double_t charge, delta, coef=0, chi2=0; | |
2238 | for (Int_t j=0; j<c.fnPads[0]+c.fnPads[1]; j++) { | |
2239 | if (c.fPadIJ[1][j] != 1) continue; | |
2240 | cath = c.fPadIJ[0][j]; | |
2241 | npads++; | |
2242 | c.fSegmentation[cath]->GetPadI(c.fXyq[0][j],c.fXyq[1][j],c.fZpad,ix,iy); | |
2243 | c.fSegmentation[cath]->SetPad(ix,iy); | |
2244 | charge = 0; | |
2245 | for (Int_t i=c.fNpar/3; i>=0; i--) { // sum over tracks | |
2246 | indx = i<2 ? 2*i : 2*i+1; | |
2247 | c.fSegmentation[cath]->SetHit(par[indx],par[indx+1],c.fZpad); | |
2248 | //charge += c.fResponse->IntXY(c.fSegmentation[cath])*par[icl*3+2]; | |
2249 | if (c.fNpar == 2) coef = 1; | |
2250 | else coef = i==c.fNpar/3 ? par[indx+2] : 1-coef; | |
2251 | //coef = TMath::Max (coef, 0.); | |
2252 | if (c.fNpar == 8 && i < 2) coef = i==1 ? coef*par[indx+2] : coef - par[7]; | |
2253 | //coef = TMath::Max (coef, 0.); | |
2254 | charge += c.fResponse->IntXY(c.fSegmentation[cath])*coef; | |
2255 | } | |
2256 | charge *= c.fQtot; | |
2257 | //if (c.fXyq[2][j] > c.fResponse->MaxAdc()-1 && charge > | |
2258 | // c.fResponse->MaxAdc()) charge = c.fResponse->MaxAdc(); | |
2259 | delta = charge - c.fXyq[2][j]; | |
2260 | delta /= TMath::Sqrt ((Double_t)c.fXyq[2][j]); | |
2261 | //chi2 += TMath::Abs(delta); | |
2262 | chi2 += delta*delta; | |
2263 | } // for (Int_t j=0; | |
2264 | f = chi2; | |
2265 | Double_t qAver = c.fQtot/npads; //(c.fnPads[0]+c.fnPads[1]); | |
2266 | f = chi2/qAver; | |
2267 | } | |
2268 | ||
2269 | //_____________________________________________________________________________ | |
6aaf81e6 | 2270 | void AliMUONClusterFinderAZ::UpdatePads(Int_t /*nfit*/, Double_t *par) |
0df3ca52 | 2271 | { |
2272 | // Subtract the fitted charges from pads with strong coupling | |
2273 | ||
2274 | Int_t cath, ix, iy, indx; | |
2275 | Double_t charge, coef=0; | |
2276 | for (Int_t j=0; j<fnPads[0]+fnPads[1]; j++) { | |
2277 | if (fPadIJ[1][j] != -1) continue; | |
2278 | if (fNpar != 0) { | |
2279 | cath = fPadIJ[0][j]; | |
2280 | fSegmentation[cath]->GetPadI(fXyq[0][j],fXyq[1][j],fZpad,ix,iy); | |
2281 | fSegmentation[cath]->SetPad(ix,iy); | |
2282 | charge = 0; | |
2283 | for (Int_t i=fNpar/3; i>=0; i--) { // sum over tracks | |
2284 | indx = i<2 ? 2*i : 2*i+1; | |
2285 | fSegmentation[cath]->SetHit(par[indx],par[indx+1],fZpad); | |
2286 | if (fNpar == 2) coef = 1; | |
2287 | else coef = i==fNpar/3 ? par[indx+2] : 1-coef; | |
2288 | if (fNpar == 8 && i < 2) coef = i==1 ? coef*par[indx+2] : coef - par[7]; | |
2289 | charge += fResponse->IntXY(fSegmentation[cath])*coef; | |
2290 | } | |
2291 | charge *= fQtot; | |
2292 | fXyq[2][j] -= charge; | |
2293 | } // if (fNpar != 0) | |
2294 | if (fXyq[2][j] > fResponse->ZeroSuppression()) fPadIJ[1][j] = 0; // return pad for further using | |
2295 | } // for (Int_t j=0; | |
2296 | } | |
2297 | ||
2298 | //_____________________________________________________________________________ | |
30178c30 | 2299 | Bool_t AliMUONClusterFinderAZ::TestTrack(Int_t /*t*/) const { |
0df3ca52 | 2300 | // Test if track was user selected |
2301 | return kTRUE; | |
2302 | /* | |
2303 | if (fTrack[0]==-1 || fTrack[1]==-1) { | |
2304 | return kTRUE; | |
2305 | } else if (t==fTrack[0] || t==fTrack[1]) { | |
2306 | return kTRUE; | |
2307 | } else { | |
2308 | return kFALSE; | |
2309 | } | |
2310 | */ | |
2311 | } | |
2312 | ||
2313 | //_____________________________________________________________________________ | |
2314 | void AliMUONClusterFinderAZ::AddRawCluster(Double_t x, Double_t y, Double_t fmin) | |
2315 | { | |
2316 | // | |
2317 | // Add a raw cluster copy to the list | |
2318 | // | |
2319 | AliMUONRawCluster cnew; | |
2320 | AliMUON *pMUON=(AliMUON*)gAlice->GetModule("MUON"); | |
2321 | //pMUON->AddRawCluster(fInput->Chamber(),c); | |
2322 | ||
2323 | Int_t cath; | |
2324 | for (cath=0; cath<2; cath++) { | |
ba12c242 | 2325 | cnew.SetX(cath, x); |
2326 | cnew.SetY(cath, y); | |
2327 | cnew.SetZ(cath, fZpad); | |
2328 | cnew.SetCharge(cath, 100); | |
9e993f2a | 2329 | cnew.SetPeakSignal(cath,20); |
2330 | cnew.SetMultiplicity(cath, 5); | |
3b5272e3 | 2331 | cnew.SetNcluster(cath, 1); |
2332 | cnew.SetChi2(cath, fmin); //0.1; | |
0df3ca52 | 2333 | /* |
2334 | cnew.fMultiplicity[cath]=c->fMultiplicity[cath]; | |
2335 | for (i=0; i<fMul[cath]; i++) { | |
2336 | cnew.fIndexMap[i][cath]=c->fIndexMap[i][cath]; | |
2337 | fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]); | |
2338 | } | |
2339 | fprintf(stderr,"\nRawCluster %d cath %d\n",ico,cath); | |
2340 | fprintf(stderr,"mult_av %d\n",c->fMultiplicity[cath]); | |
2341 | FillCluster(&cnew,cath); | |
2342 | */ | |
2343 | } | |
2344 | //cnew.fClusterType=cnew.PhysicsContribution(); | |
ce3f5e87 | 2345 | pMUON->GetMUONData()->AddRawCluster(AliMUONClusterInput::Instance()->Chamber(),cnew); |
0df3ca52 | 2346 | //fNPeaks++; |
2347 | } | |
2348 | ||
2349 | //_____________________________________________________________________________ | |
2350 | Int_t AliMUONClusterFinderAZ::FindLocalMaxima(Int_t *localMax, Double_t *maxVal) | |
2351 | { | |
2352 | // Find local maxima in pixel space for large preclusters in order to | |
2353 | // try to split them into smaller pieces (to speed up the MLEM procedure) | |
2354 | ||
2355 | TH2D *hist = (TH2D*) gROOT->FindObject("anode"); | |
2356 | if (hist) hist->Delete(); | |
2357 | ||
cd747ddb | 2358 | Double_t xylim[4] = {999, 999, 999, 999}; |
0df3ca52 | 2359 | Int_t nPix = fPixArray->GetEntriesFast(); |
2360 | AliMUONPixel *pixPtr = 0; | |
2361 | for (Int_t ipix=0; ipix<nPix; ipix++) { | |
2362 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(ipix); | |
2363 | for (Int_t i=0; i<4; i++) | |
2364 | xylim[i] = TMath::Min (xylim[i], (i%2 ? -1 : 1)*pixPtr->Coord(i/2)); | |
2365 | } | |
2366 | for (Int_t i=0; i<4; i++) xylim[i] -= pixPtr->Size(i/2); | |
2367 | ||
2368 | Int_t nx = TMath::Nint ((-xylim[1]-xylim[0])/pixPtr->Size(0)/2); | |
2369 | Int_t ny = TMath::Nint ((-xylim[3]-xylim[2])/pixPtr->Size(1)/2); | |
2370 | hist = new TH2D("anode","anode",nx,xylim[0],-xylim[1],ny,xylim[2],-xylim[3]); | |
2371 | for (Int_t ipix=0; ipix<nPix; ipix++) { | |
2372 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(ipix); | |
2373 | hist->Fill(pixPtr->Coord(0), pixPtr->Coord(1), pixPtr->Charge()); | |
2374 | } | |
2375 | if (fDraw) { | |
2376 | ((TCanvas*)gROOT->FindObject("c2"))->cd(); | |
2377 | gPad->SetTheta(55); | |
2378 | gPad->SetPhi(30); | |
2379 | hist->Draw("lego1Fb"); | |
2380 | gPad->Update(); | |
2381 | int ia; | |
2382 | cin >> ia; | |
2383 | } | |
2384 | ||
2385 | Int_t nMax = 0, indx; | |
2386 | Int_t *isLocalMax = new Int_t[ny*nx]; | |
2387 | for (Int_t i=0; i<ny*nx; i++) isLocalMax[i] = 0; | |
2388 | ||
2389 | for (Int_t i=1; i<=ny; i++) { | |
2390 | indx = (i-1) * nx; | |
2391 | for (Int_t j=1; j<=nx; j++) { | |
2392 | if (hist->GetCellContent(j,i) < 0.5) continue; | |
2393 | //if (isLocalMax[indx+j-1] < 0) continue; | |
2394 | if (isLocalMax[indx+j-1] != 0) continue; | |
2395 | FlagLocalMax(hist, i, j, isLocalMax); | |
2396 | } | |
2397 | } | |
2398 | ||
2399 | for (Int_t i=1; i<=ny; i++) { | |
2400 | indx = (i-1) * nx; | |
2401 | for (Int_t j=1; j<=nx; j++) { | |
2402 | if (isLocalMax[indx+j-1] > 0) { | |
2403 | localMax[nMax] = indx + j - 1; | |
2404 | maxVal[nMax++] = hist->GetCellContent(j,i); | |
2405 | } | |
2406 | if (nMax > 99) { cout << " Too many local maxima !!!" << endl; ::exit(0); } | |
2407 | } | |
2408 | } | |
2409 | cout << " Local max: " << nMax << endl; | |
2410 | delete [] isLocalMax; isLocalMax = 0; | |
2411 | return nMax; | |
2412 | } | |
2413 | ||
2414 | //_____________________________________________________________________________ | |
2415 | void AliMUONClusterFinderAZ::FlagLocalMax(TH2D *hist, Int_t i, Int_t j, Int_t *isLocalMax) | |
2416 | { | |
2417 | // Flag pixels (whether or not local maxima) | |
2418 | ||
2419 | Int_t nx = hist->GetNbinsX(); | |
2420 | Int_t ny = hist->GetNbinsY(); | |
2421 | Int_t cont = TMath::Nint (hist->GetCellContent(j,i)); | |
2422 | Int_t cont1 = 0; | |
2423 | ||
2424 | for (Int_t i1=i-1; i1<i+2; i1++) { | |
2425 | if (i1 < 1 || i1 > ny) continue; | |
2426 | for (Int_t j1=j-1; j1<j+2; j1++) { | |
2427 | if (j1 < 1 || j1 > nx) continue; | |
2428 | if (i == i1 && j == j1) continue; | |
2429 | cont1 = TMath::Nint (hist->GetCellContent(j1,i1)); | |
2430 | if (cont < cont1) { isLocalMax[(i-1)*nx+j-1] = -1; return; } | |
2431 | else if (cont > cont1) isLocalMax[(i1-1)*nx+j1-1] = -1; | |
2432 | else { // the same charge | |
2433 | isLocalMax[(i-1)*nx+j-1] = 1; | |
2434 | if (isLocalMax[(i1-1)*nx+j1-1] == 0) { | |
2435 | FlagLocalMax(hist, i1, j1, isLocalMax); | |
2436 | if (isLocalMax[(i1-1)*nx+j1-1] < 0) { isLocalMax[(i-1)*nx+j-1] = -1; return; } | |
2437 | else isLocalMax[(i1-1)*nx+j1-1] = -1; | |
2438 | } | |
2439 | } | |
2440 | } | |
2441 | } | |
2442 | isLocalMax[(i-1)*nx+j-1] = 1; // local maximum | |
2443 | } | |
2444 | ||
2445 | //_____________________________________________________________________________ | |
2446 | void AliMUONClusterFinderAZ::FindCluster(Int_t *localMax, Int_t iMax) | |
2447 | { | |
2448 | // Find pixel cluster around local maximum #iMax and pick up pads | |
2449 | // overlapping with it | |
2450 | ||
2451 | TH2D *hist = (TH2D*) gROOT->FindObject("anode"); | |
2452 | Int_t nx = hist->GetNbinsX(); | |
2453 | Int_t ny = hist->GetNbinsY(); | |
2454 | Int_t ic = localMax[iMax] / nx + 1; | |
2455 | Int_t jc = localMax[iMax] % nx + 1; | |
2456 | Bool_t *used = new Bool_t[ny*nx]; | |
2457 | for (Int_t i=0; i<ny*nx; i++) used[i] = kFALSE; | |
2458 | ||
2459 | // Drop all pixels from the array - pick up only the ones from the cluster | |
2460 | fPixArray->Delete(); | |
2461 | ||
2462 | Double_t wx = hist->GetXaxis()->GetBinWidth(1)/2; | |
2463 | Double_t wy = hist->GetYaxis()->GetBinWidth(1)/2; | |
2464 | Double_t yc = hist->GetYaxis()->GetBinCenter(ic); | |
2465 | Double_t xc = hist->GetXaxis()->GetBinCenter(jc); | |
2466 | Double_t cont = hist->GetCellContent(jc,ic); | |
2467 | AliMUONPixel *pixPtr = new AliMUONPixel (xc, yc, wx, wy, cont); | |
2468 | fPixArray->Add((TObject*)pixPtr); | |
2469 | used[(ic-1)*nx+jc-1] = kTRUE; | |
2470 | AddBin(hist, ic, jc, 1, used, (TObjArray*)0); // recursive call | |
2471 | ||
2472 | Int_t nPix = fPixArray->GetEntriesFast(), npad = fnPads[0] + fnPads[1]; | |
2473 | for (Int_t i=0; i<nPix; i++) { | |
2474 | ((AliMUONPixel*)fPixArray->UncheckedAt(i))->SetSize(0,wx); | |
2475 | ((AliMUONPixel*)fPixArray->UncheckedAt(i))->SetSize(1,wy); | |
2476 | } | |
2477 | cout << iMax << " " << nPix << endl; | |
2478 | ||
2479 | Float_t xy[4], xy12[4]; | |
2480 | // Pick up pads which overlap with found pixels | |
2481 | for (Int_t i=0; i<npad; i++) fPadIJ[1][i] = -1; | |
2482 | for (Int_t i=0; i<nPix; i++) { | |
2483 | pixPtr = (AliMUONPixel*) fPixArray->UncheckedAt(i); | |
2484 | for (Int_t j=0; j<4; j++) | |
2485 | xy[j] = pixPtr->Coord(j/2) + (j%2 ? 1 : -1)*pixPtr->Size(j/2); | |
2486 | for (Int_t j=0; j<npad; j++) | |
2487 | if (Overlap(xy, j, xy12, 0)) fPadIJ[1][j] = 0; // flag for use | |
2488 | } | |
2489 | ||
2490 | delete [] used; used = 0; | |
2491 | } | |
30178c30 | 2492 | |
2493 | //_____________________________________________________________________________ | |
2494 | AliMUONClusterFinderAZ& | |
2495 | AliMUONClusterFinderAZ::operator=(const AliMUONClusterFinderAZ& rhs) | |
2496 | { | |
2497 | // Protected assignement operator | |
2498 | ||
2499 | if (this == &rhs) return *this; | |
2500 | ||
2501 | Fatal("operator=", "Not implemented."); | |
2502 | ||
2503 | return *this; | |
2504 | } | |
2505 |