]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PHOS/AliPHOSv0.cxx
made abstract functions in AliVVvertex non-abstract, becasue AliFlatESDVertex does...
[u/mrichter/AliRoot.git] / PHOS / AliPHOSv0.cxx
index 19489c12f66edd7c197151bf86dff95820500d57..2341f1f6993d4e613068e5288679e8817eab94ed 100644 (file)
  * about the suitability of this software for any purpose. It is          *
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
+/* $Id$ */
+
+/* History of cvs commits:
+ *
+ * $Log$
+ * Revision 1.94  2007/10/18 08:40:02  kharlov
+ * Misalignment-related bug fixed
+ *
+ * Revision 1.93  2007/10/06 22:24:40  kharlov
+ * Bug in strip unit geometry is corrected
+ *
+ * Revision 1.92  2007/07/04 16:38:19  policheh
+ * Tracking2LocalCS matrices corrected for CPV.
+ *
+ * Revision 1.91  2007/07/02 14:50:49  policheh
+ * Tracking2LocalCS matrices corrected.
+ *
+ * Revision 1.90  2007/05/24 13:04:05  policheh
+ * AddAlignableVolumes: local to tracking CS transformation matrices creates for each
+ * PHOS supermodule
+ *
+ * Revision 1.89  2007/04/24 14:34:39  hristov
+ * Additional protection: do not search for alignable object if the CPV is not in the geometry
+ *
+ * Revision 1.88  2007/04/19 15:28:30  kharlov
+ * Modify strip unit geometry according to the final drawings (Timur)
+ *
+ * Revision 1.87  2007/04/01 07:37:10  kharlov
+ * TGeo RS to Local RS transf matr added
+ *
+ * Revision 1.86  2007/03/06 06:55:46  kharlov
+ * DP:Misalignment of CPV added
+ *
+ * Revision 1.85  2007/03/01 11:37:37  kharlov
+ * Strip units changed from 8x1 to 8x2 (T.Pocheptsov)
+ *
+ * Revision 1.84  2006/12/20 16:56:43  kharlov
+ * Optional geometry without CPV
+ *
+ * Revision 1.83  2006/11/14 17:11:15  hristov
+ * Removing inheritances from TAttLine, TAttMarker and AliRndm in AliModule. The copy constructor and assignment operators are moved to the private part of the class and not implemented. The corresponding changes are propagated to the detectors
+ *
+ * Revision 1.82  2006/09/27 19:55:57  kharlov
+ * Alignment object with symbolic volume names are introduced
+ *
+ * Revision 1.81  2006/03/04 20:25:56  kharlov
+ * Set geom parameters from CDB
+ *
+ * Revision 1.80  2005/06/17 07:39:07  hristov
+ * Removing GetDebug and SetDebug from AliRun and AliModule. Using AliLog for the messages
+ *
+ * Revision 1.79  2005/05/28 14:19:05  schutz
+ * Compilation warnings fixed by T.P.
+ *
+ */
 
 //_________________________________________________________________________
-// Manager class for PHOS version SUBATECH
-//*-- Author : Y. Schutz SUBATECH 
-//////////////////////////////////////////////////////////////////////////////
+// Implementation version v0 of PHOS Manager class 
+// An object of this class does not produce hits nor digits
+// It is the one to use if you do not want to produce outputs in TREEH or TREED
+//                  
+//*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
+
 
 // --- ROOT system ---
 
-#include "TBRIK.h"
-#include "TNode.h"
+#include <TFolder.h>
+#include <TGeometry.h>
+#include <TROOT.h>
+#include <TRandom.h>
+#include <TTree.h>
+#include <TVirtualMC.h>
+#include <TGeoPhysicalNode.h>
+#include <TGeoManager.h>
+#include <TGeoMatrix.h>
+#include <TVector3.h>
 
 // --- Standard library ---
 
-#include <cstdio>
-#include <cstring>
-#include <cstdlib>
-#include <strstream>
-#include <cassert>
+#include <string.h>
+#include <stdlib.h>
 
 // --- AliRoot header files ---
 
+#include "AliConst.h"
+#include "AliPHOSGeometry.h"
+#include "AliPHOSLoader.h"
 #include "AliPHOSv0.h"
-#include "AliPHOSHit.h"
-#include "AliPHOSDigit.h"
-#include "AliPHOSReconstructioner.h"
 #include "AliRun.h"
-#include "AliConst.h"
+#include "AliLog.h"
+#include "AliGeomManager.h"
 
 ClassImp(AliPHOSv0)
 
