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