Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4MolecularConfiguration.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27// Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr)
28//
29// History:
30// -----------
31// 10 Oct 2011 M.Karamitros created
32//
33// -------------------------------------------------------------------
34
37#include "G4UIcommand.hh"
38#include "G4AllocatorList.hh"
39#include "G4AutoLock.hh"
40#include "G4MoleculeTable.hh"
41#include "G4Serialize.hh"
42#include <fstream>
43
44using CLHEP::m2;
45using CLHEP::s;
46using CLHEP::kelvin;
47
48using namespace std;
49
50#if defined ( WIN32 )
51#define __func__ __FUNCTION__
52#endif
53
54/*G4ThreadLocal*/G4double G4MolecularConfiguration::fgTemperature = 298; // 310*kelvin;
55// 25°C, used to shoot an energy
56
57//______________________________________________________________________________
58// G4MolecularConfigurationManager
60
62
64
69
71 double,
73 molConf)
74{
75 return molConf->fDynDiffusionCoefficient;
76}
77
112
114{
115 if(fIsFinalized)
116 {
118 errMsg << "This molecular configuration " << GetName()
119 << " is already finalized. Therefore its "
120 " properties cannot be changed.";
121 G4Exception("G4MolecularConfiguration::MakeExceptionIfFinalized",
122 "CONF_FINALIZED",FatalException,errMsg);
123 }
124}
125
126//______________________________________________________________________________
127
130{
131 if (fgManager == nullptr)
132 {
134 if (fgManager == nullptr) // double check for MT
135 {
136 fgManager = new G4MolecularConfiguration::
137 G4MolecularConfigurationManager();
138 }
139 lock.unlock();
140 }
141
142 return fgManager;
143}
144
145//______________________________________________________________________________
146
149{
150// G4cout << "Does G4AllocatorList exists= ";
151// G4cout << (G4AllocatorList::GetAllocatorListIfExist() ? "true":"false")
152// << G4endl;
153
154 G4MolecularConfigurationManager::MolElectronConfTable::iterator it1;
155 G4MolecularConfigurationManager::ElectronOccupancyTable::
156 iterator it2;
157
158 for (it1 = fElecOccTable.begin(); it1 != fElecOccTable.end(); it1++)
159 {
160 for (it2 = it1->second.begin(); it2 != it1->second.end(); it2++)
161 {
162
163
164 delete it2->second;
165
166 }
167 }
168 fElecOccTable.clear();
169 fgManager = nullptr;
170}
171
172//______________________________________________________________________________
173// G4MolecularConfigurationManager
176Insert(const G4MoleculeDefinition* molDef,
177 const G4ElectronOccupancy& eOcc,
179{
180 //G4AutoLock lock(&fMoleculeCreationMutex);
181
182 ElectronOccupancyTable& table2 = fElecOccTable[molDef];
183 auto it = table2.find(eOcc);
184
185 if(it == table2.end())
186 {
187 table2[eOcc] = molConf;
188 }
189 else
190 {
192 errMsg << "The same molecular configuration seemed to be recorded twice";
193 G4Exception("G4MolecularConfigurationManager::"
194 "SetMolecularConfiguration(const G4MoleculeDefinition* molDef,"
195 "const G4ElectronOccupancy& eOcc,"
196 "G4MolecularConfiguration* molConf)",
197 "",
199 errMsg
200 );
201 }
202
203 fLastMoleculeID++;
204
205 fMolConfPerID.push_back(molConf);
206
207 //lock.unlock();
208 return fLastMoleculeID;
209}
210
211//______________________________________________________________________________
212
216 const G4ElectronOccupancy& eOcc)
217{
218 //G4AutoLock lock(&fMoleculeCreationMutex);
219
220 auto it1 = fElecOccTable.find(molDef);
221
222 if(it1 == fElecOccTable.end())
223 {
224 // TODO = handle exception ?
225 return nullptr;
226 }
227
228 ElectronOccupancyTable& table2 = it1->second;
229 auto it2 = table2.find(eOcc);
230
231 //lock.unlock();
232
233 if (it2 == table2.end())
234 {
235 // TODO = handle exception ?
236 return nullptr;
237 }
238
239 return &(it2->first);
240}
241
242//______________________________________________________________________________
243
247 const G4ElectronOccupancy& eOcc)
248{
249 auto it1 = fElecOccTable.find(molDef);
250
251 if(it1 == fElecOccTable.end()) return nullptr;
252
253 ElectronOccupancyTable& table2 = it1->second;
254 auto it = table2.find(eOcc);
255
256 if(it == table2.end())
257 {
258 return nullptr;
259 }
260
261 return it->second;
262}
263
264//______________________________________________________________________________
265
267Insert(const G4MoleculeDefinition* molDef,
268 int charge,
270{
271
272 //G4AutoLock lock(&fMoleculeCreationMutex);
273 ChargeTable& table2 = fChargeTable[molDef];
274 auto it = table2.find(charge);
275
276 if(it == table2.end())
277 {
278 table2[charge] = molConf;
279 }
280 else
281 {
282 //lock.unlock();
284 errMsg << "The same molecular configuration seemed to be recorded twice";
285 G4Exception("G4MolecularConfigurationManager::"
286 "SetMolecularConfiguration(const G4MoleculeDefinition* molDef,"
287 "int charge,"
288 "G4MolecularConfiguration* molConf)",
289 "", FatalException, errMsg);
290 }
291
292 fLastMoleculeID++;
293 fMolConfPerID.push_back(molConf);
294 //lock.unlock();
295 return fLastMoleculeID;
296}
297
298//______________________________________________________________________________
299
303 int charge)
304{
305 //G4AutoLock lock(&fMoleculeCreationMutex);
306
307 auto it1 = fChargeTable.find(molDef);
308
309 if(it1 == fChargeTable.end()) return nullptr;
310
311 ChargeTable& table2 = it1->second;
312 auto it = table2.find(charge);
313
314 if(it == table2.end())
315 {
316 return nullptr;
317 }
318
319 return it->second;
320
321}
322
323//______________________________________________________________________________
324// Static method in G4MolecularConfiguration
328{
329 if (molDef->GetGroundStateElectronOccupancy() != nullptr)
330 {
331 const G4ElectronOccupancy& elecOcc =
333 G4MolecularConfiguration* molConf =
334 GetManager()->GetMolecularConfiguration(molDef, elecOcc);
335
336 if (molConf != nullptr)
337 {
338 return molConf;
339 }
340
341 auto newConf =
342 new G4MolecularConfiguration(molDef,
343 elecOcc);
344 newConf->SetUserID(molDef->GetName());
345 return newConf;
346 }
347
348 G4MolecularConfiguration* molConf =
349 GetManager()->GetMolecularConfiguration(molDef, molDef->GetCharge());
350 if(molConf != nullptr)
351 {
352 return molConf;
353 }
354
355 auto newConf =
356 new G4MolecularConfiguration(molDef, molDef->GetCharge());
357 newConf->SetUserID(molDef->GetName());
358 return newConf;
359}
360
361//______________________________________________________________________________
362
366 const G4ElectronOccupancy& elecOcc)
367{
368 return GetManager()->GetOrCreateMolecularConfiguration(molDef, elecOcc);
369
370// G4MolecularConfiguration* molConf =
371// GetManager()->GetMolecularConfiguration(molDef, elecOcc);
372//
373// if (molConf)
374// {
375// return molConf;
376// }
377// else
378// {
379// G4MolecularConfiguration* newConf =
380// new G4MolecularConfiguration(molDef, elecOcc);
381// return newConf;
382// }
383}
384
385//______________________________________________________________________________
386
390 int charge)
391{
392 G4MolecularConfiguration* molConf =
393 GetManager()->GetMolecularConfiguration(molDef, charge);
394
395 if(molConf != nullptr)
396 {
397 return molConf;
398 }
399
400 auto newConf =
401 new G4MolecularConfiguration(molDef, charge);
402 return newConf;
403}
404
405//______________________________________________________________________________
406
414
415//______________________________________________________________________________
416// G4MolecularConfiguration
419 const G4ElectronOccupancy& elecOcc,
420 const G4String& label)
421{
422 fMoleculeDefinition = moleculeDef;
423
424 fMoleculeID = GetManager()->Insert(moleculeDef,
425 elecOcc,
426 this);
428 elecOcc);
429
430 /*
431 fgManager->fTable[fMoleculeDefinition][elecOcc] = this;
432 std::map<G4ElectronOccupancy, G4MolecularConfiguration*, comparator>::iterator it ;
433 it = fgManager->fTable[moleculeDef].find(elecOcc);
434 fElectronOccupancy = &(it->first);
435 */
436
439 + moleculeDef->GetCharge();
441
445
447 fName += "^";
449
451 fFormatedName += "^";
452 fFormatedName += "{";
454 fFormatedName += "}";
455
456 fLabel = nullptr; // let it here
457
458 if(!label.empty())
459 {
460 SetLabel(label);
461 }
462
464
465 fIsFinalized = false;
466}
467
468//______________________________________________________________________________
469
504
505//______________________________________________________________________________
506
508{
510
511// if (G4AllocatorList::GetAllocatorListIfExist())
512// {
513// if (fElectronOccupancy)
514// {
515// delete fElectronOccupancy;
516// fElectronOccupancy = 0;
517// }
518// }
519}
520
521//______________________________________________________________________________
522
525ChangeConfiguration(const G4ElectronOccupancy& newElectronOccupancy) const
526{
529 newElectronOccupancy);
530
531 if (output == nullptr)
532 {
534 newElectronOccupancy);
535 }
536 return output;
537}
538
539//______________________________________________________________________________
540
543{
546
547 if (output == nullptr)
548 {
549 output = new G4MolecularConfiguration(fMoleculeDefinition, charge);
550 }
551 return output;
552}
553
554//______________________________________________________________________________
555
558{
559// if (&right == this) return *this;
560 return *this;
561}
562
563//______________________________________________________________________________
564
565/** Method used in Geant4-DNA to excite water molecules
566 */
569{
570// MakeExceptionIfFinalized();
571 CheckElectronOccupancy(__func__);
572 G4ElectronOccupancy newElectronOccupancy(*fElectronOccupancy);
573
574 newElectronOccupancy.RemoveElectron(ExcitedLevel, 1);
575 newElectronOccupancy.AddElectron(5, 1);
576
577 return ChangeConfiguration(newElectronOccupancy);
578}
579
580//______________________________________________________________________________
581
582/** Method used in Geant4-DNA to ionize water molecules
583 */
586{
587// MakeExceptionIfFinalized();
588 CheckElectronOccupancy(__func__);
589 G4ElectronOccupancy newElectronOccupancy(*fElectronOccupancy);
590
591 if (newElectronOccupancy.GetOccupancy(IonizedLevel) != 0)
592 {
593 newElectronOccupancy.RemoveElectron(IonizedLevel, 1);
594 }
595 else
596 {
597 G4String errMsg = "There is no electron on the orbit "
598 + G4UIcommand::ConvertToString(IonizedLevel)
599 + " you want to free. The molecule's name you want to ionized is "
600 + GetName();
601 G4Exception("G4MolecularConfiguration::IonizeMolecule",
602 "",
604 errMsg);
605 PrintState();
606 }
607
608 // DEBUG
609 // PrintState();
610
611 return ChangeConfiguration(newElectronOccupancy);
612}
613
614//______________________________________________________________________________
615
617 G4int number) const
618{
619// MakeExceptionIfFinalized();
620 CheckElectronOccupancy(__func__);
621 G4ElectronOccupancy newElectronOccupancy(*fElectronOccupancy);
622 newElectronOccupancy.AddElectron(orbit, number);
623 return ChangeConfiguration(newElectronOccupancy);
624}
625
626//______________________________________________________________________________
627
630 G4int number) const
631{
632// MakeExceptionIfFinalized();
633 CheckElectronOccupancy(__func__);
634 G4ElectronOccupancy newElectronOccupancy(*fElectronOccupancy);
635
636 if (newElectronOccupancy.GetOccupancy(orbit) != 0)
637 {
638 newElectronOccupancy.RemoveElectron(orbit, number);
639 }
640 else
641 {
642 G4String errMsg = "There is already no electron into the orbit "
644 + " you want to free. The molecule's name is " + GetName();
645 G4Exception("G4MolecularConfiguration::RemoveElectron",
646 "",
648 errMsg);
649 PrintState();
650 }
651
652 return ChangeConfiguration(newElectronOccupancy);
653}
654
655//______________________________________________________________________________
656
659 G4int orbitToFill) const
660{
661// MakeExceptionIfFinalized();
662 CheckElectronOccupancy(__func__);
663 G4ElectronOccupancy newElectronOccupancy(*fElectronOccupancy);
664
665 if (newElectronOccupancy.GetOccupancy(orbitToFree) >= 1)
666 {
667 newElectronOccupancy.RemoveElectron(orbitToFree, 1);
668 newElectronOccupancy.AddElectron(orbitToFill, 1);
669 }
670 else
671 {
672 G4String errMsg = "There is no electron on the orbit "
673 + G4UIcommand::ConvertToString(orbitToFree)
674 + " you want to free. The molecule's name is " + GetName();
675 G4Exception("G4MolecularConfiguration::MoveOneElectron",
676 "",
678 errMsg);
679 PrintState();
680 }
681
682 return ChangeConfiguration(newElectronOccupancy);
683}
684
685//______________________________________________________________________________
686
688{
689 return fName;
690}
691
692//______________________________________________________________________________
693
698
699//______________________________________________________________________________
700
705
706//______________________________________________________________________________
707
713
714//______________________________________________________________________________
715
717{
718 G4cout << "-------------- Start Printing State " << GetName()
719 << " ---------------" << G4endl;
720
721 if (fElectronOccupancy != nullptr)
722 {
723 G4cout << "--------------Print electronic state of " << GetName()
724 << "---------------" << G4endl;
727 {
728 G4cout<<"At ground state"<<G4endl;
729 }
730 }
731 else
732 {
733 G4cout << "--- No electron occupancy set up ---" << G4endl;
734 }
735
736 G4cout << "Charge :"
737 << fDynCharge
738 << G4endl;
739
740 if(fLabel != nullptr)
741 {
742 G4cout << "Label :"
743 << GetLabel()
744 << G4endl;
745 }
746 G4cout << "-------------- End Of State " << GetName()
747 << " -----------------------" << G4endl;
748}
749
750//______________________________________________________________________________
751
752// added - to be transformed in a "Decay method"
753const vector<const G4MolecularDissociationChannel*>*
755{
756 // if (fElectronOccupancy == 0) return 0;
758}
759
760//______________________________________________________________________________
761
763{
765 G4Exception("G4MolecularConfiguration::GetMoleculeID",
766 "",
768 "You should first enter a molecule definition");
769
770 return INT_MAX;
771}
772
773//______________________________________________________________________________
774
775const char* removePath(const char* path)
776{
777 const char* pDelimeter = strrchr(path, '\\');
778 if (pDelimeter != nullptr) path = pDelimeter + 1;
779
780 pDelimeter = strrchr(path, '/');
781 if (pDelimeter != nullptr) path = pDelimeter + 1;
782
783 return path;
784}
785
786//______________________________________________________________________________
787
789{
790 if (fElectronOccupancy == nullptr)
791 {
792 G4String functionName(function);
793 G4ExceptionDescription description;
794 description
795 << "No G4ElectronOccupancy was defined for molecule definition : "
797 << ". The definition was probably defined using the charge state, "
798 "rather than electron state.";
799
800 G4Exception(functionName, "", FatalErrorInArgument, description);
801 }
802}
803
804//______________________________________________________________________________
805
808{
809 //G4AutoLock lock(&fMoleculeCreationMutex);
810
811 LabelTable& tmpMap = fLabelTable[molConf->fMoleculeDefinition];
812
813 auto it = tmpMap.find(*molConf->fLabel);
814
815 if(it == tmpMap.end())
816 {
817 tmpMap[*(molConf->fLabel)] = molConf;
818 }
819 else
820 {
822 errMsg << "The same molecular configuration seemed to be recorded twice";
823 G4Exception("G4MolecularConfigurationManager::"
824 "SetMolecularConfiguration(const G4MoleculeDefinition* molDef,"
825 "const G4String& label,"
826 "G4MolecularConfiguration* molConf)",
827 "", FatalException, errMsg);
828 }
829
830 //lock.unlock();
831}
832
834 G4MolecularConfiguration* molecule)
835{
836 auto it = fUserIDTable.find(userID);
837
838 if(it == fUserIDTable.end())
839 {
840 fUserIDTable[userID] = molecule;
841 }
842 else if(molecule != it->second)
843 {
844 // TODO improve exception
845 // exception
846 G4ExceptionDescription description;
847 description << "The user identifier " << userID
848 << " was already given in another configuration in the table"
849 << G4endl;
850 G4Exception("G4MolecularConfiguration::G4MolecularConfigurationManager::AddUserID",
851 "CONF_ALREADY_RECORDED",
853 description);
854 }
855}
856
857//______________________________________________________________________________
858
861{
862 auto it1 =
863 fElecOccTable.find(configuration->GetDefinition());
864 auto end = fElecOccTable.end();
865
866 if (it1 == end) return;
867
868 auto it2 =
869 it1->second.find(*configuration->GetElectronOccupancy());
870
871 if (it2 == it1->second.end()) return;
872
873 it2->second = 0;
874// it1->second.erase(it2);
875
876 configuration->fElectronOccupancy = nullptr;
877}
878
879//______________________________________________________________________________
880
884 const G4String& label)
885{
886 //G4AutoLock lock(&fMoleculeCreationMutex);
887
888 auto it1 = fLabelTable.find(molDef);
889
890 if(it1 == fLabelTable.end()) return nullptr;
891
892 LabelTable& table2 = it1->second;
893
894 auto it2 = table2.find(label);
895
896 //lock.unlock();
897
898 if(it2 == table2.end()) return nullptr;
899 return it2->second;
900}
901
902//______________________________________________________________________________
903
906GetMolecularConfiguration(int moleculeID)
907{
908 if(moleculeID > (int) fMolConfPerID.size() ||
909 moleculeID < 0) return nullptr;
910
911 return fMolConfPerID[moleculeID];
912}
913
914//______________________________________________________________________________
915
916G4int
918Insert(const G4MoleculeDefinition* molDef,
919 const G4String& label,
921{
922 G4AutoLock lock(&fMoleculeCreationMutex);
923 LabelTable& tmpMap = fLabelTable[molDef];
924 auto it = tmpMap.find(label);
925
926 if(it == tmpMap.end())
927 {
928 fLastMoleculeID++;
929 tmpMap[label] = molConf;
930 lock.unlock();
931 }
932 else
933 {
934 lock.unlock();
936 errMsg << "The same molecular configuration seemed to be recorded twice";
937 G4Exception("G4MolecularConfigurationManager::"
938 "SetMolecularConfiguration(const G4MoleculeDefinition* molDef,"
939 "const G4String& label,"
940 "G4MolecularConfiguration* molConf)",
941 "", FatalException, errMsg);
942 }
943
944 fMolConfPerID.push_back(molConf);
945
946 return fLastMoleculeID;
947}
948
949//______________________________________________________________________________
950
957
958//______________________________________________________________________________
959
965
966//______________________________________________________________________________
967
970 const G4MoleculeDefinition* molDef,
971 int charge,
972 const G4String& label,
973 bool& wasAlreadyCreated)
974{
975 wasAlreadyCreated = false;
976 G4MolecularConfiguration* molConf =
977 GetManager()->GetMolecularConfiguration(molDef, charge);
978
979 if (molConf != nullptr)
980 {
981 if(molConf->fLabel == nullptr)
982 {
983 molConf->SetLabel(label);
985 wMsg << "The molecular configuration for the definition named "
986 << molDef->GetName()
987 << " with charge " << charge << " has already been created "
988 "but with NO label";
989 G4Exception("G4MolecularConfiguration::CreateMolecularConfiguration",
990 "DOUBLE_CREATION",
992 wMsg);
993 }
994 else if(molConf->fLabel->empty() )
995 {
996 molConf->SetLabel(label);
997 }
998 else if(*(molConf->fLabel) != label)
999 {
1000 G4ExceptionDescription errMsg ;
1001 errMsg << "The molecular configuration for the definition named "
1002 << molDef->GetName()
1003 << " with charge " << charge << " has already been created "
1004 "but with a different label :"
1005 << molConf->GetLabel();
1006 G4Exception("G4MolecularConfiguration::CreateMolecularConfiguration",
1007 "DOUBLE_CREATION",
1009 errMsg);
1010 // KILL APP
1011 }
1012
1013 if(molConf->fUserIdentifier.empty())
1014 {
1015 molConf->fUserIdentifier = userIdentifier;
1016
1018 wMsg << "The molecular configuration for the definition named "
1019 << molDef->GetName()
1020 << " with label " << label << " has already been created.";
1021 G4Exception("G4MolecularConfiguration::CreateMolecularConfiguration",
1022 "DOUBLE_CREATION",
1024 wMsg);
1025 }
1026 else if(molConf->fUserIdentifier != userIdentifier)
1027 {
1028 G4ExceptionDescription errMsg ;
1029 errMsg << "The molecular configuration for the definition named "
1030 << molDef->GetName()
1031 << " with label " << label << " has already been created "
1032 "BUT with a different user ID :"
1033 << molConf->fUserIdentifier;
1034 G4Exception("G4MolecularConfiguration::CreateMolecularConfiguration",
1035 "DOUBLE_CREATION",
1037 errMsg);
1038 // KILL APP
1039 }
1040
1041 wasAlreadyCreated = true;
1042 return molConf;
1043 }
1044
1045 auto newConf =
1046 new G4MolecularConfiguration(molDef, label, charge);
1047 newConf->fUserIdentifier = userIdentifier;
1048
1049 GetManager()->AddUserID(userIdentifier, newConf);
1050
1051// G4MoleculeTable::Instance()->RecordMolecularConfiguration(userIdentifier,
1052// newConf);
1053 return newConf;
1054}
1055
1056//______________________________________________________________________________
1057
1060CreateMolecularConfiguration(const G4String& userIdentifier,
1061 const G4MoleculeDefinition* molDef,
1062 bool& wasAlreadyCreated)
1063{
1064 wasAlreadyCreated = false;
1065 G4MolecularConfiguration* preRegisteredMolConf =
1066 GetManager()->GetMolecularConfiguration(userIdentifier);
1067
1068 if(preRegisteredMolConf != nullptr)
1069 {
1070 if(preRegisteredMolConf->GetDefinition() == molDef)
1071 {
1072 wasAlreadyCreated = true;
1073 return preRegisteredMolConf;
1074 }
1075 }
1076
1077 if(molDef->GetGroundStateElectronOccupancy() != nullptr)
1078 {
1079 const G4ElectronOccupancy& elecOcc = *molDef
1081 G4MolecularConfiguration* molConf =
1082 GetManager()->GetMolecularConfiguration(molDef, elecOcc);
1083
1084 if(molConf != nullptr)
1085 {
1086 if(molConf->fUserIdentifier.empty())
1087 {
1088 molConf->fUserIdentifier = userIdentifier;
1089 }
1090 else if(molConf->fUserIdentifier != userIdentifier)
1091 {
1093 errMsg << "A molecular configuration for the definition named "
1094 << molDef->GetName() << " has already been created "
1095 "and recorded with a different user ID "
1096 << molConf->fUserIdentifier;
1097 G4Exception("G4MolecularConfiguration::CreateMolecularConfiguration",
1098 "DOUBLE_CREATION",
1100 errMsg);
1101 }
1102// TODO exception
1104 errMsg << "A molecular configuration for the definition named "
1105 << molDef->GetName() << " has already been created.";
1106 G4Exception("G4MolecularConfiguration::CreateMolecularConfiguration",
1107 "DOUBLE_CREATION",
1109 errMsg);
1110 wasAlreadyCreated = true;
1111 return molConf;
1112 }
1113
1114 // G4cout << "Create molConf for " << molDef->GetName() << G4endl;
1115 auto newConf = new G4MolecularConfiguration(molDef,
1116 elecOcc);
1117 newConf->fUserIdentifier = userIdentifier;
1118
1119 GetManager()->AddUserID(userIdentifier, newConf);
1120
1121// G4MoleculeTable::Instance()->RecordMolecularConfiguration(userIdentifier,
1122// newConf);
1123 return newConf;
1124 }
1125
1126 return CreateMolecularConfiguration(userIdentifier,
1127 molDef,
1128 molDef->GetName(),
1129 molDef->GetCharge(),
1130 wasAlreadyCreated);
1131}
1132
1133//______________________________________________________________________________
1134
1137CreateMolecularConfiguration(const G4String& userIdentifier,
1138 const G4MoleculeDefinition* molDef,
1139 const G4String& label,
1140 bool& wasAlreadyCreated)
1141{
1142 assert(label != "");
1143 wasAlreadyCreated = false;
1144
1145 G4MolecularConfiguration* molConf =
1146 GetManager()->GetMolecularConfiguration(molDef, label);
1147 if(molConf != nullptr)
1148 {
1149 if((molConf->fLabel != nullptr)
1150 && *molConf->fLabel == label)
1151 {
1152 wasAlreadyCreated = true;
1153 return molConf;
1154 }
1155 if(molConf->fLabel == nullptr)
1156 {
1157 wasAlreadyCreated = true;
1158 molConf->SetLabel(label);
1159 return molConf;
1160 }
1161 if(molConf->fLabel->empty())
1162 {
1163 wasAlreadyCreated = true;
1164 molConf->SetLabel(label);
1165 return molConf;
1166 }
1167
1168 molConf->PrintState();
1169 G4ExceptionDescription errMsg ;
1170 errMsg << "A molecular configuration for the definition named "
1171 << molDef->GetName()
1172 << " has already been created "
1173 "with user ID "
1174 << molConf->fUserIdentifier << " and label "
1175 << molConf->GetLabel();
1176 G4Exception("G4MolecularConfiguration::CreateMolecularConfiguration",
1177 "DOUBLE_CREATION",
1179 errMsg);
1180 // KILL APP
1181 }
1182 else
1183 {
1184 auto newConf =
1185 new G4MolecularConfiguration(molDef,
1186 label,
1187 molDef->GetCharge());
1188 newConf->fUserIdentifier = userIdentifier;
1189
1190 GetManager()->AddUserID(userIdentifier, newConf);
1191
1192// G4MoleculeTable::Instance()->
1193// RecordMolecularConfiguration(userIdentifier, newConf);
1194 return newConf;
1195 }
1196 return molConf;
1197}
1198
1199//______________________________________________________________________________
1200
1203CreateMolecularConfiguration(const G4String& userIdentifier,
1204 const G4MoleculeDefinition* molDef,
1205 const G4String& label,
1206 const G4ElectronOccupancy& eOcc,
1207 bool& wasAlreadyCreated)
1208{
1209 assert(label != "");
1210 wasAlreadyCreated = false;
1211
1212 G4MolecularConfiguration* molConf =
1213 GetManager()->GetMolecularConfiguration(molDef, eOcc);
1214
1215 if(molConf != nullptr)
1216 {
1217 if(molConf->GetElectronOccupancy() != nullptr)
1218 {
1219 if(*molConf->GetElectronOccupancy() == eOcc)
1220 {
1221 if((molConf->fLabel != nullptr) && *molConf->fLabel == label)
1222 {
1223 wasAlreadyCreated = true;
1224 return molConf;
1225 }
1226 if(molConf->fLabel == nullptr)
1227 {
1228 wasAlreadyCreated = true;
1229 molConf->SetLabel(label);
1230 return molConf;
1231 }
1232 if(molConf->fLabel->empty())
1233 {
1234 wasAlreadyCreated = true;
1235 molConf->SetLabel(label);
1236 return molConf;
1237 }
1238 }
1239 }
1240
1241
1242 molConf->PrintState();
1243 G4ExceptionDescription errMsg ;
1244 errMsg << "A molecular configuration for the definition named "
1245 << molDef->GetName()
1246 << " has already been created "
1247 "with user ID "
1248 << molConf->fUserIdentifier
1249 << " and possible different electronic state";
1250 G4Exception("G4MolecularConfiguration::CreateMolecularConfiguration",
1251 "DOUBLE_CREATION",
1253 errMsg);
1254 }
1255 else
1256 {
1257 auto newConf =
1258 new G4MolecularConfiguration(molDef,
1259 eOcc,
1260 label);
1261 newConf->fUserIdentifier = userIdentifier;
1262
1263 GetManager()->AddUserID(userIdentifier, newConf);
1264
1265// G4MoleculeTable::Instance()->
1266// RecordMolecularConfiguration(userIdentifier, newConf);
1267 return newConf;
1268 }
1269 return molConf;
1270}
1271
1272
1273//______________________________________________________________________________
1274
1278 const G4ElectronOccupancy& eOcc)
1279{
1280 auto it1 = fElecOccTable.find(molDef);
1281
1282 if(it1 == fElecOccTable.end())
1283 {
1284 return new G4MolecularConfiguration(molDef, eOcc);
1285 }
1286
1287 ElectronOccupancyTable& table2 = it1->second;
1288 auto it = table2.find(eOcc);
1289
1290 if(it == table2.end())
1291 {
1292 auto molConf =
1293 new G4MolecularConfiguration(molDef, eOcc);
1294// molConf->Finalize();
1295 return molConf;
1296 }
1297
1298 return it->second;
1299}
1300
1301//______________________________________________________________________________
1302
1306 int charge)
1307{
1308 auto it1 = fChargeTable.find(molDef);
1309
1310 if(it1 == fChargeTable.end())
1311 {
1312 G4AutoLock lock(&fMoleculeCreationMutex);
1313
1314 auto newConf = new G4MolecularConfiguration(molDef, charge);
1315 return newConf ;
1316 }
1317
1318 ChargeTable& table2 = it1->second;
1319 auto it = table2.find(charge);
1320
1321 if(it == table2.end())
1322 {
1323 G4AutoLock lock(&fMoleculeCreationMutex);
1324
1325 auto newConf =
1326 new G4MolecularConfiguration(molDef, charge);
1327// newConf->Finalize();
1328 return newConf ;
1329 }
1330
1331 return it->second;
1332}
1333
1334//______________________________________________________________________________
1335
1337{
1338 G4String moleculeName = fMoleculeDefinition->GetName();
1339 WRITE(out, moleculeName);
1340
1341// if(fLabel)
1342// out << fLabel;
1343// else
1344// out << "";
1347 WRITE(out,fDynDecayTime);
1348 WRITE(out,fDynMass);
1349 WRITE(out,fDynCharge);
1350 WRITE(out,fMoleculeID);
1351 WRITE(out,fFormatedName);
1352 WRITE(out,fName);
1353 WRITE(out,fIsFinalized);
1354}
1355
1356//______________________________________________________________________________
1357
1359{
1360 G4String moleculeName;
1361 READ(in, moleculeName);
1364
1365// G4String label;
1366//
1367// in.read((char*)(&label), sizeof(label));
1368//
1369// if(label)
1370// fLabel = new G4String(label);
1371// else
1372// fLabel = 0;
1375 READ(in,fDynDecayTime);
1376 READ(in,fDynMass);
1377 READ(in,fDynCharge);
1378 READ(in,fMoleculeID);
1379 READ(in,fFormatedName);
1380 READ(in,fName);
1381 READ(in,fIsFinalized);
1382}
1383
1384//______________________________________________________________________________
1385
1390
1391//______________________________________________________________________________
1392
1394{
1395 fLabel = nullptr; // TODO: for now not serialized
1396 Unserialize(in);
1397 fMoleculeDefinition = nullptr;
1398 fElectronOccupancy = nullptr;
1399 if(fElectronOccupancy != nullptr)
1400 {
1405
1406 if(fLabel != nullptr)
1407 {
1409 }
1410 }
1411 else if(fLabel != nullptr)
1412 {
1414 }
1415 else if(fDynCharge != 0)
1416 {
1418 }
1419}
1420
1421//______________________________________________________________________________
1422
1424{
1425 fUserIdentifier = userID;
1426 GetManager()->AddUserID(userID, this);
1427// G4MoleculeTable::Instance()->RecordMolecularConfiguration(userID, this);
1428}
1429
1430//______________________________________________________________________________
1431
1433{
1434 return pow(10, 4.311
1435 - 2.722e3/temperature_K
1436 + 8.565e5/(temperature_K *temperature_K)
1437 - 1.181e8/(temperature_K*temperature_K*temperature_K ))*1e-9*m2/s;
1438}
1439
1440//______________________________________________________________________________
1441
1442void
1444ScaleAllDiffusionCoefficientsOnWater(double temperature_K)
1445{
1446 double D_water_0 = DiffCoeffWater(fgTemperature);
1447 double D_water_f = DiffCoeffWater(temperature_K);
1448
1449 G4cout << "Scaling factor = " << D_water_f/D_water_0 << G4endl;
1450
1453
1454 while(it())
1455 {
1456 G4MolecularConfiguration* conf = it.value();
1457 double D_0 = conf->GetDiffusionCoefficient() ;
1458 double D_f = D_water_f * D_0 /D_water_0;
1459 conf->SetDiffusionCoefficient(D_f);
1460 };
1461}
1462
1463//______________________________________________________________________________
1464
1472
1473//______________________________________________________________________________
1474
1476{
1478 fgTemperature = temperature;
1479}
1480
1481//______________________________________________________________________________
1482
1487
1488//______________________________________________________________________________
1489
1493{
1494 for(auto it : fMolConfPerID)
1495 {
1496 if(it->GetUserID() == userID) return it;
1497 }
1498 return nullptr;
1499}
1500
1501//______________________________________________________________________________
1502
1508
1509//______________________________________________________________________________
1510
1512{
1513 const std::vector<G4MolecularConfiguration*>& species =
1515
1516 for(auto specie : species)
1517 {
1518 specie->Finalize();
1519 }
1520
1521}
1522
1524{
1525 const std::vector<G4MolecularConfiguration*>& species =
1527 G4cout<<G4endl;
1528 G4cout<<"Molecular Config"<<std::setw(25)<<" | Diffusion Coefficient (m2 / s) "<<std::setw(20)<<" | Radius (nm) "<<G4endl;
1529 G4cout<<"__________________________________________"
1530 "___________________________________"<<G4endl;
1531 for(auto specie : species)
1532 {
1533 G4cout<<specie->GetName()
1534 <<std::setw(G4int(30 - specie->GetName().length()))
1535 <<right<<specie->GetDiffusionCoefficient() * 1.0e3<<std::setw(30)
1536 <<specie->GetVanDerVaalsRadius()/CLHEP::nm<<G4endl;
1537 G4cout<<"__________________________________________"
1538 "___________________________________"<<G4endl;
1539 }
1540
1541}
G4double(*)(G4double) function
@ JustWarning
@ FatalException
@ FatalErrorInArgument
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
const char * removePath(const char *path)
void WRITE(std::ostream &out, const T &toBeSaved)
void READ(std::istream &in, T &toBeSaved)
std::mutex G4Mutex
double G4double
Definition G4Types.hh:83
int G4int
Definition G4Types.hh:85
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
G4int AddElectron(G4int orbit, G4int number=1)
G4int RemoveElectron(G4int orbit, G4int number=1)
G4int GetOccupancy(G4int orbit) const
const G4ElectronOccupancy * FindCommonElectronOccupancy(const G4MoleculeDefinition *molDef, const G4ElectronOccupancy &eOcc)
G4int Insert(const G4MoleculeDefinition *molDef, const G4ElectronOccupancy &eOcc, G4MolecularConfiguration *molConf)
const std::vector< G4MolecularConfiguration * > & GetAllSpecies()
void RecordNewlyLabeledConfiguration(G4MolecularConfiguration *molConf)
G4MolecularConfiguration * GetOrCreateMolecularConfiguration(const G4MoleculeDefinition *molDef, const G4ElectronOccupancy &eOcc)
G4MolecularConfiguration * GetMolecularConfiguration(const G4MoleculeDefinition *molDef, const G4ElectronOccupancy &eOcc)
void AddUserID(const G4String &name, G4MolecularConfiguration *molecule)
static G4MolecularConfiguration * Load(std::istream &)
void SetUserID(const G4String &userID)
static G4MolecularConfigurationManager * GetManager()
const G4String & GetName() const
const G4ElectronOccupancy * fElectronOccupancy
G4MolecularConfiguration * IonizeMolecule(G4int) const
const G4String & GetLabel() const
G4MolecularConfiguration * ChangeConfiguration(const G4ElectronOccupancy &newElectronOccupancy) const
G4MolecularConfiguration & operator=(G4MolecularConfiguration &right)
G4MolecularConfiguration * RemoveElectron(G4int, G4int number=1) const
const G4MoleculeDefinition * GetDefinition() const
static void ScaleAllDiffusionCoefficientsOnWater(double temperature_K)
G4MolecularConfiguration * MoveOneElectron(G4int, G4int) const
static double ReturnDefaultDiffCoeff(const G4Material *, double, const G4MolecularConfiguration *molConf)
const G4MoleculeDefinition * fMoleculeDefinition
static void SetGlobalTemperature(G4double)
static G4MolecularConfiguration * GetOrCreateMolecularConfiguration(const G4MoleculeDefinition *)
const G4ElectronOccupancy * GetElectronOccupancy() const
void CheckElectronOccupancy(const char *line) const
const std::vector< const G4MolecularDissociationChannel * > * GetDissociationChannels() const
const G4String & GetFormatedName() const
static G4MolecularConfigurationManager * fgManager
G4MolecularConfiguration(const G4MoleculeDefinition *, const G4ElectronOccupancy &, const G4String &label="")
static G4MolecularConfiguration * GetMolecularConfiguration(const G4MoleculeDefinition *, const G4String &label)
G4MolecularConfiguration * ExciteMolecule(G4int) const
static double DiffCoeffWater(double temperature_K)
G4MolecularConfiguration * AddElectron(G4int orbit, G4int n=1) const
static G4MolecularConfiguration * CreateMolecularConfiguration(const G4String &userIdentifier, const G4MoleculeDefinition *, bool &wasAlreadyCreated)
const G4ElectronOccupancy * GetGroundStateElectronOccupancy() const
const G4String & GetName() const
const G4String & GetFormatedName() const
G4double GetVanDerVaalsRadius() const
G4double GetDiffusionCoefficient() const
const std::vector< const G4MolecularDissociationChannel * > * GetDecayChannels(const G4MolecularConfiguration *) const
G4MoleculeDefinition * GetMoleculeDefinition(const G4String &, bool mustExist=true)
static G4MoleculeTable * Instance()
G4ConfigurationIterator GetConfigurationIterator()
static G4String ConvertToString(G4bool boolVal)
#define INT_MAX
Definition templates.hh:90