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