1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 #include "AliRICHClusterFinder.h"
18 #include "AliRICHMap.h"
21 #include <AliLoader.h>
24 void RICHMinMathieson(Int_t &npar, Double_t *gin, Double_t &chi2, Double_t *par, Int_t iflag);
26 ClassImp(AliRICHClusterFinder)
27 //__________________________________________________________________________________________________
28 AliRICHClusterFinder::AliRICHClusterFinder(AliRICH *pRICH)
30 Info("main ctor","Start.");
37 //__________________________________________________________________________________________________
38 void AliRICHClusterFinder::FindLocalMaxima()
39 {// Split the cluster according to the number of maxima inside
40 Info("FindLocalMaxima","Start.");
42 Int_t localX[100],localY[100];
43 for(Int_t iDig1=0;iDig1<fCurrentCluster.Size();iDig1++) {
45 AliRICHdigit *pDig1 = (AliRICHdigit *)fCurrentCluster.Digits()->At(iDig1);
46 Int_t padX1 = pDig1->X();
47 Int_t padY1 = pDig1->Y();
48 Double_t padQ1 = pDig1->Q();
49 for(Int_t iDig2=0;iDig2<fCurrentCluster.Size();iDig2++) {
50 AliRICHdigit *pDig2 = (AliRICHdigit *)fCurrentCluster.Digits()->At(iDig2);
51 Int_t padX2 = pDig2->X();
52 Int_t padY2 = pDig2->Y();
53 Double_t padQ2 = pDig2->Q();
54 if(iDig1==iDig2) continue;
55 Int_t diffx = TMath::Sign(padX1-padX2,1);
56 Int_t diffy = TMath::Sign(padY1-padY2,1);
57 if((diffx+diffy)<=1) {
58 if(padQ2>padQ1) iNotMax++;
62 localX[Nlocal] = padX1;
63 localY[Nlocal] = padY1;
68 //__________________________________________________________________________________________________
69 void AliRICHClusterFinder::Exec()
71 Info("Exec","Start.");
74 Rich()->GetLoader()->LoadDigits();
76 for(Int_t iEventN=0;iEventN<gAlice->GetEventsPerRun();iEventN++){//events loop
77 gAlice->GetRunLoader()->GetEvent(iEventN);
79 Rich()->GetLoader()->MakeTree("R"); Rich()->MakeBranch("R");
80 Rich()->ResetDigits(); Rich()->ResetClusters();
82 Rich()->GetLoader()->TreeD()->GetEntry(0);
83 for(Int_t iChamber=1;iChamber<=kNCH;iChamber++){//chambers loop
84 FindRawClusters(iChamber);
88 Rich()->GetLoader()->TreeR()->Fill();
89 Rich()->GetLoader()->WriteRecPoints("OVERWRITE");
91 Rich()->GetLoader()->UnloadDigits(); Rich()->GetLoader()->UnloadRecPoints();
92 Rich()->ResetDigits(); Rich()->ResetClusters();
95 //__________________________________________________________________________________________________
96 void AliRICHClusterFinder::FindRawClusters(Int_t iChamber)
97 {//finds neighbours and fill the tree with raw clusters
98 Int_t nDigits=Rich()->Digits(iChamber)->GetEntriesFast();
99 Info("FindRawClusters","Start for Chamber %i with %i digits.",iChamber,nDigits);
100 if(nDigits==0)return;
102 fHitMap=new AliRICHMap(Rich()->Digits(iChamber));//create digit map for the given chamber
104 for(Int_t iDig=0;iDig<nDigits;iDig++){
105 AliRICHdigit *dig=(AliRICHdigit*)Rich()->Digits(iChamber)->At(iDig);
106 Int_t i=dig->X(); Int_t j=dig->Y();
107 if(fHitMap->TestHit(i,j)==kUsed) continue;
111 if(AliRICHParam::IsResolveClusters()) {
112 ResolveCluster(); // ResolveCluster serialization will happen inside
114 WriteRawCluster(); // simply output of the RawCluster found without deconvolution
116 fCurrentCluster.Reset();
120 Info("FindRawClusters","Stop.");
123 //__________________________________________________________________________________________________
124 void AliRICHClusterFinder::FormRawCluster(Int_t i, Int_t j)
125 {// Builder of the final Raw Cluster (before deconvolution)
126 Info("FormRawCluster","Start with digit(%i,%i)",i,j);
128 fCurrentCluster.AddDigit((AliRICHdigit*) fHitMap->GetHit(i,j));
129 fHitMap->FlagHit(i,j);// Flag hit as taken
131 Int_t listX[4], listY[4]; // Now look recursively for all neighbours
132 for (Int_t iNeighbour=0;iNeighbour<Rich()->Param()->PadNeighbours(i,j,listX,listY);iNeighbour++)
133 if(fHitMap->TestHit(listX[iNeighbour],listY[iNeighbour])==kUnused)
134 FormRawCluster(listX[iNeighbour],listY[iNeighbour]);
135 }//AddDigit2Cluster()
136 //__________________________________________________________________________________________________
137 void AliRICHClusterFinder::ResolveCluster()
138 {// Decluster algorithm
139 Info("ResolveCluster","Start.");
141 fCurrentCluster.CoG(); // first initial approxmation of the CoG...to start minimization.
142 fCurrentCluster.Print();
143 switch (fCurrentCluster.Size()) {
146 WriteRawCluster(); break;
149 WriteRawCluster(); break;
152 WriteRawCluster(); break;
155 //__________________________________________________________________________________________________
156 void AliRICHClusterFinder::WriteRawCluster()
157 {// out the current RawCluster
158 Info("WriteRawCluster","Start.");
160 Rich()->AddCluster(fCurrentCluster);
163 //__________________________________________________________________________________________________
164 void AliRICHClusterFinder::FitCoG()
165 {// Fit cluster size 2 by single Mathieson
166 Info("FitCoG","Start.");
168 TMinuit *pMinuit = new TMinuit(2);
173 static Double_t vstart[2];
174 static Double_t lower[2], upper[2];
175 static Double_t step[2]={0.001,0.001};
180 pMinuit->SetObjectFit((TObject*)this);
181 pMinuit->SetFCN(RICHMinMathieson);
182 pMinuit->mninit(5,10,7);
184 vstart[0] = fCurrentCluster.X();
185 vstart[1] = fCurrentCluster.Y();
187 lower[0] = vstart[0] - 2*AliRICHParam::PadSizeX();
188 upper[0] = vstart[0] + 2*AliRICHParam::PadSizeX();
189 lower[1] = vstart[1] - 2*AliRICHParam::PadSizeY();
190 upper[1] = vstart[1] + 2*AliRICHParam::PadSizeY();
193 pMinuit->mnparm(0," x position ",vstart[0],step[0],lower[0],upper[0],ierflag);
194 pMinuit->mnparm(1," y position ",vstart[1],step[1],lower[1],upper[1],ierflag);
198 pMinuit->SetPrintLevel(-1);
199 pMinuit->mnexcm("SET NOGR",&arglist, 1, ierflag);
200 pMinuit->mnexcm("SET NOW",&arglist, 1, ierflag);
202 pMinuit->mnexcm("SET ERR", &arglist, 1,ierflg);
204 pMinuit->mnexcm("SIMPLEX",&arglist, 0, ierflag);
205 pMinuit->mnexcm("MIGRAD",&arglist, 0, ierflag);
206 pMinuit->mnexcm("EXIT" ,&arglist, 0, ierflag);
208 Double_t eps, b1, b2;
209 pMinuit->mnpout(0,chname, xCoG, eps , b1, b2, ierflg);
210 pMinuit->mnpout(1,chname, yCoG, eps , b1, b2, ierflg);
213 //__________________________________________________________________________________________________
214 void RICHMinMathieson(Int_t &, Double_t *, Double_t &chi2, Double_t *par, Int_t iflag)
215 {// Minimization function of Mathieson
217 AliRICHcluster *pRawCluster = ((AliRICHClusterFinder*)gMinuit->GetObjectFit())->GetCurrentCluster();
219 TVector3 centroid(par[0],par[1],0);
222 Int_t qtot = pRawCluster->Q();
223 for(Int_t i=0;i<pRawCluster->Size();i++) {
224 Int_t padX = ((AliRICHdigit *)pRawCluster->Digits()->At(i))->X();
225 Int_t padY = ((AliRICHdigit *)pRawCluster->Digits()->At(i))->Y();
226 Double_t padQ = ((AliRICHdigit *)pRawCluster->Digits()->At(i))->Q();
227 chi2 += TMath::Power((qtot*AliRICHParam::Loc2PadFrac(centroid,padX,padY)-padQ),2)/padQ;
231 cout << " --- end convergence...summary --- " << endl;
232 cout << " x position " << par[0] << endl;
233 cout << " y position " << par[1] << endl;
234 cout << " chi2 " << chi2 << endl;
236 }//RICHMinMathieson()