-//____________________________________________________________________________
-AliPHOSv0::AliPHOSv0()
-{
-  fNTmpHits = 0 ; 
-  fTmpHits  = 0 ; 
-}
-
 //____________________________________________________________________________
 AliPHOSv0::AliPHOSv0(const char *name, const char *title):
   AliPHOS(name,title)
 {
-  
-  // We use 2 arrays of hits :
-  //
-  //   - fHits (the "normal" one), which retains the hits associated with
-  //     the current primary particle being tracked
-  //     (this array is reset after each primary has been tracked).
-  //
-  //   - fTmpHits, which retains all the hits of the current event. It 
-  //     is used for the digitization part.
-
-  fHits   = new TClonesArray("AliPHOSHit",100) ;
-  gAlice->AddHitList(fHits) ; 
-
-  fTmpHits= new TClonesArray("AliPHOSHit",100) ;
-
-  fNTmpHits = fNhits = 0 ;
-
-  fDigits = new TClonesArray("AliPHOSDigit",100) ;
-
-
-  fIshunt     =  1 ; // All hits are associated with primary particles
-  // gets an instance of the geometry parameters class  
-   
-  fGeom =  AliPHOSGeometry::GetInstance(title, "") ; 
-
-  if (fGeom->IsInitialized() ) 
-    cout << "AliPHOSv0 : PHOS geometry intialized for " << fGeom->GetName() << endl ;
-  else
-   cout << "AliPHOSv0 : PHOS geometry initialization failed !" << endl ;   
-}
-//____________________________________________________________________________
-AliPHOSv0::AliPHOSv0(AliPHOSReconstructioner * Reconstructioner, const char *name, const char *title):
-  AliPHOS(name,title)
-{
-  
-  // We use 2 arrays of hits :
-  //
-  //   - fHits (the "normal" one), which retains the hits associated with
-  //     the current primary particle being tracked
-  //     (this array is reset after each primary has been tracked).
-  //
-  //   - fTmpHits, which retains all the hits of the current event. It 
-  //     is used for the digitization part.
-
-  fHits   = new TClonesArray("AliPHOSHit",100) ;
-  fDigits = new TClonesArray("AliPHOSDigit",100) ;
-  fTmpHits= new TClonesArray("AliPHOSHit",100) ;
-
-  fNTmpHits = fNhits = 0 ;
-
-  fIshunt     =  1 ; // All hits are associated with primary particles
-  // gets an instance of the geometry parameters class  
-  fGeom =  AliPHOSGeometry::GetInstance(title, "") ; 
-
-  if (fGeom->IsInitialized() ) 
-    cout << "AliPHOSv0 : PHOS geometry intialized for " << fGeom->GetName() << endl ;
-  else
-   cout << "AliPHOSv0 : PHOS geometry initialization failed !" << endl ;   
-
-  // Defining the PHOS Reconstructioner
- fReconstructioner = Reconstructioner ;
-}
-
-//____________________________________________________________________________
-AliPHOSv0::~AliPHOSv0()
-{
-  fTmpHits->Delete() ; 
-  delete fTmpHits ;
-  fTmpHits = 0 ; 
-
-  fEmcClusters->Delete() ; 
-  delete fEmcClusters ; 
-  fEmcClusters = 0 ; 
-
-  fPpsdClusters->Delete() ;
-  delete fPpsdClusters ;
-  fPpsdClusters = 0 ; 
-
-  fTrackSegments->Delete() ; 
-  delete fTrackSegments ;
-  fTrackSegments = 0 ; 
-}
-
-//____________________________________________________________________________
-void AliPHOSv0::AddHit(Int_t track, Int_t Id, Float_t * hits)
-{
-  Int_t hitCounter ;
-  TClonesArray &ltmphits = *fTmpHits ;
-  AliPHOSHit *newHit ;
-  AliPHOSHit *curHit ;
-  Bool_t deja = false ;
-
-  // In any case, fills the fTmpHit TClonesArray (with "accumulated hits")
-
-  newHit = new AliPHOSHit(fIshunt, track, Id, hits) ;
-
-  for ( hitCounter = 0 ; hitCounter < fNTmpHits && !deja ; hitCounter++ ) {
-    curHit = (AliPHOSHit*) ltmphits[hitCounter] ;
-    if( *curHit == *newHit ) {
-      *curHit = *curHit + *newHit ;
-      deja = true ;
-    }
-  }
-       
-  if ( !deja ) {
-    new(ltmphits[fNTmpHits]) AliPHOSHit(*newHit) ;
-    fNTmpHits++ ;
-  }
-
-  // Please note that the fTmpHits array must survive up to the
-  // end of the events, so it does not appear e.g. in ResetHits() (
-  // which is called at the end of each primary).  
-
-  //  if (IsTreeSelected('H')) {
-    // And, if we really want raw hits tree, have the fHits array filled also
-  //    TClonesArray &lhits = *fHits;
-  //    new(lhits[fNhits]) AliPHOSHit(*newHit) ;
-  //    fNhits++ ;
-  //  }
-
-   delete newHit;
-
-}
-
-
-//____________________________________________________________________________
-void AliPHOSv0::BuildGeometry()
-{
-
-  this->BuildGeometryforPHOS() ; 
-  if ( ( strcmp(fGeom->GetName(), "GPS2" ) == 0 ) ) 
-    this->BuildGeometryforPPSD() ;
-  else
-    cout << "AliPHOSv0::BuildGeometry : no charged particle identification system installed" << endl; 
-
-}
-
-//____________________________________________________________________________
-void AliPHOSv0:: BuildGeometryforPHOS(void)
-{
- // Build the PHOS geometry for the ROOT display
-
-  const Int_t kColorPHOS = kRed ;
-  const Int_t kColorXTAL = kBlue ;
-
-  Double_t const kRADDEG = 180.0 / kPI ;
-  new TBRIK( "OuterBox", "PHOS box", "void", fGeom->GetOuterBoxSize(0)/2, 
-                                             fGeom->GetOuterBoxSize(1)/2, 
-                                             fGeom->GetOuterBoxSize(2)/2 );
-
-  // Textolit Wall box, position inside PHOS 
-  
-  new TBRIK( "TextolitBox", "PHOS Textolit box ", "void", fGeom->GetTextolitBoxSize(0)/2, 
-                                                          fGeom->GetTextolitBoxSize(1)/2, 
-                                                          fGeom->GetTextolitBoxSize(2)/2);
-
-  // Polystyrene Foam Plate
-
-  new TBRIK( "UpperFoamPlate", "PHOS Upper foam plate", "void", fGeom->GetTextolitBoxSize(0)/2, 
-                                                                fGeom->GetSecondUpperPlateThickness()/2, 
-                                                                fGeom->GetTextolitBoxSize(2)/2 ) ; 
-
-  // Air Filled Box
-  new TBRIK( "AirFilledBox", "PHOS air filled box", "void", fGeom->GetAirFilledBoxSize(0)/2, 
-                                                            fGeom->GetAirFilledBoxSize(1)/2, 
-                                                            fGeom->GetAirFilledBoxSize(2)/2 );
-
-  // Crystals Box
-
-  Float_t xtlX = fGeom->GetCrystalSize(0) ; 
-  Float_t xtlY = fGeom->GetCrystalSize(1) ; 
-  Float_t xtlZ = fGeom->GetCrystalSize(2) ; 
-
-  Float_t xl =  fGeom->GetNPhi() * ( xtlX + 2 * fGeom->GetGapBetweenCrystals() ) / 2.0 + fGeom->GetModuleBoxThickness() ;
-  Float_t yl =  ( xtlY + fGeom->GetCrystalSupportHeight() + fGeom->GetCrystalWrapThickness() + fGeom->GetCrystalHolderThickness() ) / 2.0 
-             + fGeom->GetModuleBoxThickness() / 2.0 ;
-  Float_t zl =  fGeom->GetNZ() * ( xtlZ + 2 * fGeom->GetGapBetweenCrystals() ) / 2.0 +  fGeom->GetModuleBoxThickness() ;
-  
-  new TBRIK( "CrystalsBox", "PHOS crystals box", "void", xl, yl, zl ) ;
-
-// position PHOS into ALICE
-
-  Float_t r = fGeom->GetIPtoOuterCoverDistance() + fGeom->GetOuterBoxSize(1) / 2.0 ;
-  Int_t number = 988 ; 
-  Float_t pphi =  TMath::ATan( fGeom->GetOuterBoxSize(0)  / ( 2.0 * fGeom->GetIPtoOuterCoverDistance() ) ) ;
-  pphi *= kRADDEG ;
-  TNode * top = gAlice->GetGeometry()->GetNode("alice") ;
-  char * nodename = new char[20] ;  
-  char * rotname  = new char[20] ; 
-
-  for( Int_t i = 1; i <= fGeom->GetNModules(); i++ ) { 
-   Float_t angle = pphi * 2 * ( i - fGeom->GetNModules() / 2.0 - 0.5 ) ;
-   sprintf(rotname, "%s%d", "rot", number++) ;
-   new TRotMatrix(rotname, rotname, 90, angle, 90, 90 + angle, 0, 0);
-   top->cd();
-   sprintf(nodename,"%s%d", "Module", i) ;    
-   Float_t x =  r * TMath::Sin( angle / kRADDEG ) ;
-   Float_t y = -r * TMath::Cos( angle / kRADDEG ) ;
-   TNode * outerboxnode = new TNode(nodename, nodename, "OuterBox", x, y, 0, rotname ) ;
-   outerboxnode->SetLineColor(kColorPHOS) ;
-   fNodes->Add(outerboxnode) ;
-   outerboxnode->cd() ; 
-   // now inside the outer box the textolit box
-   y = ( fGeom->GetOuterBoxThickness(1) -  fGeom->GetUpperPlateThickness() ) / 2.  ;
-   sprintf(nodename,"%s%d", "TexBox", i) ;  
-   TNode * textolitboxnode = new TNode(nodename, nodename, "TextolitBox", 0, y, 0) ; 
-   textolitboxnode->SetLineColor(kColorPHOS) ;
-   fNodes->Add(textolitboxnode) ;
-   // upper foam plate inside outre box
-   outerboxnode->cd() ; 
-   sprintf(nodename, "%s%d", "UFPlate", i) ;
-   y =  ( fGeom->GetTextolitBoxSize(1) - fGeom->GetSecondUpperPlateThickness() ) / 2.0 ;
-   TNode * upperfoamplatenode = new TNode(nodename, nodename, "UpperFoamPlate", 0, y, 0) ; 
-   upperfoamplatenode->SetLineColor(kColorPHOS) ;
-   fNodes->Add(upperfoamplatenode) ;  
-   // air filled box inside textolit box (not drawn)
-   textolitboxnode->cd();
-   y = ( fGeom->GetTextolitBoxSize(1) - fGeom->GetAirFilledBoxSize(1) ) / 2.0 -  fGeom->GetSecondUpperPlateThickness() ;
-   sprintf(nodename, "%s%d", "AFBox", i) ;
-   TNode * airfilledboxnode = new TNode(nodename, nodename, "AirFilledBox", 0, y, 0) ; 
-   fNodes->Add(airfilledboxnode) ; 
-   // crystals box inside air filled box
-   airfilledboxnode->cd() ; 
-   y = fGeom->GetAirFilledBoxSize(1) / 2.0 - yl 
-       - ( fGeom->GetIPtoCrystalSurface() - fGeom->GetIPtoOuterCoverDistance() - fGeom->GetModuleBoxThickness() 
-       -  fGeom->GetUpperPlateThickness() -  fGeom->GetSecondUpperPlateThickness() ) ; 
-   sprintf(nodename, "%s%d", "XTBox", i) ; 
-   TNode * crystalsboxnode = new TNode(nodename, nodename, "CrystalsBox", 0, y, 0) ;    
-   crystalsboxnode->SetLineColor(kColorXTAL) ; 
-   fNodes->Add(crystalsboxnode) ; 
-  }
-}
-
-//____________________________________________________________________________
-void AliPHOSv0:: BuildGeometryforPPSD(void)
-{
- //  Build the PPSD geometry for the ROOT display
-
-  Double_t const kRADDEG = 180.0 / kPI ;
-
-  const Int_t kColorPHOS = kRed ;
-  const Int_t kColorPPSD = kGreen ;
-  const Int_t kColorGas  = kBlue ;  
-  const Int_t kColorAir  = kYellow ; 
-
-  // Box for a full PHOS module
-
-  new TBRIK( "PPSDBox", "PPSD box", "void",  fGeom->GetPPSDBoxSize(0)/2, 
-                                             fGeom->GetPPSDBoxSize(1)/2, 
-                                            fGeom->GetPPSDBoxSize(2)/2 );
-
-  // Box containing one micromegas module 
-
-  new TBRIK( "PPSDModule", "PPSD module", "void",  fGeom->GetPPSDModuleSize(0)/2, 
-                                                   fGeom->GetPPSDModuleSize(1)/2, 
-                                                  fGeom->GetPPSDModuleSize(2)/2 );
- // top lid
-
-  new TBRIK ( "TopLid", "Micromegas top lid", "void",  fGeom->GetPPSDModuleSize(0)/2,
-                                                       fGeom->GetLidThickness()/2,
-                                                       fGeom->GetPPSDModuleSize(2)/2 ) ; 
- // composite panel (top and bottom)
-
-  new TBRIK ( "TopPanel", "Composite top panel", "void",  ( fGeom->GetPPSDModuleSize(0) - fGeom->GetMicromegasWallThickness() )/2,
-                                                            fGeom->GetCompositeThickness()/2,
-                                                          ( fGeom->GetPPSDModuleSize(2) - fGeom->GetMicromegasWallThickness() )/2 ) ;  
-  
-  new TBRIK ( "BottomPanel", "Composite bottom panel", "void",  ( fGeom->GetPPSDModuleSize(0) - fGeom->GetMicromegasWallThickness() )/2,
-                                                                  fGeom->GetCompositeThickness()/2,
-                                                                ( fGeom->GetPPSDModuleSize(2) - fGeom->GetMicromegasWallThickness() )/2 ) ; 
- // gas gap (conversion and avalanche)
-
-  new TBRIK ( "GasGap", "gas gap", "void",  ( fGeom->GetPPSDModuleSize(0) - fGeom->GetMicromegasWallThickness() )/2,
-                                           ( fGeom->GetConversionGap() +  fGeom->GetAvalancheGap() )/2,
-                                            ( fGeom->GetPPSDModuleSize(2) - fGeom->GetMicromegasWallThickness() )/2 ) ; 
-
- // anode and cathode 
-
-  new TBRIK ( "Anode", "Anode", "void",  ( fGeom->GetPPSDModuleSize(0) - fGeom->GetMicromegasWallThickness() )/2,
-                                           fGeom->GetAnodeThickness()/2,
-                                         ( fGeom->GetPPSDModuleSize(2) - fGeom->GetMicromegasWallThickness() )/2 ) ; 
-
-  new TBRIK ( "Cathode", "Cathode", "void",  ( fGeom->GetPPSDModuleSize(0) - fGeom->GetMicromegasWallThickness() )/2,
-                                               fGeom->GetCathodeThickness()/2,
-                                             ( fGeom->GetPPSDModuleSize(2) - fGeom->GetMicromegasWallThickness() )/2 ) ; 
- // PC  
-
-  new TBRIK ( "PCBoard", "Printed Circuit", "void",  ( fGeom->GetPPSDModuleSize(0) - fGeom->GetMicromegasWallThickness() )/2,
-                                                       fGeom->GetPCThickness()/2,
-                                                     ( fGeom->GetPPSDModuleSize(2) - fGeom->GetMicromegasWallThickness() )/2 ) ; 
- // Gap between Lead and top micromegas
-
-  new TBRIK ( "LeadToM", "Air Gap top", "void", fGeom->GetPPSDBoxSize(0)/2,
-                                                fGeom->GetMicro1ToLeadGap()/2,
-                                                fGeom->GetPPSDBoxSize(2)/2  ) ;  
-// Gap between Lead and bottom micromegas
-
-  new TBRIK ( "MToLead", "Air Gap bottom", "void", fGeom->GetPPSDBoxSize(0)/2,
-                                                   fGeom->GetLeadToMicro2Gap()/2,
-                                                   fGeom->GetPPSDBoxSize(2)/2  ) ; 
- // Lead converter
-   
-  new TBRIK ( "Lead", "Lead converter", "void", fGeom->GetPPSDBoxSize(0)/2,
-                                                fGeom->GetLeadConverterThickness()/2,
-                                                fGeom->GetPPSDBoxSize(2)/2  ) ; 
-
-     // position PPSD into ALICE
-
-  char * nodename = new char[20] ;  
-  char * rotname  = new char[20] ; 
-
-  Float_t r = fGeom->GetIPtoTopLidDistance() + fGeom->GetPPSDBoxSize(1) / 2.0 ;
-  Int_t number = 988 ; 
-  TNode * top = gAlice->GetGeometry()->GetNode("alice") ;
-  for( Int_t i = 1; i <= fGeom->GetNModules(); i++ ) { // the number of PHOS modules
-    Float_t angle = fGeom->GetPHOSAngle(i) ;
-    sprintf(rotname, "%s%d", "rotg", number++) ;
-    new TRotMatrix(rotname, rotname, 90, angle, 90, 90 + angle, 0, 0);
-    top->cd();
-    sprintf(nodename, "%s%d", "Moduleg", i) ;    
-    Float_t x =  r * TMath::Sin( angle / kRADDEG ) ;
-    Float_t y = -r * TMath::Cos( angle / kRADDEG ) ;
-    TNode * ppsdboxnode = new TNode(nodename , nodename ,"PPSDBox", x, y, 0, rotname ) ;
-    ppsdboxnode->SetLineColor(kColorPPSD) ;
-    fNodes->Add(ppsdboxnode) ;
-    ppsdboxnode->cd() ;
-    // inside the PPSD box: 
-    //   1.   fNumberOfModulesPhi x fNumberOfModulesZ top micromegas
-    x = ( fGeom->GetPPSDBoxSize(0) - fGeom->GetPPSDModuleSize(0) ) / 2. ;  
-    for ( Int_t iphi = 1; iphi <= fGeom->GetNumberOfModulesPhi(); iphi++ ) { // the number of micromegas modules in phi per PHOS module
-      Float_t z = ( fGeom->GetPPSDBoxSize(2) - fGeom->GetPPSDModuleSize(2) ) / 2. ;
-      TNode * micro1node ; 
-      for ( Int_t iz = 1; iz <= fGeom->GetNumberOfModulesZ(); iz++ ) { // the number of micromegas modules in z per PHOS module
-       y = ( fGeom->GetPPSDBoxSize(1) - fGeom->GetMicromegas1Thickness() ) / 2. ; 
-       sprintf(nodename, "%s%d%d%d", "Mic1", i, iphi, iz) ;
-       micro1node  = new TNode(nodename, nodename, "PPSDModule", x, y, z) ;
-       micro1node->SetLineColor(kColorPPSD) ;  
-       fNodes->Add(micro1node) ; 
-       // inside top micromegas
-       micro1node->cd() ; 
-       //      a. top lid
-       y = ( fGeom->GetMicromegas1Thickness() - fGeom->GetLidThickness() ) / 2. ; 
-       sprintf(nodename, "%s%d%d%d", "Lid", i, iphi, iz) ;
-       TNode * toplidnode = new TNode(nodename, nodename, "TopLid", 0, y, 0) ;
-       toplidnode->SetLineColor(kColorPPSD) ;  
-       fNodes->Add(toplidnode) ; 
-       //      b. composite panel
-       y = y - fGeom->GetLidThickness() / 2. - fGeom->GetCompositeThickness() / 2. ; 
-       sprintf(nodename, "%s%d%d%d", "CompU", i, iphi, iz) ;
-       TNode * compupnode = new TNode(nodename, nodename, "TopPanel", 0, y, 0) ;
-       compupnode->SetLineColor(kColorPPSD) ;  
-       fNodes->Add(compupnode) ; 
-       //      c. anode
-       y = y - fGeom->GetCompositeThickness() / 2. - fGeom->GetAnodeThickness()  / 2. ; 
-       sprintf(nodename, "%s%d%d%d", "Ano", i, iphi, iz) ;
-       TNode * anodenode = new TNode(nodename, nodename, "Anode", 0, y, 0) ;
-       anodenode->SetLineColor(kColorPHOS) ;  
-       fNodes->Add(anodenode) ; 
-       //      d.  gas 
-       y = y - fGeom->GetAnodeThickness() / 2. - ( fGeom->GetConversionGap() +  fGeom->GetAvalancheGap() ) / 2. ; 
-       sprintf(nodename, "%s%d%d%d", "GGap", i, iphi, iz) ;
-       TNode * ggapnode = new TNode(nodename, nodename, "GasGap", 0, y, 0) ;
-       ggapnode->SetLineColor(kColorGas) ;  
-       fNodes->Add(ggapnode) ;          
-         //      f. cathode
-       y = y - ( fGeom->GetConversionGap() +  fGeom->GetAvalancheGap() ) / 2. - fGeom->GetCathodeThickness()  / 2. ; 
-       sprintf(nodename, "%s%d%d%d", "Cathode", i, iphi, iz) ;
-       TNode * cathodenode = new TNode(nodename, nodename, "Cathode", 0, y, 0) ;
-       cathodenode->SetLineColor(kColorPHOS) ;  
-       fNodes->Add(cathodenode) ;        
-       //      g. printed circuit
-       y = y - fGeom->GetCathodeThickness() / 2. - fGeom->GetPCThickness()  / 2. ; 
-       sprintf(nodename, "%s%d%d%d", "PC", i, iphi, iz) ;
-       TNode * pcnode = new TNode(nodename, nodename, "PCBoard", 0, y, 0) ;
-       pcnode->SetLineColor(kColorPPSD) ;  
-       fNodes->Add(pcnode) ;        
-       //      h. composite panel
-       y = y - fGeom->GetPCThickness() / 2. - fGeom->GetCompositeThickness()  / 2. ; 
-       sprintf(nodename, "%s%d%d%d", "CompDown", i, iphi, iz) ;
-       TNode * compdownnode = new TNode(nodename, nodename, "BottomPanel", 0, y, 0) ;
-       compdownnode->SetLineColor(kColorPPSD) ;  
-       fNodes->Add(compdownnode) ;   
-       z = z - fGeom->GetPPSDModuleSize(2) ;
-       ppsdboxnode->cd() ;
-      } // end of Z module loop     
-      x = x -  fGeom->GetPPSDModuleSize(0) ; 
-      ppsdboxnode->cd() ;
-    } // end of phi module loop
-    //   2. air gap      
-    ppsdboxnode->cd() ;
-    y = ( fGeom->GetPPSDBoxSize(1) - 2 * fGeom->GetMicromegas1Thickness() - fGeom->GetMicro1ToLeadGap() ) / 2. ; 
-    sprintf(nodename, "%s%d", "GapUp", i) ;
-    TNode * gapupnode = new TNode(nodename, nodename, "LeadToM", 0, y, 0) ;
-    gapupnode->SetLineColor(kColorAir) ;  
-    fNodes->Add(gapupnode) ;        
-    //   3. lead converter
-    y = y - fGeom->GetMicro1ToLeadGap() / 2. - fGeom->GetLeadConverterThickness() / 2. ; 
-    sprintf(nodename, "%s%d", "LeadC", i) ;
-    TNode * leadcnode = new TNode(nodename, nodename, "Lead", 0, y, 0) ;
-    leadcnode->SetLineColor(kColorPPSD) ;  
-    fNodes->Add(leadcnode) ;        
-    //   4. air gap
-    y = y - fGeom->GetLeadConverterThickness() / 2. - fGeom->GetLeadToMicro2Gap()  / 2. ; 
-    sprintf(nodename, "%s%d", "GapDown", i) ;
-    TNode * gapdownnode = new TNode(nodename, nodename, "MToLead", 0, y, 0) ;
-    gapdownnode->SetLineColor(kColorAir) ;  
-    fNodes->Add(gapdownnode) ;        
-    //    5.  fNumberOfModulesPhi x fNumberOfModulesZ bottom micromegas
-    x = ( fGeom->GetPPSDBoxSize(0) - fGeom->GetPPSDModuleSize(0) ) / 2. - fGeom->GetPhiDisplacement() ;  
-    for ( Int_t iphi = 1; iphi <= fGeom->GetNumberOfModulesPhi(); iphi++ ) { 
-      Float_t z = ( fGeom->GetPPSDBoxSize(2) - fGeom->GetPPSDModuleSize(2) ) / 2.  - fGeom->GetZDisplacement() ;;
-      TNode * micro2node ; 
-      for ( Int_t iz = 1; iz <= fGeom->GetNumberOfModulesZ(); iz++ ) { 
-       y = - ( fGeom->GetPPSDBoxSize(1) - fGeom->GetMicromegas2Thickness() ) / 2. ; 
-       sprintf(nodename, "%s%d%d%d", "Mic2", i, iphi, iz) ;
-       micro2node  = new TNode(nodename, nodename, "PPSDModule", x, y, z) ;
-       micro2node->SetLineColor(kColorPPSD) ;  
-       fNodes->Add(micro2node) ; 
-       // inside bottom micromegas
-       micro2node->cd() ; 
-         //      a. top lid
-         y = ( fGeom->GetMicromegas2Thickness() - fGeom->GetLidThickness() ) / 2. ; 
-         sprintf(nodename, "%s%d", "Lidb", i) ;
-         TNode * toplidbnode = new TNode(nodename, nodename, "TopLid", 0, y, 0) ;
-         toplidbnode->SetLineColor(kColorPPSD) ;  
-         fNodes->Add(toplidbnode) ; 
-         //      b. composite panel
-         y = y - fGeom->GetLidThickness() / 2. - fGeom->GetCompositeThickness() / 2. ; 
-         sprintf(nodename, "%s%d", "CompUb", i) ;
-         TNode * compupbnode = new TNode(nodename, nodename, "TopPanel", 0, y, 0) ;
-         compupbnode->SetLineColor(kColorPPSD) ;  
-         fNodes->Add(compupbnode) ; 
-         //      c. anode
-         y = y - fGeom->GetCompositeThickness() / 2. - fGeom->GetAnodeThickness()  / 2. ; 
-         sprintf(nodename, "%s%d", "Anob", i) ;
-         TNode * anodebnode = new TNode(nodename, nodename, "Anode", 0, y, 0) ;
-         anodebnode->SetLineColor(kColorPPSD) ;  
-         fNodes->Add(anodebnode) ; 
-         //      d. conversion gas
-         y = y - fGeom->GetAnodeThickness() / 2. - ( fGeom->GetConversionGap() +  fGeom->GetAvalancheGap() )  / 2. ; 
-         sprintf(nodename, "%s%d", "GGapb", i) ;
-         TNode * ggapbnode = new TNode(nodename, nodename, "GasGap", 0, y, 0) ;
-         ggapbnode->SetLineColor(kColorGas) ;  
-         fNodes->Add(ggapbnode) ;           
-         //      f. cathode
-         y = y - ( fGeom->GetConversionGap() + fGeom->GetAvalancheGap() ) / 2. - fGeom->GetCathodeThickness()  / 2. ; 
-         sprintf(nodename, "%s%d", "Cathodeb", i) ;
-         TNode * cathodebnode = new TNode(nodename, nodename, "Cathode", 0, y, 0) ;
-         cathodebnode->SetLineColor(kColorPPSD) ;  
-         fNodes->Add(cathodebnode) ;        
-         //      g. printed circuit
-         y = y - fGeom->GetCathodeThickness() / 2. - fGeom->GetPCThickness()  / 2. ; 
-         sprintf(nodename, "%s%d", "PCb", i) ;
-         TNode * pcbnode = new TNode(nodename, nodename, "PCBoard", 0, y, 0) ;
-         pcbnode->SetLineColor(kColorPPSD) ;  
-         fNodes->Add(pcbnode) ;        
-         //      h. composite pane
-         y = y - fGeom->GetPCThickness() / 2. - fGeom->GetCompositeThickness()  / 2. ; 
-         sprintf(nodename, "%s%d", "CompDownb", i) ;
-         TNode * compdownbnode = new TNode(nodename, nodename, "BottomPanel", 0, y, 0) ;
-         compdownbnode->SetLineColor(kColorPPSD) ;  
-         fNodes->Add(compdownbnode) ;        
-                 z = z - fGeom->GetPPSDModuleSize(2) ;
-         ppsdboxnode->cd() ;
-       } // end of Z module loop     
-       x = x -  fGeom->GetPPSDModuleSize(0) ; 
-       ppsdboxnode->cd() ;
-       } // end of phi module loop
-     } // PHOS modules
- delete rotname ; 
- delete nodename ; 
+  // ctor : title is used to identify the layout
+  GetGeometry() ; 
 }
 
 //____________________________________________________________________________
 void AliPHOSv0::CreateGeometry()
 {
+  // Create the PHOS geometry for Geant
 
-  AliPHOSv0 *phostmp = (AliPHOSv0*)gAlice->GetModule("PHOS") ;
+  AliPHOSv0 *phostmp = dynamic_cast<AliPHOSv0*>(gAlice->GetModule("PHOS")) ;
 
   if ( phostmp == NULL ) {
     
@@ -547,659 +128,857 @@ void AliPHOSv0::CreateGeometry()
     
   }
 
+  AliPHOSGeometry * geom = GetGeometry() ; 
+
   // Get pointer to the array containing media indeces
   Int_t *idtmed = fIdtmed->GetArray() - 699 ;
 
-  Float_t bigbox[3] ; 
-  bigbox[0] =   fGeom->GetOuterBoxSize(0) / 2.0 ;
-  bigbox[1] = ( fGeom->GetOuterBoxSize(1) + fGeom->GetPPSDBoxSize(1) ) / 2.0 ;
-  bigbox[2] =   fGeom->GetOuterBoxSize(2) / 2.0 ;
+  // Create a PHOS module.
+  
+  TVirtualMC::GetMC()->Gsvolu("PHOS", "TRD1", idtmed[798], geom->GetPHOSParams(), 4) ;        
   
-  gMC->Gsvolu("PHOS", "BOX ", idtmed[798], bigbox, 3) ;
+  this->CreateGeometryforEMC() ; 
+
+  if (strstr(fTitle.Data(),"noCPV") == 0) 
+    this->CreateGeometryforCPV() ;
   
-  this->CreateGeometryforPHOS() ; 
-  if ( strcmp( fGeom->GetName(), "GPS2") == 0  ) 
-    this->CreateGeometryforPPSD() ;
-  else
-    cout << "AliPHOSv0::CreateGeometry : no charged particle identification system installed" << endl; 
+  this->CreateGeometryforSupport() ; 
   
   // --- Position  PHOS mdules in ALICE setup ---
-  
   Int_t idrotm[99] ;
-  Double_t const kRADDEG = 180.0 / kPI ;
-  
-  for( Int_t i = 1; i <= fGeom->GetNModules(); i++ ) {
+  Int_t iXYZ,iAngle;
+  char im[5] ;
+  Bool_t anyModuleCreated=0 ;
+  for (Int_t iModule = 0; iModule < 5 ; iModule++ ) {
+    snprintf(im,5,"%d",iModule+1) ;
+    if(strstr(GetTitle(),im)==0 && strcmp(GetTitle(),"IHEP")!=0 && strcmp(GetTitle(),"noCPV")!=0)
+      continue ;
+    anyModuleCreated=1 ;
+    Float_t angle[3][2];
+    for (iXYZ=0; iXYZ<3; iXYZ++)
+      for (iAngle=0; iAngle<2; iAngle++)
+       angle[iXYZ][iAngle] = geom->GetModuleAngle(iModule,iXYZ, iAngle);
+    AliMatrix(idrotm[iModule],
+             angle[0][0],angle[0][1],
+             angle[1][0],angle[1][1],
+             angle[2][0],angle[2][1]) ;
     
-    Float_t angle = fGeom->GetPHOSAngle(i) ;
-    AliMatrix(idrotm[i-1], 90.0, angle, 90.0, 90.0+angle, 0.0, 0.0) ;
-    Float_t r = fGeom->GetIPtoOuterCoverDistance() + ( fGeom->GetOuterBoxSize(1) + fGeom->GetPPSDBoxSize(1) ) / 2.0 ;
-
-    Float_t xP1 = r * TMath::Sin( angle / kRADDEG ) ;
-    Float_t yP1 = -r * TMath::Cos( angle / kRADDEG ) ;
-
-    gMC->Gspos("PHOS", i, "ALIC", xP1, yP1, 0.0, idrotm[i-1], "ONLY") ;
-  } // for GetNModules
-
+    Float_t pos[3];
+    for (iXYZ=0; iXYZ<3; iXYZ++)
+      pos[iXYZ] = geom->GetModuleCenter(iModule,iXYZ);
+    TVirtualMC::GetMC()->Gspos("PHOS", iModule+1, "ALIC", pos[0], pos[1], pos[2],
+              idrotm[iModule], "ONLY") ;
+  }
+  if(!anyModuleCreated)
+    AliError("No one PHOS module was created") ;
 }
 
 //____________________________________________________________________________
