Geant4 Cross Reference |
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 // $Id: G4DNAMolecularMaterial.cc 79184 2014-02-20 09:14:38Z gcosmo $ 26 // 27 // 27 // Author: Mathieu Karamitros << 28 // << 29 << 30 #include "G4DNAMolecularMaterial.hh" 28 #include "G4DNAMolecularMaterial.hh" 31 << 32 #include "G4AutoLock.hh" << 33 #include "G4Material.hh" 29 #include "G4Material.hh" 34 #include "G4MoleculeTable.hh" << 30 #include <utility> 35 #include "G4StateManager.hh" 31 #include "G4StateManager.hh" 36 #include "G4Threading.hh" 32 #include "G4Threading.hh" 37 << 33 #include "G4AutoLock.hh" 38 #include <utility> << 39 34 40 using namespace std; 35 using namespace std; 41 36 42 G4DNAMolecularMaterial* G4DNAMolecularMaterial << 37 G4DNAMolecularMaterial* G4DNAMolecularMaterial::fInstance(0); 43 << 38 //G4ThreadLocal G4DNAMolecularMaterial* G4DNAMolecularMaterial::fInstance(0); 44 namespace << 39 G4Mutex aMutex=G4MUTEX_INITIALIZER; 45 { << 46 G4Mutex aMutex = G4MUTEX_INITIALIZER; << 47 } << 48 40 49 //-------------------------------------------- << 50 41 51 bool CompareMaterial::operator()(const G4Mater << 42 bool CompareMaterial::operator() (const G4Material* mat1, const G4Material* mat2) const 52 const G4Mater << 53 { 43 { 54 if (mat1 == nullptr && mat2 == nullptr) retu << 44 if(mat1==0 && mat2==0) return false; //(mat1 == mat2) 55 if (mat1 == nullptr) return true; // mat1 < << 45 if(mat1==0) return true; // mat1 < mat2 56 if (mat2 == nullptr) return false; //mat2 < << 46 if(mat2==0) return false; //mat2 < mat1 57 47 58 const G4Material* baseMat1 = mat1->GetBaseMa << 48 const G4Material* baseMat1 = mat1->GetBaseMaterial(); 59 const G4Material* baseMat2 = mat2->GetBaseMa << 49 const G4Material* baseMat2 = mat2->GetBaseMaterial(); 60 50 61 if ((baseMat1 == nullptr) && (baseMat2 == nu << 51 if((baseMat1 || baseMat2) == 0) // None of the materials derives from a base material 62 // None of the materials derives from a ba << 52 { 63 return mat1 < mat2; << 53 return mat1 < mat2; 64 } << 54 } 65 if ((baseMat1 != nullptr) && (baseMat2 != nu << 55 else if(baseMat1 && baseMat2) // Both materials derive from a base material 66 // Both materials derive from a base mater << 56 { 67 return baseMat1 < baseMat2; << 57 return baseMat1 < baseMat2; 68 } << 58 } 69 59 70 if ((baseMat1 != nullptr) && (baseMat2 == nu << 60 else if(baseMat1 && (baseMat2 == 0)) // Only the material 1 derives from a base material 71 // Only the material 1 derives from a base << 61 { 72 return baseMat1 < mat2; << 62 return baseMat1 < mat2; 73 } << 63 } 74 // only case baseMat1==nullptr && baseMat2 r << 64 // only case baseMat1==0 && baseMat2 remains 75 return mat1 < baseMat2; << 65 return mat1 < baseMat2; 76 } 66 } 77 67 78 //-------------------------------------------- << 79 << 80 G4DNAMolecularMaterial* G4DNAMolecularMaterial 68 G4DNAMolecularMaterial* G4DNAMolecularMaterial::Instance() 81 { 69 { 82 if (fInstance == nullptr) fInstance = new G4 << 70 if(! fInstance) new G4DNAMolecularMaterial(); 83 return fInstance; << 71 return fInstance; 84 } 72 } 85 73 86 //-------------------------------------------- << 74 void G4DNAMolecularMaterial::DeleteInstance() >> 75 { >> 76 delete fInstance; >> 77 fInstance = 0; >> 78 } 87 79 88 void G4DNAMolecularMaterial::Create() 80 void G4DNAMolecularMaterial::Create() 89 { 81 { 90 fpCompFractionTable = nullptr; << 82 fpCompFractionTable = 0; 91 fpCompDensityTable = nullptr; << 83 fpCompDensityTable = 0; 92 fpCompNumMolPerVolTable = nullptr; << 84 fpCompNumMolPerVolTable = 0; 93 fIsInitialized = false; << 85 fIsInitialized = false; 94 fNMaterials = 0; << 86 fNMaterials = 0; >> 87 fInstance = this; 95 } 88 } 96 89 97 //-------------------------------------------- << 90 G4DNAMolecularMaterial::G4DNAMolecularMaterial() :G4VStateDependent() 98 << 99 void G4DNAMolecularMaterial::Clear() << 100 { 91 { 101 G4AutoLock l2(&aMutex); << 92 Create(); 102 if (fpCompFractionTable != nullptr){ << 93 fInstance = this; 103 fpCompFractionTable->clear(); << 104 delete fpCompFractionTable; << 105 fpCompFractionTable = nullptr; << 106 } << 107 if (fpCompDensityTable != nullptr){ << 108 fpCompDensityTable->clear(); << 109 delete fpCompDensityTable; << 110 fpCompDensityTable = nullptr; << 111 } << 112 if (fpCompNumMolPerVolTable != nullptr){ << 113 fpCompNumMolPerVolTable->clear(); << 114 delete fpCompNumMolPerVolTable; << 115 fpCompNumMolPerVolTable = nullptr; << 116 } << 117 << 118 std::map<const G4Material*, std::vector<G4do << 119 << 120 for (it = fAskedDensityTable.begin(); it != << 121 if (it->second != nullptr){ << 122 delete it->second; << 123 it->second = nullptr; << 124 } << 125 } << 126 << 127 for (it = fAskedNumPerVolTable.begin(); it ! << 128 if (it->second != nullptr){ << 129 delete it->second; << 130 it->second = nullptr; << 131 } << 132 } << 133 l2.unlock(); << 134 } 94 } 135 95 136 << 96 G4bool G4DNAMolecularMaterial::Notify(G4ApplicationState requestedState) 137 //-------------------------------------------- << 138 << 139 G4DNAMolecularMaterial::G4DNAMolecularMaterial << 140 { 97 { 141 Create(); << 98 if(requestedState == G4State_Idle) Initialize(); >> 99 return true; 142 } 100 } 143 101 144 //-------------------------------------------- << 102 G4DNAMolecularMaterial::G4DNAMolecularMaterial(const G4DNAMolecularMaterial& /*rhs*/) : G4VStateDependent() 145 << 146 G4bool G4DNAMolecularMaterial::Notify(G4Applic << 147 { 103 { 148 if (requestedState == G4State_Idle && G4Stat << 104 Create(); 149 ->GetPreviousState() == G4State_PreInit) << 150 Initialize(); << 151 } << 152 return true; << 153 } 105 } 154 106 155 //-------------------------------------------- << 107 G4DNAMolecularMaterial& G4DNAMolecularMaterial::operator=(const G4DNAMolecularMaterial& rhs) >> 108 { >> 109 if(this == &rhs) return *this; >> 110 Create(); >> 111 return *this; >> 112 } 156 113 157 G4DNAMolecularMaterial::~G4DNAMolecularMateria 114 G4DNAMolecularMaterial::~G4DNAMolecularMaterial() 158 { 115 { 159 Clear(); << 116 if(fpCompFractionTable) >> 117 { >> 118 fpCompFractionTable->clear(); >> 119 delete fpCompFractionTable; >> 120 fpCompFractionTable = 0; >> 121 } >> 122 if(fpCompDensityTable) >> 123 { >> 124 fpCompDensityTable->clear(); >> 125 delete fpCompDensityTable; >> 126 fpCompDensityTable = 0; >> 127 } >> 128 if(fpCompNumMolPerVolTable) >> 129 { >> 130 fpCompNumMolPerVolTable->clear(); >> 131 delete fpCompNumMolPerVolTable; >> 132 fpCompNumMolPerVolTable = 0; >> 133 } >> 134 >> 135 std::map<const G4Material*,std::vector<double>*,CompareMaterial>::iterator it; >> 136 >> 137 for(it= fAskedDensityTable.begin() ; it != fAskedDensityTable.end() ;it++) >> 138 { >> 139 if(it->second) >> 140 { >> 141 delete it->second; >> 142 it->second = 0; >> 143 } >> 144 } >> 145 >> 146 for(it= fAskedNumPerVolTable.begin() ; it != fAskedNumPerVolTable.end() ;it++) >> 147 { >> 148 if(it->second) >> 149 { >> 150 delete it->second; >> 151 it->second = 0; >> 152 } >> 153 } 160 } 154 } 161 155 162 //-------------------------------------------- << 163 156 164 void G4DNAMolecularMaterial::Initialize() 157 void G4DNAMolecularMaterial::Initialize() 165 { 158 { 166 if (fIsInitialized){ << 159 G4AutoLock l(&aMutex); 167 return; << 160 if(fIsInitialized) 168 } << 161 { >> 162 return; >> 163 } >> 164 >> 165 const G4MaterialTable* materialTable = G4Material::GetMaterialTable(); 169 166 170 const G4MaterialTable* materialTable = G4Mat << 167 fNMaterials = materialTable->size(); >> 168 // This is to prevent segment fault if materials are created later on >> 169 // Actually this creation should not be done 171 170 172 fNMaterials = materialTable->size(); << 171 if(fpCompFractionTable==0) 173 // This is to prevent segment fault if mater << 172 { 174 // Actually this creation should not be done << 173 fpCompFractionTable = new vector<ComponentMap>(materialTable->size()); >> 174 } 175 175 176 G4AutoLock l1(&aMutex); << 176 G4Material* mat(0); 177 if (fpCompFractionTable == nullptr){ << 178 fpCompFractionTable = new vector<Component << 179 } << 180 177 181 G4Material* mat(nullptr); << 178 for(size_t i = 0 ; i < fNMaterials ; i++) >> 179 { >> 180 mat = materialTable->at(i); >> 181 SearchMolecularMaterial(mat,mat,1); 182 182 183 for (std::size_t i = 0; i < fNMaterials; ++i << 183 mat = 0; 184 mat = materialTable->at(i); << 184 } 185 SearchMolecularMaterial(mat, mat, 1); << 186 } << 187 185 188 InitializeDensity(); << 186 InitializeDensity(); 189 InitializeNumMolPerVol(); << 187 InitializeNumMolPerVol(); 190 l1.unlock(); << 191 188 192 fIsInitialized = true; << 189 fIsInitialized = true; 193 } 190 } 194 191 195 //-------------------------------------------- << 196 << 197 void G4DNAMolecularMaterial::InitializeDensity 192 void G4DNAMolecularMaterial::InitializeDensity() 198 { 193 { 199 if (fpCompFractionTable != nullptr){ << 194 if(fpCompFractionTable) 200 const G4MaterialTable* materialTable = G4M << 195 { 201 fpCompDensityTable = new vector<ComponentM << 196 const G4MaterialTable* materialTable = G4Material::GetMaterialTable(); 202 G4Material::GetMaterialTable()->size() << 197 fpCompDensityTable = new vector<ComponentMap>(G4Material::GetMaterialTable()->size()); 203 << 198 204 G4Material* parentMat; << 199 G4Material* parentMat; 205 const G4Material* compMat(nullptr); << 200 const G4Material* compMat(0); 206 G4double massFraction = -1; << 201 double massFraction = -1; 207 G4double parentDensity = -1; << 202 double parentDensity = -1; 208 << 203 209 for (std::size_t i = 0; i < fNMaterials; + << 204 for(size_t i = 0 ; i < fNMaterials ; i++) 210 parentMat = materialTable->at(i); << 205 { 211 ComponentMap& massFractionComp = (*fpCom << 206 parentMat = materialTable->at(i); 212 ComponentMap& densityComp = (*fpCompDens << 207 ComponentMap& massFractionComp = (*fpCompFractionTable)[i]; 213 << 208 ComponentMap& densityComp = (*fpCompDensityTable)[i]; 214 parentDensity = parentMat->GetDensity(); << 209 215 << 210 parentDensity = parentMat->GetDensity(); 216 for (const auto& it : massFractionComp){ << 211 217 compMat = it.first; << 212 for(ComponentMap::iterator it = massFractionComp.begin() ; it!=massFractionComp.end() ; it++) 218 massFraction = it.second; << 213 { 219 densityComp[compMat] = massFraction * << 214 compMat = it->first; 220 compMat = nullptr; << 215 massFraction = it->second; 221 massFraction = -1; << 216 densityComp[compMat] = massFraction*parentDensity; 222 } << 217 compMat = 0; 223 } << 218 massFraction = -1; 224 } << 219 } 225 else{ << 220 } 226 G4ExceptionDescription exceptionDescriptio << 221 } 227 exceptionDescription << "The pointer fpCom << 222 else 228 << G4endl; << 223 { 229 G4Exception("G4DNAMolecularMaterial::Initi << 224 G4ExceptionDescription exceptionDescription; 230 "G4DNAMolecularMaterial001", F << 225 exceptionDescription << "The pointer fpCompFractionTable is not initialized" << G4endl; 231 exceptionDescription); << 226 G4Exception("G4DNAMolecularMaterial::InitializeDensity","G4DNAMolecularMaterial001", 232 } << 227 FatalException,exceptionDescription); >> 228 } 233 } 229 } 234 230 235 //-------------------------------------------- << 236 << 237 void G4DNAMolecularMaterial::InitializeNumMolP 231 void G4DNAMolecularMaterial::InitializeNumMolPerVol() 238 { 232 { 239 if (fpCompDensityTable != nullptr){ << 233 if(fpCompDensityTable) 240 fpCompNumMolPerVolTable = new vector<Compo << 234 { >> 235 fpCompNumMolPerVolTable = new vector<ComponentMap>(fNMaterials); 241 236 242 const G4Material* compMat(nullptr); << 237 const G4Material* compMat(0); 243 238 244 for (std::size_t i = 0; i < fNMaterials; + << 239 for(size_t i = 0 ; i < fNMaterials ; i++) 245 ComponentMap& massFractionComp = (*fpCom << 240 { 246 ComponentMap& densityComp = (*fpCompDens << 241 ComponentMap& massFractionComp = (*fpCompFractionTable)[i]; 247 ComponentMap& numMolPerVol = (*fpCompNum << 242 ComponentMap& densityComp = (*fpCompDensityTable)[i]; >> 243 ComponentMap& numMolPerVol = (*fpCompNumMolPerVolTable)[i]; 248 244 249 for (auto& it : massFractionComp){ << 245 for(ComponentMap::iterator it = massFractionComp.begin() ; it!=massFractionComp.end() ; it++) 250 compMat = it.first; << 246 { 251 numMolPerVol[compMat] = densityComp[co << 247 compMat = it->first; 252 / compMat->GetMassOfMolecule(); << 248 numMolPerVol[compMat] = densityComp[compMat]/ compMat->GetMassOfMolecule(); 253 compMat = nullptr; << 249 compMat = 0; 254 } << 250 } >> 251 } >> 252 } >> 253 else >> 254 { >> 255 G4ExceptionDescription exceptionDescription; >> 256 exceptionDescription << "The pointer fpCompDensityTable is not initialized" << G4endl; >> 257 G4Exception("G4DNAMolecularMaterial::InitializeNumMolPerVol","G4DNAMolecularMaterial002", >> 258 FatalException,exceptionDescription); 255 } 259 } 256 } << 257 else{ << 258 G4ExceptionDescription exceptionDescriptio << 259 exceptionDescription << "The pointer fpCom << 260 << G4endl; << 261 G4Exception("G4DNAMolecularMaterial::Initi << 262 "G4DNAMolecularMaterial002", F << 263 exceptionDescription); << 264 } << 265 } 260 } 266 261 267 //-------------------------------------------- << 262 void G4DNAMolecularMaterial::RecordMolecularMaterial(G4Material* parentMaterial, G4Material* molecularMaterial, G4double fraction) 268 << 269 void << 270 G4DNAMolecularMaterial::RecordMolecularMateria << 271 << 272 << 273 { 263 { 274 ComponentMap& matComponent = << 264 ComponentMap& matComponent = (*fpCompFractionTable)[parentMaterial->GetIndex()]; 275 (*fpCompFractionTable)[parentMaterial->G << 276 << 277 if (matComponent.empty()){ << 278 matComponent[molecularMaterial] = fraction << 279 return; << 280 } << 281 265 282 auto it = matComponent.find(molecularMateria << 266 if(matComponent.empty()) 283 << 267 { 284 if (it == matComponent.cend()){ << 268 matComponent[molecularMaterial] = fraction; 285 matComponent[molecularMaterial] = fraction << 269 return; 286 } << 270 } 287 else{ << 288 matComponent[molecularMaterial] = it->seco << 289 // handle "base material" << 290 } << 291 } << 292 << 293 //-------------------------------------------- << 294 << 295 void G4DNAMolecularMaterial::SearchMolecularMa << 296 << 297 << 298 { << 299 if (material->GetMassOfMolecule() != 0.0){ / << 300 RecordMolecularMaterial(parentMaterial, ma << 301 return; << 302 } << 303 271 304 G4Material* compMat(nullptr); << 272 ComponentMap::iterator it = matComponent.find(molecularMaterial); 305 G4double fraction = -1.; << 306 std::map<G4Material*, G4double> matComponent << 307 auto it = matComponent.cbegin(); << 308 273 309 for (; it != matComponent.cend(); ++it){ << 274 if(it == matComponent.end()) 310 compMat = it->first; << 275 { 311 fraction = it->second; << 276 matComponent[molecularMaterial] = fraction; 312 if (compMat->GetMassOfMolecule() == 0.0){ << 313 SearchMolecularMaterial(parentMaterial, << 314 currentFraction << 315 } 277 } 316 else{ // is a molecular material << 278 else 317 RecordMolecularMaterial(parentMaterial, << 279 { 318 currentFraction << 280 matComponent[molecularMaterial] = it->second + fraction; 319 } 281 } 320 } << 321 } 282 } 322 283 323 //-------------------------------------------- << 284 void G4DNAMolecularMaterial::SearchMolecularMaterial(G4Material* parentMaterial, G4Material* material, double currentFraction) 324 << 325 const std::vector<G4double>* << 326 G4DNAMolecularMaterial:: << 327 GetDensityTableFor(const G4Material* lookForMa << 328 { 285 { 329 if (fpCompDensityTable == nullptr){ << 286 if(material->GetMassOfMolecule() != 0.0) 330 if (fIsInitialized){ << 287 { 331 G4ExceptionDescription exceptionDescript << 288 RecordMolecularMaterial(parentMaterial,material,currentFraction); 332 exceptionDescription << 289 return; 333 << "The pointer fpCompDensityTable i << 334 "singleton of G4DNAMolecularMaterial << 335 << "has already been initialized." < << 336 G4Exception("G4DNAMolecularMaterial::Get << 337 "G4DNAMolecularMaterial003", << 338 exceptionDescription); << 339 } << 340 << 341 if (G4StateManager::GetStateManager()->Get << 342 const_cast<G4DNAMolecularMaterial*>(this << 343 } 290 } 344 else{ << 345 G4ExceptionDescription exceptionDescript << 346 exceptionDescription << 347 << "The geant4 application is at the << 348 "G4State_Init." << 349 << G4endl; << 350 G4Exception("G4DNAMolecularMaterial::Get << 351 "G4DNAMolecularMaterial_WRON << 352 FatalException, exceptionDes << 353 } << 354 } << 355 << 356 auto it_askedDensityTable = fAskedDensityTab << 357 291 358 if (it_askedDensityTable != fAskedDensityTab << 292 G4Material* compMat(0); 359 return it_askedDensityTable->second; << 293 G4double fraction = -1; 360 } << 294 std::map<G4Material*,G4double> matComponent = material->GetMatComponents(); >> 295 std::map<G4Material*,G4double>::iterator it = matComponent.begin(); 361 296 362 const G4MaterialTable* materialTable = G4Mat << 297 for( ; it!=matComponent.end() ; it++) >> 298 { >> 299 compMat = it->first; >> 300 fraction = it->second; >> 301 if(compMat->GetMassOfMolecule() == 0.0) >> 302 { >> 303 SearchMolecularMaterial(parentMaterial,compMat,currentFraction*fraction); >> 304 } >> 305 else >> 306 { >> 307 RecordMolecularMaterial(parentMaterial,compMat,currentFraction*fraction); >> 308 } 363 309 364 auto output = new std::vector<G4double>(mat << 310 compMat = 0; 365 << 311 fraction = -1; 366 ComponentMap::const_iterator it; << 367 << 368 G4bool materialWasNotFound = true; << 369 << 370 for (std::size_t i = 0; i < fNMaterials; ++i << 371 ComponentMap& densityTable = (*fpCompDensi << 372 << 373 it = densityTable.find(lookForMaterial); << 374 << 375 if (it == densityTable.cend()){ << 376 (*output)[i] = 0.0; << 377 } << 378 else{ << 379 materialWasNotFound = false; << 380 (*output)[i] = it->second; << 381 } 312 } 382 } << 383 << 384 if (materialWasNotFound){ << 385 PrintNotAMolecularMaterial("G4DNAMolecular << 386 lookForMaterial << 387 } << 388 << 389 fAskedDensityTable.insert(make_pair(lookForM << 390 << 391 return output; << 392 } 313 } 393 314 394 //-------------------------------------------- << 395 315 396 const std::vector<G4double>* G4DNAMolecularMat << 316 const std::vector<double>* G4DNAMolecularMaterial::GetDensityTableFor(const G4Material* lookForMaterial) const 397 const G4Material* lookForMaterial) const << 398 { 317 { 399 if(lookForMaterial==nullptr) return nullptr; << 318 if(!fpCompDensityTable) >> 319 { >> 320 if(fIsInitialized) >> 321 { >> 322 G4ExceptionDescription exceptionDescription; >> 323 exceptionDescription << "The pointer fpCompDensityTable is not initialized will the singleton of G4DNAMolecularMaterial " >> 324 << "has already been initialized."<< G4endl; >> 325 G4Exception("G4DNAMolecularMaterial::GetDensityTableFor","G4DNAMolecularMaterial003", >> 326 FatalException,exceptionDescription); >> 327 } 400 328 401 if (fpCompNumMolPerVolTable == nullptr){ << 329 if(G4StateManager::GetStateManager()->GetCurrentState() == G4State_Idle) 402 if (fIsInitialized){ << 330 const_cast<G4DNAMolecularMaterial*>(this)->Initialize(); 403 G4ExceptionDescription exceptionDescript << 331 else 404 exceptionDescription << 332 { 405 << "The pointer fpCompNumMolPerVolTa << 333 G4ExceptionDescription exceptionDescription; 406 "the singleton of G4DNAMolecularMate << 334 exceptionDescription << "The geant4 application is at the wrong state. State must be: G4State_Idle."<< G4endl; 407 << "has already been initialized." < << 335 G4Exception("G4DNAMolecularMaterial::GetDensityTableFor", 408 G4Exception("G4DNAMolecularMaterial::Get << 336 "G4DNAMolecularMaterial_WRONG_STATE_APPLICATION",FatalException,exceptionDescription); 409 "G4DNAMolecularMaterial005", << 337 } 410 exceptionDescription); << 411 } 338 } 412 339 413 if (G4StateManager::GetStateManager()->Get << 340 std::map<const G4Material*,std::vector<double>*,CompareMaterial>::const_iterator it_askedDensityTable = fAskedDensityTable.find(lookForMaterial); 414 const_cast<G4DNAMolecularMaterial*>(this << 341 if(it_askedDensityTable != fAskedDensityTable.end()) >> 342 { >> 343 return it_askedDensityTable->second; 415 } 344 } 416 else{ << 417 G4ExceptionDescription exceptionDescript << 418 exceptionDescription << 419 << "The geant4 application is at the << 420 "G4State_Init." << 421 << G4endl; << 422 G4Exception("G4DNAMolecularMaterial::Get << 423 "G4DNAMolecularMaterial_WRON << 424 FatalException, exceptionDes << 425 } << 426 } << 427 << 428 auto it_askedNumMolPerVolTable = fAskedNumPe << 429 if (it_askedNumMolPerVolTable != fAskedNumPe << 430 return it_askedNumMolPerVolTable->second; << 431 } << 432 345 433 const G4MaterialTable* materialTable = G4Mat << 346 const G4MaterialTable* materialTable = G4Material::GetMaterialTable(); 434 347 435 auto output = new std::vector<G4double>(mat << 348 std::vector<double>* output = new std::vector<double>(materialTable->size()); 436 349 437 ComponentMap::const_iterator it; << 350 ComponentMap::const_iterator it; 438 351 439 G4bool materialWasNotFound = true; << 352 G4bool materialWasNotFound = true; 440 353 441 for (std::size_t i = 0; i < fNMaterials; ++i << 354 for(size_t i = 0 ; i < fNMaterials ; i++) 442 ComponentMap& densityTable = (*fpCompNumMo << 355 { >> 356 ComponentMap& densityTable = (*fpCompDensityTable)[i]; 443 357 444 it = densityTable.find(lookForMaterial); << 358 it = densityTable.find(lookForMaterial); 445 359 446 if (it == densityTable.cend()){ << 360 if(it==densityTable.end()) 447 (*output)[i] = 0.0; << 361 { 448 } << 362 (*output)[i] = 0.0; 449 else{ << 363 } 450 materialWasNotFound = false; << 364 else 451 (*output)[i] = it->second; << 365 { >> 366 materialWasNotFound = false; >> 367 (*output)[i] = it->second; >> 368 } 452 } 369 } 453 } << 454 370 455 if (materialWasNotFound){ << 371 if(materialWasNotFound) 456 PrintNotAMolecularMaterial( << 372 { 457 "G4DNAMolecularMaterial::GetNumMolPerV << 373 PrintNotAMolecularMaterial("G4DNAMolecularMaterial::GetDensityTableFor",lookForMaterial); 458 } << 374 } 459 375 460 fAskedNumPerVolTable.insert(make_pair(lookFo << 376 fAskedDensityTable.insert(make_pair(lookForMaterial, output)); 461 377 462 return output; << 378 return output; 463 } 379 } 464 380 465 //-------------------------------------------- << 381 const std::vector<double>* G4DNAMolecularMaterial::GetNumMolPerVolTableFor(const G4Material* lookForMaterial) const 466 << 467 void G4DNAMolecularMaterial:: << 468 PrintNotAMolecularMaterial(const char* methodN << 469 const G4Material* l << 470 { 382 { 471 auto it = fWarningPrinted.find(lookForMateri << 383 if(!fpCompNumMolPerVolTable) >> 384 { >> 385 if(fIsInitialized) >> 386 { >> 387 G4ExceptionDescription exceptionDescription; >> 388 exceptionDescription << "The pointer fpCompNumMolPerVolTable is not initialized whereas the singleton of G4DNAMolecularMaterial " >> 389 << "has already been initialized."<< G4endl; >> 390 G4Exception("G4DNAMolecularMaterial::GetNumMolPerVolTableFor","G4DNAMolecularMaterial005", >> 391 FatalException,exceptionDescription); >> 392 } 472 393 473 if (it == fWarningPrinted.cend()){ << 394 if(G4StateManager::GetStateManager()->GetCurrentState() == G4State_Idle) 474 G4ExceptionDescription exceptionDescriptio << 395 { 475 exceptionDescription << "The material " << << 396 const_cast<G4DNAMolecularMaterial*>(this)->Initialize(); 476 << " is not defined a << 397 } 477 << G4endl << 398 else 478 << "Meaning: The elem << 399 { 479 "material using atom << 400 G4ExceptionDescription exceptionDescription; 480 "(cf. G4Material)" << 401 exceptionDescription << "The geant4 application is at the wrong state. State must be : G4State_Idle."<< G4endl; 481 << G4endl << 402 G4Exception("G4DNAMolecularMaterial::GetNumMolPerVolTableFor", 482 << "If you want to use DNA processes on li << 403 "G4DNAMolecularMaterial_WRONG_STATE_APPLICATION",FatalException,exceptionDescription); 483 "the NistManager to create the water mater << 404 } 484 << G4endl << 405 } 485 << "Since this message is displayed, it me << 486 "be called." << 487 << "Please note that this message will onl << 488 "using other methods of G4DNAMolecularMate << 489 << G4endl; << 490 406 491 G4Exception(methodName, "MATERIAL_NOT_DEFI << 407 std::map<const G4Material*,std::vector<double>*,CompareMaterial>::const_iterator it_askedNumMolPerVolTable = fAskedNumPerVolTable.find(lookForMaterial); 492 exceptionDescription); << 408 if(it_askedNumMolPerVolTable != fAskedNumPerVolTable.end()) 493 fWarningPrinted[lookForMaterial] = true; << 409 { 494 } << 410 return it_askedNumMolPerVolTable->second; 495 } << 411 } 496 412 497 //-------------------------------------------- << 413 const G4MaterialTable* materialTable = G4Material::GetMaterialTable(); 498 414 499 G4MolecularConfiguration* << 415 std::vector<double>* output = new std::vector<double>(materialTable->size()); 500 G4DNAMolecularMaterial:: << 501 GetMolecularConfiguration(const G4Material* ma << 502 { << 503 auto material_id = (G4int)material->GetInde << 504 auto it = fMaterialToMolecularConf.find(mate << 505 if(it == fMaterialToMolecularConf.cend()) re << 506 return it->second; << 507 } << 508 416 509 //-------------------------------------------- << 417 ComponentMap::const_iterator it; 510 418 511 void << 419 G4bool materialWasNotFound = true; 512 G4DNAMolecularMaterial:: << 513 SetMolecularConfiguration(const G4Material* ma << 514 G4MolecularConfigura << 515 { << 516 assert(material != nullptr); << 517 auto material_id = (G4int)material->GetInde << 518 fMaterialToMolecularConf[material_id] = molC << 519 } << 520 420 521 //-------------------------------------------- << 421 for(size_t i = 0 ; i < fNMaterials ; i++) >> 422 { >> 423 ComponentMap& densityTable = (*fpCompNumMolPerVolTable)[i]; 522 424 523 void << 425 it = densityTable.find(lookForMaterial); 524 G4DNAMolecularMaterial::SetMolecularConfigurat << 525 << 526 { << 527 assert(material != nullptr); << 528 auto material_id = (G4int)material->GetInde << 529 fMaterialToMolecularConf[material_id] = << 530 G4MoleculeTable::Instance()->GetConfigurat << 531 } << 532 426 533 //-------------------------------------------- << 427 if(it==densityTable.end()) >> 428 { >> 429 (*output)[i] = 0.0; >> 430 } >> 431 else >> 432 { >> 433 materialWasNotFound = false; >> 434 (*output)[i] = it->second; >> 435 } >> 436 } 534 437 535 void << 438 if(materialWasNotFound) 536 G4DNAMolecularMaterial::SetMolecularConfigurat << 439 { 537 << 440 PrintNotAMolecularMaterial("G4DNAMolecularMaterial::GetNumMolPerVolTableFor",lookForMaterial); 538 { << 441 } 539 G4Material* material = G4Material::GetMateri << 540 442 541 if(material == nullptr){ << 443 fAskedNumPerVolTable.insert(make_pair(lookForMaterial, output)); 542 G4cout<< "Material " << materialName << 543 << " was not found and therefore won << 544 << molUserID << G4endl; << 545 return; << 546 } << 547 SetMolecularConfiguration(material, molUserI << 548 } << 549 444 550 //-------------------------------------------- << 445 return output; >> 446 } 551 447 552 G4double << 448 void G4DNAMolecularMaterial::PrintNotAMolecularMaterial(const char* methodName, const G4Material* lookForMaterial) const 553 G4DNAMolecularMaterial:: << 554 GetNumMoleculePerVolumeUnitForMaterial(const G << 555 { 449 { 556 G4Exception("G4DNAMolecularMaterial::GetNumM << 450 std::map<const G4Material*,bool,CompareMaterial>::iterator it = fWarningPrinted.find(lookForMaterial); 557 "DEPRECATED", << 558 FatalException,"Use standard met << 559 " at the run initialization to r << 560 " during stepping. The method is << 561 return 0.; << 562 } << 563 451 564 //-------------------------------------------- << 452 if(it == fWarningPrinted.end()) >> 453 { >> 454 G4ExceptionDescription exceptionDescription; >> 455 exceptionDescription >> 456 << "The material " << lookForMaterial->GetName() >> 457 << " is not defined as a molecular material."<< G4endl >> 458 << "Meaning: The elements should be added to the material using atom count rather than mass fraction (cf. G4Material)" >> 459 << G4endl >> 460 << "If you want to use DNA processes on liquid water, you should better use the NistManager to create the water material." >> 461 << G4endl >> 462 << "Since this message is displayed, it means that the DNA models will not be called." >> 463 << "Please note that this message will only appear once even if you are using other methods of G4DNAMolecularMaterial." >> 464 << G4endl; 565 465 566 G4double << 466 G4Exception(methodName,"MATERIAL_NOT_DEFINE_USING_ATOM_COUNT",JustWarning,exceptionDescription); 567 G4DNAMolecularMaterial:: << 467 fWarningPrinted[lookForMaterial] = true; 568 GetNumMolPerVolForComponentInComposite(const G << 468 } 569 const G << 570 G4doubl << 571 { << 572 G4Exception("G4DNAMolecularMaterial::GetNumM << 573 "DEPRECATED", << 574 FatalException,"Use standard me << 575 " at the run initialization to r << 576 " during stepping. The method is << 577 return 0.; << 578 } 469 } 579 470