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