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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 4.0)


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