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