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