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