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