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