-void AliPHOSv0::CreateGeometryforPHOS()
+void AliPHOSv0::CreateGeometryforEMC()
 {
-  // Get pointer to the array containing media indeces
+  // Create the PHOS-EMC geometry for GEANT
+  // Author: Dmitri Peressounko August 2001
+  // The used coordinate system: 
+  //   1. in Module: X along longer side, Y out of beam, Z along shorter side (along beam)
+  //   2. In Strip the same: X along longer side, Y out of beam, Z along shorter side (along beam)
+
+
+    //BEGIN_HTML
+  /*
+    <H2>
+    Geant3 geometry tree of PHOS-EMC in ALICE
+    </H2>
+    <P><CENTER>
+    <IMG Align=BOTTOM ALT="EMC geant tree" SRC="../images/EMCinAlice.gif"> 
+    </CENTER><P>
+  */
+  //END_HTML  
+  
+  // Get pointer to the array containing media indexes
   Int_t *idtmed = fIdtmed->GetArray() - 699 ;
 
-  // ---
-  // --- Define PHOS box volume, fPUFPill with thermo insulating foam ---
-  // --- Foam Thermo Insulating outer cover dimensions ---
-  // --- Put it in bigbox = PHOS
+  AliPHOSGeometry * geom = GetGeometry() ; 
+  AliPHOSEMCAGeometry * emcg = geom->GetEMCAGeometry() ;
+  Float_t par[4];
+  Int_t  ipar;
 
-  Float_t dphos[3] ; 
-  dphos[0] =  fGeom->GetOuterBoxSize(0) / 2.0 ;
-  dphos[1] =  fGeom->GetOuterBoxSize(1) / 2.0 ;
-  dphos[2] =  fGeom->GetOuterBoxSize(2) / 2.0 ;
+  // ======= Define the strip ===============
 
-  gMC->Gsvolu("EMCA", "BOX ", idtmed[706], dphos, 3) ;
-
-  Float_t yO =  - fGeom->GetPPSDBoxSize(1)  / 2.0 ;
-
-  gMC->Gspos("EMCA", 1, "PHOS", 0.0, yO, 0.0, 0, "ONLY") ; 
-
-  // ---
-  // --- Define Textolit Wall box, position inside EMCA ---
-  // --- Textolit Wall box dimentions ---
+  for (ipar=0; ipar<3; ipar++) par[ipar] = *(emcg->GetStripHalfSize() + ipar);
+  TVirtualMC::GetMC()->Gsvolu("PSTR", "BOX ", idtmed[716], par, 3) ;  //Made of steel
+   
+  // --- define steel volume (cell of the strip unit)
+  for (ipar=0; ipar<3; ipar++) par[ipar] = *(emcg->GetAirCellHalfSize() + ipar);
+  TVirtualMC::GetMC()->Gsvolu("PCEL", "BOX ", idtmed[798], par, 3);
+
+  // --- define wrapped crystal and put it into steel cell
+
+  for (ipar=0; ipar<3; ipar++) par[ipar] = *(emcg->GetWrappedHalfSize() + ipar);
+  TVirtualMC::GetMC()->Gsvolu("PWRA", "BOX ", idtmed[702], par, 3);
+  const Float_t * pin    = emcg->GetAPDHalfSize() ; 
+  const Float_t * preamp = emcg->GetPreampHalfSize() ;
+  Float_t y = (emcg->GetAirGapLed()-2*pin[1]-2*preamp[1])/2;
+  TVirtualMC::GetMC()->Gspos("PWRA", 1, "PCEL", 0.0, y, 0.0, 0, "ONLY") ;
+    
+  // --- Define crystal and put it into wrapped crystall ---
+  for (ipar=0; ipar<3; ipar++) par[ipar] = *(emcg->GetCrystalHalfSize() + ipar);
+  TVirtualMC::GetMC()->Gsvolu("PXTL", "BOX ", idtmed[699], par, 3) ;
+  TVirtualMC::GetMC()->Gspos("PXTL", 1, "PWRA", 0.0, 0.0, 0.0, 0, "ONLY") ;
+      
+  // --- define APD/PIN preamp and put it into AirCell
  
-  Float_t dptxw[3];
-  dptxw[0] = fGeom->GetTextolitBoxSize(0) / 2.0 ;
-  dptxw[1] = fGeom->GetTextolitBoxSize(1) / 2.0 ;
-  dptxw[2] = fGeom->GetTextolitBoxSize(2) / 2.0 ;
-
-  gMC->Gsvolu("PTXW", "BOX ", idtmed[707], dptxw, 3);
+  for (ipar=0; ipar<3; ipar++) par[ipar] = *(emcg->GetAPDHalfSize() + ipar);
+  TVirtualMC::GetMC()->Gsvolu("PPIN", "BOX ", idtmed[705], par, 3) ;
+  const Float_t * crystal = emcg->GetCrystalHalfSize() ;
+  y = crystal[1] + emcg->GetAirGapLed() /2 - preamp[1]; 
+  TVirtualMC::GetMC()->Gspos("PPIN", 1, "PCEL", 0.0, y, 0.0, 0, "ONLY") ;
+  for (ipar=0; ipar<3; ipar++) par[ipar] = *(emcg->GetPreampHalfSize() + ipar);
+  TVirtualMC::GetMC()->Gsvolu("PREA", "BOX ", idtmed[711], par, 3) ;   // Here I assumed preamp as a printed Circuit
+  y = crystal[1] + emcg->GetAirGapLed() /2 + pin[1]  ;    // May it should be changed
+  TVirtualMC::GetMC()->Gspos("PREA", 1, "PCEL", 0.0, y, 0.0, 0, "ONLY") ; // to ceramics?
+  
+  
+  // --- Fill strip with wrapped cristals in steel cells
+  
+  const Float_t* splate = emcg->GetSupportPlateHalfSize();  
+  y = -splate[1] ;
+  const Float_t* acel = emcg->GetAirCellHalfSize() ;
+  
+  for(Int_t lev = 2, icel = 1; 
+      icel <= emcg->GetNCellsXInStrip()*emcg->GetNCellsZInStrip(); 
+      icel += 2, lev += 2) {
+    Float_t x = (2*(lev / 2) - 1 - emcg->GetNCellsXInStrip())* acel[0] ;
+    Float_t z = acel[2];
+    TVirtualMC::GetMC()->Gspos("PCEL", icel, "PSTR", x, y, +z, 0, "ONLY") ;
+    TVirtualMC::GetMC()->Gspos("PCEL", icel + 1, "PSTR", x, y, -z, 0, "ONLY") ;
+  }
 
-  yO =   (  fGeom->GetOuterBoxThickness(1) -   fGeom->GetUpperPlateThickness() ) / 2.  ;
-   
-  gMC->Gspos("PTXW", 1, "EMCA", 0.0, yO, 0.0, 0, "ONLY") ;
+  // --- define the support plate, hole in it and position it in strip ----
+  for (ipar=0; ipar<3; ipar++) par[ipar] = *(emcg->GetSupportPlateHalfSize() + ipar);
+  TVirtualMC::GetMC()->Gsvolu("PSUP", "BOX ", idtmed[701], par, 3) ;
+  
+  for (ipar=0; ipar<3; ipar++) par[ipar] = *(emcg->GetSupportPlateInHalfSize() + ipar);
+  TVirtualMC::GetMC()->Gsvolu("PSHO", "BOX ", idtmed[798], par, 3) ;
+  Float_t z = emcg->GetSupportPlateThickness()/2 ;
+  TVirtualMC::GetMC()->Gspos("PSHO", 1, "PSUP", 0.0, 0.0, z, 0, "ONLY") ;
 
-  // --- 
-  // --- Define Upper Polystyrene Foam Plate, place inside PTXW ---
-  // --- immediately below Foam Thermo Insulation Upper plate ---
+  y = acel[1] ;
+  TVirtualMC::GetMC()->Gspos("PSUP", 1, "PSTR", 0.0, y, 0.0, 0, "ONLY") ;
 
-  // --- Upper Polystyrene Foam plate thickness ---
-  Float_t  dpufp[3] ;
-  dpufp[0] = fGeom->GetTextolitBoxSize(0) / 2.0 ; 
-  dpufp[1] = fGeom->GetSecondUpperPlateThickness() / 2. ;
-  dpufp[2] = fGeom->GetTextolitBoxSize(2) /2.0 ; 
-
-  gMC->Gsvolu("PUFP", "BOX ", idtmed[703], dpufp, 3) ;
   
-  yO = ( fGeom->GetTextolitBoxSize(1) -  fGeom->GetSecondUpperPlateThickness() ) / 2.0 ;
+  // ========== Fill module with strips and put them into inner thermoinsulation=============
+  for (ipar=0; ipar<3; ipar++) par[ipar] = *(emcg->GetInnerThermoHalfSize() + ipar);
+  TVirtualMC::GetMC()->Gsvolu("PTII", "BOX ", idtmed[706], par, 3) ;     
   
-  gMC->Gspos("PUFP", 1, "PTXW", 0.0, yO, 0.0, 0, "ONLY") ;
+  const Float_t * inthermo = emcg->GetInnerThermoHalfSize() ;
+  const Float_t * strip    = emcg->GetStripHalfSize() ;
+  y = inthermo[1] - strip[1] ;
+  Int_t irow;
+  Int_t nr = 1 ;
+  Int_t icol ;
   
-  // ---
-  // --- Define air-filled box, place inside PTXW ---
-  // --- Inner AIR volume dimensions ---
-
-  Float_t  dpair[3] ;
-  dpair[0] = fGeom->GetAirFilledBoxSize(0) / 2.0 ;
-  dpair[1] = fGeom->GetAirFilledBoxSize(1) / 2.0 ;
-  dpair[2] = fGeom->GetAirFilledBoxSize(2) / 2.0 ;
-
-  gMC->Gsvolu("PAIR", "BOX ", idtmed[798], dpair, 3) ;
+  for(irow = 0; irow < emcg->GetNStripX(); irow ++){
+    Float_t x = (2*irow + 1 - emcg->GetNStripX())* strip[0] ;
+    for(icol = 0; icol < emcg->GetNStripZ(); icol ++){
+      z = (2*icol + 1 - emcg->GetNStripZ()) * strip[2] ;
+      TVirtualMC::GetMC()->Gspos("PSTR", nr, "PTII", x, y, z, 0, "ONLY") ;
+      nr++ ;
+    }
+  }
   
-  yO = ( fGeom->GetTextolitBoxSize(1) -  fGeom->GetAirFilledBoxSize(1) ) / 2.0 -   fGeom->GetSecondUpperPlateThickness() ;
   
-  gMC->Gspos("PAIR", 1, "PTXW", 0.0, yO, 0.0, 0, "ONLY") ;
-
-// --- Dimensions of PbWO4 crystal ---
-
-  Float_t xtlX =  fGeom->GetCrystalSize(0) ; 
-  Float_t xtlY =  fGeom->GetCrystalSize(1) ; 
-  Float_t xtlZ =  fGeom->GetCrystalSize(2) ; 
-
-  Float_t dptcb[3] ;  
-  dptcb[0] =  fGeom->GetNPhi() * ( xtlX + 2 *  fGeom->GetGapBetweenCrystals() ) / 2.0 + fGeom->GetModuleBoxThickness() ;
-  dptcb[1] = ( xtlY +  fGeom->GetCrystalSupportHeight() +  fGeom->GetCrystalWrapThickness() + fGeom->GetCrystalHolderThickness() ) / 2.0 
-             + fGeom->GetModuleBoxThickness() / 2.0 ;
-  dptcb[2] = fGeom->GetNZ() * ( xtlZ + 2 * fGeom->GetGapBetweenCrystals() ) / 2.0 +  fGeom->GetModuleBoxThickness() ;
+  // ------- define the air gap between thermoinsulation and cooler
+  for (ipar=0; ipar<3; ipar++) par[ipar] = *(emcg->GetAirGapHalfSize() + ipar);
+  TVirtualMC::GetMC()->Gsvolu("PAGA", "BOX ", idtmed[798], par, 3) ;   
+  const Float_t * agap = emcg->GetAirGapHalfSize() ;
+  y = agap[1] - inthermo[1]  ;
   
-  gMC->Gsvolu("PTCB", "BOX ", idtmed[706], dptcb, 3) ;
+  TVirtualMC::GetMC()->Gspos("PTII", 1, "PAGA", 0.0, y, 0.0, 0, "ONLY") ;
 
-  yO =  fGeom->GetAirFilledBoxSize(1) / 2.0 - dptcb[1] 
-       - ( fGeom->GetIPtoCrystalSurface() - fGeom->GetIPtoOuterCoverDistance() - fGeom->GetModuleBoxThickness() 
-       -  fGeom->GetUpperPlateThickness() -  fGeom->GetSecondUpperPlateThickness() ) ;
-  
-  gMC->Gspos("PTCB", 1, "PAIR", 0.0, yO, 0.0, 0, "ONLY") ;
 
-  // ---
-  // --- Define Crystal BLock filled with air, position it inside PTCB ---
-  Float_t dpcbl[3] ; 
+  // ------- define the Al passive cooler 
+  for (ipar=0; ipar<3; ipar++) par[ipar] = *(emcg->GetCoolerHalfSize() + ipar);
+  TVirtualMC::GetMC()->Gsvolu("PCOR", "BOX ", idtmed[701], par, 3) ;   
+  const Float_t * cooler = emcg->GetCoolerHalfSize() ;
+  y = cooler[1] - agap[1]  ;
   
-  dpcbl[0] = fGeom->GetNPhi() * ( xtlX + 2 * fGeom->GetGapBetweenCrystals() ) / 2.0 ;
-  dpcbl[1] = ( xtlY + fGeom->GetCrystalSupportHeight() + fGeom->GetCrystalWrapThickness() + fGeom->GetCrystalHolderThickness() ) / 2.0 ;
-  dpcbl[2] = fGeom->GetNZ() * ( xtlZ + 2 * fGeom->GetGapBetweenCrystals() ) / 2.0 ;
+  TVirtualMC::GetMC()->Gspos("PAGA", 1, "PCOR", 0.0, y, 0.0, 0, "ONLY") ;
   
-  gMC->Gsvolu("PCBL", "BOX ", idtmed[798], dpcbl, 3) ;
+  // ------- define the outer thermoinsulating cover
+  for (ipar=0; ipar<4; ipar++) par[ipar] = *(emcg->GetOuterThermoParams() + ipar);
+  TVirtualMC::GetMC()->Gsvolu("PTIO", "TRD1", idtmed[706], par, 4) ;        
+  const Float_t * outparams = emcg->GetOuterThermoParams() ; 
   
-  // --- Divide PCBL in X (phi) and Z directions --
-  gMC->Gsdvn("PROW", "PCBL", Int_t (fGeom->GetNPhi()), 1) ;
-  gMC->Gsdvn("PCEL", "PROW", Int_t (fGeom->GetNZ()), 3) ;
-
-  yO = -fGeom->GetModuleBoxThickness() / 2.0 ;
+  Int_t idrotm[99] ;
+  AliMatrix(idrotm[1], 90.0, 0.0, 0.0, 0.0, 90.0, 270.0) ;
+  // Frame in outer thermoinsulation and so on: z out of beam, y along beam, x across beam
+  
+  z = outparams[3] - cooler[1] ;
+  TVirtualMC::GetMC()->Gspos("PCOR", 1, "PTIO", 0., 0.0, z, idrotm[1], "ONLY") ;
+  
+  // -------- Define the outer Aluminium cover -----
+  for (ipar=0; ipar<4; ipar++) par[ipar] = *(emcg->GetAlCoverParams() + ipar);
+  TVirtualMC::GetMC()->Gsvolu("PCOL", "TRD1", idtmed[701], par, 4) ;        
+  const Float_t * covparams = emcg->GetAlCoverParams() ; 
+  z = covparams[3] - outparams[3] ;
+  TVirtualMC::GetMC()->Gspos("PTIO", 1, "PCOL", 0., 0.0, z, 0, "ONLY") ;
+
+  // --------- Define front fiberglass cover -----------
+  for (ipar=0; ipar<3; ipar++) par[ipar] = *(emcg->GetFiberGlassHalfSize() + ipar);
+  TVirtualMC::GetMC()->Gsvolu("PFGC", "BOX ", idtmed[717], par, 3) ;  
+  z = - outparams[3] ;
+  TVirtualMC::GetMC()->Gspos("PFGC", 1, "PCOL", 0., 0.0, z, 0, "ONLY") ;
+
+  //=============This is all with cold section==============
+  
+
+  //------ Warm Section --------------
+  for (ipar=0; ipar<3; ipar++) par[ipar] = *(emcg->GetWarmAlCoverHalfSize() + ipar);
+  TVirtualMC::GetMC()->Gsvolu("PWAR", "BOX ", idtmed[701], par, 3) ; 
+  const Float_t * warmcov = emcg->GetWarmAlCoverHalfSize() ;
+  
+  // --- Define the outer thermoinsulation ---
+  for (ipar=0; ipar<3; ipar++) par[ipar] = *(emcg->GetWarmThermoHalfSize() + ipar);
+  TVirtualMC::GetMC()->Gsvolu("PWTI", "BOX ", idtmed[706], par, 3) ; 
+  const Float_t * warmthermo = emcg->GetWarmThermoHalfSize() ;
+  z = -warmcov[2] + warmthermo[2] ;
+  
+  TVirtualMC::GetMC()->Gspos("PWTI", 1, "PWAR", 0., 0.0, z, 0, "ONLY") ;     
+  
+  // --- Define cables area and put in it T-supports ---- 
+  for (ipar=0; ipar<3; ipar++) par[ipar] = *(emcg->GetTCables1HalfSize() + ipar);
+  TVirtualMC::GetMC()->Gsvolu("PCA1", "BOX ", idtmed[718], par, 3) ; 
+  const Float_t * cbox = emcg->GetTCables1HalfSize() ;
+  
+  for (ipar=0; ipar<3; ipar++) par[ipar] = *(emcg->GetTSupport1HalfSize() + ipar);
+  TVirtualMC::GetMC()->Gsvolu("PBE1", "BOX ", idtmed[701], par, 3) ;
+  const Float_t * beams = emcg->GetTSupport1HalfSize() ;
+  Int_t isup ;
+  for(isup = 0; isup < emcg->GetNTSuppots(); isup++){
+    Float_t x = -cbox[0] + beams[0] + (2*beams[0]+emcg->GetTSupportDist())*isup ;
+    TVirtualMC::GetMC()->Gspos("PBE1", isup, "PCA1", x, 0.0, 0.0, 0, "ONLY") ;
+  }
   
-  gMC->Gspos("PCBL", 1, "PTCB", 0.0, yO, 0.0, 0, "ONLY") ;
-
-  // ---
-  // --- Define STeel (actually, it's titanium) Cover volume, place inside PCEL
-  Float_t  dpstc[3] ; 
+  z = -warmthermo[2] + cbox[2];
+  TVirtualMC::GetMC()->Gspos("PCA1", 1, "PWTI", 0.0, 0.0, z, 0, "ONLY") ;     
   
-  dpstc[0] = ( xtlX + 2 * fGeom->GetCrystalWrapThickness() ) / 2.0 ;
-  dpstc[1] = ( xtlY + fGeom->GetCrystalSupportHeight() + fGeom->GetCrystalWrapThickness() + fGeom->GetCrystalHolderThickness() ) / 2.0 ;
-  dpstc[2] = ( xtlZ + 2 * fGeom->GetCrystalWrapThickness()  + 2 *  fGeom->GetCrystalHolderThickness() ) / 2.0 ;
+  for (ipar=0; ipar<3; ipar++) par[ipar] = *(emcg->GetTCables2HalfSize() + ipar);
+  TVirtualMC::GetMC()->Gsvolu("PCA2", "BOX ", idtmed[718], par, 3) ; 
+  const Float_t * cbox2 = emcg->GetTCables2HalfSize() ;
   
-  gMC->Gsvolu("PSTC", "BOX ", idtmed[704], dpstc, 3) ;
-
-  gMC->Gspos("PSTC", 1, "PCEL", 0.0, 0.0, 0.0, 0, "ONLY") ;
-
-  // ---
-  // --- Define Tyvek volume, place inside PSTC ---
-  Float_t  dppap[3] ;
-
-  dppap[0] = xtlX / 2.0 + fGeom->GetCrystalWrapThickness() ;
-  dppap[1] = ( xtlY + fGeom->GetCrystalSupportHeight() + fGeom->GetCrystalWrapThickness() ) / 2.0 ;
-  dppap[2] = xtlZ / 2.0 + fGeom->GetCrystalWrapThickness() ;
+  for (ipar=0; ipar<3; ipar++) par[ipar] = *(emcg->GetTSupport2HalfSize() + ipar);
+  TVirtualMC::GetMC()->Gsvolu("PBE2", "BOX ", idtmed[701], par, 3) ;
+  for(isup = 0; isup < emcg->GetNTSuppots(); isup++){
+    Float_t x = -cbox[0] + beams[0] + (2*beams[0]+emcg->GetTSupportDist())*isup ;
+    TVirtualMC::GetMC()->Gspos("PBE2", isup, "PCA2", x, 0.0, 0.0, 0, "ONLY") ;
+  }
   
-  gMC->Gsvolu("PPAP", "BOX ", idtmed[702], dppap, 3) ;
+  z = -warmthermo[2] + 2*cbox[2] + cbox2[2];
+  TVirtualMC::GetMC()->Gspos("PCA2", 1, "PWTI", 0.0, 0.0, z, 0, "ONLY") ;     
   
-  yO = ( xtlY + fGeom->GetCrystalSupportHeight() + fGeom->GetCrystalWrapThickness() ) / 2.0 
-              - ( xtlY +  fGeom->GetCrystalSupportHeight() +  fGeom->GetCrystalWrapThickness() + fGeom->GetCrystalHolderThickness() ) / 2.0 ;
-   
-  gMC->Gspos("PPAP", 1, "PSTC", 0.0, yO, 0.0, 0, "ONLY") ;
-
-  // ---
-  // --- Define PbWO4 crystal volume, place inside PPAP ---
-  Float_t  dpxtl[3] ; 
-
-  dpxtl[0] = xtlX / 2.0 ;
-  dpxtl[1] = xtlY / 2.0 ;
-  dpxtl[2] = xtlZ / 2.0 ;
   
-  gMC->Gsvolu("PXTL", "BOX ", idtmed[699], dpxtl, 3) ;
-
-  yO = ( xtlY + fGeom->GetCrystalSupportHeight() + fGeom->GetCrystalWrapThickness() ) / 2.0 - xtlY / 2.0 - fGeom->GetCrystalWrapThickness() ;
+  // --- Define frame ---
+  for (ipar=0; ipar<3; ipar++) par[ipar] = *(emcg->GetFrameXHalfSize() + ipar);
+  TVirtualMC::GetMC()->Gsvolu("PFRX", "BOX ", idtmed[716], par, 3) ; 
+  const Float_t * posit1 = emcg->GetFrameXPosition() ;
+  TVirtualMC::GetMC()->Gspos("PFRX", 1, "PWTI", posit1[0],  posit1[1], posit1[2], 0, "ONLY") ;
+  TVirtualMC::GetMC()->Gspos("PFRX", 2, "PWTI", posit1[0], -posit1[1], posit1[2], 0, "ONLY") ;
   
-  gMC->Gspos("PXTL", 1, "PPAP", 0.0, yO, 0.0, 0, "ONLY") ;
-
-  // ---
-  // --- Define crystal support volume, place inside PPAP ---
-  Float_t dpsup[3] ; 
-
-  dpsup[0] = xtlX / 2.0 + fGeom->GetCrystalWrapThickness()  ;
-  dpsup[1] = fGeom->GetCrystalSupportHeight() / 2.0 ;
-  dpsup[2] = xtlZ / 2.0 +  fGeom->GetCrystalWrapThickness() ;
+  for (ipar=0; ipar<3; ipar++) par[ipar] = *(emcg->GetFrameZHalfSize() + ipar);
+  TVirtualMC::GetMC()->Gsvolu("PFRZ", "BOX ", idtmed[716], par, 3) ; 
+  const Float_t * posit2 = emcg->GetFrameZPosition() ;
+  TVirtualMC::GetMC()->Gspos("PFRZ", 1, "PWTI",  posit2[0], posit2[1], posit2[2], 0, "ONLY") ;
+  TVirtualMC::GetMC()->Gspos("PFRZ", 2, "PWTI", -posit2[0], posit2[1], posit2[2], 0, "ONLY") ;
 
-  gMC->Gsvolu("PSUP", "BOX ", idtmed[798], dpsup, 3) ;
+ // --- Define Fiber Glass support ---
+  for (ipar=0; ipar<3; ipar++) par[ipar] = *(emcg->GetFGupXHalfSize() + ipar);
+  TVirtualMC::GetMC()->Gsvolu("PFG1", "BOX ", idtmed[717], par, 3) ; 
+  const Float_t * posit3 = emcg->GetFGupXPosition() ;
+  TVirtualMC::GetMC()->Gspos("PFG1", 1, "PWTI", posit3[0],  posit3[1], posit3[2], 0, "ONLY") ;
+  TVirtualMC::GetMC()->Gspos("PFG1", 2, "PWTI", posit3[0], -posit3[1], posit3[2], 0, "ONLY") ;
 
-  yO =  fGeom->GetCrystalSupportHeight() / 2.0 - ( xtlY +  fGeom->GetCrystalSupportHeight() + fGeom->GetCrystalWrapThickness() ) / 2.0 ;
+  for (ipar=0; ipar<3; ipar++) par[ipar] = *(emcg->GetFGupZHalfSize() + ipar);
+  TVirtualMC::GetMC()->Gsvolu("PFG2", "BOX ", idtmed[717], par, 3) ; 
+  const Float_t * posit4 = emcg->GetFGupZPosition();
+  TVirtualMC::GetMC()->Gspos("PFG2", 1, "PWTI",  posit4[0], posit4[1], posit4[2], 0, "ONLY") ;
+  TVirtualMC::GetMC()->Gspos("PFG2", 2, "PWTI", -posit4[0], posit4[1], posit4[2], 0, "ONLY") ;
 
-  gMC->Gspos("PSUP", 1, "PPAP", 0.0, yO, 0.0, 0, "ONLY") ;
+  for (ipar=0; ipar<3; ipar++) par[ipar] = *(emcg->GetFGlowXHalfSize() + ipar);
+  TVirtualMC::GetMC()->Gsvolu("PFG3", "BOX ", idtmed[717], par, 3) ; 
+  const Float_t * posit5 = emcg->GetFGlowXPosition() ;
+  TVirtualMC::GetMC()->Gspos("PFG3", 1, "PWTI", posit5[0],  posit5[1], posit5[2], 0, "ONLY") ;
+  TVirtualMC::GetMC()->Gspos("PFG3", 2, "PWTI", posit5[0], -posit5[1], posit5[2], 0, "ONLY") ;
 
-  // ---
-  // --- Define PIN-diode volume and position it inside crystal support ---
-  // --- right behind PbWO4 crystal
+  for (ipar=0; ipar<3; ipar++) par[ipar] = *(emcg->GetFGlowZHalfSize() + ipar);
+  TVirtualMC::GetMC()->Gsvolu("PFG4", "BOX ", idtmed[717], par, 3) ; 
+  const Float_t * posit6 = emcg->GetFGlowZPosition() ;
+  TVirtualMC::GetMC()->Gspos("PFG4", 1, "PWTI",  posit6[0], posit6[1], posit6[2], 0, "ONLY") ;
+  TVirtualMC::GetMC()->Gspos("PFG4", 2, "PWTI", -posit6[0], posit6[1], posit6[2], 0, "ONLY") ;
 
-  // --- PIN-diode dimensions ---
-
-  Float_t dppin[3] ;
-  dppin[0] = fGeom->GetPinDiodeSize(0) / 2.0 ;
-  dppin[1] = fGeom->GetPinDiodeSize(1) / 2.0 ;
-  dppin[2] = fGeom->GetPinDiodeSize(2) / 2.0 ;
-  gMC->Gsvolu("PPIN", "BOX ", idtmed[705], dppin, 3) ;
-  yO = fGeom->GetCrystalSupportHeight() / 2.0 - fGeom->GetPinDiodeSize(1) / 2.0 ;
-  gMC->Gspos("PPIN", 1, "PSUP", 0.0, yO, 0.0, 0, "ONLY") ;
-
-  // ---
-  // --- Define Upper Cooling Panel, place it on top of PTCB ---
-  Float_t dpucp[3] ;
- // --- Upper Cooling Plate thickness ---
-  dpucp[0] = dptcb[0] ;
-  dpucp[1] = fGeom->GetUpperCoolingPlateThickness() ;
-  dpucp[2] = dptcb[2] ;
+  // --- Define Air Gap for FEE electronics ----- 
   
-  gMC->Gsvolu("PUCP", "BOX ", idtmed[701], dpucp,3) ;
+  for (ipar=0; ipar<3; ipar++) par[ipar] = *(emcg->GetFEEAirHalfSize() + ipar);
+  TVirtualMC::GetMC()->Gsvolu("PAFE", "BOX ", idtmed[798], par, 3) ; 
+  const Float_t * posit7 = emcg->GetFEEAirPosition() ;
+  TVirtualMC::GetMC()->Gspos("PAFE", 1, "PWTI",  posit7[0], posit7[1], posit7[2], 0, "ONLY") ;
   
-  yO = (  fGeom->GetAirFilledBoxSize(1) -  fGeom->GetUpperCoolingPlateThickness() ) / 2. 
-       - ( fGeom->GetIPtoCrystalSurface() - fGeom->GetIPtoOuterCoverDistance() - fGeom->GetModuleBoxThickness()
-           - fGeom->GetUpperPlateThickness() - fGeom->GetSecondUpperPlateThickness() - fGeom->GetUpperCoolingPlateThickness() ) ; 
+  // Define the EMC module volume and combine Cool and Warm sections
   
-  gMC->Gspos("PUCP", 1, "PAIR", 0.0, yO, 0.0, 0, "ONLY") ;
-
-  // ---
-  // --- Define Al Support Plate, position it inside PAIR ---
-  // --- right beneath PTCB ---
- // --- Al Support Plate thickness ---
-  Float_t dpasp[3] ;
-  dpasp[0] =  fGeom->GetAirFilledBoxSize(0) / 2.0 ;
-  dpasp[1] = fGeom->GetSupportPlateThickness() / 2.0 ;
-  dpasp[2] =  fGeom->GetAirFilledBoxSize(2) / 2.0 ;
+  for (ipar=0; ipar<4; ipar++) par[ipar] = *(emcg->GetEMCParams() + ipar);
+  TVirtualMC::GetMC()->Gsvolu("PEMC", "TRD1", idtmed[798], par, 4) ;        
+  z =  - warmcov[2] ;
+  TVirtualMC::GetMC()->Gspos("PCOL", 1, "PEMC",  0., 0., z, 0, "ONLY") ;
+  z = covparams[3] ;
+  TVirtualMC::GetMC()->Gspos("PWAR", 1, "PEMC",  0., 0., z, 0, "ONLY") ;
   
-  gMC->Gsvolu("PASP", "BOX ", idtmed[701], dpasp, 3) ;
   
-  yO = (  fGeom->GetAirFilledBoxSize(1) - fGeom->GetSupportPlateThickness() ) / 2. 
-       -  ( fGeom->GetIPtoCrystalSurface() - fGeom->GetIPtoOuterCoverDistance()
-           - fGeom->GetUpperPlateThickness() - fGeom->GetSecondUpperPlateThickness() + dpcbl[1] * 2 ) ;
+  // Put created EMC geometry into PHOS volume
   
-  gMC->Gspos("PASP", 1, "PAIR", 0.0, yO, 0.0, 0, "ONLY") ;
-
-  // ---
-  // --- Define Thermo Insulating Plate, position it inside PAIR ---
-  // --- right beneath PASP ---
-  // --- Lower Thermo Insulating Plate thickness ---
+  z = geom->GetCPVBoxSize(1) / 2. ;
+  TVirtualMC::GetMC()->Gspos("PEMC", 1, "PHOS", 0., 0., z, 0, "ONLY") ; 
   
-  Float_t dptip[3] ;
-  dptip[0] = fGeom->GetAirFilledBoxSize(0) / 2.0 ;
-  dptip[1] = fGeom->GetLowerThermoPlateThickness() / 2.0 ;
-  dptip[2] = fGeom->GetAirFilledBoxSize(2) / 2.0 ;
-
-  gMC->Gsvolu("PTIP", "BOX ", idtmed[706], dptip, 3) ;
-
-  yO =  ( fGeom->GetAirFilledBoxSize(1) - fGeom->GetLowerThermoPlateThickness() ) / 2. 
-       -  ( fGeom->GetIPtoCrystalSurface() - fGeom->GetIPtoOuterCoverDistance() - fGeom->GetUpperPlateThickness() 
-            - fGeom->GetSecondUpperPlateThickness() + dpcbl[1] * 2 + fGeom->GetSupportPlateThickness() ) ;
-
-  gMC->Gspos("PTIP", 1, "PAIR", 0.0, yO, 0.0, 0, "ONLY") ;
-
-  // ---
-  // --- Define Textolit Plate, position it inside PAIR ---
-  // --- right beneath PTIP ---
-  // --- Lower Textolit Plate thickness ---
-  Float_t dptxp[3] ;
-  dptxp[0] = fGeom->GetAirFilledBoxSize(0) / 2.0 ;
-  dptxp[1] = fGeom->GetLowerTextolitPlateThickness() / 2.0 ;
-  dptxp[2] = fGeom->GetAirFilledBoxSize(2) / 2.0 ;
-
-  gMC->Gsvolu("PTXP", "BOX ", idtmed[707], dptxp, 3) ;
-
-  yO =  ( fGeom->GetAirFilledBoxSize(1) - fGeom->GetLowerTextolitPlateThickness() ) / 2. 
-       -  ( fGeom->GetIPtoCrystalSurface() - fGeom->GetIPtoOuterCoverDistance() - fGeom->GetUpperPlateThickness() 
-            - fGeom->GetSecondUpperPlateThickness() + dpcbl[1] * 2 + fGeom->GetSupportPlateThickness() 
-            +  fGeom->GetLowerThermoPlateThickness() ) ;
-
-  gMC->Gspos("PTXP", 1, "PAIR", 0.0, yO, 0.0, 0, "ONLY") ;
-
 }
 
 //____________________________________________________________________________
