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