]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCv3.cxx
secure code fixes
[u/mrichter/AliRoot.git] / TPC / AliTPCv3.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 3 -- detailed TPC and slow simulation    //
22 //                                                                     
23 //Begin_Html
24 /*
25 <img src="picts/AliTPCv3Class.gif">
26 */
27 //End_Html
28 //                                                                           //
29 //                                                                           //
30 ///////////////////////////////////////////////////////////////////////////////
31
32 #include <stdlib.h>
33
34 #include <TInterpreter.h>
35 #include <TLorentzVector.h>
36 #include <TMath.h>
37 #include <TVirtualMC.h>
38 #include <TPDGCode.h>
39 #include <TString.h>
40 #include <TSystem.h>
41
42 #include "AliConst.h"
43 #include "AliRun.h"
44 #include "AliMathBase.h"
45 #include "AliTPCDigitsArray.h"
46 #include "AliTPCParam.h"
47 #include "AliTPCParamSR.h"
48 #include "AliTPCTrackHitsV2.h"
49 #include "AliTPCv3.h"
50 #include "AliMC.h"
51 #include "TGeoManager.h"
52 #include "TGeoVolume.h"
53 #include "TGeoPcon.h"
54 #include "TGeoTube.h"
55 #include "TGeoPgon.h"
56 #include "TGeoTrd1.h"
57 #include "TGeoCompositeShape.h"
58 #include "TGeoPara.h"
59
60 ClassImp(AliTPCv3)
61 //_____________________________________________________________________________
62
63   AliTPCv3::AliTPCv3():AliTPC(),fIdSens(0)
64 {
65
66   fHitType = 1;
67
68
69
70 //_____________________________________________________________________________
71 AliTPCv3::AliTPCv3(const char *name, const char *title) :
72   AliTPC(name, title), fIdSens(0)
73 {
74   //
75   // Standard constructor for Time Projection Chamber version 3
76   //
77
78   SetBufferSize(128000);
79
80   if (fTPCParam)
81      fTPCParam->Write(fTPCParam->GetTitle());
82
83   fHitType =1;
84 }
85  
86 //_____________________________________________________________________________
87 void AliTPCv3::CreateGeometry()
88 {
89   //
90   // Creation of the TPC coarse geometry (version 3)
91   // The whole drift volume is sensitive
92   // Origin Marek Kowalski Cracow
93   //
94   //Begin_Html
95   /*
96     <img src="picts/AliTPCgif">
97   */
98   //End_Html
99   //Begin_Html
100   /*
101     <img src="picts/AliTPCv3Tree.gif">
102   */
103   //End_Html
104    //----------------------------------------------------------
105   // This geometry is written using TGeo class
106   // Firstly the shapes are defined, and only then the volumes
107   // What is recognized by the MC are volumes
108   //----------------------------------------------------------
109   //
110   //  tpc - this will be the mother volume
111   //
112
113   //
114   // here I define a volume TPC
115   // retrive the medium name with "TPC_" as a leading string
116   //
117   TGeoPcon *tpc = new TGeoPcon(0.,360.,28); //28 sections
118   //
119   tpc->DefineSection(0,-291.,77.,278.);
120   tpc->DefineSection(1,-270,77.,278.);
121   //
122   tpc->DefineSection(2,-270.,77.,278.);
123   tpc->DefineSection(3,-262.1,77.,278.);
124   //
125   tpc->DefineSection(4,-262.1,83.1,278.);
126   tpc->DefineSection(5,-260.,83.1,278.);
127   //
128   tpc->DefineSection(6,-260.,70.,278.);    
129   tpc->DefineSection(7,-259.6,70.,278.);
130   //
131   tpc->DefineSection(8,-259.6,68.1,278.);
132   tpc->DefineSection(9,-253.6,68.1,278.);
133   //
134   tpc->DefineSection(10,-253.6,68.,278.);
135   tpc->DefineSection(11,-74.0,60.8,278.);
136   //
137   tpc->DefineSection(12,-74.0,60.1,278.);
138   tpc->DefineSection(13,-73.3,60.1,278.);
139   //
140   tpc->DefineSection(14,-73.3,56.9,278.); 
141   tpc->DefineSection(15,-68.5,56.9,278.);
142   //
143   tpc->DefineSection(16,-68.5,60.,278.);
144   tpc->DefineSection(17,-65.,60.,278.);
145   //
146   tpc->DefineSection(18,-65.,56.9,278.); 
147   tpc->DefineSection(19,73.3,56.9,278.);
148   //
149   tpc->DefineSection(20,73.3,60.1,278.);
150   tpc->DefineSection(21,74.0,60.1,278.);
151   //
152   tpc->DefineSection(22,74.0,60.8,278.);
153   tpc->DefineSection(23,253.6,65.5,278.);
154   //
155   tpc->DefineSection(24,253.6,65.6,278.);
156   tpc->DefineSection(25,259.6,65.6,278.);
157   //
158   tpc->DefineSection(26,259.6,70.0,278.);
159   tpc->DefineSection(27,291.,77.,278.);
160   //
161   TGeoMedium *m1 = gGeoManager->GetMedium("TPC_Air");
162   TGeoVolume *v1 = new TGeoVolume("TPC_M",tpc,m1);
163   //
164   // drift volume - sensitive volume, extended beyond the
165   // endcaps, because of the alignment
166   //
167   TGeoPcon *dvol = new TGeoPcon(0.,360.,6);
168   dvol->DefineSection(0,-260.,74.5,264.4);
169   dvol->DefineSection(1,-253.6,74.5,264.4);
170   //
171   dvol->DefineSection(2,-253.6,76.6774,258.);
172   dvol->DefineSection(3,253.6,76.6774,258.); 
173   //
174   dvol->DefineSection(4,253.6,74.5,264.4);
175   dvol->DefineSection(5,260.,74.5,264.4);
176   //
177   TGeoMedium *m5 = gGeoManager->GetMedium("TPC_Ne-CO2-2");
178   TGeoVolume *v9 = new TGeoVolume("TPC_Drift",dvol,m5);
179   //
180   v1->AddNode(v9,1);
181   //
182   // outer insulator
183   //
184   TGeoPcon *tpco = new TGeoPcon(0.,360.,6); //insulator
185   //
186   tpco->DefineSection(0,-256.6,264.8,278.);
187   tpco->DefineSection(1,-253.6,264.8,278.);
188   //
189   tpco->DefineSection(2,-253.6,258.,278.);
190   tpco->DefineSection(3,250.6,258.,278.);
191   //
192   tpco->DefineSection(4,250.6,258.,275.5);
193   tpco->DefineSection(5,253.6,258.,275.5);
194   //
195   TGeoMedium *m2 = gGeoManager->GetMedium("TPC_CO2");
196   TGeoVolume *v2 = new TGeoVolume("TPC_OI",tpco,m2);
197   //
198   // outer containment vessel
199   //
200   TGeoPcon *tocv = new TGeoPcon(0.,360.,6);  // containment vessel
201   //
202   tocv->DefineSection(0,-256.6,264.8,278.);
203   tocv->DefineSection(1,-253.6,264.8,278.);
204   //
205   tocv->DefineSection(2,-253.6,274.8124,278.);
206   tocv->DefineSection(3,247.6,274.8124,278.);  
207   //
208   tocv->DefineSection(4,247.6,270.4,278.);
209   tocv->DefineSection(5,250.6,270.4,278.);
210   //
211   TGeoMedium *m3 = gGeoManager->GetMedium("TPC_Al");
212   TGeoVolume *v3 = new TGeoVolume("TPC_OCV",tocv,m3); 
213   //
214   TGeoTube *to1 = new TGeoTube(274.8174,277.995,252.1); //epoxy
215   TGeoTube *to2 = new TGeoTube(274.8274,277.985,252.1); //tedlar
216   TGeoTube *to3 = new TGeoTube(274.8312,277.9812,252.1);//prepreg2
217   TGeoTube *to4 = new TGeoTube(274.9062,277.9062,252.1);//nomex
218   //
219   TGeoMedium *sm1 = gGeoManager->GetMedium("TPC_Epoxy");
220   TGeoMedium *sm2 = gGeoManager->GetMedium("TPC_Tedlar");
221   TGeoMedium *sm3 = gGeoManager->GetMedium("TPC_Prepreg2");
222   TGeoMedium *sm4 = gGeoManager->GetMedium("TPC_Nomex");
223   //
224   TGeoVolume *tov1 = new TGeoVolume("TPC_OCV1",to1,sm1);
225   TGeoVolume *tov2 = new TGeoVolume("TPC_OCV2",to2,sm2);
226   TGeoVolume *tov3 = new TGeoVolume("TPC_OCV3",to3,sm3);
227   TGeoVolume *tov4 = new TGeoVolume("TPC_OCV4",to4,sm4);
228
229   //-------------------------------------------------------
230   //  Tpc Outer Field Cage
231   //  daughters - composite (sandwich)
232   //-------------------------------------------------------
233
234   TGeoPcon *tofc = new TGeoPcon(0.,360.,6);
235   //
236   tofc->DefineSection(0,-253.6,258.,269.6);
237   tofc->DefineSection(1,-250.6,258.,269.6);
238   //
239   tofc->DefineSection(2,-250.6,258.,260.0676); 
240   tofc->DefineSection(3,250.6,258.,260.0676);
241   //
242   tofc->DefineSection(4,250.6,258.,275.5);
243   tofc->DefineSection(5,253.6,258.,275.5);
244   //
245   TGeoVolume *v4 = new TGeoVolume("TPC_TOFC",tofc,m3); 
246   //sandwich
247   TGeoTube *tf1 = new TGeoTube(258.0,260.0676,252.1); //tedlar
248   TGeoTube *tf2 = new TGeoTube(258.0038,260.0638,252.1); //prepreg3
249   TGeoTube *tf3 = new TGeoTube(258.0338,260.0338,252.1);//nomex
250   //
251   TGeoMedium *sm5 = gGeoManager->GetMedium("TPC_Prepreg3");
252   //
253   TGeoVolume *tf1v = new TGeoVolume("TPC_OFC1",tf1,sm2);
254   TGeoVolume *tf2v = new TGeoVolume("TPC_OFC2",tf2,sm5);
255   TGeoVolume *tf3v = new TGeoVolume("TPC_OFC3",tf3,sm4);
256   //
257   // outer part - positioning
258   //
259   tov1->AddNode(tov2,1); tov2->AddNode(tov3,1); tov3->AddNode(tov4,1);
260   //
261   tf1v->AddNode(tf2v,1); tf2v->AddNode(tf3v,1);
262   //
263   v3->AddNode(tov1,1,new TGeoTranslation(0.,0.,-1.5)); v4->AddNode(tf1v,1);
264   //
265   v2->AddNode(v3,1); v2->AddNode(v4,1); 
266   //
267   v1->AddNode(v2,1);
268   //-----------------------------------------------------------
269
270
271
272
273
274
275   //--------------------------------------------------------------------
276   // Tpc Inner INsulator (CO2) 
277   // the cones, the central drum and the inner f.c. sandwich with a piece
278   // of the flane will be placed in the TPC
279   //--------------------------------------------------------------------
280   TGeoPcon *tpci = new TGeoPcon(0.,360.,4);
281   //
282   tpci->DefineSection(0,-253.6,68.4,76.6774);
283   tpci->DefineSection(1,-74.0,61.2,76.6774);
284   //
285   tpci->DefineSection(2,74.0,61.2,76.6774);  
286   //
287   tpci->DefineSection(3,253.6,65.9,76.6774);
288   //
289   TGeoVolume *v5 = new TGeoVolume("TPC_INI",tpci,m2);
290   //
291   // now the inner field cage - only part of flanges (2 copies)
292   //
293   TGeoTube *tif1 = new TGeoTube(69.9,76.6774,1.5); 
294   TGeoVolume *v6 = new TGeoVolume("TPC_IFC1",tif1,m3);
295   //
296  //---------------------------------------------------------
297   // Tpc Inner Containment vessel - Muon side
298   //---------------------------------------------------------
299   TGeoPcon *tcms = new TGeoPcon(0.,360.,10);
300   //
301   tcms->DefineSection(0,-259.1,68.1,74.2);
302   tcms->DefineSection(1,-253.6,68.1,74.2);
303   //
304   tcms->DefineSection(2,-253.6,68.1,68.4);
305   tcms->DefineSection(3,-74.0,60.9,61.2);
306   //
307   tcms->DefineSection(4,-74.0,60.1,61.2);
308   tcms->DefineSection(5,-73.3,60.1,61.2);
309   //
310   tcms->DefineSection(6,-73.3,56.9,61.2);
311   tcms->DefineSection(7,-73.0,56.9,61.2);
312   //
313   tcms->DefineSection(8,-73.0,56.9,58.8);
314   tcms->DefineSection(9,-71.3,56.9,58.8);
315   //
316   TGeoVolume *v7 = new TGeoVolume("TPC_ICVM",tcms,m3);
317   //-----------------------------------------------
318   // inner containment vessel - shaft side
319   //-----------------------------------------------
320   TGeoPcon *tcss = new TGeoPcon(0.,360.,10);
321   //
322   tcss->DefineSection(0,71.3,56.9,58.8);
323   tcss->DefineSection(1,73.0,56.9,58.8);
324   //
325   tcss->DefineSection(2,73.0,56.9,61.2);
326   tcss->DefineSection(3,73.3,56.9,61.2);
327   //  
328   tcss->DefineSection(4,73.3,60.1,61.2);
329   tcss->DefineSection(5,74.0,60.1,61.2);
330   //
331   tcss->DefineSection(6,74.0,60.9,61.2);
332   tcss->DefineSection(7,253.6,65.6,65.9);
333   //
334   tcss->DefineSection(8,253.6,65.6,74.2);
335   tcss->DefineSection(9,258.1,65.6,74.2);
336   //
337   TGeoVolume *v8 = new TGeoVolume("TPC_ICVS",tcss,m3);
338   //-----------------------------------------------
339   //  Inner field cage
340   //  define 4 parts and make an assembly
341   //-----------------------------------------------
342   // part1 - Al - 2 copies
343   TGeoTube *t1 = new TGeoTube(76.6774,78.845,0.75);
344   TGeoVolume *tv1 = new TGeoVolume("TPC_IFC2",t1,m3);
345   // sandwich - outermost parts - 2 copies
346   TGeoTube *t2 = new TGeoTube(76.6774,78.845,74.175); // tedlar 38 microns
347   TGeoTube *t3 = new TGeoTube(76.6812,78.8412,74.175); // prepreg2 500 microns
348   TGeoTube *t4 = new TGeoTube(76.7312,78.7912,74.175); // prepreg3 300 microns
349   TGeoTube *t5 = new TGeoTube(76.7612,78.7612,74.175); // nomex 2 cm
350   //
351   TGeoVolume *tv2 = new TGeoVolume("TPC_IFC3",t2,sm2);
352   TGeoVolume *tv3 = new TGeoVolume("TPC_IFC4",t3,sm3);
353   TGeoVolume *tv4 = new TGeoVolume("TPC_IFC5",t4,sm5);
354   TGeoVolume *tv5 = new TGeoVolume("TPC_IFC6",t5,sm4);
355   //
356   // middle parts - 2 copies
357   TGeoTube *t6 = new TGeoTube(76.6774,78.795,5.); // tedlar 38 microns
358   TGeoTube *t7 = new TGeoTube(76.6812,78.7912,5.); // prepreg2 250 microns
359   TGeoTube *t8 = new TGeoTube(76.7062,78.7662,5.); // prepreg3 300 microns
360   TGeoTube *t9 = new TGeoTube(76.7362,78.7362,5.); // nomex 2 cm
361   //
362   TGeoVolume *tv6 = new TGeoVolume("TPC_IFC7",t6,sm2);
363   TGeoVolume *tv7 = new TGeoVolume("TPC_IFC8",t7,sm3);
364   TGeoVolume *tv8 = new TGeoVolume("TPC_IFC9",t8,sm5);
365   TGeoVolume *tv9 = new TGeoVolume("TPC_IFC10",t9,sm4);
366   // central part - 1 copy
367   TGeoTube *t10 = new TGeoTube(76.6774,78.745,93.75); // tedlar 38 microns 
368   TGeoTube *t11 = new TGeoTube(76.6812,78.7412,93.75); // prepreg3 300 microns
369   TGeoTube *t12 = new TGeoTube(76.7112,78.7112,93.75); // nomex 2 cm
370   //
371   TGeoVolume *tv10 = new TGeoVolume("TPC_IFC11",t10,sm2);
372   TGeoVolume *tv11 = new TGeoVolume("TPC_IFC12",t11,sm5);
373   TGeoVolume *tv12 = new TGeoVolume("TPC_IFC13",t12,sm4);
374   //
375   // inner part - positioning
376   //
377   // creating a sandwich
378   tv2->AddNode(tv3,1); tv3->AddNode(tv4,1); tv4->AddNode(tv5,1);
379   //
380   tv6->AddNode(tv7,1); tv7->AddNode(tv8,1); tv8->AddNode(tv9,1);
381   //
382   tv10->AddNode(tv11,1); tv11->AddNode(tv12,1);
383   //
384   TGeoVolumeAssembly *tv100 = new TGeoVolumeAssembly("TPC_IFC");
385   //
386   tv100->AddNode(tv10,1);
387   tv100->AddNode(tv6,1,new TGeoTranslation(0.,0.,-98.75));
388   tv100->AddNode(tv6,2,new TGeoTranslation(0.,0.,98.75));
389   tv100->AddNode(tv2,1,new TGeoTranslation(0.,0.,-177.925));
390   tv100->AddNode(tv2,2,new TGeoTranslation(0.,0.,177.925));
391   tv100->AddNode(tv1,1,new TGeoTranslation(0.,0.,-252.85));
392   tv100->AddNode(tv1,2,new TGeoTranslation(0.,0.,252.85));
393   //
394   v5->AddNode(v6,1, new TGeoTranslation(0.,0.,-252.1));
395   v5->AddNode(v6,2, new TGeoTranslation(0.,0.,252.1));
396   v1->AddNode(v5,1); v1->AddNode(v7,1); v1->AddNode(v8,1); 
397   v9->AddNode(tv100,1);
398   //
399   // central drum 
400   //
401   // flange + sandwich
402   //
403   TGeoPcon *cfl = new TGeoPcon(0.,360.,6);
404   cfl->DefineSection(0,-71.1,59.7,61.2);
405   cfl->DefineSection(1,-68.6,59.7,61.2);
406   //
407   cfl->DefineSection(2,-68.6,60.6324,61.2);
408   cfl->DefineSection(3,68.6,60.6324,61.2); 
409   //
410   cfl->DefineSection(4,68.6,59.7,61.2);
411   cfl->DefineSection(5,71.1,59.7,61.2);  
412   //
413   TGeoVolume *cflv = new TGeoVolume("TPC_CDR",cfl,m3);
414   // sandwich
415   TGeoTube *cd1 = new TGeoTube(60.6424,61.19,71.1);
416   TGeoTube *cd2 = new TGeoTube(60.6462,61.1862,71.1);
417   TGeoTube *cd3 = new TGeoTube(60.6662,61.1662,71.1);  
418   //
419   TGeoMedium *sm6 = gGeoManager->GetMedium("TPC_Prepreg1");
420   TGeoVolume *cd1v = new TGeoVolume("TPC_CDR1",cd1,sm2); //tedlar
421   TGeoVolume *cd2v = new TGeoVolume("TPC_CDR2",cd2,sm6);// prepreg1
422   TGeoVolume *cd3v = new TGeoVolume("TPC_CDR3",cd3,sm4); //nomex
423   //
424   // seals for central drum 2 copies
425   //
426   TGeoTube *cs = new TGeoTube(56.9,61.2,0.1);
427   TGeoMedium *sm7 = gGeoManager->GetMedium("TPC_Mylar");
428   TGeoVolume *csv = new TGeoVolume("TPC_CDRS",cs,sm7);
429   v1->AddNode(csv,1,new TGeoTranslation(0.,0.,-71.2));
430   v1->AddNode(csv,2,new TGeoTranslation(0.,0.,71.2));
431   //
432   // seal collars 
433   TGeoPcon *se = new TGeoPcon(0.,360.,6);
434   se->DefineSection(0,-72.8,59.7,61.2);
435   se->DefineSection(1,-72.3,59.7,61.2);
436   //
437   se->DefineSection(2,-72.3,58.85,61.2);
438   se->DefineSection(3,-71.6,58.85,61.2); 
439   //
440   se->DefineSection(4,-71.6,59.7,61.2);
441   se->DefineSection(5,-71.3,59.7,61.2);  
442   //
443   TGeoVolume *sev = new TGeoVolume("TPC_CDCE",se,m3);
444   //
445   TGeoTube *si = new TGeoTube(56.9,58.8,1.); 
446   TGeoVolume *siv = new TGeoVolume("TPC_CDCI",si,m3);
447   //
448   // define reflection matrix 
449   //
450   TGeoRotation *ref = new TGeoRotation("ref",90.,0.,90.,90.,180.,0.);
451   //
452   cd1v->AddNode(cd2v,1); cd2v->AddNode(cd3v,1); cflv->AddNode(cd1v,1);
453   //
454   v1->AddNode(siv,1,new TGeoTranslation(0.,0.,-69.9));
455   v1->AddNode(siv,2,new TGeoTranslation(0.,0.,69.9));
456   v1->AddNode(sev,1); v1->AddNode(sev,2,ref); v1->AddNode(cflv,1);
457   //
458   // central membrane - 2 rings and a mylar membrane - assembly
459   //
460   TGeoTube *ih = new TGeoTube(81.05,84.05,0.3);
461   TGeoTube *oh = new TGeoTube(250.,256.,.5);
462   TGeoTube *mem = new TGeoTube(84.05,250,0.01);
463   TGeoVolume *ihv = new TGeoVolume("TPC_IHVH",ih,m3);
464   TGeoVolume *ohv = new TGeoVolume("TPC_OHVH",oh,m3);
465   TGeoVolume *memv = new TGeoVolume("TPC_HV",mem,sm7);
466   //
467   TGeoVolumeAssembly *cm = new TGeoVolumeAssembly("TPC_HVMEM");
468   cm->AddNode(ihv,1);
469   cm->AddNode(ohv,1);
470   cm->AddNode(memv,1);
471   v9->AddNode(cm,1);
472   //
473   // end caps - they are make as an assembly of single segments
474   // containing both readout chambers
475   //
476   Double_t openingAngle = 10.*TMath::DegToRad();
477   Double_t thick=1.5; // rib
478   Double_t shift = thick/TMath::Sin(openingAngle);
479   //
480   Double_t lowEdge = 86.3; // hole in the wheel
481   Double_t upEdge = 240.4; // hole in the wheel
482   //
483   new TGeoTubeSeg("sec",74.5,264.4,3.,0.,20.);
484   //
485   TGeoPgon *hole = new TGeoPgon("hole",0.,20.,1,4);
486   //
487   hole->DefineSection(0,-3.5,lowEdge-shift,upEdge-shift);
488   hole->DefineSection(1,-1.5,lowEdge-shift,upEdge-shift);
489   //
490   hole->DefineSection(2,-1.5,lowEdge-shift,upEdge+3.-shift);
491   hole->DefineSection(3,3.5,lowEdge-shift,upEdge+3.-shift);
492   //
493   Double_t ys = shift*TMath::Sin(openingAngle); 
494   Double_t xs = shift*TMath::Cos(openingAngle);
495   TGeoTranslation *tr = new TGeoTranslation("tr",xs,ys,0.);  
496   tr->RegisterYourself();
497   TGeoCompositeShape *chamber = new TGeoCompositeShape("sec-hole:tr");
498   TGeoVolume *sv = new TGeoVolume("TPC_WSEG",chamber,m3);
499   TGeoPgon *bar = new TGeoPgon("bar",0.,20.,1,2);
500   bar->DefineSection(0,-3.,131.5-shift,136.5-shift);
501   bar->DefineSection(1,1.5,131.5-shift,136.5-shift);
502   TGeoVolume *barv = new TGeoVolume("TPC_WBAR",bar,m3);
503   TGeoVolumeAssembly *ch = new TGeoVolumeAssembly("TPC_WCH");//empty segment
504   //
505   ch->AddNode(sv,1); ch->AddNode(barv,1,tr);
506   //
507   // readout chambers
508   //
509   // IROC first
510   //
511    TGeoTrd1 *ibody = new TGeoTrd1(13.8742,21.3328,4.29,21.15);
512    TGeoVolume *ibdv = new TGeoVolume("TPC_IROCB",ibody,m3);
513   // empty space
514    TGeoTrd1 *emp = new TGeoTrd1(12.3742,19.8328,3.99,19.65);
515    TGeoVolume *empv = new TGeoVolume("TPC_IROCE",emp,m1);
516    ibdv->AddNode(empv,1,new TGeoTranslation(0.,-0.3,0.));
517    //bars
518    Double_t tga = (19.8328-12.3742)/39.3;
519    Double_t xmin,xmax;
520    xmin = 9.55*tga+12.3742;
521    xmax = 9.95*tga+12.3742;
522    TGeoTrd1 *ib1 = new TGeoTrd1(xmin,xmax,3.29,0.2);
523    TGeoVolume *ib1v = new TGeoVolume("TPC_IRB1",ib1,m3);
524    empv->AddNode(ib1v,1,new TGeoTranslation("tt1",0.,0.7,-9.9));
525    xmin=19.4*tga+12.3742;
526    xmax=19.9*tga+12.3742;
527    TGeoTrd1 *ib2 = new TGeoTrd1(xmin,xmax,3.29,0.25);
528    TGeoVolume *ib2v = new TGeoVolume("TPC_TRB2",ib2,m3);
529    empv->AddNode(ib2v,1,new TGeoTranslation(0.,0.7,0.));
530    xmin=29.35*tga+12.3742;
531    xmax=29.75*tga+12.3742;
532    TGeoTrd1 *ib3 = new TGeoTrd1(xmin,xmax,3.29,0.2); 
533    TGeoVolume *ib3v = new TGeoVolume("TPC_IRB3",ib3,m3);    
534    empv->AddNode(ib3v,1,new TGeoTranslation(0.,0.7,9.9));
535    //
536    // holes for connectors
537    //
538    TGeoBBox *conn = new TGeoBBox(0.4,0.3,4.675); // identical for iroc and oroc
539    TGeoVolume *connv = new TGeoVolume("TPC_RCCON",conn,m1);
540    TString fileName(gSystem->Getenv("ALICE_ROOT"));
541    fileName += "/TPC/conn_iroc.dat";
542    ifstream in;
543    in.open(fileName.Data(), ios_base::in); // asci file
544    for(Int_t i =0;i<86;i++){
545       Double_t y = 3.99;
546       Double_t x,z,ang;
547       in>>x>>z>>ang;
548       z-=26.5;
549       TGeoRotation *rrr = new TGeoRotation();
550       rrr->RotateY(ang);
551       TGeoCombiTrans *trans = new TGeoCombiTrans("trans",x,y,z,rrr);
552       ibdv->AddNode(connv,i+1,trans);
553    }
554    in.close();
555    // "cap"
556    new TGeoTrd1("icap",14.5974,23.3521,1.19,24.825);
557    // "hole"
558    new TGeoTrd1("ihole",13.8742,21.3328,1.2,21.15);
559    TGeoTranslation *tr1 = new TGeoTranslation("tr1",0.,0.,1.725);  
560    tr1->RegisterYourself();
561    TGeoCompositeShape *ic = new TGeoCompositeShape("icap-ihole:tr1");
562    TGeoVolume *icv = new TGeoVolume("TPC_IRCAP",ic,m3);
563    //
564    // pad plane and wire fixations
565    //
566    TGeoTrd1 *pp = new TGeoTrd1(14.5974,23.3521,0.3,24.825); //pad+iso
567    TGeoMedium *m4 = gGeoManager->GetMedium("TPC_G10");
568    TGeoVolume *ppv = new TGeoVolume("TPC_IRPP",pp,m4);
569    TGeoPara *f1 = new TGeoPara(.6,.5,24.825,0.,-10.,0.);
570    TGeoVolume *f1v = new TGeoVolume("TPC_IRF1",f1,m4);
571    TGeoPara *f2 = new TGeoPara(.6,.5,24.825,0.,10.,0.);
572    TGeoVolume *f2v = new TGeoVolume("TPC_IRF2",f2,m4);
573    //
574    TGeoVolumeAssembly *iroc = new TGeoVolumeAssembly("TPC_IROC");
575    //
576    iroc->AddNode(ibdv,1);
577    iroc->AddNode(icv,1,new TGeoTranslation(0.,3.1,-1.725));
578    iroc->AddNode(ppv,1,new TGeoTranslation(0.,4.59,-1.725));
579    tga =(23.3521-14.5974)/49.65; 
580    Double_t xx = 24.825*tga+14.5974-0.6;
581    iroc->AddNode(f1v,1,new TGeoTranslation(-xx,5.39,-1.725));
582    iroc->AddNode(f2v,1,new TGeoTranslation(xx,5.39,-1.725));
583    //
584    // OROC
585    //
586    TGeoTrd1 *obody = new TGeoTrd1(22.2938,40.5084,4.19,51.65);
587    TGeoVolume *obdv = new TGeoVolume("TPC_OROCB",obody,m3);
588    TGeoTrd1 *oemp = new TGeoTrd1(20.2938,38.5084,3.89,49.65);
589    TGeoVolume *oempv = new TGeoVolume("TPC_OROCE",oemp,m1);
590    obdv->AddNode(oempv,1,new TGeoTranslation(0.,-0.3,0.));
591    //horizontal bars
592    tga=(38.5084-20.2938)/99.3;
593    xmin=tga*10.2+20.2938;
594    xmax=tga*10.6+20.2938;
595    TGeoTrd1 *ob1 = new TGeoTrd1(xmin,xmax,2.915,0.2);
596    TGeoVolume *ob1v = new TGeoVolume("TPC_ORB1",ob1,m3);
597    //
598    xmin=22.55*tga+20.2938;
599    xmax=24.15*tga+20.2938;
600    TGeoTrd1 *ob2 = new TGeoTrd1(xmin,xmax,2.915,0.8);
601    TGeoVolume *ob2v = new TGeoVolume("TPC_ORB2",ob2,m3);
602    //
603    xmin=36.1*tga+20.2938;
604    xmax=36.5*tga+20.2938;
605    TGeoTrd1 *ob3 = new TGeoTrd1(xmin,xmax,2.915,0.2);
606    TGeoVolume *ob3v = new TGeoVolume("TPC_ORB3",ob3,m3);
607    //
608    xmin=49.0*tga+20.2938;
609    xmax=50.6*tga+20.2938;   
610    TGeoTrd1 *ob4 = new TGeoTrd1(xmin,xmax,2.915,0.8);
611    TGeoVolume *ob4v = new TGeoVolume("TPC_ORB4",ob4,m3);
612    //
613    xmin=63.6*tga+20.2938;
614    xmax=64.0*tga+20.2938;
615    TGeoTrd1 *ob5 = new TGeoTrd1(xmin,xmax,2.915,0.2);
616    TGeoVolume *ob5v = new TGeoVolume("TPC_ORB5",ob5,m3);
617    //
618    xmin=75.5*tga+20.2938;
619    xmax=77.15*tga+20.2938;
620    TGeoTrd1 *ob6 = new TGeoTrd1(xmin,xmax,2.915,0.8);
621    TGeoVolume *ob6v = new TGeoVolume("TPC_ORB6",ob6,m3);
622    //
623    xmin=88.7*tga+20.2938;
624    xmax=89.1*tga+20.2938;
625    TGeoTrd1 *ob7 = new TGeoTrd1(xmin,xmax,2.915,0.2);
626    TGeoVolume *ob7v = new TGeoVolume("TPC_ORB7",ob7,m3);
627    //
628    oempv->AddNode(ob1v,1,new TGeoTranslation(0.,0.975,-39.25));
629    oempv->AddNode(ob2v,1,new TGeoTranslation(0.,0.975,-26.3));
630    oempv->AddNode(ob3v,1,new TGeoTranslation(0.,0.975,-13.35));
631    oempv->AddNode(ob4v,1,new TGeoTranslation(0.,0.975,0.15));
632    oempv->AddNode(ob5v,1,new TGeoTranslation(0.,0.975,14.15));
633    oempv->AddNode(ob6v,1,new TGeoTranslation(0.,0.975,26.7));
634    oempv->AddNode(ob7v,1,new TGeoTranslation(0.,0.975,39.25));
635    // vertical bars
636    TGeoBBox *ob8 = new TGeoBBox(0.8,2.915,5.1); 
637    TGeoBBox *ob9 = new TGeoBBox(0.8,2.915,5.975);
638    TGeoBBox *ob10 = new TGeoBBox(0.8,2.915,5.775);
639    TGeoBBox *ob11 = new TGeoBBox(0.8,2.915,6.25);
640    TGeoBBox *ob12 = new TGeoBBox(0.8,2.915,6.5);
641    //
642    TGeoVolume *ob8v = new TGeoVolume("TPC_ORB8",ob8,m3);
643    TGeoVolume *ob9v = new TGeoVolume("TPC_ORB9",ob9,m3);
644    TGeoVolume *ob10v = new TGeoVolume("TPC_ORB10",ob10,m3);
645    TGeoVolume *ob11v = new TGeoVolume("TPC_ORB11",ob11,m3);
646    TGeoVolume *ob12v = new TGeoVolume("TPC_ORB12",ob12,m3);
647    //
648    oempv->AddNode(ob8v,1,new TGeoTranslation(0.,0.975,-44.55));
649    oempv->AddNode(ob8v,2,new TGeoTranslation(0.,0.975,44.55));
650    oempv->AddNode(ob9v,1,new TGeoTranslation(0.,0.975,-33.075));
651    oempv->AddNode(ob9v,2,new TGeoTranslation(0.,0.975,-19.525));
652    oempv->AddNode(ob10v,1,new TGeoTranslation(0.,0.975,20.125));
653    oempv->AddNode(ob10v,2,new TGeoTranslation(0.,0.975,33.275));
654    oempv->AddNode(ob11v,1,new TGeoTranslation(0.,0.975,-6.9));
655    oempv->AddNode(ob12v,1,new TGeoTranslation(0.,0.975,7.45));
656    //
657    // holes for connectors
658    //
659    fileName = gSystem->Getenv("ALICE_ROOT");
660    fileName += "/TPC/conn_oroc.dat";
661    in.open(fileName.Data(), ios_base::in); // asci file
662    for(Int_t i =0;i<78;i++){
663       Double_t y =3.89;
664       Double_t x,z,ang;
665       Double_t x1,z1,x2,z2;
666       in>>x>>z>>ang;        
667       Double_t xr = 4.7*TMath::Sin(ang*TMath::DegToRad());
668       Double_t zr = 4.7*TMath::Cos(ang*TMath::DegToRad());
669       //
670       x1=xr+x; x2=-xr+x; z1=zr+z; z2 = -zr+z;      
671       //
672       TGeoRotation *rr = new TGeoRotation();
673       rr->RotateY(ang); 
674       z1-=54.95;
675       z2-=54.95;
676       TGeoCombiTrans *trans1 = new TGeoCombiTrans("trans1",x1,y,z1,rr);
677       TGeoCombiTrans *trans2 = new TGeoCombiTrans("trans2",x2,y,z2,rr);
678       obdv->AddNode(connv,i+1,trans1);
679       obdv->AddNode(connv,i+79,trans2);
680    }
681    in.close();
682    // cap
683    new TGeoTrd1("ocap",23.3874,43.5239,1.09,57.1);
684    new TGeoTrd1("ohole",22.2938,40.5084,1.09,51.65);
685    TGeoTranslation *tr5 = new TGeoTranslation("tr5",0.,0.,-2.15);
686    tr5->RegisterYourself();
687    TGeoCompositeShape *oc = new TGeoCompositeShape("ocap-ohole:tr5");
688    TGeoVolume *ocv = new TGeoVolume("TPC_ORCAP",oc,m3);
689    //
690    // pad plane and wire fixations
691    //
692    TGeoTrd1 *opp = new TGeoTrd1(23.3874,43.5239,0.3,57.1);
693    TGeoVolume *oppv = new TGeoVolume("TPC_ORPP",opp,m4);
694    //
695    tga=(43.5239-23.3874)/114.2;
696    TGeoPara *f3 = new TGeoPara(.7,.6,57.1,0.,-10.,0.);
697    TGeoPara *f4 = new TGeoPara(.7,.6,57.1,0.,10.,0.);  
698    xx = 57.1*tga+23.3874-0.7;
699    TGeoVolume *f3v = new TGeoVolume("TPC_ORF1",f3,m4);
700    TGeoVolume *f4v = new TGeoVolume("TPC_ORF2",f4,m4);
701    //
702    TGeoVolumeAssembly *oroc = new TGeoVolumeAssembly("TPC_OROC");
703    //
704    oroc->AddNode(obdv,1);
705    oroc->AddNode(ocv,1,new TGeoTranslation(0.,3.1,2.15));
706    oroc->AddNode(oppv,1,new TGeoTranslation(0.,4.49,2.15));
707    oroc->AddNode(f3v,1,new TGeoTranslation(-xx,5.39,2.15));
708    oroc->AddNode(f4v,1,new TGeoTranslation(xx,5.39,2.15));
709    // 
710    // now iroc and oroc are placed into a sector...
711    //
712    TGeoVolumeAssembly *secta = new TGeoVolumeAssembly("TPC_SECT"); // a-side
713    TGeoVolumeAssembly *sectc = new TGeoVolumeAssembly("TPC_SECT"); // c-side
714    TGeoRotation rot1("rot1",90.,90.,0.);
715    TGeoRotation rot2("rot2");
716    rot2.RotateY(10.);
717    TGeoRotation *rot = new TGeoRotation("rot");
718    *rot=rot1*rot2;
719    //
720    Double_t x0,y0;
721    x0=110.2*TMath::Cos(openingAngle);
722    y0=110.2*TMath::Sin(openingAngle);
723    TGeoCombiTrans *combi1a = new TGeoCombiTrans("combi1",x0,y0,1.09+0.195,rot); //a-side 
724    TGeoCombiTrans *combi1c = new TGeoCombiTrans("combi1",x0,y0,1.09+0.222,rot); //c-side
725    x0=188.45*TMath::Cos(openingAngle);
726    y0=188.45*TMath::Sin(openingAngle);
727    TGeoCombiTrans *combi2a = new TGeoCombiTrans("combi2",x0,y0,0.99+0.195,rot); //a-side
728    TGeoCombiTrans *combi2c = new TGeoCombiTrans("combi2",x0,y0,0.99+0.222,rot); //c-side
729    //
730    // A-side
731    //
732    secta->AddNode(ch,1);
733    secta->AddNode(iroc,1,combi1a);
734    secta->AddNode(oroc,1,combi2a);
735    //
736    // C-side
737    //
738    sectc->AddNode(ch,1);
739    sectc->AddNode(iroc,1,combi1c);
740    sectc->AddNode(oroc,1,combi2c);
741    //
742    // now I try to make  wheels...
743    //
744    TGeoVolumeAssembly *wheela = new TGeoVolumeAssembly("TPC_ENDCAP");
745    TGeoVolumeAssembly *wheelc = new TGeoVolumeAssembly("TPC_ENDCAP");
746    //
747    for(Int_t i =0;i<18;i++){
748      Double_t phi = (20.*i);
749      TGeoRotation *r = new TGeoRotation();
750      r->RotateZ(phi);
751      wheela->AddNode(secta,i+1,r);
752      wheelc->AddNode(sectc,i+1,r);
753     
754    }
755    // wheels in the drift volume!
756    TGeoCombiTrans *combi3 = new TGeoCombiTrans("combi3",0.,0.,256.6,ref);
757    v9->AddNode(wheela,1,combi3);
758    v9->AddNode(wheelc,2,new TGeoTranslation(0.,0.,-256.6));
759    
760    //_____________________________________________________________
761    // service support wheel
762    //_____________________________________________________________
763   TGeoPgon *sw = new TGeoPgon(0.,20.,1,2);
764   sw->DefineSection(0,-4.,80.5,251.75);
765   sw->DefineSection(1,4.,80.5,251.75); 
766   TGeoVolume *swv = new TGeoVolume("TPC_SWSEG",sw,m3); //Al
767   //
768   thick=1.;
769   shift = thick/TMath::Sin(openingAngle);
770   TGeoPgon *sh = new TGeoPgon(0.,20.,1,2);
771   sh->DefineSection(0,-4.,81.5-shift,250.75-shift);
772   sh->DefineSection(1,4.,81.5-shift,250.75-shift);
773   TGeoVolume *shv = new TGeoVolume("TPC_SWS1",sh,m1); //Air
774   //
775   TGeoMedium *m9 =  gGeoManager->GetMedium("TPC_Si"); 
776   TGeoPgon *el = new TGeoPgon(0.,20.,1,2);
777   el->DefineSection(0,-1.872,81.5-shift,250.75-shift);
778   el->DefineSection(1,1.872,81.5-shift,250.75-shift);
779   TGeoVolume *elv = new TGeoVolume("TPC_ELEC",el,m9); //Si 
780   //
781   shv->AddNode(elv,1);
782   //
783   ys = shift*TMath::Sin(openingAngle);
784   xs = shift*TMath::Cos(openingAngle);
785   swv->AddNode(shv,1,new TGeoTranslation(xs,ys,0.));
786   // cover
787   TGeoPgon *co = new TGeoPgon(0.,20.,1,2);
788   co->DefineSection(0,-0.5,77.,255.25);
789   co->DefineSection(1,0.5,77.,255.25);
790   TGeoVolume *cov = new TGeoVolume("TPC_SWC1",co,m3);//Al
791   // hole in a cover
792   TGeoPgon *coh = new TGeoPgon(0.,20.,1,2);
793   shift=4./TMath::Sin(openingAngle);
794   coh->DefineSection(0,-0.5,85.-shift,247.25-shift);
795   coh->DefineSection(1,0.5,85.-shift,247.25-shift);  
796   //
797   TGeoVolume *cohv = new TGeoVolume("TPC_SWC2",coh,m1);
798   //
799   ys = shift*TMath::Sin(openingAngle);
800   xs = shift*TMath::Cos(openingAngle);  
801   cov->AddNode(cohv,1,new TGeoTranslation(xs,ys,0.));
802   //
803   // Sector as an Assembly
804   //
805   TGeoVolumeAssembly *swhs = new TGeoVolumeAssembly("TPC_SSWSEC");
806   swhs->AddNode(swv,1);
807   swhs->AddNode(cov,1,new TGeoTranslation(0.,0.,-4.5));
808   swhs->AddNode(cov,2,new TGeoTranslation(0.,0.,4.5));
809   //
810   // SSW as an Assembly of sectors
811   //
812  TGeoVolumeAssembly *swheel = new TGeoVolumeAssembly("TPC_SSWHEEL");
813    for(Int_t i =0;i<18;i++){
814      Double_t phi = (20.*i);
815      TGeoRotation *r = new TGeoRotation();
816      r->RotateZ(phi);
817      swheel->AddNode(swhs,i+1,r);   
818    }
819    v1->AddNode(swheel,1,new TGeoTranslation(0.,0.,-284.6));
820    v1->AddNode(swheel,2,new TGeoTranslation(0.,0.,284.6));
821    //
822   //----------------------------------------------------------
823   // TPc Support Rods - MAKROLON
824   //----------------------------------------------------------
825   TGeoMedium *m6=gGeoManager->GetMedium("TPC_Makrolon");
826   TGeoMedium *m7=gGeoManager->GetMedium("TPC_Cu");
827   TGeoMedium *m10 =  gGeoManager->GetMedium("TPC_Alumina");
828   TGeoMedium *m11 =  gGeoManager->GetMedium("TPC_Peek");
829   TGeoMedium *m12 =  gGeoManager->GetMedium("TPC_Water");
830   // upper and lower rods differ in length!
831   Double_t *upar;
832   upar=NULL;
833   gGeoManager->Volume("TPC_Rod","TUBE",m6->GetId(),upar);
834   upar=new Double_t [3];
835   upar[0]=1.8;
836   upar[1]=2.2;
837   
838   //
839   //HV rods - makrolon + 0.58cm (diameter) Cu
840   TGeoTube *hvr = new TGeoTube(0.,2.2,126.64);
841   TGeoTube *hvc = new TGeoTube(0.,0.29,126.64);
842   //
843   TGeoVolume *hvrv = new TGeoVolume("TPC_HV_Rod",hvr,m6);
844   TGeoVolume *hvcv = new TGeoVolume("TPC_HV_Cable",hvc,m7);
845   hvrv->AddNode(hvcv,1);
846   //
847   // resistor rods
848   //
849   TGeoTube *cri = new TGeoTube(0.,0.45,126.64); //inner 
850   TGeoTube *cro = new TGeoTube(0.,0.45,126.54); //outer 
851   TGeoTube *cwi = new TGeoTube(0.,0.15,126.64); // water inner
852   TGeoTube *cwo = new TGeoTube(0.,0.15,126.54); // water outer
853   //
854   TGeoVolume *criv = new TGeoVolume("TPC_CR_I",cri,m10);
855   TGeoVolume *crov = new TGeoVolume("TPC_CR_O",cro,m10);    
856   TGeoVolume *cwiv = new TGeoVolume("TPC_W_I",cwi,m11);
857   TGeoVolume *cwov = new TGeoVolume("TPC_W_O",cwo,m11);   
858   //
859   // ceramic rod with water
860   //
861   criv->AddNode(cwiv,1); 
862   crov->AddNode(cwov,1);
863   //
864   TGeoTube *pri =new TGeoTube(0.2,0.35,126.64); //inner 
865   TGeoTube *pro = new TGeoTube(0.2,0.35,126.54); //outer    
866   //
867   // peek rod
868   //
869   TGeoVolume *priv = new TGeoVolume("TPC_PR_I",pri,m12);
870   TGeoVolume *prov = new TGeoVolume("TPC_PR_O",pro,m12); 
871   //
872   // resistor rods assembly
873   //
874    TGeoRotation *rotr = new TGeoRotation("rotr");
875    rotr->RotateZ(-21.);
876   //
877   TGeoTube *rri = new TGeoTube(1.8,2.2,126.64);//inner
878   TGeoTube *rro = new TGeoTube(1.8,2.2,126.54);//inner
879   //
880   TGeoVolume *rriv = new TGeoVolume("TPC_RR_I",rri,m6);
881   TGeoVolume *rrov = new TGeoVolume("TPC_RR_O",rro,m6);  
882   //
883   TGeoVolumeAssembly *rrin = new TGeoVolumeAssembly("TPC_RROD_I");
884   TGeoVolumeAssembly *rrou = new TGeoVolumeAssembly("TPC_RROD_O");
885   rrin->AddNode(rriv,1);
886   rrin->AddNode(criv,1,new TGeoTranslation(0.5,0.866, 0.));
887   rrin->AddNode(criv,2,new TGeoTranslation(0.5,-0.866, 0.)); 
888   rrin->AddNode(priv,1); 
889   //
890   rrou->AddNode(rrov,1);
891   rrou->AddNode(crov,1,new TGeoTranslation(0.5,0.866, 0.));
892   rrou->AddNode(crov,2,new TGeoTranslation(0.5,-0.866, 0.)); 
893   rrou->AddNode(prov,1);
894   for(Int_t i=0;i<18;i++){
895     Double_t angle,x,y;
896     Double_t z,r; 
897     angle=TMath::DegToRad()*20.*(Double_t)i;
898     r=81.5;
899     x=r * TMath::Cos(angle);
900     y=r * TMath::Sin(angle);
901     upar[2]=126.64; //lower
902     z= 126.96;
903     //
904     if(i==3){
905       v9->AddNode(rrin,1,new TGeoCombiTrans(x,y,z,rotr)); //A
906       v9->AddNode(rrin,2,new TGeoCombiTrans(x,y,-z,rotr)); //C 
907     } 
908     else { 
909       gGeoManager->Node("TPC_Rod",i+1,"TPC_Drift",x,y,z,0,kTRUE,upar,3);//shaft
910       gGeoManager->Node("TPC_Rod",i+19,"TPC_Drift",x,y,-z,0,kTRUE,upar,3);//muon
911     }
912    
913
914     //
915     r=254.25;
916     x=r * TMath::Cos(angle);
917     y=r * TMath::Sin(angle);
918     upar[2]=126.54; //upper
919     z=127.06;
920     if(i==15){
921       //v9->AddNode(hvrv,1,new TGeoTranslation(x,y,z));//A-side only
922       v9->AddNode(hvrv,1,new TGeoTranslation(x,y,127.14));//A-side only
923       gGeoManager->Node("TPC_Rod",i+55,"TPC_Drift",x,y,-z,0,kTRUE,upar,3);
924     }
925     else if(i==11){
926       v9->AddNode(rrou,1,new TGeoCombiTrans(x,y,z,rotr)); //A
927       v9->AddNode(rrou,2,new TGeoCombiTrans(x,y,-z,rotr)); //C
928     }
929     else{
930     //
931       gGeoManager->Node("TPC_Rod",i+37,"TPC_Drift",x,y,z,0,kTRUE,upar,3);
932       gGeoManager->Node("TPC_Rod",i+55,"TPC_Drift",x,y,-z,0,kTRUE,upar,3);
933     }
934   }
935
936   TGeoVolume *alice = gGeoManager->GetVolume("ALIC");
937   alice->AddNode(v1,1);
938   
939
940  
941 } // end of function
942  
943
944 //_____________________________________________________________________________
945 void AliTPCv3::CreateMaterials()
946 {
947   //
948   // Define materials for version 2 of the Time Projection Chamber
949   //
950
951
952   //
953   AliTPC::CreateMaterials();
954 }
955
956 //_____________________________________________________________________________
957 void AliTPCv3::Init()
958 {
959   //
960   // Initialises version 3 of the TPC after that it has been built
961   //
962   //Int_t *idtmed = fIdtmed->GetArray();
963
964   AliTPC::Init();
965
966    fIdSens=gMC->VolId("TPC_Drift"); // drift gas as a sensitive volume
967
968   gMC->SetMaxNStep(-30000); // max. number of steps increased
969
970   // specific energy loss is now set in galice.cuts
971
972   printf("%s: *** TPC version 3 initialized***\n",ClassName());
973
974   printf("%s: Maximum number of steps = %d\n",ClassName(),gMC->GetMaxNStep());
975
976   // printf("*** TPC version 3 initialized ***\n");
977   // printf("Maximum number of steps = %d\n",gMC->GetMaxNStep());
978
979   //
980   
981 }
982
983 //_____________________________________________________________________________
984 void AliTPCv3::StepManager()
985 {
986   //
987   // Called for every step in the Time Projection Chamber
988   //
989
990   //
991   // parameters used for the energy loss calculations
992   //
993   const Float_t kprim = 14.35; // number of primary collisions per 1 cm
994   const Float_t kpoti = 20.77e-9; // first ionization potential for Ne/CO2
995   const Float_t kwIon = 35.97e-9; // energy for the ion-electron pair creation 
996  
997  
998   const Float_t kbig = 1.e10;
999
1000   Int_t id,copy;
1001   TLorentzVector pos;
1002   Float_t hits[5];
1003   Int_t vol[2];  
1004   
1005   vol[1]=0;
1006   vol[0]=0;
1007
1008   //
1009
1010   gMC->SetMaxStep(kbig);
1011   
1012   if(!gMC->IsTrackAlive()) return; // particle has disappeared
1013   
1014   Float_t charge = gMC->TrackCharge();
1015   
1016   if(TMath::Abs(charge)<=0.) return; // take only charged particles
1017   
1018   
1019   id=gMC->CurrentVolID(copy);
1020
1021   
1022   if (id != fIdSens) return;
1023   
1024   //
1025   //  charged particle is in the sensitive volume
1026   //
1027   
1028   if(gMC->TrackStep() > 0) {
1029
1030     
1031     Int_t nel = (Int_t)(((gMC->Edep())-kpoti)/kwIon) + 1;
1032     nel=TMath::Min(nel,300); // 300 electrons corresponds to 10 keV
1033     
1034     gMC->TrackPosition(pos);
1035     hits[0]=pos[0];
1036     hits[1]=pos[1];
1037     hits[2]=pos[2];
1038
1039     // Get also the track time for pileup simulation
1040     hits[4]=gMC->TrackTime();
1041
1042     //
1043     // check the selected side of the TPC
1044     //
1045  
1046     if(fSide && fSide*hits[2]<=0.) return;
1047
1048     hits[3]=(Float_t)nel;
1049     
1050     // Add this hit
1051    
1052     AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol,hits);  //MI change
1053     
1054   } 
1055   
1056   // Stemax calculation for the next step
1057   
1058   Float_t pp;
1059   TLorentzVector mom;
1060   gMC->TrackMomentum(mom);
1061   Float_t ptot=mom.Rho();
1062   Float_t betaGamma = ptot/gMC->TrackMass();
1063   
1064   Int_t pid=gMC->TrackPid();
1065   if((pid==kElectron || pid==kPositron) && ptot > 0.002)
1066     { 
1067       pp = kprim*1.58; // electrons above 20 MeV/c are on the plateau!
1068     }
1069   else
1070     {
1071       betaGamma = TMath::Max(betaGamma,(Float_t)7.e-3); 
1072       pp=kprim*AliMathBase::BetheBlochAleph(betaGamma);    
1073       if(TMath::Abs(charge) > 1.) pp *= (charge*charge);
1074     }
1075   
1076   Double_t rnd = gMC->GetRandom()->Rndm();
1077   
1078   gMC->SetMaxStep(-TMath::Log(rnd)/pp);
1079   
1080 }