Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/processes/electromagnetic/dna/utils/src/G4DNAMolecularMaterial.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 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/utils/src/G4DNAMolecularMaterial.cc (Version 11.3.0) and /processes/electromagnetic/dna/utils/src/G4DNAMolecularMaterial.cc (Version 9.6)


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