ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4Molecule.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4Molecule.cc
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"
52 #include "G4PhysicalConstants.hh"
53 #include "G4SystemOfUnits.hh"
54 #include "G4Track.hh"
55 #include "G4VMoleculeCounter.hh"
56 
57 using namespace std;
58 
60 
62 {
63  G4ThreadLocalStatic G4Allocator<G4Molecule>* _instance = nullptr;
64  return _instance;
65 }
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")
106  , G4IT(right)
107 {
109 }
110 
111 //______________________________________________________________________________
112 
114 {
115  if (&right == this) return *this;
117  return *this;
118 }
119 
120 //______________________________________________________________________________
121 
123 {
125  {
126  return true;
127  }
128  return false;
129 }
130 
131 //______________________________________________________________________________
132 
134 {
135  return !(*this == right);
136 }
137 
138 //______________________________________________________________________________
145 {
147 }
148 
149 //______________________________________________________________________________
150 
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 //______________________________________________________________________________
181  : G4VUserTrackInformation("G4Molecule")
182  , G4IT()
183 {
185 }
186 
187 //______________________________________________________________________________
188 
190 {
192  charge);
193 }
194 
195 //______________________________________________________________________________
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 
225  pMoleculeDefinition, dynElectronOccupancy);
226  }
227  else
228  {
229  fpMolecularConfiguration = nullptr;
230  G4Exception(
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 //______________________________________________________________________________
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 
268  dynElectronOccupancy);
269  }
270  else
271  {
272  fpMolecularConfiguration = nullptr;
273  G4Exception(
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 
285 G4Molecule::G4Molecule(const G4MolecularConfiguration* pMolecularConfiguration)
286 {
287  fpMolecularConfiguration = pMolecularConfiguration;
288 }
289 
290 //______________________________________________________________________________
291 
293 {
296  *pElectronOcc);
297 }
298 
299 //______________________________________________________________________________
300 
301 void G4Molecule::ExciteMolecule(G4int excitationLevel)
302 {
304 }
305 
306 //______________________________________________________________________________
307 
308 void G4Molecule::IonizeMolecule(G4int ionizationLevel)
309 {
311 }
312 
313 //______________________________________________________________________________
314 
316 {
318 }
319 
320 //______________________________________________________________________________
321 
323 {
326 }
327 
328 //______________________________________________________________________________
329 
330 void G4Molecule::MoveOneElectron(G4int orbitToFree, G4int orbitToFill)
331 {
333  fpMolecularConfiguration->MoveOneElectron(orbitToFree, orbitToFill);
334 }
335 
336 //______________________________________________________________________________
337 
339 {
341 }
342 
343 //______________________________________________________________________________
344 
346 {
348 }
349 
350 //______________________________________________________________________________
351 
353 {
355 }
356 
357 //______________________________________________________________________________
358 
360 {
362 }
363 
364 //______________________________________________________________________________
365 
367 {
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 {
419  // Ideal Gaz case
420  double v = GetDiffusionVelocity();
421  double E = (fpMolecularConfiguration->GetMass() / (c_squared)) * (v * v) / 2.;
423  return E;
424 }
425 
426 //______________________________________________________________________________
427 
429 {
430  double moleculeMass = fpMolecularConfiguration->GetMass() / (c_squared);
431 
433  // Different possibilities
435  // Ideal Gaz case : Maxwell Boltzmann Distribution
436  // double sigma = k_Boltzmann * fgTemperature / mass;
437  // return G4RandGauss::shoot( 0, sigma );
439  // Ideal Gaz case : mean velocity from equipartition theorem
440  return sqrt(3 * k_Boltzmann *
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"
452 const vector<const G4MolecularDissociationChannel*>*
454 {
456 }
457 
458 //______________________________________________________________________________
459 
461 {
463 }
464 
465 //______________________________________________________________________________
466 
468 {
470 }
471 
472 //______________________________________________________________________________
473 
475 {
477 }
478 
479 //______________________________________________________________________________
480 
482 {
484 }
485 
486 //______________________________________________________________________________
487 
489 {
491 }
492 
493 //______________________________________________________________________________
494 
496 {
498 }
499 
500 //______________________________________________________________________________
501 
503 {
505 }
506 
507 //______________________________________________________________________________
508 
510 {
512 }
513 
514 //______________________________________________________________________________
515 
517 {
519 }
520 
521 //______________________________________________________________________________
522 
524  double temperature) const
525 {
527  temperature);
528 }
529 
530 //______________________________________________________________________________
531 
533 {
535 }
536 
537 //______________________________________________________________________________
538 
540 {
542 }
543 
544 //______________________________________________________________________________
545 
547 {
548  // TODO check fpMolecularConfiguration already exists
549  // and new one as well
550  // TODO notify for stack change
553 
554  assert(fpMolecularConfiguration != nullptr);
555 }