]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCv4.cxx
Task for offline calibration CALIBRATION_EMD runs
[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 "TGeoTrd1.h"
53 #include "TGeoCompositeShape.h"
54 #include "TGeoPara.h"
55 #include "TGeoPhysicalNode.h"
56
57 ClassImp(AliTPCv4)
58  
59 //_____________________________________________________________________________
60 AliTPCv4::AliTPCv4(const char *name, const char *title) :
61   AliTPC(name, title),
62   fIdSens(0),
63   fIDrift(0),
64   fSecOld(0) 
65 {
66   //
67   // Standard constructor for Time Projection Chamber version 2
68   //
69
70
71   SetBufferSize(128000);
72
73
74   if (fTPCParam)
75      fTPCParam->Write(fTPCParam->GetTitle());
76 }
77  
78 //_____________________________________________________________________________
79 void AliTPCv4::CreateGeometry()
80 {
81   //
82   // Create the geometry of Time Projection Chamber version 2
83   //
84   //Begin_Html
85   /*
86     <img src="picts/AliTPC.gif">
87   */
88   //End_Html
89   //Begin_Html
90   /*
91     <img src="picts/AliTPCv2Tree.gif">
92   */
93   //End_Html
94
95   //----------------------------------------------------------
96   // This geometry is written using TGeo class
97   // Firstly the shapes are defined, and only then the volumes
98   // What is recognized by the MC are volumes
99   //----------------------------------------------------------
100   //
101   //  tpc - this will be the mother volume
102   //
103
104   //
105   // here I define a volume TPC
106   // retrive the medium name with "TPC_" as a leading string
107   //
108   TGeoPcon *tpc = new TGeoPcon(0.,360.,20); //20 sections
109   //
110   tpc->DefineSection(0,-291.,77.,278.);
111   tpc->DefineSection(1,-270,77.,278.);
112   //
113   tpc->DefineSection(2,-270.,77.,278.);
114   tpc->DefineSection(3,-259.6,70.,278.);
115   //
116   tpc->DefineSection(4,-259.6,68.1,278.);
117   tpc->DefineSection(5,-253.6,68.1,278.);
118   //
119   tpc->DefineSection(6,-253.6,68.,278.);
120   tpc->DefineSection(7,-74.0,60.8,278.);
121   //
122   tpc->DefineSection(8,-74.0,60.1,278.);
123   tpc->DefineSection(9,-73.3,60.1,278.);
124   //
125   tpc->DefineSection(10,-73.3,56.9,278.); 
126   tpc->DefineSection(11,73.3,56.9,278.);
127   //
128   tpc->DefineSection(12,73.3,60.1,278.);
129   tpc->DefineSection(13,74.0,60.1,278.);
130   //
131   tpc->DefineSection(14,74.0,60.8,278.);
132   tpc->DefineSection(15,253.6,65.5,278.);
133   //
134   tpc->DefineSection(16,253.6,65.6,278.);
135   tpc->DefineSection(17,259.6,65.6,278.);
136   //
137   tpc->DefineSection(18,259.6,70.0,278.);
138   tpc->DefineSection(19,291.,77.,278.);
139   //
140   TGeoMedium *m1 = gGeoManager->GetMedium("TPC_Air");
141   TGeoVolume *v1 = new TGeoVolume("TPC_M",tpc,m1);
142   //
143   // drift volume - sensitive volume, extended beyond the
144   // endcaps, because of the alignment
145   //
146   TGeoPcon *dvol = new TGeoPcon(0.,360.,6);
147   dvol->DefineSection(0,-260.,74.5,264.4);
148   dvol->DefineSection(1,-253.6,74.5,264.4);
149   //
150   dvol->DefineSection(2,-253.6,76.6774,258.);
151   dvol->DefineSection(3,253.6,76.6774,258.); 
152   //
153   dvol->DefineSection(4,253.6,74.5,264.4);
154   dvol->DefineSection(5,260.,74.5,264.4);
155   //
156   TGeoMedium *m5 = gGeoManager->GetMedium("TPC_Ne-CO2-N-3");
157   TGeoVolume *v9 = new TGeoVolume("TPC_Drift",dvol,m5);
158   //
159   v1->AddNode(v9,1);
160   //
161   // outer insulator
162   //
163   TGeoPcon *tpco = new TGeoPcon(0.,360.,6); //insulator
164   //
165   tpco->DefineSection(0,-256.6,264.8,278.);
166   tpco->DefineSection(1,-253.6,264.8,278.);
167   //
168   tpco->DefineSection(2,-253.6,258.,278.);
169   tpco->DefineSection(3,250.6,258.,278.);
170   //
171   tpco->DefineSection(4,250.6,258.,275.5);
172   tpco->DefineSection(5,253.6,258.,275.5);
173   //
174   TGeoMedium *m2 = gGeoManager->GetMedium("TPC_CO2");
175   TGeoVolume *v2 = new TGeoVolume("TPC_OI",tpco,m2);
176   //
177   // outer containment vessel
178   //
179   TGeoPcon *tocv = new TGeoPcon(0.,360.,6);  // containment vessel
180   //
181   tocv->DefineSection(0,-256.6,264.8,278.);
182   tocv->DefineSection(1,-253.6,264.8,278.);
183   //
184   tocv->DefineSection(2,-253.6,274.8124,278.);
185   tocv->DefineSection(3,247.6,274.8124,278.);  
186   //
187   tocv->DefineSection(4,247.6,270.4,278.);
188   tocv->DefineSection(5,250.6,270.4,278.);
189   //
190   TGeoMedium *m3 = gGeoManager->GetMedium("TPC_Al");
191   TGeoVolume *v3 = new TGeoVolume("TPC_OCV",tocv,m3); 
192   //
193   TGeoTube *to1 = new TGeoTube(274.8174,277.995,252.1); //epoxy
194   TGeoTube *to2 = new TGeoTube(274.8274,277.985,252.1); //tedlar
195   TGeoTube *to3 = new TGeoTube(274.8312,277.9812,252.1);//prepreg2
196   TGeoTube *to4 = new TGeoTube(274.9062,277.9062,252.1);//nomex
197   //
198   TGeoMedium *sm1 = gGeoManager->GetMedium("TPC_Epoxy");
199   TGeoMedium *sm2 = gGeoManager->GetMedium("TPC_Tedlar");
200   TGeoMedium *sm3 = gGeoManager->GetMedium("TPC_Prepreg2");
201   TGeoMedium *sm4 = gGeoManager->GetMedium("TPC_Nomex");
202   //
203   TGeoVolume *tov1 = new TGeoVolume("TPC_OCV1",to1,sm1);
204   TGeoVolume *tov2 = new TGeoVolume("TPC_OCV2",to2,sm2);
205   TGeoVolume *tov3 = new TGeoVolume("TPC_OCV3",to3,sm3);
206   TGeoVolume *tov4 = new TGeoVolume("TPC_OCV4",to4,sm4);
207  //-------------------------------------------------------
208   //  Tpc Outer Field Cage
209   //  daughters - composite (sandwich)
210   //-------------------------------------------------------
211
212   TGeoPcon *tofc = new TGeoPcon(0.,360.,6);
213   //
214   tofc->DefineSection(0,-253.6,258.,269.6);
215   tofc->DefineSection(1,-250.6,258.,269.6);
216   //
217   tofc->DefineSection(2,-250.6,258.,260.0676); 
218   tofc->DefineSection(3,250.6,258.,260.0676);
219   //
220   tofc->DefineSection(4,250.6,258.,275.5);
221   tofc->DefineSection(5,253.6,258.,275.5);
222   //
223   TGeoVolume *v4 = new TGeoVolume("TPC_TOFC",tofc,m3); 
224   //sandwich
225   TGeoTube *tf1 = new TGeoTube(258.0,260.0676,252.1); //tedlar
226   TGeoTube *tf2 = new TGeoTube(258.0038,260.0638,252.1); //prepreg3
227   TGeoTube *tf3 = new TGeoTube(258.0338,260.0338,252.1);//nomex
228   //
229   TGeoMedium *sm5 = gGeoManager->GetMedium("TPC_Prepreg3");
230   //
231   TGeoVolume *tf1v = new TGeoVolume("TPC_OFC1",tf1,sm2);
232   TGeoVolume *tf2v = new TGeoVolume("TPC_OFC2",tf2,sm5);
233   TGeoVolume *tf3v = new TGeoVolume("TPC_OFC3",tf3,sm4);
234   //
235   // outer part - positioning
236   //
237   tov1->AddNode(tov2,1); tov2->AddNode(tov3,1); tov3->AddNode(tov4,1);
238   //
239   tf1v->AddNode(tf2v,1); tf2v->AddNode(tf3v,1);
240   //
241   v3->AddNode(tov1,1,new TGeoTranslation(0.,0.,-1.5)); v4->AddNode(tf1v,1);
242   //
243   v2->AddNode(v3,1); v2->AddNode(v4,1); 
244   //
245   v1->AddNode(v2,1);
246   //--------------------------------------------------------------------
247   // Tpc Inner INsulator (CO2) 
248   // the cones, the central drum and the inner f.c. sandwich with a piece
249   // of the flane will be placed in the TPC
250   //--------------------------------------------------------------------
251   TGeoPcon *tpci = new TGeoPcon(0.,360.,4);
252   //
253   tpci->DefineSection(0,-253.6,68.4,76.6774);
254   tpci->DefineSection(1,-74.0,61.2,76.6774);
255   //
256   tpci->DefineSection(2,74.0,61.2,76.6774);  
257   //
258   tpci->DefineSection(3,253.6,65.9,76.6774);
259   //
260   TGeoVolume *v5 = new TGeoVolume("TPC_INI",tpci,m2);
261   //
262   // now the inner field cage - only part of flanges (2 copies)
263   //
264   TGeoTube *tif1 = new TGeoTube(69.9,76.6774,1.5); 
265   TGeoVolume *v6 = new TGeoVolume("TPC_IFC1",tif1,m3);
266   //
267  //---------------------------------------------------------
268   // Tpc Inner Containment vessel - Muon side
269   //---------------------------------------------------------
270   TGeoPcon *tcms = new TGeoPcon(0.,360.,10);
271   //
272   tcms->DefineSection(0,-259.1,68.1,74.2);
273   tcms->DefineSection(1,-253.6,68.1,74.2);
274   //
275   tcms->DefineSection(2,-253.6,68.1,68.4);
276   tcms->DefineSection(3,-74.0,60.9,61.2);
277   //
278   tcms->DefineSection(4,-74.0,60.1,61.2);
279   tcms->DefineSection(5,-73.3,60.1,61.2);
280   //
281   tcms->DefineSection(6,-73.3,56.9,61.2);
282   tcms->DefineSection(7,-73.0,56.9,61.2);
283   //
284   tcms->DefineSection(8,-73.0,56.9,58.8);
285   tcms->DefineSection(9,-71.3,56.9,58.8);
286   //
287   TGeoVolume *v7 = new TGeoVolume("TPC_ICVM",tcms,m3);
288   //-----------------------------------------------
289   // inner containment vessel - shaft side
290   //-----------------------------------------------
291   TGeoPcon *tcss = new TGeoPcon(0.,360.,10);
292   //
293   tcss->DefineSection(0,71.3,56.9,58.8);
294   tcss->DefineSection(1,73.0,56.9,58.8);
295   //
296   tcss->DefineSection(2,73.0,56.9,61.2);
297   tcss->DefineSection(3,73.3,56.9,61.2);
298   //  
299   tcss->DefineSection(4,73.3,60.1,61.2);
300   tcss->DefineSection(5,74.0,60.1,61.2);
301   //
302   tcss->DefineSection(6,74.0,60.9,61.2);
303   tcss->DefineSection(7,253.6,65.6,65.9);
304   //
305   tcss->DefineSection(8,253.6,65.6,74.2);
306   tcss->DefineSection(9,258.1,65.6,74.2);
307   //
308   TGeoVolume *v8 = new TGeoVolume("TPC_ICVS",tcss,m3);
309   //-----------------------------------------------
310   //  Inner field cage
311   //  define 4 parts and make an assembly
312   //-----------------------------------------------
313   // part1 - Al - 2 copies
314   TGeoTube *t1 = new TGeoTube(76.6774,78.845,0.75);
315   TGeoVolume *tv1 = new TGeoVolume("TPC_IFC2",t1,m3);
316   // sandwich - outermost parts - 2 copies
317   TGeoTube *t2 = new TGeoTube(76.6774,78.845,74.175); // tedlar 38 microns
318   TGeoTube *t3 = new TGeoTube(76.6812,78.8412,74.175); // prepreg2 500 microns
319   TGeoTube *t4 = new TGeoTube(76.7312,78.7912,74.175); // prepreg3 300 microns
320   TGeoTube *t5 = new TGeoTube(76.7612,78.7612,74.175); // nomex 2 cm
321   //
322   TGeoVolume *tv2 = new TGeoVolume("TPC_IFC3",t2,sm2);
323   TGeoVolume *tv3 = new TGeoVolume("TPC_IFC4",t3,sm3);
324   TGeoVolume *tv4 = new TGeoVolume("TPC_IFC5",t4,sm5);
325   TGeoVolume *tv5 = new TGeoVolume("TPC_IFC6",t5,sm4);
326   //
327   // middle parts - 2 copies
328   TGeoTube *t6 = new TGeoTube(76.6774,78.795,5.); // tedlar 38 microns
329   TGeoTube *t7 = new TGeoTube(76.6812,78.7912,5.); // prepreg2 250 microns
330   TGeoTube *t8 = new TGeoTube(76.7062,78.7662,5.); // prepreg3 300 microns
331   TGeoTube *t9 = new TGeoTube(76.7362,78.7362,5.); // nomex 2 cm
332   //
333   TGeoVolume *tv6 = new TGeoVolume("TPC_IFC7",t6,sm2);
334   TGeoVolume *tv7 = new TGeoVolume("TPC_IFC8",t7,sm3);
335   TGeoVolume *tv8 = new TGeoVolume("TPC_IFC9",t8,sm5);
336   TGeoVolume *tv9 = new TGeoVolume("TPC_IFC10",t9,sm4);
337   // central part - 1 copy
338   TGeoTube *t10 = new TGeoTube(76.6774,78.745,93.75); // tedlar 38 microns 
339   TGeoTube *t11 = new TGeoTube(76.6812,78.7412,93.75); // prepreg3 300 microns
340   TGeoTube *t12 = new TGeoTube(76.7112,78.7112,93.75); // nomex 2 cm
341   //
342   TGeoVolume *tv10 = new TGeoVolume("TPC_IFC11",t10,sm2);
343   TGeoVolume *tv11 = new TGeoVolume("TPC_IFC12",t11,sm5);
344   TGeoVolume *tv12 = new TGeoVolume("TPC_IFC13",t12,sm4);
345   //
346   // inner part - positioning
347   //
348   // creating a sandwich
349   tv2->AddNode(tv3,1); tv3->AddNode(tv4,1); tv4->AddNode(tv5,1);
350   //
351   tv6->AddNode(tv7,1); tv7->AddNode(tv8,1); tv8->AddNode(tv9,1);
352   //
353   tv10->AddNode(tv11,1); tv11->AddNode(tv12,1);
354   //
355   TGeoVolumeAssembly *tv100 = new TGeoVolumeAssembly("TPC_IFC");
356   //
357   tv100->AddNode(tv10,1);
358   tv100->AddNode(tv6,1,new TGeoTranslation(0.,0.,-98.75));
359   tv100->AddNode(tv6,2,new TGeoTranslation(0.,0.,98.75));
360   tv100->AddNode(tv2,1,new TGeoTranslation(0.,0.,-177.925));
361   tv100->AddNode(tv2,2,new TGeoTranslation(0.,0.,177.925));
362   tv100->AddNode(tv1,1,new TGeoTranslation(0.,0.,-252.85));
363   tv100->AddNode(tv1,2,new TGeoTranslation(0.,0.,252.85));
364   //
365   v5->AddNode(v6,1, new TGeoTranslation(0.,0.,-252.1));
366   v5->AddNode(v6,2, new TGeoTranslation(0.,0.,252.1));
367   v1->AddNode(v5,1); v1->AddNode(v7,1); v1->AddNode(v8,1); 
368   v9->AddNode(tv100,1);
369   //
370   // central drum 
371   //
372   // flange + sandwich
373   //
374   TGeoPcon *cfl = new TGeoPcon(0.,360.,6);
375   cfl->DefineSection(0,-71.1,59.7,61.2);
376   cfl->DefineSection(1,-68.6,59.7,61.2);
377   //
378   cfl->DefineSection(2,-68.6,60.6324,61.2);
379   cfl->DefineSection(3,68.6,60.6324,61.2); 
380   //
381   cfl->DefineSection(4,68.6,59.7,61.2);
382   cfl->DefineSection(5,71.1,59.7,61.2);  
383   //
384   TGeoVolume *cflv = new TGeoVolume("TPC_CDR",cfl,m3);
385   // sandwich
386   TGeoTube *cd1 = new TGeoTube(60.6424,61.19,71.1);
387   TGeoTube *cd2 = new TGeoTube(60.6462,61.1862,71.1);
388   TGeoTube *cd3 = new TGeoTube(60.6662,61.1662,71.1);  
389   //
390   TGeoMedium *sm6 = gGeoManager->GetMedium("TPC_Prepreg1");
391   TGeoVolume *cd1v = new TGeoVolume("TPC_CDR1",cd1,sm2); //tedlar
392   TGeoVolume *cd2v = new TGeoVolume("TPC_CDR2",cd2,sm6);// prepreg1
393   TGeoVolume *cd3v = new TGeoVolume("TPC_CDR3",cd3,sm4); //nomex
394   //
395   // seals for central drum 2 copies
396   //
397   TGeoTube *cs = new TGeoTube(56.9,61.2,0.1);
398   TGeoMedium *sm7 = gGeoManager->GetMedium("TPC_Mylar");
399   TGeoVolume *csv = new TGeoVolume("TPC_CDRS",cs,sm7);
400   v1->AddNode(csv,1,new TGeoTranslation(0.,0.,-71.2));
401   v1->AddNode(csv,2,new TGeoTranslation(0.,0.,71.2));
402   //
403   // seal collars 
404   TGeoPcon *se = new TGeoPcon(0.,360.,6);
405   se->DefineSection(0,-72.8,59.7,61.2);
406   se->DefineSection(1,-72.3,59.7,61.2);
407   //
408   se->DefineSection(2,-72.3,58.85,61.2);
409   se->DefineSection(3,-71.6,58.85,61.2); 
410   //
411   se->DefineSection(4,-71.6,59.7,61.2);
412   se->DefineSection(5,-71.3,59.7,61.2);  
413   //
414   TGeoVolume *sev = new TGeoVolume("TPC_CDCE",se,m3);
415   //
416   TGeoTube *si = new TGeoTube(56.9,58.8,1.); 
417   TGeoVolume *siv = new TGeoVolume("TPC_CDCI",si,m3);
418   //
419   // define reflection matrix 
420   //
421   TGeoRotation *ref = new TGeoRotation("ref",90.,0.,90.,90.,180.,0.);
422   //
423   cd1v->AddNode(cd2v,1); cd2v->AddNode(cd3v,1); cflv->AddNode(cd1v,1);
424   //
425   v1->AddNode(siv,1,new TGeoTranslation(0.,0.,-69.9));
426   v1->AddNode(siv,2,new TGeoTranslation(0.,0.,69.9));
427   v1->AddNode(sev,1); v1->AddNode(sev,2,ref); v1->AddNode(cflv,1);
428   //
429   // central membrane - 2 rings and a mylar membrane - assembly
430   //
431   TGeoTube *ih = new TGeoTube(81.05,84.05,0.3);
432   TGeoTube *oh = new TGeoTube(250.,256.,.5);
433   TGeoTube *mem = new TGeoTube(84.05,250,0.01);
434   TGeoVolume *ihv = new TGeoVolume("TPC_IHVH",ih,m3);
435   TGeoVolume *ohv = new TGeoVolume("TPC_OHVH",oh,m3);
436   TGeoVolume *memv = new TGeoVolume("TPC_HV",mem,sm7);
437   //
438   TGeoVolumeAssembly *cm = new TGeoVolumeAssembly("TPC_HVMEM");
439   cm->AddNode(ihv,1);
440   cm->AddNode(ohv,1);
441   cm->AddNode(memv,1);
442   v9->AddNode(cm,1);
443   //
444   // end caps - they are make as an assembly of single segments
445   // containing both readout chambers
446   //
447   Double_t openingAngle = 10.*TMath::DegToRad();
448   Double_t thick=1.5; // rib
449   Double_t shift = thick/TMath::Sin(openingAngle);
450   //
451   Double_t lowEdge = 86.3; // hole in the wheel
452   Double_t upEdge = 240.4; // hole in the wheel
453   //
454   new TGeoTubeSeg("sec",74.5,264.4,3.,0.,20.);
455   //
456   TGeoPgon *hole = new TGeoPgon("hole",0.,20.,1,4);
457   //
458   hole->DefineSection(0,-3.5,lowEdge-shift,upEdge-shift);
459   hole->DefineSection(1,-1.5,lowEdge-shift,upEdge-shift);
460   //
461   hole->DefineSection(2,-1.5,lowEdge-shift,upEdge+3.-shift);
462   hole->DefineSection(3,3.5,lowEdge-shift,upEdge+3.-shift);
463   //
464   Double_t ys = shift*TMath::Sin(openingAngle); 
465   Double_t xs = shift*TMath::Cos(openingAngle);
466   TGeoTranslation *tr = new TGeoTranslation("tr",xs,ys,0.);  
467   tr->RegisterYourself();
468   TGeoCompositeShape *chamber = new TGeoCompositeShape("sec-hole:tr");
469   TGeoVolume *sv = new TGeoVolume("TPC_WSEG",chamber,m3);
470   TGeoPgon *bar = new TGeoPgon("bar",0.,20.,1,2);
471   bar->DefineSection(0,-3.,131.5-shift,136.5-shift);
472   bar->DefineSection(1,1.5,131.5-shift,136.5-shift);
473   TGeoVolume *barv = new TGeoVolume("TPC_WBAR",bar,m3);
474   TGeoVolumeAssembly *ch = new TGeoVolumeAssembly("TPC_WCH");//empty segment
475   //
476   ch->AddNode(sv,1); ch->AddNode(barv,1,tr);
477   //
478   // readout chambers
479   //
480   // IROC first
481   //
482    TGeoTrd1 *ibody = new TGeoTrd1(13.8742,21.3328,4.29,21.15);
483    TGeoVolume *ibdv = new TGeoVolume("TPC_IROCB",ibody,m3);
484   // empty space
485    TGeoTrd1 *emp = new TGeoTrd1(12.3742,19.8328,3.99,19.65);
486    TGeoVolume *empv = new TGeoVolume("TPC_IROCE",emp,m1);
487    ibdv->AddNode(empv,1,new TGeoTranslation(0.,-0.3,0.));
488    //bars
489    Double_t tga = (19.8328-12.3742)/39.3;
490    Double_t xmin,xmax;
491    xmin = 9.55*tga+12.3742;
492    xmax = 9.95*tga+12.3742;
493    TGeoTrd1 *ib1 = new TGeoTrd1(xmin,xmax,3.29,0.2);
494    TGeoVolume *ib1v = new TGeoVolume("TPC_IRB1",ib1,m3);
495    empv->AddNode(ib1v,1,new TGeoTranslation("tt1",0.,0.7,-9.9));
496    xmin=19.4*tga+12.3742;
497    xmax=19.9*tga+12.3742;
498    TGeoTrd1 *ib2 = new TGeoTrd1(xmin,xmax,3.29,0.25);
499    TGeoVolume *ib2v = new TGeoVolume("TPC_TRB2",ib2,m3);
500    empv->AddNode(ib2v,1,new TGeoTranslation(0.,0.7,0.));
501    xmin=29.35*tga+12.3742;
502    xmax=29.75*tga+12.3742;
503    TGeoTrd1 *ib3 = new TGeoTrd1(xmin,xmax,3.29,0.2); 
504    TGeoVolume *ib3v = new TGeoVolume("TPC_IRB3",ib3,m3);    
505    empv->AddNode(ib3v,1,new TGeoTranslation(0.,0.7,9.9));
506    //
507    // holes for connectors
508    //
509    TGeoBBox *conn = new TGeoBBox(0.4,0.3,4.675); // identical for iroc and oroc
510    TGeoVolume *connv = new TGeoVolume("TPC_RCCON",conn,m1);
511    TString fileName(gSystem->Getenv("ALICE_ROOT"));
512    fileName += "/TPC/conn_iroc.dat";
513    ifstream in;
514    in.open(fileName.Data(), ios_base::in); // asci file
515    for(Int_t i =0;i<86;i++){
516       Double_t y = 3.99;
517       Double_t x,z,ang;
518       in>>x>>z>>ang;
519       z-=26.5;
520       TGeoRotation *rrr = new TGeoRotation();
521       rrr->RotateY(ang);
522       TGeoCombiTrans *trans = new TGeoCombiTrans("trans",x,y,z,rrr);
523       ibdv->AddNode(connv,i+1,trans);
524    }
525    in.close();
526    // "cap"
527    new TGeoTrd1("icap",14.5974,23.3521,1.19,24.825);
528    // "hole"
529    new TGeoTrd1("ihole",13.8742,21.3328,1.2,21.15);
530    TGeoTranslation *tr1 = new TGeoTranslation("tr1",0.,0.,1.725);  
531    tr1->RegisterYourself();
532    TGeoCompositeShape *ic = new TGeoCompositeShape("icap-ihole:tr1");
533    TGeoVolume *icv = new TGeoVolume("TPC_IRCAP",ic,m3);
534    //
535    // pad plane and wire fixations
536    //
537    TGeoTrd1 *pp = new TGeoTrd1(14.5974,23.3521,0.3,24.825); //pad+iso
538    TGeoMedium *m4 = gGeoManager->GetMedium("TPC_G10");
539    TGeoVolume *ppv = new TGeoVolume("TPC_IRPP",pp,m4);
540    TGeoPara *f1 = new TGeoPara(.6,.5,24.825,0.,-10.,0.);
541    TGeoVolume *f1v = new TGeoVolume("TPC_IRF1",f1,m4);
542    TGeoPara *f2 = new TGeoPara(.6,.5,24.825,0.,10.,0.);
543    TGeoVolume *f2v = new TGeoVolume("TPC_IRF2",f2,m4);
544    //
545    TGeoVolumeAssembly *iroc = new TGeoVolumeAssembly("TPC_IROC");
546    //
547    iroc->AddNode(ibdv,1);
548    iroc->AddNode(icv,1,new TGeoTranslation(0.,3.1,-1.725));
549    iroc->AddNode(ppv,1,new TGeoTranslation(0.,4.59,-1.725));
550    tga =(23.3521-14.5974)/49.65; 
551    Double_t xx = 24.825*tga+14.5974-0.6;
552    iroc->AddNode(f1v,1,new TGeoTranslation(-xx,5.39,-1.725));
553    iroc->AddNode(f2v,1,new TGeoTranslation(xx,5.39,-1.725));
554    //
555    // OROC
556    //
557    TGeoTrd1 *obody = new TGeoTrd1(22.2938,40.5084,4.19,51.65);
558    TGeoVolume *obdv = new TGeoVolume("TPC_OROCB",obody,m3);
559    TGeoTrd1 *oemp = new TGeoTrd1(20.2938,38.5084,3.89,49.65);
560    TGeoVolume *oempv = new TGeoVolume("TPC_OROCE",oemp,m1);
561    obdv->AddNode(oempv,1,new TGeoTranslation(0.,-0.3,0.));
562    //horizontal bars
563    tga=(38.5084-20.2938)/99.3;
564    xmin=tga*10.2+20.2938;
565    xmax=tga*10.6+20.2938;
566    TGeoTrd1 *ob1 = new TGeoTrd1(xmin,xmax,2.915,0.2);
567    TGeoVolume *ob1v = new TGeoVolume("TPC_ORB1",ob1,m3);
568    //
569    xmin=22.55*tga+20.2938;
570    xmax=24.15*tga+20.2938;
571    TGeoTrd1 *ob2 = new TGeoTrd1(xmin,xmax,2.915,0.8);
572    TGeoVolume *ob2v = new TGeoVolume("TPC_ORB2",ob2,m3);
573    //
574    xmin=36.1*tga+20.2938;
575    xmax=36.5*tga+20.2938;
576    TGeoTrd1 *ob3 = new TGeoTrd1(xmin,xmax,2.915,0.2);
577    TGeoVolume *ob3v = new TGeoVolume("TPC_ORB3",ob3,m3);
578    //
579    xmin=49.0*tga+20.2938;
580    xmax=50.6*tga+20.2938;   
581    TGeoTrd1 *ob4 = new TGeoTrd1(xmin,xmax,2.915,0.8);
582    TGeoVolume *ob4v = new TGeoVolume("TPC_ORB4",ob4,m3);
583    //
584    xmin=63.6*tga+20.2938;
585    xmax=64.0*tga+20.2938;
586    TGeoTrd1 *ob5 = new TGeoTrd1(xmin,xmax,2.915,0.2);
587    TGeoVolume *ob5v = new TGeoVolume("TPC_ORB5",ob5,m3);
588    //
589    xmin=75.5*tga+20.2938;
590    xmax=77.15*tga+20.2938;
591    TGeoTrd1 *ob6 = new TGeoTrd1(xmin,xmax,2.915,0.8);
592    TGeoVolume *ob6v = new TGeoVolume("TPC_ORB6",ob6,m3);
593    //
594    xmin=88.7*tga+20.2938;
595    xmax=89.1*tga+20.2938;
596    TGeoTrd1 *ob7 = new TGeoTrd1(xmin,xmax,2.915,0.2);
597    TGeoVolume *ob7v = new TGeoVolume("TPC_ORB7",ob7,m3);
598    //
599    oempv->AddNode(ob1v,1,new TGeoTranslation(0.,0.975,-39.25));
600    oempv->AddNode(ob2v,1,new TGeoTranslation(0.,0.975,-26.3));
601    oempv->AddNode(ob3v,1,new TGeoTranslation(0.,0.975,-13.35));
602    oempv->AddNode(ob4v,1,new TGeoTranslation(0.,0.975,0.15));
603    oempv->AddNode(ob5v,1,new TGeoTranslation(0.,0.975,14.15));
604    oempv->AddNode(ob6v,1,new TGeoTranslation(0.,0.975,26.7));
605    oempv->AddNode(ob7v,1,new TGeoTranslation(0.,0.975,39.25));
606    // vertical bars
607    TGeoBBox *ob8 = new TGeoBBox(0.8,2.915,5.1); 
608    TGeoBBox *ob9 = new TGeoBBox(0.8,2.915,5.975);
609    TGeoBBox *ob10 = new TGeoBBox(0.8,2.915,5.775);
610    TGeoBBox *ob11 = new TGeoBBox(0.8,2.915,6.25);
611    TGeoBBox *ob12 = new TGeoBBox(0.8,2.915,6.5);
612    //
613    TGeoVolume *ob8v = new TGeoVolume("TPC_ORB8",ob8,m3);
614    TGeoVolume *ob9v = new TGeoVolume("TPC_ORB9",ob9,m3);
615    TGeoVolume *ob10v = new TGeoVolume("TPC_ORB10",ob10,m3);
616    TGeoVolume *ob11v = new TGeoVolume("TPC_ORB11",ob11,m3);
617    TGeoVolume *ob12v = new TGeoVolume("TPC_ORB12",ob12,m3);
618    //
619    oempv->AddNode(ob8v,1,new TGeoTranslation(0.,0.975,-44.55));
620    oempv->AddNode(ob8v,2,new TGeoTranslation(0.,0.975,44.55));
621    oempv->AddNode(ob9v,1,new TGeoTranslation(0.,0.975,-33.075));
622    oempv->AddNode(ob9v,2,new TGeoTranslation(0.,0.975,-19.525));
623    oempv->AddNode(ob10v,1,new TGeoTranslation(0.,0.975,20.125));
624    oempv->AddNode(ob10v,2,new TGeoTranslation(0.,0.975,33.275));
625    oempv->AddNode(ob11v,1,new TGeoTranslation(0.,0.975,-6.9));
626    oempv->AddNode(ob12v,1,new TGeoTranslation(0.,0.975,7.45));
627    //
628    // holes for connectors
629    //
630    fileName = gSystem->Getenv("ALICE_ROOT");
631    fileName += "/TPC/conn_oroc.dat";
632    in.open(fileName.Data(), ios_base::in); // asci file
633    for(Int_t i =0;i<78;i++){
634       Double_t y =3.89;
635       Double_t x,z,ang;
636       Double_t x1,z1,x2,z2;
637       in>>x>>z>>ang;        
638       Double_t xr = 4.7*TMath::Sin(ang*TMath::DegToRad());
639       Double_t zr = 4.7*TMath::Cos(ang*TMath::DegToRad());
640       //
641       x1=xr+x; x2=-xr+x; z1=zr+z; z2 = -zr+z;      
642       //
643       TGeoRotation *rr = new TGeoRotation();
644       rr->RotateY(ang); 
645       z1-=54.95;
646       z2-=54.95;
647       TGeoCombiTrans *trans1 = new TGeoCombiTrans("trans1",x1,y,z1,rr);
648       TGeoCombiTrans *trans2 = new TGeoCombiTrans("trans2",x2,y,z2,rr);
649       obdv->AddNode(connv,i+1,trans1);
650       obdv->AddNode(connv,i+79,trans2);
651    }
652    in.close();
653    // cap
654    new TGeoTrd1("ocap",23.3874,43.5239,1.09,57.1);
655    new TGeoTrd1("ohole",22.2938,40.5084,1.09,51.65);
656    TGeoTranslation *tr5 = new TGeoTranslation("tr5",0.,0.,-2.15);
657    tr5->RegisterYourself();
658    TGeoCompositeShape *oc = new TGeoCompositeShape("ocap-ohole:tr5");
659    TGeoVolume *ocv = new TGeoVolume("TPC_ORCAP",oc,m3);
660    //
661    // pad plane and wire fixations
662    //
663    TGeoTrd1 *opp = new TGeoTrd1(23.3874,43.5239,0.3,57.1);
664    TGeoVolume *oppv = new TGeoVolume("TPC_ORPP",opp,m4);
665    //
666    tga=(43.5239-23.3874)/114.2;
667    TGeoPara *f3 = new TGeoPara(.7,.6,57.1,0.,-10.,0.);
668    TGeoPara *f4 = new TGeoPara(.7,.6,57.1,0.,10.,0.);  
669    xx = 57.1*tga+23.3874-0.7;
670    TGeoVolume *f3v = new TGeoVolume("TPC_ORF1",f3,m4);
671    TGeoVolume *f4v = new TGeoVolume("TPC_ORF2",f4,m4);
672    //
673    TGeoVolumeAssembly *oroc = new TGeoVolumeAssembly("TPC_OROC");
674    //
675    oroc->AddNode(obdv,1);
676    oroc->AddNode(ocv,1,new TGeoTranslation(0.,3.1,2.15));
677    oroc->AddNode(oppv,1,new TGeoTranslation(0.,4.49,2.15));
678    oroc->AddNode(f3v,1,new TGeoTranslation(-xx,5.39,2.15));
679    oroc->AddNode(f4v,1,new TGeoTranslation(xx,5.39,2.15));
680    // 
681    // now iroc and oroc are placed into a sector...
682    //
683    TGeoVolumeAssembly *secta = new TGeoVolumeAssembly("TPC_SECT"); // a-side
684    TGeoVolumeAssembly *sectc = new TGeoVolumeAssembly("TPC_SECT"); // c-side
685    TGeoRotation rot1("rot1",90.,90.,0.);
686    TGeoRotation rot2("rot2");
687    rot2.RotateY(10.);
688    TGeoRotation *rot = new TGeoRotation("rot");
689    *rot=rot1*rot2;
690    //
691    Double_t x0,y0;
692    x0=110.2*TMath::Cos(openingAngle);
693    y0=110.2*TMath::Sin(openingAngle);
694    TGeoCombiTrans *combi1a = new TGeoCombiTrans("combi1",x0,y0,1.09+0.195,rot); //a-side 
695    TGeoCombiTrans *combi1c = new TGeoCombiTrans("combi1",x0,y0,1.09+0.222,rot); //c-side
696    x0=188.45*TMath::Cos(openingAngle);
697    y0=188.45*TMath::Sin(openingAngle);
698    TGeoCombiTrans *combi2a = new TGeoCombiTrans("combi2",x0,y0,0.99+0.195,rot); //a-side
699    TGeoCombiTrans *combi2c = new TGeoCombiTrans("combi2",x0,y0,0.99+0.222,rot); //c-side
700    //
701    //
702    // A-side
703    //
704    secta->AddNode(ch,1);
705    secta->AddNode(iroc,1,combi1a);
706    secta->AddNode(oroc,1,combi2a);
707    //
708    // C-side
709    //
710    sectc->AddNode(ch,1);
711    sectc->AddNode(iroc,1,combi1c);
712    sectc->AddNode(oroc,1,combi2c);
713    //
714    // now I try to make  wheels...
715    //
716    TGeoVolumeAssembly *wheela = new TGeoVolumeAssembly("TPC_ENDCAP");
717    TGeoVolumeAssembly *wheelc = new TGeoVolumeAssembly("TPC_ENDCAP");
718    //
719    for(Int_t i =0;i<18;i++){
720      Double_t phi = (20.*i);
721      TGeoRotation *r = new TGeoRotation();
722      r->RotateZ(phi);
723      wheela->AddNode(secta,i+1,r);
724      wheelc->AddNode(sectc,i+1,r); 
725     
726    }
727    // wheels in the drift volume!   
728
729    TGeoCombiTrans *combi3 = new TGeoCombiTrans("combi3",0.,0.,256.6,ref);
730    v9->AddNode(wheela,1,combi3);
731    v9->AddNode(wheelc,2,new TGeoTranslation(0.,0.,-256.6));
732    //_____________________________________________________________
733    // service support wheel
734    //_____________________________________________________________
735   TGeoPgon *sw = new TGeoPgon(0.,20.,1,2);
736   sw->DefineSection(0,-4.,80.5,251.75);
737   sw->DefineSection(1,4.,80.5,251.75); 
738   TGeoVolume *swv = new TGeoVolume("TPC_SWSEG",sw,m3); //Al
739   //
740   thick=1.;
741   shift = thick/TMath::Sin(openingAngle);
742   TGeoPgon *sh = new TGeoPgon(0.,20.,1,2);
743   sh->DefineSection(0,-4.,81.5-shift,250.75-shift);
744   sh->DefineSection(1,4.,81.5-shift,250.75-shift);
745   TGeoVolume *shv = new TGeoVolume("TPC_SWS1",sh,m1); //Air
746   //
747   TGeoMedium *m9 =  gGeoManager->GetMedium("TPC_Si"); 
748   TGeoPgon *el = new TGeoPgon(0.,20.,1,2);
749   el->DefineSection(0,-1.872,81.5-shift,250.75-shift);
750   el->DefineSection(1,1.872,81.5-shift,250.75-shift);
751   TGeoVolume *elv = new TGeoVolume("TPC_ELEC",el,m9); //Si 
752   //
753   shv->AddNode(elv,1);
754   //
755   //
756   ys = shift*TMath::Sin(openingAngle);
757   xs = shift*TMath::Cos(openingAngle);
758   swv->AddNode(shv,1,new TGeoTranslation(xs,ys,0.));
759   // cover
760   TGeoPgon *co = new TGeoPgon(0.,20.,1,2);
761   co->DefineSection(0,-0.5,77.,255.25);
762   co->DefineSection(1,0.5,77.,255.25);
763   TGeoVolume *cov = new TGeoVolume("TPC_SWC1",co,m3);//Al
764   // hole in a cover
765   TGeoPgon *coh = new TGeoPgon(0.,20.,1,2);
766   shift=4./TMath::Sin(openingAngle);
767   coh->DefineSection(0,-0.5,85.-shift,247.25-shift);
768   coh->DefineSection(1,0.5,85.-shift,247.25-shift);  
769   //
770   TGeoVolume *cohv = new TGeoVolume("TPC_SWC2",coh,m1);
771   //
772   ys = shift*TMath::Sin(openingAngle);
773   xs = shift*TMath::Cos(openingAngle);  
774   cov->AddNode(cohv,1,new TGeoTranslation(xs,ys,0.));
775   //
776   // Sector as an Assembly
777   //
778   TGeoVolumeAssembly *swhs = new TGeoVolumeAssembly("TPC_SSWSEC");
779   swhs->AddNode(swv,1);
780   swhs->AddNode(cov,1,new TGeoTranslation(0.,0.,-4.5));
781   swhs->AddNode(cov,2,new TGeoTranslation(0.,0.,4.5));
782   //
783   // SSW as an Assembly of sectors
784   //
785  TGeoVolumeAssembly *swheel = new TGeoVolumeAssembly("TPC_SSWHEEL");
786    for(Int_t i =0;i<18;i++){
787      Double_t phi = (20.*i);
788      TGeoRotation *r = new TGeoRotation();
789      r->RotateZ(phi);
790      swheel->AddNode(swhs,i+1,r);   
791    }
792    v1->AddNode(swheel,1,new TGeoTranslation(0.,0.,-284.6));
793    v1->AddNode(swheel,2,new TGeoTranslation(0.,0.,284.6));
794
795    // sensitive strips - strip "0" is always set
796    // conditional
797    Int_t totrows;
798    totrows = fTPCParam->GetNRowLow() + fTPCParam->GetNRowUp();
799    Double_t *upar;
800    upar=NULL;
801    gGeoManager->Volume("TPC_Strip","PGON",m5->GetId(),upar);
802    upar=new Double_t [10];
803    upar[0]=0.;
804    upar[1]=360.;
805    upar[2]=18.;
806    upar[3]=2.;
807    //
808    upar[4]=-124.8;
809    upar[7]=124.8;
810
811    Double_t rlow=fTPCParam->GetPadRowRadiiLow(0);
812
813    upar[5]=rlow;
814    upar[6]=rlow+.01;
815    upar[8]=upar[5];
816    upar[9]=upar[6];
817    //
818    gGeoManager->Node("TPC_Strip",1,"TPC_Drift",0.,0.,124.82,0,kTRUE,upar,10);
819    gGeoManager->Node("TPC_Strip",totrows+1,
820                      "TPC_Drift",0.,0.,-124.82,0,kTRUE,upar,10);
821    //
822    // now, strips optionally
823    //
824    if(fSens){
825      //lower sectors
826      for(Int_t i=2;i<fTPCParam->GetNRowLow()+1;i++){
827        rlow=fTPCParam->GetPadRowRadiiLow(i-1);
828        upar[5]=rlow;
829        upar[6]=rlow+.01;
830        upar[8]=upar[5];
831        upar[9]=upar[6];
832        gGeoManager->Node("TPC_Strip",i,
833                          "TPC_Drift",0.,0.,124.82,0,kTRUE,upar,10);
834        gGeoManager->Node("TPC_Strip",totrows+i,
835                          "TPC_Drift",0.,0.,-124.82,0,kTRUE,upar,10);       
836      }
837      //upper sectors
838      for(Int_t i=1;i<fTPCParam->GetNRowUp()+1;i++){
839        rlow=fTPCParam->GetPadRowRadiiUp(i-1); 
840        upar[5]=rlow;
841        upar[6]=rlow+.01;
842        upar[8]=upar[5];
843        upar[9]=upar[6];
844        gGeoManager->Node("TPC_Strip",i+fTPCParam->GetNRowLow(),
845                          "TPC_Drift",0.,0.,124.82,0,kTRUE,upar,10); 
846        gGeoManager->Node("TPC_Strip",totrows+i+fTPCParam->GetNRowLow(),
847                          "TPC_Drift",0.,0.,-124.82,0,kTRUE,upar,10); 
848      }
849    }//strips
850   //----------------------------------------------------------
851   // TPc Support Rods - MAKROLON
852   //----------------------------------------------------------
853   TGeoMedium *m6=gGeoManager->GetMedium("TPC_Makrolon");
854   TGeoMedium *m7=gGeoManager->GetMedium("TPC_Cu");
855   TGeoMedium *m10 =  gGeoManager->GetMedium("TPC_Alumina");
856   TGeoMedium *m11 =  gGeoManager->GetMedium("TPC_Peek");
857   TGeoMedium *m12 =  gGeoManager->GetMedium("TPC_Water");
858   // upper and lower rods differ in length!
859   delete [] upar;
860   upar=NULL;
861   gGeoManager->Volume("TPC_Rod","TUBE",m6->GetId(),upar);
862   upar=new Double_t [3];
863   upar[0]=1.8;
864   upar[1]=2.2;
865   
866   //
867   //HV rods - makrolon + 0.58cm (diameter) Cu
868   TGeoTube *hvr = new TGeoTube(0.,2.2,126.64);
869   TGeoTube *hvc = new TGeoTube(0.,0.29,126.64);
870   //
871   TGeoVolume *hvrv = new TGeoVolume("TPC_HV_Rod",hvr,m6);
872   TGeoVolume *hvcv = new TGeoVolume("TPC_HV_Cable",hvc,m7);
873   hvrv->AddNode(hvcv,1);
874   //
875   // resistor rods
876   //
877   TGeoTube *cri = new TGeoTube(0.,0.45,126.64); //inner 
878   TGeoTube *cro = new TGeoTube(0.,0.45,126.54); //outer 
879   TGeoTube *cwi = new TGeoTube(0.,0.15,126.64); // water inner
880   TGeoTube *cwo = new TGeoTube(0.,0.15,126.54); // water outer
881   //
882   TGeoVolume *criv = new TGeoVolume("TPC_CR_I",cri,m10);
883   TGeoVolume *crov = new TGeoVolume("TPC_CR_O",cro,m10);    
884   TGeoVolume *cwiv = new TGeoVolume("TPC_W_I",cwi,m11);
885   TGeoVolume *cwov = new TGeoVolume("TPC_W_O",cwo,m11);   
886   //
887   // ceramic rod with water
888   //
889   criv->AddNode(cwiv,1); 
890   crov->AddNode(cwov,1);
891   //
892   TGeoTube *pri =new TGeoTube(0.2,0.35,126.64); //inner 
893   TGeoTube *pro = new TGeoTube(0.2,0.35,126.54); //outer    
894   //
895   // peek rod
896   //
897   TGeoVolume *priv = new TGeoVolume("TPC_PR_I",pri,m12);
898   TGeoVolume *prov = new TGeoVolume("TPC_PR_O",pro,m12); 
899   //
900   // resistor rods assembly
901   //
902    TGeoRotation *rotr = new TGeoRotation("rotr");
903    rotr->RotateZ(-21.);
904   //
905   TGeoTube *rri = new TGeoTube(1.8,2.2,126.64);//inner
906   TGeoTube *rro = new TGeoTube(1.8,2.2,126.54);//inner
907   //
908   TGeoVolume *rriv = new TGeoVolume("TPC_RR_I",rri,m6);
909   TGeoVolume *rrov = new TGeoVolume("TPC_RR_O",rro,m6);  
910   //
911   TGeoVolumeAssembly *rrin = new TGeoVolumeAssembly("TPC_RROD_I");
912   TGeoVolumeAssembly *rrou = new TGeoVolumeAssembly("TPC_RROD_O");
913   rrin->AddNode(rriv,1);
914   rrin->AddNode(criv,1,new TGeoTranslation(0.5,0.866, 0.));
915   rrin->AddNode(criv,2,new TGeoTranslation(0.5,-0.866, 0.)); 
916   rrin->AddNode(priv,1); 
917   //
918   rrou->AddNode(rrov,1);
919   rrou->AddNode(crov,1,new TGeoTranslation(0.5,0.866, 0.));
920   rrou->AddNode(crov,2,new TGeoTranslation(0.5,-0.866, 0.)); 
921   rrou->AddNode(prov,1); 
922   for(Int_t i=0;i<18;i++){
923     Double_t angle,x,y;
924     Double_t z,r; 
925     angle=TMath::DegToRad()*20.*(Double_t)i;
926     r=81.5;
927     x=r * TMath::Cos(angle);
928     y=r * TMath::Sin(angle);
929     upar[2]=126.64; //lower
930     z= 126.96;
931     //
932     if(i==3){
933       v9->AddNode(rrin,1,new TGeoCombiTrans(x,y,z,rotr)); //A
934       v9->AddNode(rrin,2,new TGeoCombiTrans(x,y,-z,rotr)); //C   
935     } 
936     else { 
937       gGeoManager->Node("TPC_Rod",i+1,"TPC_Drift",x,y,z,0,kTRUE,upar,3);//shaft
938       gGeoManager->Node("TPC_Rod",i+19,"TPC_Drift",x,y,-z,0,kTRUE,upar,3);//muon
939     }
940    
941
942     //
943     r=254.25;
944     x=r * TMath::Cos(angle);
945     y=r * TMath::Sin(angle);
946     upar[2]=126.54; //upper
947     z=127.06;
948     if(i==15){
949       //v9->AddNode(hvrv,1,new TGeoTranslation(x,y,z));//A-side only
950       v9->AddNode(hvrv,1,new TGeoTranslation(x,y,127.14));//A-side only
951       gGeoManager->Node("TPC_Rod",i+55,"TPC_Drift",x,y,-z,0,kTRUE,upar,3);
952     }
953     else if(i==11){
954       v9->AddNode(rrou,1,new TGeoCombiTrans(x,y,z,rotr)); //A
955       v9->AddNode(rrou,2,new TGeoCombiTrans(x,y,-z,rotr)); //C
956     }
957     else{
958     //
959       gGeoManager->Node("TPC_Rod",i+37,"TPC_Drift",x,y,z,0,kTRUE,upar,3);
960       gGeoManager->Node("TPC_Rod",i+55,"TPC_Drift",x,y,-z,0,kTRUE,upar,3);
961     }
962   }
963
964   TGeoVolume *alice = gGeoManager->GetVolume("ALIC");
965   alice->AddNode(v1,1);  
966   
967 } // end of function
968  
969 //_____________________________________________________________________________
970 void AliTPCv4::AddAlignableVolumes() const
971 {
972   //
973   // Create entries for alignable volumes associating the symbolic volume
974   // name with the corresponding volume path. Needs to be syncronized with
975   // eventual changes in the geometry.
976   // 
977   SetInnerChambersAlignable();
978   SetOuterChambersAlignable();
979 }
980  
981 //_____________________________________________________________________________
982 void AliTPCv4::SetInnerChambersAlignable() const
983 {
984   //
985   Int_t modnum = 0;
986   TString vpstr1 = "ALIC_1/TPC_M_1/TPC_Drift_1/TPC_ENDCAP_1/TPC_SECT_";
987   TString vpstr2 = "ALIC_1/TPC_M_1/TPC_Drift_1/TPC_ENDCAP_2/TPC_SECT_";
988   TString vpappend = "/TPC_IROC_1";
989   TString snstr1="TPC/EndcapA/Sector";
990   TString snstr2="TPC/EndcapC/Sector";
991   TString snappend="/InnerChamber";
992   TString volpath, symname;
993   
994   for(Int_t cnt=1; cnt<=18; cnt++){
995     volpath = vpstr1;
996     volpath += cnt;
997     volpath += vpappend;
998     symname = snstr1;
999     symname += cnt;
1000     symname += snappend;
1001     if(!gGeoManager->SetAlignableEntry(symname.Data(),volpath.Data()))
1002       AliFatal(Form("Alignable entry %s not created. Volume path %s not valid", symname.Data(),volpath.Data()));
1003     //
1004     TGeoPNEntry *alignableEntry = gGeoManager->GetAlignableEntry(symname.Data());
1005     const char *path = alignableEntry->GetTitle();
1006     if (!gGeoManager->cd(path))
1007       AliFatal(Form("Volume path %s not valid!",path));
1008     TGeoHMatrix* globMatrix = gGeoManager->GetCurrentMatrix();
1009     TGeoHMatrix* matTtoL = fTPCParam->Tracking2LocalMatrix(globMatrix,cnt-1);
1010     alignableEntry->SetMatrix(matTtoL);
1011     modnum++;
1012   }
1013
1014   for(Int_t cnt=1; cnt<=18; cnt++){
1015     volpath = vpstr2;
1016     volpath += cnt;
1017     volpath += vpappend;
1018     symname = snstr2;
1019     symname += cnt;
1020     symname += snappend;
1021     if(!gGeoManager->SetAlignableEntry(symname.Data(),volpath.Data()))
1022       AliFatal(Form("Alignable entry %s not created. Volume path %s not valid", symname.Data(),volpath.Data()));
1023     TGeoPNEntry *alignableEntry = gGeoManager->GetAlignableEntry(symname.Data());
1024     const char *path = alignableEntry->GetTitle();
1025     if (!gGeoManager->cd(path))
1026       AliFatal(Form("Volume path %s not valid!",path));
1027     TGeoHMatrix* globMatrix = gGeoManager->GetCurrentMatrix();
1028     TGeoHMatrix* matTtoL = fTPCParam->Tracking2LocalMatrix(globMatrix,18+cnt-1);
1029     alignableEntry->SetMatrix(matTtoL);
1030     modnum++;
1031   }
1032 }
1033
1034 //_____________________________________________________________________________
1035 void AliTPCv4::SetOuterChambersAlignable() const
1036 {
1037   //
1038   Int_t modnum = 0;
1039   TString vpstr1 = "ALIC_1/TPC_M_1/TPC_Drift_1/TPC_ENDCAP_1/TPC_SECT_";
1040   TString vpstr2 = "ALIC_1/TPC_M_1/TPC_Drift_1/TPC_ENDCAP_2/TPC_SECT_";
1041   TString vpappend = "/TPC_OROC_1";
1042   TString snstr1="TPC/EndcapA/Sector";
1043   TString snstr2="TPC/EndcapC/Sector";
1044   TString snappend="/OuterChamber";
1045   TString volpath, symname;
1046   
1047   for(Int_t cnt=1; cnt<=18; cnt++){
1048     volpath = vpstr1;
1049     volpath += cnt;
1050     volpath += vpappend;
1051     symname = snstr1;
1052     symname += cnt;
1053     symname += snappend;
1054     if(!gGeoManager->SetAlignableEntry(symname.Data(),volpath.Data()))
1055       AliFatal(Form("Alignable entry %s not created. Volume path %s not valid", symname.Data(),volpath.Data()));
1056     TGeoPNEntry *alignableEntry = gGeoManager->GetAlignableEntry(symname.Data());
1057     const char *path = alignableEntry->GetTitle();
1058     if (!gGeoManager->cd(path))
1059       AliFatal(Form("Volume path %s not valid!",path));
1060     TGeoHMatrix* globMatrix = gGeoManager->GetCurrentMatrix();
1061     TGeoHMatrix* matTtoL = fTPCParam->Tracking2LocalMatrix(globMatrix,36+cnt-1);
1062     alignableEntry->SetMatrix(matTtoL);
1063     modnum++;
1064   }
1065
1066   for(Int_t cnt=1; cnt<=18; cnt++){
1067     volpath = vpstr2;
1068     volpath += cnt;
1069     volpath += vpappend;
1070     symname = snstr2;
1071     symname += cnt;
1072     symname += snappend;
1073     if(!gGeoManager->SetAlignableEntry(symname.Data(),volpath.Data()))
1074       AliFatal(Form("Alignable entry %s not created. Volume path %s not valid", symname.Data(),volpath.Data()));
1075      TGeoPNEntry *alignableEntry = gGeoManager->GetAlignableEntry(symname.Data());
1076     const char *path = alignableEntry->GetTitle();
1077     if (!gGeoManager->cd(path))
1078       AliFatal(Form("Volume path %s not valid!",path));
1079     TGeoHMatrix* globMatrix = gGeoManager->GetCurrentMatrix();
1080     TGeoHMatrix* matTtoL = fTPCParam->Tracking2LocalMatrix(globMatrix,36+18+cnt-1);
1081     alignableEntry->SetMatrix(matTtoL);
1082     modnum++;
1083   }
1084 }
1085
1086 //_____________________________________________________________________________
1087 void AliTPCv4::DrawDetector() const
1088 {
1089   //
1090   // Draw a shaded view of the Time Projection Chamber version 1
1091   //
1092
1093   // Set everything unseen
1094   gMC->Gsatt("*", "seen", -1);
1095   // 
1096   // Set ALIC mother transparent
1097   gMC->Gsatt("ALIC","SEEN",0);
1098   //
1099   // Set the volumes visible
1100   //
1101
1102   gMC->Gsatt("TPC ","SEEN",0);
1103   gMC->Gsatt("TOIN","SEEN",1);
1104   gMC->Gsatt("TOIN","COLO",7);
1105   gMC->Gsatt("TOCV","SEEN",1);
1106   gMC->Gsatt("TOCV","COLO",4);
1107   gMC->Gsatt("TSA1","SEEN",0);
1108   gMC->Gsatt("TSA2","SEEN",0);
1109   gMC->Gsatt("TSA3","SEEN",0);
1110   gMC->Gsatt("TSA4","SEEN",0);  
1111   gMC->Gsatt("TSA5","SEEN",0);
1112   gMC->Gsatt("TOFC","SEEN",1);
1113   gMC->Gsatt("TOFC","COLO",4);
1114   gMC->Gsatt("TSA6","SEEN",0);
1115   gMC->Gsatt("TSA7","SEEN",0);
1116   gMC->Gsatt("TSA8","SEEN",0);    
1117   gMC->Gsatt("TIIN","SEEN",1);
1118   gMC->Gsatt("TIIN","COLO",7);
1119   gMC->Gsatt("TII1","SEEN",0);
1120   gMC->Gsatt("TIFC","SEEN",1);
1121   gMC->Gsatt("TIFC","COLO",4);
1122   gMC->Gsatt("TSA9","SEEN",0); 
1123   gMC->Gsatt("TS10","SEEN",0);
1124   gMC->Gsatt("TS11","SEEN",0);
1125   gMC->Gsatt("TS12","SEEN",0);
1126   gMC->Gsatt("TS13","SEEN",0);
1127   gMC->Gsatt("TS14","SEEN",0);
1128   gMC->Gsatt("TICC","SEEN",0);
1129   gMC->Gsatt("TICM","SEEN",0);
1130   gMC->Gsatt("TS15","SEEN",0);
1131   gMC->Gsatt("TS16","SEEN",0);
1132   gMC->Gsatt("TS17","SEEN",0);
1133   gMC->Gsatt("TS18","SEEN",0);  
1134   gMC->Gsatt("TS19","SEEN",0); 
1135   gMC->Gsatt("TPJ1","SEEN",0);
1136   gMC->Gsatt("TPJ2","SEEN",0);
1137   gMC->Gsatt("TICS","SEEN",0);
1138   gMC->Gsatt("TDGN","SEEN",0); 
1139   gMC->Gsatt("TIRC","SEEN",0);
1140   gMC->Gsatt("TIC1","SEEN",1);
1141   gMC->Gsatt("TIPP","SEEN",0);
1142   gMC->Gsatt("TIC3","SEEN",0);
1143   gMC->Gsatt("TRCE","SEEN",0);
1144   gMC->Gsatt("TPSC","SEEN",0);
1145   gMC->Gsatt("TPCC","SEEN",0); 
1146   gMC->Gsatt("TORC","SEEN",0);
1147   gMC->Gsatt("TOPP","SEEN",0);
1148   gMC->Gsatt("TOC3","SEEN",0);
1149   gMC->Gsatt("TOC1","SEEN",1);
1150   gMC->Gsatt("TSSW","SEEN",1);
1151   gMC->Gsatt("TSWC","SEEN",1);
1152   gMC->Gsatt("TSSW","COLO",3);
1153   gMC->Gsatt("TSWC","COLO",3);
1154   gMC->Gsatt("TSCE","COLO",6);
1155   gMC->Gsatt("TSCE","SEEN",1);
1156   gMC->Gsatt("TWES","SEEN",0);
1157   gMC->Gsatt("TSWB","SEEN",0);
1158   gMC->Gsatt("TPEL","SEEN",0);
1159   gMC->Gsatt("TPMW","SEEN",1);
1160   gMC->Gsatt("TESR","SEEN",1);
1161   gMC->Gsatt("TPMW","COLO",12);
1162   gMC->Gsatt("TIC1","COLO",5);
1163   gMC->Gsatt("TOC1","COLO",5);
1164   gMC->Gsatt("TESB","SEEN",0);
1165   gMC->Gsatt("THVM","SEEN",1);
1166   gMC->Gsatt("THVM","COLO",11);
1167   gMC->Gsatt("THVH","SEEN",0);
1168   gMC->Gsatt("TPSR","SEEN",0); 
1169   gMC->Gsatt("THVL","SEEN",0);
1170   gMC->Gsatt("THVC","SEEN",0);  
1171   gMC->Gsatt("THVE","SEEN",0);
1172   gMC->Gsatt("THVR","SEEN",0);
1173   gMC->Gsatt("TPSS","SEEN",0);
1174   gMC->Gsatt("TPUS","SEEN",0);
1175   gMC->Gsatt("TPLS","SEEN",0);
1176
1177   //
1178   gMC->Gdopt("hide", "on");
1179   gMC->Gdopt("shad", "on");
1180   gMC->Gsatt("*", "fill", 7);
1181   gMC->SetClipBox(".");
1182   gMC->SetClipBox("TPMW",-300,300,-300,300,254.,270.);
1183   gMC->SetClipBox("TESR",-300,300,-300,300,254.,270.);
1184   gMC->SetClipBox("TSSW",-300,300,-300,300,283.,284.);
1185   gMC->SetClipBox("TSWC",-300,300,-300,300,283.,284.);
1186   gMC->SetClipBox("*", 0, 300, -300, 300, -290, 290);
1187   gMC->DefaultRange();
1188   gMC->Gdraw("alic", 40, 30, 0, 12, 9.5, .025, .025);
1189   gMC->Gdhead(1111, "Time Projection Chamber");
1190   gMC->Gdman(18, 4, "MAN");
1191   gMC->Gdopt("hide","off");
1192 }
1193
1194 //_____________________________________________________________________________
1195 void AliTPCv4::CreateMaterials()
1196 {
1197   //
1198   // Define materials for version 2 of the Time Projection Chamber
1199   //
1200  
1201   AliTPC::CreateMaterials();
1202 }
1203
1204 //_____________________________________________________________________________
1205 void AliTPCv4::Init()
1206 {
1207   //
1208   // Initialises version 2 of the TPC after that it has been built
1209   //
1210
1211   Int_t *idtmed = fIdtmed->GetArray();
1212   
1213   AliTPC::Init();
1214
1215  
1216   fIdSens=gMC->VolId("TPC_Strip");  // one strip is always selected...
1217
1218   fIDrift=gMC->VolId("TPC_Drift");
1219   fSecOld=-100; // fake number 
1220
1221   gMC->SetMaxNStep(-30000); // max. number of steps increased
1222
1223   gMC->Gstpar(idtmed[20],"LOSS",6); // specific energy loss
1224
1225   AliInfo("*** TPC version 4 initialized ***");
1226   AliInfo(Form("Maximum number of steps = %d",gMC->GetMaxNStep()));
1227
1228   //
1229   
1230 }
1231
1232 //_____________________________________________________________________________
1233 void AliTPCv4::StepManager()
1234 {
1235   //
1236   // Called for every step in the Time Projection Chamber
1237   //
1238
1239   //
1240   // parameters used for the energy loss calculations
1241   //
1242   const Float_t kprim = 14.35; // number of primary collisions per 1 cm
1243   const Float_t kpoti = 20.77e-9; // first ionization potential for Ne/CO2
1244   const Float_t kwIon = 35.97e-9; // energy for the ion-electron pair creation 
1245  
1246  
1247   const Float_t kbig = 1.e10;
1248
1249   Int_t id,copy;
1250   Float_t hits[5];
1251   Int_t vol[2];  
1252   TLorentzVector p;
1253   
1254   vol[1]=0; // preset row number to 0
1255   //
1256   gMC->SetMaxStep(kbig);
1257   
1258   
1259   
1260   Float_t charge = gMC->TrackCharge();
1261   
1262   if(TMath::Abs(charge)<=0.) return; // take only charged particles
1263   
1264   // check the sensitive volume
1265
1266   id = gMC->CurrentVolID(copy); // vol ID and copy number (starts from 1!)
1267   if(id != fIDrift && id != fIdSens) return; // not in the sensitive folume 
1268
1269   gMC->TrackPosition(p);
1270   Double_t r = TMath::Sqrt(p[0]*p[0]+p[1]*p[1]);
1271   //
1272   
1273   //
1274   Double_t angle = TMath::ACos(p[0]/r);  
1275   angle = (p[1]<0.) ? TMath::TwoPi()-angle : angle;
1276   //
1277   // angular segment, it is not a real sector number...
1278   //
1279   Int_t sector=TMath::Nint((angle-fTPCParam->GetInnerAngleShift())/
1280                fTPCParam->GetInnerAngle());
1281   // rotate to segment "0"
1282   Float_t cos,sin;
1283   fTPCParam->AdjustCosSin(sector,cos,sin);
1284   Float_t x1=p[0]*cos + p[1]*sin;
1285   // check if within sector's limits
1286   if((x1>=fTPCParam->GetInnerRadiusLow()&&x1<=fTPCParam->GetInnerRadiusUp())
1287      ||(x1>=fTPCParam->GetOuterRadiusLow()&&x1<=fTPCParam->GetOuterRadiusUp())){
1288   // calculate real sector number...
1289   if (x1>fTPCParam->GetOuterRadiusLow()){
1290     sector = TMath::Nint((angle-fTPCParam->GetOuterAngleShift())/
1291              fTPCParam->GetOuterAngle())+fTPCParam->GetNInnerSector();
1292     if (p[2]<0)         sector+=(fTPCParam->GetNOuterSector()>>1);
1293   }
1294     else   
1295       if (p[2]<0) sector+=(fTPCParam->GetNInnerSector()>>1);  
1296   //
1297   // here I have a sector number
1298   //
1299
1300   vol[0]=sector;
1301   // check if change of sector
1302   if(sector != fSecOld){
1303     fSecOld=sector;
1304     // add track reference
1305     AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber());
1306   }  
1307   // track is in the sensitive strip
1308   if(id == fIdSens){
1309     // track is entering the strip
1310     if (gMC->IsTrackEntering()){
1311       Int_t totrows = fTPCParam->GetNRowLow()+fTPCParam->GetNRowUp();
1312       vol[1] = (copy<=totrows) ? copy-1 : copy-1-totrows;
1313       // row numbers are autonomous for lower and upper sectors
1314       if(vol[0] > fTPCParam->GetNInnerSector()) {
1315         vol[1] -= fTPCParam->GetNRowLow();
1316       }
1317     //
1318       if(vol[0]<fTPCParam->GetNInnerSector()&&vol[1] == 0){
1319   
1320         // lower sector, row 0, because Jouri wants to have this
1321
1322         gMC->TrackMomentum(p);
1323         hits[0]=p[0];
1324         hits[1]=p[1];
1325         hits[2]=p[2];
1326         hits[3]=0.; // this hit has no energy loss
1327         // Get also the track time for pileup simulation
1328         hits[4]=gMC->TrackTime();
1329
1330         AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol,hits);  
1331       }
1332     //
1333
1334        gMC->TrackPosition(p);
1335        hits[0]=p[0];
1336        hits[1]=p[1];
1337        hits[2]=p[2];
1338        hits[3]=0.; // this hit has no energy loss
1339        // Get also the track time for pileup simulation
1340        hits[4]=gMC->TrackTime();
1341
1342        AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol,hits);  
1343     
1344     }
1345     else return;
1346   }  
1347   //-----------------------------------------------------------------
1348   //  charged particle is in the sensitive drift volume
1349   //-----------------------------------------------------------------
1350
1351   if(gMC->TrackStep() > 0){ 
1352
1353     Int_t nel = (Int_t)(((gMC->Edep())-kpoti)/kwIon) + 1;
1354     nel=TMath::Min(nel,30); // 30 electrons corresponds to 1 keV
1355     //
1356     gMC->TrackPosition(p);
1357     hits[0]=p[0];
1358     hits[1]=p[1];
1359     hits[2]=p[2];
1360     hits[3]=(Float_t)nel;
1361
1362     // Add this hit
1363
1364     if (fHitType&&2){
1365       gMC->TrackMomentum(p);
1366       Float_t momentum = TMath::Sqrt(p[0]*p[0]+p[1]*p[1]);
1367       Float_t precision =   (momentum>0.1) ? 0.002 :0.01;
1368       fTrackHits->SetHitPrecision(precision);
1369     }
1370
1371     // Get also the track time for pileup simulation
1372     hits[4]=gMC->TrackTime();
1373  
1374     AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol,hits);
1375
1376   } // step>0 
1377   } //within sector's limits
1378   // Stemax calculation for the next step
1379   if(!gMC->IsTrackAlive()) return; // particle has disappeared
1380   Float_t pp;
1381   TLorentzVector mom;
1382   gMC->TrackMomentum(mom);
1383   Float_t ptot=mom.Rho();
1384   Float_t betaGamma = ptot/gMC->TrackMass();
1385   
1386   Int_t pid=gMC->TrackPid();
1387   if((pid==kElectron || pid==kPositron) && ptot > 0.002)
1388     { 
1389       pp = kprim*1.58; // electrons above 20 MeV/c are on the plateau!
1390     }
1391   else
1392     {
1393
1394       betaGamma = TMath::Max(betaGamma,(Float_t)7.e-3); // protection against too small bg
1395       pp=kprim*AliMathBase::BetheBlochAleph(betaGamma); 
1396    
1397       if(TMath::Abs(charge) > 1.) pp *= (charge*charge);
1398     }
1399   
1400   Double_t rnd = gMC->GetRandom()->Rndm();
1401   
1402   gMC->SetMaxStep(-TMath::Log(rnd)/pp);
1403   
1404   
1405 }
1406