]> git.uio.no Git - u/mrichter/AliRoot.git/blob - VZERO/AliVZEROv6.cxx
Containers removed and replaced by Assemblies
[u/mrichter/AliRoot.git] / VZERO / AliVZEROv6.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 //  (V-zero) detector  version 6  as designed by the Lyon group     //
21 //   All comments should be sent to Brigitte CHEYNIS :              //
22 //                                  b.cheynis@ipnl.in2p3.fr         // 
23 //   Geometry of september 2005 done with ROOT geometrical modeler  //                                  //
24 //   V0R (now V0C) sits between Z values  -89.5 and  -84.8 cm       //
25 //   V0L (now V0A) sits between Z values +339.0 and +341.0 cm       //
26 //   New coordinate system has been implemented in october 2003     //
27 //                                                                  //
28 //////////////////////////////////////////////////////////////////////
29
30 // --- Standard libraries ---
31 #include <Riostream.h>
32 #include <stdlib.h>
33 #include <string.h>
34
35 // --- ROOT libraries ---
36 #include <TClonesArray.h>
37 #include <TGeometry.h>
38 #include <TLorentzVector.h>
39 #include <TMath.h>
40 #include <TNode.h>
41 #include <TObjectTable.h>
42 #include <TVirtualMC.h>
43 #include <TParticle.h>
44
45 #include <TGeoManager.h>
46 #include <TGeoMaterial.h>
47 #include <TGeoMedium.h>
48 #include <TGeoNode.h>
49 #include <TGeoVolume.h>
50 #include "TGeoTube.h"
51 #include "TGeoMatrix.h"
52
53 // --- AliRoot header files ---
54 #include "AliRun.h"
55 #include "AliMC.h"
56 #include "AliConst.h"
57 #include "AliMagF.h"
58 #include "AliVZEROLoader.h"
59 #include "AliVZEROdigit.h"
60 #include "AliVZEROhit.h"
61 #include "AliVZEROv6.h"
62 #include "AliLog.h"
63  
64 ClassImp(AliVZEROv6)
65
66 //_____________________________________________________________________________
67 AliVZEROv6:: AliVZEROv6():AliVZERO()
68 {
69 // Standard default constructor 
70 }
71
72 //_____________________________________________________________________________
73 AliVZEROv6::AliVZEROv6(const char *name, const char *title):
74  AliVZERO(name,title)
75 {
76
77 // Standard constructor for V-zero Detector  version 6
78
79   AliDebug(2,"Create VZERO object ");
80   
81   fVersion            =     6;  // version number
82   
83 // Parameters related to geometry :
84 // V0 part in front of muon arm absorber 
85
86   fV0CHeight1         =    2.5; // height of cell 1, in cm
87   fV0CHeight2         =    4.4; // height of cell 2, in cm
88   fV0CHeight3         =    7.4; // height of cell 3, in cm
89   fV0CHeight4         =   12.5; // height of cell 4, in cm
90   fV0CRMin            =    4.6; 
91   fV0CRBox            =   38.0; // outer radius of box, in cm
92   fV0CLidThickness    =   0.30; // thickness of Carbon lid
93   fV0CCellThickness   =   2.00; // thickness of elementary cell
94   fV0CBoxThickness    =   4.70; // thickness of V0C Box
95   fV0COffsetFibers    =    1.0; // offset to output fibers, in cm
96
97 // V0 part on the other side with respect to Interaction Point
98
99   fV0AHeight1         =    3.3; // height of cell 1, in cm
100   fV0AHeight2         =    6.2; // height of cell 2, in cm
101   fV0AHeight3         =    8.9; // height of cell 3, in cm
102   fV0AHeight4         =   20.9; // height of cell 4, in cm
103   fV0ARMin            =   4.30; 
104   fV0ACellThickness   =   2.00; // thickness of elementary cell  
105   
106 // Parameters related to light output :
107          
108   fLightYield         =  93.75; // Light yield in BC408 (93.75 eV per photon)
109   fLightAttenuation   =   0.05; // Light attenuation in fiber (0.05 per meter)
110   fnMeters            =   15.0; // Number of meters of clear fibers to PM
111   fFibToPhot          =    0.3; // Attenuation at fiber-photocathode interface
112 }
113      
114 //_____________________________________________________________________________
115
116 void AliVZEROv6::BuildGeometry()
117
118           
119 }
120             
121 //_____________________________________________________________________________
122 void AliVZEROv6::CreateGeometry()
123 {
124   
125 // Constructs TGeo geometry 
126
127   const int kColorVZERO  = kGreen;  
128   
129   AliDebug(2,"VZERO ConstructGeometry");
130   
131   TGeoManager *geoManager = gGeoManager;
132 //  TGeoMedium  *medAir = gGeoManager->GetMedium("VZERO_Air"); 
133   TGeoMedium  *medAlu = gGeoManager->GetMedium("VZERO_Aluminum");
134   TGeoMedium  *medCar = gGeoManager->GetMedium("VZERO_Carbon");
135   TGeoMedium  *medSci = gGeoManager->GetMedium("VZERO_Scintillator");
136     
137   TGeoVolume *top = gGeoManager->GetVolume("ALIC");
138   
139   Float_t  heightRight, r4Right;
140   
141   Float_t  zdet   =    90.0 - 0.5 - fV0CBoxThickness/2.0;
142   heightRight     =    fV0CHeight1 + fV0CHeight2 + fV0CHeight3 + fV0CHeight4;
143   r4Right         =    fV0CRMin + heightRight + 3.0*0.2;  // 3 spacings of 2mm between rings
144
145 // Creation of assembly V0RI - right part - :
146
147   TGeoVolume *v0RI = new TGeoVolumeAssembly("V0RI");  
148   TGeoTranslation *tr1 = new TGeoTranslation(0.,0.,-zdet);
149   top->AddNode(v0RI,1,tr1);
150
151 // Creation of  carbon lids (3.0 mm thick) to keep V0C box shut :
152     
153   Float_t   partube[3];
154   
155   partube[0] =   fV0CRMin;
156   partube[1] =   fV0CRBox;
157   partube[2] =   fV0CLidThickness/2.0;
158   
159   TGeoTube   *sV0CA = new TGeoTube("V0CA", partube[0], partube[1], partube[2]);
160   TGeoVolume *v0CA  = new TGeoVolume("V0CA",sV0CA,medCar);
161   TGeoTranslation *tr2 = new TGeoTranslation(0.,0., fV0CBoxThickness/2.0-partube[2]);
162   TGeoTranslation *tr3 = new TGeoTranslation(0.,0.,-fV0CBoxThickness/2.0+partube[2]);
163   v0RI->AddNode(v0CA,1,tr2);
164   v0RI->AddNode(v0CA,2,tr3);
165   v0CA->SetLineColor(kYellow);
166   
167 // Creation of aluminum rings 3.0 mm thick to maintain the v0RI pieces : 
168  
169   partube[0] =   fV0CRMin - 0.3;
170   partube[1] =   fV0CRMin;
171   partube[2] =   fV0CBoxThickness/2.0;
172   
173   TGeoTube   *sV0IR = new TGeoTube("V0IR", partube[0], partube[1], partube[2]);
174   TGeoVolume *v0IR  = new TGeoVolume("V0IR",sV0IR,medAlu);
175   v0RI->AddNode(v0IR,1,0);
176   v0IR->SetLineColor(kYellow);
177   
178   partube[0] =   fV0CRBox;
179   partube[1] =   fV0CRBox + 0.3; 
180   partube[2] =   fV0CBoxThickness/2.0;
181
182   TGeoTube   *sV0ER = new TGeoTube("V0ER", partube[0], partube[1], partube[2]);
183   TGeoVolume *v0ER  = new TGeoVolume("V0ER",sV0ER,medAlu);
184   v0RI->AddNode(v0ER,1,0);
185   v0ER->SetLineColor(kYellow);
186   
187 // Creation of assembly V0R0 of scintillator cells within one sector
188  
189   TGeoVolume *v0R0 = new TGeoVolumeAssembly("V0R0");                                      
190                                                  
191 // Elementary cell of ring 1  - right part - :
192 // (cells of ring 1 will be shifted by 2.0 cm backwards to output fibers)
193                                                   
194   Float_t   r1Right =  fV0CRMin + fV0CHeight1;
195   Float_t   offset  = fV0CBoxThickness/2.0 - fV0CLidThickness - fV0CCellThickness/2.0;   
196
197   Float_t   partubs[5];   
198      
199   partubs[0]     =  fV0CRMin;
200   partubs[1]     =  r1Right;
201   partubs[2]     =  fV0CCellThickness/2.0;
202   partubs[3]      =  90.0-22.5;
203   partubs[4]      = 135.0-22.5;
204   
205   TGeoTubeSeg  *sV0R1 = new TGeoTubeSeg("V0R1", partubs[0], partubs[1], partubs[2], 
206                                                 partubs[3], partubs[4]);
207   TGeoVolume   *v0R1  =  new TGeoVolume("V0R1",sV0R1,medSci);                                  
208   TGeoTranslation *tr4 = new TGeoTranslation(0.,0.,-offset);
209   v0R0->AddNode(v0R1,1,tr4);
210   v0R1->SetLineColor(kColorVZERO);
211
212 // Elementary cell of ring 2 - right part - :
213 // (cells of ring 2 will be shifted by 1.0 cm backwards to output fibers)
214
215   Float_t   r2Right  =  r1Right + fV0CHeight2;  
216
217   partubs[0]     =  r1Right;  //  must be equal to 7.1
218   partubs[1]     =  r2Right;  //  must be equal to 11.5
219   TGeoTubeSeg *sV0R2 = new TGeoTubeSeg("V0R2", partubs[0], partubs[1], partubs[2], 
220                                                partubs[3], partubs[4]);
221   TGeoVolume  *v0R2  = new TGeoVolume("V0R2",sV0R2,medSci);                                                   
222   TGeoTranslation *tr5 = new TGeoTranslation(0.0,0.2,-offset + fV0COffsetFibers);                                             
223   v0R0->AddNode(v0R2,1,tr5);
224   v0R2->SetLineColor(kColorVZERO);
225    
226 // Ring 3 - right part -  :
227
228 //  Float_t   x = TMath::ATan(1.0/156.0) * ((180./TMath::Pi()));
229   
230   r2Right  =  r2Right + 0.2;
231   Float_t   r3Right  =  r2Right + fV0CHeight3;     
232 //  printf(" r2 = %f, r3 = %f \n\n", r2Right,r3Right); 
233   
234   partubs[0]     =  r2Right;  //  must be equal to 11.7
235   partubs[1]     =  r3Right;  //  must be equal to 19.1
236   partubs[3]     =  90.0-22.5;
237   partubs[4]     = 112.5-22.5;
238   
239   TGeoTubeSeg *sV0R3 = new TGeoTubeSeg("V0R3", partubs[0], partubs[1], partubs[2], 
240                                                partubs[3], partubs[4]); 
241   TGeoVolume  *v0R3  = new TGeoVolume("V0R3",sV0R3,medSci);                                           
242   TGeoTranslation *tr6 = new TGeoTranslation(0.,0.2,-offset + 2.0*fV0COffsetFibers);                                           
243   v0R0->AddNode(v0R3,1,tr6);
244   v0R3->SetLineColor(kColorVZERO);
245  
246   partubs[3]     = 112.5-22.5;
247   partubs[4]     = 135.0-22.5;
248   
249   TGeoTubeSeg *sV0R4 = new TGeoTubeSeg("V0R4", partubs[0], partubs[1], partubs[2], 
250                                                partubs[3], partubs[4]);  
251   TGeoVolume  *v0R4  = new TGeoVolume("V0R4",sV0R4,medSci);                                                                                   
252   v0R0->AddNode(v0R4,1,tr6);
253   v0R4->SetLineColor(kColorVZERO);
254   
255 // Ring 4 - right part -  : 
256
257   Float_t x = TMath::ATan(3.5/257.5) * ((180./TMath::Pi()));
258   r3Right = r3Right + 0.2 + 0.2;   // + 0.2 because no shift in translation here !!
259    
260   partubs[0]     =  r3Right;  //  must be equal to 19.5
261   partubs[1]     =  r4Right;  //  must be equal to 32.0
262   partubs[3]     =  90.0-22.5+x;
263   partubs[4]     = 112.5-22.5-x;
264   
265   TGeoTubeSeg *sV0R5 = new TGeoTubeSeg("V0R5", partubs[0], partubs[1], partubs[2], 
266                                                partubs[3], partubs[4]);
267   TGeoVolume  *v0R5  = new TGeoVolume("V0R5",sV0R5,medSci);
268   TGeoTranslation *tr7 = new TGeoTranslation(0.,0.0,-offset + 2.0*fV0COffsetFibers);                                          
269   v0R0->AddNode(v0R5,1,tr7);
270   v0R5->SetLineColor(kColorVZERO);
271   
272   partubs[3]     = 112.5-22.5+x;
273   partubs[4]     = 135.0-22.5-x;
274   
275   TGeoTubeSeg *sV0R6 = new TGeoTubeSeg("V0R6", partubs[0], partubs[1], partubs[2], 
276                                                partubs[3], partubs[4]);
277   TGeoVolume  *v0R6  = new TGeoVolume("V0R6",sV0R6,medSci);                                                   
278   v0R0->AddNode(v0R6,1,tr7);
279   v0R6->SetLineColor(kColorVZERO);
280   
281   Float_t  phi;
282   Float_t  phiDeg= 180./4.;
283     
284   Int_t    nsecR = 1;     // number of sectors in right part of V0
285   Int_t    ncellsR;       // number of scintillating cells 
286  
287   for (phi = 22.5; phi < 360.0; phi = phi + phiDeg)
288   
289   {              
290     TGeoRotation  *rot1 = new TGeoRotation("rot1", 90.0, +phi, 90., 90.+phi, 0.0, 0.0 ); 
291     
292     v0RI->AddNode(v0R0,nsecR,rot1);    
293     nsecR++;        
294   } 
295      
296   ncellsR = (nsecR - 1) * 6;    // 6 cells per sector (2 cells in  ring 3 and 4)  
297   AliInfo(Form("Number of cells on Right side  - V0C =   %d",  ncellsR)); 
298   
299 // Creation of assembly v0LE - left part - :
300 // Entrance face at  +339.0 cm  (new coordinate system) ...
301           
302   Float_t   heightLeft  = fV0AHeight1 + fV0AHeight2 + fV0AHeight3 + fV0AHeight4;   
303   Float_t   r4Left      = fV0ARMin + heightLeft; 
304  
305   TGeoVolume *v0LE = new TGeoVolumeAssembly("V0LE"); 
306    
307   TGeoTranslation *tr8 = new TGeoTranslation(0.,0.,339.0 + fV0ACellThickness/2.0);
308   top->AddNode(v0LE,1,tr8);
309   
310 // Creation of assembly V0L0 of scintillator cells within one sector 
311   
312   TGeoVolume *v0L0 = new TGeoVolumeAssembly("V0L0");                                      
313    
314   Float_t   offsetLeft;
315   offsetLeft    = - fV0ACellThickness/2.0; 
316
317   Float_t   r1Left =  fV0ARMin + fV0AHeight1;        
318       
319   partubs[0]     =  fV0ARMin;
320   partubs[1]     =  r1Left;
321   partubs[2]      =  fV0ACellThickness/2.0;
322   partubs[3]      =  90.0-22.5;
323   partubs[4]      = 135.0-22.5;
324   
325   TGeoTubeSeg  *sV0L1 = new TGeoTubeSeg("V0L1", partubs[0], partubs[1], partubs[2], 
326                                                 partubs[3], partubs[4]);
327   TGeoVolume   *v0L1  =  new TGeoVolume("V0L1",sV0L1,medSci);                                  
328   v0L0->AddNode(v0L1,1,gGeoIdentity);
329   v0L1->SetLineColor(kColorVZERO);
330   v0L1->SetVisibility(kTRUE);
331          
332   Float_t   r2Left =  r1Left + fV0AHeight2;       
333   
334   partubs[0]     =  r1Left;
335   partubs[1]     =  r2Left;
336   
337   TGeoTubeSeg  *sV0L2 = new TGeoTubeSeg("V0L2", partubs[0], partubs[1], partubs[2], 
338                                                 partubs[3], partubs[4]);
339   TGeoVolume   *v0L2  =  new TGeoVolume("V0L2",sV0L2,medSci);                                  
340   v0L0->AddNode(v0L2,1,gGeoIdentity);
341   v0L2->SetLineColor(kColorVZERO);
342   v0L2->SetVisibility(kTRUE);
343
344   Float_t   r3Left =  r2Left + fV0AHeight3; 
345    
346   partubs[0]     =  r2Left;
347   partubs[1]     =  r3Left;
348   
349   TGeoTubeSeg  *sV0L3 = new TGeoTubeSeg("V0L3", partubs[0], partubs[1], partubs[2], 
350                                                 partubs[3], partubs[4]);
351   TGeoVolume   *v0L3  =  new TGeoVolume("V0L3",sV0L3,medSci);                                  
352   v0L0->AddNode(v0L3,1,gGeoIdentity);
353   v0L3->SetLineColor(kColorVZERO);
354   v0L3->SetVisibility(kTRUE);
355
356   partubs[0]     =  r3Left;
357   partubs[1]     =  r4Left;
358
359   TGeoTubeSeg  *sV0L4 = new TGeoTubeSeg("V0L4", partubs[0], partubs[1], partubs[2], 
360                                                 partubs[3], partubs[4]);
361   TGeoVolume   *v0L4  =  new TGeoVolume("V0L4",sV0L4,medSci);                                  
362   v0L0->AddNode(v0L4,1,gGeoIdentity);
363   v0L4->SetLineColor(kColorVZERO);
364   v0L4->SetVisibility(kTRUE);
365
366   Int_t    nsecL = 1;     // number of sectors in left part of V0
367   Int_t    ncellsL;       // number of scintillating cells 
368   
369   for (phi = 22.5; phi < 360.0; phi = phi + phiDeg)
370   
371   {                  
372     TGeoRotation  *rot1 = new TGeoRotation("rot1", 90.0, +phi, 90., 90.+phi, 0.0, 0.0 ); 
373     v0LE->AddNode(v0L0,nsecL,rot1);    
374     nsecL++;        
375   } 
376      
377   ncellsL = (nsecL - 1) * 4;    // 4 cells per sector
378   AliInfo(Form("Number of cells on Left  side  - V0A =   %d\n",  ncellsL));
379  
380   gGeoManager->CloseGeometry();  
381 //  gGeoManager-> SetVisLevel(4);
382   geoManager->Export("VZEROGeometry.root"); 
383 }  
384     
385 //_____________________________________________________________________________
386 void AliVZEROv6::CreateMaterials()
387 {
388
389 // Creates materials used for geometry 
390
391    AliDebug(2,"Create materials");
392
393 //   Int_t  *idtmed = fIdtmed->GetArray()-2999;
394       
395    Int_t     fieldType       = gAlice->Field()->Integ();     // Field type 
396    Double_t  maxField        = gAlice->Field()->Max();       // Field max.
397    Double_t  maxBending      = 0;     // Max Angle
398    Double_t  maxStepSize     = 0.001; // Max step size 
399    Double_t  maxEnergyLoss   = 1;     // Max Delta E
400    Double_t  precision       = 0.001; // Precision
401    Double_t  minStepSize     = 0.001; // Minimum step size 
402    Int_t     id;
403    Double_t  a, z, density, radLength, absLength; 
404    Float_t   tmaxfd, stemax, deemax, epsil, stmin;
405    
406    a = 0.0; z = 0.0; 
407    density    = 0.0;
408    radLength  = 0.0; 
409    absLength  = 999.0;
410    tmaxfd     = 10.;
411    stemax     = 0.1;
412    deemax     = 0.1;     
413    epsil      = 0.001;
414    stmin      = 0.001;
415    
416 // Parameters  for Air (=  0.01% C + 75% N + 23% O + 1% Ar )
417
418     Float_t aa[] = { 12.0107, 14.0067,   15.9994,  39.948 };
419     Float_t za[] = {  6.,      7.,       8.,       18. };
420     Float_t wa[] = { 0.000124, 0.755267, 0.231781, 0.012827 }; 
421     density      = 0.00120479;
422     maxBending   = 1;
423     maxStepSize  = .001;
424     precision    = .001;
425     minStepSize  = .001;
426     id           = 1;
427     AliMixture(id, "Air", aa, za, density, 4, wa);
428     AliMedium(id, "Air", id, 1, fieldType, maxField, maxBending,
429                          maxStepSize, maxEnergyLoss, precision, minStepSize);
430                         
431 // Parameters  for Aluminum
432  
433     a = 26.98; 
434     z = 13.00;
435     density    = 2.7;
436     radLength  = 8.9;
437     maxBending  = 10;
438     maxStepSize = .01;
439     precision   = .003;
440     minStepSize = .003;
441     id = 2;
442     AliMaterial( id, "Aluminum", a, z, density, radLength, 37.2, 0, 0);
443     AliMedium(id, "Aluminum", id, 1, fieldType, maxField, maxBending,
444                               maxStepSize, maxEnergyLoss, precision, minStepSize);
445                     
446 // Parameters  for Carbon 
447
448     a = 12.01; 
449     z =  6.00;
450     density     = 2.265;
451     radLength   = 18.8;
452     id = 3;
453     AliMaterial(id, "Carbon",  a, z, density, radLength, 49.9, 0, 0);
454     AliMedium(id,   "Carbon", id, 1, fieldType, maxField, maxBending,
455                               maxStepSize, maxEnergyLoss, precision, minStepSize);
456                     
457 // Parameters  for scintillator 
458
459     Float_t as[] = { 1.00794, 12.011};
460     Float_t zs[] = { 1.,  6.};
461     Float_t ws[] = { 1.,  1.};
462     density      = 1.032;
463     maxBending   = 10;
464     maxStepSize  = .01;
465     precision    = .003;
466     minStepSize  = .003;
467     id           = 4;
468     AliMixture(id, "Scintillator", as, zs, density, -2, ws);
469     AliMedium(id,  "Scintillator", id, 1, fieldType, maxField, maxBending,
470                                    maxStepSize,maxEnergyLoss,precision,minStepSize);
471
472                                                              
473 }
474
475 //_____________________________________________________________________________
476 void AliVZEROv6::DrawModule() const
477 {
478
479 //  Drawing is done in DrawVZERO.C
480
481    AliDebug(2,"DrawModule");
482 }
483
484
485 //_____________________________________________________________________________
486 void AliVZEROv6::DrawGeometry() 
487 {
488
489 //  Drawing of V0 geometry done in DrawV0.C
490
491    AliDebug(2,"DrawGeometry");
492  
493 //  Here is  DrawV0.C :
494
495 // void DrawV0()
496 // {
497 //    TGeoVolume *top = gGeoManager->GetMasterVolume();
498 //    gGeoManager->SetNsegments(80);
499 //    Int_t nd = top->GetNdaughters();
500 //    for (Int_t i=0; i<nd; i++) top->GetNode(i)->GetVolume()->InvisibleAll();
501 //    TGeoVolume *v0ri = gGeoManager->GetVolume("V0RI");  
502 //    TGeoVolume *v0le = gGeoManager->GetVolume("V0LE");
503 //    v0ri->SetVisibility(kTRUE);
504 //    v0ri->VisibleDaughters(kTRUE);
505 //    v0le->SetVisibility(kTRUE);
506 //    v0le->VisibleDaughters(kTRUE);
507 //    top->SetVisibility(kTRUE);
508 //    top->Draw();
509 // }
510    
511 }
512
513 //_____________________________________________________________________________
514 void AliVZEROv6::Init()
515 {
516 // Initialises version of the VZERO Detector given in Config
517 // Just prints an information message
518   
519    AliInfo(Form("VZERO version %d initialized \n",IsVersion()));
520    
521    AliVZERO::Init();  
522 }
523
524 //_____________________________________________________________________________
525 void AliVZEROv6::StepManager()
526 {
527  
528 // Step Manager, called at each step 
529  
530      Int_t     copy;
531      static    Int_t   vol[4];
532      static    Float_t hits[21];
533      static    Float_t eloss, tlength;
534      static    Int_t   nPhotonsInStep;
535      static    Int_t   nPhotons; 
536      static    Int_t   numStep;
537      Float_t   ringNumber;
538      Float_t   destep, step;
539      
540      numStep += 1; 
541           
542 //   We keep only charged tracks :
543      
544      if ( !gMC->TrackCharge() || !gMC->IsTrackAlive() ) return; 
545
546      vol[0]    = gMC->CurrentVolOffID(1, vol[1]);
547      vol[2]    = gMC->CurrentVolID(copy);
548      vol[3]    = copy;
549      
550      static Int_t idV0R1 = gMC->VolId("V0R1");
551      static Int_t idV0L1 = gMC->VolId("V0L1");
552      static Int_t idV0R2 = gMC->VolId("V0R2");
553      static Int_t idV0L2 = gMC->VolId("V0L2");
554      static Int_t idV0R3 = gMC->VolId("V0R3");
555      static Int_t idV0L3 = gMC->VolId("V0L3");
556      static Int_t idV0R4 = gMC->VolId("V0R4");
557      static Int_t idV0L4 = gMC->VolId("V0L4");
558      static Int_t idV0R5 = gMC->VolId("V0R5");
559      static Int_t idV0R6 = gMC->VolId("V0R6");
560    
561      if      ( gMC->CurrentVolID(copy) == idV0R1 ||
562                gMC->CurrentVolID(copy) == idV0L1 )
563                ringNumber = 1.0;
564      else if ( gMC->CurrentVolID(copy) == idV0R2 ||
565                gMC->CurrentVolID(copy) == idV0L2 ) 
566                ringNumber = 2.0;  
567      else if ( gMC->CurrentVolID(copy) == idV0R3 ||
568                gMC->CurrentVolID(copy) == idV0R4 ||
569                gMC->CurrentVolID(copy) == idV0L3 )
570                ringNumber = 3.0;
571      else if ( gMC->CurrentVolID(copy) == idV0R5 ||
572                gMC->CurrentVolID(copy) == idV0R6 ||
573                gMC->CurrentVolID(copy) == idV0L4 )
574                ringNumber = 4.0;               
575      else
576                ringNumber = 0.0;
577                
578  
579      if  (  ringNumber > 0.5  ) { 
580      
581         destep    = gMC->Edep();
582         step      = gMC->TrackStep();
583         
584         nPhotonsInStep  = Int_t(destep / (fLightYield *1e-9) ); 
585         nPhotonsInStep  = gRandom->Poisson(nPhotonsInStep);
586         
587         eloss    += destep;
588         tlength  += step;        
589         
590         if  ( gMC->IsTrackEntering()  )  { 
591          
592             nPhotons  =  nPhotonsInStep;       
593             gMC->TrackPosition(fTrackPosition);
594             gMC->TrackMomentum(fTrackMomentum);
595             
596             Float_t pt  = TMath::Sqrt( fTrackMomentum.Px() * fTrackMomentum.Px() +
597                                        fTrackMomentum.Py() * fTrackMomentum.Py() );
598                
599             hits[0]  = fTrackPosition.X();
600             hits[1]  = fTrackPosition.Y();
601             hits[2]  = fTrackPosition.Z();               
602             hits[3]  = Float_t (gMC->TrackPid()); 
603
604             hits[4]  = gMC->TrackTime();
605             hits[5]  = gMC->TrackCharge();
606             hits[6]  = fTrackMomentum.Theta()*TMath::RadToDeg();
607             hits[7]  = fTrackMomentum.Phi()*TMath::RadToDeg();
608             hits[8]  = ringNumber;
609          
610             hits[9]  = pt;
611             hits[10] = fTrackMomentum.P();
612             hits[11] = fTrackMomentum.Px();
613             hits[12] = fTrackMomentum.Py();
614             hits[13] = fTrackMomentum.Pz();
615             
616             TParticle *par = gAlice->GetMCApp()->Particle(gAlice->GetMCApp()->GetCurrentTrackNumber());
617             hits[14] = par->Vx();
618             hits[15] = par->Vy();
619             hits[16] = par->Vz();
620             
621             tlength  = 0.0;
622             eloss    = 0.0;         
623          }
624          
625          nPhotons  = nPhotons + nPhotonsInStep;
626          
627          if( gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()){
628          
629          nPhotons  = nPhotons - Int_t((Float_t(nPhotons) * fLightAttenuation * fnMeters));       
630          nPhotons  = nPhotons - Int_t( Float_t(nPhotons) * fFibToPhot);  
631          
632          hits[17] =   eloss;
633          hits[18] = tlength;
634          hits[19] = nPhotons;
635          hits[20] = GetCellId (vol, hits); 
636                  
637          AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol, hits);
638                  
639          tlength         = 0.0;
640          eloss           = 0.0; 
641          nPhotons        =   0;
642          nPhotonsInStep  =   0;
643          
644          numStep         =   0;  
645          } 
646     }
647       
648 }
649
650 //_____________________________________________________________________________
651 void AliVZEROv6::AddHit(Int_t track, Int_t *vol, Float_t *hits)
652 {
653   
654 //  Adds a VZERO hit
655   
656   TClonesArray &lhits = *fHits;
657   new(lhits[fNhits++]) AliVZEROhit(fIshunt,track,vol,hits);
658 }
659
660 //_____________________________________________________________________________
661 void AliVZEROv6::AddDigits(Int_t *tracks, Int_t* digits) 
662 {
663
664 //  Adds a VZERO digit
665
666    TClonesArray  &ldigits = *fDigits;
667    new(ldigits[fNdigits++]) AliVZEROdigit(tracks, digits);
668 }
669
670 //_____________________________________________________________________________
671 void AliVZEROv6::MakeBranch(Option_t *option)
672 {
673   
674 // Creates new branches in the current Root Tree
675     
676   char branchname[10];
677   sprintf(branchname,"%s",GetName());
678   AliDebug(2,Form("fBufferSize = %d",fBufferSize));
679   
680   const char *cH = strstr(option,"H");
681   
682   if (fHits   && TreeH() && cH) {
683     TreeH()->Branch(branchname,&fHits, fBufferSize);
684     AliDebug(2,Form("Making Branch %s for hits",branchname));
685   }     
686
687   const char *cD = strstr(option,"D");
688   
689   if (fDigits   && fLoader->TreeD() && cD) {
690     fLoader->TreeD()->Branch(branchname,&fDigits, fBufferSize);
691     AliDebug(2,Form("Making Branch %s for digits",branchname));
692   }  
693    
694 }
695
696 //_____________________________________________________________________________
697 Int_t AliVZEROv6::GetCellId(Int_t *vol, Float_t *hits) 
698 {
699
700   //   Returns Id of scintillator cell
701   //   Right side from  0 to 47
702   //   Left  side from 48 to 95
703   
704   //   hits[8] = ring number (1 to 4)
705   //   vol[1]  = copy number (1 to 8)
706
707    Int_t index      = vol[1];
708    Int_t RingNumber = Int_t(hits[8]);   
709    fCellId          = 0;
710    
711 //    cout << "volID = " << vol[0] << "  copy = " << vol[1] << endl;
712 //    cout << "X     = " << hits[0] << "    Y = " << hits[1] << endl;
713    
714    Float_t phi = Float_t(TMath::ATan2(Double_t(hits[1]),Double_t(hits[0])) ); 
715    Float_t kRaddeg = 180.0/TMath::Pi();
716    phi = kRaddeg * phi;
717     
718    if (index < 7) index = index + 8; 
719    
720    if (hits[2] < 0.0) { 
721       if(RingNumber < 3) {
722          index = (index - 7) + ( ( RingNumber - 1 ) * 8);}
723       else if(RingNumber >= 3){ 
724        if(gMC->CurrentVolID(vol[1]) == gMC->VolId("V0R3")|| 
725           gMC->CurrentVolID(vol[1]) == gMC->VolId("V0R5") ) 
726          {index = (index*2 - 14) + ( ( RingNumber - 2 ) * 16); }
727        if(gMC->CurrentVolID(vol[1]) == gMC->VolId("V0R4")||
728           gMC->CurrentVolID(vol[1]) == gMC->VolId("V0R6") ) 
729          {index = (index*2 - 13) + ( ( RingNumber - 2 ) * 16); }
730       }
731       fCellId   = index;           
732    }
733            
734    else if (hits[2] > 0.0){
735       index = (index - 7 + 48) + ( ( RingNumber - 1 ) * 8);
736       fCellId   = index;}
737              
738 //    cout << " ring   = " << RingNumber << " phi = "<<  phi << endl; 
739 //    cout << " cellID = " << fCellId <<  endl;
740 //    cout <<  "**********" << endl;         
741            
742    return fCellId;
743    
744    
745 }