Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4Molecule.cc
Go to the documentation of this file.
1 // ********************************************************************
2 // * License and Disclaimer *
3 // * *
4 // * The Geant4 software is copyright of the Copyright Holders of *
5 // * the Geant4 Collaboration. It is provided under the terms and *
6 // * conditions of the Geant4 Software License, included in the file *
7 // * LICENSE and available at http://cern.ch/geant4/license . These *
8 // * include a list of copyright holders. *
9 // * *
10 // * Neither the authors of this software system, nor their employing *
11 // * institutes,nor the agencies providing financial support for this *
12 // * work make any representation or warranty, express or implied, *
13 // * regarding this software system or assume any liability for its *
14 // * use. Please see the license in the file LICENSE and URL above *
15 // * for the full disclaimer and the limitation of liability. *
16 // * *
17 // * This code implementation is the result of the scientific and *
18 // * technical work of the GEANT4 collaboration. *
19 // * By using, copying, modifying or distributing the software (or *
20 // * any work based on the software) you agree to acknowledge its *
21 // * use in resulting scientific publications, and indicate your *
22 // * acceptance of all terms of the Geant4 Software license. *
23 // ********************************************************************
24 //
25 // $Id: G4Molecule.cc 102637 2017-02-10 11:08:17Z gcosmo $
26 //
27 // ---------------------------------------------------------------------
28 // GEANT 4 class header file
29 //
30 // History: first implementation, based on G4DynamicParticle
31 // New dependency : G4VUserTrackInformation
32 //
33 // ---------------- G4Molecule ----------------
34 // first design&implementation by Alfonso Mantero, 7 Apr 2009
35 // New developments Alfonso Mantero & Mathieu Karamitros
36 // Oct/Nov 2009 Class Name changed to G4Molecule
37 // Removed dependency from G4DynamicParticle
38 // New constructors :
39 // copy constructor
40 // direct ionized/excited molecule
41 // New methods :
42 // Get : name,atoms' number,nb electrons,decayChannel
43 // PrintState //To get the electronic level and the
44 // corresponding name of the excitation
45 // Kinematic :
46 // BuildTrack,GetKineticEnergy,GetDiffusionVelocity
47 // Change the way dynCharge and eNb is calculated
48 // ---------------------------------------------------------------------
49 
50 #include "G4Molecule.hh"
52 #include "Randomize.hh"
53 #include "G4PhysicalConstants.hh"
54 #include "G4SystemOfUnits.hh"
55 #include "G4Track.hh"
56 #include "G4VMoleculeCounter.hh"
57 
58 using namespace std;
59 
61 // 37°C, used to shoot an energy
62 
64 
66 
67 //______________________________________________________________________________
68 
69 template<>
71  fPoint->SetNode(nullptr);
72 }
73 
74 //______________________________________________________________________________
75 
77 {
78  return (G4Molecule*) (GetIT(track));
79 }
80 
81 //______________________________________________________________________________
82 
84 {
85  return (G4Molecule*) (GetIT(track));
86 }
87 
88 //______________________________________________________________________________
89 
91 {
92  return (G4Molecule*) (GetIT(track));
93 }
94 
95 //______________________________________________________________________________
96 
97 void G4Molecule::Print() const
98 {
99  G4cout << "The user track information is a molecule" << G4endl;
100 }
101 
102 //______________________________________________________________________________
103 
105  G4VUserTrackInformation("G4Molecule"), G4IT(right)
106 {
107  fpMolecularConfiguration = right.fpMolecularConfiguration;
108 }
109 
110 //______________________________________________________________________________
111 
113 {
114  if (&right == this) return *this;
115  fpMolecularConfiguration = right.fpMolecularConfiguration;
116  return *this;
117 }
118 
119 //______________________________________________________________________________
120 
122 {
123  if (fpMolecularConfiguration == right.fpMolecularConfiguration)
124  {
125  return true;
126  }
127  return false;
128 }
129 
130 //______________________________________________________________________________
131 
133 {
134  return !(*this == right);
135 }
136 
137 //______________________________________________________________________________
144 {
145  return fpMolecularConfiguration < right.fpMolecularConfiguration;
146 }
147 
148 //______________________________________________________________________________
151 G4Molecule::G4Molecule() :
152  G4VUserTrackInformation("G4Molecule"), G4IT()
153 
154 {
155  fpMolecularConfiguration = 0;
156 }
157 
158 //______________________________________________________________________________
159 
161 {
162  if (fpTrack != nullptr)
163  {
164  if (G4VMoleculeCounter::Instance()->InUse())
165  {
167  RemoveAMoleculeAtTime(fpMolecularConfiguration,
169  &(fpTrack->GetPosition()));
170  }
171  fpTrack = nullptr;
172  }
173  fpMolecularConfiguration = nullptr;
174 }
175 
176 //______________________________________________________________________________
180 G4Molecule::G4Molecule(G4MoleculeDefinition * moleculeDefinition) :
182  G4VUserTrackInformation("G4Molecule"), G4IT()
184 {
185  fpMolecularConfiguration =
187  GetOrCreateMolecularConfiguration(moleculeDefinition);
188 }
189 
190 //______________________________________________________________________________
191 
192 G4Molecule::G4Molecule(G4MoleculeDefinition* moleculeDefinition, int charge)
193 {
194  fpMolecularConfiguration =
196  GetOrCreateMolecularConfiguration(moleculeDefinition,
197  charge);
198 }
199 
200 //______________________________________________________________________________
205 G4Molecule::G4Molecule(G4MoleculeDefinition * moleculeDefinition,
207  G4int OrbitalToFree,
208  G4int OrbitalToFill) :
209  G4VUserTrackInformation("G4Molecule"), G4IT()
211 {
212  if (moleculeDefinition->GetGroundStateElectronOccupancy())
213  {
214  G4ElectronOccupancy dynElectronOccupancy(
215  *moleculeDefinition->GetGroundStateElectronOccupancy());
216 
217  if (OrbitalToFill != 0)
218  {
219  dynElectronOccupancy.RemoveElectron(OrbitalToFree - 1, 1);
220  dynElectronOccupancy.AddElectron(OrbitalToFill - 1, 1);
221  // dynElectronOccupancy.DumpInfo(); // DEBUG
222  }
223 
224  if (OrbitalToFill == 0)
225  {
226  dynElectronOccupancy.RemoveElectron(OrbitalToFree - 1, 1);
227  // dynElectronOccupancy.DumpInfo(); // DEBUG
228  }
229 
230  fpMolecularConfiguration =
232  moleculeDefinition, dynElectronOccupancy);
233  }
234  else
235  {
236  fpMolecularConfiguration = 0;
237  G4Exception(
238  "G4Molecule::G4Molecule(G4MoleculeDefinition * moleculeDefinition, "
239  "G4int OrbitalToFree, G4int OrbitalToFill)",
240  "G4Molecule_wrong_usage_of_constructor",
242  "If you want to use this constructor, the molecule definition has to be "
243  "first defined with electron occupancies");
244  }
245 }
246 
247 //______________________________________________________________________________
254  G4int Level,
255  G4bool Excitation) :
256  G4VUserTrackInformation("G4Molecule"), G4IT()
257 {
258  if (moleculeDefinition->GetGroundStateElectronOccupancy())
259  {
260  G4ElectronOccupancy dynElectronOccupancy(
261  *moleculeDefinition->GetGroundStateElectronOccupancy());
262 
263  if (Excitation == true)
264  {
265  dynElectronOccupancy.RemoveElectron(Level, 1);
266  dynElectronOccupancy.AddElectron(5, 1);
267  // dynElectronOccupancy.DumpInfo(); // DEBUG
268  }
269 
270  if (Excitation == false)
271  {
272  dynElectronOccupancy.RemoveElectron(Level, 1);
273  // dynElectronOccupancy.DumpInfo(); // DEBUG
274  }
275 
276  fpMolecularConfiguration =
278  moleculeDefinition, dynElectronOccupancy);
279  }
280  else
281  {
282  fpMolecularConfiguration = 0;
283  G4Exception(
284  "G4Molecule::G4Molecule(G4MoleculeDefinition * moleculeDefinition, "
285  "G4int OrbitalToFree, G4int OrbitalToFill)",
286  "G4Molecule_wrong_usage_of_constructor",
288  "If you want to use this constructor, the molecule definition has to be "
289  "first defined with electron occupancies");
290 
291  }
292 }
293 
294 //______________________________________________________________________________
295 
297 {
298  fpMolecularConfiguration = molConf;
299 }
300 
301 //______________________________________________________________________________
302 
304 {
305  fpMolecularConfiguration =
307  fpMolecularConfiguration->GetDefinition(), *occ);
308 }
309 
310 //______________________________________________________________________________
311 
315 {
316  fpMolecularConfiguration = fpMolecularConfiguration->ExciteMolecule(
317  ExcitedLevel);
318 }
319 
320 //______________________________________________________________________________
321 
325 {
326  fpMolecularConfiguration = fpMolecularConfiguration->IonizeMolecule(
327  IonizedLevel);
328 }
329 
330 //______________________________________________________________________________
331 
333 {
334  fpMolecularConfiguration = fpMolecularConfiguration->AddElectron(orbit,
335  number);
336 }
337 
338 //______________________________________________________________________________
339 
341 {
342  fpMolecularConfiguration = fpMolecularConfiguration->RemoveElectron(orbit,
343  number);
344 }
345 
346 //______________________________________________________________________________
347 
348 void G4Molecule::MoveOneElectron(G4int orbitToFree, G4int orbitToFill)
349 {
350  fpMolecularConfiguration = fpMolecularConfiguration->MoveOneElectron(
351  orbitToFree, orbitToFill);
352 }
353 
354 //______________________________________________________________________________
355 
357 {
358  return fpMolecularConfiguration->GetName();
359 }
360 
361 //______________________________________________________________________________
362 
364 {
365  return fpMolecularConfiguration->GetFormatedName();
366 }
367 
368 //______________________________________________________________________________
369 
371 {
372  return fpMolecularConfiguration->GetAtomsNumber();
373 }
374 
375 //______________________________________________________________________________
376 
378 {
379  return fpMolecularConfiguration->GetNbElectrons();
380 }
381 
382 //______________________________________________________________________________
383 
385 {
386  fpMolecularConfiguration->PrintState();
387 }
388 
389 //______________________________________________________________________________
390 
392  const G4ThreeVector& position)
393 {
394  if (fpTrack != 0){
395  G4Exception("G4Molecule::BuildTrack", "Molecule001", FatalErrorInArgument,
396  "A track was already assigned to this molecule");
397  }
398 
399  // Kinetic Values
400  // Set a random direction to the molecule
401  G4double costheta = (2 * G4UniformRand()-1);
402  G4double theta = acos(costheta);
403  G4double phi = 2 * pi * G4UniformRand();
404 
405  G4double xMomentum = cos(phi) * sin(theta);
406  G4double yMomentum = sin(theta) * sin(phi);
407  G4double zMomentum = costheta;
408 
409  G4ThreeVector MomentumDirection(xMomentum, yMomentum, zMomentum);
410  G4double KineticEnergy = GetKineticEnergy();
411 
412  G4DynamicParticle* dynamicParticle = new G4DynamicParticle(
413  fpMolecularConfiguration->GetDefinition(), MomentumDirection,
414  KineticEnergy);
415 
418  AddAMoleculeAtTime(fpMolecularConfiguration,
419  globalTime,
420  &(fpTrack->GetPosition()));
421  }
422 
423  //Set the Track
424  fpTrack = new G4Track(dynamicParticle, globalTime, position);
426 
427  return fpTrack;
428 }
429 
430 //______________________________________________________________________________
431 
433 {
435  // Ideal Gaz case
436  double v = GetDiffusionVelocity();
437  double E = (fpMolecularConfiguration->GetMass() / (c_squared)) * (v * v) / 2.;
439  return E;
440 }
441 
442 //______________________________________________________________________________
443 
445 {
446  double moleculeMass = fpMolecularConfiguration->GetMass() / (c_squared);
447 
449  // Different possibilities
451  // Ideal Gaz case : Maxwell Boltzmann Distribution
452  // double sigma = k_Boltzmann * fgTemperature / mass;
453  // return G4RandGauss::shoot( 0, sigma );
455  // Ideal Gaz case : mean velocity from equipartition theorem
456  return sqrt(3 * k_Boltzmann *
459  // Using this approximation for liquid is wrong
460  // However the brownian process avoid taking
461  // care of energy consideration and plays only
462  // with positions
463 }
464 
465 //______________________________________________________________________________
466 
467 // added - to be transformed in a "Decay method"
468 const vector<const G4MolecularDissociationChannel*>*
470 {
471  return fpMolecularConfiguration->GetDecayChannel();
472 }
473 
474 //______________________________________________________________________________
475 
477 {
478  return fpMolecularConfiguration->GetFakeParticleID();
479 }
480 
481 //______________________________________________________________________________
482 
484 {
485  return fpMolecularConfiguration->GetMoleculeID();
486 }
487 
488 //______________________________________________________________________________
489 
491 {
492  fpMolecularConfiguration->SetDecayTime(dynDecayTime);
493 }
494 
495 //______________________________________________________________________________
496 
498 {
499  return fpMolecularConfiguration->GetDecayTime();
500 }
501 
502 //______________________________________________________________________________
503 
504 void G4Molecule::SetVanDerVaalsRadius(G4double dynVanDerVaalsRadius)
505 {
506  fpMolecularConfiguration->SetVanDerVaalsRadius(dynVanDerVaalsRadius);
507 }
508 
509 //______________________________________________________________________________
510 
512 {
513  return fpMolecularConfiguration->GetVanDerVaalsRadius();
514 }
515 
516 //______________________________________________________________________________
517 
519 {
520  return fpMolecularConfiguration->GetCharge();
521 }
522 
523 //______________________________________________________________________________
524 
526 {
527  fpMolecularConfiguration->SetMass(aMass);
528 }
529 
530 //______________________________________________________________________________
531 
533 {
534  return fpMolecularConfiguration->GetMass();
535 }
536 
537 //______________________________________________________________________________
538 
540 {
541  return fpMolecularConfiguration->GetElectronOccupancy();
542 }
543 
544 //______________________________________________________________________________
545 
547 {
548  return fpMolecularConfiguration->GetDefinition();
549 }
550 
551 //______________________________________________________________________________
552 
553 void G4Molecule::SetDiffusionCoefficient(G4double dynDiffusionCoefficient)
554 {
555  fpMolecularConfiguration->SetDiffusionCoefficient(dynDiffusionCoefficient);
556 }
557 
558 //______________________________________________________________________________
559 
561 {
562  return fpMolecularConfiguration->GetDiffusionCoefficient();
563 }
564 
565 //______________________________________________________________________________
566 
568  double temperature) const
569 {
570  return fpMolecularConfiguration->GetDiffusionCoefficient(mat,
571  temperature);
572 }
573 
574 //______________________________________________________________________________
575 
577 {
578  return fpMolecularConfiguration;
579 }
580 
581 //______________________________________________________________________________
582 
583 //void G4Molecule::SetGlobalTemperature(G4double temperature)
584 //{
585 // fgTemperature = temperature;
586 //}
587 //
589 //
590 //G4double G4Molecule::GetGlobalTemperature()
591 //{
592 // return fgTemperature;
593 //}
594 
595 //______________________________________________________________________________
596 
598 {
599  return fpMolecularConfiguration->GetLabel();
600 }
601 
602 //______________________________________________________________________________
603 
604 void G4Molecule::SetLabel(const G4String& label)
605 {
606  fpMolecularConfiguration->SetLabel(label);
607 }
608 
609 //______________________________________________________________________________
610 
612 {
613  // TODO check fpMolecularConfiguration already exists
614  // and new one as well
615  // TODO notify for stack change
616  fpMolecularConfiguration =
618  fpMolecularConfiguration->GetDefinition(), label);
619 
620  assert(fpMolecularConfiguration!=0);
621 }
static constexpr double k_Boltzmann
Definition: G4IT.hh:88
const G4String & GetName() const
void SetDiffusionCoefficient(G4double)
Definition: G4Molecule.cc:553
const std::vector< const G4MolecularDissociationChannel * > * GetDecayChannel() const
Definition: G4Molecule.cc:469
G4bool operator!=(const G4Molecule &right) const
Definition: G4Molecule.cc:132
G4bool operator<(const G4Molecule &right) const
Definition: G4Molecule.cc:143
static G4Molecule * GetMolecule(const G4Track *)
Definition: G4Molecule.cc:90
G4double GetMass() const
Definition: G4Molecule.cc:532
void SetMass(G4double)
Definition: G4Molecule.cc:525
const G4ThreeVector & GetPosition() const
void SetLabel(const G4String &label)
Definition: G4Molecule.cc:604
static G4MolecularConfiguration * GetMolecularConfiguration(const G4MoleculeDefinition *, const G4String &label)
G4double GetDiffusionCoefficient() const
Definition: G4Molecule.cc:560
G4double GetNbElectrons() const
Definition: G4Molecule.cc:377
const std::vector< const G4MolecularDissociationChannel * > * GetDecayChannel() const
G4MolecularConfiguration * GetMolecularConfiguration() const
Definition: G4Molecule.cc:576
const G4ElectronOccupancy * GetElectronOccupancy() const
#define G4ThreadLocal
Definition: tls.hh:89
virtual ~G4Molecule()
Definition: G4Molecule.cc:160
int G4int
Definition: G4Types.hh:78
void ChangeConfigurationToLabel(const G4String &label)
Definition: G4Molecule.cc:611
G4Molecule(const G4Molecule &)
Definition: G4Molecule.cc:104
const G4String & GetName() const
Definition: G4Molecule.cc:356
G4IT * GetIT(const G4Track *track)
Definition: G4IT.cc:49
void MoveOneElectron(G4int, G4int)
Definition: G4Molecule.cc:348
const G4String & GetLabel() const
Definition: G4Molecule.cc:597
#define G4UniformRand()
Definition: Randomize.hh:97
G4GLOB_DLL std::ostream G4cout
G4MolecularConfiguration * IonizeMolecule(G4int)
void SetElectronOccupancy(const G4ElectronOccupancy *)
Definition: G4Molecule.cc:303
G4int GetAtomsNumber() const
Definition: G4Molecule.cc:370
G4MolecularConfiguration * AddElectron(G4int orbit, G4int n=1)
G4int GetFakeParticleID() const
Definition: G4Molecule.cc:476
bool G4bool
Definition: G4Types.hh:79
G4Track * fpTrack
Definition: G4IT.hh:168
void SetVanDerVaalsRadius(G4double)
Definition: G4Molecule.cc:504
G4MolecularConfiguration * MoveOneElectron(G4int, G4int)
G4Molecule & operator=(const G4Molecule &right)
Definition: G4Molecule.cc:112
G4double GetGlobalTime() const
G4Molecule * GetMolecule(const G4Track &track)
Definition: G4Molecule.cc:76
static G4VMoleculeCounter * Instance()
void IonizeMolecule(G4int)
Definition: G4Molecule.cc:324
static G4MolecularConfiguration * GetOrCreateMolecularConfiguration(const G4MoleculeDefinition *)
const G4MoleculeDefinition * GetDefinition() const
Definition: G4Molecule.cc:546
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static constexpr double c_squared
void SetUserInformation(G4VUserTrackInformation *aValue) const
G4Track * BuildTrack(G4double globalTime, const G4ThreeVector &Position)
Definition: G4Molecule.cc:391
const G4String & GetFormatedName() const
Definition: G4Molecule.cc:363
G4int GetCharge() const
Definition: G4Molecule.cc:518
const G4String & GetFormatedName() const
G4double GetKineticEnergy() const
Definition: G4Molecule.cc:432
void RemoveElectron(G4int, G4int number=1)
Definition: G4Molecule.cc:340
G4DLLIMPORT G4ThreadLocal G4Allocator< G4Molecule > * aMoleculeAllocator
G4ThreadLocal/G4double G4Molecule::fgTemperature = 310; // 310*kelvin;
Definition: G4Molecule.cc:65
void PrintState() const
Definition: G4Molecule.cc:384
const G4MoleculeDefinition * GetDefinition() const
const G4String & GetLabel() const
#define G4endl
Definition: G4ios.hh:61
static constexpr double pi
Definition: G4SIunits.hh:75
G4double GetDiffusionVelocity() const
Definition: G4Molecule.cc:444
void Print() const
Definition: G4Molecule.cc:97
double G4double
Definition: G4Types.hh:76
const G4ElectronOccupancy * GetGroundStateElectronOccupancy() const
const G4ElectronOccupancy * GetElectronOccupancy() const
Definition: G4Molecule.cc:539
static G4bool InUse()
G4MolecularConfiguration * RemoveElectron(G4int, G4int number=1)
G4double GetVanDerVaalsRadius() const
Definition: G4Molecule.cc:511
G4double GetDecayTime() const
Definition: G4Molecule.cc:497
G4MolecularConfiguration * ExciteMolecule(G4int)
void AddElectron(G4int orbit, G4int n=1)
Definition: G4Molecule.cc:332
#define ITImp(T)
Definition: G4ITType.hh:136
G4bool operator==(const G4Molecule &right) const
Definition: G4Molecule.cc:121
void SetDecayTime(G4double)
Definition: G4Molecule.cc:490
G4int RemoveElectron(G4int orbit, G4int number=1)
void ExciteMolecule(G4int)
Definition: G4Molecule.cc:314
G4int GetMoleculeID() const
Definition: G4Molecule.cc:483