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