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