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