+
+ if (!gGeoManager){
+ AliFatal("Geo manager not initialized\n");
+ }
+ //construct module name
+ char path[100] ;
+ if(relid[1]==0){ //this is PHOS
+
+// Calculations using ideal geometry (obsolete)
+// x = - ( GetNPhi()/2. - relid[2] + 0.5 ) * GetCellStep() ; // position of Xtal with respect
+// z = - ( GetNZ() /2. - relid[3] + 0.5 ) * GetCellStep() ; // of center of PHOS module
+
+ Double_t pos[3]= {0.0,-fCryCellShift,0.}; //Position incide the crystal
+ Double_t posC[3]={0.0,0.0,0.}; //Global position
+
+ //Shift and possibly apply misalignment corrections
+ Int_t nCellsXInStrip=fGeometryEMCA->GetNCellsXInStrip() ;
+ Int_t nCellsZInStrip=fGeometryEMCA->GetNCellsZInStrip() ;
+// Int_t strip=1+(relid[3]-1)/fGeometryEMCA->GetNCellsZInStrip()+((relid[2]-1)/nCellsInStrip)*fGeometryEMCA->GetNStripZ() ;
+ Int_t strip=1+((Int_t) TMath::Ceil((Double_t)relid[2]/nCellsXInStrip))*fGeometryEMCA->GetNStripZ()-
+ (Int_t) TMath::Ceil((Double_t)relid[3]/nCellsZInStrip) ;
+ Int_t cellraw= relid[3]%nCellsZInStrip ;
+ if(cellraw==0)cellraw=nCellsZInStrip ;
+ Int_t cell= ((relid[2]-1)%nCellsXInStrip)*nCellsZInStrip + cellraw ;
+ sprintf(path,"/ALIC_1/PHOS_%d/PEMC_1/PCOL_1/PTIO_1/PCOR_1/PAGA_1/PTII_1/PSTR_%d/PCEL_%d",
+ relid[0],strip,cell) ;
+ if (!gGeoManager->cd(path)){
+ AliFatal("Geo manager can not find path \n");
+ }
+ TGeoHMatrix *m = gGeoManager->GetCurrentMatrix();
+ if (m) m->LocalToMaster(pos,posC);
+ else{
+ AliFatal("Geo matrixes are not loaded \n") ;
+ }
+ //Return to PHOS local system
+ Double_t posL[3]={posC[0],posC[1],posC[2]};
+ sprintf(path,"/ALIC_1/PHOS_%d",relid[0]) ;
+ if (!gGeoManager->cd(path)){
+ AliFatal("Geo manager can not find path \n");
+ }
+ TGeoHMatrix *mPHOS = gGeoManager->GetCurrentMatrix();
+ if (mPHOS) mPHOS->MasterToLocal(posC,posL);
+ else{
+ AliFatal("Geo matrixes are not loaded \n") ;
+ }
+//printf("RelPosInMod: posL=[%f,%f,%f]\n",posL[0],posL[1],posL[2]) ;
+//printf("old: x=%f, z=%f \n",x,z);
+ x=posL[0] ;
+ z=posL[1];
+ return ;
+ }
+ else{//CPV
+ //first calculate position with respect to CPV plain
+ Int_t row = relid[2] ; //offset along x axis
+ Int_t column = relid[3] ; //offset along z axis
+ Double_t pos[3]= {0.0,0.0,0.}; //Position incide the CPV printed circuit
+ Double_t posC[3]={0.0,0.0,0.}; //Global position
+ pos[0] = - ( GetNumberOfCPVPadsPhi()/2. - row - 0.5 ) * GetPadSizePhi() ; // position of pad with respect
+ pos[2] = - ( GetNumberOfCPVPadsZ() /2. - column - 0.5 ) * GetPadSizeZ() ; // of center of PHOS module
+
+ //now apply possible shifts and rotations
+ sprintf(path,"/ALIC_1/PHOS_%d/PCPV_1",relid[0]) ;
+ if (!gGeoManager->cd(path)){
+ AliFatal("Geo manager can not find path \n");
+ }
+ TGeoHMatrix *m = gGeoManager->GetCurrentMatrix();
+ if (m) m->LocalToMaster(pos,posC);
+ else{
+ AliFatal("Geo matrixes are not loaded \n") ;
+ }
+ //Return to PHOS local system
+ Double_t posL[3]={0.,0.,0.,} ;
+ sprintf(path,"/ALIC_1/PHOS_%d",relid[0]) ;
+ if (!gGeoManager->cd(path)){
+ AliFatal("Geo manager can not find path \n");
+ }
+ TGeoHMatrix *mPHOS = gGeoManager->GetCurrentMatrix();
+ if (mPHOS) mPHOS->MasterToLocal(posC,posL);
+ else{
+ AliFatal("Geo matrixes are not loaded \n") ;
+ }
+ x=posL[0] ;
+ z=posL[1];
+ return ;
+
+ }