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