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