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