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