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 // **************************************************************************
16 #include "AliRICHCluster.h" //class header
17 #include <TMinuit.h> //Solve()
18 #include <AliStack.h> //FindCfm(), Solve()
19 #include <TParticle.h> //FindCfm()
20 #include <TClonesArray.h> //Solve() Test()
22 ClassImp(AliRICHCluster)
23 //__________________________________________________________________________________________________
24 void AliRICHCluster::CoG()
26 // Calculates naive cluster position as a center of gravity of its digits.
28 // Returns: shape of the cluster i.e. the box which fully contains the cluster
29 if(fDigs==0) return; //no digits in this cluster
30 fX=fY=0; //set cluster position to (0,0) to start to collect contributions
31 for(Int_t iDig=0;iDig<fDigs->GetEntriesFast();iDig++){//digits loop
32 AliRICHDigit *pDig=(AliRICHDigit*)fDigs->At(iDig); //get pointer to next digit
33 TVector pad=pDig->Pad(); Double_t q=pDig->Qdc(); //get pad adn QDC of this digit
34 TVector2 x2=AliRICHParam::Pad2Loc(pad); //calculate center of the pad in LORS
35 fX += x2.X()*q;fY +=x2.Y()*q; //sum up digit centers weighted by QDC
37 fX/=fQdc;fY/=fQdc; //final center of gravity
39 TVector2 center = AliRICHParam::Pad2Loc(AliRICHParam::Loc2Pad(TVector2(fX,fY)));//center of the pad containing calculated cluster position
40 fX += AliRICHParam::CogCorr(fX-center.X()); //correct cluster position for sinoid
44 //__________________________________________________________________________________________________
45 void AliRICHCluster::FitFunc(Int_t &iNpars, Double_t *, Double_t &chi2, Double_t *par, Int_t )
47 // Cluster fit function
48 // par[0]=x par[1]=y par[2]=q for the first Mathieson shape
49 // par[3]=x par[4]=y par[5]=q for the second Mathieson shape and so on up to iNpars/3 Mathieson shapes
50 // We need to calculate QpadExp - QpadMathieson summup over all pads of the cluster
51 // Here QpadExp is a actual charge of the pad, QpadMathieson is calculated charge of the pad induced by all Mathiesons
52 // Arguments: iNpars - number of parameters which is number of local maxima of cluster * 3
53 // chi2 - function result to be minimised
54 // par - parameters array of size iNpars
56 AliRICHCluster *pClu=(AliRICHCluster*)gMinuit->GetObjectFit();
57 Int_t iNmathiesons = iNpars/3;
59 TVector2 curMathiesonPos;
61 for(Int_t i=0;i<pClu->Size();i++){ //loop on all pads of the cluster
62 TVector pad = pClu->Dig(i)->Pad();
63 Double_t dQpadExp = pClu->Dig(i)->Qdc();
64 Double_t dQpadMathieson = 0;
65 for(Int_t j=0;j<iNmathiesons;j++){ //Mathiesons loop as all of them may contribute to this pad
66 curMathiesonPos.Set(par[3*j],par[3*j+1]); //get position of current Mathieson
67 dQpadMathieson += par[3*j+2]*AliRICHParam::FracQdc(curMathiesonPos,pad); //sums up contributions to the current pad from all Mathiesons
69 chi2 += TMath::Power((dQpadMathieson-dQpadExp),2); //
70 } //loop on all pads of the cluster
72 //__________________________________________________________________________________________________
73 void AliRICHCluster::Print(Option_t* opt)const
75 //Print current cluster
78 case kFormed: status="formed" ;break;
79 case kUnfolded: status="unfolded" ;break;
80 case kCoG: status="coged" ;break;
81 case kEmpty: status="empty" ;break;
83 Int_t iNdigs=0; if(fDigs) iNdigs=fDigs->GetEntriesFast();
85 Printf("%s cs=%2i, Size=%2i (x=%7.3f cm,y=%7.3f cm,Q=%4i qdc), %s",
86 opt,fCham,iNdigs,fX,fY,fQdc,status);
87 for(Int_t i=0;i<iNdigs;i++) Dig(i)->Print();
89 //__________________________________________________________________________________________________
90 Int_t AliRICHCluster::Solve(TClonesArray *pCluLst,Bool_t isTryUnfold)
92 //This methode is invoked when the cluster is formed to solve it. Solve the cluster means to try to unfold the cluster
93 //into the local maxima number of clusters. This methode is invoked by AliRICHRconstructor::Dig2Clu() on cluster by cluster basis.
94 //At this point, cluster contains a list of digits, cluster charge and size is precalculated in AddDigit(), position is preset to (-1,-1) in ctor,
95 //status is preset to kFormed in AddDigit(), chamber-sector info is preseted to actual values in AddDigit()
96 //Method first finds number of local maxima and if it's more then one tries to unfold this cluster into local maxima number of clusters
97 //Arguments: pCluLst - cluster list pointer where to add new cluster(s)
98 // isTryUnfold - flag to switch on/off unfolding
99 // Returns: number of local maxima of original cluster
101 //Phase 0. Initialise TMinuit
102 const Int_t kMaxLocMax=6; //max allowed number of loc max for fitting
103 TMinuit *pMinuit = new TMinuit(3*kMaxLocMax); //init MINUIT with this number of parameters (3 params per mathieson)
104 pMinuit->SetObjectFit((TObject*)this); pMinuit->SetFCN(AliRICHCluster::FitFunc); //set fit function
105 Double_t aArg=-1,parStart,parStep,parLow,parHigh; Int_t iErrFlg; //tmp vars for TMinuit
106 pMinuit->mnexcm("SET PRI",&aArg,1,iErrFlg); //suspend all printout from TMinuit
107 pMinuit->mnexcm("SET NOW",&aArg,0,iErrFlg); //suspend all warning printout from TMinuit
108 //Phase 1. Find number of local maxima. Strategy is to check if the current pad has QDC more then all neigbours
110 for(Int_t iDig1=0;iDig1<Size();iDig1++) { //first digits loop
111 AliRICHDigit *pDig1 = Dig(iDig1); //take next digit
112 Int_t iHowManyMoreCnt = 0; //counts how many neighbouring pads has QDC more then current one
113 for(Int_t iDig2=0;iDig2<Size();iDig2++) { //loop on all digits again
114 AliRICHDigit *pDig2 = Dig(iDig2); //take second digit to compare with the first one
115 if(iDig1==iDig2) continue; //the same digit, no need to compare
116 Int_t dist = TMath::Sign(Int_t(pDig1->PadX()-pDig2->PadX()),1)+TMath::Sign(Int_t(pDig1->PadY()-pDig2->PadY()),1);//distance between pads
117 if(dist==1) //means dig2 is a neighbour of dig1
118 if(pDig2->Qdc()>=pDig1->Qdc()) iHowManyMoreCnt++; //count number of pads with Q more then Q of current pad
119 }//second digits loop
120 if(iHowManyMoreCnt==0&&iLocMaxCnt<=kMaxLocMax){ //this pad has Q more then any neighbour so it's local maximum
121 TVector2 x2=AliRICHParam::Pad2Loc(pDig1->Pad()); //take pad center position and use it as parameter for current Mathienson shape
122 pMinuit->mnparm(3*iLocMaxCnt ,Form("x%i",iLocMaxCnt),parStart=x2.X() ,parStep=0.01,parLow=0,parHigh=0,iErrFlg);
123 pMinuit->mnparm(3*iLocMaxCnt+1,Form("y%i",iLocMaxCnt),parStart=x2.Y() ,parStep=0.01,parLow=0,parHigh=0,iErrFlg);
124 pMinuit->mnparm(3*iLocMaxCnt+2,Form("q%i",iLocMaxCnt),parStart=pDig1->Qdc(),parStep=0.01,parLow=0,parHigh=0,iErrFlg);
126 }//if this pad is local maximum
128 //Phase 2. Fit loc max number of Mathiesons or add this current cluster to the list
129 Int_t iCluCnt=pCluLst->GetEntriesFast(); //get current number of clusters already stored in the list by previous operations
130 if(isTryUnfold==kTRUE && iLocMaxCnt<=kMaxLocMax){ //resonable number of local maxima to fit and user requested it
131 pMinuit->mnexcm("MIGRAD" ,&aArg,0,iErrFlg); //start fitting
132 Double_t fitX,fitY,fitQ,d1,d2,d3; TString sName; //vars to get results from TMinuit
133 for(Int_t i=0;i<iLocMaxCnt;i++){//local maxima loop
134 pMinuit->mnpout(3*i ,sName, fitX, d1 , d2, d3, iErrFlg);
135 pMinuit->mnpout(3*i+1 ,sName, fitY, d1 , d2, d3, iErrFlg);
136 pMinuit->mnpout(3*i+2 ,sName, fitQ, d1 , d2, d3, iErrFlg);
137 new ((*pCluLst)[iCluCnt++]) AliRICHCluster(C(),fitX,fitY,(Int_t)fitQ); //add new unfolded clusters
139 }else{//do not unfold since number of loc max is unresonably high or user's baned unfolding
141 new ((*pCluLst)[iCluCnt++]) AliRICHCluster(*this); //add this raw cluster
146 //__________________________________________________________________________________________________
147 void AliRICHCluster::Test(Double_t x,Double_t y,Double_t e,Bool_t isTryUnfold)
149 //This is to test all cluster functionality
150 //Uses AddDigit() to add a predifined pad structure and then calls Solve
152 Int_t iQtot=AliRICHParam::TotQdc(hitX2,e);
154 Printf("Provided hit position out of sensitive area");
157 TVector area=AliRICHParam::Loc2Area(hitX2);
160 for(pad[1]=area[1];pad[1]<=area[3];pad[1]++){//affected pads loop first y
161 for(pad[0]=area[0];pad[0]<=area[2];pad[0]++){//then x
162 Double_t dQpad=iQtot*AliRICHParam::FracQdc(hitX2,pad);//charge fraction from Mathieson centered at x to pad
163 clu.DigAdd(new AliRICHDigit(pad,dQpad));
164 }//affected pads loop
166 clu.CoG(); clu.Print("Initial cluster:");
167 TClonesArray *pCluLst=new TClonesArray("AliRICHCluster",1);
168 clu.Solve(pCluLst,isTryUnfold);
169 Printf("Initial hit : (%.2f,%.2f) Qtot=%i E=%.2f eV",x,y,iQtot,e*1e9);
170 ((AliRICHCluster *)pCluLst->At(0))->Print("Solved cluster:");
172 delete pCluLst; clu.Reset();
174 //__________________________________________________________________________________________________
175 void AliRICHCluster::Test()
177 //Test cluster builder by a number of predefined digit patterns
180 AliRICHCluster clu; Int_t ch,padx,pady,qdc; TClonesArray *pCluLst=new TClonesArray("AliRICHCluster",10);
181 Printf("2 digits vertical cluster");
182 clu.DigAdd(new AliRICHDigit(ch=1,padx=3,pady=3,qdc=101));
183 clu.DigAdd(new AliRICHDigit(ch=1,padx=3,pady=4,qdc=202)); clu.Print("Formed cluster:");
184 clu.Solve(pCluLst,kTRUE); pCluLst->Print();