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