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