]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/Sim/AliTPCv2.cxx
fix for pid in pr task: sjena
[u/mrichter/AliRoot.git] / TPC / Sim / 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 "TGeoCone.h"
48 #include "TGeoPgon.h"
49 #include "TGeoTrd1.h"
50 #include "TGeoCompositeShape.h"
51 #include "TGeoPara.h"
52 #include "TGeoPhysicalNode.h"
53 #include "TGeoHalfSpace.h"
54 #include "TTreeStream.h"
55 #include "TGeoArb8.h"
56
57 using std::ifstream;
58 using std::ios_base;
59 extern "C"{
60   Gas gaspar_;
61 };
62 ClassImp(AliTPCv2)
63  
64 //_____________________________________________________________________________
65 AliTPCv2::AliTPCv2(const char *name, const char *title) :
66   AliTPC(name, title),
67   fIdSens(0),
68   fIDrift(0),
69   fSecOld(0) 
70 {
71   //
72   // Standard constructor for Time Projection Chamber version 2
73   //
74
75
76   SetBufferSize(128000);
77   if(!fTPCParam) {AliFatal("TPC parameters not set");
78       return;
79   }
80   gaspar_.fpot=fTPCParam->GetFpot();
81   gaspar_.eend=fTPCParam->GetEend();
82   gaspar_.eexpo=fTPCParam->GetExp();
83
84
85 }
86  
87 //_____________________________________________________________________________
88 void AliTPCv2::CreateGeometry()
89 {
90   //
91   // Create the geometry of Time Projection Chamber version 2
92   //
93   //Begin_Html
94   /*
95     <img src="picts/AliTPC.gif">
96   */
97   //End_Html
98   //Begin_Html
99   /*
100     <img src="picts/AliTPCv2Tree.gif">
101   */
102   //End_Html
103
104   //----------------------------------------------------------
105   // This geometry is written using TGeo class
106   // Firstly the shapes are defined, and only then the volumes
107   // What is recognized by the MC are volumes
108   //----------------------------------------------------------
109   //
110   //  tpc - this will be the mother volume
111   //
112
113   //
114   // here I define a volume TPC
115   // retrive the medium name with "TPC_" as a leading string
116   //
117   TGeoPcon *tpc = new TGeoPcon(0.,360.,30); //30 sections
118   //
119   tpc->DefineSection(0,-289.6,77.,278.);
120   tpc->DefineSection(1,-262.1,77.,278.);
121   //
122   tpc->DefineSection(2,-262.1,83.1,278.);
123   tpc->DefineSection(3,-260.,83.1,278.);
124   //
125   tpc->DefineSection(4,-260.,70.,278.);    
126   tpc->DefineSection(5,-259.6,70.,278.);
127   //
128   tpc->DefineSection(6,-259.6,68.1,278.);
129   tpc->DefineSection(7,-253.6,68.1,278.);
130   //
131   tpc->DefineSection(8,-253.6,67.88,278.);//hs
132   tpc->DefineSection(9,-74.0,60.68,278.);// hs
133   //
134   tpc->DefineSection(10,-74.0,60.1,278.);
135   tpc->DefineSection(11,-73.3,60.1,278.);
136   //
137   tpc->DefineSection(12,-73.3,56.9,278.); 
138   tpc->DefineSection(13,-68.5,56.9,278.);
139   //
140   tpc->DefineSection(14,-68.5,60.,278.);
141   tpc->DefineSection(15,-64.7,60.,278.);
142   //
143   tpc->DefineSection(16,-64.7,56.9,278.); 
144   tpc->DefineSection(17,73.3,56.9,278.);
145   //
146   tpc->DefineSection(18,73.3,60.1,278.);
147   tpc->DefineSection(19,74.0,60.1,278.);
148   //
149   tpc->DefineSection(20,74.0,60.68,278.);// hs
150   tpc->DefineSection(21,253.6,65.38,278.);// hs
151   //
152   tpc->DefineSection(22,253.6,65.6,278.);
153   tpc->DefineSection(23,259.6,65.6,278.);
154   //
155   tpc->DefineSection(24,259.6,70.0,278.);
156   tpc->DefineSection(25,260.,70.0,278.);
157   //
158   tpc->DefineSection(26,260.,83.1,278.);
159   tpc->DefineSection(27,262.1,83.1,278.);
160   //
161   tpc->DefineSection(28,262.1,77.,278);
162   tpc->DefineSection(29,289.6,77.,278.);
163   //
164   TGeoMedium *m1 = gGeoManager->GetMedium("TPC_Air");
165   TGeoVolume *v1 = new TGeoVolume("TPC_M",tpc,m1);
166   //
167   // drift volume - sensitive volume, extended beyond the
168   // endcaps, because of the alignment
169   //
170   TGeoPcon *dvol = new TGeoPcon(0.,360.,6);
171   dvol->DefineSection(0,-260.,74.5,264.4);
172   dvol->DefineSection(1,-253.6,74.5,264.4);
173   //
174   dvol->DefineSection(2,-253.6,76.6774,258.);
175   dvol->DefineSection(3,253.6,76.6774,258.); 
176   //
177   dvol->DefineSection(4,253.6,74.5,264.4);
178   dvol->DefineSection(5,260.,74.5,264.4);
179   //
180   TGeoMedium *m5 = gGeoManager->GetMedium("TPC_DriftGas2");
181   TGeoVolume *v9 = new TGeoVolume("TPC_Drift",dvol,m5);
182   //
183   v1->AddNode(v9,1);
184   //
185   // outer insulator
186   //
187   TGeoPcon *tpco = new TGeoPcon(0.,360.,6); //insulator
188   //
189   tpco->DefineSection(0,-256.6,264.8,278.);
190   tpco->DefineSection(1,-253.6,264.8,278.);
191   //
192   tpco->DefineSection(2,-253.6,258.,278.);
193   tpco->DefineSection(3,250.6,258.,278.);
194   //
195   tpco->DefineSection(4,250.6,258.,275.5);
196   tpco->DefineSection(5,253.6,258.,275.5);
197   //
198   TGeoMedium *m2 = gGeoManager->GetMedium("TPC_CO2");
199   TGeoVolume *v2 = new TGeoVolume("TPC_OI",tpco,m2);
200   //
201   TGeoRotation *segrot;//segment rotations
202   //
203   // outer containment vessel
204   //
205   TGeoPcon *tocv = new TGeoPcon(0.,360.,6);  // containment vessel
206   //
207   tocv->DefineSection(0,-256.6,264.8,278.);
208   tocv->DefineSection(1,-253.6,264.8,278.);
209   //
210   tocv->DefineSection(2,-253.6,274.8124,278.);
211   tocv->DefineSection(3,247.6,274.8124,278.);  
212   //
213   tocv->DefineSection(4,247.6,270.4,278.);
214   tocv->DefineSection(5,250.6,270.4,278.);
215   //
216   TGeoMedium *m3 = gGeoManager->GetMedium("TPC_Al");
217   TGeoVolume *v3 = new TGeoVolume("TPC_OCV",tocv,m3); 
218   //
219   TGeoTubeSeg *to1 = new TGeoTubeSeg(274.8174,277.995,252.1,0.,59.9); //epoxy
220   TGeoTubeSeg *to2 = new TGeoTubeSeg(274.8274,277.985,252.1,0.,59.9); //tedlar
221   TGeoTubeSeg *to3 = new TGeoTubeSeg(274.8312,277.9812,252.1,0.,59.9);//prepreg2
222   TGeoTubeSeg *to4 = new TGeoTubeSeg(274.9062,277.9062,252.1,0.,59.9);//nomex
223   TGeoTubeSeg *tog5 = new TGeoTubeSeg(274.8174,277.995,252.1,59.9,60.);//epoxy
224   //
225   TGeoMedium *sm1 = gGeoManager->GetMedium("TPC_Epoxy");
226   TGeoMedium *sm2 = gGeoManager->GetMedium("TPC_Tedlar");
227   TGeoMedium *sm3 = gGeoManager->GetMedium("TPC_Prepreg2");
228   TGeoMedium *sm4 = gGeoManager->GetMedium("TPC_Nomex");
229   //
230   TGeoMedium *smep = gGeoManager->GetMedium("TPC_Epoxy1");
231   //
232   TGeoVolume *tov1 = new TGeoVolume("TPC_OCV1",to1,sm1);
233   TGeoVolume *tov2 = new TGeoVolume("TPC_OCV2",to2,sm2);
234   TGeoVolume *tov3 = new TGeoVolume("TPC_OCV3",to3,sm3);
235   TGeoVolume *tov4 = new TGeoVolume("TPC_OCV4",to4,sm4);
236   TGeoVolume *togv5 = new TGeoVolume("TPC_OCVG5",tog5,sm1);
237   //
238   TGeoMedium *mhs = gGeoManager->GetMedium("TPC_Steel");
239   TGeoMedium *m12 =  gGeoManager->GetMedium("TPC_Water");
240   //-------------------------------------------------------
241   //  Tpc Outer Field Cage
242   //  daughters - composite (sandwich)
243   //-------------------------------------------------------
244
245   TGeoPcon *tofc = new TGeoPcon(0.,360.,6);
246   //
247   tofc->DefineSection(0,-253.6,258.,269.6);
248   tofc->DefineSection(1,-250.6,258.,269.6);
249   //
250   tofc->DefineSection(2,-250.6,258.,260.0676); 
251   tofc->DefineSection(3,250.6,258.,260.0676);
252   //
253   tofc->DefineSection(4,250.6,258.,275.5);
254   tofc->DefineSection(5,253.6,258.,275.5);
255   //
256   TGeoVolume *v4 = new TGeoVolume("TPC_TOFC",tofc,m3); 
257   //sandwich
258   TGeoTubeSeg *tf1 = new TGeoTubeSeg(258.0,260.0676,252.1,0.,59.9); //tedlar
259   TGeoTubeSeg *tf2 = new TGeoTubeSeg(258.0038,260.0638,252.1,0.,59.9); //prepreg3
260   TGeoTubeSeg *tf3 = new TGeoTubeSeg(258.0338,260.0338,252.1,0.,59.9);//nomex
261   TGeoTubeSeg *tfg4 = new TGeoTubeSeg(258.0,260.0676,252.1,59.9,60.); //epoxy glue
262   //
263   TGeoMedium *sm5 = gGeoManager->GetMedium("TPC_Prepreg3");
264   //
265   TGeoVolume *tf1v = new TGeoVolume("TPC_OFC1",tf1,sm2);
266   TGeoVolume *tf2v = new TGeoVolume("TPC_OFC2",tf2,sm5);
267   TGeoVolume *tf3v = new TGeoVolume("TPC_OFC3",tf3,sm4);
268   TGeoVolume *tfg4v = new TGeoVolume("TPC_OFCG4",tfg4,smep);
269   //
270   // outer part - positioning
271   //
272   tov1->AddNode(tov2,1); tov2->AddNode(tov3,1); tov3->AddNode(tov4,1);//ocv
273   //
274   tf1v->AddNode(tf2v,1); tf2v->AddNode(tf3v,1);//ofc
275   //
276   TGeoVolumeAssembly *t200 = new TGeoVolumeAssembly("TPC_OCVSEG");
277   TGeoVolumeAssembly *t300 = new TGeoVolumeAssembly("TPC_OFCSEG");
278   //
279   // assembly OCV and OFC
280   //
281   // 1st - no rotation
282   t200->AddNode(tov1,1); t200->AddNode(togv5,1);
283   t300->AddNode(tf1v,1); t300->AddNode(tfg4v,1);
284   // 2nd - rotation 60 deg
285   segrot = new TGeoRotation();
286   segrot->RotateZ(60.);
287   t200->AddNode(tov1,2,segrot); t200->AddNode(togv5,2,segrot);
288   t300->AddNode(tf1v,2,segrot); t300->AddNode(tfg4v,2,segrot);
289   // 3rd rotation 120 deg
290   segrot = new TGeoRotation();
291   segrot->RotateZ(120.);
292   t200->AddNode(tov1,3,segrot); t200->AddNode(togv5,3,segrot);
293   t300->AddNode(tf1v,3,segrot); t300->AddNode(tfg4v,3,segrot);
294   //4th rotation 180 deg
295   segrot = new TGeoRotation();
296   segrot->RotateZ(180.);
297   t200->AddNode(tov1,4,segrot); t200->AddNode(togv5,4,segrot);
298   t300->AddNode(tf1v,4,segrot); t300->AddNode(tfg4v,4,segrot);
299   //5th rotation 240 deg
300   segrot = new TGeoRotation();
301   segrot->RotateZ(240.);
302   t200->AddNode(tov1,5,segrot); t200->AddNode(togv5,5,segrot);
303   t300->AddNode(tf1v,5,segrot); t300->AddNode(tfg4v,5,segrot);
304   //6th rotation 300 deg
305   segrot = new TGeoRotation();
306   segrot->RotateZ(300.);
307   t200->AddNode(tov1,6,segrot); t200->AddNode(togv5,6,segrot);
308   t300->AddNode(tf1v,6,segrot); t300->AddNode(tfg4v,6,segrot);
309   //
310   v3->AddNode(t200,1,new TGeoTranslation(0.,0.,-1.5)); v4->AddNode(t300,1);
311   //
312   v2->AddNode(v3,1); v2->AddNode(v4,1); 
313   //
314   v1->AddNode(v2,1);
315   //--------------------------------------------------------------------
316   // Tpc Inner INsulator (CO2) 
317   // the cones, the central drum and the inner f.c. sandwich with a piece
318   // of the flane will be placed in the TPC
319   //--------------------------------------------------------------------
320   TGeoPcon *tpci = new TGeoPcon(0.,360.,4);
321   //
322   tpci->DefineSection(0,-253.6,68.4,76.6774);
323   tpci->DefineSection(1,-74.0,61.2,76.6774);
324   //
325   tpci->DefineSection(2,74.0,61.2,76.6774);  
326   //
327   tpci->DefineSection(3,253.6,65.9,76.6774);
328   //
329   TGeoVolume *v5 = new TGeoVolume("TPC_INI",tpci,m2);
330   //
331   // now the inner field cage - only part of flanges (2 copies)
332   //
333   TGeoTube *tif1 = new TGeoTube(69.9,76.6774,1.5); 
334   TGeoVolume *v6 = new TGeoVolume("TPC_IFC1",tif1,m3);
335   //
336  //---------------------------------------------------------
337   // Tpc Inner Containment vessel - Muon side
338   //---------------------------------------------------------
339   TGeoPcon *tcms = new TGeoPcon(0.,360.,10);
340   //
341   tcms->DefineSection(0,-259.1,68.1,74.2);
342   tcms->DefineSection(1,-253.6,68.1,74.2);
343   //
344   tcms->DefineSection(2,-253.6,68.1,68.4);
345   tcms->DefineSection(3,-74.0,60.9,61.2);
346   //
347   tcms->DefineSection(4,-74.0,60.1,61.2);
348   tcms->DefineSection(5,-73.3,60.1,61.2);
349   //
350   tcms->DefineSection(6,-73.3,56.9,61.2);
351   tcms->DefineSection(7,-73.0,56.9,61.2);
352   //
353   tcms->DefineSection(8,-73.0,56.9,58.8);
354   tcms->DefineSection(9,-71.3,56.9,58.8);
355   //
356   TGeoVolume *v7 = new TGeoVolume("TPC_ICVM",tcms,m3);
357   //------------------------------------------------
358   //  Heat screen muon side
359   //------------------------------------------------
360  
361   TGeoCone *thsm = new TGeoCone(89.8,67.88,68.1,60.68,60.9);
362   TGeoCone *thsmw = new TGeoCone(89.8,67.94,68.04,60.74,60.84);
363   TGeoVolume *hvsm = new TGeoVolume("TPC_HSM",thsm,mhs); //steel
364   TGeoVolume *hvsmw = new TGeoVolume("TPC_HSMW",thsmw,m12); //water 
365   // assembly heat screen muon
366   hvsm->AddNode(hvsmw,1);
367   //-----------------------------------------------
368   // inner containment vessel - shaft side
369   //-----------------------------------------------
370   TGeoPcon *tcss = new TGeoPcon(0.,360.,10);
371   //
372   tcss->DefineSection(0,71.3,56.9,58.8);
373   tcss->DefineSection(1,73.0,56.9,58.8);
374   //
375   tcss->DefineSection(2,73.0,56.9,61.2);
376   tcss->DefineSection(3,73.3,56.9,61.2);
377   //  
378   tcss->DefineSection(4,73.3,60.1,61.2);
379   tcss->DefineSection(5,74.0,60.1,61.2);
380   //
381   tcss->DefineSection(6,74.0,60.9,61.2);
382   tcss->DefineSection(7,253.6,65.6,65.9);
383   //
384   tcss->DefineSection(8,253.6,65.6,74.2);
385   tcss->DefineSection(9,258.1,65.6,74.2);
386   //
387   TGeoVolume *v8 = new TGeoVolume("TPC_ICVS",tcss,m3);
388   //-------------------------------------------------
389   //  Heat screen shaft side
390   //--------------------------------------------------
391   TGeoCone *thss = new TGeoCone(89.8,60.68,60.9,65.38,65.6);       
392   TGeoCone *thssw = new TGeoCone(89.8,60.74,60.84,65.44,65.54);     
393   TGeoVolume *hvss = new TGeoVolume("TPC_HSS",thss,mhs); //steel
394   TGeoVolume *hvssw = new TGeoVolume("TPC_HSSW",thssw,m12); //water 
395   //assembly heat screen shaft
396   hvss->AddNode(hvssw,1);
397   //-----------------------------------------------
398   //  Inner field cage
399   //  define 4 parts and make an assembly
400   //-----------------------------------------------
401   // part1 - Al - 2 copies
402   TGeoTube *t1 = new TGeoTube(76.6774,78.845,0.75);
403   TGeoVolume *tv1 = new TGeoVolume("TPC_IFC2",t1,m3);
404   // sandwich - outermost parts - 2 copies
405   //
406   // segment outermost
407   //
408   TGeoTubeSeg *t2 = new TGeoTubeSeg(76.6774,78.845,74.175,350.,109.4); // tedlar 38 microns
409   TGeoTubeSeg *t3 = new TGeoTubeSeg(76.6812,78.8412,74.175,350.,109.4); // prepreg2 500 microns
410   TGeoTubeSeg *t4 = new TGeoTubeSeg(76.7312,78.7912,74.175,350.,109.4); // prepreg3 300 microns
411   TGeoTubeSeg *t5 = new TGeoTubeSeg(76.7612,78.7612,74.175,350.,109.4); // nomex 2 cm
412   TGeoTubeSeg *tepox1 = new TGeoTubeSeg(76.6774,78.845,74.175,109.4,110.);//epoxy
413   TGeoTubeSeg *tpr1 = new TGeoTubeSeg(78.845,78.885,74.175,109.,111.);
414   
415   // volumes for the outer part  
416   TGeoVolume *tv2 = new TGeoVolume("TPC_IFC3",t2,sm2);
417   TGeoVolume *tv3 = new TGeoVolume("TPC_IFC4",t3,sm3);
418   TGeoVolume *tv4 = new TGeoVolume("TPC_IFC5",t4,sm5);
419   TGeoVolume *tv5 = new TGeoVolume("TPC_IFC6",t5,sm4);
420   TGeoVolume *tvep1 = new TGeoVolume("TPC_IFEPOX1",tepox1,smep); 
421   TGeoVolume *tvpr1 = new TGeoVolume("TPC_PRSTR1",tpr1,sm2); 
422   //
423   // middle parts - 2 copies
424   //
425   // segment middle
426   //
427   TGeoTubeSeg *t6 = new TGeoTubeSeg(76.6774,78.795,5.,350.,109.4); // tedlar 38 microns
428   TGeoTubeSeg *t7 = new TGeoTubeSeg(76.6812,78.7912,5.,350.,109.4); // prepreg2 250 microns
429   TGeoTubeSeg *t8 = new TGeoTubeSeg(76.7062,78.7662,5.,350.,109.4); // prepreg3 300 microns
430   TGeoTubeSeg *t9 = new TGeoTubeSeg(76.7362,78.7362,5.,350.,109.4); // nomex 2 cm
431   TGeoTubeSeg *tepox2 = new TGeoTubeSeg(76.6774,78.795,5.,109.4,110.);//epoxy
432   TGeoTubeSeg *tpr2 = new TGeoTubeSeg(78.795,78.835,5.,109.,111.);
433   // volumes for the middle part
434   TGeoVolume *tv6 = new TGeoVolume("TPC_IFC7",t6,sm2);
435   TGeoVolume *tv7 = new TGeoVolume("TPC_IFC8",t7,sm3);
436   TGeoVolume *tv8 = new TGeoVolume("TPC_IFC9",t8,sm5);
437   TGeoVolume *tv9 = new TGeoVolume("TPC_IFC10",t9,sm4);
438   TGeoVolume *tvep2 = new TGeoVolume("TPC_IFEPOX2",tepox2,smep);
439   TGeoVolume *tvpr2 = new TGeoVolume("TPC_PRSTR2",tpr2,sm2);
440   // central part - 1 copy
441   // 
442   // segment central part
443   //
444   TGeoTubeSeg *t10 = new TGeoTubeSeg(76.6774,78.785,93.75,350.,109.4); // tedlar 38 microns 
445   TGeoTubeSeg *t11 = new TGeoTubeSeg(76.6812,78.7812,93.75,350.,109.4); // prepreg3 500 microns
446   TGeoTubeSeg *t12 = new TGeoTubeSeg(76.7312,78.7312,93.75,350.,109.4); // nomex 2 cm 
447   TGeoTubeSeg *tepox3 = new TGeoTubeSeg(76.6774,78.785,93.75,109.4,110.);//epoxy
448   TGeoTubeSeg *tpr3 = new TGeoTubeSeg(78.785,78.825,93.75,109.,111.);
449   // volumes for the central part
450   TGeoVolume *tv10 = new TGeoVolume("TPC_IFC11",t10,sm2);
451   TGeoVolume *tv11 = new TGeoVolume("TPC_IFC12",t11,sm5);
452   TGeoVolume *tv12 = new TGeoVolume("TPC_IFC13",t12,sm4);
453   TGeoVolume *tvep3 = new TGeoVolume("TPC_IFEPOX3",tepox3,smep);
454   TGeoVolume *tvpr3 = new TGeoVolume("TPC_PRSTR3",tpr3,sm2);  
455   //
456   // creating a sandwich for the outer par,t tv2 is the mother
457   //
458   tv2->AddNode(tv3,1); tv3->AddNode(tv4,1); tv4->AddNode(tv5,1);
459   //
460   // creating a sandwich for the middle part, tv6 is the mother
461   //
462   tv6->AddNode(tv7,1); tv7->AddNode(tv8,1); tv8->AddNode(tv9,1);
463   //
464   // creating a sandwich for the central part, tv10 is the mother
465   //
466   tv10->AddNode(tv11,1); tv11->AddNode(tv12,1);
467   //
468   TGeoVolumeAssembly *tv100 = new TGeoVolumeAssembly("TPC_IFC"); // ifc itself - 3 segments
469
470   //
471   // first segment - no rotation
472   //
473   // central
474   tv100->AddNode(tv10,1); //sandwich
475   tv100->AddNode(tvep3,1);//epoxy
476   tv100->AddNode(tvpr3,1);//prepreg strip                                    
477   // middle
478   tv100->AddNode(tv6,1,new TGeoTranslation(0.,0.,-98.75)); //sandwich1
479   tv100->AddNode(tv6,2,new TGeoTranslation(0.,0.,98.75)); // sandwich2
480   tv100->AddNode(tvep2,1,new TGeoTranslation(0.,0.,-98.75)); //epoxy
481   tv100->AddNode(tvep2,2,new TGeoTranslation(0.,0.,98.75)); //epoxy
482   tv100->AddNode(tvpr2,1,new TGeoTranslation(0.,0.,-98.75));//prepreg strip
483   tv100->AddNode(tvpr2,2,new TGeoTranslation(0.,0.,98.75));
484   // outer
485   tv100->AddNode(tv2,1,new TGeoTranslation(0.,0.,-177.925)); //sandwich
486   tv100->AddNode(tv2,2,new TGeoTranslation(0.,0.,177.925));
487   tv100->AddNode(tvep1,1,new TGeoTranslation(0.,0.,-177.925)); //epoxy
488   tv100->AddNode(tvep1,2,new TGeoTranslation(0.,0.,177.925));
489   tv100->AddNode(tvpr1,1,new TGeoTranslation(0.,0.,-177.925));//prepreg strip
490   tv100->AddNode(tvpr1,2,new TGeoTranslation(0.,0.,-177.925));
491   //
492   // second segment - rotation 120 deg.
493   //
494   segrot = new TGeoRotation();
495   segrot->RotateZ(120.);
496   //
497   // central    
498   tv100->AddNode(tv10,2,segrot); //sandwich
499   tv100->AddNode(tvep3,2,segrot);//epoxy
500   tv100->AddNode(tvpr3,2,segrot);//prepreg strip
501   // middle
502   tv100->AddNode(tv6,3,new TGeoCombiTrans(0.,0.,-98.75,segrot)); //sandwich1
503   tv100->AddNode(tv6,4,new TGeoCombiTrans(0.,0.,98.75,segrot)); // sandwich2
504   tv100->AddNode(tvep2,3,new TGeoCombiTrans(0.,0.,-98.75,segrot)); //epoxy
505   tv100->AddNode(tvep2,4,new TGeoCombiTrans(0.,0.,98.75,segrot)); //epoxy
506   tv100->AddNode(tvpr2,3,new TGeoCombiTrans(0.,0.,-98.75,segrot));//prepreg strip
507   tv100->AddNode(tvpr2,4,new TGeoCombiTrans(0.,0.,98.75,segrot));
508   //outer
509   tv100->AddNode(tv2,3,new TGeoCombiTrans(0.,0.,-177.925,segrot));//sandwich
510   tv100->AddNode(tv2,4,new TGeoCombiTrans(0.,0.,177.925,segrot));
511   tv100->AddNode(tvep1,3,new TGeoCombiTrans(0.,0.,-177.925,segrot));//epoxy
512   tv100->AddNode(tvep1,4,new TGeoCombiTrans(0.,0.,177.925,segrot));
513   tv100->AddNode(tvpr1,3,new TGeoCombiTrans(0.,0.,-177.925,segrot));//prepreg strip
514   tv100->AddNode(tvpr1,4,new TGeoCombiTrans(0.,0.,177.925,segrot));
515   //
516   //  third segment - rotation 240 deg.
517   //
518   segrot = new TGeoRotation();
519   segrot->RotateZ(240.);
520   //
521   // central    
522   tv100->AddNode(tv10,3,segrot); //sandwich
523   tv100->AddNode(tvep3,3,segrot);//epoxy
524   tv100->AddNode(tvpr3,3,segrot);//prepreg strip
525   // middle
526   tv100->AddNode(tv6,5,new TGeoCombiTrans(0.,0.,-98.75,segrot)); //sandwich1
527   tv100->AddNode(tv6,6,new TGeoCombiTrans(0.,0.,98.75,segrot)); // sandwich2
528   tv100->AddNode(tvep2,5,new TGeoCombiTrans(0.,0.,-98.75,segrot)); //epoxy
529   tv100->AddNode(tvep2,6,new TGeoCombiTrans(0.,0.,98.75,segrot)); //epoxy
530   tv100->AddNode(tvpr2,5,new TGeoCombiTrans(0.,0.,-98.75,segrot));//prepreg strip
531   tv100->AddNode(tvpr2,6,new TGeoCombiTrans(0.,0.,98.75,segrot));
532   //outer
533   tv100->AddNode(tv2,5,new TGeoCombiTrans(0.,0.,-177.925,segrot));//sandwich
534   tv100->AddNode(tv2,6,new TGeoCombiTrans(0.,0.,177.925,segrot));
535   tv100->AddNode(tvep1,5,new TGeoCombiTrans(0.,0.,-177.925,segrot));//epoxy
536   tv100->AddNode(tvep1,6,new TGeoCombiTrans(0.,0.,177.925,segrot));
537   tv100->AddNode(tvpr1,5,new TGeoCombiTrans(0.,0.,-177.925,segrot));//prepreg strip
538   tv100->AddNode(tvpr1,6,new TGeoCombiTrans(0.,0.,177.925,segrot));
539   // Al parts - rings
540   tv100->AddNode(tv1,1,new TGeoTranslation(0.,0.,-252.85));
541   tv100->AddNode(tv1,2,new TGeoTranslation(0.,0.,252.85));
542   //
543   v5->AddNode(v6,1, new TGeoTranslation(0.,0.,-252.1));
544   v5->AddNode(v6,2, new TGeoTranslation(0.,0.,252.1));
545   v1->AddNode(v5,1); v1->AddNode(v7,1); v1->AddNode(v8,1); 
546   v1->AddNode(hvsm,1,new TGeoTranslation(0.,0.,-163.8)); 
547   v1->AddNode(hvss,1,new TGeoTranslation(0.,0.,163.8)); 
548   v9->AddNode(tv100,1);
549   //
550   // central drum 
551   //
552   // flange + sandwich
553   //
554   TGeoPcon *cfl = new TGeoPcon(0.,360.,6);
555   cfl->DefineSection(0,-71.1,59.7,61.2);
556   cfl->DefineSection(1,-68.6,59.7,61.2);
557   //
558   cfl->DefineSection(2,-68.6,60.6124,61.2);
559   cfl->DefineSection(3,68.6,60.6124,61.2); 
560   //
561   cfl->DefineSection(4,68.6,59.7,61.2);
562   cfl->DefineSection(5,71.1,59.7,61.2);  
563   //
564   TGeoVolume *cflv = new TGeoVolume("TPC_CDR",cfl,m3);
565   // sandwich
566   TGeoTubeSeg *cd1 = new TGeoTubeSeg(60.6224,61.19,71.1,0.2,119.2);
567   TGeoTubeSeg *cd2 = new TGeoTubeSeg(60.6262,61.1862,71.1,0.2,119.2);
568   TGeoTubeSeg *cd3 = new TGeoTubeSeg(60.6462,61.1662,71.1,0.2,119.2);
569   TGeoTubeSeg *cd4 = new TGeoTubeSeg(60.6562,61.1562,71.1,0.2,119.2);
570   TGeoTubeSeg *tepox4 = new TGeoTubeSeg(60.6224,61.19,71.1,359.8,0.8);
571   //
572   TGeoMedium *sm6 = gGeoManager->GetMedium("TPC_Prepreg1");
573   TGeoMedium *sm8 = gGeoManager->GetMedium("TPC_Epoxyfm");
574   TGeoVolume *cd1v = new TGeoVolume("TPC_CDR1",cd1,sm2); //tedlar
575   TGeoVolume *cd2v = new TGeoVolume("TPC_CDR2",cd2,sm6);// prepreg1
576   TGeoVolume *cd3v = new TGeoVolume("TPC_CDR3",cd3,sm8); //epoxy film
577   TGeoVolume *cd4v = new TGeoVolume("TPC_CDR4",cd4,sm4); //nomex
578   TGeoVolume *tvep4 = new TGeoVolume("TPC_IFEPOX4",tepox4,smep);
579
580   //
581   // seals for central drum 2 copies
582   //
583   TGeoTube *cs = new TGeoTube(56.9,61.2,0.1);
584   TGeoMedium *sm7 = gGeoManager->GetMedium("TPC_Mylar");
585   TGeoVolume *csv = new TGeoVolume("TPC_CDRS",cs,sm7);
586   v1->AddNode(csv,1,new TGeoTranslation(0.,0.,-71.2));
587   v1->AddNode(csv,2,new TGeoTranslation(0.,0.,71.2));
588   //
589   // seal collars 
590   TGeoPcon *se = new TGeoPcon(0.,360.,6);
591   se->DefineSection(0,-72.8,59.7,61.2);
592   se->DefineSection(1,-72.3,59.7,61.2);
593   //
594   se->DefineSection(2,-72.3,58.85,61.2);
595   se->DefineSection(3,-71.6,58.85,61.2); 
596   //
597   se->DefineSection(4,-71.6,59.7,61.2);
598   se->DefineSection(5,-71.3,59.7,61.2);  
599   //
600   TGeoVolume *sev = new TGeoVolume("TPC_CDCE",se,m3);
601   //
602   TGeoTube *si = new TGeoTube(56.9,58.8,1.); 
603   TGeoVolume *siv = new TGeoVolume("TPC_CDCI",si,m3);
604   //
605   // define reflection matrix 
606   //
607   TGeoRotation *ref = new TGeoRotation("ref",90.,0.,90.,90.,180.,0.);
608   //
609   cd1v->AddNode(cd2v,1); cd2v->AddNode(cd3v,1); cd3v->AddNode(cd4v,1); //sandwich
610   // first segment  
611   cflv->AddNode(cd1v,1); cflv->AddNode(tvep4,1);
612   // second segment
613   segrot = new TGeoRotation();
614   segrot->RotateZ(120.);
615   cflv->AddNode(cd1v,2,segrot); cflv->AddNode(tvep4,2,segrot);
616   // third segment
617   segrot = new TGeoRotation();
618   segrot->RotateZ(240.);
619   cflv->AddNode(cd1v,3,segrot); cflv->AddNode(tvep4,3,segrot);
620   //
621   v1->AddNode(siv,1,new TGeoTranslation(0.,0.,-69.9));
622   v1->AddNode(siv,2,new TGeoTranslation(0.,0.,69.9));
623   v1->AddNode(sev,1); v1->AddNode(sev,2,ref); v1->AddNode(cflv,1);
624   //
625   // central membrane - 2 rings and a mylar membrane - assembly
626   //
627   TGeoTube *ih = new TGeoTube(81.05,84.05,0.3);
628   TGeoTube *oh = new TGeoTube(250.,256.,0.5);
629   TGeoTube *mem = new TGeoTube(84.05,250.,0.00115);
630
631   //
632   TGeoMedium *m4 = gGeoManager->GetMedium("TPC_G10");
633   //
634   TGeoVolume *ihv = new TGeoVolume("TPC_IHVH",ih,m3);
635   TGeoVolume *ohv = new TGeoVolume("TPC_OHVH",oh,m3);
636   
637   TGeoVolume *memv = new TGeoVolume("TPC_HV",mem,sm7);
638   //
639   TGeoVolumeAssembly *cm = new TGeoVolumeAssembly("TPC_HVMEM");
640   cm->AddNode(ihv,1);
641   cm->AddNode(ohv,1);
642   cm->AddNode(memv,1);
643  
644   v9->AddNode(cm,1);
645   //
646   // end caps - they are make as an assembly of single segments
647   // containing both readout chambers
648   //
649   Double_t openingAngle = 10.*TMath::DegToRad();
650   Double_t thick=1.5; // rib
651   Double_t shift = thick/TMath::Sin(openingAngle);
652   //
653   Double_t lowEdge = 86.3; // hole in the wheel
654   Double_t upEdge = 240.4; // hole in the wheel
655   //
656   new TGeoTubeSeg("sec",74.5,264.4,3.,0.,20.);
657   //
658   TGeoPgon *hole = new TGeoPgon("hole",0.,20.,1,4);
659   //
660   hole->DefineSection(0,-3.5,lowEdge-shift,upEdge-shift);
661   hole->DefineSection(1,-1.5,lowEdge-shift,upEdge-shift);
662   //
663   hole->DefineSection(2,-1.5,lowEdge-shift,upEdge+3.-shift);
664   hole->DefineSection(3,3.5,lowEdge-shift,upEdge+3.-shift);
665   //
666   Double_t ys = shift*TMath::Sin(openingAngle); 
667   Double_t xs = shift*TMath::Cos(openingAngle);
668   TGeoTranslation *tr = new TGeoTranslation("tr",xs,ys,0.);  
669   tr->RegisterYourself();
670   TGeoCompositeShape *chamber = new TGeoCompositeShape("sec-hole:tr");
671   TGeoVolume *sv = new TGeoVolume("TPC_WSEG",chamber,m3);
672   TGeoPgon *bar = new TGeoPgon("bar",0.,20.,1,2);
673   bar->DefineSection(0,-3.,131.5-shift,136.5-shift);
674   bar->DefineSection(1,1.5,131.5-shift,136.5-shift);
675   TGeoVolume *barv = new TGeoVolume("TPC_WBAR",bar,m3);
676   TGeoVolumeAssembly *ch = new TGeoVolumeAssembly("TPC_WCH");//empty segment
677   //
678   ch->AddNode(sv,1); ch->AddNode(barv,1,tr);
679   //
680   // readout chambers
681   //
682   // IROC first
683   //
684    TGeoTrd1 *ibody = new TGeoTrd1(13.8742,21.3328,4.29,21.15);
685    TGeoVolume *ibdv = new TGeoVolume("TPC_IROCB",ibody,m3);
686   // empty space
687    TGeoTrd1 *emp = new TGeoTrd1(12.3742,19.8328,3.99,19.65);
688    TGeoVolume *empv = new TGeoVolume("TPC_IROCE",emp,m1);
689    ibdv->AddNode(empv,1,new TGeoTranslation(0.,-0.3,0.));
690    //bars
691    Double_t tga = (19.8328-12.3742)/39.3;
692    Double_t xmin,xmax;
693    xmin = 9.55*tga+12.3742;
694    xmax = 9.95*tga+12.3742;
695    TGeoTrd1 *ib1 = new TGeoTrd1(xmin,xmax,3.29,0.2);
696    TGeoVolume *ib1v = new TGeoVolume("TPC_IRB1",ib1,m3);
697    empv->AddNode(ib1v,1,new TGeoTranslation("tt1",0.,0.7,-9.9));
698    xmin=19.4*tga+12.3742;
699    xmax=19.9*tga+12.3742;
700    TGeoTrd1 *ib2 = new TGeoTrd1(xmin,xmax,3.29,0.25);
701    TGeoVolume *ib2v = new TGeoVolume("TPC_TRB2",ib2,m3);
702    empv->AddNode(ib2v,1,new TGeoTranslation(0.,0.7,0.));
703    xmin=29.35*tga+12.3742;
704    xmax=29.75*tga+12.3742;
705    TGeoTrd1 *ib3 = new TGeoTrd1(xmin,xmax,3.29,0.2); 
706    TGeoVolume *ib3v = new TGeoVolume("TPC_IRB3",ib3,m3);    
707    empv->AddNode(ib3v,1,new TGeoTranslation(0.,0.7,9.9));
708    //
709    // holes for connectors
710    //
711    TGeoBBox *conn = new TGeoBBox(0.4,0.3,4.675); // identical for iroc and oroc
712    TGeoVolume *connv = new TGeoVolume("TPC_RCCON",conn,m1);
713    TString fileName(gSystem->Getenv("ALICE_ROOT"));
714    fileName += "/TPC/conn_iroc.dat";
715    ifstream in;
716    in.open(fileName.Data(), ios_base::in); // asci file
717    TGeoRotation *rrr[86];
718    for(Int_t i =0;i<86;i++){
719       Double_t y = 3.99;
720       Double_t x,z,ang;
721       in>>x>>z>>ang;
722       z-=26.5;
723       rrr[i]= new TGeoRotation();
724       rrr[i]->RotateY(ang);
725       ibdv->AddNode(connv,i+1,new TGeoCombiTrans(x,y,z,rrr[i]));
726    }
727    in.close();
728    // "cap"
729    new TGeoTrd1("icap",14.5974,23.3521,1.19,24.825);
730    // "hole"
731    new TGeoTrd1("ihole",13.8742,21.3328,1.2,21.15);
732    TGeoTranslation *tr1 = new TGeoTranslation("tr1",0.,0.,1.725);  
733    tr1->RegisterYourself();
734    TGeoCompositeShape *ic = new TGeoCompositeShape("icap-ihole:tr1");
735    TGeoVolume *icv = new TGeoVolume("TPC_IRCAP",ic,m3);
736    //
737    // pad plane and wire fixations
738    //
739    TGeoTrd1 *pp = new TGeoTrd1(14.5974,23.3521,0.3,24.825); //pad+iso
740    TGeoVolume *ppv = new TGeoVolume("TPC_IRPP",pp,m4);
741    TGeoPara *f1 = new TGeoPara(.6,.5,24.825,0.,-10.,0.);
742    TGeoVolume *f1v = new TGeoVolume("TPC_IRF1",f1,m4);
743    TGeoPara *f2 = new TGeoPara(.6,.5,24.825,0.,10.,0.);
744    TGeoVolume *f2v = new TGeoVolume("TPC_IRF2",f2,m4);
745    //
746    TGeoVolumeAssembly *iroc = new TGeoVolumeAssembly("TPC_IROC");
747    //
748    iroc->AddNode(ibdv,1);
749    iroc->AddNode(icv,1,new TGeoTranslation(0.,3.1,-1.725));
750    iroc->AddNode(ppv,1,new TGeoTranslation(0.,4.59,-1.725));
751    tga =(23.3521-14.5974)/49.65; 
752    Double_t xx = 24.825*tga+14.5974-0.6;
753    iroc->AddNode(f1v,1,new TGeoTranslation(-xx,5.39,-1.725));
754    iroc->AddNode(f2v,1,new TGeoTranslation(xx,5.39,-1.725));
755    //
756    // OROC
757    //
758    TGeoTrd1 *obody = new TGeoTrd1(22.2938,40.5084,4.19,51.65);
759    TGeoVolume *obdv = new TGeoVolume("TPC_OROCB",obody,m3);
760    TGeoTrd1 *oemp = new TGeoTrd1(20.2938,38.5084,3.89,49.65);
761    TGeoVolume *oempv = new TGeoVolume("TPC_OROCE",oemp,m1);
762    obdv->AddNode(oempv,1,new TGeoTranslation(0.,-0.3,0.));
763    //horizontal bars
764    tga=(38.5084-20.2938)/99.3;
765    xmin=tga*10.2+20.2938;
766    xmax=tga*10.6+20.2938;
767    TGeoTrd1 *ob1 = new TGeoTrd1(xmin,xmax,2.915,0.2);
768    TGeoVolume *ob1v = new TGeoVolume("TPC_ORB1",ob1,m3);
769    //
770    xmin=22.55*tga+20.2938;
771    xmax=24.15*tga+20.2938;
772    TGeoTrd1 *ob2 = new TGeoTrd1(xmin,xmax,2.915,0.8);
773    TGeoVolume *ob2v = new TGeoVolume("TPC_ORB2",ob2,m3);
774    //
775    xmin=36.1*tga+20.2938;
776    xmax=36.5*tga+20.2938;
777    TGeoTrd1 *ob3 = new TGeoTrd1(xmin,xmax,2.915,0.2);
778    TGeoVolume *ob3v = new TGeoVolume("TPC_ORB3",ob3,m3);
779    //
780    xmin=49.0*tga+20.2938;
781    xmax=50.6*tga+20.2938;   
782    TGeoTrd1 *ob4 = new TGeoTrd1(xmin,xmax,2.915,0.8);
783    TGeoVolume *ob4v = new TGeoVolume("TPC_ORB4",ob4,m3);
784    //
785    xmin=63.6*tga+20.2938;
786    xmax=64.0*tga+20.2938;
787    TGeoTrd1 *ob5 = new TGeoTrd1(xmin,xmax,2.915,0.2);
788    TGeoVolume *ob5v = new TGeoVolume("TPC_ORB5",ob5,m3);
789    //
790    xmin=75.5*tga+20.2938;
791    xmax=77.15*tga+20.2938;
792    TGeoTrd1 *ob6 = new TGeoTrd1(xmin,xmax,2.915,0.8);
793    TGeoVolume *ob6v = new TGeoVolume("TPC_ORB6",ob6,m3);
794    //
795    xmin=88.7*tga+20.2938;
796    xmax=89.1*tga+20.2938;
797    TGeoTrd1 *ob7 = new TGeoTrd1(xmin,xmax,2.915,0.2);
798    TGeoVolume *ob7v = new TGeoVolume("TPC_ORB7",ob7,m3);
799    //
800    oempv->AddNode(ob1v,1,new TGeoTranslation(0.,0.975,-39.25));
801    oempv->AddNode(ob2v,1,new TGeoTranslation(0.,0.975,-26.3));
802    oempv->AddNode(ob3v,1,new TGeoTranslation(0.,0.975,-13.35));
803    oempv->AddNode(ob4v,1,new TGeoTranslation(0.,0.975,0.15));
804    oempv->AddNode(ob5v,1,new TGeoTranslation(0.,0.975,14.15));
805    oempv->AddNode(ob6v,1,new TGeoTranslation(0.,0.975,26.7));
806    oempv->AddNode(ob7v,1,new TGeoTranslation(0.,0.975,39.25));
807    // vertical bars
808    TGeoBBox *ob8 = new TGeoBBox(0.8,2.915,5.1); 
809    TGeoBBox *ob9 = new TGeoBBox(0.8,2.915,5.975);
810    TGeoBBox *ob10 = new TGeoBBox(0.8,2.915,5.775);
811    TGeoBBox *ob11 = new TGeoBBox(0.8,2.915,6.25);
812    TGeoBBox *ob12 = new TGeoBBox(0.8,2.915,6.5);
813    //
814    TGeoVolume *ob8v = new TGeoVolume("TPC_ORB8",ob8,m3);
815    TGeoVolume *ob9v = new TGeoVolume("TPC_ORB9",ob9,m3);
816    TGeoVolume *ob10v = new TGeoVolume("TPC_ORB10",ob10,m3);
817    TGeoVolume *ob11v = new TGeoVolume("TPC_ORB11",ob11,m3);
818    TGeoVolume *ob12v = new TGeoVolume("TPC_ORB12",ob12,m3);
819    //
820    oempv->AddNode(ob8v,1,new TGeoTranslation(0.,0.975,-44.55));
821    oempv->AddNode(ob8v,2,new TGeoTranslation(0.,0.975,44.55));
822    oempv->AddNode(ob9v,1,new TGeoTranslation(0.,0.975,-33.075));
823    oempv->AddNode(ob9v,2,new TGeoTranslation(0.,0.975,-19.525));
824    oempv->AddNode(ob10v,1,new TGeoTranslation(0.,0.975,20.125));
825    oempv->AddNode(ob10v,2,new TGeoTranslation(0.,0.975,33.275));
826    oempv->AddNode(ob11v,1,new TGeoTranslation(0.,0.975,-6.9));
827    oempv->AddNode(ob12v,1,new TGeoTranslation(0.,0.975,7.45));
828    //
829    // holes for connectors
830    //
831    fileName = gSystem->Getenv("ALICE_ROOT");
832    fileName += "/TPC/conn_oroc.dat";
833    in.open(fileName.Data(), ios_base::in); // asci file
834    TGeoRotation *rr[78];
835    for(Int_t i =0;i<78;i++){
836       Double_t y =3.89;
837       Double_t x,z,ang;
838       Double_t x1,z1,x2,z2;
839       in>>x>>z>>ang;        
840       Double_t xr = 4.7*TMath::Sin(ang*TMath::DegToRad());
841       Double_t zr = 4.7*TMath::Cos(ang*TMath::DegToRad());
842       //
843       x1=xr+x; x2=-xr+x; z1=zr+z; z2 = -zr+z;      
844       //
845       rr[i]= new TGeoRotation();
846       rr[i]->RotateY(ang); 
847       z1-=54.95;
848       z2-=54.95;
849       //
850       obdv->AddNode(connv,i+1,new TGeoCombiTrans(x1,y,z1,rr[i]));
851       obdv->AddNode(connv,i+79,new TGeoCombiTrans(x2,y,z2,rr[i]));
852    }
853    in.close();
854    // cap
855    new TGeoTrd1("ocap",23.3874,43.5239,1.09,57.1);
856    new TGeoTrd1("ohole",22.2938,40.5084,1.09,51.65);
857    TGeoTranslation *tr5 = new TGeoTranslation("tr5",0.,0.,-2.15);
858    tr5->RegisterYourself();
859    TGeoCompositeShape *oc = new TGeoCompositeShape("ocap-ohole:tr5");
860    TGeoVolume *ocv = new TGeoVolume("TPC_ORCAP",oc,m3);
861    //
862    // pad plane and wire fixations
863    //
864    TGeoTrd1 *opp = new TGeoTrd1(23.3874,43.5239,0.3,57.1);
865    TGeoVolume *oppv = new TGeoVolume("TPC_ORPP",opp,m4);
866    //
867    tga=(43.5239-23.3874)/114.2;
868    TGeoPara *f3 = new TGeoPara(.7,.6,57.1,0.,-10.,0.);
869    TGeoPara *f4 = new TGeoPara(.7,.6,57.1,0.,10.,0.);  
870    xx = 57.1*tga+23.3874-0.7;
871    TGeoVolume *f3v = new TGeoVolume("TPC_ORF1",f3,m4);
872    TGeoVolume *f4v = new TGeoVolume("TPC_ORF2",f4,m4);
873    //
874    TGeoVolumeAssembly *oroc = new TGeoVolumeAssembly("TPC_OROC");
875    //
876    oroc->AddNode(obdv,1);
877    oroc->AddNode(ocv,1,new TGeoTranslation(0.,3.1,2.15));
878    oroc->AddNode(oppv,1,new TGeoTranslation(0.,4.49,2.15));
879    oroc->AddNode(f3v,1,new TGeoTranslation(-xx,5.39,2.15));
880    oroc->AddNode(f4v,1,new TGeoTranslation(xx,5.39,2.15));
881    // 
882    // now iroc and oroc are placed into a sector...
883    //
884    TGeoVolumeAssembly *secta = new TGeoVolumeAssembly("TPC_SECT"); // a-side
885    TGeoVolumeAssembly *sectc = new TGeoVolumeAssembly("TPC_SECT"); // c-side
886    TGeoRotation rot1("rot1",90.,90.,0.);
887    TGeoRotation rot2("rot2");
888    rot2.RotateY(10.);
889    TGeoRotation *rot = new TGeoRotation("rot");
890    *rot=rot1*rot2;
891    //
892    Double_t x0,y0;
893    x0=110.2*TMath::Cos(openingAngle);
894    y0=110.2*TMath::Sin(openingAngle);
895    TGeoCombiTrans *combi1a = new TGeoCombiTrans("combi1",x0,y0,1.09+0.195,rot); //a-side 
896    TGeoCombiTrans *combi1c = new TGeoCombiTrans("combi1",x0,y0,1.09+0.222,rot); //c-side
897    x0=188.45*TMath::Cos(openingAngle);
898    y0=188.45*TMath::Sin(openingAngle);
899    TGeoCombiTrans *combi2a = new TGeoCombiTrans("combi2",x0,y0,0.99+0.195,rot); //a-side
900    TGeoCombiTrans *combi2c = new TGeoCombiTrans("combi2",x0,y0,0.99+0.222,rot); //c-side
901    //
902    //
903    // A-side
904    //
905    secta->AddNode(ch,1);
906    secta->AddNode(iroc,1,combi1a);
907    secta->AddNode(oroc,1,combi2a);
908    //
909    // C-side
910    //
911    sectc->AddNode(ch,1);
912    sectc->AddNode(iroc,1,combi1c);
913    sectc->AddNode(oroc,1,combi2c);
914    //
915    // now I try to make  wheels...
916    //
917    TGeoVolumeAssembly *wheela = new TGeoVolumeAssembly("TPC_ENDCAP");
918    TGeoVolumeAssembly *wheelc = new TGeoVolumeAssembly("TPC_ENDCAP");
919    //
920    TGeoRotation *rwh[18]; 
921    for(Int_t i =0;i<18;i++){
922      Double_t phi = (20.*i);
923      rwh[i]=new TGeoRotation();
924      rwh[i]->RotateZ(phi);
925      wheela->AddNode(secta,i+1,rwh[i]);
926      wheelc->AddNode(sectc,i+1,rwh[i]); 
927     
928    }
929    // wheels in the drift volume!   
930
931    TGeoCombiTrans *combi3 = new TGeoCombiTrans("combi3",0.,0.,256.6,ref);
932    v9->AddNode(wheela,1,combi3);
933    v9->AddNode(wheelc,2,new TGeoTranslation(0.,0.,-256.6));
934    //_____________________________________________________________
935    // service support wheel
936    //_____________________________________________________________
937   TGeoPgon *sw = new TGeoPgon(0.,20.,1,2);
938   sw->DefineSection(0,-4.,80.5,251.75);
939   sw->DefineSection(1,4.,80.5,251.75); 
940   TGeoVolume *swv = new TGeoVolume("TPC_SWSEG",sw,m3); //Al
941   //
942   thick=1.;
943   shift = thick/TMath::Sin(openingAngle);
944   TGeoPgon *sh = new TGeoPgon(0.,20.,1,2);
945   sh->DefineSection(0,-4.,81.5-shift,250.75-shift);
946   sh->DefineSection(1,4.,81.5-shift,250.75-shift);
947   TGeoVolume *shv = new TGeoVolume("TPC_SWS1",sh,m1); //Air
948   //
949   TGeoMedium *m9 =  gGeoManager->GetMedium("TPC_Si"); 
950   TGeoPgon *el = new TGeoPgon(0.,20.,1,2);
951   el->DefineSection(0,-1.872,81.5-shift,250.75-shift);
952   el->DefineSection(1,1.872,81.5-shift,250.75-shift);
953   TGeoVolume *elv = new TGeoVolume("TPC_ELEC",el,m9); //Si 
954   //
955   shv->AddNode(elv,1);
956   //
957   //
958   ys = shift*TMath::Sin(openingAngle);
959   xs = shift*TMath::Cos(openingAngle);
960   swv->AddNode(shv,1,new TGeoTranslation(xs,ys,0.));
961   // cover
962   TGeoPgon *co = new TGeoPgon(0.,20.,1,2);
963   co->DefineSection(0,-0.5,77.,255.25);
964   co->DefineSection(1,0.5,77.,255.25);
965   TGeoVolume *cov = new TGeoVolume("TPC_SWC1",co,m3);//Al
966   // hole in a cover
967   TGeoPgon *coh = new TGeoPgon(0.,20.,1,2);
968   shift=4./TMath::Sin(openingAngle);
969   coh->DefineSection(0,-0.5,85.-shift,247.25-shift);
970   coh->DefineSection(1,0.5,85.-shift,247.25-shift);  
971   //
972   TGeoVolume *cohv = new TGeoVolume("TPC_SWC2",coh,m1);
973   //
974   ys = shift*TMath::Sin(openingAngle);
975   xs = shift*TMath::Cos(openingAngle);  
976   cov->AddNode(cohv,1,new TGeoTranslation(xs,ys,0.));
977   //
978   // Sector as an Assembly
979   //
980   TGeoVolumeAssembly *swhs = new TGeoVolumeAssembly("TPC_SSWSEC");
981   swhs->AddNode(swv,1);
982   swhs->AddNode(cov,1,new TGeoTranslation(0.,0.,-4.5));
983   swhs->AddNode(cov,2,new TGeoTranslation(0.,0.,4.5));
984   //
985   // SSW as an Assembly of sectors
986   //
987   TGeoRotation *rsw[18];
988   TGeoVolumeAssembly *swheel = new TGeoVolumeAssembly("TPC_SSWHEEL");
989    for(Int_t i =0;i<18;i++){
990      Double_t phi = (20.*i);
991      rsw[i] = new TGeoRotation();
992      rsw[i]->RotateZ(phi);
993      swheel->AddNode(swhs,i+1,rsw[i]);   
994    }
995    v1->AddNode(swheel,1,new TGeoTranslation(0.,0.,-284.6));
996    v1->AddNode(swheel,2,new TGeoTranslation(0.,0.,284.6));
997
998    // sensitive strips - strip "0" is always set
999    // conditional
1000    Int_t totrows;
1001    totrows = fTPCParam->GetNRowLow() + fTPCParam->GetNRowUp();
1002    Double_t *upar;
1003    upar=NULL;
1004    gGeoManager->Volume("TPC_Strip","PGON",m5->GetId(),upar);
1005    upar=new Double_t [10];
1006    upar[0]=0.;
1007    upar[1]=360.;
1008    upar[2]=18.;
1009    upar[3]=2.;
1010    //
1011    upar[4]=-124.8;
1012    upar[7]=124.8;
1013
1014    Double_t rlow=fTPCParam->GetPadRowRadiiLow(0);
1015
1016    upar[5]=rlow;
1017    upar[6]=rlow+.01;
1018    upar[8]=upar[5];
1019    upar[9]=upar[6];
1020    //
1021    gGeoManager->Node("TPC_Strip",1,"TPC_Drift",0.,0.,124.82,0,kTRUE,upar,10);
1022    gGeoManager->Node("TPC_Strip",totrows+1,
1023                      "TPC_Drift",0.,0.,-124.82,0,kTRUE,upar,10);
1024    //
1025    // now, strips optionally
1026    //
1027    if(fSens){
1028      //lower sectors
1029      for(Int_t i=2;i<fTPCParam->GetNRowLow()+1;i++){
1030        rlow=fTPCParam->GetPadRowRadiiLow(i-1);
1031        upar[5]=rlow;
1032        upar[6]=rlow+.01;
1033        upar[8]=upar[5];
1034        upar[9]=upar[6];
1035        gGeoManager->Node("TPC_Strip",i,
1036                          "TPC_Drift",0.,0.,124.82,0,kTRUE,upar,10);
1037        gGeoManager->Node("TPC_Strip",totrows+i,
1038                          "TPC_Drift",0.,0.,-124.82,0,kTRUE,upar,10);       
1039      }
1040      //upper sectors
1041      for(Int_t i=1;i<fTPCParam->GetNRowUp()+1;i++){
1042        rlow=fTPCParam->GetPadRowRadiiUp(i-1); 
1043        upar[5]=rlow;
1044        upar[6]=rlow+.01;
1045        upar[8]=upar[5];
1046        upar[9]=upar[6];
1047        gGeoManager->Node("TPC_Strip",i+fTPCParam->GetNRowLow(),
1048                          "TPC_Drift",0.,0.,124.82,0,kTRUE,upar,10); 
1049        gGeoManager->Node("TPC_Strip",totrows+i+fTPCParam->GetNRowLow(),
1050                          "TPC_Drift",0.,0.,-124.82,0,kTRUE,upar,10); 
1051      }
1052    }//strips
1053   //----------------------------------------------------------
1054   // TPC Support Rods - MAKROLON
1055   //----------------------------------------------------------
1056   TGeoMedium *m6=gGeoManager->GetMedium("TPC_Makrolon");
1057   TGeoMedium *m7=gGeoManager->GetMedium("TPC_Cu");
1058   TGeoMedium *m10 =  gGeoManager->GetMedium("TPC_Alumina");
1059   TGeoMedium *m11 =  gGeoManager->GetMedium("TPC_Peek");;
1060   TGeoMedium *m13 = gGeoManager->GetMedium("TPC_Brass");
1061   TGeoMedium *m14 = gGeoManager->GetMedium("TPC_Alumina1");
1062   // 
1063   // tpc rod is an assembly of 10 long parts and 2 short parts
1064   // connected with alu rings and plagged on both sides.
1065   //
1066   //
1067   // tpc rod long
1068   //
1069   TGeoPcon *rod = new TGeoPcon("rod",0.,360.,6);
1070  rod->DefineSection(0,-10.43,1.92,2.08);
1071  rod->DefineSection(1,-9.75,1.92,2.08);
1072
1073  rod->DefineSection(2,-9.75,1.8,2.2);
1074  rod->DefineSection(3,9.75,1.8,2.2);
1075
1076  rod->DefineSection(4,9.75,1.92,2.08);
1077  rod->DefineSection(5,10.43,1.92,2.08);
1078  //
1079  TGeoVolume *mrodl = new TGeoVolume("TPC_mrodl",rod,m6);
1080  //
1081  // tpc rod short 
1082  //
1083  TGeoPcon *rod1 = new TGeoPcon("rod1",0.,360.,6);
1084  rod1->DefineSection(0,-8.93,1.92,2.08);
1085  rod1->DefineSection(1,-8.25,1.92,2.08);
1086
1087  rod1->DefineSection(2,-8.25,1.8,2.2);
1088  rod1->DefineSection(3,8.25,1.8,2.2);
1089
1090  rod1->DefineSection(4,8.25,1.92,2.08);
1091  rod1->DefineSection(5,8.93,1.92,2.08);
1092  //
1093  TGeoVolume *mrods = new TGeoVolume("TPC_mrods",rod1,m6);
1094  //
1095  // below is for the resistor rod
1096  //
1097  // hole for the brass connectors
1098  //
1099
1100  new TGeoTube("hhole",0.,0.3,0.3);
1101  //
1102  //transformations for holes - initialy they
1103  // are placed at x=0 and negative y
1104  //
1105   TGeoRotation *rhole = new TGeoRotation();
1106   rhole->RotateX(90.);
1107   TGeoCombiTrans *transf[13];
1108   Char_t name[30];
1109   for(Int_t i=0;i<13;i++){
1110     snprintf(name,30,"transf%d",i);
1111     transf[i]= new TGeoCombiTrans(name,0.,-2.,-9.+i*1.5,rhole);
1112     transf[i]->RegisterYourself();
1113   }
1114   // union expression for holes
1115   TString operl("hhole:transf0");
1116   for (Int_t i=1;i<13;i++){
1117     snprintf(name,30,"+hhole:transf%d",i);
1118     operl.Append(name);   
1119   }
1120   //
1121  TString opers("hhole:transf1");
1122   for (Int_t i=2;i<12;i++){
1123     snprintf(name,30,"+hhole:transf%d",i); 
1124     opers.Append(name);   
1125   }
1126   //union of holes
1127   new TGeoCompositeShape("hlv",operl.Data());
1128   new TGeoCompositeShape("hsv",opers.Data());
1129   //
1130   TGeoCompositeShape *rodl = new TGeoCompositeShape("rodl","rod-hlv");
1131   TGeoCompositeShape *rods = new TGeoCompositeShape("rods","rod1-hsv");
1132  //rods - volumes - makrolon rods with holes
1133   TGeoVolume *rodlv = new TGeoVolume("TPC_rodl",rodl,m6);
1134   TGeoVolume *rodsv = new TGeoVolume("TPC_rods",rods,m6);
1135   //brass connectors
1136  //connectors
1137   TGeoTube *bcon = new TGeoTube(0.,0.3,0.3);//connectors
1138   TGeoVolume *bconv = new TGeoVolume("TPC_bcon",bcon,m13);
1139  //
1140  // hooks holding strips
1141  //
1142  new TGeoBBox("hk1",0.625,0.015,0.75);
1143  new TGeoBBox("hk2",0.625,0.015,0.15);
1144  TGeoTranslation *tr21 = new TGeoTranslation("tr21",0.,-0.03,-0.6);
1145  TGeoTranslation *tr12 = new TGeoTranslation("tr12",0.,-0.03,0.6);
1146  tr21->RegisterYourself();
1147  tr12->RegisterYourself();
1148  
1149  TGeoCompositeShape *hook = new TGeoCompositeShape("hook","hk1+hk2:tr21+hk2:tr12");
1150  TGeoVolume *hookv = new TGeoVolume("TPC_hook",hook,m13);
1151  //
1152  // assembly of the short rod with connectors and hooks
1153  //
1154  //
1155  // short rod
1156  //
1157   TGeoVolumeAssembly *spart = new TGeoVolumeAssembly("TPC_spart");
1158   //
1159   spart->AddNode( rodsv,1);
1160   for(Int_t i=1;i<12;i++){
1161   spart->AddNode(bconv,i,transf[i]);
1162   }
1163   for(Int_t i =0;i<11;i++){
1164     spart->AddNode(hookv,i+1,new TGeoTranslation(0.,-2.315,-7.5+i*1.5));
1165   } 
1166  //
1167  // long rod
1168  //
1169   TGeoVolumeAssembly *lpart = new TGeoVolumeAssembly("TPC_lpart");
1170   //
1171   lpart->AddNode( rodlv,1);
1172   for(Int_t i=0;i<13;i++){
1173   lpart->AddNode(bconv,i+12,transf[i]);
1174   }
1175   for(Int_t i =0;i<13;i++){
1176     lpart->AddNode(hookv,i+12,new TGeoTranslation(0.,-2.315,-9.+i*1.5));
1177   }   
1178   //
1179   // alu ring
1180   //
1181   new TGeoTube("ring1",2.1075,2.235,0.53);
1182   new TGeoTube("ring2",1.7925,1.89,0.43);
1183   new TGeoTube("ring3",1.89,2.1075,0.05);
1184   TGeoCompositeShape *ring = new TGeoCompositeShape("ring","ring1+ring2+ring3");
1185   TGeoVolume *ringv = new TGeoVolume("TPC_ring",ring,m3);
1186   //
1187   // rod assembly
1188   //
1189   TGeoVolumeAssembly *tpcrrod = new TGeoVolumeAssembly("TPC_rrod");//rrod
1190   TGeoVolumeAssembly *tpcmrod = new TGeoVolumeAssembly("TPC_mrod");//makrolon rod  
1191   //long pieces
1192   for(Int_t i=0;i<11;i++){
1193     tpcrrod->AddNode(ringv,i+1,new TGeoTranslation(0.,0.,-105.+i*21));
1194     tpcmrod->AddNode(ringv,i+12,new TGeoTranslation(0.,0.,-105.+i*21));
1195   }
1196   for(Int_t i=0;i<10;i++){
1197     tpcrrod->AddNode(lpart,i+1,new TGeoTranslation(0.,0.,-94.5+i*21));//resistor rod
1198     tpcmrod->AddNode(mrodl,i+1,new TGeoTranslation(0.,0.,-94.5+i*21));//makrolon rod        
1199   }
1200   //
1201   // right plug - identical for all rods
1202   //
1203   TGeoPcon *tpcrp = new TGeoPcon(0.,360.,6);
1204   //
1205   tpcrp->DefineSection(0,123.05,1.89,2.1075);
1206   tpcrp->DefineSection(1,123.59,1.89,2.1075);
1207   //
1208   tpcrp->DefineSection(2,123.59,1.8,2.2);
1209   tpcrp->DefineSection(3,127.,1.8,2.2);
1210   //
1211   tpcrp->DefineSection(4,127.,0.,2.2);
1212   tpcrp->DefineSection(5,127.5,0.,2.2);
1213   //
1214   TGeoVolume *tpcrpv = new TGeoVolume("TPC_RP",tpcrp,m6);
1215   //
1216   // adding short pieces and right plug
1217   //
1218   tpcrrod->AddNode(spart,1,new TGeoTranslation(0.,0.,-114.));
1219   tpcrrod->AddNode(spart,2,new TGeoTranslation(0.,0.,114.)); 
1220   tpcrrod->AddNode(ringv,23,new TGeoTranslation(0.,0.,-123.));
1221   tpcrrod->AddNode(ringv,24,new TGeoTranslation(0.,0.,123.));
1222   tpcrrod->AddNode(tpcrpv,1);
1223   //
1224   tpcmrod->AddNode(mrods,1,new TGeoTranslation(0.,0.,-114.));
1225   tpcmrod->AddNode(mrods,2,new TGeoTranslation(0.,0.,114.)); 
1226   tpcmrod->AddNode(ringv,25,new TGeoTranslation(0.,0.,-123.));
1227   tpcmrod->AddNode(ringv,26,new TGeoTranslation(0.,0.,123.));
1228   tpcmrod->AddNode(tpcrpv,2);
1229   //
1230   // from the ringv position to the CM is 3.0 cm!
1231   //----------------------------------------
1232   //
1233   //
1234   //HV rods - makrolon + 0.58cm (diameter) Cu ->check the length
1235   TGeoTube *hvr = new TGeoTube(0.,1.465,123.);
1236   TGeoTube *hvc = new TGeoTube(0.,0.29,123.);
1237   //
1238   TGeoVolume *hvrv = new TGeoVolume("TPC_HV_Rod",hvr,m6);
1239   TGeoVolume *hvcv = new TGeoVolume("TPC_HV_Cable",hvc,m7);
1240   hvrv->AddNode(hvcv,1);
1241   //
1242   //resistor rod
1243   //
1244   TGeoTube *cr = new TGeoTube(0.,0.45,123.);   
1245   TGeoTube *cw = new TGeoTube(0.,0.15,123.);  
1246   TGeoVolume *crv = new TGeoVolume("TPC_CR",cr,m10);
1247   TGeoVolume *cwv = new TGeoVolume("TPC_W",cw,m12);   
1248   //
1249   // ceramic rod with water
1250   //
1251   crv->AddNode(cwv,1);
1252   //
1253   //peek rod
1254   //
1255   TGeoTube *pr =new TGeoTube(0.2,0.35,123.);  
1256   TGeoVolume *prv = new TGeoVolume("TPC_PR",pr,m11); 
1257   //
1258   // copper plates with connectors
1259   //
1260   new TGeoTube("tub",0.,1.7,0.025);
1261   //
1262   // half space - points on the plane and a normal vector
1263   //
1264   Double_t n[3],p[3];
1265   Double_t slope = TMath::Tan(22.*TMath::DegToRad());
1266   Double_t intp = 1.245;
1267   //
1268   Double_t b = slope*slope+1.;
1269   p[0]=intp*slope/b;
1270   p[1]=-intp/b;
1271   p[2]=0.;
1272   //
1273   n[0]=-p[0];
1274   n[1]=-p[1];
1275   n[2]=0.;
1276   Double_t norm;
1277   norm=TMath::Sqrt(n[0]*n[0]+n[1]*n[1]);
1278   n[0] /= norm;
1279   n[1] /=norm;
1280   //
1281   new TGeoHalfSpace("sp1",p,n);
1282   //
1283   slope = -slope; 
1284   //
1285   p[0]=intp*slope/b;
1286   p[1]=-intp/b;
1287   //
1288   n[0]=-p[0];
1289   n[1]=-p[1];
1290   norm=TMath::Sqrt(n[0]*n[0]+n[1]*n[1]);
1291   n[0] /= norm;
1292   n[1] /=norm;
1293   //
1294   new TGeoHalfSpace("sp2",p,n);
1295   // holes for rods
1296  //holes
1297  new TGeoTube("h1",0.,0.5,0.025);
1298  new TGeoTube("h2",0.,0.35,0.025);
1299  //translations:
1300  TGeoTranslation *ttr11 = new TGeoTranslation("ttr11",-0.866,0.5,0.);
1301  TGeoTranslation *ttr22 = new TGeoTranslation("ttr22",0.866,0.5,0.);
1302  ttr11->RegisterYourself();
1303  ttr22->RegisterYourself();
1304  // elastic connector
1305  new TGeoBBox("elcon",0.72,0.005,0.3);
1306  TGeoRotation *crr1 = new TGeoRotation();
1307  crr1->RotateZ(-22.);
1308 TGeoCombiTrans *ctr1 = new TGeoCombiTrans("ctr1",-0.36011, -1.09951,-0.325,crr1);
1309 ctr1->RegisterYourself();
1310  TGeoCompositeShape *cs1 = new TGeoCompositeShape("cs1",
1311 "(((((tub-h1:ttr11)-h1:ttr22)-sp1)-sp2)-h2)+elcon:ctr1");
1312  //
1313  TGeoVolume *csvv = new TGeoVolume("TPC_RR_CU",cs1,m7);
1314  //
1315  // resistor rod assembly 2 ceramic rods, peak rod, Cu plates
1316  // and resistors
1317  //
1318  TGeoVolumeAssembly *rrod = new TGeoVolumeAssembly("TPC_RRIN");
1319  // rods
1320  rrod->AddNode(crv,1,ttr11);
1321  rrod->AddNode(crv,2,ttr22); 
1322  rrod->AddNode(prv,1);
1323  //Cu plates
1324  for(Int_t i=0;i<165;i++){
1325    rrod->AddNode(csvv,i+1,new TGeoTranslation(0.,0.,-122.675+i*1.5));
1326  }
1327  //resistors
1328  TGeoTube *res = new TGeoTube(0.,0.15,0.5);
1329  TGeoVolume *resv = new TGeoVolume("TPC_RES",res,m14);
1330  TGeoVolumeAssembly *ress = new TGeoVolumeAssembly("TPC_RES_CH");
1331  ress->AddNode(resv,1,new TGeoTranslation(0.2,0.,0.));
1332  ress->AddNode(resv,2,new TGeoTranslation(-0.2,0.,0.));
1333  //
1334  TGeoRotation *crr2 = new TGeoRotation();
1335  crr2->RotateY(30.);
1336  TGeoRotation *crr3 = new TGeoRotation();
1337  crr3->RotateY(-30.); 
1338  //
1339  for(Int_t i=0;i<164;i+=2){
1340    rrod->AddNode(ress,i+1, new TGeoCombiTrans(0.,1.2,-121.925+i*1.5,crr2));
1341    rrod->AddNode(ress,i+2, new TGeoCombiTrans(0.,1.2,-121.925+(i+1)*1.5,crr3));
1342  }
1343
1344  tpcrrod->AddNode(rrod,1,new TGeoCombiTrans(0.,0.,0.5,crr1));
1345  //
1346  // rod left head with holders - inner
1347  //
1348  // first element - support for inner holder  TPC_IHS
1349  Double_t shift1[3] = {0.0,-0.175,0.0};
1350
1351 new TGeoBBox("tpcihs1", 4.7, 0.66, 2.35);               
1352 new TGeoBBox("tpcihs2", 4.7, 0.485, 1.0, shift1);
1353 new TGeoBBox("tpcihs3", 1.5, 0.485, 2.35, shift1);
1354 new TGeoTube("tpcihs4", 0.0, 2.38, 0.1);
1355 //
1356 Double_t pointstrap[16];    
1357 pointstrap[0]= 0.0;
1358 pointstrap[1]= 0.0;
1359 pointstrap[2]= 0.0;
1360 pointstrap[3]= 1.08;
1361 pointstrap[4]= 2.3;
1362 pointstrap[5]= 1.08;
1363 pointstrap[6]= 3.38;
1364 pointstrap[7]= 0.0;
1365 pointstrap[8]= 0.0;
1366 pointstrap[9]= 0.0;
1367 pointstrap[10]= 0.0;
1368 pointstrap[11]= 1.08;
1369 pointstrap[12]= 2.3;
1370 pointstrap[13]= 1.08;
1371 pointstrap[14]= 3.38;
1372 pointstrap[15]= 0.0;
1373 //
1374 TGeoArb8 *tpcihs5 = new TGeoArb8("tpcihs5", 0.6, pointstrap);
1375 //
1376 //  half space - cutting "legs"
1377 // 
1378  p[0]=0.0;
1379  p[1]=0.105;
1380  p[2]=0.0;
1381  //       
1382 n[0] = 0.0;
1383 n[1] = 1.0;
1384 n[2] = 0.0;
1385
1386 new TGeoHalfSpace("cutil1", p, n);
1387
1388 //
1389 // transformations
1390 //
1391 TGeoTranslation *trans2 = new TGeoTranslation("trans2", 0.0, 2.84, 2.25);
1392 trans2->RegisterYourself();
1393 TGeoTranslation*trans3= new TGeoTranslation("trans3", 0.0, 2.84, -2.25);
1394 trans3->RegisterYourself();
1395 //support - composite volume
1396 //
1397 TGeoCompositeShape *tpcihs6 = new TGeoCompositeShape("tpcihs6", "tpcihs1-(tpcihs2+tpcihs3)-(tpcihs4:trans2)-(tpcihs4:trans3)-cutil1");
1398 //
1399 // volumes - all makrolon
1400 //  
1401  TGeoVolume *tpcihss = new TGeoVolume("TPC_IHSS", tpcihs6, m6); //support
1402  TGeoVolume *tpcihst = new TGeoVolume("TPC_IHSTR",tpcihs5 , m6); //trapesoid
1403  //now assembly
1404 TGeoRotation *rot111 = new TGeoRotation(); 
1405 rot111->RotateY(180.0);
1406 //
1407 TGeoVolumeAssembly *tpcihs = new TGeoVolumeAssembly("TPC_IHS");    // assembly of the support
1408 tpcihs->AddNode(tpcihss, 1);
1409 tpcihs->AddNode(tpcihst, 1, new TGeoTranslation(-4.7, 0.66, 0.0));
1410 tpcihs->AddNode(tpcihst, 2, new TGeoCombiTrans(4.7, 0.66, 0.0, rot111));
1411 //
1412 // two rod holders (TPC_IRH) assembled with the support
1413 //
1414 new TGeoBBox("tpcirh1", 4.7, 1.33, 0.5);
1415  shift1[0]=-3.65;
1416  shift1[1]=0.53;
1417  shift1[2]=0.;
1418 new TGeoBBox("tpcirh2", 1.05, 0.8, 0.5, shift1);
1419  shift1[0]=3.65;
1420  shift1[1]=0.53;
1421  shift1[2]=0.;
1422 new TGeoBBox("tpcirh3", 1.05, 0.8, 0.5, shift1);
1423  shift1[0]=0.0;
1424  shift1[1]=1.08;
1425  shift1[2]=0.;
1426 new TGeoBBox("tpcirh4", 1.9, 0.25, 0.5, shift1);
1427 new TGeoTube("tpcirh5", 0, 1.9, 5);
1428 //
1429 TGeoTranslation *trans4 = new TGeoTranslation("trans4", 0, 0.83, 0.0); 
1430 trans4->RegisterYourself();
1431 //
1432 TGeoCompositeShape *tpcirh6 = new TGeoCompositeShape("tpcirh6", "tpcirh1-tpcirh2-tpcirh3-(tpcirh5:trans4)-tpcirh4");
1433 //
1434 // now volume
1435 //
1436 TGeoVolume *tpcirh = new TGeoVolume("TPC_IRH", tpcirh6, m6);   
1437 //
1438 // and all together...
1439 //
1440 TGeoVolume *tpciclamp = new TGeoVolumeAssembly("TPC_ICLP");
1441 tpciclamp->AddNode(tpcihs, 1);
1442 tpciclamp->AddNode(tpcirh, 1, new TGeoTranslation(0, 1.99, 1.1));
1443 tpciclamp->AddNode(tpcirh, 2, new TGeoTranslation(0, 1.99, -1.1));
1444 //
1445 // and now left inner "head"
1446 //
1447 TGeoPcon *inplug = new TGeoPcon("inplug", 0.0, 360.0, 14); 
1448
1449 inplug->DefineSection(0, 0.3, 0.0, 2.2);
1450 inplug->DefineSection(1, 0.6, 0.0, 2.2);
1451
1452 inplug->DefineSection(2, 0.6, 0.0, 1.75);
1453 inplug->DefineSection(3, 0.7, 0.0, 1.75);
1454
1455 inplug->DefineSection(4, 0.7, 1.55, 1.75);
1456 inplug->DefineSection(5, 1.6, 1.55, 1.75);
1457
1458 inplug->DefineSection(6, 1.6, 1.55, 2.2);
1459 inplug->DefineSection(7, 1.875, 1.55, 2.2);
1460
1461 inplug->DefineSection(8, 1.875, 1.55, 2.2);
1462 inplug->DefineSection(9, 2.47, 1.75, 2.2);
1463
1464 inplug->DefineSection(10, 2.47, 1.75, 2.08);
1465 inplug->DefineSection(11, 2.57, 1.8, 2.08);
1466
1467 inplug->DefineSection(12, 2.57, 1.92, 2.08);
1468 inplug->DefineSection(13, 2.95, 1.92, 2.08);
1469 //
1470  shift1[0]=0.0;
1471  shift1[1]=-2.09;
1472  shift1[2]=1.075;
1473  //
1474 new TGeoBBox("pcuti", 1.5, 0.11, 1.075, shift1);
1475 //
1476 TGeoCompositeShape *inplleft = new TGeoCompositeShape("inplleft", "inplug-pcuti");
1477 TGeoVolume *tpcinlplug = new TGeoVolume("TPC_INPLL", inplleft, m6);   
1478 //
1479 //  holder + plugs
1480 //
1481  TGeoVolume *tpcihpl = new TGeoVolumeAssembly("TPC_IHPL"); //holder+2 plugs (reflected)
1482  tpcihpl->AddNode(tpcinlplug, 1);
1483  tpcihpl->AddNode(tpcinlplug, 2,ref);
1484  tpcihpl->AddNode(tpciclamp,1,new TGeoTranslation(0.0, -2.765, 0.0)); 
1485  //
1486  // outer holders and clamps
1487  //
1488
1489  // outer membrane holder (between rods)  
1490 pointstrap[0]= 0.0;
1491 pointstrap[1]= 0.0;
1492 pointstrap[2]= 0.0;
1493 pointstrap[3]= 2.8;
1494 pointstrap[4]= 3.1;
1495 pointstrap[5]= 2.8-3.1*TMath::Tan(15.*TMath::DegToRad());
1496 pointstrap[6]= 3.1;
1497 pointstrap[7]= 0.0;
1498 pointstrap[8]= 0.0;
1499 pointstrap[9]= 0.0;
1500 pointstrap[10]= 0.0;
1501 pointstrap[11]= 2.8;
1502 pointstrap[12]= 3.1;
1503 pointstrap[13]= 2.8-3.1*TMath::Tan(15.*TMath::DegToRad());
1504 pointstrap[14]= 3.1;
1505 pointstrap[15]= 0.0;
1506 //
1507 TGeoArb8 *tpcomh1 = new TGeoArb8("tpcomh1", 1.05, pointstrap);   
1508 TGeoBBox *tpcomh2 = new TGeoBBox("tpcomh2", 0.8, 1.4, 6);
1509 //
1510 TGeoVolume *tpcomh1v = new TGeoVolume("TPC_OMH1", tpcomh1, m7);    
1511 TGeoVolume *tpcomh2v = new TGeoVolume("TPC_OMH2", tpcomh2, m7);
1512 //
1513 TGeoVolume *tpcomh3v = new TGeoVolumeAssembly("TPC_OMH3");    // assembly1
1514 tpcomh3v->AddNode(tpcomh1v, 1, new TGeoTranslation(0.8, -1.4, 4.95));
1515  tpcomh3v->AddNode(tpcomh1v, 2, new TGeoTranslation(0.8, -1.4, -4.95));
1516 tpcomh3v->AddNode(tpcomh2v, 1);
1517 //
1518 shift1[0] = 0.9;
1519 shift1[1] = -1.85;
1520 shift1[2] = 0.0;
1521 //
1522 new TGeoBBox("tpcomh3", 1.65, 1.15, 3.4);
1523 TGeoBBox *tpcomh4 = new TGeoBBox("tpcomh4", 0.75, 0.7, 3.4, shift1);
1524 //
1525 // halfspace 1
1526 //
1527 p[0] = 0.0;
1528 p[1] = -1.05;   
1529 p[2] = -3.4;
1530 //
1531 n[0] = 0.0;
1532 n[1] = -1.0*TMath::Tan(30.*TMath::DegToRad());
1533 n[2] = 1.0;
1534 //
1535 new TGeoHalfSpace("cutomh1", p, n); 
1536 //
1537 // halfspace 2
1538 //
1539 p[0] = 0.0;
1540 p[1] = -1.05;   
1541 p[2] = 3.4;
1542 //
1543 n[0] = 0.0;
1544 n[1] = -1.0*TMath::Tan(30.*TMath::DegToRad());
1545 n[2] = -1.0;
1546 //
1547 new TGeoHalfSpace("cutomh2", p, n);
1548 //
1549 // halfspace 3
1550 //
1551 p[0] = -1.65;
1552 p[1] = 0.0;     
1553 p[2] = -0.9;
1554 //
1555 n[0] = 1.0*TMath::Tan(75.*TMath::DegToRad());
1556 n[1] = 0.0;
1557 n[2] = 1.0;
1558 //
1559 new TGeoHalfSpace("cutomh3", p, n);   
1560 //
1561 // halfspace 4
1562 //
1563 p[0] = -1.65;
1564 p[1] = 0.0;      
1565 p[2] = 0.9;
1566 //
1567 n[0] = 1.0*TMath::Tan(75*TMath::DegToRad());
1568 n[1] = 0.0;
1569 n[2] = -1.0;
1570 //
1571 new TGeoHalfSpace("cutomh4", p, n); 
1572 //
1573 // halsfspace 5
1574 //
1575 p[0] = 1.65;
1576 p[1] = -1.05;      
1577 p[2] = 0.0;  
1578 //
1579 n[0] = -1.0;
1580 n[1] = -1.0*TMath::Tan(20.*TMath::DegToRad());
1581 n[2] = 0.0;
1582 //
1583 new TGeoHalfSpace("cutomh5", p, n); 
1584 //  
1585 TGeoCompositeShape *tpcomh5 = new TGeoCompositeShape("tpcomh5", "tpcomh3-cutomh1-cutomh2-cutomh3-cutomh4-cutomh5"); 
1586 //
1587  TGeoVolume *tpcomh5v = new TGeoVolume("TPC_OMH5",tpcomh5,m6);
1588  TGeoVolume *tpcomh4v = new TGeoVolume("TPC_OMH6",tpcomh4,m6);
1589  //
1590  TGeoVolumeAssembly *tpcomh7v = new TGeoVolumeAssembly("TPC_OMH7");
1591  tpcomh7v->AddNode(tpcomh5v,1);
1592  tpcomh7v->AddNode(tpcomh4v,1);
1593  //
1594  // full membrane holder - tpcomh3v + tpcomh7v
1595  //
1596  TGeoVolumeAssembly *tpcomh = new TGeoVolumeAssembly("TPC_OMH");
1597  tpcomh->AddNode(tpcomh3v,1,new TGeoTranslation(1.5,0.,0.));
1598  tpcomh->AddNode(tpcomh3v,2,new TGeoCombiTrans(-1.5,0.,0.,rot111));
1599  tpcomh->AddNode(tpcomh7v,1,new TGeoTranslation(0.65+1.5, 2.55, 0.0));
1600  tpcomh->AddNode(tpcomh7v,2,new TGeoCombiTrans(-0.65-1.5, 2.55, 0.0,rot111)); 
1601  //
1602  //  outer rod holder support
1603  //
1604 new TGeoBBox("tpcohs1", 3.8, 0.675, 2.35); 
1605 //
1606 shift1[0] = 0.0;
1607 shift1[1] = 0.175;
1608 shift1[2] = 0.0;
1609 //
1610 new TGeoBBox("tpcohs2", 1.5, 0.5, 2.35, shift1);
1611 new TGeoBBox("tpcohs3", 3.8, 0.5, 0.85, shift1);
1612 //
1613 shift1[0] = 0.0;
1614 shift1[1] = -1.175;
1615 shift1[2] = 0.0;
1616 //
1617 TGeoBBox *tpcohs4 = new TGeoBBox("tpsohs4", 3.1, 0.5, 0.7, shift1);
1618 //
1619 TGeoVolume *tpcohs4v = new TGeoVolume("TPC_OHS4", tpcohs4, m6);
1620 //
1621 p[0] = 0.0;
1622 p[1] = -0.186;   
1623 p[2] = 0.0;
1624 //
1625 n[0] = 0.0;
1626 n[1] = -1.0;
1627 n[2] = 0.0;
1628 //
1629 new TGeoHalfSpace("cutohs1", p, n);
1630 //
1631 TGeoCompositeShape *tpcohs5 = new TGeoCompositeShape("tpcohs5", "tpcohs1-tpcohs2-tpcohs3-cutohs1"); 
1632 TGeoVolume *tpcohs5v = new TGeoVolume("TPC_OHS5", tpcohs5, m6); 
1633 //
1634 TGeoVolumeAssembly *tpcohs = new TGeoVolumeAssembly("TPC_OHS");    
1635 tpcohs->AddNode(tpcohs5v, 1);
1636 tpcohs->AddNode(tpcohs4v, 1); 
1637 //
1638 // outer rod holder itself
1639 //
1640 shift1[0] = 0.0;
1641 shift1[1] = 1.325;
1642 shift1[2] = 0.0;
1643  new TGeoBBox("tpcorh1", 3.1, 1.825, 0.55); //from this box we cut pieces...
1644  //
1645 shift1[0] = -3.1;       
1646 shift1[1] = -0.5;       
1647 shift1[2] = 0.0;
1648 //
1649 new TGeoBBox("tpcorh2", 0.5, 2.75, 1.1, shift1);
1650 //
1651 shift1[0] = 3.1;        
1652 shift1[1] = -0.5;       
1653 shift1[2] = 0.0;
1654 //
1655 new TGeoBBox("tpcorh3", 0.5, 2.75, 1.1, shift1);
1656 //
1657 shift1[0] = 0.0;
1658 shift1[1] = -0.5;       
1659 shift1[2] = -0.95;
1660 //
1661 new TGeoBBox("tpcorh4", 3.9, 2.75, 0.5, shift1);
1662 //
1663 shift1[0] = 0.0;
1664 shift1[1] = -0.5;
1665 shift1[2] = 0.0;
1666 //
1667 new TGeoBBox("tpcorh5", 1.95, 0.5, 1.1, shift1);
1668 //
1669 shift1[0] = 0.0;
1670 shift1[1] = -0.5;
1671 shift1[2] = 0.55;
1672 //
1673 new TGeoBBox("tpcorh6", 2.4, 0.5, 0.6, shift1);
1674 //
1675 new TGeoTube("tpcorh7", 0, 1.95, 0.85);
1676 new TGeoTube("tpcorh8", 0, 2.4, 0.6);
1677 //
1678 TGeoTranslation *trans33 = new TGeoTranslation("trans33", 0.0, 0.0, 0.55); 
1679 trans33->RegisterYourself();
1680 //
1681 TGeoCompositeShape *tpcorh9 = new TGeoCompositeShape("tpcorh9", "tpcorh1-tpcorh2-tpcorh3-tpcorh4-tpcorh5-tpcorh6-(tpcorh8:trans33)-tpcorh7");
1682 //
1683  TGeoVolume *tpcorh9v = new TGeoVolume("TPC_ORH",tpcorh9,m6); //outer rod holder 
1684  //
1685  // now 2 holders together
1686  //
1687  TGeoVolumeAssembly *tpcorh = new TGeoVolumeAssembly("TPC_ORH2");
1688  //
1689  tpcorh->AddNode(tpcorh9v,1,new TGeoTranslation(0.0, 0.0, 1.25));
1690  tpcorh->AddNode(tpcorh9v,2,new TGeoCombiTrans(0.0, 0.0, -1.25,rot111));
1691 //
1692 // outer rod plug left
1693 //
1694 TGeoPcon *outplug = new TGeoPcon("outplug", 0.0, 360.0, 14); 
1695
1696 outplug->DefineSection(0, 0.5, 0.0, 2.2);
1697 outplug->DefineSection(1, 0.7, 0.0, 2.2);
1698
1699 outplug->DefineSection(2, 0.7, 1.55, 2.2);
1700 outplug->DefineSection(3, 0.8, 1.55, 2.2);
1701
1702 outplug->DefineSection(4, 0.8, 1.55, 1.75);
1703 outplug->DefineSection(5, 1.2, 1.55, 1.75);
1704
1705 outplug->DefineSection(6, 1.2, 1.55, 2.2);
1706 outplug->DefineSection(7, 1.875, 1.55, 2.2);
1707
1708 outplug->DefineSection(8, 1.875, 1.55, 2.2);
1709 outplug->DefineSection(9, 2.47, 1.75, 2.2);
1710
1711 outplug->DefineSection(10, 2.47, 1.75, 2.08);
1712 outplug->DefineSection(11, 2.57, 1.8, 2.08);
1713
1714 outplug->DefineSection(12, 2.57, 1.92, 2.08);
1715 outplug->DefineSection(13, 2.95, 1.92, 2.08);
1716 //
1717 shift1[0] = 0.0;
1718 shift1[1] = 2.09;
1719 shift1[2] = 1.01;
1720
1721 new TGeoBBox("cutout", 2.5, 0.11, 1.01, shift1);
1722 //
1723
1724 TGeoCompositeShape *outplleft = new TGeoCompositeShape("outplleft", "outplug-cutout");    
1725 TGeoVolume *outplleftv = new TGeoVolume("TPC_OPLL", outplleft, m6); 
1726 //
1727 //  support + holder + plug
1728 //
1729
1730  
1731  TGeoVolumeAssembly *tpcohpl = new TGeoVolumeAssembly("TPC_OHPL"); 
1732  //
1733  tpcohpl->AddNode(outplleftv,1); //plug
1734  tpcohpl->AddNode(outplleftv,2,ref); //plug reflected
1735  tpcohpl->AddNode(tpcorh,1); //rod holder
1736  tpcohpl->AddNode(tpcohs,1,new TGeoTranslation(0.0, 3.925, 0)); // support
1737  //
1738
1739  //
1740  // main membrane holder
1741  //           
1742 pointstrap[0]= 0.0;
1743 pointstrap[1]= 0.0;
1744 pointstrap[2]= 0.0;
1745 pointstrap[3]= 2.8;
1746 pointstrap[4]= 3.1;
1747 pointstrap[5]= 1.96;
1748 pointstrap[6]= 3.1;
1749 pointstrap[7]= 0.0;
1750 pointstrap[8]= 0.0;
1751 pointstrap[9]= 0.0;
1752 pointstrap[10]= 0.0;
1753 pointstrap[11]= 2.8;
1754 pointstrap[12]= 3.1;
1755 pointstrap[13]= 1.96;
1756 pointstrap[14]= 3.1;
1757 pointstrap[15]= 0.0; 
1758 //
1759 TGeoArb8 *tpcmmh1 = new TGeoArb8("tpcmmh1", 1.75, pointstrap);
1760 TGeoBBox *tpcmmh2 = new TGeoBBox("tpcmmh2", 0.8, 1.4, 12.5); 
1761 //
1762 TGeoVolume *tpcmmh1v = new TGeoVolume("TPC_MMH1", tpcmmh1, m6);   
1763 TGeoVolume *tpcmmh2v = new TGeoVolume("TPC_MMH2", tpcmmh2, m6);
1764 //
1765  TGeoVolumeAssembly *tpcmmhs = new TGeoVolumeAssembly("TPC_MMHS");
1766  tpcmmhs->AddNode(tpcmmh1v,1,new TGeoTranslation(0.8, -1.4, 10.75));
1767  tpcmmhs->AddNode(tpcmmh1v,2,new TGeoTranslation(0.8, -1.4, -10.75));
1768  tpcmmhs->AddNode(tpcmmh2v,1);
1769  //
1770  // main membrahe holder clamp
1771  //
1772 shift1[0] = -0.75;
1773 shift1[1] = -1.15;
1774 shift1[2] = 0.0;
1775 //
1776 new TGeoBBox("tpcmmhc1", 1.65, 1.85, 8.9); 
1777 new TGeoBBox("tpcmmhc2", 0.9, 0.7, 8.9, shift1);
1778 //
1779 // half spaces  - cuts
1780 //
1781 p[0] = -1.65;
1782 p[1] = 0.0;   
1783 p[2] = -0.9;
1784 //
1785 n[0] = 8.0;
1786 n[1] = 0.0;
1787 n[2] = 8.0*TMath::Tan(13.*TMath::DegToRad());
1788 //
1789 new TGeoHalfSpace("cutmmh1", p, n);
1790 //
1791 p[0] = -1.65;
1792 p[1] = 0.0;   
1793 p[2] = 0.9;
1794 //
1795 n[0] = 8.0;
1796 n[1] = 0.0;
1797 n[2] = -8.0*TMath::Tan(13.*TMath::DegToRad());
1798 //
1799 new TGeoHalfSpace("cutmmh2", p, n);
1800 //
1801 p[0] = 0.0;
1802 p[1] = 1.85;   
1803 p[2] = -2.8;
1804 //
1805 n[0] = 0.0;
1806 n[1] = -6.1;
1807 n[2] = 6.1*TMath::Tan(20.*TMath::DegToRad());
1808 //
1809 new TGeoHalfSpace("cutmmh3", p, n);
1810 //
1811 p[0] = 0.0;
1812 p[1] = 1.85;      
1813 p[2] = 2.8;
1814 //
1815 n[0] = 0.0;
1816 n[1] = -6.1;
1817 n[2] = -6.1*TMath::Tan(20*TMath::DegToRad());
1818 //
1819 new TGeoHalfSpace("cutmmh4", p, n);
1820 //
1821 p[0] = 0.75;
1822 p[1] = 0.0; 
1823 p[2] = -8.9;
1824 //
1825 n[0] = 2.4*TMath::Tan(30*TMath::DegToRad());
1826 n[1] = 0.0;
1827 n[2] = 2.4;
1828 //
1829  new TGeoHalfSpace("cutmmh5", p, n);
1830 //
1831 p[0] = 0.75;
1832 p[1] = 0.0;
1833 p[2] = 8.9;
1834 //
1835 n[0] = 2.4*TMath::Tan(30*TMath::DegToRad());
1836 n[1] = 0.0;
1837 n[2] = -2.4;
1838 //
1839 new TGeoHalfSpace("cutmmh6", p, n);
1840
1841 TGeoCompositeShape *tpcmmhc = new TGeoCompositeShape("TPC_MMHC", "tpcmmhc1-tpcmmhc2-cutmmh1-cutmmh2-cutmmh3-cutmmh4-cutmmh5-cutmmh6"); 
1842
1843  TGeoVolume *tpcmmhcv = new TGeoVolume("TPC_MMHC",tpcmmhc,m6);
1844  //
1845 TGeoVolume *tpcmmh = new TGeoVolumeAssembly("TPC_MMH");
1846 //
1847  tpcmmh->AddNode(tpcmmhcv,1,new TGeoTranslation(0.65+1.5, 1.85, 0.0));
1848  tpcmmh->AddNode(tpcmmhcv,2,new TGeoCombiTrans(-0.65-1.5, 1.85, 0.0,rot111));
1849  tpcmmh->AddNode(tpcmmhs,1,new TGeoTranslation(1.5, 0.0, 0.0));
1850  tpcmmh->AddNode(tpcmmhs,2,new TGeoCombiTrans(-1.5, 0.0, 0.0,rot111));
1851  //
1852  
1853  //
1854
1855 //--------------------------------------------
1856  //
1857  // guard ring resistor chain
1858  //
1859
1860  TGeoTube *gres1 = new TGeoTube(0.,0.375,125.);// inside ifc
1861  //
1862  TGeoVolume *vgres1 = new TGeoVolume("TPC_GRES1",gres1,m14);
1863
1864  //
1865  Double_t xrc,yrc;
1866  //
1867  xrc=79.3*TMath::Cos(350.*TMath::DegToRad());
1868  yrc=79.3*TMath::Sin(350.*TMath::DegToRad());
1869  //
1870  v9->AddNode(vgres1,1,new TGeoTranslation(xrc,yrc,126.9));
1871  v9->AddNode(vgres1,2,new TGeoTranslation(xrc,yrc,-126.9));
1872  //
1873  xrc=79.3*TMath::Cos(190.*TMath::DegToRad());
1874  yrc=79.3*TMath::Sin(190.*TMath::DegToRad()); 
1875  //
1876  v9->AddNode(vgres1,3,new TGeoTranslation(xrc,yrc,126.9));
1877  v9->AddNode(vgres1,4,new TGeoTranslation(xrc,yrc,-126.9));
1878  //------------------------------------------------------------------
1879  TGeoRotation refl("refl",90.,0.,90.,90.,180.,0.);
1880  TGeoRotation rotrod("rotrod");
1881  //
1882  TGeoRotation *rotpos[2]; 
1883  //
1884  TGeoRotation *rotrod1[2]; 
1885  //
1886  // clamps holding rods
1887  //
1888   TGeoBBox *clampi1 = new TGeoBBox("clampi1",0.2,3.1,0.8);
1889   TGeoVolume *clampi1v = new TGeoVolume("TPC_clampi1v",clampi1,m6);
1890  //
1891  pointstrap[0]=0.49;
1892  pointstrap[1]=0.375;
1893  //
1894  pointstrap[2]=0.49;
1895  pointstrap[3]=-0.375;
1896  //
1897  pointstrap[4]=-0.49;
1898  pointstrap[5]=-0.375;
1899  //
1900  pointstrap[6]=-0.49;
1901  pointstrap[7]=1.225;
1902  //
1903  pointstrap[8]=0.49;
1904  pointstrap[9]=0.375;
1905  //
1906  pointstrap[10]=0.49;
1907  pointstrap[11]=-0.375;
1908  //
1909  pointstrap[12]=-0.49;
1910  pointstrap[13]=-0.375;
1911  //
1912  pointstrap[14]=-0.49;
1913  pointstrap[15]=1.225;
1914  //
1915  TGeoArb8 *clitrap = new TGeoArb8("clitrap",0.25,pointstrap);
1916  TGeoVolume *clitrapv = new TGeoVolume("TPC_clitrapv",clitrap,m6);  
1917  //
1918  TGeoRotation *clamprot = new TGeoRotation();
1919  clamprot->RotateX(180.);
1920  //
1921  new TGeoBBox("clibox",1.125,3.1,.1);
1922  new TGeoTube("clitub",0.,2.2,0.1);
1923  //
1924  // copmisite shape for the clamp holder
1925  //
1926  TGeoTranslation *clitr1 = new TGeoTranslation("clitr1",1.125,0.,0.);
1927  clitr1->RegisterYourself();
1928  TGeoCompositeShape *clihold = new TGeoCompositeShape("clihold","clibox-clitub:clitr1"); 
1929  TGeoVolume *cliholdv = new TGeoVolume("TPC_cliholdv",clihold,m6);
1930  //
1931  // now assembly the whole inner clamp
1932  //
1933  TGeoVolume *iclamp = new TGeoVolumeAssembly("TPC_iclamp");
1934  //
1935  iclamp->AddNode(clampi1v,1); //main box
1936  iclamp->AddNode(clitrapv,1,new TGeoTranslation(0.69,-2.725,0.35)); //trapezoids
1937  iclamp->AddNode(clitrapv,2,new TGeoTranslation(0.69,-2.725,-0.35));
1938  iclamp->AddNode(clitrapv,3,new TGeoCombiTrans(0.69,2.725,0.35,clamprot));
1939  iclamp->AddNode(clitrapv,4,new TGeoCombiTrans(0.69,2.725,-0.35,clamprot));
1940  iclamp->AddNode(cliholdv,1,new TGeoTranslation(1.325,0.,0.)); //holder
1941  //
1942  //  outer clamps
1943  //
1944   TGeoBBox *clampo1 = new TGeoBBox("clampo1",0.25,3.1,1.);
1945   TGeoBBox *clampo2 = new TGeoBBox("clampo2",0.4,0.85,1.);
1946   //
1947   TGeoVolume *clampo1v = new TGeoVolume("TPC_clampo1v",clampo1,m6);
1948   TGeoVolume *clampo2v = new TGeoVolume("TPC_clampo2v",clampo2,m6);
1949   //
1950   TGeoVolumeAssembly *oclamp = new TGeoVolumeAssembly("TPC_oclamp");
1951   //
1952   oclamp->AddNode(clampo1v,1);
1953  //
1954  oclamp->AddNode(clampo2v,1,new TGeoTranslation(0.65,-2.25,0));
1955  oclamp->AddNode(clampo2v,2,new TGeoTranslation(0.65,2.25,0));
1956
1957  //
1958  pointstrap[0]=0.375; 
1959  pointstrap[1]=0.75;
1960  pointstrap[2]=0.375;
1961  pointstrap[3]=-0.35;
1962  pointstrap[5]=-0.375;
1963  pointstrap[4]=-0.35;
1964  pointstrap[6]=-0.375; 
1965  pointstrap[7]=0.35;
1966  //
1967  pointstrap[8]=0.375; 
1968  pointstrap[9]=0.75;
1969  pointstrap[10]=0.375;
1970  pointstrap[11]=-0.35;
1971  pointstrap[12]=-0.375;
1972  pointstrap[13]=-0.35;
1973  pointstrap[14]=-0.375; 
1974  pointstrap[15]=0.35;
1975  //
1976  TGeoArb8 *clotrap = new TGeoArb8("clotrap",0.25,pointstrap);
1977  TGeoVolume *clotrapv = new TGeoVolume("TPC_clotrapv",clotrap,m6);
1978  //
1979  oclamp->AddNode(clotrapv,1,new TGeoTranslation(-0.625,-2.75,0.35)); 
1980  oclamp->AddNode(clotrapv,2,new TGeoTranslation(-0.625,-2.75,-0.35));
1981  oclamp->AddNode(clotrapv,3,new TGeoCombiTrans(-0.625,2.75,0.35,clamprot)); 
1982  oclamp->AddNode(clotrapv,4,new TGeoCombiTrans(-0.625,2.75,-0.35,clamprot));  
1983  //
1984  TGeoBBox *clampo3 = new TGeoBBox("clampo3",1.6,0.45,.1);
1985  TGeoVolume *clampo3v = new TGeoVolume("TPC_clampo3v",clampo3,m6); 
1986  //
1987  oclamp->AddNode(clampo3v,1,new TGeoTranslation(-1.85,2.625,0.));
1988  oclamp->AddNode(clampo3v,2,new TGeoTranslation(-1.85,-2.625,0));
1989  //
1990  TGeoTubeSeg *clampo4 = new TGeoTubeSeg("clampo4",2.2,3.1,0.1,90.,270.);
1991  TGeoVolume *clampo4v = new TGeoVolume("TPC_clampo4v",clampo4,m6);
1992  //
1993  oclamp->AddNode(clampo4v,1,new TGeoTranslation(-3.45,0.,0.));
1994
1995
1996
1997  //v9 - drift gas
1998
1999     TGeoRotation rot102("rot102");
2000     rot102.RotateY(-90.);
2001
2002   for(Int_t i=0;i<18;i++){
2003     Double_t angle,x,y;
2004     Double_t z,r; 
2005     angle=TMath::DegToRad()*20.*(Double_t)i;
2006     //inner rods
2007     r=81.5;
2008     x=r * TMath::Cos(angle);
2009     y=r * TMath::Sin(angle);
2010     z = 126.;
2011     TGeoRotation *rot12 = new TGeoRotation();
2012     rot12->RotateZ(-90.0+i*20.);
2013     v9->AddNode(tpcihpl,i+1,new TGeoCombiTrans(x, y, 0., rot12));
2014     //
2015     if(i==11){//resistor rod inner
2016        rotrod.RotateZ(-90.+i*20.);
2017        rotrod1[0]= new TGeoRotation();
2018        rotpos[0]= new TGeoRotation();
2019        //
2020        rotrod1[0]->RotateZ(90.+i*20.);
2021        *rotpos[0] = refl*rotrod; //rotation+reflection
2022         v9->AddNode(tpcrrod,1,new TGeoCombiTrans(x,y, z, rotrod1[0])); //A
2023         v9->AddNode(tpcrrod,2,new TGeoCombiTrans(x,y,-z, rotpos[0])); //C      
2024     } 
2025     else { 
2026       v9->AddNode(tpcmrod,i+1,new TGeoTranslation(x,y,z));//shaft
2027       v9->AddNode(tpcmrod,i+19,new TGeoCombiTrans(x,y,-z,ref));//muon
2028     }
2029     //
2030     // inner clamps positioning
2031     //
2032     r=79.05;
2033     x=r * TMath::Cos(angle);
2034     y=r * TMath::Sin(angle);
2035     rot12= new TGeoRotation();
2036     rot12->RotateZ(i*20.);
2037     //
2038       //A-side
2039       v9->AddNode(iclamp,7*i+1,new TGeoCombiTrans(x,y,5.25,rot12));
2040       v9->AddNode(iclamp,7*i+2,new TGeoCombiTrans(x,y,38.25,rot12));
2041       v9->AddNode(iclamp,7*i+3,new TGeoCombiTrans(x,y,80.25,rot12));
2042       v9->AddNode(iclamp,7*i+4,new TGeoCombiTrans(x,y,122.25,rot12));
2043       v9->AddNode(iclamp,7*i+5,new TGeoCombiTrans(x,y,164.25,rot12));
2044       v9->AddNode(iclamp,7*i+6,new TGeoCombiTrans(x,y,206.25,rot12));
2045       v9->AddNode(iclamp,7*i+7,new TGeoCombiTrans(x,y,246.75,rot12));
2046       //C-side
2047       v9->AddNode(iclamp,7*i+127,new TGeoCombiTrans(x,y,-5.25,rot12));
2048       v9->AddNode(iclamp,7*i+128,new TGeoCombiTrans(x,y,-38.25,rot12));
2049       v9->AddNode(iclamp,7*i+129,new TGeoCombiTrans(x,y,-80.25,rot12));
2050       v9->AddNode(iclamp,7*i+130,new TGeoCombiTrans(x,y,-122.25,rot12));
2051       v9->AddNode(iclamp,7*i+131,new TGeoCombiTrans(x,y,-164.25,rot12));
2052       v9->AddNode(iclamp,7*i+132,new TGeoCombiTrans(x,y,-206.25,rot12));
2053       v9->AddNode(iclamp,7*i+133,new TGeoCombiTrans(x,y,-246.75,rot12));
2054     //
2055     //--------------------------
2056     // outer rods
2057     r=254.25;
2058     x=r * TMath::Cos(angle);
2059     y=r * TMath::Sin(angle);
2060     z=126.;
2061     //
2062     // outer rod holder + outer left plug
2063     //
2064
2065     TGeoRotation *rot33 = new TGeoRotation();
2066     rot33->RotateZ(-90+i*20.);
2067     //
2068     v9->AddNode(tpcohpl,i+1,new TGeoCombiTrans(x, y, 0., rot33));
2069     //
2070     Double_t xxx = 256.297*TMath::Cos((i*20.+10.)*TMath::DegToRad());
2071     Double_t yyy = 256.297*TMath::Sin((i*20.+10.)*TMath::DegToRad());
2072     //
2073     TGeoRotation rot101("rot101");
2074     rot101.RotateZ(90.+i*20.+10.);
2075     TGeoRotation *rot103 = new TGeoRotation("rot103");
2076     *rot103 = rot101*rot102;
2077     //
2078     TGeoCombiTrans *trh100 = new TGeoCombiTrans(xxx,yyy,0.,rot103);
2079     //
2080     if(i==2) {
2081       //main membrane holder
2082       v9->AddNode(tpcmmh,1,trh100);
2083     }
2084     else{
2085       // "normal" membrane holder
2086       v9->AddNode(tpcomh,i+1,trh100);      
2087     }
2088
2089     //
2090     if(i==3){//resistor rod outer
2091       rotrod.RotateZ(90.+i*20.);
2092       rotrod1[1]= new TGeoRotation();
2093       rotpos[1]= new TGeoRotation();
2094       rotrod1[1]->RotateZ(90.+i*20.);
2095       *rotpos[1] = refl*rotrod;//rotation+reflection
2096       v9->AddNode(tpcrrod,3,new TGeoCombiTrans(x,y, z, rotrod1[1])); //A 
2097       v9->AddNode(tpcrrod,4,new TGeoCombiTrans(x,y, -z, rotpos[1])); //C
2098     }
2099     else {
2100       v9->AddNode(tpcmrod,i+37,new TGeoTranslation(x,y,z));//shaft
2101       v9->AddNode(tpcmrod,i+55,new TGeoCombiTrans(x,y,-z,ref));//muon      
2102     }
2103     if(i==15){
2104       v9->AddNode(hvrv,1,new TGeoTranslation(x,y,z+0.7)); //hv->A-side only     
2105     }
2106     //
2107     // outer clamps
2108     //
2109     r=256.9;
2110     x=r * TMath::Cos(angle);
2111     y=r * TMath::Sin(angle);
2112     rot12= new TGeoRotation();
2113     rot12->RotateZ(i*20.);
2114     //
2115       //A-side
2116       v9->AddNode(oclamp,7*i+1,new TGeoCombiTrans(x,y,5.25,rot12));
2117       v9->AddNode(oclamp,7*i+2,new TGeoCombiTrans(x,y,38.25,rot12));
2118       v9->AddNode(oclamp,7*i+3,new TGeoCombiTrans(x,y,80.25,rot12));
2119       v9->AddNode(oclamp,7*i+4,new TGeoCombiTrans(x,y,122.25,rot12));
2120       v9->AddNode(oclamp,7*i+5,new TGeoCombiTrans(x,y,164.25,rot12));
2121       v9->AddNode(oclamp,7*i+6,new TGeoCombiTrans(x,y,206.25,rot12));
2122       v9->AddNode(oclamp,7*i+7,new TGeoCombiTrans(x,y,246.75,rot12));
2123       //C-side
2124       v9->AddNode(oclamp,7*i+127,new TGeoCombiTrans(x,y,-5.25,rot12));
2125       v9->AddNode(oclamp,7*i+128,new TGeoCombiTrans(x,y,-38.25,rot12));
2126       v9->AddNode(oclamp,7*i+129,new TGeoCombiTrans(x,y,-80.25,rot12));
2127       v9->AddNode(oclamp,7*i+130,new TGeoCombiTrans(x,y,-122.25,rot12));
2128       v9->AddNode(oclamp,7*i+131,new TGeoCombiTrans(x,y,-164.25,rot12));
2129       v9->AddNode(oclamp,7*i+132,new TGeoCombiTrans(x,y,-206.25,rot12));
2130       v9->AddNode(oclamp,7*i+133,new TGeoCombiTrans(x,y,-246.75,rot12));
2131     
2132   } //end of rods positioning
2133
2134   TGeoVolume *alice = gGeoManager->GetVolume("ALIC");
2135   alice->AddNode(v1,1);  
2136   
2137 } // end of function
2138  
2139 //_____________________________________________________________________________
2140 void AliTPCv2::AddAlignableVolumes() const
2141 {
2142   //
2143   // Create entries for alignable volumes associating the symbolic volume
2144   // name with the corresponding volume path. Needs to be syncronized with
2145   // eventual changes in the geometry.
2146   // 
2147   SetInnerChambersAlignable();
2148   SetOuterChambersAlignable();
2149 }
2150  
2151 //_____________________________________________________________________________
2152 void AliTPCv2::SetInnerChambersAlignable() const
2153 {
2154   //
2155   AliGeomManager::ELayerID idTPC1 = AliGeomManager::kTPC1;
2156   Int_t modUID, modnum = 0;
2157   TString vpstr1 = "ALIC_1/TPC_M_1/TPC_Drift_1/TPC_ENDCAP_1/TPC_SECT_";
2158   TString vpstr2 = "ALIC_1/TPC_M_1/TPC_Drift_1/TPC_ENDCAP_2/TPC_SECT_";
2159   TString vpappend = "/TPC_IROC_1";
2160   TString snstr1="TPC/EndcapA/Sector";
2161   TString snstr2="TPC/EndcapC/Sector";
2162   TString snappend="/InnerChamber";
2163   TString volpath, symname;
2164   
2165   for(Int_t cnt=1; cnt<=18; cnt++){
2166     modUID = AliGeomManager::LayerToVolUID(idTPC1,modnum++);
2167     volpath = vpstr1;
2168     volpath += cnt;
2169     volpath += vpappend;
2170     symname = snstr1;
2171     symname += cnt;
2172     symname += snappend;
2173     if(!gGeoManager->SetAlignableEntry(symname.Data(),volpath.Data(),modUID))
2174       AliFatal(Form("Alignable entry %s not created. Volume path %s not valid", symname.Data(),volpath.Data()));
2175     TGeoPNEntry *alignableEntry = gGeoManager->GetAlignableEntryByUID(modUID);
2176     TGeoHMatrix* globMatrix = alignableEntry->GetGlobalOrig();
2177     TGeoHMatrix* matTtoL = fTPCParam->Tracking2LocalMatrix(globMatrix,cnt-1);
2178     alignableEntry->SetMatrix(matTtoL);
2179   }
2180
2181   for(Int_t cnt=1; cnt<=18; cnt++){
2182     modUID = AliGeomManager::LayerToVolUID(idTPC1,modnum++);
2183     volpath = vpstr2;
2184     volpath += cnt;
2185     volpath += vpappend;
2186     symname = snstr2;
2187     symname += cnt;
2188     symname += snappend;
2189     if(!gGeoManager->SetAlignableEntry(symname.Data(),volpath.Data(),modUID))
2190       AliFatal(Form("Alignable entry %s not created. Volume path %s not valid", symname.Data(),volpath.Data()));
2191     TGeoPNEntry *alignableEntry = gGeoManager->GetAlignableEntryByUID(modUID);
2192     TGeoHMatrix* globMatrix = alignableEntry->GetGlobalOrig();
2193     TGeoHMatrix* matTtoL = fTPCParam->Tracking2LocalMatrix(globMatrix,18+cnt-1);
2194     alignableEntry->SetMatrix(matTtoL);
2195   }
2196 }
2197
2198 //_____________________________________________________________________________
2199 void AliTPCv2::SetOuterChambersAlignable() const
2200 {
2201   //
2202   AliGeomManager::ELayerID idTPC2 = AliGeomManager::kTPC2;
2203   Int_t modUID, modnum = 0;
2204   TString vpstr1 = "ALIC_1/TPC_M_1/TPC_Drift_1/TPC_ENDCAP_1/TPC_SECT_";
2205   TString vpstr2 = "ALIC_1/TPC_M_1/TPC_Drift_1/TPC_ENDCAP_2/TPC_SECT_";
2206   TString vpappend = "/TPC_OROC_1";
2207   TString snstr1="TPC/EndcapA/Sector";
2208   TString snstr2="TPC/EndcapC/Sector";
2209   TString snappend="/OuterChamber";
2210   TString volpath, symname;
2211   
2212   for(Int_t cnt=1; cnt<=18; cnt++){
2213     modUID = AliGeomManager::LayerToVolUID(idTPC2,modnum++);
2214     volpath = vpstr1;
2215     volpath += cnt;
2216     volpath += vpappend;
2217     symname = snstr1;
2218     symname += cnt;
2219     symname += snappend;
2220     if(!gGeoManager->SetAlignableEntry(symname.Data(),volpath.Data(),modUID))
2221       AliFatal(Form("Alignable entry %s not created. Volume path %s not valid", symname.Data(),volpath.Data()));
2222     TGeoPNEntry *alignableEntry = gGeoManager->GetAlignableEntryByUID(modUID);
2223     TGeoHMatrix* globMatrix = alignableEntry->GetGlobalOrig();
2224     TGeoHMatrix* matTtoL = fTPCParam->Tracking2LocalMatrix(globMatrix,36+cnt-1);
2225     alignableEntry->SetMatrix(matTtoL);
2226   }
2227
2228   for(Int_t cnt=1; cnt<=18; cnt++){
2229     modUID = AliGeomManager::LayerToVolUID(idTPC2,modnum++);
2230     volpath = vpstr2;
2231     volpath += cnt;
2232     volpath += vpappend;
2233     symname = snstr2;
2234     symname += cnt;
2235     symname += snappend;
2236     if(!gGeoManager->SetAlignableEntry(symname.Data(),volpath.Data(),modUID))
2237       AliFatal(Form("Alignable entry %s not created. Volume path %s not valid", symname.Data(),volpath.Data()));
2238     TGeoPNEntry *alignableEntry = gGeoManager->GetAlignableEntryByUID(modUID);
2239     TGeoHMatrix* globMatrix = alignableEntry->GetGlobalOrig();
2240     TGeoHMatrix* matTtoL = fTPCParam->Tracking2LocalMatrix(globMatrix,36+18+cnt-1);
2241     alignableEntry->SetMatrix(matTtoL);
2242   }
2243 }
2244
2245
2246 //_____________________________________________________________________________
2247 void AliTPCv2::CreateMaterials()
2248 {
2249   //
2250   // Define materials for version 2 of the Time Projection Chamber
2251   //
2252  
2253   AliTPC::CreateMaterials();
2254 }
2255
2256 //_____________________________________________________________________________
2257 void AliTPCv2::Init()
2258 {
2259   //
2260   // Initialises version 2 of the TPC after that it has been built
2261   //
2262
2263   Int_t *idtmed = fIdtmed->GetArray();
2264   
2265   AliTPC::Init();
2266
2267  
2268   fIdSens=TVirtualMC::GetMC()->VolId("TPC_Strip");  // one strip is always selected...
2269
2270   fIDrift=TVirtualMC::GetMC()->VolId("TPC_Drift");
2271   fSecOld=-100; // fake number 
2272
2273   TVirtualMC::GetMC()->SetMaxNStep(-120000); // max. number of steps increased
2274
2275   if (fPrimaryIonisation) {
2276     // for FLUKA
2277       TVirtualMC::GetMC()->Gstpar(idtmed[2],"PRIMIO_E", 20.77); // 1st ionisation potential
2278  
2279       TVirtualMC::GetMC()->Gstpar(idtmed[2],"PRIMIO_N", 14.35);
2280       TVirtualMC::GetMC()->Gstpar(idtmed[2],"LOSS", 14); // specific energy loss
2281       TVirtualMC::GetMC()->Gstpar(idtmed[2],"STRA",4);
2282   } 
2283   // specific energy loss for geant3 is now defined in galice.cuts
2284
2285
2286   AliDebug(1,"*** TPC version 2 initialized ***");
2287   AliDebug(1,Form("Maximum number of steps = %d",TVirtualMC::GetMC()->GetMaxNStep()));
2288
2289   //
2290   
2291 }
2292
2293 //_____________________________________________________________________________
2294 void AliTPCv2::StepManager()
2295 {
2296   //
2297   // Called for every step in the Time Projection Chamber
2298   //
2299
2300   //
2301   // parameters used for the energy loss calculations
2302   //
2303   //const Float_t kprim = 14.35; // number of primary collisions per 1 cm
2304   //const Float_t kpoti = 20.77e-9; // first ionization potential for Ne/CO2
2305   //const Float_t kwIon = 35.97e-9; // energy for the ion-electron pair creation 
2306   const Float_t kScalewIonG4 = 0.85; // scale factor to tune kwIon for Geant4 
2307   const Float_t kFanoFactorG4 = 0.7; // parameter for smearing the number of ionizations (nel) using Geant4
2308   const Int_t   kMaxDistRef =15;     // maximal difference between 2 stored references 
2309   Float_t prim = fTPCParam->GetNprim();
2310   Float_t poti = fTPCParam->GetFpot();
2311   Float_t wIon = fTPCParam->GetWmean();
2312  
2313   const Float_t kbig = 1.e10;
2314
2315   Int_t id,copy;
2316   Float_t hits[5];
2317   Int_t vol[2];  
2318   TLorentzVector p;
2319   
2320   vol[1]=0; // preset row number to 0
2321   //
2322   if (!fPrimaryIonisation) TVirtualMC::GetMC()->SetMaxStep(kbig);
2323   
2324   if(!TVirtualMC::GetMC()->IsTrackAlive()) return; // particle has disappeared
2325   
2326   Float_t charge = TVirtualMC::GetMC()->TrackCharge();
2327   
2328   if(TMath::Abs(charge)<=0.) return; // take only charged particles
2329   
2330   // check the sensitive volume
2331
2332   id = TVirtualMC::GetMC()->CurrentVolID(copy); // vol ID and copy number (starts from 1!)
2333   if(id != fIDrift && id != fIdSens) return; // not in the sensitive folume 
2334
2335   if ( fPrimaryIonisation && id == fIDrift ) {
2336     Double_t rnd = TVirtualMC::GetMC()->GetRandom()->Rndm();
2337     TVirtualMC::GetMC()->SetMaxStep(0.2+(2.*rnd-1.)*0.05);  // 2 mm +- rndm*0.5mm step
2338   }   
2339
2340   //if ( fPrimaryIonisation && id == fIDrift && TVirtualMC::GetMC()->IsTrackEntering()) {
2341   //  TVirtualMC::GetMC()->SetMaxStep(0.2);  // 2 mm 
2342   //}   
2343   
2344   TVirtualMC::GetMC()->TrackPosition(p);
2345   Double_t r = TMath::Sqrt(p[0]*p[0]+p[1]*p[1]);
2346   //
2347   
2348   //
2349   Double_t angle = TMath::ACos(p[0]/r);  
2350   angle = (p[1]<0.) ? TMath::TwoPi()-angle : angle;
2351   //
2352   // angular segment, it is not a real sector number...
2353   //
2354   Int_t sector=TMath::Nint((angle-fTPCParam->GetInnerAngleShift())/
2355                fTPCParam->GetInnerAngle());
2356   // rotate to segment "0"
2357   Float_t cos,sin;
2358   fTPCParam->AdjustCosSin(sector,cos,sin);
2359   Float_t x1=p[0]*cos + p[1]*sin;
2360   // check if within sector's limits
2361   if((x1>=fTPCParam->GetInnerRadiusLow()&&x1<=fTPCParam->GetInnerRadiusUp())
2362      ||(x1>=fTPCParam->GetOuterRadiusLow()&&x1<=fTPCParam->GetOuterRadiusUp())){
2363   // calculate real sector number...
2364   if (x1>fTPCParam->GetOuterRadiusLow()){
2365     sector = TMath::Nint((angle-fTPCParam->GetOuterAngleShift())/
2366              fTPCParam->GetOuterAngle())+fTPCParam->GetNInnerSector();
2367     if (p[2]<0)         sector+=(fTPCParam->GetNOuterSector()>>1);
2368   }
2369     else   
2370       if (p[2]<0) sector+=(fTPCParam->GetNInnerSector()>>1);  
2371   //
2372   // here I have a sector number
2373   //
2374
2375   vol[0]=sector;
2376
2377   static Double_t lastReferenceR=0;
2378   if (TMath::Abs(lastReferenceR-r)>kMaxDistRef){
2379     AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber(), AliTrackReference::kTPC);
2380     lastReferenceR = r;
2381   }
2382
2383   // check if change of sector
2384   if(sector != fSecOld){
2385     fSecOld=sector;
2386     // add track reference
2387     AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber(), AliTrackReference::kTPC);
2388   }  
2389   // track is in the sensitive strip
2390   if(id == fIdSens){
2391     // track is entering the strip
2392     if (TVirtualMC::GetMC()->IsTrackEntering()){
2393       Int_t totrows = fTPCParam->GetNRowLow()+fTPCParam->GetNRowUp();
2394       vol[1] = (copy<=totrows) ? copy-1 : copy-1-totrows;
2395       // row numbers are autonomous for lower and upper sectors
2396       if(vol[0] > fTPCParam->GetNInnerSector()) {
2397         vol[1] -= fTPCParam->GetNRowLow();
2398       }
2399     //
2400       if(vol[0]<fTPCParam->GetNInnerSector()&&vol[1] == 0){
2401   
2402         // lower sector, row 0, because Jouri wants to have this
2403
2404         TVirtualMC::GetMC()->TrackMomentum(p);
2405         hits[0]=p[0];
2406         hits[1]=p[1];
2407         hits[2]=p[2];
2408         hits[3]=0.; // this hit has no energy loss
2409         // Get also the track time for pileup simulation
2410         hits[4]=TVirtualMC::GetMC()->TrackTime();
2411
2412         AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol,hits);  
2413       }
2414     //
2415
2416        TVirtualMC::GetMC()->TrackPosition(p);
2417        hits[0]=p[0];
2418        hits[1]=p[1];
2419        hits[2]=p[2];
2420        hits[3]=0.; // this hit has no energy loss
2421        // Get also the track time for pileup simulation
2422        hits[4]=TVirtualMC::GetMC()->TrackTime();
2423
2424        AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol,hits);  
2425     
2426     }
2427     else return;
2428   }  
2429   //-----------------------------------------------------------------
2430   //  charged particle is in the sensitive drift volume
2431   //-----------------------------------------------------------------
2432   if(TVirtualMC::GetMC()->TrackStep() > 0) {
2433     Int_t nel=0;
2434     if (!fPrimaryIonisation) {
2435       nel = (Int_t)(((TVirtualMC::GetMC()->Edep())-poti)/wIon) + 1;
2436     }
2437     else {
2438       
2439       /*
2440       static Double_t deForNextStep = 0.;
2441       // Geant4 (the meaning of Edep as in Geant3) - wrong
2442       //nel = (Int_t)(((TVirtualMC::GetMC()->Edep())-poti)/wIon) + 1;
2443
2444       // Geant4 (the meaning of Edep as in Geant3) - NEW
2445       Double_t eAvailable = TVirtualMC::GetMC()->Edep() + deForNextStep;
2446       nel = (Int_t)(eAvailable/wIon);
2447       deForNextStep = eAvailable - nel*wIon;
2448       */
2449
2450       //new Geant4-approach
2451       Double_t meanIon = TVirtualMC::GetMC()->Edep()/(wIon*kScalewIonG4);
2452       nel = (Int_t) ( kFanoFactorG4*AliMathBase::Gamma(meanIon/kFanoFactorG4)); // smear nel using gamma distr w mean = meanIon and variance = meanIon/kFanoFactorG4
2453     }
2454     nel=TMath::Min(nel,300); // 300 electrons corresponds to 10 keV
2455     //
2456     TVirtualMC::GetMC()->TrackPosition(p);
2457     hits[0]=p[0];
2458     hits[1]=p[1];
2459     hits[2]=p[2];
2460     hits[3]=(Float_t)nel;
2461
2462     // Add this hit
2463
2464     //    if (fHitType&&2){
2465     if(fHitType){
2466       TVirtualMC::GetMC()->TrackMomentum(p);
2467       Float_t momentum = TMath::Sqrt(p[0]*p[0]+p[1]*p[1]);
2468       Float_t precision =   (momentum>0.1) ? 0.002 :0.01;
2469       fTrackHits->SetHitPrecision(precision);
2470     }
2471
2472     // Get also the track time for pileup simulation
2473     hits[4]=TVirtualMC::GetMC()->TrackTime();
2474  
2475     AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol,hits);
2476     if (fDebugStreamer){   
2477       // You can dump here what you need
2478       // function  CreateDebugStremer() to be called in the Config.C  macro
2479       // if you want to enable it
2480       // By default debug streaemer is OFF
2481       Float_t edep = TVirtualMC::GetMC()->Edep();
2482       Float_t tstep = TVirtualMC::GetMC()->TrackStep();
2483       Int_t pid=TVirtualMC::GetMC()->TrackPid();
2484       (*fDebugStreamer)<<"hit"<<      
2485         "x="<<hits[0]<<  // hit position
2486         "y="<<hits[1]<<
2487         "z="<<hits[2]<<
2488         "nel="<<hits[3]<<  // number of electorns
2489         "tof="<<hits[4]<<  // hit TOF
2490         "edep="<<edep<<    // energy deposit
2491         "pid="<<pid<<      // pid
2492         "step="<<tstep<<
2493         "p.="<<&p<<
2494         "\n";
2495     }
2496     
2497   } // step>0 
2498   } //within sector's limits
2499   // Stemax calculation for the next step
2500   
2501   Float_t pp;
2502   TLorentzVector mom;
2503   // below is valid only for Geant3 (fPromaryIonisation not set)
2504   if(!fPrimaryIonisation){
2505     TVirtualMC::GetMC()->TrackMomentum(mom);
2506     Float_t ptot=mom.Rho();
2507     Float_t betaGamma = ptot/TVirtualMC::GetMC()->TrackMass();
2508
2509     //Int_t pid=TVirtualMC::GetMC()->TrackPid();
2510     // if((pid==kElectron || pid==kPositron) && ptot > 0.002)
2511     //       { 
2512     //         pp = prim*1.58; // electrons above 20 MeV/c are on the plateau!
2513     //       }
2514     //     else
2515     //       {
2516     
2517     betaGamma = TMath::Max(betaGamma,(Float_t)7.e-3); // protection against too small bg
2518     TVectorD *bbpar = fTPCParam->GetBetheBlochParameters(); //get parametrization from OCDB
2519     pp=prim*AliMathBase::BetheBlochAleph(betaGamma,(*bbpar)(0),(*bbpar)(1),(*bbpar)(2),(*bbpar)(3),(*bbpar)(4));         
2520     //     }
2521   
2522     Double_t rnd = TVirtualMC::GetMC()->GetRandom()->Rndm();
2523   
2524     TVirtualMC::GetMC()->SetMaxStep(-TMath::Log(rnd)/pp);
2525   }
2526   
2527 }
2528
2529