/
FairGeoMedium.cxx
323 lines (305 loc) · 7.42 KB
/
FairGeoMedium.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
//*-- ö : Ilse Koenig
//*-- Modified : 10/11/2003 by Ilse Koenig
////////////////////////////////////////////////////////////////////////////////
//
// Class for tracking medium ( includes also material )
//
////////////////////////////////////////////////////////////////////////////////
#include "FairGeoMedium.h"
#include <iostream>
#include <cmath>
#include "stdlib.h"
using std::cout;
using std::log;
using std::pow;
ClassImp(FairGeoMedium)
FairGeoMedium::FairGeoMedium(const char* name)
: TNamed(name,""),
medId(0),
autoflag(1),
nComponents(0),
weightFac(0),
ca(NULL),
cz(NULL),
cw(NULL),
density(0),
radLen(0),
sensFlag(0),
fldFlag(0),
fld(0),
epsil(0),
madfld(-1),
maxstep(-1),
maxde(-1),
minstep(-1),
npckov(0),
ppckov(NULL),
absco(NULL),
effic(NULL),
rindex(NULL)
{
// Constructor for a medium with name and index id
// SetName(name);
};
FairGeoMedium::~FairGeoMedium()
{
// Destructor
if (nComponents>0) {
delete [] ca;
ca=0;
delete [] cz;
cz=0;
delete [] cw;
cw=0;
nComponents=0;
}
if (npckov>0) {
delete [] ppckov;
ppckov=0;
delete [] absco;
absco=0;
delete [] effic;
effic=0;
delete [] rindex;
rindex=0;
npckov=0;
}
}
void FairGeoMedium::setNComponents(Int_t n)
{
// Sets the number of components in the material
if (n==0) { return; }
Int_t k=abs(n);
if (nComponents!=0 && k!=nComponents) {
delete [] ca;
delete [] cz;
delete [] cw;
nComponents=0;
}
if (nComponents==0) {
nComponents=k;
ca=new Double_t[k];
cz=new Double_t[k];
cw=new Double_t[k];
}
weightFac=(Int_t)(n/nComponents);
}
Bool_t FairGeoMedium::setComponent (Int_t i,Double_t a,Double_t z,Double_t weight)
{
// Defines the ith material component
if (i<0||i>=nComponents) {
Error("setNComponents","Wrong index");
return kFALSE;
}
ca[i]=a;
cz[i]=z;
cw[i]=weight;
return kTRUE;
}
void FairGeoMedium::getComponent(Int_t i,Double_t* p)
{
// Returns the ith material component
if (i>=0&&i<nComponents) {
p[0]=ca[i];
p[1]=cz[i];
p[2]=cw[i];
// cout << " -I p: " << p[0] << p[1] << p[2] << endl;
} else { p[0]=p[1]=p[2]=0.; }
}
void FairGeoMedium::setNpckov (Int_t n)
{
// Sets the number of optical parameters for the tracking of Cerenkov light
if (n!=npckov && npckov>0) {
delete [] ppckov;
delete [] absco;
delete [] effic;
delete [] rindex;
}
npckov=n;
if (n>0) {
ppckov=new Double_t[npckov];
absco=new Double_t[npckov];
effic=new Double_t[npckov];
rindex=new Double_t[npckov];
}
}
Bool_t FairGeoMedium::setCerenkovPar(Int_t i,Double_t p,Double_t a,Double_t e ,Double_t r)
{
// Defines the ith parameter set of the optical parameters
if (i<0 || i>=npckov) {
Error("setNpckov","Wrong index");
return kFALSE;
}
ppckov[i]=p;
absco[i]=a;
effic[i]=e;
rindex[i]=r;
return kTRUE;
}
void FairGeoMedium::getCerenkovPar(Int_t i,Double_t* p)
{
// returns the ith parameter set of the optical parameters
if (i>=0&&i<npckov) {
p[0]=ppckov[i];
p[1]=absco[i];
p[2]=effic[i];
p[3]=rindex[i];
} else { p[0]=p[1]=p[2]=p[3]=0.; }
}
void FairGeoMedium::setMediumPar(Int_t sensitivityFlag,Int_t fieldFlag,
Double_t maxField,Double_t precision,Double_t maxDeviation,
Double_t maxStep,Double_t maxDE,Double_t minStep )
{
// Sets the medium parameters
sensFlag=sensitivityFlag;
fldFlag=fieldFlag;
fld=maxField;
epsil=precision;
madfld=maxDeviation;
maxstep=maxStep;
maxde=maxDE;
minstep=minStep;
}
void FairGeoMedium::getMediumPar(Double_t* params)
{
// Returns the medium parameters
params[0]=sensFlag;
params[1]=fldFlag;
params[2]=fld;
params[3]=madfld;
params[4]=maxstep;
params[5]=maxde;
params[6]=epsil;
params[7]=minstep;
params[8]=0.;
params[9]=0.;
}
void FairGeoMedium::read(std::fstream& fin, Int_t aflag )
{
// Reads the parameters from file
autoflag=aflag;
Int_t n;
fin>>n;
setNComponents(n);
for(Int_t ik=0; ik<nComponents; ik++) {
fin>>ca[ik];
}
for(Int_t i=0; i<nComponents; i++) {
fin>>cz[i];
}
fin>>density;
if (nComponents==1) {
cw[0]=1.;
calcRadiationLength();
} else {
for(Int_t i=0; i<nComponents; i++) {
fin>>cw[i];
}
}
fin>>sensFlag>>fldFlag>>fld>>epsil ;
if (autoflag<1) { fin>>madfld>>maxstep>>maxde>>minstep; }
else {
//to use this feature one has to set TGeant3::SetAUTO(0), thus if the media does not
// defined these values one can force Geant3 to calculate them by given them a value
// of -1
madfld=-1;
maxstep=-1;
maxde=-1;
minstep=-1;
}
fin>>n;
setNpckov(n);
if (n>0) {
for(Int_t i=0; i<n; i++) {
fin>>ppckov[i]>>absco[i]>>effic[i]>>rindex[i];
}
}
}
void FairGeoMedium::print()
{
// Prints the medium definition
const char* bl=" ";
cout<<GetName()<<'\n'<<nComponents* weightFac<<bl;
for(Int_t ii=0; ii<nComponents; ii++) { cout<<ca[ii]<<bl ;}
for(Int_t j=0; j<nComponents; j++) { cout<<cz[j]<<bl ;}
cout<<density<<bl;
if (nComponents<2) { cout<<radLen; }
else for(Int_t iik=0; iik<nComponents; iik++) { cout<<cw[iik]<<bl ;}
cout<<'\n'<<sensFlag<<bl<<fldFlag<<bl<<fld<<bl<<epsil<<'\n';
if (autoflag<1) {
cout<<madfld<<bl<<maxstep<<bl<<maxde<<bl<<minstep<<'\n';
}
cout<<npckov<<'\n';
if (npckov>0) {
for(Int_t i=0; i<npckov; i++) {
cout<<ppckov[i]<< bl<<absco[i]<<bl<<effic[i]<<bl<<rindex[i]<<'\n';
}
}
cout<<'\n';
}
void FairGeoMedium::write (std::fstream& fout)
{
// Writes the medium definition into stream
const char* bl=" ";
fout<<GetName()<<'\n'<<nComponents* weightFac<<bl;
for(Int_t i=0; i<nComponents; i++) { fout<<ca[i]<<bl ;}
for(Int_t j=0; j<nComponents; j++) { fout<<cz[j]<<bl ;}
fout<<density<<bl;
if (nComponents<2) { fout<<radLen; }
else for(Int_t i=0; i<nComponents; i++) { fout<<cw[i]<<bl ;}
fout<<'\n'<<sensFlag<<bl<<fldFlag<<bl<<fld<<bl<<epsil<<'\n';
if (autoflag<1) {
fout<<madfld<<bl<<maxstep<<bl<<maxde<<bl<<minstep<<'\n';
}
fout<<npckov<<'\n';
if (npckov>0) {
for(Int_t i=0; i<npckov; i++) {
fout<<ppckov[i]<< bl<<absco[i]<<bl<<effic[i]<<bl<<rindex[i]<<'\n';
}
}
fout<<'\n';
}
Bool_t FairGeoMedium::calcRadiationLength()
{
// calculates radiation length
// formula in GEANT manual CONS110
if (cz[0]<1.e-6) { // VAKUUM$
radLen=1.e+16;
return kTRUE;
}
Double_t alpha=1/137.; // fine structure constant
Double_t fac=.1912821; // 4*((electron radius)**2)*(avogadro's number)
Double_t z, a, w, az2, fc, y, xi, x0i, amol=0., x0itot=0.;
if (weightFac>0) { amol=1.; }
else {
for (int i=0; i<nComponents; i++) {
amol+=cw[i]*ca[i];
if (amol==0.) {
Error("calcRadiationLength()","amol==0 for medium %s",fName.Data());
return kFALSE;
}
}
}
for (int i=0; i<nComponents; i++) {
z=cz[i];
a=ca[i];
if(weightFac>0) {
w=cw[i]/amol;
} else {
w=a*cw[i]/amol;
}
az2=alpha*alpha*z*z;
fc=az2 * (1./(1.+az2) + 0.20206 - 0.0369*az2 + 0.0083*az2*az2
- .002F*az2*az2*az2);
y=log(183./pow(z,1./3.)) - fc;
xi=(float)(log(1440./pow(z,2./3.)) / y);
x0i=fac*alpha/a*z*(z+xi)*y;
x0itot+=(x0i*w);
}
if (x0itot==0. || density==0.) {
Error("calcRadiationLength()","x0itot=0 or density=0 for medium %s",fName.Data());
return kFALSE;
}
radLen=1/density/x0itot;
return kTRUE;
}