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] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /examples/advanced/xray_fluorescence/src/XrayFluoDataSet.cc (Version 11.3.0) and /examples/advanced/xray_fluorescence/src/XrayFluoDataSet.cc (Version 10.7.p4)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 //                                                 26 //
 27 //                                                 27 //
 28 // Author: Elena Guardincerri (Elena.Guardince     28 // Author: Elena Guardincerri (Elena.Guardincerri@ge.infn.it)
 29 //                                                 29 //
 30 // History:                                        30 // History:
 31 // -----------                                     31 // -----------
 32 // 28 Nov 2001 Elena Guardincerri     Created      32 // 28 Nov 2001 Elena Guardincerri     Created
 33 //                                                 33 //
 34 // -------------------------------------------     34 // -------------------------------------------------------------------
 35                                                    35 
 36 #include "XrayFluoDataSet.hh"                      36 #include "XrayFluoDataSet.hh"
 37 #include <fstream>                                 37 #include <fstream>
 38 #include "G4VDataSetAlgorithm.hh"                  38 #include "G4VDataSetAlgorithm.hh"
 39                                                    39 
 40 XrayFluoDataSet::XrayFluoDataSet(G4int /*Z*/,      40 XrayFluoDataSet::XrayFluoDataSet(G4int /*Z*/,
 41        G4DataVector* points,                       41        G4DataVector* points, 
 42        G4DataVector* values,                       42        G4DataVector* values,
 43        const G4VDataSetAlgorithm* interpolatio     43        const G4VDataSetAlgorithm* interpolation,
 44        G4double unitE, G4double unitData)          44        G4double unitE, G4double unitData)
 45   :energies(points), data(values), algorithm(i     45   :energies(points), data(values), algorithm(interpolation)
 46 {                                                  46 {
 47   numberOfBins = energies->size();                 47   numberOfBins = energies->size();
 48   unit1 = unitE;                                   48   unit1 = unitE;
 49   unit2 = unitData;                                49   unit2 = unitData;
 50 }                                                  50 }
 51                                                    51 
 52 //....oooOO0OOooo........oooOO0OOooo........oo     52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 53                                                    53 
 54 XrayFluoDataSet:: XrayFluoDataSet(G4int /*Z*/,     54 XrayFluoDataSet:: XrayFluoDataSet(G4int /*Z*/, 
 55         const G4String& dataFile,                  55         const G4String& dataFile,
 56         const G4VDataSetAlgorithm* interpolati     56         const G4VDataSetAlgorithm* interpolation,
 57         G4double unitE, G4double unitData)         57         G4double unitE, G4double unitData)
 58   : algorithm(interpolation)                       58   : algorithm(interpolation)
 59 {                                                  59 {
 60   energies = new G4DataVector;                     60   energies = new G4DataVector;
 61   data = new G4DataVector;                         61   data = new G4DataVector;
 62   unit1 = unitE;                                   62   unit1 = unitE;
 63   unit2 = unitData;                                63   unit2 = unitData;  
 64   LoadData(dataFile);                              64   LoadData(dataFile);
 65   numberOfBins = energies->size();                 65   numberOfBins = energies->size();
 66 }                                                  66 }
 67                                                    67 
 68 //....oooOO0OOooo........oooOO0OOooo........oo     68 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 69                                                    69 
 70 // Destructor                                      70 // Destructor
 71 XrayFluoDataSet::~XrayFluoDataSet()                71 XrayFluoDataSet::~XrayFluoDataSet()
 72 {                                                  72 { 
 73   delete energies;                                 73   delete energies;
 74   delete data;                                     74   delete data;
 75 }                                                  75 }
 76                                                    76 
 77 //....oooOO0OOooo........oooOO0OOooo........oo     77 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 78                                                    78 
 79 G4double XrayFluoDataSet::FindValue(G4double e     79 G4double XrayFluoDataSet::FindValue(G4double e, G4int) const
 80 {                                                  80 {
 81   G4double value;                                  81   G4double value;
 82   G4double e0 = (*energies)[0];                    82   G4double e0 = (*energies)[0];
 83   // Protections                                   83   // Protections
 84   size_t bin = FindBinLocation(e);                 84   size_t bin = FindBinLocation(e);
 85   if (bin == numberOfBins)                         85   if (bin == numberOfBins)
 86     {                                              86     {
 87                                                    87      
 88       value = (*data)[bin];                        88       value = (*data)[bin];
 89     }                                              89     }
 90   else if (e <= e0)                                90   else if (e <= e0)
 91     {                                              91     {
 92                                                    92     
 93       value = (*data)[0];                          93       value = (*data)[0];
 94     }                                              94     }
 95   else                                             95   else
 96     {                                              96     {
 97       value = algorithm->Calculate(e,bin,*ener     97       value = algorithm->Calculate(e,bin,*energies,*data);
 98     }                                              98     }
 99                                                    99   
100   return value;                                   100   return value;
101 }                                                 101 }
102                                                   102 
103 //....oooOO0OOooo........oooOO0OOooo........oo    103 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
104                                                   104 
105 G4int XrayFluoDataSet::FindBinLocation(G4doubl    105 G4int XrayFluoDataSet::FindBinLocation(G4double energy) const
106 {                                                 106 {
107   // Protection against call outside allowed r    107   // Protection against call outside allowed range
108   G4double e0 = (*energies)[0];                   108   G4double e0 = (*energies)[0];
109   if (energy < e0)                                109   if (energy < e0)
110     {                                             110     {
111                                                   111     
112       energy = e0;                                112       energy = e0;
113     }                                             113     }
114                                                   114 
115   size_t lowerBound = 0;                          115   size_t lowerBound = 0;
116   size_t upperBound = numberOfBins - 1;           116   size_t upperBound = numberOfBins - 1;
117                                                   117   
118   // Binary search                                118   // Binary search
119   while (lowerBound <= upperBound)                119   while (lowerBound <= upperBound) 
120     {                                             120     {
121       size_t midBin = (lowerBound + upperBound    121       size_t midBin = (lowerBound + upperBound)/2;
122       if ( energy < (*energies)[midBin] ) uppe    122       if ( energy < (*energies)[midBin] ) upperBound = midBin-1;
123       else lowerBound = midBin+1;                 123       else lowerBound = midBin+1;
124   }                                               124   }
125                                                   125  
126   return upperBound;                              126   return upperBound;
127 }                                                 127 }
128                                                   128 
129 //....oooOO0OOooo........oooOO0OOooo........oo    129 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
130                                                   130 
131 G4bool XrayFluoDataSet::LoadData(const G4Strin    131 G4bool XrayFluoDataSet::LoadData(const G4String& fileName)
132 {                                                 132 {
133   // Build the complete string identifying the    133   // Build the complete string identifying the file with the data set
134   G4String dirFile = "";                          134   G4String dirFile = "";
135                                                   135   
136   char* path;                                     136   char* path;
137                                                   137 
138   path = std::getenv("XRAYDATA");                 138   path = std::getenv("XRAYDATA");
139   if (!path)                                      139   if (!path)
140     path = std::getenv("PWD");                    140     path = std::getenv("PWD");
141                                                   141 
142   //G4cout << path << G4endl;                     142   //G4cout << path << G4endl;
143   //G4cout << fileName << G4endl;                 143   //G4cout << fileName << G4endl;
144                                                   144 
145                                                   145 
146   G4String pathString(path);                      146   G4String pathString(path);
147   pathString += "\0";                             147   pathString += "\0";
148   dirFile = pathString + "/" + fileName + ".da    148   dirFile = pathString + "/" + fileName + ".dat";
149                                                   149     
150   std::ifstream file(dirFile);                    150   std::ifstream file(dirFile);
151   std::filebuf* lsdp = file.rdbuf();              151   std::filebuf* lsdp = file.rdbuf();
152                                                   152   
153   if (! (lsdp->is_open()) )                       153   if (! (lsdp->is_open()) )
154   {                                               154   {
155     G4ExceptionDescription execp;                 155     G4ExceptionDescription execp;
156     execp << "XrayFluoDataSet - data file: " +    156     execp << "XrayFluoDataSet - data file: " + dirFile + " not found"<<G4endl;
157     G4Exception("XrayFluoDataSet::LoadData()",    157     G4Exception("XrayFluoDataSet::LoadData()","example-xray_fluorescence01",
158     FatalException, execp);                       158     FatalException, execp);
159   }                                               159   }
160   G4double a = 0;                                 160   G4double a = 0;
161   G4int k = 1;                                    161   G4int k = 1;
162                                                   162 
163   do                                              163   do
164     {                                             164     {
165       file >> a;                                  165       file >> a;
166       G4int nColumns = 2;                         166       G4int nColumns = 2;
167       // The file is organized into two column    167       // The file is organized into two columns:
168       // 1st column is the energy                 168       // 1st column is the energy
169       // 2nd column is the corresponding value    169       // 2nd column is the corresponding value
170       // The file terminates with the pattern:    170       // The file terminates with the pattern: -1   -1
171       //                                          171       //                                       -2   -2
172       if (a == -1 || a == -2)                     172       if (a == -1 || a == -2)
173   {                                               173   {
174                                                   174    
175   }                                               175   }
176       else                                        176       else
177   {                                               177   {
178     if (k%nColumns != 0)                          178     if (k%nColumns != 0)
179       {                                           179       { 
180         G4double e = a * unit1;                   180         G4double e = a * unit1;
181         energies->push_back(e);                   181         energies->push_back(e);
182                                                   182       
183         k++;                                      183         k++;
184                                                   184 
185       }                                           185       }
186     else if (k%nColumns == 0)                     186     else if (k%nColumns == 0)
187       {                                           187       {
188         G4double value = a * unit2;               188         G4double value = a * unit2;
189         data->push_back(value);                   189         data->push_back(value);
190                                                   190        
191         k = 1;                                    191         k = 1;
192       }                                           192       }
193   }                                               193   }
194                                                   194       
195     } while (a != -2); // end of file             195     } while (a != -2); // end of file
196                                                   196   
197   file.close();                                   197   file.close();
198   return true;                                    198   return true;
199                                                   199 
200 }                                                 200 }
201                                                   201 
202 //....oooOO0OOooo........oooOO0OOooo........oo    202 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
203                                                   203 
204 void XrayFluoDataSet::PrintData() const           204 void XrayFluoDataSet::PrintData() const
205 {                                                 205 {
206   size_t size = numberOfBins;                     206   size_t size = numberOfBins;
207   for (size_t i=0; i<size; i++)                   207   for (size_t i=0; i<size; i++)
208     {                                             208     {
209       G4double e = (*energies)[i]  / unit1;       209       G4double e = (*energies)[i]  / unit1;
210       G4double sigma = (*data)[i] / unit2 ;       210       G4double sigma = (*data)[i] / unit2 ;
211       G4cout << "Point: "                         211       G4cout << "Point: "
212        << e                                       212        << e
213        << " - Data value : "                      213        << " - Data value : "
214        << sigma                                   214        << sigma 
215        << G4endl;                                 215        << G4endl; 
216     }                                             216     }
217 }                                                 217 }
218                                                   218 
219                                                   219 
220                                                   220 
221                                                   221