]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RICH/AliRICHClusterFinder.cxx
Changes to obey the coding conventions
[u/mrichter/AliRoot.git] / RICH / AliRICHClusterFinder.cxx
CommitLineData
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>
20#include <TVector3.h>
cbaf35fb 21#include <AliLoader.h>
22#include <AliRun.h>
8265fa96 23
9d6f9427 24void RICHMinMathieson(Int_t &npar, Double_t *gin, Double_t &chi2, Double_t *par, Int_t iflag);
8265fa96 25
26ClassImp(AliRICHClusterFinder)
543d5224 27//__________________________________________________________________________________________________
28AliRICHClusterFinder::AliRICHClusterFinder(AliRICH *pRICH)
29{//main ctor
30 Info("main ctor","Start.");
31
cbaf35fb 32 fRICH = pRICH;
543d5224 33
cbaf35fb 34 fHitMap = 0;
543d5224 35
543d5224 36}//main ctor
37//__________________________________________________________________________________________________
9d6f9427 38void AliRICHClusterFinder::FindLocalMaxima()
543d5224 39{// Split the cluster according to the number of maxima inside
9d6f9427 40 Info("FindLocalMaxima","Start.");
cbaf35fb 41 Int_t Nlocal = 0;
42 Int_t localX[100],localY[100];
9d6f9427 43 for(Int_t iDig1=0;iDig1<fCurrentCluster.Size();iDig1++) {
cbaf35fb 44 Int_t iNotMax = 0;
9d6f9427 45 AliRICHdigit *pDig1 = (AliRICHdigit *)fCurrentCluster.Digits()->At(iDig1);
cbaf35fb 46 Int_t padX1 = pDig1->X();
47 Int_t padY1 = pDig1->Y();
48 Double_t padQ1 = pDig1->Q();
9d6f9427 49 for(Int_t iDig2=0;iDig2<fCurrentCluster.Size();iDig2++) {
50 AliRICHdigit *pDig2 = (AliRICHdigit *)fCurrentCluster.Digits()->At(iDig2);
cbaf35fb 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++;
59 }
8265fa96 60 }
cbaf35fb 61 if(iNotMax==0) {
62 localX[Nlocal] = padX1;
63 localY[Nlocal] = padY1;
64 Nlocal++;
8265fa96 65 }
cbaf35fb 66 }
67}//FindLocalMaxima()
543d5224 68//__________________________________________________________________________________________________
69void AliRICHClusterFinder::Exec()
237c933d 70{
543d5224 71 Info("Exec","Start.");
72
cbaf35fb 73
543d5224 74 Rich()->GetLoader()->LoadDigits();
75
76 for(Int_t iEventN=0;iEventN<gAlice->GetEventsPerRun();iEventN++){//events loop
77 gAlice->GetRunLoader()->GetEvent(iEventN);
237c933d 78
543d5224 79 Rich()->GetLoader()->MakeTree("R"); Rich()->MakeBranch("R");
cbaf35fb 80 Rich()->ResetDigits(); Rich()->ResetClusters();
543d5224 81
82 Rich()->GetLoader()->TreeD()->GetEntry(0);
cbaf35fb 83 for(Int_t iChamber=1;iChamber<=kNCH;iChamber++){//chambers loop
84 FindRawClusters(iChamber);
543d5224 85
86 }//chambers loop
87
88 Rich()->GetLoader()->TreeR()->Fill();
89 Rich()->GetLoader()->WriteRecPoints("OVERWRITE");
90 }//events loop
91 Rich()->GetLoader()->UnloadDigits(); Rich()->GetLoader()->UnloadRecPoints();
cbaf35fb 92 Rich()->ResetDigits(); Rich()->ResetClusters();
543d5224 93 Info("Exec","Stop.");
94}//Exec()
95//__________________________________________________________________________________________________
cbaf35fb 96void AliRICHClusterFinder::FindRawClusters(Int_t iChamber)
97{//finds neighbours and fill the tree with raw clusters
cbaf35fb 98 Int_t nDigits=Rich()->Digits(iChamber)->GetEntriesFast();
e33758d8 99 Info("FindRawClusters","Start for Chamber %i with %i digits.",iChamber,nDigits);
cbaf35fb 100 if(nDigits==0)return;
101
eaf390d9 102 fHitMap=new AliRICHMap(Rich()->Digits(iChamber));//create digit map for the given chamber
cbaf35fb 103
cbaf35fb 104 for(Int_t iDig=0;iDig<nDigits;iDig++){
e33758d8 105 AliRICHdigit *dig=(AliRICHdigit*)Rich()->Digits(iChamber)->At(iDig);
cbaf35fb 106 Int_t i=dig->X(); Int_t j=dig->Y();
107 if(fHitMap->TestHit(i,j)==kUsed) continue;
108
9d6f9427 109 FormRawCluster(i,j);
cbaf35fb 110
111 if(AliRICHParam::IsResolveClusters()) {
9d6f9427 112 ResolveCluster(); // ResolveCluster serialization will happen inside
cbaf35fb 113 } else {
9d6f9427 114 WriteRawCluster(); // simply output of the RawCluster found without deconvolution
cbaf35fb 115 }
9d6f9427 116 fCurrentCluster.Reset();
cbaf35fb 117 }//digits loop
118
119 delete fHitMap;
120 Info("FindRawClusters","Stop.");
121
122}//FindRawClusters()
123//__________________________________________________________________________________________________
9d6f9427 124void AliRICHClusterFinder::FormRawCluster(Int_t i, Int_t j)
cbaf35fb 125{// Builder of the final Raw Cluster (before deconvolution)
126 Info("FormRawCluster","Start with digit(%i,%i)",i,j);
127
9d6f9427 128 fCurrentCluster.AddDigit((AliRICHdigit*) fHitMap->GetHit(i,j));
cbaf35fb 129 fHitMap->FlagHit(i,j);// Flag hit as taken
130
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)
9d6f9427 134 FormRawCluster(listX[iNeighbour],listY[iNeighbour]);
cbaf35fb 135}//AddDigit2Cluster()
136//__________________________________________________________________________________________________
9d6f9427 137void AliRICHClusterFinder::ResolveCluster()
cbaf35fb 138{// Decluster algorithm
139 Info("ResolveCluster","Start.");
9d6f9427 140
141 fCurrentCluster.CoG(); // first initial approxmation of the CoG...to start minimization.
142 fCurrentCluster.Print();
143 switch (fCurrentCluster.Size()) {
cbaf35fb 144
9d6f9427 145 case 1:
146 WriteRawCluster(); break;
147 case 2:
148 FitCoG();
149 WriteRawCluster(); break;
150
151 default:
152 WriteRawCluster(); break;
153 }
cbaf35fb 154}//ResolveCluster()
155//__________________________________________________________________________________________________
9d6f9427 156void AliRICHClusterFinder::WriteRawCluster()
cbaf35fb 157{// out the current RawCluster
eaf390d9 158 Info("WriteRawCluster","Start.");
cbaf35fb 159
9d6f9427 160 Rich()->AddCluster(fCurrentCluster);
cbaf35fb 161
162}//WriteRawCluster()
163//__________________________________________________________________________________________________
9d6f9427 164void AliRICHClusterFinder::FitCoG()
165{// Fit cluster size 2 by single Mathieson
166 Info("FitCoG","Start.");
167
168 TMinuit *pMinuit = new TMinuit(2);
169
170 Double_t arglist;
171 Int_t ierflag = 0;
172
173 static Double_t vstart[2];
174 static Double_t lower[2], upper[2];
175 static Double_t step[2]={0.001,0.001};
176
177 TString chname;
178 Int_t ierflg;
179
180 pMinuit->SetObjectFit((TObject*)this);
181 pMinuit->SetFCN(RICHMinMathieson);
182 pMinuit->mninit(5,10,7);
183
184 vstart[0] = fCurrentCluster.X();
185 vstart[1] = fCurrentCluster.Y();
186
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();
191
192
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);
195
196 arglist = -1;
197
198 pMinuit->SetPrintLevel(-1);
199 pMinuit->mnexcm("SET NOGR",&arglist, 1, ierflag);
200 pMinuit->mnexcm("SET NOW",&arglist, 1, ierflag);
201 arglist = 1;
202 pMinuit->mnexcm("SET ERR", &arglist, 1,ierflg);
203 arglist = -1;
204 pMinuit->mnexcm("SIMPLEX",&arglist, 0, ierflag);
205 pMinuit->mnexcm("MIGRAD",&arglist, 0, ierflag);
206 pMinuit->mnexcm("EXIT" ,&arglist, 0, ierflag);
207 Double_t xCoG,yCoG;
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);
211 delete pMinuit;
212}
213//__________________________________________________________________________________________________
214void RICHMinMathieson(Int_t &, Double_t *, Double_t &chi2, Double_t *par, Int_t iflag)
215{// Minimization function of Mathieson
216
217 AliRICHcluster *pRawCluster = ((AliRICHClusterFinder*)gMinuit->GetObjectFit())->GetCurrentCluster();
218
219 TVector3 centroid(par[0],par[1],0);
220
221 chi2 = 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;
228 }
229 if(iflag == 3)
230 {
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;
235 }
236}//RICHMinMathieson()