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