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