]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCv2.cxx
Syntax corrections for HP-UX
[u/mrichter/AliRoot.git] / TPC / AliTPCv2.cxx
1 ///////////////////////////////////////////////////////////////////////////////
2 //                                                                           //
3 //  Time Projection Chamber version 2 -- detailed TPC and slow simulation    //
4 //                                                                           //
5 //Begin_Html
6 /*
7 <img src="picts/AliTPCv2Class.gif">
8 */
9 //End_Html
10 //                                                                           //
11 //                                                                           //
12 ///////////////////////////////////////////////////////////////////////////////
13 #include <stdlib.h>
14
15 #include <TMath.h>
16
17 #include "AliTPCv2.h"
18 #include "AliTPCD.h"
19 #include "AliRun.h"
20 #include "AliConst.h"
21
22 ClassImp(AliTPCv2)
23  
24 //_____________________________________________________________________________
25 AliTPCv2::AliTPCv2(const char *name, const char *title) :
26   AliTPC(name, title) 
27 {
28   //
29   // Standard constructor for Time Projection Chamber version 2
30   //
31   fIdSens1=0;
32   fIdSens2=0;
33   SetBufferSize(128000);
34 }
35  
36 //_____________________________________________________________________________
37 void AliTPCv2::CreateGeometry()
38 {
39   //
40   // Create the geometry of Time Projection Chamber version 2
41   //
42   //Begin_Html
43   /*
44     <img src="picts/AliTPCv2.gif">
45   */
46   //End_Html
47   //Begin_Html
48   /*
49     <img src="picts/AliTPCv2Tree.gif">
50   */
51   //End_Html
52
53   Int_t *idtmed = fIdtmed->GetArray()-399;
54
55   AliTPCParam * fTPCParam = &(fDigParam->GetParam());
56
57   Float_t tana;
58   Int_t isll;
59   Float_t rlsl, wlsl, rssl, rlsu, wssl, wlsu, rssu, wssu;
60   Int_t i;
61   Float_t alpha, x, y, z, sec_thick;
62   
63   Float_t r1, r2, x1, z0, z1, x2, theta1, theta2, theta3, dm[21];
64   Int_t il, iu;
65   Float_t z_side, zz;
66   Int_t idrotm[100];
67   
68   Float_t x0l, x0u;
69   Int_t idr;
70   Float_t thl, opl;
71   Int_t ils, iss;
72   Float_t thu, opu;
73   Int_t ifl1 = 0, ifl2 = 0;
74   Float_t phi1, phi2, phi3;
75   
76   // --------------------------------------------------- 
77   //        sector specification check 
78   // --------------------------------------------------- 
79   if (fSecAL >= 0) {
80     ifl1 = 0;
81     
82     for (i = 0; i < 6; ++i) {
83       if (fSecLows[i] > 0 && fSecLows[i] <25) {
84         ifl1 = 1;
85         printf("*** SECTOR %d selected\n",fSecLows[i]);
86       }
87     }
88
89   } else {
90     printf("*** ALL LOWER SECTORS SELECTED ***\n");
91     ifl1 = 1;
92   }
93
94   if (fSecAU >= 0) {
95     ifl2 = 0;
96     
97     for (i = 0; i < 12; ++i) {
98       if (fSecUps[i] > 24 && fSecUps[i] < 73) {
99         ifl2 = 1;
100         printf("*** SECTOR %d selected\n",fSecUps[i]);
101       }
102     }
103     
104   } else {
105     printf("*** ALL UPPER SECTORS SELECTED ***\n");
106     ifl1 = 1;
107   }
108   
109   if (ifl1 == 0 && ifl2 == 0) {
110     printf("*** ERROR: AT LEAST ONE SECTOR MUST BE SPECIFIED ***\n");
111     printf("!!! PROGRAM STOPPED !!!\n");
112     exit(1);
113   }
114   
115   if ((fSecAL < 0 || fSecAU < 0) && fSens >= 0) {
116     printf("** ERROR: STRIPS CANNOT BE SPECIFIED FOR ALL SECTORS **\n");
117     printf("!!! PROGRAM STOPPED !!!\n");
118     exit(1);
119   }
120   // ---------------------------------------------------- 
121   //          FIELD CAGE WITH ENDCAPS - CARBON FIBER 
122   //          THIS IS ALSO A TPC MOTHER VOLUME 
123   // ---------------------------------------------------- 
124   dm[0] = 76.;
125   dm[1] = 278.;
126   dm[2] = 275.;
127   
128   gMC->Gsvolu("TPC ", "TUBE", idtmed[407], dm, 3);
129   // ------------------------------------------------------- 
130   //     drift gas Ne/CO2 (90/10 volume) - nonsensitive 
131   //     field cage thickness = 0.52% X0 
132   // ---------------------------------------------------- 
133   dm[0] = 76.+0.09776;
134   dm[1] = 257.;
135   dm[2] = 250.;
136   
137   gMC->Gsvolu("TGAS", "TUBE", idtmed[402], dm, 3);
138   // ------------------------------------------------------ 
139   //     "side" gas volume (the same as drift gas), 
140   //      here the readout chambers are positioned 
141   // ------------------------------------------------------ 
142   dm[2] = 0.5*(275.-250.);
143   z_side = dm[2];
144
145   gMC->Gsvolu("TPSG", "TUBE", idtmed[401], dm, 3);
146   // ------------------------------------------------------ 
147   //      HV midplane - 20 microns of mylar 
148   // ----------------------------------------------------- 
149   dm[2] = .001;
150   
151   gMC->Gsvolu("TPHV", "TUBE", idtmed[405], dm, 3);
152   
153   // ==================================================== 
154   //   lower and upper readout chambers 
155   // ==================================================== 
156   //   sectros opening angles in degrees 
157   // --------------------------------------------------- 
158   opl = 30.;
159   opu = 15.;
160   thl = TMath::Tan(opl * .5 * kDegrad);
161   thu = TMath::Tan(opu * .5 * kDegrad);
162   // --------------------------------------------------- 
163   //         S and L-sectors radii 
164   // --------------------------------------------------- 
165   rssl = 88.;
166   rssu = 136.;
167   rlsl = 142.;
168   rlsu = 250.;
169   // -------------------------------------------------- 
170   //          Sectors widths 
171   // -------------------------------------------------- 
172   wssl = 46.5;
173   wssu = 72.2;
174   wlsl = 37.;
175   wlsu = 65.4;
176   // --------------------------------------------------- 
177   //    Sector thickness 25% of X0 (Al) 
178   // --------------------------------------------------- 
179   sec_thick = 2.225;
180   // --------------------------------------------------- 
181   //     S-sectors (lower sectors) 
182   // --------------------------------------------------- 
183   dm[0] = wssl * .5;
184   dm[1] = wssu * .5;
185   dm[2] = sec_thick * .5;
186   dm[3] = (rssu - rssl) * .5;
187   
188   x0l = rssl + dm[3];
189   
190   gMC->Gsvolu("TRCS", "TRD1", idtmed[399], dm, 4);
191   // ----------------------------------------------------- 
192   //     S-sectors --> "gas sectors" - sensitive 
193   // ----------------------------------------------------- 
194   dm[2] = (250.-0.001)/2.;
195   gMC->Gsvolu("TSGA", "TRD1", idtmed[403], dm, 4);
196   // ------------------------------------------------------------- 
197   //  Only for the debugging purpose and resolution calculation 
198   //  Sensitive strips at the pad-row center 
199   // ------------------------------------------------------------- 
200   if (fSens >= 0) {
201     gMC->Gsvolu("TSST", "TRD1", idtmed[403], dm, 0);
202     dm[3] = .005;
203   
204     z0    = rssl + (rssu - rssl) * .5;
205     
206     for (iss = 0; iss < fTPCParam->GetNRowLow(); ++iss) {
207       r1    = fTPCParam->GetPadRowRadiiLow(iss);
208       r2    = r1 + dm[3] * 2.;
209       dm[0] = r1 * thl - 2.63;
210       dm[1] = r2 * thl - 2.63;
211       
212       zz    = -z0 + r1 +dm[3];
213
214       gMC->Gsposp("TSST", iss+1, "TSGA", 0, 0, zz, 0, "ONLY", dm, 4);
215     }
216     gMC->Gsord("TSGA", 3);
217   }
218   // --------------------------------------------------- 
219   //     L-sectors (upper sectors) 
220   // --------------------------------------------------- 
221   dm[0] = wlsl * .5;
222   dm[1] = wlsu * .5;
223   dm[2] = sec_thick * .5;
224   dm[3] = (rlsu - rlsl) * .5;
225   
226   x0u = rlsl + dm[3];
227   
228   gMC->Gsvolu("TRCL", "TRD1", idtmed[399], dm, 4);
229   // ----------------------------------------------------- 
230   //     L-sectors - "gas sectors" - sensitive! 
231   // ----------------------------------------------------- 
232   dm[2] = (250.-0.001)/2.;
233   gMC->Gsvolu("TLGA", "TRD1", idtmed[403], dm, 4);
234   // ------------------------------------------------------------- 
235   //  Only for the debugging purpose and resolution calculation 
236   //  Sensitive strips at the pad-row center 
237   // ------------------------------------------------------------- 
238   if (fSens >= 0) {
239     gMC->Gsvolu("TLST", "TRD1", idtmed[403], dm, 0);
240     
241     dm[3] = .005;
242
243     z0   = rlsl+ (rlsu - rlsl) * .5;
244     
245     for (ils = 0; ils <fTPCParam->GetNRowUp(); ++ils) {
246       r1    = fTPCParam->GetPadRowRadiiUp(ils);
247       r2    = r1 + dm[3] * 2.;
248       dm[0] = r1 * thu - 2.63;
249       dm[1] = r2 * thu - 2.63;
250
251       zz  = -z0 + r1 +dm[3]; 
252
253       gMC->Gsposp("TLST", ils+1, "TLGA", 0, 0, zz, 0, "ONLY", dm, 4);
254     }
255     gMC->Gsord("TLGA", 3);
256   }
257   // ****************************************************** 
258   // ------------------------------------------------ 
259   //      positioning of lower sectors (1-12)*2 
260   //          rotation matrices 1-12 
261   
262   //      the isec_al flag allows to select all (<0) or 
263   //      only a few (up to 6) sectors 
264   // ------------------------------------------------ 
265   z  = (250.+0.001)/2.;
266     z1 = -z_side + sec_thick * .5;
267     
268     for (il = 1; il <= 12; ++il) {
269       phi1 = (il - 1) * opl + 270.;
270       if (phi1 > 360.) {
271         phi1 += -360.;
272       }
273       theta1 = 90.;
274       phi2   = 90.;
275       theta2 = 180.;
276       phi3   = (il - 1) * opl;
277       theta3 = 90.;
278       
279       idr = il;
280       AliMatrix(idrotm[idr], theta1, phi1, theta2, phi2, theta3, phi3);
281       
282       alpha = (il - 1) * opl * kDegrad;
283       x     = x0l * TMath::Cos(alpha);
284       y     = x0l * TMath::Sin(alpha);
285       
286       if (fSecAL < 0) {
287         // ----------------------------------------------------------- 
288         //       position ALL lower sectors 
289         // ----------------------------------------------------------- 
290         gMC->Gspos("TSGA", il, "TGAS", x, y, z, idrotm[idr], "ONLY");
291         gMC->Gspos("TSGA",il+12 , "TGAS", x, y, -z, idrotm[idr], "ONLY");
292       } else {
293         // ----------------------------------------------------------- 
294         //       position selected lower sectors 
295         // ----------------------------------------------------------- 
296         for (isll = 1; isll <= 6; ++isll) {
297           if (fSecLows[isll - 1] == il) {
298             gMC->Gspos("TSGA", il, "TGAS", x, y, z, idrotm[idr], "ONLY");
299           } else if (fSecLows[isll - 1] == il + 12) {
300             gMC->Gspos("TSGA",il+12 , "TGAS", x, y, -z, idrotm[idr],"ONLY");
301           }
302         }
303       }
304       
305       gMC->Gspos("TRCS", il, "TPSG", x, y, z1, idrotm[idr], "ONLY");
306       
307     }
308     // ---------------------------------------------------- 
309     //      positioning of upper sectors (1-24)*2 
310     //          rotation matrices 13-36 
311     //      the isec_au flag allows to select all (<0) or 
312     //      only a few (up to 12) sectors 
313     // ---------------------------------------------------- 
314     for (iu = 1; iu <= 24; ++iu) {
315       phi1 = (iu - 1) * opu + 270.;
316       if (phi1 > 360.) {
317         phi1 += -360.;
318       }
319       theta1 = 90.;
320       phi2   = 90.;
321       theta2 = 180.;
322       phi3   = (iu - 1) * opu;
323       theta3 = 90.;
324       
325       idr = iu + 12;
326       AliMatrix(idrotm[idr], theta1, phi1, theta2, phi2, theta3, phi3);
327       
328       alpha = (iu - 1) * opu * kDegrad;
329       x     = x0u * TMath::Cos(alpha);
330       y     = x0u * TMath::Sin(alpha);
331
332       if (fSecAU < 0) {
333         // ------------------------------------------------------------- 
334         //           position ALL upper sectors 
335         // ------------------------------------------------------------- 
336         gMC->Gspos("TLGA", iu, "TGAS", x, y, z, idrotm[idr], "ONLY");
337         gMC->Gspos("TLGA",iu+24 , "TGAS", x, y, -z, idrotm[idr], "ONLY");
338       } else {
339         // ------------------------------------------------------------- 
340         //         position selected upper sectors 
341         // ------------------------------------------------------------- 
342         for (isll = 1; isll <= 12; ++isll) {
343           if (fSecUps[isll - 1] == iu + 24) {
344             gMC->Gspos("TLGA", iu, "TGAS", x, y, z, idrotm[idr], "ONLY");
345           } else if (fSecUps[isll - 1] == iu + 48) {
346             gMC->Gspos("TLGA",iu+24 , "TGAS", x, y, -z, idrotm[idr],"ONLY");
347           }
348         }
349       }
350       
351       gMC->Gspos("TRCL", iu, "TPSG", x, y, z1, idrotm[idr], "ONLY");
352     }
353     // -------------------------------------------------------- 
354     //             Spoke wheel structures 
355     // -------------------------------------------------------- 
356     gMC->Gsvolu("TSWS", "TUBE", idtmed[399], dm, 0);
357     
358     z0 = -z_side + 2.;
359     
360     dm[0] = 82.;
361     dm[1] = 86.;
362     dm[2] = 1.;
363     
364     gMC->Gsposp("TSWS", 1, "TPSG", 0, 0, z0, 0, "ONLY", dm, 3);
365     
366     dm[0] = 253.;
367     dm[1] = 257.;
368     
369     gMC->Gsposp("TSWS", 2, "TPSG", 0, 0, z0, 0, "ONLY", dm, 3);
370     
371     dm[0] = 140.9;
372     dm[1] = 141.9;
373     
374     gMC->Gsposp("TSWS", 3, "TPSG", 0, 0, z0, 0, "ONLY", dm, 3);
375     
376     // ------------------------------------------------------- 
377     //    this volumes are to avoid overlaping 
378     // ------------------------------------------------------- 
379     z0 = 253.;
380     
381     dm[0] = 76.;
382     dm[1] = 76.+0.09776;
383
384     gMC->Gsposp("TSWS", 4, "TPC ", 0, 0, z0, 0, "ONLY", dm, 3);
385     gMC->Gsposp("TSWS", 5, "TPC ", 0, 0, -z0, 0, "ONLY", dm, 3);
386
387     z0 += 21.;
388
389     gMC->Gsposp("TSWS", 6, "TPC ", 0, 0, z0, 0, "ONLY", dm, 3);
390     gMC->Gsposp("TSWS", 7, "TPC ", 0, 0, -z0, 0, "ONLY", dm, 3);
391
392     dm[0] = 257.;
393     dm[1] = 257.+0.09776;
394     dm[2] = 11.5;
395
396     z0 = 263.5;
397
398     gMC->Gsposp("TSWS", 8, "TPC ", 0, 0, z0, 0, "ONLY", dm, 3);
399     gMC->Gsposp("TSWS", 9, "TPC ", 0, 0, -z0, 0, "ONLY", dm, 3);
400     // ========================================================== 
401     //                  wheels 
402     // ========================================================== 
403     // ---------------------------------------------------------- 
404     //       Large wheel -> positioned in the TPC 
405     // ---------------------------------------------------------- 
406     dm[0] = 257.+0.09776;
407     dm[1] = 278.;
408     dm[2] = 11.5;
409     gMC->Gsvolu("TPW1", "TUBE", idtmed[399], dm, 3);
410     
411     dm[0] = 259.;
412     dm[1] = 278.;
413     dm[2] = 9.5;
414     
415     gMC->Gsvolu("TPW2", "TUBE", idtmed[498], dm, 3);
416     
417     gMC->Gspos("TPW2", 1, "TPW1", 0, 0, 0, 0, "ONLY");
418
419     gMC->Gspos("TPW1", 1, "TPC ", 0, 0, z0, 0, "ONLY");
420     gMC->Gspos("TPW1", 2, "TPC ", 0, 0, -z0, 0, "ONLY");
421     // ----------------------------------------------------------- 
422     //     Small wheel -> positioned in the TPSG 
423     // ----------------------------------------------------------- 
424     dm[0] = 76.+0.09776;
425     dm[1] = 82.;
426     dm[2] = 11.5;
427     
428     gMC->Gsvolu("TPW3", "TUBE", idtmed[399], dm, 3);
429     
430     dm[0] = 76.+0.09776;
431     dm[1] = 80.;
432     dm[2] = 9.5;
433     
434     gMC->Gsvolu("TPW4", "TUBE", idtmed[401], dm, 3);
435     
436     gMC->Gspos("TPW4", 1, "TPW3", 0, 0, 0, 0, "ONLY");
437     
438     z0 = 1.;
439     
440     gMC->Gspos("TPW3", 1, "TPSG", 0, 0, z0, 0, "ONLY");
441     // --------------------------------------------------------- 
442     //       spokes, inner and outer, also the inner ring 
443     // --------------------------------------------------------- 
444     dm[0] = 0.5*(135.9-82.1);
445     dm[1] = 3.;
446     dm[2] = 2.;
447     
448     x1 = dm[0] + 82.;
449     
450     gMC->Gsvolu("TSPI", "BOX ", idtmed[399], dm, 3);
451     
452     dm[1] = 2.;
453     dm[2] = 1.;
454     
455     gMC->Gsvolu("TSP1", "BOX ", idtmed[498], dm, 3);
456     
457     gMC->Gspos("TSP1", 1, "TSPI", 0, 0, 0, 0, "ONLY");
458     
459     dm[0] = 0.5*(256.9-142.1);
460     dm[1] = 3.;
461     dm[2] = 2.;
462     
463     x2 = dm[0] + 142.;
464     
465     gMC->Gsvolu("TSPO", "BOX ", idtmed[399], dm, 3);
466     
467     dm[1] = 2.;
468     dm[2] = 1.;
469     
470     gMC->Gsvolu("TSP2", "BOX ", idtmed[498], dm, 3);
471
472     gMC->Gspos("TSP2", 1, "TSPO", 0, 0, 0, 0, "ONLY");
473     // -------------------------------------------------------- 
474     dm[0] = 136.;
475     dm[1] = 142.;
476     dm[2] = 2.;
477
478     gMC->Gsvolu("TSWH", "TUBE", idtmed[399], dm, 3);
479
480     dm[0] = 137.;
481     dm[1] = 141.;
482     dm[2] = 1.;
483
484     gMC->Gsvolu("TSW1", "TUBE", idtmed[498], dm, 3);
485
486     gMC->Gspos("TSW1", 1, "TSWH", 0, 0, 0, 0, "ONLY");
487
488     z0 = z_side - .16168 - 2.;
489     // -------------------------------------------------------- 
490     gMC->Gspos("TSWH", 1, "TPSG", 0, 0, z0, 0, "ONLY");
491     // ------------------------------------------------------- 
492     //     posiioning of the inner spokes 
493     // ------------------------------------------------------- 
494     for (il = 1; il <= 6; ++il) {
495       phi1   = opl * .5 + (il - 1) * 2. * opl;
496       theta1 = 90.;
497       phi2   = opl * .5 + 90. + (il - 1) * 2. * opl;
498       if (phi2 > 360.) {
499         phi2 += -360.;
500       }
501       theta2 = 90.;
502       phi3   = 0.;
503       theta3 = 0.;
504       
505       alpha = phi1 * kDegrad;
506       x     = x1 * TMath::Cos(alpha);
507       y     = x1 * TMath::Sin(alpha);
508       
509       idr = il + 36;
510       
511       AliMatrix(idrotm[idr], theta1, phi1, theta2, phi2, theta3, phi3);
512       gMC->Gspos("TSPI", il, "TPSG", x, y, z0, idrotm[idr], "ONLY");
513       
514     }
515     
516     for (iu = 1; iu <= 12; ++iu) {
517       phi1   = opu * .5 + (iu - 1) * 2. * opu;
518       theta1 = 90.;
519       phi2   = opu * .5 + 90. + (iu - 1) * 2. * opu;
520       if (phi2 > 360.) {
521         phi2 += -360.;
522       }
523       theta2 = 90.;
524       phi3   = 0.;
525       theta3 = 0.;
526       
527       alpha = phi1 * kDegrad;
528       x     = x2 * TMath::Cos(alpha);
529       y     = x2 * TMath::Sin(alpha);
530       
531       idr = iu + 42;
532       
533       AliMatrix(idrotm[idr], theta1, phi1, theta2, phi2, theta3, phi3);
534       gMC->Gspos("TSPO", iu, "TPSG", x, y, z0, idrotm[idr], "ONLY");
535     }
536     // -------------------------------------------------------- 
537     //       endcap cover (C, 0.86% X0) 
538     // -------------------------------------------------------- 
539     dm[0] = 76.+0.09776;
540     dm[1] = 257.;
541     dm[2] = 0.16168*0.5;
542     
543     gMC->Gsvolu("TCOV", "TUBE", idtmed[407], dm, 3);
544     
545     z0 = z_side - dm[2];
546     
547     gMC->Gspos("TCOV", 1, "TPSG", 0, 0, z0, 0, "ONLY");
548     // -------------------------------------------------------- 
549     //         put the readout chambers into the TPC 
550     // -------------------------------------------------------- 
551     theta1 = 90.;
552     phi1   = 0.;
553     theta2 = 90.;
554     phi2   = 270.;
555     theta3 = 180.;
556     phi3   = 0.;
557
558     AliMatrix(idrotm[55], theta1, phi1, theta2, phi2, theta3, phi3);
559     
560     z0 = z_side + 250.;
561     
562     gMC->Gspos("TPSG", 1, "TPC ", 0, 0, z0, 0, "ONLY");
563     gMC->Gspos("TPSG", 2, "TPC ", 0, 0, -z0, idrotm[55], "ONLY");
564     // --------------------------------------------------------- 
565     //     outer gas insulation (CO2) 
566     // --------------------------------------------------------- 
567     dm[0] = 257.+0.09776;
568     dm[1] = 278.-0.25004;
569     dm[2] = 275.-23.;
570     
571     gMC->Gsvolu("TPOI", "TUBE", idtmed[406], dm, 3);
572     
573     gMC->Gspos("TPHV", 1, "TGAS", 0, 0, 0, 0, "ONLY");
574     gMC->Gspos("TGAS", 1, "TPC ", 0, 0, 0, 0, "ONLY");
575     gMC->Gspos("TPOI", 1, "TPC ", 0, 0, 0, 0, "ONLY");
576     
577     gMC->Gspos("TPC ", 1, "ALIC", 0, 0, 0, 0, "ONLY");
578     // ====================================================== 
579     //      all volumes below are positioned in ALIC 
580     // ====================================================== 
581     // ------------------------------------------------------ 
582     //        the last parts of the smaller wheel (TSWS) 
583     // ------------------------------------------------------ 
584     dm[0] = 74.;
585     dm[1] = 76.;
586     dm[2] = 1.;
587     
588     z0 = 253.;
589     
590     gMC->Gsposp("TSWS", 10, "TPC ", 0, 0, z0, 0, "ONLY", dm, 3);
591     gMC->Gsposp("TSWS", 11, "TPC ", 0, 0, -z0, 0, "ONLY", dm, 3);
592
593     dm[0] = 70.;
594     
595     z0 += 21.;
596     
597     gMC->Gsposp("TSWS", 12, "TPC ", 0, 0, z0, 0, "ONLY", dm, 3);
598     gMC->Gsposp("TSWS", 13, "TPC ", 0, 0, -z0, 0, "ONLY", dm, 3);
599     // ---------------------------------------------------- 
600     //             Inner vessel (PCON) 
601     //   This volume is to be positioned directly in ALIC 
602     // ---------------------------------------------------- 
603     dm[0] = 0.;
604     dm[1] = 360.;
605     dm[2] = 4.;
606
607     dm[3] = -250.;
608     dm[4] = 75.;
609     dm[5] = 76.;
610
611     dm[6] = -64.5;
612     dm[7] = 50.;
613     dm[8] = 76.;
614
615     dm[9]  = 64.5;
616     dm[10] = 50.;
617     dm[11] = 76.;
618
619     dm[12] = 250.;
620     dm[13] = 75.;
621     dm[14] = 76.;
622
623     gMC->Gsvolu("TPIV", "PCON", idtmed[407], dm, 15);
624     // -------------------------------------------------------- 
625     //     fill the inner vessel with CO2, (HV kDegrader) 
626     //     cone parts have different thickness 
627     //     than the central barrel, according to the TP 
628     // -------------------------------------------------------- 
629     tana = 75./185.5;
630     
631     dm[0] = 0.;
632     dm[1] = 360.;
633     dm[2] = 6.;
634     
635     dm[3] = -(250.-0.2162);
636     dm[4] = (185.5-0.2126)*tana+0.2126;
637     dm[5] = 76-0.001;
638     
639     dm[6] = -64.5;
640     dm[7] = 50.+0.2162;
641     dm[8] = 76-0.001;
642     
643     dm[9] = -64.5;
644     dm[10] = 50+0.05076;
645     dm[11] = 76-0.001;
646     
647     dm[12] = 64.5;
648     dm[13] = 50+0.05076;
649     dm[14] = 76-0.001;
650     
651     dm[15] = 64.5;
652     dm[16] = 50.+0.2162;
653     dm[17] = 76-0.001;
654     
655     dm[18] = (250.-0.2162);
656     dm[19] = (185.5-0.2126)*tana+0.2126;
657     dm[20] = 76-0.001;
658     
659     gMC->Gsvolu("TPVD", "PCON", idtmed[406], dm, 21);
660     
661     gMC->Gspos("TPVD", 1, "TPIV", 0, 0, 0, 0, "ONLY");
662     
663     gMC->Gspos("TPIV", 1, "ALIC", 0, 0, 0, 0, "ONLY");
664     // --------------------------------------------------- 
665     //               volumes ordering 
666     // --------------------------------------------------- 
667     gMC->Gsord("TGAS", 6);
668     gMC->Gsord("TPSG", 6);
669 }
670  
671 //_____________________________________________________________________________
672 void AliTPCv2::DrawDetector()
673 {
674   //
675   // Draw a shaded view of the Time Projection Chamber version 1
676   //
677
678   // Set everything unseen
679   gMC->Gsatt("*", "seen", -1);
680   // 
681   // Set ALIC mother transparent
682   gMC->Gsatt("ALIC","SEEN",0);
683   //
684   // Set the volumes visible
685   gMC->Gsatt("TPC","SEEN",0);
686   gMC->Gsatt("TGAS","SEEN",0);
687   gMC->Gsatt("TPSG","SEEN",0);
688   gMC->Gsatt("TPHV","SEEN",1);
689   gMC->Gsatt("TRCS","SEEN",1);
690   gMC->Gsatt("TRCL","SEEN",1);
691   gMC->Gsatt("TSWS","SEEN",1);
692   gMC->Gsatt("TPW1","SEEN",1);
693   gMC->Gsatt("TPW3","SEEN",1);
694   gMC->Gsatt("TSPI","SEEN",1);
695   gMC->Gsatt("TSPO","SEEN",1);
696   gMC->Gsatt("TSWH","SEEN",1);
697   gMC->Gsatt("TPOI","SEEN",1);
698   gMC->Gsatt("TPIV","SEEN",1);
699   gMC->Gsatt("TPVD","SEEN",1);
700   //
701   gMC->Gdopt("hide", "on");
702   gMC->Gdopt("shad", "on");
703   gMC->Gsatt("*", "fill", 7);
704   gMC->SetClipBox(".");
705   gMC->SetClipBox("*", 0, 1000, -1000, 1000, -1000, 1000);
706   gMC->DefaultRange();
707   gMC->Gdraw("alic", 40, 30, 0, 12, 9.5, .025, .025);
708   gMC->Gdhead(1111, "Time Projection Chamber");
709   gMC->Gdman(18, 4, "MAN");
710   gMC->Gdopt("hide","off");
711 }
712
713 //_____________________________________________________________________________
714 void AliTPCv2::CreateMaterials()
715 {
716   //
717   // Define materials for version 2 of the Time Projection Chamber
718   //
719
720   //
721   // Increase maximum number of steps
722   gMC->SetMaxNStep(30000);
723   //
724   AliTPC::CreateMaterials();
725 }
726
727 //_____________________________________________________________________________
728 void AliTPCv2::Init()
729 {
730   //
731   // Initialises version 2 of the TPC after that it has been built
732   //
733   Int_t *idtmed = fIdtmed->GetArray()-399;
734   AliTPC::Init();
735   fIdSens1=gMC->VolId("TLGA"); // L-sector
736   fIdSens2=gMC->VolId("TSGA"); // S-sector 
737   fIdSens3=gMC->VolId("TSST"); // strip - S-sector (not always used)
738   fIdSens4=gMC->VolId("TLST"); // strip - S-sector (not always used)
739
740   gMC->SetMaxNStep(30000); // max. number of steps increased
741
742   gMC->Gstpar(idtmed[403],"LOSS",5);
743
744   printf("*** TPC version 2 initialized ***\n");
745   printf("Maximum number of steps = %d\n",gMC->GetMaxNStep());
746
747   //
748   
749 }
750
751 //_____________________________________________________________________________
752 void AliTPCv2::StepManager()
753 {
754   //
755   // Called for every step in the Time Projection Chamber
756   //
757
758   //
759   // parameters used for the energy loss calculations
760   //
761   const Float_t prim = 14.35; // number of primary collisions per 1 cm
762   const Float_t poti = 20.77e-9; // first ionization potential for Ne/CO2
763   const Float_t w_ion = 35.97e-9; // energy for the ion-electron pair creation 
764  
765  
766   const Float_t big = 1.e10;
767
768   Int_t id,copy;
769   Float_t hits[4];
770   Int_t vol[2];  
771   TClonesArray &lhits = *fHits;
772   TLorentzVector pos;
773   
774   vol[1]=0;
775
776   //
777
778   gMC->SetMaxStep(big);
779   
780   if(!gMC->IsTrackAlive()) return; // particle has disappeared
781   
782   Float_t charge = gMC->TrackCharge();
783   
784   if(TMath::Abs(charge)<=0.) return; // take only charged particles
785   
786   
787   id=gMC->CurrentVolID(copy);
788   
789   // Check the sensitive volume
790   
791   if(id == fIdSens1) 
792     {
793       vol[0] = copy + 24; // L-sector number
794     }
795   else if(id == fIdSens2) 
796     {
797       vol[0] = copy; // S-sector number 
798     }
799   else if(id == fIdSens3 && gMC->IsTrackEntering())
800     {
801       vol[1] = copy;  // row number  
802       id = gMC->CurrentVolOffID(1,copy);
803       vol[0] = copy; // sector number (S-sector)
804       
805       gMC->TrackPosition(pos);
806       hits[0]=pos[0];
807       hits[1]=pos[1];
808       hits[2]=pos[2];
809       hits[3]=0.; // this hit has no energy loss
810       new(lhits[fNhits++]) AliTPChit(fIshunt,gAlice->CurrentTrack(),vol,hits);
811     }
812   else if(id == fIdSens4 && gMC->IsTrackEntering())
813     {
814       vol[1] = copy; // row number 
815       id = gMC->CurrentVolOffID(1,copy);
816       vol[0] = copy+24; // sector number (L-sector)
817       
818       gMC->TrackPosition(pos);
819       hits[0]=pos[0];
820       hits[1]=pos[1];
821       hits[2]=pos[2];
822       hits[3]=0.; // this hit has no energy loss
823       new(lhits[fNhits++]) AliTPChit(fIshunt,gAlice->CurrentTrack(),vol,hits);
824     }
825   else return;
826   
827   //
828   //  charged particle is in the sensitive volume
829   //
830   
831   if(gMC->TrackStep() > 0) {
832     
833     Int_t nel = (Int_t)(((gMC->Edep())-poti)/w_ion) + 1;
834     nel=TMath::Min(nel,300); // 300 electrons corresponds to 10 keV
835     
836     gMC->TrackPosition(pos);
837     hits[0]=pos[0];
838     hits[1]=pos[1];
839     hits[2]=pos[2];
840     hits[3]=(Float_t)nel;
841     
842     // Add this hit
843     
844     new(lhits[fNhits++]) AliTPChit(fIshunt,gAlice->CurrentTrack(),vol,hits);
845     
846   } 
847   
848   // Stemax calculation for the next step
849   
850   Float_t pp;
851   TLorentzVector mom;
852   gMC->TrackMomentum(mom);
853   Float_t ptot=mom.Rho();
854   Float_t beta_gamma = ptot/gMC->TrackMass();
855   
856   if(gMC->TrackPid() <= 3 && ptot > 0.002)
857     { 
858       pp = prim*1.58; // electrons above 20 MeV/c are on the plateau!
859     }
860   else
861     {
862       pp=prim*BetheBloch(beta_gamma);    
863       if(TMath::Abs(charge) > 1.) pp *= (charge*charge);
864     }
865   
866   Float_t random[1];
867   gMC->Rndm(random,1); // good, old GRNDM from Geant3
868   
869   Double_t rnd = (Double_t)random[0];
870   
871   gMC->SetMaxStep(-TMath::Log(rnd)/pp);
872   
873 }
874
875 //_____________________________________________________________________________
876 Float_t AliTPCv2::BetheBloch(Float_t bg)
877 {
878   //
879   // Bethe-Bloch energy loss formula
880   //
881   const Double_t p1=0.76176e-1;
882   const Double_t p2=10.632;
883   const Double_t p3=0.13279e-4;
884   const Double_t p4=1.8631;
885   const Double_t p5=1.9479;
886
887   Double_t dbg = (Double_t) bg;
888
889   Double_t beta = dbg/TMath::Sqrt(1.+dbg*dbg);
890
891   Double_t aa = TMath::Power(beta,p4);
892   Double_t bb = TMath::Power(1./dbg,p5);
893
894   bb=TMath::Log(p3+bb);
895   
896   return ((Float_t)((p2-aa-bb)*p1/aa));
897 }