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