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