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