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