1 | // |
---|
2 | // ******************************************************************** |
---|
3 | // * License and Disclaimer * |
---|
4 | // * * |
---|
5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
7 | // * conditions of the Geant4 Software License, included in the file * |
---|
8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
9 | // * include a list of copyright holders. * |
---|
10 | // * * |
---|
11 | // * Neither the authors of this software system, nor their employing * |
---|
12 | // * institutes,nor the agencies providing financial support for this * |
---|
13 | // * work make any representation or warranty, express or implied, * |
---|
14 | // * regarding this software system or assume any liability for its * |
---|
15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
16 | // * for the full disclaimer and the limitation of liability. * |
---|
17 | // * * |
---|
18 | // * This code implementation is the result of the scientific and * |
---|
19 | // * technical work of the GEANT4 collaboration. * |
---|
20 | // * By using, copying, modifying or distributing the software (or * |
---|
21 | // * any work based on the software) you agree to acknowledge its * |
---|
22 | // * use in resulting scientific publications, and indicate your * |
---|
23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
24 | // ******************************************************************** |
---|
25 | // |
---|
26 | // |
---|
27 | // G4 Tools program: NuMu DIS(Q2) fixed step integration |
---|
28 | // ..................................................... |
---|
29 | // Created: M.V. Kossov, CERN/ITEP(Moscow), 20-Dec-2005 |
---|
30 | // |
---|
31 | //===================================================================== |
---|
32 | #include "globals.hh" |
---|
33 | #include <iostream> |
---|
34 | #include <fstream> |
---|
35 | #include <vector> |
---|
36 | #include "G4ios.hh" |
---|
37 | //#include <CLHEP/GenericFunctions/LogGamma.hh> |
---|
38 | |
---|
39 | // Solution for randomization of the high order polinoms is tabulated |
---|
40 | |
---|
41 | double poli(double x, int n) // f=n*x^(n-1)-(n-1)*x^n=R(0-1), n>2, as n=2 has analSolution |
---|
42 | { |
---|
43 | double p=x; |
---|
44 | int n1=n-1; |
---|
45 | for(int i=1; i<n1; i++) p*=x; |
---|
46 | return p*(n-n1*x); |
---|
47 | } |
---|
48 | |
---|
49 | double dpoli(double x, int n) // df=n*(n-1)*x^(n-2)-(n-1)*n*x^(n-1), n>2 (n=2 has analSol) |
---|
50 | { |
---|
51 | double p=x; |
---|
52 | int n1=n-1; |
---|
53 | if(n>3) for(int i=2; i<n1; i++) p*=x; |
---|
54 | return p*n*n1*(1.-x); |
---|
55 | } |
---|
56 | // One can define for tabulation more similar functions |
---|
57 | |
---|
58 | int main() |
---|
59 | { |
---|
60 | const double eps=.0000001; // relative accuracy of the integral calculation |
---|
61 | // ============= |
---|
62 | int nSub=10; |
---|
63 | double dSub=1./nSub; |
---|
64 | for(int n=3; n<12; n++) |
---|
65 | { |
---|
66 | G4cout<<"n="<<n<<G4endl; |
---|
67 | G4double s=0.; |
---|
68 | for(int i=1; i<nSub; i++) |
---|
69 | { |
---|
70 | s+=dSub; |
---|
71 | G4double r=std::pow(s,(n-1.5)/1.5); |
---|
72 | G4double x=0.5; |
---|
73 | if(n==3) |
---|
74 | { |
---|
75 | if (r==0.5) x=0.5; |
---|
76 | else if(r<0.5) x=std::sqrt(r+r)*(.5+.1579*(r-.5)); |
---|
77 | else x=1.-std::sqrt(2.-r-r)*(.5+.1579*(.5-r)); |
---|
78 | } |
---|
79 | else |
---|
80 | { |
---|
81 | G4int n1=n-1; |
---|
82 | G4double r1=n1; |
---|
83 | G4double r2=r1-1.; |
---|
84 | G4double rr=r2/r1; |
---|
85 | G4double rp=std::pow(rr,n1); |
---|
86 | G4double p2=rp+rp; |
---|
87 | if (r==rr) x=p2; |
---|
88 | else |
---|
89 | { |
---|
90 | if(r<rr) |
---|
91 | { |
---|
92 | G4double pr=0.; |
---|
93 | G4double pra=0.; |
---|
94 | if(n>7) |
---|
95 | { |
---|
96 | if(n>9) |
---|
97 | { |
---|
98 | if(n>10) // >10(11) |
---|
99 | { |
---|
100 | pr=.614/std::pow((n+1+1.25),.75); |
---|
101 | pra=.915/std::pow((n+1+6.7),1.75); |
---|
102 | } |
---|
103 | else // 10 |
---|
104 | { |
---|
105 | pr=.09945; |
---|
106 | pra=.00667; |
---|
107 | } |
---|
108 | } |
---|
109 | else |
---|
110 | { |
---|
111 | if(n>8) // 9 |
---|
112 | { |
---|
113 | pr=.1064; |
---|
114 | pra=.00741; |
---|
115 | } |
---|
116 | else // 8 |
---|
117 | { |
---|
118 | pr=.11425; |
---|
119 | pra=.00828; |
---|
120 | } |
---|
121 | } |
---|
122 | } |
---|
123 | else |
---|
124 | { |
---|
125 | if(n>5) |
---|
126 | { |
---|
127 | if(n>6) // 7 |
---|
128 | { |
---|
129 | pr=.12347; |
---|
130 | pra=.00926; |
---|
131 | } |
---|
132 | else // 6 |
---|
133 | { |
---|
134 | pr=.13405; |
---|
135 | pra=.01027; |
---|
136 | } |
---|
137 | } |
---|
138 | else |
---|
139 | { |
---|
140 | if(n>4) // 5 |
---|
141 | { |
---|
142 | pr=.1454; |
---|
143 | pra=.01112; |
---|
144 | } |
---|
145 | else // 4 |
---|
146 | { |
---|
147 | pr=.15765; |
---|
148 | pra=.00965; |
---|
149 | } |
---|
150 | } |
---|
151 | } |
---|
152 | x=std::pow((r/p2),(1.-rr+pra))*(rr+pr*(r-p2)); |
---|
153 | } |
---|
154 | else |
---|
155 | { |
---|
156 | G4double sr=0.; |
---|
157 | if(n>7) |
---|
158 | { |
---|
159 | if(n>9) |
---|
160 | { |
---|
161 | if(n>10) sr=.86/(n+1+1.05); // >10(11) |
---|
162 | else sr=.0774; // 10 |
---|
163 | } |
---|
164 | else |
---|
165 | { |
---|
166 | if(n>8) sr=.0849; // 9 |
---|
167 | else sr=.0938; // 8 |
---|
168 | } |
---|
169 | } |
---|
170 | else |
---|
171 | { |
---|
172 | if(n>5) |
---|
173 | { |
---|
174 | if(n>6) sr=.1047; // 7 |
---|
175 | else sr=.1179; // 6 |
---|
176 | } |
---|
177 | else |
---|
178 | { |
---|
179 | if(n>7) sr=.1339; // 5 |
---|
180 | else sr=.15135; // 4 |
---|
181 | } |
---|
182 | } |
---|
183 | x=1.-std::sqrt((1.-r)/(1.-p2))*(1.-rr+sr*(p2-r)); |
---|
184 | } |
---|
185 | } |
---|
186 | } |
---|
187 | G4double dx=x; |
---|
188 | G4double f=poli(x,n)-r; |
---|
189 | G4int it=0; |
---|
190 | while(std::fabs(f/r)>eps) |
---|
191 | { |
---|
192 | it++; |
---|
193 | G4double df=dpoli(x,n); |
---|
194 | //G4cout<<"n="<<n<<", r="<<r<<", f="<<f<<", d="<<df<<", x="<<x<<", i="<<it<<G4endl; |
---|
195 | x-=f/df; |
---|
196 | f=poli(x,n)-r; |
---|
197 | } |
---|
198 | dx=std::fabs(dx-x); |
---|
199 | G4double d=std::fabs(f/r); |
---|
200 | G4cout<<"n="<<n<<",r="<<r<<", Final: f="<<d<<",x="<<x<<",d="<<dx<<",it="<<it<<G4endl; |
---|
201 | } // End of loop over r |
---|
202 | } // End of loop over n |
---|
203 | return 0; |
---|
204 | } |
---|