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