]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCv2.cxx
Bug fix in the interpolation
[u/mrichter/AliRoot.git] / TPC / AliTPCv2.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 /* $Id$ */
17
18 //
19 ///////////////////////////////////////////////////////////////////////////////
20 //                                                                           //
21 //  Time Projection Chamber version 2 -- detailed TPC and slow simulation    //
22 //                                                                           //
23 //Begin_Html
24 /*
25 <img src="picts/AliTPCv2Class.gif">
26 */
27 //End_Html
28 //                                                                           //
29 //                                                                           //
30 ///////////////////////////////////////////////////////////////////////////////
31
32 //#include <stdlib.h>
33
34 #include <TLorentzVector.h>
35 #include <TPDGCode.h>
36 #include <TString.h>
37 #include "AliLog.h"
38 #include "AliMathBase.h"
39 #include "AliTrackReference.h"
40 #include "AliTPCParam.h"
41 #include "AliTPCTrackHitsV2.h"
42 #include "AliTPCv2.h"
43 #include "AliGeomManager.h"
44 #include "TGeoVolume.h"
45 #include "TGeoPcon.h"
46 #include "TGeoTube.h"
47 #include "TGeoPgon.h"
48 #include "TGeoTrd1.h"
49 #include "TGeoCompositeShape.h"
50 #include "TGeoPara.h"
51 #include "TGeoPhysicalNode.h"
52 #include "TGeoHalfSpace.h"
53
54 ClassImp(AliTPCv2)
55  
56 //_____________________________________________________________________________
57 AliTPCv2::AliTPCv2(const char *name, const char *title) :
58   AliTPC(name, title),
59   fIdSens(0),
60   fIDrift(0),
61   fSecOld(0) 
62 {
63   //
64   // Standard constructor for Time Projection Chamber version 2
65   //
66
67
68   SetBufferSize(128000);
69
70
71 //   if (fTPCParam)
72 //      fTPCParam->Write(fTPCParam->GetTitle());
73 }
74  
75 //_____________________________________________________________________________
76 void AliTPCv2::CreateGeometry()
77 {
78   //
79   // Create the geometry of Time Projection Chamber version 2
80   //
81   //Begin_Html
82   /*
83     <img src="picts/AliTPC.gif">
84   */
85   //End_Html
86   //Begin_Html
87   /*
88     <img src="picts/AliTPCv2Tree.gif">
89   */
90   //End_Html
91
92   //----------------------------------------------------------
93   // This geometry is written using TGeo class
94   // Firstly the shapes are defined, and only then the volumes
95   // What is recognized by the MC are volumes
96   //----------------------------------------------------------
97   //
98   //  tpc - this will be the mother volume
99   //
100
101   //
102   // here I define a volume TPC
103   // retrive the medium name with "TPC_" as a leading string
104   //
105   TGeoPcon *tpc = new TGeoPcon(0.,360.,20); //20 sections
106   //
107   tpc->DefineSection(0,-291.,77.,278.);
108   tpc->DefineSection(1,-270,77.,278.);
109   //
110   tpc->DefineSection(2,-270.,77.,278.);
111   tpc->DefineSection(3,-259.6,70.,278.);
112   //
113   tpc->DefineSection(4,-259.6,68.1,278.);
114   tpc->DefineSection(5,-253.6,68.1,278.);
115   //
116   tpc->DefineSection(6,-253.6,68.,278.);
117   tpc->DefineSection(7,-74.0,60.8,278.);
118   //
119   tpc->DefineSection(8,-74.0,60.1,278.);
120   tpc->DefineSection(9,-73.3,60.1,278.);
121   //
122   tpc->DefineSection(10,-73.3,56.9,278.); 
123   tpc->DefineSection(11,73.3,56.9,278.);
124   //
125   tpc->DefineSection(12,73.3,60.1,278.);
126   tpc->DefineSection(13,74.0,60.1,278.);
127   //
128   tpc->DefineSection(14,74.0,60.8,278.);
129   tpc->DefineSection(15,253.6,65.5,278.);
130   //
131   tpc->DefineSection(16,253.6,65.6,278.);
132   tpc->DefineSection(17,259.6,65.6,278.);
133   //
134   tpc->DefineSection(18,259.6,70.0,278.);
135   tpc->DefineSection(19,291.,77.,278.);
136   //
137   TGeoMedium *m1 = gGeoManager->GetMedium("TPC_Air");
138   TGeoVolume *v1 = new TGeoVolume("TPC_M",tpc,m1);
139   //
140   // drift volume - sensitive volume, extended beyond the
141   // endcaps, because of the alignment
142   //
143   TGeoPcon *dvol = new TGeoPcon(0.,360.,6);
144   dvol->DefineSection(0,-260.,74.5,264.4);
145   dvol->DefineSection(1,-253.6,74.5,264.4);
146   //
147   dvol->DefineSection(2,-253.6,76.6774,258.);
148   dvol->DefineSection(3,253.6,76.6774,258.); 
149   //
150   dvol->DefineSection(4,253.6,74.5,264.4);
151   dvol->DefineSection(5,260.,74.5,264.4);
152   //
153   TGeoMedium *m5 = gGeoManager->GetMedium("TPC_Ne-CO2-N-2");
154   TGeoVolume *v9 = new TGeoVolume("TPC_Drift",dvol,m5);
155   //
156   v1->AddNode(v9,1);
157   //
158   // outer insulator
159   //
160   TGeoPcon *tpco = new TGeoPcon(0.,360.,6); //insulator
161   //
162   tpco->DefineSection(0,-256.6,264.8,278.);
163   tpco->DefineSection(1,-253.6,264.8,278.);
164   //
165   tpco->DefineSection(2,-253.6,258.,278.);
166   tpco->DefineSection(3,250.6,258.,278.);
167   //
168   tpco->DefineSection(4,250.6,258.,275.5);
169   tpco->DefineSection(5,253.6,258.,275.5);
170   //
171   TGeoMedium *m2 = gGeoManager->GetMedium("TPC_CO2");
172   TGeoVolume *v2 = new TGeoVolume("TPC_OI",tpco,m2);
173   //
174   // outer containment vessel
175   //
176   TGeoPcon *tocv = new TGeoPcon(0.,360.,6);  // containment vessel
177   //
178   tocv->DefineSection(0,-256.6,264.8,278.);
179   tocv->DefineSection(1,-253.6,264.8,278.);
180   //
181   tocv->DefineSection(2,-253.6,274.8124,278.);
182   tocv->DefineSection(3,247.6,274.8124,278.);  
183   //
184   tocv->DefineSection(4,247.6,270.4,278.);
185   tocv->DefineSection(5,250.6,270.4,278.);
186   //
187   TGeoMedium *m3 = gGeoManager->GetMedium("TPC_Al");
188   TGeoVolume *v3 = new TGeoVolume("TPC_OCV",tocv,m3); 
189   //
190   TGeoTube *to1 = new TGeoTube(274.8174,277.995,252.1); //epoxy
191   TGeoTube *to2 = new TGeoTube(274.8274,277.985,252.1); //tedlar
192   TGeoTube *to3 = new TGeoTube(274.8312,277.9812,252.1);//prepreg2
193   TGeoTube *to4 = new TGeoTube(274.9062,277.9062,252.1);//nomex
194   //
195   TGeoMedium *sm1 = gGeoManager->GetMedium("TPC_Epoxy");
196   TGeoMedium *sm2 = gGeoManager->GetMedium("TPC_Tedlar");
197   TGeoMedium *sm3 = gGeoManager->GetMedium("TPC_Prepreg2");
198   TGeoMedium *sm4 = gGeoManager->GetMedium("TPC_Nomex");
199   //
200   TGeoVolume *tov1 = new TGeoVolume("TPC_OCV1",to1,sm1);
201   TGeoVolume *tov2 = new TGeoVolume("TPC_OCV2",to2,sm2);
202   TGeoVolume *tov3 = new TGeoVolume("TPC_OCV3",to3,sm3);
203   TGeoVolume *tov4 = new TGeoVolume("TPC_OCV4",to4,sm4);
204  //-------------------------------------------------------
205   //  Tpc Outer Field Cage
206   //  daughters - composite (sandwich)
207   //-------------------------------------------------------
208
209   TGeoPcon *tofc = new TGeoPcon(0.,360.,6);
210   //
211   tofc->DefineSection(0,-253.6,258.,269.6);
212   tofc->DefineSection(1,-250.6,258.,269.6);
213   //
214   tofc->DefineSection(2,-250.6,258.,260.0676); 
215   tofc->DefineSection(3,250.6,258.,260.0676);
216   //
217   tofc->DefineSection(4,250.6,258.,275.5);
218   tofc->DefineSection(5,253.6,258.,275.5);
219   //
220   TGeoVolume *v4 = new TGeoVolume("TPC_TOFC",tofc,m3); 
221   //sandwich
222   TGeoTube *tf1 = new TGeoTube(258.0,260.0676,252.1); //tedlar
223   TGeoTube *tf2 = new TGeoTube(258.0038,260.0638,252.1); //prepreg3
224   TGeoTube *tf3 = new TGeoTube(258.0338,260.0338,252.1);//nomex
225   //
226   TGeoMedium *sm5 = gGeoManager->GetMedium("TPC_Prepreg3");
227   //
228   TGeoVolume *tf1v = new TGeoVolume("TPC_OFC1",tf1,sm2);
229   TGeoVolume *tf2v = new TGeoVolume("TPC_OFC2",tf2,sm5);
230   TGeoVolume *tf3v = new TGeoVolume("TPC_OFC3",tf3,sm4);
231   //
232   // outer part - positioning
233   //
234   tov1->AddNode(tov2,1); tov2->AddNode(tov3,1); tov3->AddNode(tov4,1);
235   //
236   tf1v->AddNode(tf2v,1); tf2v->AddNode(tf3v,1);
237   //
238   v3->AddNode(tov1,1,new TGeoTranslation(0.,0.,-1.5)); v4->AddNode(tf1v,1);
239   //
240   v2->AddNode(v3,1); v2->AddNode(v4,1); 
241   //
242   v1->AddNode(v2,1);
243   //--------------------------------------------------------------------
244   // Tpc Inner INsulator (CO2) 
245   // the cones, the central drum and the inner f.c. sandwich with a piece
246   // of the flane will be placed in the TPC
247   //--------------------------------------------------------------------
248   TGeoPcon *tpci = new TGeoPcon(0.,360.,4);
249   //
250   tpci->DefineSection(0,-253.6,68.4,76.6774);
251   tpci->DefineSection(1,-74.0,61.2,76.6774);
252   //
253   tpci->DefineSection(2,74.0,61.2,76.6774);  
254   //
255   tpci->DefineSection(3,253.6,65.9,76.6774);
256   //
257   TGeoVolume *v5 = new TGeoVolume("TPC_INI",tpci,m2);
258   //
259   // now the inner field cage - only part of flanges (2 copies)
260   //
261   TGeoTube *tif1 = new TGeoTube(69.9,76.6774,1.5); 
262   TGeoVolume *v6 = new TGeoVolume("TPC_IFC1",tif1,m3);
263   //
264  //---------------------------------------------------------
265   // Tpc Inner Containment vessel - Muon side
266   //---------------------------------------------------------
267   TGeoPcon *tcms = new TGeoPcon(0.,360.,10);
268   //
269   tcms->DefineSection(0,-259.1,68.1,74.2);
270   tcms->DefineSection(1,-253.6,68.1,74.2);
271   //
272   tcms->DefineSection(2,-253.6,68.1,68.4);
273   tcms->DefineSection(3,-74.0,60.9,61.2);
274   //
275   tcms->DefineSection(4,-74.0,60.1,61.2);
276   tcms->DefineSection(5,-73.3,60.1,61.2);
277   //
278   tcms->DefineSection(6,-73.3,56.9,61.2);
279   tcms->DefineSection(7,-73.0,56.9,61.2);
280   //
281   tcms->DefineSection(8,-73.0,56.9,58.8);
282   tcms->DefineSection(9,-71.3,56.9,58.8);
283   //
284   TGeoVolume *v7 = new TGeoVolume("TPC_ICVM",tcms,m3);
285   //-----------------------------------------------
286   // inner containment vessel - shaft side
287   //-----------------------------------------------
288   TGeoPcon *tcss = new TGeoPcon(0.,360.,10);
289   //
290   tcss->DefineSection(0,71.3,56.9,58.8);
291   tcss->DefineSection(1,73.0,56.9,58.8);
292   //
293   tcss->DefineSection(2,73.0,56.9,61.2);
294   tcss->DefineSection(3,73.3,56.9,61.2);
295   //  
296   tcss->DefineSection(4,73.3,60.1,61.2);
297   tcss->DefineSection(5,74.0,60.1,61.2);
298   //
299   tcss->DefineSection(6,74.0,60.9,61.2);
300   tcss->DefineSection(7,253.6,65.6,65.9);
301   //
302   tcss->DefineSection(8,253.6,65.6,74.2);
303   tcss->DefineSection(9,258.1,65.6,74.2);
304   //
305   TGeoVolume *v8 = new TGeoVolume("TPC_ICVS",tcss,m3);
306   //-----------------------------------------------
307   //  Inner field cage
308   //  define 4 parts and make an assembly
309   //-----------------------------------------------
310   // part1 - Al - 2 copies
311   TGeoTube *t1 = new TGeoTube(76.6774,78.845,0.75);
312   TGeoVolume *tv1 = new TGeoVolume("TPC_IFC2",t1,m3);
313   // sandwich - outermost parts - 2 copies
314   //
315   // segment outermost
316   //
317   TGeoTubeSeg *t2 = new TGeoTubeSeg(76.6774,78.845,74.175,350.,109.9); // tedlar 38 microns
318   TGeoTubeSeg *t3 = new TGeoTubeSeg(76.6812,78.8412,74.175,350.,109.9); // prepreg2 500 microns
319   TGeoTubeSeg *t4 = new TGeoTubeSeg(76.7312,78.7912,74.175,350.,109.9); // prepreg3 300 microns
320   TGeoTubeSeg *t5 = new TGeoTubeSeg(76.7612,78.7612,74.175,350.,109.9); // nomex 2 cm
321   TGeoTubeSeg *tepox1 = new TGeoTubeSeg(76.6774,78.845,74.175,109.9,110.);//epoxy
322   TGeoTubeSeg *tpr1 = new TGeoTubeSeg(78.845,78.885,74.175,119.,121.);
323   
324   // volumes for the outer part  
325   TGeoVolume *tv2 = new TGeoVolume("TPC_IFC3",t2,sm2);
326   TGeoVolume *tv3 = new TGeoVolume("TPC_IFC4",t3,sm3);
327   TGeoVolume *tv4 = new TGeoVolume("TPC_IFC5",t4,sm5);
328   TGeoVolume *tv5 = new TGeoVolume("TPC_IFC6",t5,sm4);
329   TGeoVolume *tvep1 = new TGeoVolume("TPC_IFEPOX1",tepox1,sm1); 
330   TGeoVolume *tvpr1 = new TGeoVolume("TPC_PRSTR1",tpr1,sm2); 
331   //
332   // middle parts - 2 copies
333   //
334   // segment middle
335   //
336   TGeoTubeSeg *t6 = new TGeoTubeSeg(76.6774,78.795,5.,350.,109.9); // tedlar 38 microns
337   TGeoTubeSeg *t7 = new TGeoTubeSeg(76.6812,78.7912,5.,350.,109.9); // prepreg2 250 microns
338   TGeoTubeSeg *t8 = new TGeoTubeSeg(76.7062,78.7662,5.,350.,109.9); // prepreg3 300 microns
339   TGeoTubeSeg *t9 = new TGeoTubeSeg(76.7362,78.7362,5.,350.,109.9); // nomex 2 cm
340   TGeoTubeSeg *tepox2 = new TGeoTubeSeg(76.6774,78.795,5.,109.9,110.);//epoxy
341   TGeoTubeSeg *tpr2 = new TGeoTubeSeg(78.795,78.835,5.,119.,121.);
342   // volumes for the middle part
343   TGeoVolume *tv6 = new TGeoVolume("TPC_IFC7",t6,sm2);
344   TGeoVolume *tv7 = new TGeoVolume("TPC_IFC8",t7,sm3);
345   TGeoVolume *tv8 = new TGeoVolume("TPC_IFC9",t8,sm5);
346   TGeoVolume *tv9 = new TGeoVolume("TPC_IFC10",t9,sm4);
347   TGeoVolume *tvep2 = new TGeoVolume("TPC_IFEPOX2",tepox2,sm1);
348   TGeoVolume *tvpr2 = new TGeoVolume("TPC_PRSTR2",tpr2,sm2);
349   // central part - 1 copy
350   // 
351   // segment central part
352   //
353   TGeoTubeSeg *t10 = new TGeoTubeSeg(76.6774,78.785,93.75,350.,109.9); // tedlar 38 microns 
354   TGeoTubeSeg *t11 = new TGeoTubeSeg(76.6812,78.7812,93.75,350.,109.9); // prepreg3 500 microns
355   TGeoTubeSeg *t12 = new TGeoTubeSeg(76.7312,78.7312,93.75,350.,109.9); // nomex 2 cm 
356   TGeoTubeSeg *tepox3 = new TGeoTubeSeg(76.6774,78.785,93.75,109.9,110.);//epoxy
357   TGeoTubeSeg *tpr3 = new TGeoTubeSeg(78.785,78.825,93.75,119.,121.);
358   // volumes for the central part
359   TGeoVolume *tv10 = new TGeoVolume("TPC_IFC11",t10,sm2);
360   TGeoVolume *tv11 = new TGeoVolume("TPC_IFC12",t11,sm5);
361   TGeoVolume *tv12 = new TGeoVolume("TPC_IFC13",t12,sm4);
362   TGeoVolume *tvep3 = new TGeoVolume("TPC_IFEPOX3",tepox3,sm1);
363   TGeoVolume *tvpr3 = new TGeoVolume("TPC_PRSTR3",tpr3,sm2);  
364   //
365   // creating a sandwich for the outer par,t tv2 is the mother
366   //
367   tv2->AddNode(tv3,1); tv3->AddNode(tv4,1); tv4->AddNode(tv5,1);
368   //
369   // creating a sandwich for the middle part, tv6 is the mother
370   //
371   tv6->AddNode(tv7,1); tv7->AddNode(tv8,1); tv8->AddNode(tv9,1);
372   //
373   // creating a sandwich for the central part, tv10 is the mother
374   //
375   tv10->AddNode(tv11,1); tv11->AddNode(tv12,1);
376   //
377   TGeoVolumeAssembly *tv100 = new TGeoVolumeAssembly("TPC_IFC"); // ifc itself - 3 segments
378   //
379   //
380   //
381   TGeoRotation *segrot;
382
383   //
384   // first segment - no rotation
385   //
386   // central
387   tv100->AddNode(tv10,1); //sandwich
388   tv100->AddNode(tvep3,1);//epoxy
389   tv100->AddNode(tvpr3,1);//prepreg strip                                    
390   // middle
391   tv100->AddNode(tv6,1,new TGeoTranslation(0.,0.,-98.75)); //sandwich1
392   tv100->AddNode(tv6,2,new TGeoTranslation(0.,0.,98.75)); // sandwich2
393   tv100->AddNode(tvep2,1,new TGeoTranslation(0.,0.,-98.75)); //epoxy
394   tv100->AddNode(tvep2,2,new TGeoTranslation(0.,0.,98.75)); //epoxy
395   tv100->AddNode(tvpr2,1,new TGeoTranslation(0.,0.,-98.75));//prepreg strip
396   tv100->AddNode(tvpr2,2,new TGeoTranslation(0.,0.,98.75));
397   // outer
398   tv100->AddNode(tv2,1,new TGeoTranslation(0.,0.,-177.925)); //sandwich
399   tv100->AddNode(tv2,2,new TGeoTranslation(0.,0.,177.925));
400   tv100->AddNode(tvep1,1,new TGeoTranslation(0.,0.,-177.925)); //epoxy
401   tv100->AddNode(tvep1,2,new TGeoTranslation(0.,0.,177.925));
402   tv100->AddNode(tvpr1,1,new TGeoTranslation(0.,0.,-177.925));//prepreg strip
403   tv100->AddNode(tvpr1,2,new TGeoTranslation(0.,0.,-177.925));
404   //
405   // second segment - rotation 120 deg.
406   //
407   segrot = new TGeoRotation();
408   segrot->RotateZ(120.);
409   //
410   // central    
411   tv100->AddNode(tv10,2,segrot); //sandwich
412   tv100->AddNode(tvep3,2,segrot);//epoxy
413   tv100->AddNode(tvpr3,2,segrot);//prepreg strip
414   // middle
415   tv100->AddNode(tv6,3,new TGeoCombiTrans(0.,0.,-98.75,segrot)); //sandwich1
416   tv100->AddNode(tv6,4,new TGeoCombiTrans(0.,0.,98.75,segrot)); // sandwich2
417   tv100->AddNode(tvep2,3,new TGeoCombiTrans(0.,0.,-98.75,segrot)); //epoxy
418   tv100->AddNode(tvep2,4,new TGeoCombiTrans(0.,0.,98.75,segrot)); //epoxy
419   tv100->AddNode(tvpr2,3,new TGeoCombiTrans(0.,0.,-98.75,segrot));//prepreg strip
420   tv100->AddNode(tvpr2,4,new TGeoCombiTrans(0.,0.,98.75,segrot));
421   //outer
422   tv100->AddNode(tv2,3,new TGeoCombiTrans(0.,0.,-177.925,segrot));//sandwich
423   tv100->AddNode(tv2,4,new TGeoCombiTrans(0.,0.,177.925,segrot));
424   tv100->AddNode(tvep1,3,new TGeoCombiTrans(0.,0.,-177.925,segrot));//epoxy
425   tv100->AddNode(tvep1,4,new TGeoCombiTrans(0.,0.,177.925,segrot));
426   tv100->AddNode(tvpr1,3,new TGeoCombiTrans(0.,0.,-177.925,segrot));//prepreg strip
427   tv100->AddNode(tvpr1,4,new TGeoCombiTrans(0.,0.,177.925,segrot));
428   //
429   //  third segment - rotation 240 deg.
430   //
431   segrot = new TGeoRotation();
432   segrot->RotateZ(240.);
433   //
434   // central    
435   tv100->AddNode(tv10,3,segrot); //sandwich
436   tv100->AddNode(tvep3,3,segrot);//epoxy
437   tv100->AddNode(tvpr3,3,segrot);//prepreg strip
438   // middle
439   tv100->AddNode(tv6,5,new TGeoCombiTrans(0.,0.,-98.75,segrot)); //sandwich1
440   tv100->AddNode(tv6,6,new TGeoCombiTrans(0.,0.,98.75,segrot)); // sandwich2
441   tv100->AddNode(tvep2,5,new TGeoCombiTrans(0.,0.,-98.75,segrot)); //epoxy
442   tv100->AddNode(tvep2,6,new TGeoCombiTrans(0.,0.,98.75,segrot)); //epoxy
443   tv100->AddNode(tvpr2,5,new TGeoCombiTrans(0.,0.,-98.75,segrot));//prepreg strip
444   tv100->AddNode(tvpr2,6,new TGeoCombiTrans(0.,0.,98.75,segrot));
445   //outer
446   tv100->AddNode(tv2,5,new TGeoCombiTrans(0.,0.,-177.925,segrot));//sandwich
447   tv100->AddNode(tv2,6,new TGeoCombiTrans(0.,0.,177.925,segrot));
448   tv100->AddNode(tvep1,5,new TGeoCombiTrans(0.,0.,-177.925,segrot));//epoxy
449   tv100->AddNode(tvep1,6,new TGeoCombiTrans(0.,0.,177.925,segrot));
450   tv100->AddNode(tvpr1,5,new TGeoCombiTrans(0.,0.,-177.925,segrot));//prepreg strip
451   tv100->AddNode(tvpr1,6,new TGeoCombiTrans(0.,0.,177.925,segrot));
452   // Al parts - rings
453   tv100->AddNode(tv1,1,new TGeoTranslation(0.,0.,-252.85));
454   tv100->AddNode(tv1,2,new TGeoTranslation(0.,0.,252.85));
455   //
456   v5->AddNode(v6,1, new TGeoTranslation(0.,0.,-252.1));
457   v5->AddNode(v6,2, new TGeoTranslation(0.,0.,252.1));
458   v1->AddNode(v5,1); v1->AddNode(v7,1); v1->AddNode(v8,1); 
459   v9->AddNode(tv100,1);
460   //
461   // central drum 
462   //
463   // flange + sandwich
464   //
465   TGeoPcon *cfl = new TGeoPcon(0.,360.,6);
466   cfl->DefineSection(0,-71.1,59.7,61.2);
467   cfl->DefineSection(1,-68.6,59.7,61.2);
468   //
469   cfl->DefineSection(2,-68.6,60.6124,61.2);
470   cfl->DefineSection(3,68.6,60.6124,61.2); 
471   //
472   cfl->DefineSection(4,68.6,59.7,61.2);
473   cfl->DefineSection(5,71.1,59.7,61.2);  
474   //
475   TGeoVolume *cflv = new TGeoVolume("TPC_CDR",cfl,m3);
476   // sandwich
477   TGeoTube *cd1 = new TGeoTube(60.6224,61.19,71.1);
478   TGeoTube *cd2 = new TGeoTube(60.6262,61.1862,71.1);
479   TGeoTube *cd3 = new TGeoTube(60.6462,61.1662,71.1);  
480   TGeoTube *cd4 = new TGeoTube(60.6562,61.1562,71.1);  
481   //
482   TGeoMedium *sm6 = gGeoManager->GetMedium("TPC_Prepreg1");
483   TGeoMedium *sm8 = gGeoManager->GetMedium("TPC_Epoxyfm");
484   TGeoVolume *cd1v = new TGeoVolume("TPC_CDR1",cd1,sm2); //tedlar
485   TGeoVolume *cd2v = new TGeoVolume("TPC_CDR2",cd2,sm6);// prepreg1
486   TGeoVolume *cd3v = new TGeoVolume("TPC_CDR3",cd3,sm8); //epoxy film
487   TGeoVolume *cd4v = new TGeoVolume("TPC_CDR4",cd4,sm4); //nomex
488
489   //
490   // seals for central drum 2 copies
491   //
492   TGeoTube *cs = new TGeoTube(56.9,61.2,0.1);
493   TGeoMedium *sm7 = gGeoManager->GetMedium("TPC_Mylar");
494   TGeoVolume *csv = new TGeoVolume("TPC_CDRS",cs,sm7);
495   v1->AddNode(csv,1,new TGeoTranslation(0.,0.,-71.2));
496   v1->AddNode(csv,2,new TGeoTranslation(0.,0.,71.2));
497   //
498   // seal collars 
499   TGeoPcon *se = new TGeoPcon(0.,360.,6);
500   se->DefineSection(0,-72.8,59.7,61.2);
501   se->DefineSection(1,-72.3,59.7,61.2);
502   //
503   se->DefineSection(2,-72.3,58.85,61.2);
504   se->DefineSection(3,-71.6,58.85,61.2); 
505   //
506   se->DefineSection(4,-71.6,59.7,61.2);
507   se->DefineSection(5,-71.3,59.7,61.2);  
508   //
509   TGeoVolume *sev = new TGeoVolume("TPC_CDCE",se,m3);
510   //
511   TGeoTube *si = new TGeoTube(56.9,58.8,1.); 
512   TGeoVolume *siv = new TGeoVolume("TPC_CDCI",si,m3);
513   //
514   // define reflection matrix 
515   //
516   TGeoRotation *ref = new TGeoRotation("ref",90.,0.,90.,90.,180.,0.);
517   //
518   cd1v->AddNode(cd2v,1); cd2v->AddNode(cd3v,1); cd3v->AddNode(cd4v,1); cflv->AddNode(cd1v,1); 
519   //
520   v1->AddNode(siv,1,new TGeoTranslation(0.,0.,-69.9));
521   v1->AddNode(siv,2,new TGeoTranslation(0.,0.,69.9));
522   v1->AddNode(sev,1); v1->AddNode(sev,2,ref); v1->AddNode(cflv,1);
523   //
524   // central membrane - 2 rings and a mylar membrane - assembly
525   //
526   TGeoTube *ih = new TGeoTube(80.1,84.1,0.2);
527   TGeoTube *oh = new TGeoTube(250.25,256.75,0.2);
528   TGeoTube *mem = new TGeoTube(84.1,250.25,0.01);
529   TGeoVolume *ihv = new TGeoVolume("TPC_IHVH",ih,m3);
530   TGeoVolume *ohv = new TGeoVolume("TPC_OHVH",oh,m3);
531   TGeoVolume *memv = new TGeoVolume("TPC_HV",mem,sm7);
532   //
533   TGeoVolumeAssembly *cm = new TGeoVolumeAssembly("TPC_HVMEM");
534   cm->AddNode(ihv,1);
535   cm->AddNode(ohv,1);
536   cm->AddNode(memv,1);
537   v9->AddNode(cm,1);
538   //
539   // end caps - they are make as an assembly of single segments
540   // containing both readout chambers
541   //
542   Double_t openingAngle = 10.*TMath::DegToRad();
543   Double_t thick=1.5; // rib
544   Double_t shift = thick/TMath::Sin(openingAngle);
545   //
546   Double_t lowEdge = 86.3; // hole in the wheel
547   Double_t upEdge = 240.4; // hole in the wheel
548   //
549   new TGeoTubeSeg("sec",74.5,264.4,3.,0.,20.);
550   //
551   TGeoPgon *hole = new TGeoPgon("hole",0.,20.,1,4);
552   //
553   hole->DefineSection(0,-3.5,lowEdge-shift,upEdge-shift);
554   hole->DefineSection(1,-1.5,lowEdge-shift,upEdge-shift);
555   //
556   hole->DefineSection(2,-1.5,lowEdge-shift,upEdge+3.-shift);
557   hole->DefineSection(3,3.5,lowEdge-shift,upEdge+3.-shift);
558   //
559   Double_t ys = shift*TMath::Sin(openingAngle); 
560   Double_t xs = shift*TMath::Cos(openingAngle);
561   TGeoTranslation *tr = new TGeoTranslation("tr",xs,ys,0.);  
562   tr->RegisterYourself();
563   TGeoCompositeShape *chamber = new TGeoCompositeShape("sec-hole:tr");
564   TGeoVolume *sv = new TGeoVolume("TPC_WSEG",chamber,m3);
565   TGeoPgon *bar = new TGeoPgon("bar",0.,20.,1,2);
566   bar->DefineSection(0,-3.,131.5-shift,136.5-shift);
567   bar->DefineSection(1,1.5,131.5-shift,136.5-shift);
568   TGeoVolume *barv = new TGeoVolume("TPC_WBAR",bar,m3);
569   TGeoVolumeAssembly *ch = new TGeoVolumeAssembly("TPC_WCH");//empty segment
570   //
571   ch->AddNode(sv,1); ch->AddNode(barv,1,tr);
572   //
573   // readout chambers
574   //
575   // IROC first
576   //
577    TGeoTrd1 *ibody = new TGeoTrd1(13.8742,21.3328,4.29,21.15);
578    TGeoVolume *ibdv = new TGeoVolume("TPC_IROCB",ibody,m3);
579   // empty space
580    TGeoTrd1 *emp = new TGeoTrd1(12.3742,19.8328,3.99,19.65);
581    TGeoVolume *empv = new TGeoVolume("TPC_IROCE",emp,m1);
582    ibdv->AddNode(empv,1,new TGeoTranslation(0.,-0.3,0.));
583    //bars
584    Double_t tga = (19.8328-12.3742)/39.3;
585    Double_t xmin,xmax;
586    xmin = 9.55*tga+12.3742;
587    xmax = 9.95*tga+12.3742;
588    TGeoTrd1 *ib1 = new TGeoTrd1(xmin,xmax,3.29,0.2);
589    TGeoVolume *ib1v = new TGeoVolume("TPC_IRB1",ib1,m3);
590    empv->AddNode(ib1v,1,new TGeoTranslation("tt1",0.,0.7,-9.9));
591    xmin=19.4*tga+12.3742;
592    xmax=19.9*tga+12.3742;
593    TGeoTrd1 *ib2 = new TGeoTrd1(xmin,xmax,3.29,0.25);
594    TGeoVolume *ib2v = new TGeoVolume("TPC_TRB2",ib2,m3);
595    empv->AddNode(ib2v,1,new TGeoTranslation(0.,0.7,0.));
596    xmin=29.35*tga+12.3742;
597    xmax=29.75*tga+12.3742;
598    TGeoTrd1 *ib3 = new TGeoTrd1(xmin,xmax,3.29,0.2); 
599    TGeoVolume *ib3v = new TGeoVolume("TPC_IRB3",ib3,m3);    
600    empv->AddNode(ib3v,1,new TGeoTranslation(0.,0.7,9.9));
601    //
602    // holes for connectors
603    //
604    TGeoBBox *conn = new TGeoBBox(0.4,0.3,4.675); // identical for iroc and oroc
605    TGeoVolume *connv = new TGeoVolume("TPC_RCCON",conn,m1);
606    TString fileName(gSystem->Getenv("ALICE_ROOT"));
607    fileName += "/TPC/conn_iroc.dat";
608    ifstream in;
609    in.open(fileName.Data(), ios_base::in); // asci file
610    TGeoRotation *rrr[86];
611    for(Int_t i =0;i<86;i++){
612       Double_t y = 3.99;
613       Double_t x,z,ang;
614       in>>x>>z>>ang;
615       z-=26.5;
616       rrr[i]= new TGeoRotation();
617       rrr[i]->RotateY(ang);
618       ibdv->AddNode(connv,i+1,new TGeoCombiTrans(x,y,z,rrr[i]));
619    }
620    in.close();
621    // "cap"
622    new TGeoTrd1("icap",14.5974,23.3521,1.19,24.825);
623    // "hole"
624    new TGeoTrd1("ihole",13.8742,21.3328,1.2,21.15);
625    TGeoTranslation *tr1 = new TGeoTranslation("tr1",0.,0.,1.725);  
626    tr1->RegisterYourself();
627    TGeoCompositeShape *ic = new TGeoCompositeShape("icap-ihole:tr1");
628    TGeoVolume *icv = new TGeoVolume("TPC_IRCAP",ic,m3);
629    //
630    // pad plane and wire fixations
631    //
632    TGeoTrd1 *pp = new TGeoTrd1(14.5974,23.3521,0.3,24.825); //pad+iso
633    TGeoMedium *m4 = gGeoManager->GetMedium("TPC_G10");
634    TGeoVolume *ppv = new TGeoVolume("TPC_IRPP",pp,m4);
635    TGeoPara *f1 = new TGeoPara(.6,.5,24.825,0.,-10.,0.);
636    TGeoVolume *f1v = new TGeoVolume("TPC_IRF1",f1,m4);
637    TGeoPara *f2 = new TGeoPara(.6,.5,24.825,0.,10.,0.);
638    TGeoVolume *f2v = new TGeoVolume("TPC_IRF2",f2,m4);
639    //
640    TGeoVolumeAssembly *iroc = new TGeoVolumeAssembly("TPC_IROC");
641    //
642    iroc->AddNode(ibdv,1);
643    iroc->AddNode(icv,1,new TGeoTranslation(0.,3.1,-1.725));
644    iroc->AddNode(ppv,1,new TGeoTranslation(0.,4.59,-1.725));
645    tga =(23.3521-14.5974)/49.65; 
646    Double_t xx = 24.825*tga+14.5974-0.6;
647    iroc->AddNode(f1v,1,new TGeoTranslation(-xx,5.39,-1.725));
648    iroc->AddNode(f2v,1,new TGeoTranslation(xx,5.39,-1.725));
649    //
650    // OROC
651    //
652    TGeoTrd1 *obody = new TGeoTrd1(22.2938,40.5084,4.19,51.65);
653    TGeoVolume *obdv = new TGeoVolume("TPC_OROCB",obody,m3);
654    TGeoTrd1 *oemp = new TGeoTrd1(20.2938,38.5084,3.89,49.65);
655    TGeoVolume *oempv = new TGeoVolume("TPC_OROCE",oemp,m1);
656    obdv->AddNode(oempv,1,new TGeoTranslation(0.,-0.3,0.));
657    //horizontal bars
658    tga=(38.5084-20.2938)/99.3;
659    xmin=tga*10.2+20.2938;
660    xmax=tga*10.6+20.2938;
661    TGeoTrd1 *ob1 = new TGeoTrd1(xmin,xmax,2.915,0.2);
662    TGeoVolume *ob1v = new TGeoVolume("TPC_ORB1",ob1,m3);
663    //
664    xmin=22.55*tga+20.2938;
665    xmax=24.15*tga+20.2938;
666    TGeoTrd1 *ob2 = new TGeoTrd1(xmin,xmax,2.915,0.8);
667    TGeoVolume *ob2v = new TGeoVolume("TPC_ORB2",ob2,m3);
668    //
669    xmin=36.1*tga+20.2938;
670    xmax=36.5*tga+20.2938;
671    TGeoTrd1 *ob3 = new TGeoTrd1(xmin,xmax,2.915,0.2);
672    TGeoVolume *ob3v = new TGeoVolume("TPC_ORB3",ob3,m3);
673    //
674    xmin=49.0*tga+20.2938;
675    xmax=50.6*tga+20.2938;   
676    TGeoTrd1 *ob4 = new TGeoTrd1(xmin,xmax,2.915,0.8);
677    TGeoVolume *ob4v = new TGeoVolume("TPC_ORB4",ob4,m3);
678    //
679    xmin=63.6*tga+20.2938;
680    xmax=64.0*tga+20.2938;
681    TGeoTrd1 *ob5 = new TGeoTrd1(xmin,xmax,2.915,0.2);
682    TGeoVolume *ob5v = new TGeoVolume("TPC_ORB5",ob5,m3);
683    //
684    xmin=75.5*tga+20.2938;
685    xmax=77.15*tga+20.2938;
686    TGeoTrd1 *ob6 = new TGeoTrd1(xmin,xmax,2.915,0.8);
687    TGeoVolume *ob6v = new TGeoVolume("TPC_ORB6",ob6,m3);
688    //
689    xmin=88.7*tga+20.2938;
690    xmax=89.1*tga+20.2938;
691    TGeoTrd1 *ob7 = new TGeoTrd1(xmin,xmax,2.915,0.2);
692    TGeoVolume *ob7v = new TGeoVolume("TPC_ORB7",ob7,m3);
693    //
694    oempv->AddNode(ob1v,1,new TGeoTranslation(0.,0.975,-39.25));
695    oempv->AddNode(ob2v,1,new TGeoTranslation(0.,0.975,-26.3));
696    oempv->AddNode(ob3v,1,new TGeoTranslation(0.,0.975,-13.35));
697    oempv->AddNode(ob4v,1,new TGeoTranslation(0.,0.975,0.15));
698    oempv->AddNode(ob5v,1,new TGeoTranslation(0.,0.975,14.15));
699    oempv->AddNode(ob6v,1,new TGeoTranslation(0.,0.975,26.7));
700    oempv->AddNode(ob7v,1,new TGeoTranslation(0.,0.975,39.25));
701    // vertical bars
702    TGeoBBox *ob8 = new TGeoBBox(0.8,2.915,5.1); 
703    TGeoBBox *ob9 = new TGeoBBox(0.8,2.915,5.975);
704    TGeoBBox *ob10 = new TGeoBBox(0.8,2.915,5.775);
705    TGeoBBox *ob11 = new TGeoBBox(0.8,2.915,6.25);
706    TGeoBBox *ob12 = new TGeoBBox(0.8,2.915,6.5);
707    //
708    TGeoVolume *ob8v = new TGeoVolume("TPC_ORB8",ob8,m3);
709    TGeoVolume *ob9v = new TGeoVolume("TPC_ORB9",ob9,m3);
710    TGeoVolume *ob10v = new TGeoVolume("TPC_ORB10",ob10,m3);
711    TGeoVolume *ob11v = new TGeoVolume("TPC_ORB11",ob11,m3);
712    TGeoVolume *ob12v = new TGeoVolume("TPC_ORB12",ob12,m3);
713    //
714    oempv->AddNode(ob8v,1,new TGeoTranslation(0.,0.975,-44.55));
715    oempv->AddNode(ob8v,2,new TGeoTranslation(0.,0.975,44.55));
716    oempv->AddNode(ob9v,1,new TGeoTranslation(0.,0.975,-33.075));
717    oempv->AddNode(ob9v,2,new TGeoTranslation(0.,0.975,-19.525));
718    oempv->AddNode(ob10v,1,new TGeoTranslation(0.,0.975,20.125));
719    oempv->AddNode(ob10v,2,new TGeoTranslation(0.,0.975,33.275));
720    oempv->AddNode(ob11v,1,new TGeoTranslation(0.,0.975,-6.9));
721    oempv->AddNode(ob12v,1,new TGeoTranslation(0.,0.975,7.45));
722    //
723    // holes for connectors
724    //
725    fileName = gSystem->Getenv("ALICE_ROOT");
726    fileName += "/TPC/conn_oroc.dat";
727    in.open(fileName.Data(), ios_base::in); // asci file
728    TGeoRotation *rr[78];
729    for(Int_t i =0;i<78;i++){
730       Double_t y =3.89;
731       Double_t x,z,ang;
732       Double_t x1,z1,x2,z2;
733       in>>x>>z>>ang;        
734       Double_t xr = 4.7*TMath::Sin(ang*TMath::DegToRad());
735       Double_t zr = 4.7*TMath::Cos(ang*TMath::DegToRad());
736       //
737       x1=xr+x; x2=-xr+x; z1=zr+z; z2 = -zr+z;      
738       //
739       rr[i]= new TGeoRotation();
740       rr[i]->RotateY(ang); 
741       z1-=54.95;
742       z2-=54.95;
743       //
744       obdv->AddNode(connv,i+1,new TGeoCombiTrans(x1,y,z1,rr[i]));
745       obdv->AddNode(connv,i+79,new TGeoCombiTrans(x2,y,z2,rr[i]));
746    }
747    in.close();
748    // cap
749    new TGeoTrd1("ocap",23.3874,43.5239,1.09,57.1);
750    new TGeoTrd1("ohole",22.2938,40.5084,1.09,51.65);
751    TGeoTranslation *tr5 = new TGeoTranslation("tr5",0.,0.,-2.15);
752    tr5->RegisterYourself();
753    TGeoCompositeShape *oc = new TGeoCompositeShape("ocap-ohole:tr5");
754    TGeoVolume *ocv = new TGeoVolume("TPC_ORCAP",oc,m3);
755    //
756    // pad plane and wire fixations
757    //
758    TGeoTrd1 *opp = new TGeoTrd1(23.3874,43.5239,0.3,57.1);
759    TGeoVolume *oppv = new TGeoVolume("TPC_ORPP",opp,m4);
760    //
761    tga=(43.5239-23.3874)/114.2;
762    TGeoPara *f3 = new TGeoPara(.7,.6,57.1,0.,-10.,0.);
763    TGeoPara *f4 = new TGeoPara(.7,.6,57.1,0.,10.,0.);  
764    xx = 57.1*tga+23.3874-0.7;
765    TGeoVolume *f3v = new TGeoVolume("TPC_ORF1",f3,m4);
766    TGeoVolume *f4v = new TGeoVolume("TPC_ORF2",f4,m4);
767    //
768    TGeoVolumeAssembly *oroc = new TGeoVolumeAssembly("TPC_OROC");
769    //
770    oroc->AddNode(obdv,1);
771    oroc->AddNode(ocv,1,new TGeoTranslation(0.,3.1,2.15));
772    oroc->AddNode(oppv,1,new TGeoTranslation(0.,4.49,2.15));
773    oroc->AddNode(f3v,1,new TGeoTranslation(-xx,5.39,2.15));
774    oroc->AddNode(f4v,1,new TGeoTranslation(xx,5.39,2.15));
775    // 
776    // now iroc and oroc are placed into a sector...
777    //
778    TGeoVolumeAssembly *secta = new TGeoVolumeAssembly("TPC_SECT"); // a-side
779    TGeoVolumeAssembly *sectc = new TGeoVolumeAssembly("TPC_SECT"); // c-side
780    TGeoRotation rot1("rot1",90.,90.,0.);
781    TGeoRotation rot2("rot2");
782    rot2.RotateY(10.);
783    TGeoRotation *rot = new TGeoRotation("rot");
784    *rot=rot1*rot2;
785    //
786    Double_t x0,y0;
787    x0=110.2*TMath::Cos(openingAngle);
788    y0=110.2*TMath::Sin(openingAngle);
789    TGeoCombiTrans *combi1a = new TGeoCombiTrans("combi1",x0,y0,1.09+0.195,rot); //a-side 
790    TGeoCombiTrans *combi1c = new TGeoCombiTrans("combi1",x0,y0,1.09+0.222,rot); //c-side
791    x0=188.45*TMath::Cos(openingAngle);
792    y0=188.45*TMath::Sin(openingAngle);
793    TGeoCombiTrans *combi2a = new TGeoCombiTrans("combi2",x0,y0,0.99+0.195,rot); //a-side
794    TGeoCombiTrans *combi2c = new TGeoCombiTrans("combi2",x0,y0,0.99+0.222,rot); //c-side
795    //
796    //
797    // A-side
798    //
799    secta->AddNode(ch,1);
800    secta->AddNode(iroc,1,combi1a);
801    secta->AddNode(oroc,1,combi2a);
802    //
803    // C-side
804    //
805    sectc->AddNode(ch,1);
806    sectc->AddNode(iroc,1,combi1c);
807    sectc->AddNode(oroc,1,combi2c);
808    //
809    // now I try to make  wheels...
810    //
811    TGeoVolumeAssembly *wheela = new TGeoVolumeAssembly("TPC_ENDCAP");
812    TGeoVolumeAssembly *wheelc = new TGeoVolumeAssembly("TPC_ENDCAP");
813    //
814    TGeoRotation *rwh[18]; 
815    for(Int_t i =0;i<18;i++){
816      Double_t phi = (20.*i);
817      rwh[i]=new TGeoRotation();
818      rwh[i]->RotateZ(phi);
819      wheela->AddNode(secta,i+1,rwh[i]);
820      wheelc->AddNode(sectc,i+1,rwh[i]); 
821     
822    }
823    // wheels in the drift volume!   
824
825    TGeoCombiTrans *combi3 = new TGeoCombiTrans("combi3",0.,0.,256.6,ref);
826    v9->AddNode(wheela,1,combi3);
827    v9->AddNode(wheelc,2,new TGeoTranslation(0.,0.,-256.6));
828    //_____________________________________________________________
829    // service support wheel
830    //_____________________________________________________________
831   TGeoPgon *sw = new TGeoPgon(0.,20.,1,2);
832   sw->DefineSection(0,-4.,80.5,251.75);
833   sw->DefineSection(1,4.,80.5,251.75); 
834   TGeoVolume *swv = new TGeoVolume("TPC_SWSEG",sw,m3); //Al
835   //
836   thick=1.;
837   shift = thick/TMath::Sin(openingAngle);
838   TGeoPgon *sh = new TGeoPgon(0.,20.,1,2);
839   sh->DefineSection(0,-4.,81.5-shift,250.75-shift);
840   sh->DefineSection(1,4.,81.5-shift,250.75-shift);
841   TGeoVolume *shv = new TGeoVolume("TPC_SWS1",sh,m1); //Air
842   //
843   TGeoMedium *m9 =  gGeoManager->GetMedium("TPC_Si"); 
844   TGeoPgon *el = new TGeoPgon(0.,20.,1,2);
845   el->DefineSection(0,-1.872,81.5-shift,250.75-shift);
846   el->DefineSection(1,1.872,81.5-shift,250.75-shift);
847   TGeoVolume *elv = new TGeoVolume("TPC_ELEC",el,m9); //Si 
848   //
849   shv->AddNode(elv,1);
850   //
851   //
852   ys = shift*TMath::Sin(openingAngle);
853   xs = shift*TMath::Cos(openingAngle);
854   swv->AddNode(shv,1,new TGeoTranslation(xs,ys,0.));
855   // cover
856   TGeoPgon *co = new TGeoPgon(0.,20.,1,2);
857   co->DefineSection(0,-0.5,77.,255.25);
858   co->DefineSection(1,0.5,77.,255.25);
859   TGeoVolume *cov = new TGeoVolume("TPC_SWC1",co,m3);//Al
860   // hole in a cover
861   TGeoPgon *coh = new TGeoPgon(0.,20.,1,2);
862   shift=4./TMath::Sin(openingAngle);
863   coh->DefineSection(0,-0.5,85.-shift,247.25-shift);
864   coh->DefineSection(1,0.5,85.-shift,247.25-shift);  
865   //
866   TGeoVolume *cohv = new TGeoVolume("TPC_SWC2",coh,m1);
867   //
868   ys = shift*TMath::Sin(openingAngle);
869   xs = shift*TMath::Cos(openingAngle);  
870   cov->AddNode(cohv,1,new TGeoTranslation(xs,ys,0.));
871   //
872   // Sector as an Assembly
873   //
874   TGeoVolumeAssembly *swhs = new TGeoVolumeAssembly("TPC_SSWSEC");
875   swhs->AddNode(swv,1);
876   swhs->AddNode(cov,1,new TGeoTranslation(0.,0.,-4.5));
877   swhs->AddNode(cov,2,new TGeoTranslation(0.,0.,4.5));
878   //
879   // SSW as an Assembly of sectors
880   //
881   TGeoRotation *rsw[18];
882   TGeoVolumeAssembly *swheel = new TGeoVolumeAssembly("TPC_SSWHEEL");
883    for(Int_t i =0;i<18;i++){
884      Double_t phi = (20.*i);
885      rsw[i] = new TGeoRotation();
886      rsw[i]->RotateZ(phi);
887      swheel->AddNode(swhs,i+1,rsw[i]);   
888    }
889    v1->AddNode(swheel,1,new TGeoTranslation(0.,0.,-284.6));
890    v1->AddNode(swheel,2,new TGeoTranslation(0.,0.,284.6));
891
892    // sensitive strips - strip "0" is always set
893    // conditional
894    Int_t totrows;
895    totrows = fTPCParam->GetNRowLow() + fTPCParam->GetNRowUp();
896    Double_t *upar;
897    upar=NULL;
898    gGeoManager->Volume("TPC_Strip","PGON",m5->GetId(),upar);
899    upar=new Double_t [10];
900    upar[0]=0.;
901    upar[1]=360.;
902    upar[2]=18.;
903    upar[3]=2.;
904    //
905    upar[4]=-124.8;
906    upar[7]=124.8;
907
908    Double_t rlow=fTPCParam->GetPadRowRadiiLow(0);
909
910    upar[5]=rlow;
911    upar[6]=rlow+.01;
912    upar[8]=upar[5];
913    upar[9]=upar[6];
914    //
915    gGeoManager->Node("TPC_Strip",1,"TPC_Drift",0.,0.,124.82,0,kTRUE,upar,10);
916    gGeoManager->Node("TPC_Strip",totrows+1,
917                      "TPC_Drift",0.,0.,-124.82,0,kTRUE,upar,10);
918    //
919    // now, strips optionally
920    //
921    if(fSens){
922      //lower sectors
923      for(Int_t i=2;i<fTPCParam->GetNRowLow()+1;i++){
924        rlow=fTPCParam->GetPadRowRadiiLow(i-1);
925        upar[5]=rlow;
926        upar[6]=rlow+.01;
927        upar[8]=upar[5];
928        upar[9]=upar[6];
929        gGeoManager->Node("TPC_Strip",i,
930                          "TPC_Drift",0.,0.,124.82,0,kTRUE,upar,10);
931        gGeoManager->Node("TPC_Strip",totrows+i,
932                          "TPC_Drift",0.,0.,-124.82,0,kTRUE,upar,10);       
933      }
934      //upper sectors
935      for(Int_t i=1;i<fTPCParam->GetNRowUp()+1;i++){
936        rlow=fTPCParam->GetPadRowRadiiUp(i-1); 
937        upar[5]=rlow;
938        upar[6]=rlow+.01;
939        upar[8]=upar[5];
940        upar[9]=upar[6];
941        gGeoManager->Node("TPC_Strip",i+fTPCParam->GetNRowLow(),
942                          "TPC_Drift",0.,0.,124.82,0,kTRUE,upar,10); 
943        gGeoManager->Node("TPC_Strip",totrows+i+fTPCParam->GetNRowLow(),
944                          "TPC_Drift",0.,0.,-124.82,0,kTRUE,upar,10); 
945      }
946    }//strips
947   //----------------------------------------------------------
948   // TPC Support Rods - MAKROLON
949   //----------------------------------------------------------
950   TGeoMedium *m6=gGeoManager->GetMedium("TPC_Makrolon");
951   TGeoMedium *m7=gGeoManager->GetMedium("TPC_Cu");
952   TGeoMedium *m10 =  gGeoManager->GetMedium("TPC_Alumina");
953   TGeoMedium *m11 =  gGeoManager->GetMedium("TPC_Peek");
954   TGeoMedium *m12 =  gGeoManager->GetMedium("TPC_Water");
955   TGeoMedium *m13 = gGeoManager->GetMedium("TPC_Brass");
956   // 
957   // tpc rod is an assembly of 10 long parts and 2 short parts
958   // connected with alu rings and plagged on both sides.
959   //
960   //
961 // tpc rod long
962 //
963   TGeoPcon *rod = new TGeoPcon("rod",0.,360.,6);
964  rod->DefineSection(0,-10.43,1.92,2.08);
965  rod->DefineSection(1,-9.75,1.92,2.08);
966
967  rod->DefineSection(2,-9.75,1.8,2.2);
968  rod->DefineSection(3,9.75,1.8,2.2);
969
970  rod->DefineSection(4,9.75,1.92,2.08);
971  rod->DefineSection(5,10.43,1.92,2.08);
972  //
973  TGeoVolume *mrodl = new TGeoVolume("TPC_mrodl",rod,m6);
974  //
975  // tpc rod short 
976  //
977  TGeoPcon *rod1 = new TGeoPcon("rod1",0.,360.,6);
978  rod1->DefineSection(0,-8.93,1.92,2.08);
979  rod1->DefineSection(1,-8.25,1.92,2.08);
980
981  rod1->DefineSection(2,-8.25,1.8,2.2);
982  rod1->DefineSection(3,8.25,1.8,2.2);
983
984  rod1->DefineSection(4,8.25,1.92,2.08);
985  rod1->DefineSection(5,8.93,1.92,2.08);
986  //
987  TGeoVolume *mrods = new TGeoVolume("TPC_mrods",rod1,m6);
988  //
989  // below is for the resistor rod
990  //
991  // hole for the brass connectors
992  //
993
994  new TGeoTube("hhole",0.,0.3,0.3);
995  //
996  //transformations for holes - initialy they
997  // are placed at x=0 and negative y
998  //
999   TGeoRotation *rhole = new TGeoRotation();
1000   rhole->RotateX(90.);
1001   TGeoCombiTrans *transf[13];
1002   Char_t name[30];
1003   for(Int_t i=0;i<13;i++){
1004     sprintf(name,"transf%d",i);
1005     transf[i]= new TGeoCombiTrans(name,0.,-2.,-9.+i*1.5,rhole);
1006     transf[i]->RegisterYourself();
1007   }
1008   // union expression for holes
1009   TString operl("hhole:transf0");
1010   for (Int_t i=1;i<13;i++){
1011     sprintf(name,"+hhole:transf%d",i);
1012     operl.Append(name);   
1013   }
1014   //
1015  TString opers("hhole:transf1");
1016   for (Int_t i=2;i<12;i++){
1017     sprintf(name,"+hhole:transf%d",i);
1018     opers.Append(name);   
1019   }
1020   //union of holes
1021   new TGeoCompositeShape("hlv",operl.Data());
1022   new TGeoCompositeShape("hsv",opers.Data());
1023   //
1024   TGeoCompositeShape *rodl = new TGeoCompositeShape("rodl","rod-hlv");
1025   TGeoCompositeShape *rods = new TGeoCompositeShape("rods","rod1-hsv");
1026  //rods - volumes - makrolon rods with holes
1027   TGeoVolume *rodlv = new TGeoVolume("TPC_rodl",rodl,m6);
1028   TGeoVolume *rodsv = new TGeoVolume("TPC_rods",rods,m6);
1029   //brass connectors
1030  //connectors
1031   TGeoTube *bcon = new TGeoTube(0.,0.3,0.3);//connectors
1032   TGeoVolume *bconv = new TGeoVolume("TPC_bcon",bcon,m13);
1033  //
1034  // hooks holding strips
1035  //
1036  new TGeoBBox("hk1",0.625,0.015,0.75);
1037  new TGeoBBox("hk2",0.625,0.015,0.15);
1038  TGeoTranslation *tr21 = new TGeoTranslation("tr21",0.,-0.03,-0.6);
1039  TGeoTranslation *tr12 = new TGeoTranslation("tr12",0.,-0.03,0.6);
1040  tr21->RegisterYourself();
1041  tr12->RegisterYourself();
1042  
1043  TGeoCompositeShape *hook = new TGeoCompositeShape("hook","hk1+hk2:tr21+hk2:tr12");
1044  TGeoVolume *hookv = new TGeoVolume("TPC_hook",hook,m13);
1045  //
1046  // assembly of the short rod with connectors and hooks
1047  //
1048  //
1049  // short rod
1050  //
1051   TGeoVolumeAssembly *spart = new TGeoVolumeAssembly("TPC_spart");
1052   //
1053   spart->AddNode( rodsv,1);
1054   for(Int_t i=1;i<12;i++){
1055   spart->AddNode(bconv,i,transf[i]);
1056   }
1057   for(Int_t i =0;i<11;i++){
1058     spart->AddNode(hookv,i+1,new TGeoTranslation(0.,-2.315,-7.5+i*1.5));
1059   } 
1060  //
1061  // long rod
1062  //
1063   TGeoVolumeAssembly *lpart = new TGeoVolumeAssembly("TPC_lpart");
1064   //
1065   lpart->AddNode( rodlv,1);
1066   for(Int_t i=0;i<13;i++){
1067   lpart->AddNode(bconv,i+12,transf[i]);
1068   }
1069   for(Int_t i =0;i<13;i++){
1070     lpart->AddNode(hookv,i+12,new TGeoTranslation(0.,-2.315,-9.+i*1.5));
1071   }   
1072   //
1073   // alu ring
1074   //
1075   new TGeoTube("ring1",2.1075,2.235,0.53);
1076   new TGeoTube("ring2",1.7925,1.89,0.43);
1077   new TGeoTube("ring3",1.89,2.1075,0.05);
1078   TGeoCompositeShape *ring = new TGeoCompositeShape("ring","ring1+ring2+ring3");
1079   TGeoVolume *ringv = new TGeoVolume("TPC_ring",ring,m3);
1080   //
1081   // rod assembly
1082   //
1083   TGeoVolumeAssembly *tpcrrod = new TGeoVolumeAssembly("TPC_rrod");//rrod
1084   TGeoVolumeAssembly *tpcmrod = new TGeoVolumeAssembly("TPC_mrod");//makrolon rod  
1085   //long pieces
1086   for(Int_t i=0;i<11;i++){
1087     tpcrrod->AddNode(ringv,i+1,new TGeoTranslation(0.,0.,-105.+i*21));
1088     tpcmrod->AddNode(ringv,i+12,new TGeoTranslation(0.,0.,-105.+i*21));
1089   }
1090   for(Int_t i=0;i<10;i++){
1091     tpcrrod->AddNode(lpart,i+1,new TGeoTranslation(0.,0.,-94.5+i*21));
1092     tpcmrod->AddNode(mrodl,i+1,new TGeoTranslation(0.,0.,-94.5+i*21));      
1093   }
1094   //
1095   // short pieces
1096   //
1097   tpcrrod->AddNode(spart,1,new TGeoTranslation(0.,0.,-114.));
1098   tpcrrod->AddNode(spart,2,new TGeoTranslation(0.,0.,114.)); 
1099   tpcrrod->AddNode(ringv,23,new TGeoTranslation(0.,0.,-123.));
1100   tpcrrod->AddNode(ringv,24,new TGeoTranslation(0.,0.,123.));
1101   //
1102   tpcmrod->AddNode(mrods,1,new TGeoTranslation(0.,0.,-114.));
1103   tpcmrod->AddNode(mrods,2,new TGeoTranslation(0.,0.,114.)); 
1104   tpcmrod->AddNode(ringv,25,new TGeoTranslation(0.,0.,-123.));
1105   tpcmrod->AddNode(ringv,26,new TGeoTranslation(0.,0.,123.));
1106  //
1107   // left plaque
1108   //
1109   TGeoPcon *lp = new TGeoPcon(0.,360.,4);
1110   //
1111   lp->DefineSection(0,-125.8,1.92,2.235);
1112   lp->DefineSection(1,-124.8,1.92,2.235);
1113   //
1114   lp->DefineSection(2,-124.8,1.92,2.08);
1115   lp->DefineSection(3,-123.1,1.92,2.08);
1116   //
1117   TGeoVolume *lpv1 = new TGeoVolume("TPC_lpv1",lp,m6);
1118   TGeoVolume *lpv2 = new TGeoVolume("TPC_lpv2",lp,m6);
1119   // left ring
1120   TGeoTube *lr = new TGeoTube(2.1075,2.235,0.5);
1121   TGeoVolume *lrv = new TGeoVolume("TPC_lrv",lr,m3);
1122   //
1123   lpv2->AddNode(lrv,1,new TGeoTranslation(0.,0.,-125.3));
1124   //
1125   tpcrrod->AddNode(lpv2,1); 
1126   tpcmrod->AddNode(lpv1,1);
1127   //
1128   //  right plaque
1129   //
1130   TGeoTube *rp = new TGeoTube(1.92,2.08,2.025);
1131   TGeoVolume *rpv = new TGeoVolume("TPC_rpv",rp,m6);
1132   tpcrrod->AddNode(rpv,1, new TGeoTranslation(0.,0.,125.125)); 
1133   tpcmrod->AddNode(rpv,2,new TGeoTranslation(0.,0.,125.125));
1134   //
1135   //
1136   //HV rods - makrolon + 0.58cm (diameter) Cu
1137   TGeoTube *hvr = new TGeoTube(0.,1.465,126.7);
1138   TGeoTube *hvc = new TGeoTube(0.,0.29,126.7);
1139   //
1140   TGeoVolume *hvrv = new TGeoVolume("TPC_HV_Rod",hvr,m6);
1141   TGeoVolume *hvcv = new TGeoVolume("TPC_HV_Cable",hvc,m7);
1142   hvrv->AddNode(hvcv,1);
1143   //
1144   //resistor rod
1145   //
1146   TGeoTube *cr = new TGeoTube(0.,0.45,126.2);   
1147   TGeoTube *cw = new TGeoTube(0.,0.15,126.2);  
1148   TGeoVolume *crv = new TGeoVolume("TPC_CR",cr,m10);
1149   TGeoVolume *cwv = new TGeoVolume("TPC_W",cw,m12);   
1150   //
1151   // ceramic rod with water
1152   //
1153   crv->AddNode(cwv,1);
1154   //
1155   //peek rod
1156   //
1157   TGeoTube *pr =new TGeoTube(0.2,0.35,126.2);  
1158   TGeoVolume *prv = new TGeoVolume("TPC_PR",pr,m11); 
1159   //
1160   // copper plates with connectors
1161   //
1162   new TGeoTube("tub",0.,1.7,0.025);
1163   //
1164   // half space - points on the plane and a normal vector
1165   //
1166   Double_t n[3],p[3];
1167   Double_t slope = TMath::Tan(22.*TMath::DegToRad());
1168   Double_t intp = 1.245;
1169   //
1170   Double_t b = slope*slope+1.;
1171   p[0]=intp*slope/b;
1172   p[1]=-intp/b;
1173   p[2]=0.;
1174   //
1175   n[0]=-p[0];
1176   n[1]=-p[1];
1177   n[2]=0.;
1178   Double_t norm;
1179   norm=TMath::Sqrt(n[0]*n[0]+n[1]*n[1]);
1180   n[0] /= norm;
1181   n[1] /=norm;
1182   //
1183   new TGeoHalfSpace("sp1",p,n);
1184   //
1185   slope = -slope; 
1186   //
1187   p[0]=intp*slope/b;
1188   p[1]=-intp/b;
1189   //
1190   n[0]=-p[0];
1191   n[1]=-p[1];
1192   norm=TMath::Sqrt(n[0]*n[0]+n[1]*n[1]);
1193   n[0] /= norm;
1194   n[1] /=norm;
1195   //
1196   new TGeoHalfSpace("sp2",p,n);
1197   // holes for rods
1198  //holes
1199  new TGeoTube("h1",0.,0.5,0.025);
1200  new TGeoTube("h2",0.,0.35,0.025);
1201  //translations:
1202  TGeoTranslation *ttr11 = new TGeoTranslation("ttr11",-0.866,0.5,0.);
1203  TGeoTranslation *ttr22 = new TGeoTranslation("ttr22",0.866,0.5,0.);
1204  ttr11->RegisterYourself();
1205  ttr22->RegisterYourself();
1206  // elastic connector
1207  new TGeoBBox("elcon",0.72,0.005,0.3);
1208  TGeoRotation *crr1 = new TGeoRotation();
1209  crr1->RotateZ(-22.);
1210 TGeoCombiTrans *ctr1 = new TGeoCombiTrans("ctr1",-0.36011, -1.09951,-0.325,crr1);
1211 ctr1->RegisterYourself();
1212  TGeoCompositeShape *cs1 = new TGeoCompositeShape("cs1",
1213 "(((((tub-h1:ttr11)-h1:ttr22)-sp1)-sp2)-h2)+elcon:ctr1");
1214  //
1215  TGeoVolume *csvv = new TGeoVolume("TPC_RR_CU",cs1,m7);
1216  //
1217  // resistor rod assembly 2 ceramic rods, peak rod, Cu plates
1218  // and resistors
1219  //
1220  TGeoVolumeAssembly *rrod = new TGeoVolumeAssembly("TPC_RRIN");
1221  // rods
1222  rrod->AddNode(crv,1,ttr11);
1223  rrod->AddNode(crv,2,ttr22); 
1224  rrod->AddNode(prv,1);
1225  //Cu plates
1226  for(Int_t i=0;i<165;i++){
1227    rrod->AddNode(csvv,i+1,new TGeoTranslation(0.,0.,-122.675+i*1.5));
1228  }
1229  //resistors
1230  TGeoTube *res = new TGeoTube(0.,0.15,0.5);
1231  TGeoVolume *resv = new TGeoVolume("TPC_RES",res,m10);
1232  TGeoVolumeAssembly *ress = new TGeoVolumeAssembly("TPC_RES_CH");
1233  ress->AddNode(resv,1,new TGeoTranslation(0.2,0.,0.));
1234  ress->AddNode(resv,2,new TGeoTranslation(-0.2,0.,0.));
1235  //
1236  TGeoRotation *crr2 = new TGeoRotation();
1237  crr2->RotateY(30.);
1238  TGeoRotation *crr3 = new TGeoRotation();
1239  crr3->RotateY(-30.); 
1240  //
1241  for(Int_t i=0;i<164;i+=2){
1242    rrod->AddNode(ress,i+1, new TGeoCombiTrans(0.,1.2,-121.925+i*1.5,crr2));
1243    rrod->AddNode(ress,i+2, new TGeoCombiTrans(0.,1.2,-121.925+(i+1)*1.5,crr3));
1244  }
1245
1246  tpcrrod->AddNode(rrod,1,new TGeoCombiTrans(0.,0.,0.5,crr1));
1247  //
1248  // guard ring resistor chain
1249  //
1250
1251  TGeoTube *gres1 = new TGeoTube(0.,0.375,125.);// inside ifc
1252  //
1253  TGeoVolume *vgres1 = new TGeoVolume("TPC_GRES1",gres1,m10);
1254
1255  //
1256  Double_t xrc,yrc;
1257  //
1258  xrc=79.3*TMath::Cos(350.*TMath::DegToRad());
1259  yrc=79.3*TMath::Sin(350.*TMath::DegToRad());
1260  //
1261  v9->AddNode(vgres1,1,new TGeoTranslation(xrc,yrc,126.9));
1262  v9->AddNode(vgres1,2,new TGeoTranslation(xrc,yrc,-126.9));
1263  //
1264  xrc=79.3*TMath::Cos(170.*TMath::DegToRad());
1265  yrc=79.3*TMath::Sin(170.*TMath::DegToRad()); 
1266  //
1267  v9->AddNode(vgres1,3,new TGeoTranslation(xrc,yrc,126.9));
1268  v9->AddNode(vgres1,4,new TGeoTranslation(xrc,yrc,-126.9));
1269  //------------------------------------------------------------------
1270  TGeoRotation refl("refl",90.,0.,90.,90.,180.,0.);
1271  TGeoRotation rotrod("rotrod");
1272  //
1273  TGeoRotation *rotpos[2]; 
1274  //
1275  TGeoRotation *rotrod1[2]; 
1276   
1277  //v9 - drift gas
1278
1279   for(Int_t i=0;i<18;i++){
1280     Double_t angle,x,y;
1281     Double_t z,r; 
1282     angle=TMath::DegToRad()*20.*(Double_t)i;
1283     //inner rods
1284     r=81.5;
1285     x=r * TMath::Cos(angle);
1286     y=r * TMath::Sin(angle);
1287     z = 126.;
1288     //
1289     if(i==11){//resistor rod inner
1290        rotrod.RotateZ(-90.+angle);
1291        rotrod1[0]= new TGeoRotation();
1292        rotpos[0]= new TGeoRotation();
1293        //
1294        rotrod1[0]->RotateZ(-90.+angle);
1295        *rotpos[0] = refl*rotrod; //rotation+reflection
1296         v9->AddNode(tpcrrod,1,new TGeoCombiTrans(x,y, z, rotrod1[0])); //A
1297         v9->AddNode(tpcrrod,2,new TGeoCombiTrans(x,y,-z, rotpos[0])); //C      
1298     } 
1299     else { 
1300       v9->AddNode(tpcmrod,i+1,new TGeoTranslation(x,y,z));//shaft
1301       v9->AddNode(tpcmrod,i+19,new TGeoCombiTrans(x,y,-z,ref));//muon
1302     }
1303     // outer rods
1304     r=254.25;
1305     x=r * TMath::Cos(angle);
1306     y=r * TMath::Sin(angle);
1307     z=126.;
1308     //
1309     if(i==3){//resistor rod outer
1310       rotrod.RotateZ(90.+angle);
1311       rotrod1[1]= new TGeoRotation();
1312       rotpos[1]= new TGeoRotation();
1313       rotrod1[1]->RotateZ(90.+angle);
1314       *rotpos[1] = refl*rotrod;//rotation+reflection
1315       v9->AddNode(tpcrrod,3,new TGeoCombiTrans(x,y, z, rotrod1[1])); //A 
1316       v9->AddNode(tpcrrod,4,new TGeoCombiTrans(x,y, -z, rotpos[1])); //C
1317     }
1318     else {
1319       v9->AddNode(tpcmrod,i+37,new TGeoTranslation(x,y,z));//shaft
1320       v9->AddNode(tpcmrod,i+55,new TGeoCombiTrans(x,y,-z,ref));//muon      
1321     }
1322     if(i==15){
1323       v9->AddNode(hvrv,1,new TGeoTranslation(x,y,z)); //hv->A-side only      
1324     }
1325   } //end of rods positioning
1326
1327   TGeoVolume *alice = gGeoManager->GetVolume("ALIC");
1328   alice->AddNode(v1,1);  
1329   
1330 } // end of function
1331  
1332 //_____________________________________________________________________________
1333 void AliTPCv2::AddAlignableVolumes() const
1334 {
1335   //
1336   // Create entries for alignable volumes associating the symbolic volume
1337   // name with the corresponding volume path. Needs to be syncronized with
1338   // eventual changes in the geometry.
1339   // 
1340   SetInnerChambersAlignable();
1341   SetOuterChambersAlignable();
1342 }
1343  
1344 //_____________________________________________________________________________
1345 void AliTPCv2::SetInnerChambersAlignable() const
1346 {
1347   //
1348   AliGeomManager::ELayerID idTPC1 = AliGeomManager::kTPC1;
1349   Int_t modUID, modnum = 0;
1350   TString vpstr1 = "ALIC_1/TPC_M_1/TPC_Drift_1/TPC_ENDCAP_1/TPC_SECT_";
1351   TString vpstr2 = "ALIC_1/TPC_M_1/TPC_Drift_1/TPC_ENDCAP_2/TPC_SECT_";
1352   TString vpappend = "/TPC_IROC_1";
1353   TString snstr1="TPC/EndcapA/Sector";
1354   TString snstr2="TPC/EndcapC/Sector";
1355   TString snappend="/InnerChamber";
1356   TString volpath, symname;
1357   
1358   for(Int_t cnt=1; cnt<=18; cnt++){
1359     modUID = AliGeomManager::LayerToVolUID(idTPC1,modnum++);
1360     volpath = vpstr1;
1361     volpath += cnt;
1362     volpath += vpappend;
1363     symname = snstr1;
1364     symname += cnt;
1365     symname += snappend;
1366     if(!gGeoManager->SetAlignableEntry(symname.Data(),volpath.Data(),modUID))
1367       AliFatal(Form("Alignable entry %s not created. Volume path %s not valid", symname.Data(),volpath.Data()));
1368     TGeoPNEntry *alignableEntry = gGeoManager->GetAlignableEntryByUID(modUID);
1369     TGeoHMatrix* globMatrix = alignableEntry->GetGlobalOrig();
1370     TGeoHMatrix* matTtoL = fTPCParam->Tracking2LocalMatrix(globMatrix,cnt-1);
1371     alignableEntry->SetMatrix(matTtoL);
1372   }
1373
1374   for(Int_t cnt=1; cnt<=18; cnt++){
1375     modUID = AliGeomManager::LayerToVolUID(idTPC1,modnum++);
1376     volpath = vpstr2;
1377     volpath += cnt;
1378     volpath += vpappend;
1379     symname = snstr2;
1380     symname += cnt;
1381     symname += snappend;
1382     if(!gGeoManager->SetAlignableEntry(symname.Data(),volpath.Data(),modUID))
1383       AliFatal(Form("Alignable entry %s not created. Volume path %s not valid", symname.Data(),volpath.Data()));
1384     TGeoPNEntry *alignableEntry = gGeoManager->GetAlignableEntryByUID(modUID);
1385     TGeoHMatrix* globMatrix = alignableEntry->GetGlobalOrig();
1386     TGeoHMatrix* matTtoL = fTPCParam->Tracking2LocalMatrix(globMatrix,18+cnt-1);
1387     alignableEntry->SetMatrix(matTtoL);
1388   }
1389 }
1390
1391 //_____________________________________________________________________________
1392 void AliTPCv2::SetOuterChambersAlignable() const
1393 {
1394   //
1395   AliGeomManager::ELayerID idTPC2 = AliGeomManager::kTPC2;
1396   Int_t modUID, modnum = 0;
1397   TString vpstr1 = "ALIC_1/TPC_M_1/TPC_Drift_1/TPC_ENDCAP_1/TPC_SECT_";
1398   TString vpstr2 = "ALIC_1/TPC_M_1/TPC_Drift_1/TPC_ENDCAP_2/TPC_SECT_";
1399   TString vpappend = "/TPC_OROC_1";
1400   TString snstr1="TPC/EndcapA/Sector";
1401   TString snstr2="TPC/EndcapC/Sector";
1402   TString snappend="/OuterChamber";
1403   TString volpath, symname;
1404   
1405   for(Int_t cnt=1; cnt<=18; cnt++){
1406     modUID = AliGeomManager::LayerToVolUID(idTPC2,modnum++);
1407     volpath = vpstr1;
1408     volpath += cnt;
1409     volpath += vpappend;
1410     symname = snstr1;
1411     symname += cnt;
1412     symname += snappend;
1413     if(!gGeoManager->SetAlignableEntry(symname.Data(),volpath.Data(),modUID))
1414       AliFatal(Form("Alignable entry %s not created. Volume path %s not valid", symname.Data(),volpath.Data()));
1415     TGeoPNEntry *alignableEntry = gGeoManager->GetAlignableEntryByUID(modUID);
1416     TGeoHMatrix* globMatrix = alignableEntry->GetGlobalOrig();
1417     TGeoHMatrix* matTtoL = fTPCParam->Tracking2LocalMatrix(globMatrix,36+cnt-1);
1418     alignableEntry->SetMatrix(matTtoL);
1419   }
1420
1421   for(Int_t cnt=1; cnt<=18; cnt++){
1422     modUID = AliGeomManager::LayerToVolUID(idTPC2,modnum++);
1423     volpath = vpstr2;
1424     volpath += cnt;
1425     volpath += vpappend;
1426     symname = snstr2;
1427     symname += cnt;
1428     symname += snappend;
1429     if(!gGeoManager->SetAlignableEntry(symname.Data(),volpath.Data(),modUID))
1430       AliFatal(Form("Alignable entry %s not created. Volume path %s not valid", symname.Data(),volpath.Data()));
1431     TGeoPNEntry *alignableEntry = gGeoManager->GetAlignableEntryByUID(modUID);
1432     TGeoHMatrix* globMatrix = alignableEntry->GetGlobalOrig();
1433     TGeoHMatrix* matTtoL = fTPCParam->Tracking2LocalMatrix(globMatrix,36+18+cnt-1);
1434     alignableEntry->SetMatrix(matTtoL);
1435   }
1436 }
1437
1438 //_____________________________________________________________________________
1439 void AliTPCv2::DrawDetector() const
1440 {
1441   //
1442   // Draw a shaded view of the Time Projection Chamber version 1
1443   //
1444
1445   // Set everything unseen
1446   gMC->Gsatt("*", "seen", -1);
1447   // 
1448   // Set ALIC mother transparent
1449   gMC->Gsatt("ALIC","SEEN",0);
1450   //
1451   // Set the volumes visible
1452   //
1453
1454   gMC->Gsatt("TPC ","SEEN",0);
1455   gMC->Gsatt("TOIN","SEEN",1);
1456   gMC->Gsatt("TOIN","COLO",7);
1457   gMC->Gsatt("TOCV","SEEN",1);
1458   gMC->Gsatt("TOCV","COLO",4);
1459   gMC->Gsatt("TSA1","SEEN",0);
1460   gMC->Gsatt("TSA2","SEEN",0);
1461   gMC->Gsatt("TSA3","SEEN",0);
1462   gMC->Gsatt("TSA4","SEEN",0);  
1463   gMC->Gsatt("TSA5","SEEN",0);
1464   gMC->Gsatt("TOFC","SEEN",1);
1465   gMC->Gsatt("TOFC","COLO",4);
1466   gMC->Gsatt("TSA6","SEEN",0);
1467   gMC->Gsatt("TSA7","SEEN",0);
1468   gMC->Gsatt("TSA8","SEEN",0);    
1469   gMC->Gsatt("TIIN","SEEN",1);
1470   gMC->Gsatt("TIIN","COLO",7);
1471   gMC->Gsatt("TII1","SEEN",0);
1472   gMC->Gsatt("TIFC","SEEN",1);
1473   gMC->Gsatt("TIFC","COLO",4);
1474   gMC->Gsatt("TSA9","SEEN",0); 
1475   gMC->Gsatt("TS10","SEEN",0);
1476   gMC->Gsatt("TS11","SEEN",0);
1477   gMC->Gsatt("TS12","SEEN",0);
1478   gMC->Gsatt("TS13","SEEN",0);
1479   gMC->Gsatt("TS14","SEEN",0);
1480   gMC->Gsatt("TICC","SEEN",0);
1481   gMC->Gsatt("TICM","SEEN",0);
1482   gMC->Gsatt("TS15","SEEN",0);
1483   gMC->Gsatt("TS16","SEEN",0);
1484   gMC->Gsatt("TS17","SEEN",0);
1485   gMC->Gsatt("TS18","SEEN",0);  
1486   gMC->Gsatt("TS19","SEEN",0); 
1487   gMC->Gsatt("TPJ1","SEEN",0);
1488   gMC->Gsatt("TPJ2","SEEN",0);
1489   gMC->Gsatt("TICS","SEEN",0);
1490   gMC->Gsatt("TDGN","SEEN",0); 
1491   gMC->Gsatt("TIRC","SEEN",0);
1492   gMC->Gsatt("TIC1","SEEN",1);
1493   gMC->Gsatt("TIPP","SEEN",0);
1494   gMC->Gsatt("TIC3","SEEN",0);
1495   gMC->Gsatt("TRCE","SEEN",0);
1496   gMC->Gsatt("TPSC","SEEN",0);
1497   gMC->Gsatt("TPCC","SEEN",0); 
1498   gMC->Gsatt("TORC","SEEN",0);
1499   gMC->Gsatt("TOPP","SEEN",0);
1500   gMC->Gsatt("TOC3","SEEN",0);
1501   gMC->Gsatt("TOC1","SEEN",1);
1502   gMC->Gsatt("TSSW","SEEN",1);
1503   gMC->Gsatt("TSWC","SEEN",1);
1504   gMC->Gsatt("TSSW","COLO",3);
1505   gMC->Gsatt("TSWC","COLO",3);
1506   gMC->Gsatt("TSCE","COLO",6);
1507   gMC->Gsatt("TSCE","SEEN",1);
1508   gMC->Gsatt("TWES","SEEN",0);
1509   gMC->Gsatt("TSWB","SEEN",0);
1510   gMC->Gsatt("TPEL","SEEN",0);
1511   gMC->Gsatt("TPMW","SEEN",1);
1512   gMC->Gsatt("TESR","SEEN",1);
1513   gMC->Gsatt("TPMW","COLO",12);
1514   gMC->Gsatt("TIC1","COLO",5);
1515   gMC->Gsatt("TOC1","COLO",5);
1516   gMC->Gsatt("TESB","SEEN",0);
1517   gMC->Gsatt("THVM","SEEN",1);
1518   gMC->Gsatt("THVM","COLO",11);
1519   gMC->Gsatt("THVH","SEEN",0);
1520   gMC->Gsatt("TPSR","SEEN",0); 
1521   gMC->Gsatt("THVL","SEEN",0);
1522   gMC->Gsatt("THVC","SEEN",0);  
1523   gMC->Gsatt("THVE","SEEN",0);
1524   gMC->Gsatt("THVR","SEEN",0);
1525   gMC->Gsatt("TPSS","SEEN",0);
1526   gMC->Gsatt("TPUS","SEEN",0);
1527   gMC->Gsatt("TPLS","SEEN",0);
1528
1529   //
1530   gMC->Gdopt("hide", "on");
1531   gMC->Gdopt("shad", "on");
1532   gMC->Gsatt("*", "fill", 7);
1533   gMC->SetClipBox(".");
1534   gMC->SetClipBox("TPMW",-300,300,-300,300,254.,270.);
1535   gMC->SetClipBox("TESR",-300,300,-300,300,254.,270.);
1536   gMC->SetClipBox("TSSW",-300,300,-300,300,283.,284.);
1537   gMC->SetClipBox("TSWC",-300,300,-300,300,283.,284.);
1538   gMC->SetClipBox("*", 0, 300, -300, 300, -290, 290);
1539   gMC->DefaultRange();
1540   gMC->Gdraw("alic", 40, 30, 0, 12, 9.5, .025, .025);
1541   gMC->Gdhead(1111, "Time Projection Chamber");
1542   gMC->Gdman(18, 4, "MAN");
1543   gMC->Gdopt("hide","off");
1544 }
1545
1546 //_____________________________________________________________________________
1547 void AliTPCv2::CreateMaterials()
1548 {
1549   //
1550   // Define materials for version 2 of the Time Projection Chamber
1551   //
1552  
1553   AliTPC::CreateMaterials();
1554 }
1555
1556 //_____________________________________________________________________________
1557 void AliTPCv2::Init()
1558 {
1559   //
1560   // Initialises version 2 of the TPC after that it has been built
1561   //
1562
1563   Int_t *idtmed = fIdtmed->GetArray();
1564   
1565   AliTPC::Init();
1566
1567  
1568   fIdSens=gMC->VolId("TPC_Strip");  // one strip is always selected...
1569
1570   fIDrift=gMC->VolId("TPC_Drift");
1571   fSecOld=-100; // fake number 
1572
1573   gMC->SetMaxNStep(-30000); // max. number of steps increased
1574
1575   if (fPrimaryIonisation) {
1576       gMC->Gstpar(idtmed[2],"PRIMIO_E", 20.77); // 1st ionisation potential
1577  
1578       gMC->Gstpar(idtmed[2],"PRIMIO_N", 14.35);
1579       gMC->Gstpar(idtmed[2],"LOSS", 14); // specific energy loss
1580       gMC->Gstpar(idtmed[2],"STRA",4);
1581   } else {
1582       gMC->Gstpar(idtmed[2],"LOSS", 5); // specific energy loss
1583   }
1584
1585
1586   AliDebug(1,"*** TPC version 2 initialized ***");
1587   AliDebug(1,Form("Maximum number of steps = %d",gMC->GetMaxNStep()));
1588
1589   //
1590   
1591 }
1592
1593 //_____________________________________________________________________________
1594 void AliTPCv2::StepManager()
1595 {
1596   //
1597   // Called for every step in the Time Projection Chamber
1598   //
1599
1600   //
1601   // parameters used for the energy loss calculations
1602   //
1603   const Float_t kprim = 14.35; // number of primary collisions per 1 cm
1604   const Float_t kpoti = 20.77e-9; // first ionization potential for Ne/CO2
1605   const Float_t kwIon = 35.97e-9; // energy for the ion-electron pair creation 
1606   const Int_t   kMaxDistRef =15;     // maximal difference between 2 stored references 
1607  
1608   const Float_t kbig = 1.e10;
1609
1610   Int_t id,copy;
1611   Float_t hits[5];
1612   Int_t vol[2];  
1613   TLorentzVector p;
1614   
1615   vol[1]=0; // preset row number to 0
1616   //
1617   if (fPrimaryIonisation) gMC->SetMaxStep(kbig);
1618   
1619   if(!gMC->IsTrackAlive()) return; // particle has disappeared
1620   
1621   Float_t charge = gMC->TrackCharge();
1622   
1623   if(TMath::Abs(charge)<=0.) return; // take only charged particles
1624   
1625   // check the sensitive volume
1626
1627   id = gMC->CurrentVolID(copy); // vol ID and copy number (starts from 1!)
1628   if(id != fIDrift && id != fIdSens) return; // not in the sensitive folume 
1629
1630   gMC->TrackPosition(p);
1631   Double_t r = TMath::Sqrt(p[0]*p[0]+p[1]*p[1]);
1632   //
1633   
1634   //
1635   Double_t angle = TMath::ACos(p[0]/r);  
1636   angle = (p[1]<0.) ? TMath::TwoPi()-angle : angle;
1637   //
1638   // angular segment, it is not a real sector number...
1639   //
1640   Int_t sector=TMath::Nint((angle-fTPCParam->GetInnerAngleShift())/
1641                fTPCParam->GetInnerAngle());
1642   // rotate to segment "0"
1643   Float_t cos,sin;
1644   fTPCParam->AdjustCosSin(sector,cos,sin);
1645   Float_t x1=p[0]*cos + p[1]*sin;
1646   // check if within sector's limits
1647   if((x1>=fTPCParam->GetInnerRadiusLow()&&x1<=fTPCParam->GetInnerRadiusUp())
1648      ||(x1>=fTPCParam->GetOuterRadiusLow()&&x1<=fTPCParam->GetOuterRadiusUp())){
1649   // calculate real sector number...
1650   if (x1>fTPCParam->GetOuterRadiusLow()){
1651     sector = TMath::Nint((angle-fTPCParam->GetOuterAngleShift())/
1652              fTPCParam->GetOuterAngle())+fTPCParam->GetNInnerSector();
1653     if (p[2]<0)         sector+=(fTPCParam->GetNOuterSector()>>1);
1654   }
1655     else   
1656       if (p[2]<0) sector+=(fTPCParam->GetNInnerSector()>>1);  
1657   //
1658   // here I have a sector number
1659   //
1660
1661   vol[0]=sector;
1662
1663   static Double_t lastReferenceR=0;
1664   if (TMath::Abs(lastReferenceR-r)>kMaxDistRef){
1665     AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber(), AliTrackReference::kTPC);
1666     lastReferenceR = r;
1667   }
1668
1669   // check if change of sector
1670   if(sector != fSecOld){
1671     fSecOld=sector;
1672     // add track reference
1673     AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber(), AliTrackReference::kTPC);
1674   }  
1675   // track is in the sensitive strip
1676   if(id == fIdSens){
1677     // track is entering the strip
1678     if (gMC->IsTrackEntering()){
1679       Int_t totrows = fTPCParam->GetNRowLow()+fTPCParam->GetNRowUp();
1680       vol[1] = (copy<=totrows) ? copy-1 : copy-1-totrows;
1681       // row numbers are autonomous for lower and upper sectors
1682       if(vol[0] > fTPCParam->GetNInnerSector()) {
1683         vol[1] -= fTPCParam->GetNRowLow();
1684       }
1685     //
1686       if(vol[0]<fTPCParam->GetNInnerSector()&&vol[1] == 0){
1687   
1688         // lower sector, row 0, because Jouri wants to have this
1689
1690         gMC->TrackMomentum(p);
1691         hits[0]=p[0];
1692         hits[1]=p[1];
1693         hits[2]=p[2];
1694         hits[3]=0.; // this hit has no energy loss
1695         // Get also the track time for pileup simulation
1696         hits[4]=gMC->TrackTime();
1697
1698         AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol,hits);  
1699       }
1700     //
1701
1702        gMC->TrackPosition(p);
1703        hits[0]=p[0];
1704        hits[1]=p[1];
1705        hits[2]=p[2];
1706        hits[3]=0.; // this hit has no energy loss
1707        // Get also the track time for pileup simulation
1708        hits[4]=gMC->TrackTime();
1709
1710        AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol,hits);  
1711     
1712     }
1713     else return;
1714   }  
1715   //-----------------------------------------------------------------
1716   //  charged particle is in the sensitive drift volume
1717   //-----------------------------------------------------------------
1718   if(gMC->TrackStep() > 0) {
1719     Int_t nel=0;
1720     if (!fPrimaryIonisation) {
1721       nel = (Int_t)(((gMC->Edep())-kpoti)/kwIon) + 1;
1722     }
1723     else {
1724           Float_t edep = gMC->Edep();
1725           if (edep > 0.) nel = (Int_t)((gMC->Edep()*1.5)/kwIon) + 1;      
1726     }
1727     nel=TMath::Min(nel,300); // 300 electrons corresponds to 10 keV
1728     //
1729     gMC->TrackPosition(p);
1730     hits[0]=p[0];
1731     hits[1]=p[1];
1732     hits[2]=p[2];
1733     hits[3]=(Float_t)nel;
1734
1735     // Add this hit
1736
1737     if (fHitType&&2){
1738       gMC->TrackMomentum(p);
1739       Float_t momentum = TMath::Sqrt(p[0]*p[0]+p[1]*p[1]);
1740       Float_t precision =   (momentum>0.1) ? 0.002 :0.01;
1741       fTrackHits->SetHitPrecision(precision);
1742     }
1743
1744     // Get also the track time for pileup simulation
1745     hits[4]=gMC->TrackTime();
1746  
1747     AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol,hits);
1748
1749   } // step>0 
1750   } //within sector's limits
1751   // Stemax calculation for the next step
1752   
1753   Float_t pp;
1754   TLorentzVector mom;
1755   // below is valid only for Geant3 (fPromaryIonisation not set)
1756   if(!fPrimaryIonisation){
1757     gMC->TrackMomentum(mom);
1758     Float_t ptot=mom.Rho();
1759     Float_t betaGamma = ptot/gMC->TrackMass();
1760
1761     Int_t pid=gMC->TrackPid();
1762     if((pid==kElectron || pid==kPositron) && ptot > 0.002)
1763       { 
1764         pp = kprim*1.58; // electrons above 20 MeV/c are on the plateau!
1765       }
1766     else
1767       {
1768
1769         betaGamma = TMath::Max(betaGamma,(Float_t)7.e-3); // protection against too small bg
1770         pp=kprim*AliMathBase::BetheBlochAleph(betaGamma); 
1771    
1772     }
1773   
1774     Double_t rnd = gMC->GetRandom()->Rndm();
1775   
1776     gMC->SetMaxStep(-TMath::Log(rnd)/pp);
1777   }
1778   
1779 }
1780
1781