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