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