Geant4-11
G4LEPTSElossDistr.cc
Go to the documentation of this file.
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#include "G4LEPTSElossDistr.hh"
28
29
31 fileName = file;
32
33 ReadFile();
34}
35
36
38{
40
41 FILE * fp;
42
43 if ((fp=fopen(fileName.c_str(), "r"))==NULL){
44 //G4cout << "Error reading " << fileName << G4endl;
45 NoBins = 0;
46 bFileFound = false;
47 return;
48 }
49
50 bFileFound = true;
51 // G4cout << "Read Eloss Distro (" << fileName << ") " << G4endl;
52 G4int nEnergies;
53 G4int nAngles;
54 G4int nData;
55 (void) fscanf(fp,"%i \n",&nEnergies);
56 for( G4int ie = 0; ie < nEnergies; ie++ ){
57 float energySep;
58 (void) fscanf(fp,"%f \n",&energySep);
59 (void) fscanf(fp,"%i \n",&nAngles);
60 for( G4int ia = 0; ia < nAngles; ia++ ){
61 float angleSep;
62 (void) fscanf(fp,"%f \n",&angleSep);
65 mddist angleDist;
66 angleDist[angleSep] = dist;
67 theDistributions[energySep] = angleDist;
68
69 (void) fscanf(fp,"%i \n",&nData);
70 if( dist->ReadFile( fp, nData ) ) {
71 G4Exception("G4LEPTSElossDistr",
72 "",
74 ("End of file found while reading file"+ fileName).c_str());
75 }
76 }
77 }
78
79 fclose(fp);
80
81}
82
83
84
86{
87// Sample Energy from Cumulative distr. G4interval [eMin, eMax]
88
89 if( eMin > eMax) return 0.0;
90
91 //Get the distribution to do the sampling
92 G4LEPTSDistribution* distr = 0;
93 if( theNDistributions == 1 ){
94 distr = (*( (*(theDistributions.begin())).second ).begin()).second;
95 } else{
96 mdmddist::const_iterator itedd;
97 for( itedd = theDistributions.begin(); itedd != theDistributions.end(); itedd++ ){
98 G4double energySep = (*itedd).first;
99 if( eMax < energySep ) {
100 //tt if( eMax <= energySep ) {
101 mddist dist1 = (*itedd).second;
102 mddist::const_iterator ited;
103 for( ited = dist1.begin(); ited != dist1.end(); ited++ ){
104 G4double angleSep = (*ited).first;
105 if( 1 < angleSep ) {
106 distr = (*ited).second;
107 break;
108 }
109 }
110 break;
111 }
112 }
113 }
114
115 // G4cout << " LEPTSElossDistr::Sample( " << distr << " NDIST " << theNDistributions << G4endl; //GDEB
116 return distr->Sample(eMin, eMax);
117}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::map< G4double, G4LEPTSDistribution * > mddist
static constexpr double second
Definition: G4SIunits.hh:137
double G4double
Definition: G4Types.hh:83
int G4int
Definition: G4Types.hh:85
G4double Sample(G4double, G4double)
void ReadFile(G4String fileName)
G4double Sample(G4double, G4double)
G4LEPTSElossDistr(std::string)