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