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