]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCv2.cxx
caching of the correction coeficients from the graph
[u/mrichter/AliRoot.git] / TPC / AliTPCv2.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 //
19 ///////////////////////////////////////////////////////////////////////////////
20 //                                                                           //
21 //  Time Projection Chamber version 2 -- detailed TPC and slow simulation    //
22 //                                                                           //
23 //Begin_Html
24 /*
25 <img src="picts/AliTPCv2Class.gif">
26 */
27 //End_Html
28 //                                                                           //
29 //                                                                           //
30 ///////////////////////////////////////////////////////////////////////////////
31
32 //#include <stdlib.h>
33
34 #include <TLorentzVector.h>
35 #include <TPDGCode.h>
36 #include <TString.h>
37 #include "AliLog.h"
38 #include "AliMathBase.h"
39 #include "AliTrackReference.h"
40 #include "AliTPCParam.h"
41 #include "AliTPCTrackHitsV2.h"
42 #include "AliTPCv2.h"
43 #include "AliGeomManager.h"
44 #include "TGeoVolume.h"
45 #include "TGeoPcon.h"
46 #include "TGeoTube.h"
47 #include "TGeoPgon.h"
48 #include "TGeoTrd1.h"
49 #include "TGeoCompositeShape.h"
50 #include "TGeoPara.h"
51 #include "TGeoPhysicalNode.h"
52 #include "TGeoHalfSpace.h"
53 #include "TTreeStream.h"
54
55 ClassImp(AliTPCv2)
56  
57 //_____________________________________________________________________________
58 AliTPCv2::AliTPCv2(const char *name, const char *title) :
59   AliTPC(name, title),
60   fIdSens(0),
61   fIDrift(0),
62   fSecOld(0) 
63 {
64   //
65   // Standard constructor for Time Projection Chamber version 2
66   //
67
68
69   SetBufferSize(128000);
70
71
72 //   if (fTPCParam)
73 //      fTPCParam->Write(fTPCParam->GetTitle());
74 }
75  
76 //_____________________________________________________________________________
77 void AliTPCv2::CreateGeometry()
78 {
79   //
80   // Create the geometry of Time Projection Chamber version 2
81   //
82   //Begin_Html
83   /*
84     <img src="picts/AliTPC.gif">
85   */
86   //End_Html
87   //Begin_Html
88   /*
89     <img src="picts/AliTPCv2Tree.gif">
90   */
91   //End_Html
92
93   //----------------------------------------------------------
94   // This geometry is written using TGeo class
95   // Firstly the shapes are defined, and only then the volumes
96   // What is recognized by the MC are volumes
97   //----------------------------------------------------------
98   //
99   //  tpc - this will be the mother volume
100   //
101
102   //
103   // here I define a volume TPC
104   // retrive the medium name with "TPC_" as a leading string
105   //
106   TGeoPcon *tpc = new TGeoPcon(0.,360.,24); //24 sections
107   //
108   tpc->DefineSection(0,-291.,77.,278.);
109   tpc->DefineSection(1,-270,77.,278.);
110   //
111   tpc->DefineSection(2,-270.,77.,278.);
112   tpc->DefineSection(3,-259.6,70.,278.);
113   //
114   tpc->DefineSection(4,-259.6,68.1,278.);
115   tpc->DefineSection(5,-253.6,68.1,278.);
116   //
117   tpc->DefineSection(6,-253.6,68.,278.);
118   tpc->DefineSection(7,-74.0,60.8,278.);
119   //
120   tpc->DefineSection(8,-74.0,60.1,278.);
121   tpc->DefineSection(9,-73.3,60.1,278.);
122   //
123   tpc->DefineSection(10,-73.3,56.9,278.); 
124   tpc->DefineSection(11,-68.5,56.9,278.);
125   //
126   tpc->DefineSection(12,-68.5,60.,278.);
127   tpc->DefineSection(13,-65.,60.,278.);
128   //
129   tpc->DefineSection(14,-65.,56.9,278.); 
130   tpc->DefineSection(15,73.3,56.9,278.);
131   //
132   tpc->DefineSection(16,73.3,60.1,278.);
133   tpc->DefineSection(17,74.0,60.1,278.);
134   //
135   tpc->DefineSection(18,74.0,60.8,278.);
136   tpc->DefineSection(19,253.6,65.5,278.);
137   //
138   tpc->DefineSection(20,253.6,65.6,278.);
139   tpc->DefineSection(21,259.6,65.6,278.);
140   //
141   tpc->DefineSection(22,259.6,70.0,278.);
142   tpc->DefineSection(23,291.,77.,278.);
143   //
144   TGeoMedium *m1 = gGeoManager->GetMedium("TPC_Air");
145   TGeoVolume *v1 = new TGeoVolume("TPC_M",tpc,m1);
146   //
147   // drift volume - sensitive volume, extended beyond the
148   // endcaps, because of the alignment
149   //
150   TGeoPcon *dvol = new TGeoPcon(0.,360.,6);
151   dvol->DefineSection(0,-260.,74.5,264.4);
152   dvol->DefineSection(1,-253.6,74.5,264.4);
153   //
154   dvol->DefineSection(2,-253.6,76.6774,258.);
155   dvol->DefineSection(3,253.6,76.6774,258.); 
156   //
157   dvol->DefineSection(4,253.6,74.5,264.4);
158   dvol->DefineSection(5,260.,74.5,264.4);
159   //
160   TGeoMedium *m5 = gGeoManager->GetMedium("TPC_Ne-CO2-N-2");
161   TGeoVolume *v9 = new TGeoVolume("TPC_Drift",dvol,m5);
162   //
163   v1->AddNode(v9,1);
164   //
165   // outer insulator
166   //
167   TGeoPcon *tpco = new TGeoPcon(0.,360.,6); //insulator
168   //
169   tpco->DefineSection(0,-256.6,264.8,278.);
170   tpco->DefineSection(1,-253.6,264.8,278.);
171   //
172   tpco->DefineSection(2,-253.6,258.,278.);
173   tpco->DefineSection(3,250.6,258.,278.);
174   //
175   tpco->DefineSection(4,250.6,258.,275.5);
176   tpco->DefineSection(5,253.6,258.,275.5);
177   //
178   TGeoMedium *m2 = gGeoManager->GetMedium("TPC_CO2");
179   TGeoVolume *v2 = new TGeoVolume("TPC_OI",tpco,m2);
180   //
181   TGeoRotation *segrot;//segment rotations
182   //
183   // outer containment vessel
184   //
185   TGeoPcon *tocv = new TGeoPcon(0.,360.,6);  // containment vessel
186   //
187   tocv->DefineSection(0,-256.6,264.8,278.);
188   tocv->DefineSection(1,-253.6,264.8,278.);
189   //
190   tocv->DefineSection(2,-253.6,274.8124,278.);
191   tocv->DefineSection(3,247.6,274.8124,278.);  
192   //
193   tocv->DefineSection(4,247.6,270.4,278.);
194   tocv->DefineSection(5,250.6,270.4,278.);
195   //
196   TGeoMedium *m3 = gGeoManager->GetMedium("TPC_Al");
197   TGeoVolume *v3 = new TGeoVolume("TPC_OCV",tocv,m3); 
198   //
199   TGeoTubeSeg *to1 = new TGeoTubeSeg(274.8174,277.995,252.1,0.,59.9); //epoxy
200   TGeoTubeSeg *to2 = new TGeoTubeSeg(274.8274,277.985,252.1,0.,59.9); //tedlar
201   TGeoTubeSeg *to3 = new TGeoTubeSeg(274.8312,277.9812,252.1,0.,59.9);//prepreg2
202   TGeoTubeSeg *to4 = new TGeoTubeSeg(274.9062,277.9062,252.1,0.,59.9);//nomex
203   TGeoTubeSeg *tog5 = new TGeoTubeSeg(274.8174,277.995,252.1,59.9,60.);//epoxy
204   //
205   TGeoMedium *sm1 = gGeoManager->GetMedium("TPC_Epoxy");
206   TGeoMedium *sm2 = gGeoManager->GetMedium("TPC_Tedlar");
207   TGeoMedium *sm3 = gGeoManager->GetMedium("TPC_Prepreg2");
208   TGeoMedium *sm4 = gGeoManager->GetMedium("TPC_Nomex");
209   //
210   TGeoVolume *tov1 = new TGeoVolume("TPC_OCV1",to1,sm1);
211   TGeoVolume *tov2 = new TGeoVolume("TPC_OCV2",to2,sm2);
212   TGeoVolume *tov3 = new TGeoVolume("TPC_OCV3",to3,sm3);
213   TGeoVolume *tov4 = new TGeoVolume("TPC_OCV4",to4,sm4);
214   TGeoVolume *togv5 = new TGeoVolume("TPC_OCVG5",tog5,sm1);
215   //-------------------------------------------------------
216   //  Tpc Outer Field Cage
217   //  daughters - composite (sandwich)
218   //-------------------------------------------------------
219
220   TGeoPcon *tofc = new TGeoPcon(0.,360.,6);
221   //
222   tofc->DefineSection(0,-253.6,258.,269.6);
223   tofc->DefineSection(1,-250.6,258.,269.6);
224   //
225   tofc->DefineSection(2,-250.6,258.,260.0676); 
226   tofc->DefineSection(3,250.6,258.,260.0676);
227   //
228   tofc->DefineSection(4,250.6,258.,275.5);
229   tofc->DefineSection(5,253.6,258.,275.5);
230   //
231   TGeoVolume *v4 = new TGeoVolume("TPC_TOFC",tofc,m3); 
232   //sandwich
233   TGeoTubeSeg *tf1 = new TGeoTubeSeg(258.0,260.0676,252.1,0.,59.9); //tedlar
234   TGeoTubeSeg *tf2 = new TGeoTubeSeg(258.0038,260.0638,252.1,0.,59.9); //prepreg3
235   TGeoTubeSeg *tf3 = new TGeoTubeSeg(258.0338,260.0338,252.1,0.,59.9);//nomex
236   TGeoTubeSeg *tfg4 = new TGeoTubeSeg(258.0,260.0676,252.1,59.9,60.); //epoxy glue
237   //
238   TGeoMedium *sm5 = gGeoManager->GetMedium("TPC_Prepreg3");
239   //
240   TGeoVolume *tf1v = new TGeoVolume("TPC_OFC1",tf1,sm2);
241   TGeoVolume *tf2v = new TGeoVolume("TPC_OFC2",tf2,sm5);
242   TGeoVolume *tf3v = new TGeoVolume("TPC_OFC3",tf3,sm4);
243   TGeoVolume *tfg4v = new TGeoVolume("TPC_OFCG4",tfg4,sm1);
244   //
245   // outer part - positioning
246   //
247   tov1->AddNode(tov2,1); tov2->AddNode(tov3,1); tov3->AddNode(tov4,1);//ocv
248   //
249   tf1v->AddNode(tf2v,1); tf2v->AddNode(tf3v,1);//ofc
250   //
251   TGeoVolumeAssembly *t200 = new TGeoVolumeAssembly("TPC_OCVSEG");
252   TGeoVolumeAssembly *t300 = new TGeoVolumeAssembly("TPC_OFCSEG");
253   //
254   // assembly OCV and OFC
255   //
256   // 1st - no rotation
257   t200->AddNode(tov1,1); t200->AddNode(togv5,1);
258   t300->AddNode(tf1v,1); t300->AddNode(tfg4v,1);
259   // 2nd - rotation 60 deg
260   segrot = new TGeoRotation();
261   segrot->RotateZ(60.);
262   t200->AddNode(tov1,2,segrot); t200->AddNode(togv5,2,segrot);
263   t300->AddNode(tf1v,2,segrot); t300->AddNode(tfg4v,2,segrot);
264   // 3rd rotation 120 deg
265   segrot = new TGeoRotation();
266   segrot->RotateZ(120.);
267   t200->AddNode(tov1,3,segrot); t200->AddNode(togv5,3,segrot);
268   t300->AddNode(tf1v,3,segrot); t300->AddNode(tfg4v,3,segrot);
269   //4th rotation 180 deg
270   segrot = new TGeoRotation();
271   segrot->RotateZ(180.);
272   t200->AddNode(tov1,4,segrot); t200->AddNode(togv5,4,segrot);
273   t300->AddNode(tf1v,4,segrot); t300->AddNode(tfg4v,4,segrot);
274   //5th rotation 240 deg
275   segrot = new TGeoRotation();
276   segrot->RotateZ(240.);
277   t200->AddNode(tov1,5,segrot); t200->AddNode(togv5,5,segrot);
278   t300->AddNode(tf1v,5,segrot); t300->AddNode(tfg4v,5,segrot);
279   //6th rotation 300 deg
280   segrot = new TGeoRotation();
281   segrot->RotateZ(300.);
282   t200->AddNode(tov1,6,segrot); t200->AddNode(togv5,6,segrot);
283   t300->AddNode(tf1v,6,segrot); t300->AddNode(tfg4v,6,segrot);
284   //
285   v3->AddNode(t200,1,new TGeoTranslation(0.,0.,-1.5)); v4->AddNode(t300,1);
286   //
287   v2->AddNode(v3,1); v2->AddNode(v4,1); 
288   //
289   v1->AddNode(v2,1);
290   //--------------------------------------------------------------------
291   // Tpc Inner INsulator (CO2) 
292   // the cones, the central drum and the inner f.c. sandwich with a piece
293   // of the flane will be placed in the TPC
294   //--------------------------------------------------------------------
295   TGeoPcon *tpci = new TGeoPcon(0.,360.,4);
296   //
297   tpci->DefineSection(0,-253.6,68.4,76.6774);
298   tpci->DefineSection(1,-74.0,61.2,76.6774);
299   //
300   tpci->DefineSection(2,74.0,61.2,76.6774);  
301   //
302   tpci->DefineSection(3,253.6,65.9,76.6774);
303   //
304   TGeoVolume *v5 = new TGeoVolume("TPC_INI",tpci,m2);
305   //
306   // now the inner field cage - only part of flanges (2 copies)
307   //
308   TGeoTube *tif1 = new TGeoTube(69.9,76.6774,1.5); 
309   TGeoVolume *v6 = new TGeoVolume("TPC_IFC1",tif1,m3);
310   //
311  //---------------------------------------------------------
312   // Tpc Inner Containment vessel - Muon side
313   //---------------------------------------------------------
314   TGeoPcon *tcms = new TGeoPcon(0.,360.,10);
315   //
316   tcms->DefineSection(0,-259.1,68.1,74.2);
317   tcms->DefineSection(1,-253.6,68.1,74.2);
318   //
319   tcms->DefineSection(2,-253.6,68.1,68.4);
320   tcms->DefineSection(3,-74.0,60.9,61.2);
321   //
322   tcms->DefineSection(4,-74.0,60.1,61.2);
323   tcms->DefineSection(5,-73.3,60.1,61.2);
324   //
325   tcms->DefineSection(6,-73.3,56.9,61.2);
326   tcms->DefineSection(7,-73.0,56.9,61.2);
327   //
328   tcms->DefineSection(8,-73.0,56.9,58.8);
329   tcms->DefineSection(9,-71.3,56.9,58.8);
330   //
331   TGeoVolume *v7 = new TGeoVolume("TPC_ICVM",tcms,m3);
332   //-----------------------------------------------
333   // inner containment vessel - shaft side
334   //-----------------------------------------------
335   TGeoPcon *tcss = new TGeoPcon(0.,360.,10);
336   //
337   tcss->DefineSection(0,71.3,56.9,58.8);
338   tcss->DefineSection(1,73.0,56.9,58.8);
339   //
340   tcss->DefineSection(2,73.0,56.9,61.2);
341   tcss->DefineSection(3,73.3,56.9,61.2);
342   //  
343   tcss->DefineSection(4,73.3,60.1,61.2);
344   tcss->DefineSection(5,74.0,60.1,61.2);
345   //
346   tcss->DefineSection(6,74.0,60.9,61.2);
347   tcss->DefineSection(7,253.6,65.6,65.9);
348   //
349   tcss->DefineSection(8,253.6,65.6,74.2);
350   tcss->DefineSection(9,258.1,65.6,74.2);
351   //
352   TGeoVolume *v8 = new TGeoVolume("TPC_ICVS",tcss,m3);
353   //-----------------------------------------------
354   //  Inner field cage
355   //  define 4 parts and make an assembly
356   //-----------------------------------------------
357   // part1 - Al - 2 copies
358   TGeoTube *t1 = new TGeoTube(76.6774,78.845,0.75);
359   TGeoVolume *tv1 = new TGeoVolume("TPC_IFC2",t1,m3);
360   // sandwich - outermost parts - 2 copies
361   //
362   // segment outermost
363   //
364   TGeoTubeSeg *t2 = new TGeoTubeSeg(76.6774,78.845,74.175,350.,109.4); // tedlar 38 microns
365   TGeoTubeSeg *t3 = new TGeoTubeSeg(76.6812,78.8412,74.175,350.,109.4); // prepreg2 500 microns
366   TGeoTubeSeg *t4 = new TGeoTubeSeg(76.7312,78.7912,74.175,350.,109.4); // prepreg3 300 microns
367   TGeoTubeSeg *t5 = new TGeoTubeSeg(76.7612,78.7612,74.175,350.,109.4); // nomex 2 cm
368   TGeoTubeSeg *tepox1 = new TGeoTubeSeg(76.6774,78.845,74.175,109.4,110.);//epoxy
369   TGeoTubeSeg *tpr1 = new TGeoTubeSeg(78.845,78.885,74.175,109.,111.);
370   
371   // volumes for the outer part  
372   TGeoVolume *tv2 = new TGeoVolume("TPC_IFC3",t2,sm2);
373   TGeoVolume *tv3 = new TGeoVolume("TPC_IFC4",t3,sm3);
374   TGeoVolume *tv4 = new TGeoVolume("TPC_IFC5",t4,sm5);
375   TGeoVolume *tv5 = new TGeoVolume("TPC_IFC6",t5,sm4);
376   TGeoVolume *tvep1 = new TGeoVolume("TPC_IFEPOX1",tepox1,sm1); 
377   TGeoVolume *tvpr1 = new TGeoVolume("TPC_PRSTR1",tpr1,sm2); 
378   //
379   // middle parts - 2 copies
380   //
381   // segment middle
382   //
383   TGeoTubeSeg *t6 = new TGeoTubeSeg(76.6774,78.795,5.,350.,109.4); // tedlar 38 microns
384   TGeoTubeSeg *t7 = new TGeoTubeSeg(76.6812,78.7912,5.,350.,109.4); // prepreg2 250 microns
385   TGeoTubeSeg *t8 = new TGeoTubeSeg(76.7062,78.7662,5.,350.,109.4); // prepreg3 300 microns
386   TGeoTubeSeg *t9 = new TGeoTubeSeg(76.7362,78.7362,5.,350.,109.4); // nomex 2 cm
387   TGeoTubeSeg *tepox2 = new TGeoTubeSeg(76.6774,78.795,5.,109.4,110.);//epoxy
388   TGeoTubeSeg *tpr2 = new TGeoTubeSeg(78.795,78.835,5.,109.,111.);
389   // volumes for the middle part
390   TGeoVolume *tv6 = new TGeoVolume("TPC_IFC7",t6,sm2);
391   TGeoVolume *tv7 = new TGeoVolume("TPC_IFC8",t7,sm3);
392   TGeoVolume *tv8 = new TGeoVolume("TPC_IFC9",t8,sm5);
393   TGeoVolume *tv9 = new TGeoVolume("TPC_IFC10",t9,sm4);
394   TGeoVolume *tvep2 = new TGeoVolume("TPC_IFEPOX2",tepox2,sm1);
395   TGeoVolume *tvpr2 = new TGeoVolume("TPC_PRSTR2",tpr2,sm2);
396   // central part - 1 copy
397   // 
398   // segment central part
399   //
400   TGeoTubeSeg *t10 = new TGeoTubeSeg(76.6774,78.785,93.75,350.,109.4); // tedlar 38 microns 
401   TGeoTubeSeg *t11 = new TGeoTubeSeg(76.6812,78.7812,93.75,350.,109.4); // prepreg3 500 microns
402   TGeoTubeSeg *t12 = new TGeoTubeSeg(76.7312,78.7312,93.75,350.,109.4); // nomex 2 cm 
403   TGeoTubeSeg *tepox3 = new TGeoTubeSeg(76.6774,78.785,93.75,109.4,110.);//epoxy
404   TGeoTubeSeg *tpr3 = new TGeoTubeSeg(78.785,78.825,93.75,109.,111.);
405   // volumes for the central part
406   TGeoVolume *tv10 = new TGeoVolume("TPC_IFC11",t10,sm2);
407   TGeoVolume *tv11 = new TGeoVolume("TPC_IFC12",t11,sm5);
408   TGeoVolume *tv12 = new TGeoVolume("TPC_IFC13",t12,sm4);
409   TGeoVolume *tvep3 = new TGeoVolume("TPC_IFEPOX3",tepox3,sm1);
410   TGeoVolume *tvpr3 = new TGeoVolume("TPC_PRSTR3",tpr3,sm2);  
411   //
412   // creating a sandwich for the outer par,t tv2 is the mother
413   //
414   tv2->AddNode(tv3,1); tv3->AddNode(tv4,1); tv4->AddNode(tv5,1);
415   //
416   // creating a sandwich for the middle part, tv6 is the mother
417   //
418   tv6->AddNode(tv7,1); tv7->AddNode(tv8,1); tv8->AddNode(tv9,1);
419   //
420   // creating a sandwich for the central part, tv10 is the mother
421   //
422   tv10->AddNode(tv11,1); tv11->AddNode(tv12,1);
423   //
424   TGeoVolumeAssembly *tv100 = new TGeoVolumeAssembly("TPC_IFC"); // ifc itself - 3 segments
425
426   //
427   // first segment - no rotation
428   //
429   // central
430   tv100->AddNode(tv10,1); //sandwich
431   tv100->AddNode(tvep3,1);//epoxy
432   tv100->AddNode(tvpr3,1);//prepreg strip                                    
433   // middle
434   tv100->AddNode(tv6,1,new TGeoTranslation(0.,0.,-98.75)); //sandwich1
435   tv100->AddNode(tv6,2,new TGeoTranslation(0.,0.,98.75)); // sandwich2
436   tv100->AddNode(tvep2,1,new TGeoTranslation(0.,0.,-98.75)); //epoxy
437   tv100->AddNode(tvep2,2,new TGeoTranslation(0.,0.,98.75)); //epoxy
438   tv100->AddNode(tvpr2,1,new TGeoTranslation(0.,0.,-98.75));//prepreg strip
439   tv100->AddNode(tvpr2,2,new TGeoTranslation(0.,0.,98.75));
440   // outer
441   tv100->AddNode(tv2,1,new TGeoTranslation(0.,0.,-177.925)); //sandwich
442   tv100->AddNode(tv2,2,new TGeoTranslation(0.,0.,177.925));
443   tv100->AddNode(tvep1,1,new TGeoTranslation(0.,0.,-177.925)); //epoxy
444   tv100->AddNode(tvep1,2,new TGeoTranslation(0.,0.,177.925));
445   tv100->AddNode(tvpr1,1,new TGeoTranslation(0.,0.,-177.925));//prepreg strip
446   tv100->AddNode(tvpr1,2,new TGeoTranslation(0.,0.,-177.925));
447   //
448   // second segment - rotation 120 deg.
449   //
450   segrot = new TGeoRotation();
451   segrot->RotateZ(120.);
452   //
453   // central    
454   tv100->AddNode(tv10,2,segrot); //sandwich
455   tv100->AddNode(tvep3,2,segrot);//epoxy
456   tv100->AddNode(tvpr3,2,segrot);//prepreg strip
457   // middle
458   tv100->AddNode(tv6,3,new TGeoCombiTrans(0.,0.,-98.75,segrot)); //sandwich1
459   tv100->AddNode(tv6,4,new TGeoCombiTrans(0.,0.,98.75,segrot)); // sandwich2
460   tv100->AddNode(tvep2,3,new TGeoCombiTrans(0.,0.,-98.75,segrot)); //epoxy
461   tv100->AddNode(tvep2,4,new TGeoCombiTrans(0.,0.,98.75,segrot)); //epoxy
462   tv100->AddNode(tvpr2,3,new TGeoCombiTrans(0.,0.,-98.75,segrot));//prepreg strip
463   tv100->AddNode(tvpr2,4,new TGeoCombiTrans(0.,0.,98.75,segrot));
464   //outer
465   tv100->AddNode(tv2,3,new TGeoCombiTrans(0.,0.,-177.925,segrot));//sandwich
466   tv100->AddNode(tv2,4,new TGeoCombiTrans(0.,0.,177.925,segrot));
467   tv100->AddNode(tvep1,3,new TGeoCombiTrans(0.,0.,-177.925,segrot));//epoxy
468   tv100->AddNode(tvep1,4,new TGeoCombiTrans(0.,0.,177.925,segrot));
469   tv100->AddNode(tvpr1,3,new TGeoCombiTrans(0.,0.,-177.925,segrot));//prepreg strip
470   tv100->AddNode(tvpr1,4,new TGeoCombiTrans(0.,0.,177.925,segrot));
471   //
472   //  third segment - rotation 240 deg.
473   //
474   segrot = new TGeoRotation();
475   segrot->RotateZ(240.);
476   //
477   // central    
478   tv100->AddNode(tv10,3,segrot); //sandwich
479   tv100->AddNode(tvep3,3,segrot);//epoxy
480   tv100->AddNode(tvpr3,3,segrot);//prepreg strip
481   // middle
482   tv100->AddNode(tv6,5,new TGeoCombiTrans(0.,0.,-98.75,segrot)); //sandwich1
483   tv100->AddNode(tv6,6,new TGeoCombiTrans(0.,0.,98.75,segrot)); // sandwich2
484   tv100->AddNode(tvep2,5,new TGeoCombiTrans(0.,0.,-98.75,segrot)); //epoxy
485   tv100->AddNode(tvep2,6,new TGeoCombiTrans(0.,0.,98.75,segrot)); //epoxy
486   tv100->AddNode(tvpr2,5,new TGeoCombiTrans(0.,0.,-98.75,segrot));//prepreg strip
487   tv100->AddNode(tvpr2,6,new TGeoCombiTrans(0.,0.,98.75,segrot));
488   //outer
489   tv100->AddNode(tv2,5,new TGeoCombiTrans(0.,0.,-177.925,segrot));//sandwich
490   tv100->AddNode(tv2,6,new TGeoCombiTrans(0.,0.,177.925,segrot));
491   tv100->AddNode(tvep1,5,new TGeoCombiTrans(0.,0.,-177.925,segrot));//epoxy
492   tv100->AddNode(tvep1,6,new TGeoCombiTrans(0.,0.,177.925,segrot));
493   tv100->AddNode(tvpr1,5,new TGeoCombiTrans(0.,0.,-177.925,segrot));//prepreg strip
494   tv100->AddNode(tvpr1,6,new TGeoCombiTrans(0.,0.,177.925,segrot));
495   // Al parts - rings
496   tv100->AddNode(tv1,1,new TGeoTranslation(0.,0.,-252.85));
497   tv100->AddNode(tv1,2,new TGeoTranslation(0.,0.,252.85));
498   //
499   v5->AddNode(v6,1, new TGeoTranslation(0.,0.,-252.1));
500   v5->AddNode(v6,2, new TGeoTranslation(0.,0.,252.1));
501   v1->AddNode(v5,1); v1->AddNode(v7,1); v1->AddNode(v8,1); 
502   v9->AddNode(tv100,1);
503   //
504   // central drum 
505   //
506   // flange + sandwich
507   //
508   TGeoPcon *cfl = new TGeoPcon(0.,360.,6);
509   cfl->DefineSection(0,-71.1,59.7,61.2);
510   cfl->DefineSection(1,-68.6,59.7,61.2);
511   //
512   cfl->DefineSection(2,-68.6,60.6124,61.2);
513   cfl->DefineSection(3,68.6,60.6124,61.2); 
514   //
515   cfl->DefineSection(4,68.6,59.7,61.2);
516   cfl->DefineSection(5,71.1,59.7,61.2);  
517   //
518   TGeoVolume *cflv = new TGeoVolume("TPC_CDR",cfl,m3);
519   // sandwich
520   TGeoTubeSeg *cd1 = new TGeoTubeSeg(60.6224,61.19,71.1,0.1,119.9);
521   TGeoTubeSeg *cd2 = new TGeoTubeSeg(60.6262,61.1862,71.1,0.1,119.9);
522   TGeoTubeSeg *cd3 = new TGeoTubeSeg(60.6462,61.1662,71.1,0.1,119.9);
523   TGeoTubeSeg *cd4 = new TGeoTubeSeg(60.6562,61.1562,71.1,0.1,119.9);
524   TGeoTubeSeg *tepox4 = new TGeoTubeSeg(60.6224,61.19,71.1,359.9,0.1);
525   //  TGeoTube *cd1 = new TGeoTube(60.6224,61.19,71.1);
526   //  TGeoTube *cd2 = new TGeoTube(60.6262,61.1862,71.1);
527   //  TGeoTube *cd3 = new TGeoTube(60.6462,61.1662,71.1);  
528   //  TGeoTube *cd4 = new TGeoTube(60.6562,61.1562,71.1);  
529   //
530   TGeoMedium *sm6 = gGeoManager->GetMedium("TPC_Prepreg1");
531   TGeoMedium *sm8 = gGeoManager->GetMedium("TPC_Epoxyfm");
532   TGeoVolume *cd1v = new TGeoVolume("TPC_CDR1",cd1,sm2); //tedlar
533   TGeoVolume *cd2v = new TGeoVolume("TPC_CDR2",cd2,sm6);// prepreg1
534   TGeoVolume *cd3v = new TGeoVolume("TPC_CDR3",cd3,sm8); //epoxy film
535   TGeoVolume *cd4v = new TGeoVolume("TPC_CDR4",cd4,sm4); //nomex
536   TGeoVolume *tvep4 = new TGeoVolume("TPC_IFEPOX4",tepox4,sm1);
537
538   //
539   // seals for central drum 2 copies
540   //
541   TGeoTube *cs = new TGeoTube(56.9,61.2,0.1);
542   TGeoMedium *sm7 = gGeoManager->GetMedium("TPC_Mylar");
543   TGeoVolume *csv = new TGeoVolume("TPC_CDRS",cs,sm7);
544   v1->AddNode(csv,1,new TGeoTranslation(0.,0.,-71.2));
545   v1->AddNode(csv,2,new TGeoTranslation(0.,0.,71.2));
546   //
547   // seal collars 
548   TGeoPcon *se = new TGeoPcon(0.,360.,6);
549   se->DefineSection(0,-72.8,59.7,61.2);
550   se->DefineSection(1,-72.3,59.7,61.2);
551   //
552   se->DefineSection(2,-72.3,58.85,61.2);
553   se->DefineSection(3,-71.6,58.85,61.2); 
554   //
555   se->DefineSection(4,-71.6,59.7,61.2);
556   se->DefineSection(5,-71.3,59.7,61.2);  
557   //
558   TGeoVolume *sev = new TGeoVolume("TPC_CDCE",se,m3);
559   //
560   TGeoTube *si = new TGeoTube(56.9,58.8,1.); 
561   TGeoVolume *siv = new TGeoVolume("TPC_CDCI",si,m3);
562   //
563   // define reflection matrix 
564   //
565   TGeoRotation *ref = new TGeoRotation("ref",90.,0.,90.,90.,180.,0.);
566   //
567   cd1v->AddNode(cd2v,1); cd2v->AddNode(cd3v,1); cd3v->AddNode(cd4v,1); //sandwich
568   // first segment  
569   cflv->AddNode(cd1v,1); cflv->AddNode(tvep4,1);
570   // second segment
571   segrot = new TGeoRotation();
572   segrot->RotateZ(120.);
573   cflv->AddNode(cd1v,2,segrot); cflv->AddNode(tvep4,2,segrot);
574   // third segment
575   segrot = new TGeoRotation();
576   segrot->RotateZ(240.);
577   cflv->AddNode(cd1v,3,segrot); cflv->AddNode(tvep4,3,segrot);
578   //
579   v1->AddNode(siv,1,new TGeoTranslation(0.,0.,-69.9));
580   v1->AddNode(siv,2,new TGeoTranslation(0.,0.,69.9));
581   v1->AddNode(sev,1); v1->AddNode(sev,2,ref); v1->AddNode(cflv,1);
582   //
583   // central membrane - 2 rings and a mylar membrane - assembly
584   //
585   TGeoTube *ih = new TGeoTube(81.05,84.05,0.3);
586   TGeoTube *oh = new TGeoTube(250.,256.,0.5);
587   TGeoTube *mem = new TGeoTube(84.05,250.,0.00115);
588
589   //
590   TGeoMedium *m4 = gGeoManager->GetMedium("TPC_G10");
591   //
592   TGeoVolume *ihv = new TGeoVolume("TPC_IHVH",ih,m3);
593   TGeoVolume *ohv = new TGeoVolume("TPC_OHVH",oh,m3);
594   
595   TGeoVolume *memv = new TGeoVolume("TPC_HV",mem,sm7);
596   //
597   TGeoVolumeAssembly *cm = new TGeoVolumeAssembly("TPC_HVMEM");
598   cm->AddNode(ihv,1);
599   cm->AddNode(ohv,1);
600   cm->AddNode(memv,1);
601  
602   v9->AddNode(cm,1);
603   //
604   // end caps - they are make as an assembly of single segments
605   // containing both readout chambers
606   //
607   Double_t openingAngle = 10.*TMath::DegToRad();
608   Double_t thick=1.5; // rib
609   Double_t shift = thick/TMath::Sin(openingAngle);
610   //
611   Double_t lowEdge = 86.3; // hole in the wheel
612   Double_t upEdge = 240.4; // hole in the wheel
613   //
614   new TGeoTubeSeg("sec",74.5,264.4,3.,0.,20.);
615   //
616   TGeoPgon *hole = new TGeoPgon("hole",0.,20.,1,4);
617   //
618   hole->DefineSection(0,-3.5,lowEdge-shift,upEdge-shift);
619   hole->DefineSection(1,-1.5,lowEdge-shift,upEdge-shift);
620   //
621   hole->DefineSection(2,-1.5,lowEdge-shift,upEdge+3.-shift);
622   hole->DefineSection(3,3.5,lowEdge-shift,upEdge+3.-shift);
623   //
624   Double_t ys = shift*TMath::Sin(openingAngle); 
625   Double_t xs = shift*TMath::Cos(openingAngle);
626   TGeoTranslation *tr = new TGeoTranslation("tr",xs,ys,0.);  
627   tr->RegisterYourself();
628   TGeoCompositeShape *chamber = new TGeoCompositeShape("sec-hole:tr");
629   TGeoVolume *sv = new TGeoVolume("TPC_WSEG",chamber,m3);
630   TGeoPgon *bar = new TGeoPgon("bar",0.,20.,1,2);
631   bar->DefineSection(0,-3.,131.5-shift,136.5-shift);
632   bar->DefineSection(1,1.5,131.5-shift,136.5-shift);
633   TGeoVolume *barv = new TGeoVolume("TPC_WBAR",bar,m3);
634   TGeoVolumeAssembly *ch = new TGeoVolumeAssembly("TPC_WCH");//empty segment
635   //
636   ch->AddNode(sv,1); ch->AddNode(barv,1,tr);
637   //
638   // readout chambers
639   //
640   // IROC first
641   //
642    TGeoTrd1 *ibody = new TGeoTrd1(13.8742,21.3328,4.29,21.15);
643    TGeoVolume *ibdv = new TGeoVolume("TPC_IROCB",ibody,m3);
644   // empty space
645    TGeoTrd1 *emp = new TGeoTrd1(12.3742,19.8328,3.99,19.65);
646    TGeoVolume *empv = new TGeoVolume("TPC_IROCE",emp,m1);
647    ibdv->AddNode(empv,1,new TGeoTranslation(0.,-0.3,0.));
648    //bars
649    Double_t tga = (19.8328-12.3742)/39.3;
650    Double_t xmin,xmax;
651    xmin = 9.55*tga+12.3742;
652    xmax = 9.95*tga+12.3742;
653    TGeoTrd1 *ib1 = new TGeoTrd1(xmin,xmax,3.29,0.2);
654    TGeoVolume *ib1v = new TGeoVolume("TPC_IRB1",ib1,m3);
655    empv->AddNode(ib1v,1,new TGeoTranslation("tt1",0.,0.7,-9.9));
656    xmin=19.4*tga+12.3742;
657    xmax=19.9*tga+12.3742;
658    TGeoTrd1 *ib2 = new TGeoTrd1(xmin,xmax,3.29,0.25);
659    TGeoVolume *ib2v = new TGeoVolume("TPC_TRB2",ib2,m3);
660    empv->AddNode(ib2v,1,new TGeoTranslation(0.,0.7,0.));
661    xmin=29.35*tga+12.3742;
662    xmax=29.75*tga+12.3742;
663    TGeoTrd1 *ib3 = new TGeoTrd1(xmin,xmax,3.29,0.2); 
664    TGeoVolume *ib3v = new TGeoVolume("TPC_IRB3",ib3,m3);    
665    empv->AddNode(ib3v,1,new TGeoTranslation(0.,0.7,9.9));
666    //
667    // holes for connectors
668    //
669    TGeoBBox *conn = new TGeoBBox(0.4,0.3,4.675); // identical for iroc and oroc
670    TGeoVolume *connv = new TGeoVolume("TPC_RCCON",conn,m1);
671    TString fileName(gSystem->Getenv("ALICE_ROOT"));
672    fileName += "/TPC/conn_iroc.dat";
673    ifstream in;
674    in.open(fileName.Data(), ios_base::in); // asci file
675    TGeoRotation *rrr[86];
676    for(Int_t i =0;i<86;i++){
677       Double_t y = 3.99;
678       Double_t x,z,ang;
679       in>>x>>z>>ang;
680       z-=26.5;
681       rrr[i]= new TGeoRotation();
682       rrr[i]->RotateY(ang);
683       ibdv->AddNode(connv,i+1,new TGeoCombiTrans(x,y,z,rrr[i]));
684    }
685    in.close();
686    // "cap"
687    new TGeoTrd1("icap",14.5974,23.3521,1.19,24.825);
688    // "hole"
689    new TGeoTrd1("ihole",13.8742,21.3328,1.2,21.15);
690    TGeoTranslation *tr1 = new TGeoTranslation("tr1",0.,0.,1.725);  
691    tr1->RegisterYourself();
692    TGeoCompositeShape *ic = new TGeoCompositeShape("icap-ihole:tr1");
693    TGeoVolume *icv = new TGeoVolume("TPC_IRCAP",ic,m3);
694    //
695    // pad plane and wire fixations
696    //
697    TGeoTrd1 *pp = new TGeoTrd1(14.5974,23.3521,0.3,24.825); //pad+iso
698    TGeoVolume *ppv = new TGeoVolume("TPC_IRPP",pp,m4);
699    TGeoPara *f1 = new TGeoPara(.6,.5,24.825,0.,-10.,0.);
700    TGeoVolume *f1v = new TGeoVolume("TPC_IRF1",f1,m4);
701    TGeoPara *f2 = new TGeoPara(.6,.5,24.825,0.,10.,0.);
702    TGeoVolume *f2v = new TGeoVolume("TPC_IRF2",f2,m4);
703    //
704    TGeoVolumeAssembly *iroc = new TGeoVolumeAssembly("TPC_IROC");
705    //
706    iroc->AddNode(ibdv,1);
707    iroc->AddNode(icv,1,new TGeoTranslation(0.,3.1,-1.725));
708    iroc->AddNode(ppv,1,new TGeoTranslation(0.,4.59,-1.725));
709    tga =(23.3521-14.5974)/49.65; 
710    Double_t xx = 24.825*tga+14.5974-0.6;
711    iroc->AddNode(f1v,1,new TGeoTranslation(-xx,5.39,-1.725));
712    iroc->AddNode(f2v,1,new TGeoTranslation(xx,5.39,-1.725));
713    //
714    // OROC
715    //
716    TGeoTrd1 *obody = new TGeoTrd1(22.2938,40.5084,4.19,51.65);
717    TGeoVolume *obdv = new TGeoVolume("TPC_OROCB",obody,m3);
718    TGeoTrd1 *oemp = new TGeoTrd1(20.2938,38.5084,3.89,49.65);
719    TGeoVolume *oempv = new TGeoVolume("TPC_OROCE",oemp,m1);
720    obdv->AddNode(oempv,1,new TGeoTranslation(0.,-0.3,0.));
721    //horizontal bars
722    tga=(38.5084-20.2938)/99.3;
723    xmin=tga*10.2+20.2938;
724    xmax=tga*10.6+20.2938;
725    TGeoTrd1 *ob1 = new TGeoTrd1(xmin,xmax,2.915,0.2);
726    TGeoVolume *ob1v = new TGeoVolume("TPC_ORB1",ob1,m3);
727    //
728    xmin=22.55*tga+20.2938;
729    xmax=24.15*tga+20.2938;
730    TGeoTrd1 *ob2 = new TGeoTrd1(xmin,xmax,2.915,0.8);
731    TGeoVolume *ob2v = new TGeoVolume("TPC_ORB2",ob2,m3);
732    //
733    xmin=36.1*tga+20.2938;
734    xmax=36.5*tga+20.2938;
735    TGeoTrd1 *ob3 = new TGeoTrd1(xmin,xmax,2.915,0.2);
736    TGeoVolume *ob3v = new TGeoVolume("TPC_ORB3",ob3,m3);
737    //
738    xmin=49.0*tga+20.2938;
739    xmax=50.6*tga+20.2938;   
740    TGeoTrd1 *ob4 = new TGeoTrd1(xmin,xmax,2.915,0.8);
741    TGeoVolume *ob4v = new TGeoVolume("TPC_ORB4",ob4,m3);
742    //
743    xmin=63.6*tga+20.2938;
744    xmax=64.0*tga+20.2938;
745    TGeoTrd1 *ob5 = new TGeoTrd1(xmin,xmax,2.915,0.2);
746    TGeoVolume *ob5v = new TGeoVolume("TPC_ORB5",ob5,m3);
747    //
748    xmin=75.5*tga+20.2938;
749    xmax=77.15*tga+20.2938;
750    TGeoTrd1 *ob6 = new TGeoTrd1(xmin,xmax,2.915,0.8);
751    TGeoVolume *ob6v = new TGeoVolume("TPC_ORB6",ob6,m3);
752    //
753    xmin=88.7*tga+20.2938;
754    xmax=89.1*tga+20.2938;
755    TGeoTrd1 *ob7 = new TGeoTrd1(xmin,xmax,2.915,0.2);
756    TGeoVolume *ob7v = new TGeoVolume("TPC_ORB7",ob7,m3);
757    //
758    oempv->AddNode(ob1v,1,new TGeoTranslation(0.,0.975,-39.25));
759    oempv->AddNode(ob2v,1,new TGeoTranslation(0.,0.975,-26.3));
760    oempv->AddNode(ob3v,1,new TGeoTranslation(0.,0.975,-13.35));
761    oempv->AddNode(ob4v,1,new TGeoTranslation(0.,0.975,0.15));
762    oempv->AddNode(ob5v,1,new TGeoTranslation(0.,0.975,14.15));
763    oempv->AddNode(ob6v,1,new TGeoTranslation(0.,0.975,26.7));
764    oempv->AddNode(ob7v,1,new TGeoTranslation(0.,0.975,39.25));
765    // vertical bars
766    TGeoBBox *ob8 = new TGeoBBox(0.8,2.915,5.1); 
767    TGeoBBox *ob9 = new TGeoBBox(0.8,2.915,5.975);
768    TGeoBBox *ob10 = new TGeoBBox(0.8,2.915,5.775);
769    TGeoBBox *ob11 = new TGeoBBox(0.8,2.915,6.25);
770    TGeoBBox *ob12 = new TGeoBBox(0.8,2.915,6.5);
771    //
772    TGeoVolume *ob8v = new TGeoVolume("TPC_ORB8",ob8,m3);
773    TGeoVolume *ob9v = new TGeoVolume("TPC_ORB9",ob9,m3);
774    TGeoVolume *ob10v = new TGeoVolume("TPC_ORB10",ob10,m3);
775    TGeoVolume *ob11v = new TGeoVolume("TPC_ORB11",ob11,m3);
776    TGeoVolume *ob12v = new TGeoVolume("TPC_ORB12",ob12,m3);
777    //
778    oempv->AddNode(ob8v,1,new TGeoTranslation(0.,0.975,-44.55));
779    oempv->AddNode(ob8v,2,new TGeoTranslation(0.,0.975,44.55));
780    oempv->AddNode(ob9v,1,new TGeoTranslation(0.,0.975,-33.075));
781    oempv->AddNode(ob9v,2,new TGeoTranslation(0.,0.975,-19.525));
782    oempv->AddNode(ob10v,1,new TGeoTranslation(0.,0.975,20.125));
783    oempv->AddNode(ob10v,2,new TGeoTranslation(0.,0.975,33.275));
784    oempv->AddNode(ob11v,1,new TGeoTranslation(0.,0.975,-6.9));
785    oempv->AddNode(ob12v,1,new TGeoTranslation(0.,0.975,7.45));
786    //
787    // holes for connectors
788    //
789    fileName = gSystem->Getenv("ALICE_ROOT");
790    fileName += "/TPC/conn_oroc.dat";
791    in.open(fileName.Data(), ios_base::in); // asci file
792    TGeoRotation *rr[78];
793    for(Int_t i =0;i<78;i++){
794       Double_t y =3.89;
795       Double_t x,z,ang;
796       Double_t x1,z1,x2,z2;
797       in>>x>>z>>ang;        
798       Double_t xr = 4.7*TMath::Sin(ang*TMath::DegToRad());
799       Double_t zr = 4.7*TMath::Cos(ang*TMath::DegToRad());
800       //
801       x1=xr+x; x2=-xr+x; z1=zr+z; z2 = -zr+z;      
802       //
803       rr[i]= new TGeoRotation();
804       rr[i]->RotateY(ang); 
805       z1-=54.95;
806       z2-=54.95;
807       //
808       obdv->AddNode(connv,i+1,new TGeoCombiTrans(x1,y,z1,rr[i]));
809       obdv->AddNode(connv,i+79,new TGeoCombiTrans(x2,y,z2,rr[i]));
810    }
811    in.close();
812    // cap
813    new TGeoTrd1("ocap",23.3874,43.5239,1.09,57.1);
814    new TGeoTrd1("ohole",22.2938,40.5084,1.09,51.65);
815    TGeoTranslation *tr5 = new TGeoTranslation("tr5",0.,0.,-2.15);
816    tr5->RegisterYourself();
817    TGeoCompositeShape *oc = new TGeoCompositeShape("ocap-ohole:tr5");
818    TGeoVolume *ocv = new TGeoVolume("TPC_ORCAP",oc,m3);
819    //
820    // pad plane and wire fixations
821    //
822    TGeoTrd1 *opp = new TGeoTrd1(23.3874,43.5239,0.3,57.1);
823    TGeoVolume *oppv = new TGeoVolume("TPC_ORPP",opp,m4);
824    //
825    tga=(43.5239-23.3874)/114.2;
826    TGeoPara *f3 = new TGeoPara(.7,.6,57.1,0.,-10.,0.);
827    TGeoPara *f4 = new TGeoPara(.7,.6,57.1,0.,10.,0.);  
828    xx = 57.1*tga+23.3874-0.7;
829    TGeoVolume *f3v = new TGeoVolume("TPC_ORF1",f3,m4);
830    TGeoVolume *f4v = new TGeoVolume("TPC_ORF2",f4,m4);
831    //
832    TGeoVolumeAssembly *oroc = new TGeoVolumeAssembly("TPC_OROC");
833    //
834    oroc->AddNode(obdv,1);
835    oroc->AddNode(ocv,1,new TGeoTranslation(0.,3.1,2.15));
836    oroc->AddNode(oppv,1,new TGeoTranslation(0.,4.49,2.15));
837    oroc->AddNode(f3v,1,new TGeoTranslation(-xx,5.39,2.15));
838    oroc->AddNode(f4v,1,new TGeoTranslation(xx,5.39,2.15));
839    // 
840    // now iroc and oroc are placed into a sector...
841    //
842    TGeoVolumeAssembly *secta = new TGeoVolumeAssembly("TPC_SECT"); // a-side
843    TGeoVolumeAssembly *sectc = new TGeoVolumeAssembly("TPC_SECT"); // c-side
844    TGeoRotation rot1("rot1",90.,90.,0.);
845    TGeoRotation rot2("rot2");
846    rot2.RotateY(10.);
847    TGeoRotation *rot = new TGeoRotation("rot");
848    *rot=rot1*rot2;
849    //
850    Double_t x0,y0;
851    x0=110.2*TMath::Cos(openingAngle);
852    y0=110.2*TMath::Sin(openingAngle);
853    TGeoCombiTrans *combi1a = new TGeoCombiTrans("combi1",x0,y0,1.09+0.195,rot); //a-side 
854    TGeoCombiTrans *combi1c = new TGeoCombiTrans("combi1",x0,y0,1.09+0.222,rot); //c-side
855    x0=188.45*TMath::Cos(openingAngle);
856    y0=188.45*TMath::Sin(openingAngle);
857    TGeoCombiTrans *combi2a = new TGeoCombiTrans("combi2",x0,y0,0.99+0.195,rot); //a-side
858    TGeoCombiTrans *combi2c = new TGeoCombiTrans("combi2",x0,y0,0.99+0.222,rot); //c-side
859    //
860    //
861    // A-side
862    //
863    secta->AddNode(ch,1);
864    secta->AddNode(iroc,1,combi1a);
865    secta->AddNode(oroc,1,combi2a);
866    //
867    // C-side
868    //
869    sectc->AddNode(ch,1);
870    sectc->AddNode(iroc,1,combi1c);
871    sectc->AddNode(oroc,1,combi2c);
872    //
873    // now I try to make  wheels...
874    //
875    TGeoVolumeAssembly *wheela = new TGeoVolumeAssembly("TPC_ENDCAP");
876    TGeoVolumeAssembly *wheelc = new TGeoVolumeAssembly("TPC_ENDCAP");
877    //
878    TGeoRotation *rwh[18]; 
879    for(Int_t i =0;i<18;i++){
880      Double_t phi = (20.*i);
881      rwh[i]=new TGeoRotation();
882      rwh[i]->RotateZ(phi);
883      wheela->AddNode(secta,i+1,rwh[i]);
884      wheelc->AddNode(sectc,i+1,rwh[i]); 
885     
886    }
887    // wheels in the drift volume!   
888
889    TGeoCombiTrans *combi3 = new TGeoCombiTrans("combi3",0.,0.,256.6,ref);
890    v9->AddNode(wheela,1,combi3);
891    v9->AddNode(wheelc,2,new TGeoTranslation(0.,0.,-256.6));
892    //_____________________________________________________________
893    // service support wheel
894    //_____________________________________________________________
895   TGeoPgon *sw = new TGeoPgon(0.,20.,1,2);
896   sw->DefineSection(0,-4.,80.5,251.75);
897   sw->DefineSection(1,4.,80.5,251.75); 
898   TGeoVolume *swv = new TGeoVolume("TPC_SWSEG",sw,m3); //Al
899   //
900   thick=1.;
901   shift = thick/TMath::Sin(openingAngle);
902   TGeoPgon *sh = new TGeoPgon(0.,20.,1,2);
903   sh->DefineSection(0,-4.,81.5-shift,250.75-shift);
904   sh->DefineSection(1,4.,81.5-shift,250.75-shift);
905   TGeoVolume *shv = new TGeoVolume("TPC_SWS1",sh,m1); //Air
906   //
907   TGeoMedium *m9 =  gGeoManager->GetMedium("TPC_Si"); 
908   TGeoPgon *el = new TGeoPgon(0.,20.,1,2);
909   el->DefineSection(0,-1.872,81.5-shift,250.75-shift);
910   el->DefineSection(1,1.872,81.5-shift,250.75-shift);
911   TGeoVolume *elv = new TGeoVolume("TPC_ELEC",el,m9); //Si 
912   //
913   shv->AddNode(elv,1);
914   //
915   //
916   ys = shift*TMath::Sin(openingAngle);
917   xs = shift*TMath::Cos(openingAngle);
918   swv->AddNode(shv,1,new TGeoTranslation(xs,ys,0.));
919   // cover
920   TGeoPgon *co = new TGeoPgon(0.,20.,1,2);
921   co->DefineSection(0,-0.5,77.,255.25);
922   co->DefineSection(1,0.5,77.,255.25);
923   TGeoVolume *cov = new TGeoVolume("TPC_SWC1",co,m3);//Al
924   // hole in a cover
925   TGeoPgon *coh = new TGeoPgon(0.,20.,1,2);
926   shift=4./TMath::Sin(openingAngle);
927   coh->DefineSection(0,-0.5,85.-shift,247.25-shift);
928   coh->DefineSection(1,0.5,85.-shift,247.25-shift);  
929   //
930   TGeoVolume *cohv = new TGeoVolume("TPC_SWC2",coh,m1);
931   //
932   ys = shift*TMath::Sin(openingAngle);
933   xs = shift*TMath::Cos(openingAngle);  
934   cov->AddNode(cohv,1,new TGeoTranslation(xs,ys,0.));
935   //
936   // Sector as an Assembly
937   //
938   TGeoVolumeAssembly *swhs = new TGeoVolumeAssembly("TPC_SSWSEC");
939   swhs->AddNode(swv,1);
940   swhs->AddNode(cov,1,new TGeoTranslation(0.,0.,-4.5));
941   swhs->AddNode(cov,2,new TGeoTranslation(0.,0.,4.5));
942   //
943   // SSW as an Assembly of sectors
944   //
945   TGeoRotation *rsw[18];
946   TGeoVolumeAssembly *swheel = new TGeoVolumeAssembly("TPC_SSWHEEL");
947    for(Int_t i =0;i<18;i++){
948      Double_t phi = (20.*i);
949      rsw[i] = new TGeoRotation();
950      rsw[i]->RotateZ(phi);
951      swheel->AddNode(swhs,i+1,rsw[i]);   
952    }
953    v1->AddNode(swheel,1,new TGeoTranslation(0.,0.,-284.6));
954    v1->AddNode(swheel,2,new TGeoTranslation(0.,0.,284.6));
955
956    // sensitive strips - strip "0" is always set
957    // conditional
958    Int_t totrows;
959    totrows = fTPCParam->GetNRowLow() + fTPCParam->GetNRowUp();
960    Double_t *upar;
961    upar=NULL;
962    gGeoManager->Volume("TPC_Strip","PGON",m5->GetId(),upar);
963    upar=new Double_t [10];
964    upar[0]=0.;
965    upar[1]=360.;
966    upar[2]=18.;
967    upar[3]=2.;
968    //
969    upar[4]=-124.8;
970    upar[7]=124.8;
971
972    Double_t rlow=fTPCParam->GetPadRowRadiiLow(0);
973
974    upar[5]=rlow;
975    upar[6]=rlow+.01;
976    upar[8]=upar[5];
977    upar[9]=upar[6];
978    //
979    gGeoManager->Node("TPC_Strip",1,"TPC_Drift",0.,0.,124.82,0,kTRUE,upar,10);
980    gGeoManager->Node("TPC_Strip",totrows+1,
981                      "TPC_Drift",0.,0.,-124.82,0,kTRUE,upar,10);
982    //
983    // now, strips optionally
984    //
985    if(fSens){
986      //lower sectors
987      for(Int_t i=2;i<fTPCParam->GetNRowLow()+1;i++){
988        rlow=fTPCParam->GetPadRowRadiiLow(i-1);
989        upar[5]=rlow;
990        upar[6]=rlow+.01;
991        upar[8]=upar[5];
992        upar[9]=upar[6];
993        gGeoManager->Node("TPC_Strip",i,
994                          "TPC_Drift",0.,0.,124.82,0,kTRUE,upar,10);
995        gGeoManager->Node("TPC_Strip",totrows+i,
996                          "TPC_Drift",0.,0.,-124.82,0,kTRUE,upar,10);       
997      }
998      //upper sectors
999      for(Int_t i=1;i<fTPCParam->GetNRowUp()+1;i++){
1000        rlow=fTPCParam->GetPadRowRadiiUp(i-1); 
1001        upar[5]=rlow;
1002        upar[6]=rlow+.01;
1003        upar[8]=upar[5];
1004        upar[9]=upar[6];
1005        gGeoManager->Node("TPC_Strip",i+fTPCParam->GetNRowLow(),
1006                          "TPC_Drift",0.,0.,124.82,0,kTRUE,upar,10); 
1007        gGeoManager->Node("TPC_Strip",totrows+i+fTPCParam->GetNRowLow(),
1008                          "TPC_Drift",0.,0.,-124.82,0,kTRUE,upar,10); 
1009      }
1010    }//strips
1011   //----------------------------------------------------------
1012   // TPC Support Rods - MAKROLON
1013   //----------------------------------------------------------
1014   TGeoMedium *m6=gGeoManager->GetMedium("TPC_Makrolon");
1015   TGeoMedium *m7=gGeoManager->GetMedium("TPC_Cu");
1016   TGeoMedium *m10 =  gGeoManager->GetMedium("TPC_Alumina");
1017   TGeoMedium *m11 =  gGeoManager->GetMedium("TPC_Peek");
1018   TGeoMedium *m12 =  gGeoManager->GetMedium("TPC_Water");
1019   TGeoMedium *m13 = gGeoManager->GetMedium("TPC_Brass");
1020   // 
1021   // tpc rod is an assembly of 10 long parts and 2 short parts
1022   // connected with alu rings and plagged on both sides.
1023   //
1024   //
1025 // tpc rod long
1026 //
1027   TGeoPcon *rod = new TGeoPcon("rod",0.,360.,6);
1028  rod->DefineSection(0,-10.43,1.92,2.08);
1029  rod->DefineSection(1,-9.75,1.92,2.08);
1030
1031  rod->DefineSection(2,-9.75,1.8,2.2);
1032  rod->DefineSection(3,9.75,1.8,2.2);
1033
1034  rod->DefineSection(4,9.75,1.92,2.08);
1035  rod->DefineSection(5,10.43,1.92,2.08);
1036  //
1037  TGeoVolume *mrodl = new TGeoVolume("TPC_mrodl",rod,m6);
1038  //
1039  // tpc rod short 
1040  //
1041  TGeoPcon *rod1 = new TGeoPcon("rod1",0.,360.,6);
1042  rod1->DefineSection(0,-8.93,1.92,2.08);
1043  rod1->DefineSection(1,-8.25,1.92,2.08);
1044
1045  rod1->DefineSection(2,-8.25,1.8,2.2);
1046  rod1->DefineSection(3,8.25,1.8,2.2);
1047
1048  rod1->DefineSection(4,8.25,1.92,2.08);
1049  rod1->DefineSection(5,8.93,1.92,2.08);
1050  //
1051  TGeoVolume *mrods = new TGeoVolume("TPC_mrods",rod1,m6);
1052  //
1053  // below is for the resistor rod
1054  //
1055  // hole for the brass connectors
1056  //
1057
1058  new TGeoTube("hhole",0.,0.3,0.3);
1059  //
1060  //transformations for holes - initialy they
1061  // are placed at x=0 and negative y
1062  //
1063   TGeoRotation *rhole = new TGeoRotation();
1064   rhole->RotateX(90.);
1065   TGeoCombiTrans *transf[13];
1066   Char_t name[30];
1067   for(Int_t i=0;i<13;i++){
1068     sprintf(name,"transf%d",i);
1069     transf[i]= new TGeoCombiTrans(name,0.,-2.,-9.+i*1.5,rhole);
1070     transf[i]->RegisterYourself();
1071   }
1072   // union expression for holes
1073   TString operl("hhole:transf0");
1074   for (Int_t i=1;i<13;i++){
1075     sprintf(name,"+hhole:transf%d",i);
1076     operl.Append(name);   
1077   }
1078   //
1079  TString opers("hhole:transf1");
1080   for (Int_t i=2;i<12;i++){
1081     sprintf(name,"+hhole:transf%d",i);
1082     opers.Append(name);   
1083   }
1084   //union of holes
1085   new TGeoCompositeShape("hlv",operl.Data());
1086   new TGeoCompositeShape("hsv",opers.Data());
1087   //
1088   TGeoCompositeShape *rodl = new TGeoCompositeShape("rodl","rod-hlv");
1089   TGeoCompositeShape *rods = new TGeoCompositeShape("rods","rod1-hsv");
1090  //rods - volumes - makrolon rods with holes
1091   TGeoVolume *rodlv = new TGeoVolume("TPC_rodl",rodl,m6);
1092   TGeoVolume *rodsv = new TGeoVolume("TPC_rods",rods,m6);
1093   //brass connectors
1094  //connectors
1095   TGeoTube *bcon = new TGeoTube(0.,0.3,0.3);//connectors
1096   TGeoVolume *bconv = new TGeoVolume("TPC_bcon",bcon,m13);
1097  //
1098  // hooks holding strips
1099  //
1100  new TGeoBBox("hk1",0.625,0.015,0.75);
1101  new TGeoBBox("hk2",0.625,0.015,0.15);
1102  TGeoTranslation *tr21 = new TGeoTranslation("tr21",0.,-0.03,-0.6);
1103  TGeoTranslation *tr12 = new TGeoTranslation("tr12",0.,-0.03,0.6);
1104  tr21->RegisterYourself();
1105  tr12->RegisterYourself();
1106  
1107  TGeoCompositeShape *hook = new TGeoCompositeShape("hook","hk1+hk2:tr21+hk2:tr12");
1108  TGeoVolume *hookv = new TGeoVolume("TPC_hook",hook,m13);
1109  //
1110  // assembly of the short rod with connectors and hooks
1111  //
1112  //
1113  // short rod
1114  //
1115   TGeoVolumeAssembly *spart = new TGeoVolumeAssembly("TPC_spart");
1116   //
1117   spart->AddNode( rodsv,1);
1118   for(Int_t i=1;i<12;i++){
1119   spart->AddNode(bconv,i,transf[i]);
1120   }
1121   for(Int_t i =0;i<11;i++){
1122     spart->AddNode(hookv,i+1,new TGeoTranslation(0.,-2.315,-7.5+i*1.5));
1123   } 
1124  //
1125  // long rod
1126  //
1127   TGeoVolumeAssembly *lpart = new TGeoVolumeAssembly("TPC_lpart");
1128   //
1129   lpart->AddNode( rodlv,1);
1130   for(Int_t i=0;i<13;i++){
1131   lpart->AddNode(bconv,i+12,transf[i]);
1132   }
1133   for(Int_t i =0;i<13;i++){
1134     lpart->AddNode(hookv,i+12,new TGeoTranslation(0.,-2.315,-9.+i*1.5));
1135   }   
1136   //
1137   // alu ring
1138   //
1139   new TGeoTube("ring1",2.1075,2.235,0.53);
1140   new TGeoTube("ring2",1.7925,1.89,0.43);
1141   new TGeoTube("ring3",1.89,2.1075,0.05);
1142   TGeoCompositeShape *ring = new TGeoCompositeShape("ring","ring1+ring2+ring3");
1143   TGeoVolume *ringv = new TGeoVolume("TPC_ring",ring,m3);
1144   //
1145   // rod assembly
1146   //
1147   TGeoVolumeAssembly *tpcrrod = new TGeoVolumeAssembly("TPC_rrod");//rrod
1148   TGeoVolumeAssembly *tpcmrod = new TGeoVolumeAssembly("TPC_mrod");//makrolon rod  
1149   //long pieces
1150   for(Int_t i=0;i<11;i++){
1151     tpcrrod->AddNode(ringv,i+1,new TGeoTranslation(0.,0.,-105.+i*21));
1152     tpcmrod->AddNode(ringv,i+12,new TGeoTranslation(0.,0.,-105.+i*21));
1153   }
1154   for(Int_t i=0;i<10;i++){
1155     tpcrrod->AddNode(lpart,i+1,new TGeoTranslation(0.,0.,-94.5+i*21));
1156     tpcmrod->AddNode(mrodl,i+1,new TGeoTranslation(0.,0.,-94.5+i*21));      
1157   }
1158   //
1159   // short pieces
1160   //
1161   tpcrrod->AddNode(spart,1,new TGeoTranslation(0.,0.,-114.));
1162   tpcrrod->AddNode(spart,2,new TGeoTranslation(0.,0.,114.)); 
1163   tpcrrod->AddNode(ringv,23,new TGeoTranslation(0.,0.,-123.));
1164   tpcrrod->AddNode(ringv,24,new TGeoTranslation(0.,0.,123.));
1165   //
1166   tpcmrod->AddNode(mrods,1,new TGeoTranslation(0.,0.,-114.));
1167   tpcmrod->AddNode(mrods,2,new TGeoTranslation(0.,0.,114.)); 
1168   tpcmrod->AddNode(ringv,25,new TGeoTranslation(0.,0.,-123.));
1169   tpcmrod->AddNode(ringv,26,new TGeoTranslation(0.,0.,123.));
1170  //
1171   // left plaque
1172   //
1173   TGeoPcon *lp = new TGeoPcon(0.,360.,4);
1174   //
1175   lp->DefineSection(0,-125.8,1.92,2.235);
1176   lp->DefineSection(1,-124.8,1.92,2.235);
1177   //
1178   lp->DefineSection(2,-124.8,1.92,2.08);
1179   lp->DefineSection(3,-123.1,1.92,2.08);
1180   //
1181   TGeoVolume *lpv1 = new TGeoVolume("TPC_lpv1",lp,m6);
1182   TGeoVolume *lpv2 = new TGeoVolume("TPC_lpv2",lp,m6);
1183   // left ring
1184   TGeoTube *lr = new TGeoTube(2.1075,2.235,0.5);
1185   TGeoVolume *lrv = new TGeoVolume("TPC_lrv",lr,m3);
1186   //
1187   lpv2->AddNode(lrv,1,new TGeoTranslation(0.,0.,-125.3));
1188   //
1189   tpcrrod->AddNode(lpv2,1); 
1190   tpcmrod->AddNode(lpv1,1);
1191   //
1192   //  right plaque
1193   //
1194   TGeoTube *rp = new TGeoTube(1.92,2.08,2.025);
1195   TGeoVolume *rpv = new TGeoVolume("TPC_rpv",rp,m6);
1196   tpcrrod->AddNode(rpv,1, new TGeoTranslation(0.,0.,125.125)); 
1197   tpcmrod->AddNode(rpv,2,new TGeoTranslation(0.,0.,125.125));
1198   //
1199   //
1200   //HV rods - makrolon + 0.58cm (diameter) Cu
1201   TGeoTube *hvr = new TGeoTube(0.,1.465,126.5);
1202   TGeoTube *hvc = new TGeoTube(0.,0.29,126.5);
1203   //
1204   TGeoVolume *hvrv = new TGeoVolume("TPC_HV_Rod",hvr,m6);
1205   TGeoVolume *hvcv = new TGeoVolume("TPC_HV_Cable",hvc,m7);
1206   hvrv->AddNode(hvcv,1);
1207   //
1208   //resistor rod
1209   //
1210   TGeoTube *cr = new TGeoTube(0.,0.45,126.2);   
1211   TGeoTube *cw = new TGeoTube(0.,0.15,126.2);  
1212   TGeoVolume *crv = new TGeoVolume("TPC_CR",cr,m10);
1213   TGeoVolume *cwv = new TGeoVolume("TPC_W",cw,m12);   
1214   //
1215   // ceramic rod with water
1216   //
1217   crv->AddNode(cwv,1);
1218   //
1219   //peek rod
1220   //
1221   TGeoTube *pr =new TGeoTube(0.2,0.35,126.2);  
1222   TGeoVolume *prv = new TGeoVolume("TPC_PR",pr,m11); 
1223   //
1224   // copper plates with connectors
1225   //
1226   new TGeoTube("tub",0.,1.7,0.025);
1227   //
1228   // half space - points on the plane and a normal vector
1229   //
1230   Double_t n[3],p[3];
1231   Double_t slope = TMath::Tan(22.*TMath::DegToRad());
1232   Double_t intp = 1.245;
1233   //
1234   Double_t b = slope*slope+1.;
1235   p[0]=intp*slope/b;
1236   p[1]=-intp/b;
1237   p[2]=0.;
1238   //
1239   n[0]=-p[0];
1240   n[1]=-p[1];
1241   n[2]=0.;
1242   Double_t norm;
1243   norm=TMath::Sqrt(n[0]*n[0]+n[1]*n[1]);
1244   n[0] /= norm;
1245   n[1] /=norm;
1246   //
1247   new TGeoHalfSpace("sp1",p,n);
1248   //
1249   slope = -slope; 
1250   //
1251   p[0]=intp*slope/b;
1252   p[1]=-intp/b;
1253   //
1254   n[0]=-p[0];
1255   n[1]=-p[1];
1256   norm=TMath::Sqrt(n[0]*n[0]+n[1]*n[1]);
1257   n[0] /= norm;
1258   n[1] /=norm;
1259   //
1260   new TGeoHalfSpace("sp2",p,n);
1261   // holes for rods
1262  //holes
1263  new TGeoTube("h1",0.,0.5,0.025);
1264  new TGeoTube("h2",0.,0.35,0.025);
1265  //translations:
1266  TGeoTranslation *ttr11 = new TGeoTranslation("ttr11",-0.866,0.5,0.);
1267  TGeoTranslation *ttr22 = new TGeoTranslation("ttr22",0.866,0.5,0.);
1268  ttr11->RegisterYourself();
1269  ttr22->RegisterYourself();
1270  // elastic connector
1271  new TGeoBBox("elcon",0.72,0.005,0.3);
1272  TGeoRotation *crr1 = new TGeoRotation();
1273  crr1->RotateZ(-22.);
1274 TGeoCombiTrans *ctr1 = new TGeoCombiTrans("ctr1",-0.36011, -1.09951,-0.325,crr1);
1275 ctr1->RegisterYourself();
1276  TGeoCompositeShape *cs1 = new TGeoCompositeShape("cs1",
1277 "(((((tub-h1:ttr11)-h1:ttr22)-sp1)-sp2)-h2)+elcon:ctr1");
1278  //
1279  TGeoVolume *csvv = new TGeoVolume("TPC_RR_CU",cs1,m7);
1280  //
1281  // resistor rod assembly 2 ceramic rods, peak rod, Cu plates
1282  // and resistors
1283  //
1284  TGeoVolumeAssembly *rrod = new TGeoVolumeAssembly("TPC_RRIN");
1285  // rods
1286  rrod->AddNode(crv,1,ttr11);
1287  rrod->AddNode(crv,2,ttr22); 
1288  rrod->AddNode(prv,1);
1289  //Cu plates
1290  for(Int_t i=0;i<165;i++){
1291    rrod->AddNode(csvv,i+1,new TGeoTranslation(0.,0.,-122.675+i*1.5));
1292  }
1293  //resistors
1294  TGeoTube *res = new TGeoTube(0.,0.15,0.5);
1295  TGeoVolume *resv = new TGeoVolume("TPC_RES",res,m10);
1296  TGeoVolumeAssembly *ress = new TGeoVolumeAssembly("TPC_RES_CH");
1297  ress->AddNode(resv,1,new TGeoTranslation(0.2,0.,0.));
1298  ress->AddNode(resv,2,new TGeoTranslation(-0.2,0.,0.));
1299  //
1300  TGeoRotation *crr2 = new TGeoRotation();
1301  crr2->RotateY(30.);
1302  TGeoRotation *crr3 = new TGeoRotation();
1303  crr3->RotateY(-30.); 
1304  //
1305  for(Int_t i=0;i<164;i+=2){
1306    rrod->AddNode(ress,i+1, new TGeoCombiTrans(0.,1.2,-121.925+i*1.5,crr2));
1307    rrod->AddNode(ress,i+2, new TGeoCombiTrans(0.,1.2,-121.925+(i+1)*1.5,crr3));
1308  }
1309
1310  tpcrrod->AddNode(rrod,1,new TGeoCombiTrans(0.,0.,0.5,crr1));
1311  //
1312  // guard ring resistor chain
1313  //
1314
1315  TGeoTube *gres1 = new TGeoTube(0.,0.375,125.);// inside ifc
1316  //
1317  TGeoVolume *vgres1 = new TGeoVolume("TPC_GRES1",gres1,m10);
1318
1319  //
1320  Double_t xrc,yrc;
1321  //
1322  xrc=79.3*TMath::Cos(350.*TMath::DegToRad());
1323  yrc=79.3*TMath::Sin(350.*TMath::DegToRad());
1324  //
1325  v9->AddNode(vgres1,1,new TGeoTranslation(xrc,yrc,126.9));
1326  v9->AddNode(vgres1,2,new TGeoTranslation(xrc,yrc,-126.9));
1327  //
1328  xrc=79.3*TMath::Cos(190.*TMath::DegToRad());
1329  yrc=79.3*TMath::Sin(190.*TMath::DegToRad()); 
1330  //
1331  v9->AddNode(vgres1,3,new TGeoTranslation(xrc,yrc,126.9));
1332  v9->AddNode(vgres1,4,new TGeoTranslation(xrc,yrc,-126.9));
1333  //------------------------------------------------------------------
1334  TGeoRotation refl("refl",90.,0.,90.,90.,180.,0.);
1335  TGeoRotation rotrod("rotrod");
1336  //
1337  TGeoRotation *rotpos[2]; 
1338  //
1339  TGeoRotation *rotrod1[2]; 
1340  TGeoTubeSeg *irh = new TGeoTubeSeg(78.825,79.25,1.5,358.5,1.5);
1341  TGeoTubeSeg *orh = new TGeoTubeSeg(256.5,257.95,1.5,359.5,0.5);
1342  TGeoTubeSeg *ohh = new TGeoTubeSeg(256.5,257.95,1.5,9.5,10.5);
1343   TGeoVolume *irhv = new TGeoVolume("TPC_IRHH",irh,m4);
1344   TGeoVolume *orhv = new TGeoVolume("TPC_ORHH",orh,m4);
1345   TGeoVolume *ohhv = new TGeoVolume("TPC_OHVHH",ohh,m4);
1346   
1347  //v9 - drift gas
1348
1349   for(Int_t i=0;i<18;i++){
1350     Double_t angle,x,y;
1351     Double_t z,r; 
1352     angle=TMath::DegToRad()*20.*(Double_t)i;
1353     TGeoRotation *roth = new TGeoRotation(); //rotation for rod holders
1354     roth->RotateZ(angle);
1355     //inner rods
1356     r=81.5;
1357     x=r * TMath::Cos(angle);
1358     y=r * TMath::Sin(angle);
1359     z = 126.1;
1360     //
1361     v9->AddNode(irhv,i+1,roth);
1362     v9->AddNode(orhv,i+1,roth);
1363     v9->AddNode(ohhv,i+1,roth);
1364     //
1365     if(i==11){//resistor rod inner
1366        rotrod.RotateZ(-90.+angle);
1367        rotrod1[0]= new TGeoRotation();
1368        rotpos[0]= new TGeoRotation();
1369        //
1370        rotrod1[0]->RotateZ(-90.+angle);
1371        *rotpos[0] = refl*rotrod; //rotation+reflection
1372         v9->AddNode(tpcrrod,1,new TGeoCombiTrans(x,y, z, rotrod1[0])); //A
1373         v9->AddNode(tpcrrod,2,new TGeoCombiTrans(x,y,-z, rotpos[0])); //C      
1374     } 
1375     else { 
1376       v9->AddNode(tpcmrod,i+1,new TGeoTranslation(x,y,z));//shaft
1377       v9->AddNode(tpcmrod,i+19,new TGeoCombiTrans(x,y,-z,ref));//muon
1378     }
1379     // outer rods
1380     r=254.25;
1381     x=r * TMath::Cos(angle);
1382     y=r * TMath::Sin(angle);
1383     z=126.3;
1384     //
1385     if(i==3){//resistor rod outer
1386       rotrod.RotateZ(90.+angle);
1387       rotrod1[1]= new TGeoRotation();
1388       rotpos[1]= new TGeoRotation();
1389       rotrod1[1]->RotateZ(90.+angle);
1390       *rotpos[1] = refl*rotrod;//rotation+reflection
1391       v9->AddNode(tpcrrod,3,new TGeoCombiTrans(x,y, z, rotrod1[1])); //A 
1392       v9->AddNode(tpcrrod,4,new TGeoCombiTrans(x,y, -z, rotpos[1])); //C
1393     }
1394     else {
1395       v9->AddNode(tpcmrod,i+37,new TGeoTranslation(x,y,z));//shaft
1396       v9->AddNode(tpcmrod,i+55,new TGeoCombiTrans(x,y,-z,ref));//muon      
1397     }
1398     if(i==15){
1399       v9->AddNode(hvrv,1,new TGeoTranslation(x,y,z+0.7)); //hv->A-side only      
1400     }
1401   } //end of rods positioning
1402
1403   TGeoVolume *alice = gGeoManager->GetVolume("ALIC");
1404   alice->AddNode(v1,1);  
1405   
1406 } // end of function
1407  
1408 //_____________________________________________________________________________
1409 void AliTPCv2::AddAlignableVolumes() const
1410 {
1411   //
1412   // Create entries for alignable volumes associating the symbolic volume
1413   // name with the corresponding volume path. Needs to be syncronized with
1414   // eventual changes in the geometry.
1415   // 
1416   SetInnerChambersAlignable();
1417   SetOuterChambersAlignable();
1418 }
1419  
1420 //_____________________________________________________________________________
1421 void AliTPCv2::SetInnerChambersAlignable() const
1422 {
1423   //
1424   AliGeomManager::ELayerID idTPC1 = AliGeomManager::kTPC1;
1425   Int_t modUID, modnum = 0;
1426   TString vpstr1 = "ALIC_1/TPC_M_1/TPC_Drift_1/TPC_ENDCAP_1/TPC_SECT_";
1427   TString vpstr2 = "ALIC_1/TPC_M_1/TPC_Drift_1/TPC_ENDCAP_2/TPC_SECT_";
1428   TString vpappend = "/TPC_IROC_1";
1429   TString snstr1="TPC/EndcapA/Sector";
1430   TString snstr2="TPC/EndcapC/Sector";
1431   TString snappend="/InnerChamber";
1432   TString volpath, symname;
1433   
1434   for(Int_t cnt=1; cnt<=18; cnt++){
1435     modUID = AliGeomManager::LayerToVolUID(idTPC1,modnum++);
1436     volpath = vpstr1;
1437     volpath += cnt;
1438     volpath += vpappend;
1439     symname = snstr1;
1440     symname += cnt;
1441     symname += snappend;
1442     if(!gGeoManager->SetAlignableEntry(symname.Data(),volpath.Data(),modUID))
1443       AliFatal(Form("Alignable entry %s not created. Volume path %s not valid", symname.Data(),volpath.Data()));
1444     TGeoPNEntry *alignableEntry = gGeoManager->GetAlignableEntryByUID(modUID);
1445     TGeoHMatrix* globMatrix = alignableEntry->GetGlobalOrig();
1446     TGeoHMatrix* matTtoL = fTPCParam->Tracking2LocalMatrix(globMatrix,cnt-1);
1447     alignableEntry->SetMatrix(matTtoL);
1448   }
1449
1450   for(Int_t cnt=1; cnt<=18; cnt++){
1451     modUID = AliGeomManager::LayerToVolUID(idTPC1,modnum++);
1452     volpath = vpstr2;
1453     volpath += cnt;
1454     volpath += vpappend;
1455     symname = snstr2;
1456     symname += cnt;
1457     symname += snappend;
1458     if(!gGeoManager->SetAlignableEntry(symname.Data(),volpath.Data(),modUID))
1459       AliFatal(Form("Alignable entry %s not created. Volume path %s not valid", symname.Data(),volpath.Data()));
1460     TGeoPNEntry *alignableEntry = gGeoManager->GetAlignableEntryByUID(modUID);
1461     TGeoHMatrix* globMatrix = alignableEntry->GetGlobalOrig();
1462     TGeoHMatrix* matTtoL = fTPCParam->Tracking2LocalMatrix(globMatrix,18+cnt-1);
1463     alignableEntry->SetMatrix(matTtoL);
1464   }
1465 }
1466
1467 //_____________________________________________________________________________
1468 void AliTPCv2::SetOuterChambersAlignable() const
1469 {
1470   //
1471   AliGeomManager::ELayerID idTPC2 = AliGeomManager::kTPC2;
1472   Int_t modUID, modnum = 0;
1473   TString vpstr1 = "ALIC_1/TPC_M_1/TPC_Drift_1/TPC_ENDCAP_1/TPC_SECT_";
1474   TString vpstr2 = "ALIC_1/TPC_M_1/TPC_Drift_1/TPC_ENDCAP_2/TPC_SECT_";
1475   TString vpappend = "/TPC_OROC_1";
1476   TString snstr1="TPC/EndcapA/Sector";
1477   TString snstr2="TPC/EndcapC/Sector";
1478   TString snappend="/OuterChamber";
1479   TString volpath, symname;
1480   
1481   for(Int_t cnt=1; cnt<=18; cnt++){
1482     modUID = AliGeomManager::LayerToVolUID(idTPC2,modnum++);
1483     volpath = vpstr1;
1484     volpath += cnt;
1485     volpath += vpappend;
1486     symname = snstr1;
1487     symname += cnt;
1488     symname += snappend;
1489     if(!gGeoManager->SetAlignableEntry(symname.Data(),volpath.Data(),modUID))
1490       AliFatal(Form("Alignable entry %s not created. Volume path %s not valid", symname.Data(),volpath.Data()));
1491     TGeoPNEntry *alignableEntry = gGeoManager->GetAlignableEntryByUID(modUID);
1492     TGeoHMatrix* globMatrix = alignableEntry->GetGlobalOrig();
1493     TGeoHMatrix* matTtoL = fTPCParam->Tracking2LocalMatrix(globMatrix,36+cnt-1);
1494     alignableEntry->SetMatrix(matTtoL);
1495   }
1496
1497   for(Int_t cnt=1; cnt<=18; cnt++){
1498     modUID = AliGeomManager::LayerToVolUID(idTPC2,modnum++);
1499     volpath = vpstr2;
1500     volpath += cnt;
1501     volpath += vpappend;
1502     symname = snstr2;
1503     symname += cnt;
1504     symname += snappend;
1505     if(!gGeoManager->SetAlignableEntry(symname.Data(),volpath.Data(),modUID))
1506       AliFatal(Form("Alignable entry %s not created. Volume path %s not valid", symname.Data(),volpath.Data()));
1507     TGeoPNEntry *alignableEntry = gGeoManager->GetAlignableEntryByUID(modUID);
1508     TGeoHMatrix* globMatrix = alignableEntry->GetGlobalOrig();
1509     TGeoHMatrix* matTtoL = fTPCParam->Tracking2LocalMatrix(globMatrix,36+18+cnt-1);
1510     alignableEntry->SetMatrix(matTtoL);
1511   }
1512 }
1513
1514 //_____________________________________________________________________________
1515 void AliTPCv2::DrawDetector() const
1516 {
1517   //
1518   // Draw a shaded view of the Time Projection Chamber version 1
1519   //
1520
1521   // Set everything unseen
1522   gMC->Gsatt("*", "seen", -1);
1523   // 
1524   // Set ALIC mother transparent
1525   gMC->Gsatt("ALIC","SEEN",0);
1526   //
1527   // Set the volumes visible
1528   //
1529
1530   gMC->Gsatt("TPC ","SEEN",0);
1531   gMC->Gsatt("TOIN","SEEN",1);
1532   gMC->Gsatt("TOIN","COLO",7);
1533   gMC->Gsatt("TOCV","SEEN",1);
1534   gMC->Gsatt("TOCV","COLO",4);
1535   gMC->Gsatt("TSA1","SEEN",0);
1536   gMC->Gsatt("TSA2","SEEN",0);
1537   gMC->Gsatt("TSA3","SEEN",0);
1538   gMC->Gsatt("TSA4","SEEN",0);  
1539   gMC->Gsatt("TSA5","SEEN",0);
1540   gMC->Gsatt("TOFC","SEEN",1);
1541   gMC->Gsatt("TOFC","COLO",4);
1542   gMC->Gsatt("TSA6","SEEN",0);
1543   gMC->Gsatt("TSA7","SEEN",0);
1544   gMC->Gsatt("TSA8","SEEN",0);    
1545   gMC->Gsatt("TIIN","SEEN",1);
1546   gMC->Gsatt("TIIN","COLO",7);
1547   gMC->Gsatt("TII1","SEEN",0);
1548   gMC->Gsatt("TIFC","SEEN",1);
1549   gMC->Gsatt("TIFC","COLO",4);
1550   gMC->Gsatt("TSA9","SEEN",0); 
1551   gMC->Gsatt("TS10","SEEN",0);
1552   gMC->Gsatt("TS11","SEEN",0);
1553   gMC->Gsatt("TS12","SEEN",0);
1554   gMC->Gsatt("TS13","SEEN",0);
1555   gMC->Gsatt("TS14","SEEN",0);
1556   gMC->Gsatt("TICC","SEEN",0);
1557   gMC->Gsatt("TICM","SEEN",0);
1558   gMC->Gsatt("TS15","SEEN",0);
1559   gMC->Gsatt("TS16","SEEN",0);
1560   gMC->Gsatt("TS17","SEEN",0);
1561   gMC->Gsatt("TS18","SEEN",0);  
1562   gMC->Gsatt("TS19","SEEN",0); 
1563   gMC->Gsatt("TPJ1","SEEN",0);
1564   gMC->Gsatt("TPJ2","SEEN",0);
1565   gMC->Gsatt("TICS","SEEN",0);
1566   gMC->Gsatt("TDGN","SEEN",0); 
1567   gMC->Gsatt("TIRC","SEEN",0);
1568   gMC->Gsatt("TIC1","SEEN",1);
1569   gMC->Gsatt("TIPP","SEEN",0);
1570   gMC->Gsatt("TIC3","SEEN",0);
1571   gMC->Gsatt("TRCE","SEEN",0);
1572   gMC->Gsatt("TPSC","SEEN",0);
1573   gMC->Gsatt("TPCC","SEEN",0); 
1574   gMC->Gsatt("TORC","SEEN",0);
1575   gMC->Gsatt("TOPP","SEEN",0);
1576   gMC->Gsatt("TOC3","SEEN",0);
1577   gMC->Gsatt("TOC1","SEEN",1);
1578   gMC->Gsatt("TSSW","SEEN",1);
1579   gMC->Gsatt("TSWC","SEEN",1);
1580   gMC->Gsatt("TSSW","COLO",3);
1581   gMC->Gsatt("TSWC","COLO",3);
1582   gMC->Gsatt("TSCE","COLO",6);
1583   gMC->Gsatt("TSCE","SEEN",1);
1584   gMC->Gsatt("TWES","SEEN",0);
1585   gMC->Gsatt("TSWB","SEEN",0);
1586   gMC->Gsatt("TPEL","SEEN",0);
1587   gMC->Gsatt("TPMW","SEEN",1);
1588   gMC->Gsatt("TESR","SEEN",1);
1589   gMC->Gsatt("TPMW","COLO",12);
1590   gMC->Gsatt("TIC1","COLO",5);
1591   gMC->Gsatt("TOC1","COLO",5);
1592   gMC->Gsatt("TESB","SEEN",0);
1593   gMC->Gsatt("THVM","SEEN",1);
1594   gMC->Gsatt("THVM","COLO",11);
1595   gMC->Gsatt("THVH","SEEN",0);
1596   gMC->Gsatt("TPSR","SEEN",0); 
1597   gMC->Gsatt("THVL","SEEN",0);
1598   gMC->Gsatt("THVC","SEEN",0);  
1599   gMC->Gsatt("THVE","SEEN",0);
1600   gMC->Gsatt("THVR","SEEN",0);
1601   gMC->Gsatt("TPSS","SEEN",0);
1602   gMC->Gsatt("TPUS","SEEN",0);
1603   gMC->Gsatt("TPLS","SEEN",0);
1604
1605   //
1606   gMC->Gdopt("hide", "on");
1607   gMC->Gdopt("shad", "on");
1608   gMC->Gsatt("*", "fill", 7);
1609   gMC->SetClipBox(".");
1610   gMC->SetClipBox("TPMW",-300,300,-300,300,254.,270.);
1611   gMC->SetClipBox("TESR",-300,300,-300,300,254.,270.);
1612   gMC->SetClipBox("TSSW",-300,300,-300,300,283.,284.);
1613   gMC->SetClipBox("TSWC",-300,300,-300,300,283.,284.);
1614   gMC->SetClipBox("*", 0, 300, -300, 300, -290, 290);
1615   gMC->DefaultRange();
1616   gMC->Gdraw("alic", 40, 30, 0, 12, 9.5, .025, .025);
1617   gMC->Gdhead(1111, "Time Projection Chamber");
1618   gMC->Gdman(18, 4, "MAN");
1619   gMC->Gdopt("hide","off");
1620 }
1621
1622 //_____________________________________________________________________________
1623 void AliTPCv2::CreateMaterials()
1624 {
1625   //
1626   // Define materials for version 2 of the Time Projection Chamber
1627   //
1628  
1629   AliTPC::CreateMaterials();
1630 }
1631
1632 //_____________________________________________________________________________
1633 void AliTPCv2::Init()
1634 {
1635   //
1636   // Initialises version 2 of the TPC after that it has been built
1637   //
1638
1639   Int_t *idtmed = fIdtmed->GetArray();
1640   
1641   AliTPC::Init();
1642
1643  
1644   fIdSens=gMC->VolId("TPC_Strip");  // one strip is always selected...
1645
1646   fIDrift=gMC->VolId("TPC_Drift");
1647   fSecOld=-100; // fake number 
1648
1649   gMC->SetMaxNStep(-30000); // max. number of steps increased
1650
1651   if (fPrimaryIonisation) {
1652     // for FLUKA
1653       gMC->Gstpar(idtmed[2],"PRIMIO_E", 20.77); // 1st ionisation potential
1654  
1655       gMC->Gstpar(idtmed[2],"PRIMIO_N", 14.35);
1656       gMC->Gstpar(idtmed[2],"LOSS", 14); // specific energy loss
1657       gMC->Gstpar(idtmed[2],"STRA",4);
1658   } 
1659   // specific energy loss for geant3 is now defined in galice.cuts
1660
1661
1662   AliDebug(1,"*** TPC version 2 initialized ***");
1663   AliDebug(1,Form("Maximum number of steps = %d",gMC->GetMaxNStep()));
1664
1665   //
1666   
1667 }
1668
1669 //_____________________________________________________________________________
1670 void AliTPCv2::StepManager()
1671 {
1672   //
1673   // Called for every step in the Time Projection Chamber
1674   //
1675
1676   //
1677   // parameters used for the energy loss calculations
1678   //
1679   const Float_t kprim = 14.35; // number of primary collisions per 1 cm
1680   const Float_t kpoti = 20.77e-9; // first ionization potential for Ne/CO2
1681   const Float_t kwIon = 35.97e-9; // energy for the ion-electron pair creation 
1682   const Int_t   kMaxDistRef =15;     // maximal difference between 2 stored references 
1683  
1684   const Float_t kbig = 1.e10;
1685
1686   Int_t id,copy;
1687   Float_t hits[5];
1688   Int_t vol[2];  
1689   TLorentzVector p;
1690   
1691   vol[1]=0; // preset row number to 0
1692   //
1693   if (!fPrimaryIonisation) gMC->SetMaxStep(kbig);
1694   
1695   if(!gMC->IsTrackAlive()) return; // particle has disappeared
1696   
1697   Float_t charge = gMC->TrackCharge();
1698   
1699   if(TMath::Abs(charge)<=0.) return; // take only charged particles
1700   
1701   // check the sensitive volume
1702
1703   id = gMC->CurrentVolID(copy); // vol ID and copy number (starts from 1!)
1704   if(id != fIDrift && id != fIdSens) return; // not in the sensitive folume 
1705
1706   gMC->TrackPosition(p);
1707   Double_t r = TMath::Sqrt(p[0]*p[0]+p[1]*p[1]);
1708   //
1709   
1710   //
1711   Double_t angle = TMath::ACos(p[0]/r);  
1712   angle = (p[1]<0.) ? TMath::TwoPi()-angle : angle;
1713   //
1714   // angular segment, it is not a real sector number...
1715   //
1716   Int_t sector=TMath::Nint((angle-fTPCParam->GetInnerAngleShift())/
1717                fTPCParam->GetInnerAngle());
1718   // rotate to segment "0"
1719   Float_t cos,sin;
1720   fTPCParam->AdjustCosSin(sector,cos,sin);
1721   Float_t x1=p[0]*cos + p[1]*sin;
1722   // check if within sector's limits
1723   if((x1>=fTPCParam->GetInnerRadiusLow()&&x1<=fTPCParam->GetInnerRadiusUp())
1724      ||(x1>=fTPCParam->GetOuterRadiusLow()&&x1<=fTPCParam->GetOuterRadiusUp())){
1725   // calculate real sector number...
1726   if (x1>fTPCParam->GetOuterRadiusLow()){
1727     sector = TMath::Nint((angle-fTPCParam->GetOuterAngleShift())/
1728              fTPCParam->GetOuterAngle())+fTPCParam->GetNInnerSector();
1729     if (p[2]<0)         sector+=(fTPCParam->GetNOuterSector()>>1);
1730   }
1731     else   
1732       if (p[2]<0) sector+=(fTPCParam->GetNInnerSector()>>1);  
1733   //
1734   // here I have a sector number
1735   //
1736
1737   vol[0]=sector;
1738
1739   static Double_t lastReferenceR=0;
1740   if (TMath::Abs(lastReferenceR-r)>kMaxDistRef){
1741     AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber(), AliTrackReference::kTPC);
1742     lastReferenceR = r;
1743   }
1744
1745   // check if change of sector
1746   if(sector != fSecOld){
1747     fSecOld=sector;
1748     // add track reference
1749     AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber(), AliTrackReference::kTPC);
1750   }  
1751   // track is in the sensitive strip
1752   if(id == fIdSens){
1753     // track is entering the strip
1754     if (gMC->IsTrackEntering()){
1755       Int_t totrows = fTPCParam->GetNRowLow()+fTPCParam->GetNRowUp();
1756       vol[1] = (copy<=totrows) ? copy-1 : copy-1-totrows;
1757       // row numbers are autonomous for lower and upper sectors
1758       if(vol[0] > fTPCParam->GetNInnerSector()) {
1759         vol[1] -= fTPCParam->GetNRowLow();
1760       }
1761     //
1762       if(vol[0]<fTPCParam->GetNInnerSector()&&vol[1] == 0){
1763   
1764         // lower sector, row 0, because Jouri wants to have this
1765
1766         gMC->TrackMomentum(p);
1767         hits[0]=p[0];
1768         hits[1]=p[1];
1769         hits[2]=p[2];
1770         hits[3]=0.; // this hit has no energy loss
1771         // Get also the track time for pileup simulation
1772         hits[4]=gMC->TrackTime();
1773
1774         AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol,hits);  
1775       }
1776     //
1777
1778        gMC->TrackPosition(p);
1779        hits[0]=p[0];
1780        hits[1]=p[1];
1781        hits[2]=p[2];
1782        hits[3]=0.; // this hit has no energy loss
1783        // Get also the track time for pileup simulation
1784        hits[4]=gMC->TrackTime();
1785
1786        AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol,hits);  
1787     
1788     }
1789     else return;
1790   }  
1791   //-----------------------------------------------------------------
1792   //  charged particle is in the sensitive drift volume
1793   //-----------------------------------------------------------------
1794   if(gMC->TrackStep() > 0) {
1795     Int_t nel=0;
1796     if (!fPrimaryIonisation) {
1797       nel = (Int_t)(((gMC->Edep())-kpoti)/kwIon) + 1;
1798     }
1799     else {
1800           Float_t edep = gMC->Edep();
1801           if (edep > 0.) nel = (Int_t)((gMC->Edep()*1.5)/kwIon) + 1;      
1802     }
1803     nel=TMath::Min(nel,300); // 300 electrons corresponds to 10 keV
1804     //
1805     gMC->TrackPosition(p);
1806     hits[0]=p[0];
1807     hits[1]=p[1];
1808     hits[2]=p[2];
1809     hits[3]=(Float_t)nel;
1810
1811     // Add this hit
1812
1813     if (fHitType&&2){
1814       gMC->TrackMomentum(p);
1815       Float_t momentum = TMath::Sqrt(p[0]*p[0]+p[1]*p[1]);
1816       Float_t precision =   (momentum>0.1) ? 0.002 :0.01;
1817       fTrackHits->SetHitPrecision(precision);
1818     }
1819
1820     // Get also the track time for pileup simulation
1821     hits[4]=gMC->TrackTime();
1822  
1823     AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol,hits);
1824     if (fDebugStreamer){   
1825       // You can dump here what you need
1826       // function  CreateDebugStremer() to be called in the Config.C  macro
1827       // if you want to enable it
1828       // By default debug streaemer is OFF
1829       Float_t edep = gMC->Edep();
1830       Float_t tstep = gMC->TrackStep();
1831       Int_t pid=gMC->TrackPid();
1832       (*fDebugStreamer)<<"hit"<<      
1833         "x="<<hits[0]<<  // hit position
1834         "y="<<hits[1]<<
1835         "z="<<hits[2]<<
1836         "nel="<<hits[3]<<  // number of electorns
1837         "tof="<<hits[4]<<  // hit TOF
1838         "edep="<<edep<<    // energy deposit
1839         "pid="<<pid<<      // pid
1840         "step="<<tstep<<
1841         "p.="<<&p<<
1842         "\n";
1843     }
1844     
1845   } // step>0 
1846   } //within sector's limits
1847   // Stemax calculation for the next step
1848   
1849   Float_t pp;
1850   TLorentzVector mom;
1851   // below is valid only for Geant3 (fPromaryIonisation not set)
1852   if(!fPrimaryIonisation){
1853     gMC->TrackMomentum(mom);
1854     Float_t ptot=mom.Rho();
1855     Float_t betaGamma = ptot/gMC->TrackMass();
1856
1857     Int_t pid=gMC->TrackPid();
1858     if((pid==kElectron || pid==kPositron) && ptot > 0.002)
1859       { 
1860         pp = kprim*1.58; // electrons above 20 MeV/c are on the plateau!
1861       }
1862     else
1863       {
1864
1865         betaGamma = TMath::Max(betaGamma,(Float_t)7.e-3); // protection against too small bg
1866         pp=kprim*AliMathBase::BetheBlochAleph(betaGamma); 
1867    
1868     }
1869   
1870     Double_t rnd = gMC->GetRandom()->Rndm();
1871   
1872     gMC->SetMaxStep(-TMath::Log(rnd)/pp);
1873   }
1874   
1875 }
1876
1877