]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/UPGRADE/ITSUpgradeSim/AliITSUv1Layer.cxx
The last missing parts of the OB geometry from Mario (U-legs etc)
[u/mrichter/AliRoot.git] / ITS / UPGRADE / ITSUpgradeSim / AliITSUv1Layer.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, 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 //*************************************************************************
17 // This class Defines the Geometry for the ITS Upgrade using TGeo
18 // This is a work class used to study different configurations
19 // during the development of the new ITS structure.
20 //
21 //  Mario Sitta <sitta@to.infn.it>
22 //  Chinorat Kobdaj (kobdaj@g.sut.ac.th)
23 //*************************************************************************
24
25
26 /* $Id: AliITSUv1Layer.cxx  */
27 // General Root includes
28 #include <TMath.h>
29 // Root Geometry includes
30 //#include <AliLog.h>
31 #include <TGeoManager.h>
32 #include <TGeoVolume.h>
33 #include <TGeoPcon.h>
34 #include <TGeoCone.h>
35 #include <TGeoTube.h> // contaings TGeoTubeSeg
36 #include <TGeoArb8.h>
37 #include <TGeoXtru.h>
38 #include <TGeoCompositeShape.h>
39 #include <TGeoMatrix.h>
40 #include "AliITSUv1Layer.h"
41 #include "AliITSUGeomTGeo.h"
42 #include <TGeoBBox.h>
43 #include <TGeoShape.h>
44 #include <TGeoTrd1.h>
45 using namespace TMath;
46
47 // General Parameters
48 const Int_t    AliITSUv1Layer::fgkNumberOfInnerLayers =   3;
49
50 const Double_t AliITSUv1Layer::fgkDefaultSensorThick  =  18*fgkmicron;
51 const Double_t AliITSUv1Layer::fgkDefaultChipThick    =  50*fgkmicron;
52
53 // Inner Barrel Parameters
54 const Int_t    AliITSUv1Layer::fgkIBChipsPerRow       =   9;
55 const Int_t    AliITSUv1Layer::fgkIBNChipRows         =   1;
56
57 const Double_t AliITSUv1Layer::fgkIBFlexCableAlThick  =  50.0  *fgkmicron;
58 const Double_t AliITSUv1Layer::fgkIBFlexCableKapThick = 125.0  *fgkmicron;
59 const Double_t AliITSUv1Layer::fgkIBGlueThick         = 100.0  *fgkmicron;
60 const Double_t AliITSUv1Layer::fgkIBCarbonFleeceThick =  20.0  *fgkmicron;
61 const Double_t AliITSUv1Layer::fgkIBCarbonPaperThick  =  30.0  *fgkmicron;
62 const Double_t AliITSUv1Layer::fgkIBK13D2UThick       =  70.0  *fgkmicron;
63 const Double_t AliITSUv1Layer::fgkIBCoolPipeInnerD    =   1.024*fgkmm;
64 const Double_t AliITSUv1Layer::fgkIBCoolPipeThick     =  25.4  *fgkmicron;
65 const Double_t AliITSUv1Layer::fgkIBCoolPipeXDist     =   5.0  *fgkmm;
66 const Double_t AliITSUv1Layer::fgkIBTopVertexWidth    =   0.072*fgkcm;
67 const Double_t AliITSUv1Layer::fgkIBTopVertexHeight   =   0.04 *fgkcm;
68 const Double_t AliITSUv1Layer::fgkIBSideVertexWidth   =   0.052*fgkcm;
69 const Double_t AliITSUv1Layer::fgkIBSideVertexHeight  =   0.11 *fgkcm;
70 const Double_t AliITSUv1Layer::fgkIBTopFilamentLength =   0.844*fgkcm;
71 const Double_t AliITSUv1Layer::fgkIBTopFilamentSide   =   0.02 *fgkcm;
72 const Double_t AliITSUv1Layer::fgkIBTopFilamentAlpha  =  57.0; // Deg
73
74 const Double_t AliITSUv1Layer::fgkIBStaveHeight       =   0.283*fgkcm;
75
76 // Outer Barrel Parameters
77 const Int_t    AliITSUv1Layer::fgkOBChipsPerRow       =   7;
78 const Int_t    AliITSUv1Layer::fgkOBNChipRows         =   2;
79
80 const Double_t AliITSUv1Layer::fgkOBHalfStaveWidth    =   3.01 *fgkcm;
81 const Double_t AliITSUv1Layer::fgkOBModuleWidth       = fgkOBHalfStaveWidth;
82 const Double_t AliITSUv1Layer::fgkOBModuleGap         =   0.01 *fgkcm;
83 const Double_t AliITSUv1Layer::fgkOBChipXGap          =   0.01 *fgkcm;
84 const Double_t AliITSUv1Layer::fgkOBChipZGap          =   0.01 *fgkcm;
85 const Double_t AliITSUv1Layer::fgkOBFlexCableAlThick  =   0.005*fgkcm;
86 const Double_t AliITSUv1Layer::fgkOBFlexCableCuThick  =   0.004*fgkcm;
87 const Double_t AliITSUv1Layer::fgkOBFlexCableKapThick1=   0.01 *fgkcm;
88 const Double_t AliITSUv1Layer::fgkOBFlexCableKapThick = 125.0  *fgkmicron;
89 const Double_t AliITSUv1Layer::fgkOBBusCableAlThick   =   0.02 *fgkcm;
90 const Double_t AliITSUv1Layer::fgkOBBusCableKapThick  =   0.02 *fgkcm;
91 const Double_t AliITSUv1Layer::fgkOBColdPlateThick    =   0.012*fgkcm;
92 const Double_t AliITSUv1Layer::fgkOBCarbonPlateThick  =   0.012*fgkcm;
93 const Double_t AliITSUv1Layer::fgkOBGlueThickM1       =   0.03 *fgkcm;
94 const Double_t AliITSUv1Layer::fgkOBGlueThick         =   0.01 *fgkcm;
95 const Double_t AliITSUv1Layer::fgkOBModuleZLength     =  21.06 *fgkcm;
96 const Double_t AliITSUv1Layer::fgkOBHalfStaveYPos     =   2.067*fgkcm;
97 const Double_t AliITSUv1Layer::fgkOBHalfStaveYTrans   =   1.76 *fgkmm;
98 const Double_t AliITSUv1Layer::fgkOBHalfStaveXOverlap =   4.3  *fgkmm;
99 const Double_t AliITSUv1Layer::fgkOBGraphiteFoilThick =  30.0  *fgkmicron;
100 const Double_t AliITSUv1Layer::fgkOBCarbonFleeceThick =  20.0  *fgkmicron;
101 const Double_t AliITSUv1Layer::fgkOBCoolTubeInnerDM1  =   2.052*fgkmm;
102 const Double_t AliITSUv1Layer::fgkOBCoolTubeInnerD    =   2.05 *fgkmm;
103 const Double_t AliITSUv1Layer::fgkOBCoolTubeThick     =  32.0  *fgkmicron;
104 const Double_t AliITSUv1Layer::fgkOBCoolTubeXDist     =  11.1  *fgkmm;
105
106 const Double_t AliITSUv1Layer::fgkOBSpaceFrameZLen[2] = { 900.0*fgkmm,
107                                                          1526.0*fgkmm};
108 const Int_t    AliITSUv1Layer::fgkOBSpaceFrameNUnits[2]= { 23, 39};
109 const Double_t AliITSUv1Layer::fgkOBSpaceFrameUnitLen =  39.1  *fgkmm;
110 const Double_t AliITSUv1Layer::fgkOBSpaceFrameWidth   =  42.44 *fgkmm;
111 const Double_t AliITSUv1Layer::fgkOBSpaceFrameHeight  =  36.45 *fgkmm;
112 const Double_t AliITSUv1Layer::fgkOBSpaceFrameTopVL   =   4.0  *fgkmm;
113 const Double_t AliITSUv1Layer::fgkOBSpaceFrameTopVH   =   0.35 *fgkmm;
114 const Double_t AliITSUv1Layer::fgkOBSpaceFrameSideVL  =   4.5  *fgkmm;
115 const Double_t AliITSUv1Layer::fgkOBSpaceFrameSideVH  =   0.35 *fgkmm;
116 const Double_t AliITSUv1Layer::fgkOBSpaceFrameVAlpha  =  60.0; // deg
117 const Double_t AliITSUv1Layer::fgkOBSpaceFrameVBeta   =  68.0; // deg
118 const Double_t AliITSUv1Layer::fgkOBSFrameBaseRibDiam =   1.33 *fgkmm;
119 const Double_t AliITSUv1Layer::fgkOBSFrameBaseRibPhi  =  54.0; // deg
120 const Double_t AliITSUv1Layer::fgkOBSFrameSideRibDiam =   1.25 *fgkmm;
121 const Double_t AliITSUv1Layer::fgkOBSFrameSideRibPhi  =  70.0; // deg
122 const Double_t AliITSUv1Layer::fgkOBSFrameULegLen     =  14.2  *fgkmm;
123 const Double_t AliITSUv1Layer::fgkOBSFrameULegWidth   =   1.5  *fgkmm;
124 const Double_t AliITSUv1Layer::fgkOBSFrameULegHeight1 =   2.7  *fgkmm;
125 const Double_t AliITSUv1Layer::fgkOBSFrameULegHeight2 =   5.0  *fgkmm;
126 const Double_t AliITSUv1Layer::fgkOBSFrameULegThick   =   0.3  *fgkmm;
127 const Double_t AliITSUv1Layer::fgkOBSFrameULegXPos    =  12.9  *fgkmm;
128
129
130 ClassImp(AliITSUv1Layer)
131
132 #define SQ(A) (A)*(A)
133
134 //________________________________________________________________________
135 AliITSUv1Layer::AliITSUv1Layer(): 
136   AliITSv11Geometry(),
137   fLayerNumber(0),
138   fPhi0(0),
139   fLayRadius(0),
140   fZLength(0),
141   fSensorThick(0),
142   fChipThick(0),
143   fStaveWidth(0),
144   fStaveTilt(0),
145   fNStaves(0),
146   fNModules(0),
147   fNChips(0),
148   fChipTypeID(0),
149   fIsTurbo(0),
150   fBuildLevel(0),
151   fStaveModel(AliITSUv1::kIBModelDummy)
152 {
153   //
154   // Standard constructor
155   for (int i=kNHLevels;i--;) fHierarchy[i] = 0;
156   //
157 }
158
159 //________________________________________________________________________
160 AliITSUv1Layer::AliITSUv1Layer(Int_t debug): 
161   AliITSv11Geometry(debug),
162   fLayerNumber(0),
163   fPhi0(0),
164   fLayRadius(0),
165   fZLength(0),
166   fSensorThick(0),
167   fChipThick(0),
168   fStaveWidth(0),
169   fStaveTilt(0),
170   fNStaves(0),
171   fNModules(0),
172   fNChips(0),
173   fChipTypeID(0),
174   fIsTurbo(0),
175   fBuildLevel(0),
176   fStaveModel(AliITSUv1::kIBModelDummy)
177 {
178   //
179   // Constructor setting debugging level
180   for (int i=kNHLevels;i--;) fHierarchy[i] = 0;
181   //
182 }
183
184 //________________________________________________________________________
185 AliITSUv1Layer::AliITSUv1Layer(Int_t lay, Int_t debug): 
186   AliITSv11Geometry(debug),
187   fLayerNumber(lay),
188   fPhi0(0),
189   fLayRadius(0),
190   fZLength(0),
191   fSensorThick(0),
192   fChipThick(0),
193   fStaveWidth(0),
194   fStaveTilt(0),
195   fNStaves(0),
196   fNModules(0),
197   fNChips(0),
198   fChipTypeID(0),
199   fIsTurbo(0),
200   fBuildLevel(0),
201   fStaveModel(AliITSUv1::kIBModelDummy)
202 {
203   //
204   // Constructor setting layer number and debugging level
205   for (int i=kNHLevels;i--;) fHierarchy[i] = 0;
206   //
207 }
208
209 //________________________________________________________________________
210 AliITSUv1Layer::AliITSUv1Layer(Int_t lay, Bool_t turbo, Int_t debug): 
211   AliITSv11Geometry(debug),
212   fLayerNumber(lay),
213   fPhi0(0),
214   fLayRadius(0),
215   fZLength(0),
216   fSensorThick(0),
217   fChipThick(0),
218   fStaveWidth(0),
219   fStaveTilt(0),
220   fNStaves(0),
221   fNModules(0),
222   fNChips(0),
223   fChipTypeID(0),
224   fIsTurbo(turbo),
225   fBuildLevel(0),
226   fStaveModel(AliITSUv1::kIBModelDummy)
227 {
228   //
229   // Constructor setting layer number and debugging level
230   // for a "turbo" layer (i.e. where staves overlap in phi)
231   for (int i=kNHLevels;i--;) fHierarchy[i] = 0;
232   //
233 }
234
235 //________________________________________________________________________
236 AliITSUv1Layer::AliITSUv1Layer(const AliITSUv1Layer &s):
237   AliITSv11Geometry(s.GetDebug()),
238   fLayerNumber(s.fLayerNumber),
239   fPhi0(s.fPhi0),
240   fLayRadius(s.fLayRadius),
241   fZLength(s.fZLength),
242   fSensorThick(s.fSensorThick),
243   fChipThick(s.fChipThick),
244   fStaveWidth(s.fStaveWidth),
245   fStaveTilt(s.fStaveTilt),
246   fNStaves(s.fNStaves),
247   fNModules(s.fNModules),
248   fNChips(s.fNChips),
249   fChipTypeID(s.fChipTypeID),
250   fIsTurbo(s.fIsTurbo),
251   fBuildLevel(s.fBuildLevel),
252   fStaveModel(s.fStaveModel)
253 {
254   //
255   // Copy constructor
256   for (int i=kNHLevels;i--;) fHierarchy[i] = s.fHierarchy[i];
257   //
258 }
259
260 //________________________________________________________________________
261 AliITSUv1Layer& AliITSUv1Layer::operator=(const AliITSUv1Layer &s)
262 {
263   //
264   // Assignment operator 
265   //
266   if(&s == this) return *this;
267
268   fLayerNumber = s.fLayerNumber;
269   fPhi0        = s.fPhi0;
270   fLayRadius   = s.fLayRadius;
271   fZLength     = s.fZLength;
272   fSensorThick = s.fSensorThick;
273   fChipThick   = s.fChipThick;
274   fStaveWidth  = s.fStaveWidth;
275   fStaveTilt   = s.fStaveTilt;
276   fNStaves     = s.fNStaves;
277   fNModules    = s.fNModules;
278   fNChips      = s.fNChips;
279   fIsTurbo     = s.fIsTurbo;
280   fChipTypeID  = s.fChipTypeID;
281   fBuildLevel  = s.fBuildLevel;
282   fStaveModel  = s.fStaveModel;
283   for (int i=kNHLevels;i--;) fHierarchy[i] = s.fHierarchy[i];
284   //
285   return *this;
286 }
287
288 //________________________________________________________________________
289 AliITSUv1Layer::~AliITSUv1Layer() {
290   //
291   // Destructor
292   //
293 }
294
295 //________________________________________________________________________
296 void AliITSUv1Layer::CreateLayer(TGeoVolume *moth){
297 //
298 // Creates the actual Layer and places inside its mother volume
299 //
300 // Input:
301 //         moth : the TGeoVolume owing the volume structure
302 //
303 // Output:
304 //
305 // Return:
306 //
307 // Created:      17 Jun 2011  Mario Sitta
308 // Updated:      08 Jul 2011  Mario Sitta
309 // Updated:      20 May 2013  Mario Sitta  Layer is Assembly instead of Tube
310 //
311   // Local variables
312   char volname[30];
313   Double_t xpos, ypos, zpos;
314   Double_t alpha;
315
316
317   // Check if the user set the proper parameters
318   if (fLayRadius<= 0) AliFatal(Form("Wrong layer radius (%f)",fLayRadius));
319   if (fZLength  <= 0) AliFatal(Form("Wrong layer length (%f)",fZLength));
320   if (fNStaves  <= 0) AliFatal(Form("Wrong number of staves (%d)",fNStaves));
321   if (fNChips   <= 0) AliFatal(Form("Wrong number of chips (%d)",fNChips));
322
323   if (fLayerNumber >= fgkNumberOfInnerLayers && fNModules <= 0)
324     AliFatal(Form("Wrong number of modules (%d)",fNModules));
325
326   if (fChipThick <= 0) {
327     AliInfo(Form("Chip thickness wrong or not set (%f), using default (%f)",
328                  fChipThick,fgkDefaultChipThick));
329     fChipThick = fgkDefaultChipThick;
330   }
331
332   if (fSensorThick <= 0) {
333     AliInfo(Form("Sensor thickness wrong or not set (%f), using default (%f)",
334                  fSensorThick,fgkDefaultSensorThick));
335     fSensorThick = fgkDefaultSensorThick;
336   }
337
338   if (fSensorThick > fChipThick) {
339     AliWarning(Form("Sensor thickness (%f) is greater than chip thickness (%f), fixing",
340                  fSensorThick,fChipThick));
341     fSensorThick = fChipThick;
342   }
343
344
345   // If a Turbo layer is requested, do it and exit
346   if (fIsTurbo) {
347     CreateLayerTurbo(moth);
348     return;
349   }
350
351
352   // First create the stave container
353   alpha = (360./(2*fNStaves))*DegToRad();
354
355   //  fStaveWidth = fLayRadius*Tan(alpha);
356
357   snprintf(volname, 30, "%s%d", AliITSUGeomTGeo::GetITSLayerPattern(),fLayerNumber);
358   TGeoVolume *layVol = new TGeoVolumeAssembly(volname);
359   layVol->SetTitle(
360            Form("Model %d Build level %d",(Int_t)fStaveModel,fBuildLevel));
361   layVol->SetUniqueID(fChipTypeID);
362
363 //  layVol->SetVisibility(kFALSE);
364   layVol->SetVisibility(kTRUE);
365   layVol->SetLineColor(1);
366
367   TGeoVolume *stavVol = CreateStave();
368
369
370   // Now build up the layer
371   alpha = 360./fNStaves;
372   Double_t r = fLayRadius + ((TGeoBBox*)stavVol->GetShape())->GetDY();
373   for (Int_t j=0; j<fNStaves; j++) {
374     Double_t phi = j*alpha + fPhi0;
375     xpos = r*CosD(phi);// r*SinD(-phi);
376     ypos = r*SinD(phi);// r*CosD(-phi);
377     zpos = 0.;
378     phi += 90;
379     layVol->AddNode(stavVol, j, new TGeoCombiTrans( xpos, ypos, zpos,
380                                                     new TGeoRotation("",phi,0,0)));
381   }
382
383
384   // Finally put everything in the mother volume
385   moth->AddNode(layVol, 1, 0);
386
387
388   // Upgrade geometry is served
389   return;
390 }
391
392 //________________________________________________________________________
393 void AliITSUv1Layer::CreateLayerTurbo(TGeoVolume *moth){
394 //
395 // Creates the actual Layer and places inside its mother volume
396 // A so-called "turbo" layer is a layer where staves overlap in phi
397 // User can set width and tilt angle, no check is performed here
398 // to avoid volume overlaps
399 //
400 // Input:
401 //         moth : the TGeoVolume owing the volume structure
402 //
403 // Output:
404 //
405 // Return:
406 //
407 // Created:      08 Jul 2011  Mario Sitta
408 // Updated:      08 Mar 2012  Mario Sitta  Correct way to compute container R
409 // Updated:      20 May 2013  Mario Sitta  Layer is Assemgbly instead of Tube
410 //
411
412
413   // Local variables
414   char volname[30];
415   Double_t xpos, ypos, zpos;
416   Double_t alpha;
417
418
419   // Check if the user set the proper (remaining) parameters
420   if (fStaveWidth <= 0)
421     AliFatal(Form("Wrong stave width (%f)",fStaveWidth));
422   if (Abs(fStaveTilt) > 45)
423     AliWarning(Form("Stave tilt angle (%f) greater than 45deg",fStaveTilt));
424
425
426   snprintf(volname, 30, "%s%d", AliITSUGeomTGeo::GetITSLayerPattern(), fLayerNumber);
427   TGeoVolume *layVol = new TGeoVolumeAssembly(volname);
428   layVol->SetTitle(
429            Form("Model %d Build level %d",(Int_t)fStaveModel,fBuildLevel));
430   layVol->SetUniqueID(fChipTypeID);
431   layVol->SetVisibility(kTRUE);
432   layVol->SetLineColor(1);
433   TGeoVolume *stavVol = CreateStave();
434
435
436   // Now build up the layer
437   alpha = 360./fNStaves;
438   Double_t r = fLayRadius /* +chip thick ?! */;
439   for (Int_t j=0; j<fNStaves; j++) {
440     Double_t phi = j*alpha + fPhi0;
441     xpos = r*CosD(phi);// r*SinD(-phi);
442     ypos = r*SinD(phi);// r*CosD(-phi);
443     zpos = 0.;
444     phi += 90;
445     layVol->AddNode(stavVol, j, new TGeoCombiTrans( xpos, ypos, zpos,
446                                                     new TGeoRotation("", phi-fStaveTilt,0,0)));
447   }
448
449
450   // Finally put everything in the mother volume
451   moth->AddNode(layVol, 1, 0);
452
453   return;
454 }
455
456 //________________________________________________________________________
457 TGeoVolume* AliITSUv1Layer::CreateStave(const TGeoManager * /*mgr*/){
458 //
459 // Creates the actual Stave
460 //
461 // Input:
462 //         mgr  : the GeoManager (used only to get the proper material)
463 //
464 // Output:
465 //
466 // Return:
467 //
468 // Created:      22 Jun 2011  Mario Sitta
469 // Updated:      18 Dec 2013  Mario Sitta  Handle IB and OB
470 // Updated:      12 Jan 2015  Mario Sitta  Fix overlap with new OB space frame
471 //                            (by moving the latter, not the sensors to avoid
472 //                             spoiling their position in space)
473 //
474
475   char volname[30];
476  
477   Double_t xlen, ylen, zlen;
478   Double_t xpos, ypos;
479   Double_t alpha;
480
481
482   // First create all needed shapes
483   alpha = (360./(2*fNStaves))*DegToRad();
484
485   // The stave
486   xlen = fLayRadius*Tan(alpha);
487   if (fIsTurbo) xlen = 0.5*fStaveWidth;
488   ylen = 0.5*fChipThick;
489   zlen = 0.5*fZLength;
490
491   Double_t yplus = 0.46;
492   TGeoXtru *stave = new TGeoXtru(2); //z sections
493   Double_t xv[5] = {xlen,xlen,0,-xlen,-xlen};
494   Double_t yv[5] = {ylen+0.09,-0.15,-yplus-fSensorThick,-0.15,ylen+0.09};    
495   stave->DefinePolygon(5,xv,yv);
496   stave->DefineSection(0,-zlen,0,0,1.);
497   stave->DefineSection(1,+zlen,0,0,1.);
498
499   // We have all shapes: now create the real volumes
500
501   snprintf(volname, 30, "%s%d", AliITSUGeomTGeo::GetITSStavePattern(), fLayerNumber);
502 //  TGeoVolume *staveVol = new TGeoVolume(volname, stave, medAir);
503   TGeoVolume *staveVol = new TGeoVolumeAssembly(volname);
504
505   //  staveVol->SetVisibility(kFALSE);
506   staveVol->SetVisibility(kTRUE);
507   staveVol->SetLineColor(2);
508   TGeoVolume *mechStaveVol = 0;
509
510   // Now build up the stave
511   if (fLayerNumber < fgkNumberOfInnerLayers) {
512     TGeoVolume *modVol = CreateStaveInnerB(xlen,ylen,zlen);
513     staveVol->AddNode(modVol, 0);
514     fHierarchy[kHalfStave] = 1;
515  
516   // Mechanical stave structure
517     mechStaveVol = CreateStaveStructInnerB(xlen,zlen); 
518     if (mechStaveVol) {
519       ypos = ((TGeoBBox*)(modVol->GetShape()))->GetDY();
520       if (fStaveModel != AliITSUv1::kIBModel4)
521         ypos += ((TGeoBBox*)(mechStaveVol->GetShape()))->GetDY();
522       staveVol->AddNode(mechStaveVol, 1, new TGeoCombiTrans(0, -ypos, 0, new TGeoRotation("",0, 0, 180)));
523     }
524   }
525
526   else{
527     TGeoVolume *hstaveVol = CreateStaveOuterB();
528     if (fStaveModel == AliITSUv1::kOBModel0) { // Create simplified stave struct as in v0
529       staveVol->AddNode(hstaveVol, 0);
530       fHierarchy[kHalfStave] = 1;
531     } else { // (if fStaveModel) Create new stave struct as in TDR
532       xpos = ((TGeoBBox*)(hstaveVol->GetShape()))->GetDX()
533            - fgkOBHalfStaveXOverlap/2;
534       // ypos is now a parameter to avoid HS displacement wrt nominal radii
535       ypos = fgkOBHalfStaveYPos;
536       staveVol->AddNode(hstaveVol, 0, new TGeoTranslation(-xpos, ypos, 0));
537       staveVol->AddNode(hstaveVol, 1, new TGeoTranslation( xpos, ypos+fgkOBHalfStaveYTrans, 0));
538       fHierarchy[kHalfStave] = 2; // RS 
539       mechStaveVol = CreateSpaceFrameOuterB();
540       if (mechStaveVol) {
541         staveVol->AddNode(mechStaveVol, 1,
542                           new TGeoCombiTrans(0, -fgkOBSFrameULegHeight1, 0,
543                                              new TGeoRotation("", 180, 0, 0)));
544       }
545     } // if (fStaveModel)
546   }
547   
548
549   // Done, return the stave
550   return staveVol;
551 }
552
553 //________________________________________________________________________
554 TGeoVolume* AliITSUv1Layer::CreateStaveInnerB(const Double_t xsta,
555                                               const Double_t ysta,
556                                               const Double_t zsta,
557                                               const TGeoManager *mgr){
558 //
559 // Create the chip stave for the Inner Barrel
560 // (Here we fake the halfstave volume to have the same
561 // formal geometry hierarchy as for the Outer Barrel)
562 //
563 // Input:
564 //         xsta, ysta, zsta : X, Y, Z stave half lengths
565 //         mgr  : the GeoManager (used only to get the proper material)
566 //
567 // Output:
568 //
569 // Return:
570 //
571 // Created:      06 Mar 2014  Mario Sitta
572 //
573
574   // Local variables
575   Double_t xmod, ymod, zmod;
576   char volname[30];
577
578   // First we create the module (i.e. the HIC with 9 chips)
579   TGeoVolume *moduleVol = CreateModuleInnerB(xsta, ysta, zsta);
580
581   // Then we create the fake halfstave and the actual stave
582   xmod = ((TGeoBBox*)(moduleVol->GetShape()))->GetDX();
583   ymod = ((TGeoBBox*)(moduleVol->GetShape()))->GetDY();
584   zmod = ((TGeoBBox*)(moduleVol->GetShape()))->GetDZ();
585
586   TGeoBBox *hstave = new TGeoBBox(xmod, ymod, zmod);
587
588   TGeoMedium *medAir = mgr->GetMedium("ITS_AIR$");
589
590   snprintf(volname, 30, "%s%d", AliITSUGeomTGeo::GetITSHalfStavePattern(), fLayerNumber);
591   TGeoVolume *hstaveVol  = new TGeoVolume(volname, hstave, medAir);
592
593
594   // Finally build it up
595   hstaveVol->AddNode(moduleVol, 0);
596   fHierarchy[kModule] = 1;
597
598   // Done, return the stave structure
599   return hstaveVol;
600 }
601
602 //________________________________________________________________________
603 TGeoVolume* AliITSUv1Layer::CreateModuleInnerB(Double_t xmod,
604                                                Double_t ymod,
605                                                Double_t zmod,
606                                                const TGeoManager *mgr){
607 //
608 // Creates the IB Module: (only the chips for the time being)
609 //
610 // Input:
611 //         xmod, ymod, zmod : X, Y, Z module half lengths
612 //         mgr  : the GeoManager (used only to get the proper material)
613 //
614 // Output:
615 //
616 // Return:
617 //         the module as a TGeoVolume
618 //
619 // Created:      06 Mar 2014  M. Sitta
620 //
621
622   Double_t zchip;
623   Double_t zpos;
624   char volname[30];
625
626   // First create the single chip
627   zchip = zmod/fgkIBChipsPerRow;
628   TGeoVolume *chipVol = CreateChipInnerB(xmod, ymod, zchip);
629
630   // Then create the module and populate it with the chips
631   TGeoBBox *module = new TGeoBBox(xmod, ymod, zmod);
632
633   TGeoMedium *medAir = mgr->GetMedium("ITS_AIR$");
634
635   snprintf(volname, 30, "%s%d", AliITSUGeomTGeo::GetITSModulePattern(), fLayerNumber);
636   TGeoVolume *modVol = new TGeoVolume(volname, module, medAir);
637
638   // mm (not used)  zlen = ((TGeoBBox*)chipVol->GetShape())->GetDZ();
639   for (Int_t j=0; j<fgkIBChipsPerRow; j++) {
640     zpos = -zmod + j*2*zchip + zchip;
641     modVol->AddNode(chipVol, j, new TGeoTranslation(0, 0, zpos));
642     fHierarchy[kChip]++;
643   }
644
645   // Done, return the module
646   return modVol;
647 }
648
649 //________________________________________________________________________
650 TGeoVolume* AliITSUv1Layer::CreateStaveStructInnerB(const Double_t xsta,
651                                                     const Double_t zsta,
652                                                     const TGeoManager *mgr){
653 //
654 // Create the mechanical stave structure
655 //
656 // Input:
657 //         xsta : X length
658 //         zsta : Z length
659 //         mgr  : the GeoManager (used only to get the proper material)
660 //
661 // Output:
662 //
663 // Return:
664 //
665 // Created:      22 Mar 2013  Chinorat Kobdaj
666 // Updated:      26 Apr 2013  Mario Sitta
667 //
668
669   TGeoVolume *mechStavVol = 0;
670
671   switch (fStaveModel) {
672     case AliITSUv1::kIBModelDummy:
673       mechStavVol = CreateStaveModelInnerBDummy(xsta,zsta,mgr);
674       break;
675     case AliITSUv1::kIBModel0:
676       mechStavVol = CreateStaveModelInnerB0(xsta,zsta,mgr);
677       break;
678     case AliITSUv1::kIBModel1:
679       mechStavVol = CreateStaveModelInnerB1(xsta,zsta,mgr);
680       break;
681     case AliITSUv1::kIBModel21:
682       mechStavVol = CreateStaveModelInnerB21(xsta,zsta,mgr);
683       break;
684     case AliITSUv1::kIBModel22:
685       mechStavVol = CreateStaveModelInnerB22(xsta,zsta,mgr);
686       break;
687     case AliITSUv1::kIBModel3:
688       mechStavVol = CreateStaveModelInnerB3(xsta,zsta,mgr);
689       break;
690     case AliITSUv1::kIBModel4:
691       mechStavVol = CreateStaveModelInnerB4(xsta,zsta,mgr);
692       break;
693     default:
694       AliFatal(Form("Unknown stave model %d",fStaveModel));
695       break;
696   }
697
698   return mechStavVol; 
699 }
700
701
702 //________________________________________________________________________
703 TGeoVolume* AliITSUv1Layer::CreateStaveModelInnerBDummy(const Double_t ,
704                                                         const Double_t ,
705                                                         const TGeoManager *) const {
706 //
707 // Create dummy stave
708 //
709 // Input:
710 //         xsta : X length
711 //         zsta : Z length
712 //         mgr  : the GeoManager (used only to get the proper material)
713 //
714 // Output:
715 //
716 // Return:
717 //
718 // Created:      22 Mar 2013  Chinorat Kobdaj
719 // Updated:      26 Apr 2013  Mario Sitta
720 //
721
722   // Done, return the stave structur
723   return 0;
724 }
725
726 //________________________________________________________________________
727 TGeoVolume* AliITSUv1Layer::CreateStaveModelInnerB0(const Double_t xsta,
728                                                     const Double_t zsta,
729                                                     const TGeoManager *mgr){
730 //
731 // Create the mechanical stave structure for Model 0 of TDR
732 //
733 // Input:
734 //         xsta : X length
735 //         zsta : Z length
736 //         mgr  : the GeoManager (used only to get the proper material)
737 //
738 // Output:
739 //
740 // Return:
741 //
742 // Created:      22 Mar 2013  Chinorat Kobdaj
743 // Updated:      26 Apr 2013  Mario Sitta
744 //
745   
746   // Materials defined in AliITSUv1
747   TGeoMedium *medAir    = mgr->GetMedium("ITS_AIR$");
748   TGeoMedium *medWater  = mgr->GetMedium("ITS_WATER$");
749
750   TGeoMedium *medM60J3K    = mgr->GetMedium("ITS_M60J3K$"); 
751   TGeoMedium *medKapton    = mgr->GetMedium("ITS_KAPTON(POLYCH2)$");
752   TGeoMedium *medGlue      = mgr->GetMedium("ITS_GLUE$");
753   TGeoMedium *medFlexCable = mgr->GetMedium("ITS_FLEXCABLE$");
754
755   // Local parameters
756   Double_t kConeOutRadius = 0.15/2;
757   Double_t kConeInRadius = 0.1430/2;
758   Double_t kStaveLength = zsta*2;
759   Double_t kStaveWidth = xsta*2-kConeOutRadius*2;
760   Double_t kWidth = kStaveWidth/4;//1/2 of kWidth
761   Double_t kStaveHeight = 0.3;
762   Double_t kHeight = kStaveHeight/2;
763   Double_t kAlpha = 90-67;//90-33.69;
764   Double_t kTheta = kAlpha*TMath::DegToRad();
765   Double_t kS1 = kWidth/TMath::Sin(kTheta);
766   Double_t kL1 = kWidth/TMath::Tan(kTheta);
767   Double_t kS2 = TMath::Sqrt(kHeight*kHeight + kS1*kS1);//TMath::Sin(the2);
768   Double_t kThe2 = TMath::ATan(kHeight/kS1);
769   Double_t kBeta = kThe2*TMath::RadToDeg();
770   // Int_t  loop = kStaveLength/(kL1);
771   // Double_t s3 = kWidth/(2*TMath::Sin(kTheta));
772   // Double_t s4 = 3*kWidth/(2*TMath::Sin(kTheta));
773
774   AliDebug(1, Form("BuildLevel %d\n",fBuildLevel));
775
776   char volname[30];
777   snprintf(volname, 30, "%s%d_StaveStruct", AliITSUGeomTGeo::GetITSStavePattern(), fLayerNumber);
778
779   Double_t z=0, y=-0.011+0.0150, x=0;
780
781    TGeoVolume *mechStavVol = 0;
782
783   if (fBuildLevel < 5) {
784
785     // world (trapezoid)
786     TGeoXtru *mechStruct = new TGeoXtru(2); //z sections
787     Double_t xv[5] = {kStaveWidth/2+0.1,kStaveWidth/2+0.1,0,-kStaveWidth/2-0.1,-kStaveWidth/2-0.1};
788     Double_t yv[5] = {-kConeOutRadius*2-0.07,0,kStaveHeight,0,-kConeOutRadius*2-0.07};    
789     mechStruct->DefinePolygon(5,xv,yv);
790     mechStruct->DefineSection(0,-kStaveLength-0.1,0,0,1.);
791     mechStruct->DefineSection(1,kStaveLength+0.1,0,0,1.);
792
793     mechStavVol = new TGeoVolume(volname, mechStruct, medAir);
794     mechStavVol->SetLineColor(12);
795     mechStavVol->SetFillColor(12); 
796     mechStavVol->SetVisibility(kTRUE);
797       
798     // detailed structure ++++++++++++++
799     //Pipe Kapton grey-35
800     TGeoTube *coolTube = new TGeoTube(kConeInRadius,kConeOutRadius,kStaveLength/2);
801     TGeoVolume *volCoolTube= new TGeoVolume("pipe", coolTube, medKapton);
802     volCoolTube->SetFillColor(35);
803     volCoolTube->SetLineColor(35);
804     mechStavVol->AddNode(volCoolTube,0,new TGeoTranslation(x+(kStaveWidth/2),y-(kHeight-kConeOutRadius),0));
805     mechStavVol->AddNode(volCoolTube,1,new TGeoTranslation(x-(kStaveWidth/2),y-(kHeight-kConeOutRadius),0));
806   }
807
808   if (fBuildLevel < 4) {
809     TGeoTube *coolTubeW = new TGeoTube(0.,kConeInRadius,kStaveLength/2);
810     TGeoVolume *volCoolTubeW= new TGeoVolume("pipeWater", coolTubeW, medWater);
811     volCoolTubeW->SetFillColor(4);
812     volCoolTubeW->SetLineColor(4);
813     mechStavVol->AddNode(volCoolTubeW,0,new TGeoTranslation(x+(kStaveWidth/2),y-(kHeight-kConeOutRadius),0));
814     mechStavVol->AddNode(volCoolTubeW,1,new TGeoTranslation(x-(kStaveWidth/2),y-(kHeight-kConeOutRadius),0));
815   }
816
817   //frequency of filament
818   //n = 4 means very dense(4 filaments per interval)
819   //n = 2 means dense(2 filaments per interval)
820   Int_t n =4;
821   Int_t loop = (Int_t)(kStaveLength/(4*kL1/n) + 2/n)-1;
822   if (fBuildLevel < 3) {
823     //Top CFRP Filament black-12 Carbon structure TGeoBBox (length,thickness,width)
824     TGeoBBox *t2=new TGeoBBox(kS2,0.007/2,0.15/2);//(kS2,0.002,0.02);
825     TGeoVolume *volT2=new TGeoVolume("TopFilament", t2, medM60J3K);
826     volT2->SetLineColor(12);
827     volT2->SetFillColor(12); 
828
829     for(int i=1;i<loop;i++){  //i<60;i++){
830       mechStavVol->AddNode(volT2,4*i+0,
831                                   new TGeoCombiTrans(x+kWidth,y+(2*kConeOutRadius),z-kStaveLength/2+(i*(4/n)*kL1)+kS1/2,//z-14.25+(i*2*kL1),
832                                                      new TGeoRotation("volT2",90,90-kAlpha,90-kBeta)));
833       mechStavVol->AddNode(volT2,4*i+1,
834                                   new TGeoCombiTrans(x-kWidth,y+(2*kConeOutRadius),z-kStaveLength/2+(i*(4/n)*kL1)+kS1/2,//z-14.25+(i*2*kL1),
835                                                      new TGeoRotation("volT2",90,-90+kAlpha,-90+kBeta)));
836       mechStavVol->AddNode(volT2,4*i+2,
837                                   new TGeoCombiTrans(x+kWidth,y+(2*kConeOutRadius),z-kStaveLength/2+(i*(4/n)*kL1)+kS1/2,//z-14.25+(i*2*kL1),
838                                                      new TGeoRotation("volT2",90,-90+kAlpha,90-kBeta)));
839       mechStavVol->AddNode(volT2,4*i+3,
840                                   new TGeoCombiTrans(x-kWidth,y+(2*kConeOutRadius),z-kStaveLength/2+(i*(4/n)*kL1)+kS1/2,//z-14.25+(i*2*kL1),  
841                                                      new TGeoRotation("volT2",90,90-kAlpha,-90+kBeta)));
842     }
843
844
845     //Bottom CFRP Filament black-12 Carbon structure  TGeoBBox (thickness,width,length)
846     TGeoBBox *t1=new TGeoBBox(0.007/2,0.15/2,kS1);//(0.002,0.02,kS1);
847     TGeoVolume *volT1=new TGeoVolume("CFRPBottom", t1, medM60J3K);
848     volT1->SetLineColor(12);
849     volT1->SetFillColor(12); 
850
851     for(int i=1;i<loop;i++){
852       mechStavVol->AddNode(volT1,4*i+0,
853                                   new TGeoCombiTrans(x+kWidth,y-kHeight,z-kStaveLength/2+((4/n)*kL1*i)+kS1/2, //z-14.25+(i*2*kL1),  
854                                                      new TGeoRotation("volT1",-90,kAlpha,0)));
855       mechStavVol->AddNode(volT1,4*i+1,
856                                   new TGeoCombiTrans(x-kWidth,y-kHeight,z-kStaveLength/2+((4/n)*kL1*i)+kS1/2,  //z-14.25+(i*2*kL1), 
857                                                      new TGeoRotation("volT1",90,kAlpha,0)));
858       mechStavVol->AddNode(volT1,4*i+2,
859                                   new TGeoCombiTrans(x+kWidth,y-kHeight,z-kStaveLength/2+(i*(4/n)*kL1)+kS1/2, //z-14.25+(i*2*kL1), 
860                                                      new TGeoRotation("volT1",-90,-kAlpha,0)));
861       mechStavVol->AddNode(volT1,4*i+3,
862                                   new TGeoCombiTrans(x-kWidth,y-kHeight,z-kStaveLength/2+(i*(4/n)*kL1)+kS1/2, //z-14.25+(i*2*kL1), 
863                                                      new TGeoRotation("volT1",-90,+kAlpha,0)));
864     }
865   }
866    
867   if (fBuildLevel < 2) {
868     // Glue CFRP-Silicon layers TGeoBBox(thickness,width,kS1);
869     TGeoBBox *tG=new TGeoBBox(0.0075/2,0.18/2,kS1);
870     TGeoVolume *volTG=new TGeoVolume("Glue1", tG, medGlue);
871     volTG->SetLineColor(5);
872     volTG->SetFillColor(5); 
873
874     for(int i=1;i<loop;i++){ //i<60;i++){
875       mechStavVol->AddNode(volTG,4*i+0,
876                                   new TGeoCombiTrans(x+kWidth,y-0.16,z-kStaveLength/2+((4/n)*kL1*i)+kS1/2, //z-14.25+(2*kL1*i), 
877                                                      new TGeoRotation("volTG",-90,kAlpha,0)));
878       mechStavVol->AddNode(volTG,4*i+1,
879                                   new TGeoCombiTrans(x-kWidth,y-0.16,z-kStaveLength/2+((4/n)*kL1*i)+kS1/2, //z-14.25+(2*kL1*i), 
880                                                      new TGeoRotation("volTG",90,kAlpha,0)));
881       mechStavVol->AddNode(volTG,4*i+2,
882                                   new TGeoCombiTrans(x+kWidth,y-0.16,z-kStaveLength/2+((4/n)*i*kL1)+kS1/2, //z-14.25+(i*2*kL1), 
883                                                      new TGeoRotation("volTG",-90,-kAlpha,0)));
884       mechStavVol->AddNode(volTG,4*i+3,
885                                   new TGeoCombiTrans(x-kWidth,y-0.16,z-kStaveLength/2+(i*(4/n)*kL1)+kS1/2, //z-14.25+(i*2*kL1), 
886                                                      new TGeoRotation("volTG",-90,+kAlpha,0)));
887     }
888
889     TGeoBBox *glue = new TGeoBBox(xsta, 0.005/2, zsta);
890     TGeoVolume *volGlue=new TGeoVolume("Glue2", glue, medGlue);
891     volGlue->SetLineColor(5);
892     volGlue->SetFillColor(5); 
893     //mechStavVol->AddNode(volGlue, 0, new TGeoCombiTrans(x, y-0.16, z, new TGeoRotation("",0, 0, 0)));
894     mechStavVol->AddNode(volGlue, 1, new TGeoCombiTrans(x, y-0.165-fSensorThick-0.005, z, new TGeoRotation("",0, 0, 0)));
895   }
896
897   if (fBuildLevel < 1) {
898     //Flex cable brown-28 TGeoBBox(width,thickness,length); 
899     TGeoBBox *kapCable = new TGeoBBox(xsta, 0.01/2, zsta);
900     TGeoVolume *volCable=new TGeoVolume("FlexCable", kapCable, medFlexCable);
901     volCable->SetLineColor(28);
902     volCable->SetFillColor(28); 
903     mechStavVol->AddNode(volCable, 0, new TGeoCombiTrans(x, y-0.165-fSensorThick-0.005-0.01, z, new TGeoRotation("",0, 0, 0)));
904  }
905
906   // Done, return the stave structur
907   return mechStavVol;
908 }
909
910
911 //________________________________________________________________________
912 TGeoVolume* AliITSUv1Layer::CreateStaveModelInnerB1(const Double_t xsta,
913                                                     const Double_t zsta,
914                                                     const TGeoManager *mgr){
915 //
916 // Create the mechanical stave structure for Model 1 of TDR
917 //
918 // Input:
919 //         xsta : X length
920 //         zsta : Z length
921 //         mgr  : the GeoManager (used only to get the proper material)
922 //
923 // Output:
924 //
925 // Return:
926 //
927 // Created:      22 Mar 2013  Chinorat Kobdaj
928 // Updated:      26 Apr 2013  Mario Sitta
929 //
930   
931   // Materials defined in AliITSUv1
932   TGeoMedium *medAir    = mgr->GetMedium("ITS_AIR$");
933   TGeoMedium *medWater  = mgr->GetMedium("ITS_WATER$");
934
935   TGeoMedium *medM60J3K    = mgr->GetMedium("ITS_M60J3K$"); 
936   TGeoMedium *medKapton    = mgr->GetMedium("ITS_KAPTON(POLYCH2)$");
937   TGeoMedium *medGlue      = mgr->GetMedium("ITS_GLUE$");
938   TGeoMedium *medFlexCable = mgr->GetMedium("ITS_FLEXCABLE$");
939
940   // Local parameters
941   Double_t kConeOutRadius = 0.15/2;
942   //    Double_t kConeInRadius = 0.1430/2;
943   Double_t kStaveLength = zsta*2;
944   //    Double_t kStaveWidth = xsta*2-kConeOutRadius*2;
945   Double_t kStaveWidth = xsta*2;
946   Double_t kWidth = kStaveWidth/4;//1/2 of kWidth
947   Double_t kStaveHeight = 0.3;
948   Double_t kHeight = kStaveHeight/2;
949   Double_t kAlpha = 90-33.;//90-30;
950   Double_t kTheta = kAlpha*TMath::DegToRad();
951   Double_t kS1 = kWidth/TMath::Sin(kTheta);
952   Double_t kL1 = kWidth/TMath::Tan(kTheta);
953   Double_t kS2 = TMath::Sqrt(kHeight*kHeight + kS1*kS1);//TMath::Sin(the2);
954   Double_t kThe2 = TMath::ATan(kHeight/kS1);
955   Double_t kBeta = kThe2*TMath::RadToDeg();
956   Int_t  loop = (Int_t)((kStaveLength/(2*kL1))/2);
957   
958
959   TGeoVolume *mechStavVol = 0;
960
961   char volname[30];
962   snprintf(volname, 30, "%s%d_StaveStruct", AliITSUGeomTGeo::GetITSStavePattern(), fLayerNumber);
963     
964
965   // detailed structure ++++++++++++++
966   Double_t z=0, y=-0.011+0.0150, x=0;
967
968   // Polimide micro channels numbers
969   Double_t yMC = y-kHeight+0.01;
970   Int_t nb = (Int_t)(kStaveWidth/0.1)+1;
971   Double_t xstaMC = (nb*0.1-0.08)/2;
972
973
974   if (fBuildLevel < 5) {
975     // world (trapezoid)
976     TGeoXtru *mechStruct = new TGeoXtru(2); //z sections
977     Double_t xv[5] = {kStaveWidth/2+0.1,kStaveWidth/2+0.1,0,-kStaveWidth/2-0.1,-kStaveWidth/2-0.1};
978     Double_t yv[5] = {-kConeOutRadius*2-0.07,0,kStaveHeight,0,-kConeOutRadius*2-0.07};    
979     mechStruct->DefinePolygon(5,xv,yv);
980     mechStruct->DefineSection(0,-kStaveLength-0.1,0,0,1.);
981     mechStruct->DefineSection(1,kStaveLength+0.1,0,0,1.);
982
983     mechStavVol = new TGeoVolume(volname, mechStruct, medAir);
984     mechStavVol->SetLineColor(12);
985     mechStavVol->SetFillColor(12); 
986     mechStavVol->SetVisibility(kTRUE);
987       
988     // Polimide micro channels numbers
989     TGeoBBox *tM0=new TGeoBBox(xstaMC, 0.005/2, zsta);
990     TGeoVolume *volTM0=new TGeoVolume("MicroChanCover", tM0, medKapton);
991     volTM0->SetLineColor(35);
992     volTM0->SetFillColor(35); 
993     mechStavVol->AddNode(volTM0, 0, new TGeoCombiTrans(x,-0.0125+yMC, z, new TGeoRotation("",0, 0, 0)));
994     mechStavVol->AddNode(volTM0, 1, new TGeoCombiTrans(x,+0.0125+yMC, z, new TGeoRotation("",0, 0, 0)));
995       
996     TGeoBBox *tM0b=new TGeoBBox(0.02/2, 0.02/2, zsta);
997     TGeoVolume *volTM0b=new TGeoVolume("MicroChanWalls", tM0b, medKapton);
998     volTM0b->SetLineColor(35);
999     volTM0b->SetFillColor(35); 
1000     for (Int_t ib=0;ib<nb;ib++) {
1001       mechStavVol->AddNode(volTM0b, ib, new TGeoCombiTrans(x+ib*0.1-xstaMC+0.01,yMC, z, new TGeoRotation("",0, 0, 0)));
1002     }
1003       
1004   }
1005     
1006   if (fBuildLevel < 4) {
1007     // Water in Polimide micro channels
1008     TGeoBBox *water=new TGeoBBox(0.08/2, 0.02/2, zsta+0.1);
1009     TGeoVolume *volWater=new TGeoVolume("Water", water, medWater);
1010     volWater->SetLineColor(4);
1011     volWater->SetFillColor(4); 
1012     for (Int_t ib=0;ib<(nb-1);ib++) {
1013       mechStavVol->AddNode(volWater, ib, new TGeoCombiTrans(x+ib*0.1-xstaMC+0.06,yMC, z, new TGeoRotation("",0, 0, 0)));
1014     }
1015   }
1016     
1017   if (fBuildLevel < 3) {
1018     //Bottom filament CFRP black-12 Carbon structure TGeoBBox (thickness,width,length)
1019     Double_t filWidth = 0.04;
1020     Double_t filHeight= 0.02;
1021     TGeoBBox *t1=new TGeoBBox(filHeight/2,filWidth/2,kS1);
1022     TGeoVolume *volT1=new TGeoVolume("CFRPBottom", t1, medM60J3K);
1023     volT1->SetLineColor(12);
1024     volT1->SetFillColor(12); 
1025     for(int i=0;i<loop;i++){//i<30;i++){
1026       mechStavVol->AddNode(volT1,4*i+0,
1027                                   new TGeoCombiTrans(x+kWidth,y-kHeight+0.04+filHeight/2,z-kStaveLength/2+(4*kL1)+kS1/2, 
1028                                                      new TGeoRotation("volT1",-90,kAlpha,0)));
1029       mechStavVol->AddNode(volT1,4*i+1,
1030                                   new TGeoCombiTrans(x-kWidth,y-kHeight+0.04+filHeight/2,z-kStaveLength/2+(4*kL1*i)+kS1/2, 
1031                                                      new TGeoRotation("volT1",90,kAlpha,0)));
1032       mechStavVol->AddNode(volT1,4*i+2,
1033                                   new TGeoCombiTrans(x+kWidth,y-kHeight+0.04+filHeight/2,z-kStaveLength/2+2*kL1+(i*4*kL1)+kS1/2, 
1034                                                      new TGeoRotation("volT1",-90,-kAlpha,0)));
1035       mechStavVol->AddNode(volT1,4*i+3,
1036                                   new TGeoCombiTrans(x-kWidth,y-kHeight+0.04+filHeight/2,z-kStaveLength/2+2*kL1+(i*4*kL1)+kS1/2, 
1037                                                      new TGeoRotation("volT1",-90,+kAlpha,0)));
1038     }
1039
1040       // Top filament CFRP black-12 Carbon structure TGeoBBox (length,thickness,width)
1041     TGeoBBox *t2=new TGeoBBox(kS2,filHeight/2,filWidth/2);
1042     TGeoVolume *volT2=new TGeoVolume("CFRPTop", t2, medM60J3K);
1043     volT2->SetLineColor(12);
1044     volT2->SetFillColor(12); 
1045     for(int i=0;i<loop;i++){ //i<30;i++){
1046       mechStavVol->AddNode(volT2,4*i+0,
1047                                   new TGeoCombiTrans(x+kWidth,y+0.04+filHeight/2,z-kStaveLength/2+(i*4*kL1)+kS1/2,
1048                                                      new TGeoRotation("volT2",90,90-kAlpha,90-kBeta)));
1049       mechStavVol->AddNode(volT2,4*i+1,
1050                                   new TGeoCombiTrans(x-kWidth,y+0.04+filHeight/2,z-kStaveLength/2+(i*4*kL1)+kS1/2,
1051                                                      new TGeoRotation("volT2",90,-90+kAlpha,-90+kBeta)));
1052       mechStavVol->AddNode(volT2,4*i+2,
1053                                   new TGeoCombiTrans(x+kWidth,y+0.04+filHeight/2,z-kStaveLength/2+2*kL1+(i*4*kL1)+kS1/2,
1054                                                      new TGeoRotation("volT2",90,-90+kAlpha,90-kBeta)));
1055       mechStavVol->AddNode(volT2,4*i+3,
1056                                   new TGeoCombiTrans(x-kWidth,y+0.04+filHeight/2,z-kStaveLength/2+2*kL1+(i*4*kL1)+kS1/2, 
1057                                                      new TGeoRotation("volT2",90,90-kAlpha,-90+kBeta)));
1058     }
1059   }
1060
1061   if (fBuildLevel < 2) {
1062     // Glue between filament and polimide micro channel
1063     TGeoBBox *t3=new TGeoBBox(0.01/2,0.04,kS1);
1064     TGeoVolume *volT3=new TGeoVolume("FilamentGlue", t3, medGlue);
1065     volT3->SetLineColor(5);
1066     volT3->SetFillColor(5); 
1067     for(int i=0;i<loop;i++){//i<30;i++){
1068       mechStavVol->AddNode(volT3,4*i+0,
1069                                   new TGeoCombiTrans(x+kWidth,y-kHeight+0.0325,z-kStaveLength/2+(4*kL1*i)+kS1/2, 
1070                                                      new TGeoRotation("volT1",-90,kAlpha,0)));
1071       mechStavVol->AddNode(volT3,4*i+1,
1072                                   new TGeoCombiTrans(x-kWidth,y-kHeight+0.0325,z-kStaveLength/2+(4*kL1*i)+kS1/2, 
1073                                                      new TGeoRotation("volT1",90,kAlpha,0)));
1074       mechStavVol->AddNode(volT3,4*i+2,
1075                                   new TGeoCombiTrans(x+kWidth,y-kHeight+0.0325,z-kStaveLength/2+2*kL1+(i*4*kL1)+kS1/2, 
1076                                                      new TGeoRotation("volT1",-90,-kAlpha,0)));
1077       mechStavVol->AddNode(volT3,4*i+3,
1078                                   new TGeoCombiTrans(x-kWidth,y-kHeight+0.0325,z-kStaveLength/2+2*kL1+(i*4*kL1)+kS1/2, 
1079                                                      new TGeoRotation("volT1",-90,+kAlpha,0)));
1080     }
1081       
1082     // Glue microchannel and sensor
1083     TGeoBBox *glueM = new TGeoBBox(xsta, 0.01/2, zsta);
1084     TGeoVolume *volGlueM=new TGeoVolume("MicroChanGlue", glueM, medGlue);
1085     volGlueM->SetLineColor(5);
1086     volGlueM->SetFillColor(5); 
1087     mechStavVol->AddNode(volGlueM, 0, new TGeoCombiTrans(x, y-0.16, z, new TGeoRotation("",0, 0, 0)));
1088
1089     // Glue sensor and kapton
1090     TGeoBBox *glue = new TGeoBBox(xsta, 0.005/2, zsta);
1091     TGeoVolume *volGlue=new TGeoVolume("SensorGlue", glue, medGlue);
1092     volGlue->SetLineColor(5);
1093     volGlue->SetFillColor(5); 
1094     mechStavVol->AddNode(volGlue, 1, new TGeoCombiTrans(x, y-0.165-fSensorThick-0.005, z, new TGeoRotation("",0, 0, 0)));
1095   }
1096
1097   if (fBuildLevel < 1) {
1098     TGeoBBox *kapCable = new TGeoBBox(xsta, 0.01/2, zsta);
1099     TGeoVolume *volCable=new TGeoVolume("FlexCable", kapCable, medFlexCable);
1100     volCable->SetLineColor(28);
1101     volCable->SetFillColor(28); 
1102     mechStavVol->AddNode(volCable, 0, new TGeoCombiTrans(x, y-0.165-fSensorThick-0.005-0.01, z, new TGeoRotation("",0, 0, 0)));
1103   }
1104     
1105   // Done, return the stave structur
1106   return mechStavVol;
1107
1108 }
1109
1110 //________________________________________________________________________
1111 TGeoVolume* AliITSUv1Layer::CreateStaveModelInnerB21(const Double_t xsta,
1112                                                      const Double_t zsta,
1113                                                      const TGeoManager *mgr){
1114 //
1115 // Create the mechanical stave structure for Model 2.1 of TDR
1116 //
1117 // Input:
1118 //         xsta : X length
1119 //         zsta : Z length
1120 //         mgr  : the GeoManager (used only to get the proper material)
1121 //
1122 // Output:
1123 //
1124 // Return:
1125 //
1126 // Created:      22 Mar 2013  Chinorat Kobdaj
1127 // Updated:      26 Apr 2013  Mario Sitta
1128 //
1129   
1130   // Materials defined in AliITSUv1
1131   TGeoMedium *medAir    = mgr->GetMedium("ITS_AIR$");
1132   TGeoMedium *medWater  = mgr->GetMedium("ITS_WATER$");
1133
1134   TGeoMedium *medM60J3K    = mgr->GetMedium("ITS_M60J3K$"); 
1135   TGeoMedium *medKapton    = mgr->GetMedium("ITS_KAPTON(POLYCH2)$");
1136   TGeoMedium *medGlue      = mgr->GetMedium("ITS_GLUE$");
1137   TGeoMedium *medFlexCable = mgr->GetMedium("ITS_FLEXCABLE$");
1138   TGeoMedium *medK13D2U2k  = mgr->GetMedium("ITS_K13D2U2k$");
1139   TGeoMedium *medFGS003    = mgr->GetMedium("ITS_FGS003$"); 
1140   TGeoMedium *medCarbonFleece = mgr->GetMedium("ITS_CarbonFleece$"); 
1141
1142   // Local parameters
1143   Double_t kConeOutRadius =0.151384/2;
1144   Double_t kConeInRadius = 0.145034/2;
1145   Double_t kStaveLength = zsta;
1146   Double_t kStaveWidth = xsta*2;
1147   Double_t kWidth = (kStaveWidth+0.005)/4;
1148   Double_t kStaveHeigth = 0.33;//0.33;
1149   Double_t kHeight = (kStaveHeigth+0.025)/2;
1150   Double_t kAlpha = 57; //56.31;
1151   Double_t kTheta = kAlpha*TMath::DegToRad();
1152   Double_t kS1 = (kStaveWidth/4)/TMath::Sin(kTheta);
1153   Double_t kL1 = (kStaveWidth/4)/TMath::Tan(kTheta);
1154   Double_t kS2 = sqrt(kHeight*kHeight + kS1*kS1);//TMath::Sin(the2);
1155   Double_t kThe2 = TMath::ATan(kHeight/kS1);
1156   Double_t kBeta = kThe2*TMath::RadToDeg();
1157   // Double_t lay1 = 0.003157;
1158   Double_t kLay1 = 0.003;//Amec carbon
1159   // Double_t lay2 = 0.0043215;//C Fleece carbon
1160   Double_t kLay2 = 0.002;//C Fleece carbon
1161   Double_t kLay3 = 0.007;//K13D2U carbon
1162   Int_t  loop = (Int_t)(kStaveLength/(2*kL1));
1163
1164
1165   char volname[30];
1166   snprintf(volname, 30, "%s%d_StaveStruct", AliITSUGeomTGeo::GetITSStavePattern(), fLayerNumber);
1167
1168   Double_t z=0, y=-(kConeOutRadius+0.03)+0.0385, x=0;
1169
1170   TGeoVolume *mechStavVol = 0;
1171
1172   if (fBuildLevel < 5) {
1173     // world (trapezoid)
1174     TGeoXtru *mechStruct = new TGeoXtru(2); //z sections
1175     Double_t xv[5] = {kStaveWidth/2+0.1,kStaveWidth/2+0.1,0,-kStaveWidth/2-0.1,-kStaveWidth/2-0.1};
1176     Double_t yv[5] = {-kConeOutRadius*2-0.07,0,kStaveHeigth,0,-kConeOutRadius*2-0.07};    
1177     mechStruct->DefinePolygon(5,xv,yv);
1178     mechStruct->DefineSection(0,-kStaveLength-0.1,0,0,1.);
1179     mechStruct->DefineSection(1,kStaveLength+0.1,0,0,1.);
1180
1181     mechStavVol = new TGeoVolume(volname, mechStruct, medAir);
1182     mechStavVol->SetLineColor(12);
1183     mechStavVol->SetFillColor(12); 
1184     mechStavVol->SetVisibility(kTRUE);  
1185       
1186     //Pipe Kapton grey-35 
1187     TGeoCone *cone1 = new TGeoCone(kStaveLength,kConeInRadius,kConeOutRadius,kConeInRadius,kConeOutRadius);
1188     TGeoVolume *volCone1= new TGeoVolume("PolyimidePipe", cone1, medKapton);
1189     volCone1->SetFillColor(35);
1190     volCone1->SetLineColor(35);
1191     mechStavVol->AddNode(volCone1,1,new TGeoTranslation(x+0.25,y,z));
1192     mechStavVol->AddNode(volCone1,2,new TGeoTranslation(x-0.25,y,z));
1193   }
1194
1195   if (fBuildLevel < 4) {
1196     
1197     TGeoTube *coolTubeW = new TGeoTube(0.,kConeInRadius,kStaveLength);
1198     TGeoVolume *volCoolTubeW= new TGeoVolume("Water", coolTubeW, medWater);
1199     volCoolTubeW->SetFillColor(4);
1200     volCoolTubeW->SetLineColor(4);
1201     mechStavVol->AddNode(volCoolTubeW,0,new TGeoTranslation(x-0.25,y,z));
1202     mechStavVol->AddNode(volCoolTubeW,1,new TGeoTranslation(x+0.25,y,z));
1203   }
1204
1205   if (fBuildLevel < 3) {
1206     //top fillament
1207     // Top filament M60J black-12 Carbon structure TGeoBBox (length,thickness,width)
1208     TGeoBBox *t2=new TGeoBBox(kS2,0.02/2,0.04/2); //TGeoBBox *t2=new TGeoBBox(kS2,0.01,0.02);
1209     TGeoVolume *volT2=new TGeoVolume("TopFilament", t2, medM60J3K);
1210     volT2->SetLineColor(12);
1211     volT2->SetFillColor(12); 
1212     for(int i=0;i<loop;i++){// i<28;i++){
1213       mechStavVol->AddNode(volT2,i*4+1,new TGeoCombiTrans(x+kWidth,y+kHeight+(0.12/2)-0.014+0.007,z-kStaveLength+(i*4*kL1)+kS1/2, new TGeoRotation("volT2",90,90-kAlpha,90-kBeta)));
1214       mechStavVol->AddNode(volT2,i*4+2,new TGeoCombiTrans(x-kWidth,y+kHeight+(0.12/2)-0.014+0.007,z-kStaveLength+(i*4*kL1)+kS1/2, new TGeoRotation("volT2",90,-90+kAlpha,-90+kBeta)));
1215       mechStavVol->AddNode(volT2,i*4+3,new TGeoCombiTrans(x+kWidth,y+kHeight+(0.12/2)-0.014+0.007,z-kStaveLength+2*kL1+(i*4*kL1)+kS1/2, new TGeoRotation("volT2",90,-90+kAlpha,90-kBeta)));
1216       mechStavVol->AddNode(volT2,i*4+4,new TGeoCombiTrans(x-kWidth,y+kHeight+(0.12/2)-0.014+0.007,z-kStaveLength+2*kL1+(i*4*kL1)+kS1/2, new TGeoRotation("volT2",90,90-kAlpha,-90+kBeta)));
1217 //    mechStavVol->AddNode(volT2,i*4+1,new TGeoCombiTrans(x+kWidth+0.0036,y+kHeight-(0.12/2)+0.072,z+kStaveLength+(i*4*kL1)+kS1/2, new TGeoRotation("volT2",90,90-kAlpha,90-kBeta)));
1218
1219  }
1220  
1221     //wall side structure out
1222     TGeoBBox *box4 = new TGeoBBox(0.03/2,0.12/2,kStaveLength-0.50);
1223     TGeoVolume *plate4 = new TGeoVolume("WallOut",box4,medM60J3K);
1224     plate4->SetFillColor(35);
1225     plate4->SetLineColor(35);
1226     mechStavVol->AddNode(plate4,1,new TGeoCombiTrans(x+(2*kStaveWidth/4)-(0.03/2),y-0.0022-kConeOutRadius+0.12/2+0.007,z,new TGeoRotation("plate4",0,0,0)));
1227     mechStavVol->AddNode(plate4,2,new TGeoCombiTrans(x-(2*kStaveWidth/4)+(0.03/2),y-0.0022-kConeOutRadius+0.12/2+0.007,z,new TGeoRotation("plate4",0,0,0)));
1228     //wall side in
1229     TGeoBBox *box5 = new TGeoBBox(0.015/2,0.12/2,kStaveLength-0.50);
1230     TGeoVolume *plate5 = new TGeoVolume("WallIn",box5,medM60J3K);
1231     plate5->SetFillColor(12);
1232     plate5->SetLineColor(12);
1233     mechStavVol->AddNode(plate5,1,new TGeoCombiTrans(x+(2*kStaveWidth/4)-0.03-0.015/2,y-0.0022-kConeOutRadius+0.12/2+0.007,z,new TGeoRotation("plate5",0,0,0)));
1234     mechStavVol->AddNode(plate5,2,new TGeoCombiTrans(x-(2*kStaveWidth/4)+0.03+0.015/2,y-0.0022-kConeOutRadius+0.12/2+0.007,z,new TGeoRotation("plate5",0,0,0)));
1235
1236      //Amec Thermasol red-2 cover tube FGS300
1237     TGeoConeSeg *cons1 = new TGeoConeSeg(kStaveLength-0.50,kConeOutRadius,kConeOutRadius+kLay1,kConeOutRadius,kConeOutRadius+kLay1,0,180);
1238     TGeoVolume *cone11 = new TGeoVolume("ThermasolPipeCover",cons1,medFGS003);
1239     cone11->SetFillColor(2);
1240     cone11->SetLineColor(2);
1241     mechStavVol->AddNode(cone11,1,new TGeoCombiTrans(x+0.25,y,z,new TGeoRotation("Cone11",0,0,0)));
1242     mechStavVol->AddNode(cone11,2,new TGeoCombiTrans(x-0.25,y,z,new TGeoRotation("Cone11",0,0,0)));
1243
1244     TGeoBBox *box2 = new TGeoBBox((0.50-(2*kConeOutRadius))/2,kLay1/2,kStaveLength-0.50);
1245     TGeoVolume *plate2 = new TGeoVolume("ThermasolMiddle",box2,medFGS003);
1246     plate2->SetFillColor(2);
1247     plate2->SetLineColor(2);
1248     mechStavVol->AddNode(plate2,1,new TGeoCombiTrans(x,y-kConeOutRadius+(kLay1/2),z,new TGeoRotation("plate2",0,0,0)));
1249
1250     TGeoBBox *box21 = new TGeoBBox((0.75-0.25-kConeOutRadius-kLay1)/2,kLay1/2,kStaveLength-0.50);
1251     TGeoVolume *plate21 = new TGeoVolume("ThermasolLeftRight",box21,medFGS003);
1252     plate21->SetFillColor(2);
1253     plate21->SetLineColor(2);
1254     mechStavVol->AddNode(plate21,1,new TGeoCombiTrans(x+0.25+kConeOutRadius+(0.75-0.25-kConeOutRadius)/2-(kLay1/2),y-kConeOutRadius+(kLay1/2),z,new TGeoRotation("plate21",0,0,0)));
1255     mechStavVol->AddNode(plate21,2,new TGeoCombiTrans(x-0.25-kConeOutRadius-(0.75-0.25-kConeOutRadius)/2+(kLay1/2),y-kConeOutRadius+(kLay1/2),z,new TGeoRotation("plate21",0,0,0)));
1256
1257     TGeoBBox *box22 = new TGeoBBox((kLay1/2),kConeOutRadius/2,kStaveLength-0.50);
1258     TGeoVolume *plate22 = new TGeoVolume("ThermasolVertical",box22,medFGS003);
1259     plate22->SetFillColor(2);
1260     plate22->SetLineColor(2);
1261     mechStavVol->AddNode(plate22,1,new TGeoCombiTrans(x+0.25+kConeOutRadius+(kLay1/2),y-kConeOutRadius/2,z,new TGeoRotation("plate22",0,0,0)));
1262     mechStavVol->AddNode(plate22,2,new TGeoCombiTrans(x+0.25-kConeOutRadius-(kLay1/2),y-kConeOutRadius/2,z,new TGeoRotation("plate22",0,0,0)));
1263     mechStavVol->AddNode(plate22,3,new TGeoCombiTrans(x-0.25+kConeOutRadius+(kLay1/2),y-kConeOutRadius/2,z,new TGeoRotation("plate22",0,0,0)));
1264     mechStavVol->AddNode(plate22,4,new TGeoCombiTrans(x-0.25-kConeOutRadius-(kLay1/2),y-kConeOutRadius/2,z,new TGeoRotation("plate22",0,0,0)));
1265
1266     //C Fleece
1267     TGeoConeSeg *cons2 = new TGeoConeSeg(kStaveLength-0.50,kConeOutRadius+kLay1,kConeOutRadius+kLay1+kLay2,kConeOutRadius+kLay1,kConeOutRadius+kLay1+kLay2,0,180); 
1268     TGeoVolume *cone12 = new TGeoVolume("CFleecePipeCover",cons2,medCarbonFleece);
1269     cone12->SetFillColor(28);
1270     cone12->SetLineColor(28);
1271     mechStavVol->AddNode(cone12,1,new TGeoCombiTrans(x+0.25,y,z,new TGeoRotation("Cone12",0,0,0)));
1272     mechStavVol->AddNode(cone12,2,new TGeoCombiTrans(x-0.25,y,z,new TGeoRotation("Cone12",0,0,0)));
1273
1274     TGeoBBox *box3 = new TGeoBBox((0.50-(2*(kConeOutRadius+kLay1)))/2,kLay2/2,kStaveLength-0.50);
1275     TGeoVolume *plate3 = new TGeoVolume("CFleeceMiddle",box3,medCarbonFleece);
1276     plate3->SetFillColor(28);
1277     plate3->SetLineColor(28);
1278     mechStavVol->AddNode(plate3,1,new TGeoCombiTrans(x,y-kConeOutRadius+kLay1+(kLay2/2),z,new TGeoRotation("plate3",0,0,0)));
1279
1280     TGeoBBox *box31 = new TGeoBBox((0.75-0.25-kConeOutRadius-kLay1)/2,kLay2/2,kStaveLength-0.50);
1281     TGeoVolume *plate31 = new TGeoVolume("CFleeceLeftRight",box31,medCarbonFleece);
1282     plate31->SetFillColor(28);
1283     plate31->SetLineColor(28);
1284     mechStavVol->AddNode(plate31,1,new TGeoCombiTrans(x+0.25+kConeOutRadius+kLay1+(0.75-0.25-kConeOutRadius-kLay1)/2,y-kConeOutRadius+kLay1+(kLay2/2),z,new TGeoRotation("plate31",0,0,0)));
1285     mechStavVol->AddNode(plate31,2,new TGeoCombiTrans(x-0.25-kConeOutRadius-kLay1-(0.75-0.25-kConeOutRadius-kLay1)/2,y-kConeOutRadius+kLay1+(kLay2/2),z,new TGeoRotation("plate31",0,0,0)));
1286
1287     TGeoBBox *box32 = new TGeoBBox((kLay2/2),(kConeOutRadius-kLay1)/2,kStaveLength-0.50);
1288     TGeoVolume *plate32 = new TGeoVolume("CFleeceVertical",box32,medCarbonFleece);
1289     plate32->SetFillColor(28);
1290     plate32->SetLineColor(28);
1291     mechStavVol->AddNode(plate32,1,new TGeoCombiTrans(x+0.25+kConeOutRadius+kLay1+(kLay2/2),y+(kLay1-kConeOutRadius)/2,z,new TGeoRotation("plate32",0,0,0)));
1292     mechStavVol->AddNode(plate32,2,new TGeoCombiTrans(x+0.25-kConeOutRadius-kLay1-(kLay2/2),y+(kLay1-kConeOutRadius)/2,z,new TGeoRotation("plate32",0,0,0)));
1293     mechStavVol->AddNode(plate32,3,new TGeoCombiTrans(x-0.25+kConeOutRadius+kLay1+(kLay2/2),y+(kLay1-kConeOutRadius)/2,z,new TGeoRotation("plate32",0,0,0)));
1294     mechStavVol->AddNode(plate32,4,new TGeoCombiTrans(x-0.25-kConeOutRadius-kLay1-(kLay2/2),y+(kLay1-kConeOutRadius)/2,z,new TGeoRotation("plate32",0,0,0)));
1295
1296
1297     //K13D2U carbon plate
1298     TGeoBBox *box1 = new TGeoBBox(2*kWidth,kLay3/2,kStaveLength-0.50);
1299     TGeoVolume *plate1 = new TGeoVolume("CarbonPlate",box1,medK13D2U2k);
1300     plate1->SetFillColor(5);
1301     plate1->SetLineColor(5);
1302     mechStavVol->AddNode(plate1,1,new TGeoCombiTrans(x,y-(kConeOutRadius+(kLay3/2)),z,new TGeoRotation("plate1",0,0,0)));
1303
1304     //C Fleece bottom plate 
1305     TGeoBBox *box6 = new TGeoBBox(2*kWidth,kLay2/2,kStaveLength-0.50);
1306     TGeoVolume *plate6 = new TGeoVolume("CFleeceBottom",box6,medCarbonFleece);
1307     plate6->SetFillColor(2);
1308     plate6->SetLineColor(2);
1309     mechStavVol->AddNode(plate6,1,new TGeoCombiTrans(x,y-(kConeOutRadius+kLay3+(kLay2/2)),z,new TGeoRotation("plate1",0,0,0)));
1310       
1311       
1312   }
1313
1314   if (fBuildLevel < 2) {
1315     //Glue layers and kapton
1316     TGeoBBox *glue = new TGeoBBox(kStaveWidth/2, 0.005/2, zsta);
1317     TGeoVolume *volGlue=new TGeoVolume("Glue", glue, medGlue);
1318     volGlue->SetLineColor(5);
1319     volGlue->SetFillColor(5); 
1320     mechStavVol->AddNode(volGlue, 0, new TGeoCombiTrans(x,y-(kConeOutRadius+kLay3+(kLay2/2)+(0.01/2)), z, new TGeoRotation("",0, 0, 0)));
1321     mechStavVol->AddNode(volGlue, 1, new TGeoCombiTrans(x,y-(kConeOutRadius+kLay3+(kLay2/2)+0.01+fSensorThick+(0.01/2)), z, new TGeoRotation("",0, 0, 0)));
1322   }
1323
1324   if (fBuildLevel < 1) {
1325     TGeoBBox *kapCable = new TGeoBBox(kStaveWidth/2, 0.01/2, zsta);
1326     TGeoVolume *volCable=new TGeoVolume("FlexCable", kapCable, medFlexCable);
1327     volCable->SetLineColor(28);
1328     volCable->SetFillColor(28); 
1329     mechStavVol->AddNode(volCable, 0, new TGeoCombiTrans(x, y-(kConeOutRadius+kLay3+(kLay2/2)+0.01+fSensorThick+0.01+(0.01/2)), z, new TGeoRotation("",0, 0, 0)));
1330   }
1331     
1332
1333   // Done, return the stave structure
1334   return mechStavVol;
1335   
1336 }
1337
1338 // new model22
1339 //________________________________________________________________________
1340 TGeoVolume* AliITSUv1Layer::CreateStaveModelInnerB22(const Double_t xsta,
1341                                                      const Double_t zsta,
1342                                                      const TGeoManager *mgr){
1343 //
1344 // Create the mechanical stave structure for Model 2.2 of TDR
1345 //
1346 // Input:
1347 //         xsta : X length
1348 //         zsta : Z length
1349 //         mgr  : the GeoManager (used only to get the proper material)
1350 //
1351 // Output:
1352 //
1353 // Return:
1354 //
1355 // Created:      22 Mar 2013  Chinorat Kobdaj
1356 // Updated:      26 Apr 2013  Mario Sitta
1357 // Updated:      30 Apr 2013  Wanchaloem Poonsawat 
1358 //
1359   
1360   // Materials defined in AliITSUv1
1361   TGeoMedium *medAir    = mgr->GetMedium("ITS_AIR$");
1362   TGeoMedium *medWater  = mgr->GetMedium("ITS_WATER$");
1363
1364   TGeoMedium *medM60J3K    = mgr->GetMedium("ITS_M60J3K$"); 
1365   TGeoMedium *medKapton    = mgr->GetMedium("ITS_KAPTON(POLYCH2)$");
1366   TGeoMedium *medGlue      = mgr->GetMedium("ITS_GLUE$");
1367   TGeoMedium *medFlexCable = mgr->GetMedium("ITS_FLEXCABLE$");
1368   TGeoMedium *medK13D2U2k  = mgr->GetMedium("ITS_K13D2U2k$");
1369   TGeoMedium *medFGS003    = mgr->GetMedium("ITS_FGS003$"); 
1370   TGeoMedium *medCarbonFleece = mgr->GetMedium("ITS_CarbonFleece$"); 
1371
1372   // Local parameters
1373   Double_t kConeOutRadius =(0.1024+0.0025)/2;//0.107/2;
1374   Double_t kConeInRadius = 0.1024/2;//0.10105/2
1375   Double_t kStaveLength = zsta;
1376   Double_t kStaveWidth = xsta*2;
1377   Double_t kWidth = (kStaveWidth)/4;
1378   Double_t kStaveHeight = 0.283;//0.33;
1379   Double_t kHeight = (kStaveHeight)/2;
1380   Double_t kAlpha = 57;//56.31;
1381   Double_t kTheta = kAlpha*TMath::DegToRad();
1382   Double_t kS1 = ((kStaveWidth)/4)/TMath::Sin(kTheta);
1383   Double_t kL1 = (kStaveWidth/4)/TMath::Tan(kTheta);
1384   Double_t kS2 = sqrt(kHeight*kHeight + kS1*kS1);//TMath::Sin(kThe2);
1385   Double_t kThe2 = TMath::ATan(kHeight/(0.375-0.036));
1386   Double_t kBeta = kThe2*TMath::RadToDeg();
1387   Double_t klay1 = 0.003;//Amec carbon
1388   Double_t klay2 = 0.002;//C Fleece carbon
1389   Double_t klay3 = 0.007;//CFplate K13D2U carbon
1390   Double_t klay4 = 0.007;//GluekStaveLength/2
1391   Double_t klay5 = 0.01;//Flex cable
1392   Double_t kTopVertexMaxWidth = 0.072;
1393   Double_t kTopVertexHeight = 0.04;
1394   Double_t kSideVertexMWidth = 0.052;
1395   Double_t kSideVertexHeight = 0.11; 
1396
1397  
1398   Int_t  loop = (Int_t)(kStaveLength/(2*kL1));
1399
1400   char volname[30];
1401   snprintf(volname, 30, "%s%d_StaveStruct", AliITSUGeomTGeo::GetITSStavePattern(), fLayerNumber);
1402
1403   Double_t z=0, y=-(2*kConeOutRadius)+klay1+klay2+fSensorThick/2-0.0004, x=0;
1404
1405   TGeoVolume *mechStavVol = 0;
1406
1407   if (fBuildLevel < 5) {
1408     // world (trapezoid)
1409     TGeoXtru *mechStruct = new TGeoXtru(2); //z sections
1410     Double_t xv[6] = {kStaveWidth/2,kStaveWidth/2,0.012,-0.012,-kStaveWidth/2,-kStaveWidth/2}; 
1411     /* Double_t yv[6] = {-2*(kConeOutRadius+klay1+1.5*klay2+klay3+klay4+fSensorThick+klay5),
1412                         0-0.02,kStaveHeight+0.01,kStaveHeight+0.01,0-0.02,
1413                         -2*(kConeOutRadius+klay1+1.5*klay2+klay3+klay4+fSensorThick+klay5)};  // (kConeOutRadius*2)-0.0635 */
1414     Double_t yv[6] = {-(kConeOutRadius*2)-0.07295,0-0.02,kStaveHeight+0.01,kStaveHeight+0.01,0-0.02,-(kConeOutRadius*2)-0.07295};  // (kConeOutRadius*2)-0.064
1415     mechStruct->DefinePolygon(6,xv,yv);
1416     mechStruct->DefineSection(0,-kStaveLength,0,0,1.);
1417     mechStruct->DefineSection(1,kStaveLength,0,0,1.);
1418
1419     mechStavVol = new TGeoVolume(volname, mechStruct, medAir);
1420     mechStavVol->SetLineColor(12);
1421     mechStavVol->SetFillColor(12); 
1422     mechStavVol->SetVisibility(kTRUE);  
1423       
1424     //Polyimide Pipe Kapton grey-35 
1425     TGeoCone *cone1 = new TGeoCone(kStaveLength,kConeInRadius,kConeOutRadius-0.0001,kConeInRadius,kConeOutRadius-0.0001);
1426     TGeoVolume *volCone1= new TGeoVolume("PolyimidePipe", cone1, medKapton);
1427     volCone1->SetFillColor(35);
1428     volCone1->SetLineColor(35);
1429     mechStavVol->AddNode(volCone1,1,new TGeoTranslation(x+0.25,y,z));
1430     mechStavVol->AddNode(volCone1,2,new TGeoTranslation(x-0.25,y,z));
1431     }
1432
1433   if (fBuildLevel < 4) {
1434     TGeoTube *coolTubeW = new TGeoTube(0.,kConeInRadius-0.0001,kStaveLength);
1435     TGeoVolume *volCoolTubeW= new TGeoVolume("Water", coolTubeW, medWater);
1436     volCoolTubeW->SetFillColor(4);
1437     volCoolTubeW->SetLineColor(4);
1438     mechStavVol->AddNode(volCoolTubeW,0,new TGeoTranslation(x-0.25,y,z));
1439     mechStavVol->AddNode(volCoolTubeW,1,new TGeoTranslation(x+0.25,y,z));
1440   }
1441
1442   if (fBuildLevel < 3) {
1443     //top fillament
1444     // Top filament M60J black-12 Carbon structure TGeoBBox (length,thickness,width)
1445     TGeoBBox *t2=new TGeoBBox(kS2-0.028,0.02/2,0.02/2); //0.04/2//TGeoBBox *t2=new TGeoBBox(kS2,0.01,0.02);//kS2-0.03 old Config.C
1446     TGeoVolume *volT2=new TGeoVolume("TopFilament", t2, medM60J3K);
1447     volT2->SetLineColor(12);
1448     volT2->SetFillColor(12); 
1449     for(int i=0;i<loop;i++){// i<28;i++){
1450       // 1) Front Left Top Filament
1451        mechStavVol->AddNode(volT2,i*4+1,new TGeoCombiTrans(x+kWidth+0.0036,y+kHeight+0.01,z-kStaveLength+0.1+(i*4*kL1)+kS1/2, new TGeoRotation("volT2",90,90-kAlpha,90-kBeta)));
1452       // 2) Front Right Top Filament
1453       mechStavVol->AddNode(volT2,i*4+2,new TGeoCombiTrans(x-kWidth-0.0036,y+kHeight+0.01,z-kStaveLength+0.1+(i*4*kL1)+kS1/2, new TGeoRotation("volT2",90,-90+kAlpha,-90+kBeta)));
1454       // 3) Back Left  Top Filament
1455       mechStavVol->AddNode(volT2,i*4+3,new TGeoCombiTrans(x+kWidth+0.0036,y+kHeight+0.01,z-kStaveLength+0.1+2*kL1+(i*4*kL1)+kS1/2, new TGeoRotation("volT2",90,-90+kAlpha,90-kBeta)));
1456       // 4) Back Right Top Filament
1457       mechStavVol->AddNode(volT2,i*4+4,new TGeoCombiTrans(x-kWidth-0.0036,y+kHeight+0.01,z-kStaveLength+0.1+2*kL1+(i*4*kL1)+kS1/2, new TGeoRotation("volT2",90,90-kAlpha,-90+kBeta)));
1458    }
1459  
1460      //Vertex  structure 
1461
1462       //top ver trd1
1463       TGeoTrd1 *trd1 = new TGeoTrd1(0,kTopVertexMaxWidth/2,kStaveLength,kTopVertexHeight/2);
1464       TGeoVolume *ibdv = new TGeoVolume("TopVertex",trd1,medM60J3K);
1465       ibdv->SetFillColor(12);
1466       ibdv->SetLineColor(12);
1467       mechStavVol->AddNode(ibdv,1,new TGeoCombiTrans(x,y+kStaveHeight+0.03,z,new TGeoRotation("ibdv",0.,-90,0)));//y+kStaveHeight+0.056
1468
1469       //left trd2
1470       TGeoTrd1 *trd2 = new TGeoTrd1(0,kSideVertexMWidth/2,kStaveLength, kSideVertexHeight/2);
1471       TGeoVolume *ibdv2 = new TGeoVolume("LeftVertex",trd2,medM60J3K);
1472       ibdv2->SetFillColor(12);
1473       ibdv2->SetLineColor(12);
1474       mechStavVol->AddNode(ibdv2,1,new TGeoCombiTrans(x+kStaveWidth/2-0.06,y-0.0348,z,new TGeoRotation("ibdv2",-103.3,90,0))); //x-kStaveWidth/2-0.09 old Config.C y-0.0355,
1475
1476       //right trd3
1477       TGeoTrd1 *trd3 = new TGeoTrd1(0,kSideVertexMWidth/2,kStaveLength, kSideVertexHeight/2);
1478       TGeoVolume *ibdv3 = new TGeoVolume("RightVertex",trd3,medM60J3K);
1479       ibdv3->SetFillColor(12);
1480       ibdv3->SetLineColor(12);
1481       mechStavVol->AddNode(ibdv3,1,new TGeoCombiTrans(x-kStaveWidth/2+0.06,y-0.0348,z,new TGeoRotation("ibdv3",103.3,90,0))); //x-kStaveWidth/2+0.09 old Config.C
1482       
1483      //Carbon Fleece
1484       TGeoConeSeg *cons2 = new TGeoConeSeg(zsta,kConeOutRadius+klay1,kConeOutRadius+klay1+klay2,kConeOutRadius+klay1,kConeOutRadius+klay1+klay2,0,180); 
1485       TGeoVolume *cone12 = new TGeoVolume("CarbonFleecePipeCover",cons2,medCarbonFleece);
1486       cone12->SetFillColor(28);
1487       cone12->SetLineColor(28);
1488       mechStavVol->AddNode(cone12,1,new TGeoCombiTrans(x+0.25,y,z,new TGeoRotation("cone12",0,0,0)));
1489       mechStavVol->AddNode(cone12,2,new TGeoCombiTrans(x-0.25,y,z,new TGeoRotation("cone12",0,0,0)));
1490
1491       TGeoBBox *box3 = new TGeoBBox((0.50-(2*(kConeOutRadius+klay1)))/2,klay2/2,zsta);//kStaveLength-0.50);
1492       TGeoVolume *plate3 = new TGeoVolume("CarbonFleeceMiddle",box3,medCarbonFleece);
1493       plate3->SetFillColor(28);
1494       plate3->SetLineColor(28);
1495       mechStavVol->AddNode(plate3,1,new TGeoCombiTrans(x,y-kConeOutRadius+klay1+(klay2/2),z,new TGeoRotation("plate3",0,0,0)));
1496
1497       TGeoBBox *box31 = new TGeoBBox((0.75-0.25-kConeOutRadius-klay1)/2+0.0025,klay2/2,zsta);
1498       TGeoVolume *plate31 = new TGeoVolume("CarbonFleeceLeftRight",box31,medCarbonFleece);
1499       plate31->SetFillColor(28);
1500       plate31->SetLineColor(28);
1501       mechStavVol->AddNode(plate31,1,new TGeoCombiTrans(x+0.25+kConeOutRadius+klay1+(0.75-0.25-kConeOutRadius-klay1)/2,y-kConeOutRadius+klay1+(klay2/2),z,new TGeoRotation("plate31",0,0,0)));
1502       mechStavVol->AddNode(plate31,2,new TGeoCombiTrans(x-0.25-kConeOutRadius-klay1-(0.75-0.25-kConeOutRadius-klay1)/2,y-kConeOutRadius+klay1+(klay2/2),z,new TGeoRotation("plate31",0,0,0)));
1503
1504       TGeoBBox *box32 = new TGeoBBox((klay2/2),(kConeOutRadius-klay1)/2,zsta);
1505       TGeoVolume *plate32 = new TGeoVolume("CarbonFleeceVertical",box32,medCarbonFleece);
1506       plate32->SetFillColor(28);
1507       plate32->SetLineColor(28);
1508       mechStavVol->AddNode(plate32,1,new TGeoCombiTrans(x+0.25+kConeOutRadius+klay1+(klay2/2),y+(klay1-kConeOutRadius)/2,z,new TGeoRotation("plate32",0,0,0)));
1509       mechStavVol->AddNode(plate32,2,new TGeoCombiTrans(x+0.25-kConeOutRadius-klay1-(klay2/2),y+(klay1-kConeOutRadius)/2,z,new TGeoRotation("plate32",0,0,0)));
1510       mechStavVol->AddNode(plate32,3,new TGeoCombiTrans(x-0.25+kConeOutRadius+klay1+(klay2/2),y+(klay1-kConeOutRadius)/2,z,new TGeoRotation("plate32",0,0,0)));
1511       mechStavVol->AddNode(plate32,4,new TGeoCombiTrans(x-0.25-kConeOutRadius-klay1-(klay2/2),y+(klay1-kConeOutRadius)/2,z,new TGeoRotation("plate32",0,0,0)));
1512
1513      //Amec Thermasol red-2 cover tube FGS300 or Carbon Paper
1514       TGeoConeSeg *cons1 = new TGeoConeSeg(zsta,kConeOutRadius,kConeOutRadius+klay1-0.0001,kConeOutRadius,kConeOutRadius+klay1-0.0001,0,180);//kConeOutRadius+klay1-0.0001
1515       TGeoVolume *cone11 = new TGeoVolume("ThermasolPipeCover",cons1,medFGS003);
1516       cone11->SetFillColor(2);
1517       cone11->SetLineColor(2);
1518       mechStavVol->AddNode(cone11,1,new TGeoCombiTrans(x+0.25,y,z,new TGeoRotation("cone11",0,0,0)));
1519       mechStavVol->AddNode(cone11,2,new TGeoCombiTrans(x-0.25,y,z,new TGeoRotation("cone11",0,0,0)));
1520
1521       TGeoBBox *box2 = new TGeoBBox((0.50-(2*kConeOutRadius))/2,(klay1/2),zsta);//kStaveLength-0.50);
1522       TGeoVolume *plate2 = new TGeoVolume("ThermasolMiddle",box2,medFGS003);
1523       plate2->SetFillColor(2);
1524       plate2->SetLineColor(2);
1525       mechStavVol->AddNode(plate2,1,new TGeoCombiTrans(x,y-kConeOutRadius+(klay1/2),z,new TGeoRotation("plate2",0,0,0)));
1526
1527       TGeoBBox *box21 = new TGeoBBox((0.75-0.25-kConeOutRadius-klay1)/2+0.0025,(klay1/2),zsta);
1528       TGeoVolume *plate21 = new TGeoVolume("ThermasolLeftRight",box21,medFGS003);
1529       plate21->SetFillColor(2);
1530       plate21->SetLineColor(2);
1531       mechStavVol->AddNode(plate21,1,new TGeoCombiTrans(x+0.25+kConeOutRadius+(0.75-0.25-kConeOutRadius)/2-(klay1/2)+0.0025,y-kConeOutRadius+(klay1/2),z,new TGeoRotation("plate21",0,0,0)));
1532       mechStavVol->AddNode(plate21,2,new TGeoCombiTrans(x-0.25-kConeOutRadius-(0.75-0.25-kConeOutRadius)/2+(klay1/2)-0.0025,y-kConeOutRadius+(klay1/2),z,new TGeoRotation("plate21",0,0,0)));
1533
1534       TGeoBBox *box22 = new TGeoBBox((klay1/2),kConeOutRadius/2,zsta);
1535       TGeoVolume *plate22 = new TGeoVolume("ThermasolVertical",box22,medFGS003);
1536       plate22->SetFillColor(2);
1537       plate22->SetLineColor(2);
1538       mechStavVol->AddNode(plate22,1,new TGeoCombiTrans(x+0.25+kConeOutRadius+(klay1/2),y-kConeOutRadius/2,z,new TGeoRotation("plate22",0,0,0)));
1539       mechStavVol->AddNode(plate22,2,new TGeoCombiTrans(x+0.25-kConeOutRadius-(klay1/2),y-kConeOutRadius/2,z,new TGeoRotation("plate22",0,0,0)));
1540       mechStavVol->AddNode(plate22,3,new TGeoCombiTrans(x-0.25+kConeOutRadius+(klay1/2),y-kConeOutRadius/2,z,new TGeoRotation("plate22",0,0,0)));
1541       mechStavVol->AddNode(plate22,4,new TGeoCombiTrans(x-0.25-kConeOutRadius-(klay1/2),y-kConeOutRadius/2,z,new TGeoRotation("plate22",0,0,0)));
1542
1543      //K13D2U CF plate
1544       TGeoBBox *box1 = new TGeoBBox(2*kWidth,(klay3)/2,zsta);
1545       TGeoVolume *plate1 = new TGeoVolume("CFPlate",box1,medK13D2U2k);
1546       plate1->SetFillColor(5);
1547       plate1->SetLineColor(5);
1548       mechStavVol->AddNode(plate1,1,new TGeoCombiTrans(x,y-(kConeOutRadius+(klay3/2)),z,new TGeoRotation("plate1",0,0,0)));
1549
1550      //C Fleece bottom plate 
1551       TGeoBBox *box6 = new TGeoBBox(2*kWidth,(klay2)/2,zsta);
1552       TGeoVolume *plate6 = new TGeoVolume("CarbonFleeceBottom",box6,medCarbonFleece);
1553       plate6->SetFillColor(2);
1554       plate6->SetLineColor(2);
1555       mechStavVol->AddNode(plate6,1,new TGeoCombiTrans(x,y-(kConeOutRadius+klay3+(klay2/2)),z,new TGeoRotation("plate6",0,0,0)));
1556
1557     }
1558    if (fBuildLevel < 2) {
1559       //Glue klayers and kapton
1560      TGeoBBox *glue = new TGeoBBox(kStaveWidth/2, (klay4)/2, zsta);
1561       TGeoVolume *volGlue=new TGeoVolume("Glue", glue, medGlue);
1562       volGlue->SetLineColor(5);
1563       volGlue->SetFillColor(5); 
1564       // mechStavVol->AddNode(volGlue, 0, new TGeoCombiTrans(x,y-(kConeOutRadius+klay3+klay2+(klay4/2)), z, new TGeoRotation("",0, 0, 0)));
1565       mechStavVol->AddNode(volGlue, 0, new TGeoCombiTrans(x,y-(kConeOutRadius+klay3+klay2+(klay4)/2)+0.00005, z, new TGeoRotation("",0, 0, 0)));
1566     }
1567
1568      if (fBuildLevel < 1) {
1569      //Flex Cable or Bus
1570       TGeoBBox *kapCable = new TGeoBBox(kStaveWidth/2, klay5/2, zsta);//klay5/2
1571       TGeoVolume *volCable=new TGeoVolume("FlexCable", kapCable, medFlexCable);
1572       volCable->SetLineColor(28);
1573       volCable->SetFillColor(28); 
1574       //      mechStavVol->AddNode(volCable, 0, new TGeoCombiTrans(x, y-(kConeOutRadius+klay3+klay2+klay4+fSensorThick+(klay5)/2)+0.0002, z, new TGeoRotation("",0, 0, 0)));
1575       mechStavVol->AddNode(volCable, 0, new TGeoCombiTrans(x, y-(kConeOutRadius+klay3+klay2+klay4+(klay5)/2), z, new TGeoRotation("",0, 0, 0)));
1576       }
1577     // Done, return the stave structe
1578     return mechStavVol;
1579 }
1580
1581 // model3
1582 //________________________________________________________________________
1583 TGeoVolume* AliITSUv1Layer::CreateStaveModelInnerB3(const Double_t xsta,
1584                                                     const Double_t zsta,
1585                                                     const TGeoManager *mgr){
1586 //
1587 // Create the mechanical stave structure for Model 3 of TDR
1588 //
1589 // Input:
1590 //         xsta : X length
1591 //         zsta : Z length
1592 //         mgr  : the GeoManager (used only to get the proper material)
1593 //
1594 // Output:
1595 //
1596 // Return:
1597 //
1598 // Created:      28 May 2013  Chinorat Kobdaj
1599 // Updated:                   Mario Sitta
1600 // Updated:                   Wanchaloem Poonsawat 
1601 //
1602   
1603   // Materials defined in AliITSUv1
1604   TGeoMedium *medAir    = mgr->GetMedium("ITS_AIR$");
1605   TGeoMedium *medWater  = mgr->GetMedium("ITS_WATER$");
1606
1607   TGeoMedium *medM60J3K    = mgr->GetMedium("ITS_M60J3K$"); 
1608   TGeoMedium *medKapton    = mgr->GetMedium("ITS_KAPTON(POLYCH2)$");
1609   TGeoMedium *medGlue      = mgr->GetMedium("ITS_GLUE$");
1610   TGeoMedium *medFlexCable = mgr->GetMedium("ITS_FLEXCABLE$");
1611   //TGeoMedium *medK13D2U2k  = mgr->GetMedium("ITS_K13D2U2k$");
1612   //TGeoMedium *medFGS003    = mgr->GetMedium("ITS_FGS003$"); 
1613   //TGeoMedium *medCarbonFleece = mgr->GetMedium("ITS_CarbonFleece$"); 
1614
1615   // Local parameters
1616     Double_t kConeOutRadius = 0.15/2;
1617     Double_t kStaveLength = zsta*2;
1618     Double_t kStaveWidth = xsta*2;
1619     Double_t w = kStaveWidth/4;//1/2 of W
1620     Double_t staveHeight = 0.3;
1621     Double_t h = staveHeight/2;
1622     Double_t alpha = 90-33.;//90-30;
1623     Double_t the1 = alpha*TMath::DegToRad();
1624     Double_t s1 = w/TMath::Sin(the1);
1625     Double_t l = w/TMath::Tan(the1);
1626     Double_t s2 = TMath::Sqrt(h*h + s1*s1);//TMath::Sin(the2);
1627     Double_t the2 = TMath::ATan(h/s1);
1628     Double_t beta = the2*TMath::RadToDeg();
1629     Double_t klay4 = 0.007; //Glue
1630     Double_t klay5 = 0.01; //Flexcable
1631     Int_t  loop = (Int_t)((kStaveLength/(2*l))/2);
1632     Double_t hh = 0.01;
1633        Double_t ang1 = 0*TMath::DegToRad();
1634        Double_t ang2 = 0*TMath::DegToRad();
1635        Double_t ang3 = 0*TMath::DegToRad();
1636        Int_t chips = 4;
1637        Double_t headWidth=0.25;
1638        Double_t smcLength=kStaveLength/chips-2*headWidth;//6.25;
1639        Double_t smcWidth=kStaveWidth;
1640        Double_t smcSide1Thick=0.03;
1641        Double_t vaporThick=0.032;
1642        Double_t liquidThick=0.028;
1643        Double_t smcSide2Thick=0.01;
1644        Double_t smcSide3Thick=0.0055;
1645        Double_t smcSide4Thick=0.0095;
1646        Double_t smcSide5Thick=0.0075;
1647        Double_t smcSpace=0.01;
1648
1649
1650     char volname[30];
1651     snprintf(volname, 30, "%s%d_StaveStruct", AliITSUGeomTGeo::GetITSStavePattern(), fLayerNumber);
1652     
1653     // detailed structure ++++++++++++++
1654     Double_t z=0, y=0-0.007, x=0;
1655
1656     // Polimide micro channels numbers
1657     Double_t yMC = y-h+0.01;
1658     Int_t nb = (Int_t)(kStaveWidth/0.1)+1;
1659     Double_t xstaMC = (nb*0.1-0.08)/2;
1660
1661
1662     TGeoVolume *mechStavVol = 0;
1663     if (fBuildLevel < 5) {
1664       // world (trapezoid)
1665       TGeoXtru *mechStruct = new TGeoXtru(2); //z sections
1666       Double_t xv[5] = {kStaveWidth/2+0.1,kStaveWidth/2+0.1,0,-kStaveWidth/2-0.1,-kStaveWidth/2-0.1};
1667       Double_t yv[5] = {-kConeOutRadius*2-0.07,0,staveHeight,0,-kConeOutRadius*2-0.07};    
1668       mechStruct->DefinePolygon(5,xv,yv);
1669       mechStruct->DefineSection(0,-kStaveLength-0.1,0,0,1.);
1670       mechStruct->DefineSection(1,kStaveLength+0.1,0,0,1.);
1671       mechStavVol = new TGeoVolume(volname, mechStruct, medAir);
1672       mechStavVol->SetLineColor(12);
1673       mechStavVol->SetFillColor(12); 
1674       mechStavVol->SetVisibility(kTRUE);
1675
1676        // Silicon micro channels numbers
1677       
1678       TGeoBBox *tM0a=new TGeoBBox(smcWidth/2, 0.003/2, headWidth/2);
1679       TGeoVolume *volTM0a=new TGeoVolume("microChanTop1", tM0a, medKapton);
1680       volTM0a->SetLineColor(35);
1681       volTM0a->SetFillColor(35); 
1682
1683       for(Int_t  mo=1; mo<=chips; mo++) {
1684       mechStavVol->AddNode(volTM0a, 0, new TGeoCombiTrans(x,yMC+0.03, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth+smcLength/2+(headWidth/2), new TGeoRotation("",ang1, ang2, ang3)));
1685       mechStavVol->AddNode(volTM0a, 1, new TGeoCombiTrans(x,yMC+0.03, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth-smcLength/2-(headWidth/2), new TGeoRotation("",ang1, ang2, ang3)));
1686       }
1687       TGeoBBox *tM0c=new TGeoBBox(0.3/2, 0.003/2,smcLength/2);
1688       TGeoVolume *volTM0c=new TGeoVolume("microChanTop2", tM0c, medKapton);
1689       volTM0c->SetLineColor(35);
1690       volTM0c->SetFillColor(35); 
1691       for(Int_t  mo=1; mo<=chips; mo++) {
1692       mechStavVol->AddNode(volTM0c, 0, new TGeoCombiTrans(x+(smcWidth/2)-(0.3/2),yMC+0.03, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));
1693       mechStavVol->AddNode(volTM0c, 1, new TGeoCombiTrans(x-(smcWidth/2)+(0.3/2),yMC+0.03, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
1694       }
1695       TGeoBBox *tM0c1=new TGeoBBox(0.2225/2, 0.003/2,smcLength/2);
1696       TGeoVolume *volTM0c1=new TGeoVolume("microChanBot1", tM0c1, medKapton);
1697       volTM0c1->SetLineColor(6);
1698       volTM0c1->SetFillColor(6); 
1699       for(Int_t  mo=1; mo<=chips; mo++) {
1700       mechStavVol->AddNode(volTM0c1, 0, new TGeoCombiTrans(x+smcWidth/2-(smcSide1Thick)-(vaporThick)-(smcSide2Thick)-(smcSide3Thick)-(0.2225/2),yMC+0.03-hh-(0.003), z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
1701       mechStavVol->AddNode(volTM0c1, 1, new TGeoCombiTrans(x-smcWidth/2+(smcSide1Thick)+(liquidThick)+(smcSide2Thick)+(smcSide4Thick)+(0.2225/2),yMC+0.03-hh-(0.003), z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
1702       }
1703       TGeoBBox *tM0c2=new TGeoBBox(0.072/2, 0.003/2,smcLength/2);
1704       TGeoVolume *volTM0c2=new TGeoVolume("microChanBot2", tM0c2, medKapton);
1705       volTM0c2->SetLineColor(35);
1706       volTM0c2->SetFillColor(35); 
1707       for(Int_t  mo=1; mo<=chips; mo++) {
1708       mechStavVol->AddNode(volTM0c2, 0, new TGeoCombiTrans(x+smcWidth/2-(0.072/2),yMC+0.03-(0.035+0.0015)-(0.003)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
1709       }
1710       TGeoBBox *tM0c2r=new TGeoBBox(0.068/2, 0.003/2,smcLength/2);
1711       TGeoVolume *volTM0c2r=new TGeoVolume("microChanBot3", tM0c2r, medKapton);
1712       volTM0c2r->SetLineColor(35);
1713       volTM0c2r->SetFillColor(35); 
1714       for(Int_t  mo=1; mo<=chips; mo++) {      
1715       mechStavVol->AddNode(volTM0c2r, 0, new TGeoCombiTrans(x-smcWidth/2+(0.068/2),yMC+0.03-(0.035+0.0015)-(0.003)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
1716       }
1717       TGeoBBox *tM0d=new TGeoBBox(smcSide1Thick/2, 0.035/2,smcLength/2);
1718       TGeoVolume *volTM0d=new TGeoVolume("microChanSide1", tM0d, medKapton);
1719       volTM0d->SetLineColor(12);
1720       volTM0d->SetFillColor(12); 
1721       for(Int_t  mo=1; mo<=chips; mo++) {
1722       mechStavVol->AddNode(volTM0d, 0, new TGeoCombiTrans(x+smcWidth/2-(smcSide1Thick/2),yMC+0.03-0.0015-(0.035)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
1723       mechStavVol->AddNode(volTM0d, 1, new TGeoCombiTrans(x-smcWidth/2+(smcSide1Thick/2),yMC+0.03-0.0015-(0.035)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
1724       }
1725
1726       TGeoBBox *tM0d1=new TGeoBBox(smcSide2Thick/2, 0.035/2,smcLength/2);
1727       TGeoVolume *volTM0d1=new TGeoVolume("microChanSide2", tM0d1, medKapton);
1728       volTM0d1->SetLineColor(12);
1729       volTM0d1->SetFillColor(12); 
1730       for(Int_t  mo=1; mo<=chips; mo++) {
1731       mechStavVol->AddNode(volTM0d1, 0, new TGeoCombiTrans(x+smcWidth/2-(smcSide1Thick)-(vaporThick)-(smcSide2Thick/2),yMC+0.03-(0.003+0.035)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
1732       mechStavVol->AddNode(volTM0d1, 1, new TGeoCombiTrans(x-smcWidth/2+(smcSide1Thick)+(liquidThick)+(smcSide2Thick/2),yMC+0.03-(0.003+0.035)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
1733       }
1734       TGeoBBox *tM0d2=new TGeoBBox(smcSide3Thick/2, (hh+0.003)/2, smcLength/2);
1735       TGeoVolume *volTM0d2=new TGeoVolume("microChanSide3", tM0d2, medKapton);
1736       volTM0d2->SetLineColor(12);
1737       volTM0d2->SetFillColor(12); 
1738       for(Int_t  mo=1; mo<=chips; mo++) {
1739       mechStavVol->AddNode(volTM0d2, 0, new TGeoCombiTrans(x+smcWidth/2-(smcSide1Thick)-(vaporThick)-(smcSide2Thick)-(smcSide3Thick/2),yMC+0.03-(0.003+hh+0.003)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
1740       }
1741       TGeoBBox *tM0d2r=new TGeoBBox(smcSide4Thick/2, (hh+0.003)/2, smcLength/2);
1742       TGeoVolume *volTM0d2r=new TGeoVolume("microChanSide4", tM0d2r, medKapton);
1743       volTM0d2r->SetLineColor(12);
1744       volTM0d2r->SetFillColor(12); 
1745       for(Int_t  mo=1; mo<=chips; mo++) {
1746       mechStavVol->AddNode(volTM0d2r, 0, new TGeoCombiTrans(x-smcWidth/2+(smcSide1Thick)+(liquidThick)+(smcSide2Thick)+(smcSide4Thick/2),yMC+0.03-(0.003+hh+0.003)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
1747       }
1748       TGeoBBox *tM0e=new TGeoBBox(smcSide5Thick/2, hh/2,smcLength/2);
1749       TGeoVolume *volTM0e=new TGeoVolume("microChanSide5", tM0e, medKapton);    
1750       volTM0e->SetLineColor(12);
1751       volTM0e->SetFillColor(12); 
1752       for(Int_t  mo=1; mo<=chips; mo++) {
1753       for (Int_t ie=0;ie<11;ie++) {
1754         mechStavVol->AddNode(volTM0e, 0, new TGeoCombiTrans(x-(ie*(smcSpace+smcSide5Thick))+smcWidth/2-(smcSide1Thick)-(vaporThick)-(smcSide2Thick)-(smcSide3Thick)-smcSpace-(smcSide5Thick/2),yMC+0.03-(0.003+hh)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
1755         mechStavVol->AddNode(volTM0e, 1, new TGeoCombiTrans(x+(ie*(smcSpace+smcSide5Thick))-smcWidth/2+(smcSide1Thick)+(liquidThick)+(smcSide2Thick)+(smcSide4Thick)+smcSpace+(smcSide5Thick/2),yMC+0.03-(0.003+hh)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
1756          }
1757       }
1758       
1759       TGeoBBox *tM0f=new TGeoBBox(0.02/2, hh/2, smcLength/2);
1760       TGeoVolume *volTM0f=new TGeoVolume("microChanTop3", tM0f, medKapton);
1761       //Double_t smcChannels=12;
1762       Double_t smcCloseWallvapor=smcWidth/2-smcSide1Thick-vaporThick-smcSide2Thick-smcSide3Thick-12*smcSpace-11*smcSide5Thick;
1763       Double_t smcCloseWallliquid=smcWidth/2-smcSide1Thick-liquidThick-smcSide2Thick-smcSide4Thick-12*smcSpace-11*smcSide5Thick;
1764       volTM0f->SetLineColor(12);
1765       volTM0f->SetFillColor(12); 
1766       for(Int_t  mo=1; mo<=chips; mo++) {
1767        mechStavVol->AddNode(volTM0f, 0, new TGeoCombiTrans(x+smcCloseWallvapor-(0.02)/2,yMC+0.03-(0.003+hh)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
1768        mechStavVol->AddNode(volTM0f, 1, new TGeoCombiTrans(x-smcCloseWallliquid+(0.02)/2,yMC+0.03-(0.003+hh)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
1769       }
1770       //Head(back) microchannel
1771
1772       TGeoBBox *tM0hb=new TGeoBBox(smcWidth/2, 0.025/2, headWidth/2);
1773       TGeoVolume *volTM0hb=new TGeoVolume("microChanHeadBackBottom1", tM0hb, medKapton);
1774       volTM0hb->SetLineColor(4);
1775       volTM0hb->SetFillColor(4); 
1776       for(Int_t  mo=1; mo<=chips; mo++) {
1777       mechStavVol->AddNode(volTM0hb, 0, new TGeoCombiTrans(x,yMC+0.03-0.0145-(0.025/2), z+(mo-3)*kStaveLength/4+smcLength/2+headWidth+smcLength/2+(headWidth/2), new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
1778       mechStavVol->AddNode(volTM0hb, 1, new TGeoCombiTrans(x,yMC+0.03-0.0145-(0.025)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth-smcLength/2-(headWidth/2), new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
1779       }
1780       TGeoBBox *tM0h1=new TGeoBBox(smcWidth/2, 0.013/2, 0.05/2);
1781       TGeoVolume *volTM0h1=new TGeoVolume("microChanHeadBackBottom2", tM0h1, medKapton);
1782       volTM0h1->SetLineColor(5);
1783       volTM0h1->SetFillColor(5); 
1784       for(Int_t  mo=1; mo<=chips; mo++) {
1785       mechStavVol->AddNode(volTM0h1, 0, new TGeoCombiTrans(x,yMC+0.03-0.0015-(0.013/2), z+(mo-3)*kStaveLength/4+smcLength/2+headWidth-smcLength/2-headWidth+(0.05/2), new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
1786       }
1787       TGeoBBox *tM0h2=new TGeoBBox(smcWidth/2, 0.003/2, 0.18/2);
1788       TGeoVolume *volTM0h2=new TGeoVolume("microChanHeadBackBottom7", tM0h2, medKapton);
1789       volTM0h2->SetLineColor(6);
1790       volTM0h2->SetFillColor(6);
1791       for(Int_t  mo=1; mo<=chips; mo++) {
1792       mechStavVol->AddNode(volTM0h2, 0, new TGeoCombiTrans(x,yMC+0.03-0.0015-0.01-(0.003/2), z+(mo-3)*kStaveLength/4+smcLength/2+headWidth-smcLength/2-0.02-(0.18/2), new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
1793       }
1794       TGeoBBox *tM0h3=new TGeoBBox(smcWidth/2, 0.013/2, 0.02/2);
1795       TGeoVolume *volTM0h3=new TGeoVolume("microChanHeadBackBottom3", tM0h3, medKapton);
1796       volTM0h3->SetLineColor(5);
1797       volTM0h3->SetFillColor(5); 
1798       for(Int_t  mo=1; mo<=chips; mo++) {
1799       mechStavVol->AddNode(volTM0h3, 0, new TGeoCombiTrans(x,yMC+0.03-0.0015-(0.013/2), z+(mo-3)*kStaveLength/4+smcLength/2+headWidth-smcLength/2-(0.02/2), new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
1800       }
1801       TGeoBBox *tM0b1=new TGeoBBox(smcWidth/2, 0.013/2, 0.03/2);
1802       TGeoVolume *volTM0b1=new TGeoVolume("microChanHeadBackBottom4", tM0b1, medKapton);
1803       volTM0b1->SetLineColor(5);
1804       volTM0b1->SetFillColor(5); 
1805       for(Int_t  mo=1; mo<=chips; mo++) {
1806       mechStavVol->AddNode(volTM0b1, 0, new TGeoCombiTrans(x,yMC+0.03-0.0015-(0.013/2), z+(mo-3)*kStaveLength/4+smcLength/2+headWidth+smcLength/2+headWidth-(0.03/2), new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
1807       }
1808       TGeoBBox *tM0b2=new TGeoBBox(smcWidth/2, 0.003/2, 0.2/2);
1809       TGeoVolume *volTM0b2=new TGeoVolume("microChanHeadBackBottom5", tM0b2, medKapton);
1810       volTM0b2->SetLineColor(6);
1811       volTM0b2->SetFillColor(6); 
1812       for(Int_t  mo=1; mo<=chips; mo++) {
1813       mechStavVol->AddNode(volTM0b2, 0, new TGeoCombiTrans(x,yMC+0.03-0.0015-0.01-(0.003/2), z+(mo-3)*kStaveLength/4+smcLength/2+headWidth+smcLength/2+0.02+(0.2/2), new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
1814       }
1815       TGeoBBox *tM0b3=new TGeoBBox(smcWidth/2, 0.013/2, 0.02/2);
1816       TGeoVolume *volTM0b3=new TGeoVolume("microChanHeadBackBottom6", tM0b3, medKapton);
1817       volTM0b3->SetLineColor(5);
1818       volTM0b3->SetFillColor(5); 
1819       for(Int_t  mo=1; mo<=chips; mo++) {
1820       mechStavVol->AddNode(volTM0b3, 0, new TGeoCombiTrans(x,yMC+0.03-0.0015-(0.013/2), z+(mo-3)*kStaveLength/4+smcLength/2+headWidth+smcLength/2+(0.02/2), new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
1821       }
1822      
1823       TGeoBBox *tM0b=new TGeoBBox(0.02/2, 0.02/2, zsta);
1824       TGeoVolume *volTM0b=new TGeoVolume("microChanWalls", tM0b, medKapton);
1825       volTM0b->SetLineColor(35);
1826       volTM0b->SetFillColor(35); 
1827       for (Int_t ib=0;ib<nb;ib++) {
1828         //mechStavVol->AddNode(volTM0b, ib, new TGeoCombiTrans(x+ib*0.1-xstaMC+0.01,yMC, z, new TGeoRotation("",0, 0, 0)));
1829       }
1830       
1831       } 
1832     
1833     if (fBuildLevel < 4) {
1834
1835       //**********cooling  inlet outlet
1836
1837       TGeoBBox *tM0dv=new TGeoBBox(vaporThick/2, 0.035/2,smcLength/2);
1838       TGeoVolume *volTM0dv=new TGeoVolume("microChanVapor", tM0dv, medWater);
1839       volTM0dv->SetLineColor(2);
1840       volTM0dv->SetFillColor(2);
1841       for(Int_t  mo=1; mo<=chips; mo++) {
1842       mechStavVol->AddNode(volTM0dv, 0, new TGeoCombiTrans(x+smcWidth/2-(smcSide1Thick)-(vaporThick/2),yMC+0.03-0.0015-(0.035)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
1843       }
1844       TGeoBBox *tM0dl=new TGeoBBox(liquidThick/2, 0.035/2,smcLength/2);
1845       TGeoVolume *volTM0dl=new TGeoVolume("microChanLiquid", tM0dl, medWater);
1846       volTM0dl->SetLineColor(3);
1847       volTM0dl->SetFillColor(3); 
1848       for(Int_t  mo=1; mo<=chips; mo++) {
1849       mechStavVol->AddNode(volTM0dl, 0, new TGeoCombiTrans(x-smcWidth/2+(smcSide1Thick)+(liquidThick/2),yMC+0.03-0.0015-(0.035)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
1850       }
1851       // small cooling fluid now using water wait for freeon value  
1852       TGeoBBox *tM0dlq=new TGeoBBox(smcSpace/2, hh/2,smcLength/2);
1853       TGeoVolume *volTM0dlq=new TGeoVolume("smallLiquid", tM0dlq, medWater);
1854       volTM0dlq->SetLineColor(3);
1855       volTM0dlq->SetFillColor(3); 
1856       TGeoBBox *tM0dvp=new TGeoBBox(smcSpace/2, hh/2,smcLength/2);
1857       TGeoVolume *volTM0dvp=new TGeoVolume("microChanVapor", tM0dvp, medWater);
1858       volTM0dvp->SetLineColor(2);
1859       volTM0dvp->SetFillColor(2); 
1860       for(Int_t  mo=1; mo<=chips; mo++) {
1861       for (Int_t is=0;is<12;is++) {
1862         mechStavVol->AddNode(volTM0dlq, 0, new TGeoCombiTrans(x+(is*(smcSpace+smcSide5Thick))-smcWidth/2+(smcSide1Thick)+(vaporThick)+(smcSide2Thick)+(smcSide3Thick)+smcSpace/2,yMC+0.03-(0.003+hh)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
1863         mechStavVol->AddNode(volTM0dvp, 1, new TGeoCombiTrans(x-(is*(smcSpace+smcSide5Thick))+smcWidth/2-(smcSide1Thick)-(vaporThick)-(smcSide2Thick)-(smcSide3Thick)-smcSpace/2,yMC+0.03-(0.003+hh)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
1864       }
1865       }
1866
1867       //*************
1868
1869     }
1870     
1871     if (fBuildLevel < 3) {
1872
1873       //Bottom filament CFRP black-12 Carbon structure TGeoBBox (thickness,width,length)
1874  
1875       Double_t filWidth = 0.04;
1876       Double_t filHeight= 0.02;
1877       TGeoBBox *t1=new TGeoBBox(filHeight/2,filWidth/2,s1);
1878       TGeoVolume *volT1=new TGeoVolume("bottomFilament", t1, medM60J3K);
1879       volT1->SetLineColor(12);
1880       volT1->SetFillColor(12); 
1881       for(int i=0;i<loop;i++){//i<30;i++){
1882         mechStavVol->AddNode(volT1,4*i+0,
1883                                     new TGeoCombiTrans(x+w,y-h+0.04+filHeight/2,z-kStaveLength/2+(4*l*i)+s1/2, 
1884                                                        new TGeoRotation("volT1",-90,alpha,0)));
1885         mechStavVol->AddNode(volT1,4*i+1,
1886                                     new TGeoCombiTrans(x-w,y-h+0.04+filHeight/2,z-kStaveLength/2+(4*l*i)+s1/2, 
1887                                                        new TGeoRotation("volT1",90,alpha,0)));
1888         mechStavVol->AddNode(volT1,4*i+2,
1889                                     new TGeoCombiTrans(x+w,y-h+0.04+filHeight/2,z-kStaveLength/2+2*l+(i*4*l)+s1/2, 
1890                                                        new TGeoRotation("volT1",-90,-alpha,0)));
1891         mechStavVol->AddNode(volT1,4*i+3,
1892                                     new TGeoCombiTrans(x-w,y-h+0.04+filHeight/2,z-kStaveLength/2+2*l+(i*4*l)+s1/2, 
1893                                                        new TGeoRotation("volT1",-90,+alpha,0)));
1894         }
1895  
1896      // Top filament CERP black-12 Carbon structure TGeoBBox (length,thickness,width)
1897
1898       TGeoBBox *t2=new TGeoBBox(s2,filHeight/2,filWidth/2);
1899       TGeoVolume *volT2=new TGeoVolume("topFilament", t2, medM60J3K);
1900       volT2->SetLineColor(12);
1901       volT2->SetFillColor(12); 
1902       for(int i=0;i<loop;i++){ //i<30;i++){
1903         mechStavVol->AddNode(volT2,4*i+0,
1904                                     new TGeoCombiTrans(x+w,y+0.04+filHeight/2,z-kStaveLength/2+(i*4*l)+s1/2,
1905                                                        new TGeoRotation("volT2",90,90-alpha,90-beta)));
1906         mechStavVol->AddNode(volT2,4*i+1,
1907                                     new TGeoCombiTrans(x-w,y+0.04+filHeight/2,z-kStaveLength/2+(i*4*l)+s1/2,
1908                                                        new TGeoRotation("volT2",90,-90+alpha,-90+beta)));
1909         mechStavVol->AddNode(volT2,4*i+2,
1910                                     new TGeoCombiTrans(x+w,y+0.04+filHeight/2,z-kStaveLength/2+2*l+(i*4*l)+s1/2,
1911                                                        new TGeoRotation("volT2",90,-90+alpha,90-beta)));
1912         mechStavVol->AddNode(volT2,4*i+3,
1913                                     new TGeoCombiTrans(x-w,y+0.04+filHeight/2,z-kStaveLength/2+2*l+(i*4*l)+s1/2, 
1914                                                        new TGeoRotation("volT2",90,90-alpha,-90+beta)));
1915         }
1916     }
1917
1918     if (fBuildLevel < 2) {
1919
1920       // Glue Filament and Silicon MicroChannel
1921       TGeoBBox *tM0=new TGeoBBox(xstaMC/5, klay4/2, zsta);
1922       TGeoVolume *volTM0=new TGeoVolume("glueFM", tM0,medGlue );
1923       volTM0->SetLineColor(5);
1924       volTM0->SetFillColor(5); 
1925       mechStavVol->AddNode(volTM0, 0, new TGeoCombiTrans(x-xsta/2-0.25,0.03+yMC, z, new TGeoRotation("",0, 0, 0)));
1926       mechStavVol->AddNode(volTM0, 1, new TGeoCombiTrans(x+xsta/2+0.25,0.03+yMC, z, new TGeoRotation("",0, 0, 0)));
1927
1928             
1929       // Glue microchannel and sensor
1930       TGeoBBox *glueM = new TGeoBBox(xstaMC/5, klay4/2, zsta);
1931       TGeoVolume *volGlueM=new TGeoVolume("glueMS", glueM, medGlue);
1932       volGlueM->SetLineColor(5);
1933       volGlueM->SetFillColor(5); 
1934       mechStavVol->AddNode(volGlueM, 0, new TGeoCombiTrans(x-xsta/2-0.25,yMC-0.01, z, new TGeoRotation("",0, 0, 0)));
1935       mechStavVol->AddNode(volGlueM, 1, new TGeoCombiTrans(x+xsta/2+0.25,yMC-0.01, z, new TGeoRotation("",0, 0, 0)));
1936      
1937        // Glue sensor and kapton
1938       TGeoBBox *glue = new TGeoBBox(xsta, klay4/2, zsta);
1939       TGeoVolume *volGlue=new TGeoVolume("glueSensorBus", glue, medGlue);
1940       volGlue->SetLineColor(5);
1941       volGlue->SetFillColor(5); 
1942        mechStavVol->AddNode(volGlue, 1, new TGeoCombiTrans(x, y-0.154-fSensorThick-klay4/2, z, new TGeoRotation("",0, 0, 0)));
1943     }      
1944
1945     if (fBuildLevel < 1) {
1946       TGeoBBox *kapCable = new TGeoBBox(xsta, klay5/2, zsta);
1947       TGeoVolume *volCable=new TGeoVolume("Flexcable", kapCable, medFlexCable);
1948       volCable->SetLineColor(28);
1949       volCable->SetFillColor(28); 
1950       mechStavVol->AddNode(volCable, 0, new TGeoCombiTrans(x, y-0.154-fSensorThick-klay4-klay5/2, z, new TGeoRotation("",0, 0, 0)));
1951     }
1952
1953   // Done, return the stave structur
1954     return mechStavVol;
1955  }
1956
1957 // model4
1958 //________________________________________________________________________
1959 TGeoVolume* AliITSUv1Layer::CreateStaveModelInnerB4(const Double_t xstave,
1960                                                     const Double_t zstave,
1961                                                     const TGeoManager *mgr){
1962 //
1963 // Create the mechanical stave structure for Model 2.2 of TDR
1964 // Logic is similar to method CreateStaveModelInnerB22
1965 // but completely rewritten:
1966 // - code completely revised, made systematic and more similar to OB
1967 // - fix some inconsistencies (stave element sequence, empty space)
1968 // - use static const as parameters
1969 // - comply with latest (nov '14) C.Gargiulo data
1970 //
1971 // Input:
1972 //         xstave : stave X half length
1973 //         zstave : stave Z half length
1974 //         mgr    : the GeoManager (used only to get the proper material)
1975 //
1976 // Output:
1977 //
1978 // Return:
1979 //
1980 // Created:      04 Dec 2014  Mario Sitta
1981 //
1982
1983   
1984   // Local parameters
1985   Double_t layerHeight = 0.;
1986
1987   Double_t rPipeMin = fgkIBCoolPipeInnerD/2;
1988   Double_t rPipeMax = rPipeMin + fgkIBCoolPipeThick;
1989
1990   Double_t topFilTheta = fgkIBTopFilamentAlpha*TMath::DegToRad();
1991   Double_t topFilLProj = xstave/TMath::Sin(topFilTheta); // Top filament length projected on stave XZ plane
1992   Double_t topFilYLen = xstave/TMath::Tan(topFilTheta); // Filament length on Y
1993   Int_t  nFilaments = (Int_t)(zstave/topFilYLen);
1994   // Question: would it be better to fix the number of filaments and
1995   // compute the angle alpha from it, or leave as it is now, i.e. fix the
1996   // filament inclination angle alpha and compute their number ?
1997
1998   const Int_t nv = 6;
1999   Double_t xv[nv], yv[nv]; // The stave container Xtru
2000   Double_t xlen;
2001   Double_t xpos, ypos, zpos, ylay;
2002   Double_t beta, gamma, theta;
2003
2004
2005   // First create all needed shapes
2006   TGeoBBox *kapCable = new TGeoBBox(xstave, fgkIBFlexCableKapThick/2, zstave);
2007
2008   TGeoBBox *aluCable = new TGeoBBox(xstave, fgkIBFlexCableAlThick/2, zstave);
2009
2010   TGeoBBox *glue     = new TGeoBBox(xstave, fgkIBGlueThick/2, zstave);
2011
2012   TGeoBBox *fleecbot = new TGeoBBox(xstave, fgkIBCarbonFleeceThick/2, zstave);
2013
2014   TGeoBBox *cfplate  = new TGeoBBox(xstave, fgkIBK13D2UThick/2, zstave);
2015
2016   TGeoTube *pipe     = new TGeoTube(rPipeMin, rPipeMax, zstave);
2017
2018   TGeoTube *water    = new TGeoTube(0., rPipeMin, zstave);
2019
2020   TGeoTubeSeg *cpaptub  = new TGeoTubeSeg(rPipeMax,
2021                                           rPipeMax + fgkIBCarbonPaperThick,
2022                                           zstave, 0, 180);
2023
2024   TGeoBBox *cpapvert = new TGeoBBox(fgkIBCarbonPaperThick/2,
2025                                     pipe->GetRmax()/2, zstave);
2026
2027   xlen = fgkIBCoolPipeXDist/2 - pipe->GetRmax() - fgkIBCarbonPaperThick;
2028   TGeoBBox *cpapmid  = new TGeoBBox(xlen, fgkIBCarbonPaperThick/2, zstave);
2029
2030   xlen = xstave -fgkIBCoolPipeXDist/2 -pipe->GetRmax() -fgkIBCarbonPaperThick;
2031   TGeoBBox *cpaplr   = new TGeoBBox(xlen/2, fgkIBCarbonPaperThick/2, zstave);
2032
2033   TGeoTubeSeg *fleecpipe = new TGeoTubeSeg(cpaptub->GetRmax(),
2034                                cpaptub->GetRmax() + fgkIBCarbonFleeceThick,
2035                                            zstave, 0, 180); 
2036
2037   TGeoBBox *fleecvert = new TGeoBBox(fgkIBCarbonFleeceThick/2,
2038                                      (pipe->GetRmax()-fgkIBCarbonPaperThick)/2,
2039                                      zstave);
2040
2041   xlen = fgkIBCoolPipeXDist/2 - pipe->GetRmax() - fgkIBCarbonPaperThick
2042        - fgkIBCarbonFleeceThick;
2043   TGeoBBox *fleecmid  = new TGeoBBox(xlen, fgkIBCarbonFleeceThick/2, zstave);
2044
2045   xlen = xstave - fgkIBCoolPipeXDist/2 - pipe->GetRmax()
2046        - fgkIBCarbonPaperThick - fgkIBCarbonFleeceThick;
2047   TGeoBBox *fleeclr   = new TGeoBBox(xlen/2, fgkIBCarbonFleeceThick/2, zstave);
2048
2049   // The spaceframe structure
2050   TGeoTrd1 *topv  = new TGeoTrd1(0, fgkIBTopVertexWidth/2, zstave,
2051                                     fgkIBTopVertexHeight/2);
2052
2053   TGeoTrd1 *sidev = new TGeoTrd1(0, fgkIBSideVertexWidth/2, zstave,
2054                                     fgkIBSideVertexHeight/2);
2055
2056   TGeoBBox *topfil = new TGeoBBox(fgkIBTopFilamentLength/2,
2057                                   fgkIBTopFilamentSide/2,
2058                                   fgkIBTopFilamentSide/2);
2059
2060   // The half stave container (an XTru to avoid overlaps between neighbours)
2061   beta = TMath::ATan(2*sidev->GetDz()/sidev->GetDx2());
2062   gamma = TMath::PiOver2() - beta;
2063
2064   layerHeight = 2*(  kapCable->GetDY() + aluCable->GetDY() +   glue->GetDY()
2065                    + fleecbot->GetDY() +  cfplate->GetDY() + cpaplr->GetDY()
2066                    +  fleeclr->GetDY() );
2067
2068   xv[0] = xstave;
2069   yv[0] = 0;
2070   xv[1] = xv[0];
2071   yv[1] = layerHeight + fgkIBSideVertexHeight;
2072   xv[2] = fgkIBTopVertexWidth/2;
2073   yv[2] = fgkIBStaveHeight + 2*topfil->GetDZ();
2074   for (Int_t i = 0; i<nv/2; i++) {
2075     xv[3+i] = -xv[2-i];
2076     yv[3+i] =  yv[2-i];
2077   }
2078
2079   TGeoXtru *mechStruct = new TGeoXtru(2);
2080   mechStruct->DefinePolygon(nv, xv, yv);
2081   mechStruct->DefineSection(0,-zstave-topfil->GetDY());
2082   mechStruct->DefineSection(1, zstave+topfil->GetDY());
2083
2084
2085   // We have all shapes: now create the real volumes
2086
2087   TGeoMedium *medAir          = mgr->GetMedium("ITS_AIR$");
2088   TGeoMedium *medWater        = mgr->GetMedium("ITS_WATER$");
2089   TGeoMedium *medM55J6K       = mgr->GetMedium("ITS_M55J6K$"); 
2090   TGeoMedium *medM60J3K       = mgr->GetMedium("ITS_M60J3K$"); 
2091   TGeoMedium *medKapton       = mgr->GetMedium("ITS_KAPTON(POLYCH2)$");
2092   TGeoMedium *medGlue         = mgr->GetMedium("ITS_GLUE$");
2093   TGeoMedium *medK13D2U2k     = mgr->GetMedium("ITS_K13D2U2k$");
2094   TGeoMedium *medFGS003       = mgr->GetMedium("ITS_FGS003$"); 
2095   TGeoMedium *medCarbonFleece = mgr->GetMedium("ITS_CarbonFleece$"); 
2096   TGeoMedium *medAluminum     = mgr->GetMedium("ITS_ALUMINUM$");
2097
2098
2099   char volname[30];
2100   snprintf(volname, 30, "%s%d_StaveStruct",
2101            AliITSUGeomTGeo::GetITSStavePattern(), fLayerNumber);
2102   TGeoVolume *mechStavVol = new TGeoVolume(volname, mechStruct, medAir);
2103   mechStavVol->SetLineColor(12);
2104   mechStavVol->SetFillColor(12); 
2105   mechStavVol->SetVisibility(kTRUE);  
2106
2107   TGeoVolume *kapCableVol = new TGeoVolume("FPCKapton", kapCable, medKapton);
2108   kapCableVol->SetLineColor(kBlue);
2109   kapCableVol->SetFillColor(kBlue);
2110
2111   TGeoVolume *aluCableVol = new TGeoVolume("FPCAluminum",
2112                                            aluCable, medAluminum);
2113   aluCableVol->SetLineColor(kCyan);
2114   aluCableVol->SetFillColor(kCyan);
2115
2116   TGeoVolume *glueVol = new TGeoVolume("Glue", glue, medGlue);
2117   glueVol->SetLineColor(kBlack);
2118   glueVol->SetFillColor(kBlack);
2119
2120   TGeoVolume *fleecbotVol = new TGeoVolume("CarbonFleeceBottom",
2121                                            fleecbot, medCarbonFleece);
2122   fleecbotVol->SetFillColor(kViolet);
2123   fleecbotVol->SetLineColor(kViolet);
2124
2125   TGeoVolume *cfplateVol = new TGeoVolume("CFPlate", cfplate, medK13D2U2k);
2126   cfplateVol->SetFillColor(5);  // Yellow
2127   cfplateVol->SetLineColor(5);
2128
2129   TGeoVolume *pipeVol = new TGeoVolume("PolyimidePipe", pipe, medKapton);
2130   pipeVol->SetFillColor(35);  // Blue shade
2131   pipeVol->SetLineColor(35);
2132
2133   TGeoVolume *waterVol= new TGeoVolume("Water", water, medWater);
2134   waterVol->SetFillColor(4);  // Bright blue
2135   waterVol->SetLineColor(4);
2136
2137   TGeoVolume *cpaptubVol = new TGeoVolume("ThermasolPipeCover",
2138                                           cpaptub, medFGS003);
2139   cpaptubVol->SetFillColor(2);  // Red
2140   cpaptubVol->SetLineColor(2);
2141
2142   TGeoVolume *cpapvertVol = new TGeoVolume("ThermasolVertical",
2143                                            cpapvert, medFGS003);
2144   cpapvertVol->SetFillColor(2);  // Red
2145   cpapvertVol->SetLineColor(2);
2146
2147   TGeoVolume *cpapmidVol = new TGeoVolume("ThermasolMiddle",
2148                                           cpapmid, medFGS003);
2149   cpapmidVol->SetFillColor(2);  // Red
2150   cpapmidVol->SetLineColor(2);
2151
2152   TGeoVolume *cpaplrVol = new TGeoVolume("ThermasolLeftRight",
2153                                          cpaplr, medFGS003);
2154   cpaplrVol->SetFillColor(2);  // Red
2155   cpaplrVol->SetLineColor(2);
2156
2157   TGeoVolume *fleecpipeVol = new TGeoVolume("CarbonFleecePipeCover",
2158                                             fleecpipe, medCarbonFleece);
2159   fleecpipeVol->SetFillColor(28);  // Brown shade
2160   fleecpipeVol->SetLineColor(28);
2161
2162   TGeoVolume *fleecvertVol = new TGeoVolume("CarbonFleeceVertical",
2163                                             fleecvert, medCarbonFleece);
2164   fleecvertVol->SetFillColor(28);  // Brown shade
2165   fleecvertVol->SetLineColor(28);
2166
2167   TGeoVolume *fleecmidVol = new TGeoVolume("CarbonFleeceMiddle",
2168                                            fleecmid, medCarbonFleece);
2169   fleecmidVol->SetFillColor(28);  // Brown shade
2170   fleecmidVol->SetLineColor(28);
2171
2172   TGeoVolume *fleeclrVol = new TGeoVolume("CarbonFleeceLeftRight",
2173                                           fleeclr, medCarbonFleece);
2174   fleeclrVol->SetFillColor(28);  // Brown shade
2175   fleeclrVol->SetLineColor(28);
2176
2177   TGeoVolume *topvVol = new TGeoVolume("TopVertex", topv, medM55J6K);
2178   topvVol->SetFillColor(12);  // Gray shade
2179   topvVol->SetLineColor(12);
2180   
2181   TGeoVolume *sidevVol = new TGeoVolume("SideVertex", sidev, medM55J6K);
2182   sidevVol->SetFillColor(12);  // Gray shade
2183   sidevVol->SetLineColor(12);
2184   
2185   TGeoVolume *topfilVol = new TGeoVolume("TopFilament", topfil, medM60J3K);
2186   topfilVol->SetFillColor(12);  // Gray shade
2187   topfilVol->SetLineColor(12);
2188   
2189
2190   // Now build up the half stave
2191   ypos = kapCable->GetDY();
2192   if (fBuildLevel < 4)   // Kapton
2193     mechStavVol->AddNode(kapCableVol, 1, new TGeoTranslation(0, ypos, 0));
2194
2195   ypos += (kapCable->GetDY() + aluCable->GetDY());
2196   if (fBuildLevel < 1)   // Aluminum
2197     mechStavVol->AddNode(aluCableVol, 1, new TGeoTranslation(0, ypos, 0));
2198
2199   ypos += (aluCable->GetDY() + glue->GetDY());
2200   if (fBuildLevel < 2)   // Glue
2201     mechStavVol->AddNode(glueVol, 1, new TGeoTranslation(0, ypos, 0));
2202
2203   ypos += (glue->GetDY() + fleecbot->GetDY());
2204   if (fBuildLevel < 5)   // Carbon
2205     mechStavVol->AddNode(fleecbotVol, 1, new TGeoTranslation(0, ypos, 0));
2206
2207   ypos += (fleecbot->GetDY() + cfplate->GetDY());
2208   if (fBuildLevel < 5)   // Carbon
2209     mechStavVol->AddNode(cfplateVol, 1, new TGeoTranslation(0, ypos, 0));
2210
2211   ylay = ypos + cfplate->GetDY(); // The level where tubes etc. lay
2212
2213   xpos = fgkIBCoolPipeXDist/2;
2214   ypos = ylay + pipe->GetRmax();
2215   if (fBuildLevel < 4) { // Kapton
2216     mechStavVol->AddNode(pipeVol, 1, new TGeoTranslation(-xpos, ypos, 0));
2217     mechStavVol->AddNode(pipeVol, 2, new TGeoTranslation( xpos, ypos, 0));
2218   }
2219
2220   if (fBuildLevel < 3) { // Water
2221     mechStavVol->AddNode(waterVol, 1, new TGeoTranslation(-xpos, ypos, 0));
2222     mechStavVol->AddNode(waterVol, 2, new TGeoTranslation( xpos, ypos, 0));
2223   }
2224
2225   if (fBuildLevel < 5) { // Carbon (stave components)
2226     mechStavVol->AddNode(cpaptubVol, 1, new TGeoTranslation(-xpos, ypos, 0));
2227     mechStavVol->AddNode(cpaptubVol, 2, new TGeoTranslation( xpos, ypos, 0));
2228
2229     mechStavVol->AddNode(fleecpipeVol,1, new TGeoTranslation(-xpos, ypos, 0));
2230     mechStavVol->AddNode(fleecpipeVol,2, new TGeoTranslation( xpos, ypos, 0));
2231
2232     xpos = fgkIBCoolPipeXDist/2 - pipe->GetRmax() - cpapvert->GetDX();
2233     ypos = ylay + cpapvert->GetDY();
2234     mechStavVol->AddNode(cpapvertVol, 1, new TGeoTranslation(-xpos, ypos, 0));
2235     mechStavVol->AddNode(cpapvertVol, 2, new TGeoTranslation( xpos, ypos, 0));
2236
2237     xpos = fgkIBCoolPipeXDist/2 + pipe->GetRmax() + cpapvert->GetDX();
2238     mechStavVol->AddNode(cpapvertVol, 3, new TGeoTranslation(-xpos, ypos, 0));
2239     mechStavVol->AddNode(cpapvertVol, 4, new TGeoTranslation( xpos, ypos, 0));
2240
2241     ypos = ylay + fgkIBCarbonPaperThick/2;
2242     mechStavVol->AddNode(cpapmidVol, 1, new TGeoTranslation(0, ypos, 0));
2243
2244     xpos = xstave - cpaplr->GetDX();
2245     mechStavVol->AddNode(cpaplrVol, 1, new TGeoTranslation(-xpos, ypos, 0));
2246     mechStavVol->AddNode(cpaplrVol, 2, new TGeoTranslation( xpos, ypos, 0));
2247
2248     xpos = fgkIBCoolPipeXDist/2 - pipe->GetRmax() - 2*cpapvert->GetDX()
2249          - fleecvert->GetDX();
2250     ypos = ylay + fgkIBCarbonPaperThick + fleecvert->GetDY();
2251     mechStavVol->AddNode(fleecvertVol, 1, new TGeoTranslation(-xpos, ypos, 0));
2252     mechStavVol->AddNode(fleecvertVol, 2, new TGeoTranslation( xpos, ypos, 0));
2253
2254     xpos = fgkIBCoolPipeXDist/2 + pipe->GetRmax() + 2*cpapvert->GetDX()
2255          + fleecvert->GetDX();
2256     mechStavVol->AddNode(fleecvertVol, 3, new TGeoTranslation(-xpos, ypos, 0));
2257     mechStavVol->AddNode(fleecvertVol, 4, new TGeoTranslation( xpos, ypos, 0));
2258
2259     ypos = ylay + fgkIBCarbonPaperThick + fgkIBCarbonFleeceThick/2;
2260     mechStavVol->AddNode(fleecmidVol, 1, new TGeoTranslation(0, ypos, 0));
2261
2262     xpos = xstave - fleeclr->GetDX();
2263     mechStavVol->AddNode(fleeclrVol, 1, new TGeoTranslation(-xpos, ypos, 0));
2264     mechStavVol->AddNode(fleeclrVol, 2, new TGeoTranslation( xpos, ypos, 0));
2265   }
2266
2267   ylay += (fgkIBCarbonPaperThick + fgkIBCarbonFleeceThick);
2268
2269   if (fBuildLevel < 5) { // Carbon (spaceframe)
2270     ypos = fgkIBStaveHeight - topv->GetDz(); // Due to rotation, z is on Y
2271     mechStavVol->AddNode(topvVol, 1,
2272                          new TGeoCombiTrans(0, ypos, 0,
2273                                             new TGeoRotation("",0,-90,0)));
2274
2275     // beta and gamma were already computed when building mechStruct shape
2276     xpos = xstave - TMath::Cos(gamma)*sidev->GetDz();
2277     ypos = ylay + TMath::Sin(gamma)*sidev->GetDz();
2278     beta *= TMath::RadToDeg();  // beta was rad, we need deg
2279
2280     mechStavVol->AddNode(sidevVol, 1,
2281                          new TGeoCombiTrans(-xpos, ypos, 0,
2282                                         new TGeoRotation("", 180-beta,90,0)));
2283     mechStavVol->AddNode(sidevVol, 2,
2284                          new TGeoCombiTrans( xpos, ypos, 0,
2285                                         new TGeoRotation("",-180+beta,90,0)));
2286
2287     gamma *= TMath::RadToDeg();  // gamma was rad, we need deg
2288     theta = 90. - fgkIBTopFilamentAlpha;
2289     xpos = xstave/2 + topfil->GetDZ();
2290     ypos = ( layerHeight + fgkIBStaveHeight )/2 +
2291            fgkIBSideVertexWidth*TMath::Sin(beta*TMath::DegToRad())/2 ;
2292     for(int i=0; i<nFilaments; i++){ // i<28 (?)
2293       // 1) Front Left Top Filament
2294       zpos = -zstave + (i*2*topFilYLen) + topFilLProj/4; // ?????
2295       mechStavVol->AddNode(topfilVol, i*4+1,
2296                          new TGeoCombiTrans( xpos, ypos, zpos,
2297                               new TGeoRotation("", 90, theta, 90-gamma)));
2298       // 2) Front Right Top Filament
2299       mechStavVol->AddNode(topfilVol, i*4+2,
2300                          new TGeoCombiTrans(-xpos, ypos, zpos,
2301                               new TGeoRotation("", 90,-theta,-90+gamma)));
2302       // 3) Back Left  Top Filament
2303       zpos += topFilYLen;
2304       mechStavVol->AddNode(topfilVol, i*4+3,
2305                          new TGeoCombiTrans( xpos, ypos, zpos,
2306                               new TGeoRotation("", 90,-theta, 90-gamma)));
2307       // 4) Back Right Top Filament
2308       mechStavVol->AddNode(topfilVol, i*4+4,
2309                          new TGeoCombiTrans(-xpos, ypos, zpos,
2310                               new TGeoRotation("", 90, theta,-90+gamma)));
2311     }
2312   }
2313
2314
2315   // Done, return the stave structure
2316   return mechStavVol;
2317 }
2318
2319 //________________________________________________________________________
2320 TGeoVolume* AliITSUv1Layer::CreateStaveOuterB(const TGeoManager *mgr){
2321 //
2322 // Create the chip stave for the Outer Barrel
2323 //
2324 // Input:
2325 //         mgr  : the GeoManager (used only to get the proper material)
2326 //
2327 // Output:
2328 //
2329 // Return:
2330 //
2331 // Created:      20 Dec 2013  Mario Sitta
2332 // Updated:      12 Mar 2014  Mario Sitta
2333 //
2334
2335   TGeoVolume *mechStavVol = 0;
2336
2337   switch (fStaveModel) {
2338     case AliITSUv1::kOBModelDummy:
2339       mechStavVol = CreateStaveModelOuterBDummy(mgr);
2340       break;
2341     case AliITSUv1::kOBModel0:
2342       mechStavVol = CreateStaveModelOuterB0(mgr);
2343       break;
2344     case AliITSUv1::kOBModel1:
2345     case AliITSUv1::kOBModel2:
2346       mechStavVol = CreateStaveModelOuterB12(mgr);
2347       break;
2348     default:
2349       AliFatal(Form("Unknown stave model %d",fStaveModel));
2350       break;
2351   }
2352
2353   return mechStavVol; 
2354 }
2355
2356 //________________________________________________________________________
2357 TGeoVolume* AliITSUv1Layer::CreateStaveModelOuterBDummy(const TGeoManager *) const {
2358 //
2359 // Create dummy stave
2360 //
2361 // Input:
2362 //         mgr  : the GeoManager (used only to get the proper material)
2363 //
2364 // Output:
2365 //
2366 // Return:
2367 //
2368 // Created:      20 Dec 2013  Mario Sitta
2369 //
2370
2371
2372   // Done, return the stave structure
2373   return 0;
2374 }
2375
2376 //________________________________________________________________________
2377 TGeoVolume* AliITSUv1Layer::CreateStaveModelOuterB0(const TGeoManager *mgr){
2378 //
2379 // Creation of the mechanical stave structure for the Outer Barrel as in v0
2380 // (we fake the module and halfstave volumes to have always
2381 // the same formal geometry hierarchy)
2382 //
2383 // Input:
2384 //         mgr  : the GeoManager (used only to get the proper material)
2385 //
2386 // Output:
2387 //
2388 // Return:
2389 //
2390 // Created:      20 Dec 2013  Mario Sitta
2391 // Updated:      12 Mar 2014  Mario Sitta
2392 //
2393
2394   // Local variables
2395   Double_t xmod, ymod, zmod;
2396   Double_t xlen, ylen, zlen;
2397   Double_t ypos, zpos;
2398   char volname[30];
2399   
2400   // First create all needed shapes
2401
2402   // The chip
2403   xlen = fgkOBHalfStaveWidth;
2404   ylen = 0.5*fChipThick;
2405   zlen = fgkOBModuleZLength/2;
2406
2407   TGeoVolume *chipVol = CreateChipInnerB(xlen, ylen, zlen);
2408
2409   xmod = ((TGeoBBox*)chipVol->GetShape())->GetDX();
2410   ymod = ((TGeoBBox*)chipVol->GetShape())->GetDY();
2411   zmod = ((TGeoBBox*)chipVol->GetShape())->GetDZ();
2412
2413   TGeoBBox *module = new TGeoBBox(xmod, ymod, zmod);
2414
2415   zlen = fgkOBModuleZLength*fNModules;
2416   TGeoBBox *hstave = new TGeoBBox(xlen, ylen, zlen/2);
2417
2418
2419   // We have all shapes: now create the real volumes
2420
2421   TGeoMedium *medAir = mgr->GetMedium("ITS_AIR$");
2422
2423   snprintf(volname, 30, "%s%d", AliITSUGeomTGeo::GetITSModulePattern(), fLayerNumber);
2424   TGeoVolume *modVol = new TGeoVolume(volname, module, medAir);
2425   modVol->SetVisibility(kTRUE);
2426
2427   snprintf(volname, 30, "%s%d", AliITSUGeomTGeo::GetITSHalfStavePattern(), fLayerNumber);
2428   TGeoVolume *hstaveVol  = new TGeoVolume(volname, hstave, medAir);
2429
2430
2431   // Finally build it up
2432   modVol->AddNode(chipVol, 0);
2433   fHierarchy[kChip]=1;
2434
2435   for (Int_t j=0; j<fNModules; j++) {
2436     ypos = 0.021;  // Remove small overlap - M.S: 21may13
2437     zpos = -hstave->GetDZ() + j*2*zmod + zmod;
2438     hstaveVol->AddNode(modVol, j, new TGeoTranslation(0, ypos, zpos));
2439     fHierarchy[kModule]++;
2440   }
2441
2442
2443   // Done, return the stave structure
2444   return hstaveVol;
2445 }
2446
2447 //________________________________________________________________________
2448 TGeoVolume* AliITSUv1Layer::CreateStaveModelOuterB12(const TGeoManager *mgr){
2449 //
2450 // Create the mechanical half stave structure
2451 // for the Outer Barrel as in TDR
2452 //
2453 // Input:
2454 //         mgr  : the GeoManager (used only to get the proper material)
2455 //
2456 // Output:
2457 //
2458 // Return:
2459 //
2460 // Created:      20 Nov 2013  Anastasia Barbano
2461 // Updated:      16 Jan 2014  Mario Sitta
2462 // Updated:      24 Feb 2014  Mario Sitta
2463 // Updated:      11 Nov 2014  Mario Sitta  Model2
2464 // Updated:      03 Dec 2014  Mario Sitta  Revised with C.Gargiulo latest infos
2465 //
2466
2467
2468   // Local parameters
2469   Double_t yFlex1      = fgkOBFlexCableAlThick;
2470   Double_t yFlex2      = fgkOBFlexCableKapThick;
2471   Double_t flexOverlap = 5; // to be checked - unused for the time being
2472   Double_t xHalfSt     = fgkOBHalfStaveWidth/2;
2473   Double_t yCFleece    = fgkOBCarbonFleeceThick;
2474   Double_t yGraph      = fgkOBGraphiteFoilThick;
2475
2476   Double_t ymod, zmod;
2477   Double_t xtru[12], ytru[12];
2478   Double_t xpos, ypos, ypos1, zpos/*, zpos5cm*/;
2479   Double_t xlen, ylen, zlen;
2480   char volname[30];
2481
2482   Double_t rCoolMin, rCoolMax;
2483   if (fStaveModel == AliITSUv1::kOBModel1)
2484     rCoolMin = fgkOBCoolTubeInnerDM1/2;
2485   else
2486     rCoolMin = fgkOBCoolTubeInnerD/2;
2487
2488   rCoolMax = rCoolMin + fgkOBCoolTubeThick;
2489
2490   zlen = (fNModules*fgkOBModuleZLength + (fNModules-1)*fgkOBModuleGap)/2;
2491
2492
2493   // First create all needed shapes
2494
2495   TGeoVolume *moduleVol = CreateModuleOuterB();
2496   moduleVol->SetVisibility(kTRUE);
2497   ymod = ((TGeoBBox*)(moduleVol->GetShape()))->GetDY();
2498   zmod = ((TGeoBBox*)(moduleVol->GetShape()))->GetDZ();
2499
2500   TGeoBBox *busAl  = new TGeoBBox("BusAl",  xHalfSt, fgkOBBusCableAlThick/2,
2501                                             zlen);
2502   TGeoBBox *busKap = new TGeoBBox("BusKap", xHalfSt, fgkOBBusCableKapThick/2,
2503                                             zlen);
2504
2505   TGeoBBox *glue = new TGeoBBox("Glue", xHalfSt, fgkOBGlueThick/2, zlen);
2506
2507   TGeoBBox *coldPlate  = new TGeoBBox("ColdPlate", fgkOBHalfStaveWidth/2,
2508                                       fgkOBColdPlateThick/2, zlen);
2509
2510   TGeoBBox *fleeccent  = new TGeoBBox("FleeceCent",  xHalfSt,
2511                                       yCFleece/2, zlen);
2512
2513   TGeoTube *coolTube   = new TGeoTube("CoolingTube", rCoolMin, rCoolMax, zlen);
2514   TGeoTube *coolWater  = new TGeoTube("CoolingWater", 0., rCoolMin, zlen);
2515
2516   xlen = xHalfSt - fgkOBCoolTubeXDist/2 - coolTube->GetRmax();
2517   TGeoBBox *graphlat   = new TGeoBBox("GraphLateral", xlen/2, yGraph/2, zlen);
2518
2519   xlen = fgkOBCoolTubeXDist/2 - coolTube->GetRmax();
2520   TGeoBBox *graphmid   = new TGeoBBox("GraphMiddle", xlen, yGraph/2, zlen);
2521
2522   ylen = coolTube->GetRmax() - yGraph;
2523   TGeoBBox *graphvert  = new TGeoBBox("GraphVertical", yGraph/2, ylen/2, zlen);
2524
2525   TGeoTubeSeg *graphtub = new TGeoTubeSeg("GraphTube", rCoolMax,
2526                                           rCoolMax+yGraph, zlen,
2527                                           180., 360.);
2528
2529   xlen = xHalfSt - fgkOBCoolTubeXDist/2 - coolTube->GetRmax() - yGraph;
2530   TGeoBBox *fleeclat  = new TGeoBBox("FleecLateral", xlen/2, yCFleece/2, zlen);
2531
2532   xlen = fgkOBCoolTubeXDist/2 - coolTube->GetRmax() - yGraph;
2533   TGeoBBox *fleecmid  = new TGeoBBox("FleecMiddle", xlen, yCFleece/2, zlen);
2534
2535   ylen = coolTube->GetRmax() - yGraph - yCFleece;
2536   TGeoBBox *fleecvert = new TGeoBBox("FleecVertical", yCFleece/2, ylen/2,
2537                                                       zlen);
2538
2539   TGeoTubeSeg *fleectub = new TGeoTubeSeg("FleecTube", rCoolMax+yGraph,
2540                                           rCoolMax+yCFleece+yGraph,
2541                                           zlen, 180., 360.);
2542
2543   TGeoBBox *flex1_5cm  = new TGeoBBox("Flex1MV_5cm",xHalfSt,yFlex1/2,flexOverlap/2);
2544   TGeoBBox *flex2_5cm  = new TGeoBBox("Flex2MV_5cm",xHalfSt,yFlex2/2,flexOverlap/2);
2545
2546   // The half stave container (an XTru to avoid overlaps between neightbours)
2547   ylen = ymod + busAl->GetDY() + busKap->GetDY() + coldPlate->GetDY()
2548               + fleeccent->GetDY() + graphlat->GetDY() + fleeclat->GetDY();
2549   if (fStaveModel == AliITSUv1::kOBModel2)
2550     ylen += 2*glue->GetDY();
2551
2552   xtru[0] = xHalfSt;
2553   ytru[0] = 0;
2554   xtru[1] = xtru[0];
2555   ytru[1] = -2*ylen;
2556   xtru[2] = fgkOBCoolTubeXDist/2 + fleectub->GetRmax();
2557   ytru[2] = ytru[1];
2558   xtru[3] = xtru[2];
2559   ytru[3] = ytru[2] - (coolTube->GetRmax() + fleectub->GetRmax());
2560   xtru[4] = fgkOBCoolTubeXDist/2 - fleectub->GetRmax();
2561   ytru[4] = ytru[3];
2562   xtru[5] = xtru[4];
2563   ytru[5] = ytru[2];
2564   for (Int_t i = 0; i<6; i++) {
2565     xtru[6+i] = -xtru[5-i];
2566     ytru[6+i] =  ytru[5-i];
2567   }
2568   TGeoXtru *halfStave = new TGeoXtru(2);
2569   halfStave->DefinePolygon(12, xtru, ytru);
2570   halfStave->DefineSection(0,-fZLength/2);
2571   halfStave->DefineSection(1, fZLength/2);
2572
2573
2574   // We have all shapes: now create the real volumes
2575
2576   TGeoMedium *medAluminum     = mgr->GetMedium("ITS_ALUMINUM$");
2577   TGeoMedium *medK13D2U120    = mgr->GetMedium("ITS_K13D2U120$");
2578   TGeoMedium *medKapton       = mgr->GetMedium("ITS_KAPTON(POLYCH2)$");
2579   TGeoMedium *medWater        = mgr->GetMedium("ITS_WATER$");
2580   TGeoMedium *medCarbonFleece = mgr->GetMedium("ITS_CarbonFleece$"); 
2581   TGeoMedium *medFGS003       = mgr->GetMedium("ITS_FGS003$"); //amec thermasol
2582   TGeoMedium *medAir          = mgr->GetMedium("ITS_AIR$");
2583   TGeoMedium *medGlue         = mgr->GetMedium("ITS_GLUE$");
2584
2585
2586   TGeoVolume *busAlVol = new TGeoVolume("PowerBusAlVol", busAl , medAluminum);
2587   busAlVol->SetLineColor(kCyan);
2588   busAlVol->SetFillColor(busAlVol->GetLineColor());
2589   busAlVol->SetFillStyle(4000); // 0% transparent
2590
2591   TGeoVolume *busKapVol = new TGeoVolume("PowerBusKapVol", busKap, medKapton);
2592   busKapVol->SetLineColor(kBlue);
2593   busKapVol->SetFillColor(busKapVol->GetLineColor());
2594   busKapVol->SetFillStyle(4000); // 0% transparent
2595
2596   TGeoVolume *coldPlateVol = new TGeoVolume("ColdPlateVol",
2597                                             coldPlate, medK13D2U120);
2598   coldPlateVol->SetLineColor(kYellow-3);
2599   coldPlateVol->SetFillColor(coldPlateVol->GetLineColor());
2600   coldPlateVol->SetFillStyle(4000); // 0% transparent
2601
2602   TGeoVolume *fleeccentVol = new TGeoVolume("CarbonFleeceCentral",
2603                                             fleeccent, medCarbonFleece);
2604   fleeccentVol->SetLineColor(kViolet);
2605   fleeccentVol->SetFillColor(fleeccentVol->GetLineColor());
2606   fleeccentVol->SetFillStyle(4000); // 0% transparent
2607
2608   TGeoVolume *glueVol = new TGeoVolume("GlueVol", glue, medGlue);
2609   glueVol->SetLineColor(kBlack);
2610   glueVol->SetFillColor(glueVol->GetLineColor());
2611   glueVol->SetFillStyle(4000); // 0% transparent
2612
2613   TGeoVolume *coolTubeVol  = new TGeoVolume("CoolingTubeVol",
2614                                             coolTube, medKapton);
2615   coolTubeVol->SetLineColor(kGray);
2616   coolTubeVol->SetFillColor(coolTubeVol->GetLineColor());
2617   coolTubeVol->SetFillStyle(4000); // 0% transparent
2618
2619   TGeoVolume *coolWaterVol;
2620   coolWaterVol = new TGeoVolume("CoolingWaterVol", coolWater, medWater);
2621   coolWaterVol->SetLineColor(kBlue);
2622   coolWaterVol->SetFillColor(coolWaterVol->GetLineColor());
2623   coolWaterVol->SetFillStyle(4000); // 0% transparent
2624
2625   TGeoVolume *graphlatVol = new TGeoVolume("GraphiteFoilLateral",
2626                                            graphlat, medFGS003);
2627   graphlatVol->SetLineColor(kGreen);
2628   graphlatVol->SetFillColor(graphlatVol->GetLineColor());
2629   graphlatVol->SetFillStyle(4000); // 0% transparent
2630
2631   TGeoVolume *graphmidVol = new TGeoVolume("GraphiteFoilMiddle",
2632                                            graphmid, medFGS003);
2633   graphmidVol->SetLineColor(kGreen);
2634   graphmidVol->SetFillColor(graphmidVol->GetLineColor());
2635   graphmidVol->SetFillStyle(4000); // 0% transparent
2636
2637   TGeoVolume *graphvertVol = new TGeoVolume("GraphiteFoilVertical",
2638                                             graphvert, medFGS003);
2639   graphvertVol->SetLineColor(kGreen);
2640   graphvertVol->SetFillColor(graphvertVol->GetLineColor());
2641   graphvertVol->SetFillStyle(4000); // 0% transparent
2642
2643   TGeoVolume *graphtubVol = new TGeoVolume("GraphiteFoilPipeCover",
2644                                            graphtub, medFGS003);
2645   graphtubVol->SetLineColor(kGreen);
2646   graphtubVol->SetFillColor(graphtubVol->GetLineColor());
2647   graphtubVol->SetFillStyle(4000); // 0% transparent
2648
2649   TGeoVolume *fleeclatVol = new TGeoVolume("CarbonFleeceLateral",
2650                                            fleeclat, medCarbonFleece);
2651   fleeclatVol->SetLineColor(kViolet);
2652   fleeclatVol->SetFillColor(fleeclatVol->GetLineColor());
2653   fleeclatVol->SetFillStyle(4000); // 0% transparent
2654
2655   TGeoVolume *fleecmidVol = new TGeoVolume("CarbonFleeceMiddle",
2656                                            fleecmid, medCarbonFleece);
2657   fleecmidVol->SetLineColor(kViolet);
2658   fleecmidVol->SetFillColor(fleecmidVol->GetLineColor());
2659   fleecmidVol->SetFillStyle(4000); // 0% transparent
2660
2661   TGeoVolume *fleecvertVol = new TGeoVolume("CarbonFleeceVertical",
2662                                             fleecvert, medCarbonFleece);
2663   fleecvertVol->SetLineColor(kViolet);
2664   fleecvertVol->SetFillColor(fleecvertVol->GetLineColor());
2665   fleecvertVol->SetFillStyle(4000); // 0% transparent
2666
2667   TGeoVolume *fleectubVol = new TGeoVolume("CarbonFleecePipeCover",
2668                                            fleectub, medCarbonFleece);
2669   fleectubVol->SetLineColor(kViolet);
2670   fleectubVol->SetFillColor(fleectubVol->GetLineColor());
2671   fleectubVol->SetFillStyle(4000); // 0% transparent
2672
2673   snprintf(volname, 30, "%s%d", AliITSUGeomTGeo::GetITSHalfStavePattern(), fLayerNumber);
2674   TGeoVolume *halfStaveVol  = new TGeoVolume(volname, halfStave, medAir);
2675 //   halfStaveVol->SetLineColor(12);
2676 //   halfStaveVol->SetFillColor(12); 
2677 //   halfStaveVol->SetVisibility(kTRUE);
2678
2679
2680   TGeoVolume *flex1_5cmVol = new TGeoVolume("Flex1Vol5cm",flex1_5cm,medAluminum);
2681   TGeoVolume *flex2_5cmVol = new TGeoVolume("Flex2Vol5cm",flex2_5cm,medKapton);
2682
2683
2684   flex1_5cmVol->SetLineColor(kRed);
2685   flex2_5cmVol->SetLineColor(kGreen);
2686   
2687
2688   // Now build up the half stave
2689   ypos = - busKap->GetDY();
2690   if ( (fStaveModel == AliITSUv1::kOBModel1 && fBuildLevel < 4) || // Kapton
2691        (fStaveModel == AliITSUv1::kOBModel2 && fBuildLevel < 5) )
2692     halfStaveVol->AddNode(busKapVol, 1, new TGeoTranslation(0, ypos, 0));
2693
2694   ypos -= (busKap->GetDY() + busAl->GetDY());
2695   if ( (fStaveModel == AliITSUv1::kOBModel1 && fBuildLevel < 1) || // Aluminum
2696        (fStaveModel == AliITSUv1::kOBModel2 && fBuildLevel < 2) )
2697     halfStaveVol->AddNode(busAlVol, 1, new TGeoTranslation(0, ypos, 0));
2698
2699   ypos -= busAl->GetDY();
2700
2701   if (fStaveModel == AliITSUv1::kOBModel2) {
2702     ypos -= glue->GetDY();
2703     if (fBuildLevel < 3) // Glue
2704       halfStaveVol->AddNode(glueVol, 1, new TGeoTranslation(0, ypos, 0));
2705     ypos -= glue->GetDY();
2706   }
2707
2708   ypos -= ymod;
2709   for (Int_t j=0; j<fNModules; j++) {
2710     zpos = -zlen + j*(2*zmod + fgkOBModuleGap) + zmod;
2711     halfStaveVol->AddNode(moduleVol, j, new TGeoTranslation(0, ypos, zpos));
2712     fHierarchy[kModule]++;
2713   }
2714
2715   ypos -= ymod;
2716
2717   if (fStaveModel == AliITSUv1::kOBModel2) {
2718     ypos -= glue->GetDY();
2719     if (fBuildLevel < 3) // Glue
2720       halfStaveVol->AddNode(glueVol, 2, new TGeoTranslation(0, ypos, 0));
2721     ypos -= glue->GetDY();
2722   }
2723
2724   ypos -= fleeccent->GetDY();
2725   if ( (fStaveModel == AliITSUv1::kOBModel1 && fBuildLevel < 5) || // Carbon
2726        (fStaveModel == AliITSUv1::kOBModel2 && fBuildLevel < 6) )
2727     halfStaveVol->AddNode(fleeccentVol, 1, new TGeoTranslation(0, ypos, 0));
2728   ypos -= fleeccent->GetDY();
2729
2730   ypos -= coldPlate->GetDY();
2731   if ( (fStaveModel == AliITSUv1::kOBModel1 && fBuildLevel < 5) || // Carbon
2732        (fStaveModel == AliITSUv1::kOBModel2 && fBuildLevel < 6) )
2733     halfStaveVol->AddNode(coldPlateVol, 1, new TGeoTranslation(0, ypos, 0));
2734
2735   xpos = fgkOBCoolTubeXDist/2;
2736   ypos1 = ypos - (coldPlate->GetDY() + coolTube->GetRmax());
2737   if ( (fStaveModel == AliITSUv1::kOBModel1 && fBuildLevel < 3) || // Water
2738        (fStaveModel == AliITSUv1::kOBModel2 && fBuildLevel < 4) ) {
2739     halfStaveVol->AddNode(coolWaterVol, 1, new TGeoTranslation(-xpos, ypos1, 0));
2740     halfStaveVol->AddNode(coolWaterVol, 2, new TGeoTranslation( xpos, ypos1, 0));
2741   }
2742
2743   if ( (fStaveModel == AliITSUv1::kOBModel1 && fBuildLevel < 4) || // Kapton
2744        (fStaveModel == AliITSUv1::kOBModel2 && fBuildLevel < 5) ) {
2745     halfStaveVol->AddNode(coolTubeVol,1, new TGeoTranslation(-xpos, ypos1, 0));
2746     halfStaveVol->AddNode(coolTubeVol,2, new TGeoTranslation( xpos, ypos1, 0));
2747   }
2748
2749   if ( (fStaveModel == AliITSUv1::kOBModel1 && fBuildLevel < 5) || // Carbon
2750        (fStaveModel == AliITSUv1::kOBModel2 && fBuildLevel < 6) ) {
2751     halfStaveVol->AddNode(graphtubVol,1, new TGeoTranslation(-xpos, ypos1, 0));
2752     halfStaveVol->AddNode(graphtubVol,2, new TGeoTranslation( xpos, ypos1, 0));
2753
2754     halfStaveVol->AddNode(fleectubVol,1, new TGeoTranslation(-xpos, ypos1, 0));
2755     halfStaveVol->AddNode(fleectubVol,2, new TGeoTranslation( xpos, ypos1, 0));
2756   }
2757
2758   xpos = xHalfSt - graphlat->GetDX();
2759   ypos1 = ypos - (coldPlate->GetDY() + graphlat->GetDY());
2760   if ( (fStaveModel == AliITSUv1::kOBModel1 && fBuildLevel < 5) || // Carbon
2761        (fStaveModel == AliITSUv1::kOBModel2 && fBuildLevel < 6) ) {
2762     halfStaveVol->AddNode(graphlatVol,1, new TGeoTranslation(-xpos, ypos1, 0));
2763     halfStaveVol->AddNode(graphlatVol,2, new TGeoTranslation( xpos, ypos1, 0));
2764
2765     halfStaveVol->AddNode(graphmidVol,1, new TGeoTranslation(0, ypos1, 0));
2766
2767     xpos = xHalfSt - 2*graphlat->GetDX() + graphvert->GetDX();
2768     ypos1 = ypos - (coldPlate->GetDY()+2*graphlat->GetDY()+graphvert->GetDY());
2769     halfStaveVol->AddNode(graphvertVol,1,new TGeoTranslation(-xpos, ypos1, 0));
2770     halfStaveVol->AddNode(graphvertVol,2,new TGeoTranslation( xpos, ypos1, 0));
2771     xpos = graphmid->GetDX() - graphvert->GetDX();
2772     halfStaveVol->AddNode(graphvertVol,3,new TGeoTranslation(-xpos, ypos1, 0));
2773     halfStaveVol->AddNode(graphvertVol,4,new TGeoTranslation( xpos, ypos1, 0));
2774   }
2775
2776   xpos = xHalfSt - fleeclat->GetDX();
2777   ypos1 = ypos - (coldPlate->GetDY() +2*graphlat->GetDY() +fleeclat->GetDY());
2778   if ( (fStaveModel == AliITSUv1::kOBModel1 && fBuildLevel < 5) || // Carbon
2779        (fStaveModel == AliITSUv1::kOBModel2 && fBuildLevel < 6) ) {
2780     halfStaveVol->AddNode(fleeclatVol,1, new TGeoTranslation(-xpos, ypos1, 0));
2781     halfStaveVol->AddNode(fleeclatVol,2, new TGeoTranslation( xpos, ypos1, 0));
2782
2783     halfStaveVol->AddNode(fleecmidVol, 1, new TGeoTranslation(0, ypos1, 0));
2784
2785     xpos = xHalfSt - 2*fleeclat->GetDX() + fleecvert->GetDX();
2786     ypos1 = ypos - (coldPlate->GetDY() +2*graphlat->GetDY()
2787                  + 2*fleeclat->GetDY() + fleecvert->GetDY());
2788     halfStaveVol->AddNode(fleecvertVol,1,new TGeoTranslation(-xpos, ypos1, 0));
2789     halfStaveVol->AddNode(fleecvertVol,2,new TGeoTranslation( xpos, ypos1, 0));
2790     xpos = fleecmid->GetDX() - fleecvert->GetDX();
2791     halfStaveVol->AddNode(fleecvertVol,3,new TGeoTranslation(-xpos, ypos1, 0));
2792     halfStaveVol->AddNode(fleecvertVol,4,new TGeoTranslation( xpos, ypos1, 0));
2793   }
2794
2795
2796   //THE FOLLOWING IS ONLY A REMINDER FOR WHAT IS STILL MISSING
2797
2798 //   for (Int_t j=0; j<fNChips; j++) {
2799
2800 //     zpos = -(zact + (fNChips-1)*modGap)/2 + j*(zMod + modGap) + zMod/2;
2801 //     zpos5cm = -(zact + (fNChips-1)*modGap)/2 + (j+1)*(zMod + modGap) + flexOverlap/2 ;
2802
2803 //     halfStaveVol->AddNode(moduleVol, j, new TGeoTranslation(xPos, -ylen + yPos + 2*rCoolMax + yCPlate + yGlue + yModPlate + ymod, zpos));
2804 //     halfStaveVol->AddNode(moduleVol, fNChips+j, new TGeoTranslation(-xPos, -ylen + yPos + 2*rCoolMax + yCPlate + yGlue + yModPlate + ymod +deltaY, zpos));
2805
2806 //     if((j+1)!=fNChips){
2807 //       halfStaveVol->AddNode(flex1_5cmVol,j,new TGeoTranslation(xPos,-ylen + yPos + 2*rCoolMax + yCPlate + yGlue + yModPlate + 2*ymod + yFlex1 + yFlex2 + yFlex1/2,zpos5cm));
2808 //       halfStaveVol->AddNode(flex1_5cmVol,fNChips+j,new TGeoTranslation(-xPos,-ylen + yPos + 2*rCoolMax + yCPlate + yGlue + yModPlate + 2*ymod + yFlex1 + yFlex2 + yFlex1/2 +deltaY,zpos5cm));
2809 //       halfStaveVol->AddNode(flex2_5cmVol,j,new TGeoTranslation(xPos,-ylen + yPos + 2*rCoolMax + yCPlate + yGlue + yModPlate + 2*ymod + 2*yFlex1 + 3*yFlex2/2,zpos5cm));
2810 //       halfStaveVol->AddNode(flex2_5cmVol,fNChips+j,new TGeoTranslation(-xPos,-ylen + yPos + 2*rCoolMax + yCPlate + yGlue + yModPlate + 2*ymod + 2*yFlex1 + 3*yFlex2/2 +deltaY,zpos5cm));
2811 //     }
2812 //     else {
2813 //       halfStaveVol->AddNode(flex1_5cmVol,j,new TGeoTranslation(xPos,-ylen + yPos + 2*rCoolMax + yCPlate + yGlue + yModPlate + 2*ymod + yFlex1/2,zpos5cm-modGap));
2814 //       halfStaveVol->AddNode(flex1_5cmVol,fNChips+j,new TGeoTranslation(-xPos,-ylen + yPos + 2*rCoolMax + yCPlate + yGlue + yModPlate + 2*ymod + yFlex1/2 +deltaY,zpos5cm-modGap));
2815 //       halfStaveVol->AddNode(flex2_5cmVol,j,new TGeoTranslation(xPos,-ylen + yPos + 2*rCoolMax + yCPlate + yGlue + yModPlate +2*ymod + yFlex1 + yFlex2/2,zpos5cm-modGap));
2816 //       halfStaveVol->AddNode(flex2_5cmVol,fNChips+j,new TGeoTranslation(-xPos,-ylen + yPos + 2*rCoolMax + yCPlate + yGlue + yModPlate + 2*ymod + yFlex1 + yFlex2/2 +deltaY,zpos5cm-modGap));
2817
2818 //       }
2819 //   }
2820   
2821
2822   // Done, return the half stave structure
2823   return halfStaveVol;
2824 }
2825
2826 //________________________________________________________________________
2827 TGeoVolume* AliITSUv1Layer::CreateSpaceFrameOuterB(const TGeoManager *mgr){
2828 //
2829 // Create the space frame for the Outer Barrel
2830 //
2831 // Input:
2832 //         mgr  : the GeoManager (used only to get the proper material)
2833 //
2834 // Output:
2835 //
2836 // Return:
2837 //
2838 //
2839
2840   TGeoVolume *mechStavVol = 0;
2841
2842   switch (fStaveModel) {
2843     case AliITSUv1::kOBModelDummy:
2844     case AliITSUv1::kOBModel0:
2845       mechStavVol = CreateSpaceFrameOuterBDummy(mgr);
2846       break;
2847     case AliITSUv1::kOBModel1:
2848     case AliITSUv1::kOBModel2:
2849       mechStavVol = CreateSpaceFrameOuterB1(mgr);
2850       break;
2851     default:
2852       AliFatal(Form("Unknown stave model %d",fStaveModel));
2853       break;
2854   }
2855
2856   return mechStavVol; 
2857 }
2858
2859 //________________________________________________________________________
2860 TGeoVolume* AliITSUv1Layer::CreateSpaceFrameOuterBDummy(const TGeoManager *) const {
2861 //
2862 // Create dummy stave
2863 //
2864 // Input:
2865 //         mgr  : the GeoManager (used only to get the proper material)
2866 //
2867 // Output:
2868 //
2869 // Return:
2870 //
2871
2872
2873   // Done, return the stave structur
2874   return 0;
2875 }
2876
2877 //________________________________________________________________________
2878 TGeoVolume* AliITSUv1Layer::CreateSpaceFrameOuterB1(const TGeoManager *mgr){
2879 //
2880 // Create the space frame for the Outer Barrel (Model 1)
2881 //
2882 // Input:
2883 //         mgr  : the GeoManager (used only to get the proper material)
2884 //
2885 // Output:
2886 //
2887 // Return:
2888 //         a TGeoVolume with the Space Frame of a stave
2889 //
2890 // Created:      20 Dec 2013  Anastasia Barbano
2891 // Updated:      15 Jan 2014  Mario Sitta
2892 // Updated:      18 Feb 2014  Mario Sitta
2893 // Updated:      12 Mar 2014  Mario Sitta
2894 // Updated:      15 Dec 2014  Mario Sitta
2895 // Updated:      28 Jan 2014  Mario Sitta  Change frame shape to avoid overlaps
2896 //
2897
2898
2899   // Materials defined in AliITSUv1
2900   TGeoMedium *medCarbon       = mgr->GetMedium("ITS_M55J6K$");
2901   TGeoMedium *medF6151B05M    = mgr->GetMedium("ITS_F6151B05M$");
2902   TGeoMedium *medAir          = mgr->GetMedium("ITS_AIR$");
2903
2904
2905   // Local parameters
2906   Double_t halfFrameWidth  = fgkOBSpaceFrameWidth/2;
2907   Double_t triangleHeight  = fgkOBSpaceFrameHeight;
2908   Double_t sframeHeight    = triangleHeight + fgkOBSFrameBaseRibDiam
2909                                             + fgkOBSFrameULegHeight2*2;
2910   Double_t staveLa         = fgkOBSpaceFrameTopVL;
2911   Double_t staveHa         = fgkOBSpaceFrameTopVH;
2912   Double_t staveLb         = fgkOBSpaceFrameSideVL;
2913   Double_t staveHb         = fgkOBSpaceFrameSideVH;
2914   Double_t alphaDeg        = fgkOBSpaceFrameVAlpha;
2915   Double_t alphaRad        = alphaDeg*TMath::DegToRad()/2;
2916   Double_t beta            = fgkOBSpaceFrameVBeta*TMath::DegToRad()/2;
2917   Double_t sideRibRadius   = fgkOBSFrameSideRibDiam/2;
2918   Double_t sidePhiDeg      = fgkOBSFrameSideRibPhi;
2919   Double_t sidePhiRad      = sidePhiDeg*TMath::DegToRad();
2920   Double_t baseRibRadius   = fgkOBSFrameBaseRibDiam/2;
2921   Double_t basePhiDeg      = fgkOBSFrameBaseRibPhi;
2922   Double_t basePhiRad      = basePhiDeg*TMath::DegToRad();
2923   Double_t ulegHalfLen     = fgkOBSFrameULegLen/2;
2924   Double_t ulegHalfWidth   = fgkOBSFrameULegWidth;
2925   Double_t ulegHigh1       = fgkOBSFrameULegHeight1;
2926   Double_t ulegHigh2       = fgkOBSFrameULegHeight2;
2927   Double_t ulegThick       = fgkOBSFrameULegThick;
2928
2929   Double_t xlen, zlen;
2930   Double_t xpos, ypos, zpos;
2931   Double_t unitlen;
2932   Double_t xtru[22], ytru[22];
2933   char volname[30];
2934
2935
2936   zlen = fgkOBSpaceFrameZLen[fLayerNumber/5]; // 3,4 -> 0 - 5,6 -> 1
2937   unitlen = fgkOBSpaceFrameUnitLen;
2938
2939   xlen = halfFrameWidth + sideRibRadius;
2940
2941   // We need a properly shaped Xtru to accomodate the ribs avoiding
2942   // overlaps with the HalfStave cooling tubes
2943   xtru[ 0] = fgkOBSFrameULegXPos - ulegHalfLen;
2944   ytru[ 0] = -(triangleHeight/2 + baseRibRadius);
2945   xtru[ 1] = xtru[0];
2946   ytru[ 1] = ytru[0] - ulegHigh1;
2947   xtru[ 2] = xtru[1] + ulegThick;
2948   ytru[ 2] = ytru[1];
2949   xtru[ 3] = xtru[2];
2950   ytru[ 3] = ytru[0] - ulegThick;
2951   xtru[ 7] = fgkOBSFrameULegXPos + ulegHalfLen;
2952   ytru[ 7] = ytru[0];
2953   xtru[ 6] = xtru[7];
2954   ytru[ 6] = ytru[1];
2955   xtru[ 5] = xtru[6] - ulegThick;
2956   ytru[ 5] = ytru[6];
2957   xtru[ 4] = xtru[5];
2958   ytru[ 4] = ytru[3];
2959   xtru[ 8] = xlen;
2960   ytru[ 8] = ytru[7];
2961   xtru[ 9] = xtru[8];
2962   ytru[ 9] = 0.9*ytru[8];
2963   xtru[10] = 0.3*xtru[8];
2964   ytru[10] = triangleHeight/2;
2965   for (Int_t i=0; i<11; i++) { // Reflect on the X negative side
2966     xtru[i+11] = -xtru[10-i];
2967     ytru[i+11] =  ytru[10-i];
2968   }
2969   ytru[15] = ytru[0] - ulegHigh2; // U-legs on negative X are longer
2970   ytru[16] = ytru[15];
2971   ytru[19] = ytru[15];
2972   ytru[20] = ytru[15];
2973
2974
2975   // The space frame container and a single unit
2976   // We need two units because the base ribs are alternately oriented
2977   // The end units are slightly different
2978   TGeoXtru *spaceFrame = new TGeoXtru(2);
2979   spaceFrame->DefinePolygon(22, xtru, ytru);
2980   spaceFrame->DefineSection(0,-zlen/2);
2981   spaceFrame->DefineSection(1, zlen/2);
2982
2983   TGeoXtru *frameUnit  = new TGeoXtru(2);
2984   frameUnit->DefinePolygon(22, xtru, ytru);
2985   frameUnit->DefineSection(0,-unitlen/2);
2986   frameUnit->DefineSection(1, unitlen/2);
2987
2988   TGeoXtru *endUnit    = new TGeoXtru(2);
2989   endUnit->DefinePolygon(22, xtru, ytru);
2990   endUnit->DefineSection(0,-unitlen/2);
2991   endUnit->DefineSection(1, unitlen/2);
2992
2993
2994   snprintf(volname, 30, "SpaceFrameVolumeLay%d", fLayerNumber);
2995   TGeoVolume *spaceFrameVol = new TGeoVolume(volname, spaceFrame, medAir);
2996   spaceFrameVol->SetVisibility(kFALSE);
2997
2998   TGeoVolume *unitVol[2];
2999   unitVol[0] = new TGeoVolume("SpaceFrameUnit0", frameUnit, medAir);
3000   unitVol[1] = new TGeoVolume("SpaceFrameUnit1", frameUnit, medAir);
3001
3002   TGeoVolume *endVol[2];
3003   endVol[0]  = new TGeoVolume("SpaceFrameEndUnit0", endUnit, medAir);
3004   endVol[1]  = new TGeoVolume("SpaceFrameEndUnit1", endUnit, medAir);
3005
3006   // The actual volumes
3007
3008   //--- The top V of the Carbon Fiber Stave (segment)
3009   TGeoXtru *cfStavTop = CreateStaveSide("CFstavTopCornerVolshape",
3010                         unitlen/2., alphaRad, beta, staveLa, staveHa, kTRUE);
3011
3012   TGeoVolume *cfStavTopVol = new TGeoVolume("CFstavTopCornerVol",
3013                                             cfStavTop, medCarbon);
3014   cfStavTopVol->SetLineColor(35);
3015
3016   unitVol[0]->AddNode(cfStavTopVol, 1,
3017                       new TGeoTranslation(0, triangleHeight/2, 0));
3018
3019   unitVol[1]->AddNode(cfStavTopVol, 1,
3020                       new TGeoTranslation(0, triangleHeight/2, 0));
3021   
3022   endVol[0]->AddNode(cfStavTopVol, 1,
3023                       new TGeoTranslation(0, triangleHeight/2, 0));
3024
3025   endVol[1]->AddNode(cfStavTopVol, 1,
3026                       new TGeoTranslation(0, triangleHeight/2, 0));
3027   
3028   //--- The two side V's
3029   TGeoXtru *cfStavSide = CreateStaveSide("CFstavSideCornerVolshape",
3030                          unitlen/2., alphaRad, beta, staveLb, staveHb, kFALSE);
3031
3032   TGeoVolume *cfStavSideVol = new TGeoVolume("CFstavSideCornerVol",
3033                                              cfStavSide, medCarbon);
3034   cfStavSideVol->SetLineColor(35);
3035
3036   unitVol[0]->AddNode(cfStavSideVol, 1,
3037                    new TGeoTranslation( halfFrameWidth, -triangleHeight/2, 0));
3038   unitVol[0]->AddNode(cfStavSideVol, 2,
3039                    new TGeoCombiTrans( -halfFrameWidth, -triangleHeight/2, 0,
3040                                          new TGeoRotation("",90,180,-90)));
3041
3042   unitVol[1]->AddNode(cfStavSideVol, 1,
3043                    new TGeoTranslation( halfFrameWidth, -triangleHeight/2, 0));
3044   unitVol[1]->AddNode(cfStavSideVol, 2,
3045                    new TGeoCombiTrans( -halfFrameWidth, -triangleHeight/2, 0,
3046                                          new TGeoRotation("",90,180,-90)));
3047
3048   endVol[0]->AddNode(cfStavSideVol, 1,
3049                    new TGeoTranslation( halfFrameWidth, -triangleHeight/2, 0));
3050   endVol[0]->AddNode(cfStavSideVol, 2,
3051                    new TGeoCombiTrans( -halfFrameWidth, -triangleHeight/2, 0,
3052                                          new TGeoRotation("",90,180,-90)));
3053
3054   endVol[1]->AddNode(cfStavSideVol, 1,
3055                    new TGeoTranslation( halfFrameWidth, -triangleHeight/2, 0));
3056   endVol[1]->AddNode(cfStavSideVol, 2,
3057                    new TGeoCombiTrans( -halfFrameWidth, -triangleHeight/2, 0,
3058                                          new TGeoRotation("",90,180,-90)));
3059
3060
3061   //--- The beams
3062   // Ribs on the sides
3063   Double_t ribZProj = triangleHeight/TMath::Tan(sidePhiRad);
3064   Double_t sideRibLen = TMath::Sqrt( ribZProj*ribZProj             +
3065                                      triangleHeight*triangleHeight +
3066                                      halfFrameWidth*halfFrameWidth );
3067
3068   TGeoTubeSeg *sideRib = new TGeoTubeSeg(0, sideRibRadius,
3069                                          sideRibLen/2, 0, 180);
3070   TGeoVolume *sideRibVol = new TGeoVolume("CFstavSideBeamVol",
3071                                           sideRib, medCarbon);
3072   sideRibVol->SetLineColor(35);
3073
3074   TGeoCombiTrans *sideTransf[4];
3075   xpos = halfFrameWidth/2 + 0.8*staveHa*TMath::Cos(alphaRad/2);
3076   ypos = -sideRibRadius/2;
3077   zpos = unitlen/4;
3078
3079   sideTransf[0] = new TGeoCombiTrans( xpos, ypos,-zpos,
3080                                       new TGeoRotation("", 90-alphaDeg,
3081                                                        -sidePhiDeg, -90));
3082   sideTransf[1] = new TGeoCombiTrans( xpos, ypos, zpos,
3083                                       new TGeoRotation("", 90-alphaDeg,
3084                                                         sidePhiDeg, -90));
3085   sideTransf[2] = new TGeoCombiTrans(-xpos, ypos,-zpos,
3086                                       new TGeoRotation("", 90+alphaDeg,
3087                                                         sidePhiDeg, -90));
3088   sideTransf[3] = new TGeoCombiTrans(-xpos, ypos, zpos,
3089                                       new TGeoRotation("", 90+alphaDeg,
3090                                                        -sidePhiDeg, -90));
3091
3092   unitVol[0]->AddNode(sideRibVol, 1, sideTransf[0]);
3093   unitVol[0]->AddNode(sideRibVol, 2, sideTransf[1]);
3094   unitVol[0]->AddNode(sideRibVol, 3, sideTransf[2]);
3095   unitVol[0]->AddNode(sideRibVol, 4, sideTransf[3]);
3096
3097   unitVol[1]->AddNode(sideRibVol, 1, sideTransf[0]);
3098   unitVol[1]->AddNode(sideRibVol, 2, sideTransf[1]);
3099   unitVol[1]->AddNode(sideRibVol, 3, sideTransf[2]);
3100   unitVol[1]->AddNode(sideRibVol, 4, sideTransf[3]);
3101
3102   endVol[0]->AddNode(sideRibVol, 1, sideTransf[0]);
3103   endVol[0]->AddNode(sideRibVol, 2, sideTransf[1]);
3104   endVol[0]->AddNode(sideRibVol, 3, sideTransf[2]);
3105   endVol[0]->AddNode(sideRibVol, 4, sideTransf[3]);
3106
3107   endVol[1]->AddNode(sideRibVol, 1, sideTransf[0]);
3108   endVol[1]->AddNode(sideRibVol, 2, sideTransf[1]);
3109   endVol[1]->AddNode(sideRibVol, 3, sideTransf[2]);
3110   endVol[1]->AddNode(sideRibVol, 4, sideTransf[3]);
3111
3112
3113   // Ribs on the bottom
3114   // Rib1 are the inclined ones, Rib2 the straight ones
3115   Double_t baseRibLen = 0.98*2*halfFrameWidth/TMath::Sin(basePhiRad);
3116
3117   TGeoTubeSeg *baseRib1 = new TGeoTubeSeg(0, baseRibRadius,
3118                                           baseRibLen/2, 0, 180);
3119   TGeoVolume *baseRib1Vol = new TGeoVolume("CFstavBaseBeam1Vol",
3120                                            baseRib1, medCarbon);
3121   baseRib1Vol->SetLineColor(35);
3122
3123   TGeoTubeSeg *baseRib2 = new TGeoTubeSeg(0, baseRibRadius,
3124                                           halfFrameWidth, 0, 90);
3125   TGeoVolume *baseRib2Vol = new TGeoVolume("CFstavBaseBeam2Vol",
3126                                            baseRib2, medCarbon);
3127   baseRib2Vol->SetLineColor(35);
3128
3129   TGeoTubeSeg *baseEndRib = new TGeoTubeSeg(0, baseRibRadius,
3130                                             halfFrameWidth, 0, 180);
3131   TGeoVolume *baseEndRibVol = new TGeoVolume("CFstavBaseEndBeamVol",
3132                                              baseEndRib, medCarbon);
3133   baseEndRibVol->SetLineColor(35);
3134
3135   TGeoCombiTrans *baseTransf[6];
3136   ypos = triangleHeight/2;
3137   zpos = unitlen/2;
3138
3139   baseTransf[0] = new TGeoCombiTrans("", 0, -ypos, -zpos,
3140                                      new TGeoRotation("", 90, 90,  90));
3141   baseTransf[1] = new TGeoCombiTrans("", 0, -ypos,  zpos,
3142                                      new TGeoRotation("",-90, 90, -90));
3143   baseTransf[2] = new TGeoCombiTrans(0, -ypos, 0,
3144                                      new TGeoRotation("",-90, basePhiDeg,-90));
3145   baseTransf[3] = new TGeoCombiTrans(0, -ypos, 0,
3146                                      new TGeoRotation("",-90,-basePhiDeg,-90));
3147   zpos -= baseEndRib->GetRmax();
3148   baseTransf[4] = new TGeoCombiTrans("", 0, -ypos, -zpos,
3149                                      new TGeoRotation("", 90, 90,  90));
3150   baseTransf[5] = new TGeoCombiTrans("", 0, -ypos,  zpos,
3151                                      new TGeoRotation("", 90, 90,  90));
3152
3153   unitVol[0]->AddNode(baseRib2Vol, 1, baseTransf[0]);
3154   unitVol[0]->AddNode(baseRib2Vol, 2, baseTransf[1]);
3155   unitVol[0]->AddNode(baseRib1Vol, 1, baseTransf[2]);
3156
3157   unitVol[1]->AddNode(baseRib2Vol, 1, baseTransf[0]);
3158   unitVol[1]->AddNode(baseRib2Vol, 2, baseTransf[1]);
3159   unitVol[1]->AddNode(baseRib1Vol, 1, baseTransf[3]);
3160
3161   endVol[0]->AddNode(baseEndRibVol, 1, baseTransf[4]);
3162   endVol[0]->AddNode(baseRib2Vol,   1, baseTransf[1]);
3163   endVol[0]->AddNode(baseRib1Vol,   1, baseTransf[2]);
3164
3165   endVol[1]->AddNode(baseEndRibVol, 1, baseTransf[5]);
3166   endVol[1]->AddNode(baseRib2Vol,   1, baseTransf[0]);
3167   endVol[1]->AddNode(baseRib1Vol,   1, baseTransf[2]);
3168
3169
3170   // U-Legs
3171   // The shorter
3172   xtru[0] = ulegHalfLen;
3173   ytru[0] = 0;
3174   xtru[1] = xtru[0];
3175   ytru[1] = -ulegHigh1;
3176   xtru[2] = xtru[1] - ulegThick;
3177   ytru[2] = ytru[1];
3178   xtru[3] = xtru[2];
3179   ytru[3] = ytru[0] - ulegThick;
3180   for (Int_t i=0; i<4; i++) { // Reflect on the X negative side
3181     xtru[i+4] = -xtru[3-i];
3182     ytru[i+4] =  ytru[3-i];
3183   }
3184
3185   TGeoXtru *uleg1full = new TGeoXtru(2);  // This will go in the end units
3186   uleg1full->DefinePolygon(8, xtru, ytru);
3187   uleg1full->DefineSection(0,-ulegHalfWidth);
3188   uleg1full->DefineSection(1, ulegHalfWidth);
3189
3190   TGeoXtru *uleg1half = new TGeoXtru(2);  // This will go in the middle unitys
3191   uleg1half->DefinePolygon(8, xtru, ytru);
3192   uleg1half->DefineSection(0,-ulegHalfWidth/2);
3193   uleg1half->DefineSection(1, ulegHalfWidth/2);
3194
3195   TGeoVolume *uleg1fullVol = new TGeoVolume("CFstavULeg1FullVol",
3196                                             uleg1full, medF6151B05M);
3197   uleg1fullVol->SetLineColor(35);
3198
3199   TGeoVolume *uleg1halfVol = new TGeoVolume("CFstavULeg1HalfVol",
3200                                             uleg1half, medF6151B05M);
3201   uleg1halfVol->SetLineColor(35);
3202
3203   // The longer
3204   ytru[1] = -ulegHigh2;
3205   ytru[2] = -ulegHigh2;
3206   ytru[5] = -ulegHigh2;
3207   ytru[6] = -ulegHigh2;
3208
3209   TGeoXtru *uleg2full = new TGeoXtru(2);  // This will go in the end units
3210   uleg2full->DefinePolygon(8, xtru, ytru);
3211   uleg2full->DefineSection(0,-ulegHalfWidth);
3212   uleg2full->DefineSection(1, ulegHalfWidth);
3213
3214   TGeoXtru *uleg2half = new TGeoXtru(2);  // This will go in the middle unitys
3215   uleg2half->DefinePolygon(8, xtru, ytru);
3216   uleg2half->DefineSection(0,-ulegHalfWidth/2);
3217   uleg2half->DefineSection(1, ulegHalfWidth/2);
3218
3219   TGeoVolume *uleg2fullVol = new TGeoVolume("CFstavULeg2FullVol",
3220                                             uleg2full, medF6151B05M);
3221   uleg2fullVol->SetLineColor(35);
3222
3223   TGeoVolume *uleg2halfVol = new TGeoVolume("CFstavULeg2HalfVol",
3224                                             uleg2half, medF6151B05M);
3225   uleg2halfVol->SetLineColor(35);
3226
3227
3228   xpos = fgkOBSFrameULegXPos;
3229   ypos = triangleHeight/2 + baseRibRadius;
3230   zpos = unitlen/2 - uleg1half->GetZ(1);
3231
3232   unitVol[0]->AddNode(uleg1halfVol, 1,  // Shorter on +X
3233                       new TGeoTranslation(  xpos, -ypos, -zpos));
3234   unitVol[0]->AddNode(uleg1halfVol, 2,
3235                       new TGeoTranslation(  xpos, -ypos,  zpos));
3236
3237   unitVol[1]->AddNode(uleg1halfVol, 1,
3238                       new TGeoTranslation(  xpos, -ypos, -zpos));
3239   unitVol[1]->AddNode(uleg1halfVol, 2,
3240                       new TGeoTranslation(  xpos, -ypos,  zpos));
3241
3242   unitVol[0]->AddNode(uleg2halfVol, 1,  // Longer on -X
3243                       new TGeoTranslation( -xpos, -ypos, -zpos));
3244   unitVol[0]->AddNode(uleg2halfVol, 2,
3245                       new TGeoTranslation( -xpos, -ypos,  zpos));
3246
3247   unitVol[1]->AddNode(uleg2halfVol, 1,
3248                       new TGeoTranslation( -xpos, -ypos, -zpos));
3249   unitVol[1]->AddNode(uleg2halfVol, 2,
3250                       new TGeoTranslation( -xpos, -ypos,  zpos));
3251
3252   endVol[0]->AddNode(uleg1halfVol, 1,
3253                   new TGeoTranslation(  xpos, -ypos,  zpos));
3254   endVol[0]->AddNode(uleg2halfVol, 1,
3255                   new TGeoTranslation( -xpos, -ypos,  zpos));
3256
3257   endVol[1]->AddNode(uleg1halfVol, 1,
3258                   new TGeoTranslation(  xpos, -ypos, -zpos));
3259   endVol[1]->AddNode(uleg2halfVol, 1,
3260                   new TGeoTranslation( -xpos, -ypos, -zpos));
3261
3262   zpos = unitlen/2 - uleg1full->GetZ(1);
3263   endVol[0]->AddNode(uleg1fullVol, 1,
3264                   new TGeoTranslation(  xpos, -ypos, -zpos));
3265   endVol[0]->AddNode(uleg2fullVol, 1,
3266                   new TGeoTranslation( -xpos, -ypos, -zpos));
3267
3268   endVol[1]->AddNode(uleg1fullVol, 1,
3269                   new TGeoTranslation(  xpos, -ypos,  zpos));
3270   endVol[1]->AddNode(uleg2fullVol, 1,
3271                   new TGeoTranslation( -xpos, -ypos,  zpos));
3272
3273
3274   // Finally build up the space frame
3275   Int_t nUnits = fgkOBSpaceFrameNUnits[fLayerNumber/5]; // 3,4 -> 0 - 5,6 -> 1
3276
3277   zpos = -spaceFrame->GetDZ() + endUnit->GetDZ();
3278   spaceFrameVol->AddNode(endVol[0], 1, new TGeoTranslation(0, 0, zpos));
3279
3280   for(Int_t i=1; i<nUnits-1; i++){
3281     zpos = -spaceFrame->GetDZ() + (1 + 2*i)*frameUnit->GetDZ();
3282     Int_t j = i/2;
3283     Int_t k = i - j*2;  // alternatively 0 or 1
3284     spaceFrameVol->AddNode(unitVol[k], j+1, new TGeoTranslation(0, 0, zpos));
3285   }
3286
3287   zpos = -spaceFrame->GetDZ() + (2*nUnits - 1)*endUnit->GetDZ();
3288   spaceFrameVol->AddNode(endVol[1], 1, new TGeoTranslation(0, 0, zpos));
3289
3290
3291   // Done, return the space frame structure
3292   return spaceFrameVol;
3293 }
3294
3295 //________________________________________________________________________
3296 TGeoVolume* AliITSUv1Layer::CreateChipInnerB(const Double_t xchip,
3297                                              const Double_t ychip,   
3298                                              const Double_t zchip,
3299                                              const TGeoManager *mgr){
3300 //
3301 // Creates the actual Chip
3302 //
3303 // Input:
3304 //         xchip,ychip,zchip : the chip dimensions
3305 //         mgr  : the GeoManager (used only to get the proper material)
3306 //
3307 // Output:
3308 //
3309 // Return:
3310 //
3311 // Created:      22 Jun 2011  Mario Sitta
3312 //
3313
3314   char volname[30];
3315   Double_t xlen, ylen, zlen;
3316   Double_t xpos, ypos, zpos;
3317
3318
3319   // First create all needed shapes
3320
3321   // The chip
3322   TGeoBBox *chip = new TGeoBBox(xchip,  ychip, zchip);
3323
3324   // The sensor
3325   xlen = chip->GetDX();
3326   ylen = 0.5*fSensorThick;
3327   zlen = chip->GetDZ();
3328   TGeoBBox *sensor = new TGeoBBox(xlen, ylen, zlen);
3329
3330
3331   // We have all shapes: now create the real volumes
3332   TGeoMedium *medSi  = mgr->GetMedium("ITS_SI$");
3333
3334   snprintf(volname, 30, "%s%d", AliITSUGeomTGeo::GetITSChipPattern(), fLayerNumber);
3335   TGeoVolume *chipVol = new TGeoVolume(volname, chip, medSi);
3336   chipVol->SetVisibility(kTRUE);
3337   chipVol->SetLineColor(1);
3338
3339   snprintf(volname, 30, "%s%d", AliITSUGeomTGeo::GetITSSensorPattern(), fLayerNumber);
3340   TGeoVolume *sensVol = new TGeoVolume(volname, sensor, medSi);
3341   sensVol->SetVisibility(kTRUE);
3342   sensVol->SetLineColor(8);
3343   sensVol->SetLineWidth(1);
3344   sensVol->SetFillColor(sensVol->GetLineColor());
3345   sensVol->SetFillStyle(4000); // 0% transparent
3346
3347
3348   // Now build up the chip
3349   xpos = 0.;
3350   ypos = -chip->GetDY() + sensor->GetDY();
3351   zpos = 0.;
3352
3353   chipVol->AddNode(sensVol, 1, new TGeoTranslation(xpos, ypos, zpos));
3354
3355   // Done, return the chip
3356   return chipVol;
3357 }
3358
3359 //________________________________________________________________________
3360 TGeoVolume* AliITSUv1Layer::CreateModuleOuterB(const TGeoManager *mgr){
3361 //
3362 // Creates the OB Module: HIC + FPC + Carbon plate
3363 //
3364 // Input:
3365 //         mgr  : the GeoManager (used only to get the proper material)
3366 //
3367 // Output:
3368 //
3369 // Return:
3370 //         the module as a TGeoVolume
3371 //
3372 // Created:      18 Dec 2013  M. Sitta, A. Barbano
3373 // Updated:      26 Feb 2014  M. Sitta
3374 // Updated:      12 Nov 2014  M. Sitta  Model2 is w/o Carbon Plate and Glue
3375 //                                      and Cu instead of Al
3376 //
3377
3378
3379   char volname[30];
3380
3381   Double_t xGap  = fgkOBChipXGap;
3382   Double_t zGap  = fgkOBChipZGap;
3383
3384   Double_t xchip, ychip, zchip;
3385   Double_t xlen, ylen, zlen;
3386   Double_t xpos, ypos, zpos;
3387   
3388   // First create all needed shapes
3389
3390   // The chip (the same as for IB)
3391   xlen = (fgkOBHalfStaveWidth/2-xGap/2)/fgkOBNChipRows;
3392   ylen = 0.5*fChipThick;
3393   zlen = (fgkOBModuleZLength - (fgkOBChipsPerRow-1)*zGap)/(2*fgkOBChipsPerRow);
3394
3395   TGeoVolume *chipVol = CreateChipInnerB(xlen, ylen, zlen);
3396
3397   xchip = ((TGeoBBox*)chipVol->GetShape())->GetDX();
3398   ychip = ((TGeoBBox*)chipVol->GetShape())->GetDY();
3399   zchip = ((TGeoBBox*)chipVol->GetShape())->GetDZ();
3400
3401   // The module carbon plate
3402   xlen = fgkOBHalfStaveWidth/2;
3403   ylen = fgkOBCarbonPlateThick/2;
3404   zlen = fgkOBModuleZLength/2;
3405   TGeoBBox *modPlate = new TGeoBBox("CarbonPlate", xlen, ylen, zlen);
3406
3407   // The glue
3408   ylen = fgkOBGlueThickM1/2;
3409   TGeoBBox *glue = new TGeoBBox("Glue", xlen, ylen, zlen);
3410
3411   // The FPC cables
3412   TGeoBBox *flexMetal;
3413   if (fStaveModel == AliITSUv1::kOBModel1) {
3414     ylen = fgkOBFlexCableAlThick/2;
3415     flexMetal = new TGeoBBox("FlexAl", xlen, ylen, zlen);
3416   } else {
3417     ylen = fgkOBFlexCableCuThick/2;
3418     flexMetal = new TGeoBBox("FlexCu", xlen, ylen, zlen);
3419   }
3420
3421   if (fStaveModel == AliITSUv1::kOBModel1)
3422     ylen = fgkOBFlexCableKapThick1/2;
3423   else
3424     ylen = fgkOBFlexCableKapThick/2;
3425   TGeoBBox *flexKap = new TGeoBBox("FlexKap", xlen, ylen, zlen);
3426
3427   // The module
3428   xlen = fgkOBHalfStaveWidth/2;
3429   ylen = ychip + flexMetal->GetDY() + flexKap->GetDY();
3430   if (fStaveModel == AliITSUv1::kOBModel1)
3431     ylen += (modPlate->GetDY() + glue->GetDY());
3432   zlen = fgkOBModuleZLength/2;
3433   TGeoBBox *module = new TGeoBBox("OBModule", xlen,  ylen, zlen);
3434
3435
3436   // We have all shapes: now create the real volumes
3437  
3438   TGeoMedium *medAir      = mgr->GetMedium("ITS_AIR$");
3439   TGeoMedium *medCarbon   = mgr->GetMedium("ITS_CARBON$");
3440   TGeoMedium *medGlue     = mgr->GetMedium("ITS_GLUE$");
3441   TGeoMedium *medAluminum = mgr->GetMedium("ITS_ALUMINUM$");
3442   TGeoMedium *medCopper   = mgr->GetMedium("ITS_COPPER$");
3443   TGeoMedium *medKapton   = mgr->GetMedium("ITS_KAPTON(POLYCH2)$");
3444
3445   TGeoVolume *modPlateVol = new TGeoVolume("CarbonPlateVol",
3446                                             modPlate, medCarbon);
3447   modPlateVol->SetLineColor(kMagenta-8);
3448   modPlateVol->SetFillColor(modPlateVol->GetLineColor());
3449   modPlateVol->SetFillStyle(4000); // 0% transparent
3450
3451   TGeoVolume *glueVol = new TGeoVolume("GlueVol", glue, medGlue);
3452   glueVol->SetLineColor(kBlack);
3453   glueVol->SetFillColor(glueVol->GetLineColor());
3454   glueVol->SetFillStyle(4000); // 0% transparent
3455
3456   TGeoVolume *flexMetalVol;
3457   if (fStaveModel == AliITSUv1::kOBModel1)
3458     flexMetalVol = new TGeoVolume("FPCAlVol", flexMetal, medAluminum);
3459   else
3460     flexMetalVol = new TGeoVolume("FPCCuVol", flexMetal, medCopper);
3461   flexMetalVol->SetLineColor(kRed);
3462   flexMetalVol->SetFillColor(flexMetalVol->GetLineColor());
3463   flexMetalVol->SetFillStyle(4000); // 0% transparent
3464
3465   TGeoVolume *flexKapVol = new TGeoVolume("FPCKapVol", flexKap, medKapton);
3466   flexKapVol->SetLineColor(kGreen);
3467   flexKapVol->SetFillColor(flexKapVol->GetLineColor());
3468   flexKapVol->SetFillStyle(4000); // 0% transparent
3469
3470   snprintf(volname, 30, "%s%d", AliITSUGeomTGeo::GetITSModulePattern(), fLayerNumber);
3471   TGeoVolume *modVol = new TGeoVolume(volname, module, medAir);
3472   modVol->SetVisibility(kTRUE);
3473   
3474
3475   // Now build up the module
3476   // Model1 : CarbonPlate-Glue-Chips-AluminumFPC-KaptonFPC
3477   // Model2 : Chips-CopperFPC-KaptonFPCChips
3478   ypos = -module->GetDY();
3479
3480   if (fStaveModel == AliITSUv1::kOBModel1) {
3481     ypos += modPlate->GetDY();
3482     if (fBuildLevel < 5) // Carbon
3483       modVol->AddNode(modPlateVol, 1, new TGeoTranslation(0, ypos, 0));
3484
3485     ypos += (modPlate->GetDY() + glue->GetDY());
3486     if (fBuildLevel < 2) // Glue
3487       modVol->AddNode(glueVol, 1, new TGeoTranslation(0, ypos, 0));
3488
3489     ypos += glue->GetDY();
3490   }
3491
3492   xpos = -module->GetDX() + xchip;
3493   ypos += ychip;
3494   for(Int_t k=0; k<fgkOBChipsPerRow; k++)   //put 7x2 chip into one module
3495     {
3496       zpos = -module->GetDZ() + zchip + k*(2*zchip + zGap);
3497       modVol->AddNode(chipVol, 2*k  , new TGeoTranslation( xpos, ypos, zpos));
3498       modVol->AddNode(chipVol, 2*k+1, 
3499       new TGeoCombiTrans(-xpos, ypos, zpos, new TGeoRotation("",0,180,180)));
3500       fHierarchy[kChip]+=2;
3501     }
3502
3503   ypos += (ychip + flexMetal->GetDY());
3504   if (fBuildLevel < 1) // Model1: Aluminum  Model2: Copper
3505     modVol->AddNode(flexMetalVol, 1, new TGeoTranslation(0, ypos, 0));
3506
3507   ypos += (flexMetal->GetDY() + flexKap->GetDY());
3508   if ( (fStaveModel == AliITSUv1::kOBModel1 && fBuildLevel < 4) || // Kapton
3509        (fStaveModel == AliITSUv1::kOBModel2 && fBuildLevel < 5) )
3510     modVol->AddNode(flexKapVol, 1, new TGeoTranslation(0, ypos, 0));
3511
3512   // Done, return the module
3513   return modVol;
3514 }
3515
3516 //________________________________________________________________________
3517 void AliITSUv1Layer::SetNUnits(Int_t u)
3518 {
3519 //
3520 // Sets the number of units in a stave:
3521 //      for the Inner Barrel: the number of chips per stave
3522 //      for the Outer Barrel: the number of modules per half stave
3523 //
3524 //
3525 // Input:
3526 //         u :  the number of units
3527 //
3528 // Output:
3529 //
3530 // Return:
3531 //
3532 // Created:      18 Feb 2013  Mario Sitta (was already SetNChips)
3533 //
3534
3535   if (fLayerNumber < fgkNumberOfInnerLayers)
3536     fNChips = u;
3537   else {
3538     fNModules = u;
3539     fNChips = fgkOBChipsPerRow;
3540   }
3541
3542 }
3543
3544 //________________________________________________________________________
3545 void AliITSUv1Layer::SetStaveTilt(const Double_t t)
3546 {
3547 //
3548 // Sets the Stave tilt angle (for turbo layers only)
3549 //
3550 // Input:
3551 //         t :  the stave tilt angle
3552 //
3553 // Output:
3554 //
3555 // Return:
3556 //
3557 // Created:      08 Jul 2011  Mario Sitta
3558 //
3559
3560   if (fIsTurbo)
3561     fStaveTilt = t;
3562   else
3563     AliError("Not a Turbo layer");
3564
3565 }
3566
3567 //________________________________________________________________________
3568 void AliITSUv1Layer::SetStaveWidth(const Double_t w){
3569 //
3570 // Sets the Stave width (for turbo layers only)
3571 //
3572 // Input:
3573 //         w :  the stave width
3574 //
3575 // Output:
3576 //
3577 // Return:
3578 //
3579 // Created:      08 Jul 2011  Mario Sitta
3580 //
3581
3582   if (fIsTurbo)
3583     fStaveWidth = w;
3584   else
3585     AliError("Not a Turbo layer");
3586
3587 }
3588
3589 //________________________________________________________________________
3590 TGeoXtru *AliITSUv1Layer::CreateStaveSide(const char *name,
3591                          Double_t dz, Double_t alpha, Double_t beta,
3592                          Double_t L, Double_t H, Bool_t top) {
3593 //
3594 // Creates the V-shaped sides of the OB space frame
3595 // (from a similar method with same name and function
3596 // in AliITSv11GeometrySDD class by L.Gaudichet)
3597 //
3598 // Updated:      15 Dec 2014  Mario Sitta  Rewritten using Xtru
3599 // Updated:      09 Jan 2015  Mario Sitta  Rewritten again using different
3600 //                                         aperture angles (info by C.Gargiulo)
3601 //
3602
3603     // Create the V shape corner of CF stave
3604
3605     const Int_t nv = 6;
3606     Double_t xv[nv], yv[nv];
3607   
3608     TGeoXtru *cfStavSide = new TGeoXtru(2);
3609     cfStavSide->SetName(name);
3610
3611     Double_t theta = TMath::PiOver2() - beta;
3612     Double_t gamma = beta - alpha;
3613     // Points must be in clockwise order
3614     if (top) { // TOP - vertices not in order
3615       xv[3] = 0;
3616       yv[3] = 0;
3617       xv[2] =  L*TMath::Sin(alpha);
3618       yv[2] = -L*TMath::Cos(alpha);
3619       xv[1] = xv[2] - H*TMath::Cos(alpha);
3620       yv[1] = yv[2] - H*TMath::Sin(alpha);
3621       xv[0] = 0;
3622       yv[0] = yv[1] + TMath::Tan(theta)*xv[1];
3623       xv[4] = -xv[2];  // Reflect
3624       yv[4] =  yv[2];
3625       xv[5] = -xv[1];
3626       yv[5] =  yv[1];
3627     } else { // SIDE
3628       Double_t m = -TMath::Tan(alpha), n = TMath::Tan(gamma);
3629       xv[0] = 0;
3630       yv[0] = 0;
3631       xv[1] = -L*TMath::Cos(2*alpha);
3632       yv[1] =  L*TMath::Sin(2*alpha);
3633       xv[2] = xv[1] - H*TMath::Sin(2*alpha);
3634       yv[2] = yv[1] - H*TMath::Cos(2*alpha);
3635       xv[4] = -L;
3636       yv[4] =  H;
3637       xv[5] = xv[4];
3638       yv[5] = 0;
3639       xv[3] = (yv[4] - n*xv[4])/(m - n);
3640       yv[3] = m*xv[3];
3641     }
3642
3643     cfStavSide->DefinePolygon(nv, xv, yv);
3644     cfStavSide->DefineSection(0,-dz);
3645     cfStavSide->DefineSection(1, dz);
3646
3647     return cfStavSide;
3648 }
3649
3650 //________________________________________________________________________
3651 TGeoCombiTrans *AliITSUv1Layer::CreateCombiTrans(const char *name,
3652                                          Double_t dy, Double_t dz,
3653                                          Double_t dphi, Bool_t planeSym) {
3654 //
3655 // Help method to create a TGeoCombiTrans matrix
3656 // (from a similar method with same name and function
3657 // in AliITSv11GeometrySDD class by L.Gaudichet)
3658 //
3659
3660     //
3661     // return the TGeoCombiTrans which make a translation in y and z
3662     // and a rotation in phi in the global coord system
3663     // If planeSym = true, the rotation places the object symetrically
3664     // (with respect to the transverse plane) to its position in the
3665     // case planeSym = false
3666     //
3667
3668     TGeoTranslation t1(dy*CosD(90.+dphi),dy*SinD(90.+dphi), dz);
3669     TGeoRotation r1("",0.,0.,dphi);
3670     TGeoRotation r2("",90, 180, -90-dphi);
3671
3672     TGeoCombiTrans *combiTrans1 = new TGeoCombiTrans(name);
3673     combiTrans1->SetTranslation(t1);
3674     if (planeSym) combiTrans1->SetRotation(r1);
3675     else  combiTrans1->SetRotation(r2);
3676     return combiTrans1;
3677 }
3678
3679 //________________________________________________________________________
3680 void AliITSUv1Layer::AddTranslationToCombiTrans(TGeoCombiTrans* ct,
3681                                                        Double_t dx,
3682                                                        Double_t dy,
3683                                                        Double_t dz) const{
3684 //
3685 // Help method to add a translation to a TGeoCombiTrans matrix
3686 // (from a similar method with same name and function
3687 // in AliITSv11GeometrySDD class by L.Gaudichet)
3688 //
3689
3690   // Add a dx,dy,dz translation to the initial TGeoCombiTrans
3691   const Double_t *vect = ct->GetTranslation();
3692   Double_t newVect[3] = {vect[0]+dx, vect[1]+dy, vect[2]+dz};
3693   ct->SetTranslation(newVect);
3694 }