+//_____________________________________________________________________________
+Bool_t AliEMCALRecPoint::EvalLocalPosition2(TClonesArray * digits, TArrayD &ed)
+{
+ // Evaluated local position of rec.point using digits
+ // and parametrisation of w0 and deff
+ //printf(" <I> AliEMCALRecPoint::EvalLocalPosition2() \n");
+ return AliEMCALRecPoint::EvalLocalPositionFromDigits(digits, ed, fLocPos);
+}
+
+//_____________________________________________________________________________
+Bool_t AliEMCALRecPoint::EvalLocalPositionFromDigits(TClonesArray *digits, TArrayD &ed, TVector3 &locPos)
+{
+ // Used when digits should be recalibrated
+ Double_t deff=0, w0=0, esum=0;
+ Int_t iDigit=0;
+ // AliEMCALDigit *digit;
+
+ if(ed.GetSize() && (digits->GetEntries()!=ed.GetSize())) return kFALSE;
+
+ // Calculate sum energy of digits
+ esum = 0.0;
+ for(iDigit=0; iDigit<ed.GetSize(); iDigit++) esum += ed[iDigit];
+
+ GetDeffW0(esum, deff, w0);
+
+ return EvalLocalPositionFromDigits(esum, deff, w0, digits, ed, locPos);
+}
+
+//_____________________________________________________________________________
+Bool_t AliEMCALRecPoint::EvalLocalPositionFromDigits(const Double_t esum, const Double_t deff, const Double_t w0, TClonesArray *digits, TArrayD &ed, TVector3 &locPos)
+{
+ //Evaluate position of digits in supermodule.
+ AliEMCALDigit *digit=0;
+
+ Int_t i=0, nstat=0;
+ Double_t clXYZ[3]={0.,0.,0.}, xyzi[3], wtot=0., w=0.;
+ //Int_t idMax = GetAbsIdMaxDigit();// idMax is not used at all in RelPosCellInSModule, why use it?
+
+ // Get pointer to EMCAL geometry
+ // (can't use fGeomPtr in static method)
+ AliEMCALGeometry* geo = AliEMCALGeometry::GetInstance();
+
+ for(Int_t iDigit=0; iDigit<digits->GetEntries(); iDigit++) {
+ digit = dynamic_cast<AliEMCALDigit *>(digits->At(iDigit));
+ if(digit){
+ //geo->RelPosCellInSModule(digit->GetId(), idMax, deff, xyzi[0], xyzi[1], xyzi[2]);
+ geo->RelPosCellInSModule(digit->GetId(), deff, xyzi[0], xyzi[1], xyzi[2]);
+
+ if(w0 > 0.0) w = TMath::Max( 0., w0 + TMath::Log(ed[iDigit] / esum));
+ else w = ed[iDigit]; // just energy
+
+ if(w>0.0) {
+ wtot += w ;
+ nstat++;
+ for(i=0; i<3; i++ ) {
+ clXYZ[i] += (w*xyzi[i]);
+ }
+ }
+ }else AliError("Digit null");
+ }//loop
+ // cout << " wtot " << wtot << endl;
+ if (wtot > 0) {
+ for(i=0; i<3; i++ ) {
+ clXYZ[i] /= wtot;
+ }
+ locPos.SetX(clXYZ[0]);
+ locPos.SetY(clXYZ[1]);
+ locPos.SetZ(clXYZ[2]);
+ return kTRUE;
+ } else {
+ return kFALSE;
+ }
+
+}
+
+//_____________________________________________________________________________
+void AliEMCALRecPoint::GetDeffW0(const Double_t esum , Double_t &deff, Double_t &w0)
+{
+ //
+ // Aug 31, 2001
+ // Applied for simulation data with threshold 3 adc
+ // Calculate efective distance (deff) and weigh parameter (w0)
+ // for coordinate calculation; 0.5 GeV < esum <100 GeV.
+ // Look to: http://rhic.physics.wayne.edu/~pavlinov/ALICE/SHISHKEBAB/RES/CALIB/GEOMCORR/deffandW0VaEgamma_2.gif
+ //
+ Double_t e=0.0;
+ const Double_t kdp0=9.25147, kdp1=1.16700; // Hard coded now
+ const Double_t kwp0=4.83713, kwp1=-2.77970e-01, kwp2 = 4.41116;
+
+ // No extrapolation here
+ e = esum<0.5?0.5:esum;
+ e = e>100.?100.:e;
+
+ deff = kdp0 + kdp1*TMath::Log(e);
+ w0 = kwp0 / (1. + TMath::Exp(kwp1*(e+kwp2)));
+ //printf("<I> AliEMCALRecPoint::GetDeffW0 esum %5.2f : deff %5.2f : w0 %5.2f \n", esum, deff, w0);
+}