#include <G4EMDataSet.hh>
Inheritance diagram for G4EMDataSet:
Public Member Functions | |
G4EMDataSet (G4int argZ, G4VDataSetAlgorithm *algo, G4double xUnit=CLHEP::MeV, G4double yUnit=CLHEP::barn, G4bool random=false) | |
G4EMDataSet (G4int argZ, G4DataVector *xData, G4DataVector *data, G4VDataSetAlgorithm *algo, G4double xUnit=CLHEP::MeV, G4double yUnit=CLHEP::barn, G4bool random=false) | |
G4EMDataSet (G4int argZ, G4DataVector *xData, G4DataVector *data, G4DataVector *xLogData, G4DataVector *Logdata, G4VDataSetAlgorithm *algo, G4double xUnit=CLHEP::MeV, G4double yUnit=CLHEP::barn, G4bool random=false) | |
virtual | ~G4EMDataSet () |
virtual G4double | FindValue (G4double x, G4int componentId=0) const |
virtual void | PrintData (void) const |
virtual const G4VEMDataSet * | GetComponent (G4int) const |
virtual void | AddComponent (G4VEMDataSet *) |
virtual size_t | NumberOfComponents (void) const |
virtual const G4DataVector & | GetEnergies (G4int) const |
virtual const G4DataVector & | GetData (G4int) const |
virtual const G4DataVector & | GetLogEnergies (G4int) const |
virtual const G4DataVector & | GetLogData (G4int) const |
virtual void | SetEnergiesData (G4DataVector *xData, G4DataVector *data, G4int componentId) |
virtual void | SetLogEnergiesData (G4DataVector *xData, G4DataVector *data, G4DataVector *xLogData, G4DataVector *Logdata, G4int componentId) |
virtual G4bool | LoadData (const G4String &fileName) |
virtual G4bool | LoadNonLogData (const G4String &fileName) |
virtual G4bool | SaveData (const G4String &fileName) const |
virtual G4double | RandomSelect (G4int componentId=0) const |
Definition at line 58 of file G4EMDataSet.hh.
G4EMDataSet::G4EMDataSet | ( | G4int | argZ, | |
G4VDataSetAlgorithm * | algo, | |||
G4double | xUnit = CLHEP::MeV , |
|||
G4double | yUnit = CLHEP::barn , |
|||
G4bool | random = false | |||
) |
Definition at line 62 of file G4EMDataSet.cc.
References FatalException, G4EMDataSet(), and G4Exception().
Referenced by G4EMDataSet().
00066 : 00067 z(Z), 00068 energies(0), 00069 data(0), 00070 log_energies(0), 00071 log_data(0), 00072 algorithm(algo), 00073 unitEnergies(xUnit), 00074 unitData(yUnit), 00075 pdf(0), 00076 randomSet(random) 00077 { 00078 if (algorithm == 0) { 00079 G4Exception("G4EMDataSet::G4EMDataSet", 00080 "em1012",FatalException,"interpolation == 0"); 00081 } else if (randomSet) { BuildPdf(); } 00082 }
G4EMDataSet::G4EMDataSet | ( | G4int | argZ, | |
G4DataVector * | xData, | |||
G4DataVector * | data, | |||
G4VDataSetAlgorithm * | algo, | |||
G4double | xUnit = CLHEP::MeV , |
|||
G4double | yUnit = CLHEP::barn , |
|||
G4bool | random = false | |||
) |
Definition at line 84 of file G4EMDataSet.cc.
References FatalException, G4EMDataSet(), and G4Exception().
00090 : 00091 z(argZ), 00092 energies(dataX), 00093 data(dataY), 00094 log_energies(0), 00095 log_data(0), 00096 algorithm(algo), 00097 unitEnergies(xUnit), 00098 unitData(yUnit), 00099 pdf(0), 00100 randomSet(random) 00101 { 00102 if (algorithm == 0) { 00103 G4Exception("G4EMDataSet::G4EMDataSet", 00104 "em1012",FatalException,"interpolation == 0"); 00105 } else if ((energies == 0) ^ (data == 0)) { 00106 G4Exception("G4EMDataSet::G4EMDataSet", 00107 "em1012",FatalException,"different size for energies and data (zero case)"); 00108 } else if (energies->size() != data->size()) { 00109 G4Exception("G4EMDataSet::G4EMDataSet", 00110 "em1012",FatalException,"different size for energies and data"); 00111 } else if (randomSet) { 00112 BuildPdf(); 00113 } 00114 }
G4EMDataSet::G4EMDataSet | ( | G4int | argZ, | |
G4DataVector * | xData, | |||
G4DataVector * | data, | |||
G4DataVector * | xLogData, | |||
G4DataVector * | Logdata, | |||
G4VDataSetAlgorithm * | algo, | |||
G4double | xUnit = CLHEP::MeV , |
|||
G4double | yUnit = CLHEP::barn , |
|||
G4bool | random = false | |||
) |
Definition at line 116 of file G4EMDataSet.cc.
References FatalException, G4EMDataSet(), and G4Exception().
00124 : 00125 z(argZ), 00126 energies(dataX), 00127 data(dataY), 00128 log_energies(dataLogX), 00129 log_data(dataLogY), 00130 algorithm(algo), 00131 unitEnergies(xUnit), 00132 unitData(yUnit), 00133 pdf(0), 00134 randomSet(random) 00135 { 00136 if (algorithm == 0) { 00137 G4Exception("G4EMDataSet::G4EMDataSet", 00138 "em1012",FatalException,"interpolation == 0"); 00139 } else if ((energies == 0) ^ (data == 0)) { 00140 G4Exception("G4EMDataSet::G4EMDataSet", 00141 "em1012",FatalException,"different size for energies and data (zero case)"); 00142 } else if (energies->size() != data->size()) { 00143 G4Exception("G4EMDataSet::G4EMDataSet", 00144 "em1012",FatalException,"different size for energies and data"); 00145 } else if ((log_energies == 0) ^ (log_data == 0)) { 00146 G4Exception("G4EMDataSet::G4EMDataSet", 00147 "em1012",FatalException,"different size for log energies and log data (zero case)"); 00148 } else if (log_energies->size() != log_data->size()) { 00149 G4Exception("G4EMDataSet::G4EMDataSet", 00150 "em1012",FatalException,"different size for log energies and log data"); 00151 } else if (randomSet) { 00152 BuildPdf(); 00153 } 00154 }
G4EMDataSet::~G4EMDataSet | ( | ) | [virtual] |
Definition at line 157 of file G4EMDataSet.cc.
00158 { 00159 delete algorithm; 00160 delete energies; 00161 delete data; 00162 delete pdf; 00163 delete log_energies; 00164 delete log_data; 00165 }
virtual void G4EMDataSet::AddComponent | ( | G4VEMDataSet * | ) | [inline, virtual] |
Implements G4VEMDataSet.
Definition at line 168 of file G4EMDataSet.cc.
References G4VDataSetAlgorithm::Calculate(), FatalException, and G4Exception().
00169 { 00170 if (!energies) { 00171 G4Exception("G4EMDataSet::FindValue", 00172 "em1012",FatalException,"energies == 0"); 00173 return 0.0; 00174 } else if (energies->empty()) { 00175 return 0.0; 00176 } else if (energy <= (*energies)[0]) { 00177 return (*data)[0]; 00178 } 00179 size_t i = energies->size()-1; 00180 if (energy >= (*energies)[i]) { return (*data)[i]; } 00181 00182 //Nicolas A. Karakatsanis: Check if the logarithmic data have been loaded to decide 00183 // which Interpolation-Calculation method will be applied 00184 if (log_energies != 0) 00185 { 00186 return algorithm->Calculate(energy, FindLowerBound(energy), *energies, *data, *log_energies, *log_data); 00187 } 00188 00189 return algorithm->Calculate(energy, FindLowerBound(energy), *energies, *data); 00190 }
virtual const G4VEMDataSet* G4EMDataSet::GetComponent | ( | G4int | ) | const [inline, virtual] |
virtual const G4DataVector& G4EMDataSet::GetData | ( | G4int | ) | const [inline, virtual] |
virtual const G4DataVector& G4EMDataSet::GetEnergies | ( | G4int | ) | const [inline, virtual] |
virtual const G4DataVector& G4EMDataSet::GetLogData | ( | G4int | ) | const [inline, virtual] |
virtual const G4DataVector& G4EMDataSet::GetLogEnergies | ( | G4int | ) | const [inline, virtual] |
Implements G4VEMDataSet.
Definition at line 292 of file G4EMDataSet.cc.
References FatalException, and G4Exception().
00293 { 00294 // The file is organized into four columns: 00295 // 1st column contains the values of energy 00296 // 2nd column contains the corresponding data value 00297 // The file terminates with the pattern: -1 -1 00298 // -2 -2 00299 00300 G4String fullFileName(FullFileName(fileName)); 00301 std::ifstream in(fullFileName); 00302 00303 if (!in.is_open()) 00304 { 00305 G4String message("data file \""); 00306 message += fullFileName; 00307 message += "\" not found"; 00308 G4Exception("G4EMDataSet::LoadData", 00309 "em1012",FatalException,message); 00310 return false; 00311 } 00312 00313 delete energies; 00314 delete data; 00315 delete log_energies; 00316 delete log_data; 00317 energies = new G4DataVector; 00318 data = new G4DataVector; 00319 log_energies = new G4DataVector; 00320 log_data = new G4DataVector; 00321 00322 G4double a, b; 00323 //G4int k = 0; 00324 //G4int nColumns = 2; 00325 00326 do 00327 { 00328 in >> a >> b; 00329 00330 if (a != -1 && a != -2) 00331 { 00332 if (a==0.) { a=1e-300; } 00333 if (b==0.) { b=1e-300; } 00334 a *= unitEnergies; 00335 b *= unitData; 00336 energies->push_back(a); 00337 log_energies->push_back(std::log10(a)); 00338 data->push_back(b); 00339 log_data->push_back(std::log10(b)); 00340 } 00341 } 00342 while (a != -2); 00343 00344 if (randomSet) { BuildPdf(); } 00345 00346 return true; 00347 }
Implements G4VEMDataSet.
Definition at line 350 of file G4EMDataSet.cc.
References FatalException, G4Exception(), and SetEnergiesData().
00351 { 00352 // The file is organized into four columns: 00353 // 1st column contains the values of energy 00354 // 2nd column contains the corresponding data value 00355 // The file terminates with the pattern: -1 -1 00356 // -2 -2 00357 00358 G4String fullFileName(FullFileName(fileName)); 00359 std::ifstream in(fullFileName); 00360 if (!in.is_open()) 00361 { 00362 G4String message("data file \""); 00363 message += fullFileName; 00364 message += "\" not found"; 00365 G4Exception("G4EMDataSet::LoadNonLogData", 00366 "em1012",FatalException,message); 00367 } 00368 00369 G4DataVector* argEnergies=new G4DataVector; 00370 G4DataVector* argData=new G4DataVector; 00371 00372 G4double a; 00373 G4int k = 0; 00374 G4int nColumns = 2; 00375 00376 do 00377 { 00378 in >> a; 00379 00380 if (a != -1 && a != -2) 00381 { 00382 if (k%nColumns == 0) 00383 { 00384 argEnergies->push_back(a*unitEnergies); 00385 } 00386 else if (k%nColumns == 1) 00387 { 00388 argData->push_back(a*unitData); 00389 } 00390 k++; 00391 } 00392 } 00393 while (a != -2); 00394 00395 SetEnergiesData(argEnergies, argData, 0); 00396 00397 if (randomSet) BuildPdf(); 00398 00399 return true; 00400 }
virtual size_t G4EMDataSet::NumberOfComponents | ( | void | ) | const [inline, virtual] |
void G4EMDataSet::PrintData | ( | void | ) | const [virtual] |
Implements G4VEMDataSet.
Definition at line 193 of file G4EMDataSet.cc.
References G4cout, and G4endl.
00194 { 00195 if (!energies) 00196 { 00197 G4cout << "Data not available." << G4endl; 00198 } 00199 else 00200 { 00201 size_t size = energies->size(); 00202 for (size_t i(0); i<size; i++) 00203 { 00204 G4cout << "Point: " << ((*energies)[i]/unitEnergies) 00205 << " - Data value: " << ((*data)[i]/unitData); 00206 if (pdf != 0) G4cout << " - PDF : " << (*pdf)[i]; 00207 G4cout << G4endl; 00208 } 00209 } 00210 }
Implements G4VEMDataSet.
Definition at line 555 of file G4EMDataSet.cc.
References G4VDataSetAlgorithm::Calculate(), G4LinInterpolation::Calculate(), FatalException, G4Exception(), and G4UniformRand.
00556 { 00557 G4double value = 0.; 00558 // Random select a X value according to the cumulative probability distribution 00559 // derived from the data 00560 00561 if (!pdf) { 00562 G4Exception("G4EMDataSet::RandomSelect", 00563 "em1012",FatalException,"PDF has not been created for this data set"); 00564 return value; 00565 } 00566 00567 G4double x = G4UniformRand(); 00568 00569 // Locate the random value in the X vector based on the PDF 00570 size_t bin = FindLowerBound(x,pdf); 00571 00572 // Interpolate the PDF to calculate the X value: 00573 // linear interpolation in the first bin (to avoid problem with 0), 00574 // interpolation with associated data set algorithm in other bins 00575 00576 G4LinInterpolation linearAlgo; 00577 if (bin == 0) value = linearAlgo.Calculate(x, bin, *pdf, *energies); 00578 else value = algorithm->Calculate(x, bin, *pdf, *energies); 00579 00580 // G4cout << x << " random bin "<< bin << " - " << value << G4endl; 00581 return value; 00582 }
Implements G4VEMDataSet.
Definition at line 404 of file G4EMDataSet.cc.
References FatalException, and G4Exception().
00405 { 00406 // The file is organized into two columns: 00407 // 1st column is the energy 00408 // 2nd column is the corresponding value 00409 // The file terminates with the pattern: -1 -1 00410 // -2 -2 00411 00412 G4String fullFileName(FullFileName(name)); 00413 std::ofstream out(fullFileName); 00414 00415 if (!out.is_open()) 00416 { 00417 G4String message("cannot open \""); 00418 message+=fullFileName; 00419 message+="\""; 00420 G4Exception("G4EMDataSet::SaveData", 00421 "em1012",FatalException,message); 00422 } 00423 00424 out.precision(10); 00425 out.width(15); 00426 out.setf(std::ofstream::left); 00427 00428 if (energies!=0 && data!=0) 00429 { 00430 G4DataVector::const_iterator i(energies->begin()); 00431 G4DataVector::const_iterator endI(energies->end()); 00432 G4DataVector::const_iterator j(data->begin()); 00433 00434 while (i!=endI) 00435 { 00436 out.precision(10); 00437 out.width(15); 00438 out.setf(std::ofstream::left); 00439 out << ((*i)/unitEnergies) << ' '; 00440 00441 out.precision(10); 00442 out.width(15); 00443 out.setf(std::ofstream::left); 00444 out << ((*j)/unitData) << std::endl; 00445 00446 i++; 00447 j++; 00448 } 00449 } 00450 00451 out.precision(10); 00452 out.width(15); 00453 out.setf(std::ofstream::left); 00454 out << -1.f << ' '; 00455 00456 out.precision(10); 00457 out.width(15); 00458 out.setf(std::ofstream::left); 00459 out << -1.f << std::endl; 00460 00461 out.precision(10); 00462 out.width(15); 00463 out.setf(std::ofstream::left); 00464 out << -2.f << ' '; 00465 00466 out.precision(10); 00467 out.width(15); 00468 out.setf(std::ofstream::left); 00469 out << -2.f << std::endl; 00470 00471 return true; 00472 }
void G4EMDataSet::SetEnergiesData | ( | G4DataVector * | xData, | |
G4DataVector * | data, | |||
G4int | componentId | |||
) | [virtual] |
Implements G4VEMDataSet.
Definition at line 213 of file G4EMDataSet.cc.
References FatalException, and G4Exception().
Referenced by LoadNonLogData().
00216 { 00217 if (energies) { delete energies; } 00218 energies = dataX; 00219 00220 if (data) { delete data; } 00221 data = dataY; 00222 00223 if ((energies == 0) ^ (data==0)) { 00224 G4Exception("G4EMDataSet::SetEnergiesData", 00225 "em1012",FatalException,"different size for energies and data (zero case)"); 00226 return; 00227 } else if (energies == 0) { return; } 00228 00229 //G4cout << "Size of energies: " << energies->size() << G4endl << "Size of data: " << data->size() << G4endl; 00230 if (energies->size() != data->size()) { 00231 G4Exception("G4EMDataSet::SetEnergiesData", 00232 "em1012",FatalException,"different size for energies and data"); 00233 } 00234 }
void G4EMDataSet::SetLogEnergiesData | ( | G4DataVector * | xData, | |
G4DataVector * | data, | |||
G4DataVector * | xLogData, | |||
G4DataVector * | Logdata, | |||
G4int | componentId | |||
) | [virtual] |
Implements G4VEMDataSet.
Definition at line 236 of file G4EMDataSet.cc.
References FatalException, and G4Exception().
00241 { 00242 //Load of the actual energy and data values 00243 if (energies) { delete energies; } 00244 energies = dataX; 00245 if (data) { delete data; } 00246 data = dataY; 00247 //Load of the logarithmic energy and data values 00248 if (log_energies) { delete log_energies; } 00249 log_energies = data_logX; 00250 if (log_data) { delete log_data; } 00251 log_data = data_logY; 00252 00253 //Check if data loaded properly from data files 00254 if ( !energies ) { 00255 if(data || log_energies || log_data ) { 00256 G4Exception("G4EMDataSet::SetLogEnergiesData", 00257 "em1012",FatalException,"inconsistent data"); 00258 } 00259 return; 00260 } else { 00261 if ( !data ) { 00262 G4Exception("G4EMDataSet::SetLogEnergiesData", 00263 "em1012",FatalException,"only energy, no data"); 00264 return; 00265 } else if (energies->size() != data->size()) { 00266 G4Exception("G4EMDataSet::SetLogEnergiesData", 00267 "em1012",FatalException,"different size for energies and data"); 00268 return; 00269 } 00270 //G4cout << "Size of energies: " << energies->size() << G4endl << "Size of data: " << data->size() << G4endl << G4endl; 00271 00272 //Check if logarithmic data loaded properly from data files 00273 if ( !log_energies ) { 00274 if(log_data) { 00275 G4Exception("G4EMDataSet::SetLogEnergiesData", 00276 "em1012",FatalException,"inconsistence of log_data"); 00277 } 00278 return; 00279 } else { 00280 if ( !log_data ) { 00281 G4Exception("G4EMDataSet::SetLogEnergiesData", 00282 "em1012",FatalException,"only log_energies, no data"); 00283 } else if ((log_energies->size() != log_data->size()) || (log_energies->size() != data->size())) { 00284 G4Exception("G4EMDataSet::SetLogEnergiesData", 00285 "em1012",FatalException,"different size for log energies and data"); 00286 } 00287 } 00288 } 00289 //G4cout << "Size of log energies: " << log_energies->size() << G4endl << "Size of log data: " << log_data->size() << G4endl; 00290 }