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