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