]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RICH/AliRICHClusterFinder.cxx
Zero suppression added. Sigmas of noise generated randomly.
[u/mrichter/AliRoot.git] / RICH / AliRICHClusterFinder.cxx
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
17 #include "AliRICHClusterFinder.h"
18 #include "AliRICHMap.h"
19 #include <TMinuit.h>
20 #include <TVector3.h>
21 #include <AliLoader.h>
22 #include <AliRun.h>
23
24 void RICHMinMathieson(Int_t &npar, Double_t *gin, Double_t &chi2, Double_t *par, Int_t iflag);
25
26 ClassImp(AliRICHClusterFinder)
27 //__________________________________________________________________________________________________
28 AliRICHClusterFinder::AliRICHClusterFinder(AliRICH *pRICH)   
29 {//main ctor
30   Info("main ctor","Start.");
31   
32   fRICH = pRICH;
33   
34   fHitMap = 0;  
35   
36 }//main ctor
37 //__________________________________________________________________________________________________
38 void AliRICHClusterFinder::FindLocalMaxima()
39 {// Split the cluster according to the number of maxima inside
40   Info("FindLocalMaxima","Start.");
41   Int_t Nlocal = 0;
42   Int_t localX[100],localY[100];
43   for(Int_t iDig1=0;iDig1<fCurrentCluster.Size();iDig1++) {
44     Int_t iNotMax = 0;
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++;
59       }
60     }
61     if(iNotMax==0) {
62     localX[Nlocal] = padX1;
63     localY[Nlocal] = padY1;
64     Nlocal++;
65     }
66   }   
67 }//FindLocalMaxima()
68 //__________________________________________________________________________________________________
69 void AliRICHClusterFinder::Exec()
70 {
71   Info("Exec","Start.");
72   
73   
74   Rich()->GetLoader()->LoadDigits(); 
75   
76   for(Int_t iEventN=0;iEventN<gAlice->GetEventsPerRun();iEventN++){//events loop
77     gAlice->GetRunLoader()->GetEvent(iEventN);
78     
79     Rich()->GetLoader()->MakeTree("R");  Rich()->MakeBranch("R");
80     Rich()->ResetDigits();  Rich()->ResetClusters();
81     
82     Rich()->GetLoader()->TreeD()->GetEntry(0);
83     for(Int_t iChamber=1;iChamber<=kNCH;iChamber++){//chambers loop
84      FindRawClusters(iChamber);
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();  
92   Rich()->ResetDigits();  Rich()->ResetClusters();
93   Info("Exec","Stop.");      
94 }//Exec()
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;
101
102   fHitMap=new AliRICHMap(Rich()->Digits(iChamber));//create digit map for the given chamber
103
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;
108         
109     FormRawCluster(i,j);
110         
111     if(AliRICHParam::IsResolveClusters()) {
112       ResolveCluster(); // ResolveCluster serialization will happen inside
113     } else {
114       WriteRawCluster(); // simply output of the RawCluster found without deconvolution
115     }    
116     fCurrentCluster.Reset();
117   }//digits loop
118
119   delete fHitMap;
120   Info("FindRawClusters","Stop.");
121   
122 }//FindRawClusters()
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);
127   
128   fCurrentCluster.AddDigit((AliRICHdigit*) fHitMap->GetHit(i,j));
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) 
134                       FormRawCluster(listX[iNeighbour],listY[iNeighbour]);    
135 }//AddDigit2Cluster()
136 //__________________________________________________________________________________________________
137 void AliRICHClusterFinder::ResolveCluster()
138 {// Decluster algorithm
139   Info("ResolveCluster","Start.");    
140
141   fCurrentCluster.CoG(); // first initial approxmation of the CoG...to start minimization.
142   fCurrentCluster.Print();
143   switch (fCurrentCluster.Size()) {
144   
145   case 1:
146     WriteRawCluster(); break;
147   case 2:
148     FitCoG();
149     WriteRawCluster(); break;
150     
151   default:
152     WriteRawCluster(); break;
153   }     
154 }//ResolveCluster()
155 //__________________________________________________________________________________________________
156 void AliRICHClusterFinder::WriteRawCluster()
157 {// out the current RawCluster
158   Info("WriteRawCluster","Start.");
159   
160   Rich()->AddCluster(fCurrentCluster);
161   
162 }//WriteRawCluster()
163 //__________________________________________________________________________________________________
164 void 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 //__________________________________________________________________________________________________
214 void 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()