]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCv3.cxx
Corrected bug in the HV degrader geometry, thanks to G.Tabary
[u/mrichter/AliRoot.git] / TPC / AliTPCv3.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.8  1999/10/04 13:39:55  fca
19 Correct array index problem
20
21 Revision 1.7  1999/09/29 09:24:34  fca
22 Introduction of the Copyright and cvs Log
23
24 */
25
26 ///////////////////////////////////////////////////////////////////////////////
27 //                                                                           //
28 //  Time Projection Chamber version 3 -- detailed TPC and slow simulation    //
29 //                                                                           //
30 //Begin_Html
31 /*
32 <img src="picts/AliTPCv3Class.gif">
33 */
34 //End_Html
35 //                                                                           //
36 //                                                                           //
37 ///////////////////////////////////////////////////////////////////////////////
38
39 #include <stdlib.h>
40 #include <TMath.h>
41
42 #include "AliTPCv3.h"
43 #include "AliRun.h"
44 #include "AliConst.h"
45 #include "AliTPCD.h"
46 #include "AliTPCParam.h"
47
48 ClassImp(AliTPCv3)
49  
50 //_____________________________________________________________________________
51 AliTPCv3::AliTPCv3(const char *name, const char *title) :
52   AliTPC(name, title) 
53 {
54   //
55   // Standard constructor for Time Projection Chamber version 2
56   //
57
58   SetBufferSize(128000);
59 }
60  
61 //_____________________________________________________________________________
62 void AliTPCv3::CreateGeometry()
63 {
64   //
65   // Creation of the TPC coarse geometry (version 0)
66   // Origin Marek Kowalski Crakow
67   //
68   //Begin_Html
69   /*
70     <img src="picts/AliTPCv0.gif">
71   */
72   //End_Html
73   //Begin_Html
74   /*
75     <img src="picts/AliTPCv0Tree.gif">
76   */
77   //End_Html
78
79   AliTPCParam * fTPCParam = &(fDigParam->GetParam());
80
81   Int_t *idtmed = fIdtmed->GetArray();
82
83   Float_t dm[21];
84   Int_t idrotm[120];
85
86   Int_t nRotMat = 0;
87
88
89   // ---------------------------------------------------- 
90   //          FIELD CAGE WITH ENDCAPS - G10
91   //          THIS IS ALSO A TPC MOTHER VOLUME 
92   // ---------------------------------------------------- 
93
94   dm[0] = 76.;
95   dm[1] = 278.;
96   dm[2] = 275.;
97
98   gMC->Gsvolu("TPC ", "TUBE", idtmed[8], dm, 3); 
99
100   //-----------------------------------------------------
101   //  Endcap cover c-fibre 0.86% X0
102   //-----------------------------------------------------
103
104   dm[0] = 78.;
105   dm[1] = 258.;
106   dm[2] = 0.95;
107
108   gMC->Gsvolu("TPEC","TUBE",idtmed[10],dm,3);
109
110   //-----------------------------------------------------
111   // Drift gas , leave 2 cm at the outer radius
112   // and inner raddius
113   //-----------------------------------------------------
114
115   dm[0] = 78.;
116   dm[1] = 258.;
117   dm[2] = 250.;
118
119   gMC->Gsvolu("TGAS", "TUBE", idtmed[4], dm, 3);
120
121
122   //------------------------------------------------------
123   //  membrane holder - carbon fiber
124   //------------------------------------------------------
125
126
127   gMC->Gsvolu("TPMH","TUBE",idtmed[6],dm,0);
128
129   dm[0] = 252.;
130   dm[1] = 258.;
131   dm[2] = 0.2;
132
133   gMC->Gsposp("TPMH",1,"TGAS",0.,0.,0.,0,"ONLY",dm,3);
134  
135   dm[0] = 78.;
136   dm[1] = 82.;
137   dm[2] = 0.1;
138
139   gMC->Gsposp("TPMH",2,"TGAS",0.,0.,0.,0,"ONLY",dm,3);
140
141   //----------------------------------------------------------
142   //  HV membrane - 25 microns of mylar
143   //----------------------------------------------------------
144
145   dm[0] = 82.;
146   dm[1] = 252.;
147   dm[2] = 0.00125;
148
149   gMC->Gsvolu("TPHV","TUBE",idtmed[5],dm,3);
150
151   gMC->Gspos("TPHV",1,"TGAS",0.,0.,0.,0,"ONLY");
152
153   gMC->Gspos("TGAS",1,"TPC ",0.,0.,0.,0,"ONLY");
154
155   //----------------------------------------------------------
156   // "side" gas volume, the same as the drift gas
157   // the readout chambers are placed there.  
158   //----------------------------------------------------------
159
160   dm[0] = 78.;
161   dm[1] = 258.;
162   dm[2] = 0.5*(275. - 250.);
163    
164   gMC->Gsvolu("TPSG", "TUBE", idtmed[2], dm, 3);
165
166   Float_t z_side = dm[2]; // 1/2 of the side gas thickness
167
168   //-----------------------------------------------------------
169   //   Readout chambers , 25% of X0, I use Al as the material
170   //-----------------------------------------------------------
171
172   Float_t InnerOpenAngle = fTPCParam->GetInnerAngle();
173   Float_t OuterOpenAngle = fTPCParam->GetOuterAngle();
174
175   Float_t InnerAngleShift = fTPCParam->GetInnerAngleShift();
176   Float_t OuterAngleShift = fTPCParam->GetOuterAngleShift();
177
178
179   Int_t nInnerSector = fTPCParam->GetNInnerSector()/2;
180   Int_t nOuterSector = fTPCParam->GetNOuterSector()/2;
181
182
183   Float_t InSecLowEdge = fTPCParam->GetInSecLowEdge();
184   Float_t InSecUpEdge =  fTPCParam->GetInSecUpEdge();
185
186   Float_t OuSecLowEdge = fTPCParam->GetOuSecLowEdge();
187   Float_t OuSecUpEdge = fTPCParam->GetOuSecUpEdge();
188
189   Float_t SecThick = 2.225; // Al
190
191   Float_t edge = fTPCParam->GetEdge();
192
193   //  S (Inner) sectors
194
195   dm[0] = InSecLowEdge*TMath::Tan(0.5*InnerOpenAngle)-edge;
196   dm[1] = InSecUpEdge*TMath::Tan(0.5*InnerOpenAngle)-edge;
197   dm[2] = SecThick;
198   dm[3] = 0.5*(InSecUpEdge-InSecLowEdge);
199
200   Float_t xCenterS = InSecLowEdge+dm[3];
201
202   gMC->Gsvolu("TRCS", "TRD1", idtmed[0], dm, 4); 
203
204   //  L (Outer) sectors
205
206   dm[0] = OuSecLowEdge*TMath::Tan(0.5*OuterOpenAngle)-edge;
207   dm[1] = OuSecUpEdge*TMath::Tan(0.5*OuterOpenAngle)-edge;
208   dm[2] = SecThick;
209   dm[3] = 0.5*(OuSecUpEdge-OuSecLowEdge);
210
211   Float_t xCenterL = OuSecLowEdge+dm[3];  
212
213   gMC->Gsvolu("TRCL", "TRD1", idtmed[0], dm, 4);
214
215   Float_t z1 = -z_side + SecThick*0.5;
216
217   //------------------------------------------------------------------
218   // Positioning of the S-sector readout chambers
219   //------------------------------------------------------------------
220
221   Int_t ns;
222   Float_t theta1,theta2,theta3;
223   Float_t phi1,phi2,phi3;
224   Float_t alpha;
225   Float_t x,y;
226
227   for(ns=0;ns<nInnerSector;ns++){
228     
229     phi1 = ns * InnerOpenAngle + 270.*kDegrad + InnerAngleShift;
230     phi1 *= kRaddeg; // in degrees
231
232     phi1 = (Float_t)TMath::Nint(phi1);
233
234     if (phi1 > 360.) phi1 -= 360.;
235       
236     theta1 = 90.;
237     phi2   = 90.;
238     theta2 = 180.;
239     phi3   = ns * InnerOpenAngle + InnerAngleShift;
240     phi3 *= kRaddeg; // in degrees
241
242     phi3 = (Float_t)TMath::Nint(phi3);
243       
244     if(phi3 > 360.) phi3 -= 360.;
245
246     theta3 = 90.;
247
248     alpha = phi3*kDegrad;
249
250     x = xCenterS * TMath::Cos(alpha);
251     y = xCenterS * TMath::Sin(alpha); 
252  
253     AliMatrix(idrotm[nRotMat], theta1, phi1, theta2, phi2, theta3, phi3);  
254      
255     gMC->Gspos("TRCS", ns+1, "TPSG", x, y, z1, idrotm[nRotMat], "ONLY");
256
257     nRotMat++;     
258
259   }
260     
261   //-------------------------------------------------------------------
262   //  Positioning of the L-sectors readout chambers
263   //-------------------------------------------------------------------
264     
265   for(ns=0;ns<nOuterSector;ns++){
266     phi1 = ns * OuterOpenAngle + 270.*kDegrad + OuterAngleShift;
267     phi1 *= kRaddeg; // in degrees
268
269     phi1 = (Float_t)TMath::Nint(phi1);
270     
271
272     if (phi1 > 360.) phi1 -= 360.;
273       
274     theta1 = 90.;
275     phi2   = 90.;
276     theta2 = 180.;
277     phi3   = ns * OuterOpenAngle+OuterAngleShift;
278     phi3 *= kRaddeg; // in degrees
279
280     phi3 = (Float_t)TMath::Nint(phi3);
281
282       
283     if(phi3 > 360.) phi3 -= 360.;
284
285     theta3 = 90.;
286
287     alpha = phi3*kDegrad;
288
289     x = xCenterL * TMath::Cos(alpha);
290     y = xCenterL * TMath::Sin(alpha); 
291  
292     AliMatrix(idrotm[nRotMat], theta1, phi1, theta2, phi2, theta3, phi3);  
293      
294
295     gMC->Gspos("TRCL", ns+1, "TPSG", x, y, z1, idrotm[nRotMat], "ONLY"); 
296
297     nRotMat++;   
298
299   }
300
301   Float_t z0 = z_side - 0.95;
302
303   gMC->Gspos("TPEC",1,"TPSG",0.,0.,z0,0,"ONLY");
304
305   // ========================================================== 
306   //                  wheels 
307   // ========================================================== 
308
309   //
310   //  auxilary structures
311   //
312
313
314   gMC->Gsvolu("TPWI","TUBE",idtmed[24],dm,0); // "air" 
315
316   // ---------------------------------------------------------- 
317   //       Large wheel -> positioned in the TPC 
318   // ---------------------------------------------------------- 
319   
320
321   z0 = 263.5; // TPC length - 1/2 spoke wheel width
322
323   dm[0] = 258.;
324   dm[1] = 278.;
325   dm[2] = 11.5;
326   
327   gMC->Gsvolu("TPWL", "TUBE", idtmed[0], dm, 3); 
328
329   dm[0] = dm[0]+2.;
330   dm[1] = 278.;
331   dm[2] = dm[2]-2.;
332
333   gMC->Gsposp("TPWI",1,"TPWL",0.,0.,0.,0,"ONLY",dm,3);
334
335   gMC->Gspos("TPWL", 1, "TPC ", 0, 0, z0, 0, "ONLY");
336   gMC->Gspos("TPWL", 2, "TPC ", 0, 0, -z0, 0, "ONLY");
337
338   //
339   //  Outer vessel + CO2 HV degrader
340   //
341
342   dm[0] = 260.;
343   dm[1] = 278.;
344   dm[2] = 252.;
345
346   gMC->Gsvolu("TPCO","TUBE",idtmed[12],dm,3);
347
348   dm[0] = 275.;
349   dm[1] = 278.;
350   
351   gMC->Gsvolu("TPOV","TUBE",idtmed[10],dm,3);
352
353   gMC->Gspos("TPOV",1,"TPCO",0.,0.,0.,0,"ONLY");
354
355
356   // G10 plugs
357
358   dm[0] = 258.;
359   dm[1] = 260.;
360   dm[2] = 1.;
361
362   gMC->Gsvolu("TPG1","TUBE",idtmed[8],dm,3);
363   gMC->Gspos("TPG1",1,"TPCO",0.,0.,251.,0,"ONLY");
364   gMC->Gspos("TPG1",2,"TPCO",0.,0.,-251.,0,"ONLY");  
365
366   gMC->Gspos("TPCO",1,"TPC ",0.,0.,0.,0,"ONLY");
367
368
369   //----------------------------------------------------------
370   //  Small wheel -> positioned in "side gas
371   //----------------------------------------------------------
372
373   dm[0] = 78.;
374   dm[1] = 82.;
375   dm[2] = 11.5;
376
377   gMC->Gsvolu("TPWS", "TUBE", idtmed[0], dm, 3);
378
379   dm[0] = 78.;
380   dm[1] = dm[1]-2;
381   dm[2] = dm[2]-2.;
382
383   gMC->Gsvolu("TPW1", "TUBE", idtmed[2], dm, 3);
384   
385   gMC->Gspos("TPW1", 1, "TPWS", 0., 0., 0., 0, "ONLY");
386
387   z0 = 1.; // spoke wheel is shifted w.r.t. center of the "side gas"
388
389   gMC->Gspos("TPWS", 1, "TPSG", 0, 0, z0, 0, "ONLY");
390
391
392   // to avoid overlaps
393
394   dm[0] = 76.;
395   dm[1] = 78.;
396   dm[2] = 11.5;
397
398   gMC->Gsvolu("TPS1","TUBE",idtmed[0],dm,3);
399
400   dm[2] = 9.5;
401
402   gMC->Gsvolu("TPS2","TUBE",idtmed[24],dm,3);
403
404   gMC->Gspos("TPS2",1,"TPS1",0.,0.,0.,0,"ONLY");
405
406   z0= 263.5;
407   
408   gMC->Gspos("TPS1",1,"TPC ",0.,0.,z0,0,"ONLY");
409   gMC->Gspos("TPS1",2,"TPC ",0.,0.,-z0,0,"ONLY");
410
411   // G10 plug
412
413   dm[0] = 76.;
414   dm[1] = 78.;
415   dm[2] = 1.;
416
417   gMC->Gsvolu("TPG2","TUBE",idtmed[8],dm,3);
418
419   z0 = 251.;
420
421   gMC->Gspos("TPG2",1,"TPC ",0.,0.,z0,0,"ONLY");
422   gMC->Gspos("TPG2",2,"TPC ",0.,0.,-z0,0,"ONLY");
423
424
425   //---------------------------------------------------------
426   //  central wheel  6 (radial direction) x 4 (along z) cm2
427   //---------------------------------------------------------
428
429   dm[0] = 140.;
430   dm[1] = 146.;
431   dm[2] = 2.;
432
433   gMC->Gsvolu("TPWC","TUBE",idtmed[0],dm,3);
434
435   dm[0] = dm[0] + 2.;
436   dm[1] = dm[1] - 2.;
437   dm[2] = dm[2] - 1.;
438
439   gMC->Gsposp("TPWI",2,"TPWC",0.,0.,0.,0,"ONLY",dm,3);
440
441   z0 = z_side - 1.9 - 2.;
442
443   gMC->Gspos("TPWC",1,"TPSG",0.,0.,z0,0,"ONLY");
444
445   //
446
447   gMC->Gsvolu("TPSE","BOX ",idtmed[24],dm,0); // "empty" part of the spoke 
448
449  
450   //---------------------------------------------------------
451   //  inner spokes (nSectorInner)
452   //---------------------------------------------------------
453
454   dm[0] = 0.5*(139.9-82.1);
455   dm[1] = 3.;
456   dm[2] = 2.;
457
458   Float_t x1 = dm[0]+82.;
459
460   gMC->Gsvolu("TPSI","BOX",idtmed[0],dm,3);
461
462   dm[1] = dm[1]-1.;
463   dm[2] = dm[2]-1.;
464
465   gMC->Gsposp("TPSE",1,"TPSI",0.,0.,0.,0,"ONLY",dm,3);
466
467   for(ns=0;ns<nInnerSector;ns++){
468
469     phi1 = 0.5*InnerOpenAngle + ns*InnerOpenAngle + InnerAngleShift;
470     theta1=90.;
471     phi1 *=kRaddeg;
472
473     phi1 = (Float_t)TMath::Nint(phi1);
474
475     phi2 = phi1+90.;
476     if(phi2>360.) phi2 -= 360.;
477     theta2=90.;
478     phi3=0.;
479     theta3=0.;
480
481     alpha = phi1 * kDegrad;
482     x     = x1 * TMath::Cos(alpha);
483     y     = x1 * TMath::Sin(alpha);    
484
485    AliMatrix(idrotm[nRotMat],theta1,phi1,theta2,phi2,theta3,phi3);
486
487    gMC->Gspos("TPSI",ns+1,"TPSG",x,y,z0,idrotm[nRotMat],"ONLY");  
488
489    nRotMat++;
490
491   }
492
493   //-------------------------------------------------------------
494   // outer spokes (nSectorOuter)
495   //-------------------------------------------------------------
496
497   dm[0] = 0.5*(257.9-146.1);
498   dm[1] = 3.;
499   dm[2] = 2.;
500
501   x1 = dm[0] + 146.;
502
503   gMC->Gsvolu("TPSO","BOX ",idtmed[0],dm,3);
504
505   dm[1] = dm[1] - 1.;
506   dm[2] = dm[2] - 1.;
507
508   gMC->Gsposp("TPSE",2,"TPSO",0.,0.,0.,0,"ONLY",dm,3);
509
510   for(ns=0;ns<nOuterSector;ns++){
511
512     phi1 = 0.5*OuterOpenAngle + ns*OuterOpenAngle + OuterAngleShift;
513     theta1=90.;
514     phi1 *=kRaddeg;
515
516     phi1 = (Float_t)TMath::Nint(phi1);
517
518     phi2 = phi1+90.;
519     if(phi2>360.) phi2 -= 360.;
520     theta2=90.;
521     phi3=0.;
522     theta3=0.;
523
524     alpha = phi1 * kDegrad;
525     x     = x1 * TMath::Cos(alpha);
526     y     = x1 * TMath::Sin(alpha);    
527
528    AliMatrix(idrotm[nRotMat],theta1,phi1,theta2,phi2,theta3,phi3);
529
530    gMC->Gspos("TPSO",ns+1,"TPSG",x,y,z0,idrotm[nRotMat],"ONLY");  
531
532    nRotMat++;
533
534   }  
535   
536
537   
538   // -------------------------------------------------------- 
539   //         put the readout chambers into the TPC 
540   // -------------------------------------------------------- 
541
542   theta1 = 90.;
543   phi1   = 0.;
544   theta2 = 90.;
545   phi2   = 270.;
546   theta3 = 180.;
547   phi3   = 0.;
548   
549   AliMatrix(idrotm[nRotMat], theta1, phi1, theta2, phi2, theta3, phi3);
550   
551   z0 = z_side + 250.;
552   
553   gMC->Gspos("TPSG", 1, "TPC ", 0, 0, z0, 0, "ONLY");
554   gMC->Gspos("TPSG", 2, "TPC ", 0, 0, -z0, idrotm[nRotMat], "ONLY");
555   
556   gMC->Gspos("TPC ", 1, "ALIC", 0, 0, 0, 0, "ONLY");
557
558   //----------------------------------------------------
559   //  Inner vessel and HV degrader
560   //----------------------------------------------------
561
562   dm[0] = 0.;
563   dm[1] = 360.;
564   dm[2] = 4.;
565   
566   dm[3] = -250.;
567   dm[4] = 74.4;
568   dm[5] = 76.;
569
570   dm[6] = -64.5;
571   dm[7] = 50.;
572   dm[8] = 76.;
573
574   dm[9] = 64.5;
575   dm[10] = 50.;
576   dm[11] = 76.;
577
578   dm[12] = 250.;
579   dm[13] = 74.4;
580   dm[14] = 76.;
581
582   gMC->Gsvolu("TPVD", "PCON", idtmed[12], dm, 15); // CO2
583
584   // cone parts
585
586   dm[0] = 0.;
587   dm[1] = 360.;
588   dm[2] = 2.;
589
590   dm[3] = 64.5;
591   dm[4] = 50.;
592   dm[5] = 51.6;
593  
594   dm[6] = 250.;
595   dm[7] = 74.4;
596   dm[8] = 76.;
597
598
599   gMC->Gsvolu("TIVC","PCON",idtmed[11],dm,9); // C-fibre
600
601   gMC->Gspos("TIVC",1,"TPVD",0.,0.,0.,0,"ONLY");
602   gMC->Gspos("TIVC",2,"TPVD",0.,0.,0.,idrotm[nRotMat],"ONLY");
603
604   // barrel part
605
606   dm[0] = 50.;
607   dm[1] = 50.5;
608   dm[2] = 32.25;
609
610   gMC->Gsvolu("TIVB","TUBE",idtmed[9],dm,3);
611
612   gMC->Gspos("TIVB",1,"TPVD",0.,0.,0.,0,"ONLY");
613
614   gMC->Gspos("TPVD",1,"ALIC",0.,0.,0.,0,"ONLY");
615
616   
617
618   
619
620   // --------------------------------------------------- 
621   //               volumes ordering 
622   // --------------------------------------------------- 
623   gMC->Gsord("TPSG", 6);
624  
625 } // end of function
626
627  
628  
629 //_____________________________________________________________________________
630 void AliTPCv3::DrawDetector()
631 {
632   //
633   // Draw a shaded view of the Time Projection Chamber version 1
634   //
635
636
637   // Set everything unseen
638   gMC->Gsatt("*", "seen", -1);
639   // 
640   // Set ALIC mother transparent
641   gMC->Gsatt("ALIC","SEEN",0);
642   //
643   // Set the volumes visible
644   gMC->Gsatt("TPC","SEEN",0);
645   gMC->Gsatt("TGAS","SEEN",0);
646   gMC->Gsatt("TPSG","SEEN",0);
647   gMC->Gsatt("TPHV","SEEN",1);
648   gMC->Gsatt("TPMH","SEEN",1);
649   gMC->Gsatt("TPEC","SEEN",0);
650   gMC->Gsatt("TRCS","SEEN",1);
651   gMC->Gsatt("TRCL","SEEN",1);
652   gMC->Gsatt("TPWL","SEEN",1);
653   gMC->Gsatt("TPWI","SEEN",1);
654   gMC->Gsatt("TPWS","SEEN",1);
655   gMC->Gsatt("TPW1","SEEN",1);
656   gMC->Gsatt("TPS1","SEEN",1);
657   gMC->Gsatt("TPS2","SEEN",1);
658   gMC->Gsatt("TPG1","SEEN",1);
659   gMC->Gsatt("TPG2","SEEN",1);
660   gMC->Gsatt("TPWC","SEEN",1);
661   gMC->Gsatt("TPSI","SEEN",1); 
662   gMC->Gsatt("TPSO","SEEN",1);
663   gMC->Gsatt("TPCO","SEEN",1);
664   gMC->Gsatt("TPOV","SEEN",1);
665   gMC->Gsatt("TPVD","SEEN",1);
666   //
667   gMC->Gdopt("hide", "on");
668   gMC->Gdopt("shad", "on");
669   gMC->Gsatt("*", "fill", 7);
670   gMC->SetClipBox(".");
671   gMC->SetClipBox("*", 0, 1000, -1000, 1000, -1000, 1000);
672   gMC->DefaultRange();
673   gMC->Gdraw("alic", 40, 30, 0, 12, 9.5, .025, .025);
674   gMC->Gdhead(1111, "Time Projection Chamber");
675   gMC->Gdman(18, 4, "MAN");
676   gMC->Gdopt("hide","off");
677 }
678
679 //_____________________________________________________________________________
680 void AliTPCv3::CreateMaterials()
681 {
682   //
683   // Define materials for version 2 of the Time Projection Chamber
684   //
685
686
687   //
688   // Increase maximum number of steps
689   gMC->SetMaxNStep(30000);
690   //
691   AliTPC::CreateMaterials();
692 }
693
694 //_____________________________________________________________________________
695 void AliTPCv3::Init()
696 {
697   //
698   // Initialises version 3 of the TPC after that it has been built
699   //
700   Int_t *idtmed = fIdtmed->GetArray()-399;
701
702   AliTPC::Init();
703
704   fIdSens1=gMC->VolId("TGAS"); // drift gas as a sensitive volume
705
706   gMC->SetMaxNStep(30000); // max. number of steps increased
707
708   gMC->Gstpar(idtmed[403],"LOSS",5);
709
710   printf("*** TPC version 3 initialized ***\n");
711   printf("Maximum number of steps = %d\n",gMC->GetMaxNStep());
712
713   //
714   
715 }
716
717 //_____________________________________________________________________________
718 void AliTPCv3::StepManager()
719 {
720   //
721   // Called for every step in the Time Projection Chamber
722   //
723
724   //
725   // parameters used for the energy loss calculations
726   //
727   const Float_t prim = 14.35; // number of primary collisions per 1 cm
728   const Float_t poti = 20.77e-9; // first ionization potential for Ne/CO2
729   const Float_t w_ion = 35.97e-9; // energy for the ion-electron pair creation 
730  
731  
732   const Float_t big = 1.e10;
733
734   Int_t id,copy;
735   TLorentzVector pos;
736   Float_t hits[4];
737   Int_t vol[2];  
738   TClonesArray &lhits = *fHits;
739   
740   vol[1]=0;
741   vol[0]=0;
742
743   //
744
745   gMC->SetMaxStep(big);
746   
747   if(!gMC->IsTrackAlive()) return; // particle has disappeared
748   
749   Float_t charge = gMC->TrackCharge();
750   
751   if(TMath::Abs(charge)<=0.) return; // take only charged particles
752   
753   
754   id=gMC->CurrentVolID(copy);
755   
756   // Check the sensitive volume
757   
758   if (id != fIdSens1) return;
759   
760   //
761   //  charged particle is in the sensitive volume
762   //
763   
764   if(gMC->TrackStep() > 0) {
765
766     
767     Int_t nel = (Int_t)(((gMC->Edep())-poti)/w_ion) + 1;
768     nel=TMath::Min(nel,300); // 300 electrons corresponds to 10 keV
769     
770     gMC->TrackPosition(pos);
771     hits[0]=pos[0];
772     hits[1]=pos[1];
773     hits[2]=pos[2];
774
775     //
776     // check the selected side of the TPC
777     //
778  
779     if(fSide && fSide*hits[2]<=0.) return;
780
781     hits[3]=(Float_t)nel;
782     
783     // Add this hit
784    
785     new(lhits[fNhits++]) AliTPChit(fIshunt,gAlice->CurrentTrack(),vol,hits);
786     
787   } 
788   
789   // Stemax calculation for the next step
790   
791   Float_t pp;
792   TLorentzVector mom;
793   gMC->TrackMomentum(mom);
794   Float_t ptot=mom.Rho();
795   Float_t beta_gamma = ptot/gMC->TrackMass();
796   
797   if(gMC->IdFromPDG(gMC->TrackPid()) <= 3 && ptot > 0.002)
798     { 
799       pp = prim*1.58; // electrons above 20 MeV/c are on the plateau!
800     }
801   else
802     {
803       pp=prim*BetheBloch(beta_gamma);    
804       if(TMath::Abs(charge) > 1.) pp *= (charge*charge);
805     }
806   
807   Float_t random[1];
808   gMC->Rndm(random,1); // good, old GRNDM from Geant3
809   
810   Double_t rnd = (Double_t)random[0];
811   
812   gMC->SetMaxStep(-TMath::Log(rnd)/pp);
813   
814 }
815
816 //_____________________________________________________________________________
817 Float_t AliTPCv3::BetheBloch(Float_t bg)
818 {
819   //
820   // Bethe-Bloch energy loss formula
821   //
822   const Double_t p1=0.76176e-1;
823   const Double_t p2=10.632;
824   const Double_t p3=0.13279e-4;
825   const Double_t p4=1.8631;
826   const Double_t p5=1.9479;
827
828   Double_t dbg = (Double_t) bg;
829
830   Double_t beta = dbg/TMath::Sqrt(1.+dbg*dbg);
831
832   Double_t aa = TMath::Power(beta,p4);
833   Double_t bb = TMath::Power(1./dbg,p5);
834
835   bb=TMath::Log(p3+bb);
836   
837   return ((Float_t)((p2-aa-bb)*p1/aa));
838 }