7 #include "G4IonTable.hh" 8 #include "G4EmCalculator.hh" 9 #include "G4NistManager.hh" 10 #include "G4ParticleDefinition.hh" 12 #include "FairLogger.h" 15 TMatrixD* ReadCalFile(TString fileName) {
19 LOG(FATAL) <<
"Can`t open calibration file " << fileName << FairLogger::FairLogger::endl;
23 Int_t nRows = -1, nCols = -1;
26 if (nCols <= 0 || nRows <= 0){
27 LOG(FATAL) <<
"Can`t read rows or cols from calibration file " << fileName << FairLogger::FairLogger::endl;
31 TMatrixD* calTable =
new TMatrixD(nRows,nCols);
38 in >> (*calTable)[i][0] >> (*calTable)[i][1];
43 LOG(FATAL) <<
"Wrong file format in " << fileName << FairLogger::FairLogger::endl;
49 double EiEo(
double tableER[][105],
double Tp,
double Rp){
51 {printf(
"Energy is out of range\n");
return -1.;}
54 while (Tp>tableER[0][look]) {look++;}
56 double R1=tableER[2][look-1]+
57 +tableER[3][look-1]*Tp+
58 +tableER[4][look-1]*Tp*Tp+
59 +tableER[5][look-1]*Tp*Tp*Tp;
64 {
if(R2<tableER[1][0]) {
return 0.;}}
66 {
if(R2>=tableER[1][104]) {
return -2.;
67 printf(
"table is out of range\n");}}
70 while (R2>tableER[1][look]) {look++;}
72 double E1=tableER[6][look-1]+
73 +tableER[7][look-1]*R2+
74 +tableER[8][look-1]*R2*R2+
75 +tableER[9][look-1]*R2*R2*R2;
80 int ReadRint(
char* Fname,
double Ranges[][105]){
83 char unR[10],un3[10],un4[10],dee[10],b[10],cc[10];
85 double Energy,Rng,e,r,den;
86 double x[4],y[4],c[4];
90 FILE *F2 = fopen(Fname,
"r");
91 if(F2==NULL) {printf(
"ReadRint: File %s has not been read\n",Fname);
95 printf(
"ReadRint: File %s has been read\n",Fname);
96 while (fgets(DummyA,256,F2)) {
if(strstr(DummyA,termA))
break;}
98 while (strcmp(unE,
"GeV"))
102 res = fscanf(F2,
"%lf %s %s %lf %lf %s %s %s %s %s\n",&e,unE,dee,
103 &den,&r,unR,b,un3,cc,un4);
104 if(!strcmp(unE,
"keV")) {Energy=e/1000.0;}
105 else if(!strcmp(unE,
"MeV")) {Energy=e;}
106 else if(!strcmp(unE,
"GeV")) {Energy=e*1000.0;}
107 else {printf(
"Error of reading in ReadRint a: %s %s\n",unE,unR);}
109 if(!strcmp(unR,
"A")) {Rng=r*1.0E-8;}
110 else if(!strcmp(unR,
"um")) {Rng=r/10000.0;}
111 else if(!strcmp(unR,
"mm")) {Rng=r/10.0;}
112 else if(!strcmp(unR,
"cm")) {Rng=r;}
113 else if(!strcmp(unR,
"m")) {Rng=r*100.0;}
114 else if(!strcmp(unR,
"km")) {Rng=r*100000.0;}
115 else {printf(
"Error of reading in ReadRint b: %s %s\n",unE,unR);}
130 printf(
"1 Interpolation error 1 intrp4=%i\n",intrp4(x,y,c));
147 printf(
"2 Interpolation error 2 intrp4=%i\n",intrp4(x,y,c));
return 1;
157 x[0] = Ranges[0][i-1];
159 x[2] = Ranges[0][i+1];
160 x[3] = Ranges[0][i+2];
161 y[0] = Ranges[1][i-1];
163 y[2] = Ranges[1][i+1];
164 y[3] = Ranges[1][i+2];
167 {printf(
"3 Interpolation error 3 intrp4=%i\n",intrp4(x,y,c));
return 1;}
178 Ranges[2][i+1] = c[0];
179 Ranges[3][i+1] = c[1];
180 Ranges[4][i+1] = c[2];
181 Ranges[5][i+1] = c[3];
185 y[0] = Ranges[0][i-1];
187 y[2] = Ranges[0][i+1];
188 y[3] = Ranges[0][i+2];
190 x[0] = Ranges[1][i-1];
192 x[2] = Ranges[1][i+1];
193 x[3] = Ranges[1][i+2];
197 printf(
"4 Interpolation error 4 intrp4=%i\n",intrp4(x,y,c));
return 1;
210 Ranges[6][i+1] = c[0];
211 Ranges[7][i+1] = c[1];
212 Ranges[8][i+1] = c[2];
213 Ranges[9][i+1] = c[3];
219 int intrp4(
double* x,
double* y,
double* c)
227 double x12,x13,x22,x23,x32,x33,x42,x43;
239 d3=(x13*x22*x[2]-x12*x23*x[2]-x13*x[1]*x32+x[0]*x23*x32+x12*x[1]*x33-
240 x[0]*x22*x33-x13*x22*x[3]+x12*x23*x[3]+x13*x32*x[3]-x23*x32*x[3]-
241 x12*x33*x[3]+x22*x33*x[3]+x13*x[1]*x42-x[0]*x23*x42-x13*x[2]*x42+
242 x23*x[2]*x42+x[0]*x33*x42-x[1]*x33*x42-x12*x[1]*x43+x[0]*x22*x43+
243 x12*x[2]*x43-x22*x[2]*x43-x[0]*x32*x43+x[1]*x32*x43);
245 c[3]=(x22*x[2]*y[0]-x[1]*x32*y[0]-x22*x[3]*y[0]+
246 x32*x[3]*y[0]+x[1]*x42*y[0]-x[2]*x42*y[0]-
247 x12*x[2]*y[1]+x[0]*x32*y[1]+x12*x[3]*y[1]-
248 x32*x[3]*y[1]-x[0]*x42*y[1]+x[2]*x42*y[1]+
249 x12*x[1]*y[2]-x[0]*x22*y[2]-x12*x[3]*y[2]+
250 x22*x[3]*y[2]+x[0]*x42*y[2]-x[1]*x42*y[2]-
251 x12*x[1]*y[3]+x[0]*x22*y[3]+x12*x[2]*y[3]-
252 x22*x[2]*y[3]-x[0]*x32*y[3]+x[1]*x32*y[3])/d3;
254 d2=(x13*x22*x[2]-x12*x23*x[2]-x13*x[1]*x32+x[0]*x23*x32+x12*x[1]*x33-
255 x[0]*x22*x33-x13*x22*x[3]+x12*x23*x[3]+x13*x32*x[3]-x23*x32*x[3]-
256 x12*x33*x[3]+x22*x33*x[3]+x13*x[1]*x42-x[0]*x23*x42-x13*x[2]*x42+
257 x23*x[2]*x42+x[0]*x33*x42-x[1]*x33*x42-x12*x[1]*x43+x[0]*x22*x43+
258 x12*x[2]*x43-x22*x[2]*x43-x[0]*x32*x43+x[1]*x32*x43);
260 c[2]=(-(x23*x[2]*y[0])+x[1]*x33*y[0]+x23*x[3]*y[0]-x33*x[3]*y[0]-x[1]*x43*y[0]+
261 x[2]*x43*y[0]+x13*x[2]*y[1]-x[0]*x33*y[1]-
262 x13*x[3]*y[1]+x33*x[3]*y[1]+x[0]*x43*y[1]-
263 x[2]*x43*y[1]-x13*x[1]*y[2]+x[0]*x23*y[2]+
264 x13*x[3]*y[2]-x23*x[3]*y[2]-x[0]*x43*y[2]+
265 x[1]*x43*y[2]+x13*x[1]*y[3]-x[0]*x23*y[3]-
266 x13*x[2]*y[3]+x23*x[2]*y[3]+x[0]*x33*y[3]-
269 d1=(x13*x22*x[2]-x12*x23*x[2]-x13*x[1]*x32+x[0]*x23*x32+x12*x[1]*x33-
270 x[0]*x22*x33-x13*x22*x[3]+x12*x23*x[3]+x13*x32*x[3]-x23*x32*x[3]-
271 x12*x33*x[3]+x22*x33*x[3]+x13*x[1]*x42-x[0]*x23*x42-x13*x[2]*x42+
272 x23*x[2]*x42+x[0]*x33*x42-x[1]*x33*x42-x12*x[1]*x43+x[0]*x22*x43+
273 x12*x[2]*x43-x22*x[2]*x43-x[0]*x32*x43+x[1]*x32*x43);
275 c[1]=(x23*x32*y[0]-x22*x33*y[0]-x23*x42*y[0]+x33*x42*y[0]+x22*x43*y[0]-
276 x32*x43*y[0]-x13*x32*y[1]+x12*x33*y[1]+x13*x42*y[1]-x33*x42*y[1]-
277 x12*x43*y[1]+x32*x43*y[1]+x13*x22*y[2]-x12*x23*y[2]-x13*x42*y[2]+
278 x23*x42*y[2]+x12*x43*y[2]-x22*x43*y[2]-x13*x22*y[3]+x12*x23*y[3]+
279 x13*x32*y[3]-x23*x32*y[3]-x12*x33*y[3]+x22*x33*y[3])/d1;
281 d0=(x13*x22*x[2]-x12*x23*x[2]-x13*x[1]*x32+x[0]*x23*x32+x12*x[1]*x33-
282 x[0]*x22*x33-x13*x22*x[3]+x12*x23*x[3]+x13*x32*x[3]-x23*x32*x[3]-
283 x12*x33*x[3]+x22*x33*x[3]+x13*x[1]*x42-x[0]*x23*x42-x13*x[2]*x42+
284 x23*x[2]*x42+x[0]*x33*x42-x[1]*x33*x42-x12*x[1]*x43+x[0]*x22*x43+
285 x12*x[2]*x43-x22*x[2]*x43-x[0]*x32*x43+x[1]*x32*x43);
287 c[0]=(-(x23*x32*x[3]*y[0])+x22*x33*x[3]*y[0]+x23*x[2]*x42*y[0]-x[1]*x33*x42*y[0]-
288 x22*x[2]*x43*y[0]+x[1]*x32*x43*y[0]+x13*x32*x[3]*y[1]-x12*x33*x[3]*y[1]-
289 x13*x[2]*x42*y[1]+x[0]*x33*x42*y[1]+x12*x[2]*x43*y[1]-x[0]*x32*x43*y[1]-
290 x13*x22*x[3]*y[2]+x12*x23*x[3]*y[2]+x13*x[1]*x42*y[2]-x[0]*x23*x42*y[2]-
291 x12*x[1]*x43*y[2]+x[0]*x22*x43*y[2]+x13*x22*x[2]*y[3]-x12*x23*x[2]*y[3]-
292 x13*x[1]*x32*y[3]+x[0]*x23*x32*y[3]+x12*x[1]*x33*y[3]-x[0]*x22*x33*y[3])/d0;
294 if(d0*d1*d2*d3!=0.0) {rp4=0;}
323 Double_t CalcElossIntegralVolStep (Double_t kineticEnergy,
const G4ParticleDefinition& particle,
324 const G4Material& material,
const Double_t range,
const Double_t ) {
327 Double_t integralEloss = 0.;
328 const Double_t intStep = range / 20;
329 Double_t curStep = 0.;
330 G4EmCalculator* calc =
new G4EmCalculator();
331 while (curStep < range) {
332 Double_t eloss = calc->GetDEDX(kineticEnergy, &particle, &material) * intStep * 10 ;
333 integralEloss += eloss;
334 kineticEnergy += eloss;
337 return integralEloss;
340 Double_t ComputeElossIntegralVolStep(Double_t kineticEnergy,
const G4ParticleDefinition& particle,
341 const G4Material& material,
const TString& process_name,
342 const Double_t range) {
345 Double_t integralEloss = 0.;
346 const Double_t intStep = range / 20;
347 Double_t curStep = 0.;
348 G4EmCalculator* calc =
new G4EmCalculator();
349 while (curStep < range) {
350 Double_t eloss = calc->ComputeDEDX(kineticEnergy, &particle,
351 process_name.Data(), &material) * intStep * 10 ;
352 integralEloss += eloss;
353 kineticEnergy += eloss;
356 return integralEloss;
359 Double_t ElossCalculator::CalcDeDx(
const TString& material_name,
const int pdg,
const double kineticEnergy) {
360 const auto* particle = G4ParticleTable::GetParticleTable()->FindParticle(pdg);
361 const auto* material = G4NistManager::Instance()->FindOrBuildMaterial(material_name.Data());
363 return calc.GetDEDX(kineticEnergy, particle, material);
366 Double_t ElossCalculator::CalcDeDx_long(
const TString& material_name,
const int pdg,
double kineticEnergy,
const Double_t range) {
367 const auto* particle = G4ParticleTable::GetParticleTable()->FindParticle(pdg);
368 const auto* material = G4NistManager::Instance()->FindOrBuildMaterial(material_name.Data());
371 Double_t integralEloss = 0.;
372 const Double_t intStep = range / 20;
373 Double_t curStep = 0.;
375 while (curStep < range) {
376 Double_t eloss = calc.GetDEDX(kineticEnergy, particle, material) * intStep * 10 ;
377 integralEloss += eloss;
378 kineticEnergy += eloss;
381 return integralEloss;