EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EicGeoMedia.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EicGeoMedia.cxx
1 
2 //
3 // A renamed excerpt of FairGeoMedia.cxx;
4 //
5 
6 #include <iostream>
7 
8 using std::cout;
9 using std::endl;
10 
11 #include "TGeoMedium.h"
12 #include "TGeoMaterial.h"
13 #include "TList.h"
14 
15 #include "EicGeoMedia.h"
16 #include "EicGeoMedium.h"
17 
18 // ---------------------------------------------------------------------------------------
19 
21  TNamed(),
22  nMed(0),
23  media(new TList())
24 {
25 } // EicGeoMedia::EicGeoMedia()
26 
27 // ---------------------------------------------------------------------------------------
28 
30 {
31  if (media) {
32  media->Delete();
33  delete media;
34  media=0;
35  }
36 } // EicGeoMedia::~EicGeoMedia()
37 
38 // ---------------------------------------------------------------------------------------
39 
40 EicGeoMedium* EicGeoMedia::getMedium(const char* mediumName)
41 {
42  // Returns the medium with name mediumName
43  return (EicGeoMedium*)media->FindObject(mediumName);
44 } // EicGeoMedia::getMedium()
45 
46 // ---------------------------------------------------------------------------------------
47 
49 {
50  // Adds a medium to the list of media
51  media->Add(m);
52 } // EicGeoMedia::addMedium()
53 
54 // ---------------------------------------------------------------------------------------
55 
57 {
58  TListIter iter(media);
59  EicGeoMedium* medium;
60  Int_t i=0;
61  while((medium=(EicGeoMedium*)iter.Next())) {
62  if (medium->getAutoFlag()!=0) {
63  medium->print();
64  i++;
65  }
66  }
67  if (i!=media->GetSize()) {
68  iter.Reset();
69  cout<<"//----------------------------------------------\n";
70  cout<<"AUTONULL\n";
71  cout<<"//----------------------------------------------\n";
72  while((medium=(EicGeoMedium*)iter.Next())) {
73  if (medium->getAutoFlag()==0) { medium->print(); }
74  }
75  }
76 } // EicGeoMedia::print()
77 
78 // ---------------------------------------------------------------------------------------
79 
80 void EicGeoMedia::read(std::fstream& fin)
81 {
82  // Reads the media from file
83  cout<<"-I- EicGeoMedia Read media"<<endl;
84  const Int_t maxBuf=256;
85  char buf[maxBuf];
86  Int_t autoflag=1;
87  while(!fin.eof()) {
88  fin>>buf;
89  if (buf[0]=='\0' || buf[0]=='/') { fin.getline(buf,maxBuf); }
90  else if (fin.eof()) { break; }
91  else {
92  TString eleName(buf);
93  if (eleName.CompareTo("AUTONULL")!=0) {
94  EicGeoMedium* medium=new EicGeoMedium(eleName);
95  medium->read(fin,autoflag);
96  media->Add(medium);
97  } else { autoflag=0; }
98  }
99  }
100 } // EicGeoMedia::read()
101 
102 // ---------------------------------------------------------------------------------------
103 
105 {
106  // Creates the medium
107  //@@@if (!geoManager&&!med) { return 0; }
108 
109  Int_t nComp=med->getNComponents();
110  Int_t weightFac=med->getWeightFac();
111  TGeoMaterial* material=0;
112  Double_t p[3];
113  if (nComp==1) {
114  med->getComponent(0,p);
115  material=new TGeoMaterial(med->GetName(),p[0],p[1],med->getDensity());//,
116  //med->getRadiationLength());
117  // Interaction length not defined!!!!!!
118  } else {
119  material=new TGeoMixture(med->GetName(),nComp,med->getDensity());
120  Double_t sumWeights=0.;
121  if (weightFac<0) {
122  for(Int_t i=0; i<nComp; i++) {
123  med->getComponent(i,p);
124  sumWeights+=p[0]*p[2];
125  }
126  }
127  for(Int_t i=0; i<nComp; i++) {
128  med->getComponent(i,p);
129  if (weightFac>0) {
130  ((TGeoMixture*)material)->DefineElement(i,p[0],p[1],p[2]);
131  } else {
132  ((TGeoMixture*)material)->DefineElement(i,p[0],p[1],p[0]*p[2]/sumWeights);
133  }
134  }
135  }
136  nMed++;
137  //@@@med->setMediumIndex(nMed);
138  Double_t mp[10];
139  med->getMediumPar(mp);
140  TGeoMedium* medium=new TGeoMedium(med->GetName(),nMed,material,mp);
141  if (medium) { return nMed; }
142  else { return 0; }
143 } // EicGeoMedia::createMedium()
144 
145 // ---------------------------------------------------------------------------------------
146