]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSv11GeometrySPD.cxx
Eliminated hardwired names. The layed detector type ID is stored in TGeo and can
[u/mrichter/AliRoot.git] / ITS / AliITSv11GeometrySPD.cxx
1 /**************************************************************************
2  * Copyright(c) 2007-2009, 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 // This class Defines the Geometry for the ITS services and support cones
17 // outside of the central volume (except for the Central support
18 // cylinders). Other classes define the rest of the ITS, specifically the
19 // SSD support cone, the SSD Support central cylinder, the SDD support cone,
20 // the SDD support central cylinder, the SPD Thermal Shield, The supports
21 // and cable trays on both the RB26 (muon dump) and RB24 sides, and all of
22 // the cabling from the ladders/stave ends out past the TPC.
23 //
24 //     Here is the calling sequence associated with this file
25 //   SPDSector(TGeoVolume *moth,TGeoManager *mgr)
26 //   -----CarbonFiberSector(TGeoVolume *moth,Double_t &xAAtubeCenter0,
27 //                          Double_t &yAAtubeCenter0,TGeoManager *mgr)
28 //        -----2* SPDsectorShape(Int_t n,const Double_t *xc,const Double_t *yc,
29 //        |                      const Double_t *r,const Double_t *ths,
30 //        |                      const Double_t *the,Int_t npr,Int_t &m,
31 //        |                      Double_t **xp,Double_t **yp)
32 //        -----StavesInSector(TGeoVolume *moth,TGeoManager *mgr)
33 //             -----3* CreaeStave(Int_t layer,TArrayD &sizes,Bool_t addClips,
34 //             |                  TGeoManager *mgr)
35 //             |    -----2* CreateHalfStave(Boot_t isRight,Int_t layer,
36 //             |                            Int_t idxCentral,Int_t idxSide,
37 //             |                            TArrayD &sizes,Bool_t addClips,
38 //             |                            TGeoManager *mgr)
39 //             |         -----CreateGrondingFoil(Bool_t isRight,TArrayD &sizes,
40 //             |         |                       TGeoManager *mgr)
41 //             |         |    -----4* CreateGroundingFoilSingle(Int_t type,
42 //             |         |                                     TArrayD &sizes,
43 //             |         |                                     TGeoManger *mgr)
44 //             |         |----CreateLadder(Int_t layer, TArrayD &sizes,
45 //             |         |                 TGeoManager *mgr)
46 //             |         |----CreateMCM(Bool_t isRight,TArrayD &sizes,
47 //             |         |              TGeoManger *mgr)
48 //             |         |----CreatePixelBus(Bool_t isRight,TArrayD &sizes,
49 //             |         |                   TGeoManager *mgr)
50 //             |         -----CreateClip(TArrayD &sizes,TGeoManager *mgr)
51 //             |----GetSectorMountingPoints(Int_t index,Double_t &x0,
52 //             |                            Double_t &y0,Double_t &x1,
53 //             |                            Double_t y1)
54 //             -----3* ParallelPosition(Double_t dist1,Double_t dist2,
55 //                                      Double_t phi,Double_t &x,Double_t &y)
56 //
57 //     Obsoleate or presently unused routines are: setAddStave(Bool_t *mask),
58 // CreatePixelBusAndExtensions(...) which calles CreateExtender(...).
59
60 /* $Id$ */
61
62
63 // General Root includes
64 #include <Riostream.h>
65 #include <TMath.h>
66 #include <TLatex.h>
67 #include <TCanvas.h>
68 #include <TPolyLine.h>
69 #include <TPolyMarker.h>
70
71 // Root Geometry includes
72 #include <TGeoCompositeShape.h>
73 #include <TGeoEltu.h>
74 #include <TGeoGlobalMagField.h>
75 #include <TGeoMaterial.h>
76 #include <TGeoMatrix.h>
77 #include <TGeoMedium.h>
78 #include <TGeoTube.h> // contains TGeoTubeSeg
79 #include <TGeoVolume.h>
80 #include <TGeoXtru.h>
81 #include <TGeoPcon.h>
82
83 // AliRoot includes
84 #include "AliLog.h"
85 #include "AliMagF.h"
86 #include "AliRun.h"
87
88 // Declaration file
89 #include "AliITSv11GeometrySPD.h"
90
91 // Constant definistions
92 const Double_t AliITSv11GeometrySPD::fgkGapLadder    =
93                       AliITSv11Geometry::fgkmicron*75.; //  75 microns
94 const Double_t AliITSv11GeometrySPD::fgkGapHalfStave =
95                      AliITSv11Geometry::fgkmicron*120.; // 120 microns
96
97 using std::endl;
98 using std::cout;
99 using std::ios;
100 ClassImp(AliITSv11GeometrySPD)
101 //______________________________________________________________________
102 AliITSv11GeometrySPD::AliITSv11GeometrySPD(/*Double_t gap*/):
103 AliITSv11Geometry(),// Default constructor of base class
104 fAddStave(),        // [DEBUG] must be TRUE for all staves which will be
105                     // mounted in the sector (used to check overlaps)
106 fSPDsectorX0(0),    // X of first edge of sector plane for stave
107 fSPDsectorY0(0),    // Y of first edge of sector plane for stave
108 fSPDsectorX1(0),    // X of second edge of sector plane for stave
109 fSPDsectorY1(0),    // Y of second edge of sector plane for stave
110 fTubeEndSector()    // coordinate of cooling tube ends
111 {
112     //
113     // Default constructor.
114     // This does not initialize anything and is provided just for
115     // completeness. It is recommended to use the other one.
116     // The alignment gap is specified as argument (default = 0.0075 cm).
117     // Inputs:
118     //    none.
119     // Outputs:
120     //    none.
121     // Return:
122     //    A default constructed AliITSv11GeometrySPD class.
123     //
124     Int_t i = 0,j=0,k=0;
125
126     for (i = 0; i < 6; i++) fAddStave[i] = kTRUE;
127     for(k=0;k<10;k++)for(i=0;i<6;i++)for(j=0;j<3;j++){
128         this->fTubeEndSector[k][0][i][j] = 0.0;
129         this->fTubeEndSector[k][1][i][j] = 0.0;
130     } // end for i,j
131 }
132 //______________________________________________________________________
133 AliITSv11GeometrySPD::AliITSv11GeometrySPD(Int_t debug/*, Double_t gap*/):
134 AliITSv11Geometry(debug),// Default constructor of base class
135 fAddStave(),        // [DEBUG] must be TRUE for all staves which will be
136                     // mounted in the sector (used to check overlaps)
137 fSPDsectorX0(0),    // X of first edge of sector plane for stave
138 fSPDsectorY0(0),    // Y of first edge of sector plane for stave
139 fSPDsectorX1(0),    // X of second edge of sector plane for stave
140 fSPDsectorY1(0),    // Y of second edge of sector plane for stave
141 fTubeEndSector()    // coordinate of cooling tube ends
142 {
143     //
144     // Constructor with debug setting argument
145     // This is the constructor which is recommended to be used.
146     // It sets a debug level, and initializes the name of the object.
147     // The alignment gap is specified as argument (default = 0.0075 cm).
148     // Inputs:
149     //    Int_t    debug               Debug level, 0= no debug output.
150     // Outputs:
151     //    none.
152     // Return:
153     //    A default constructed AliITSv11GeometrySPD class.
154     //
155     Int_t i = 0,j=0,k=0;
156
157     for (i = 0; i < 6; i++) fAddStave[i] = kTRUE;
158     for(k=0;k<10;k++)for(i=0;i<6;i++)for(j=0;j<3;j++){
159         this->fTubeEndSector[k][0][i][j] = 0.0;
160         this->fTubeEndSector[k][1][i][j] = 0.0;
161     } // end for i,j
162 }
163 //______________________________________________________________________
164 AliITSv11GeometrySPD::AliITSv11GeometrySPD(const AliITSv11GeometrySPD &s):
165 AliITSv11Geometry(s),// Base Class Copy constructor
166 fAddStave(),        // [DEBUG] must be TRUE for all staves which will be
167                     // mounted in the sector (used to check overlaps)
168 fSPDsectorX0(s.fSPDsectorX0),    // X of first edge of sector plane for stave
169 fSPDsectorY0(s.fSPDsectorY0),    // Y of first edge of sector plane for stave
170 fSPDsectorX1(s.fSPDsectorX1),    // X of second edge of sector plane for stave
171 fSPDsectorY1(s.fSPDsectorY1)     // Y of second edge of sector plane for stave
172 {
173     //
174     // Copy Constructor
175     // Inputs:
176     //    AliITSv11GeometrySPD &s      source class
177     // Outputs:
178     //    none.
179     // Return:
180     //    A copy of a AliITSv11GeometrySPD class.
181     //
182     Int_t i=0,j=0,k=0;
183
184     for (i = 0; i < 6; i++) this->fAddStave[i] = s.fAddStave[i];
185     for(k=0;k<10;k++)for(i=0;i<6;i++)for(j=0;j<3;j++){
186         this->fTubeEndSector[k][0][i][j] = s.fTubeEndSector[k][0][i][j];
187         this->fTubeEndSector[k][1][i][j] = s.fTubeEndSector[k][1][i][j];
188     } // end for i,j
189 }
190 //______________________________________________________________________
191 AliITSv11GeometrySPD& AliITSv11GeometrySPD::operator=(const
192                                                AliITSv11GeometrySPD &s)
193 {
194     //
195     // = operator
196     // Inputs:
197     //    AliITSv11GeometrySPD &s      source class
198     // Outputs:
199     //    none.
200     // Return:
201     //    A copy of a AliITSv11GeometrySPD class.
202     //
203     Int_t i=0,j=0,k=0;
204
205     if(this==&s) return *this;
206     for (i = 0; i < 6; i++) this->fAddStave[i] = s.fAddStave[i];
207     this->fSPDsectorX0=s.fSPDsectorX0;
208     this->fSPDsectorY0=s.fSPDsectorY0;
209     this->fSPDsectorX1=s.fSPDsectorX1;
210     this->fSPDsectorY1=s.fSPDsectorY1;
211     for(k=0;k<10;k++)for(i=0;i<6;i++)for(j=0;j<3;j++){
212         this->fTubeEndSector[k][0][i][j] = s.fTubeEndSector[k][0][i][j];
213         this->fTubeEndSector[k][1][i][j] = s.fTubeEndSector[k][1][i][j];
214     } // end for i,j
215     return *this;
216 }
217 //______________________________________________________________________
218 TGeoMedium* AliITSv11GeometrySPD::GetMedium(const char* mediumName,
219                                             const TGeoManager *mgr) const
220 {
221     //
222     // This function is used to recovery any medium
223     // used to build the geometry volumes.
224     // If the required medium does not exists,
225     // a NULL pointer is returned, and an error message is written.
226     //
227      Char_t itsMediumName[30];
228
229      snprintf(itsMediumName, 30, "ITS_%s", mediumName);
230      TGeoMedium* medium = mgr->GetMedium(itsMediumName);
231      if (!medium) AliError(Form("Medium <%s> not found", mediumName));
232
233      return medium;
234 }
235
236 //______________________________________________________________________
237 void AliITSv11GeometrySPD::SPDSector(TGeoVolume *moth, TGeoManager *mgr)
238 {
239     //
240     // Creates a single SPD carbon fiber sector and places it
241     // in a container volume passed as first argument ('moth').
242     // Second argument points to the TGeoManager which coordinates
243     // the overall volume creation.
244     // The position of the sector is based on distance of
245     // closest point of SPD stave to beam pipe
246     // (figures all-sections-modules.ps) of 7.22mm at section A-A.
247     //
248
249     // Begin_Html
250     /*
251      <img src="http://alice.pd.infn.it/latestdr/Geometric-Revision/assembly.ps"
252      title="SPD     Sector    drawing   with all  cross     sections  defined">
253      <p>The    SPD  Sector    definition.    In
254      <a   href="http://alice.pd.infn.it/latestdr/Geometric-Revision/assembly.hpgl">HPGL</a>    format.
255      <img src="http://alice.pd.infn.it/latestdr/Geometric-Revision/assembly-10-modules.ps"
256      titile="SPD    All  Sectors   end  view with thermal   sheald">
257      <p>The    SPD  all  sector    end  view with thermal   sheald.
258      <img src="http://alice.pd.infn.it/latestdr/Geometric-Revision/assembly.ps"
259      title="SPD     side view cross     section">
260      <p>SPD    side view cross     section   with condes    and  thermal   shealds.
261      <img src="http://alice.pd.infn.it/latestdr/Geometric-Revision/SECTION-A_A.jpg"
262      title="Cross   section   A-A"><p>Cross  section   A-A.
263      <img src="http://alice.pd.infn.it/latestdr/Geometric-Revision/SECTION-B_B.jpg"
264      title="Cross  updated section   A-A"><p>Cross updated section   A-A.
265      <img src="http://physics.mps.ohio-state.edu/~nilsen/ITSfigures/Sezione_layerAA.pdf"
266      title="Cross   section   B-B"><p>Cross  section   B-B.
267      <img src="http://alice.pd.infn.it/latestdr/Geometric-Revision/SECTION-C_C.jpg"
268      title-"Cross   section   C-C"><p>Cross  section   C-C.
269      <img src="http://alice.pd.infn.it/latestdr/Geometric-Revision/SECTION-D_D.jpg"
270      title="Cross   section   D-D"><p>Cross  section   D-D.
271      <img src="http://alice.pd.infn.it/latestdr/Geometric-Revision/SECTION-E_E.jpg"
272      title="Cross   section   E-E"><p>Cross  section   E-E.
273      <img src="http://alice.pd.infn.it/latestdr/Geometric-Revision/SECTION-F_F.jpg"
274      title="Cross   section   F-F"><p>Cross  section   F-F.
275      <img src="http://alice.pd.infn.it/latestdr/Geometric-Revision/SECTION-G_G.jpg"
276      title="Cross   section   G-G"><p>Cross  section   G-G.
277     */
278     // End_Html
279
280     // Inputs:
281     //    TGeoVolume *moth  Pointer to mother volume where this object
282     //                      is to be placed in
283     //    TGeoManager *mgr  Pointer to the TGeoManager used, defaule is
284     //                      gGeoManager.
285     // Outputs:
286     //    none.
287     // Return:
288     //    none.
289     // Updated values for kSPDclossesStaveAA, kBeamPipeRadius, and
290     // staveThicknessAA are taken from
291     // http://physics.mps.ohio-state.edu/~nilsen/ITSfigures/Sezione_layerAA.pdf
292     //
293     const Double_t kSPDclossesStaveAA   =   7.25* fgkmm;
294     const Double_t kSectorStartingAngle = -72.0 * fgkDegree;
295     const Int_t    kNSectorsTotal       =  10;
296     const Double_t kSectorRelativeAngle =  36.0 * fgkDegree;    // = 360.0 / 10
297     const Double_t kBeamPipeRadius      =   0.5 * 59.6 * fgkmm; // diam. = 59.6 mm
298   //const Double_t staveThicknessAA     =   0.9 *fgkmm;         // nominal thickness
299     const Double_t staveThicknessAA     =   1.02 * fgkmm;       // get from stave geometry.
300
301     Int_t i, j, k;
302     Double_t angle, radiusSector, xAAtubeCenter0, yAAtubeCenter0;
303     TGeoCombiTrans *secRot = new TGeoCombiTrans(), *comrot;
304     TGeoVolume *vCarbonFiberSector[10];
305     TGeoMedium *medSPDcf;
306
307     // Define an assembly and fill it with the support of
308     // a single carbon fiber sector and staves in it
309     medSPDcf = GetMedium("SPD C (M55J)$", mgr);
310     for(Int_t is=0; is<10; is++)
311     {
312             vCarbonFiberSector[is] = new TGeoVolumeAssembly("ITSSPDCarbonFiberSectorV");
313             vCarbonFiberSector[is]->SetMedium(medSPDcf);
314             CarbonFiberSector(vCarbonFiberSector[is], is, xAAtubeCenter0, yAAtubeCenter0, mgr);
315     }
316
317     // Compute the radial shift out of the sectors
318     radiusSector = kBeamPipeRadius + kSPDclossesStaveAA + staveThicknessAA;
319     radiusSector  = GetSPDSectorTranslation(fSPDsectorX0.At(1), fSPDsectorY0.At(1),
320                                             fSPDsectorX1.At(1), fSPDsectorY1.At(1), radiusSector);
321   //radiusSector *= radiusSector; // squaring;
322   //radiusSector -= xAAtubeCenter0 * xAAtubeCenter0;
323   //radiusSector  = -yAAtubeCenter0 + TMath::Sqrt(radiusSector);
324
325     AliDebug(1, Form("SPDSector : radiusSector=%f\n",radiusSector));
326     i = 1;
327     AliDebug(1, Form("i= %d x0=%f y0=%f x1=%f y1=%f\n", i,
328                      fSPDsectorX0.At(i), fSPDsectorY0.At(i),
329                      fSPDsectorX1.At(i),fSPDsectorY1.At(i)));
330
331     // add 10 single sectors, by replicating the virtual sector defined above
332     // and placing at different angles
333     Double_t shiftX, shiftY, tub[2][6][3];
334     for(i=0;i<2;i++)for(j=0;j<6;j++)for(k=0;k<3;k++) tub[i][j][k] = fTubeEndSector[0][i][j][k];
335     angle = kSectorStartingAngle;
336     secRot->RotateZ(angle);
337     TGeoVolumeAssembly *vcenteral = new TGeoVolumeAssembly("ITSSPD");
338     moth->AddNode(vcenteral, 1, 0);
339     for(i = 0; i < kNSectorsTotal; i++) {
340         shiftX = -radiusSector * TMath::Sin(angle/fgkRadian);
341         shiftY =  radiusSector * TMath::Cos(angle/fgkRadian);
342         //cout << "ANGLE = " << angle << endl;
343         shiftX += 0.1094 * TMath::Cos((angle + 196.)/fgkRadian);
344         shiftY += 0.1094 * TMath::Sin((angle + 196.)/fgkRadian);
345         //shiftX -= 0.105;
346         //shiftY -= 0.031;
347         //shiftX -= 0.11 * TMath::Cos(angle/fgkRadian); // add by Alberto
348         //shiftY -= 0.11 * TMath::Sin(angle/fgkRadian); // don't ask me where that 0.11 comes from!
349         secRot->SetDx(shiftX);
350         secRot->SetDy(shiftY);
351         comrot  = new TGeoCombiTrans(*secRot);
352         vcenteral->AddNode(vCarbonFiberSector[i],i+1,comrot);
353         for(j=0;j<2;j++)for(k=0;k<6;k++) // Transform Tube ends for each sector
354             comrot->LocalToMaster(tub[j][k],fTubeEndSector[i][j][k]);
355         if(GetDebug(5)) {
356             AliInfo(Form("i=%d angle=%g angle[rad]=%g radiusSector=%g "
357                          "x=%g y=%g \n",i, angle, angle/fgkRadian,
358                          radiusSector, shiftX, shiftY));
359         } // end if GetDebug(5)
360         angle += kSectorRelativeAngle;
361         secRot->RotateZ(kSectorRelativeAngle);
362     } // end for i
363     if(GetDebug(3)) moth->PrintNodes();
364     delete secRot;
365
366     CreateCones(moth);
367     CreateServices(moth);
368 }
369 //______________________________________________________________________
370 void AliITSv11GeometrySPD::CarbonFiberSector(TGeoVolume *moth, Int_t sect,
371      Double_t &xAAtubeCenter0, Double_t &yAAtubeCenter0, TGeoManager *mgr)
372 {
373     // The method has been modified in order to build a support sector
374     // whose shape is dependent on the sector number; the aim is to get
375     // as close as possible to the shape inferred from alignment
376     // and avoid as much as possible overlaps generated by alignment.
377     //
378     // Define the detail SPD Carbon fiber support Sector geometry.
379     // Based on the drawings:
380     /*
381       http:///QA-construzione-profilo-modulo.ps
382      */
383     // - ALICE-Pixel "Costruzione Profilo Modulo" (march 25 2004)
384     // - ALICE-SUPPORTO "Costruzione Profilo Modulo"
385     // ---
386     // Define outside radii as negative, where "outside" means that the
387     // center of the arc is outside of the object (feb 16 2004).
388     // ---
389     // Arguments [the one passed by ref contain output values]:
390     // Inputs:
391     //   TGeoVolume *moth             the voulme which will contain this object
392     //   TGeoManager *mgr             TGeo builder defauls is gGeoManager
393     // Outputs:
394     //   Double_t   &xAAtubeCenter0  (by ref) x location of the outer surface
395     //                               of the cooling tube center for tube 0.
396     //   Double_t   &yAAtubeCenter0  (by ref) y location of the outer surface
397     //                                of the cooling tube center for tube 0.
398     // Return:
399     //   none.
400     // ---
401     // Int the two variables passed by reference values will be stored
402     // which will then be used to correctly locate this sector.
403     // The information used for this is the distance between the
404     // center of the #0 detector and the beam pipe.
405     // Measurements are taken at cross section A-A.
406     //
407
408     //TGeoMedium *medSPDfs      = 0;//SPD support cone inserto stesalite 4411w
409     //TGeoMedium *medSPDfo      = 0;//SPD support cone foam, Rohacell 50A.
410     //TGeoMedium *medSPDal      = 0;//SPD support cone SDD mounting bracket Al
411     TGeoMedium *medSPDcf     = GetMedium("SPD C (M55J)$", mgr);
412     TGeoMedium *medSPDss     = GetMedium("INOX$", mgr);
413     TGeoMedium *medSPDair    = GetMedium("AIR$", mgr);
414     TGeoMedium *medSPDcoolfl = GetMedium("Freon$", mgr); //ITSspdCoolingFluid
415     //
416     const Double_t ksecDz           =  0.5 * 500.0 * fgkmm;
417     //const Double_t ksecLen        = 30.0 * fgkmm;
418     const Double_t ksecCthick       =  0.2 * fgkmm;
419     const Double_t ksecDipLength =  3.2 * fgkmm;
420     const Double_t ksecDipRadii  =  0.4 * fgkmm;
421     //const Double_t ksecCoolingTubeExtraDepth = 0.86 * fgkmm;
422     //
423     // The following positions ('ksecX#' and 'ksecY#') and radii ('ksecR#')
424     // are the centers and radii of curvature of all the rounded corners
425     // between the straight borders of the SPD sector shape.
426     // To draw this SPD sector, the following steps are followed:
427     // 1) the (ksecX, ksecY) points are plotted
428     //    and circles of the specified radii are drawn around them.
429     // 2) each pair of consecutive circles is connected by a line
430     //    tangent to them, in accordance with the radii being "internal"
431     //    or "external" with respect to the closed shape which describes
432     //    the sector itself.
433     // The resulting connected shape is the section
434     // of the SPD sector surface in the transverse plane (XY).
435     //
436     const Double_t ksecX0   = -10.725 * fgkmm;
437     const Double_t ksecY0   = -14.853 * fgkmm;
438     const Double_t ksecR0   =  -0.8   * fgkmm; // external
439
440     const Double_t ksecR1   =  +0.6   * fgkmm;
441     const Double_t ksecR2   =  +0.6   * fgkmm;
442     const Double_t ksecR3   =  -0.6   * fgkmm;
443     const Double_t ksecR4   =  +0.8   * fgkmm;
444     const Double_t ksecR5   =  +0.8   * fgkmm;
445     const Double_t ksecR6   =  +0.6   * fgkmm;
446     const Double_t ksecR7   =  -0.6   * fgkmm;
447     const Double_t ksecR8   =  +0.6   * fgkmm;
448     const Double_t ksecR9   =  -0.6   * fgkmm;
449     const Double_t ksecR10   =  +0.6   * fgkmm;
450     const Double_t ksecR11   =  -0.6   * fgkmm;
451     const Double_t ksecR12   =  +0.85   * fgkmm;
452
453 //    // IDEAL GEOMETRY
454 //     const Double_t ksecX1[10] ={-1.3187,-1.3187,-1.3187,-1.3187,-1.3187,-1.3187,-1.3187,-1.3187,-1.3187,-1.3187};
455 //     const Double_t ksecY1[10] ={-1.9964,-1.9964,-1.9964,-1.9964,-1.9964,-1.9964,-1.9964,-1.9964,-1.9964,-1.9964};
456 //     const Double_t ksecX2[10] ={-0.3833,-0.3833,-0.3833,-0.3833,-0.3833,-0.3833,-0.3833,-0.3833,-0.3833,-0.3833};
457 //     const Double_t ksecY2[10] ={-1.7805,-1.7805,-1.7805,-1.7805,-1.7805,-1.7805,-1.7805,-1.7805,-1.7805,-1.7805};
458 //     const Double_t ksecX3[10] ={-0.3123,-0.3123,-0.3123,-0.3123,-0.3123,-0.3123,-0.3123,-0.3123,-0.3123,-0.3123};
459 //     const Double_t ksecY3[10] ={-1.4618,-1.4618,-1.4618,-1.4618,-1.4618,-1.4618,-1.4618,-1.4618,-1.4618,-1.4618};
460 //     const Double_t ksecX4[10] ={+1.1280,+1.1280,+1.1280,+1.1280,+1.1280,+1.1280,+1.1280,+1.1280,+1.1280,+1.1280};
461 //     const Double_t ksecY4[10] ={-1.4473,-1.4473,-1.4473,-1.4473,-1.4473,-1.4473,-1.4473,-1.4473,-1.4473,-1.4473};
462 //     const Double_t ksecX5[10] ={+1.9544,+1.9544,+1.9544,+1.9544,+1.9544,+1.9544,+1.9544,+1.9544,+1.9544,+1.9544};
463 //     const Double_t ksecY5[10] ={+1.0961,+1.0961,+1.0961,+1.0961,+1.0961,+1.0961,+1.0961,+1.0961,+1.0961,+1.0961};
464 //     const Double_t ksecX6[10] ={+1.0830,+1.0830,+1.0830,+1.0830,+1.0830,+1.0830,+1.0830,+1.0830,+1.0830,+1.0830};
465 //     const Double_t ksecY6[10] ={+1.6868,+1.6868,+1.6868,+1.6868,+1.6868,+1.6868,+1.6868,+1.6868,+1.6868,+1.6868};
466 //     const Double_t ksecX7[10] ={+1.1581,+1.1581,+1.1581,+1.1581,+1.1581,+1.1581,+1.1581,+1.1581,+1.1581,+1.1581};
467 //     const Double_t ksecY7[10] ={+1.3317,+1.3317,+1.3317,+1.3317,+1.3317,+1.3317,+1.3317,+1.3317,+1.3317,+1.3317};
468 //     const Double_t ksecX8[10] ={-0.0733,-0.0733,-0.0733,-0.0733,-0.0733,-0.0733,-0.0733,-0.0733,-0.0733,-0.0733};
469 //     const Double_t ksecY8[10] ={+1.7486,+1.7486,+1.7486,+1.7486,+1.7486,+1.7486,+1.7486,+1.7486,+1.7486,+1.7486};
470 //     const Double_t ksecX9[10] ={+0.0562,+0.0562,+0.0562,+0.0562,+0.0562,+0.0562,+0.0562,+0.0562,+0.0562,+0.0562};
471 //     const Double_t ksecY9[10] ={+1.4107,+1.4107,+1.4107,+1.4107,+1.4107,+1.4107,+1.4107,+1.4107,+1.4107,+1.4107};
472 //     const Double_t ksecX10[10]={-1.2252,-1.2252,-1.2252,-1.2252,-1.2252,-1.2252,-1.2252,-1.2252,-1.2252,-1.2252};
473 //     const Double_t ksecY10[10]={+1.6298,+1.6298,+1.6298,+1.6298,+1.6298,+1.6298,+1.6298,+1.6298,+1.6298,+1.6298};
474 //     const Double_t ksecX11[10]={-1.0445,-1.0445,-1.0445,-1.0445,-1.0445,-1.0445,-1.0445,-1.0445,-1.0445,-1.0445};
475 //     const Double_t ksecY11[10]={+1.3162,+1.3162,+1.3162,+1.3162,+1.3162,+1.3162,+1.3162,+1.3162,+1.3162,+1.3162};
476 //     const Double_t ksecX12[10]={-2.2276,-2.2276,-2.2276,-2.2276,-2.2276,-2.2276,-2.2276,-2.2276,-2.2276,-2.2276};
477 //     const Double_t ksecY12[10]={+1.2948,+1.2948,+1.2948,+1.2948,+1.2948,+1.2948,+1.2948,+1.2948,+1.2948,+1.2948};
478   
479
480 //    MODIFIED GEOMETRY according with partial alignment of Staves relative to Sectors
481 //    last numbers: 2010/06/11 (ML)
482
483     const Double_t ksecX1[10]={-1.305917, -1.322242, -1.300649, -1.298700, -1.290830, -1.274307, -1.276433, -1.286468, -1.274381, -1.314864};
484     const Double_t ksecY1[10]={-1.997857, -2.018611, -2.005854, -2.004897, -1.995517, -2.002552, -1.995860, -2.021062, -2.012931, -2.043967};
485     const Double_t ksecX2[10]={-0.366115, -0.385562, -0.372689, -0.365682, -0.348432, -0.348442, -0.342468, -0.354071, -0.346900, -0.381275};
486     const Double_t ksecY2[10]={-1.801679, -1.808306, -1.759315, -1.778851, -1.811655, -1.747888, -1.773811, -1.792427, -1.764514, -1.820324};
487 //     const Double_t ksecX1[10]={-1.305917, -1.322242, -1.300649, -1.298700, -1.290830, -1.274307, -1.276433, -1.286468, -1.274381, -1.325864};
488 //     const Double_t ksecY1[10]={-1.997857, -2.018611, -2.005854, -2.004897, -1.995517, -2.002552, -1.995860, -2.021062, -2.012931, -2.032967};
489 //     const Double_t ksecX2[10]={-0.366115, -0.385562, -0.372689, -0.365682, -0.348432, -0.348442, -0.342468, -0.354071, -0.346900, -0.392275};
490 //     const Double_t ksecY2[10]={-1.801679, -1.808306, -1.759315, -1.778851, -1.811655, -1.747888, -1.773811, -1.792427, -1.764514, -1.809324};
491     const Double_t ksecX3[10]={-0.314030, -0.315531, -0.347521, -0.337675, -0.300420, -0.378487, -0.330729, -0.330850, -0.362360, -0.321097};
492     const Double_t ksecY3[10]={-1.452488, -1.460418, -1.447060, -1.443146, -1.472410, -1.430019, -1.469073, -1.472048, -1.462010, -1.444355};
493     const Double_t ksecX4[10]={1.124299, 1.124162, 1.089523, 1.095520, 1.136171, 1.058616, 1.105626, 1.106433, 1.077455, 1.117946};
494     const Double_t ksecY4[10]={-1.458714, -1.452649, -1.465297, -1.492717, -1.494665, -1.447732, -1.493369, -1.488126, -1.452925, -1.443447};
495     const Double_t ksecX5[10]={1.951621, 1.939284, 1.931830, 1.935235, 1.952206, 1.939082, 1.924822, 1.940114, 1.918160, 1.960017};
496     const Double_t ksecY5[10]={1.092731, 1.118870, 1.129765, 1.129422, 1.081511, 1.127387, 1.103960, 1.101784, 1.121428, 1.150110};
497     const Double_t ksecX6[10]={1.070070, 1.048297, 1.035920, 1.049049, 1.083621, 1.045882, 1.050399, 1.067823, 1.037967, 1.070850};
498     const Double_t ksecY6[10]={1.667590, 1.678571, 1.681383, 1.696892, 1.676520, 1.683470, 1.689988, 1.691111, 1.698432, 1.712770};
499     const Double_t ksecX7[10]={1.139398, 1.150471, 1.150074, 1.132807, 1.150192, 1.124064, 1.124335, 1.137723, 1.143056, 1.130568};
500     const Double_t ksecY7[10]={1.345588, 1.356062, 1.342468, 1.320467, 1.335807, 1.334477, 1.328622, 1.347184, 1.319861, 1.308420};
501     const Double_t ksecX8[10]={-0.096963, -0.098603, -0.095286, -0.099990, -0.075132, -0.121593, -0.108673, -0.104237, -0.092082, -0.104044};
502     const Double_t ksecY8[10]={1.751207, 1.731467, 1.726908, 1.734219, 1.766159, 1.718203, 1.741891, 1.739743, 1.728288, 1.718046};
503     const Double_t ksecX9[10]={0.047615, 0.087875, 0.034917, 0.071603, 0.026468, 0.091619, 0.051994, 0.059947, 0.079785, 0.043443};
504     const Double_t ksecY9[10]={1.414699, 1.403187, 1.399061, 1.403430, 1.435056, 1.384557, 1.397692, 1.420269, 1.391372, 1.398954};
505     const Double_t ksecX10[10]={-1.233255, -1.186874, -1.246702, -1.213368, -1.259425, -1.190067, -1.225655, -1.224171, -1.197833, -1.237182};
506     const Double_t ksecY10[10]={1.635767, 1.646249, 1.617336, 1.608928, 1.636944, 1.602583, 1.630504, 1.629065, 1.624295, 1.620934};
507     const Double_t ksecX11[10]={-1.018270, -1.031317, -0.960524, -1.001155, -1.045437, -0.986867, -1.002685, -1.017369, -1.005614, -0.985385};
508     const Double_t ksecY11[10]={1.318108, 1.330683, 1.301572, 1.314410, 1.326680, 1.295226, 1.306372, 1.309414, 1.306542, 1.307086};
509     const Double_t ksecX12[10]={-2.199004, -2.214964, -2.139247, -2.180547, -2.224505, -2.165324, -2.175883, -2.193485, -2.183227, -2.161570};
510     const Double_t ksecY12[10]={1.317677, 1.303982, 1.317057, 1.324766, 1.339537, 1.312715, 1.359642, 1.343638, 1.330234, 1.340836};
511
512
513     const Double_t ksecR13  =  -0.8   * fgkmm; // external
514     const Double_t ksecAngleSide13 = 36.0 * fgkDegree;
515     //
516     const Int_t ksecNRadii = 20;
517     const Int_t ksecNPointsPerRadii = 4;
518     const Int_t ksecNCoolingTubeDips = 6;
519     //
520     // Since the rounded parts are approximated by a regular polygon
521     // and a cooling tube of the propper diameter must fit, a scaling factor
522     // increases the size of the polygon for the tube to fit.
523     //const Double_t ksecRCoolScale = 1./TMath::Cos(TMath::Pi()/
524     //                                      (Double_t)ksecNPointsPerRadii);
525     const Double_t ksecZEndLen   = 30.000 * fgkmm;
526     //const Double_t ksecZFlangLen = 45.000 * fgkmm;
527     const Double_t ksecTl        =  0.860 * fgkmm;
528     const Double_t ksecCthick2   =  0.600 * fgkmm;
529     //const Double_t ksecCthick3  =  1.80  * fgkmm;
530     //const Double_t ksecSidelen  = 22.0   * fgkmm;
531     //const Double_t ksecSideD5   =  3.679 * fgkmm;
532     //const Double_t ksecSideD12  =  7.066 * fgkmm;
533     const Double_t ksecRCoolOut  = 2.400 * fgkmm;
534     const Double_t ksecRCoolIn   = 2.000 * fgkmm;
535     const Double_t ksecDl1       = 5.900 * fgkmm;
536     const Double_t ksecDl2       = 8.035 * fgkmm;
537     const Double_t ksecDl3       = 4.553 * fgkmm;
538     const Double_t ksecDl4       = 6.978 * fgkmm;
539     const Double_t ksecDl5       = 6.978 * fgkmm;
540     const Double_t ksecDl6       = 6.978 * fgkmm;
541     const Double_t ksecCoolTubeThick  = 0.04  * fgkmm;
542     const Double_t ksecCoolTubeROuter = 2.6   * fgkmm;
543     const Double_t ksecCoolTubeFlatX  = 3.696 * fgkmm;
544     const Double_t ksecCoolTubeFlatY  = 0.68  * fgkmm;
545     //const Double_t ksecBeamX0 = 0.0 * fgkmm; // guess
546     //const Double_t ksecBeamY0 = (15.223 + 40.) * fgkmm; // guess
547     //
548     // redefine some of the points already defined above
549     // in the format of arrays (???)
550     const Int_t ksecNPoints = (ksecNPointsPerRadii + 1) * ksecNRadii + 8;
551     Double_t secX[ksecNRadii] = {
552         ksecX0,  ksecX1[sect],  -1000.0,
553         ksecX2[sect],  ksecX3[sect],  -1000.0,
554         ksecX4[sect],  ksecX5[sect],  -1000.0,
555         ksecX6[sect],  ksecX7[sect],  -1000.0,
556         ksecX8[sect],  ksecX9[sect],  -1000.0,
557         ksecX10[sect], ksecX11[sect], -1000.0,
558         ksecX12[sect], -1000.0
559     };
560     Double_t secY[ksecNRadii] = {
561         ksecY0,  ksecY1[sect],  -1000.0,
562         ksecY2[sect],  ksecY3[sect],  -1000.0,
563         ksecY4[sect],  ksecY5[sect],  -1000.0,
564         ksecY6[sect],  ksecY7[sect],  -1000.0,
565         ksecY8[sect],  ksecY9[sect],  -1000.0,
566         ksecY10[sect], ksecY11[sect], -1000.0,
567         ksecY12[sect], -1000.0
568     };
569     Double_t secR[ksecNRadii] = {
570         ksecR0,  ksecR1,  -.5 * ksecDipLength - ksecDipRadii,
571         ksecR2,  ksecR3,  -.5 * ksecDipLength - ksecDipRadii,
572         ksecR4,  ksecR5,  -.5 * ksecDipLength - ksecDipRadii,
573         ksecR6,  ksecR7,  -.5 * ksecDipLength - ksecDipRadii,
574         ksecR8,  ksecR9,  -.5 * ksecDipLength - ksecDipRadii,
575         ksecR10, ksecR11, -.5 * ksecDipLength - ksecDipRadii,
576         ksecR12, ksecR13
577     };
578
579     Double_t secX2[ksecNRadii];
580     Double_t secY2[ksecNRadii];
581     Double_t secR2[ksecNRadii] = {
582         ksecR0,  ksecR1,  ksecRCoolOut,
583         ksecR2,  ksecR3,  ksecRCoolOut,
584         ksecR4,  ksecR5,  ksecRCoolOut,
585         ksecR6,  ksecR7,  ksecRCoolOut,
586         ksecR8,  ksecR9,  ksecRCoolOut,
587         ksecR10, ksecR11, ksecRCoolOut,
588         ksecR12, ksecR13
589     };
590     Double_t secDip2[ksecNCoolingTubeDips] = {
591         ksecDl1, ksecDl2, ksecDl3,
592         ksecDl4, ksecDl5, ksecDl6
593     };
594     Double_t secX3[ksecNRadii];
595     Double_t secY3[ksecNRadii];
596     const Int_t ksecDipIndex[ksecNCoolingTubeDips] = {2, 5, 8, 11, 14, 17};
597     Double_t secAngleStart[ksecNRadii];
598     Double_t secAngleEnd[ksecNRadii];
599     for(Int_t i = 0; i < ksecNRadii; i++)secAngleEnd[i] = 0.;
600     Double_t secAngleStart2[ksecNRadii];
601     Double_t secAngleEnd2[ksecNRadii];
602     Double_t secAngleTurbo[ksecNCoolingTubeDips] = {0., 0., 0., 0., 0., 0.0};
603     //Double_t secAngleStart3[ksecNRadii];
604     //Double_t secAngleEnd3[ksecNRadii];
605     Double_t  xpp[ksecNPoints],  ypp[ksecNPoints];
606     Double_t  xpp2[ksecNPoints], ypp2[ksecNPoints];
607     Double_t *xp[ksecNRadii],   *xp2[ksecNRadii];
608     Double_t *yp[ksecNRadii],   *yp2[ksecNRadii];
609     TGeoXtru *sA0,  *sA1, *sB0, *sB1,*sB2;
610     TGeoBBox *sB3;
611     TGeoEltu *sTA0, *sTA1;
612     TGeoTube *sTB0, *sTB1; //,*sM0;
613     TGeoRotation    *rot;
614     TGeoTranslation *trans;
615     TGeoCombiTrans  *rotrans;
616     Double_t t, t0, t1, a, b, x0, y0,z0, x1, y1;
617     Int_t i, j, k, m;
618     Bool_t tst;
619
620     if(!moth) {
621         AliError("Container volume (argument) is NULL");
622         return;
623     } // end if(!moth)
624     for(i = 0; i < ksecNRadii; i++) {
625         xp[i]  = &(xpp[i*(ksecNPointsPerRadii+1)]);
626         yp[i]  = &(ypp[i*(ksecNPointsPerRadii+1)]);
627         xp2[i] = &(xpp2[i*(ksecNPointsPerRadii+1)]);
628         yp2[i] = &(ypp2[i*(ksecNPointsPerRadii+1)]);
629         secX2[i] = secX[i];
630         secY2[i] = secY[i];
631         secX3[i] = secX[i];
632         secY3[i] = secY[i];
633     } // end for i
634     //
635     // find starting and ending angles for all but cooling tube sections
636     secAngleStart[0] = 0.5 * ksecAngleSide13;
637     for(i = 0; i < ksecNRadii - 2; i++) {
638         tst = kFALSE;
639         for(j=0;j<ksecNCoolingTubeDips;j++) tst = (tst||i==ksecDipIndex[j]);
640         if (tst) continue;
641         tst = kFALSE;
642         for(j=0;j<ksecNCoolingTubeDips;j++) tst =(tst||(i+1)==ksecDipIndex[j]);
643         if (tst) j = i+2; else j = i+1;
644         AnglesForRoundedCorners(secX[i],secY[i],secR[i],secX[j],secY[j],
645                                 secR[j],t0,t1);
646         secAngleEnd[i]   = t0;
647         secAngleStart[j] = t1;
648         if(secR[i] > 0.0 && secR[j] > 0.0) {
649             if(secAngleStart[i] > secAngleEnd[i]) secAngleEnd[i] += 360.0;
650         } // end if(secR[i]>0.0 && secR[j]>0.0)
651         secAngleStart2[i] = secAngleStart[i];
652         secAngleEnd2[i]   = secAngleEnd[i];
653     } // end for i
654     secAngleEnd[ksecNRadii-2] = secAngleStart[ksecNRadii-2] +
655                    (secAngleEnd[ksecNRadii-5] - secAngleStart[ksecNRadii-5]);
656     if (secAngleEnd[ksecNRadii-2] < 0.0) secAngleEnd[ksecNRadii-2] += 360.0;
657     secAngleStart[ksecNRadii-1]  = secAngleEnd[ksecNRadii-2] - 180.0;
658     secAngleEnd[ksecNRadii-1]    = secAngleStart[0];
659     secAngleStart2[ksecNRadii-2] = secAngleStart[ksecNRadii-2];
660     secAngleEnd2[ksecNRadii-2]   = secAngleEnd[ksecNRadii-2];
661     secAngleStart2[ksecNRadii-1] = secAngleStart[ksecNRadii-1];
662     secAngleEnd2[ksecNRadii-1]   = secAngleEnd[ksecNRadii-1];
663     //
664     // find location of circle last rounded corner.
665     i = 0;
666     j = ksecNRadii - 2;
667     t0 = TanD(secAngleStart[i]-90.);
668     t1 = TanD(secAngleEnd[j]-90.);
669     t  = secY[i] - secY[j];
670     // NOTE: secR[i=0] < 0; secR[j=18] > 0; and secR[j+1=19] < 0
671     t += (-secR[i]+secR[j+1]) * SinD(secAngleStart[i]);
672     t -= (secR[j]-secR[j+1]) * SinD(secAngleEnd[j]);
673     t += t1 * secX[j] - t0*secX[i];
674     t += t1 * (secR[j] - secR[j+1]) * CosD(secAngleEnd[j]);
675     t -= t0 * (-secR[i]+secR[j+1]) * CosD(secAngleStart[i]);
676     secX[ksecNRadii-1] = t / (t1-t0);
677     secY[ksecNRadii-1] = TanD(90.0+0.5*ksecAngleSide13)*
678         (secX[ksecNRadii-1]-secX[0])+secY[0];
679     secX2[ksecNRadii-1] = secX[ksecNRadii-1];
680     secY2[ksecNRadii-1] = secY[ksecNRadii-1];
681     secX3[ksecNRadii-1] = secX[ksecNRadii-1];
682     secY3[ksecNRadii-1] = secY[ksecNRadii-1];
683
684     // find location of cooling tube centers
685     for(i = 0; i < ksecNCoolingTubeDips; i++) {
686         j = ksecDipIndex[i];
687         x0 = secX[j-1] + TMath::Abs(secR[j-1]) * CosD(secAngleEnd[j-1]);
688         y0 = secY[j-1] + TMath::Abs(secR[j-1]) * SinD(secAngleEnd[j-1]);
689         x1 = secX[j+1] + TMath::Abs(secR[j+1]) * CosD(secAngleStart[j+1]);
690         y1 = secY[j+1] + TMath::Abs(secR[j+1]) * SinD(secAngleStart[j+1]);
691         t0 = TMath::Sqrt((x0-x1)*(x0-x1)+(y0-y1)*(y0-y1));
692         t  = secDip2[i] / t0;
693         a  = x0+(x1-x0) * t;
694         b  = y0+(y1-y0) * t;
695         if(i == 0) {
696             // get location of tube center->Surface for locating
697             // this sector around the beam pipe.
698             // This needs to be double checked, but I need my notes for that.
699             // (Bjorn Nilsen)
700             xAAtubeCenter0 = x0 + (x1 - x0) * t * 0.5;
701             yAAtubeCenter0 = y0 + (y1 - y0) * t * 0.5;
702         }// end if i==0
703         if(a + b*(a - x0) / (b - y0) > 0.0) {
704             secX[j]  = a + TMath::Abs(y1-y0) * 2.0 * ksecDipRadii/t0;
705             secY[j]  = b - TMath::Sign(2.0*ksecDipRadii,y1-y0) * (x1-x0)/t0;
706             secX2[j] = a + TMath::Abs(y1-y0) * ksecTl/t0;
707             secY2[j] = b - TMath::Sign(ksecTl,y1-y0) * (x1-x0) / t0;
708             secX3[j] = a + TMath::Abs(y1-y0) *
709                        (2.0*ksecDipRadii-0.5*ksecCoolTubeFlatY)/t0;
710             secY3[j] = b - TMath::Sign(2.0*ksecDipRadii-0.5*ksecCoolTubeFlatY,
711                                        y1-y0)*(x1-x0)/t0;
712         } else {
713             secX[j] = a - TMath::Abs(y1-y0)*2.0*ksecDipRadii/t0;
714             secY[j] = b + TMath::Sign(2.0*ksecDipRadii,y1-y0)*(x1-x0)/t0;
715             secX2[j] = a - TMath::Abs(y1-y0)*ksecTl/t0;
716             secY2[j] = b + TMath::Sign(ksecTl,y1-y0)*(x1-x0)/t0;
717             secX3[j] = a - TMath::Abs(y1-y0)*(2.0*ksecDipRadii-0.5*
718                                                   ksecCoolTubeFlatY)/t0;
719             secY3[j] = b + TMath::Sign(2.0*ksecDipRadii-0.5*ksecCoolTubeFlatY,
720                                        y1-y0)*(x1-x0)/t0;
721         } // end if(a+b*(a-x0)/(b-y0)>0.0)
722
723           // Set up Start and End angles to correspond to start/end of dips.
724         t1 = (secDip2[i]-TMath::Abs(secR[j])) / t0;
725         secAngleStart[j] =TMath::RadToDeg()*TMath::ATan2(y0+(y1-y0)*t1-secY[j],
726                                                         x0+(x1-x0)*t1-secX[j]);
727         if (secAngleStart[j]<0.0) secAngleStart[j] += 360.0;
728         secAngleStart2[j] = secAngleStart[j];
729         t1 = (secDip2[i]+TMath::Abs(secR[j]))/t0;
730         secAngleEnd[j] = TMath::RadToDeg()*TMath::ATan2(y0+(y1-y0)*t1-secY[j],
731                                                         x0+(x1-x0)*t1-secX[j]);
732         if (secAngleEnd[j]<0.0) secAngleEnd[j] += 360.0;
733         secAngleEnd2[j] = secAngleEnd[j];
734         if (secAngleEnd[j]>secAngleStart[j]) secAngleEnd[j] -= 360.0;
735         secR[j] = TMath::Sqrt(secR[j]*secR[j]+4.0*ksecDipRadii*ksecDipRadii);
736     } // end for i
737
738     // Special cases
739     secAngleStart2[8] -= 360.;
740     secAngleStart2[11] -= 360.;
741
742     SPDsectorShape(ksecNRadii, secX, secY, secR, secAngleStart, secAngleEnd,
743                    ksecNPointsPerRadii, m, xp, yp);
744
745     //  Fix up dips to be square.
746     for(i = 0; i < ksecNCoolingTubeDips; i++) {
747         j = ksecDipIndex[i];
748         t = 0.5*ksecDipLength+ksecDipRadii;
749         t0 = TMath::RadToDeg()*TMath::ATan(2.0*ksecDipRadii/t);
750         t1 = secAngleEnd[j] + t0;
751         t0 = secAngleStart[j] - t0;
752         x0 = xp[j][1] = secX[j] + t*CosD(t0);
753         y0 = yp[j][1] = secY[j] + t*SinD(t0);
754         x1 = xp[j][ksecNPointsPerRadii-1] = secX[j] + t*CosD(t1);
755         y1 = yp[j][ksecNPointsPerRadii-1] = secY[j] + t*SinD(t1);
756         t0 = 1./((Double_t)(ksecNPointsPerRadii-2));
757         for(k = 2; k < ksecNPointsPerRadii - 1; k++) {
758             // extra points spread them out.
759             t = ((Double_t)(k-1)) * t0;
760             xp[j][k] = x0+(x1-x0) * t;
761             yp[j][k] = y0+(y1-y0) * t;
762         } // end for k
763         secAngleTurbo[i] = -TMath::RadToDeg() * TMath::ATan2(y1-y0, x1-x0);
764         if(GetDebug(3)) {
765             AliInfo(
766                 Form("i=%d -- angle=%f -- x0,y0=(%f, %f) -- x1,y1=(%f, %f)",
767                      i, secAngleTurbo[i], x0, y0, x1, y1));
768         } // end if GetDebug(3)
769     } // end for i
770     sA0 = new TGeoXtru(2);
771     sA0->SetName("ITS SPD Carbon fiber support Sector A0");
772     sA0->DefinePolygon(m, xpp, ypp);
773     sA0->DefineSection(0, -ksecDz);
774     sA0->DefineSection(1,  ksecDz);
775
776     // store the edges of each XY segment which defines
777     // one of the plane zones where staves will have to be placed
778     fSPDsectorX0.Set(ksecNCoolingTubeDips);
779     fSPDsectorY0.Set(ksecNCoolingTubeDips);
780     fSPDsectorX1.Set(ksecNCoolingTubeDips);
781     fSPDsectorY1.Set(ksecNCoolingTubeDips);
782     Int_t ixy0, ixy1;
783     for(i = 0; i < ksecNCoolingTubeDips; i++) {
784         // Find index in xpp[] and ypp[] corresponding to where the
785         // SPD ladders are to be attached. Order them according to
786         // the ALICE numbering schema. Using array of indexes (+-1 for
787         // cooling tubes. For any "bend/dip/edge, there are
788         // ksecNPointsPerRadii+1 points involved.
789         if(i == 0) j = 1;
790         else if (i == 1) j = 0;
791         else j = i;
792         ixy0 = (ksecDipIndex[j]-1)*(ksecNPointsPerRadii+1)+
793             (ksecNPointsPerRadii);
794         ixy1 = (ksecDipIndex[j]+1) * (ksecNPointsPerRadii+1);
795         fSPDsectorX0[i] = sA0->GetX(ixy0);
796         fSPDsectorY0[i] = sA0->GetY(ixy0);
797         fSPDsectorX1[i] = sA0->GetX(ixy1);
798         fSPDsectorY1[i] = sA0->GetY(ixy1);
799     } // end for i
800
801     //printf("SectorA#%d ",0);
802     InsidePoint(xpp[m-1],ypp[m-1],xpp[0],ypp[0],xpp[1],ypp[1],ksecCthick,
803                 xpp2[0],ypp2[0]);
804     for(i = 1; i < m - 1; i++) {
805         j = i / (ksecNPointsPerRadii+1);
806         //printf("SectorA#%d ",i);
807         InsidePoint(xpp[i-1],ypp[i-1],xpp[i],ypp[i],xpp[i+1],ypp[i+1],
808                     ksecCthick,xpp2[i],ypp2[i]);
809     } // end for i
810     //printf("SectorA#%d ",m);
811     InsidePoint(xpp[m-2],ypp[m-2],xpp[m-1],ypp[m-1],xpp[0],ypp[0],
812                 ksecCthick,xpp2[m-1],ypp2[m-1]);
813     // Fix center value of cooling tube dip and
814     // find location of cooling tube centers
815     for(i = 0; i < ksecNCoolingTubeDips; i++) {
816         j = ksecDipIndex[i];
817         x0 = xp2[j][1];
818         y0 = yp2[j][1];
819         x1 = xp2[j][ksecNPointsPerRadii-1];
820         y1 = yp2[j][ksecNPointsPerRadii-1];
821         t0 = TMath::Sqrt((x0-x1)*(x0-x1)+(y0-y1)*(y0-y1));
822         t  = secDip2[i]/t0;
823         for(k = 2; k < ksecNPointsPerRadii - 1; k++) {
824             // extra points spread them out.
825             t = ((Double_t)(k-1)) * t0;
826             xp2[j][k] = x0+(x1-x0) * t;
827             yp2[j][k] = y0+(y1-y0) * t;
828         } // end for k
829     } // end for i
830     sA1 = new TGeoXtru(2);
831     sA1->SetName("ITS SPD Carbon fiber support Sector Air A1");
832     sA1->DefinePolygon(m, xpp2, ypp2);
833     sA1->DefineSection(0, -ksecDz);
834     sA1->DefineSection(1,  ksecDz);
835     //
836     // Error in TGeoEltu. Semi-axis X must be < Semi-axis Y (?).
837     sTA0 = new TGeoEltu("ITS SPD Cooling Tube TA0", 0.5 * ksecCoolTubeFlatY,
838                         0.5 * ksecCoolTubeFlatX, ksecDz);
839     sTA1 = new TGeoEltu("ITS SPD Cooling Tube coolant TA1",
840                         sTA0->GetA() - ksecCoolTubeThick,
841                         sTA0->GetB()-ksecCoolTubeThick,ksecDz);
842     SPDsectorShape(ksecNRadii,secX2,secY2,secR2,secAngleStart2,secAngleEnd2,
843                    ksecNPointsPerRadii, m, xp, yp);
844     sB0 = new TGeoXtru(2);
845     sB0->SetName("ITS SPD Carbon fiber support Sector End B0");
846     sB0->DefinePolygon(m, xpp, ypp);
847     sB0->DefineSection(0, ksecDz);
848     sB0->DefineSection(1, ksecDz + ksecZEndLen);
849
850     //printf("SectorB#%d ",0);
851   // Points around the most sharpened tips have to be avoided - M.S. 24 feb 09
852     const Int_t nSpecialPoints = 5;
853     const Int_t kSpecialPoints[nSpecialPoints] = {7, 17, 47, 62, 77};
854     Int_t i2 = 0;
855     InsidePoint(xpp[m-1],ypp[m-1],xpp[0],ypp[0],xpp[1],ypp[1],
856                 ksecCthick2,xpp2[i2],ypp2[i2]);
857     for(i = 1; i < m - 1; i++) {
858         t = ksecCthick2;
859         for(k = 0; k < ksecNCoolingTubeDips; k++)
860             if((i/(ksecNPointsPerRadii+1))==ksecDipIndex[k])
861                 if(!(ksecDipIndex[k]*(ksecNPointsPerRadii+1) == i ||
862                      ksecDipIndex[k]*(ksecNPointsPerRadii+1) +
863                      ksecNPointsPerRadii == i))
864                     t = ksecRCoolOut-ksecRCoolIn;
865         //printf("SectorB#%d ",i);
866         Bool_t useThisPoint = kTRUE;
867         for(Int_t ii = 0; ii < nSpecialPoints; ii++)
868           if ( (i == kSpecialPoints[ii] - 1) ||
869                (i == kSpecialPoints[ii] + 1)   ) useThisPoint = kFALSE;
870         if (useThisPoint) {
871           i2++;
872           InsidePoint(xpp[i-1],ypp[i-1],xpp[i],ypp[i],xpp[i+1],ypp[i+1],t,
873                       xpp2[i2],ypp2[i2]);
874         }
875     }// end for i
876     //printf("SectorB#%d ",m);
877     i2++;
878     InsidePoint(xpp[m-2],ypp[m-2],xpp[m-1],ypp[m-1],xpp[0],ypp[0],
879                 ksecCthick2,xpp2[i2],ypp2[i2]);
880     sB1 = new TGeoXtru(2);
881     sB1->SetName("ITS SPD Carbon fiber support Sector Air End B1");
882     sB1->DefinePolygon(i2+1, xpp2, ypp2);
883     sB1->DefineSection(0,sB0->GetZ(0));
884     sB1->DefineSection(1,sB0->GetZ(1)-ksecCthick2);
885     const Double_t kspdEndHoleRadius1=5.698*fgkmm;
886     const Double_t kspdEndHoleRadius2=2.336*fgkmm;
887     const Double_t kspdEndHoleDisplacement=6.29*fgkmm;
888     k = (m-1)/4;
889     for(i=0;i<=k;i++){
890         t= ((Double_t)i)/((Double_t)(k));
891         if(!CFHolePoints(t,kspdEndHoleRadius1,kspdEndHoleRadius2,
892                          kspdEndHoleDisplacement,xpp2[i],ypp2[i])){
893             Warning("CarbonFiberSector","CFHolePoints failed "
894                     "i=%d m=%d k=%d t=%e",i,m,k,t);
895         } // end if
896         // simitry in each quadrant.
897         xpp2[2*k-i] = -xpp2[i];
898         ypp2[2*k-i] =  ypp2[i];
899         xpp2[2*k+i] = -xpp2[i];
900         ypp2[2*k+i] = -ypp2[i];
901         xpp2[4*k-i] =  xpp2[i];
902         ypp2[4*k-i] = -ypp2[i];
903     }// end for i
904     //xpp2[m-1] = xpp2[0]; // begining point in
905     //ypp2[m-1] = ypp2[0]; // comment with end point
906     sB2 = new TGeoXtru(2);
907     sB2->SetName("ITS SPD Hole in Carbon fiber support End plate");
908     sB2->DefinePolygon(4*k, xpp2, ypp2);
909     sB2->DefineSection(0,sB1->GetZ(1));
910     sB2->DefineSection(1,sB0->GetZ(1));
911     // SPD sector mount blocks
912     const Double_t kMountBlock[3] = {0.5*(1.8-0.2)*fgkmm,0.5*22.0*fgkmm,
913                                      0.5*45.0*fgkmm};
914     sB3 = new TGeoBBox((Double_t*)kMountBlock);
915     // SPD sector cooling tubes
916     sTB0 = new TGeoTube("ITS SPD Cooling Tube End TB0", 0.0,
917                    0.5*ksecCoolTubeROuter,0.5*(sB1->GetZ(1)-sB1->GetZ(0)));
918     sTB1 = new TGeoTube("ITS SPD Cooling Tube End coolant TB0", 0.0,
919                         sTB0->GetRmax() - ksecCoolTubeThick,sTB0->GetDz());
920     //
921     if(GetDebug(3)) {
922         if(medSPDcf) medSPDcf->Dump(); else AliInfo("medSPDcf = 0");
923         if(medSPDss) medSPDss->Dump(); else AliInfo("medSPDss = 0");
924         if(medSPDair) medSPDair->Dump(); else AliInfo("medSPDAir = 0");
925         if(medSPDcoolfl) medSPDcoolfl->Dump();else AliInfo("medSPDcoolfl = 0");
926         sA0->InspectShape();
927         sA1->InspectShape();
928         sB0->InspectShape();
929         sB1->InspectShape();
930         sB2->InspectShape();
931     } // end if(GetDebug(3))
932
933     // create the assembly of the support and place staves on it
934     TGeoVolumeAssembly *vM0 = new TGeoVolumeAssembly(
935                                          "ITSSPDSensitiveVirtualvolumeM0");
936     StavesInSector(vM0);
937     // create other volumes with some graphical settings
938     TGeoVolume *vA0 = new TGeoVolume("ITSSPDCarbonFiberSupportSectorA0",
939                                      sA0, medSPDcf);
940     vA0->SetVisibility(kTRUE);
941     vA0->SetLineColor(4); // Blue
942     vA0->SetLineWidth(1);
943     vA0->SetFillColor(vA0->GetLineColor());
944     vA0->SetFillStyle(4010); // 10% transparent
945     TGeoVolume *vA1 = new TGeoVolume("ITSSPDCarbonFiberSupportSectorAirA1",
946                                      sA1, medSPDair);
947     vA1->SetVisibility(kTRUE);
948     vA1->SetLineColor(7); // light Blue
949     vA1->SetLineWidth(1);
950     vA1->SetFillColor(vA1->GetLineColor());
951     vA1->SetFillStyle(4090); // 90% transparent
952     TGeoVolume *vTA0 = new TGeoVolume("ITSSPDCoolingTubeTA0", sTA0, medSPDss);
953     vTA0->SetVisibility(kTRUE);
954     vTA0->SetLineColor(15); // gray
955     vTA0->SetLineWidth(1);
956     vTA0->SetFillColor(vTA0->GetLineColor());
957     vTA0->SetFillStyle(4000); // 0% transparent
958     TGeoVolume *vTA1 = new TGeoVolume("ITSSPDCoolingTubeFluidTA1",
959                                       sTA1, medSPDcoolfl);
960     vTA1->SetVisibility(kTRUE);
961     vTA1->SetLineColor(6); // Purple
962     vTA1->SetLineWidth(1);
963     vTA1->SetFillColor(vTA1->GetLineColor());
964     vTA1->SetFillStyle(4000); // 0% transparent
965     TGeoVolume *vB0 = new TGeoVolume("ITSSPDCarbonFiberSupportSectorEndB0",
966                                      sB0, medSPDcf);
967     vB0->SetVisibility(kTRUE);
968     vB0->SetLineColor(1); // Black
969     vB0->SetLineWidth(1);
970     vB0->SetFillColor(vB0->GetLineColor());
971     vB0->SetFillStyle(4000); // 0% transparent
972     TGeoVolume *vB1 = new TGeoVolume("ITSSPDCarbonFiberSupportSectorEndAirB1",
973                                      sB1, medSPDair);
974     vB1->SetVisibility(kTRUE);
975     vB1->SetLineColor(0); // white
976     vB1->SetLineWidth(1);
977     vB1->SetFillColor(vB1->GetLineColor());
978     vB1->SetFillStyle(4100); // 100% transparent
979     TGeoVolume *vB2 = new TGeoVolume("ITSSPDCarbonFiberSupportSectorEndAirB2",
980                                      sB2, medSPDair);
981     vB2->SetVisibility(kTRUE);
982     vB2->SetLineColor(0); // white
983     vB2->SetLineWidth(1);
984     vB2->SetFillColor(vB2->GetLineColor());
985     vB2->SetFillStyle(4100); // 100% transparent
986     TGeoVolume *vB3 = new TGeoVolume(
987         "ITSSPDCarbonFiberSupportSectorMountBlockB3",sB3, medSPDcf);
988     vB3->SetVisibility(kTRUE);
989     vB3->SetLineColor(1); // Black
990     vB3->SetLineWidth(1);
991     vB3->SetFillColor(vB3->GetLineColor());
992     vB3->SetFillStyle(4000); // 0% transparent
993     TGeoVolume *vTB0 = new TGeoVolume("ITSSPDCoolingTubeEndTB0",sTB0,medSPDss);
994     vTB0->SetVisibility(kTRUE);
995     vTB0->SetLineColor(15); // gray
996     vTB0->SetLineWidth(1);
997     vTB0->SetFillColor(vTB0->GetLineColor());
998     vTB0->SetFillStyle(4000); // 0% transparent
999     TGeoVolume *vTB1 = new TGeoVolume("ITSSPDCoolingTubeEndFluidTB1",sTB1,
1000                                       medSPDcoolfl);
1001     vTB1->SetVisibility(kTRUE);
1002     vTB1->SetLineColor(7); // light blue
1003     vTB1->SetLineWidth(1);
1004     vTB1->SetFillColor(vTB1->GetLineColor());
1005     vTB1->SetFillStyle(4050); // 0% transparent
1006
1007     // add volumes to mother container passed as argument of this method
1008     moth->AddNode(vM0,1,0); // Add virtual volume to mother
1009     vA0->AddNode(vA1,1,0); // Put air inside carbon fiber.
1010     vB0->AddNode(vB1,1,0); // Put air inside carbon fiber ends.
1011     vB0->AddNode(vB2,1,0); // Put air wholes inside carbon fiber ends
1012     vTA0->AddNode(vTA1,1,0); // Put cooling liquid indide tube middel.
1013     vTB0->AddNode(vTB1,1,0); // Put cooling liquid inside tube end.
1014     Double_t tubeEndLocal[3]={0.0,0.0,sTA0->GetDz()};
1015     for(i = 0; i < ksecNCoolingTubeDips; i++) {
1016         x0 = secX3[ksecDipIndex[i]];
1017         y0 = secY3[ksecDipIndex[i]];
1018         t = 90.0 - secAngleTurbo[i];
1019         trans = new TGeoTranslation("",x0,y0,0.5*(sB1->GetZ(0)+sB1->GetZ(1)));
1020         vB1->AddNode(vTB0, i+1, trans);
1021         // Find location of tube ends for later use.
1022         trans->LocalToMaster(tubeEndLocal,fTubeEndSector[0][0][i]);
1023         rot = new TGeoRotation("", 0.0, 0.0, t);
1024         rotrans = new TGeoCombiTrans("", x0, y0, 0.0, rot);
1025         vM0->AddNode(vTA0, i+1, rotrans);
1026     } // end for i
1027     vM0->AddNode(vA0, 1, 0);
1028     vM0->AddNode(vB0, 1, 0);
1029     // Reflection.
1030     rot = new TGeoRotation("", 90., 0., 90., 90., 180., 0.);
1031     vM0->AddNode(vB0,2,rot);
1032     // Find location of tube ends for later use.
1033     for(i=0;i<ksecNCoolingTubeDips;i++) rot->LocalToMaster(
1034                             fTubeEndSector[0][0][i],fTubeEndSector[0][1][i]);
1035     // left side
1036     t = -TMath::RadToDeg()*TMath::ATan2(
1037                                    sB0->GetX(0)-sB0->GetX(sB0->GetNvert()-1),
1038                                    sB0->GetY(0)-sB0->GetY(sB0->GetNvert()-1));
1039     rot = new TGeoRotation("",t,0.0,0.0);// z axis rotation
1040     x0 = 0.5*(sB0->GetX(0)+sB0->GetX(sB0->GetNvert()-1))+
1041         sB3->GetDX()*TMath::Cos(t*TMath::DegToRad());
1042     y0 = 0.5*(sB0->GetY(0)+sB0->GetY(sB0->GetNvert()-1))+
1043         sB3->GetDX()*TMath::Sin(t*TMath::DegToRad());
1044     z0 = sB0->GetZ(0)+sB3->GetDZ();
1045     rotrans = new TGeoCombiTrans("",x0,y0,z0,rot);
1046     vM0->AddNode(vB3,1,rotrans); // Put Mounting bracket on sector
1047     rotrans = new TGeoCombiTrans("",x0,y0,-z0,rot);
1048     vM0->AddNode(vB3,2,rotrans); // Put Mounting bracket on sector
1049     t *= -1.0;
1050     rot = new TGeoRotation("",t,0.0,0.0); // z axis rotation
1051   
1052     x0 = -0.5*(sB0->GetX(0)+sB0->GetX(sB0->GetNvert()-1))-3.5*
1053         sB3->GetDX()*TMath::Cos(t*TMath::DegToRad());
1054     y0 = 0.5*(sB0->GetY(0)+sB0->GetY(sB0->GetNvert()-1))-3.5*
1055         sB3->GetDX()*TMath::Sin(t*TMath::DegToRad());
1056     rotrans = new TGeoCombiTrans("",1.01*x0,y0,z0,rot);
1057     vM0->AddNode(vB3,3,rotrans); // Put Mounting bracket on sector
1058     rotrans = new TGeoCombiTrans("",1.01*x0,y0,-z0,rot);
1059     vM0->AddNode(vB3,4,rotrans); // Put Mounting bracket on sector
1060     if(GetDebug(3)){
1061         vM0->PrintNodes();
1062         vA0->PrintNodes();
1063         vA1->PrintNodes();
1064         vB0->PrintNodes();
1065         vB1->PrintNodes();
1066         vB2->PrintNodes();
1067         vB3->PrintNodes();
1068         vTA0->PrintNodes();
1069         vTA1->PrintNodes();
1070         vTB0->PrintNodes();
1071         vTB1->PrintNodes();
1072     } // end if(GetDebug(3))
1073 }
1074 //______________________________________________________________________
1075 Bool_t AliITSv11GeometrySPD::CFHolePoints(Double_t s,Double_t r1,
1076                    Double_t r2,Double_t l,Double_t &x,Double_t &y) const
1077 {
1078     //
1079     // Step along arck a distancs ds and compute boundry of
1080     // two holes (radius r1 and r2) a distance l apart (along
1081     // x-axis).
1082     // Inputs:
1083     //   Double_t s   fractional Distance along arcs [0-1]
1084     //                where 0-> alpha=beta=0, 1-> alpha=90 degrees.
1085     //   Double_t r1  radius at center circle
1086     //   Double_t r2  radius of displaced circle
1087     //   Double_t l   Distance displaced circle is displaces (x-axis)
1088     // Output:
1089     //   Double_t x   x coordinate along double circle.
1090     //   Double_t y   y coordinate along double circle.
1091     // Return:
1092     //   logical, kFALSE if an error
1093     //
1094     Double_t alpha,beta;
1095     Double_t ac,bc,scb,sca,t,alphac,betac; // at intersection of two circles
1096
1097     x=y=0.0;
1098     ac = r1*r1-l*l-r2*r2;
1099     bc = 2.*l*r2;
1100     if(bc==0.0) {printf("bc=0 l=%e r2=%e\n",l,r2);return kFALSE;}
1101     betac = TMath::ACos(ac/bc);
1102     alphac = TMath::Sqrt((bc-ac)*(bc+ac))/(2.*l*r1);
1103     scb = r2*betac;
1104     sca = r1*alphac;
1105     t = r1*0.5*TMath::Pi() - sca + scb;
1106     if(s<= scb/t){
1107         beta = s*t/r2;
1108         x = r2*TMath::Cos(beta) + l;
1109         y = r2*TMath::Sin(beta);
1110         //printf("betac=%e scb=%e t=%e s=%e beta=%e x=%e y=%e\n",
1111         //       betac,scb,t,s,beta,x,y);
1112         return kTRUE;
1113     }else{
1114         beta = (s*t-scb+sca)/(r1*0.5*TMath::Pi());
1115         alpha = beta*0.5*TMath::Pi();
1116         x = r1*TMath::Cos(alpha);
1117         y = r1*TMath::Sin(alpha);
1118         //printf("alphac=%e sca=%e t=%e s=%e beta=%e alpha=%e x=%e y=%e\n",
1119         //       alphac,sca,t,s,beta,alpha,x,y);
1120         return kTRUE;
1121     } // end if
1122     return kFALSE;
1123 }
1124 //______________________________________________________________________
1125 Bool_t AliITSv11GeometrySPD::GetSectorMountingPoints(Int_t index,Double_t &x0,
1126                               Double_t &y0, Double_t &x1, Double_t &y1) const
1127 {
1128     //
1129     // Returns the edges of the straight borders in the SPD sector shape,
1130     // which are used to mount staves on them.
1131     // Coordinate system is that of the carbon fiber sector volume.
1132     // ---
1133     // Index numbering is as follows:
1134     //                         /5
1135     //                        /\/4
1136     //                      1\   \/3
1137     //                      0|___\/2
1138     // ---
1139     // Arguments [the ones passed by reference contain output values]:
1140     //    Int_t    index   --> location index according to above scheme [0-5]
1141     //    Double_t &x0     --> (by ref) x0 location or the ladder sector [cm]
1142     //    Double_t &y0     --> (by ref) y0 location of the ladder sector [cm]
1143     //    Double_t &x1     --> (by ref) x1 location or the ladder sector [cm]
1144     //    Double_t &y1     --> (by ref) y1 location of the ladder sector [cm]
1145     //    TGeoManager *mgr --> The TGeo builder
1146     // ---
1147     // The location is described by a line going from (x0, y0) to (x1, y1)
1148     // ---
1149     // Returns kTRUE if no problems encountered.
1150     // Returns kFALSE if a problem was encountered (e.g.: shape not found).
1151     //
1152     Int_t isize = fSPDsectorX0.GetSize();
1153
1154     x0 = x1 = y0 = y1 = 0.0;
1155     if(index < 0 || index > isize) {
1156       AliError(Form("index = %d: allowed 0 --> %d", index, isize));
1157       return kFALSE;
1158     } // end if(index<0||index>isize)
1159     x0 = fSPDsectorX0[index];
1160     x1 = fSPDsectorX1[index];
1161     y0 = fSPDsectorY0[index];
1162     y1 = fSPDsectorY1[index];
1163     return kTRUE;
1164 }
1165 //______________________________________________________________________
1166 void AliITSv11GeometrySPD::SPDsectorShape(Int_t n,const Double_t *xc,
1167                               const Double_t *yc,  const Double_t *r,
1168                               const Double_t *ths, const Double_t *the,
1169                       Int_t npr, Int_t &m, Double_t **xp, Double_t **yp) const
1170 {
1171     //
1172     // Code to compute the points that make up the shape of the SPD
1173     // Carbon fiber support sections
1174     // Inputs:
1175     //   Int_t n        size of arrays xc,yc, and r.
1176     //   Double_t *xc   array of x values for radii centers.
1177     //   Double_t *yc   array of y values for radii centers.
1178     //   Double_t *r    array of signed radii values.
1179     //   Double_t *ths  array of starting angles [degrees].
1180     //   Double_t *the  array of ending angles [degrees].
1181     //   Int_t     npr  the number of lines segments to aproximate the arc.
1182     // Outputs (arguments passed by reference):
1183     //   Int_t       m    the number of enetries in the arrays *xp[npr+1]
1184     //                    and *yp[npr+1].
1185     //   Double_t **xp    array of x coordinate values of the line segments
1186     //                    which make up the SPD support sector shape.
1187     //   Double_t **yp    array of y coordinate values of the line segments
1188     //                    which make up the SPD support sector shape.
1189     //
1190     Int_t    i, k;
1191     Double_t t, t0, t1;
1192
1193     m = n*(npr + 1);
1194     if(GetDebug(2)) {
1195         cout <<"  X    \t  Y  \t  R  \t  S  \t  E" << m << endl;
1196         for(i = 0; i < n; i++) {
1197             cout << "{"    << xc[i] << ", ";
1198             cout << yc[i]  << ", ";
1199             cout << r[i]   << ", ";
1200             cout << ths[i] << ", ";
1201             cout << the[i] << "}, " << endl;
1202         } // end for i
1203     } // end if(GetDebug(2))
1204     if (GetDebug(3)) cout << "Double_t sA0 = [" << n*(npr+1)+1<<"][";
1205     if (GetDebug(4)) cout << "3] {";
1206     else if(GetDebug(3)) cout <<"2] {";
1207     t0 = (Double_t)npr;
1208     for(i = 0; i < n; i++) {
1209         t1 = (the[i] - ths[i]) / t0;
1210         if(GetDebug(5)) cout << "t1 = " << t1 << endl;
1211         for(k = 0; k <= npr; k++) {
1212             t = ths[i] + ((Double_t)k) * t1;
1213             xp[i][k] = TMath::Abs(r[i]) * CosD(t) + xc[i];
1214             yp[i][k] = TMath::Abs(r[i]) * SinD(t) + yc[i];
1215             if(GetDebug(3)) {
1216                 cout << "{" << xp[i][k] << "," << yp[i][k];
1217                 if (GetDebug(4)) cout << "," << t;
1218                 cout << "},";
1219             } // end if GetDebug
1220         } // end for k
1221         if(GetDebug(3)) cout << endl;
1222     } // end of i
1223     if(GetDebug(3)) cout << "{"  << xp[0][0] << ", " << yp[0][0];
1224     if(GetDebug(4)) cout << ","  << ths[0];
1225     if(GetDebug(3)) cout << "}}" << endl;
1226 }
1227
1228 //______________________________________________________________________
1229 TGeoVolume* AliITSv11GeometrySPD::CreateLadder(Int_t layer,TArrayD &sizes,
1230                                                TGeoManager *mgr) const
1231 {
1232     //
1233     // Creates the "ladder" = silicon sensor + 5 chips.
1234     // Returns a TGeoVolume containing the following components:
1235     //  - the sensor (TGeoBBox), whose name depends on the layer
1236     //  - 5 identical chips (TGeoBBox)
1237     //  - a guard ring around the sensor (subtraction of TGeoBBoxes),
1238     //    which is separated from the rest of sensor because it is not
1239     //    a sensitive part
1240     //  - bump bondings (TGeoBBox stripes for the whole width of the
1241     //    sensor, one per column).
1242     // ---
1243     // Arguments:
1244     //  1 - the owner layer (MUST be 1 or 2 or a fatal error is raised)
1245     //  2 - a TArrayD passed by reference, which will contain relevant
1246     //      dimensions related to this object:
1247     //      size[0] = 'thickness' (the smallest dimension)
1248     //      size[1] = 'length' (the direction along the ALICE Z axis)
1249     //      size[2] = 'width' (extension in the direction perp. to the
1250     //                         above ones)
1251     //  3 - the used TGeoManager
1252
1253     // ** CRITICAL CHECK **
1254     // layer number can be ONLY 1 or 2
1255     if (layer != 1 && layer != 2) AliFatal("Layer number MUST be 1 or 2");
1256
1257     // ** MEDIA **
1258     TGeoMedium *medAir       = GetMedium("AIR$",mgr);
1259     TGeoMedium *medSPDSiChip = GetMedium("SPD SI CHIP$",mgr); // SPD SI CHIP
1260     TGeoMedium *medSi        = GetMedium("SI$",mgr);
1261     TGeoMedium *medBumpBond  = GetMedium("COPPER$",mgr);  // ??? BumpBond
1262
1263     // ** SIZES **
1264     Double_t chipThickness  = fgkmm *  0.150;
1265     Double_t chipWidth      = fgkmm * 15.950;
1266     Double_t chipLength     = fgkmm * 13.600;
1267     Double_t chipSpacing    = fgkmm *  0.400; // separation of chips along Z
1268     Double_t sensThickness  = fgkmm *  0.200;
1269     Double_t sensLength     = fgkmm * 69.600;
1270     Double_t sensWidth      = fgkmm * 12.800;
1271     Double_t guardRingWidth = fgkmm *  0.560; // a border of this thickness
1272                                               // all around the sensor
1273     Double_t bbLength       = fgkmm * 0.042;
1274     Double_t bbWidth        = sensWidth;
1275     Double_t bbThickness    = fgkmm * 0.012;
1276     Double_t bbPos          = 0.080;  // Z position w.r. to left pixel edge
1277     // compute the size of the container volume which
1278     // will also be returned in the referenced TArrayD;
1279     // for readability, they are linked by reference to a more meaningful name
1280     sizes.Set(3);
1281     Double_t &thickness = sizes[0];
1282     Double_t &length = sizes[1];
1283     Double_t &width = sizes[2];
1284     // the container is a box which exactly enclose all the stuff;
1285     width = chipWidth;
1286     length = sensLength + 2.0*guardRingWidth;
1287     thickness = sensThickness + chipThickness + bbThickness;
1288
1289     // ** VOLUMES **
1290     // While creating this volume, since it is a sensitive volume,
1291     // we must respect some standard criteria for its local reference frame.
1292     // Local X must correspond to x coordinate of the sensitive volume:
1293     // this means that we are going to create the container with a local
1294     // reference system that is **not** in the middle of the box.
1295     // This is accomplished by calling the shape constructor with an
1296     // additional option ('originShift'):
1297     Double_t xSens = 0.5 * (width - sensWidth - 2.0*guardRingWidth);
1298     Double_t originShift[3] = {-xSens, 0., 0.};
1299     TGeoBBox *shapeContainer = new TGeoBBox(0.5*width,0.5*thickness,
1300                                             0.5*length,originShift);
1301     // then the volume is made of air, and using this shape
1302     TGeoVolume *container = new TGeoVolume(Form("ITSSPDlay%d-Ladder",layer),
1303                                            shapeContainer, medAir);
1304     // the chip is a common box
1305     TGeoVolume *volChip = mgr->MakeBox("ITSSPDchip",medSPDSiChip,
1306                               0.5*chipWidth,0.5*chipThickness,0.5*chipLength);
1307     // the sensor as well
1308     TGeoVolume *volSens = mgr->MakeBox(GetSenstiveVolumeName(layer),medSi,
1309                              0.5*sensWidth,0.5*sensThickness,0.5*sensLength);
1310     // the guard ring shape is the subtraction of two boxes with the
1311     // same center.
1312     TGeoBBox  *shIn = new TGeoBBox(0.5*sensWidth,sensThickness,0.5*sensLength);
1313     TGeoBBox  *shOut = new TGeoBBox(0.5*sensWidth+guardRingWidth,
1314                               0.5*sensThickness,0.5*sensLength+guardRingWidth);
1315     shIn->SetName("ITSSPDinnerBox");
1316     shOut->SetName("ITSSPDouterBox");
1317     TGeoCompositeShape *shBorder = new TGeoCompositeShape(
1318       "ITSSPDgaurdRingBorder",Form("%s-%s",shOut->GetName(),shIn->GetName()));
1319     TGeoVolume *volBorder = new TGeoVolume("ITSSPDgaurdRing",shBorder,medSi);
1320     // bump bonds for one whole column
1321     TGeoVolume *volBB = mgr->MakeBox("ITSSPDbb",medBumpBond,0.5*bbWidth,
1322                                      0.5*bbThickness,0.5*bbLength);
1323     // set colors of all objects for visualization
1324     volSens->SetLineColor(kYellow + 1);
1325     volChip->SetLineColor(kGreen);
1326     volBorder->SetLineColor(kYellow + 3);
1327     volBB->SetLineColor(kGray);
1328
1329     // ** MOVEMENTS **
1330     // sensor is translated along thickness (X) and width (Y)
1331     Double_t ySens = 0.5 * (thickness - sensThickness);
1332     Double_t zSens = 0.0;
1333     // we want that the x of the ladder is the same as the one of
1334     // its sensitive volume
1335     TGeoTranslation *trSens = new TGeoTranslation(0.0, ySens, zSens);
1336     // bump bonds are translated along all axes:
1337     // keep same Y used for sensors, but change the Z
1338     TGeoTranslation *trBB[160];
1339     Double_t x =  0.0;
1340     Double_t y =  0.5 * (thickness - bbThickness) - sensThickness;
1341     Double_t z = -0.5 * sensLength + guardRingWidth + fgkmm*0.425 - bbPos;
1342     Int_t i;
1343     for (i = 0; i < 160; i++) {
1344         trBB[i] = new TGeoTranslation(x, y, z);
1345         switch(i) {
1346         case  31:case  63:case  95:case 127:
1347             z += fgkmm * 0.625 + fgkmm * 0.2;
1348             break;
1349         default:
1350             z += fgkmm * 0.425;
1351         } // end switch
1352     } // end for i
1353     // the chips are translated along the length (Z) and thickness (X)
1354     TGeoTranslation *trChip[5] = {0, 0, 0, 0, 0};
1355     x = -xSens;
1356     y = 0.5 * (chipThickness - thickness);
1357     z = 0.0;
1358     for (i = 0; i < 5; i++) {
1359         z = -0.5*length + guardRingWidth
1360             + (Double_t)i*chipSpacing + ((Double_t)(i) + 0.5)*chipLength;
1361         trChip[i] = new TGeoTranslation(x, y, z);
1362     } // end ofr i
1363
1364     // add nodes to container
1365     container->AddNode(volSens, 1, trSens);
1366     container->AddNode(volBorder, 1, trSens);
1367     for (i = 0; i < 160; i++) container->AddNode(volBB,i+1,trBB[i]);
1368     for (i = 0; i < 5; i++) container->AddNode(volChip,i+3,trChip[i]);
1369     // return the container
1370     return container;
1371 }
1372
1373 //______________________________________________________________________
1374 TGeoVolume* AliITSv11GeometrySPD::CreateClip(TArrayD &sizes,Bool_t isDummy,
1375                                              TGeoManager *mgr) const
1376 {
1377     //
1378     // Creates the carbon fiber clips which are added to the central ladders.
1379     // They have a complicated shape which is approximated by a TGeoXtru
1380     // Implementation of a single clip over an half-stave.
1381     // It has a complicated shape which is approximated to a section like this:
1382     //
1383     //     6
1384     //     /\   .
1385     //  7 //\\  5
1386     //    / 1\\___________________4
1387     //   0    \___________________
1388     //        2                   3
1389     // with a finite thickness for all the shape
1390     // Its local reference frame is such that point A corresponds to origin.
1391     //
1392
1393   // MODIFIED geometry
1394     Double_t sposty = fgkmm * -0.5; // lower internal side to avoid overlaps with modified geometry
1395
1396     Double_t fullLength      = fgkmm * 12.6;    // = x4 - x0
1397     Double_t flatLength      = fgkmm *  5.4;    // = x4 - x3
1398     Double_t inclLongLength  = fgkmm *  5.0;    // = 5-6
1399     Double_t inclShortLength = fgkmm *  2.0;    // = 6-7
1400     Double_t fullHeight      = fgkmm *  2.8;    // = y6 - y3
1401     Double_t thickness       = fgkmm *  0.18;    // thickness
1402     Double_t totalLength     = fgkmm * 52.0;    // total length in Z
1403     Double_t holeSize        = fgkmm *  5.0;    // dimension of cubic
1404                                                 // hole inserted for pt1000
1405     Double_t angle1          = 27.0;            // supplementary of angle DCB
1406     Double_t angle2;                            // angle DCB
1407     Double_t angle3;                            // angle of GH with vertical
1408
1409     angle2 = 0.5 * (180.0 - angle1);
1410     angle3 = 90.0 - TMath::ACos(fullLength - flatLength -
1411                                 inclLongLength*TMath::Cos(angle1)) *
1412                                 TMath::RadToDeg();
1413     angle1 *= TMath::DegToRad();
1414     angle2 *= TMath::DegToRad();
1415     angle3 *= TMath::DegToRad();
1416
1417     Double_t x[8], y[8];
1418
1419     x[0] =  0.0;
1420     x[1] = x[0] + fullLength - flatLength - inclLongLength*TMath::Cos(angle1);
1421     x[2] = x[0] + fullLength - flatLength;
1422     x[3] = x[0] + fullLength;
1423     x[4] = x[3];
1424     x[5] = x[4] - flatLength + thickness * TMath::Cos(angle2);
1425     x[6] = x[1];
1426     x[7] = x[0];
1427
1428     y[0] = 0.0;
1429     y[1] = y[0] + inclShortLength * TMath::Cos(angle3);
1430     y[2] = y[1] - inclLongLength * TMath::Sin(angle1);
1431     y[3] = y[2];
1432     y[4] = y[3] + thickness;
1433     y[5] = y[4];
1434     y[6] = y[1] + thickness;
1435     y[7] = y[0] + thickness;
1436
1437     y[0] += sposty;
1438     y[7] += sposty;
1439
1440     sizes.Set(7);
1441     sizes[0] = totalLength;
1442     sizes[1] = fullHeight;
1443     sizes[2] = y[2];
1444     sizes[3] = y[6];
1445     sizes[4] = x[0];
1446     sizes[5] = x[3];
1447     sizes[6] = x[2];
1448
1449     if(isDummy){// use this argument when on ewant just the
1450                 // positions without create any volume
1451         return NULL;
1452     } // end if isDummy
1453
1454     TGeoXtru *shClip = new TGeoXtru(2);
1455     shClip->SetName("ITSSPDshclip");
1456     shClip->DefinePolygon(8, x, y);
1457     shClip->DefineSection(0, -0.5*totalLength, 0., 0., 1.0);
1458     shClip->DefineSection(1,  0.5*totalLength, 0., 0., 1.0);
1459
1460     TGeoBBox *shHole = new TGeoBBox("ITSSPDSHClipHole",0.5*holeSize,
1461                                     0.5*holeSize,0.5*holeSize);
1462     TGeoTranslation *tr1 = new TGeoTranslation("ITSSPDTRClipHole1",x[2],0.0,
1463                                                fgkmm*14.);
1464     TGeoTranslation *tr2 = new TGeoTranslation("ITSSPDTRClipHole2",x[2],0.0,
1465                                                0.0);
1466     TGeoTranslation *tr3 = new TGeoTranslation("ITSSPDTRClipHole3",x[2],0.0,
1467                                                -fgkmm*14.);
1468     tr1->RegisterYourself();
1469     tr2->RegisterYourself();
1470     tr3->RegisterYourself();
1471
1472     //TString strExpr("ITSSPDshclip-(");
1473     TString strExpr(shClip->GetName());
1474     strExpr.Append("-(");
1475     strExpr.Append(Form("%s:%s+", shHole->GetName(), tr1->GetName()));
1476     strExpr.Append(Form("%s:%s+", shHole->GetName(), tr2->GetName()));
1477     strExpr.Append(Form("%s:%s)", shHole->GetName(), tr3->GetName()));
1478     TGeoCompositeShape *shClipHole = new TGeoCompositeShape(
1479         "ITSSPDSHClipHoles",strExpr.Data());
1480
1481     TGeoMedium *mat = GetMedium("SPD C (M55J)$", mgr);
1482     TGeoVolume *vClip = new TGeoVolume("ITSSPDclip", shClipHole, mat);
1483     vClip->SetLineColor(kGray + 2);
1484     return vClip;
1485 }
1486
1487 //______________________________________________________________________
1488 TGeoVolume* AliITSv11GeometrySPD::CreatePatchPanel(TArrayD &sizes,
1489                                                    TGeoManager *mgr) const
1490 {
1491     //
1492     // Creates the patch panel approximated with a "L"-shaped TGeoXtru
1493     // with a finite thickness for all the shape
1494     // Its local reference frame is such that point A corresponds to origin.
1495     //
1496     Double_t hLength         = fgkmm *  50.0;    // horizontal length
1497     Double_t vLength         = fgkmm *  50.0;    // vertical length
1498     Double_t angle           = 88.3;             // angle between hor and vert
1499     Double_t thickness       = fgkmm *   4.0;    // thickness
1500     Double_t width           = fgkmm * 100.0;    // width looking from cone
1501
1502     Double_t x[7], y[7];
1503
1504     y[0] =  0.0;
1505     y[1] = y[0] + hLength;
1506     y[2] = y[1];
1507     y[3] = y[0] + thickness;
1508     y[4] = y[3] + vLength * TMath::Cos(angle*TMath::DegToRad());
1509     y[5] = y[4] - thickness / TMath::Sin(angle*TMath::DegToRad());
1510     y[6] = y[0];
1511
1512     x[0] = 0.0;
1513     x[1] = x[0];
1514     x[2] = x[1] + thickness;
1515     x[3] = x[2];
1516     x[4] = x[3] + vLength * TMath::Sin(angle*TMath::DegToRad());
1517     x[5] = x[4];
1518     x[6] = x[0] + thickness;
1519
1520     sizes.Set(3);
1521     sizes[0] = hLength;
1522     sizes[1] = vLength;
1523     sizes[2] = thickness;
1524
1525     TGeoXtru *shPatch = new TGeoXtru(2);
1526     shPatch->SetName("ITSSPDpatchShape1");
1527     shPatch->DefinePolygon(7, x, y);
1528     shPatch->DefineSection(0, -0.5*width, 0., 0., 1.0);
1529     shPatch->DefineSection(1,  0.5*width, 0., 0., 1.0);
1530     
1531     /*
1532     Double_t subThickness = 10.0 * fgkmm;
1533     Double_t subWidth     = 55.0 * fgkmm;
1534     new TGeoBBox("ITSSPDpatchShape2", 0.5*subThickness, 60.0 * fgkmm, 0.5*subWidth);
1535     TGeoRotation *rotSub = new TGeoRotation(*gGeoIdentity);
1536     rotSub->SetName("shPatchSubRot");
1537     rotSub->RotateZ(50.0);
1538     rotSub->RegisterYourself();
1539     TGeoCombiTrans *trSub = new TGeoCombiTrans(0.26*hLength, 0.26*vLength, 0.0, rotSub);
1540     trSub->SetName("shPatchSubTr");
1541     trSub->RegisterYourself();
1542     
1543     TGeoCompositeShape *shPatchFinal = new TGeoCompositeShape("ITSSPDpatchShape1-(ITSSPDpatchShape2:shPatchSubTr)");
1544     */
1545
1546     TGeoMedium *mat = GetMedium("AL$", mgr);
1547     //TGeoVolume *vPatch = new TGeoVolume("ITSSPDpatchPanel", shPatchFinal, mat);
1548     TGeoVolume *vPatch = new TGeoVolume("ITSSPDpatchPanel", shPatch, mat);
1549     vPatch->SetLineColor(kAzure);
1550     
1551     return vPatch;
1552 }
1553
1554 //___________________________________________________________________
1555 TGeoCompositeShape* AliITSv11GeometrySPD::CreateGroundingFoilShape
1556                        (Int_t itype,Double_t &length,Double_t &width,
1557                         Double_t thickness,TArrayD &sizes)
1558 {
1559     //
1560     // Creates the typical composite shape of the grounding foil:
1561     //
1562     //  +---------------------------------------------------------+
1563     //  |                         5           6      9            |
1564     //  |                         +-----------+      +------------+ 10
1565     //  |             O           |           |      |
1566     //  |                 3 /-----+ 4         +------+
1567     //  |     1            /                 7        8
1568     //  |      /----------/
1569     //  +-----/                2                                  +
1570     //       0
1571     //       Z                                                    + 11
1572     //
1573     // This shape is used 4 times: two layers of glue, one in kapton
1574     // and one in aluminum, taking into account that the aliminum
1575     // layer has small differences in the size of some parts.
1576     // ---
1577     // In order to overcome problems apparently due to a large number
1578     // of points, the shape creation is done according the following
1579     // steps:
1580     //    1) a TGeoBBox is created with a size right enough to contain
1581     //       the whole shape (0-1-X-13)
1582     //    2) holes are defined as other TGeoBBox which are subtracted
1583     //       from the main shape
1584     //    3) a TGeoXtru is defined connecting the points (0-->11-->0)
1585     //       and is also subtracted from the main shape
1586     // ---
1587     // The argument ("type") is used to choose between all these
1588     // possibilities:
1589     //   - type = 0 --> kapton layer
1590     //   - type = 1 --> aluminum layer
1591     //   - type = 2 --> glue layer between support and GF
1592     //   - type = 3 --> glue layer between GF and ladders
1593     // Returns: a TGeoCompositeShape which will then be used to shape
1594     // several volumes. Since TGeoXtru is used, the local reference
1595     // frame of this object has X horizontal and Y vertical w.r to
1596     // the shape drawn above, and Z axis going perpendicularly to the screen.
1597     // This is not the correct reference for the half stave, for which
1598     // the "long" dimension is Z and the "short" is X, while Y goes in
1599     // the direction of thickness. This will imply some rotations when
1600     // using the volumes created with this shape.
1601
1602     // suffix to differentiate names
1603     Char_t type[10];
1604
1605     // size of the virtual box containing exactly this volume
1606     length = fgkmm * 243.18;
1607     width  = fgkmm *  15.95;
1608     if (itype == 1) {
1609         length -= fgkmm * 0.4;
1610         width  -= fgkmm * 0.4;
1611     } // end if itype==1
1612     switch (itype) {
1613     case 0:
1614         snprintf(type,10,"Kap");
1615         break;
1616     case 1:
1617         snprintf(type,10, "Alu");
1618         break;
1619     case 2:
1620         snprintf(type,10,"Glue1");
1621         break;
1622     case 3:
1623         snprintf(type,10,"Glue2");
1624         break;
1625     }
1626     // we divide the shape in several slices along the horizontal
1627     // direction (local X) here we define define the length of all
1628     // sectors (from leftmost to rightmost)
1629     Int_t i;
1630     Double_t sliceLength[] = { 140.71,  2.48,  26.78,   4.00,
1631                                 10.00, 24.40,  10.00,  24.81 };
1632     for (i = 0; i < 8; i++) sliceLength[i] *= fgkmm;
1633     if (itype == 1) {
1634         sliceLength[0] -= fgkmm * 0.2;
1635         sliceLength[4] -= fgkmm * 0.2;
1636         sliceLength[5] += fgkmm * 0.4;
1637         sliceLength[6] -= fgkmm * 0.4;
1638     } // end if itype ==1
1639
1640     // as shown in the drawing, we have four different widths
1641     // (along local Y) in this shape:
1642     Double_t widthMax  = fgkmm * 15.95;
1643     Double_t widthMed1 = fgkmm * 15.00;
1644     Double_t widthMed2 = fgkmm * 11.00;
1645     Double_t widthMin  = fgkmm *  4.40;
1646     if (itype == 1) {
1647         widthMax  -= fgkmm * 0.4;
1648         widthMed1 -= fgkmm * 0.4;
1649         widthMed2 -= fgkmm * 0.4;
1650         widthMin  -= fgkmm * 0.4;
1651     } // end if itype==1
1652
1653     // create the main shape
1654     TGeoBBox *shGroundFull = 0;
1655     shGroundFull = new TGeoBBox(Form("ITSSPDSHgFoil%sFull", type),
1656                                 0.5*length,0.5*width, 0.5*thickness);
1657
1658     if(GetDebug(5)) shGroundFull->Print(); // Avoid Coverity warning
1659
1660     // create the polygonal shape to be subtracted to give the correct
1661     // shape to the borders its vertices are defined in sugh a way that
1662     // this polygonal will be placed in the correct place considered
1663     // that the origin of the local reference frame is in the center
1664     // of the main box: we fix the starting point at the lower-left
1665     // edge of the shape (point 12), and add all points in order,
1666     // following a clockwise rotation
1667
1668     Double_t x[13], y[13];
1669     x[ 0] = -0.5 * length + sliceLength[0];
1670     y[ 0] = -0.5 * widthMax;
1671
1672     x[ 1] = x[0] + sliceLength[1];
1673     y[ 1] = y[0] + (widthMax - widthMed1);
1674
1675     x[ 2] = x[1] + sliceLength[2];
1676     y[ 2] = y[1];
1677
1678     x[ 3] = x[2] + sliceLength[3];
1679     y[ 3] = y[2] + (widthMed1 - widthMed2);
1680
1681     x[ 4] = x[3] + sliceLength[4];
1682     y[ 4] = y[3];
1683
1684     x[ 5] = x[4];
1685     y[ 5] = y[4] + (widthMed2 - widthMin);
1686
1687     x[ 6] = x[5] + sliceLength[5];
1688     y[ 6] = y[5];
1689
1690     x[ 7] = x[6];
1691     y[ 7] = y[4];
1692
1693     x[ 8] = x[7] + sliceLength[6];
1694     y[ 8] = y[7];
1695
1696     x[ 9] = x[8];
1697     y[ 9] = y[6];
1698
1699     x[10] = x[9] + sliceLength[7] + 0.5;
1700     y[10] = y[9];
1701
1702     x[11] = x[10];
1703     y[11] = y[0] - 0.5;
1704
1705     x[12] = x[0];
1706     y[12] = y[11];
1707
1708     // create the shape
1709     TGeoXtru *shGroundXtru = new TGeoXtru(2);
1710     shGroundXtru->SetName(Form("ITSSPDSHgFoil%sXtru", type));
1711     shGroundXtru->DefinePolygon(13, x, y);
1712     shGroundXtru->DefineSection(0, -thickness, 0., 0., 1.0);
1713     shGroundXtru->DefineSection(1,  thickness, 0., 0., 1.0);
1714
1715     // define a string which will express the algebric operations among volumes
1716     // and add the subtraction of this shape from the main one
1717     TString strComposite(Form("ITSSPDSHgFoil%sFull-(%s+", type,
1718                               shGroundXtru->GetName()));
1719
1720     // define the holes according to size information coming from drawings:
1721     Double_t holeLength = fgkmm * 10.00;
1722     Double_t holeWidth  = fgkmm *  7.50;
1723     Double_t holeSepX0  = fgkmm *  7.05;  // separation between center
1724                                           // of first hole and left border
1725     Double_t holeSepXC  = fgkmm * 14.00;  // separation between the centers
1726                                           // of two consecutive holes
1727     Double_t holeSepX1  = fgkmm * 15.42;  // separation between centers of
1728                                           // 5th and 6th hole
1729     Double_t holeSepX2  = fgkmm * 22.00;  // separation between centers of
1730                                           // 10th and 11th hole
1731     if (itype == 1) {
1732         holeSepX0  -= fgkmm * 0.2;
1733         holeLength += fgkmm * 0.4;
1734         holeWidth  += fgkmm * 0.4;
1735     } // end if itype==1
1736     sizes.Set(7);
1737     sizes[0] = holeLength;
1738     sizes[1] = holeWidth;
1739     sizes[2] = holeSepX0;
1740     sizes[3] = holeSepXC;
1741     sizes[4] = holeSepX1;
1742     sizes[5] = holeSepX2;
1743     sizes[6] = fgkmm * 4.40;
1744
1745     // X position of hole center (will change for each hole)
1746     Double_t holeX = -0.5*length;
1747     // Y position of center of all holes (= 4.4 mm from upper border)
1748     Double_t holeY = 0.5*(width - holeWidth) - widthMin;
1749
1750     // create a shape for the holes (common)
1751     new TGeoBBox(Form("ITSSPD%sGfoilHole", type),0.5*holeLength,
1752                        0.5*holeWidth, thickness);
1753
1754     // insert the holes in the XTRU shape:
1755     // starting from the first value of X, they are simply
1756     // shifted along this axis
1757     char name[200];
1758     TGeoTranslation *transHole[11];
1759     for (i = 0; i < 11; i++) {
1760         // set the position of the hole, depending on index
1761         if (i == 0) {
1762             holeX += holeSepX0;
1763         }else if (i < 5) {
1764             holeX += holeSepXC;
1765         }else if (i == 5) {
1766             holeX += holeSepX1;
1767         }else if (i < 10) {
1768             holeX += holeSepXC;
1769         }else {
1770             holeX += holeSepX2;
1771         } // end if else if's
1772         //cout << i << " --> X = " << holeX << endl;
1773         snprintf(name,200,"ITSSPDTRgFoil%sHole%d", type, i);
1774         transHole[i] = new TGeoTranslation(name, holeX, holeY, 0.0);
1775         transHole[i]->RegisterYourself();
1776         strComposite.Append(Form("ITSSPD%sGfoilHole:%s", type, name));
1777         if (i < 10) strComposite.Append("+"); else strComposite.Append(")");
1778     } // end for i
1779
1780     // create composite shape
1781     TGeoCompositeShape *shGround = new TGeoCompositeShape(
1782         Form("ITSSPDSHgFoil%s", type), strComposite.Data());
1783
1784     return shGround;
1785 }
1786 //______________________________________________________________________
1787 TGeoVolumeAssembly* AliITSv11GeometrySPD::CreateGroundingFoil(Bool_t isRight,
1788                                    TArrayD &sizes, TGeoManager *mgr)
1789 {
1790     //
1791     // Create a volume containing all parts of the grounding foil a
1792     // for a half-stave.
1793     // It consists of 4 layers with the same shape but different thickness:
1794     // 1) a layer of glue
1795     // 2) the aluminum layer
1796     // 3) the kapton layer
1797     // 4) another layer of glue
1798     // ---
1799     // Arguments:
1800     //  1: a boolean value to know if it is the grounding foir for
1801     //     the right or left side
1802     //  2: a TArrayD which will contain the dimension of the container box:
1803     //       - size[0] = length along Z (the beam line direction)
1804     //       - size[1] = the 'width' of the stave, which defines, together
1805     //                   with Z, the plane of the carbon fiber support
1806     //       - size[2] = 'thickness' (= the direction along which all
1807     //                    stave components are superimposed)
1808     //  3: the TGeoManager
1809     // ---
1810     // The return value is a TGeoBBox volume containing all grounding
1811     // foil components.
1812     // to avoid strange behaviour of the geometry manager,
1813     // create a suffix to be used in the names of all shapes
1814     //
1815     char suf[5];
1816     if (isRight) strncpy(suf, "R", 5); else strncpy(suf, "L", 5);
1817     // this volume will be created in order to ease its placement in
1818     // the half-stave; then, it is added here the small distance of
1819     // the "central" edge of each volume from the Z=0 plane in the stave
1820     // reference (which coincides with ALICE one)
1821     Double_t dist = fgkmm * 0.71;
1822
1823     // define materials
1824     TGeoMedium *medKap  = GetMedium("SPD KAPTON(POLYCH2)$", mgr);
1825     TGeoMedium *medAlu  = GetMedium("AL$", mgr);
1826     TGeoMedium *medGlue = GetMedium("EPOXY$", mgr); //??? GLUE_GF_SUPPORT
1827
1828     // compute the volume shapes (thicknesses change from one to the other)
1829     Double_t kpLength, kpWidth, alLength, alWidth;
1830     TArrayD  kpSize, alSize, glSize;
1831     Double_t kpThickness = fgkmm * 0.04;
1832     Double_t alThickness = fgkmm * 0.01;
1833 //cout << "AL THICKNESS" << alThickness << endl;
1834     //Double_t g0Thickness = fgkmm * 0.1175 - fgkGapHalfStave;
1835     //Double_t g1Thickness = fgkmm * 0.1175 - fgkGapLadder;
1836     Double_t g0Thickness = fgkmm * 0.1275 - fgkGapHalfStave;
1837     Double_t g1Thickness = fgkmm * 0.1275 - fgkGapLadder;
1838     TGeoCompositeShape *kpShape = CreateGroundingFoilShape(0,kpLength,kpWidth,
1839                                                           kpThickness, kpSize);
1840     TGeoCompositeShape *alShape = CreateGroundingFoilShape(1,alLength,alWidth,
1841                                                           alThickness, alSize);
1842     TGeoCompositeShape *g0Shape = CreateGroundingFoilShape(2,kpLength,kpWidth,
1843                                                           g0Thickness, glSize);
1844     TGeoCompositeShape *g1Shape = CreateGroundingFoilShape(3,kpLength,kpWidth,
1845                                                           g1Thickness, glSize);
1846     // create the component volumes and register their sizes in the
1847     // passed arrays for readability reasons, some reference variables
1848     // explicit the meaning of the array slots
1849     TGeoVolume *kpVol = new TGeoVolume(Form("ITSSPDgFoilKap%s",suf),
1850                                        kpShape, medKap);
1851     TGeoVolume *alVol = new TGeoVolume(Form("ITSSPDgFoilAlu%s",suf),
1852                                        alShape, medAlu);
1853     TGeoVolume *g0Vol = new TGeoVolume(Form("ITSSPDgFoilGlue%s",suf),
1854                                        g0Shape, medGlue);
1855     TGeoVolume *g1Vol = new TGeoVolume(Form("ITSSPDgFoilGlue%s",suf),
1856                                        g1Shape, medGlue);
1857     // set colors for the volumes
1858     kpVol->SetLineColor(kRed);
1859     alVol->SetLineColor(kGray);
1860     g0Vol->SetLineColor(kYellow);
1861     g1Vol->SetLineColor(kYellow);
1862     // create references for the final size object
1863     if (sizes.GetSize() != 3) sizes.Set(3);
1864     Double_t &fullThickness = sizes[0];
1865     Double_t &fullLength = sizes[1];
1866     Double_t &fullWidth = sizes[2];
1867     // kapton leads the larger dimensions of the foil
1868     // (including the cited small distance from Z=0 stave reference plane)
1869     // the thickness is the sum of the ones of all components
1870     fullLength    = kpLength + dist;
1871     fullWidth     = kpWidth;
1872     fullThickness = kpThickness + alThickness + g0Thickness + g1Thickness;
1873     // create the container
1874 //    TGeoMedium *air = GetMedium("AIR$", mgr);
1875     TGeoVolumeAssembly *container = new TGeoVolumeAssembly(Form("ITSSPDgFOIL-%s",suf));
1876 //    TGeoVolume *container = mgr->MakeBox(Form("ITSSPDgFOIL-%s",suf),
1877 //                 air, 0.5*fullThickness, 0.5*fullWidth, 0.5*fullLength);
1878     // create the common correction rotation (which depends of what side
1879     // we are building)
1880     TGeoRotation *rotCorr = new TGeoRotation(*gGeoIdentity);
1881     if (isRight) rotCorr->RotateY(90.0);
1882     else rotCorr->RotateY(-90.0);
1883     // compute the translations, which are in the length and
1884     // thickness directions
1885     Double_t x, y, z, shift = 0.0;
1886     if (isRight) shift = dist;
1887     // glue (bottom)
1888     x = -0.5*(fullThickness - g0Thickness);
1889     z =  0.5*(fullLength - kpLength) - shift;
1890     TGeoCombiTrans *glTrans0 = new TGeoCombiTrans(x, 0.0, z, rotCorr);
1891     // kapton
1892     x += 0.5*(g0Thickness + kpThickness);
1893     TGeoCombiTrans *kpTrans  = new TGeoCombiTrans(x, 0.0, z, rotCorr);
1894     // aluminum
1895     x += 0.5*(kpThickness + alThickness);
1896     z  = 0.5*(fullLength - alLength) - shift - 0.5*(kpLength - alLength);
1897     TGeoCombiTrans *alTrans  = new TGeoCombiTrans(x, 0.0, z, rotCorr);
1898     // glue (top)
1899     x += 0.5*(alThickness + g1Thickness);
1900     z  = 0.5*(fullLength - kpLength) - shift;
1901     TGeoCombiTrans *glTrans1 = new TGeoCombiTrans(x, 0.0, z, rotCorr);
1902
1903     //cout << fgkGapHalfStave << endl;
1904     //cout << g0Thickness << endl;
1905     //cout << kpThickness << endl;
1906     //cout << alThickness << endl;
1907     //cout << g1Thickness << endl;
1908
1909     // add to container
1910     container->SetLineColor(kMagenta-10);
1911     container->AddNode(kpVol, 1, kpTrans);
1912     container->AddNode(alVol, 1, alTrans);
1913     container->AddNode(g0Vol, 1, glTrans0);
1914     container->AddNode(g1Vol, 2, glTrans1);
1915     // to add the grease we remember the sizes of the holes, stored as
1916     // additional parameters in the kapton layer size:
1917     //   - sizes[3] = hole length
1918     //   - sizes[4] = hole width
1919     //   - sizes[5] = position of first hole center
1920     //   - sizes[6] = standard separation between holes
1921     //   - sizes[7] = separation between 5th and 6th hole
1922     //   - sizes[8] = separation between 10th and 11th hole
1923     //   - sizes[9] = separation between the upper hole border and
1924     //                the foil border
1925     Double_t holeLength      = kpSize[0];
1926     Double_t holeWidth       = kpSize[1];
1927     Double_t holeFirstZ      = kpSize[2];
1928     Double_t holeSepZ        = kpSize[3];
1929     Double_t holeSep5th6th   = kpSize[4];
1930     Double_t holeSep10th11th = kpSize[5];
1931     Double_t holeSepY        = kpSize[6];
1932     // volume (common)
1933     // Grease has not been defined to date. Need much more information
1934     // no this material!
1935     TGeoMedium *grease = GetMedium("SPD KAPTON(POLYCH2)$", mgr); // ??? GREASE
1936     TGeoVolume *hVol   = mgr->MakeBox("ITSSPDGrease", grease,
1937                            0.5*fullThickness, 0.5*holeWidth, 0.5*holeLength);
1938     hVol->SetLineColor(kBlue);
1939     // displacement of volumes in the container
1940     Int_t    idx = 1;  // copy numbers start from 1.
1941     x = 0.0;
1942     y = 0.5*(fullWidth - holeWidth) - holeSepY;
1943     if (isRight) z = holeFirstZ - 0.5*fullLength + dist;
1944     else z = 0.5*fullLength - holeFirstZ - dist;
1945     for (Int_t i = 0; i < 11; i++) {
1946         TGeoTranslation *t = 0;
1947         t = new TGeoTranslation(x, y, -z);
1948         container->AddNode(hVol, idx++, t);
1949         if (i < 4) shift = holeSepZ;
1950         else if (i == 4) shift = holeSep5th6th;
1951         else if (i < 9) shift = holeSepZ;
1952         else shift = holeSep10th11th;
1953         if (isRight) z += shift;
1954         else z -= shift;
1955     } // end for i
1956     return container;
1957 }
1958 //___________________________________________________________________
1959 TGeoVolumeAssembly* AliITSv11GeometrySPD::CreateMCM(Bool_t isRight,
1960                                    TArrayD &sizes, TGeoManager *mgr) const
1961 {
1962     //
1963     // Create a TGeoAssembly containing all the components of the MCM.
1964     // The TGeoVolume container is rejected due to the possibility of overlaps
1965     // when placing this object on the carbon fiber sector.
1966     // The assembly contains:
1967     //  - the thin part of the MCM (integrated circuit)
1968     //  - the MCM chips (specifications from EDMS)
1969     //  - the cap which covers the zone where chips are bound to MCM
1970     // ---
1971     // The local reference frame of this assembly is defined in such a way
1972     // that all volumes are contained in a virtual box whose center
1973     // is placed exactly in the middle of the occupied space w.r to all
1974     // directions. This will ease the positioning of this object in the
1975     // half-stave. The sizes of this virtual box are stored in
1976     // the array passed by reference.
1977     // ---
1978     // Arguments:
1979     //  - a boolean flag to know if this is the "left" or "right" MCM, when
1980     //    looking at the stave from above (i.e. the direction from which
1981     //    one sees bus over ladders over grounding foil) and keeping the
1982     //    continuous border in the upper part, one sees the thicker part
1983     //    on the left or right.
1984     //  - an array passed by reference which will contain the size of
1985     //    the virtual container.
1986     //  - a pointer to the used TGeoManager.
1987     //
1988
1989     // to distinguish the "left" and "right" objects, a suffix is created
1990     char suf[5];
1991     if (isRight) strncpy(suf, "R", 5); else strncpy(suf, "L", 5);
1992
1993     // ** MEDIA **
1994     TGeoMedium *medBase = GetMedium("SPD KAPTON(POLYCH2)$",mgr);// ??? MCM BASE
1995     TGeoMedium *medChip = GetMedium("SPD SI CHIP$",mgr);
1996     TGeoMedium *medCap  = GetMedium("AL$",mgr);
1997
1998     // The shape of the MCM is divided into 3 sectors with different
1999     // widths (Y) and lengths (X), like in this sketch:
2000     //
2001     //   0                      1                                   2
2002     //    +---------------------+-----------------------------------+
2003     //    |                                    4       sect 2       |
2004     //    |                    6      sect 1    /-------------------+
2005     //    |      sect 0         /--------------/                    3
2006     //    +--------------------/               5
2007     //   8                     7
2008     //
2009     // the inclination of all oblique borders (6-7, 4-5) is always 45 degrees.
2010     // From drawings we can parametrize the dimensions of all these sectors,
2011     // then the shape of this part of the MCM is implemented as a
2012     // TGeoXtru centerd in the virtual XY space.
2013     // The first step is definig the relevant sizes of this shape:
2014     Int_t i, j;
2015     Double_t mcmThickness  = fgkmm * 0.35;
2016     Double_t sizeXtot      = fgkmm * 105.6;   // total distance (0-2)
2017     // resp. 7-8, 5-6 and 3-4
2018     Double_t sizeXsector[3] = {fgkmm * 28.4, fgkmm * 41.4, fgkmm * 28.8};
2019     // resp. 0-8, 1-6 and 2-3
2020     Double_t sizeYsector[3] = {fgkmm * 15.0, fgkmm * 11.0, fgkmm *  8.0};
2021     Double_t sizeSep01 = fgkmm * 4.0;      // x(6)-x(7)
2022     Double_t sizeSep12 = fgkmm * 3.0;      // x(4)-x(5)
2023
2024     // define sizes of chips (last is the thickest)
2025     Double_t chipLength[5]     = { 4.00, 6.15, 3.85, 5.60, 18.00 };
2026     Double_t chipWidth[5]      = { 3.00, 4.10, 3.85, 5.60,  5.45 };
2027     Double_t chipThickness[5]  = { 0.60, 0.30, 0.30, 1.00,  1.20 };
2028     TString  name[5];
2029     name[0] = "ITSSPDanalog";
2030     name[1] = "ITSSPDpilot";
2031     name[2] = "ITSSPDgol";
2032     name[3] = "ITSSPDrx40";
2033     name[4] = "ITSSPDoptical";
2034     Color_t color[5] = { kCyan, kGreen, kYellow, kBlue, kOrange };
2035
2036     // define the sizes of the cover
2037     Double_t capThickness = fgkmm * 0.3;
2038     Double_t capHeight = fgkmm * 1.7;
2039
2040     // compute the total size of the virtual container box
2041     sizes.Set(3);
2042     Double_t &thickness = sizes[0];
2043     Double_t &length = sizes[1];
2044     Double_t &width = sizes[2];
2045     length = sizeXtot;
2046     width = sizeYsector[0];
2047     thickness = mcmThickness + capHeight;
2048
2049     // define all the relevant vertices of the polygon
2050     // which defines the transverse shape of the MCM.
2051     // These values are used to several purposes, and
2052     // for each one, some points must be excluded
2053     Double_t xRef[9], yRef[9];
2054     xRef[0] = -0.5*sizeXtot;
2055     yRef[0] =  0.5*sizeYsector[0];
2056     xRef[1] =  xRef[0] + sizeXsector[0] + sizeSep01;
2057     yRef[1] =  yRef[0];
2058     xRef[2] = -xRef[0];
2059     yRef[2] =  yRef[0];
2060     xRef[3] =  xRef[2];
2061     yRef[3] =  yRef[2] - sizeYsector[2];
2062     xRef[4] =  xRef[3] - sizeXsector[2];
2063     yRef[4] =  yRef[3];
2064     xRef[5] =  xRef[4] - sizeSep12;
2065     yRef[5] =  yRef[4] - sizeSep12;
2066     xRef[6] =  xRef[5] - sizeXsector[1];
2067     yRef[6] =  yRef[5];
2068     xRef[7] =  xRef[6] - sizeSep01;
2069     yRef[7] =  yRef[6] - sizeSep01;
2070     xRef[8] =  xRef[0];
2071     yRef[8] = -yRef[0];
2072
2073     // the above points are defined for the "right" MCM (if ve view the
2074     // stave from above) in order to change to the "left" one, we must
2075     // change the sign to all X values:
2076     if (isRight) for (i = 0; i < 9; i++) xRef[i] = -xRef[i];
2077
2078     // the shape of the MCM and glue layer are done excluding point 1,
2079     // which is not necessary and cause the geometry builder to get confused
2080     j = 0;
2081     Double_t xBase[8], yBase[8];
2082     for (i = 0; i < 9; i++) {
2083         if (i == 1) continue;
2084         xBase[j] = xRef[i];
2085         yBase[j] = yRef[i];
2086         j++;
2087     } // end for i
2088
2089     // the MCM cover is superimposed over the zones 1 and 2 only
2090     Double_t xCap[6], yCap[6];
2091     j = 0;
2092     for (i = 1; i <= 6; i++) {
2093         xCap[j] = xRef[i];
2094         yCap[j] = yRef[i];
2095         j++;
2096     } // end for i
2097
2098     // define positions of chips,
2099     // which must be added to the bottom-left corner of MCM
2100     // and divided by 1E4;
2101     Double_t chipX[5], chipY[5];
2102     if (isRight) {
2103         chipX[0] = 666320.;
2104         chipX[1] = 508320.;
2105         chipX[2] = 381320.;
2106         chipX[3] = 295320.;
2107         chipX[4] = 150320.;
2108         chipY[0] =  23750.;
2109         chipY[1] =  27750.;
2110         chipY[2] =  20750.;
2111         chipY[3] =  42750.;
2112         chipY[4] =  39750.;
2113     } else {
2114         chipX[0] = 389730.;
2115         chipX[1] = 548630.;
2116         chipX[2] = 674930.;
2117         chipX[3] = 761430.;
2118         chipX[4] = 905430.;
2119         chipY[0] =  96250.;
2120         chipY[1] =  91950.;
2121         chipY[2] =  99250.;
2122         chipY[3] = 107250.;
2123         chipY[4] = 109750.;
2124     } // end if isRight
2125     for (i = 0; i < 5; i++) {
2126         chipX[i] *= 0.00001;
2127         chipY[i] *= 0.00001;
2128         if (isRight) {
2129             chipX[i] += xRef[3];
2130             chipY[i] += yRef[3];
2131         } else {
2132             chipX[i] += xRef[8];
2133             chipY[i] += yRef[8];
2134         } // end for isRight
2135         chipLength[i] *= fgkmm;
2136         chipWidth[i] *= fgkmm;
2137         chipThickness[i] *= fgkmm;
2138     } // end for i
2139
2140     // create shapes for MCM
2141     Double_t z1, z2;
2142     TGeoXtru *shBase = new TGeoXtru(2);
2143     z1 = -0.5*thickness;
2144     z2 = z1 + mcmThickness;
2145     shBase->DefinePolygon(8, xBase, yBase);
2146     shBase->DefineSection(0, z1, 0., 0., 1.0);
2147     shBase->DefineSection(1, z2, 0., 0., 1.0);
2148
2149     // create volumes of MCM
2150     TGeoVolume *volBase = new TGeoVolume("ITSSPDbase", shBase, medBase);
2151     volBase->SetLineColor(kRed);
2152
2153     // to create the border of the MCM cover, it is required the
2154     // subtraction of two shapes the outer is created using the
2155     // reference points defined here
2156     TGeoXtru *shCapOut = new TGeoXtru(2);
2157     shCapOut->SetName(Form("ITSSPDshCAPOUT%s", suf));
2158     z1 = z2;
2159     z2 = z1 + capHeight - capThickness;
2160     shCapOut->DefinePolygon(6, xCap, yCap);
2161     shCapOut->DefineSection(0, z1, 0., 0., 1.0);
2162     shCapOut->DefineSection(1, z2, 0., 0., 1.0);
2163     // the inner is built similarly but subtracting the thickness
2164     Double_t angle, cs;
2165     Double_t xin[6], yin[6];
2166     if (!isRight) {
2167         angle = 45.0;
2168         cs = TMath::Cos( 0.5*(TMath::Pi() - angle*TMath::DegToRad()) );
2169         xin[0] = xCap[0] + capThickness;
2170         yin[0] = yCap[0] - capThickness;
2171         xin[1] = xCap[1] - capThickness;
2172         yin[1] = yin[0];
2173         xin[2] = xin[1];
2174         yin[2] = yCap[2] + capThickness;
2175         xin[3] = xCap[3] - capThickness*cs;
2176         yin[3] = yin[2];
2177         xin[4] = xin[3] - sizeSep12;
2178         yin[4] = yCap[4] + capThickness;
2179         xin[5] = xin[0];
2180         yin[5] = yin[4];
2181     } else {
2182         angle = 45.0;
2183         cs = TMath::Cos( 0.5*(TMath::Pi() - angle*TMath::DegToRad()) );
2184         xin[0] = xCap[0] - capThickness;
2185         yin[0] = yCap[0] - capThickness;
2186         xin[1] = xCap[1] + capThickness;
2187         yin[1] = yin[0];
2188         xin[2] = xin[1];
2189         yin[2] = yCap[2] + capThickness;
2190         xin[3] = xCap[3] - capThickness*cs;
2191         yin[3] = yin[2];
2192         xin[4] = xin[3] + sizeSep12;
2193         yin[4] = yCap[4] + capThickness;
2194         xin[5] = xin[0];
2195         yin[5] = yin[4];
2196     } // end if !isRight
2197     TGeoXtru *shCapIn = new TGeoXtru(2);
2198     shCapIn->SetName(Form("ITSSPDshCAPIN%s", suf));
2199     shCapIn->DefinePolygon(6, xin, yin);
2200     shCapIn->DefineSection(0, z1 - 0.01, 0., 0., 1.0);
2201     shCapIn->DefineSection(1, z2 + 0.01, 0., 0., 1.0);
2202     // compose shapes
2203     TGeoCompositeShape *shCapBorder = new TGeoCompositeShape(
2204                             Form("ITSSPDshBORDER%s", suf),
2205                             Form("%s-%s", shCapOut->GetName(),
2206                                  shCapIn->GetName()));
2207     // create volume
2208     TGeoVolume *volCapBorder = new TGeoVolume("ITSSPDcapBoarder",
2209                                               shCapBorder,medCap);
2210     volCapBorder->SetLineColor(kGreen);
2211     // finally, we create the top of the cover, which has the same
2212     // shape of outer border and a thickness equal of the one othe
2213     // cover border one
2214     TGeoXtru *shCapTop = new TGeoXtru(2);
2215     z1 = z2;
2216     z2 = z1 + capThickness;
2217     shCapTop->DefinePolygon(6, xCap, yCap);
2218     shCapTop->DefineSection(0, z1, 0., 0., 1.0);
2219     shCapTop->DefineSection(1, z2, 0., 0., 1.0);
2220     TGeoVolume *volCapTop = new TGeoVolume("ITSSPDcapTop", shCapTop, medCap);
2221     volCapTop->SetLineColor(kBlue);
2222
2223     // create container assembly with right suffix
2224     TGeoVolumeAssembly *mcmAssembly = new TGeoVolumeAssembly(
2225         Form("ITSSPDmcm%s", suf));
2226
2227     // add mcm layer
2228     mcmAssembly->AddNode(volBase, 1, gGeoIdentity);
2229     // add chips
2230     for (i = 0; i < 5; i++) {
2231         TGeoVolume *box = gGeoManager->MakeBox(name[i],medChip,
2232                0.5*chipLength[i], 0.5*chipWidth[i], 0.5*chipThickness[i]);
2233         TGeoTranslation *tr = new TGeoTranslation(chipX[i],chipY[i],
2234                       0.5*(-thickness + chipThickness[i]) + mcmThickness);
2235         box->SetLineColor(color[i]);
2236         mcmAssembly->AddNode(box, 1, tr);
2237     } // end for i
2238     // add cap border
2239     mcmAssembly->AddNode(volCapBorder, 1, gGeoIdentity);
2240     // add cap top
2241     mcmAssembly->AddNode(volCapTop, 1, gGeoIdentity);
2242
2243     return mcmAssembly;
2244 }
2245
2246 //______________________________________________________________________
2247 TGeoVolumeAssembly* AliITSv11GeometrySPD::CreatePixelBus
2248 (Bool_t isRight, Int_t ilayer, TArrayD &sizes, TGeoManager *mgr) const
2249 {
2250     //
2251     // The pixel bus is implemented as a TGeoBBox with some objects on it,
2252     // which could affect the particle energy loss.
2253     // ---
2254     // In order to avoid confusion, the bus is directly displaced
2255     // according to the axis orientations which are used in the final stave:
2256     // X --> thickness direction
2257     // Y --> width direction
2258     // Z --> length direction
2259     //
2260
2261     // ** CRITICAL CHECK ******************************************************
2262     // layer number can be ONLY 1 or 2
2263     if (ilayer != 1 && ilayer != 2) AliFatal("Layer number MUST be 1 or 2");
2264
2265     // ** MEDIA **
2266     //PIXEL BUS
2267     TGeoMedium *medBus     = GetMedium("SPDBUS(AL+KPT+EPOX)$",mgr);
2268     TGeoMedium *medPt1000  = GetMedium("CERAMICS$",mgr); // ??? PT1000
2269     // Capacity
2270     TGeoMedium *medCap     = GetMedium("SDD X7R capacitors$",mgr);
2271     // ??? Resistance
2272     //TGeoMedium *medRes     = GetMedium("SDD X7R capacitors$",mgr);
2273     TGeoMedium *medRes     = GetMedium("ALUMINUM$",mgr);
2274     //TGeoMedium *medExt     = GetMedium("SDDKAPTON (POLYCH2)$", mgr);
2275     TGeoMedium *medExt     = GetMedium("SPD-MIX CU KAPTON$", mgr);
2276     // ** SIZES & POSITIONS **
2277     Double_t busLength          = 170.501 * fgkmm; // length of plane part
2278     Double_t busWidth           =  13.800 * fgkmm; // width
2279     Double_t busThickness       =   0.280 * fgkmm; // thickness
2280     Double_t pt1000Length       = fgkmm * 1.50;
2281     Double_t pt1000Width        = fgkmm * 3.10;
2282     Double_t pt1000Thickness    = fgkmm * 0.60;
2283     Double_t pt1000Y, pt1000Z[10];// position of the pt1000's along the bus
2284     Double_t capLength          = fgkmm * 2.55;
2285     Double_t capWidth           = fgkmm * 1.50;
2286     Double_t capThickness       = fgkmm * 1.35;
2287     Double_t capY[2], capZ[2];
2288
2289     Double_t resLength          = fgkmm * 2.20;
2290     Double_t resWidth           = fgkmm * 0.80;
2291     Double_t resThickness       = fgkmm * 0.35;
2292     Double_t resY[2], resZ[2];
2293
2294     Double_t extThickness       = fgkmm * 0.25;
2295     Double_t ext1Length         = fgkmm * (26.7 - 10.0);
2296     Double_t ext2Length         = fgkmm * 284.0 - ext1Length + extThickness;
2297     Double_t extWidth           = fgkmm * 11.0;
2298     Double_t extHeight          = fgkmm * 2.5;
2299
2300     // position of pt1000, resistors and capacitors depends on the
2301     // bus if it's left or right one
2302     if (!isRight) {
2303         pt1000Y    =   64400.;
2304         pt1000Z[0] =   66160.;
2305         pt1000Z[1] =  206200.;
2306         pt1000Z[2] =  346200.;
2307         pt1000Z[3] =  486200.;
2308         pt1000Z[4] =  626200.;
2309         pt1000Z[5] =  776200.;
2310         pt1000Z[6] =  916200.;
2311         pt1000Z[7] = 1056200.;
2312         pt1000Z[8] = 1196200.;
2313         pt1000Z[9] = 1336200.;
2314         resZ[0]    = 1397500.;
2315         resY[0]    =   26900.;
2316         resZ[1]    =  682500.;
2317         resY[1]    =   27800.;
2318         capZ[0]    = 1395700.;
2319         capY[0]    =   45700.;
2320         capZ[1]    =  692600.;
2321         capY[1]    =   45400.;
2322     } else {
2323         pt1000Y    =   66100.;
2324         pt1000Z[0] =  319700.;
2325         pt1000Z[1] =  459700.;
2326         pt1000Z[2] =  599700.;
2327         pt1000Z[3] =  739700.;
2328         pt1000Z[4] =  879700.;
2329         pt1000Z[5] = 1029700.;
2330         pt1000Z[6] = 1169700.;
2331         pt1000Z[7] = 1309700.;
2332         pt1000Z[8] = 1449700.;
2333         pt1000Z[9] = 1589700.;
2334         capY[0]    =   44500.;
2335         capZ[0]    =  266700.;
2336         capY[1]    =   44300.;
2337         capZ[1]    =  974700.;
2338         resZ[0]    =  266500.;
2339         resY[0]    =   29200.;
2340         resZ[1]    =  974600.;
2341         resY[1]    =   29900.;
2342     } // end if isRight
2343     Int_t i;
2344     pt1000Y *= 1E-4 * fgkmm;
2345     for (i = 0; i < 10; i++) {
2346         pt1000Z[i] *= 1E-4 * fgkmm;
2347         if (i < 2) {
2348             capZ[i] *= 1E-4 * fgkmm;
2349             capY[i] *= 1E-4 * fgkmm;
2350             resZ[i] *= 1E-4 * fgkmm;
2351             resY[i] *= 1E-4 * fgkmm;
2352         }  // end if iM2
2353     } // end for i
2354
2355     Double_t &fullLength = sizes[1];
2356     Double_t &fullWidth = sizes[2];
2357     Double_t &fullThickness = sizes[0];
2358     fullLength = busLength;
2359     fullWidth = busWidth;
2360     // add the thickness of the thickest component on bus (capacity)
2361     fullThickness = busThickness + capThickness;
2362
2363     // ** VOLUMES **
2364     TGeoVolumeAssembly *container = new TGeoVolumeAssembly("ITSSPDpixelBus");
2365     TGeoVolume *bus = mgr->MakeBox("ITSSPDbus", medBus, 0.5*busThickness,
2366                                    0.5*busWidth, 0.5*busLength);
2367     TGeoVolume *pt1000 = mgr->MakeBox("ITSSPDpt1000",medPt1000,
2368                         0.5*pt1000Thickness,0.5*pt1000Width, 0.5*pt1000Length);
2369     TGeoVolume *res = mgr->MakeBox("ITSSPDresistor", medRes, 0.5*resThickness,
2370                                    0.5*resWidth, 0.5*resLength);
2371     TGeoVolume *cap = mgr->MakeBox("ITSSPDcapacitor", medCap, 0.5*capThickness,
2372                                    0.5*capWidth, 0.5*capLength);
2373
2374     char extname[12];
2375     snprintf(extname,12,"Extender1l%d",ilayer);
2376     TGeoVolume *ext1 = mgr->MakeBox(extname, medExt, 0.5*extThickness, 0.5*extWidth, 0.5*ext1Length);
2377     snprintf(extname,12,"Extender2l%d",ilayer);
2378     TGeoVolume *ext2 = mgr->MakeBox(extname, medExt, 0.5*extHeight - 2.*extThickness, 0.5*extWidth, 0.5*extThickness);
2379     TGeoVolume *ext3=0;
2380     snprintf(extname,12,"Extender3l%d",ilayer);
2381     if (ilayer==1) {
2382       Double_t halflen=(0.5*ext2Length + extThickness);
2383       Double_t xprof[6],yprof[6];
2384       Double_t alpha=24;
2385       xprof[0] = -halflen;
2386       yprof[0] = -0.5*extThickness;
2387       xprof[1] = halflen/2;
2388       yprof[1] = yprof[0];
2389       xprof[2] = xprof[1] + 0.5*halflen*CosD(alpha);
2390       yprof[2] = yprof[1] + 0.5*halflen*SinD(alpha);
2391       xprof[3] = xprof[2] - extThickness*SinD(alpha);
2392       yprof[3] = yprof[2] + extThickness*CosD(alpha);
2393       InsidePoint(xprof[0], yprof[0], xprof[1], yprof[1], xprof[2], yprof[2],
2394                   extThickness, xprof[4], yprof[4]);
2395       xprof[5] = xprof[0];
2396       yprof[5] = 0.5*extThickness;
2397       TGeoXtru *ext3sh = new TGeoXtru(2);
2398       ext3sh->DefinePolygon(6, xprof, yprof);
2399       ext3sh->DefineSection(0, -0.5*(extWidth-0.8*fgkmm));
2400       ext3sh->DefineSection(1,  0.5*(extWidth-0.8*fgkmm));
2401       ext3 = new TGeoVolume(extname, ext3sh, medExt);
2402     } else
2403       ext3 = mgr->MakeBox(extname, medExt, 0.5*extThickness, 0.5*(extWidth-0.8*fgkmm), 0.5*ext2Length + extThickness); // Hardcode fix of a small overlap
2404     bus->SetLineColor(kYellow + 2);
2405     pt1000->SetLineColor(kGreen + 3);
2406     res->SetLineColor(kRed + 1);
2407     cap->SetLineColor(kBlue - 7);
2408     ext1->SetLineColor(kGray);
2409     ext2->SetLineColor(kGray);
2410     ext3->SetLineColor(kGray);
2411
2412     // ** MOVEMENTS AND POSITIONEMENT **
2413     // bus
2414     TGeoTranslation *trBus = new TGeoTranslation(0.5 * (busThickness -
2415                                                    fullThickness), 0.0, 0.0);
2416     container->AddNode(bus, 1, trBus);
2417     Double_t zRef, yRef, x, y, z;
2418     if (isRight) {
2419         zRef = -0.5*fullLength;
2420         yRef = -0.5*fullWidth;
2421     } else {
2422         zRef = -0.5*fullLength;
2423         yRef = -0.5*fullWidth;
2424     } // end if isRight
2425     // pt1000
2426     x = 0.5*(pt1000Thickness - fullThickness) + busThickness;
2427     for (i = 0; i < 10; i++) {
2428         y = yRef + pt1000Y;
2429         z = zRef + pt1000Z[i];
2430         TGeoTranslation *tr = new TGeoTranslation(x, y, z);
2431         container->AddNode(pt1000, i+1, tr);
2432     } // end for i
2433     // capacitors
2434     x = 0.5*(capThickness - fullThickness) + busThickness;
2435     for (i = 0; i < 2; i++) {
2436         y = yRef + capY[i];
2437         z = zRef + capZ[i];
2438         TGeoTranslation *tr = new TGeoTranslation(x, y, z);
2439         container->AddNode(cap, i+1, tr);
2440     } // end for i
2441     // resistors
2442     x = 0.5*(resThickness - fullThickness) + busThickness;
2443     for (i = 0; i < 2; i++) {
2444         y = yRef + resY[i];
2445         z = zRef + resZ[i];
2446         TGeoTranslation *tr = new TGeoTranslation(x, y, z);
2447         container->AddNode(res, i+1, tr);
2448     } // end for i
2449
2450     // extender
2451         if (ilayer == 2) {
2452        if (isRight) {
2453           y = 0.5 * (fullWidth - extWidth) - 0.1;
2454           z = 0.5 * (-fullLength + fgkmm * 10.0);
2455        }
2456        else {
2457           y = 0.5 * (fullWidth - extWidth) - 0.1;
2458           z = 0.5 * ( fullLength - fgkmm * 10.0);
2459        }
2460         }
2461         else {
2462             if (isRight) {
2463                 y = -0.5 * (fullWidth - extWidth);
2464                 z = 0.5 * (-fullLength + fgkmm * 10.0);
2465             }
2466             else {
2467                 y = -0.5 * (fullWidth - extWidth);
2468                 z = 0.5 * ( fullLength - fgkmm * 10.0);
2469             }
2470         }
2471     x = 0.5 * (extThickness - fullThickness) + busThickness;
2472     //y = 0.5 * (fullWidth - extWidth);
2473     TGeoTranslation *trExt1 = new TGeoTranslation(x, y, z);
2474     if (isRight) {
2475         z -= 0.5 * (ext1Length - extThickness);
2476     }
2477     else {
2478         z += 0.5 * (ext1Length - extThickness);
2479     }
2480     x += 0.5*(extHeight - 3.*extThickness);
2481     TGeoTranslation *trExt2 = new TGeoTranslation(x, y, z);
2482     if (isRight) {
2483         z -= 0.5 * (ext2Length - extThickness) + 2.5*extThickness;
2484     }
2485     else {
2486         z += 0.5 * (ext2Length - extThickness) + 2.5*extThickness;
2487     }
2488     x += 0.5*(extHeight - extThickness) - 2.*extThickness;
2489     TGeoCombiTrans *trExt3=0;
2490     if (ilayer==1) {
2491       if (isRight)
2492         trExt3 = new TGeoCombiTrans(x, y, z, new TGeoRotation("",0.,-90.,90.));
2493       else
2494         trExt3 = new TGeoCombiTrans(x, y, z, new TGeoRotation("",0., 90.,90.));
2495     } else
2496       trExt3 = new TGeoCombiTrans(x, y, z, 0);
2497     container->AddNode(ext1, 0, trExt1);
2498     container->AddNode(ext2, 0, trExt2);
2499     container->AddNode(ext3, 0, trExt3);
2500
2501     sizes[3] = yRef + pt1000Y;
2502     sizes[4] = zRef + pt1000Z[2];
2503     sizes[5] = zRef + pt1000Z[7];
2504
2505     return container;
2506 }
2507
2508 //______________________________________________________________________
2509 TList* AliITSv11GeometrySPD::CreateConeModule(Bool_t sideC, const Double_t angrot,
2510                                               TGeoManager *mgr) const
2511 {
2512     //
2513     // Creates all services modules and places them in a TList
2514     // angrot is the rotation angle (passed as an argument to avoid
2515     // defining the same quantity in two different places)
2516     //
2517     // Created:      ?? ??? 2008  A. Pulvirenti
2518     // Updated:      03 May 2010  M. Sitta
2519     // Updated:      20 Jun 2010  A. Pulvirenti  Optical patch panels
2520     // Updated:      22 Jun 2010  M. Sitta  Fiber cables
2521     // Updated:      04 Jul 2010  M. Sitta  Water cooling
2522     // Updated:      08 Jul 2010  A. Pulvirenti  Air cooling on Side C
2523     //
2524
2525     TGeoMedium *medInox  = GetMedium("INOX$",mgr);
2526     //TGeoMedium *medExt   = GetMedium("SDDKAPTON (POLYCH2)$", mgr);
2527     TGeoMedium *medExtB  = GetMedium("SPD-BUS CU KAPTON$", mgr);
2528     TGeoMedium *medExtM  = GetMedium("SPD-MCM CU KAPTON$", mgr);
2529     TGeoMedium *medPlate = GetMedium("SPD C (M55J)$", mgr);
2530     TGeoMedium *medFreon = GetMedium("Freon$", mgr);
2531     TGeoMedium *medGas   = GetMedium("GASEOUS FREON$", mgr);
2532     TGeoMedium *medFibs  = GetMedium("SDD OPTICFIB$",mgr);
2533     TGeoMedium *medCopper= GetMedium("COPPER$",mgr);
2534     TGeoMedium *medPVC   = GetMedium("PVC$",mgr);
2535
2536     Double_t extThickness = fgkmm * 0.25;
2537     Double_t ext1Length   = fgkmm * (26.7 - 10.0);
2538 //    Double_t ext2Length   = fgkmm * (285.0 - ext1Length + extThickness);
2539     Double_t ext2Length   = fgkmm * 285.0 - ext1Length + extThickness;
2540
2541     const Double_t kCableThickness  =   1.5  *fgkmm;
2542     Double_t cableL0 =  10.0 * fgkmm;
2543     Double_t cableL1 = 340.0 * fgkmm - extThickness - ext1Length - ext2Length;
2544     Double_t cableL2 = 300.0 * fgkmm;
2545     //Double_t cableL3 = 570.0 * fgkmm;
2546     Double_t cableL3 = 57.0 * fgkmm;
2547     Double_t cableW1 =  11.0 * fgkmm;
2548     Double_t cableW2 =  30.0 * fgkmm;
2549     Double_t cableW3 =  50.0 * fgkmm;
2550
2551     const Double_t kMCMLength       =   cableL0 + cableL1 + cableL2 + cableL3;
2552     const Double_t kMCMWidth        =   cableW1;
2553     const Double_t kMCMThickness    =   1.2  *fgkmm;
2554
2555     const Double_t kPlateLength     = 200.0  *fgkmm;
2556     const Double_t kPlateWidth      =  50.0  *fgkmm;
2557     const Double_t kPlateThickness  =   5.0  *fgkmm;
2558
2559     const Double_t kConeTubeRmin    =   2.0  *fgkmm;
2560     const Double_t kConeTubeRmax    =   3.0  *fgkmm;
2561
2562     const Double_t kHorizTubeLen    = 150.0  *fgkmm;
2563     const Double_t kYtoHalfStave    =   9.5  *fgkmm;
2564
2565     const Double_t kWaterCoolRMax   =   2.6  *fgkmm;
2566     const Double_t kWaterCoolThick  =   0.04 *fgkmm;
2567     const Double_t kWaterCoolLen    = 250.0  *fgkmm;
2568     const Double_t kWCPlateThick    =   0.5  *fgkmm;
2569     const Double_t kWCPlateWide     =  33.0  *fgkmm;
2570     const Double_t kWCPlateLen      = 230.0  *fgkmm;
2571     const Double_t kWCFittingRext1  =   2.4  *fgkmm;
2572     const Double_t kWCFittingRext2  =   3.7  *fgkmm;
2573     const Double_t kWCFittingRint1  =   1.9  *fgkmm;
2574     const Double_t kWCFittingRint2  = kWaterCoolRMax;
2575     const Double_t kWCFittingLen1   =   7.0  *fgkmm;
2576     const Double_t kWCFittingLen2   =   8.0  *fgkmm;
2577     
2578     const Double_t kCollWidth       =  40.0  *fgkmm;
2579     const Double_t kCollLength      =  60.0  *fgkmm;
2580     const Double_t kCollThickness   =  10.0  *fgkmm;
2581     const Double_t kCollTubeThick   =   1.0  *fgkmm;
2582     const Double_t kCollTubeRadius  =   7.0  *fgkmm;
2583     const Double_t kCollTubeLength  = 205.0  *fgkmm;
2584
2585     const Double_t kOptFibDiamet    =   4.5  *fgkmm;
2586
2587     Double_t x[12], y[12];
2588     Double_t xloc, yloc, zloc;
2589
2590     Int_t kPurple = 6; // Purple (Root does not define it)
2591
2592     TGeoVolumeAssembly* container[5];
2593     if (sideC)
2594     container[0] = new TGeoVolumeAssembly("ITSSPDConeModuleC");
2595     else
2596     container[0] = new TGeoVolumeAssembly("ITSSPDConeModuleA");
2597     container[1] = new TGeoVolumeAssembly("ITSSPDCoolingModuleSideA");
2598     container[2] = new TGeoVolumeAssembly("ITSSPDCoolingModuleSideC");
2599     container[3] = new TGeoVolumeAssembly("ITSSPDPatchPanelModule");
2600     container[4] = new TGeoVolumeAssembly("ITSSPDWaterCooling");
2601
2602     // The extender on the cone as a Xtru
2603     x[0] = -cableL0;
2604     y[0] = 0.0 + 0.5 * cableW1;
2605
2606     x[1] = x[0] + cableL0 + cableL1 - 0.5*(cableW2 - cableW1);
2607     y[1] = y[0];
2608
2609     x[2] = x[0] + cableL0 + cableL1;
2610     y[2] = y[1] + 0.5*(cableW2 - cableW1);
2611
2612     x[3] = x[2] + cableL2;
2613     y[3] = y[2];
2614
2615     x[4] = x[3] + 0.5*(cableW3 - cableW2);
2616     y[4] = y[3] + 0.5*(cableW3 - cableW2);
2617
2618     x[5] = x[4] + cableL3 - 0.5*(cableW3 - cableW2);
2619     y[5] = y[4];
2620
2621     for (Int_t i = 6; i < 12; i++) {
2622         x[i] =  x[11 - i];
2623         y[i] = -y[11 - i];
2624     }
2625
2626     TGeoXtru *shCable = new TGeoXtru(2);
2627     shCable->DefinePolygon(12, x, y);
2628     shCable->DefineSection(0, 0.0);
2629     shCable->DefineSection(1, kCableThickness);
2630
2631     TGeoVolume *volCable = new TGeoVolume("ITSSPDExtender", shCable, medExtB);
2632     volCable->SetLineColor(kGreen);
2633
2634     // The MCM extender on the cone as a Xtru
2635     TGeoBBox *shMCMExt = new TGeoBBox(0.5*kMCMLength,
2636                                       0.5*kMCMWidth,
2637                                       0.5*kMCMThickness);
2638
2639     TGeoVolume *volMCMExt = new TGeoVolume("ITSSPDExtenderMCM",
2640                                            shMCMExt, medExtM);
2641     volMCMExt->SetLineColor(kGreen+3);
2642
2643     // The support plate on the cone as a composite shape
2644     Double_t thickness = kCableThickness + kMCMThickness;
2645     TGeoBBox *shOut = new TGeoBBox("ITSSPD_shape_plateout",
2646                                    0.5*kPlateLength,
2647                                    0.5*kPlateWidth,
2648                                    0.5*kPlateThickness);
2649     TGeoBBox *shIn  = new TGeoBBox("ITSSPD_shape_platein" ,
2650                                    0.5*kPlateLength,
2651                                    0.5*cableW2,
2652                                    0.5*thickness);
2653     Char_t string[255];
2654     snprintf(string, 255, "%s-%s", shOut->GetName(), shIn->GetName());
2655     TGeoCompositeShape *shPlate = new TGeoCompositeShape("ITSSPDPlate_shape",
2656                                  string);
2657
2658     TGeoVolume *volPlate = new TGeoVolume("ITSSPDPlate",
2659                                           shPlate, medPlate);
2660     volPlate->SetLineColor(kRed);
2661     
2662     // The air cooling tubes
2663     TGeoBBox   *shCollBox   = new TGeoBBox("ITSSPD_shape_collector_box", 0.5*kCollLength, 0.5*kCollWidth, 0.5*kCollThickness);
2664     TGeoTube   *shCollTube  = new TGeoTube("ITSSPD_shape_collector_tube",kCollTubeRadius - kCollTubeThick, kCollTubeRadius, 0.5*kCollTubeLength);
2665     TGeoVolume *volCollBox  = new TGeoVolume("ITSSPDCollectorBox", shCollBox, medPVC);
2666     TGeoVolume *volCollTube = new TGeoVolume("ITSSPDCollectorTube", shCollTube, medPVC);
2667     volCollBox->SetLineColor(kAzure);
2668     volCollTube->SetLineColor(kAzure);
2669
2670     // The cooling tube on the cone as a Ctub
2671     Double_t tubeLength = shCable->GetX(5) - shCable->GetX(0) + kYtoHalfStave -0.85;
2672     TGeoCtub *shTube = new TGeoCtub(0, kConeTubeRmax, 0.5*tubeLength, 0, 360,
2673                                     0, SinD(angrot/2), -CosD(angrot/2),
2674                                     0,              0,              1);
2675
2676     TGeoVolume *volTubeA = new TGeoVolume("ITSSPDCoolingTubeOnConeA",
2677                                           shTube, medInox);
2678     volTubeA->SetLineColor(kGray);
2679
2680     TGeoVolume *volTubeC = new TGeoVolume("ITSSPDCoolingTubeOnConeC",
2681                                           shTube, medInox);
2682     volTubeC->SetLineColor(kGray);
2683
2684     // The freon in the cooling tubes on the cone as a Ctub
2685     TGeoCtub *shFreon = new TGeoCtub(0, kConeTubeRmin, 0.5*tubeLength, 0, 360,
2686                                      0, SinD(angrot/2), -CosD(angrot/2),
2687                                      0,              0,              1);
2688
2689     TGeoVolume *volFreon = new TGeoVolume("ITSSPDCoolingFreonOnCone",
2690                                           shFreon, medFreon);
2691     volFreon->SetLineColor(kPurple);
2692
2693     TGeoVolume *volGasFr = new TGeoVolume("ITSSPDCoolingFreonGasOnCone",
2694                                           shFreon, medGas);
2695     volGasFr->SetLineColor(kPurple);
2696
2697     // The cooling tube inside the cylinder as a Ctub
2698     TGeoCtub *shCylTub = new TGeoCtub(0, kConeTubeRmax,
2699                                       0.5*kHorizTubeLen, 0, 360,
2700                                       0,            0,           -1,
2701                                       0, SinD(angrot/2), CosD(angrot/2));
2702
2703     TGeoVolume *volCylTubA = new TGeoVolume("ITSSPDCoolingTubeOnCylA",
2704                                             shCylTub, medInox);
2705     volCylTubA->SetLineColor(kGray);
2706
2707     TGeoVolume *volCylTubC = new TGeoVolume("ITSSPDCoolingTubeOnCylC",
2708                                             shCylTub, medInox);
2709     volCylTubC->SetLineColor(kGray);
2710
2711     // The freon in the cooling tubes in the cylinder as a Ctub
2712     TGeoCtub *shCylFr = new TGeoCtub(0, kConeTubeRmin,
2713                                      0.5*kHorizTubeLen, 0, 360,
2714                                      0,            0,           -1,
2715                                      0, SinD(angrot/2), CosD(angrot/2));
2716
2717     TGeoVolume *volCylFr = new TGeoVolume("ITSSPDCoolingFreonOnCyl",
2718                                           shCylFr, medFreon);
2719     volCylFr->SetLineColor(kPurple);
2720
2721     TGeoVolume *volCylGasFr = new TGeoVolume("ITSSPDCoolingFreonGasOnCyl",
2722                                              shCylFr, medGas);
2723     volCylGasFr->SetLineColor(kPurple);
2724
2725     // The optical fibers bundle on the cone as a Tube
2726     Double_t optLength = shCable->GetX(5) - shCable->GetX(0) + kYtoHalfStave -0.85;
2727     TGeoTube *shOptFibs = new TGeoTube(0., 0.5*kOptFibDiamet, 0.5*optLength);
2728
2729     TGeoVolume *volOptFibs = new TGeoVolume("ITSSPDOpticalFibersOnCone",
2730                                             shOptFibs, medFibs);
2731     volOptFibs->SetLineColor(kOrange);
2732
2733     // The optical patch panels
2734     TArrayD psizes;
2735     TGeoVolume *volPatch = CreatePatchPanel(psizes, mgr);
2736
2737     // The water cooling tube as a Tube
2738     TGeoTube *shWatCool = new TGeoTube(kWaterCoolRMax-kWaterCoolThick,
2739                                        kWaterCoolRMax, kWaterCoolLen/2);
2740
2741     TGeoVolume *volWatCool = new TGeoVolume("ITSSPDWaterCoolingOnCone",
2742                                             shWatCool, medInox);
2743     volWatCool->SetLineColor(kGray);
2744
2745     // The support plate for the water tubes: a Tubs and a BBox
2746     TGeoTubeSeg *shWCPltT = new TGeoTubeSeg(kWaterCoolRMax,
2747                                             kWaterCoolRMax+kWCPlateThick,
2748                                             kWCPlateLen/2, 180., 360.);
2749
2750     Double_t plateBoxWide = (kWCPlateWide - 2*kWaterCoolRMax)/2;
2751     TGeoBBox *shWCPltB = new TGeoBBox(plateBoxWide/2,
2752                                       kWCPlateThick/2,
2753                                       kWCPlateLen/2);
2754
2755     TGeoVolume *volWCPltT = new TGeoVolume("ITSSPDWaterCoolingTubsPlate",
2756                                           shWCPltT, medPlate);
2757     volWCPltT->SetLineColor(kRed);
2758
2759     TGeoVolume *volWCPltB = new TGeoVolume("ITSSPDWaterCoolingBoxPlate",
2760                                           shWCPltB, medPlate);
2761     volWCPltB->SetLineColor(kRed);
2762
2763     // The fitting for the water cooling tube: a Pcon
2764     TGeoPcon *shFitt = new TGeoPcon(0., 360., 4);
2765     shFitt->Z(0)    = -kWCFittingLen1;
2766     shFitt->Rmin(0) =  kWCFittingRint1;
2767     shFitt->Rmax(0) =  kWCFittingRext1;
2768
2769     shFitt->Z(1)    =  0;
2770     shFitt->Rmin(1) =  kWCFittingRint1;
2771     shFitt->Rmax(1) =  kWCFittingRext1;
2772
2773     shFitt->Z(2)    =  0;
2774     shFitt->Rmin(2) =  kWCFittingRint2;
2775     shFitt->Rmax(2) =  kWCFittingRext2;
2776
2777     shFitt->Z(3)    =  kWCFittingLen2;
2778     shFitt->Rmin(3) =  kWCFittingRint2;
2779     shFitt->Rmax(3) =  kWCFittingRext2;
2780
2781     TGeoVolume *volFitt = new TGeoVolume("ITSSPDWaterCoolingFitting",
2782                                          shFitt, medCopper);
2783     volFitt->SetLineColor(kOrange);
2784
2785     // Now place everything in the containers
2786     volTubeA->AddNode(volGasFr, 1, 0);
2787     volTubeC->AddNode(volFreon, 1, 0);
2788
2789     volCylTubA->AddNode(volCylGasFr, 1, 0);
2790     volCylTubC->AddNode(volCylFr   , 1, 0);
2791
2792     container[0]->AddNode(volCable, 1, 0);
2793
2794     xloc = shMCMExt->GetDX() - cableL0;
2795     zloc = shMCMExt->GetDZ();
2796     container[0]->AddNode(volMCMExt, 1,
2797                           new TGeoTranslation( xloc, 0.,-zloc));
2798
2799     xloc = shMCMExt->GetDX();
2800     zloc = shCable->GetZ(1)/2 - shMCMExt->GetDZ();
2801     container[0]->AddNode(volPlate, 1,
2802                           new TGeoTranslation( xloc, 0., zloc));
2803
2804     TGeoRotation *rot2 = new TGeoRotation(*gGeoIdentity);
2805     rot2->SetName("rotPatch");
2806     rot2->RotateX(90.0);
2807     rot2->RotateY(163.0);
2808     //rot2->RotateZ(132.5);
2809     
2810     // add collectors only on side C
2811     if (sideC)
2812     {
2813       TGeoTranslation *trCollBox   = new TGeoTranslation(xloc - 0.5*kPlateLength + 0.5*kCollLength, 0.0, +0.5*(kPlateThickness+1.1*kCollThickness));
2814       TGeoRotation    *rotCollTube = new TGeoRotation(*gGeoIdentity);
2815       rotCollTube->RotateY(90.0);
2816       TGeoCombiTrans  *trCollTube  = new TGeoCombiTrans(xloc + 0.5*kCollTubeLength - (0.5*kPlateLength - kCollLength), 0.0, +0.5*(kPlateThickness+2.0*kCollTubeRadius+kCollTubeThick), rotCollTube);
2817       container[0]->AddNode(volCollBox, 1, trCollBox);
2818       container[0]->AddNode(volCollTube, 1, trCollTube);
2819     }
2820         
2821     Double_t dxPatch = 2.75;
2822     Double_t dzPatch = 2.8;
2823     TGeoCombiTrans *tr2 = new TGeoCombiTrans(1.7*ext2Length - dxPatch, 0.0, dzPatch, rot2);
2824     container[3]->AddNode(volPatch, 0, tr2);
2825
2826     xloc = shTube->GetRmax();
2827     yloc = shTube->GetRmax();
2828     zloc = shTube->GetDz() - shTube->GetRmax() - kYtoHalfStave;
2829     container[1]->AddNode(volTubeA, 1,
2830                           new TGeoTranslation(-xloc, -yloc, zloc));
2831     container[2]->AddNode(volTubeC, 1,
2832                           new TGeoTranslation(-xloc, -yloc, zloc));
2833
2834     xloc = shTube->GetRmax();
2835     yloc = (shCylTub->GetDz())*SinD(angrot) - shTube->GetRmax();
2836     zloc = (shCylTub->GetDz())*CosD(angrot) + shTube->GetRmax() +kYtoHalfStave;
2837     container[1]->AddNode(volCylTubA, 1,
2838                           new TGeoCombiTrans(-xloc, yloc,-zloc,
2839                                      new TGeoRotation("",0.,angrot,0.)));
2840     container[2]->AddNode(volCylTubC, 1,
2841                           new TGeoCombiTrans(-xloc, yloc,-zloc,
2842                                      new TGeoRotation("",0.,angrot,0.)));
2843
2844     xloc = shOptFibs->GetRmax() + 2*shTube->GetRmax();
2845     yloc = 1.6*shOptFibs->GetRmax();
2846     zloc = shOptFibs->GetDZ() - shTube->GetRmax() - kYtoHalfStave;
2847     container[1]->AddNode(volOptFibs, 1,
2848                           new TGeoTranslation(-xloc, -yloc, zloc));
2849     container[2]->AddNode(volOptFibs, 1,
2850                           new TGeoTranslation(-xloc, -yloc, zloc));
2851
2852     yloc = shWatCool->GetRmax();
2853     zloc = (2*shTube->GetDz() - shTube->GetRmax() - kYtoHalfStave)/2;
2854     container[4]->AddNode(volWatCool, 1,
2855                           new TGeoTranslation(0, -yloc, zloc));
2856
2857     container[4]->AddNode(volWCPltT, 1,
2858                           new TGeoTranslation(0, -yloc, zloc));
2859
2860     yloc -= shWCPltB->GetDY();
2861     xloc = shWatCool->GetRmax() + shWCPltB->GetDX();
2862     container[4]->AddNode(volWCPltB, 1,
2863                           new TGeoTranslation( xloc, -yloc, zloc));
2864     container[4]->AddNode(volWCPltB, 2,
2865                           new TGeoTranslation(-xloc, -yloc, zloc));
2866
2867     yloc = shWatCool->GetRmax();
2868     zloc -= shWatCool->GetDz();
2869     container[4]->AddNode(volFitt, 1,
2870                           new TGeoTranslation(0, -yloc, zloc));
2871
2872     // Finally create the list of assemblies and return it to the caller
2873     TList* conemodulelist = new TList();
2874     conemodulelist->Add(container[0]);
2875     conemodulelist->Add(container[1]);
2876     conemodulelist->Add(container[2]);
2877     conemodulelist->Add(container[3]);
2878     conemodulelist->Add(container[4]);
2879
2880     return conemodulelist;
2881 }
2882
2883 //______________________________________________________________________
2884 void AliITSv11GeometrySPD::CreateCones(TGeoVolume *moth) const
2885 {
2886     //
2887     // Places all services modules in the mother reference system
2888     //
2889     // Created:      ?? ??? 2008  Alberto Pulvirenti
2890     // Updated:      03 May 2010  Mario Sitta
2891     // Updated:      04 Jul 2010  Mario Sitta  Water cooling
2892     //
2893
2894     const Int_t kNumberOfModules    =  10;
2895
2896     const Double_t kInnerRadius     =  80.775*fgkmm;
2897     const Double_t kZTrans          = 451.800*fgkmm;
2898     const Double_t kAlphaRot        =  46.500*fgkDegree;
2899     const Double_t kAlphaSpaceCool  =   9.200*fgkDegree;
2900
2901     TList*  modulelistA = CreateConeModule(kFALSE, 90-kAlphaRot);
2902     TList*  modulelistC = CreateConeModule(kTRUE , 90-kAlphaRot);
2903     TList* &modulelist  = modulelistC;
2904     TGeoVolumeAssembly* module, *moduleA, *moduleC;
2905
2906     Double_t xloc, yloc, zloc;
2907
2908     //Double_t angle[10] = {18., 54., 90., 126., 162., -18., -54., -90., -126., -162.};
2909     // anglem for cone modules (cables and cooling tubes)
2910     // anglep for pathc panels
2911     Double_t anglem[10] = {18., 54., 90., 126., 162., 198., 234., 270., 306., 342.};
2912     Double_t anglep[10] = {18., 62., 90., 115., 162., 198., 242., 270., 295., 342.};
2913 //    Double_t angle1m[10] = {23., 53., 90., 127., 157., 203.0, 233.0, 270.0, 307.0, 337.0};
2914 //    Double_t angle2m[10] = {18., 53., 90., 126., 162., 198.0, 233.0, 270.0, 309.0, 342.0};
2915 //    Double_t angle1c[10] = {23., 53., 90., 124., 157., 203.0, 233.0, 270.0, 304.0, 337.0};
2916 //    Double_t angle2c[10] = {18., 44., 90., 126., 162., 198.0, 223.0, 270.0, 309.0, 342.0};
2917
2918     // First add the cables
2919     moduleA = (TGeoVolumeAssembly*)modulelistA->At(0);
2920     moduleC = (TGeoVolumeAssembly*)modulelistC->At(0);
2921     for (Int_t i = 0; i < kNumberOfModules; i++) {
2922         TGeoRotation *rot1 = new TGeoRotation(*gGeoIdentity);
2923         rot1->RotateY(-kAlphaRot);
2924         rot1->RotateZ(anglem[i]);
2925         xloc = kInnerRadius*CosD(anglem[i]);
2926         yloc = kInnerRadius*SinD(anglem[i]);
2927         zloc = kZTrans;
2928         moth->AddNode(moduleA, 2*i+2,
2929                       new TGeoCombiTrans( xloc, yloc, zloc, rot1));
2930
2931         TGeoRotation *rot2 = new TGeoRotation(*gGeoIdentity);
2932         rot2->RotateY(180.-kAlphaRot);
2933         rot2->RotateZ(anglem[i]);
2934         xloc = kInnerRadius*CosD(anglem[i]);
2935         yloc = kInnerRadius*SinD(anglem[i]);
2936         zloc = kZTrans;
2937         moth->AddNode(moduleC, 2*i+1,
2938                       new TGeoCombiTrans(-xloc,-yloc,-zloc, rot2));
2939     }
2940
2941     // Then the cooling tubes on Side A
2942     module = (TGeoVolumeAssembly*)modulelist->At(1);
2943     Double_t anglec;
2944     for (Int_t i = 0; i < kNumberOfModules; i++) {
2945         anglec = anglem[i] + kAlphaSpaceCool;
2946         TGeoRotation *rot1 = new TGeoRotation(*gGeoIdentity);
2947         rot1->RotateX(-90.0+kAlphaRot-0.04); // 0.04 fixes small overlap
2948         rot1->RotateZ(-90.0+anglec);
2949         xloc = kInnerRadius*CosD(anglec);
2950         yloc = kInnerRadius*SinD(anglec);
2951         zloc = kZTrans+0.162; // 0.162 fixes small overlap
2952         moth->AddNode(module, 2*i+2, 
2953                       new TGeoCombiTrans( xloc, yloc, zloc, rot1));
2954     }
2955
2956     // And the cooling tubes on Side C
2957     module = (TGeoVolumeAssembly*)modulelist->At(2);
2958     for (Int_t i = 0; i < kNumberOfModules; i++) {
2959         anglec = anglem[i] - kAlphaSpaceCool;
2960         TGeoRotation *rot2 = new TGeoRotation(*gGeoIdentity);
2961         rot2->RotateX(-90.0+kAlphaRot-0.04); // 0.04 fixes small overlap
2962         rot2->RotateY(180.);
2963         rot2->RotateZ(90.0+anglec);
2964         xloc = kInnerRadius*CosD(anglec);
2965         yloc = kInnerRadius*SinD(anglec);
2966         zloc = kZTrans+0.162; // 0.162 fixes small overlap
2967         moth->AddNode(module, 2*i+1,
2968                       new TGeoCombiTrans(-xloc,-yloc,-zloc, rot2));
2969     }
2970
2971     // Then the water cooling tubes
2972     module = (TGeoVolumeAssembly*)modulelist->At(4);
2973     for (Int_t i = 1; i < kNumberOfModules; i++) { // i = 1,2,...,9
2974         if (i != 5) { // There is no tube in this position
2975           anglec = (anglem[i-1]+anglem[i])/2;
2976             TGeoRotation *rot1 = new TGeoRotation(*gGeoIdentity);
2977             rot1->RotateX(-90.0+kAlphaRot);
2978             rot1->RotateZ(-90.0+anglec);
2979             xloc = kInnerRadius*CosD(anglec);
2980             yloc = kInnerRadius*SinD(anglec);
2981             zloc = kZTrans;
2982             moth->AddNode(module, 2*i+2,
2983                           new TGeoCombiTrans( xloc, yloc, zloc, rot1));
2984
2985             TGeoRotation *rot2 = new TGeoRotation(*gGeoIdentity);
2986             rot2->RotateX(-90.0+kAlphaRot);
2987             rot2->RotateY(180.);
2988             rot2->RotateZ(90.0+anglec);
2989             xloc = kInnerRadius*CosD(anglec);
2990             yloc = kInnerRadius*SinD(anglec);
2991             zloc = kZTrans;
2992             moth->AddNode(module, 2*i+1,
2993                           new TGeoCombiTrans(-xloc,-yloc,-zloc, rot2));
2994         }
2995     }
2996
2997     // Finally the optical patch panels
2998     module = (TGeoVolumeAssembly*)modulelist->At(3);
2999     for (Int_t i = 0; i < kNumberOfModules; i++) {
3000         TGeoRotation *rot1 = new TGeoRotation(*gGeoIdentity);
3001         rot1->RotateY(-kAlphaRot);
3002         rot1->RotateZ(anglep[i]);
3003         xloc = kInnerRadius*CosD(anglep[i]);
3004         yloc = kInnerRadius*SinD(anglep[i]);
3005         zloc = kZTrans;
3006         moth->AddNode(module, 2*i+2,
3007                       new TGeoCombiTrans( xloc, yloc, zloc, rot1));
3008
3009         TGeoRotation *rot2 = new TGeoRotation(*gGeoIdentity);
3010         rot2->RotateY(180.-kAlphaRot);
3011         rot2->RotateZ(anglep[i]);
3012         xloc = kInnerRadius*CosD(anglep[i]);
3013         yloc = kInnerRadius*SinD(anglep[i]);
3014         zloc = kZTrans;
3015         moth->AddNode(module, 2*i+1,
3016                       new TGeoCombiTrans(-xloc,-yloc,-zloc, rot2));
3017     }
3018
3019 }
3020
3021
3022 //______________________________________________________________________
3023 void AliITSv11GeometrySPD::CreateServices(TGeoVolume *moth) const
3024 {
3025     //
3026     // New method to implement SPD services
3027     //
3028     // Created:      25 Jul 2012  Mario Sitta
3029     //
3030     // Data provided by C.Gargiulo from CAD
3031
3032     // Cooling manifolds
3033     const Double_t kCoolManifWidth    = fgkmm * 22.0;
3034     const Double_t kCoolManifLength   = fgkmm * 50.0;
3035     const Double_t kCoolManifThick    = fgkmm *  7.0;
3036     const Double_t kCoolManifFitR1out = fgkmm *  4.0; // TO BE CHECKED!
3037     const Double_t kCoolManifFitH1    = fgkmm *  2.5;
3038     const Double_t kCoolManifFitR2out = fgkmm *  4.0;
3039     const Double_t kCoolManifFitR2in  = fgkmm *  3.2;
3040     const Double_t kCoolManifFitH2    = fgkmm *  7.0;
3041     const Double_t kCoolManifFitZPos  = fgkmm *  2.0; // TO BE CHECKED!
3042     const Double_t kCoolManifCollR1   = fgkmm *  3.0;
3043     const Double_t kCoolManifCollH1   = fgkmm *  2.5;
3044     const Double_t kCoolManifCollR2   = fgkmm *  1.5;
3045     const Double_t kCoolManifCollH2   = fgkmm *  5.0;
3046     const Double_t kCoolManifCollDX   = fgkmm *  6.0;
3047     const Double_t kCoolManifCollDZ   = fgkmm * 13.0;
3048     const Double_t kCoolManifCollZ0   = fgkmm *  6.0; // ??? should be 9...
3049
3050     const Double_t kCoolManifRPos     = fgkmm * 76.2;
3051     const Double_t kCoolManifZPos     = fgkcm * 34.0;
3052
3053
3054     // Local variables
3055     Double_t radius, theta;
3056     Double_t xpos, ypos, zpos;
3057
3058     // The cooling manifold: an Assembly
3059     TGeoVolumeAssembly *coolmanif = new TGeoVolumeAssembly("ITSSPDCoolManif");
3060
3061     // The various parts of the manifold
3062     TGeoBBox *manifblksh = new TGeoBBox(kCoolManifWidth/2,
3063                                         kCoolManifThick/2,
3064                                         kCoolManifLength/2);
3065
3066     TGeoBBox *manifinscubesh = new TGeoBBox(kCoolManifFitR2out,
3067                                             kCoolManifFitR2out,
3068                                             kCoolManifFitR2out);
3069
3070     TGeoTube *manifinscyl1sh = new TGeoTube(0, // TO BE CHECKED!
3071                                             kCoolManifFitR1out,
3072                                             kCoolManifFitH1/2);
3073
3074     TGeoTube *manifinscyl2sh = new TGeoTube(kCoolManifFitR2in,
3075                                             kCoolManifFitR2out,
3076                                             kCoolManifFitH2/2);
3077
3078     TGeoTube *manifcollcyl1sh = new TGeoTube(0,
3079                                              kCoolManifCollR1,
3080                                              kCoolManifCollH1/2);
3081
3082     TGeoTube *manifcollcyl2sh = new TGeoTube(0,
3083                                              kCoolManifCollR2,
3084                                              kCoolManifCollH2/2);
3085
3086
3087     // We have the shapes: now create the real volumes
3088     TGeoMedium *medInox  = GetMedium("INOX$");
3089     TGeoMedium *medCu    = GetMedium("COPPER$");
3090
3091     TGeoVolume *manifblk = new TGeoVolume("ITSSPDBlkManif",
3092                                           manifblksh,medInox);
3093     manifblk->SetLineColor(kGreen+2);
3094
3095     TGeoVolume *manifinscube = new TGeoVolume("ITSSPDInsCubeManif",
3096                                               manifinscubesh,medCu);
3097     manifinscube->SetLineColor(kYellow);
3098
3099     TGeoVolume *manifinscyl1 = new TGeoVolume("ITSSPDInsCyl1Manif",
3100                                               manifinscyl1sh,medCu);
3101     manifinscyl1->SetLineColor(kYellow);
3102
3103     TGeoVolume *manifinscyl2 = new TGeoVolume("ITSSPDInsCyl2Manif",
3104                                               manifinscyl2sh,medCu);
3105     manifinscyl2->SetLineColor(kYellow);
3106
3107     TGeoVolume *manifcollcyl1 = new TGeoVolume("ITSSPDCollCyl1Manif",
3108                                                manifcollcyl1sh,medCu);
3109     manifcollcyl1->SetLineColor(kYellow);
3110
3111     TGeoVolume *manifcollcyl2 = new TGeoVolume("ITSSPDCollCyl2Manif",
3112                                                manifcollcyl2sh,medCu);
3113     manifcollcyl2->SetLineColor(kYellow);
3114
3115
3116     // Add all volumes in the assemblies
3117     coolmanif->AddNode(manifblk,1,0);
3118
3119     ypos = manifblksh->GetDY() + manifinscyl1sh->GetDz();
3120     zpos = manifblksh->GetDZ() - manifinscyl1sh->GetRmax() - kCoolManifFitZPos;
3121     coolmanif->AddNode(manifinscyl1, 1, new TGeoCombiTrans(0, -ypos, zpos,
3122                                         new TGeoRotation("",0,90,0)));
3123
3124     ypos += (manifinscyl1sh->GetDz() + manifinscubesh->GetDY());
3125     coolmanif->AddNode(manifinscube, 1, new TGeoTranslation(0, -ypos, zpos));
3126
3127     zpos += (manifinscubesh->GetDZ() + manifinscyl2sh->GetDz());
3128     coolmanif->AddNode(manifinscyl2, 1, new TGeoTranslation(0, -ypos, zpos));
3129
3130     xpos = kCoolManifCollDX;
3131     ypos = manifblksh->GetDY() + manifcollcyl1sh->GetDz();
3132     zpos =-manifblksh->GetDZ() + manifcollcyl1sh->GetRmax() + kCoolManifCollZ0;
3133     for (Int_t i=0; i<3; i++) {
3134       coolmanif->AddNode(manifcollcyl1, 2*i+1,
3135                          new TGeoCombiTrans( xpos, -ypos, zpos,
3136                                              new TGeoRotation("",0,90,0)));
3137       coolmanif->AddNode(manifcollcyl1, 2*i+2,
3138                          new TGeoCombiTrans(-xpos, -ypos, zpos,
3139                                              new TGeoRotation("",0,90,0)));
3140       Double_t y = ypos + manifcollcyl1sh->GetDz() + manifcollcyl2sh->GetDz();
3141       coolmanif->AddNode(manifcollcyl2, 2*i+1,
3142                          new TGeoCombiTrans( xpos, -y, zpos,
3143                                              new TGeoRotation("",0,90,0)));
3144       coolmanif->AddNode(manifcollcyl2, 2*i+2,
3145                          new TGeoCombiTrans(-xpos, -y, zpos,
3146                                              new TGeoRotation("",0,90,0)));
3147       zpos += kCoolManifCollDZ;
3148     }
3149
3150
3151     // Finally put everything in the mother volume
3152     radius = kCoolManifRPos + (manifinscubesh->GetDY() +
3153                              2*manifinscyl1sh->GetDz() +
3154                                manifblksh->GetDY()     );
3155     zpos = kCoolManifZPos + manifblksh->GetDZ();
3156     for (Int_t i=0; i<10; i++) {
3157       theta = 36.*i;
3158       moth->AddNode(coolmanif, 2*i+1, new TGeoCombiTrans(radius*SinD(theta),
3159                                                          radius*CosD(theta),
3160                                                          zpos,
3161                                           new TGeoRotation("",-theta,0,0)));
3162       moth->AddNode(coolmanif, 2*i+2, new TGeoCombiTrans(radius*SinD(theta),
3163                                                          radius*CosD(theta),
3164                                                         -zpos,
3165                                           new TGeoRotation("",90-theta,180,-90)));
3166     }
3167
3168 }
3169
3170
3171 //______________________________________________________________________
3172 TGeoVolume* AliITSv11GeometrySPD::CreateExtender(
3173     const Double_t *extenderParams, const TGeoMedium *extenderMedium,
3174     TArrayD& sizes) const
3175 {
3176     //
3177     // ------------------   CREATE AN EXTENDER    ------------------------
3178     //
3179     // This function creates the following picture (in plane xOy)
3180     // Should be useful for the definition of the pixel bus and MCM extenders
3181     // The origin corresponds to point 0 on the picture, at half-width
3182     // in Z direction
3183     //
3184     //   Y                         7     6                      5
3185     //   ^                           +---+---------------------+
3186     //   |                          /                          |
3187     //   |                         /                           |
3188     //   0------> X               /      +---------------------+
3189     //                           /      / 3                     4
3190     //                          /      /
3191     //            9          8 /      /
3192     //            +-----------+      /
3193     //            |                 /
3194     //            |                /
3195     //      --->  +-----------+---+
3196     //      |     0          1     2
3197     //      |
3198     //  origin (0,0,0)
3199     //
3200     //
3201     // Takes 6 parameters in the following order :
3202     //   |--> par 0 : inner length [0-1] / [9-8]
3203     //   |--> par 1 : thickness ( = [0-9] / [4-5])
3204     //   |--> par 2 : angle of the slope
3205     //   |--> par 3 : total height in local Y direction
3206     //   |--> par 4 : outer length [3-4] / [6-5]
3207     //   |--> par 5 : width in local Z direction
3208     //
3209     Double_t slopeDeltaX = (extenderParams[3] - extenderParams[1]
3210                             * TMath::Cos(extenderParams[2])) /
3211                             TMath::Tan(extenderParams[2]);
3212     Double_t extenderXtruX[10] = {
3213         0 ,
3214         extenderParams[0] ,
3215         extenderParams[0]+extenderParams[1]*TMath::Sin(extenderParams[2]) ,
3216         extenderParams[0]+extenderParams[1]*TMath::Sin(extenderParams[2])+
3217                                                               slopeDeltaX ,
3218         extenderParams[0]+extenderParams[1]*TMath::Sin(extenderParams[2])+
3219                                            slopeDeltaX + extenderParams[4],
3220         extenderParams[0]+extenderParams[1]*TMath::Sin(extenderParams[2])+
3221                                            slopeDeltaX + extenderParams[4],
3222         extenderParams[0]+extenderParams[1]*TMath::Sin(extenderParams[2])+
3223                                                               slopeDeltaX ,
3224         extenderParams[0]+extenderParams[1]*TMath::Sin(extenderParams[2])+
3225           slopeDeltaX - extenderParams[1] * TMath::Sin(extenderParams[2]) ,
3226         extenderParams[0] ,
3227         0
3228     };
3229     Double_t extenderXtruY[10] = {
3230         0 ,
3231         0 ,
3232         extenderParams[1] * (1-TMath::Cos(extenderParams[2])) ,
3233         extenderParams[3] - extenderParams[1] ,
3234         extenderParams[3] - extenderParams[1] ,
3235         extenderParams[3] ,
3236         extenderParams[3] ,
3237         extenderParams[3]-extenderParams[1]*(1-TMath::Cos(extenderParams[2])) ,
3238         extenderParams[1] ,
3239         extenderParams[1]
3240     };
3241
3242     if (sizes.GetSize() != 3) sizes.Set(3);
3243     Double_t &thickness = sizes[0];
3244     Double_t &length    = sizes[1];
3245     Double_t &width     = sizes[2];
3246
3247     thickness = extenderParams[3];
3248     width     = extenderParams[5];
3249     length    = extenderParams[0]+extenderParams[1]*
3250             TMath::Sin(extenderParams[2])+slopeDeltaX+extenderParams[4];
3251
3252     // creation of the volume
3253     TGeoXtru   *extenderXtru    = new TGeoXtru(2);
3254     TGeoVolume *extenderXtruVol = new TGeoVolume("ITSSPDextender",extenderXtru,
3255                                                  extenderMedium);
3256     extenderXtru->DefinePolygon(10,extenderXtruX,extenderXtruY);
3257     extenderXtru->DefineSection(0,-0.5*extenderParams[4]);
3258     extenderXtru->DefineSection(1, 0.5*extenderParams[4]);
3259     return extenderXtruVol;
3260 }
3261
3262 //______________________________________________________________________
3263 TGeoVolumeAssembly* AliITSv11GeometrySPD::CreateHalfStave(Bool_t isRight,
3264 Int_t layer,Int_t idxCentral,Int_t idxSide,TArrayD &sizes,TGeoManager *mgr)
3265 {
3266     //
3267     // Implementation of an half-stave, which depends on the side where
3268     // we are on the stave. The convention for "left" and "right" is the
3269     // same as for the MCM. The return value is a TGeoAssembly which is
3270     // structured in such a way that the origin of its local reference
3271     // frame coincides with the origin of the whole stave.
3272     // The TArrayD passed by reference will contain details of the shape:
3273     //  - sizes[0] = thickness
3274     //  - sizes[1] = length
3275     //  - sizes[2] = width
3276     //  - sizes[3] = common 'x' position for eventual clips
3277     //  - sizes[4] = common 'y' position for eventual clips
3278     //  - sizes[5] = 'z' position of first clip
3279     //  - sizes[6] = 'z' position of second clip
3280     //
3281
3282     // ** CHECK **
3283
3284     // idxCentral and idxSide must be different
3285     if (idxCentral == idxSide) {
3286         AliInfo("Ladders must be inserted in half-stave with "
3287                 "different indexes.");
3288         idxSide = idxCentral + 1;
3289         AliInfo(Form("Central ladder will be inserted with index %d",
3290                      idxCentral));
3291         AliInfo(Form("Side    ladder will be inserted with index %d",idxSide));
3292     } // end if
3293
3294     // define the separations along Z direction between the objects
3295     Double_t sepLadderLadder = fgkmm * 0.2; // sep. btw the 2 ladders
3296     Double_t sepLadderCenter = fgkmm * 0.4; // sep. btw the "central" ladder
3297                                             // and the Z=0 plane in stave ref.
3298     Double_t sepLadderMCM    = fgkmm * 0.3; // sep. btw the "external" ladder
3299                                             // and MCM
3300     Double_t sepBusCenter    = fgkmm * 0.3; // sep. btw the bus central edge
3301                                             // and the Z=0 plane in stave ref.
3302
3303     // ** VOLUMES **
3304
3305     // grounding foil
3306     TArrayD grndSize(3);
3307     // This one line repalces the 3 bellow, BNS.
3308     TGeoVolume *grndVol = CreateGroundingFoil(isRight, grndSize, mgr);
3309     Double_t &grndThickness = grndSize[0];
3310     Double_t &grndLength = grndSize[1];
3311
3312     // ladder
3313     TArrayD ladderSize(3);
3314     TGeoVolume *ladder = CreateLadder(layer, ladderSize, mgr);
3315     Double_t ladderThickness = ladderSize[0];
3316     Double_t ladderLength = ladderSize[1];
3317     Double_t ladderWidth = ladderSize[2];
3318
3319     // MCM
3320     TArrayD mcmSize(3);
3321     TGeoVolumeAssembly *mcm = CreateMCM(!isRight,mcmSize,mgr);
3322     Double_t mcmThickness = mcmSize[0];
3323     Double_t mcmLength = mcmSize[1];
3324     Double_t mcmWidth = mcmSize[2];
3325
3326     // bus
3327     TArrayD busSize(6);
3328     TGeoVolumeAssembly *bus = CreatePixelBus(isRight, layer, busSize, mgr);
3329     Double_t busThickness = busSize[0];
3330     Double_t busLength = busSize[1];
3331     Double_t busWidth = busSize[2];
3332
3333     // glue between ladders and pixel bus
3334     TGeoMedium *medLadGlue = GetMedium("EPOXY$", mgr);
3335     Double_t ladGlueThickness = fgkmm * 0.1175 - fgkGapLadder;
3336     TGeoVolume *ladderGlue = mgr->MakeBox("ITSSPDladderGlue",medLadGlue,
3337                            0.5*ladGlueThickness, 0.5*busWidth, 0.5*busLength);
3338     ladderGlue->SetLineColor(kYellow + 5);
3339
3340     // create references for the whole object, as usual
3341     sizes.Set(7);
3342     Double_t &fullThickness = sizes[0];
3343     Double_t &fullLength = sizes[1];
3344     Double_t &fullWidth = sizes[2];
3345
3346     // compute the full size of the container
3347     fullLength    = sepLadderCenter+2.0*ladderLength+sepLadderMCM+
3348                        sepLadderLadder+mcmLength;
3349     fullWidth     = ladderWidth;
3350     fullThickness = grndThickness + fgkGapLadder + mcmThickness + busThickness;
3351     //cout << "HSTAVE FULL THICKNESS = " << fullThickness << endl;
3352
3353     // ** MOVEMENTS **
3354
3355     // grounding foil (shifted only along thickness)
3356     Double_t xGrnd = -0.5*fullThickness + 0.5*grndThickness;
3357     Double_t zGrnd = -0.5*grndLength;
3358     if (!isRight) zGrnd = -zGrnd;
3359     TGeoTranslation *grndTrans = new TGeoTranslation(xGrnd, 0.0, zGrnd);
3360
3361     // ladders (translations along thickness and length)
3362     // layers must be sorted going from the one at largest Z to the
3363     // one at smallest Z:
3364     // -|Zmax| ------> |Zmax|
3365     //      3   2   1   0
3366     // then, for layer 1 ladders they must be placed exactly this way,
3367     // and in layer 2 at the opposite. In order to remember the placements,
3368     // we define as "inner" and "outer" ladder respectively the one close
3369     // to barrel center, and the one closer to MCM, respectively.
3370     Double_t xLad, zLadIn, zLadOut;
3371     xLad    = xGrnd + 0.5*(grndThickness + ladderThickness) +
3372               0.01175 - fgkGapLadder;
3373     zLadIn  = -sepLadderCenter - 0.5*ladderLength;
3374     zLadOut = zLadIn - sepLadderLadder - ladderLength;
3375     if (!isRight) {
3376         zLadIn = -zLadIn;
3377         zLadOut = -zLadOut;
3378     } // end if !isRight
3379     TGeoRotation *rotLad = new TGeoRotation(*gGeoIdentity);
3380     rotLad->RotateZ(90.0);
3381     rotLad->RotateY(180.0);
3382     Double_t sensWidth      = fgkmm * 12.800;
3383     Double_t chipWidth      = fgkmm * 15.950;
3384     Double_t guardRingWidth = fgkmm *  0.560;
3385     Double_t ladderShift = 0.5 * (chipWidth - sensWidth - 2.0*guardRingWidth);
3386     TGeoCombiTrans *trLadIn  = new TGeoCombiTrans(xLad,ladderShift,zLadIn,
3387                                                   rotLad);
3388     TGeoCombiTrans *trLadOut = new TGeoCombiTrans(xLad,ladderShift,zLadOut,
3389                                                   rotLad);
3390
3391     // MCM (length and thickness direction, placing at same level as the
3392     // ladder, which implies to recompute the position of center, because
3393     // ladder and MCM have NOT the same thickness) the two copies of the
3394     // MCM are placed at the same distance from the center, on both sides
3395     Double_t xMCM = xGrnd + 0.5*grndThickness + 0.5*mcmThickness +
3396                     0.01175 - fgkGapLadder;
3397     Double_t yMCM = 0.5*(fullWidth - mcmWidth);
3398     Double_t zMCM = zLadOut - 0.5*ladderLength - 0.5*mcmLength - sepLadderMCM;
3399     if (!isRight) zMCM = zLadOut + 0.5*ladderLength + 0.5*mcmLength +
3400                          sepLadderMCM;
3401
3402     // create the correction rotations
3403     TGeoRotation *rotMCM = new TGeoRotation(*gGeoIdentity);
3404     rotMCM->RotateY(90.0);
3405     TGeoCombiTrans *trMCM = new TGeoCombiTrans(xMCM, yMCM, zMCM, rotMCM);
3406
3407     // glue between ladders and pixel bus
3408     Double_t xLadGlue = xLad + 0.5*ladderThickness + 0.01175 -
3409                         fgkGapLadder + 0.5*ladGlueThickness;
3410
3411     // bus (length and thickness direction)
3412     Double_t xBus = xLadGlue + 0.5*ladGlueThickness + 0.5*busThickness;
3413     Double_t yBus  = 0.5*(fullWidth - busWidth) + 0.075; // Hardcode fix of a small overlap
3414     Double_t zBus = -0.5*busLength - sepBusCenter;
3415     if (!isRight) zBus = -zBus;
3416     TGeoTranslation *trBus = new TGeoTranslation(xBus, yBus, zBus);
3417
3418     TGeoTranslation *trLadGlue = new TGeoTranslation(xLadGlue, 0.0, zBus);
3419
3420     // create the container
3421     TGeoVolumeAssembly *container = 0;
3422     if (idxCentral+idxSide==5) {
3423         container = new TGeoVolumeAssembly("ITSSPDhalf-Stave1");
3424     } else {
3425         container = new TGeoVolumeAssembly("ITSSPDhalf-Stave0");
3426     } // end if
3427
3428     // add to container all objects
3429     container->AddNode(grndVol, 1, grndTrans);
3430     // ladders are inserted in different order to respect numbering scheme
3431     // which is inverted when going from outer to inner layer
3432     container->AddNode(ladder, idxCentral+1, trLadIn);
3433     container->AddNode(ladder, idxSide+1, trLadOut);
3434     container->AddNode(ladderGlue, 1, trLadGlue);
3435     container->AddNode(mcm, 1, trMCM);
3436     container->AddNode(bus, 1, trBus);
3437
3438     // since the clips are placed in correspondence of two pt1000s,
3439     // their position is computed here, but they are not added by default
3440     // it will be the StavesInSector method which will decide to add them
3441     // anyway, to recovery some size informations on the clip, it must be
3442     // created
3443     TArrayD clipSize;
3444     //    TGeoVolume *clipDummy = CreateClip(clipSize, kTRUE, mgr);
3445     CreateClip(clipSize, kTRUE, mgr);
3446     // define clip movements (width direction)
3447     sizes[3] = xBus + 0.5*busThickness;
3448     sizes[4] = 0.5 * (fullWidth - busWidth) - clipSize[6] - fgkmm*0.26;
3449     sizes[5] = zBus + busSize[4];
3450     sizes[6] = zBus + busSize[5];
3451
3452     return container;
3453 }
3454 //______________________________________________________________________
3455 TGeoVolumeAssembly* AliITSv11GeometrySPD::CreateStave(Int_t layer,
3456                                     TArrayD &sizes, TGeoManager *mgr)
3457 {
3458     //
3459     // This method uses all other ones which create pieces of the stave
3460     // and assemblies everything together, in order to return the whole
3461     // stave implementation, which is returned as a TGeoVolumeAssembly,
3462     // due to the presence of some parts which could generate fake overlaps
3463     // when put on the sector.
3464     // This assembly contains, going from bottom to top in the thickness
3465     // direction:
3466     //   - the complete grounding foil, defined by the "CreateGroundingFoil"
3467     //     method which already joins some glue and real groudning foil
3468     //     layers for the whole stave (left + right);
3469     //   - 4 ladders, which are sorted according to the ALICE numbering
3470     //     scheme, which depends on the layer we are building this stave for;
3471     //   - 2 MCMs (a left and a right one);
3472     //   - 2 pixel buses (a left and a right one);
3473     // ---
3474     // Arguments:
3475     //   - the layer number, which determines the displacement and naming
3476     //     of sensitive volumes
3477     //   - a TArrayD passed by reference which will contain the size
3478     //     of virtual box containing the stave
3479     //   - the TGeoManager
3480     //
3481
3482     // create the container
3483     TGeoVolumeAssembly *container = new TGeoVolumeAssembly(Form(
3484                                                  "ITSSPDlay%d-Stave",layer));
3485     // define the indexes of the ladders in order to have the correct order
3486     // keeping in mind that the staves will be inserted as they are on layer
3487     // 2, while they are rotated around their local Y axis when inserted
3488     // on layer 1, so in this case they must be put in the "wrong" order
3489     // to turn out to be right at the end. The convention is:
3490     //   -|Zmax| ------> |Zmax|
3491     //      3   2   1   0
3492     // with respect to the "native" stave reference frame, "left" is in
3493     // the positive Z this leads the definition of these indexes:
3494     Int_t idxCentralL, idxSideL, idxCentralR, idxSideR;
3495
3496     if (layer == 1) {
3497         idxSideL = 3;
3498         idxCentralL = 2;
3499         idxCentralR = 1;
3500         idxSideR = 0;
3501     } else {
3502         idxSideL = 0;
3503         idxCentralL = 1;
3504         idxCentralR = 2;
3505         idxSideR = 3;
3506     } // end if layer ==1
3507
3508      // create the two half-staves
3509     TArrayD sizeL, sizeR;
3510     TGeoVolumeAssembly *hstaveL = CreateHalfStave(kFALSE, layer, idxCentralL,
3511                                              idxSideL, sizeL,mgr);
3512     TGeoVolumeAssembly *hstaveR = CreateHalfStave(kTRUE, layer, idxCentralR,
3513                                              idxSideR, sizeR, mgr);
3514     // copy the size to the stave's one
3515     sizes.Set(9);
3516     sizes[0] = sizeL[0];
3517     sizes[1] = sizeR[1] + sizeL[1];
3518     sizes[2] = sizeL[2];
3519     sizes[3] = sizeL[3];
3520     sizes[4] = sizeL[4];
3521     sizes[5] = sizeL[5];
3522     sizes[6] = sizeL[6];
3523     sizes[7] = sizeR[5];
3524     sizes[8] = sizeR[6];
3525
3526     // add to container all objects
3527     container->AddNode(hstaveL, 1);
3528     container->AddNode(hstaveR, 1);
3529
3530     return container;
3531 }
3532 //______________________________________________________________________
3533 void AliITSv11GeometrySPD::SetAddStave(Bool_t *mask)
3534 {
3535     //
3536     // Define a mask which states qhich staves must be placed.
3537     // It is a string which must contain '0' or '1' depending if
3538     // a stave must be placed or not.
3539     // Each place is referred to one of the staves, so the first
3540     // six characters of the string will be checked.
3541     //
3542      Int_t i;
3543
3544      for (i = 0; i < 6; i++) fAddStave[i] = mask[i];
3545 }
3546 //______________________________________________________________________
3547 void AliITSv11GeometrySPD::StavesInSector(TGeoVolume *moth, TGeoManager *mgr)
3548 {
3549     //
3550     // Unification of essentially two methods:
3551     // - the one which creates the sector structure
3552     // - the one which returns the complete stave
3553     // ---
3554     // For compatibility, this method requires the same arguments
3555     // asked by "CarbonFiberSector" method, which is recalled here.
3556     // Like this cited method, this one does not return any value,
3557     // but it inserts in the mother volume (argument 'moth') all the stuff
3558     // which composes the complete SPD sector.
3559     // ---
3560     // In the following, the stave numbering order used for arrays is the
3561     // same as defined in the GetSectorMountingPoints():
3562     //                         /5
3563     //                        /\/4
3564     //                      1\   \/3
3565     //                      0|___\/2
3566     // ---
3567     // Arguments: see description of "CarbonFiberSector" method.
3568     //
3569
3570     Double_t shift[6];  // shift from the innermost position in the
3571                         // sector placement plane (where the stave
3572                         // edge is in the point where the rounded
3573                         // corner begins)
3574
3575     shift[0] = fgkmm * -0.691;
3576     shift[1] = fgkmm *  5.041;
3577     shift[2] = fgkmm *  1.816;
3578     shift[3] = fgkmm * -0.610;
3579     shift[4] = fgkmm * -0.610;
3580     shift[5] = fgkmm * -0.610;
3581
3582     // corrections after interaction with Andrea and CAD
3583     Double_t corrX[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
3584     Double_t corrY[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
3585
3586     corrX[0] =  0.0046;
3587     corrX[1] = -0.0041;
3588     corrX[2] = corrX[3] = corrX[4] = corrX[5] = -0.0016;
3589
3590     corrY[0] = -0.0007;
3591     corrY[1] = -0.0009;
3592     corrY[2] = corrY[3] = corrY[4] = corrY[5] = -0.0003;
3593
3594     corrX[0] +=  0.00026;
3595     corrY[0] += -0.00080;
3596
3597     corrX[1] +=  0.00018;
3598     corrY[1] += -0.00086;
3599
3600     corrX[2] +=  0.00020;
3601     corrY[2] += -0.00062;
3602
3603     corrX[3] +=  0.00017;
3604     corrY[3] += -0.00076;
3605
3606     corrX[4] +=  0.00016;
3607     corrY[4] += -0.00096;
3608
3609     corrX[5] +=  0.00018;
3610     corrY[5] += -0.00107;
3611
3612     // create stave volumes (different for layer 1 and 2)
3613     TArrayD staveSizes1(9), staveSizes2(9), clipSize(5);
3614     Double_t &staveHeight = staveSizes1[2], &staveThickness = staveSizes1[0];
3615     TGeoVolume *stave1 = CreateStave(1, staveSizes1, mgr);
3616     TGeoVolume *stave2 = CreateStave(2, staveSizes2, mgr);
3617     TGeoVolume *clip   = CreateClip(clipSize, kFALSE, mgr);
3618
3619     Double_t xL, yL;      // leftmost edge of mounting point (XY projection)
3620     Double_t xR, yR;      // rightmost edge of mounting point (XY projection)
3621     Double_t xM, yM;      // middle point of the segment L-R
3622     Double_t dx, dy;      // (xL - xR) and (yL - yR)
3623     Double_t widthLR;     // width of the segment L-R
3624     Double_t angle;       // stave rotation angle in degrees
3625     Double_t diffWidth;   // difference between mounting plane width and
3626                           // stave width (smaller)
3627     Double_t xPos, yPos;  // final translation of the stave
3628     Double_t parMovement; // translation in the LR plane direction
3629
3630     staveThickness += fgkGapHalfStave;
3631
3632     // loop on staves
3633     Int_t i, iclip = 1;
3634     for (i = 0; i < 6; i++) {
3635         // in debug mode, if this stave is not required, it is skipped
3636         if (!fAddStave[i]) continue;
3637         // retrieve reference points
3638         GetSectorMountingPoints(i, xL, yL, xR, yR);
3639         xM = 0.5 * (xL + xR);
3640         yM = 0.5 * (yL + yR);
3641         dx = xL - xR;
3642         dy = yL - yR;
3643         angle = TMath::ATan2(dy, dx);
3644         widthLR = TMath::Sqrt(dx*dx + dy*dy);
3645         diffWidth = 0.5*(widthLR - staveHeight);
3646         // first, a movement along this plane must be done
3647         // by an amount equal to the width difference
3648         // and then the fixed shift must also be added
3649         parMovement = diffWidth + shift[i];
3650         // due to stave thickness, another movement must be done
3651         // in the direction normal to the mounting plane
3652         // which is computed using an internal method, in a reference
3653         // frame where the LR segment has its middle point in the origin
3654         // and axes parallel to the master reference frame
3655         if (i == 0) {
3656             ParallelPosition(-0.5*staveThickness, -parMovement, angle,
3657                                   xPos, yPos);
3658         } // end if i==0
3659         if (i == 1) {
3660             ParallelPosition( 0.5*staveThickness, -parMovement, angle,
3661                                   xPos, yPos);
3662         }else {
3663             ParallelPosition( 0.5*staveThickness,  parMovement, angle,
3664                                   xPos, yPos);
3665         } // end if i==1
3666         // then we go into the true reference frame
3667         xPos += xM;
3668         yPos += yM;
3669         xPos += corrX[i];
3670         yPos += corrY[i];
3671         // using the parameters found here, compute the
3672         // translation and rotation of this stave:
3673         TGeoRotation *rot = new TGeoRotation(*gGeoIdentity);
3674         if (i == 0 || i == 1) rot->RotateX(180.0);
3675         rot->RotateZ(90.0 + angle * TMath::RadToDeg());
3676         TGeoCombiTrans *trans = new TGeoCombiTrans(xPos, yPos, 0.0, rot);
3677         if (i == 0 || i == 1) {
3678             moth->AddNode(stave1, i+1, trans);
3679         }else {
3680             moth->AddNode(stave2, i - 1, trans);
3681             if (i != 2) {
3682                 // except in the case of stave #2,
3683                 // clips must be added, and this is done directly on the sector
3684                 Int_t j;
3685                 //TArrayD clipSize;
3686                 TGeoRotation *rotClip = new TGeoRotation(*gGeoIdentity);
3687                 rotClip->RotateZ(-90.0);
3688                 rotClip->RotateX(180.0);
3689                 Double_t x = staveSizes2[3] + fgkGapHalfStave;
3690                 Double_t y = staveSizes2[4];
3691                 Double_t z[4] = { staveSizes2[5], staveSizes2[6],
3692                                   staveSizes2[7], staveSizes2[8] };
3693                 for (j = 0; j < 4; j++) {
3694                     TGeoCombiTrans *trClip = new TGeoCombiTrans(x, y, z[j],
3695                                                                 rotClip);
3696                     *trClip = *trans * *trClip;
3697                     moth->AddNode(clip, iclip++, trClip);
3698                 } // end for j
3699             } // end if i!=2
3700         } // end if i==0||i==1 else
3701     } // end for i
3702     
3703     
3704     // Add a box representing the collector for cooling tubes
3705     // MOVED TO CreateServices() - M.S. 25 jul 12
3706     
3707 }
3708 //______________________________________________________________________
3709 void AliITSv11GeometrySPD::ParallelPosition(Double_t dist1, Double_t dist2,
3710                                Double_t phi, Double_t &x, Double_t &y) const
3711 {
3712     //
3713     // Performs the following steps:
3714     // 1 - finds a straight line parallel to the one passing through
3715     //     the origin and with angle 'phi' with X axis(phi in RADIANS);
3716     // 2 - finds another line parallel to the previous one, with a
3717     //     distance 'dist1' from it
3718     // 3 - takes a reference point in the second line in the intersection
3719     //     between the normal to both lines  passing through the origin
3720     // 4 - finds a point whith has distance 'dist2' from this reference,
3721     //     in the second line (point 2)
3722     // ----
3723     // According to the signs given to dist1 and dist2, the point is
3724     // found in different position w.r. to the origin
3725     // compute the point
3726     //
3727     Double_t cs = TMath::Cos(phi);
3728     Double_t sn = TMath::Sin(phi);
3729
3730     x = dist2*cs - dist1*sn;
3731     y = dist1*cs + dist2*sn;
3732 }
3733 //______________________________________________________________________
3734 Double_t AliITSv11GeometrySPD::GetSPDSectorTranslation(
3735     Double_t x0,Double_t y0,Double_t x1,Double_t y1,Double_t r) const
3736 {
3737     //
3738     // Comutes the radial translation of a sector to give the
3739     // proper distance between SPD detectors and the beam pipe.
3740     // Units in are units out.
3741     //
3742
3743     //Begin_Html
3744     /*
3745       <A HREF="http://www.physics.ohio-state.edu/HIRG/SoftWareDoc/SPD_Sector_Position.png">
3746       Figure showing the geometry used in the computation below. </A>
3747      */
3748     //End_Html
3749
3750     // Inputs:
3751     //   Double_t x0  Point x0 on Sector surface for the inner
3752     //                most detector mounting
3753     //   Double_t y0  Point y0 on Sector surface for the innor
3754     //                most detector mounting
3755     //   Double_t x1  Point x1 on Sector surface for the inner
3756     //                most detector mounting
3757     //   Double_t y1  Point y1 on Sector surface for the innor
3758     //                most detector mounting
3759     //   Double_t r   The radial distance this mounting surface
3760     //                should be from the center of the beam pipe.
3761     // Outputs:
3762     //   none.
3763     // Return:
3764     //   The distance the SPD sector should be displaced radialy.
3765     //
3766     Double_t a,b,c;
3767
3768     a = x0-x1;
3769     if(a==0.0) return 0.0;
3770     a = (y0-y1)/a;
3771     b = TMath::Sqrt(1.0+a*a);
3772     c = y0-a*x0-r*b;
3773     return -c;
3774 }
3775
3776 //______________________________________________________________________
3777 void AliITSv11GeometrySPD::PrintAscii(ostream *os) const
3778 {
3779     //
3780     // Print out class data values in Ascii Form to output stream
3781     // Inputs:
3782     //   ostream *os   Output stream where Ascii data is to be writen
3783     // Outputs:
3784     //   none.
3785     // Return:
3786     //   none.
3787     //
3788     Int_t i,j,k;
3789 #if defined __GNUC__
3790 #if __GNUC__ > 2
3791     ios::fmtflags fmt = cout.flags();
3792 #else
3793     Int_t fmt;
3794 #endif
3795 #else
3796 #if defined __ICC || defined __ECC || defined __xlC__
3797     ios::fmtflags fmt;
3798 #else
3799     Int_t fmt;
3800 #endif
3801 #endif
3802
3803     *os<< fgkGapLadder <<" "<< fgkGapHalfStave<<" "<< 6 <<" ";
3804     for(i=0;i<6;i++) *os<< fAddStave[i] <<" "<<fSPDsectorX0.GetSize();
3805     for(i=0;i<fSPDsectorX0.GetSize();i++) *os<< fSPDsectorX0.GetAt(i) << " ";
3806     for(i=0;i<fSPDsectorX0.GetSize();i++) *os<< fSPDsectorY0.GetAt(i) << " ";
3807     for(i=0;i<fSPDsectorX1.GetSize();i++) *os<< fSPDsectorX1.GetAt(i) << " ";
3808     for(i=0;i<fSPDsectorX1.GetSize();i++) *os<< fSPDsectorY1.GetAt(i) << " ";
3809     *os<<10<<" "<< 2 <<" " << 6 << " "<< 3 <<" ";
3810     for(k=0;k<10;k++)for(i=0;i<6;i++)for(j=0;j<3;j++)
3811         *os<<fTubeEndSector[k][0][i][j]<<" ";
3812     for(k=0;k<10;k++)for(i=0;i<6;i++)for(j=0;j<3;j++)
3813         *os<<fTubeEndSector[k][1][i][j]<<" ";
3814     os->flags(fmt); // reset back to old Formating.
3815     return;
3816 }
3817 //
3818 //______________________________________________________________________
3819 void AliITSv11GeometrySPD::ReadAscii(istream* is)
3820 {
3821     //
3822     // Read in class data values in Ascii Form to output stream
3823     // Inputs:
3824     //   istream *is   Input stream where Ascii data is to be read in from
3825     // Outputs:
3826     //   none.
3827     // Return:
3828     //   none.
3829     //
3830     Int_t i,j,k,n;
3831     Double_t gapLadder,gapHalfStave;
3832     const Int_t kLimits = 100;
3833     *is>>gapLadder>>gapHalfStave>>n;
3834     if(n!=6){
3835       AliError(Form("fAddStave Array !=6 n=%d",n));
3836         return;
3837     } // end if
3838     for(i=0;i<n;i++) *is>>fAddStave[i];
3839     *is>>n;
3840     if(n<0 || n> kLimits){
3841       AliError("Anomalous value for parameter n");
3842       return;
3843     } 
3844     fSPDsectorX0.Set(n);
3845     fSPDsectorY0.Set(n);
3846     fSPDsectorX1.Set(n);
3847     fSPDsectorY1.Set(n);
3848     for(i=0;i<n;i++) *is>>fSPDsectorX0[i];
3849     for(i=0;i<n;i++) *is>>fSPDsectorY0[i];
3850     for(i=0;i<n;i++) *is>>fSPDsectorX1[i];
3851     for(i=0;i<n;i++) *is>>fSPDsectorY1[i];
3852     *is>> i>>j>>n;
3853     if(i!=2||j!=6||n!=3){
3854         Warning("ReadAscii","fTubeEndSector array wrong size [2][6][3],"
3855                 "found [%d][%d][%d]",i,j,n);
3856         return;
3857     } // end if
3858     for(k=0;k<10;k++)for(i=0;i<6;i++)for(j=0;j<3;j++)
3859         *is>>fTubeEndSector[k][0][i][j];
3860     for(k=0;k<10;k++)for(i=0;i<6;i++)for(j=0;j<3;j++)
3861         *is>>fTubeEndSector[k][1][i][j];
3862     return;
3863 }
3864 //
3865 //______________________________________________________________________
3866 ostream &operator<<(ostream &os,const AliITSv11GeometrySPD &s)
3867 {
3868     //
3869     // Standard output streaming function
3870     // Inputs:
3871     //   ostream            &os  output steam
3872     //   AliITSvPPRasymmFMD &s class to be streamed.
3873     // Output:
3874     //   none.
3875     // Return:
3876     //   ostream &os  The stream pointer
3877     //
3878     s.PrintAscii(&os);
3879     return os;
3880 }
3881 //
3882 //______________________________________________________________________
3883 istream &operator>>(istream &is,AliITSv11GeometrySPD &s)
3884 {
3885     //
3886     // Standard inputput streaming function
3887     // Inputs:
3888     //   istream            &is  input steam
3889     //   AliITSvPPRasymmFMD &s class to be streamed.
3890     // Output:
3891     //   none.
3892     // Return:
3893     //   ostream &os  The stream pointer
3894     //
3895     s.ReadAscii(&is);
3896     return is;
3897 }
3898