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