Geant4  10.01.p01
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 // $Id: G4MolecularConfiguration.cc 87375 2014-12-02 08:17:28Z gcosmo $
27 //
28 // Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr)
29 //
30 // History:
31 // -----------
32 // 10 Oct 2011 M.Karamitros created
33 //
34 // -------------------------------------------------------------------
35 
37 #include "G4MoleculeDefinition.hh"
38 #include "G4UIcommand.hh"
39 #include "G4AllocatorList.hh"
40 #include "G4AutoLock.hh"
41 
42 using namespace std;
43 
44 #if defined ( WIN32 )
45 #define __func__ __FUNCTION__
46 #endif
47 
48 //______________________________________________________________
49 // G4MolecularConfigurationManager
51 
53 
55 
58 {
59  if (!fgManager)
60  {
62  if (!fgManager) // double check for MT
63  {
65  }
66  lock.unlock();
67  }
68 
69  return fgManager;
70 }
71 
74 {
75 // G4cout << "Does G4AllocatorList exists= ";
76 // G4cout << (G4AllocatorList::GetAllocatorListIfExist() ? "true":"false")
77 // << G4endl;
78 
79  G4MolecularConfigurationManager::MolecularConfigurationTable::iterator it1;
80  std::map<G4ElectronOccupancy, G4MolecularConfiguration*, comparator>::iterator it2;
81 
82  for (it1 = fTable.begin(); it1 != fTable.end(); it1++)
83  {
84  for (it2 = it1->second.begin(); it2 != it1->second.end(); it2++)
85  {
86  if (it2->second)
87  {
88  delete it2->second;
89  }
90  }
91  }
92  fTable.clear();
93  fgManager = 0;
94 }
95 
96 //______________________________________________________________
97 // G4MolecularConfigurationManager
101  const G4ElectronOccupancy& eOcc,
102  G4MolecularConfiguration* molConf)
103 {
104  G4AutoLock lock(&fMoleculeCreationMutex);
105  fTable[molDef][eOcc] = molConf;
106  fLastMoleculeID++;
107  lock.unlock();
108  return fLastMoleculeID;
109 }
110 
111 const G4ElectronOccupancy*
114  const G4MoleculeDefinition* molDef,
115  const G4ElectronOccupancy& eOcc)
116 {
117  std::map<G4ElectronOccupancy, G4MolecularConfiguration*, comparator>::iterator it;
118  G4AutoLock lock(&fMoleculeCreationMutex);
119  it = fTable[molDef].find(eOcc);
120  lock.unlock();
121 
122  if (it == fTable[molDef].end())
123  {
124  // TODO = handle exception ?
125  return 0;
126  }
127 
128  return &(it->first);
129 }
130 
134  const G4ElectronOccupancy& eOcc)
135 {
136  G4AutoLock lock(&fMoleculeCreationMutex);
137  G4MolecularConfiguration* output = fTable[molDef][eOcc];
138  lock.unlock();
139  return output;
140 }
141 
144  int charge,
145  G4MolecularConfiguration* molConf)
146 {
147  G4AutoLock lock(&fMoleculeCreationMutex);
148  fChargeTable[molDef][charge] = molConf;
149  fLastMoleculeID++;
150  lock.unlock();
151  return fLastMoleculeID;
152 }
153 
157  int charge)
158 {
159  G4AutoLock lock(&fMoleculeCreationMutex);
160  G4MolecularConfiguration* output = fChargeTable[molDef][charge];
161  lock.unlock();
162  return output;
163 }
164 
165 //______________________________________________________________
166 // Static method in G4MolecularConfiguration
168 {
169  if (molDef->GetGroundStateElectronOccupancy())
170  {
171  const G4ElectronOccupancy& elecOcc = *molDef
173  G4MolecularConfiguration* molConf = GetManager()->GetMolecularConfiguration(
174  molDef, elecOcc);
175 
176  if (molConf)
177  {
178  return molConf;
179  }
180  else
181  {
183  elecOcc);
184  return newConf;
185  }
186  }
187  else
188  {
189  return GetMolecularConfiguration(molDef, molDef->GetCharge());
190  }
191 }
192 
196  const G4ElectronOccupancy& elecOcc)
197 {
198  G4MolecularConfiguration* molConf = GetManager()->GetMolecularConfiguration(
199  molDef, elecOcc);
200 
201  if (molConf)
202  {
203  return molConf;
204  }
205  else
206  {
208  elecOcc);
209  return newConf;
210  }
211 }
212 
215  int charge)
216 {
217  G4MolecularConfiguration* molConf = GetManager()->GetMolecularConfiguration(
218  molDef, charge);
219 
220  if (molConf)
221  {
222  return molConf;
223  }
224  else
225  {
227  charge);
228  return newConf;
229  }
230 }
231 
233 {
235  if (fgManager) delete fgManager;
236  fgManager = 0;
237  lock.unlock();
238 }
239 
240 //______________________________________________________________
241 // G4MolecularConfiguration
243  const G4ElectronOccupancy& elecOcc)
244 {
245  fMoleculeDefinition = moleculeDef;
246 
247  fMoleculeID = GetManager()->SetMolecularConfiguration(moleculeDef, elecOcc,
248  this);
249  fElectronOccupancy = GetManager()->FindCommonElectronOccupancy(moleculeDef,
250  elecOcc);
251 
252  /*
253  fgManager->fTable[fMoleculeDefinition][elecOcc] = this;
254  std::map<G4ElectronOccupancy, G4MolecularConfiguration*, comparator>::iterator it ;
255  it = fgManager->fTable[moleculeDef].find(elecOcc);
256  fElectronOccupancy = &(it->first);
257  */
258 
259  fDynCharge = fMoleculeDefinition->GetNbElectrons()
260  - fElectronOccupancy->GetTotalOccupancy()
261  + moleculeDef->GetCharge();
262  fDynMass = fMoleculeDefinition->GetMass();
263 
264  fDynDiffusionCoefficient = fMoleculeDefinition->GetDiffusionCoefficient();
265  fDynVanDerVaalsRadius = fMoleculeDefinition->GetVanDerVaalsRadius();
266  fDynDecayTime = fMoleculeDefinition->GetDecayTime();
267 
268  fName = fMoleculeDefinition->GetName();
269  fName += "^";
270  fName += G4UIcommand::ConvertToString(fDynCharge);
271 
272  fFormatedName = fMoleculeDefinition->GetFormatedName();
273  fFormatedName += "^";
274  fFormatedName += "{";
275  fFormatedName += G4UIcommand::ConvertToString(fDynCharge);
276  fFormatedName += "}";
277 }
278 
280  int charge)
281 {
282  fMoleculeDefinition = moleculeDef;
283 
284  fMoleculeID = GetManager()->SetMolecularConfiguration(moleculeDef, charge,
285  this);
286  fElectronOccupancy = 0;
287 
288  fDynCharge = charge;
289  fDynMass = fMoleculeDefinition->GetMass();
290 
291  fDynDiffusionCoefficient = fMoleculeDefinition->GetDiffusionCoefficient();
292  fDynVanDerVaalsRadius = fMoleculeDefinition->GetVanDerVaalsRadius();
293  fDynDecayTime = fMoleculeDefinition->GetDecayTime();
294 
295  fName = fMoleculeDefinition->GetName();
296  fName += "^";
297  fName += G4UIcommand::ConvertToString(fDynCharge);
298 
299  fFormatedName = fMoleculeDefinition->GetFormatedName();
300  fFormatedName += "^";
301  fFormatedName += "{";
302  fFormatedName += G4UIcommand::ConvertToString(fDynCharge);
303  fFormatedName += "}";
304 }
305 
307 {
308  if (fgManager) fgManager->RemoveMolecularConfigurationFromTable(this);
309 
310 // if (G4AllocatorList::GetAllocatorListIfExist())
311 // {
312 // if (fElectronOccupancy)
313 // {
314 // delete fElectronOccupancy;
315 // fElectronOccupancy = 0;
316 // }
317 // }
318 }
319 
321 {
322  G4MolecularConfiguration* output = GetManager()->GetMolecularConfiguration(
323  fMoleculeDefinition, newElectronOccupancy);
324 
325  if (!output)
326  {
327  output = new G4MolecularConfiguration(fMoleculeDefinition,
328  newElectronOccupancy);
329  }
330  return output;
331 }
332 
334 {
335  G4MolecularConfiguration* output = GetManager()->GetMolecularConfiguration(
336  fMoleculeDefinition, charge);
337 
338  if (!output)
339  {
340  output = new G4MolecularConfiguration(fMoleculeDefinition, charge);
341  }
342  return output;
343 }
344 
346 {
347  if (&right == this) return *this;
348  return *this;
349 }
350 
354 {
355  CheckElectronOccupancy(__func__);
356  G4ElectronOccupancy newElectronOccupancy(*fElectronOccupancy);
357 
358  newElectronOccupancy.RemoveElectron(ExcitedLevel, 1);
359  newElectronOccupancy.AddElectron(5, 1);
360 
361  return ChangeConfiguration(newElectronOccupancy);
362 }
363 
367 {
368  CheckElectronOccupancy(__func__);
369  G4ElectronOccupancy newElectronOccupancy(*fElectronOccupancy);
370 
371  if (newElectronOccupancy.GetOccupancy(IonizedLevel) != 0)
372  {
373  newElectronOccupancy.RemoveElectron(IonizedLevel, 1);
374  }
375  else
376  {
377  G4String errMsg = "There is no electron on the orbit "
378  + G4UIcommand::ConvertToString(IonizedLevel)
379  + " you want to free. The molecule's name you want to ionized is "
380  + GetName();
381  G4Exception("G4Molecule::IonizeMolecule", "", FatalErrorInArgument, errMsg);
382  PrintState();
383  }
384 
385  // DEBUG
386  // PrintState();
387 
388  return ChangeConfiguration(newElectronOccupancy);
389 }
390 
392  G4int number)
393 {
394  CheckElectronOccupancy(__func__);
395  G4ElectronOccupancy newElectronOccupancy(*fElectronOccupancy);
396  newElectronOccupancy.AddElectron(orbit, number);
397  return ChangeConfiguration(newElectronOccupancy);
398 }
399 
401  G4int number)
402 {
403  CheckElectronOccupancy(__func__);
404  G4ElectronOccupancy newElectronOccupancy(*fElectronOccupancy);
405 
406  if (newElectronOccupancy.GetOccupancy(orbit) != 0)
407  {
408  newElectronOccupancy.RemoveElectron(orbit, number);
409  }
410  else
411  {
412  G4String errMsg = "There is already no electron into the orbit "
414  + " you want to free. The molecule's name is " + GetName();
415  G4Exception("G4Molecule::RemoveElectron", "", JustWarning, errMsg);
416  PrintState();
417  }
418 
419  return ChangeConfiguration(newElectronOccupancy);
420 }
421 
423  G4int orbitToFill)
424 {
425  CheckElectronOccupancy(__func__);
426  G4ElectronOccupancy newElectronOccupancy(*fElectronOccupancy);
427 
428  if (newElectronOccupancy.GetOccupancy(orbitToFree) >= 1)
429  {
430  newElectronOccupancy.RemoveElectron(orbitToFree, 1);
431  newElectronOccupancy.AddElectron(orbitToFill, 1);
432  }
433  else
434  {
435  G4String errMsg = "There is no electron on the orbit "
436  + G4UIcommand::ConvertToString(orbitToFree)
437  + " you want to free. The molecule's name is " + GetName();
438  G4Exception("G4Molecule::MoveOneElectron", "", FatalErrorInArgument,
439  errMsg);
440  PrintState();
441  }
442 
443  return ChangeConfiguration(newElectronOccupancy);
444 }
445 
447 {
448 // if (fName.isNull())
449 // {
450 // fName = fMoleculeDefinition->GetName();
451 // fName += "^";
452 // // fName+= "{";
453 // fName += G4UIcommand::ConvertToString(fDynCharge);
454 // // fName+= "}";
455 // }
456  return fName;
457 }
458 
460 {
461 // if (fFormatedName.isNull())
462 // {
463 // fFormatedName = fMoleculeDefinition->GetFormatedName();
464 // fFormatedName += "^";
465 // fFormatedName += "{";
466 // fFormatedName += G4UIcommand::ConvertToString(fDynCharge);
467 // fFormatedName += "}";
468 // }
469  return fFormatedName;
470 }
471 
473 {
474  return fMoleculeDefinition->GetAtomsNumber();
475 }
476 
478 {
479  CheckElectronOccupancy(__func__);
480  return fElectronOccupancy->GetTotalOccupancy();
481 }
482 
484 {
485  if (fElectronOccupancy)
486  {
487  G4cout << "--------------Print electronic state of " << GetName()
488  << "---------------" << G4endl;
489  fElectronOccupancy->DumpInfo();
490  if(fElectronOccupancy==fMoleculeDefinition->GetGroundStateElectronOccupancy())
491  {
492  G4cout<<"At ground state"<<G4endl;
493  }
494  else
495  {
496  if(fMoleculeDefinition->GetDecayTable())
497  G4cout<<"Transition :"<<(fMoleculeDefinition->GetDecayTable())->GetExcitedState(fElectronOccupancy)<<G4endl;
498  }
499  }
500  else
501  {
502  G4cout<<"--- No electron occupancy set up ---"<<G4endl;
503  }
504 }
505 
506 // added - to be transformed in a "Decay method"
507 const vector<const G4MolecularDissociationChannel*>* G4MolecularConfiguration::GetDecayChannel() const
508 {
509  if (fElectronOccupancy == 0) return 0;
510  return fMoleculeDefinition->GetDecayChannels(fElectronOccupancy);
511 }
512 
514 {
515  if (fMoleculeDefinition) return fMoleculeDefinition->GetPDGEncoding();
516  else G4Exception("G4Molecule::GetMoleculeID", "", FatalErrorInArgument,
517  "You should first enter a molecule defintion");
518 
519  return INT_MAX;
520 }
521 
522 const char* removePath(const char* path)
523 {
524  const char* pDelimeter = strrchr(path, '\\');
525  if (pDelimeter) path = pDelimeter + 1;
526 
527  pDelimeter = strrchr(path, '/');
528  if (pDelimeter) path = pDelimeter + 1;
529 
530  return path;
531 }
532 
533 void G4MolecularConfiguration::CheckElectronOccupancy(const char* function) const
534 {
535  if (fElectronOccupancy == 0)
536  {
537  G4String functionName(function);
538  G4ExceptionDescription description;
539  description
540  << "No G4ElectronOccupancy was defined for molecule definition : "
541  << fMoleculeDefinition->GetName()
542  << ". The definition was probably defined using the charge state, rather than electron state.";
543 
544  G4Exception(functionName, "", FatalErrorInArgument, description);
545  }
546 }
547 
550 {
551  MolecularConfigurationTable::iterator it1 = fTable.find(
552  configuration->GetDefinition());
553  MolecularConfigurationTable::iterator end = fTable.end();
554 
555  if (it1 == end) return;
556 
557  std::map<G4ElectronOccupancy, G4MolecularConfiguration*, comparator>::iterator it2 =
558  it1->second.find(*configuration->GetElectronOccupancy());
559 
560  if (it2 == it1->second.end()) return;
561 
562  it2->second = 0;
563 // it1->second.erase(it2);
564 
565  configuration->fElectronOccupancy = 0;
566 }
The pointer G4MolecularConfiguration will be shared by all the molecules having the same molecule def...
void PrintState() const
Display the electronic state of the molecule.
const G4String & GetName() const
Returns the name of the molecule.
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
G4String fName
Definition: G4AttUtils.hh:55
G4MolecularConfiguration * ChangeConfiguration(const G4ElectronOccupancy &newElectronOccupancy)
G4int SetMolecularConfiguration(const G4MoleculeDefinition *molDef, const G4ElectronOccupancy &eOcc, G4MolecularConfiguration *molConf)
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:371
G4double GetNbElectrons() const
Returns the number of electron.
const std::vector< const G4MolecularDissociationChannel * > * GetDecayChannel() const
const G4ElectronOccupancy * FindCommonElectronOccupancy(const G4MoleculeDefinition *molDef, const G4ElectronOccupancy &eOcc)
const G4ElectronOccupancy * GetElectronOccupancy() const
Returns the object ElectronOccupancy describing the electronic configuration of the molecule...
int G4int
Definition: G4Types.hh:78
static G4MolecularConfigurationManager * fgManager
G4GLOB_DLL std::ostream G4cout
G4int GetOccupancy(G4int orbit) const
G4MolecularConfiguration * IonizeMolecule(G4int)
Method used in Geant4-DNA to ionize water molecules.
G4MolecularConfiguration * AddElectron(G4int orbit, G4int n=1)
Add n electrons to a given orbit.
G4MolecularConfiguration::G4MolecularConfigurationManager MolecularConfigurationManager
G4int AddElectron(G4int orbit, G4int number=1)
void CheckElectronOccupancy(const char *line) const
G4MolecularConfiguration * MoveOneElectron(G4int, G4int)
Move one electron from an orbit to another.
G4MolecularConfiguration & operator=(G4MolecularConfiguration &right)
static G4MolecularConfiguration * GetMolecularConfiguration(const G4MoleculeDefinition *)
static G4MolecularConfigurationManager * GetManager()
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
#define INT_MAX
Definition: templates.hh:111
G4int G4Mutex
Definition: G4Threading.hh:169
const char * removePath(const char *path)
const G4String & GetFormatedName() const
Returns the formated name of the molecule.
G4int GetAtomsNumber() const
Returns the nomber of atoms compouning the molecule.
const G4MoleculeDefinition * GetDefinition() const
G4MolecularConfiguration(const G4MoleculeDefinition *, const G4ElectronOccupancy &)
#define G4endl
Definition: G4ios.hh:61
G4MolecularConfiguration * GetMolecularConfiguration(const G4MoleculeDefinition *molDef, const G4ElectronOccupancy &eOcc)
double G4double
Definition: G4Types.hh:76
const G4ElectronOccupancy * GetGroundStateElectronOccupancy() const
G4MolecularConfiguration * RemoveElectron(G4int, G4int number=1)
Remove n electrons to a given orbit.
const G4ElectronOccupancy * fElectronOccupancy
G4MolecularConfiguration * ExciteMolecule(G4int)
Method used in Geant4-DNA to excite water molecules.
G4int RemoveElectron(G4int orbit, G4int number=1)