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