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