Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4DNAChemistryManager.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // $Id: G4DNAChemistryManager.cc 75583 2013-11-04 12:16:46Z gcosmo $
27 //
28 // Author: Mathieu Karamitros (kara@cenbg.in2p3.fr)
29 //
30 // WARNING : This class is released as a prototype.
31 // It might strongly evolve or even disapear in the next releases.
32 //
33 // History:
34 // -----------
35 // 10 Oct 2011 M.Karamitros created
36 //
37 // -------------------------------------------------------------------
38 
39 #include "G4DNAChemistryManager.hh"
40 #include "G4SystemOfUnits.hh"
41 #include "G4Molecule.hh"
42 #include "G4ITTrackHolder.hh"
43 #include "G4H2O.hh"
47 #include "G4Electron_aq.hh"
48 #include "G4ITManager.hh"
50 #include "G4MoleculeCounter.hh"
51 #include "G4Tokenizer.hh"
52 #include "G4AutoLock.hh"
53 
54 using namespace std;
55 
56 auto_ptr<G4DNAChemistryManager> G4DNAChemistryManager::fInstance ;
57 G4ThreadLocal std::ofstream* G4DNAChemistryManager::fOutput = 0;
59 
61  fActiveChemistry(false)
62 {
63  fExcitationLevel = 0;
64  fIonisationLevel = 0;
65  fWriteFile = false;
66 }
67 
69 {
70  if (fInstance.get() == 0)
71  {
73  if(fInstance.get() == 0) // MT : double check at initialisation
74  {
75  fInstance = auto_ptr<G4DNAChemistryManager> (new G4DNAChemistryManager()) ;
76  }
77  lock.unlock();
78  }
79  return fInstance.get();
80 }
81 
82 G4DNAChemistryManager::~G4DNAChemistryManager()
83 {
84  if(fIonisationLevel) delete fIonisationLevel;
85  if(fExcitationLevel) delete fExcitationLevel;
89  fInstance.release();
91 }
92 
94 {
96  if(fInstance.get())
97  {
98  fInstance.reset();
99  }
100 }
101 
103 {
104  *fOutput << std::setprecision(6) << std::scientific;
105  *fOutput << setw(11) << left << "#Parent ID"
106  << setw(10) << "Molecule"
107  << setw(14) << "Elec Modif"
108  << setw(13) << "Energy (eV)"
109  << setw(22) << "X pos of parent [nm]"
110  << setw(22) << "Y pos of parent [nm]"
111  << setw(22) << "Z pos of parent [nm]"
112  << setw(14) << "X pos [nm]"
113  << setw(14) << "Y pos [nm]"
114  << setw(14) << "Z pos [nm]"
115  << G4endl
116  << setw(21) << "#"
117  << setw(13) << "1)io/ex=0/1"
118  << G4endl
119  << setw(21) << "#"
120  << setw(13) << "2)level=0...5"
121  << G4endl;
122 }
123 
125  ios_base::openmode mode)
126 {
127  fOutput = new std::ofstream();
128  fOutput->open(output.data(), mode);
129  fWriteFile = true;
130 }
131 
133 {
134  if (fOutput->is_open())
135  {
136  fOutput->close();
137  }
138 
139  fWriteFile = false;
140 }
141 
143 {
144  if(!fExcitationLevel)
145  {
146  fExcitationLevel = new G4DNAWaterExcitationStructure;
147  }
148  return fExcitationLevel;
149 }
150 
152 {
153  if(!fIonisationLevel)
154  {
155  fIonisationLevel = new G4DNAWaterIonisationStructure;
156  }
157  return fIonisationLevel;
158 }
159 
161  G4int electronicLevel,
162  const G4Track* theIncomingTrack)
163 {
164  if(fWriteFile)
165  {
166  G4double energy = -1.;
167 
168  switch (modification)
169  {
171  energy = -1;
172  break;
173  case eExcitedMolecule :
174  energy = GetExcitationLevel()->ExcitationEnergy(electronicLevel);
175  break;
176  case eIonizedMolecule :
177  energy = GetIonisationLevel()->IonisationEnergy(electronicLevel);
178  break;
179  }
180 
181  *fOutput << setw(11) << left << theIncomingTrack->GetTrackID()
182  << setw(10) << "H2O"
183  << left << modification
184  << internal <<":"
185  << right <<electronicLevel
186  << left
187  << setw(11) << ""
188  << std::setprecision(2) << std::fixed
189  << setw(13) << energy/eV
190  << std::setprecision(6) << std::scientific
191  << setw(22) << (theIncomingTrack->GetPosition().x())/nanometer
192  << setw(22) << (theIncomingTrack->GetPosition().y())/nanometer
193  << setw(22) << (theIncomingTrack->GetPosition().z())/nanometer
194  << G4endl;
195  }
196 
197  if(fActiveChemistry)
198  {
199  G4Molecule * H2O = new G4Molecule (G4H2O::Definition());
200 
201  switch (modification)
202  {
204  H2O -> AddElectron(5,1);
205  break;
206  case eExcitedMolecule :
207  H2O -> ExciteMolecule(electronicLevel);
208  break;
209  case eIonizedMolecule :
210  H2O -> IonizeMolecule(electronicLevel);
211  break;
212  }
213 
214  G4Track * H2OTrack = H2O->BuildTrack(1*picosecond,
215  theIncomingTrack->GetPosition());
216 
217  H2OTrack -> SetParentID(theIncomingTrack->GetTrackID());
218  H2OTrack -> SetTrackStatus(fStopButAlive);
219  H2OTrack -> SetKineticEnergy(0.);
220 
222  }
223 }
224 
226  G4ThreeVector* finalPosition)
227 // finalPosition is a pointer because this argument is optional
228 {
229  if(fWriteFile)
230  {
231  *fOutput << setw(11)<< theIncomingTrack->GetTrackID()
232  << setw(10)<< "e_aq"
233  << setw(14)<< -1
234  << std::setprecision(2) << std::fixed
235  << setw(13)<< theIncomingTrack->GetKineticEnergy()/eV
236  << std::setprecision(6) << std::scientific
237  << setw(22)<< (theIncomingTrack->GetPosition().x())/nanometer
238  << setw(22)<< (theIncomingTrack->GetPosition().y())/nanometer
239  << setw(22)<< (theIncomingTrack->GetPosition().z())/nanometer ;
240 
241  if(finalPosition != 0)
242  {
243  *fOutput<< setw(14)<< (finalPosition->x())/nanometer
244  << setw(14)<< (finalPosition->y())/nanometer
245  << setw(14)<< (finalPosition->z())/nanometer ;
246  }
247 
248  *fOutput << G4endl;
249  }
250 
251  if(fActiveChemistry)
252  {
254  G4Track * e_aqTrack(0);
255  if(finalPosition)
256  {
257  e_aqTrack = e_aq->BuildTrack(picosecond,*finalPosition);
258  }
259  else
260  {
261  e_aqTrack = e_aq->BuildTrack(picosecond,theIncomingTrack->GetPosition());
262  }
263  e_aqTrack -> SetTrackStatus(fAlive);
264  e_aqTrack -> SetParentID(theIncomingTrack->GetTrackID());
265  G4ITTrackHolder::Instance()->PushTrack(e_aqTrack);
266  G4ITManager<G4Molecule>::Instance()->Push(e_aqTrack);
267  }
268 }
269 
270 
271 void G4DNAChemistryManager::PushMolecule(G4Molecule*& molecule, double time,
272  const G4ThreeVector& position, int parentID)
273 {
274  if(fWriteFile)
275  {
276  *fOutput << setw(11)<< parentID
277  << setw(10)<< molecule->GetName()
278  << setw(14)<< -1
279  << std::setprecision(2) << std::fixed
280  << setw(13)<< -1
281  << std::setprecision(6) << std::scientific
282  << setw(22)<< (position.x())/nanometer
283  << setw(22)<< (position.y())/nanometer
284  << setw(22)<< (position.z())/nanometer;
285  *fOutput << G4endl;
286  }
287 
288  if(fActiveChemistry)
289  {
290  G4Track* track = molecule->BuildTrack(time,position);
291  track -> SetTrackStatus(fAlive);
292  track -> SetParentID(parentID);
294  G4ITManager<G4Molecule>::Instance()->Push(track);
295  }
296  else
297  {
298  delete molecule;
299  molecule = 0;
300  }
301 }
302 
304  const G4Track* theIncomingTrack)
305 {
306  if(fWriteFile)
307  {
308  *fOutput << setw(11)<< theIncomingTrack->GetTrackID()
309  << setw(10)<< molecule->GetName()
310  << setw(14)<< -1
311  << std::setprecision(2) << std::fixed
312  << setw(13)<< theIncomingTrack->GetKineticEnergy()/eV
313  << std::setprecision(6) << std::scientific
314  << setw(22)<< (theIncomingTrack->GetPosition().x())/nanometer
315  << setw(22)<< (theIncomingTrack->GetPosition().y())/nanometer
316  << setw(22)<< (theIncomingTrack->GetPosition().z())/nanometer ;
317  *fOutput << G4endl;
318  }
319 
320  if(fActiveChemistry)
321  {
322  G4Track* track = molecule->BuildTrack(theIncomingTrack->GetGlobalTime(),theIncomingTrack->GetPosition());
323  track -> SetTrackStatus(fAlive);
324  track -> SetParentID(theIncomingTrack->GetTrackID());
326  G4ITManager<G4Molecule>::Instance()->Push(track);
327  }
328  else
329  {
330  delete molecule;
331  molecule = 0;
332  }
333 }
334 
336 {
337  if(fWriteFile)
338  {
339  *fOutput << G4endl;
340  }
341 }
void WriteInto(const G4String &, std::ios_base::openmode mode=std::ios_base::out)
void PushMoleculeAtParentTimeAndPlace(G4Molecule *&molecule, const G4Track *)
static G4Electron_aq * Definition()
static G4H2O * Definition()
Definition: G4H2O.cc:46
double x() const
void CreateSolvatedElectron(const G4Track *, G4ThreeVector *finalPosition=0)
const G4ThreeVector & GetPosition() const
ElectronicModification
#define G4ThreadLocal
Definition: tls.hh:52
int G4int
Definition: G4Types.hh:78
double z() const
G4DNAWaterExcitationStructure * GetExcitationLevel()
int nanometer
Definition: hepunit.py:35
const G4String & GetName() const
Definition: G4Molecule.cc:243
G4Mutex chemManExistence
double precision function energy(A, Z)
Definition: dpm25nuc6.f:4106
G4double GetKineticEnergy() const
static G4ITManager< T > * Instance()
void PushMolecule(G4Molecule *&molecule, double time, const G4ThreeVector &position, int parentID)
G4int GetTrackID() const
G4double GetGlobalTime() const
G4Track * BuildTrack(G4double globalTime, const G4ThreeVector &Position)
Definition: G4Molecule.cc:263
const char * data() const
static G4DNAChemistryManager * Instance()
G4int G4Mutex
Definition: G4Threading.hh:156
int picosecond
Definition: hepunit.py:86
void CreateWaterMolecule(ElectronicModification, G4int, const G4Track *)
double y() const
static G4ITTrackHolder * Instance()
#define G4endl
Definition: G4ios.hh:61
virtual void PushTrack(G4Track *)
double G4double
Definition: G4Types.hh:76
G4DNAWaterIonisationStructure * GetIonisationLevel()
static void DeleteInstance()