New TPC geometry.
[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 /*
17 $Log$
18 Revision 1.34  2001/04/23 10:20:18  hristov
19 Constant casted to avoid ambiguity
20
21 Revision 1.33  2001/04/20 08:16:47  kowal2
22 Protection against too small betaGamma. Thanks to Ivana and Yves.
23
24 Revision 1.32  2001/03/13 13:07:34  kowal2
25 Corrected bug in the TPC mother volume geometry.
26 Thanks to A. Morsch
27
28 Revision 1.31  2000/11/30 11:48:50  kowal2
29 TLorentzVector.h adde to satisfy the latest changes by Federico
30
31 Revision 1.30  2000/11/14 10:48:57  kowal2
32 Correct material used for TSA4. Thanks to J. Barbosa.
33
34 Revision 1.29  2000/11/06 17:24:10  kowal2
35 Corrected bug in the outer containment vessel and
36 the outer field cage geometry.
37 Thanks to J. Barbosa.
38
39 Revision 1.28  2000/11/02 16:55:24  kowal2
40 Corrected bug in the inner containment vessel geometry.
41 Thanks to J. Belikov
42
43 Revision 1.27  2000/11/02 07:24:11  kowal2
44 Correction in the TPC geometry.
45 Changes due to the new hit structure.
46
47 Revision 1.26  2000/10/05 16:16:29  kowal2
48 Corrections of the hit recording algorithm.
49
50 Revision 1.25  2000/10/02 21:28:18  fca
51 Removal of useless dependecies via forward declarations
52
53 Revision 1.24  2000/08/28 10:02:30  kowal2
54 Corrected bug in the StepManager
55
56 Revision 1.23  2000/07/10 20:57:39  hristov
57 Update of TPC code and macros by M.Kowalski
58
59 Revision 1.22  2000/06/30 12:07:50  kowal2
60 Updated from the TPC-PreRelease branch
61
62 Revision 1.21.2.4  2000/06/26 07:39:42  kowal2
63 Changes to obey the coding rules
64
65 Revision 1.21.2.3  2000/06/25 08:38:41  kowal2
66 Splitted from AliTPCtracking
67
68 Revision 1.21.2.2  2000/06/16 12:58:13  kowal2
69 Changed parameter settings
70
71 Revision 1.21.2.1  2000/06/09 07:15:07  kowal2
72
73 Defaults loaded automatically (hard-wired)
74 Optional parameters can be set via macro called in the constructor
75
76 Revision 1.21  2000/05/15 10:00:30  kowal2
77 Corrected bug in the TPC geometry, thanks to Ivana Hrivnacova
78
79 Revision 1.20  2000/04/17 09:37:33  kowal2
80 removed obsolete AliTPCDigitsDisplay.C
81
82 Revision 1.19.8.2  2000/04/10 08:31:52  kowal2
83
84 Different geometry for different sectors
85 Updated readout chambers
86 Some modifications to StepManager by J.Belikov
87
88 Revision 1.19.8.1  2000/04/10 07:56:53  kowal2
89 Not used anymore - removed
90
91 Revision 1.19  1999/11/04 17:28:07  fca
92 Correct barrel part of HV Degrader
93
94 Revision 1.18  1999/10/14 16:52:08  fca
95 Only use PDG codes and not GEANT ones
96
97 Revision 1.17  1999/10/08 06:27:23  fca
98 Corrected bug in the HV degrader geometry, thanks to G.Tabary
99
100 Revision 1.16  1999/10/04 13:39:54  fca
101 Correct array index problem
102
103 Revision 1.15  1999/09/29 09:24:34  fca
104 Introduction of the Copyright and cvs Log
105
106 */
107
108 //
109 ///////////////////////////////////////////////////////////////////////////////
110 //                                                                           //
111 //  Time Projection Chamber version 2 -- detailed TPC and slow simulation    //
112 //                                                                           //
113 //Begin_Html
114 /*
115 <img src="picts/AliTPCv2Class.gif">
116 */
117 //End_Html
118 //                                                                           //
119 //                                                                           //
120 ///////////////////////////////////////////////////////////////////////////////
121 #include <stdlib.h>
122
123 #include <TMath.h>
124
125 #include "AliTPCv2.h"
126 #include "AliTPCDigitsArray.h"
127 #include "AliRun.h"
128 #include "AliMC.h"
129 #include "AliConst.h"
130 #include "AliPDG.h"
131 #include "AliTPCParam.h"
132 #include "AliTPCParamSR.h"
133 #include "AliTPCTrackHits.h"
134 #include "TLorentzVector.h"
135
136
137 ClassImp(AliTPCv2)
138  
139 //_____________________________________________________________________________
140 AliTPCv2::AliTPCv2(const char *name, const char *title) :
141   AliTPC(name, title) 
142 {
143   //
144   // Standard constructor for Time Projection Chamber version 2
145   //
146   fIdSens=0;
147   fIdLSec=0;
148   fIdUSec=0;
149
150   SetBufferSize(128000);
151
152   SetGasMixt(2,20,10,-1,0.9,0.1,0.); // Ne-CO2 90-10
153
154   // Default sectors
155
156   SetSecAL(4);
157   SetSecAU(4);
158   SetSecLows(1,  2,  3, 19, 20, 21);
159   SetSecUps(37, 38, 39, 37+18, 38+18, 39+18, -1, -1, -1, -1, -1, -1);
160   SetSens(1); // sensitive strips set 
161
162   if (fTPCParam)
163      fTPCParam->Write(fTPCParam->GetTitle());
164 }
165  
166 //_____________________________________________________________________________
167 void AliTPCv2::CreateGeometry()
168 {
169   //
170   // Create the geometry of Time Projection Chamber version 2
171   //
172   //Begin_Html
173   /*
174     <img src="picts/AliTPC.gif">
175   */
176   //End_Html
177   //Begin_Html
178   /*
179     <img src="picts/AliTPCv2Tree.gif">
180   */
181   //End_Html
182
183
184   Int_t *idtmed = fIdtmed->GetArray();
185
186   Float_t dm[50];
187   Int_t idrotm[120];
188
189   Int_t nRotMat = 0;
190
191   Int_t i,ifl1=0;
192
193   // number of sectors
194
195   Int_t nInnerSector = fTPCParam->GetNInnerSector()/2;
196   Int_t nOuterSector = fTPCParam->GetNOuterSector()/2;
197   
198   // --------------------------------------------------- 
199   //        sector specification check 
200   // --------------------------------------------------- 
201   if (fSecAL >= 0) {
202     ifl1 = 0;
203     
204     for (i = 0; i < 6; ++i) {
205       if (fSecLows[i] >= 0 && fSecLows[i] < 2*nInnerSector) {
206         ifl1 = 1;
207         printf("*** SECTOR %d selected\n",fSecLows[i]);
208       }
209     }
210
211   } else {
212     printf("*** ALL LOWER SECTORS SELECTED ***\n");
213     ifl1 = 1;
214   }
215
216   if (ifl1 == 0) {
217     printf("*** ERROR: AT LEAST ONE LOWER SECTOR MUST BE SPECIFIED ***\n");
218     printf("!!! PROGRAM STOPPED !!!\n");
219     exit(1);
220   }
221
222   if (fSecAU >= 0) {
223     
224     for (i = 0; i < 12; ++i) {
225       if (fSecUps[i] > 2*nInnerSector-1 && 
226           fSecUps[i] < 2*(nInnerSector+nOuterSector)) {
227         printf("*** SECTOR %d selected\n",fSecUps[i]);
228       }
229     }
230     
231   } else {
232     printf("*** ALL UPPER SECTORS SELECTED ***\n");
233   }
234   
235  
236
237   //--------------------------------------------------------------------
238
239   //
240   //  Mother volume TPC (Air) - all volumes will be positioned in it
241   //
242
243   dm[0]=0.;
244   dm[1]=360.;
245   dm[2]=8.;
246
247   //
248
249   dm[3]=-283.7;
250   dm[4]=65.6;
251   dm[5]=278.;
252
253   //
254
255   dm[6]=-253.6;
256   dm[7]=65.6;
257   dm[8]=278.;
258
259   //
260
261   dm[9]=-73.3;
262   dm[10]=60.9;
263   dm[11]=278.;  
264
265   //
266
267   dm[12]=-73.3;
268   dm[13]=56.9;
269   dm[14]=278.;
270
271   //
272
273   dm[15]=73.3;
274   dm[16]=56.9;
275   dm[17]=278.;
276
277   //
278
279   dm[18]=73.3;
280   dm[19]=60.9;
281   dm[20]=278.;
282
283   //
284
285   dm[21]=253.6;
286   dm[22]=65.6;
287   dm[23]=278.;
288
289   //
290
291   dm[24]=283.7;
292   dm[25]=65.6;
293   dm[26]=278.;
294   
295   gMC->Gsvolu("TPC ","PCON",idtmed[0],dm,27);
296
297   // outer part
298
299   //-------------------------------------------------------------------
300   //   Tpc Outer INsulator (CO2) - contains cont. vessel and field cage
301   //-------------------------------------------------------------------
302
303   dm[0]= 0.;
304   dm[1]= 360.;
305   dm[2]= 6.;
306
307   //
308
309   dm[3]=-253.6;
310   dm[4]=258.;
311   dm[5]=275.5;
312
313   //
314
315   dm[6]=-250.6;
316   dm[7]=258.;
317   dm[8]=275.5; 
318
319   //
320
321   dm[9]=-250.6;
322   dm[10]=258.;
323   dm[11]=278.;
324
325   //
326
327   dm[12]=253.6;
328   dm[13]=258.;
329   dm[14]=278.; 
330
331   //
332
333   dm[15]=253.6;
334   dm[16]=264.8;
335   dm[17]=278.;  
336
337   //
338
339   dm[18]=256.6;
340   dm[19]=264.8;
341   dm[20]=278.;
342
343   gMC->Gsvolu("TOIN","PCON",idtmed[3],dm,21);
344
345   //----------------------------------------------------------------
346   // Tpc Outer Contaiment Vessel  
347   //  mother volume - Al, daughters - composite (sandwich)
348   //----------------------------------------------------------------
349
350   dm[0]=0.;
351   dm[1]=360.;
352   dm[2]=6.;
353
354   //
355
356   dm[3]=-250.6;
357   dm[4]=270.4;
358   dm[5]=278.;
359
360   //
361
362   dm[6]=-247.6;
363   dm[7]=270.4;
364   dm[8]=278.; 
365
366   //
367
368   dm[9]=-247.6;
369   dm[10]=274.81;
370   dm[11]=278.;
371
372   //
373
374   dm[12]=253.6;
375   dm[13]=274.81;
376   dm[14]=278.;
377
378   //
379
380   dm[15]=253.6;
381   dm[16]=264.8;
382   dm[17]=278.;
383
384   //
385
386   dm[18]=256.6;
387   dm[19]=264.8;
388   dm[20]=278.;
389
390   gMC->Gsvolu("TOCV","PCON",idtmed[4],dm,21);
391
392   // Daughter volumes - sandwich
393
394   // Tpc SAndwich 1 - Al
395
396   dm[0]=274.81;
397   dm[1]=278.;
398   dm[2]=252.1;
399
400   gMC->Gsvolu("TSA1","TUBE",idtmed[4],dm,3);
401
402   // Tpc SAndwich 2 - epoxy glue (I use Lexan)
403
404   dm[0] += 5.e-3;
405   dm[1] -= 5.e-3;
406
407   gMC->Gsvolu("TSA2","TUBE",idtmed[14],dm,3);
408
409   // Tpc SAndwich 3 - Tedlar
410
411   dm[0] += 0.01;
412   dm[1] -= 0.01;
413   
414   gMC->Gsvolu("TSA3","TUBE",idtmed[9],dm,3);
415
416
417   // Tpc SAndwich 4 - fiber glass (G10)
418
419   dm[0] += 5.e-3;
420   dm[1] -= 5.e-3;
421
422   gMC->Gsvolu("TSA4","TUBE",idtmed[12],dm,3);  
423
424   // Tpc SAndwich 5 - NOMEX honeycomb
425
426   dm[0] += 0.075;
427   dm[1] -= 0.075;   
428   
429   gMC->Gsvolu("TSA5","TUBE",idtmed[6],dm,3);
430
431   // 5->4->3->2->1->TCOV
432
433
434   gMC->Gspos("TSA5",1,"TSA4",0.,0.,0.,0,"ONLY");
435   gMC->Gspos("TSA4",1,"TSA3",0.,0.,0.,0,"ONLY");
436   gMC->Gspos("TSA3",1,"TSA2",0.,0.,0.,0,"ONLY");
437   gMC->Gspos("TSA2",1,"TSA1",0.,0.,0.,0,"ONLY");  
438
439   gMC->Gspos("TSA1",1,"TOCV",0.,0.,3.,0,"ONLY");
440
441   // TCOV-> TOIN
442
443   gMC->Gspos("TOCV",1,"TOIN",0.,0.,0.,0,"ONLY");
444
445   //-------------------------------------------------------
446   //  Tpc Outer Field Cage
447   //  mother volume - Al, daughters - composite (sandwich)
448   //-------------------------------------------------------
449
450   dm[0]=0.;
451   dm[1]=360.;
452   dm[2]=6.;
453
454   //
455
456   dm[3]=-253.6;
457   dm[4]=258.;
458   dm[5]=275.5;
459
460   //
461
462   dm[6]=-250.6;
463   dm[7]=258.;
464   dm[8]=275.5;
465
466   //
467
468   dm[9]=-250.6;
469   dm[10]=258.;
470   dm[11]=260.05;
471
472   //
473
474   dm[12]=250.6;
475   dm[13]=258.;
476   dm[14]=260.05;
477
478   //
479
480   dm[15]=250.6;
481   dm[16]=258.;
482   dm[17]=275.5;
483
484   //
485
486   dm[18]=253.6;
487   dm[19]=258.;
488   dm[20]=275.5;
489
490   gMC->Gsvolu("TOFC","PCON",idtmed[4],dm,21);
491
492   // Daughter volumes 
493
494   // Tpc SAndwich 6 - Tedlar
495
496   dm[0]= 258.;
497   dm[1]= 260.05;
498   dm[2]= 252.1;
499
500   gMC->Gsvolu("TSA6","TUBE",idtmed[9],dm,3);
501
502   // Tpc SAndwich 7 - fiber glass
503
504   dm[0] += 5.e-3;
505   dm[1] -= 5.e-3;
506
507   gMC->Gsvolu("TSA7","TUBE",idtmed[12],dm,3);
508
509
510   // Tpc SAndwich 8 - NOMEX
511
512   dm[0] += 0.02;
513   dm[1] -= 0.02;
514
515   gMC->Gsvolu("TSA8","TUBE",idtmed[6],dm,3);    
516
517   // 8->7->6->TOFC
518
519   gMC->Gspos("TSA8",1,"TSA7",0.,0.,0.,0,"ONLY");
520   gMC->Gspos("TSA7",1,"TSA6",0.,0.,0.,0,"ONLY"); 
521   gMC->Gspos("TSA6",1,"TOFC",0.,0.,0.,0,"ONLY");
522
523   // TOFC->TOIN
524
525   gMC->Gspos("TOFC",1,"TOIN",0.,0.,0.,0,"ONLY");
526
527   // TOIN->TPC
528
529   gMC->Gspos("TOIN",1,"TPC ",0.,0.,0.,0,"ONLY");
530
531   // inner part
532
533   //--------------------------------------------------------------------
534   // Tpc Inner INsulator (CO2) - inner f.c. will be placed there
535   // Inner containment vessel will be placed directly in the TPC
536   //-------------------------------------------------------------------- 
537
538   dm[0]=0.;
539   dm[1]=360.;
540   dm[2]=4.;
541
542   // 
543
544   dm[3]=-253.6;
545   dm[4]=65.9;
546   dm[5]=79.2;
547
548   //
549
550   dm[6]=-73.3;
551   dm[7]=61.2;
552   dm[8]=79.2;  
553
554   //
555
556   dm[9]=73.3;
557   dm[10]=61.2;
558   dm[11]=79.2;
559
560   //
561
562   dm[12]=253.6;
563   dm[13]=65.9;
564   dm[14]=79.2;
565
566   gMC->Gsvolu("TIIN","PCON",idtmed[3],dm,15);
567
568   // the middle part of the F.C. is thinner - carve out the strip - Ne-CO2
569
570   dm[0]=79.16;
571   dm[1]=79.2;
572   dm[2]=88.;
573
574   gMC->Gsvolu("TII1","TUBE",idtmed[1],dm,3);
575
576   gMC->Gspos("TII1",1,"TIIN",0.,0.,0.,0,"ONLY");
577
578   //-----------------------------------------------------
579   // Tpc Inner Field Cage
580   // mother volume - Al, daughters - composite (sandwich)
581   //------------------------------------------------------
582
583   dm[0]=0.;
584   dm[1]=360.;
585   dm[2]=10.;
586
587   //
588
589   dm[3]=-253.6;
590   dm[4]=70.3;
591   dm[5]=79.2;
592
593   //
594
595   dm[6]=-250.6;
596   dm[7]=70.3;
597   dm[8]=79.2;
598
599   //
600
601   dm[9]=-250.6;
602   dm[10]=77.05;
603   dm[11]=79.2;
604
605   //
606
607   dm[12]=-88.;
608   dm[13]=77.05;
609   dm[14]=79.2;
610
611   //
612
613   dm[15]=-88.;
614   dm[16]=77.09;
615   dm[17]=79.16;
616
617   //
618
619   dm[18]=88.;
620   dm[19]=77.09;
621   dm[20]=79.16;
622
623   //
624
625   dm[21]=88.;
626   dm[22]=77.05;
627   dm[23]=79.2;
628
629   //
630
631   dm[24]=250.6;
632   dm[25]=77.05;
633   dm[26]=79.2;
634
635   //
636
637   dm[27]=250.6;
638   dm[28]=70.3;
639   dm[29]=79.2;
640
641   //
642
643   dm[30]=253.6;
644   dm[31]=70.3;
645   dm[32]=79.2;
646
647   gMC->Gsvolu("TIFC","PCON",idtmed[4],dm,33);
648
649   // daughter volumes - central part
650
651   // Tpc Sandwich 9 -Tedlar
652
653   dm[0]=77.09;
654   dm[1]=79.16;
655   dm[2]=88.;
656
657   gMC->Gsvolu("TSA9","TUBE",idtmed[9],dm,3); 
658
659   // Tpc Sandwich 10 - fiber glass (G10) 
660
661   dm[0] += 5.e-3;
662   dm[1] -= 5.e-3;
663
664   gMC->Gsvolu("TS10","TUBE",idtmed[12],dm,3);
665
666   // Tpc Sandwich 11 - NOMEX
667
668   dm[0] += 0.03;
669   dm[1] -= 0.03; 
670
671   gMC->Gsvolu("TS11","TUBE",idtmed[6],dm,3);
672
673   // 11->10->9->TIFC
674
675   gMC->Gspos("TS11",1,"TS10",0.,0.,0.,0,"ONLY");
676   gMC->Gspos("TS10",1,"TSA9",0.,0.,0.,0,"ONLY");
677
678   gMC->Gspos("TSA9",1,"TIFC",0.,0.,0.,0,"ONLY");
679
680   // daughter volumes - outer parts (reinforced)
681
682   // Tpc Sandwich 12 -Tedlar
683
684   dm[0]=77.05;
685   dm[1]=79.2;
686   dm[2]=82.05;
687
688   gMC->Gsvolu("TS12","TUBE",idtmed[9],dm,3);
689
690   // Tpc Sandwich 13 - fiber glass (G10) 
691
692   dm[0] += 5.e-3;
693   dm[1] -= 5.e-3;
694
695   gMC->Gsvolu("TS13","TUBE",idtmed[12],dm,3);
696
697   // Tpc Sandwich 14 - NOMEX
698
699   dm[0] += 0.07;
700   dm[1] -= 0.07;  
701
702   gMC->Gsvolu("TS14","TUBE",idtmed[6],dm,3);
703
704   // 14->13->12->TIFC
705
706   gMC->Gspos("TS14",1,"TS13",0.,0.,0.,0,"ONLY");
707   gMC->Gspos("TS13",1,"TS12",0.,0.,0.,0,"ONLY"); 
708
709   gMC->Gspos("TS12",1,"TIFC",0.,0.,170.05,0,"ONLY");
710   gMC->Gspos("TS12",2,"TIFC",0.,0.,-170.05,0,"ONLY"); 
711
712   // place this inside the inner insulator
713
714   gMC->Gspos("TIFC",1,"TIIN",0.,0.,0.,0,"ONLY");
715
716   // and now in the TPC...
717
718   gMC->Gspos("TIIN",1,"TPC ",0.,0.,0.,0,"ONLY");
719
720   //---------------------------------------------------------
721   // Tpc Inner Containment vessel - Cones
722   //---------------------------------------------------------
723
724   dm[0]=0.;
725   dm[1]=360.;
726   dm[2]=8.;
727
728   //
729
730   dm[3]=71.8;
731   dm[4]=56.9;
732   dm[5]=59.4;
733
734   //
735
736   dm[6]=73.;
737   dm[7]=56.9;
738   dm[8]=59.4;
739
740   //
741
742   dm[9]=73.;
743   dm[10]=56.9;
744   dm[11]=61.2;
745
746   //
747
748   dm[12]=73.3;
749   dm[13]=56.9;
750   dm[14]=61.2;
751
752   //
753    
754   dm[15]=73.3;
755   dm[16]=60.9;
756   dm[17]=61.2;
757
758   // 
759
760   dm[18]=253.6;
761   dm[19]=65.6;
762   dm[20]=65.9; 
763
764   //
765
766   dm[21]=253.6;
767   dm[22]=65.6;
768   dm[23]=76.4;
769
770   //
771
772   dm[24]=256.3;
773   dm[25]=65.6;
774   dm[26]=76.4;
775
776   gMC->Gsvolu("TICC","PCON",idtmed[4],dm,27);
777
778   Float_t phi1,phi2,phi3,theta1,theta2,theta3; // rotation angles
779
780   // reflection matrix
781   
782   theta1 = 90.;
783   phi1   = 0.;
784   theta2 = 90.;
785   phi2   = 270.;
786   theta3 = 180.;
787   phi3   = 0.;
788
789   AliMatrix(idrotm[nRotMat], theta1, phi1, theta2, phi2, theta3, phi3);
790
791   gMC->Gspos("TICC",1,"TPC ",0.,0.,0.,0,"ONLY");
792   gMC->Gspos("TICC",2,"TPC ",0.,0.,0.,idrotm[nRotMat],"ONLY");
793
794
795   //---------------------------------------------------------
796   // Tpc Inner Containment vessel - Middle part -Al
797   //---------------------------------------------------------
798
799   dm[0]=0.;
800   dm[1]=360.;
801   dm[2]=6.;
802
803   //
804
805   dm[3]=-71.6;
806   dm[4]=60.2;
807   dm[5]=61.2;
808
809   //
810
811   dm[6]=-69.1;
812   dm[7]=60.2;
813   dm[8]=61.2;
814
815   //
816
817   dm[9]=-69.1;
818   dm[10]=60.64;
819   dm[11]=61.2;  
820
821   //
822
823   dm[12]=69.1;
824   dm[13]=60.64;
825   dm[14]=61.2;
826
827   //
828
829   dm[15]=69.1;
830   dm[16]=60.2;
831   dm[17]=61.2;
832
833   //
834
835   dm[18]=71.6;
836   dm[19]=60.2;
837   dm[20]=61.2;
838
839   gMC->Gsvolu("TICM","PCON",idtmed[4],dm,21);
840
841   // Tpc Sandwich 15 - Al
842
843   dm[0]=60.64;
844   dm[1]=61.2;
845   dm[2]=70.1;
846
847   gMC->Gsvolu("TS15","TUBE",idtmed[4],dm,3);
848
849   // Tpc Sandwich 16 -  epoxy glue
850
851   dm[0] += 5.e-3;
852   dm[1] -= 5.e-3;
853
854   gMC->Gsvolu("TS16","TUBE",idtmed[14],dm,3);
855
856   // Tpc Sandwich 17 - Tedlar
857
858   dm[0] += 0.01;
859   dm[1] -= 0.01;
860
861   gMC->Gsvolu("TS17","TUBE",idtmed[9],dm,3);
862
863   // Tpc Sandwich 18 - fiber glass
864
865   dm[0] += 5.e-3;
866   dm[1] -= 5.e-3;
867
868   gMC->Gsvolu("TS18","TUBE",idtmed[12],dm,3);  
869
870   // Tpc Sandwich 19 - Nomex
871
872   dm[0] += 0.01;
873   dm[1] -= 0.01;
874
875   gMC->Gsvolu("TS19","TUBE",idtmed[12],dm,3); 
876
877   // 19->18->17->16->15-> TICM
878
879   gMC->Gspos("TS19",1,"TS18",0.,0.,0.,0,"ONLY"); 
880   gMC->Gspos("TS18",1,"TS17",0.,0.,0.,0,"ONLY");
881   gMC->Gspos("TS17",1,"TS16",0.,0.,0.,0,"ONLY");
882   gMC->Gspos("TS16",1,"TS15",0.,0.,0.,0,"ONLY");
883
884   gMC->Gspos("TS15",1,"TICM ",0.,0.,0.,0,"ONLY");
885  
886
887   // TPc inner cont. vessel Joints
888
889   dm[0]=60.2;
890   dm[1]=61.2;
891   dm[2]=0.5;
892
893   gMC->Gsvolu("TPJ1","TUBE",idtmed[4],dm,3);
894
895   gMC->Gspos("TPJ1",1,"TPC ",0.,0.,72.3,0,"ONLY");
896   gMC->Gspos("TPJ1",2,"TPC ",0.,0.,-72.3,0,"ONLY");
897
898   //
899
900   dm[0]=0.;
901   dm[1]=360.;
902   dm[2]=4.;
903
904   //
905
906   dm[3]=70.8;
907   dm[4]=58.4;
908   dm[5]=60.1;
909
910   //
911
912   dm[6]=71.2;
913   dm[7]=58.4;
914   dm[8]=60.1;
915
916   //
917
918   dm[9]=71.2;
919   dm[10]=58.4;
920   dm[11]=59.4;
921
922   //
923
924   dm[12]=71.6;
925   dm[13]=58.4;
926   dm[14]=59.4;
927
928   gMC->Gsvolu("TPJ2","PCON",idtmed[4],dm,15);
929
930   gMC->Gspos("TPJ2",1,"TPC ",0.,0.,0.,0,"ONLY");
931   gMC->Gspos("TPJ2",2,"TPC ",0.,0.,0.,idrotm[nRotMat],"ONLY");
932
933
934
935   // Tpc Inner Containment vessel Seal (Viton, I use Lexan for a time being)
936
937   dm[0]=58.4;
938   dm[1]=61.2;
939   dm[2]=0.1;
940
941   gMC->Gsvolu("TICS","TUBE",idtmed[14],dm,3);
942
943   gMC->Gspos("TICS",1,"TPC ",0.,0.,71.7,0,"ONLY");
944   gMC->Gspos("TICS",2,"TPC ",0.,0.,-71.7,0,"ONLY"); 
945
946   // TICM -> TPC
947
948   gMC->Gspos("TICM",1,"TPC ",0.,0.,0.,0,"ONLY");
949
950   //
951
952   nRotMat++; // prepare for the next rotation matrix 
953
954   //---------------------------------------------------------
955   //  Tpc Dift Gas volume Nonsensitive (Ne-CO2 90/10)
956   //  and its daughters (HV membrane, rods, readout chambers)
957   //---------------------------------------------------------
958
959   dm[0]= 79.2;
960   dm[1]= 258.0;
961   dm[2]= 253.6;
962
963   gMC->Gsvolu("TDGN","TUBE",idtmed[1],dm,3); 
964
965   // sector opening angles
966
967   Float_t innerOpenAngle = fTPCParam->GetInnerAngle();
968   Float_t outerOpenAngle = fTPCParam->GetOuterAngle();
969
970   // sector angle shift
971
972   Float_t innerAngleShift = fTPCParam->GetInnerAngleShift();
973
974
975   // All above parameters are identical for inner and outer
976   // sectors. The distinction is kept for the historical reasons
977   // and eventually will disappear.
978
979   Float_t tanAlpha = TMath::Tan(0.5*innerOpenAngle);
980   Float_t cosAlpha = TMath::Sqrt(1.+tanAlpha*tanAlpha);
981   Float_t space;
982
983   //-------------------------------------------------------------------------
984   //   Tpc Inner Readout Chambers 
985   //-------------------------------------------------------------------------
986
987   dm[0]= 14.483;
988   dm[1]= 23.3345; 
989   dm[2]= 1.6; // thickness
990   dm[3]= 25.1;
991
992   gMC->Gsvolu("TIRC","TRD1",idtmed[4],dm,4);
993
994   // this volume will be positioned in the empty space
995   // of the end-cap to avoid overlaps
996
997   dm[0]= 13.7305;
998   dm[1]= 21.1895;
999   dm[2]= 2.25;
1000   dm[3]= 21.15;
1001
1002   gMC->Gsvolu("TIC1","TRD1",idtmed[4],dm,4);
1003
1004
1005   //------------------------------------------------
1006   // Tpc Inner readout chamber Pad Plane
1007   //------------------------------------------------
1008
1009   dm[0]= 14.483;
1010   dm[1]= 23.3345;
1011   dm[2]= 0.5;
1012   dm[3]= 25.1;
1013
1014   gMC->Gsvolu("TIPP","TRD1",idtmed[12],dm,4);
1015
1016   // 
1017
1018   dm[0] -= 1.218511934;
1019   dm[1] -= 1.218511934;
1020   dm[2] = 0.35;
1021
1022   gMC->Gsvolu("TIC3","TRD1",idtmed[1],dm,4);
1023
1024   gMC->Gspos("TIC3",1,"TIPP",0.,0.15,0.,0,"ONLY");
1025
1026   gMC->Gspos("TIPP",1,"TIRC",0.,1.1,0.,0,"ONLY");
1027
1028
1029   //----------------------------------------------
1030   // Tpc Readout Chambers Empty spaces - for both
1031   // inner and outer sectors
1032   //----------------------------------------------
1033
1034   gMC->Gsvolu("TRCE","TRD1",idtmed[0],dm,0);
1035
1036   // Inner sector - 4 spaces
1037
1038
1039   dm[3] = 4.7625;
1040   dm[0] = 12.472;
1041
1042   Float_t rr = 90.52;
1043   Float_t zz;
1044
1045   zz= -12.7875;
1046   
1047   space = rr*tanAlpha-dm[0];
1048
1049   for(Int_t nsLow=0;nsLow<4;nsLow++){
1050
1051     rr += 9.525;
1052     dm[1]= rr*tanAlpha - space;  
1053
1054     dm[2]=0.8;
1055
1056     gMC->Gsposp("TRCE",nsLow+1,"TIRC",0.,-0.8,zz,0,"ONLY",dm,4);
1057
1058     //
1059
1060     dm[2] = 1.2;
1061
1062     gMC->Gsposp("TRCE",nsLow+5,"TIC1",0.,1.05,zz-2.1,0,"ONLY",dm,4);
1063
1064     rr += 0.4;
1065     dm[0] = rr*tanAlpha - space;
1066     zz += (0.4+9.525); 
1067
1068   }
1069
1070   dm[0]= 12.472;
1071   // dm[1] - this is the dm[1] from the previous TRCE
1072   dm[2]= 1.05;
1073   dm[3]= 19.65;
1074
1075   gMC->Gsposp("TRCE",9,"TIC1",0.,-1.2,0.,0,"ONLY",dm,4);   
1076
1077   //
1078   // TPc Space for Connectors
1079   //
1080
1081   dm[0]= .3;
1082   dm[1]= .3;
1083   dm[2]= 4.5;
1084
1085   gMC->Gsvolu("TPSC","BOX ",idtmed[0],dm,3);
1086
1087   // TPC Connectors
1088
1089   dm[0]= .25;
1090   dm[1]= .15;
1091   dm[2]= 3.75;
1092
1093   gMC->Gsvolu("TPCC","BOX ",idtmed[13],dm,3); 
1094
1095   gMC->Gspos("TPCC",1,"TPSC",0.,0.15,0.,0,"ONLY");
1096
1097   zz = -12.7875;
1098
1099
1100   Float_t alpha;
1101   Float_t astep;
1102
1103   // inner part of the inner sector - 2 x 20 holes
1104   
1105   astep = 20.00096874/19.;
1106
1107   alpha = 10.00048437-astep;
1108
1109   Float_t x1,x2;
1110
1111     x1 = 13.31175725;
1112     x1 -= 0.996357832; 
1113
1114     x2 = 15.06180253;
1115     x2 -= 1.163028812;
1116
1117   Int_t ncon;
1118
1119   for(ncon=0;ncon<20;ncon++){
1120
1121     phi1 = 0.;
1122     theta1 = 90.+alpha;
1123     phi2=90.;
1124     theta2 = 90.;
1125     phi3 = (alpha>0) ? 0. : 180.;
1126     theta3 = TMath::Abs(alpha);
1127
1128     AliMatrix(idrotm[nRotMat], theta1, phi1, theta2, phi2, theta3, phi3);
1129
1130  
1131
1132     gMC->Gspos("TPSC",ncon+1,"TIRC",x1,0.3,-12.7875,idrotm[nRotMat],"ONLY");
1133     gMC->Gspos("TPSC",ncon+21,"TIRC",x2,0.3,-2.8625,idrotm[nRotMat],"ONLY");
1134
1135
1136     x1 -= 1.296357833;
1137     x2 -= 1.463028812;
1138
1139     alpha -= astep;   
1140     nRotMat++; 
1141
1142   }
1143
1144   // outer part of the inner sector - 2 x 25 holes
1145
1146    astep = 20.00096874/24.; 
1147    alpha = 10.00048437-astep;
1148
1149    x1 = 16.81184781;
1150    x1 -= 1.016295986;
1151
1152    x2 = 18.5618931;
1153    x2 -= 1.150914854;
1154
1155   for(ncon=0;ncon<25;ncon++){
1156
1157     phi1 = 0.;
1158     theta1 = 90.+alpha;
1159     phi2=90.;
1160     theta2 = 90.;
1161     phi3 = (alpha>0) ? 0. : 180.;
1162     theta3 = TMath::Abs(alpha);
1163
1164     AliMatrix(idrotm[nRotMat], theta1, phi1, theta2, phi2, theta3, phi3);
1165
1166  
1167
1168     gMC->Gspos("TPSC",ncon+41,"TIRC",x1,0.3,7.0625,idrotm[nRotMat],"ONLY");
1169     gMC->Gspos("TPSC",ncon+66,"TIRC",x2,0.3,16.9875,idrotm[nRotMat],"ONLY");
1170
1171
1172     x1 -= 1.316295986;
1173     x2 -= 1.450914854;
1174
1175     alpha -= astep;   
1176     nRotMat++; 
1177
1178   }  
1179
1180   //--------------------------------------------------------------------------
1181   //  TPC Outer Readout Chambers
1182   //  this is NOT a final design
1183   //--------------------------------------------------------------------------
1184
1185   dm[0]= 23.3875;
1186   dm[1]= 43.524;
1187   dm[2]= 1.5; //thickness
1188   dm[3]= 57.1;
1189
1190   gMC->Gsvolu("TORC","TRD1",idtmed[4],dm,4);
1191
1192   //------------------------------------------------
1193   // Tpc Outer readout chamber Pad Plane
1194   //------------------------------------------------
1195
1196   dm[2]= 0.5;
1197
1198   gMC->Gsvolu("TOPP","TRD1",idtmed[12],dm,4);
1199
1200   dm[0] -= 1.218511934;
1201   dm[1] -= 1.218511934;
1202   dm[2] = 0.35;
1203
1204   gMC->Gsvolu("TOC3","TRD1",idtmed[1],dm,4);
1205
1206   gMC->Gspos("TOC3",1,"TOPP",0.,0.15,0.,0,"ONLY");
1207
1208   gMC->Gspos("TOPP",1,"TORC",0.,1.0,0.,0,"ONLY");
1209
1210   // empty space
1211
1212   dm[0]= 21.035;
1213   dm[1]= 38.7205;
1214   dm[2]= 0.7; 
1215   dm[3]= 50.15;
1216
1217   gMC->Gsposp("TRCE",10,"TORC",0.,-0.8,-2.15,0,"ONLY",dm,4);  
1218
1219   dm[0]= 22.2935;
1220   dm[1]= 40.5085;
1221   dm[2]= 2.25;
1222   dm[3]= 51.65;
1223
1224   gMC->Gsvolu("TOC1","TRD1",idtmed[4],dm,4);
1225
1226   dm[0]= 21.35;
1227   dm[1]= 38.7205;
1228   dm[2]= 2.25;
1229   dm[3]= 50.15;
1230
1231   gMC->Gsposp("TRCE",11,"TOC1",0.,0.,0.,0,"ONLY",dm,4);
1232
1233   //-----------------------------------------------
1234   // Tpc Services Support Wheel
1235   //-----------------------------------------------
1236
1237   dm[0]=0.;
1238   dm[1]=360.;
1239   dm[2]=18.;
1240   dm[3]=2.;
1241
1242   dm[4]= -5.;
1243   dm[5]= 77.017;
1244   dm[6]= 255.267;
1245
1246   dm[7]= 5.;
1247   dm[8]= dm[5];
1248   dm[9]= dm[6];
1249
1250   gMC->Gsvolu("TSSW","PGON",idtmed[4],dm,10);
1251
1252   // Tpc Services Wheel Cover
1253
1254   dm[4]= -0.5;
1255   dm[7]= 0.5;
1256
1257   gMC->Gsvolu("TSWC","PGON",idtmed[4],dm,10);
1258
1259   // Tpc Service wheel Cover Empty space
1260    
1261   dm[0]= 10.99;
1262   dm[1]= 39.599;
1263   dm[2]= .5;
1264   dm[3]= 81.125;
1265
1266   gMC->Gsvolu("TSCE","TRD1",idtmed[0],dm,4);
1267
1268   // Tpc services Wheel Empty Spaces
1269
1270   dm[0]= 13.18017507;
1271   dm[1]= 44.61045938;
1272   dm[2]= 4.;
1273   dm[3]= 89.125;
1274
1275   gMC->Gsvolu("TWES","TRD1",idtmed[0],dm,4);
1276
1277   // Tpc Services Wheel Bars
1278
1279   gMC->Gsvolu("TSWB","TRD1",idtmed[4],dm,0);
1280
1281   // bars-> TWES
1282
1283   dm[2]= 4.;
1284   dm[3]= .4;
1285
1286   dm[0]= 13.8149522;
1287   dm[1]= 13.95601379;
1288   
1289   gMC->Gsposp("TSWB",1,"TWES",0.,0.,-85.125,0,"ONLY",dm,4);
1290
1291   dm[0]= 43.83462067; 
1292   dm[1]= 43.97568225;
1293
1294   gMC->Gsposp("TSWB",2,"TWES",0.,0.,85.125,0,"ONLY",dm,4);
1295
1296   // TPc ELectronics - right now 30% X0 Si
1297
1298   dm[0]= 14.03813696;
1299   dm[1]= 43.3524075;
1300   dm[2]= 1.404;
1301   dm[3]= 83.125;
1302
1303   gMC->Gsvolu("TPEL","TRD1",idtmed[11],dm,4);
1304   gMC->Gspos("TPEL",1,"TWES",0.,0.,0.,0,"ONLY");
1305
1306   //--------------------------------------------------------------------------
1307   //  End caps
1308   //--------------------------------------------------------------------------
1309
1310   // TPc Main Wheel - Al
1311
1312   dm[0]= 74.9;
1313   dm[1]= 264.4;
1314   dm[2]= 3.0;
1315
1316   gMC->Gsvolu("TPMW","TUBE",idtmed[4],dm,3);
1317
1318   //--------------------------------------------------------------------------
1319   //  Tpc Empty Space for the Readout chambers
1320   //--------------------------------------------------------------------------  
1321
1322   Float_t rLow= 86.2;
1323   Float_t rUp= 243.5;
1324   Float_t dR = 0.5*(rUp-rLow);
1325
1326   space= 1.5/cosAlpha; // wheel ribs are 3.0 cm wide
1327
1328   dm[0]= rLow*tanAlpha-space;
1329   dm[1]= rUp*tanAlpha-space;
1330   dm[2] = 3.0;
1331   dm[3]= dR;
1332
1333   gMC->Gsvolu("TESR","TRD1",idtmed[0],dm,4);
1334
1335   // TIC1->TESR
1336
1337   gMC->Gspos("TIC1",1,"TESR",0.,0.75,-dR+23.97,0,"ONLY");
1338
1339   // TOC1->TESR
1340
1341   gMC->Gspos("TOC1",1,"TESR",0.,0.75,dR-55.02,0,"ONLY");
1342
1343   // Tpc Empty Space Bars - Al (daughters of TESR)
1344
1345   Float_t zBar;
1346
1347   gMC->Gsvolu("TESB","TRD1",idtmed[4],dm,0);
1348
1349   // lower bar
1350
1351   dm[0]= rLow*tanAlpha-space;
1352   dm[1]= 88.7*tanAlpha-space;
1353   dm[2]= 2.25;
1354   dm[3]= 1.275;
1355
1356   zBar = -dR+dm[3];
1357
1358   gMC->Gsposp("TESB",1,"TESR",0.,0.75,zBar,0,"ONLY",dm,4);
1359
1360   // middle bar
1361
1362   dm[0]= 131.65*tanAlpha-space;
1363   dm[1]= 136.5*tanAlpha-space;
1364   dm[3]= 2.425;
1365
1366   zBar = -dR +131.65+dm[3]-rLow;
1367
1368   gMC->Gsposp("TESB",2,"TESR",0.,0.75,zBar,0,"ONLY",dm,4);  
1369
1370   // upper bar
1371
1372   dm[0]= 240.4*tanAlpha-space;
1373   dm[1]= rUp*tanAlpha-space;
1374   dm[3]= 1.55;
1375
1376   zBar = dR-dm[3];
1377
1378   gMC->Gsposp("TESB",3,"TESR",0.,0.75,zBar,0,"ONLY",dm,4);
1379
1380   //------------------------------------------------------
1381   //  TPc Lower "S" Sectors 
1382   //------------------------------------------------------
1383
1384
1385   Float_t inSecLowEdge = fTPCParam->GetInnerRadiusLow();
1386   Float_t inSecUpEdge =  fTPCParam->GetInnerRadiusUp();
1387
1388   dm[0] = inSecLowEdge*TMath::Tan(0.5*innerOpenAngle)-0.01;
1389   dm[1] = inSecUpEdge*TMath::Tan(0.5*innerOpenAngle)-0.01;
1390   dm[2] = 0.5*(250. - 5.e-3);
1391   dm[3] = 0.5*(inSecUpEdge-inSecLowEdge);  
1392
1393   gMC->Gsvolu("TPLS", "TRD1", idtmed[2], dm, 4); // sensitive 
1394
1395
1396   //----------------------------------------------------------
1397   //  TPc Upper Sectors
1398   //----------------------------------------------------------
1399
1400   Float_t ouSecLowEdge = fTPCParam->GetOuterRadiusLow();
1401   Float_t ouSecUpEdge = fTPCParam->GetOuterRadiusUp();
1402
1403   dm[0] = ouSecLowEdge*TMath::Tan(0.5*outerOpenAngle)-0.01;  
1404   dm[1] = ouSecUpEdge*TMath::Tan(0.5*outerOpenAngle)-0.01;  
1405   dm[2] = 0.5*(250. - 5.e-3);
1406   dm[3] = 0.5*(ouSecUpEdge-ouSecLowEdge);
1407
1408   gMC->Gsvolu("TPUS", "TRD1", idtmed[2], dm, 4); // sensitive
1409
1410
1411
1412   // sensitive strips
1413
1414     gMC->Gsvolu("TPSS","TRD1",idtmed[2],dm,0); // sensitive
1415
1416     Int_t nofStrips,nstr;
1417     Float_t r1,r2,zs;
1418     Float_t stripThick = 0.01; // 100 microns
1419     Float_t deadSpace;
1420
1421     // inner sector
1422
1423
1424     // if all lower sectors selected define only 1 strip
1425
1426     nofStrips=((fSecAL <0)||(fSecAL>=0 && fSens<0)) ? 1 : fTPCParam->GetNRowLow(); 
1427     deadSpace = fTPCParam->GetInnerWireMount();
1428
1429     dm[2] = 0.5*(250. - 5.e-3);
1430     dm[3] = 0.5 * stripThick;
1431
1432     for(nstr=0;nstr<nofStrips;nstr++){
1433
1434       r1 = fTPCParam->GetPadRowRadiiLow(nstr);
1435       r2 = r1 + stripThick;     
1436       dm[0] = r1 * TMath::Tan(0.5*innerOpenAngle) - deadSpace;
1437       dm[1] = r2 * TMath::Tan(0.5*innerOpenAngle) - deadSpace;
1438       zs = -inSecLowEdge -0.5*(inSecUpEdge-inSecLowEdge);
1439       zs += r1;
1440       zs += dm[3];
1441     
1442       gMC->Gsposp("TPSS", nstr+1, "TPLS", 0., 0., zs, 0, "ONLY", dm, 4);
1443
1444
1445     }
1446
1447     // strips only if several upper sectors selected end fSens > 0
1448
1449     if(fSecAU >=0 && fSens >0){
1450
1451     Int_t nsSave = nofStrips;
1452
1453     // outer sector
1454
1455     nofStrips = fTPCParam->GetNRowUp();
1456     deadSpace = fTPCParam->GetOuterWireMount();
1457
1458     dm[2] = 0.5*(250. - 5.e-3);
1459     dm[3] = 0.5 * stripThick;
1460
1461   
1462     for(nstr=0;nstr<nofStrips;nstr++){
1463     
1464       r1 = fTPCParam->GetPadRowRadiiUp(nstr); 
1465       r2 = r1 + stripThick;
1466       dm[0] = r1 * TMath::Tan(0.5*outerOpenAngle) - deadSpace;
1467       dm[1] = r2 * TMath::Tan(0.5*outerOpenAngle) - deadSpace;
1468       zs = -ouSecLowEdge -0.5*(ouSecUpEdge-ouSecLowEdge);
1469       zs += r1;
1470       zs += dm[3];
1471
1472       gMC->Gsposp("TPSS", nstr+1+nsSave, "TPUS", 0., 0., zs, 0, "ONLY", dm, 4);
1473
1474      }    
1475     }    
1476
1477
1478   //-------------------------------------------------------
1479   //  positioning of the empty spaces into the main wheel
1480   //  and readout chambers and sectors into the drift gas
1481   //-------------------------------------------------------
1482
1483   Float_t rCenter,xc,yc;
1484   Float_t rInner,rOuter; // center of the inner and outer chamber
1485
1486   rCenter = rLow+dR;
1487
1488   rInner = 108.07;
1489   rOuter = 190.68;
1490
1491
1492   for(Int_t ns=0; ns<nInnerSector;ns++){
1493
1494     phi1 = ns * innerOpenAngle + innerAngleShift;
1495     phi1 *= kRaddeg; // in degrees
1496
1497     phi1 = (Float_t)TMath::Nint(phi1) + 270.;
1498
1499     if (phi1 > 360.) phi1 -= 360.;
1500
1501     theta1 = 90.;
1502     phi2   = 90.;
1503     theta2 = 180.;
1504     phi3   = ns * innerOpenAngle + innerAngleShift;
1505     phi3 *= kRaddeg; // in degrees
1506
1507     phi3 = (Float_t)TMath::Nint(phi3);
1508       
1509     if(phi3 > 360.) phi3 -= 360.;
1510
1511     theta3 = 90.;
1512
1513     // "holes"->End plate
1514
1515     xc = rCenter*TMath::Cos(phi3*kDegrad);
1516     yc = rCenter*TMath::Sin(phi3*kDegrad);
1517
1518     AliMatrix(idrotm[nRotMat], theta1, phi1, theta2, phi2, theta3, phi3);
1519
1520     gMC->Gspos("TESR",ns+1,"TPMW",xc,yc,0.,idrotm[nRotMat],"ONLY");
1521
1522     // TSCE->TSWC (services wheel volumes)
1523
1524     xc = 166.142*TMath::Cos(phi3*kDegrad);
1525     yc = 166.142*TMath::Sin(phi3*kDegrad);
1526
1527     gMC->Gspos("TSCE",ns+1,"TSWC",xc,yc,0.,idrotm[nRotMat],"ONLY");
1528     gMC->Gspos("TWES",ns+1,"TSSW",xc,yc,0.,idrotm[nRotMat],"ONLY");
1529
1530
1531     // readout chambers->TDGN (drift gas)
1532
1533     xc = rInner*TMath::Cos(phi3*kDegrad);
1534     yc = rInner*TMath::Sin(phi3*kDegrad);
1535
1536     gMC->Gspos("TIRC",ns+1,"TDGN",xc,yc,252.,idrotm[nRotMat],"ONLY");
1537
1538     // here lower sectors 
1539
1540     if(fSecAL <0){
1541
1542       // all lower sectors are positioned
1543
1544       gMC->Gspos("TPLS",ns+1,"TDGN",xc,yc,125.0025,idrotm[nRotMat],"ONLY");
1545       gMC->
1546         Gspos("TPLS",ns+nInnerSector+1,"TDGN",xc,yc,-125.0025,idrotm[nRotMat],"ONLY");
1547     }
1548     else{
1549
1550       // only selected sectors are positioned (up to 6 sectors)
1551
1552       for(Int_t sel=0;sel<6;sel++){
1553
1554         if(fSecLows[sel] == ns){
1555           gMC->Gspos("TPLS",ns+1,"TDGN",xc,yc,125.0025,idrotm[nRotMat],"ONLY");
1556         }
1557         else if(fSecLows[sel] == ns+nInnerSector){
1558          gMC->
1559          Gspos("TPLS",ns+nInnerSector+1,"TDGN",xc,yc,-125.0025,idrotm[nRotMat],"ONLY");
1560         }
1561       }
1562     } // lower sectors finished
1563
1564     
1565     xc = rOuter*TMath::Cos(phi3*kDegrad);
1566     yc = rOuter*TMath::Sin(phi3*kDegrad);
1567
1568     gMC->Gspos("TORC",ns+1,"TDGN",xc,yc,252.1,idrotm[nRotMat],"ONLY");
1569
1570     // here upper sectors 
1571
1572     if(fSecAU <0){
1573
1574       // all upper sectors
1575
1576       gMC->Gspos("TPUS",ns+1,"TDGN",xc,yc,125.0025,idrotm[nRotMat],"ONLY");
1577       gMC->
1578         Gspos("TPUS",ns+nOuterSector+1,"TDGN",xc,yc,-125.0025,idrotm[nRotMat],"ONLY");
1579     }
1580     else{
1581
1582       // only selected sectors (up to 12)
1583
1584       for(Int_t sel=0;sel<12;sel++){
1585         if(fSecUps[sel] == ns+2*nInnerSector){
1586           gMC->Gspos("TPUS",ns+1,"TDGN",xc,yc,125.0025,idrotm[nRotMat],"ONLY");
1587         }         
1588         else if(fSecUps[sel] == ns+2*nInnerSector+nOuterSector){
1589          gMC->
1590           Gspos("TPUS",ns+nOuterSector+1,"TDGN",xc,yc,-125.0025,idrotm[nRotMat],"ONLY"); 
1591         }
1592       }
1593     } // upper sectors finished
1594
1595
1596     nRotMat++;
1597
1598     theta2 = 0.; // reflection
1599
1600     AliMatrix(idrotm[nRotMat], theta1, phi1, theta2, phi2, theta3, phi3);
1601
1602     xc = rInner*TMath::Cos(phi3*kDegrad);
1603     yc = rInner*TMath::Sin(phi3*kDegrad);
1604
1605     gMC->Gspos("TIRC",ns+nInnerSector+1,"TDGN",xc,yc,-252.,idrotm[nRotMat],"ONLY");
1606
1607     xc = rOuter*TMath::Cos(phi3*kDegrad);
1608     yc = rOuter*TMath::Sin(phi3*kDegrad);
1609
1610     gMC->Gspos("TORC",ns+nOuterSector+1,"TDGN",xc,yc,-252.1,idrotm[nRotMat],"ONLY");
1611
1612     nRotMat++;
1613
1614   } 
1615   // TPMW->TPC
1616
1617   gMC->Gspos("TPMW",1,"TPC ",0.,0.,256.6,0,"ONLY");
1618   gMC->Gspos("TPMW",2,"TPC ",0.,0.,-256.6,idrotm[0],"ONLY");
1619
1620   //---------------------------------------------------------
1621   //  Tpc High Voltage Membrane - 100 microns of mylar
1622   //---------------------------------------------------------
1623
1624   dm[0]=82.8;
1625   dm[1]=252.;
1626   dm[2]=0.005;
1627
1628   gMC->Gsvolu("THVM","TUBE",idtmed[8],dm,3);
1629
1630   gMC->Gspos("THVM",1,"TDGN",0.,0.,0.,0,"ONLY");
1631
1632   // Tpc High Voltage membrane Holders
1633
1634   gMC->Gsvolu("THVH","TUBE",idtmed[4],dm,0);
1635
1636   
1637
1638   // inner
1639
1640   dm[0]=79.3;
1641   dm[1]=82.8;
1642   dm[2]=0.2;
1643
1644   gMC->Gsposp("THVH",1,"TDGN",0.,0.,0.,0,"ONLY",dm,3);
1645   
1646   // outer
1647
1648   dm[0]= 252.;
1649   dm[1]= 257.9;
1650   dm[2]= 0.4;
1651
1652   gMC->Gsposp("THVH",2,"TDGN",0.,0.,0.,0,"ONLY",dm,3);
1653
1654   //----------------------------------------------------------
1655   // TPc Support Rods - MAKROLON
1656   //----------------------------------------------------------
1657
1658   dm[0]= 0.9;
1659   dm[1]= 1.2;
1660
1661   gMC->Gsvolu("TPSR","TUBE",idtmed[7],dm,0); // inner and outer rods differ
1662
1663
1664   for(Int_t nrod=0;nrod<18;nrod++){
1665     Float_t angle=innerOpenAngle*(Float_t)nrod;
1666
1667     xc=81.5*TMath::Cos(angle);
1668     yc=81.5*TMath::Sin(angle); 
1669
1670     dm[2]=126.7;
1671
1672     gMC->Gsposp("TPSR",nrod+1,"TDGN",xc,yc,126.9,0,"ONLY",dm,3); 
1673     gMC->Gsposp("TPSR",nrod+19,"TDGN",xc,yc,-126.9,0,"ONLY",dm,3);
1674
1675     dm[2]=126.6;
1676
1677     xc=254.25*TMath::Cos(angle);
1678     yc=254.25*TMath::Sin(angle);   
1679       
1680     // rod number 54 contans the HV cable
1681
1682     if(nrod<17) {
1683       gMC->Gsposp("TPSR",nrod+37,"TDGN",xc,yc,127.,0,"ONLY",dm,3);
1684       gMC->Gsposp("TPSR",nrod+54,"TDGN",xc,yc,-127.,0,"ONLY",dm,3);
1685     }
1686     
1687   }
1688
1689   //----------------------------------------------------------
1690   // Tpc High Voltage Rod - MAKROLON + Copper cable
1691   //----------------------------------------------------------
1692
1693   // rod with cable (Left)
1694
1695   dm[0]=0.;
1696   dm[1]=2.25;
1697   dm[2]=126.6;
1698
1699   gMC->Gsvolu("THVL","TUBE",idtmed[7],dm,3);
1700
1701   // HV cable
1702  
1703   dm[0]=0.;
1704   dm[1]=0.3;
1705   dm[2]=126.6;
1706
1707   gMC->Gsvolu("THVC","TUBE",idtmed[10],dm,3);  
1708
1709   // empty space
1710
1711   dm[0]=0.3;
1712   dm[1]=1.;
1713   dm[2]=126.6;
1714
1715   gMC->Gsvolu("THVE","TUBE",idtmed[1],dm,3);
1716
1717   gMC->Gspos("THVC",1,"THVL",0.,0.,0.,0,"ONLY");
1718   gMC->Gspos("THVE",1,"THVL",0.,0.,0.,0,"ONLY");
1719
1720   // rod without cable
1721
1722   dm[0]=1.8;
1723   dm[1]=2.25;
1724   dm[2]=126.6;
1725
1726   gMC->Gsvolu("THVR","TUBE",idtmed[7],dm,3);
1727
1728   gMC->Gspos("THVL",1,"TDGN",xc,yc,-127.,0,"ONLY");  
1729   gMC->Gspos("THVR",1,"TDGN",xc,yc,127.,0,"ONLY");
1730
1731   gMC->Gspos("TDGN",1,"TPC ",0.,0.,0.,0,"ONLY"); 
1732  
1733   // services wheel cover -> wheel
1734
1735
1736   gMC->Gspos("TSWC",1,"TSSW",0.,0.,4.5,0,"ONLY");
1737   gMC->Gspos("TSWC",2,"TSSW",0.,0.,-4.5,0,"ONLY");
1738
1739
1740   // put the wheel into the TPC
1741
1742   gMC->Gspos("TSSW",1,"TPC ",0.,0.,278.7,0,"ONLY");
1743   gMC->Gspos("TSSW",2,"TPC ",0.,0.,-278.7,0,"ONLY");
1744
1745   //
1746
1747   gMC->Gsord("TPMW",6);
1748   gMC->Gsord("TSSW",6);
1749   gMC->Gsord("TSWC",6);
1750   if(fSecAL >=0)  gMC->Gsord("TPLS",3);
1751   if(fSecAU >=0 && fSens >0)  gMC->Gsord("TPUS",3);
1752   gMC->Gsord("TDGN",6);
1753
1754   // put the TPC into ALIC (main mother volume)
1755
1756   gMC->Gspos("TPC ",1,"ALIC",0.,0.,0.,0,"ONLY");
1757
1758  
1759
1760 } // end of function
1761  
1762 //_____________________________________________________________________________
1763 void AliTPCv2::DrawDetector()
1764 {
1765   //
1766   // Draw a shaded view of the Time Projection Chamber version 1
1767   //
1768
1769   // Set everything unseen
1770   gMC->Gsatt("*", "seen", -1);
1771   // 
1772   // Set ALIC mother transparent
1773   gMC->Gsatt("ALIC","SEEN",0);
1774   //
1775   // Set the volumes visible
1776   //
1777
1778   gMC->Gsatt("TPC ","SEEN",0);
1779   gMC->Gsatt("TOIN","SEEN",1);
1780   gMC->Gsatt("TOIN","COLO",7);
1781   gMC->Gsatt("TOCV","SEEN",1);
1782   gMC->Gsatt("TOCV","COLO",4);
1783   gMC->Gsatt("TSA1","SEEN",0);
1784   gMC->Gsatt("TSA2","SEEN",0);
1785   gMC->Gsatt("TSA3","SEEN",0);
1786   gMC->Gsatt("TSA4","SEEN",0);  
1787   gMC->Gsatt("TSA5","SEEN",0);
1788   gMC->Gsatt("TOFC","SEEN",1);
1789   gMC->Gsatt("TOFC","COLO",4);
1790   gMC->Gsatt("TSA6","SEEN",0);
1791   gMC->Gsatt("TSA7","SEEN",0);
1792   gMC->Gsatt("TSA8","SEEN",0);    
1793   gMC->Gsatt("TIIN","SEEN",1);
1794   gMC->Gsatt("TIIN","COLO",7);
1795   gMC->Gsatt("TII1","SEEN",0);
1796   gMC->Gsatt("TIFC","SEEN",1);
1797   gMC->Gsatt("TIFC","COLO",4);
1798   gMC->Gsatt("TSA9","SEEN",0); 
1799   gMC->Gsatt("TS10","SEEN",0);
1800   gMC->Gsatt("TS11","SEEN",0);
1801   gMC->Gsatt("TS12","SEEN",0);
1802   gMC->Gsatt("TS13","SEEN",0);
1803   gMC->Gsatt("TS14","SEEN",0);
1804   gMC->Gsatt("TICC","SEEN",0);
1805   gMC->Gsatt("TICM","SEEN",0);
1806   gMC->Gsatt("TS15","SEEN",0);
1807   gMC->Gsatt("TS16","SEEN",0);
1808   gMC->Gsatt("TS17","SEEN",0);
1809   gMC->Gsatt("TS18","SEEN",0);  
1810   gMC->Gsatt("TS19","SEEN",0); 
1811   gMC->Gsatt("TPJ1","SEEN",0);
1812   gMC->Gsatt("TPJ2","SEEN",0);
1813   gMC->Gsatt("TICS","SEEN",0);
1814   gMC->Gsatt("TDGN","SEEN",0); 
1815   gMC->Gsatt("TIRC","SEEN",0);
1816   gMC->Gsatt("TIC1","SEEN",1);
1817   gMC->Gsatt("TIPP","SEEN",0);
1818   gMC->Gsatt("TIC3","SEEN",0);
1819   gMC->Gsatt("TRCE","SEEN",0);
1820   gMC->Gsatt("TPSC","SEEN",0);
1821   gMC->Gsatt("TPCC","SEEN",0); 
1822   gMC->Gsatt("TORC","SEEN",0);
1823   gMC->Gsatt("TOPP","SEEN",0);
1824   gMC->Gsatt("TOC3","SEEN",0);
1825   gMC->Gsatt("TOC1","SEEN",1);
1826   gMC->Gsatt("TSSW","SEEN",1);
1827   gMC->Gsatt("TSWC","SEEN",1);
1828   gMC->Gsatt("TSSW","COLO",3);
1829   gMC->Gsatt("TSWC","COLO",3);
1830   gMC->Gsatt("TSCE","COLO",6);
1831   gMC->Gsatt("TSCE","SEEN",1);
1832   gMC->Gsatt("TWES","SEEN",0);
1833   gMC->Gsatt("TSWB","SEEN",0);
1834   gMC->Gsatt("TPEL","SEEN",0);
1835   gMC->Gsatt("TPMW","SEEN",1);
1836   gMC->Gsatt("TESR","SEEN",1);
1837   gMC->Gsatt("TPMW","COLO",12);
1838   gMC->Gsatt("TIC1","COLO",5);
1839   gMC->Gsatt("TOC1","COLO",5);
1840   gMC->Gsatt("TESB","SEEN",0);
1841   gMC->Gsatt("THVM","SEEN",1);
1842   gMC->Gsatt("THVM","COLO",11);
1843   gMC->Gsatt("THVH","SEEN",0);
1844   gMC->Gsatt("TPSR","SEEN",0); 
1845   gMC->Gsatt("THVL","SEEN",0);
1846   gMC->Gsatt("THVC","SEEN",0);  
1847   gMC->Gsatt("THVE","SEEN",0);
1848   gMC->Gsatt("THVR","SEEN",0);
1849   gMC->Gsatt("TPSS","SEEN",0);
1850   gMC->Gsatt("TPUS","SEEN",0);
1851   gMC->Gsatt("TPLS","SEEN",0);
1852
1853   //
1854   gMC->Gdopt("hide", "on");
1855   gMC->Gdopt("shad", "on");
1856   gMC->Gsatt("*", "fill", 7);
1857   gMC->SetClipBox(".");
1858   gMC->SetClipBox("TPMW",-300,300,-300,300,254.,270.);
1859   gMC->SetClipBox("TESR",-300,300,-300,300,254.,270.);
1860   gMC->SetClipBox("TSSW",-300,300,-300,300,283.,284.);
1861   gMC->SetClipBox("TSWC",-300,300,-300,300,283.,284.);
1862   gMC->SetClipBox("*", 0, 300, -300, 300, -290, 290);
1863   gMC->DefaultRange();
1864   gMC->Gdraw("alic", 40, 30, 0, 12, 9.5, .025, .025);
1865   gMC->Gdhead(1111, "Time Projection Chamber");
1866   gMC->Gdman(18, 4, "MAN");
1867   gMC->Gdopt("hide","off");
1868 }
1869
1870 //_____________________________________________________________________________
1871 void AliTPCv2::CreateMaterials()
1872 {
1873   //
1874   // Define materials for version 2 of the Time Projection Chamber
1875   //
1876  
1877   AliTPC::CreateMaterials();
1878 }
1879
1880 //_____________________________________________________________________________
1881 void AliTPCv2::Init()
1882 {
1883   //
1884   // Initialises version 2 of the TPC after that it has been built
1885   //
1886
1887   Int_t *idtmed = fIdtmed->GetArray();
1888   
1889   AliTPC::Init();
1890
1891
1892   
1893   fIdSens=gMC->VolId("TPSS");  
1894
1895   fIdLSec=gMC->VolId("TPLS"); // lower sector 
1896   fIdUSec=gMC->VolId("TPUS"); // upper sector
1897
1898   gMC->SetMaxNStep(30000); // max. number of steps increased
1899
1900   gMC->Gstpar(idtmed[2],"LOSS",5); // specific energy loss
1901
1902   printf("*** TPC version 2 initialized ***\n");
1903   printf("Maximum number of steps = %d\n",gMC->GetMaxNStep());
1904
1905   //
1906   
1907 }
1908
1909 //_____________________________________________________________________________
1910 void AliTPCv2::StepManager()
1911 {
1912   //
1913   // Called for every step in the Time Projection Chamber
1914   //
1915
1916   //
1917   // parameters used for the energy loss calculations
1918   //
1919   const Float_t kprim = 14.35; // number of primary collisions per 1 cm
1920   const Float_t kpoti = 20.77e-9; // first ionization potential for Ne/CO2
1921   const Float_t kwIon = 35.97e-9; // energy for the ion-electron pair creation 
1922  
1923  
1924   const Float_t kbig = 1.e10;
1925
1926   Int_t id,copy;
1927   Float_t hits[4];
1928   Int_t vol[2];  
1929   TLorentzVector p;
1930   
1931   vol[1]=0; // preset row number to 0
1932
1933   //
1934
1935   gMC->SetMaxStep(kbig);
1936   
1937   if(!gMC->IsTrackAlive()) return; // particle has disappeared
1938   
1939   Float_t charge = gMC->TrackCharge();
1940   
1941   if(TMath::Abs(charge)<=0.) return; // take only charged particles
1942   
1943   // check the sensitive volume
1944
1945   id = gMC->CurrentVolID(copy); // current volume Id
1946
1947   if(id == fIdLSec){
1948     vol[0] = copy-1; // lower sector number
1949   }
1950   else if(id == fIdUSec){
1951     vol[0] = copy+fTPCParam->GetNInnerSector()-1; // upper sector number
1952   }
1953   else if(id == fIdSens && gMC->IsTrackEntering()){
1954  
1955     // track is entering the sensitive strip
1956     
1957     vol[1]= copy-1; // row number (absolute)
1958    
1959     // sector type
1960  
1961     id = gMC->CurrentVolOffID(1,copy);
1962
1963     if(id == fIdLSec){
1964
1965       // lower sector
1966      
1967       vol[0] = copy-1; // sector number
1968
1969     }
1970     else {
1971    
1972       // upper sector
1973
1974       vol[0] = copy-1+fTPCParam->GetNInnerSector(); // sector number
1975       vol[1] -= fTPCParam->GetNRowLow(); // row number (starts also from 0)  
1976
1977     } 
1978
1979     if(vol[1] == 0){
1980   
1981       // because Jouri wants to have this
1982
1983       gMC->TrackMomentum(p);
1984       hits[0]=p[0];
1985       hits[1]=p[1];
1986       hits[2]=p[2];
1987       hits[3]=0.; // this hit has no energy loss
1988       // new(lhits[fNhits++]) AliTPChit(fIshunt,gAlice->CurrentTrack(),vol,hits);
1989
1990       AddHit(gAlice->CurrentTrack(), vol,hits);  //MI change
1991
1992     }
1993
1994      gMC->TrackPosition(p);
1995      hits[0]=p[0];
1996      hits[1]=p[1];
1997      hits[2]=p[2];
1998      hits[3]=0.; // this hit has no energy loss
1999      // new(lhits[fNhits++]) AliTPChit(fIshunt,gAlice->CurrentTrack(),vol,hits);
2000
2001      AddHit(gAlice->CurrentTrack(), vol,hits);  //MI change    
2002
2003   }
2004   else return;
2005     
2006   //-----------------------------------------------------------------
2007   //  charged particle is in the sensitive volume
2008   //-----------------------------------------------------------------
2009   
2010   if(gMC->TrackStep() > 0) {
2011     
2012     Int_t nel = (Int_t)(((gMC->Edep())-kpoti)/kwIon) + 1;
2013     nel=TMath::Min(nel,300); // 300 electrons corresponds to 10 keV
2014     
2015     gMC->TrackPosition(p);
2016     hits[0]=p[0];
2017     hits[1]=p[1];
2018     hits[2]=p[2];
2019     hits[3]=(Float_t)nel;
2020     
2021     // Add this hit
2022     
2023     // new(lhits[fNhits++]) AliTPChit(fIshunt,gAlice->CurrentTrack(),vol,hits);
2024     if (fHitType&&2){
2025       gMC->TrackMomentum(p);
2026       Float_t momentum = TMath::Sqrt(p[0]*p[0]+p[1]*p[1]);
2027       Float_t precision =   (momentum>0.1) ? 0.002 :0.01;
2028       fTrackHits->SetHitPrecision(precision);
2029     }
2030     AddHit(gAlice->CurrentTrack(), vol,hits);  //MI change 
2031     
2032   } 
2033   
2034   // Stemax calculation for the next step
2035   
2036   Float_t pp;
2037   TLorentzVector mom;
2038   gMC->TrackMomentum(mom);
2039   Float_t ptot=mom.Rho();
2040   Float_t betaGamma = ptot/gMC->TrackMass();
2041   
2042   Int_t pid=gMC->TrackPid();
2043   if((pid==kElectron || pid==kPositron) && ptot > 0.002)
2044     { 
2045       pp = kprim*1.58; // electrons above 20 MeV/c are on the plateau!
2046     }
2047   else
2048     {
2049
2050       betaGamma = TMath::Max(betaGamma,(Float_t)7.e-3); // protection against too small bg
2051       pp=kprim*BetheBloch(betaGamma); 
2052    
2053       if(TMath::Abs(charge) > 1.) pp *= (charge*charge);
2054     }
2055   
2056   Float_t random[1];
2057   gMC->Rndm(random,1); // good, old GRNDM from Geant3
2058   
2059   Double_t rnd = (Double_t)random[0];
2060   
2061   gMC->SetMaxStep(-TMath::Log(rnd)/pp);
2062   
2063 }
2064
2065 //_____________________________________________________________________________
2066 Float_t AliTPCv2::BetheBloch(Float_t bg)
2067 {
2068   //
2069   // Bethe-Bloch energy loss formula
2070   //
2071   const Double_t kp1=0.76176e-1;
2072   const Double_t kp2=10.632;
2073   const Double_t kp3=0.13279e-4;
2074   const Double_t kp4=1.8631;
2075   const Double_t kp5=1.9479;
2076
2077   Double_t dbg = (Double_t) bg;
2078
2079   Double_t beta = dbg/TMath::Sqrt(1.+dbg*dbg);
2080
2081   Double_t aa = TMath::Power(beta,kp4);
2082   Double_t bb = TMath::Power(1./dbg,kp5);
2083
2084   bb=TMath::Log(kp3+bb);
2085   
2086   return ((Float_t)((kp2-aa-bb)*kp1/aa));
2087 }
2088
2089