-void AliPHOSv0::CreateGeometryforPPSD()
+void AliPHOSv0::CreateGeometryforCPV()
 {
-  // Get pointer to the array containing media indeces
+  // Create the PHOS-CPV geometry for GEANT
+  // Author: Yuri Kharlov 11 September 2000
+  //BEGIN_HTML
+  /*
+    <H2>
+    Geant3 geometry of PHOS-CPV in ALICE
+    </H2>
+    <table width=700>
+
+    <tr>
+         <td>CPV perspective view</td>
+         <td>CPV front view      </td>
+    </tr>
+
+    <tr>
+         <td> <img height=300 width=290 src="../images/CPVallPersp.gif"> </td>
+         <td> <img height=300 width=290 src="../images/CPVallFront.gif"> </td>
+    </tr>
+
+    <tr>
+         <td>One CPV module, perspective view                            </td>
+         <td>One CPV module, front view (extended in vertical direction) </td>
+    </tr>
+
+    <tr>
+         <td><img height=300 width=290 src="../images/CPVmodulePers.gif"></td>
+         <td><img height=300 width=290 src="../images/CPVmoduleSide.gif"></td>
+    </tr>
+
+    </table>
+
+    <H2>
+    Geant3 geometry tree of PHOS-CPV in ALICE
+    </H2>
+    <center>
+    <img height=300 width=290 src="../images/CPVtree.gif">
+    </center>
+  */
+  //END_HTML  
+
+  Float_t par[3], x,y,z;
+
+  // Get pointer to the array containing media indexes
   Int_t *idtmed = fIdtmed->GetArray() - 699 ;
-  
-  // The box containing all ppsd's for one PHOS module filled with air 
-  Float_t ppsd[3] ; 
-  ppsd[0] = fGeom->GetPPSDBoxSize(0) / 2.0 ;  
-  ppsd[1] = fGeom->GetPPSDBoxSize(1) / 2.0 ; 
-  ppsd[2] = fGeom->GetPPSDBoxSize(2) / 2.0 ;
 
-  gMC->Gsvolu("PPSD", "BOX ", idtmed[798], ppsd, 3) ;
+  AliPHOSGeometry * geom = GetGeometry() ; 
 
-  Float_t yO =  fGeom->GetOuterBoxSize(1) / 2.0 ;
+  // The box containing all CPV for one PHOS module filled with air 
+  par[0] = geom->GetCPVBoxSize(0) / 2.0 ;  
+  par[1] = geom->GetCPVBoxSize(1) / 2.0 ; 
+  par[2] = geom->GetCPVBoxSize(2) / 2.0 ;
+  TVirtualMC::GetMC()->Gsvolu("PCPV", "BOX ", idtmed[798], par, 3) ;
 
-  gMC->Gspos("PPSD", 1, "PHOS", 0.0, yO, 0.0, 0, "ONLY") ; 
+  const Float_t * emcParams = geom->GetEMCAGeometry()->GetEMCParams() ;
+  z = - emcParams[3] ;
+  Int_t rotm ;
+  AliMatrix(rotm, 90.,0., 0., 0., 90., 90.) ;
 
-  // Now we build a micromegas module
-  // The box containing the whole module filled with epoxy (FR4)
+  TVirtualMC::GetMC()->Gspos("PCPV", 1, "PHOS", 0.0, 0.0, z, rotm, "ONLY") ; 
+  
+  // Gassiplex board
+  
+  par[0] = geom->GetGassiplexChipSize(0)/2.;
+  par[1] = geom->GetGassiplexChipSize(1)/2.;
+  par[2] = geom->GetGassiplexChipSize(2)/2.;
+  TVirtualMC::GetMC()->Gsvolu("PCPC","BOX ",idtmed[707],par,3);
+  
+  // Cu+Ni foil covers Gassiplex board
 
-  Float_t mppsd[3] ;  
-  mppsd[0] = fGeom->GetPPSDModuleSize(0) / 2.0 ;  
-  mppsd[1] = fGeom->GetPPSDModuleSize(1) / 2.0 ;  
-  mppsd[2] = fGeom->GetPPSDModuleSize(2) / 2.0 ;
+  par[1] = geom->GetCPVCuNiFoilThickness()/2;
+  TVirtualMC::GetMC()->Gsvolu("PCPD","BOX ",idtmed[710],par,3);
+  y      = -(geom->GetGassiplexChipSize(1)/2 - par[1]);
+  TVirtualMC::GetMC()->Gspos("PCPD",1,"PCPC",0,y,0,0,"ONLY");
 
-  gMC->Gsvolu("MPPS", "BOX ", idtmed[708], mppsd, 3) ;  
-  // Inside mppsd :
-  // 1. The Top Lid made of epoxy (FR4) 
+  // Position of the chip inside CPV
 
-  Float_t tlppsd[3] ; 
-  tlppsd[0] = fGeom->GetPPSDModuleSize(0) / 2.0 ; 
-  tlppsd[1] = fGeom->GetLidThickness() / 2.0 ;
-  tlppsd[2] = fGeom->GetPPSDModuleSize(2) / 2.0 ;
+  Float_t xStep = geom->GetCPVActiveSize(0) / (geom->GetNumberOfCPVChipsPhi() + 1);
+  Float_t zStep = geom->GetCPVActiveSize(1) / (geom->GetNumberOfCPVChipsZ()   + 1);
+  Int_t   copy  = 0;
+  y = geom->GetCPVFrameSize(1)/2           - geom->GetFTPosition(0) +
+    geom->GetCPVTextoliteThickness() / 2 + geom->GetGassiplexChipSize(1) / 2 + 0.1;
+  for (Int_t ix=0; ix<geom->GetNumberOfCPVChipsPhi(); ix++) {
+    x = xStep * (ix+1) - geom->GetCPVActiveSize(0)/2;
+    for (Int_t iz=0; iz<geom->GetNumberOfCPVChipsZ(); iz++) {
+      copy++;
+      z = zStep * (iz+1) - geom->GetCPVActiveSize(1)/2;
+      TVirtualMC::GetMC()->Gspos("PCPC",copy,"PCPV",x,y,z,0,"ONLY");
+    }
+  }
 
-  gMC->Gsvolu("TLPS", "BOX ", idtmed[708], tlppsd, 3) ; 
+  // Foiled textolite (1 mm of textolite + 50 mkm of Cu + 6 mkm of Ni)
+  
+  par[0] = geom->GetCPVActiveSize(0)        / 2;
+  par[1] = geom->GetCPVTextoliteThickness() / 2;
+  par[2] = geom->GetCPVActiveSize(1)        / 2;
+  TVirtualMC::GetMC()->Gsvolu("PCPF","BOX ",idtmed[707],par,3);
 
-  Float_t  y0 = ( fGeom->GetMicromegas1Thickness() - fGeom->GetLidThickness() ) / 2. ; 
+  // Argon gas volume
 
-  gMC->Gspos("TLPS", 1, "MPPS", 0.0, y0, 0.0, 0, "ONLY") ; 
-  // 2. the upper panel made of composite material
+  par[1] = (geom->GetFTPosition(2) - geom->GetFTPosition(1) - geom->GetCPVTextoliteThickness()) / 2;
+  TVirtualMC::GetMC()->Gsvolu("PCPG","BOX ",idtmed[715],par,3);
 
-  Float_t upppsd[3] ; 
-  upppsd[0] = ( fGeom->GetPPSDModuleSize(0) - fGeom->GetMicromegasWallThickness() ) / 2.0 ;
-  upppsd[1] = fGeom->GetCompositeThickness() / 2.0 ;
-  upppsd[2] = ( fGeom->GetPPSDModuleSize(2) - fGeom->GetMicromegasWallThickness() ) / 2.0 ;
-  gMC->Gsvolu("UPPS", "BOX ", idtmed[709], upppsd, 3) ; 
-  
-  y0 = y0 - fGeom->GetLidThickness() / 2. - fGeom->GetCompositeThickness() / 2. ; 
+  for (Int_t i=0; i<4; i++) {
+    y = geom->GetCPVFrameSize(1) / 2 - geom->GetFTPosition(i) + geom->GetCPVTextoliteThickness()/2;
+    TVirtualMC::GetMC()->Gspos("PCPF",i+1,"PCPV",0,y,0,0,"ONLY");
+    if(i==1){
+      y-= (geom->GetFTPosition(2) - geom->GetFTPosition(1)) / 2;
+      TVirtualMC::GetMC()->Gspos("PCPG",1,"PCPV ",0,y,0,0,"ONLY");
+    }
+  }
 
-  gMC->Gspos("UPPS", 1, "MPPS", 0.0, y0, 0.0, 0, "ONLY") ; 
+  // Dummy sensitive plane in the middle of argone gas volume
 
-  // 3. the anode made of Copper
-  
-  Float_t anppsd[3] ; 
-  anppsd[0] = ( fGeom->GetPPSDModuleSize(0) - fGeom->GetMicromegasWallThickness() ) / 2.0 ; 
-  anppsd[1] = fGeom->GetAnodeThickness() / 2.0 ; 
-  anppsd[2] = ( fGeom->GetPPSDModuleSize(2) - fGeom->GetMicromegasWallThickness() ) / 2.0  ; 
+  par[1]=0.001;
+  TVirtualMC::GetMC()->Gsvolu("PCPQ","BOX ",idtmed[715],par,3);
+  TVirtualMC::GetMC()->Gspos ("PCPQ",1,"PCPG",0,0,0,0,"ONLY");
 
-  gMC->Gsvolu("ANPS", "BOX ", idtmed[710], anppsd, 3) ; 
-  
-  y0 = y0 - fGeom->GetCompositeThickness() / 2. - fGeom->GetAnodeThickness()  / 2. ; 
-  
-  gMC->Gspos("ANPS", 1, "MPPS", 0.0, y0, 0.0, 0, "ONLY") ; 
+  // Cu+Ni foil covers textolite
 
-  // 4. the conversion gap + avalanche gap filled with gas
+  par[1] = geom->GetCPVCuNiFoilThickness() / 2;
+  TVirtualMC::GetMC()->Gsvolu("PCP1","BOX ",idtmed[710],par,3);
+  y = geom->GetCPVTextoliteThickness()/2 - par[1];
+  TVirtualMC::GetMC()->Gspos ("PCP1",1,"PCPF",0,y,0,0,"ONLY");
 
-  Float_t ggppsd[3] ; 
-  ggppsd[0] = ( fGeom->GetPPSDModuleSize(0) - fGeom->GetMicromegasWallThickness() ) / 2.0 ;
-  ggppsd[1] = ( fGeom->GetConversionGap() +  fGeom->GetAvalancheGap() ) / 2.0 ; 
-  ggppsd[2] = ( fGeom->GetPPSDModuleSize(2) - fGeom->GetMicromegasWallThickness() ) / 2.0 ;
+  // Aluminum frame around CPV
 
-  gMC->Gsvolu("GGPS", "BOX ", idtmed[715], ggppsd, 3) ; 
-  
-  // --- Divide GGPP in X (phi) and Z directions --
-  gMC->Gsdvn("GROW", "GGPS", fGeom->GetNumberOfPadsPhi(), 1) ;
-  gMC->Gsdvn("GCEL", "GROW", fGeom->GetNumberOfPadsZ() , 3) ;
+  par[0] = geom->GetCPVFrameSize(0)/2;
+  par[1] = geom->GetCPVFrameSize(1)/2;
+  par[2] = geom->GetCPVBoxSize(2)  /2;
+  TVirtualMC::GetMC()->Gsvolu("PCF1","BOX ",idtmed[701],par,3);
 
-  y0 = y0 - fGeom->GetAnodeThickness() / 2.  - ( fGeom->GetConversionGap() +  fGeom->GetAvalancheGap() ) / 2. ; 
+  par[0] = geom->GetCPVBoxSize(0)/2 - geom->GetCPVFrameSize(0);
+  par[1] = geom->GetCPVFrameSize(1)/2;
+  par[2] = geom->GetCPVFrameSize(2)/2;
+  TVirtualMC::GetMC()->Gsvolu("PCF2","BOX ",idtmed[701],par,3);
 
-  gMC->Gspos("GGPS", 1, "MPPS", 0.0, y0, 0.0, 0, "ONLY") ; 
+  for (Int_t j=0; j<=1; j++) {
+    x = TMath::Sign(1,2*j-1) * (geom->GetCPVBoxSize(0) - geom->GetCPVFrameSize(0)) / 2;
+    TVirtualMC::GetMC()->Gspos("PCF1",j+1,"PCPV", x,0,0,0,"ONLY");
+    z = TMath::Sign(1,2*j-1) * (geom->GetCPVBoxSize(2) - geom->GetCPVFrameSize(2)) / 2;
+    TVirtualMC::GetMC()->Gspos("PCF2",j+1,"PCPV",0, 0,z,0,"ONLY");
+  }
 
+}
 
