bug in alignableVolumes fixed
[u/mrichter/AliRoot.git] / T0 / AliT0v1.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 /////////////////////////////////////////////////////////////////////
19 //                                                                 //
20 // T0 ( T-zero) detector  version 1                             //
21 //
22 //Begin Html       
23 /*
24 <img src="gif/AliT0v1Class.gif">
25 */
26 //End Html
27 //                                                                  //
28 //                                                                  //
29 //////////////////////////////////////////////////////////////////////
30
31 #include <Riostream.h>
32 #include <stdlib.h>
33
34 #include <TGeometry.h>
35 #include <TLorentzVector.h>
36 #include <TMath.h>
37 #include <TNode.h>
38 #include <TTUBE.h>
39 #include <TVirtualMC.h>
40 #include "TGeoManager.h"
41 #include "TGeoPgon.h"
42 #include "TGeoTube.h"
43 #include "TGeoCompositeShape.h"
44 #include <TGraph.h>
45
46 #include "AliLog.h"
47 #include "AliMagF.h"
48 #include "AliRun.h"
49
50 #include "AliT0hit.h"
51 #include "AliT0v1.h"
52 #include "AliT0Parameters.h"
53
54 #include "AliMC.h"
55 #include "AliCDBLocal.h"
56 #include "AliCDBStorage.h"
57 #include "AliCDBManager.h"
58 #include "AliCDBEntry.h"
59
60 ClassImp(AliT0v1)
61
62 //--------------------------------------------------------------------
63 AliT0v1::AliT0v1(const char *name, const char *title):
64   AliT0(name,title),
65   fIdSens1(0)
66 {
67   //
68   // Standart constructor for T0 Detector version 0
69   //
70   fIshunt = 2;
71   AliT0Parameters* param = AliT0Parameters::Instance();
72   for (Int_t i=0; i<24; i++){
73     TGraph* grEff = param ->GetPMTeff(i);
74     fEffPMT.AddAtAndExpand(grEff,i);
75   }
76 }
77 //_____________________________________________________________________________
78
79 AliT0v1::~AliT0v1() 
80 {
81   // desctructor  
82 }
83
84 //-------------------------------------------------------------------------
85 void AliT0v1::CreateGeometry()
86 {
87   //
88   // Create the geometry of T0 Detector version 0
89   //
90   // begin Html
91   /*
92    <img src="gif/AliT0v0.gif">
93   */
94   //
95
96
97    Int_t *idtmed = fIdtmed->GetArray();
98    /*
99    AliT0Parameters* param = AliT0Parameters::Instance();
100    param->Init();
101   Float_t zdetC = param->GetZposition(0);
102   Float_t zdetA = param->GetZposition(1);
103    */
104    Float_t zdetC = 69.7;
105    Float_t zdetA = 373.;
106
107   Int_t is;
108   Int_t idrotm[999];
109   Float_t x,y,z;
110   //C T0 mother volume
111   Float_t pstartR[18]={0., 360., 5., 
112                        -6.8, 4.25, 10., //-76.5+0.00+69.7
113                        -0.75 , 4.5, 10.,  // -76.5+6.05+69.7
114                        1.25   , 4.5, 10.,  //-76.5+8.05+69.7
115                        1.25 , 5.1, 10., //-76.5+8.05+69.7 
116                        6.8 , 5.1, 10.};  //-62.9+0.00+69.7
117   
118   Float_t pstart[3]={4., 12.5,6.8};
119   Float_t pinstart[3]={0.,1.6,6.5};
120   Float_t ppmt[3]={0.,1.5,3.5};
121   Float_t ptop[3]={0.,1.,1.0};
122   Float_t preg[3]={0., 1.0, 0.005}; //photcathode dobavil bogdanov
123   Float_t ptopout[3]={1.,1.01, 1.};  //metal air around raiator for photos reflection 
124   Float_t pbot[3]={0.6,1.2,0.1};
125   Float_t pglass[3]={1.2,1.3,2.};
126   Float_t pcer[3]={0.9,1.1,1.35};
127   Float_t psteel[3]={0.9,1.1,0.15};
128   Float_t psupport1[3] = {4.51,4.6,4.0};//C kozhuh vnutri
129   Float_t psupport2[3] = {9.4,9.5,4.0};// snaruzhi  C
130   Float_t psupport3[3] = {4.51,9.5,0.05};//kryshki  C
131   Float_t psupport5[3] = {1.44,1.5,6.5}; // stakanchik dlai feu  C
132   Float_t psupport6[3] = {0,1.4,0.04}; //kryshechka stakanchika  Al
133   Float_t psupport7[3] = {1.5,1.6,0.4}; //kolechko snaruzhu stakanchika Al
134    
135   // Mother Volume katushka dlia krepezha vokrug truby k Absorbru
136     AliMatrix(idrotm[901], 90., 0., 90., 90., 180., 0.);
137   Float_t ppcon[70]; 
138     ppcon[0]  =   0;
139     ppcon[1]  = 360;
140     ppcon[2]  =  13;
141 //  1: 
142     ppcon[3]  =  7.2;
143     ppcon[4]  =   4.4;
144     ppcon[5]  =   4.5;
145 //  2
146     ppcon[6]  = 8.2;
147     ppcon[7]  = 4.4;
148     ppcon[8]  = 4.5;
149 //  3
150     ppcon[9]  = 8.2;
151     ppcon[10] = 4.4;
152     ppcon[11] = 5.1;
153
154 //  4
155
156     ppcon[12] = 8.3; 
157     ppcon[13] = 4.4;
158     ppcon[14] = 5.1;
159 //  5
160
161     ppcon[15] = 8.3;
162     ppcon[16] = 4.9;
163     ppcon[17] = 5.1;
164     
165 //  6
166     ppcon[18] = 15.; 
167     ppcon[19] = 4.9;
168     ppcon[20] = 5.1;
169     
170 //  7
171     ppcon[21] = 15.; 
172     ppcon[22] = 3.15  ;
173     ppcon[23] = 5.1;
174
175 /// 8
176     ppcon[24] = 15.01; 
177     ppcon[25] = 3.15;
178     ppcon[26] = 5.1;
179
180 /// 9
181     ppcon[27] = 15.01; 
182     ppcon[28] = 3.15;
183     ppcon[29] = 3.25;
184
185     
186 /// 9
187      ppcon[30] = 19.71;
188      ppcon[31] = 3.15;
189      ppcon[32] = 3.25; 
190 //  10
191     ppcon[33] = 19.8; 
192     ppcon[34] = 3.15;
193     ppcon[35] = 3.25;
194     //  11
195     ppcon[36] = 19.8;
196     ppcon[37] = 3.15;
197     ppcon[38] = 7.6;
198         
199    //  14
200
201     ppcon[39] =  19.91;
202     ppcon[40] =  3.15;
203     ppcon[41] =  7.6;
204
205
206     gMC->Gsvolu("0SUP", "PCON", idtmed[kAir], ppcon,42);
207     z = -zdetC;
208     gMC->Gspos("0SUP",1,"ALIC",0.,0.,z,idrotm[901],"ONLY");
209    
210 //-------------------------------------------------------------------
211  //  T0 volume 
212  //-------------------------------------------------------------------
213   
214     
215     gMC->Gsvolu("0STR","PCON",idtmed[kAir],pstartR,18);
216     gMC->Gspos("0STR",1,"ALIC",0.,0.,-zdetC+pstartR[3],idrotm[901],"ONLY");
217     // gMC->Gspos("0STL",1,"ALIC",0.,0.,zdetA+pstart[2],0,"ONLY");
218
219 //T0 interior
220    gMC->Gsvolu("0INS","TUBE",idtmed[kAir],pinstart,3);
221    gMC->Gsvolu("0PMT","TUBE",idtmed[kAir],ppmt,3);     
222           
223     gMC->Gsvolu("0SU1","TUBE",idtmed[kC],psupport1,3);//C kozhuh vnutri
224     gMC->Gsvolu("0SU2","TUBE",idtmed[kC],psupport2,3);// snaruzhi  C
225     gMC->Gsvolu("0SU3","TUBE",idtmed[kC],psupport3,3);//kryshka perednaiai  C
226     gMC->Gsvolu("0SU4","TUBE",idtmed[kC],psupport3,3);//kryshka zadnaiai  C
227     //    gMC->Gsvolu("0SU5","TUBE",idtmed[kAir],psupport4,3);// dyrki dlia feu v zadnej kryshke Air
228     gMC->Gsvolu("0SU6","TUBE",idtmed[kC],psupport5,3);// stakanchik dlai feu  C
229     gMC->Gsvolu("0SU7","TUBE",idtmed[kAl],psupport6,3);//kryshechka stakanchika  Al
230     gMC->Gsvolu("0SU8","TUBE",idtmed[kAl],psupport7,3);//kolechko snaruzhu stakanchika Al
231    
232  
233
234    //non-absorber side support  and T0A !!!!!!!!
235     
236     TGeoPgon * supPgon = new TGeoPgon("supPgon",0.,360.,360,4);
237     supPgon->DefineSection(0, 0, 4.1, 5.5);
238     supPgon->DefineSection(1, 10.5 , 4.1, 5.5);
239     supPgon->DefineSection(2, 10.5 , 4.1, 4.9);
240     supPgon->DefineSection(3, 12.5 , 4.1, 4.9);
241     TGeoTranslation *trPgon = new TGeoTranslation("trPgon",0,0,0);
242     trPgon->RegisterYourself();
243  
244     TGeoVolumeAssembly * stlin = new TGeoVolumeAssembly("0STL");//empty segment
245     TGeoVolume *ins = gGeoManager->GetVolume("0INS");
246
247     Double_t phimin = TMath::ACos((16-4.8)/16.) * (180 / TMath::Pi()) ;
248     //  TGeoTubeSeg *hole = new TGeoTubeSeg("hole", 0, 1.6, 0, -phimin+90, phimin+90);
249     TGeoTube*hole = new TGeoTube("hole", 0, 1.61, 6.5);
250     TGeoTranslation *tr [12];
251     Float_t angle  = 2 * TMath::Pi() / 12;
252     Char_t nameTr[4];
253     for (Int_t itr=0; itr<12; itr++) {
254       sprintf (nameTr,"tr%i",itr+1);
255       x = 6.5 * TMath::Sin(itr * angle);
256       y = 6.5 * TMath::Cos(itr * angle);
257       tr[itr] = new TGeoTranslation(nameTr,x,y,6.5);
258       tr[itr]->RegisterYourself();
259        stlin->AddNode(ins,itr+13,tr[itr]);
260     }
261     TGeoCompositeShape *supsh = new TGeoCompositeShape("supsh","supPgon:trPgon-(hole:tr1+hole:tr2+hole:tr3+hole:tr4+hole:tr5+hole:tr6+hole:tr7+hole:tr8+hole:tr9+hole:tr10+hole:tr11+hole:tr12)");
262   
263     TGeoMedium *medal = gGeoManager->GetMedium("T0_Aluminium$");
264     TGeoVolume *supA = new TGeoVolume("0SUA",supsh,medal);
265     stlin->AddNode(supA,1,new TGeoTranslation(0,0,0));
266  
267     TGeoVolume *alice = gGeoManager->GetVolume("ALIC");
268     alice->AddNode(stlin,1,new TGeoTranslation(0,0, zdetA ));
269             
270     // T0A finished
271
272     //T0C 
273 // first ring: 12 units of Scintillator+PMT+divider
274   Float_t  theta  = (180 / TMath::Pi()) * TMath::ATan(6.5 / zdetC);
275   Float_t phi[3];
276    for (is=0; is<12; is++)
277       {  
278
279         x = 6.5 * TMath::Sin(is * angle);
280         y = 6.5 * TMath::Cos(is * angle);
281         
282         phi[0] = -30 * is;
283         phi[1] = 90 - is * 30;
284         phi[2] = 90 - is * 30;
285         for (Int_t j = 0; j < 3; j++)
286           if (phi[j] < 0)  phi[j] += 360;
287         
288         AliMatrix (idrotm[902 + is], 90.,         phi[0],
289                    90. + theta, phi[1],
290                    theta,       phi[2]);  
291         z=-pstart[2]+pinstart[2]+0.2;
292         gMC->Gspos ("0INS", is + 1, "0STR", x, y, z, idrotm[902 + is], "ONLY");
293   }     
294      
295    x=0;
296    y=0;
297     z=-pinstart[2]+ppmt[2]+psupport6[2]*2;
298    gMC->Gspos("0PMT",1,"0INS",x,y,z,0,"ONLY");
299    // PMT
300    
301    // Entry window (glass)
302    gMC->Gsvolu("0TOP","TUBE",idtmed[kOpGlass],ptop,3); //glass
303    z=-ppmt[2]+ptop[2];
304    gMC->Gspos("0TOP",1,"0PMT",0,0,z,0,"ONLY");
305    //"metal" air volume to simulate reclection  
306    gMC->Gsvolu("0TOO","TUBE",idtmed[kOpAir],ptopout,3); 
307    gMC->Gspos("0TOO",1,"0PMT",0,0,z,0,"ONLY");
308
309    //Fotokatod
310    gMC->Gsvolu ("0REG", "TUBE", idtmed[kOpGlassCathode], preg, 3); 
311    z = -ppmt[2] + 2 * ptop[2] + preg[2]; 
312    gMC->Gspos ("0REG", 1, "0PMT", 0, 0, z, 0, "ONLY"); 
313   // Bottom glass
314    gMC->Gsvolu("0BOT","TUBE",idtmed[kGlass],pbot,3);
315    z=ppmt[2]-pbot[2];
316    gMC->Gspos("0BOT",1,"0PMT",0,0,z,0,"ONLY");
317    // Side cylinder glass
318    gMC->Gsvolu("0OUT","TUBE",idtmed[kGlass],pglass,3);
319    z=ppmt[2]-pglass[2];
320    gMC->Gspos("0OUT",1,"0PMT",0,0,z,0,"ONLY");
321    //PMT electrodes support structure
322    gMC->Gsvolu("0CER","TUBE",idtmed[kCer],pcer,3);
323    gMC->Gsvolu("0STE","TUBE",idtmed[kSteel],psteel,3);
324    z=-ppmt[2]+2*ptop[2]+0.3 + pcer[2];
325    gMC->Gspos("0CER",1,"0PMT",0,0,z,0,"ONLY");
326    z +=psteel[2]+pcer[2];
327    gMC->Gspos("0STE",1,"0PMT",0,0,z,0,"ONLY");
328     
329    //Support absorber (C) side
330    z=-pstart[2]+psupport1[2]+0.1;
331    gMC->Gspos("0SU1",1,"0STR",0,0,z,0,"ONLY"); //C kozhuh snaruzhi
332    gMC->Gspos("0SU2",1,"0STR",0,0,z,0,"ONLY"); //C kozhuh vnutri
333    z=-pstart[2]+psupport3[2]+0.1;
334    gMC->Gspos("0SU3",1,"0STR",0,0,z,0,"ONLY"); //peredniaia kryshka
335    z=-pstart[2]+2.*psupport1[2]-0.05;//+0.1;
336    gMC->Gspos("0SU4",1,"0STR",0,0,z,0,"MANY"); //zadnaiai kryshka
337    gMC->Gspos("0SU6",1,"0INS",0,0,0,0,"ONLY");//C stakanchik dlia feu 
338    z=-pinstart[2]+psupport6[2];
339    gMC->Gspos("0SU7",1,"0INS",0,0,z,0,"ONLY"); //Al kryshechka 
340    
341    z=pinstart[2]-psupport7[2];
342    gMC->Gspos("0SU8",1,"0INS",0,0,z,0,"ONLY"); //Al kolechko
343    
344    
345    Float_t par[3];
346    par[0]=4.4;
347    par[1]=4.5;
348    par[2]=0.5;
349    gMC->Gsvolu("0SC0","TUBE",idtmed[kC],par,3);
350    z=ppcon[3]+par[2];
351    gMC->Gspos("0SC0",1,"0SUP",0,0,z,0,"ONLY"); 
352    z += par[2];
353    par[0]=4.4;
354    par[1]=5.1;
355    par[2]=0.05;
356    gMC->Gsvolu("0SC1","TUBE",idtmed[kC],par,3);
357    z += par[2];
358    gMC->Gspos("0SC1",1,"0SUP",0,0,z,0,"ONLY"); 
359    z=z+par[2];
360    par[0]=4.9;
361    par[1]=5.0;
362    par[2]=6.7/2;
363     gMC->Gsvolu("0SC2","TUBE",idtmed[kC],par,3);
364     z += par[2];
365     gMC->Gspos("0SC2",1,"0SUP",0,0,z,0,"ONLY"); 
366     z += par[2];
367    
368     par[0]=3.15;
369     par[1]=4.9;
370     par[2]=0.1/2;
371     gMC->Gsvolu("0SA1","TUBE",idtmed[kAl],par,3);
372     
373     z += par[2];
374     gMC->Gspos("0SA1",1,"0SUP",0,0,z,0,"ONLY"); 
375     z=z+par[2];
376     par[0]=3.15;
377     par[1]=3.16;
378     par[2]=4.7/2;
379     gMC->Gsvolu("0SA2","TUBE",idtmed[kAl],par,3);
380     z += par[2];
381     gMC->Gspos("0SA2",1,"0SUP",0,0,z,0,"ONLY"); 
382     z=z+par[2];
383     par[0]=3.16; // eta chast' prikruchena k absorberu
384     par[1]=7.5;
385     par[2]=0.1;
386     gMC->Gsvolu("0SA3","TUBE",idtmed[kAl],par,3);
387     z += par[2];
388     gMC->Gspos("0SA3",1,"0SUP",0,0,z,0,"ONLY"); 
389     par[0]=3.16; // gvozdi eta chast' prikruchena k absorberu
390     par[1]=7.5;
391     par[2]=0.01;
392     gMC->Gsvolu("0SN2","TUBE",idtmed[kSteel],par,3);
393     gMC->Gspos("0SN2",1,"0SUP",0,0,z,0,"ONLY"); 
394  
395    
396
397  
398 }    
399 //------------------------------------------------------------------------
400 void AliT0v1::AddAlignableVolumes() const
401 {
402   //
403   // Create entries for alignable volumes associating the symbolic volume
404   // name with the corresponding volume path. Needs to be syncronized with
405   // eventual changes in the geometry.
406   //
407
408   TString volPath;
409   TString symName, sn;
410
411   TString vpA  = "/ALIC_1/0STL_1/0INS_";
412   TString vpC  = "/ALIC_1/0STR_1/0INS_";
413   TString vpInside  = "/0PMT_1/0TOP_1";
414
415   for (Int_t imod=0; imod<24; imod++)
416     {
417       if (imod < 12) 
418         {volPath  = vpC; sn="T0/C/PMT";} 
419      else  
420        {volPath  = vpA; sn="T0/A/PMT";}
421       volPath += imod+1;
422       volPath += vpInside;
423       
424       symName = sn;
425       symName += imod+1;
426       
427       AliDebug(2,"--------------------------------------------");
428       AliDebug(2,Form("Alignable object %d", imod));
429       AliDebug(2,Form("volPath=%s\n",volPath.Data()));
430       AliDebug(2,Form("symName=%s\n",symName.Data()));
431       AliDebug(2,"--------------------------------------------");
432       if(!gGeoManager->SetAlignableEntry(symName.Data(),volPath.Data()))
433         AliFatal(Form("Alignable entry %s not created. Volume path %s not valid",   symName.Data(),volPath.Data()));
434       
435     }
436 }   
437 //------------------------------------------------------------------------
438 void AliT0v1::CreateMaterials()
439 {
440    Int_t isxfld   = gAlice->Field()->Integ();
441    Float_t sxmgmx = gAlice->Field()->Max();
442    //   Float_t a,z,d,radl,absl,buf[1];
443    // Int_t nbuf;
444    Int_t *idtmed = fIdtmed->GetArray();
445
446 // AIR
447                                                                                 
448    Float_t aAir[4]={12.0107,14.0067,15.9994,39.948};
449    Float_t zAir[4]={6.,7.,8.,18.};
450    Float_t wAir[4]={0.000124,0.755267,0.231781,0.012827};
451    Float_t dAir = 1.20479E-3;
452                                                                                 
453 // Scintillator CH
454    Float_t ascin[2]={1.01,12.01};
455    Float_t zscin[2]={1,6};
456    Float_t wscin[2]={1,1};
457    Float_t denscin=1.03;
458 //Lucite C(CH3)CO2CH3
459    Float_t alucite[3]={1.01,12.01,15.999};
460    Float_t zlucite[3]={1,6,8};
461    Float_t wlucite[3]={8,5,2};
462    Float_t denlucite=1.16;
463  // PMT glass SiO2
464    Float_t aglass[2]={28.0855,15.9994};
465    Float_t zglass[2]={14.,8.};
466    Float_t wglass[2]={1.,2.};
467    Float_t dglass=2.65;
468 // Ceramic   97.2% Al2O3 , 2.8% SiO2
469    // Float_t wcer[2]={0.972,0.028};
470    Float_t aCeramic[2]  = { 26.981539,15.9994 };
471    Float_t zCeramic[2]  = { 13.,8. };
472    Float_t wCeramic[2]  = { 2.,3. };
473    Float_t denscer  = 3.6;
474
475 // Brass 80% Cu, 20% Zn
476    Float_t abrass[2] = {63.546,65.39};
477    Float_t zbrass[2] = {29,30};
478    Float_t wbrass[2] = {0.8,0.2};
479    Float_t denbrass=8.96;
480
481 //Ribber C6H12S
482    Float_t aribber[3] = {12.,1.,32.};
483    Float_t zribber[3] = {6.,1.,16.};
484    Float_t wribber[3] = {6.,12.,1.};
485    Float_t denribber=0.8;
486 // Support inside 
487    Float_t asupport[2] = {12.,1.};
488    Float_t zsupport[2] = {6.,1.};
489    Float_t wsupport[2] = {1.,1.};
490    Float_t densupport=0.1;
491     
492 //*** Definition Of avaible T0 materials ***
493    AliMaterial(0, "Steel$", 55.850,26.,7.87,1.76,999);
494    AliMaterial(1, "Vacuum$", 1.e-16,1.e-16,1.e-16,1.e16,999);
495    AliMixture(2, "Air$", aAir, zAir, dAir,4,wAir);
496    AliMaterial(10, "CarbonPlastic$", 12.01, 6.0, 2.26, 18.8,999); 
497    AliMaterial(11, "Aliminium$", 26.98, 13.0, 2.7, 8.9,999); 
498
499    AliMixture( 3, "Ceramic  $",aCeramic, zCeramic, denscer, -2, wCeramic);
500    AliMixture( 4, "PMT glass   $",aglass,zglass,dglass,-2,wglass);
501    /* 
502   char namate[21]="";
503   
504    gMC->Gfmate((*fIdmate)[3], namate, a, z, d, radl, absl, buf, nbuf);
505    acer[0]=a;  
506
507    zcer[0]=z;
508    gMC->Gfmate((*fIdmate)[4], namate, a, z, d, radl, absl, buf, nbuf);
509    acer[1]=a;
510    zcer[1]=z;
511    AliMixture( 11, "Ceramic    $", acer, zcer, denscer, 2, wcer);
512    */ 
513     AliMixture( 5, "Scintillator$",ascin,zscin,denscin,-2,wscin);
514    AliMixture( 6, "Brass    $", abrass, zbrass, denbrass, 2, wbrass);
515    AliMixture( 7, "Ribber $",aribber,zribber,denribber,-3,wribber);
516    AliMixture( 8, "Lucite$",alucite,zlucite,denlucite,-3,wlucite);
517    AliMixture( 9, "Penoplast$",asupport,zsupport,densupport,-2,wsupport);
518    AliMixture( 21, "PMT Optical glass   $",aglass,zglass,dglass,-2,wglass);
519    AliMixture( 24, "PMT Optical glass cathode $",aglass,zglass,dglass,-2,wglass);
520     AliMixture(22, "T0 Opt Air$", aAir, zAir, dAir,4,wAir);
521    AliMixture(23, "T0 Opt Air Next$", aAir, zAir, dAir,4,wAir);
522    
523    AliMedium(1, "T0 Air$", 2, 0, isxfld, sxmgmx, 10., .1, 1., .003, .003);
524    AliMedium(2, "Scintillator$", 5, 1, isxfld, sxmgmx, 10., .01, 1., .003, .003);
525    AliMedium(3, "Vacuum$", 1, 0, isxfld, sxmgmx, 10., .01, .1, .003, .003);
526    AliMedium(4, "Ceramic$", 3, 0, isxfld, sxmgmx, 10., .01, .1, .003, .003);
527    AliMedium(6, "Glass$", 4, 1, isxfld, sxmgmx, 10., .01, .1, .003, .003);
528    AliMedium(8, "Steel$", 0, 0, isxfld, sxmgmx, 1., .001, 1., .001, .001);
529    AliMedium(9, "Ribber  $", 7, 0, isxfld, sxmgmx, 10., .01, .1, .003, .003);
530    AliMedium(11, "Brass  $", 6, 0, isxfld, sxmgmx, 10., .01, .1, .003, .003);
531    AliMedium(12, "Lucite$", 8, 1, isxfld, sxmgmx, 10., .01, 1., .003, .003);  
532    AliMedium(13, "CarbonPlastic$", 10, 0, isxfld, sxmgmx, 10., .01, 1., .003, .003);  
533    AliMedium(14, "PenoPlast$", 9, 0, isxfld, sxmgmx, 10., .01, 1., .003, .003);  
534    AliMedium(15, "Aluminium$", 11, 0, isxfld, sxmgmx, 10., .01, 1., .003, .003);  
535    AliMedium(16, "OpticalGlass$", 21, 1, isxfld, sxmgmx, 10., .01, .1, .003, .003);
536    AliMedium(17, "T0 OpAir$", 22, 0, isxfld, sxmgmx, 10., .1, 1., .003, .003);
537    AliMedium(18, "T0 OpAirNext$", 23, 0, isxfld, sxmgmx, 10., .1, 1., .003, .003);
538     AliMedium(19, "OpticalGlassCathode$", 24, 1, isxfld, sxmgmx, 10., .01, .1, .003, .003);
539
540
541 // Definition Cherenkov parameters
542    int i;
543    const Int_t kNbins=31;
544    
545    Float_t rindexSiO2[kNbins],  efficAll[kNbins], rindexAir[kNbins], absorAir[kNbins],rindexCathodeNext[kNbins], absorbCathodeNext[kNbins];
546             
547    // quartz 20mm
548    Float_t aAbsSiO2[kNbins]={29.0, 28.6, 28.3, 27.7, 27.3, 26.7, 26.4, 
549                              25.9, 25.3, 24.9, 24.5, 23.7, 
550                              23.2, 22.8, 22.4, 21.8, 21.3,
551                              22.8, 22.1, 21.7, 21.2, 20.5, 
552                              19.9, 19.3, 18.7, 18.0, 17.1, 
553                              16.3, 15.3, 14.3, 14.3   };
554           
555    Float_t aPckov[kNbins]  ={3.87, 3.94, 4.02, 4.11, 4.19, 4.29, 4.38,
556                              4.48, 4.58, 4.69, 4.81, 4.93, 
557                              5.05, 5.19, 5.33, 5.48, 5.63,
558                              5.8,  5.97, 6.16, 6.36, 6.57, 
559                              6.8,  7.04, 7.3,  7.58, 7.89, 
560                              8.22, 8.57, 8.97, 9.39 };  
561    /*     
562    Float_t effCathode[kNbins]={0.11, 0.13, 0.15, 0.16, 0.18, 0.19, 0.20,
563                               0.21, 0.22, 0.23, 0.24, 0.26, 
564                               0.27, 0.29, 0.30, 0.29, 0.29, 
565                               0.28, 0.28, 0.27, 0.26, 0.25, 
566                               0.25, 0.23, 0.20, 0.19, 0.17,
567                               0.17, 0.17, 0.2, 0.23};
568    */     
569    //  Float_t aAbsSiO2[kNbins]; //quartz 30mm
570   for(i=0;i<kNbins;i++)
571     {
572       aPckov[i]=aPckov[i]*1e-9;//Photons energy bins 4 eV - 8.5 eV step 0.1 eV   
573       rindexAir[i]=0;
574       rindexSiO2[i]=1.458; //refractive index for qwarts
575       rindexCathodeNext[i]=0;
576       efficAll[i]=1.;
577
578       //      aAbsSiO2[i]=28.5; //quartz 30mm
579       absorAir[i]=0.3;      
580       absorbCathodeNext[i]=0;
581
582     }
583   
584   
585    gMC->SetCerenkov (idtmed[kOpGlass], kNbins, aPckov, aAbsSiO2, efficAll, rindexSiO2 );
586    // gMC->SetCerenkov (idtmed[kOpGlassCathode], kNbins, aPckov, aAbsSiO2, effCathode, rindexSiO2 );
587    gMC->SetCerenkov (idtmed[kOpGlassCathode], kNbins, aPckov, aAbsSiO2,efficAll , rindexSiO2 );
588   gMC->SetCerenkov (idtmed[kOpAir], kNbins, aPckov,absorAir , efficAll,rindexAir );
589    gMC->SetCerenkov (idtmed[kOpAirNext], kNbins, aPckov,absorbCathodeNext , efficAll, rindexCathodeNext);
590    
591    AliDebugClass(1,": ++++++++++++++Medium set++++++++++");
592    
593    
594 }
595 //---------------------------------------------------------------------
596 void AliT0v1::DrawDetector()
597 {
598 //
599 // Draw a shaded view of the Forward multiplicity detector version 0
600 //
601   
602   //Set ALIC mother transparent
603   gMC->Gsatt("ALIC","SEEN",0);
604   //
605   //Set volumes visible
606   //  gMC->Gsatt("0STR","SEEN",0);
607   //  gMC->Gsatt("0INS","SEEN",0);
608   // gMC->Gsatt("0PMT","SEEN",1);
609   // gMC->Gsatt("0DIV","SEEN",1);
610   //
611   gMC->Gdopt("hide","off");
612   gMC->Gdopt("shad","on");
613   gMC->SetClipBox(".");
614   gMC->SetClipBox("*",0,1000,-1000,1000,-1000,1000);
615   gMC->DefaultRange();
616   gMC->Gdraw("alic",90,0,0,-35,9.5,.6,0.6);
617   //gMC->Gdraw("alic",0,0,0,10,9.5,.8,0.8); //other side view
618   gMC->Gdhead(1111,"T-Zero detector");
619   gMC->Gdopt("hide","off");
620 }
621
622 //-------------------------------------------------------------------
623 void AliT0v1::Init()
624 {
625 // Initialises version 0 of the Forward Multiplicity Detector
626 //
627 //Int_t *idtmed  = gAlice->Idtmed();
628   AliT0::Init();
629   fIdSens1=gMC->VolId("0REG");
630
631    AliDebug(1,Form("%s: *** T0 version 1 initialized ***\n",ClassName()));
632
633 }
634
635 //-------------------------------------------------------------------
636
637 void AliT0v1::StepManager()
638 {
639   //
640   // Called for every step in the T0 Detector
641   //
642   Int_t id,copy,copy1;
643   static Float_t hits[6];
644   static Int_t vol[2];
645   TLorentzVector pos;
646   
647   //   TClonesArray &lhits = *fHits;
648   
649   if(!gMC->IsTrackAlive()) return; // particle has disappeared
650   
651   
652     // If particles is photon then ...
653   
654  if (gMC->TrackPid() == 50000050)
655   {
656       id=gMC->CurrentVolID(copy);
657       
658       
659       // Check the sensetive volume
660       if(id==fIdSens1 ) { 
661         if(gMC->IsTrackEntering()) {
662             gMC->CurrentVolOffID(2,copy);
663             vol[1]=copy;
664             gMC->CurrentVolOffID(3,copy1);
665             vol[0]=copy1;
666             gMC->TrackPosition(pos);
667             hits[0] = pos[0];
668             hits[1] = pos[1];
669             hits[2] = pos[2];
670             if(pos[2]<0) vol[0]=2;
671             if(pos[2]>=0) vol[0]=1; 
672             
673             Float_t etot=gMC->Etot();
674             hits[3]=etot;
675             Int_t iPart= gMC->TrackPid();
676             Int_t partID=gMC->IdFromPDG(iPart);
677             hits[4]=partID;
678             Float_t ttime=gMC->TrackTime();
679             hits[5]=ttime*1e12;
680             if(RegisterPhotoE(vol[1]-1,hits[3])) 
681               AddHit(fIshunt,vol,hits);
682             
683           }
684           //  cout<< gAlice->GetMCApp()->GetCurrentTrackNumber()<<" hit added "<<endl;
685         
686         /*              
687                 printf("track(%i) alive(%i) disap(%i) enter(%i) exit(%i) inside(%i) out(%i) stop(%i) new(%i) \n",
688                        gAlice->GetMCApp()->GetCurrentTrackNumber(),
689                gMC->IsTrackAlive(),
690                gMC->IsTrackDisappeared(),
691                gMC->IsTrackEntering(),
692                gMC->IsTrackExiting(),
693                gMC->IsTrackInside(),
694                gMC->IsTrackOut(),
695                gMC->IsTrackStop(),
696                gMC->IsNewTrack());
697         */              
698       } //sensitive
699   } //photon
700 }
701
702
703
704 //------------------------------------------------------------------------
705 Bool_t AliT0v1::RegisterPhotoE(Int_t ipmt,Double_t energy)
706 {
707
708   
709   //  Float_t hc=197.326960*1.e6; //mev*nm
710   Double_t hc=1.973*1.e-6; //gev*nm
711   Float_t lambda=hc/energy;
712   Float_t eff = ((TGraph*) fEffPMT.At(ipmt))->Eval(lambda);
713   Double_t  p = gRandom->Rndm();
714
715   if (p > eff)
716     return kFALSE;
717   
718   return kTRUE;
719 }
720
721 //----------------------------------------------------------------------------
722
723
724
725
726
727