Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

G3Volume.cxx

Go to the documentation of this file.
00001 /* *************************************************************************
00002  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
00003  *                                                                        *
00004  * Author: The ALICE Off-line Project.                                    *
00005  * Contributors are mentioned in the code where appropriate.              *
00006  *                                                                        *
00007  * Permission to use, copy, modify and distribute this software and its   *
00008  * documentation strictly for non-commercial purposes is hereby granted   *
00009  * without fee, provided that the above copyright notice appears in all   *
00010  * copies and that both the copyright notice and this permission notice   *
00011  * appear in the supporting documentation. The authors make no claims     *
00012  * about the suitability of this software for any purpose. It is          *
00013  * provided "as is" without express or implied warranty.                  *
00014  **************************************************************************/
00015 
00016 /*
00017 Revision 1.4  2005/07/21 17:50:46  brun
00018 From Frederico
00019 Use MakeCopy instead of Copy
00020 
00021 Revision 1.3  2004/01/28 08:17:52  brun
00022 Reintroduce the Geant3 graphics classes (thanks Andreas Morsch)
00023 
00024 Revision 1.1.1.1  2002/07/24 15:56:26  rdm
00025 initial import into CVS
00026 
00027 */
00028 
00029 //
00030 // G3 Volume Class for the G3 GUI
00031 // Author: Andreas Morsch
00032 // andreas.morsch@cern.ch
00033 //
00034 
00035 
00036 
00037 
00038 #include "G3Volume.h"
00039 #include <TArrayF.h>
00040 #include "TMaterial.h"
00041 #include "TShape.h"
00042 #include "TTUBE.h"
00043 #include "TBRIK.h"
00044 #include "TTRD1.h"
00045 #include "TTRD2.h"
00046 #include "TTRAP.h"
00047 #include "TTUBS.h"
00048 #include "TCONE.h"
00049 #include "TCONS.h"
00050 #include "TSPHE.h"
00051 #include "TPARA.h"
00052 #include "TPGON.h"
00053 #include "TPCON.h"
00054 #include "TTUBS.h"
00055 #include "TELTU.h"
00056 #include "THYPE.h"
00057 #include "TGTRA.h"
00058 #include "TCTUB.h"
00059 
00060 ClassImp(G3Volume)
00061 
00062     G3Volume::G3Volume(const char* name) 
00063         : TNamed(name, " ")
00064 {
00065 // Constructor
00066 
00067     fTheta  = 30;
00068     fPhi    = 30;
00069     fPsi    = 0;
00070     fU      = 10;
00071     fV      = 10;
00072     fUscale = 0.01;
00073     fVscale = 0.01;
00074     fHide=0;
00075     fShadow=0;
00076     fFill=1;
00077     fSeen=1;
00078     fClip=0;
00079     fClipXmin=0.;
00080     fClipXmax=2000.;
00081     fClipYmin=0.;
00082     fClipYmax=2000.;
00083     fClipZmin=0.;
00084     fClipZmax=2000.;
00085     fNParam = 0;
00086     fPosition.Set(3);
00087     fCopies = new TList;
00088     fNCopies = 0;
00089     fPosp = kFALSE;
00090     fAxis = -1;
00091 }
00092 
00093 G3Volume::G3Volume(const G3Volume& volume)
00094     : TNamed(volume)
00095 {
00096 // Constructor
00097 
00098     fTheta  = 30;
00099     fPhi    = 30;
00100     fPsi    = 0;
00101     fU      = 10;
00102     fV      = 10;
00103     fUscale = 0.01;
00104     fVscale = 0.01;
00105     fHide=0;
00106     fShadow=0;
00107     fFill=1;
00108     fSeen=1;
00109     fClip=0;
00110     fClipXmin=0.;
00111     fClipXmax=2000.;
00112     fClipYmin=0.;
00113     fClipYmax=2000.;
00114     fClipZmin=0.;
00115     fClipZmax=2000.;
00116     fAxis = -1;
00117 //
00118     fIdVolume   = volume.GetIdVolume();
00119     fIdCopy     = volume.GetIdCopy();
00120     fIdMedium   = volume.Medium();
00121     fIdMaterial = volume.Material();
00122     fPosition   = volume.Position(0);
00123     fShape      = volume.Shape();
00124     fRotMatrix  = volume.RotMatrix();
00125     TArrayF par;
00126     volume.Parameters(0, fParameters);
00127     fNCopies    = volume.NCopies();
00128     fPosp       = volume.Posp();
00129     
00130     fNParam     = volume.NParam();
00131     fCopies     = volume.Copies();
00132     fRotMatrix  = volume.RotMatrix();
00133     volume.Division(fNdiv, fAxis, fStartC, fStep);
00134     
00135 }
00136 
00137 
00138 
00139 
00140 void G3Volume::Draw(Option_t *)
00141 {
00142 // Wraps the geant Gdraw
00143     gMC->Gsatt(fName,"seen", fSeen);
00144     
00145     if (fHide) {
00146         gMC->Gdopt("hide", "on");
00147     } else {
00148         gMC->Gdopt("hide", "off");
00149     }
00150 
00151     if (fShadow) {
00152         gMC->Gdopt("shad", "on");
00153         gMC->Gsatt("*", "fill", fFill);
00154     } else {
00155         gMC->Gdopt("shad", "off");
00156     }
00157 
00158         gMC->SetClipBox(".");
00159     if (fClip) {
00160         gMC->SetClipBox("*", fClipXmin, fClipXmax, 
00161                         fClipYmin, fClipYmax, fClipZmin, fClipZmax);
00162     } else {
00163         gMC->SetClipBox(".");
00164     }
00165     
00166 
00167     gMC->Gdraw(fName, fTheta, fPhi, fPsi, fU, fV, fUscale, fVscale);
00168 }
00169 
00170 void G3Volume::DrawSpec()
00171 {
00172 // Wraps the Geant DrawSpec
00173     gMC->Gsatt(fName,"seen", fSeen);
00174     
00175     if (fHide) {
00176         gMC->Gdopt("hide", "on");
00177     } else {
00178         gMC->Gdopt("hide", "off");
00179     }
00180 
00181     if (fShadow) {
00182         gMC->Gdopt("shad", "on");
00183         gMC->Gsatt("*", "fill", fFill);
00184     } else {
00185         gMC->Gdopt("shad", "off");
00186     }
00187 
00188     gMC->SetClipBox(".");
00189     if (fClip) {
00190         gMC->SetClipBox("*", fClipXmin, fClipXmax, fClipYmin, fClipYmax, fClipZmin, fClipZmax);
00191     } else {
00192         gMC->SetClipBox(".");
00193     }
00194     
00195 
00196     ((TGeant3*) gMC)->DrawOneSpec(fName);
00197 }
00198 
00199 void G3Volume::SetParam(Int_t ip, Float_t param)
00200 {
00201 // Set drawing parameters
00202     switch (ip) {
00203     case kTheta:
00204         fTheta=param;
00205         break;
00206     case kPhi:
00207         fPhi=param;
00208         break;
00209     case kPsi:
00210         fPsi=param;
00211         break;
00212     case kU:
00213         fU=param;
00214         break;
00215     case kV:
00216         fV=param;
00217         break;
00218     case kUscale:
00219         fUscale=param;
00220         break;
00221     case kVscale:
00222         fVscale=param;
00223         break;
00224     case kHide:
00225         fHide=Int_t(param);
00226         break;
00227     case kShadow:
00228         fShadow=Int_t(param);
00229         break;
00230     case kFill:
00231         fFill=Int_t(param);
00232         break;
00233     case kSeen:
00234         fSeen=Int_t(param);
00235         break;
00236     case kClip:
00237         fClip=Int_t(param);
00238         break;
00239     case kClipXmin:
00240         fClipXmin=param;
00241         break;
00242     case kClipXmax:
00243         fClipXmax=param;
00244         break;
00245     case kClipYmin:
00246         fClipYmin=param;
00247         break;
00248     case kClipYmax:
00249         fClipYmax=param;
00250         break;
00251     case kClipZmin:
00252         fClipZmin=param;
00253         break;
00254     case kClipZmax:
00255         fClipZmax=param;
00256         break;
00257     }
00258 }
00259 
00260 Float_t  G3Volume::GetParam(Int_t ip)
00261 {
00262 // Get drawing parameters
00263     switch (ip) {
00264     case kTheta:
00265         return fTheta;
00266     case kPhi:
00267         return fPhi;
00268     case kPsi:
00269         return fPsi;
00270     case kU:
00271         return fU;
00272     case kV:
00273         return fV;
00274     case kUscale:
00275         return fUscale;
00276     case kVscale:
00277         return fVscale;
00278     case kHide:
00279         return Float_t(fHide);
00280     case kShadow:
00281         return Float_t(fShadow);
00282     case kFill:
00283         return Float_t(fFill);
00284     case kSeen:
00285         return Float_t(fSeen);
00286     case kClip:
00287         return Float_t(fClip);
00288     case kClipXmin:
00289         return fClipXmin;
00290     case kClipXmax:
00291         return fClipXmax;
00292     case kClipYmin:
00293         return fClipYmin;
00294     case kClipYmax:
00295         return fClipYmax;
00296     case kClipZmin:
00297         return fClipZmin;
00298     case kClipZmax:
00299         return fClipZmax;
00300     default:
00301         return 0.;
00302     }
00303     return 0.;
00304 }
00305 
00306 void  G3Volume::AddCopy(G3Volume* volume)
00307 {
00308     volume->SetIdMaterial(Material());
00309     fCopies->Add(volume);
00310     fNCopies++;
00311 }
00312 
00313 G3Volume* G3Volume::MakeCopy(Int_t i)
00314 {
00315     return (G3Volume*) fCopies->At(i);
00316 }
00317 
00318 
00319 TArrayF G3Volume::Position(Int_t i) const
00320 {
00321 //
00322 // Get position for volume copy i 
00323 //
00324     if (i==0) {
00325         return fPosition;
00326     } else {
00327         return ((G3Volume*) fCopies->At(i-1))->Position(0);
00328     }
00329 }
00330 
00331 void G3Volume::SetPosition(Float_t x, Float_t y, Float_t z)
00332 {
00333 //
00334 // Set position
00335 //
00336   fPosition[0] = x;
00337   fPosition[1] = y;
00338   fPosition[2] = z;
00339 }
00340 
00341 
00342 void  G3Volume::SetParameters(Int_t np, Float_t* param) 
00343 {
00344 //
00345 // Set parameters 
00346 //
00347     fParameters.Set(np);
00348     for (Int_t j=0; j<np; j++) fParameters[j]=param[j];
00349     fNParam = np;
00350 }
00351     
00352 
00353 void  G3Volume::Parameters(Int_t i, TArrayF& param) const
00354 {
00355 //
00356 // Get parameters for volume copy i 
00357 //
00358     TArrayF p;
00359     if (i==0) {
00360         p = fParameters;
00361     } else {
00362         ((G3Volume*) (fCopies->At(i-1)))->Parameters(0, p);
00363     }
00364     Int_t np = fNParam;
00365     param.Set(np);
00366     for (Int_t j=0; j<np; j++) {
00367         param[j] = p.At(j);
00368     }
00369 }
00370     
00371 
00372 void G3Volume::CreateTShape(char* nameV, TMaterial* mat)
00373 {
00374 //
00375 // Create a root volume from G3 volume
00376 //
00377     Int_t   ip;
00378     
00379     Float_t kRadDeg = 180./TMath::Pi();
00380     Float_t theta, phi, alpha1, alpha2;
00381     Float_t p1, p2;
00382     
00383     TShape* nShape=0;
00384     const char* tmp = mat->GetName();
00385     char nameM[21];
00386     strncpy(nameM, tmp, 20);
00387     nameM[20]='\0';
00388     switch(fShape)
00389     {
00390     case 1:
00391 // BOX
00392         nShape = new TBRIK(nameV,"BRIK",nameM,fParameters[0], fParameters[1], fParameters[2]);
00393         break;
00394         
00395     case 2:
00396 // TRD1   
00397         nShape = new TTRD1(nameV, "TRD1", nameM, fParameters[0], fParameters[1], fParameters[2],
00398                            fParameters[3]);
00399         break;
00400         
00401     case 3:
00402 // TRD2
00403         nShape = new TTRD2(nameV, "TRD2", nameM, fParameters[0], fParameters[1], fParameters[2], 
00404                            fParameters[3], fParameters[4]);
00405         break;
00406         
00407     case 4:
00408 // TRAP
00409         p1     = fParameters[1];
00410         p2     = fParameters[2];
00411         
00412         theta  = TMath::ATan(TMath::Sqrt(p1*p1+p2*p2))*kRadDeg;
00413         phi    = TMath::ATan2(p2,p1)*kRadDeg;
00414         alpha1 = fParameters[6 ]*kRadDeg;
00415         alpha2 = fParameters[10]*kRadDeg;
00416 
00417         if (theta < 0.) theta+=180.;
00418         
00419         nShape =  new TTRAP(nameV, "TRAP", nameM, fParameters[0], 
00420                             theta, phi,
00421                             fParameters[3], fParameters[4], fParameters[5], 
00422                             alpha1, 
00423                             fParameters[7], fParameters[8], fParameters[9], 
00424                             alpha2);
00425         break;
00426         
00427     case 5:
00428 // TUBE
00429         nShape =  new TTUBE(nameV,"TUBE",nameM,fParameters[0], fParameters[1], fParameters[2]);
00430         break;
00431         
00432     case 6:
00433 // TUBS
00434         nShape =  new TTUBS(nameV,"TUBS",nameM,fParameters[0], fParameters[1], fParameters[2], 
00435                             fParameters[3], fParameters[4]);
00436         break;
00437         
00438     case 7:
00439 // CONE
00440         nShape =  new TCONE(nameV, "CONE", nameM, fParameters[0], fParameters[1], fParameters[2], 
00441                             fParameters[3], fParameters[4]);
00442         break;
00443         
00444     case 8:
00445         
00446 // CONS
00447         nShape =  new TCONS(nameV, "CONS", nameM, fParameters[0], fParameters[1], fParameters[2], 
00448                             fParameters[3], fParameters[4], fParameters[5], fParameters[6]);
00449         break;
00450         
00451     case 9:
00452 // SPHE
00453         
00454         nShape =  new TSPHE(nameV, "SPHE", nameM, fParameters[0], fParameters[1], fParameters[2], 
00455                             fParameters[3], fParameters[4], fParameters[5]);
00456         break;
00457         
00458     case 10:
00459 // PARA
00460         alpha1 = fParameters[3]*kRadDeg;
00461         p1     = fParameters[4];
00462         p2     = fParameters[5];
00463         theta  = TMath::ATan(TMath::Sqrt(p1*p1+p2*p2))*kRadDeg;
00464         phi    = TMath::ATan2(p2,p1)*kRadDeg;
00465 
00466         nShape =  new TPARA(nameV, "PARA", nameM, fParameters[0], fParameters[1], fParameters[2], 
00467                                     alpha1, theta, phi);
00468         break;
00469         
00470     case 11:
00471 // PGON
00472         nShape =  new TPGON(nameV, "PGON", nameM, fParameters[0], fParameters[1], Int_t(fParameters[2]), 
00473                             Int_t(fParameters[3]));
00474         for (ip=0; ip<Int_t(fParameters[3]); ip++) {
00475             ((TPGON*) nShape)->DefineSection(ip, fParameters[4+3*ip], fParameters[4+3*ip+1], 
00476                                              fParameters[4+3*ip+2]);
00477         }
00478         break;
00479         
00480     case 12:
00481 // PCON
00482         nShape = new TPCON(nameV, "PCON", nameM, fParameters[0], fParameters[1], Int_t(fParameters[2]));
00483         for (ip=0; ip<Int_t(fParameters[2]); ip++) {
00484             ((TPCON*) nShape)->DefineSection(ip, fParameters[3+3*ip], fParameters[3+3*ip+1], 
00485                                              fParameters[3+3*ip+2]);
00486         }
00487         break;
00488         
00489     case 13:
00490 // ELTU  
00491         nShape = new TELTU(nameV,"ELTU",nameM,fParameters[0], fParameters[1], fParameters[2]);
00492         break;
00493         
00494     case 14:
00495 // HYPE
00496         nShape = new THYPE(nameV,"HYPE",nameM,fParameters[0], fParameters[1], fParameters[2], 
00497                            fParameters[3]);
00498         break;
00499         
00500     case 15:
00501 // GTRA
00502         nShape = new TGTRA(nameV, "GTRA", nameM, fParameters[0], fParameters[1], fParameters[2], 
00503                            fParameters[3], fParameters[4], fParameters[5], fParameters[6], 
00504                            fParameters[7], fParameters[8], fParameters[9], fParameters[10], 
00505                            fParameters[11]);
00506         break;
00507         
00508     case 16:
00509 // CTUB
00510         nShape = new TCTUB(nameV, "CTUB", nameM, fParameters[0], fParameters[1], fParameters[2], 
00511                            fParameters[3], fParameters[4], fParameters[5], fParameters[6], 
00512                            fParameters[7], fParameters[8], fParameters[9], fParameters[10]);
00513         break;
00514     default:
00515         break;
00516     }
00517     if (nShape) {
00518         Float_t density = mat->GetDensity();
00519         if (density < 0.01) {
00520             nShape->SetVisibility(0);
00521         } else {
00522             nShape->SetVisibility(1);
00523         }
00524         
00525         Int_t color = Int_t(density/20.*100.);
00526         nShape->SetLineColor(color);
00527     }
00528 }
00529 
00530 void   G3Volume::SetDivision(Int_t ndiv, Int_t axis, Float_t start, Float_t step)
00531 {
00532     fNdiv   = ndiv;
00533     fAxis   = axis;
00534     fStartC = start;
00535     fStep   = step;
00536 }
00537 
00538 void   G3Volume::Division(Int_t& ndiv, Int_t& axis, Float_t& start, Float_t& step) const
00539 {
00540     ndiv  = fNdiv;
00541     axis  = fAxis;
00542     start = fStartC;
00543     step  = fStep;
00544 }

Generated on Mon Feb 15 11:06:45 2010 for loon by  doxygen 1.3.9.1