]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSv0.cxx
More Coding Convention respect
[u/mrichter/AliRoot.git] / PHOS / AliPHOSv0.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 // Implementation version v0 of PHOS Manager class 
20 // Layout EMC + PPSD has name GPS2  
21 //                  
22 //*-- Author: Yves Schutz (SUBATECH)
23
24
25 // --- ROOT system ---
26
27 #include "TBRIK.h"
28 #include "TNode.h"
29 #include "TRandom.h"
30
31
32 // --- Standard library ---
33
34 #include <stdio.h>
35 #include <string.h>
36 #include <stdlib.h>
37 #include <strstream.h>
38
39 // --- AliRoot header files ---
40
41 #include "AliPHOSv0.h"
42 #include "AliPHOSHit.h"
43 #include "AliPHOSDigit.h"
44 #include "AliPHOSReconstructioner.h"
45 #include "AliRun.h"
46 #include "AliConst.h"
47
48 ClassImp(AliPHOSv0)
49
50 //____________________________________________________________________________
51 AliPHOSv0::AliPHOSv0()
52 {
53   // ctor
54   fNTmpHits = 0 ; 
55   fTmpHits  = 0 ; 
56 }
57
58 //____________________________________________________________________________
59 AliPHOSv0::AliPHOSv0(const char *name, const char *title):
60   AliPHOS(name,title)
61 {
62   // ctor : title is used to identify the layout
63   //        GPS2 = 5 modules (EMC + PPSD)   
64   // We use 2 arrays of hits :
65   //
66   //   - fHits (the "normal" one), which retains the hits associated with
67   //     the current primary particle being tracked
68   //     (this array is reset after each primary has been tracked).
69   //
70   //   - fTmpHits, which retains all the hits of the current event. It 
71   //     is used for the digitization part.
72
73   fPinElectronicNoise = 0.010 ;
74   fDigitThreshold      = 1. ;   // 1 GeV 
75
76   // We do not want to save in TreeH the raw hits
77   // fHits   = new TClonesArray("AliPHOSHit",100) ;
78   // gAlice->AddHitList(fHits) ; 
79
80   // But save the cumulated hits instead (need to create the branch myself)
81   // It is put in the Digit Tree because the TreeH is filled after each primary
82  // and the TreeD at the end of the event (branch is set in FinishEvent() ).
83   
84   fTmpHits= new TClonesArray("AliPHOSHit",1000) ;
85
86   fNTmpHits = fNhits = 0 ;
87
88   fDigits = new TClonesArray("AliPHOSDigit",1000) ;
89
90
91   fIshunt     =  1 ; // All hits are associated with primary particles
92  
93   // gets an instance of the geometry parameters class  
94    
95   fGeom =  AliPHOSGeometry::GetInstance(title, "") ; 
96
97   if (fGeom->IsInitialized() ) 
98     cout << "AliPHOSv0 : PHOS geometry intialized for " << fGeom->GetName() << endl ;
99   else
100    cout << "AliPHOSv0 : PHOS geometry initialization failed !" << endl ;   
101
102   // For reconstruction
103   // fEmcRecPoints    = new  TObjArray(1000);
104   //fPpsdRecPoints   = new  TObjArray(1000);
105   //fRecParticles    = new  TClonesArray("AliPHOSRecParticle", 1000) ;
106   //fTrackSegments   = new  TClonesArray("AliPHOSTrackSegment", 1000) ;
107 }
108
109 //____________________________________________________________________________
110 AliPHOSv0::AliPHOSv0(AliPHOSReconstructioner * Reconstructioner, const char *name, const char *title):
111   AliPHOS(name,title)
112 {
113   // ctor : title is used to identify the layout
114   //        GPS2 = 5 modules (EMC + PPSD)   
115   // We use 2 arrays of hits :
116   //
117   //   - fHits (the "normal" one), which retains the hits associated with
118   //     the current primary particle being tracked
119   //     (this array is reset after each primary has been tracked).
120   //
121   //   - fTmpHits, which retains all the hits of the current event. It 
122   //     is used for the digitization part.
123
124   fPinElectronicNoise = 0.010 ;
125
126   // We do not want to save in TreeH the raw hits
127   //fHits   = new TClonesArray("AliPHOSHit",100) ;
128
129   fDigits = new TClonesArray("AliPHOSDigit",1000) ;
130   fTmpHits= new TClonesArray("AliPHOSHit",1000) ;
131
132   fNTmpHits = fNhits = 0 ;
133
134   fIshunt     =  1 ; // All hits are associated with primary particles
135  
136   // gets an instance of the geometry parameters class  
137   fGeom =  AliPHOSGeometry::GetInstance(title, "") ; 
138
139   if (fGeom->IsInitialized() ) 
140     cout << "AliPHOSv0 : PHOS geometry intialized for " << fGeom->GetName() << endl ;
141   else
142    cout << "AliPHOSv0 : PHOS geometry initialization failed !" << endl ;   
143
144   // Defining the PHOS Reconstructioner
145  
146  fReconstructioner = Reconstructioner ;
147
148
149 }
150
151 //____________________________________________________________________________
152 AliPHOSv0::~AliPHOSv0()
153 {
154   // dtor
155
156   if ( fTmpHits) {
157     fTmpHits->Delete() ; 
158     delete fTmpHits ;
159     fTmpHits = 0 ; 
160   }
161
162   if ( fEmcRecPoints ) {
163     fEmcRecPoints->Delete() ; 
164     delete fEmcRecPoints ; 
165     fEmcRecPoints = 0 ; 
166   }
167
168   if ( fPpsdRecPoints ) { 
169     fPpsdRecPoints->Delete() ;
170     delete fPpsdRecPoints ;
171     fPpsdRecPoints = 0 ; 
172   }
173   
174   if ( fTrackSegments ) {
175     fTrackSegments->Delete() ; 
176     delete fTrackSegments ;
177     fTrackSegments = 0 ; 
178   }
179
180 }
181
182 //____________________________________________________________________________
183 void AliPHOSv0::AddHit(Int_t primary, Int_t Id, Float_t * hits)
184 {
185   // Add a hit to the hit list.
186   // A PHOS hit is the sum of all hits in a single crystal
187   //   or in a single PPSD gas cell
188
189   Int_t hitCounter ;
190   TClonesArray &ltmphits = *fTmpHits ;
191   AliPHOSHit *newHit ;
192   AliPHOSHit *curHit ;
193   //  AliPHOSHit *curHit2 ;
194   Bool_t deja = kFALSE ;
195
196   // In any case, fills the fTmpHit TClonesArray (with "accumulated hits")
197
198   newHit = new AliPHOSHit(primary, Id, hits) ;
199
200   // We do not want to save in TreeH the raw hits 
201   //  TClonesArray &lhits = *fHits;
202
203   for ( hitCounter = 0 ; hitCounter < fNTmpHits && !deja ; hitCounter++ ) {
204     curHit = (AliPHOSHit*) ltmphits[hitCounter] ;
205   if( *curHit == *newHit ) {
206     *curHit = *curHit + *newHit ;
207     deja = kTRUE ;
208     }
209   }
210          
211   if ( !deja ) {
212     new(ltmphits[fNTmpHits]) AliPHOSHit(*newHit) ;
213     fNTmpHits++ ;
214   }
215
216   // We do not want to save in TreeH the raw hits 
217   //   new(lhits[fNhits]) AliPHOSHit(*newHit) ;    
218   //   fNhits++ ;
219
220   // Please note that the fTmpHits array must survive up to the
221   // end of the events, so it does not appear e.g. in ResetHits() (
222   // which is called at the end of each primary).  
223
224   delete newHit;
225
226 }
227
228
229 //____________________________________________________________________________
230 void AliPHOSv0::BuildGeometry()
231 {
232   // Build the PHOS geometry for the ROOT display
233   //BEGIN_HTML
234   /*
235     <H2>
236      PHOS in ALICE displayed by root
237     </H2>
238     <UL>
239     <LI> All Views
240     <P>
241     <CENTER>
242     <IMG Align=BOTTOM ALT="All Views" SRC="../images/AliPHOSv0AllViews.gif"> 
243     </CENTER></P></LI>
244     <LI> Front View
245     <P>
246     <CENTER>
247     <IMG Align=BOTTOM ALT="Front View" SRC="../images/AliPHOSv0FrontView.gif"> 
248     </CENTER></P></LI>
249      <LI> 3D View 1
250     <P>
251     <CENTER>
252     <IMG Align=BOTTOM ALT="3D View 1" SRC="../images/AliPHOSv03DView1.gif"> 
253     </CENTER></P></LI>
254     <LI> 3D View 2
255     <P>
256     <CENTER>
257     <IMG Align=BOTTOM ALT="3D View 2" SRC="../images/AliPHOSv03DView2.gif"> 
258     </CENTER></P></LI>
259     </UL>
260   */
261   //END_HTML  
262
263   this->BuildGeometryforPHOS() ; 
264   if ( ( strcmp(fGeom->GetName(), "GPS2" ) == 0 ) ) 
265     this->BuildGeometryforPPSD() ;
266   else
267     cout << "AliPHOSv0::BuildGeometry : no charged particle identification system installed" << endl; 
268
269 }
270
271 //____________________________________________________________________________
272 void AliPHOSv0:: BuildGeometryforPHOS(void)
273 {
274  // Build the PHOS-EMC geometry for the ROOT display
275
276   const Int_t kColorPHOS = kRed ;
277   const Int_t kColorXTAL = kBlue ;
278
279   Double_t const kRADDEG = 180.0 / kPI ;
280  
281   new TBRIK( "OuterBox", "PHOS box", "void", fGeom->GetOuterBoxSize(0)/2, 
282                                              fGeom->GetOuterBoxSize(1)/2, 
283                                              fGeom->GetOuterBoxSize(2)/2 );
284
285   // Textolit Wall box, position inside PHOS 
286   
287   new TBRIK( "TextolitBox", "PHOS Textolit box ", "void", fGeom->GetTextolitBoxSize(0)/2, 
288                                                           fGeom->GetTextolitBoxSize(1)/2, 
289                                                           fGeom->GetTextolitBoxSize(2)/2);
290
291   // Polystyrene Foam Plate
292
293   new TBRIK( "UpperFoamPlate", "PHOS Upper foam plate", "void", fGeom->GetTextolitBoxSize(0)/2, 
294                                                                 fGeom->GetSecondUpperPlateThickness()/2, 
295                                                                 fGeom->GetTextolitBoxSize(2)/2 ) ; 
296
297   // Air Filled Box
298  
299   new TBRIK( "AirFilledBox", "PHOS air filled box", "void", fGeom->GetAirFilledBoxSize(0)/2, 
300                                                             fGeom->GetAirFilledBoxSize(1)/2, 
301                                                             fGeom->GetAirFilledBoxSize(2)/2 );
302
303   // Crystals Box
304
305   Float_t xtlX = fGeom->GetCrystalSize(0) ; 
306   Float_t xtlY = fGeom->GetCrystalSize(1) ; 
307   Float_t xtlZ = fGeom->GetCrystalSize(2) ; 
308
309   Float_t xl =  fGeom->GetNPhi() * ( xtlX + 2 * fGeom->GetGapBetweenCrystals() ) / 2.0 + fGeom->GetModuleBoxThickness() ;
310   Float_t yl =  ( xtlY + fGeom->GetCrystalSupportHeight() + fGeom->GetCrystalWrapThickness() + fGeom->GetCrystalHolderThickness() ) / 2.0 
311              + fGeom->GetModuleBoxThickness() / 2.0 ;
312   Float_t zl =  fGeom->GetNZ() * ( xtlZ + 2 * fGeom->GetGapBetweenCrystals() ) / 2.0 +  fGeom->GetModuleBoxThickness() ;
313   
314   new TBRIK( "CrystalsBox", "PHOS crystals box", "void", xl, yl, zl ) ;
315
316 // position PHOS into ALICE
317
318   Float_t r = fGeom->GetIPtoOuterCoverDistance() + fGeom->GetOuterBoxSize(1) / 2.0 ;
319   Int_t number = 988 ; 
320   Float_t pphi =  TMath::ATan( fGeom->GetOuterBoxSize(0)  / ( 2.0 * fGeom->GetIPtoOuterCoverDistance() ) ) ;
321   pphi *= kRADDEG ;
322   TNode * top = gAlice->GetGeometry()->GetNode("alice") ;
323  
324   char * nodename = new char[20] ;  
325   char * rotname  = new char[20] ; 
326
327   for( Int_t i = 1; i <= fGeom->GetNModules(); i++ ) { 
328    Float_t angle = pphi * 2 * ( i - fGeom->GetNModules() / 2.0 - 0.5 ) ;
329    sprintf(rotname, "%s%d", "rot", number++) ;
330    new TRotMatrix(rotname, rotname, 90, angle, 90, 90 + angle, 0, 0);
331    top->cd();
332    sprintf(nodename,"%s%d", "Module", i) ;    
333    Float_t x =  r * TMath::Sin( angle / kRADDEG ) ;
334    Float_t y = -r * TMath::Cos( angle / kRADDEG ) ;
335    TNode * outerboxnode = new TNode(nodename, nodename, "OuterBox", x, y, 0, rotname ) ;
336    outerboxnode->SetLineColor(kColorPHOS) ;
337    fNodes->Add(outerboxnode) ;
338    outerboxnode->cd() ; 
339    // now inside the outer box the textolit box
340    y = ( fGeom->GetOuterBoxThickness(1) -  fGeom->GetUpperPlateThickness() ) / 2.  ;
341    sprintf(nodename,"%s%d", "TexBox", i) ;  
342    TNode * textolitboxnode = new TNode(nodename, nodename, "TextolitBox", 0, y, 0) ; 
343    textolitboxnode->SetLineColor(kColorPHOS) ;
344    fNodes->Add(textolitboxnode) ;
345    // upper foam plate inside outre box
346    outerboxnode->cd() ; 
347    sprintf(nodename, "%s%d", "UFPlate", i) ;
348    y =  ( fGeom->GetTextolitBoxSize(1) - fGeom->GetSecondUpperPlateThickness() ) / 2.0 ;
349    TNode * upperfoamplatenode = new TNode(nodename, nodename, "UpperFoamPlate", 0, y, 0) ; 
350    upperfoamplatenode->SetLineColor(kColorPHOS) ;
351    fNodes->Add(upperfoamplatenode) ;  
352    // air filled box inside textolit box (not drawn)
353    textolitboxnode->cd();
354    y = ( fGeom->GetTextolitBoxSize(1) - fGeom->GetAirFilledBoxSize(1) ) / 2.0 -  fGeom->GetSecondUpperPlateThickness() ;
355    sprintf(nodename, "%s%d", "AFBox", i) ;
356    TNode * airfilledboxnode = new TNode(nodename, nodename, "AirFilledBox", 0, y, 0) ; 
357    fNodes->Add(airfilledboxnode) ; 
358    // crystals box inside air filled box
359    airfilledboxnode->cd() ; 
360    y = fGeom->GetAirFilledBoxSize(1) / 2.0 - yl 
361        - ( fGeom->GetIPtoCrystalSurface() - fGeom->GetIPtoOuterCoverDistance() - fGeom->GetModuleBoxThickness() 
362        -  fGeom->GetUpperPlateThickness() -  fGeom->GetSecondUpperPlateThickness() ) ; 
363    sprintf(nodename, "%s%d", "XTBox", i) ; 
364    TNode * crystalsboxnode = new TNode(nodename, nodename, "CrystalsBox", 0, y, 0) ;    
365    crystalsboxnode->SetLineColor(kColorXTAL) ; 
366    fNodes->Add(crystalsboxnode) ; 
367   }
368
369   delete[] rotname ;  
370   delete[] nodename ;
371 }
372
373 //____________________________________________________________________________
374 void AliPHOSv0:: BuildGeometryforPPSD(void)
375 {
376  //  Build the PHOS-PPSD geometry for the ROOT display
377  //BEGIN_HTML
378   /*
379     <H2>
380      PPSD displayed by root
381     </H2>
382     <UL>
383     <LI> Zoom on PPSD: Front View
384     <P>
385     <CENTER>
386     <IMG Align=BOTTOM ALT="PPSD Front View" SRC="../images/AliPHOSv0PPSDFrontView.gif"> 
387     </CENTER></P></LI>
388     <LI> Zoom on PPSD: Perspective View
389     <P>
390     <CENTER>
391     <IMG Align=BOTTOM ALT="PPSD Prespective View" SRC="../images/AliPHOSv0PPSDPerspectiveView.gif"> 
392     </CENTER></P></LI>
393     </UL>
394   */
395   //END_HTML  
396   Double_t const kRADDEG = 180.0 / kPI ;
397
398   const Int_t kColorPHOS = kRed ;
399   const Int_t kColorPPSD = kGreen ;
400   const Int_t kColorGas  = kBlue ;  
401   const Int_t kColorAir  = kYellow ; 
402
403   // Box for a full PHOS module
404
405   new TBRIK( "PPSDBox", "PPSD box", "void",  fGeom->GetPPSDBoxSize(0)/2, 
406                                              fGeom->GetPPSDBoxSize(1)/2, 
407                                              fGeom->GetPPSDBoxSize(2)/2 );
408
409   // Box containing one micromegas module 
410
411   new TBRIK( "PPSDModule", "PPSD module", "void",  fGeom->GetPPSDModuleSize(0)/2, 
412                                                    fGeom->GetPPSDModuleSize(1)/2, 
413                                                    fGeom->GetPPSDModuleSize(2)/2 );
414  // top lid
415
416   new TBRIK ( "TopLid", "Micromegas top lid", "void",  fGeom->GetPPSDModuleSize(0)/2,
417                                                        fGeom->GetLidThickness()/2,
418                                                        fGeom->GetPPSDModuleSize(2)/2 ) ; 
419  // composite panel (top and bottom)
420
421   new TBRIK ( "TopPanel", "Composite top panel", "void",  ( fGeom->GetPPSDModuleSize(0) - fGeom->GetMicromegasWallThickness() )/2,
422                                                             fGeom->GetCompositeThickness()/2,
423                                                           ( fGeom->GetPPSDModuleSize(2) - fGeom->GetMicromegasWallThickness() )/2 ) ;  
424   
425   new TBRIK ( "BottomPanel", "Composite bottom panel", "void",  ( fGeom->GetPPSDModuleSize(0) - fGeom->GetMicromegasWallThickness() )/2,
426                                                                   fGeom->GetCompositeThickness()/2,
427                                                                 ( fGeom->GetPPSDModuleSize(2) - fGeom->GetMicromegasWallThickness() )/2 ) ; 
428  // gas gap (conversion and avalanche)
429
430   new TBRIK ( "GasGap", "gas gap", "void",  ( fGeom->GetPPSDModuleSize(0) - fGeom->GetMicromegasWallThickness() )/2,
431                                             ( fGeom->GetConversionGap() +  fGeom->GetAvalancheGap() )/2,
432                                             ( fGeom->GetPPSDModuleSize(2) - fGeom->GetMicromegasWallThickness() )/2 ) ; 
433
434  // anode and cathode 
435
436   new TBRIK ( "Anode", "Anode", "void",  ( fGeom->GetPPSDModuleSize(0) - fGeom->GetMicromegasWallThickness() )/2,
437                                            fGeom->GetAnodeThickness()/2,
438                                          ( fGeom->GetPPSDModuleSize(2) - fGeom->GetMicromegasWallThickness() )/2 ) ; 
439
440   new TBRIK ( "Cathode", "Cathode", "void",  ( fGeom->GetPPSDModuleSize(0) - fGeom->GetMicromegasWallThickness() )/2,
441                                                fGeom->GetCathodeThickness()/2,
442                                              ( fGeom->GetPPSDModuleSize(2) - fGeom->GetMicromegasWallThickness() )/2 ) ; 
443  // PC  
444
445   new TBRIK ( "PCBoard", "Printed Circuit", "void",  ( fGeom->GetPPSDModuleSize(0) - fGeom->GetMicromegasWallThickness() )/2,
446                                                        fGeom->GetPCThickness()/2,
447                                                      ( fGeom->GetPPSDModuleSize(2) - fGeom->GetMicromegasWallThickness() )/2 ) ; 
448  // Gap between Lead and top micromegas
449
450   new TBRIK ( "LeadToM", "Air Gap top", "void", fGeom->GetPPSDBoxSize(0)/2,
451                                                 fGeom->GetMicro1ToLeadGap()/2,
452                                                 fGeom->GetPPSDBoxSize(2)/2  ) ;  
453  
454 // Gap between Lead and bottom micromegas
455
456   new TBRIK ( "MToLead", "Air Gap bottom", "void", fGeom->GetPPSDBoxSize(0)/2,
457                                                    fGeom->GetLeadToMicro2Gap()/2,
458                                                    fGeom->GetPPSDBoxSize(2)/2  ) ; 
459  // Lead converter
460    
461   new TBRIK ( "Lead", "Lead converter", "void", fGeom->GetPPSDBoxSize(0)/2,
462                                                 fGeom->GetLeadConverterThickness()/2,
463                                                 fGeom->GetPPSDBoxSize(2)/2  ) ; 
464
465      // position PPSD into ALICE
466
467   char * nodename = new char[20] ;  
468   char * rotname  = new char[20] ; 
469
470   Float_t r = fGeom->GetIPtoTopLidDistance() + fGeom->GetPPSDBoxSize(1) / 2.0 ;
471   Int_t number = 988 ; 
472   TNode * top = gAlice->GetGeometry()->GetNode("alice") ;
473  
474   for( Int_t i = 1; i <= fGeom->GetNModules(); i++ ) { // the number of PHOS modules
475     Float_t angle = fGeom->GetPHOSAngle(i) ;
476     sprintf(rotname, "%s%d", "rotg", number++) ;
477     new TRotMatrix(rotname, rotname, 90, angle, 90, 90 + angle, 0, 0);
478     top->cd();
479     sprintf(nodename, "%s%d", "Moduleg", i) ;    
480     Float_t x =  r * TMath::Sin( angle / kRADDEG ) ;
481     Float_t y = -r * TMath::Cos( angle / kRADDEG ) ;
482     TNode * ppsdboxnode = new TNode(nodename , nodename ,"PPSDBox", x, y, 0, rotname ) ;
483     ppsdboxnode->SetLineColor(kColorPPSD) ;
484     fNodes->Add(ppsdboxnode) ;
485     ppsdboxnode->cd() ;
486     // inside the PPSD box: 
487     //   1.   fNumberOfModulesPhi x fNumberOfModulesZ top micromegas
488     x = ( fGeom->GetPPSDBoxSize(0) - fGeom->GetPPSDModuleSize(0) ) / 2. ;  
489     {
490       for ( Int_t iphi = 1; iphi <= fGeom->GetNumberOfModulesPhi(); iphi++ ) { // the number of micromegas modules in phi per PHOS module
491         Float_t z = ( fGeom->GetPPSDBoxSize(2) - fGeom->GetPPSDModuleSize(2) ) / 2. ;
492         TNode * micro1node ; 
493         for ( Int_t iz = 1; iz <= fGeom->GetNumberOfModulesZ(); iz++ ) { // the number of micromegas modules in z per PHOS module
494           y = ( fGeom->GetPPSDBoxSize(1) - fGeom->GetMicromegas1Thickness() ) / 2. ; 
495           sprintf(nodename, "%s%d%d%d", "Mic1", i, iphi, iz) ;
496           micro1node  = new TNode(nodename, nodename, "PPSDModule", x, y, z) ;
497           micro1node->SetLineColor(kColorPPSD) ;  
498           fNodes->Add(micro1node) ; 
499           // inside top micromegas
500           micro1node->cd() ; 
501           //      a. top lid
502           y = ( fGeom->GetMicromegas1Thickness() - fGeom->GetLidThickness() ) / 2. ; 
503           sprintf(nodename, "%s%d%d%d", "Lid", i, iphi, iz) ;
504           TNode * toplidnode = new TNode(nodename, nodename, "TopLid", 0, y, 0) ;
505           toplidnode->SetLineColor(kColorPPSD) ;  
506           fNodes->Add(toplidnode) ; 
507           //      b. composite panel
508           y = y - fGeom->GetLidThickness() / 2. - fGeom->GetCompositeThickness() / 2. ; 
509           sprintf(nodename, "%s%d%d%d", "CompU", i, iphi, iz) ;
510           TNode * compupnode = new TNode(nodename, nodename, "TopPanel", 0, y, 0) ;
511           compupnode->SetLineColor(kColorPPSD) ;  
512           fNodes->Add(compupnode) ; 
513           //      c. anode
514           y = y - fGeom->GetCompositeThickness() / 2. - fGeom->GetAnodeThickness()  / 2. ; 
515           sprintf(nodename, "%s%d%d%d", "Ano", i, iphi, iz) ;
516           TNode * anodenode = new TNode(nodename, nodename, "Anode", 0, y, 0) ;
517           anodenode->SetLineColor(kColorPHOS) ;  
518           fNodes->Add(anodenode) ; 
519           //      d.  gas 
520           y = y - fGeom->GetAnodeThickness() / 2. - ( fGeom->GetConversionGap() +  fGeom->GetAvalancheGap() ) / 2. ; 
521           sprintf(nodename, "%s%d%d%d", "GGap", i, iphi, iz) ;
522           TNode * ggapnode = new TNode(nodename, nodename, "GasGap", 0, y, 0) ;
523           ggapnode->SetLineColor(kColorGas) ;  
524           fNodes->Add(ggapnode) ;          
525           //      f. cathode
526           y = y - ( fGeom->GetConversionGap() +  fGeom->GetAvalancheGap() ) / 2. - fGeom->GetCathodeThickness()  / 2. ; 
527           sprintf(nodename, "%s%d%d%d", "Cathode", i, iphi, iz) ;
528           TNode * cathodenode = new TNode(nodename, nodename, "Cathode", 0, y, 0) ;
529           cathodenode->SetLineColor(kColorPHOS) ;  
530           fNodes->Add(cathodenode) ;        
531           //      g. printed circuit
532           y = y - fGeom->GetCathodeThickness() / 2. - fGeom->GetPCThickness()  / 2. ; 
533           sprintf(nodename, "%s%d%d%d", "PC", i, iphi, iz) ;
534           TNode * pcnode = new TNode(nodename, nodename, "PCBoard", 0, y, 0) ;
535           pcnode->SetLineColor(kColorPPSD) ;  
536           fNodes->Add(pcnode) ;        
537           //      h. composite panel
538           y = y - fGeom->GetPCThickness() / 2. - fGeom->GetCompositeThickness()  / 2. ; 
539           sprintf(nodename, "%s%d%d%d", "CompDown", i, iphi, iz) ;
540           TNode * compdownnode = new TNode(nodename, nodename, "BottomPanel", 0, y, 0) ;
541           compdownnode->SetLineColor(kColorPPSD) ;  
542           fNodes->Add(compdownnode) ;   
543           z = z - fGeom->GetPPSDModuleSize(2) ;
544           ppsdboxnode->cd() ;
545         } // end of Z module loop     
546         x = x -  fGeom->GetPPSDModuleSize(0) ; 
547         ppsdboxnode->cd() ;
548       } // end of phi module loop
549     }
550     //   2. air gap      
551     ppsdboxnode->cd() ;
552     y = ( fGeom->GetPPSDBoxSize(1) - 2 * fGeom->GetMicromegas1Thickness() - fGeom->GetMicro1ToLeadGap() ) / 2. ; 
553     sprintf(nodename, "%s%d", "GapUp", i) ;
554     TNode * gapupnode = new TNode(nodename, nodename, "LeadToM", 0, y, 0) ;
555     gapupnode->SetLineColor(kColorAir) ;  
556     fNodes->Add(gapupnode) ;        
557     //   3. lead converter
558     y = y - fGeom->GetMicro1ToLeadGap() / 2. - fGeom->GetLeadConverterThickness() / 2. ; 
559     sprintf(nodename, "%s%d", "LeadC", i) ;
560     TNode * leadcnode = new TNode(nodename, nodename, "Lead", 0, y, 0) ;
561     leadcnode->SetLineColor(kColorPPSD) ;  
562     fNodes->Add(leadcnode) ;        
563     //   4. air gap
564     y = y - fGeom->GetLeadConverterThickness() / 2. - fGeom->GetLeadToMicro2Gap()  / 2. ; 
565     sprintf(nodename, "%s%d", "GapDown", i) ;
566     TNode * gapdownnode = new TNode(nodename, nodename, "MToLead", 0, y, 0) ;
567     gapdownnode->SetLineColor(kColorAir) ;  
568     fNodes->Add(gapdownnode) ;        
569     //    5.  fNumberOfModulesPhi x fNumberOfModulesZ bottom micromegas
570     x = ( fGeom->GetPPSDBoxSize(0) - fGeom->GetPPSDModuleSize(0) ) / 2. - fGeom->GetPhiDisplacement() ;  
571     {
572       for ( Int_t iphi = 1; iphi <= fGeom->GetNumberOfModulesPhi(); iphi++ ) { 
573         Float_t z = ( fGeom->GetPPSDBoxSize(2) - fGeom->GetPPSDModuleSize(2) ) / 2.  - fGeom->GetZDisplacement() ;;
574         TNode * micro2node ; 
575         for ( Int_t iz = 1; iz <= fGeom->GetNumberOfModulesZ(); iz++ ) { 
576           y = - ( fGeom->GetPPSDBoxSize(1) - fGeom->GetMicromegas2Thickness() ) / 2. ; 
577           sprintf(nodename, "%s%d%d%d", "Mic2", i, iphi, iz) ;
578           micro2node  = new TNode(nodename, nodename, "PPSDModule", x, y, z) ;
579           micro2node->SetLineColor(kColorPPSD) ;  
580           fNodes->Add(micro2node) ; 
581           // inside bottom micromegas
582           micro2node->cd() ; 
583           //      a. top lid
584           y = ( fGeom->GetMicromegas2Thickness() - fGeom->GetLidThickness() ) / 2. ; 
585           sprintf(nodename, "%s%d", "Lidb", i) ;
586           TNode * toplidbnode = new TNode(nodename, nodename, "TopLid", 0, y, 0) ;
587           toplidbnode->SetLineColor(kColorPPSD) ;  
588           fNodes->Add(toplidbnode) ; 
589           //      b. composite panel
590           y = y - fGeom->GetLidThickness() / 2. - fGeom->GetCompositeThickness() / 2. ; 
591           sprintf(nodename, "%s%d", "CompUb", i) ;
592           TNode * compupbnode = new TNode(nodename, nodename, "TopPanel", 0, y, 0) ;
593           compupbnode->SetLineColor(kColorPPSD) ;  
594           fNodes->Add(compupbnode) ; 
595           //      c. anode
596           y = y - fGeom->GetCompositeThickness() / 2. - fGeom->GetAnodeThickness()  / 2. ; 
597           sprintf(nodename, "%s%d", "Anob", i) ;
598           TNode * anodebnode = new TNode(nodename, nodename, "Anode", 0, y, 0) ;
599           anodebnode->SetLineColor(kColorPPSD) ;  
600           fNodes->Add(anodebnode) ; 
601           //      d. conversion gas
602           y = y - fGeom->GetAnodeThickness() / 2. - ( fGeom->GetConversionGap() +  fGeom->GetAvalancheGap() )  / 2. ; 
603           sprintf(nodename, "%s%d", "GGapb", i) ;
604           TNode * ggapbnode = new TNode(nodename, nodename, "GasGap", 0, y, 0) ;
605           ggapbnode->SetLineColor(kColorGas) ;  
606           fNodes->Add(ggapbnode) ;           
607           //      f. cathode
608           y = y - ( fGeom->GetConversionGap() + fGeom->GetAvalancheGap() ) / 2. - fGeom->GetCathodeThickness()  / 2. ; 
609           sprintf(nodename, "%s%d", "Cathodeb", i) ;
610           TNode * cathodebnode = new TNode(nodename, nodename, "Cathode", 0, y, 0) ;
611           cathodebnode->SetLineColor(kColorPPSD) ;  
612           fNodes->Add(cathodebnode) ;        
613           //      g. printed circuit
614           y = y - fGeom->GetCathodeThickness() / 2. - fGeom->GetPCThickness()  / 2. ; 
615           sprintf(nodename, "%s%d", "PCb", i) ;
616           TNode * pcbnode = new TNode(nodename, nodename, "PCBoard", 0, y, 0) ;
617           pcbnode->SetLineColor(kColorPPSD) ;  
618           fNodes->Add(pcbnode) ;        
619           //      h. composite pane
620           y = y - fGeom->GetPCThickness() / 2. - fGeom->GetCompositeThickness()  / 2. ; 
621           sprintf(nodename, "%s%d", "CompDownb", i) ;
622           TNode * compdownbnode = new TNode(nodename, nodename, "BottomPanel", 0, y, 0) ;
623           compdownbnode->SetLineColor(kColorPPSD) ;  
624           fNodes->Add(compdownbnode) ;        
625           z = z - fGeom->GetPPSDModuleSize(2) ;
626           ppsdboxnode->cd() ;
627         } // end of Z module loop     
628         x = x -  fGeom->GetPPSDModuleSize(0) ; 
629         ppsdboxnode->cd() ;
630       } // end of phi module loop
631     }
632   } // PHOS modules
633  
634   delete[] rotname ;  
635   delete[] nodename ; 
636
637 }
638
639 //____________________________________________________________________________
640 void AliPHOSv0::CreateGeometry()
641 {
642   // Create the PHOS geometry for Geant
643
644   AliPHOSv0 *phostmp = (AliPHOSv0*)gAlice->GetModule("PHOS") ;
645
646   if ( phostmp == NULL ) {
647     
648     fprintf(stderr, "PHOS detector not found!\n") ;
649     return;
650     
651   }
652   // Get pointer to the array containing media indeces
653   Int_t *idtmed = fIdtmed->GetArray() - 699 ;
654
655   Float_t bigbox[3] ; 
656   bigbox[0] =   fGeom->GetOuterBoxSize(0) / 2.0 ;
657   bigbox[1] = ( fGeom->GetOuterBoxSize(1) + fGeom->GetPPSDBoxSize(1) ) / 2.0 ;
658   bigbox[2] =   fGeom->GetOuterBoxSize(2) / 2.0 ;
659   
660   gMC->Gsvolu("PHOS", "BOX ", idtmed[798], bigbox, 3) ;
661   
662   this->CreateGeometryforPHOS() ; 
663   if ( strcmp( fGeom->GetName(), "GPS2") == 0  ) 
664     this->CreateGeometryforPPSD() ;
665   else
666     cout << "AliPHOSv0::CreateGeometry : no charged particle identification system installed" << endl; 
667   
668   // --- Position  PHOS mdules in ALICE setup ---
669   
670   Int_t idrotm[99] ;
671   Double_t const kRADDEG = 180.0 / kPI ;
672   
673   for( Int_t i = 1; i <= fGeom->GetNModules(); i++ ) {
674     
675     Float_t angle = fGeom->GetPHOSAngle(i) ;
676     AliMatrix(idrotm[i-1], 90.0, angle, 90.0, 90.0+angle, 0.0, 0.0) ;
677  
678     Float_t r = fGeom->GetIPtoOuterCoverDistance() + ( fGeom->GetOuterBoxSize(1) + fGeom->GetPPSDBoxSize(1) ) / 2.0 ;
679
680     Float_t xP1 = r * TMath::Sin( angle / kRADDEG ) ;
681     Float_t yP1 = -r * TMath::Cos( angle / kRADDEG ) ;
682
683     gMC->Gspos("PHOS", i, "ALIC", xP1, yP1, 0.0, idrotm[i-1], "ONLY") ;
684  
685   } // for GetNModules
686
687 }
688
689 //____________________________________________________________________________
690 void AliPHOSv0::CreateGeometryforPHOS()
691 {
692   // Create the PHOS-EMC geometry for GEANT
693     //BEGIN_HTML
694   /*
695     <H2>
696     Geant3 geometry tree of PHOS-EMC in ALICE
697     </H2>
698     <P><CENTER>
699     <IMG Align=BOTTOM ALT="EMC geant tree" SRC="../images/EMCinAlice.gif"> 
700     </CENTER><P>
701   */
702   //END_HTML  
703   
704   // Get pointer to the array containing media indexes
705   Int_t *idtmed = fIdtmed->GetArray() - 699 ;
706
707   // ---
708   // --- Define PHOS box volume, fPUFPill with thermo insulating foam ---
709   // --- Foam Thermo Insulating outer cover dimensions ---
710   // --- Put it in bigbox = PHOS
711
712   Float_t dphos[3] ; 
713   dphos[0] =  fGeom->GetOuterBoxSize(0) / 2.0 ;
714   dphos[1] =  fGeom->GetOuterBoxSize(1) / 2.0 ;
715   dphos[2] =  fGeom->GetOuterBoxSize(2) / 2.0 ;
716
717   gMC->Gsvolu("EMCA", "BOX ", idtmed[706], dphos, 3) ;
718
719   Float_t yO =  - fGeom->GetPPSDBoxSize(1)  / 2.0 ;
720
721   gMC->Gspos("EMCA", 1, "PHOS", 0.0, yO, 0.0, 0, "ONLY") ; 
722
723   // ---
724   // --- Define Textolit Wall box, position inside EMCA ---
725   // --- Textolit Wall box dimentions ---
726  
727  
728   Float_t dptxw[3];
729   dptxw[0] = fGeom->GetTextolitBoxSize(0) / 2.0 ;
730   dptxw[1] = fGeom->GetTextolitBoxSize(1) / 2.0 ;
731   dptxw[2] = fGeom->GetTextolitBoxSize(2) / 2.0 ;
732
733   gMC->Gsvolu("PTXW", "BOX ", idtmed[707], dptxw, 3);
734
735   yO =   (  fGeom->GetOuterBoxThickness(1) -   fGeom->GetUpperPlateThickness() ) / 2.  ;
736    
737   gMC->Gspos("PTXW", 1, "EMCA", 0.0, yO, 0.0, 0, "ONLY") ;
738
739   // --- 
740   // --- Define Upper Polystyrene Foam Plate, place inside PTXW ---
741   // --- immediately below Foam Thermo Insulation Upper plate ---
742
743   // --- Upper Polystyrene Foam plate thickness ---
744  
745   Float_t  dpufp[3] ;
746   dpufp[0] = fGeom->GetTextolitBoxSize(0) / 2.0 ; 
747   dpufp[1] = fGeom->GetSecondUpperPlateThickness() / 2. ;
748   dpufp[2] = fGeom->GetTextolitBoxSize(2) /2.0 ; 
749
750   gMC->Gsvolu("PUFP", "BOX ", idtmed[703], dpufp, 3) ;
751   
752   yO = ( fGeom->GetTextolitBoxSize(1) -  fGeom->GetSecondUpperPlateThickness() ) / 2.0 ;
753   
754   gMC->Gspos("PUFP", 1, "PTXW", 0.0, yO, 0.0, 0, "ONLY") ;
755   
756   // ---
757   // --- Define air-filled box, place inside PTXW ---
758   // --- Inner AIR volume dimensions ---
759  
760
761   Float_t  dpair[3] ;
762   dpair[0] = fGeom->GetAirFilledBoxSize(0) / 2.0 ;
763   dpair[1] = fGeom->GetAirFilledBoxSize(1) / 2.0 ;
764   dpair[2] = fGeom->GetAirFilledBoxSize(2) / 2.0 ;
765
766   gMC->Gsvolu("PAIR", "BOX ", idtmed[798], dpair, 3) ;
767   
768   yO = ( fGeom->GetTextolitBoxSize(1) -  fGeom->GetAirFilledBoxSize(1) ) / 2.0 -   fGeom->GetSecondUpperPlateThickness() ;
769   
770   gMC->Gspos("PAIR", 1, "PTXW", 0.0, yO, 0.0, 0, "ONLY") ;
771
772 // --- Dimensions of PbWO4 crystal ---
773
774   Float_t xtlX =  fGeom->GetCrystalSize(0) ; 
775   Float_t xtlY =  fGeom->GetCrystalSize(1) ; 
776   Float_t xtlZ =  fGeom->GetCrystalSize(2) ; 
777
778   Float_t dptcb[3] ;  
779   dptcb[0] =  fGeom->GetNPhi() * ( xtlX + 2 *  fGeom->GetGapBetweenCrystals() ) / 2.0 + fGeom->GetModuleBoxThickness() ;
780   dptcb[1] = ( xtlY +  fGeom->GetCrystalSupportHeight() +  fGeom->GetCrystalWrapThickness() + fGeom->GetCrystalHolderThickness() ) / 2.0 
781              + fGeom->GetModuleBoxThickness() / 2.0 ;
782   dptcb[2] = fGeom->GetNZ() * ( xtlZ + 2 * fGeom->GetGapBetweenCrystals() ) / 2.0 +  fGeom->GetModuleBoxThickness() ;
783   
784   gMC->Gsvolu("PTCB", "BOX ", idtmed[706], dptcb, 3) ;
785
786   yO =  fGeom->GetAirFilledBoxSize(1) / 2.0 - dptcb[1] 
787        - ( fGeom->GetIPtoCrystalSurface() - fGeom->GetIPtoOuterCoverDistance() - fGeom->GetModuleBoxThickness() 
788        -  fGeom->GetUpperPlateThickness() -  fGeom->GetSecondUpperPlateThickness() ) ;
789   
790   gMC->Gspos("PTCB", 1, "PAIR", 0.0, yO, 0.0, 0, "ONLY") ;
791
792   // ---
793   // --- Define Crystal BLock filled with air, position it inside PTCB ---
794   Float_t dpcbl[3] ; 
795   
796   dpcbl[0] = fGeom->GetNPhi() * ( xtlX + 2 * fGeom->GetGapBetweenCrystals() ) / 2.0 ;
797   dpcbl[1] = ( xtlY + fGeom->GetCrystalSupportHeight() + fGeom->GetCrystalWrapThickness() + fGeom->GetCrystalHolderThickness() ) / 2.0 ;
798   dpcbl[2] = fGeom->GetNZ() * ( xtlZ + 2 * fGeom->GetGapBetweenCrystals() ) / 2.0 ;
799   
800   gMC->Gsvolu("PCBL", "BOX ", idtmed[798], dpcbl, 3) ;
801   
802   // --- Divide PCBL in X (phi) and Z directions --
803   gMC->Gsdvn("PROW", "PCBL", Int_t (fGeom->GetNPhi()), 1) ;
804   gMC->Gsdvn("PCEL", "PROW", Int_t (fGeom->GetNZ()), 3) ;
805
806   yO = -fGeom->GetModuleBoxThickness() / 2.0 ;
807   
808   gMC->Gspos("PCBL", 1, "PTCB", 0.0, yO, 0.0, 0, "ONLY") ;
809
810   // ---
811   // --- Define STeel (actually, it's titanium) Cover volume, place inside PCEL
812   Float_t  dpstc[3] ; 
813   
814   dpstc[0] = ( xtlX + 2 * fGeom->GetCrystalWrapThickness() ) / 2.0 ;
815   dpstc[1] = ( xtlY + fGeom->GetCrystalSupportHeight() + fGeom->GetCrystalWrapThickness() + fGeom->GetCrystalHolderThickness() ) / 2.0 ;
816   dpstc[2] = ( xtlZ + 2 * fGeom->GetCrystalWrapThickness()  + 2 *  fGeom->GetCrystalHolderThickness() ) / 2.0 ;
817   
818   gMC->Gsvolu("PSTC", "BOX ", idtmed[704], dpstc, 3) ;
819
820   gMC->Gspos("PSTC", 1, "PCEL", 0.0, 0.0, 0.0, 0, "ONLY") ;
821
822   // ---
823   // --- Define Tyvek volume, place inside PSTC ---
824   Float_t  dppap[3] ;
825
826   dppap[0] = xtlX / 2.0 + fGeom->GetCrystalWrapThickness() ;
827   dppap[1] = ( xtlY + fGeom->GetCrystalSupportHeight() + fGeom->GetCrystalWrapThickness() ) / 2.0 ;
828   dppap[2] = xtlZ / 2.0 + fGeom->GetCrystalWrapThickness() ;
829   
830   gMC->Gsvolu("PPAP", "BOX ", idtmed[702], dppap, 3) ;
831   
832   yO = ( xtlY + fGeom->GetCrystalSupportHeight() + fGeom->GetCrystalWrapThickness() ) / 2.0 
833               - ( xtlY +  fGeom->GetCrystalSupportHeight() +  fGeom->GetCrystalWrapThickness() + fGeom->GetCrystalHolderThickness() ) / 2.0 ;
834    
835   gMC->Gspos("PPAP", 1, "PSTC", 0.0, yO, 0.0, 0, "ONLY") ;
836
837   // ---
838   // --- Define PbWO4 crystal volume, place inside PPAP ---
839   Float_t  dpxtl[3] ; 
840
841   dpxtl[0] = xtlX / 2.0 ;
842   dpxtl[1] = xtlY / 2.0 ;
843   dpxtl[2] = xtlZ / 2.0 ;
844   
845   gMC->Gsvolu("PXTL", "BOX ", idtmed[699], dpxtl, 3) ;
846
847   yO = ( xtlY + fGeom->GetCrystalSupportHeight() + fGeom->GetCrystalWrapThickness() ) / 2.0 - xtlY / 2.0 - fGeom->GetCrystalWrapThickness() ;
848   
849   gMC->Gspos("PXTL", 1, "PPAP", 0.0, yO, 0.0, 0, "ONLY") ;
850
851   // ---
852   // --- Define crystal support volume, place inside PPAP ---
853   Float_t dpsup[3] ; 
854
855   dpsup[0] = xtlX / 2.0 + fGeom->GetCrystalWrapThickness()  ;
856   dpsup[1] = fGeom->GetCrystalSupportHeight() / 2.0 ;
857   dpsup[2] = xtlZ / 2.0 +  fGeom->GetCrystalWrapThickness() ;
858
859   gMC->Gsvolu("PSUP", "BOX ", idtmed[798], dpsup, 3) ;
860
861   yO =  fGeom->GetCrystalSupportHeight() / 2.0 - ( xtlY +  fGeom->GetCrystalSupportHeight() + fGeom->GetCrystalWrapThickness() ) / 2.0 ;
862
863   gMC->Gspos("PSUP", 1, "PPAP", 0.0, yO, 0.0, 0, "ONLY") ;
864
865   // ---
866   // --- Define PIN-diode volume and position it inside crystal support ---
867   // --- right behind PbWO4 crystal
868
869   // --- PIN-diode dimensions ---
870
871  
872   Float_t dppin[3] ;
873   dppin[0] = fGeom->GetPinDiodeSize(0) / 2.0 ;
874   dppin[1] = fGeom->GetPinDiodeSize(1) / 2.0 ;
875   dppin[2] = fGeom->GetPinDiodeSize(2) / 2.0 ;
876  
877   gMC->Gsvolu("PPIN", "BOX ", idtmed[705], dppin, 3) ;
878  
879   yO = fGeom->GetCrystalSupportHeight() / 2.0 - fGeom->GetPinDiodeSize(1) / 2.0 ;
880  
881   gMC->Gspos("PPIN", 1, "PSUP", 0.0, yO, 0.0, 0, "ONLY") ;
882
883   // ---
884   // --- Define Upper Cooling Panel, place it on top of PTCB ---
885   Float_t dpucp[3] ;
886  // --- Upper Cooling Plate thickness ---
887  
888   dpucp[0] = dptcb[0] ;
889   dpucp[1] = fGeom->GetUpperCoolingPlateThickness() ;
890   dpucp[2] = dptcb[2] ;
891   
892   gMC->Gsvolu("PUCP", "BOX ", idtmed[701], dpucp,3) ;
893   
894   yO = (  fGeom->GetAirFilledBoxSize(1) -  fGeom->GetUpperCoolingPlateThickness() ) / 2. 
895        - ( fGeom->GetIPtoCrystalSurface() - fGeom->GetIPtoOuterCoverDistance() - fGeom->GetModuleBoxThickness()
896            - fGeom->GetUpperPlateThickness() - fGeom->GetSecondUpperPlateThickness() - fGeom->GetUpperCoolingPlateThickness() ) ; 
897   
898   gMC->Gspos("PUCP", 1, "PAIR", 0.0, yO, 0.0, 0, "ONLY") ;
899
900   // ---
901   // --- Define Al Support Plate, position it inside PAIR ---
902   // --- right beneath PTCB ---
903  // --- Al Support Plate thickness ---
904  
905   Float_t dpasp[3] ;
906   dpasp[0] =  fGeom->GetAirFilledBoxSize(0) / 2.0 ;
907   dpasp[1] = fGeom->GetSupportPlateThickness() / 2.0 ;
908   dpasp[2] =  fGeom->GetAirFilledBoxSize(2) / 2.0 ;
909   
910   gMC->Gsvolu("PASP", "BOX ", idtmed[701], dpasp, 3) ;
911   
912   yO = (  fGeom->GetAirFilledBoxSize(1) - fGeom->GetSupportPlateThickness() ) / 2. 
913        -  ( fGeom->GetIPtoCrystalSurface() - fGeom->GetIPtoOuterCoverDistance()
914            - fGeom->GetUpperPlateThickness() - fGeom->GetSecondUpperPlateThickness() + dpcbl[1] * 2 ) ;
915   
916   gMC->Gspos("PASP", 1, "PAIR", 0.0, yO, 0.0, 0, "ONLY") ;
917
918   // ---
919   // --- Define Thermo Insulating Plate, position it inside PAIR ---
920   // --- right beneath PASP ---
921   // --- Lower Thermo Insulating Plate thickness ---
922   
923   Float_t dptip[3] ;
924   dptip[0] = fGeom->GetAirFilledBoxSize(0) / 2.0 ;
925   dptip[1] = fGeom->GetLowerThermoPlateThickness() / 2.0 ;
926   dptip[2] = fGeom->GetAirFilledBoxSize(2) / 2.0 ;
927
928   gMC->Gsvolu("PTIP", "BOX ", idtmed[706], dptip, 3) ;
929
930   yO =  ( fGeom->GetAirFilledBoxSize(1) - fGeom->GetLowerThermoPlateThickness() ) / 2. 
931        -  ( fGeom->GetIPtoCrystalSurface() - fGeom->GetIPtoOuterCoverDistance() - fGeom->GetUpperPlateThickness() 
932             - fGeom->GetSecondUpperPlateThickness() + dpcbl[1] * 2 + fGeom->GetSupportPlateThickness() ) ;
933
934   gMC->Gspos("PTIP", 1, "PAIR", 0.0, yO, 0.0, 0, "ONLY") ;
935
936   // ---
937   // --- Define Textolit Plate, position it inside PAIR ---
938   // --- right beneath PTIP ---
939   // --- Lower Textolit Plate thickness ---
940  
941   Float_t dptxp[3] ;
942   dptxp[0] = fGeom->GetAirFilledBoxSize(0) / 2.0 ;
943   dptxp[1] = fGeom->GetLowerTextolitPlateThickness() / 2.0 ;
944   dptxp[2] = fGeom->GetAirFilledBoxSize(2) / 2.0 ;
945
946   gMC->Gsvolu("PTXP", "BOX ", idtmed[707], dptxp, 3) ;
947
948   yO =  ( fGeom->GetAirFilledBoxSize(1) - fGeom->GetLowerTextolitPlateThickness() ) / 2. 
949        -  ( fGeom->GetIPtoCrystalSurface() - fGeom->GetIPtoOuterCoverDistance() - fGeom->GetUpperPlateThickness() 
950             - fGeom->GetSecondUpperPlateThickness() + dpcbl[1] * 2 + fGeom->GetSupportPlateThickness() 
951             +  fGeom->GetLowerThermoPlateThickness() ) ;
952
953   gMC->Gspos("PTXP", 1, "PAIR", 0.0, yO, 0.0, 0, "ONLY") ;
954
955 }
956
957 //____________________________________________________________________________
958 void AliPHOSv0::CreateGeometryforPPSD()
959 {
960   // Create the PHOS-PPSD geometry for GEANT
961
962   //BEGIN_HTML
963   /*
964     <H2>
965     Geant3 geometry tree of PHOS-PPSD in ALICE
966     </H2>
967     <P><CENTER>
968     <IMG Align=BOTTOM ALT="PPSD geant tree" SRC="../images/PPSDinAlice.gif"> 
969     </CENTER><P>
970   */
971   //END_HTML  
972
973   // Get pointer to the array containing media indexes
974   Int_t *idtmed = fIdtmed->GetArray() - 699 ;
975   
976   // The box containing all ppsd's for one PHOS module filled with air 
977   Float_t ppsd[3] ; 
978   ppsd[0] = fGeom->GetPPSDBoxSize(0) / 2.0 ;  
979   ppsd[1] = fGeom->GetPPSDBoxSize(1) / 2.0 ; 
980   ppsd[2] = fGeom->GetPPSDBoxSize(2) / 2.0 ;
981
982   gMC->Gsvolu("PPSD", "BOX ", idtmed[798], ppsd, 3) ;
983
984   Float_t yO =  fGeom->GetOuterBoxSize(1) / 2.0 ;
985
986   gMC->Gspos("PPSD", 1, "PHOS", 0.0, yO, 0.0, 0, "ONLY") ; 
987
988   // Now we build a micromegas module
989   // The box containing the whole module filled with epoxy (FR4)
990
991   Float_t mppsd[3] ;  
992   mppsd[0] = fGeom->GetPPSDModuleSize(0) / 2.0 ;  
993   mppsd[1] = fGeom->GetPPSDModuleSize(1) / 2.0 ;  
994   mppsd[2] = fGeom->GetPPSDModuleSize(2) / 2.0 ;
995
996   gMC->Gsvolu("MPPS", "BOX ", idtmed[708], mppsd, 3) ;  
997  
998   // Inside mppsd :
999   // 1. The Top Lid made of epoxy (FR4) 
1000
1001   Float_t tlppsd[3] ; 
1002   tlppsd[0] = fGeom->GetPPSDModuleSize(0) / 2.0 ; 
1003   tlppsd[1] = fGeom->GetLidThickness() / 2.0 ;
1004   tlppsd[2] = fGeom->GetPPSDModuleSize(2) / 2.0 ;
1005
1006   gMC->Gsvolu("TLPS", "BOX ", idtmed[708], tlppsd, 3) ; 
1007
1008   Float_t  y0 = ( fGeom->GetMicromegas1Thickness() - fGeom->GetLidThickness() ) / 2. ; 
1009
1010   gMC->Gspos("TLPS", 1, "MPPS", 0.0, y0, 0.0, 0, "ONLY") ; 
1011  
1012   // 2. the upper panel made of composite material
1013
1014   Float_t upppsd[3] ; 
1015   upppsd[0] = ( fGeom->GetPPSDModuleSize(0) - fGeom->GetMicromegasWallThickness() ) / 2.0 ;
1016   upppsd[1] = fGeom->GetCompositeThickness() / 2.0 ;
1017   upppsd[2] = ( fGeom->GetPPSDModuleSize(2) - fGeom->GetMicromegasWallThickness() ) / 2.0 ;
1018  
1019   gMC->Gsvolu("UPPS", "BOX ", idtmed[709], upppsd, 3) ; 
1020   
1021   y0 = y0 - fGeom->GetLidThickness() / 2. - fGeom->GetCompositeThickness() / 2. ; 
1022
1023   gMC->Gspos("UPPS", 1, "MPPS", 0.0, y0, 0.0, 0, "ONLY") ; 
1024
1025   // 3. the anode made of Copper
1026   
1027   Float_t anppsd[3] ; 
1028   anppsd[0] = ( fGeom->GetPPSDModuleSize(0) - fGeom->GetMicromegasWallThickness() ) / 2.0 ; 
1029   anppsd[1] = fGeom->GetAnodeThickness() / 2.0 ; 
1030   anppsd[2] = ( fGeom->GetPPSDModuleSize(2) - fGeom->GetMicromegasWallThickness() ) / 2.0  ; 
1031
1032   gMC->Gsvolu("ANPS", "BOX ", idtmed[710], anppsd, 3) ; 
1033   
1034   y0 = y0 - fGeom->GetCompositeThickness() / 2. - fGeom->GetAnodeThickness()  / 2. ; 
1035   
1036   gMC->Gspos("ANPS", 1, "MPPS", 0.0, y0, 0.0, 0, "ONLY") ; 
1037
1038   // 4. the conversion gap + avalanche gap filled with gas
1039
1040   Float_t ggppsd[3] ; 
1041   ggppsd[0] = ( fGeom->GetPPSDModuleSize(0) - fGeom->GetMicromegasWallThickness() ) / 2.0 ;
1042   ggppsd[1] = ( fGeom->GetConversionGap() +  fGeom->GetAvalancheGap() ) / 2.0 ; 
1043   ggppsd[2] = ( fGeom->GetPPSDModuleSize(2) - fGeom->GetMicromegasWallThickness() ) / 2.0 ;
1044
1045   gMC->Gsvolu("GGPS", "BOX ", idtmed[715], ggppsd, 3) ; 
1046   
1047   // --- Divide GGPP in X (phi) and Z directions --
1048   gMC->Gsdvn("GROW", "GGPS", fGeom->GetNumberOfPadsPhi(), 1) ;
1049   gMC->Gsdvn("GCEL", "GROW", fGeom->GetNumberOfPadsZ() , 3) ;
1050
1051   y0 = y0 - fGeom->GetAnodeThickness() / 2.  - ( fGeom->GetConversionGap() +  fGeom->GetAvalancheGap() ) / 2. ; 
1052
1053   gMC->Gspos("GGPS", 1, "MPPS", 0.0, y0, 0.0, 0, "ONLY") ; 
1054
1055
1056   // 6. the cathode made of Copper
1057
1058   Float_t cappsd[3] ;
1059   cappsd[0] = ( fGeom->GetPPSDModuleSize(0) - fGeom->GetMicromegasWallThickness() ) / 2.0 ;
1060   cappsd[1] = fGeom->GetCathodeThickness() / 2.0 ; 
1061   cappsd[2] = ( fGeom->GetPPSDModuleSize(2) - fGeom->GetMicromegasWallThickness() ) / 2.0  ;
1062
1063   gMC->Gsvolu("CAPS", "BOX ", idtmed[710], cappsd, 3) ; 
1064
1065   y0 = y0 - ( fGeom->GetAvalancheGap() +  fGeom->GetAvalancheGap() ) / 2. - fGeom->GetCathodeThickness()  / 2. ; 
1066
1067   gMC->Gspos("CAPS", 1, "MPPS", 0.0, y0, 0.0, 0, "ONLY") ; 
1068
1069   // 7. the printed circuit made of G10       
1070
1071   Float_t pcppsd[3] ; 
1072   pcppsd[0] = ( fGeom->GetPPSDModuleSize(0) - fGeom->GetMicromegasWallThickness() ) / 2,.0 ; 
1073   pcppsd[1] = fGeom->GetPCThickness() / 2.0 ; 
1074   pcppsd[2] = ( fGeom->GetPPSDModuleSize(2) - fGeom->GetMicromegasWallThickness() ) / 2.0 ;
1075
1076   gMC->Gsvolu("PCPS", "BOX ", idtmed[711], cappsd, 3) ; 
1077
1078   y0 = y0 - fGeom->GetCathodeThickness() / 2. - fGeom->GetPCThickness()  / 2. ; 
1079
1080   gMC->Gspos("PCPS", 1, "MPPS", 0.0, y0, 0.0, 0, "ONLY") ; 
1081
1082   // 8. the lower panel made of composite material
1083                                                     
1084   Float_t lpppsd[3] ; 
1085   lpppsd[0] = ( fGeom->GetPPSDModuleSize(0) - fGeom->GetMicromegasWallThickness() ) / 2.0 ; 
1086   lpppsd[1] = fGeom->GetCompositeThickness() / 2.0 ; 
1087   lpppsd[2] = ( fGeom->GetPPSDModuleSize(2) - fGeom->GetMicromegasWallThickness() ) / 2.0 ;
1088
1089   gMC->Gsvolu("LPPS", "BOX ", idtmed[709], lpppsd, 3) ; 
1090  
1091   y0 = y0 - fGeom->GetPCThickness() / 2. - fGeom->GetCompositeThickness()  / 2. ; 
1092
1093   gMC->Gspos("LPPS", 1, "MPPS", 0.0, y0, 0.0, 0, "ONLY") ; 
1094
1095   // Position the  fNumberOfModulesPhi x fNumberOfModulesZ modules (mppsd) inside PPSD to cover a PHOS module
1096   // the top and bottom one's (which are assumed identical) :
1097
1098    Float_t yt = ( fGeom->GetPPSDBoxSize(1) - fGeom->GetMicromegas1Thickness() ) / 2. ; 
1099    Float_t yb = - ( fGeom->GetPPSDBoxSize(1) - fGeom->GetMicromegas2Thickness() ) / 2. ; 
1100
1101    Int_t copyNumbertop = 0 ; 
1102    Int_t copyNumberbot = fGeom->GetNumberOfModulesPhi() *  fGeom->GetNumberOfModulesZ() ; 
1103
1104    Float_t x  = ( fGeom->GetPPSDBoxSize(0) - fGeom->GetPPSDModuleSize(0) ) / 2. ;  
1105
1106    for ( Int_t iphi = 1; iphi <= fGeom->GetNumberOfModulesPhi(); iphi++ ) { // the number of micromegas modules in phi per PHOS module
1107       Float_t z = ( fGeom->GetPPSDBoxSize(2) - fGeom->GetPPSDModuleSize(2) ) / 2. ;
1108
1109       for ( Int_t iz = 1; iz <= fGeom->GetNumberOfModulesZ(); iz++ ) { // the number of micromegas modules in z per PHOS module
1110         gMC->Gspos("MPPS", ++copyNumbertop, "PPSD", x, yt, z, 0, "ONLY") ;
1111         gMC->Gspos("MPPS", ++copyNumberbot, "PPSD", x, yb, z, 0, "ONLY") ; 
1112         z = z - fGeom->GetPPSDModuleSize(2) ;
1113       } // end of Z module loop   
1114       x = x -  fGeom->GetPPSDModuleSize(0) ; 
1115     } // end of phi module loop
1116
1117    // The Lead converter between two air gaps
1118    // 1. Upper air gap
1119
1120    Float_t uappsd[3] ;
1121    uappsd[0] = fGeom->GetPPSDBoxSize(0) / 2.0 ;
1122    uappsd[1] = fGeom->GetMicro1ToLeadGap() / 2.0 ; 
1123    uappsd[2] = fGeom->GetPPSDBoxSize(2) / 2.0 ;
1124
1125   gMC->Gsvolu("UAPPSD", "BOX ", idtmed[798], uappsd, 3) ; 
1126
1127   y0 = ( fGeom->GetPPSDBoxSize(1) - 2 * fGeom->GetMicromegas1Thickness() - fGeom->GetMicro1ToLeadGap() ) / 2. ; 
1128
1129   gMC->Gspos("UAPPSD", 1, "PPSD", 0.0, y0, 0.0, 0, "ONLY") ; 
1130
1131    // 2. Lead converter
1132  
1133   Float_t lcppsd[3] ; 
1134   lcppsd[0] = fGeom->GetPPSDBoxSize(0) / 2.0 ;
1135   lcppsd[1] = fGeom->GetLeadConverterThickness() / 2.0 ; 
1136   lcppsd[2] = fGeom->GetPPSDBoxSize(2) / 2.0 ;
1137  
1138   gMC->Gsvolu("LCPPSD", "BOX ", idtmed[712], lcppsd, 3) ; 
1139   
1140   y0 = y0 - fGeom->GetMicro1ToLeadGap() / 2. - fGeom->GetLeadConverterThickness() / 2. ; 
1141
1142   gMC->Gspos("LCPPSD", 1, "PPSD", 0.0, y0, 0.0, 0, "ONLY") ; 
1143
1144   // 3. Lower air gap
1145
1146   Float_t lappsd[3] ; 
1147   lappsd[0] = fGeom->GetPPSDBoxSize(0) / 2.0 ; 
1148   lappsd[1] = fGeom->GetLeadToMicro2Gap() / 2.0 ; 
1149   lappsd[2] = fGeom->GetPPSDBoxSize(2) / 2.0 ;
1150
1151   gMC->Gsvolu("LAPPSD", "BOX ", idtmed[798], lappsd, 3) ; 
1152     
1153   y0 = y0 - fGeom->GetLeadConverterThickness() / 2. - fGeom->GetLeadToMicro2Gap()  / 2. ; 
1154   
1155   gMC->Gspos("LAPPSD", 1, "PPSD", 0.0, y0, 0.0, 0, "ONLY") ; 
1156    
1157 }
1158
1159 //___________________________________________________________________________
1160 Int_t AliPHOSv0::Digitize(Float_t Energy)
1161 {
1162   // Applies the energy calibration
1163   
1164   Float_t fB = 100000000. ;
1165   Float_t fA = 0. ;
1166   Int_t chan = Int_t(fA + Energy*fB ) ;
1167   return chan ;
1168 }
1169
1170 //___________________________________________________________________________
1171 void AliPHOSv0::FinishEvent()
1172 {
1173   // Makes the digits from the sum of summed hit in a single crystal or PPSD gas cell
1174   // Adds to the energy the electronic noise
1175   // Keeps digits with energy above fDigitThreshold
1176
1177   // Save the cumulated hits instead of raw hits (need to create the branch myself)
1178   // It is put in the Digit Tree because the TreeH is filled after each primary
1179   // and the TreeD at the end of the event.
1180   
1181   
1182   Int_t i ;
1183   Int_t relid[4];
1184   Int_t j ; 
1185   TClonesArray &lDigits = *fDigits ;
1186   AliPHOSHit  * hit ;
1187   AliPHOSDigit * newdigit ;
1188   AliPHOSDigit * curdigit ;
1189   Bool_t deja = kFALSE ; 
1190   
1191   for ( i = 0 ; i < fNTmpHits ; i++ ) {
1192     hit = (AliPHOSHit*)fTmpHits->At(i) ;
1193     newdigit = new AliPHOSDigit( hit->GetPrimary(), hit->GetId(), Digitize( hit->GetEnergy() ) ) ;
1194     deja =kFALSE ;
1195     for ( j = 0 ; j < fNdigits ;  j++) { 
1196       curdigit = (AliPHOSDigit*) lDigits[j] ;
1197       if ( *curdigit == *newdigit) {
1198         *curdigit = *curdigit + *newdigit ; 
1199         deja = kTRUE ; 
1200       }
1201     }
1202     if ( !deja ) {
1203       new(lDigits[fNdigits]) AliPHOSDigit(* newdigit) ;
1204       fNdigits++ ;  
1205     }
1206  
1207     delete newdigit ;    
1208   } 
1209   
1210   // Noise induced by the PIN diode of the PbWO crystals
1211
1212   Float_t energyandnoise ;
1213   for ( i = 0 ; i < fNdigits ; i++ ) {
1214     newdigit =  (AliPHOSDigit * ) fDigits->At(i) ;
1215     fGeom->AbsToRelNumbering(newdigit->GetId(), relid) ;
1216
1217     if (relid[1]==0){   // Digits belong to EMC (PbW0_4 crystals)
1218       energyandnoise = newdigit->GetAmp() + Digitize(gRandom->Gaus(0., fPinElectronicNoise)) ;
1219
1220       if (energyandnoise < 0 ) 
1221         energyandnoise = 0 ;
1222
1223       if ( newdigit->GetAmp() < fDigitThreshold ) // if threshold not surpassed, remove digit from list
1224         fDigits->RemoveAt(i) ; 
1225     }
1226   }
1227   
1228   fDigits->Compress() ;  
1229
1230   fNdigits =  fDigits->GetEntries() ; 
1231   for (i = 0 ; i < fNdigits ; i++) { 
1232     newdigit = (AliPHOSDigit *) fDigits->At(i) ; 
1233     newdigit->SetIndexInList(i) ; 
1234   }
1235   
1236 }
1237
1238 //____________________________________________________________________________
1239 void AliPHOSv0::Init(void)
1240 {
1241   // Just prints an information message
1242   
1243   Int_t i;
1244
1245   printf("\n");
1246   for(i=0;i<35;i++) printf("*");
1247   printf(" PHOS_INIT ");
1248   for(i=0;i<35;i++) printf("*");
1249   printf("\n");
1250
1251   // Here the PHOS initialisation code (if any!)
1252
1253   for(i=0;i<80;i++) printf("*");
1254   printf("\n");
1255   
1256 }
1257
1258 //___________________________________________________________________________
1259 void AliPHOSv0::MakeBranch(Option_t* opt)
1260 {  
1261   // Create new branche in the current Root Tree in the digit Tree
1262
1263   AliDetector::MakeBranch(opt) ;
1264   
1265   char branchname[10];
1266   sprintf(branchname,"%s",GetName());
1267   char *cdD = strstr(opt,"D");
1268   if (fDigits && gAlice->TreeD() && cdD) {
1269     gAlice->TreeD()->Branch(branchname, &fDigits, fBufferSize);
1270   }
1271
1272   // Create new branche PHOSCH in the current Root Tree in the digit Tree for accumulated Hits
1273   if ( ! (gAlice->IsLegoRun()) ) { // only when not in lego plot mode 
1274     if ( fTmpHits && gAlice->TreeD()  && cdD) {
1275       char branchname[10] ;
1276       sprintf(branchname, "%sCH", GetName()) ;
1277       gAlice->TreeD()->Branch(branchname, &fTmpHits, fBufferSize) ;
1278     }   
1279   }
1280
1281 }
1282
1283
1284 //_____________________________________________________________________________
1285 void AliPHOSv0::Reconstruction(AliPHOSReconstructioner * Reconstructioner)
1286
1287   // 1. Reinitializes the existing RecPoint, TrackSegment, and RecParticles Lists and 
1288   // 2. Creates TreeR with a branch for each list
1289   // 3. Steers the reconstruction processes
1290   // 4. Saves the 3 lists in TreeR
1291   // 5. Write the Tree to File
1292   
1293   fReconstructioner = Reconstructioner ;
1294   
1295   char branchname[10] ;
1296   
1297   // 1.
1298
1299   //  gAlice->MakeTree("R") ; 
1300   Int_t splitlevel = 0 ; 
1301   
1302   if (fEmcRecPoints) { 
1303     fEmcRecPoints->Delete() ; 
1304     delete fEmcRecPoints ;
1305     fEmcRecPoints = 0 ; 
1306   }
1307
1308   //  fEmcRecPoints= new AliPHOSRecPoint::RecPointsList("AliPHOSEmcRecPoint", 1000) ; if TClonesArray
1309   fEmcRecPoints= new AliPHOSRecPoint::RecPointsList(1000) ; 
1310
1311   if ( fEmcRecPoints && gAlice->TreeR() ) {
1312     sprintf(branchname,"%sEmcRP",GetName()) ;
1313     
1314     // gAlice->TreeR()->Branch(branchname, &fEmcRecPoints, fBufferSize); if TClonesArray
1315     gAlice->TreeR()->Branch(branchname, "TObjArray", &fEmcRecPoints, fBufferSize, splitlevel) ; 
1316   }
1317
1318   if (fPpsdRecPoints) { 
1319     fPpsdRecPoints->Delete() ; 
1320     delete fPpsdRecPoints ; 
1321     fPpsdRecPoints = 0 ; 
1322   }
1323
1324   //  fPpsdRecPoints = new AliPHOSRecPoint::RecPointsList("AliPHOSPpsdRecPoint", 1000) ; if TClonesArray
1325   fPpsdRecPoints = new AliPHOSRecPoint::RecPointsList(1000) ;
1326
1327   if ( fPpsdRecPoints && gAlice->TreeR() ) {
1328     sprintf(branchname,"%sPpsdRP",GetName()) ;
1329      
1330      // gAlice->TreeR()->Branch(branchname, &fPpsdRecPoints, fBufferSize); if TClonesArray
1331     gAlice->TreeR()->Branch(branchname, "TObjArray", &fPpsdRecPoints, fBufferSize, splitlevel) ;
1332   }
1333
1334   if (fTrackSegments) { 
1335    fTrackSegments->Delete() ; 
1336     delete fTrackSegments ; 
1337     fTrackSegments = 0 ; 
1338   }
1339
1340   fTrackSegments = new AliPHOSTrackSegment::TrackSegmentsList("AliPHOSTrackSegment", 1000) ;
1341   if ( fTrackSegments && gAlice->TreeR() ) { 
1342     sprintf(branchname,"%sTS",GetName()) ;
1343     gAlice->TreeR()->Branch(branchname, &fTrackSegments, fBufferSize) ;
1344   }
1345
1346   if (fRecParticles) {  
1347     fRecParticles->Delete() ; 
1348     delete fRecParticles ; 
1349     fRecParticles = 0 ; 
1350   }
1351   fRecParticles = new AliPHOSRecParticle::RecParticlesList("AliPHOSRecParticle", 1000) ;
1352   if ( fRecParticles && gAlice->TreeR() ) { 
1353      sprintf(branchname,"%sRP",GetName()) ;
1354      gAlice->TreeR()->Branch(branchname, &fRecParticles, fBufferSize) ;
1355   }
1356   
1357   // 3.
1358
1359   fReconstructioner->Make(fDigits, fEmcRecPoints, fPpsdRecPoints, fTrackSegments, fRecParticles);
1360
1361   // 4. Expand or Shrink the arrays to the proper size
1362   
1363   Int_t size ;
1364   
1365   size = fEmcRecPoints->GetEntries() ;
1366   fEmcRecPoints->Expand(size) ;
1367  
1368   size = fPpsdRecPoints->GetEntries() ;
1369   fPpsdRecPoints->Expand(size) ;
1370
1371   size = fTrackSegments->GetEntries() ;
1372   fTrackSegments->Expand(size) ;
1373
1374   size = fRecParticles->GetEntries() ;
1375   fRecParticles->Expand(size) ;
1376
1377   gAlice->TreeR()->Fill() ;
1378   cout << "filled" << endl ;
1379   // 5.
1380
1381   gAlice->TreeR()->Write() ;
1382   cout << "writen" << endl ;
1383  
1384   // Deleting reconstructed objects
1385   ResetReconstruction();
1386
1387   
1388 }
1389
1390 //____________________________________________________________________________
1391 void AliPHOSv0::ResetDigits() 
1392
1393   // May sound strange, but cumulative hits are store in digits Tree
1394   AliDetector::ResetDigits();
1395   if(  fTmpHits ) {
1396     fTmpHits->Delete();
1397     fNTmpHits = 0 ;
1398   }
1399 }  
1400 //____________________________________________________________________________
1401 void AliPHOSv0::ResetReconstruction() 
1402
1403   // Deleting reconstructed objects
1404
1405   if ( fEmcRecPoints )   fEmcRecPoints->Delete();
1406   if ( fPpsdRecPoints )  fPpsdRecPoints->Delete();
1407   if ( fTrackSegments )  fTrackSegments->Delete();
1408   if ( fRecParticles )   fRecParticles->Delete();
1409   
1410 }
1411 //____________________________________________________________________________
1412
1413 //____________________________________________________________________________
1414 void AliPHOSv0::SetTreeAddress()
1415
1416   //  TBranch *branch;
1417   AliPHOS::SetTreeAddress();
1418
1419  //  //Branch address for TreeR: RecPpsdRecPoint
1420 //   TTree *treeR = gAlice->TreeR();
1421 //   if ( treeR && fPpsdRecPoints ) {
1422 //     branch = treeR->GetBranch("PHOSPpsdRP");
1423 //     if (branch) branch->SetAddress(&fPpsdRecPoints) ;
1424   //  }
1425 }
1426
1427 //____________________________________________________________________________
1428
1429 void AliPHOSv0::StepManager(void)
1430 {
1431   // Accumulates hits as long as the track stays in a single crystal or PPSD gas Cell
1432
1433   Int_t          relid[4] ;      // (box, layer, row, column) indices
1434   Float_t        xyze[4] ;       // position wrt MRS and energy deposited
1435   TLorentzVector pos ;
1436   Int_t copy ;
1437
1438   Int_t primary =  gAlice->GetPrimary( gAlice->CurrentTrack() ); 
1439   TString name = fGeom->GetName() ; 
1440   if ( name == "GPS2" ) { // the CPV is a PPSD
1441     if( gMC->CurrentVolID(copy) == gMC->VolId("GCEL") ) // We are inside a gas cell 
1442     {
1443       gMC->TrackPosition(pos) ;
1444       xyze[0] = pos[0] ;
1445       xyze[1] = pos[1] ;
1446       xyze[2] = pos[2] ;
1447       xyze[3] = gMC->Edep() ; 
1448
1449       if ( xyze[3] != 0 ) { // there is deposited energy 
1450         gMC->CurrentVolOffID(5, relid[0]) ;  // get the PHOS Module number
1451         gMC->CurrentVolOffID(3, relid[1]) ;  // get the Micromegas Module number 
1452       // 1-> Geom->GetNumberOfModulesPhi() *  fGeom->GetNumberOfModulesZ() upper                         
1453       //  >  fGeom->GetNumberOfModulesPhi()  *  fGeom->GetNumberOfModulesZ() lower
1454         gMC->CurrentVolOffID(1, relid[2]) ;  // get the row number of the cell
1455         gMC->CurrentVolID(relid[3]) ;        // get the column number 
1456
1457         // get the absolute Id number
1458
1459         Int_t absid ; 
1460         fGeom->RelToAbsNumbering(relid, absid) ; 
1461
1462         // add current hit to the hit list      
1463         AddHit(primary, absid, xyze);
1464
1465       } // there is deposited energy 
1466      } // We are inside the gas of the CPV  
1467    } // GPS2 configuration
1468   
1469    if(gMC->CurrentVolID(copy) == gMC->VolId("PXTL") )  //  We are inside a PBWO crystal
1470      {
1471        gMC->TrackPosition(pos) ;
1472        xyze[0] = pos[0] ;
1473        xyze[1] = pos[1] ;
1474        xyze[2] = pos[2] ;
1475        xyze[3] = gMC->Edep() ;
1476
1477        if ( xyze[3] != 0 ) {
1478           gMC->CurrentVolOffID(10, relid[0]) ; // get the PHOS module number ;
1479           relid[1] = 0   ;                    // means PBW04
1480           gMC->CurrentVolOffID(4, relid[2]) ; // get the row number inside the module
1481           gMC->CurrentVolOffID(3, relid[3]) ; // get the cell number inside the module
1482
1483       // get the absolute Id number
1484
1485           Int_t absid ; 
1486           fGeom->RelToAbsNumbering(relid, absid) ; 
1487  
1488       // add current hit to the hit list
1489
1490           AddHit(primary, absid, xyze);
1491     
1492        } // there is deposited energy
1493     } // we are inside a PHOS Xtal
1494 }
1495