-  // 6. the cathode made of Copper
 
-  Float_t cappsd[3] ;
-  cappsd[0] = ( fGeom->GetPPSDModuleSize(0) - fGeom->GetMicromegasWallThickness() ) / 2.0 ;
-  cappsd[1] = fGeom->GetCathodeThickness() / 2.0 ; 
-  cappsd[2] = ( fGeom->GetPPSDModuleSize(2) - fGeom->GetMicromegasWallThickness() ) / 2.0  ;
+//____________________________________________________________________________
+void AliPHOSv0::CreateGeometryforSupport()
+{
+  // Create the PHOS' support geometry for GEANT
+    //BEGIN_HTML
+  /*
+    <H2>
+    Geant3 geometry of the PHOS's support
+    </H2>
+    <P><CENTER>
+    <IMG Align=BOTTOM ALT="EMC geant tree" SRC="../images/PHOS_support.gif"> 
+    </CENTER><P>
+  */
+  //END_HTML  
+  
+  Float_t par[5], x0,y0,z0 ; 
+  Int_t   i,j,copy;
+
+  // Get pointer to the array containing media indexes
+  Int_t *idtmed = fIdtmed->GetArray() - 699 ;
 
-  gMC->Gsvolu("CAPS", "BOX ", idtmed[710], cappsd, 3) ; 
+  AliPHOSGeometry * geom = GetGeometry() ; 
 
-  y0 = y0 - ( fGeom->GetAvalancheGap() +  fGeom->GetAvalancheGap() ) / 2. - fGeom->GetCathodeThickness()  / 2. ; 
+  // --- Dummy box containing two rails on which PHOS support moves
+  // --- Put these rails to the bottom of the L3 magnet
 
-  gMC->Gspos("CAPS", 1, "MPPS", 0.0, y0, 0.0, 0, "ONLY") ; 
+  par[0] =  geom->GetRailRoadSize(0) / 2.0 ;
+  par[1] =  geom->GetRailRoadSize(1) / 2.0 ;
+  par[2] =  geom->GetRailRoadSize(2) / 2.0 ;
+  TVirtualMC::GetMC()->Gsvolu("PRRD", "BOX ", idtmed[798], par, 3) ;
 
-  // 7. the printed circuit made of G10       
+  y0     = -(geom->GetRailsDistanceFromIP() - geom->GetRailRoadSize(1) / 2.0) ;
+  TVirtualMC::GetMC()->Gspos("PRRD", 1, "ALIC", 0.0, y0, 0.0, 0, "ONLY") ; 
 
-  Float_t pcppsd[3] ; 
-  pcppsd[0] = ( fGeom->GetPPSDModuleSize(0) - fGeom->GetMicromegasWallThickness() ) / 2,.0 ; 
-  pcppsd[1] = fGeom->GetPCThickness() / 2.0 ; 
-  pcppsd[2] = ( fGeom->GetPPSDModuleSize(2) - fGeom->GetMicromegasWallThickness() ) / 2.0 ;
+  // --- Dummy box containing one rail
 
-  gMC->Gsvolu("PCPS", "BOX ", idtmed[711], cappsd, 3) ; 
+  par[0] =  geom->GetRailOuterSize(0) / 2.0 ;
+  par[1] =  geom->GetRailOuterSize(1) / 2.0 ;
+  par[2] =  geom->GetRailOuterSize(2) / 2.0 ;
+  TVirtualMC::GetMC()->Gsvolu("PRAI", "BOX ", idtmed[798], par, 3) ;
 
-  y0 = y0 - fGeom->GetCathodeThickness() / 2. - fGeom->GetPCThickness()  / 2. ; 
+  for (i=0; i<2; i++) {
+    x0     = (2*i-1) * geom->GetDistanceBetwRails()  / 2.0 ;
+    TVirtualMC::GetMC()->Gspos("PRAI", i, "PRRD", x0, 0.0, 0.0, 0, "ONLY") ; 
+  }
 
-  gMC->Gspos("PCPS", 1, "MPPS", 0.0, y0, 0.0, 0, "ONLY") ; 
+  // --- Upper and bottom steel parts of the rail
 
-  // 8. the lower panel made of composite material
-                                                   
-  Float_t lpppsd[3] ; 
-  lpppsd[0] = ( fGeom->GetPPSDModuleSize(0) - fGeom->GetMicromegasWallThickness() ) / 2.0 ; 
-  lpppsd[1] = fGeom->GetCompositeThickness() / 2.0 ; 
-  lpppsd[2] = ( fGeom->GetPPSDModuleSize(2) - fGeom->GetMicromegasWallThickness() ) / 2.0 ;
+  par[0] =  geom->GetRailPart1(0) / 2.0 ;
+  par[1] =  geom->GetRailPart1(1) / 2.0 ;
+  par[2] =  geom->GetRailPart1(2) / 2.0 ;
+  TVirtualMC::GetMC()->Gsvolu("PRP1", "BOX ", idtmed[716], par, 3) ;
 
-  gMC->Gsvolu("LPPS", "BOX ", idtmed[709], lpppsd, 3) ; 
-  y0 = y0 - fGeom->GetPCThickness() / 2. - fGeom->GetCompositeThickness()  / 2. ; 
+  y0     = - (geom->GetRailOuterSize(1) - geom->GetRailPart1(1))  / 2.0 ;
+  TVirtualMC::GetMC()->Gspos("PRP1", 1, "PRAI", 0.0, y0, 0.0, 0, "ONLY") ;
+  y0     =   (geom->GetRailOuterSize(1) - geom->GetRailPart1(1))  / 2.0 - geom->GetRailPart3(1);
+  TVirtualMC::GetMC()->Gspos("PRP1", 2, "PRAI", 0.0, y0, 0.0, 0, "ONLY") ;
 
-  gMC->Gspos("LPPS", 1, "MPPS", 0.0, y0, 0.0, 0, "ONLY") ; 
+  // --- The middle vertical steel parts of the rail
 
-  // Position the  fNumberOfModulesPhi x fNumberOfModulesZ modules (mppsd) inside PPSD to cover a PHOS module
-  // the top and bottom one's (which are assumed identical) :
+  par[0] =  geom->GetRailPart2(0) / 2.0 ;
+  par[1] =  geom->GetRailPart2(1) / 2.0 ;
+  par[2] =  geom->GetRailPart2(2) / 2.0 ;
+  TVirtualMC::GetMC()->Gsvolu("PRP2", "BOX ", idtmed[716], par, 3) ;
 
-   Float_t yt = ( fGeom->GetPPSDBoxSize(1) - fGeom->GetMicromegas1Thickness() ) / 2. ; 
-   Float_t yb = - ( fGeom->GetPPSDBoxSize(1) - fGeom->GetMicromegas2Thickness() ) / 2. ; 
+  y0     =   - geom->GetRailPart3(1) / 2.0 ;
+  TVirtualMC::GetMC()->Gspos("PRP2", 1, "PRAI", 0.0, y0, 0.0, 0, "ONLY") ; 
 
-   Int_t copyNumbertop = 0 ; 
-   Int_t copyNumberbot = fGeom->GetNumberOfModulesPhi() *  fGeom->GetNumberOfModulesZ() ; 
+  // --- The most upper steel parts of the rail
 
-   Float_t x  = ( fGeom->GetPPSDBoxSize(0) - fGeom->GetPPSDModuleSize(0) ) / 2. ;  
+  par[0] =  geom->GetRailPart3(0) / 2.0 ;
+  par[1] =  geom->GetRailPart3(1) / 2.0 ;
+  par[2] =  geom->GetRailPart3(2) / 2.0 ;
+  TVirtualMC::GetMC()->Gsvolu("PRP3", "BOX ", idtmed[716], par, 3) ;
 
-   for ( Int_t iphi = 1; iphi <= fGeom->GetNumberOfModulesPhi(); iphi++ ) { // the number of micromegas modules in phi per PHOS module
-      Float_t z = ( fGeom->GetPPSDBoxSize(2) - fGeom->GetPPSDModuleSize(2) ) / 2. ;
+  y0     =   (geom->GetRailOuterSize(1) - geom->GetRailPart3(1))  / 2.0 ;
+  TVirtualMC::GetMC()->Gspos("PRP3", 1, "PRAI", 0.0, y0, 0.0, 0, "ONLY") ; 
 
-      for ( Int_t iz = 1; iz <= fGeom->GetNumberOfModulesZ(); iz++ ) { // the number of micromegas modules in z per PHOS module
-       gMC->Gspos("MPPS", ++copyNumbertop, "PPSD", x, yt, z, 0, "ONLY") ;
-       gMC->Gspos("MPPS", ++copyNumberbot, "PPSD", x, yb, z, 0, "ONLY") ; 
-       z = z - fGeom->GetPPSDModuleSize(2) ;
-      } // end of Z module loop   
-      x = x -  fGeom->GetPPSDModuleSize(0) ; 
-    } // end of phi module loop
+  // --- The wall of the cradle
+  // --- The wall is empty: steel thin walls and air inside
 
-   // The Lead converter between two air gaps
-   // 1. Upper air gap
+  par[1] =  TMath::Sqrt(TMath::Power((geom->GetIPtoCPVDistance() + geom->GetOuterBoxSize(3)),2) +
+                       TMath::Power((geom->GetOuterBoxSize(1)/2),2))+10. ;
+  par[0] =  par[1] - geom->GetCradleWall(1) ;
+  par[2] =  geom->GetCradleWall(2) / 2.0 ;
+  par[3] =  geom->GetCradleWall(3) ;
+  par[4] =  geom->GetCradleWall(4) ;
+  TVirtualMC::GetMC()->Gsvolu("PCRA", "TUBS", idtmed[716], par, 5) ;
 
-   Float_t uappsd[3] ;
-   uappsd[0] = fGeom->GetPPSDBoxSize(0) / 2.0 ;
-   uappsd[1] = fGeom->GetMicro1ToLeadGap() / 2.0 ; 
-   uappsd[2] = fGeom->GetPPSDBoxSize(2) / 2.0 ;
+  par[0] +=  geom->GetCradleWallThickness() ;
+  par[1] -=  geom->GetCradleWallThickness() ;
+  par[2] -=  geom->GetCradleWallThickness() ;
+  TVirtualMC::GetMC()->Gsvolu("PCRE", "TUBS", idtmed[798], par, 5) ;
+  TVirtualMC::GetMC()->Gspos ("PCRE", 1, "PCRA", 0.0, 0.0, 0.0, 0, "ONLY") ; 
 
-  gMC->Gsvolu("UAPPSD", "BOX ", idtmed[798], uappsd, 3) ; 
+  for (i=0; i<2; i++) {
+    z0 = (2*i-1) * (geom->GetOuterBoxSize(2) + geom->GetCradleWall(2) )/ 2.0  ;
+        TVirtualMC::GetMC()->Gspos("PCRA", i, "ALIC", 0.0, 0.0, z0, 0, "ONLY") ; 
+  }
 
-  y0 = ( fGeom->GetPPSDBoxSize(1) - 2 * fGeom->GetMicromegas1Thickness() - fGeom->GetMicro1ToLeadGap() ) / 2. ; 
+  // --- The "wheels" of the cradle
+  
+  par[0] = geom->GetCradleWheel(0) / 2;
+  par[1] = geom->GetCradleWheel(1) / 2;
+  par[2] = geom->GetCradleWheel(2) / 2;
+  TVirtualMC::GetMC()->Gsvolu("PWHE", "BOX ", idtmed[716], par, 3) ;
+
+  y0 = -(geom->GetRailsDistanceFromIP() - geom->GetRailRoadSize(1) -
+        geom->GetCradleWheel(1)/2) ;
+  for (i=0; i<2; i++) {
+    z0 = (2*i-1) * ((geom->GetOuterBoxSize(2) + geom->GetCradleWheel(2))/ 2.0 +
+                    geom->GetCradleWall(2));
+    for (j=0; j<2; j++) {
+      copy = 2*i + j;
+      x0 = (2*j-1) * geom->GetDistanceBetwRails()  / 2.0 ;
+      TVirtualMC::GetMC()->Gspos("PWHE", copy, "ALIC", x0, y0, z0, 0, "ONLY") ; 
+    }
+  }
 
-  gMC->Gspos("UAPPSD", 1, "PPSD", 0.0, y0, 0.0, 0, "ONLY") ; 
+}
 
