TGeoMCGeometry.cxx

Go to the documentation of this file.
00001 // @(#)root/vmc:$Id: TGeoMCGeometry.cxx 34810 2010-08-13 13:36:26Z ivana $
00002 // Authors: Alice collaboration 25/06/2002
00003 
00004 /*************************************************************************
00005  * Copyright (C) 2006, Rene Brun and Fons Rademakers.                    *
00006  * Copyright (C) 2002, ALICE Experiment at CERN.                         *
00007  * All rights reserved.                                                  *
00008  *                                                                       *
00009  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00010  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00011  *************************************************************************/
00012 
00013 
00014 //______________________________________________________________________________
00015 //
00016 // Implementation of the TVirtualMCGeometry interface
00017 // for building TGeo geometry.
00018 //______________________________________________________________________________
00019 
00020 #include <ctype.h>
00021 #include "TError.h"
00022 #include "TArrayD.h"
00023 
00024 #include "TGeoMCGeometry.h"
00025 #include "TGeoManager.h"
00026 #include "TGeoMatrix.h"
00027 #include "TGeoVolume.h"
00028 #include "TGeoArb8.h"
00029 #include "TGeoTrd1.h"
00030 #include "TGeoTrd2.h"
00031 #include "TGeoTube.h"
00032 #include "TGeoCone.h"
00033 #include "TGeoPgon.h"
00034 #include "TGeoSphere.h"
00035 #include "TGeoPara.h"
00036 #include "TGeoEltu.h"
00037 #include "TGeoHype.h"
00038 #include "TMath.h"
00039 
00040 ClassImp(TGeoMCGeometry)
00041 
00042 TGeoMCGeometry* TGeoMCGeometry::fgInstance=0;
00043 
00044 //_____________________________________________________________________________
00045 TGeoMCGeometry::TGeoMCGeometry(const char *name, const char *title,
00046                                Bool_t g3CompatibleVolumeNames)
00047   : TVirtualMCGeometry(name, title),
00048     fG3CompatibleVolumeNames(g3CompatibleVolumeNames)
00049 {
00050    //
00051    // Standard constructor
00052    //
00053 }
00054 
00055 //_____________________________________________________________________________
00056 TGeoMCGeometry::TGeoMCGeometry()
00057   : TVirtualMCGeometry(),
00058     fG3CompatibleVolumeNames(kFALSE)
00059 {
00060    //
00061    // Default constructor
00062    //
00063 }
00064 
00065 //_____________________________________________________________________________
00066 TGeoMCGeometry::~TGeoMCGeometry()
00067 {
00068    //
00069    // Destructor
00070    //
00071    fgInstance=0;
00072 }
00073 
00074 //
00075 // private methods
00076 //
00077 
00078 
00079 //_____________________________________________________________________________
00080 TGeoManager* TGeoMCGeometry::GetTGeoManager() const
00081 {
00082 // Return TGeoManager global pointer.
00083 // Create a new TGeoManager object if it does not yet exist.
00084 
00085   if ( ! gGeoManager ) new TGeoManager("TGeo", "Root geometry manager");
00086 
00087   return gGeoManager;
00088 }  
00089 
00090 //_____________________________________________________________________________
00091 Double_t* TGeoMCGeometry::CreateDoubleArray(Float_t* array, Int_t size) const
00092 {
00093 // Converts Float_t* array to Double_t*,
00094 // !! The new array has to be deleted by user.
00095 // ---
00096 
00097    Double_t* doubleArray;
00098    if (size>0) {
00099       doubleArray = new Double_t[size];
00100       for (Int_t i=0; i<size; i++) doubleArray[i] = array[i];
00101    } else {
00102       //doubleArray = 0;
00103       doubleArray = new Double_t[1];
00104    }
00105    return doubleArray;
00106 }
00107 
00108 //______________________________________________________________________________
00109 void TGeoMCGeometry::Vname(const char *name, char *vname) const
00110 {
00111    //
00112    //  convert name to upper case. Make vname at least 4 chars
00113    //
00114    if (fG3CompatibleVolumeNames) {
00115       Int_t l = strlen(name);
00116       Int_t i;
00117       l = l < 4 ? l : 4;
00118       for (i=0;i<l;i++) vname[i] = toupper(name[i]);
00119       for (i=l;i<4;i++) vname[i] = ' ';
00120       vname[4] = 0;
00121    } else {
00122       Int_t l = strlen(name);
00123       if ( l>=79 ) l = 79;
00124       for (Int_t i=0;i<l;i++) vname[i] = name[i];
00125       vname[l] = 0;
00126    }
00127 }
00128 
00129 //
00130 // public methods
00131 //
00132 
00133 //_____________________________________________________________________________
00134 void TGeoMCGeometry::Material(Int_t& kmat, const char* name, Double_t a, Double_t z,
00135                        Double_t dens, Double_t radl, Double_t absl, Float_t* buf,
00136                        Int_t nwbuf)
00137 {
00138   //
00139   // Defines a Material
00140   //
00141   //  kmat               number assigned to the material
00142   //  name               material name
00143   //  a                  atomic mass in au
00144   //  z                  atomic number
00145   //  dens               density in g/cm3
00146   //  absl               absorbtion length in cm
00147   //                     if >=0 it is ignored and the program
00148   //                     calculates it, if <0. -absl is taken
00149   //  radl               radiation length in cm
00150   //                     if >=0 it is ignored and the program
00151   //                     calculates it, if <0. -radl is taken
00152   //  buf                pointer to an array of user words
00153   //  nbuf               number of user words
00154   //
00155 
00156    Double_t* dbuf = CreateDoubleArray(buf, nwbuf);
00157    Material(kmat, name, a, z, dens, radl, absl, dbuf, nwbuf);
00158    delete [] dbuf;
00159 }
00160 
00161 //_____________________________________________________________________________
00162 void TGeoMCGeometry::Material(Int_t& kmat, const char* name, Double_t a, Double_t z,
00163                      Double_t dens, Double_t radl, Double_t absl, Double_t* /*buf*/,
00164                      Int_t /*nwbuf*/)
00165 {
00166   //
00167   // Defines a Material
00168   //
00169   //  kmat               number assigned to the material
00170   //  name               material name
00171   //  a                  atomic mass in au
00172   //  z                  atomic number
00173   //  dens               density in g/cm3
00174   //  absl               absorbtion length in cm
00175   //                     if >=0 it is ignored and the program
00176   //                     calculates it, if <0. -absl is taken
00177   //  radl               radiation length in cm
00178   //                     if >=0 it is ignored and the program
00179   //                     calculates it, if <0. -radl is taken
00180   //  buf                pointer to an array of user words
00181   //  nbuf               number of user words
00182   //
00183 
00184    GetTGeoManager()->Material(name, a, z, dens, kmat, radl, absl);
00185 }
00186 
00187 //_____________________________________________________________________________
00188 void TGeoMCGeometry::Mixture(Int_t& kmat, const char* name, Float_t* a, Float_t* z,
00189                     Double_t dens, Int_t nlmat, Float_t* wmat)
00190 {
00191   //
00192   // Defines mixture OR COMPOUND IMAT as composed by
00193   // THE BASIC NLMAT materials defined by arrays A,Z and WMAT
00194   //
00195   // If NLMAT > 0 then wmat contains the proportion by
00196   // weights of each basic material in the mixture.
00197   //
00198   // If nlmat < 0 then WMAT contains the number of atoms
00199   // of a given kind into the molecule of the COMPOUND
00200   // In this case, WMAT in output is changed to relative
00201   // weigths.
00202   //
00203 
00204    Double_t* da = CreateDoubleArray(a, TMath::Abs(nlmat));
00205    Double_t* dz = CreateDoubleArray(z, TMath::Abs(nlmat));
00206    Double_t* dwmat = CreateDoubleArray(wmat, TMath::Abs(nlmat));
00207 
00208    Mixture(kmat, name, da, dz, dens, nlmat, dwmat);
00209    for (Int_t i=0; i<nlmat; i++) {
00210       a[i] = da[i]; z[i] = dz[i]; wmat[i] = dwmat[i];
00211    }
00212 
00213    delete [] da;
00214    delete [] dz;
00215    delete [] dwmat;
00216 }
00217 
00218 //_____________________________________________________________________________
00219 void TGeoMCGeometry::Mixture(Int_t& kmat, const char* name, Double_t* a, Double_t* z,
00220                     Double_t dens, Int_t nlmat, Double_t* wmat)
00221 {
00222   //
00223   // Defines mixture OR COMPOUND IMAT as composed by
00224   // THE BASIC NLMAT materials defined by arrays A,Z and WMAT
00225   //
00226   // If NLMAT > 0 then wmat contains the proportion by
00227   // weights of each basic material in the mixture.
00228   //
00229   // If nlmat < 0 then WMAT contains the number of atoms
00230   // of a given kind into the molecule of the COMPOUND
00231   // In this case, WMAT in output is changed to relative
00232   // weigths.
00233   //
00234 
00235    if (nlmat < 0) {
00236       nlmat = - nlmat;
00237       Double_t amol = 0;
00238       Int_t i;
00239       for (i=0;i<nlmat;i++) {
00240          amol += a[i]*wmat[i];
00241       }
00242       for (i=0;i<nlmat;i++) {
00243          wmat[i] *= a[i]/amol;
00244       }
00245    }
00246    GetTGeoManager()->Mixture(name, a, z, dens, nlmat, wmat, kmat);
00247 }
00248 
00249 //_____________________________________________________________________________
00250 void TGeoMCGeometry::Medium(Int_t& kmed, const char* name, Int_t nmat, Int_t isvol,
00251                    Int_t ifield, Double_t fieldm, Double_t tmaxfd,
00252                    Double_t stemax, Double_t deemax, Double_t epsil,
00253                    Double_t stmin, Float_t* ubuf, Int_t nbuf)
00254 {
00255   //
00256   //  kmed      tracking medium number assigned
00257   //  name      tracking medium name
00258   //  nmat      material number
00259   //  isvol     sensitive volume flag
00260   //  ifield    magnetic field
00261   //  fieldm    max. field value (kilogauss)
00262   //  tmaxfd    max. angle due to field (deg/step)
00263   //  stemax    max. step allowed
00264   //  deemax    max. fraction of energy lost in a step
00265   //  epsil     tracking precision (cm)
00266   //  stmin     min. step due to continuous processes (cm)
00267   //
00268   //  ifield = 0 if no magnetic field; ifield = -1 if user decision in guswim;
00269   //  ifield = 1 if tracking performed with g3rkuta; ifield = 2 if tracking
00270   //  performed with g3helix; ifield = 3 if tracking performed with g3helx3.
00271   //
00272 
00273   //printf("Creating mediuma: %s, numed=%d, nmat=%d\n",name,kmed,nmat);
00274    Double_t* dubuf = CreateDoubleArray(ubuf, nbuf);
00275    Medium(kmed, name, nmat, isvol, ifield, fieldm, tmaxfd, stemax, deemax, epsil,
00276           stmin, dubuf, nbuf);
00277    delete [] dubuf;
00278 }
00279 
00280 //_____________________________________________________________________________
00281 void TGeoMCGeometry::Medium(Int_t& kmed, const char* name, Int_t nmat, Int_t isvol,
00282                    Int_t ifield, Double_t fieldm, Double_t tmaxfd,
00283                    Double_t stemax, Double_t deemax, Double_t epsil,
00284                    Double_t stmin, Double_t* /*ubuf*/, Int_t /*nbuf*/)
00285 {
00286   //
00287   //  kmed      tracking medium number assigned
00288   //  name      tracking medium name
00289   //  nmat      material number
00290   //  isvol     sensitive volume flag
00291   //  ifield    magnetic field
00292   //  fieldm    max. field value (kilogauss)
00293   //  tmaxfd    max. angle due to field (deg/step)
00294   //  stemax    max. step allowed
00295   //  deemax    max. fraction of energy lost in a step
00296   //  epsil     tracking precision (cm)
00297   //  stmin     min. step due to continuos processes (cm)
00298   //
00299   //  ifield = 0 if no magnetic field; ifield = -1 if user decision in guswim;
00300   //  ifield = 1 if tracking performed with g3rkuta; ifield = 2 if tracking
00301   //  performed with g3helix; ifield = 3 if tracking performed with g3helx3.
00302   //
00303 
00304    GetTGeoManager()->Medium(name,kmed,nmat, isvol, ifield, fieldm, tmaxfd, stemax,deemax, epsil, stmin);
00305 }
00306 
00307 //_____________________________________________________________________________
00308 void TGeoMCGeometry::Matrix(Int_t& krot, Double_t thex, Double_t phix, Double_t they,
00309                    Double_t phiy, Double_t thez, Double_t phiz)
00310 {
00311   //
00312   //  krot     rotation matrix number assigned
00313   //  theta1   polar angle for axis i
00314   //  phi1     azimuthal angle for axis i
00315   //  theta2   polar angle for axis ii
00316   //  phi2     azimuthal angle for axis ii
00317   //  theta3   polar angle for axis iii
00318   //  phi3     azimuthal angle for axis iii
00319   //
00320   //  it defines the rotation matrix number irot.
00321   //
00322 
00323    krot = GetTGeoManager()->GetListOfMatrices()->GetEntriesFast();
00324    GetTGeoManager()->Matrix(krot, thex, phix, they, phiy, thez, phiz);
00325 }
00326 
00327 //_____________________________________________________________________________
00328 Int_t TGeoMCGeometry::Gsvolu(const char *name, const char *shape, Int_t nmed,
00329                     Float_t *upar, Int_t npar)
00330 {
00331   //
00332   //  NAME   Volume name
00333   //  SHAPE  Volume type
00334   //  NUMED  Tracking medium number
00335   //  NPAR   Number of shape parameters
00336   //  UPAR   Vector containing shape parameters
00337   //
00338   //  It creates a new volume in the JVOLUM data structure.
00339   //
00340 
00341    Double_t* dupar = CreateDoubleArray(upar, npar);
00342    Int_t id = Gsvolu(name, shape, nmed, dupar, npar);
00343    delete [] dupar;
00344    return id;
00345 }
00346 
00347 //_____________________________________________________________________________
00348 Int_t TGeoMCGeometry::Gsvolu(const char *name, const char *shape, Int_t nmed,
00349                     Double_t *upar, Int_t npar)
00350 {
00351   //
00352   //  NAME   Volume name
00353   //  SHAPE  Volume type
00354   //  NUMED  Tracking medium number
00355   //  NPAR   Number of shape parameters
00356   //  UPAR   Vector containing shape parameters
00357   //
00358   //  It creates a new volume in the JVOLUM data structure.
00359   //
00360 
00361    char vname[80];
00362    Vname(name,vname);
00363    char vshape[5];
00364    Vname(shape,vshape);
00365 
00366    TGeoVolume* vol = GetTGeoManager()->Volume(vname, vshape, nmed, upar, npar);
00367    return vol->GetNumber();
00368 }
00369 
00370 //_____________________________________________________________________________
00371 void  TGeoMCGeometry::Gsdvn(const char *name, const char *mother, Int_t ndiv,
00372                    Int_t iaxis)
00373 {
00374   //
00375   // Create a new volume by dividing an existing one
00376   //
00377   //  NAME   Volume name
00378   //  MOTHER Mother volume name
00379   //  NDIV   Number of divisions
00380   //  IAXIS  Axis value
00381   //
00382   //  X,Y,Z of CAXIS will be translated to 1,2,3 for IAXIS.
00383   //  It divides a previously defined volume.
00384   //
00385    char vname[80];
00386    Vname(name,vname);
00387    char vmother[80];
00388    Vname(mother,vmother);
00389 
00390    GetTGeoManager()->Division(vname, vmother, iaxis, ndiv, 0, 0, 0, "n");
00391 }
00392 
00393 //_____________________________________________________________________________
00394 void  TGeoMCGeometry::Gsdvn2(const char *name, const char *mother, Int_t ndiv,
00395                     Int_t iaxis, Double_t c0i, Int_t numed)
00396 {
00397   //
00398   // Create a new volume by dividing an existing one
00399   //
00400   // Divides mother into ndiv divisions called name
00401   // along axis iaxis starting at coordinate value c0.
00402   // the new volume created will be medium number numed.
00403   //
00404    char vname[80];
00405    Vname(name,vname);
00406    char vmother[80];
00407    Vname(mother,vmother);
00408 
00409    GetTGeoManager()->Division(vname, vmother, iaxis, ndiv, c0i, 0, numed, "nx");
00410 }
00411 //_____________________________________________________________________________
00412 void  TGeoMCGeometry::Gsdvt(const char *name, const char *mother, Double_t step,
00413                    Int_t iaxis, Int_t numed, Int_t /*ndvmx*/)
00414 {
00415   //
00416   // Create a new volume by dividing an existing one
00417   //
00418   //       Divides MOTHER into divisions called NAME along
00419   //       axis IAXIS in steps of STEP. If not exactly divisible
00420   //       will make as many as possible and will centre them
00421   //       with respect to the mother. Divisions will have medium
00422   //       number NUMED. If NUMED is 0, NUMED of MOTHER is taken.
00423   //       NDVMX is the expected maximum number of divisions
00424   //          (If 0, no protection tests are performed)
00425   //
00426    char vname[80];
00427    Vname(name,vname);
00428    char vmother[80];
00429    Vname(mother,vmother);
00430 
00431    GetTGeoManager()->Division(vname, vmother, iaxis, 0, 0, step, numed, "s");
00432 }
00433 
00434 //_____________________________________________________________________________
00435 void  TGeoMCGeometry::Gsdvt2(const char *name, const char *mother, Double_t step,
00436                     Int_t iaxis, Double_t c0, Int_t numed, Int_t /*ndvmx*/)
00437 {
00438   //
00439   // Create a new volume by dividing an existing one
00440   //
00441   //           Divides MOTHER into divisions called NAME along
00442   //            axis IAXIS starting at coordinate value C0 with step
00443   //            size STEP.
00444   //           The new volume created will have medium number NUMED.
00445   //           If NUMED is 0, NUMED of mother is taken.
00446   //           NDVMX is the expected maximum number of divisions
00447   //             (If 0, no protection tests are performed)
00448   //
00449    char vname[80];
00450    Vname(name,vname);
00451    char vmother[80];
00452    Vname(mother,vmother);
00453 
00454    GetTGeoManager()->Division(vname, vmother, iaxis, 0, c0, step, numed, "sx");
00455 }
00456 
00457 //_____________________________________________________________________________
00458 void  TGeoMCGeometry::Gsord(const char * /*name*/, Int_t /*iax*/)
00459 {
00460   //
00461   //    Flags volume CHNAME whose contents will have to be ordered
00462   //    along axis IAX, by setting the search flag to -IAX
00463   //           IAX = 1    X axis
00464   //           IAX = 2    Y axis
00465   //           IAX = 3    Z axis
00466   //           IAX = 4    Rxy (static ordering only  -> GTMEDI)
00467   //           IAX = 14   Rxy (also dynamic ordering -> GTNEXT)
00468   //           IAX = 5    Rxyz (static ordering only -> GTMEDI)
00469   //           IAX = 15   Rxyz (also dynamic ordering -> GTNEXT)
00470   //           IAX = 6    PHI   (PHI=0 => X axis)
00471   //           IAX = 7    THETA (THETA=0 => Z axis)
00472   //
00473 
00474   // TBC - keep this function
00475   // nothing to be done for TGeo  //xx
00476 }
00477 
00478 //_____________________________________________________________________________
00479 void  TGeoMCGeometry::Gspos(const char *name, Int_t nr, const char *mother, Double_t x,
00480                    Double_t y, Double_t z, Int_t irot, const char *konly)
00481 {
00482   //
00483   // Position a volume into an existing one
00484   //
00485   //  NAME   Volume name
00486   //  NUMBER Copy number of the volume
00487   //  MOTHER Mother volume name
00488   //  X      X coord. of the volume in mother ref. sys.
00489   //  Y      Y coord. of the volume in mother ref. sys.
00490   //  Z      Z coord. of the volume in mother ref. sys.
00491   //  IROT   Rotation matrix number w.r.t. mother ref. sys.
00492   //  ONLY   ONLY/MANY flag
00493   //
00494   //  It positions a previously defined volume in the mother.
00495   //
00496 
00497    TString only = konly;
00498    only.ToLower();
00499    Bool_t isOnly = kFALSE;
00500    if (only.Contains("only")) isOnly = kTRUE;
00501    char vname[80];
00502    Vname(name,vname);
00503    char vmother[80];
00504    Vname(mother,vmother);
00505 
00506    Double_t *upar=0;
00507    GetTGeoManager()->Node(vname, nr, vmother, x, y, z, irot, isOnly, upar);
00508 }
00509 
00510 //_____________________________________________________________________________
00511 void  TGeoMCGeometry::Gsposp(const char *name, Int_t nr, const char *mother,
00512                     Double_t x, Double_t y, Double_t z, Int_t irot,
00513                     const char *konly, Float_t *upar, Int_t np )
00514 {
00515   //
00516   //      Place a copy of generic volume NAME with user number
00517   //      NR inside MOTHER, with its parameters UPAR(1..NP)
00518   //
00519 
00520    Double_t* dupar = CreateDoubleArray(upar, np);
00521    Gsposp(name, nr, mother, x, y, z, irot, konly, dupar, np);
00522    delete [] dupar;
00523 }
00524 
00525 //_____________________________________________________________________________
00526 void  TGeoMCGeometry::Gsposp(const char *name, Int_t nr, const char *mother,
00527                     Double_t x, Double_t y, Double_t z, Int_t irot,
00528                     const char *konly, Double_t *upar, Int_t np )
00529 {
00530   //
00531   //      Place a copy of generic volume NAME with user number
00532   //      NR inside MOTHER, with its parameters UPAR(1..NP)
00533   //
00534 
00535    TString only = konly;
00536    only.ToLower();
00537    Bool_t isOnly = kFALSE;
00538    if (only.Contains("only")) isOnly = kTRUE;
00539    char vname[80];
00540    Vname(name,vname);
00541    char vmother[80];
00542    Vname(mother,vmother);
00543 
00544    GetTGeoManager()->Node(vname,nr,vmother, x,y,z,irot,isOnly,upar,np);
00545 }
00546 
00547 //_____________________________________________________________________________
00548 Int_t TGeoMCGeometry::VolId(const char *name) const
00549 {
00550   //
00551   // Return the unique numeric identifier for volume name
00552   //
00553 
00554    Int_t uid = GetTGeoManager()->GetUID(name);
00555    if (uid<0) {
00556       printf("VolId: Volume %s not found\n",name);
00557       return 0;
00558    }
00559    return uid;
00560 }
00561 
00562 //_____________________________________________________________________________
00563 Int_t TGeoMCGeometry::MediumId(const char *name) const
00564 {
00565   //
00566   // Return the unique numeric identifier for medium name
00567   //
00568 
00569    TGeoMedium* medium = GetTGeoManager()->GetMedium(name);
00570    if (medium) return medium->GetId();
00571 
00572    printf("MediumId: Medium %s not found\n",name);
00573    return 0;
00574 }
00575 
00576 //_____________________________________________________________________________
00577 const char* TGeoMCGeometry::VolName(Int_t id) const
00578 {
00579   //
00580   // Return the volume name given the volume identifier
00581   //
00582 
00583    TGeoVolume *volume = GetTGeoManager()->GetVolume(id);
00584    if (!volume) {
00585       Error("VolName","volume with id=%d does not exist",id);
00586       return "NULL";
00587    }
00588    return volume->GetName();
00589 }
00590 
00591 //_____________________________________________________________________________
00592 Int_t TGeoMCGeometry::NofVolumes() const
00593 {
00594   //
00595   // Return total number of volumes in the geometry
00596   //
00597 
00598    return GetTGeoManager()->GetListOfUVolumes()->GetEntriesFast()-1;
00599 }
00600 
00601 //_____________________________________________________________________________
00602 Int_t TGeoMCGeometry::NofVolDaughters(const char* volName) const
00603 {
00604 // Return number of daughters of the volume specified by volName
00605 // According to A. Morsch' G3toRoot class (by A. Morsch)
00606 // ---
00607 
00608    TGeoVolume* volume = GetTGeoManager()->GetVolume(volName);
00609 
00610    if (!volume) {
00611       Error("NofVolDaughters", "Volume %s not found.", volName);
00612       return 0;
00613    }
00614 
00615    return volume->GetNdaughters();
00616 }
00617 
00618 //_____________________________________________________________________________
00619 const char*  TGeoMCGeometry::VolDaughterName(const char* volName, Int_t i) const
00620 {
00621 // Return the name of i-th daughters of the volume specified by volName
00622 // According to A. Morsch' G3toRoot class.
00623 // ---
00624 
00625    // Get volume
00626    TGeoVolume* volume = GetTGeoManager()->GetVolume(volName);
00627    if (!volume) {
00628       Error("VolDaughterName", "Volume %s not found.", volName);
00629       return "";
00630    }
00631 
00632    // Check index
00633    if (i<0 || i>=volume->GetNdaughters()) {
00634       Error("VolDaughterName", "Volume %s Index out of limits", volName);
00635       return "";
00636    }
00637 
00638    // Return node's volume name
00639    return volume->GetNode(i)->GetVolume()->GetName();
00640 }
00641 
00642 //_____________________________________________________________________________
00643 Int_t TGeoMCGeometry::VolDaughterCopyNo(const char* volName, Int_t i) const
00644 {
00645 // Return the copyNo of i-th daughters of the volume specified by volName
00646 // According to A. Morsch' G3toRoot class.
00647 // ---
00648 
00649 
00650    // Get volume
00651    TGeoVolume* volume = GetTGeoManager()->GetVolume(volName);
00652    if (!volume) {
00653       Error("VolDaughterName", "Volume %s not found.", volName);
00654       return 0;
00655    }
00656 
00657    // Check index
00658    if (i<0 || i>=volume->GetNdaughters()) {
00659       Error("VolDaughterName", "Volume %s Index out of limits", volName);
00660       return 0;
00661    }
00662 
00663    // Return node's copyNo
00664    return volume->GetNode(i)->GetNumber();
00665 }
00666 
00667 //_____________________________________________________________________________
00668 Int_t TGeoMCGeometry::VolId2Mate(Int_t id) const
00669 {
00670   //
00671   // Return material number for a given volume id
00672   //
00673 
00674    TGeoVolume *volume = GetTGeoManager()->GetVolume(id);
00675    if (!volume) {
00676       Error("VolId2Mate","volume with id=%d does not exist",id);
00677       return 0;
00678    }
00679    TGeoMedium *med = volume->GetMedium();
00680    if (!med) return 0;
00681    return med->GetId();
00682 }
00683 
00684 //______________________________________________________________________
00685 Bool_t TGeoMCGeometry::GetTransformation(const TString &volumePath,TGeoHMatrix &mat)
00686 {
00687     // Returns the Transformation matrix between the volume specified
00688     // by the path volumePath and the Top or mater volume. The format
00689     // of the path volumePath is as follows (assuming ALIC is the Top volume)
00690     // "/ALIC_1/DDIP_1/S05I_2/S05H_1/S05G_3". Here ALIC is the top most
00691     // or master volume which has only 1 instance of. Of all of the daughter
00692     // volumes of ALICE, DDIP volume copy #1 is indicated. Similarly for
00693     // the daughter volume of DDIP is S05I copy #2 and so on.
00694     // Inputs:
00695     //   TString& volumePath  The volume path to the specific volume
00696     //                        for which you want the matrix. Volume name
00697     //                        hierarchy is separated by "/" while the
00698     //                        copy number is appended using a "_".
00699     // Outputs:
00700     //  TGeoHMatrix &mat      A matrix with its values set to those
00701     //                        appropriate to the Local to Master transformation
00702     // Return:
00703     //   A logical value if kFALSE then an error occurred and no change to
00704     //   mat was made.
00705 
00706    // We have to preserve the modeler state
00707    GetTGeoManager()->PushPath();
00708    if (!GetTGeoManager()->cd(volumePath.Data())) {
00709       GetTGeoManager()->PopPath();
00710       return kFALSE;
00711    }
00712    mat = *GetTGeoManager()->GetCurrentMatrix();
00713    GetTGeoManager()->PopPath();
00714    return kTRUE;
00715 }
00716 //______________________________________________________________________
00717 Bool_t TGeoMCGeometry::GetShape(const TString &volumePath,TString &shapeType,
00718                          TArrayD &par)
00719 {
00720     // Returns the shape and its parameters for the volume specified
00721     // by volumeName.
00722     // Inputs:
00723     //   TString& volumeName  The volume name
00724     // Outputs:
00725     //   TString &shapeType   Shape type
00726     //   TArrayD &par         A TArrayD of parameters with all of the
00727     //                        parameters of the specified shape.
00728     // Return:
00729     //   A logical indicating whether there was an error in getting this
00730     //   information
00731    Int_t npar;
00732    GetTGeoManager()->PushPath();
00733    if (!GetTGeoManager()->cd(volumePath.Data())) {
00734       GetTGeoManager()->PopPath();
00735       return kFALSE;
00736    }
00737    TGeoVolume * vol = GetTGeoManager()->GetCurrentVolume();
00738    GetTGeoManager()->PopPath();
00739    if (!vol) return kFALSE;
00740    TGeoShape *shape = vol->GetShape();
00741    TClass *class_type = shape->IsA();
00742    if (class_type==TGeoBBox::Class()) {
00743       shapeType = "BOX";
00744       npar = 3;
00745       par.Set(npar);
00746       TGeoBBox *box = (TGeoBBox*)shape;
00747       par.AddAt(box->GetDX(),0);
00748       par.AddAt(box->GetDY(),1);
00749       par.AddAt(box->GetDZ(),2);
00750       return kTRUE;
00751    }
00752    if (class_type==TGeoTrd1::Class()) {
00753       shapeType = "TRD1";
00754       npar = 4;
00755       par.Set(npar);
00756       TGeoTrd1 *trd1 = (TGeoTrd1*)shape;
00757       par.AddAt(trd1->GetDx1(),0);
00758       par.AddAt(trd1->GetDx2(),1);
00759       par.AddAt(trd1->GetDy(), 2);
00760       par.AddAt(trd1->GetDz(), 3);
00761       return kTRUE;
00762    }
00763    if (class_type==TGeoTrd2::Class()) {
00764       shapeType = "TRD2";
00765       npar = 5;
00766       par.Set(npar);
00767       TGeoTrd2 *trd2 = (TGeoTrd2*)shape;
00768       par.AddAt(trd2->GetDx1(),0);
00769       par.AddAt(trd2->GetDx2(),1);
00770       par.AddAt(trd2->GetDy1(),2);
00771       par.AddAt(trd2->GetDy2(),3);
00772       par.AddAt(trd2->GetDz(), 4);
00773       return kTRUE;
00774    }
00775    if (class_type==TGeoTrap::Class()) {
00776       shapeType = "TRAP";
00777       npar = 11;
00778       par.Set(npar);
00779       TGeoTrap *trap = (TGeoTrap*)shape;
00780       Double_t tth = TMath::Tan(trap->GetTheta()*TMath::DegToRad());
00781       par.AddAt(trap->GetDz(),0);
00782       par.AddAt(tth*TMath::Cos(trap->GetPhi()*TMath::DegToRad()),1);
00783       par.AddAt(tth*TMath::Sin(trap->GetPhi()*TMath::DegToRad()),2);
00784       par.AddAt(trap->GetH1(),3);
00785       par.AddAt(trap->GetBl1(),4);
00786       par.AddAt(trap->GetTl1(),5);
00787       par.AddAt(TMath::Tan(trap->GetAlpha1()*TMath::DegToRad()),6);
00788       par.AddAt(trap->GetH2(),7);
00789       par.AddAt(trap->GetBl2(),8);
00790       par.AddAt(trap->GetTl2(),9);
00791       par.AddAt(TMath::Tan(trap->GetAlpha2()*TMath::DegToRad()),10);
00792       return kTRUE;
00793    }
00794    if (class_type==TGeoTube::Class()) {
00795       shapeType = "TUBE";
00796       npar = 3;
00797       par.Set(npar);
00798       TGeoTube *tube = (TGeoTube*)shape;
00799       par.AddAt(tube->GetRmin(),0);
00800       par.AddAt(tube->GetRmax(),1);
00801       par.AddAt(tube->GetDz(),2);
00802       return kTRUE;
00803    }
00804    if (class_type==TGeoTubeSeg::Class()) {
00805       shapeType = "TUBS";
00806       npar = 5;
00807       par.Set(npar);
00808       TGeoTubeSeg *tubs = (TGeoTubeSeg*)shape;
00809       par.AddAt(tubs->GetRmin(),0);
00810       par.AddAt(tubs->GetRmax(),1);
00811       par.AddAt(tubs->GetDz(),2);
00812       par.AddAt(tubs->GetPhi1(),3);
00813       par.AddAt(tubs->GetPhi2(),4);
00814       return kTRUE;
00815    }
00816    if (class_type==TGeoCone::Class()) {
00817       shapeType = "CONE";
00818       npar = 5;
00819       par.Set(npar);
00820       TGeoCone *cone = (TGeoCone*)shape;
00821       par.AddAt(cone->GetDz(),0);
00822       par.AddAt(cone->GetRmin1(),1);
00823       par.AddAt(cone->GetRmax1(),2);
00824       par.AddAt(cone->GetRmin2(),3);
00825       par.AddAt(cone->GetRmax2(),4);
00826       return kTRUE;
00827    }
00828    if (class_type==TGeoConeSeg::Class()) {
00829       shapeType = "CONS";
00830       npar = 7;
00831       par.Set(npar);
00832       TGeoConeSeg *cons = (TGeoConeSeg*)shape;
00833       par.AddAt(cons->GetDz(),0);
00834       par.AddAt(cons->GetRmin1(),1);
00835       par.AddAt(cons->GetRmax1(),2);
00836       par.AddAt(cons->GetRmin2(),3);
00837       par.AddAt(cons->GetRmax2(),4);
00838       par.AddAt(cons->GetPhi1(),5);
00839       par.AddAt(cons->GetPhi2(),6);
00840       return kTRUE;
00841    }
00842    if (class_type==TGeoSphere::Class()) {
00843       shapeType = "SPHE";
00844       npar = 6;
00845       par.Set(npar);
00846       TGeoSphere *sphe = (TGeoSphere*)shape;
00847       par.AddAt(sphe->GetRmin(),0);
00848       par.AddAt(sphe->GetRmax(),1);
00849       par.AddAt(sphe->GetTheta1(),2);
00850       par.AddAt(sphe->GetTheta2(),3);
00851       par.AddAt(sphe->GetPhi1(),4);
00852       par.AddAt(sphe->GetPhi2(),5);
00853       return kTRUE;
00854    }
00855    if (class_type==TGeoPara::Class()) {
00856       shapeType = "PARA";
00857       npar = 6;
00858       par.Set(npar);
00859       TGeoPara *para = (TGeoPara*)shape;
00860       par.AddAt(para->GetX(),0);
00861       par.AddAt(para->GetY(),1);
00862       par.AddAt(para->GetZ(),2);
00863       par.AddAt(para->GetTxy(),3);
00864       par.AddAt(para->GetTxz(),4);
00865       par.AddAt(para->GetTyz(),5);
00866       return kTRUE;
00867    }
00868    if (class_type==TGeoPgon::Class()) {
00869       shapeType = "PGON";
00870       TGeoPgon *pgon = (TGeoPgon*)shape;
00871       Int_t nz = pgon->GetNz();
00872       const Double_t *rmin = pgon->GetRmin();
00873       const Double_t *rmax = pgon->GetRmax();
00874       const Double_t *z = pgon->GetZ();
00875       npar = 4 + 3*nz;
00876       par.Set(npar);
00877       par.AddAt(pgon->GetPhi1(),0);
00878       par.AddAt(pgon->GetDphi(),1);
00879       par.AddAt(pgon->GetNedges(),2);
00880       par.AddAt(pgon->GetNz(),3);
00881       for (Int_t i=0; i<nz; i++) {
00882          par.AddAt(z[i], 4+3*i);
00883          par.AddAt(rmin[i], 4+3*i+1);
00884          par.AddAt(rmax[i], 4+3*i+2);
00885       }
00886       return kTRUE;
00887    }
00888    if (class_type==TGeoPcon::Class()) {
00889       shapeType = "PCON";
00890       TGeoPcon *pcon = (TGeoPcon*)shape;
00891       Int_t nz = pcon->GetNz();
00892       const Double_t *rmin = pcon->GetRmin();
00893       const Double_t *rmax = pcon->GetRmax();
00894       const Double_t *z = pcon->GetZ();
00895       npar = 3 + 3*nz;
00896       par.Set(npar);
00897       par.AddAt(pcon->GetPhi1(),0);
00898       par.AddAt(pcon->GetDphi(),1);
00899       par.AddAt(pcon->GetNz(),2);
00900       for (Int_t i=0; i<nz; i++) {
00901          par.AddAt(z[i], 3+3*i);
00902          par.AddAt(rmin[i], 3+3*i+1);
00903          par.AddAt(rmax[i], 3+3*i+2);
00904       }
00905       return kTRUE;
00906    }
00907    if (class_type==TGeoEltu::Class()) {
00908       shapeType = "ELTU";
00909       npar = 3;
00910       par.Set(npar);
00911       TGeoEltu *eltu = (TGeoEltu*)shape;
00912       par.AddAt(eltu->GetA(),0);
00913       par.AddAt(eltu->GetB(),1);
00914       par.AddAt(eltu->GetDz(),2);
00915       return kTRUE;
00916    }
00917    if (class_type==TGeoHype::Class()) {
00918       shapeType = "HYPE";
00919       npar = 5;
00920       par.Set(npar);
00921       TGeoHype *hype = (TGeoHype*)shape;
00922       par.AddAt(TMath::Sqrt(hype->RadiusHypeSq(0.,kTRUE)),0);
00923       par.AddAt(TMath::Sqrt(hype->RadiusHypeSq(0.,kFALSE)),1);
00924       par.AddAt(hype->GetDZ(),2);
00925       par.AddAt(hype->GetStIn(),3);
00926       par.AddAt(hype->GetStOut(),4);
00927       return kTRUE;
00928    }
00929    if (class_type==TGeoGtra::Class()) {
00930       shapeType = "GTRA";
00931       npar = 12;
00932       par.Set(npar);
00933       TGeoGtra *trap = (TGeoGtra*)shape;
00934       Double_t tth = TMath::Tan(trap->GetTheta()*TMath::DegToRad());
00935       par.AddAt(trap->GetDz(),0);
00936       par.AddAt(tth*TMath::Cos(trap->GetPhi()*TMath::DegToRad()),1);
00937       par.AddAt(tth*TMath::Sin(trap->GetPhi()*TMath::DegToRad()),2);
00938       par.AddAt(trap->GetH1(),3);
00939       par.AddAt(trap->GetBl1(),4);
00940       par.AddAt(trap->GetTl1(),5);
00941       par.AddAt(TMath::Tan(trap->GetAlpha1()*TMath::DegToRad()),6);
00942       par.AddAt(trap->GetH2(),7);
00943       par.AddAt(trap->GetBl2(),8);
00944       par.AddAt(trap->GetTl2(),9);
00945       par.AddAt(TMath::Tan(trap->GetAlpha2()*TMath::DegToRad()),10);
00946       par.AddAt(trap->GetTwistAngle(),11);
00947       return kTRUE;
00948    }
00949    if (class_type==TGeoCtub::Class()) {
00950       shapeType = "CTUB";
00951       npar = 11;
00952       par.Set(npar);
00953       TGeoCtub *ctub = (TGeoCtub*)shape;
00954       const Double_t *lx = ctub->GetNlow();
00955       const Double_t *tx = ctub->GetNhigh();
00956       par.AddAt(ctub->GetRmin(),0);
00957       par.AddAt(ctub->GetRmax(),1);
00958       par.AddAt(ctub->GetDz(),2);
00959       par.AddAt(ctub->GetPhi1(),3);
00960       par.AddAt(ctub->GetPhi2(),4);
00961       par.AddAt(lx[0],5);
00962       par.AddAt(lx[1],6);
00963       par.AddAt(lx[2],7);
00964       par.AddAt(tx[0],8);
00965       par.AddAt(tx[1],9);
00966       par.AddAt(tx[2],10);
00967       return kTRUE;
00968 
00969    }
00970    Error("GetShape","Getting shape parameters for shape %s not implemented", shape->ClassName());
00971    return kFALSE;
00972 }
00973 
00974 //______________________________________________________________________
00975 Bool_t TGeoMCGeometry::GetMaterial(const TString &volumeName,
00976                             TString &name,Int_t &imat,
00977                             Double_t &a,Double_t &z,Double_t &dens,
00978                             Double_t &radl,Double_t &inter,TArrayD &par)
00979 {
00980     // Returns the Material and its parameters for the volume specified
00981     // by volumeName.
00982     // Note, Geant3 stores and uses mixtures as an element with an effective
00983     // Z and A. Consequently, if the parameter Z is not integer, then
00984     // this material represents some sort of mixture.
00985     // Inputs:
00986     //   TString& volumeName  The volume name
00987     // Outputs:
00988     //   TSrting   &name       Material name
00989     //   Int_t     &imat       Material index number
00990     //   Double_t  &a          Average Atomic mass of material
00991     //   Double_t  &z          Average Atomic number of material
00992     //   Double_t  &dens       Density of material [g/cm^3]
00993     //   Double_t  &radl       Average radiation length of material [cm]
00994     //   Double_t  &inter      Average interaction length of material [cm]
00995     //   TArrayD   &par        A TArrayD of user defined parameters.
00996     // Return:
00997     //   kTRUE if no errors
00998    TGeoVolume *vol = GetTGeoManager()->GetVolume(volumeName.Data());
00999    if (!vol) return kFALSE;
01000    TGeoMedium *med = vol->GetMedium();
01001    if (!med) return kFALSE;
01002    TGeoMaterial *mat = med->GetMaterial();
01003    imat = mat->GetUniqueID();
01004    name = mat->GetName();
01005    name = name.Strip(TString::kTrailing, '$');
01006    a      = mat->GetA();
01007    z      = mat->GetZ();
01008    dens   = mat->GetDensity();
01009    radl   = mat->GetRadLen();
01010    inter  = mat->GetIntLen(); // WARNING: THIS IS NOT COMPUTED NATIVELY BY TGEO
01011    par.Set(0); // NO USER PARAMETERS STORED IN TGEO
01012    return kTRUE;
01013 }
01014 
01015 //______________________________________________________________________
01016 Bool_t TGeoMCGeometry::GetMedium(const TString &volumeName,TString &name,
01017                           Int_t &imed,Int_t &nmat,Int_t &isvol,Int_t &ifield,
01018                           Double_t &fieldm,Double_t &tmaxfd,Double_t &stemax,
01019                           Double_t &deemax,Double_t &epsil, Double_t &stmin,
01020                           TArrayD &par)
01021 {
01022     // Returns the Medium and its parameters for the volume specified
01023     // by volumeName.
01024     // Inputs:
01025     //   TString& volumeName  The volume name.
01026     // Outputs:
01027     //   TString  &name       Medium name
01028     //   Int_t    &nmat       Material number defined for this medium
01029     //   Int_t    &imed       The medium index number
01030     //   Int_t    &isvol      volume number defined for this medium
01031     //   Int_t    &iflield    Magnetic field flag
01032     //   Double_t &fieldm     Magnetic field strength
01033     //   Double_t &tmaxfd     Maximum angle of deflection per step
01034     //   Double_t &stemax     Maximum step size
01035     //   Double_t &deemax     Maximum fraction of energy allowed to be lost
01036     //                        to continuous process.
01037     //   Double_t &epsil      Boundary crossing precision
01038     //   Double_t &stmin      Minimum step size allowed
01039     //   TArrayD  &par        A TArrayD of user parameters with all of the
01040     //                        parameters of the specified medium.
01041     // Return:
01042     //   kTRUE if there where no errors
01043    TGeoVolume *vol = GetTGeoManager()->GetVolume(volumeName.Data());
01044    if (!vol) return kFALSE;
01045    TGeoMedium *med = vol->GetMedium();
01046    if (!med) return kFALSE;
01047    TGeoMaterial *mat = med->GetMaterial();
01048    nmat = mat->GetUniqueID();
01049    imed = med->GetId();
01050    name = med->GetName();
01051    name = name.Strip(TString::kTrailing, '$');
01052    par.Set(0); // NO USER PARAMETERS IN TGEO
01053    isvol  = (Int_t)med->GetParam(0);
01054    ifield = (Int_t)med->GetParam(1);
01055    fieldm = med->GetParam(2);
01056    tmaxfd = med->GetParam(3);
01057    stemax = med->GetParam(4);
01058    deemax = med->GetParam(5);
01059    epsil  = med->GetParam(6);
01060    stmin  = med->GetParam(7);
01061    return kTRUE;
01062 }
01063 

Generated on Tue Jul 5 14:45:27 2011 for ROOT_528-00b_version by  doxygen 1.5.1