Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files 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 /** \class TGeoMedium
14 \ingroup Geometry_classes
15 
16 Media are used to store properties related to tracking and which are useful
17 only when using geometry with a particle transport MC package (via VMC). One
18 may define several tracking media for a given material. The media ID are user
19 defined values that are not used by the geometry package. In case geometry
20 is used via VMC (in GEANT) these numbers are overwritten, so one can only
21 rely on these values after gMC->FinishGeometry() is called.
22 The media parameters are inspired from GEANT3 and the values defined make sense
23 in context of GEANT (3 but also 4) or FLUKA interfaces.
24 */
25 
26 #include "Riostream.h"
27 #include "TGeoManager.h"
28 #include "TGeoMedium.h"
29 #include "TList.h"
30 
31 ClassImp(TGeoMedium);
32 
33 ////////////////////////////////////////////////////////////////////////////////
34 /// Default constructor
35 
36 TGeoMedium::TGeoMedium()
37 {
38  fId = 0;
39  for (Int_t i=0; i<20; i++) fParams[i] = 0.;
40  fMaterial= 0;
41 }
42 
43 ////////////////////////////////////////////////////////////////////////////////
44 /// constructor
45 
46 TGeoMedium::TGeoMedium(const char *name, Int_t numed, const TGeoMaterial *mat, Double_t *params)
47  :TNamed(name,"")
48 {
49  fName = fName.Strip();
50  fId = numed;
51  for (Int_t i=0; i<20; i++) fParams[i] = 0.;
52  fMaterial = (TGeoMaterial*)mat;
53  for (Int_t i=0;i<10;i++) {
54  if (params) fParams[i] = params[i];
55  else fParams[i] = 0;
56  }
57  gGeoManager->GetListOfMedia()->Add(this);
58 }
59 
60 ////////////////////////////////////////////////////////////////////////////////
61 /// constructor
62 
63 TGeoMedium::TGeoMedium(const char *name, Int_t numed, Int_t imat, Int_t isvol, Int_t ifield,
64  Double_t fieldm, Double_t tmaxfd, Double_t stemax, Double_t deemax, Double_t epsil, Double_t stmin)
65  :TNamed(name,"")
66 {
67  fName = fName.Strip();
68  fId = numed;
69  for (Int_t i=0; i<20; i++) fParams[i] = 0.;
70  TIter next (gGeoManager->GetListOfMaterials());
71  TGeoMaterial *mat;
72  while ((mat = (TGeoMaterial*)next())) {
73  if (mat->GetUniqueID() == (UInt_t)imat) break;
74  }
75  if (!mat || (mat->GetUniqueID() != (UInt_t)imat)) {
76  fMaterial = 0;
77  Error("TGeoMedium", "%s, material number %d does not exist",name,imat);
78  return;
79  }
80  fMaterial = (TGeoMaterial*)mat;
81  fParams[0] = isvol;
82  fParams[1] = ifield;
83  fParams[2] = fieldm;
84  fParams[3] = tmaxfd;
85  fParams[4] = stemax;
86  fParams[5] = deemax;
87  fParams[6] = epsil;
88  fParams[7] = stmin;
89  gGeoManager->GetListOfMedia()->Add(this);
90 }
91 
92 ////////////////////////////////////////////////////////////////////////////////
93 ///copy constructor
94 
95 TGeoMedium::TGeoMedium(const TGeoMedium& gm) :
96  TNamed(gm),
97  fId(gm.fId),
98  fMaterial(gm.fMaterial)
99 {
100  for(Int_t i=0; i<20; i++) fParams[i]=gm.fParams[i];
101 }
102 
103 ////////////////////////////////////////////////////////////////////////////////
104 ///assignment operator
105 
106 TGeoMedium& TGeoMedium::operator=(const TGeoMedium& gm)
107 {
108  if(this!=&gm) {
109  TNamed::operator=(gm);
110  fId=gm.fId;
111  for(Int_t i=0; i<20; i++) fParams[i]=gm.fParams[i];
112  fMaterial=gm.fMaterial;
113  }
114  return *this;
115 }
116 
117 ////////////////////////////////////////////////////////////////////////////////
118 /// Destructor
119 
120 TGeoMedium::~TGeoMedium()
121 {
122 }
123 
124 ////////////////////////////////////////////////////////////////////////////////
125 /// Provide a pointer name containing uid.
126 
127 char *TGeoMedium::GetPointerName() const
128 {
129  static TString name;
130  name = TString::Format("pMed%d", GetUniqueID());
131  return (char*)name.Data();
132 }
133 
134 ////////////////////////////////////////////////////////////////////////////////
135 /// Save a primitive as a C++ statement(s) on output stream "out".
136 
137 void TGeoMedium::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
138 {
139  if (TestBit(TGeoMedium::kMedSavePrimitive)) return;
140  fMaterial->SavePrimitive(out,option);
141  out << "// Medium: " << GetName() << std::endl;
142  out << " numed = " << fId << "; // medium number" << std::endl;
143  out << " par[0] = " << fParams[0] << "; // isvol" << std::endl;
144  out << " par[1] = " << fParams[1] << "; // ifield" << std::endl;
145  out << " par[2] = " << fParams[2] << "; // fieldm" << std::endl;
146  out << " par[3] = " << fParams[3] << "; // tmaxfd" << std::endl;
147  out << " par[4] = " << fParams[4] << "; // stemax" << std::endl;
148  out << " par[5] = " << fParams[5] << "; // deemax" << std::endl;
149  out << " par[6] = " << fParams[6] << "; // epsil" << std::endl;
150  out << " par[7] = " << fParams[7] << "; // stmin" << std::endl;
151 
152  out << " " << GetPointerName() << " = new TGeoMedium(\"" << GetName() << "\", numed," << fMaterial->GetPointerName() << ", par);" << std::endl;
153  SetBit(TGeoMedium::kMedSavePrimitive);
154 }