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 | |
cbaf35fb |
36 | fHitMap = 0; |
543d5224 |
37 | |
543d5224 |
38 | }//main ctor |
39 | //__________________________________________________________________________________________________ |
9d6f9427 |
40 | void AliRICHClusterFinder::FindLocalMaxima() |
543d5224 |
41 | {// Split the cluster according to the number of maxima inside |
0f72f306 |
42 | // Info("FindLocalMaxima","Start."); |
cbaf35fb |
43 | Int_t Nlocal = 0; |
44 | Int_t localX[100],localY[100]; |
9d6f9427 |
45 | for(Int_t iDig1=0;iDig1<fCurrentCluster.Size();iDig1++) { |
cbaf35fb |
46 | Int_t iNotMax = 0; |
9d6f9427 |
47 | AliRICHdigit *pDig1 = (AliRICHdigit *)fCurrentCluster.Digits()->At(iDig1); |
cbaf35fb |
48 | Int_t padX1 = pDig1->X(); |
49 | Int_t padY1 = pDig1->Y(); |
50 | Double_t padQ1 = pDig1->Q(); |
9d6f9427 |
51 | for(Int_t iDig2=0;iDig2<fCurrentCluster.Size();iDig2++) { |
52 | AliRICHdigit *pDig2 = (AliRICHdigit *)fCurrentCluster.Digits()->At(iDig2); |
cbaf35fb |
53 | Int_t padX2 = pDig2->X(); |
54 | Int_t padY2 = pDig2->Y(); |
55 | Double_t padQ2 = pDig2->Q(); |
56 | if(iDig1==iDig2) continue; |
57 | Int_t diffx = TMath::Sign(padX1-padX2,1); |
58 | Int_t diffy = TMath::Sign(padY1-padY2,1); |
59 | if((diffx+diffy)<=1) { |
60 | if(padQ2>padQ1) iNotMax++; |
61 | } |
8265fa96 |
62 | } |
cbaf35fb |
63 | if(iNotMax==0) { |
64 | localX[Nlocal] = padX1; |
65 | localY[Nlocal] = padY1; |
66 | Nlocal++; |
8265fa96 |
67 | } |
cbaf35fb |
68 | } |
69 | }//FindLocalMaxima() |
543d5224 |
70 | //__________________________________________________________________________________________________ |
71 | void AliRICHClusterFinder::Exec() |
237c933d |
72 | { |
543d5224 |
73 | Info("Exec","Start."); |
74 | |
cbaf35fb |
75 | |
543d5224 |
76 | Rich()->GetLoader()->LoadDigits(); |
77 | |
ed3ceb24 |
78 | Rich()->GetLoader()->GetRunLoader()->LoadHeader(); |
79 | Rich()->GetLoader()->GetRunLoader()->LoadKinematics(); |
80 | |
543d5224 |
81 | for(Int_t iEventN=0;iEventN<gAlice->GetEventsPerRun();iEventN++){//events loop |
0f72f306 |
82 | Info("Exec","Event %i processed.",iEventN+1); |
543d5224 |
83 | gAlice->GetRunLoader()->GetEvent(iEventN); |
237c933d |
84 | |
543d5224 |
85 | Rich()->GetLoader()->MakeTree("R"); Rich()->MakeBranch("R"); |
cbaf35fb |
86 | Rich()->ResetDigits(); Rich()->ResetClusters(); |
543d5224 |
87 | |
88 | Rich()->GetLoader()->TreeD()->GetEntry(0); |
cbaf35fb |
89 | for(Int_t iChamber=1;iChamber<=kNCH;iChamber++){//chambers loop |
ed3ceb24 |
90 | FindClusters(iChamber); |
543d5224 |
91 | }//chambers loop |
543d5224 |
92 | Rich()->GetLoader()->TreeR()->Fill(); |
93 | Rich()->GetLoader()->WriteRecPoints("OVERWRITE"); |
94 | }//events loop |
95 | Rich()->GetLoader()->UnloadDigits(); Rich()->GetLoader()->UnloadRecPoints(); |
cbaf35fb |
96 | Rich()->ResetDigits(); Rich()->ResetClusters(); |
ed3ceb24 |
97 | |
98 | Rich()->GetLoader()->GetRunLoader()->UnloadHeader(); |
99 | Rich()->GetLoader()->GetRunLoader()->UnloadKinematics(); |
100 | |
543d5224 |
101 | Info("Exec","Stop."); |
102 | }//Exec() |
103 | //__________________________________________________________________________________________________ |
ed3ceb24 |
104 | void AliRICHClusterFinder::FindClusters(Int_t iChamber) |
105 | { |
106 | //finds neighbours and fill the tree with raw clusters |
cbaf35fb |
107 | Int_t nDigits=Rich()->Digits(iChamber)->GetEntriesFast(); |
0f72f306 |
108 | // Info("FindClusters","Start for Chamber %i with %i digits.",iChamber,nDigits); |
cbaf35fb |
109 | if(nDigits==0)return; |
110 | |
eaf390d9 |
111 | fHitMap=new AliRICHMap(Rich()->Digits(iChamber));//create digit map for the given chamber |
cbaf35fb |
112 | |
cbaf35fb |
113 | for(Int_t iDig=0;iDig<nDigits;iDig++){ |
e33758d8 |
114 | AliRICHdigit *dig=(AliRICHdigit*)Rich()->Digits(iChamber)->At(iDig); |
cbaf35fb |
115 | Int_t i=dig->X(); Int_t j=dig->Y(); |
116 | if(fHitMap->TestHit(i,j)==kUsed) continue; |
117 | |
9d6f9427 |
118 | FormRawCluster(i,j); |
cbaf35fb |
119 | |
120 | if(AliRICHParam::IsResolveClusters()) { |
9d6f9427 |
121 | ResolveCluster(); // ResolveCluster serialization will happen inside |
cbaf35fb |
122 | } else { |
9d6f9427 |
123 | WriteRawCluster(); // simply output of the RawCluster found without deconvolution |
ed3ceb24 |
124 | } |
9d6f9427 |
125 | fCurrentCluster.Reset(); |
cbaf35fb |
126 | }//digits loop |
127 | |
128 | delete fHitMap; |
0f72f306 |
129 | // Info("FindClusters","Stop."); |
cbaf35fb |
130 | |
ed3ceb24 |
131 | }//FindClusters() |
132 | //__________________________________________________________________________________________________ |
133 | void AliRICHClusterFinder::FindClusterContribs() |
134 | { |
135 | //finds CombiPid for a given cluster |
0f72f306 |
136 | // Info("FindClusterContribs","Start"); |
ed3ceb24 |
137 | |
138 | TObjArray *pDigits = fCurrentCluster.Digits(); |
139 | Int_t iNmips=0,iNckovs=0,iNfeeds=0; |
140 | TArrayI contribs(3*fCurrentCluster.Size()); |
141 | Int_t *pindex = new Int_t[3*fCurrentCluster.Size()]; |
142 | for(Int_t iDigN=0;iDigN<fCurrentCluster.Size();iDigN++) {//loop on digits of a given cluster |
143 | contribs[3*iDigN] =((AliRICHdigit*)pDigits->At(iDigN))->Tid(0); |
144 | contribs[3*iDigN+1]=((AliRICHdigit*)pDigits->At(iDigN))->Tid(1); |
145 | contribs[3*iDigN+2]=((AliRICHdigit*)pDigits->At(iDigN))->Tid(2); |
0f72f306 |
146 | // cout << "TID1 " << contribs[3*iDigN] << " TID2 " << contribs[3*iDigN+1] << " TID3 " << contribs[3*iDigN+2] << endl; |
ed3ceb24 |
147 | }//loop on digits of a given cluster |
148 | TMath::Sort(contribs.GetSize(),contribs.GetArray(),pindex); |
149 | for(Int_t iDigN=0;iDigN<3*fCurrentCluster.Size()-1;iDigN++) {//loop on digits to sort Tid |
0f72f306 |
150 | // cout << " contrib " << contribs[pindex[iDigN]] << " digit " << iDigN << |
151 | // " contrib " << contribs[pindex[iDigN+1]] << " digit " << iDigN+1 << endl; |
ed3ceb24 |
152 | if(contribs[pindex[iDigN]]!=contribs[pindex[iDigN+1]]) { |
153 | Int_t code = Rich()->GetLoader()->GetRunLoader()->Stack()->Particle(contribs[pindex[iDigN]])->GetPdgCode(); |
154 | Double_t charge = Rich()->GetLoader()->GetRunLoader()->Stack()->Particle(contribs[pindex[iDigN]])->GetPDG()->Charge(); |
155 | |
156 | if(code==50000050) iNckovs++; |
157 | else if(code==50000051) iNfeeds++; |
158 | else if(charge!=0) iNmips++; |
159 | if (contribs[pindex[iDigN+1]]==kBad) break; |
160 | } |
161 | }//loop on digits to sort Tid |
162 | fCurrentCluster.SetCombiPid(iNckovs,iNfeeds,iNmips); |
0f72f306 |
163 | // fCurrentCluster.Print(); |
ed3ceb24 |
164 | delete [] pindex; |
165 | }// FindClusterContribs() |
cbaf35fb |
166 | //__________________________________________________________________________________________________ |
9d6f9427 |
167 | void AliRICHClusterFinder::FormRawCluster(Int_t i, Int_t j) |
ed3ceb24 |
168 | { |
169 | // Builder of the final Raw Cluster (before deconvolution) |
0f72f306 |
170 | // Info("FormRawCluster","Start with digit(%i,%i)",i,j); |
cbaf35fb |
171 | |
9d6f9427 |
172 | fCurrentCluster.AddDigit((AliRICHdigit*) fHitMap->GetHit(i,j)); |
cbaf35fb |
173 | fHitMap->FlagHit(i,j);// Flag hit as taken |
174 | |
175 | Int_t listX[4], listY[4]; // Now look recursively for all neighbours |
176 | for (Int_t iNeighbour=0;iNeighbour<Rich()->Param()->PadNeighbours(i,j,listX,listY);iNeighbour++) |
177 | if(fHitMap->TestHit(listX[iNeighbour],listY[iNeighbour])==kUnused) |
9d6f9427 |
178 | FormRawCluster(listX[iNeighbour],listY[iNeighbour]); |
cbaf35fb |
179 | }//AddDigit2Cluster() |
180 | //__________________________________________________________________________________________________ |
9d6f9427 |
181 | void AliRICHClusterFinder::ResolveCluster() |
cbaf35fb |
182 | {// Decluster algorithm |
0f72f306 |
183 | // Info("ResolveCluster","Start."); |
9d6f9427 |
184 | |
185 | fCurrentCluster.CoG(); // first initial approxmation of the CoG...to start minimization. |
0f72f306 |
186 | // fCurrentCluster.Print(); |
9d6f9427 |
187 | switch (fCurrentCluster.Size()) { |
cbaf35fb |
188 | |
9d6f9427 |
189 | case 1: |
190 | WriteRawCluster(); break; |
191 | case 2: |
192 | FitCoG(); |
193 | WriteRawCluster(); break; |
194 | |
195 | default: |
196 | WriteRawCluster(); break; |
197 | } |
cbaf35fb |
198 | }//ResolveCluster() |
199 | //__________________________________________________________________________________________________ |
9d6f9427 |
200 | void AliRICHClusterFinder::WriteRawCluster() |
cbaf35fb |
201 | {// out the current RawCluster |
0f72f306 |
202 | // Info("WriteRawCluster","Start."); |
cbaf35fb |
203 | |
ed3ceb24 |
204 | FindClusterContribs(); |
9d6f9427 |
205 | Rich()->AddCluster(fCurrentCluster); |
cbaf35fb |
206 | |
207 | }//WriteRawCluster() |
208 | //__________________________________________________________________________________________________ |
9d6f9427 |
209 | void AliRICHClusterFinder::FitCoG() |
210 | {// Fit cluster size 2 by single Mathieson |
0f72f306 |
211 | // Info("FitCoG","Start."); |
212 | |
213 | Double_t arglist; |
214 | Int_t ierflag = 0; |
9d6f9427 |
215 | |
216 | TMinuit *pMinuit = new TMinuit(2); |
0f72f306 |
217 | pMinuit->mninit(5,10,7); |
218 | |
219 | arglist = -1; |
220 | pMinuit->mnexcm("SET PRI",&arglist, 1, ierflag); |
9d6f9427 |
221 | |
9d6f9427 |
222 | static Double_t vstart[2]; |
223 | static Double_t lower[2], upper[2]; |
224 | static Double_t step[2]={0.001,0.001}; |
225 | |
226 | TString chname; |
227 | Int_t ierflg; |
228 | |
229 | pMinuit->SetObjectFit((TObject*)this); |
230 | pMinuit->SetFCN(RICHMinMathieson); |
9d6f9427 |
231 | |
232 | vstart[0] = fCurrentCluster.X(); |
233 | vstart[1] = fCurrentCluster.Y(); |
234 | |
235 | lower[0] = vstart[0] - 2*AliRICHParam::PadSizeX(); |
236 | upper[0] = vstart[0] + 2*AliRICHParam::PadSizeX(); |
237 | lower[1] = vstart[1] - 2*AliRICHParam::PadSizeY(); |
238 | upper[1] = vstart[1] + 2*AliRICHParam::PadSizeY(); |
239 | |
240 | |
241 | pMinuit->mnparm(0," x position ",vstart[0],step[0],lower[0],upper[0],ierflag); |
242 | pMinuit->mnparm(1," y position ",vstart[1],step[1],lower[1],upper[1],ierflag); |
243 | |
244 | arglist = -1; |
245 | |
9d6f9427 |
246 | pMinuit->mnexcm("SET NOGR",&arglist, 1, ierflag); |
247 | pMinuit->mnexcm("SET NOW",&arglist, 1, ierflag); |
248 | arglist = 1; |
249 | pMinuit->mnexcm("SET ERR", &arglist, 1,ierflg); |
250 | arglist = -1; |
251 | pMinuit->mnexcm("SIMPLEX",&arglist, 0, ierflag); |
252 | pMinuit->mnexcm("MIGRAD",&arglist, 0, ierflag); |
253 | pMinuit->mnexcm("EXIT" ,&arglist, 0, ierflag); |
254 | Double_t xCoG,yCoG; |
255 | Double_t eps, b1, b2; |
256 | pMinuit->mnpout(0,chname, xCoG, eps , b1, b2, ierflg); |
257 | pMinuit->mnpout(1,chname, yCoG, eps , b1, b2, ierflg); |
258 | delete pMinuit; |
259 | } |
260 | //__________________________________________________________________________________________________ |
261 | void RICHMinMathieson(Int_t &, Double_t *, Double_t &chi2, Double_t *par, Int_t iflag) |
262 | {// Minimization function of Mathieson |
263 | |
264 | AliRICHcluster *pRawCluster = ((AliRICHClusterFinder*)gMinuit->GetObjectFit())->GetCurrentCluster(); |
265 | |
266 | TVector3 centroid(par[0],par[1],0); |
267 | |
268 | chi2 = 0; |
269 | Int_t qtot = pRawCluster->Q(); |
270 | for(Int_t i=0;i<pRawCluster->Size();i++) { |
271 | Int_t padX = ((AliRICHdigit *)pRawCluster->Digits()->At(i))->X(); |
272 | Int_t padY = ((AliRICHdigit *)pRawCluster->Digits()->At(i))->Y(); |
273 | Double_t padQ = ((AliRICHdigit *)pRawCluster->Digits()->At(i))->Q(); |
274 | chi2 += TMath::Power((qtot*AliRICHParam::Loc2PadFrac(centroid,padX,padY)-padQ),2)/padQ; |
275 | } |
276 | if(iflag == 3) |
277 | { |
0f72f306 |
278 | // cout << " --- end convergence...summary --- " << endl; |
279 | // cout << " x position " << par[0] << endl; |
280 | // cout << " y position " << par[1] << endl; |
281 | // cout << " chi2 " << chi2 << endl; |
9d6f9427 |
282 | } |
283 | }//RICHMinMathieson() |