-   // 2. Lead converter
+//_____________________________________________________________________________
+void AliPHOSv0::AddAlignableVolumes() const
+{
+  //
+  // Create entries for alignable volumes associating the symbolic volume
+  // name with the corresponding volume path. Needs to be syncronized with
+  // eventual changes in the geometry
+  // Alignable volumes are:
+  // 1) PHOS modules as a whole
+  // 2) Cradle
+  // 3) Cradle wheels
+  // 4) Strip units (group of 2x8 crystals)
+
+  TString volpath, symname;
+
+  // Alignable modules
+  // Volume path /ALIC_1/PHOS_<i> => symbolic name /PHOS/Module<i>, <i>=1,2,3,4,5
+  
+  AliGeomManager::ELayerID idPHOS1 = AliGeomManager::kPHOS1;
+  AliGeomManager::ELayerID idPHOS2 = AliGeomManager::kPHOS2;
+  Int_t modUID, modnum = 0;
+  TString physModulePath="/ALIC_1/PHOS_";
+  TString symbModuleName="PHOS/Module";
+  Int_t nModules = GetGeometry()->GetNModules();
+  
+  char im[5] ;
+  for(Int_t iModule=1; iModule<=nModules; iModule++){
+    snprintf(im,5,"%d",iModule) ;
+    modUID = AliGeomManager::LayerToVolUID(idPHOS1,modnum++);
+    if(strstr(GetTitle(),im)==0 && strcmp(GetTitle(),"IHEP")!=0 && strcmp(GetTitle(),"noCPV")!=0)
+      continue ;
+    volpath = physModulePath;
+    volpath += iModule;
+    //    volpath += "/PEMC_1/PCOL_1/PTIO_1/PCOR_1/PAGA_1/PTII_1";
  
-  Float_t lcppsd[3] ; 
-  lcppsd[0] = fGeom->GetPPSDBoxSize(0) / 2.0 ;
-  lcppsd[1] = fGeom->GetLeadConverterThickness() / 2.0 ; 
-  lcppsd[2] = fGeom->GetPPSDBoxSize(2) / 2.0 ;
+   // Check the volume path if not all 5 modules exist
+    if (!gGeoManager->CheckPath(volpath.Data())) {                                                                                         
+      AliError(Form("Volume path %s not valid!",volpath.Data()));                                                                          
+      continue;                                                                                                                            
+    }                                                                                                                                      
  
-  gMC->Gsvolu("LCPPSD", "BOX ", idtmed[712], lcppsd, 3) ; 
-  
-  y0 = y0 - fGeom->GetMicro1ToLeadGap() / 2. - fGeom->GetLeadConverterThickness() / 2. ; 
+    symname = symbModuleName;
+    symname += iModule;
+    if(!gGeoManager->SetAlignableEntry(symname.Data(),volpath.Data(),modUID))
+      continue ;
+//      AliFatal(Form("Alignable entry %s not created. Volume path %s not valid", symname.Data(),volpath.Data()));
+
+    // Creates the Tracking to Local transformation matrix for PHOS modules
+    TGeoPNEntry *alignableEntry = gGeoManager->GetAlignableEntryByUID(modUID) ;
+
+    Float_t angle = GetGeometry()->GetPHOSAngle(iModule);
+    TGeoHMatrix* globMatrix = alignableEntry->GetGlobalOrig();
+
+    TGeoHMatrix *matTtoL = new TGeoHMatrix;
+    matTtoL->RotateZ(-90.+angle);
+    matTtoL->MultiplyLeft(&(globMatrix->Inverse()));
+    alignableEntry->SetMatrix(matTtoL);
+  }
 
-  gMC->Gspos("LCPPSD", 1, "PPSD", 0.0, y0, 0.0, 0, "ONLY") ; 
+  //Aligning of CPV should be done for volume PCPV_1
+  symbModuleName="PHOS/Module";
+  modnum=0;
+  for(Int_t iModule=1; iModule<=nModules; iModule++){
+    if(strstr(GetTitle(),"noCPV"))
+      continue ;
+    snprintf(im,5,"%d",iModule) ;
+    modUID = AliGeomManager::LayerToVolUID(idPHOS2,modnum++);
+    if(strstr(GetTitle(),im)==0 && strcmp(GetTitle(),"IHEP")!=0)
+      continue ;
+    volpath = physModulePath;
+    volpath += iModule;
+    volpath += "/PCPV_1";
+    // Check the volume path
+    if (!gGeoManager->CheckPath(volpath.Data())) {
+      AliError(Form("Volume path %s not valid!",volpath.Data()));
+      continue;
+    }
 
-  // 3. Lower air gap
+    symname = symbModuleName;
+    symname += iModule;
+    symname += "/CPV";
+    if(!gGeoManager->SetAlignableEntry(symname.Data(),volpath.Data(),modUID))
+      AliFatal(Form("Alignable entry %s not created. Volume path %s not valid", symname.Data(),volpath.Data()));
+          
+    // Creates the TGeo Local to Tracking transformation matrix ...
+    TGeoPNEntry *alignableEntry = gGeoManager->GetAlignableEntryByUID(modUID) ;
+
+    Float_t angle = GetGeometry()->GetPHOSAngle(iModule);
+    TGeoHMatrix* globMatrix = alignableEntry->GetGlobalOrig();
+
+    TGeoHMatrix *matTtoL = new TGeoHMatrix;
+    matTtoL->RotateZ(-90.+angle);
+    matTtoL->MultiplyLeft(&(globMatrix->Inverse()));
+    alignableEntry->SetMatrix(matTtoL);
+    
+  }
 
-  Float_t lappsd[3] ; 
-  lappsd[0] = fGeom->GetPPSDBoxSize(0) / 2.0 ; 
-  lappsd[1] = fGeom->GetLeadToMicro2Gap() / 2.0 ; 
-  lappsd[2] = fGeom->GetPPSDBoxSize(2) / 2.0 ;
+  // Alignable cradle walls
+  // Volume path /ALIC_1/PCRA_<i> => symbolic name /PHOS/Cradle<i>, <i>=0,1
 
-  gMC->Gsvolu("LAPPSD", "BOX ", idtmed[798], lappsd, 3) ; 
-    
-  y0 = y0 - fGeom->GetLeadConverterThickness() / 2. - fGeom->GetLeadToMicro2Gap()  / 2. ; 
-  
-  gMC->Gspos("LAPPSD", 1, "PPSD", 0.0, y0, 0.0, 0, "ONLY") ; 
-   
-}
+  TString physCradlePath="/ALIC_1/PCRA_";
+  TString symbCradleName="PHOS/Cradle";
+  Int_t nCradles = 2;
 
