ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TGeoMedium.cxx
Go to the documentation of this file.
1 // @(#)root/geom:$Id$
2 // Author: Rene Brun 26/12/02
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 ////////////////////////////////////////////////////////////////////////////////
13 // Media are used to store properties related to tracking and which are useful
14 // only when using geometry with a particle transport MC package (via VMC). One
15 // may define several tracking media for a given material. The media ID are user
16 // defined values that are not used by the geometry package. In case geometry
17 // is used via VMC (in GEANT) these numbers are overwritten, so one can only
18 // rely on these values after gMC->FinishGeometry() is called.
19 // The media parameters are inspired from GEANT3 and the values defined make sense
20 // in context of GEANT (3 but also 4) or FLUKA interfaces.
21 ////////////////////////////////////////////////////////////////////////////////
22 
23 #include "Riostream.h"
24 #include "TGeoManager.h"
25 #include "TGeoMedium.h"
26 #include "TList.h"
27 
29 
30 ////////////////////////////////////////////////////////////////////////////////
31 /// Default constructor
32 
34 {
35  fId = 0;
36  for (Int_t i=0; i<20; i++) fParams[i] = 0.;
37  fMaterial= 0;
38 }
39 
40 ////////////////////////////////////////////////////////////////////////////////
41 /// constructor
42 
43 TGeoMedium::TGeoMedium(const char *name, Int_t numed, const TGeoMaterial *mat, Double_t *params)
44  :TNamed(name,"")
45 {
46  fName = fName.Strip();
47  fId = numed;
48  for (Int_t i=0; i<20; i++) fParams[i] = 0.;
49  fMaterial = (TGeoMaterial*)mat;
50  for (Int_t i=0;i<10;i++) {
51  if (params) fParams[i] = params[i];
52  else fParams[i] = 0;
53  }
54  gGeoManager->GetListOfMedia()->Add(this);
55 }
56 
57 ////////////////////////////////////////////////////////////////////////////////
58 /// constructor
59 
60 TGeoMedium::TGeoMedium(const char *name, Int_t numed, Int_t imat, Int_t isvol, Int_t ifield,
61  Double_t fieldm, Double_t tmaxfd, Double_t stemax, Double_t deemax, Double_t epsil, Double_t stmin)
62  :TNamed(name,"")
63 {
64  fName = fName.Strip();
65  fId = numed;
66  for (Int_t i=0; i<20; i++) fParams[i] = 0.;
68  TGeoMaterial *mat;
69  while ((mat = (TGeoMaterial*)next())) {
70  if (mat->GetUniqueID() == (UInt_t)imat) break;
71  }
72  if (!mat || (mat->GetUniqueID() != (UInt_t)imat)) {
73  fMaterial = 0;
74  Error("TGeoMedium", "%s, material number %d does not exist",name,imat);
75  return;
76  }
77  fMaterial = (TGeoMaterial*)mat;
78  fParams[0] = isvol;
79  fParams[1] = ifield;
80  fParams[2] = fieldm;
81  fParams[3] = tmaxfd;
82  fParams[4] = stemax;
83  fParams[5] = deemax;
84  fParams[6] = epsil;
85  fParams[7] = stmin;
86  gGeoManager->GetListOfMedia()->Add(this);
87 }
88 
89 ////////////////////////////////////////////////////////////////////////////////
90 ///copy constructor
91 
93  TNamed(gm),
94  fId(gm.fId),
95  fMaterial(gm.fMaterial)
96 {
97  for(Int_t i=0; i<20; i++) fParams[i]=gm.fParams[i];
98 }
99 
100 ////////////////////////////////////////////////////////////////////////////////
101 ///assignment operator
102 
104 {
105  if(this!=&gm) {
106  TNamed::operator=(gm);
107  fId=gm.fId;
108  for(Int_t i=0; i<20; i++) fParams[i]=gm.fParams[i];
109  fMaterial=gm.fMaterial;
110  }
111  return *this;
112 }
113 
114 ////////////////////////////////////////////////////////////////////////////////
115 /// Destructor
116 
118 {
119 }
120 
121 ////////////////////////////////////////////////////////////////////////////////
122 /// Provide a pointer name containing uid.
123 
125 {
126  static TString name;
127  name = TString::Format("pMed%d", GetUniqueID());
128  return (char*)name.Data();
129 }
130 
131 ////////////////////////////////////////////////////////////////////////////////
132 /// Save a primitive as a C++ statement(s) on output stream "out".
133 
134 void TGeoMedium::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
135 {
137  fMaterial->SavePrimitive(out,option);
138  out << "// Medium: " << GetName() << std::endl;
139  out << " numed = " << fId << "; // medium number" << std::endl;
140  out << " par[0] = " << fParams[0] << "; // isvol" << std::endl;
141  out << " par[1] = " << fParams[1] << "; // ifield" << std::endl;
142  out << " par[2] = " << fParams[2] << "; // fieldm" << std::endl;
143  out << " par[3] = " << fParams[3] << "; // tmaxfd" << std::endl;
144  out << " par[4] = " << fParams[4] << "; // stemax" << std::endl;
145  out << " par[5] = " << fParams[5] << "; // deemax" << std::endl;
146  out << " par[6] = " << fParams[6] << "; // epsil" << std::endl;
147  out << " par[7] = " << fParams[7] << "; // stmin" << std::endl;
148 
149  out << " " << GetPointerName() << " = new TGeoMedium(\"" << GetName() << "\", numed," << fMaterial->GetPointerName() << ", par);" << std::endl;
151 }
Double_t fParams[20]
Definition: TGeoMedium.h:34
TList * GetListOfMaterials() const
Definition: TGeoManager.h:463
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
const char Option_t
Definition: RtypesCore.h:62
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:732
const char * Data() const
Definition: TString.h:349
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
Definition: TString.cxx:2321
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
TList * GetListOfMedia() const
Definition: TGeoManager.h:464
Int_t fId
Definition: TGeoMedium.h:33
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition: TGeoMedium.cxx:134
char * out
Definition: TBase64.cxx:29
char * GetPointerName() const
Provide a pointer name containing uid.
Definition: TGeoMedium.cxx:124
TNamed & operator=(const TNamed &rhs)
TNamed assignment operator.
Definition: TNamed.cxx:40
char * GetPointerName() const
Provide a pointer name containing uid.
ClassImp(TGeoMedium) TGeoMedium
Default constructor.
Definition: TGeoMedium.cxx:28
unsigned int UInt_t
Definition: RtypesCore.h:42
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:173
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
TSubString Strip(EStripType s=kTrailing, char c= ' ') const
Return a substring of self stripped at beginning and/or end.
Definition: TString.cxx:1056
TString fName
Definition: TNamed.h:36
R__EXTERN TGeoManager * gGeoManager
Definition: TGeoManager.h:556
double Double_t
Definition: RtypesCore.h:55
virtual ~TGeoMedium()
Destructor.
Definition: TGeoMedium.cxx:117
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
TGeoMaterial * fMaterial
Definition: TGeoMedium.h:35
virtual UInt_t GetUniqueID() const
Return the unique object id.
Definition: TObject.cxx:433
#define name(a, b)
Definition: linkTestLib0.cpp:5
virtual void Add(TObject *obj)
Definition: TList.h:81
TGeoMedium & operator=(const TGeoMedium &)
assignment operator
Definition: TGeoMedium.cxx:103