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