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