]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALv0.cxx
Add new geometry option EMCAL_COMPLETEV1, with 10 SM for 2011 runs.
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALv0.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 /* $Id$ */
16
17 //_________________________________________________________________________
18 // Implementation version v0 of EMCAL Manager class 
19 // An object of this class does not produce hits nor digits
20 // It is the one to use if you do not want to produce outputs in TREEH or TREED
21 // This class places a Geometry of the EMCAL in the ALICE Detector as defined in AliEMCALGeometry.cxx                 
22 //*-- Author: Yves Schutz (SUBATECH)
23 //*-- and   : Sahal Yacoob (LBL / UCT)
24 //          : Alexei Pavlinov (WSU)     SHASHLYK
25
26 // --- ROOT system ---
27 #include <cassert>
28
29 #include <TGeometry.h>
30 #include <TGeoPhysicalNode.h>
31 #include <TGeoManager.h>
32 #include <TGeoMatrix.h>
33 #include <TVirtualMC.h>
34 #include <TArrayI.h>
35 #include <TROOT.h>
36 #include <TList.h>
37 #include <TVector2.h>
38 #include <cassert>
39
40 //--- EMCAL system---
41 #include "AliEMCALShishKebabTrd1Module.h"
42
43 // --- Standard library ---
44
45 //#include <stdio.h>
46
47 // --- AliRoot header files ---
48
49 #include "AliEMCALv0.h"
50 #include "AliEMCALGeometry.h"
51 #include "AliRun.h"
52 #include "AliLog.h"
53 #include "AliGeomManager.h"
54 #include "AliEMCALSpaceFrame.h"
55
56 ClassImp(AliEMCALv0)
57
58 // EMCAL material: look to the AliEMCAL.cxx
59 enum
60  {
61   kIdAIR   = 1599, 
62   kIdPB    = 1600, 
63   kIdSC    = 1601, 
64   kIdAL    = 1602, 
65   kIdSTEEL = 1603,
66   kIdPAPER = 1604
67  };
68
69
70 //______________________________________________________________________
71 AliEMCALv0::AliEMCALv0()
72   : AliEMCAL(),
73     fShishKebabModules(),fEnvelop1(0),fIdRotm(0),fIdTmedArr(0),
74     fSampleWidth(0),fSmodPar0(0),fSmodPar1(0),fSmodPar2(0),fCalFrame(0)
75 {
76   //default ctor
77   for(Int_t i = 0; i < 5 ; i++) fParEMOD[i]=0.0;
78 }
79
80 //______________________________________________________________________
81 AliEMCALv0::AliEMCALv0(const char *name, const char *title)
82   : AliEMCAL(name,title),
83     fShishKebabModules(),fEnvelop1(0),fIdRotm(0),fIdTmedArr(0),
84     fSampleWidth(0),fSmodPar0(0),fSmodPar1(0),fSmodPar2(0),fCalFrame(0)
85 {
86   // ctor : title is used to identify the layout
87   // Apr 25, 2006
88   // Nov 22, 2006 - case of 1X1  
89   
90   for(Int_t i = 0; i < 5 ; i++) fParEMOD[i]=0.0;
91   TString ntmp(GetTitle());
92   ntmp.ToUpper();
93
94   AliEMCALGeometry *g = GetGeometry() ; 
95   TString gn(g->GetName()); gn.ToUpper();
96   fShishKebabModules = g->GetShishKebabTrd1Modules(); 
97   fGeometry = g;
98   fSampleWidth = double(g->GetECPbRadThick()+g->GetECScintThick());
99   if(gn.Contains("V1")) fSampleWidth += 2.*g->GetTrd1BondPaperThick();
100   printf("<I> AliEMCALv0::AliEMCALv : fGeometry %p : gMC %p : fSampleWidth %5.4f\n", 
101          fGeometry, gMC, fSampleWidth);
102 }
103
104 //______________________________________________________________________
105 void AliEMCALv0::CreateGeometry()
106 {
107   // Create the EMCAL geometry for Geant
108   // Geometry of a tower
109   
110   AliEMCALGeometry * geom = GetGeometry() ; 
111   TString gn(geom->GetName());
112   gn.ToUpper(); 
113   
114   if(!(geom->IsInitialized())){
115     Error("CreateGeometry","EMCAL Geometry class has not been set up.");
116   } // end if
117
118   // Get pointer to the array containing media indices
119   fIdTmedArr = fIdtmed->GetArray() - 1599 ;
120   
121   fIdRotm = 1;
122   //  gMC->Matrix(nmat, theta1, phi1, theta2, phi2, theta3, phi3) - see AliModule
123   AliMatrix(fIdRotm, 90.0, 0., 90.0, 90.0, 0.0, 0.0) ; 
124   
125   // Create the EMCAL Mother Volume (a polygone) within which to place the Detector and named XEN1 
126   
127   Float_t envelopA[10];
128   if(gn.Contains("WSUC") ) { // TRD1 for WSUC facility
129     // 17-may-05 - just BOX
130     envelopA[0] = 26;
131     envelopA[1] = 15;
132     envelopA[2] = 30;
133     gMC->Gsvolu("XEN1", "BOX", fIdTmedArr[kIdSC], envelopA, 3) ;
134     fEnvelop1.Set(3);
135     for(int i=0; i<3; i++) fEnvelop1[i] = envelopA[i]; // 23-may-05  
136     // Position the EMCAL Mother Volume (XEN1) in WSUC  
137     gMC->Gspos("XEN1", 1, "WSUC", 0.0, 0.0, 0.0, fIdRotm, "ONLY") ;
138   } else { 
139     envelopA[0] = geom->GetArm1PhiMin();                         // minimum phi angle
140     envelopA[1] = geom->GetArm1PhiMax() - geom->GetArm1PhiMin(); // angular range in phi
141     envelopA[2] = geom->GetNPhiSuperModule();                    // number of sections in phi
142     envelopA[3] = 2;                                             // 2 z coordinates
143     envelopA[4] = -geom->GetEnvelop(2)/2.;                       // zmin - includes padding
144     envelopA[5] = geom->GetEnvelop(0) ;                          // rmin at z1 - includes padding
145     envelopA[6] = geom->GetEnvelop(1) ;                          // rmax at z1 - includes padding
146     envelopA[7] = geom->GetEnvelop(2)/2.;                        // zmax includes padding
147     
148     envelopA[8] = envelopA[5] ;                                  // radii are the same.
149     envelopA[9] = envelopA[6] ;                                  // radii are the same.
150
151     gMC->Gsvolu("XEN1", "PGON", fIdTmedArr[kIdAIR], envelopA, 10) ;   // Polygone filled with air 
152     fEnvelop1.Set(10, envelopA);
153     if (gDebug==2) {
154       printf("CreateGeometry: XEN1 = %f, %f\n", envelopA[5], envelopA[6]); 
155       printf("CreateGeometry: XU0 = %f, %f\n", envelopA[5], envelopA[6]); 
156     }
157     // Position the EMCAL Mother Volume (XEN1) in Alice (ALIC)  
158     gMC->Gspos(geom->GetNameOfEMCALEnvelope(), 1, "ALIC", 0.0, 0.0, 0.0, fIdRotm, "ONLY") ;
159   }
160
161   // COMPACT, TRD1
162   AliDebug(2,Form("Shish-Kebab geometry : %s", GetTitle())); 
163   CreateShishKebabGeometry();
164
165   //Space Frame
166   AliDebug(2,"Creating EMCAL Space Frame");
167   fCalFrame = new AliEMCALSpaceFrame();
168   fCalFrame->CreateGeometry();
169
170 }
171
172 //______________________________________________________________________
173 void AliEMCALv0::Init(void)
174 {
175     // Just prints an information message
176   AliEMCAL::Init();
177   if(AliLog::GetGlobalDebugLevel()>0) { 
178     TString message("\n") ; 
179     message += "*****************************************\n" ;
180     
181     // Here the EMCAL initialisation code (if any!)
182     
183     AliEMCALGeometry * geom = GetGeometry() ; 
184     
185     if (geom!=0) {   
186       message += "AliEMCAL " ; 
187       message += Version() ; 
188       message += "EMCAL geometry initialized for " ; 
189       message += geom->GetName()  ;
190     }
191     else {
192       message += "AliEMCAL " ; 
193       message += Version() ;  
194       message += "EMCAL geometry initialization failed !" ; 
195     }
196     message += "\n*****************************************" ;
197     printf("%s",message.Data() ) ; 
198   }
199 }
200
201 // 24-aug-04 by PAI
202 //______________________________________________________________________
203 void AliEMCALv0::CreateShishKebabGeometry()
204 {  
205   // Oct 26,2010
206   // TRD1
207   AliEMCALGeometry * g = GetGeometry(); 
208   TString gn(g->GetName()); gn.ToUpper(); 
209   Double_t trd1Angle = g->GetTrd1Angle()*TMath::DegToRad(), tanTrd1 = TMath::Tan(trd1Angle/2.);
210   // see AliModule::fFIdTmedArr
211   //  fIdTmedArr = fIdtmed->GetArray() - 1599 ; // see AliEMCAL::::CreateMaterials()
212   //  int kIdAIR=1599, kIdPB = 1600, kIdSC = 1601, kIdSTEEL = 1603;
213   //  idAL = 1602;
214   Double_t par[10], xpos=0., ypos=0., zpos=0.;
215
216   CreateSmod(g->GetNameOfEMCALEnvelope());
217
218   CreateEmod("SMOD","EMOD"); // 18-may-05
219
220   if(g->GetKey110DEG()) CreateEmod("SM10","EMOD"); // Nov 1,2006 
221
222   // Sensitive SC  (2x2 tiles)
223   double parSCM0[5]={0,0,0,0}, *dummy = 0, parTRAP[11];
224
225   if(!gn.Contains("V1")) {
226     double wallThickness = g->GetPhiModuleSize()/g->GetNPHIdiv() -  g->GetPhiTileSize();
227     for(int i=0; i<3; i++) parSCM0[i] = fParEMOD[i] - wallThickness;
228     parSCM0[3] = fParEMOD[3];
229     gMC->Gsvolu("SCM0", "TRD1", fIdTmedArr[kIdAIR], parSCM0, 4);
230     gMC->Gspos("SCM0", 1, "EMOD", 0., 0., 0., 0, "ONLY") ;
231   } else {
232     double wTh = g->GetLateralSteelStrip();
233     parSCM0[0] = fParEMOD[0] - wTh + tanTrd1*g->GetTrd1AlFrontThick();
234     parSCM0[1] = fParEMOD[1] - wTh;
235     parSCM0[2] = fParEMOD[2] - wTh;
236     parSCM0[3] = fParEMOD[3] - g->GetTrd1AlFrontThick()/2.;
237     gMC->Gsvolu("SCM0", "TRD1", fIdTmedArr[kIdAIR], parSCM0, 4);
238     double zshift = g->GetTrd1AlFrontThick()/2.;
239     gMC->Gspos("SCM0", 1, "EMOD", 0., 0., zshift, 0, "ONLY");
240     // 
241     CreateAlFrontPlate("EMOD","ALFP");
242   }
243
244   if(g->GetNPHIdiv()==2 && g->GetNETAdiv()==2) {
245     // Division to tile size - 1-oct-04
246     AliDebug(2,Form(" Divide SCM0 on y-axis %i\n", g->GetNETAdiv()));
247     gMC->Gsdvn("SCMY","SCM0", g->GetNETAdiv(), 2); // y-axis
248     // Trapesoid 2x2
249     parTRAP[0] = parSCM0[3];    // dz
250     parTRAP[1] = TMath::ATan2((parSCM0[1]-parSCM0[0])/2.,2.*parSCM0[3])*180./TMath::Pi(); // theta
251     parTRAP[2] = 0.;           // phi
252     // bottom
253     parTRAP[3] = parSCM0[2]/2.; // H1
254     parTRAP[4] = parSCM0[0]/2.; // BL1
255     parTRAP[5] = parTRAP[4];    // TL1
256     parTRAP[6] = 0.0;           // ALP1
257     // top
258     parTRAP[7] = parSCM0[2]/2.; // H2
259     parTRAP[8] = parSCM0[1]/2.; // BL2
260     parTRAP[9] = parTRAP[8];    // TL2
261     parTRAP[10]= 0.0;           // ALP2
262     AliDebug(2,Form(" ** TRAP ** \n"));
263     for(int i=0; i<11; i++) AliDebug(3, Form(" par[%2.2i] %9.4f\n", i, parTRAP[i]));
264     
265     gMC->Gsvolu("SCMX", "TRAP", fIdTmedArr[kIdSC], parTRAP, 11);
266     xpos = +(parSCM0[1]+parSCM0[0])/4.;
267     gMC->Gspos("SCMX", 1, "SCMY", xpos, 0.0, 0.0, 0, "ONLY") ;
268
269     // Using rotation because SCMX should be the same due to Pb tiles
270     xpos = -xpos; 
271     AliMatrix(fIdRotm, 90.0,180., 90.0, 270.0, 0.0,0.0) ;
272     gMC->Gspos("SCMX", 2, "SCMY", xpos, 0.0, 0.0, fIdRotm, "ONLY");
273     // put LED to the SCM0 
274     AliEMCALShishKebabTrd1Module *mod = (AliEMCALShishKebabTrd1Module*)fShishKebabModules->At(0);
275     Double_t tanBetta = mod->GetTanBetta();
276
277     int nr=0; 
278     ypos = 0.0; 
279     double xCenterSCMX =  (parTRAP[4] +  parTRAP[8])/2.;
280     if(!gn.Contains("V1")) {
281       par[1] = parSCM0[2]/2;            // y 
282       par[2] = g->GetECPbRadThick()/2.; // z
283       gMC->Gsvolu("PBTI", "BOX", fIdTmedArr[kIdPB], dummy, 0);
284       zpos = -fSampleWidth*g->GetNECLayers()/2. + g->GetECPbRadThick()/2.;
285       AliDebug(2,Form(" Pb tiles \n"));
286       for(int iz=0; iz<g->GetNECLayers(); iz++){
287         par[0] = (parSCM0[0] + tanBetta*fSampleWidth*iz)/2.;
288         xpos   = par[0] - xCenterSCMX;
289         gMC->Gsposp("PBTI", ++nr, "SCMX", xpos, ypos, zpos, 0, "ONLY", par, 3) ;
290         AliDebug(3,Form(" %i xpos %f zpos %f par[0] %f \n", iz+1, xpos, zpos, par[0]));
291         zpos += fSampleWidth;
292       } 
293       AliDebug(2,Form(" Number of Pb tiles in SCMX %i \n", nr));
294     } else {
295       // Oct 26, 2010
296       // First sheet of paper
297       par[1] = parSCM0[2]/2.;                 // y 
298       par[2] = g->GetTrd1BondPaperThick()/2.; // z
299       par[0] = parSCM0[0]/2.;                 // x 
300       gMC->Gsvolu("PAP1", "BOX", fIdTmedArr[kIdPAPER], par, 3);
301       xpos = par[0] - xCenterSCMX;
302       zpos = -parSCM0[3] + g->GetTrd1BondPaperThick()/2.;
303       gMC->Gspos("PAP1", 1, "SCMX", xpos, ypos, zpos, 0, "ONLY");
304       for(int iz=0; iz<g->GetNECLayers()-1; iz++){
305         nr = iz + 1;
306         Double_t dz = g->GetECScintThick() + g->GetTrd1BondPaperThick() + fSampleWidth*iz;
307         // PB + 2 paper sheets
308         par[2] = g->GetECPbRadThick()/2. + g->GetTrd1BondPaperThick(); // z
309         par[0] = (parSCM0[0] + tanBetta*dz)/2.;
310         TString pa(Form("PA%2.2i",nr));
311         gMC->Gsvolu(pa.Data(), "BOX", fIdTmedArr[kIdPAPER], par, 3);
312         xpos   = par[0] - xCenterSCMX;
313         zpos   = -parSCM0[3] + dz + par[2];
314         gMC->Gspos(pa.Data(), 1, "SCMX", xpos, ypos, zpos, 0, "ONLY") ;
315         // Pb
316         TString pb(Form("PB%2.2i",nr));
317         par[2] = g->GetECPbRadThick()/2.; // z
318         gMC->Gsvolu(pb.Data(), "BOX", fIdTmedArr[kIdPB], par, 3);
319         gMC->Gspos(pb.Data(), 1, pa.Data(), 0.0, 0.0, 0.0, 0, "ONLY") ;
320       } 
321     }
322     
323   } else if(g->GetNPHIdiv()==3 && g->GetNETAdiv()==3) {
324     printf(" before AliEMCALv0::Trd1Tower3X3() : parSCM0");
325     for(int i=0; i<4; i++) printf(" %7.4f ", parSCM0[i]);
326     printf("\n"); 
327     Trd1Tower3X3(parSCM0);
328   } else if(g->GetNPHIdiv()==1 && g->GetNETAdiv()==1) {
329     // no division in SCM0
330     Trd1Tower1X1(parSCM0);
331   } else if(g->GetNPHIdiv()==4 && g->GetNETAdiv()==4) {
332     Trd1Tower4X4();
333   }
334   
335 }
336
337 //______________________________________________________________________
338 void AliEMCALv0::CreateSmod(const char* mother)
339
340   // 18-may-05; mother="XEN1"; 
341   // child="SMOD" from first to 10th, "SM10" (11th and 12th) (TRD1 case)
342   AliEMCALGeometry * g = GetGeometry(); 
343   TString gn(g->GetName()); gn.ToUpper();
344
345   Double_t par[3], xpos=0., ypos=0., zpos=0., rpos=0., dphi=0., phi=0.0, phiRad=0.;
346   Double_t par1C = 0.;
347   //  ===== define Super Module from air - 14x30 module ==== ;
348   AliDebug(2,Form("\n ## Super Module | fSampleWidth %5.3f ## %s \n", fSampleWidth, gn.Data()));
349   par[0] = g->GetShellThickness()/2.;
350   par[1] = g->GetPhiModuleSize()*g->GetNPhi()/2.; 
351   par[2] = g->GetEtaModuleSize()*15.; 
352   fIdRotm=0;
353   int nphism = g->GetNumberOfSuperModules()/2; // 20-may-05
354   if(nphism>0) {
355     dphi = (g->GetArm1PhiMax() - g->GetArm1PhiMin())/nphism;
356     //    if(g->GetKey110DEG()) dphi = (g->GetArm1PhiMax() - g->GetArm1PhiMin())/(nphism-1);
357     rpos = (g->GetEnvelop(0) + g->GetEnvelop(1))/2.;
358     AliDebug(2,Form(" rpos %8.2f : dphi %6.1f degree \n", rpos, dphi));
359   }
360
361   if(gn.Contains("WSUC")) {
362     par[0] = g->GetPhiModuleSize()*g->GetNPhi()/2.; 
363     par[1] = g->GetShellThickness()/2.;
364     par[2] = g->GetEtaModuleSize()*g->GetNZ()/2. + 5; 
365
366     gMC->Gsvolu("SMOD", "BOX", fIdTmedArr[kIdAIR], par, 3);
367
368     AliDebug(2,Form("SMOD in WSUC : tmed %i | dx %7.2f dy %7.2f dz %7.2f (SMOD, BOX)\n", 
369                     fIdTmedArr[kIdAIR], par[0],par[1],par[2]));
370     fSmodPar0 = par[0]; 
371     fSmodPar1 = par[1];
372     fSmodPar2 = par[2];
373     nphism   =  g->GetNumberOfSuperModules();
374   } else {
375     par[2]  = 350./2.; // 11-oct-04 - for 26 division
376     AliDebug(2,Form(" par[0] %7.2f (old) \n",  par[0]));
377     Float_t *parSM = g->GetSuperModulesPars(); 
378     for(int i=0; i<3; i++) par[i] = parSM[i];
379   }
380   gMC->Gsvolu("SMOD", "BOX", fIdTmedArr[kIdAIR], par, 3);
381   AliDebug(2,Form("tmed %i | dx %7.2f dy %7.2f dz %7.2f (SMOD, BOX)\n", 
382                   fIdTmedArr[kIdAIR], par[0],par[1],par[2]));
383   fSmodPar0 = par[0]; 
384   fSmodPar2 = par[2];
385   if(g->GetKey110DEG()) { // 12-oct-05
386     par1C = par[1];
387     par[1] /= 2.;
388     gMC->Gsvolu("SM10", "BOX", fIdTmedArr[kIdAIR], par, 3);
389     AliDebug(2,Form(" Super module with name \"SM10\" was created too par[1] = %f\n", par[1]));
390     par[1] = par1C;
391   }
392   // Steel plate
393   if(g->GetSteelFrontThickness() > 0.0) { // 28-mar-05
394     par[0] = g->GetSteelFrontThickness()/2.;
395     gMC->Gsvolu("STPL", "BOX", fIdTmedArr[kIdSTEEL], par, 3);
396     printf("tmed %i | dx %7.2f dy %7.2f dz %7.2f (STPL) \n", fIdTmedArr[kIdSTEEL], par[0],par[1],par[2]);
397     xpos = -(g->GetShellThickness() - g->GetSteelFrontThickness())/2.;
398     gMC->Gspos("STPL", 1, "SMOD", xpos, 0.0, 0.0, 0, "ONLY") ;
399   }
400
401   int nr=0, nrsmod=0, i0=0;
402
403   // Turn whole super module
404   for(int i=i0; i<nphism; i++) {
405     if(gn.Contains("WSUC")) {
406       xpos = ypos = zpos = 0.0;
407       fIdRotm = 0;
408       gMC->Gspos("SMOD", 1, mother, xpos, ypos, zpos, fIdRotm, "ONLY") ;
409       printf(" fIdRotm %3i phi %6.1f(%5.3f) xpos %7.2f ypos %7.2f zpos %7.2f \n", 
410       fIdRotm, phi, phiRad, xpos, ypos, zpos);
411       nr++;
412     } else { // TRD1 
413       TString smName("SMOD"); // 12-oct-05
414       if(i==5 && g->GetKey110DEG()) {
415         smName = "SM10";
416         nrsmod = nr;
417         nr     = 0;
418       }
419       phi    = g->GetArm1PhiMin() + dphi*(2*i+1)/2.; // phi= 70, 90, 110, 130, 150, 170
420       phiRad = phi*TMath::Pi()/180.;
421
422       AliMatrix(fIdRotm, 90.0, phi, 90.0, 90.0+phi, 0.0, 0.0);
423
424       xpos = rpos * TMath::Cos(phiRad);
425       ypos = rpos * TMath::Sin(phiRad);
426       zpos = fSmodPar2; // 21-sep-04
427       if(i==5 && g->GetKey110DEG()) {
428         xpos += (par1C/2. * TMath::Sin(phiRad)); 
429         ypos -= (par1C/2. * TMath::Cos(phiRad)); 
430       }
431       
432       // 1th module in z-direction;
433       gMC->Gspos(smName.Data(), ++nr, mother, xpos, ypos, zpos, fIdRotm, "ONLY") ;
434       AliDebug(3, Form(" %s : %2i fIdRotm %3i phi %6.1f(%5.3f) xpos %7.2f ypos %7.2f zpos %7.2f : i %i \n", 
435                        smName.Data(), nr, fIdRotm, phi, phiRad, xpos, ypos, zpos, i));
436       // 2th module in z-direction;
437       // turn arround X axis; 0<phi<360
438       double phiy = 90. + phi + 180.;
439       if(phiy>=360.) phiy -= 360.;
440       
441       AliMatrix(fIdRotm, 90.0, phi, 90.0, phiy, 180.0, 0.0);
442       gMC->Gspos(smName.Data(), ++nr, mother, xpos, ypos, -zpos, fIdRotm, "ONLY");
443       AliDebug(3, Form(" %s : %2i fIdRotm %3i phiy %6.1f  xpos %7.2f ypos %7.2f zpos %7.2f \n", 
444                        smName.Data(), nr, fIdRotm, phiy, xpos, ypos, -zpos));
445     }
446   }
447   AliDebug(2,Form(" Number of Super Modules %i \n", nr+nrsmod));
448 }
449
450 //______________________________________________________________________
451 void AliEMCALv0::CreateEmod(const char* mother, const char* child)
452
453   // 17-may-05; mother="SMOD"; child="EMOD"
454   // Oct 26,2010 
455   AliEMCALGeometry * g = GetGeometry(); 
456   TString gn(g->GetName()); gn.ToUpper(); 
457   // Module definition
458   Double_t xpos=0., ypos=0., zpos=0.;
459   //Double_t trd1Angle = g->GetTrd1Angle()*TMath::DegToRad();tanTrd1 = TMath::Tan(trd1Angle/2.);
460
461   if(strcmp(mother,"SMOD")==0) {
462     fParEMOD[0] = g->GetEtaModuleSize()/2.;   // dx1
463     fParEMOD[1] = g->Get2Trd1Dx2()/2.;        // dx2
464     fParEMOD[2] = g->GetPhiModuleSize()/2.;;  // dy
465     fParEMOD[3] = g->GetLongModuleSize()/2.;  // dz
466     gMC->Gsvolu(child, "TRD1", fIdTmedArr[kIdSTEEL], fParEMOD, 4);
467   }
468   
469   int nr=0;
470   fIdRotm=0;
471   // X->Z(0, 0); Y->Y(90, 90); Z->X(90, 0)
472   AliEMCALShishKebabTrd1Module *mod=0; // current module
473
474   for(int iz=0; iz<g->GetNZ(); iz++) {
475     Double_t  angle=90., phiOK=0;
476     mod = (AliEMCALShishKebabTrd1Module*)fShishKebabModules->At(iz);
477     angle = mod->GetThetaInDegree();
478     if(!gn.Contains("WSUC")) { // ALICE 
479       AliMatrix(fIdRotm, 90.-angle,180., 90.0,90.0, angle, 0.);
480       phiOK = mod->GetCenterOfModule().Phi()*180./TMath::Pi(); 
481       //          printf(" %2i | angle | %6.3f - %6.3f = %6.3f(eta %5.3f)\n", 
482       //iz+1, angle, phiOK, angle-phiOK, mod->GetEtaOfCenterOfModule());
483       xpos = mod->GetPosXfromR() + g->GetSteelFrontThickness() - fSmodPar0;
484       zpos = mod->GetPosZ() - fSmodPar2;
485       
486       int iyMax = g->GetNPhi();
487       if(strcmp(mother,"SMOD") && g->GetKey110DEG()) {
488         iyMax /= 2;
489       }
490       for(int iy=0; iy<iyMax; iy++) { // flat in phi
491         ypos = g->GetPhiModuleSize()*(2*iy+1 - iyMax)/2.;
492         gMC->Gspos(child, ++nr, mother, xpos, ypos, zpos, fIdRotm, "ONLY") ;
493         //printf(" %2i xpos %7.2f ypos %7.2f zpos %7.2f fIdRotm %i\n", nr, xpos, ypos, zpos, fIdRotm);
494         AliDebug(3,Form("%3.3i(%2.2i,%2.2i) ", nr,iy+1,iz+1));
495       }
496       //PH          printf("\n");
497     } else { //WSUC
498       if(iz==0) AliMatrix(fIdRotm, 0.,0., 90.,0., 90.,90.); // (x')z; y'(x); z'(y)
499       else      AliMatrix(fIdRotm, 90-angle,270., 90.0,0.0, angle,90.);
500       phiOK = mod->GetCenterOfModule().Phi()*180./TMath::Pi(); 
501       printf(" %2i | angle -phiOK | %6.3f - %6.3f = %6.3f(eta %5.3f)\n", 
502              iz+1, angle, phiOK, angle-phiOK, mod->GetEtaOfCenterOfModule());
503       zpos = mod->GetPosZ()      - fSmodPar2;
504       ypos = mod->GetPosXfromR() - fSmodPar1;
505       printf(" zpos %7.2f ypos %7.2f fIdRotm %i\n xpos ", zpos, xpos, fIdRotm);
506       for(int ix=0; ix<g->GetNPhi(); ix++) { // flat in phi
507         xpos = g->GetPhiModuleSize()*(2*ix+1 - g->GetNPhi())/2.;
508         gMC->Gspos(child, ++nr, mother, xpos, ypos, zpos, fIdRotm, "ONLY") ;
509         printf(" %7.2f ", xpos);
510       }
511       printf("\n");
512     }
513   }
514   AliDebug(2,Form(" Number of modules in Super Module(%s) %i \n", mother, nr));
515 }
516
517 void AliEMCALv0::CreateAlFrontPlate(const char* mother, const char* child)
518 {
519   // Oct 26,2010 : Al front plate : ALFP
520   AliEMCALGeometry * g = GetGeometry(); 
521   TString gn(g->GetName()); gn.ToUpper(); 
522   Double_t trd1Angle = g->GetTrd1Angle()*TMath::DegToRad(), tanTrd1 = TMath::Tan(trd1Angle/2.);
523   Double_t parALFP[5], zposALFP=0.;
524
525   parALFP[0] = g->GetEtaModuleSize()/2. - g->GetLateralSteelStrip();    // dx1
526   parALFP[1] = parALFP[0]               + tanTrd1*g->GetTrd1AlFrontThick(); // dx2
527   parALFP[2] = g->GetPhiModuleSize()/2. - g->GetLateralSteelStrip();    // dy
528   parALFP[3] = g->GetTrd1AlFrontThick()/2.; // dz
529   gMC->Gsvolu(child, "TRD1", fIdTmedArr[kIdAL], parALFP, 4);
530   zposALFP   = -fParEMOD[3] + g->GetTrd1AlFrontThick()/2.;
531   gMC->Gspos (child, 1, mother, 0.0, 0.0, zposALFP, 0, "ONLY");
532 }
533
534 //______________________________________________________________________
535 void AliEMCALv0::Trd1Tower3X3(const double *parSCM0)
536 {
537   // Started Dec 8,2004 by PAI
538   // Fixed Nov 13,2006
539   printf(" AliEMCALv0::Trd1Tower3X3() : parSCM0");
540   for(int i=0; i<4; i++) printf(" %7.4f ", parSCM0[i]);
541   printf("\n"); 
542   // Nov 10, 2006 - different name of SCMX
543   double parTRAP[11], *dummy=0;
544   AliEMCALGeometry * g = GetGeometry(); 
545   TString gn(g->GetName()), scmx; 
546   gn.ToUpper(); 
547  // Division to tile size 
548   AliDebug(2,Form("Trd1Tower3X3() : Divide SCM0 on y-axis %i", g->GetNETAdiv()));
549   gMC->Gsdvn("SCMY","SCM0", g->GetNETAdiv(), 2); // y-axis
550   double dx1=parSCM0[0], dx2=parSCM0[1], dy=parSCM0[2], dz=parSCM0[3];
551   double ndiv=3., xpos=0.0;
552   // should be defined once
553   gMC->Gsvolu("PBTI", "BOX", fIdTmedArr[kIdPB], dummy, 0);
554   for(int ix=1; ix<=3; ix++) { // 3X3
555     scmx = "SCX"; // Nov 10,2006 
556     // ix=1
557     parTRAP[0] = dz;
558     double xCentBot = 2.*dx1/3.;
559     double xCentTop = 2.*(dx2/4. + dx1/12.);
560     parTRAP[1] = TMath::ATan2((xCentTop-xCentBot),2.*dz)*TMath::RadToDeg(); // theta
561     parTRAP[2] = 0.;           // phi
562     // bottom
563     parTRAP[3] = dy/ndiv;      // H1
564     parTRAP[4] = dx1/ndiv;     // BL1
565     parTRAP[5] = parTRAP[4];   // TL1
566     parTRAP[6] = 0.0;          // ALP1
567     // top
568     parTRAP[7] = dy/ndiv;      // H2
569     parTRAP[8] = dx2/2 - dx1/6.;// BL2
570     parTRAP[9] = parTRAP[8];   // TL2
571     parTRAP[10]= 0.0;          // ALP2
572     xpos = (xCentBot+xCentTop)/2.;
573
574     if      (ix==3) {
575       parTRAP[1] = -parTRAP[1];
576       xpos = -xpos;
577     } else if(ix==2) { // central part is box but we treat as trapesoid due to numbering
578       parTRAP[1] = 0.;
579       parTRAP[8] = dx1/ndiv;     // BL2
580       parTRAP[9] = parTRAP[8];   // TL2
581       xpos = 0.0;
582     }
583     AliDebug(2,Form(" ** TRAP ** xpos %9.3f\n", xpos));
584     for(int i=0; i<11; i++) AliDebug(2,Form(" par[%2.2i] %9.4f\n", i, parTRAP[i]));
585
586     scmx += ix;
587     gMC->Gsvolu(scmx.Data(), "TRAP", fIdTmedArr[kIdSC], parTRAP, 11);
588     gMC->Gspos(scmx.Data(), 1, "SCMY", xpos, 0.0, 0.0, 0, "ONLY") ;
589
590     PbInTrap(parTRAP, scmx);
591   }
592   AliDebug(2,"Trd1Tower3X3 - Ver. 1.0 : was tested.");
593 }
594
595 // 8-dec-04 by PAI
596 //______________________________________________________________________
597 void AliEMCALv0::PbInTrap(const double parTRAP[11], TString n)
598 {
599  // see for example CreateShishKebabGeometry(); just for case TRD1
600   static int nr=0;
601   AliDebug(2,Form(" Pb tiles : nrstart %i\n", nr));
602   AliEMCALGeometry * g = GetGeometry(); 
603
604   double par[3];
605   double xpos = 0.0, ypos = 0.0;
606   double zpos = -fSampleWidth*g->GetNECLayers()/2. + g->GetECPbRadThick()/2.;
607
608   double coef = (parTRAP[8] -  parTRAP[4]) / (2.*parTRAP[0]);
609   double xCenterSCMX =  (parTRAP[4] +  parTRAP[8])/2.; // ??
610   //  double tan = TMath::Tan(parTRAP[1]*TMath::DegToRad());
611
612   par[1] = parTRAP[3];              // y 
613   par[2] = g->GetECPbRadThick()/2.; // z
614   for(int iz=0; iz<g->GetNECLayers(); iz++){
615     par[0] = parTRAP[4] + coef*fSampleWidth*iz;
616     xpos   = par[0] - xCenterSCMX;
617     if(parTRAP[1] < 0.) xpos = -xpos;
618     gMC->Gsposp("PBTI", ++nr, n.Data(), xpos, ypos, zpos, 0, "ONLY", par, 3) ;
619     AliDebug(2,Form(" %i xpos %9.3f zpos %9.3f par[0] %9.3f |", iz+1, xpos, zpos, par[0]));
620     zpos += fSampleWidth;
621     if(iz%2>0) printf("\n");
622   } 
623   AliDebug(2,Form(" Number of Pb tiles in SCMX %i coef %9.7f \n", nr, coef));
624   AliDebug(2,Form(" par[1] %9.3f  par[2] %9.3f ypos %9.3f \n", par[1], par[2], ypos)); 
625   AliDebug(2,Form(" PbInTrap Ver. 1.0 : was tested."));
626 }
627
628 // 8-dec-04 by PAI
629 //______________________________________________________________________
630 void AliEMCALv0::Trd1Tower4X4() const
631 {
632  // Not ready yet
633 }
634
635 //______________________________________________________________________
636 void AliEMCALv0::Trd1Tower1X1(double *parSCM0)
637 {
638   // Started Nov 22,2006 by PAI
639   AliDebug(1," AliEMCALv0::Trd1Tower1X1() : parSCM0");
640   for(int i=0; i<4; i++) printf(" %7.4f ", parSCM0[i]);
641   printf("\n"); 
642
643   // No division - keeping the same volume logic 
644   // and as consequence the same abs is scheme
645   AliDebug(2,"Trd1Tower1X1() : Create SCMX(SCMY) as SCM0");
646
647   gMC->Gsvolu("SCMY", "TRD1", fIdTmedArr[kIdAIR], parSCM0, 4);
648   gMC->Gspos("SCMY", 1, "SCM0", 0.0, 0.0, 0.0, 0, "ONLY");
649   gMC->Gsvolu("SCMX", "TRD1", fIdTmedArr[kIdSC], parSCM0, 4);
650   gMC->Gspos("SCMX", 1, "SCMY", 0.0, 0.0, 0.0, 0, "ONLY");
651
652   // should be defined once
653   double *dummy=0;
654   gMC->Gsvolu("PBTI", "BOX", fIdTmedArr[kIdPB], dummy, 0);
655
656   PbInTrd1(parSCM0, "SCMX");
657
658   AliDebug(1,"Trd1Tower1X1() : Ver. 0.1 : was tested.");
659 }
660
661 //______________________________________________________________________
662 void AliEMCALv0::PbInTrd1(const double *parTrd1, TString n)
663 {
664  // see PbInTrap(const double parTrd1[11], TString n)
665   static int nr=0, ndeb=2;
666   AliDebug(ndeb,Form(" Pb tiles : nrstart %i\n", nr));
667   AliEMCALGeometry * g = GetGeometry(); 
668
669   double par[3];
670   double xpos = 0.0, ypos = 0.0;
671   double zpos = -fSampleWidth*g->GetNECLayers()/2. + g->GetECPbRadThick()/2.;
672   double coef = (parTrd1[1] -  parTrd1[0]) / (2.*parTrd1[3]);
673
674   par[1] = parTrd1[2];              // y 
675   par[2] = g->GetECPbRadThick()/2.; // z
676
677   for(int iz=0; iz<g->GetNECLayers(); iz++){
678     par[0] = parTrd1[0] + coef*fSampleWidth*iz;
679     gMC->Gsposp("PBTI", ++nr, n.Data(), xpos, ypos, zpos, 0, "ONLY", par, 3) ;
680     AliDebug(2,Form(" %i xpos %9.3f zpos %9.3f par[0] %9.3f |", iz+1, xpos, zpos, par[0]));
681     zpos += fSampleWidth;
682     if(iz%2>0) printf("\n");
683   } 
684   AliDebug(ndeb,Form(" Number of Pb tiles in SCMX %i coef %9.7f ", nr, coef));
685   AliDebug(ndeb,Form(" PbInTrd1 Ver. 0.1 : was tested."));
686 }
687
688 // 3-feb-05
689 //______________________________________________________________________
690 void AliEMCALv0::Scm0InTrd2(const AliEMCALGeometry * g, const Double_t emodPar[5], Double_t parSCM0[5])
691 {
692   // Passive material inside the detector
693   double wallThickness = g->GetPhiModuleSize()/2. -  g->GetPhiTileSize(); //Need check
694   AliDebug(2,Form(" wall thickness %7.5f \n", wallThickness));
695   for(int i=0; i<4; i++) { // on pictures sometimes I can not see 0 -> be carefull!!
696     parSCM0[i] = emodPar[i] - wallThickness;
697     AliDebug(2,Form(" %i parSCMO %7.3f emodPar %7.3f : dif %7.3f \n", 
698                     i, parSCM0[i],emodPar[i], parSCM0[i]-emodPar[i]));
699   }
700   parSCM0[4] = emodPar[4];
701   gMC->Gsvolu("SCM0", "TRD2", fIdTmedArr[kIdSC], parSCM0, 5); // kIdAIR -> kIdSC
702   gMC->Gspos("SCM0", 1, "EMOD", 0., 0., 0., 0, "ONLY") ;
703   // Division 
704   if(g->GetNPHIdiv()==2 && g->GetNETAdiv()==2) {
705     Division2X2InScm0(g, parSCM0);
706   } else {
707     Info("Scm0InTrd2"," no division SCM0 in this geometry |%s|\n", g->GetName());
708     assert(0);
709   }
710 }
711
712 //______________________________________________________________________
713 void AliEMCALv0::Division2X2InScm0(const AliEMCALGeometry * g, const Double_t parSCM0[5])
714 {
715   // Division 2X2
716   Double_t parTRAP[11], xpos=0.,ypos=0., dx1=0.0,dx2=0.,dy1=0.0,dy2=0.,dz=0.
717   ,dr1=0.0,dr2=0.;
718   fIdRotm=0;
719
720   Info("Division2X2InScm0","Divide SCM0 on y-axis %i\n", g->GetNETAdiv());
721   TString n("SCMX"), overLapFlagSCMY("ONLY"), overLapFlagSCMX("ONLY");
722   n = "SCM0"; // for testing - 14-mar-05
723   if(n=="SCM0"){
724     PbInTrapForTrd2(parSCM0, n);
725     // overLapFlagSCMY=overLapFlagSCMX="MANY"; // do not work
726     return;
727   }
728
729   dy1 = parSCM0[2] , dy2 = parSCM0[3], dz = parSCM0[4];
730
731   parTRAP[0] = parSCM0[4];    // dz
732   parTRAP[1] = TMath::ATan2((dy2-dy1)/2.,2.*dz)*TMath::RadToDeg();
733   parTRAP[2] = 90.;           // phi
734   // bottom
735   parTRAP[3] = parSCM0[2]/2.; // H1
736   parTRAP[4] = parSCM0[0];    // BL1
737   parTRAP[5] = parTRAP[4];    // TL1
738   parTRAP[6] = 0.0;           // ALP1
739   // top
740   parTRAP[7] = parSCM0[3]/2.; // H2
741   parTRAP[8] = parSCM0[1];    // BL2
742   parTRAP[9] = parTRAP[8];    // TL2
743   parTRAP[10]= 0.0;           // ALP2
744   AliDebug(2,Form(" ** SCMY ** \n"));
745            for(int i=0; i<11; i++) AliDebug(2,Form(" par[%2.2i] %9.4f\n", i, parTRAP[i]));
746
747   fIdRotm=0;
748   gMC->Gsvolu("SCMY", "TRAP", fIdTmedArr[kIdSC], parTRAP, 11); // kIdAIR -> kIdSC
749   ypos = +(parTRAP[3]+parTRAP[7])/2.; //
750   AliDebug(2,Form(" Y shift SCMY inside SCM0 : %7.3f : opt %s\n", ypos, overLapFlagSCMY.Data())); 
751   gMC->Gspos("SCMY", 1, "SCM0", 0.0, ypos, 0.0, fIdRotm,  overLapFlagSCMY.Data()) ;
752   // Rotation SCMY around z-axis on 180 degree; x'=-x; y'=-y and z=z
753   AliMatrix(fIdRotm, 90.0,180., 90.0, 270.0, 0.0,0.0) ;
754   // We may have problem with numeration due to rotation - 4-feb-05
755   gMC->Gspos("SCMY", 2, "SCM0", 0.0, -ypos, 0.0, fIdRotm,  overLapFlagSCMY.Data()); 
756
757   Info("Division2X2InScm0","Divide SCMY on x-axis %i\n", g->GetNPHIdiv());
758   dx1 = parSCM0[0]; 
759   dx2 = parSCM0[1]; 
760   dr1=TMath::Sqrt(dx1*dx1+dy1*dy1);
761   dr2=TMath::Sqrt(dx2*dx2+dy2*dy2);
762
763   parTRAP[0] = parSCM0[4];    // dz
764   parTRAP[1] = TMath::ATan2((dr2-dr1)/2.,2.*dz)*TMath::RadToDeg(); // 
765   parTRAP[2] = 45.;           // phi
766   // bottom
767   parTRAP[3] = parSCM0[2]/2.; // H1
768   parTRAP[4] = parSCM0[0]/2.; // BL1
769   parTRAP[5] = parTRAP[4];    // TL1
770   parTRAP[6] = 0.0;           // ALP1
771   // top
772   parTRAP[7] = parSCM0[3]/2.; // H2
773   parTRAP[8] = parSCM0[1]/2;  // BL2
774   parTRAP[9] = parTRAP[8];    // TL2
775   parTRAP[10]= 0.0;           // ALP2
776   AliDebug(2,Form(" ** SCMX ** \n"));
777   for(int i=0; i<11; i++) AliDebug(2,Form(" par[%2.2i] %9.4f\n", i, parTRAP[i]));
778
779   fIdRotm=0;
780   gMC->Gsvolu("SCMX", "TRAP", fIdTmedArr[kIdSC], parTRAP, 11);
781   xpos = (parTRAP[4]+parTRAP[8])/2.;
782   AliDebug(2,Form(" X shift SCMX inside SCMX : %7.3f : opt %s\n", xpos, overLapFlagSCMX.Data())); 
783   gMC->Gspos("SCMX", 1, "SCMY", xpos, 0.0, 0.0, fIdRotm,  overLapFlagSCMX.Data()) ;
784   //  AliMatrix(fIdRotm, 90.0,270., 90.0, 0.0, 0.0,0.0); // x'=-y; y'=x; z'=z
785   AliMatrix(fIdRotm, 90.0,90., 90.0, -180.0, 0.0,0.0);     // x'=y;  y'=-x; z'=z
786   gMC->Gspos("SCMX", 2, "SCMY", -xpos, 0.0, 0.0, fIdRotm,  overLapFlagSCMX.Data()) ;
787   // PB:
788   if(n=="SCMX" && overLapFlagSCMY == "ONLY") {
789     PbInTrapForTrd2(parTRAP, n);
790   }
791
792
793 // 4-feb-05 by PAI
794 //______________________________________________________________________
795 void AliEMCALv0::PbInTrapForTrd2(const double *parTRAP, TString name)
796 {
797  // TRD2 cases
798   Double_t *dummy=0;
799   TString pbShape("BOX"), pbtiChonly("ONLY");
800   if(name=="SCM0") {
801     pbShape    = "TRD2";
802     //    pbtiChonly = "MANY";
803   }
804   gMC->Gsvolu("PBTI", pbShape.Data(), fIdTmedArr[kIdPB], dummy, 0);
805
806   int nr=0;
807   Info("PbInTrapForTrd2"," Pb tiles inside %s: shape %s :pbtiChonly %s\n nrstart %i\n", 
808   name.Data(), pbShape.Data(), pbtiChonly.Data(), nr);
809   AliEMCALGeometry * g = GetGeometry(); 
810
811   double par[5], parPB[5], parSC[5];
812   double xpos = 0.0, ypos = 0.0;
813   double zpos = -fSampleWidth*g->GetNECLayers()/2. + g->GetECPbRadThick()/2.;
814   if(name == "SCMX") { // common trapezoid - 11 parameters
815     double coef = (parTRAP[8] -  parTRAP[4]) / (2.*parTRAP[0]);
816     double xCenterSCMX =  (parTRAP[4] +  parTRAP[8])/2.; // the same for y
817     AliDebug(2,Form(" xCenterSCMX %8.5f : coef %8.7f \n", xCenterSCMX, coef));
818
819     par[2] = g->GetECPbRadThick()/2.; // z
820     for(int iz=0; iz<g->GetNECLayers(); iz++){
821       par[0] = parTRAP[4] + coef*fSampleWidth*iz;
822       par[1] = par[0];
823       xpos   = ypos = par[0] - xCenterSCMX;
824     //if(parTRAP[1] < 0.) xpos = -xpos;
825       gMC->Gsposp("PBTI", ++nr, name.Data(), xpos, ypos, zpos, 0, "ONLY", par, 3) ;
826       AliDebug(2,Form(" %2.2i xpos %8.5f zpos %6.3f par[0,1] %6.3f |", iz+1, xpos, zpos, par[0]));
827       if(iz%2>0) AliDebug(2,Form("\n"));
828       zpos += fSampleWidth;
829     } 
830     AliDebug(2,Form(" Number of Pb tiles in SCMX %i coef %9.7f \n", nr, coef));
831     AliDebug(2,Form(" par[1] %9.5f  par[2] %9.5f ypos %9.5f \n", par[1], par[2], ypos)); 
832   } else if(name == "SCM0") { // 1-mar-05 ; TRD2 - 5 parameters
833     AliDebug(2,Form(" SCM0 par = "));
834     for(int i=0; i<5; i++) AliDebug(2,Form(" %9.5f ", parTRAP[i]));
835     AliDebug(2,Form("\n zpos %f \n",zpos));
836
837     double tanx = (parTRAP[1] -  parTRAP[0]) / (2.*parTRAP[4]); //  tanx =  tany now
838     double tany = (parTRAP[3] -  parTRAP[2]) / (2.*parTRAP[4]), ztmp=0.;
839     parPB[4] = g->GetECPbRadThick()/2.;
840     parSC[2] = g->GetECScintThick()/2.;
841     for(int iz=0; iz<g->GetNECLayers(); iz++){
842       ztmp     = fSampleWidth*double(iz);
843       parPB[0] = parTRAP[0] + tanx*ztmp;
844       parPB[1] = parPB[0]   + tanx*g->GetECPbRadThick();
845       parPB[2] = parTRAP[2] + tany*ztmp;
846       parPB[3] = parPB[2]   + tany*g->GetECPbRadThick();
847       gMC->Gsposp("PBTI", ++nr, name.Data(), xpos, ypos, zpos, 0, pbtiChonly.Data(), parPB, 5) ;
848       AliDebug(2,Form("\n PBTI %2i | zpos %6.3f | par = ", nr, zpos));
849       /*
850       for(int i=0; i<5; i++) printf(" %9.5f ", parPB[i]);
851       // individual SC tile
852       parSC[0] = parPB[0];
853       parSC[1] = parPB[1];
854       gMC->Gsposp("SCTI", nr, name.Data(), xpos, ypos, zpos+g->GetECScintThick(), 
855       0, pbtiChonly.Data(), parSC, 3) ;
856       printf("\n SCTI     zpos %6.3f | par = ", zpos+g->GetECScintThick());
857       for(int i=0; i<3; i++) printf(" %9.5f ", parPB[i]);
858       */
859       zpos  += fSampleWidth;
860     }
861     AliDebug(2,Form("\n"));
862   }
863   Info("PbInTrapForTrd2", "Ver. 0.03 : was tested.");
864 }
865
866 // 15-mar-05
867 //______________________________________________________________________
868 void AliEMCALv0::PbmoInTrd2(const AliEMCALGeometry * g, const Double_t emodPar[5], Double_t parPBMO[5])
869 {
870   // Pb inside Trd2
871   Info("PbmoInTrd2"," started : geometry %s ", g->GetName());
872   double wallThickness = g->GetPhiModuleSize()/2. -  g->GetPhiTileSize();
873   AliDebug(2,Form(" wall thickness %7.5f \n", wallThickness));
874   for(int i=0; i<4; i++) {
875     parPBMO[i] = emodPar[i] - wallThickness;
876     AliDebug(2,Form(" %i parPBMO %7.3f emodPar %7.3f : dif %7.3f \n", 
877                     i, parPBMO[i],emodPar[i], parPBMO[i]-emodPar[i]));
878   }
879   parPBMO[4] = emodPar[4];
880   gMC->Gsvolu("PBMO", "TRD2", fIdTmedArr[kIdPB], parPBMO, 5);
881   gMC->Gspos("PBMO", 1, "EMOD", 0., 0., 0., 0, "ONLY") ;
882   // Division 
883   if(g->GetNPHIdiv()==2 && g->GetNETAdiv()==2) {
884     Division2X2InPbmo(g, parPBMO);
885     AliDebug(2,Form(" PBMO, division 2X2 | geometry |%s|\n", g->GetName()));
886   } else {
887     AliDebug(2,Form(" no division PBMO in this geometry |%s|\n", g->GetName()));
888     assert(0);
889   }
890 }
891
892 //______________________________________________________________________
893 void AliEMCALv0::Division2X2InPbmo(const AliEMCALGeometry * g, const Double_t parPBMO[5]) 
894 {
895   // Division 2X2
896   Info("Division2X2InPbmo"," started : geometry %s ", g->GetName());
897   //Double_t *dummy=0;
898   //  gMC->Gsvolu("SCTI", "BOX", fIdTmedArr[kIdSC], dummy, 0);
899
900   double parSC[3];
901   double xpos = 0.0, ypos = 0.0, zpos = 0.0, ztmp=0;;
902   double tanx = (parPBMO[1] -  parPBMO[0]) / (2.*parPBMO[4]); //  tanx =  tany now
903   double tany = (parPBMO[3] -  parPBMO[2]) / (2.*parPBMO[4]);
904   const Int_t buffersize = 10;
905   char name[buffersize], named[buffersize], named2[buffersize];
906
907   AliDebug(2,Form(" PBMO par = "));
908   for(int i=0; i<5; i++) AliDebug(2,Form(" %9.5f ", parPBMO[i]));
909   AliDebug(2,Form("\n"));
910
911   parSC[2] = g->GetECScintThick()/2.;
912   zpos = -fSampleWidth*g->GetNECLayers()/2. + g->GetECPbRadThick() + g->GetECScintThick()/2.;
913   AliDebug(2,Form(" parSC[2] %9.5f \n", parSC[2]));
914   for(int iz=0; iz<g->GetNECLayers(); iz++){
915     ztmp     = g->GetECPbRadThick() + fSampleWidth*double(iz); // Z for previous PB
916     parSC[0] =  parPBMO[0] + tanx*ztmp;
917     parSC[1] =  parPBMO[2] + tany*ztmp;
918
919     snprintf(name,buffersize,"SC%2.2i", iz+1);
920     gMC->Gsvolu(name, "BOX", fIdTmedArr[kIdSC], parSC, 3);
921     gMC->Gspos(name, 1, "PBMO", xpos, ypos, zpos, 0, "ONLY") ;
922     AliDebug(2,Form("%s | zpos %6.3f | parSC[0,1]=(%7.5f,%7.5f) -> ", 
923                     name, zpos, parSC[0], parSC[1]));
924     
925     snprintf(named,buffersize,"SY%2.2i", iz+1);
926     printf(" %s -> ", named);
927     gMC->Gsdvn(named,name, 2, 2);
928
929     snprintf(named2,buffersize,"SX%2.2i", iz+1);
930     printf(" %s \n", named2);
931     gMC->Gsdvn(named2,named, 2, 1);
932
933     zpos    += fSampleWidth;
934   }
935 }
936
937 //______________________________________________________________________
938 AliEMCALShishKebabTrd1Module* AliEMCALv0::GetShishKebabModule(Int_t neta)
939
940   // 28-oct-05
941   AliEMCALShishKebabTrd1Module* trd1=0;
942   if(fShishKebabModules && neta>=0 && neta<fShishKebabModules->GetSize()) {
943     trd1 = (AliEMCALShishKebabTrd1Module*)fShishKebabModules->At(neta);
944   }
945   return trd1;
946 }
947
948 //_____________________________________________________________________________
949 void AliEMCALv0::AddAlignableVolumes() const
950 {
951   //Add volumes which are alignable (?)
952   TString ntmp(GetTitle()); // name of EMCAL geometry
953
954   if(ntmp.Contains("WSUC")) {
955     AddAlignableVolumesInWSUC();  // WSUC case
956   } else {
957     AddAlignableVolumesInALICE(); // ALICE case
958   }
959 }
960
961 //______________________________________________________________________
962 void AliEMCALv0::AddAlignableVolumesInALICE() const
963 {
964   //
965   // Create entries for alignable volumes associating the symbolic volume
966   // name with the corresponding volume path. Needs to be synchronized with
967   // eventual changes in the geometry.
968   //
969
970   Float_t * pars = GetGeometry()->GetSuperModulesPars();
971   double rpos = (GetGeometry()->GetEnvelop(0) + GetGeometry()->GetEnvelop(1))/2.;
972   double phi, phiRad, xpos, ypos, zpos;
973
974   AliGeomManager::ELayerID idEMCAL = AliGeomManager::kEMCAL;
975   Int_t modUID, modnum = 0;
976   TString volpath, symname;
977
978   Int_t nSMod = GetGeometry()->GetNumberOfSuperModules(); 
979   for (Int_t smodnum=0; smodnum < nSMod; smodnum++) {
980     modUID = AliGeomManager::LayerToVolUID(idEMCAL,modnum++);
981     volpath = "ALIC_1/XEN1_1/SMOD_";
982     volpath += (smodnum+1);
983     symname = "EMCAL/FullSupermodule";
984     symname += (smodnum+1);
985
986     if(GetGeometry()->GetKey110DEG() && smodnum>=10) {
987       volpath = "ALIC_1/XEN1_1/SM10_";
988       volpath += (smodnum-10+1);
989       symname = "EMCAL/HalfSupermodule";    
990       symname += (smodnum-10+1);
991     }
992
993     if(!gGeoManager->SetAlignableEntry(symname.Data(),volpath.Data(),modUID))
994       AliFatal("AliEMCALv0::Unable to set alignable entry!!");
995
996     // Creates the Tracking to Local transformation matrix for EMCAL
997     // modules                         
998     TGeoPNEntry *alignableEntry = gGeoManager->GetAlignableEntryByUID(modUID) ;
999
1000     phiRad = GetGeometry()->GetPhiCenterOfSM(smodnum);  //comes in radians, not degrees
1001     phi = phiRad*180./TMath::Pi();             //need degrees for rot. matrix
1002     xpos = rpos * TMath::Cos(phiRad);
1003     ypos = rpos * TMath::Sin(phiRad);
1004     zpos = pars[2];
1005     if(GetGeometry()->GetKey110DEG() && smodnum >= 10) {
1006       xpos += (pars[1]/2. * TMath::Sin(phiRad));
1007       ypos -= (pars[1]/2. * TMath::Cos(phiRad));
1008     }
1009
1010     TGeoHMatrix *matTtoL;
1011     TGeoHMatrix *globMatrix = alignableEntry->GetGlobalOrig();
1012
1013     if(smodnum%2 == 0) {
1014       // pozitive z                                                        
1015       TGeoTranslation geoTran0(xpos,ypos, zpos);                        
1016       TGeoRotation geoRot0("geoRot0", 90.0, phi, 90.0, 90.0+phi, 0.0, 0.0);
1017       TGeoCombiTrans mat0(geoTran0, geoRot0);
1018       matTtoL = new TGeoHMatrix(mat0);
1019
1020       matTtoL->MultiplyLeft(&(globMatrix->Inverse()));
1021       alignableEntry->SetMatrix(matTtoL);
1022
1023     } else {
1024       // negative z                                                                                 
1025       double phiy = 90. + phi + 180.;
1026       if(phiy>=360.) phiy -= 360.;
1027       TGeoTranslation geoTran1(xpos,ypos,-zpos);
1028       TGeoRotation geoRot1("geoRot1", 90.0, phi, 90.0, phiy, 180.0, 0.0);
1029       TGeoCombiTrans mat1(geoTran1, geoRot1);
1030       matTtoL = new TGeoHMatrix(mat1);
1031
1032       matTtoL->MultiplyLeft(&(globMatrix->Inverse()));
1033       alignableEntry->SetMatrix(matTtoL);
1034
1035     }
1036
1037   }
1038
1039 }
1040
1041 //______________________________________________________________________
1042 void AliEMCALv0::AddAlignableVolumesInWSUC() const
1043 {
1044   //
1045   // Create entries for alignable volumes associating the symbolic volume
1046   // name with the corresponding volume path. Needs to be synchronized with
1047   // eventual changes in the geometry.
1048   //
1049
1050   TString vpstr1 = "WSUC_1/XEN1_1/SMOD_";
1051   TString snstr1 = "EMCAL/CosmicTestSupermodule";
1052   TString volpath, symname;
1053
1054   // #SM is just one 
1055   for (Int_t smodnum=0; smodnum < 1; smodnum++) {
1056     symname = snstr1;
1057     symname += (smodnum+1);
1058     volpath = vpstr1;
1059     volpath += (smodnum+1);
1060     if(!gGeoManager->SetAlignableEntry(symname.Data(),volpath.Data()))
1061       AliFatal("Unable to set alignable entry!!");
1062   }
1063 }