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