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