]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EMCAL/AliEMCALRecPoint.cxx
after successful nightly shuttle test : turn of debug AliInfo lines and and only...
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALRecPoint.cxx
index 5c86773fd8af9ac7a248159852365003b7104787..20e9c4f9ae9cfd2f9289fba187de1c525c5a88b2 100644 (file)
@@ -176,12 +176,12 @@ AliEMCALRecPoint& AliEMCALRecPoint::operator= (const AliEMCALRecPoint &rp)
   for(Int_t i = 0; i<fMaxDigit; i++) fDigitsList[i] = rp.fDigitsList[i];
   for(Int_t i = 0; i<fMaxTrack; i++) fTracksList[i] = rp.fTracksList[i];
   fClusterType = rp.fClusterType;
-  fCoreEnergy = rp.fCoreEnergy; 
-  fDispersion = rp.fDispersion;
+  fCoreEnergy  = rp.fCoreEnergy; 
+  fDispersion  = rp.fDispersion;
   for(Int_t i = 0; i<fMaxDigit; i++) {
     fEnergyList[i] = rp.fEnergyList[i];
-    fTimeList[i] = rp.fTimeList[i]; 
-    fAbsIdList[i] = rp.fAbsIdList[i];
+    fTimeList[i]   = rp.fTimeList[i]; 
+    fAbsIdList[i]  = rp.fAbsIdList[i];
   }
   fTime = rp.fTime;
   fNExMax = rp.fNExMax;
@@ -207,7 +207,7 @@ AliEMCALRecPoint& AliEMCALRecPoint::operator= (const AliEMCALRecPoint &rp)
 }
 
 //____________________________________________________________________________
