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