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