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