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