ACTARSim
ACTAR TPC Simulation Reference Guide
ActarSimCinePrimGenerator.cc
Go to the documentation of this file.
1 // - AUTHOR: Wolfgang Mittig (translated to C++: Hector Alvarez-Pol 11/2005)
2 /******************************************************************
3  * Copyright (C) 2005-2016, Hector Alvarez-Pol *
4  * All rights reserved. *
5  * *
6  * License according to GNU LESSER GPL (see lgpl-3.0.txt). *
7  * For the list of contributors see CREDITS. *
8  ******************************************************************/
9 //////////////////////////////////////////////////////////////////
10 /// \class ActarSimCinePrimGenerator
11 /// Description:
12 /// PROGRAM CINE CINEMATIQUE RELATIVISTIQUE.
13 /// Original FORTRAN code by Wolfgang Mittig translated to C++.
14 ///
15 //////////////////////////////////////////////////////////////////
16 
18 
19 #include "globals.hh"
20 #include "Randomize.hh"
21 
22 using namespace std;
23 
24 //////////////////////////////////////////////////////////////////
25 /// Constructor
26 /// Original program needs the following data:
27 ///
28 /// char: 1 Title
29 ///
30 /// G4double: - 1-4 Masses 1 to 4, (CIRE)
31 /// - 5 Reaction Q, (CIRE)
32 /// - 6 Excitation of scattered particle,
33 /// - 7 Excitation of the recoil
34 /// - 8-9 Lab Energy 1 and 2
35 /// (min/max energies when making the table?) (ELAB1 is isued in CIRE)
36 /// - 10 Delta E (step for energies when making the table?)
37 /// - 11-13 Theta angles 1 and 2
38 /// - 14 Delta Theta
40  //Default masses (just an elastic 8He on 12C)
41  S1 = 8; // 8He mass
42  S2 = 12; // C12 mass
43  S3 = 8; // 8He mass
44  S4 = 12; // C12 mass
45 
46  EI = 100; // 15MeV*number of nucleons
47  EN = 0;
48  ENI = 0;
49 
50  QM = 0.0001; //does 0 work?
51 
52  TH = 12.3456789; // in degrees, as the program converts to rad
53 
54  ANGAV = new G4double[8];
55  ANGAR = new G4double[8];
56 
57  for(G4int i = 0;i<8;i++){
58  ANGAV[i] = 0.;
59  ANGAR[i] = 0.;
60  }
61  // For debugging
62  // Dump();
63 }
64 
65 //////////////////////////////////////////////////////////////////
66 /// Destructor
68  delete ANGAV;
69  delete ANGAR;
70 }
71 
72 
73 //////////////////////////////////////////////////////////////////
74 /// Reproduces the relativistic kinematics calculations from
75 /// CIRE2 subroutine in the original CINE.for code.
76 ///
77 /// Arguments:
78 /// - masses: S1, S2, S3, S4 (for incident, target, scattered and recoil masses)
79 /// - reaction q: QM
80 /// - energies: EI, EN, ENI (for lab, excitation of target (positive) and
81 /// excitation of the projectile (positive))
82 /// - angles: TH (theta lab angle)
83 ///
84 /// Output:
85 /// given in two vectors called ANGAV and ANGAR (1st and 2nd solutions)
86 /// the elements are:
87 /// - 0: Theta CM
88 /// - 1: ELAB
89 /// - 2: De/D(Theta)
90 /// - 3: Jacobian
91 /// - 4: Theta Lab
92 /// - 5: Elab S4
93 /// - 6: Recoil Jacobian
94 /// - 7:
95 ///
96 /// Using ANGAV[1] and ANGAR[1] it is possible
97 /// to check the number of solutions
98 /// - if(ANGAV[1] < 0.) No solution
99 /// - if(ANGAV[1] >= 0.) Test ANGAR[1]
100 /// - if(ANGAR[1] < 0.) 1 Solution (ANGAV)
101 /// - if(ANGAR[1] >= 0.) 2 Solutions (ANGAV and ANGAR)
102 
104  //Check
105  //Dump();
106 
107  //Initial constants
108  const G4double U = 931.49401; // dypang 080227
109  const G4double TK = 0.0174532925;
110 
111  G4double EMI = -ENI/U;
112  G4double EM = EN/U;
113  G4double Q = QM/U;
114  G4double Z1 = S1+EMI;
115  G4double Z4 = S4+EM;
116  G4double W = EI/U;
117  G4double ET = Z1+S2+W;
118  G4double P12 = W*(Z1+Z1+W);
119  G4double BETA2 = P12/(ET*ET);
120  G4double BETA = sqrt(BETA2);
121  G4double GA2 = 1./(1.- BETA2);
122  G4double GA = sqrt(GA2);
123  G4double PSA = (Z1+S2+S3+Z4+W)*(Q+W+EMI-EM)-P12;
124  G4double PSB = (Z1+S2-S3+Z4+W)*(Z1+S2+S3-Z4+W)-P12;
125  G4double SM2 = ET*ET-P12;
126  G4double PS2 = PSA*PSB/(SM2*4.);
127 
128  /*//IF CHECKS ARE NEEDED...
129  G4cout << G4endl << EMI << " " << EM << " " << Q << G4endl;
130  G4cout << Z1 << " " << Z4 << " " << W << G4endl;
131  G4cout << ET << " " << P12 << " " << BETA2 << G4endl;
132  G4cout << BETA << " " << GA2 << " " << GA << G4endl;
133  G4cout << PSA << " " << PSB << " " << SM2 << G4endl;
134  G4cout << PS2 << G4endl;
135  */
136 
137  //translation note
138  //IF(PS2) 6,7,7
139  //are the goto lines for negative, zero and positive results of the argument
140 
141  if(PS2 < 0.) {
142  G4cout << " !! ERROR. NO SOLUTION IN CINE::RelativisticKinematics() PS2 < 0. Returning " << G4endl;
143  ANGAV[1] = -1.;
144  return;
145  }
146 
147  G4double PS = sqrt(PS2);
148  G4double CT = cos(TH*TK);
149  G4double ST = sin(TH*TK);
150  G4double E3S = sqrt(S3*S3+PS2);
151  G4double A = CT*CT+GA2*ST*ST;
152  G4double B = E3S*CT*GA*BETA;
153  G4double DELTA = GA2*(PS2-GA2*BETA2*ST*ST*S3*S3);
154  G4double WA = -1.;
155  ANGAV[1] = -1.;
156 
157  /*//IF CHECKS ARE NEEDED...
158  G4cout << G4endl << PS << " " << CT << " " << ST << G4endl;
159  G4cout << E3S << " " << A << " " << B << G4endl;
160  G4cout << DELTA << " " << WA << " " << ANGAV[1] << G4endl;
161  */
162 
163  //translation note
164  //IF(DELTA) 30,8,8
165  if(DELTA < 0.) {
166  G4cout << " !! ERROR. NO SOLUTION IN CINE::RelativisticKinematics() DELTA < 0. Returning " << G4endl;
167  return;
168  }
169 
170  G4double P3=(B+sqrt(DELTA))/A;
171 
172  //dummy boolean for a second iteration of the code
173  //searching for a second solution
174  G4bool secondIter = 0;
175 
176  do{//translation solution for the last GOTO 10 at the end of FORTRAN code
177  secondIter=0; //control the do... while loop
178 
179  //tranlation note: point 10
180  G4double P32 = P3*P3;
181 
182  G4double ET3 = sqrt(S3*S3+P32);
183  G4double W3 = P32/(S3+ET3);
184  G4double CSTE = 1E-8;
185 
186  if(W3-CSTE < 0.) {
187  G4cout << " !! ERROR. NO SOLUTION IN CINE::RelativisticKinematics() W3-CSTE < 0. Returning " << G4endl;
188  ANGAR[1] = -1.;
189  return;
190  }
191 
192  G4double CCHI,SCHI;
193  G4bool pass41 = 0; //logic aux variable to handle
194  //the nested loops in FORTRAN
195  G4double CX;
196 
197  if(PS <= 0.) {
198  CCHI = 1.;
199  SCHI = 0.;
200  //moves to 41, which is at the end of the next else
201  }
202  else{
203  CCHI = (P3*CT-GA*BETA*E3S)/(GA*PS);
204  SCHI = P3*ST/PS;
205  G4double ACX = fabs(CCHI);
206  if (ACX-1.> 0.) { // IF(ACX-1.) 42,42,12
207  if(TH-CSTE < 0.) ; //12 IF(TH-CSTE) 41,13,13
208  else if(180.-TH-CSTE < 0.) ; //13 IF(TH-CSTE) 41,13,13
209  else {
210  ANGAR[1]=-1.;
211  return;
212  }
213  }
214  else{
215  if(CCHI == 0.) { // 42 IF(CCHI) 41,40,41
216  CX = 90.000; //tranlation note:here comes a GOTO 14
217  pass41 = 1; //to handle the GOTO 14 line properly
218  }
219  }
220  }
221 
222  //translation note: point 41
223  if(!pass41){ //valid for all cases except when original
224  //FORTRAN code passes through GOTO 14
225  G4double TGCX = SCHI/CCHI;
226  CX = (atan(TGCX))/TK;
227  if(CX < 0.) CX = 180.+CX;
228  }
229 
230  pass41=0; //back again to 0
231 
232  G4double XJ,AJ;
233 
234  //tranlation note: point 14
235  if(P3 > 0.){
236  XJ = GA*PS2*(PS+BETA*CCHI*E3S)/(P32*P3);
237  AJ = fabs(XJ);
238  if(AJ-1000. >= 0.) XJ = 999.9999;
239  }
240  else {
241  XJ = 999.9999;
242  }
243 
244  //translation note: point 27
245  G4double ANUM = GA*BETA*P32*ST*(E3S+P3*CT*GA*BETA);
246  G4double DENO = (S3+W3)*(GA*BETA*E3S*CT-P3);
247 
248  G4double DX;
249 
250  if(DENO == 0.) DX = 9999.9;
251  else DX = 1000.*U*TK*(ANUM/DENO);
252 
253  //translation note: point 17
254  G4double E4S = sqrt(Z4*Z4+PS2);
255 
256  G4double DENOM = GA*(BETA*E4S-PS*CCHI);
257  G4double TR;
258  G4double TGTR;
259 
260  if(DENOM == 0.) TR = 90.;
261  else {
262  TGTR = PS*SCHI/DENOM;
263  TR = (atan(TGTR))/TK;
264  if(TR < 0.) TR = 180.+TR;
265  }
266 
267  //tranlation note: point 38
268  G4double P42 = DENOM*DENOM+PS2*SCHI*SCHI;
269  G4double P4 = sqrt(P42);
270  G4double ER = U*P42/(Z4+sqrt(Z4*Z4+P42));
271 
272  G4double RJ;
273 
274  if(P4 > 0.) RJ = 999.9999;
275  else {
276  RJ = GA*PS2*(PS-BETA*CCHI*E4S)/(P42*P4);
277  AJ = fabs(RJ);
278  if(AJ-1000. >= 0.) RJ = 999.9999;
279  }
280 
281  //tranlation note: point 33
282  if(WA < 0.) {
283  ANGAV[0] = CX;
284  WA = W3*U;
285  ANGAV[1] = WA;
286  ANGAV[2] = DX;
287  ANGAV[3] = fabs(XJ);
288  ANGAV[4] = TR;
289  ANGAV[5] = ER;
290  ANGAV[6] = fabs(RJ);
291  P3=(B-sqrt(DELTA))/A;
292  //printResults(0);
293  if(P3 < 0.) {
294  ANGAR[1] = -1.;
295  return;
296  }
297  else{
298  secondIter = 1;
299  }
300  }
301  else{
302  //tranlation note: point 19
303  ANGAR[0] = CX;
304  ANGAR[1] = W3*U;
305  ANGAR[2] = DX;
306  ANGAR[3] = fabs(XJ);
307  ANGAR[4] = TR;
308  ANGAR[5] = ER;
309  ANGAR[6] = fabs(RJ);
310  //printResults(1);
311  return;
312  }
313  } while(secondIter == 1);
314 
315  return;
316 }
317 
318 //////////////////////////////////////////////////////////////////
319 /// Dump the status of the variables
321  G4cout << G4endl << "ActarSimCinePrimGenerator::Dump()" << G4endl;
322  G4cout << "Incident Mass: " << S1 << " "
323  << "Target Mass: " << S2 << G4endl;
324  G4cout << "Scattered Mass: " << S3 << " "
325  << "Recoil Mass: " << S4 << G4endl;
326  G4cout << "Reaction Q: " << QM << " "
327  << "Theta Lab Angle: " << TH << " "
328  << "LAB energy :" << EI << G4endl;
329  G4cout << "Target excitation energy:" << EN << " "
330  << "Projectile excitation energy:" << ENI << G4endl;
331  G4cout << G4endl<< "ANGAV:" << ANGAV << " ";
332  for(G4int i=0;i<8;i++) G4cout << ANGAV[i] << ", ";
333  G4cout << G4endl <<"ANGAR:" << ANGAR << " ";
334  for(G4int i=0;i<8;i++) G4cout << ANGAR[i] << ", ";
335 }
336 
337 //////////////////////////////////////////////////////////////////
338 /// Print the results for each solution
340  G4int prec = G4cout.precision(6);
341 
342  G4cout << G4endl << " ActarSimCinePrimGenerator::printResult(" << sel << ")" << G4endl;
343  if(sel == 0){
344  G4cout << " CINE result: Scattered Particle Angle: " << GetThetaLabAngle()
345  << " deg, Scattered Particle Energy: " << ANGAV[1] << " MeV" << G4endl;
346  G4cout << " CINE result: Recoil Particle Angle: " << ANGAV[4]
347  << " deg, Recoil Particle Energy: " << ANGAV[5] << " MeV" << G4endl;
348  }
349  if(sel == 1){
350  G4cout << " Second solution in CINE ... " << G4endl;
351  G4cout << " CINE result: Scattered Particle Angle: " << GetThetaLabAngle()
352  << " deg, Scattered Particle Energy: " << ANGAR[1] << " MeV" << G4endl;
353  G4cout << " CINE result: Recoil Particle Angle: " << ANGAR[4]
354  << " deg, Recoil Particle Energy: " << ANGAR[5] << " MeV" << G4endl;
355  }
356  G4cout.precision(prec);
357 }
void Dump()
Dump the status of the variables.
STL namespace.
void printResults(G4int sel)
Print the results for each solution.