]> git.uio.no Git - u/mrichter/AliRoot.git/blob - VZERO/AliVZEROv4.cxx
Several Changes:
[u/mrichter/AliRoot.git] / VZERO / AliVZEROv4.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 4  as designed by the Lyon group     //
21 //   All comments should be sent to Brigitte CHEYNIS :              //
22 //                                  b.cheynis@ipnl.in2p3.fr         // 
23 //   Geometry of the   24th of february 2004                        //
24 //  (now 4 rings instead of 3 rings as in previous version)         // 
25 //   V0R (now V0C) sits between Z values  -89.4 and  -84.9 cm       //
26 //   V0L (now V0A) sits between Z values +350.0 and +352.0 cm       //
27 //   New coordinate system has been implemented in october 2003     //
28 //                                                                  //
29 //////////////////////////////////////////////////////////////////////
30
31 // --- Standard libraries ---
32 #include <Riostream.h>
33 #include <stdlib.h>
34 #include <string.h>
35
36 // --- ROOT libraries ---
37 #include <TClonesArray.h>
38 #include <TLorentzVector.h>
39 #include <TMath.h>
40 #include <TObjectTable.h>
41 #include <TVirtualMC.h>
42 #include <TParticle.h>
43
44 // --- AliRoot header files ---
45 #include "AliRun.h"
46 #include "AliMC.h"
47 #include "AliConst.h"
48 #include "AliLog.h"
49 #include "AliMagF.h"
50 #include "AliVZEROLoader.h"
51 #include "AliVZEROdigit.h"
52 #include "AliVZEROhit.h"
53 #include "AliVZEROv4.h"
54  
55 ClassImp(AliVZEROv4)
56
57 //_____________________________________________________________________________
58 AliVZEROv4:: AliVZEROv4():AliVZERO(),
59    fCellId(0),
60    fTrackPosition(),
61    fTrackMomentum(), 
62    fLightYield(93.75),
63    fLightAttenuation(0.05),
64    fnMeters(15.0),
65    fFibToPhot(0.3)
66    
67 {
68 // Standard default constructor 
69 }
70
71 //_____________________________________________________________________________
72 AliVZEROv4::AliVZEROv4(const char *name, const char *title):
73    AliVZERO(name,title),
74    fCellId(0),
75    fTrackPosition(),
76    fTrackMomentum(),
77    fLightYield(93.75),
78    fLightAttenuation(0.05),
79    fnMeters(15.0),
80    fFibToPhot(0.3)
81    
82 {
83
84 // Standard constructor for V-zero Detector  version 2
85
86   AliDebug(2,"Create VZERO object");
87 //       
88 //   fLightYield              =  93.75; // Light yield in BC408 (93.75 eV per photon)
89 //   fLightAttenuation        =   0.05; // Light attenuation in fiber (0.05 per meter)
90 //   fnMeters                 =   15.0; // Number of meters of clear fibers to PM
91 //   fFibToPhot               =    0.3; // Attenuation at fiber-photocathode interface
92 }
93
94 //_____________________________________________________________________________
95 void AliVZEROv4::CreateGeometry()
96 {
97
98 // Creates the GEANT geometry of the V-zero Detector  version 3
99   
100   AliDebug(2,"Create VZERO Geometry ");
101       
102   Int_t    *idtmed = fIdtmed->GetArray()-2999;
103
104   Int_t    ndetR = 1;
105   Int_t    ndetL = 1;
106  
107   Int_t    ncellsR = 1;
108   Int_t    ncellsL = 1;
109   
110   Int_t    idrotm[999];
111  
112   Float_t  height1Right, height2Right, height3Right, height4Right; 
113   Float_t  heightRight;
114   Float_t  theta;  
115   
116   Float_t  halfThickQua;
117   
118   Float_t  zdet;
119   Float_t  r0Right, r4Right;
120   Float_t  pi = TMath::Pi();
121     
122   height1Right    =     3.42;  // height of cell 1, in cm
123   height2Right    =     6.78;  // height of cell 2, in cm
124   height3Right    =     7.11;  // height of cell 3, in cm
125   height4Right    =    10.91;  // height of cell 4, in cm
126   
127   theta       = pi/6.0/2.0;       // half angular opening = 15 degrees
128     
129   halfThickQua= fThickness1/2.0;  // half thickness of elementary cell (inner ring)
130   
131 // distance 0.6 cm in zdet accounts for the fact V0R box back lid sits 0.6 away from 
132 // absorber nose sitting at 90 cm. Will use -zdet later...
133 // size of V0R box  (fThickness) is increased by 1 mm as compared to version v2 
134
135   fThickness  =    fThickness + 0.1;  
136   zdet        =    90.0 - 0.6 - fThickness/2.0;  // distance to vertex (along Z axis)   
137   r0Right     =    4.05;          // closest distance to center of the beam pipe
138   heightRight =    height1Right + height2Right + height3Right + height4Right;
139   r4Right     =    r0Right + heightRight;
140
141 // Creation of mother volume v0LE - left part - :
142 // Entrance face at  +350.0 cm  (new coordinate system) ...
143
144    Float_t   partube[3];
145    
146    partube[0] =  4.3;
147    partube[1] = 45.0;
148    partube[2] = fThickness1/2.0;   
149     
150    gMC->Gsvolu("V0LE","TUBE",idtmed[3005],partube,3);
151      
152 // Creation of five rings - left part - :
153 // Entrance face at +350.0 cm  (new coordinate system) ... 
154
155 // Mother volume v0L0 in which will be set 5 scintillator cells 
156
157   Float_t   partubs[5];  
158     
159   Float_t   r0Left      =   4.3;   
160   Float_t   height1Left =   3.6;  
161   Float_t   height2Left =   6.4;  
162   Float_t   height3Left =  14.9; 
163   Float_t   height4Left =  14.4;  
164   Float_t   heightLeft  =   height1Left + height2Left + height3Left + height4Left; 
165                                       
166   Float_t   r4Left      =   r0Left  + heightLeft; 
167   
168   partubs[0]     =  r0Left;
169   partubs[1]     =  r4Left;
170   partubs[2]     =  fThickness1/2.0;
171   partubs[3]     =  90.0-15.0;
172   partubs[4]     = 120.0-15.0;
173
174   gMC->Gsvolu("V0L0","TUBS",idtmed[3010],partubs,5);  // air volume
175   
176   Float_t  r1Left =  r0Left + height1Left;        
177      
178   partubs[0]     =  r0Left;
179   partubs[1]     =  r1Left;
180
181   gMC->Gsvolu("V0L1","TUBS",idtmed[3005],partubs,5);  // quartz volume
182   gMC->Gspos("V0L1",1,"V0L0", 0.0, 0.0 , 0.0, 0,"ONLY"); 
183
184   Float_t  r2Left  =  r1Left + height2Left;       
185   
186   partubs[0]     =  r1Left;
187   partubs[1]     =  r2Left;
188
189   gMC->Gsvolu("V0L2","TUBS",idtmed[3005],partubs,5);  // quartz volume
190   gMC->Gspos("V0L2",1,"V0L0", 0.0, 0.0 , 0.0, 0,"ONLY"); 
191   
192   Float_t  r3Left  =  r2Left + height3Left;       
193       
194   partubs[0]     =  r2Left;
195   partubs[1]     =  r3Left;
196
197   gMC->Gsvolu("V0L3","TUBS",idtmed[3005],partubs,5);  // quartz volume
198   gMC->Gspos("V0L3",1,"V0L0", 0.0, 0.0 , 0.0, 0,"ONLY");
199
200   partubs[0]     =  r3Left;
201   partubs[1]     =  r4Left;
202
203   gMC->Gsvolu("V0L4","TUBS",idtmed[3005],partubs,5);  // quartz volume
204   gMC->Gspos("V0L4",1,"V0L0", 0.0, 0.0 , 0.0, 0,"ONLY");  
205
206 // Creation of mother volume v0RI - right part - :
207   
208   partube[0] = r0Right - 0.2;
209   partube[1] = r4Right + 1.0;
210   partube[2] = fThickness/2.0; 
211       
212   gMC->Gsvolu("V0RI","TUBE",idtmed[3010],partube,3);
213   
214 // Creation of  carbon lids (3.5 mm thick) to keep v0RI box shut...
215
216   Float_t  lidThickness = 0.35;
217  
218   partube[0] =   r0Right;
219   partube[1] =   r4Right;
220   partube[2] =   +lidThickness/2.0;
221     
222   gMC->Gsvolu("V0CA","TUBE",idtmed[3001],partube,3); 
223   gMC->Gspos("V0CA",1,"V0RI",0.0,0.0, fThickness/2.0-partube[2],0,"ONLY");
224   gMC->Gspos("V0CA",2,"V0RI",0.0,0.0,-fThickness/2.0+partube[2],0,"ONLY");
225   
226 // Creation of aluminum rings to maintain the v0RI pieces ...
227
228   partube[0] =   r0Right - 0.2;
229   partube[1] =   r0Right;
230   partube[2] =   +fThickness/2.0;
231    
232   gMC->Gsvolu("V0IR","TUBE",idtmed[3003],partube,3);    
233   gMC->Gspos("V0IR",1,"V0RI",0.0,0.0,0.0,0,"ONLY");
234
235   partube[0] =   r4Right;
236   partube[1] =   r4Right + 1.0;
237   partube[2] =   +fThickness/2.0;
238  
239   gMC->Gsvolu("V0ER","TUBE",idtmed[3003],partube,3);    
240   gMC->Gspos("V0ER",1,"V0RI",0.0,0.0,0.0,0,"ONLY");
241   
242 // Mother volume v0R0 in which will be set 4  scintillator cells 
243   
244   partubs[0]      =  r0Right;
245   partubs[1]      =  r4Right;
246   partubs[2]      =  fThickness/2.0;
247   partubs[3]      =  90.0-15.0;
248   partubs[4]      = 120.0-15.0;
249
250   gMC->Gsvolu("V0R0","TUBS",idtmed[3010],partubs,5);  // air volume 
251
252 // Elementary cell of ring 1 :
253 // (cells of ring 1  will be shifted by 1.7 cm towards vertex to output fibers) 
254    
255   Float_t   offsetFibers  =  1.7;
256   Float_t   offset        =  fThickness/2.0 - lidThickness - fThickness1/2.0; 
257   Float_t   r1Right       =  r0Right + height1Right;
258       
259   partubs[0]     =  r0Right;
260   partubs[1]     =  r1Right;
261   partubs[2]     =  fThickness1/2.0;
262   
263   gMC->Gsvolu("V0R1","TUBS",idtmed[3005],partubs,5);  // scintillator volume
264   gMC->Gspos("V0R1",1,"V0R0", 0.0, 0.0 , -offset + offsetFibers, 0,"ONLY"); 
265
266 // Elementary cell of ring 2 :
267
268   Float_t   r2Right   =  r1Right + height2Right;       
269   
270   partubs[0]     =  r1Right;
271   partubs[1]     =  r2Right;
272
273   gMC->Gsvolu("V0R2","TUBS",idtmed[3005],partubs,5);  // scintillator volume
274   gMC->Gspos("V0R2",1,"V0R0", 0.0, 0.0 , -offset, 0,"ONLY"); 
275
276
277 // Elementary cell of ring 3 :
278
279   Float_t   r3Right   =  r2Right + height3Right;   
280      
281   partubs[0]     =  r2Right;
282   partubs[1]     =  r3Right;
283
284   gMC->Gsvolu("V0R3","TUBS",idtmed[3005],partubs,5);  // scintillator volume
285   gMC->Gspos("V0R3",1,"V0R0", 0.0, 0.0 , -offset, 0,"ONLY");
286
287 // Elementary cell of ring 4 :
288    
289   partubs[0]     =  r3Right;
290   partubs[1]     =  r4Right;
291
292   gMC->Gsvolu("V0R4","TUBS",idtmed[3005],partubs,5);  // scintillator volume
293   gMC->Gspos("V0R4",1,"V0R0", 0.0, 0.0 , -offset, 0,"ONLY");
294
295   Float_t  phiDeg = 180./6.; 
296
297 // Right part : 
298  
299   for(Float_t  phi = 15.0 ; phi < 360.0; phi = phi + phiDeg)
300       {        
301         AliMatrix(idrotm[902], 90.0, phi, 90.0, 90.0 +phi, 0.0 , 0.0);
302         gMC->Gspos("V0R0",ndetR,"V0RI",0.0,
303                           0.0,0.0,idrotm[902],"ONLY");
304         ndetR++;
305        }
306
307   gMC->Gspos("V0RI",1,"ALIC",0.0,0.0,-zdet,0,"ONLY");
308  
309   ncellsR = (ndetR - 1) * 4;  
310   AliInfo(Form("Number of cells on Right side =   %d",  ncellsR));    
311
312 // Left part :
313   
314   for(Float_t  phi = 15.0 ; phi < 360.0; phi = phi + phiDeg)
315       {       
316         AliMatrix(idrotm[902], 90.0, phi, 90.0, 90.0 +phi, 0.0 , 0.0);
317         gMC->Gspos("V0L0",ndetL,"V0LE",0.0,
318                           0.0,0.0,idrotm[902],"ONLY");
319         ndetL++;
320        }
321
322   gMC->Gspos("V0LE",1,"ALIC",0.0,0.0,350.0+fThickness1/2.0,0,"ONLY");
323  
324   ncellsL = (ndetL - 1) * 4;
325   AliInfo(Form("Number of cells on Left side  =   %d",  ncellsL));    
326            
327 }            
328     
329 //_____________________________________________________________________________
330 void AliVZEROv4::CreateMaterials()
331 {
332
333 // Creates materials used for geometry 
334
335     AliDebug(2,"VZERO create materials");
336     
337 /*
338     Float_t ppckov[14] = { 5.5e-9, 5.7e-9, 5.9e-9, 6.1e-9, 6.3e-9, 6.5e-9, 6.7e-9, 
339                            6.9e-9, 7.1e-9, 7.3e-9, 7.5e-9, 7.7e-9, 7.9e-9, 8.1e-9 };
340
341            
342     Float_t ppckov_alu[14] = { 5.5e-9, 5.7e-9, 5.9e-9, 6.1e-9, 6.3e-9, 6.5e-9, 6.7e-9, 
343                                6.9e-9, 7.1e-9, 7.3e-9, 7.5e-9, 7.7e-9, 7.9e-9, 8.1e-9 };
344                            
345     Float_t rindex_quarz[14] = { 1.52398,  1.53090, 1.53835, 1.54641, 1.55513, 1.56458, 
346                                  1.57488,  1.58611, 1.59842, 1.61197, 1.62696, 1.64362, 
347                                  1.662295, 1.68337 };
348                                  
349     Float_t absco_quarz[14] = { 105.8,  45.656, 35.665, 28.598, 25.007, 21.04, 17.525, 
350                                 14.177, 9.282, 4.0925, 1.149, 0.3627, 0.1497, 0.05 };   
351                                                                                         
352     Float_t effic_all[14]   = { 1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1. };
353     
354         
355     Float_t rindex_alu[14] = { 1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1. }; 
356     
357     
358     Float_t absco_alu[14]  = { 1e-4,1e-4,1e-4,1e-4,1e-4,1e-4,1e-4,1e-4,1e-4,1e-4,
359                                1e-4,1e-4,1e-4,1e-4 };
360     Float_t effic_alu[14]  = { 1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1. };
361
362 */        
363
364     Int_t *idtmed = fIdtmed->GetArray()-2999;
365     
366     
367 //  Parameters related to Quarz (SiO2) :
368  
369     Float_t aqua[2], zqua[2], densqua, wmatqua[2];
370     Int_t nlmatqua;
371     
372     aqua[0]    = 28.09;
373     aqua[1]    = 16.;
374     zqua[0]    = 14.;
375     zqua[1]    = 8.;
376     densqua    = 2.64;
377     nlmatqua   = -2;
378     wmatqua[0] = 1.;
379     wmatqua[1] = 2.;
380
381 // Parameters  related to aluminum sheets :
382     
383     Float_t  aal   = 26.98;
384     Float_t  zal   = 13.00; 
385     Float_t  densal=   2.7; 
386     Float_t  radlal=   8.9;
387        
388 // Parameters  related to scintillator CH :
389     
390     Float_t ascin[2] = {1.00794,12.011};
391     Float_t zscin[2] = {1.,6.};
392     Float_t wscin[2] = {1.,1.};
393     Float_t denscin  = 1.032;
394     
395 // AIR
396
397     Float_t aAir[4]={12.,14.,16.,36.};
398     Float_t zAir[4]={6.,7.,8.,18.};
399     Float_t wAir[4]={0.000124,0.755267,0.231781,0.012827};
400     Float_t dAir = 1.20479E-3;
401     
402 //  Definition of materials :
403
404 // AIR
405
406     AliMixture( 1, "AIR A$", aAir,zAir,dAir,4,wAir);
407     AliMixture(11, "AIR I$", aAir,zAir,dAir,4,wAir);
408     AliMaterial( 2, "CARBON$"  , 12.01, 6.0, 2.265, 18.8, 49.9, 0, 0);
409     AliMixture(  3, "QUA", aqua, zqua, densqua, nlmatqua, wmatqua);
410     AliMaterial( 4, "ALUMINIUM1$", 26.98, 13., 2.7, 8.9, 37.2, 0, 0);
411     AliMaterial( 5, "ALUMINIUM2$", aal, zal, densal, radlal, 0, 0, 0);
412  
413     AliMixture( 6, "Scintillator$",ascin,zscin,denscin,-2,wscin);
414     
415      
416     Int_t   iSXFLD = gAlice->Field()->Integ();
417     Float_t sXMGMX = gAlice->Field()->Max();
418     
419     Float_t tmaxfd, stemax, deemax, epsil, stmin;
420         
421     tmaxfd = 10.;
422     stemax = 0.1;
423     deemax = 0.1;     
424     epsil  = 0.001;
425     stmin  = 0.001;
426   
427 //  Active Air :    
428     AliMedium(1, "ACTIVE AIR$", 1, 1, iSXFLD, sXMGMX,
429               10.0, 1.0, 0.1, 0.1, 10.0, 0, 0) ;
430
431 //  Inactive air : 
432   
433     AliMedium(11, "INACTIVE AIR$", 11, 0, iSXFLD, sXMGMX,
434               10.0, 1.0, 0.1, 0.1, 10.0, 0, 0) ;
435     
436     AliMedium(2, "CARBON$ ", 2,  1, iSXFLD, sXMGMX,
437               tmaxfd, stemax, deemax, epsil, stmin, 0, 0);   
438
439     AliMedium(3, "QUARZ$", 3, 1, iSXFLD, sXMGMX,
440               tmaxfd, fMaxStepQua, fMaxDestepQua, epsil, stmin, 0, 0);
441     
442     AliMedium(4,"ALUMINUM1$",4, 1, iSXFLD, sXMGMX,
443               tmaxfd, fMaxStepAlu, fMaxDestepAlu, epsil, stmin, 0, 0);
444               
445
446     AliMedium(5,"ALUMINUM2$",5, 1, iSXFLD, sXMGMX,
447               tmaxfd, fMaxStepAlu, fMaxDestepAlu, epsil, stmin, 0, 0);    
448
449     AliMedium(6,"SCINTILLATOR$",6, 1, iSXFLD, sXMGMX, 10.0, 0.1, 0.1, 0.003, 0.003, 0, 0);
450
451     gMC->Gstpar(idtmed[3000], "LOSS", 1.);  //  [3000] = air ACTIF  [3010] = air INACTIF
452     gMC->Gstpar(idtmed[3000], "HADR", 1.);
453     gMC->Gstpar(idtmed[3000], "DCAY", 1.);
454     gMC->Gstpar(idtmed[3000], "DRAY", 1.);
455     
456     gMC->Gstpar(idtmed[3001], "LOSS", 1.);  //  [3001] = carbon
457     gMC->Gstpar(idtmed[3001], "HADR", 1.);
458     gMC->Gstpar(idtmed[3001], "DCAY", 1.);
459     gMC->Gstpar(idtmed[3001], "DRAY", 1.);
460
461     gMC->Gstpar(idtmed[3002], "LOSS", 1.);  //  [3002] = quartz
462     gMC->Gstpar(idtmed[3002], "HADR", 1.);
463     gMC->Gstpar(idtmed[3002], "DCAY", 1.);
464     gMC->Gstpar(idtmed[3002], "DRAY", 1.);  
465     gMC->Gstpar(idtmed[3002], "CUTGAM",0.5E-4) ; 
466     gMC->Gstpar(idtmed[3002], "CUTELE",1.0E-4) ;
467     
468     gMC->Gstpar(idtmed[3003], "LOSS", 1.);  //  [3003] = normal aluminum
469     gMC->Gstpar(idtmed[3003], "HADR", 1.);
470     gMC->Gstpar(idtmed[3003], "DCAY", 1.);
471     gMC->Gstpar(idtmed[3003], "DRAY", 1.);
472     
473     gMC->Gstpar(idtmed[3004], "LOSS", 1.);  //  [3004] = reflecting aluminum
474     gMC->Gstpar(idtmed[3004], "HADR", 1.);
475     gMC->Gstpar(idtmed[3004], "DCAY", 1.);
476     gMC->Gstpar(idtmed[3004], "DRAY", 1.);
477     gMC->Gstpar(idtmed[3004], "CUTGAM",0.5E-4) ; 
478     gMC->Gstpar(idtmed[3004], "CUTELE",1.0E-4) ;
479     
480     gMC->Gstpar(idtmed[3005], "LOSS", 1.);  //  [3005] = scintillator
481     gMC->Gstpar(idtmed[3005], "HADR", 1.);
482     gMC->Gstpar(idtmed[3005], "DCAY", 1.);
483     gMC->Gstpar(idtmed[3005], "DRAY", 1.); 
484     gMC->Gstpar(idtmed[3005], "CUTGAM",0.5E-4) ; 
485     gMC->Gstpar(idtmed[3005], "CUTELE",1.0E-4) ;
486       
487     
488 //    geant3->Gsckov(idtmed[3002], 14, ppckov, absco_quarz, effic_all,rindex_quarz);    
489 //    geant3->Gsckov(idtmed[3004], 14, ppckov_alu, absco_alu, effic_alu, rindex_alu);
490
491 //    gMC->SetCerenkov(idtmed[3002], 14, ppckov, absco_quarz, effic_all,rindex_quarz);    
492 //    gMC->SetCerenkov(idtmed[3004], 14, ppckov_alu, absco_alu, effic_alu, rindex_alu);
493                                        
494 }
495
496 //_____________________________________________________________________________
497 void AliVZEROv4::DrawModule() const
498 {
499
500 //  Drawing is done in DrawVZERO.C
501
502    AliDebug(2,"VZERO DrawModule");
503 }
504
505 //_____________________________________________________________________________
506 void AliVZEROv4::Init()
507 {
508 // Initialises version 2 of the VZERO Detector
509 // Just prints an information message
510   
511   AliDebug(2,Form("VZERO version %d initialized",IsVersion()));
512    
513 //   gMC->SetMaxStep(fMaxStepAlu);
514 //   gMC->SetMaxStep(fMaxStepQua);
515    
516     AliVZERO::Init();  
517 }
518
519 //_____________________________________________________________________________
520 void AliVZEROv4::StepManager()
521 {
522  
523 // Step Manager, called at each step 
524  
525      Int_t     copy;
526      static    Int_t   vol[4];
527      static    Float_t hits[21];
528      static    Float_t eloss, tlength;
529      static    Int_t   nPhotonsInStep;
530      static    Int_t   nPhotons; 
531      static    Int_t   numStep;
532      Float_t   ringNumber;
533      Float_t   destep, step;
534      
535      numStep += 1; 
536           
537 //   We keep only charged tracks :
538      
539      if ( !gMC->TrackCharge() || !gMC->IsTrackAlive() ) return; 
540
541      vol[0]    = gMC->CurrentVolOffID(1, vol[1]);
542      vol[2]    = gMC->CurrentVolID(copy);
543      vol[3]    = copy;
544      
545      static Int_t idV0R1 = gMC->VolId("V0R1");
546      static Int_t idV0L1 = gMC->VolId("V0L1");
547      static Int_t idV0R2 = gMC->VolId("V0R2");
548      static Int_t idV0L2 = gMC->VolId("V0L2");
549      static Int_t idV0R3 = gMC->VolId("V0R3");
550      static Int_t idV0L3 = gMC->VolId("V0L3");
551      static Int_t idV0R4 = gMC->VolId("V0R4");
552      static Int_t idV0L4 = gMC->VolId("V0L4");
553
554      if      ( gMC->CurrentVolID(copy) == idV0R1 ||
555                gMC->CurrentVolID(copy) == idV0L1 )
556                ringNumber = 1.0;
557      else if ( gMC->CurrentVolID(copy) == idV0R2 ||
558                gMC->CurrentVolID(copy) == idV0L2 ) 
559                ringNumber = 2.0;  
560      else if ( gMC->CurrentVolID(copy) == idV0R3 ||
561                gMC->CurrentVolID(copy) == idV0L3 )
562                ringNumber = 3.0;
563      else if ( gMC->CurrentVolID(copy) == idV0R4 ||
564                gMC->CurrentVolID(copy) == idV0L4 )
565                ringNumber = 4.0;               
566      else
567                ringNumber = 0.0;
568
569      if  (  ringNumber > 0.5  ) { 
570      
571         destep    = gMC->Edep();
572         step      = gMC->TrackStep();
573         
574         nPhotonsInStep  = Int_t(destep / (fLightYield *1e-9) ); 
575         nPhotonsInStep  = gRandom->Poisson(nPhotonsInStep);
576         
577         eloss    += destep;
578         tlength  += step;        
579         
580         if  ( gMC->IsTrackEntering()  )  { 
581          
582             nPhotons  =  nPhotonsInStep;       
583             gMC->TrackPosition(fTrackPosition);
584             gMC->TrackMomentum(fTrackMomentum);
585             
586             Float_t pt  = TMath::Sqrt( fTrackMomentum.Px() * fTrackMomentum.Px() +
587                                        fTrackMomentum.Py() * fTrackMomentum.Py() );
588                
589             hits[0]  = fTrackPosition.X();
590             hits[1]  = fTrackPosition.Y();
591             hits[2]  = fTrackPosition.Z();               
592             hits[3]  = Float_t (gMC->TrackPid()); 
593
594             hits[4]  = gMC->TrackTime();
595             hits[5]  = gMC->TrackCharge();
596             hits[6]  = fTrackMomentum.Theta()*TMath::RadToDeg();
597             hits[7]  = fTrackMomentum.Phi()*TMath::RadToDeg();
598             hits[8]  = ringNumber;
599          
600             hits[9]  = pt;
601             hits[10] = fTrackMomentum.P();
602             hits[11] = fTrackMomentum.Px();
603             hits[12] = fTrackMomentum.Py();
604             hits[13] = fTrackMomentum.Pz();
605             
606             TParticle *par = gAlice->GetMCApp()->Particle(gAlice->GetMCApp()->GetCurrentTrackNumber());
607             hits[14] = par->Vx();
608             hits[15] = par->Vy();
609             hits[16] = par->Vz();
610             
611             tlength  = 0.0;
612             eloss    = 0.0;         
613          }
614          
615          nPhotons  = nPhotons + nPhotonsInStep;
616          
617          if( gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()){
618          
619          nPhotons  = nPhotons - Int_t((Float_t(nPhotons) * fLightAttenuation * fnMeters));       
620          nPhotons  = nPhotons - Int_t( Float_t(nPhotons) * fFibToPhot);  
621          
622          hits[17] =   eloss;
623          hits[18] = tlength;
624          hits[19] = nPhotons;
625          hits[20] = GetCellId (vol, hits); 
626                  
627          AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol, hits);
628                  
629          tlength         = 0.0;
630          eloss           = 0.0; 
631          nPhotons        =   0;
632          nPhotonsInStep  =   0;
633          
634          numStep         =   0;  
635          } 
636     }
637       
638 }
639
640 //_____________________________________________________________________________
641 void AliVZEROv4::AddHit(Int_t track, Int_t *vol, Float_t *hits)
642 {
643   
644 //  Adds a VZERO hit
645   
646   TClonesArray &lhits = *fHits;
647   new(lhits[fNhits++]) AliVZEROhit(fIshunt,track,vol,hits);
648 }
649
650 //_____________________________________________________________________________
651 void AliVZEROv4::AddDigits(Int_t *tracks, Int_t* digits) 
652 {
653
654 //  Adds a VZERO digit
655
656    TClonesArray  &ldigits = *fDigits;
657    new(ldigits[fNdigits++]) AliVZEROdigit(tracks, digits);
658 }
659
660 //_____________________________________________________________________________
661 void AliVZEROv4::MakeBranch(Option_t *option)
662 {
663   
664 // Creates new branches in the current Root Tree
665     
666   char branchname[10];
667   sprintf(branchname,"%s",GetName());
668   AliDebug(2,Form("fBufferSize = %d",fBufferSize));
669   
670   const char *cH = strstr(option,"H");
671   
672   if (fHits   && fLoader->TreeH() && cH) {
673     fLoader->TreeH()->Branch(branchname,&fHits, fBufferSize);
674     AliDebug(2,Form("Making Branch %s for hits",branchname));
675   }     
676
677   const char *cD = strstr(option,"D");
678   
679   if (fDigits   && fLoader->TreeD() && cD) {
680     fLoader->TreeD()->Branch(branchname,&fDigits, fBufferSize);
681     AliDebug(2,Form("Making Branch %s for digits",branchname));
682   }  
683    
684 }
685
686 //_____________________________________________________________________________
687 Int_t AliVZEROv4::GetCellId(Int_t *vol, Float_t *hits) 
688 {
689
690   //   Returns Id of scintillator cell
691   //   Right side from  0 to 47
692   //   Left  side from 48 to 95
693
694    Int_t index = vol[1];
695    fCellId     = 0;
696    
697    if (index < 10) index = index + 12; 
698    
699    if (hits[2] < 0.0) { 
700       index = (index - 10) + ( ( Int_t(hits[8]) - 1 ) * 12);
701       fCellId   = index;
702    }
703    else if (hits[2] > 0.0)
704    {
705       index = (index + 38) + ( ( Int_t(hits[8]) - 1 ) * 12);
706       fCellId   = index;}
707            
708    return fCellId;
709 }