]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALv0.cxx
1f9131464553f9827f05b1aa731ca6c3f79ee173
[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     //add some padding for mother volume
318       envelopA[5] = geom->GetEnvelop(0) ;                          // rmin at z1
319       envelopA[6] = geom->GetEnvelop(1) ;                          // rmax at z1
320       envelopA[7] = geom->ZFromEtaR(geom->GetEnvelop(1),
321                                   geom->GetArm1EtaMax());        // z coordinate 2
322       envelopA[8] = envelopA[5] ;                                  // radii are the same.
323       envelopA[9] = envelopA[6] ;                                  // radii are the same.
324
325       if(gn.Contains("SHISH")) envelopA[2] = geom->GetNPhiSuperModule();
326
327       gMC->Gsvolu("XEN1", "PGON", fIdTmedArr[kIdAIR], envelopA, 10) ;   // Polygone filled with air 
328       fEnvelop1.Set(10, envelopA);
329       if (gDebug==2) {
330         printf("CreateGeometry: XEN1 = %f, %f\n", envelopA[5], envelopA[6]); 
331         printf("CreateGeometry: XU0 = %f, %f\n", envelopA[5], envelopA[6]); 
332       }
333     // Position the EMCAL Mother Volume (XEN1) in Alice (ALIC)  
334       gMC->Gspos(geom->GetNameOfEMCALEnvelope(), 1, "ALIC", 0.0, 0.0, 0.0, fIdRotm, "ONLY") ;
335     }
336
337     if(gn.Contains("SHISH")){
338       // COMPACT, TWIST, TRD2 or TRD1
339       AliInfo(Form("Shish-Kebab geometry : %s", GetTitle())); 
340       CreateShishKebabGeometry();
341     }
342 }
343
344 //______________________________________________________________________
345 void AliEMCALv0::Init(void)
346 {
347     // Just prints an information message
348   
349   if(AliLog::GetGlobalDebugLevel()>0) { 
350     TString message("\n") ; 
351     message += "*****************************************\n" ;
352     
353     // Here the EMCAL initialisation code (if any!)
354     
355     AliEMCALGeometry * geom = GetGeometry() ; 
356     
357     if (geom!=0) {   
358       message += "AliEMCAL " ; 
359       message += Version() ; 
360       message += "EMCAL geometry initialized for " ; 
361       message += geom->GetName()  ;
362     }
363     else {
364       message += "AliEMCAL " ; 
365       message += Version() ;  
366       message += "EMCAL geometry initialization failed !" ; 
367     }
368     message += "\n*****************************************" ;
369     printf(message.Data() ) ; 
370   }
371 }
372
373 // 24-aug-04 by PAI
374 void AliEMCALv0::CreateShishKebabGeometry()
375 {  
376   // TWIST, TRD1 and TRD2 
377   AliEMCALGeometry * g = GetGeometry(); 
378   TString gn(g->GetName()); gn.ToUpper(); 
379   // see AliModule::fFIdTmedArr
380   //  fIdTmedArr = fIdtmed->GetArray() - 1599 ; // see AliEMCAL::::CreateMaterials()
381   //  int kIdAIR=1599, kIdPB = 1600, kIdSC = 1601, kIdSTEEL = 1603;
382   //  idAL = 1602;
383   Double_t par[10], xpos=0., ypos=0., zpos=0.;
384
385   CreateSmod(g->GetNameOfEMCALEnvelope());
386
387   CreateEmod("SMOD","EMOD"); // 18-may-05
388
389   if(gn.Contains("110DEG")) CreateEmod("SM10","EMOD"); // 12-oct-05
390
391   // Sensitive SC  (2x2 tiles)
392   double parSCM0[5], *dummy = 0, parTRAP[11];
393   Double_t trd1Angle = g->GetTrd1Angle()*TMath::DegToRad(), tanTmp = TMath::Tan(trd1Angle/2.);
394    if(!gn.Contains("TRD")) { // standard module
395     par[0] = (g->GetECPbRadThick()+g->GetECScintThick())*g->GetNECLayers()/2.;
396     par[1] = par[2] = g->GetPhiTileSize();   // Symetric case
397     gMC->Gsvolu("SCM0", "BOX", fIdTmedArr[kIdSC], par, 3); // 2x2 tiles
398     gMC->Gspos("SCM0", 1, "EMOD", 0., 0., 0., 0, "ONLY") ;
399     // Division to tile size
400     gMC->Gsdvn("SCM1","SCM0", g->GetNPHIdiv(), 2); // y-axis
401     gMC->Gsdvn("SCM2","SCM1", g->GetNETAdiv(), 3); // z-axis
402   // put LED to the SCM2 
403     par[0] = g->GetECPbRadThick()/2.;
404     par[1] = par[2] = g->GetPhiTileSize()/2.; // Symetric case
405     gMC->Gsvolu("PBTI", "BOX", fIdTmedArr[kIdPB], par, 3);
406
407     printf(" Pb tiles \n");
408     int nr=0;
409     ypos = zpos = 0.0;
410     xpos = -fSampleWidth*g->GetNECLayers()/2. + g->GetECPbRadThick()/2.;
411     for(int ix=0; ix<g->GetNECLayers(); ix++){
412       gMC->Gspos("PBTI", ++nr, "SCM2", xpos, ypos, zpos, 0, "ONLY") ;
413     //    printf(" %i xpos %f \n", ix+1, xpos);
414       xpos += fSampleWidth;
415     } 
416     printf(" Number of Pb tiles in SCM2 %i \n", nr);
417   } else if(gn.Contains("TRD1")) { // TRD1 - 30-sep-04
418     if(gn.Contains("MAY05")){
419       Double_t dzTmp = g->GetFrontSteelStrip()+g->GetPassiveScintThick();
420       parSCM0[0] = fParEMOD[0] + tanTmp*dzTmp; // dx1
421       parSCM0[1] = fParEMOD[1];                // dx2
422       parSCM0[2] = fParEMOD[2];                // dy
423       for(int i=0; i<3; i++) parSCM0[i] -= g->GetLateralSteelStrip();
424       parSCM0[3] = fParEMOD[3] - dzTmp/2.; // dz
425
426       gMC->Gsvolu("SCM0", "TRD1", fIdTmedArr[kIdAIR], parSCM0, 4);
427       gMC->Gspos("SCM0", 1, "EMOD", 0., 0., dzTmp/2., 0, "ONLY") ;
428     } else { // before MAY 2005
429       double wallThickness = g->GetPhiModuleSize()/2. -  g->GetPhiTileSize(); // Need check
430       for(int i=0; i<3; i++) parSCM0[i] = fParEMOD[i] - wallThickness;
431       parSCM0[3] = fParEMOD[3];
432       gMC->Gsvolu("SCM0", "TRD1", fIdTmedArr[kIdAIR], parSCM0, 4);
433       gMC->Gspos("SCM0", 1, "EMOD", 0., 0., 0., 0, "ONLY") ;
434     }
435
436     if(g->GetNPHIdiv()==2 && g->GetNETAdiv()==2) {
437     // Division to tile size - 1-oct-04
438       AliDebug(2,Form(" Divide SCM0 on y-axis %i\n", g->GetNETAdiv()));
439       gMC->Gsdvn("SCMY","SCM0", g->GetNETAdiv(), 2); // y-axis
440     // Trapesoid 2x2
441       parTRAP[0] = parSCM0[3];    // dz
442       parTRAP[1] = TMath::ATan2((parSCM0[1]-parSCM0[0])/2.,2.*parSCM0[3])*180./TMath::Pi(); // theta
443       parTRAP[2] = 0.;           // phi
444       // bottom
445       parTRAP[3] = parSCM0[2]/2.; // H1
446       parTRAP[4] = parSCM0[0]/2.; // BL1
447       parTRAP[5] = parTRAP[4];    // TL1
448       parTRAP[6] = 0.0;           // ALP1
449       // top
450       parTRAP[7] = parSCM0[2]/2.; // H2
451       parTRAP[8] = parSCM0[1]/2.; // BL2
452       parTRAP[9] = parTRAP[8];    // TL2
453       parTRAP[10]= 0.0;           // ALP2
454       AliDebug(2,Form(" ** TRAP ** \n"));
455       for(int i=0; i<11; i++) AliDebug(3, Form(" par[%2.2i] %9.4f\n", i, parTRAP[i]));
456
457       gMC->Gsvolu("SCMX", "TRAP", fIdTmedArr[kIdSC], parTRAP, 11);
458       xpos = +(parSCM0[1]+parSCM0[0])/4.;
459       gMC->Gspos("SCMX", 1, "SCMY", xpos, 0.0, 0.0, 0, "ONLY") ;
460
461       // Using rotation because SCMX should be the same due to Pb tiles
462       xpos = -xpos; 
463       AliMatrix(fIdRotm, 90.0,180., 90.0, 270.0, 0.0,0.0) ;
464       gMC->Gspos("SCMX", 2, "SCMY", xpos, 0.0, 0.0, fIdRotm, "ONLY");
465     // put LED to the SCM0 
466       AliEMCALShishKebabTrd1Module *mod = (AliEMCALShishKebabTrd1Module*)fShishKebabModules->At(0);
467       gMC->Gsvolu("PBTI", "BOX", fIdTmedArr[kIdPB], dummy, 0);
468
469       par[1] = parSCM0[2]/2;            // y 
470       par[2] = g->GetECPbRadThick()/2.; // z
471
472       int nr=0;
473       ypos = 0.0; 
474       zpos = -fSampleWidth*g->GetNECLayers()/2. + g->GetECPbRadThick()/2.;
475       double xCenterSCMX =  (parTRAP[4] +  parTRAP[8])/2.;
476       if(!gn.Contains("NOPB")) { // for testing - 11-jul-05
477         AliDebug(2,Form(" Pb tiles \n"));
478         for(int iz=0; iz<g->GetNECLayers(); iz++){
479           par[0] = (parSCM0[0] + mod->GetTanBetta()*fSampleWidth*iz)/2.;
480           xpos   = par[0] - xCenterSCMX;
481           gMC->Gsposp("PBTI", ++nr, "SCMX", xpos, ypos, zpos, 0, "ONLY", par, 3) ;
482           AliDebug(3,Form(" %i xpos %f zpos %f par[0] %f \n", iz+1, xpos, zpos, par[0]));
483           zpos += fSampleWidth;
484         } 
485         AliDebug(2,Form(" Number of Pb tiles in SCMX %i \n", nr));
486       }
487     } else if(g->GetNPHIdiv()==3 && g->GetNETAdiv()==3) {
488       Trd1Tower3X3(parSCM0);
489     } else if(g->GetNPHIdiv()==4 && g->GetNETAdiv()==4) {
490       Trd1Tower4X4();
491     }
492   } else if(gn.Contains("TRD2")) {    // TRD2 - 14-jan-05
493     //    Scm0InTrd2(g, fParEMOD, parSCM0); // First dessin 
494     PbmoInTrd2(g, fParEMOD, parSCM0); // Second dessin 
495   }
496 }
497
498 void AliEMCALv0::CreateSmod(const char* mother)
499
500   // 18-may-05; mother="XEN1"; 
501   // child="SMOD" from first to 10th, "SM10" (11th and 12th) (TRD1 case)
502   // child="SMON" and "SMOP"("TRD2" case)
503   AliEMCALGeometry * g = GetGeometry(); 
504   TString gn(g->GetName()); gn.ToUpper();
505
506   Double_t par[3], parTubs[5], xpos=0., ypos=0., zpos=0., rpos=0., dphi=0., phi=0.0, phiRad=0.;
507   Double_t par1C = 0.;
508   //  ===== define Super Module from air - 14x30 module ==== ;
509   fSampleWidth = double(g->GetECPbRadThick()+g->GetECScintThick());
510   AliDebug(2,Form("\n ## Super Module | fSampleWidth %5.3f ## %s \n", fSampleWidth, gn.Data()));
511   par[0] = g->GetShellThickness()/2.;
512   par[1] = g->GetPhiModuleSize()*g->GetNPhi()/2.; 
513   par[2] = g->GetEtaModuleSize()*15.; 
514   fIdRotm=0;
515   int nphism = g->GetNumberOfSuperModules()/2; // 20-may-05
516   if(nphism>0) {
517     dphi = (g->GetArm1PhiMax() - g->GetArm1PhiMin())/nphism;
518     //    if(gn.Contains("110DEG")) dphi = (g->GetArm1PhiMax() - g->GetArm1PhiMin())/(nphism-1);
519     rpos = (g->GetEnvelop(0) + g->GetEnvelop(1))/2.;
520     AliDebug(2,Form(" rpos %8.2f : dphi %6.1f degree \n", rpos, dphi));
521   }
522
523   if (gn.Contains("TRD2")) { // tubs - 27-jan-05
524     parTubs[0] = g->GetTubsR();                       // rmin
525     parTubs[1] = parTubs[0] + g->GetShellThickness(); // rmax ?? 
526     parTubs[2] = 380./2.;                             // DZ half length in z; 11-oct-04 - for 26 division
527     parTubs[3] = -dphi/2.;                            // PHI1 starting angle of the segment;
528     parTubs[4] = +dphi/2.;                            // PHI2 ending angle of the segment;
529
530     gMC->Gsvolu("SMOP", "TUBS", fIdTmedArr[kIdAIR], parTubs, 5); // pozitive Z
531     gMC->Gsvolu("SMON", "TUBS", fIdTmedArr[kIdAIR], parTubs, 5); // negative Z
532
533     AliDebug(2,Form(" SMOP,N ** TUBS **\n")); 
534     AliDebug(2,Form("tmed %i | Rmin %7.2f Rmax %7.2f dz %7.2f phi1,2 (%7.2f,%7.2f)\n", 
535                     fIdTmedArr[kIdAIR], parTubs[0],parTubs[1],parTubs[2], parTubs[3],parTubs[4]));
536     // have to add 1 cm plastic before EMOD - time solution 
537   } else if(gn.Contains("WSUC")) {
538     par[0] = g->GetPhiModuleSize()*g->GetNPhi()/2.; 
539     par[1] = g->GetShellThickness()/2.;
540     par[2] = g->GetEtaModuleSize()*g->GetNZ()/2. + 5; 
541
542     gMC->Gsvolu("SMOD", "BOX", fIdTmedArr[kIdAIR], par, 3);
543
544     AliDebug(2,Form("SMOD in WSUC : tmed %i | dx %7.2f dy %7.2f dz %7.2f (SMOD, BOX)\n", 
545                     fIdTmedArr[kIdAIR], par[0],par[1],par[2]));
546     fSmodPar0 = par[0]; 
547     fSmodPar1 = par[1];
548     fSmodPar2 = par[2];
549     nphism   =  g->GetNumberOfSuperModules();
550   } else {
551     if     (gn.Contains("TWIST")) {
552       par[2] += 0.4;      // for 27 division
553     } else if(gn.Contains("TRD")) {
554       par[2]  = 350./2.; // 11-oct-04 - for 26 division
555       if(gn.Contains("TRD1")) {
556         AliDebug(2,Form(" par[0] %7.2f (old) \n",  par[0]));
557         Float_t *parSM = g->GetSuperModulesPars(); 
558         for(int i=0; i<3; i++) par[i] = parSM[i];
559       }
560     }
561     gMC->Gsvolu("SMOD", "BOX", fIdTmedArr[kIdAIR], par, 3);
562     AliDebug(2,Form("tmed %i | dx %7.2f dy %7.2f dz %7.2f (SMOD, BOX)\n", 
563                     fIdTmedArr[kIdAIR], par[0],par[1],par[2]));
564     fSmodPar0 = par[0]; 
565     fSmodPar2 = par[2];
566     if(gn.Contains("110DEG")) { // 12-oct-05
567       par1C = par[1];
568       par[1] /= 2.;
569       gMC->Gsvolu("SM10", "BOX", fIdTmedArr[kIdAIR], par, 3);
570       AliDebug(2,Form(" Super module with name \"SM10\" was created too par[1] = %f\n", par[1]));
571       par[1] = par1C;
572     }
573   // Steel plate
574     if(g->GetSteelFrontThickness() > 0.0) { // 28-mar-05
575       par[0] = g->GetSteelFrontThickness()/2.;
576       gMC->Gsvolu("STPL", "BOX", fIdTmedArr[kIdSTEEL], par, 3);
577       printf("tmed %i | dx %7.2f dy %7.2f dz %7.2f (STPL) \n", fIdTmedArr[kIdSTEEL], par[0],par[1],par[2]);
578       xpos = -(g->GetShellThickness() - g->GetSteelFrontThickness())/2.;
579       gMC->Gspos("STPL", 1, "SMOD", xpos, 0.0, 0.0, 0, "ONLY") ;
580     }
581   }
582
583   int nr=0, nrsmod=0, i0=0;
584   if(gn.Contains("TEST")) {nphism = 1;} // just only 2 super modules;
585
586   // Turn whole super module
587   int turnSupMod = 1; // should be ONE; for testing = 0
588   for(int i=i0; i<nphism; i++) {
589     if (gn.Contains("TRD2")) {      // tubs - 27-jan-05
590       if(i==i0) {
591         printf("** TRD2 ** ");
592         if(turnSupMod==1) printf(" No 3 degree rotation !!! ");
593         printf("\n");
594       }
595       Double_t phic=0., phicRad=0.; // phi angle of arc center
596       phic    = g->GetArm1PhiMin() + dphi*(2*i+1)/2.; //
597       phicRad = phic*TMath::DegToRad();
598       phi     = phic - g->GetTubsTurnAngle();
599       phiRad  = phi*TMath::DegToRad();
600       if(turnSupMod==1) {
601         TVector2  vc;     // position of super module center
602         vc.SetMagPhi(parTubs[0], phicRad);
603         TVector2  vcTurn; // position of super module center with turn
604         vcTurn.SetMagPhi(parTubs[0], phiRad);
605         TVector2 vcShift = vc - vcTurn;
606         phic = phi;
607
608         xpos = vcShift.X();
609         ypos = vcShift.Y();
610       } else { // 1-mar-05 ; just for testing - no turn od SMOD; looks good
611         xpos = ypos = 0.0;
612       }
613       zpos = parTubs[2];
614       AliMatrix(fIdRotm, 90.0, phic, 90.0, 90.0+phic, 0.0, 0.0);
615
616       gMC->Gspos("SMOP", ++nr, mother, xpos, ypos, zpos, fIdRotm, "ONLY") ;
617       printf("SMOP %2i | %2i fIdRotm %3i phi %6.1f(%5.3f) xpos %7.2f ypos %7.2f zpos %7.2f \n", 
618       i, nr, fIdRotm, phic, phicRad, xpos, ypos, zpos);
619       printf(" phiy(90+phic)  %6.1f \n", 90. + phic);
620
621       if(!gn.Contains("TEST1") && g->GetNumberOfSuperModules() > 1){
622         //        double  phiy = 90. + phic + 180.;
623         //        if(phiy>=360.) phiy -= 360.;
624         //        printf(" phiy  %6.1f \n", phiy);
625         //        AliMatrix(fIdRotm, 90.0, phic, 90.0, phiy, 180.0, 0.0);
626         gMC->Gspos("SMON", nr, mother, xpos, ypos, -zpos, fIdRotm, "ONLY") ;
627         printf("SMON %2i | %2i fIdRotm %3i phi %6.1f(%5.3f) xpos %7.2f ypos %7.2f zpos %7.2f \n", 
628         i, nr, fIdRotm, phic, phicRad, xpos, ypos, -zpos);
629       }
630     } else if(gn.Contains("WSUC")) {
631       xpos = ypos = zpos = 0.0;
632       fIdRotm = 0;
633       gMC->Gspos("SMOD", 1, mother, xpos, ypos, zpos, fIdRotm, "ONLY") ;
634       printf(" fIdRotm %3i phi %6.1f(%5.3f) xpos %7.2f ypos %7.2f zpos %7.2f \n", 
635       fIdRotm, phi, phiRad, xpos, ypos, zpos);
636       nr++;
637     } else { // TRD1 
638       TString smName("SMOD"); // 12-oct-05
639       if(i==5 && gn.Contains("110DEG")) {
640         smName = "SM10";
641         nrsmod = nr;
642         nr     = 0;
643       }
644       phi    = g->GetArm1PhiMin() + dphi*(2*i+1)/2.; // phi= 70, 90, 110, 130, 150, 170
645       phiRad = phi*TMath::Pi()/180.;
646
647       AliMatrix(fIdRotm, 90.0, phi, 90.0, 90.0+phi, 0.0, 0.0);
648
649       xpos = rpos * TMath::Cos(phiRad);
650       ypos = rpos * TMath::Sin(phiRad);
651       zpos = fSmodPar2; // 21-sep-04
652       if(i==5 && gn.Contains("110DEG")) {
653         xpos += (par1C/2. * TMath::Sin(phiRad)); 
654         ypos -= (par1C/2. * TMath::Cos(phiRad)); 
655       }
656       
657       // 1th module in z-direction;
658       gMC->Gspos(smName.Data(), ++nr, mother, xpos, ypos, zpos, fIdRotm, "ONLY") ;
659       AliDebug(3, Form(" %s : %2i fIdRotm %3i phi %6.1f(%5.3f) xpos %7.2f ypos %7.2f zpos %7.2f : i %i \n", 
660                        smName.Data(), nr, fIdRotm, phi, phiRad, xpos, ypos, zpos, i));
661       // 2th module in z-direction;
662       if(gn.Contains("TWIST") || gn.Contains("TRD")) {
663       // turn arround X axis; 0<phi<360
664         double phiy = 90. + phi + 180.;
665         if(phiy>=360.) phiy -= 360.;
666  
667         AliMatrix(fIdRotm, 90.0, phi, 90.0, phiy, 180.0, 0.0);
668         gMC->Gspos(smName.Data(), ++nr, mother, xpos, ypos, -zpos, fIdRotm, "ONLY");
669         AliDebug(3, Form(" %s : %2i fIdRotm %3i phiy %6.1f  xpos %7.2f ypos %7.2f zpos %7.2f \n", 
670                          smName.Data(), nr, fIdRotm, phiy, xpos, ypos, -zpos));
671       } else {
672         gMC->Gspos("SMOD", ++nr, mother, xpos, ypos, -zpos, fIdRotm, "ONLY");
673       }
674     }
675   }
676   AliDebug(2,Form(" Number of Super Modules %i \n", nr+nrsmod));
677 }
678
679 void AliEMCALv0::CreateEmod(const char* mother, const char* child)
680
681   // 17-may-05; mother="SMOD"; child="EMOD"
682   AliEMCALGeometry * g = GetGeometry(); 
683   TString gn(g->GetName()); gn.ToUpper(); 
684   // Module definition
685   Double_t par[10], parTubs[5], xpos=0., ypos=0., zpos=0., rpos=0.;
686   Double_t parSCPA[5], zposSCPA=0.; // passive SC - 13-MAY-05, TRD1 case
687   Double_t trd1Angle = g->GetTrd1Angle()*TMath::DegToRad(), tanTrd1 = TMath::Tan(trd1Angle/2.);
688   Double_t tanTrd2y  = TMath::Tan(g->GetTrd2AngleY()*TMath::DegToRad()/2.);
689   int nr=0;
690   fIdRotm=0;
691   if(!gn.Contains("TRD")) { // standard module
692     par[0] = (fSampleWidth*g->GetNECLayers())/2.; 
693     par[1] = par[2] = g->GetPhiModuleSize()/2.;
694     gMC->Gsvolu(child, "BOX", fIdTmedArr[kIdSTEEL], par, 3);
695
696   } else if (gn.Contains("TRD1")){ // TRD1 system coordinate iz differnet
697     if(strcmp(mother,"SMOD")==0) {
698       fParEMOD[0] = g->GetEtaModuleSize()/2.;   // dx1
699       fParEMOD[1] = g->Get2Trd1Dx2()/2.;        // dx2
700       fParEMOD[2] = g->GetPhiModuleSize()/2.;;  // dy
701       fParEMOD[3] = g->GetLongModuleSize()/2.;  // dz
702       gMC->Gsvolu(child, "TRD1", fIdTmedArr[kIdSTEEL], fParEMOD, 4);
703       if(gn.Contains("WSUC") || gn.Contains("MAY05")){
704         parSCPA[0] = g->GetEtaModuleSize()/2. + tanTrd1*g->GetFrontSteelStrip();   // dx1
705         parSCPA[1] = parSCPA[0]               + tanTrd1*g->GetPassiveScintThick(); // dx2
706         parSCPA[2] = g->GetPhiModuleSize()/2.;     // dy
707         parSCPA[3] = g->GetPassiveScintThick()/2.; // dz
708         gMC->Gsvolu("SCPA", "TRD1", fIdTmedArr[kIdSC], parSCPA, 4);
709         zposSCPA   = -fParEMOD[3] + g->GetFrontSteelStrip() + g->GetPassiveScintThick()/2.;
710         gMC->Gspos ("SCPA", ++nr, child, 0.0, 0.0, zposSCPA, 0, "ONLY");
711       }
712     }
713   } else if (gn.Contains("TRD2")){ // TRD2 as for TRD1 - 27-jan-05
714     fParEMOD[0] = g->GetEtaModuleSize()/2.;   // dx1
715     fParEMOD[1] = g->Get2Trd1Dx2()/2.;        // dx2
716     fParEMOD[2] = g->GetPhiModuleSize()/2.;   // dy1
717     fParEMOD[3] = fParEMOD[2] + tanTrd2y*g->GetLongModuleSize();// dy2
718     fParEMOD[4] = g->GetLongModuleSize()/2.;  // dz
719     gMC->Gsvolu(child, "TRD2", fIdTmedArr[kIdSTEEL], fParEMOD, 5);
720   }
721
722   nr   = 0;
723   if(gn.Contains("TWIST")) { // 13-sep-04
724     fShishKebabModules = new TList;
725     AliEMCALShishKebabModule *mod=0, *mTmp; // current module
726     for(int iz=0; iz<g->GetNZ(); iz++) {
727       //for(int iz=0; iz<4; iz++) {
728       if(iz==0) {
729         mod    = new AliEMCALShishKebabModule();
730         fIdRotm = 0;
731       } else {
732         mTmp = new AliEMCALShishKebabModule(*mod);
733         mod  = mTmp;
734         Double_t  angle = mod->GetThetaInDegree();
735         AliMatrix(fIdRotm, angle,0., 90.0,90.0, 90.-angle, 180.);
736       }
737       fShishKebabModules->Add(mod);
738
739       xpos = mod->GetPosXfromR() + g->GetSteelFrontThickness() - fSmodPar0;
740       zpos = mod->GetPosZ() - fSmodPar2;
741       for(int iy=0; iy<g->GetNPhi(); iy++) {
742         ypos = g->GetPhiModuleSize()*(2*iy+1 - g->GetNPhi())/2.;
743         gMC->Gspos(child, ++nr, mother, xpos, ypos, zpos, fIdRotm, "ONLY") ;
744         //        printf(" %3i(%2i,2i) xpos %7.2f ypos %7.2f zpos %7.2f \n", nr,iy,iz, xpos, ypos, zpos);
745       }
746     }    
747   } else if(gn.Contains("TRD")) { // 30-sep-04; 27-jan-05 - as for TRD1 as for TRD2
748     // X->Z(0, 0); Y->Y(90, 90); Z->X(90, 0)
749     AliEMCALShishKebabTrd1Module *mod=0, *mTmp; // current module
750
751     for(int iz=0; iz<g->GetNZ(); iz++) {
752       Double_t  angle=90., phiOK=0;
753       if(gn.Contains("TRD1")) {
754         mod = (AliEMCALShishKebabTrd1Module*)fShishKebabModules->At(iz);
755         angle = mod->GetThetaInDegree();
756         if(!gn.Contains("WSUC")) { // ALICE 
757           if(iz==0) AliMatrix(fIdRotm, 0.,0., 90.,90., 90.,0.); // z'(x); y'(y); x'(z)
758           else      AliMatrix(fIdRotm, 90.-angle,180., 90.0,90.0, angle, 0.);
759           phiOK = mod->GetCenterOfModule().Phi()*180./TMath::Pi(); 
760           //          printf(" %2i | angle | %6.3f - %6.3f = %6.3f(eta %5.3f)\n", 
761           //iz+1, angle, phiOK, angle-phiOK, mod->GetEtaOfCenterOfModule());
762           xpos = mod->GetPosXfromR() + g->GetSteelFrontThickness() - fSmodPar0;
763           zpos = mod->GetPosZ() - fSmodPar2;
764
765           int iyMax = g->GetNPhi();
766           if(strcmp(mother,"SMOD") && gn.Contains("110DEG")) {
767             iyMax /= 2;
768           }
769           for(int iy=0; iy<iyMax; iy++) { // flat in phi
770             ypos = g->GetPhiModuleSize()*(2*iy+1 - iyMax)/2.;
771             gMC->Gspos(child, ++nr, mother, xpos, ypos, zpos, fIdRotm, "ONLY") ;
772         //printf(" %2i xpos %7.2f ypos %7.2f zpos %7.2f fIdRotm %i\n", nr, xpos, ypos, zpos, fIdRotm);
773             AliDebug(3,Form("%3.3i(%2.2i,%2.2i) ", nr,iy+1,iz+1));
774           }
775           //PH          printf("\n");
776         } else {
777           if(iz==0) AliMatrix(fIdRotm, 0.,0., 90.,0., 90.,90.); // (x')z; y'(x); z'(y)
778           else      AliMatrix(fIdRotm, 90-angle,270., 90.0,0.0, angle,90.);
779           phiOK = mod->GetCenterOfModule().Phi()*180./TMath::Pi(); 
780           printf(" %2i | angle -phiOK | %6.3f - %6.3f = %6.3f(eta %5.3f)\n", 
781           iz+1, angle, phiOK, angle-phiOK, mod->GetEtaOfCenterOfModule());
782           zpos = mod->GetPosZ()      - fSmodPar2;
783           ypos = mod->GetPosXfromR() - fSmodPar1;
784           printf(" zpos %7.2f ypos %7.2f fIdRotm %i\n xpos ", zpos, xpos, fIdRotm);
785           for(int ix=0; ix<g->GetNPhi(); ix++) { // flat in phi
786             xpos = g->GetPhiModuleSize()*(2*ix+1 - g->GetNPhi())/2.;
787             gMC->Gspos(child, ++nr, mother, xpos, ypos, zpos, fIdRotm, "ONLY") ;
788             printf(" %7.2f ", xpos);
789           }
790           printf("\n");
791         }
792       } else if(gn.Contains("TRD2")){ // 1-feb-05 - TRD2;  curve in phi
793         double angEtaRow = 0.;
794         double theta1=0.,phi1=0., theta2=0.,phi2=0., theta3=0.,phi3=0.;
795         angle=90.;
796         if(iz==0) {
797           mod   = new AliEMCALShishKebabTrd1Module();
798         } else {
799           mTmp  = new AliEMCALShishKebabTrd1Module(*mod);
800           mod   = mTmp;
801           angle = mod->GetThetaInDegree();
802         }
803
804         fShishKebabModules->Add(mod);
805         phiOK = mod->GetCenterOfModule().Phi()*180./TMath::Pi(); 
806         AliDebug(2,Form(" %i | theta | %6.3f - %6.3f = %6.3f\n", iz+1, angle, phiOK, angle-phiOK));
807
808         zpos = mod->GetPosZ() - parTubs[2];
809         rpos = parTubs[0] + mod->GetPosXfromR();
810
811         angle     = mod->GetThetaInDegree();
812         Double_t stepAngle = (parTubs[4] -  parTubs[3])/g->GetNPhi(); // 11-mar-04
813         for(int iy=0; iy<g->GetNPhi(); iy++) {
814           angEtaRow = parTubs[3] + stepAngle*(0.5+double(iy));
815           //          angEtaRow = 0;
816           theta1  = 90. +  angle; phi1 = angEtaRow;      // x' ~-z;
817           theta2  = 90.;          phi2 = 90. + angEtaRow;// y' ~ y;
818           theta3  = angle;        phi3 = angEtaRow;      // z' ~ x;
819           if(phi3 < 0.0) phi3 += 360.; 
820           AliMatrix(fIdRotm, theta1,phi1, theta2,phi2, theta3,phi3);
821
822           xpos = rpos * TMath::Cos(angEtaRow*TMath::DegToRad());
823           ypos = rpos * TMath::Sin(angEtaRow*TMath::DegToRad());
824           gMC->Gspos(child, ++nr, "SMOP", xpos, ypos, zpos, fIdRotm, "ONLY") ;
825           // SMON; 
826           phi1    = 180 + angEtaRow;
827           theta3  = 180.-theta3;  phi3 = angEtaRow;
828           AliMatrix(fIdRotm, theta1,phi1, theta2,phi2, theta3,phi3);
829           gMC->Gspos(child,  nr, "SMON", xpos, ypos, -zpos, fIdRotm, "ONLY") ;
830           if(AliDebugLevel()>=2) {
831             printf(" angEtaRow(phi) %7.2f |  angle(eta) %7.2f \n",  angEtaRow, angle);
832             printf("iy=%2i xpos %7.2f ypos %7.2f zpos %7.2f fIdRotm %i\n", iy, xpos, ypos, zpos, fIdRotm);
833           }
834         } // for(int iy=0; iy<g->GetNPhi(); iy++)
835       }
836     } 
837   } else {
838     xpos = g->GetSteelFrontThickness()/2.;
839     for(int iz=0; iz<g->GetNZ(); iz++) {
840       zpos = -fSmodPar2 + g->GetEtaModuleSize()*(2*iz+1)/2.;
841       for(int iy=0; iy<g->GetNPhi(); iy++) {
842         ypos = g->GetPhiModuleSize()*(2*iy+1 - g->GetNPhi())/2.;
843         gMC->Gspos(child, ++nr, mother, xpos, ypos, zpos, 0, "ONLY") ;
844       //printf(" %2i xpos %7.2f ypos %7.2f zpos %7.2f \n", nr, xpos, ypos, zpos);
845       }
846     }
847   }
848   AliDebug(2,Form(" Number of modules in Super Module %i \n", nr));
849 }
850
851 // 8-dec-04 by PAI
852 void AliEMCALv0::Trd1Tower3X3(const double parSCM0[4])
853 {
854   // PB should be for whole SCM0 - ?
855   double parTRAP[11], *dummy=0;
856   AliEMCALGeometry * g = GetGeometry(); 
857   TString gn(g->GetName()), scmx; 
858   gn.ToUpper(); 
859  // Division to tile size 
860   AliDebug(2,Form("Trd1Tower3X3() : Divide SCM0 on y-axis %i", g->GetNETAdiv()));
861   gMC->Gsdvn("SCMY","SCM0", g->GetNETAdiv(), 2); // y-axis
862   double dx1=parSCM0[0], dx2=parSCM0[1], dy=parSCM0[2], dz=parSCM0[3];
863   double ndiv=3., xpos=0.0;
864   // should be defined once
865   gMC->Gsvolu("PBTI", "BOX", fIdTmedArr[kIdPB], dummy, 0);
866   if(gn.Contains("TEST")==0) { // one name for all trapesoid
867     scmx = "SCMX"; 
868     gMC->Gsvolu(scmx.Data(), "TRAP", fIdTmedArr[kIdSC], dummy, 0);
869   }
870
871   
872   for(int ix=1; ix<=3; ix++) { // 3X3
873     // ix=1
874     parTRAP[0] = dz;
875     parTRAP[1] = TMath::ATan2((dx2-dx1)/2.,2.*dz)*TMath::RadToDeg(); // theta
876     parTRAP[2] = 0.;           // phi
877     // bottom
878     parTRAP[3] = dy/ndiv;      // H1
879     parTRAP[4] = dx1/ndiv;     // BL1
880     parTRAP[5] = parTRAP[4];   // TL1
881     parTRAP[6] = 0.0;          // ALP1
882     // top
883     parTRAP[7] = dy/ndiv;      // H2
884     parTRAP[8] = dx2/ndiv;     // BL2
885     parTRAP[9] = parTRAP[8];   // TL2
886     parTRAP[10]= 0.0;          // ALP2
887     xpos = +(dx1+dx2)/3.;      // 6 or 3
888
889     if      (ix==3) {
890       parTRAP[1] = -parTRAP[1];
891       xpos = -xpos;
892     } else if(ix==2) { // central part is box but we treat as trapesoid due to numbering
893       parTRAP[1] = 0.;
894       parTRAP[8] = dx1/ndiv;     // BL2
895       parTRAP[9] = parTRAP[8];   // TL2
896       xpos = 0.0;
897     }
898     AliDebug(2,Form(" ** TRAP ** xpos %9.3f\n", xpos));
899     for(int i=0; i<11; i++) AliDebug(2,Form(" par[%2.2i] %9.4f\n", i, parTRAP[i]));
900     if(gn.Contains("TEST")){
901       scmx = "SCX"; scmx += ix;
902       gMC->Gsvolu(scmx.Data(), "TRAP", fIdTmedArr[kIdSC], parTRAP, 11);
903       gMC->Gspos(scmx.Data(), 1, "SCMY", xpos, 0.0, 0.0, 0, "ONLY") ;
904     } else {
905       gMC->Gsposp(scmx.Data(), ix, "SCMY", xpos, 0.0, 0.0, 0, "ONLY", parTRAP, 11) ;
906     }
907     PbInTrap(parTRAP, scmx);
908   }
909   AliDebug(2,Form("Trd1Tower3X3()", "Ver. 1.0 : was tested."));
910 }
911
912 // 8-dec-04 by PAI
913 void AliEMCALv0::PbInTrap(const double parTRAP[11], TString n)
914 {
915  // see for example CreateShishKebabGeometry(); just for case TRD1
916   static int nr=0;
917   AliDebug(2,Form(" Pb tiles : nrstart %i\n", nr));
918   AliEMCALGeometry * g = GetGeometry(); 
919
920   double par[3];
921   //  double fSampleWidth = double(g->GetECPbRadThick()+g->GetECScintThick());
922   double xpos = 0.0, ypos = 0.0;
923   double zpos = -fSampleWidth*g->GetNECLayers()/2. + g->GetECPbRadThick()/2.;
924
925   double coef = (parTRAP[8] -  parTRAP[4]) / (2.*parTRAP[0]);
926   double xCenterSCMX =  (parTRAP[4] +  parTRAP[8])/2.; // ??
927   //  double tan = TMath::Tan(parTRAP[1]*TMath::DegToRad());
928
929   par[1] = parTRAP[3];              // y 
930   par[2] = g->GetECPbRadThick()/2.; // z
931   for(int iz=0; iz<g->GetNECLayers(); iz++){
932     par[0] = parTRAP[4] + coef*fSampleWidth*iz;
933     xpos   = par[0] - xCenterSCMX;
934     if(parTRAP[1] < 0.) xpos = -xpos;
935     gMC->Gsposp("PBTI", ++nr, n.Data(), xpos, ypos, zpos, 0, "ONLY", par, 3) ;
936     AliDebug(2,Form(" %i xpos %9.3f zpos %9.3f par[0] %9.3f |", iz+1, xpos, zpos, par[0]));
937     zpos += fSampleWidth;
938     if(iz%2>0) printf("\n");
939   } 
940   AliDebug(2,Form(" Number of Pb tiles in SCMX %i coef %9.7f \n", nr, coef));
941   AliDebug(2,Form(" par[1] %9.3f  par[2] %9.3f ypos %9.3f \n", par[1], par[2], ypos)); 
942   AliDebug(2,Form(" PbInTrap Ver. 1.0 : was tested."));
943 }
944
945 // 8-dec-04 by PAI
946 void AliEMCALv0::Trd1Tower4X4()
947 {
948  // Not ready yet
949 }
950 // 3-feb-05
951 void AliEMCALv0::Scm0InTrd2(const AliEMCALGeometry * g, const Double_t emodPar[5], Double_t parSCM0[5])
952 {
953   // Passive material inside the detector
954   double wallThickness = g->GetPhiModuleSize()/2. -  g->GetPhiTileSize(); //Need check
955   AliDebug(2,Form(" wall thickness %7.5f \n", wallThickness));
956   for(int i=0; i<4; i++) { // on pictures sometimes I can not see 0 -> be carefull!!
957     parSCM0[i] = emodPar[i] - wallThickness;
958     AliDebug(2,Form(" %i parSCMO %7.3f emodPar %7.3f : dif %7.3f \n", 
959                     i, parSCM0[i],emodPar[i], parSCM0[i]-emodPar[i]));
960   }
961   parSCM0[4] = emodPar[4];
962   gMC->Gsvolu("SCM0", "TRD2", fIdTmedArr[kIdSC], parSCM0, 5); // kIdAIR -> kIdSC
963   gMC->Gspos("SCM0", 1, "EMOD", 0., 0., 0., 0, "ONLY") ;
964   // Division 
965   if(g->GetNPHIdiv()==2 && g->GetNETAdiv()==2) {
966     Division2X2InScm0(g, parSCM0);
967   } else {
968     Info("Scm0InTrd2"," no division SCM0 in this geometry |%s|\n", g->GetName());
969     assert(0);
970   }
971 }
972
973 void AliEMCALv0::Division2X2InScm0(const AliEMCALGeometry * g, const Double_t parSCM0[5])
974 {
975   // Division 2X2
976   Double_t parTRAP[11], xpos=0.,ypos=0., dx1=0.0,dx2=0.,dy1=0.0,dy2=0.,dz=0.
977   ,dr1=0.0,dr2=0.;
978   fIdRotm=0;
979
980   Info("Division2X2InScm0","Divide SCM0 on y-axis %i\n", g->GetNETAdiv());
981   TString n("SCMX"), overLapFlagSCMY("ONLY"), overLapFlagSCMX("ONLY");
982   n = "SCM0"; // for testing - 14-mar-05
983   if(n=="SCM0"){
984     PbInTrapForTrd2(parSCM0, n);
985     // overLapFlagSCMY=overLapFlagSCMX="MANY"; // do not work
986     return;
987   }
988
989   dy1 = parSCM0[2] , dy2 = parSCM0[3], dz = parSCM0[4];
990
991   parTRAP[0] = parSCM0[4];    // dz
992   parTRAP[1] = TMath::ATan2((dy2-dy1)/2.,2.*dz)*TMath::RadToDeg();
993   parTRAP[2] = 90.;           // phi
994   // bottom
995   parTRAP[3] = parSCM0[2]/2.; // H1
996   parTRAP[4] = parSCM0[0];    // BL1
997   parTRAP[5] = parTRAP[4];    // TL1
998   parTRAP[6] = 0.0;           // ALP1
999   // top
1000   parTRAP[7] = parSCM0[3]/2.; // H2
1001   parTRAP[8] = parSCM0[1];    // BL2
1002   parTRAP[9] = parTRAP[8];    // TL2
1003   parTRAP[10]= 0.0;           // ALP2
1004   AliDebug(2,Form(" ** SCMY ** \n"));
1005            for(int i=0; i<11; i++) AliDebug(2,Form(" par[%2.2i] %9.4f\n", i, parTRAP[i]));
1006
1007   fIdRotm=0;
1008   gMC->Gsvolu("SCMY", "TRAP", fIdTmedArr[kIdSC], parTRAP, 11); // kIdAIR -> kIdSC
1009   ypos = +(parTRAP[3]+parTRAP[7])/2.; //
1010   AliDebug(2,Form(" Y shift SCMY inside SCM0 : %7.3f : opt %s\n", ypos, overLapFlagSCMY.Data())); 
1011   gMC->Gspos("SCMY", 1, "SCM0", 0.0, ypos, 0.0, fIdRotm,  overLapFlagSCMY.Data()) ;
1012   // Rotation SCMY around z-axis on 180 degree; x'=-x; y'=-y and z=z
1013   AliMatrix(fIdRotm, 90.0,180., 90.0, 270.0, 0.0,0.0) ;
1014   // We may have problem with numeration due to rotation - 4-feb-05
1015   gMC->Gspos("SCMY", 2, "SCM0", 0.0, -ypos, 0.0, fIdRotm,  overLapFlagSCMY.Data()); 
1016
1017   Info("Division2X2InScm0","Divide SCMY on x-axis %i\n", g->GetNPHIdiv());
1018   dx1 = parSCM0[0]; 
1019   dx2 = parSCM0[1]; 
1020   dr1=TMath::Sqrt(dx1*dx1+dy1*dy1);
1021   dr2=TMath::Sqrt(dx2*dx2+dy2*dy2);
1022
1023   parTRAP[0] = parSCM0[4];    // dz
1024   parTRAP[1] = TMath::ATan2((dr2-dr1)/2.,2.*dz)*TMath::RadToDeg(); // 
1025   parTRAP[2] = 45.;           // phi
1026   // bottom
1027   parTRAP[3] = parSCM0[2]/2.; // H1
1028   parTRAP[4] = parSCM0[0]/2.; // BL1
1029   parTRAP[5] = parTRAP[4];    // TL1
1030   parTRAP[6] = 0.0;           // ALP1
1031   // top
1032   parTRAP[7] = parSCM0[3]/2.; // H2
1033   parTRAP[8] = parSCM0[1]/2;  // BL2
1034   parTRAP[9] = parTRAP[8];    // TL2
1035   parTRAP[10]= 0.0;           // ALP2
1036   AliDebug(2,Form(" ** SCMX ** \n"));
1037   for(int i=0; i<11; i++) AliDebug(2,Form(" par[%2.2i] %9.4f\n", i, parTRAP[i]));
1038
1039   fIdRotm=0;
1040   gMC->Gsvolu("SCMX", "TRAP", fIdTmedArr[kIdSC], parTRAP, 11);
1041   xpos = (parTRAP[4]+parTRAP[8])/2.;
1042   AliDebug(2,Form(" X shift SCMX inside SCMX : %7.3f : opt %s\n", xpos, overLapFlagSCMX.Data())); 
1043   gMC->Gspos("SCMX", 1, "SCMY", xpos, 0.0, 0.0, fIdRotm,  overLapFlagSCMX.Data()) ;
1044   //  AliMatrix(fIdRotm, 90.0,270., 90.0, 0.0, 0.0,0.0); // x'=-y; y'=x; z'=z
1045   AliMatrix(fIdRotm, 90.0,90., 90.0, -180.0, 0.0,0.0);     // x'=y;  y'=-x; z'=z
1046   gMC->Gspos("SCMX", 2, "SCMY", -xpos, 0.0, 0.0, fIdRotm,  overLapFlagSCMX.Data()) ;
1047   // PB:
1048   if(n=="SCMX" && overLapFlagSCMY == "ONLY") {
1049     PbInTrapForTrd2(parTRAP, n);
1050   }
1051
1052
1053 // 4-feb-05 by PAI
1054 void AliEMCALv0::PbInTrapForTrd2(const double *parTRAP, TString name)
1055 {
1056  // TRD2 cases
1057   Double_t *dummy=0;
1058   TString pbShape("BOX"), pbtiChonly("ONLY");
1059   if(name=="SCM0") {
1060     pbShape    = "TRD2";
1061     //    pbtiChonly = "MANY";
1062   }
1063   gMC->Gsvolu("PBTI", pbShape.Data(), fIdTmedArr[kIdPB], dummy, 0);
1064
1065   int nr=0;
1066   Info("PbInTrapForTrd2"," Pb tiles inside %s: shape %s :pbtiChonly %s\n nrstart %i\n", 
1067   name.Data(), pbShape.Data(), pbtiChonly.Data(), nr);
1068   AliEMCALGeometry * g = GetGeometry(); 
1069
1070   double par[5], parPB[5], parSC[5];
1071   //double fSampleWidth = double(g->GetECPbRadThick()+g->GetECScintThick());
1072   double xpos = 0.0, ypos = 0.0;
1073   double zpos = -fSampleWidth*g->GetNECLayers()/2. + g->GetECPbRadThick()/2.;
1074   if(name == "SCMX") { // common trapezoid - 11 parameters
1075     double coef = (parTRAP[8] -  parTRAP[4]) / (2.*parTRAP[0]);
1076     double xCenterSCMX =  (parTRAP[4] +  parTRAP[8])/2.; // the same for y
1077     AliDebug(2,Form(" xCenterSCMX %8.5f : coef %8.7f \n", xCenterSCMX, coef));
1078
1079     par[2] = g->GetECPbRadThick()/2.; // z
1080     for(int iz=0; iz<g->GetNECLayers(); iz++){
1081       par[0] = parTRAP[4] + coef*fSampleWidth*iz;
1082       par[1] = par[0];
1083       xpos   = ypos = par[0] - xCenterSCMX;
1084     //if(parTRAP[1] < 0.) xpos = -xpos;
1085       gMC->Gsposp("PBTI", ++nr, name.Data(), xpos, ypos, zpos, 0, "ONLY", par, 3) ;
1086       AliDebug(2,Form(" %2.2i xpos %8.5f zpos %6.3f par[0,1] %6.3f |", iz+1, xpos, zpos, par[0]));
1087       if(iz%2>0) AliDebug(2,Form("\n"));
1088       zpos += fSampleWidth;
1089     } 
1090     AliDebug(2,Form(" Number of Pb tiles in SCMX %i coef %9.7f \n", nr, coef));
1091     AliDebug(2,Form(" par[1] %9.5f  par[2] %9.5f ypos %9.5f \n", par[1], par[2], ypos)); 
1092   } else if(name == "SCM0") { // 1-mar-05 ; TRD2 - 5 parameters
1093     AliDebug(2,Form(" SCM0 par = "));
1094     for(int i=0; i<5; i++) AliDebug(2,Form(" %9.5f ", parTRAP[i]));
1095     AliDebug(2,Form("\n zpos %f \n",zpos));
1096
1097     double tanx = (parTRAP[1] -  parTRAP[0]) / (2.*parTRAP[4]); //  tanx =  tany now
1098     double tany = (parTRAP[3] -  parTRAP[2]) / (2.*parTRAP[4]), ztmp=0.;
1099     parPB[4] = g->GetECPbRadThick()/2.;
1100     parSC[2] = g->GetECScintThick()/2.;
1101     for(int iz=0; iz<g->GetNECLayers(); iz++){
1102       ztmp     = fSampleWidth*double(iz);
1103       parPB[0] = parTRAP[0] + tanx*ztmp;
1104       parPB[1] = parPB[0]   + tanx*g->GetECPbRadThick();
1105       parPB[2] = parTRAP[2] + tany*ztmp;
1106       parPB[3] = parPB[2]   + tany*g->GetECPbRadThick();
1107       gMC->Gsposp("PBTI", ++nr, name.Data(), xpos, ypos, zpos, 0, pbtiChonly.Data(), parPB, 5) ;
1108       AliDebug(2,Form("\n PBTI %2i | zpos %6.3f | par = ", nr, zpos));
1109       /*
1110       for(int i=0; i<5; i++) printf(" %9.5f ", parPB[i]);
1111       // individual SC tile
1112       parSC[0] = parPB[0];
1113       parSC[1] = parPB[1];
1114       gMC->Gsposp("SCTI", nr, name.Data(), xpos, ypos, zpos+g->GetECScintThick(), 
1115       0, pbtiChonly.Data(), parSC, 3) ;
1116       printf("\n SCTI     zpos %6.3f | par = ", zpos+g->GetECScintThick());
1117       for(int i=0; i<3; i++) printf(" %9.5f ", parPB[i]);
1118       */
1119       zpos  += fSampleWidth;
1120     }
1121     AliDebug(2,Form("\n"));
1122   }
1123   Info("PbInTrapForTrd2", "Ver. 0.03 : was tested.");
1124 }
1125
1126 // 15-mar-05
1127 void AliEMCALv0::PbmoInTrd2(const AliEMCALGeometry * g, const Double_t emodPar[5], Double_t parPBMO[5])
1128 {
1129   // Pb inside Trd2
1130   Info("PbmoInTrd2"," started : geometry %s ", g->GetName());
1131   double wallThickness = g->GetPhiModuleSize()/2. -  g->GetPhiTileSize();
1132   AliDebug(2,Form(" wall thickness %7.5f \n", wallThickness));
1133   for(int i=0; i<4; i++) {
1134     parPBMO[i] = emodPar[i] - wallThickness;
1135     AliDebug(2,Form(" %i parPBMO %7.3f emodPar %7.3f : dif %7.3f \n", 
1136                     i, parPBMO[i],emodPar[i], parPBMO[i]-emodPar[i]));
1137   }
1138   parPBMO[4] = emodPar[4];
1139   gMC->Gsvolu("PBMO", "TRD2", fIdTmedArr[kIdPB], parPBMO, 5);
1140   gMC->Gspos("PBMO", 1, "EMOD", 0., 0., 0., 0, "ONLY") ;
1141   // Division 
1142   if(g->GetNPHIdiv()==2 && g->GetNETAdiv()==2) {
1143     Division2X2InPbmo(g, parPBMO);
1144     AliDebug(2,Form(" PBMO, division 2X2 | geometry |%s|\n", g->GetName()));
1145   } else {
1146     AliDebug(2,Form(" no division PBMO in this geometry |%s|\n", g->GetName()));
1147     assert(0);
1148   }
1149 }
1150
1151 void AliEMCALv0::Division2X2InPbmo(const AliEMCALGeometry * g, const Double_t parPBMO[5]) 
1152 {
1153   // Division 2X2
1154   Info("Division2X2InPbmo"," started : geometry %s ", g->GetName());
1155   //Double_t *dummy=0;
1156   //  gMC->Gsvolu("SCTI", "BOX", fIdTmedArr[kIdSC], dummy, 0);
1157
1158   double parSC[3];
1159   //double fSampleWidth = double(g->GetECPbRadThick()+g->GetECScintThick());
1160   double xpos = 0.0, ypos = 0.0, zpos = 0.0, ztmp=0;;
1161   double tanx = (parPBMO[1] -  parPBMO[0]) / (2.*parPBMO[4]); //  tanx =  tany now
1162   double tany = (parPBMO[3] -  parPBMO[2]) / (2.*parPBMO[4]);
1163   char name[10], named[10], named2[10];
1164
1165   AliDebug(2,Form(" PBMO par = "));
1166   for(int i=0; i<5; i++) AliDebug(2,Form(" %9.5f ", parPBMO[i]));
1167   AliDebug(2,Form("\n"));
1168
1169   parSC[2] = g->GetECScintThick()/2.;
1170   zpos = -fSampleWidth*g->GetNECLayers()/2. + g->GetECPbRadThick() + g->GetECScintThick()/2.;
1171   AliDebug(2,Form(" parSC[2] %9.5f \n", parSC[2]));
1172   for(int iz=0; iz<g->GetNECLayers(); iz++){
1173     ztmp     = g->GetECPbRadThick() + fSampleWidth*double(iz); // Z for previous PB
1174     parSC[0] =  parPBMO[0] + tanx*ztmp;
1175     parSC[1] =  parPBMO[2] + tany*ztmp;
1176
1177     sprintf(name,"SC%2.2i", iz+1);
1178     gMC->Gsvolu(name, "BOX", fIdTmedArr[kIdSC], parSC, 3);
1179     gMC->Gspos(name, 1, "PBMO", xpos, ypos, zpos, 0, "ONLY") ;
1180     AliDebug(2,Form("%s | zpos %6.3f | parSC[0,1]=(%7.5f,%7.5f) -> ", 
1181                     name, zpos, parSC[0], parSC[1]));
1182     
1183     sprintf(named,"SY%2.2i", iz+1);
1184     printf(" %s -> ", named);
1185     gMC->Gsdvn(named,name, 2, 2);
1186
1187     sprintf(named2,"SX%2.2i", iz+1);
1188     printf(" %s \n", named2);
1189     gMC->Gsdvn(named2,named, 2, 1);
1190
1191     zpos    += fSampleWidth;
1192   }
1193 }
1194
1195 AliEMCALShishKebabTrd1Module* AliEMCALv0::GetShishKebabModule(Int_t neta)
1196
1197   // 28-oct-05
1198   AliEMCALShishKebabTrd1Module* trd1=0;
1199   if(fShishKebabModules && neta>=0 && neta<fShishKebabModules->GetSize()) {
1200     trd1 = (AliEMCALShishKebabTrd1Module*)fShishKebabModules->At(neta);
1201   }
1202   return trd1;
1203 }