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