LCOV - code coverage report
Current view: top level - MUON/MUONsim - AliMUONSlatGeometryBuilder.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1400 1432 97.8 %
Date: 2016-06-14 17:26:59 Functions: 13 13 100.0 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       3             :  *                                                                        *
       4             :  * Author: The ALICE Off-line Project.                                    *
       5             :  * Contributors are mentioned in the code where appropriate.              *
       6             :  *                                                                        *
       7             :  * Permission to use, copy, modify and distribute this software and its   *
       8             :  * documentation strictly for non-commercial purposes is hereby granted   *
       9             :  * without fee, provided that the above copyright notice appears in all   *
      10             :  * copies and that both the copyright notice and this permission notice   *
      11             :  * appear in the supporting documentation. The authors make no claims     *
      12             :  * about the suitability of this software for any purpose. It is          *
      13             :  * provided "as is" without express or implied warranty.                  *
      14             :  **************************************************************************/
      15             : 
      16             : // $Id$
      17             : //
      18             : 
      19             : //-----------------------------------------------------------------------------
      20             : /// \class AliMUONSlatGeometryBuilder
      21             : /// This Builder is designed according to the enveloppe methode. The basic idea is to be able to allow moves 
      22             : /// of the slats on the support panels. 
      23             : /// Those moves can be described with a simple set of parameters. The next step should be now to describe all 
      24             : /// the slats and their places by a unique 
      25             : /// class, which would make the SlatBuilder far more compact since now only three parameters can define a slat 
      26             : /// and its position, like:
      27             : ///   - Bool_t rounded_shape_slat
      28             : ///   - Float_t slat_length
      29             : ///   - Float_t slat_number or Float_t slat_position
      30             : /// Reference system is the one described in the note ALICE-INT-2003-038  v.2  EDMS Id 406391 
      31             : ///
      32             : /// \author Eric Dumonteil (dumontei@cea.fr)
      33             : //-----------------------------------------------------------------------------
      34             : 
      35             : #include "AliMUONSlatGeometryBuilder.h"
      36             : #include "AliMUON.h"
      37             : #include "AliMUONConstants.h"
      38             : #include "AliMUONGeometryModule.h"
      39             : #include "AliMUONGeometryEnvelopeStore.h"
      40             : #include "AliMUONConstants.h"
      41             : 
      42             : #include "AliMpDEManager.h"
      43             : 
      44             : #include "AliRun.h"
      45             : #include "AliLog.h"
      46             : 
      47             : #include <TVirtualMC.h>
      48             : #include <TGeoBBox.h>
      49             : #include <TGeoVolume.h>
      50             : #include <TGeoManager.h>
      51             : #include <TGeoMatrix.h>
      52             : #include <TGeoCompositeShape.h>
      53             : #include <TGeoTube.h>
      54             : #include <Riostream.h>
      55             : 
      56             : using std::endl;
      57             : using std::cout;
      58             : /// \cond CLASSIMP
      59          16 : ClassImp(AliMUONSlatGeometryBuilder)
      60             : /// \endcond
      61             : 
      62             : //______________________________________________________________________________
      63             : AliMUONSlatGeometryBuilder::AliMUONSlatGeometryBuilder(AliMUON* muon)
      64           1 :  : AliMUONVGeometryBuilder(4, 12),
      65           1 :    fMUON(muon)
      66           5 : {
      67             : /// Standard constructor
      68             : 
      69           2 : }
      70             : 
      71             : //______________________________________________________________________________
      72             : AliMUONSlatGeometryBuilder::AliMUONSlatGeometryBuilder() 
      73          12 :  : AliMUONVGeometryBuilder(),
      74          12 :    fMUON(0)
      75          60 : {
      76             : /// Default constructor
      77          24 : }
      78             : 
      79             : //______________________________________________________________________________
      80             : AliMUONSlatGeometryBuilder::~AliMUONSlatGeometryBuilder() 
      81          52 : {
      82             : /// Destructor
      83          52 : }
      84             : 
      85             : //
      86             : // public methods
      87             : //
      88             : 
      89             : //______________________________________________________________________________
      90             : void AliMUONSlatGeometryBuilder::CreateGeometry()
      91             : {
      92             :   /// CreateGeometry is the method containing all the informations concerning Stations 345 geometry.
      93             :   /// It includes description and placements of support panels and slats.
      94             :   /// The code comes directly from what was written in AliMUONv1.cxx before, with modifications concerning 
      95             :   /// the use of Enveloppe method to place the Geant volumes.
      96             :   /// Now, few changes would allow the creation of a Slat methode where slat could be described by few parameters, 
      97             :   /// and this builder would then be dedicated only to the
      98             :   /// placements of the slats. Those modifications could shorten the Station 345 geometry by a non-negligeable factor...
      99             :  
     100           2 :   Int_t *idtmed = fMUON->GetIdtmed()->GetArray()-1099;
     101             : 
     102             :   Float_t angle;
     103             :   Float_t *dum=0;
     104             : 
     105             :   // define the id of tracking media:
     106             :   //  Int_t idAir    = idtmed[1100]; // medium 1
     107           1 :   Int_t idGas    = idtmed[1108]; // medium 9 = Ar-CO2 gas (80%+20%)
     108           1 :   Int_t idCopper = idtmed[1110];
     109           1 :   Int_t idG10    = idtmed[1111];
     110           1 :   Int_t idCarbon = idtmed[1112];
     111           1 :   Int_t idRoha   = idtmed[1113];
     112           1 :   Int_t idNomex  = idtmed[1114]; // honey comb
     113           1 :   Int_t idNoryl  = idtmed[1115]; 
     114           1 :   Int_t idNomexB = idtmed[1116]; // bulk material 
     115             :   
     116             :   // Getting mediums for pannel support geometry
     117           1 :   TGeoMedium* kMedNomex     = gGeoManager->GetMedium("MUON_Nomex");
     118           1 :   TGeoMedium* kMedCarbon    = gGeoManager->GetMedium("MUON_CARBON");
     119             : 
     120             :   // sensitive area: 40*40 cm**2
     121             :   const Float_t kSensLength = 40.; 
     122             :   const Float_t kSensHeight = 40.; 
     123           1 :   const Float_t kSensWidth  = AliMUONConstants::Pitch()*2;// 0.5 cm, according to TDR fig 2.120 
     124             :   const Int_t kSensMaterial = idGas;
     125             :   //     const Float_t kYoverlap   = 1.5; 
     126             : 
     127             :   // PCB dimensions in cm; width: 30 mum copper   
     128             :   const Float_t kPcbLength  = kSensLength; 
     129             :   const Float_t kPcbHeight  = 58.; // updated Ch. Finck 
     130             :   const Float_t kPcbWidth   = 0.003; 
     131             :   const Int_t kPcbMaterial  = idCopper;
     132             : 
     133             :   // Insulating material: 220 mum G10 fiber  glued to pcb  
     134             :   const Float_t kInsuLength = kPcbLength; 
     135             :   const Float_t kInsuHeight = kPcbHeight; 
     136             :   const Float_t kInsuWidth  = 0.022;  // updated Ch. Finck 
     137             :   const Int_t kInsuMaterial = idG10;
     138             : 
     139             :   // Carbon fiber panels: 200mum carbon/epoxy skin   
     140             :   const Float_t kCarbonWidth  = 0.020;      
     141             :   const Int_t kCarbonMaterial = idCarbon;
     142             : 
     143             :   // Nomex (honey comb) between the two panel carbon skins    
     144             :   const Float_t kNomexLength = kSensLength; 
     145             :   const Float_t kNomexHeight = kSensHeight; 
     146             :   const Float_t kNomexWidth  = 0.8; // updated Ch. Finck 
     147             :   const Int_t kNomexMaterial = idNomex;
     148             :  
     149             :   // Bulk Nomex under panel sandwich Ch. Finck    
     150             :   const Float_t kNomexBWidth  = 0.025; 
     151             :   const Int_t kNomexBMaterial = idNomexB;
     152             : 
     153             :   // Panel sandwich 0.02 carbon*2 + 0.8 nomex     
     154             :   const Float_t kPanelLength = kSensLength; 
     155             :   const Float_t kPanelHeight = kSensHeight; 
     156             :   const Float_t kPanelWidth  = 2 * kCarbonWidth + kNomexWidth;
     157             : 
     158             :   // Frame along the rounded (spacers) slats 
     159             :   const Float_t kRframeHeight = 2.00; 
     160             : 
     161             :   // spacer around the slat: 2 sticks along length,2 along height  
     162             :   // H: the horizontal ones 
     163             :   const Float_t kHframeLength = kPcbLength; 
     164             :   const Float_t kHframeHeight = 1.95; // updated Ch. Finck 
     165             :   const Float_t kHframeWidth  = kSensWidth; 
     166             :   const Int_t kHframeMaterial = idNoryl;
     167             : 
     168             :   // V: the vertical ones; vertical spacers 
     169             :   const Float_t kVframeLength = 2.5; 
     170             :   const Float_t kVframeHeight = kSensHeight + kHframeHeight; 
     171             :   const Float_t kVframeWidth  = kSensWidth;
     172             :   const Int_t kVframeMaterial = idNoryl;
     173             : 
     174             :   // R: rounded part of vertical spacers 
     175             :   const Float_t kRframeLength = 2.0; 
     176             :   const Float_t kRframeWidth  = kSensWidth;
     177             :   const Int_t kRframeMaterial = idNoryl;
     178             : 
     179             :   // B: the horizontal border filled with rohacell: ok Ch. Finck
     180             :   const Float_t kBframeLength = kHframeLength; 
     181             :   const Float_t kBframeHeight = (kPcbHeight - kSensHeight)/2. - kHframeHeight; 
     182             :   const Float_t kBframeWidth  = kHframeWidth;
     183             :   const Int_t kBframeMaterial = idRoha;
     184             : 
     185             :   // NULOC: 30 mum copper + 200 mum vetronite (same radiation length as 14mum copper) for electronics
     186             :   const Float_t kNulocLength   = 2.5; 
     187             :   const Float_t kNulocHeight   = kBframeHeight;
     188             :   const Float_t kNulocWidth    = 0.0030 + 0.0014; // equivalent copper width of vetronite; 
     189             :   const Int_t   kNulocMaterial = idCopper;
     190             : 
     191             :   // Readout cables: Equivalent to 260 mum copper   
     192             :   const Float_t kCableHeight = 2.6; 
     193             :   const Float_t kCableWidth  = 0.026;  
     194             :   const Int_t kCableMaterial = idCopper;
     195             : 
     196             :   // Slat parameters
     197             :   const Float_t kSlatHeight = kPcbHeight; 
     198           1 :   const Float_t kSlatWidth  = kSensWidth + 2.*(kPcbWidth + kInsuWidth + kPanelWidth 
     199             :                                                + kNomexBWidth); //replaced rohacell with Nomex Ch. Finck 
     200             :   // const Int_t   kSlatMaterial = idAir;
     201             :   const Float_t kDslatLength  = -1.25; // position of the slat respect to the beam plane (half vertical spacer) Ch. Finck
     202           1 :   Float_t zSlat               = AliMUONConstants::DzSlat();// implemented Ch. Finck
     203           1 :   Float_t dzCh                = AliMUONConstants::DzCh();
     204             : 
     205             :   Float_t spar[3];  
     206             :   Int_t i, j;
     207             :   Int_t detElemId;
     208             :   Int_t moduleId;
     209             : 
     210             :   // the panel volume contains the nomex
     211           1 :   Float_t panelpar[3] = { static_cast<Float_t>(kPanelLength/2.), static_cast<Float_t>(kPanelHeight/2.), static_cast<Float_t>(kPanelWidth/2.) }; 
     212           1 :   Float_t nomexpar[3] = { static_cast<Float_t>(kNomexLength/2.), static_cast<Float_t>(kNomexHeight/2.), static_cast<Float_t>(kNomexWidth/2.) }; 
     213             :   Float_t twidth =  kPanelWidth +  kNomexBWidth; 
     214           1 :   Float_t nomexbpar[3] = {static_cast<Float_t>(kNomexLength/2.), static_cast<Float_t>(kNomexHeight/2.),static_cast<Float_t>(twidth/2.) };// bulk nomex 
     215             : 
     216             :   // insulating material contains PCB-> gas   
     217           1 :   twidth = 2*(kInsuWidth + kPcbWidth) + kSensWidth ; 
     218           1 :   Float_t insupar[3] = {static_cast<Float_t>(kInsuLength/2.), static_cast<Float_t>(kInsuHeight/2.), static_cast<Float_t>(twidth/2.) }; 
     219           1 :   twidth -= 2 * kInsuWidth; 
     220           1 :   Float_t pcbpar[3]  = {static_cast<Float_t>(kPcbLength/2.), static_cast<Float_t>(kPcbHeight/2.), static_cast<Float_t>(twidth/2.) }; 
     221           1 :   Float_t senspar[3] = {static_cast<Float_t>(kSensLength/2.), static_cast<Float_t>(kSensHeight/2.), static_cast<Float_t>(kSensWidth/2.) }; 
     222             :   Float_t theight    = 2 * kHframeHeight + kSensHeight;
     223           1 :   Float_t hFramepar[3] = {static_cast<Float_t>(kHframeLength/2.), static_cast<Float_t>(theight/2.), static_cast<Float_t>(kHframeWidth/2.)}; 
     224           1 :   Float_t bFramepar[3] = {static_cast<Float_t>(kBframeLength/2.), static_cast<Float_t>(kBframeHeight/2.), static_cast<Float_t>(kBframeWidth/2.)}; 
     225           1 :   Float_t vFramepar[3] = {static_cast<Float_t>(kVframeLength/2.), static_cast<Float_t>(kVframeHeight/2.), static_cast<Float_t>(kVframeWidth/2.)};
     226           1 :   Float_t nulocpar[3]  = {static_cast<Float_t>(kNulocLength/2.),  static_cast<Float_t>(kNulocHeight/2.),  static_cast<Float_t>(kNulocWidth/2.)}; 
     227             : 
     228             :   Float_t xx;
     229             :   Float_t xxmax = (kBframeLength - kNulocLength)/2.; 
     230             :   Int_t index=0;
     231           1 :   Int_t* fStations = new Int_t[5];
     232          12 :   for (Int_t iSt=0; iSt<5; iSt++) fStations[iSt] = 1;
     233           1 :   fStations[2] = 1;
     234             :      
     235           1 :   if (fStations[2])
     236             :     {
     237             :       //********************************************************************
     238             :       //                            Station 3                             **
     239             :       //********************************************************************
     240             :       // Mother volume for each chamber in St3 is an envelop (or assembly)
     241             :       // There is one assembly mother per half a chamber
     242             :       // Mother volume for each chamber in St3 is an envelop (or assembly)
     243             :       // There is one assembly mother per half a chamber  called SC05I, SC05O, SC06I and SC06O
     244             :       // volumes for slat geometry (xx=5,..,10 chamber id): 
     245             :       // Sxx0 Sxx1 Sxx2 Sxx3  -->   Slat Mother volumes 
     246             :       // SxxG                          -->   Sensitive volume (gas)
     247             :       // SxxP                          -->   PCB (copper) 
     248             :       // SxxI                          -->   Insulator (G10) 
     249             :       // SxxC                          -->   Carbon panel 
     250             :       // SxxN                          -->   Nomex comb
     251             :       // SxxX                          -->   Nomex bulk
     252             :       // SxxH, SxxV                    -->   Horizontal and Vertical frames (Noryl)
     253             :       // SB5x                          -->   Volumes for the 35 cm long PCB
     254             :       // slat dimensions: slat is a MOTHER volume!!! made of air
     255             :       // Only for chamber 5: slat 1 has a PCB shorter by 5cm!
     256             : 
     257             :       Float_t tlength = 35.;
     258           1 :       Float_t panelpar2[3]  = { static_cast<Float_t>(tlength/2.), panelpar[1],  panelpar[2]}; 
     259           1 :       Float_t nomexpar2[3]  = { static_cast<Float_t>(tlength/2.), nomexpar[1],  nomexpar[2]}; 
     260           1 :       Float_t nomexbpar2[3] = { static_cast<Float_t>(tlength/2.), nomexbpar[1],  nomexbpar[2]}; 
     261           1 :       Float_t insupar2[3]   = { static_cast<Float_t>(tlength/2.), insupar[1],   insupar[2]}; 
     262           1 :       Float_t pcbpar2[3]    = { static_cast<Float_t>(tlength/2.), pcbpar[1],    pcbpar[2]}; 
     263           1 :       Float_t senspar2[3]   = { static_cast<Float_t>(tlength/2.), senspar[1],   senspar[2]}; 
     264           1 :       Float_t hFramepar2[3] = { static_cast<Float_t>(tlength/2.), hFramepar[1], hFramepar[2]}; 
     265           1 :       Float_t bFramepar2[3] = { static_cast<Float_t>(tlength/2.), bFramepar[1], bFramepar[2]}; 
     266             :       Float_t pcbDLength3   = (kPcbLength - tlength);
     267             :       
     268             :       // For rounded pcb of central slat
     269             :       Float_t csvPcbLength = 59.25-40.; // PQ-LAT-SR1
     270           1 :       Float_t panelpar3[3]  = { static_cast<Float_t>(csvPcbLength/2.), panelpar[1],  panelpar[2]}; 
     271           1 :       Float_t nomexpar3[3]  = { static_cast<Float_t>(csvPcbLength/2.), nomexpar[1],  nomexpar[2]}; 
     272           1 :       Float_t nomexbpar3[3] = {static_cast<Float_t>( csvPcbLength/2.), nomexbpar[1],  nomexbpar[2]}; 
     273           1 :       Float_t insupar3[3]   = { static_cast<Float_t>(csvPcbLength/2.), insupar[1],   insupar[2]}; 
     274           1 :       Float_t pcbpar3[3]    = { static_cast<Float_t>(csvPcbLength/2.), pcbpar[1],    pcbpar[2]}; 
     275           1 :       Float_t senspar3[3]   = { static_cast<Float_t>(csvPcbLength/2.), senspar[1],   senspar[2]}; 
     276           1 :       Float_t hFramepar3[3] = { static_cast<Float_t>(csvPcbLength/2.), hFramepar[1], hFramepar[2]}; 
     277           1 :       Float_t bFramepar3[3] = { static_cast<Float_t>(csvPcbLength/2.), bFramepar[1], bFramepar[2]}; 
     278           1 :       Float_t cPhi = TMath::RadToDeg()*(TMath::Pi()/2.-TMath::ACos(hFramepar3[1]/(AliMUONConstants::Rmin(2)-kRframeLength)));
     279           1 :       Float_t cFramepar3[5] = { AliMUONConstants::Rmin(2)-kRframeLength, AliMUONConstants::Rmin(2), kRframeWidth, -cPhi, cPhi}; 
     280             : 
     281             :       const Int_t   kNslats3         = 5;  // number of slats per quadrant
     282             :       const Int_t   kNPCB3[kNslats3] = {4, 4, 4, 3, 2}; // n PCB per slat
     283             :       const Float_t kXpos3[kNslats3] = {0., 0., 0., 0., 0.};//{31., 0., 0., 0., 0.};
     284             :       const Float_t kYpos3[kNslats3] = {0, 37.8, 37.7, 37.3, 33.7};
     285           1 :       Float_t slatLength3[kNslats3]; 
     286             : 
     287           1 :       Float_t rPhi1 = TMath::RadToDeg()*(TMath::ASin((kYpos3[1]-hFramepar3[1])/(AliMUONConstants::Rmin(2))));
     288           1 :       Float_t rPhi2 = TMath::RadToDeg()*(TMath::ACos(-vFramepar[0]/(AliMUONConstants::Rmin(2)-kRframeLength)));
     289           1 :       Float_t rFramepar3[5] = { AliMUONConstants::Rmin(2)-kRframeLength, AliMUONConstants::Rmin(2), kRframeWidth, rPhi1, rPhi2}; 
     290           1 :       Float_t vrFrameHeight = hFramepar3[1]+kYpos3[1]-AliMUONConstants::Rmin(2)+kRframeLength;
     291             : 
     292             :       // create and position the slat (mother) volumes 
     293             : 
     294           1 :       char idSlatCh5[6];
     295           1 :       char idSlatCh6[6];
     296             :       Float_t xSlat3;
     297             :       Float_t ySlat3 = 0;
     298             :       angle = 0.;
     299             : 
     300             :       Float_t spar2[3];
     301          12 :       for (i = 0; i < kNslats3; i++){
     302             : 
     303           5 :         slatLength3[i] = kPcbLength * kNPCB3[i] + 2.* kVframeLength; 
     304           5 :         xSlat3 = slatLength3[i]/2. +  kDslatLength + kXpos3[i]; 
     305           5 :         ySlat3 += kYpos3[i];
     306             : 
     307           5 :         spar[0] = slatLength3[i]/2.; 
     308             :         spar[1] = kSlatHeight/2.;
     309           5 :         spar[2] = kSlatWidth/2.; 
     310             :         // take away 5 cm from the first slat in chamber 5
     311           5 :         if (i == 0 || i == 1 || i == 2) { // 1 pcb is shortened by 5cm
     312           3 :           spar2[0] = spar[0] - pcbDLength3/2.;
     313           3 :         } else {
     314             :           spar2[0] = spar[0];
     315             :         }
     316             :         spar2[1] = spar[1];
     317             :         spar2[2] = spar[2]; 
     318             :         Float_t dzCh3 = dzCh; 
     319             :         Float_t dzSlat3 = -0.25; // see drawing PQ7EN345-6 (Delta_slat=80mm instead 85mm)
     320           5 :         Float_t zSlat3 = (i%2 ==0)? -(zSlat+dzSlat3) : (zSlat+dzSlat3); // seems not that zSlat3 = zSlat4 & 5 refering to plan PQ7EN345-6 ? -> Indeed, fixed J.C.
     321             : 
     322           5 :         sprintf(idSlatCh5,"SLA%d",i+kNslats3-1);
     323           5 :         detElemId = 509 - (i + kNslats3-1-4);
     324           5 :         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
     325           5 :         if (detElemId == 508 || detElemId == 509) // Round slat, new rotation due to mapping convention
     326           6 :           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh5, detElemId, true, TGeoTranslation(xSlat3, ySlat3, -zSlat3 + dzCh3),
     327           2 :                                               TGeoRotation("rot1",90,180+angle,90,90+angle,180,0) );
     328             :         else {
     329           6 :           if (detElemId % 2 == 0)
     330           6 :             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh5, detElemId, true, TGeoTranslation(xSlat3, ySlat3, -zSlat3 + dzCh3),
     331           1 :                                                 TGeoRotation("rot1",90,angle,90,90+angle,0,0) );        
     332             :           else 
     333           6 :             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh5, detElemId, true, TGeoTranslation(xSlat3, ySlat3, -zSlat3 + dzCh3),
     334           2 :                                                 TGeoRotation("rot1",90,angle,90,270+angle,180,0) ); 
     335             :         }
     336             :      
     337           5 :         sprintf(idSlatCh5,"SLA%d",3*kNslats3-2+i);
     338           5 :         detElemId = 500 + (i + kNslats3-1-4);
     339           5 :         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
     340           5 :         if (detElemId == 500 || detElemId == 501) // Round slat, new rotation due to mapping convention
     341           6 :           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh5, detElemId, true, TGeoTranslation(-xSlat3, ySlat3, zSlat3 - dzCh3),
     342           2 :                                               TGeoRotation("rot2",90,angle,90,90+angle,0,0) );
     343             :         else {
     344           6 :           if (detElemId % 2 == 1) 
     345           6 :             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh5, detElemId, true, TGeoTranslation(-xSlat3, ySlat3, zSlat3 - dzCh3),
     346           1 :                                                 TGeoRotation("rot2",90,180+angle,90,90+angle,180,0) );           
     347             :           else
     348           6 :             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh5, detElemId, true, TGeoTranslation(-xSlat3, ySlat3, zSlat3 - dzCh3),
     349           2 :                                                 TGeoRotation("rot2",90,180+angle,90,270+angle,0,0) );
     350             :         }
     351             : 
     352           5 :         if (i > 0) { 
     353           4 :           sprintf(idSlatCh5,"SLA%d",kNslats3-1-i);
     354           4 :           detElemId = 509 + (i + kNslats3-1-4);
     355           4 :           moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
     356           4 :           if (detElemId % 2 == 0 ) {
     357           4 :             if (detElemId == 510) // Round slat, new rotation due to mapping convention
     358           5 :               GetEnvelopes(moduleId)->AddEnvelope(idSlatCh5, detElemId, true, TGeoTranslation(xSlat3, -ySlat3, -zSlat3 + dzCh3), 
     359           1 :                                                   TGeoRotation("rot3",90,180+angle,90,270+angle,0,0) );
     360             :             else
     361           3 :               GetEnvelopes(moduleId)->AddEnvelope(idSlatCh5, detElemId, true, TGeoTranslation(xSlat3, -ySlat3, -zSlat3 + dzCh3), 
     362           1 :                                                   TGeoRotation("rot3",90,angle,90,90+angle,0,0) );
     363             :           }
     364             :           else
     365           6 :               GetEnvelopes(moduleId)->AddEnvelope(idSlatCh5, detElemId, true, TGeoTranslation(xSlat3, -ySlat3, -zSlat3 + dzCh3), 
     366           2 :                                                   TGeoRotation("rot3",90,angle,90,270+angle,180,0) );
     367             : 
     368           4 :           sprintf(idSlatCh5,"SLA%d",3*kNslats3-2-i);
     369           4 :           detElemId = 518 - (i + kNslats3-1-4);
     370           4 :           moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
     371           4 :           if (detElemId % 2 == 1) {
     372           4 :             if (detElemId == 517) // Round slat, new rotation due to mapping convention
     373           5 :               GetEnvelopes(moduleId)->AddEnvelope(idSlatCh5, detElemId, true, TGeoTranslation(-xSlat3, -ySlat3, zSlat3 - dzCh3),
     374           1 :                                                   TGeoRotation("rot4",90,angle,90,270+angle,180,0) );
     375             :             else
     376           3 :               GetEnvelopes(moduleId)->AddEnvelope(idSlatCh5, detElemId, true, TGeoTranslation(-xSlat3, -ySlat3, zSlat3 - dzCh3),
     377           1 :                                                   TGeoRotation("rot4",90,180+angle,90,90+angle,180,0) );
     378             :           }
     379             :           else
     380           6 :               GetEnvelopes(moduleId)->AddEnvelope(idSlatCh5, detElemId, true, TGeoTranslation(-xSlat3, -ySlat3, zSlat3 - dzCh3),
     381           2 :                                                   TGeoRotation("rot4",90,180+angle,90,270+angle,0,0) );   
     382             :         }
     383             : 
     384           5 :         sprintf(idSlatCh6,"SLB%d",kNslats3-1+i);  
     385           5 :         detElemId = 609 - (i  + kNslats3-1-4);
     386           5 :         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
     387           5 :         if (detElemId == 608 || detElemId == 609) // Round slat, new rotation due to mapping convention
     388           6 :           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh6, detElemId, true, TGeoTranslation(xSlat3, ySlat3, -zSlat3 + dzCh3),
     389           2 :                                               TGeoRotation("rot5",90,180+angle,90,90+angle,180,0));
     390             :         else {
     391           6 :           if (detElemId % 2 == 0) 
     392           6 :             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh6, detElemId, true, TGeoTranslation(xSlat3, ySlat3, -zSlat3 + dzCh3),
     393           1 :                                                 TGeoRotation("rot5",90,angle,90,90+angle,0,0));
     394             :           else
     395           6 :             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh6, detElemId, true, TGeoTranslation(xSlat3, ySlat3, -zSlat3 + dzCh3),
     396           2 :                                                 TGeoRotation("rot5",90,angle,90,270+angle,180,0));
     397             :         }
     398             : 
     399           5 :         sprintf(idSlatCh6,"SLB%d",3*kNslats3-2+i);
     400           5 :         detElemId = 600 + (i + kNslats3-1-4);
     401           5 :         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
     402           5 :         if (detElemId == 600 || detElemId == 601) // Round slat, new rotation due to mapping convention
     403           6 :           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh6, detElemId, true, TGeoTranslation(-xSlat3, ySlat3, zSlat3 - dzCh3),
     404           2 :                                               TGeoRotation("rot6",90,angle,90,90+angle,0,0) );
     405             :         else {
     406           6 :           if (detElemId % 2 == 1) 
     407           6 :             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh6, detElemId, true, TGeoTranslation(-xSlat3, ySlat3, zSlat3 - dzCh3),
     408           1 :                                                 TGeoRotation("rot6",90,180+angle,90,90+angle,180,0) ); 
     409             :           else
     410           6 :             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh6, detElemId, true, TGeoTranslation(-xSlat3, ySlat3, zSlat3 - dzCh3),
     411           2 :                                                 TGeoRotation("rot6",90,180+angle,90,270+angle,0,0) );
     412             :         }
     413             : 
     414           5 :         if (i > 0) { 
     415           4 :           sprintf(idSlatCh6,"SLB%d",kNslats3-1-i);
     416           4 :           detElemId = 609 + (i + kNslats3-1-4);
     417           4 :           moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
     418           4 :           if (detElemId % 2 == 0 ) {
     419           4 :             if (detElemId == 610) // Round slat, new rotation due to mapping convention
     420           5 :               GetEnvelopes(moduleId)->AddEnvelope(idSlatCh6, detElemId, true, TGeoTranslation(xSlat3, -ySlat3, -zSlat3 + dzCh3),
     421           1 :                                                   TGeoRotation("rot7",90,180+angle,90,270+angle,0,0) );
     422             :             else
     423           3 :               GetEnvelopes(moduleId)->AddEnvelope(idSlatCh6, detElemId, true, TGeoTranslation(xSlat3, -ySlat3, -zSlat3 + dzCh3),
     424           1 :                                                   TGeoRotation("rot7",90,angle,90,90+angle,0,0) );
     425             :           }
     426             :           else
     427           6 :               GetEnvelopes(moduleId)->AddEnvelope(idSlatCh6, detElemId, true, TGeoTranslation(xSlat3, -ySlat3, -zSlat3 + dzCh3),
     428           2 :                                                   TGeoRotation("rot7",90,angle,90,270+angle,180,0) );
     429             : 
     430           4 :           sprintf(idSlatCh6,"SLB%d",3*kNslats3-2-i);
     431           4 :           detElemId = 618 - (i + kNslats3-1-4);
     432           4 :           moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
     433           4 :           if (detElemId % 2 == 1) {
     434           4 :             if (detElemId == 617) // Round slat, new rotation due to mapping convention
     435           5 :               GetEnvelopes(moduleId)->AddEnvelope(idSlatCh6, detElemId, true, TGeoTranslation(-xSlat3, -ySlat3, zSlat3 - dzCh3),
     436           1 :                                                   TGeoRotation("rot8",90,angle,90,270+angle,180,0) );
     437             :             else
     438           3 :               GetEnvelopes(moduleId)->AddEnvelope(idSlatCh6, detElemId, true, TGeoTranslation(-xSlat3, -ySlat3, zSlat3 - dzCh3),
     439           1 :                                                   TGeoRotation("rot8",90,180+angle,90,90+angle,180,0) );
     440             :           }
     441             :           else
     442           6 :               GetEnvelopes(moduleId)->AddEnvelope(idSlatCh6, detElemId, true, TGeoTranslation(-xSlat3, -ySlat3, zSlat3 - dzCh3),
     443           2 :                                                   TGeoRotation("rot8",90,180+angle,90,270+angle,0,0) );   
     444             :         }
     445             :       }
     446             :      
     447             :       // create the panel volume 
     448             :  
     449           1 :       TVirtualMC::GetMC()->Gsvolu("S05C","BOX",kCarbonMaterial,panelpar,3);
     450           1 :       TVirtualMC::GetMC()->Gsvolu("SB5C","BOX",kCarbonMaterial,panelpar2,3);
     451           1 :       TVirtualMC::GetMC()->Gsvolu("SC5C","BOX",kCarbonMaterial,panelpar3,3);
     452           1 :       TVirtualMC::GetMC()->Gsvolu("SD5C","BOX",kCarbonMaterial,panelpar,3);
     453           1 :       TVirtualMC::GetMC()->Gsvolu("S06C","BOX",kCarbonMaterial,panelpar,3);
     454           1 :       TVirtualMC::GetMC()->Gsvolu("SC6C","BOX",kCarbonMaterial,panelpar3,3);
     455           1 :       TVirtualMC::GetMC()->Gsvolu("SD6C","BOX",kCarbonMaterial,panelpar,3);
     456             :  
     457             :       // create the nomex volume (honey comb)
     458             : 
     459           1 :       TVirtualMC::GetMC()->Gsvolu("S05N","BOX",kNomexMaterial,nomexpar,3);
     460           1 :       TVirtualMC::GetMC()->Gsvolu("SB5N","BOX",kNomexMaterial,nomexpar2,3);
     461           1 :       TVirtualMC::GetMC()->Gsvolu("SC5N","BOX",kNomexMaterial,nomexpar3,3);
     462           1 :       TVirtualMC::GetMC()->Gsvolu("SD5N","BOX",kNomexMaterial,nomexpar,3);
     463           1 :       TVirtualMC::GetMC()->Gsvolu("S06N","BOX",kNomexMaterial,nomexpar,3);
     464           1 :       TVirtualMC::GetMC()->Gsvolu("SC6N","BOX",kNomexMaterial,nomexpar3,3);
     465           1 :       TVirtualMC::GetMC()->Gsvolu("SD6N","BOX",kNomexMaterial,nomexpar,3);
     466             :  
     467             :       // create the nomex volume (bulk)
     468             : 
     469           1 :       TVirtualMC::GetMC()->Gsvolu("S05X","BOX",kNomexBMaterial,nomexbpar,3);
     470           1 :       TVirtualMC::GetMC()->Gsvolu("SB5X","BOX",kNomexBMaterial,nomexbpar2,3);
     471           1 :       TVirtualMC::GetMC()->Gsvolu("SC5X","BOX",kNomexBMaterial,nomexbpar3,3);
     472           1 :       TVirtualMC::GetMC()->Gsvolu("SD5X","BOX",kNomexBMaterial,nomexbpar,3);
     473           1 :       TVirtualMC::GetMC()->Gsvolu("S06X","BOX",kNomexBMaterial,nomexbpar,3);
     474           1 :       TVirtualMC::GetMC()->Gsvolu("SC6X","BOX",kNomexBMaterial,nomexbpar3,3);
     475           1 :       TVirtualMC::GetMC()->Gsvolu("SD6X","BOX",kNomexBMaterial,nomexbpar,3);
     476             : 
     477             :       // create the insulating material volume 
     478             : 
     479           1 :       TVirtualMC::GetMC()->Gsvolu("S05I","BOX",kInsuMaterial,insupar,3);
     480           1 :       TVirtualMC::GetMC()->Gsvolu("SB5I","BOX",kInsuMaterial,insupar2,3);
     481           1 :       TVirtualMC::GetMC()->Gsvolu("SC5I","BOX",kInsuMaterial,insupar3,3);
     482           1 :       TVirtualMC::GetMC()->Gsvolu("SD5I","BOX",kInsuMaterial,insupar,3);
     483           1 :       TVirtualMC::GetMC()->Gsvolu("S06I","BOX",kInsuMaterial,insupar,3);
     484           1 :       TVirtualMC::GetMC()->Gsvolu("SC6I","BOX",kInsuMaterial,insupar3,3);
     485           1 :       TVirtualMC::GetMC()->Gsvolu("SD6I","BOX",kInsuMaterial,insupar,3);
     486             :  
     487             :       // create the PCB volume 
     488             : 
     489           1 :       TVirtualMC::GetMC()->Gsvolu("S05P","BOX",kPcbMaterial,pcbpar,3);
     490           1 :       TVirtualMC::GetMC()->Gsvolu("SB5P","BOX",kPcbMaterial,pcbpar2,3);
     491           1 :       TVirtualMC::GetMC()->Gsvolu("SC5P","BOX",kPcbMaterial,pcbpar3,3);
     492           1 :       TVirtualMC::GetMC()->Gsvolu("SD5P","BOX",kPcbMaterial,pcbpar,3);
     493           1 :       TVirtualMC::GetMC()->Gsvolu("S06P","BOX",kPcbMaterial,pcbpar,3);
     494           1 :       TVirtualMC::GetMC()->Gsvolu("SC6P","BOX",kPcbMaterial,pcbpar3,3);
     495           1 :       TVirtualMC::GetMC()->Gsvolu("SD6P","BOX",kPcbMaterial,pcbpar,3);
     496             :  
     497             :       // create the sensitive volumes,
     498             : 
     499           1 :       TVirtualMC::GetMC()->Gsvolu("S05G","BOX",kSensMaterial,dum,0);
     500           1 :       TVirtualMC::GetMC()->Gsvolu("SC5G","BOX",kSensMaterial,senspar3,3);
     501           1 :       TVirtualMC::GetMC()->Gsvolu("SD5G","BOX",kSensMaterial,senspar,3);
     502           1 :       TVirtualMC::GetMC()->Gsvolu("S06G","BOX",kSensMaterial,dum,0);
     503           1 :       TVirtualMC::GetMC()->Gsvolu("SC6G","BOX",kSensMaterial,senspar3,3);
     504           1 :       TVirtualMC::GetMC()->Gsvolu("SD6G","BOX",kSensMaterial,senspar,3);
     505             : 
     506             :       // create the vertical frame volume 
     507             : 
     508           1 :       TVirtualMC::GetMC()->Gsvolu("S05V","BOX",kVframeMaterial,vFramepar,3);
     509           1 :       TVirtualMC::GetMC()->Gsvolu("S06V","BOX",kVframeMaterial,vFramepar,3);
     510             : 
     511             :       // create the rounded vertical frame volume 
     512             : 
     513           1 :       TVirtualMC::GetMC()->Gsvolu("SC5D","TUBS",kRframeMaterial,cFramepar3,5);
     514           1 :       TVirtualMC::GetMC()->Gsvolu("SD5D","TUBS",kRframeMaterial,rFramepar3,5);
     515           1 :       TVirtualMC::GetMC()->Gsvolu("SC6D","TUBS",kRframeMaterial,cFramepar3,5);
     516           1 :       TVirtualMC::GetMC()->Gsvolu("SD6D","TUBS",kRframeMaterial,rFramepar3,5);
     517             : 
     518             :       // create the horizontal frame volume 
     519             : 
     520           1 :       TVirtualMC::GetMC()->Gsvolu("S05H","BOX",kHframeMaterial,hFramepar,3);
     521           1 :       TVirtualMC::GetMC()->Gsvolu("SB5H","BOX",kHframeMaterial,hFramepar2,3);
     522           1 :       TVirtualMC::GetMC()->Gsvolu("SC5H","BOX",kHframeMaterial,hFramepar3,3);
     523           1 :       TVirtualMC::GetMC()->Gsvolu("SD5H","BOX",kHframeMaterial,hFramepar,3);
     524           1 :       TVirtualMC::GetMC()->Gsvolu("S06H","BOX",kHframeMaterial,hFramepar,3);
     525           1 :       TVirtualMC::GetMC()->Gsvolu("SC6H","BOX",kHframeMaterial,hFramepar3,3);
     526           1 :       TVirtualMC::GetMC()->Gsvolu("SD6H","BOX",kHframeMaterial,hFramepar,3);
     527             :  
     528             :       // create the horizontal border volume 
     529             : 
     530           1 :       TVirtualMC::GetMC()->Gsvolu("S05B","BOX",kBframeMaterial,bFramepar,3);
     531           1 :       TVirtualMC::GetMC()->Gsvolu("SB5B","BOX",kBframeMaterial,bFramepar2,3);
     532           1 :       TVirtualMC::GetMC()->Gsvolu("SC5B","BOX",kBframeMaterial,bFramepar3,3);
     533           1 :       TVirtualMC::GetMC()->Gsvolu("SD5B","BOX",kBframeMaterial,bFramepar,3);
     534           1 :       TVirtualMC::GetMC()->Gsvolu("S06B","BOX",kBframeMaterial,bFramepar,3);
     535           1 :       TVirtualMC::GetMC()->Gsvolu("SC6B","BOX",kBframeMaterial,bFramepar3,3);
     536           1 :       TVirtualMC::GetMC()->Gsvolu("SD6B","BOX",kBframeMaterial,bFramepar,3);
     537             : 
     538             :       // Replace the volume shape with a composite shape
     539             :       // with substracted overlap with beam shield     
     540           1 :       if ( TVirtualMC::GetMC()->IsRootGeometrySupported() ) { 
     541             :         
     542             :         // Get shape
     543             :         Int_t nSlatType = 2;
     544             :         Int_t nVol = 8;
     545             :         const char* slatType = "CD"; // C: central slat; D: rounded slat
     546             :         const char* volLetter = "CNXIPHBG";
     547           1 :         TString volName;
     548           1 :         TString compName;
     549           1 :         TString csName;
     550             :         TGeoVolume *mVol = 0x0;
     551           1 :         TObjArray centerSlat(nSlatType*((nVol+1)*2));   
     552           1 :         TObjArray composite(nSlatType*((nVol+1)*2));
     553             : 
     554             :         // Beam shield recess
     555           3 :         new TGeoTube("tubeCut", 0., AliMUONConstants::Rmin(2), kSlatWidth/2.+0.001);
     556             :         // Displacement
     557           2 :         TGeoTranslation* trCTube = new TGeoTranslation("trCTube", -(kPcbLength-csvPcbLength/2.+kVframeLength/2.), 0., 0.);
     558           1 :         trCTube->RegisterYourself();
     559           2 :         TGeoTranslation* trDTube = new TGeoTranslation("trDTube", -(kPcbLength+kVframeLength)/2., -kYpos3[1], 0.);
     560           1 :         trDTube->RegisterYourself();
     561           2 :         TGeoTranslation* trCBTube = new TGeoTranslation("trCBTube", 0., ( kPcbHeight - kBframeHeight ) / 2., 0.);
     562           1 :         trCBTube->Add(trCTube);
     563           1 :         trCBTube->RegisterYourself();
     564           2 :         TGeoTranslation* trDBTube = new TGeoTranslation("trDBTube", 0., ( kPcbHeight - kBframeHeight ) / 2., 0.);
     565           1 :         trDBTube->Add(trDTube);
     566           1 :         trDBTube->RegisterYourself();
     567             : 
     568           2 :         Float_t cPhi2 = (TMath::Pi()/2.-TMath::ACos((kSensHeight/2.)/(AliMUONConstants::Rmin(2)-kRframeLength)));
     569           2 :         TGeoBBox *boxCCut = new TGeoBBox("boxCCut",(cFramepar3[1]-cFramepar3[0]*TMath::Cos(cPhi2))/2., hFramepar3[1], cFramepar3[2]+0.001);
     570             :         // Displacement
     571           3 :         TGeoTranslation* trCBox = new TGeoTranslation("trCBox",cFramepar3[0]*TMath::Cos(cPhi2)+boxCCut->GetDX(), 0., 0.);
     572           1 :         trCBox->RegisterYourself();
     573           2 :         new TGeoBBox("boxDCut",(kPcbLength+kVframeLength)/2., hFramepar3[1], vFramepar[2]+0.001);
     574             :         // Displacement
     575           2 :         TGeoTranslation* trDBox = new TGeoTranslation("trDBox",kPcbLength/2., kYpos3[1], 0.);
     576           1 :         trDBox->RegisterYourself();
     577             : 
     578           2 :         TGeoBBox *boxVframe = new TGeoBBox("boxVframe",vFramepar[0],vrFrameHeight/2., vFramepar[2]);
     579           4 :         TGeoTranslation* trVBox = new TGeoTranslation("trVBox", 0., AliMUONConstants::Rmin(2)-kRframeLength + boxVframe->GetDY(), 0.);
     580           1 :         trVBox->RegisterYourself();
     581             : 
     582           6 :         for(int iCh=5; iCh<=6; iCh++){
     583          12 :           for (int iSlatType = 0; iSlatType<nSlatType; iSlatType++) {
     584          72 :             for (int iVol = 0; iVol<nVol; iVol++){
     585          32 :               Int_t lIndex = (iCh-5)*(nSlatType*(nVol+1))+iSlatType*(nVol+1)+iVol;
     586          64 :               volName=Form("S%c%d%c",slatType[iSlatType],iCh,volLetter[iVol]);
     587          64 :               mVol = gGeoManager->FindVolumeFast(volName);
     588          32 :               if ( !mVol ) {
     589           0 :                 AliErrorStream() 
     590           0 :                   << "Slat volume " << volName << " not found" << endl;      
     591             :               }
     592             :               else {
     593          64 :                 centerSlat[lIndex] = mVol->GetShape();
     594          64 :                 csName=Form("centerSlat%c%d%c",slatType[iSlatType],iCh,volLetter[iVol]);
     595          96 :                 ((TGeoShape*)centerSlat[lIndex])->SetName(csName); 
     596             : 
     597             :                 // Composite shape
     598          32 :                 TString compOperation(csName);
     599          32 :                 compOperation+="-tubeCut:tr";
     600          32 :                 compOperation+=slatType[iSlatType];
     601          96 :                 if (strstr(volName,"B")){
     602           4 :                   compOperation+="B";
     603             :                 }
     604          32 :                 compOperation+="Tube";
     605          64 :                 compName=Form("composite%c%d%c",slatType[iSlatType],iCh,volLetter[iVol]);
     606         192 :                 composite[lIndex] = new TGeoCompositeShape(compName, compOperation.Data()); 
     607             :                 // Reset shape to volume      
     608          64 :                 mVol->SetShape((TGeoShape*)composite[lIndex]);
     609          32 :               }
     610             :             }
     611             : 
     612             :             // For rounded spacer
     613           4 :             Int_t lIndex = (iCh-5)*(nSlatType*(nVol+1))+iSlatType*(nVol+1)+nVol;
     614           8 :             volName=Form("S%c%dD",slatType[iSlatType],iCh);
     615           8 :             mVol = gGeoManager->FindVolumeFast(volName);
     616           4 :             if ( !mVol ) {
     617           0 :               AliErrorStream() 
     618           0 :                 << "Slat volume " << volName << " not found" << endl;        
     619             :             }
     620             :             else {
     621           8 :               centerSlat[lIndex] = mVol->GetShape();
     622           8 :               csName=Form("centerSlat%c%dD",slatType[iSlatType],iCh);
     623          12 :               ((TGeoShape*)centerSlat[lIndex])->SetName(csName);               
     624             :               
     625             :               // Composite shape
     626           4 :               TString compOperation(csName);
     627          12 :               if (strstr(volName,"SC")){
     628           2 :                 compOperation+="*boxCCut:trCBox";
     629             :               }
     630          12 :               if (strstr(volName,"SD")){
     631           2 :                 compOperation.Prepend("(");
     632           2 :                 compOperation+="+boxVframe:trVBox)*boxDCut:trDBox";
     633             :               }
     634           8 :               compName=Form("composite%c%dD",slatType[iSlatType],iCh);
     635          24 :               composite[lIndex] = new TGeoCompositeShape(compName, compOperation.Data());             
     636             :               // Reset shape to volume      
     637           8 :               mVol->SetShape((TGeoShape*)composite[lIndex]);
     638           4 :             }
     639             :           }
     640             :         }
     641           1 :       }
     642             :         
     643             :       index = 0; 
     644          12 :       for (i = 0; i<kNslats3; i++){
     645          50 :         for (Int_t quadrant = 1; quadrant <= 4; quadrant++) {
     646             : 
     647          20 :           if (i == 0 && quadrant == 2) continue;
     648          19 :           if (i == 0 && quadrant == 4) continue;
     649             : 
     650          18 :           sprintf(idSlatCh5,"SLA%d",ConvertSlatNum(i,quadrant,kNslats3-1));
     651          18 :           sprintf(idSlatCh6,"SLB%d",ConvertSlatNum(i,quadrant,kNslats3-1));
     652          36 :           Int_t moduleSlatCh5 = GetModuleId(idSlatCh5);
     653          36 :           Int_t moduleSlatCh6 = GetModuleId(idSlatCh6);
     654          18 :           Float_t xvFrame  = (slatLength3[i] - kVframeLength)/2.;
     655             :           Float_t xvFrame2  = xvFrame;    
     656             : 
     657          28 :           if (i == 0 || i == 1 || i == 2) xvFrame2 -= pcbDLength3; // Correct position (J.C.)
     658             : 
     659             :           // position the vertical frames 
     660          18 :           if ( i > 2) { 
     661          24 :             GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05V", idSlatCh5, 
     662           8 :                                                     (2*i+1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
     663          24 :             GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05V", idSlatCh5, 
     664           8 :                                                     (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
     665          24 :             GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06V", idSlatCh6, 
     666           8 :                                                     (2*i+1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
     667          24 :             GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06V", idSlatCh6, 
     668           8 :                                                     (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));   
     669           8 :           } 
     670             : 
     671          18 :           if (i == 2) {
     672          12 :             GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05V", idSlatCh5, 
     673           4 :                                                     (2*i+1)*10+quadrant,TGeoTranslation(xvFrame2,0.,0.)); 
     674          12 :             GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05V", idSlatCh5, 
     675           4 :                                                     (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
     676          12 :             GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06V", idSlatCh6, 
     677           4 :                                                     (2*i+1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
     678          12 :             GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06V", idSlatCh6, 
     679           4 :                                                     (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
     680           4 :           }
     681             : 
     682             :           // Different rotation due to new mapping convention
     683          18 :           if (i == 0 || i == 1) { // first vertical spacers
     684          18 :             GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05V", idSlatCh5, 
     685          12 :                                                     (2*i+1)*10+quadrant,TGeoTranslation(-xvFrame2,0.,0.),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0)); 
     686          18 :             GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06V", idSlatCh6, 
     687          12 :                                                     (2*i+1)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));         
     688           6 :             if (i == 0) { // rounded spacer for central slat (J.C.)
     689           6 :               GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SC5D", idSlatCh5, 
     690           4 :                                                                   (2*i)*10+quadrant,TGeoTranslation(xvFrame,0.,0.),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
     691           6 :               GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("SC6D", idSlatCh6, 
     692           4 :                                                                   (2*i)*10+quadrant,TGeoTranslation(xvFrame,0.,0.),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
     693             : 
     694           2 :             }
     695           6 :             if (i == 1) { // rounded + vertical spacer for rounded slat (J.C.)
     696          12 :               GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SD5D", idSlatCh5, 
     697           8 :                                                                   (2*i)*10+quadrant,TGeoTranslation(xvFrame,-kYpos3[1],0.),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
     698          12 :               GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("SD6D", idSlatCh6, 
     699           8 :                                                                   (2*i)*10+quadrant,TGeoTranslation(xvFrame,-kYpos3[1],0.),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
     700           4 :             }
     701             :           }
     702             : 
     703             :           // position the panels and the insulating material 
     704         156 :           for (j = 0; j < kNPCB3[i]; j++){
     705          60 :             index++;
     706          60 :             xx = kSensLength * (-kNPCB3[i]/2. + j + 0.5); 
     707          60 :             Float_t xx2 = xx - pcbDLength3/2.; 
     708          60 :             Float_t xx3 = xx + (kSensLength-csvPcbLength)/2.;
     709             : 
     710          60 :             Float_t zPanel = spar[2] - nomexbpar[2]; 
     711             : 
     712          60 :             if (i==0 || i==1) { // Different rotation due to new mapping convention
     713          24 :               if (i==0 && j==0) { // Rounded pcb of central slat (SR1, NR1)             
     714          10 :                 GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SC5X", idSlatCh5, 2*index-1,TGeoTranslation(-xx3,0.,zPanel),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
     715          10 :                 GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SC5X", idSlatCh5, 2*index,TGeoTranslation(-xx3,0.,-zPanel),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
     716          10 :                 GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SC5I", idSlatCh5, index,TGeoTranslation(-xx3,0.,0.),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
     717          10 :                 GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("SC6X", idSlatCh6, 2*index-1,TGeoTranslation(-xx3,0.,zPanel),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
     718          10 :                 GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("SC6X", idSlatCh6, 2*index,TGeoTranslation(-xx3,0.,-zPanel),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
     719          10 :                 GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("SC6I", idSlatCh6, index,TGeoTranslation(-xx3,0.,0.),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
     720           2 :               } 
     721             :               else {
     722          22 :                 if (i==1 && j==0){ // Rounded pcb of rounded slats (SR2. NR2)
     723          20 :                   GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SD5X", idSlatCh5, 2*index-1,TGeoTranslation(-xx,0.,zPanel),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
     724          20 :                   GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SD5X", idSlatCh5, 2*index,TGeoTranslation(-xx,0.,-zPanel),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
     725          20 :                   GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SD5I", idSlatCh5, index,TGeoTranslation(-xx,0.,0.),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
     726          20 :                   GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("SD6X", idSlatCh6, 2*index-1,TGeoTranslation(-xx,0.,zPanel),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
     727          20 :                   GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("SD6X", idSlatCh6, 2*index,TGeoTranslation(-xx,0.,-zPanel),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
     728          20 :                   GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("SD6I", idSlatCh6, index,TGeoTranslation(-xx,0.,0.),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
     729           4 :                 }
     730             :                 else {
     731          36 :                   if (j == kNPCB3[i]-1) { // 1 pcb is shortened by 5cm 
     732          48 :                     GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SB5X", idSlatCh5, 2*index-1,TGeoTranslation(-xx2,0.,zPanel),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
     733          30 :                     GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SB5X", idSlatCh5, 2*index,TGeoTranslation(-xx2,0.,-zPanel),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
     734          30 :                     GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SB5I", idSlatCh5, index,TGeoTranslation(-xx2,0.,0.),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
     735           6 :                   } 
     736             :                   else {                
     737          60 :                     GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05X", idSlatCh5, 2*index-1,TGeoTranslation(-xx,0.,zPanel),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
     738          60 :                     GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05X", idSlatCh5, 2*index,TGeoTranslation(-xx,0.,-zPanel),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
     739          60 :                     GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05I", idSlatCh5, index,TGeoTranslation(-xx,0.,0.),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
     740             :                   }
     741          90 :                   GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06X", idSlatCh6, 2*index-1,TGeoTranslation(-xx,0.,zPanel),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
     742          90 :                   GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06X", idSlatCh6, 2*index,TGeoTranslation(-xx,0.,-zPanel),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
     743          90 :                   GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06I", idSlatCh6, index,TGeoTranslation(-xx,0.,0.),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
     744             :                 }
     745             :               }
     746             :             }
     747             :             else {            
     748          52 :               if (i==2 && j == kNPCB3[i]-1) { // 1 pcb is shortened by 5cm 
     749          16 :                 GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SB5X", idSlatCh5, 2*index-1,TGeoTranslation(xx2,0.,zPanel));
     750          16 :                 GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SB5X", idSlatCh5, 2*index,TGeoTranslation(xx2,0.,-zPanel));
     751          16 :                 GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SB5I", idSlatCh5, index,TGeoTranslation(xx2,0.,0.));
     752           4 :               } else {          
     753         128 :                 GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05X", idSlatCh5, 2*index-1,TGeoTranslation(xx,0.,zPanel));
     754         128 :                 GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05X", idSlatCh5, 2*index,TGeoTranslation(xx,0.,-zPanel));
     755         128 :                 GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05I", idSlatCh5, index,TGeoTranslation(xx,0.,0.));
     756             :               }
     757         144 :               GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06X", idSlatCh6, 2*index-1,TGeoTranslation(xx,0.,zPanel));
     758         144 :               GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06X", idSlatCh6, 2*index,TGeoTranslation(xx,0.,-zPanel));
     759         144 :               GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06I", idSlatCh6, index,TGeoTranslation(xx,0.,0.));                     
     760             :             }
     761             :           }
     762          18 :         }
     763             :       }
     764             : 
     765             :       
     766             :       // position the nomex volume inside the panel volume
     767           1 :       TVirtualMC::GetMC()->Gspos("S05N",1,"S05C",0.,0.,0.,0,"ONLY"); 
     768           1 :       TVirtualMC::GetMC()->Gspos("SB5N",1,"SB5C",0.,0.,0.,0,"ONLY"); 
     769           1 :       TVirtualMC::GetMC()->Gspos("SC5N",1,"SC5C",0.,0.,0.,0,"ONLY"); 
     770           1 :       TVirtualMC::GetMC()->Gspos("SD5N",1,"SD5C",0.,0.,0.,0,"ONLY"); 
     771           1 :       TVirtualMC::GetMC()->Gspos("S06N",1,"S06C",0.,0.,0.,0,"ONLY"); 
     772           1 :       TVirtualMC::GetMC()->Gspos("SC6N",1,"SC6C",0.,0.,0.,0,"ONLY"); 
     773           1 :       TVirtualMC::GetMC()->Gspos("SD6N",1,"SD6C",0.,0.,0.,0,"ONLY"); 
     774             :   
     775             :       // position panel volume inside the bulk nomex material volume
     776           1 :       TVirtualMC::GetMC()->Gspos("S05C",1,"S05X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
     777           1 :       TVirtualMC::GetMC()->Gspos("SB5C",1,"SB5X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
     778           1 :       TVirtualMC::GetMC()->Gspos("SC5C",1,"SC5X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
     779           1 :       TVirtualMC::GetMC()->Gspos("SD5C",1,"SD5X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
     780           1 :       TVirtualMC::GetMC()->Gspos("S06C",1,"S06X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
     781           1 :       TVirtualMC::GetMC()->Gspos("SC6C",1,"SC6X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
     782           1 :       TVirtualMC::GetMC()->Gspos("SD6C",1,"SD6X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
     783             : 
     784             :       // position the PCB volume inside the insulating material volume
     785           1 :       TVirtualMC::GetMC()->Gspos("S05P",1,"S05I",0.,0.,0.,0,"ONLY"); 
     786           1 :       TVirtualMC::GetMC()->Gspos("SB5P",1,"SB5I",0.,0.,0.,0,"ONLY"); 
     787           1 :       TVirtualMC::GetMC()->Gspos("SC5P",1,"SC5I",0.,0.,0.,0,"ONLY"); 
     788           1 :       TVirtualMC::GetMC()->Gspos("SD5P",1,"SD5I",0.,0.,0.,0,"ONLY"); 
     789           1 :       TVirtualMC::GetMC()->Gspos("S06P",1,"S06I",0.,0.,0.,0,"ONLY"); 
     790           1 :       TVirtualMC::GetMC()->Gspos("SC6P",1,"SC6I",0.,0.,0.,0,"ONLY"); 
     791           1 :       TVirtualMC::GetMC()->Gspos("SD6P",1,"SD6I",0.,0.,0.,0,"ONLY"); 
     792             :   
     793             :       // position the horizontal frame volume inside the PCB volume
     794           1 :       TVirtualMC::GetMC()->Gspos("S05H",1,"S05P",0.,0.,0.,0,"ONLY"); 
     795           1 :       TVirtualMC::GetMC()->Gspos("SB5H",1,"SB5P",0.,0.,0.,0,"ONLY"); 
     796           1 :       TVirtualMC::GetMC()->Gspos("SC5H",1,"SC5P",0.,0.,0.,0,"ONLY"); 
     797           1 :       TVirtualMC::GetMC()->Gspos("SD5H",1,"SD5P",0.,0.,0.,0,"ONLY"); 
     798           1 :       TVirtualMC::GetMC()->Gspos("S06H",1,"S06P",0.,0.,0.,0,"ONLY"); 
     799           1 :       TVirtualMC::GetMC()->Gspos("SC6H",1,"SC6P",0.,0.,0.,0,"ONLY"); 
     800           1 :       TVirtualMC::GetMC()->Gspos("SD6H",1,"SD6P",0.,0.,0.,0,"ONLY"); 
     801             :   
     802             :       // position the sensitive volume inside the horizontal frame volume
     803           1 :       TVirtualMC::GetMC()->Gsposp("S05G",1,"S05H",0.,0.,0.,0,"ONLY",senspar,3); 
     804           1 :       TVirtualMC::GetMC()->Gsposp("S05G",1,"SB5H",0.,0.,0.,0,"ONLY",senspar2,3); 
     805           1 :       TVirtualMC::GetMC()->Gspos("SC5G",1,"SC5H",0.,0.,0.,0,"ONLY"); 
     806           1 :       TVirtualMC::GetMC()->Gspos("SD5G",1,"SD5H",0.,0.,0.,0,"ONLY"); 
     807           1 :       TVirtualMC::GetMC()->Gsposp("S06G",1,"S06H",0.,0.,0.,0,"ONLY",senspar,3); 
     808           1 :       TVirtualMC::GetMC()->Gspos("SC6G",1,"SC6H",0.,0.,0.,0,"ONLY"); 
     809           1 :       TVirtualMC::GetMC()->Gspos("SD6G",1,"SD6H",0.,0.,0.,0,"ONLY"); 
     810             :   
     811             :  
     812             :       // position the border volumes inside the PCB volume
     813             :       Float_t yborder = ( kPcbHeight - kBframeHeight ) / 2.; 
     814           1 :       Int_t rotB = 0;
     815           1 :       TVirtualMC::GetMC()->Matrix(rotB,90,0,90,270,180,0); // rotation around x for second border
     816             : 
     817           1 :       TVirtualMC::GetMC()->Gspos("S05B",1,"S05P",0., yborder,0.,0,"ONLY"); 
     818           1 :       TVirtualMC::GetMC()->Gspos("S05B",2,"S05P",0.,-yborder,0.,0,"ONLY"); 
     819           1 :       TVirtualMC::GetMC()->Gspos("SB5B",1,"SB5P",0., yborder,0.,0,"ONLY"); 
     820           1 :       TVirtualMC::GetMC()->Gspos("SB5B",2,"SB5P",0.,-yborder,0.,0,"ONLY"); 
     821           1 :       TVirtualMC::GetMC()->Gspos("SC5B",1,"SC5P",0., yborder,0.,rotB,"ONLY"); 
     822           1 :       TVirtualMC::GetMC()->Gspos("SC5B",2,"SC5P",0.,-yborder,0.,0,"ONLY"); 
     823           1 :       TVirtualMC::GetMC()->Gspos("S05B",1,"SD5P",0., yborder,0.,0,"ONLY"); 
     824           1 :       TVirtualMC::GetMC()->Gspos("SD5B",1,"SD5P",0.,-yborder,0.,0,"ONLY"); 
     825             : 
     826           1 :       TVirtualMC::GetMC()->Gspos("S06B",1,"S06P",0., yborder,0.,0,"ONLY"); 
     827           1 :       TVirtualMC::GetMC()->Gspos("S06B",2,"S06P",0.,-yborder,0.,0,"ONLY"); 
     828           1 :       TVirtualMC::GetMC()->Gspos("SC6B",1,"SC6P",0., yborder,0.,rotB,"ONLY"); 
     829           1 :       TVirtualMC::GetMC()->Gspos("SC6B",2,"SC6P",0.,-yborder,0.,0,"ONLY"); 
     830           1 :       TVirtualMC::GetMC()->Gspos("S06B",1,"SD6P",0., yborder,0.,0,"ONLY"); 
     831           1 :       TVirtualMC::GetMC()->Gspos("SD6B",1,"SD6P",0.,-yborder,0.,0,"ONLY"); 
     832             :   
     833             :       // create the NULOC volume and position it in the horizontal frame
     834           1 :       TVirtualMC::GetMC()->Gsvolu("S05E","BOX",kNulocMaterial,nulocpar,3);
     835           1 :       TVirtualMC::GetMC()->Gsvolu("S06E","BOX",kNulocMaterial,nulocpar,3);
     836             :       index = 0;
     837           1 :       Float_t xxmax2 = xxmax - pcbDLength3/2.;
     838           1 :       Float_t xxmax3 = xxmax - (kPcbLength-csvPcbLength)/2.;
     839           1 :       Float_t rPhi3 = TMath::ASin((kYpos3[1]-kPcbHeight/2.)/AliMUONConstants::Rmin(2));
     840           1 :       Float_t xxmax4 = (AliMUONConstants::Rmin(2)*TMath::Cos(rPhi3)-kVframeLength/2.) - (kBframeLength - kNulocLength)/2.;
     841          18 :       for (xx = -xxmax; xx <= xxmax; xx += 2*kNulocLength) { 
     842           8 :         index++; 
     843           8 :         TVirtualMC::GetMC()->Gspos("S05E",2*index-1,"S05B", xx, 0.,-kBframeWidth/2. + kNulocWidth/2, 0, "ONLY");
     844           8 :         TVirtualMC::GetMC()->Gspos("S05E",2*index  ,"S05B", xx, 0., kBframeWidth/2. - kNulocWidth/2, 0, "ONLY");
     845           8 :         TVirtualMC::GetMC()->Gspos("S06E",2*index-1,"S06B", xx, 0.,-kBframeWidth/2. + kNulocWidth/2, 0, "ONLY");
     846           8 :         TVirtualMC::GetMC()->Gspos("S06E",2*index  ,"S06B", xx, 0., kBframeWidth/2.-  kNulocWidth/2, 0, "ONLY");
     847          15 :         if (xx > -xxmax2 && xx< xxmax2) {
     848           6 :           TVirtualMC::GetMC()->Gspos("S05E",2*index-1,"SB5B", xx, 0.,-kBframeWidth/2.+ kNulocWidth/2, 0, "ONLY");
     849           6 :           TVirtualMC::GetMC()->Gspos("S05E",2*index  ,"SB5B", xx, 0., kBframeWidth/2.- kNulocWidth/2, 0, "ONLY");
     850           6 :         }
     851          13 :         if (xx > -xxmax3 && xx< xxmax3) {
     852           3 :           TVirtualMC::GetMC()->Gspos("S05E",2*index-1,"SC5B", xx, 0.,-kBframeWidth/2.+ kNulocWidth/2., 0, "ONLY");
     853           3 :           TVirtualMC::GetMC()->Gspos("S05E",2*index  ,"SC5B", xx, 0., kBframeWidth/2.- kNulocWidth/2., 0, "ONLY");
     854           3 :           TVirtualMC::GetMC()->Gspos("S06E",2*index-1,"SC6B", xx, 0.,-kBframeWidth/2.+ kNulocWidth/2, 0, "ONLY");
     855           3 :           TVirtualMC::GetMC()->Gspos("S06E",2*index  ,"SC6B", xx, 0., kBframeWidth/2.- kNulocWidth/2, 0, "ONLY");
     856           3 :         }
     857          10 :         if (xx > xxmax4 && xx< xxmax) {
     858           2 :           TVirtualMC::GetMC()->Gspos("S05E",2*index-1,"SD5B", xx, 0.,-kBframeWidth/2.+ kNulocWidth/2, 0, "ONLY");
     859           2 :           TVirtualMC::GetMC()->Gspos("S05E",2*index  ,"SD5B", xx, 0., kBframeWidth/2.- kNulocWidth/2, 0, "ONLY");
     860           2 :           TVirtualMC::GetMC()->Gspos("S06E",2*index-1,"SD6B", xx, 0.,-kBframeWidth/2.+ kNulocWidth/2, 0, "ONLY");
     861           2 :           TVirtualMC::GetMC()->Gspos("S06E",2*index  ,"SD6B", xx, 0., kBframeWidth/2.- kNulocWidth/2, 0, "ONLY");
     862           2 :         }
     863             :       }      
     864             :       
     865             :       //
     866             :       //Geometry of the support pannel Verticla length 3.62m, horizontal length 1.62m, internal radius  dMotherInner of SC05 and SC06  (F. Orsini, Saclay)
     867             :       //Carbon fiber of 0.3 mm thick (2 layers) and a central layer of Nomex of 15mm thick. 
     868             :       // Outer excess and inner recess for mother volume radius
     869             :       // with respect to ROuter and RInner
     870           1 :       Float_t dMotherInner = AliMUONConstants::Rmin(2)-kRframeHeight; 
     871             :       Float_t nomexthickness = 1.5;
     872             :       Float_t carbonthickness = 0.03;
     873             :       Float_t supporthlength =  162.;  //    chamber 5 
     874             :       Float_t supporthlengthCh6 =  167.;  // chamber 6 
     875             :       Float_t supportvlength =  362.; 
     876             : 
     877             :       // Generating the composite shape of the carbon and nomex pannels
     878           1 :       new TGeoBBox("shNomexBoxSt3",supporthlength/2., supportvlength/2. ,nomexthickness/2.+carbonthickness+3*kCableWidth);
     879           1 :       new TGeoBBox("shCarbonBoxSt3",supporthlength/2., supportvlength/2. ,carbonthickness/2.); 
     880           1 :       new TGeoBBox("shNomexBoxSt3Ch6",(supporthlengthCh6)/2., supportvlength/2. ,nomexthickness/2.+carbonthickness+3*kCableWidth);
     881           1 :       new TGeoBBox("shCarbonBoxSt3Ch6",(supporthlengthCh6)/2., supportvlength/2. ,carbonthickness/2.); 
     882           1 :       new TGeoTubeSeg("shNomexHoleSt3",0., dMotherInner, nomexthickness/2.+carbonthickness+3*kCableWidth+0.001, -90. ,90.);
     883           1 :       new TGeoTubeSeg("shCarbonHoleSt3",0., dMotherInner, carbonthickness/2.+0.001, -90. ,90.);
     884           1 :       TGeoTranslation* trHoleSt3 = new TGeoTranslation("trHoleSt3",-supporthlength/2.,0.,0.); 
     885           1 :       trHoleSt3->RegisterYourself();
     886           1 :       TGeoTranslation* trHoleSt3Ch6 = new TGeoTranslation("trHoleSt3Ch6",-(supporthlengthCh6)/2.,0.,0.); 
     887           1 :       trHoleSt3Ch6->RegisterYourself();
     888           1 :       TGeoCompositeShape* shNomexSupportSt3  = new TGeoCompositeShape("shNomexSupportSt3","shNomexBoxSt3-shNomexHoleSt3:trHoleSt3");
     889           1 :       TGeoCompositeShape* shCarbonSupportSt3 = new TGeoCompositeShape("shCarbonSupportSt3","shCarbonBoxSt3-shCarbonHoleSt3:trHoleSt3");
     890           1 :       TGeoCompositeShape* shNomexSupportSt3Ch6  = new TGeoCompositeShape("shNomexSupportSt3Ch6","shNomexBoxSt3Ch6-shNomexHoleSt3:trHoleSt3Ch6");
     891           1 :       TGeoCompositeShape* shCarbonSupportSt3Ch6 = new TGeoCompositeShape("shCarbonSupportSt3Ch6","shCarbonBoxSt3Ch6-shCarbonHoleSt3:trHoleSt3Ch6");
     892             : 
     893             :       // Generating Nomex and Carbon pannel volumes
     894           1 :       TGeoVolume * voNomexSupportSt3  = new TGeoVolume("S05S", shNomexSupportSt3, kMedNomex);
     895           1 :       TGeoVolume * voCarbonSupportSt3 = new TGeoVolume("S05K", shCarbonSupportSt3, kMedCarbon);
     896           1 :       TGeoVolume * voNomexSupportSt3Ch6  = new TGeoVolume("S06S", shNomexSupportSt3Ch6, kMedNomex);
     897           1 :       TGeoVolume * voCarbonSupportSt3Ch6 = new TGeoVolume("S06K", shCarbonSupportSt3Ch6, kMedCarbon);
     898             : 
     899           1 :       TGeoTranslation *trCarbon1St3   = new TGeoTranslation("trCarbon1St3",0.,0., -(nomexthickness+carbonthickness)/2.);
     900           1 :       TGeoTranslation *trCarbon2St3   = new TGeoTranslation("trCarbon2St3",0.,0.,  (nomexthickness+carbonthickness)/2.);
     901           1 :       voNomexSupportSt3->AddNode(voCarbonSupportSt3,1,trCarbon1St3);
     902           1 :       voNomexSupportSt3->AddNode(voCarbonSupportSt3,2,trCarbon2St3);
     903           1 :       voNomexSupportSt3Ch6->AddNode(voCarbonSupportSt3Ch6,1,trCarbon1St3);
     904           1 :       voNomexSupportSt3Ch6->AddNode(voCarbonSupportSt3Ch6,2,trCarbon2St3);
     905             : 
     906             : 
     907             :       // Add readout cables
     908           1 :       TVirtualMC::GetMC()->Gsvolu("S05L","BOX",kCableMaterial,dum,0);
     909           1 :       TVirtualMC::GetMC()->Gsvolu("S06L","BOX",kCableMaterial,dum,0);
     910             : 
     911             :       ySlat3 = 0.;
     912             :       Float_t lCableX = 0.;
     913             :       Float_t lCableX6 = 0.;
     914             :       Float_t lCableY = 0.;
     915             :       Float_t lCableZ = 0.;
     916           1 :       Float_t cablepar[3] = {static_cast<Float_t>(supporthlength/2.), static_cast<Float_t>(kCableHeight/2.), static_cast<Float_t>(kCableWidth/2.)};
     917           1 :       Float_t cablepar6[3] = {static_cast<Float_t>(supporthlengthCh6/2.), static_cast<Float_t>(kCableHeight/2.), static_cast<Float_t>(kCableWidth/2.)};
     918             :       Float_t lCableDY = 0.;
     919             :       Int_t cIndex = 0;
     920             :       Int_t cIndex6 = 0;
     921          12 :       for (i = 0; i<kNslats3; i++){
     922             :         Int_t iCable = 1;
     923             :         cIndex = 0;
     924             :         cIndex6 = 0;
     925           5 :         ySlat3 += kYpos3[i];
     926             :         lCableY = ySlat3;
     927             : 
     928             :         // Cables going out from the start of slat
     929           5 :         if(kNPCB3[i]>=4 && i<kNslats3-2){ // Only if 4 or more pcb
     930             :           // First top cables
     931           3 :           cablepar[0] = supporthlength/2.;
     932             :           lCableX = 0.;
     933           3 :           cablepar6[0] = supporthlengthCh6/2.;
     934             :           lCableX6 = 0.;
     935           3 :           lCableDY = (kYpos3[i+1]+kYpos3[i+2])/2.-cablepar[1]; // half way between 2 slats on same side
     936           3 :           lCableZ = TMath::Power(-1,i)*(nomexthickness/2.+carbonthickness+(-1+iCable++)*kCableWidth+kCableWidth/2.);
     937           3 :           if(i==0){ // central slat is shorter (rounded)
     938           1 :             cablepar[0] -= (kPcbLength-csvPcbLength)/2.;
     939           1 :             lCableX = (kPcbLength-csvPcbLength)/2.;
     940           1 :             cablepar6[0] -= (kPcbLength-csvPcbLength)/2.;
     941             :             lCableX6 = (kPcbLength-csvPcbLength)/2.;
     942           1 :           }
     943           3 :           TVirtualMC::GetMC()->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar,3);      
     944           3 :           TVirtualMC::GetMC()->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar,3);
     945           3 :           TVirtualMC::GetMC()->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar6,3);   
     946           3 :           TVirtualMC::GetMC()->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar6,3);
     947             : 
     948             :           // Then bottom cables
     949           3 :           if(i>0){
     950           2 :             if(i==1){ // Rounded slat. Bottom cable starts at dMotherInner (beam pipe)
     951           1 :               cablepar[0] -= dMotherInner/2.;
     952           1 :               lCableX += dMotherInner/2.;
     953           1 :               cablepar6[0] -= dMotherInner/2.;
     954           1 :               lCableX6 += dMotherInner/2.;
     955           1 :               lCableDY = (kYpos3[i]+kYpos3[i])/2.-cablepar[1];
     956           1 :             }
     957           2 :             if(i>=2){ 
     958           1 :               lCableDY = (kYpos3[i]+kYpos3[i-1])/2.-cablepar[1]; // half way between 2 slats on same side
     959           1 :               if ((lCableY-lCableDY)<(dMotherInner+cablepar[1])){
     960           0 :                 lCableDY = lCableY - dMotherInner - cablepar[1];
     961           0 :               }
     962             :             }
     963           2 :             TVirtualMC::GetMC()->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,lCableY-lCableDY,lCableZ,0,"ONLY",cablepar,3); 
     964           2 :             TVirtualMC::GetMC()->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,-(lCableY-lCableDY),lCableZ,0,"ONLY",cablepar,3); 
     965           2 :             TVirtualMC::GetMC()->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,lCableY-lCableDY,lCableZ,0,"ONLY",cablepar6,3); 
     966           2 :             TVirtualMC::GetMC()->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,-(lCableY-lCableDY),lCableZ,0,"ONLY",cablepar6,3); 
     967           2 :           }
     968             :         }
     969             :         
     970             :         // Rounded slats have an extra cable starting at second pcb
     971           5 :         if(i==1){ 
     972             :           // First top cables
     973           1 :           cablepar[0] = (supporthlength-kPcbLength-kVframeLength)/2.;
     974             :           lCableX = (kPcbLength+kVframeLength)/2.;
     975           1 :           cablepar6[0] = (supporthlengthCh6-kPcbLength-kVframeLength)/2.;
     976             :           lCableX6 = (kPcbLength+kVframeLength)/2.;
     977           1 :           lCableDY = (kYpos3[i+1]+kYpos3[i+2])/2.-cablepar[1]; // half way between 2 slats on same side
     978           1 :           lCableZ = TMath::Power(-1,i)*(nomexthickness/2.+carbonthickness+(-1+iCable++)*kCableWidth+kCableWidth/2.);
     979           1 :           TVirtualMC::GetMC()->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar,3);      
     980           1 :           TVirtualMC::GetMC()->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar,3);
     981           1 :           TVirtualMC::GetMC()->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar6,3);   
     982           1 :           TVirtualMC::GetMC()->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar6,3);
     983             :           // Then bottom cables
     984           1 :           lCableDY = (kYpos3[i]+kYpos3[i])/2.-cablepar[1];
     985           1 :           TVirtualMC::GetMC()->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,lCableY-lCableDY,lCableZ,0,"ONLY",cablepar,3); 
     986           1 :           TVirtualMC::GetMC()->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,-(lCableY-lCableDY),lCableZ,0,"ONLY",cablepar,3); 
     987           1 :           TVirtualMC::GetMC()->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,lCableY-lCableDY,lCableZ,0,"ONLY",cablepar6,3); 
     988           1 :           TVirtualMC::GetMC()->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,-(lCableY-lCableDY),lCableZ,0,"ONLY",cablepar6,3); 
     989           1 :         }
     990             :         
     991             :         // Cables going out from the end of the slats
     992             :         // First top cables
     993           5 :         cablepar[0] = (supporthlength-(slatLength3[i]+kDslatLength)+kVframeLength)/2.;
     994           5 :         lCableX = slatLength3[i]-kVframeLength+kDslatLength+cablepar[0]-supporthlength/2.;
     995           5 :         cablepar6[0] = (supporthlengthCh6-(slatLength3[i]+kDslatLength)+kVframeLength)/2.;
     996           5 :         lCableX6 = slatLength3[i]-kVframeLength+kDslatLength+cablepar6[0]-supporthlengthCh6/2.;
     997           9 :         if(i+1>=kNslats3 || i+2>=kNslats3){ // If no more higher slats, then use distance to lower slat
     998           2 :           lCableDY = kPcbHeight/2.+cablepar[1];
     999           2 :         }
    1000             :         else {
    1001           3 :           lCableDY = (kYpos3[i+1]+kYpos3[i+2])/2.-cablepar[1];
    1002             :         }
    1003           5 :         lCableZ = TMath::Power(-1,i)*(nomexthickness/2.+carbonthickness+(-1+iCable++)*kCableWidth+kCableWidth/2.);
    1004             : 
    1005           5 :         if (i<=2){ // shortened pcb
    1006           3 :           cablepar[0] += pcbDLength3/2.;
    1007           3 :           lCableX -=  pcbDLength3/2.;
    1008           3 :         } 
    1009           5 :         TVirtualMC::GetMC()->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar,3); 
    1010           5 :         TVirtualMC::GetMC()->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar,3); 
    1011           5 :         TVirtualMC::GetMC()->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar6,3); 
    1012           5 :         TVirtualMC::GetMC()->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar6,3); 
    1013             :         // Then bottom cables
    1014           5 :         if(i>0){ // Loop is over top half of slats, lower half are symmetric 
    1015           4 :           if (i==1) {
    1016           5 :             lCableDY = (kYpos3[i]+kYpos3[i])/2.-cablepar[1];
    1017           1 :           }
    1018             :           else{
    1019           3 :             lCableDY = (kYpos3[i]+kYpos3[i-1])/2.-cablepar[1]; // half way between 2 slats on same side
    1020             :           }
    1021           4 :           TVirtualMC::GetMC()->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,lCableY-lCableDY,lCableZ,0,"ONLY",cablepar,3); 
    1022           4 :           TVirtualMC::GetMC()->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,-(lCableY-lCableDY),lCableZ,0,"ONLY",cablepar,3); 
    1023           4 :           TVirtualMC::GetMC()->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,lCableY-lCableDY,lCableZ,0,"ONLY",cablepar6,3); 
    1024           4 :           TVirtualMC::GetMC()->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,-(lCableY-lCableDY),lCableZ,0,"ONLY",cablepar6,3); 
    1025           4 :         }
    1026             :       }
    1027             : 
    1028             :       Float_t dzCh5  = dzCh;
    1029           1 :       TGeoTranslation* trSupport1St3   = new TGeoTranslation("trSupport1St3", supporthlength/2., 0. , dzCh5);
    1030           1 :       TGeoRotation*    roSupportSt3    = new TGeoRotation("roSupportSt3",90.,180.,-90.);
    1031           1 :       TGeoCombiTrans*  coSupport2St3   = new TGeoCombiTrans(-supporthlength/2., 0., -dzCh5, roSupportSt3);       
    1032           1 :       TGeoTranslation* trSupport1St3Ch6   = new TGeoTranslation("trSupport1St3Ch6", supporthlengthCh6/2., 0. , dzCh5);
    1033           1 :       TGeoCombiTrans*  coSupport2St3Ch6   = new TGeoCombiTrans(-supporthlengthCh6/2., 0., -dzCh5, roSupportSt3);       
    1034           2 :       GetEnvelopes(5)->AddEnvelope("S05S", 0, 1, *trSupport1St3);  
    1035           2 :       GetEnvelopes(4)->AddEnvelope("S05S", 0, 2, *coSupport2St3);  
    1036           2 :       GetEnvelopes(7)->AddEnvelope("S06S", 0, 1, *trSupport1St3Ch6);   
    1037           2 :       GetEnvelopes(6)->AddEnvelope("S06S", 0, 2, *coSupport2St3Ch6);  
    1038             :       // End of pannel support geometry          
    1039             : 
    1040             :       // cout << "Geometry for Station 3...... done" << endl;     
    1041           1 :     }
    1042           1 :   if (fStations[3]) {
    1043             : 
    1044             : 
    1045             :     // //********************************************************************
    1046             :     // //                            Station 4                             **
    1047             :     // //********************************************************************
    1048             :     // Mother volume for each chamber in St4 is an envelop (or assembly)
    1049             :     // There is one assembly mother per half a chamber  called SC07I, SC07O, SC08I and SC08O
    1050             :     // Same volume name definitions as in St3
    1051             :     const Int_t   kNslats4          = 7;  // number of slats per quadrant
    1052             :     const Int_t   kNPCB4[kNslats4]  = {5, 6, 5, 5, 4, 3, 2}; // n PCB per slat
    1053             :     const Float_t kXpos4[kNslats4]  = {38.75, 0., 0., 0., 0., 0., 0.}; // J.C. Correct value
    1054             :     const Float_t kYpos41[kNslats4] = {0., 38.2, 34.40, 36.60, 29.3, 37.0, 28.6};
    1055             :     const Float_t kYpos42[kNslats4] = {0., 38.2, 37.85, 37.55, 29.4, 37.0, 28.6};
    1056           1 :     Float_t slatLength4[kNslats4];     
    1057             : 
    1058           1 :     Float_t rPhi1 = TMath::RadToDeg()*(TMath::ASin((kYpos41[1]-hFramepar[1])/(AliMUONConstants::Rmin(3))));
    1059           1 :     Float_t rPhi2 = TMath::RadToDeg()*(TMath::ACos(-vFramepar[0]/(AliMUONConstants::Rmin(3)-kRframeLength)));
    1060           1 :     Float_t rFramepar4[5] = { AliMUONConstants::Rmin(3)-kRframeLength, AliMUONConstants::Rmin(3), kRframeWidth, rPhi1, rPhi2}; 
    1061           1 :     Float_t vrFrameHeight = hFramepar[1]+kYpos41[1]-AliMUONConstants::Rmin(3)+kRframeLength;
    1062             :     
    1063           1 :     char idSlatCh7[6];
    1064           1 :     char idSlatCh8[6];
    1065             :     Float_t xSlat4;
    1066             :     Float_t ySlat41 = 0;
    1067             :     Float_t ySlat42 = 0;
    1068             :     angle = 0.;
    1069             : 
    1070          16 :     for (i = 0; i<kNslats4; i++){
    1071           7 :       slatLength4[i] = kPcbLength * kNPCB4[i] + 2. * kVframeLength; 
    1072           7 :       xSlat4 = slatLength4[i]/2. + kDslatLength + kXpos4[i]; 
    1073           7 :       ySlat41 += kYpos41[i];
    1074           7 :       ySlat42 += kYpos42[i];
    1075             : 
    1076             :       spar[0] = slatLength4[i]/2.; 
    1077             :       spar[1] = kSlatHeight/2.;
    1078           7 :       spar[2] = kSlatWidth/2.; 
    1079             :       Float_t dzCh4 = dzCh;
    1080           7 :       Float_t zSlat4 = (i%2 ==0)? -zSlat : zSlat; 
    1081             : 
    1082           7 :       sprintf(idSlatCh7,"SLC%d",kNslats4-1+i);
    1083           7 :       detElemId = 713 - (i + kNslats4-1-6);
    1084           7 :       moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
    1085           7 :       if (detElemId % 2 == 0) {
    1086           6 :         if (detElemId == 712) // Round slat, new rotation due to mapping convention
    1087           6 :           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(xSlat4, ySlat41, -zSlat4 + dzCh4),
    1088           1 :                                               TGeoRotation("rot1",90,180+angle,90,90+angle,180,0) );
    1089             :         else
    1090           6 :           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(xSlat4, ySlat41, -zSlat4 + dzCh4),
    1091           2 :                                               TGeoRotation("rot1",90,angle,90,90+angle,0,0) );
    1092             :       }
    1093             :       else
    1094          12 :           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(xSlat4, ySlat41, -zSlat4 + dzCh4),
    1095           4 :                                    TGeoRotation("rot1",90,angle,90,270+angle,180,0) );
    1096             : 
    1097           7 :       sprintf(idSlatCh7,"SLC%d",3*kNslats4-2+i);
    1098           7 :       detElemId = 700 + (i + kNslats4-1-6);
    1099           7 :       moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
    1100           7 :       if (detElemId % 2 == 1) {
    1101           6 :         if (detElemId == 701) // Round slat, new rotation due to mapping convention
    1102           6 :           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(-xSlat4, ySlat41, zSlat4 - dzCh4),
    1103           1 :                                               TGeoRotation("rot2",90,angle,90,90+angle,0,0) );
    1104             :         else
    1105           6 :           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(-xSlat4, ySlat41, zSlat4 - dzCh4),
    1106           2 :                                               TGeoRotation("rot2",90,180+angle,90,90+angle,180,0) );
    1107             :       }
    1108             :       else
    1109          12 :         GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(-xSlat4, ySlat41, zSlat4 - dzCh4),
    1110           4 :                                             TGeoRotation("rot2",90,180+angle,90,270+angle,0,0) );
    1111             : 
    1112           7 :       if (i > 0) { 
    1113           6 :         sprintf(idSlatCh7,"SLC%d",kNslats4-1-i);
    1114           6 :         detElemId = 713 + (i + kNslats4-1-6);
    1115           6 :         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
    1116           6 :         if (detElemId % 2 == 0) {
    1117           6 :           if (detElemId == 714) // Round slat, new rotation due to mapping convention
    1118           6 :             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(xSlat4, -ySlat41, -zSlat4 + dzCh4),
    1119           1 :                                                 TGeoRotation("rot3",90,180+angle,90,270+angle,0,0) );
    1120             :           else
    1121           6 :             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(xSlat4, -ySlat41, -zSlat4 + dzCh4),
    1122           2 :                                                 TGeoRotation("rot3",90,angle,90,90+angle,0,0) );
    1123             :         }
    1124             :         else
    1125           9 :             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(xSlat4, -ySlat41, -zSlat4 + dzCh4),
    1126           3 :                                                 TGeoRotation("rot3",90,angle,90,270+angle,180,0) );
    1127             : 
    1128           6 :         sprintf(idSlatCh7,"SLC%d",3*kNslats4-2-i);
    1129           6 :         detElemId = 726 - (i + kNslats4-1-6);
    1130           6 :         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
    1131           6 :         if (detElemId % 2 == 1) {
    1132           6 :           if (detElemId == 725) // Round slat, new rotation due to mapping convention
    1133           6 :             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(-xSlat4, -ySlat41, zSlat4 - dzCh4),
    1134           1 :                                                 TGeoRotation("rot4",90,angle,90,270+angle,180,0) );
    1135             :           else
    1136           6 :             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(-xSlat4, -ySlat41, zSlat4 - dzCh4),
    1137           2 :                                                 TGeoRotation("rot4",90,180+angle,90,90+angle,180,0) );
    1138             :         }
    1139             :         else
    1140           9 :           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(-xSlat4, -ySlat41, zSlat4 - dzCh4),
    1141           3 :                                               TGeoRotation("rot4",90,180+angle,90,270+angle,0,0) ); 
    1142             :       }
    1143             : 
    1144           7 :       sprintf(idSlatCh8,"SLD%d",kNslats4-1+i);
    1145           7 :       detElemId = 813 - (i + kNslats4-1-6);
    1146           7 :       moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
    1147           7 :       if (detElemId % 2 == 0) {
    1148           6 :         if (detElemId == 812) // Round slat, new rotation due to mapping convention
    1149           6 :           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(xSlat4, ySlat42, -zSlat4 + dzCh4),
    1150           1 :                                               TGeoRotation("rot5",90,180+angle,90,90+angle,180,0) );
    1151             :         else
    1152           6 :           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(xSlat4, ySlat42, -zSlat4 + dzCh4),
    1153           2 :                                               TGeoRotation("rot5",90,angle,90,90+angle,0,0) );
    1154             :       }
    1155             :       else
    1156          12 :         GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(xSlat4, ySlat42, -zSlat4 + dzCh4),
    1157           4 :                                             TGeoRotation("rot5",90,angle,90,270+angle,180,0) ); 
    1158             : 
    1159           7 :       sprintf(idSlatCh8,"SLD%d",3*kNslats4-2+i);
    1160           7 :       detElemId = 800 + (i + kNslats4-1-6);
    1161           7 :       moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
    1162           7 :       if (detElemId % 2 == 1) {
    1163           6 :         if (detElemId == 801) // Round slat, new rotation due to mapping convention
    1164           6 :           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(-xSlat4, ySlat42, zSlat4 - dzCh4),
    1165           1 :                                               TGeoRotation("rot6",90,angle,90,90+angle,0,0) );
    1166             :         else
    1167           6 :           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(-xSlat4, ySlat42, zSlat4 - dzCh4),
    1168           2 :                                               TGeoRotation("rot6",90,180+angle,90,90+angle,180,0) );
    1169             :       }
    1170             :       else
    1171          12 :         GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(-xSlat4, ySlat42, zSlat4 - dzCh4),
    1172           4 :                                             TGeoRotation("rot6",90,180+angle,90,270+angle,0,0) );
    1173           7 :       if (i > 0) { 
    1174           6 :         sprintf(idSlatCh8,"SLD%d",kNslats4-1-i);
    1175           6 :         detElemId = 813 + (i + kNslats4-1-6);
    1176           6 :         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
    1177           6 :         if (detElemId % 2 == 0) {
    1178           6 :           if (detElemId == 814) // Round slat, new rotation due to mapping convention
    1179           6 :             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(xSlat4, -ySlat42, -zSlat4 + dzCh4),
    1180           1 :                                                 TGeoRotation("rot7",90,180+angle,90,270+angle,0,0) );
    1181             :           else
    1182           6 :             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(xSlat4, -ySlat42, -zSlat4 + dzCh4),
    1183           2 :                                                 TGeoRotation("rot7",90,angle,90,90+angle,0,0) );
    1184             :         }
    1185             :         else
    1186           9 :           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(xSlat4, -ySlat42, -zSlat4 + dzCh4),
    1187           3 :                                               TGeoRotation("rot7",90,angle,90,270+angle,180,0) );
    1188             : 
    1189           6 :         sprintf(idSlatCh8,"SLD%d",3*kNslats4-2-i);
    1190           6 :         detElemId = 826 - (i + kNslats4-1-6);
    1191           6 :         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
    1192           6 :         if (detElemId % 2 == 1) {
    1193           6 :           if (detElemId == 825 ) // Round slat, new rotation due to mapping convention
    1194           6 :             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(-xSlat4, -ySlat42, zSlat4 - dzCh4),
    1195           1 :                                                 TGeoRotation("rot8",90,angle,90,270+angle,180,0) ); 
    1196             :           else
    1197           6 :             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(-xSlat4, -ySlat42, zSlat4 - dzCh4),
    1198           2 :                                                 TGeoRotation("rot8",90,180+angle,90,90+angle,180,0) ); 
    1199             :         }
    1200             :         else
    1201           9 :           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(-xSlat4, -ySlat42, zSlat4 - dzCh4),
    1202           3 :                                               TGeoRotation("rot8",90,180+angle,90,270+angle,0,0) );
    1203             :        
    1204             :       }
    1205             :     }
    1206             :      
    1207             :     // create the panel volume 
    1208             :  
    1209           1 :     TVirtualMC::GetMC()->Gsvolu("S07C","BOX",kCarbonMaterial,panelpar,3);
    1210           1 :     TVirtualMC::GetMC()->Gsvolu("SD7C","BOX",kCarbonMaterial,panelpar,3);
    1211           1 :     TVirtualMC::GetMC()->Gsvolu("S08C","BOX",kCarbonMaterial,panelpar,3);
    1212           1 :     TVirtualMC::GetMC()->Gsvolu("SD8C","BOX",kCarbonMaterial,panelpar,3);
    1213             : 
    1214             :     // create the nomex volume 
    1215             : 
    1216           1 :     TVirtualMC::GetMC()->Gsvolu("S07N","BOX",kNomexMaterial,nomexpar,3);
    1217           1 :     TVirtualMC::GetMC()->Gsvolu("SD7N","BOX",kNomexMaterial,nomexpar,3);
    1218           1 :     TVirtualMC::GetMC()->Gsvolu("S08N","BOX",kNomexMaterial,nomexpar,3);
    1219           1 :     TVirtualMC::GetMC()->Gsvolu("SD8N","BOX",kNomexMaterial,nomexpar,3);
    1220             : 
    1221             : 
    1222             :     // create the nomex volume (bulk)
    1223             : 
    1224           1 :     TVirtualMC::GetMC()->Gsvolu("S07X","BOX",kNomexBMaterial,nomexbpar,3);
    1225           1 :     TVirtualMC::GetMC()->Gsvolu("SD7X","BOX",kNomexBMaterial,nomexbpar,3);
    1226           1 :     TVirtualMC::GetMC()->Gsvolu("S08X","BOX",kNomexBMaterial,nomexbpar,3);
    1227           1 :     TVirtualMC::GetMC()->Gsvolu("SD8X","BOX",kNomexBMaterial,nomexbpar,3);
    1228             : 
    1229             :     // create the insulating material volume 
    1230             : 
    1231           1 :     TVirtualMC::GetMC()->Gsvolu("S07I","BOX",kInsuMaterial,insupar,3);
    1232           1 :     TVirtualMC::GetMC()->Gsvolu("SD7I","BOX",kInsuMaterial,insupar,3);
    1233           1 :     TVirtualMC::GetMC()->Gsvolu("S08I","BOX",kInsuMaterial,insupar,3);
    1234           1 :     TVirtualMC::GetMC()->Gsvolu("SD8I","BOX",kInsuMaterial,insupar,3);
    1235             : 
    1236             :     // create the PCB volume 
    1237             : 
    1238           1 :     TVirtualMC::GetMC()->Gsvolu("S07P","BOX",kPcbMaterial,pcbpar,3);
    1239           1 :     TVirtualMC::GetMC()->Gsvolu("SD7P","BOX",kPcbMaterial,pcbpar,3);
    1240           1 :     TVirtualMC::GetMC()->Gsvolu("S08P","BOX",kPcbMaterial,pcbpar,3);
    1241           1 :     TVirtualMC::GetMC()->Gsvolu("SD8P","BOX",kPcbMaterial,pcbpar,3);
    1242             :  
    1243             :     // create the sensitive volumes,
    1244             : 
    1245           1 :     TVirtualMC::GetMC()->Gsvolu("S07G","BOX",kSensMaterial,dum,0);
    1246           1 :     TVirtualMC::GetMC()->Gsvolu("SD7G","BOX",kSensMaterial,senspar,3);
    1247           1 :     TVirtualMC::GetMC()->Gsvolu("S08G","BOX",kSensMaterial,dum,0);
    1248           1 :     TVirtualMC::GetMC()->Gsvolu("SD8G","BOX",kSensMaterial,senspar,3);
    1249             : 
    1250             :     // create the vertical frame volume 
    1251             : 
    1252           1 :     TVirtualMC::GetMC()->Gsvolu("S07V","BOX",kVframeMaterial,vFramepar,3);
    1253           1 :     TVirtualMC::GetMC()->Gsvolu("S08V","BOX",kVframeMaterial,vFramepar,3);
    1254             : 
    1255             :     // create the rounded vertical frame volume 
    1256             : 
    1257           1 :     TVirtualMC::GetMC()->Gsvolu("SD7D","TUBS",kRframeMaterial,rFramepar4,5);
    1258           1 :     TVirtualMC::GetMC()->Gsvolu("SD8D","TUBS",kRframeMaterial,rFramepar4,5);
    1259             :     
    1260             :     // create the horizontal frame volume 
    1261             : 
    1262           1 :     TVirtualMC::GetMC()->Gsvolu("S07H","BOX",kHframeMaterial,hFramepar,3);
    1263           1 :     TVirtualMC::GetMC()->Gsvolu("SD7H","BOX",kHframeMaterial,hFramepar,3);
    1264           1 :     TVirtualMC::GetMC()->Gsvolu("S08H","BOX",kHframeMaterial,hFramepar,3);
    1265           1 :     TVirtualMC::GetMC()->Gsvolu("SD8H","BOX",kHframeMaterial,hFramepar,3);
    1266             : 
    1267             :     // create the horizontal border volume 
    1268             : 
    1269           1 :     TVirtualMC::GetMC()->Gsvolu("S07B","BOX",kBframeMaterial,bFramepar,3);
    1270           1 :     TVirtualMC::GetMC()->Gsvolu("SD7B","BOX",kBframeMaterial,bFramepar,3);
    1271           1 :     TVirtualMC::GetMC()->Gsvolu("S08B","BOX",kBframeMaterial,bFramepar,3);
    1272           1 :     TVirtualMC::GetMC()->Gsvolu("SD8B","BOX",kBframeMaterial,bFramepar,3);
    1273             : 
    1274             :     // Replace the volume shape with a composite shape
    1275             :     // with substracted overlap with beam shield     
    1276           1 :     if ( TVirtualMC::GetMC()->IsRootGeometrySupported() ) { 
    1277             :         
    1278             :       // Get shape
    1279             :       Int_t nSlatType = 1;
    1280             :       Int_t nVol = 8;
    1281             :       const char* slatType = "D"; // D: Rounded slat
    1282             :       const char* volLetter = "CNXIPHBG";
    1283           1 :       TString volName;
    1284           1 :       TString compName;
    1285           1 :       TString csName;
    1286             :       TGeoVolume *mVol = 0x0;
    1287             :       // Beam shield recess
    1288           3 :       new TGeoTube("tube4Cut", 0., AliMUONConstants::Rmin(3), kSlatWidth/2.+0.001);
    1289           1 :       TObjArray rounded4Slat(nSlatType*((nVol+1)*2));   
    1290             :       // Displacement
    1291           2 :       TGeoTranslation* trDTube4 = new TGeoTranslation("trDTube4", -(kPcbLength+kVframeLength)/2., -kYpos41[1], 0.);
    1292           1 :       trDTube4->RegisterYourself();
    1293           2 :       TGeoTranslation* trDBTube4 = new TGeoTranslation("trDBTube4", 0., ( kPcbHeight - kBframeHeight ) / 2., 0.);
    1294           1 :       trDBTube4->Add(trDTube4);
    1295           1 :       trDBTube4->RegisterYourself();
    1296             : 
    1297           1 :       TObjArray composite4(nSlatType*((nVol+1)*2));
    1298           2 :       new TGeoBBox("box4DCut",(kPcbLength+kVframeLength)/2., hFramepar[1], vFramepar[2]+0.001);
    1299             :       // Displacement
    1300           2 :       TGeoTranslation* trDBox4 = new TGeoTranslation("trDBox4",kPcbLength/2., kYpos41[1], 0.);
    1301           1 :       trDBox4->RegisterYourself();      
    1302             : 
    1303           2 :       TGeoBBox *box4Vframe = new TGeoBBox("box4Vframe",vFramepar[0],vrFrameHeight/2., vFramepar[2]);
    1304           4 :       TGeoTranslation* trVBox4 = new TGeoTranslation("trVBox4", 0., AliMUONConstants::Rmin(3)-kRframeLength + box4Vframe->GetDY(), 0.);
    1305           1 :       trVBox4->RegisterYourself();
    1306             :       
    1307           6 :       for(int iCh=7; iCh<=8; iCh++){
    1308           8 :         for (int iSlatType = 0; iSlatType<nSlatType; iSlatType++) {
    1309          36 :           for (int iVol = 0; iVol<nVol; iVol++){
    1310          16 :             Int_t lIndex = (iCh-7)*(nSlatType*(nVol+1))+iSlatType*(nVol+1)+iVol;
    1311          32 :             volName=Form("S%c%d%c",slatType[iSlatType],iCh,volLetter[iVol]);
    1312          32 :             mVol = gGeoManager->FindVolumeFast(volName);
    1313          16 :             if ( !mVol ) {
    1314           0 :               AliErrorStream() 
    1315           0 :                 << "Slat volume " << volName << " not found" << endl;        
    1316             :             }
    1317             :             else {
    1318          32 :               rounded4Slat[lIndex] = mVol->GetShape();
    1319          32 :               csName=Form("rounded4Slat%c%d%c",slatType[iSlatType],iCh,volLetter[iVol]);
    1320          48 :               ((TGeoShape*)rounded4Slat[lIndex])->SetName(csName);
    1321             :               
    1322             :               // Composite shape
    1323          16 :               TString compOperation(csName);
    1324          16 :               compOperation+="-tube4Cut:tr";
    1325          16 :               compOperation+=slatType[iSlatType];
    1326          48 :               if (strstr(volName,"B")){
    1327           2 :                 compOperation+="B";
    1328             :               }       
    1329          16 :               compOperation+="Tube4";
    1330          32 :               compName=Form("composite4%c%d%c",slatType[iSlatType],iCh,volLetter[iVol]);
    1331          96 :               composite4[lIndex] = new TGeoCompositeShape(compName, compOperation.Data()); 
    1332             :               
    1333             :               // Reset shape to volume      
    1334          32 :               mVol->SetShape((TGeoShape*)composite4[lIndex]);
    1335          16 :             }
    1336             :           }
    1337             : 
    1338             :           // For rounded spacer
    1339           2 :           Int_t lIndex = (iCh-7)*(nSlatType*(nVol+1))+iSlatType*(nVol+1)+nVol;
    1340           4 :           volName=Form("S%c%dD",slatType[iSlatType],iCh);
    1341           4 :           mVol = gGeoManager->FindVolumeFast(volName);
    1342           2 :           if ( !mVol ) {
    1343           0 :             AliErrorStream() 
    1344           0 :               << "Slat volume " << volName << " not found" << endl;  
    1345             :           }
    1346             :           else {
    1347           4 :             rounded4Slat[lIndex] = mVol->GetShape();
    1348           4 :             csName=Form("rounded4Slat%c%dD",slatType[iSlatType],iCh);
    1349           6 :             ((TGeoShape*)rounded4Slat[lIndex])->SetName(csName);
    1350             :             
    1351             :             // Composite shape
    1352           2 :             TString compOperation(csName);
    1353           6 :             if (strstr(volName,"SD")){
    1354           2 :               compOperation.Prepend("(");
    1355           2 :               compOperation+="+box4Vframe:trVBox4)*box4DCut:trDBox4";
    1356             :             }
    1357           4 :             compName=Form("composite4%c%dD",slatType[iSlatType],iCh);
    1358          12 :             composite4[lIndex] = new TGeoCompositeShape(compName, compOperation.Data());              
    1359             :             // Reset shape to volume      
    1360           4 :             mVol->SetShape((TGeoShape*)composite4[lIndex]);
    1361           2 :           }
    1362             :         }
    1363             :       }
    1364           1 :     }
    1365             : 
    1366             : 
    1367             :     index = 0; 
    1368          16 :     for (i = 0; i < kNslats4; i++){
    1369          70 :       for (Int_t quadrant = 1; quadrant <= 4; quadrant++) {
    1370             : 
    1371          28 :         if (i == 0 && quadrant == 2) continue;
    1372          27 :         if (i == 0 && quadrant == 4) continue;
    1373             : 
    1374          26 :         sprintf(idSlatCh7,"SLC%d",ConvertSlatNum(i,quadrant,kNslats4-1));
    1375          26 :         sprintf(idSlatCh8,"SLD%d",ConvertSlatNum(i,quadrant,kNslats4-1));
    1376          52 :         Int_t moduleSlatCh7 = GetModuleId(idSlatCh7);
    1377          52 :         Int_t moduleSlatCh8 = GetModuleId(idSlatCh8);
    1378             : 
    1379          26 :         Float_t xvFrame  = (slatLength4[i] - kVframeLength)/2.;
    1380             : 
    1381             :         // position the vertical frames 
    1382          52 :         if (i != 1) { 
    1383         114 :           GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("S07V", idSlatCh7, (2*i+1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
    1384          88 :           GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("S07V", idSlatCh7, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
    1385          88 :           GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("S08V", idSlatCh8, (2*i+1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
    1386          88 :           GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("S08V", idSlatCh8, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
    1387          22 :         } else { // Vertical and Rounded+Vertical spacer - Different rotation due to new mapping convention
    1388          20 :           GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("S07V", idSlatCh7, (2*i+1)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
    1389          20 :           GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("SD7D", idSlatCh7, (2*i)*10+quadrant,TGeoTranslation(xvFrame,-kYpos41[1],0.),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
    1390          20 :           GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("S08V", idSlatCh8, (2*i+1)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
    1391          20 :           GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("SD8D", idSlatCh8, (2*i)*10+quadrant,TGeoTranslation(+xvFrame,-kYpos42[1],0.),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
    1392             :         }
    1393             :         // position the panels and the insulating material 
    1394         272 :         for (j = 0; j < kNPCB4[i]; j++){
    1395         110 :           index++;
    1396         110 :           xx = kSensLength * (-kNPCB4[i]/2.+j+.5); 
    1397         110 :           Float_t zPanel = spar[2] - nomexbpar[2]; 
    1398         110 :           if (i==1) { // Different rotation due to new mapping convention
    1399          48 :             if (j==0){ // Rounded pcb of rounded slat
    1400          44 :               GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("SD7X", idSlatCh7, 2*index-1,TGeoTranslation(-xx,0.,zPanel),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
    1401          20 :               GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("SD7X", idSlatCh7, 2*index,TGeoTranslation(-xx,0.,-zPanel),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
    1402          20 :               GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("SD7I", idSlatCh7, index,TGeoTranslation(-xx,0.,0.),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
    1403          20 :               GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("SD8X", idSlatCh8, 2*index-1,TGeoTranslation(-xx,0.,zPanel),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
    1404          20 :               GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("SD8X", idSlatCh8, 2*index,TGeoTranslation(-xx,0.,-zPanel),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
    1405          20 :               GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("SD8I", idSlatCh8, index,TGeoTranslation(-xx,0.,0.),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
    1406           4 :             } else {          
    1407         100 :               GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("S07X", idSlatCh7, 2*index-1,TGeoTranslation(-xx,0.,zPanel),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
    1408         100 :               GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("S07X", idSlatCh7, 2*index,TGeoTranslation(-xx,0.,-zPanel),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
    1409          80 :               GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("S07I", idSlatCh7, index,TGeoTranslation(-xx,0.,0.));
    1410         100 :               GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("S08X", idSlatCh8, 2*index-1,TGeoTranslation(-xx,0.,zPanel),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
    1411         100 :               GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("S08X", idSlatCh8, 2*index,TGeoTranslation(-xx,0.,-zPanel),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
    1412         100 :               GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("S08I", idSlatCh8, index,TGeoTranslation(-xx,0.,0.),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
    1413             :             }
    1414             :           } else {            
    1415         344 :             GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("S07X", idSlatCh7, 2*index-1,TGeoTranslation(xx,0.,zPanel));
    1416         344 :             GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("S07X", idSlatCh7, 2*index,TGeoTranslation(xx,0.,-zPanel));
    1417         344 :             GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("S07I", idSlatCh7, index,TGeoTranslation(xx,0.,0.));
    1418         344 :             GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("S08X", idSlatCh8, 2*index-1,TGeoTranslation(xx,0.,zPanel));
    1419         344 :             GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("S08X", idSlatCh8, 2*index,TGeoTranslation(xx,0.,-zPanel));
    1420         344 :             GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("S08I", idSlatCh8, index,TGeoTranslation(xx,0.,0.));
    1421             :           }
    1422             :         }
    1423          26 :       } 
    1424             :     }
    1425             : 
    1426             :     // position the nomex volume inside the panel volume
    1427           1 :     TVirtualMC::GetMC()->Gspos("S07N",1,"S07C",0.,0.,0.,0,"ONLY"); 
    1428           1 :     TVirtualMC::GetMC()->Gspos("SD7N",1,"SD7C",0.,0.,0.,0,"ONLY"); 
    1429           1 :     TVirtualMC::GetMC()->Gspos("S08N",1,"S08C",0.,0.,0.,0,"ONLY"); 
    1430           1 :     TVirtualMC::GetMC()->Gspos("SD8N",1,"SD8C",0.,0.,0.,0,"ONLY"); 
    1431             : 
    1432             :     // position panel volume inside the bulk nomex material volume
    1433           1 :     TVirtualMC::GetMC()->Gspos("S07C",1,"S07X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
    1434           1 :     TVirtualMC::GetMC()->Gspos("SD7C",1,"SD7X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
    1435           1 :     TVirtualMC::GetMC()->Gspos("S08C",1,"S08X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
    1436           1 :     TVirtualMC::GetMC()->Gspos("SD8C",1,"SD8X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
    1437             : 
    1438             :     // position the PCB volume inside the insulating material volume
    1439           1 :     TVirtualMC::GetMC()->Gspos("S07P",1,"S07I",0.,0.,0.,0,"ONLY"); 
    1440           1 :     TVirtualMC::GetMC()->Gspos("SD7P",1,"SD7I",0.,0.,0.,0,"ONLY"); 
    1441           1 :     TVirtualMC::GetMC()->Gspos("S08P",1,"S08I",0.,0.,0.,0,"ONLY"); 
    1442           1 :     TVirtualMC::GetMC()->Gspos("SD8P",1,"SD8I",0.,0.,0.,0,"ONLY"); 
    1443             : 
    1444             :     // position the horizontal frame volume inside the PCB volume
    1445           1 :     TVirtualMC::GetMC()->Gspos("S07H",1,"S07P",0.,0.,0.,0,"ONLY"); 
    1446           1 :     TVirtualMC::GetMC()->Gspos("SD7H",1,"SD7P",0.,0.,0.,0,"ONLY"); 
    1447           1 :     TVirtualMC::GetMC()->Gspos("S08H",1,"S08P",0.,0.,0.,0,"ONLY"); 
    1448           1 :     TVirtualMC::GetMC()->Gspos("SD8H",1,"SD8P",0.,0.,0.,0,"ONLY"); 
    1449             : 
    1450             :     // position the sensitive volume inside the horizontal frame volume
    1451           1 :     TVirtualMC::GetMC()->Gsposp("S07G",1,"S07H",0.,0.,0.,0,"ONLY",senspar,3); 
    1452           1 :     TVirtualMC::GetMC()->Gspos("SD7G",1,"SD7H",0.,0.,0.,0,"ONLY"); 
    1453           1 :     TVirtualMC::GetMC()->Gsposp("S08G",1,"S08H",0.,0.,0.,0,"ONLY",senspar,3); 
    1454           1 :     TVirtualMC::GetMC()->Gspos("SD8G",1,"SD8H",0.,0.,0.,0,"ONLY"); 
    1455             : 
    1456             :     // position the border volumes inside the PCB volume
    1457             :     Float_t yborder = ( kPcbHeight - kBframeHeight ) / 2.; 
    1458           1 :     TVirtualMC::GetMC()->Gspos("S07B",1,"S07P",0., yborder,0.,0,"ONLY"); 
    1459           1 :     TVirtualMC::GetMC()->Gspos("S07B",2,"S07P",0.,-yborder,0.,0,"ONLY");
    1460           1 :     TVirtualMC::GetMC()->Gspos("S07B",1,"SD7P",0., yborder,0.,0,"ONLY");
    1461           1 :     TVirtualMC::GetMC()->Gspos("SD7B",1,"SD7P",0.,-yborder,0.,0,"ONLY");  
    1462           1 :     TVirtualMC::GetMC()->Gspos("S08B",1,"S08P",0., yborder,0.,0,"ONLY"); 
    1463           1 :     TVirtualMC::GetMC()->Gspos("S08B",2,"S08P",0.,-yborder,0.,0,"ONLY"); 
    1464           1 :     TVirtualMC::GetMC()->Gspos("S08B",1,"SD8P",0., yborder,0.,0,"ONLY"); 
    1465           1 :     TVirtualMC::GetMC()->Gspos("SD8B",1,"SD8P",0.,-yborder,0.,0,"ONLY"); 
    1466             : 
    1467             :     // create the NULOC volume and position it in the horizontal frame
    1468             : 
    1469           1 :     TVirtualMC::GetMC()->Gsvolu("S07E","BOX",kNulocMaterial,nulocpar,3);
    1470           1 :     TVirtualMC::GetMC()->Gsvolu("S08E","BOX",kNulocMaterial,nulocpar,3);
    1471             :     index = 0;
    1472           1 :     Float_t rPhi3 = TMath::ASin((kYpos41[1]-kPcbHeight/2.)/AliMUONConstants::Rmin(3));
    1473           1 :     Float_t xxmax4 = (AliMUONConstants::Rmin(3)*TMath::Cos(rPhi3)-kVframeLength/2.) - (kBframeLength - kNulocLength)/2.;
    1474          18 :     for (xx = -xxmax; xx <= xxmax; xx += 2*kNulocLength) { 
    1475           8 :       index++; 
    1476           8 :       TVirtualMC::GetMC()->Gspos("S07E",2*index-1,"S07B", xx, 0.,-kBframeWidth/2. + kNulocWidth/2, 0, "ONLY");
    1477           8 :       TVirtualMC::GetMC()->Gspos("S07E",2*index  ,"S07B", xx, 0., kBframeWidth/2. - kNulocWidth/2, 0, "ONLY");
    1478           8 :       TVirtualMC::GetMC()->Gspos("S08E",2*index-1,"S08B", xx, 0.,-kBframeWidth/2. + kNulocWidth/2, 0, "ONLY");
    1479           8 :       TVirtualMC::GetMC()->Gspos("S08E",2*index  ,"S08B", xx, 0., kBframeWidth/2. - kNulocWidth/2, 0, "ONLY");
    1480             :     }
    1481           2 :     if (xx > xxmax4 && xx< xxmax) {
    1482           0 :       TVirtualMC::GetMC()->Gspos("S07E",2*index-1,"SD7B", xx, 0.,-kBframeWidth/2.+ kNulocWidth/2, 0, "ONLY");
    1483           0 :       TVirtualMC::GetMC()->Gspos("S07E",2*index  ,"SD7B", xx, 0., kBframeWidth/2.- kNulocWidth/2, 0, "ONLY");
    1484           0 :       TVirtualMC::GetMC()->Gspos("S08E",2*index-1,"SD8B", xx, 0.,-kBframeWidth/2.+ kNulocWidth/2, 0, "ONLY");
    1485           0 :       TVirtualMC::GetMC()->Gspos("S08E",2*index  ,"SD8B", xx, 0., kBframeWidth/2.- kNulocWidth/2, 0, "ONLY");
    1486           0 :     }
    1487             : 
    1488             :     //
    1489             :     //Geometry of the support pannel Verticla length 5.3m, horizontal length 2.6m, internal radius  dMotherInner o SC07 and SC08  (F. Orsini, Saclay)
    1490             :     //Carbon fiber of 0.3 mm thick (2 layers) and a central layer of Nomex of 15mm thick. 
    1491           1 :     Float_t dMotherInner =  AliMUONConstants::Rmin(3)-kRframeHeight; 
    1492             :     Float_t nomexthickness = 1.5;
    1493             :     Float_t carbonthickness = 0.03;
    1494             :     Float_t supporthlength =  260.;  
    1495             :     Float_t supportvlength =  530.;  
    1496             :     // Generating the composite shape of the carbon and nomex pannels
    1497           1 :     new TGeoBBox("shNomexBoxSt4",supporthlength/2., supportvlength/2. ,nomexthickness/2.+carbonthickness+3*kCableWidth);
    1498           1 :     new TGeoBBox("shCarbonBoxSt4",supporthlength/2., supportvlength/2. ,carbonthickness/2.); 
    1499           1 :     new TGeoTubeSeg("shNomexHoleSt4",0., dMotherInner, nomexthickness/2.+carbonthickness+3*kCableWidth+0.001, -90. ,90.);
    1500           1 :     new TGeoTubeSeg("shCarbonHoleSt4",0., dMotherInner, carbonthickness/2.+0.001, -90. ,90.);
    1501           1 :     TGeoTranslation* trHoleSt4 = new TGeoTranslation("trHoleSt4",-supporthlength/2.,0.,0.); 
    1502           1 :     trHoleSt4->RegisterYourself();
    1503           1 :     TGeoCompositeShape* shNomexSupportSt4  = new TGeoCompositeShape("shNomexSupportSt4","shNomexBoxSt4-shNomexHoleSt4:trHoleSt4");
    1504           1 :     TGeoCompositeShape* shCarbonSupportSt4 = new TGeoCompositeShape("shCarbonSupportSt4","shCarbonBoxSt4-shCarbonHoleSt4:trHoleSt4");
    1505             :  
    1506             :    // Generating Nomex and Carbon pannel volumes
    1507           1 :     TGeoVolume* voNomexSupportSt4   = new TGeoVolume("S07S", shNomexSupportSt4, kMedNomex);
    1508           1 :     TGeoVolume* voCarbonSupportSt4  = new TGeoVolume("S07K", shCarbonSupportSt4, kMedCarbon);
    1509           1 :     TGeoVolume* voNomexSupportSt4Ch8   = new TGeoVolume("S08S", shNomexSupportSt4, kMedNomex);
    1510           1 :     TGeoVolume* voCarbonSupportSt4Ch8  = new TGeoVolume("S08K", shCarbonSupportSt4, kMedCarbon);
    1511           1 :     TGeoTranslation* trCarbon1St4   = new TGeoTranslation("trCarbon1St4",0.,0., -(nomexthickness+carbonthickness)/2.);
    1512           1 :     TGeoTranslation* trCarbon2St4   = new TGeoTranslation("trCarbon2St4",0.,0.,  (nomexthickness+carbonthickness)/2.);
    1513           1 :     voNomexSupportSt4->AddNode(voCarbonSupportSt4,1,trCarbon1St4);
    1514           1 :     voNomexSupportSt4->AddNode(voCarbonSupportSt4,2,trCarbon2St4);
    1515           1 :     voNomexSupportSt4Ch8->AddNode(voCarbonSupportSt4Ch8,1,trCarbon1St4);
    1516           1 :     voNomexSupportSt4Ch8->AddNode(voCarbonSupportSt4Ch8,2,trCarbon2St4);
    1517             :  
    1518             :     // Add readout cables
    1519           1 :     TVirtualMC::GetMC()->Gsvolu("S07L","BOX",kCableMaterial,dum,0);
    1520           1 :     TVirtualMC::GetMC()->Gsvolu("S08L","BOX",kCableMaterial,dum,0);
    1521             : 
    1522             :     ySlat41 = 0.;
    1523             :     ySlat42 = 0.;
    1524             :     Float_t lCableX = 0.;
    1525             :     Float_t lCableY = 0.;
    1526             :     Float_t lCableY8 = 0.;
    1527             :     Float_t lCableZ = 0.;
    1528           1 :     Float_t cablepar[3] = {static_cast<Float_t>(supporthlength/2.), static_cast<Float_t>(kCableHeight/2.), static_cast<Float_t>(kCableWidth/2.)};
    1529             :     Float_t lCableDY = 0.;
    1530             :     Float_t lCableDY8 = 0.;
    1531          16 :     for (i = 0; i<kNslats4; i++){
    1532             :       Int_t iCable = 1;
    1533             :       Int_t cIndex = 0;
    1534             :       Int_t cIndex8 = 0;
    1535           7 :       ySlat41 += kYpos41[i];
    1536           7 :       ySlat42 += kYpos42[i];
    1537             : 
    1538             :       lCableY = ySlat41;
    1539             :       lCableY8 = ySlat42;
    1540             : 
    1541             :       // Cables going out from the start of slat
    1542           7 :       if(kNPCB4[i]>=4 && i<kNslats4-2){ // Only if 4 or more pcb
    1543             :         // First top cables
    1544           5 :         cablepar[0] = (supporthlength-kXpos4[i])/2.;
    1545           5 :         lCableX = kXpos4[i]/2.;
    1546           5 :         lCableDY = (kYpos41[i+1]+kYpos41[i+2])/2.-cablepar[1];
    1547           5 :         lCableDY8 = (kYpos42[i+1]+kYpos42[i+2])/2.-cablepar[1];
    1548           5 :         lCableZ = TMath::Power(-1,i)*(nomexthickness/2.+carbonthickness+(-1+iCable++)*kCableWidth+kCableWidth/2.);
    1549           5 :         TVirtualMC::GetMC()->Gsposp("S07L",10*i+cIndex++,"S07S",lCableX,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar,3);         
    1550           5 :         TVirtualMC::GetMC()->Gsposp("S07L",10*i+cIndex++,"S07S",lCableX,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar,3);
    1551           5 :         TVirtualMC::GetMC()->Gsposp("S08L",10*i+cIndex8++,"S08S",lCableX,lCableY8+lCableDY8,lCableZ,0,"ONLY",cablepar,3);      
    1552           5 :         TVirtualMC::GetMC()->Gsposp("S08L",10*i+cIndex8++,"S08S",lCableX,-(lCableY8+lCableDY8),lCableZ,0,"ONLY",cablepar,3);
    1553             :         // Then bottom cables
    1554           5 :         if (i>0){
    1555           4 :           if (i==1) { // Rounded slat. Bottom cable starts at dMotherInner (beam pipe)
    1556           1 :             cablepar[0] = (supporthlength-kXpos4[i]-dMotherInner)/2.;
    1557           1 :             lCableX = (kXpos4[i]+dMotherInner)/2.;
    1558           1 :             lCableDY = (kYpos41[i]+kYpos41[i])/2.-cablepar[1];
    1559           1 :             lCableDY8 = (kYpos42[i]+kYpos42[i])/2.-cablepar[1];
    1560           1 :           }
    1561           4 :           if (i>=2) {
    1562           3 :             lCableDY = (kYpos41[i]+kYpos41[i-1])/2.-cablepar[1];
    1563           3 :             if ((lCableY-lCableDY)<(dMotherInner+cablepar[1])){
    1564           1 :               lCableDY = lCableY - dMotherInner - cablepar[1];
    1565           1 :             }
    1566           3 :             lCableDY8 = (kYpos42[i]+kYpos42[i-1])/2.-cablepar[1];
    1567           3 :             if ((lCableY8-lCableDY8)<(dMotherInner+cablepar[1])){
    1568           0 :               lCableDY8 = lCableY8 - dMotherInner - cablepar[1];
    1569           0 :             }
    1570             :           }
    1571           4 :           TVirtualMC::GetMC()->Gsposp("S07L",10*i+cIndex++,"S07S",lCableX,lCableY-lCableDY,lCableZ,0,"ONLY",cablepar,3); 
    1572           4 :           TVirtualMC::GetMC()->Gsposp("S07L",10*i+cIndex++,"S07S",lCableX,-(lCableY-lCableDY),lCableZ,0,"ONLY",cablepar,3); 
    1573           4 :           TVirtualMC::GetMC()->Gsposp("S08L",10*i+cIndex8++,"S08S",lCableX,lCableY8-lCableDY8,lCableZ,0,"ONLY",cablepar,3); 
    1574           4 :           TVirtualMC::GetMC()->Gsposp("S08L",10*i+cIndex8++,"S08S",lCableX,-(lCableY8-lCableDY8),lCableZ,0,"ONLY",cablepar,3); 
    1575           4 :         }
    1576             :       }
    1577             : 
    1578             :       // Rounded slats have an extra cable starting at second pcb
    1579           7 :       if(i==1){ 
    1580             :         // Only on top
    1581           1 :         cablepar[0] = (supporthlength-kPcbLength-kVframeLength)/2.;
    1582             :         lCableX = (kPcbLength+kVframeLength)/2.;
    1583           1 :         lCableDY = (kYpos41[i+1]+kYpos41[i+2])/2.-cablepar[1]; // half way between 2 slats on same side
    1584           1 :         lCableDY8 = (kYpos42[i+1]+kYpos42[i+2])/2.-cablepar[1]; // half way between 2 slats on same side
    1585           1 :         lCableZ = TMath::Power(-1,i)*(nomexthickness/2.+carbonthickness+(-1+iCable++)*kCableWidth+kCableWidth/2.);
    1586           1 :         TVirtualMC::GetMC()->Gsposp("S07L",10*i+cIndex++,"S07S",lCableX,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar,3); 
    1587           1 :         TVirtualMC::GetMC()->Gsposp("S07L",10*i+cIndex++,"S07S",lCableX,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar,3); 
    1588           1 :         TVirtualMC::GetMC()->Gsposp("S08L",10*i+cIndex8++,"S08S",lCableX,lCableY8+lCableDY8,lCableZ,0,"ONLY",cablepar,3); 
    1589           1 :         TVirtualMC::GetMC()->Gsposp("S08L",10*i+cIndex8++,"S08S",lCableX,-(lCableY8+lCableDY8),lCableZ,0,"ONLY",cablepar,3); 
    1590           1 :       } 
    1591             : 
    1592             :       // Cables going out from the end of the slats
    1593           7 :       cablepar[0] = (supporthlength-(slatLength4[i]+kXpos4[i]+kDslatLength)+kVframeLength)/2.;
    1594           7 :       lCableX = slatLength4[i]+kXpos4[i]-kVframeLength+kDslatLength+cablepar[0]-supporthlength/2.;
    1595          13 :       if(i+1>=kNslats4 || i+2>=kNslats4){ // If no more higher slats, then use distance to lower slat
    1596           2 :         lCableDY = kPcbHeight/2.+cablepar[1];
    1597             :         lCableDY8 = lCableDY;
    1598           2 :       }
    1599             :       else {
    1600           5 :         lCableDY = (kYpos41[i+1]+kYpos41[i+2])/2.-cablepar[1];
    1601           5 :         lCableDY8 = (kYpos42[i+1]+kYpos42[i+2])/2.-cablepar[1];
    1602             :       }
    1603           7 :       lCableZ = TMath::Power(-1,i)*(nomexthickness/2.+carbonthickness+(-1+iCable++)*kCableWidth+kCableWidth/2.);
    1604           7 :       TVirtualMC::GetMC()->Gsposp("S07L",10*i+cIndex++,"S07S",lCableX,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar,3); 
    1605           7 :       TVirtualMC::GetMC()->Gsposp("S07L",10*i+cIndex++,"S07S",lCableX,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar,3); 
    1606           7 :       TVirtualMC::GetMC()->Gsposp("S08L",10*i+cIndex8++,"S08S",lCableX,lCableY8+lCableDY8,lCableZ,0,"ONLY",cablepar,3); 
    1607           7 :       TVirtualMC::GetMC()->Gsposp("S08L",10*i+cIndex8++,"S08S",lCableX,-(lCableY8+lCableDY8),lCableZ,0,"ONLY",cablepar,3); 
    1608             :       // Then bottom cables
    1609           7 :       if(i>0){
    1610           6 :         if (i==1) {
    1611           7 :           lCableDY = (kYpos41[i]+kYpos41[i])/2.-cablepar[1];
    1612           1 :           lCableDY8 = (kYpos42[i]+kYpos42[i])/2.-cablepar[1];
    1613           1 :         }
    1614             :         else{
    1615           5 :           lCableDY = (kYpos41[i]+kYpos41[i-1])/2.-cablepar[1]; // half way between 2 slats on same side
    1616           5 :           if ((lCableY-lCableDY)<(dMotherInner+cablepar[1])){
    1617           1 :             lCableDY = lCableY - dMotherInner - cablepar[1];
    1618           1 :           }
    1619           5 :           lCableDY8 = (kYpos42[i]+kYpos42[i-1])/2.-cablepar[1]; // half way between 2 slats on same side
    1620           5 :           if ((lCableY8-lCableDY8)<(dMotherInner+cablepar[1])){
    1621           0 :             lCableDY8 = lCableY8 - dMotherInner - cablepar[1];
    1622           0 :           }
    1623             :         }
    1624           6 :         TVirtualMC::GetMC()->Gsposp("S07L",10*i+cIndex++,"S07S",lCableX,lCableY-lCableDY,lCableZ,0,"ONLY",cablepar,3); 
    1625           6 :         TVirtualMC::GetMC()->Gsposp("S07L",10*i+cIndex++,"S07S",lCableX,-(lCableY-lCableDY),lCableZ,0,"ONLY",cablepar,3); 
    1626           6 :         TVirtualMC::GetMC()->Gsposp("S08L",10*i+cIndex8++,"S08S",lCableX,lCableY8-lCableDY8,lCableZ,0,"ONLY",cablepar,3); 
    1627           6 :         TVirtualMC::GetMC()->Gsposp("S08L",10*i+cIndex8++,"S08S",lCableX,-(lCableY8-lCableDY8),lCableZ,0,"ONLY",cablepar,3); 
    1628           6 :       } 
    1629             :     }
    1630             :     
    1631             :     Float_t dzCh7  = dzCh;
    1632           1 :     TGeoTranslation* trSupport1St4   = new TGeoTranslation("trSupport1St4", supporthlength/2., 0. , dzCh7);
    1633           1 :     TGeoRotation*    roSupportSt4    = new TGeoRotation("roSupportSt4",90.,180.,-90.);
    1634           1 :     TGeoCombiTrans*  coSupport2St4   = new TGeoCombiTrans(-supporthlength/2., 0., -dzCh7, roSupportSt4); 
    1635           2 :     GetEnvelopes(9)->AddEnvelope("S07S", 0, 1, *trSupport1St4);  
    1636           2 :     GetEnvelopes(8)->AddEnvelope("S07S", 0, 2, *coSupport2St4);  
    1637           2 :     GetEnvelopes(11)->AddEnvelope("S08S", 0, 1, *trSupport1St4);   
    1638           2 :     GetEnvelopes(10)->AddEnvelope("S08S", 0, 2, *coSupport2St4);
    1639             : 
    1640             :     // End of pannel support geometry    
    1641             : 
    1642             :     // cout << "Geometry for Station 4...... done" << endl;
    1643             : 
    1644           1 :   }
    1645             :     
    1646           1 :   if (fStations[4]) {
    1647             :       
    1648             : 
    1649             :     // //********************************************************************
    1650             :     // //                            Station 5                             **
    1651             :     // //********************************************************************
    1652             :     // Mother volume for each chamber in St4 is an envelop (or assembly)
    1653             :     // There is one assembly mother per half a chamber  called SC09I, SC09O, SC10I and SC10O 
    1654             :     // Same volume name definitions as in St3
    1655             :     
    1656             :     const Int_t   kNslats5         = 7;  // number of slats per quadrant
    1657             :     const Int_t   kNPCB5[kNslats5] = {5, 6, 6, 6, 5, 4, 3}; // n PCB per slat
    1658             :     const Float_t kXpos5[kNslats5] = {38.75, 0., 0., 0., 0., 0., 0.}; // J.C. Correct value  
    1659             :     const Float_t kYpos5[kNslats5] = {0., 38.2, 37.9, 37.6, 37.3, 37.05, 36.75};
    1660           1 :     Float_t slatLength5[kNslats5]; 
    1661             : 
    1662           1 :     Float_t rPhi1 = TMath::RadToDeg()*(TMath::ASin((kYpos5[1]-hFramepar[1])/(AliMUONConstants::Rmin(4))));
    1663           1 :     Float_t rPhi2 = TMath::RadToDeg()*(TMath::ACos(-vFramepar[0]/(AliMUONConstants::Rmin(4)-kRframeLength)));
    1664           1 :     Float_t rFramepar5[5] = { AliMUONConstants::Rmin(4)-kRframeLength, AliMUONConstants::Rmin(4), kRframeWidth, rPhi1, rPhi2}; 
    1665           1 :     Float_t vrFrameHeight = hFramepar[1]+kYpos5[1]-AliMUONConstants::Rmin(4)+kRframeLength;
    1666             : 
    1667           1 :     char idSlatCh9[6];
    1668           1 :     char idSlatCh10[6];
    1669             :     Float_t xSlat5;
    1670             :     Float_t ySlat5 = 0;
    1671             :     angle = 0.;
    1672             : 
    1673          16 :     for (i = 0; i < kNslats5; i++){
    1674             : 
    1675           7 :       slatLength5[i] = kPcbLength * kNPCB5[i] + 2.* kVframeLength; 
    1676           7 :       xSlat5 = slatLength5[i]/2. + kDslatLength + kXpos5[i]; 
    1677           7 :       ySlat5 += kYpos5[i];
    1678             : 
    1679             :       spar[0] = slatLength5[i]/2.; 
    1680             :       spar[1] = kSlatHeight/2.;
    1681           7 :       spar[2] = kSlatWidth/2.; 
    1682             : 
    1683             :       Float_t dzCh5  = dzCh;
    1684           7 :       Float_t zSlat5 = (i%2 ==0)? -zSlat : zSlat; 
    1685             : 
    1686           7 :       sprintf(idSlatCh9,"SLE%d",kNslats5-1+i);
    1687           7 :       detElemId = 913 - (i + kNslats5-1-6);
    1688           7 :       moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
    1689           7 :       if (detElemId % 2 == 0) {
    1690           6 :         if (detElemId == 912) // Round slat, new rotation due to mapping convention
    1691           6 :           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(xSlat5, ySlat5, -zSlat5 + dzCh5),
    1692           1 :                                               TGeoRotation("rot1",90,180+angle,90,90+angle,180,0) );
    1693             :         else
    1694           6 :           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(xSlat5, ySlat5, -zSlat5 + dzCh5),
    1695           2 :                                               TGeoRotation("rot1",90,angle,90,90+angle,0,0) );
    1696             :       }
    1697             :       else
    1698          12 :         GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(xSlat5, ySlat5, -zSlat5 + dzCh5),
    1699           4 :                                             TGeoRotation("rot1",90,angle,90,270+angle,180,0) );
    1700           7 :       sprintf(idSlatCh9,"SLE%d",3*kNslats5-2+i);
    1701           7 :       detElemId = 900 + (i + kNslats5-1-6);
    1702           7 :       moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
    1703           7 :       if (detElemId % 2 == 1) {
    1704           6 :         if (detElemId == 901) // Round slat, new rotation due to mapping convention
    1705           6 :           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(-xSlat5, ySlat5, zSlat5 - dzCh5),
    1706           1 :                                               TGeoRotation("rot2",90,angle,90,90+angle,0,0) );
    1707             :         else
    1708           6 :           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(-xSlat5, ySlat5, zSlat5 - dzCh5),
    1709           2 :                                               TGeoRotation("rot2",90,180+angle,90,90+angle,180,0) );
    1710             :       }
    1711             :       else
    1712          12 :         GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(-xSlat5, ySlat5, zSlat5 - dzCh5),
    1713           4 :                                             TGeoRotation("rot2",90,180+angle,90,270+angle,0,0) );      
    1714             : 
    1715           7 :       if (i > 0) { 
    1716           6 :         sprintf(idSlatCh9,"SLE%d",kNslats5-1-i);
    1717           6 :         detElemId = 913 + (i + kNslats5-1-6);
    1718           6 :         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
    1719           6 :         if (detElemId % 2 == 0) {
    1720           6 :           if (detElemId == 914) // Round slat, new rotation due to mapping convention
    1721           6 :           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(xSlat5, -ySlat5, -zSlat5 + dzCh5),
    1722           1 :                                               TGeoRotation("rot3",90,180+angle,90,270+angle,0,0) );
    1723             :           else
    1724           6 :             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(xSlat5, -ySlat5, -zSlat5 + dzCh5),
    1725           2 :                                                 TGeoRotation("rot3",90,angle,90,90+angle,0,0) );
    1726             :         }
    1727             :         else
    1728           9 :           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(xSlat5, -ySlat5, -zSlat5 + dzCh5),
    1729           3 :                                      TGeoRotation("rot3",90,angle,90,270+angle,180,0) );
    1730             : 
    1731           6 :         sprintf(idSlatCh9,"SLE%d",3*kNslats5-2-i);
    1732           6 :         detElemId = 926 - (i + kNslats5-1-6);
    1733           6 :         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
    1734           6 :         if (detElemId % 2 == 1) {
    1735           6 :           if (detElemId == 925) // Round slat, new rotation due to mapping convention
    1736           6 :             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(-xSlat5, -ySlat5, zSlat5 - dzCh5),
    1737           1 :                                                 TGeoRotation("rot4",90,angle,90,270+angle,180,0) );
    1738             :           else
    1739           6 :             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(-xSlat5, -ySlat5, zSlat5 - dzCh5),
    1740           2 :                                                 TGeoRotation("rot4",90,180+angle,90,90+angle,180,0)  );
    1741             :         }
    1742             :         else
    1743           9 :           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(-xSlat5, -ySlat5, zSlat5 - dzCh5),
    1744           3 :                                               TGeoRotation("rot4",90,180+angle,90,270+angle,0,0)  );   
    1745             :       }
    1746             : 
    1747           7 :       sprintf(idSlatCh10,"SLF%d",kNslats5-1+i);
    1748           7 :       detElemId = 1013 - (i + kNslats5-1-6);
    1749           7 :       moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
    1750           7 :       if (detElemId % 2 == 0) {
    1751           6 :         if (detElemId == 1012) // Round slat, new rotation due to mapping convention
    1752           6 :           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(xSlat5, ySlat5, -zSlat5 + dzCh5),
    1753           1 :                                               TGeoRotation("rot5",90,180+angle,90,90+angle,180,0) );
    1754             :         else
    1755           6 :           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(xSlat5, ySlat5, -zSlat5 + dzCh5),
    1756           2 :                                               TGeoRotation("rot5",90,angle,90,90+angle,0,0) );
    1757             :       }
    1758             :       else
    1759          12 :           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(xSlat5, ySlat5, -zSlat5 + dzCh5),
    1760           4 :                                               TGeoRotation("rot5",90,angle,90,270+angle,180,0) );
    1761             : 
    1762           7 :       sprintf(idSlatCh10,"SLF%d",3*kNslats5-2+i);
    1763           7 :       detElemId = 1000 + (i + kNslats5-1-6);
    1764           7 :       moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
    1765           7 :       if (detElemId % 2 == 1) {
    1766           6 :         if (detElemId == 1001) // Round slat, new rotation due to mapping convention
    1767           6 :           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(-xSlat5, ySlat5, zSlat5 - dzCh5),
    1768           1 :                                               TGeoRotation("rot6",90,angle,90,90+angle,0,0) ); 
    1769             :         else
    1770           6 :           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(-xSlat5, ySlat5, zSlat5 - dzCh5),
    1771           2 :                                               TGeoRotation("rot6",90,180+angle,90,90+angle,180,0) ); 
    1772             :       }
    1773             :       else
    1774          12 :         GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(-xSlat5, ySlat5, zSlat5 - dzCh5),
    1775           4 :                                             TGeoRotation("rot6",90,180+angle,90,270+angle,0,0) );
    1776             : 
    1777           7 :       if (i > 0) { 
    1778           6 :         sprintf(idSlatCh10,"SLF%d",kNslats5-1-i);
    1779           6 :         detElemId = 1013 + (i + kNslats5-1-6);
    1780           6 :         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
    1781           6 :         if (detElemId % 2 == 0) {  
    1782           6 :           if (detElemId == 1014) // Round slat, new rotation due to mapping convention
    1783           6 :             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(xSlat5, -ySlat5, -zSlat5 + dzCh5),
    1784           1 :                                                 TGeoRotation("rot7",90,180+angle,90,270+angle,0,0) );
    1785             :           else
    1786           6 :             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(xSlat5, -ySlat5, -zSlat5 + dzCh5),
    1787           2 :                                                 TGeoRotation("rot7",90,angle,90,90+angle,0,0) );
    1788             :         }
    1789             :         else
    1790           9 :           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(xSlat5, -ySlat5, -zSlat5 + dzCh5),
    1791           3 :                                               TGeoRotation("rot7",90,angle,90,270+angle,180,0) );
    1792             : 
    1793           6 :         sprintf(idSlatCh10,"SLF%d",3*kNslats5-2-i);
    1794           6 :         detElemId = 1026 - (i + kNslats5-1-6);
    1795           6 :         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
    1796           6 :         if (detElemId % 2 == 1) {
    1797           6 :           if (detElemId == 1025) // Round slat, new rotation due to mapping convention
    1798           6 :             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(-xSlat5, -ySlat5, zSlat5 - dzCh5),
    1799           1 :                                                 TGeoRotation("rot8",90,angle,90,270+angle,180,0) );
    1800             :           else
    1801           6 :             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(-xSlat5, -ySlat5, zSlat5 - dzCh5),
    1802           2 :                                                 TGeoRotation("rot8",90,180+angle,90,90+angle,180,0) );
    1803             :         }
    1804             :         else
    1805           9 :           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(-xSlat5, -ySlat5, zSlat5 - dzCh5),
    1806           3 :                                               TGeoRotation("rot8",90,180+angle,90,270+angle,0,0) ); 
    1807             :       }
    1808             :     }
    1809             : 
    1810             :     // create the panel volume 
    1811             :  
    1812           1 :     TVirtualMC::GetMC()->Gsvolu("S09C","BOX",kCarbonMaterial,panelpar,3);
    1813           1 :     TVirtualMC::GetMC()->Gsvolu("SD9C","BOX",kCarbonMaterial,panelpar,3);
    1814           1 :     TVirtualMC::GetMC()->Gsvolu("S10C","BOX",kCarbonMaterial,panelpar,3);
    1815           1 :     TVirtualMC::GetMC()->Gsvolu("SD0C","BOX",kCarbonMaterial,panelpar,3);
    1816             : 
    1817             :     // create the nomex volume 
    1818             : 
    1819           1 :     TVirtualMC::GetMC()->Gsvolu("S09N","BOX",kNomexMaterial,nomexpar,3);
    1820           1 :     TVirtualMC::GetMC()->Gsvolu("SD9N","BOX",kNomexMaterial,nomexpar,3);
    1821           1 :     TVirtualMC::GetMC()->Gsvolu("S10N","BOX",kNomexMaterial,nomexpar,3);
    1822           1 :     TVirtualMC::GetMC()->Gsvolu("SD0N","BOX",kNomexMaterial,nomexpar,3);
    1823             : 
    1824             : 
    1825             :     // create the nomex volume (bulk)
    1826             : 
    1827           1 :     TVirtualMC::GetMC()->Gsvolu("S09X","BOX",kNomexBMaterial,nomexbpar,3);
    1828           1 :     TVirtualMC::GetMC()->Gsvolu("SD9X","BOX",kNomexBMaterial,nomexbpar,3);
    1829           1 :     TVirtualMC::GetMC()->Gsvolu("S10X","BOX",kNomexBMaterial,nomexbpar,3);
    1830           1 :     TVirtualMC::GetMC()->Gsvolu("SD0X","BOX",kNomexBMaterial,nomexbpar,3);
    1831             : 
    1832             :     // create the insulating material volume 
    1833             : 
    1834           1 :     TVirtualMC::GetMC()->Gsvolu("S09I","BOX",kInsuMaterial,insupar,3);
    1835           1 :     TVirtualMC::GetMC()->Gsvolu("SD9I","BOX",kInsuMaterial,insupar,3);
    1836           1 :     TVirtualMC::GetMC()->Gsvolu("S10I","BOX",kInsuMaterial,insupar,3);
    1837           1 :     TVirtualMC::GetMC()->Gsvolu("SD0I","BOX",kInsuMaterial,insupar,3);
    1838             : 
    1839             :     // create the PCB volume 
    1840             : 
    1841           1 :     TVirtualMC::GetMC()->Gsvolu("S09P","BOX",kPcbMaterial,pcbpar,3);
    1842           1 :     TVirtualMC::GetMC()->Gsvolu("SD9P","BOX",kPcbMaterial,pcbpar,3);
    1843           1 :     TVirtualMC::GetMC()->Gsvolu("S10P","BOX",kPcbMaterial,pcbpar,3);
    1844           1 :     TVirtualMC::GetMC()->Gsvolu("SD0P","BOX",kPcbMaterial,pcbpar,3);
    1845             :  
    1846             :     // create the sensitive volumes,
    1847             : 
    1848           1 :     TVirtualMC::GetMC()->Gsvolu("S09G","BOX",kSensMaterial,dum,0);
    1849           1 :     TVirtualMC::GetMC()->Gsvolu("SD9G","BOX",kSensMaterial,senspar,3);
    1850           1 :     TVirtualMC::GetMC()->Gsvolu("S10G","BOX",kSensMaterial,dum,0);
    1851           1 :     TVirtualMC::GetMC()->Gsvolu("SD0G","BOX",kSensMaterial,senspar,3);
    1852             : 
    1853             :     // create the vertical frame volume 
    1854             : 
    1855           1 :     TVirtualMC::GetMC()->Gsvolu("S09V","BOX",kVframeMaterial,vFramepar,3);
    1856           1 :     TVirtualMC::GetMC()->Gsvolu("S10V","BOX",kVframeMaterial,vFramepar,3);
    1857             : 
    1858             :     // create the rounded vertical frame volume 
    1859             : 
    1860           1 :     TVirtualMC::GetMC()->Gsvolu("SD9D","TUBS",kRframeMaterial,rFramepar5,5);
    1861           1 :     TVirtualMC::GetMC()->Gsvolu("SD0D","TUBS",kRframeMaterial,rFramepar5,5);
    1862             : 
    1863             :     // create the horizontal frame volume 
    1864             : 
    1865           1 :     TVirtualMC::GetMC()->Gsvolu("S09H","BOX",kHframeMaterial,hFramepar,3);
    1866           1 :     TVirtualMC::GetMC()->Gsvolu("SD9H","BOX",kHframeMaterial,hFramepar,3);
    1867           1 :     TVirtualMC::GetMC()->Gsvolu("S10H","BOX",kHframeMaterial,hFramepar,3);
    1868           1 :     TVirtualMC::GetMC()->Gsvolu("SD0H","BOX",kHframeMaterial,hFramepar,3);
    1869             : 
    1870             :     // create the horizontal border volume 
    1871             : 
    1872           1 :     TVirtualMC::GetMC()->Gsvolu("S09B","BOX",kBframeMaterial,bFramepar,3);
    1873           1 :     TVirtualMC::GetMC()->Gsvolu("SD9B","BOX",kBframeMaterial,bFramepar,3);
    1874           1 :     TVirtualMC::GetMC()->Gsvolu("S10B","BOX",kBframeMaterial,bFramepar,3);
    1875           1 :     TVirtualMC::GetMC()->Gsvolu("SD0B","BOX",kBframeMaterial,bFramepar,3);
    1876             : 
    1877             :     // Replace the volume shape with a composite shape
    1878             :     // with substracted overlap with beam shield     
    1879           1 :     if ( TVirtualMC::GetMC()->IsRootGeometrySupported() ) { 
    1880             :         
    1881             :       // Get shape
    1882             :       Int_t nSlatType = 1;
    1883             :       Int_t nVol = 8;
    1884             :       const char* slatType = "D"; // D: Rounde slat
    1885             :       const char* volLetter = "CNXIPHBG";
    1886           1 :       TString volName;
    1887           1 :       TString compName;
    1888           1 :       TString csName;
    1889             :       TGeoVolume *mVol = 0x0;
    1890             :       // Beam shield recess
    1891           3 :       new TGeoTube("tube5Cut", 0., AliMUONConstants::Rmin(4), kSlatWidth/2.+0.001);
    1892           1 :       TObjArray rounded5Slat(nSlatType*((nVol+1)*2));   
    1893             :       // Displacement
    1894           2 :       TGeoTranslation* trDTube5 = new TGeoTranslation("trDTube5", -(kPcbLength+kVframeLength)/2., -kYpos5[1], 0.);
    1895           1 :       trDTube5->RegisterYourself();
    1896           2 :       TGeoTranslation* trDBTube5 = new TGeoTranslation("trDBTube5", 0., ( kPcbHeight - kBframeHeight ) / 2., 0.);
    1897           1 :       trDBTube5->Add(trDTube5);
    1898           1 :       trDBTube5->RegisterYourself();
    1899             : 
    1900           1 :       TObjArray composite5(nSlatType*((nVol+1)*2));
    1901           2 :       new TGeoBBox("box5DCut",(kPcbLength+kVframeLength)/2., hFramepar[1], vFramepar[2]+0.001);
    1902             :       // Displacement
    1903           2 :       TGeoTranslation* trDBox5 = new TGeoTranslation("trDBox5",kPcbLength/2., kYpos5[1], 0.);
    1904           1 :       trDBox5->RegisterYourself();
    1905             :       
    1906           2 :       TGeoBBox *box5Vframe = new TGeoBBox("box5Vframe",vFramepar[0],vrFrameHeight/2., vFramepar[2]);
    1907           4 :       TGeoTranslation* trVBox5 = new TGeoTranslation("trVBox5", 0., AliMUONConstants::Rmin(4)-kRframeLength + box5Vframe->GetDY(), 0.);
    1908           1 :       trVBox5->RegisterYourself();
    1909             :       
    1910           6 :       for(int iCh=9; iCh<=10; iCh++){
    1911           8 :         for (int iSlatType = 0; iSlatType<nSlatType; iSlatType++) {
    1912          36 :           for (int iVol = 0; iVol<nVol; iVol++){
    1913          16 :             Int_t lIndex = (iCh-9)*(nSlatType*(nVol+1))+iSlatType*(nVol+1)+iVol;
    1914          32 :             volName=Form("S%c%d%c",slatType[iSlatType],iCh%10,volLetter[iVol]);
    1915          32 :             mVol = gGeoManager->FindVolumeFast(volName);
    1916          16 :             if ( !mVol ) {
    1917           0 :               AliErrorStream() 
    1918           0 :                 << "Slat volume " << volName << " not found" << endl;        
    1919             :             }
    1920             :             else {
    1921          32 :               rounded5Slat[lIndex] = mVol->GetShape();
    1922          32 :               csName=Form("rounded5Slat%c%d%c",slatType[iSlatType],iCh%10,volLetter[iVol]);
    1923          48 :               ((TGeoShape*)rounded5Slat[lIndex])->SetName(csName);  
    1924             :               
    1925             :               // Composite shape
    1926          16 :               TString compOperation(csName);
    1927          16 :               compOperation+="-tube5Cut:tr";
    1928          16 :               compOperation+=slatType[iSlatType];
    1929          48 :               if (strstr(volName,"B")){
    1930           2 :                 compOperation+="B";
    1931             :               }
    1932          16 :               compOperation+="Tube5";
    1933          32 :               compName=Form("composite5%c%d%c",slatType[iSlatType],iCh,volLetter[iVol]);
    1934          96 :               composite5[lIndex] = new TGeoCompositeShape(compName, compOperation.Data()); 
    1935             :               
    1936             :               // Reset shape to volume      
    1937          32 :               mVol->SetShape((TGeoShape*)composite5[lIndex]);
    1938          16 :             }
    1939             :           }
    1940             : 
    1941             :           // For rounded spacer
    1942           2 :           Int_t lIndex = (iCh-9)*(nSlatType*(nVol+1))+iSlatType*(nVol+1)+nVol;
    1943           4 :           volName=Form("S%c%dD",slatType[iSlatType],iCh%10);
    1944           4 :           mVol = gGeoManager->FindVolumeFast(volName);
    1945           2 :           if ( !mVol ) {
    1946           0 :             AliErrorStream() 
    1947           0 :               << "Slat volume " << volName << " not found" << endl;  
    1948             :           }
    1949             :           else {
    1950           4 :             rounded5Slat[lIndex] = mVol->GetShape();
    1951           4 :             csName=Form("rounded5Slat%c%dD",slatType[iSlatType],iCh%10);
    1952           6 :             ((TGeoShape*)rounded5Slat[lIndex])->SetName(csName);               
    1953             :             
    1954             :             // Composite shape
    1955           2 :             TString compOperation(csName);
    1956           6 :             if (strstr(volName,"SD")){
    1957           2 :               compOperation.Prepend("(");
    1958           2 :               compOperation+="+box5Vframe:trVBox5)*box5DCut:trDBox5";
    1959             :             }
    1960           4 :             compName=Form("composite5%c%dD",slatType[iSlatType],iCh%10);
    1961          12 :             composite5[lIndex] = new TGeoCompositeShape(compName, compOperation.Data());              
    1962             :             // Reset shape to volume      
    1963           4 :             mVol->SetShape((TGeoShape*)composite5[lIndex]);
    1964           2 :           }
    1965             :         }
    1966             :       }
    1967           1 :     }
    1968             :     
    1969             :     index = 0; 
    1970          16 :     for (i = 0; i < kNslats5; i++){
    1971          70 :       for (Int_t quadrant = 1; quadrant <= 4; quadrant++) {
    1972             : 
    1973          28 :         if (i == 0 && quadrant == 2) continue;
    1974          27 :         if (i == 0 && quadrant == 4) continue;
    1975             : 
    1976          26 :         sprintf(idSlatCh9,"SLE%d",ConvertSlatNum(i,quadrant,kNslats5-1));
    1977          26 :         sprintf(idSlatCh10,"SLF%d",ConvertSlatNum(i,quadrant,kNslats5-1));
    1978          52 :         Int_t moduleSlatCh9 = GetModuleId(idSlatCh9);
    1979          52 :         Int_t moduleSlatCh10 = GetModuleId(idSlatCh10);
    1980          26 :         Float_t xvFrame  = (slatLength5[i] - kVframeLength)/2.; // ok
    1981             : 
    1982             :         // position the vertical frames (spacers)
    1983          52 :         if (i != 1) { 
    1984         114 :           GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("S09V", idSlatCh9, (2*i+1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
    1985          88 :           GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("S09V", idSlatCh9, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
    1986          88 :           GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("S10V", idSlatCh10, (2*i+1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
    1987          88 :           GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("S10V", idSlatCh10, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
    1988          22 :         } else {  // Vertical and Rounded+Vertical spacer - Different rotation due to new mapping convention
    1989          20 :           GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("S09V", idSlatCh9, (2*i+1)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
    1990          20 :           GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("SD9D", idSlatCh9, (2*i)*10+quadrant,TGeoTranslation(xvFrame,-kYpos5[1],0.),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
    1991          20 :           GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("S10V", idSlatCh10, (2*i+1)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
    1992          20 :           GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("SD0D", idSlatCh10, (2*i)*10+quadrant,TGeoTranslation(xvFrame,-kYpos5[1],0.),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
    1993             :         }
    1994             : 
    1995             :         // position the panels and the insulating material 
    1996         312 :         for (j = 0; j < kNPCB5[i]; j++){
    1997         130 :           index++;
    1998         130 :           xx = kSensLength * (-kNPCB5[i]/2.+j+.5); 
    1999             : 
    2000         130 :           Float_t zPanel = spar[2] - nomexbpar[2]; 
    2001         130 :           if (i==1) { // Different rotation due to new mapping convention
    2002          48 :             if (j==0) { // Rounded pcb of rounded slat 
    2003          44 :             GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("SD9X", idSlatCh9, 2*index-1,TGeoTranslation(-xx,0.,zPanel),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
    2004          20 :             GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("SD9X", idSlatCh9, 2*index,TGeoTranslation(-xx,0.,-zPanel),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
    2005          20 :             GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("SD9I", idSlatCh9, index,TGeoTranslation(-xx,0.,0.),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
    2006          20 :             GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("SD0X", idSlatCh10, 2*index-1,TGeoTranslation(-xx,0.,zPanel),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
    2007          20 :             GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("SD0X", idSlatCh10, 2*index,TGeoTranslation(-xx,0.,-zPanel),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
    2008          20 :             GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("SD0I", idSlatCh10, index,TGeoTranslation(-xx,0.,0.),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
    2009           4 :             } else { 
    2010         100 :               GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("S09X", idSlatCh9, 2*index-1,TGeoTranslation(-xx,0.,zPanel),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
    2011         100 :               GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("S09X", idSlatCh9, 2*index,TGeoTranslation(-xx,0.,-zPanel),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
    2012         100 :               GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("S09I", idSlatCh9, index,TGeoTranslation(-xx,0.,0.),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));        
    2013         100 :               GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("S10X", idSlatCh10, 2*index-1,TGeoTranslation(-xx,0.,zPanel),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
    2014         100 :               GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("S10X", idSlatCh10, 2*index,TGeoTranslation(-xx,0.,-zPanel),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
    2015         100 :               GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("S10I", idSlatCh10, index,TGeoTranslation(-xx,0.,0.),TGeoRotation("rotAbX",90,180+angle,90,90+angle,180,0));
    2016             :             }
    2017             :           } else { 
    2018         424 :             GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("S09X", idSlatCh9, 2*index-1,TGeoTranslation(xx,0.,zPanel));
    2019         424 :             GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("S09X", idSlatCh9, 2*index,TGeoTranslation(xx,0.,-zPanel));
    2020         424 :             GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("S09I", idSlatCh9, index,TGeoTranslation(xx,0.,0.));           
    2021         424 :             GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("S10X", idSlatCh10, 2*index-1,TGeoTranslation(xx,0.,zPanel));
    2022         424 :             GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("S10X", idSlatCh10, 2*index,TGeoTranslation(xx,0.,-zPanel));
    2023         424 :             GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("S10I", idSlatCh10, index,TGeoTranslation(xx,0.,0.));
    2024             :           }
    2025             :         } 
    2026          26 :       }
    2027             :     }
    2028             : 
    2029             :     // position the nomex volume inside the panel volume
    2030           1 :     TVirtualMC::GetMC()->Gspos("S09N",1,"S09C",0.,0.,0.,0,"ONLY"); 
    2031           1 :     TVirtualMC::GetMC()->Gspos("SD9N",1,"SD9C",0.,0.,0.,0,"ONLY"); 
    2032           1 :     TVirtualMC::GetMC()->Gspos("S10N",1,"S10C",0.,0.,0.,0,"ONLY"); 
    2033           1 :     TVirtualMC::GetMC()->Gspos("SD0N",1,"SD0C",0.,0.,0.,0,"ONLY"); 
    2034             : 
    2035             :     // position panel  volume inside the bulk nomex material volume
    2036           1 :     TVirtualMC::GetMC()->Gspos("S09C",1,"S09X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
    2037           1 :     TVirtualMC::GetMC()->Gspos("SD9C",1,"SD9X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
    2038           1 :     TVirtualMC::GetMC()->Gspos("S10C",1,"S10X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
    2039           1 :     TVirtualMC::GetMC()->Gspos("SD0C",1,"SD0X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
    2040             : 
    2041             :     // position the PCB volume inside the insulating material volume
    2042           1 :     TVirtualMC::GetMC()->Gspos("S09P",1,"S09I",0.,0.,0.,0,"ONLY"); 
    2043           1 :     TVirtualMC::GetMC()->Gspos("SD9P",1,"SD9I",0.,0.,0.,0,"ONLY"); 
    2044           1 :     TVirtualMC::GetMC()->Gspos("S10P",1,"S10I",0.,0.,0.,0,"ONLY"); 
    2045           1 :     TVirtualMC::GetMC()->Gspos("SD0P",1,"SD0I",0.,0.,0.,0,"ONLY"); 
    2046             : 
    2047             :     // position the horizontal frame volume inside the PCB volume
    2048           1 :     TVirtualMC::GetMC()->Gspos("S09H",1,"S09P",0.,0.,0.,0,"ONLY"); 
    2049           1 :     TVirtualMC::GetMC()->Gspos("SD9H",1,"SD9P",0.,0.,0.,0,"ONLY"); 
    2050           1 :     TVirtualMC::GetMC()->Gspos("S10H",1,"S10P",0.,0.,0.,0,"ONLY"); 
    2051           1 :     TVirtualMC::GetMC()->Gspos("SD0H",1,"SD0P",0.,0.,0.,0,"ONLY"); 
    2052             : 
    2053             :     // position the sensitive volume inside the horizontal frame volume
    2054           1 :     TVirtualMC::GetMC()->Gsposp("S09G",1,"S09H",0.,0.,0.,0,"ONLY",senspar,3); 
    2055           1 :     TVirtualMC::GetMC()->Gspos("SD9G",1,"SD9H",0.,0.,0.,0,"ONLY"); 
    2056           1 :     TVirtualMC::GetMC()->Gsposp("S10G",1,"S10H",0.,0.,0.,0,"ONLY",senspar,3); 
    2057           1 :     TVirtualMC::GetMC()->Gspos("SD0G",1,"SD0H",0.,0.,0.,0,"ONLY"); 
    2058             : 
    2059             :     // position the border volumes inside the PCB volume
    2060             :     Float_t yborder = ( kPcbHeight - kBframeHeight ) / 2.; 
    2061           1 :     TVirtualMC::GetMC()->Gspos("S09B",1,"S09P",0., yborder,0.,0,"ONLY"); 
    2062           1 :     TVirtualMC::GetMC()->Gspos("S09B",2,"S09P",0.,-yborder,0.,0,"ONLY"); 
    2063           1 :     TVirtualMC::GetMC()->Gspos("S09B",1,"SD9P",0., yborder,0.,0,"ONLY"); 
    2064           1 :     TVirtualMC::GetMC()->Gspos("SD9B",1,"SD9P",0.,-yborder,0.,0,"ONLY"); 
    2065           1 :     TVirtualMC::GetMC()->Gspos("S10B",1,"S10P",0., yborder,0.,0,"ONLY"); 
    2066           1 :     TVirtualMC::GetMC()->Gspos("S10B",2,"S10P",0.,-yborder,0.,0,"ONLY"); 
    2067           1 :     TVirtualMC::GetMC()->Gspos("S10B",1,"SD0P",0., yborder,0.,0,"ONLY"); 
    2068           1 :     TVirtualMC::GetMC()->Gspos("SD0B",1,"SD0P",0.,-yborder,0.,0,"ONLY"); 
    2069             : 
    2070             :     //      // create the NULOC volume and position it in the horizontal frame
    2071             : 
    2072           1 :     TVirtualMC::GetMC()->Gsvolu("S09E","BOX",kNulocMaterial,nulocpar,3);
    2073           1 :     TVirtualMC::GetMC()->Gsvolu("S10E","BOX",kNulocMaterial,nulocpar,3);
    2074             :     index = 0;
    2075           1 :     Float_t rPhi3 = TMath::ASin((kYpos5[1]-kPcbHeight/2.)/AliMUONConstants::Rmin(4));
    2076           1 :     Float_t xxmax4 = (AliMUONConstants::Rmin(4)*TMath::Cos(rPhi3)-kVframeLength/2.) - (kBframeLength - kNulocLength)/2.;
    2077          18 :     for (xx = -xxmax; xx <= xxmax; xx += 2*kNulocLength) { 
    2078           8 :       index++; 
    2079           8 :       TVirtualMC::GetMC()->Gspos("S09E",2*index-1,"S09B", xx, 0.,-kBframeWidth/2. + kNulocWidth/2, 0, "ONLY");
    2080           8 :       TVirtualMC::GetMC()->Gspos("S09E",2*index  ,"S09B", xx, 0., kBframeWidth/2. - kNulocWidth/2, 0, "ONLY");
    2081           8 :       TVirtualMC::GetMC()->Gspos("S10E",2*index-1,"S10B", xx, 0.,-kBframeWidth/2. + kNulocWidth/2, 0, "ONLY");
    2082           8 :       TVirtualMC::GetMC()->Gspos("S10E",2*index  ,"S10B", xx, 0., kBframeWidth/2. - kNulocWidth/2, 0, "ONLY");
    2083             :     }
    2084           2 :     if (xx > xxmax4 && xx< xxmax) {
    2085           0 :       TVirtualMC::GetMC()->Gspos("S09E",2*index-1,"SD9B", xx, 0.,-kBframeWidth/2.+ kNulocWidth/2, 0, "ONLY");
    2086           0 :       TVirtualMC::GetMC()->Gspos("S09E",2*index  ,"SD9B", xx, 0., kBframeWidth/2.- kNulocWidth/2, 0, "ONLY");
    2087           0 :       TVirtualMC::GetMC()->Gspos("S10E",2*index-1,"SD0B", xx, 0.,-kBframeWidth/2.+ kNulocWidth/2, 0, "ONLY");
    2088           0 :       TVirtualMC::GetMC()->Gspos("S10E",2*index  ,"SD0B", xx, 0., kBframeWidth/2.- kNulocWidth/2, 0, "ONLY");
    2089           0 :     }
    2090             : 
    2091             :     //    
    2092             :     //Geometry of the support pannel Verticla length 5.7m, horizontal length 2.6m, internal radius  dMotherInner o SC09 and SC10  (F. Orsini, Saclay)
    2093             :     //Carbon fiber of 0.3 mm thick (2 layers) and a central layer of Nomex of 15mm thick. 
    2094           1 :     Float_t dMotherInner =  AliMUONConstants::Rmin(4)-kRframeHeight; 
    2095             :     Float_t nomexthickness = 1.5;
    2096             :     Float_t carbonthickness = 0.03;
    2097             :     Float_t supporthlength =  260.;  
    2098             :     Float_t supportvlength =  570.;  
    2099             :     // Generating the composite shape of the carbon and nomex pannels
    2100           1 :     new TGeoBBox("shNomexBoxSt5",supporthlength/2., supportvlength/2. ,nomexthickness/2.+carbonthickness+3*kCableWidth);
    2101           1 :     new TGeoBBox("shCarbonBoxSt5",supporthlength/2., supportvlength/2. ,carbonthickness/2.); 
    2102           1 :     new TGeoTubeSeg("shNomexHoleSt5",0., dMotherInner, nomexthickness/2.+carbonthickness+3*kCableWidth+0.001, -90. ,90.);
    2103           1 :     new TGeoTubeSeg("shCarbonHoleSt5",0., dMotherInner, carbonthickness/2.+0.001, -90. ,90.);
    2104           1 :     TGeoTranslation* trHoleSt5 = new TGeoTranslation("trHoleSt5",-supporthlength/2.,0.,0.); 
    2105           1 :     trHoleSt5->RegisterYourself();
    2106           1 :     TGeoCompositeShape* shNomexSupportSt5  = new TGeoCompositeShape("shNomexSupportSt5","shNomexBoxSt5-shNomexHoleSt5:trHoleSt5");
    2107           1 :     TGeoCompositeShape* shCarbonSupportSt5 = new TGeoCompositeShape("shCarbonSupportSt5","shCarbonBoxSt5-shCarbonHoleSt5:trHoleSt5");
    2108             : 
    2109             :    // Generating Nomex and Carbon pannel volumes
    2110           1 :     TGeoVolume* voNomexSupportSt5  = new TGeoVolume("S09S", shNomexSupportSt5, kMedNomex);
    2111           1 :     TGeoVolume* voCarbonSupportSt5 = new TGeoVolume("S09K", shCarbonSupportSt5, kMedCarbon);
    2112           1 :     TGeoTranslation* trCarbon1St5   = new TGeoTranslation("trCarbon1St5",0.,0., -(nomexthickness+carbonthickness)/2.);
    2113           1 :     TGeoTranslation* trCarbon2St5   = new TGeoTranslation("trCarbon2St5",0.,0.,  (nomexthickness+carbonthickness)/2.);
    2114           1 :     voNomexSupportSt5->AddNode(voCarbonSupportSt5,1,trCarbon1St5);
    2115           1 :     voNomexSupportSt5->AddNode(voCarbonSupportSt5,2,trCarbon2St5);
    2116             : 
    2117             :     // Add readout cables
    2118           1 :     TVirtualMC::GetMC()->Gsvolu("S09L","BOX",kCableMaterial,dum,0);
    2119             : 
    2120             :     ySlat5 = 0.;
    2121             :     Float_t lCableX = 0.;
    2122             :     Float_t lCableY = 0.;
    2123             :     Float_t lCableZ = 0.;
    2124           1 :     Float_t cablepar[3] = {static_cast<Float_t>(supporthlength/2.), static_cast<Float_t>(kCableHeight/2.), static_cast<Float_t>(kCableWidth/2.)};
    2125             :     Float_t lCableDY = 0.;
    2126          16 :     for (i = 0; i<kNslats5; i++){
    2127             :       Int_t iCable = 1;
    2128             :       Int_t cIndex = 0;
    2129           7 :       ySlat5 += kYpos5[i];
    2130             : 
    2131             :       lCableY = ySlat5;
    2132             : 
    2133             :       // Cables going out from the start of slat
    2134           7 :       if(kNPCB5[i]>=4){ // Only if 4 or more pcb
    2135             :         // First top cables
    2136           6 :         cablepar[0] = (supporthlength-kXpos5[i])/2.;
    2137           6 :         lCableX = kXpos5[i]/2.;
    2138          12 :         if(i+1>=kNslats5 || i+2>=kNslats5){ // If no more higher slats, then use distance to lower slat
    2139           1 :           lCableDY = (kYpos5[i]+kYpos5[i-1])/2.-cablepar[1];
    2140           1 :         }
    2141             :         else {
    2142           5 :           lCableDY = (kYpos5[i+1]+kYpos5[i+2])/2.-cablepar[1];
    2143             :         }
    2144           6 :         lCableZ = TMath::Power(-1,i)*(nomexthickness/2.+carbonthickness+(-1+iCable++)*kCableWidth+kCableWidth/2.);
    2145           6 :         TVirtualMC::GetMC()->Gsposp("S09L",10*i+cIndex++,"S09S",lCableX,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar,3);         
    2146           6 :         TVirtualMC::GetMC()->Gsposp("S09L",10*i+cIndex++,"S09S",lCableX,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar,3);
    2147             :         // Then bottom cables
    2148           6 :         if (i>0) {
    2149           5 :           if (i==1) { // Rounded slat. Bottom cable starts at dMotherInner (beam pipe)
    2150           1 :             cablepar[0] = (supporthlength-kXpos5[i]-dMotherInner)/2.;
    2151           1 :             lCableX = (kXpos5[i]+dMotherInner)/2.;
    2152           1 :             lCableDY = (kYpos5[i]+kYpos5[i])/2.-cablepar[1];
    2153           1 :           }
    2154             :           else {
    2155           4 :             lCableDY = (kYpos5[i]+kYpos5[i-1])/2.-cablepar[1];
    2156           4 :             if ((lCableY-lCableDY)<(dMotherInner+cablepar[1])){
    2157           0 :               lCableDY = lCableY - dMotherInner - cablepar[1];
    2158           0 :             }
    2159             :           }
    2160           5 :           TVirtualMC::GetMC()->Gsposp("S09L",10*i+cIndex++,"S09S",lCableX,lCableY-lCableDY,lCableZ,0,"ONLY",cablepar,3); 
    2161           5 :           TVirtualMC::GetMC()->Gsposp("S09L",10*i+cIndex++,"S09S",lCableX,-(lCableY-lCableDY),lCableZ,0,"ONLY",cablepar,3); 
    2162           5 :         }
    2163             :       }
    2164             :       
    2165             :       // Rounded slats have an extra cable starting at second pcb
    2166           7 :       if(i==1){ 
    2167             :         // Only on top
    2168           1 :         cablepar[0] = (supporthlength-kPcbLength-kVframeLength)/2.;
    2169             :         lCableX = (kPcbLength+kVframeLength)/2.;
    2170           1 :         lCableDY = (kYpos5[i+1]+kYpos5[i+2])/2.-cablepar[1]; // half way between 2 slats on same side
    2171           1 :         lCableZ = TMath::Power(-1,i)*(nomexthickness/2.+carbonthickness+(-1+iCable++)*kCableWidth+kCableWidth/2.);
    2172           1 :         TVirtualMC::GetMC()->Gsposp("S09L",10*i+cIndex++,"S09S",lCableX,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar,3); 
    2173           1 :         TVirtualMC::GetMC()->Gsposp("S09L",10*i+cIndex++,"S09S",lCableX,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar,3); 
    2174           1 :       } 
    2175             : 
    2176             :       // Cables going out from the end of the slats
    2177             :       // First top cables
    2178           7 :       cablepar[0] = (supporthlength-(slatLength5[i]+kXpos5[i]+kDslatLength)+kVframeLength)/2.;
    2179           7 :       lCableX = slatLength5[i]+kXpos5[i]-kVframeLength+kDslatLength+cablepar[0]-supporthlength/2.;
    2180          13 :       if(i+1>=kNslats5 || i+2>=kNslats5){ // If no more higher slats, then use distance to lower slat
    2181           2 :         lCableDY = (kYpos5[i]+kYpos5[i-1])/2.-cablepar[1];
    2182           2 :       }
    2183             :       else {
    2184           5 :         lCableDY = (kYpos5[i+1]+kYpos5[i+2])/2.-cablepar[1];
    2185             :       }
    2186           7 :       lCableZ = TMath::Power(-1,i)*(nomexthickness/2.+carbonthickness+(-1+iCable++)*kCableWidth+kCableWidth/2.);        
    2187           7 :       TVirtualMC::GetMC()->Gsposp("S09L",10*i+cIndex++,"S09S",lCableX,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar,3); 
    2188           7 :       TVirtualMC::GetMC()->Gsposp("S09L",10*i+cIndex++,"S09S",lCableX,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar,3); 
    2189           7 :       if(i>0){
    2190           6 :         if (i==1) { // Rounded slat. Bottom cable starts at dMotherInner (beam pipe)
    2191           7 :           lCableDY = (kYpos5[i]+kYpos5[i])/2.-cablepar[1];
    2192           1 :         }
    2193             :         else {
    2194           5 :           lCableDY = (kYpos5[i]+kYpos5[i-1])/2.-cablepar[1];
    2195           5 :           if ((lCableY-lCableDY)<(dMotherInner+cablepar[1])){
    2196           0 :               lCableDY = lCableY - dMotherInner - cablepar[1];
    2197           0 :           }
    2198             :         }
    2199           6 :         TVirtualMC::GetMC()->Gsposp("S09L",10*i+cIndex++,"S09S",lCableX,lCableY-lCableDY,lCableZ,0,"ONLY",cablepar,3); 
    2200           6 :         TVirtualMC::GetMC()->Gsposp("S09L",10*i+cIndex++,"S09S",lCableX,-(lCableY-lCableDY),lCableZ,0,"ONLY",cablepar,3); 
    2201           6 :       }
    2202             :     }
    2203             : 
    2204             :     Float_t dzCh9  = dzCh;
    2205           1 :     TGeoTranslation* trSupport1St5   = new TGeoTranslation("trSupport1St5", supporthlength/2., 0. , dzCh9);
    2206           1 :     TGeoRotation*    roSupportSt5    = new TGeoRotation("roSupportSt5",90.,180.,-90.);
    2207           1 :     TGeoCombiTrans*  coSupport2St5   = new TGeoCombiTrans(-supporthlength/2., 0., -dzCh9, roSupportSt5);
    2208           2 :     GetEnvelopes(13)->AddEnvelope("S09S", 0, 1, *trSupport1St5);  
    2209           2 :     GetEnvelopes(12)->AddEnvelope("S09S", 0, 2, *coSupport2St5);  
    2210           2 :     GetEnvelopes(15)->AddEnvelope("S09S", 0, 3, *trSupport1St5);   
    2211           2 :     GetEnvelopes(14)->AddEnvelope("S09S", 0, 4, *coSupport2St5);
    2212             : 
    2213             : 
    2214             :     // End of pannel support geometry    
    2215             : 
    2216             :     // cout << "Geometry for Station 5...... done" << endl;
    2217             : 
    2218           1 :   }
    2219             : 
    2220           2 :   delete [] fStations;
    2221             : 
    2222           1 : }
    2223             : 
    2224             : //______________________________________________________________________________
    2225             : void AliMUONSlatGeometryBuilder::SetVolumes()
    2226             : {
    2227             : /// Defines the volumes for the station345 chambers.
    2228             : 
    2229           2 :   if (gAlice->GetModule("DIPO")) {
    2230             :     // if DIPO is preset, the whole station will be placed in DDIP volume
    2231           2 :     SetMotherVolume(4, "DDIP");
    2232           2 :     SetMotherVolume(5, "DDIP");
    2233           2 :     SetMotherVolume(6, "DDIP");
    2234           2 :     SetMotherVolume(7, "DDIP");
    2235           1 :   }     
    2236           2 :   SetVolume(4, "SC05I", true);
    2237           2 :   SetVolume(5, "SC05O", true);
    2238           2 :   SetVolume(6, "SC06I", true);
    2239           2 :   SetVolume(7, "SC06O", true);
    2240             :      
    2241           1 :   if (gAlice->GetModule("SHIL")) {
    2242           2 :     SetMotherVolume(8, "YOUT2");
    2243           2 :     SetMotherVolume(9, "YOUT2");
    2244           2 :     SetMotherVolume(10, "YOUT2");
    2245           2 :     SetMotherVolume(11, "YOUT2");
    2246           2 :     SetMotherVolume(12, "YOUT2");
    2247           2 :     SetMotherVolume(13, "YOUT2");
    2248           2 :     SetMotherVolume(14, "YOUT2");
    2249           2 :     SetMotherVolume(15, "YOUT2");
    2250           1 :   }  
    2251             : 
    2252           2 :   SetVolume( 8, "SC07I", true);
    2253           2 :   SetVolume( 9, "SC07O", true);
    2254           2 :   SetVolume(10, "SC08I", true);
    2255           2 :   SetVolume(11, "SC08O", true);
    2256           2 :   SetVolume(12, "SC09I", true);
    2257           2 :   SetVolume(13, "SC09O", true);
    2258           2 :   SetVolume(14, "SC10I", true);
    2259           2 :   SetVolume(15, "SC10O", true);
    2260           1 : }
    2261             : 
    2262             : 
    2263             : //______________________________________________________________________________
    2264             : void AliMUONSlatGeometryBuilder::SetTransformations()
    2265             : {
    2266             : /// Defines the transformations for the station345 chambers.
    2267             : 
    2268             : // Stations 345 are not perpendicular to the beam axis
    2269             : // See AliMUONConstants class
    2270           2 :   TGeoRotation st345inclination("rot99");
    2271           1 :   st345inclination.RotateX(AliMUONConstants::St345Inclination());
    2272             :   
    2273             : // The rotation of the half-chamber is done with respect the center of the chamber.
    2274             : // the distance beween the roation axis and the chamber position is 
    2275             : // AliMUONConstants::DzCh()+AliMUONConstants::DzSlat()
    2276             : // Therefore the position of the half-chamber has to be corrected by a traslation in Z and Y axis
    2277           2 :   Double_t deltaY = (AliMUONConstants::DzCh()+AliMUONConstants::DzSlat())*
    2278           1 :     TMath::Sin(AliMUONConstants::St345Inclination() * TMath::Pi()/180.);
    2279           2 :   Double_t deltaZ = (AliMUONConstants::DzCh()+AliMUONConstants::DzSlat())*
    2280           1 :     (1.-TMath::Cos(AliMUONConstants::St345Inclination() * TMath::Pi()/180.));
    2281             : 
    2282             : 
    2283           1 :   Double_t zpos1= - AliMUONConstants::DefaultChamberZ(4); 
    2284           3 :   SetTransformation(4, TGeoTranslation(0., -deltaY, -deltaZ+zpos1), st345inclination);
    2285           3 :   SetTransformation(5, TGeoTranslation(0.,  deltaY,  deltaZ+zpos1), st345inclination);
    2286             : 
    2287           1 :   zpos1= - AliMUONConstants::DefaultChamberZ(5); 
    2288           3 :   SetTransformation(6, TGeoTranslation(0., -deltaY, -deltaZ+zpos1), st345inclination);
    2289           3 :   SetTransformation(7, TGeoTranslation(0.,  deltaY,  deltaZ+zpos1), st345inclination);
    2290             : 
    2291           1 :   zpos1 = - AliMUONConstants::DefaultChamberZ(6); 
    2292           3 :   SetTransformation(8, TGeoTranslation(0., -deltaY, -deltaZ+zpos1), st345inclination);
    2293           3 :   SetTransformation(9, TGeoTranslation(0.,  deltaY,  deltaZ+zpos1), st345inclination);
    2294             : 
    2295           1 :   zpos1 = - AliMUONConstants::DefaultChamberZ(7); 
    2296           3 :   SetTransformation(10, TGeoTranslation(0., -deltaY, -deltaZ+zpos1), st345inclination );
    2297           3 :   SetTransformation(11, TGeoTranslation(0.,  deltaY,  deltaZ+zpos1), st345inclination );
    2298             : 
    2299           1 :   zpos1 = - AliMUONConstants::DefaultChamberZ(8); 
    2300           3 :   SetTransformation(12, TGeoTranslation(0., -deltaY, -deltaZ+zpos1), st345inclination);
    2301           3 :   SetTransformation(13, TGeoTranslation(0.,  deltaY,  deltaZ+zpos1), st345inclination);
    2302             : 
    2303           1 :   zpos1 = - AliMUONConstants::DefaultChamberZ(9); 
    2304           3 :   SetTransformation(14, TGeoTranslation(0., -deltaY, -deltaZ+zpos1), st345inclination);
    2305           3 :   SetTransformation(15, TGeoTranslation(0.,  deltaY,  deltaZ+zpos1), st345inclination);
    2306             : 
    2307           1 : }
    2308             : 
    2309             : //______________________________________________________________________________
    2310             : void AliMUONSlatGeometryBuilder::SetSensitiveVolumes()
    2311             : {
    2312             : /// Defines the sensitive volumes for slat stations chambers.
    2313             : 
    2314           3 :   GetGeometry( 4)->SetSensitiveVolume("S05G");
    2315           2 :   GetGeometry( 4)->SetSensitiveVolume("SC5G");
    2316           2 :   GetGeometry( 4)->SetSensitiveVolume("SD5G");
    2317           2 :   GetGeometry( 5)->SetSensitiveVolume("S05G");
    2318           2 :   GetGeometry( 5)->SetSensitiveVolume("SC5G");
    2319           2 :   GetGeometry( 5)->SetSensitiveVolume("SD5G");
    2320           2 :   GetGeometry( 6)->SetSensitiveVolume("S06G");
    2321           2 :   GetGeometry( 6)->SetSensitiveVolume("SC6G");
    2322           2 :   GetGeometry( 6)->SetSensitiveVolume("SD6G");
    2323           2 :   GetGeometry( 7)->SetSensitiveVolume("S06G");
    2324           2 :   GetGeometry( 7)->SetSensitiveVolume("SC6G");
    2325           2 :   GetGeometry( 7)->SetSensitiveVolume("SD6G");
    2326           2 :   GetGeometry( 8)->SetSensitiveVolume("S07G");
    2327           2 :   GetGeometry( 8)->SetSensitiveVolume("SD7G");
    2328           2 :   GetGeometry( 9)->SetSensitiveVolume("S07G");
    2329           2 :   GetGeometry( 9)->SetSensitiveVolume("SD7G");
    2330           2 :   GetGeometry(10)->SetSensitiveVolume("S08G");
    2331           2 :   GetGeometry(10)->SetSensitiveVolume("SD8G");
    2332           2 :   GetGeometry(11)->SetSensitiveVolume("S08G");
    2333           2 :   GetGeometry(11)->SetSensitiveVolume("SD8G");
    2334           2 :   GetGeometry(12)->SetSensitiveVolume("S09G");
    2335           2 :   GetGeometry(12)->SetSensitiveVolume("SD9G");
    2336           2 :   GetGeometry(13)->SetSensitiveVolume("S09G");
    2337           2 :   GetGeometry(13)->SetSensitiveVolume("SD9G");
    2338           2 :   GetGeometry(14)->SetSensitiveVolume("S10G");
    2339           2 :   GetGeometry(14)->SetSensitiveVolume("SD0G");
    2340           2 :   GetGeometry(15)->SetSensitiveVolume("S10G");
    2341           2 :   GetGeometry(15)->SetSensitiveVolume("SD0G");
    2342           1 : }
    2343             : 
    2344             : //______________________________________________________________________________
    2345             : Int_t  AliMUONSlatGeometryBuilder::ConvertSlatNum(Int_t numslat, Int_t quadnum, Int_t fspq) const
    2346             : {
    2347             : /// On-line function establishing the correspondance between numslat (the slat number on a particular quadrant (numslat->0....4 for St3))
    2348             : /// and slatnum (the slat number on the whole panel (slatnum->1...18 for St3)
    2349         280 :   numslat += 1;
    2350         140 :   if (quadnum==2 || quadnum==3) 
    2351          70 :     numslat += fspq;
    2352             :   else
    2353          70 :     numslat = fspq + 2-numslat;
    2354         140 :   numslat -= 1;
    2355             :               
    2356         210 :   if (quadnum==3 || quadnum==4) numslat += 2*fspq+1;
    2357             : 
    2358         140 :   return numslat;
    2359             : }

Generated by: LCOV version 1.11