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