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