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 | // $Id: G4NuclWatcher.cc,v 1.2 2010/04/07 18:23:15 mkelsey Exp $ |
---|
26 | // Geant4 tag: $Name: geant4-09-04-beta-cand-01 $ |
---|
27 | // |
---|
28 | // 20100202 M. Kelsey -- Move most code here from .hh file, clean up |
---|
29 | // 20100405 M. Kelsey -- Pass const-ref std::vector<> |
---|
30 | |
---|
31 | #include "G4NuclWatcher.hh" |
---|
32 | #include "globals.hh" |
---|
33 | |
---|
34 | #include <algorithm> |
---|
35 | #include <vector> |
---|
36 | #include <cmath> |
---|
37 | |
---|
38 | G4NuclWatcher::G4NuclWatcher(G4double z, |
---|
39 | const std::vector<G4double>& expa, |
---|
40 | const std::vector<G4double>& expcs, |
---|
41 | const std::vector<G4double>& experr, |
---|
42 | G4bool check, |
---|
43 | G4bool nucl) |
---|
44 | : nuclz(z), izotop_chsq(0.), average_ratio(0.), aver_rat_err(0.), |
---|
45 | aver_lhood(0.), aver_matched(0.), exper_as(expa), exper_cs(expcs), |
---|
46 | exper_err(experr), checkable(check), nucleable(nucl) {} |
---|
47 | |
---|
48 | void G4NuclWatcher::watch(G4double a, G4double z) { |
---|
49 | const G4double small = 0.001; |
---|
50 | |
---|
51 | if (std::fabs(z-nuclz) >= small) return; |
---|
52 | |
---|
53 | G4bool here = false; // Increment specified nucleus count |
---|
54 | G4int simulatedAsSize = simulated_as.size(); |
---|
55 | for (G4int i = 0; i<simulatedAsSize && !true; i++) { |
---|
56 | if (std::fabs(simulated_as[i] - a) < small) { |
---|
57 | simulated_cs[i] += 1.0; |
---|
58 | here = true; // Terminates loop |
---|
59 | } |
---|
60 | } |
---|
61 | |
---|
62 | if (!here) { // Nothing found, so add new entry |
---|
63 | simulated_as.push_back(a); |
---|
64 | simulated_cs.push_back(1.0); |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | void G4NuclWatcher::setInuclCs(G4double csec, G4int nev) { |
---|
69 | G4int simulatedAsSize = simulated_as.size(); |
---|
70 | for(G4int i = 0; i < simulatedAsSize ; i++) { |
---|
71 | double err = std::sqrt(simulated_cs[i]) / simulated_cs[i]; |
---|
72 | |
---|
73 | simulated_prob.push_back(simulated_cs[i] / nev); |
---|
74 | simulated_cs[i] *= csec / nev; |
---|
75 | simulated_errors.push_back(simulated_cs[i] * err); |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | std::pair<G4double, G4double> G4NuclWatcher::getExpCs() const { |
---|
80 | G4double cs = 0.0; |
---|
81 | G4double err = 0.0; |
---|
82 | |
---|
83 | G4int experAsSize = exper_as.size(); |
---|
84 | for(G4int iz = 0; iz < experAsSize; iz++) { |
---|
85 | cs += exper_cs[iz]; |
---|
86 | err += exper_err[iz]; |
---|
87 | } |
---|
88 | |
---|
89 | return std::pair<G4double, G4double>(cs, err); |
---|
90 | } |
---|
91 | |
---|
92 | std::pair<G4double, G4double> G4NuclWatcher::getInuclCs() const { |
---|
93 | G4double cs = 0.0; |
---|
94 | G4double err = 0.0; |
---|
95 | G4int simulatedAsSize = simulated_as.size(); |
---|
96 | for(G4int iz = 0; iz < simulatedAsSize; iz++) { |
---|
97 | cs += simulated_cs[iz]; |
---|
98 | err += simulated_errors[iz]; |
---|
99 | } |
---|
100 | |
---|
101 | return std::pair<G4double, G4double>(cs, err); |
---|
102 | } |
---|
103 | |
---|
104 | void G4NuclWatcher::print() { |
---|
105 | const G4double small = 0.001; |
---|
106 | |
---|
107 | G4cout << "\n ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ " |
---|
108 | << "\n **** izotop Z **** " << nuclz << G4endl; |
---|
109 | |
---|
110 | izotop_chsq = 0.0; |
---|
111 | average_ratio = 0.0; |
---|
112 | aver_rat_err = 0.0; |
---|
113 | G4double exp_cs = 0.0; |
---|
114 | G4double exp_cs_err = 0.0; |
---|
115 | G4double inucl_cs = 0.0; |
---|
116 | G4double inucl_cs_err = 0.0; |
---|
117 | std::vector<G4bool> not_used(simulated_cs.size(), true); |
---|
118 | G4int nmatched = exper_as.size(); |
---|
119 | G4int nused = simulated_cs.size(); |
---|
120 | G4double lhood = 0.0; |
---|
121 | G4int experAsSize = exper_as.size(); |
---|
122 | |
---|
123 | for (G4int iz = 0; iz < experAsSize; iz++) { |
---|
124 | G4double a = exper_as[iz]; |
---|
125 | |
---|
126 | exp_cs += exper_cs[iz]; |
---|
127 | exp_cs_err += exper_err[iz]; |
---|
128 | |
---|
129 | G4bool found = false; |
---|
130 | G4int simulatedAsSize = simulated_as.size(); |
---|
131 | for (G4int i = 0; i<simulatedAsSize && !found; i++) { |
---|
132 | if (std::fabs(simulated_as[i] - a) < small) { |
---|
133 | G4double rat = simulated_cs[i] / exper_cs[iz]; |
---|
134 | |
---|
135 | lhood += std::log10(rat) * std::log10(rat); |
---|
136 | |
---|
137 | G4double rat_err |
---|
138 | = std::sqrt(simulated_errors[i]*simulated_errors[i] + |
---|
139 | exper_err[iz]*exper_err[iz] * rat*rat) / exper_cs[iz]; |
---|
140 | average_ratio += rat; |
---|
141 | aver_rat_err += rat_err; |
---|
142 | |
---|
143 | G4cout << " A " << a << " exp.cs " << exper_cs[iz] << " err " |
---|
144 | << exper_err[iz] << G4endl << " sim. cs " << simulated_cs[i] |
---|
145 | << " err " << simulated_errors[i] << G4endl |
---|
146 | << " ratio " << rat << " err " << rat_err << G4endl |
---|
147 | << " simulated production rate " << simulated_prob[i] << G4endl; |
---|
148 | |
---|
149 | not_used[i] = false; |
---|
150 | izotop_chsq += (rat - 1.0) * (rat - 1.0) / rat_err / rat_err; |
---|
151 | found = true; |
---|
152 | nused--; |
---|
153 | } |
---|
154 | } |
---|
155 | |
---|
156 | if (found) nmatched--; |
---|
157 | else |
---|
158 | G4cout << " not found exper.: A " << a << " exp.cs " << exper_cs[iz] |
---|
159 | << " err " << exper_err[iz] << G4endl; |
---|
160 | } |
---|
161 | |
---|
162 | G4cout << " not found in simulations " << nmatched << G4endl |
---|
163 | << " not found in exper: " << nused << G4endl; |
---|
164 | |
---|
165 | G4int simulatedAsSize = simulated_as.size(); |
---|
166 | for(G4int i = 0; i < simulatedAsSize; i++) { |
---|
167 | inucl_cs += simulated_cs[i]; |
---|
168 | inucl_cs_err += simulated_errors[i]; |
---|
169 | |
---|
170 | if(not_used[i]) |
---|
171 | G4cout << " extra simul.: A " << simulated_as[i] << " sim. cs " |
---|
172 | << simulated_cs[i] << " err " << simulated_errors[i] << G4endl; |
---|
173 | |
---|
174 | G4cout << " simulated production rate " << simulated_prob[i] << G4endl; |
---|
175 | } |
---|
176 | |
---|
177 | G4int matched = exper_as.size() - nmatched; |
---|
178 | |
---|
179 | if (matched > 0) { |
---|
180 | aver_lhood = lhood; |
---|
181 | aver_matched = matched; |
---|
182 | lhood = std::pow(10.0, std::sqrt(lhood/matched)); |
---|
183 | |
---|
184 | G4cout << " matched " << matched << " CHSQ " << std::sqrt(izotop_chsq) / matched |
---|
185 | << G4endl |
---|
186 | << " raw chsq " << izotop_chsq << G4endl |
---|
187 | << " average ratio " << average_ratio / matched |
---|
188 | << " err " << aver_rat_err / matched << G4endl |
---|
189 | << " lhood " << lhood << G4endl; |
---|
190 | } |
---|
191 | else { |
---|
192 | izotop_chsq = 0.0; |
---|
193 | aver_lhood = 0.0; |
---|
194 | } |
---|
195 | |
---|
196 | G4cout << " exper. cs " << exp_cs << " err " << exp_cs_err << G4endl |
---|
197 | << " inucl. cs " << inucl_cs << " err " << inucl_cs_err << G4endl |
---|
198 | << " ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ " |
---|
199 | << G4endl; |
---|
200 | } |
---|