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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 /processes/electromagnetic/dna/models/src/G4VDNAModel.cc (Version 11.3.0) and /processes/electromagnetic/dna/models/src/G4VDNAModel.cc (Version 8.1.p2)


  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 // Authors: S. Meylan and C. Villagrasa (IRSN,    
 27 // This class is used to support PTB models th    
 28 // M. Bug et al, Rad. Phys and Chem. 130, 459-    
 29 //                                                
 30                                                   
 31 #include "G4VDNAModel.hh"                         
 32                                                   
 33 #include "G4ParticleTable.hh"                     
 34 #include "G4SystemOfUnits.hh"                     
 35                                                   
 36 G4VDNAModel::G4VDNAModel(const G4String& nam,     
 37   : G4VEmModel(nam), fStringOfMaterials(applyT    
 38 {}                                                
 39                                                   
 40 G4VDNAModel::~G4VDNAModel() = default;            
 41                                                   
 42 void G4VDNAModel::AddCrossSectionData(const st    
 43                                       const G4    
 44                                       const G4    
 45                                       const G4    
 46 {                                                 
 47   fModelMaterials.push_back(materialID);          
 48   fModelParticles.push_back(particleName);        
 49   fModelCSFiles.push_back(fileCS);                
 50   fModelDiffCSFiles.push_back(fileDiffCS);        
 51   fModelScaleFactors.push_back(scaleFactor);      
 52 }                                                 
 53                                                   
 54 void G4VDNAModel::AddCrossSectionData(const st    
 55                                       const G4    
 56                                       const G4    
 57 {                                                 
 58   fModelMaterials.push_back(materialID);          
 59   fModelParticles.push_back(particleName);        
 60   fModelCSFiles.push_back(fileCS);                
 61   fModelScaleFactors.push_back(scaleFactor);      
 62 }                                                 
 63                                                   
 64 void G4VDNAModel::LoadCrossSectionData(const G    
 65 {                                                 
 66   G4String fileElectron, fileDiffElectron = ""    
 67   G4String materialName, modelParticleName;       
 68   G4double scaleFactor;                           
 69   std::size_t materialID;                         
 70                                                   
 71   const G4ParticleDefinition* pParticle;          
 72                                                   
 73   // construct applyToMatVect with materials s    
 74   std::vector<G4String> applyToMatVect = Build    
 75                                                   
 76   // iterate on each material contained into t    
 77   // applyToMatVect)                              
 78   for (const auto & i : applyToMatVect) {         
 79     auto pMat = G4Material::GetMaterial(i, fal    
 80     if (i != "all" && pMat == nullptr) {          
 81       continue;                                   
 82     }                                             
 83                                                   
 84     // We have selected a material coming from    
 85     // We try to find if this material corresp    
 86     // If it is, then isMatFound becomes true     
 87     G4bool isMatFound = false;                    
 88                                                   
 89     // We iterate on each model registered mat    
 90     // We have to do a for loop because of the    
 91     // applyToMatVect[i] == "all" implies appl    
 92     // registered materials                       
 93     for (std::size_t j = 0; j < fModelMaterial    
 94       if (i == "all" || pMat->GetIndex() == fM    
 95         isMatFound = true;                        
 96         materialID = fModelMaterials[j];          
 97         pParticle = fModelParticles[j];           
 98         fileElectron = fModelCSFiles[j];          
 99         if (!fModelDiffCSFiles.empty()) fileDi    
100         scaleFactor = fModelScaleFactors[j];      
101                                                   
102         ReadAndSaveCSFile(materialID, pParticl    
103                                                   
104         if (!fileDiffElectron.empty())            
105           ReadDiffCSFile(materialID, pParticle    
106       }                                           
107     }                                             
108                                                   
109     // check if we found a correspondance, if     
110     if (!isMatFound) {                            
111       std::ostringstream oss;                     
112       oss << i                                    
113           << " material was not found. It mean    
114              "not a model material for ";         
115       oss << particleName;                        
116       G4Exception("G4VDNAModel::LoadCrossSecti    
117       return;                                     
118     }                                             
119   }                                               
120 }                                                 
121                                                   
122 void G4VDNAModel::ReadDiffCSFile(const std::si    
123                                  const G4doubl    
124 {                                                 
125   G4String text(                                  
126     "ReadDiffCSFile must be implemented in the    
127     "file");                                      
128                                                   
129   G4Exception("G4VDNAModel::ReadDiffCSFile", "    
130 }                                                 
131                                                   
132 void G4VDNAModel::EnableForMaterialAndParticle    
133                                                   
134 {                                                 
135   fData[materialID][p] = nullptr;                 
136 }                                                 
137                                                   
138 std::vector<G4String> G4VDNAModel::BuildApplyT    
139 {                                                 
140   // output material vector                       
141   std::vector<G4String> materialVect;             
142                                                   
143   // if we don't find any "/" then it means we    
144   if (materials.find('/') == std::string::npos    
145     // we add the material to the output vecto    
146     materialVect.push_back(materials);            
147   }                                               
148   // if we have several materials listed in th    
149   else {                                          
150     G4String materialsNonIdentified = material    
151                                                   
152     while (materialsNonIdentified.find_first_o    
153       // we select the first material and stop    
154       const G4String& mat = materialsNonIdenti    
155       materialVect.push_back(mat);                
156                                                   
157       // we remove the previous material from     
158       materialsNonIdentified = materialsNonIde    
159         materialsNonIdentified.find_first_of('    
160         materialsNonIdentified.size() - materi    
161     }                                             
162                                                   
163     // we don't find "/" anymore, it means we     
164     // we get it                                  
165     materialVect.push_back(std::move(materials    
166   }                                               
167                                                   
168   return materialVect;                            
169 }                                                 
170                                                   
171 void G4VDNAModel::ReadAndSaveCSFile(const std:    
172                                     const G4St    
173 {                                                 
174   fData[materialID][p] =                          
175     std::make_unique<G4DNACrossSectionDataSet>    
176   fData[materialID][p]->LoadData(file);           
177 }                                                 
178                                                   
179 G4int G4VDNAModel::RandomSelectShell(const G4d    
180                                      const std    
181 {                                                 
182   G4int level = 0;                                
183                                                   
184   auto pos = fData[materialID].find(particle);    
185                                                   
186   if (pos != fData[materialID].end()) {           
187     G4DNACrossSectionDataSet* table = pos->sec    
188                                                   
189     if (table != nullptr) {                       
190       auto valuesBuffer = new G4double[table->    
191       auto n = (G4int)table->NumberOfComponent    
192       G4int i(n);                                 
193       G4double value = 0.;                        
194                                                   
195       while (i > 0) {                             
196         --i;                                      
197         valuesBuffer[i] = table->GetComponent(    
198         value += valuesBuffer[i];                 
199       }                                           
200                                                   
201       value *= G4UniformRand();                   
202                                                   
203       i = n;                                      
204                                                   
205       while (i > 0) {                             
206         --i;                                      
207                                                   
208         if (valuesBuffer[i] > value) {            
209           delete[] valuesBuffer;                  
210           return i;                               
211         }                                         
212         value -= valuesBuffer[i];                 
213       }                                           
214                                                   
215       delete[] valuesBuffer;                      
216     }                                             
217   }                                               
218   else {                                          
219     G4cout << "particle : " << particle->GetPa    
220            << " Materials : " << (*G4Material:    
221            << this->GetName() << G4endl;          
222     G4Exception("G4VDNAModel::RandomSelectShel    
223                 "Model not applicable to parti    
224   }                                               
225   return level;                                   
226 }                                                 
227                                                   
228 G4bool G4VDNAModel::IsMaterialDefine(const std    
229 {                                                 
230   // Check if the given material is defined in    
231                                                   
232   G4bool exist(false);                            
233                                                   
234   G4double matTableSize = G4Material::GetMater    
235                                                   
236   for (int i = 0; i < matTableSize; i++) {        
237     if (materialID == G4Material::GetMaterialT    
238       exist = true;                               
239       return exist;                               
240     }                                             
241   }                                               
242                                                   
243   G4Exception("G4VDNAModel::IsMaterialDefine",    
244               "Materials are not defined!!");     
245   return exist;                                   
246 }                                                 
247                                                   
248 G4bool G4VDNAModel::IsMaterialExistingInModel(    
249 {                                                 
250   // Check if the given material is defined in    
251                                                   
252   for (const auto& it : fModelMaterials) {        
253     if (it == materialID) {                       
254       return true;                                
255     }                                             
256   }                                               
257   return false;                                   
258 }                                                 
259                                                   
260 G4bool G4VDNAModel::IsParticleExistingInModelF    
261                                                   
262 {                                                 
263   // To check two things:                         
264   // 1- is the material existing in model ?       
265   // 2- if yes, is the particle defined for th    
266                                                   
267   if (IsMaterialExistingInModel(materialID)) {    
268     for (const auto& it : fModelParticles) {      
269       if (it == particleName) {                   
270         return true;                              
271       }                                           
272     }                                             
273   }                                               
274   return false;                                   
275 }                                                 
276