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