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