Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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//
26// ---------------------------------------------------------------------
27// GEANT 4 class header file
28//
29// History: first implementation, based on G4DynamicParticle
30// New dependency : G4VUserTrackInformation
31//
32// ---------------- G4Molecule ----------------
33// first design&implementation by Alfonso Mantero, 7 Apr 2009
34// New developments Alfonso Mantero & Mathieu Karamitros
35// Oct/Nov 2009 Class Name changed to G4Molecule
36// Removed dependency from G4DynamicParticle
37// New constructors :
38// copy constructor
39// direct ionized/excited molecule
40// New methods :
41// Get : name,atoms' number,nb electrons,decayChannel
42// PrintState //To get the electronic level and the
43// corresponding name of the excitation
44// Kinematic :
45// BuildTrack,GetKineticEnergy,GetDiffusionVelocity
46// Change the way dynCharge and eNb is calculated
47// ---------------------------------------------------------------------
48
49#include "G4Molecule.hh"
51#include "Randomize.hh"
53#include "G4SystemOfUnits.hh"
54#include "G4Track.hh"
55#include "G4VMoleculeCounter.hh"
56
57using namespace std;
58
60
62{
64 return _instance;
65}
66
67//______________________________________________________________________________
68
69template<>
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
97void G4Molecule::Print() const
98{
99 G4cout << "The user track information is a molecule" << G4endl;
100}
101
102//______________________________________________________________________________
103
105 : G4VUserTrackInformation("G4Molecule")
106 , G4IT(right)
107{
108 fpMolecularConfiguration = right.fpMolecularConfiguration;
109}
110
111//______________________________________________________________________________
112
114{
115 if (&right == this) return *this;
116 fpMolecularConfiguration = right.fpMolecularConfiguration;
117 return *this;
118}
119
120//______________________________________________________________________________
121
123{
124 if (fpMolecularConfiguration == right.fpMolecularConfiguration)
125 {
126 return true;
127 }
128 return false;
129}
130
131//______________________________________________________________________________
132
134{
135 return !(*this == right);
136}
137
138//______________________________________________________________________________
139/** The two methods below are the most called of the simulation :
140 * compare molecules in the MoleculeStackManager or in
141 * the InteractionTable
142 */
143
145{
146 return fpMolecularConfiguration < right.fpMolecularConfiguration;
147}
148
149//______________________________________________________________________________
150
151G4Molecule::G4Molecule()
152 : G4VUserTrackInformation("G4Molecule")
153 , G4IT()
154{
155 fpMolecularConfiguration = nullptr;
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//______________________________________________________________________________
177/** Build a molecule at ground state according to a given
178 * G4MoleculeDefinition that can be obtained from G4GenericMoleculeManager
179 */
181 : G4VUserTrackInformation("G4Molecule")
182 , G4IT()
183{
184 fpMolecularConfiguration = G4MolecularConfiguration::GetOrCreateMolecularConfiguration(pMoleculeDefinition);
185}
186
187//______________________________________________________________________________
188
189G4Molecule::G4Molecule(G4MoleculeDefinition* pMoleculeDefinition, int charge)
190{
191 fpMolecularConfiguration = G4MolecularConfiguration::GetOrCreateMolecularConfiguration(pMoleculeDefinition,
192 charge);
193}
194
195//______________________________________________________________________________
196/** Build a molecule at a specific excitation/ionisation state according
197 * to a ground state that can be obtained from G4GenericMoleculeManager.
198 * Put 0 in the second option if this is a ionisation.
199 */
201 G4int OrbitalToFree,
202 G4int OrbitalToFill)
203 : G4VUserTrackInformation("G4Molecule")
204 , G4IT()
205{
206 if (pMoleculeDefinition->GetGroundStateElectronOccupancy())
207 {
208 G4ElectronOccupancy dynElectronOccupancy(*pMoleculeDefinition->GetGroundStateElectronOccupancy());
209
210 if (OrbitalToFill != 0)
211 {
212 dynElectronOccupancy.RemoveElectron(OrbitalToFree - 1, 1);
213 dynElectronOccupancy.AddElectron(OrbitalToFill - 1, 1);
214 // dynElectronOccupancy.DumpInfo(); // DEBUG
215 }
216
217 if (OrbitalToFill == 0)
218 {
219 dynElectronOccupancy.RemoveElectron(OrbitalToFree - 1, 1);
220 // dynElectronOccupancy.DumpInfo(); // DEBUG
221 }
222
223 fpMolecularConfiguration =
225 pMoleculeDefinition, dynElectronOccupancy);
226 }
227 else
228 {
229 fpMolecularConfiguration = nullptr;
231 "G4Molecule::G4Molecule(G4MoleculeDefinition* pMoleculeDefinition, "
232 "G4int OrbitalToFree, G4int OrbitalToFill)",
233 "G4Molecule_wrong_usage_of_constructor",
235 "If you want to use this constructor, the molecule definition has to be "
236 "first defined with electron occupancies");
237 }
238}
239
240//______________________________________________________________________________
241/** Specific builder for water molecules to be used in Geant4-DNA,
242 * the last option Excitation is true if the molecule is excited, is
243 * false is the molecule is ionized.
244 */
246 G4int level,
247 G4bool excitation)
248 : G4VUserTrackInformation("G4Molecule")
249 , G4IT()
250{
251 if (pMoleculeDefinition->GetGroundStateElectronOccupancy())
252 {
253 G4ElectronOccupancy dynElectronOccupancy(*pMoleculeDefinition->GetGroundStateElectronOccupancy());
254
255 if (excitation)
256 {
257 dynElectronOccupancy.RemoveElectron(level, 1);
258 dynElectronOccupancy.AddElectron(5, 1);
259 // dynElectronOccupancy.DumpInfo(); // DEBUG
260 }
261 else
262 {
263 dynElectronOccupancy.RemoveElectron(level, 1);
264 // dynElectronOccupancy.DumpInfo(); // DEBUG
265 }
266
267 fpMolecularConfiguration = G4MolecularConfiguration::GetOrCreateMolecularConfiguration(pMoleculeDefinition,
268 dynElectronOccupancy);
269 }
270 else
271 {
272 fpMolecularConfiguration = nullptr;
274 "G4Molecule::G4Molecule(G4MoleculeDefinition* pMoleculeDefinition, "
275 "G4int OrbitalToFree, G4int OrbitalToFill)",
276 "G4Molecule_wrong_usage_of_constructor",
278 "If you want to use this constructor, the molecule definition has to be "
279 "first defined with electron occupancies");
280 }
281}
282
283//______________________________________________________________________________
284
286{
287 fpMolecularConfiguration = pMolecularConfiguration;
288}
289
290//______________________________________________________________________________
291
293{
294 fpMolecularConfiguration =
296 *pElectronOcc);
297}
298
299//______________________________________________________________________________
300
302{
303 fpMolecularConfiguration = fpMolecularConfiguration->ExciteMolecule(excitationLevel);
304}
305
306//______________________________________________________________________________
307
309{
310 fpMolecularConfiguration = fpMolecularConfiguration->IonizeMolecule(ionizationLevel);
311}
312
313//______________________________________________________________________________
314
316{
317 fpMolecularConfiguration = fpMolecularConfiguration->AddElectron(orbit, number);
318}
319
320//______________________________________________________________________________
321
323{
324 fpMolecularConfiguration =
325 fpMolecularConfiguration->RemoveElectron(orbit, number);
326}
327
328//______________________________________________________________________________
329
330void G4Molecule::MoveOneElectron(G4int orbitToFree, G4int orbitToFill)
331{
332 fpMolecularConfiguration =
333 fpMolecularConfiguration->MoveOneElectron(orbitToFree, orbitToFill);
334}
335
336//______________________________________________________________________________
337
339{
340 return fpMolecularConfiguration->GetName();
341}
342
343//______________________________________________________________________________
344
346{
347 return fpMolecularConfiguration->GetFormatedName();
348}
349
350//______________________________________________________________________________
351
353{
354 return fpMolecularConfiguration->GetAtomsNumber();
355}
356
357//______________________________________________________________________________
358
360{
361 return fpMolecularConfiguration->GetNbElectrons();
362}
363
364//______________________________________________________________________________
365
367{
368 fpMolecularConfiguration->PrintState();
369}
370
371//______________________________________________________________________________
372
374 const G4ThreeVector& position)
375{
376 if (fpTrack != nullptr)
377 {
378 G4Exception("G4Molecule::BuildTrack", "Molecule001", FatalErrorInArgument,
379 "A track was already assigned to this molecule");
380 }
381
382 // Kinetic Values
383 // Set a random direction to the molecule
384 G4double costheta = (2 * G4UniformRand() - 1);
385 G4double theta = acos(costheta);
386 G4double phi = 2 * pi * G4UniformRand();
387
388 G4double xMomentum = cos(phi) * sin(theta);
389 G4double yMomentum = sin(theta) * sin(phi);
390 G4double zMomentum = costheta;
391
392 G4ThreeVector MomentumDirection(xMomentum, yMomentum, zMomentum);
393 G4double KineticEnergy = GetKineticEnergy();
394
395 G4DynamicParticle* dynamicParticle = new G4DynamicParticle(
396 fpMolecularConfiguration->GetDefinition(), MomentumDirection,
397 KineticEnergy);
398
400 {
402 AddAMoleculeAtTime(fpMolecularConfiguration,
403 globalTime,
404 &(fpTrack->GetPosition()));
405 }
406
407 //Set the Track
408 fpTrack = new G4Track(dynamicParticle, globalTime, position);
410
411 return fpTrack;
412}
413
414//______________________________________________________________________________
415
417{
418 ////
419 // Ideal Gaz case
420 double v = GetDiffusionVelocity();
421 double E = (fpMolecularConfiguration->GetMass() / (c_squared)) * (v * v) / 2.;
422 ////
423 return E;
424}
425
426//______________________________________________________________________________
427
429{
430 double moleculeMass = fpMolecularConfiguration->GetMass() / (c_squared);
431
432 ////
433 // Different possibilities
434 ////
435 // Ideal Gaz case : Maxwell Boltzmann Distribution
436 // double sigma = k_Boltzmann * fgTemperature / mass;
437 // return G4RandGauss::shoot( 0, sigma );
438 ////
439 // Ideal Gaz case : mean velocity from equipartition theorem
440 return sqrt(3 * k_Boltzmann *
442 ////
443 // Using this approximation for liquid is wrong
444 // However the brownian process avoid taking
445 // care of energy consideration and plays only
446 // with positions
447}
448
449//______________________________________________________________________________
450
451// added - to be transformed in a "Decay method"
452const vector<const G4MolecularDissociationChannel*>*
454{
455 return fpMolecularConfiguration->GetDissociationChannels();
456}
457
458//______________________________________________________________________________
459
461{
462 return fpMolecularConfiguration->GetFakeParticleID();
463}
464
465//______________________________________________________________________________
466
468{
469 return fpMolecularConfiguration->GetMoleculeID();
470}
471
472//______________________________________________________________________________
473
475{
476 return fpMolecularConfiguration->GetDecayTime();
477}
478
479//______________________________________________________________________________
480
482{
483 return fpMolecularConfiguration->GetVanDerVaalsRadius();
484}
485
486//______________________________________________________________________________
487
489{
490 return fpMolecularConfiguration->GetCharge();
491}
492
493//______________________________________________________________________________
494
496{
497 return fpMolecularConfiguration->GetMass();
498}
499
500//______________________________________________________________________________
501
503{
504 return fpMolecularConfiguration->GetElectronOccupancy();
505}
506
507//______________________________________________________________________________
508
510{
511 return fpMolecularConfiguration->GetDefinition();
512}
513
514//______________________________________________________________________________
515
517{
518 return fpMolecularConfiguration->GetDiffusionCoefficient();
519}
520
521//______________________________________________________________________________
522
524 double temperature) const
525{
526 return fpMolecularConfiguration->GetDiffusionCoefficient(pMaterial,
527 temperature);
528}
529
530//______________________________________________________________________________
531
533{
534 return fpMolecularConfiguration;
535}
536
537//______________________________________________________________________________
538
540{
541 return fpMolecularConfiguration->GetLabel();
542}
543
544//______________________________________________________________________________
545
547{
548 // TODO check fpMolecularConfiguration already exists
549 // and new one as well
550 // TODO notify for stack change
552 fpMolecularConfiguration->GetDefinition(), label);
553
554 assert(fpMolecularConfiguration != nullptr);
555}
@ FatalErrorInArgument
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
#define ITImp(T)
Definition: G4ITType.hh:135
G4IT * GetIT(const G4Track *track)
Definition: G4IT.cc:48
G4Molecule * GetMolecule(const G4Track &track)
Definition: G4Molecule.cc:76
G4DLLIMPORT G4Allocator< G4Molecule > *& aMoleculeAllocator()
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
#define G4UniformRand()
Definition: Randomize.hh:52
G4int AddElectron(G4int orbit, G4int number=1)
G4int RemoveElectron(G4int orbit, G4int number=1)
Definition: G4IT.hh:88
virtual void Print() const
Definition: G4IT.hh:97
G4Track * fpTrack
Definition: G4IT.hh:167
virtual ~G4KDNode()
const G4String & GetName() const
G4MolecularConfiguration * IonizeMolecule(G4int) const
const G4String & GetLabel() const
G4MolecularConfiguration * RemoveElectron(G4int, G4int number=1) const
const G4MoleculeDefinition * GetDefinition() const
G4MolecularConfiguration * MoveOneElectron(G4int, G4int) const
static G4MolecularConfiguration * GetOrCreateMolecularConfiguration(const G4MoleculeDefinition *)
const G4ElectronOccupancy * GetElectronOccupancy() const
const std::vector< const G4MolecularDissociationChannel * > * GetDissociationChannels() const
const G4String & GetFormatedName() const
static G4MolecularConfiguration * GetMolecularConfiguration(const G4MoleculeDefinition *, const G4String &label)
G4MolecularConfiguration * ExciteMolecule(G4int) const
G4MolecularConfiguration * AddElectron(G4int orbit, G4int n=1) const
const G4ElectronOccupancy * GetGroundStateElectronOccupancy() const
void IonizeMolecule(G4int)
Definition: G4Molecule.cc:308
G4int GetCharge() const
Definition: G4Molecule.cc:488
void RemoveElectron(G4int, G4int number=1)
Definition: G4Molecule.cc:322
void AddElectron(G4int orbit, G4int n=1)
Definition: G4Molecule.cc:315
virtual ~G4Molecule()
Definition: G4Molecule.cc:160
static G4Molecule * GetMolecule(const G4Track *)
Definition: G4Molecule.cc:90
G4bool operator<(const G4Molecule &right) const
Definition: G4Molecule.cc:144
G4double GetVanDerVaalsRadius() const
Definition: G4Molecule.cc:481
const G4MolecularConfiguration * GetMolecularConfiguration() const
Definition: G4Molecule.cc:532
void SetElectronOccupancy(const G4ElectronOccupancy *)
Definition: G4Molecule.cc:292
void MoveOneElectron(G4int, G4int)
Definition: G4Molecule.cc:330
G4double GetMass() const
Definition: G4Molecule.cc:495
const G4String & GetLabel() const
Definition: G4Molecule.cc:539
void ChangeConfigurationToLabel(const G4String &label)
Definition: G4Molecule.cc:546
G4int GetMoleculeID() const
Definition: G4Molecule.cc:467
G4double GetKineticEnergy() const
Definition: G4Molecule.cc:416
G4Molecule(const G4Molecule &)
Definition: G4Molecule.cc:104
const G4String & GetFormatedName() const
Definition: G4Molecule.cc:345
G4int GetAtomsNumber() const
Definition: G4Molecule.cc:352
G4bool operator==(const G4Molecule &right) const
Definition: G4Molecule.cc:122
G4int GetFakeParticleID() const
Definition: G4Molecule.cc:460
G4double GetDiffusionVelocity() const
Definition: G4Molecule.cc:428
void PrintState() const
Definition: G4Molecule.cc:366
const G4String & GetName() const
Definition: G4Molecule.cc:338
G4Track * BuildTrack(G4double globalTime, const G4ThreeVector &Position)
Definition: G4Molecule.cc:373
void ExciteMolecule(G4int)
Definition: G4Molecule.cc:301
G4bool operator!=(const G4Molecule &right) const
Definition: G4Molecule.cc:133
const G4ElectronOccupancy * GetElectronOccupancy() const
Definition: G4Molecule.cc:502
G4Molecule & operator=(const G4Molecule &right)
Definition: G4Molecule.cc:113
const G4MoleculeDefinition * GetDefinition() const
Definition: G4Molecule.cc:509
G4double GetDiffusionCoefficient() const
Definition: G4Molecule.cc:516
G4double GetDecayTime() const
Definition: G4Molecule.cc:474
const std::vector< const G4MolecularDissociationChannel * > * GetDissociationChannels() const
Definition: G4Molecule.cc:453
G4double GetNbElectrons() const
Definition: G4Molecule.cc:359
const G4ThreeVector & GetPosition() const
G4double GetGlobalTime() const
void SetUserInformation(G4VUserTrackInformation *aValue) const
static G4VMoleculeCounter * Instance()
#define G4ThreadLocalStatic
Definition: tls.hh:76