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