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