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