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