]>
Commit | Line | Data |
---|---|---|
8265fa96 | 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 | ||
8265fa96 | 16 | |
17 | #include "AliRICHClusterFinder.h" | |
543d5224 | 18 | #include "AliRICHMap.h" |
9d6f9427 | 19 | #include <TMinuit.h> |
ed3ceb24 | 20 | #include <TParticle.h> |
9d6f9427 | 21 | #include <TVector3.h> |
cbaf35fb | 22 | #include <AliLoader.h> |
ed3ceb24 | 23 | #include <AliStack.h> |
cbaf35fb | 24 | #include <AliRun.h> |
8265fa96 | 25 | |
9d6f9427 | 26 | void RICHMinMathieson(Int_t &npar, Double_t *gin, Double_t &chi2, Double_t *par, Int_t iflag); |
8265fa96 | 27 | |
28 | ClassImp(AliRICHClusterFinder) | |
543d5224 | 29 | //__________________________________________________________________________________________________ |
30 | AliRICHClusterFinder::AliRICHClusterFinder(AliRICH *pRICH) | |
31 | {//main ctor | |
0f72f306 | 32 | // Info("main ctor","Start."); |
543d5224 | 33 | |
cbaf35fb | 34 | fRICH = pRICH; |
543d5224 | 35 | |
6865fb8d | 36 | fHitMap = 0; |
37 | fRawCluster.Reset(); | |
38 | fResolvedCluster.Reset(); | |
543d5224 | 39 | |
543d5224 | 40 | }//main ctor |
41 | //__________________________________________________________________________________________________ | |
9d6f9427 | 42 | void AliRICHClusterFinder::FindLocalMaxima() |
6865fb8d | 43 | { |
44 | // Find number of local maxima in the cluster | |
0f72f306 | 45 | // Info("FindLocalMaxima","Start."); |
6865fb8d | 46 | |
47 | fNlocals = 0; | |
48 | for(Int_t iDig1=0;iDig1<fRawCluster.Size();iDig1++) { | |
cbaf35fb | 49 | Int_t iNotMax = 0; |
6865fb8d | 50 | AliRICHdigit *pDig1 = (AliRICHdigit *)fRawCluster.Digits()->At(iDig1); |
cbaf35fb | 51 | Int_t padX1 = pDig1->X(); |
52 | Int_t padY1 = pDig1->Y(); | |
6865fb8d | 53 | Int_t padQ1 = (Int_t)(pDig1->Q()+0.1); |
d4c94996 | 54 | Int_t padC1 = pDig1->ChFbMi(); |
6865fb8d | 55 | for(Int_t iDig2=0;iDig2<fRawCluster.Size();iDig2++) { |
56 | AliRICHdigit *pDig2 = (AliRICHdigit *)fRawCluster.Digits()->At(iDig2); | |
cbaf35fb | 57 | Int_t padX2 = pDig2->X(); |
58 | Int_t padY2 = pDig2->Y(); | |
6865fb8d | 59 | Int_t padQ2 = (Int_t)(pDig2->Q()+0.1); |
cbaf35fb | 60 | if(iDig1==iDig2) continue; |
61 | Int_t diffx = TMath::Sign(padX1-padX2,1); | |
62 | Int_t diffy = TMath::Sign(padY1-padY2,1); | |
63 | if((diffx+diffy)<=1) { | |
6865fb8d | 64 | if(padQ2>=padQ1) iNotMax++; |
cbaf35fb | 65 | } |
8265fa96 | 66 | } |
cbaf35fb | 67 | if(iNotMax==0) { |
3582c1f9 | 68 | TVector2 x2=AliRICHParam::Pad2Loc(padX1,padY1); |
69 | fLocalX[fNlocals]=x2.X();fLocalY[fNlocals]=x2.Y(); | |
6865fb8d | 70 | fLocalQ[fNlocals] = (Double_t)padQ1; |
71 | fLocalC[fNlocals] = padC1; | |
72 | fNlocals++; | |
8265fa96 | 73 | } |
6865fb8d | 74 | } |
cbaf35fb | 75 | }//FindLocalMaxima() |
543d5224 | 76 | //__________________________________________________________________________________________________ |
77 | void AliRICHClusterFinder::Exec() | |
237c933d | 78 | { |
543d5224 | 79 | Info("Exec","Start."); |
80 | ||
cbaf35fb | 81 | |
543d5224 | 82 | Rich()->GetLoader()->LoadDigits(); |
83 | ||
ed3ceb24 | 84 | Rich()->GetLoader()->GetRunLoader()->LoadHeader(); |
85 | Rich()->GetLoader()->GetRunLoader()->LoadKinematics(); | |
86 | ||
543d5224 | 87 | for(Int_t iEventN=0;iEventN<gAlice->GetEventsPerRun();iEventN++){//events loop |
0f72f306 | 88 | Info("Exec","Event %i processed.",iEventN+1); |
6865fb8d | 89 | // gAlice->GetRunLoader()->GetEvent(iEventN); |
90 | Rich()->GetLoader()->GetRunLoader()->GetEvent(iEventN); | |
237c933d | 91 | |
543d5224 | 92 | Rich()->GetLoader()->MakeTree("R"); Rich()->MakeBranch("R"); |
cbaf35fb | 93 | Rich()->ResetDigits(); Rich()->ResetClusters(); |
543d5224 | 94 | |
95 | Rich()->GetLoader()->TreeD()->GetEntry(0); | |
cbaf35fb | 96 | for(Int_t iChamber=1;iChamber<=kNCH;iChamber++){//chambers loop |
ed3ceb24 | 97 | FindClusters(iChamber); |
543d5224 | 98 | }//chambers loop |
543d5224 | 99 | Rich()->GetLoader()->TreeR()->Fill(); |
100 | Rich()->GetLoader()->WriteRecPoints("OVERWRITE"); | |
101 | }//events loop | |
102 | Rich()->GetLoader()->UnloadDigits(); Rich()->GetLoader()->UnloadRecPoints(); | |
cbaf35fb | 103 | Rich()->ResetDigits(); Rich()->ResetClusters(); |
ed3ceb24 | 104 | |
105 | Rich()->GetLoader()->GetRunLoader()->UnloadHeader(); | |
106 | Rich()->GetLoader()->GetRunLoader()->UnloadKinematics(); | |
107 | ||
543d5224 | 108 | Info("Exec","Stop."); |
109 | }//Exec() | |
110 | //__________________________________________________________________________________________________ | |
ed3ceb24 | 111 | void AliRICHClusterFinder::FindClusters(Int_t iChamber) |
112 | { | |
113 | //finds neighbours and fill the tree with raw clusters | |
cbaf35fb | 114 | Int_t nDigits=Rich()->Digits(iChamber)->GetEntriesFast(); |
0f72f306 | 115 | // Info("FindClusters","Start for Chamber %i with %i digits.",iChamber,nDigits); |
cbaf35fb | 116 | if(nDigits==0)return; |
117 | ||
eaf390d9 | 118 | fHitMap=new AliRICHMap(Rich()->Digits(iChamber));//create digit map for the given chamber |
cbaf35fb | 119 | |
cbaf35fb | 120 | for(Int_t iDig=0;iDig<nDigits;iDig++){ |
e33758d8 | 121 | AliRICHdigit *dig=(AliRICHdigit*)Rich()->Digits(iChamber)->At(iDig); |
cbaf35fb | 122 | Int_t i=dig->X(); Int_t j=dig->Y(); |
123 | if(fHitMap->TestHit(i,j)==kUsed) continue; | |
124 | ||
9d6f9427 | 125 | FormRawCluster(i,j); |
6865fb8d | 126 | FindLocalMaxima(); |
127 | // cout << " fNlocals in FindCluster " << fNlocals << endl; | |
128 | fRawCluster.CoG(fNlocals); // first initial approxmation of the CoG...to start minimization. | |
129 | ||
cbaf35fb | 130 | if(AliRICHParam::IsResolveClusters()) { |
9d6f9427 | 131 | ResolveCluster(); // ResolveCluster serialization will happen inside |
cbaf35fb | 132 | } else { |
9d6f9427 | 133 | WriteRawCluster(); // simply output of the RawCluster found without deconvolution |
ed3ceb24 | 134 | } |
6865fb8d | 135 | fRawCluster.Reset(); |
136 | fResolvedCluster.Reset(); | |
cbaf35fb | 137 | }//digits loop |
138 | ||
139 | delete fHitMap; | |
0f72f306 | 140 | // Info("FindClusters","Stop."); |
cbaf35fb | 141 | |
ed3ceb24 | 142 | }//FindClusters() |
143 | //__________________________________________________________________________________________________ | |
6865fb8d | 144 | void AliRICHClusterFinder::FindClusterContribs(AliRICHcluster *pCluster) |
ed3ceb24 | 145 | { |
3582c1f9 | 146 | // finds CombiPid for a given cluster |
147 | // Info("FindClusterContribs","Start"); | |
ed3ceb24 | 148 | |
6865fb8d | 149 | TObjArray *pDigits = pCluster->Digits(); |
ed3ceb24 | 150 | Int_t iNmips=0,iNckovs=0,iNfeeds=0; |
6865fb8d | 151 | TArrayI contribs(3*pCluster->Size()); |
152 | Int_t *pindex = new Int_t[3*pCluster->Size()]; | |
153 | for(Int_t iDigN=0;iDigN<pCluster->Size();iDigN++) {//loop on digits of a given cluster | |
ed3ceb24 | 154 | contribs[3*iDigN] =((AliRICHdigit*)pDigits->At(iDigN))->Tid(0); |
155 | contribs[3*iDigN+1]=((AliRICHdigit*)pDigits->At(iDigN))->Tid(1); | |
156 | contribs[3*iDigN+2]=((AliRICHdigit*)pDigits->At(iDigN))->Tid(2); | |
ed3ceb24 | 157 | }//loop on digits of a given cluster |
158 | TMath::Sort(contribs.GetSize(),contribs.GetArray(),pindex); | |
6865fb8d | 159 | for(Int_t iDigN=0;iDigN<3*pCluster->Size()-1;iDigN++) {//loop on digits to sort Tid |
ed3ceb24 | 160 | if(contribs[pindex[iDigN]]!=contribs[pindex[iDigN+1]]) { |
161 | Int_t code = Rich()->GetLoader()->GetRunLoader()->Stack()->Particle(contribs[pindex[iDigN]])->GetPdgCode(); | |
162 | Double_t charge = Rich()->GetLoader()->GetRunLoader()->Stack()->Particle(contribs[pindex[iDigN]])->GetPDG()->Charge(); | |
163 | ||
164 | if(code==50000050) iNckovs++; | |
165 | else if(code==50000051) iNfeeds++; | |
166 | else if(charge!=0) iNmips++; | |
167 | if (contribs[pindex[iDigN+1]]==kBad) break; | |
168 | } | |
169 | }//loop on digits to sort Tid | |
6865fb8d | 170 | pCluster->SetCombiPid(iNckovs,iNfeeds,iNmips); |
171 | // pCluster->Print(); | |
ed3ceb24 | 172 | delete [] pindex; |
3582c1f9 | 173 | }//FindClusterContribs() |
cbaf35fb | 174 | //__________________________________________________________________________________________________ |
9d6f9427 | 175 | void AliRICHClusterFinder::FormRawCluster(Int_t i, Int_t j) |
ed3ceb24 | 176 | { |
3582c1f9 | 177 | // Builder of the final Raw Cluster (before deconvolution) |
178 | if(GetDebug()) Info("FormRawCluster","Start with digit(%i,%i)",i,j); | |
cbaf35fb | 179 | |
6865fb8d | 180 | fRawCluster.AddDigit((AliRICHdigit*) fHitMap->GetHit(i,j)); |
cbaf35fb | 181 | fHitMap->FlagHit(i,j);// Flag hit as taken |
182 | ||
183 | Int_t listX[4], listY[4]; // Now look recursively for all neighbours | |
d4c94996 | 184 | for (Int_t iNeighbour=0;iNeighbour<Rich()->P()->PadNeighbours(i,j,listX,listY);iNeighbour++) |
cbaf35fb | 185 | if(fHitMap->TestHit(listX[iNeighbour],listY[iNeighbour])==kUnused) |
9d6f9427 | 186 | FormRawCluster(listX[iNeighbour],listY[iNeighbour]); |
3582c1f9 | 187 | }//FormRawCluster() |
cbaf35fb | 188 | //__________________________________________________________________________________________________ |
9d6f9427 | 189 | void AliRICHClusterFinder::ResolveCluster() |
cbaf35fb | 190 | {// Decluster algorithm |
3582c1f9 | 191 | if(GetDebug()) {Info("ResolveCluster","Start."); fRawCluster.Print();} |
cbaf35fb | 192 | |
6865fb8d | 193 | switch (fRawCluster.Size()) { |
194 | ||
195 | case 1: // nothing to decluster: cluster size = 1 | |
196 | WriteRawCluster();break; | |
197 | default: // cluster size > 1: if=2 FitCoG; if>2 Resolve and FitCoG | |
198 | FitCoG();break; | |
9d6f9427 | 199 | } |
cbaf35fb | 200 | }//ResolveCluster() |
201 | //__________________________________________________________________________________________________ | |
9d6f9427 | 202 | void AliRICHClusterFinder::WriteRawCluster() |
6865fb8d | 203 | { |
204 | // out the current raw cluster | |
09c52ebc | 205 | Info("WriteRawCluster","Start."); |
cbaf35fb | 206 | |
6865fb8d | 207 | FindClusterContribs(&fRawCluster); |
09c52ebc | 208 | fRawCluster.Dump(); |
6865fb8d | 209 | Rich()->AddCluster(fRawCluster); |
210 | // fRawCluster.Print(); | |
cbaf35fb | 211 | }//WriteRawCluster() |
212 | //__________________________________________________________________________________________________ | |
6865fb8d | 213 | void AliRICHClusterFinder::WriteResolvedCluster() |
214 | { | |
215 | // out the current resolved cluster | |
09c52ebc | 216 | Info("WriteResolvedCluster","Start."); |
6865fb8d | 217 | |
218 | // FindClusterContribs(&fResolvedCluster); | |
219 | Rich()->AddCluster(fResolvedCluster); | |
220 | ||
221 | }//WriteResolvedCluster() | |
222 | //__________________________________________________________________________________________________ | |
9d6f9427 | 223 | void AliRICHClusterFinder::FitCoG() |
224 | {// Fit cluster size 2 by single Mathieson | |
6865fb8d | 225 | Info("FitCoG","Start with size %3i and local maxima %3i",fRawCluster.Size(),fNlocals); |
226 | ||
0f72f306 | 227 | Double_t arglist; |
228 | Int_t ierflag = 0; | |
6865fb8d | 229 | |
230 | // fRawCluster.Print(); | |
231 | if(fNlocals==0) fRawCluster.Print(); | |
232 | if(fNlocals==0||fNlocals>3) {WriteRawCluster();return;} | |
9d6f9427 | 233 | |
6865fb8d | 234 | TMinuit *pMinuit = new TMinuit(3*fNlocals-1); |
0f72f306 | 235 | pMinuit->mninit(5,10,7); |
236 | ||
237 | arglist = -1; | |
238 | pMinuit->mnexcm("SET PRI",&arglist, 1, ierflag); | |
9d6f9427 | 239 | |
9d6f9427 | 240 | TString chname; |
241 | Int_t ierflg; | |
242 | ||
243 | pMinuit->SetObjectFit((TObject*)this); | |
244 | pMinuit->SetFCN(RICHMinMathieson); | |
6865fb8d | 245 | |
246 | Double_t vstart,lower, upper; | |
247 | Double_t stepX= 0.001; | |
248 | Double_t stepY= 0.001; | |
249 | Double_t stepQ= 0.0001; | |
250 | ||
251 | for(Int_t i=0;i<fNlocals;i++) { | |
252 | vstart = fLocalX[i]; | |
253 | lower = vstart - 2*AliRICHParam::PadSizeX(); | |
254 | upper = vstart + 2*AliRICHParam::PadSizeX(); | |
255 | pMinuit->mnparm(3*i ,Form("xCoG %i",i),vstart,stepX,lower,upper,ierflag); | |
256 | // cout << Form("xCoG %i",i) << "start " << vstart << "lower " << lower << "upper " << upper << endl; | |
257 | vstart = fLocalY[i]; | |
258 | lower = vstart - 2*AliRICHParam::PadSizeY(); | |
259 | upper = vstart + 2*AliRICHParam::PadSizeY(); | |
260 | pMinuit->mnparm(3*i+1,Form("yCoG %i",i),vstart,stepY,lower,upper,ierflag); | |
261 | // cout << Form("yCoG %i",i) << "start " << vstart << "lower " << lower << "upper " << upper << endl; | |
262 | if(i==fNlocals-1) break; // last parameter is constrained | |
263 | vstart = fLocalQ[i]/fRawCluster.Q(); | |
264 | lower = 0; | |
265 | upper = 1; | |
266 | pMinuit->mnparm(3*i+2,Form("qfrac %i",i),vstart,stepQ,lower,upper,ierflag); | |
267 | // cout << Form("qCoG %i",i) << "start " << vstart << "lower " << lower << "upper " << upper << endl; | |
9d6f9427 | 268 | |
6865fb8d | 269 | } |
270 | ||
9d6f9427 | 271 | arglist = -1; |
6865fb8d | 272 | |
9d6f9427 | 273 | pMinuit->mnexcm("SET NOGR",&arglist, 1, ierflag); |
274 | pMinuit->mnexcm("SET NOW",&arglist, 1, ierflag); | |
275 | arglist = 1; | |
276 | pMinuit->mnexcm("SET ERR", &arglist, 1,ierflg); | |
277 | arglist = -1; | |
278 | pMinuit->mnexcm("SIMPLEX",&arglist, 0, ierflag); | |
279 | pMinuit->mnexcm("MIGRAD",&arglist, 0, ierflag); | |
6865fb8d | 280 | pMinuit->mnexcm("EXIT" ,&arglist, 0, ierflag); |
281 | ||
282 | Double_t xCoG[50],yCoG[50],qfracCoG[50]; | |
9d6f9427 | 283 | Double_t eps, b1, b2; |
6865fb8d | 284 | |
285 | Double_t qfraclast=0; | |
286 | for(Int_t i=0;i<fNlocals;i++) { | |
287 | pMinuit->mnpout(3*i ,chname, xCoG[i], eps , b1, b2, ierflg); | |
288 | pMinuit->mnpout(3*i+1,chname, yCoG[i], eps , b1, b2, ierflg); | |
289 | if(i==fNlocals-1) break; | |
290 | pMinuit->mnpout(3*i+2,chname, qfracCoG[i], eps , b1, b2, ierflg); | |
291 | qfraclast+=qfracCoG[i]; | |
292 | } | |
293 | qfracCoG[fNlocals-1] = 1 - qfraclast; | |
9d6f9427 | 294 | delete pMinuit; |
6865fb8d | 295 | |
296 | for(Int_t i=0;i<fNlocals;i++) { | |
297 | ||
298 | if(fNlocals==5) { | |
299 | cout << " Start writing deconvolved cluster n." << i << endl; | |
300 | cout << " fRawCluster " << &fRawCluster << " xCoG " << xCoG[i] << " yCoG " << yCoG[i] << " qfrac " << qfracCoG[i] << endl; | |
301 | cout << " Combipid " << fLocalC[i] << " for maximum n. " << i << endl; | |
302 | } | |
303 | fResolvedCluster.Fill(&fRawCluster,xCoG[i],yCoG[i],qfracCoG[i],fLocalC[i]); | |
304 | // fResolvedCluster.Print(); | |
305 | WriteResolvedCluster(); | |
306 | } | |
307 | if(fNlocals==5) Info("CoG","Stop."); | |
09c52ebc | 308 | }//FitCoG() |
9d6f9427 | 309 | //__________________________________________________________________________________________________ |
6865fb8d | 310 | void RICHMinMathieson(Int_t &npar, Double_t *, Double_t &chi2, Double_t *par, Int_t ) |
09c52ebc | 311 | { |
312 | // Mathieson minimization function | |
9d6f9427 | 313 | |
6865fb8d | 314 | AliRICHcluster *pRawCluster = ((AliRICHClusterFinder*)gMinuit->GetObjectFit())->GetRawCluster(); |
9d6f9427 | 315 | |
3582c1f9 | 316 | TVector2 centroid[50]; |
6865fb8d | 317 | Double_t q[50]; |
318 | Int_t nFunctions = (npar+1)/3; | |
319 | Double_t qfract = 0; | |
320 | for(Int_t i=0;i<nFunctions;i++) { | |
3582c1f9 | 321 | centroid[i].Set(par[3*i],par[3*i+1]); |
6865fb8d | 322 | if(i==nFunctions-1) break; |
323 | q[i]=par[3*i+2]; | |
324 | qfract+=q[i]; | |
325 | } | |
326 | q[nFunctions-1] = 1 - qfract; | |
327 | ||
9d6f9427 | 328 | chi2 = 0; |
329 | Int_t qtot = pRawCluster->Q(); | |
330 | for(Int_t i=0;i<pRawCluster->Size();i++) { | |
331 | Int_t padX = ((AliRICHdigit *)pRawCluster->Digits()->At(i))->X(); | |
332 | Int_t padY = ((AliRICHdigit *)pRawCluster->Digits()->At(i))->Y(); | |
333 | Double_t padQ = ((AliRICHdigit *)pRawCluster->Digits()->At(i))->Q(); | |
6865fb8d | 334 | Double_t qfracpar=0; |
335 | for(Int_t j=0;j<nFunctions;j++) { | |
3582c1f9 | 336 | qfracpar += q[j]*AliRICHParam::FracQdc(centroid[j],padX,padY); |
337 | // cout << " function n. " << j+1 << " q " << q[j] << " fracMat " << AliRICHParam::FracQdc(centroid[j],padX,padY) | |
6865fb8d | 338 | // << " xpar " << centroid[j].X() << " ypar " << centroid[j].Y() << endl; |
9d6f9427 | 339 | } |
6865fb8d | 340 | chi2 += TMath::Power((qtot*qfracpar-padQ),2)/padQ; |
341 | // cout << " chi2 " << chi2 << " pad n. " << i << " qfracpar " << qfracpar << endl; | |
342 | } | |
343 | // if(iflag==3) { | |
344 | // cout << " chi2 final " << chi2 << endl; | |
345 | // } | |
9d6f9427 | 346 | }//RICHMinMathieson() |