Code for MUON Station1 (I.Hrivnacova)
authorhristov <hristov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 2 May 2003 15:09:39 +0000 (15:09 +0000)
committerhristov <hristov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 2 May 2003 15:09:39 +0000 (15:09 +0000)
180 files changed:
MUON/AliMUONSt1Decoder.cxx
MUON/AliMUONSt1Decoder.h
MUON/AliMUONSt1ElectronicElement.cxx
MUON/AliMUONSt1ElectronicElement.h
MUON/AliMUONSt1IniReader.cxx
MUON/AliMUONSt1IniReader.h
MUON/AliMUONSt1Response.cxx
MUON/AliMUONSt1Response.h
MUON/AliMUONSt1ResponseParameter.h
MUON/AliMUONSt1ResponseRule.cxx
MUON/AliMUONSt1ResponseRule.h
MUON/AliMUONSt1Segmentation.cxx
MUON/AliMUONSt1Segmentation.h
MUON/AliMUONSt1Types.h [new file with mode: 0644]
MUON/AliMUONv1.cxx
MUON/AliMUONv1.h
MUON/AliMUONv2.cxx
MUON/AliMUONv2.h
MUON/MUONLinkDef.h
MUON/MUONLinkDefMapping.h [new file with mode: 0644]
MUON/libMUON.pkg
MUON/libMUON.pkg.mapping [new file with mode: 0644]
MUON/mapping/AliMpArea.cxx [new file with mode: 0755]
MUON/mapping/AliMpArea.h [new file with mode: 0755]
MUON/mapping/AliMpBasicTypes.h [new file with mode: 0755]
MUON/mapping/AliMpConnection.cxx [new file with mode: 0755]
MUON/mapping/AliMpConnection.h [new file with mode: 0755]
MUON/mapping/AliMpConstants.cxx [new file with mode: 0755]
MUON/mapping/AliMpConstants.h [new file with mode: 0755]
MUON/mapping/AliMpDirection.h [new file with mode: 0755]
MUON/mapping/AliMpFiles.cxx [new file with mode: 0755]
MUON/mapping/AliMpFiles.h [new file with mode: 0755]
MUON/mapping/AliMpGraphContext.cxx [new file with mode: 0755]
MUON/mapping/AliMpGraphContext.h [new file with mode: 0755]
MUON/mapping/AliMpGraphicsTypes.h [new file with mode: 0644]
MUON/mapping/AliMpIntPair.cxx [new file with mode: 0755]
MUON/mapping/AliMpIntPair.h [new file with mode: 0755]
MUON/mapping/AliMpMotif.cxx [new file with mode: 0755]
MUON/mapping/AliMpMotif.h [new file with mode: 0755]
MUON/mapping/AliMpMotifMap.cxx [new file with mode: 0755]
MUON/mapping/AliMpMotifMap.h [new file with mode: 0755]
MUON/mapping/AliMpMotifPainter.cxx [new file with mode: 0755]
MUON/mapping/AliMpMotifPainter.h [new file with mode: 0755]
MUON/mapping/AliMpMotifPosition.cxx [new file with mode: 0755]
MUON/mapping/AliMpMotifPosition.h [new file with mode: 0755]
MUON/mapping/AliMpMotifPositionPadIterator.cxx [new file with mode: 0755]
MUON/mapping/AliMpMotifPositionPadIterator.h [new file with mode: 0755]
MUON/mapping/AliMpMotifSpecial.cxx [new file with mode: 0755]
MUON/mapping/AliMpMotifSpecial.h [new file with mode: 0755]
MUON/mapping/AliMpMotifType.cxx [new file with mode: 0755]
MUON/mapping/AliMpMotifType.h [new file with mode: 0755]
MUON/mapping/AliMpMotifTypePadIterator.cxx [new file with mode: 0755]
MUON/mapping/AliMpMotifTypePadIterator.h [new file with mode: 0755]
MUON/mapping/AliMpMotifTypes.h [new file with mode: 0644]
MUON/mapping/AliMpNeighboursPadIterator.cxx [new file with mode: 0755]
MUON/mapping/AliMpNeighboursPadIterator.h [new file with mode: 0755]
MUON/mapping/AliMpPad.cxx [new file with mode: 0755]
MUON/mapping/AliMpPad.h [new file with mode: 0755]
MUON/mapping/AliMpPadIteratorPtr.cxx [new file with mode: 0755]
MUON/mapping/AliMpPadIteratorPtr.h [new file with mode: 0755]
MUON/mapping/AliMpPadPair.cxx [new file with mode: 0644]
MUON/mapping/AliMpPadPair.h [new file with mode: 0644]
MUON/mapping/AliMpPadRow.cxx [new file with mode: 0755]
MUON/mapping/AliMpPadRow.h [new file with mode: 0755]
MUON/mapping/AliMpPadRowSegment.cxx [new file with mode: 0755]
MUON/mapping/AliMpPadRowSegment.h [new file with mode: 0755]
MUON/mapping/AliMpPlane.cxx [new file with mode: 0644]
MUON/mapping/AliMpPlane.h [new file with mode: 0644]
MUON/mapping/AliMpPlaneAreaPadIterator.cxx [new file with mode: 0755]
MUON/mapping/AliMpPlaneAreaPadIterator.h [new file with mode: 0755]
MUON/mapping/AliMpPlaneSegmentation.cxx [new file with mode: 0644]
MUON/mapping/AliMpPlaneSegmentation.h [new file with mode: 0644]
MUON/mapping/AliMpPlaneType.h [new file with mode: 0755]
MUON/mapping/AliMpPlaneTypes.h [new file with mode: 0644]
MUON/mapping/AliMpReader.cxx [new file with mode: 0755]
MUON/mapping/AliMpReader.h [new file with mode: 0755]
MUON/mapping/AliMpRow.cxx [new file with mode: 0755]
MUON/mapping/AliMpRow.h [new file with mode: 0755]
MUON/mapping/AliMpRowPainter.cxx [new file with mode: 0755]
MUON/mapping/AliMpRowPainter.h [new file with mode: 0755]
MUON/mapping/AliMpRowSegment.cxx [new file with mode: 0755]
MUON/mapping/AliMpRowSegment.h [new file with mode: 0755]
MUON/mapping/AliMpRowSegmentPainter.cxx [new file with mode: 0755]
MUON/mapping/AliMpRowSegmentPainter.h [new file with mode: 0755]
MUON/mapping/AliMpRowSegmentSpecial.cxx [new file with mode: 0755]
MUON/mapping/AliMpRowSegmentSpecial.h [new file with mode: 0755]
MUON/mapping/AliMpSector.cxx [new file with mode: 0755]
MUON/mapping/AliMpSector.h [new file with mode: 0755]
MUON/mapping/AliMpSectorAreaHPadIterator.cxx [new file with mode: 0755]
MUON/mapping/AliMpSectorAreaHPadIterator.h [new file with mode: 0755]
MUON/mapping/AliMpSectorAreaVPadIterator.cxx [new file with mode: 0644]
MUON/mapping/AliMpSectorAreaVPadIterator.h [new file with mode: 0644]
MUON/mapping/AliMpSectorPadIterator.cxx [new file with mode: 0755]
MUON/mapping/AliMpSectorPadIterator.h [new file with mode: 0755]
MUON/mapping/AliMpSectorPainter.cxx [new file with mode: 0755]
MUON/mapping/AliMpSectorPainter.h [new file with mode: 0755]
MUON/mapping/AliMpSectorPosition.cxx [new file with mode: 0644]
MUON/mapping/AliMpSectorPosition.h [new file with mode: 0644]
MUON/mapping/AliMpSectorSegmentation.cxx [new file with mode: 0755]
MUON/mapping/AliMpSectorSegmentation.h [new file with mode: 0755]
MUON/mapping/AliMpSectorTypes.h [new file with mode: 0644]
MUON/mapping/AliMpSubZone.cxx [new file with mode: 0755]
MUON/mapping/AliMpSubZone.h [new file with mode: 0755]
MUON/mapping/AliMpSubZonePainter.cxx [new file with mode: 0755]
MUON/mapping/AliMpSubZonePainter.h [new file with mode: 0755]
MUON/mapping/AliMpTransformPadIterator.cxx [new file with mode: 0755]
MUON/mapping/AliMpTransformPadIterator.h [new file with mode: 0755]
MUON/mapping/AliMpTransformer.cxx [new file with mode: 0644]
MUON/mapping/AliMpTransformer.h [new file with mode: 0644]
MUON/mapping/AliMpVIndexed.cxx [new file with mode: 0755]
MUON/mapping/AliMpVIndexed.h [new file with mode: 0755]
MUON/mapping/AliMpVMotif.cxx [new file with mode: 0755]
MUON/mapping/AliMpVMotif.h [new file with mode: 0755]
MUON/mapping/AliMpVPadIterator.cxx [new file with mode: 0755]
MUON/mapping/AliMpVPadIterator.h [new file with mode: 0755]
MUON/mapping/AliMpVPainter.cxx [new file with mode: 0755]
MUON/mapping/AliMpVPainter.h [new file with mode: 0755]
MUON/mapping/AliMpVRowSegment.cxx [new file with mode: 0755]
MUON/mapping/AliMpVRowSegment.h [new file with mode: 0755]
MUON/mapping/AliMpVSegmentation.cxx [new file with mode: 0644]
MUON/mapping/AliMpVSegmentation.h [new file with mode: 0644]
MUON/mapping/AliMpZone.cxx [new file with mode: 0755]
MUON/mapping/AliMpZone.h [new file with mode: 0755]
MUON/mapping/AliMpZonePainter.cxx [new file with mode: 0755]
MUON/mapping/AliMpZonePainter.h [new file with mode: 0755]
MUON/mapping/data/bending_plane/motifA.dat [new file with mode: 0755]
MUON/mapping/data/bending_plane/motifB.dat [new file with mode: 0755]
MUON/mapping/data/bending_plane/motifC.dat [new file with mode: 0755]
MUON/mapping/data/bending_plane/motifD.dat [new file with mode: 0755]
MUON/mapping/data/bending_plane/motifE.dat [new file with mode: 0755]
MUON/mapping/data/bending_plane/motifF.dat [new file with mode: 0755]
MUON/mapping/data/bending_plane/motifG.dat [new file with mode: 0755]
MUON/mapping/data/bending_plane/motifH.dat [new file with mode: 0755]
MUON/mapping/data/bending_plane/motifI.dat [new file with mode: 0755]
MUON/mapping/data/bending_plane/motifSpecial8.2.dat [new file with mode: 0755]
MUON/mapping/data/bending_plane/motifSpecial8.3.dat [new file with mode: 0755]
MUON/mapping/data/bending_plane/motifSpecial8.dat [new file with mode: 0755]
MUON/mapping/data/bending_plane/padPosA.dat [new file with mode: 0755]
MUON/mapping/data/bending_plane/padPosB.dat [new file with mode: 0755]
MUON/mapping/data/bending_plane/padPosC.dat [new file with mode: 0755]
MUON/mapping/data/bending_plane/padPosD.dat [new file with mode: 0755]
MUON/mapping/data/bending_plane/padPosE.dat [new file with mode: 0755]
MUON/mapping/data/bending_plane/padPosF.dat [new file with mode: 0755]
MUON/mapping/data/bending_plane/padPosG.dat [new file with mode: 0755]
MUON/mapping/data/bending_plane/padPosH.dat [new file with mode: 0755]
MUON/mapping/data/bending_plane/padPosI.dat [new file with mode: 0755]
MUON/mapping/data/bending_plane/zones.dat [new file with mode: 0755]
MUON/mapping/data/bergToGC.dat [new file with mode: 0755]
MUON/mapping/data/non-bending_plane/motifA.dat [new file with mode: 0755]
MUON/mapping/data/non-bending_plane/motifB.dat [new file with mode: 0755]
MUON/mapping/data/non-bending_plane/motifC.dat [new file with mode: 0755]
MUON/mapping/data/non-bending_plane/motifD.dat [new file with mode: 0755]
MUON/mapping/data/non-bending_plane/motifE.dat [new file with mode: 0755]
MUON/mapping/data/non-bending_plane/motifF.dat [new file with mode: 0755]
MUON/mapping/data/non-bending_plane/motifG.dat [new file with mode: 0755]
MUON/mapping/data/non-bending_plane/motifH.dat [new file with mode: 0755]
MUON/mapping/data/non-bending_plane/motifI.dat [new file with mode: 0755]
MUON/mapping/data/non-bending_plane/motifJ.dat [new file with mode: 0755]
MUON/mapping/data/non-bending_plane/motifK.dat [new file with mode: 0755]
MUON/mapping/data/non-bending_plane/motifL.dat [new file with mode: 0755]
MUON/mapping/data/non-bending_plane/motifM.dat [new file with mode: 0755]
MUON/mapping/data/non-bending_plane/motifN.dat [new file with mode: 0755]
MUON/mapping/data/non-bending_plane/motifSpecial14.10.dat [new file with mode: 0755]
MUON/mapping/data/non-bending_plane/motifSpecial14.dat [new file with mode: 0755]
MUON/mapping/data/non-bending_plane/padPosA.dat [new file with mode: 0755]
MUON/mapping/data/non-bending_plane/padPosB.dat [new file with mode: 0755]
MUON/mapping/data/non-bending_plane/padPosC.dat [new file with mode: 0755]
MUON/mapping/data/non-bending_plane/padPosD.dat [new file with mode: 0755]
MUON/mapping/data/non-bending_plane/padPosE.dat [new file with mode: 0755]
MUON/mapping/data/non-bending_plane/padPosF.dat [new file with mode: 0755]
MUON/mapping/data/non-bending_plane/padPosG.dat [new file with mode: 0755]
MUON/mapping/data/non-bending_plane/padPosH.dat [new file with mode: 0755]
MUON/mapping/data/non-bending_plane/padPosI.dat [new file with mode: 0755]
MUON/mapping/data/non-bending_plane/padPosJ.dat [new file with mode: 0755]
MUON/mapping/data/non-bending_plane/padPosK.dat [new file with mode: 0755]
MUON/mapping/data/non-bending_plane/padPosL.dat [new file with mode: 0755]
MUON/mapping/data/non-bending_plane/padPosM.dat [new file with mode: 0755]
MUON/mapping/data/non-bending_plane/padPosN.dat [new file with mode: 0755]
MUON/mapping/data/non-bending_plane/zones.dat [new file with mode: 0755]
MUON/mapping/data/non-bending_plane/zones_special.dat [new file with mode: 0755]

index 1cf5869..5334752 100644 (file)
 
 /*
 $Log$
+Revision 1.1  2003/01/28 13:21:06  morsch
+Improved response simulation for station 1.
+(M. Mac Cormick, I. Hrivnacova, D. Guez)
+
 */
 
 // Authors: David Guez, Ivana Hrivnacova, Marion MacCormick; IPN Orsay
@@ -33,8 +37,6 @@ $Log$
 
 #include "AliMUONSt1Decoder.h"
 
-using namespace std;
-
 //_____________________________________________________________________
 vector<string> decoder::SplitNtuples(const string& s,
                                      const string& leftSep,
index 8563076..ec99e00 100644 (file)
 #include <vector>
 #include <utility>
 #include <string>
-#include <cstdlib>
+
+#include "AliMUONSt1Types.h"
 
 namespace decoder
 {
-  using std::vector;
-  using std::pair;
-  using std::string;
   vector<string> SplitNtuples(const string& s,
                               const string& leftSep ="({[\"'/",
                               const string& rightSep=")}]\"'/");
index 3ea8d65..7e63ca5 100644 (file)
 
 /*
 $Log$
+Revision 1.1  2003/01/28 13:21:06  morsch
+Improved response simulation for station 1.
+(M. Mac Cormick, I. Hrivnacova, D. Guez)
+
 */
 
 // Authors: David Guez, Ivana Hrivnacova, Marion MacCormick; IPN Orsay
@@ -105,7 +109,7 @@ Bool_t AliMUONSt1ElectronicElement::IsInRange(Int_t numVar,Double_t x) const
 }
 
 //______________________________________________________________________________
-Bool_t AliMUONSt1ElectronicElement::Contains(const MPad& pad) const
+Bool_t AliMUONSt1ElectronicElement::Contains(const AliMpPad& pad) const
 {
 // is the pad <pad> contained in this range
 // ---
index ab77059..00a6580 100644 (file)
@@ -16,7 +16,7 @@
 // a range of MANU numbers or, finally,
 // a range of gassiplex/MANAS numbers, in a given range of MANU addresses
 
-#include <MPad.h>
+#include "AliMpPad.h"
 
 class AliMUONSt1ElectronicElement : public TObject 
 {
@@ -29,7 +29,7 @@ class AliMUONSt1ElectronicElement : public TObject
     virtual ~AliMUONSt1ElectronicElement();
     
     // methods
-    Bool_t Contains(const MPad& pad) const;
+    Bool_t Contains(const AliMpPad& pad) const;
     void   SetRange(Int_t numVar,Int_t i1,Int_t i2);
     void   SetRange(Int_t numVar,Double_t x1,Double_t x2);
     Bool_t IsInRange(Int_t numVar,Int_t i) const;
index 38fa1da..1a22e15 100644 (file)
 
 /*
 $Log$
+Revision 1.1  2003/01/28 13:21:06  morsch
+Improved response simulation for station 1.
+(M. Mac Cormick, I. Hrivnacova, D. Guez)
+
 */
 
 // Authors: David Guez, Ivana Hrivnacova, Marion MacCormick; IPN Orsay
@@ -30,12 +34,14 @@ $Log$
 // comment lines can be introduced if the first non-blank character
 // is either ';' or '#'
 
-#include <iostream>
-#include <sstream>
+#if !defined(__HP_aCC) && !defined(__alpha)
+  #include <sstream>
+#endif
 
-#include "AliMUONSt1IniReader.h"
+#include <Riostream.h>
+#include <Rstrstream.h>
 
-using namespace std;
+#include "AliMUONSt1IniReader.h"
 
 //______________________________________________________________________
 AliMUONSt1IniReader::AliMUONSt1IniReader()
@@ -92,7 +98,12 @@ bool AliMUONSt1IniReader::ReadNextLine()
   if ( line.empty()) {             // this is a blank line
     return ReadNextLine();
   }
+#if defined (__HP_aCC) || (__alpha)
+  strstream l;
+  l << line;
+#else
   istringstream l(line); 
+#endif    
   
   char c;
 
@@ -122,8 +133,9 @@ bool AliMUONSt1IniReader::ReadNextLine()
       return false;
     }
   }
-  fCurrentType=kUndef;
-  return false;
+  // fCurrentType=kUndef;
+  // return false;
+       // unreachable
 }
 
 //______________________________________________________________________
@@ -170,7 +182,9 @@ AliMUONSt1IniReader::TChapterList AliMUONSt1IniReader::MakeChapterList()
     if (fCurrentType==kChapter) {
       string s= fCurrentName;
       ReadNextLine();
-      ans.insert(TChapter(s,MakeCurrentValueList()));
+      //ans.insert(TChapter(s,MakeCurrentValueList()));
+                   // does not compile on SunOS
+      ans.insert(TChapterList::value_type(s,MakeCurrentValueList()));
     } else ReadNextLine();
     if (fEndOfFile) break;
   }
index ca747a8..ba5767e 100644 (file)
 #include <utility>
 #include <fstream>
 
-using std::string;
-using std::vector;
-using std::multimap;
-using std::ifstream;
-using std::pair;
+#include "AliMUONSt1Types.h"
 
 class AliMUONSt1IniReader
 {
   public:
     enum TType {kUndef,kChapter,kValue};
+
     typedef pair<string,string> TValuePair;
     typedef vector<TValuePair> TValueList;
     typedef pair<string,TValueList> TChapter;
index 3c72834..0f0aa44 100644 (file)
 // The current pulse height responses do not contain any physics
 
 #include <vector>
-#include <cstdlib>
 #include <TMath.h>
 #include <TRandom.h>
 #include <TSystem.h>
 #include <Riostream.h>
-#include <MIntPair.h>
-#include <MPlaneSegmentation.h>
-#include <MPad.h>
-#include <MMotifMap.h>
-#include <MSector.h>
-#include <MPlane.h>
-#include <MZone.h>
-#include <MSubZone.h>
-#include <MVRowSegment.h>
+#include "AliMpIntPair.h"
+#include "AliMpPlaneSegmentation.h"
+#include "AliMpPad.h"
+#include "AliMpMotifMap.h"
+#include "AliMpSector.h"
+#include "AliMpPlane.h"
+#include "AliMpZone.h"
+#include "AliMpSubZone.h"
+#include "AliMpVRowSegment.h"
 #include "AliMUONSt1Response.h"
 #include "AliMUONSt1ResponseParameter.h"
 #include "AliMUONSt1ResponseRule.h"
@@ -422,10 +421,10 @@ void AliMUONSt1Response::ReadFiles()
     }
   }
   //book memory and fill them with .ini files
-  fPlane[0]=MPlane::Create(kBendingPlane);
-  fPlane[1]=MPlane::Create(kNonBendingPlane);
+  fPlane[0]=AliMpPlane::Create(kBendingPlane);
+  fPlane[1]=AliMpPlane::Create(kNonBendingPlane);
   for (i=0;i<2;i++){
-    fPlaneSegmentation[i]= new MPlaneSegmentation(fPlane[i]);
+    fPlaneSegmentation[i]= new AliMpPlaneSegmentation(fPlane[i]);
     ReadIniFile(i);
   }
 }
@@ -448,13 +447,13 @@ Float_t AliMUONSt1Response::IntPH(Float_t eloss)
 
 
 //__________________________________________________________________________
-MZone* AliMUONSt1Response::FindZone(MSector* sector,Int_t posId)
+AliMpZone* AliMUONSt1Response::FindZone(AliMpSector* sector,Int_t posId)
 {
-// to be moved to MSector::
+// to be moved to AliMpSector::
   for (Int_t izone=1;izone<=sector->GetNofZones();izone++){
-    MZone* zone = sector->GetZone(izone);
+    AliMpZone* zone = sector->GetZone(izone);
     for (Int_t isub=0;isub<zone->GetNofSubZones();isub++){
-      MSubZone* sub=zone->GetSubZone(isub);
+      AliMpSubZone* sub=zone->GetSubZone(isub);
       for (Int_t iseg=0;iseg<sub->GetNofRowSegments();iseg++){
        if (sub->GetRowSegment(iseg)->HasMotifPosition(posId)) return zone;
       }
@@ -479,21 +478,21 @@ Int_t  AliMUONSt1Response::DigitResponse(Int_t digit,AliMUONTransientDigit* wher
 
     fCountNofCalls++;
     
-    MIntPair indices(where->PadX(),where->PadY());
-    MPad pad = fPlaneSegmentation[where->Cathode()]->PadByIndices(indices,kFALSE);
+    AliMpIntPair indices(where->PadX(),where->PadY());
+    AliMpPad pad = fPlaneSegmentation[where->Cathode()]->PadByIndices(indices,kFALSE);
     Int_t GC=0;
     Int_t numZone=0;
-    MZone* zone=0;
+    AliMpZone* zone=0;
 
     if (pad.IsValid()) {
-      MIntPair location = pad.GetLocation();
+      AliMpIntPair location = pad.GetLocation();
       //cout<<location.GetFirst()<<endl;
       Int_t posId=abs(location.GetFirst());
-      MSector* sector=0;
+      AliMpSector* sector=0;
       if (fPlane[0]->GetFrontSector()->GetMotifMap()->FindMotifPosition(posId))
-               sector=(MSector*)fPlane[0]->GetFrontSector();
+               sector=(AliMpSector*)fPlane[0]->GetFrontSector();
       else if (fPlane[0]->GetBackSector()->GetMotifMap()->FindMotifPosition(posId))
-               sector=(MSector*)fPlane[0]->GetBackSector();
+               sector=(AliMpSector*)fPlane[0]->GetBackSector();
 
       if (sector) zone=FindZone(sector,posId);
       if (zone){
index 531d41d..542c6b3 100644 (file)
 // Individual pedestals or noise levels can be controlled separately. 
 // The current pulse height responses do not contain any physics
 
-#include <string>
-#include <map>
 #include <TString.h>
 #include <TList.h>
 #include "AliMUONResponseV0.h"
+#include "AliMUONSt1Types.h"
 #include "AliMUONSt1ElectronicElement.h"
 
-using std::string;
-using std::map;
-
-class MPlane;
-class MPlaneSegmentation;
-class MZone;
-class MSector;
+class AliMpPlane;
+class AliMpPlaneSegmentation;
+class AliMpZone;
+class AliMpSector;
 class TArrayF;
 class TObjArray;
 class AliMUONSt1ResponseParameter;
@@ -51,10 +47,7 @@ public:
 
 
 private:
-
-   //private types
-    typedef map<string,AliMUONSt1ResponseParameter*> TParamsMap;
-    typedef map<string,TList*> TListMap;
+    //private constants
     static const Int_t fgkNofZones=4;
     static const TString fgkTopDir;
     static const TString fgkDataDir;
@@ -86,7 +79,7 @@ private:
     static const TString fgkNofSigmaName ;
 
     //protected methods
-    MZone* FindZone(MSector* sector,Int_t posId); // to be moved in MSector::
+    AliMpZone* FindZone(AliMpSector* sector,Int_t posId); // to be moved in AliMpSector::
     void ReadFiles();
     void ReadIniFile(Int_t plane,const TString& fileName,Bool_t rdParam,Bool_t rdRegion,Bool_t rdRule);
     void ReadIniFile(Int_t plane);
@@ -97,8 +90,8 @@ private:
 
 
     //data members
-    MPlane* fPlane[2];       // !The mapping planes
-    MPlaneSegmentation* fPlaneSegmentation[2]; // !The mapping plane segmentation
+    AliMpPlane* fPlane[2];       // !The mapping planes
+    AliMpPlaneSegmentation* fPlaneSegmentation[2]; // !The mapping plane segmentation
     TString fIniFileName[2];// file names for initialisation of each cathode
 
     AliMUONSt1ResponseParameter* fDefaultParameters[2][fgkNofZones]; // !Response for each zone
index 4a47a74..44c8fa7 100644 (file)
 class AliMUONSt1ResponseParameter : public TNamed 
 {
   public:
+   typedef enum {kNone,kValue,kGauss,kFile} TMode;
+   typedef struct {Double_t mean; Double_t sigma;} TGaussParam;
+
+  public:
     AliMUONSt1ResponseParameter();
     AliMUONSt1ResponseParameter(const TString& name,const TString& title);
     virtual ~AliMUONSt1ResponseParameter();
@@ -40,12 +44,12 @@ class AliMUONSt1ResponseParameter : public TNamed
     Int_t ApplyStickyBits(Int_t base) const;
     Bool_t HasPedestal() const {return fPedestalMode != kNone;}
     Bool_t GetState() const {return fState;}
+        
  private:
     static const Int_t fgkNofChannels=64;
-    typedef enum {kNone,kValue,kGauss,kFile} TMode;
-    typedef struct {Double_t mean; Double_t sigma;} TGaussParam;
     typedef union {
-      Double_t values[fgkNofChannels];
+      //Double_t values[fgkNofChannels];
+      Double_t values[64];
       Double_t value;
       TGaussParam gauss;
     } TParam;
index 37dc0c2..f08b4bd 100644 (file)
  
 /*
 $Log$
+Revision 1.1  2003/01/28 13:21:06  morsch
+Improved response simulation for station 1.
+(M. Mac Cormick, I. Hrivnacova, D. Guez)
+
 */
 
 // Authors: David Guez, Ivana Hrivnacova, Marion MacCormick; IPN Orsay
@@ -66,7 +70,7 @@ void AliMUONSt1ResponseRule::AddParameter(AliMUONSt1ResponseParameter* param)
 }
 
 //__________________________________________________________________________
-Bool_t AliMUONSt1ResponseRule::Contains(const MPad& pad) const
+Bool_t AliMUONSt1ResponseRule::Contains(const AliMpPad& pad) const
 {
 // Is this pad is contained in this rule's list
 // ---
index 9ff39a7..4f8cf38 100644 (file)
@@ -16,7 +16,7 @@
 
 #include <TObject.h>
 #include <TList.h>
-#include <MPad.h>
+#include "AliMpPad.h"
 
 class AliMUONSt1ElectronicElement;
 class AliMUONSt1ResponseParameter;
@@ -29,7 +29,7 @@ class AliMUONSt1ResponseRule : public TObject
   
     void   AddElement(AliMUONSt1ElectronicElement* element);
     void   AddParameter(AliMUONSt1ResponseParameter* param);
-    Bool_t Contains(const MPad& pad) const;
+    Bool_t Contains(const AliMpPad& pad) const;
     TList* GetParameters() {return &fParameters;}
 
   private:
index d1c1e0d..5e38c8d 100644 (file)
  
 /*
 $Log$
+Revision 1.1  2003/01/28 13:21:06  morsch
+Improved response simulation for station 1.
+(M. Mac Cormick, I. Hrivnacova, D. Guez)
+
 */
 
 // Authors: David Guez, Ivana Hrivnacova, Marion MacCormick; IPN Orsay
@@ -24,21 +28,16 @@ $Log$
 // Segmentation for MUON station 1 using the external 
 // mapping package
 
-#include <cmath>
-
 #include <Riostream.h>
 #include <TError.h>
 #include <TObjArray.h>
 #include <TVector2.h>
 #include <TF1.h>
 
-#include <MPlane.h>
-#include <MPlaneType.h>
-#include <MPlaneSegmentation.h>
-#include <MPlaneAreaPadIterator.h>
-#include <MSector.h>
-#include <MZone.h>
-#include <MConstants.h>
+#include <AliMpPlane.h>
+#include <AliMpPlaneType.h>
+#include <AliMpPlaneSegmentation.h>
+#include <AliMpPlaneAreaPadIterator.h>
 
 #include "AliMUONSt1Segmentation.h"
 #include "AliRun.h"
@@ -51,7 +50,7 @@ const Float_t  AliMUONSt1Segmentation::fgkWireD = 0.20;
 const Float_t  AliMUONSt1Segmentation::fgkLengthUnit = 0.1; 
 
 //______________________________________________________________________________
-AliMUONSt1Segmentation::AliMUONSt1Segmentation(const MPlaneType planeType) 
+AliMUONSt1Segmentation::AliMUONSt1Segmentation(const AliMpPlaneType planeType) 
 : AliSegmentation(),
   fPlane(0),
   fPlaneSegmentation(0),
@@ -77,8 +76,8 @@ AliMUONSt1Segmentation::AliMUONSt1Segmentation(const MPlaneType planeType)
   fCorrA(0)
 {
 // Normal constructor
-  fPlane = MPlane::Create(planeType);
-  fPlaneSegmentation = new MPlaneSegmentation(fPlane);
+  fPlane = AliMpPlane::Create(planeType);
+  fPlaneSegmentation = new AliMpPlaneSegmentation(fPlane);
 
   fCorrA = new TObjArray(3);
   fCorrA->AddAt(0,0);
@@ -155,7 +154,7 @@ AliMUONSt1Segmentation::operator=(const AliMUONSt1Segmentation& rhs)
 //
 
 //______________________________________________________________________________
-void AliMUONSt1Segmentation::UpdateCurrentPadValues(const MPad& pad)
+void AliMUONSt1Segmentation::UpdateCurrentPadValues(const AliMpPad& pad)
 {
 // Updates current pad values.
 // ---
@@ -221,7 +220,7 @@ void  AliMUONSt1Segmentation::GetPadI(Float_t x, Float_t y,
 // If there is no pad, ix = 0, iy = 0 are returned.
 // ---
 
-  MPad pad = fPlaneSegmentation
+  AliMpPad pad = fPlaneSegmentation
                ->PadByPosition(TVector2(x/fgkLengthUnit, y/fgkLengthUnit), false);
 
   ix = pad.GetIndices().GetFirst();
@@ -247,7 +246,7 @@ void  AliMUONSt1Segmentation::GetPadC(Int_t ix, Int_t iy,
 // If there is no pad, x = 0., y = 0. are returned.
 // ---
 
-  MPad pad = fPlaneSegmentation->PadByIndices(MIntPair(ix,iy));
+  AliMpPad pad = fPlaneSegmentation->PadByIndices(AliMpIntPair(ix,iy));
 
   x = pad.Position().X() * fgkLengthUnit;
   y = pad.Position().Y() * fgkLengthUnit;
@@ -371,8 +370,8 @@ void  AliMUONSt1Segmentation::FirstPad(Float_t xhit, Float_t yhit, Float_t zhit,
   
   fPlaneIterator 
     = fPlaneSegmentation
-        ->CreateIterator(MArea(TVector2(fXhit/fgkLengthUnit, fYhit/fgkLengthUnit), 
-                              TVector2(dx/fgkLengthUnit, dy/fgkLengthUnit)));
+        ->CreateIterator(AliMpArea(TVector2(fXhit/fgkLengthUnit, fYhit/fgkLengthUnit), 
+                                  TVector2(dx/fgkLengthUnit, dy/fgkLengthUnit)));
 
   fPlaneIterator->First();             
 
@@ -412,7 +411,7 @@ Float_t AliMUONSt1Segmentation::Distance2AndOffset(Int_t iX, Int_t iY,
 // labelled by its channel numbers and a coordinate
 // ---
 
-  MPad pad = fPlaneSegmentation->PadByIndices(MIntPair(iX, iY));
+  AliMpPad pad = fPlaneSegmentation->PadByIndices(AliMpIntPair(iX, iY));
   
   if (!pad.IsValid())
     Fatal("Distance2AndOffset", "Cannot locate pad.");
@@ -440,12 +439,12 @@ void AliMUONSt1Segmentation::Neighbours(Int_t iX, Int_t iY,
 // Get next neighbours 
 // ---
 
-  MPad pad = fPlaneSegmentation->PadByIndices(MIntPair(iX,iY));
+  AliMpPad pad = fPlaneSegmentation->PadByIndices(AliMpIntPair(iX,iY));
   Int_t &i = *Nlist;
   i=0;
-  MVPadIterator* iter
+  AliMpVPadIterator* iter
     = fPlaneSegmentation
-      ->CreateIterator(MArea(pad.Position(),2.*pad.Dimensions()*1.1));
+      ->CreateIterator(AliMpArea(pad.Position(),2.*pad.Dimensions()*1.1));
 
   for( iter->First(); !iter->IsDone() && i<10; iter->Next()) {
     Xlist[i] = iter->CurrentItem().GetIndices().GetFirst();
@@ -492,7 +491,7 @@ Int_t AliMUONSt1Segmentation::Sector(Int_t ix, Int_t iy)
 // ---
 
   return fPlaneSegmentation
-           ->Zone(fPlaneSegmentation->PadByIndices(MIntPair(ix, iy)));
+           ->Zone(fPlaneSegmentation->PadByIndices(AliMpIntPair(ix, iy)));
 }
 
 //______________________________________________________________________________
index 5df1429..33a0c11 100644 (file)
 // Segmentation for MUON station 1 using the external 
 // mapping package
 
-#include <MPad.h>
-#include <MPlaneType.h>
+#include "AliMpPad.h"
+#include "AliMpPlaneType.h"
 
 #include "AliSegmentation.h"
 
 class TObjArray;
 
-class MPlane;
-class MPlaneSegmentation;
-class MVPadIterator;
+class AliMpPlane;
+class AliMpPlaneSegmentation;
+class AliMpVPadIterator;
 
 class AliMUONChamber;
 
 class AliMUONSt1Segmentation : public AliSegmentation 
 {
   public:
-    AliMUONSt1Segmentation(const MPlaneType planeType);
+    AliMUONSt1Segmentation(const AliMpPlaneType planeType);
     AliMUONSt1Segmentation(const AliMUONSt1Segmentation& rhs);
     AliMUONSt1Segmentation();
     
@@ -139,7 +139,7 @@ class AliMUONSt1Segmentation : public AliSegmentation
     AliMUONSt1Segmentation& operator=(const AliMUONSt1Segmentation & rhs);
 
     // methods
-    void UpdateCurrentPadValues(const MPad& pad);
+    void UpdateCurrentPadValues(const AliMpPad& pad);
   
     // constants
     static const Float_t  fgkWireD;     // default wire pitch
@@ -150,9 +150,9 @@ class AliMUONSt1Segmentation : public AliSegmentation
 
     // From mapping
     //
-    MPlane*             fPlane;            //  plane (from mapping)
-    MPlaneSegmentation* fPlaneSegmentation;//  plane segmantation (from mapping)
-    MVPadIterator*      fPlaneIterator;    // ! iterator over pads
+    AliMpPlane*             fPlane;            //  plane (from mapping)
+    AliMpPlaneSegmentation* fPlaneSegmentation;//  plane segmantation (from mapping)
+    AliMpVPadIterator*      fPlaneIterator;    // ! iterator over pads
 
     // Wire pitch
     //
diff --git a/MUON/AliMUONSt1Types.h b/MUON/AliMUONSt1Types.h
new file mode 100644 (file)
index 0000000..36b6fea
--- /dev/null
@@ -0,0 +1,42 @@
+#ifndef ALI_MUON_ST1_TYPES_H
+#define ALI_MUON_ST1_TYPES_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+// AliMUONSt1Types
+// ---------------
+// System dependent types definitions for MUON Station1.
+//
+// Authors: David Guez, Ivana Hrivnacova, Marion MacCormick; IPN Orsay
+//
+
+#include <string>
+#include <map>
+#include <vector>
+#include <fstream>
+
+#include "AliMUONSt1SpecialMotif.h"
+
+class TString;
+class AliMUONSt1ResponseParameter;
+
+#ifdef __HP_aCC
+  typedef vector<Int_t>  IntVector;
+  typedef map<Int_t , AliMUONSt1SpecialMotif> TSpecialMap;
+  typedef map<string,AliMUONSt1ResponseParameter*> TParamsMap;
+  typedef map<string,TList*> TListMap;
+#else
+  using std::string;
+  using std::vector;
+  using std::multimap;
+  using std::pair;
+
+  typedef std::vector<Int_t>  IntVector;
+  typedef std::map<Int_t , AliMUONSt1SpecialMotif> TSpecialMap;
+  typedef std::map<std::string,AliMUONSt1ResponseParameter*> TParamsMap;
+  typedef std::map<std::string,TList*> TListMap;
+#endif
+
+#endif //ALI_MUON_ST1_TYPES_H
index cdb9094..a1a8f35 100644 (file)
 
 /*
 $Log$
+Revision 1.40  2003/01/28 13:21:06  morsch
+Improved response simulation for station 1.
+(M. Mac Cormick, I. Hrivnacova, D. Guez)
+
 Revision 1.39  2003/01/14 10:50:19  alibrary
 Cleanup of STEER coding conventions
 
@@ -2086,6 +2090,20 @@ void AliMUONv1::Init()
 }
 
 //___________________________________________
+Int_t  AliMUONv1::GetChamberId(Int_t volId) const
+{
+// Check if the volume with specified  volId is a sensitive volume (gas) 
+// of some chamber and returns the chamber number;
+// if not sensitive volume - return 0.
+// ---
+
+  for (Int_t i = 1; i <= AliMUONConstants::NCh(); i++)
+    if (volId==((AliMUONChamber*)(*fChambers)[i-1])->GetGid()) return i;
+
+  return 0;
+}
+
+//___________________________________________
 void AliMUONv1::StepManager()
 {
   Int_t          copy, id;
@@ -2110,16 +2128,12 @@ void AliMUONv1::StepManager()
   //
   // Only gas gap inside chamber
   // Tag chambers and record hits when track enters 
-  idvol=-1;
   id=gMC->CurrentVolID(copy);
-  
-    for (Int_t i = 1; i <= AliMUONConstants::NCh(); i++) {
-      if(id==((AliMUONChamber*)(*fChambers)[i-1])->GetGid()){ 
-         vol[0] = i; 
-         idvol  = i-1;
-      }
-    }
-    if (idvol == -1) return;
+  vol[0] = GetChamberId(id);
+  idvol = vol[0] -1;
+
+  if (idvol == -1) return;
+
   //
   // Get current particle id (ipart), track position (pos)  and momentum (mom) 
   gMC->TrackPosition(pos);
index 82dff56..f0119ea 100644 (file)
@@ -22,6 +22,7 @@ public:
    virtual Int_t  IsVersion() const {return 1;}
    virtual void   StepManager();
 protected:
+   virtual Int_t  GetChamberId(Int_t volId) const;
    Int_t* fStations; //! allow to externally set which station to create
 private:
    ClassDef(AliMUONv1,1)  // MUON Detector class Version 1
index d2e56a5..d0ab102 100644 (file)
@@ -25,14 +25,22 @@ $Log$
 // geometrical description of station 1 
 
 #include <algorithm>
-#include <vector>
-
-#include <string.h>
+#include <string>
 
 #include <TVector2.h>
 #include <TClonesArray.h>
 #include <TLorentzVector.h>
+#include <TArrayI.h>
+#include <Riostream.h>
+#include <TSystem.h>
 
+#include "AliMpFiles.h"
+#include "AliMpReader.h"
+#include "AliMpSector.h"
+#include "AliMpRow.h"
+#include "AliMpVRowSegment.h"
+#include "AliMpMotifMap.h"
+#include "AliMpMotifPosition.h"
 
 #include "AliMUONv2.h"
 #include "AliMUONConstants.h"
@@ -40,42 +48,36 @@ $Log$
 #include "AliRun.h"
 #include "AliMagF.h"
 #include "AliConst.h" 
-
-#include <MReader.h>
-#include <MSector.h>
-#include <MRow.h>
-#include <MVRowSegment.h>
-#include <MVMotif.h>
-#include <MMotifMap.h>
-#include <MMotifPosition.h>
-#include <MMotifType.h>
-#include <MIntPair.h>
-
-
-#include <Riostream.h>
+#include "AliMUONChamber.h"
 
 ClassImp(AliMUONv2)
 
-
-
-const GReal_t AliMUONv2::fgkHzPadPlane=0.0148/2.; //Pad plane
-const GReal_t AliMUONv2::fgkHzFoam = 2.083/2.; // Foam of mechanicalplane
-const GReal_t AliMUONv2::fgkHzFR4 = 0.0031/2.; // FR4 of mechanical plane
-const GReal_t AliMUONv2::fgkHzSnPb = 0.0091/2.; //Pad/Kapton connection (66 pt)
-const GReal_t AliMUONv2::fgkHzKapton = 0.0122/2.; //Kapton
-const GReal_t AliMUONv2::fgkHzBergPlastic = 0.3062/2.; //Berg connector
+// Thickness Constants
+const GReal_t AliMUONv2::fgkHzPadPlane=0.0148/2.;     //Pad plane
+const GReal_t AliMUONv2::fgkHzFoam = 2.083/2.;        //Foam of mechanicalplane
+const GReal_t AliMUONv2::fgkHzFR4 = 0.0031/2.;        //FR4 of mechanical plane
+const GReal_t AliMUONv2::fgkHzSnPb = 0.0091/2.;       //Pad/Kapton connection (66 pt)
+const GReal_t AliMUONv2::fgkHzKapton = 0.0122/2.;     //Kapton
+const GReal_t AliMUONv2::fgkHzBergPlastic = 0.3062/2.;//Berg connector
 const GReal_t AliMUONv2::fgkHzBergCopper = 0.1882/2.; //Berg connector
-const GReal_t AliMUONv2::fgkHzDaughter = 0.0156/2.; //Daughter board
-const GReal_t AliMUONv2::fgkHzGas = 0.2/2.; //Gas
-const GReal_t AliMUONv2::fgkHxQuadrant = 94.69/2.; //Box surrounding quadrant
-const GReal_t AliMUONv2::fgkHyQuadrant = 100.31/2.; //Box surrounding quadrant
-const GReal_t AliMUONv2::fgkMotherIR = 18.3;
-const GReal_t AliMUONv2::fgkMotherOR = 104.974;   
-const GReal_t AliMUONv2::fgkMotherThick = 6.5/2; //6.5cm between two quadrants 
-const GReal_t AliMUONv2::fgkMotherPhiL = 0.; 
-const GReal_t AliMUONv2::fgkMotherPhiU = 90.;
-
-
+const GReal_t AliMUONv2::fgkHzDaughter = 0.0156/2.;   //Daughter board
+const GReal_t AliMUONv2::fgkHzGas = 0.2/2.;           //Gas thickness
+
+// Quadrant Mother volume - TUBS1 - Middle layer of model
+const GReal_t AliMUONv2::fgkMotherIR1 = 18.3;
+const GReal_t AliMUONv2::fgkMotherOR1 = 105.673;   
+const GReal_t AliMUONv2::fgkMotherThick1 = 6.5/2;  
+const GReal_t AliMUONv2::fgkMotherPhiL1 = 0.; 
+const GReal_t AliMUONv2::fgkMotherPhiU1 = 90.;
+
+// Quadrant Mother volume - TUBS2 - near and far layers of model
+const GReal_t AliMUONv2::fgkMotherIR2 = 20.7;   
+const GReal_t AliMUONv2::fgkMotherOR2 = 100.073;   
+const GReal_t AliMUONv2::fgkMotherThick2 = 3.0/2; 
+const GReal_t AliMUONv2::fgkMotherPhiL2 = 0.; 
+const GReal_t AliMUONv2::fgkMotherPhiU2 = 90.;
+
+// Sensitive copper pads, foam layer, PCB and electronics model parameters
 const GReal_t AliMUONv2::fgkHxHole=1.5/2.;
 const GReal_t AliMUONv2::fgkHyHole=6./2.;
 const GReal_t AliMUONv2::fgkHxBergPlastic=0.74/2.;
@@ -88,150 +90,399 @@ const GReal_t AliMUONv2::fgkHxDaughter=2.3/2.;
 const GReal_t AliMUONv2::fgkHyDaughter=6.3/2.;
 const GReal_t AliMUONv2::fgkOffsetX=1.46;
 const GReal_t AliMUONv2::fgkOffsetY=0.71;
-const GReal_t AliMUONv2::fgkDeltaFilleEtamX=0.;
-const GReal_t AliMUONv2::fgkDeltaFilleEtamY=0.5;
+const GReal_t AliMUONv2::fgkDeltaFilleEtamX=1.46;
+const GReal_t AliMUONv2::fgkDeltaFilleEtamY=0.051;
 
-const char* AliMUONv2::fgkHoleName="MCHL";
-const char* AliMUONv2::fgkDaughterName="MCDB";
-const char  AliMUONv2::fgkFoamLayerSuffix='F';
-const char* AliMUONv2::fgkQuadrantName="QUA";
+const GReal_t AliMUONv2::fgkDeltaQuadLHC=2.6;  // LHC Origin wrt Quadrant Origin
+const GReal_t AliMUONv2::fgkFrameOffset=5.0;  
 
-//___________________________________________
+const char* AliMUONv2::fgkHoleName="MCHL";      
+const char* AliMUONv2::fgkDaughterName="MCDB";  
+const char  AliMUONv2::fgkFoamLayerSuffix='F';  // prefix for automatic volume naming
+const char* AliMUONv2::fgkQuadrantMLayerName="SQM";
+const char* AliMUONv2::fgkQuadrantNLayerName="SQN";
+const char* AliMUONv2::fgkQuadrantFLayerName="SQF";
+
+//______________________________________________________________________________
 AliMUONv2::AliMUONv2()
-  : AliMUONv1(),
-    fIdSens(0)
+  : AliMUONv1()
 {
 // Default Constructor
-//
-
+// --
+   fChamberV2[0] = 0;
+   fChamberV2[1] = 0;
+   
    // keep secondaries
    SetIshunt(0);
+   // set path to mapping data files
+   if (! gSystem->Getenv("MINSTALL")) {    
+     TString dirPath = gSystem->Getenv("ALICE_ROOT");
+     dirPath += "/MUON/mapping"; 
+     AliMpFiles::Instance()->SetTopPath(dirPath);
+     gSystem->Setenv("MINSTALL", dirPath.Data());
+     //cout << "AliMpFiles top path set to " << dirPath << endl;         
+   }
+   //else
+   //  cout << gSystem->Getenv("MINSTALL") << endl;      
 }
  
-//___________________________________________
+//______________________________________________________________________________
 AliMUONv2::AliMUONv2(const char *name, const char *title)
-  : AliMUONv1(name,title),
-    fIdSens(0)
+  : AliMUONv1(name,title)
 {
+   fChamberV2[0] = 0;
+   fChamberV2[1] = 0;
+   
    // keep secondaries
    SetIshunt(0);
-
-   // create hits array
-   fHits     = new TClonesArray("AliMUONHit",1000);
-   gAlice->AddHitList(fHits);
+   
+   // set path to mapping data files
+   if (! gSystem->Getenv("MINSTALL")) {    
+     TString dirPath = gSystem->Getenv("ALICE_ROOT");
+     dirPath += "/MUON/mapping"; 
+     AliMpFiles::Instance()->SetTopPath(dirPath);
+     gSystem->Setenv("MINSTALL", dirPath.Data());
+     //cout << "AliMpFiles top path set to " << dirPath << endl;         
+   }
+   //else
+   //  cout << gSystem->Getenv("MINSTALL") << endl;              
 }
  
-//___________________________________________
+//______________________________________________________________________________
 AliMUONv2::AliMUONv2(const AliMUONv2& rMUON)
 {
 // Dummy copy constructor
 }
 
-//___________________________________________
+//______________________________________________________________________________
 AliMUONv2::~AliMUONv2()
 {
 // Destructor
-    if(fDebug) printf("%s: Calling AliMUONv2 destructor !!!\n",ClassName());
-    
-    if (fHits) {
-      fHits->Delete();
-      delete fHits;
-    }
 }
 
-//___________________________________________
-void AliMUONv2::CreateGeometry()
+//
+//  Private methods
+//
+
+//______________________________________________________________________________
+void AliMUONv2::CreateHole()
 {
-// Create the GEANT geometry for the dimuon arm.
-// Use the parent's method for stations 2, 3, 4 and 5.
-// Use the detailed code for the first station.
+// Create all the elements found inside a foam hole
 // --
-  cout << "AliMUONv2::CreateGeometry()" << endl;
-  cout << "_________________________________________" << endl;
-
-  // tracking medias
   Int_t* idtmed = fIdtmed->GetArray()-1099;
-  Int_t idAir  = idtmed[1100];       // medium 1
+  Int_t idAir  = idtmed[1100];    // medium 1
+  Int_t idCopper  = idtmed[1109]; // medium 10 = copper
 
+  GReal_t par[3];
+  GReal_t posX,posY,posZ;
+  
+  par[0] = fgkHxHole;
+  par[1] = fgkHyHole;
+  par[2] = fgkHzFoam;
+  gMC->Gsvolu(fgkHoleName,"BOX",idAir,par,3);
+
+  par[0] = fgkHxKapton;
+  par[1] = fgkHyKapton;
+  par[2] = fgkHzSnPb;
+  gMC->Gsvolu("SNPB", "BOX", idCopper, par, 3);
+  posX = 0.;
+  posY = 0.;
+  posZ = -fgkHzFoam+fgkHzSnPb;
+  gMC->Gspos("SNPB",1,fgkHoleName, posX, posY, posZ, 0,"ONLY");
 
+  par[0] = fgkHxHole;
+  par[1] = fgkHyBergPlastic;
+  par[2] = fgkHzKapton;
+  gMC->Gsvolu("KAPT", "BOX", idCopper, par, 3);
+  posX = 0.;
+  posY = 0.;
+  posZ = 0.;
+  gMC->Gspos("KAPT",1,fgkHoleName, posX, posY, posZ, 0,"ONLY");
+}
 
-  //create reflexion matrix
-  Int_t reflXZ,reflYZ,reflXY;
-  AliMatrix(reflXZ,  90.,  180., 90., 90., 180., 0.);
-  AliMatrix(reflYZ,  90., 0., 90.,-90., 180., 0.);
-  AliMatrix(reflXY,  90., 180., 90., 270., 0., 0.);
+//______________________________________________________________________________
+void AliMUONv2::CreateDaughterBoard()
+{
+// Create all the elements in a daughter board
+// --
+  Int_t* idtmed = fIdtmed->GetArray()-1099;
+  Int_t idAir  = idtmed[1100]; // medium 1
+  Int_t idCopper  = idtmed[1109]; // medium 10 = copper
+  Int_t idPlastic  =idtmed[1116]; // medium 17 = Plastic
 
-  CreateHole();
-  CreateDaughterBoard();
+  GReal_t par[3];
+  GReal_t posX,posY,posZ;
 
-  //build the quadrant
-  CreateQuadrant(1);
-  CreateQuadrant(2);
-  GReal_t par[5];
-  par[0] = fgkMotherIR;
-  par[1] = fgkMotherOR; 
-  par[2] = fgkHzGas;  
-  par[3] = fgkMotherPhiL; 
-  par[4] = fgkMotherPhiU;
-
-  gMC->Gsvolu("S01G","TUBS",idAir,par,5);
-  gMC->Gspos("S01G",1,QuadrantName(1),0,0,0,0,"ONLY");
-  gMC->Gsvolu("S02G","TUBS",idAir,par,5);
-  gMC->Gspos("S02G",1,QuadrantName(2),0,0,0,0,"ONLY");
-
-  // place the four copies of it
-  
-  //parameters
-  TVector3 pos[4];
-  Int_t rotm[4];
+  par[0]=fgkHxDaughter;
+  par[1]=fgkHyDaughter;
+  par[2]=TotalHzDaughter();
+  gMC->Gsvolu(fgkDaughterName,"BOX",idAir,par,3);
   
-  Double_t deltaZ = 6.5/2.; 
-  pos[0]=TVector3(-2.6,-2.6,AliMUONConstants::DefaultChamberZ(0)+deltaZ);
-  rotm[0]=0;
-  pos[1]=TVector3(2.6,-2.6,AliMUONConstants::DefaultChamberZ(0)-deltaZ);
-  rotm[1]=reflXZ;
-  pos[2]=TVector3(2.6,2.6,AliMUONConstants::DefaultChamberZ(0)+deltaZ);
-  rotm[2]=reflXY;
-  pos[3]=TVector3(-2.6,2.6,AliMUONConstants::DefaultChamberZ(0)-deltaZ);
-  rotm[3]=reflYZ;
+  par[0]=fgkHxBergPlastic;
+  par[1]=fgkHyBergPlastic;
+  par[2]=fgkHzBergPlastic;
+  gMC->Gsvolu("BRGP","BOX",idPlastic,par,3);
+  posX=0.;
+  posY=0.;
+  posZ = -TotalHzDaughter() + fgkHzBergPlastic;
+  gMC->Gspos("BRGP",1,fgkDaughterName,posX,posY,posZ,0,"ONLY");
+
+  par[0]=fgkHxBergCopper;
+  par[1]=fgkHyBergCopper;
+  par[2]=fgkHzBergCopper;
+  gMC->Gsvolu("BRGC","BOX",idCopper,par,3);
+  posX=0.;
+  posY=0.;
+  posZ=0.;
+  gMC->Gspos("BRGC",1,"BRGP",posX,posY,posZ,0,"ONLY");
+
+  par[0]=fgkHxDaughter;
+  par[1]=fgkHyDaughter;
+  par[2]=fgkHzDaughter;
+  gMC->Gsvolu("DGHT","BOX",idCopper,par,3);
+  posX=0.;
+  posY=0.;
+  posZ = -TotalHzDaughter() + 2.*fgkHzBergPlastic + fgkHzDaughter;
+  gMC->Gspos("DGHT",1,fgkDaughterName,posX,posY,posZ,0,"ONLY");
+}
+
+//______________________________________________________________________________
+void AliMUONv2::CreateInnerLayers()
+{
+// Create the layer of sensitive volumes with gas
+// and the copper layer.
+// --
+
+// Gas Medium
+  Int_t* idtmed = fIdtmed->GetArray()-1099; 
+  Int_t idArCO2  = idtmed[1108];  // medium 9 (ArCO2 80%) 
+  Int_t idCopper  = idtmed[1109]; // medium 10 = copper
+
+  Float_t par[11];
+
+//Make gas volume - composed of 11 trapezoids
+// section 1 of 11
+    par[0] = fgkHzGas;
+    par[1] = 0.;
+    par[2] = 0.;
+    par[3] = 71.33/2.;
+    par[4] = 9.76/2.;
+    par[5] = 48.77/2.;
+    par[6] = 15.3;
+    par[7] = 71.33/2.;
+    par[8] = 9.76/2.;
+    par[9] = 48.77/2.;
+    par[10] = 15.3;        
+
+  gMC->Gsvolu("SA1G", "TRAP", idArCO2, par, 11);
+  gMC->Gsvolu("SA2G", "TRAP", idArCO2, par, 11);
   
-  //placing
-  GReal_t posX,posY,posZ;
-  for (Int_t i=0;i<4;i++){
-    posX=pos[i].X();
-    posY=pos[i].Y();
-    // the 1st chamber
-    posZ=pos[i].Z();
-    gMC->Gspos(QuadrantName(1),i+1,"ALIC",posX,posY,posZ,rotm[i],"ONLY");
-    // the 2nd chamber
-    posZ=pos[i].Z()+AliMUONConstants::DefaultChamberZ(1)
-         -AliMUONConstants::DefaultChamberZ(0);
-    gMC->Gspos(QuadrantName(2),i+5,"ALIC",posX,posY,posZ,rotm[i],"ONLY");
-  }
-  static Int_t stations[5]={0,1,1,1,1};
-  fStations=stations;
-  AliMUONv1::CreateGeometry();
+  par[0] = fgkHzPadPlane;
+  gMC->Gsvolu("SA1C", "TRAP", idCopper,par, 11);
+
+// section 2 of 11  
+    par[0] = fgkHzGas;
+    par[1] = 0.;
+    par[2] = 0.;
+    par[3] = 79.68/2.;
+    par[4] = 10.4/2.;
+    par[5] = 57.0/2.;
+    par[6] = 0.;  
+    par[7] = 79.68/2.; 
+    par[8] = 10.4/2.;
+    par[9] = 57.0/2.;
+    par[10] = 0.;  
+  gMC->Gsvolu("SB1G", "TRAP", idArCO2, par, 11);  
+  gMC->Gsvolu("SB2G", "TRAP", idArCO2, par, 11);
+
+  par[0] = fgkHzPadPlane;
+  gMC->Gsvolu("SB1C", "TRAP", idCopper,par, 11);
+
+// section 3 of 11
+    par[0] = fgkHzGas;
+    par[1] = 0.;
+    par[2] = 0.;
+    par[3] = 71.33/2.;
+    par[4] = 48.77/2.;
+    par[5] = 9.73/2.;
+    par[6] = -15.3;
+    par[7] = 71.33/2.;
+    par[8] = 48.77/2.;
+    par[9] = 9.73/2.;
+    par[10] = -15.3;   
+  gMC->Gsvolu("SC1G", "TRAP", idArCO2, par, 11);  
+  gMC->Gsvolu("SC2G", "TRAP", idArCO2, par, 11);
+
+  par[0] = fgkHzPadPlane;
+  gMC->Gsvolu("SC1C", "TRAP", idCopper,par, 11);
+
+// section 4 of 11
+    par[0] = fgkHzGas;
+    par[1] = 0.;
+    par[2] = 0.;
+    par[3] = 6.00/2.;
+    par[4] = 0.;
+    par[5] = 1.56/2.;
+    par[6] = 7.41; 
+    par[7] = 6.00/2.; 
+    par[8] = 0.;
+    par[9] = 1.56/2.;
+    par[10] = 7.41;    
+  gMC->Gsvolu("SD1G", "TRAP", idArCO2, par, 11);  
+  gMC->Gsvolu("SD2G", "TRAP", idArCO2, par, 11);
+
+  par[0] = fgkHzPadPlane;
+  gMC->Gsvolu("SD1C", "TRAP", idCopper,par, 11);
+
+// section 5 of 11  
+    par[0] = fgkHzGas;
+    par[1] = 0.;
+    par[2] = 0.;
+    par[3] = 1.516/2.;
+    par[4] = 0.;
+    par[5] = 0.829/2.;
+    par[6] = 15.3;
+    par[7] = 1.516/2.;
+    par[8] = 0.;
+    par[9] = 0.829/2.;
+    par[10] = 15.3;   
+  gMC->Gsvolu("SE1G", "TRAP", idArCO2, par, 11);  
+  gMC->Gsvolu("SE2G", "TRAP", idArCO2, par, 11);
+
+  par[0] = fgkHzPadPlane;
+  gMC->Gsvolu("SE1C", "TRAP", idCopper,par, 11);
+
+// section 6 of 11
+    par[0] = fgkHzGas;
+    par[1] = 0.;
+    par[2] = 0.;
+    par[3] = 3.92/2.;
+    par[4] = 0.;
+    par[5] = 0.562/2.;
+    par[6] = -4.1;
+    par[7] = 3.92/2.;
+    par[8] = 0.;
+    par[9] = 0.562/2.;
+    par[10] = -4.1;   
+  gMC->Gsvolu("SF1G", "TRAP", idArCO2, par, 11);  
+  gMC->Gsvolu("SF2G", "TRAP", idArCO2, par, 11);
+    
+  par[0] = fgkHzPadPlane;
+  gMC->Gsvolu("SF1C", "TRAP", idCopper,par, 11);
+
+// section 7 of 11
+    par[0] = fgkHzGas;
+    par[1] = 0.;
+    par[2] = 0.;
+    par[3] = 0.941/2.;
+    par[4] = 0.562/2.;
+    par[5] = 0.;
+    par[6] = -16.6; 
+    par[7] = 0.941/2.;
+    par[8] = 0.562/2.;
+    par[9] = 0.;
+    par[10] =-16.6;    
+  gMC->Gsvolu("SG1G", "TRAP", idArCO2, par, 11);  
+  gMC->Gsvolu("SG2G", "TRAP", idArCO2, par, 11);
+
+  par[0] = fgkHzPadPlane;
+  gMC->Gsvolu("SG1C", "TRAP", idCopper,par, 11);
+
+// section 8 of 11
+    par[0] = fgkHzGas;
+    par[1] = 0.;
+    par[2] = 0.;
+    par[3] = 3.94/2.;
+    par[4] = 0.57/2.;
+    par[5] = 0.;
+    par[6] = 4.14; 
+    par[7] = 3.94/2.; 
+    par[8] = 0.57/2.;
+    par[9] = 0.;
+    par[10] = 4.14;    
+  gMC->Gsvolu("SH1G", "TRAP", idArCO2, par, 11);  
+  gMC->Gsvolu("SH2G", "TRAP", idArCO2, par, 11);
+
+  par[0] = fgkHzPadPlane;
+  gMC->Gsvolu("SH1C", "TRAP", idCopper,par, 11);
+
+// section 9 of 11  
+    par[0] = fgkHzGas;
+    par[1] = 0.;
+    par[2] = 0.;
+    par[3] = 0.95/2.;
+    par[4] = 0.;
+    par[5] = 0.57/2;
+    par[6] = 16.7;
+    par[7] = 0.95/2.;
+    par[8] = 0.;
+    par[9] = 0.57/2;
+    par[10] = 16.7;   
+  gMC->Gsvolu("SI1G", "TRAP", idArCO2, par, 11);  
+  gMC->Gsvolu("SI2G", "TRAP", idArCO2, par, 11);
+
+  par[0] = fgkHzPadPlane;
+  gMC->Gsvolu("SI1C", "TRAP", idCopper,par, 11);
+
+// section 10 of 11
+    par[0] = fgkHzGas;
+    par[1] = 0.;
+    par[2] = 0.;
+    par[3] = 1.49/2.;
+    par[4] = 0.;
+    par[5] = 0.817/2.;
+    par[6] = -15.4;
+    par[7] = 1.49/2.;
+    par[8] = 0.;
+    par[9] = 0.817/2.;
+    par[10] = -15.4;   
+  gMC->Gsvolu("SJ1G", "TRAP", idArCO2, par, 11);  
+  gMC->Gsvolu("SJ2G", "TRAP", idArCO2, par, 11);
+    
+  par[0] = fgkHzPadPlane;
+  gMC->Gsvolu("SJ1C", "TRAP", idCopper,par, 11);
+
+// section 11 of 11
+    par[0] = fgkHzGas;
+    par[1] = 0.;
+    par[2] = 0.;
+    par[3] = 5.93/2.;
+    par[4] = 0.;
+    par[5] = 1.49/2.;
+    par[6] = -7.16; 
+    par[7] = 5.93/2.;
+    par[8] = 0.;
+    par[9] = 1.49/2.;
+    par[10] = -7.16;    
+  gMC->Gsvolu("SK1G", "TRAP", idArCO2, par, 11);  
+  gMC->Gsvolu("SK2G", "TRAP", idArCO2, par, 11);
+
+  par[0] = fgkHzPadPlane;
+  gMC->Gsvolu("SK1C", "TRAP", idCopper,par, 11);
 }
-//___________________________________________
+
+//______________________________________________________________________________
 void AliMUONv2::CreateQuadrant(Int_t chamber)
 {
 // create the quadrant (bending and non-bending planes)
 // for the given chamber
 // --
+
   CreateFrame(chamber);
 
-  TSpecialMap specialMap;  
+  TSpecialMap specialMap;
+  specialMap[1001] = AliMUONSt1SpecialMotif(TVector2( 0.1, 0.84), 90.);
+  specialMap[1002] = AliMUONSt1SpecialMotif(TVector2( 0.5, 0.36));
+  specialMap[1003] = AliMUONSt1SpecialMotif(TVector2(1.01, 0.36));
+  AliMpReader reader1(kBendingPlane);
+  AliMpSector* sector1 = reader1.BuildSector();
 
-  TVector3 where;
-  specialMap[1001] = AliMUONSt1SpecialMotif(TVector2(0.1 ,0.84),90.);
-  specialMap[1002] = AliMUONSt1SpecialMotif(TVector2(0.5 ,0.76));
-  specialMap[1003] = AliMUONSt1SpecialMotif(TVector2(1.01,0.76));
-  MReader reader1(kBendingPlane);
-  MSector* sector1 = reader1.BuildSector();
-  where=TVector3(0.185+2.6,-0.52+2.6,totalHz()+fgkHzGas);
-  PlaceSector(sector1,specialMap,where,chamber);
+  Bool_t reflectZ = true;
+  TVector3 where = TVector3(2.5+0.1+0.56+0.001, 2.5+0.1+0.001, 0.);
+  PlaceSector(sector1, specialMap, where, reflectZ, chamber);
   
-
   specialMap.clear();
   specialMap[4001] = AliMUONSt1SpecialMotif(TVector2(1.01,0.59),90.);
   specialMap[4002] = AliMUONSt1SpecialMotif(TVector2(1.96, 0.17));
@@ -239,787 +490,1302 @@ void AliMUONv2::CreateQuadrant(Int_t chamber)
   specialMap[4004] = AliMUONSt1SpecialMotif(TVector2(0.2 ,-0.08));
   specialMap[4005] = AliMUONSt1SpecialMotif(TVector2(0.2 , 0.25));
   specialMap[4006] = AliMUONSt1SpecialMotif(TVector2(0.28, 0.21));
+  AliMpReader reader2(kNonBendingPlane);
+  AliMpSector* sector2 = reader2.BuildSector();
 
-  MReader reader2(kNonBendingPlane);
-  MSector* sector2 = reader2.BuildSector();
-  where=TVector3(-0.13+2.6,-0.1775+2.6,-totalHz()-fgkHzGas);
-  PlaceSector(sector2,specialMap,where,chamber);
+  reflectZ = false;
+  where = TVector3(where.X()+0.63/2.,where.Y()+0.42/2., 0.); //add a half pad shift
+  PlaceSector(sector2, specialMap, where, reflectZ, chamber);
 }
 
-//___________________________________________
-void AliMUONv2::CreateMaterials()
+//______________________________________________________________________________
+void AliMUONv2::CreateFoamBox(const char* name,const  TVector2& dimensions)
 {
-// --- Define the various mixtures for GEANT ---
-  
-  //     Ar-CO2 gas (80%+20%)
-  Float_t ag1[2]   = { 39.95,44.01};
-  Float_t zg1[2]   = { 18.,22.};
-  Float_t dg1      = .001821;
-  Float_t wg1[2]   = { .8,0.2};
-  // use wg1 weighting factors (6th arg > 0)
-  AliMixture(22, "ArCO2 80%$", ag1, zg1, dg1, 2, wg1);  
+// create all the elements in the copper plane
+// --
 
-  //    Ar-buthane-freon gas -- trigger chambers 
-  Float_t atr1[4]  = { 39.95,12.01,1.01,19. };
-  Float_t ztr1[4]  = { 18.,6.,1.,9. };
-  Float_t wtr1[4]  = { .56,.1262857,.2857143,.028 };
-  Float_t dtr1     = .002599;
-  AliMixture(23, "Ar-freon $", atr1, ztr1, dtr1, 4, wtr1);
+  Int_t* idtmed = fIdtmed->GetArray()-1099;
+  Int_t idAir  = idtmed[1100]; // medium 1
+  Int_t idFoam = idtmed[1115]; // medium 16 = Foam
+  Int_t idFR4  = idtmed[1114]; // medium 15 = FR4
 
-  // Rohacell 51  - imide methacrylique
-  Float_t aRohacell51[4] = {12.01,1.01,16.00,14.01}; 
-  Float_t zRohacell51[4] = {6.,1.,8.,7.}; 
-  Float_t dRohacell51 = 0.052;
-  Float_t wRohacell51[4] = {9.,13.,2.,1.};  
-  // use relative A (molecular) values (6th arg < 0)
-  AliMixture(32, "FOAM$",aRohacell51,zRohacell51,dRohacell51,-4,wRohacell51);  
-   
-  Float_t aSnPb[2] = {118.69,207.19};
-  Float_t zSnPb[2] = {50,82};
-  Float_t dSnPb = 8.926;
-  Float_t wSnPb[2] = {0.6, 0.4} ;
-  // use wSnPb weighting factors (6th arg > 0)
-  AliMixture(35, "SnPb$", aSnPb,zSnPb,dSnPb,2,wSnPb);
+  // mother volume
+  GReal_t par[3];
+  par[0] = dimensions.X();
+  par[1] = dimensions.Y();
+  par[2] = TotalHzPlane();
+  gMC->Gsvolu(name,"BOX",idAir,par,3);
+  
+  // foam layer
+  GReal_t posX,posY,posZ;
+  char eName[5];
+  strcpy(eName,name);
+  eName[3]=fgkFoamLayerSuffix;
+  par[0] = dimensions.X();
+  par[1] = dimensions.Y();
+  par[2] = fgkHzFoam;
+  gMC->Gsvolu(eName,"BOX",idFoam,par,3);
+  posX=0.;
+  posY=0.;
+  posZ = -TotalHzPlane() + fgkHzFoam;
+  gMC->Gspos(eName,1,name,posX,posY,posZ,0,"ONLY");
 
-  // plastic definition from K5, Freiburg (found on web)
-  Float_t aPlastic[2]={1.01,12.01};
-  Float_t zPlastic[2]={1,6};
-  Float_t denPlastic=1.107;
-  Float_t wPlastic[2]={1,1};
-  // use relative A (molecular) values (6th arg < 0)...no other info...
-  AliMixture( 33, "Plastic$",aPlastic,zPlastic,denPlastic,-2,wPlastic);
-  // from CERN note NUFACT Note023, Oct.2000 
-  // Inox/Stainless Steel (18%Cr, 9%Ni)
-  Float_t aInox[3] = {55.847,51.9961,58.6934};  
-  Float_t zInox[3] = {26.,24.,28.};
-  Float_t denInox = 7.930;
-  Float_t wInox[3] = {0.73,0.18,0.09}; 
-  // use wInox weighting factors (6th arg > 0) 
-  AliMixture(37, "StainlessSteel$",aInox,zInox,denInox,3,wInox);   
+  // mechanical plane FR4 layer
+  eName[3]='R';
+  par[0] = dimensions.X();
+  par[1] = dimensions.Y();
+  par[2] = fgkHzFR4;
+  gMC->Gsvolu(eName,"BOX",idFR4,par,3);
+  posX=0.;
+  posY=0.;
+  posZ = -TotalHzPlane()+ 2.*fgkHzFoam + fgkHzFR4;
+  gMC->Gspos(eName,1,name,posX,posY,posZ,0,"ONLY");
+}
 
-  // bakelite 
-  Float_t abak[3] = {12.01 , 1.01 , 16.};
-  Float_t zbak[3] = {6.     , 1.   , 8.};
-  Float_t wbak[3] = {6.     , 6.   , 1.}; 
-  Float_t dbak = 1.4;
-  AliMixture(19, "Bakelite$", abak, zbak, dbak, -3, wbak);
+//______________________________________________________________________________
+void AliMUONv2::CreatePlaneSegment(const char* name,const  TVector2& dimensions,
+                                  Int_t nofHoles)
+{
+// Create a segment of a plane (this includes a foam layer, 
+// holes in the foam to feed the kaptons through, kapton connectors
+// and the mother board.)
+// --
   
-  // Ar-Isobutane gas (80%+20%) 
-  Float_t ag[3]    = { 39.95,12.01,1.01 };
-  Float_t zg[3]    = { 18.,6.,1. };
-  Float_t wg[3]    = { .8,.057,.143 };
-  Float_t dg       = .0019596;
-  AliMixture(20, "ArC4H10 GAS$", ag, zg, dg, 3, wg);
+  CreateFoamBox(name,dimensions);
 
-  //     Ar-Isobutane-Forane-SF6 gas (49%+7%+40%+4%) -- trigger 
-  Float_t atrig[5] = { 39.95,12.01,1.01,19.,32.066 };
-  Float_t ztrig[5] = { 18.,6.,1.,9.,16. };
-  Float_t wtrig[5] = { .49,1.08,1.5,1.84,0.04 };
-  Float_t dtrig    = .0031463;
-  AliMixture(21, "TRIG GAS$", atrig, ztrig, dtrig, -5, wtrig);
+  char eName[5];
+  strcpy(eName,name);
+  eName[3]=fgkFoamLayerSuffix;
   
-  //     Ar-CO2 gas 
-  Float_t agas[3]  = { 39.95,12.01,16. };
-  Float_t zgas[3]  = { 18.,6.,8. };
-  Float_t wgas[3]  = { .74,.086684,.173316 };
-  Float_t dgas     = .0018327;
-  AliMixture(24, "ArCO2 GAS$", agas, zgas, dgas, 3, wgas); 
-   
-// --- Define the various AliMaterials for GEANT ---
-  // from PDG and "The Particle Detector BriefBook", Bock and Vasilescu, P.18  
-  AliMaterial( 9, "Aluminium$", 26.98, 13., 2.7, -8.9, 26.1);
-  AliMaterial(10, "Aluminium$", 26.98, 13., 2.7, -8.9, 26.1);
-  AliMaterial(15, "air$", 14.61, 7.3, .001205, -30423.24, 67500);
-  AliMaterial(30, "Copper$", 63.546,29.,8.96,-1.43,9.6);
-  AliMaterial(31, "FR4$", 17.749, 8.875, 1.7, -19.4, 999.);    // from DPG
-  AliMaterial(34, "Kapton$", 12.01,6,1.42,-28.6,999);          // from DPG
- // Density of FrameEpoxy only from manufacturer's specifications
- // Frame composite epoxy , X0 in g/cm**2 (guestimation!)
-  AliMaterial(36, "FrameEpoxy",12.24,6.0,1.85,-19.14,999);
+  for (Int_t holeNum=0;holeNum<nofHoles;holeNum++) {
+    GReal_t posX = ((2.*holeNum+1.)/nofHoles-1.)*dimensions.X();
+    GReal_t posY = 0.;
+    GReal_t posZ = 0.;
   
-// --- Define the tracking medias (AliMediums) for GEANT ---
-  GReal_t epsil  = .001; // Tracking precision,
-  GReal_t stemax = -1.;  // Maximum displacement for multiple scat
-  GReal_t tmaxfd = -20.; // Maximum angle due to field deflection
-  GReal_t deemax = -.3;  // Maximum fractional energy loss, DLS
-  GReal_t stmin  = -.8;
-  GReal_t maxStepAlu = 0.001;  // from AliMUON.cxx
-  GReal_t maxDestepAlu = -1.; // from AliMUON.cxx
-  GReal_t maxStepGas=0.01;  // from AliMUON.cxx
-
-  Int_t iSXFLD   = gAlice->Field()->Integ();
-  Float_t sXMGMX = gAlice->Field()->Max();
-
-  AliMedium(1, "AIR_CH_US$", 15, 1, iSXFLD, sXMGMX, tmaxfd,
-           stemax, deemax, epsil, stmin);
-  AliMedium(4, "ALU_CH_US$", 9, 0, iSXFLD, sXMGMX, tmaxfd,
-           maxStepAlu, maxDestepAlu, epsil, stmin);
-  AliMedium(5, "ALU_CH_US$", 10, 0, iSXFLD, sXMGMX, tmaxfd,
-           maxStepAlu,maxDestepAlu, epsil, stmin);  
-  AliMedium(6, "AR_CH_US          ", 20, 1, iSXFLD, sXMGMX, 
-              tmaxfd, fMaxStepGas,fMaxDestepGas, epsil, stmin);
-              
-  //    Ar-Isobuthane-Forane-SF6 gas 
-  AliMedium(7, "GAS_CH_TRIGGER    ", 21, 1, iSXFLD, sXMGMX, 
-               tmaxfd, stemax, deemax, epsil, stmin);
-  AliMedium(8, "BAKE_CH_TRIGGER   ", 19, 0, iSXFLD, sXMGMX, 
-               tmaxfd, fMaxStepAlu, fMaxDestepAlu, epsil, stmin);
-
-  AliMedium(9, "ARG_CO2$", 22, 1, iSXFLD, sXMGMX, tmaxfd, maxStepGas,
-             maxDestepAlu, epsil, stmin);
-  AliMedium(10, "COPPER_CH$", 30, 0, iSXFLD, sXMGMX, tmaxfd,
-             maxStepAlu, maxDestepAlu, epsil, stmin);
-  AliMedium(11, "PCB_COPPER        ", 31, 0, iSXFLD, sXMGMX, tmaxfd, 
-                fMaxStepAlu, fMaxDestepAlu, epsil, stmin);
-  AliMedium(12, "VETRONITE         ", 32, 0, iSXFLD, sXMGMX, tmaxfd, 
-                fMaxStepAlu, fMaxDestepAlu, epsil, stmin);
-  AliMedium(13, "CARBON            ", 33, 0, iSXFLD, sXMGMX, tmaxfd, 
-                fMaxStepAlu, fMaxDestepAlu, epsil, stmin);
-  AliMedium(14, "Rohacell          ", 34, 0, iSXFLD, sXMGMX, tmaxfd, 
-             fMaxStepAlu, fMaxDestepAlu, epsil, stmin);
-  AliMedium(15, "FR4_CH$",  31, 0,iSXFLD, sXMGMX, 10., .01,.1, .003, .003);
-  AliMedium(16, "FOAM_CH$", 32, 0,
-             iSXFLD, sXMGMX, 10.0, 0.1, 0.1, 0.1, 0.1, 0, 0) ;
-  AliMedium(17, "Plastic$", 33, 0,iSXFLD, sXMGMX,  10., .01, 1., .003, .003);
-  AliMedium(18, "Kapton$", 34, 0,iSXFLD, sXMGMX,  10., .01, 1., .003, .003);
-  AliMedium(19, "SnPb$", 35, 0,iSXFLD, sXMGMX,  10., .01,  1., .003, .003);
-  AliMedium(20, "FrameCH$", 36, 1,iSXFLD, sXMGMX,  10., .001, 0.001, .001, .001);
-  AliMedium(21, "InoxBolts$", 37,1,iSXFLD, sXMGMX,  10., .01, 1., .003, .003);
+    gMC->Gspos(fgkHoleName,holeNum+1,eName,posX,posY,posZ,0,"ONLY");
+  }
 }
 
+//______________________________________________________________________________
 void AliMUONv2::CreateFrame(Int_t chamber)
 {
 // Create the non-sensitive elements of the frame for the  <chamber>
+//
+// 
+// Model and notation:
+//
+// The Quadrant volume name starts with SQ
+// The volume segments are numbered 00 to XX.
+//
+//                              OutTopFrame
+//                               (SQ02-16) 
+//                              ------------  
+//             OutEdgeFrame   /              |
+//             (SQ17-24)     /               |  InVFrame (SQ00-01) 
+//                          /                |
+//                          |                |   
+//               OutVFrame  |            _- - 
+//               (SQ25-39)  |           |   InArcFrame (SQ42-45)
+//                          |           |
+//                          -------------
+//                        InHFrame (SQ40-41)
+//                          
+//
+// 06 February 2003 - Overlapping volumes resolved.
+// One quarter chamber is comprised of three TUBS volumes: SQMx, SQNx, and SQFx,
+// where SQMx is the Quadrant Middle layer for chamber <x> ( posZ in [-3.25,3.25]),
+// SQNx is the Quadrant Near side layer for chamber <x> ( posZ in [-6.25,3-.25) ), and
+// SQFx is the Quadrant Far side layer for chamber <x> ( posZ in (3.25,6.25] ).
+//---
 
+const Float_t fgkNearFarLHC=2.4;    // Near and Far TUBS Origin wrt LHC Origin
 
-// Matrices
-      Int_t idrotm[1199];   
-// To Be Checked....
-//   Rotation matrices in the x-y plane  
-//   phi =   -45 deg
-     AliMatrix(idrotm[1101],  90.,   315., 90.,  45., 0., 0.);
-//   phi =  -90 deg
-     AliMatrix(idrotm[1102],  90.,  90., 90., 180., 0., 0.);
-//   theta =  +90 deg
-     AliMatrix(idrotm[1103],  180.,  0., 90., 90.,90., 0.);
-      
-//   phi =   +45 deg
-     AliMatrix(idrotm[1104],  90.,   45., 90.,  135., 0., 0.);
-//   phi =  +45 deg + rotation 180° around Y 
-     AliMatrix(idrotm[1105],  90.,  45., 90., 315., 180., 0.);
-
-//   Translation matrices in the x-y plane  
-//   X -> X ; Y -> Y; Z -> Z
-     AliMatrix(idrotm[1110],  90.,   0., 90.,  90., 0., 0.);
-//   X->-X; Y -> Y; Z -> -Z
-     AliMatrix(idrotm[1111],  90.,  180., 90., 90., 180., 0.);
-//   X->-X; Y ->-Y; Z -> Z
-     AliMatrix(idrotm[1112],  90., 180., 90., 270., 0., 0.);
-//   X->X; Y ->-Y; Z -> -Z
-     AliMatrix(idrotm[1113],  90., 0., 90., 270., 180., 0.);
-//   
   // tracking medias
   Int_t* idtmed = fIdtmed->GetArray()-1099;
-
+  
   Int_t idAir  = idtmed[1100];       // medium 1
-  Int_t idSolder = idtmed[1118];     // medium 19
-  Int_t idFrameEpoxy = idtmed[1119]; // medium 20 = Frame Epoxy ME730
-  Int_t idInox = idtmed[1120];       // medium 21 Stainless Steel (18%Cr,9%Ni,Fe)
-
-//________________________________________________________________
-// 
-// Original model:
-//
-// Epoxy Frame segments
+  Int_t idFrameEpoxy = idtmed[1115]; // medium 16 = Frame Epoxy ME730
+  Int_t idInox = idtmed[1116];       // medium 17 Stainless Steel (18%Cr,9%Ni,Fe)
+  Int_t idFR4 = idtmed[1110];        // medium 11 FR4
+  Int_t idCopper = idtmed[1109];     // medium 10 Copper
+  Int_t idAlu = idtmed[1103];        // medium 4 Aluminium
+  
+  
+// Rotation Matrices  
+      Int_t rot1, rot2, rot3;    
+      
+//   Rotation matrices  
+     AliMatrix(rot1,  90.,  90., 90., 180.,  0., 0.); // +90 deg in x-y plane
+     AliMatrix(rot2,  90.,  45., 90., 135.,  0., 0.); // +45 deg in x-y plane 
+     AliMatrix(rot3,  90.,  45., 90., 315.,180., 0.); // +45 deg in x-y + rotation 180° around y
+
+//   Translation matrices ... NOT USED  
+//     AliMatrix(trans1, 90.,   0., 90.,  90.,   0., 0.); // X-> X; Y -> Y; Z -> Z
+//     AliMatrix(trans2, 90., 180., 90.,  90., 180., 0.); // X->-X; Y -> Y; Z ->-Z
+//     AliMatrix(trans3, 90., 180., 90., 270.,   0., 0.); // X->-X; Y ->-Y; Z -> Z
+//     AliMatrix(trans4, 90.,   0., 90., 270., 180., 0.); // X-> X; Y ->-Y; Z ->-Z
 //  
-//                         OutTopTrapFrame
-//                              ------------ |
-//      OutEdgeTrapFrame      /              |
-//                           /               |  InVFrame
-//       OutCornerTrapFrame /                |
-//                          |              --|   
-//             OutVFrame    |            _-  InArcFrame
-//                          |___________|
-//                             InHFrame
-//                          
-//
-// DATE: 27 NOVEMBER 2002 - MODEL UPDATED. THE MOTHER VOLUME IS A TUBS.
-//__________________________________________________________________
+      // ___________________Volume thicknesses________________________
 
-  const Float_t hzFrameThickness = 1.186/2.;   //equivalent thickness
-  const Float_t hzOuterFrameEpoxy = 1.23/2.;   //equivalent thickness
-  const Float_t hzOuterFrameSolder = 0.032/2.; //equivalent thickness
-  const Float_t hzOuterFrameInox = 0.035/2.;   //equivalent thickness
-      
-  // InHFrame parameters
-  const Float_t hxInHFrame  = 75.8/2.;
-  const Float_t hyInHFrame  = 2.5/2.;
-  const Float_t hzInHFrame  = hzFrameThickness;
-  // InVFrame parameters
-  const Float_t hxInVFrame  = 2.5/2.;
-  const Float_t hyInVFrame  = 73.3/2.;
+  const Float_t hzFrameThickness = 1.59/2.;     //equivalent thickness
+  const Float_t hzOuterFrameEpoxy = 1.19/2.;    //equivalent thickness
+  const Float_t hzOuterFrameInox = 0.1/2.;      //equivalent thickness
+  const Float_t hzFoam = 2.083/2.;              //evaluated elsewhere
+  
+// Pertaining to the top outer area 
+  const Float_t hzTopAnodeSteel1 = 0.185/2.;    //equivalent thickness
+  const Float_t hzTopAnodeSteel2 = 0.51/2.;     //equivalent thickness  
+  const Float_t hzAnodeFR4 = 0.08/2.;           //equivalent thickness
+  const Float_t hzTopEarthFaceCu = 0.364/2.;    //equivalent thickness
+  const Float_t hzTopEarthProfileCu = 1.1/2.;   //equivalent thickness
+  const Float_t hzTopPositionerSteel = 1.45/2.; //should really be 2.125/2.; 
+  const Float_t hzTopGasSupportAl = 0.85/2.;    //equivalent thickness
+  
+// Pertaining to the vertical outer area  
+  const Float_t hzVerticalCradleAl = 0.8/2.;     //equivalent thickness
+  const Float_t hzLateralSightAl = 0.975/2.;     //equivalent thickness
+  const Float_t hzLateralPosnInoxFace = 2.125/2.;//equivalent thickness
+  const Float_t hzLatPosInoxProfM = 6.4/2.;      //equivalent thickness
+  const Float_t hzLatPosInoxProfNF = 1.45/2.;    //equivalent thickness
+  const Float_t hzLateralPosnAl = 0.5/2.;        //equivalent thickness
+  const Float_t hzVertEarthFaceCu = 0.367/2.;    //equivalent thickness
+  const Float_t hzVertBarSteel = 0.198/2.;       //equivalent thickness
+  const Float_t hzVertEarthProfCu = 1.1/2.;      //equivalent thickness
+
+      //_______________Parameter definitions in sequence _________
+
+// InVFrame parameters
+  const Float_t hxInVFrame  = 1.85/2.;
+  const Float_t hyInVFrame  = 73.95/2.;
   const Float_t hzInVFrame  = hzFrameThickness;
 
-  //Flat 1mm vertical section
-  const Float_t hxV1mm  = 0.1/2.;
-  const Float_t hyV1mm  = 2.5/2.;
+//Flat 7.5mm vertical section
+  const Float_t hxV1mm  = 0.75/2.;
+  const Float_t hyV1mm  = 1.85/2.;
   const Float_t hzV1mm  = hzFrameThickness;
-  
-  //Flat 1mm horizontal section
-  const Float_t hxH1mm  = 2.5/2.;
-  const Float_t hyH1mm  = 0.1/2.;
-  const Float_t hzH1mm  = hzFrameThickness;
-   
-  // InArcFrame parameters
-  const Float_t IAF  = 15.70;
-  const Float_t OAF  = 18.20;
-  const Float_t hzAF  = hzFrameThickness;
-  const Float_t AFphi1  = 0.0;
-  const Float_t AFphi2  = 90.0;
-
-  // ScrewsInFrame parameters HEAD
-  const Float_t SCRUHMI  = 0.;
-  const Float_t SCRUHMA  = 0.690/2.;
-  const Float_t SCRUHLE  = 0.4/2.;
-    // ScrewsInFrame parameters MIDDLE
-  const Float_t SCRUMMI  = 0.;
-  const Float_t SCRUMMA  = 0.39/2.;
-  const Float_t SCRUMLE  = hzFrameThickness;
-    // ScrewsInFrame parameters NUT
-  const Float_t SCRUNMI  = 0.;
-  const Float_t SCRUNMA  = 0.78/2.;
-  const Float_t SCRUNLE  = 0.8/2.;
 
-  // OutVFrame parameters
-  const Float_t hxOutVFrame  = 2.5/2.;
-  const Float_t hyOutVFrame  = 43.927/2.;
-  const Float_t hzOutVFrame  = hzFrameThickness;
+// OuterTopFrame Structure 
+//
+// FRAME
+// The frame is composed of a cuboid and two trapezoids 
+// (TopFrameAnode, TopFrameAnodeA, TopFrameAnodeB). 
+// Each shape is composed of two layers (Epoxy and Inox) and 
+// takes the frame's inner anode circuitry into account in the material budget.
+//
+// ANODE
+// The overhanging anode part is composed froma cuboid and two trapezoids 
+// (TopAnode, TopAnode1, and TopAnode2). These surfaces neglect implanted
+// resistors, but accounts for the major Cu, Pb/Sn, and FR4 material
+// contributions.  
+// The stainless steel anode supports have been included.
+//
+// EARTHING (TopEarthFace, TopEarthProfile)
+// Al GAS SUPPORT (TopGasSupport)
+//  
+// ALIGNMENT (TopPositioner) - Alignment system, three sights per quarter 
+// chamber. This sight is forseen for the alignment of the horizontal level 
+// (parallel to the OY axis of LHC). Its position will be evaluated relative 
+// to a system of sights places on the cradles;
+//
+//---
   
-/////////////////////////////////////////////////////// 
-
-// OutTopCuboidFrame Epoxy parameters
-  const Float_t hxOutHFrame  = 31.9304/2.;
-  const Float_t hyOutHFrame  = 8.4/2.;
-  const Float_t hzOutHFrame  = hzOuterFrameEpoxy;
+//TopFrameAnode parameters - cuboid, 2 layers
+  const Float_t hxTFA = 34.1433/2.;
+  const Float_t hyTFA = 7.75/2.;
+  const Float_t hzTFAE = hzOuterFrameEpoxy;     // layer 1 thickness
+  const Float_t hzTFAI = hzOuterFrameInox;      // layer 3 thickness
   
-// OutTopTrapFrameA Epoxy parameters
-  const Float_t hzOTTFA = hzOuterFrameEpoxy;
-  const Float_t tetOTTFA = 0.;
-  const Float_t phiOTTFA = 0.;
-  const Float_t h1OTTFA = 9.6716/2.;
-  const Float_t bl1OTTFA = 4.7787/2.;
-  const Float_t tl1OTTFA =  8.4/2.;
-  const Float_t alp1OTTFA = 10.6; 
-  const Float_t h2OTTFA = 9.6716/2.;
-  const Float_t bl2OTTFA = 4.7787/2.;
-  const Float_t tl2OTTFA = 8.4/2.;
-  const Float_t alp2OTTFA = 10.6;  
+// TopFrameAnodeA parameters - trapezoid, 2 layers
+  const Float_t hzFAAE = hzOuterFrameEpoxy;     // layer 1 thickness
+  const Float_t hzFAAI = hzOuterFrameInox;      // layer 3 thickness
+  const Float_t tetFAA = 0.;
+  const Float_t phiFAA = 0.;
+  const Float_t h1FAA = 8.7/2.;
+  const Float_t bl1FAA = 4.35/2.;
+  const Float_t tl1FAA =  7.75/2.;
+  const Float_t alp1FAA = 11.06; 
+  const Float_t h2FAA = 8.7/2.;
+  const Float_t bl2FAA = 4.35/2.;
+  const Float_t tl2FAA = 7.75/2.;
+  const Float_t alp2FAA = 11.06;  
   
-// OutTopTrapFrameB Epoxy parameters
-  const Float_t hzOTTFB = hzOuterFrameEpoxy;
-  const Float_t tetOTTFB = 0.;
-  const Float_t phiOTTFB = 0.;
-  const Float_t h1OTTFB = 9.6716/2.;
-  const Float_t bl1OTTFB = 0.;
-  const Float_t tl1OTTFB =  4.7787/2.;
-  const Float_t alp1OTTFB = 13.88; 
-  const Float_t h2OTTFB = 9.6716/2.;
-  const Float_t bl2OTTFB = 0.;
-  const Float_t tl2OTTFB = 4.7787/2.;
-  const Float_t alp2OTTFB = 13.88;
-
-  // OutTopTrapFrame Solder parameters
-  const Float_t hzOTTFS = hzOuterFrameSolder;
+// TopFrameAnodeB parameters - trapezoid, 2 layers
+  const Float_t hzFABE = hzOuterFrameEpoxy;     // layer 1 thickness
+  const Float_t hzFABI = hzOuterFrameInox;      // layer 3 thickness
+  const Float_t tetFAB = 0.;
+  const Float_t phiFAB = 0.;
+  const Float_t h1FAB = 8.70/2.;
+  const Float_t bl1FAB = 0.;
+  const Float_t tl1FAB = 4.35/2.;
+  const Float_t alp1FAB = 14.03; 
+  const Float_t h2FAB = 8.70/2.;
+  const Float_t bl2FAB = 0.;
+  const Float_t tl2FAB = 4.35/2.;
+  const Float_t alp2FAB = 14.03;  
   
-  // OutTopTrapFrame Inox parameters
-  const Float_t hzOTTFI = hzOuterFrameInox;
-/////////////////////////////////////////////////////////  
-
-  // OutEdgeTrapFrame parameters 
-  // TRAPEZE 1
-  const Float_t hzOETF = hzOuterFrameEpoxy;   
-  const Float_t tetOETF = 0.;
-  const Float_t phiOETF = 0.;
-  const Float_t h1OETF = 7.129/2.; 
-  const Float_t bl1OETF1 = 3.705/2; 
-  const Float_t tl1OETF1 = 3.9471/2.;
-  const Float_t alp1OETF1 = 0.97;
-  const Float_t h2OETF = 7.129/2.;    
-  const Float_t bl2OETF1 = 3.705/2;
-  const Float_t tl2OETF1 = 3.9471/2.;
-  const Float_t alp2OETF1 = 0.97;
+// TopAnode parameters - cuboid (part 1 of 3 parts)
+  const Float_t hxTA1 = 16.2/2.;
+  const Float_t hyTA1 = 3.5/2.;
+  const Float_t hzTA11 = hzTopAnodeSteel1;   // layer 1
+  const Float_t hzTA12 = hzAnodeFR4;         // layer 2 
+
+// TopAnode parameters - trapezoid 1 (part 2 of 3 parts)
+  const Float_t hzTA21 = hzTopAnodeSteel2;   // layer 1 
+  const Float_t hzTA22 = hzAnodeFR4;         // layer 2 
+  const Float_t tetTA2 = 0.;
+  const Float_t phiTA2= 0.;
+  const Float_t h1TA2 = 7.268/2.;
+  const Float_t bl1TA2 = 2.03/2.;
+  const Float_t tl1TA2 = 3.5/2.;
+  const Float_t alp1TA2 = 5.78; 
+  const Float_t h2TA2 = 7.268/2.;
+  const Float_t bl2TA2 = 2.03/2.;
+  const Float_t tl2TA2 = 3.5/2.;
+  const Float_t alp2TA2 = 5.78;  
+
+// TopAnode parameters - trapezoid 2 (part 3 of 3 parts)
+  const Float_t hzTA3 = hzAnodeFR4;       // layer 1 
+  const Float_t tetTA3 = 0.;
+  const Float_t phiTA3 = 0.;
+  const Float_t h1TA3 = 7.268/2.;
+  const Float_t bl1TA3 = 0.;
+  const Float_t tl1TA3 = 2.03/2.;
+  const Float_t alp1TA3 = 7.95; 
+  const Float_t h2TA3 = 7.268/2.;
+  const Float_t bl2TA3 = 0.;
+  const Float_t tl2TA3 = 2.03/2.;
+  const Float_t alp2TA3 = 7.95;  
   
-  // TRAPEZE 2
-  const Float_t bl1OETF2 = 2.9744/2.;
-  const Float_t tl1OETF2 =  3.705/2;
-  const Float_t alp1OETF2 =  2.93;
-      
-  const Float_t bl2OETF2 =  2.9744/2.;
-  const Float_t tl2OETF2 =  3.705/2;
-  const Float_t alp2OETF2 =  2.93; 
+// TopEarthFace parameters - single trapezoid
+  const Float_t hzTEF = hzTopEarthFaceCu;
+  const Float_t tetTEF = 0.;
+  const Float_t phiTEF = 0.;
+  const Float_t h1TEF = 1.200/2.;
+  const Float_t bl1TEF = 21.323/2.;
+  const Float_t tl1TEF = 17.963/2.;
+  const Float_t alp1TEF = -54.46; 
+  const Float_t h2TEF = 1.200/2.;
+  const Float_t bl2TEF = 21.323/2.;
+  const Float_t tl2TEF = 17.963/2.;
+  const Float_t alp2TEF = -54.46;
+
+// TopEarthProfile parameters - single trapezoid
+  const Float_t hzTEP = hzTopEarthProfileCu;
+  const Float_t tetTEP = 0.;
+  const Float_t phiTEP = 0.;
+  const Float_t h1TEP = 0.40/2.;
+  const Float_t bl1TEP = 31.766/2.;
+  const Float_t tl1TEP = 30.535/2.;
+  const Float_t alp1TEP = -56.98; 
+  const Float_t h2TEP = 0.40/2.;
+  const Float_t bl2TEP = 31.766/2.;
+  const Float_t tl2TEP = 30.535/2.;
+  const Float_t alp2TEP = -56.98;
+
+// TopPositioner parameters - single Stainless Steel trapezoid 
+  const Float_t hzTP = hzTopPositionerSteel;
+  const Float_t tetTP = 0.;
+  const Float_t phiTP = 0.;
+  const Float_t h1TP = 3.00/2.;
+  const Float_t bl1TP = 7.023/2.;
+  const Float_t tl1TP = 7.314/2.;
+  const Float_t alp1TP = 2.78; 
+  const Float_t h2TP = 3.00/2.;
+  const Float_t bl2TP = 7.023/2.;
+  const Float_t tl2TP = 7.314/2.;
+  const Float_t alp2TP = 2.78;
+
+// TopGasSupport parameters - single cuboid 
+  const Float_t hxTGS  = 8.50/2.;
+  const Float_t hyTGS  = 3.00/2.;
+  const Float_t hzTGS  = hzTopGasSupportAl;
+    
+// OutEdgeFrame parameters - 4 trapezoidal sections, 2 layers of material
+//
+//---
+
+// Trapezoid 1
+  const Float_t hzOETFE = hzOuterFrameEpoxy;    // layer 1 
+  const Float_t hzOETFI = hzOuterFrameInox;     // layer 3
    
-  // TRAPEZE 3
-  const Float_t bl1OETF3 = 1.7455/2.;
-  const Float_t tl1OETF3 =  2.9744/2.;
-  const Float_t alp1OETF3 =  4.93;
+  const Float_t tetOETF = 0.;            // common to all 4 trapezoids
+  const Float_t phiOETF = 0.;            // common to all 4 trapezoids
+
+  const Float_t h1OETF = 7.196/2.;       // common to all 4 trapezoids
+  const Float_t h2OETF = 7.196/2.;       // common to all 4 trapezoids   
+  
+  const Float_t bl1OETF1 = 3.75/2; 
+  const Float_t tl1OETF1 = 3.996/2.;
+  const Float_t alp1OETF1 = 0.98;
+
+  const Float_t bl2OETF1 = 3.75/2;
+  const Float_t tl2OETF1 = 3.996/2.;
+  const Float_t alp2OETF1 = 0.98;
+  
+// Trapezoid 2
+  const Float_t bl1OETF2 = 3.01/2.;
+  const Float_t tl1OETF2 = 3.75/2;
+  const Float_t alp1OETF2 = 2.94;
+      
+  const Float_t bl2OETF2 = 3.01/2.;
+  const Float_t tl2OETF2 = 3.75/2;
+  const Float_t alp2OETF2 = 2.94; 
+// Trapezoid 3
+  const Float_t bl1OETF3 = 1.767/2.;
+  const Float_t tl1OETF3 = 3.01/2.;
+  const Float_t alp1OETF3 = 4.94;
       
-  const Float_t bl2OETF3 = 1.7455/2.;
-  const Float_t tl2OETF3 = 2.9744/2.; 
-  const Float_t alp2OETF3 =  4.93; 
+  const Float_t bl2OETF3 = 1.767/2.;
+  const Float_t tl2OETF3 = 3.01/2.; 
+  const Float_t alp2OETF3 = 4.94; 
   
-  // TRAPEZE 4
+// Trapezoid 4
   const Float_t bl1OETF4 = 0.;
-  const Float_t tl1OETF4 =  1.7455/2.;
-  const Float_t alp1OETF4 =  6.98;
+  const Float_t tl1OETF4 = 1.77/2.;
+  const Float_t alp1OETF4 = 7.01;
       
   const Float_t bl2OETF4 = 0.;
-  const Float_t tl2OETF4 = 1.7455/2.;
-  const Float_t alp2OETF4 =  6.98;   
- ///////////////////////////////////////////////////
-    
-  // OutCornerTrapFrame parameters
+  const Float_t tl2OETF4 = 1.77/2.;
+  const Float_t alp2OETF4 =  7.01;   
+  
+// Frame Structure (OutVFrame):
+//
+// OutVFrame and corner (OutVFrame cuboid, OutVFrame trapezoid)
+// EARTHING (VertEarthFaceCu,VertEarthSteel,VertEarthProfCu),
+// DETECTOR POSITIONNING (SuppLateralPositionner, LateralPositionner),
+// CRADLE (VertCradle), and
+// ALIGNMENT (LateralSightSupport, LateralSight) 
+//
+//---
+
+// OutVFrame parameters - cuboid
+  const Float_t hxOutVFrame = 1.85/2.;
+  const Float_t hyOutVFrame = 46.23/2.;
+  const Float_t hzOutVFrame = hzFrameThickness;
+
+// OutVFrame corner parameters - trapezoid
   const Float_t hzOCTF = hzFrameThickness;
   const Float_t tetOCTF = 0.;
   const Float_t phiOCTF = 0.;
-  const Float_t h1OCTF = 2.5/2.;
+  const Float_t h1OCTF = 1.85/2.;
   const Float_t bl1OCTF = 0.;
-  const Float_t tl1OCTF =  4.7469/2.;
-  const Float_t alp1OCTF = 43.51; 
-  const Float_t h2OCTF = 2.5/2.;
+  const Float_t tl1OCTF = 3.66/2.;
+  const Float_t alp1OCTF = 44.67; 
+  const Float_t h2OCTF = 1.85/2.;
   const Float_t bl2OCTF = 0.;
-  const Float_t tl2OCTF = 4.7469/2.;
-  const Float_t alp2OCTF = 43.51;  
-
-  // Reference point - MIRE (3 per quadrant, only 1 programmed)
-  const Float_t MIREInRad  = 0.6;
-  const Float_t MIREOutRad  = 1.3;
-  const Float_t MIRELen  = hzFrameThickness;
-       
-  Float_t par[11];
-  Float_t posX,posY,posZ;
-       
-// ___________________Make volumes________________________
-
-// Quadrant volume
-    par[0] = fgkMotherIR;
-    par[1] = fgkMotherOR; 
-    par[2] = fgkMotherThick;  
-    par[3] = fgkMotherPhiL; 
-    par[4] = fgkMotherPhiU;
-
-    //Quadrant volume.....positionned at the end
-    gMC->Gsvolu(QuadrantName(chamber),"TUBS",idAir,par,5);
-            
-// _______________________________________________________
-// InVFrame  
-   if (chamber==1) {   
-      // simple epoxy layer...must be inside sensitive surface for tracking
-      par[0] = hxInVFrame;
-      par[1] = hyInVFrame;
-      par[2] = hzInVFrame;
-      
-      gMC->Gsvolu("IVEF","BOX",idFrameEpoxy,par,3);
-
-  // InHFrame
-      par[0] = hxInHFrame;
-      par[1] = hyInHFrame;
-      par[2] = hzInHFrame;
-
-      gMC->Gsvolu("IHEF","BOX",idFrameEpoxy,par,3);
+  const Float_t tl2OCTF = 3.66/2.;
+  const Float_t alp2OCTF = 44.67;  
+  
+// VertEarthFaceCu parameters - single trapezoid
+  const Float_t hzVFC = hzVertEarthFaceCu;
+  const Float_t tetVFC = 0.;
+  const Float_t phiVFC = 0.;
+  const Float_t h1VFC = 1.200/2.;
+  const Float_t bl1VFC = 46.11/2.;
+  const Float_t tl1VFC = 48.236/2.;
+  const Float_t alp1VFC = 41.54; 
+  const Float_t h2VFC = 1.200/2.;
+  const Float_t bl2VFC = 46.11/2.;
+  const Float_t tl2VFC = 48.236/2.;
+  const Float_t alp2VFC = 41.54;
+    
+// VertEarthSteel parameters - single trapezoid
+  const Float_t hzVES = hzVertBarSteel;
+  const Float_t tetVES = 0.;
+  const Float_t phiVES = 0.;
+  const Float_t h1VES = 1.200/2.;
+  const Float_t bl1VES = 30.486/2.;
+  const Float_t tl1VES = 32.777/2.;
+  const Float_t alp1VES = 43.67; 
+  const Float_t h2VES = 1.200/2.;
+  const Float_t bl2VES = 30.486/2.;
+  const Float_t tl2VES = 32.777/2.;
+  const Float_t alp2VES = 43.67;
+
+// VertEarthProfCu parameters - single trapezoid
+  const Float_t hzVPC = hzVertEarthProfCu;
+  const Float_t tetVPC = 0.;
+  const Float_t phiVPC = 0.;
+  const Float_t h1VPC = 0.400/2.;
+  const Float_t bl1VPC = 29.287/2.;
+  const Float_t tl1VPC = 30.091/2.;
+  const Float_t alp1VPC = 45.14; 
+  const Float_t h2VPC = 0.400/2.;
+  const Float_t bl2VPC = 29.287/2.;
+  const Float_t tl2VPC = 30.091/2.;
+  const Float_t alp2VPC = 45.14;
+
+// SuppLateralPositionner - single cuboid
+  const Float_t hxSLP  = 2.80/2.;
+  const Float_t hySLP  = 5.00/2.;
+  const Float_t hzSLP  = hzLateralPosnAl;
+  
+// LateralPositionner - squared off U bend, face view
+  const Float_t hxLPF  = 5.2/2.;
+  const Float_t hyLPF  = 3.0/2.;
+  const Float_t hzLPF  = hzLateralPosnInoxFace;
+  
+// LateralPositionner - squared off U bend, profile view
+  const Float_t hxLPP  = 0.425/2.;
+  const Float_t hyLPP  = 3.0/2.;
+  const Float_t hzLPP  = hzLatPosInoxProfM;  // middle layer
+  const Float_t hzLPNF  = hzLatPosInoxProfNF; // near and far layers
+           
+// VertCradle, 3 layers (copies), each composed of 4 trapezoids
+// VertCradleA
+  const Float_t hzVC1 = hzVerticalCradleAl;
+  const Float_t tetVC1 = 0.;
+  const Float_t phiVC1 = 0.;
+  const Float_t h1VC1 = 10.25/2.;
+  const Float_t bl1VC1 = 3.70/2.;
+  const Float_t tl1VC1 = 0.;
+  const Float_t alp1VC1 = -10.23; 
+  const Float_t h2VC1 = 10.25/2.;
+  const Float_t bl2VC1 = 3.70/2.;
+  const Float_t tl2VC1 = 0.;
+  const Float_t alp2VC1 = -10.23;
+        
+// VertCradleB
+  const Float_t hzVC2 = hzVerticalCradleAl;
+  const Float_t tetVC2 = 0.;
+  const Float_t phiVC2 = 0.;
+  const Float_t h1VC2 = 10.25/2.;
+  const Float_t bl1VC2 = 6.266/2.;
+  const Float_t tl1VC2 = 3.70/2.;
+  const Float_t alp1VC2 = -7.13; 
+  const Float_t h2VC2 = 10.25/2.;
+  const Float_t bl2VC2 = 6.266/2.;
+  const Float_t tl2VC2 = 3.70/2.;
+  const Float_t alp2VC2 = -7.13;
+  
+// VertCradleC
+  const Float_t hzVC3 = hzVerticalCradleAl;
+  const Float_t tetVC3 = 0.;
+  const Float_t phiVC3 = 0.;
+  const Float_t h1VC3 = 10.25/2.;
+  const Float_t bl1VC3 = 7.75/2.;
+  const Float_t tl1VC3 = 6.266/2.;
+  const Float_t alp1VC3 = -4.14; 
+  const Float_t h2VC3 = 10.25/2.;
+  const Float_t bl2VC3 = 7.75/2.;
+  const Float_t tl2VC3 = 6.266/2.;
+  const Float_t alp2VC3 = -4.14;
+
+// VertCradleD
+  const Float_t hzVC4 = hzVerticalCradleAl;
+  const Float_t tetVC4 = 0.;
+  const Float_t phiVC4 = 0.;
+  const Float_t h1VC4 = 10.27/2.;
+  const Float_t bl1VC4 = 8.273/2.;
+  const Float_t tl1VC4 = 7.75/2.;
+  const Float_t alp1VC4 = -1.46; 
+  const Float_t h2VC4 = 10.27/2.;
+  const Float_t bl2VC4 = 8.273/2.;
+  const Float_t tl2VC4 = 7.75/2.;
+  const Float_t alp2VC4 = -1.46;
+  
+// LateralSightSupport - single trapezoid
+  const Float_t hzVSS = hzLateralSightAl;
+  const Float_t tetVSS = 0.;
+  const Float_t phiVSS = 0.;
+  const Float_t h1VSS = 5.00/2.;
+  const Float_t bl1VSS = 7.747/2;
+  const Float_t tl1VSS = 7.188/2.;
+  const Float_t alp1VSS = -3.20; 
+  const Float_t h2VSS = 5.00/2.;
+  const Float_t bl2VSS = 7.747/2.;
+  const Float_t tl2VSS = 7.188/2.;
+  const Float_t alp2VSS = -3.20;  
+  
+// LateralSight (reference point) - 3 per quadrant, only 1 programmed for now
+  const Float_t VSInRad  = 0.6;
+  const Float_t VSOutRad  = 1.3;
+  const Float_t VSLen  = hzFrameThickness; 
+  
+//---
 
-  //Flat 1mm vertical section
-      par[0] = hxV1mm;
-      par[1] = hyV1mm;
-      par[2] = hzV1mm;
+// InHFrame parameters
+  const Float_t hxInHFrame  = 75.8/2.;
+  const Float_t hyInHFrame  = 1.85/2.;
+  const Float_t hzInHFrame  = hzFrameThickness;
+//Flat 7.5mm horizontal section
+  const Float_t hxH1mm  = 1.85/2.;
+  const Float_t hyH1mm  = 0.75/2.;
+  const Float_t hzH1mm  = hzFrameThickness;
 
-      gMC->Gsvolu("FVMM","BOX",idFrameEpoxy,par,3);
+//---
 
-  //Flat 1mm vertical section
-      par[0] = hxH1mm;
-      par[1] = hyH1mm;
-      par[2] = hzH1mm;
+// InArcFrame parameters
+  const Float_t IAF  = 15.70;
+  const Float_t OAF  = 17.55;
+  const Float_t hzAF  = hzFrameThickness;
+  const Float_t AFphi1  = 0.0;
+  const Float_t AFphi2  = 90.0;
 
-      gMC->Gsvolu("FHMM","BOX",idFrameEpoxy,par,3);
+//---
 
-  // OutVFrame
-      par[0] = hxOutVFrame;
-      par[1] = hyOutVFrame;
-      par[2] = hzOutVFrame;
+// ScrewsInFrame parameters HEAD
+  const Float_t SCRUHMI  = 0.;
+  const Float_t SCRUHMA  = 0.690/2.;
+  const Float_t SCRUHLE  = 0.4/2.;
+// ScrewsInFrame parameters MIDDLE
+  const Float_t SCRUMMI  = 0.;
+  const Float_t SCRUMMA  = 0.39/2.;
+  const Float_t SCRUMLE  = hzFrameThickness;
+// ScrewsInFrame parameters NUT
+  const Float_t SCRUNMI  = 0.;
+  const Float_t SCRUNMA  = 0.78/2.;
+  const Float_t SCRUNLE  = 0.8/2.;   
+  
+       // ___________________Make volumes________________________
 
-      gMC->Gsvolu("OVEF","BOX",idFrameEpoxy,par,3);
+ Float_t par[11];
+ Float_t posX,posY,posZ;
 
-  // InArcFrame 
-      par[0] = IAF;
-      par[1] = OAF; 
-      par[2] = hzAF;  
-      par[3] = AFphi1; 
-      par[4] = AFphi2 ;
+// Quadrant volume TUBS1, positioned at the end
+  par[0] = fgkMotherIR1;
+  par[1] = fgkMotherOR1; 
+  par[2] = fgkMotherThick1;  
+  par[3] = fgkMotherPhiL1; 
+  par[4] = fgkMotherPhiU1;
+  gMC->Gsvolu(QuadrantMLayerName(chamber),"TUBS",idAir,par,5);
 
-      gMC->Gsvolu("IAF1","TUBS",idFrameEpoxy,par,5);
+// Quadrant volume TUBS2, positioned at the end
+  par[0] = fgkMotherIR2;
+  par[1] = fgkMotherOR2; 
+  par[2] = fgkMotherThick2;  
+  par[3] = fgkMotherPhiL2; 
+  par[4] = fgkMotherPhiU2;
 
-  // ScrewsInFrame - 3 sections in order to avoid overlapping volumes
-  // Screw Head, in air
-      par[0] = SCRUHMI;
-      par[1] = SCRUHMA; 
-      par[2] = SCRUHLE;  
+  gMC->Gsvolu(QuadrantNLayerName(chamber),"TUBS",idAir,par,5); 
+  gMC->Gsvolu(QuadrantFLayerName(chamber),"TUBS",idAir,par,5); 
 
-      gMC->Gsvolu("SCRH","TUBE",idInox,par,3);
+   if (chamber==1) {   
+    // InVFrame  
+    par[0] = hxInVFrame;
+    par[1] = hyInVFrame;
+    par[2] = hzInVFrame;
+    gMC->Gsvolu("SQ00","BOX",idFrameEpoxy,par,3);
+
+    //Flat 1mm vertical section
+    par[0] = hxV1mm;
+    par[1] = hyV1mm;
+    par[2] = hzV1mm;
+    gMC->Gsvolu("SQ01","BOX",idFrameEpoxy,par,3); 
+// OutTopFrame 
+//
+// - 3 components (a cuboid and 2 trapezes) and 2 layers (Epoxy/Inox)
+//
+//---
 
-  // Middle part, in the Epoxy
-      par[0] = SCRUMMI;
-      par[1] = SCRUMMA;
-      par[2] = SCRUMLE;
+    // TopFrameAnode - layer 1 of 2 
+    par[0] = hxTFA;
+    par[1] = hyTFA;
+    par[2] = hzTFAE;
+    gMC->Gsvolu("SQ02","BOX",idFrameEpoxy,par,3);
+    
+    // TopFrameAnode - layer 2 of 2 
+    par[2] = hzTFAI;
+    gMC->Gsvolu("SQ03","BOX",idInox,par,3);
+            
+    // TopFrameAnodeA - layer 1 of 2  
+    par[0] = hzFAAE;
+    par[1] = tetFAA;
+    par[2] = phiFAA;
+    par[3] = h1FAA;
+    par[4] = bl1FAA;
+    par[5] = tl1FAA;
+    par[6] = alp1FAA;
+    par[7] = h2FAA;
+    par[8] = bl2FAA;
+    par[9] = tl2FAA;
+    par[10] = alp2FAA;    
+    gMC->Gsvolu("SQ04","TRAP",idFrameEpoxy,par,11);    
+
+    // TopFrameAnodeA - layer 2 of 2
+    par[0] = hzFAAI;    
+    gMC->Gsvolu("SQ05","TRAP",idInox,par,11); 
       
-      gMC->Gsvolu("SCRM","TUBE",idInox,par,3);
-
-  // Screw nut, in air
-      par[0] = SCRUNMI;
-      par[1] = SCRUNMA;
-      par[2] = SCRUNLE; 
-        
-      gMC->Gsvolu("SCRN","TUBE",idInox,par,3);   
+    // TopFrameAnodeB - layer 1 of 2
+    par[0] = hzFABE;
+    par[1] = tetFAB;
+    par[2] = phiFAB;
+    par[3] = h1FAB;
+    par[4] = bl1FAB;
+    par[5] = tl1FAB;
+    par[6] = alp1FAB;
+    par[7] = h2FAB;
+    par[8] = bl2FAB;
+    par[9] = tl2FAB;
+    par[10] = alp2FAB;
+    gMC->Gsvolu("SQ06","TRAP",idFrameEpoxy,par,11);     
+
+    // OutTopTrapFrameB - layer 2 of 2
+    par[0] = hzFABI;   
+    gMC->Gsvolu("SQ07","TRAP",idInox,par,11);
+
+    // TopAnode1 -  layer 1 of 2
+    par[0] = hxTA1;
+    par[1] = hyTA1;
+    par[2] = hzTA11;    
+    gMC->Gsvolu("SQ08","BOX",idInox,par,3); 
+    
+    // TopAnode1 -  layer 2 of 2
+    par[2] = hzTA12;    
+    gMC->Gsvolu("SQ09","BOX",idFR4,par,11); 
+
+    // TopAnode2 -  layer 1 of 2
+    par[0] = hzTA21;
+    par[1] = tetTA2;
+    par[2] = phiTA2;
+    par[3] = h1TA2;
+    par[4] = bl1TA2;
+    par[5] = tl1TA2;
+    par[6] = alp1TA2;
+    par[7] = h2TA2;
+    par[8] = bl2TA2;
+    par[9] = tl2TA2;
+    par[10] = alp2TA2;    
+    gMC->Gsvolu("SQ10","TRAP",idInox,par,11); 
+    // TopAnode2 -  layer 2 of 2
+    par[0] = hzTA22;    
+    gMC->Gsvolu("SQ11","TRAP",idFR4,par,11);   
+
+    // TopAnode3 -  layer 1 of 1 
+    par[0] = hzTA3;
+    par[1] = tetTA3;
+    par[2] = phiTA3;
+    par[3] = h1TA3;
+    par[4] = bl1TA3;
+    par[5] = tl1TA3;
+    par[6] = alp1TA3;
+    par[7] = h2TA3;
+    par[8] = bl2TA3;
+    par[9] = tl2TA3;
+    par[10] = alp2TA3;    
+    gMC->Gsvolu("SQ12","TRAP",idFR4,par,11); 
+
+    // TopEarthFace 
+    par[0] = hzTEF;
+    par[1] = tetTEF;
+    par[2] = phiTEF;
+    par[3] = h1TEF;
+    par[4] = bl1TEF;
+    par[5] = tl1TEF;
+    par[6] = alp1TEF;
+    par[7] = h2TEF;
+    par[8] = bl2TEF;
+    par[9] = tl2TEF;
+    par[10] = alp2TEF;    
+    gMC->Gsvolu("SQ13","TRAP",idCopper,par,11);   
+
+    // TopEarthProfile 
+    par[0] = hzTEP;
+    par[1] = tetTEP;
+    par[2] = phiTEP;
+    par[3] = h1TEP;
+    par[4] = bl1TEP;
+    par[5] = tl1TEP;
+    par[6] = alp1TEP;
+    par[7] = h2TEP;
+    par[8] = bl2TEP;
+    par[9] = tl2TEP;
+    par[10] = alp2TEP;
+    gMC->Gsvolu("SQ14","TRAP",idCopper,par,11);       
+
+    // TopGasSupport  
+    par[0] = hxTGS;
+    par[1] = hyTGS;
+    par[2] = hzTGS;
+    gMC->Gsvolu("SQ15","BOX",idAlu,par,3);
+
+    // TopPositioner parameters - single Stainless Steel trapezoid 
+    par[0] = hzTP;
+    par[1] = tetTP; 
+    par[2] = phiTP;
+    par[3] = h1TP;
+    par[4] = bl1TP; 
+    par[5] = tl1TP; 
+    par[6] = alp1TP;
+    par[7] = h2TP;
+    par[8] = bl2TP; 
+    par[9] = tl2TP; 
+    par[10] = alp2TP;     
+    gMC->Gsvolu("SQ16","TRAP",idInox,par,11);       
 
-  ///////////////////////////////////////////
+//
+// OutEdgeTrapFrame Epoxy = (4 trapezes)*2 copies*2 layers (Epoxy/Inox)
+//
+//---
+    // Trapezoid 1 - 2 layers
+    par[1] = tetOETF;
+    par[2] = phiOETF;
+    par[3] = h1OETF;
+    par[4] = bl1OETF1;
+    par[5] = tl1OETF1;
+    par[6] = alp1OETF1;
+    par[7] = h2OETF;
+    par[8] = bl2OETF1;
+    par[9] = tl2OETF1;
+    par[10] = alp2OETF1; 
+           
+    par[0] = hzOETFE;             
+    gMC->Gsvolu("SQ17","TRAP",idFrameEpoxy,par,11); 
+    par[0] = hzOETFI;
+    gMC->Gsvolu("SQ18","TRAP",idInox,par,11);
+    
+    // Trapezoid 2 - 2 layers
+    par[4] = bl1OETF2;
+    par[5] = tl1OETF2;
+    par[6] = alp1OETF2;
+
+    par[8] = bl2OETF2;
+    par[9] = tl2OETF2;
+    par[10] = alp2OETF2; 
+    
+    par[0] = hzOETFE;    
+    gMC->Gsvolu("SQ19","TRAP",idFrameEpoxy,par,11);    
+    par[0] = hzOETFI;    
+    gMC->Gsvolu("SQ20","TRAP",idInox,par,11);     
+    
+    // Trapezoid 3 - 2 layers
+    par[4] = bl1OETF3;
+    par[5] = tl1OETF3;
+    par[6] = alp1OETF3;
+
+    par[8] = bl2OETF3;
+    par[9] = tl2OETF3;
+    par[10] = alp2OETF3; 
+    par[0] = hzOETFE;    
+    gMC->Gsvolu("SQ21","TRAP",idFrameEpoxy,par,11);   
+    par[0] = hzOETFI;    
+    gMC->Gsvolu("SQ22","TRAP",idInox,par,11);     
+    
+    // Trapezoid 4 - 2 layers
 
-  // OutTopTrapFrame Epoxy 
-  // - 3 components (cuboid and 2 trapezes) and 3 layers (Epoxy/Inox/Solder)
+    par[4] = bl1OETF4;
+    par[5] = tl1OETF4;
+    par[6] = alp1OETF4;
 
-  // OutTopCuboidFrame Epoxy 
-      par[0] = hxOutHFrame;
-      par[1] = hyOutHFrame;
-      par[2] = hzOutHFrame;
-      
-      gMC->Gsvolu("OHEA","BOX",idFrameEpoxy,par,3);
-
-  // OutTopTrapFrameA Epoxy parameters    
-      par[0] = hzOTTFA;
-      par[1] = tetOTTFA;
-      par[2] = phiOTTFA;
-      par[3] = h1OTTFA;
-      par[4] = bl1OTTFA;
-      par[5] = tl1OTTFA;
-      par[6] = alp1OTTFA;
-      par[7] = h2OTTFA;
-      par[8] = bl2OTTFA;
-      par[9] = tl2OTTFA;
-      par[10] = alp2OTTFA;
-
-      gMC->Gsvolu("OHEB","TRAP",idFrameEpoxy,par,11);    
-
-  // OutTopTrapFrameB Epoxy parameters    
-      par[0] = hzOTTFB;
-      par[1] = tetOTTFB;
-      par[2] = phiOTTFB;
-      par[3] = h1OTTFB;
-      par[4] = bl1OTTFB;
-      par[5] = tl1OTTFB;
-      par[6] = alp1OTTFB;
-      par[7] = h2OTTFB;
-      par[8] = bl2OTTFB;
-      par[9] = tl2OTTFB;
-      par[10] = alp2OTTFB;
-
-      gMC->Gsvolu("OHEC","TRAP",idFrameEpoxy,par,11);    
-
-  // OutTopCuboidFrame Solder 
-      par[0] = hxOutHFrame;
-      par[1] = hyOutHFrame;
-      par[2] = hzOTTFS;
-      gMC->Gsvolu("OHSA","BOX",idSolder,par,3);
-
-  // OutTopTrapFrameA Solder 
-      par[0] = hzOTTFS;
-      par[1] = tetOTTFA;
-      par[2] = phiOTTFA;
-      par[3] = h1OTTFA;
-      par[4] = bl1OTTFA;
-      par[5] = tl1OTTFA;
-      par[6] = alp1OTTFA;
-      par[7] = h2OTTFA;
-      par[8] = bl2OTTFA;
-      par[9] = tl2OTTFA;
-      par[10] = alp2OTTFA;
-
-      gMC->Gsvolu("OHSB","TRAP",idSolder,par,11); 
-
-
-  // OutTopTrapFrameB Solder 
-      par[0] = hzOTTFI;
-      par[1] = tetOTTFB;
-      par[2] = phiOTTFB;
-      par[3] = h1OTTFB;
-      par[4] = bl1OTTFB;
-      par[5] = tl1OTTFB;
-      par[6] = alp1OTTFB;
-      par[7] = h2OTTFB;
-      par[8] = bl2OTTFB;
-      par[9] = tl2OTTFB;
-      par[10] = alp2OTTFB;
-
-      gMC->Gsvolu("OHSC","TRAP",idSolder,par,11);  
-
-  // OutTopCuboidFrame Solder 
-      par[0] = hxOutHFrame;
-      par[1] = hyOutHFrame;
-      par[2] = hzOTTFI;
-      gMC->Gsvolu("OHIA","BOX",idInox,par,3);
-
-  // OutTopTrapFrameA Inox 
-      par[0] = hzOTTFI;
-      par[1] = tetOTTFA;
-      par[2] = phiOTTFA;
-      par[3] = h1OTTFA;
-      par[4] = bl1OTTFA;
-      par[5] = tl1OTTFA;
-      par[6] = alp1OTTFA;
-      par[7] = h2OTTFA;
-      par[8] = bl2OTTFA;
-      par[9] = tl2OTTFA;
-      par[10] = alp2OTTFA;
-
-      gMC->Gsvolu("OHIB","TRAP",idInox,par,11); 
-
-  // OutTopTrapFrameB Inox 
-      par[0] = hzOTTFI;
-      par[1] = tetOTTFB;
-      par[2] = phiOTTFB;
-      par[3] = h1OTTFB;
-      par[4] = bl1OTTFB;
-      par[5] = tl1OTTFB;
-      par[6] = alp1OTTFB;
-      par[7] = h2OTTFB;
-      par[8] = bl2OTTFB;
-      par[9] = tl2OTTFB;
-      par[10] = alp2OTTFB;
-
-      gMC->Gsvolu("OHIC","TRAP",idInox,par,11);
-
-  /////////////////////////////////
-
-  // OutEdgeTrapFrame Epoxy = (4 trapezes)*2 copies*3 layers (Epoxy/Inox/Solder)
-  // TRAPEZE 1
-      par[0] = hzOETF;
-      par[1] = tetOETF;
-      par[2] = phiOETF;
-      par[3] = h1OETF;
-      par[4] = bl1OETF1;
-      par[5] = tl1OETF1;
-      par[6] = alp1OETF1;
-      par[7] = h2OETF;
-      par[8] = bl2OETF1;
-      par[9] = tl2OETF1;
-      par[10] = alp2OETF1;
-
-      gMC->Gsvolu("EDE1","TRAP",idFrameEpoxy,par,11);  
-
-  // TRAPEZE 2
-      par[4] = bl1OETF2;
-      par[5] = tl1OETF2;
-      par[6] = alp1OETF2;
-
-      par[8] = bl2OETF2;
-      par[9] = tl2OETF2;
-      par[10] = alp2OETF2; 
-     gMC->Gsvolu("EDE2","TRAP",idFrameEpoxy,par,11);  
-
-  // TRAPEZE 3
-      par[4] = bl1OETF3;
-      par[5] = tl1OETF3;
-      par[6] = alp1OETF3;
-
-      par[8] = bl2OETF3;
-      par[9] = tl2OETF3;
-      par[10] = alp2OETF3; 
-     gMC->Gsvolu("EDE3","TRAP",idFrameEpoxy,par,11);  
-
-  // TRAPEZE 4
-      par[4] = bl1OETF4;
-      par[5] = tl1OETF4;
-      par[6] = alp1OETF4;
-
-      par[8] = bl2OETF4;
-      par[9] = tl2OETF4;
-      par[10] = alp2OETF4; 
-     gMC->Gsvolu("EDE4","TRAP",idFrameEpoxy,par,11);          
-
-  ////////////////////////////////
-
-    // TRAPEZE 1
-      par[0] = hzOuterFrameInox;
-      par[1] = tetOETF;
-      par[2] = phiOETF;
-      par[3] = h1OETF;
-      par[4] = bl1OETF1;
-      par[5] = tl1OETF1;
-      par[6] = alp1OETF1;
-      par[7] = h2OETF;
-      par[8] = bl2OETF1;
-      par[9] = tl2OETF1;
-      par[10] = alp2OETF1;
-
-      gMC->Gsvolu("EDI1","TRAP",idInox,par,11);  
-
-  // TRAPEZE 2
-      par[4] = bl1OETF2;
-      par[5] = tl1OETF2;
-      par[6] = alp1OETF2;
-
-      par[8] = bl2OETF2;
-      par[9] = tl2OETF2;
-      par[10] = alp2OETF2; 
-     gMC->Gsvolu("EDI2","TRAP",idInox,par,11);  
-
-  // TRAPEZE 3
-      par[4] = bl1OETF3;
-      par[5] = tl1OETF3;
-      par[6] = alp1OETF3;
-
-      par[8] = bl2OETF3;
-      par[9] = tl2OETF3;
-      par[10] = alp2OETF3; 
-     gMC->Gsvolu("EDI3","TRAP",idInox,par,11);  
-
-  // TRAPEZE 4
-      par[4] = bl1OETF4;
-      par[5] = tl1OETF4;
-      par[6] = alp1OETF4;
-
-      par[8] = bl2OETF4;
-      par[9] = tl2OETF4;
-      par[10] = alp2OETF4; 
-     gMC->Gsvolu("EDI4","TRAP",idInox,par,11);          
-
-
-  ////////////////////////////////
-
-    // TRAPEZE 1
-      par[0] = hzOuterFrameSolder;
-      par[1] = tetOETF;
-      par[2] = phiOETF;
-      par[3] = h1OETF;
-      par[4] = bl1OETF1;
-      par[5] = tl1OETF1;
-      par[6] = alp1OETF1;
-      par[7] = h2OETF;
-      par[8] = bl2OETF1;
-      par[9] = tl2OETF1;
-      par[10] = alp2OETF1;
-
-      gMC->Gsvolu("EDS1","TRAP",idSolder,par,11);
-
-  // TRAPEZE 2
-      par[4] = bl1OETF2;
-      par[5] = tl1OETF2;
-      par[6] = alp1OETF2;
-
-      par[8] = bl2OETF2;
-      par[9] = tl2OETF2;
-      par[10] = alp2OETF2; 
-     gMC->Gsvolu("EDS2","TRAP",idSolder,par,11);  
-
-  // TRAPEZE 3
-      par[4] = bl1OETF3;
-      par[5] = tl1OETF3;
-      par[6] = alp1OETF3;
-
-      par[8] = bl2OETF3;
-      par[9] = tl2OETF3;
-      par[10] = alp2OETF3; 
-     gMC->Gsvolu("EDS3","TRAP",idSolder,par,11);  
-
-  // TRAPEZE 4
-      par[4] = bl1OETF4;
-      par[5] = tl1OETF4;
-      par[6] = alp1OETF4;
-
-      par[8] = bl2OETF4;
-      par[9] = tl2OETF4;
-      par[10] = alp2OETF4; 
-     gMC->Gsvolu("EDS4","TRAP",idSolder,par,11);          
-
-  //////////////////////////////////
-
-  // OutCornerTrapFrame  
-      par[0] = hzOCTF;
-      par[1] = tetOCTF;
-      par[2] = phiOCTF;
-      par[3] = h1OCTF;
-      par[4] = bl1OCTF;
-      par[5] = tl1OCTF;
-      par[6] = alp1OCTF;
-      par[7] = h2OCTF;
-      par[8] = bl2OCTF;
-      par[9] = tl2OCTF;
-      par[10] = alp2OCTF;
-
-      gMC->Gsvolu("TCOR","TRAP",idFrameEpoxy,par,11);
-
-  // MIRE
-      par[0] = MIREInRad;
-      par[1] = MIREOutRad;
-      par[2] = MIRELen;    
-
-      gMC->Gsvolu("MIRE","TUBE",idFrameEpoxy,par,3);   
-  }
+    par[8] = bl2OETF4;
+    par[9] = tl2OETF4;
+    par[10] = alp2OETF4;  
+   
+    par[0] = hzOETFE;    
+    gMC->Gsvolu("SQ23","TRAP",idFrameEpoxy,par,11);    
+    par[0] = hzOETFI;    
+    gMC->Gsvolu("SQ24","TRAP",idInox,par,11);     
              
-// __________________Place volumes in the quadrant ____________ 
-
-    const Float_t BeamOX = 2.6;
-    const Float_t BeamOY = 2.6;  
-
- // Coordinates of the frame corner wrt the beam axis defined at (0,0)
-    Float_t QuadOX = 0.;
-    Float_t QuadOY = 0.;
+//---
+    // OutVFrame    
+    par[0] = hxOutVFrame;
+    par[1] = hyOutVFrame;
+    par[2] = hzOutVFrame;
+    gMC->Gsvolu("SQ25","BOX",idFrameEpoxy,par,3);
+    
+    // OutVFrame corner  
+    par[0] = hzOCTF;
+    par[1] = tetOCTF;
+    par[2] = phiOCTF;
+    par[3] = h1OCTF;
+    par[4] = bl1OCTF;
+    par[5] = tl1OCTF;
+    par[6] = alp1OCTF;
+    par[7] = h2OCTF;
+    par[8] = bl2OCTF;
+    par[9] = tl2OCTF;
+    par[10] = alp2OCTF;    
+    gMC->Gsvolu("SQ26","TRAP",idFrameEpoxy,par,11);
+    // EarthFaceCu trapezoid
+    par[0] = hzVFC;
+    par[1] = tetVFC;
+    par[2] = phiVFC;
+    par[3] = h1VFC;
+    par[4] = bl1VFC;
+    par[5] = tl1VFC;
+    par[6] = alp1VFC;
+    par[7] = h2VFC;
+    par[8] = bl2VFC;
+    par[9] = tl2VFC;
+    par[10] = alp2VFC;   
+    gMC->Gsvolu("SQ27","TRAP",idCopper,par,11);     
+
+    // VertEarthSteel trapezoid
+    par[0] = hzVES;
+    par[1] = tetVES;
+    par[2] = phiVES;
+    par[3] = h1VES;
+    par[4] = bl1VES;
+    par[5] = tl1VES;
+    par[6] = alp1VES;
+    par[7] = h2VES;
+    par[8] = bl2VES;
+    par[9] = tl2VES;
+    par[10] = alp2VES;    
+    gMC->Gsvolu("SQ28","TRAP",idInox,par,11); 
+
+    // VertEarthProfCu trapezoid       
+    par[0] = hzVPC;
+    par[1] = tetVPC;
+    par[2] = phiVPC;
+    par[3] = h1VPC;
+    par[4] = bl1VPC;
+    par[5] = tl1VPC;
+    par[6] = alp1VPC;
+    par[7] = h2VPC;
+    par[8] = bl2VPC;
+    par[9] = tl2VPC;
+    par[10] = alp2VPC;
+    gMC->Gsvolu("SQ29","TRAP",idCopper,par,11);
+
+    // SuppLateralPositionner cuboid    
+    par[0] = hxSLP;
+    par[1] = hySLP;
+    par[2] = hzSLP;
+    gMC->Gsvolu("SQ30","BOX",idAlu,par,3);
+
+    // LateralPositionerFace
+    par[0] = hxLPF;
+    par[1] = hyLPF;
+    par[2] = hzLPF;
+    gMC->Gsvolu("SQ31","BOX",idInox,par,3);
+
+    // LateralPositionerProfile
+    par[0] = hxLPP;
+    par[1] = hyLPP;
+    par[2] = hzLPP;
+    gMC->Gsvolu("SQ32","BOX",idInox,par,3); // middle layer
+    
+    par[0] = hxLPP;
+    par[1] = hyLPP;
+    par[2] = hzLPNF;
+    gMC->Gsvolu("SQ33","BOX",idInox,par,3); // near and far layers
+
+    // VertCradleA - 1st trapezoid
+    par[0] = hzVC1;
+    par[1] = tetVC1;
+    par[2] = phiVC1;
+    par[3] = h1VC1;
+    par[4] = bl1VC1;
+    par[5] = tl1VC1;
+    par[6] = alp1VC1;
+    par[7] = h2VC1;
+    par[8] = bl2VC1;
+    par[9] = tl2VC1;
+    par[10] = alp2VC1;
+    gMC->Gsvolu("SQ34","TRAP",idAlu,par,11); 
     
-// InVFrame  
+    // VertCradleB - 2nd trapezoid
+    par[0] = hzVC2;
+    par[1] = tetVC2;
+    par[2] = phiVC2;
+    par[3] = h1VC2;
+    par[4] = bl1VC2;
+    par[5] = tl1VC2;
+    par[6] = alp1VC2;
+    par[7] = h2VC2;
+    par[8] = bl2VC2;
+    par[9] = tl2VC2;
+    par[10] = alp2VC2;
+    gMC->Gsvolu("SQ35","TRAP",idAlu,par,11);  
+       
+    // VertCradleC - 3rd trapezoid
+    par[0] = hzVC3;
+    par[1] = tetVC3;
+    par[2] = phiVC3;
+    par[3] = h1VC3;
+    par[4] = bl1VC3;
+    par[5] = tl1VC3;
+    par[6] = alp1VC3;
+    par[7] = h2VC3;
+    par[8] = bl2VC3;
+    par[9] = tl2VC3;
+    par[10] = alp2VC3;    
+    gMC->Gsvolu("SQ36","TRAP",idAlu,par,11);  
+
+    // VertCradleD - 4th trapezoid
+    par[0] = hzVC4;
+    par[1] = tetVC4;
+    par[2] = phiVC4;
+    par[3] = h1VC4;
+    par[4] = bl1VC4;
+    par[5] = tl1VC4;
+    par[6] = alp1VC4;
+    par[7] = h2VC4;
+    par[8] = bl2VC4;
+    par[9] = tl2VC4;
+    par[10] = alp2VC4;    
+    gMC->Gsvolu("SQ37","TRAP",idAlu,par,11);  
+          
+    // LateralSightSupport trapezoid
+    par[0] = hzVSS;
+    par[1] = tetVSS;
+    par[2] = phiVSS;
+    par[3] = h1VSS;
+    par[4] = bl1VSS;
+    par[5] = tl1VSS;
+    par[6] = alp1VSS;
+    par[7] = h2VSS;
+    par[8] = bl2VSS;
+    par[9] = tl2VSS;
+    par[10] = alp2VSS;
+    gMC->Gsvolu("SQ38","TRAP",idAlu,par,11);
+
+    // LateralSight
+    par[0] = VSInRad;
+    par[1] = VSOutRad;
+    par[2] = VSLen;       
+    gMC->Gsvolu("SQ39","TUBE",idFrameEpoxy,par,3);   
+
+//---
+    // InHFrame
+    par[0] = hxInHFrame;
+    par[1] = hyInHFrame;
+    par[2] = hzInHFrame;
+    gMC->Gsvolu("SQ40","BOX",idFrameEpoxy,par,3);
+
+    //Flat 7.5mm horizontal section
+    par[0] = hxH1mm;
+    par[1] = hyH1mm;
+    par[2] = hzH1mm;
+    gMC->Gsvolu("SQ41","BOX",idFrameEpoxy,par,3);
+
+    // InArcFrame 
+    par[0] = IAF;
+    par[1] = OAF; 
+    par[2] = hzAF;  
+    par[3] = AFphi1; 
+    par[4] = AFphi2;
+
+    gMC->Gsvolu("SQ42","TUBS",idFrameEpoxy,par,5);
+
+//---
+    // ScrewsInFrame - 3 sections in order to avoid overlapping volumes
+    // Screw Head, in air
+    par[0] = SCRUHMI;
+    par[1] = SCRUHMA; 
+    par[2] = SCRUHLE;  
+
+    gMC->Gsvolu("SQ43","TUBE",idInox,par,3);
+    
+    // Middle part, in the Epoxy
+    par[0] = SCRUMMI;
+    par[1] = SCRUMMA;
+    par[2] = SCRUMLE;
+    gMC->Gsvolu("SQ44","TUBE",idInox,par,3);
+    
+    // Screw nut, in air
+    par[0] = SCRUNMI;
+    par[1] = SCRUNMA;
+    par[2] = SCRUNLE;   
+    gMC->Gsvolu("SQ45","TUBE",idInox,par,3);     
+   }
+              
+// __________________Place volumes in the quadrant ____________ 
+        
+    // InVFrame  
     posX = hxInVFrame;
     posY = 2.0*hyInHFrame+2.*hyH1mm+IAF+hyInVFrame;        
-    posZ = 0.;   
-    gMC->Gspos("IVEF",1,QuadrantName(chamber),posX, posY, posZ, 0, "ONLY"); 
+    posZ = 0.;
+    gMC->Gspos("SQ00",1,QuadrantMLayerName(chamber),posX, posY, posZ, 0, "ONLY"); 
 
-// InHFrame
-    posX = 2.0*hxInVFrame+2.*hxV1mm+IAF+hxInHFrame;
-    posY = hyInHFrame;
-    posZ = 0.;       
-    gMC->Gspos("IHEF",1,QuadrantName(chamber),posX, posY, posZ, 0, "ONLY"); 
+    //Flat 7.5mm vertical section
+    posX = 2.0*hxInVFrame+hxV1mm;
+    posY = 2.0*hyInHFrame+2.*hyH1mm+IAF+hyV1mm;
+    posZ = 0.;
+    gMC->Gspos("SQ01",1,QuadrantMLayerName(chamber),posX, posY, posZ,0, "ONLY"); 
+    
+    // TopFrameAnode place 2 layers of TopFrameAnode cuboids  
+    posX = hxTFA;
+    posY = 2.*hyInHFrame+2.*hyH1mm+IAF+2.*hyInVFrame+hyTFA;   
+    posZ = hzOuterFrameInox;
+    gMC->Gspos("SQ02",1,QuadrantMLayerName(chamber),posX, posY, posZ,0,"ONLY"); 
+    posZ = posZ+hzOuterFrameInox;
+    gMC->Gspos("SQ03",1,QuadrantMLayerName(chamber),posX, posY, posZ,0,"ONLY");
+    
+    // place 2 layers of TopFrameAnodeA trapezoids 
+    posX = 35.8932+fgkDeltaQuadLHC;
+    posY = 92.6745+fgkDeltaQuadLHC;
+    posZ = hzOuterFrameInox; 
+    gMC->Gspos("SQ04",1,QuadrantMLayerName(chamber),posX, posY, posZ, rot1,"ONLY");
+    posZ = posZ+hzOuterFrameInox;
+    gMC->Gspos("SQ05",1,QuadrantMLayerName(chamber),posX, posY, posZ, rot1,"ONLY");
+    
+    // place 2 layers of TopFrameAnodeB trapezoids 
+    posX = 44.593+fgkDeltaQuadLHC;
+    posY = 90.737+fgkDeltaQuadLHC;
+    posZ = hzOuterFrameInox; 
+    gMC->Gspos("SQ06",1,QuadrantMLayerName(chamber),posX, posY, posZ, rot1,"ONLY");
+    posZ = posZ+hzOuterFrameInox;
+    gMC->Gspos("SQ07",1,QuadrantMLayerName(chamber),posX, posY, posZ, rot1,"ONLY");    
+
+    // TopAnode1 place 2 layers  
+    posX = 6.8+fgkDeltaQuadLHC;
+    posY = 99.85+fgkDeltaQuadLHC;
+    posZ = -1.*hzAnodeFR4;
+    gMC->Gspos("SQ08",1,QuadrantMLayerName(chamber),posX, posY, posZ, 0,"ONLY");  
+    posZ = posZ+hzTopAnodeSteel1;
+    gMC->Gspos("SQ09",1,QuadrantMLayerName(chamber),posX, posY, posZ, 0,"ONLY");    
+         
+    // TopAnode2 place 2 layers
+    posX = 18.534+fgkDeltaQuadLHC;
+    posY = 99.482+fgkDeltaQuadLHC; 
+    posZ = -1.*hzAnodeFR4;    
+    gMC->Gspos("SQ10",1,QuadrantMLayerName(chamber),posX, posY, posZ, rot1,"ONLY");
+    posZ = posZ+hzTopAnodeSteel2;    
+    gMC->Gspos("SQ11",1,QuadrantMLayerName(chamber),posX, posY, posZ, rot1,"ONLY");       
+    
+    // TopAnode3 place 1 layer
+    posX = 25.80+fgkDeltaQuadLHC;
+    posY = 98.61+fgkDeltaQuadLHC;
+    posZ = 0.;    
+    gMC->Gspos("SQ12",1,QuadrantMLayerName(chamber),posX, posY, posZ, rot1,"ONLY");  
+          
+    // TopEarthFace - 2 copies
+    posX = 23.122+fgkDeltaQuadLHC;
+    posY = 96.90+fgkDeltaQuadLHC;
+    posZ = hzOuterFrameEpoxy+hzOuterFrameInox+hzTopEarthFaceCu;
+    gMC->Gspos("SQ13",1,QuadrantMLayerName(chamber),posX, posY, posZ, 0,"ONLY");
+    posZ = -1.*posZ;
+    gMC->Gspos("SQ13",2,QuadrantMLayerName(chamber),posX, posY, posZ, 0,"ONLY");
+
+    // TopEarthProfile 
+    posX = 14.475+fgkDeltaQuadLHC;
+    posY = 97.900+fgkDeltaQuadLHC; 
+    posZ = hzTopEarthProfileCu;
+    gMC->Gspos("SQ14",1,QuadrantMLayerName(chamber),posX, posY, posZ, 0,"ONLY");
+    posZ = -1.0*posZ;
+    gMC->Gspos("SQ14",2,QuadrantMLayerName(chamber),posX, posY, posZ, 0,"ONLY");
+
+    // TopGasSupport - 2 copies                            
+    posX = 4.9500+fgkDeltaQuadLHC;
+    posY = 96.200+fgkDeltaQuadLHC;
+    posZ = hzOuterFrameEpoxy+hzOuterFrameInox+hzTopGasSupportAl;
+    gMC->Gspos("SQ15",1,QuadrantMLayerName(chamber),posX, posY, posZ, 0,"ONLY");
+    posZ = -1.*posZ;
+    gMC->Gspos("SQ15",2,QuadrantMLayerName(chamber),posX, posY, posZ, 0,"ONLY");
+    
+    // TopPositioner parameters - single Stainless Steel trapezoid - 2 copies
+    posX = 7.60+fgkDeltaQuadLHC;
+    posY = 98.98+fgkDeltaQuadLHC;   
+    posZ = hzOuterFrameEpoxy+hzOuterFrameInox+2.*hzTopGasSupportAl+hzTopPositionerSteel;
+    gMC->Gspos("SQ16",1,QuadrantMLayerName(chamber),posX, posY, posZ, rot1,"ONLY");
+    posZ = -1.*posZ;
+    gMC->Gspos("SQ16",2,QuadrantMLayerName(chamber),posX, posY, posZ, rot1,"ONLY"); 
+
+    // OutEdgeFrame 
+    Float_t XCenter[8]; 
+    Float_t YCenter[8];
+    
+    XCenter[0] = 73.201 + fgkDeltaQuadLHC;
+    XCenter[1] = 78.124 + fgkDeltaQuadLHC; 
+    XCenter[2] = 82.862 + fgkDeltaQuadLHC;
+    XCenter[3] = 87.418 + fgkDeltaQuadLHC; 
+    
+    YCenter[0] = 68.122 + fgkDeltaQuadLHC;
+    YCenter[1] = 62.860 + fgkDeltaQuadLHC;   
+    YCenter[2] = 57.420 + fgkDeltaQuadLHC;
+    YCenter[3] = 51.800 + fgkDeltaQuadLHC; 
+      
+    XCenter[4] = 68.122 + fgkDeltaQuadLHC;
+    XCenter[5] = 62.860 + fgkDeltaQuadLHC; 
+    XCenter[6] = 57.420 + fgkDeltaQuadLHC;
+    XCenter[7] = 51.800 + fgkDeltaQuadLHC; 
+    
+    YCenter[4] = 73.210 + fgkDeltaQuadLHC;
+    YCenter[5] = 78.124 + fgkDeltaQuadLHC; 
+    YCenter[6] = 82.862 + fgkDeltaQuadLHC;
+    YCenter[7] = 87.418 + fgkDeltaQuadLHC; 
+      
+    posZ = -1.0*hzOuterFrameInox;     
+    gMC->Gspos("SQ17",1,QuadrantMLayerName(chamber), XCenter[0], YCenter[0], posZ, rot2,"ONLY");
+    gMC->Gspos("SQ17",2,QuadrantMLayerName(chamber), XCenter[4], YCenter[4], posZ, rot3,"ONLY");
+
+    gMC->Gspos("SQ19",1,QuadrantMLayerName(chamber), XCenter[1], YCenter[1], posZ, rot2,"ONLY");   
+    gMC->Gspos("SQ19",2,QuadrantMLayerName(chamber), XCenter[5], YCenter[5], posZ, rot3,"ONLY");
+
+    gMC->Gspos("SQ21",1,QuadrantMLayerName(chamber), XCenter[2], YCenter[2], posZ, rot2,"ONLY");
+    gMC->Gspos("SQ21",2,QuadrantMLayerName(chamber), XCenter[6], YCenter[6], posZ, rot3,"ONLY");
     
+    gMC->Gspos("SQ23",1,QuadrantMLayerName(chamber), XCenter[3], YCenter[3], posZ, rot2,"ONLY");
+    gMC->Gspos("SQ23",2,QuadrantMLayerName(chamber), XCenter[7], YCenter[7], posZ, rot3,"ONLY");
+     
+    posZ = posZ+hzOuterFrameEpoxy;
+   
+    gMC->Gspos("SQ18",1,QuadrantMLayerName(chamber), XCenter[0], YCenter[0], posZ, rot2,"ONLY");
+    gMC->Gspos("SQ18",2,QuadrantMLayerName(chamber), XCenter[4], YCenter[4], posZ, rot3,"ONLY");
+    
+    gMC->Gspos("SQ20",1,QuadrantMLayerName(chamber), XCenter[1], YCenter[1], posZ, rot2,"ONLY");   
+    gMC->Gspos("SQ20",2,QuadrantMLayerName(chamber), XCenter[5], YCenter[5], posZ, rot3,"ONLY");
+
+    gMC->Gspos("SQ22",1,QuadrantMLayerName(chamber), XCenter[2], YCenter[2], posZ, rot2,"ONLY");
+    gMC->Gspos("SQ22",2,QuadrantMLayerName(chamber), XCenter[6], YCenter[6], posZ, rot3,"ONLY");
+       
+    gMC->Gspos("SQ24",1,QuadrantMLayerName(chamber), XCenter[3], YCenter[3], posZ, rot2,"ONLY");
+    gMC->Gspos("SQ24",2,QuadrantMLayerName(chamber), XCenter[7], YCenter[7], posZ, rot3,"ONLY");  
+
+//---    
+        
 // OutVFrame
     posX = 2.*hxInVFrame+IAF+2.*hxInHFrame-hxOutVFrame+2.*hxV1mm;
     posY = 2.*hyInHFrame+hyOutVFrame;    
     posZ = 0.;              
-    gMC->Gspos("OVEF",1,QuadrantName(chamber),posX, posY, posZ, 0, "ONLY"); 
-//    cout << " Outer vertical frame at " << posX << " " << posY << " "
-//           << posZ << " and half length " << hyOutVFrame << endl;           
+    gMC->Gspos("SQ25",1,QuadrantMLayerName(chamber),posX, posY, posZ, 0, "ONLY"); 
+
     const Float_t TOPY = posY+hyOutVFrame;
     const Float_t OUTX = posX;
 
-//Flat 1mm vertical section
-    posX = 2.0*hxInVFrame+hxV1mm;
-    posY = 2.0*hyInHFrame+2.*hyH1mm+IAF+hyV1mm;
+// OutVFrame corner
+    posX = OUTX;
+    posY = TOPY+((bl1OCTF+tl1OCTF)/2.);
+    posZ = 0.;     
+    gMC->Gspos("SQ26",1,QuadrantMLayerName(chamber),posX, posY, posZ, rot1,"ONLY"); 
+
+// VertEarthFaceCu - 2 copies
+    posX = 89.4000+fgkDeltaQuadLHC;
+    posY = 25.79+fgkDeltaQuadLHC;    
+    posZ = hzFrameThickness+2.0*hzFoam+hzVertEarthFaceCu;              
+    gMC->Gspos("SQ27",1,QuadrantMLayerName(chamber),posX, posY, posZ, rot1, "ONLY"); 
+    posZ = -1.0*posZ; 
+    gMC->Gspos("SQ27",2,QuadrantMLayerName(chamber),posX, posY, posZ, rot1, "ONLY"); 
+    
+// VertEarthSteel - 2 copies
+    posX = 91.00+fgkDeltaQuadLHC;
+    posY = 30.616+fgkDeltaQuadLHC;    
+    posZ = hzFrameThickness+2.0*hzFoam+hzVertBarSteel;              
+    gMC->Gspos("SQ28",1,QuadrantMLayerName(chamber),posX, posY, posZ, rot1, "ONLY"); 
+    posZ = -1.0*posZ;              
+    gMC->Gspos("SQ28",2,QuadrantMLayerName(chamber),posX, posY, posZ, rot1, "ONLY");
+// VertEarthProfCu - 2 copies
+    posX = 92.000+fgkDeltaQuadLHC;
+    posY = 29.64+fgkDeltaQuadLHC;    
+    posZ = hzFrameThickness;              
+    gMC->Gspos("SQ29",1,QuadrantMLayerName(chamber),posX, posY, posZ, rot1, "ONLY"); 
+    posZ = -1.0*posZ;    
+    gMC->Gspos("SQ29",2,QuadrantMLayerName(chamber),posX, posY, posZ, rot1, "ONLY"); 
+
+// SuppLateralPositionner - 2 copies 
+    posX = 90.2-fgkNearFarLHC;
+    posY = 5.00-fgkNearFarLHC;    
+    posZ = hzLateralPosnAl-fgkMotherThick2;             
+    gMC->Gspos("SQ30",1,QuadrantFLayerName(chamber),posX, posY, posZ, 0, "ONLY"); 
+    posZ = -1.0*posZ;            
+    gMC->Gspos("SQ30",2,QuadrantNLayerName(chamber),posX, posY, posZ, 0, "ONLY"); 
+
+// LateralPositionner - 2 copies - Face view
+    posX = 92.175-fgkNearFarLHC-2.*hxLPP;
+    posY = 5.00-fgkNearFarLHC;   
+    posZ =2.0*hzLateralPosnAl+hzLateralPosnInoxFace-fgkMotherThick2;              
+    gMC->Gspos("SQ31",1,QuadrantFLayerName(chamber),posX, posY, posZ, 0, "ONLY"); 
+    posZ = -1.0*posZ;             
+    gMC->Gspos("SQ31",2,QuadrantNLayerName(chamber),posX, posY, posZ, 0, "ONLY"); 
+
+// LateralPositionner -  Profile view   
+    posX = 92.175+fgkDeltaQuadLHC+hxLPF-hxLPP;
+    posY = 5.00+fgkDeltaQuadLHC;    
+    posZ = 0.;              
+    gMC->Gspos("SQ32",1,QuadrantMLayerName(chamber),posX, posY, posZ, 0, "ONLY"); // middle layer
+
+    posX = 92.175-fgkNearFarLHC+hxLPF-hxLPP; 
+    posY = 5.0000-fgkNearFarLHC;    
+    posZ = fgkMotherThick2-hzLPNF;              
+    gMC->Gspos("SQ33",1,QuadrantNLayerName(chamber),posX, posY, posZ, 0, "ONLY"); // near layer
+    posZ = -1.*posZ;
+    gMC->Gspos("SQ33",2,QuadrantFLayerName(chamber),posX, posY, posZ, 0, "ONLY"); // far layer
+      
+// VertCradleA  1st Trapezoid - 3 copies
+    posX = 95.73+fgkDeltaQuadLHC;
+    posY = 33.26+fgkDeltaQuadLHC; 
+    posZ = 0.;              
+    gMC->Gspos("SQ34",2,QuadrantMLayerName(chamber),posX, posY, posZ, 0, "ONLY");  
+
+    posX = 95.73-fgkNearFarLHC;
+    posY = 33.26-fgkNearFarLHC;
+    posZ = 2.0*hzLateralSightAl+hzVerticalCradleAl-fgkMotherThick2;               
+    gMC->Gspos("SQ34",1,QuadrantNLayerName(chamber),posX, posY, posZ, 0, "ONLY");
+    posZ = -1.0*posZ;              
+    gMC->Gspos("SQ34",3,QuadrantFLayerName(chamber),posX, posY, posZ, 0, "ONLY");
+
+// VertCradleB  2nd Trapezoid - 3 copies
+    posX = 97.29+fgkDeltaQuadLHC;
+    posY = 23.02+fgkDeltaQuadLHC;    
+    posZ = 0.;              
+    gMC->Gspos("SQ35",2,QuadrantMLayerName(chamber),posX, posY, posZ, 0, "ONLY");
+
+    posX = 97.29-fgkNearFarLHC;
+    posY = 23.02-fgkNearFarLHC;   
+    posZ = 2.0*hzLateralSightAl+hzVerticalCradleAl-fgkMotherThick2;          
+    gMC->Gspos("SQ35",1,QuadrantNLayerName(chamber),posX, posY, posZ, 0, "ONLY");    
+    posZ = -1.0*posZ;          
+    gMC->Gspos("SQ35",3,QuadrantFLayerName(chamber),posX, posY, posZ, 0, "ONLY");
+
+// OutVertCradleC  3rd Trapeze - 3 copies
+    posX = 98.31+fgkDeltaQuadLHC;
+    posY = 12.77+fgkDeltaQuadLHC;  
+    posZ = 0.;              
+    gMC->Gspos("SQ36",2,QuadrantMLayerName(chamber),posX, posY, posZ, 0, "ONLY");
+
+    posX = 98.31-fgkNearFarLHC;
+    posY = 12.77-fgkNearFarLHC;        
+
+    posZ = 2.0*hzLateralSightAl+hzVerticalCradleAl-fgkMotherThick2;         
+    gMC->Gspos("SQ36",1,QuadrantNLayerName(chamber),posX, posY, posZ, 0, "ONLY");       
+    posZ = -1.0*posZ;
+    gMC->Gspos("SQ36",3,QuadrantFLayerName(chamber),posX, posY, posZ, 0, "ONLY");  
+
+// OutVertCradleD  4th Trapeze - 3 copies
+    posX = 98.81+fgkDeltaQuadLHC;
+    posY = 2.52+fgkDeltaQuadLHC;    
+    posZ = 0.;              
+    gMC->Gspos("SQ37",2,QuadrantMLayerName(chamber),posX, posY, posZ, 0, "ONLY");
+   
+    posZ = fgkMotherThick1-hzVerticalCradleAl;                
+    gMC->Gspos("SQ37",1,QuadrantMLayerName(chamber),posX, posY, posZ, 0, "ONLY");
+    posZ = -1.0*posZ;          
+    gMC->Gspos("SQ37",3,QuadrantMLayerName(chamber),posX, posY, posZ, 0, "ONLY");          
+             
+// LateralSightSupport - 2 copies
+    posX = 98.53-fgkNearFarLHC;
+    posY = 10.00-fgkNearFarLHC;    
+    posZ = hzLateralSightAl-fgkMotherThick2;
+    gMC->Gspos("SQ38",1,QuadrantNLayerName(chamber),posX, posY, posZ, 0, "ONLY"); 
+    posZ = -1.0*posZ;             
+    gMC->Gspos("SQ38",2,QuadrantFLayerName(chamber),posX, posY, posZ, 0, "ONLY"); 
+    
+// Mire placement
+    posX = 92.84+fgkDeltaQuadLHC;  
+    posY = 8.13+fgkDeltaQuadLHC;
     posZ = 0.;
-    gMC->Gspos("FVMM",1,QuadrantName(chamber),posX, posY, posZ,0, "ONLY"); 
+    gMC->Gspos("SQ39",1,QuadrantMLayerName(chamber),posX, posY, posZ, 0,"ONLY");    
+
+//---
+
+// InHFrame
+    posX = 2.0*hxInVFrame+2.*hxV1mm+IAF+hxInHFrame;
+    posY = hyInHFrame;
+    posZ = 0.;       
+    gMC->Gspos("SQ40",1,QuadrantMLayerName(chamber),posX, posY, posZ, 0, "ONLY"); 
  
-// Flat 1mm horizontal section
+// Flat 7.5mm horizontal section
     posX = 2.0*hxInVFrame+2.*hxV1mm+IAF+hxH1mm;
     posY = 2.0*hyInHFrame+hyH1mm;
     posZ = 0.;
-    gMC->Gspos("FHMM",1,QuadrantName(chamber),posX, posY, posZ,0, "ONLY"); 
+    gMC->Gspos("SQ41",1,QuadrantMLayerName(chamber),posX, posY, posZ,0, "ONLY"); 
         
 // InArcFrame 
     posX = 2.0*hxInVFrame+2.*hxV1mm;
     posY = 2.0*hyInHFrame+2.*hyH1mm;
     posZ = 0.;    
-    gMC->Gspos("IAF1",1,QuadrantName(chamber),posX, posY, posZ,0, "ONLY"); 
-
-    
-// ScrewsInFrame  
+    gMC->Gspos("SQ42",1,QuadrantMLayerName(chamber),posX, posY, posZ,0, "ONLY"); 
 
-// Only place screws that are inside the sensitive volume.
+// ScrewsInFrame - in sensitive volume
 
      Float_t scruX[64];
      Float_t scruY[64]; 
@@ -1039,22 +1805,22 @@ void AliMUONv2::CreateFrame(Int_t chamber)
      }    
      // Position the volumes on the frames
      for (Int_t i = 0;i<NumberOfScrewsIH;i++){
-     posX = BeamOX + scruX[i];
-     posY = BeamOY + scruY[i];
+     posX = fgkDeltaQuadLHC + scruX[i];
+     posY = fgkDeltaQuadLHC + scruY[i];
      posZ = 0.;   
-     gMC->Gspos("SCRH",i+1,QuadrantName(chamber),posX-QuadOX+0.1, posY-QuadOY+0.1, posZ-hzInHFrame-SCRUHLE, 0, "ONLY");      
-     gMC->Gspos("SCRM",i+1,QuadrantName(chamber),posX-QuadOX+0.1, posY-QuadOY+0.1, posZ, 0, "ONLY");
-     gMC->Gspos("SCRN",i+1,QuadrantName(chamber),posX-QuadOX+0.1, posY-QuadOY+0.1, posZ+hzInHFrame+SCRUNLE, 0, "ONLY"); 
+     gMC->Gspos("SQ43",i+1,QuadrantMLayerName(chamber),posX+0.1, posY+0.1, posZ-hzInHFrame-SCRUHLE, 0, "ONLY");      
+     gMC->Gspos("SQ44",i+1,QuadrantMLayerName(chamber),posX+0.1, posY+0.1, posZ, 0, "ONLY");
+     gMC->Gspos("SQ45",i+1,QuadrantMLayerName(chamber),posX+0.1, posY+0.1, posZ+hzInHFrame+SCRUNLE, 0, "ONLY"); 
      }
      // special screw coordinates
      scruX[63] = 16.3;  
      scruY[63] = -2.23; 
-     posX = BeamOX + scruX[63];
-     posY = BeamOY + scruY[63];
+     posX = fgkDeltaQuadLHC + scruX[63];
+     posY = fgkDeltaQuadLHC + scruY[63];
      posZ = 0.;            
-     gMC->Gspos("SCRH",64,QuadrantName(chamber),posX-QuadOX+0.1, posY-QuadOY+0.1, posZ-hzInHFrame-SCRUHLE, 0, "ONLY");
-     gMC->Gspos("SCRM",64,QuadrantName(chamber),posX-QuadOX+0.1, posY-QuadOY+0.1, posZ, 0, "ONLY"); 
-     gMC->Gspos("SCRN",64,QuadrantName(chamber),posX-QuadOX+0.1, posY-QuadOY+0.1, posZ+hzInHFrame+SCRUNLE, 0, "ONLY");  
+     gMC->Gspos("SQ43",64,QuadrantMLayerName(chamber),posX+0.1, posY+0.1, posZ-hzInHFrame-SCRUHLE, 0, "ONLY");
+     gMC->Gspos("SQ44",64,QuadrantMLayerName(chamber),posX+0.1, posY+0.1, posZ, 0, "ONLY"); 
+     gMC->Gspos("SQ45",64,QuadrantMLayerName(chamber),posX+0.1, posY+0.1, posZ+hzInHFrame+SCRUNLE, 0, "ONLY");  
      
 // Screws on the IVEpoxyFrame
   
@@ -1076,12 +1842,12 @@ void AliMUONv2::CreateFrame(Int_t chamber)
     }
     
     for (Int_t i = 0;i<NumberOfScrewsIV;i++){
-    posX = BeamOX + scruX[i+LastScrew-1];
-    posY = BeamOY + scruY[i+LastScrew-1];
+    posX = fgkDeltaQuadLHC + scruX[i+LastScrew-1];
+    posY = fgkDeltaQuadLHC + scruY[i+LastScrew-1];
     posZ = 0.;       
-    gMC->Gspos("SCRH",i+LastScrew,QuadrantName(chamber),posX-QuadOX+0.1, posY-QuadOY+0.1, posZ-hzInHFrame-SCRUHLE, 0, "ONLY");     
-    gMC->Gspos("SCRM",i+LastScrew,QuadrantName(chamber),posX-QuadOX+0.1, posY-QuadOY+0.1, posZ, 0, "ONLY"); 
-    gMC->Gspos("SCRN",i+LastScrew,QuadrantName(chamber),posX-QuadOX+0.1, posY-QuadOY+0.1, posZ+hzInHFrame+SCRUNLE, 0, "ONLY");
+    gMC->Gspos("SQ43",i+LastScrew,QuadrantMLayerName(chamber),posX+0.1, posY+0.1, posZ-hzInHFrame-SCRUHLE, 0, "ONLY");     
+    gMC->Gspos("SQ44",i+LastScrew,QuadrantMLayerName(chamber),posX+0.1, posY+0.1, posZ, 0, "ONLY"); 
+    gMC->Gspos("SQ45",i+LastScrew,QuadrantMLayerName(chamber),posX+0.1, posY+0.1, posZ+hzInHFrame+SCRUNLE, 0, "ONLY");
     }    
     
 // Screws on the OVEpoxyFrame
@@ -1101,12 +1867,12 @@ void AliMUONv2::CreateFrame(Int_t chamber)
     scruY[i] = scruY[i-1]+offY;
     }
     for (Int_t i = 0;i<NumberOfScrewsOV;i++){
-    posX = BeamOX + scruX[i+FirstScrew-1];
-    posY = BeamOY + scruY[i+FirstScrew-1];
+    posX = fgkDeltaQuadLHC + scruX[i+FirstScrew-1];
+    posY = fgkDeltaQuadLHC + scruY[i+FirstScrew-1];
     posZ = 0.;   
-    gMC->Gspos("SCRH",i+FirstScrew,QuadrantName(chamber),posX-QuadOX+0.1, posY-QuadOY+0.1, posZ-hzInHFrame-SCRUHLE, 0, "ONLY");     
-    gMC->Gspos("SCRM",i+FirstScrew,QuadrantName(chamber),posX-QuadOX+0.1, posY-QuadOY+0.1, posZ, 0, "ONLY"); 
-    gMC->Gspos("SCRN",i+FirstScrew,QuadrantName(chamber),posX-QuadOX+0.1, posY-QuadOY+0.1, posZ+hzInHFrame+SCRUNLE, 0, "ONLY"); 
+    gMC->Gspos("SQ43",i+FirstScrew,QuadrantMLayerName(chamber),posX+0.1, posY+0.1, posZ-hzInHFrame-SCRUHLE, 0, "ONLY");     
+    gMC->Gspos("SQ44",i+FirstScrew,QuadrantMLayerName(chamber),posX+0.1, posY+0.1, posZ, 0, "ONLY"); 
+    gMC->Gspos("SQ45",i+FirstScrew,QuadrantMLayerName(chamber),posX+0.1, posY+0.1, posZ+hzInHFrame+SCRUNLE, 0, "ONLY"); 
     }
       
 // Inner Arc of Frame, screw positions and numbers-1
@@ -1117,437 +1883,553 @@ void AliMUONv2::CreateFrame(Int_t chamber)
    scruX[58] = 1.401 ; scruY[58]  = 16.009;
     
     for (Int_t i = 0;i<5;i++){
-    posX = BeamOX + scruX[i+58];
-    posY = BeamOY + scruY[i+58];
+    posX = fgkDeltaQuadLHC + scruX[i+58];
+    posY = fgkDeltaQuadLHC + scruY[i+58];
     posZ = 0.;   
-    gMC->Gspos("SCRH",i+58+1,QuadrantName(chamber),posX-QuadOX+0.1, posY-QuadOY+0.1, posZ-hzInHFrame-SCRUHLE, 0, "ONLY");    
-    gMC->Gspos("SCRM",i+58+1,QuadrantName(chamber),posX-QuadOX+0.1, posY-QuadOY+0.1, posZ, 0, "ONLY");
-    gMC->Gspos("SCRN",i+58+1,QuadrantName(chamber),posX-QuadOX+0.1, posY-QuadOY+0.1, posZ+hzInHFrame+SCRUNLE, 0, "ONLY");
-    }  
-
-// OutTopTrapFrame   
-    posX = hxOutHFrame;
-    posY = 2.*hyInHFrame+IAF+2.*hyInVFrame+hyOutHFrame+2.*hyH1mm;
-    posZ = 0.;
-
-// place 3 layers of cuboids    
-    posZ = posZ-(hzOuterFrameSolder+hzOuterFrameInox);
-    gMC->Gspos("OHEA",1,QuadrantName(chamber),posX, posY, posZ,0,"ONLY"); 
-    posZ = posZ+hzOuterFrameInox+hzOuterFrameSolder;
-    gMC->Gspos("OHSA",1,QuadrantName(chamber),posX, posY, posZ,0,"ONLY");
-    posZ = posZ+hzOuterFrameSolder+hzOuterFrameInox;
-    gMC->Gspos("OHIA",1,QuadrantName(chamber),posX, posY, posZ,0,"ONLY");
-    
-// place 3 layers of trapezoid A
-    posX = 34.1663+2.6;
-    posY = 92.2946+2.6;
-    posZ = 0.; 
-    
-    posZ = posZ-(hzOuterFrameSolder+hzOuterFrameInox); 
-    gMC->Gspos("OHEB",1,QuadrantName(chamber),posX, posY, posZ, idrotm[1102],"ONLY"); 
-    posZ = posZ+hzOuterFrameInox+hzOuterFrameSolder;
-    gMC->Gspos("OHSB",1,QuadrantName(chamber),posX, posY, posZ, idrotm[1102],"ONLY");
-    posZ = posZ+hzOuterFrameSolder+hzOuterFrameInox;
-    gMC->Gspos("OHIB",1,QuadrantName(chamber),posX, posY, posZ, idrotm[1102],"ONLY");
-    
-// place 3 layers of trapezoid B
-    posX = 43.8379+2.6;
-    posY = 90.1946+2.6;
-    posZ = 0.; 
-    
-    posZ = posZ-(hzOuterFrameSolder+hzOuterFrameInox); 
-    gMC->Gspos("OHEC",1,QuadrantName(chamber),posX, posY, posZ, idrotm[1102],"ONLY"); 
-    posZ = posZ+hzOuterFrameInox+hzOuterFrameSolder;
-    gMC->Gspos("OHSC",1,QuadrantName(chamber),posX, posY, posZ, idrotm[1102],"ONLY");
-    posZ = posZ+hzOuterFrameSolder+hzOuterFrameInox;
-    gMC->Gspos("OHIC",1,QuadrantName(chamber),posX, posY, posZ, idrotm[1102],"ONLY");    
-              
-///////////////////////////////////////////////////             
-        
-// OutEdgeTrapFrame  
-    const Float_t refY = 70.13685;
-    const Float_t refX = 71.43685;
-    
-    posX = refX;
-    posY = refY;
-    posZ = 0.; 
-    
-    Float_t XCenter[8]; 
-    Float_t YCenter[8];
-    
-    XCenter[0] = 72.7099 + 2.6;
-    XCenter[1] = 77.5787 + 2.6; 
-    XCenter[2] = 82.2732 + 2.6;
-    XCenter[3] = 86.7882 + 2.6; 
-    
-    YCenter[0] = 67.6691 + 2.6;
-    YCenter[1] = 62.4564 + 2.6; 
-    YCenter[2] = 57.0693 + 2.6;
-    YCenter[3] = 51.5027 + 2.6; 
-      
-    XCenter[4] = 67.6691 + 2.6;
-    XCenter[5] = 62.4564 + 2.6; 
-    XCenter[6] = 57.0693 + 2.6;
-    XCenter[7] = 51.5027 + 2.6; 
-    
-    YCenter[4] = 72.7099 + 2.6;
-    YCenter[5] = 77.5787 + 2.6; 
-    YCenter[6] = 82.2732 + 2.6;
-    YCenter[7] = 86.7882 + 2.6; 
-      
-    posZ = posZ-(hzOuterFrameSolder+hzOuterFrameInox);     
-    gMC->Gspos("EDE1",1,QuadrantName(chamber), XCenter[0], YCenter[0], posZ, idrotm[1104],"ONLY");
-    gMC->Gspos("EDE1",2,QuadrantName(chamber), XCenter[4], YCenter[4],posZ, idrotm[1105],"ONLY");
-
-
-    gMC->Gspos("EDE2",1,QuadrantName(chamber), XCenter[1], YCenter[1], posZ, idrotm[1104],"ONLY");   
-    gMC->Gspos("EDE2",2,QuadrantName(chamber), XCenter[5], YCenter[5], posZ, idrotm[1105],"ONLY");
-
-    gMC->Gspos("EDE3",1,QuadrantName(chamber), XCenter[2], YCenter[2], posZ, idrotm[1104],"ONLY");
-    gMC->Gspos("EDE3",2,QuadrantName(chamber), XCenter[6], YCenter[6], posZ, idrotm[1105],"ONLY");
-    
-    
-    gMC->Gspos("EDE4",1,QuadrantName(chamber), XCenter[3], YCenter[3], posZ, idrotm[1104],"ONLY");
-    gMC->Gspos("EDE4",2,QuadrantName(chamber), XCenter[7], YCenter[7], posZ, idrotm[1105],"ONLY");          
-
+    gMC->Gspos("SQ43",i+58+1,QuadrantMLayerName(chamber),posX+0.1, posY+0.1, posZ-hzInHFrame-SCRUHLE, 0, "ONLY");    
+    gMC->Gspos("SQ44",i+58+1,QuadrantMLayerName(chamber),posX+0.1, posY+0.1, posZ, 0, "ONLY");
+    gMC->Gspos("SQ45",i+58+1,QuadrantMLayerName(chamber),posX+0.1, posY+0.1, posZ+hzInHFrame+SCRUNLE, 0, "ONLY");
+    }
+}
 
-     
-    posZ = posZ+hzOuterFrameEpoxy+hzOuterFrameInox;
-     
-    gMC->Gspos("EDI1",1,QuadrantName(chamber), XCenter[0], YCenter[0], posZ, idrotm[1104],"ONLY");
-    gMC->Gspos("EDI1",2,QuadrantName(chamber), XCenter[4], YCenter[4], posZ, idrotm[1105],"ONLY");
-    
-    gMC->Gspos("EDI2",1,QuadrantName(chamber), XCenter[1], YCenter[1], posZ, idrotm[1104],"ONLY");   
-    gMC->Gspos("EDI2",2,QuadrantName(chamber), XCenter[5], YCenter[5], posZ, idrotm[1105],"ONLY");
+//______________________________________________________________________________
+void AliMUONv2::PlaceInnerLayers(Int_t chamber)
+{
+// Place the gas and copper layers for the specified chamber.
+// --
 
-    gMC->Gspos("EDI3",1,QuadrantName(chamber), XCenter[2], YCenter[2], posZ, idrotm[1104],"ONLY");
-    gMC->Gspos("EDI3",2,QuadrantName(chamber), XCenter[6], YCenter[6], posZ, idrotm[1105],"ONLY");
-       
-    gMC->Gspos("EDI4",1,QuadrantName(chamber), XCenter[3], YCenter[3], posZ, idrotm[1104],"ONLY");
-    gMC->Gspos("EDI4",2,QuadrantName(chamber), XCenter[7], YCenter[7], posZ, idrotm[1105],"ONLY");  
-           
+// Rotation Matrices 
+  Int_t rot1, rot2, rot3, rot4;   
 
-    posZ = posZ+hzOuterFrameInox+hzOuterFrameSolder;
-       
-    gMC->Gspos("EDS1",1,QuadrantName(chamber), XCenter[0], YCenter[0], posZ, idrotm[1104],"ONLY");
-    gMC->Gspos("EDS1",2,QuadrantName(chamber), XCenter[4], YCenter[4], posZ, idrotm[1105],"ONLY");
-    
-    gMC->Gspos("EDS2",1,QuadrantName(chamber), XCenter[1], YCenter[1], posZ, idrotm[1104],"ONLY");   
-    gMC->Gspos("EDS2",2,QuadrantName(chamber), XCenter[5], YCenter[5], posZ, idrotm[1105],"ONLY");
+  AliMatrix(rot1,  90., 315., 90.,  45., 0., 0.); // -45 deg
+  AliMatrix(rot2,  90.,  90., 90., 180., 0., 0.); //  90 deg
+  AliMatrix(rot3,  90., 270., 90.,   0., 0., 0.); // -90 deg 
+  AliMatrix(rot4,  90.,  45., 90., 135., 0., 0.); //  deg 
 
-    gMC->Gspos("EDS3",1,QuadrantName(chamber), XCenter[2], YCenter[2], posZ, idrotm[1104],"ONLY");
-    gMC->Gspos("EDS3",2,QuadrantName(chamber), XCenter[6], YCenter[6], posZ, idrotm[1105],"ONLY");
-       
-    gMC->Gspos("EDS4",1,QuadrantName(chamber), XCenter[3], YCenter[3], posZ, idrotm[1104],"ONLY");
-    gMC->Gspos("EDS4",2,QuadrantName(chamber), XCenter[7], YCenter[7], posZ, idrotm[1105],"ONLY");  
-    
+  GReal_t x;
+  GReal_t y;
+  GReal_t zg = 0.;
+  GReal_t zc = fgkHzGas + fgkHzPadPlane;
+  Int_t dpos = (chamber-1)*2;
+  TString name;
   
-// OutCornerTrapFrame  
-    posX = OUTX;
-    posY = TOPY+((bl1OCTF+tl1OCTF)/2.);
-    posZ = 0.;     
-    gMC->Gspos("TCOR",1,QuadrantName(chamber),posX, posY, posZ, idrotm[1102],"ONLY"); 
-    
-// Mire placement
-    posX = OUTX+hxOutVFrame+1.3;
-    posY = 8.13+2.6;
-    posZ = 0.;
-   gMC->Gspos("MIRE",1,QuadrantName(chamber),posX, posY, posZ, 0,"ONLY");
-    
+  x = 14.53 + fgkDeltaQuadLHC;
+  y = 53.34 + fgkDeltaQuadLHC;
+  name = GasVolumeName("SAG", chamber);
+  gMC->Gspos(name,1,QuadrantMLayerName(chamber),x,y,zg,0,"ONLY");
+  gMC->Gspos("SA1C", 1+dpos, QuadrantMLayerName(chamber),x,y, zc,0,"ONLY");
+  gMC->Gspos("SA1C", 2+dpos, QuadrantMLayerName(chamber),x,y,-zc,0,"ONLY");
+
+  x = 40.67 + fgkDeltaQuadLHC;
+  y = 40.66 + fgkDeltaQuadLHC;    
+  name = GasVolumeName("SBG", chamber);
+  gMC->Gspos(name,1,QuadrantMLayerName(chamber),x,y,zg,rot1,"ONLY"); 
+  gMC->Gspos("SB1C", 1+dpos ,QuadrantMLayerName(chamber),x,y, zc,rot1,"ONLY");
+  gMC->Gspos("SB1C", 2+dpos, QuadrantMLayerName(chamber),x,y,-zc,rot1,"ONLY");
+
+  x = 53.34 + fgkDeltaQuadLHC;
+  y = 14.52 + fgkDeltaQuadLHC; 
+  name = GasVolumeName("SCG", chamber);
+  gMC->Gspos(name,1,QuadrantMLayerName(chamber),x,y,zg,rot2,"ONLY");
+  gMC->Gspos("SC1C", 1+dpos ,QuadrantMLayerName(chamber),x,y, zc,rot2,"ONLY");
+  gMC->Gspos("SC1C", 2+dpos ,QuadrantMLayerName(chamber),x,y,-zc,rot2,"ONLY");
+
+  x = 5.83 + fgkDeltaQuadLHC;
+  y = 17.29 + fgkDeltaQuadLHC;
+  name = GasVolumeName("SDG", chamber);
+  gMC->Gspos(name,1,QuadrantMLayerName(chamber),x,y,zg,rot3,"ONLY");
+  gMC->Gspos("SD1C", 1+dpos ,QuadrantMLayerName(chamber),x,y, zc,rot3,"ONLY");
+  gMC->Gspos("SD1C", 2+dpos ,QuadrantMLayerName(chamber),x,y,-zc,rot3,"ONLY");
+
+  x = 9.04 + fgkDeltaQuadLHC;
+  y = 16.91 + fgkDeltaQuadLHC; 
+  name = GasVolumeName("SEG", chamber);
+  gMC->Gspos(name,1,QuadrantMLayerName(chamber),x,y,zg,0,"ONLY");
+  gMC->Gspos("SE1C", 1+dpos ,QuadrantMLayerName(chamber),x,y, zc,0,"ONLY");
+  gMC->Gspos("SE1C", 2+dpos ,QuadrantMLayerName(chamber),x,y,-zc,0,"ONLY");
+
+  x = 10.12 + fgkDeltaQuadLHC;
+  y = 14.67 + fgkDeltaQuadLHC;  
+  name = GasVolumeName("SFG", chamber);
+  gMC->Gspos(name,1,QuadrantMLayerName(chamber),x,y,zg,rot4,"ONLY");   
+  gMC->Gspos("SF1C", 1+dpos ,QuadrantMLayerName(chamber),x,y, zc,rot4,"ONLY");
+  gMC->Gspos("SF1C", 2+dpos ,QuadrantMLayerName(chamber),x,y,-zc,rot4,"ONLY");
+
+  x = 8.2042 + fgkDeltaQuadLHC;
+  y = 16.19 + fgkDeltaQuadLHC;
+  name = GasVolumeName("SGG", chamber);
+  gMC->Gspos(name,1,QuadrantMLayerName(chamber),x,y,zg,rot4,"ONLY");
+  gMC->Gspos("SG1C", 1+dpos ,QuadrantMLayerName(chamber),x,y, zc,rot4,"ONLY");
+  gMC->Gspos("SG1C", 2+dpos ,QuadrantMLayerName(chamber),x,y,-zc,rot4,"ONLY");
+
+  x = 14.68 + fgkDeltaQuadLHC;
+  y = 10.10 + fgkDeltaQuadLHC;
+  name = GasVolumeName("SHG", chamber);
+  gMC->Gspos(name,1,QuadrantMLayerName(chamber),x,y,zg,rot4,"ONLY");
+  gMC->Gspos("SH1C", 1+dpos ,QuadrantMLayerName(chamber),x,y, zc,rot4,"ONLY");
+  gMC->Gspos("SH1C", 2+dpos ,QuadrantMLayerName(chamber),x,y,-zc,rot4,"ONLY");
+
+  x = 16.21 + fgkDeltaQuadLHC;
+  y = 8.17 + fgkDeltaQuadLHC;
+  name = GasVolumeName("SIG", chamber);
+  gMC->Gspos(name,1,QuadrantMLayerName(chamber),x,y,zg,rot4,"ONLY");
+  gMC->Gspos("SI1C", 1+dpos ,QuadrantMLayerName(chamber),x,y, zc,rot4,"ONLY");
+  gMC->Gspos("SI1C", 2+dpos ,QuadrantMLayerName(chamber),x,y,-zc,rot4,"ONLY");
+
+  x = 16.92 + fgkDeltaQuadLHC;
+  y = 9.02 + fgkDeltaQuadLHC;
+  name = GasVolumeName("SJG", chamber);
+  gMC->Gspos(name,1,QuadrantMLayerName(chamber),x,y,zg,rot3,"ONLY");
+  gMC->Gspos("SJ1C", 1+dpos ,QuadrantMLayerName(chamber),x,y, zc,rot3,"ONLY");
+  gMC->Gspos("SJ1C", 2+dpos ,QuadrantMLayerName(chamber),x,y,-zc,rot3,"ONLY");
+
+  x =  17.30 + fgkDeltaQuadLHC;
+  y =  5.85 + fgkDeltaQuadLHC;
+  name = GasVolumeName("SKG", chamber);
+  gMC->Gspos(name,1,QuadrantMLayerName(chamber),x,y,zg,0,"ONLY");
+  gMC->Gspos("SK1C", 1+dpos ,QuadrantMLayerName(chamber),x,y, zc,0,"ONLY");
+  gMC->Gspos("SK1C", 2+dpos ,QuadrantMLayerName(chamber),x,y,-zc,0,"ONLY");
 }
 
-//___________________________________________
-void AliMUONv2::CreateHole()
+//______________________________________________________________________________
+void AliMUONv2::PlaceSector(AliMpSector* sector,TSpecialMap specialMap, 
+                            const TVector3& where, Bool_t reflectZ, Int_t chamber)
 {
-// Create all the element inside a foam hole
+// Place all the segments in the mother volume, at the position defined
+// by the sector's data.
 // --
-  Int_t* idtmed = fIdtmed->GetArray()-1099;
-  Int_t idAir  = idtmed[1100]; // medium 1
-  Int_t idCopper  = idtmed[1109]; // medium 10 = copper
 
-  GReal_t par[3];
+  static Int_t segNum=1;
+  Int_t sgn;
+  Int_t reflZ;
+  Int_t rotMat;
+
+  if (!reflectZ) {
+    sgn= 1;
+    reflZ=0;                                     // no reflection along z... nothing
+    AliMatrix(rotMat,  90.,90.,90,180.,0.,0.);   // 90° rotation around z, NO reflection along z
+  } else  {
+    sgn=-1;
+    AliMatrix(reflZ,  90.,0.,90,90.,180.,0.);    // reflection along z
+    AliMatrix(rotMat,  90.,90.,90,180.,180.,0.); // 90° rotation around z AND reflection along z
+  }
+  
   GReal_t posX,posY,posZ;
   
-  par[0] = fgkHxHole;
-  par[1] = fgkHyHole;
-  par[2] = fgkHzFoam;
-  gMC->Gsvolu(fgkHoleName,"BOX",idAir,par,3);
+  IntVector already_done;
+  for (Int_t irow=0;irow<sector->GetNofRows();irow++){ // for each row
+    AliMpRow* row = sector->GetRow(irow);
 
-  par[0] = fgkHxKapton;
-  par[1] = fgkHyKapton;
-  par[2] = fgkHzSnPb;
-  gMC->Gsvolu("SNPB", "BOX", idCopper, par, 3);
-  posX = 0.;
-  posY = 0.;
-  posZ = -fgkHzFoam+fgkHzSnPb;
-  gMC->Gspos("SNPB",1,fgkHoleName, posX, posY, posZ, 0,"ONLY");
 
-  par[0] = fgkHxHole;
-  par[1] = fgkHyBergPlastic;
-  par[2] = fgkHzKapton;
-  gMC->Gsvolu("KAPT", "BOX", idCopper, par, 3);
-  posX = 0.;
-  posY = 0.;
-  posZ = 0.;
-  gMC->Gspos("KAPT",1,fgkHoleName, posX, posY, posZ, 0,"ONLY");
-}
+    for (Int_t iseg=0;iseg<row->GetNofRowSegments();iseg++){ // for each row segment
+      AliMpVRowSegment* seg = row->GetRowSegment(iseg);
+      char segName[5];
+      
+      TSpecialMap::iterator iter 
+        = specialMap.find(seg->GetMotifPositionId(0));
 
-//___________________________________________
-void AliMUONv2::CreateDaughterBoard()
+      if ( iter == specialMap.end()){ //if this is a normal segment (ie. not part of <specialMap>)
+      
+        // create the cathode part
+        sprintf(segName,"%.3dM", segNum);
+        CreatePlaneSegment(segName, seg->Dimensions()/10., seg->GetNofMotifs());
+  
+        posX = where.X() + seg->Position().X()/10.;
+        posY = where.Y() + seg->Position().Y()/10.;
+        posZ = where.Z() + sgn * (TotalHzPlane() + fgkHzGas + 2.*fgkHzPadPlane);
+        gMC->Gspos(segName, 1, QuadrantMLayerName(chamber), posX, posY, posZ, reflZ, "ONLY");
+
+        // and place all the daughter boards of this segment
+        for (Int_t motifNum=0;motifNum<seg->GetNofMotifs();motifNum++) {
+          Int_t motifPosId = seg->GetMotifPositionId(motifNum);
+          AliMpMotifPosition* motifPos = 
+            sector->GetMotifMap()->FindMotifPosition(motifPosId);
+  
+          posX = where.X() + motifPos->Position().X()/10.+fgkOffsetX;
+          posY = where.Y() + motifPos->Position().Y()/10.+fgkOffsetY;
+         posZ = where.Z() + sgn * (fgkMotherThick1 - TotalHzDaughter()); 
+          gMC->Gspos(fgkDaughterName, motifPosId, QuadrantMLayerName(chamber), posX, posY, posZ, reflZ, "ONLY");
+        }  
+        segNum++;
+       
+      } else { 
+
+        // if this is a special segment        
+        for (Int_t motifNum=0;motifNum<seg->GetNofMotifs();motifNum++) {// for each motif
+
+          Int_t motifPosId = seg->GetMotifPositionId(motifNum);
+          
+          if (find(already_done.begin(),already_done.end(),motifPosId)
+              != already_done.end()) continue; // don't treat the same motif twice
+          
+          AliMUONSt1SpecialMotif spMot = specialMap[motifPosId];
+          AliMpMotifPosition* motifPos = sector->GetMotifMap()->FindMotifPosition(motifPosId);
+
+          // place the hole for the motif, wrt the requested rotation angle
+          Int_t rot = ( spMot.GetRotAngle()<0.1 ) ? reflZ:rotMat;
+
+          posX = where.X() + motifPos->Position().X()/10.+spMot.GetDelta().X();
+          posY = where.Y() + motifPos->Position().Y()/10.+spMot.GetDelta().Y();
+          posZ = where.Z() + sgn * (TotalHzPlane() + fgkHzGas + 2.*fgkHzPadPlane);
+          gMC->Gspos(fgkHoleName, motifPosId, QuadrantMLayerName(chamber), posX, posY, posZ, rot, "ONLY");
+
+          // then place the daughter board for the motif, wrt the requested rotation angle
+          posX = posX+fgkDeltaFilleEtamX;
+          posY = posY+fgkDeltaFilleEtamY;
+         posZ = where.Z() + sgn * (fgkMotherThick1 - TotalHzDaughter()); 
+          gMC->Gspos(fgkDaughterName, motifPosId, QuadrantMLayerName(chamber), posX, posY, posZ, rot, "ONLY");
+
+          already_done.push_back(motifPosId);// mark this motif as done
+       }               
+      }// end of special motif case
+    }
+  }
+} 
+
+//______________________________________________________________________________
+TString AliMUONv2::GasVolumeName(const TString& name, Int_t chamber) const
 {
-// Create all the elements in a daughter board
-// --
-  Int_t* idtmed = fIdtmed->GetArray()-1099;
-  Int_t idAir  = idtmed[1100]; // medium 1
-  Int_t idCopper  = idtmed[1109]; // medium 10 = copper
-  Int_t idPlastic  =idtmed[1116]; // medium 17 = Plastic
+// Inserts the chamber number into the name.
+// ---
 
-  GReal_t par[3];
-  GReal_t posX,posY,posZ;
+  TString newString(name);
+  TString number(""); 
+  number += chamber;
 
-  par[0]=fgkHxDaughter;
-  par[1]=fgkHyDaughter;
-  par[2]=totalHzDaughter();
-  gMC->Gsvolu(fgkDaughterName,"BOX",idAir,par,3);
+  newString.Insert(2, number);
   
-  par[0]=fgkHxBergPlastic;
-  par[1]=fgkHyBergPlastic;
-  par[2]=fgkHzBergPlastic;
-  gMC->Gsvolu("BRGP","BOX",idPlastic,par,3);
-  posX=0.;
-  posY=0.;
-  posZ = -totalHzDaughter() + fgkHzBergPlastic;
-  gMC->Gspos("BRGP",1,fgkDaughterName,posX,posY,posZ,0,"ONLY");
-
-  par[0]=fgkHxBergCopper;
-  par[1]=fgkHyBergCopper;
-  par[2]=fgkHzBergCopper;
-  gMC->Gsvolu("BRGC","BOX",idCopper,par,3);
-  posX=0.;
-  posY=0.;
-  posZ=0.;
-  gMC->Gspos("BRGC",1,"BRGC",posX,posY,posZ,0,"ONLY");
-
-  par[0]=fgkHxDaughter;
-  par[1]=fgkHyDaughter;
-  par[2]=fgkHzDaughter;
-  gMC->Gsvolu("DGHT","BOX",idCopper,par,3);
-  posX=0.;
-  posY=0.;
-  posZ = -totalHzDaughter() + 2.*fgkHzBergPlastic + fgkHzDaughter;
-  gMC->Gspos("DGHT",1,fgkDaughterName,posX,posY,posZ,0,"ONLY");
+  return newString;
 }
 
-//___________________________________________
-void AliMUONv2::CreatePlaneBox(const char* name,const  TVector2& dimensions)
+//______________________________________________________________________________
+Bool_t AliMUONv2::IsInChamber(Int_t ich, Int_t volGid) const
 {
-// create all the elements in the copper plane
-// --
-  Int_t* idtmed = fIdtmed->GetArray()-1099;
-  Int_t idAir  = idtmed[1100]; // medium 1
-  Int_t idCopper  = idtmed[1109]; // medium 10 = copper
-  Int_t idFoam = idtmed[1115]; // medium 16 = Foam
-  Int_t idFR4 =idtmed[1114]; // medium 15 = FR4
+// True if volume <volGid> is part of the sensitive 
+// volumes of chamber <ich> 
+// ---
+  for (Int_t i = 0; i < fChamberV2[ich]->GetSize(); i++) {
+      if (fChamberV2[ich]->At(i) == volGid) return kTRUE;
+  }
+  return kFALSE;
+}
 
-  GReal_t par[3];
-  GReal_t posX,posY,posZ;
+//
+// protected methods
+//
 
-  // mother volume
-  par[0] = dimensions.X();
-  par[1] = dimensions.Y();
-  par[2] = totalHzPlane();
-  gMC->Gsvolu(name,"BOX",idAir,par,3);
-  
-  // pad plane
-  char* planeName = strdup(name);
-  planeName[3]='P';
-  par[0] = dimensions.X();
-  par[1] = dimensions.Y();
-  par[2] = fgkHzPadPlane;
-  gMC->Gsvolu(planeName,"BOX",idCopper,par,3);
-  posX=0.;
-  posY=0.;
-  posZ = -totalHzPlane()+fgkHzPadPlane;
-  gMC->Gspos(planeName,1,name,posX,posY,posZ,0,"ONLY");
+//______________________________________________________________________________
+Int_t  AliMUONv2::GetChamberId(Int_t volId) const
+{
+// Check if the volume with specified  volId is a sensitive volume (gas) 
+// of some chamber and returns the chamber number;
+// if not sensitive volume - return 0.
+// ---
+
+  for (Int_t i = 1; i <=2; i++) 
+     if (IsInChamber(i-1,volId)) return i;
   
-  //foam layer
-  char* foamName = strdup(name);
-  foamName[3]=fgkFoamLayerSuffix;
-  par[0] = dimensions.X();
-  par[1] = dimensions.Y();
-  par[2] = fgkHzFoam;
-  gMC->Gsvolu(foamName,"BOX",idFoam,par,3);
-  posX=0.;
-  posY=0.;
-  posZ = -totalHzPlane()+2.*fgkHzPadPlane+fgkHzFoam;
-  gMC->Gspos(foamName,1,name,posX,posY,posZ,0,"ONLY");
+  for (Int_t i = 3; i <= AliMUONConstants::NCh(); i++)
+    if (volId==((AliMUONChamber*)(*fChambers)[i-1])->GetGid()) return i;
 
-  // mechanical plane FR4 layer
-  char* fr4Name = strdup(name);
-  fr4Name[3]='R';
-  par[0] = dimensions.X();
-  par[1] = dimensions.Y();
-  par[2] = fgkHzFR4;
-  gMC->Gsvolu(fr4Name,"BOX",idFR4,par,3);
-  posX=0.;
-  posY=0.;
-  posZ = -totalHzPlane()+2.*fgkHzPadPlane+2.*fgkHzFoam+fgkHzFR4;
-  gMC->Gspos(fr4Name,1,name,posX,posY,posZ,0,"ONLY");
+  return 0;
 }
 
-//___________________________________________
-void AliMUONv2::CreatePlaneSegment(const char* name,const  TVector2& dimensions
-                                 ,Int_t nofHoles)
+//
+// public methods
+//
+
+//______________________________________________________________________________
+void AliMUONv2::CreateMaterials()
 {
-// Create a segment of a plane (this includes a copper layer, foam, hole, 
-// and kapton as well as the mother board.)
-// --
-  static Int_t holeNum=1;
-    
-  GReal_t posX,posY,posZ;
+// --- Define the various mixtures for GEANT ---
   
-  CreatePlaneBox(name,dimensions);
-  char holeName[5];
-  strcpy(holeName,name);
-  holeName[3]=fgkFoamLayerSuffix;
-  // <dname> is a motif on the pad plane
-  char* dname = strdup(name);
-  dname[3]='D';
-  gMC->Gsdvn(dname,holeName,nofHoles,1);
+  //     Ar-CO2 gas (80%+20%)
+  Float_t ag1[2]   = { 39.95,44.01};
+  Float_t zg1[2]   = { 18.,22.};
+  Float_t dg1      = .001821;
+  Float_t wg1[2]   = { .8,0.2};
+  // use wg1 weighting factors (6th arg > 0)
+  AliMixture(22, "ArCO2 80%$", ag1, zg1, dg1, 2, wg1);  
   
-  posX=0.;
-  posY=0.;
-  posZ= fgkHzPadPlane;
-  gMC->Gspos(fgkHoleName,holeNum++,dname,posX,posY,posZ,0,"ONLY");
-}
+  // Ar-buthane-freon gas -- trigger chambers 
+  Float_t atr1[4]  = { 39.95,12.01,1.01,19. };
+  Float_t ztr1[4]  = { 18.,6.,1.,9. };
+  Float_t wtr1[4]  = { .56,.1262857,.2857143,.028 };
+  Float_t dtr1     = .002599;
+  AliMixture(23, "Ar-freon $", atr1, ztr1, dtr1, 4, wtr1);
 
-//___________________________________________
-void AliMUONv2::CreateDaughterSegment(const char* name,const  TVector2& dimensions,
-                              Int_t nofHoles)
-{
-// Create a segment of a daughter board layer
-// --
-  static Int_t holeNum=1;
-  Int_t* idtmed = fIdtmed->GetArray()-1099;
-  Int_t idAir  = idtmed[1100]; // medium 1
+  // Rohacell 51  - imide methacrylique
+  Float_t aRohacell51[4] = {12.01,1.01,16.00,14.01}; 
+  Float_t zRohacell51[4] = {6.,1.,8.,7.}; 
+  Float_t dRohacell51 = 0.052;
+  Float_t wRohacell51[4] = {9.,13.,2.,1.};  
+  // use relative A (molecular) values (6th arg < 0)
+  AliMixture(32, "FOAM$",aRohacell51,zRohacell51,dRohacell51,-4,wRohacell51);  
+   
+  Float_t aSnPb[2] = {118.69,207.19};
+  Float_t zSnPb[2] = {50,82};
+  Float_t dSnPb = 8.926;
+  Float_t wSnPb[2] = {0.6, 0.4} ;
+  // use wSnPb weighting factors (6th arg > 0)
+  AliMixture(35, "SnPb$", aSnPb,zSnPb,dSnPb,2,wSnPb);
 
-  GReal_t par[3];
-  GReal_t posX,posY,posZ;
-  
-  par[0] = dimensions.X();
-  par[1] = dimensions.Y();
-  par[2] = totalHzDaughter();
-  gMC->Gsvolu(name,"BOX",idAir,par,3);
+  // plastic definition from K5, Freiburg (found on web)
+  Float_t aPlastic[2]={1.01,12.01};
+  Float_t zPlastic[2]={1,6};
+  Float_t denPlastic=1.107;
+  Float_t wPlastic[2]={1,1};
+  // use relative A (molecular) values (6th arg < 0)...no other info...
+  AliMixture( 33, "Plastic$",aPlastic,zPlastic,denPlastic,-2,wPlastic);
+  // from CERN note NUFACT Note023, Oct.2000 
+  // Inox/Stainless Steel (18%Cr, 9%Ni)
+  Float_t aInox[3] = {55.847,51.9961,58.6934};  
+  Float_t zInox[3] = {26.,24.,28.};
+  Float_t denInox = 7.930;
+  Float_t wInox[3] = {0.73,0.18,0.09}; 
+  // use wInox weighting factors (6th arg > 0) 
+  AliMixture(37, "StainlessSteel$",aInox,zInox,denInox,3,wInox);   
+
+  // bakelite 
+  Float_t abak[3] = {12.01 , 1.01 , 16.};
+  Float_t zbak[3] = {6.     , 1.   , 8.};
+  Float_t wbak[3] = {6.     , 6.   , 1.}; 
+  Float_t dbak = 1.4;
+  AliMixture(19, "Bakelite$", abak, zbak, dbak, -3, wbak);
   
-  // <dname> is a motif on pad plane
-  char* dname = strdup(name);
-  dname[3]='D';
-  gMC->Gsdvn(dname,name,nofHoles,1);
+  // Ar-Isobutane gas (80%+20%) 
+  Float_t ag[3]    = { 39.95,12.01,1.01 };
+  Float_t zg[3]    = { 18.,6.,1. };
+  Float_t wg[3]    = { .8,.057,.143 };
+  Float_t dg       = .0019596;
+  AliMixture(20, "ArC4H10 GAS$", ag, zg, dg, 3, wg);
+
+  //     Ar-Isobutane-Forane-SF6 gas (49%+7%+40%+4%) -- trigger 
+  Float_t atrig[5] = { 39.95,12.01,1.01,19.,32.066 };
+  Float_t ztrig[5] = { 18.,6.,1.,9.,16. };
+  Float_t wtrig[5] = { .49,1.08,1.5,1.84,0.04 };
+  Float_t dtrig    = .0031463;
+  AliMixture(21, "TRIG GAS$", atrig, ztrig, dtrig, -5, wtrig);
+      
+// --- Define the various AliMaterials for GEANT ---
+  // from PDG and "The Particle Detector BriefBook", Bock and Vasilescu, P.18  
+  AliMaterial( 9, "Aluminium$", 26.98, 13., 2.7, -8.9, 26.1);
+  AliMaterial(10, "Aluminium$", 26.98, 13., 2.7, -8.9, 26.1);
+  AliMaterial(15, "air$", 14.61, 7.3, .001205, -30423.24, 67500);
+  AliMaterial(30, "Copper$", 63.546,29.,8.96,-1.43,9.6);
+  AliMaterial(31, "FR4$", 17.749, 8.875, 1.7, -19.4, 999.);    // from DPG
+  AliMaterial(34, "Kapton$", 12.01,6,1.42,-28.6,999);          // from DPG
+ // Density of FrameEpoxy only from manufacturer's specifications
+ // Frame composite epoxy , X0 in g/cm**2 (guestimation!)
+  AliMaterial(36, "FrameEpoxy",12.24,6.0,1.85,-19.14,999);// use 16.75cm
   
-  posX=0.;
-  posY=0.;
-  posZ=0.;
-  gMC->Gspos(fgkDaughterName,holeNum++,dname,posX,posY,posZ,0,"ONLY");
+// --- Define the tracking medias (AliMediums) for GEANT ---
+  GReal_t epsil  = .001;       // Tracking precision,
+  GReal_t stemax = -1.;        // Maximum displacement for multiple scat
+  GReal_t tmaxfd = -20.;       // Maximum angle due to field deflection
+  GReal_t deemax = -.3;        // Maximum fractional energy loss, DLS
+  GReal_t stmin  = -.8;
+  GReal_t maxStepAlu = 0.001;  // from AliMUON.cxx
+  GReal_t maxDestepAlu = -1.;  // from AliMUON.cxx
+  GReal_t maxStepGas=0.01;     // from AliMUON.cxx
+
+  Int_t iSXFLD   = gAlice->Field()->Integ();
+  Float_t sXMGMX = gAlice->Field()->Max();
+
+  AliMedium(1, "AIR_CH_US$", 15, 1, iSXFLD, sXMGMX, tmaxfd,
+           stemax, deemax, epsil, stmin);
+  AliMedium(4, "ALU_CH_US$", 9, 0, iSXFLD, sXMGMX, tmaxfd,
+           maxStepAlu, maxDestepAlu, epsil, stmin);
+  AliMedium(5, "ALU_CH_US$", 10, 0, iSXFLD, sXMGMX, tmaxfd,
+           maxStepAlu,maxDestepAlu, epsil, stmin);  
+  AliMedium(6, "AR_CH_US          ", 20, 1, iSXFLD, sXMGMX, 
+              tmaxfd, fMaxStepGas,fMaxDestepGas, epsil, stmin);
+              
+  //    Ar-Isobuthane-Forane-SF6 gas 
+  AliMedium(7, "GAS_CH_TRIGGER    ", 21, 1, iSXFLD, sXMGMX, 
+               tmaxfd, stemax, deemax, epsil, stmin);
+  AliMedium(8, "BAKE_CH_TRIGGER   ", 19, 0, iSXFLD, sXMGMX, 
+               tmaxfd, fMaxStepAlu, fMaxDestepAlu, epsil, stmin);
+
+  AliMedium(9, "ArCO2 80%$", 22, 1, iSXFLD, sXMGMX, tmaxfd, maxStepGas,
+             maxDestepAlu, epsil, stmin);
+  AliMedium(10, "COPPER_CH$", 30, 0, iSXFLD, sXMGMX, tmaxfd,
+             maxStepAlu, maxDestepAlu, epsil, stmin);
+  AliMedium(11, "PCB_COPPER        ", 31, 0, iSXFLD, sXMGMX, tmaxfd, 
+                fMaxStepAlu, fMaxDestepAlu, epsil, stmin);
+  AliMedium(12, "VETRONITE         ", 32, 0, iSXFLD, sXMGMX, tmaxfd, 
+                fMaxStepAlu, fMaxDestepAlu, epsil, stmin);
+  AliMedium(13, "CARBON            ", 33, 0, iSXFLD, sXMGMX, tmaxfd, 
+                fMaxStepAlu, fMaxDestepAlu, epsil, stmin);
+  AliMedium(14, "Rohacell          ", 34, 0, iSXFLD, sXMGMX, tmaxfd, 
+             fMaxStepAlu, fMaxDestepAlu, epsil, stmin);
+  AliMedium(15, "FR4_CH$",  31, 0,iSXFLD, sXMGMX, 10., .01,.1, .003, .003);
+  AliMedium(16, "FOAM_CH$", 32, 0,
+             iSXFLD, sXMGMX, 10.0, 0.1, 0.1, 0.1, 0.1, 0, 0) ;
+  AliMedium(17, "Plastic$", 33, 0,iSXFLD, sXMGMX,  10., .01, 1., .003, .003);
+  AliMedium(18, "Kapton$", 34, 0,iSXFLD, sXMGMX,  10., .01, 1., .003, .003);
+  AliMedium(19, "SnPb$", 35, 0,iSXFLD, sXMGMX,  10., .01,  1., .003, .003);
+  AliMedium(20, "FrameCH$", 36, 1,iSXFLD, sXMGMX,  10., .001, 0.001, .001, .001);
+  AliMedium(21, "InoxBolts$", 37,1,iSXFLD, sXMGMX,  10., .01, 1., .003, .003);
+
+// store the parameters
+  Float_t a, z, dens, absl;
+  char matName[5];
+  AliGetMaterial(30,matName,a,z,dens,fRadlCopper,absl);
+  AliGetMaterial(31,matName,a,z,dens,fRadlFR4,absl);
+  AliGetMaterial(32,matName,a,z,dens,fRadlFoam,absl);
 }
 
-//___________________________________________
-void AliMUONv2::PlaceSector(MSector* sector,TSpecialMap specialMap
-                           ,const TVector3& where,Int_t chamber)
+//______________________________________________________________________________
+void AliMUONv2::CreateGeometry()
 {
-// Place all the segments in the mother volume, in the position defined
-// by the sector's data.
+// Create the GEANT geometry for the dimuon arm.
+// Use the parent's method for stations 2, 3, 4 and 5.
+// Use the detailed code for the first station.
 // --
-  static Int_t segNum=1;
+  cout << "AliMUONv2::CreateGeometry()" << endl;
+  cout << "_________________________________________" << endl;
+
+  // Create basic volumes
+  // 
+  CreateHole();
+  CreateDaughterBoard();
+  CreateInnerLayers();
   
-  GReal_t posX,posY,posZ;
+  // Create reflexion matrices
+  //
+  Int_t reflXZ, reflYZ, reflXY;
+  AliMatrix(reflXZ,  90.,  180., 90., 90., 180., 0.);
+  AliMatrix(reflYZ,  90., 0., 90.,-90., 180., 0.);
+  AliMatrix(reflXY,  90., 180., 90., 270., 0., 0.);
+
+  // Define transformations for each quadrant
+  // 
+  //     II. |  I.
+  //   _____ | ____
+  //         |
+  //    III. |  IV.
+  // 
+  Int_t rotm[4];
+  rotm[0]=0;       // quadrant I
+  rotm[1]=reflXZ;  // quadrant II
+  rotm[2]=reflXY;  // quadrant III
+  rotm[3]=reflYZ;  // quadrant IV
   
-  vector<int> already_done;
-  Int_t rotNum;
-  AliMatrix(rotNum,  90.,90.,90,180.,0.,0.);
+  TVector3 scale[4];  
+  scale[0] = TVector3( 1,  1,  1);  // quadrant I
+  scale[1] = TVector3(-1,  1, -1);  // quadrant II
+  scale[2] = TVector3(-1, -1,  1);  // quadrant III
+  scale[3] = TVector3( 1, -1, -1);  // quadrant IV
   
-  for (Int_t irow=0;irow<sector->GetNofRows();irow++){
-    MRow* row = sector->GetRow(irow);
-    for (Int_t iseg=0;iseg<row->GetNofRowSegments();iseg++){
-      MVRowSegment* seg = row->GetRowSegment(iseg);
-      char* segName;
-      
-      TSpecialMap::iterator iter 
-        = specialMap.find(seg->GetMotifPositionId(0));
-      if ( iter == specialMap.end()){
-        segName = strdup(Form("%.3dM",segNum*2));
-        CreatePlaneSegment(segName,seg->Dimensions()/10.,seg->GetNofMotifs());     
-        posX = where.X()+seg->Position().X()/10.-fgkOffsetX/2.;
-        posY = where.Y()+seg->Position().Y()/10.-fgkOffsetY/2.;
-        posZ = where.Z()-totalHz()+totalHzPlane();
-        gMC->Gspos(segName,1,QuadrantName(chamber),posX,posY,posZ,0,"ONLY");
-
-        segName = strdup(Form("%.3dM",segNum*2+1));
-        CreateDaughterSegment(segName,seg->Dimensions()/10.,seg->GetNofMotifs());     
-        posX = where.X()+seg->Position().X()/10.+fgkOffsetX/2.;
-        posY = where.Y()+seg->Position().Y()/10.-+fgkOffsetY/2.;
-        posZ = where.Z()-totalHz()+2.*totalHzPlane()+totalHzDaughter();
-        gMC->Gspos(segName,1,QuadrantName(chamber),posX,posY,posZ,0,"ONLY");
-       segNum++;
-      } else {
-       for (Int_t motifNum=0;motifNum<seg->GetNofMotifs();motifNum++) {
-         Int_t motifPosId = seg->GetMotifPositionId(motifNum);
-         
-         if (find(already_done.begin(),already_done.end(),motifPosId)
-             != already_done.end()) continue;
-         
-            AliMUONSt1SpecialMotif spMot = specialMap[motifPosId];
-
-         MMotifPosition* motifPos = 
-           sector->GetMotifMap()->FindMotifPosition(motifPosId);
-         MMotifType* mType = motifPos->GetMotif()->GetMotifType();
-         for (Int_t line=0;line<mType->GetNofPadsY();line++) {
-           Int_t iMin=-1,iMax=-1,col;
-           for (col=0;col<mType->GetNofPadsX();col++) {
-             if (mType->HasPad(MIntPair(col,line))) {
-               iMin=col;
-               break;
-             }
-           }
-           for (col=mType->GetNofPadsX()-1;col>=0;col--) {
-             if (mType->HasPad(MIntPair(col,line))) {
-               iMax=col;
-               break;
-             }
-           }
-           if ( (iMin>=0) && (iMax>=0) ) {
-             TVector2 dim =  
-              motifPos->GetMotif()->GetPadDimensions(MIntPair(iMin,line))/10.;
-             TVector2 lineDim(dim.X()*(iMax-iMin+1),dim.Y());
-             char* boxName = strdup(Form("%.3dM",segNum*2));
-             CreatePlaneBox(boxName,lineDim);
-             TVector2 posLLline = TVector2(dim.X()*2.*iMin,dim.Y()*2.*line)
-                                   +motifPos->Position()/10.-motifPos->Dimensions()/10.;
-             TVector2 centerLine = posLLline + lineDim;
-             posX = where.X()+centerLine.X()-fgkOffsetX/2.;
-             posY = where.Y()+centerLine.Y()-fgkOffsetY/2.;
-             posZ = where.Z()-totalHz()+totalHzPlane();
-             gMC->Gspos(boxName,1,QuadrantName(chamber),posX,posY,posZ,0,"ONLY");
-           }
-           
-           segNum++;
-         }
-         
-         Int_t rot = ( spMot.GetRotAngle()<0.1 ) ? 0:rotNum;
-
-         posX = where.X()+motifPos->Position().X()/10.-fgkOffsetX/2.+spMot.GetDelta().X();
-         posY = where.Y()+motifPos->Position().Y()/10.-fgkOffsetY/2.+spMot.GetDelta().Y();
-         posZ = where.Z()-fgkHzPadPlane;
-         gMC->Gspos(fgkHoleName,motifPosId,QuadrantName(chamber),posX,posY,posZ,rot,"ONLY");
-         
-         posX = where.X()+motifPos->Position().X()/10.+fgkOffsetX/2.-fgkDeltaFilleEtamX+spMot.GetDelta().X();
-         posY = where.Y()+motifPos->Position().Y()/10.-+fgkOffsetY/2.-fgkDeltaFilleEtamY+spMot.GetDelta().Y();
-         posZ = where.Z()-totalHz()+2.*totalHzPlane()+totalHzDaughter();
-         gMC->Gspos(fgkDaughterName,motifPosId,QuadrantName(chamber),posX,posY,posZ,rot,"ONLY");
-
-         already_done.push_back(motifPosId);             
-       }
-      }
-    }
-  } 
+  // Shift in Z of the middle layer
+  Double_t deltaZ = 6.5/2.;         
+
+  // Position of quadrant I wrt to the chamber position
+  TVector3 pos0(-fgkDeltaQuadLHC, -fgkDeltaQuadLHC, deltaZ);
+
+  // Shift for near/far layers
+  GReal_t  shiftXY = fgkFrameOffset;
+  GReal_t  shiftZ  = fgkMotherThick1+fgkMotherThick2;
+
+  // Build two chambers
+  //
+  for (Int_t ich=1; ich<3; ich++) {
+
+    // Create quadrant volume
+    CreateQuadrant(ich);
+
+    // Place gas volumes
+    PlaceInnerLayers(ich);
+    
+    // Place the quadrant
+    for (Int_t i=0; i<4; i++) {
+
+      // Middle layer
+      GReal_t posx = pos0.X() * scale[i].X();
+      GReal_t posy = pos0.Y() * scale[i].Y();
+      GReal_t posz = pos0.Z() * scale[i].Z() + AliMUONConstants::DefaultChamberZ(ich-1);
+      gMC->Gspos(QuadrantMLayerName(ich), i+1, "ALIC", posx, posy, posz, rotm[i], "ONLY");
+
+      // Near/far layers
+      Real_t  posx2 = posx + shiftXY * scale[i].X();
+      Real_t  posy2 = posy + shiftXY * scale[i].Y();
+      Real_t  posz2 = posz - scale[i].Z()*shiftZ;
+      gMC->Gspos(QuadrantNLayerName(ich), i+1, "ALIC", posx2, posy2, posz2, rotm[i],"ONLY");
+    
+      posz2 = posz + scale[i].Z()*shiftZ;
+      gMC->Gspos(QuadrantFLayerName(ich), i+1, "ALIC", posx2, posy2, posz2, rotm[i],"ONLY");
+   }
+ }     
+
+  static Int_t stations[5]={0,1,1,1,1};
+  fStations=stations;
+  AliMUONv1::CreateGeometry();
+}
+
+//______________________________________________________________________________
+void AliMUONv2::Init() 
+{
+   // Initialize Station 1 Tracking Chambers
+   //
+   // Set the chamber (sensitive region) GEANT identifier
+    fChamberV2[0] = new TArrayI(11);             // Chamber 1 sensitive volume Id array
+    fChamberV2[1] = new TArrayI(11);             // Chamber 2 sensitive volume Id array
+
+    AddChamberGid(0,gMC->VolId("SA1G"),0);
+    AddChamberGid(0,gMC->VolId("SB1G"),1);
+    AddChamberGid(0,gMC->VolId("SC1G"),2);
+    AddChamberGid(0,gMC->VolId("SD1G"),3);
+    AddChamberGid(0,gMC->VolId("SE1G"),4);
+    AddChamberGid(0,gMC->VolId("SF1G"),5);
+    AddChamberGid(0,gMC->VolId("SG1G"),6);
+    AddChamberGid(0,gMC->VolId("SH1G"),7);
+    AddChamberGid(0,gMC->VolId("SI1G"),8);
+    AddChamberGid(0,gMC->VolId("SJ1G"),9);
+    AddChamberGid(0,gMC->VolId("SK1G"),10);
+
+    
+    AddChamberGid(1,gMC->VolId("SA2G"),0);
+    AddChamberGid(1,gMC->VolId("SB2G"),1);
+    AddChamberGid(1,gMC->VolId("SC2G"),2);
+    AddChamberGid(1,gMC->VolId("SD2G"),3);
+    AddChamberGid(1,gMC->VolId("SE2G"),4);
+    AddChamberGid(1,gMC->VolId("SF2G"),5);
+    AddChamberGid(1,gMC->VolId("SG2G"),6);
+    AddChamberGid(1,gMC->VolId("SH2G"),7);
+    AddChamberGid(1,gMC->VolId("SI2G"),8);
+    AddChamberGid(1,gMC->VolId("SJ2G"),9);
+    AddChamberGid(1,gMC->VolId("SK2G"),10);
+
+  Int_t i;
+// now do the other stations as in AliMUONv1
+   for (i=0; i<AliMUONConstants::NCh(); i++) {
+       ( (AliMUONChamber*) (*fChambers)[i])->Init();
+   }
+   
+   //
+   // Set the chamber (sensitive region) GEANT identifier
+   ((AliMUONChamber*)(*fChambers)[0])->SetGid(-1);  // joker
+   ((AliMUONChamber*)(*fChambers)[1])->SetGid(-1);  // joker
+
+   ((AliMUONChamber*)(*fChambers)[2])->SetGid(gMC->VolId("S03G"));
+   ((AliMUONChamber*)(*fChambers)[3])->SetGid(gMC->VolId("S04G"));
+
+   ((AliMUONChamber*)(*fChambers)[4])->SetGid(gMC->VolId("S05G"));
+   ((AliMUONChamber*)(*fChambers)[5])->SetGid(gMC->VolId("S06G"));
+
+   ((AliMUONChamber*)(*fChambers)[6])->SetGid(gMC->VolId("S07G"));
+   ((AliMUONChamber*)(*fChambers)[7])->SetGid(gMC->VolId("S08G"));
+
+   ((AliMUONChamber*)(*fChambers)[8])->SetGid(gMC->VolId("S09G"));
+   ((AliMUONChamber*)(*fChambers)[9])->SetGid(gMC->VolId("S10G"));
+
+   ((AliMUONChamber*)(*fChambers)[10])->SetGid(gMC->VolId("SG1A"));
+   ((AliMUONChamber*)(*fChambers)[11])->SetGid(gMC->VolId("SG2A"));
+   ((AliMUONChamber*)(*fChambers)[12])->SetGid(gMC->VolId("SG3A"));
+   ((AliMUONChamber*)(*fChambers)[13])->SetGid(gMC->VolId("SG4A"));
+
 }
+
index 66062bb..90c2f8a 100644 (file)
 // Inherits from AliMUONv1 but with a more detailed
 // geometrical description of station 1 
 
-#include <map>
+#include <TVector2.h>
+#include <TVector3.h>
 
 #include "AliMUONv1.h"
+#include "AliMUONSt1Types.h"
 #include "AliMUONSt1SpecialMotif.h"
 
-#include <TVector2.h>
-#include <TVector3.h>
-
-typedef Float_t GReal_t; // for AliGeant3
-//typedef Double_t GReal_t; // for VirtualMC
+//typedef Float_t GReal_t; // for AliGeant3
+typedef Double_t GReal_t; // for VirtualMC
 
 class TTree;
-class MSector;
-using std::map;
-
+class TArrayI;
+class AliMpSector;
 
-class AliMUONv2 : public  AliMUONv1 {
+class AliMUONv2 : public  AliMUONv1 
+{
   public:
     AliMUONv2();
     AliMUONv2(const char* name, const char* title);
@@ -36,30 +35,56 @@ class AliMUONv2 : public  AliMUONv1 {
     virtual ~AliMUONv2();
 
     virtual Int_t IsVersion() const;
-    virtual void  CreateGeometry();
     virtual void  CreateMaterials();
-
+    virtual void  CreateGeometry();
+    virtual void  Init();
+   
   protected:
     // Copy Operator
-    AliMUONv2& operator = (const AliMUONv2& rhs);
-    
+    AliMUONv2& operator = (const AliMUONv2& rhs);    
+    virtual Int_t  GetChamberId(Int_t volId) const;
+
   private:
-    
-    typedef map< Int_t , AliMUONSt1SpecialMotif > TSpecialMap;
-    static const GReal_t fgkHzPadPlane; // Pad plane
-    static const GReal_t fgkHzFoam;  // Foam of mechanicalplane
-    static const GReal_t fgkHzFR4;  // FR4 of mechanical plane
-    static const GReal_t fgkHzSnPb; //Pad/Kapton connection (66 pt)
-    static const GReal_t fgkHzKapton; //Kapton
-    static const GReal_t fgkHzBergPlastic; //Berg connector 
-    static const GReal_t fgkHzBergCopper; //Berg connector (80 pt)
-    static const GReal_t fgkHzDaughter; //Daughter board
-    static const GReal_t fgkHzGas ; // ArCO2 Gas
-
-    GReal_t totalHzPlane() const ; //Total mechanical plane half Size
-    GReal_t totalHzDaughter() const ; //Total daughter plane half Size
-    GReal_t totalHz() const ; //Total plane half Size
+    // Methods
+    //
+    void CreateHole();
+    void CreateDaughterBoard();
+    void CreateInnerLayers();
+    void CreateQuadrant(Int_t chamber);
+    void CreateFoamBox(const char* name,const TVector2& dimensions);
+    void CreatePlaneSegment(const char* name,const TVector2& dimensions,
+                     Int_t nofHoles);
+    void CreateFrame(Int_t chamber);
 
+    void PlaceInnerLayers(Int_t chamber);
+    void PlaceSector(AliMpSector* sector, TSpecialMap specialMap,
+                     const TVector3& where, Bool_t reflectZ, Int_t chamber);
+                    
+    TString QuadrantMLayerName(Int_t chamber) const;
+    TString QuadrantNLayerName(Int_t chamber) const;
+    TString QuadrantFLayerName(Int_t chamber) const;
+    TString GasVolumeName(const TString& name, Int_t chamber) const;
+
+    void   AddChamberGid(Int_t id,Int_t volName,Int_t idx);
+    Bool_t IsInChamber(Int_t ich, Int_t volGid) const;   
+
+    GReal_t TotalHzPlane() const ;         // Total mechanical plane half Size
+    GReal_t TotalHzDaughter() const ;      // Total daughter plane half Size
+    GReal_t TotalHz() const ;              // Total plane half Size
+       
+    // Constants
+    //
+    static const GReal_t fgkHzPadPlane;    // Pad plane
+    static const GReal_t fgkHzFoam;        // Foam of mechanicalplane
+    static const GReal_t fgkHzFR4;         // FR4 of mechanical plane
+    static const GReal_t fgkHzSnPb;        // Pad/Kapton connection (66 pt)
+    static const GReal_t fgkHzKapton;      // Kapton
+    static const GReal_t fgkHzBergPlastic; // Berg connector 
+    static const GReal_t fgkHzBergCopper;  // Berg connector (80 pt)
+    static const GReal_t fgkHzDaughter;    // Daughter board
+    static const GReal_t fgkHzGas;         // ArCO2 Gas
+        
+    // Sensitive copper pads, foam layer, PCB and electronics model parameters
     static const GReal_t fgkHxHole;
     static const GReal_t fgkHyHole;
     static const GReal_t fgkHxBergPlastic;
@@ -74,50 +99,67 @@ class AliMUONv2 : public  AliMUONv1 {
     static const GReal_t fgkOffsetY;
     static const GReal_t fgkDeltaFilleEtamX;
     static const GReal_t fgkDeltaFilleEtamY;
-    static const GReal_t fgkHxQuadrant;
-    static const GReal_t fgkHyQuadrant;
-    static const GReal_t fgkMotherIR;
-    static const GReal_t fgkMotherOR; 
-    static const GReal_t fgkMotherThick;  
-    static const GReal_t fgkMotherPhiL; 
-    static const GReal_t fgkMotherPhiU;
-
-    static const char* fgkHoleName;
-    static const char* fgkQuadrantName;
-    static const char* fgkDaughterName;
-    static const char fgkFoamLayerSuffix;
 
-
-    void CreateHole();
-    void CreateDaughterBoard();
-    void CreateFrame(Int_t chamber);
-    void CreateQuadrant(Int_t chamber);
-    void CreatePlaneBox(const char* name,const TVector2& dimensions);
-    void CreatePlaneSegment(const char* name,const  TVector2& dimensions
-                      ,Int_t nofHoles);
-    void CreateDaughterSegment(const char* name,const  TVector2& dimensions
-                      ,Int_t nofHoles);
-    void PlaceSector(MSector* sector,TSpecialMap specialMap
-                    ,const TVector3& where,Int_t chamber);
-    TString QuadrantName(Int_t chamber);
-    Int_t      fIdSens;  // Sensitive volume identifier
+    static const GReal_t fgkDeltaQuadLHC; //LHC Origin wrt Quadrant Origin
+    static const GReal_t fgkFrameOffset;  
+
+    // Quadrant Mother volume - TUBS1   
+    static const GReal_t fgkMotherIR1;
+    static const GReal_t fgkMotherOR1; 
+    static const GReal_t fgkMotherThick1;  
+    static const GReal_t fgkMotherPhiL1; 
+    static const GReal_t fgkMotherPhiU1;
+
+    // Quadrant Mother volume - TUBS2 (2 copies at different Z's)   
+    static const GReal_t fgkMotherIR2;
+    static const GReal_t fgkMotherOR2; 
+    static const GReal_t fgkMotherThick2;  
+    static const GReal_t fgkMotherPhiL2; 
+    static const GReal_t fgkMotherPhiU2;    
+
+    static const char* fgkHoleName;          // prefix for automatic volume naming
+    static const char* fgkQuadrantMLayerName;// prefix for automatic volume naming
+    static const char* fgkQuadrantNLayerName;// prefix for automatic volume naming
+    static const char* fgkQuadrantFLayerName;// prefix for automatic volume naming
+    static const char* fgkDaughterName;      // prefix for automatic volume naming
+    static const char  fgkFoamLayerSuffix;   // suffix for automatic volume naming
+
+    // Data members
+    //
+    Float_t  fRadlCopper;  //! copper computed radiation length
+    Float_t  fRadlFoam;    //! foam   computed radiation length
+    Float_t  fRadlFR4;     //! FR4    computed radiation length
+    TArrayI* fChamberV2[2];// Sensitive volumes IDs    
     
-
   ClassDef(AliMUONv2,1)  // MUON Detector base class
 };
 
 // inline functions
 
 inline Int_t AliMUONv2::IsVersion () const 
- { return 2; }
-inline GReal_t AliMUONv2::totalHzPlane() const 
- { return fgkHzPadPlane + fgkHzFoam + fgkHzFR4;}
-inline GReal_t AliMUONv2::totalHzDaughter() const 
- { return fgkHzBergPlastic + fgkHzDaughter;}
-inline GReal_t AliMUONv2::totalHz() const 
- { return totalHzPlane() + totalHzDaughter();}
-inline TString AliMUONv2::QuadrantName(Int_t chamber)
-{return Form("%s%d",fgkQuadrantName,chamber);}
+{ return 2; }
+
+inline GReal_t AliMUONv2::TotalHzPlane() const 
+//{ return fgkHzPadPlane + fgkHzFoam + fgkHzFR4; }
+{ return fgkHzFoam + fgkHzFR4; }
+
+inline GReal_t AliMUONv2::TotalHzDaughter() const 
+{ return fgkHzBergPlastic + fgkHzDaughter; }
+
+inline GReal_t AliMUONv2::TotalHz() const 
+{ return TotalHzPlane() + TotalHzDaughter(); }
+
+inline TString AliMUONv2::QuadrantMLayerName(Int_t chamber) const
+{ return Form("%s%d",fgkQuadrantMLayerName,chamber); }
+
+inline TString AliMUONv2::QuadrantNLayerName(Int_t chamber) const
+{ return Form("%s%d",fgkQuadrantNLayerName,chamber); }
+
+inline TString AliMUONv2::QuadrantFLayerName(Int_t chamber) const
+{ return Form("%s%d",fgkQuadrantFLayerName,chamber); }
+
+inline void AliMUONv2::AddChamberGid(Int_t id,Int_t volName,Int_t idx)
+{ fChamberV2[id]->AddAt(volName,idx); }
 
 
 #endif //ALI_MUON_V2_H
index fb2a003..c7339ed 100644 (file)
@@ -5,7 +5,6 @@
 #pragma link C++ class  AliMUON+;
 #pragma link C++ class  AliMUONv0+;
 #pragma link C++ class  AliMUONv1+;
-#pragma link C++ class  AliMUONv3+;
 #pragma link C++ class  AliMUONHit+;
 #pragma link C++ class  AliMUONPadHit+;
 #pragma link C++ class  AliMUONDigit+;
 #pragma link C++ class  AliMUONMerger+;
 #pragma link C++ class  AliMUONFactory+;
 #pragma link C++ class  AliMUONDigitizer+;
-#pragma link C++ class  AliMUONDigitizerv1+;
 #pragma link C++ class  AliMUONTrackK+;
 #pragma link C++ class  AliMUONPixel+;
 #pragma link C++ class  AliMUONClusterFinderAZ+;
-
-#ifdef USE_MUON_MAPPING
 #pragma link C++ class  AliMUONv2+;
 #pragma link C++ class  AliMUONSt1Segmentation+;
 #pragma link C++ class  AliMUONSt1Response+;
@@ -68,6 +64,8 @@
 #pragma link C++ class  AliMUONSt1SpecialMotif+;
 #pragma link C++ class  AliMUONSt1ResponseParameter+;
 #pragma link C++ class  AliMUONSt1ResponseRule+;
-#endif
+
+#include "MUONLinkDefMapping.h"
 
 #endif
+
diff --git a/MUON/MUONLinkDefMapping.h b/MUON/MUONLinkDefMapping.h
new file mode 100644 (file)
index 0000000..ffb9549
--- /dev/null
@@ -0,0 +1,75 @@
+// $Id$ 
+
+#pragma link C++ class  AliMpArea+;
+#pragma link C++ class  AliMpConstants+;
+#pragma link C++ class  AliMpIntPair+;
+#pragma link C++ class  AliMpPad+;
+#pragma link C++ class  AliMpPadPair+;
+#pragma link C++ class  AliMpVIndexed+;
+#pragma link C++ class  AliMpVSegmentation+;
+#pragma link C++ class  AliMpTransformer+;
+#pragma link C++ class  AliMpVPadIterator+;
+#pragma link C++ class  AliMpPadIteratorPtr+;
+#pragma link C++ class  AliMpTransformPadIterator+;
+
+#pragma link C++ enum   AliMpDirection;
+
+
+#pragma link C++ function operator-(const AliMpIntPair& ,const AliMpIntPair& );
+#pragma link C++ function operator+(const AliMpIntPair& ,const AliMpIntPair& );
+#pragma link C++ function operator<<(ostream& ,const AliMpIntPair& );
+#pragma link C++ function operator<<(ostream& ,const AliMpPad& );
+#pragma link C++ function operator<<(ostream& ,const AliMpArea& );
+#pragma link C++ function operator<(const AliMpPad& ,const AliMpPad& );
+
+// $Id$ 
+
+#pragma link C++ class  AliMpMotifMap+;
+#pragma link C++ class  AliMpVMotif+;
+#pragma link C++ class  AliMpMotif+;
+#pragma link C++ class  AliMpMotifSpecial+;
+#pragma link C++ class  AliMpMotifType+;
+#pragma link C++ class  AliMpMotifTypePadIterator+;
+#pragma link C++ class  AliMpMotifPosition+;
+#pragma link C++ class  AliMpMotifPositionPadIterator+;
+#pragma link C++ class  AliMpConnection+;
+
+// $Id$ 
+
+#pragma link C++ class  AliMpReader+;
+#pragma link C++ class  AliMpFiles+;
+#pragma link C++ class  AliMpSector+;
+#pragma link C++ class  AliMpSectorPadIterator+;
+#pragma link C++ class  AliMpSectorAreaHPadIterator+;
+#pragma link C++ class  AliMpSectorAreaVPadIterator+;
+#pragma link C++ class  AliMpSectorSegmentation+;
+#pragma link C++ class  AliMpNeighboursPadIterator+;
+#pragma link C++ class  AliMpZone+;
+#pragma link C++ class  AliMpSubZone+;
+#pragma link C++ class  AliMpRow+;
+#pragma link C++ class  AliMpVRowSegment+;
+#pragma link C++ class  AliMpRowSegment+;
+#pragma link C++ class  AliMpRowSegmentSpecial+;
+#pragma link C++ class  AliMpPadRow+;
+#pragma link C++ class  AliMpPadRowSegment+;
+
+#pragma link C++ enum   AliMpPlaneType;
+
+// $Id$ 
+
+#pragma link C++ class  AliMpSectorPosition+;
+#pragma link C++ class  AliMpPlane+;
+#pragma link C++ class  AliMpPlaneSegmentation+;
+#pragma link C++ class  AliMpPlaneAreaPadIterator+;
+
+// $Id$ 
+
+#pragma link C++ class  AliMpGraphContext+;
+#pragma link C++ class  AliMpVPainter+;
+#pragma link C++ class  AliMpMotifPainter+;
+#pragma link C++ class  AliMpRowPainter+;
+#pragma link C++ class  AliMpRowSegmentPainter+;
+#pragma link C++ class  AliMpSectorPainter+;
+#pragma link C++ class  AliMpSubZonePainter+;
+#pragma link C++ class  AliMpZonePainter+;
+
index 8750ef4..0be60a1 100644 (file)
@@ -9,7 +9,7 @@ SRCS         = AliMUONChamber.cxx AliMUONChamberTrigger.cxx \
               AliMUONSegmentationTrigger.cxx  AliMUONResponseTrigger.cxx\
                AliMUONResponseTriggerV1.cxx\
               AliMUONSegmentationTriggerX.cxx AliMUONSegmentationTriggerY.cxx \
-               AliMUONSegmentationV1.cxx AliMUON.cxx AliMUONv0.cxx AliMUONv1.cxx AliMUONv3.cxx \
+               AliMUONSegmentationV1.cxx AliMUON.cxx AliMUONv0.cxx AliMUONv1.cxx \
                AliMUONDisplay.cxx AliMUONPoints.cxx \
                AliMUONClusterFinderVS.cxx \
                AliMUONHitMapA1.cxx \
@@ -27,9 +27,14 @@ SRCS         = AliMUONChamber.cxx AliMUONChamberTrigger.cxx \
               AliMUONSegmentationSlatModule.cxx AliMUONSegmentationSlatModuleN.cxx \
               AliMUONSegmentationSlat.cxx AliMUONSegmentationSlatN.cxx \
               AliMUONRecoEvent.cxx AliMUONRecoDisplay.cxx \
-               AliMUONMerger.cxx AliMUONFactory.cxx AliMUONDigitizer.cxx AliMUONDigitizerv1.cxx\
+               AliMUONMerger.cxx AliMUONFactory.cxx AliMUONDigitizer.cxx \
                AliMUONTrackK.cxx AliMUONClusterFinderAZ.cxx AliMUONPixel.cxx
 
+SRCS     += AliMUONv2.cxx AliMUONSt1Segmentation.cxx AliMUONSt1Response.cxx \
+           AliMUONSt1ElectronicElement.cxx AliMUONSt1SpecialMotif.cxx \
+           AliMUONSt1ResponseParameter.cxx AliMUONSt1ResponseRule.cxx \
+           AliMUONSt1IniReader.cxx AliMUONSt1Decoder.cxx \
+
 HDRS         =  $(SRCS:.cxx=.h) 
 
 EHDRS        = $(ROOTSYS)/include/TF1.h \
@@ -37,22 +42,8 @@ EHDRS        =       $(ROOTSYS)/include/TF1.h \
                $(ROOTSYS)/include/TMarker3DBox.h \
                $(ROOTSYS)/include/TMatrix.h \
                $(ROOTSYS)/include/TTree.h \
+                $(ROOTSYS)/include/TArrayF.h \
 
 DHDR:= MUONLinkDef.h
 
-ifneq ($(MINSTALL),)          
-
-SRCS     += AliMUONv2.cxx AliMUONSt1Segmentation.cxx AliMUONSt1Response.cxx \
-           AliMUONSt1ElectronicElement.cxx AliMUONSt1SpecialMotif.cxx \
-           AliMUONSt1ResponseParameter.cxx AliMUONSt1ResponseRule.cxx \
-           AliMUONSt1IniReader.cxx AliMUONSt1Decoder.cxx \
-
-EHDRS    += $(ROOTSYS)/include/TArrayF.h \
-
-EINCLUDE := $(MINSTALL)/include
-ELIBSDIR := $(MINSTALL)/lib/$(MPSYSTEM)
-ELIBS    := basic graphics motif sector plane 
-
-CINTFLAGS += -DUSE_MUON_MAPPING
-
-endif         
+include MUON/libMUON.pkg.mapping
diff --git a/MUON/libMUON.pkg.mapping b/MUON/libMUON.pkg.mapping
new file mode 100644 (file)
index 0000000..8ef7ccd
--- /dev/null
@@ -0,0 +1,73 @@
+#
+# mapping 
+#
+
+# Category basic
+#
+SRCS +=  \
+        mapping/AliMpArea.cxx  \
+        mapping/AliMpConstants.cxx  \
+        mapping/AliMpIntPair.cxx  \
+        mapping/AliMpPad.cxx  \
+        mapping/AliMpPadIteratorPtr.cxx  \
+        mapping/AliMpPadPair.cxx  \
+        mapping/AliMpTransformer.cxx  \
+        mapping/AliMpTransformPadIterator.cxx  \
+        mapping/AliMpVIndexed.cxx  \
+        mapping/AliMpVPadIterator.cxx  \
+        mapping/AliMpVSegmentation.cxx  \
+
+# Category motif
+#
+SRCS +=  \
+        mapping/AliMpConnection.cxx  \
+        mapping/AliMpMotif.cxx  \
+        mapping/AliMpMotifMap.cxx  \
+        mapping/AliMpMotifPosition.cxx  \
+        mapping/AliMpMotifPositionPadIterator.cxx  \
+        mapping/AliMpMotifSpecial.cxx  \
+        mapping/AliMpMotifType.cxx  \
+        mapping/AliMpMotifTypePadIterator.cxx  \
+        mapping/AliMpVMotif.cxx  \
+
+# Category sector
+#
+SRCS +=  \
+        mapping/AliMpFiles.cxx  \
+        mapping/AliMpNeighboursPadIterator.cxx  \
+        mapping/AliMpPadRow.cxx  \
+        mapping/AliMpPadRowSegment.cxx  \
+        mapping/AliMpReader.cxx  \
+        mapping/AliMpRow.cxx  \
+        mapping/AliMpRowSegment.cxx  \
+        mapping/AliMpRowSegmentSpecial.cxx  \
+        mapping/AliMpSectorAreaHPadIterator.cxx  \
+        mapping/AliMpSectorAreaVPadIterator.cxx  \
+        mapping/AliMpSector.cxx  \
+        mapping/AliMpSectorPadIterator.cxx  \
+        mapping/AliMpSectorSegmentation.cxx  \
+        mapping/AliMpSubZone.cxx  \
+        mapping/AliMpVRowSegment.cxx  \
+        mapping/AliMpZone.cxx  \
+
+# Category plane
+#
+SRCS +=  \
+        mapping/AliMpPlaneAreaPadIterator.cxx  \
+        mapping/AliMpPlane.cxx  \
+        mapping/AliMpPlaneSegmentation.cxx  \
+        mapping/AliMpSectorPosition.cxx  \
+
+# Category graphics
+#
+SRCS +=  \
+        mapping/AliMpGraphContext.cxx  \
+        mapping/AliMpMotifPainter.cxx  \
+        mapping/AliMpRowPainter.cxx  \
+        mapping/AliMpRowSegmentPainter.cxx  \
+        mapping/AliMpSectorPainter.cxx  \
+        mapping/AliMpSubZonePainter.cxx  \
+        mapping/AliMpVPainter.cxx  \
+        mapping/AliMpZonePainter.cxx  \
+
+EINCLUDE := $(ALICE_ROOT)/MUON/mapping
diff --git a/MUON/mapping/AliMpArea.cxx b/MUON/mapping/AliMpArea.cxx
new file mode 100755 (executable)
index 0000000..3ae92ab
--- /dev/null
@@ -0,0 +1,162 @@
+// $Id$
+// Category: basic
+//
+// Class AliMpArea
+// ----------------
+// Class that defines a rectangle area positioned in plane..
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#include <Riostream.h>
+
+#include "AliMpArea.h"
+
+ClassImp(AliMpArea)
+
+
+//_____________________________________________________________________________
+AliMpArea::AliMpArea(const TVector2& position, const TVector2& dimensions)
+  : TObject(),
+    fPosition(position),
+    fDimensions(dimensions),
+    fValidity(true) {
+//
+  // Check dimensions
+  if (fDimensions.X() <= 0. || fDimensions.Y() <=0.) {
+    fDimensions = TVector2();
+    fValidity = false;
+  }  
+}
+
+//_____________________________________________________________________________
+AliMpArea::AliMpArea()
+  : TObject(),
+    fPosition(TVector2()),
+    fDimensions(TVector2()), 
+    fValidity(false) {
+//
+}
+
+//_____________________________________________________________________________
+AliMpArea::AliMpArea(const AliMpArea& rhs):
+  TObject(rhs),
+  fPosition(rhs.fPosition),
+  fDimensions(rhs.fDimensions) {
+//
+}
+
+//_____________________________________________________________________________
+AliMpArea::~AliMpArea() {
+//
+}
+
+//
+// operators
+//
+
+//______________________________________________________________________________
+AliMpArea& AliMpArea::operator = (const AliMpArea& right)
+{
+// Assignement operator
+
+  // check assignement to self
+  if (this == &right) return *this;
+
+  // base class assignement
+  TObject::operator=(right);
+
+  fPosition = right.fPosition;
+  fDimensions = right.fDimensions;
+  fValidity = right.fValidity;
+
+  return *this;
+} 
+
+//
+// public methods
+//
+
+//_____________________________________________________________________________
+Double_t AliMpArea::LeftBorder() const
+{
+// Returns the position of the left edge.
+// --
+
+  return fPosition.X() - fDimensions.X();
+}
+
+//_____________________________________________________________________________
+Double_t AliMpArea::RightBorder() const
+{
+// Returns the position of right edge.
+// --
+
+  return fPosition.X() + fDimensions.X();
+}
+
+//_____________________________________________________________________________
+Double_t AliMpArea::UpBorder() const
+{
+// Returns the position of the up edge.
+// --
+
+  return fPosition.Y() + fDimensions.Y();
+}
+
+//_____________________________________________________________________________
+Double_t AliMpArea::DownBorder() const
+{
+// Returns the position of the down edge.
+// --
+
+  return fPosition.Y() - fDimensions.Y();
+}
+
+//_____________________________________________________________________________
+TVector2 AliMpArea::LeftDownCorner() const
+{
+// Returns position of the left down corner.
+// --
+
+  return TVector2(LeftBorder(), DownBorder());
+}  
+
+//_____________________________________________________________________________
+TVector2 AliMpArea::LeftUpCorner() const
+{
+// Returns position of the left up corner.
+// --
+
+  return TVector2(LeftBorder(), UpBorder());
+}  
+
+//_____________________________________________________________________________
+TVector2 AliMpArea::RightDownCorner() const
+{
+// Returns position of the right down corner.
+// --
+
+  return TVector2(RightBorder(), DownBorder());
+}  
+
+
+//_____________________________________________________________________________
+TVector2 AliMpArea::RightUpCorner() const
+{
+// Returns position of the right up corner.
+// --
+
+  return TVector2(RightBorder(), UpBorder());
+}  
+
+//_____________________________________________________________________________
+ostream& operator<< (ostream &stream,const AliMpArea& area)
+{
+  stream << "Area: position: (" 
+         << area.Position().X() << ", " << area.Position().Y() << ") " 
+        << " dimensions: (" 
+         << area.Dimensions().X() << ", " << area.Dimensions().Y() << ") " 
+        << endl;
+  return stream;
+}
+
diff --git a/MUON/mapping/AliMpArea.h b/MUON/mapping/AliMpArea.h
new file mode 100755 (executable)
index 0000000..e863f80
--- /dev/null
@@ -0,0 +1,60 @@
+// $Id$
+// Category: basic
+//
+// Class AliMpArea
+// ----------------
+// Class that defines a rectangle area positioned in plane..
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#ifndef ALI_MP_AREA_H
+#define ALI_MP_AREA_H
+
+#include <TObject.h>
+#include <TVector2.h>
+
+class AliMpArea : public TObject
+{
+ public:
+  AliMpArea(const TVector2& position, const TVector2& dimensions);
+  AliMpArea(const AliMpArea& rhs);
+  AliMpArea();
+  virtual ~AliMpArea();
+
+  // operators
+  AliMpArea& operator = (const AliMpArea& right);
+
+  // methods
+  Double_t LeftBorder() const;
+  Double_t RightBorder() const;
+  Double_t UpBorder() const;
+  Double_t DownBorder() const;
+
+  TVector2 LeftDownCorner() const;
+  TVector2 LeftUpCorner() const;
+  TVector2 RightDownCorner() const;
+  TVector2 RightUpCorner() const;
+
+  // get methods
+  TVector2  Position() const;
+  TVector2  Dimensions() const;    
+  Bool_t    IsValid() const;
+  
+ private:
+  // data members
+  TVector2  fPosition;  // position
+  TVector2  fDimensions;// dimensions (half lengths)
+  Bool_t    fValidity;  // validity
+
+  ClassDef(AliMpArea,1) //utility class for area iterators
+};
+
+ostream& operator << (ostream &stream,const AliMpArea& area);
+
+// inline functions
+
+inline TVector2  AliMpArea::Position() const   { return fPosition; }
+inline TVector2  AliMpArea::Dimensions() const { return fDimensions; }    
+inline Bool_t    AliMpArea::IsValid() const    { return fValidity; }
+
+#endif //ALI_MP_AREA_H
diff --git a/MUON/mapping/AliMpBasicTypes.h b/MUON/mapping/AliMpBasicTypes.h
new file mode 100755 (executable)
index 0000000..1972396
--- /dev/null
@@ -0,0 +1,22 @@
+// $Id$
+// Category: basic
+//
+// AliMpBasicTypes
+// ---------------
+// Sytem dependent types definitions for basic category.
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#ifndef ALI_MP_BASIC_TYPES_H
+#define ALI_MP_BASIC_TYPES_H
+
+#include <utility>
+#include "AliMpPad.h"
+
+#ifdef __HP_aCC
+  typedef pair<AliMpPad, AliMpPad> PadPair;
+#else
+  typedef std::pair<AliMpPad, AliMpPad> PadPair;
+#endif
+
+#endif //ALI_MP_BASIC_TYPES_H
diff --git a/MUON/mapping/AliMpConnection.cxx b/MUON/mapping/AliMpConnection.cxx
new file mode 100755 (executable)
index 0000000..504f349
--- /dev/null
@@ -0,0 +1,42 @@
+// $Id$
+// Category: motif
+//
+// Class AliMpConnection
+// ----------------
+// Class that defines a connexion properties.
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#include "AliMpConnection.h"
+
+ClassImp(AliMpConnection)
+
+//_____________________________________________________________________________
+AliMpConnection::AliMpConnection(Int_t padNum, Int_t bergNum,Int_t kaptonNum,
+                                Int_t gassiNum) 
+  : TObject(),
+    fPadNum(padNum),
+    fBergNum(bergNum),
+    fKaptonNum(kaptonNum),
+    fGassiNum(gassiNum),
+    fOwner(0)
+{
+//
+}
+
+//_____________________________________________________________________________
+AliMpConnection::AliMpConnection() 
+  : TObject(),
+    fPadNum(-1),
+    fBergNum(-1),
+    fKaptonNum(-1),
+    fGassiNum(-1),
+    fOwner(0)
+{
+//
+}
+
+//_____________________________________________________________________________
+AliMpConnection::~AliMpConnection() {
+//  
+}
diff --git a/MUON/mapping/AliMpConnection.h b/MUON/mapping/AliMpConnection.h
new file mode 100755 (executable)
index 0000000..c3d933e
--- /dev/null
@@ -0,0 +1,58 @@
+// $Id$
+// Category: motif
+//
+// Class AliMpConnection
+// ---------------------
+// Class that defines a connexion properties.
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#ifndef ALI_MP_CONNECTION_H
+#define ALI_MP_CONNECTION_H
+
+#include <TObject.h>
+
+#include "AliMpMotifType.h"
+#include "AliMpIntPair.h"
+
+class AliMpConnection : public TObject
+{
+  public:
+    AliMpConnection();
+    AliMpConnection(Int_t padNum,Int_t bergNum,Int_t kaptonNum,Int_t gassiNum);
+    virtual ~AliMpConnection();
+
+    // methods
+
+    // accessors
+    Int_t GetBergNum()   const {return fBergNum;}
+    Int_t GetKaptonNum() const {return fKaptonNum;}
+    Int_t GetGassiNum()  const {return fGassiNum;}
+    Int_t GetPadNum()  const {return fPadNum;}
+    AliMpMotifType *GetOwner() const {return fOwner;}
+    
+    AliMpIntPair LocalIndices() const;
+    TString  PadName() const;
+    // modifiers
+    void SetOwner(AliMpMotifType *owner) {fOwner=owner;}
+
+  private:
+    // data members
+    Int_t fPadNum;    // Pad number
+    Int_t fBergNum;   // Berg connector number
+    Int_t fKaptonNum; // Kapton connector number
+    Int_t fGassiNum;  // Gassiplex channel number
+    AliMpMotifType *fOwner; //The motif type which contains this connection
+
+  ClassDef(AliMpConnection,1)  // Connection description
+};
+
+// inline functions
+
+inline TString AliMpConnection::PadName() const 
+{ return fOwner->PadName(fPadNum); }
+
+inline AliMpIntPair AliMpConnection::LocalIndices() const
+{ return fOwner->FindLocalIndicesByConnection(this);}
+
+#endif //ALI_MP_CONNECTION_H
diff --git a/MUON/mapping/AliMpConstants.cxx b/MUON/mapping/AliMpConstants.cxx
new file mode 100755 (executable)
index 0000000..d4c4c37
--- /dev/null
@@ -0,0 +1,50 @@
+// $Id$
+// Category: basic
+//
+// Class AliMpConstants
+// --------------------
+// Class for globally used constants definition.
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#include <TMath.h>
+
+#include "AliMpConstants.h"
+
+ClassImp(AliMpConstants)
+
+// static data
+const Double_t AliMpConstants::fgkLengthTolerance = 1e-04; // 0.1 mum;
+const Double_t AliMpConstants::fgkLengthStep = 1.; // 1 mm;
+const Int_t    AliMpConstants::fgkStartPadIndex = 1;
+
+//_____________________________________________________________________________
+AliMpConstants::AliMpConstants()
+  : TObject() {
+//  
+}
+
+//_____________________________________________________________________________
+AliMpConstants::~AliMpConstants() {
+//
+}
+
+//_____________________________________________________________________________
+Bool_t  AliMpConstants::IsEqual(Double_t length1, Double_t length2)
+{
+// Compares lengths within the length tolerance.
+// ---
+
+  return TMath::Abs(length1 - length2) < fgkLengthTolerance;
+}  
+
+
+//_____________________________________________________________________________
+Bool_t  AliMpConstants::IsEqual(const TVector2& v1, const TVector2& v2)
+{
+// Compares x, y vector coordinates within the length tolerance.
+// ---
+
+  return (  TMath::Abs(v1.X() - v2.X()) 
+          + TMath::Abs(v1.Y() - v2.Y())) < 2.*fgkLengthTolerance;
+}
diff --git a/MUON/mapping/AliMpConstants.h b/MUON/mapping/AliMpConstants.h
new file mode 100755 (executable)
index 0000000..50ba66e
--- /dev/null
@@ -0,0 +1,50 @@
+// $Id$
+// Category: basic
+//
+// Class AliMpConstants
+// --------------------
+// Class for globally used constants definition.
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#ifndef ALI_MP_CONSTANTS_H
+#define ALI_MP_CONSTANTS_H
+
+#include <TObject.h>
+#include <TVector2.h>
+
+class AliMpConstants : public TObject
+{
+ public:
+  AliMpConstants();
+  virtual ~AliMpConstants();
+
+  // static compare methods
+  static Bool_t  IsEqual(Double_t length1, Double_t length2);
+  static Bool_t  IsEqual(const TVector2& v1, const TVector2& v2);
+
+  // static get methods
+  static Double_t LengthTolerance();
+  static Double_t LengthStep();
+  static Int_t    StartPadIndex();
+
+ private:
+  // unused derived functions
+  virtual Bool_t  IsEqual(const TObject*) const { return true; }
+  // static data members
+  static const Double_t  fgkLengthTolerance;// the length precision for tests
+  static const Double_t  fgkLengthStep;     // the step in length used to move from
+                                            // a geometric border inside (pad, motif)
+  static const Int_t     fgkStartPadIndex;  // global pad indices start value
+
+  ClassDef(AliMpConstants,1) //Class for globally used constants definition
+};
+
+// inline functions
+
+inline Double_t AliMpConstants::LengthTolerance() {return fgkLengthTolerance;}
+inline Double_t AliMpConstants::LengthStep()      {return fgkLengthStep;}
+inline Int_t    AliMpConstants::StartPadIndex()   {return fgkStartPadIndex;}
+
+#endif //ALI_MP_CONSTANTS_H
diff --git a/MUON/mapping/AliMpDirection.h b/MUON/mapping/AliMpDirection.h
new file mode 100755 (executable)
index 0000000..4377414
--- /dev/null
@@ -0,0 +1,19 @@
+// $Id$
+// Category: basic
+//
+// Enum AliMpDirection
+// -------------------
+// Enumeration for the directions in a plane.
+//
+// Authors: David Guez, IPN Orsay
+
+#ifndef ALI_MP_DIRECTION_H
+#define ALI_MP_DIRECTION_H
+
+enum AliMpDirection 
+{
+  kX, // direction in x
+  kY  // direction in y
+};
+
+#endif //ALI_MP_DIRECTION_H
diff --git a/MUON/mapping/AliMpFiles.cxx b/MUON/mapping/AliMpFiles.cxx
new file mode 100755 (executable)
index 0000000..307bde5
--- /dev/null
@@ -0,0 +1,173 @@
+// $Id$
+// Category: sector
+//
+// Class AliMpFiles
+// ----------------
+// Class for generating file names and paths.
+// The input files:
+// zones.dat, zones_special.dat - sector description
+// motif*.dat   - motif description (generated from Exceed)
+// padPos*.dat  - pad positions in motif
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#include <stdlib.h>
+
+#include "AliMpFiles.h"
+
+ClassImp(AliMpFiles)
+
+// static data members
+
+AliMpFiles* AliMpFiles::fgInstance = 0;
+const TString AliMpFiles::fgkDefaultTop = getenv("MINSTALL");    
+const TString AliMpFiles::fgkDataDir = "/data";;
+const TString AliMpFiles::fgkBendingDir = "/bending_plane/";;
+const TString AliMpFiles::fgkNonBendingDir = "/non-bending_plane/";;
+const TString AliMpFiles::fgkSector  = "zones"; 
+const TString AliMpFiles::fgkSectorSpecial = "zones_special";
+const TString AliMpFiles::fgkMotifPrefix   = "motif";  
+const TString AliMpFiles::fgkMotifSpecialPrefix ="motifSpecial";
+const TString AliMpFiles::fgkPadPosPrefix  = "padPos"; 
+const TString AliMpFiles::fgkDataExt = ".dat";      
+const TString AliMpFiles::fgkBergToGCFileName = "/bergToGC";      
+
+//______________________________________________________________________________
+AliMpFiles::AliMpFiles()
+  : fTop(fgkDefaultTop)
+{
+//    
+  if (fgInstance) {
+    Fatal("AliMpFiles", 
+          "AliMpFiles: attempt to create two instances of singleton.");
+  }
+      
+  fgInstance = this;      
+}
+  
+//______________________________________________________________________________
+AliMpFiles::AliMpFiles(const AliMpFiles& right) {
+// 
+  Fatal("AliMpFiles", "Attempt to copy AliMpFiles singleton.");
+}
+
+
+//______________________________________________________________________________
+AliMpFiles::~AliMpFiles() {
+//
+
+  fgInstance = 0;      
+}
+
+// operators
+
+//______________________________________________________________________________
+AliMpFiles& AliMpFiles::operator=(const AliMpFiles& right)
+{
+  // check assignement to self
+  if (this == &right) return *this;
+
+  Fatal("operator=", "Attempt to assign AliMpFiles singleton.");
+    
+  return *this;  
+}    
+          
+//
+// private methods
+//
+
+//______________________________________________________________________________
+TString AliMpFiles::PlaneDataDir(AliMpPlaneType plane) const
+{
+// Returns path to data files with sector description
+// for a specified plane.
+// ---
+
+  switch (plane) {
+    case kBendingPlane:
+       return fTop + fgkDataDir + fgkBendingDir;
+       ;;
+    case kNonBendingPlane:   
+       return fTop + fgkDataDir + fgkNonBendingDir;
+       ;;
+  }   
+  
+  Fatal("PlaneDataDir", "Incomplete switch on AliMpPlaneType");
+  return TString();
+}
+
+//
+// public methods
+//
+
+//______________________________________________________________________________
+AliMpFiles* AliMpFiles::Instance() 
+{ 
+// Return the singleton instance;
+// Creates it if it does not yet exist,
+//
+// ---
+
+  if (!fgInstance)  fgInstance = new AliMpFiles(); 
+  
+  return fgInstance; 
+}
+
+//______________________________________________________________________________
+TString AliMpFiles::SectorFilePath(AliMpPlaneType plane) const
+{
+// Returns path to data file with sector description.
+// ---
+  return TString(PlaneDataDir(plane) + fgkSector + fgkDataExt);
+}
+    
+//______________________________________________________________________________
+TString AliMpFiles::SectorSpecialFilePath(AliMpPlaneType plane) const
+{
+// Returns path to data file with sector special description (irregular motifs).
+// ---
+
+  return TString(PlaneDataDir(plane) + fgkSectorSpecial + fgkDataExt);
+}
+    
+//______________________________________________________________________________
+TString AliMpFiles::MotifFilePath(AliMpPlaneType plane, 
+                                  const TString& motifTypeID) const
+{
+// Returns path to data file for a given motif type.
+// ---
+
+  return TString(PlaneDataDir(plane) + fgkMotifPrefix +  motifTypeID + fgkDataExt);
+}
+    
+//______________________________________________________________________________
+TString AliMpFiles::PadPosFilePath(AliMpPlaneType plane, 
+                                   const TString& motifTypeID) const
+{
+// Returns path to data file with pad positions for a given motif type.
+// ---
+
+  return TString(PlaneDataDir(plane) + fgkPadPosPrefix +  motifTypeID + fgkDataExt);
+}
+
+//______________________________________________________________________________ 
+TString AliMpFiles::MotifSpecialFilePath(AliMpPlaneType plane,
+                                         const TString& motifID) const
+{
+// Returns path to data file with pad dimensions for a given motif ID.
+// ---
+
+  return TString(PlaneDataDir(plane) + fgkMotifSpecialPrefix + motifID + fgkDataExt);
+
+}
+
+//______________________________________________________________________________ 
+TString AliMpFiles::BergToGCFilePath() const
+{
+// Returns the path of the file which describes the correspondance between
+// the berg number and the gassiplex channel.
+// ---
+
+  return fTop+fgkDataDir+fgkBergToGCFileName+fgkDataExt;
+}
diff --git a/MUON/mapping/AliMpFiles.h b/MUON/mapping/AliMpFiles.h
new file mode 100755 (executable)
index 0000000..5aacc30
--- /dev/null
@@ -0,0 +1,83 @@
+// $Id$
+// Category: sector
+//
+// Class AliMpFiles
+// ----------------
+// Class for generating file names and paths.
+// The input files:
+// zones.dat, zones_special.dat - sector description
+// motif*.dat   - motif description (generated from Exceed)
+// padPos*.dat  - pad positions in motif
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#ifndef M_FILES_H
+#define M_FILES_H
+
+#include <TObject.h>
+#include <TString.h>
+
+#include "AliMpPlaneType.h"
+
+class AliMpFiles : public TObject
+{
+  public:
+    AliMpFiles();
+    // --> protected
+    //AliMpFiles(const AliMpFiles& right);
+    virtual ~AliMpFiles();
+    
+    // static access method
+    static AliMpFiles* Instance();
+
+    // methods
+    TString SectorFilePath(AliMpPlaneType plane) const;
+    TString SectorSpecialFilePath(AliMpPlaneType plane) const;
+    TString MotifFilePath(AliMpPlaneType plane, 
+                          const TString& motifTypeID) const;
+    TString MotifSpecialFilePath(AliMpPlaneType plane, 
+                          const TString& motifID) const;
+    TString PadPosFilePath(AliMpPlaneType plane, 
+                          const TString& motifTypeID) const;
+    TString BergToGCFilePath() const;
+
+    // set methods
+    void SetTopPath(const TString& topPath);
+                             
+  protected:
+    AliMpFiles(const AliMpFiles& right);
+    
+    // operators
+    AliMpFiles& operator=(const AliMpFiles& right);    
+    
+  private: 
+    // methods
+    TString PlaneDataDir(AliMpPlaneType plane) const; 
+  
+    // static data members  
+    static AliMpFiles*   fgInstance;      //this instance
+    static const TString fgkDefaultTop;   //top directory path (default)
+    static const TString fgkDataDir;      //data directory
+    static const TString fgkBendingDir;   //bending plane directory
+    static const TString fgkNonBendingDir;//non-bending plane directory
+    static const TString fgkSector;       //sector data file name
+    static const TString fgkSectorSpecial;//sector special data file name
+    static const TString fgkMotifPrefix;  //motif data file name
+    static const TString fgkMotifSpecialPrefix; //special motif data file name 
+    static const TString fgkPadPosPrefix; //pad position data file name
+    static const TString fgkDataExt;      //file extension
+    static const TString fgkBergToGCFileName; //name of the file with BergToGC mapping
+    
+    // data members
+    TString  fTop; // top directory path
+    
+
+  ClassDef(AliMpFiles, 1) //File names and paths 
+};  
+
+// inline functions
+
+inline void AliMpFiles::SetTopPath(const TString& topPath)
+{ fTop = topPath; }
+
+#endif //M_FILES_H
diff --git a/MUON/mapping/AliMpGraphContext.cxx b/MUON/mapping/AliMpGraphContext.cxx
new file mode 100755 (executable)
index 0000000..d21fa68
--- /dev/null
@@ -0,0 +1,92 @@
+// $Id$
+// Category: graphics
+//
+// Class AliMpGraphContext
+// -----------------------
+// Class describing a the correspondance between a given area
+// in pad, and a zone of real (cm) position
+//
+// Author: David GUEZ, IPN Orsay
+
+#include "AliMpGraphContext.h"
+
+ClassImp(AliMpGraphContext)
+
+AliMpGraphContext *AliMpGraphContext::fgInstance = 0;
+GraphContextVector AliMpGraphContext::fgStack;
+
+// private constructor
+AliMpGraphContext::AliMpGraphContext():
+  TObject(),
+  fPadPosition(TVector2(0.5,0.5)),
+  fPadDimensions(TVector2(0.49,0.49)),
+  fRealPosition(TVector2(0.,0.)),
+  fRealDimensions(TVector2(1,1))
+{
+  fColor = 20;
+  // default constructor (private)
+}
+AliMpGraphContext *AliMpGraphContext::Instance()
+{
+  // return or create a unique instance of this class
+  if (fgInstance) return fgInstance;
+  fgInstance = new AliMpGraphContext;
+  return fgInstance;
+}
+
+TVector2 AliMpGraphContext::RealToPad(const TVector2 &position) const
+{
+  // transform a real position into its equivalent position in the pad
+  Double_t x=position.X();
+  Double_t y=position.Y();
+  x-= (fRealPosition.X()-fRealDimensions.X());
+  x/=fRealDimensions.X();
+  x*=fPadDimensions.X();
+  x+= (fPadPosition.X()-fPadDimensions.X() );
+
+  y-= (fRealPosition.Y()-fRealDimensions.Y());
+  y/=fRealDimensions.Y();
+  y*=fPadDimensions.Y();
+  y+= (fPadPosition.Y()-fPadDimensions.Y() );
+
+  return TVector2(x,y);
+}
+
+
+
+void AliMpGraphContext::RealToPad(const TVector2 &position,
+                             const TVector2 &dimensions,
+                             TVector2 &padPosition,
+                             TVector2 &padDimensions) const
+{
+  // transform the real area (position,dimensions) to
+  // its equivalent pad area
+  padPosition = RealToPad(position);
+  padDimensions = 
+    TVector2(dimensions.X()*fPadDimensions.X()/fRealDimensions.X(),
+            dimensions.Y()*fPadDimensions.Y()/fRealDimensions.Y());
+
+}
+void AliMpGraphContext::SetPadPosForReal(const TVector2 &position,
+                                    const TVector2 &dimensions)
+{
+  // Set the pad area from the actual one
+  // corresponding to the given real area.
+  RealToPad(position,dimensions,fPadPosition,fPadDimensions);
+}
+void AliMpGraphContext::Push() const
+{
+  // Store the current configuration
+  AliMpGraphContext *save = new AliMpGraphContext(*this);
+  fgStack.push_back(save);
+}
+void AliMpGraphContext::Pop()
+{
+  // restore the last saved configuration
+  if (!fgStack.empty()){
+    AliMpGraphContext *obj = fgStack.back();
+    *this = *obj;
+    fgStack.pop_back();
+    delete obj;
+  }
+}
diff --git a/MUON/mapping/AliMpGraphContext.h b/MUON/mapping/AliMpGraphContext.h
new file mode 100755 (executable)
index 0000000..0fef553
--- /dev/null
@@ -0,0 +1,71 @@
+// $Id$
+// Category: graphics
+//
+// Class AliMpGraphContext
+// -----------------------
+// Class describing the correspondance between a given area
+// in pad, and a zone of real (cm) position
+//
+// Author: David GUEZ, IPN Orsay
+
+#ifndef ALI_MP_GRAPH_CONTEXT
+#define ALI_MP_GRAPH_CONTEXT
+
+#include <TObject.h>
+#include <TVector2.h>
+
+#include "AliMpGraphicsTypes.h"
+
+class MPainter;
+
+class AliMpGraphContext : public TObject{
+ public:
+  void Push() const;
+  void Pop();
+  static AliMpGraphContext *Instance();
+
+  // set methods
+
+  void SetPadPosition(const TVector2 &position){fPadPosition=position;}
+  void SetPadDimensions(const TVector2 &dimensions){fPadDimensions=dimensions;}
+  void SetRealPosition(const TVector2 &position){fRealPosition=position;}
+  void SetRealDimensions(const TVector2 &dimensions){fRealDimensions=dimensions;}
+  void SetColor(Int_t color){fColor=color;}
+
+  // get methods
+  TVector2 GetPadPosition() const {return fPadPosition;}
+  TVector2 GetPadDimensions() const {return fPadDimensions;}
+  TVector2 GetRealPosition() const{return fRealPosition;}
+  TVector2 GetRealDimensions() const{return fRealDimensions;}
+  Int_t GetColor() const {return fColor;}
+
+  //methods
+  TVector2 RealToPad(const TVector2 &position) const;
+  void RealToPad(const TVector2 &position
+                ,const TVector2 &dimensions,
+                TVector2 &padPosition,
+                TVector2 &padDimensions) const;
+  void SetPadPosForReal(const TVector2 &position,const TVector2 &dimensions);
+
+ private:
+  //private constructor (not instanciable from outside)
+  AliMpGraphContext();
+
+  // static data members
+  static AliMpGraphContext *fgInstance;   // the global instance
+  static GraphContextVector fgStack;  // the object statck
+
+  //data members
+  Int_t    fColor;          // color to use
+  TVector2 fPadPosition;    // Position of the pad area where to draw
+  TVector2 fPadDimensions;   // Dimensions of the pad area where to draw
+
+  TVector2 fRealPosition;   // Position of the real area to draw
+  TVector2 fRealDimensions;  // Dimensions of the real area to draw
+
+  ClassDef(AliMpGraphContext,1) // Correspondance pad area/real world
+};
+
+#endif //ALI_MP_GRAPH_CONTEXT
+
+
diff --git a/MUON/mapping/AliMpGraphicsTypes.h b/MUON/mapping/AliMpGraphicsTypes.h
new file mode 100644 (file)
index 0000000..9a39b93
--- /dev/null
@@ -0,0 +1,23 @@
+// $Id$
+// Category: graphics
+//
+// AliMpGraphicsTypes
+// ------------------
+// Sytem dependent types definitions for graphics category.
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#ifndef ALI_MP_GRAPHICS_TYPES_H
+#define ALI_MP_GRAPHICS_TYPES_H
+
+#include <vector>
+
+class AliMpGraphContext;
+
+#ifdef __HP_aCC
+  typedef vector<AliMpGraphContext*> GraphContextVector;
+#else
+  typedef std::vector<AliMpGraphContext*> GraphContextVector;
+#endif
+
+#endif //ALI_MP_GRAPHICS_TYPES_H
diff --git a/MUON/mapping/AliMpIntPair.cxx b/MUON/mapping/AliMpIntPair.cxx
new file mode 100755 (executable)
index 0000000..ee3b20a
--- /dev/null
@@ -0,0 +1,176 @@
+// $Id$
+// Category: basic
+//
+// Class AliMpIntPair
+// --------------
+// Class that defines the pair of integers.
+// The pair created by the default constructor is in invalide state,
+// setting one of values changes the state to valid.
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#include <Riostream.h>
+
+#include "AliMpIntPair.h"
+
+ClassImp(AliMpIntPair)
+
+
+///////////////////////////////////////////////////
+//
+// This class is a replacement for the standard STL
+// pair<int,int> class, which can not be handed
+// by the normal ROOT automatic streamer
+// (at least in the ROOT version 3.03/03)
+//
+///////////////////////////////////////////////////
+
+
+//_____________________________________________________________________________
+AliMpIntPair::AliMpIntPair(Int_t ix,Int_t iy)
+  : TObject(),
+    fFirst(ix),
+    fSecond(iy),
+    fValidity(true) {
+//
+}
+
+//_____________________________________________________________________________
+AliMpIntPair::AliMpIntPair(Int_t ix,Int_t iy, Bool_t validity)
+  : TObject(),
+    fFirst(ix),
+    fSecond(iy),
+    fValidity(validity) {
+//
+}
+
+//_____________________________________________________________________________
+AliMpIntPair::AliMpIntPair()
+  : TObject(),
+    //fFirst(9999),
+    //fSecond(9999),
+    fFirst(0),
+    fSecond(0),
+    fValidity(false) {
+//
+}
+//_____________________________________________________________________________
+AliMpIntPair::AliMpIntPair(const AliMpIntPair& src):
+  TObject(src),
+  fFirst(src.fFirst),
+  fSecond(src.fSecond),
+  fValidity(src.fValidity)
+{
+
+}
+
+//_____________________________________________________________________________
+AliMpIntPair::~AliMpIntPair() {
+//
+}
+
+//_____________________________________________________________________________
+Bool_t AliMpIntPair::operator< (const AliMpIntPair& pos2) const
+{
+  // fFirst prior to fSecond
+  if (fFirst<pos2.fFirst) return kTRUE;
+  if (fFirst>pos2.fFirst) return kFALSE;
+  if (fSecond<pos2.fSecond) return kTRUE;
+  return kFALSE;
+}
+
+//_____________________________________________________________________________
+Bool_t AliMpIntPair::operator== (const AliMpIntPair& pos2) const
+{
+  // are this and pos2 equals?
+  
+  // one valid, one invalid
+  if (fValidity != pos2.fValidity) return false;
+  
+  // both invalid
+  if (!fValidity) return true;
+  
+  // both valid
+  return (fFirst==pos2.fFirst) && (fSecond==pos2.fSecond);
+}
+
+//_____________________________________________________________________________
+Bool_t AliMpIntPair::operator!= (const AliMpIntPair& pos2) const
+{
+  // are this and pos2 equals?
+  return !(*this == pos2);
+}
+
+//_____________________________________________________________________________
+AliMpIntPair& AliMpIntPair::operator=(const AliMpIntPair& src) 
+{
+  // check assignement to self
+  if (this == &src) return *this;
+
+  // base class assignement
+  TObject::operator=(src);
+
+  // assignement operator
+  fFirst = src.fFirst;
+  fSecond = src.fSecond;
+  fValidity = src.fValidity;
+  
+  return *this;
+}
+
+//_____________________________________________________________________________
+void AliMpIntPair::operator += (const AliMpIntPair& op)
+{
+  // incrementation operator
+  fFirst += op.fFirst;
+  fSecond += op.fSecond;
+  
+  // operation only on valid pairs
+  fValidity = fValidity && op.fValidity;
+}
+//_____________________________________________________________________________
+void AliMpIntPair::operator -= (const AliMpIntPair& op)
+{
+  // decrementation operator
+  fFirst -= op.fFirst;
+  fSecond -= op.fSecond;
+
+  // operation only on valid pairs
+  fValidity = fValidity && op.fValidity;
+}
+
+//_____________________________________________________________________________
+AliMpIntPair operator-(const AliMpIntPair& op1,const AliMpIntPair& op2)
+{
+  return AliMpIntPair(op1.GetFirst()-op2.GetFirst(),
+                  op1.GetSecond()-op2.GetSecond(),
+                 op1.IsValid() && op2.IsValid());
+}
+//_____________________________________________________________________________
+AliMpIntPair operator+(const AliMpIntPair& op1,const AliMpIntPair& op2)
+{
+  return AliMpIntPair(op1.GetFirst()+op2.GetFirst(),
+                  op1.GetSecond()+op2.GetSecond(),
+                 op1.IsValid() && op2.IsValid());
+}
+//_____________________________________________________________________________
+AliMpIntPair operator*(const AliMpIntPair& op1,const AliMpIntPair& op2)
+{
+  return AliMpIntPair(op1.GetFirst()*op2.GetFirst(),
+                  op1.GetSecond()*op2.GetSecond(),
+                 op1.IsValid() && op2.IsValid());
+}
+//_____________________________________________________________________________
+ostream& operator<< (ostream &stream,const AliMpIntPair& op)
+{
+  if (op.IsValid()) {
+    stream << '(';
+    stream << op.GetFirst()<<','<<op.GetSecond()<<')';
+    return stream;
+  }  
+  else { 
+    stream << "AliMpIntPair::Invalid";
+    return stream;
+  }  
+}
+
diff --git a/MUON/mapping/AliMpIntPair.h b/MUON/mapping/AliMpIntPair.h
new file mode 100755 (executable)
index 0000000..dcb78ac
--- /dev/null
@@ -0,0 +1,60 @@
+// $Id$
+// Category: basic
+//
+// Class AliMpIntPair
+// ------------------
+// Class that defines the pair of integers.
+// The pair created by the default constructor is in invalide state,
+// setting one of values changes the state to valid.
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#ifndef ALI_MP_INT_PAIR_H
+#define ALI_MP_INT_PAIR_H
+
+#include <TObject.h>
+
+class AliMpIntPair : public TObject
+{
+ public:
+  AliMpIntPair(Int_t ix,Int_t iy);
+  AliMpIntPair(Int_t ix,Int_t iy, Bool_t validity);
+  AliMpIntPair(const AliMpIntPair& right);
+  AliMpIntPair();
+  virtual ~AliMpIntPair();
+
+  // operators  
+  Bool_t operator <  (const AliMpIntPair& pos2) const;
+  Bool_t operator == (const AliMpIntPair& pos2) const;
+  Bool_t operator != (const AliMpIntPair& pos2) const;
+  AliMpIntPair& operator = (const AliMpIntPair& src) ;
+  void operator += (const AliMpIntPair& op);
+  void operator -= (const AliMpIntPair& op);
+
+  // static get methods
+  static AliMpIntPair Invalid() {return AliMpIntPair();}
+
+  // get methods
+  Int_t  GetFirst() const  {return fFirst;}
+  Int_t  GetSecond() const {return fSecond;}
+  Bool_t IsValid() const   {return fValidity;}
+
+  // set methods
+  void SetFirst(Int_t ix)  {fFirst=ix; fValidity=true; }
+  void SetSecond(Int_t iy) {fSecond=iy; fValidity=true;}
+  
+ private:
+  // data members
+  Int_t   fFirst;    // position along x
+  Int_t   fSecond;   // position along y
+  Bool_t  fValidity; // validity
+
+  ClassDef(AliMpIntPair,1) //utility class for the motif type
+};
+
+AliMpIntPair operator + (const AliMpIntPair& op1,const AliMpIntPair& op2);
+AliMpIntPair operator - (const AliMpIntPair& op1,const AliMpIntPair& op2);
+AliMpIntPair operator * (const AliMpIntPair& op1,const AliMpIntPair& op2);
+ostream& operator << (ostream &stream,const AliMpIntPair& op);
+
+#endif //ALI_MP_INT_PAIR_H
diff --git a/MUON/mapping/AliMpMotif.cxx b/MUON/mapping/AliMpMotif.cxx
new file mode 100755 (executable)
index 0000000..88830e6
--- /dev/null
@@ -0,0 +1,86 @@
+// $Id$
+// Category: motif
+//
+// Class AliMpMotif
+// ----------------
+// Class that defines a motif with its unique ID
+// and the motif type.
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#include "AliMpMotif.h"
+#include "AliMpMotifType.h"
+#include "AliMpIntPair.h"
+
+ClassImp(AliMpMotif)
+
+//_____________________________________________________________________________
+AliMpMotif::AliMpMotif()
+  : AliMpVMotif(),
+    fPadDimensions(TVector2(0.,0.))
+{
+  //default dummy constructor
+}
+
+//_____________________________________________________________________________
+AliMpMotif::AliMpMotif(const TString &id, AliMpMotifType *motifType,
+                      const TVector2& padDimension)
+  : AliMpVMotif(id,motifType),
+    fPadDimensions(padDimension)
+{
+  // Normal constructor.
+  // The dimension in a given direction is calculated by
+  // multiplying the total dimension by the number of pads
+
+}
+
+//_____________________________________________________________________________
+TVector2 AliMpMotif::GetPadDimensions(const AliMpIntPair& localIndices) const
+{
+  // gives the dimension of the specified pad in the motif
+
+  if (GetMotifType()->HasPad(localIndices))
+    return fPadDimensions;
+  else {
+    Warning("GetPadDimensions","indices outside range");
+    return TVector2(0.,0.);
+  }
+}
+
+//_____________________________________________________________________________
+TVector2 AliMpMotif::Dimensions() const
+{
+  // gives the dimension of the motif
+
+  return TVector2(GetMotifType()->GetNofPadsX()*fPadDimensions.X(),
+               GetMotifType()->GetNofPadsY()*fPadDimensions.Y());
+}
+
+//_____________________________________________________________________________
+TVector2 AliMpMotif::PadPositionLocal(const AliMpIntPair& localIndices) const 
+{
+  // gives the local position of the pad number (ix,iy)
+  // (0,0 is the center of the motif)
+
+  TVector2 dim=Dimensions();
+  return TVector2((2.*localIndices.GetFirst()+1.)*fPadDimensions.X()-dim.X(),
+                 (2.*localIndices.GetSecond()+1.)*fPadDimensions.Y()-dim.Y());
+}
+
+//_____________________________________________________________________________
+AliMpIntPair AliMpMotif::PadIndicesLocal(const TVector2& localPos) const
+{
+  // return the pad indices from a given local position
+  // or (-1,-1) if this position doesn't correspond to any valid
+  // connection
+
+  TVector2 lowerLeft = localPos+Dimensions();
+  Int_t ix = (Int_t)(lowerLeft.X()/(2.*fPadDimensions.X()));
+  Int_t iy = (Int_t)(lowerLeft.Y()/(2.*fPadDimensions.Y()));
+  
+  if (!GetMotifType()->FindConnectionByLocalIndices(AliMpIntPair(ix,iy))) {
+    //Warning("PadIndicesLocal","Position outside motif");
+    return AliMpIntPair::Invalid();
+  }
+  return AliMpIntPair(ix,iy);
+}
diff --git a/MUON/mapping/AliMpMotif.h b/MUON/mapping/AliMpMotif.h
new file mode 100755 (executable)
index 0000000..ef2ac53
--- /dev/null
@@ -0,0 +1,52 @@
+// $Id$
+// Category: motif
+//
+// Class AliMpMotif
+// ----------------
+// Class that defines a motif with its unique ID
+// and the motif type.
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#ifndef M_MOTIF_H
+#define M_MOTIF_H
+
+#include <TObject.h>
+#include <TString.h>
+#include <TVector2.h>
+
+#include "AliMpVMotif.h"
+
+class AliMpMotif : public AliMpVMotif
+{
+ public:
+  AliMpMotif(const TString &id,AliMpMotifType *motifType, const TVector2& padDimension);
+  AliMpMotif();
+
+  // Access methods
+  virtual Int_t    GetNofPadDimensions() const;
+  virtual TVector2 GetPadDimensions(Int_t i = 0) const;
+  virtual TVector2 GetPadDimensions(const AliMpIntPair& localIndices) const;
+
+  // Geometry
+  virtual TVector2 Dimensions() const;
+
+  // Other methods
+  virtual TVector2 PadPositionLocal(const AliMpIntPair& localIndices) const;
+  virtual AliMpIntPair PadIndicesLocal(const TVector2& localPos) const;
+
+ private:
+  // methods
+
+  // data members 
+  TVector2    fPadDimensions; //pad dimensions (halflength x, y size) 
+
+  ClassDef(AliMpMotif,1) // A motif with its ID
+};
+
+// inline functions
+
+inline Int_t    AliMpMotif::GetNofPadDimensions() const { return 1; }
+inline TVector2 AliMpMotif::GetPadDimensions(Int_t i) const { return fPadDimensions; }  
+
+#endif //M_MOTIF_H
diff --git a/MUON/mapping/AliMpMotifMap.cxx b/MUON/mapping/AliMpMotifMap.cxx
new file mode 100755 (executable)
index 0000000..1e6b5f3
--- /dev/null
@@ -0,0 +1,434 @@
+// $Id$
+// Category: motif
+//
+// Class AliMpMotifMap
+// -------------------
+// Class describing the motif map container, where motifs are
+// mapped to their string IDs.
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#include <Riostream.h>
+
+#include "AliMpMotifMap.h"
+#include "AliMpVMotif.h"
+#include "AliMpMotif.h"
+#include "AliMpMotifSpecial.h"
+#include "AliMpMotifType.h"
+#include "AliMpMotifPosition.h"
+
+ClassImp(AliMpMotifMap)
+
+//_____________________________________________________________________________
+AliMpMotifMap::AliMpMotifMap() 
+  : TObject()
+{
+//
+}
+
+//_____________________________________________________________________________
+AliMpMotifMap::~AliMpMotifMap() {
+//  
+
+  // Delete all registered motifs, motif types, motif positions
+  
+  for (MotifMapIterator im=fMotifs.begin(); im != fMotifs.end(); im++) {
+    delete im->second;
+  }  
+  
+  for (MotifTypeMapIterator it=fMotifTypes.begin(); 
+       it != fMotifTypes.end(); it++) {
+    delete it->second;
+  }
+  
+  for (MotifPositionMapIterator ip=fMotifPositions.begin(); 
+       ip != fMotifPositions.end(); ip++) {
+    delete ip->second;
+  }  
+}
+
+// 
+// private methods
+//
+
+//_____________________________________________________________________________
+void  AliMpMotifMap::PrintMotifs() const
+{
+// Prints all the motifs and their motif types 
+// for all motifs in the motifs map.
+// ---
+
+  if (fMotifs.size()) {
+    cout << "Dump of Motif Map - " << fMotifs.size() << " entries:" << endl;
+    Int_t counter = 0;        
+    for (MotifMapIterator i=fMotifs.begin(); i != fMotifs.end(); i++) {
+      const TString& id  = (*i).first;
+      AliMpVMotif* motif = (*i).second;
+      cout << "Map element " 
+           << setw(3) << counter++ << "   " 
+           << id.Data() << "   " 
+          << motif->GetID().Data() << "  "
+          << motif->GetMotifType()->GetID() << "    "
+          << motif->Dimensions().X() << " "
+          << motif->Dimensions().Y()
+          << endl;
+    }
+    cout << endl;
+  }
+}
+
+//_____________________________________________________________________________
+void  AliMpMotifMap::PrintMotifTypes() const
+{
+// Prints all the the motifs types and their motif dimensions
+// for all motif types in the motif types map.
+// ---
+
+  if (fMotifTypes.size()) {
+    cout << "Dump of Motif Type Map - " << fMotifTypes.size() << " entries:" << endl;
+    Int_t counter = 0;        
+    for (MotifTypeMapIterator i=fMotifTypes.begin(); i != fMotifTypes.end(); i++) {
+      const TString& id  = (*i).first;
+      AliMpMotifType* motifType = (*i).second;
+      cout << "Map element " 
+           << setw(3) << counter++ << "   " 
+           << id.Data() << "   " 
+          << motifType->GetID().Data() << "  "
+          << motifType->GetNofPadsX() << "  " 
+          << motifType->GetNofPadsY() << "  "
+          << endl;
+    }
+    cout << endl;
+  }
+}
+
+//_____________________________________________________________________________
+void  AliMpMotifMap::PrintMotifPositions() const
+{
+// Prints all the the motifs positions.
+// ---
+
+  if (fMotifPositions.size()) {
+    cout << "Dump of Motif Position Map - " << fMotifPositions.size() << " entries:" << endl;
+    Int_t counter = 0;        
+    for (MotifPositionMapIterator i=fMotifPositions.begin(); 
+                                  i != fMotifPositions.end(); i++) {
+
+      AliMpMotifPosition* motifPosition = (*i).second;
+      cout << "Map element " 
+           << setw(3) << counter++ << "   " 
+          << motifPosition->GetID() << "  "
+          << motifPosition->GetMotif()->GetID() << "  " 
+          << motifPosition->Position().X() << "  "
+          << motifPosition->Position().Y() << "    "
+          << endl;
+    }
+    cout << endl;
+  }
+}
+
+//_____________________________________________________________________________
+void  AliMpMotifMap::PrintMotifPositions2() const
+{
+// Prints all the the motifs positions from the second map
+// (by global indices)
+// ---
+
+  if (fMotifPositions2.size()) {
+    cout << "Dump of Motif Position Map 2 - " << fMotifPositions2.size() << " entries:" << endl;
+    Int_t counter = 0;        
+    for (MotifPositionMap2Iterator i=fMotifPositions2.begin(); 
+                                   i != fMotifPositions2.end(); i++) {
+
+      AliMpMotifPosition* motifPosition = (*i).second;
+      cout << "Map element " 
+           << setw(3) << counter++ << "   " 
+          << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << "  "
+          << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond() << "  "
+          << setw(3) << motifPosition->GetHighIndicesLimit().GetFirst()  << " " 
+          << setw(3) << motifPosition->GetHighIndicesLimit().GetSecond()  << " "
+          << motifPosition->GetID() << "  "
+          << endl;
+    }
+    cout << endl;
+  }
+}
+
+//
+// public methods
+//
+
+//_____________________________________________________________________________
+Bool_t AliMpMotifMap::AddMotif(AliMpVMotif* motif, Bool_t warn)
+{
+// Adds the specified motif 
+// if the motif with this ID is not yet present.
+// ---
+
+  AliMpVMotif* found = FindMotif(motif->GetID());
+  if (found) {    
+    if (warn && found == motif) 
+      Warning("AddMotif", "The motif is already in map.");
+    if (warn && found != motif) 
+      Warning("AddMotif", "Another motif with the same ID is already in map.");      
+    return false;
+  }  
+
+  fMotifs[motif->GetID()] = motif;
+  return true;
+}
+
+//_____________________________________________________________________________
+Bool_t AliMpMotifMap::AddMotifType(AliMpMotifType* motifType, Bool_t warn)
+{
+// Adds the specified motif type
+// if the motif with this ID is not yet present.
+// ---
+
+  AliMpMotifType* found = FindMotifType(motifType->GetID());
+  if (found) {    
+    if (warn && found == motifType) 
+      Warning("AddMotifType", "The motif type is already in map.");
+    if (warn && found != motifType) 
+      Warning("AddMotifType", 
+              "Another motif type with the same ID is already in map.");      
+    return false;
+  }  
+
+  fMotifTypes[motifType->GetID()] = motifType;
+  return true;
+}
+
+//_____________________________________________________________________________
+Bool_t AliMpMotifMap::AddMotifPosition(AliMpMotifPosition* motifPosition, Bool_t warn)
+{
+// Adds the specified motif position
+// if this position is not yet present.
+// ---
+
+  AliMpMotifPosition* found = FindMotifPosition(motifPosition->GetID());
+  if (found) {    
+    if (warn && found == motifPosition) 
+      Warning("AddMotifPosition", "This motif position is already in map.");
+    if (warn && found != motifPosition) 
+      Warning("AddMotifposition", 
+              "Another motif position with the same ID is already in map.");      
+    return false;
+  }  
+
+  fMotifPositions[motifPosition->GetID()] = motifPosition;
+  return true;
+}
+
+//_____________________________________________________________________________
+void AliMpMotifMap::FillMotifPositionMap2()
+{
+// Fills the second map (by global indices) of motif positions.
+// ---
+
+  if (fMotifPositions2.size() > 0 ) {
+    Warning("FillMotifPositionMap2", "Map has been already filled.");
+    return;
+  }  
+
+  for (MotifPositionMapIterator ip=fMotifPositions.begin(); 
+       ip != fMotifPositions.end(); ip++) {
+
+    fMotifPositions2[(*ip).second->GetLowIndicesLimit()] = (*ip).second;
+  }  
+
+}
+
+//_____________________________________________________________________________
+void  AliMpMotifMap::Print() const
+{
+// Prints the motifs and motif types maps.
+// ---
+
+  PrintMotifs();
+  PrintMotifTypes();
+  PrintMotifPositions();
+  PrintMotifPositions2();
+}
+
+//_____________________________________________________________________________
+void  AliMpMotifMap::PrintGlobalIndices(const char* fileName) const
+{
+// Prints all the motifs positions and their global indices.
+// ---
+
+  ofstream out(fileName, ios::out);
+
+  if (fMotifPositions.size()) {
+    for (MotifPositionMapIterator i=fMotifPositions.begin(); 
+                                   i != fMotifPositions.end(); i++) {
+
+      AliMpMotifPosition* motifPosition = (*i).second;
+      out << setw(5) << motifPosition->GetID() << "     "
+         << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst()  << " " 
+         << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond() 
+         << endl;
+    }
+    out << endl;
+  }
+}
+
+//_____________________________________________________________________________
+void  AliMpMotifMap::UpdateGlobalIndices(const char* fileName)
+{
+// Updates the motifs positions global indices
+// from the file.
+// ---
+
+  ifstream in(fileName, ios::in);
+
+  Int_t motifPositionId, offx, offy;
+    
+  do {
+    in >> motifPositionId >> offx >> offy;
+    
+    if (in.eof()) {
+      FillMotifPositionMap2();
+      return;
+    }  
+    
+    AliMpMotifPosition* motifPosition = FindMotifPosition(motifPositionId);
+         
+    if (motifPosition) {
+       cout << "Processing " 
+            << motifPosition->GetID() << " " << offx << " " << offy << endl; 
+
+       motifPosition->SetLowIndicesLimit(AliMpIntPair(offx, offy));
+       
+       Int_t offx2 
+         = offx + motifPosition->GetMotif()->GetMotifType()->GetNofPadsX() - 1;
+        
+       Int_t offy2 
+         = offy + motifPosition->GetMotif()->GetMotifType()->GetNofPadsY() - 1;
+       
+       motifPosition->SetHighIndicesLimit(AliMpIntPair(offx2, offy2));
+    }
+    else {   
+       cerr <<"Motif position " << motifPositionId << endl;
+       Warning("UpdateGlobalIndices", "Motif position not found !!!");
+    }
+  }    
+  while (!in.eof());
+}
+
+
+//_____________________________________________________________________________
+AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID) const
+{
+// Finds the motif with the specified ID.
+// ---
+  
+  MotifMapIterator i = fMotifs.find(motifID);
+  
+  if (i != fMotifs.end()) 
+    return (*i).second;
+  else                 
+    return 0;
+}
+
+//_____________________________________________________________________________
+AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID, 
+                             const TString& motifTypeID,
+                            TVector2 padDimensions ) const
+{
+// Finds the motif with the specified ID and returns it
+// only if its motif type and motif dimensions agree
+// with the given motifTypeID and motifDimensions.
+// Disagreement causes fatal error.
+// ---
+  
+  AliMpVMotif* motif = FindMotif(motifID);
+
+  if (motif && motif->GetMotifType()->GetID() != motifTypeID) {
+      Fatal("FindMotif", 
+            "Motif has been already defined with a different type.");
+      return 0;            
+  }
+
+  // check pad dimension in case of a normal motif
+  if (motif && 
+      dynamic_cast<AliMpMotif*>(motif) && 
+      ( motif->GetPadDimensions(0).X() != padDimensions.X() ||
+        motif->GetPadDimensions(0).Y() != padDimensions.Y())) { 
+      
+      Fatal("FindMotifType", 
+            "Motif type has been already defined with different dimensions.");
+      return 0;
+
+  } 
+
+  // check case of a special motif
+  if (motif && 
+      (padDimensions.X() == 0. && padDimensions.Y() == 0.) &&
+      !dynamic_cast<AliMpMotifSpecial*>(motif)) {
+
+      Fatal("FindMotifType", 
+            "Motif type has been already defined with different dimensions.");
+      return 0;
+
+  } 
+  
+  return motif;
+}
+
+//_____________________________________________________________________________
+AliMpMotifType* AliMpMotifMap::FindMotifType(const TString& motifTypeID) const
+{
+// Finds the motif type with the specified motif type ID.
+// ---
+  
+  MotifTypeMapIterator i = fMotifTypes.find(motifTypeID);
+  
+  if (i != fMotifTypes.end()) 
+    return (*i).second;
+  else                 
+    return 0;
+}
+
+//_____________________________________________________________________________
+AliMpMotifPosition* AliMpMotifMap::FindMotifPosition(Int_t motifPositionID) const
+{
+// Finds the motif position with the specified motif position ID.
+// ---
+  
+  MotifPositionMapIterator i = fMotifPositions.find(motifPositionID);
+  
+  if (i != fMotifPositions.end()) 
+    return (*i).second;
+  else                 
+    return 0;
+}
+
+//_____________________________________________________________________________
+AliMpMotifPosition* AliMpMotifMap::FindMotifPosition(AliMpIntPair indices) const
+{
+// Finds the last motif position which has the global indices (low limit)
+// less then the indices specified.
+// ---
+
+  MotifPositionMap2Iterator found 
+    = fMotifPositions2.lower_bound(indices);
+  
+  if (found == fMotifPositions2.end()) found--; 
+
+  MotifPositionMap2Iterator i=found;
+  do {
+    AliMpIntPair low = (*i).second->GetLowIndicesLimit();
+    AliMpIntPair up = (*i).second->GetHighIndicesLimit();
+    
+    if ( indices.GetFirst()  >= low.GetFirst() &&
+         indices.GetSecond() >= low.GetSecond() &&
+        indices.GetFirst()  <= up.GetFirst() &&
+         indices.GetSecond() <= up.GetSecond())
+        
+        return (*i).second;                     
+  }
+  while ( i-- != fMotifPositions2.begin());
+  
+  return 0;
+}
diff --git a/MUON/mapping/AliMpMotifMap.h b/MUON/mapping/AliMpMotifMap.h
new file mode 100755 (executable)
index 0000000..e53f85e
--- /dev/null
@@ -0,0 +1,82 @@
+// $Id$
+// Category: motif
+//
+// Class AliMpMotifMap
+// -------------------
+// Class describing the motif map container, where motifs are
+// mapped to their string IDs.
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#ifndef ALI_MP_MOTIF_MAP_H
+#define ALI_MP_MOTIF_MAP_H
+
+#include <map>
+
+#include <TObject.h>
+#include <TString.h>
+#include <TVector2.h>
+
+#include "AliMpMotifTypes.h"
+#include "AliMpIntPair.h"
+
+class AliMpVMotif;
+class AliMpMotifType;
+class AliMpMotifPosition;
+
+class AliMpMotifMap : public TObject
+{
+  public:
+    AliMpMotifMap();
+    virtual ~AliMpMotifMap();
+    
+    // methods
+    Bool_t  AddMotif(AliMpVMotif* motif, Bool_t warn = true);
+    Bool_t  AddMotifType(AliMpMotifType* motifType, Bool_t warn = true);
+    Bool_t  AddMotifPosition(AliMpMotifPosition* motifType, Bool_t warn = true);
+    void   FillMotifPositionMap2();
+    void   Print() const;
+    void   PrintGlobalIndices(const char* fileName) const;
+    void   UpdateGlobalIndices(const char* fileName);
+   
+    // find methods
+    AliMpVMotif*  FindMotif(const TString& motifID) const;
+    AliMpVMotif*  FindMotif(const TString& motifID, const TString& motifTypeID, 
+                            TVector2 padDimensions) const;
+    AliMpMotifType*      FindMotifType(const TString& motifTypeID) const;
+    AliMpMotifPosition*  FindMotifPosition(Int_t motifPositionID) const;
+    AliMpMotifPosition*  FindMotifPosition(AliMpIntPair indices) const;
+
+  private:
+    // methods
+    void  PrintMotifs() const;
+    void  PrintMotifTypes() const;
+    void  PrintMotifPositions() const;
+    void  PrintMotifPositions2() const;
+
+    // unused derrived functions
+    virtual void Print(const char* option) const {}
+#ifdef __HP_aCC
+    // data members
+            // EXCLUDED FOR CINT (does not compile on HP)
+    MotifMap          fMotifs; //! motifs map
+    MotifTypeMap      fMotifTypes; //!motif types map 
+    //MotifPositionMap  fMotifPositions;  //! motif positions map 
+                                          // not taken by cint
+    map<Int_t, AliMpMotifPosition*>  fMotifPositions; //! motif positions map by Id
+    MotifPositionMap2 fMotifPositions2; //! motif positions map
+#else
+    // data members
+    MotifMap          fMotifs;     // motifs map
+    MotifTypeMap      fMotifTypes; // motif types map 
+    //MotifPositionMap  fMotifPositions;  // motif positions map 
+                                          // not taken by cint
+    std::map<Int_t, AliMpMotifPosition*> fMotifPositions; // motif positions map by Id
+    MotifPositionMap2 fMotifPositions2; // motif positions map
+#endif
+
+  ClassDef(AliMpMotifMap,1)  // motif map
+};
+
+#endif //ALI_MP_MOTIF_MAP_H
diff --git a/MUON/mapping/AliMpMotifPainter.cxx b/MUON/mapping/AliMpMotifPainter.cxx
new file mode 100755 (executable)
index 0000000..48ad555
--- /dev/null
@@ -0,0 +1,149 @@
+// $Id$
+// Category: graphics
+//
+// Class AliMpMotifPainter
+// -----------------------
+// Class for drawing a motif into canvas
+//
+// Authors: David Guez, IPN Orsay
+
+#include <Riostream.h>
+#include "AliMpMotifPainter.h"
+#include "AliMpGraphContext.h"
+#include "AliMpMotifPosition.h"
+#include "AliMpMotifType.h"
+#include "AliMpConnection.h"
+#include "AliMpIntPair.h"
+
+ClassImp(AliMpMotifPainter)
+
+//_______________________________________________________________________
+AliMpMotifPainter::AliMpMotifPainter()
+  : AliMpVPainter(),
+    fMotifPos(0)
+{
+  // default dummy constructor
+}
+//_______________________________________________________________________
+AliMpMotifPainter::AliMpMotifPainter(AliMpMotifPosition *motifPos)
+  : AliMpVPainter(),
+    fMotifPos(motifPos)
+{
+  // normal constructor 
+
+}
+//_______________________________________________________________________
+void AliMpMotifPainter::DumpObject()
+{
+// Draw the owned object
+  fMotifPos->Dump();
+
+}
+
+//_______________________________________________________________________
+TVector2 AliMpMotifPainter::GetPosition() const
+{
+// Get the owned object's position
+  return fMotifPos->Position();
+
+}
+//_______________________________________________________________________
+TVector2 AliMpMotifPainter::GetDimensions() const
+{
+// Get the owned object's dimensions
+  return fMotifPos->Dimensions();
+
+}
+
+//_______________________________________________________________________
+void AliMpMotifPainter::Paint(Option_t *option)
+{
+// Paint the object
+  AliMpGraphContext *gr = AliMpGraphContext::Instance();
+  if (!fMotifPos) return;
+  Int_t col=gVirtualX->GetFillColor();
+  gr->Push();
+  gPad->Range(0.,0.,1.,1.);
+  InitGraphContext();
+
+  switch (option[0]){
+  case 'T':
+  case 'I':
+  case 'X':
+    {
+      PaintWholeBox();
+      Float_t textSize =   gVirtualX->GetTextSize();
+      gVirtualX->SetTextSize(10);
+      TString str;
+      switch (option[0]) {
+        case 'T' : 
+          str = Form("%d",fMotifPos->GetID());
+          break;
+        case 'I':{
+         switch (option[1]){
+           case '+' :
+            str = Form("(%d,%d)",fMotifPos->GetHighIndicesLimit().GetFirst(),
+                               fMotifPos->GetHighIndicesLimit().GetSecond());
+           break;
+           default:
+            str = Form("(%d,%d)",fMotifPos->GetLowIndicesLimit().GetFirst(),
+                               fMotifPos->GetLowIndicesLimit().GetSecond());
+         }
+       }
+        break;
+        case 'X' :
+          str = Form("(%f,%f)",(GetPosition()-GetDimensions()).X(),
+                               (GetPosition()-GetDimensions()).Y());
+          break;
+      }
+      gPad->PaintText(GetPadPosition().X()-0.01,GetPadPosition().Y()-0.01,str);
+      
+      gVirtualX->SetTextSize(textSize);
+    }
+    break;
+  case 'P':
+    {
+      //PaintWholeBox(kFALSE);
+      AliMpMotifType *motifType = fMotifPos->GetMotif()->GetMotifType();
+      for (Int_t j=motifType->GetNofPadsY()-1;j>=0;j--){
+          for (Int_t i=0;i<motifType->GetNofPadsX();i++){
+            AliMpIntPair indices = AliMpIntPair(i,j);
+               AliMpConnection* connect = 
+                 motifType->FindConnectionByLocalIndices(indices);
+            if (connect){
+              TVector2 realPadPos = 
+               GetPosition()+fMotifPos->GetMotif()->PadPositionLocal(indices);
+              TVector2 padPadPos,padPadDim;
+              gr->RealToPad(realPadPos,
+                               fMotifPos->GetMotif()->GetPadDimensions(indices),
+                        padPadPos,padPadDim);
+              TVector2 bl = padPadPos - padPadDim;
+              TVector2 ur = padPadPos + padPadDim;
+
+
+              Style_t sty = gVirtualX->GetFillStyle();
+              gVirtualX->SetFillStyle(1);
+              gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y());
+              gVirtualX->SetFillStyle(0);
+              gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y());
+              gVirtualX->SetFillStyle(sty);
+              if (option[1]=='T'){
+                Float_t textSize =   gVirtualX->GetTextSize();
+                gVirtualX->SetTextSize(10);
+                gPad->PaintText(padPadPos.X()-0.01,padPadPos.Y()-0.01,
+                             Form("%d",connect->GetGassiNum()));
+             
+                gVirtualX->SetTextSize(textSize);
+                 }
+           }
+          }
+      }
+    }
+    break;
+  default:
+    PaintWholeBox(kFALSE);
+  }
+  gr->Pop();
+  gVirtualX->SetFillColor(col);
+}
diff --git a/MUON/mapping/AliMpMotifPainter.h b/MUON/mapping/AliMpMotifPainter.h
new file mode 100755 (executable)
index 0000000..5f3cb8f
--- /dev/null
@@ -0,0 +1,32 @@
+// $Id$
+// Category: graphics
+//
+// Class AliMpMotifPainter
+// -----------------------
+// Class for drawing a motif into canvas
+//
+// Authors: David Guez, IPN Orsay
+
+#ifndef ALI_MP_MOTIF_PAINTER_H
+#define ALI_MP_MOTIF_PAINTER_H
+
+#include "AliMpVPainter.h"
+
+class AliMpMotifPosition;
+
+class AliMpMotifPainter : public AliMpVPainter
+{
+ public:
+  AliMpMotifPainter();
+  AliMpMotifPainter(AliMpMotifPosition *motifPos);
+  virtual void DumpObject(); //-MENU-
+  virtual void Paint(Option_t *option);
+  virtual TVector2 GetPosition() const;
+  virtual TVector2 GetDimensions() const;
+
+ private:
+  AliMpMotifPosition *fMotifPos;          // the motif to draw
+
+  ClassDef(AliMpMotifPainter,1) // Motif painter
+};
+#endif //ALI_MP_MOTIF_PAINTER_H
diff --git a/MUON/mapping/AliMpMotifPosition.cxx b/MUON/mapping/AliMpMotifPosition.cxx
new file mode 100755 (executable)
index 0000000..b4b11e5
--- /dev/null
@@ -0,0 +1,57 @@
+// $Id$
+//
+// Author: Ivana Hrivnacova, IPN Orsay
+
+#include "AliMpMotifPosition.h"
+#include "AliMpMotifPositionPadIterator.h"
+#include "AliMpMotifType.h"
+
+ClassImp(AliMpMotifPosition)
+
+//______________________________________________________________________________
+AliMpMotifPosition::AliMpMotifPosition(Int_t id, AliMpVMotif* motif, 
+                                       TVector2 position)
+  : AliMpVIndexed(),
+    fID(id),
+    fMotif(motif),
+    fPosition(position) {
+//
+}
+
+//______________________________________________________________________________
+AliMpMotifPosition::AliMpMotifPosition()
+  : AliMpVIndexed(), 
+    fID(0),
+    fMotif(0),
+    fPosition(TVector2(0.,0.)) {
+//
+}
+
+//______________________________________________________________________________
+AliMpMotifPosition::~AliMpMotifPosition(){
+// 
+}
+
+//______________________________________________________________________________
+AliMpVPadIterator* AliMpMotifPosition::CreateIterator() const
+{
+// Iterator is not yet implemented.
+//
+
+  return new AliMpMotifPositionPadIterator(this);
+}  
+
+//______________________________________________________________________________
+Bool_t AliMpMotifPosition::HasPad(const AliMpIntPair& indices) const
+{
+// Returns true if pad with the specified indices exists in 
+// this motif position.
+// ---
+
+  if (!HasIndices(indices)) return kFALSE;
+  
+  if (fMotif->GetMotifType()->IsFull()) return kTRUE;
+  
+  return fMotif->GetMotifType()->HasPad(indices-GetLowIndicesLimit());
+}
+
diff --git a/MUON/mapping/AliMpMotifPosition.h b/MUON/mapping/AliMpMotifPosition.h
new file mode 100755 (executable)
index 0000000..bd3077e
--- /dev/null
@@ -0,0 +1,63 @@
+// $Id$
+// Category: motif
+//
+// Class AliMpMotifPosition
+// ------------------------
+// Class that represents a placed motif.
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#ifndef ALI_MP_MOTIF_POSITION_H
+#define ALI_MP_MOTIF_POSITION_H
+
+#include <TVector2.h>
+
+#include "AliMpVIndexed.h"
+#include "AliMpVMotif.h"
+
+class AliMpVPadIterator;
+
+class AliMpMotifPosition : public AliMpVIndexed
+{
+ public:
+  AliMpMotifPosition(Int_t id, AliMpVMotif* motif, TVector2 position);
+  AliMpMotifPosition();
+  virtual ~AliMpMotifPosition();
+
+  // methods
+  virtual AliMpVPadIterator* CreateIterator() const;
+
+  // get methods
+  Int_t        GetID() const;
+  AliMpVMotif* GetMotif() const;
+  Bool_t       HasPad(const AliMpIntPair& indices) const;
+
+  // Geometry
+  TVector2 Position() const;
+  TVector2 Dimensions() const;
+
+ private:
+  // methods
+  // data members 
+  Int_t         fID;       //identifier
+  AliMpVMotif*  fMotif;    //motif
+  TVector2      fPosition; //position
+
+  ClassDef(AliMpMotifPosition,1) // A motif position
+};
+
+// inline functions
+
+inline Int_t  AliMpMotifPosition::GetID() const 
+{ return fID; }
+
+inline AliMpVMotif*  AliMpMotifPosition::GetMotif() const
+{ return fMotif; }
+inline TVector2 AliMpMotifPosition::Position() const
+{ return fPosition; }
+
+inline TVector2 AliMpMotifPosition::Dimensions() const
+{ return fMotif->Dimensions(); }
+
+#endif //ALI_MP_MOTIF_POSITION_H
diff --git a/MUON/mapping/AliMpMotifPositionPadIterator.cxx b/MUON/mapping/AliMpMotifPositionPadIterator.cxx
new file mode 100755 (executable)
index 0000000..c9cb635
--- /dev/null
@@ -0,0 +1,143 @@
+// $Id$
+// Category: motif
+//
+// Class AliMpMotifPositionPadIterator
+// -----------------------------------
+// Class, which defines an iterator over the pads of a given motif type
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#include "AliMpMotifPositionPadIterator.h"
+#include "AliMpMotifPosition.h"
+#include "AliMpMotifType.h"
+#include "AliMpConnection.h"
+
+ClassImp(AliMpMotifPositionPadIterator)
+
+//______________________________________________________________________________
+AliMpMotifPositionPadIterator::AliMpMotifPositionPadIterator():
+    AliMpVPadIterator(),
+    fMotifPos(0),
+    fIterator()
+{
+// default constructor, set the current position to "invalid"
+}
+
+//______________________________________________________________________________
+
+AliMpMotifPositionPadIterator::AliMpMotifPositionPadIterator(
+                                    const AliMpMotifPosition* motifPos)
+  : AliMpVPadIterator(),
+    fMotifPos(motifPos),
+    fIterator(motifPos->GetMotif()->GetMotifType())
+{
+// normal constructor, let *this to invalid position
+}
+
+//______________________________________________________________________________
+AliMpMotifPositionPadIterator::AliMpMotifPositionPadIterator(
+                                    const AliMpMotifPositionPadIterator& right)
+  : AliMpVPadIterator(right),
+    fMotifPos(right.fMotifPos),
+    fIterator(right.fIterator)
+    
+{
+// copy constructor
+}
+
+//______________________________________________________________________________
+AliMpMotifPositionPadIterator::~AliMpMotifPositionPadIterator()
+{
+// destructor
+}
+
+// operators
+
+//______________________________________________________________________________
+AliMpMotifPositionPadIterator& 
+AliMpMotifPositionPadIterator::operator = (const AliMpMotifPositionPadIterator& right)
+{
+// assignement operator
+// if the right hand iterator isn't of good type
+// the current operator is invalidated
+
+  // check assignement to self
+  if (this == &right) return *this;
+
+  // base class assignement
+  AliMpVPadIterator::operator=(right);
+
+  fMotifPos = right.fMotifPos;
+  fIterator = right.fIterator;
+
+  return *this;
+}  
+
+//private methods
+
+
+//______________________________________________________________________________
+Bool_t AliMpMotifPositionPadIterator::IsValid() const
+{
+// Is the iterator in a valid position?
+
+    return (fMotifPos!=0) && (!fIterator.IsDone());
+} 
+
+//public methods
+
+//______________________________________________________________________________
+void AliMpMotifPositionPadIterator::First()
+{
+// Reset the iterator, so that it points to the first available
+// pad in the motif type
+
+    if (!fMotifPos) {
+        Invalidate();
+        return ;
+    }
+
+    fIterator.First();
+    return;
+}
+
+//______________________________________________________________________________
+void AliMpMotifPositionPadIterator::Next()
+{
+// Move the iterator to the next valid pad.
+  fIterator.Next();
+}
+
+//______________________________________________________________________________
+Bool_t AliMpMotifPositionPadIterator::IsDone() const
+{
+// 
+  return !IsValid();
+}
+
+//______________________________________________________________________________
+AliMpPad AliMpMotifPositionPadIterator::CurrentItem() const 
+{
+// Returns current pad.
+
+    if (!fMotifPos)
+        return AliMpPad::Invalid();
+    else {
+      AliMpIntPair ind = fIterator.CurrentItem().GetIndices();
+      AliMpMotifType* mt = fMotifPos->GetMotif()->GetMotifType();
+      AliMpConnection* connect = 
+        mt->FindConnectionByLocalIndices(ind);
+      return AliMpPad(AliMpIntPair(fMotifPos->GetID(),connect->GetGassiNum()),
+                  fMotifPos->GlobalIndices(ind),
+                  fMotifPos->Position()+fMotifPos->GetMotif()->PadPositionLocal(ind),
+                  fMotifPos->GetMotif()->GetPadDimensions(ind));
+    }
+}
+
+//______________________________________________________________________________
+void AliMpMotifPositionPadIterator::Invalidate()
+{
+// Let the iterator points to the invalid position
+  fIterator.Invalidate();
+} 
+
diff --git a/MUON/mapping/AliMpMotifPositionPadIterator.h b/MUON/mapping/AliMpMotifPositionPadIterator.h
new file mode 100755 (executable)
index 0000000..ab0d793
--- /dev/null
@@ -0,0 +1,48 @@
+// $Id$
+// Category: motif
+//
+// Class AliMpMotifPositionPadIterator
+// -----------------------------------
+// Class, which defines an iterator over the pads of a given motif type
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#ifndef ALI_MP_MOTIF_POSITION_PAD_ITERATOR_H
+#define ALI_MP_MOTIF_POSITION_PAD_ITERATOR_H
+
+#include "AliMpVPadIterator.h"
+#include "AliMpIntPair.h"
+#include "AliMpMotifTypePadIterator.h"
+
+class AliMpMotifPosition;
+
+class AliMpMotifPositionPadIterator : public AliMpVPadIterator
+{
+  public:
+    AliMpMotifPositionPadIterator();
+    AliMpMotifPositionPadIterator(const AliMpMotifPosition* motifPos);
+    AliMpMotifPositionPadIterator(const AliMpMotifPositionPadIterator& right);
+    virtual ~AliMpMotifPositionPadIterator();     
+
+    // operators
+    AliMpMotifPositionPadIterator& 
+      operator = (const AliMpMotifPositionPadIterator& right);
+
+    virtual void First();
+    virtual void Next();
+    virtual Bool_t IsDone() const;
+    virtual AliMpPad CurrentItem() const;
+    virtual void Invalidate();
+
+  private:
+    // private methods
+    Bool_t IsValid() const;
+
+    // private data members
+    const AliMpMotifPosition* fMotifPos; // the AliMpMotifPosition over which iterate
+    AliMpMotifTypePadIterator fIterator; // Iterator over the motif type
+
+ ClassDef(AliMpMotifPositionPadIterator,1) // iterator over motif's pads
+};
+
+#endif // ALI_MP_MOTIF_POSITION_PAD_ITERATOR_H
diff --git a/MUON/mapping/AliMpMotifSpecial.cxx b/MUON/mapping/AliMpMotifSpecial.cxx
new file mode 100755 (executable)
index 0000000..216c3c0
--- /dev/null
@@ -0,0 +1,217 @@
+// $Id$
+// Category: motif
+//
+// Class AliMpMotifSpecial
+// -----------------------
+// Class that defines a motif with its unique ID
+// and the motif type.
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#include "AliMpMotifSpecial.h"
+#include "AliMpMotifType.h"
+#include "AliMpIntPair.h"
+#include "AliMpConstants.h"
+
+ClassImp(AliMpMotifSpecial)
+
+
+// private methods
+//______________________________________________________________________________
+Int_t AliMpMotifSpecial::VectorIndex(const AliMpIntPair& indices) const
+{
+// transform indices to linear vector index
+  return indices.GetFirst()*GetMotifType()->GetNofPadsY() + indices.GetSecond();
+}
+
+
+
+//public methods
+//______________________________________________________________________________
+AliMpMotifSpecial::AliMpMotifSpecial():
+  AliMpVMotif(),
+  fPadDimensionsVector(),
+  fPadDimensionsVector2()
+{
+  //default dummy constructor
+}
+
+
+//______________________________________________________________________________
+AliMpMotifSpecial::AliMpMotifSpecial(const TString &id, 
+                                     AliMpMotifType *motifType)
+  : AliMpVMotif(id,motifType),
+    fPadDimensionsVector(),
+    fPadDimensionsVector2()
+  
+{
+  // Normal constructor.
+
+  fPadDimensionsVector.resize(motifType->GetNofPadsX()*motifType->GetNofPadsY());
+}
+
+//______________________________________________________________________________
+TVector2 
+AliMpMotifSpecial::GetPadDimensions(const AliMpIntPair& localIndices) const
+{
+// returns the dimensions of pad located at the given indices
+  if (GetMotifType()->HasPad(localIndices))
+    return fPadDimensionsVector[VectorIndex(localIndices)];
+  else {
+    Warning("GetPadDimensions","Indices outside limits");
+    return TVector2(0.,0.);
+  }
+}
+
+//______________________________________________________________________________
+Int_t AliMpMotifSpecial::GetNofPadDimensions() const
+{
+// returns number of different pad dimensions in this motif
+
+  return fPadDimensionsVector2.size();
+}  
+
+//______________________________________________________________________________
+TVector2 AliMpMotifSpecial::GetPadDimensions(Int_t i) const
+{
+// returns the i-th different pad dimensions 
+
+  if (i<0 || i>GetNofPadDimensions()) {
+    Fatal("GetPadDimensions(i)", "Index outside limits.");
+    return TVector2();
+  }  
+
+  return fPadDimensionsVector2[i];
+}  
+
+//______________________________________________________________________________
+TVector2 AliMpMotifSpecial::Dimensions() const
+{
+  // gives the dimension of the motif
+
+
+  Int_t i,j;
+  Double_t sizeY=0.;
+  Double_t sizeX=0.;
+  
+  Double_t* tabSizeX = new Double_t[GetMotifType()->GetNofPadsY()];
+  for (j=0;j<GetMotifType()->GetNofPadsY();++j) tabSizeX[j]=0.0;
+  
+  for (i=0;i<GetMotifType()->GetNofPadsX();++i) {
+    Double_t trSizeY=0.;
+    for (j=0;j<GetMotifType()->GetNofPadsY();++j) {
+      TVector2 dim = GetPadDimensions(AliMpIntPair(i,j));
+      trSizeY+=dim.Y();
+      tabSizeX[j]+=dim.X();
+    }
+    if (trSizeY>sizeY) sizeY=trSizeY;
+  }
+  for (j=0;j<GetMotifType()->GetNofPadsY();++j) {
+    if (tabSizeX[j]>sizeX) sizeX = tabSizeX[j];
+  }
+
+  delete tabSizeX;
+  
+  return TVector2(sizeX,sizeY);
+}
+
+//______________________________________________________________________________
+TVector2 
+AliMpMotifSpecial::PadPositionLocal(const AliMpIntPair& localIndices) const 
+{
+  // gives the local position of the pad number (ix,iy)
+  // (0,0 is the center of the motif)
+
+  TVector2 dim = GetPadDimensions(localIndices);
+  
+  Double_t posX= dim.X();
+  for (Int_t i=0;i<localIndices.GetFirst();++i) {
+    posX+=2.*GetPadDimensions(AliMpIntPair(i,localIndices.GetSecond())).X();
+  }
+  
+  Double_t posY= dim.Y();
+  for (Int_t j=0;j<localIndices.GetSecond();++j) {
+    posY+=2.*GetPadDimensions(AliMpIntPair(localIndices.GetFirst(),j)).Y();
+  }
+
+  return TVector2(posX,posY)-Dimensions();
+
+}
+//______________________________________________________________________________
+AliMpIntPair AliMpMotifSpecial::PadIndicesLocal(const TVector2& localPos) const
+{
+  // return the pad indices from a given local position
+  // or AliMpIntPair::Invalid() if this position doesn't correspond to any valid
+  // connection
+
+  // *SOLEIL* : This code suppose that
+  // 1) all cells have the same size along the Y direction
+  // 2) the column 0 is entierly filled
+    
+
+  // First : find the j index
+  TVector2 pos = localPos + Dimensions();
+  Int_t j=0;
+  Double_t y=pos.Y();
+  
+  while (j<GetMotifType()->GetNofPadsY()) {
+    TVector2 padDim = GetPadDimensions(AliMpIntPair(0,j));
+    y-=2.*padDim.Y();
+    if (y<0.) break;
+    j++;
+  }
+
+  // Test if it's outside limits
+  if (j==GetMotifType()->GetNofPadsY()){
+    Warning("PadIndicesLocal","The position is outside the motif");
+    return AliMpIntPair::Invalid();
+  }
+  
+  
+  // now find the i index, in the j_th row
+  Int_t i=0;
+  Double_t x=pos.X();
+  
+  while (i<GetMotifType()->GetNofPadsX()) {
+    TVector2 padDim = GetPadDimensions(AliMpIntPair(i,j));
+    x-=2.*padDim.X();
+    if (x<0.) break;
+    i++;
+  }
+  
+  
+  // Test if it's outside limits
+
+  if (i==GetMotifType()->GetNofPadsX()){
+    Warning("PadIndicesLocal","The position is outside the motif");
+    return AliMpIntPair::Invalid();
+  }
+   
+  // then return the found (i,j)
+  return AliMpIntPair(i,j);  
+}
+//______________________________________________________________________________
+void AliMpMotifSpecial::SetPadDimensions(const AliMpIntPair& localIndices,
+                                         const TVector2& dimensions)
+{
+  // set the dimensions of the pad located at <localIndices> to the given
+  // <dimensions>
+  
+  if ( !GetMotifType()->HasPad(localIndices)){
+    Warning("SetPadDimensions","Pad indices outside limits");
+    return;
+  }  
+
+  // fill the dimensions map vector
+  fPadDimensionsVector[VectorIndex(localIndices)]=dimensions;
+  
+  // fill the vector of different pad dimensions
+  // only if these dimensions are not yet present
+  Bool_t isPresent = false;
+  for (Int_t i=0; i<GetNofPadDimensions(); i++) {
+    if (AliMpConstants::IsEqual(fPadDimensionsVector2[i], dimensions)) 
+      isPresent = true;    
+  }    
+  
+  if (!isPresent) fPadDimensionsVector2.push_back(dimensions);
+}
diff --git a/MUON/mapping/AliMpMotifSpecial.h b/MUON/mapping/AliMpMotifSpecial.h
new file mode 100755 (executable)
index 0000000..c759d7b
--- /dev/null
@@ -0,0 +1,55 @@
+// $Id$
+// Category: motif
+//
+// Class AliMpMotifSpecial
+// -----------------------
+// Class that defines a motif with its unique ID
+// and the motif type.
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#ifndef ALI_MP_MOTIF_SPECIAL_H
+#define ALI_MP_MOTIF_SPECIAL_H
+
+#include <TObject.h>
+#include <TString.h>
+#include <TVector2.h>
+
+#include "AliMpMotifTypes.h"
+#include "AliMpVMotif.h"
+
+class AliMpMotifSpecial : public AliMpVMotif
+{
+ public:
+  AliMpMotifSpecial(const TString &id, AliMpMotifType *motifType);
+  AliMpMotifSpecial();
+
+  // Access methods
+  virtual TVector2 GetPadDimensions(const AliMpIntPair& localIndices) const;
+  virtual Int_t    GetNofPadDimensions() const;
+  virtual TVector2 GetPadDimensions(Int_t i) const;
+
+  // Set methods
+  void SetPadDimensions(const AliMpIntPair& localIndices,
+                        const TVector2& dimensions);
+  
+  // Geometry
+  virtual TVector2 Dimensions() const;
+
+  // Other methods
+  virtual TVector2     PadPositionLocal(const AliMpIntPair& localIndices) const;
+  virtual AliMpIntPair PadIndicesLocal(const TVector2& localPos) const;
+
+ private:
+  // methods
+  Int_t VectorIndex(const AliMpIntPair& indices) const;
+
+  // data members
+  DimensionsMap fPadDimensionsVector;  // the vector of pad dimensions
+  DimensionsMap fPadDimensionsVector2; // the vector of different pad dimensions
+
+  ClassDef(AliMpMotifSpecial,1) // A motif with its ID
+};
+
+#endif //ALI_MP_MOTIF_SPECIAL_H
diff --git a/MUON/mapping/AliMpMotifType.cxx b/MUON/mapping/AliMpMotifType.cxx
new file mode 100755 (executable)
index 0000000..2f6eade
--- /dev/null
@@ -0,0 +1,273 @@
+// $Id$
+// Category: motif
+//
+// Class AliMpMotifType
+// --------------------
+// Class that defines the motif properties.
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#include <Riostream.h>
+
+#include "AliMpMotifType.h"
+#include "AliMpMotifTypePadIterator.h"
+#include "AliMpConnection.h"
+
+ClassImp(AliMpMotifType)
+
+const Int_t AliMpMotifType::fgkPadNumForA = 65;
+
+
+
+//______________________________________________________________________________
+AliMpMotifType::AliMpMotifType(const TString &id) 
+  : TObject(),
+    fID(id),
+    fNofPadsX(0),   
+    fNofPadsY(0),
+    fVerboseLevel(0),
+    fConnections()
+{
+  // Constructor
+}
+
+//______________________________________________________________________________
+AliMpMotifType::AliMpMotifType() 
+  : TObject(),
+    fID(""),
+    fNofPadsX(0),   
+    fNofPadsY(0),
+    fVerboseLevel(0),
+    fConnections()
+{
+  // Default constructor (dummy)
+}
+
+//______________________________________________________________________________
+AliMpMotifType::~AliMpMotifType() {
+// Destructor
+
+ for(ConnectionMap_t::const_iterator i = fConnections.begin();
+  i!=fConnections.end();++i)
+   delete i->second;
+
+  fConnections.erase(fConnections.begin(),fConnections.end());
+}
+
+//______________________________________________________________________________
+AliMpVPadIterator* AliMpMotifType::CreateIterator() const
+{
+  return new AliMpMotifTypePadIterator(this);
+}
+
+//______________________________________________________________________________
+void AliMpMotifType::SetNofPads(Int_t nofPadsX, Int_t nofPadsY)
+{
+  // Change the number of pads in this motif
+
+  fNofPadsX = nofPadsX;
+  fNofPadsY = nofPadsY;
+}
+
+
+//______________________________________________________________________________
+Int_t AliMpMotifType::PadNum(const TString &padName) const
+{
+  // Transform a pad name into the equivalent pad number
+  if ( (padName[0]>='A') && (padName[0]<='Z') )
+    return fgkPadNumForA+padName[0]-'A';
+  else
+    return atoi(padName.Data());
+}
+
+//______________________________________________________________________________
+TString AliMpMotifType::PadName(Int_t padNum) const
+{
+  // Transform a pad number into its equivalent pad name
+  if (padNum<fgkPadNumForA)
+    return Form("%d",padNum);
+  else
+    return char('A'+padNum-fgkPadNumForA);
+}
+
+//______________________________________________________________________________
+void AliMpMotifType::AddConnection(const AliMpIntPair &localIndices, 
+                               AliMpConnection* connection)
+{
+  // Add the connection to the map
+  
+  fConnections[localIndices]=connection;
+  connection->SetOwner(this);
+}  
+//______________________________________________________________________________
+AliMpConnection *AliMpMotifType::FindConnectionByPadNum(Int_t padNum) const
+{
+  // Retrive the AliMpConnection pointer from its pad num
+ for(ConnectionMap_t::const_iterator i = fConnections.begin();
+  i!=fConnections.end();++i)
+   if (i->second->GetPadNum()==padNum) return i->second;
+ return 0;
+}
+
+//______________________________________________________________________________
+AliMpConnection *AliMpMotifType::FindConnectionByLocalIndices(
+                                       AliMpIntPair localIndices) const
+{
+  if (!localIndices.IsValid()) return 0;
+
+  // Retrive the AliMpConnection pointer from its position (in pad unit)
+  ConnectionMap_t::const_iterator i = fConnections.find(localIndices);
+ if (i != fConnections.end())
+   return i->second;
+ else return 0;
+}
+
+//______________________________________________________________________________
+AliMpConnection *AliMpMotifType::FindConnectionByGassiNum(Int_t gassiNum) const
+{
+  // return the connection for the given gassiplex number
+ for(ConnectionMap_t::const_iterator i = fConnections.begin();
+  i!=fConnections.end();++i)
+   if (i->second->GetGassiNum()==gassiNum) return i->second;
+ return 0;
+}
+//______________________________________________________________________________
+AliMpConnection *AliMpMotifType::FindConnectionByKaptonNum(Int_t kaptonNum) const
+{
+  // Gives the connection related to the given kapton number
+ for(ConnectionMap_t::const_iterator i = fConnections.begin();
+  i!=fConnections.end();++i)
+   if (i->second->GetKaptonNum()==kaptonNum) return i->second;
+ return 0;
+}
+//______________________________________________________________________________
+AliMpConnection *AliMpMotifType::FindConnectionByBergNum(Int_t bergNum) const
+{
+  // Retrieve the connection from a Berg connector number
+ for(ConnectionMap_t::const_iterator i = fConnections.begin();
+  i!=fConnections.end();++i)
+   if (i->second->GetBergNum()==bergNum) return i->second;
+ return 0;
+}
+
+
+//______________________________________________________________________________
+AliMpIntPair AliMpMotifType::FindLocalIndicesByConnection(
+                                         const AliMpConnection* connection)
+{
+  // Retrieve the pad position from the connection pointer.
+  // Not to be used widely, since it use a search in the
+  // connection list...
+
+ for(ConnectionMap_t::const_iterator i = fConnections.begin();
+  i!=fConnections.end();++i)
+   if (i->second==connection) return i->first;
+
+ return AliMpIntPair::Invalid();
+}
+
+//______________________________________________________________________________
+AliMpIntPair AliMpMotifType::FindLocalIndicesByPadNum(Int_t padNum) const
+{
+  // Retrive the AliMpConnection pointer from its pad num
+ for(ConnectionMap_t::const_iterator i = fConnections.begin();
+  i!=fConnections.end();++i)
+   if (i->second->GetPadNum()==padNum) return i->first;
+   
+ return AliMpIntPair::Invalid();
+}
+
+//______________________________________________________________________________
+AliMpIntPair AliMpMotifType::FindLocalIndicesByGassiNum(Int_t gassiNum) const
+{
+  // return the connection for the given gassiplex number
+ for(ConnectionMap_t::const_iterator i = fConnections.begin();
+  i!=fConnections.end();++i)
+   if (i->second->GetGassiNum()==gassiNum) return i->first;
+   
+ return AliMpIntPair::Invalid();
+}
+
+//______________________________________________________________________________
+AliMpIntPair AliMpMotifType::FindLocalIndicesByKaptonNum(Int_t kaptonNum) const
+{
+  // Gives the connection related to the given kapton number
+ for(ConnectionMap_t::const_iterator i = fConnections.begin();
+  i!=fConnections.end();++i)
+   if (i->second->GetKaptonNum()==kaptonNum) return i->first;
+   
+ return AliMpIntPair::Invalid();
+}
+
+//______________________________________________________________________________
+AliMpIntPair AliMpMotifType::FindLocalIndicesByBergNum(Int_t bergNum) const
+{
+  // Retrieve the connection from a Berg connector number
+ for(ConnectionMap_t::const_iterator i = fConnections.begin();
+  i!=fConnections.end();++i)
+   if (i->second->GetBergNum()==bergNum) return i->first;
+   
+ return AliMpIntPair::Invalid();
+}
+
+//______________________________________________________________________________
+Bool_t AliMpMotifType::HasPad(const AliMpIntPair& localIndices) const
+{
+  if (!localIndices.IsValid()) return false;
+
+  // return true if the pad indexed by <localIndices> has a connection
+  return fConnections.find(localIndices)!=fConnections.end();
+
+}
+
+//______________________________________________________________________________
+void AliMpMotifType::Print(Option_t *option) const
+{
+  // Print the map of the motif. In each cel, the value
+  // printed depends of option, as the following:
+  // option="N" the "name" of the pad is written
+  // option="K" the Kapton connect. number attached to the pad is written
+  // option="B" the Berg connect. number attached to the pad is written
+  // option="G" the Gassiplex channel number attached to the pad is written
+  // otherwise the number of the pad is written
+
+  // NOTE : this method is really not optimized, in case 'N' or '',
+  // but the Print() this should not be very important in a Print() method
+
+  switch (option[0]){
+  case 'N':cout<<"Name mapping";
+    break;
+  case 'K':cout<<"Kapton mapping";
+    break;
+  case 'B':cout<<"Berg mapping";
+    break;
+  case 'G':cout<<"Gassiplex number mapping";
+    break;
+  default:cout<<"Pad mapping";
+  }
+  cout<<" in the motif "<<fID<<endl;
+  cout<<"-----------------------------------"<<endl;
+
+  for (Int_t j=fNofPadsY-1;j>=0;j--){
+    for (Int_t i=0;i<fNofPadsX;i++){
+      AliMpConnection *connexion = FindConnectionByLocalIndices(AliMpIntPair(i,j));
+      TString str;
+      if (connexion){
+       switch (option[0]){
+       case 'N':str=PadName(connexion->GetPadNum());
+         break;
+       case 'K':str=Form("%d",connexion->GetKaptonNum());
+         break;
+       case 'B':str=Form("%d",connexion->GetBergNum());
+         break;
+        case 'G':str=Form("%d",connexion->GetGassiNum());
+          break;
+       default:str= Form("%d",connexion->GetPadNum());
+       }
+       cout<<setw(2)<<str;
+      } else cout<<setw(2)<<"--";
+      cout<<" ";
+    }
+    cout<<endl;
+  }
+}
diff --git a/MUON/mapping/AliMpMotifType.h b/MUON/mapping/AliMpMotifType.h
new file mode 100755 (executable)
index 0000000..077dbc5
--- /dev/null
@@ -0,0 +1,87 @@
+// $Id$
+// Category: motif
+//
+// Class AliMpMotifType
+// --------------------
+// Class that defines the motif properties.
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#ifndef ALI_MP_MOTIF_TYPE_H
+#define ALI_MP_MOTIF_TYPE_H
+
+#include <TObject.h>
+#include <TString.h>
+#include <TVector2.h>
+#include <TObjArray.h>
+
+#include "AliMpMotifTypes.h"
+#include "AliMpIntPair.h"
+
+class AliMpConnection;
+class AliMpVPadIterator;
+
+class AliMpMotifType : public TObject
+{
+  public:
+    AliMpMotifType(const TString &id);
+    AliMpMotifType();
+    virtual ~AliMpMotifType();
+
+    virtual AliMpVPadIterator* CreateIterator() const;
+
+    // find methods
+    AliMpConnection *FindConnectionByPadNum(Int_t padNum) const;
+    AliMpConnection *FindConnectionByLocalIndices(AliMpIntPair localIndices) const;
+    AliMpConnection *FindConnectionByGassiNum(Int_t gassiNum) const;
+    AliMpConnection *FindConnectionByKaptonNum(Int_t kaptonNum) const;
+    AliMpConnection *FindConnectionByBergNum(Int_t bergNum) const;
+
+    AliMpIntPair FindLocalIndicesByPadNum(Int_t padNum) const;
+    AliMpIntPair FindLocalIndicesByGassiNum(Int_t gassiNum) const;
+    AliMpIntPair FindLocalIndicesByKaptonNum(Int_t kaptonNum) const;
+    AliMpIntPair FindLocalIndicesByBergNum(Int_t bergNum) const;
+    AliMpIntPair FindLocalIndicesByConnection(const AliMpConnection* connection);
+
+    // set methods
+    void SetNofPads(Int_t nofPadsX, Int_t nofPadY);
+    void SetVerboseLevel(Int_t level){fVerboseLevel=level;}
+    
+    // get methods
+    TString  GetID() const        {return fID;}
+    Int_t    GetNofPadsX() const  {return fNofPadsX;}
+    Int_t    GetNofPadsY() const  {return fNofPadsY;}
+    Int_t    GetNofPads() const   {return fConnections.size();}
+    
+    // Other methods
+    void AddConnection(const AliMpIntPair &localIndices, 
+                       AliMpConnection* connection);
+    virtual void Print(Option_t *option) const;
+    Int_t   PadNum(const TString &padName) const;
+    TString PadName(Int_t padNum) const;
+    Bool_t  HasPad(const AliMpIntPair& localIndices) const;
+    Bool_t  IsFull() const;
+
+  private:
+    // static data members
+    static const Int_t   fgkPadNumForA;
+
+    // data members
+    TString   fID;        // unique motif ID
+    Int_t     fNofPadsX;  // number of pads in x direction
+    Int_t     fNofPadsY;  // number of pads in y direction
+    Int_t     fVerboseLevel;  // verbose level
+
+    ConnectionMap_t fConnections; //! Map (ix,iy) of connections
+                          // EXCLUDED FOR CINT (does not compile on HP)
+
+  ClassDef(AliMpMotifType,1)  //Motif type
+};
+
+// inline functions
+
+inline Bool_t AliMpMotifType::IsFull() const 
+{ return GetNofPads() == fNofPadsX*fNofPadsY; }
+
+#endif //ALI_MP_MOTIF_TYPE_H
+
diff --git a/MUON/mapping/AliMpMotifTypePadIterator.cxx b/MUON/mapping/AliMpMotifTypePadIterator.cxx
new file mode 100755 (executable)
index 0000000..a77aa84
--- /dev/null
@@ -0,0 +1,178 @@
+// $Id$
+// Category: motif
+//
+// Class AliMpMotifTypePadIterator
+// -------------------------------
+// Class, which defines an iterator over the pads of a given motif type
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#include "AliMpMotifTypePadIterator.h"
+#include "AliMpMotifType.h"
+
+ClassImp(AliMpMotifTypePadIterator)
+
+//______________________________________________________________________________
+AliMpMotifTypePadIterator::AliMpMotifTypePadIterator():
+    AliMpVPadIterator(),
+    fMotifType(0),
+    fCurrentPosition(AliMpIntPair::Invalid())
+{
+// default constructor, set the current position to "invalid"
+}
+
+//______________________________________________________________________________
+AliMpMotifTypePadIterator::AliMpMotifTypePadIterator( 
+                                const AliMpMotifType* motifType)
+  : AliMpVPadIterator(),
+    fMotifType(motifType),
+    fCurrentPosition(AliMpIntPair::Invalid())
+{
+// normal constructor, let *this to invalid position
+}
+
+//______________________________________________________________________________
+AliMpMotifTypePadIterator::AliMpMotifTypePadIterator(
+                                const AliMpMotifTypePadIterator& right)
+  : AliMpVPadIterator(right),
+    fMotifType(right.fMotifType),
+    fCurrentPosition(right.fCurrentPosition)
+    
+{
+// copy constructor
+}
+
+//______________________________________________________________________________
+AliMpMotifTypePadIterator::~AliMpMotifTypePadIterator()
+{
+// destructor
+}
+
+// operators
+
+//______________________________________________________________________________
+AliMpMotifTypePadIterator& 
+AliMpMotifTypePadIterator::operator = (const AliMpMotifTypePadIterator& right)
+{
+// assignement operator
+// if the right hand iterator isn't of good type
+// the current operator is invalidated
+
+  // check assignement to self
+  if (this == &right) return *this;
+
+  // base class assignement
+  AliMpVPadIterator::operator=(right);
+
+  fMotifType = right.fMotifType;
+  fCurrentPosition = right.fCurrentPosition;
+
+  return *this;
+}  
+
+//
+//private methods
+//
+
+//______________________________________________________________________________
+AliMpIntPair 
+AliMpMotifTypePadIterator::FindFirstPadInLine(AliMpIntPair indices) const
+{
+// Find the indices of the first pad in the same line
+// as the <indices>, and in column, at least equal, to the
+// one of <indices>
+
+    if (!fMotifType) return AliMpIntPair::Invalid();
+
+    while (indices.GetFirst() < fMotifType->GetNofPadsX()) {
+        if (fMotifType->HasPad(indices)) return indices;
+        indices += AliMpIntPair(1,0);
+    }
+    return AliMpIntPair::Invalid();
+} 
+
+//______________________________________________________________________________
+Bool_t AliMpMotifTypePadIterator::IsValid() const
+{
+// Is the iterator in a valid position?
+
+    return fMotifType!=0 && fCurrentPosition.IsValid();
+} 
+
+//
+//public methods
+//
+
+//______________________________________________________________________________
+void AliMpMotifTypePadIterator::First()
+{
+// Reset the iterator, so that it points to the first available
+// pad in the motif type
+
+    if (!fMotifType) {
+        Invalidate();
+        return ;
+    }
+    fCurrentPosition = AliMpIntPair(0,0);
+    if (fMotifType->HasPad(fCurrentPosition)) return;
+    
+    
+    // if (0,0) is not available
+    // place itself to the first avalable motif after (0,0) (if exists)
+    // ++(*this);
+    Next();
+    
+    return;
+}
+
+//______________________________________________________________________________
+void AliMpMotifTypePadIterator::Next()
+{
+// Move the iterator to the next valid pad.
+
+    //if (!IsValid()) return *this;
+    if (!IsValid()) return;
+
+    while (fCurrentPosition.GetSecond() < fMotifType->GetNofPadsY()){
+        AliMpIntPair nextTry 
+         = FindFirstPadInLine(fCurrentPosition + AliMpIntPair(1,0));
+        if (nextTry.IsValid()){
+            fCurrentPosition = nextTry;
+            return;
+        }
+        fCurrentPosition.SetFirst(-1);
+        fCurrentPosition.SetSecond(fCurrentPosition.GetSecond()+1);
+    }
+    
+    // if the loop is finished, there's not available pads at all...
+    Invalidate();
+    return;
+}
+
+//______________________________________________________________________________
+Bool_t AliMpMotifTypePadIterator::IsDone() const
+{
+// 
+  return !IsValid();
+}
+
+//______________________________________________________________________________
+AliMpPad AliMpMotifTypePadIterator::CurrentItem() const 
+{
+// Returns current pad.
+
+    if (!fMotifType)
+        return AliMpPad::Invalid();
+    else
+        return AliMpPad(AliMpIntPair::Invalid(),
+                       fCurrentPosition,TVector2(),TVector2());
+}
+
+//______________________________________________________________________________
+void AliMpMotifTypePadIterator::Invalidate()
+{
+// Let the iterator points to the invalid position
+    fCurrentPosition = AliMpIntPair::Invalid();
+
+} 
+
diff --git a/MUON/mapping/AliMpMotifTypePadIterator.h b/MUON/mapping/AliMpMotifTypePadIterator.h
new file mode 100755 (executable)
index 0000000..e63c8e7
--- /dev/null
@@ -0,0 +1,49 @@
+// $Id$
+// Category: motif
+//
+// Class AliMpMotifTypePadIterator
+// -------------------------------
+// Class, which defines an iterator over the pads of a given motif type
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#ifndef ALI_MP_MOTIF_TYPE_PAD_ITERATOR_H
+#define ALI_MP_MOTIF_TYPE_PAD_ITERATOR_H
+
+#include "AliMpVPadIterator.h"
+#include "AliMpIntPair.h"
+
+class AliMpMotifType;
+
+class AliMpMotifTypePadIterator : public AliMpVPadIterator
+{
+  public:
+    AliMpMotifTypePadIterator();
+    AliMpMotifTypePadIterator(const AliMpMotifType* motifType);
+    AliMpMotifTypePadIterator(const AliMpMotifTypePadIterator& right);
+    virtual ~AliMpMotifTypePadIterator();     
+
+    // operators
+    AliMpMotifTypePadIterator& 
+      operator = (const AliMpMotifTypePadIterator& right);
+
+    virtual void First();
+    virtual void Next();
+    virtual Bool_t IsDone() const;
+    virtual AliMpPad CurrentItem() const;
+    virtual void Invalidate();
+
+  private:
+    // private methods
+    AliMpIntPair FindFirstPadInLine(AliMpIntPair indices) const;
+    Bool_t IsValid() const;
+
+    // private data members
+    const AliMpMotifType* fMotifType;// the motif type over which iterate
+    AliMpIntPair fCurrentPosition;   //! the current position inside the motif type
+                                     // EXCLUDED FOR CINT (does not compile on HP)
+
+ ClassDef(AliMpMotifTypePadIterator,1) // iterator over motif's pads
+};
+
+#endif // ALI_MP_MOTIF_TYPE_PAD_ITERATOR_H
diff --git a/MUON/mapping/AliMpMotifTypes.h b/MUON/mapping/AliMpMotifTypes.h
new file mode 100644 (file)
index 0000000..b1da32c
--- /dev/null
@@ -0,0 +1,49 @@
+// $Id$
+// Category: motif
+//
+// AliMpMotifTypes
+// ---------------
+// Sytem dependent types definitions for motif category.
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#ifndef ALI_MP_MOTIF_TYPES_H
+#define ALI_MP_MOTIF_TYPES_H
+
+#include <map>
+#include <vector>
+
+#include <TVector2.h>
+
+#include "AliMpIntPair.h"
+
+class AliMpConnection;
+class AliMpVMotif;
+class AliMpMotifType;
+class AliMpMotifPosition;
+
+#ifdef __HP_aCC
+  typedef map<AliMpIntPair, AliMpConnection*> ConnectionMap_t;
+  typedef map<TString, AliMpVMotif*> MotifMap;
+  typedef MotifMap::const_iterator   MotifMapIterator;
+  typedef map<TString, AliMpMotifType*>  MotifTypeMap;
+  typedef MotifTypeMap::const_iterator   MotifTypeMapIterator;
+  typedef map<Int_t, AliMpMotifPosition*>  MotiPositionMap;
+  typedef MotiPositionMap::const_iterator  MotifPositionMapIterator;
+  typedef map<AliMpIntPair, AliMpMotifPosition*> MotifPositionMap2;
+  typedef MotifPositionMap2::const_iterator      MotifPositionMap2Iterator;
+  typedef vector<TVector2> DimensionsMap;
+#else
+  typedef std::map< AliMpIntPair, AliMpConnection* > ConnectionMap_t;
+  typedef std::map<TString, AliMpVMotif*> MotifMap;
+  typedef MotifMap::const_iterator        MotifMapIterator;
+  typedef std::map<TString, AliMpMotifType*> MotifTypeMap;
+  typedef MotifTypeMap::const_iterator       MotifTypeMapIterator;
+  typedef std::map<Int_t, AliMpMotifPosition*>  MotiPositionMap;
+  typedef MotiPositionMap::const_iterator       MotifPositionMapIterator;
+  typedef std::map<AliMpIntPair, AliMpMotifPosition*> MotifPositionMap2;
+  typedef MotifPositionMap2::const_iterator           MotifPositionMap2Iterator;
+  typedef std::vector< TVector2 > DimensionsMap;
+#endif
+
+#endif //ALI_MP_MOTIF_TYPES_H
diff --git a/MUON/mapping/AliMpNeighboursPadIterator.cxx b/MUON/mapping/AliMpNeighboursPadIterator.cxx
new file mode 100755 (executable)
index 0000000..1219d36
--- /dev/null
@@ -0,0 +1,288 @@
+// $Id$
+// Category: sector
+//
+// Class AliMpNeighboursPadIterator
+// --------------------------------
+// Class, which defines an iterator over the pads surrounding a given pad
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#include <set>
+
+#include <TVector2.h>
+
+#include "AliMpNeighboursPadIterator.h"
+#include "AliMpIntPair.h"
+#include "AliMpSectorSegmentation.h"
+#include "AliMpRow.h"
+#include "AliMpConstants.h"
+
+ClassImp(AliMpNeighboursPadIterator)
+
+const UInt_t AliMpNeighboursPadIterator::fgkInvalidIndex = 9999; 
+                                                   //never so much neighbours...
+
+//______________________________________________________________________________
+AliMpNeighboursPadIterator::AliMpNeighboursPadIterator()
+  : AliMpVPadIterator(),
+    fkSegmentation(0),
+    fCenterPad(AliMpPad::Invalid()),
+    fPads(),
+    fIndex(fgkInvalidIndex)
+{
+// default constructor, set the current position to "invalid"
+}
+
+//______________________________________________________________________________
+AliMpNeighboursPadIterator::AliMpNeighboursPadIterator(
+                                 const AliMpSectorSegmentation* segmentation,
+                                 const AliMpPad& centerPad,
+                                 Bool_t includeCenter)
+  : AliMpVPadIterator(),
+    fkSegmentation(segmentation),
+    fCenterPad(centerPad),
+    fIndex(fgkInvalidIndex)
+{
+// normal constructor, set *this to invalid position
+
+    FillPadsVector(includeCenter);
+}
+
+//______________________________________________________________________________
+AliMpNeighboursPadIterator::AliMpNeighboursPadIterator(
+                                 const AliMpNeighboursPadIterator& right)
+  : AliMpVPadIterator(right)
+{
+// copy constructor
+
+  *this = right;
+}
+
+//______________________________________________________________________________
+AliMpNeighboursPadIterator::~AliMpNeighboursPadIterator()
+{
+// destructor
+}
+
+// operators
+
+//______________________________________________________________________________
+AliMpNeighboursPadIterator& 
+AliMpNeighboursPadIterator::operator = (const AliMpNeighboursPadIterator& right)
+{
+// assignement operator
+// if the right hand iterator isn't of good type
+// the current operator is invalidated
+
+  // check assignement to self
+  if (this == &right) return *this;
+
+  // base class assignement
+  AliMpVPadIterator::operator=(right);
+
+  fkSegmentation = right.fkSegmentation;
+  fCenterPad     = right.fCenterPad;
+  fPads          = right.fPads;
+  fIndex         = right.fIndex;
+    
+
+  return *this;
+} 
+
+//private methods
+
+//______________________________________________________________________________
+Bool_t AliMpNeighboursPadIterator::IsNeighbours(const AliMpPad& pad) const
+{
+// true if the pad located by <padIndice> is a neighbours of those
+// located at <fCenterPad>
+
+    
+    TVector2 relPos  = pad.Position()   - fCenterPad.Position();
+    TVector2 bounds  = pad.Dimensions() + fCenterPad.Dimensions();
+    return (TMath::Abs(relPos.X())- bounds.X()<AliMpConstants::LengthTolerance()) && 
+           (TMath::Abs(relPos.Y())- bounds.Y()<AliMpConstants::LengthTolerance());
+
+}
+
+//______________________________________________________________________________
+PadVector AliMpNeighboursPadIterator::PadVectorLine(const AliMpPad& from,
+                                           const AliMpIntPair& direction) const
+{
+// Fill  a new vector with all pads which have common
+// parts with the pad located at <fCenterPad>, in a given line
+// starting from <from> and moving by <direction>
+
+    AliMpPad current = from;
+    PadVector ans;
+    Bool_t cont=kTRUE;
+    do {
+        if (IsNeighbours(current))
+            ans.push_back(current);
+        else
+            cont=kFALSE;
+        TVector2 nextPos = current.Position() + TVector2(
+          current.Dimensions().X()*(AliMpConstants::LengthStep()+1.)*direction.GetFirst(),
+          current.Dimensions().Y()*(AliMpConstants::LengthStep()+1.)*direction.GetSecond());
+        current = fkSegmentation->PadByPosition(nextPos);
+    } while (cont);
+    return ans;
+}
+
+//______________________________________________________________________________
+void AliMpNeighboursPadIterator::FillPadsVector(Bool_t includeCenter)
+{
+// Fill the indices vector with all indices of pads which have common
+// parts with the pad located at <fCenterPad>
+
+    if (!fkSegmentation || !fCenterPad.IsValid()) return;
+    
+    
+    AliMpPad from;
+    AliMpIntPair direction;
+    PadVector found;
+    
+    // repare a unique simple associative container
+    // --> no doublons, rapid insersion
+    PadSet setTotal;
+
+  /////////////  Left side
+  
+  ////////////////// up direction
+    
+    from = fkSegmentation->PadsLeft(fCenterPad).GetFirst();
+    direction = AliMpIntPair(0,1);
+    found = PadVectorLine(from,direction);
+    setTotal.insert(found.begin(),found.end());
+
+
+  ////////////////// down direction
+
+    from = fkSegmentation->PadsDown(from).GetFirst(); // the Pad down is already added
+    direction = AliMpIntPair(0,-1);
+    found = PadVectorLine(from,direction);
+    setTotal.insert(found.begin(),found.end());
+    
+  /////////////  Up side
+  
+  ////////////////// right direction
+
+    from = fkSegmentation->PadsUp(fCenterPad).GetFirst();
+    direction = AliMpIntPair(1,0);
+    found = PadVectorLine(from,direction);
+    setTotal.insert(found.begin(),found.end());
+    
+  ////////////////// left direction
+
+    from = fkSegmentation->PadsLeft(from).GetFirst(); // the pad up is already added
+    direction = AliMpIntPair(-1,0);
+    found = PadVectorLine(from,direction);
+    setTotal.insert(found.begin(),found.end());
+    
+  /////////////  Right side
+  
+  ////////////////// Up direction
+    
+    from = fkSegmentation->PadsRight(fCenterPad).GetFirst();
+    direction = AliMpIntPair(0,1);
+    found = PadVectorLine(from,direction);
+    setTotal.insert(found.begin(),found.end());
+    
+  ////////////////// down direction
+
+    from = fkSegmentation->PadsDown(from).GetFirst(); // the pad right is already added
+    direction = AliMpIntPair(0,-1);
+    found = PadVectorLine(from,direction);
+    setTotal.insert(found.begin(),found.end());
+    
+  /////////////  Down side
+  
+  ////////////////// Right direction
+
+    from = fkSegmentation->PadsDown(fCenterPad).GetFirst();
+    direction = AliMpIntPair(1,0);
+    found = PadVectorLine(from,direction);
+    setTotal.insert(found.begin(),found.end());
+    
+  ////////////////// left direction
+    
+    from = fkSegmentation->PadsLeft(from).GetFirst(); // the pad down is already added
+    direction = AliMpIntPair(-1,0);
+    found = PadVectorLine(from,direction);
+    setTotal.insert(found.begin(),found.end());
+    
+
+    // fill the fIndices vector with the set (-->pass from a rapid insertion,
+    // to rapid and indexed access, for the rest of the job)
+
+    fPads.clear();
+    // include the center pad if requiered
+    if (includeCenter) fPads.push_back(fCenterPad);
+    //fPads.insert(fPads.end(),setTotal.begin(),setTotal.end());
+    
+    PadSetIterator it;
+    for (it = setTotal.begin(); it != setTotal.end(); it++)
+      fPads.push_back((*it));
+}
+
+//______________________________________________________________________________
+Bool_t AliMpNeighboursPadIterator::IsValid() const
+{
+// Is the iterator in a valid position?
+    return (fkSegmentation!=0 && fIndex!=fgkInvalidIndex);
+} 
+
+//public methods
+
+//______________________________________________________________________________
+void AliMpNeighboursPadIterator::First()
+{
+// Reset the iterator, so that it points to the first available
+// pad in the sector
+
+    if ((fkSegmentation != 0) && (fPads.size() != 0)) 
+      fIndex=0; 
+    else 
+      fIndex=fgkInvalidIndex;
+
+}
+
+//______________________________________________________________________________
+void AliMpNeighboursPadIterator::Next()
+{
+// pre-increment operator. Should be used by default for iterating over
+// pads
+
+
+  if (!IsValid()) return;
+  
+  if (fIndex < fPads.size()-1) 
+    fIndex++; 
+  else 
+    Invalidate();
+}
+
+//______________________________________________________________________________
+Bool_t AliMpNeighboursPadIterator::IsDone() const
+{
+// 
+  return !IsValid();
+}
+
+//______________________________________________________________________________
+AliMpPad AliMpNeighboursPadIterator::CurrentItem() const 
+{
+// dereferencement operator
+  if (!IsValid())
+    return AliMpPad::Invalid();
+  else
+    return fPads[fIndex];
+}
+
+//______________________________________________________________________________
+void AliMpNeighboursPadIterator::Invalidate()
+{
+// Let the iterator points to the invalid position
+    fIndex=fgkInvalidIndex;
+}
+
diff --git a/MUON/mapping/AliMpNeighboursPadIterator.h b/MUON/mapping/AliMpNeighboursPadIterator.h
new file mode 100755 (executable)
index 0000000..5fe9ae1
--- /dev/null
@@ -0,0 +1,66 @@
+// $Id$
+// Category: sector
+//
+// Class AliMpNeighboursPadIterator
+// --------------------------------
+// Class, which defines an iterator over the pads surrounding a given pad
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#ifndef ALI_MP_NEIGHBOURS_PAD_ITERATOR_H
+#define ALI_MP_NEIGHBOURS_PAD_ITERATOR_H
+
+#include <TObject.h>
+#include <TVector2.h>
+
+#include "AliMpSectorTypes.h"
+#include "AliMpVPadIterator.h"
+#include "AliMpMotifTypePadIterator.h"
+#include "AliMpIntPair.h"
+#include "AliMpPad.h"
+
+class AliMpSectorSegmentation;
+
+class AliMpNeighboursPadIterator : public AliMpVPadIterator
+{
+  public:
+    AliMpNeighboursPadIterator();
+    AliMpNeighboursPadIterator(const AliMpSectorSegmentation* segmentation,
+                               const AliMpPad& centerPad,
+                               Bool_t includeCenter=kFALSE);
+    AliMpNeighboursPadIterator(const AliMpNeighboursPadIterator& right);
+    virtual ~AliMpNeighboursPadIterator();
+
+    // operators
+    AliMpNeighboursPadIterator& 
+      operator = (const AliMpNeighboursPadIterator& right);
+
+    // methods
+    virtual void First();
+    virtual void Next();
+    virtual Bool_t IsDone() const;
+    virtual AliMpPad CurrentItem() const;
+    virtual void Invalidate();
+
+  private:
+    // static members
+    static const UInt_t   fgkInvalidIndex;
+
+    // private methods
+    Bool_t    IsNeighbours(const AliMpPad& pad) const;
+    PadVector PadVectorLine(const AliMpPad& from,
+                            const AliMpIntPair& direction) const;
+    void      FillPadsVector(Bool_t includeCenter);
+    Bool_t    IsValid() const;
+
+    // private data members
+    const AliMpSectorSegmentation* fkSegmentation; // The sector segmentation 
+                                                   // over which to iterate
+    AliMpPad   fCenterPad; // Pad arround which we iterate
+    PadVector  fPads;      // The list of pad arround fCenterIndices
+    UInt_t     fIndex;     // Current index inside the fPads vector
+
+  ClassDef(AliMpNeighboursPadIterator,1) // iterator over motif's pads
+};
+
+#endif // ALI_MP_NEIGHBOURS_PAD_ITERATOR_H
diff --git a/MUON/mapping/AliMpPad.cxx b/MUON/mapping/AliMpPad.cxx
new file mode 100755 (executable)
index 0000000..81cf2fb
--- /dev/null
@@ -0,0 +1,163 @@
+// $Id$
+// Category: basic
+//
+// Class AliMpPad
+// ---------------
+// Class which encapsuate all informations about a pad
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#include <Riostream.h>
+
+#include "AliMpPad.h"
+
+ClassImp(AliMpPad)
+
+//////////////////////////////////////////////////////////
+//
+// This class encapsulate all the information about a pad
+//
+//////////////////////////////////////////////////////////
+
+//
+// foreign operators
+//
+
+//_____________________________________________________________________________
+Bool_t operator==(const TVector2& v1,const TVector2& v2)
+{
+return v1.X()==v2.X() && v1.Y()==v2.Y();
+}
+
+
+//_____________________________________________________________________________
+ostream& operator<<(ostream& out,const TVector2& v)
+{
+  out << '(' << v.X() << ',' << v.Y() << ')';
+  return out; 
+}
+
+//_____________________________________________________________________________
+AliMpPad::AliMpPad(const AliMpIntPair& location,const AliMpIntPair& indices,
+                   const TVector2& position,const TVector2& dimensions,
+                   Bool_t validity)
+ : TObject(),
+   fLocation(location),
+   fIndices(indices),
+   fPosition(position),
+   fDimensions(dimensions),
+   fValidity(validity)
+{
+// Be carefull : this constructor doesn't check the validity of
+// the correspondance between location and indices.
+// By default, validity is set true.
+// It is aimed to be used by MSegmentation methods, and never from outside....
+}
+
+
+//_____________________________________________________________________________
+AliMpPad::AliMpPad()
+  : TObject(),
+    fLocation(AliMpIntPair::Invalid()),
+    fIndices(AliMpIntPair::Invalid()),
+    fPosition(-1.,-1.),
+    fDimensions(0.,0.),
+    fValidity(false) 
+{
+// Default constructor - creates pad in invalid state
+}
+
+
+//_____________________________________________________________________________
+AliMpPad::AliMpPad(const AliMpPad& src)
+  : TObject(src)
+{
+ *this = src;
+}
+
+//_____________________________________________________________________________
+AliMpPad::~AliMpPad() {
+//
+}
+
+//_____________________________________________________________________________
+AliMpPad& AliMpPad::operator = (const AliMpPad& src) 
+{
+  // check assignement to self
+  if (this == &src) return *this;
+
+  // base class assignement
+  TObject::operator=(src);
+
+  // assignement operator
+  fLocation   = src.fLocation;
+  fIndices    = src.fIndices;
+  fPosition.Set(src.fPosition);
+  fDimensions.Set(src.fDimensions);
+  fValidity = src.fValidity;
+
+  return *this;
+}
+
+//_____________________________________________________________________________
+Bool_t AliMpPad::operator == (const AliMpPad& pos2) const
+{
+  // are this and pos2 equals?
+
+  // one valid, one invalid
+  if (fValidity != pos2.fValidity) return false;
+  
+  // both invalid
+  if (!fValidity) return true;
+  
+  // both valid
+  return    (fLocation==pos2.fLocation) && (fIndices   ==pos2.fIndices   )
+         && (fPosition==pos2.fPosition) && (fDimensions==pos2.fDimensions);
+}
+//_____________________________________________________________________________
+Bool_t AliMpPad::operator!= (const AliMpPad& pos2) const
+{
+  // are this and pos2 equals?
+  return !(*this==pos2);
+}
+
+//_____________________________________________________________________________
+ostream& operator<< (ostream &out, const AliMpPad& op)
+{
+  if (op.IsValid()) {
+    out << "Pad: Location " << op.GetLocation() 
+        << "  Indices "     << op.GetIndices() 
+       << "  Position "    << op.Position()
+        << "  Dimensions "  << op.Dimensions();
+    return out;
+  }
+  else {
+    out << "Pad::Invalid";
+    return out;
+  }  
+}
+
+//_____________________________________________________________________________
+Bool_t operator < (const AliMpPad& left, const AliMpPad& right)
+{
+return left.GetIndices()<right.GetIndices();
+}
+
+//_____________________________________________________________________________
+void AliMpPad::Print() const
+{
+// Prints all pad data.
+// ---
+
+  if (fValidity) {
+    cout << "Indices: " << fIndices << "; "
+         << " Location: " << fLocation << "; "
+         << " Position: " << fPosition.X() << " " << fPosition.Y() << "; "
+         << " Dimensions: " << fDimensions.X() << " " << fDimensions.Y() 
+         << endl;
+  }
+  else {        
+    cout << "Pad::Invalid " << endl;
+  }  
+}
+
diff --git a/MUON/mapping/AliMpPad.h b/MUON/mapping/AliMpPad.h
new file mode 100755 (executable)
index 0000000..4016b7f
--- /dev/null
@@ -0,0 +1,63 @@
+// $Id$
+// Category: basic
+//
+// Class AliMpPad
+// ---------------
+// Class which encapsuate all informations about a pad
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#ifndef ALI_MP_PAD_H
+#define ALI_MP_PAD_H
+
+#include <TObject.h>
+#include <TVector2.h>
+
+#include "AliMpIntPair.h"
+
+class AliMpPad : public TObject
+{
+ public:
+  AliMpPad(const AliMpIntPair& location, const AliMpIntPair& indices,
+           const TVector2& position, const TVector2& dimensions,
+           Bool_t validity = true);
+  AliMpPad();
+  AliMpPad(const AliMpPad& src);
+  virtual ~AliMpPad();
+
+  // operators  
+  Bool_t operator == (const AliMpPad& pos2) const;
+  Bool_t operator != (const AliMpPad& pos2) const;
+  AliMpPad& operator = (const AliMpPad& src) ;
+  
+  // methods
+  void Print() const;
+
+  // static get methods
+  static AliMpPad Invalid() {return AliMpPad();}
+
+  // get methods
+  AliMpIntPair GetLocation() const {return fLocation  ;}
+  AliMpIntPair GetIndices()  const {return fIndices   ;}
+  TVector2 Position()    const {return fPosition  ;}
+  TVector2 Dimensions()  const {return fDimensions;}
+  Bool_t   IsValid()     const {return fValidity  ;}
+
+ private:
+  // unused derived functions
+  virtual void Print(const char* option) const {}
+
+  // data members
+  AliMpIntPair  fLocation;  //pad location
+  AliMpIntPair  fIndices;   //pad indices
+  TVector2  fPosition;  // the pad position (in cm)
+  TVector2  fDimensions;// the pad dimensions (in cm)
+  Bool_t    fValidity;  // validity
+
+  ClassDef(AliMpPad,1) //utility class for the motif type
+};
+
+ostream& operator << (ostream &out, const AliMpPad& op);
+Bool_t operator < (const AliMpPad& left, const AliMpPad& right);
+
+#endif //ALI_MP_PAD_H
diff --git a/MUON/mapping/AliMpPadIteratorPtr.cxx b/MUON/mapping/AliMpPadIteratorPtr.cxx
new file mode 100755 (executable)
index 0000000..155302e
--- /dev/null
@@ -0,0 +1,26 @@
+// $Id$
+// Category: basic
+//
+// Class AliMpPadIteratorPtr
+// --------------------------
+// Pointer to the virtual pad iterator;
+// enables to allocate the virtual pad iterator on stack.
+// Usage:
+// MVIndexed* myIndexed = MyIndexed()
+// MVIterator& it = *AliMpPadIteratorPtr(myIndexed->CreateIterator());
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#include "AliMpPadIteratorPtr.h"
+
+ClassImp(AliMpPadIteratorPtr)
+
+AliMpPadIteratorPtr::AliMpPadIteratorPtr(AliMpVPadIterator* it)
+  : fIterator(it)
+{}
+
+AliMpPadIteratorPtr::~AliMpPadIteratorPtr() {
+//
+  delete fIterator;
+}
+
diff --git a/MUON/mapping/AliMpPadIteratorPtr.h b/MUON/mapping/AliMpPadIteratorPtr.h
new file mode 100755 (executable)
index 0000000..d83fbf8
--- /dev/null
@@ -0,0 +1,43 @@
+// $Id$
+// Category: basic
+//
+// Class AliMpPadIteratorPtr
+// --------------------------
+// Pointer to the virtual pad iterator;
+// enables to allocate the virtual pad iterator on stack.
+// Usage:
+// AliMpVIndexed* myIndexed = MyIndexed()
+// MVIterator& it = *AliMpPadIteratorPtr(myIndexed->CreateIterator());
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#ifndef ALI_MP_PAD_ITERATOR_PTR_H
+#define ALI_MP_PAD_ITERATOR_PTR_H
+
+#include <TObject.h>
+
+#include "AliMpVPadIterator.h"
+
+class AliMpPadIteratorPtr : public TObject
+{
+  public:
+    AliMpPadIteratorPtr(AliMpVPadIterator* it);
+    // AliMpPadIteratorPtr(const AliMpPadIteratorPtr& right); --> private
+    virtual ~AliMpPadIteratorPtr();
+  
+    AliMpVPadIterator* operator->() { return  fIterator; }
+    AliMpVPadIterator& operator*()  { return *fIterator; }
+
+  private:   
+    // disallow copy and assignment to avoid
+    // multiple deletion of fIterator
+    AliMpPadIteratorPtr(const AliMpPadIteratorPtr& right);
+    AliMpPadIteratorPtr& operator=(const AliMpPadIteratorPtr& right);
+     
+    // data members
+    AliMpVPadIterator*  fIterator; //The pad iterator
+     
+  ClassDef(AliMpPadIteratorPtr,1) // Pointer to abstract pad iterator
+};
+
+#endif // ALI_MP_PAD_ITERATOR_PTR_H
diff --git a/MUON/mapping/AliMpPadPair.cxx b/MUON/mapping/AliMpPadPair.cxx
new file mode 100644 (file)
index 0000000..c716cb5
--- /dev/null
@@ -0,0 +1,69 @@
+// $Id$
+// Category: basic
+//
+// Class AliMpPadPair
+// ------------------
+// Wrap up for std::pair<AliMpPad, AliMpPad>
+// to avoid problems with CINT.
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#include "AliMpPadPair.h"
+
+ClassImp(AliMpPadPair)
+
+
+//_____________________________________________________________________________
+AliMpPadPair::AliMpPadPair(const AliMpPad& pad1, const AliMpPad& pad2)
+  : TObject(),
+    fPair(pad1, pad2) {
+//
+}
+
+//_____________________________________________________________________________
+AliMpPadPair::AliMpPadPair(const AliMpPadPair& right)
+  : TObject(),
+    fPair(right.GetFirst(), right.GetSecond()) {
+//
+}
+
+//_____________________________________________________________________________
+AliMpPadPair::AliMpPadPair()
+  : TObject(),
+    fPair(AliMpPad::Invalid(), AliMpPad::Invalid()) {
+//
+}
+
+//_____________________________________________________________________________
+AliMpPadPair::~AliMpPadPair() {
+//
+}
+
+//_____________________________________________________________________________
+Bool_t AliMpPadPair::operator == (const AliMpPadPair& right) const
+{
+  return fPair == right.fPair;
+}
+
+//_____________________________________________________________________________
+Bool_t AliMpPadPair::operator!= (const AliMpPadPair& right) const
+{
+  return !(*this == right);
+}
+
+//_____________________________________________________________________________
+AliMpPadPair& AliMpPadPair::operator = (const AliMpPadPair& right) 
+{
+  // check assignement to self
+  if (this == &right) return *this;
+
+  // base class assignement
+  TObject::operator=(right);
+
+  // assignement operator
+  fPair = right.fPair;
+  
+  return *this;
+}
+
+
diff --git a/MUON/mapping/AliMpPadPair.h b/MUON/mapping/AliMpPadPair.h
new file mode 100644 (file)
index 0000000..bdcaa95
--- /dev/null
@@ -0,0 +1,47 @@
+// $Id$
+// Category: basic
+//
+// Class AliMpPadPair
+// ------------------
+// Wrap up for std::pair<AliMpPad, AliMpPad>
+// to avoid problems with CINT.
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#ifndef ALI_MP_PAD_PAIR_H
+#define ALI_MP_PAD_PAIR_H
+
+#include "AliMpBasicTypes.h"
+#include "AliMpPad.h"
+
+class AliMpPadPair : public TObject
+{
+  public:
+    AliMpPadPair(const AliMpPad& pad1, const AliMpPad& pad2);      
+    AliMpPadPair(const AliMpPadPair& pair);      
+    AliMpPadPair();
+    virtual ~AliMpPadPair();
+
+    // operators    
+    Bool_t operator == (const AliMpPadPair& right) const;
+    Bool_t operator != (const AliMpPadPair& right) const;
+    AliMpPadPair& operator = (const AliMpPadPair& right);
+
+    // methods
+    AliMpPad GetFirst() const;  
+    AliMpPad GetSecond() const;  
+
+  private:
+    // data members
+    PadPair  fPair;
+    
+  ClassDef(AliMpPadPair,1) //utility class for the motif type
+};
+
+// inline functions
+
+inline AliMpPad AliMpPadPair::GetFirst() const  { return fPair.first; } 
+inline AliMpPad AliMpPadPair::GetSecond() const { return fPair.second; } 
+
+
+#endif //ALI_MP_PAD_PAIR_H
diff --git a/MUON/mapping/AliMpPadRow.cxx b/MUON/mapping/AliMpPadRow.cxx
new file mode 100755 (executable)
index 0000000..78cd1de
--- /dev/null
@@ -0,0 +1,137 @@
+// $Id$
+// --------------------------------------------------------
+// Category: sector
+//
+// Class AliMpPadRow
+// -----------------
+// Class describing a pad row composed of the pad row segments.
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#include <TError.h>
+
+#include "AliMpPadRow.h"
+#include "AliMpPadRowSegment.h"
+
+ClassImp(AliMpPadRow)
+
+//_____________________________________________________________________________
+AliMpPadRow::AliMpPadRow() 
+  : TObject(),
+    fID(0) 
+{
+//
+}
+
+//_____________________________________________________________________________
+AliMpPadRow::~AliMpPadRow() {
+//  
+
+  for (Int_t i=0; i<GetNofPadRowSegments() ; i++)
+    delete fSegments[i];
+}
+
+//
+// public methods
+//
+
+//_____________________________________________________________________________
+void AliMpPadRow::AddPadRowSegment(AliMpPadRowSegment* padRowSegment)
+{
+// Adds row segment.
+// ---
+
+  // Set pad row segment offset
+  if (GetNofPadRowSegments() == 0)
+    padRowSegment
+      ->SetOffsetX(fOffsetX);
+  else 
+    padRowSegment
+      ->SetOffsetX(GetPadRowSegment(GetNofPadRowSegments()-1)->LeftBorderX());
+
+  // Adds the pad row segment
+  fSegments.push_back(padRowSegment);
+}  
+  
+//_____________________________________________________________________________
+AliMpPadRowSegment* AliMpPadRow::FindPadRowSegment(Double_t x) const
+{
+// Finds the row segment for the specified x position;
+// returns 0 if no row segment is found.
+// ---
+
+  for (Int_t i=0; i<GetNofPadRowSegments(); i++) {
+    AliMpPadRowSegment* rs = GetPadRowSegment(i);
+    if (x >= rs->LeftBorderX() && x <= rs->RightBorderX())
+      return rs;
+  }
+  
+  return 0;    
+}    
+
+//_____________________________________________________________________________
+Double_t  AliMpPadRow::HalfSizeY() const
+{
+  return GetPadRowSegment(0)->HalfSizeY();
+}
+
+//_____________________________________________________________________________
+void  AliMpPadRow::SetID(Int_t id)
+{
+// Sets the ID.
+// ---
+
+  fID = id;
+}    
+
+//_____________________________________________________________________________
+void  AliMpPadRow::SetOffsetX(Double_t offsetX)
+{
+// Sets the x offset.
+// ---
+
+  fOffsetX = offsetX;
+}    
+
+//_____________________________________________________________________________
+Int_t AliMpPadRow::GetID() const 
+{
+// Returns the row ID.
+// ---
+
+  return fID;
+}  
+
+//_____________________________________________________________________________
+Int_t AliMpPadRow::GetNofPadRowSegments() const 
+{
+// Returns number of row segments.
+// ---
+
+  return fSegments.size();
+}  
+
+//_____________________________________________________________________________
+AliMpPadRowSegment* AliMpPadRow::GetPadRowSegment(Int_t i) const 
+{
+  if (i<0 || i>=GetNofPadRowSegments()) {
+    Warning("GetRowSegment", "Index outside range");
+    return 0;
+  }
+  
+  return fSegments[i];  
+}
+
+//_____________________________________________________________________________
+Int_t AliMpPadRow::GetNofPads() const 
+{
+// Returns number of pads in this pad row.
+// ---
+
+  Int_t nofPads=0;
+  for (Int_t i=0; i<GetNofPadRowSegments(); i++)
+    nofPads += GetPadRowSegment(i)->GetNofPads();
+
+  return nofPads;
+}  
+
diff --git a/MUON/mapping/AliMpPadRow.h b/MUON/mapping/AliMpPadRow.h
new file mode 100755 (executable)
index 0000000..1fbaef9
--- /dev/null
@@ -0,0 +1,50 @@
+// $Id$
+// Category: sector
+//
+// Class AliMpPadRow
+// -----------------
+// Class describing a pad row composed of the pad row segments.
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#ifndef ALI_MP_PAD_ROW_H
+#define ALI_MP_PAD_ROW_H
+
+#include <TObject.h>
+
+#include "AliMpSectorTypes.h"
+
+class AliMpPadRowSegment;
+
+class AliMpPadRow : public TObject
+{
+  public:
+    AliMpPadRow();
+    virtual ~AliMpPadRow();
+  
+    // methods
+    void  AddPadRowSegment(AliMpPadRowSegment* padRowSegment);
+    AliMpPadRowSegment*  FindPadRowSegment(Double_t x) const;
+    Double_t  HalfSizeY() const;
+    
+    // set methods
+    void  SetID(Int_t id);
+    void  SetOffsetX(Double_t offsetX);
+    
+    // get methods
+    Int_t   GetID() const;
+    Int_t   GetNofPadRowSegments() const;
+    AliMpPadRowSegment*  GetPadRowSegment(Int_t i) const;
+    Int_t   GetNofPads() const;
+
+  private:
+    // data members
+    Int_t               fID;
+    Double_t            fOffsetX; //the x position of the right border
+    PadRowSegmentVector fSegments;
+
+  ClassDef(AliMpPadRow,1)  //Pad row
+};
+
+#endif //ALI_MP_PAD_ROW_H
+
diff --git a/MUON/mapping/AliMpPadRowSegment.cxx b/MUON/mapping/AliMpPadRowSegment.cxx
new file mode 100755 (executable)
index 0000000..1104af2
--- /dev/null
@@ -0,0 +1,165 @@
+// $Id$
+// Category: sector
+//
+// Class AliMpPadRowSegment
+// --------------------
+// Class describing a pad row segment composed of the 
+// the identic pads.
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#include <TError.h>
+
+#include "AliMpPadRowSegment.h"
+#include "AliMpPadRow.h"
+#include "AliMpMotif.h"
+#include "AliMpMotifType.h"
+
+ClassImp(AliMpPadRowSegment)
+
+//_____________________________________________________________________________
+AliMpPadRowSegment::AliMpPadRowSegment(AliMpPadRow* padRow, AliMpMotif* motif, 
+                                       Int_t motifPositionId, Int_t nofPads)
+  : TObject(),
+    fNofPads(nofPads),
+    fOffsetX(0.),
+    fPadRow(padRow),
+    fMotif(motif),
+    fMotifPositionId(motifPositionId)
+{
+// 
+}
+
+//_____________________________________________________________________________
+AliMpPadRowSegment::AliMpPadRowSegment() 
+  : TObject(),
+    fNofPads(0),
+    fOffsetX(0.),
+    fPadRow(0),
+    fMotif(0),
+    fMotifPositionId(0)
+{
+//
+}
+
+//_____________________________________________________________________________
+AliMpPadRowSegment::~AliMpPadRowSegment() {
+//  
+}
+
+//
+// private methods  
+//
+
+//_____________________________________________________________________________
+Double_t AliMpPadRowSegment::FirstPadCenterX() const
+{
+// Returns the x coordinate of the first (the most right) pad center
+// in global coordinate system.
+// ---
+
+  return fOffsetX - fMotif->GetPadDimensions().X();
+}  
+
+//_____________________________________________________________________________
+Double_t AliMpPadRowSegment::LastPadCenterX() const
+{
+// Returns the x coordinate of the last (the most left) pad center
+// in global coordinate system.
+// !! numbering of pads is in (-x) direction
+// ---
+
+  return fOffsetX - (2.*fNofPads - 1)*fMotif->GetPadDimensions().X();
+}
+
+//_____________________________________________________________________________
+Double_t AliMpPadRowSegment::FirstPadBorderX() const
+{
+// Returns the x coordinate of the right border of the first (the most right) 
+// pad in global coordinate system.
+// ---
+
+  return fOffsetX;
+         // Also could be
+         // return FirstPadCenterX() + fMotif->GetPadDimensions().X();
+}  
+
+//_____________________________________________________________________________
+Double_t AliMpPadRowSegment::LastPadBorderX() const
+{
+// Returns the x coordinate of the left border of the last (the most left)
+// pad in global coordinate system.
+// ---
+
+  return LastPadCenterX() - fMotif->GetPadDimensions().X();
+}  
+
+//
+// public methods  
+//
+
+//_____________________________________________________________________________
+Double_t  AliMpPadRowSegment::LeftBorderX() const
+{
+// Returns the x coordinate of the left row segment border
+// in global coordinate system.
+// ---
+
+  return LastPadBorderX();
+}
+
+//_____________________________________________________________________________
+Double_t  AliMpPadRowSegment::RightBorderX() const
+{
+// Returns the x coordinate of the right row segment border
+// in global coordinate system.
+// ---
+
+  return FirstPadBorderX();
+}
+
+//_____________________________________________________________________________
+Double_t  AliMpPadRowSegment::HalfSizeY() const
+{
+// Returns the size in y of this row segment.
+// ---
+
+  return fMotif->GetPadDimensions().Y();
+}
+
+//_____________________________________________________________________________
+AliMpPadRow*  AliMpPadRowSegment::GetPadRow() const
+{
+// Returns the pad row.which this pad row segment belongs to.
+// ---
+
+  return fPadRow;
+}  
+
+//_____________________________________________________________________________
+AliMpMotif*  AliMpPadRowSegment::GetMotif() const
+{
+// Returns the motif of this pad row segment. 
+// ---
+
+  return fMotif;
+}  
+
+//_____________________________________________________________________________
+Int_t  AliMpPadRowSegment::GetMotifPositionId() const
+{
+// Returns the motif of this pad row segment. 
+// ---
+
+  return fMotifPositionId;
+}  
+
+//_____________________________________________________________________________
+void  AliMpPadRowSegment::SetOffsetX(Double_t offsetX)
+{
+// Sets the x offset.
+// ---
+
+  fOffsetX = offsetX;
+}    
+
diff --git a/MUON/mapping/AliMpPadRowSegment.h b/MUON/mapping/AliMpPadRowSegment.h
new file mode 100755 (executable)
index 0000000..bb94cc1
--- /dev/null
@@ -0,0 +1,61 @@
+// $Id$
+// ---------------------------------------------------------------
+// Category: sector
+//
+// Class AliMpPadRowSegment
+// ------------------------
+// Class describing a pad row segment composed of the 
+// the identic pads.
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#ifndef M_PAD_ROW_SEGMENT_H
+#define M_PAD_ROW_SEGMENT_H
+
+#include <TObject.h>
+#include <TVector2.h>
+
+class AliMpPadRow;
+class AliMpMotif;
+
+class AliMpPadRowSegment : public TObject
+{
+  public:
+    AliMpPadRowSegment(AliMpPadRow* padRow, AliMpMotif* motif, Int_t motifPositionId,
+                   Int_t nofPads);
+    AliMpPadRowSegment();
+    virtual ~AliMpPadRowSegment();
+
+    // methods
+    virtual Double_t  LeftBorderX() const;
+    virtual Double_t  RightBorderX() const;
+    virtual Double_t  HalfSizeY() const;
+
+    // get methods
+    virtual AliMpPadRow*  GetPadRow() const;
+    virtual AliMpMotif*   GetMotif() const;    
+    virtual Int_t     GetMotifPositionId() const;
+            Int_t     GetNofPads() const {return fNofPads;}     
+
+    // set methods
+    void  SetOffsetX(Double_t offsetX);  
+
+  private:
+    // methods
+    Double_t  FirstPadCenterX() const;
+    Double_t  LastPadCenterX() const;
+    Double_t  FirstPadBorderX() const;
+    Double_t  LastPadBorderX() const;
+
+    // data members
+    Int_t     fNofPads;  //number of pads
+    Double_t  fOffsetX;  //the x position of the right border
+    AliMpPadRow*  fPadRow;   //the pad row containing this segment 
+    AliMpMotif*   fMotif;    //the motif 
+    Int_t     fMotifPositionId;  // the motif position id
+    
+  ClassDef(AliMpPadRowSegment,1)  //Row segment
+};
+
+#endif //M_PAD_ROW_SEGMENT_H
+
diff --git a/MUON/mapping/AliMpPlane.cxx b/MUON/mapping/AliMpPlane.cxx
new file mode 100644 (file)
index 0000000..83adcc5
--- /dev/null
@@ -0,0 +1,154 @@
+// $Id$
+// Category: plane
+//
+// Class AliMpPlane
+// ----------------
+// Class represents the plane composed of 4 sector positions:
+// 
+//   I.  FS                             II. |  I.
+//  II.  BS inverted in x             _____ | ____
+// III.  FS inverted in x, y                |
+//  IV.  BS inverted in y              III. |  IV.
+//   
+// FS - front sector
+// BS - back sector    
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#include <Riostream.h>
+
+#include "AliMpPlane.h"
+#include "AliMpReader.h"
+#include "AliMpSector.h"
+#include "AliMpSectorPosition.h"
+
+ClassImp(AliMpPlane)
+
+//
+// static methods
+//
+
+//______________________________________________________________________________
+AliMpPlane* 
+AliMpPlane::Create(AliMpPlaneType type, 
+                   const TVector2& q1Position, const TVector2& q2Position,
+                  const TVector2& q3Position, const TVector2& q4Position)
+{
+// Factory method for creating planes.
+// ---
+
+  // Build sectors
+  AliMpReader bReader(kBendingPlane);
+  // bReader.SetVerboseLevel(1);
+  AliMpSector* bSector = bReader.BuildSector();
+  cout << "bending sector is built" << endl;
+
+  AliMpReader nbReader(kNonBendingPlane);
+  // nbReader.SetVerboseLevel(1);
+  AliMpSector* nbSector = nbReader.BuildSector();
+  cout << "non-bending sector is built" << endl;
+
+  if (type == kBendingPlane)
+    return new AliMpPlane(bSector, nbSector,
+                      q1Position, q2Position, q3Position, q4Position );
+  else  
+    return new AliMpPlane(nbSector, bSector,
+                      q1Position, q2Position, q3Position, q4Position );
+}
+
+//______________________________________________________________________________
+AliMpPlane* AliMpPlane::Create(AliMpPlaneType type) 
+{
+// Factory method for creating planes with 
+// not shifted qudrants.
+// ---
+
+  return Create(type, TVector2(), TVector2(), TVector2(), TVector2());
+}
+
+//
+// constructors, destructors
+//
+
+//______________________________________________________________________________
+AliMpPlane::AliMpPlane(AliMpSector* frontSector, AliMpSector* backSector,
+                       const TVector2& q1Position, const TVector2& q2Position,
+                      const TVector2& q3Position, const TVector2& q4Position)
+  : TObject(),
+    fkFrontSector(frontSector),
+    fkBackSector(backSector),
+    fSectorPositions()
+{
+//
+  
+  // Create sector positions
+  fSectorPositions.push_back(
+    new AliMpSectorPosition(fkFrontSector, q1Position, AliMpIntPair( 1, 1)));
+  fSectorPositions.push_back(
+    new AliMpSectorPosition(fkBackSector,  q2Position, AliMpIntPair(-1, 1)));
+  fSectorPositions.push_back(
+    new AliMpSectorPosition(fkFrontSector, q3Position, AliMpIntPair(-1,-1)));
+  fSectorPositions.push_back(
+    new AliMpSectorPosition(fkBackSector,  q4Position, AliMpIntPair( 1,-1)));
+}
+
+
+//______________________________________________________________________________
+AliMpPlane::AliMpPlane() 
+  : TObject(),
+    fkFrontSector(0),
+    fkBackSector(0),
+    fSectorPositions()
+{
+//
+}
+
+//______________________________________________________________________________
+AliMpPlane::~AliMpPlane() {
+// 
+
+  delete fkFrontSector; 
+  delete fkBackSector; 
+
+  for (Int_t i=0; i<GetNofSectorPositions(); i++) 
+    delete GetSectorPosition(i);    
+}
+
+//
+// public methods
+//
+
+//______________________________________________________________________________
+const AliMpSectorPosition* 
+AliMpPlane::SectorPosition(const AliMpIntPair& scale) const
+{
+// Returns the sector position specified by scale.
+// ---
+
+  for (UInt_t i=0; i<fSectorPositions.size(); i++) 
+    if (fSectorPositions[i]->GetScale() == scale) return GetSectorPosition(i);
+
+  Fatal("SectorPosition", "Wrong scale");
+  return 0; 
+}
+
+//______________________________________________________________________________
+Int_t AliMpPlane::GetNofSectorPositions() const
+{
+// Returns number of sector positions.
+// ---
+
+  return fSectorPositions.size();
+}  
+
+
+//______________________________________________________________________________
+AliMpSectorPosition* AliMpPlane::GetSectorPosition(Int_t i) const
+{
+// Returns i-th sector position.
+// ---
+  return  fSectorPositions[i];
+}     
+
+
diff --git a/MUON/mapping/AliMpPlane.h b/MUON/mapping/AliMpPlane.h
new file mode 100644 (file)
index 0000000..e31b75d
--- /dev/null
@@ -0,0 +1,73 @@
+// $Id$
+// Category: plane
+//
+// Class AliMpPlane
+// ----------------
+// Class represents the plane composed of 4 sector positions:
+// 
+//   I.  FS                             II. |  I.
+//  II.  BS inverted in x             _____ | ____
+// III.  FS inverted in x, y                |
+//  IV.  BS inverted in y              III. |  IV.
+//   
+// FS - front sector
+// BS - back sector    
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#ifndef ALI_MP_PLANE_H
+#define ALI_MP_PLANE_H
+
+#include <TObject.h>
+#include <TVector2.h>
+
+#include "AliMpPlaneTypes.h"
+#include "AliMpPlaneType.h"
+#include "AliMpIntPair.h"
+
+class AliMpSector;
+class AliMpSectorPosition;
+
+class AliMpPlane : public TObject
+{
+  public:
+    AliMpPlane(AliMpSector* frontSector, AliMpSector* backSector,
+               const TVector2& q1Position, const TVector2& q2Position,
+              const TVector2& q3Position, const TVector2& q4Position);
+    AliMpPlane();
+    virtual ~AliMpPlane();
+    
+    // factory methods
+    static AliMpPlane* Create(AliMpPlaneType type,
+               const TVector2& q1Position, const TVector2& q2Position,
+               const TVector2& q3Position, const TVector2& q4Position);
+    static AliMpPlane* Create(AliMpPlaneType type);
+    
+    // methods
+    const AliMpSectorPosition* SectorPosition(const AliMpIntPair& scale) const;
+
+    // get methods
+    const AliMpSector*   GetFrontSector() const;
+    const AliMpSector*   GetBackSector() const;
+    Int_t GetNofSectorPositions() const;
+    AliMpSectorPosition* GetSectorPosition(Int_t i) const;
+
+  private:
+    // data members    
+    const AliMpSector*    fkFrontSector;    // front sector in the 1st quadrant
+    const AliMpSector*    fkBackSector;     // back sector in the 1st quadrant
+    SectorPositionVector  fSectorPositions; // sector positions
+
+  ClassDef(AliMpPlane,1)  //Plane
+};
+
+// inline functions
+
+inline const AliMpSector* AliMpPlane::GetFrontSector() const
+{ return fkFrontSector; }
+
+inline const AliMpSector* AliMpPlane::GetBackSector() const
+{ return fkBackSector; }
+
+#endif //ALI_MP_PLANE_H
+
diff --git a/MUON/mapping/AliMpPlaneAreaPadIterator.cxx b/MUON/mapping/AliMpPlaneAreaPadIterator.cxx
new file mode 100755 (executable)
index 0000000..0ed2925
--- /dev/null
@@ -0,0 +1,184 @@
+// $Id$
+// Category: plane
+//
+// Class AliMpPlaneAreaPadIterator
+// -------------------------------
+// Class, which defines an iterator over the pads 
+// inside a given area in a plane in horizontal direction.
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#include <Riostream.h>
+#include <TVector2.h>
+
+#include "AliMpPlaneAreaPadIterator.h"
+#include "AliMpTransformPadIterator.h"
+#include "AliMpPlaneSegmentation.h"
+#include "AliMpSectorSegmentation.h"
+
+ClassImp(AliMpPlaneAreaPadIterator)
+
+//______________________________________________________________________________
+AliMpPlaneAreaPadIterator::AliMpPlaneAreaPadIterator(
+                                const AliMpPlaneSegmentation* segmentation,
+                                const AliMpArea& area) 
+ : AliMpVPadIterator(),
+   fkPlaneSegmentation(segmentation),
+   fkArea(area),
+   fPadIterators()
+{
+// Normal constructor, start in invalid position
+  DecomposeArea();
+
+  fCurrentIterator = fPadIterators.end();
+}
+
+//______________________________________________________________________________
+AliMpPlaneAreaPadIterator::AliMpPlaneAreaPadIterator(
+                                const AliMpPlaneAreaPadIterator& right)
+  : AliMpVPadIterator(right)
+{
+// copy constructor
+  Fatal("Copy constructor", "Not implemented");
+}
+
+//______________________________________________________________________________
+AliMpPlaneAreaPadIterator::AliMpPlaneAreaPadIterator()
+ : AliMpVPadIterator(),
+   fkPlaneSegmentation(0),
+   fkArea(AliMpArea()),
+   fPadIterators()
+{
+// Dummy default constructor.
+}
+
+//______________________________________________________________________________
+AliMpPlaneAreaPadIterator::~AliMpPlaneAreaPadIterator()
+{
+// destructor
+
+  // delete created iterators here
+}
+
+//
+// operators
+//
+
+//______________________________________________________________________________
+AliMpPlaneAreaPadIterator& 
+AliMpPlaneAreaPadIterator::operator = (const AliMpPlaneAreaPadIterator& right)
+{
+// Assignement operator
+
+  Fatal("operator =", "Not implemented.");
+  return *this;
+} 
+
+//
+// private methods
+//
+
+//______________________________________________________________________________
+void AliMpPlaneAreaPadIterator::DecomposeArea()
+{
+// Decompose the area into areas belonging to the quadrants.
+// --
+
+  for (Int_t i=0; i<fkPlaneSegmentation->GetNofTransformers(); i++) {
+  
+    AliMpTransformer* transformer = fkPlaneSegmentation->GetTransformer(i);
+    AliMpArea area = transformer->CutArea(fkArea);
+
+    if (area.IsValid()) {
+    
+      AliMpSectorSegmentation* segmentation 
+       = fkPlaneSegmentation->GetSectorSegmentation(transformer->GetScale());
+         
+      AliMpVPadIterator* sectorIt 
+       = segmentation->CreateIterator(area);
+           
+      fPadIterators.push_back(
+        new AliMpTransformPadIterator(sectorIt, transformer));
+    }  
+  }
+}
+
+//
+// public methods
+//
+
+//______________________________________________________________________________
+void AliMpPlaneAreaPadIterator::First()
+{
+// Reset the iterator, so that it points to the first available
+// pad in the area
+// ---
+  if (fPadIterators.size()==0) return;
+
+  fCurrentIterator = fPadIterators.begin();
+  (*fCurrentIterator)->First();
+
+  while ( fCurrentIterator != fPadIterators.end() &&
+          (*fCurrentIterator)->IsDone()) {
+        
+    fCurrentIterator++;
+    if (fCurrentIterator != fPadIterators.end()) {
+      (*fCurrentIterator)->First();
+    }           
+  }
+}
+
+//______________________________________________________________________________
+void AliMpPlaneAreaPadIterator::Next()
+{
+// Move the iterator to the next valid pad.
+// ---
+
+  (*fCurrentIterator)->Next();
+  
+  while ( fCurrentIterator != fPadIterators.end() &&
+          (*fCurrentIterator)->IsDone()) {
+        
+    fCurrentIterator++;
+    if (fCurrentIterator != fPadIterators.end()) {
+      (*fCurrentIterator)->First();
+    }           
+  }
+}
+
+//______________________________________________________________________________
+Bool_t AliMpPlaneAreaPadIterator::IsDone() const
+{
+// 
+  return  fCurrentIterator == fPadIterators.end();
+}
+
+//______________________________________________________________________________
+AliMpPad AliMpPlaneAreaPadIterator::CurrentItem() const 
+{
+// Returns the current pad.
+// ---
+
+  if (fCurrentIterator != fPadIterators.end())
+    return (*fCurrentIterator)->CurrentItem();
+  else
+    return AliMpPad::Invalid();  
+}
+
+//______________________________________________________________________________
+void AliMpPlaneAreaPadIterator::Invalidate()
+{
+// Invalidates all sector iterators and sets the current
+// iterator to invalid position.
+// ---
+  PadIteratorVectorIterator it;
+  for (it=fPadIterators.begin(); it !=fPadIterators.end(); it++) {
+    (*it)->Invalidate(); 
+  }
+  
+  fCurrentIterator = fPadIterators.end();
+}
+
diff --git a/MUON/mapping/AliMpPlaneAreaPadIterator.h b/MUON/mapping/AliMpPlaneAreaPadIterator.h
new file mode 100755 (executable)
index 0000000..7cf40e4
--- /dev/null
@@ -0,0 +1,60 @@
+// $Id$
+// Category: plane
+//
+// Class AliMpPlaneAreaPadIterator
+// -------------------------------
+// Class, which defines an iterator over the pads 
+// inside a given area in a plane in horizontal direction.
+//
+// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+
+#ifndef ALI_MP_PLANE_AREA_PAD_ITERATOR_H
+#define ALI_MP_PLANE_AREA_PAD_ITERATOR_H
+
+#include <TObject.h>
+
+#include "AliMpPlaneTypes.h"
+#include "AliMpVPadIterator.h"
+#include "AliMpTransformPadIterator.h"
+#include "AliMpArea.h"
+#include "AliMpPad.h"
+