]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSv11GeometrySPD.cxx
New version of SPD geometry, comlete in the barrel region
[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 ceneteral volume (except for the Ceneteral support 
18 // cylinders. Other classes define the rest of the ITS. Specificaly the ITS
19 // The SSD support cone, SSD Support central cylinder, SDD support cone,
20 // The SDD cupport central cylinder, the SPD Thermal Sheald, 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
25 /* $Id$ */
26
27 // General Root includes
28 #include <Riostream.h>
29 #include <TMath.h>
30 #include <TLatex.h>
31 #include <TCanvas.h>
32 #include <TPolyLine.h>
33 #include <TPolyMarker.h>
34
35 // Root Geometry includes
36 #include <TGeoVolume.h>
37 #include <TGeoPcon.h>
38 #include <TGeoCone.h>
39 #include <TGeoTube.h> // contains TGeoTubeSeg
40 #include <TGeoArb8.h>
41 #include <TGeoEltu.h>
42 #include <TGeoXtru.h>
43 #include <TGeoMatrix.h>
44 #include <TGeoMaterial.h>
45 #include <TGeoMedium.h>
46 #include <TGeoCompositeShape.h>
47
48 // AliRoot includes
49 #include "AliLog.h"
50 #include "AliMagF.h"
51 #include "AliRun.h"
52
53 // Declaration file
54 #include "AliITSv11GeometrySPD.h"
55
56 ClassImp(AliITSv11GeometrySPD)
57
58 //#define SQ(A) (A)*(A)
59
60 AliITSv11GeometrySPD::AliITSv11GeometrySPD(Double_t gap) :
61         AliITSv11Geometry(), fAlignmentGap(gap),
62         fSPDsectorX0(0), fSPDsectorY0(0), fSPDsectorX1(0), fSPDsectorY1(0)
63 {
64         //
65         // Default constructor.
66         // This does not initialize anything and is provided just for completeness.
67         // It is recommended to use the other one.
68         // The alignment gap is specified as argument (default = 0.0075 cm).
69         //
70         
71         Int_t i = 0;
72         for (i = 0; i < 6; i++) fAddStave[i] = kTRUE;
73 }
74 //
75 //__________________________________________________________________________________________
76 AliITSv11GeometrySPD::AliITSv11GeometrySPD(Int_t debug, Double_t gap):
77         AliITSv11Geometry(debug), fAlignmentGap(gap),
78         fSPDsectorX0(0), fSPDsectorY0(0), fSPDsectorX1(0), fSPDsectorY1(0)
79 {
80         //
81         // Constructor with debug setting argument
82         // This is the constructor which is recommended to be used.
83         // It sets a debug level, and initializes the name of the object.
84         // The alignment gap is specified as argument (default = 0.0075 cm).
85         //
86         
87         Int_t i = 0;
88         for (i = 0; i < 6; i++) fAddStave[i] = kTRUE;
89 }
90 //
91 //__________________________________________________________________________________________
92 TGeoMedium* AliITSv11GeometrySPD::GetMedium(const char* mediumName, TGeoManager *mgr) const
93 {
94         //
95         // This function is used to recovery any medium 
96         // used to build the geometry volumes. 
97         // If the required medium does not exists, 
98         // a NULL pointer is returned, and an error message is written.
99         //
100         
101         Char_t itsMediumName[30];
102         sprintf(itsMediumName, "ITS_%s", mediumName);
103         TGeoMedium* medium = mgr->GetMedium(itsMediumName);
104         if (!medium) AliError(Form("Medium <%s> not found", mediumName));
105         
106         return medium;
107 }
108 //
109 //__________________________________________________________________________________________
110 Int_t AliITSv11GeometrySPD::CreateSPDCentralMaterials(Int_t &medOffset, Int_t &matOffset) const
111 {
112         //
113         // Define the specific materials used for the ITS SPD central detectors.
114         // ---
115         // NOTE: These are the same old names. 
116         //       By the ALICE naming conventions, they start with "ITS SPD ...."
117         //       Data taken from ** AliITSvPPRasymmFMD::CreateMaterials() **.
118         // ---
119         // Arguments [the ones passed by reference contain output values]:
120         // - medOffset --> (by ref) starting number of the list of media
121         // - matOffset --> (by ref) starting number of the list of Materials
122         // ---
123         // Return value:
124         // - the last material index used + 1 (= next avaiable material index)
125         // ---
126         // Begin_Html
127         /*
128                 <img    src="http://alice.pd.infn.it/latestdr/Geometric-Revision/assembly.ps"
129                 title="SPD      Sector  drawing with    all     cross   sections        defined">
130                 <p>The  SPD     Sector  definition.     In      
131                 <a      href="http://alice.pd.infn.it/latestdr/Geometric-Revision/assembly.hpgl">HPGL</a>       format.
132                 <img    src="http://alice.pd.infn.it/latestdr/Geometric-Revision/assembly-10-modules.ps"
133                 titile="SPD     All     Sectors end     view    with    thermal sheald">
134                 <p>The  SPD     all     sector  end     view    with    thermal sheald.
135                 <img    src="http://alice.pd.infn.it/latestdr/Geometric-Revision/assembly.ps"
136                 title="SPD      side    view    cross   section">
137                 <p>SPD  side    view    cross   section with    condes  and     thermal shealds.
138                 <img    src="http://alice.pd.infn.it/latestdr/Geometric-Revision/SECTION-A_A.jpg"
139                 title="Cross    section A-A"><p>Cross   section A-A.
140                 <img    src="http://alice.pd.infn.it/latestdr/Geometric-Revision/SECTION-B_B.jpg"
141                 title="Cross    section B-B"><p>Cross   section B-B.
142                 <img    src="http://alice.pd.infn.it/latestdr/Geometric-Revision/SECTION-C_C.jpg"
143                 title-"Cross    section C-C"><p>Cross   section C-C.
144                 <img    src="http://alice.pd.infn.it/latestdr/Geometric-Revision/SECTION-D_D.jpg"
145                 title="Cross    section D-D"><p>Cross   section D-D.
146                 <img    src="http://alice.pd.infn.it/latestdr/Geometric-Revision/SECTION-E_E.jpg"
147                 title="Cross    section E-E"><p>Cross   section E-E.
148                 <img    src="http://alice.pd.infn.it/latestdr/Geometric-Revision/SECTION-F_F.jpg"
149                 title="Cross    section F-F"><p>Cross   section F-F.
150                 <img    src="http://alice.pd.infn.it/latestdr/Geometric-Revision/SECTION-G_G.jpg"
151                 title="Cross    section G-G"><p>Cross   section G-G.
152         */
153         // End_Html
154         //
155         const Double_t ktmaxfd    = 0.1 * fgkDegree; // Degree
156         const Double_t kstemax    = 1.0 * fgkcm; // cm
157         const Double_t kdeemax    = 0.1;//Fraction of particle's energy 0<deemax<=1
158         const Double_t kepsil     = 1.0E-4; //
159         const Double_t kstmin     = 0.0 * fgkcm; // cm "Default value used"
160         const Double_t ktmaxfdAir = 0.1 * fgkDegree; // Degree
161         const Double_t kstemaxAir = 1.0000E+00 * fgkcm; // cm
162         const Double_t kdeemaxAir = 0.1; // Fraction of particle's energy 0<deemax<=1
163         const Double_t kepsilAir  = 1.0E-4;//
164         const Double_t kstminAir  = 0.0 * fgkcm; // cm "Default value used"
165         const Double_t ktmaxfdSi  = 0.1 * fgkDegree; // .10000E+01; // Degree
166         const Double_t kstemaxSi  = 0.0075 * fgkcm; //  .10000E+01; // cm
167         const Double_t kdeemaxSi  = 0.1; // Fraction of particle's energy 0<deemax<=1
168         const Double_t kepsilSi   = 1.0E-4;//
169         const Double_t kstminSi   = 0.0 * fgkcm; // cm "Default value used"
170         
171         Int_t matindex = matOffset;
172         Int_t medindex = medOffset;
173         TGeoMaterial *mat;
174         TGeoMixture  *mix;
175         TGeoMedium   *med;
176         
177         Int_t    ifield = (gAlice->Field()->Integ());
178         Double_t fieldm = (gAlice->Field()->Max());
179         Double_t params[8] = {8 * 0.0};
180         params[1] = (Double_t) ifield;
181         params[2] = fieldm;
182         params[3] = ktmaxfdSi;
183         params[4] = kstemaxSi;
184         params[5] = kdeemaxSi;
185         params[6] = kepsilSi;
186         params[7] = kstminSi;
187         
188         //
189         // Definition of materials and mediums.
190         // Last argument in material definition is its pressure,
191         // which is initialized to ZERO.
192         // For better readability, it is simply set to zero.
193         // Then the writing "0.0 * fgkPascal" is replaced by "0."
194         // (Alberto)
195         //
196         
197         // silicon definition for ITS (overall)
198         mat = new TGeoMaterial("ITS_SI", 28.086, 14.0, 2.33 * fgkgcm3,
199                                TGeoMaterial::kMatStateSolid, 25.0 * fgkCelsius, 0.);
200         mat->SetIndex(matindex);
201         med = new TGeoMedium("SI", medindex++, mat, params);
202         
203         // silicon for ladder chips
204         mat = new TGeoMaterial("SPD SI CHIP", 28.086, 14.0, 2.33 * fgkgcm3,
205                                TGeoMaterial::kMatStateSolid, 25.0 * fgkCelsius, 0.);
206         mat->SetIndex(matindex);
207         med = new TGeoMedium("SPD SI CHIP", medindex++, mat, params);
208         
209         // silicon for pixel bus
210         mat = new TGeoMaterial("SPD SI BUS", 28.086, 14.0, 2.33 * fgkgcm3,
211                                TGeoMaterial::kMatStateSolid, 25.0 * fgkCelsius, 0.);
212         mat->SetIndex(matindex);
213         med = new TGeoMedium("SPD SI BUS", medindex++, mat, params);
214         
215         // carbon fiber material is defined as a mix of C-O-N-H
216         // defined in terms of fractional weights according to 'C (M55J)'
217         // it is used for the support and clips
218         mix = new TGeoMixture("C (M55J)", 4, 1.9866 * fgkgcm3);
219         mix->SetIndex(matindex);
220         mix->DefineElement(0, 12.01070, 6.0, 0.908508078); // C by fractional weight
221         mix->DefineElement(1, 14.00670, 7.0, 0.010387573); // N by fractional weight
222         mix->DefineElement(2, 15.99940, 8.0, 0.055957585); // O by fractional weight
223         mix->DefineElement(3,  1.00794, 1.0, 0.025146765); // H by fractional weight
224         mix->SetPressure(0.0 * fgkPascal);
225         mix->SetTemperature(25.0 * fgkCelsius);
226         mix->SetState(TGeoMaterial::kMatStateSolid);
227         params[3] = ktmaxfd;
228         params[4] = kstemax;
229         params[5] = kdeemax;
230         params[6] = kepsil;
231         params[7] = kstmin;
232         med = new TGeoMedium("ITSspdCarbonFiber", medindex++, mix, params);
233         
234         // air defined as a mixture of C-N-O-Ar: 
235         // it is used to fill all containers
236         mix = new TGeoMixture("Air", 4, 1.20479E-3 * fgkgcm3);
237         mix->SetIndex(matindex);
238         mix->DefineElement(0, 12.0107,  6.0, 0.000124); // C by fractional weight
239         mix->DefineElement(1, 14.0067,  7.0, 0.755267); // N by fractional weight
240         mix->DefineElement(2, 15.9994,  8.0, 0.231781); // O by fractional weight
241         mix->DefineElement(3, 39.9480, 18.0, 0.012827); // Ar by fractional weight
242         mix->SetPressure(101325.0 * fgkPascal); // = 1 atmosphere
243         mix->SetTemperature(25.0 * fgkCelsius);
244         mix->SetState(TGeoMaterial::kMatStateGas);
245         params[3] = ktmaxfdAir;
246         params[4] = kstemaxAir;
247         params[5] = kdeemaxAir;
248         params[6] = kepsilAir;
249         params[7] = kstminAir;
250         med = new TGeoMedium("ITSspdAir", medindex++, mix, params);
251         
252         // inox stainless steel, defined as a mixture
253         // used for all metallic parts
254         mix = new TGeoMixture("INOX", 9, 8.03 * fgkgcm3);
255         mix->SetIndex(matindex);
256         mix->DefineElement(0, 12.0107,  6., .0003);  // C  by fractional weight
257         mix->DefineElement(1, 54.9380, 25., .02);    // Fe by fractional weight
258         mix->DefineElement(2, 28.0855, 14., .01);    // Na by fractional weight
259         mix->DefineElement(3, 30.9738, 15., .00045); // P  by fractional weight
260         mix->DefineElement(4, 32.066 , 16., .0003);  // S  by fractional weight
261         mix->DefineElement(5, 58.6928, 28., .12);    // Ni by fractional weight
262         mix->DefineElement(6, 55.9961, 24., .17);    //    by fractional weight
263         mix->DefineElement(7, 95.84  , 42., .025);   //    by fractional weight
264         mix->DefineElement(8, 55.845 , 26., .654);   //    by fractional weight
265         mix->SetPressure(0.0 * fgkPascal);
266         mix->SetTemperature(25.0 * fgkCelsius);
267         mix->SetState(TGeoMaterial::kMatStateSolid);
268         params[3] = ktmaxfdAir;
269         params[4] = kstemaxAir;
270         params[5] = kdeemaxAir;
271         params[6] = kepsilAir;
272         params[7] = kstminAir;
273         med = new TGeoMedium("ITSspdStainlessSteel", medindex++, mix, params);
274         
275         // freon gas which fills the cooling system (C+F)
276         mix = new TGeoMixture("Freon", 2, 1.63 * fgkgcm3);
277         mix->SetIndex(matindex);
278         mix->DefineElement(0, 12.0107   , 6.0,  4);  // C by fractional weight
279         mix->DefineElement(1, 18.9984032, 9.0, 10); // F by fractional weight
280         mix->SetPressure(101325.0 * fgkPascal); // = 1 atmosphere
281         mix->SetTemperature(25.0 * fgkCelsius);
282         mix->SetState(TGeoMaterial::kMatStateLiquid);
283         params[3] = ktmaxfdAir;
284         params[4] = kstemaxAir;
285         params[5] = kdeemaxAir;
286         params[6] = kepsilAir;
287         params[7] = kstminAir;
288         med = new TGeoMedium("ITSspdCoolingFluid", medindex++, mix, params);
289         
290         // return the next index to be used in case of adding new materials
291         medOffset = medindex;
292         matOffset = matindex;
293         return matOffset;
294 }
295 //
296 //__________________________________________________________________________________________
297 void AliITSv11GeometrySPD::InitSPDCentral(Int_t offset, TVirtualMC *vmc) const
298 {
299         //
300         // Do all SPD Central detector initializations (e.g.: transport cuts).
301         // ---
302         // Here follow some GEANT3 physics switches, which are interesting 
303         // for these settings to be defined:
304         // - "MULTS" (MULtiple Scattering):
305         //   the variable IMULS controls this process. See [PHYS320/325/328]
306         //   0 - No multiple scattering.
307         //   1 - (DEFAULT) Multiple scattering according to Moliere theory.
308         //   2 - Same as 1. Kept for backward compatibility.
309         //   3 - Pure Gaussian scattering according to the Rossi formula.
310         // - "DRAY" (Delta RAY production)
311         //   The variable IDRAY controls this process. See [PHYS430]
312         //   0 - No delta rays production.
313         //   1 - (DEFAULT) Delta rays production with generation of.
314         //   2 - Delta rays production without generation of.
315         // - "LOSS" (continuous energy loss)
316         //   The variable ILOSS controls this process.
317         //   0 - No continuous energy loss, IDRAY is set to 0.
318         //   1 - Continuous energy loss with generation of delta rays above 
319         //       DCUTE (common/GCUTS/) and restricted Landau fluctuations below DCUTE.
320         //   2 - (DEFAULT) Continuous energy loss without generation of delta rays 
321         //       and full Landau-Vavilov-Gauss fluctuations.
322         //       In this case the variable IDRAY is forced to 0 to avoid
323         //       double counting of fluctuations.
324         //   3 - Same as 1, kept for backward compatibility.
325         //   4 - Energy loss without fluctuation.
326         //       The value obtained from the tables is used directly.
327         // ---
328         // Arguments:
329         //    Int_t offset    --> the material/medium index offset
330         //    TVirtualMC *vmc --> pointer to the virtual Monte Carlo default gMC
331         //
332
333         Int_t i, n = 4;
334         
335         for(i=0;i<n;i++) {
336                 vmc->Gstpar(i+offset, "CUTGAM", 30.0 * fgkKeV);
337                 vmc->Gstpar(i+offset, "CUTELE", 30.0 * fgkKeV);
338                 vmc->Gstpar(i+offset, "CUTNEU", 30.0 * fgkKeV);
339                 vmc->Gstpar(i+offset, "CUTHAD", 30.0 * fgkKeV);
340                 vmc->Gstpar(i+offset, "CUTMUO", 30.0 * fgkKeV);
341                 vmc->Gstpar(i+offset, "BCUTE",  30.0 * fgkKeV);
342                 vmc->Gstpar(i+offset, "BCUTM",  30.0 * fgkKeV);
343                 vmc->Gstpar(i+offset, "DCUTE",  30.0 * fgkKeV);
344                 vmc->Gstpar(i+offset, "DCUTM",  30.0 * fgkKeV);
345                 //vmc->Gstpar(i+offset, "PPCUTM", );
346                 //vmc->Gstpar(i+offset, "PAIR", );
347                 //vmc->Gstpar(i+offset, "COMPT", );
348                 //vmc->Gstpar(i+offset, "PHOT", );
349                 //vmc->Gstpar(i+offset, "PFIS", );
350                 vmc->Gstpar(i+offset, "DRAY", 1);
351                 //vmc->Gstpar(i+offset, "ANNI", );
352                 //vmc->Gstpar(i+offset, "BREM", );
353                 //vmc->Gstpar(i+offset, "HADR", );
354                 //vmc->Gstpar(i+offset, "MUNU", );
355                 //vmc->Gstpar(i+offset, "DCAY", );
356                 vmc->Gstpar(i+offset, "LOSS", 1);
357                 //vmc->Gstpar(i+offset, "MULS", );
358                 //vmc->Gstpar(i+offset, "GHCOR1", );
359                 //vmc->Gstpar(i+offset, "BIRK1", );
360                 //vmc->Gstpar(i+offset, "BRIK2", );
361                 //vmc->Gstpar(i+offset, "BRIK3", );
362                 //vmc->Gstpar(i+offset, "LABS", );
363                 //vmc->Gstpar(i+offset, "SYNC", );
364                 //vmc->Gstpar(i+offset, "STRA", );
365         }
366 }
367 //
368 //__________________________________________________________________________________________
369 void AliITSv11GeometrySPD::SPDSector(TGeoVolume *moth, TGeoManager *mgr)
370 {
371         //
372         // Creates a single SPD carbon fiber sector and places it 
373         // in a container volume passed as first argument ('moth').
374         // Second argument points to the TGeoManager which coordinates
375         // the overall volume creation.
376         // The position of the sector is based on distance of 
377         // closest point of SPD stave to beam pipe 
378         // (figures all-sections-modules.ps) of 7.22mm at section A-A.
379         //
380
381         const Double_t kSPDclossesStaveAA       =   7.22 * fgkmm;
382         const Double_t kSectorStartingAngle = -72.0 * fgkDegree;
383         const Double_t kNSectorsTotal       =  10.0;
384         const Double_t kSectorRelativeAngle = 360.0 / kNSectorsTotal * fgkDegree;
385         const Double_t kBeamPipeRadius     =   0.5 * 60.0 * fgkmm;
386         
387         Int_t i;
388         Double_t angle, radiusSector, xAAtubeCenter0, yAAtubeCenter0;
389         Double_t staveThicknessAA = 1.03 * fgkmm; // get from stave geometry.
390         TGeoCombiTrans *secRot = new TGeoCombiTrans();
391         TGeoVolume *vCarbonFiberSector;
392         TGeoMedium *medSPDcf;
393         
394         // define an assembly and fill it with the support of 
395         // a single carbon fiber sector and staves in it
396         medSPDcf = GetMedium("SPD C (M55J)$", mgr);
397         vCarbonFiberSector = new TGeoVolumeAssembly("ITSSPDCarbonFiberSectorV");
398         vCarbonFiberSector->SetMedium(medSPDcf);
399         CarbonFiberSector(vCarbonFiberSector, xAAtubeCenter0, yAAtubeCenter0, mgr);
400         vCarbonFiberSector->SetVisibility(kTRUE); // logical volume
401         
402         // Compute the radial shift out of the sectors
403         radiusSector  = kBeamPipeRadius + kSPDclossesStaveAA + staveThicknessAA;
404         radiusSector *= radiusSector; // squaring;
405         radiusSector -= xAAtubeCenter0 * xAAtubeCenter0;
406         radiusSector  = -yAAtubeCenter0 + TMath::Sqrt(radiusSector);
407         
408         // add 10 single sectors, by replicating the virtual sector defined above
409         // and placing at different angles
410         Double_t shiftX, shiftY;
411         angle = kSectorStartingAngle;
412         secRot->RotateZ(angle);
413         for(i = 0; i < (Int_t)kNSectorsTotal; i++) {
414                 shiftX = -radiusSector * TMath::Sin(angle/fgkRadian);
415                 shiftY =  radiusSector * TMath::Cos(angle/fgkRadian);
416                 secRot->SetDx(shiftX);
417                 secRot->SetDy(shiftY);
418                 moth->AddNode(vCarbonFiberSector, i+1, new TGeoCombiTrans(*secRot));
419                 if(GetDebug(5)) {
420                         AliInfo(Form("i=%d angle=%g angle[rad]=%g radiusSector=%g x=%g y=%g \n",
421                                 i, angle, angle/fgkRadian, radiusSector, shiftX, shiftY));
422                 }
423                 angle += kSectorRelativeAngle;
424                 secRot->RotateZ(kSectorRelativeAngle);
425         }
426         if(GetDebug(3)) moth->PrintNodes();
427
428         delete secRot;
429 }
430 //
431 //__________________________________________________________________________________________
432 void AliITSv11GeometrySPD::CarbonFiberSector
433 (TGeoVolume *moth, Double_t &xAAtubeCenter0, Double_t &yAAtubeCenter0, TGeoManager *mgr)
434 {
435         //
436         // Define the detail SPD Carbon fiber support Sector geometry.
437         // Based on the drawings:
438         // - ALICE-Pixel "Costruzione Profilo Modulo" (march 25 2004)
439         // - ALICE-SUPPORTO "Costruzione Profilo Modulo"
440         // ---
441         // Define outside radii as negative, where "outside" means that the
442         // center of the arc is outside of the object (feb 16 2004).
443         // ---
444         // Arguments [the one passed by ref contain output values]:
445         //   TGeoVolume *moth            --> the voulme which will contain this object
446         //   Double_t   &xAAtubeCenter0  --> (by ref) x location of the outer surface
447         //                                   of the cooling tube center for tube 0.
448         //   Double_t   &yAAtubeCenter0  --> (by ref) y location of the outer surface
449         //                                   of the cooling tube center for tube 0.
450         //   TGeoManager *mgr            --> TGeo builder
451         // ---
452         // Int the two variables passed by reference values will be stored
453         // which will then be used to correctly locate this sector.
454         // The information used for this is the distance between the
455         // center of the #0 detector and the beam pipe.
456         // Measurements are taken at cross section A-A.
457         //
458         
459         //TGeoMedium *medSPDfs      = 0; // SPD support cone inserto stesalite 4411w.
460         //TGeoMedium *medSPDfo      = 0; // SPD support cone foam, Rohacell 50A.
461         //TGeoMedium *medSPDal      = 0; // SPD support cone SDD mounting bracket Al
462         TGeoMedium *medSPDcf     = GetMedium("SPD C (M55J)$", mgr);
463         TGeoMedium *medSPDss     = GetMedium("INOX$", mgr);
464         TGeoMedium *medSPDair    = GetMedium("AIR$", mgr);
465         TGeoMedium *medSPDcoolfl = GetMedium("Freon$", mgr); //ITSspdCoolingFluid
466         
467         const Double_t ksecDz             =  0.5 * 500.0 * fgkmm;
468         const Double_t ksecLen       = 30.0 * fgkmm;
469         const Double_t ksecCthick         =  0.2 * fgkmm;
470         const Double_t ksecDipLength =  3.2 * fgkmm;
471         const Double_t ksecDipRadii  =  0.4 * fgkmm;
472         //const Double_t ksecCoolingTubeExtraDepth = 0.86 * fgkmm;
473
474         // The following positions ('ksecX#' and 'ksecY#') and radii ('ksecR#')
475         // are the centers and radii of curvature of all the rounded corners
476         // between the straight borders of the SPD sector shape.
477         // To draw this SPD sector, the following steps are followed:
478         // 1) the (ksecX, ksecY) points are plotted
479         //    and circles of the specified radii are drawn around them.
480         // 2) each pair of consecutive circles is connected by a line
481         //    tangent to them, in accordance with the radii being "internal" or "external"
482         //    with respect to the closed shape which describes the sector itself.
483         // The resulting connected shape is the section 
484         // of the SPD sector surface in the transverse plane (XY).
485         
486         const Double_t ksecX0   = -10.725 * fgkmm;
487         const Double_t ksecY0   = -14.853 * fgkmm;
488         const Double_t ksecR0   =  -0.8   * fgkmm; // external
489         const Double_t ksecX1   = -13.187 * fgkmm;
490         const Double_t ksecY1   = -19.964 * fgkmm;
491         const Double_t ksecR1   =  +0.6   * fgkmm; // internal
492         // const Double_t ksecDip0 = 5.9 * fgkmm;
493         
494         const Double_t ksecX2   =  -3.883 * fgkmm;
495         const Double_t ksecY2   = -17.805 * fgkmm;
496         const Double_t ksecR2   =  +0.80  * fgkmm; // internal (guess)
497         const Double_t ksecX3   =  -3.123 * fgkmm;
498         const Double_t ksecY3   = -14.618 * fgkmm;
499         const Double_t ksecR3   =  -0.6   * fgkmm; // external
500         //const Double_t ksecDip1 = 8.035 * fgkmm;
501         
502         const Double_t ksecX4   = +11.280 * fgkmm;
503         const Double_t ksecY4   = -14.473 * fgkmm;
504         const Double_t ksecR4   =  +0.8   * fgkmm; // internal
505         const Double_t ksecX5   = +19.544 * fgkmm;
506         const Double_t ksecY5   = +10.961 * fgkmm;
507         const Double_t ksecR5   =  +0.8   * fgkmm; // internal
508         //const Double_t ksecDip2 = 4.553 * fgkmm;
509         
510         const Double_t ksecX6   = +10.830 * fgkmm;
511         const Double_t ksecY6   = +16.858 * fgkmm;
512         const Double_t ksecR6   =  +0.6   * fgkmm; // internal
513         const Double_t ksecX7   = +11.581 * fgkmm;
514         const Double_t ksecY7   = +13.317 * fgkmm;
515         const Double_t ksecR7   =  -0.6   * fgkmm; // external
516         //const Double_t ksecDip3 = 6.978 * fgkmm;
517         
518         const Double_t ksecX8   =  -0.733 * fgkmm;
519         const Double_t ksecY8   = +17.486 * fgkmm;
520         const Double_t ksecR8   =  +0.6   * fgkmm; // internal
521         const Double_t ksecX9   =  +0.562 * fgkmm;
522         //const Double_t ksecY9 = +14.486 * fgkmm; // correction by
523         const Double_t ksecY9   = +14.107 * fgkmm; // Alberto
524         const Double_t ksecR9   =  -0.6   * fgkmm; // external
525         //const Double_t ksecDip4 = 6.978 * fgkmm;
526
527         const Double_t ksecX10  = -12.252 * fgkmm;
528         const Double_t ksecY10  = +16.298 * fgkmm;
529         const Double_t ksecR10  =  +0.6   * fgkmm; // internal
530         const Double_t ksecX11  = -10.445 * fgkmm;
531         const Double_t ksecY11  = +13.162 * fgkmm;
532         const Double_t ksecR11  =  -0.6   * fgkmm; // external
533         //const Double_t ksecDip5 = 6.978 * fgkmm;
534         
535         const Double_t ksecX12  = -22.276 * fgkmm;
536         const Double_t ksecY12  = +12.948 * fgkmm;
537         const Double_t ksecR12  =  +0.85  * fgkmm; // internal
538         const Double_t ksecR13  =  -0.8   * fgkmm; // external
539         const Double_t ksecAngleSide13 = 36.0 * fgkDegree;
540         
541         const Int_t ksecNRadii = 20;
542         const Int_t ksecNPointsPerRadii = 4;
543         const Int_t ksecNCoolingTubeDips = 6;
544         
545         // Since the rounded parts are approximated by a regular polygon
546         // and a cooling tube of the propper diameter must fit, a scaling factor
547         // increases the size of the polygon for the tube to fit.
548         //const Double_t ksecRCoolScale = 1./TMath::Cos(TMath::Pi()/(Double_t)ksecNPointsPerRadii);
549         const Double_t ksecZEndLen   = 30.000 * fgkmm;
550         //const Double_t ksecZFlangLen = 45.000 * fgkmm;
551         const Double_t ksecTl        =  0.860 * fgkmm;
552         const Double_t ksecCthick2   =  0.600 * fgkmm;
553         //const Double_t ksecCthick3  =  1.80  * fgkmm;
554         //const Double_t ksecSidelen  = 22.0   * fgkmm;
555         //const Double_t ksecSideD5   =  3.679 * fgkmm;
556         //const Double_t ksecSideD12  =  7.066 * fgkmm;
557         const Double_t ksecRCoolOut  = 2.400 * fgkmm;
558         const Double_t ksecRCoolIn   = 2.000 * fgkmm;
559         const Double_t ksecDl1       = 5.900 * fgkmm;
560         const Double_t ksecDl2       = 8.035 * fgkmm;
561         const Double_t ksecDl3       = 4.553 * fgkmm;
562         const Double_t ksecDl4       = 6.978 * fgkmm;
563         const Double_t ksecDl5       = 6.978 * fgkmm;
564         const Double_t ksecDl6       = 6.978 * fgkmm;
565         const Double_t ksecCoolTubeThick  = 0.04  * fgkmm;
566         const Double_t ksecCoolTubeROuter = 2.6   * fgkmm;
567         const Double_t ksecCoolTubeFlatX  = 3.696 * fgkmm;
568         const Double_t ksecCoolTubeFlatY  = 0.68  * fgkmm;
569         //const Double_t ksecBeamX0 = 0.0 * fgkmm; // guess
570         //const Double_t ksecBeamY0 = (15.223 + 40.) * fgkmm; // guess
571
572         // redefine some of the points already defined above
573         // in the format of arrays (???)
574         const Int_t ksecNPoints = (ksecNPointsPerRadii + 1) * ksecNRadii + 8;
575         Double_t secX[ksecNRadii] = {
576                 ksecX0,  ksecX1,  -1000.0,
577                 ksecX2,  ksecX3,  -1000.0,
578                 ksecX4,  ksecX5,  -1000.0,
579                 ksecX6,  ksecX7,  -1000.0,
580                 ksecX8,  ksecX9,  -1000.0,
581                 ksecX10, ksecX11, -1000.0,
582                 ksecX12, -1000.0
583         };
584         Double_t secY[ksecNRadii] = {
585                 ksecY0,  ksecY1,  -1000.0,
586                 ksecY2,  ksecY3,  -1000.0,
587                 ksecY4,  ksecY5,  -1000.0,
588                 ksecY6,  ksecY7,  -1000.0,
589                 ksecY8,  ksecY9,  -1000.0,
590                 ksecY10, ksecY11, -1000.0,
591                 ksecY12, -1000.0
592         };
593         Double_t secR[ksecNRadii] = { 
594                 ksecR0,  ksecR1,  -.5 * ksecDipLength - ksecDipRadii,
595                 ksecR2,  ksecR3,  -.5 * ksecDipLength - ksecDipRadii,
596                 ksecR4,  ksecR5,  -.5 * ksecDipLength - ksecDipRadii,
597                 ksecR6,  ksecR7,  -.5 * ksecDipLength - ksecDipRadii,
598                 ksecR8,  ksecR9,  -.5 * ksecDipLength - ksecDipRadii,
599                 ksecR10, ksecR11, -.5 * ksecDipLength - ksecDipRadii,
600                 ksecR12, ksecR13
601         };
602         /*
603         Double_t secDip[ksecNRadii] = {
604                 0., 0., ksecDip0, 0., 0., ksecDip1,
605                 0., 0., ksecDip2, 0., 0., ksecDip3,
606                 0., 0., ksecDip4, 0., 0., ksecDip5,
607                 0., 0.
608         };
609         */
610         Double_t secX2[ksecNRadii];
611         Double_t secY2[ksecNRadii];
612         Double_t secR2[ksecNRadii] = {
613                 ksecR0,  ksecR1,  ksecRCoolOut,
614                 ksecR2,  ksecR3,  ksecRCoolOut,
615                 ksecR4,  ksecR5,  ksecRCoolOut,
616                 ksecR6,  ksecR7,  ksecRCoolOut,
617                 ksecR8,  ksecR9,  ksecRCoolOut,
618                 ksecR10, ksecR11, ksecRCoolOut,
619                 ksecR12, ksecR13
620         };
621         Double_t secDip2[ksecNCoolingTubeDips] = { 
622                 ksecDl1, ksecDl2, ksecDl3, 
623                 ksecDl4, ksecDl5, ksecDl6 
624         };
625         Double_t secX3[ksecNRadii];
626         Double_t secY3[ksecNRadii];
627         const Int_t ksecDipIndex[ksecNCoolingTubeDips] = {2, 5, 8, 11, 14, 17};
628         Double_t secAngleStart[ksecNRadii];
629         Double_t secAngleEnd[ksecNRadii];
630         Double_t secAngleStart2[ksecNRadii];
631         Double_t secAngleEnd2[ksecNRadii];
632         Double_t secAngleTurbo[ksecNCoolingTubeDips] = {0., 0., 0., 0., 0., 0.0};
633         //Double_t secAngleStart3[ksecNRadii];
634         //Double_t secAngleEnd3[ksecNRadii];
635         Double_t  xpp[ksecNPoints],  ypp[ksecNPoints];
636         Double_t  xpp2[ksecNPoints], ypp2[ksecNPoints];
637         Double_t *xp[ksecNRadii],   *xp2[ksecNRadii];
638         Double_t *yp[ksecNRadii],   *yp2[ksecNRadii];
639         TGeoXtru *sA0,  *sA1, *sB0, *sB1;
640         TGeoEltu *sTA0, *sTA1;
641         TGeoTube *sTB0, *sTB1; //,*sM0;
642         TGeoRotation     *rot;
643         TGeoTranslation *trans;
644         TGeoCombiTrans  *rotrans;
645         Double_t t, t0, t1, a, b, x0, y0, x1, y1;
646         Int_t i, j, k, m;
647         Bool_t tst;
648
649         if(!moth) {
650                 AliError("Container volume (argument) is NULL");
651                 return;
652         }
653         for(i = 0; i < ksecNRadii; i++) {
654                 xp[i]  = &(xpp[i*(ksecNPointsPerRadii+1)]);
655                 yp[i]  = &(ypp[i*(ksecNPointsPerRadii+1)]);
656                 xp2[i] = &(xpp2[i*(ksecNPointsPerRadii+1)]);
657                 yp2[i] = &(ypp2[i*(ksecNPointsPerRadii+1)]);
658                 secX2[i] = secX[i];
659                 secY2[i] = secY[i];
660                 secX3[i] = secX[i];
661                 secY3[i] = secY[i];
662         }
663         
664         // find starting and ending angles for all but cooling tube sections
665         secAngleStart[0] = 0.5 * ksecAngleSide13;
666         for(i = 0; i < ksecNRadii - 2; i++) {
667                 tst = kFALSE;
668                 for(j = 0; j < ksecNCoolingTubeDips; j++) tst = (tst || i == ksecDipIndex[j]);
669                 if (tst) continue;
670                 tst = kFALSE;
671                 for(j = 0; j < ksecNCoolingTubeDips; j++) tst = (tst || (i+1) == ksecDipIndex[j]);
672                 if (tst) j = i+2; else j = i+1;
673                 AnglesForRoundedCorners(secX[i], secY[i], secR[i], secX[j], secY[j], secR[j], t0, t1);
674                 secAngleEnd[i]   = t0;
675                 secAngleStart[j] = t1;
676                 if(secR[i] > 0.0 && secR[j] > 0.0) {
677                         if(secAngleStart[i] > secAngleEnd[i]) secAngleEnd[i] += 360.0;
678                 }
679                 secAngleStart2[i] = secAngleStart[i];
680                 secAngleEnd2[i]   = secAngleEnd[i];
681         } // end for i
682         secAngleEnd[ksecNRadii-2] = secAngleStart[ksecNRadii-2]
683                                   + (secAngleEnd[ksecNRadii-5] - secAngleStart[ksecNRadii-5]);
684         if (secAngleEnd[ksecNRadii-2] < 0.0) secAngleEnd[ksecNRadii-2] += 360.0;
685         secAngleStart[ksecNRadii-1]  = secAngleEnd[ksecNRadii-2] - 180.0;
686         secAngleEnd[ksecNRadii-1]    = secAngleStart[0];
687         secAngleStart2[ksecNRadii-2] = secAngleStart[ksecNRadii-2];
688         secAngleEnd2[ksecNRadii-2]   = secAngleEnd[ksecNRadii-2];
689         secAngleStart2[ksecNRadii-1] = secAngleStart[ksecNRadii-1];
690         secAngleEnd2[ksecNRadii-1]   = secAngleEnd[ksecNRadii-1];
691         
692         // find location of circle last rounded corner.
693         i = 0;
694         j = ksecNRadii - 2;
695         t0 = TanD(secAngleStart[i]-90.);
696         t1 = TanD(secAngleEnd[j]-90.);
697         t  = secY[i] - secY[j];
698         // NOTE: secR[i=0] < 0; secR[j=18] > 0; and secR[j+1=19] < 0
699         t += (-secR[i]+secR[j+1]) * SinD(secAngleStart[i]);
700         t -= (secR[j]-secR[j+1]) * SinD(secAngleEnd[j]);
701         t += t1 * secX[j] - t0*secX[i];
702         t += t1 * (secR[j] - secR[j+1]) * CosD(secAngleEnd[j]);
703         t -= t0 * (-secR[i]+secR[j+1]) * CosD(secAngleStart[i]);
704         secX[ksecNRadii-1] = t / (t1-t0);
705         secY[ksecNRadii-1] = TanD(90. + 0.5*ksecAngleSide13) * (secX[ksecNRadii-1] - secX[0]) + secY[0];
706         secX2[ksecNRadii-1] = secX[ksecNRadii-1];
707         secY2[ksecNRadii-1] = secY[ksecNRadii-1];
708         secX3[ksecNRadii-1] = secX[ksecNRadii-1];
709         secY3[ksecNRadii-1] = secY[ksecNRadii-1];
710         
711         // find location of cooling tube centers
712         for(i = 0; i < ksecNCoolingTubeDips; i++) {
713                 j = ksecDipIndex[i];
714                 x0 = secX[j-1] + TMath::Abs(secR[j-1]) * CosD(secAngleEnd[j-1]);
715                 y0 = secY[j-1] + TMath::Abs(secR[j-1]) * SinD(secAngleEnd[j-1]);
716                 x1 = secX[j+1] + TMath::Abs(secR[j+1]) * CosD(secAngleStart[j+1]);
717                 y1 = secY[j+1] + TMath::Abs(secR[j+1]) * SinD(secAngleStart[j+1]);
718                 t0 = TMath::Sqrt((x0-x1)*(x0-x1)+(y0-y1)*(y0-y1));
719                 t  = secDip2[i] / t0;
720                 a  = x0+(x1-x0) * t;
721                 b  = y0+(y1-y0) * t;
722                 if(i == 0) { 
723                         // get location of tube center->Surface for locating
724                         // this sector around the beam pipe.
725                         // This needs to be double checked, but I need my notes for that.
726                         // (Bjorn Nilsen)
727                         xAAtubeCenter0 = x0 + (x1 - x0) * t * 0.5;
728                         yAAtubeCenter0 = y0 + (y1 - y0) * t * 0.5;
729                 }
730                 if(a + b*(a - x0) / (b - y0) > 0.0) {
731                         secX[j]  = a + TMath::Abs(y1-y0) * 2.0 * ksecDipRadii/t0;
732                         secY[j]  = b - TMath::Sign(2.0*ksecDipRadii,y1-y0) * (x1-x0)/t0;
733                         secX2[j] = a + TMath::Abs(y1-y0) * ksecTl/t0;
734                         secY2[j] = b - TMath::Sign(ksecTl,y1-y0) * (x1-x0) / t0;
735                         secX3[j] = a + TMath::Abs(y1-y0) * (2.0*ksecDipRadii-0.5*ksecCoolTubeFlatY)/t0;
736                         secY3[j] = b - TMath::Sign(2.0*ksecDipRadii-0.5*ksecCoolTubeFlatY,y1-y0)*(x1-x0)/t0;
737                 } 
738                 else {
739                         secX[j] = a - TMath::Abs(y1-y0)*2.0*ksecDipRadii/t0;
740                         secY[j] = b + TMath::Sign(2.0*ksecDipRadii,y1-y0)*(x1-x0)/t0;
741                         secX2[j] = a - TMath::Abs(y1-y0)*ksecTl/t0;
742                         secY2[j] = b + TMath::Sign(ksecTl,y1-y0)*(x1-x0)/t0;
743                         secX3[j] = a - TMath::Abs(y1-y0)*(2.0*ksecDipRadii-0.5*ksecCoolTubeFlatY)/t0;
744                         secY3[j] = b + TMath::Sign(2.0*ksecDipRadii-0.5*ksecCoolTubeFlatY,y1-y0)*(x1-x0)/t0;
745                 }
746                 
747                 // Set up Start and End angles to correspond to start/end of dips.
748                 t1 = (secDip2[i]-TMath::Abs(secR[j])) / t0;
749                 secAngleStart[j] = TMath::RadToDeg()*TMath::ATan2(y0+(y1-y0)*t1-secY[j],x0+(x1-x0)*t1-secX[j]);
750                 if (secAngleStart[j]<0.0) secAngleStart[j] += 360.0;
751                 secAngleStart2[j] = secAngleStart[j];
752                 t1 = (secDip2[i]+TMath::Abs(secR[j]))/t0;
753                 secAngleEnd[j] = TMath::RadToDeg()*TMath::ATan2(y0+(y1-y0)*t1-secY[j],x0+(x1-x0)*t1-secX[j]);
754                 if (secAngleEnd[j]<0.0) secAngleEnd[j] += 360.0;
755                 secAngleEnd2[j] = secAngleEnd[j];
756                 if (secAngleEnd[j]>secAngleStart[j]) secAngleEnd[j] -= 360.0;
757                 secR[j] = TMath::Sqrt(secR[j]*secR[j]+4.0*ksecDipRadii*ksecDipRadii);
758         } // end for i
759         
760         // Special cases
761         secAngleStart2[8] -= 360.;
762         secAngleStart2[11] -= 360.;
763         
764         SPDsectorShape(ksecNRadii, secX, secY, secR, secAngleStart, secAngleEnd,
765                        ksecNPointsPerRadii, m, xp, yp);
766         
767         //  Fix up dips to be square.
768         for(i = 0; i < ksecNCoolingTubeDips; i++) {
769                 j = ksecDipIndex[i];
770                 t = 0.5*ksecDipLength+ksecDipRadii;
771                 t0 = TMath::RadToDeg()*TMath::ATan(2.0*ksecDipRadii/t);
772                 t1 = secAngleEnd[j] + t0;
773                 t0 = secAngleStart[j] - t0;
774                 x0 = xp[j][1] = secX[j] + t*CosD(t0);
775                 y0 = yp[j][1] = secY[j] + t*SinD(t0);
776                 x1 = xp[j][ksecNPointsPerRadii-1] = secX[j] + t*CosD(t1);
777                 y1 = yp[j][ksecNPointsPerRadii-1] = secY[j] + t*SinD(t1);
778                 t0 = 1./((Double_t)(ksecNPointsPerRadii-2));
779                 for(k = 2; k < ksecNPointsPerRadii - 1; k++) {
780                         // extra points spread them out.
781                         t = ((Double_t)(k-1)) * t0;
782                         xp[j][k] = x0+(x1-x0) * t;
783                         yp[j][k] = y0+(y1-y0) * t;
784                 } // end for k
785                 secAngleTurbo[i] = -TMath::RadToDeg() * TMath::ATan2(y1-y0, x1-x0);
786                 if(GetDebug(3)) { 
787                         AliInfo(Form("i=%d -- angle=%f -- x0,y0=(%f, %f) -- x1,y1=(%f, %f)", i, secAngleTurbo[i], x0, y0, x1, y1));
788                 }
789         } // end for i
790         sA0 = new TGeoXtru(2);
791         sA0->SetName("ITS SPD Carbon fiber support Sector A0");
792         sA0->DefinePolygon(m, xpp, ypp);
793         sA0->DefineSection(0, -ksecDz);
794         sA0->DefineSection(1,  ksecDz);
795         
796         // store the edges of each XY segment which defines
797         // one of the plane zones where staves will have to be placed
798         fSPDsectorX0.Set(ksecNCoolingTubeDips);
799         fSPDsectorY0.Set(ksecNCoolingTubeDips);
800         fSPDsectorX1.Set(ksecNCoolingTubeDips);
801         fSPDsectorY1.Set(ksecNCoolingTubeDips);
802         Int_t ixy0, ixy1;
803         for(i = 0; i < ksecNCoolingTubeDips; i++) {
804                 // Find index in xpp[] and ypp[] corresponding to where the
805                 // SPD ladders are to be attached. Order them according to
806                 // the ALICE numbering schema. Using array of indexes (+-1 for
807                 // cooling tubes. For any "bend/dip/edge, there are 
808                 // ksecNPointsPerRadii+1 points involved.
809                 if(i == 0) j = 1;
810                 else if (i == 1) j = 0;
811                 else j = i;
812                 ixy0 = (ksecDipIndex[j]-1) * (ksecNPointsPerRadii+1) + (ksecNPointsPerRadii);
813                 ixy1 = (ksecDipIndex[j]+1) * (ksecNPointsPerRadii+1);
814                 fSPDsectorX0[i] = sA0->GetX(ixy0);
815                 fSPDsectorY0[i] = sA0->GetY(ixy0);
816                 fSPDsectorX1[i] = sA0->GetX(ixy1);
817                 fSPDsectorY1[i] = sA0->GetY(ixy1);
818         }
819         
820         //printf("SectorA#%d ",0);
821         InsidePoint(xpp[m-1], ypp[m-1], xpp[0], ypp[0], xpp[1], ypp[1], ksecCthick, xpp2[0], ypp2[0]);
822         for(i = 1; i < m - 1; i++) {
823                 j = i / (ksecNPointsPerRadii+1);
824                 //printf("SectorA#%d ",i);
825                 InsidePoint(xpp[i-1], ypp[i-1], xpp[i], ypp[i], xpp[i+1], ypp[i+1], ksecCthick, xpp2[i], ypp2[i]);
826         }
827         //printf("SectorA#%d ",m);
828         InsidePoint(xpp[m-2], ypp[m-2], xpp[m-1], ypp[m-1], xpp[0], ypp[0], ksecCthick, xpp2[m-1], ypp2[m-1]);
829         // Fix center value of cooling tube dip and
830         // find location of cooling tube centers
831         for(i = 0; i < ksecNCoolingTubeDips; i++) {
832                 j = ksecDipIndex[i];
833                 x0 = xp2[j][1];
834                 y0 = yp2[j][1];
835                 x1 = xp2[j][ksecNPointsPerRadii-1];
836                 y1 = yp2[j][ksecNPointsPerRadii-1];
837                 t0 = TMath::Sqrt((x0-x1)*(x0-x1)+(y0-y1)*(y0-y1));
838                 t  = secDip2[i]/t0;
839                 for(k = 2; k < ksecNPointsPerRadii - 1; k++) {
840                         // extra points spread them out.
841                         t = ((Double_t)(k-1)) * t0;
842                         xp2[j][k] = x0+(x1-x0) * t;
843                         yp2[j][k] = y0+(y1-y0) * t;
844                 }
845         } // end for i
846         sA1 = new TGeoXtru(2);
847         sA1->SetName("ITS SPD Carbon fiber support Sector Air A1");
848         sA1->DefinePolygon(m, xpp2, ypp2);
849         sA1->DefineSection(0, -ksecDz);
850         sA1->DefineSection(1,  ksecDz);
851         
852         // Error in TGeoEltu. Semi-axis X must be < Semi-axis Y (?).
853         sTA0 = new TGeoEltu("ITS SPD Cooling Tube TA0", 0.5 * ksecCoolTubeFlatY, 0.5 * ksecCoolTubeFlatX, ksecDz);
854         sTA1 = new TGeoEltu("ITS SPD Cooling Tube coolant TA1", 
855                             sTA0->GetA() - ksecCoolTubeThick,
856                             sTA0->GetB()-ksecCoolTubeThick,ksecDz);
857         
858         SPDsectorShape(ksecNRadii, secX2, secY2, secR2, secAngleStart2, secAngleEnd2,
859                        ksecNPointsPerRadii, m, xp, yp);
860
861         sB0 = new TGeoXtru(2);
862         sB0->SetName("ITS SPD Carbon fiber support Sector End B0");
863         sB0->DefinePolygon(m, xpp, ypp);
864         sB0->DefineSection(0, ksecDz);
865         sB0->DefineSection(1, ksecDz + ksecZEndLen);
866
867         //printf("SectorB#%d ",0);
868         InsidePoint(xpp[m-1], ypp[m-1], xpp[0], ypp[0], xpp[1], ypp[1], ksecCthick2, xpp2[0], ypp2[0]);
869         for(i = 1; i < m - 1; i++) {
870                 t = ksecCthick2;
871                 for(k = 0; k < ksecNCoolingTubeDips; k++)
872                         if((i/(ksecNPointsPerRadii+1))==ksecDipIndex[k])
873                                 if(!(ksecDipIndex[k]*(ksecNPointsPerRadii+1) == i ||
874                                          ksecDipIndex[k]*(ksecNPointsPerRadii+1) + ksecNPointsPerRadii == i))
875                                         t = ksecRCoolOut-ksecRCoolIn;
876                 //printf("SectorB#%d ",i);
877                 InsidePoint(xpp[i-1], ypp[i-1], xpp[i], ypp[i], xpp[i+1], ypp[i+1], t, xpp2[i], ypp2[i]);
878         }
879         //printf("SectorB#%d ",m);
880         InsidePoint(xpp[m-2], ypp[m-2], xpp[m-1], ypp[m-1], xpp[0], ypp[0], ksecCthick2, xpp2[m-1], ypp2[m-1]);
881         sB1 = new TGeoXtru(2);
882         sB1->SetName("ITS SPD Carbon fiber support Sector Air End B1");
883         sB1->DefinePolygon(m, xpp2, ypp2);
884         sB1->DefineSection(0, ksecDz);
885         sB1->DefineSection(1, ksecDz + ksecLen);
886         sTB0 = new TGeoTube("ITS SPD Cooling Tube End TB0", 0.0,
887                             0.5 * ksecCoolTubeROuter, 0.5 * ksecLen);
888         sTB1 = new TGeoTube("ITS SPD Cooling Tube End coolant TB0", 0.0,
889                             sTB0->GetRmax() - ksecCoolTubeThick, 0.5 * ksecLen);
890         
891         if(GetDebug(3)) {
892                 if(medSPDcf) medSPDcf->Dump(); else AliInfo("medSPDcf = 0");
893                 if(medSPDss) medSPDss->Dump(); else AliInfo("medSPDss = 0");
894                 if(medSPDair) medSPDair->Dump(); else AliInfo("medSPDAir = 0");
895                 if(medSPDcoolfl) medSPDcoolfl->Dump(); else AliInfo("medSPDcoolfl = 0");
896                 sA0->InspectShape();
897                 sA1->InspectShape();
898                 sB0->InspectShape();
899                 sB1->InspectShape();
900         }
901         
902         // create the assembly of the support and place staves on it
903         TGeoVolumeAssembly *vM0 = new TGeoVolumeAssembly("ITSSPDSensitiveVirtualvolumeM0");
904         StavesInSector(vM0);
905         // create other volumes with some graphical settings
906         TGeoVolume *vA0 = new TGeoVolume("ITSSPDCarbonFiberSupportSectorA0", sA0, medSPDcf);
907         vA0->SetVisibility(kTRUE);
908         vA0->SetLineColor(4); // Blue
909         vA0->SetLineWidth(1);
910         vA0->SetFillColor(vA0->GetLineColor());
911         vA0->SetFillStyle(4010); // 10% transparent
912         TGeoVolume *vA1 = new TGeoVolume("ITSSPDCarbonFiberSupportSectorAirA1", sA1, medSPDair);
913         vA1->SetVisibility(kTRUE);
914         vA1->SetLineColor(7); // light Blue
915         vA1->SetLineWidth(1);
916         vA1->SetFillColor(vA1->GetLineColor());
917         vA1->SetFillStyle(4090); // 90% transparent
918         TGeoVolume *vTA0 = new TGeoVolume("ITSSPDCoolingTubeTA0", sTA0, medSPDss);
919         vTA0->SetVisibility(kTRUE);
920         vTA0->SetLineColor(1); // Black
921         vTA0->SetLineWidth(1);
922         vTA0->SetFillColor(vTA0->GetLineColor());
923         vTA0->SetFillStyle(4000); // 0% transparent
924         TGeoVolume *vTA1 = new TGeoVolume("ITSSPDCoolingTubeFluidTA1", sTA1, medSPDcoolfl);
925         vTA1->SetVisibility(kTRUE);
926         vTA1->SetLineColor(6); // Purple
927         vTA1->SetLineWidth(1);
928         vTA1->SetFillColor(vTA1->GetLineColor());
929         vTA1->SetFillStyle(4000); // 0% transparent
930         TGeoVolume *vB0 = new TGeoVolume("ITSSPDCarbonFiberSupportSectorEndB0", sB0, medSPDcf);
931         vB0->SetVisibility(kTRUE);
932         vB0->SetLineColor(4); // Blue
933         vB0->SetLineWidth(1);
934         vB0->SetFillColor(vB0->GetLineColor());
935         vB0->SetFillStyle(4010); // 10% transparent
936         TGeoVolume *vB1 = new TGeoVolume("ITSSPDCarbonFiberSupportSectorEndAirB1", sB1, medSPDair);
937         vB1->SetVisibility(kTRUE);
938         vB1->SetLineColor(7); // light Blue
939         vB1->SetLineWidth(1);
940         vB1->SetFillColor(vB1->GetLineColor());
941         vB1->SetFillStyle(4090); // 90% transparent
942         TGeoVolume *vTB0 = new TGeoVolume("ITSSPDCoolingTubeEndTB0", sTB0, medSPDss);
943         vTB0->SetVisibility(kTRUE);
944         vTB0->SetLineColor(1); // Black
945         vTB0->SetLineWidth(1);
946         vTB0->SetFillColor(vTB0->GetLineColor());
947         vTB0->SetFillStyle(4000); // 0% transparent
948         TGeoVolume *vTB1 = new TGeoVolume("ITSSPDCoolingTubeEndFluidTB1", sTB1, medSPDcoolfl);
949         vTB1->SetVisibility(kTRUE);
950         vTB1->SetLineColor(6); // Purple
951         vTB1->SetLineWidth(1);
952         vTB1->SetFillColor(vTB1->GetLineColor());
953         vTB1->SetFillStyle(4000); // 0% transparent
954         
955         // add volumes to mother container passed as argument of this method
956         moth->AddNode(vM0,1,0); // Add virtual volume to mother
957         vA0->AddNode(vA1,1,0); // Put air inside carbon fiber.
958         vB0->AddNode(vB1,1,0); // Put air inside carbon fiber.
959         vTA0->AddNode(vTA1,1,0); // Put air inside carbon fiber.
960         vTB0->AddNode(vTB1,1,0); // Put air inside carbon fiber.
961         for(i = 0; i < ksecNCoolingTubeDips; i++) {
962                 x0 = secX3[ksecDipIndex[i]];
963                 y0 = secY3[ksecDipIndex[i]];
964                 t = 90.0 - secAngleTurbo[i];
965                 trans = new TGeoTranslation("", x0, y0, 0.5 * (sB1->GetZ(0) + sB1->GetZ(1)));
966                 vB1->AddNode(vTB0, i+1, trans);
967                 rot = new TGeoRotation("", 0.0, 0.0, t);
968                 rotrans = new TGeoCombiTrans("", x0, y0, 0.0, rot);
969                 vM0->AddNode(vTA0, i+1, rotrans);
970         } // end for i
971         vM0->AddNode(vA0, 1, 0);
972         vM0->AddNode(vB0, 1, 0);
973         // Reflection.
974         vM0->AddNode(vB0, 2, new TGeoRotation("", 90., 0., 90., 90., 180., 0.));
975         if(GetDebug(3)){
976                 vM0->PrintNodes();
977                 vA0->PrintNodes();
978                 vA1->PrintNodes();
979                 vB0->PrintNodes();
980                 vB1->PrintNodes();
981                 vTA0->PrintNodes();
982                 vTA1->PrintNodes();
983                 vTB0->PrintNodes();
984                 vTB1->PrintNodes();
985         }
986 }
987 //
988 //__________________________________________________________________________________________
989 Bool_t AliITSv11GeometrySPD::GetSectorMountingPoints
990 (Int_t index, Double_t &x0, Double_t &y0, Double_t &x1, Double_t &y1) const
991 {
992         //
993         // Returns the edges of the straight borders in the SPD sector shape,
994         // which are used to mount staves on them.
995         // Coordinate system is that of the carbon fiber sector volume.
996         // ---
997         // Index numbering is as follows:
998         //                         /5
999         //                        /\/4
1000         //                      1\   \/3
1001         //                      0|___\/2
1002         // ---
1003         // Arguments [the ones passed by reference contain output values]:
1004         //    Int_t    index   --> location index according to above scheme [0-5]
1005         //    Double_t &x0     --> (by ref) x0 location or the ladder sector [cm]
1006         //    Double_t &y0     --> (by ref) y0 location of the ladder sector [cm]
1007         //    Double_t &x1     --> (by ref) x1 location or the ladder sector [cm]
1008         //    Double_t &y1     --> (by ref) y1 location of the ladder sector [cm]
1009         //    TGeoManager *mgr --> The TGeo builder
1010         // ---
1011         // The location is described by a line going from (x0, y0) to (x1, y1)
1012         // ---
1013         // Returns kTRUE if no problems encountered.
1014         // Returns kFALSE if a problem was encountered (e.g.: shape not found).
1015         //
1016         
1017         Int_t isize = fSPDsectorX0.GetSize();
1018         x0 = x1 = y0 = y1 = 0.0;
1019         if(index < 0 || index > isize) {
1020                 AliError(Form("index = %d: allowed 0 --> %", index, isize));
1021                 return kFALSE;
1022         }
1023         
1024         x0 = fSPDsectorX0[index];
1025         x1 = fSPDsectorX1[index];
1026         y0 = fSPDsectorY0[index];
1027         y1 = fSPDsectorY1[index];
1028         
1029         return kTRUE;
1030 }
1031 //
1032 //__________________________________________________________________________________________
1033 void AliITSv11GeometrySPD::SPDsectorShape
1034 (Int_t n,
1035  const Double_t *xc,  const Double_t *yc,  const Double_t *r,
1036  const Double_t *ths, const Double_t *the, 
1037  Int_t npr, Int_t &m, Double_t **xp, Double_t **yp) const
1038 {
1039                 
1040         // Code to compute the points that make up the shape of the SPD
1041         // Carbon fiber support sections
1042         // Inputs:
1043         //   Int_t n        size of arrays xc,yc, and r.
1044         //   Double_t *xc   array of x values for radii centers.
1045         //   Double_t *yc   array of y values for radii centers.
1046         //   Double_t *r    array of signed radii values.
1047         //   Double_t *ths  array of starting angles [degrees].
1048         //   Double_t *the  array of ending angles [degrees].
1049         //   Int_t     npr  the number of lines segments to aproximate the arc.
1050         // Outputs (arguments passed by reference):
1051         //   Int_t       m    the number of enetries in the arrays *xp[npr+1] and *yp[npr+1].
1052         //   Double_t **xp    array of x coordinate values of the line segments
1053         //                    which make up the SPD support sector shape.
1054         //   Double_t **yp    array of y coordinate values of the line segments
1055         //                    which make up the SPD support sector shape.
1056         //
1057         
1058         Int_t    i, k;
1059         Double_t t, t0, t1;
1060
1061         m = n*(npr + 1);
1062         if(GetDebug(2)) {
1063                 cout <<"        X       \t  Y  \t  R  \t  S  \t  E" << m << endl;
1064                 for(i = 0; i < n; i++) {
1065                         cout << "{"    << xc[i] << ", ";
1066                         cout << yc[i]  << ", ";
1067                         cout << r[i]   << ", ";
1068                         cout << ths[i] << ", ";
1069                         cout << the[i] << "}, " << endl;
1070                 }
1071         }
1072         
1073         if (GetDebug(3)) cout << "Double_t sA0 = [" << n*(npr+1)+1<<"][";
1074         if (GetDebug(4)) cout << "3] {";
1075         else if(GetDebug(3)) cout <<"2] {";
1076         t0 = (Double_t)npr;
1077         for(i = 0; i < n; i++) {
1078                 t1 = (the[i] - ths[i]) / t0;
1079                 if(GetDebug(5)) cout << "t1 = " << t1 << endl;
1080                 for(k = 0; k <= npr; k++) {
1081                         t = ths[i] + ((Double_t)k) * t1;
1082                         xp[i][k] = TMath::Abs(r[i]) * CosD(t) + xc[i];
1083                         yp[i][k] = TMath::Abs(r[i]) * SinD(t) + yc[i];
1084                         if(GetDebug(3)) {
1085                                 cout << "{" << xp[i][k] << "," << yp[i][k];
1086                                 if (GetDebug(4)) cout << "," << t;
1087                                 cout << "},";
1088                         } // end if GetDebug
1089                 } // end for k
1090                 if(GetDebug(3)) cout << endl;
1091         } // end of i
1092         if(GetDebug(3)) cout << "{"  << xp[0][0] << ", " << yp[0][0];
1093         if(GetDebug(4)) cout << ","  << ths[0];
1094         if(GetDebug(3)) cout << "}}" << endl;
1095 }
1096 //
1097 //__________________________________________________________________________________________
1098 TGeoVolume* AliITSv11GeometrySPD::CreateLadder
1099 (Int_t layer,TArrayD &sizes, TGeoManager *mgr) const
1100 {
1101         // Creates the "ladder" = silicon sensor + 5 chips.
1102         // Returns a TGeoVolume containing the following components:
1103         //  - the sensor (TGeoBBox), whose name depends on the layer
1104         //  - 5 identical chips (TGeoBBox)
1105         //  - a guard ring around the sensor (subtraction of TGeoBBoxes),
1106         //    which is separated from the rest of sensor because it is not 
1107         //    a sensitive part
1108         //  - bump bondings (TGeoBBox stripes for the whole width of the 
1109         //    sensor, one per column).
1110         // ---
1111         // Arguments:
1112         //  1 - the owner layer (MUST be 1 or 2 or a fatal error is raised)
1113         //  2 - a TArrayD passed by reference, which contains some relevant 
1114         //      sizes of this object:
1115         //      size[0] = 'thickness' (the direction orthogonal to the ALICE 
1116         //                 Z axis, along which the different parts of the 
1117         //                  stave are superimposed on each other)
1118         //      size[1] = 'length' (the direction along the ALICE Z axis)
1119         //      size[2] = 'width' (the direction orthogonal to both the 
1120         //                above ones) 
1121         //  3 - the used TGeoManager
1122         
1123         // ** CRITICAL CHECK ** 
1124         // layer number can be ONLY 1 or 2
1125         if (layer != 1 && layer != 2) AliFatal("Layer number MUST be 1 or 2");
1126         
1127         // ** MEDIA **
1128         // instantiate all required media
1129         TGeoMedium *medAir       = GetMedium("AIR$",mgr);
1130         TGeoMedium *medSPDSiChip = GetMedium("SPD SI CHIP$",mgr);// SPD SI CHIP
1131         TGeoMedium *medSi        = GetMedium("SI$",mgr);
1132         TGeoMedium *medBumpBond  = GetMedium("COPPER$",mgr); // ??? BumpBond    
1133         
1134         // ** SIZES **
1135         // for the chip, also the spacing between them is required
1136         Double_t chipThickness  = fgkmm *  0.150;
1137         Double_t chipWidth      = fgkmm * 15.950;
1138         Double_t chipLength     = fgkmm * 13.600;
1139         Double_t chipSpacing    = fgkmm *  0.400;       
1140         // for the sensor, we define the area of sensitive volume
1141         // while the guard ring is added as a separate piece
1142         Double_t sensThickness  = fgkmm *  0.200;
1143         Double_t sensLength     = fgkmm * 69.600;
1144         Double_t sensWidth      = fgkmm * 12.800;
1145         Double_t guardRingWidth = fgkmm *  0.560;
1146         // bump bond is defined as a small stripe of height = 0.012 mm
1147         // and a suitable width to keep the same volume it has 
1148         // before being compressed (a line of spheres of 0.025 mm radius)
1149         Double_t bbLength    = fgkmm * 0.042;
1150         Double_t bbWidth     = sensWidth;
1151         Double_t bbThickness = fgkmm * 0.012;
1152         Double_t bbPos       = 0.080; // Z position w.r. to left pixel edge
1153         
1154         // ** VOLUMES **
1155         // for readability reasons, create references to
1156         // the overall sizes which will be returned in the TArrayD
1157         if (sizes.GetSize() != 3) sizes.Set(3);
1158         Double_t &thickness = sizes[0];
1159         Double_t &length = sizes[1];
1160         Double_t &width = sizes[2];             
1161         // the container is a box which exactly enclose all the stuff;
1162         // it is filled with air and named according to the layer number
1163         width = chipWidth;
1164         length = sensLength + 2.0*guardRingWidth;
1165         thickness = sensThickness + chipThickness + bbThickness;
1166         //TGeoVolume *container = mgr->MakeBox(Form("LAY%d_LADDER", layer),
1167         //                       medAir, 0.5*width, 0.5*thickness, 0.5*length);
1168         // We must have the x coordinate of this container conresponding to 
1169         // the x corrdinate of the sensitive volume. In order to do that we 
1170         // are going to create the container with a local reference system 
1171         // that is not in the middle of the box. This need to call directly 
1172         // the constructor of the shape, with an option :
1173         Double_t xSens = 0.5 * (width - sensWidth - 2.0*guardRingWidth);
1174         Double_t originShift[3] = {-xSens, 0., 0.};
1175         TGeoBBox *shapeContainer = new TGeoBBox(0.5*width, 0.5*thickness, 0.5*length, originShift);
1176         TGeoVolume *container = new TGeoVolume(Form("LAY%d_LADDER",layer), shapeContainer, medAir);
1177         // the chip
1178         TGeoVolume *volChip = mgr->MakeBox
1179                 ("CHIP", medSPDSiChip, 0.5*chipWidth, 0.5*chipThickness, 0.5*chipLength);
1180         // the sensor
1181         TGeoVolume *volSens = mgr->MakeBox
1182                 (GetSenstiveVolumeName(layer), medSi, 0.5*sensWidth, 0.5*sensThickness, 0.5*sensLength);
1183         // the guard ring shape is the subtraction of two boxes with the same center.
1184         TGeoBBox  *shIn = new TGeoBBox(0.5*sensWidth, sensThickness, 0.5*sensLength);
1185         TGeoBBox  *shOut = new TGeoBBox
1186                 (0.5*sensWidth + guardRingWidth, 0.5*sensThickness, 0.5*sensLength + guardRingWidth);
1187         shIn->SetName("innerBox");
1188         shOut->SetName("outerBox");
1189         TGeoCompositeShape *shBorder = new TGeoCompositeShape("", "outerBox-innerBox");
1190         TGeoVolume *volBorder = new TGeoVolume("GUARD_RING", shBorder, medSi);
1191         // bump bonds for one whole column
1192         TGeoVolume *volBB = mgr->MakeBox
1193                 ("BB", medBumpBond, 0.5*bbWidth, 0.5*bbThickness, 0.5*bbLength);
1194         // set colors of all objects for visualization  
1195         volSens->SetLineColor(kYellow + 1);
1196         volChip->SetLineColor(kGreen);
1197         volBorder->SetLineColor(kYellow + 3);
1198         
1199         // ** MOVEMENTS **
1200         // translation for the sensor parts: direction of width and 
1201         // thickness (moved up)
1202         Double_t ySens = 0.5 * (thickness - sensThickness);
1203         Double_t zSens = 0.0;
1204         // We want that the x of the ladder is the same as the one of its sensitive volume
1205         TGeoTranslation *trSens = new TGeoTranslation(xSens - xSens, ySens, zSens);
1206         // translation for the bump bonds:
1207         // keep same y used for sensors, but change the Z
1208         TGeoTranslation *trBB[160];
1209         Double_t x = xSens - xSens;
1210         Double_t y = 0.5 * (thickness - bbThickness) - sensThickness;
1211         Double_t z = -0.5 * sensLength + guardRingWidth + fgkmm*0.425 - bbPos;
1212         Int_t i;
1213         for (i = 0; i < 160; i++) {
1214                 trBB[i] = new TGeoTranslation(x, y, z);
1215                 switch(i) {
1216                 case  31:
1217                 case  63:
1218                 case  95:
1219                 case 127:
1220                         z += fgkmm * 0.625 + fgkmm * 0.2;
1221                         break;
1222                 default:
1223                         z += fgkmm * 0.425;
1224                 } // end switch
1225         } // end for i
1226         // translations for the chip box: direction of length and 
1227         // thickness (moved down)
1228         TGeoTranslation *trChip[5] = {0, 0, 0, 0, 0};
1229         x = -xSens;
1230         y = 0.5 * (chipThickness - thickness);
1231         z = 0.0;
1232         for (i = 0; i < 5; i++) {
1233                 z = -0.5*length + guardRingWidth 
1234                   + (Double_t)i*chipSpacing + ((Double_t)(i) + 0.5)*chipLength;
1235                 trChip[i] = new TGeoTranslation(x, y, z);
1236         } // end for i
1237         
1238         // add nodes to container
1239         container->AddNode(volSens, 1, trSens);
1240         container->AddNode(volBorder, 1, trSens);
1241         for (i = 0; i < 160; i++) container->AddNode(volBB, i, trBB[i]);
1242         for (i = 0; i < 5; i++) container->AddNode(volChip, i + 2, trChip[i]);
1243         
1244         // return the container
1245         return container;
1246 }
1247 //
1248 //__________________________________________________________________________________________
1249 TGeoVolume* AliITSv11GeometrySPD::CreateClip
1250 (TArrayD &sizes, TGeoManager *mgr) const
1251 {
1252         //
1253         // Creates the carbon fiber clips which are added to the central ladders.
1254         // They have a complicated shape which is approximated by a TGeoXtru
1255         // Implementation of a single clip over an half-stave.
1256         // It has a complicated shape which is approximated to a section like this:
1257         //   
1258         //     6
1259         //     /\   .
1260         //  7 //\\  5
1261         //    / 1\\___________________4
1262         //   0    \___________________
1263         //        2                   3
1264         // with a finite thickness for all the shape 
1265         // Its local reference frame is such that point A corresponds to origin.
1266         //
1267         
1268         Double_t fullLength      = fgkmm * 12.6;    // = x4 - x0
1269         Double_t flatLength      = fgkmm *  5.4;    // = x4 - x3
1270         Double_t inclLongLength  = fgkmm *  5.0;    // = 5-6
1271         Double_t inclShortLength = fgkmm *  2.0;    // = 6-7
1272         Double_t fullHeight      = fgkmm *  2.8;    // = y6 - y3
1273         Double_t thickness       = fgkmm *  0.2;    // thickness
1274         Double_t totalLength     = fgkmm * 52.0;    // total length in Z
1275         Double_t holeSize        = fgkmm *  4.0;    // dimension of cubic hole inserted for pt1000
1276         Double_t angle1          = 27.0;            // supplementary of angle DCB
1277         Double_t angle2;                            // angle DCB
1278         Double_t angle3;                            // angle of GH with vertical
1279         
1280         angle2 = 0.5 * (180.0 - angle1);
1281         angle3 = 90.0 - TMath::ACos(fullLength - flatLength - inclLongLength*TMath::Cos(angle1)) * TMath::RadToDeg();
1282         
1283         angle1 *= TMath::DegToRad();
1284         angle2 *= TMath::DegToRad();
1285         angle3 *= TMath::DegToRad();
1286         
1287         Double_t x[8], y[8];
1288         
1289         x[0] =  0.0;
1290         x[1] = x[0] + fullLength - flatLength - inclLongLength*TMath::Cos(angle1);
1291         x[2] = x[0] + fullLength - flatLength;
1292         x[3] = x[0] + fullLength;
1293         x[4] = x[3];
1294         x[5] = x[4] - flatLength + thickness * TMath::Cos(angle2);
1295         x[6] = x[1];
1296         x[7] = x[0];
1297         
1298         y[0] = 0.0;
1299         y[1] = y[0] + inclShortLength * TMath::Cos(angle3);
1300         y[2] = y[1] - inclLongLength * TMath::Sin(angle1);
1301         y[3] = y[2];
1302         y[4] = y[3] + thickness;
1303         y[5] = y[4];
1304         y[6] = y[1] + thickness;
1305         y[7] = y[0] + thickness;
1306         
1307         sizes.Set(7);
1308         sizes[0] = totalLength;
1309         sizes[1] = fullHeight;
1310         sizes[2] = y[2];
1311         sizes[3] = y[6];
1312         sizes[4] = x[0];
1313         sizes[5] = x[3];
1314         sizes[6] = x[2];
1315         
1316         TGeoXtru *shClip = new TGeoXtru(2);
1317         shClip->SetName("SHCLIP");
1318         shClip->DefinePolygon(8, x, y);
1319         shClip->DefineSection(0, -0.5*totalLength, 0., 0., 1.0);
1320         shClip->DefineSection(1,  0.5*totalLength, 0., 0., 1.0);
1321         
1322         TGeoBBox *shHole = new TGeoBBox("SH_CLIPHOLE", 0.5*holeSize, 0.5*holeSize, 0.5*holeSize);
1323         TGeoTranslation *tr1 = new TGeoTranslation("TR_CLIPHOLE1", x[2], 0.0,  fgkmm*14.);
1324         TGeoTranslation *tr2 = new TGeoTranslation("TR_CLIPHOLE2", x[2], 0.0, 0.0);
1325         TGeoTranslation *tr3 = new TGeoTranslation("TR_CLIPHOLE3", x[2], 0.0, -fgkmm*14.);
1326         tr1->RegisterYourself();
1327         tr2->RegisterYourself();
1328         tr3->RegisterYourself();
1329         
1330         TString strExpr("SHCLIP-(");
1331         strExpr.Append(Form("%s:%s+", shHole->GetName(), tr1->GetName()));
1332         strExpr.Append(Form("%s:%s+", shHole->GetName(), tr2->GetName()));
1333         strExpr.Append(Form("%s:%s)", shHole->GetName(), tr3->GetName()));
1334         TGeoCompositeShape *shClipHole = new TGeoCompositeShape("SHCLIPHOLES", strExpr.Data());
1335         
1336         TGeoMedium *mat = GetMedium("ITSspdCarbonFiber", mgr);
1337         TGeoVolume *vClip = new TGeoVolume("clip", shClipHole, mat);
1338         vClip->SetLineColor(kGray + 2);
1339         return vClip;
1340 }
1341 //
1342 //__________________________________________________________________________________________
1343 TGeoVolumeAssembly* AliITSv11GeometrySPD::CreateGroundingFoilSingle
1344 (Int_t type, TArrayD &sizes, TGeoManager *mgr) const
1345 {
1346         // Returns a TGeoVolume representing a single grounding foil layer.
1347         // This shape is used to create the two real foils of the GF (one in 
1348         // kapton, and one in aluminum), and also to implement the glue 
1349         // layers which link the GF to the carbon fiber support, and to the 
1350         // ladders.
1351         // ---
1352         // The glue and kapton layers have exactly the same size, while 
1353         // the aluminum foil has some small differences in its overall size 
1354         // and in the dimensions of its holes. The first argument passed to 
1355         // the function ("type") is used to choose between all these 
1356         // possibilities:
1357         //   - type = 0 --> kapton layer
1358         //   - type = 1 --> aluminum layer
1359         //   - type = 2 --> glue layer between support and GF
1360         //   - type = 3 --> glue layer between GF and ladders
1361         // ---
1362         // The complete object is created as the sum of the following parts:
1363         // 1) the part which is connected to the chips, which is a 
1364         //    simple box with some box-shaped holes at regular intervals
1365         // 2) a trapezoidal connection where the Y size changes
1366         // 3) another box with a unique hole of the same shape and size as above
1367         // 4) another trapezoidal connection where the Y size changes
1368         // 5) a final part which is built as a sequence of 4 BOX volumes
1369         //    where the first and the third are equal and the others have 
1370         //    same size in Y.
1371         // ---
1372         // The sizes of all parts are parameterized with variable names,
1373         // even if their value is fixed according to engineers' drawings.
1374         // ---
1375         // The returns value is a TGeoVolume object which contains all parts 
1376         // of this layer. The 'sizes' argument passed by reference will 
1377         // contain the three dimensions of the container and some other 
1378         // values which upper level methods (stave assemblier) must know:
1379         //   - sizes[0] = full thickness
1380         //   - sizes[1] = full length
1381         //   - sizes[2] = full width
1382         //   - sizes[3] = hole length
1383         //   - sizes[4] = hole width
1384         //   - sizes[5] = position of first hole center
1385         //   - sizes[6] = standard separation between holes
1386         //   - sizes[7] = separation between 5th and 6th hole
1387         //   - sizes[8] = separation between 10th and 11th hole
1388         //   - sizes[9] = separation between the upper hole border and the 
1389         //                foil border
1390         // ** MEDIA **
1391         // - vacuum for the container volume
1392         // - kapton/aluminum/glue for the pysical volume
1393         TGeoMedium *mat = GetMedium("SPD KAPTON(POLYCH2)$", mgr);       
1394         // ** SIZES **
1395         Double_t sizeZ      = fgkmm *   0.05;
1396         Double_t part1X     = fgkmm * 140.71;
1397         Double_t part2X     = fgkmm *   2.48;
1398         Double_t part3X     = fgkmm *  26.78;
1399         Double_t part4X     = fgkmm *   4.00;
1400         Double_t part5X     = fgkmm *  10.00;
1401         Double_t part6X     = fgkmm *  24.40;
1402         Double_t part7X     = fgkmm *  10.00;
1403         Double_t part8X     = fgkmm *  24.81;
1404         Double_t sizeYMax   = fgkmm *  15.95;
1405         Double_t sizeYMed1  = fgkmm *  15.00;
1406         Double_t sizeYMed2  = fgkmm *  11.00;
1407         Double_t sizeYMin   = fgkmm *   4.40;
1408         Double_t holeX      = fgkmm *  10.00;
1409         Double_t holeY      = fgkmm *   7.50;
1410         Double_t holeFirstX = fgkmm *   7.05;  // position of center of first hole
1411         Double_t holeSepX   = fgkmm *  14.00;  // separation between the 
1412         // centers of two consecutive holes
1413         Double_t holeSepX1  = fgkmm *   1.42;  // to be added after 4th hole in 
1414         // volume 1
1415         Double_t holeSepY   = fgkmm *   4.40;  // dist between hole's and 
1416         // volume's upper border
1417         Double_t holeAloneX = fgkmm *  13.28;  // position of hole center in 
1418         // box "part 3"
1419         // correct sizes/material in case we are on Aluminum foil
1420         if (type == 1) {
1421                 mat = GetMedium("AL$", mgr);
1422                 sizeZ       = fgkmm * 0.025;
1423                 part1X     -= fgkmm * 0.2;
1424                 part5X     -= fgkmm * 0.2;
1425                 part6X     += fgkmm * 0.4;
1426                 part7X     -= fgkmm * 0.4;
1427                 sizeYMax   -= fgkmm * 0.4;
1428                 sizeYMed1  -= fgkmm * 0.4;
1429                 sizeYMed2  -= fgkmm * 0.4;
1430                 sizeYMin   -= fgkmm * 0.4;
1431                 holeX      += fgkmm * 0.4;
1432                 holeY      += fgkmm * 0.4;
1433                 holeFirstX -= fgkmm * 0.2;
1434                 holeSepY   -= fgkmm * 0.4;
1435         } // end if type==1
1436         
1437         // correct sizes/material in case we are in a glue layer
1438         if (type == 2) {
1439                 mat = GetMedium("EPOXY$", mgr); //??? GLUE_GF_SUPPORT
1440                 sizeZ = fgkmm * 0.1175;
1441         } // end if type ==2
1442         if (type == 3) {
1443                 mat = GetMedium("EPOXY$", mgr); //??? GLUE_GF_SUPPORT
1444                 sizeZ = fgkmm * 0.1175 - fAlignmentGap;
1445                 if (sizeZ <= 0.0) {
1446                         AliFatal("Too large gap thickness.");
1447                         return 0;
1448                 } // end if sizeZ<=0
1449         }// end if type==3
1450      // initialize the argument TArrayD
1451         if (sizes.GetSize() != 10) sizes.Set(10);
1452         Double_t &thickness = sizes[0];
1453         Double_t &length = sizes[1];
1454         Double_t &width = sizes[2];
1455         // compute full length and width
1456         length = part1X+part2X+part3X+part4X+part5X+part6X+part7X+part8X;
1457         width = sizeYMax;
1458         thickness = sizeZ;
1459         sizes[3] = holeX;
1460         sizes[4] = holeY;
1461         sizes[5] = holeFirstX;
1462         sizes[6] = holeSepX;
1463         sizes[7] = holeSepX + holeSepX1;
1464         sizes[8] = fgkmm * 22.0; // the last separation is not used in the 
1465         // rest, and is implemented from scratch
1466         sizes[9] = holeSepY;
1467         // ** OBJECT NAMES **
1468         // define names for the object
1469         char stype[20];
1470         if (type == 0) strcpy(stype, "KAP");
1471         else if (type == 1) strcpy(stype, "ALU");
1472         else if (type == 2) strcpy(stype, "GLUE1");
1473         else if (type == 3) strcpy(stype, "GLUE2");
1474         else {
1475                 AliFatal(Form("Type %d not allowed for grounding foil", type));
1476         } // end if else
1477         // ** VOLUMES **
1478         // grounding foil world, bounded exactly around the limits of the structure
1479         // TGeoVolume *container = mgr->MakeBox(Form("GFOIL_%s", stype), 
1480         // air, 0.5*length, 0.5*sizeYMax, 0.5*sizeZ);
1481         TGeoVolumeAssembly *container = new TGeoVolumeAssembly(Form("GFOIL_%s",
1482                                                                                                                                 stype));
1483         // === PART 1: box with holes ===
1484         TGeoBBox *shBox1 = 0, *shHole = 0;
1485         shBox1 = new TGeoBBox(Form("GF%s_BOX1", stype), 0.5*part1X, 0.5*sizeYMax, 
1486                                                   0.5*sizeZ);
1487         shHole = new TGeoBBox(Form("GF%s_HOLE", stype), 0.5*holeX, 0.5*holeY,
1488                                                   0.5*sizeZ + 0.01);
1489         // define the position of all holes and compose the expression
1490         // to define the composite shape (box - holes)
1491         Double_t firstX = -0.5*part1X + holeFirstX;
1492         Double_t transY =  0.5*sizeYMax - holeSepY - 0.5*holeY;
1493         Double_t transX;
1494         TGeoTranslation *transHole[10];
1495         TString strComposite(Form("%s - (", shBox1->GetName()));
1496         for (Int_t i = 0; i < 10; i++) {
1497                 transX = firstX + (Double_t)i * holeSepX;
1498                 if (i > 4) transX += holeSepX1;
1499                 transHole[i] = new TGeoTranslation(Form("TGF%s_HOLE%d", stype, i), 
1500                                                                                    transX, transY, 0.0);
1501                 transHole[i]->RegisterYourself();
1502                 strComposite.Append(Form("%s:%s", shHole->GetName(), 
1503                                                                  transHole[i]->GetName()));
1504                 if (i < 9) strComposite.Append("+"); else strComposite.Append(")");
1505         } // end for i
1506         // create composite shape
1507         TGeoCompositeShape *shPart1 = new TGeoCompositeShape(
1508                                                                                                                  Form("GF%s_PART1_SHAPE", stype), strComposite.Data());
1509         // create the volume
1510         TGeoVolume *volPart1 = new TGeoVolume(Form("GF%s_PART1", stype), 
1511                                                                                   shPart1, mat);
1512         // === PART 2: first trapezoidal connection
1513         TGeoArb8 *shTrap1 = new TGeoArb8(0.5*sizeZ);
1514         shTrap1->SetVertex(0, -0.5*part2X,  0.5*sizeYMax);
1515         shTrap1->SetVertex(1,  0.5*part2X,  0.5*sizeYMax);
1516         shTrap1->SetVertex(2,  0.5*part2X,  0.5*sizeYMax - sizeYMed1);
1517         shTrap1->SetVertex(3, -0.5*part2X, -0.5*sizeYMax);
1518         shTrap1->SetVertex(4, -0.5*part2X,  0.5*sizeYMax);
1519         shTrap1->SetVertex(5,  0.5*part2X,  0.5*sizeYMax);
1520         shTrap1->SetVertex(6,  0.5*part2X,  0.5*sizeYMax - sizeYMed1);
1521         shTrap1->SetVertex(7, -0.5*part2X, -0.5*sizeYMax);
1522         TGeoVolume *volPart2 = new TGeoVolume(Form("GF%s_PART2", stype), 
1523                                                                                   shTrap1, mat);
1524         // === PART 3: other box with one hole
1525         TGeoBBox *shBox2 = 0;
1526         shBox2 = new TGeoBBox(Form("GF%s_BOX2", stype), 0.5*part3X, 
1527                                                   0.5*sizeYMed1, 0.5*sizeZ);
1528         // define the position of the hole
1529         transX = holeAloneX - 0.5*part3X;
1530         transY -= 0.5*(sizeYMax - sizeYMed1);
1531         TGeoTranslation *transHoleAlone = new TGeoTranslation(
1532                                                                                                                   Form("TGF%s_HOLE_ALONE", stype), transX, transY, 0.0);
1533         transHoleAlone->RegisterYourself();
1534         // create composite shape
1535         TGeoCompositeShape *shPart3 = new TGeoCompositeShape(
1536                                                                                                                  Form("GF%sPART3_SHAPE", stype), 
1537                                                                                                                  Form("%s - %s:%s", shBox2->GetName(), 
1538                                                                                                                           shHole->GetName(), transHoleAlone->GetName()));
1539         // create the volume
1540         TGeoVolume *volPart3 = new TGeoVolume(Form("GF%s_PART3", stype), 
1541                                                                                   shPart3, mat);
1542         // === PART 4: second trapezoidal connection
1543         TGeoArb8 *shTrap2 = new TGeoArb8(0.5*sizeZ);
1544         shTrap2->SetVertex(0, -0.5*part4X,  0.5*sizeYMed1);
1545         shTrap2->SetVertex(1,  0.5*part4X,  0.5*sizeYMed1);
1546         shTrap2->SetVertex(2,  0.5*part4X,  0.5*sizeYMed1 - sizeYMed2);
1547         shTrap2->SetVertex(3, -0.5*part4X, -0.5*sizeYMed1);
1548         shTrap2->SetVertex(4, -0.5*part4X,  0.5*sizeYMed1);
1549         shTrap2->SetVertex(5,  0.5*part4X,  0.5*sizeYMed1);
1550         shTrap2->SetVertex(6,  0.5*part4X,  0.5*sizeYMed1 - sizeYMed2);
1551         shTrap2->SetVertex(7, -0.5*part4X, -0.5*sizeYMed1);
1552         TGeoVolume *volPart4 = new TGeoVolume(Form("GF%s_PART4", stype), 
1553                                                                                   shTrap2, mat);
1554         // === PART 5 --> 8: sequence of boxes ===
1555         TGeoVolume *volPart5 = mgr->MakeBox(Form("GF%s_BOX3", stype), mat, 
1556                                                                                 0.5*part5X, 0.5*sizeYMed2, 0.5*sizeZ);
1557         TGeoVolume *volPart6 = mgr->MakeBox(Form("GF%s_BOX4", stype), mat, 
1558                                                                                 0.5*part6X, 0.5*sizeYMin , 0.5*sizeZ);
1559         TGeoVolume *volPart7 = mgr->MakeBox(Form("GF%s_BOX5", stype), mat, 
1560                                                                                 0.5*part7X, 0.5*sizeYMed2, 0.5*sizeZ);
1561         TGeoVolume *volPart8 = mgr->MakeBox(Form("GF%s_BOX6", stype), mat, 
1562                                                                                 0.5*part8X, 0.5*sizeYMin , 0.5*sizeZ);
1563         // === SET COLOR ===
1564         Color_t color = kRed + 3;
1565         if (type == 1) color = kGreen;
1566         if (type == 2 || type == 3) color = kYellow;
1567         volPart1->SetLineColor(color);
1568         volPart2->SetLineColor(color);
1569         volPart3->SetLineColor(color);
1570         volPart4->SetLineColor(color);
1571         volPart5->SetLineColor(color);
1572         volPart6->SetLineColor(color);
1573         volPart7->SetLineColor(color);
1574         volPart8->SetLineColor(color);
1575         // ** MOVEMENTS **      
1576         transX = 0.5*(part1X - length);
1577         TGeoTranslation *transPart1 = new TGeoTranslation(transX, 0.0, 0.0);
1578         transX += 0.5*(part1X + part2X);
1579         TGeoTranslation *transPart2 = new TGeoTranslation(transX, 0.0, 0.0);
1580         transX += 0.5*(part2X + part3X);
1581         transY  = 0.5*(sizeYMax - sizeYMed1);
1582         TGeoTranslation *transPart3 = new TGeoTranslation(transX, transY, 0.0);
1583         transX += 0.5*(part3X + part4X);
1584         TGeoTranslation *transPart4 = new TGeoTranslation(transX, transY, 0.0);
1585         transX += 0.5*(part4X + part5X);
1586         transY  = 0.5*(sizeYMax - sizeYMed2);
1587         TGeoTranslation *transPart5 = new TGeoTranslation(transX, transY, 0.0);
1588         transX += 0.5*(part5X + part6X);
1589         transY  = 0.5*(sizeYMax - sizeYMin);
1590         TGeoTranslation *transPart6 = new TGeoTranslation(transX, transY, 0.0);
1591         transX += 0.5*(part6X + part7X);
1592         transY  = 0.5*(sizeYMax - sizeYMed2);
1593         TGeoTranslation *transPart7 = new TGeoTranslation(transX, transY, 0.0);
1594         transX += 0.5*(part7X + part8X);
1595         transY  = 0.5*(sizeYMax - sizeYMin);
1596         TGeoTranslation *transPart8 = new TGeoTranslation(transX, transY, 0.0);
1597         // add the partial volumes to the container
1598         container->AddNode(volPart1, 1, transPart1);
1599         container->AddNode(volPart2, 2, transPart2);
1600         container->AddNode(volPart3, 3, transPart3);
1601         container->AddNode(volPart4, 4, transPart4);
1602         container->AddNode(volPart5, 5, transPart5);
1603         container->AddNode(volPart6, 6, transPart6);
1604         container->AddNode(volPart7, 7, transPart7);
1605         container->AddNode(volPart8, 8, transPart8);
1606         return container;
1607 }
1608 //
1609 //__________________________________________________________________________________________
1610 TGeoVolume* AliITSv11GeometrySPD::CreateGroundingFoil
1611 (Bool_t isRight, TArrayD &sizes, TGeoManager *mgr) const
1612 {
1613         // Create a volume containing all parts of the grounding foil a 
1614         // half-stave. The use of the TGeoXtru shape causes that in each 
1615         // single component volume the Z axis lies perpendicularly to the 
1616         // polygonal basis of this shape. Since we want that the Z axis 
1617         // of this volume must coincide with the one of the ALICE global 
1618         // reference frame, this requires some rotations of each component, 
1619         // besides the necessary translations to place it correctly with 
1620         // respect to the whole stave volume.
1621         // ---
1622         // Arguments:
1623         //  1: a boolean value to know if it is the grounding foir for 
1624         //     the right or left side
1625         //  2: a TArrayD which will contain the dimension of the container box:
1626         //       - size[0] = length along Z (the beam line direction)
1627         //       - size[1] = the 'width' of the stave, which defines, together 
1628         //                   with Z, the plane of the carbon fiber support
1629         //       - size[2] = 'thickness' (= the direction along which all 
1630         //                    stave components are superimposed)
1631         //  3: the TGeoManager
1632         // ---
1633         // The return value is a TGeoBBox volume containing all grounding 
1634         // foil components.
1635         // to avoid strange behaviour of the geometry manager,
1636         // create a suffix to be used in the names of all shapes
1637         char suf[5];
1638         if (isRight) strcpy(suf, "R"); else strcpy(suf, "L");
1639         // this volume will be created in order to ease its placement in 
1640         // the half-stave; then, it is added here the small distance of 
1641         // the "central" edge of each volume from the Z=0 plane in the stave 
1642         // reference (which coincides with ALICE one)
1643         Double_t dist = fgkmm * 0.71;           
1644         // create the component volumes and register their sizes in the 
1645         // passed arrays for readability reasons, some reference variables 
1646         // explicit the meaning of the array slots
1647         TArrayD kpSize(9), alSize(9), g1Size(9), g2Size(9);
1648         TGeoVolume *kpVol = CreateGroundingFoilSingle(0, kpSize, mgr);
1649         TGeoVolume *alVol = CreateGroundingFoilSingle(1, alSize, mgr);
1650         TGeoVolume *g1Vol = CreateGroundingFoilSingle(2, g1Size, mgr);
1651         TGeoVolume *g2Vol = CreateGroundingFoilSingle(3, g2Size, mgr);
1652         Double_t &kpLength = kpSize[1],&kpThickness=kpSize[0];//,&kpWidth=kpSize[2];
1653         Double_t &alLength = alSize[1],&alThickness=alSize[0];//,&alWidth=alSize[2];
1654         Double_t &g1Thickness = g1Size[0], &g2Thickness = g2Size[0];
1655
1656         // create references for the final size object
1657         if (sizes.GetSize() != 3) sizes.Set(3);
1658         Double_t &fullThickness = sizes[0];
1659         Double_t &fullLength = sizes[1];
1660         Double_t &fullWidth = sizes[2];                 
1661         // kapton leads the larger dimensions of the foil 
1662         // (including the cited small distance from Z=0 stave reference plane)
1663         // the thickness is the sum of the ones of all components
1664         fullLength    = kpSize[1] + dist;
1665         fullWidth     = kpSize[2];
1666         fullThickness = kpSize[0] + alSize[0] + g1Size[0] + g2Size[0];
1667         // create the container
1668         TGeoMedium *air = GetMedium("AIR$", mgr);
1669         TGeoVolume *container = mgr->MakeBox(Form("GFOIL_%s", suf), air, 
1670                                                                                  0.5*fullThickness, 0.5*fullWidth, 0.5*fullLength);
1671         // create the common correction rotation (which depends of what side 
1672         // we are building)
1673         TGeoRotation *rotCorr = new TGeoRotation(*gGeoIdentity);
1674         if (isRight) rotCorr->RotateY(90.0);
1675         else rotCorr->RotateY(-90.0);           
1676         // compute the translations, which are in the length and thickness 
1677         // directions
1678         Double_t x, y, z, shift = 0.0;
1679         if (isRight) shift = dist;
1680         // glue (bottom)
1681         x = -0.5*(fullThickness - g1Thickness);
1682         z =  0.5*(fullLength - kpLength) - shift;
1683         TGeoCombiTrans *g1Trans = new TGeoCombiTrans(x, 0.0, z, rotCorr);
1684         // kapton
1685         x += 0.5*(g1Thickness + kpThickness);
1686         TGeoCombiTrans *kpTrans  = new TGeoCombiTrans(x, 0.0, z, rotCorr);
1687         // aluminum
1688         x += 0.5*(kpThickness + alThickness);
1689         z  = 0.5*(fullLength - alLength) - shift - 0.5*(kpLength - alLength);
1690         TGeoCombiTrans *alTrans  = new TGeoCombiTrans(x, 0.0, z, rotCorr);
1691         // glue (top)
1692         x += 0.5*(alThickness + g2Thickness);
1693         z  = 0.5*(fullLength - kpLength) - shift;
1694         TGeoCombiTrans *g2Trans = new TGeoCombiTrans(x, 0.0, z, rotCorr);
1695                 
1696         // add to container
1697         container->AddNode(kpVol, 0, kpTrans);
1698         container->AddNode(alVol, 0, alTrans);
1699         container->AddNode(g1Vol, 0, g1Trans);
1700         container->AddNode(g2Vol, 0, g2Trans);  
1701         // to add the grease we remember the sizes of the holes, stored as 
1702         // additional parameters in the kapton layer size:
1703         //   - sizes[3] = hole length
1704         //   - sizes[4] = hole width
1705         //   - sizes[5] = position of first hole center
1706         //   - sizes[6] = standard separation between holes
1707         //   - sizes[7] = separation between 5th and 6th hole
1708         //   - sizes[8] = separation between 10th and 11th hole
1709         //   - sizes[9] = separation between the upper hole border and 
1710         //                the foil border
1711         Double_t holeLength      = kpSize[3];
1712         Double_t holeWidth       = kpSize[4];
1713         Double_t holeFirstZ      = kpSize[5];
1714         Double_t holeSepZ        = kpSize[6];
1715         Double_t holeSep5th6th   = kpSize[7];
1716         Double_t holeSep10th11th = kpSize[8];
1717         Double_t holeSepY        = kpSize[9];
1718         // volume (common)
1719         TGeoMedium *grease = GetMedium("SPD KAPTON(POLYCH2)$", mgr); // ??? GREASE
1720         TGeoVolume *hVol   = mgr->MakeBox("GREASE", grease, 0.5*fullThickness, 
1721                                                                           0.5*holeWidth, 0.5*holeLength);
1722         hVol->SetLineColor(kBlue);
1723         // displacement of volumes in the container
1724         Int_t    idx = 0;
1725         x = 0.0;
1726         y = 0.5*(fullWidth - holeWidth) - holeSepY;
1727         if (isRight) z = holeFirstZ - 0.5*fullLength + dist;
1728         else z = 0.5*fullLength - holeFirstZ - dist;
1729         for (Int_t i = 0; i < 11; i++) {
1730                 TGeoTranslation *t = 0;
1731                 t = new TGeoTranslation(x, y, -z);
1732                 container->AddNode(hVol, idx++, t);
1733                 if (i < 4) shift = holeSepZ;
1734                 else if (i == 4) shift = holeSep5th6th;
1735                 else if (i < 9) shift = holeSepZ;
1736                 else shift = holeSep10th11th;
1737                 if (isRight) z += shift;
1738                 else z -= shift;
1739         }// end for i
1740         return container;
1741 }
1742 //
1743 //__________________________________________________________________________________________
1744 TGeoVolumeAssembly* AliITSv11GeometrySPD::CreateMCM
1745 (Bool_t isRight, TArrayD &sizes, TGeoManager *mgr) const
1746 {
1747         // Assemblies all the components of the MCM and builds it as an 
1748         // assembly, because its large thickness could cause inexistent 
1749         // overlaps if all components were put into a true TGeoBBox.
1750         // This assembly contains:
1751         //  - a layer of glue which has the same size of the MCM itself, 
1752         //     and it the lowest part
1753         //  - the thin part of the MCM
1754         //  - the chips on the MCM, according to the specifications from EDMS
1755         //  - the cover which is superimposed to the part of the MCM with the chips
1756         // ---
1757         // Even if this is an assembly, the placement of objects is made in 
1758         // such a way that they are virtually contained in an imaginary box 
1759         // whose center is placed exactly in the middle of the occupied space
1760         // in all directions. This will ease the positioning of this object 
1761         // in the final stave. The sizes of this virtual box are stored in 
1762         // the array passed by reference.
1763         // ---
1764         // Arguments:
1765         //  - a boolean flag to know if this is the left or right MCM, when 
1766         //    looking at the stave from above (i.e. the direction from which 
1767         //    one sees bus over ladders over grounding foil) and keeping the 
1768         //    upper border continuous.
1769         //  - an array passed by reference which will contain the size of a 
1770         //    virtual box containing all this stuff
1771         //  - a pointer to the used TGeoManager.
1772         // to avoid strange behaviour of the geometry manager,
1773         // create a suffix to be used in the names of all shapes
1774         char suf[5];
1775         if (isRight) strcpy(suf, "R"); else strcpy(suf, "L");   
1776         // ** MEDIA **
1777         TGeoMedium *medBase = GetMedium("SPD KAPTON(POLYCH2)$",mgr);// ??? MCM BASE
1778         TGeoMedium *medGlue = GetMedium("EPOXY$",mgr);   // ??? GlueMCM
1779         TGeoMedium *medChip = GetMedium("SPD SI CHIP$",mgr);
1780         TGeoMedium *medCap  = GetMedium("AL$",mgr);
1781         // The shape of the MCM is divided into 3 sectors with different 
1782         // widths (Y) and lengths (X), like in this sketch:
1783         //
1784         //   0                      1                                   2 
1785         //    +---------------------+-----------------------------------+
1786         //    |                                    4       sect 2       |
1787         //    |                    6      sect 1    /-------------------+
1788         //    |      sect 0         /--------------/                    3
1789         //    +--------------------/               5
1790         //   8                     7
1791         //
1792         // the inclination of all oblique borders (6-7, 4-5) is always 45 degrees.
1793         // From drawings we can parametrize the dimensions of all these sectors,
1794         // then the shape of this part of the MCM is implemented as a 
1795         // TGeoXtru centerd in the virtual XY space. Since this shape 
1796         // is used twice (to define the MCM itself and the glue below it), 
1797         // we need to define two different shapes with different thicknesses 
1798         // and, since we place them in an assembly, we displace them 
1799         // directly in the right place with respect to the local Z axis 
1800         // (which is in the direction of thickness). The first step is 
1801         // definig the relevant sizes of this shape:
1802         Int_t i, j;
1803         Double_t mcmThickness  = fgkmm * 0.35;
1804         Double_t glueThickness = fAlignmentGap;
1805         Double_t sizeXtot = fgkmm * 105.6;   // total distance 0-2
1806         // resp. 7-8, 5-6 and 3-4
1807         Double_t sizeXsector[3] = {fgkmm * 28.4, fgkmm * 41.4, fgkmm * 28.8};
1808         // resp. 0-8, 1-6 and 2-3
1809         Double_t sizeYsector[3] = {fgkmm * 15.0, fgkmm * 11.0, fgkmm *  8.0};
1810         Double_t sizeSep01 = fgkmm * 4.0;      // x(6)-x(7)
1811         Double_t sizeSep12 = fgkmm * 3.0;      // x(4)-x(5)
1812         // define sizes of chips (last is the thickest)
1813         Double_t chipLength[5]     = { 4.00, 6.15, 3.85, 5.60, 18.00 };
1814         Double_t chipWidth[5]      = { 3.00, 4.10, 3.85, 5.60,  5.45 };
1815         Double_t chipThickness[5]  = { 0.60, 0.30, 0.30, 1.00,  1.20 };
1816         TString  name[5];
1817         name[0] = "ANALOG";
1818         name[1] = "PILOT";
1819         name[2] = "GOL";
1820         name[3] = "RX40";
1821         name[4] = "OPTICAL";
1822         Color_t color[5] = { kCyan, kGreen, kYellow, kBlue, kOrange };
1823
1824         // define the sizes of the cover
1825         Double_t capThickness = fgkmm * 0.3;
1826         Double_t capHeight = fgkmm * 1.7;
1827         // compute the total size of the virtual container box
1828         Double_t &thickness = sizes[0];
1829         Double_t &length = sizes[1];
1830         Double_t &width = sizes[2];
1831         length = sizeXtot;
1832         width = sizeYsector[0];
1833         thickness = glueThickness + mcmThickness + capHeight;
1834         // define all the relevant vertices of the polygon 
1835         // which defines the transverse shape of the MCM.
1836         // These values are used to several purposes, and 
1837         // for each one, some points must be excluded
1838         Double_t xRef[9], yRef[9];
1839         xRef[0] = -0.5*sizeXtot;
1840         yRef[0] =  0.5*sizeYsector[0];
1841         xRef[1] =  xRef[0] + sizeXsector[0] + sizeSep01;
1842         yRef[1] =  yRef[0];
1843         xRef[2] = -xRef[0];
1844         yRef[2] =  yRef[0];
1845         xRef[3] =  xRef[2];
1846         yRef[3] =  yRef[2] - sizeYsector[2];
1847         xRef[4] =  xRef[3] - sizeXsector[2];
1848         yRef[4] =  yRef[3];
1849         xRef[5] =  xRef[4] - sizeSep12;
1850         yRef[5] =  yRef[4] - sizeSep12;
1851         xRef[6] =  xRef[5] - sizeXsector[1];
1852         yRef[6] =  yRef[5];
1853         xRef[7] =  xRef[6] - sizeSep01;
1854         yRef[7] =  yRef[6] - sizeSep01;
1855         xRef[8] =  xRef[0];
1856         yRef[8] = -yRef[0];
1857         // the above points are defined for the "right" MCM (if ve view the 
1858         // stave from above) in order to change to the "left" one, we must 
1859         // change the sign to all X values:
1860         if (isRight) for (i = 0; i < 9; i++) xRef[i] = -xRef[i];
1861         // the shape of the MCM and glue layer are done excluding point 1, 
1862         // which is not necessary and cause the geometry builder to get confused
1863         j = 0;
1864         Double_t xBase[8], yBase[8];
1865         for (i = 0; i < 9; i++) {
1866                 if (i == 1) continue;
1867                 xBase[j] = xRef[i];
1868                 yBase[j] = yRef[i];
1869                 j++;
1870         } // end for i
1871         
1872         // the MCM cover is superimposed over the sectors 1 and 2 only
1873         Double_t xCap[6], yCap[6];
1874         j = 0;
1875         for (i = 1; i <= 6; i++) {
1876                 xCap[j] = xRef[i];
1877                 yCap[j] = yRef[i];
1878                 j++;
1879         } // end for i
1880         
1881         // define positions of chips, 
1882         // which must be added to the bottom-left corner of MCM
1883         // and divided by 1E4;
1884         Double_t chipX[5], chipY[5];
1885         if (isRight) {
1886                 chipX[0] = 666320.;
1887                 chipX[1] = 508320.;
1888                 chipX[2] = 381320.;
1889                 chipX[3] = 295320.;
1890                 chipX[4] = 150320.;
1891                 chipY[0] =  23750.;
1892                 chipY[1] =  27750.;
1893                 chipY[2] =  20750.;
1894                 chipY[3] =  42750.;
1895                 chipY[4] =  39750.;
1896         } else {
1897                 chipX[0] = 389730.;
1898                 chipX[1] = 548630.;
1899                 chipX[2] = 674930.;
1900                 chipX[3] = 761430.;
1901                 chipX[4] = 905430.;
1902                 chipY[0] =  96250.;
1903                 chipY[1] =  91950.;
1904                 chipY[2] =  99250.;
1905                 chipY[3] = 107250.;
1906                 chipY[4] = 109750.;
1907         } // end for isRight
1908         for (i = 0; i < 5; i++) {
1909                 chipX[i] *= 0.00001;
1910                 chipY[i] *= 0.00001;
1911                 if (isRight) {
1912                         chipX[i] += xRef[3];
1913                         chipY[i] += yRef[3];
1914                 } else {
1915                         chipX[i] += xRef[8];
1916                         chipY[i] += yRef[8];
1917                 } // end for isRight
1918                 chipLength[i] *= fgkmm;
1919                 chipWidth[i] *= fgkmm;
1920                 chipThickness[i] *= fgkmm;
1921         } // end for i
1922         // create shapes for MCM 
1923         Double_t z1, z2;
1924         TGeoXtru *shBase = new TGeoXtru(2);
1925         TGeoXtru *shGlue = new TGeoXtru(2);
1926         z1 = -0.5*thickness;
1927         z2 =  z1 + glueThickness;
1928         shGlue->DefinePolygon(8, xBase, yBase);
1929         shGlue->DefineSection(0, z1, 0., 0., 1.0);
1930         shGlue->DefineSection(1, z2, 0., 0., 1.0);
1931         z1 = z2;
1932         z2 = z1 + mcmThickness;
1933         shBase->DefinePolygon(8, xBase, yBase);
1934         shBase->DefineSection(0, z1, 0., 0., 1.0);
1935         shBase->DefineSection(1, z2, 0., 0., 1.0);
1936         
1937         // create volumes of MCM
1938         TGeoVolume *volBase = new TGeoVolume("BASE", shBase, medBase);
1939         volBase->SetLineColor(kRed);
1940         TGeoVolume *volGlue = new TGeoVolume("GLUE", shGlue, medGlue);
1941         volGlue->SetLineColor(kYellow + 1);
1942         
1943         // to create the border of the MCM cover, it is required the 
1944         // subtraction of two shapes the outer is created using the 
1945         // reference points defined here
1946         TGeoXtru *shCapOut = new TGeoXtru(2);
1947         shCapOut->SetName(Form("SHCAPOUT%s", suf));
1948         z1 = z2;
1949         z2 = z1 + capHeight - capThickness;
1950         shCapOut->DefinePolygon(6, xCap, yCap);
1951         shCapOut->DefineSection(0, z1, 0., 0., 1.0);
1952         shCapOut->DefineSection(1, z2, 0., 0., 1.0);
1953         // the inner is built similarly but subtracting the thickness
1954         Double_t angle, cs;
1955         Double_t xin[6], yin[6];
1956         if (!isRight) {
1957                 angle = 45.0;
1958                 cs = TMath::Cos( 0.5*(TMath::Pi() - angle*TMath::DegToRad()) );
1959                 xin[0] = xCap[0] + capThickness;
1960                 yin[0] = yCap[0] - capThickness;
1961                 xin[1] = xCap[1] - capThickness;
1962                 yin[1] = yin[0];
1963                 xin[2] = xin[1];
1964                 yin[2] = yCap[2] + capThickness;
1965                 xin[3] = xCap[3] - capThickness*cs;
1966                 yin[3] = yin[2];
1967                 xin[4] = xin[3] - sizeSep12;
1968                 yin[4] = yCap[4] + capThickness;
1969                 xin[5] = xin[0];
1970                 yin[5] = yin[4];
1971         } else {
1972                 angle = 45.0;
1973                 cs = TMath::Cos( 0.5*(TMath::Pi() - angle*TMath::DegToRad()) );
1974                 xin[0] = xCap[0] - capThickness;
1975                 yin[0] = yCap[0] - capThickness;
1976                 xin[1] = xCap[1] + capThickness;
1977                 yin[1] = yin[0];
1978                 xin[2] = xin[1];
1979                 yin[2] = yCap[2] + capThickness;
1980                 xin[3] = xCap[3] - capThickness*cs;
1981                 yin[3] = yin[2];
1982                 xin[4] = xin[3] + sizeSep12;
1983                 yin[4] = yCap[4] + capThickness;
1984                 xin[5] = xin[0];
1985                 yin[5] = yin[4];
1986         } // end if isRight
1987         TGeoXtru *shCapIn = new TGeoXtru(2);
1988         shCapIn->SetName(Form("SHCAPIN%s", suf));
1989         shCapIn->DefinePolygon(6, xin, yin);
1990         shCapIn->DefineSection(0, z1 - 0.01, 0., 0., 1.0);
1991         shCapIn->DefineSection(1, z2 + 0.01, 0., 0., 1.0);
1992         // compose shapes
1993         TGeoCompositeShape *shCapBorder = new TGeoCompositeShape(
1994                                                                                                                          Form("SHBORDER%s", suf), 
1995                                                                                                                          Form("%s-%s", shCapOut->GetName(),
1996                                                                                                                                   shCapIn->GetName()));
1997         // create volume
1998         TGeoVolume *volCapBorder = new TGeoVolume("CAPBORDER",shCapBorder,medCap);
1999         volCapBorder->SetLineColor(kGreen);
2000         // finally, we create the top of the cover, which has the same 
2001         // shape of outer border and a thickness equal of the one othe 
2002         // cover border one
2003         TGeoXtru *shCapTop = new TGeoXtru(2);
2004         z1 = z2;
2005         z2 = z1 + capThickness;
2006         shCapTop->DefinePolygon(6, xCap, yCap);
2007         shCapTop->DefineSection(0, z1, 0., 0., 1.0);
2008         shCapTop->DefineSection(1, z2, 0., 0., 1.0);
2009         TGeoVolume *volCapTop = new TGeoVolume("CAPTOP", shCapTop, medCap);
2010         volCapTop->SetLineColor(kBlue);
2011         
2012         // create container assembly
2013         TGeoVolumeAssembly *mcmAssembly = new TGeoVolumeAssembly("MCM");
2014         
2015         // add objects in the assembly
2016         
2017         // glue
2018         mcmAssembly->AddNode(volGlue, 0, gGeoIdentity);
2019         // mcm layer
2020         mcmAssembly->AddNode(volBase, 0, gGeoIdentity);
2021         // chips
2022         for (i = 0; i < 5; i++) {
2023                 TGeoVolume *box = gGeoManager->MakeBox(name[i], medChip, 
2024                                                                                            0.5*chipLength[i], 0.5*chipWidth[i], 0.5*chipThickness[i]);
2025                 TGeoTranslation *tr = new TGeoTranslation(chipX[i], chipY[i],
2026                                                                                                   0.5*(-thickness + chipThickness[i]) + mcmThickness +
2027                                                                                                   glueThickness);
2028                 box->SetLineColor(color[i]);
2029                 mcmAssembly->AddNode(box, 0, tr);
2030         } // end for i
2031         // cap border
2032         mcmAssembly->AddNode(volCapBorder, 0, gGeoIdentity);
2033         // cap top
2034         mcmAssembly->AddNode(volCapTop, 0, gGeoIdentity);       
2035         return mcmAssembly;
2036 }
2037 //
2038 //__________________________________________________________________________________________
2039 TGeoVolumeAssembly* AliITSv11GeometrySPD::CreatePixelBus
2040 (Bool_t isRight, TArrayD &sizes, TGeoManager *mgr) const
2041 {
2042         //
2043         // The pixel bus is implemented as a TGeoBBox with some objects on it, 
2044         // which could affect the particle energy loss.
2045         // ---
2046         // In order to avoid confusion, the bus is directly displaced 
2047         // according to the axis orientations which are used in the final stave:
2048         // X --> thickness direction
2049         // Y --> width direction
2050         // Z --> length direction
2051         //
2052   
2053         
2054         // ** MEDIA **
2055         
2056         //PIXEL BUS
2057         TGeoMedium *medBus     = GetMedium("SPDBUS(AL+KPT+EPOX)$",mgr);
2058         TGeoMedium *medPt1000  = GetMedium("CERAMICS$",mgr); // ??? PT1000
2059         // Capacity
2060         TGeoMedium *medCap     = GetMedium("SDD X7R capacitors$",mgr);
2061         // ??? Resistance
2062         TGeoMedium *medRes     = GetMedium("SDD X7R capacitors$",mgr); 
2063         // ** SIZES & POSITIONS **
2064         Double_t busLength          = 170.501 * fgkmm; // length of plane part
2065         Double_t busWidth           =  13.800 * fgkmm; // width
2066         Double_t busThickness       =   0.280 * fgkmm; // thickness
2067         Double_t pt1000Length       = fgkmm * 1.50;
2068         Double_t pt1000Width        = fgkmm * 3.10;
2069         Double_t pt1000Thickness    = fgkmm * 0.60;
2070         Double_t pt1000Y, pt1000Z[10];// position of the pt1000's along the bus
2071         Double_t capLength          = fgkmm * 2.55;
2072         Double_t capWidth           = fgkmm * 1.50;
2073         Double_t capThickness       = fgkmm * 1.35;
2074         Double_t capY[2], capZ[2];
2075         
2076         Double_t resLength          = fgkmm * 2.20;
2077         Double_t resWidth           = fgkmm * 0.80;
2078         Double_t resThickness       = fgkmm * 0.35;
2079         Double_t resY[2], resZ[2];
2080                         
2081         // position of pt1000, resistors and capacitors depends on the 
2082         // bus if it's left or right one
2083         if (!isRight) {
2084                 pt1000Y    =   64400.;
2085                 pt1000Z[0] =   66160.;
2086                 pt1000Z[1] =  206200.;
2087                 pt1000Z[2] =  346200.;
2088                 pt1000Z[3] =  486200.;
2089                 pt1000Z[4] =  626200.;
2090                 pt1000Z[5] =  776200.;
2091                 pt1000Z[6] =  916200.;
2092                 pt1000Z[7] = 1056200.;
2093                 pt1000Z[8] = 1196200.;
2094                 pt1000Z[9] = 1336200.;  
2095                 resZ[0]    = 1397500.;
2096                 resY[0]    =   26900.;
2097                 resZ[1]    =  682500.;
2098                 resY[1]    =   27800.;
2099                 capZ[0]    = 1395700.;
2100                 capY[0]    =   45700.;
2101                 capZ[1]    =  692600.;
2102                 capY[1]    =   45400.;
2103         } else {
2104                 pt1000Y    =   66100.;
2105                 pt1000Z[0] =  319700.;
2106                 pt1000Z[1] =  459700.;
2107                 pt1000Z[2] =  599700.;
2108                 pt1000Z[3] =  739700.;
2109                 pt1000Z[4] =  879700.;
2110                 pt1000Z[5] = 1029700.;
2111                 pt1000Z[6] = 1169700.;
2112                 pt1000Z[7] = 1309700.;
2113                 pt1000Z[8] = 1449700.;
2114                 pt1000Z[9] = 1589700.;  
2115                 capY[0]    =   44500.;
2116                 capZ[0]    =  266700.;
2117                 capY[1]    =   44300.;
2118                 capZ[1]    =  974700.;
2119                 resZ[0]    =  266500.;
2120                 resY[0]    =   29200.;
2121                 resZ[1]    =  974600.;
2122                 resY[1]    =   29900.;
2123         } // end if isRight
2124         Int_t i;
2125         pt1000Y *= 1E-4 * fgkmm;
2126         for (i = 0; i < 10; i++) {
2127                 pt1000Z[i] *= 1E-4 * fgkmm;
2128                 if (i < 2) {
2129                         capZ[i] *= 1E-4 * fgkmm;
2130                         capY[i] *= 1E-4 * fgkmm;
2131                         resZ[i] *= 1E-4 * fgkmm;
2132                         resY[i] *= 1E-4 * fgkmm;
2133                 }  // end if iM2
2134         } // end for i
2135         
2136         Double_t &fullLength = sizes[1];
2137         Double_t &fullWidth = sizes[2];
2138         Double_t &fullThickness = sizes[0];
2139         fullLength = busLength;
2140         fullWidth = busWidth;
2141         // add the thickness of the thickest component on bus (capacity)
2142         fullThickness = busThickness + capThickness; 
2143         // ** VOLUMES **
2144         TGeoVolumeAssembly *container = new TGeoVolumeAssembly("PixelBus");
2145         TGeoVolume *bus = mgr->MakeBox("Bus", medBus, 0.5*busThickness, 
2146                                                                    0.5*busWidth, 0.5*busLength);
2147         TGeoVolume *pt1000 = mgr->MakeBox("PT1000", medPt1000, 
2148                                                                           0.5*pt1000Thickness, 0.5*pt1000Width, 0.5*pt1000Length);
2149         TGeoVolume *res = mgr->MakeBox("Resistor", medRes, 0.5*resThickness,
2150                                                                    0.5*resWidth, 0.5*resLength);
2151         TGeoVolume *cap = mgr->MakeBox("Capacitor", medCap, 0.5*capThickness,
2152                                                                    0.5*capWidth, 0.5*capLength);
2153         bus->SetLineColor(kYellow + 2);
2154         pt1000->SetLineColor(kGreen + 3);
2155         res->SetLineColor(kRed + 1);
2156         cap->SetLineColor(kBlue - 7);
2157         // ** MOVEMENTS AND POSITIONEMENT **
2158         // bus
2159         TGeoTranslation *trBus = new TGeoTranslation(0.5 * (busThickness - 
2160                                                                                                                 fullThickness), 0.0, 0.0);
2161         container->AddNode(bus, 0, trBus);
2162         Double_t zRef, yRef, x, y, z;
2163         if (isRight) {
2164                 zRef = -0.5*fullLength;
2165                 yRef = -0.5*fullWidth;
2166         } else {
2167                 zRef = -0.5*fullLength;
2168                 yRef = -0.5*fullWidth;
2169         } // end if isRight
2170         // pt1000
2171         x = 0.5*(pt1000Thickness - fullThickness) + busThickness;
2172         for (i = 0; i < 10; i++) {
2173                 y = yRef + pt1000Y;
2174                 z = zRef + pt1000Z[i];
2175                 TGeoTranslation *tr = new TGeoTranslation(x, y, z);
2176                 container->AddNode(pt1000, i, tr);
2177         } // end for i
2178         // capacitors
2179         x = 0.5*(capThickness - fullThickness) + busThickness;
2180         for (i = 0; i < 2; i++) {
2181                 y = yRef + capY[i];
2182                 z = zRef + capZ[i];
2183                 TGeoTranslation *tr = new TGeoTranslation(x, y, z);
2184                 container->AddNode(cap, i, tr);
2185         } // end for i
2186         // resistors
2187         x = 0.5*(resThickness - fullThickness) + busThickness;
2188         for (i = 0; i < 2; i++) {
2189                 y = yRef + resY[i];
2190                 z = zRef + resZ[i];
2191                 TGeoTranslation *tr = new TGeoTranslation(x, y, z);
2192                 container->AddNode(res, i, tr);
2193         } // end for i
2194         
2195         sizes[3] = yRef + pt1000Y;
2196         sizes[4] = zRef + pt1000Z[2];
2197         sizes[5] = zRef + pt1000Z[7];
2198         
2199         return container;
2200 }
2201 //
2202 //__________________________________________________________________________________________
2203 TGeoVolume* AliITSv11GeometrySPD::CreateExtender
2204 (const Double_t *extenderParams, const TGeoMedium *extenderMedium, TArrayD& sizes) const
2205 {
2206         // ------------------   CREATE AN EXTENDER    ------------------------
2207         // 
2208         // This function creates the following picture (in plane xOy)                          
2209         // Should be useful for the definition of the pixel bus and MCM extenders              
2210         // The origin corresponds to point 0 on the picture, at half-width in Z direction      
2211         //                                                                                     
2212         //   Y                         7     6                      5                          
2213         //   ^                           +---+---------------------+                           
2214         //   |                          /                          |                           
2215         //   |                         /                           |                           
2216         //   0------> X               /      +---------------------+                           
2217         //                           /      / 3                     4                          
2218         //                          /      /                                                   
2219         //            9          8 /      /                                                    
2220         //            +-----------+      /                                                     
2221         //            |                 /                                                      
2222         //            |                /                                                       
2223         //      --->  +-----------+---+                                                        
2224         //      |     0          1     2                                                       
2225         //      |                                                                              
2226         //  origin (0,0,0)                                                                     
2227         //                                                                                     
2228         //                                                                                     
2229         // Takes 6 parameters in the following order :                                         
2230         //   |--> par 0 : inner length [0-1] / [9-8]                                           
2231         //   |--> par 1 : thickness ( = [0-9] / [4-5])                                         
2232         //   |--> par 2 : angle of the slope                                                   
2233         //   |--> par 3 : total height in local Y direction                                    
2234         //   |--> par 4 : outer length [3-4] / [6-5]                                           
2235         //   |--> par 5 : width in local Z direction                                           
2236         //                                                                                     
2237
2238
2239         Double_t slopeDeltaX = (extenderParams[3] - extenderParams[1] * TMath::Cos(extenderParams[2])) / TMath::Tan(extenderParams[2]);
2240
2241         Double_t extenderXtruX[10] = {
2242                 0 ,
2243                 extenderParams[0] ,
2244                 extenderParams[0] + extenderParams[1] * TMath::Sin(extenderParams[2]) , 
2245                 extenderParams[0] + extenderParams[1] * TMath::Sin(extenderParams[2]) + slopeDeltaX ,
2246                 extenderParams[0] + extenderParams[1] * TMath::Sin(extenderParams[2]) + slopeDeltaX + extenderParams[4], 
2247                 extenderParams[0] + extenderParams[1] * TMath::Sin(extenderParams[2]) + slopeDeltaX + extenderParams[4], 
2248                 extenderParams[0] + extenderParams[1] * TMath::Sin(extenderParams[2]) + slopeDeltaX , 
2249                 extenderParams[0] + extenderParams[1] * TMath::Sin(extenderParams[2]) + slopeDeltaX - extenderParams[1] * TMath::Sin(extenderParams[2]) ,
2250                 extenderParams[0] ,
2251                 0
2252         } ;
2253
2254         Double_t extenderXtruY[10] = {
2255                 0 ,
2256                 0 ,
2257                 extenderParams[1] * (1-TMath::Cos(extenderParams[2])) ,
2258                 extenderParams[3] - extenderParams[1] ,
2259                 extenderParams[3] - extenderParams[1] ,
2260                 extenderParams[3] ,
2261                 extenderParams[3] ,
2262                 extenderParams[3] - extenderParams[1] * (1-TMath::Cos(extenderParams[2])) ,
2263                 extenderParams[1] ,
2264                 extenderParams[1]
2265         } ;
2266
2267         if (sizes.GetSize() != 3) sizes.Set(3);
2268         Double_t &thickness = sizes[0] ;
2269         Double_t &length    = sizes[1] ;
2270         Double_t &width     = sizes[2] ;
2271
2272         thickness = extenderParams[3] ;
2273         width     = extenderParams[5] ;
2274         length    = extenderParams[0] + extenderParams[1] * TMath::Sin(extenderParams[2]) + slopeDeltaX + extenderParams[4] ;
2275
2276         // creation of the volume
2277         TGeoXtru   *extenderXtru    = new TGeoXtru(2);
2278         TGeoVolume *extenderXtruVol = new TGeoVolume("EXTENDER",extenderXtru,extenderMedium) ;
2279         extenderXtru->DefinePolygon(10,extenderXtruX,extenderXtruY);
2280         extenderXtru->DefineSection(0,-0.5*extenderParams[4]);
2281         extenderXtru->DefineSection(1, 0.5*extenderParams[4]);
2282         return extenderXtruVol ;
2283 }
2284
2285 //______________________________________________________________________
2286 TGeoVolumeAssembly* AliITSv11GeometrySPD::CreatePixelBusAndExtensions
2287 (Bool_t /*zpos*/, TGeoManager *mgr) const
2288 {
2289         //
2290         // Creates an assembly which contains the pixel bus and its extension
2291         // and the extension of the MCM.
2292         // By: Renaud Vernet
2293         // NOTE: to be defined its material and its extension in the outside direction
2294         //
2295   
2296         // ====   constants   =====
2297
2298         //get the media
2299         //TGeoMedium   *medPixelBus    = GetMedium("SPDBUS(AL+KPT+EPOX)$",mgr) ;  // ??? PIXEL BUS
2300         TGeoMedium   *medPBExtender  = GetMedium("SDDKAPTON (POLYCH2)$",mgr) ;  // ??? IXEL BUS EXTENDER
2301         TGeoMedium   *medMCMExtender = GetMedium("SDDKAPTON (POLYCH2)$",mgr) ;  // ??? MCM EXTENDER
2302         
2303         //   //geometrical constants
2304         const Double_t kPbextenderThickness     =   0.07 * fgkmm ;
2305         const Double_t kPbExtenderSlopeAngle    =  70.0  * TMath::Pi()/180. ; //design=?? 70 deg. seems OK
2306         const Double_t kPbExtenderHeight        =   1.92 * fgkmm ;            // = 2.6 - (0.28+0.05+0.35) cf design
2307         const Double_t kPbExtenderWidthY        =  11.0  * fgkmm ;
2308         const Double_t kMcmExtenderSlopeAngle   =  70.0  * TMath::Pi()/180. ; //design=?? 70 deg. seems OK
2309         const Double_t kMcmExtenderThickness    =   0.10 * fgkmm ;
2310         const Double_t kMcmExtenderHeight       =   1.8  * fgkmm ;
2311         const Double_t kMcmExtenderWidthY       =   kPbExtenderWidthY ;
2312         //   const Double_t groundingThickness    =   0.07  * fgkmm ;
2313         //   const Double_t grounding2pixelBusDz  =   0.625 * fgkmm ;
2314         //   const Double_t pixelBusThickness     =   0.28  * fgkmm ;
2315         //   const Double_t groundingWidthX       = 170.501 * fgkmm ;
2316         //   const Double_t pixelBusContactDx     =   1.099 * fgkmm ;
2317         //   const Double_t pixelBusWidthY        =  13.8   * fgkmm ;
2318         //   const Double_t pixelBusContactPhi    =  20.0   * TMath::Pi()/180. ; //design=20 deg.
2319         //   const Double_t pbExtenderTopZ        =   2.72  * fgkmm ;
2320         //   const Double_t mcmThickness          =   0.35  * fgkmm ;
2321         //   const Double_t halfStaveTotalLength  = 247.64  * fgkmm ;
2322         //   const Double_t deltaYOrigin          =  15.95/2.* fgkmm ;
2323         //   const Double_t deltaXOrigin          =   1.1    * fgkmm ;
2324         //   const Double_t deltaZOrigin          = halfStaveTotalLength / 2. ;
2325         //   const Double_t grounding2pixelBusDz2 = grounding2pixelBusDz+groundingThickness/2. + pixelBusThickness/2. ;
2326         //   const Double_t pixelBusWidthX        = groundingWidthX ;
2327         //   const Double_t pixelBusRaiseLength   = (pixelBusContactDx-pixelBusThickness*TMath::Sin(pixelBusContactPhi))/TMath::Cos(pixelBusContactPhi) ;
2328
2329         //   const Double_t pbExtenderBaseZ       = grounding2pixelBusDz2 + pixelBusRaiseLength*TMath::Sin(pixelBusContactPhi) + 2*pixelBusThickness*TMath::Sin(pixelBusContactPhi)*TMath::Tan(pixelBusContactPhi) ;
2330         //   const Double_t pbExtenderDeltaZ      = pbExtenderTopZ-pbExtenderBaseZ ;
2331         //   const Double_t pbExtenderEndPointX   = 2*deltaZOrigin - groundingWidthX - 2*pixelBusThickness*TMath::Sin(pixelBusContactPhi) ;
2332         //   const Double_t pbExtenderXtru3L   = 1.5 * fgkmm ; //arbitrary ?
2333         //   const Double_t pbExtenderXtru4L   = (pbExtenderDeltaZ + pixelBusThickness*(TMath::Cos(extenderSlope)-2))/TMath::Sin(extenderSlope) ;
2334
2335         //   const Double_t kMcmExtenderEndPointX  = deltaZOrigin - 48.2 * fgkmm ;
2336         //   const Double_t kMcmExtenderXtru3L     = 1.5  * fgkmm ;
2337
2338         //   //=====  end constants  =====
2339
2340
2341         const Double_t kPbExtenderInnerLength    = 10. * fgkmm ;
2342         const Double_t kPbExtenderOuterLength    = 15. * fgkmm ;
2343         const Double_t kMcmExtenderInnerLength   = 10. * fgkmm ;
2344         const Double_t kMcmExtenderOuterLength   = 15. * fgkmm ;
2345   
2346         Double_t pbExtenderParams[6]  = {kPbExtenderInnerLength,  //0
2347                                                                          kPbextenderThickness,    //1
2348                                                                          kPbExtenderSlopeAngle,   //2
2349                                                                          kPbExtenderHeight,       //3
2350                                                                          kPbExtenderOuterLength,  //4
2351                                                                          kPbExtenderWidthY};      //5
2352   
2353         Double_t mcmExtenderParams[6] = {kMcmExtenderInnerLength, //0
2354                                                                          kMcmExtenderThickness,   //1
2355                                                                          kMcmExtenderSlopeAngle,  //2
2356                                                                          kMcmExtenderHeight,      //3
2357                                                                          kMcmExtenderOuterLength, //4
2358                                                                          kMcmExtenderWidthY};     //5
2359
2360         TArrayD sizes(3);
2361         TGeoVolume* pbExtender  = CreateExtender(pbExtenderParams,  medPBExtender, sizes)  ;
2362         printf("CREATED AN EXTENDER : THICKNESS = %5.5f cm\tLENGTH=%5.5f cm\tWIDTH=%5.5f cm\n",sizes[0],sizes[1],sizes[2]);
2363         TGeoVolume* mcmExtender = CreateExtender(mcmExtenderParams, medMCMExtender, sizes) ;
2364         printf("CREATED AN EXTENDER : THICKNESS = %5.5f cm\tLENGTH=%5.5f cm\tWIDTH=%5.5f cm\n",sizes[0],sizes[1],sizes[2]);
2365
2366
2367
2368         //   Double_t pixelBusValues[5]    = {pixelBusWidthX,        //0
2369         //                                 pixelBusThickness,     //1
2370         //                                 pixelBusContactPhi,    //2
2371         //                                 pixelBusRaiseLength,   //3
2372         //                                 pixelBusWidthY} ;      //4
2373
2374         //   Double_t pbExtenderValues[8]  = {pixelBusRaiseLength,   //0
2375         //                                 pixelBusContactPhi,    //1
2376         //                                 pbExtenderXtru3L,      //2
2377         //                                 pixelBusThickness,     //3
2378         //                                 extenderSlope,         //4
2379         //                                 pbExtenderXtru4L,      //5
2380         //                                 pbExtenderEndPointX,   //6
2381         //                                 kPbExtenderWidthY} ;    //7
2382
2383         //   Double_t mcmExtenderValues[6] = {mcmExtenderXtru3L,     //0
2384         //                                 mcmExtenderThickness,  //1
2385         //                                 extenderSlope,         //2
2386         //                                 deltaMcmMcmExtender,   //3
2387         //                                 mcmExtenderEndPointX,  //4
2388         //                                 mcmExtenderWidthY};    //5
2389   
2390         //   TGeoVolumeAssembly *pixelBus = new TGeoVolumeAssembly("PIXEL BUS");
2391         //   CreatePixelBus(pixelBus,pixelBusValues,medPixelBus) ; 
2392         //   TGeoVolumeAssembly *pbExtender = new TGeoVolumeAssembly("PIXEL BUS EXTENDER");
2393         //   CreatePixelBusExtender(pbExtender,pbExtenderValues,medPBExtender) ;
2394         //   TGeoVolumeAssembly *mcmExtender = new TGeoVolumeAssembly("MCM EXTENDER");
2395         //   CreateMCMExtender(mcmExtender,mcmExtenderValues,medMCMExtender) ;
2396   
2397         //   //--------------   DEFINITION OF GEOMETRICAL TRANSFORMATIONS -------------------
2398         //   TGeoRotation    * commonRot       = new TGeoRotation("commonRot",0,90,0);
2399         //   commonRot->MultiplyBy(new TGeoRotation("rot",-90,0,0)) ;
2400         //   TGeoTranslation * pixelBusTrans   = new TGeoTranslation(pixelBusThickness/2. - deltaXOrigin + 0.52*fgkmm ,
2401         //                                                        -pixelBusWidthY/2.     + deltaYOrigin , 
2402         //                                                        -groundingWidthX/2.    + deltaZOrigin) ;
2403         //   TGeoRotation    * pixelBusRot     = new TGeoRotation(*commonRot);
2404         //   TGeoTranslation * pbExtenderTrans = new TGeoTranslation(*pixelBusTrans) ;
2405         //   TGeoRotation    * pbExtenderRot   = new TGeoRotation(*pixelBusRot) ;
2406         //   pbExtenderTrans->SetDz(*(pbExtenderTrans->GetTranslation()+2) - pixelBusWidthX/2. - 2*pixelBusThickness*TMath::Sin(pixelBusContactPhi)) ;  
2407         //   if (!zpos) {
2408         //     pbExtenderTrans->SetDy(*(pbExtenderTrans->GetTranslation()+1) - (pixelBusWidthY - kPbExtenderWidthY)/2.);
2409         //   }
2410         //   else {
2411         //     pbExtenderTrans->SetDy(*(pbExtenderTrans->GetTranslation()+1) + (pixelBusWidthY - kPbExtenderWidthY)/2.);
2412         //   }
2413         //   pbExtenderTrans->SetDx(*(pbExtenderTrans->GetTranslation()) + pixelBusThickness/2 + 2*pixelBusThickness*TMath::Sin(pixelBusContactPhi)*TMath::Tan(pixelBusContactPhi)) ;
2414         //   TGeoTranslation * mcmExtenderTrans = new TGeoTranslation(0.12*fgkmm + mcmThickness - deltaXOrigin,
2415         //                                                         pbExtenderTrans->GetTranslation()[1],
2416         //                                                         -4.82);
2417         //   TGeoRotation    * mcmExtenderRot   = new TGeoRotation(*pbExtenderRot);
2418   
2419         //   // add pt1000 components
2420         //   Double_t pt1000Z = fgkmm * 64400. * 1E-4;
2421         //   //Double_t pt1000X[10] = {319700., 459700., 599700., 739700., 879700., 1029700., 1169700., 1309700., 1449700., 1589700.};
2422         //   Double_t pt1000X[10] = {66160., 206200., 346200., 486200., 626200., 776200., 916200., 1056200., 1196200., 1336200.};
2423         //   Double_t pt1000size[3] = {fgkmm*1.5, fgkmm*0.6, fgkmm*3.1};
2424         //   Int_t i;
2425         //   for (i = 0; i < 10; i++) {
2426         //        pt1000X[i] *= fgkmm * 1E-4;
2427         //   }
2428         //   TGeoVolume *pt1000 = mgr->MakeBox("PT1000", 0, 0.5*pt1000size[0], 0.5*pt1000size[1], 0.5*pt1000size[2]);
2429         //   pt1000->SetLineColor(kGray);
2430         //   Double_t refThickness = - pixelBusThickness ;
2431         //   for (i = 0; i < 10; i++) {
2432         //        TGeoTranslation *tr = new TGeoTranslation(pt1000X[i]-0.5*pixelBusWidthX, 0.002+0.5*(-3.*refThickness+pt1000size[3]), pt1000Z -0.5*pixelBusWidthY);
2433         //        pixelBus->AddNode(pt1000, i, tr);
2434         //   }
2435   
2436         //CREATE FINAL VOLUME ASSEMBLY AND ROTATE IT
2437         TGeoVolumeAssembly *assembly = new TGeoVolumeAssembly("EXTENDERS");
2438         //   assembly->AddNode((TGeoVolume*)pixelBus    ,0, new TGeoCombiTrans(*pixelBusTrans,*pixelBusRot));
2439         //   assembly->AddNode((TGeoVolume*)pbExtender  ,0, new TGeoCombiTrans(*pbExtenderTrans,*pbExtenderRot));
2440         //   assembly->AddNode((TGeoVolume*)mcmExtender ,0, new TGeoCombiTrans(*mcmExtenderTrans,*mcmExtenderRot));
2441         //   assembly->AddNode(mcmExtender,0,new TGeoIdentity());
2442         assembly->AddNode(pbExtender,0);
2443         assembly->AddNode(mcmExtender,0);
2444         //   assembly->SetTransparency(50);
2445   
2446         return assembly ;
2447 }
2448 //
2449 //__________________________________________________________________________________________
2450 TGeoVolumeAssembly* AliITSv11GeometrySPD::CreateHalfStave
2451 (Bool_t isRight,
2452  Int_t layer, Int_t idxCentral, Int_t idxSide,
2453  TArrayD &sizes, Bool_t addClips, TGeoManager *mgr)
2454 {
2455         //
2456         // Implementation of an half-stave, which depends on the side where we are on the stave.
2457         // The convention for "left" and "right" is the same as for the MCM.
2458         // The return value is a TGeoAssembly which is structured in such a way that the origin
2459         // of its local reference frame coincides with the origin of the whole stave.
2460         //
2461         
2462         // ** CHECK **
2463         
2464         // idxCentral and idxSide must be different
2465         if (idxCentral == idxSide) {
2466                 AliInfo("Ladders must be inserted in half-stave with different indexes.");
2467                 idxSide = idxCentral + 1;
2468                 AliInfo(Form("Central ladder will be inserted with index %d", idxCentral));
2469                 AliInfo(Form("Side    ladder will be inserted with index %d", idxSide));
2470         }
2471                 
2472         // define the separations along Z direction between the objects
2473         Double_t sepLadderLadder = fgkmm * 0.2; // sep. btw the 2 ladders
2474         Double_t sepLadderCenter = fgkmm * 0.4; // sep. btw the "central" ladder and the Z=0 plane in stave ref.
2475         Double_t sepLadderMCM    = fgkmm * 0.3; // sep. btw the "external" ladder and MCM
2476         Double_t sepBusCenter    = fgkmm * 0.3; // sep. btw the bus central edge and the Z=0 plane in stave ref.
2477         
2478         // ** VOLUMES **
2479         
2480         // grounding foil
2481         TArrayD grndSize(3);
2482         // This one line repalces the 3 bellow, BNS.
2483         TGeoVolume *grndVol = CreateGroundingFoil(isRight,grndSize,mgr);
2484         //TGeoVolume *grndVol = 0;
2485         //if (isRight) grndVol = CreateGroundingFoil(kTRUE, grndSize, mgr);
2486         //else grndVol = CreateGroundingFoil(kFALSE, grndSize, mgr);
2487         Double_t &grndThickness = grndSize[0];
2488         Double_t &grndLength = grndSize[1];
2489         
2490         // ladder
2491         TArrayD ladderSize(3);
2492         TGeoVolume *ladder = CreateLadder(layer, ladderSize, mgr);
2493         Double_t ladderThickness = ladderSize[0];
2494         Double_t ladderLength = ladderSize[1];
2495         Double_t ladderWidth = ladderSize[2];
2496         
2497         // glue between ladders and pixel bus
2498         TGeoMedium *medLadGlue = GetMedium("EPOXY$", mgr); // ??? LadderBusGlue
2499         Double_t ladGlueThickness = fgkmm * 0.12 - fAlignmentGap;
2500         TGeoVolume *ladderGlue = mgr->MakeBox("LADDER_GLUE", medLadGlue, 0.5*ladGlueThickness, 0.5*ladderWidth, 0.5*ladderLength);
2501         ladderGlue->SetLineColor(kRed);
2502         
2503         // MCM
2504         TArrayD mcmSize(3);
2505         TGeoVolumeAssembly *mcm = CreateMCM(!isRight,mcmSize,mgr);
2506         //TGeoVolumeAssembly *mcm = 0;
2507         //if (isRight) mcm = CreateMCM(kFALSE, mcmSize, mgr);
2508         //else mcm = CreateMCM(kTRUE, mcmSize, mgr);
2509         Double_t mcmThickness = mcmSize[0];
2510         Double_t mcmLength = mcmSize[1];
2511         Double_t mcmWidth = mcmSize[2];
2512                 
2513         // bus
2514         TArrayD busSize(6);
2515         TGeoVolumeAssembly *bus = CreatePixelBus(isRight, busSize, mgr);
2516         //TGeoVolume *bus = 0;
2517         //if (isRight) bus = CreatePixelBus(kTRUE, busSize, mgr);
2518         //else bus = CreatePixelBus(kFALSE, busSize, mgr);
2519         Double_t busThickness = busSize[0];
2520         Double_t busLength = busSize[1];
2521         Double_t busWidth = busSize[2];
2522         
2523         // create references for the whole object, as usual
2524         if (sizes.GetSize() != 3) sizes.Set(3);
2525         Double_t &fullThickness = sizes[0];
2526         Double_t &fullLength = sizes[1];
2527         Double_t &fullWidth = sizes[2];
2528                 
2529         // compute the full size of the container
2530         fullLength    = sepLadderCenter + 2.0*ladderLength + sepLadderMCM + sepLadderLadder + mcmLength;
2531         fullWidth     = ladderWidth;
2532         fullThickness = grndThickness + fAlignmentGap + mcmThickness + busThickness;
2533         
2534         // ** MOVEMENTS **
2535         
2536         // grounding foil (shifted only along thickness)
2537         Double_t xGrnd = -0.5*fullThickness + 0.5*grndThickness;
2538         Double_t zGrnd = -0.5*grndLength;
2539         if (!isRight) zGrnd = -zGrnd;
2540         TGeoTranslation *grndTrans = new TGeoTranslation(xGrnd, 0.0, zGrnd);
2541         
2542         // ladders (translations along thickness and length)
2543         // layers must be sorted going from the one at largest Z to the one at smallest Z:
2544         // -|Zmax| ------> |Zmax|
2545         //      3   2   1   0
2546         // then, for layer 1 ladders they must be placed exactly this way, and in layer 2 at the opposite.
2547         // In order to remember the placements, we define as "inner" and "outer" ladder respectively
2548         // the one close to barrel center, and the one closer to MCM, respectively.
2549         Double_t xLad, zLadIn, zLadOut;
2550         xLad    = xGrnd + 0.5*(grndThickness + ladderThickness) + 0.01175 - fAlignmentGap;
2551         zLadIn  = -sepLadderCenter - 0.5*ladderLength;
2552         zLadOut = zLadIn - sepLadderLadder - ladderLength;
2553         if (!isRight) {
2554                 zLadIn = -zLadIn;
2555                 zLadOut = -zLadOut;
2556         }
2557         TGeoRotation *rotLad = new TGeoRotation(*gGeoIdentity);
2558         rotLad->RotateZ(90.0);
2559         rotLad->RotateY(180.0);
2560         Double_t sensWidth      = fgkmm * 12.800;
2561         Double_t chipWidth      = fgkmm * 15.950;
2562         Double_t guardRingWidth = fgkmm *  0.560;
2563         Double_t ladderShift = 0.5 * (chipWidth - sensWidth - 2.0*guardRingWidth);
2564         TGeoCombiTrans *trLadIn  = new TGeoCombiTrans(xLad, ladderShift, zLadIn, rotLad);
2565         TGeoCombiTrans *trLadOut = new TGeoCombiTrans(xLad, ladderShift, zLadOut, rotLad);
2566         
2567         // glue between ladders and pixel bus
2568         Double_t xLadGlue = xLad + 0.5*ladderThickness + fAlignmentGap - 0.5*ladGlueThickness;
2569         TGeoTranslation *trLadGlueIn = new TGeoTranslation(xLadGlue, 0.0, zLadIn);
2570         TGeoTranslation *trLadGlueOut = new TGeoTranslation(xLadGlue, 0.0, zLadOut);
2571                 
2572         // MCM (length and thickness direction, placing at same level as the ladder, which implies to
2573         // recompute the position of center, because ladder and MCM have NOT the same thickness)
2574         // the two copies of the MCM are placed at the same distance from the center, on both sides
2575         Double_t xMCM = xGrnd + 0.5*grndThickness + 0.5*mcmThickness + fAlignmentGap;
2576         Double_t yMCM = 0.5*(fullWidth - mcmWidth);
2577         Double_t zMCM = zLadOut - 0.5*ladderLength - 0.5*mcmLength - sepLadderMCM;
2578         if (!isRight) zMCM = zLadOut + 0.5*ladderLength + 0.5*mcmLength + sepLadderMCM;
2579         
2580         // create the correction rotations
2581         TGeoRotation *rotMCM = new TGeoRotation(*gGeoIdentity);
2582         rotMCM->RotateY(90.0);
2583         TGeoCombiTrans *trMCM = new TGeoCombiTrans(xMCM, yMCM, zMCM, rotMCM);
2584         
2585         // bus (length and thickness direction)
2586         Double_t xBus = xLad + 0.5*ladderThickness + 0.5*busThickness + fAlignmentGap + ladGlueThickness;
2587         Double_t yBus  = 0.5*(fullWidth - busWidth);
2588         Double_t zBus = -0.5*busLength - sepBusCenter;
2589         if (!isRight) zBus = -zBus;
2590         TGeoTranslation *trBus = new TGeoTranslation(xBus, yBus, zBus);
2591         
2592         // create the container
2593         TGeoVolumeAssembly *container = 0;
2594         if (idxCentral+idxSide==5) {
2595                 container = new TGeoVolumeAssembly("HALF-STAVE1");
2596         } else {
2597                 container = new TGeoVolumeAssembly("HALF-STAVE0");
2598         }
2599
2600         // add to container all objects
2601         container->AddNode(grndVol, 1, grndTrans);
2602         // ladders are inserted in different order to respect numbering scheme
2603         // which is inverted when going from outer to inner layer
2604         container->AddNode(ladder, idxCentral, trLadIn);
2605         container->AddNode(ladder, idxSide, trLadOut);
2606         container->AddNode(ladderGlue, 0, trLadGlueIn);
2607         container->AddNode(ladderGlue, 1, trLadGlueOut);
2608         container->AddNode(mcm, 0, trMCM);
2609         container->AddNode(bus, 0, trBus);
2610         
2611         if (addClips) {
2612         
2613         // ad clips if requested
2614                 // create clip volume
2615         TArrayD clipSize(3);
2616         TGeoVolume *clip = CreateClip(clipSize, mgr);
2617                 
2618         // define clip movements (width direction)
2619         TGeoRotation *rotClip = new TGeoRotation(*gGeoIdentity);
2620         rotClip->RotateZ(-90.0);
2621         rotClip->RotateX(180.0);
2622         Double_t x  = xBus + 0.5*busThickness;//clipSize[3] - clipSize[2];
2623         Double_t y  = 0.5 * (fullWidth - busWidth) - clipSize[6] - fgkmm*0.48;
2624         Double_t z1 = zBus + busSize[4];
2625         Double_t z2 = zBus + busSize[5];
2626         cout << z1 << ' ' << z2 << endl;
2627         TGeoCombiTrans *trClip1 = new TGeoCombiTrans(x, y, z1, rotClip);
2628         TGeoCombiTrans *trClip2 = new TGeoCombiTrans(x, y, z2, rotClip);
2629         container->AddNode(clip, 0, trClip1);
2630         container->AddNode(clip, 1, trClip2);
2631         }
2632         
2633         
2634         return container;
2635 }
2636 //
2637 //__________________________________________________________________________________________
2638 TGeoVolumeAssembly* AliITSv11GeometrySPD::CreateStave
2639 (Int_t layer,
2640                                                                                                           TArrayD &sizes, Bool_t addClips, TGeoManager *mgr) {
2641         // This method uses all other ones which create pieces of the stave
2642         // and assemblies everything together, in order to return the whole
2643         // stave implementation, which is returned as a TGeoVolumeAssembly,
2644         // due to the presence of some parts which could generate fake overlaps
2645         // when put on the sector.
2646         // This assembly contains, going from bottom to top in the thickness direction:
2647         //   - the complete grounding foil, defined by the "CreateGroundingFoil" method which
2648         //     already joins some glue and real groudning foil layers for the whole stave (left + right);
2649         //   - 4 ladders, which are sorted according to the ALICE numbering scheme, which depends
2650         //     on the layer we are building this stave for;
2651         //   - 2 MCMs (a left and a right one);
2652         //   - 2 pixel buses (a left and a right one);
2653         // ---
2654         // Arguments:
2655         //   - the layer number, which determines the displacement and naming of sensitive volumes
2656         //   - a TArrayD passed by reference which will contain the size of virtual box containing the stave
2657         //   - the TGeoManager
2658         //
2659         
2660         // create the container
2661         TGeoVolumeAssembly *container = new TGeoVolumeAssembly(Form("LAY%d_STAVE", layer));
2662         
2663         // define the indexes of the ladders in order to have the correct order
2664         // keeping in mind that the staves will be inserted as they are on layer 2, while
2665         // they are rotated around their local Y axis when inserted on layer 1, so in this case
2666         // they must be put in the "wrong" order to turn out to be right at the end
2667         // The convention is:   
2668         //   -|Zmax| ------> |Zmax|
2669         //      3   2   1   0
2670         // with respect to the "native" stave reference frame, "left" is in the positive Z
2671         // this leads the definition of these indexes:
2672
2673         Int_t idxCentralL, idxSideL, idxCentralR, idxSideR;
2674         if (layer == 1) {
2675                 idxSideL = 3;
2676                 idxCentralL = 2;
2677                 idxCentralR = 1;
2678                 idxSideR = 0;
2679         }
2680         else {
2681                 idxSideL = 0;
2682                 idxCentralL = 1;
2683                 idxCentralR = 2;
2684                 idxSideR = 3;
2685         }
2686                 
2687         // create the two half-staves
2688         TArrayD sizeL(3), sizeR(3);
2689         TGeoVolumeAssembly *hstaveL = CreateHalfStave(kFALSE, layer, idxCentralL, idxSideL, sizeL, addClips, mgr);
2690         TGeoVolumeAssembly *hstaveR = CreateHalfStave(kTRUE, layer, idxCentralR, idxSideR, sizeR, addClips, mgr);
2691         
2692         // copy the size to the stave's one
2693         sizes[0] = sizeL[0];
2694         sizes[1] = sizeR[1] + sizeL[1];
2695         sizes[2] = sizeL[2];
2696         
2697         // add to container all objects
2698         container->AddNode(hstaveL, 1);
2699         container->AddNode(hstaveR, 1);
2700         
2701         return container;
2702 }
2703 //
2704 //__________________________________________________________________________________________
2705 void AliITSv11GeometrySPD::SetAddStave(Bool_t *mask)
2706 {
2707         //
2708         // Define a mask which states qhich staves must be placed.
2709         // It is a string which must contain '0' or '1' depending if 
2710         // a stave must be placed or not.
2711         // Each place is referred to one of the staves, so the first 
2712         // six characters of the string will be checked.
2713         //
2714         
2715         Int_t i;
2716         for (i = 0; i < 6; i++) fAddStave[i] = mask[i];
2717 }
2718 //
2719 //__________________________________________________________________________________________
2720 void AliITSv11GeometrySPD::StavesInSector(TGeoVolume *moth, TGeoManager *mgr) {
2721         //
2722         // Unification of essentially two methods:
2723         // - the one which creates the sector structure
2724         // - the one which returns the complete stave
2725         // ---
2726         // For compatibility, this method requires the same arguments
2727         // asked by "CarbonFiberSector" method, which is recalled here.
2728         // Like this cited method, this one does not return any value,
2729         // but it inserts in the mother volume (argument 'moth') all the stuff
2730         // which composes the complete SPD sector.
2731         // ---
2732         // In the following, the stave numbering order used for arrays is the same as
2733         // defined in the GetSectorMountingPoints():
2734         //                         /5
2735         //                        /\/4
2736         //                      1\   \/3
2737         //                      0|___\/2
2738         // ---
2739         // Arguments: see description of "CarbonFiberSector" method.
2740         //
2741         
2742         Double_t shift[6];  // shift from the innermost position in the sector placement plane
2743                             // (where the stave edge is in the point where the rounded corner begins)
2744         
2745         shift[0] = fgkmm * -0.691;
2746         shift[1] = fgkmm *  1.300;
2747         shift[2] = fgkmm *  1.816;
2748         shift[3] = fgkmm * -0.610;
2749         shift[4] = fgkmm * -0.610;
2750         shift[5] = fgkmm * -0.610;
2751         
2752         // create stave volumes (different for layer 1 and 2)
2753         TArrayD staveSizes1(3), staveSizes2(3);
2754         Double_t &staveHeight = staveSizes1[2], &staveThickness = staveSizes1[0];
2755         TGeoVolume *stave1        = CreateStave(1, staveSizes1, kFALSE, mgr);
2756         TGeoVolume *stave2clips   = CreateStave(2, staveSizes2, kTRUE, mgr);
2757         TGeoVolume *stave2noclips = CreateStave(2, staveSizes2, kFALSE, mgr);
2758         
2759         Double_t xL, yL;      // leftmost edge of mounting point (XY projection)
2760         Double_t xR, yR;      // rightmost edge of mounting point (XY projection)
2761         Double_t xM, yM;      // middle point of the segment L-R
2762         Double_t dx, dy;      // (xL - xR) and (yL - yR)
2763         Double_t widthLR;     // width of the segment L-R
2764         Double_t angle;       // stave rotation angle in degrees
2765         Double_t diffWidth;   // difference between mounting plane width and stave width (smaller)
2766         Double_t xPos, yPos;  // final translation of the stave
2767         Double_t parMovement; // translation in the LR plane direction
2768         
2769         // loop on staves
2770         for (Int_t i = 0; i < 6; i++) {
2771                 // in debug mode, if this stave is not required, it is skipped
2772                 if (!fAddStave[i]) continue;
2773                 // retrieve reference points
2774                 GetSectorMountingPoints(i, xL, yL, xR, yR);
2775                 xM = 0.5 * (xL + xR);
2776                 yM = 0.5 * (yL + yR);
2777                 dx = xL - xR;
2778                 dy = yL - yR;
2779                 angle = TMath::ATan2(dy, dx);
2780                 widthLR = TMath::Sqrt(dx*dx + dy*dy);
2781                 diffWidth = 0.5*(widthLR - staveHeight);
2782                 // first, a movement along this plane must be done
2783                 // by an amount equal to the width difference
2784                 // and then the fixed shift must also be added
2785                 parMovement = diffWidth + shift[i];
2786                 // due to stave thickness, another movement must be done 
2787                 // in the direction normal to the mounting plane
2788                 // which is computed using an internal method, in a reference frame where the LR segment
2789                 // has its middle point in the origin and axes parallel to the master reference frame
2790                 if (i == 0) {
2791                         ParallelPosition(-0.5*staveThickness, -parMovement, angle, xPos, yPos);
2792                 }
2793                 if (i == 1) {
2794                         ParallelPosition( 0.5*staveThickness, -parMovement, angle, xPos, yPos);
2795                 }
2796                 else {
2797                         ParallelPosition( 0.5*staveThickness,  parMovement, angle, xPos, yPos);
2798                 }
2799                 // then we go into the true reference frame
2800                 xPos += xM;
2801                 yPos += yM;
2802                 // using the parameters found here, compute the 
2803                 // translation and rotation of this stave:
2804                 TGeoRotation *rot = new TGeoRotation(*gGeoIdentity);
2805                 if (i == 0 || i == 1) rot->RotateX(180.0);
2806                 rot->RotateZ(90.0 + angle * TMath::RadToDeg());
2807                 TGeoCombiTrans *trans = new TGeoCombiTrans(xPos, yPos, 0.0, rot);
2808                 if (i == 0 || i == 1) {
2809                         moth->AddNode(stave1, i, trans);
2810                 }
2811                 else {
2812                         if (i == 2) {
2813                                 moth->AddNode(stave2noclips, i, trans);
2814                         }
2815                         else {
2816                                 moth->AddNode(stave2clips, i, trans);
2817                         }
2818                 }
2819         }
2820 }
2821 //
2822 //__________________________________________________________________________________________
2823 void AliITSv11GeometrySPD::ParallelPosition(Double_t dist1, Double_t dist2,
2824                                                                                         Double_t phi, Double_t &x, Double_t &y) const {
2825         // Performs the following steps:
2826         // 1 - finds a straight line parallel to the one passing through the origin and with angle 'phi' with X axis
2827         //     (phi in RADIANS);
2828         // 2 - finds another line parallel to the previous one, with a distance 'dist1' from it
2829         // 3 - takes a reference point in the second line in the intersection between the normal to both lines 
2830         //     passing through the origin
2831         // 4 - finds a point whith has distance 'dist2' from this reference, in the second line (point 2)
2832         // ----
2833         // According to the signs given to dist1 and dist2, the point is found in different position w.r. to the origin
2834         //
2835         
2836         // compute the point
2837         Double_t cs = TMath::Cos(phi);
2838         Double_t sn = TMath::Sin(phi);
2839         
2840         x = dist2*cs - dist1*sn;
2841         y = dist1*cs + dist2*sn;
2842 }
2843 //
2844 //__________________________________________________________________________________________
2845 void AliITSv11GeometrySPD::CreateFigure0(const Char_t *filepath,
2846                                          const Char_t *type,
2847                                                                                  TGeoManager *mgr) const {
2848     // Creates Figure 0 for the documentation of this class. In this
2849     // specific case, it creates the X,Y cross section of the SPD suport
2850     // section, center and ends. The output is written to a standard
2851     // file name to the path specificed.
2852     // Inputs:
2853     //   const Char_t *filepath  Path where the figure is to be drawn
2854     //   const Char_t *type      The type of file, default is gif.
2855     //   TGeoManager  *mgr       The TGeoManager default gGeoManager
2856     // Output:
2857     //   none.
2858     // Return:
2859     //   none.
2860     TGeoXtru *sA0,*sA1,*sB0,*sB1;
2861     //TPolyMarker *pmA,*pmB;
2862     TPolyLine plA0,plA1,plB0,plB1;
2863     TCanvas *canvas;
2864     TLatex txt;
2865     Double_t x=0.0,y=0.0;
2866     Int_t i,kNRadii=6;
2867
2868     if(strcmp(filepath,"")){
2869         Error("CreateFigure0","filepath=%s type=%s",filepath,type);
2870     } // end if
2871     //
2872     sA0 = (TGeoXtru*) mgr->GetVolume(
2873                                                                          "ITSSPDCarbonFiberSupportSectorA0_1")->GetShape();
2874     sA1 = (TGeoXtru*) mgr->GetVolume(
2875                                                                          "ITSSPDCarbonFiberSupportSectorAirA1_1")->GetShape();
2876     sB0 = (TGeoXtru*) mgr->GetVolume(
2877                                                                          "ITSSPDCarbonFiberSupportSectorEndB0_1")->GetShape();
2878     sB1 = (TGeoXtru*) mgr->GetVolume(
2879                                                                          "ITSSPDCarbonFiberSupportSectorEndAirB1_1")->GetShape();
2880     //pmA = new TPolyMarker();
2881     //pmA.SetMarkerStyle(2); // +
2882     //pmA.SetMarkerColor(7); // light blue
2883     //pmB = new TPolyMarker();
2884     //pmB.SetMarkerStyle(5); // X
2885     //pmB.SetMarkerColor(6); // purple
2886     plA0.SetPolyLine(sA0->GetNvert());
2887     plA0.SetLineColor(1); // black
2888     plA0.SetLineStyle(1);
2889     plA1.SetPolyLine(sA1->GetNvert());
2890     plA1.SetLineColor(2); // red
2891     plA1.SetLineStyle(1);
2892     plB0.SetPolyLine(sB0->GetNvert());
2893     plB0.SetLineColor(3); // Green
2894     plB0.SetLineStyle(2);
2895     plB1.SetPolyLine(sB1->GetNvert());
2896     plB1.SetLineColor(4); // Blue
2897     plB1.SetLineStyle(2);
2898     //for(i=0;i<kNRadii;i++) pmA.SetPoint(i,xyB1p[i][0],xyB1p[i][1]);
2899     //for(i=0;i<kNRadii;i++) pmB.SetPoint(i,xyB1p[i][0],xyB1p[i][1]);
2900     for(i=0;i<sA0->GetNvert();i++) plA0.SetPoint(i,sA0->GetX(i),sA0->GetY(i));
2901     for(i=0;i<sA1->GetNvert();i++) plA1.SetPoint(i,sA1->GetX(i),sA1->GetY(i));
2902     for(i=0;i<sB0->GetNvert();i++) plB0.SetPoint(i,sB0->GetX(i),sB0->GetY(i));
2903     for(i=0;i<sB1->GetNvert();i++) plB1.SetPoint(i,sB1->GetX(i),sB1->GetY(i));
2904     canvas = new TCanvas("AliITSv11GeometrySPDFig0","",1000,1000);
2905     canvas->Range(-3.,-3.,3.,3.);
2906     txt.SetTextSize(0.05);
2907     txt.SetTextAlign(33);
2908     txt.SetTextColor(1);
2909     txt.DrawLatex(2.9,2.9,"Section A-A outer Carbon Fiber surface");
2910     txt.SetTextColor(2);
2911     txt.DrawLatex(2.9,2.5,"Section A-A Inner Carbon Fiber surface");
2912     txt.SetTextColor(3);
2913     txt.DrawLatex(2.9,2.1,"Section E-E outer Carbon Fiber surface");
2914     txt.SetTextColor(4);
2915     txt.DrawLatex(2.9,1.7,"Section E-E Inner Carbon Fiber surface");
2916     plA0.Draw();
2917     plA1.Draw();
2918     plB0.Draw();
2919     plB1.Draw();
2920     //pmA.Draw();
2921     //pmB.Draw();
2922     //
2923     x = 1.0;
2924     y = -2.5;
2925     Char_t chr[3];
2926     for(i=0;i<kNRadii;i++){
2927         sprintf(chr,"%2d",i);txt.DrawLatex(x-0.1,y,chr);
2928         sprintf(chr,"%8.4f",5.000);txt.DrawLatex(x,y,chr);
2929         sprintf(chr,"%8.4f",5.000);txt.DrawLatex(x+0.5,y,chr);
2930         sprintf(chr,"%8.4f",5.000);txt.DrawLatex(x+1.0,y,chr);
2931         sprintf(chr,"%8.4f",5.000);txt.DrawLatex(x+1.5,y,chr);
2932         sprintf(chr,"%8.4f",5.000);txt.DrawLatex(x+2.0,y,chr);
2933         if(kTRUE) txt.DrawLatex(x+2.5,y,"A-A/E-E");
2934         else txt.DrawLatex(x+2.5,y,"E-E");
2935     } // end for i
2936     txt.DrawLatex(x,y,"x_{c} mm");
2937     txt.DrawLatex(x+0.5,y,"y_{c} mm");
2938     txt.DrawLatex(x+1.0,y,"R mm");
2939     txt.DrawLatex(x+1.5,y,"#theta_{start}^{#circle}");
2940     txt.DrawLatex(x+2.0,y,"#theta_{end}^{#circle}");
2941     txt.DrawLatex(x+2.5,y,"Section");
2942     //
2943 }
2944 //
2945 //__________________________________________________________________________________________
2946 void AliITSv11GeometrySPD::PrintAscii(ostream *os)const{
2947     // Print out class data values in Ascii Form to output stream
2948     // Inputs:
2949     //   ostream *os   Output stream where Ascii data is to be writen
2950     // Outputs:
2951     //   none.
2952     // Return:
2953     //   none.
2954 #if defined __GNUC__
2955 #if __GNUC__ > 2
2956     ios::fmtflags fmt = cout.flags();
2957 #else
2958     Int_t fmt;
2959 #endif
2960 #else
2961 #if defined __ICC || defined __ECC || defined __xlC__
2962     ios::fmtflags fmt;
2963 #else
2964     Int_t fmt;
2965 #endif
2966 #endif
2967     os->flags(fmt); // reset back to old Formating.
2968     return;
2969 }
2970 //
2971 //__________________________________________________________________________________________
2972 void AliITSv11GeometrySPD::ReadAscii(istream* /* is */){
2973     // Read in class data values in Ascii Form to output stream
2974     // Inputs:
2975     //   istream *is   Input stream where Ascii data is to be read in from
2976     // Outputs:
2977     //   none.
2978     // Return:
2979     //   none.
2980 }
2981 //
2982 //__________________________________________________________________________________________
2983 ostream &operator<<(ostream &os,const AliITSv11GeometrySPD &s){
2984     // Standard output streaming function
2985     // Inputs:
2986     //   ostream            &os  output steam
2987     //   AliITSvPPRasymmFMD &s class to be streamed.
2988     // Output:
2989     //   none.
2990     // Return:
2991     //   ostream &os  The stream pointer
2992
2993     s.PrintAscii(&os);
2994     return os;
2995 }
2996 //
2997 //__________________________________________________________________________________________
2998 istream &operator>>(istream &is,AliITSv11GeometrySPD &s){
2999     // Standard inputput streaming function
3000     // Inputs:
3001     //   istream            &is  input steam
3002     //   AliITSvPPRasymmFMD &s class to be streamed.
3003     // Output:
3004     //   none.
3005     // Return:
3006     //   ostream &os  The stream pointer
3007
3008     s.ReadAscii(&is);
3009     return is;
3010 }
3011 //
3012 //__________________________________________________________________________________________
3013 Bool_t AliITSv11GeometrySPD::Make2DCrossSections(TPolyLine &a0,TPolyLine &a1,
3014                                                                                                  TPolyLine &b0,TPolyLine &b1,TPolyMarker &p)const{
3015     // Fill the objects with the points representing
3016     // a0 the outer carbon fiber SPD sector shape Cross Section A
3017     // a1 the inner carbon fiber SPD sector shape Cross Section A
3018     // b0 the outer carbon fiber SPD sector shape Cross Section B
3019     // b1 the inner carbon fiber SPD sector shape Cross Section B
3020     //
3021     // Inputs:
3022     //   TPolyLine &a0   The outer carbon fiber SPD sector shape
3023     //   TPolyLine &a1   The Inner carbon fiber SPD sector shape
3024     //   TPolyLine &b0   The outer carbon fiber SPD sector shape
3025     //   TPolyLine &b1   The Inner carbon fiber SPD sector shape
3026     //   TPolyMarker &p  The points where the ladders are to be placed
3027     // Outputs:
3028     //   TPolyLine &a0   The shape filled with the points
3029     //   TPolyLine &a1   The shape filled with the points
3030     //   TPolyLine &b0   The shape filled with the points
3031     //   TPolyLine &b1   The shape filled with the points
3032     //   TPolyMarker &p  The filled array of points
3033     // Return:
3034     //     An error flag.
3035     Int_t n0,n1,i;
3036     Double_t x,y;
3037     TGeoVolume *a0V,*a1V,*b0V,*b1V;
3038     TGeoXtru *a0S,*a1S,*b0S,*b1S;
3039     TGeoManager *mgr = gGeoManager;
3040
3041     a0V = mgr->GetVolume("ITS SPD Carbon fiber support Sector A0");
3042     a0S = dynamic_cast<TGeoXtru*>(a0V->GetShape());
3043     n0 = a0S->GetNvert();
3044     a0.SetPolyLine(n0+1);
3045     //for(i=0;i<fSPDsectorPoints0.GetSize();i++) 
3046     //  printf("%d %d %d\n",i,fSPDsectorPoints0[i],fSPDsectorPoints1[i]);
3047     for(i=0;i<n0;i++){
3048         x = a0S->GetX(i);
3049                 y = a0S->GetY(i);
3050                 //printf("%d %g %g\n",i,x,y);
3051         a0.SetPoint(i,x,y);
3052                 if(i==0) a0.SetPoint(n0,x,y);
3053     } // end for i
3054     a1V = mgr->GetVolume("ITSSPDCarbonFiberSupportSectorAirA1");
3055     a1S = dynamic_cast<TGeoXtru*>(a1V->GetShape());
3056     n1 = a1S->GetNvert();
3057     a1.SetPolyLine(n1+1);
3058     for(i=0;i<n1;i++){
3059         x = a1S->GetX(i);
3060                 y = a1S->GetY(i);
3061         a1.SetPoint(i,x,y);
3062                 if(i==0) a1.SetPoint(n1,x,y);
3063     } // end for i
3064     // Cross Section B
3065     b0V = mgr->GetVolume("ITSSPDCarbonFiberSupportSectorEndB0");
3066     b0S = dynamic_cast<TGeoXtru*>(b0V->GetShape());
3067     n0 = b0S->GetNvert();
3068     b0.SetPolyLine(n0+1);
3069     for(i=0;i<n0;i++){
3070         x = b0S->GetX(i);
3071                 y = b0S->GetY(i);
3072         b0.SetPoint(i,x,y);
3073                 if(i==0) b0.SetPoint(n0,x,y);
3074     } // end for i
3075     b1V = mgr->GetVolume("ITSSPDCarbonFiberSupportSectorEndAirB1");
3076     b1S = dynamic_cast<TGeoXtru*>(b1V->GetShape());
3077     n1 = b1S->GetNvert();
3078     b1.SetPolyLine(n1+1);
3079     for(i=0;i<n1;i++){
3080         x = b1S->GetX(i);
3081                 y = b1S->GetY(i);
3082         b1.SetPoint(i,x,y);
3083                 if(i==0) b1.SetPoint(n1,x,y);
3084     } // end for i
3085     //
3086     Double_t x0,y0,x1,y1;
3087     p.SetPolyMarker(2*fSPDsectorX0.GetSize());
3088     for(i=0;i<fSPDsectorX0.GetSize();i++){
3089                 GetSectorMountingPoints(i,x0,y0,x1,y1);
3090                 p.SetPoint(2*i,x0,y0);
3091                 p.SetPoint(2*i+1,x1,y1);
3092     } // end for i
3093     return kTRUE;
3094 }