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