058488dba625755cac42d1a555108ccfc5e0d407
[u/mrichter/AliRoot.git] / TPC / AliTPCv1.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/02 07:24:11  kowal2
19 Correction in the TPC geometry.
20 Changes due to the new hit structure.
21
22 Revision 1.19  2000/07/10 20:57:39  hristov
23 Update of TPC code and macros by M.Kowalski
24
25 Revision 1.18  2000/06/30 12:07:50  kowal2
26 Updated from the TPC-PreRelease branch
27
28 Revision 1.17.2.4  2000/06/26 07:39:42  kowal2
29 Changes to obey the coding rules
30
31 Revision 1.17.2.3  2000/06/25 08:38:41  kowal2
32 Splitted from AliTPCtracking
33
34 Revision 1.17.2.2  2000/06/16 12:58:13  kowal2
35 Changed parameter settings
36
37 Revision 1.17.2.1  2000/06/09 07:15:07  kowal2
38
39 Defaults loaded automatically (hard-wired)
40 Optional parameters can be set via macro called in the constructor
41
42 Revision 1.17  2000/05/15 10:00:30  kowal2
43 Corrected bug in the TPC geometry, thanks to Ivana Hrivnacova
44
45 Revision 1.16  2000/04/17 09:37:33  kowal2
46 removed obsolete AliTPCDigitsDisplay.C
47
48 Revision 1.15.8.2  2000/04/10 08:29:48  kowal2
49
50 Different pad geometry for different sectors
51 Updated readouch chambers geometry
52
53 Revision 1.15.8.1  2000/04/10 07:56:53  kowal2
54 Not used anymore - removed
55
56 Revision 1.15  1999/11/04 17:28:07  fca
57 Correct barrel part of HV Degrader
58
59 Revision 1.14  1999/10/08 06:27:23  fca
60 Corrected bug in the HV degrader geometry, thanks to G.Tabary
61
62 Revision 1.13  1999/10/04 13:39:54  fca
63 Correct array index problem
64
65 Revision 1.12  1999/09/29 09:24:34  fca
66 Introduction of the Copyright and cvs Log
67
68 */
69
70 //
71 ///////////////////////////////////////////////////////////////////////////////
72 //                                                                           //
73 //  Time Projection Chamber version 1 -- detailed TPC and fast simulation    //
74 //                                                                           // 
75 //Begin_Html
76 /*
77 <img src="picts/AliTPCv1Class.gif">
78 */
79 //End_Html
80 //                                                                           //
81 //                                                                           //
82 ///////////////////////////////////////////////////////////////////////////////
83
84 #include <TMath.h>
85 #include <TGeometry.h>
86 #include <TNode.h>
87 #include <TBRIK.h>
88 #include <TTUBE.h>
89 #include "AliTPCv1.h"
90 #include "AliRun.h"
91 #include <iostream.h>
92 #include <fstream.h>
93
94 #include "AliMC.h"
95 #include "AliConst.h"
96
97 #include "AliTPCParam.h"
98 #include "AliTPCParamSR.h"
99 #include "AliTPCDigitsArray.h"
100 #include <TInterpreter.h>
101
102 ClassImp(AliTPCv1)
103
104 //_____________________________________________________________________________
105
106   AliTPCv1::AliTPCv1(){
107
108   fHitType = 1;
109
110 }
111  
112 //_____________________________________________________________________________
113 AliTPCv1::AliTPCv1(const char *name, const char *title) 
114   :AliTPC(name, title) {
115   //
116   // Standard constructor for Time Projection Chamber
117   //
118   fIdSens=fIdLSec=fIdUSec=0;
119
120   SetGasMixt(2,20,10,-1,0.9,0.1,0.);
121
122   if (fTPCParam)
123      fTPCParam->Write(fTPCParam->GetTitle());
124
125   fHitType=1;
126 }
127
128 //_____________________________________________________________________________
129 void AliTPCv1::CreateGeometry()
130 {
131   //-------------------------------------------------------------
132   // Creates geometry for Time Projection Chamber version 1
133   // Detailed geometry -- Fast simulation - space points
134   // at the pad-rows centers
135   // Origin M.Kowalski, INP Cracow, Marek.Kowalski@ifj.edu.pl
136   //-----------------------------------------------------------
137
138   //Begin_Html
139   /*
140     <img src="picts/AliTPC.gif">
141   */
142   //End_Html
143   //Begin_Html
144   /*
145     <img src="picts/AliTPCv1Tree.gif">
146   */
147   //End_Html
148   Float_t dm[50];
149
150   Int_t *idtmed = fIdtmed->GetArray(); // TPC media
151
152   Int_t idrotm[120]; // rotation matrices
153
154   Int_t nRotMat = 0; // actual number of rotation matrices
155
156
157   //
158   //  Mother volume (Air) - all volumes will be positioned in it
159   //
160   
161   dm[0]=0.;
162   dm[1]=360.;
163   dm[2]=12.;
164
165   //
166  
167   dm[3]= -283.7;
168   dm[4]= 66.2;
169   dm[5]= 277.95;
170
171   //
172
173   dm[6]= -255.6;
174   dm[7]= 66.2;
175   dm[8]= 277.95;
176
177   //
178
179   dm[9]= -73.3;
180   dm[10]= 59.0;
181   dm[11]= 277.95;
182
183   //
184
185   dm[12]= -73.3;
186   dm[13]= 56.9;
187   dm[14]= 277.95;
188
189   //
190
191   dm[15]= -72.1;
192   dm[16]= 56.9;
193   dm[17]= 277.95;
194
195   //
196
197   dm[18]= -72.1;
198   dm[19]= 60.65;
199   dm[20]= 277.95;
200
201   //
202
203   dm[21]= 72.1;
204   dm[22]= 60.65;
205   dm[23]= 277.95;  
206
207   //
208
209   dm[24]= 72.1;
210   dm[25]= 56.9;
211   dm[26]= 277.95;
212
213   //
214
215   dm[27]= 73.3;
216   dm[28]= 56.9;
217   dm[29]= 277.95;
218
219   //
220
221   dm[30]= 73.3;
222   dm[31]= 60.65;
223   dm[32]= 277.95;
224
225   //
226
227   dm[33]= 250.4;
228   dm[34]= 66.0;
229   dm[35]= 277.95;
230
231   //
232
233   dm[36]= 283.7;
234   dm[37]= 66.0;
235   dm[38]= 277.95;
236
237
238   gMC->Gsvolu("TPC ","PCON",idtmed[0],dm,39);
239
240
241   //-------------------------------------------------------------------
242   //  Tpc Outer INsulator (CO2)
243   //-------------------------------------------------------------------
244
245   dm[0]= 0.;
246   dm[1]= 360.;
247   dm[2]= 6.;
248
249   //
250  
251   dm[3]= -253.6;
252   dm[4]= 258.;
253   dm[5]= 266.65;
254
255   //
256
257   dm[6]= -253.;
258   dm[7]= 258.;
259   dm[8]= 266.65;
260
261   dm[9]= -253.;
262   dm[10]= 258.;
263   dm[11]= 277.97;
264
265   dm[12]= 253.6;
266   dm[13]= 258.;
267   dm[14]= 277.97;
268
269   //
270
271   dm[15]= 253.6;
272   dm[16]= 265.2;
273   dm[17]= 277.95;
274
275   //
276
277   dm[18]= 255.6;
278   dm[19]= 265.2;
279   dm[20]= 277.95;
280
281
282   gMC->Gsvolu("TOIN","PCON",idtmed[3],dm,21);
283
284   //---------------------------------------------------------------
285   // shreds (G10) - TPC Rings
286   //---------------------------------------------------------------
287
288   gMC->Gsvolu("TPCR","TUBE",idtmed[12],dm,0);
289
290   dm[0]= 258.;
291   dm[1]= 266.65;
292   dm[2]= 0.3;
293
294   gMC->Gsposp("TPCR",1,"TOIN",0.,0.,-253.3,0,"ONLY",dm,3); // left bottom
295
296   //
297
298   dm[0]= 258.;
299   dm[1]= 270.9;
300   dm[2]= 0.3;
301
302   gMC->Gsposp("TPCR",2,"TOIN",0.,0.,253.3,0,"ONLY",dm,3); // right
303
304   //
305
306   dm[0]= 272.2;
307   dm[1]= 277.95;
308   dm[2]= 0.3;
309
310   gMC->Gsposp("TPCR",3,"TOIN",0.,0.,-250.7,0,"ONLY",dm,3); // left top
311
312   //----------------------------------------------------------------
313   // Tpc Outer Contaiment Vessel  
314   //  mother volume - Al, daughters - composite (sandwich)
315   //----------------------------------------------------------------
316   
317   dm[0]= 0.;
318   dm[1]= 360.;
319   dm[2]=5.;
320
321   //
322
323   dm[3]= -250.4;
324   dm[4]= 272.2;
325   dm[5]= 277.95;
326
327   //
328
329   dm[6]= -248.4;
330   dm[7]= 272.2;
331   dm[8]= 277.95;
332
333   //
334
335   dm[9]= 253.6;
336   dm[10]= 272.2;
337   dm[11]= 277.95;
338
339   //
340
341   dm[12]= 253.6;
342   dm[13]= 265.2;
343   dm[14]= 277.95;
344
345   // 
346
347   dm[15]= 255.6;
348   dm[16]= 265.2;
349   dm[17]= 277.95;
350
351   gMC->Gsvolu("TOCV","PCON",idtmed[4],dm,18);
352
353   // Daughter volumes
354
355   // Tpc SAndwich 1 - Al
356  
357   dm[0]= 274.81;
358   dm[1]= 277.95;
359   dm[2]= 251.7;
360
361   gMC->Gsvolu("TSA1","TUBE",idtmed[4],dm,3);
362
363   // Tpc SAndwich 2 - Tedlar
364
365   dm[0] += 5.e-3;
366   dm[1] -= 5.e-3;
367   
368   gMC->Gsvolu("TSA2","TUBE",idtmed[9],dm,3);
369
370   // Tpc SAndwich 3 - Kevlar
371
372   dm[0] += 5e-3;
373   dm[1] -= 5.e-3;
374
375   gMC->Gsvolu("TSA3","TUBE",idtmed[5],dm,3);
376
377   // Tpc SAndwich 4 - NOMEX honeycomb
378
379   dm[0] += 0.06;
380   dm[1] -= 0.06;
381
382   gMC->Gsvolu("TSA4","TUBE",idtmed[5],dm,3);  
383   
384   // 4->3->2->1->TOCV
385
386   gMC->Gspos("TSA4",1,"TSA3",0.,0.,0.,0,"ONLY");
387   gMC->Gspos("TSA3",1,"TSA2",0.,0.,0.,0,"ONLY");
388   gMC->Gspos("TSA2",1,"TSA1",0.,0.,0.,0,"ONLY");
389
390   gMC->Gspos("TSA1",1,"TOCV",0.,0.,2.6,0,"ONLY");
391
392   // TCOV-> TOIN
393
394   gMC->Gspos("TOCV",1,"TOIN",0.,0.,0.,0,"ONLY");
395
396   //-------------------------------------------------------
397   //  Tpc Outer Field Cage
398   //  mother volume - Al, daughters - composite (sandwich)
399   //-------------------------------------------------------
400
401   dm[0]=0.;
402   dm[1]=360.;
403   dm[2]=6.;
404
405   dm[3]= -253.;
406   dm[4]= 258.;
407   dm[5]= 277.95;
408
409   //
410
411   dm[6]= -251.;
412   dm[7]= 258.;
413   dm[8]= 277.95;
414
415   //
416  
417   dm[9]= -251.;
418   dm[10]= 258.;
419   dm[11]= 260.05;
420
421   //
422
423   dm[12]= 251.;
424   dm[13]= 258.;
425   dm[14]= 260.05;
426
427   //
428
429   dm[15]= 251.;
430   dm[16]= 258.;
431   dm[17]= 260.05;
432
433   //
434
435   dm[18]= 253.;
436   dm[19]= 258.;
437   dm[20]= 270.9;
438
439   gMC->Gsvolu("TOFC","PCON",idtmed[4],dm,21);  
440
441   // Daughter volumes 
442
443   // Tpc SAndwich 5 - Tedlar
444
445   dm[0]= 258.;
446   dm[1]= 260.05;
447   dm[2]= 251.7;
448
449   gMC->Gsvolu("TSA5","TUBE",idtmed[9],dm,3);
450
451   // Tpc SAndwich 6 - Kevlar
452
453   dm[0] += 5.e-3;
454   dm[1] -= 5.e-3;
455
456   gMC->Gsvolu("TSA6","TUBE",idtmed[5],dm,3);
457
458
459   // Tpc SAndwich 7 - NOMEX
460
461   dm[0] += 0.02;
462   dm[1] -= 0.02;
463
464   gMC->Gsvolu("TSA7","TUBE",idtmed[6],dm,3);    
465
466   // 7->6->5->TOFC
467
468   gMC->Gspos("TSA7",1,"TSA6",0.,0.,0.,0,"ONLY");
469   gMC->Gspos("TSA6",1,"TSA5",0.,0.,0.,0,"ONLY"); 
470
471   gMC->Gspos("TSA5",1,"TOFC",0.,0.,0.,0,"ONLY");
472
473   // TOFC->TOIN
474
475   gMC->Gspos("TOFC",1,"TOIN",0.,0.,0.,0,"ONLY"); 
476
477   // TOIN->TPC
478
479   gMC->Gspos("TOIN",1,"TPC ",0.,0.,0.,0,"ONLY");
480
481   //--------------------------------------------------------------------
482   // Tpc Inner INsulator (CO2)
483   //--------------------------------------------------------------------
484
485
486   dm[0]=0.;
487   dm[1]= 360.;
488   dm[2]= 15.;
489
490   //
491
492   dm[3]= -255.6;
493   dm[4]= 66.2;
494   dm[5]= 74.8;
495
496   //
497
498   Float_t tanL = (66.2-59.0)/(255.6-73.3); // tangent of the left cone part
499
500   dm[6]= -253.6;
501   dm[7]= 59.0+ (253.6-73.3)*tanL;
502   dm[8]= 74.8;
503
504   //
505
506   dm[9]= -253.6;
507   dm[10]= dm[7];
508   dm[11]= 79.2;
509
510   //
511
512   dm[12]= -73.3;
513   dm[13]= 59.0;
514   dm[14]= 79.2;
515
516   //
517
518   dm[15]= -73.3;
519   dm[16]= 56.9;
520   dm[17]= 79.2;
521
522   //
523
524   dm[18]= -72.1;
525   dm[19]= 59.6;
526   dm[20]= 79.2;
527
528   //
529
530   dm[21]= -72.1;
531   dm[22]= 60.65;
532   dm[23]= 79.2;
533
534   //
535
536   dm[24]= 72.1;
537   dm[25]= 60.65;
538   dm[26]= 79.2;  
539
540   //
541
542   dm[27]= 72.1;
543   dm[28]= 59.6;
544   dm[29]= 79.2;
545
546   //
547
548   dm[30]= 73.3;
549   dm[31]= 56.9;
550   dm[32]= 79.2;
551
552   //
553
554   dm[33]= 73.3;
555   dm[34]= 59.0;
556   dm[35]= 79.2;
557
558   //
559
560   dm[36]= 250.4;
561   dm[37]= 66.0;
562   dm[38]= 79.2;
563
564   //
565   
566   dm[39]= 253.0;
567   dm[40]= 66.0;
568   dm[41]= 79.2;
569
570   //
571
572   dm[42]= 253.0;
573   dm[43]= 75.3;
574   dm[44]= 79.2;
575
576   //
577
578   dm[45]= 253.6;
579   dm[46]= 75.3;
580   dm[47]= 79.2;
581
582   gMC->Gsvolu("TIIN","PCON",idtmed[3],dm,48);
583
584
585   //--------------------------------------------------------------------
586   //  Tpc Inner Containment vessel, Left part
587   //  mother volume - Al, daughter - composite (sandwich)
588   //--------------------------------------------------------------------
589
590   dm[0]= 0.;
591   dm[1]= 360.;
592   dm[2]= 8.;
593
594   //
595
596   dm[3]= -255.6;
597   dm[4]= 66.2;
598   dm[5]= 74.8;
599
600   //
601
602   Float_t cosL = 1./TMath::Sqrt(1.+tanL*tanL);
603   Float_t sandThick = 2.14; // cone composite thickness
604
605
606   //
607
608   dm[6]= -253.6;
609   dm[7]= 59.0 + (253.6-73.3)*tanL;
610   dm[8]= 74.8;
611
612   //
613
614   dm[9]= -253.6;
615   dm[10]= dm[7];
616   dm[11]= dm[7]+sandThick/cosL;
617
618   //
619
620   dm[12]= -75.6;
621   dm[13]= 59.0+(75.6-73.3)*tanL;
622   dm[14]= dm[13]+sandThick/cosL;
623
624   //
625
626   dm[15]= -75.6;
627   dm[16]= dm[13];
628   dm[17]= 60.65;
629
630   //
631
632   dm[18]= -73.3;
633   dm[19]= 59.0;
634   dm[20]= 60.65;
635
636   //
637
638   dm[21]= -73.3;
639   dm[22]= 56.9;
640   dm[23]= 60.65;
641
642   //
643
644   dm[24]= -72.1;
645   dm[25]= 56.9;
646   dm[26]= 60.65;
647
648   gMC->Gsvolu("TICL","PCON",idtmed[4],dm,27);
649
650   // Daughter volumes 
651
652   // Tpc SAndwich 9 - Al
653
654   dm[0]= 0.;
655   dm[1]= 360.;
656   dm[2]= 2.;
657
658   //
659
660   dm[3]= - 254.3;
661   dm[4]= 59.0+(254.3-73.3)*tanL;
662   dm[5]= dm[4]+sandThick/cosL;
663
664   //
665
666   dm[6]= -78.3;
667   dm[7]= 59.0+(78.3-73.3)*tanL;
668   dm[8]= dm[7]+sandThick/cosL;
669
670   //
671
672   gMC->Gsvolu("TSA9","PCON",idtmed[4],dm,9);
673
674   // Tpc SAndwich 10 - Tedlar
675
676   dm[4]+= 5.e-3/cosL;
677   dm[5]-= 5.e-3/cosL;
678
679   //
680
681   dm[7]+= 5.e-3/cosL;
682   dm[8]+= 5.e-3/cosL;
683
684   gMC->Gsvolu("TS10","PCON",idtmed[9],dm,9); 
685
686   // Tpc SAndwich 11 - Kevlar
687
688   dm[4]+= 5.e-3/cosL;
689   dm[5]-= 5.e-3/cosL;
690
691   //
692
693   dm[7]+= 5.e-3/cosL;
694   dm[8]+= 5.e-3/cosL;
695
696   gMC->Gsvolu("TS11","PCON",idtmed[5],dm,9); 
697
698   // Tpc SAndwich 12 - NOMEX
699
700   dm[4]+= 0.06/cosL;
701   dm[5]-= 0.06/cosL;
702
703   //
704
705   dm[7]+= 0.06/cosL;
706   dm[8]+= 0.06/cosL;
707
708   gMC->Gsvolu("TS12","PCON",idtmed[6],dm,9);   
709
710   // 12->11->10->9
711
712   gMC->Gspos("TS12",1,"TS11",0.,0.,0.,0,"ONLY");
713   gMC->Gspos("TS11",1,"TS10",0.,0.,0.,0,"ONLY");
714   gMC->Gspos("TS10",1,"TSA9",0.,0.,0.,0,"ONLY");
715
716   // TSA9->TICL
717
718   gMC->Gspos("TSA9",1,"TICL",0.,0.,0.,0,"ONLY");
719  
720   //--------------------------------------------------------------------
721   //  Tpc Inner Containment vessel, Right part
722   //  mother volume - Al, daughter - composite (sandwich)
723   //--------------------------------------------------------------------
724
725   dm[0]= 0.;
726   dm[1]= 360.;
727   dm[2]=8.;
728
729   //
730
731   dm[3]= 72.1;
732   dm[4]= 56.9;
733   dm[5]= 60.65;
734
735   //
736
737   dm[6]= 73.3;
738   dm[7]= 56.9;
739   dm[8]= 60.65;
740
741   //
742
743   dm[9]= 73.3;
744   dm[10]= 59.0;
745   dm[11]= 60.65;
746
747   //
748
749   Float_t tanR = (66.0-59.0)/(250.5-73.3); // to avoid accuracy problems
750   Float_t cosR = 1./TMath::Sqrt(1.+tanR*tanR); //as above
751
752   //
753
754   dm[12]= 75.6;
755   dm[13]= 59.0+(75.6-73.3)*tanR;
756   dm[14]= 60.65;
757
758   //
759
760   dm[15]= 75.6;
761   dm[16]= dm[13];
762   dm[17]= dm[16]+sandThick/cosR;
763
764   //
765
766   dm[18]= 248.4;
767   dm[19]= 59.0+(248.4-73.3)*tanR;
768   dm[20]= dm[19]+sandThick/cosR;
769
770   //
771
772   dm[21]= 248.4;
773   dm[22]= dm[19];
774   dm[23]= 70.2;
775
776   //
777
778   dm[24]= 250.4;
779   dm[25]= 66.0;
780   dm[26]= 70.2;
781
782   gMC->Gsvolu("TICR","PCON",idtmed[4],dm,27);
783
784
785
786   // Daughter volumes 
787
788   // Tpc SAndwich 13 - Al
789
790   dm[0]= 0.;
791   dm[1]= 360.;
792   dm[2]= 2.;
793
794   //
795
796   dm[3]= 78.3;
797   dm[4]= 59.0+(78.3-73.3)*tanR;
798   dm[5]= dm[4]+sandThick/cosR;
799
800   //
801
802   dm[6]= 249.1;
803   dm[7]= 59.0+(249.1-73.3)*tanR;
804   dm[8]= dm[7]+sandThick/cosR;
805
806   //
807
808   gMC->Gsvolu("TS13","PCON",idtmed[4],dm,9);
809
810   // Tpc SAndwich 14 - Tedlar
811
812   dm[4]+= 5.e-3/cosR;
813   dm[5]-= 5.e-3/cosR;
814
815   //
816
817   dm[7]+= 5.e-3/cosR;
818   dm[8]+= 5.e-3/cosR;
819
820   gMC->Gsvolu("TS14","PCON",idtmed[9],dm,9); 
821
822   // Tpc SAndwich 15 - Kevlar
823
824   dm[4]+= 5.e-3/cosR;
825   dm[5]-= 5.e-3/cosR;
826
827   //
828
829   dm[7]+= 5.e-3/cosR;
830   dm[8]+= 5.e-3/cosR;
831
832   gMC->Gsvolu("TS15","PCON",idtmed[5],dm,9); 
833
834   // Tpc SAndwich 16 - NOMEX
835
836   dm[4]+= 0.06/cosR;
837   dm[5]-= 0.06/cosR;
838
839   //
840
841   dm[7]+= 0.06/cosR;
842   dm[8]+= 0.06/cosR;
843
844   gMC->Gsvolu("TS16","PCON",idtmed[6],dm,9);   
845
846   // 16->15->14->13
847
848   gMC->Gspos("TS16",1,"TS15",0.,0.,0.,0,"ONLY");
849   gMC->Gspos("TS15",1,"TS14",0.,0.,0.,0,"ONLY");
850   gMC->Gspos("TS14",1,"TS13",0.,0.,0.,0,"ONLY");
851
852   // TS12->TICR
853
854   gMC->Gspos("TS13",1,"TICR",0.,0.,0.,0,"ONLY");
855
856   //------------------------------------------------------
857   // Tpc Inner Field Cage
858   // mother volume - Al, daughters - composite (sandwich)
859   //------------------------------------------------------
860
861   dm[0]= 0.;
862   dm[1]= 360.;
863   dm[2]=6.;
864
865   //
866
867   dm[3]= -253.0;
868   dm[4]= 70.7;
869   dm[5]= 79.2;
870
871   //
872
873   dm[6]= -251.0;
874   dm[7]= 70.7;
875   dm[8]= 79.2;
876
877   //
878
879   dm[9]= -251.0;
880   dm[10]= 77.15;
881   dm[11]= 79.2;
882
883   //
884   
885   dm[12]= 251.0;
886   dm[13]= 77.15;
887   dm[14]= 79.2;
888
889   //
890
891   dm[15]= 251.0;
892   dm[16]= 66.0;
893   dm[17]= 79.2;
894
895   //
896
897   dm[18]= 253.0;
898   dm[19]= 66.0;
899   dm[20]= 79.2;
900
901   gMC->Gsvolu("TIFC","PCON",idtmed[4],dm,21);
902
903   // Daughter volumes
904
905   // Tpc Sandwich 17 - Tedlar
906
907   dm[0]= 77.15;
908   dm[1]= 79.2;
909   dm[2]= 251.7;
910
911   gMC->Gsvolu("TS17","TUBE",idtmed[9],dm,3);
912
913   // Tpc Sandwich 18 - Kevlar
914
915   dm[0]+= 5.e-3;
916   dm[1]-= 5.e-3;
917
918   gMC->Gsvolu("TS18","TUBE",idtmed[5],dm,3);
919
920
921   // Tpc Sandwich 19 - NOMEX
922
923   dm[0]+= 0.02;
924   dm[1]-= 0.02;
925
926   gMC->Gsvolu("TS19","TUBE",idtmed[6],dm,3);
927
928   // 19->18->17
929
930   gMC->Gspos("TS19",1,"TS18",0.,0.,0.,0,"ONLY");
931   gMC->Gspos("TS18",1,"TS17",0.,0.,0.,0,"ONLY");
932
933   // TS17->TIFC
934
935   gMC->Gspos("TS17",1,"TIFC",0.,0.,0.,0,"ONLY");
936
937   // TPC Rings
938
939   dm[0]= 70.7;
940   dm[1]= 79.2;
941   dm[2]= 0.3;
942
943   gMC->Gsposp("TPCR",4,"TIIN",0.,0.,-253.3,0,"ONLY",dm,3);
944
945   dm[0]= 66.0;
946   dm[1]= 70.2;  
947
948   gMC->Gsposp("TPCR",5,"TIIN",0.,0.,250.7,0,"ONLY",dm,3);
949
950   dm[0]= 75.3;
951   dm[1]= 79.2;  
952
953   gMC->Gsposp("TPCR",6,"TIIN",0.,0.,253.3,0,"ONLY",dm,3);  
954
955   // TICL->TIIN
956
957   gMC->Gspos("TICL",1,"TIIN",0.,0.,0.,0,"ONLY");
958
959   // TICR->TIIN
960
961   gMC->Gspos("TICR",1,"TIIN",0.,0.,0.,0,"ONLY");
962
963   // TIFC->TIIN
964
965   gMC->Gspos("TIFC",1,"TIIN",0.,0.,0.,0,"ONLY");
966
967   // Tpc Sandwich 21 - Al (central barrel)
968
969   dm[0]= 60.65;
970   dm[1]= 61.21;
971   dm[2]= 75.2;
972
973   gMC->Gsvolu("TS21","TUBE",idtmed[4],dm,3);
974
975   // Tpc Sandwich 22 - Tedlar (central barrel) 
976
977   dm[0]+= 5.e-3;
978   dm[1]-= 5.e-3;
979
980   gMC->Gsvolu("TS22","TUBE",idtmed[9],dm,3); 
981
982   // Tpc Sandwich 23 - Kevlar (central barrel) 
983
984   dm[0]+= 5.e-3;
985   dm[1]-= 5.e-3;
986
987   gMC->Gsvolu("TS23","TUBE",idtmed[5],dm,3); 
988
989   // Tpc Sandwich 24 - NOMEX (central barrel) 
990
991   dm[0]+= 0.02;
992   dm[1]-= 0.02;
993
994   gMC->Gsvolu("TS24","TUBE",idtmed[6],dm,3); 
995
996   // 24->23->22->21
997
998   gMC->Gspos("TS24",1,"TS23",0.,0.,0.,0,"ONLY");
999   gMC->Gspos("TS23",1,"TS22",0.,0.,0.,0,"ONLY");
1000   gMC->Gspos("TS22",1,"TS21",0.,0.,0.,0,"ONLY");
1001
1002   gMC->Gspos("TS21",1,"TIIN",0.,0.,0.,0,"ONLY");
1003
1004   // put everything into the TPC 
1005
1006   gMC->Gspos("TIIN",1,"TPC ",0.,0.,0.,0,"ONLY");
1007
1008
1009   //---------------------------------------------------------
1010   //  Tpc Dift Gas volume Nonsensitive (Ne-CO2 90/10)
1011   //  and its daughters (HV membrane, rods, readout chambers)
1012   //---------------------------------------------------------
1013
1014   dm[0]= 79.2;
1015   dm[1]= 258.0;
1016   dm[2]= 253.6;
1017
1018   gMC->Gsvolu("TDGN","TUBE",idtmed[1],dm,3);  
1019
1020   // sector opening angles
1021
1022   Float_t innerOpenAngle = fTPCParam->GetInnerAngle();
1023   Float_t outerOpenAngle = fTPCParam->GetOuterAngle();
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[1],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.2,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 Outer 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[1],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",11,"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   //  End caps
1372   //--------------------------------------------------------------------------
1373
1374   // TPc Main Wheel - Al
1375
1376   dm[0]= 75.3;
1377   dm[1]= 264.8;
1378   dm[2]= 3.0;
1379
1380   gMC->Gsvolu("TPMW","TUBE",idtmed[4],dm,3);
1381
1382   // TPc Extra Wheel (to avoid overlapping) - Al
1383
1384   dm[0]= 264.8;
1385   dm[1]= 277.0;
1386   dm[2]= 1.95;
1387
1388   gMC->Gsvolu("TPEW","TUBE",idtmed[4],dm,3);
1389
1390   //--------------------------------------------------------------------------
1391   //  Tpc Empty Space for the Readout chambers
1392   //--------------------------------------------------------------------------  
1393
1394   Float_t rLow= 86.2;
1395   Float_t rUp= 243.5;
1396   Float_t dR = 0.5*(rUp-rLow);
1397
1398   space= 1.4/cosAlpha; // wheel ribs are 2.8 cm wide
1399
1400   dm[0]= rLow*tanAlpha-space;
1401   dm[1]= rUp*tanAlpha-space;
1402   dm[2]= 3.0;
1403   dm[3]= dR;
1404
1405   gMC->Gsvolu("TESR","TRD1",idtmed[0],dm,4);
1406
1407   // TIC1->TESR
1408
1409
1410   gMC->Gspos("TIC1",1,"TESR",0.,0.75,-dR+23.97,0,"ONLY");
1411
1412
1413   // TOC1->TESR
1414
1415   gMC->Gspos("TOC1",1,"TESR",0.,0.75,dR-55.02,0,"ONLY");
1416
1417   // Tpc Empty Space Bars - Al (daughters of TESR)
1418
1419   Float_t zBar;
1420
1421   gMC->Gsvolu("TESB","TRD1",idtmed[4],dm,0);
1422
1423   // lower bar
1424
1425   dm[0]= rLow*tanAlpha-space;
1426   dm[1]= 88.7*tanAlpha-space;
1427   dm[2]= 0.95;
1428   dm[3]= 1.275;
1429
1430   zBar = -dR+dm[3];
1431
1432   gMC->Gsposp("TESB",1,"TESR",0.,2.05,zBar,0,"ONLY",dm,4);
1433
1434   // middle bar
1435
1436   dm[0]= 131.65*tanAlpha-space;
1437   dm[1]= 136.5*tanAlpha-space;
1438   dm[3]= 2.425;
1439
1440   zBar = -dR +131.65+dm[3]-rLow;
1441
1442   gMC->Gsposp("TESB",2,"TESR",0.,2.05,zBar,0,"ONLY",dm,4);
1443
1444   // upper bar
1445
1446   dm[0]= 240.4*tanAlpha-space;
1447   dm[1]= rUp*tanAlpha-space;
1448   dm[3]= 1.55;
1449
1450   zBar = dR-dm[3];
1451
1452   gMC->Gsposp("TESB",3,"TESR",0.,2.05,zBar,0,"ONLY",dm,4);
1453
1454   //------------------------------------------------------
1455   //  TPc Lower "S" Sectors 
1456   //------------------------------------------------------
1457   
1458   Float_t deadSpace;
1459
1460
1461   Float_t inSecLowEdge = fTPCParam->GetInnerRadiusLow();
1462   Float_t inSecUpEdge =  fTPCParam->GetInnerRadiusUp();
1463
1464   dm[0] = inSecLowEdge*TMath::Tan(0.5*innerOpenAngle)-0.01;
1465   dm[1] = inSecUpEdge*TMath::Tan(0.5*innerOpenAngle)-0.01;
1466   dm[2] = 0.5*(250. - 0.3);
1467   dm[3] = 0.5*(inSecUpEdge-inSecLowEdge);  
1468
1469   gMC->Gsvolu("TPLS", "TRD1", idtmed[1], dm, 4); // nonsensitive 
1470
1471   //----------------------------------------------------------
1472   //  TPc Upper Sectors
1473   //----------------------------------------------------------
1474
1475   Float_t ouSecLowEdge = fTPCParam->GetOuterRadiusLow();
1476   Float_t ouSecUpEdge = fTPCParam->GetOuterRadiusUp();
1477
1478   dm[0] = ouSecLowEdge*TMath::Tan(0.5*outerOpenAngle)-0.01;  
1479   dm[1] = ouSecUpEdge*TMath::Tan(0.5*outerOpenAngle)-0.01;  
1480   dm[2] = 0.5*(250. - 0.3);
1481   dm[3] = 0.5*(ouSecUpEdge-ouSecLowEdge);
1482
1483   gMC->Gsvolu("TPUS", "TRD1", idtmed[1], dm, 4); // nonsensitive   
1484
1485   //--------------------------------------------------------
1486   // TPc Sensitive Strips, the same for S and L sectors
1487   //--------------------------------------------------------
1488
1489   gMC->Gsvolu("TPSS","TRD1",idtmed[2],dm,0); // sensitive
1490
1491   Int_t nofStrips,nstr;
1492   Float_t r1,r2,zs;
1493   Float_t stripThick = 0.01; // 100 microns
1494
1495   // inner sector
1496
1497   nofStrips = fTPCParam->GetNRowLow();
1498   deadSpace = fTPCParam->GetInnerWireMount();
1499
1500   dm[2] = 0.5*(250. - 0.3);
1501   dm[3] = 0.5 * stripThick;
1502
1503   for(nstr=0;nstr<nofStrips;nstr++){
1504
1505     r1 = fTPCParam->GetPadRowRadiiLow(nstr);
1506     r2 = r1 + stripThick;     
1507     dm[0] = r1 * TMath::Tan(0.5*innerOpenAngle) - deadSpace;
1508     dm[1] = r2 * TMath::Tan(0.5*innerOpenAngle) - deadSpace;
1509     zs = -inSecLowEdge -0.5*(inSecUpEdge-inSecLowEdge);
1510     zs += r1;
1511     zs += dm[3];
1512     
1513     gMC->Gsposp("TPSS", nstr+1, "TPLS", 0., 0., zs, 0, "ONLY", dm, 4);
1514
1515   }
1516
1517   Int_t nsSave = nofStrips;
1518
1519   // outer sector
1520
1521   nofStrips = fTPCParam->GetNRowUp();
1522   deadSpace = fTPCParam->GetOuterWireMount();
1523
1524   dm[2] = 0.5*(250. - 0.3);
1525   dm[3] = 0.5 * stripThick;
1526   
1527    for(nstr=0;nstr<nofStrips;nstr++){
1528     
1529     r1 = fTPCParam->GetPadRowRadiiUp(nstr); 
1530     r2 = r1 + stripThick;
1531     dm[0] = r1 * TMath::Tan(0.5*outerOpenAngle) - deadSpace;
1532     dm[1] = r2 * TMath::Tan(0.5*outerOpenAngle) - deadSpace;
1533     zs = -ouSecLowEdge -0.5*(ouSecUpEdge-ouSecLowEdge);
1534     zs += r1;
1535     zs += dm[3];
1536
1537     gMC->Gsposp("TPSS", nstr+1+nsSave, "TPUS", 0., 0., zs, 0, "ONLY", dm, 4);
1538
1539    } 
1540   
1541
1542   //-------------------------------------------------------
1543   //  positioning of the empty spaces into the main wheel
1544   //  and readout chambers and sectors into the drift gas
1545   //-------------------------------------------------------
1546
1547   Float_t rCenter,xc,yc;
1548   Float_t rInner,rOuter; // center of the inner and outer chamber
1549
1550   rCenter = rLow+dR;
1551
1552   rInner = 108.07;
1553   rOuter = 190.68;
1554
1555   for(Int_t ns=0; ns<nInnerSector;ns++){
1556
1557     phi1 = ns * innerOpenAngle + innerAngleShift;
1558     phi1 *= kRaddeg; // in degrees
1559
1560     phi1 = (Float_t)TMath::Nint(phi1) + 270.;
1561
1562     if (phi1 > 360.) phi1 -= 360.;
1563
1564     theta1 = 90.;
1565     phi2   = 90.;
1566     theta2 = 180.;
1567     phi3   = ns * innerOpenAngle + innerAngleShift;
1568     phi3 *= kRaddeg; // in degrees
1569
1570     phi3 = (Float_t)TMath::Nint(phi3);
1571       
1572     if(phi3 > 360.) phi3 -= 360.;
1573
1574     theta3 = 90.;
1575
1576     // "holes"->End plate
1577
1578     xc = rCenter*TMath::Cos(phi3*kDegrad);
1579     yc = rCenter*TMath::Sin(phi3*kDegrad);
1580
1581     AliMatrix(idrotm[nRotMat], theta1, phi1, theta2, phi2, theta3, phi3);
1582
1583     gMC->Gspos("TESR",ns+1,"TPMW",xc,yc,0.,idrotm[nRotMat],"ONLY");
1584
1585     // TSCE->TSWC (services wheel volumes)
1586
1587     xc = 166.142*TMath::Cos(phi3*kDegrad);
1588     yc = 166.142*TMath::Sin(phi3*kDegrad);
1589
1590     gMC->Gspos("TSCE",ns+1,"TSWC",xc,yc,0.,idrotm[nRotMat],"ONLY");
1591     gMC->Gspos("TWES",ns+1,"TSSW",xc,yc,0.,idrotm[nRotMat],"ONLY");
1592
1593
1594     // readout chambers->TDGN (drift gas)
1595
1596     xc = rInner*TMath::Cos(phi3*kDegrad);
1597     yc = rInner*TMath::Sin(phi3*kDegrad);
1598
1599     gMC->Gspos("TIRC",ns+1,"TDGN",xc,yc,252.,idrotm[nRotMat],"ONLY");
1600
1601     // here lower sectors 
1602
1603     gMC->Gspos("TPLS",ns+1,"TDGN",xc,yc,125.15,idrotm[nRotMat],"ONLY");
1604     gMC->Gspos("TPLS",ns+nInnerSector+1,"TDGN",xc,yc,-125.15,idrotm[nRotMat],"ONLY");
1605      
1606     xc = rOuter*TMath::Cos(phi3*kDegrad);
1607     yc = rOuter*TMath::Sin(phi3*kDegrad);
1608
1609     gMC->Gspos("TORC",ns+1,"TDGN",xc,yc,252.1,idrotm[nRotMat],"ONLY");
1610
1611     // here upper sectors 
1612
1613     gMC->Gspos("TPUS",ns+1,"TDGN",xc,yc,125.15,idrotm[nRotMat],"ONLY");
1614     gMC->Gspos("TPUS",ns+nOuterSector+1,"TDGN",xc,yc,-125.15,idrotm[nRotMat],"ONLY");
1615
1616     nRotMat++;
1617
1618     theta2 = 0.; // reflection
1619
1620     AliMatrix(idrotm[nRotMat], theta1, phi1, theta2, phi2, theta3, phi3);
1621
1622     xc = rInner*TMath::Cos(phi3*kDegrad);
1623     yc = rInner*TMath::Sin(phi3*kDegrad);
1624
1625     gMC->Gspos("TIRC",ns+nInnerSector+1,"TDGN",xc,yc,-252.,idrotm[nRotMat],"ONLY");
1626
1627     xc = rOuter*TMath::Cos(phi3*kDegrad);
1628     yc = rOuter*TMath::Sin(phi3*kDegrad);
1629
1630     gMC->Gspos("TORC",ns+nOuterSector+1,"TDGN",xc,yc,-252.1,idrotm[nRotMat],"ONLY");
1631
1632     nRotMat++;
1633
1634   } 
1635
1636   // reflection matrix
1637
1638   theta1 = 90.;
1639   phi1   = 0.;
1640   theta2 = 90.;
1641   phi2   = 270.;
1642   theta3 = 180.;
1643   phi3   = 0.;
1644
1645   AliMatrix(idrotm[nRotMat], theta1, phi1, theta2, phi2, theta3, phi3);
1646
1647
1648   // TPMW->TPC
1649
1650   gMC->Gspos("TPMW",1,"TPC ",0.,0.,256.6,0,"ONLY");
1651   gMC->Gspos("TPMW",2,"TPC ",0.,0.,-256.6,idrotm[nRotMat],"ONLY");
1652   gMC->Gspos("TPEW",1,"TPC ",0.,0.,257.65,0,"ONLY");
1653   gMC->Gspos("TPEW",2,"TPC ",0.,0.,-257.5,0,"ONLY");
1654
1655
1656
1657   //-------------------------------------------------------
1658   // Tpc High Voltage Membrane - NOMEX honeycomb
1659   //-------------------------------------------------------
1660
1661   dm[0]=0.,
1662   dm[1]=360.;
1663   dm[2]=18.;
1664   dm[3]=2.;
1665
1666   //
1667
1668   dm[4]= -0.3;
1669   dm[5]= 81.156;
1670   dm[6]= 253.386;
1671
1672   //
1673
1674   dm[7]= 0.3;
1675   dm[8]= dm[5];
1676   dm[9]= dm[6];
1677
1678   gMC->Gsvolu("THVM","PGON",idtmed[6],dm,10);
1679
1680   gMC->Gspos("THVM",1,"TDGN",0.,0.,0.,0,"ONLY");
1681
1682   //----------------------------------------------------------
1683   // TPc Support Rods - MAKROLON
1684   //----------------------------------------------------------
1685
1686   dm[0]= 0.9;
1687   dm[1]= 1.2;
1688   dm[2]= 126.65;
1689
1690   gMC->Gsvolu("TPSR","TUBE",idtmed[7],dm,3);
1691
1692   for(Int_t nrod=1;nrod<18;nrod++){
1693     Float_t angle=innerOpenAngle*(Float_t)nrod;
1694
1695     xc=82.4*TMath::Cos(angle);
1696     yc=82.4*TMath::Sin(angle);
1697
1698     gMC->Gspos("TPSR",nrod,"TDGN",xc,yc,126.95,0,"ONLY");
1699     gMC->Gspos("TPSR",nrod+17,"TDGN",xc,yc,-126.95,0,"ONLY");
1700
1701     xc=254.2*TMath::Cos(angle);
1702     yc=254.2*TMath::Sin(angle);
1703
1704     gMC->Gspos("TPSR",nrod+34,"TDGN",xc,yc,126.95,0,"ONLY");
1705     gMC->Gspos("TPSR",nrod+51,"TDGN",xc,yc,-126.95,0,"ONLY");    
1706
1707   }
1708
1709   //----------------------------------------------------------
1710   // Tpc High Voltage rod - MAKROLON + Copper cable
1711   //----------------------------------------------------------
1712
1713   // rod with cable (Left)
1714
1715   dm[0]=0.;
1716   dm[1]=2.25;
1717   dm[2]=126.65;
1718
1719   gMC->Gsvolu("THVL","TUBE",idtmed[7],dm,3);
1720
1721   // HV cable
1722  
1723   dm[0]=0.;
1724   dm[1]=0.3;
1725   dm[2]=126.65;
1726
1727   gMC->Gsvolu("THVC","TUBE",idtmed[10],dm,3);
1728
1729   // empty space
1730
1731   dm[0]=0.3;
1732   dm[1]=1.;
1733   dm[2]=126.65;
1734
1735   gMC->Gsvolu("THVE","TUBE",idtmed[1],dm,3);
1736
1737   gMC->Gspos("THVC",1,"THVL",0.,0.,0.,0,"ONLY");
1738   gMC->Gspos("THVE",1,"THVL",0.,0.,0.,0,"ONLY");
1739
1740   // rod without cable
1741
1742   dm[0]=1.8;
1743   dm[1]=2.25;
1744   dm[2]=126.65;
1745
1746   gMC->Gsvolu("THVR","TUBE",idtmed[7],dm,3);
1747
1748   
1749   
1750   gMC->Gspos("THVL",1,"TDGN",82.4,0.,-126.95,0,"ONLY");
1751   gMC->Gspos("THVL",2,"TDGN",254.2,0.,-126.95,0,"ONLY");
1752
1753   gMC->Gspos("THVR",1,"TDGN",82.4,0.,126.95,0,"ONLY");
1754   gMC->Gspos("THVR",2,"TDGN",254.2,0.,126.95,0,"ONLY");  
1755   
1756
1757
1758   gMC->Gspos("TDGN",1,"TPC ",0.,0.,0.,0,"ONLY"); 
1759
1760   // services wheel cover -> wheel
1761
1762
1763   gMC->Gspos("TSWC",1,"TSSW",0.,0.,4.5,0,"ONLY");
1764   gMC->Gspos("TSWC",2,"TSSW",0.,0.,-4.5,0,"ONLY");
1765
1766
1767   // put the wheel into the TPC
1768
1769   gMC->Gspos("TSSW",1,"TPC ",0.,0.,278.7,0,"ONLY");
1770   gMC->Gspos("TSSW",2,"TPC ",0.,0.,-278.7,0,"ONLY");
1771
1772   gMC->Gsord("TPMW",6);
1773   gMC->Gsord("TPLS",3);
1774   gMC->Gsord("TPUS",3);
1775   gMC->Gsord("TDGN",6);
1776   gMC->Gsord("TSSW",6);
1777   gMC->Gsord("TSWC",6);
1778
1779   // put the TPC into ALIC (main mother volume)
1780
1781   gMC->Gspos("TPC ", 1, "ALIC", 0, 0, 0, 0, "ONLY");
1782
1783
1784 } // end of function
1785
1786 //_____________________________________________________________________________
1787 void AliTPCv1::DrawDetector()
1788 {
1789   //
1790   // Draw a shaded view of the Time Projection Chamber version 1
1791   //
1792
1793   // Set everything unseen
1794   gMC->Gsatt("*", "seen", -1);
1795   // 
1796   // Set ALIC mother transparent
1797   gMC->Gsatt("ALIC","SEEN",0);
1798   //
1799   // Set the volumes visible
1800   gMC->Gsatt("TPC ","SEEN",0);
1801   gMC->Gsatt("TOIN","SEEN",1);
1802   gMC->Gsatt("TOIN","COLO",7);
1803   gMC->Gsatt("TPCR","SEEN",0);
1804   gMC->Gsatt("TOCV","SEEN",1);
1805   gMC->Gsatt("TOCV","COLO",4);
1806   gMC->Gsatt("TSA1","SEEN",0);
1807   gMC->Gsatt("TSA2","SEEN",0);
1808   gMC->Gsatt("TSA3","SEEN",0);
1809   gMC->Gsatt("TSA4","SEEN",0);
1810   gMC->Gsatt("TOFC","SEEN",1);
1811   gMC->Gsatt("TOFC","COLO",4);
1812   gMC->Gsatt("TSA5","SEEN",0);
1813   gMC->Gsatt("TSA6","SEEN",0);
1814   gMC->Gsatt("TSA7","SEEN",0);
1815   gMC->Gsatt("TIIN","COLO",7);
1816   gMC->Gsatt("TIIN","SEEN",1);
1817   gMC->Gsatt("TICL","SEEN",0);
1818   gMC->Gsatt("TSA9","SEEN",0);
1819   gMC->Gsatt("TS10","SEEN",0);
1820   gMC->Gsatt("TS11","SEEN",0);
1821   gMC->Gsatt("TS12","SEEN",0);
1822   gMC->Gsatt("TICR","SEEN",0); 
1823   gMC->Gsatt("TS13","SEEN",0);
1824   gMC->Gsatt("TS14","SEEN",0);
1825   gMC->Gsatt("TS15","SEEN",0);
1826   gMC->Gsatt("TS16","SEEN",0);
1827   gMC->Gsatt("TIFC","SEEN",1);
1828   gMC->Gsatt("TIFC","COLO",4); 
1829   gMC->Gsatt("TS17","SEEN",0);
1830   gMC->Gsatt("TS18","SEEN",0);
1831   gMC->Gsatt("TS19","SEEN",0);
1832   gMC->Gsatt("TS21","SEEN",0);
1833   gMC->Gsatt("TS22","SEEN",0);
1834   gMC->Gsatt("TS23","SEEN",0);
1835   gMC->Gsatt("TS24","SEEN",0);
1836   gMC->Gsatt("TDGN","SEEN",0);
1837   gMC->Gsatt("TIRC","SEEN",0);
1838   gMC->Gsatt("TIC1","SEEN",1);
1839   gMC->Gsatt("TIPP","SEEN",0);
1840   gMC->Gsatt("TIC3","SEEN",0);
1841   gMC->Gsatt("TRCE","SEEN",0);
1842   gMC->Gsatt("TPSC","SEEN",0);
1843   gMC->Gsatt("TPCC","SEEN",0);
1844   gMC->Gsatt("TORC","SEEN",0);
1845   gMC->Gsatt("TOPP","SEEN",0);
1846   gMC->Gsatt("TOC3","SEEN",0);
1847   gMC->Gsatt("TOC1","SEEN",1);
1848   gMC->Gsatt("TSSW","SEEN",1);
1849   gMC->Gsatt("TSWC","SEEN",1);
1850   gMC->Gsatt("TSCE","SEEN",1); 
1851   gMC->Gsatt("TSSW","COLO",3);
1852   gMC->Gsatt("TSWC","COLO",3);
1853   gMC->Gsatt("TSCE","COLO",6);
1854   gMC->Gsatt("TWES","SEEN",0);
1855   gMC->Gsatt("TSWB","SEEN",0);
1856   gMC->Gsatt("TPEL","SEEN",0);
1857   gMC->Gsatt("TPMW","SEEN",1);
1858   gMC->Gsatt("TPEW","SEEN",1);
1859   gMC->Gsatt("TESR","SEEN",1);
1860   gMC->Gsatt("TPMW","COLO",12);
1861   gMC->Gsatt("TPEW","COLO",12);
1862   gMC->Gsatt("TWES","COLO",5);
1863   gMC->Gsatt("TIC1","COLO",5);
1864   gMC->Gsatt("TOC1","COLO",5);  
1865   gMC->Gsatt("TESB","SEEN",0);
1866   gMC->Gsatt("TPLS","SEEN",0);
1867   gMC->Gsatt("TPUS","SEEN",0);
1868   gMC->Gsatt("TPSS","SEEN",0);
1869   gMC->Gsatt("THVM","SEEN",1);
1870   gMC->Gsatt("THVM","COLO",11);
1871   gMC->Gsatt("TPSR","SEEN",0);
1872   gMC->Gsatt("THVL","SEEN",0);
1873   gMC->Gsatt("THVC","SEEN",0);
1874   gMC->Gsatt("THVE","SEEN",0);
1875   gMC->Gsatt("THVR","SEEN",0);
1876   
1877   gMC->Gdopt("hide", "on");
1878   gMC->Gdopt("shad", "on");
1879   gMC->Gsatt("*", "fill", 7);
1880   gMC->SetClipBox(".");
1881   gMC->SetClipBox("TPMW",-300,300,-300,300,254.,270.);
1882   gMC->SetClipBox("TESR",-300,300,-300,300,254.,270.);
1883   gMC->SetClipBox("TSSW",-300,300,-300,300,283.,284.);
1884   gMC->SetClipBox("TSWC",-300,300,-300,300,283.,284.);
1885   gMC->SetClipBox("*", 0, 300, -300, 300, -290, 290);
1886   gMC->DefaultRange();
1887   gMC->Gdraw("alic", 40, 30, 0, 12, 9.5, .025, .025);
1888   gMC->Gdhead(1111, "Time Projection Chamber");
1889   gMC->Gdman(18, 4, "MAN");
1890   gMC->Gdopt("hide","off");
1891 }
1892
1893 //_____________________________________________________________________________
1894 void AliTPCv1::CreateMaterials()
1895 {
1896   //
1897   // Define materials for Time Projection Chamber
1898   //
1899   AliTPC::CreateMaterials();
1900 }
1901
1902 //_____________________________________________________________________________
1903 void AliTPCv1::Init()
1904 {
1905   //
1906   // Initialises TPC detector after it has been created
1907   //
1908
1909   fIdSens=gMC->VolId("TPSS"); // sensitive strip
1910   fIdLSec=gMC->VolId("TPLS"); // lower sector
1911   fIdUSec=gMC->VolId("TPUS"); // upper sector
1912
1913   printf("TPC version 1 initialized\n");
1914 }
1915
1916 //_____________________________________________________________________________
1917 void AliTPCv1::StepManager()
1918 {
1919   //
1920   // Called at every step in the Time Projection Chamber
1921   //
1922   Int_t         copy, id, i;
1923   Float_t       hits[4];
1924   Int_t         vol[2];
1925   TLorentzVector p;
1926  //
1927
1928   if(gMC->TrackCharge() && gMC->IsTrackEntering()) {
1929
1930     // 
1931     // Only charged tracks entering the sensitive volume
1932     //
1933
1934     id = gMC->CurrentVolID(copy);
1935
1936     if(id == fIdSens){
1937
1938       // sensitive volume (strip)
1939
1940       vol[1]= copy-1; // row number (absolute)
1941     
1942       // sector type
1943       
1944       id = gMC->CurrentVolOffID(1,copy); 
1945       
1946       if(id == fIdLSec){
1947
1948         // lower sector
1949      
1950         vol[0] = copy-1; // sector number
1951
1952       }
1953       else {
1954    
1955         // upper sector
1956
1957         vol[0] = copy-1+fTPCParam->GetNInnerSector(); // sector number
1958         vol[1] -= fTPCParam->GetNRowLow(); // row number  
1959
1960       } 
1961     
1962       if(vol[1] == 0){
1963   
1964         // because Jouri wants to have this
1965
1966         gMC->TrackMomentum(p);
1967         hits[0]=p[0];
1968         hits[1]=p[1];
1969         hits[2]=p[2];
1970         hits[3]=0.; // this hit has no energy loss
1971         // new(lhits[fNhits++]) AliTPChit(fIshunt,gAlice->CurrentTrack(),vol,hits);
1972
1973         AddHit(gAlice->CurrentTrack(), vol,hits); // M.I. 
1974
1975         gMC->TrackPosition(p);
1976         hits[0]=p[0];
1977         hits[1]=p[1];
1978         hits[2]=p[2];
1979         hits[3]=0.; // this hit has no energy loss
1980         // new(lhits[fNhits++]) AliTPChit(fIshunt,gAlice->CurrentTrack(),vol,hits);
1981
1982         AddHit(gAlice->CurrentTrack(), vol,hits); // M.I. 
1983
1984       } 
1985
1986       gMC->TrackPosition(p);
1987       for(i=0;i<3;++i) hits[i]=p[i];
1988       hits[3]=1; //I'd like to have something positive here (I.Belikov)
1989       // new(lhits[fNhits++]) AliTPChit(fIshunt,gAlice->CurrentTrack(),vol,hits);
1990
1991       AddHit(gAlice->CurrentTrack(), vol,hits); // M.I. 
1992
1993     }
1994
1995   }  
1996    
1997 }
1998 //_____________________________________________________________________________
1999
2000
2001