Data calibration header
[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 <TGeometry.h>
39 #include <TLorentzVector.h>
40 #include <TMath.h>
41 #include <TNode.h>
42 #include <TObjectTable.h>
43 #include <TTUBE.h>
44 #include <TTUBS.h>
45 #include <TVirtualMC.h>
46 #include <TParticle.h>
47
48 // --- AliRoot header files ---
49 #include "AliRun.h"
50 #include "AliMC.h"
51 #include "AliConst.h"
52 #include "AliLog.h"
53 #include "AliMagF.h"
54 #include "AliVZEROLoader.h"
55 #include "AliVZEROdigit.h"
56 #include "AliVZEROhit.h"
57 #include "AliVZEROv4.h"
58  
59 ClassImp(AliVZEROv4)
60
61 //_____________________________________________________________________________
62 AliVZEROv4:: AliVZEROv4():AliVZERO()
63 {
64 // Standard default constructor 
65 }
66
67 //_____________________________________________________________________________
68 AliVZEROv4::AliVZEROv4(const char *name, const char *title):
69  AliVZERO(name,title)
70 {
71
72 // Standard constructor for V-zero Detector  version 2
73
74   AliDebug(2,"Create VZERO object");
75       
76   fLightYield              =  93.75; // Light yield in BC408 (93.75 eV per photon)
77   fLightAttenuation        =   0.05; // Light attenuation in fiber (0.05 per meter)
78   fnMeters                 =   15.0; // Number of meters of clear fibers to PM
79   fFibToPhot               =    0.3; // Attenuation at fiber-photocathode interface
80 }
81
82 //_____________________________________________________________________________
83 void AliVZEROv4::CreateGeometry()
84 {
85
86 // Creates the GEANT geometry of the V-zero Detector  version 3
87   
88   AliDebug(2,"Create VZERO Geometry ");
89       
90   Int_t    *idtmed = fIdtmed->GetArray()-2999;
91
92   Int_t    ndetR = 1;
93   Int_t    ndetL = 1;
94  
95   Int_t    ncellsR = 1;
96   Int_t    ncellsL = 1;
97   
98   Int_t    idrotm[999];
99  
100   Float_t  height1Right, height2Right, height3Right, height4Right; 
101   Float_t  heightRight;
102   Float_t  theta;  
103   
104   Float_t  halfThickQua;
105   
106   Float_t  zdet;
107   Float_t  r0Right, r4Right;
108   Float_t  pi = TMath::Pi();
109     
110   height1Right    =     3.42;  // height of cell 1, in cm
111   height2Right    =     6.78;  // height of cell 2, in cm
112   height3Right    =     7.11;  // height of cell 3, in cm
113   height4Right    =    10.91;  // height of cell 4, in cm
114   
115   theta       = pi/6.0/2.0;       // half angular opening = 15 degrees
116     
117   halfThickQua= fThickness1/2.0;  // half thickness of elementary cell (inner ring)
118   
119 // distance 0.6 cm in zdet accounts for the fact V0R box back lid sits 0.6 away from 
120 // absorber nose sitting at 90 cm. Will use -zdet later...
121 // size of V0R box  (fThickness) is increased by 1 mm as compared to version v2 
122
123   fThickness  =    fThickness + 0.1;  
124   zdet        =    90.0 - 0.6 - fThickness/2.0;  // distance to vertex (along Z axis)   
125   r0Right     =    4.05;          // closest distance to center of the beam pipe
126   heightRight =    height1Right + height2Right + height3Right + height4Right;
127   r4Right     =    r0Right + heightRight;
128
129 // Creation of mother volume v0LE - left part - :
130 // Entrance face at  +350.0 cm  (new coordinate system) ...
131
132    Float_t   partube[3];
133    
134    partube[0] =  4.3;
135    partube[1] = 45.0;
136    partube[2] = fThickness1/2.0;   
137     
138    gMC->Gsvolu("V0LE","TUBE",idtmed[3005],partube,3);
139      
140 // Creation of five rings - left part - :
141 // Entrance face at +350.0 cm  (new coordinate system) ... 
142
143 // Mother volume v0L0 in which will be set 5 scintillator cells 
144
145   Float_t   partubs[5];  
146     
147   Float_t   r0Left      =   4.3;   
148   Float_t   height1Left =   3.6;  
149   Float_t   height2Left =   6.4;  
150   Float_t   height3Left =  14.9; 
151   Float_t   height4Left =  14.4;  
152   Float_t   heightLeft  =   height1Left + height2Left + height3Left + height4Left; 
153                                       
154   Float_t   r4Left      =   r0Left  + heightLeft; 
155   
156   partubs[0]     =  r0Left;
157   partubs[1]     =  r4Left;
158   partubs[2]     =  fThickness1/2.0;
159   partubs[3]     =  90.0-15.0;
160   partubs[4]     = 120.0-15.0;
161
162   gMC->Gsvolu("V0L0","TUBS",idtmed[3010],partubs,5);  // air volume
163   
164   Float_t  r1Left =  r0Left + height1Left;        
165      
166   partubs[0]     =  r0Left;
167   partubs[1]     =  r1Left;
168
169   gMC->Gsvolu("V0L1","TUBS",idtmed[3005],partubs,5);  // quartz volume
170   gMC->Gspos("V0L1",1,"V0L0", 0.0, 0.0 , 0.0, 0,"ONLY"); 
171
172   Float_t  r2Left  =  r1Left + height2Left;       
173   
174   partubs[0]     =  r1Left;
175   partubs[1]     =  r2Left;
176
177   gMC->Gsvolu("V0L2","TUBS",idtmed[3005],partubs,5);  // quartz volume
178   gMC->Gspos("V0L2",1,"V0L0", 0.0, 0.0 , 0.0, 0,"ONLY"); 
179   
180   Float_t  r3Left  =  r2Left + height3Left;       
181       
182   partubs[0]     =  r2Left;
183   partubs[1]     =  r3Left;
184
185   gMC->Gsvolu("V0L3","TUBS",idtmed[3005],partubs,5);  // quartz volume
186   gMC->Gspos("V0L3",1,"V0L0", 0.0, 0.0 , 0.0, 0,"ONLY");
187
188   partubs[0]     =  r3Left;
189   partubs[1]     =  r4Left;
190
191   gMC->Gsvolu("V0L4","TUBS",idtmed[3005],partubs,5);  // quartz volume
192   gMC->Gspos("V0L4",1,"V0L0", 0.0, 0.0 , 0.0, 0,"ONLY");  
193
194 // Creation of mother volume v0RI - right part - :
195   
196   partube[0] = r0Right - 0.2;
197   partube[1] = r4Right + 1.0;
198   partube[2] = fThickness/2.0; 
199       
200   gMC->Gsvolu("V0RI","TUBE",idtmed[3010],partube,3);
201   
202 // Creation of  carbon lids (3.5 mm thick) to keep v0RI box shut...
203
204   Float_t  lidThickness = 0.35;
205  
206   partube[0] =   r0Right;
207   partube[1] =   r4Right;
208   partube[2] =   +lidThickness/2.0;
209     
210   gMC->Gsvolu("V0CA","TUBE",idtmed[3001],partube,3); 
211   gMC->Gspos("V0CA",1,"V0RI",0.0,0.0, fThickness/2.0-partube[2],0,"ONLY");
212   gMC->Gspos("V0CA",2,"V0RI",0.0,0.0,-fThickness/2.0+partube[2],0,"ONLY");
213   
214 // Creation of aluminum rings to maintain the v0RI pieces ...
215
216   partube[0] =   r0Right - 0.2;
217   partube[1] =   r0Right;
218   partube[2] =   +fThickness/2.0;
219    
220   gMC->Gsvolu("V0IR","TUBE",idtmed[3003],partube,3);    
221   gMC->Gspos("V0IR",1,"V0RI",0.0,0.0,0.0,0,"ONLY");
222
223   partube[0] =   r4Right;
224   partube[1] =   r4Right + 1.0;
225   partube[2] =   +fThickness/2.0;
226  
227   gMC->Gsvolu("V0ER","TUBE",idtmed[3003],partube,3);    
228   gMC->Gspos("V0ER",1,"V0RI",0.0,0.0,0.0,0,"ONLY");
229   
230 // Mother volume v0R0 in which will be set 4  scintillator cells 
231   
232   partubs[0]      =  r0Right;
233   partubs[1]      =  r4Right;
234   partubs[2]      =  fThickness/2.0;
235   partubs[3]      =  90.0-15.0;
236   partubs[4]      = 120.0-15.0;
237
238   gMC->Gsvolu("V0R0","TUBS",idtmed[3010],partubs,5);  // air volume 
239
240 // Elementary cell of ring 1 :
241 // (cells of ring 1  will be shifted by 1.7 cm towards vertex to output fibers) 
242    
243   Float_t   offsetFibers  =  1.7;
244   Float_t   offset        =  fThickness/2.0 - lidThickness - fThickness1/2.0; 
245   Float_t   r1Right       =  r0Right + height1Right;
246       
247   partubs[0]     =  r0Right;
248   partubs[1]     =  r1Right;
249   partubs[2]     =  fThickness1/2.0;
250   
251   gMC->Gsvolu("V0R1","TUBS",idtmed[3005],partubs,5);  // scintillator volume
252   gMC->Gspos("V0R1",1,"V0R0", 0.0, 0.0 , -offset + offsetFibers, 0,"ONLY"); 
253
254 // Elementary cell of ring 2 :
255
256   Float_t   r2Right   =  r1Right + height2Right;       
257   
258   partubs[0]     =  r1Right;
259   partubs[1]     =  r2Right;
260
261   gMC->Gsvolu("V0R2","TUBS",idtmed[3005],partubs,5);  // scintillator volume
262   gMC->Gspos("V0R2",1,"V0R0", 0.0, 0.0 , -offset, 0,"ONLY"); 
263
264
265 // Elementary cell of ring 3 :
266
267   Float_t   r3Right   =  r2Right + height3Right;   
268      
269   partubs[0]     =  r2Right;
270   partubs[1]     =  r3Right;
271
272   gMC->Gsvolu("V0R3","TUBS",idtmed[3005],partubs,5);  // scintillator volume
273   gMC->Gspos("V0R3",1,"V0R0", 0.0, 0.0 , -offset, 0,"ONLY");
274
275 // Elementary cell of ring 4 :
276    
277   partubs[0]     =  r3Right;
278   partubs[1]     =  r4Right;
279
280   gMC->Gsvolu("V0R4","TUBS",idtmed[3005],partubs,5);  // scintillator volume
281   gMC->Gspos("V0R4",1,"V0R0", 0.0, 0.0 , -offset, 0,"ONLY");
282
283   Float_t  phiDeg = 180./6.; 
284
285 // Right part : 
286  
287   for(Float_t  phi = 15.0 ; phi < 360.0; phi = phi + phiDeg)
288       {        
289         AliMatrix(idrotm[902], 90.0, phi, 90.0, 90.0 +phi, 0.0 , 0.0);
290         gMC->Gspos("V0R0",ndetR,"V0RI",0.0,
291                           0.0,0.0,idrotm[902],"ONLY");
292         ndetR++;
293        }
294
295   gMC->Gspos("V0RI",1,"ALIC",0.0,0.0,-zdet,0,"ONLY");
296  
297   ncellsR = (ndetR - 1) * 4;  
298   AliInfo(Form("Number of cells on Right side =   %d",  ncellsR));    
299
300 // Left part :
301   
302   for(Float_t  phi = 15.0 ; phi < 360.0; phi = phi + phiDeg)
303       {       
304         AliMatrix(idrotm[902], 90.0, phi, 90.0, 90.0 +phi, 0.0 , 0.0);
305         gMC->Gspos("V0L0",ndetL,"V0LE",0.0,
306                           0.0,0.0,idrotm[902],"ONLY");
307         ndetL++;
308        }
309
310   gMC->Gspos("V0LE",1,"ALIC",0.0,0.0,350.0+fThickness1/2.0,0,"ONLY");
311  
312   ncellsL = (ndetL - 1) * 4;
313   AliInfo(Form("Number of cells on Left side  =   %d",  ncellsL));    
314            
315 }
316             
317 //_____________________________________________________________________________
318 void AliVZEROv4::BuildGeometry()
319 {
320   
321 // Builds simple ROOT TNode geometry for event display
322
323   AliDebug(2,"VZERO BuildGeometry ");
324
325   TNode *top; 
326
327   TNode *v0Rnode, *v0Rnode0, *v0Rnode6 , *v0Rnode7, *v0Rnode8, *v0Rnode9;
328   TNode *v0Rnode1, *v0Rnode2, *v0Rnode3, *v0Rnode4;
329   TNode *v0Lnode, *v0Lnode0;
330   TNode *v0Lnode1, *v0Lnode2, *v0Lnode3, *v0Lnode4;
331    
332   const int kColorVZERO  = kGreen;
333  
334   top = gAlice->GetGeometry()->GetNode("alice");
335
336   Float_t  height1Right, height2Right, height3Right, height4Right; 
337   Float_t  heightRight;
338   Float_t  theta;  
339   
340   Float_t  halfThickQua;
341   Float_t  zdet;
342   Float_t  r0Right, r4Right;
343   Float_t  pi = TMath::Pi();
344
345   height1Right      =     3.42;  // height of cell 1, in cm
346   height2Right      =     6.78;  // height of cell 2, in cm
347   height3Right      =     7.11;  // height of cell 3, in cm
348   height4Right      =    10.91;  // height of cell 4, in cm
349     
350   theta             =    pi/6.0/2.0;    
351    
352   halfThickQua      =    fThickness1/2.0; 
353   
354   zdet              =    90.0 - 0.6 - fThickness/2.0;   
355   r0Right           =    4.05;         
356   heightRight       =    height1Right + height2Right + height3Right + height4Right;
357   r4Right           =    r0Right + heightRight;
358   
359   Int_t     ndiv    =     1;  
360
361   Float_t   partube[3];
362
363   partube[0] =  r0Right - 0.2;
364   partube[1] =  r4Right + 1.0;
365   partube[2] = fThickness/2.0;   
366   
367   TTUBE *v0RI = new TTUBE("V0RI", "V0RI", "void", partube[0], partube[1], partube[2]);
368                 
369   top->cd();
370   
371   v0Rnode = new TNode("V0RI","V0RI",v0RI,0.0,0.0,-zdet,0);
372   
373   v0Rnode->SetLineColor(kYellow);
374   fNodes->Add(v0Rnode);  
375   v0Rnode->SetVisibility(2);     
376  
377 // Rondelles de carbone (epaisseur 3.5 mm) de maintien des cellules ...
378
379   Float_t  lidThickness = 0.35;
380   
381   partube[0] =   r0Right;
382   partube[1] =   r4Right;
383   partube[2] =   +lidThickness/2.0;
384   
385   TTUBE  *v0CA = new TTUBE("V0CA", "V0CA", "void",partube[0], partube[1], partube[2]);
386   
387   v0Rnode->cd();
388   v0Rnode6 = new TNode("V0CA", "V0CA",v0CA,0.0,0.0, fThickness/2.0-partube[2],0);        
389   v0Rnode6->SetLineColor(kYellow);
390   fNodes->Add(v0Rnode6); 
391   v0Rnode->cd();
392   v0Rnode7 = new TNode("V0CA", "V0CA",v0CA,0.0,0.0,-fThickness/2.0+partube[2],0);        
393   v0Rnode7->SetLineColor(kYellow);
394   fNodes->Add(v0Rnode7);
395   
396   partube[0] =   r0Right - 0.2;
397   partube[1] =   r0Right;
398   partube[2] =   +fThickness/2.0;
399   
400   TTUBE *v0IR = new TTUBE("V0IR","V0IR","void", partube[0], partube[1], partube[2]);
401  
402   v0Rnode->cd();
403   v0Rnode8 = new TNode("V0IR", "V0IR",v0IR,0.0,0.0,0.0,0);
404   v0Rnode8->SetLineColor(kYellow);
405   fNodes->Add(v0Rnode8);
406
407   partube[0] =   r4Right;
408   partube[1] =   r4Right + 1.0; 
409   partube[2] =   +fThickness/2.0;
410
411   TTUBE  *v0ER = new TTUBE("V0ER","V0ER","void", partube[0], partube[1], partube[2]);
412   
413   v0Rnode->cd();
414   v0Rnode9 = new TNode("V0ER", "V0ER",v0ER,0.0,0.0,0.0,0);
415   v0Rnode9->SetLineColor(kYellow);
416   fNodes->Add(v0Rnode9);
417   
418   Float_t   partubs[5];
419  
420   partubs[0]      =  r0Right;
421   partubs[1]      =  r4Right;
422   partubs[2]      =  fThickness/2.0;
423   partubs[3]      =  90.0-15.0;
424   partubs[4]      = 120.0-15.0;
425
426   TTUBS  *v0R0 = new TTUBS("V0R0", "V0R0", "void",partubs[0], partubs[1], partubs[2], 
427                                                   partubs[3], partubs[4]); 
428                                                   
429   v0R0->SetNumberOfDivisions(ndiv);                                               
430
431   Float_t   r1Right =  r0Right + height1Right;
432   Float_t   offset  = fThickness/2.0 - lidThickness - fThickness1/2.0; 
433   Float_t   offsetFibers = 1.7;
434     
435   partubs[0]     =  r0Right;
436   partubs[1]     =  r1Right;
437   partubs[2]     =  fThickness1/2.0;
438
439   TTUBS *v0R1 = new TTUBS("V0R1", "V0R1", "void", partubs[0], partubs[1], partubs[2], 
440                                                   partubs[3], partubs[4]);
441
442   v0R1->SetNumberOfDivisions(ndiv);
443   
444   Float_t   r2Right  =  r1Right + height2Right;       
445   
446   partubs[0]     =  r1Right;
447   partubs[1]     =  r2Right;
448
449   TTUBS *v0R2 = new TTUBS("V0R2", "V0R2", "void", partubs[0], partubs[1], partubs[2], 
450                                                   partubs[3], partubs[4]);
451
452   v0R2->SetNumberOfDivisions(ndiv);
453
454   Float_t   r3Right  =  r2Right + height3Right;     
455    
456   partubs[0]     =  r2Right;
457   partubs[1]     =  r3Right;
458   
459   TTUBS *v0R3 = new TTUBS("V0R3", "V0R3", "void", partubs[0], partubs[1], partubs[2], 
460                                                   partubs[3], partubs[4]);
461   v0R3->SetNumberOfDivisions(ndiv);
462
463   partubs[0]     =  r3Right;
464   partubs[1]     =  r4Right;
465   
466   TTUBS *v0R4 = new TTUBS("V0R4", "V0R4", "void", partubs[0], partubs[1], partubs[2], 
467                                                   partubs[3], partubs[4]);
468   v0R4->SetNumberOfDivisions(ndiv);
469         
470   Float_t  phi;
471   Float_t  phiDeg= 180./6.;
472     
473   Int_t    ndetR = 1; 
474
475   char     nameNode[12];  
476  
477   for (phi = 15.0; phi < 360.0; phi = phi + phiDeg)
478   
479   {     
480     TRotMatrix* mat920 = new TRotMatrix("rot920","rot920", 90.0, +phi, 90., 90.+phi, 0.0, 0.0 );        
481      
482     sprintf(nameNode,"SUBDER%d",ndetR);
483     
484     v0Rnode->cd();
485     v0Rnode0 = new TNode(nameNode,nameNode,v0R0,0.0,0.0, 0.0,mat920);    
486     v0Rnode0->SetLineColor(kYellow);
487     fNodes->Add(v0Rnode0);
488     ndetR++;
489     
490     sprintf(nameNode,"SUBDER%d",ndetR);
491     v0Rnode0->cd();    
492     v0Rnode1 = new TNode(nameNode,nameNode,v0R1,0.0,0.0, -offset+ offsetFibers ,0);      
493     v0Rnode1->SetLineColor(kColorVZERO);
494     fNodes->Add(v0Rnode1);
495     ndetR++;
496     
497     sprintf(nameNode,"SUBDER%d",ndetR);
498     v0Rnode0->cd();    
499     v0Rnode2 = new TNode(nameNode,nameNode,v0R2,0.0,0.0, -offset,0);     
500     v0Rnode2->SetLineColor(kColorVZERO);
501     fNodes->Add(v0Rnode2);
502     ndetR++;
503
504     sprintf(nameNode,"SUBDER%d",ndetR);
505     v0Rnode0->cd();    
506     v0Rnode3 = new TNode(nameNode,nameNode,v0R3,0.0,0.0, -offset,0);     
507     v0Rnode3->SetLineColor(kColorVZERO);
508     fNodes->Add(v0Rnode3);
509     ndetR++;
510
511     sprintf(nameNode,"SUBDER%d",ndetR);
512     v0Rnode0->cd();    
513     v0Rnode4 = new TNode(nameNode,nameNode,v0R4,0.0,0.0, -offset,0);     
514     v0Rnode4->SetLineColor(kColorVZERO);
515     fNodes->Add(v0Rnode4);
516     ndetR++;
517        
518     v0Rnode0->SetVisibility(2);    
519   }    
520
521 // Left side of VZERO :
522      
523   Float_t   r0Left      =    4.3;   
524   Float_t   height1Left =    3.6; 
525   Float_t   height2Left =    6.4;
526   Float_t   height3Left =   14.9; 
527   Float_t   height4Left =   14.4;     
528   Float_t   heightLeft  = height1Left + height2Left + height3Left + height4Left; 
529                                         
530   Float_t   r4Left      = r0Left  + heightLeft; 
531
532   partube[0] =  r0Left;
533   partube[1] =  r4Left;
534   partube[2] =  fThickness1/2.0; 
535   
536   TTUBE *v0LE = new TTUBE("V0LE", "V0LE", "void", partube[0], partube[1], partube[2]);
537                 
538   top->cd();
539   
540   v0Lnode = new TNode("V0LE","V0LE",v0LE,0.0,0.0,350.0+fThickness1/2.0,0);
541   
542   v0Lnode->SetLineColor(kBlue);
543   fNodes->Add(v0Lnode);
544   
545   v0Lnode->SetVisibility(2);
546
547   partubs[0]      =  r0Left;
548   partubs[1]      =  r4Left;
549   partubs[2]      =  fThickness1/2.0;
550   partubs[3]      =  90.0-15.0;
551   partubs[4]      = 120.0-15.0;
552   
553   TTUBS *v0L0 = new TTUBS("V0L0", "V0L0", "void", partubs[0], partubs[1], partubs[2], 
554                                                   partubs[3], partubs[4]);
555
556   v0L0->SetNumberOfDivisions(ndiv); 
557   v0L0->SetLineColor(7);
558   
559   Float_t   offsetLeft;
560   offsetLeft    = - fThickness1/2.0; 
561
562   Float_t   r1Left =  r0Left + height1Left;        
563       
564   partubs[0]     =  r0Left;
565   partubs[1]     =  r1Left;
566
567   TTUBS *v0L1 = new TTUBS("V0L1", "V0L1", "void", partubs[0], partubs[1], partubs[2], 
568                                                   partubs[3], partubs[4]);
569   v0L1->SetNumberOfDivisions(ndiv);
570   
571   Float_t   r2Left =  r1Left + height2Left;       
572   
573   partubs[0]     =  r1Left;
574   partubs[1]     =  r2Left;
575
576   TTUBS *v0L2 = new TTUBS("V0L2", "V0L2", "void", partubs[0], partubs[1], partubs[2], 
577                                                   partubs[3], partubs[4]);
578   v0L2->SetNumberOfDivisions(ndiv);
579
580   Float_t   r3Left =  r2Left + height3Left; 
581    
582   partubs[0]     =  r2Left;
583   partubs[1]     =  r3Left;
584   
585   TTUBS *v0L3 = new TTUBS("V0L3", "V0L3", "void", partubs[0], partubs[1], partubs[2], 
586                                                   partubs[3], partubs[4]);
587   v0L3->SetNumberOfDivisions(ndiv);
588
589   partubs[0]     =  r3Left;
590   partubs[1]     =  r4Left;
591   
592   TTUBS *v0L4 = new TTUBS("V0L4", "V0L4", "void", partubs[0], partubs[1], partubs[2], 
593                                                   partubs[3], partubs[4]);
594   v0L4->SetNumberOfDivisions(ndiv);
595  
596   Int_t    ndetL   = 1;
597  
598   for (phi = 15.0; phi < 360.0; phi = phi + phiDeg)
599   
600   {
601      
602     TRotMatrix* mat920 = new TRotMatrix("rot920","rot920", 90.0, +phi, 90., 90.+phi, 0.0, 0.0 );        
603      
604     sprintf(nameNode,"SUBDEL%d",ndetL);
605     
606     v0Lnode->cd();
607     v0Lnode0 = new TNode(nameNode,nameNode,v0L0,0.0,0.0, offsetLeft + halfThickQua,mat920);      
608     v0Lnode0->SetLineColor(kColorVZERO);
609     fNodes->Add(v0Lnode0);
610     ndetL++;
611     
612     sprintf(nameNode,"SUBDEL%d",ndetL);
613     v0Lnode0->cd();    
614     v0Lnode1 = new TNode(nameNode,nameNode,v0L1,0.0,0.0, 0.0,0);         
615     v0Lnode1->SetLineColor(kColorVZERO);
616     fNodes->Add(v0Lnode1);
617     ndetL++;
618     
619     sprintf(nameNode,"SUBDEL%d",ndetL);
620     v0Lnode0->cd();    
621     v0Lnode2 = new TNode(nameNode,nameNode,v0L2,0.0,0.0, 0.0,0);         
622     v0Lnode2->SetLineColor(kColorVZERO);
623     fNodes->Add(v0Lnode2);
624     ndetL++;
625
626     sprintf(nameNode,"SUBDEL%d",ndetL);
627     v0Lnode0->cd();    
628     v0Lnode3 = new TNode(nameNode,nameNode,v0L3,0.0,0.0, 0.0,0);         
629     v0Lnode3->SetLineColor(kColorVZERO);
630     fNodes->Add(v0Lnode3);
631     ndetL++;
632
633     sprintf(nameNode,"SUBDEL%d",ndetL);
634     v0Lnode0->cd();    
635     v0Lnode4 = new TNode(nameNode,nameNode,v0L4,0.0,0.0, 0.0,0);         
636     v0Lnode4->SetLineColor(kColorVZERO);
637     fNodes->Add(v0Lnode4);
638     ndetL++; 
639           
640     v0Lnode0->SetVisibility(2);    
641   }         
642 }  
643     
644 //_____________________________________________________________________________
645 void AliVZEROv4::CreateMaterials()
646 {
647
648 // Creates materials used for geometry 
649
650     AliDebug(2,"VZERO create materials");
651     
652 /*
653     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, 
654                            6.9e-9, 7.1e-9, 7.3e-9, 7.5e-9, 7.7e-9, 7.9e-9, 8.1e-9 };
655
656            
657     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, 
658                                6.9e-9, 7.1e-9, 7.3e-9, 7.5e-9, 7.7e-9, 7.9e-9, 8.1e-9 };
659                            
660     Float_t rindex_quarz[14] = { 1.52398,  1.53090, 1.53835, 1.54641, 1.55513, 1.56458, 
661                                  1.57488,  1.58611, 1.59842, 1.61197, 1.62696, 1.64362, 
662                                  1.662295, 1.68337 };
663                                  
664     Float_t absco_quarz[14] = { 105.8,  45.656, 35.665, 28.598, 25.007, 21.04, 17.525, 
665                                 14.177, 9.282, 4.0925, 1.149, 0.3627, 0.1497, 0.05 };   
666                                                                                         
667     Float_t effic_all[14]   = { 1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1. };
668     
669         
670     Float_t rindex_alu[14] = { 1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1. }; 
671     
672     
673     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,
674                                1e-4,1e-4,1e-4,1e-4 };
675     Float_t effic_alu[14]  = { 1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1. };
676
677 */        
678
679     Int_t *idtmed = fIdtmed->GetArray()-2999;
680     
681     
682 //  Parameters related to Quarz (SiO2) :
683  
684     Float_t aqua[2], zqua[2], densqua, wmatqua[2];
685     Int_t nlmatqua;
686     
687     aqua[0]    = 28.09;
688     aqua[1]    = 16.;
689     zqua[0]    = 14.;
690     zqua[1]    = 8.;
691     densqua    = 2.64;
692     nlmatqua   = -2;
693     wmatqua[0] = 1.;
694     wmatqua[1] = 2.;
695
696 // Parameters  related to aluminum sheets :
697     
698     Float_t  aal   = 26.98;
699     Float_t  zal   = 13.00; 
700     Float_t  densal=   2.7; 
701     Float_t  radlal=   8.9;
702        
703 // Parameters  related to scintillator CH :
704     
705     Float_t ascin[2] = {1.00794,12.011};
706     Float_t zscin[2] = {1.,6.};
707     Float_t wscin[2] = {1.,1.};
708     Float_t denscin  = 1.032;
709     
710 // AIR
711
712     Float_t aAir[4]={12.,14.,16.,36.};
713     Float_t zAir[4]={6.,7.,8.,18.};
714     Float_t wAir[4]={0.000124,0.755267,0.231781,0.012827};
715     Float_t dAir = 1.20479E-3;
716     
717 //  Definition of materials :
718
719 // AIR
720
721     AliMixture( 1, "AIR A$", aAir,zAir,dAir,4,wAir);
722     AliMixture(11, "AIR I$", aAir,zAir,dAir,4,wAir);
723     AliMaterial( 2, "CARBON$"  , 12.01, 6.0, 2.265, 18.8, 49.9, 0, 0);
724     AliMixture(  3, "QUA", aqua, zqua, densqua, nlmatqua, wmatqua);
725     AliMaterial( 4, "ALUMINIUM1$", 26.98, 13., 2.7, 8.9, 37.2, 0, 0);
726     AliMaterial( 5, "ALUMINIUM2$", aal, zal, densal, radlal, 0, 0, 0);
727  
728     AliMixture( 6, "Scintillator$",ascin,zscin,denscin,-2,wscin);
729     
730      
731     Int_t   iSXFLD = gAlice->Field()->Integ();
732     Float_t sXMGMX = gAlice->Field()->Max();
733     
734     Float_t tmaxfd, stemax, deemax, epsil, stmin;
735         
736     tmaxfd = 10.;
737     stemax = 0.1;
738     deemax = 0.1;     
739     epsil  = 0.001;
740     stmin  = 0.001;
741   
742 //  Active Air :    
743     AliMedium(1, "ACTIVE AIR$", 1, 1, iSXFLD, sXMGMX,
744               10.0, 1.0, 0.1, 0.1, 10.0, 0, 0) ;
745
746 //  Inactive air : 
747   
748     AliMedium(11, "INACTIVE AIR$", 11, 0, iSXFLD, sXMGMX,
749               10.0, 1.0, 0.1, 0.1, 10.0, 0, 0) ;
750     
751     AliMedium(2, "CARBON$ ", 2,  1, iSXFLD, sXMGMX,
752               tmaxfd, stemax, deemax, epsil, stmin, 0, 0);   
753
754     AliMedium(3, "QUARZ$", 3, 1, iSXFLD, sXMGMX,
755               tmaxfd, fMaxStepQua, fMaxDestepQua, epsil, stmin, 0, 0);
756     
757     AliMedium(4,"ALUMINUM1$",4, 1, iSXFLD, sXMGMX,
758               tmaxfd, fMaxStepAlu, fMaxDestepAlu, epsil, stmin, 0, 0);
759               
760
761     AliMedium(5,"ALUMINUM2$",5, 1, iSXFLD, sXMGMX,
762               tmaxfd, fMaxStepAlu, fMaxDestepAlu, epsil, stmin, 0, 0);    
763
764     AliMedium(6,"SCINTILLATOR$",6, 1, iSXFLD, sXMGMX, 10.0, 0.1, 0.1, 0.003, 0.003, 0, 0);
765
766     gMC->Gstpar(idtmed[3000], "LOSS", 1.);  //  [3000] = air ACTIF  [3010] = air INACTIF
767     gMC->Gstpar(idtmed[3000], "HADR", 1.);
768     gMC->Gstpar(idtmed[3000], "DCAY", 1.);
769     gMC->Gstpar(idtmed[3000], "DRAY", 1.);
770     
771     gMC->Gstpar(idtmed[3001], "LOSS", 1.);  //  [3001] = carbon
772     gMC->Gstpar(idtmed[3001], "HADR", 1.);
773     gMC->Gstpar(idtmed[3001], "DCAY", 1.);
774     gMC->Gstpar(idtmed[3001], "DRAY", 1.);
775
776     gMC->Gstpar(idtmed[3002], "LOSS", 1.);  //  [3002] = quartz
777     gMC->Gstpar(idtmed[3002], "HADR", 1.);
778     gMC->Gstpar(idtmed[3002], "DCAY", 1.);
779     gMC->Gstpar(idtmed[3002], "DRAY", 1.);  
780     gMC->Gstpar(idtmed[3002], "CUTGAM",0.5E-4) ; 
781     gMC->Gstpar(idtmed[3002], "CUTELE",1.0E-4) ;
782     
783     gMC->Gstpar(idtmed[3003], "LOSS", 1.);  //  [3003] = normal aluminum
784     gMC->Gstpar(idtmed[3003], "HADR", 1.);
785     gMC->Gstpar(idtmed[3003], "DCAY", 1.);
786     gMC->Gstpar(idtmed[3003], "DRAY", 1.);
787     
788     gMC->Gstpar(idtmed[3004], "LOSS", 1.);  //  [3004] = reflecting aluminum
789     gMC->Gstpar(idtmed[3004], "HADR", 1.);
790     gMC->Gstpar(idtmed[3004], "DCAY", 1.);
791     gMC->Gstpar(idtmed[3004], "DRAY", 1.);
792     gMC->Gstpar(idtmed[3004], "CUTGAM",0.5E-4) ; 
793     gMC->Gstpar(idtmed[3004], "CUTELE",1.0E-4) ;
794     
795     gMC->Gstpar(idtmed[3005], "LOSS", 1.);  //  [3005] = scintillator
796     gMC->Gstpar(idtmed[3005], "HADR", 1.);
797     gMC->Gstpar(idtmed[3005], "DCAY", 1.);
798     gMC->Gstpar(idtmed[3005], "DRAY", 1.); 
799     gMC->Gstpar(idtmed[3005], "CUTGAM",0.5E-4) ; 
800     gMC->Gstpar(idtmed[3005], "CUTELE",1.0E-4) ;
801       
802     
803 //    geant3->Gsckov(idtmed[3002], 14, ppckov, absco_quarz, effic_all,rindex_quarz);    
804 //    geant3->Gsckov(idtmed[3004], 14, ppckov_alu, absco_alu, effic_alu, rindex_alu);
805
806 //    gMC->SetCerenkov(idtmed[3002], 14, ppckov, absco_quarz, effic_all,rindex_quarz);    
807 //    gMC->SetCerenkov(idtmed[3004], 14, ppckov_alu, absco_alu, effic_alu, rindex_alu);
808                                        
809 }
810
811 //_____________________________________________________________________________
812 void AliVZEROv4::DrawModule() const
813 {
814
815 //  Drawing is done in DrawVZERO.C
816
817    AliDebug(2,"VZERO DrawModule");
818 }
819
820 //_____________________________________________________________________________
821 void AliVZEROv4::Init()
822 {
823 // Initialises version 2 of the VZERO Detector
824 // Just prints an information message
825   
826   AliDebug(2,Form("VZERO version %d initialized",IsVersion()));
827    
828 //   gMC->SetMaxStep(fMaxStepAlu);
829 //   gMC->SetMaxStep(fMaxStepQua);
830    
831     AliVZERO::Init();  
832 }
833
834 //_____________________________________________________________________________
835 void AliVZEROv4::StepManager()
836 {
837  
838 // Step Manager, called at each step 
839  
840      Int_t     copy;
841      static    Int_t   vol[4];
842      static    Float_t hits[21];
843      static    Float_t eloss, tlength;
844      static    Int_t   nPhotonsInStep;
845      static    Int_t   nPhotons; 
846      static    Int_t   numStep;
847      Float_t   ringNumber;
848      Float_t   destep, step;
849      
850      numStep += 1; 
851           
852 //   We keep only charged tracks :
853      
854      if ( !gMC->TrackCharge() || !gMC->IsTrackAlive() ) return; 
855
856      vol[0]    = gMC->CurrentVolOffID(1, vol[1]);
857      vol[2]    = gMC->CurrentVolID(copy);
858      vol[3]    = copy;
859      
860      static Int_t idV0R1 = gMC->VolId("V0R1");
861      static Int_t idV0L1 = gMC->VolId("V0L1");
862      static Int_t idV0R2 = gMC->VolId("V0R2");
863      static Int_t idV0L2 = gMC->VolId("V0L2");
864      static Int_t idV0R3 = gMC->VolId("V0R3");
865      static Int_t idV0L3 = gMC->VolId("V0L3");
866      static Int_t idV0R4 = gMC->VolId("V0R4");
867      static Int_t idV0L4 = gMC->VolId("V0L4");
868
869      if      ( gMC->CurrentVolID(copy) == idV0R1 ||
870                gMC->CurrentVolID(copy) == idV0L1 )
871                ringNumber = 1.0;
872      else if ( gMC->CurrentVolID(copy) == idV0R2 ||
873                gMC->CurrentVolID(copy) == idV0L2 ) 
874                ringNumber = 2.0;  
875      else if ( gMC->CurrentVolID(copy) == idV0R3 ||
876                gMC->CurrentVolID(copy) == idV0L3 )
877                ringNumber = 3.0;
878      else if ( gMC->CurrentVolID(copy) == idV0R4 ||
879                gMC->CurrentVolID(copy) == idV0L4 )
880                ringNumber = 4.0;               
881      else
882                ringNumber = 0.0;
883
884      if  (  ringNumber > 0.5  ) { 
885      
886         destep    = gMC->Edep();
887         step      = gMC->TrackStep();
888         
889         nPhotonsInStep  = Int_t(destep / (fLightYield *1e-9) ); 
890         nPhotonsInStep  = gRandom->Poisson(nPhotonsInStep);
891         
892         eloss    += destep;
893         tlength  += step;        
894         
895         if  ( gMC->IsTrackEntering()  )  { 
896          
897             nPhotons  =  nPhotonsInStep;       
898             gMC->TrackPosition(fTrackPosition);
899             gMC->TrackMomentum(fTrackMomentum);
900             
901             Float_t pt  = TMath::Sqrt( fTrackMomentum.Px() * fTrackMomentum.Px() +
902                                        fTrackMomentum.Py() * fTrackMomentum.Py() );
903                
904             hits[0]  = fTrackPosition.X();
905             hits[1]  = fTrackPosition.Y();
906             hits[2]  = fTrackPosition.Z();               
907             hits[3]  = Float_t (gMC->TrackPid()); 
908
909             hits[4]  = gMC->TrackTime();
910             hits[5]  = gMC->TrackCharge();
911             hits[6]  = fTrackMomentum.Theta()*TMath::RadToDeg();
912             hits[7]  = fTrackMomentum.Phi()*TMath::RadToDeg();
913             hits[8]  = ringNumber;
914          
915             hits[9]  = pt;
916             hits[10] = fTrackMomentum.P();
917             hits[11] = fTrackMomentum.Px();
918             hits[12] = fTrackMomentum.Py();
919             hits[13] = fTrackMomentum.Pz();
920             
921             TParticle *par = gAlice->GetMCApp()->Particle(gAlice->GetMCApp()->GetCurrentTrackNumber());
922             hits[14] = par->Vx();
923             hits[15] = par->Vy();
924             hits[16] = par->Vz();
925             
926             tlength  = 0.0;
927             eloss    = 0.0;         
928          }
929          
930          nPhotons  = nPhotons + nPhotonsInStep;
931          
932          if( gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()){
933          
934          nPhotons  = nPhotons - Int_t((Float_t(nPhotons) * fLightAttenuation * fnMeters));       
935          nPhotons  = nPhotons - Int_t( Float_t(nPhotons) * fFibToPhot);  
936          
937          hits[17] =   eloss;
938          hits[18] = tlength;
939          hits[19] = nPhotons;
940          hits[20] = GetCellId (vol, hits); 
941                  
942          AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol, hits);
943                  
944          tlength         = 0.0;
945          eloss           = 0.0; 
946          nPhotons        =   0;
947          nPhotonsInStep  =   0;
948          
949          numStep         =   0;  
950          } 
951     }
952       
953 }
954
955 //_____________________________________________________________________________
956 void AliVZEROv4::AddHit(Int_t track, Int_t *vol, Float_t *hits)
957 {
958   
959 //  Adds a VZERO hit
960   
961   TClonesArray &lhits = *fHits;
962   new(lhits[fNhits++]) AliVZEROhit(fIshunt,track,vol,hits);
963 }
964
965 //_____________________________________________________________________________
966 void AliVZEROv4::AddDigits(Int_t *tracks, Int_t* digits) 
967 {
968
969 //  Adds a VZERO digit
970
971    TClonesArray  &ldigits = *fDigits;
972    new(ldigits[fNdigits++]) AliVZEROdigit(tracks, digits);
973 }
974
975 //_____________________________________________________________________________
976 void AliVZEROv4::MakeBranch(Option_t *option)
977 {
978   
979 // Creates new branches in the current Root Tree
980     
981   char branchname[10];
982   sprintf(branchname,"%s",GetName());
983   AliDebug(2,Form("fBufferSize = %d",fBufferSize));
984   
985   const char *cH = strstr(option,"H");
986   
987   if (fHits   && TreeH() && cH) {
988     TreeH()->Branch(branchname,&fHits, fBufferSize);
989     AliDebug(2,Form("Making Branch %s for hits",branchname));
990   }     
991
992   const char *cD = strstr(option,"D");
993   
994   if (fDigits   && fLoader->TreeD() && cD) {
995     fLoader->TreeD()->Branch(branchname,&fDigits, fBufferSize);
996     AliDebug(2,Form("Making Branch %s for digits",branchname));
997   }  
998    
999 }
1000
1001 //_____________________________________________________________________________
1002 Int_t AliVZEROv4::GetCellId(Int_t *vol, Float_t *hits) 
1003 {
1004
1005   //   Returns Id of scintillator cell
1006   //   Right side from  0 to 47
1007   //   Left  side from 48 to 95
1008
1009    Int_t index = vol[1];
1010    fCellId     = 0;
1011    
1012    if (index < 10) index = index + 12; 
1013    
1014    if (hits[2] < 0.0) { 
1015       index = (index - 10) + ( ( Int_t(hits[8]) - 1 ) * 12);
1016       fCellId   = index;
1017    }
1018    else if (hits[2] > 0.0)
1019    {
1020       index = (index + 38) + ( ( Int_t(hits[8]) - 1 ) * 12);
1021       fCellId   = index;}
1022            
1023    return fCellId;
1024 }