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