-void AliEMCALRecPoint::AddDigit(AliEMCALDigit & digit, Float_t Energy, Bool_t shared)
+void AliEMCALRecPoint::AddDigit(AliEMCALDigit & digit, Float_t energy, Bool_t shared)
 {
   // Adds a digit to the RecPoint
   // and accumulates the total amplitude and the multiplicity 
@@ -222,10 +222,10 @@ void AliEMCALRecPoint::AddDigit(AliEMCALDigit & digit, Float_t Energy, Bool_t sh
 
   if ( fMulDigit >= fMaxDigit ) { // increase the size of the lists 
     fMaxDigit*=2 ; 
-    Int_t * tempo = new Int_t[fMaxDigit]; 
-    Float_t * tempoE  new Float_t[fMaxDigit];
-    Float_t * tempoT  new Float_t[fMaxDigit];
-    Int_t * tempoId = new Int_t[fMaxDigit]; 
+    Int_t   * tempo   = new Int_t[fMaxDigit]; 
+    Float_t * tempoE  = new Float_t[fMaxDigit];
+    Float_t * tempoT  = new Float_t[fMaxDigit];
+    Int_t   * tempoId = new Int_t[fMaxDigit]; 
 
     Int_t index ;     
     for ( index = 0 ; index < fMulDigit ; index++ ){
@@ -242,16 +242,16 @@ void AliEMCALRecPoint::AddDigit(AliEMCALDigit & digit, Float_t Energy, Bool_t sh
 
     fDigitsList = tempo;
     fEnergyList = tempoE; 
-    fTimeList = tempoT;
-    fAbsIdList = tempoId;
+    fTimeList   = tempoT;
+    fAbsIdList  = tempoId;
   } // if
   
   fDigitsList[fMulDigit]   = digit.GetIndexInList()  ; 
-  fEnergyList[fMulDigit]   = Energy ;
+  fEnergyList[fMulDigit]   = energy ;
   fTimeList[fMulDigit]     = digit.GetTimeR() ;
   fAbsIdList[fMulDigit]    = digit.GetId();
   fMulDigit++ ; 
-  fAmp += Energy ; 
+  fAmp += energy ; 
        
   if(shared) fSharedCluster = kTRUE;
        
@@ -271,11 +271,11 @@ Bool_t AliEMCALRecPoint::AreNeighbours(AliEMCALDigit * digit1, AliEMCALDigit * d
   // A neighbour is defined as being two digits which share a corner
   // ONLY USED IN CASE OF UNFOLDING 
        
-  static Bool_t areNeighbours = kFALSE ;
-  static Int_t nSupMod=0, nModule=0, nIphi=0, nIeta=0;
-  static int nSupMod1=0, nModule1=0, nIphi1=0, nIeta1=0;
-  static Int_t relid1[2] , relid2[2] ; // ieta, iphi
-  static Int_t rowdiff=0, coldiff=0;
+  Bool_t areNeighbours = kFALSE ;
+  Int_t nSupMod=0, nModule=0, nIphi=0, nIeta=0;
+  Int_t nSupMod1=0, nModule1=0, nIphi1=0, nIeta1=0;
+  Int_t relid1[2] , relid2[2] ; // ieta, iphi
+  Int_t rowdiff=0, coldiff=0;
 
   areNeighbours = kFALSE ;
 
@@ -441,12 +441,13 @@ Int_t AliEMCALRecPoint::Compare(const TObject * obj) const
 //}
 
 //____________________________________________________________________________
-void AliEMCALRecPoint::EvalAll(Float_t logWeight,TClonesArray * digits) 
+void AliEMCALRecPoint::EvalAll(Float_t logWeight,TClonesArray * digits, const Bool_t justClusters
 {
   // Evaluates cluster parameters
        
   // First calculate the index of digit with maximum amplitude and get 
   // the supermodule number where it sits.
+    
   fDigitIndMax       = GetMaximalEnergyIndex();
   fSuperModuleNumber = fGeomPtr->GetSuperModuleNumber(GetAbsIdMaxDigit());
   
@@ -464,7 +465,10 @@ void AliEMCALRecPoint::EvalAll(Float_t logWeight,TClonesArray * digits)
   EvalParents(digits);
        
   //Called last because it sets the global position of the cluster?
-  EvalLocal2TrackingCSTransform();
+  //Do not call it when recalculating clusters out of standard reconstruction
+  if(!justClusters){ 
+    EvalLocal2TrackingCSTransform();
+  }
 
 }
 
@@ -543,18 +547,18 @@ void  AliEMCALRecPoint::EvalDispersion(Float_t logWeight, TClonesArray * digits)
 //____________________________________________________________________________
 void AliEMCALRecPoint::EvalDistanceToBadChannels(AliCaloCalibPedestal* caloped)
 {
-       //For each EMC rec. point set the distance to the nearest bad channel.
-       //AliInfo(Form("%d bad channel(s) found.\n", caloped->GetDeadTowerCount()));
-    //Needs to be carefully checked!!! Gustavo 10-11-2009
-       
-       if(!caloped->GetDeadTowerCount()) return;
-               
-       //Get channels map of the supermodule where the cluster is.
-       TH2D* hMap  = caloped->GetDeadMap(fSuperModuleNumber);
-       
+  //For each EMC rec. point set the distance to the nearest bad channel.
+  //AliInfo(Form("%d bad channel(s) found.\n", caloped->GetDeadTowerCount()));
+  //It is done in cell units and not in global or local position as before (Sept 2010)
+  
+  if(!caloped->GetDeadTowerCount()) return;
+  
+  //Get channels map of the supermodule where the cluster is.
+  TH2D* hMap  = caloped->GetDeadMap(fSuperModuleNumber);
+  
   Int_t dRrow, dReta;  
-       Float_t  minDist = 10000.;
-       Float_t  dist    = 0.;
+  Float_t  minDist = 10000.;
+  Float_t  dist    = 0.;
   Int_t nSupMod, nModule;
   Int_t nIphi, nIeta;
   Int_t iphi, ieta;
@@ -569,17 +573,16 @@ void AliEMCALRecPoint::EvalDistanceToBadChannels(AliCaloCalibPedestal* caloped)
   //   Int_t    absId   = -1;  
   
   //Loop on tower status map 
-       for(Int_t irow = 0; irow < AliEMCALGeoParams::fgkEMCALRows; irow++){
-               for(Int_t icol = 0; icol < AliEMCALGeoParams::fgkEMCALCols; icol++){
-                       //Check if tower is bad.
-                       if(hMap->GetBinContent(icol,irow)==AliCaloCalibPedestal::kAlive) continue;
+  for(Int_t irow = 0; irow < AliEMCALGeoParams::fgkEMCALRows; irow++){
+    for(Int_t icol = 0; icol < AliEMCALGeoParams::fgkEMCALCols; icol++){
+      //Check if tower is bad.
+      if(hMap->GetBinContent(icol,irow)==AliCaloCalibPedestal::kAlive) continue;
       //printf("AliEMCALRecPoint::EvalDistanceToBadChannels() - Bad channel in SM %d, col %d, row %d\n",iSM,icol, irow);
-
+      
       dRrow=TMath::Abs(irow-iphi);
       dReta=TMath::Abs(icol-ieta);
       dist=TMath::Sqrt(dRrow*dRrow+dReta*dReta);
-                       if(dist < minDist) minDist = dist;
-      
+      if(dist < minDist) minDist = dist;
       
       //                       //Tower is bad, get the absId of the index.
       //                       absId = fGeomPtr->GetAbsCellIdFromCellIndexes(fSuperModuleNumber, irow, icol); 
@@ -599,36 +602,35 @@ void AliEMCALRecPoint::EvalDistanceToBadChannels(AliCaloCalibPedestal* caloped)
       //                       dist = dR.Mag();
       //                       if(dist < minDist) minDist = dist;
       
-      
-               }
-       
-       //In case the cluster is shared by 2 SuperModules, need to check the map of the second Super Module
-       if (fSharedCluster) {
-               TH2D* hMap2 = 0;
-               Int_t nSupMod2 = -1;
-       
-               //The only possible combinations are (0,1), (2,3) ... (10,11)
-               if(fSuperModuleNumber%2) nSupMod2 = fSuperModuleNumber-1;
-               else                     nSupMod2 = fSuperModuleNumber+1;
-               hMap2  = caloped->GetDeadMap(nSupMod2);
+    }
+  }
+  
+  //In case the cluster is shared by 2 SuperModules, need to check the map of the second Super Module
+  if (fSharedCluster) {
+    TH2D* hMap2 = 0;
+    Int_t nSupMod2 = -1;
     
-               //Loop on tower status map of second super module
-               for(Int_t irow = 0; irow < AliEMCALGeoParams::fgkEMCALRows; irow++){
-                       for(Int_t icol = 0; icol < AliEMCALGeoParams::fgkEMCALCols; icol++){
-                               //Check if tower is bad.
-                               if(hMap2->GetBinContent(icol,irow)==AliCaloCalibPedestal::kAlive) continue;
-                               //printf("AliEMCALRecPoint::EvalDistanceToBadChannels() - Bad channel in SM %d, col %d, row %d\n",iSM,icol, irow);
-        
+    //The only possible combinations are (0,1), (2,3) ... (10,11)
+    if(fSuperModuleNumber%2) nSupMod2 = fSuperModuleNumber-1;
+    else                     nSupMod2 = fSuperModuleNumber+1;
+    hMap2  = caloped->GetDeadMap(nSupMod2);
+    
+    //Loop on tower status map of second super module
+    for(Int_t irow = 0; irow < AliEMCALGeoParams::fgkEMCALRows; irow++){
+      for(Int_t icol = 0; icol < AliEMCALGeoParams::fgkEMCALCols; icol++){
+       //Check if tower is bad.
+       if(hMap2->GetBinContent(icol,irow)==AliCaloCalibPedestal::kAlive) continue;
+       //printf("AliEMCALRecPoint::EvalDistanceToBadChannels() - Bad channel in SM %d, col %d, row %d\n",iSM,icol, irow);
         dRrow=TMath::Abs(irow-iphi);
-
+       
         if(fSuperModuleNumber%2) {
-                                 dReta=TMath::Abs(icol-(AliEMCALGeoParams::fgkEMCALCols+ieta));
-                               }
-        else {
-          dReta=TMath::Abs(AliEMCALGeoParams::fgkEMCALCols+icol-ieta);
-                               }                    
+         dReta=TMath::Abs(icol-(AliEMCALGeoParams::fgkEMCALCols+ieta));
+       }
+       else {
+        dReta=TMath::Abs(AliEMCALGeoParams::fgkEMCALCols+icol-ieta);
+       }                    
         
-                               dist=TMath::Sqrt(dRrow*dRrow+dReta*dReta);
+       dist=TMath::Sqrt(dRrow*dRrow+dReta*dReta);
         if(dist < minDist) minDist = dist;        
         
 //                             
@@ -644,91 +646,96 @@ void AliEMCALRecPoint::EvalDistanceToBadChannels(AliCaloCalibPedestal* caloped)
 //                             
 //                             dist = dR.Mag();
 //                             if(dist < minDist) minDist = dist;
-                       }
-               }
-       
-       }// shared cluster in 2 SuperModules
-               
-       fDistToBadTower = minDist;
-       //printf("AliEMCALRecPoint::EvalDistanceToBadChannel() - Distance to Bad is %f cm, shared cluster? %d \n",fDistToBadTower,fSharedCluster);
+      }
+    }
+    
+  }// shared cluster in 2 SuperModules
+  
+  fDistToBadTower = minDist;
+  //printf("AliEMCALRecPoint::EvalDistanceToBadChannel() - Distance to Bad is %f cm, shared cluster? %d \n",fDistToBadTower,fSharedCluster);
 }
 
 
 //____________________________________________________________________________
 void AliEMCALRecPoint::EvalLocalPosition(Float_t logWeight, TClonesArray * digits)
 {
-       // Calculates the center of gravity in the local EMCAL-module coordinates 
-       //  Info("Print", " logWeight %f : cluster energy %f ", logWeight, fAmp); // for testing
-               
-       AliEMCALDigit * digit=0;
-       Int_t i=0, nstat=0;
-       
-       static Double_t dist  = TmaxInCm(Double_t(fAmp));
-       //Int_t idMax = GetAbsIdMaxDigit();// idMax is not used at all in RelPosCellInSModule, why use it?
-       
-       Double_t clXYZ[3]={0.,0.,0.}, clRmsXYZ[3]={0.,0.,0.}, xyzi[3], wtot=0., w=0.;
-       
-       //printf(" dist : %f  e : %f \n", dist, fAmp);
-       for(Int_t iDigit=0; iDigit<fMulDigit; iDigit++) {
-               digit = dynamic_cast<AliEMCALDigit *>(digits->At(fDigitsList[iDigit])) ;
-
-               //fGeomPtr->RelPosCellInSModule(digit->GetId(), idMax, dist, xyzi[0], xyzi[1], xyzi[2]);
-               fGeomPtr->RelPosCellInSModule(digit->GetId(), dist, xyzi[0], xyzi[1], xyzi[2]);
-               
-               //Temporal patch, due to mapping problem, need to swap "y" in one of the 2 SM, although no effect in position calculation. GCB 05/2010
-               if(fSharedCluster && fSuperModuleNumber != fGeomPtr->GetSuperModuleNumber(digit->GetId())) xyzi[1]*=-1;
-               
-               //printf("EvalLocalPosition Cell:  Id %i, SM %i : dist %f Local x,y,z %f %f %f \n", 
-               //              digit->GetId(), fGeomPtr->GetSuperModuleNumber(digit->GetId()), dist, xyzi[0], xyzi[1], xyzi[2]);
-               
-               if(logWeight > 0.0)  w = TMath::Max( 0., logWeight + TMath::Log( fEnergyList[iDigit] / fAmp ));
-               else  w = fEnergyList[iDigit]; // just energy
-               
-               if(w>0.0) {
-                       wtot += w ;
-                       nstat++;
-                       for(i=0; i<3; i++ ) {
-                               clXYZ[i]    += (w*xyzi[i]);
-                               clRmsXYZ[i] += (w*xyzi[i]*xyzi[i]);
-                       }
-               }
-       }
-       //  cout << " wtot " << wtot << endl;
-       if ( wtot > 0 ) { 
-               //    xRMS   = TMath::Sqrt(x2m - xMean*xMean);
-               for(i=0; i<3; i++ ) {
-                       clXYZ[i] /= wtot;
-                       if(nstat>1) {
-                               clRmsXYZ[i] /= (wtot*wtot);  
-                               clRmsXYZ[i]  =  clRmsXYZ[i] - clXYZ[i]*clXYZ[i];
-                               if(clRmsXYZ[i] > 0.0) {
-                                       clRmsXYZ[i] =  TMath::Sqrt(clRmsXYZ[i]);
-                               } else      clRmsXYZ[i] = 0;
-                       } else        clRmsXYZ[i] = 0;
-               }    
-       } else {
-               for(i=0; i<3; i++ ) {
-                       clXYZ[i] = clRmsXYZ[i] = -1.;
-               }
-       }
-       // clRmsXYZ[i] ??
-       
-//     // Cluster of one single digit, smear the position to avoid discrete position
-//     // smear x and z with +- 3 cm to uniform (avoid discrete effects). Tower size is approx 6 cm.
-//     // Rndm generates a number in ]0,1]
-//     if (fMulDigit==1) { 
-//       clXYZ[0] += fGeomPtr->GetPhiTileSize()*(0.5 - gRandom->Rndm()); 
-//       clXYZ[2] += fGeomPtr->GetEtaTileSize()*(0.5 - gRandom->Rndm()); 
-//     }
-       
-       //Set position in local vector
-       fLocPos.SetX(clXYZ[0]);
-       fLocPos.SetY(clXYZ[1]);
-       fLocPos.SetZ(clXYZ[2]);
-               
-       if (gDebug==2)
-               printf("EvalLocalPosition Cluster: Local (x,y,z) = (%f,%f,%f) \n", fLocPos.X(), fLocPos.Y(), fLocPos.Z()) ; 
-
+  // Calculates the center of gravity in the local EMCAL-module coordinates 
+  //  Info("Print", " logWeight %f : cluster energy %f ", logWeight, fAmp); // for testing
+  
+  AliEMCALDigit * digit=0;
+  Int_t i=0, nstat=0;
+  
+  Double_t dist  = TmaxInCm(Double_t(fAmp));
+  //Int_t      idMax = GetAbsIdMaxDigit();// idMax is not used at all in RelPosCellInSModule, why use it?
+  
+  Double_t clXYZ[3]={0.,0.,0.}, clRmsXYZ[3]={0.,0.,0.}, xyzi[3], wtot=0., w=0.;
+  
+  //printf(" dist : %f  e : %f \n", dist, fAmp);
+  for(Int_t iDigit=0; iDigit<fMulDigit; iDigit++) {
+    digit = dynamic_cast<AliEMCALDigit *>(digits->At(fDigitsList[iDigit])) ;
+    
+    if(!digit) {
+      AliError("No Digit!!");
+      continue;
+    }
+    
+    //fGeomPtr->RelPosCellInSModule(digit->GetId(), idMax, dist, xyzi[0], xyzi[1], xyzi[2]);
+    fGeomPtr->RelPosCellInSModule(digit->GetId(), dist, xyzi[0], xyzi[1], xyzi[2]);
+    
+    //Temporal patch, due to mapping problem, need to swap "y" in one of the 2 SM, although no effect in position calculation. GCB 05/2010
+    if(fSharedCluster && fSuperModuleNumber != fGeomPtr->GetSuperModuleNumber(digit->GetId())) xyzi[1]*=-1;
+    
+    //printf("EvalLocalPosition Cell:  Id %i, SM %i : dist %f Local x,y,z %f %f %f \n", 
+    //         digit->GetId(), fGeomPtr->GetSuperModuleNumber(digit->GetId()), dist, xyzi[0], xyzi[1], xyzi[2]);
+    
+    if(logWeight > 0.0)  w = TMath::Max( 0., logWeight + TMath::Log( fEnergyList[iDigit] / fAmp ));
+    else  w = fEnergyList[iDigit]; // just energy
+    
+    if(w>0.0) {
+      wtot += w ;
+      nstat++;
+      for(i=0; i<3; i++ ) {
+       clXYZ[i]    += (w*xyzi[i]);
+       clRmsXYZ[i] += (w*xyzi[i]*xyzi[i]);
+      }
+    }
+  }
+  //  cout << " wtot " << wtot << endl;
+  if ( wtot > 0 ) { 
+    //    xRMS   = TMath::Sqrt(x2m - xMean*xMean);
+    for(i=0; i<3; i++ ) {
+      clXYZ[i] /= wtot;
+      if(nstat>1) {
+       clRmsXYZ[i] /= (wtot*wtot);  
+       clRmsXYZ[i]  =  clRmsXYZ[i] - clXYZ[i]*clXYZ[i];
+       if(clRmsXYZ[i] > 0.0) {
+         clRmsXYZ[i] =  TMath::Sqrt(clRmsXYZ[i]);
+       } else      clRmsXYZ[i] = 0;
+      } else        clRmsXYZ[i] = 0;
+    }    
+  } else {
+    for(i=0; i<3; i++ ) {
+      clXYZ[i] = clRmsXYZ[i] = -1.;
+    }
+  }
+  // clRmsXYZ[i] ??
+  
+  //   // Cluster of one single digit, smear the position to avoid discrete position
+  //   // smear x and z with +- 3 cm to uniform (avoid discrete effects). Tower size is approx 6 cm.
+  //   // Rndm generates a number in ]0,1]
+  //   if (fMulDigit==1) { 
+  //     clXYZ[0] += fGeomPtr->GetPhiTileSize()*(0.5 - gRandom->Rndm()); 
+  //     clXYZ[2] += fGeomPtr->GetEtaTileSize()*(0.5 - gRandom->Rndm()); 
+  //   }
+  
+  //Set position in local vector
+  fLocPos.SetX(clXYZ[0]);
+  fLocPos.SetY(clXYZ[1]);
+  fLocPos.SetZ(clXYZ[2]);
+  
+  if (gDebug==2)
+    printf("EvalLocalPosition Cluster: Local (x,y,z) = (%f,%f,%f) \n", fLocPos.X(), fLocPos.Y(), fLocPos.Z()) ; 
+  
 }
 
 
@@ -741,7 +748,7 @@ void AliEMCALRecPoint::EvalGlobalPosition(Float_t logWeight, TClonesArray * digi
   AliEMCALDigit * digit=0;
   Int_t i=0, nstat=0;
        
-  static Double_t dist  = TmaxInCm(Double_t(fAmp));
+  Double_t dist  = TmaxInCm(Double_t(fAmp));
   //Int_t      idMax = GetAbsIdMaxDigit();// idMax is not used at all in RelPosCellInSModule, why use it?
        
   Double_t clXYZ[3]={0.,0.,0.}, clRmsXYZ[3]={0.,0.,0.}, lxyzi[3], xyzi[3], wtot=0., w=0.;
@@ -750,6 +757,11 @@ void AliEMCALRecPoint::EvalGlobalPosition(Float_t logWeight, TClonesArray * digi
   for(Int_t iDigit=0; iDigit<fMulDigit; iDigit++) {
     digit = dynamic_cast<AliEMCALDigit *>(digits->At(fDigitsList[iDigit])) ;
 
+    if(!digit) {
+      AliError("No Digit!!");
+      continue;
+    }    
+    
     //Get the local coordinates of the cell
     //fGeomPtr->RelPosCellInSModule(digit->GetId(), idMax, dist, lxyzi[0], lxyzi[1], lxyzi[2]);
     fGeomPtr->RelPosCellInSModule(digit->GetId(), dist, lxyzi[0], lxyzi[1], lxyzi[2]);
@@ -814,35 +826,36 @@ void AliEMCALRecPoint::EvalGlobalPosition(Float_t logWeight, TClonesArray * digi
 void AliEMCALRecPoint::EvalLocalPositionFit(Double_t deff, Double_t logWeight, 
 Double_t phiSlope, TClonesArray * digits)
 {
-  // Aug 14-16, 2007 - for fit 
-  // Aug 31 - should be static ??
-  static Double_t ycorr=0;
-  static AliEMCALDigit *digit=0;
+  // Evaluates local position of clusters in SM
+  
+  Double_t ycorr=0;
+  AliEMCALDigit *digit=0;
   Int_t i=0, nstat=0;
   Double_t clXYZ[3]={0.,0.,0.}, clRmsXYZ[3]={0.,0.,0.}, xyzi[3], wtot=0., w=0.; 
 
-  static Double_t dist  = TmaxInCm(Double_t(fAmp));
+  Double_t dist  = TmaxInCm(Double_t(fAmp));
   //Int_t      idMax = GetAbsIdMaxDigit();// idMax is not used at all in RelPosCellInSModule, why use it?
        
   for(Int_t iDigit=0; iDigit<digits->GetEntries(); iDigit++) {
     digit = dynamic_cast<AliEMCALDigit *>(digits->At(fDigitsList[iDigit])) ;
-    dist = deff;
-    //fGeomPtr->RelPosCellInSModule(digit->GetId(), idMax, dist, xyzi[0], xyzi[1], xyzi[2]);
-    fGeomPtr->RelPosCellInSModule(digit->GetId(), dist, xyzi[0], xyzi[1], xyzi[2]);
-    
-    if(logWeight > 0.0)  w = TMath::Max( 0., logWeight + TMath::Log( fEnergyList[iDigit] / fAmp ));
-    else                 w = fEnergyList[iDigit]; // just energy
-    
-    if(w>0.0) {
-      wtot += w ;
-      nstat++;
-      for(i=0; i<3; i++ ) {
-        clXYZ[i]    += (w*xyzi[i]);
-        clRmsXYZ[i] += (w*xyzi[i]*xyzi[i]);
+    if(digit){
+      dist = deff;
+      //fGeomPtr->RelPosCellInSModule(digit->GetId(), idMax, dist, xyzi[0], xyzi[1], xyzi[2]);
+      fGeomPtr->RelPosCellInSModule(digit->GetId(), dist, xyzi[0], xyzi[1], xyzi[2]);
+      
+      if(logWeight > 0.0)  w = TMath::Max( 0., logWeight + TMath::Log( fEnergyList[iDigit] / fAmp ));
+      else                 w = fEnergyList[iDigit]; // just energy
+      
+      if(w>0.0) {
+        wtot += w ;
+        nstat++;
+        for(i=0; i<3; i++ ) {
+          clXYZ[i]    += (w*xyzi[i]);
+          clRmsXYZ[i] += (w*xyzi[i]*xyzi[i]);
+        }
       }
-    }
-  }
+    }else AliError("Digit null");
+  }//loop
   //  cout << " wtot " << wtot << endl;
   if ( wtot > 0 ) { 
     //    xRMS   = TMath::Sqrt(x2m - xMean*xMean);
@@ -891,9 +904,9 @@ Bool_t AliEMCALRecPoint::EvalLocalPosition2(TClonesArray * digits, TArrayD &ed)
 Bool_t AliEMCALRecPoint::EvalLocalPositionFromDigits(TClonesArray *digits, TArrayD &ed, TVector3 &locPos)
 {
   // Used when digits should be recalibrated
-  static Double_t deff=0, w0=0, esum=0;
-  static Int_t iDigit=0;
-  //  static AliEMCALDigit *digit;
+  Double_t deff=0, w0=0, esum=0;
+  Int_t iDigit=0;
+  //  AliEMCALDigit *digit;
 
   if(ed.GetSize() && (digits->GetEntries()!=ed.GetSize())) return kFALSE;
 
@@ -910,7 +923,7 @@ Bool_t AliEMCALRecPoint::EvalLocalPositionFromDigits(TClonesArray *digits, TArra
 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.
-  static AliEMCALDigit *digit=0;
+  AliEMCALDigit *digit=0;
 
   Int_t i=0, nstat=0;
   Double_t clXYZ[3]={0.,0.,0.}, xyzi[3], wtot=0., w=0.; 
@@ -922,21 +935,22 @@ Bool_t AliEMCALRecPoint::EvalLocalPositionFromDigits(const Double_t esum, const
 
   for(Int_t iDigit=0; iDigit<digits->GetEntries(); iDigit++) {
     digit = dynamic_cast<AliEMCALDigit *>(digits->At(iDigit));
-
-    //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]);
+    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++ ) {
@@ -962,7 +976,7 @@ void AliEMCALRecPoint::GetDeffW0(const Double_t esum , Double_t &deff,  Double_t
   // 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
   //
-  static Double_t e=0.0;
+  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;
 
@@ -1014,7 +1028,7 @@ void  AliEMCALRecPoint::EvalElipsAxis(Float_t logWeight,TClonesArray * digits)
   // Calculates the axis of the shower ellipsoid in eta and phi
   // in cell units
 
-  static TString gn(fGeomPtr->GetName());
+  TString gn(fGeomPtr->GetName());
 
   Double_t wtot = 0.;
   Double_t x    = 0.;
@@ -1098,42 +1112,49 @@ void  AliEMCALRecPoint::EvalPrimaries(TClonesArray * digits)
   // Constructs the list of primary particles (tracks) which 
   // have contributed to this RecPoint and calculate deposited energy 
   // for each track
-  
+    
   AliEMCALDigit * digit =0;
   Int_t * primArray = new Int_t[fMaxTrack] ;
+  memset(primArray,-1,sizeof(Int_t)*fMaxTrack);
   Float_t * dEPrimArray = new Float_t[fMaxTrack] ;
-
+  memset(dEPrimArray,-1,sizeof(Int_t)*fMaxTrack);
+  
   Int_t index ;  
   for ( index = 0 ; index < GetDigitsMultiplicity() ; index++ ) { // all digits
     digit = dynamic_cast<AliEMCALDigit *>(digits->At( fDigitsList[index] )) ; 
+    if(!digit) {
+      AliError("No Digit!!");
+      continue;
+    }
+    
     Int_t nprimaries = digit->GetNprimary() ;
     if ( nprimaries == 0 ) continue ;
     Int_t jndex ;
     for ( jndex = 0 ; jndex < nprimaries ; jndex++ ) { // all primaries in digit
       if ( fMulTrack > fMaxTrack ) {
-       fMulTrack = fMaxTrack ;
-       Error("EvalPrimaries", "increase fMaxTrack ")  ;
-       break ;
+        fMulTrack = fMaxTrack ;
+        Error("EvalPrimaries", "increase fMaxTrack ")  ;
+        break ;
       }
       Int_t newPrimary = digit->GetPrimary(jndex+1);
       Float_t dEPrimary = digit->GetDEPrimary(jndex+1);
       Int_t kndex ;
       Bool_t already = kFALSE ;
       for ( kndex = 0 ; kndex < fMulTrack ; kndex++ ) { //check if not already stored
-       if ( newPrimary == primArray[kndex] ){
-         already = kTRUE ;
-         dEPrimArray[kndex] += dEPrimary; 
-         break ;
-       }
+        if ( newPrimary == primArray[kndex] ){
+          already = kTRUE ;
+          dEPrimArray[kndex] += dEPrimary; 
+          break ;
+        }
       } // end of check
       if ( !already && (fMulTrack < fMaxTrack)) { // store it
-       primArray[fMulTrack] = newPrimary ; 
-       dEPrimArray[fMulTrack] = dEPrimary ; 
-       fMulTrack++ ;
+        primArray[fMulTrack] = newPrimary ; 
+        dEPrimArray[fMulTrack] = dEPrimary ; 
+        fMulTrack++ ;
       } // store it
     } // all primaries in digit
   } // all digits
-
+  
   Int_t *sortIdx = new Int_t[fMulTrack];
   TMath::Sort(fMulTrack,dEPrimArray,sortIdx); 
   for(index = 0; index < fMulTrack; index++) {
@@ -1143,52 +1164,59 @@ void  AliEMCALRecPoint::EvalPrimaries(TClonesArray * digits)
   delete [] sortIdx;
   delete [] primArray ;
   delete [] dEPrimArray ;
-
+  
 }
 
 //______________________________________________________________________________
 void  AliEMCALRecPoint::EvalParents(TClonesArray * digits)
 {
   // Constructs the list of parent particles (tracks) which have contributed to this RecPoint
+
   AliEMCALDigit * digit=0 ;
   Int_t * parentArray = new Int_t[fMaxTrack] ;
+  memset(parentArray,-1,sizeof(Int_t)*fMaxTrack);
   Float_t * dEParentArray = new Float_t[fMaxTrack] ;
-
+  memset(dEParentArray,-1,sizeof(Int_t)*fMaxTrack);
+  
   Int_t index ;  
   for ( index = 0 ; index < GetDigitsMultiplicity() ; index++ ) { // all digits
     if (fDigitsList[index] >= digits->GetEntries() || fDigitsList[index] < 0)
-       AliError(Form("Trying to get invalid digit %d (idx in WriteRecPoint %d)",fDigitsList[index],index));
+      AliError(Form("Trying to get invalid digit %d (idx in WriteRecPoint %d)",fDigitsList[index],index));
     digit = dynamic_cast<AliEMCALDigit *>(digits->At( fDigitsList[index] )) ; 
+    if(!digit) {
+      AliError("No Digit!!");
+      continue;
+    }
+    
     Int_t nparents = digit->GetNiparent() ;
     if ( nparents == 0 ) continue ;
-
+    
     Int_t jndex ;
     for ( jndex = 0 ; jndex < nparents ; jndex++ ) { // all primaries in digit
       if ( fMulParent > fMaxParent ) {
-       fMulTrack = - 1 ;
-       Error("EvalParents", "increase fMaxParent")  ;
-       break ;
+        fMulTrack = - 1 ;
+        Error("EvalParents", "increase fMaxParent")  ;
+        break ;
       }
       Int_t newParent = digit->GetIparent(jndex+1) ;
       Float_t newdEParent = digit->GetDEParent(jndex+1) ;
       Int_t kndex ;
       Bool_t already = kFALSE ;
       for ( kndex = 0 ; kndex < fMulParent ; kndex++ ) { //check if not already stored
-       if ( newParent == parentArray[kndex] ){
-         dEParentArray[kndex] += newdEParent;
-         already = kTRUE ;
-         break ;
-       }
+        if ( newParent == parentArray[kndex] ){
+          dEParentArray[kndex] += newdEParent;
+          already = kTRUE ;
+          break ;
+        }
       } // end of check
       if ( !already && (fMulParent < fMaxParent)) { // store it
-       parentArray[fMulParent] = newParent ; 
-       dEParentArray[fMulParent] = newdEParent ; 
-       fMulParent++ ;
+        parentArray[fMulParent] = newParent ; 
+        dEParentArray[fMulParent] = newdEParent ; 
+        fMulParent++ ;
       } // store it
     } // all parents in digit
   } // all digits
-
+  
   if (fMulParent>0) {
     Int_t *sortIdx = new Int_t[fMulParent];
     TMath::Sort(fMulParent,dEParentArray,sortIdx); 
@@ -1198,7 +1226,7 @@ void  AliEMCALRecPoint::EvalParents(TClonesArray * digits)
     }
     delete [] sortIdx;
   }
+  
   delete [] parentArray;
   delete [] dEParentArray;
 }
@@ -1256,10 +1284,10 @@ void AliEMCALRecPoint::EvalLocal2TrackingCSTransform()
   SetX(txyz[0]); SetY(txyz[1]); SetZ(txyz[2]);
 
   if(AliLog::GetGlobalDebugLevel()>0) {
-       TVector3 gpos; //TMatrixF gmat;
+    TVector3 gpos; //TMatrixF gmat;
     //GetGlobalPosition(gpos,gmat); //Not doing anythin special, replace by next line. 
-       fGeomPtr->GetGlobal(fLocPos, gpos, GetSuperModuleNumber());
-         
+    fGeomPtr->GetGlobal(fLocPos, gpos, GetSuperModuleNumber());
+    
     Float_t gxyz[3];
     GetGlobalXYZ(gxyz);
     AliInfo(Form("lCS-->(%.3f,%.3f,%.3f), tCS-->(%.3f,%.3f,%.3f), gCS-->(%.3f,%.3f,%.3f),  gCScalc-\
@@ -1431,9 +1459,12 @@ Double_t AliEMCALRecPoint::TmaxInCm(const Double_t e , const Int_t key)
   // e energy in GeV)
   // key  =  0(gamma, default)
   //     !=  0(electron)
-  static Double_t ca   = 4.82;  // shower max parameter - first guess; ca=TMath::Log(1000./8.07)
-  static Double_t x0   = 1.23;  // radiation lenght (cm)
-  static Double_t tmax = 0.;    // position of electromagnetic shower max in cm
+  const Double_t ca   = 4.82;  // shower max parameter - first guess; ca=TMath::Log(1000./8.07)
+  Double_t tmax = 0.;    // position of electromagnetic shower max in cm
+
+  Double_t x0   = 1.31;  // radiation lenght (cm)
+  //If old geometry in use
+  if(!((fGeomPtr->GetEMCGeometry()->GetGeoName()).Contains("V1"))) x0 = 1.28;
 
   if(e>0.1) {
     tmax = TMath::Log(e) + ca;
@@ -1466,24 +1497,24 @@ void AliEMCALRecPoint::Print(Option_t *opt) const
   TString message ; 
   message  = "AliEMCALRecPoint:\n" ;
   message +=  " digits # = " ; 
-  Info("Print", message.Data()) ; 
+  AliInfo(message.Data()) ; 
 
   Int_t iDigit;
   for(iDigit=0; iDigit<fMulDigit; iDigit++)
     printf(" %d ", fDigitsList[iDigit] ) ;  
   printf("\n");
 
-  Info("Print", " Energies = ") ;
+  AliInfo(" Energies = ") ;
   for(iDigit=0; iDigit<fMulDigit; iDigit++) 
     printf(" %f ", fEnergyList[iDigit] ) ;
   printf("\n");
 
-  Info("Print", "\n Abs Ids = ") ;
+  AliInfo("\n Abs Ids = ") ;
   for(iDigit=0; iDigit<fMulDigit; iDigit++) 
     printf(" %i ", fAbsIdList[iDigit] ) ;
   printf("\n");
 
-  Info("Print", " Primaries  ") ;
+  AliInfo(" Primaries  ") ;
   for(iDigit = 0;iDigit < fMulTrack; iDigit++)
     printf(" %d ", fTracksList[iDigit]) ;
 
@@ -1496,14 +1527,14 @@ void AliEMCALRecPoint::Print(Option_t *opt) const
   message += "       Core radius     = %f" ; 
   message += "       Number of primaries %d" ; 
   message += "       Stored at position %d" ; 
-  Info("Print", message.Data(), fClusterType, fMulDigit, fAmp, fCoreEnergy, fCoreRadius, fMulTrack, GetIndexInList() ) ;  
+  AliInfo(Form(message.Data(), fClusterType, fMulDigit, fAmp, fCoreEnergy, fCoreRadius, fMulTrack, GetIndexInList()) ) ;  
 }
 
 //___________________________________________________________
 Double_t  AliEMCALRecPoint::GetPointEnergy() const
 {
   //Returns energy ....
-  static double e=0.0;
+  Double_t e=0.0;
   for(int ic=0; ic<GetMultiplicity(); ic++) e += double(fEnergyList[ic]);
   return e;
 }