-//___________________________________________________________________________
-Int_t AliPHOSv0::Digitize(Float_t Energy){
-  Float_t fB = 100000000. ;
-  Float_t fA = 0. ;
-  Int_t chan = Int_t(fA + Energy*fB ) ;
-  return chan ;
-}
-//___________________________________________________________________________
-void AliPHOSv0::FinishEvent()
-{
-  cout << "//_____________________________________________________" << endl ;
-  cout << "<I> AliPHOSv0::FinishEvent() -- Starting digitalization" << endl ;
-  Int_t i ;
-  TClonesArray &lDigits = *fDigits ;
-  AliPHOSHit  * hit ;
-  AliPHOSDigit * digit ;
-
-  for ( i = 0 ; i < fNTmpHits ; i++ ) {
-    hit = (AliPHOSHit*)fTmpHits->At(i) ;
-    digit = new AliPHOSDigit(hit->GetId(),Digitize(hit->GetEnergy())) ;
-    new(lDigits[fNdigits]) AliPHOSDigit(* digit) ;
-    fNdigits++;  delete digit ;    
+  for(Int_t iCradle=0; iCradle<nCradles; iCradle++){
+    volpath = physCradlePath;
+    volpath += iCradle;
+    symname = symbCradleName;
+    symname += iCradle;
+    gGeoManager->SetAlignableEntry(symname.Data(),volpath.Data());
   }
 
-  // Reset the array of all the "accumulated hits" of this event.
-  fNTmpHits = 0 ;
-  fTmpHits->Delete();
-}
-
-//____________________________________________________________________________
-void AliPHOSv0::Init(void)
-{
-  Int_t i;
+  // Alignable wheels
+  // Volume path /ALIC_1/PWHE_<i> => symbolic name /PHOS/Wheel<i>, i=0,1,2,3
 
-  printf("\n");
-  for(i=0;i<35;i++) printf("*");
-  printf(" PHOS_INIT ");
-  for(i=0;i<35;i++) printf("*");
-  printf("\n");
+  TString physWheelPath="/ALIC_1/PWHE_";
+  TString symbWheelName="PHOS/Wheel";
+  Int_t nWheels = 4;
 
-  // Here the PHOS initialisation code (if any!)
+  for(Int_t iWheel=0; iWheel<nWheels; iWheel++){
+    volpath = physWheelPath;
+    volpath += iWheel;
+    symname = symbWheelName;
+    symname += iWheel;
+    gGeoManager->SetAlignableEntry(symname.Data(),volpath.Data());
+  }
 
-  for(i=0;i<80;i++) printf("*");
-  printf("\n");
-  
-}
+  //Physical strip path is a combination of: physModulePath + module number + 
+  //physStripPath + strip number == ALIC_1/PHOS_N/..../PSTR_M
+  const Int_t nStripsX = GetGeometry()->GetEMCAGeometry()->GetNStripX();
+  const Int_t nStripsZ = GetGeometry()->GetEMCAGeometry()->GetNStripZ();
+  TString partialPhysStripName(100);
+  TString fullPhysStripName(100);
+  TString partialSymbStripName(100);
+  TString fullSymbStripName(100);
+
+  for(Int_t module = 1; module <= nModules; ++module){
+
+    snprintf(im,5,"%d",module) ;
+    if(strstr(GetTitle(),im)==0 && strcmp(GetTitle(),"IHEP")!=0 && strcmp(GetTitle(),"noCPV")!=0)
+      continue ;
+
+    volpath = physModulePath;
+    volpath += module;
+    // Check the volume path if not all 5 modules exist
+    if (!gGeoManager->CheckPath(volpath.Data())) {
+      AliError(Form("Volume path %s does not exist",volpath.Data())) ;
+      continue;
+    }
 
-//___________________________________________________________________________
-void AliPHOSv0::MakeBranch(Option_t* opt)
-{  
-  //
-  // Create a new branch in the current Root Tree
-  // The branch of fHits is automatically split
-  //
-  AliDetector::MakeBranch(opt) ;
-  
-  char branchname[10];
-  sprintf(branchname,"%s",GetName());
-  char *cd = strstr(opt,"D");
-  
-  if (fDigits && gAlice->TreeD() && cd) {
-    gAlice->TreeD()->Branch(branchname,&fDigits, fBufferSize);
-    printf("* AliPHOS::MakeBranch * Making Branch %s for digits\n",branchname);
+    partialPhysStripName  = physModulePath;
+    partialPhysStripName += module;
+    partialPhysStripName += "/PEMC_1/PCOL_1/PTIO_1/PCOR_1/PAGA_1/PTII_1/PSTR_";
+
+    partialSymbStripName  = symbModuleName;
+    partialSymbStripName += module;
+    partialSymbStripName += "/Strip_";
+
+    for(Int_t i = 0, ind1D = 1; i < nStripsX; ++i){//ind1D starts from 1 (PSTR_1...PSTR_224...)
+      for(Int_t j = 0; j < nStripsZ; ++j, ++ind1D){
+         fullPhysStripName = partialPhysStripName;
+         fullPhysStripName += ind1D;
+         
+         fullSymbStripName  = partialSymbStripName;
+         fullSymbStripName += i;//ind1D;
+         fullSymbStripName += '_';
+         fullSymbStripName += j;
+
+         gGeoManager->SetAlignableEntry(fullSymbStripName.Data(), fullPhysStripName.Data());
+
+         // Creates the TGeo Local to Tracking transformation matrix ...
+         TGeoPNEntry *alignableEntry = gGeoManager->GetAlignableEntry(fullSymbStripName.Data()) ;
+         const char *path = alignableEntry->GetTitle();
+         if (!gGeoManager->cd(path))
+           AliFatal(Form("Volume path %s not valid!",path));
+         TGeoHMatrix matLtoT = *gGeoManager->GetCurrentMatrix() ;
+         Double_t refl[3]={-1.,-1.,-1.} ;
+         matLtoT.SetScale(refl) ;
+         TGeoHMatrix *matTtoL = new TGeoHMatrix(matLtoT.Inverse());
+         char phosPath[50] ;
+         snprintf(phosPath,50,"/ALIC_1/PHOS_%d",module) ;
+         if (!gGeoManager->cd(phosPath)){
+            AliFatal("Geo manager can not find path \n");
+         }
+         TGeoHMatrix *mPHOS = gGeoManager->GetCurrentMatrix();
+         if (mPHOS) 
+           matTtoL->Multiply(mPHOS);
+         else{
+           AliFatal("Geo matrixes are not loaded \n") ;
+         }
+         //Switch y<->z
+         Double_t rot[9]={1.,0.,0.,  0.,1.,0., 0.,0.,1.} ;
+         matTtoL->SetRotation(rot) ;
+         alignableEntry->SetMatrix(matTtoL);
+
+/*
+  //Check poisition of corner cell of the strip
+  AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
+  Int_t relid[4] ; 
+  relid[0] = module ;
+  relid[1] = 0 ;
+  Int_t iStrip=ind1D ;
+  Int_t icell=1 ;
+  Int_t raw = geom->GetEMCAGeometry()->GetNCellsXInStrip()*((iStrip-1)/geom->GetEMCAGeometry()->GetNStripZ()) +
+                1 + (icell-1)/geom->GetEMCAGeometry()->GetNCellsZInStrip() ;
+  Int_t col = geom->GetEMCAGeometry()->GetNCellsZInStrip()*(1+(iStrip-1)%geom->GetEMCAGeometry()->GetNStripZ()) - 
+                (icell-1)%geom->GetEMCAGeometry()->GetNCellsZInStrip() ;
+  if(col==0) col=geom->GetNZ() ;
+  relid[2] = raw ;
+  relid[3] = col ;
+  Float_t xG,zG ; 
+  geom->RelPosInModule(relid, xG, zG) ;
+printf("============\n") ;
+printf("Geometry: x=%f, z=%f \n",xG,zG) ;
+  Int_t absid ; 
+  geom->RelToAbsNumbering(relid,absid) ;
+  Double_t pos[3]= {-2.2*3.5,0.0,1.1}; //Position incide the strip (Y coordinalte is not important)
+  Double_t posC[3]={0.0,0.0,0.}; //Global position
+  matTtoL->MasterToLocal(pos,posC);
+printf("Matrix:   x=%f, z=%f, y=%f \n",posC[0],posC[2],posC[1]) ;
+*/
+      }
+    }
   }
 }
 
-//_____________________________________________________________________________
-void AliPHOSv0::Reconstruction(AliPHOSReconstructioner * Reconstructioner)
-{ 
-  // reinitializes the existing RecPoint Lists and steers the reconstruction processes
+//____________________________________________________________________________
+Float_t AliPHOSv0::ZMin(void) const
+{
+  // Overall dimension of the PHOS (min)
 
-  fReconstructioner = Reconstructioner ;
+  AliPHOSGeometry * geom = GetGeometry() ; 
 
-  if (fEmcClusters) { 
-    fEmcClusters->Delete() ; 
-    delete fEmcClusters ;
-    fEmcClusters = 0 ; 
-  }
-  fEmcClusters= new RecPointsList("AliPHOSEmcRecPoint", 100) ;
-  if (fPpsdClusters) { 
-    fPpsdClusters->Delete() ; 
-    delete fPpsdClusters ; 
-    fPpsdClusters = 0 ; 
-  }
-  fPpsdClusters = new RecPointsList("AliPHOSPpsdRecPoint", 100) ;
+  return -geom->GetOuterBoxSize(2)/2.;
+}
 
-  if (fTrackSegments) {  
-   fTrackSegments->Delete() ; 
-    delete fTrackSegments ; 
-    fTrackSegments = 0 ; 
-  }
-  fTrackSegments = new TrackSegmentsList(100) ;
- if (fRecParticles) {  
-   fRecParticles->Delete() ; 
-    delete fRecParticles ; 
-    fRecParticles = 0 ; 
-  }
-  fRecParticles = new RecParticlesList("AliPHOSRecParticle", 100) ;
+//____________________________________________________________________________
+Float_t AliPHOSv0::ZMax(void) const
+{
+  // Overall dimension of the PHOS (max)
 
-  fReconstructioner->Make(fDigits, fEmcClusters, fPpsdClusters, fTrackSegments, fRecParticles);
+  AliPHOSGeometry * geom = GetGeometry() ; 
 
+  return  geom->GetOuterBoxSize(2)/2.;
 }
 
 //____________________________________________________________________________
-void AliPHOSv0::StepManager(void)
+void AliPHOSv0::Init(void)
 {
-  Int_t          relid[4] ;      // (box, layer, row, column) indices
-  Float_t        xyze[4] ;       // position wrt MRS and energy deposited
-  TLorentzVector pos ;
-  Int_t copy;
-
-  TString name = fGeom->GetName() ; 
-
-  if ( name == "GPS2" ) { // the CPV is a PPSD
-    if( gMC->CurrentVolID(copy) == gMC->VolId("GCEL") )
-    //     if( strcmp ( gMC->CurrentVolName(), "GCEL" ) == 0 )  // We are inside a gas cell 
-    {
-      gMC->TrackPosition(pos) ;
-      xyze[0] = pos[0] ;
-      xyze[1] = pos[1] ;
-      xyze[2] = pos[2] ;
-      xyze[3] = gMC->Edep() ; 
-
-      if ( xyze[3] != 0 ) { // there is deposited energy 
-               gMC->CurrentVolOffID(5, relid[0]) ;  // get the PHOS Module number
-               gMC->CurrentVolOffID(3, relid[1]) ;  // get the Micromegas Module number 
-      // 1-> Geom->GetNumberOfModulesPhi() *  fGeom->GetNumberOfModulesZ() upper                         
-      //  >  fGeom->GetNumberOfModulesPhi()  *  fGeom->GetNumberOfModulesZ() lower
-               gMC->CurrentVolOffID(1, relid[2]) ;  // get the row number of the cell
-        gMC->CurrentVolID(relid[3]) ;        // get the column number 
-
-       // get the absolute Id number
-
-       Int_t absid ; 
-               fGeom->RelToAbsNumbering(relid,absid) ; 
-
-       // add current hit to the hit list      
-       AddHit(gAlice->CurrentTrack(), absid, xyze);
-
-      } // there is deposited energy 
-     } // We are inside the gas of the CPV  
-   } // GPS2 configuration
+  // Just prints an information message
   
-   if(gMC->CurrentVolID(copy) == gMC->VolId("PXTL") ) 
-  //      if( strcmp ( gMC->CurrentVolName(), "PXTL" ) == 0 ) { //  We are inside a PWO crystal
-     {
-       gMC->TrackPosition(pos) ;
-       xyze[0] = pos[0] ;
-       xyze[1] = pos[1] ;
-       xyze[2] = pos[2] ;
-       xyze[3] = gMC->Edep() ;
-
-       if ( xyze[3] != 0 ) {
-          gMC->CurrentVolOffID(10, relid[0]) ; // get the PHOS module number ;
-          relid[1] = 0   ;                    // means PW04
-          gMC->CurrentVolOffID(4, relid[2]) ; // get the row number inside the module
-          gMC->CurrentVolOffID(3, relid[3]) ; // get the cell number inside the module
-
-      // get the absolute Id number
-
-          Int_t absid ; 
-          fGeom->RelToAbsNumbering(relid, absid) ; 
-      // add current hit to the hit list
+  Int_t i;
 
-          AddHit(gAlice->CurrentTrack(), absid, xyze);
+  if(AliLog::GetGlobalDebugLevel()>0) {
+    TString st ; 
+    for(i=0;i<35;i++) 
+      st += "*";
+    Info("Init", "%s", st.Data()) ;  
+    // Here the PHOS initialisation code (if any!)
     
-       } // there is deposited energy
-    } // we are inside a PHOS Xtal
-}
+    AliPHOSGeometry * geom = GetGeometry() ; 
 
+    if (geom!=0)  
+      Info("Init", "AliPHOS%s: PHOS geometry intialized for %s", Version().Data(), geom->GetName()) ;
+    else
+      Info("Init", "AliPHOS%s: PHOS geometry initialization failed !", Version().Data()) ;       
+
+    Info("Init", "%s", st.Data()) ;  
+  }
+}