Geant4 11.1.1
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
61
63
65
67{
69}
70
72 double,
74 molConf)
75{
76 return molConf->fDynDiffusionCoefficient;
77}
78
80 const G4String& label,
81 int charge)
82{
83 fMoleculeDefinition = moleculeDef;
84
85 fLabel = new G4String(label);
86
87 fMoleculeID = GetManager()->Insert(moleculeDef,
88 label,
89 this);
91
92 fDynCharge = charge;
93
95
99
101 fName += "^";
103
105 fFormatedName += "^";
106 fFormatedName += "{";
108 fFormatedName += "}";
109
111 fIsFinalized = false;
112}
113
115{
116 if(fIsFinalized)
117 {
119 errMsg << "This molecular configuration " << GetName()
120 << " is already finalized. Therefore its "
121 " properties cannot be changed.";
122 G4Exception("G4MolecularConfiguration::MakeExceptionIfFinalized",
123 "CONF_FINALIZED",FatalException,errMsg);
124 }
125}
126
127//______________________________________________________________________________
128
131{
132 if (!fgManager)
133 {
135 if (!fgManager) // double check for MT
136 {
137 fgManager = new G4MolecularConfiguration::
138 G4MolecularConfigurationManager();
139 }
140 lock.unlock();
141 }
142
143 return fgManager;
144}
145
146//______________________________________________________________________________
147
150{
151// G4cout << "Does G4AllocatorList exists= ";
152// G4cout << (G4AllocatorList::GetAllocatorListIfExist() ? "true":"false")
153// << G4endl;
154
155 G4MolecularConfigurationManager::MolElectronConfTable::iterator it1;
156 G4MolecularConfigurationManager::ElectronOccupancyTable::
157 iterator it2;
158
159 for (it1 = fElecOccTable.begin(); it1 != fElecOccTable.end(); it1++)
160 {
161 for (it2 = it1->second.begin(); it2 != it1->second.end(); it2++)
162 {
163 if (it2->second)
164 {
165 delete it2->second;
166 }
167 }
168 }
169 fElecOccTable.clear();
170 fgManager = 0;
171}
172
173//______________________________________________________________________________
174// G4MolecularConfigurationManager
177Insert(const G4MoleculeDefinition* molDef,
178 const G4ElectronOccupancy& eOcc,
180{
181 //G4AutoLock lock(&fMoleculeCreationMutex);
182
183 ElectronOccupancyTable& table2 = fElecOccTable[molDef];
184 ElectronOccupancyTable::iterator it = table2.find(eOcc);
185
186 if(it == table2.end())
187 {
188 table2[eOcc] = molConf;
189 }
190 else
191 {
193 errMsg << "The same molecular configuration seemed to be recorded twice";
194 G4Exception("G4MolecularConfigurationManager::"
195 "SetMolecularConfiguration(const G4MoleculeDefinition* molDef,"
196 "const G4ElectronOccupancy& eOcc,"
197 "G4MolecularConfiguration* molConf)",
198 "",
200 errMsg
201 );
202 }
203
204 fLastMoleculeID++;
205
206 fMolConfPerID.push_back(molConf);
207
208 //lock.unlock();
209 return fLastMoleculeID;
210}
211
212//______________________________________________________________________________
213
217 const G4ElectronOccupancy& eOcc)
218{
219 //G4AutoLock lock(&fMoleculeCreationMutex);
220
221 MolElectronConfTable::iterator it1 = fElecOccTable.find(molDef);
222
223 if(it1 == fElecOccTable.end())
224 {
225 // TODO = handle exception ?
226 return 0;
227 }
228
229 ElectronOccupancyTable& table2 = it1->second;
230 ElectronOccupancyTable::iterator it2 = table2.find(eOcc);
231
232 //lock.unlock();
233
234 if (it2 == table2.end())
235 {
236 // TODO = handle exception ?
237 return 0;
238 }
239
240 return &(it2->first);
241}
242
243//______________________________________________________________________________
244
248 const G4ElectronOccupancy& eOcc)
249{
250 MolElectronConfTable::iterator it1 = fElecOccTable.find(molDef);
251
252 if(it1 == fElecOccTable.end()) return 0;
253
254 ElectronOccupancyTable& table2 = it1->second;
255 ElectronOccupancyTable::iterator it = table2.find(eOcc);
256
257 if(it == table2.end())
258 {
259 return 0;
260 }
261 else
262 {
263 return it->second;
264 }
265
266 return 0;
267}
268
269//______________________________________________________________________________
270
272Insert(const G4MoleculeDefinition* molDef,
273 int charge,
275{
276
277 //G4AutoLock lock(&fMoleculeCreationMutex);
278 ChargeTable& table2 = fChargeTable[molDef];
279 ChargeTable::iterator it = table2.find(charge);
280
281 if(it == table2.end())
282 {
283 table2[charge] = molConf;
284 }
285 else
286 {
287 //lock.unlock();
289 errMsg << "The same molecular configuration seemed to be recorded twice";
290 G4Exception("G4MolecularConfigurationManager::"
291 "SetMolecularConfiguration(const G4MoleculeDefinition* molDef,"
292 "int charge,"
293 "G4MolecularConfiguration* molConf)",
294 "", FatalException, errMsg);
295 }
296
297 fLastMoleculeID++;
298 fMolConfPerID.push_back(molConf);
299 //lock.unlock();
300 return fLastMoleculeID;
301}
302
303//______________________________________________________________________________
304
308 int charge)
309{
310 //G4AutoLock lock(&fMoleculeCreationMutex);
311
312 MolChargeConfTable::iterator it1 = fChargeTable.find(molDef);
313
314 if(it1 == fChargeTable.end()) return 0;
315
316 ChargeTable& table2 = it1->second;
317 ChargeTable::iterator it = table2.find(charge);
318
319 if(it == table2.end())
320 {
321 return 0;
322 }
323 else
324 {
325 return it->second;
326 }
327
328 return 0;
329
330 //lock.unlock();
331 return 0;
332}
333
334//______________________________________________________________________________
335// Static method in G4MolecularConfiguration
339{
341 {
342 const G4ElectronOccupancy& elecOcc =
344 G4MolecularConfiguration* molConf =
345 GetManager()->GetMolecularConfiguration(molDef, elecOcc);
346
347 if (molConf)
348 {
349 return molConf;
350 }
351 else
352 {
353 G4MolecularConfiguration* newConf =
354 new G4MolecularConfiguration(molDef,
355 elecOcc);
356 newConf->SetUserID(molDef->GetName());
357 return newConf;
358 }
359 }
360 else
361 {
362 G4MolecularConfiguration* molConf =
363 GetManager()->GetMolecularConfiguration(molDef, molDef->GetCharge());
364 if(molConf)
365 {
366 return molConf;
367 }
368 else
369 {
370 G4MolecularConfiguration* newConf =
371 new G4MolecularConfiguration(molDef, molDef->GetCharge());
372 newConf->SetUserID(molDef->GetName());
373 return newConf;
374 }
375 }
376}
377
378//______________________________________________________________________________
379
383 const G4ElectronOccupancy& elecOcc)
384{
385 return GetManager()->GetOrCreateMolecularConfiguration(molDef, elecOcc);
386
387// G4MolecularConfiguration* molConf =
388// GetManager()->GetMolecularConfiguration(molDef, elecOcc);
389//
390// if (molConf)
391// {
392// return molConf;
393// }
394// else
395// {
396// G4MolecularConfiguration* newConf =
397// new G4MolecularConfiguration(molDef, elecOcc);
398// return newConf;
399// }
400}
401
402//______________________________________________________________________________
403
407 int charge)
408{
409 G4MolecularConfiguration* molConf =
410 GetManager()->GetMolecularConfiguration(molDef, charge);
411
412 if(molConf)
413 {
414 return molConf;
415 }
416 else
417 {
418 G4MolecularConfiguration* newConf =
419 new G4MolecularConfiguration(molDef, charge);
420 return newConf;
421 }
422}
423
424//______________________________________________________________________________
425
427{
429 if (fgManager) delete fgManager;
430 fgManager = 0;
431 lock.unlock();
432}
433
434//______________________________________________________________________________
435// G4MolecularConfiguration
438 const G4ElectronOccupancy& elecOcc,
439 const G4String& label)
440{
441 fMoleculeDefinition = moleculeDef;
442
443 fMoleculeID = GetManager()->Insert(moleculeDef,
444 elecOcc,
445 this);
447 elecOcc);
448
449 /*
450 fgManager->fTable[fMoleculeDefinition][elecOcc] = this;
451 std::map<G4ElectronOccupancy, G4MolecularConfiguration*, comparator>::iterator it ;
452 it = fgManager->fTable[moleculeDef].find(elecOcc);
453 fElectronOccupancy = &(it->first);
454 */
455
458 + moleculeDef->GetCharge();
460
464
466 fName += "^";
468
470 fFormatedName += "^";
471 fFormatedName += "{";
473 fFormatedName += "}";
474
475 fLabel = 0; // let it here
476
477 if(label != "")
478 {
479 SetLabel(label);
480 }
481
483
484 fIsFinalized = false;
485}
486
487//______________________________________________________________________________
488
491 int charge)
492{
493 fMoleculeDefinition = moleculeDef;
494
495 fMoleculeID = GetManager()->Insert(moleculeDef,
496 charge,
497 this);
499
500 fDynCharge = charge;
502
506
508 fName += "^";
510
512 fFormatedName += "^";
513 fFormatedName += "{";
515 fFormatedName += "}";
516
517 fLabel = 0;
518
520
521 fIsFinalized = false;
522}
523
524//______________________________________________________________________________
525
527{
529
530// if (G4AllocatorList::GetAllocatorListIfExist())
531// {
532// if (fElectronOccupancy)
533// {
534// delete fElectronOccupancy;
535// fElectronOccupancy = 0;
536// }
537// }
538}
539
540//______________________________________________________________________________
541
544ChangeConfiguration(const G4ElectronOccupancy& newElectronOccupancy) const
545{
548 newElectronOccupancy);
549
550 if (!output)
551 {
553 newElectronOccupancy);
554 }
555 return output;
556}
557
558//______________________________________________________________________________
559
562{
565
566 if (!output)
567 {
568 output = new G4MolecularConfiguration(fMoleculeDefinition, charge);
569 }
570 return output;
571}
572
573//______________________________________________________________________________
574
577{
578// if (&right == this) return *this;
579 return *this;
580}
581
582//______________________________________________________________________________
583
584/** Method used in Geant4-DNA to excite water molecules
585 */
588{
589// MakeExceptionIfFinalized();
590 CheckElectronOccupancy(__func__);
591 G4ElectronOccupancy newElectronOccupancy(*fElectronOccupancy);
592
593 newElectronOccupancy.RemoveElectron(ExcitedLevel, 1);
594 newElectronOccupancy.AddElectron(5, 1);
595
596 return ChangeConfiguration(newElectronOccupancy);
597}
598
599//______________________________________________________________________________
600
601/** Method used in Geant4-DNA to ionize water molecules
602 */
605{
606// MakeExceptionIfFinalized();
607 CheckElectronOccupancy(__func__);
608 G4ElectronOccupancy newElectronOccupancy(*fElectronOccupancy);
609
610 if (newElectronOccupancy.GetOccupancy(IonizedLevel) != 0)
611 {
612 newElectronOccupancy.RemoveElectron(IonizedLevel, 1);
613 }
614 else
615 {
616 G4String errMsg = "There is no electron on the orbit "
617 + G4UIcommand::ConvertToString(IonizedLevel)
618 + " you want to free. The molecule's name you want to ionized is "
619 + GetName();
620 G4Exception("G4MolecularConfiguration::IonizeMolecule",
621 "",
623 errMsg);
624 PrintState();
625 }
626
627 // DEBUG
628 // PrintState();
629
630 return ChangeConfiguration(newElectronOccupancy);
631}
632
633//______________________________________________________________________________
634
636 G4int number) const
637{
638// MakeExceptionIfFinalized();
639 CheckElectronOccupancy(__func__);
640 G4ElectronOccupancy newElectronOccupancy(*fElectronOccupancy);
641 newElectronOccupancy.AddElectron(orbit, number);
642 return ChangeConfiguration(newElectronOccupancy);
643}
644
645//______________________________________________________________________________
646
649 G4int number) const
650{
651// MakeExceptionIfFinalized();
652 CheckElectronOccupancy(__func__);
653 G4ElectronOccupancy newElectronOccupancy(*fElectronOccupancy);
654
655 if (newElectronOccupancy.GetOccupancy(orbit) != 0)
656 {
657 newElectronOccupancy.RemoveElectron(orbit, number);
658 }
659 else
660 {
661 G4String errMsg = "There is already no electron into the orbit "
663 + " you want to free. The molecule's name is " + GetName();
664 G4Exception("G4MolecularConfiguration::RemoveElectron",
665 "",
667 errMsg);
668 PrintState();
669 }
670
671 return ChangeConfiguration(newElectronOccupancy);
672}
673
674//______________________________________________________________________________
675
678 G4int orbitToFill) const
679{
680// MakeExceptionIfFinalized();
681 CheckElectronOccupancy(__func__);
682 G4ElectronOccupancy newElectronOccupancy(*fElectronOccupancy);
683
684 if (newElectronOccupancy.GetOccupancy(orbitToFree) >= 1)
685 {
686 newElectronOccupancy.RemoveElectron(orbitToFree, 1);
687 newElectronOccupancy.AddElectron(orbitToFill, 1);
688 }
689 else
690 {
691 G4String errMsg = "There is no electron on the orbit "
692 + G4UIcommand::ConvertToString(orbitToFree)
693 + " you want to free. The molecule's name is " + GetName();
694 G4Exception("G4MolecularConfiguration::MoveOneElectron",
695 "",
697 errMsg);
698 PrintState();
699 }
700
701 return ChangeConfiguration(newElectronOccupancy);
702}
703
704//______________________________________________________________________________
705
707{
708 return fName;
709}
710
711//______________________________________________________________________________
712
714{
715 return fFormatedName;
716}
717
718//______________________________________________________________________________
719
721{
723}
724
725//______________________________________________________________________________
726
728{
729 CheckElectronOccupancy(__func__);
731}
732
733//______________________________________________________________________________
734
736{
737 G4cout << "-------------- Start Printing State " << GetName()
738 << " ---------------" << G4endl;
739
741 {
742 G4cout << "--------------Print electronic state of " << GetName()
743 << "---------------" << G4endl;
746 {
747 G4cout<<"At ground state"<<G4endl;
748 }
749 }
750 else
751 {
752 G4cout << "--- No electron occupancy set up ---" << G4endl;
753 }
754
755 G4cout << "Charge :"
756 << fDynCharge
757 << G4endl;
758
759 if(fLabel)
760 {
761 G4cout << "Label :"
762 << GetLabel()
763 << G4endl;
764 }
765 G4cout << "-------------- End Of State " << GetName()
766 << " -----------------------" << G4endl;
767}
768
769//______________________________________________________________________________
770
771// added - to be transformed in a "Decay method"
772const vector<const G4MolecularDissociationChannel*>*
774{
775 // if (fElectronOccupancy == 0) return 0;
777}
778
779//______________________________________________________________________________
780
782{
784 else G4Exception("G4MolecularConfiguration::GetMoleculeID",
785 "",
787 "You should first enter a molecule definition");
788
789 return INT_MAX;
790}
791
792//______________________________________________________________________________
793
794const char* removePath(const char* path)
795{
796 const char* pDelimeter = strrchr(path, '\\');
797 if (pDelimeter) path = pDelimeter + 1;
798
799 pDelimeter = strrchr(path, '/');
800 if (pDelimeter) path = pDelimeter + 1;
801
802 return path;
803}
804
805//______________________________________________________________________________
806
808{
809 if (fElectronOccupancy == 0)
810 {
811 G4String functionName(function);
812 G4ExceptionDescription description;
813 description
814 << "No G4ElectronOccupancy was defined for molecule definition : "
816 << ". The definition was probably defined using the charge state, "
817 "rather than electron state.";
818
819 G4Exception(functionName, "", FatalErrorInArgument, description);
820 }
821}
822
823//______________________________________________________________________________
824
827{
828 //G4AutoLock lock(&fMoleculeCreationMutex);
829
830 LabelTable& tmpMap = fLabelTable[molConf->fMoleculeDefinition];
831
832 LabelTable::iterator it = tmpMap.find(*molConf->fLabel);
833
834 if(it == tmpMap.end())
835 {
836 tmpMap[*(molConf->fLabel)] = molConf;
837 }
838 else
839 {
841 errMsg << "The same molecular configuration seemed to be recorded twice";
842 G4Exception("G4MolecularConfigurationManager::"
843 "SetMolecularConfiguration(const G4MoleculeDefinition* molDef,"
844 "const G4String& label,"
845 "G4MolecularConfiguration* molConf)",
846 "", FatalException, errMsg);
847 }
848
849 //lock.unlock();
850}
851
853 G4MolecularConfiguration* molecule)
854{
855 UserIDTable::iterator it = fUserIDTable.find(userID);
856
857 if(it == fUserIDTable.end())
858 {
859 fUserIDTable[userID] = molecule;
860 }
861 else if(molecule != it->second)
862 {
863 // TODO improve exception
864 // exception
865 G4ExceptionDescription description;
866 description << "The user identifier " << userID
867 << " was already given in another configuration in the table"
868 << G4endl;
869 G4Exception("G4MolecularConfiguration::G4MolecularConfigurationManager::AddUserID",
870 "CONF_ALREADY_RECORDED",
872 description);
873 }
874}
875
876//______________________________________________________________________________
877
880{
881 MolElectronConfTable::iterator it1 =
882 fElecOccTable.find(configuration->GetDefinition());
883 MolElectronConfTable::iterator end = fElecOccTable.end();
884
885 if (it1 == end) return;
886
887 std::map<G4ElectronOccupancy, G4MolecularConfiguration*, comparator>::
888 iterator it2 =
889 it1->second.find(*configuration->GetElectronOccupancy());
890
891 if (it2 == it1->second.end()) return;
892
893 it2->second = 0;
894// it1->second.erase(it2);
895
896 configuration->fElectronOccupancy = 0;
897}
898
899//______________________________________________________________________________
900
904 const G4String& label)
905{
906 //G4AutoLock lock(&fMoleculeCreationMutex);
907
908 MolLabelConfTable::iterator it1 = fLabelTable.find(molDef);
909
910 if(it1 == fLabelTable.end()) return 0;
911
912 LabelTable& table2 = it1->second;
913
914 LabelTable::iterator it2 = table2.find(label);
915
916 //lock.unlock();
917
918 if(it2 == table2.end()) return 0;
919 return it2->second;
920}
921
922//______________________________________________________________________________
923
926GetMolecularConfiguration(int moleculeID)
927{
928 if(moleculeID > (int) fMolConfPerID.size() ||
929 moleculeID < 0) return 0;
930
931 return fMolConfPerID[moleculeID];
932}
933
934//______________________________________________________________________________
935
936G4int
938Insert(const G4MoleculeDefinition* molDef,
939 const G4String& label,
941{
942 G4AutoLock lock(&fMoleculeCreationMutex);
943 LabelTable& tmpMap = fLabelTable[molDef];
944 LabelTable::iterator it = tmpMap.find(label);
945
946 if(it == tmpMap.end())
947 {
948 fLastMoleculeID++;
949 tmpMap[label] = molConf;
950 lock.unlock();
951 }
952 else
953 {
954 lock.unlock();
956 errMsg << "The same molecular configuration seemed to be recorded twice";
957 G4Exception("G4MolecularConfigurationManager::"
958 "SetMolecularConfiguration(const G4MoleculeDefinition* molDef,"
959 "const G4String& label,"
960 "G4MolecularConfiguration* molConf)",
961 "", FatalException, errMsg);
962 }
963
964 fMolConfPerID.push_back(molConf);
965
966 return fLastMoleculeID;
967}
968
969//______________________________________________________________________________
970
973 const G4String& label)
974{
975 return GetManager()->GetMolecularConfiguration(molDef, label);
976}
977
978//______________________________________________________________________________
979
982{
983 return GetManager()->GetMolecularConfiguration(moleculeID);
984}
985
986//______________________________________________________________________________
987
990 const G4MoleculeDefinition* molDef,
991 int charge,
992 const G4String& label,
993 bool& wasAlreadyCreated)
994{
995 wasAlreadyCreated = false;
996 G4MolecularConfiguration* molConf =
997 GetManager()->GetMolecularConfiguration(molDef, charge);
998
999 if (molConf)
1000 {
1001 if(molConf->fLabel == 0)
1002 {
1003 molConf->SetLabel(label);
1005 wMsg << "The molecular configuration for the definition named "
1006 << molDef->GetName()
1007 << " with charge " << charge << " has already been created "
1008 "but with NO label";
1009 G4Exception("G4MolecularConfiguration::CreateMolecularConfiguration",
1010 "DOUBLE_CREATION",
1012 wMsg);
1013 }
1014 else if(*(molConf->fLabel) == "" )
1015 {
1016 molConf->SetLabel(label);
1017 }
1018 else if(*(molConf->fLabel) != label)
1019 {
1020 G4ExceptionDescription errMsg ;
1021 errMsg << "The molecular configuration for the definition named "
1022 << molDef->GetName()
1023 << " with charge " << charge << " has already been created "
1024 "but with a different label :"
1025 << molConf->GetLabel();
1026 G4Exception("G4MolecularConfiguration::CreateMolecularConfiguration",
1027 "DOUBLE_CREATION",
1029 errMsg);
1030 // KILL APP
1031 }
1032
1033 if(molConf->fUserIdentifier == "")
1034 {
1035 molConf->fUserIdentifier = userIdentifier;
1036
1038 wMsg << "The molecular configuration for the definition named "
1039 << molDef->GetName()
1040 << " with label " << label << " has already been created.";
1041 G4Exception("G4MolecularConfiguration::CreateMolecularConfiguration",
1042 "DOUBLE_CREATION",
1044 wMsg);
1045 }
1046 else if(molConf->fUserIdentifier != userIdentifier)
1047 {
1048 G4ExceptionDescription errMsg ;
1049 errMsg << "The molecular configuration for the definition named "
1050 << molDef->GetName()
1051 << " with label " << label << " has already been created "
1052 "BUT with a different user ID :"
1053 << molConf->fUserIdentifier;
1054 G4Exception("G4MolecularConfiguration::CreateMolecularConfiguration",
1055 "DOUBLE_CREATION",
1057 errMsg);
1058 // KILL APP
1059 }
1060
1061 wasAlreadyCreated = true;
1062 return molConf;
1063 }
1064 else
1065 {
1066 G4MolecularConfiguration* newConf =
1067 new G4MolecularConfiguration(molDef, label, charge);
1068 newConf->fUserIdentifier = userIdentifier;
1069
1070 GetManager()->AddUserID(userIdentifier, newConf);
1071
1072// G4MoleculeTable::Instance()->RecordMolecularConfiguration(userIdentifier,
1073// newConf);
1074 return newConf;
1075 }
1076}
1077
1078//______________________________________________________________________________
1079
1082CreateMolecularConfiguration(const G4String& userIdentifier,
1083 const G4MoleculeDefinition* molDef,
1084 bool& wasAlreadyCreated)
1085{
1086 wasAlreadyCreated = false;
1087 G4MolecularConfiguration* preRegisteredMolConf =
1088 GetManager()->GetMolecularConfiguration(userIdentifier);
1089
1090 if(preRegisteredMolConf)
1091 {
1092 if(preRegisteredMolConf->GetDefinition() == molDef)
1093 {
1094 wasAlreadyCreated = true;
1095 return preRegisteredMolConf;
1096 }
1097 }
1098
1100 {
1101 const G4ElectronOccupancy& elecOcc = *molDef
1103 G4MolecularConfiguration* molConf =
1104 GetManager()->GetMolecularConfiguration(molDef, elecOcc);
1105
1106 if(molConf)
1107 {
1108 if(molConf->fUserIdentifier == "")
1109 {
1110 molConf->fUserIdentifier = userIdentifier;
1111 }
1112 else if(molConf->fUserIdentifier != userIdentifier)
1113 {
1115 errMsg << "A molecular configuration for the definition named "
1116 << molDef->GetName() << " has already been created "
1117 "and recorded with a different user ID "
1118 << molConf->fUserIdentifier;
1119 G4Exception("G4MolecularConfiguration::CreateMolecularConfiguration",
1120 "DOUBLE_CREATION",
1122 errMsg);
1123 }
1124// TODO exception
1126 errMsg << "A molecular configuration for the definition named "
1127 << molDef->GetName() << " has already been created.";
1128 G4Exception("G4MolecularConfiguration::CreateMolecularConfiguration",
1129 "DOUBLE_CREATION",
1131 errMsg);
1132 wasAlreadyCreated = true;
1133 return molConf;
1134 }
1135 else
1136 {
1137 // G4cout << "Create molConf for " << molDef->GetName() << G4endl;
1139 elecOcc);
1140 newConf->fUserIdentifier = userIdentifier;
1141
1142 GetManager()->AddUserID(userIdentifier, newConf);
1143
1144// G4MoleculeTable::Instance()->RecordMolecularConfiguration(userIdentifier,
1145// newConf);
1146 return newConf;
1147 }
1148 }
1149 else
1150 {
1151 return CreateMolecularConfiguration(userIdentifier,
1152 molDef,
1153 molDef->GetName(),
1154 molDef->GetCharge(),
1155 wasAlreadyCreated);
1156 }
1157}
1158
1159//______________________________________________________________________________
1160
1163CreateMolecularConfiguration(const G4String& userIdentifier,
1164 const G4MoleculeDefinition* molDef,
1165 const G4String& label,
1166 bool& wasAlreadyCreated)
1167{
1168 assert(label != "");
1169 wasAlreadyCreated = false;
1170
1171 G4MolecularConfiguration* molConf =
1172 GetManager()->GetMolecularConfiguration(molDef, label);
1173 if(molConf)
1174 {
1175 if(molConf->fLabel
1176 && *molConf->fLabel == label)
1177 {
1178 wasAlreadyCreated = true;
1179 return molConf;
1180 }
1181 else if(molConf->fLabel == 0)
1182 {
1183 wasAlreadyCreated = true;
1184 molConf->SetLabel(label);
1185 return molConf;
1186 }
1187 else if(*molConf->fLabel == "")
1188 {
1189 wasAlreadyCreated = true;
1190 molConf->SetLabel(label);
1191 return molConf;
1192 }
1193
1194 molConf->PrintState();
1195 G4ExceptionDescription errMsg ;
1196 errMsg << "A molecular configuration for the definition named "
1197 << molDef->GetName()
1198 << " has already been created "
1199 "with user ID "
1200 << molConf->fUserIdentifier << " and label "
1201 << molConf->GetLabel();
1202 G4Exception("G4MolecularConfiguration::CreateMolecularConfiguration",
1203 "DOUBLE_CREATION",
1205 errMsg);
1206 // KILL APP
1207 }
1208 else
1209 {
1210 G4MolecularConfiguration* newConf =
1211 new G4MolecularConfiguration(molDef,
1212 label,
1213 molDef->GetCharge());
1214 newConf->fUserIdentifier = userIdentifier;
1215
1216 GetManager()->AddUserID(userIdentifier, newConf);
1217
1218// G4MoleculeTable::Instance()->
1219// RecordMolecularConfiguration(userIdentifier, newConf);
1220 return newConf;
1221 }
1222 return molConf;
1223}
1224
1225//______________________________________________________________________________
1226
1229CreateMolecularConfiguration(const G4String& userIdentifier,
1230 const G4MoleculeDefinition* molDef,
1231 const G4String& label,
1232 const G4ElectronOccupancy& eOcc,
1233 bool& wasAlreadyCreated)
1234{
1235 assert(label != "");
1236 wasAlreadyCreated = false;
1237
1238 G4MolecularConfiguration* molConf =
1239 GetManager()->GetMolecularConfiguration(molDef, eOcc);
1240
1241 if(molConf)
1242 {
1243 if(molConf->GetElectronOccupancy())
1244 {
1245 if(*molConf->GetElectronOccupancy() == eOcc)
1246 {
1247 if(molConf->fLabel && *molConf->fLabel == label)
1248 {
1249 wasAlreadyCreated = true;
1250 return molConf;
1251 }
1252 else if(molConf->fLabel == 0)
1253 {
1254 wasAlreadyCreated = true;
1255 molConf->SetLabel(label);
1256 return molConf;
1257 }
1258 else if(*molConf->fLabel == "")
1259 {
1260 wasAlreadyCreated = true;
1261 molConf->SetLabel(label);
1262 return molConf;
1263 }
1264 }
1265 }
1266
1267
1268 molConf->PrintState();
1269 G4ExceptionDescription errMsg ;
1270 errMsg << "A molecular configuration for the definition named "
1271 << molDef->GetName()
1272 << " has already been created "
1273 "with user ID "
1274 << molConf->fUserIdentifier
1275 << " and possible different electronic state";
1276 G4Exception("G4MolecularConfiguration::CreateMolecularConfiguration",
1277 "DOUBLE_CREATION",
1279 errMsg);
1280 }
1281 else
1282 {
1283 G4MolecularConfiguration* newConf =
1284 new G4MolecularConfiguration(molDef,
1285 eOcc,
1286 label);
1287 newConf->fUserIdentifier = userIdentifier;
1288
1289 GetManager()->AddUserID(userIdentifier, newConf);
1290
1291// G4MoleculeTable::Instance()->
1292// RecordMolecularConfiguration(userIdentifier, newConf);
1293 return newConf;
1294 }
1295 return molConf;
1296}
1297
1298
1299//______________________________________________________________________________
1300
1304 const G4ElectronOccupancy& eOcc)
1305{
1306 MolElectronConfTable::iterator it1 = fElecOccTable.find(molDef);
1307
1308 if(it1 == fElecOccTable.end())
1309 {
1310 return new G4MolecularConfiguration(molDef, eOcc);
1311 }
1312
1313 ElectronOccupancyTable& table2 = it1->second;
1314 ElectronOccupancyTable::iterator it = table2.find(eOcc);
1315
1316 if(it == table2.end())
1317 {
1318 G4MolecularConfiguration* molConf =
1319 new G4MolecularConfiguration(molDef, eOcc);
1320// molConf->Finalize();
1321 return molConf;
1322 }
1323 else
1324 {
1325 return it->second;
1326 }
1327
1328 return 0;
1329}
1330
1331//______________________________________________________________________________
1332
1336 int charge)
1337{
1338 MolChargeConfTable::iterator it1 = fChargeTable.find(molDef);
1339
1340 if(it1 == fChargeTable.end())
1341 {
1342 G4AutoLock lock(&fMoleculeCreationMutex);
1343
1344 G4MolecularConfiguration* newConf = new G4MolecularConfiguration(molDef, charge);
1345 return newConf ;
1346 }
1347
1348 ChargeTable& table2 = it1->second;
1349 ChargeTable::iterator it = table2.find(charge);
1350
1351 if(it == table2.end())
1352 {
1353 G4AutoLock lock(&fMoleculeCreationMutex);
1354
1355 G4MolecularConfiguration* newConf =
1356 new G4MolecularConfiguration(molDef, charge);
1357// newConf->Finalize();
1358 return newConf ;
1359 }
1360 else
1361 {
1362 return it->second;
1363 }
1364
1365 return 0;
1366}
1367
1368//______________________________________________________________________________
1369
1371{
1372 G4String moleculeName = fMoleculeDefinition->GetName();
1373 WRITE(out, moleculeName);
1374
1375// if(fLabel)
1376// out << fLabel;
1377// else
1378// out << "";
1381 WRITE(out,fDynDecayTime);
1382 WRITE(out,fDynMass);
1383 WRITE(out,fDynCharge);
1384 WRITE(out,fMoleculeID);
1385 WRITE(out,fFormatedName);
1386 WRITE(out,fName);
1387 WRITE(out,fIsFinalized);
1388}
1389
1390//______________________________________________________________________________
1391
1393{
1394 G4String moleculeName;
1395 READ(in, moleculeName);
1398
1399// G4String label;
1400//
1401// in.read((char*)(&label), sizeof(label));
1402//
1403// if(label)
1404// fLabel = new G4String(label);
1405// else
1406// fLabel = 0;
1409 READ(in,fDynDecayTime);
1410 READ(in,fDynMass);
1411 READ(in,fDynCharge);
1412 READ(in,fMoleculeID);
1413 READ(in,fFormatedName);
1414 READ(in,fName);
1415 READ(in,fIsFinalized);
1416}
1417
1418//______________________________________________________________________________
1419
1421{
1422 return new G4MolecularConfiguration(in);
1423}
1424
1425//______________________________________________________________________________
1426
1428{
1429 fLabel = 0; // TODO: for now not serialized
1430 Unserialize(in);
1434 {
1439
1440 if(fLabel)
1441 {
1443 }
1444 }
1445 else if(fLabel)
1446 {
1448 }
1449 else if(fDynCharge)
1450 {
1452 }
1453}
1454
1455//______________________________________________________________________________
1456
1458{
1459 fUserIdentifier = userID;
1460 GetManager()->AddUserID(userID, this);
1461// G4MoleculeTable::Instance()->RecordMolecularConfiguration(userID, this);
1462}
1463
1464//______________________________________________________________________________
1465
1467{
1468 return pow(10, 4.311
1469 - 2.722e3/temperature_K
1470 + 8.565e5/(temperature_K *temperature_K)
1471 - 1.181e8/(temperature_K*temperature_K*temperature_K ))*1e-9*m2/s;
1472}
1473
1474//______________________________________________________________________________
1475
1476void
1478ScaleAllDiffusionCoefficientsOnWater(double temperature_K)
1479{
1480 double D_water_0 = DiffCoeffWater(fgTemperature);
1481 double D_water_f = DiffCoeffWater(temperature_K);
1482
1483 G4cout << "Scaling factor = " << D_water_f/D_water_0 << G4endl;
1484
1487
1488 while(it())
1489 {
1490 G4MolecularConfiguration* conf = it.value();
1491 double D_0 = conf->GetDiffusionCoefficient() ;
1492 double D_f = D_water_f * D_0 /D_water_0;
1493 conf->SetDiffusionCoefficient(D_f);
1494 };
1495}
1496
1497//______________________________________________________________________________
1498
1500{
1501 if(bool(fDiffParam) == false)
1502 {
1504 }
1505}
1506
1507//______________________________________________________________________________
1508
1510{
1512 fgTemperature = temperature;
1513}
1514
1515//______________________________________________________________________________
1516
1518{
1519 return fgTemperature;
1520}
1521
1522//______________________________________________________________________________
1523
1527{
1528 for(auto it : fMolConfPerID)
1529 {
1530 if(it->GetUserID() == userID) return it;
1531 }
1532 return 0;
1533}
1534
1535//______________________________________________________________________________
1536
1539{
1540 return GetManager()->GetMolecularConfiguration(userID);
1541}
1542
1543//______________________________________________________________________________
1544
1546{
1547 const std::vector<G4MolecularConfiguration*>& species =
1549
1550 for(std::size_t i = 0; i < species.size() ; ++i)
1551 {
1552 species[i]->Finalize();
1553 }
1554
1555}
1556
1558{
1559 const std::vector<G4MolecularConfiguration*>& species =
1561 G4cout<<G4endl;
1562 G4cout<<"Molecular Config"<<std::setw(25)<<" | Diffusion Coefficient (m2 / s) "<<std::setw(20)<<" | Radius (nm) "<<G4endl;
1563 G4cout<<"__________________________________________"
1564 "___________________________________"<<G4endl;
1565 for(std::size_t i = 0; i < species.size() ; ++i)
1566 {
1567 G4cout<<species[i]->GetName()
1568 <<std::setw(G4int(30 - species[i]->GetName().length()))
1569 <<right<<species[i]->GetDiffusionCoefficient() * 1.0e3<<std::setw(30)
1570 <<species[i]->GetVanDerVaalsRadius()/CLHEP::nm<<G4endl;
1571 G4cout<<"__________________________________________"
1572 "___________________________________"<<G4endl;
1573 }
1574
1575}
G4double(*)(G4double) function
@ JustWarning
@ FatalException
@ FatalErrorInArgument
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
const char * removePath(const char *path)
G4MolecularConfiguration::G4MolecularConfigurationManager MolecularConfigurationManager
void WRITE(std::ostream &out, const T &toBeSaved)
Definition: G4Serialize.hh:41
void READ(std::istream &in, T &toBeSaved)
Definition: G4Serialize.hh:49
std::mutex G4Mutex
Definition: G4Threading.hh:81
double G4double
Definition: G4Types.hh:83
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4int GetTotalOccupancy() const
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 GetDecayTime() 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)
Definition: G4UIcommand.cc:446
#define INT_MAX
Definition: templates.hh:90