]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCv3.cxx
update info about cvs installation using cvs account
[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 /*
17 $Log$
18 Revision 1.14  2000/06/30 12:07:50  kowal2
19 Updated from the TPC-PreRelease branch
20
21 Revision 1.13.2.4  2000/06/26 07:39:42  kowal2
22 Changes to obey the coding rules
23
24 Revision 1.13.2.3  2000/06/25 08:38:41  kowal2
25 Splitted from AliTPCtracking
26
27 Revision 1.13.2.2  2000/06/16 12:58:13  kowal2
28 Changed parameter settings
29
30 Revision 1.13.2.1  2000/06/09 07:15:07  kowal2
31
32 Defaults loaded automatically (hard-wired)
33 Optional parameters can be set via macro called in the constructor
34
35 Revision 1.13  2000/05/15 10:00:30  kowal2
36 Corrected bug in the TPC geometry, thanks to Ivana Hrivnacova
37
38 Revision 1.12  2000/04/17 09:37:33  kowal2
39 removed obsolete AliTPCDigitsDisplay.C
40
41 Revision 1.11.8.2  2000/04/10 08:36:12  kowal2
42
43 Updated readout chambers
44 Some modifications to StepManager by M. Kowalski
45
46 Revision 1.11.8.1  2000/04/10 07:56:53  kowal2
47 Not used anymore - removed
48
49 Revision 1.11  1999/11/04 17:28:07  fca
50 Correct barrel part of HV Degrader
51
52 Revision 1.10  1999/10/14 16:52:08  fca
53 Only use PDG codes and not GEANT ones
54
55 Revision 1.9  1999/10/08 06:27:23  fca
56 Corrected bug in the HV degrader geometry, thanks to G.Tabary
57
58 Revision 1.8  1999/10/04 13:39:55  fca
59 Correct array index problem
60
61 Revision 1.7  1999/09/29 09:24:34  fca
62 Introduction of the Copyright and cvs Log
63
64 */
65
66 //
67 ///////////////////////////////////////////////////////////////////////////////
68 //                                                                           //
69 //  Time Projection Chamber version 3 -- detailed TPC and slow simulation    //
70 //                                                                     
71 //Begin_Html
72 /*
73 <img src="picts/AliTPCv3Class.gif">
74 */
75 //End_Html
76 //                                                                           //
77 //                                                                           //
78 ///////////////////////////////////////////////////////////////////////////////
79
80 #include <stdlib.h>
81 #include <TMath.h>
82 #include "AliTPCv3.h"
83 #include "AliRun.h"
84 #include "AliConst.h"
85 #include "AliTPCDigitsArray.h"
86 #include"AliTPCParam.h"
87 #include"AliTPCParamSR.h"
88 #include "AliPDG.h"
89 #include <TInterpreter.h>
90
91 ClassImp(AliTPCv3)
92  
93 //_____________________________________________________________________________
94 AliTPCv3::AliTPCv3(const char *name, const char *title) :
95   AliTPC(name, title) 
96 {
97   //
98   // Standard constructor for Time Projection Chamber version 3
99   //
100
101   SetBufferSize(128000);
102   fIdSens=0;
103
104   SetGasMixt(2,20,10,-1,0.9,0.1,0.);
105
106   if (fTPCParam)
107      fTPCParam->Write(fTPCParam->GetTitle());
108 }
109  
110 //_____________________________________________________________________________
111 void AliTPCv3::CreateGeometry()
112 {
113   //
114   // Creation of the TPC coarse geometry (version 3)
115   // The whole drift volume is sensitive
116   // Origin Marek Kowalski Cracow
117   //
118   //Begin_Html
119   /*
120     <img src="picts/AliTPCgif">
121   */
122   //End_Html
123   //Begin_Html
124   /*
125     <img src="picts/AliTPCv3Tree.gif">
126   */
127   //End_Html
128   Float_t dm[50];
129
130   Int_t *idtmed = fIdtmed->GetArray(); // TPC media
131
132   Int_t idrotm[120]; // rotation matrices
133
134   Int_t nRotMat = 0; // actual number of rotation matrices
135
136
137   //
138   //  Mother volume (Air) - all volumes will be positioned in it
139   //
140   
141   dm[0]=0.;
142   dm[1]=360.;
143   dm[2]=12.;
144
145   //
146  
147   dm[3]= -283.7;
148   dm[4]= 66.2;
149   dm[5]= 277.95;
150
151   //
152
153   dm[6]= -255.6;
154   dm[7]= 66.2;
155   dm[8]= 277.95;
156
157   //
158
159   dm[9]= -73.3;
160   dm[10]= 59.0;
161   dm[11]= 277.95;
162
163   //
164
165   dm[12]= -73.3;
166   dm[13]= 56.9;
167   dm[14]= 277.95;
168
169   //
170
171   dm[15]= -72.1;
172   dm[16]= 56.9;
173   dm[17]= 277.95;
174
175   //
176
177   dm[18]= -72.1;
178   dm[19]= 60.65;
179   dm[20]= 277.95;
180
181   //
182
183   dm[21]= 72.1;
184   dm[22]= 60.65;
185   dm[23]= 277.95;  
186
187   //
188
189   dm[24]= 72.1;
190   dm[25]= 56.9;
191   dm[26]= 277.95;
192
193   //
194
195   dm[27]= 73.3;
196   dm[28]= 56.9;
197   dm[29]= 277.95;
198
199   //
200
201   dm[30]= 73.3;
202   dm[31]= 60.65;
203   dm[32]= 277.95;
204
205   //
206
207   dm[33]= 250.4;
208   dm[34]= 66.0;
209   dm[35]= 277.95;
210
211   //
212
213   dm[36]= 283.7;
214   dm[37]= 66.0;
215   dm[38]= 277.95;
216
217
218   gMC->Gsvolu("TPC ","PCON",idtmed[0],dm,39);
219
220
221   //-------------------------------------------------------------------
222   //  Tpc Outer INsulator (CO2)
223   //-------------------------------------------------------------------
224
225   dm[0]= 0.;
226   dm[1]= 360.;
227   dm[2]= 6.;
228
229   //
230  
231   dm[3]= -253.6;
232   dm[4]= 258.;
233   dm[5]= 266.65;
234
235   //
236
237   dm[6]= -253.;
238   dm[7]= 258.;
239   dm[8]= 266.65;
240
241   dm[9]= -253.;
242   dm[10]= 258.;
243   dm[11]= 277.97;
244
245   dm[12]= 253.6;
246   dm[13]= 258.;
247   dm[14]= 277.97;
248
249   //
250
251   dm[15]= 253.6;
252   dm[16]= 265.2;
253   dm[17]= 277.95;
254
255   //
256
257   dm[18]= 255.6;
258   dm[19]= 265.2;
259   dm[20]= 277.95;
260
261
262   gMC->Gsvolu("TOIN","PCON",idtmed[3],dm,21);
263
264   //---------------------------------------------------------------
265   // shreds (G10) - TPC Rings
266   //---------------------------------------------------------------
267
268   gMC->Gsvolu("TPCR","TUBE",idtmed[12],dm,0);
269
270   dm[0]= 258.;
271   dm[1]= 266.65;
272   dm[2]= 0.3;
273
274   gMC->Gsposp("TPCR",1,"TOIN",0.,0.,-253.3,0,"ONLY",dm,3); // left bottom
275
276   //
277
278   dm[0]= 258.;
279   dm[1]= 270.9;
280   dm[2]= 0.3;
281
282   gMC->Gsposp("TPCR",2,"TOIN",0.,0.,253.3,0,"ONLY",dm,3); // right
283
284   //
285
286   dm[0]= 272.2;
287   dm[1]= 277.95;
288   dm[2]= 0.3;
289
290   gMC->Gsposp("TPCR",3,"TOIN",0.,0.,-250.7,0,"ONLY",dm,3); // left top
291
292   //----------------------------------------------------------------
293   // Tpc Outer Contaiment Vessel  
294   //  mother volume - Al, daughters - composite (sandwich)
295   //----------------------------------------------------------------
296   
297   dm[0]= 0.;
298   dm[1]= 360.;
299   dm[2]=5.;
300
301   //
302
303   dm[3]= -250.4;
304   dm[4]= 272.2;
305   dm[5]= 277.95;
306
307   //
308
309   dm[6]= -248.4;
310   dm[7]= 272.2;
311   dm[8]= 277.95;
312
313   //
314
315   dm[9]= 253.6;
316   dm[10]= 272.2;
317   dm[11]= 277.95;
318
319   //
320
321   dm[12]= 253.6;
322   dm[13]= 265.2;
323   dm[14]= 277.95;
324
325   // 
326
327   dm[15]= 255.6;
328   dm[16]= 265.2;
329   dm[17]= 277.95;
330
331   gMC->Gsvolu("TOCV","PCON",idtmed[4],dm,18);
332
333   // Daughter volumes
334
335   // Tpc SAndwich 1 - Al
336  
337   dm[0]= 274.81;
338   dm[1]= 277.95;
339   dm[2]= 251.7;
340
341   gMC->Gsvolu("TSA1","TUBE",idtmed[4],dm,3);
342
343   // Tpc SAndwich 2 - Tedlar
344
345   dm[0] += 5.e-3;
346   dm[1] -= 5.e-3;
347   
348   gMC->Gsvolu("TSA2","TUBE",idtmed[9],dm,3);
349
350   // Tpc SAndwich 3 - Kevlar
351
352   dm[0] += 5e-3;
353   dm[1] -= 5.e-3;
354
355   gMC->Gsvolu("TSA3","TUBE",idtmed[5],dm,3);
356
357   // Tpc SAndwich 4 - NOMEX honeycomb
358
359   dm[0] += 0.06;
360   dm[1] -= 0.06;
361
362   gMC->Gsvolu("TSA4","TUBE",idtmed[5],dm,3);  
363   
364   // 4->3->2->1->TOCV
365
366   gMC->Gspos("TSA4",1,"TSA3",0.,0.,0.,0,"ONLY");
367   gMC->Gspos("TSA3",1,"TSA2",0.,0.,0.,0,"ONLY");
368   gMC->Gspos("TSA2",1,"TSA1",0.,0.,0.,0,"ONLY");
369
370   gMC->Gspos("TSA1",1,"TOCV",0.,0.,2.6,0,"ONLY");
371
372   // TCOV-> TOIN
373
374   gMC->Gspos("TOCV",1,"TOIN",0.,0.,0.,0,"ONLY");
375
376   //-------------------------------------------------------
377   //  Tpc Outer Field Cage
378   //  mother volume - Al, daughters - composite (sandwich)
379   //-------------------------------------------------------
380
381   dm[0]=0.;
382   dm[1]=360.;
383   dm[2]=6.;
384
385   dm[3]= -253.;
386   dm[4]= 258.;
387   dm[5]= 277.95;
388
389   //
390
391   dm[6]= -251.;
392   dm[7]= 258.;
393   dm[8]= 277.95;
394
395   //
396  
397   dm[9]= -251.;
398   dm[10]= 258.;
399   dm[11]= 260.05;
400
401   //
402
403   dm[12]= 251.;
404   dm[13]= 258.;
405   dm[14]= 260.05;
406
407   //
408
409   dm[15]= 251.;
410   dm[16]= 258.;
411   dm[17]= 260.05;
412
413   //
414
415   dm[18]= 253.;
416   dm[19]= 258.;
417   dm[20]= 270.9;
418
419   gMC->Gsvolu("TOFC","PCON",idtmed[4],dm,21);  
420
421   // Daughter volumes 
422
423   // Tpc SAndwich 5 - Al
424
425   dm[0]= 258.;
426   dm[1]= 260.05;
427   dm[2]= 251.7;
428
429   gMC->Gsvolu("TSA5","TUBE",idtmed[4],dm,3);
430
431   // Tpc SAndwich 6 - Tedlar
432
433   dm[0] += 5.e-3;
434   dm[1] -= 5.e-3;
435
436   gMC->Gsvolu("TSA6","TUBE",idtmed[9],dm,3);
437
438   // Tpc SAndwich 7 - Kevlar
439
440   dm[0] += 5.e-3;
441   dm[1] -= 5.e-3;
442
443   gMC->Gsvolu("TSA7","TUBE",idtmed[5],dm,3);
444
445   // Tpc SAndwich 8 - NOMEX
446
447   dm[0] += 0.02;
448   dm[1] -= 0.02;
449
450   gMC->Gsvolu("TSA8","TUBE",idtmed[6],dm,3);    
451
452   // 8->7->6->5->TOFC
453
454   gMC->Gspos("TSA8",1,"TSA7",0.,0.,0.,0,"ONLY");
455   gMC->Gspos("TSA7",1,"TSA6",0.,0.,0.,0,"ONLY");
456   gMC->Gspos("TSA6",1,"TSA5",0.,0.,0.,0,"ONLY"); 
457
458   gMC->Gspos("TSA5",1,"TOFC",0.,0.,0.,0,"ONLY");
459
460   // TOFC->TOIN
461
462   gMC->Gspos("TOFC",1,"TOIN",0.,0.,0.,0,"ONLY"); 
463
464   // TOIN->TPC
465
466   gMC->Gspos("TOIN",1,"TPC ",0.,0.,0.,0,"ONLY");
467
468   //--------------------------------------------------------------------
469   // Tpc Inner INsulator (CO2)
470   //--------------------------------------------------------------------
471
472
473   dm[0]=0.;
474   dm[1]= 360.;
475   dm[2]= 15.;
476
477   //
478
479   dm[3]= -255.6;
480   dm[4]= 66.2;
481   dm[5]= 74.8;
482
483   //
484
485   Float_t tanL = (66.2-59.0)/(255.6-73.3); // tangent of the left cone part
486
487   dm[6]= -253.6;
488   dm[7]= 59.0+ (253.6-73.3)*tanL;
489   dm[8]= 74.8;
490
491   //
492
493   dm[9]= -253.6;
494   dm[10]= dm[7];
495   dm[11]= 79.2;
496
497   //
498
499   dm[12]= -73.3;
500   dm[13]= 59.0;
501   dm[14]= 79.2;
502
503   //
504
505   dm[15]= -73.3;
506   dm[16]= 56.9;
507   dm[17]= 79.2;
508
509   //
510
511   dm[18]= -72.1;
512   dm[19]= 59.6;
513   dm[20]= 79.2;
514
515   //
516
517   dm[21]= -72.1;
518   dm[22]= 60.65;
519   dm[23]= 79.2;
520
521   //
522
523   dm[24]= 72.1;
524   dm[25]= 60.65;
525   dm[26]= 79.2;  
526
527   //
528
529   dm[27]= 72.1;
530   dm[28]= 59.6;
531   dm[29]= 79.2;
532
533   //
534
535   dm[30]= 73.3;
536   dm[31]= 56.9;
537   dm[32]= 79.2;
538
539   //
540
541   dm[33]= 73.3;
542   dm[34]= 59.0;
543   dm[35]= 79.2;
544
545   //
546
547   dm[36]= 250.4;
548   dm[37]= 66.0;
549   dm[38]= 79.2;
550
551   //
552   
553   dm[39]= 253.0;
554   dm[40]= 66.0;
555   dm[41]= 79.2;
556
557   //
558
559   dm[42]= 253.0;
560   dm[43]= 75.3;
561   dm[44]= 79.2;
562
563   //
564
565   dm[45]= 253.6;
566   dm[46]= 75.3;
567   dm[47]= 79.2;
568
569   gMC->Gsvolu("TIIN","PCON",idtmed[3],dm,48);
570
571
572   //--------------------------------------------------------------------
573   //  Tpc Inner Containment vessel, Left part
574   //  mother volume - Al, daughter - composite (sandwich)
575   //--------------------------------------------------------------------
576
577   dm[0]= 0.;
578   dm[1]= 360.;
579   dm[2]= 8.;
580
581   //
582
583   dm[3]= -255.6;
584   dm[4]= 66.2;
585   dm[5]= 74.8;
586
587   //
588
589   Float_t cosL = 1./TMath::Sqrt(1.+tanL*tanL);
590   Float_t sandThick = 2.14; // cone composite thickness
591
592
593   //
594
595   dm[6]= -253.6;
596   dm[7]= 59.0 + (253.6-73.3)*tanL;
597   dm[8]= 74.8;
598
599   //
600
601   dm[9]= -253.6;
602   dm[10]= dm[7];
603   dm[11]= dm[7]+sandThick/cosL;
604
605   //
606
607   dm[12]= -75.6;
608   dm[13]= 59.0+(75.6-73.3)*tanL;
609   dm[14]= dm[13]+sandThick/cosL;
610
611   //
612
613   dm[15]= -75.6;
614   dm[16]= dm[13];
615   dm[17]= 60.65;
616
617   //
618
619   dm[18]= -73.3;
620   dm[19]= 59.0;
621   dm[20]= 60.65;
622
623   //
624
625   dm[21]= -73.3;
626   dm[22]= 56.9;
627   dm[23]= 60.65;
628
629   //
630
631   dm[24]= -72.1;
632   dm[25]= 56.9;
633   dm[26]= 60.65;
634
635   gMC->Gsvolu("TICL","PCON",idtmed[4],dm,27);
636
637   // Daughter volumes 
638
639   // Tpc SAndwich 9 - Al
640
641   dm[0]= 0.;
642   dm[1]= 360.;
643   dm[2]= 2.;
644
645   //
646
647   dm[3]= - 254.3;
648   dm[4]= 59.0+(254.3-73.3)*tanL;
649   dm[5]= dm[4]+sandThick/cosL;
650
651   //
652
653   dm[6]= -78.3;
654   dm[7]= 59.0+(78.3-73.3)*tanL;
655   dm[8]= dm[7]+sandThick/cosL;
656
657   //
658
659   gMC->Gsvolu("TSA9","PCON",idtmed[4],dm,9);
660
661   // Tpc SAndwich 10 - Tedlar
662
663   dm[4]+= 5.e-3/cosL;
664   dm[5]-= 5.e-3/cosL;
665
666   //
667
668   dm[7]+= 5.e-3/cosL;
669   dm[8]+= 5.e-3/cosL;
670
671   gMC->Gsvolu("TS10","PCON",idtmed[9],dm,9); 
672
673   // Tpc SAndwich 11 - Kevlar
674
675   dm[4]+= 5.e-3/cosL;
676   dm[5]-= 5.e-3/cosL;
677
678   //
679
680   dm[7]+= 5.e-3/cosL;
681   dm[8]+= 5.e-3/cosL;
682
683   gMC->Gsvolu("TS11","PCON",idtmed[5],dm,9); 
684
685   // Tpc SAndwich 12 - NOMEX
686
687   dm[4]+= 0.06/cosL;
688   dm[5]-= 0.06/cosL;
689
690   //
691
692   dm[7]+= 0.06/cosL;
693   dm[8]+= 0.06/cosL;
694
695   gMC->Gsvolu("TS12","PCON",idtmed[6],dm,9);   
696
697   // 12->11->10->9
698
699   gMC->Gspos("TS12",1,"TS11",0.,0.,0.,0,"ONLY");
700   gMC->Gspos("TS11",1,"TS10",0.,0.,0.,0,"ONLY");
701   gMC->Gspos("TS10",1,"TSA9",0.,0.,0.,0,"ONLY");
702
703   // TSA9->TICL
704
705   gMC->Gspos("TSA9",1,"TICL",0.,0.,0.,0,"ONLY");
706  
707   //--------------------------------------------------------------------
708   //  Tpc Inner Containment vessel, Right part
709   //  mother volume - Al, daughter - composite (sandwich)
710   //--------------------------------------------------------------------
711
712   dm[0]= 0.;
713   dm[1]= 360.;
714   dm[2]=8.;
715
716   //
717
718   dm[3]= 72.1;
719   dm[4]= 56.9;
720   dm[5]= 60.65;
721
722   //
723
724   dm[6]= 73.3;
725   dm[7]= 56.9;
726   dm[8]= 60.65;
727
728   //
729
730   dm[9]= 73.3;
731   dm[10]= 59.0;
732   dm[11]= 60.65;
733
734   //
735
736   Float_t tanR = (66.0-59.0)/(250.5-73.3); // to avoid accuracy problems
737   Float_t cosR = 1./TMath::Sqrt(1.+tanR*tanR); //as above
738
739   //
740
741   dm[12]= 75.6;
742   dm[13]= 59.0+(75.6-73.3)*tanR;
743   dm[14]= 60.65;
744
745   //
746
747   dm[15]= 75.6;
748   dm[16]= dm[13];
749   dm[17]= dm[16]+sandThick/cosR;
750
751   //
752
753   dm[18]= 248.4;
754   dm[19]= 59.0+(248.4-73.3)*tanR;
755   dm[20]= dm[19]+sandThick/cosR;
756
757   //
758
759   dm[21]= 248.4;
760   dm[22]= dm[19];
761   dm[23]= 70.2;
762
763   //
764
765   dm[24]= 250.4;
766   dm[25]= 66.0;
767   dm[26]= 70.2;
768
769   gMC->Gsvolu("TICR","PCON",idtmed[4],dm,27);
770
771
772
773   // Daughter volumes 
774
775   // Tpc SAndwich 13 - Al
776
777   dm[0]= 0.;
778   dm[1]= 360.;
779   dm[2]= 2.;
780
781   //
782
783   dm[3]= 78.3;
784   dm[4]= 59.0+(78.3-73.3)*tanR;
785   dm[5]= dm[4]+sandThick/cosR;
786
787   //
788
789   dm[6]= 249.1;
790   dm[7]= 59.0+(249.1-73.3)*tanR;
791   dm[8]= dm[7]+sandThick/cosR;
792
793   //
794
795   gMC->Gsvolu("TS13","PCON",idtmed[4],dm,9);
796
797   // Tpc SAndwich 14 - Tedlar
798
799   dm[4]+= 5.e-3/cosR;
800   dm[5]-= 5.e-3/cosR;
801
802   //
803
804   dm[7]+= 5.e-3/cosR;
805   dm[8]+= 5.e-3/cosR;
806
807   gMC->Gsvolu("TS14","PCON",idtmed[9],dm,9); 
808
809   // Tpc SAndwich 15 - Kevlar
810
811   dm[4]+= 5.e-3/cosR;
812   dm[5]-= 5.e-3/cosR;
813
814   //
815
816   dm[7]+= 5.e-3/cosR;
817   dm[8]+= 5.e-3/cosR;
818
819   gMC->Gsvolu("TS15","PCON",idtmed[5],dm,9); 
820
821   // Tpc SAndwich 16 - NOMEX
822
823   dm[4]+= 0.06/cosR;
824   dm[5]-= 0.06/cosR;
825
826   //
827
828   dm[7]+= 0.06/cosR;
829   dm[8]+= 0.06/cosR;
830
831   gMC->Gsvolu("TS16","PCON",idtmed[6],dm,9);   
832
833   // 16->15->14->13
834
835   gMC->Gspos("TS16",1,"TS15",0.,0.,0.,0,"ONLY");
836   gMC->Gspos("TS15",1,"TS14",0.,0.,0.,0,"ONLY");
837   gMC->Gspos("TS14",1,"TS13",0.,0.,0.,0,"ONLY");
838
839   // TS12->TICR
840
841   gMC->Gspos("TS13",1,"TICR",0.,0.,0.,0,"ONLY");
842
843   //------------------------------------------------------
844   // Tpc Inner Field Cage
845   // mother volume - Al, daughters - composite (sandwich)
846   //------------------------------------------------------
847
848   dm[0]= 0.;
849   dm[1]= 360.;
850   dm[2]=6.;
851
852   //
853
854   dm[3]= -253.0;
855   dm[4]= 70.7;
856   dm[5]= 79.2;
857
858   //
859
860   dm[6]= -251.0;
861   dm[7]= 70.7;
862   dm[8]= 79.2;
863
864   //
865
866   dm[9]= -251.0;
867   dm[10]= 77.15;
868   dm[11]= 79.2;
869
870   //
871   
872   dm[12]= 251.0;
873   dm[13]= 77.15;
874   dm[14]= 79.2;
875
876   //
877
878   dm[15]= 251.0;
879   dm[16]= 66.0;
880   dm[17]= 79.2;
881
882   //
883
884   dm[18]= 253.0;
885   dm[19]= 66.0;
886   dm[20]= 79.2;
887
888   gMC->Gsvolu("TIFC","PCON",idtmed[4],dm,21);
889
890   // Daughter volumes
891
892   // Tpc Sandwich 17 - Al
893
894   dm[0]= 77.15;
895   dm[1]= 79.2;
896   dm[2]= 251.7;
897
898   gMC->Gsvolu("TS17","TUBE",idtmed[4],dm,3);
899
900   // Tpc Sandwich 18 - Tedlar
901
902   dm[0]+= 5.e-3;
903   dm[1]-= 5.e-3;
904
905   gMC->Gsvolu("TS18","TUBE",idtmed[9],dm,3);
906
907   // Tpc Sandwich 19 - Kevlar
908
909   dm[0]+= 5.e-3;
910   dm[1]-= 5.e-3;
911
912   gMC->Gsvolu("TS19","TUBE",idtmed[5],dm,3);
913
914   // Tpc Sandwich 20 - NOMEX
915
916   dm[0]+= 0.06;
917   dm[1]-= 0.06;
918
919   gMC->Gsvolu("TS20","TUBE",idtmed[6],dm,3);
920
921   // 20->19->18->17
922
923   gMC->Gspos("TS20",1,"TS19",0.,0.,0.,0,"ONLY");
924   gMC->Gspos("TS19",1,"TS18",0.,0.,0.,0,"ONLY");
925   gMC->Gspos("TS18",1,"TS17",0.,0.,0.,0,"ONLY");
926
927   // TS17->TIFC
928
929   gMC->Gspos("TS17",1,"TIFC",0.,0.,0.,0,"ONLY");
930
931   // TPC Rings
932
933   dm[0]= 70.7;
934   dm[1]= 79.2;
935   dm[2]= 0.3;
936
937   gMC->Gsposp("TPCR",4,"TIIN",0.,0.,-253.3,0,"ONLY",dm,3);
938
939   dm[0]= 66.0;
940   dm[1]= 70.2;  
941
942   gMC->Gsposp("TPCR",5,"TIIN",0.,0.,250.7,0,"ONLY",dm,3);
943
944   dm[0]= 75.3;
945   dm[1]= 79.2;  
946
947   gMC->Gsposp("TPCR",6,"TIIN",0.,0.,253.3,0,"ONLY",dm,3);  
948
949   // TICL->TIIN
950
951   gMC->Gspos("TICL",1,"TIIN",0.,0.,0.,0,"ONLY");
952
953   // TICR->TIIN
954
955   gMC->Gspos("TICR",1,"TIIN",0.,0.,0.,0,"ONLY");
956
957   // TIFC->TIIN
958
959   gMC->Gspos("TIFC",1,"TIIN",0.,0.,0.,0,"ONLY");
960
961   // Tpc Sandwich 21 - Al (central barrel)
962
963   dm[0]= 77.15;
964   dm[1]= 79.2;
965   dm[2]= 75.2;
966
967   gMC->Gsvolu("TS21","TUBE",idtmed[4],dm,3);
968
969   // Tpc Sandwich 22 - Tedlar (central barrel) 
970
971   dm[0]+= 5.e-3;
972   dm[1]-= 5.e-3;
973
974   gMC->Gsvolu("TS22","TUBE",idtmed[9],dm,3); 
975
976   // Tpc Sandwich 23 - Kevlar (central barrel) 
977
978   dm[0]+= 5.e-3;
979   dm[1]-= 5.e-3;
980
981   gMC->Gsvolu("TS23","TUBE",idtmed[5],dm,3); 
982
983   // Tpc Sandwich 24 - NOMEX (central barrel) 
984
985   dm[0]+= 0.02;
986   dm[1]-= 0.02;
987
988   gMC->Gsvolu("TS24","TUBE",idtmed[6],dm,3); 
989
990   // 24->23->22->21
991
992   gMC->Gspos("TS24",1,"TS23",0.,0.,0.,0,"ONLY");
993   gMC->Gspos("TS23",1,"TS22",0.,0.,0.,0,"ONLY");
994   gMC->Gspos("TS22",1,"TS21",0.,0.,0.,0,"ONLY");
995
996   gMC->Gspos("TS21",1,"TIIN",0.,0.,0.,0,"ONLY");
997
998   // put everything into the TPC 
999
1000   gMC->Gspos("TIIN",1,"TPC ",0.,0.,0.,0,"ONLY");
1001
1002
1003   //---------------------------------------------------------
1004   //  Tpc Dift Gas volume Nonsensitive (Ne-CO2 90/10)
1005   //  and its daughters (HV membrane, rods, readout chambers)
1006   //---------------------------------------------------------
1007
1008   dm[0]= 79.2;
1009   dm[1]= 258.0;
1010   dm[2]= 253.6;
1011
1012   gMC->Gsvolu("TDGS","TUBE",idtmed[2],dm,3);  
1013
1014   // sector opening angles
1015
1016   Float_t innerOpenAngle = fTPCParam->GetInnerAngle();
1017
1018   // sector angle shift
1019
1020   Float_t innerAngleShift = fTPCParam->GetInnerAngleShift();
1021
1022   // number of sectors
1023
1024   Int_t nInnerSector = fTPCParam->GetNInnerSector()/2;
1025   Int_t nOuterSector = fTPCParam->GetNOuterSector()/2;
1026
1027   // All above parameters are identical for inner and outer
1028   // sectors. The distinction is kept for the historical reasons
1029   // and eventually will disappear.
1030
1031   Float_t tanAlpha = TMath::Tan(0.5*innerOpenAngle);
1032   Float_t cosAlpha = TMath::Sqrt(1.+tanAlpha*tanAlpha);
1033   Float_t space;
1034
1035   //-------------------------------------------------------------------------
1036   //   Tpc Inner Readout Chambers 
1037   //-------------------------------------------------------------------------
1038
1039   dm[0]= 14.483;
1040   dm[1]= 23.3345; 
1041   dm[2]= 1.6; // thickness
1042   dm[3]= 25.1;
1043
1044   gMC->Gsvolu("TIRC","TRD1",idtmed[4],dm,4);
1045
1046   // this volume will be positioned in the empty space
1047   // of the end-cap to avoid overlaps
1048
1049   dm[0]= 13.7305;
1050   dm[1]= 21.1895;
1051   dm[2]= 2.25;
1052   dm[3]= 21.15;
1053
1054   gMC->Gsvolu("TIC1","TRD1",idtmed[4],dm,4);
1055
1056
1057   //------------------------------------------------
1058   // Tpc Inner readout chamber Pad Plane
1059   //------------------------------------------------
1060
1061   dm[0]= 14.483;
1062   dm[1]= 23.3345;
1063   dm[2]= 0.5;
1064   dm[3]= 25.1;
1065
1066   gMC->Gsvolu("TIPP","TRD1",idtmed[12],dm,4);
1067
1068   // 
1069
1070   dm[0] -= 1.218511934;
1071   dm[1] -= 1.218511934;
1072   dm[2] = 0.35;
1073
1074   gMC->Gsvolu("TIC3","TRD1",idtmed[2],dm,4);
1075
1076   gMC->Gspos("TIC3",1,"TIPP",0.,0.15,0.,0,"ONLY");
1077
1078   gMC->Gspos("TIPP",1,"TIRC",0.,1.1,0.,0,"ONLY");
1079
1080
1081   //----------------------------------------------
1082   // Tpc Readout Chambers Empty spaces - for both
1083   // inner and outer sectors
1084   //----------------------------------------------
1085
1086   gMC->Gsvolu("TRCE","TRD1",idtmed[0],dm,0);
1087
1088   // Inner sector - 4 spaces
1089
1090
1091   dm[3] = 4.7625;
1092   dm[0] = 12.472;
1093
1094   Float_t rr = 90.52;
1095   Float_t zz;
1096
1097   zz= -12.7875;
1098   
1099   space = rr*tanAlpha-dm[0];
1100
1101   for(Int_t nsLow=0;nsLow<4;nsLow++){
1102
1103     rr += 9.525;
1104     dm[1]= rr*tanAlpha - space;  
1105
1106     dm[2]=0.8;
1107
1108     gMC->Gsposp("TRCE",nsLow+1,"TIRC",0.,-0.8,zz,0,"ONLY",dm,4);
1109
1110     //
1111
1112     dm[2]= 1.2;
1113
1114     gMC->Gsposp("TRCE",nsLow+5,"TIC1",0.,1.05,zz-2.1,0,"ONLY",dm,4);
1115
1116     rr += 0.4;
1117     dm[0] = rr*tanAlpha - space;
1118     zz += (0.4+9.525); 
1119
1120   }
1121
1122   dm[0]= 12.472;
1123   // dm[1] - this is the dm[1] from the previous TRCE
1124   dm[2]= 1.05;
1125   dm[3]= 19.65;
1126
1127   gMC->Gsposp("TRCE",9,"TIC1",0.,-1.,0.,0,"ONLY",dm,4);   
1128
1129   //
1130   // TPc Space for Connectors
1131   //
1132
1133   dm[0]= .3;
1134   dm[1]= .3;
1135   dm[2]= 4.5;
1136
1137   gMC->Gsvolu("TPSC","BOX ",idtmed[0],dm,3);
1138
1139   // TPC Connectors
1140
1141   dm[0]= .25;
1142   dm[1]= .15;
1143   dm[2]= 3.75;
1144
1145   gMC->Gsvolu("TPCC","BOX ",idtmed[13],dm,3); 
1146
1147   gMC->Gspos("TPCC",1,"TPSC",0.,0.15,0.,0,"ONLY");
1148
1149   zz = -12.7875;
1150
1151
1152   Float_t alpha;
1153   Float_t astep;
1154
1155   Float_t phi1,phi2,phi3,theta1,theta2,theta3; // rotation angles
1156
1157   // inner part of the inner sector - 2 x 20 holes
1158   
1159   astep = 20.00096874/19.;
1160
1161   alpha = 10.00048437-astep;
1162
1163   Float_t x1,x2;
1164
1165     x1 = 13.31175725;
1166     x1 -= 0.996357832; 
1167
1168     x2 = 15.06180253;
1169     x2 -= 1.163028812;
1170
1171   Int_t ncon;
1172
1173   for(ncon=0;ncon<20;ncon++){
1174
1175     phi1 = 0.;
1176     theta1 = 90.+alpha;
1177     phi2=90.;
1178     theta2 = 90.;
1179     phi3 = (alpha>0) ? 0. : 180.;
1180     theta3 = TMath::Abs(alpha);
1181
1182     AliMatrix(idrotm[nRotMat], theta1, phi1, theta2, phi2, theta3, phi3);
1183
1184  
1185
1186     gMC->Gspos("TPSC",ncon+1,"TIRC",x1,0.3,-12.7875,idrotm[nRotMat],"ONLY");
1187     gMC->Gspos("TPSC",ncon+21,"TIRC",x2,0.3,-2.8625,idrotm[nRotMat],"ONLY");
1188
1189
1190     x1 -= 1.296357833;
1191     x2 -= 1.463028812;
1192
1193     alpha -= astep;   
1194     nRotMat++; 
1195
1196   }
1197
1198   // outer part of the inner sector - 2 x 25 holes
1199
1200    astep = 20.00096874/24.; 
1201    alpha = 10.00048437-astep;
1202
1203    x1 = 16.81184781;
1204    x1 -= 1.016295986;
1205
1206    x2 = 18.5618931;
1207    x2 -= 1.150914854;
1208
1209   for(ncon=0;ncon<25;ncon++){
1210
1211     phi1 = 0.;
1212     theta1 = 90.+alpha;
1213     phi2=90.;
1214     theta2 = 90.;
1215     phi3 = (alpha>0) ? 0. : 180.;
1216     theta3 = TMath::Abs(alpha);
1217
1218     AliMatrix(idrotm[nRotMat], theta1, phi1, theta2, phi2, theta3, phi3);
1219
1220  
1221
1222     gMC->Gspos("TPSC",ncon+41,"TIRC",x1,0.3,7.0625,idrotm[nRotMat],"ONLY");
1223     gMC->Gspos("TPSC",ncon+66,"TIRC",x2,0.3,16.9875,idrotm[nRotMat],"ONLY");
1224
1225
1226     x1 -= 1.316295986;
1227     x2 -= 1.450914854;
1228
1229     alpha -= astep;   
1230     nRotMat++; 
1231
1232   }  
1233
1234   //--------------------------------------------------------------------------
1235   //  TPC Outer Readout Chambers
1236   //  this is NOT a final design
1237   //--------------------------------------------------------------------------
1238
1239   dm[0]= 23.3875;
1240   dm[1]= 43.524;
1241   dm[2]= 1.5; //thickness
1242   dm[3]= 57.1;
1243
1244   gMC->Gsvolu("TORC","TRD1",idtmed[4],dm,4);
1245
1246   //------------------------------------------------
1247   // Tpc Outerr readout chamber Pad Plane
1248   //------------------------------------------------
1249
1250   dm[2]= 0.5;
1251
1252   gMC->Gsvolu("TOPP","TRD1",idtmed[12],dm,4);
1253
1254   dm[0] -= 1.218511934;
1255   dm[1] -= 1.218511934;
1256   dm[2] = 0.35;
1257
1258   gMC->Gsvolu("TOC3","TRD1",idtmed[2],dm,4);
1259
1260   gMC->Gspos("TOC3",1,"TOPP",0.,0.15,0.,0,"ONLY");
1261
1262   gMC->Gspos("TOPP",1,"TORC",0.,1.0,0.,0,"ONLY");
1263
1264   // empty space
1265
1266
1267   dm[0]= 21.035;
1268   dm[1]= 38.7205;
1269   dm[2]= 0.7; 
1270   dm[3]= 50.15;
1271
1272   gMC->Gsposp("TRCE",10,"TORC",0.,-0.8,-2.15,0,"ONLY",dm,4);  
1273
1274   dm[0]= 22.2935;
1275   dm[1]= 40.5085;
1276   dm[2]= 2.25;
1277   dm[3]= 51.65;
1278
1279   gMC->Gsvolu("TOC1","TRD1",idtmed[4],dm,4);
1280
1281
1282   dm[0]= 21.35;
1283   dm[1]= 38.7205;
1284   dm[2]= 2.25;
1285   dm[3]= 50.15;
1286
1287   gMC->Gsposp("TRCE",11,"TOC1",0.,0.,0.,0,"ONLY",dm,4); 
1288
1289
1290   //-----------------------------------------------
1291   // Tpc Services Support Wheel
1292   //-----------------------------------------------
1293
1294   dm[0]=0.;
1295   dm[1]=360.;
1296   dm[2]=18.;
1297   dm[3]=2.;
1298
1299   dm[4]= -5.;
1300   dm[5]= 77.017;
1301   dm[6]= 255.267;
1302
1303   dm[7]= 5.;
1304   dm[8]= dm[5];
1305   dm[9]= dm[6];
1306
1307   gMC->Gsvolu("TSSW","PGON",idtmed[4],dm,10);
1308
1309   // Tpc Services Wheel Cover
1310
1311   dm[4]= -0.5;
1312   dm[7]= 0.5;
1313
1314   gMC->Gsvolu("TSWC","PGON",idtmed[4],dm,10);
1315
1316   // Tpc Service wheel Cover Empty space
1317    
1318   dm[0]= 10.99;
1319   dm[1]= 39.599;
1320   dm[2]= .5;
1321   dm[3]= 81.125;
1322
1323   gMC->Gsvolu("TSCE","TRD1",idtmed[0],dm,4);
1324
1325   // Tpc services Wheel Empty Spaces
1326
1327   dm[0]= 13.18017507;
1328   dm[1]= 44.61045938;
1329   dm[2]= 4.;
1330   dm[3]= 89.125;
1331
1332   gMC->Gsvolu("TWES","TRD1",idtmed[0],dm,4);
1333
1334   // Tpc Services Wheel Bars
1335
1336   gMC->Gsvolu("TSWB","TRD1",idtmed[4],dm,0);
1337
1338   // bars-> TWES
1339
1340   dm[2]= 4.;
1341   dm[3]= .4;
1342
1343   dm[0]= 13.8149522;
1344   dm[1]= 13.95601379;
1345   
1346   gMC->Gsposp("TSWB",1,"TWES",0.,0.,-85.125,0,"ONLY",dm,4);
1347
1348   dm[0]= 43.83462067; 
1349   dm[1]= 43.97568225;
1350
1351   gMC->Gsposp("TSWB",2,"TWES",0.,0.,85.125,0,"ONLY",dm,4);
1352
1353   // TPc ELectronics - right now 30% X0 Si
1354
1355   dm[0]= 14.03813696;
1356   dm[1]= 43.3524075;
1357   dm[2]= 1.404;
1358   dm[3]= 83.125;
1359
1360   gMC->Gsvolu("TPEL","TRD1",idtmed[11],dm,4);
1361   gMC->Gspos("TPEL",1,"TWES",0.,0.,0.,0,"ONLY");
1362
1363
1364   //--------------------------------------------------------------------------
1365   //  End caps
1366   //--------------------------------------------------------------------------
1367
1368   // TPc Main Wheel - Al
1369
1370   dm[0]= 75.3;
1371   dm[1]= 264.8;
1372   dm[2]= 3.0;
1373
1374   gMC->Gsvolu("TPMW","TUBE",idtmed[4],dm,3);
1375
1376   // TPc Extra Wheel (to avoid overlapping) - Al
1377
1378   dm[0]= 264.8;
1379   dm[1]= 277.0;
1380   dm[2]= 1.95;
1381
1382   gMC->Gsvolu("TPEW","TUBE",idtmed[4],dm,3);
1383
1384   //--------------------------------------------------------------------------
1385   //  Tpc Empty Space for the Readout chambers
1386   //--------------------------------------------------------------------------  
1387
1388   Float_t rLow= 86.2;
1389   Float_t rUp= 243.5;
1390   Float_t dR = 0.5*(rUp-rLow);
1391
1392   space= 1.4/cosAlpha; // wheel ribs are 2.8 cm wide
1393
1394   dm[0]= rLow*tanAlpha-space;
1395   dm[1]= rUp*tanAlpha-space;
1396   dm[2]= 3.0;
1397   dm[3]= dR;
1398
1399   gMC->Gsvolu("TESR","TRD1",idtmed[0],dm,4);
1400
1401   // TIC1->TESR
1402
1403
1404   gMC->Gspos("TIC1",1,"TESR",0.,0.75,-dR+23.97,0,"ONLY");
1405
1406
1407   // TOC1->TESR
1408
1409   gMC->Gspos("TOC1",1,"TESR",0.,0.75,dR-55.02,0,"ONLY");
1410
1411   // Tpc Empty Space Bars - Al (daughters of TESR)
1412
1413   Float_t zBar;
1414
1415   gMC->Gsvolu("TESB","TRD1",idtmed[4],dm,0);
1416
1417   // lower bar
1418
1419   dm[0]= rLow*tanAlpha-space;
1420   dm[1]= 88.7*tanAlpha-space;
1421   dm[2]= 0.95;
1422   dm[3]= 1.275;
1423
1424   zBar = -dR+dm[3];
1425
1426   gMC->Gsposp("TESB",1,"TESR",0.,2.05,zBar,0,"ONLY",dm,4);
1427
1428   // middle bar
1429
1430   dm[0]= 131.65*tanAlpha-space;
1431   dm[1]= 136.5*tanAlpha-space;
1432   dm[3]= 2.425;
1433
1434   zBar = -dR +131.65+dm[3]-rLow;
1435
1436   gMC->Gsposp("TESB",2,"TESR",0.,2.05,zBar,0,"ONLY",dm,4);
1437
1438   // upper bar
1439
1440   dm[0]= 240.4*tanAlpha-space;
1441   dm[1]= rUp*tanAlpha-space;
1442   dm[3]= 1.55;
1443
1444   zBar = dR-dm[3];
1445
1446   gMC->Gsposp("TESB",3,"TESR",0.,2.05,zBar,0,"ONLY",dm,4);
1447
1448   //  positioning of the empty spaces into the main wheel
1449
1450   Float_t rCenter,xc,yc;
1451   Float_t rInner,rOuter; // center of the inner and outer chamber
1452
1453   rCenter = rLow+dR;
1454
1455   rInner = 108.07;
1456   rOuter = 190.68;
1457
1458   for(Int_t ns=0; ns<nInnerSector;ns++){
1459
1460     phi1 = ns * innerOpenAngle + innerAngleShift;
1461     phi1 *= kRaddeg; // in degrees
1462
1463     phi1 = (Float_t)TMath::Nint(phi1) + 270.;
1464
1465     if (phi1 > 360.) phi1 -= 360.;
1466
1467     theta1 = 90.;
1468     phi2   = 90.;
1469     theta2 = 180.;
1470     phi3   = ns * innerOpenAngle + innerAngleShift;
1471     phi3 *= kRaddeg; // in degrees
1472
1473     phi3 = (Float_t)TMath::Nint(phi3);
1474       
1475     if(phi3 > 360.) phi3 -= 360.;
1476
1477     theta3 = 90.;
1478
1479     // "holes"->End plate
1480
1481     xc = rCenter*TMath::Cos(phi3*kDegrad);
1482     yc = rCenter*TMath::Sin(phi3*kDegrad);
1483
1484     AliMatrix(idrotm[nRotMat], theta1, phi1, theta2, phi2, theta3, phi3);
1485
1486     gMC->Gspos("TESR",ns+1,"TPMW",xc,yc,0.,idrotm[nRotMat],"ONLY");
1487
1488     // TSCE->TSWC (services wheel volumes)
1489
1490     xc = 166.142*TMath::Cos(phi3*kDegrad);
1491     yc = 166.142*TMath::Sin(phi3*kDegrad);
1492
1493     gMC->Gspos("TSCE",ns+1,"TSWC",xc,yc,0.,idrotm[nRotMat],"ONLY");
1494     gMC->Gspos("TWES",ns+1,"TSSW",xc,yc,0.,idrotm[nRotMat],"ONLY");
1495
1496
1497     // readout chambers->TDGS (drift gas)
1498
1499     xc = rInner*TMath::Cos(phi3*kDegrad);
1500     yc = rInner*TMath::Sin(phi3*kDegrad);
1501
1502     gMC->Gspos("TIRC",ns+1,"TDGS",xc,yc,252.,idrotm[nRotMat],"ONLY");
1503      
1504     xc = rOuter*TMath::Cos(phi3*kDegrad);
1505     yc = rOuter*TMath::Sin(phi3*kDegrad);
1506
1507     gMC->Gspos("TORC",ns+1,"TDGS",xc,yc,252.1,idrotm[nRotMat],"ONLY");
1508
1509     nRotMat++;
1510
1511     theta2 = 0.; // reflection
1512
1513     AliMatrix(idrotm[nRotMat], theta1, phi1, theta2, phi2, theta3, phi3);
1514
1515     xc = rInner*TMath::Cos(phi3*kDegrad);
1516     yc = rInner*TMath::Sin(phi3*kDegrad);
1517
1518     gMC->Gspos("TIRC",ns+nInnerSector+1,"TDGS",xc,yc,-252.,idrotm[nRotMat],"ONLY");
1519
1520     xc = rOuter*TMath::Cos(phi3*kDegrad);
1521     yc = rOuter*TMath::Sin(phi3*kDegrad);
1522
1523     gMC->Gspos("TORC",ns+nOuterSector+1,"TDGS",xc,yc,-252.1,idrotm[nRotMat],"ONLY");
1524
1525     nRotMat++;
1526
1527
1528   } 
1529
1530
1531   // reflection matrix
1532
1533   theta1 = 90.;
1534   phi1   = 0.;
1535   theta2 = 90.;
1536   phi2   = 270.;
1537   theta3 = 180.;
1538   phi3   = 0.;
1539
1540   AliMatrix(idrotm[nRotMat], theta1, phi1, theta2, phi2, theta3, phi3);
1541
1542
1543   // TPMW->TPC
1544
1545   gMC->Gspos("TPMW",1,"TPC ",0.,0.,256.6,0,"ONLY");
1546   gMC->Gspos("TPMW",2,"TPC ",0.,0.,-256.6,idrotm[nRotMat],"ONLY");
1547   gMC->Gspos("TPEW",1,"TPC ",0.,0.,257.65,0,"ONLY");
1548   gMC->Gspos("TPEW",2,"TPC ",0.,0.,-257.65,0,"ONLY");
1549
1550
1551
1552   //-------------------------------------------------------
1553   // Tpc High Voltage Membrane - NOMEX honeycomb
1554   //-------------------------------------------------------
1555
1556   dm[0]=0.,
1557   dm[1]=360.;
1558   dm[2]=18.;
1559   dm[3]=2.;
1560
1561   //
1562
1563   dm[4]= -0.3;
1564   dm[5]= 81.156;
1565   dm[6]= 253.386;
1566
1567   //
1568
1569   dm[7]= 0.3;
1570   dm[8]= dm[5];
1571   dm[9]= dm[6];
1572
1573   gMC->Gsvolu("THVM","PGON",idtmed[6],dm,10);
1574
1575   gMC->Gspos("THVM",1,"TDGS",0.,0.,0.,0,"ONLY");
1576
1577   //----------------------------------------------------------
1578   // TPc Support Rods - MAKROLON
1579   //----------------------------------------------------------
1580
1581   dm[0]= 0.9;
1582   dm[1]= 1.2;
1583   dm[2]= 126.65;
1584
1585   gMC->Gsvolu("TPSR","TUBE",idtmed[7],dm,3);
1586
1587   for(Int_t nrod=1;nrod<18;nrod++){
1588     Float_t angle=innerOpenAngle*(Float_t)nrod;
1589
1590     xc=82.4*TMath::Cos(angle);
1591     yc=82.4*TMath::Sin(angle);
1592
1593     gMC->Gspos("TPSR",nrod,"TDGS",xc,yc,126.95,0,"ONLY");
1594     gMC->Gspos("TPSR",nrod+17,"TDGS",xc,yc,-126.95,0,"ONLY");
1595
1596     xc=254.2*TMath::Cos(angle);
1597     yc=254.2*TMath::Sin(angle);
1598
1599     gMC->Gspos("TPSR",nrod+34,"TDGS",xc,yc,126.95,0,"ONLY");
1600     gMC->Gspos("TPSR",nrod+51,"TDGS",xc,yc,-126.95,0,"ONLY");    
1601
1602   }
1603
1604   //----------------------------------------------------------
1605   // Tpc High Voltage rod - MAKROLON + Copper cable
1606   //----------------------------------------------------------
1607
1608   // rod with cable (Left)
1609
1610   dm[0]=0.;
1611   dm[1]=2.25;
1612   dm[2]=126.65;
1613
1614   gMC->Gsvolu("THVL","TUBE",idtmed[7],dm,3);
1615
1616   // HV cable
1617  
1618   dm[0]=0.;
1619   dm[1]=0.3;
1620   dm[2]=126.65;
1621
1622   gMC->Gsvolu("THVC","TUBE",idtmed[10],dm,3);
1623
1624   // empty space
1625
1626   dm[0]=0.3;
1627   dm[1]=1.;
1628   dm[2]=126.65;
1629
1630   gMC->Gsvolu("THVE","TUBE",idtmed[1],dm,3);
1631
1632   gMC->Gspos("THVC",1,"THVL",0.,0.,0.,0,"ONLY");
1633   gMC->Gspos("THVE",1,"THVL",0.,0.,0.,0,"ONLY");
1634
1635   // rod without cable
1636
1637   dm[0]=1.8;
1638   dm[1]=2.25;
1639   dm[2]=126.65;
1640
1641   gMC->Gsvolu("THVR","TUBE",idtmed[7],dm,3);
1642
1643   
1644   
1645   gMC->Gspos("THVL",1,"TDGS",82.4,0.,-126.95,0,"ONLY");
1646   gMC->Gspos("THVL",2,"TDGS",254.2,0.,-126.95,0,"ONLY");
1647
1648   gMC->Gspos("THVR",1,"TDGS",82.4,0.,126.95,0,"ONLY");
1649   gMC->Gspos("THVR",2,"TDGS",254.2,0.,126.95,0,"ONLY");  
1650   
1651
1652
1653   gMC->Gspos("TDGS",1,"TPC ",0.,0.,0.,0,"ONLY"); 
1654
1655   // services wheel cover -> wheel
1656
1657
1658   gMC->Gspos("TSWC",1,"TSSW",0.,0.,4.5,0,"ONLY");
1659   gMC->Gspos("TSWC",2,"TSSW",0.,0.,-4.5,0,"ONLY");
1660
1661
1662   // put the wheel into the TPC
1663
1664   gMC->Gspos("TSSW",1,"TPC ",0.,0.,278.7,0,"ONLY");
1665   gMC->Gspos("TSSW",2,"TPC ",0.,0.,-278.7,0,"ONLY");
1666
1667   gMC->Gsord("TPMW",6);
1668   gMC->Gsord("TSSW",6);
1669   gMC->Gsord("TSWC",6);
1670
1671   // put the TPC into ALIC (main mother volume)
1672
1673   gMC->Gspos("TPC ",1,"ALIC",0.,0.,0.,0,"ONLY");
1674
1675  
1676 } // end of function
1677
1678  
1679  
1680 //_____________________________________________________________________________
1681 void AliTPCv3::DrawDetector()
1682 {
1683   //
1684   // Draw a shaded view of the Time Projection Chamber version 1
1685   //
1686
1687
1688   // Set everything unseen
1689   gMC->Gsatt("*", "seen", -1);
1690   // 
1691   // Set ALIC mother transparent
1692   gMC->Gsatt("ALIC","SEEN",0);
1693   //
1694   // Set the volumes visible
1695   //
1696
1697   gMC->Gsatt("TPC ","SEEN",0);
1698   gMC->Gsatt("TOIN","SEEN",1);
1699   gMC->Gsatt("TOIN","COLO",7);
1700   gMC->Gsatt("TPCR","SEEN",0);
1701   gMC->Gsatt("TOCV","SEEN",1);
1702   gMC->Gsatt("TOCV","COLO",4);
1703   gMC->Gsatt("TSA1","SEEN",0);
1704   gMC->Gsatt("TSA2","SEEN",0);
1705   gMC->Gsatt("TSA3","SEEN",0);
1706   gMC->Gsatt("TSA4","SEEN",0);
1707   gMC->Gsatt("TOFC","SEEN",1);
1708   gMC->Gsatt("TOFC","COLO",4);
1709   gMC->Gsatt("TSA5","SEEN",0);
1710   gMC->Gsatt("TSA6","SEEN",0);
1711   gMC->Gsatt("TSA7","SEEN",0);
1712   gMC->Gsatt("TSA8","SEEN",0);
1713   gMC->Gsatt("TIIN","COLO",7);
1714   gMC->Gsatt("TIIN","SEEN",1);
1715   gMC->Gsatt("TICL","SEEN",0);
1716   gMC->Gsatt("TSA9","SEEN",0);
1717   gMC->Gsatt("TS10","SEEN",0);
1718   gMC->Gsatt("TS11","SEEN",0);
1719   gMC->Gsatt("TS12","SEEN",0);
1720   gMC->Gsatt("TICR","SEEN",0); 
1721   gMC->Gsatt("TS13","SEEN",0);
1722   gMC->Gsatt("TS14","SEEN",0);
1723   gMC->Gsatt("TS15","SEEN",0);
1724   gMC->Gsatt("TS16","SEEN",0);
1725   gMC->Gsatt("TIFC","SEEN",1);
1726   gMC->Gsatt("TIFC","COLO",4); 
1727   gMC->Gsatt("TS17","SEEN",0);
1728   gMC->Gsatt("TS18","SEEN",0);
1729   gMC->Gsatt("TS19","SEEN",0);
1730   gMC->Gsatt("TS20","SEEN",0);
1731   gMC->Gsatt("TS21","SEEN",0);
1732   gMC->Gsatt("TS22","SEEN",0);
1733   gMC->Gsatt("TS23","SEEN",0);
1734   gMC->Gsatt("TS24","SEEN",0);
1735   gMC->Gsatt("TDGS","SEEN",0);
1736   gMC->Gsatt("TIRC","SEEN",0);
1737   gMC->Gsatt("TIC1","SEEN",1);
1738   gMC->Gsatt("TIPP","SEEN",0);
1739   gMC->Gsatt("TIC3","SEEN",0);
1740   gMC->Gsatt("TRCE","SEEN",0);
1741   gMC->Gsatt("TPSC","SEEN",0);
1742   gMC->Gsatt("TPCC","SEEN",0);
1743   gMC->Gsatt("TORC","SEEN",0);
1744   gMC->Gsatt("TOPP","SEEN",0);
1745   gMC->Gsatt("TOC3","SEEN",0);
1746   gMC->Gsatt("TOC1","SEEN",1);
1747   gMC->Gsatt("TSSW","SEEN",1);
1748   gMC->Gsatt("TSWC","SEEN",1);
1749   gMC->Gsatt("TSCE","SEEN",1); 
1750   gMC->Gsatt("TSSW","COLO",3);
1751   gMC->Gsatt("TSWC","COLO",3);
1752   gMC->Gsatt("TSCE","COLO",6);
1753   gMC->Gsatt("TWES","SEEN",0);
1754   gMC->Gsatt("TSWB","SEEN",0);
1755   gMC->Gsatt("TPEL","SEEN",0);
1756   gMC->Gsatt("TPMW","SEEN",1);
1757   gMC->Gsatt("TPEW","SEEN",1);
1758   gMC->Gsatt("TESR","SEEN",1);
1759   gMC->Gsatt("TPMW","COLO",12);
1760   gMC->Gsatt("TPEW","COLO",12);
1761   gMC->Gsatt("TWES","COLO",5);
1762   gMC->Gsatt("TIC1","COLO",5);
1763   gMC->Gsatt("TOC1","COLO",5);  
1764   gMC->Gsatt("TESB","SEEN",0);
1765   gMC->Gsatt("TPLS","SEEN",0);
1766   gMC->Gsatt("TPUS","SEEN",0);
1767   gMC->Gsatt("TPSS","SEEN",0);
1768   gMC->Gsatt("THVM","SEEN",1);
1769   gMC->Gsatt("THVM","COLO",11);
1770   gMC->Gsatt("TPSR","SEEN",0);
1771   gMC->Gsatt("THVL","SEEN",0);
1772   gMC->Gsatt("THVC","SEEN",0);
1773   gMC->Gsatt("THVE","SEEN",0);
1774   gMC->Gsatt("THVR","SEEN",0);
1775
1776   //
1777   gMC->Gdopt("hide", "on");
1778   gMC->Gdopt("shad", "on");
1779   gMC->Gsatt("*", "fill", 7);
1780   gMC->SetClipBox(".");
1781   gMC->SetClipBox("TPMW",-300,300,-300,300,254.,270.);
1782   gMC->SetClipBox("TESR",-300,300,-300,300,254.,270.);
1783   gMC->SetClipBox("TSSW",-300,300,-300,300,283.,284.);
1784   gMC->SetClipBox("TSWC",-300,300,-300,300,283.,284.);
1785   gMC->SetClipBox("*", 0, 300, -300, 300, -290, 290);
1786   gMC->DefaultRange();
1787   gMC->Gdraw("alic", 40, 30, 0, 12, 9.5, .025, .025);
1788   gMC->Gdhead(1111, "Time Projection Chamber");
1789   gMC->Gdman(18, 4, "MAN");
1790   gMC->Gdopt("hide","off");
1791 }
1792
1793 //_____________________________________________________________________________
1794 void AliTPCv3::CreateMaterials()
1795 {
1796   //
1797   // Define materials for version 2 of the Time Projection Chamber
1798   //
1799
1800
1801   //
1802   AliTPC::CreateMaterials();
1803 }
1804
1805 //_____________________________________________________________________________
1806 void AliTPCv3::Init()
1807 {
1808   //
1809   // Initialises version 3 of the TPC after that it has been built
1810   //
1811   Int_t *idtmed = fIdtmed->GetArray();
1812
1813   AliTPC::Init();
1814
1815   fIdSens=gMC->VolId("TDGS"); // drift gas as a sensitive volume
1816
1817   gMC->SetMaxNStep(30000); // max. number of steps increased
1818
1819   gMC->Gstpar(idtmed[2],"LOSS",5);
1820
1821   printf("*** TPC version 3 initialized ***\n");
1822   printf("Maximum number of steps = %d\n",gMC->GetMaxNStep());
1823
1824   //
1825   
1826 }
1827
1828 //_____________________________________________________________________________
1829 void AliTPCv3::StepManager()
1830 {
1831   //
1832   // Called for every step in the Time Projection Chamber
1833   //
1834
1835   //
1836   // parameters used for the energy loss calculations
1837   //
1838   const Float_t kprim = 14.35; // number of primary collisions per 1 cm
1839   const Float_t kpoti = 20.77e-9; // first ionization potential for Ne/CO2
1840   const Float_t kwIon = 35.97e-9; // energy for the ion-electron pair creation 
1841  
1842  
1843   const Float_t kbig = 1.e10;
1844
1845   Int_t id,copy;
1846   TLorentzVector pos;
1847   Float_t hits[4];
1848   Int_t vol[2];  
1849   TClonesArray &lhits = *fHits;
1850   
1851   vol[1]=0;
1852   vol[0]=0;
1853
1854   //
1855
1856   gMC->SetMaxStep(kbig);
1857   
1858   if(!gMC->IsTrackAlive()) return; // particle has disappeared
1859   
1860   Float_t charge = gMC->TrackCharge();
1861   
1862   if(TMath::Abs(charge)<=0.) return; // take only charged particles
1863   
1864   
1865   id=gMC->CurrentVolID(copy);
1866   
1867   // Check the sensitive volume
1868   
1869   if (id != fIdSens) return;
1870   
1871   //
1872   //  charged particle is in the sensitive volume
1873   //
1874   
1875   if(gMC->TrackStep() > 0) {
1876
1877     
1878     Int_t nel = (Int_t)(((gMC->Edep())-kpoti)/kwIon) + 1;
1879     nel=TMath::Min(nel,300); // 300 electrons corresponds to 10 keV
1880     
1881     gMC->TrackPosition(pos);
1882     hits[0]=pos[0];
1883     hits[1]=pos[1];
1884     hits[2]=pos[2];
1885
1886     //
1887     // check the selected side of the TPC
1888     //
1889  
1890     if(fSide && fSide*hits[2]<=0.) return;
1891
1892     hits[3]=(Float_t)nel;
1893     
1894     // Add this hit
1895    
1896     new(lhits[fNhits++]) AliTPChit(fIshunt,gAlice->CurrentTrack(),vol,hits);
1897     
1898   } 
1899   
1900   // Stemax calculation for the next step
1901   
1902   Float_t pp;
1903   TLorentzVector mom;
1904   gMC->TrackMomentum(mom);
1905   Float_t ptot=mom.Rho();
1906   Float_t betaGamma = ptot/gMC->TrackMass();
1907   
1908   Int_t pid=gMC->TrackPid();
1909   if((pid==kElectron || pid==kPositron) && ptot > 0.002)
1910     { 
1911       pp = kprim*1.58; // electrons above 20 MeV/c are on the plateau!
1912     }
1913   else
1914     {
1915       pp=kprim*BetheBloch(betaGamma);    
1916       if(TMath::Abs(charge) > 1.) pp *= (charge*charge);
1917     }
1918   
1919   Float_t random[1];
1920   gMC->Rndm(random,1); // good, old GRNDM from Geant3
1921   
1922   Double_t rnd = (Double_t)random[0];
1923   
1924   gMC->SetMaxStep(-TMath::Log(rnd)/pp);
1925   
1926 }
1927
1928 //_____________________________________________________________________________
1929 Float_t AliTPCv3::BetheBloch(Float_t bg)
1930 {
1931   //
1932   // Bethe-Bloch energy loss formula
1933   //
1934   const Double_t kp1=0.76176e-1;
1935   const Double_t kp2=10.632;
1936   const Double_t kp3=0.13279e-4;
1937   const Double_t kp4=1.8631;
1938   const Double_t kp5=1.9479;
1939
1940   Double_t dbg = (Double_t) bg;
1941
1942   Double_t beta = dbg/TMath::Sqrt(1.+dbg*dbg);
1943
1944   Double_t aa = TMath::Power(beta,kp4);
1945   Double_t bb = TMath::Power(1./dbg,kp5);
1946
1947   bb=TMath::Log(kp3+bb);
1948   
1949   return ((Float_t)((kp2-aa-bb)*kp1/aa));
1950 }