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