EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EicGeoMedium.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EicGeoMedium.cxx
1 
2 //
3 // A renamed excerpt of FairGeoMedium.cxx;
4 //
5 
6 #include <iostream>
7 #include <cmath>
8 #include "stdlib.h"
9 
10 using std::cout;
11 using std::log;
12 using std::pow;
13 
14 #include "EicGeoMedium.h"
15 
16 // ---------------------------------------------------------------------------------------
17 
19  TNamed(name,""),
20  //@@@medId(0),
21  autoflag(1),
22  nComponents(0),
23  weightFac(0),
24  ca(NULL),
25  cz(NULL),
26  cw(NULL),
27  density(0),
28  //@@@radLen(0),
29  sensFlag(0),
30  fldFlag(0),
31  fld(0),
32  epsil(0),
33  madfld(-1),
34  maxstep(-1),
35  maxde(-1),
36  minstep(-1)//,
37  //npckov(0),
38  // ppckov(NULL),
39  // absco(NULL),
40  // effic(NULL),
41  // rindex(NULL)
42 {
43  // Constructor for a medium with name and index id
44  // SetName(name);
45 } // EicGeoMedium::EicGeoMedium()
46 
47 // ---------------------------------------------------------------------------------------
48 
50 {
51  // Destructor
52  if (nComponents>0) {
53  delete [] ca;
54  ca=0;
55  delete [] cz;
56  cz=0;
57  delete [] cw;
58  cw=0;
59  nComponents=0;
60  }
61 #if _OLD_
62  if (npckov>0) {
63  delete [] ppckov;
64  ppckov=0;
65  delete [] absco;
66  absco=0;
67  delete [] effic;
68  effic=0;
69  delete [] rindex;
70  rindex=0;
71  npckov=0;
72  }
73 #endif
74 } // EicGeoMedium::~EicGeoMedium()
75 
76 // ---------------------------------------------------------------------------------------
77 
79 {
80  // Sets the number of components in the material
81  if (n==0) { return; }
82  Int_t k=abs(n);
83  if (nComponents!=0 && k!=nComponents) {
84  delete [] ca;
85  delete [] cz;
86  delete [] cw;
87  nComponents=0;
88  }
89  if (nComponents==0) {
90  nComponents=k;
91  ca=new Double_t[k];
92  cz=new Double_t[k];
93  cw=new Double_t[k];
94  }
95  weightFac=(Int_t)(n/nComponents);
96 } // EicGeoMedium::setNComponents()
97 
98 // ---------------------------------------------------------------------------------------
99 
100 Bool_t EicGeoMedium::setComponent (Int_t i,Double_t a,Double_t z,Double_t weight)
101 {
102  // Defines the ith material component
103  if (i<0||i>=nComponents) {
104  Error("setNComponents","Wrong index");
105  return kFALSE;
106  }
107  ca[i]=a;
108  cz[i]=z;
109  cw[i]=weight;
110  return kTRUE;
111 } // EicGeoMedium::setComponent()
112 
113 // ---------------------------------------------------------------------------------------
114 
115 void EicGeoMedium::getComponent(Int_t i,Double_t* p)
116 {
117  // Returns the ith material component
118  if (i>=0&&i<nComponents) {
119  p[0]=ca[i];
120  p[1]=cz[i];
121  p[2]=cw[i];
122 // cout << " -I p: " << p[0] << p[1] << p[2] << endl;
123  } else { p[0]=p[1]=p[2]=0.; }
124 } // EicGeoMedium::getComponent()
125 
126 // ---------------------------------------------------------------------------------------
127 
128 void EicGeoMedium::setMediumPar(Int_t sensitivityFlag,Int_t fieldFlag,
129  Double_t maxField,Double_t precision,Double_t maxDeviation,
130  Double_t maxStep,Double_t maxDE,Double_t minStep )
131 {
132  // Sets the medium parameters
133  sensFlag=sensitivityFlag;
134  fldFlag=fieldFlag;
135  fld=maxField;
137  madfld=maxDeviation;
138  maxstep=maxStep;
139  maxde=maxDE;
140  minstep=minStep;
141 } // EicGeoMedium::setMediumPar()
142 
143 // ---------------------------------------------------------------------------------------
144 
145 void EicGeoMedium::getMediumPar(Double_t* params)
146 {
147  // Returns the medium parameters
148  params[0]=sensFlag;
149  params[1]=fldFlag;
150  params[2]=fld;
151  params[3]=madfld;
152  params[4]=maxstep;
153  params[5]=maxde;
154  params[6]=epsil;
155  params[7]=minstep;
156  params[8]=0.;
157  params[9]=0.;
158 } // EicGeoMedium::getMediumPar()
159 
160 // ---------------------------------------------------------------------------------------
161 
162 void EicGeoMedium::read(std::fstream& fin, Int_t aflag )
163 {
164  // Reads the parameters from file
165  autoflag=aflag;
166  Int_t n;
167  fin>>n;
168  setNComponents(n);
169  for(Int_t ik=0; ik<nComponents; ik++) {
170  fin>>ca[ik];
171  }
172  for(Int_t i=0; i<nComponents; i++) {
173  fin>>cz[i];
174  }
175  fin>>density;
176  if (nComponents==1) {
177  cw[0]=1.;
178  //@@@calcRadiationLength();
179  } else {
180  for(Int_t i=0; i<nComponents; i++) {
181  fin>>cw[i];
182  }
183  }
184  fin>>sensFlag>>fldFlag>>fld>>epsil ;
185  if (autoflag<1) { fin>>madfld>>maxstep>>maxde>>minstep; }
186  else {
187  //to use this feature one has to set TGeant3::SetAUTO(0), thus if the media does not
188  // defined these values one can force Geant3 to calculate them by given them a value
189  // of -1
190  madfld=-1;
191  maxstep=-1;
192  maxde=-1;
193  minstep=-1;
194  }
195  fin>>n;
196  //setNpckov(n);
197  if (n>0) {
198  double ppckov, absco, effic, rindex;
199  for(Int_t i=0; i<n; i++) {
200  //@@@fin>>ppckov[i]>>absco[i]>>effic[i]>>rindex[i];
201  fin>>ppckov>>absco>>effic>>rindex;
202  }
203  }
204 
205 } // EicGeoMedium::read()
206 
207 // ---------------------------------------------------------------------------------------
208 
210 {
211  // Prints the medium definition
212  const char* bl=" ";
213  cout<<GetName()<<'\n'<<nComponents* weightFac<<bl;
214  for(Int_t ii=0; ii<nComponents; ii++) { cout<<ca[ii]<<bl ;}
215  for(Int_t j=0; j<nComponents; j++) { cout<<cz[j]<<bl ;}
216  cout<<density<<bl;
217  if (nComponents<2) { /*@@@cout<<radLen;*/ }
218  else for(Int_t iik=0; iik<nComponents; iik++) { cout<<cw[iik]<<bl ;}
219  cout<<'\n'<<sensFlag<<bl<<fldFlag<<bl<<fld<<bl<<epsil<<'\n';
220  if (autoflag<1) {
221  cout<<madfld<<bl<<maxstep<<bl<<maxde<<bl<<minstep<<'\n';
222  }
223 #if _OLD_
224  cout<<npckov<<'\n';
225  if (npckov>0) {
226  for(Int_t i=0; i<npckov; i++) {
227  cout<<ppckov[i]<< bl<<absco[i]<<bl<<effic[i]<<bl<<rindex[i]<<'\n';
228  }
229  }
230 #endif
231  cout<<'\n';
232 } // EicGeoMedium::print()
233 
234 // ---------------------------------------------------------------------------------------
235