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