+}//FillZeroChan()
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+Int_t AliHMPIDReconHTA::r2(Double_t *coef, Double_t &x1, Double_t &x2)
+{
+ //2nd deg. equation
+ //solution
+ // Arguments: coef 2 1 0: ax^2+bx+c=0
+ // Returns: n. of solutions
+ // x1= 1st sol
+ // x2= 2nd sol
+ Double_t a,b,c;
+ a = coef[2];
+ b = coef[1];
+ c = coef[0];
+ Double_t delta = b*b-4*a*c;
+ if(delta<0) {return 0;}
+ if(delta==0) {
+ x1=x2=-b/(2*a);
+ return 1;
+ }
+ if(a==0) {
+ x1 = -c/b;
+ return 1;
+ }
+ // delta>0
+ x1 = (-b+TMath::Sqrt(delta))/(2*a);
+ x2 = (-b-TMath::Sqrt(delta))/(2*a);
+ return 2;
+}//r2()
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+Double_t AliHMPIDReconHTA::FindSimmPhi()
+{
+//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+// Reconstruction of phiTRK angle with two methods (in switching)
+//
+// - least square method (for closed rings)
+// - by minimum distance mip-photon (for open rings)
+
+ Float_t coeff1ord=0; Float_t coeff2ord=0; Float_t coeff0ord=0;
+ Float_t xrotsumm =0; Float_t yrotsumm =0; Float_t xx =0;
+ Float_t yy =0; Float_t xy =0;
+ Double_t xmin=0;
+ Double_t ymin=0;
+
+ Int_t np=0;
+
+ Double_t distMin = 999.;
+
+ for(Int_t i=0;i<fNClu;i++) {
+ if(!fClCk[i]) continue;
+ np++;
+ xrotsumm+=fXClu[i]; // summ xi
+ yrotsumm+=fYClu[i]; // summ yi
+ xx+=fXClu[i]*fXClu[i]; // summ xixi
+ yy+=fYClu[i]*fYClu[i]; // summ yiyi
+ xy+=fXClu[i]*fYClu[i]; // summ yixi
+ Double_t dist2= (fXClu[i]-fMipX)*(fXClu[i]-fMipX)+(fYClu[i]-fMipY)*(fYClu[i]-fMipY);
+ if(dist2<distMin) {
+ distMin = dist2;
+ xmin = fXClu[i];
+ ymin = fYClu[i];
+ }
+ }
+
+ Double_t AngM = TMath::ATan2(ymin-fMipY,(xmin-fMipX))*TMath::RadToDeg();
+ if (AngM<0) AngM+=360;
+
+ AliDebug(1,Form(" Simple angle prediction with MIN phi = %f",AngM));
+
+ //_____calc. met min quadr using effective distance _________________________________________________
+
+ if(np>0){
+ coeff2ord = xy-xrotsumm*yrotsumm/np;
+ coeff1ord = yrotsumm*yrotsumm/np - xrotsumm*xrotsumm/np - yy + xx;
+ }
+ coeff0ord = -coeff2ord;
+
+ AliDebug(1,Form(" a = %f b = %f c = %f",coeff2ord,coeff1ord,coeff0ord));
+
+ Double_t m1=0, m2=0; Double_t n1=0, n2=0;
+ // c // b // a
+ Double_t coeff[3]={coeff0ord,coeff1ord,coeff2ord};
+
+ r2(coeff,m1,m2);
+
+ if(np>0){
+ n1=(yrotsumm-m1*xrotsumm)/np;
+ n2=(yrotsumm-m2*xrotsumm)/np;}
+ // 2 solutions.................
+
+ // negative angles solved...
+
+ Double_t d1 =(1/(m1*m1+1))*(yy+m1*m1*xx+np*n1*n1-2*m1*xy-2*n1*yrotsumm+2*m1*n1*xrotsumm);
+ Double_t d2 =(1/(m2*m2+1))*(yy+m2*m2*xx+np*n2*n2-2*m2*xy-2*n2*yrotsumm+2*m2*n2*xrotsumm);
+
+ AliDebug(1,Form(" predicted distance d1 %f for angle %6.2f d2 %f for angle %6.2f",d1,TMath::ATan(m1)*TMath::RadToDeg(),
+ d2,TMath::ATan(m2)*TMath::RadToDeg()));
+ Double_t mMin;
+ if(d1 > d2) mMin = m2; else mMin = m1;
+
+ Double_t phiTrk=0;
+ //
+ if(ymin < fMipY && xmin > fMipX) {phiTrk = TMath::ATan(mMin)*TMath::RadToDeg()+180;}
+ if(ymin > fMipY && xmin < fMipX) {phiTrk = TMath::ATan(mMin)*TMath::RadToDeg()+360;}
+ if(ymin > fMipY && xmin > fMipX) {phiTrk = TMath::ATan(mMin)*TMath::RadToDeg()+180;}
+ if(ymin < fMipY && xmin < fMipX) {phiTrk = TMath::ATan(mMin)*TMath::RadToDeg();}
+ if(ymin == fMipY && xmin > fMipX) {phiTrk = TMath::ATan(mMin)*TMath::RadToDeg()+180;}
+ if(ymin == fMipY && xmin < fMipX) {phiTrk = TMath::ATan(mMin)*TMath::RadToDeg();}
+ if(ymin < fMipY && xmin == fMipX) {phiTrk = 90;}
+ if(ymin > fMipY && xmin == fMipX) {phiTrk = 270;}
+
+ // ------------------------- choose the best-----------------------
+
+
+ if( AngM-40 <= phiTrk && AngM+40 >= phiTrk) return phiTrk; else return AngM;
+}
+//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+void AliHMPIDReconHTA::FindBinDB(Double_t x,Double_t y,Int_t &binX,Int_t &binY)
+{
+ const Int_t nxDB = 500;
+ const Int_t nyDB = 150;
+ const Double_t xlowDB = 0;
+ const Double_t xhigDB = 50;
+ const Double_t ylowDB = 0;
+ const Double_t yhigDB = 30;
+
+ binX = -1;
+ binY = -1;
+ if(x<xlowDB && x>xhigDB &&
+ y<ylowDB && y>yhigDB) return;
+ binX = Int_t((x-xlowDB)/(xhigDB-xlowDB)*nxDB);
+ binY = Int_t((y-ylowDB)/(yhigDB-ylowDB)*nyDB);
+ if(binX>=nxDB || binY>=nyDB) {
+ binX = -1;
+ binY = -1;
+ }
+